Rewrote pet back end to use a more authentic system

Pets can now stack
Fixes a bug where a pet could get reset to 0 hunger and growth when dropped
Player save version migration messages are no longer shown
Pets now morph into adults in-place
This commit is contained in:
Player Name
2024-10-06 10:47:36 +00:00
committed by Ryan
parent 6b0f942598
commit 9c202aa47a
19 changed files with 204 additions and 684 deletions
+36
View File
@@ -326,6 +326,7 @@ fun addItem(player: Player, id: Int, amount: Int = 1, container: Container = Con
* @param player the player whose container to modify
* @param slot the slot to use
* @param item the item to replace the slot with
* @param currentItem the current item that is being replaced
* @param container the Container to modify
* @return the item that was previously in the slot, or null if none.
*/
@@ -358,6 +359,41 @@ fun replaceSlot(player: Player, slot: Int, item: Item, currentItem: Item? = null
return null
}
/**
* Replaces all items a player owns anywhere (equipment, inventory, bank, second bank)
* @param player the player whose inventory to remove the item from
* @param itemId the item ID to replace
* @param replaceId the replacement item ID
* @author Player Name
*/
fun replaceAllItems(player: Player, itemId: Int, replaceId: Int) {
val item = Item(itemId)
for (container in arrayOf(player.inventory, player.equipment, player.bankPrimary, player.bankSecondary)) {
val hasItems = container.getAll(item)
if (!item.definition.isStackable && (container == player.inventory || container == player.equipment)) {
for (target in hasItems) {
val newItem = Item(replaceId, target.amount)
container.replace(newItem, target.slot, true)
}
} else {
if (hasItems.size > 0) {
val target = hasItems[0]
var count = 0
for (x in hasItems) {
count += x.amount
}
val newItem = Item(replaceId, count)
container.replace(newItem, target.slot, true)
}
if (hasItems.size > 1) {
for (i in 1 until hasItems.size) {
container.remove(hasItems[i], hasItems[i].slot, true)
}
}
}
}
}
/**
* Add an item with a variable quantity or drop it if a player does not have enough space
* @param player the player whose inventory to add to