package game import ( "fmt" "sort" "thehouseoficarus/internal/combat" "thehouseoficarus/internal/engine" "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) func (g *Game) dropItemsOnDeath(p *player.Player) { roomID := p.RoomID if p.Credits > 0 { g.World.AddGroundItem(roomID, "credits", p.Credits) p.Credits = 0 } var items []deathDrop for slot, inv := range p.Inventory { if inv == nil || inv.Quantity <= 0 { continue } val := 0 if def, err := g.ItemStore.Load(inv.ItemID); err == nil { val = def.Value * inv.Quantity } items = append(items, deathDrop{ itemID: inv.ItemID, quantity: inv.Quantity, totalValue: val, invSlot: slot, }) } for eqSlot, itemID := range p.Equipment { val := 0 if def, err := g.ItemStore.Load(itemID); err == nil { val = def.Value } items = append(items, deathDrop{ itemID: itemID, quantity: 1, totalValue: val, isEquip: true, equipSlot: eqSlot, }) } if len(items) <= 3 { return } sort.Slice(items, func(i, j int) bool { return items[i].totalValue > items[j].totalValue }) for i := 3; i < len(items); i++ { it := items[i] if it.isEquip { delete(p.Equipment, it.equipSlot) } else { p.SetInvSlot(it.invSlot, nil) } g.World.AddGroundItem(roomID, it.itemID, it.quantity) } } func (g *Game) checkAggro(sess *net.Session) { p := sess.Player if combat.GetCombat(p.Name) != nil { return } playerLevel := p.CombatLevel() mobs := g.MobStore.MobsInRoom(p.RoomID) for _, mob := range mobs { if !mob.Aggressive || mob.HP <= 0 || mob.Protected { continue } if combat.IsMobInCombat(mob.InstanceID) { continue } mobLevel := mobCombatLevel(mob) if playerLevel > mobLevel*2 { continue } if g.isSafespotted(p.Name) && g.safespotBlocksMob(p, mob) { continue } aggMob := mob g.Ticks.Subscribe(engine.ToTicks(1), func() bool { if combat.GetCombat(p.Name) != nil { return false } if aggMob.HP <= 0 || aggMob.RoomID != p.RoomID { return false } if combat.IsMobInCombat(aggMob.InstanceID) { return false } attacker := aggMob.Name if !aggMob.Unique { attacker = "The " + aggMob.Name } sess.WriteLine(fmt.Sprintf("\n%s attacks you!", g.colorize(sess, "mob", attacker))) g.startCombat(sess, p, aggMob) return false }) break } }