aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Model/Action.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalevalapokalypsi/Model/Action.scala')
-rw-r--r--src/scalevalapokalypsi/Model/Action.scala40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/scalevalapokalypsi/Model/Action.scala b/src/scalevalapokalypsi/Model/Action.scala
index e59d5f1..cee0ee5 100644
--- a/src/scalevalapokalypsi/Model/Action.scala
+++ b/src/scalevalapokalypsi/Model/Action.scala
@@ -2,10 +2,13 @@ package scalevalapokalypsi.Model
import scalevalapokalypsi.Model.Entities.*
-/** The class `Action` represents actions that a player may take in a text adventure game.
- * `Action` objects are constructed on the basis of textual commands and are, in effect,
- * parsers for such commands. An action object is immutable after creation.
- * @param input a textual in-game command such as “go east” or “rest” */
+/** The class `Action` represents actions that a player may take in a text
+ * adventure game. `Action` objects are constructed on the basis of textual
+ * commands and are, in effect, parsers for such commands. An action object is
+ * immutable after creation.
+ *
+ * @param input a textual in-game command such as “go east” or “rest”
+ */
class Action(input: String):
private val commandText = input.trim.toLowerCase
@@ -19,12 +22,19 @@ class Action(input: String):
case "get" => actor.location.hasItem(this.modifiers)
case "drop" => actor.canDrop(this.modifiers)
case "say" => false
+ case "laula" => false
case other => false
- /** Causes the given player to take the action represented by this object, assuming
- * that the command was understood. Returns a description of what happened as a result
- * of the action (such as “You go west.”). The description is returned in an `Option`
- * wrapper; if the command was not recognized, `None` is returned. */
+ /** Causes the given player to take the action represented by this object,
+ * assuming that the command was understood. Returns a description of what
+ * happened as a result of the action (such as “You go west.”). The
+ * description is returned in an `Option` wrapper; if the command was not
+ * recognized, `None` is returned.
+ *
+ * @param actor the acting player
+ * @return A textual description of the action, or `None` if the action
+ * was not recognized.
+ */
def execute(actor: Player): Option[String] =
val oldLocation = actor.location
val resOption: Option[(String, String)] = this.verb match
@@ -46,6 +56,20 @@ class Action(input: String):
else
Some(actor.say(modifiers))
case "drop" => Some(actor.drop(this.modifiers))
+ case "laula" =>
+ val end = modifiers.takeRight("suohon".length)
+ val start =
+ modifiers.take(modifiers.length - "suohon".length).trim
+ if end == "suohon" then
+ val targetEntity = actor.location.getEntity(start)
+ targetEntity
+ .foreach(e => actor.setSingEffect(defaultSingAttack(e)))
+ targetEntity.map(e => (
+ "Aloitat suohonlaulun.",
+ s"${actor.name} aloittaa suohonlaulun."
+ ))
+ else
+ None
case "xyzzy" => Some((
"The grue tastes yummy.",
s"${actor.name} tastes some grue.")