From 12316b36b120b5b3f6066632408953fd3c225a29 Mon Sep 17 00:00:00 2001 From: AnimeGitB Date: Fri, 4 Nov 2022 15:05:51 +1030 Subject: [PATCH] Reimplement namecard claiming (fixes #1882) --- src/main/java/emu/grasscutter/game/inventory/Inventory.java | 1 + .../grasscutter/game/props/ItemUseAction/ItemUseAction.java | 2 +- .../game/props/ItemUseAction/ItemUseGainNameCard.java | 3 ++- .../grasscutter/game/props/ItemUseAction/UseItemParams.java | 1 + .../java/emu/grasscutter/game/systems/InventorySystem.java | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/inventory/Inventory.java b/src/main/java/emu/grasscutter/game/inventory/Inventory.java index cb5ac633c..b82e9a96e 100644 --- a/src/main/java/emu/grasscutter/game/inventory/Inventory.java +++ b/src/main/java/emu/grasscutter/game/inventory/Inventory.java @@ -181,6 +181,7 @@ public class Inventory extends BasePlayerManager implements Iterable { if (data.isUseOnGain()) { var params = new UseItemParams(this.player, data.getUseTarget()); + params.usedItemId = data.getId(); this.player.getServer().getInventorySystem().useItemDirect(data, params); return null; } diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAction.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAction.java index 63b053b25..6af7ac8ea 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAction.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAction.java @@ -24,7 +24,7 @@ public class ItemUseAction { case ITEM_USE_GAIN_AVATAR -> new ItemUseGainAvatar(useParam); case ITEM_USE_GAIN_COSTUME -> new ItemUseGainCostume(useParam); // TODO - real success/fail case ITEM_USE_GAIN_FLYCLOAK -> new ItemUseGainFlycloak(useParam); // TODO - real success/fail - case ITEM_USE_GAIN_NAME_CARD -> new ItemUseGainNameCard(useParam); // TODO + case ITEM_USE_GAIN_NAME_CARD -> new ItemUseGainNameCard(useParam); case ITEM_USE_CHEST_SELECT_ITEM -> new ItemUseChestSelectItem(useParam); case ITEM_USE_ADD_SELECT_ITEM -> new ItemUseAddSelectItem(useParam); case ITEM_USE_GRANT_SELECT_REWARD -> new ItemUseGrantSelectReward(useParam); diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseGainNameCard.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseGainNameCard.java index ac4695269..dbcb5e37b 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseGainNameCard.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseGainNameCard.java @@ -13,6 +13,7 @@ public class ItemUseGainNameCard extends ItemUseAction { @Override public boolean useItem(UseItemParams params) { - return false; // TODO: work out if this is actually used and how to get the namecard id + params.player.addNameCard(params.usedItemId); + return true; } } diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/UseItemParams.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/UseItemParams.java index 3fc3cc5be..b2af9145b 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/UseItemParams.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/UseItemParams.java @@ -12,6 +12,7 @@ public class UseItemParams { public int count = 1; public int optionId = 0; public boolean isEnterMpDungeonTeam = false; + public int usedItemId = 0; public UseItemParams(Player player, ItemUseTarget itemUseTarget, Avatar targetAvatar, int count, int optionId, boolean isEnterMpDungeonTeam) { this.player = player; diff --git a/src/main/java/emu/grasscutter/game/systems/InventorySystem.java b/src/main/java/emu/grasscutter/game/systems/InventorySystem.java index 0cd2f4def..745697428 100644 --- a/src/main/java/emu/grasscutter/game/systems/InventorySystem.java +++ b/src/main/java/emu/grasscutter/game/systems/InventorySystem.java @@ -743,6 +743,7 @@ public class InventorySystem extends BaseGameSystem { if (itemData == null) return null; var params = new UseItemParams(player, itemData.getUseTarget(), target, count, optionId, isEnterMpDungeonTeam); + params.usedItemId = item.getItemId(); if (useItemDirect(itemData, params)) { player.getInventory().removeItem(item, count); var actions = itemData.getItemUseActions();