aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Model/Entities/Entity.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalevalapokalypsi/Model/Entities/Entity.scala')
-rw-r--r--src/scalevalapokalypsi/Model/Entities/Entity.scala72
1 files changed, 49 insertions, 23 deletions
diff --git a/src/scalevalapokalypsi/Model/Entities/Entity.scala b/src/scalevalapokalypsi/Model/Entities/Entity.scala
index e7cd45c..c7bc180 100644
--- a/src/scalevalapokalypsi/Model/Entities/Entity.scala
+++ b/src/scalevalapokalypsi/Model/Entities/Entity.scala
@@ -15,13 +15,14 @@ class Entity(
val name: String,
initialLocation: Area,
initialHP: Int = 100,
- val maxHP: Int = 100
+ val maxHP: Int = 100,
+ val maxInventoryWeight: Int = 10
):
private var currentLocation: Area = initialLocation
private var quitCommandGiven = false // one-way flag
- private val inventory: Map[String, Item] = Map()
private var hp = initialHP
+ private var items: Map[String, (Int, Item)] = Map()
// TODO: add logic for choosing from multiplu lines - can depend on HP etc.
/** Gets a verse to sing when attacking against this entity.
@@ -33,7 +34,7 @@ class Entity(
def takeDamage(amount: Int): Unit =
hp -= amount
if hp < 0 then
- println("Oh no, I died!")
+ println("Voi ei, kuolin!")
/** Returns a description of the physical condition of this entity,
* i.e. the damage it has taken.
@@ -86,42 +87,51 @@ class Entity(
(oldEntities.size)
(s"${this.name} leaves this location.")
)
- //val arriving = newEntities.map(n => n.zip(
- // Vector.fill
- // (n.size)
- // (s"${this.name} arrives here.")
- //)).getOrElse(Vector())
val self = Vector((this, s"You go $direction."))
Some(Event(
(leaving ++ self).toMap,
- s"$name arrives here."
+ s"$name saapuu tänne."
))
else None
def pickUp(itemName: String): Event =
this.currentLocation.removeItem(itemName) match
case Some(i) =>
- this.inventory += i.name -> i
- Event(
- immutable.Map.from(Vector((this, s"You pick up the ${i.name}"))),
- s"$name picks up the ${i.name}"
- )
+ val inventoryWeight = items.values.map(p => p(1).weight).sum
+ if inventoryWeight + i.weight > maxInventoryWeight then
+ Event(
+ immutable.Map.from(Vector((this, s"Voimasi eivät riitä kannattelemaan esinettä ${i.name}, koska kannat liikaa"))),
+ s"")
+ else
+ if items.contains(i.name) then
+ val (current, _) = items(i.name)
+ this.items += i.name -> (current + 1, i)
+ else
+ this.items += i.name -> (1, i)
+ Event(
+ immutable.Map.from(Vector((this, s"Poimit esineen ${i.name}"))),
+ s"$name poimi esineen ${i.name}"
+ )
case None => Event(
- immutable.Map.from(Vector((this, s"There is no $itemName here to pick up."))),
- s"${this.name} tries to pick up something but gets just dirt in their hands."
+ immutable.Map.from(Vector((this, s"Täällä ei ole esinettä $itemName noukittavaksi."))),
+ s"${this.name} yritti ottaa jotakin, mutta sai vain likaa käsilleen."
)
def drop(itemName: String): Event =
- this.inventory.remove(itemName) match
- case Some(item) =>
+ this.items.remove(itemName) match
+ case Some((current, item)) if current > 0 =>
+ if current - 1 == 0 then
+ this.items -= item.name
+ else
+ this.items += itemName -> (current - 1, item)
this.currentLocation.addItem(item)
Event(
- immutable.Map.from(Vector((this, s"You drop the $itemName"))),
- s"$name drops the $itemName"
+ immutable.Map.from(Vector((this, s"Pudotit esineen $itemName"))),
+ s"$name Pudotti esineen $itemName"
)
case None => Event(
- immutable.Map.from(Vector((this, "You don't have that!"))),
- s"$name reaches their backpack to drop $itemName but miserably fails to find it there."
+ immutable.Map.from(Vector((this, "Sinulla ei ole tätä esinettä!"))),
+ s"$name yritti tonkia rpustaan esineen $itemName mutta ei löytänyt sitä."
)
def sayTo(entity: Entity, message: String): Event =
@@ -163,9 +173,25 @@ class Entity(
* @param itemName the name to check
* @return whether this entity has this item and can drop it
*/
- def canDrop(itemName: String): Boolean = this.inventory.contains(itemName)
+ def canDrop(itemName: String): Boolean = this.items.contains(itemName)
/** Returns a brief description of the player’s state, for debugging purposes. */
override def toString = s"${this.name} at ${this.location.name}"
+
+ def inventory: Event =
+ if this.items.isEmpty then
+ Event(
+ immutable.Map.from(Vector((this, s"Sinulla ei ole esineitä"))),
+ s"")
+ else
+ var inventoryList = List[String]()
+ for (name, (count, item)) <- this.items do
+ inventoryList = inventoryList :+ s"$name $count (${item.description})"
+ Event(
+ immutable.Map.from(Vector((this, s"Kannat repussasi:\n" + inventoryList.mkString("\n")))),
+ s"")
+
+
+
end Entity