- commit
- aa50b41b740f453883059d53f8bbb66b8504bd3e
- parent
- 0e4333d0a391974b646bd62afacb954060529413
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-09-29 08:40
drop inventory on death
Diffstat
| M | game.go | 9 | ++++++--- |
| M | monster.go | 2 | +- |
| M | player.go | 2 | +- |
3 files changed, 8 insertions, 5 deletions
diff --git a/game.go b/game.go
@@ -181,7 +181,7 @@ func (game *Game) getPlayerAt(pos Point) *Player {
181 181 return nil
182 182 }
183 183
184 -1 func (game *Game) addToPile(pos Point, item string) {
-1 184 func (game *Game) addToPile(pos Point, item string, amount uint) {
185 185 pile, ok := game.Piles[pos]
186 186 if !ok {
187 187 pile = &Pile{
@@ -193,9 +193,9 @@ func (game *Game) addToPile(pos Point, item string) {
193 193
194 194 value, ok := pile.Items[item]
195 195 if ok {
196 -1 pile.Items[item] = value + 1
-1 196 pile.Items[item] = value + amount
197 197 } else {
198 -1 pile.Items[item] = 1
-1 198 pile.Items[item] = amount
199 199 game.Enqueue(Message{
200 200 "action": "create",
201 201 "type": "pile",
@@ -281,6 +281,9 @@ func (game *Game) run() {
281 281 "action": "remove",
282 282 "id": player.Id,
283 283 })
-1 284 for item, amount := range player.Inventory {
-1 285 game.addToPile(player.Pos, item, amount)
-1 286 }
284 287 }
285 288 case pmsg := <-game.Msg:
286 289 if pmsg.Msg["action"] == "move" {
diff --git a/monster.go b/monster.go
@@ -74,7 +74,7 @@ func (monster *Monster) TakeDamage(amount int) {
74 74 if monster.Health <= 0 {
75 75 monster.quit <- true
76 76 delete(monster.Game.Monsters, monster)
77 -1 monster.Game.addToPile(monster.Pos, "potion")
-1 77 monster.Game.addToPile(monster.Pos, "potion", 1)
78 78 monster.Game.Enqueue(Message{
79 79 "action": "remove",
80 80 "id": monster.Id,
diff --git a/player.go b/player.go
@@ -132,7 +132,7 @@ func (player *Player) PickupItems() {
132 132
133 133 func (player *Player) DropItem(item string) {
134 134 if player.RemoveItem(item, 1) {
135 -1 player.Game.addToPile(player.Pos, item)
-1 135 player.Game.addToPile(player.Pos, item, 1)
136 136 }
137 137 }
138 138