From 6f35bc1172c5035053c29ad9dcb30a7a137fb345 Mon Sep 17 00:00:00 2001 From: tolelom <98kimsungmin@naver.com> Date: Tue, 24 Mar 2026 10:45:01 +0900 Subject: [PATCH] feat: show log messages for trap, blessing, and treasure events --- game/event.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/game/event.go b/game/event.go index 712460e..5e78a9e 100644 --- a/game/event.go +++ b/game/event.go @@ -1,6 +1,7 @@ package game import ( + "fmt" "math/rand" "github.com/tolelom/catacombs/dungeon" @@ -107,16 +108,19 @@ func (s *GameSession) spawnBoss() { } func (s *GameSession) grantTreasure() { - // Random item for each player for _, p := range s.state.Players { if rand.Float64() < 0.5 { - p.Inventory = append(p.Inventory, entity.Item{ + item := entity.Item{ Name: "Iron Sword", Type: entity.ItemWeapon, Bonus: 3 + rand.Intn(6), - }) + } + p.Inventory = append(p.Inventory, item) + s.addLog(fmt.Sprintf("%s found %s (ATK+%d)", p.Name, item.Name, item.Bonus)) } else { - p.Inventory = append(p.Inventory, entity.Item{ + item := entity.Item{ Name: "Iron Shield", Type: entity.ItemArmor, Bonus: 2 + rand.Intn(4), - }) + } + p.Inventory = append(p.Inventory, item) + s.addLog(fmt.Sprintf("%s found %s (DEF+%d)", p.Name, item.Name, item.Bonus)) } } } @@ -130,19 +134,19 @@ func (s *GameSession) generateShopItems() { } func (s *GameSession) triggerEvent() { - // Random event: 50% trap, 50% blessing for _, p := range s.state.Players { if p.IsDead() { continue } if rand.Float64() < 0.5 { - // Trap: 10~20 damage dmg := 10 + rand.Intn(11) p.TakeDamage(dmg) + s.addLog(fmt.Sprintf("Trap! %s takes %d damage", p.Name, dmg)) } else { - // Blessing: heal 15~25 heal := 15 + rand.Intn(11) + before := p.HP p.Heal(heal) + s.addLog(fmt.Sprintf("Blessing! %s heals %d HP", p.Name, p.HP-before)) } } }