Commit 595234cc authored by AnimeGitB's avatar AnimeGitB Committed by Melledy
Browse files

Add Inventory.payItems() method

parent 226a29f7
......@@ -7,6 +7,7 @@ import java.util.List;
import emu.grasscutter.GameConstants;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.data.def.AvatarCostumeData;
import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.AvatarFlycloakData;
......@@ -256,6 +257,52 @@ public class Inventory implements Iterable<GameItem> {
getPlayer().setCrystals(player.getCrystals() + count);
}
}
private int getVirtualItemCount(int itemId) {
switch (itemId) {
case 201: // Primogem
return player.getPrimogems();
case 202: // Mora
return player.getMora();
case 203: // Genesis Crystals
return player.getCrystals();
default:
GameItem item = getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(itemId); // What if we ever want to operate on weapons/relics/furniture? :S
return (item == null) ? 0 : item.getCount();
}
}
public boolean payItems(Collection<ItemParamData> items) {
return payItems(items, null);
}
public synchronized boolean payItems(Collection<ItemParamData> costItems, ActionReason reason) {
// Make sure player has requisite items
for (ItemParamData cost : costItems) {
if (getVirtualItemCount(cost.getId()) < cost.getCount()) {
return false;
}
}
// All costs are satisfied, now remove them all
for (ItemParamData cost : costItems) {
switch (cost.getId()) {
case 201 -> // Primogem
player.setPrimogems(player.getPrimogems() - cost.getCount());
case 202 -> // Mora
player.setMora(player.getMora() - cost.getCount());
case 203 -> // Genesis Crystals
player.setCrystals(player.getCrystals() - cost.getCount());
default ->
removeItem(getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(cost.getId()), cost.getCount());
}
}
if (reason != null) { // Do we need these?
// getPlayer().sendPacket(new PacketItemAddHintNotify(changedItems, reason));
}
// getPlayer().sendPacket(new PacketStoreItemChangeNotify(changedItems));
return true;
}
public void removeItems(List<GameItem> items) {
// TODO Bulk delete
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment