diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-17 22:32:25 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-17 22:32:25 +0200 |
commit | a98f089035dbcc94c14c9cd6246c3150bee84241 (patch) | |
tree | 228ffa0d5e4a3e86c454cd297644c97abc994ef3 /src/scalevalapokalypsi/Model/Entities/Player.scala | |
parent | c954ca4d1ec677a34a6d787a23f9d01396f7e585 (diff) | |
download | scalevalapokalypsi-a98f089035dbcc94c14c9cd6246c3150bee84241.tar.gz scalevalapokalypsi-a98f089035dbcc94c14c9cd6246c3150bee84241.zip |
Improved client recovery from singing & added better logic for observations
The logic should still be implemented for all observations
Diffstat (limited to 'src/scalevalapokalypsi/Model/Entities/Player.scala')
-rw-r--r-- | src/scalevalapokalypsi/Model/Entities/Player.scala | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/src/scalevalapokalypsi/Model/Entities/Player.scala b/src/scalevalapokalypsi/Model/Entities/Player.scala index 7e441c1..f231c28 100644 --- a/src/scalevalapokalypsi/Model/Entities/Player.scala +++ b/src/scalevalapokalypsi/Model/Entities/Player.scala @@ -15,14 +15,20 @@ import scalevalapokalypsi.Model.* class Player(name: String, initialLocation: Area) extends Entity(name, initialLocation): private val observations: Buffer[String] = Buffer.empty - private var pendingSingEffect: Option[Float => String] = None + private val observedEvents: Buffer[Event] = Buffer.empty + private var pendingSingEffect: Option[SingEffect] = None - override def observe(observation: String): Unit = + override def observeString(observation: String): Unit = this.observations.append(observation) + override def observe(event: Event): Unit = + this.observedEvents.append(event) def readAndClearObservations(): Vector[String] = - val res = this.observations.toVector + val res1 = this.observations + val res2 = this.observedEvents.map(_.descriptionFor(this)) + val res = (res1 ++ res2).toVector observations.clear() + observedEvents.clear() res /** Returns whether this player has a pending sing effect. */ @@ -33,18 +39,37 @@ class Player(name: String, initialLocation: Area) extends Entity(name, initialLo * * @param effect the effect to apply based on the song. */ - def setSingEffect(effect: Float => String): Unit = + def setSingEffect(effect: SingEffect): Unit = this.pendingSingEffect = Some(effect) + + def getSingEffectTarget: Option[Entity] = + this.pendingSingEffect.map(_.target) - /** Applies the pending sing effect. - * - * @param singQuality the quality of the song - * @return a textual description of the effects of the song, - * or None if there was no pending sing effect. - */ - def applySingEffect(singQuality: Float): Option[String] = - val res = this.pendingSingEffect.map(f => f(singQuality)) + /** Applies the pending sing effect and informs the surronding Entities + * about the effects of the song. + * + * @param singQuality the quality of the song + */ + def applySingEffect(singQuality: Float): Unit = + val res = this.pendingSingEffect.map(ef => ef(singQuality)) this.pendingSingEffect = None - res - + val qualityDescriptions = + if singQuality < .10 then + ("säälittävää", "epsilonin suuruinen") + else if singQuality < .30 then + ("heikkoa", "vähäinen") + else if singQuality < .60 then + ("keskinkertaista", "huomattavissa") + else if singQuality < .80 then + ("hyvää", "huomattava") + else ("erinomaista", "merkittävä") + val quality = + s"Laulu on ${qualityDescriptions(0)} ja sen vaikutus on ${qualityDescriptions(1)}." + val event = res.map(ev => Event( + ev.target, + s"$quality\n${ev.inFirstPerson}", + s"$quality\n${ev.inThirdPerson}" + )) + event.foreach(this.location.observeEvent(_)) + end Player |