aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


server/control_items.go (1310B)


      1 package main
      2 
      3 import "slices"
      4 
      5 type controlItemSlot struct {
      6 	bag  uint32
      7 	slot uint32
      8 }
      9 
     10 func controlItemSlots(inventory playerInventory, item ownedItem) []controlItemSlot {
     11 	var slots []controlItemSlot
     12 	for slot := uint32(1); slot < 94; slot++ {
     13 		if slot < 64 && (!item.fitsEquipmentSlot(slot) || slot >= 9 && slot <= 14 && int32(slot-9) >= inventory.equipmentBonus(45)) {
     14 			continue
     15 		}
     16 		if !slices.ContainsFunc(inventory.Items, func(other ownedItem) bool { return other.Slot == slot }) {
     17 			slots = append(slots, controlItemSlot{slot: slot})
     18 		}
     19 	}
     20 	if item.Type != 51017 {
     21 		for _, bag := range append(slices.Clone(inventory.Items), inventory.Bank...) {
     22 			if !bag.isPortableContainer() {
     23 				continue
     24 			}
     25 			for slot := uint32(0); slot < 21; slot++ {
     26 				if !slices.ContainsFunc(inventory.Containers[bag.ID], func(other ownedItem) bool { return other.Slot == slot }) {
     27 					slots = append(slots, controlItemSlot{bag: bag.ID, slot: slot})
     28 				}
     29 			}
     30 		}
     31 	}
     32 	return slots
     33 }
     34 
     35 func (inventory playerInventory) allItems() []ownedItem {
     36 	items := slices.Clone(inventory.Items)
     37 	items = append(items, inventory.Bank...)
     38 	for _, entry := range inventory.Reclaim {
     39 		items = append(items, entry.Item)
     40 	}
     41 	for _, contents := range inventory.Containers {
     42 		items = append(items, contents...)
     43 	}
     44 	return items
     45 }