Skip to content

Commit

Permalink
loot from enemy kill
Browse files Browse the repository at this point in the history
  • Loading branch information
liqMix committed Jul 1, 2024
1 parent 8004515 commit f317a0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
6 changes: 6 additions & 0 deletions internal/game/dude.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ func (d *Dude) Trigger(e Event) Activity {
MessageGood,
fmt.Sprintf("%s defeated %s and gained %d xp and %d gp", d.name, d.enemy.name, xp, gold),
)
if d.room != nil {
loot := d.room.RollLoot(d.GetCalculatedStats().luck)
if loot != nil {
d.AddToInventory(loot)
}
}
d.enemy = nil
} else {
takenDamage, isDodge := d.ApplyDamage(d.enemy.Hit())
Expand Down
24 changes: 13 additions & 11 deletions internal/game/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,21 +533,23 @@ func (r *Room) GetRoomEffect(e Event) Activity {
// Add XP
e.dude.AddXP(5 * (r.story.level + 1))

// Roll for any loot if the room has any
if r.kind.Equipment() != nil {
// Loot from combat is gained on enemy kill
if r.kind != Combat {
// Roll for any loot if the room has any
if r.kind.Equipment() != nil {
// Roll for loot on exit
if eq := r.RollLoot(e.dude.stats.luck); eq != nil {
// Add to inventory and equip if slot is empty
e.dude.AddToInventory(eq)
AddMessage(
MessageLoot,
fmt.Sprintf("%s found %s", e.dude.name, eq.Name()),
)
if r.kind.Equipment() != nil {
// Roll for loot on exit
if eq := r.RollLoot(e.dude.stats.luck); eq != nil {
// Add to inventory and equip if slot is empty
e.dude.AddToInventory(eq)
AddMessage(
MessageLoot,
fmt.Sprintf("%s found %s", e.dude.name, eq.Name()),
)
}
}
}
}
// Add other leave events here
case EventCenterRoom:
// Add center room events here
switch r.kind {
Expand Down

0 comments on commit f317a0f

Please sign in to comment.