diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java index c856ac242..4b8fa0131 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java @@ -286,14 +286,18 @@ public final class DungeonManager { } public void finishDungeon() { - // Mark the dungeon has completed for the players. - var dungeonId = this.getDungeonData().getId(); - this.getScene() - .getPlayers() - .forEach(player -> player.getPlayerProgress().markDungeonAsComplete(dungeonId)); + this.notifyEndDungeon(true); + this.endDungeon(BaseDungeonResult.DungeonEndReason.COMPLETED); + } - notifyEndDungeon(true); - endDungeon(BaseDungeonResult.DungeonEndReason.COMPLETED); + public void quitDungeon() { + this.notifyEndDungeon(false); + this.endDungeon(BaseDungeonResult.DungeonEndReason.QUIT); + } + + public void failDungeon() { + this.notifyEndDungeon(false); + this.endDungeon(BaseDungeonResult.DungeonEndReason.FAILED); } public void notifyEndDungeon(boolean successfully) { @@ -301,8 +305,11 @@ public final class DungeonManager { .getPlayers() .forEach( p -> { - // Trigger the fail event if needed. - if (!successfully) { + // Trigger the fail and success event. + if (successfully) { + var dungeonId = this.getDungeonData().getId(); + p.getPlayerProgress().markDungeonAsComplete(dungeonId); + } else { p.getQuestManager() .queueEvent(QuestContent.QUEST_CONTENT_FAIL_DUNGEON, dungeonData.getId()); } @@ -317,16 +324,6 @@ public final class DungeonManager { .callEvent(new ScriptArgs(0, EventType.EVENT_DUNGEON_SETTLE, successfully ? 1 : 0)); } - public void quitDungeon() { - notifyEndDungeon(false); - endDungeon(BaseDungeonResult.DungeonEndReason.QUIT); - } - - public void failDungeon() { - notifyEndDungeon(false); - endDungeon(BaseDungeonResult.DungeonEndReason.FAILED); - } - public void endDungeon(BaseDungeonResult.DungeonEndReason endReason) { if (scene.getDungeonSettleListeners() != null) { scene.getDungeonSettleListeners().forEach(o -> o.onDungeonSettle(this, endReason)); diff --git a/src/main/java/emu/grasscutter/game/entity/EntityGadget.java b/src/main/java/emu/grasscutter/game/entity/EntityGadget.java index 2cab739fc..a04d6e67d 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityGadget.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityGadget.java @@ -150,6 +150,7 @@ public class EntityGadget extends EntityBaseGadget { public void updateState(int state) { if (state == this.getState()) return; // Don't triggers events + var oldState = this.getState(); this.setState(state); ticksSinceChange = getScene().getSceneTimeSeconds(); this.getScene().broadcastPacket(new PacketGadgetStateNotify(this, state)); @@ -157,7 +158,7 @@ public class EntityGadget extends EntityBaseGadget { .getScriptManager() .callEvent( new ScriptArgs( - this.getGroupId(), EventType.EVENT_GADGET_STATE_CHANGE, state, this.getConfigId())); + this.getGroupId(), EventType.EVENT_GADGET_STATE_CHANGE, state, this.getConfigId()).setParam3(oldState)); } @Deprecated(forRemoval = true) // Dont use! diff --git a/src/main/java/emu/grasscutter/game/inventory/EquipInventoryTab.java b/src/main/java/emu/grasscutter/game/inventory/EquipInventoryTab.java index 5082f978e..3d2f8fd5d 100644 --- a/src/main/java/emu/grasscutter/game/inventory/EquipInventoryTab.java +++ b/src/main/java/emu/grasscutter/game/inventory/EquipInventoryTab.java @@ -36,4 +36,9 @@ public class EquipInventoryTab implements InventoryTab { public int getMaxCapacity() { return this.maxCapacity; } + + @Override + public int getItemCountById(int itemId) { + return (int) items.stream().filter(item -> item.getItemId() == itemId).count(); + } } diff --git a/src/main/java/emu/grasscutter/game/inventory/GameItem.java b/src/main/java/emu/grasscutter/game/inventory/GameItem.java index 64029c752..4dbfbbb45 100644 --- a/src/main/java/emu/grasscutter/game/inventory/GameItem.java +++ b/src/main/java/emu/grasscutter/game/inventory/GameItem.java @@ -129,7 +129,7 @@ public class GameItem { public void checkIsNew(Inventory inventory) { // display notification when player obtain new item - if (inventory.getItemByGuid(this.itemId) == null) { + if (inventory.getItemById(this.itemId) == null) { this.newItem = true; } } diff --git a/src/main/java/emu/grasscutter/game/inventory/Inventory.java b/src/main/java/emu/grasscutter/game/inventory/Inventory.java index a06d55ed1..ecb12c35d 100644 --- a/src/main/java/emu/grasscutter/game/inventory/Inventory.java +++ b/src/main/java/emu/grasscutter/game/inventory/Inventory.java @@ -17,6 +17,9 @@ import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.Utils; import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.longs.*; +import lombok.val; +import javax.annotation.Nullable; + import java.util.*; public class Inventory extends BasePlayerManager implements Iterable { @@ -62,6 +65,26 @@ public class Inventory extends BasePlayerManager implements Iterable { return this.getItems().get(id); } + @Nullable + public InventoryTab getInventoryTabByItemId(int itemId) { + val itemData = GameData.getItemDataMap().get(itemId); + if (itemData == null || itemData.getItemType() == null) { + return null; + } + return getInventoryTab(itemData.getItemType()); + } + + @Nullable + public GameItem getItemById(int itemId) { + val inventoryTab = this.getInventoryTabByItemId(itemId); + return inventoryTab != null ? inventoryTab.getItemById(itemId) : null; + } + + public int getItemCountById(int itemId) { + val inventoryTab = this.getInventoryTabByItemId(itemId); + return inventoryTab != null ? inventoryTab.getItemCountById(itemId) : 0; + } + public boolean addItem(int itemId) { return addItem(itemId, 1); } @@ -562,7 +585,7 @@ public class Inventory extends BasePlayerManager implements Iterable { tab = getInventoryTab(item.getItemData().getItemType()); } - putItem(item, tab); + this.putItem(item, tab); // Equip to a character if possible if (item.isEquipped()) { diff --git a/src/main/java/emu/grasscutter/game/inventory/InventoryTab.java b/src/main/java/emu/grasscutter/game/inventory/InventoryTab.java index e50f884bf..374a43c31 100644 --- a/src/main/java/emu/grasscutter/game/inventory/InventoryTab.java +++ b/src/main/java/emu/grasscutter/game/inventory/InventoryTab.java @@ -10,4 +10,6 @@ public interface InventoryTab { int getSize(); int getMaxCapacity(); + + int getItemCountById(int itemId); } diff --git a/src/main/java/emu/grasscutter/game/inventory/MaterialInventoryTab.java b/src/main/java/emu/grasscutter/game/inventory/MaterialInventoryTab.java index 9ebf0d7f1..5f71839c4 100644 --- a/src/main/java/emu/grasscutter/game/inventory/MaterialInventoryTab.java +++ b/src/main/java/emu/grasscutter/game/inventory/MaterialInventoryTab.java @@ -2,6 +2,7 @@ package emu.grasscutter.game.inventory; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import lombok.val; public class MaterialInventoryTab implements InventoryTab { private final Int2ObjectMap items; @@ -36,4 +37,10 @@ public class MaterialInventoryTab implements InventoryTab { public int getMaxCapacity() { return this.maxCapacity; } + + @Override + public int getItemCountById(int itemId) { + val item = getItemById(itemId); + return item != null ? item.getCount() : 0; + } } diff --git a/src/main/java/emu/grasscutter/game/quest/GameQuest.java b/src/main/java/emu/grasscutter/game/quest/GameQuest.java index 904a7b404..b69367c3d 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameQuest.java @@ -172,6 +172,8 @@ public class GameQuest { this.failProgressList = new int[questData.getFailCond().size()]; } + this.getMainQuest().getTalks().values().removeIf(talk -> talk.getId() == this.getSubQuestId()); + this.getOwner().getPlayerProgress().resetCurrentProgress(String.valueOf(this.subQuestId)); setState(QuestState.QUEST_STATE_UNSTARTED); diff --git a/src/main/java/emu/grasscutter/game/quest/QuestManager.java b/src/main/java/emu/grasscutter/game/quest/QuestManager.java index 572731edb..968e06fcb 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestManager.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestManager.java @@ -279,7 +279,7 @@ public class QuestManager extends BasePlayerManager { } public GameMainQuest getMainQuestByTalkId(int talkId) { - int mainQuestId = GameData.getQuestTalkMap().getOrDefault(talkId, talkId / 100); + var mainQuestId = GameData.getQuestTalkMap().getOrDefault(talkId, 0); return getMainQuestById(mainQuestId); } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionCompleteTalk.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionCompleteTalk.java index 1a4f5df6f..c9c03ad31 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionCompleteTalk.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionCompleteTalk.java @@ -2,8 +2,6 @@ package emu.grasscutter.game.quest.conditions; import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_COMPLETE_TALK; -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.quest.QuestData; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.quest.QuestValueCond; @@ -20,16 +18,12 @@ public class ConditionCompleteTalk extends BaseCondition { String paramStr, int... params) { val talkId = condition.getParam()[0]; - val unknownParam = condition.getParam()[1]; // e.g. 3 for 7081601 val checkMainQuest = owner.getQuestManager().getMainQuestByTalkId(talkId); - if (checkMainQuest == null - || GameData.getMainQuestDataMap().get(checkMainQuest.getParentQuestId()).getTalks() - == null) { - Grasscutter.getLogger() - .debug("Warning: mainQuest {} hasn't been started yet, or has no talks", talkId / 100); - return false; + if (checkMainQuest == null) { + return talkId == params[0]; } + val talkData = checkMainQuest.getTalks().get(talkId); - return talkData != null || checkMainQuest.getChildQuestById(talkId) != null; + return talkData != null; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionItemNumLessThan.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionItemNumLessThan.java index 57eb1e8a6..8ea52cf76 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionItemNumLessThan.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionItemNumLessThan.java @@ -18,8 +18,8 @@ public class ConditionItemNumLessThan extends BaseCondition { String paramStr, int... params) { val itemId = condition.getParam()[0]; - val amount = condition.getParam()[1]; - val checkItem = owner.getInventory().getItemByGuid(itemId); - return checkItem == null || checkItem.getCount() < amount; + val targetAmount = condition.getParam()[1]; + val amount = owner.getInventory().getItemCountById(itemId); + return amount < targetAmount; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPackHaveItem.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPackHaveItem.java index 3719577b8..14bf7c662 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPackHaveItem.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPackHaveItem.java @@ -18,8 +18,11 @@ public class ConditionPackHaveItem extends BaseCondition { String paramStr, int... params) { val itemId = condition.getParam()[0]; - val targetAmount = condition.getParam()[1]; - val checkItem = owner.getInventory().getItemByGuid(itemId); - return checkItem != null && checkItem.getCount() >= targetAmount; + var targetAmount = condition.getParam()[1]; + if (targetAmount == 0) { + targetAmount = 1; + } + val amount = owner.getInventory().getItemCountById(itemId); + return amount >= targetAmount; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentAddQuestProgress.java b/src/main/java/emu/grasscutter/game/quest/content/ContentAddQuestProgress.java index cdf1ff0f5..3dc6ff573 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentAddQuestProgress.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentAddQuestProgress.java @@ -17,8 +17,12 @@ public class ContentAddQuestProgress extends BaseContent { val currentCount = quest.getOwner().getPlayerProgress().getCurrentProgress(String.valueOf(progressId)); + var targetAmount = condition.getCount(); + if (targetAmount == 0) { + targetAmount = 1; + } // if the condition count is 0 I think it is safe to assume that the // condition count from EXEC only needs to be 1 - return currentCount >= condition.getCount(); + return currentCount >= targetAmount; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteAnyTalk.java b/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteAnyTalk.java index b76c144e7..19a2a3f0d 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteAnyTalk.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteAnyTalk.java @@ -2,11 +2,10 @@ package emu.grasscutter.game.quest.content; import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_ANY_TALK; -import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.quest.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; -import java.util.stream.Stream; +import emu.grasscutter.game.quest.*; +import lombok.val; +import java.util.Arrays; @QuestValueContent(QUEST_CONTENT_COMPLETE_ANY_TALK) public class ContentCompleteAnyTalk extends BaseContent { @@ -14,10 +13,22 @@ public class ContentCompleteAnyTalk extends BaseContent { @Override public boolean execute( GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return Stream.of(condition.getParamStr().split(",")) + var conditionTalk = Arrays.stream(condition.getParamStr().split(",")) .mapToInt(Integer::parseInt) - .anyMatch( - talkId -> - GameData.getTalkConfigDataMap().get(params[0]) != null && talkId == params[0]); + .toArray(); + + for (var talkId : conditionTalk) { + val checkMainQuest = quest.getOwner().getQuestManager().getMainQuestByTalkId(talkId); + if (checkMainQuest == null) { + if (talkId == params[0]) return true; + continue; + } + + val talkData = checkMainQuest.getTalks().get(talkId); + if (talkData != null) { + return true; + } + } + return false; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteTalk.java b/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteTalk.java index 5378d4ba3..b93dffc81 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteTalk.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteTalk.java @@ -12,10 +12,9 @@ public class ContentCompleteTalk extends BaseContent { public boolean execute( GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { val talkId = condition.getParam()[0]; - if (talkId != params[0]) return false; val checkMainQuest = quest.getOwner().getQuestManager().getMainQuestByTalkId(talkId); if (checkMainQuest == null) { - return false; + return talkId == params[0]; } val talkData = checkMainQuest.getTalks().get(talkId); diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentItemLessThan.java b/src/main/java/emu/grasscutter/game/quest/content/ContentItemLessThan.java index 0bf79f4e8..43fb1d89c 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentItemLessThan.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentItemLessThan.java @@ -5,12 +5,16 @@ import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ITEM_L import emu.grasscutter.data.excels.quest.QuestData; import emu.grasscutter.game.quest.GameQuest; import emu.grasscutter.game.quest.QuestValueContent; +import lombok.val; @QuestValueContent(QUEST_CONTENT_ITEM_LESS_THAN) public class ContentItemLessThan extends BaseContent { @Override public boolean execute( GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0] && condition.getCount() > params[1]; + val itemId = condition.getParam()[0]; + val targetAmount = condition.getParam()[1]; + val amount = quest.getOwner().getInventory().getItemCountById(itemId); + return amount < targetAmount; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentLuaNotify.java b/src/main/java/emu/grasscutter/game/quest/content/ContentLuaNotify.java index 47d65bcd8..bb3f1b14c 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentLuaNotify.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentLuaNotify.java @@ -12,8 +12,10 @@ public class ContentLuaNotify extends BaseContent { @Override public boolean execute( GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParamStr().equals(paramStr) - && condition.getCount() - <= quest.getOwner().getPlayerProgress().getCurrentProgress(paramStr); + var targetAmount = condition.getCount(); + if (targetAmount == 0) { + targetAmount = 1; + } + return targetAmount <= quest.getOwner().getPlayerProgress().getCurrentProgress(condition.getParamStr()); } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentObtainItem.java b/src/main/java/emu/grasscutter/game/quest/content/ContentObtainItem.java index ecf5bf858..f2e3bef1d 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentObtainItem.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentObtainItem.java @@ -5,16 +5,19 @@ import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_OBTAIN import emu.grasscutter.data.excels.quest.QuestData; import emu.grasscutter.game.quest.GameQuest; import emu.grasscutter.game.quest.QuestValueContent; +import lombok.val; @QuestValueContent(QUEST_CONTENT_OBTAIN_ITEM) public class ContentObtainItem extends BaseContent { @Override public boolean execute( GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - var targetCount = condition.getCount(); - if (targetCount == 0) { - targetCount = 1; + val itemId = condition.getParam()[0]; + var targetAmount = condition.getCount(); + if (targetAmount == 0) { + targetAmount = 1; } - return condition.getParam()[0] == params[0] && targetCount <= params[1]; + val amount = quest.getOwner().getInventory().getItemCountById(itemId); + return amount >= targetAmount; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentTriggerFire.java b/src/main/java/emu/grasscutter/game/quest/content/ContentTriggerFire.java index be3992001..2a1256161 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentTriggerFire.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentTriggerFire.java @@ -2,23 +2,18 @@ package emu.grasscutter.game.quest.content; import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_TRIGGER_FIRE; -import emu.grasscutter.Grasscutter; import emu.grasscutter.data.excels.quest.QuestData; import emu.grasscutter.game.quest.GameQuest; import emu.grasscutter.game.quest.QuestValueContent; +import lombok.val; @QuestValueContent(QUEST_CONTENT_TRIGGER_FIRE) public class ContentTriggerFire extends BaseContent { @Override public boolean execute( GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - if (quest.getTriggers().containsKey(quest.getTriggerNameById(params[0]))) { - // We don't want to put a new key here - return quest.getTriggers().get(quest.getTriggerNameById(params[0])); - } else { - Grasscutter.getLogger() - .debug("Quest {} doesn't have trigger {} registered.", quest.getSubQuestId(), params[0]); - return false; - } + val triggerId = condition.getParam()[0]; + val triggerName = quest.getTriggerNameById(triggerId); + return quest.getTriggers().getOrDefault(triggerName, false); } }