mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-23 13:37:42 +00:00
Add Inventory.payItems() method
This commit is contained in:
parent
53797dfd3b
commit
010455548f
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user