From daa51e53b72c1ba44fd71ba6904e282e3260d222 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sat, 1 Apr 2023 18:06:30 -0400 Subject: [PATCH] Copy some files from `Grasscutter-Quests` NOT completely finished, nor is it completely done. Protocol issues remain! (including lack of packet IDs) --- .../command/commands/AchievementCommand.java | 4 +- .../command/commands/EntityCommand.java | 276 +++--- .../command/commands/GiveCommand.java | 6 +- .../command/commands/GroupCommand.java | 144 +-- .../command/commands/SpawnCommand.java | 2 +- .../command/commands/TalentCommand.java | 2 +- .../commands/TrialAvatarActivityCommand.java | 281 +++--- .../java/emu/grasscutter/data/GameData.java | 181 +++- .../java/emu/grasscutter/data/GameDepot.java | 4 +- .../emu/grasscutter/data/ResourceLoader.java | 76 +- .../binout/config/ConfigEntityAvatar.java | 7 +- .../data/binout/config/ConfigEntityBase.java | 38 +- .../binout/config/ConfigEntityGadget.java | 22 +- .../binout/config/ConfigEntityMonster.java | 13 +- .../data/binout/config/ConfigLevelEntity.java | 27 +- .../config/fields/ConfigAbilityData.java | 20 +- .../binout/config/fields/ConfigAiBeta.java | 16 +- .../binout/config/fields/ConfigCombat.java | 24 +- .../binout/config/fields/ConfigCombatDie.java | 33 +- .../config/fields/ConfigCombatProperty.java | 36 +- .../binout/config/fields/ConfigCommon.java | 13 +- .../config/fields/ConfigGlobalValue.java | 27 +- .../data/binout/routes/RotAngleType.java | 45 +- .../data/binout/routes/RotType.java | 14 +- .../grasscutter/data/binout/routes/Route.java | 60 +- .../data/binout/routes/RoutePoint.java | 65 +- .../data/binout/routes/RouteType.java | 45 +- .../data/binout/routes/SceneRoutes.java | 28 +- .../data/common/BaseTrialActivityData.java | 17 +- .../grasscutter/data/common/PointData.java | 2 +- .../custom/TrialAvatarActivityCustomData.java | 34 +- .../data/custom/TrialAvatarCustomData.java | 32 +- .../grasscutter/data/excels/DungeonData.java | 33 - .../data/excels/GuideTriggerData.java | 53 +- .../grasscutter/data/excels/QuestData.java | 183 ++-- .../excels/RefreshPolicyExcelConfigData.java | 166 ++-- .../grasscutter/data/excels/SceneData.java | 3 + .../{ => achievement}/AchievementData.java | 3 +- .../AchievementGoalData.java | 26 +- .../ActivityCondExcelConfigData.java | 79 +- .../excels/{ => activity}/ActivityData.java | 2 +- .../{ => activity}/ActivityShopData.java | 2 +- .../{ => activity}/ActivityWatcherData.java | 14 +- .../{ => avatar}/AvatarCostumeData.java | 2 +- .../excels/{ => avatar}/AvatarCurveData.java | 2 +- .../data/excels/{ => avatar}/AvatarData.java | 16 +- .../{ => avatar}/AvatarFetterLevelData.java | 2 +- .../{ => avatar}/AvatarFlycloakData.java | 2 +- .../excels/{ => avatar}/AvatarLevelData.java | 2 +- .../{ => avatar}/AvatarPromoteData.java | 2 +- .../AvatarReplaceCostumeData.java | 46 +- .../excels/{ => avatar}/AvatarSkillData.java | 2 +- .../{ => avatar}/AvatarSkillDepotData.java | 2 +- .../excels/{ => avatar}/AvatarTalentData.java | 2 +- .../excels/{ => codex}/CodexAnimalData.java | 2 +- .../excels/{ => codex}/CodexMaterialData.java | 58 +- .../excels/{ => codex}/CodexQuestData.java | 2 +- .../{ => codex}/CodexReliquaryData.java | 2 +- .../excels/{ => codex}/CodexWeaponData.java | 58 +- .../{ => dungeon}/DailyDungeonData.java | 2 +- .../DungeonChallengeConfigData.java | 154 +-- .../data/excels/dungeon/DungeonData.java | 71 ++ .../{ => dungeon}/DungeonEntryData.java | 2 +- .../{ => dungeon}/DungeonPassConfigData.java | 54 +- .../{ => monster}/MonsterCurveData.java | 2 +- .../excels/{ => monster}/MonsterData.java | 3 +- .../{ => monster}/MonsterDescribeData.java | 2 +- .../{ => monster}/MonsterSpecialNameData.java | 42 +- .../{ => reliquary}/ReliquaryAffixData.java | 2 +- .../{ => reliquary}/ReliquaryLevelData.java | 2 +- .../ReliquaryMainPropData.java | 2 +- .../{ => reliquary}/ReliquarySetData.java | 2 +- .../excels/{ => tower}/TowerFloorData.java | 42 +- .../excels/{ => tower}/TowerLevelData.java | 2 +- .../excels/{ => tower}/TowerScheduleData.java | 2 +- .../{ => trial}/TrialAvatarActivityData.java | 42 +- .../TrialAvatarActivityDataData.java | 60 +- .../excels/{ => trial}/TrialAvatarData.java | 38 +- .../{ => trial}/TrialAvatarTemplateData.java | 40 +- .../{ => trial}/TrialReliquaryData.java | 44 +- .../excels/{ => weapon}/WeaponCurveData.java | 2 +- .../excels/{ => weapon}/WeaponLevelData.java | 2 +- .../{ => weapon}/WeaponPromoteData.java | 2 +- .../data/excels/{ => world}/WeatherData.java | 2 +- .../excels/{ => world}/WorldAreaData.java | 2 +- .../excels/{ => world}/WorldLevelData.java | 2 +- .../data/server/ActivityCondGroup.java | 21 +- .../data/server/GadgetMapping.java | 18 +- .../emu/grasscutter/data/server/Grid.java | 68 +- .../game/ability/AbilityManager.java | 18 + .../game/achievement/Achievements.java | 2 +- .../game/activity/ActivityConfigItem.java | 12 + .../game/activity/ActivityHandler.java | 51 +- .../game/activity/ActivityManager.java | 122 ++- .../game/activity/ActivityWatcher.java | 2 +- .../game/activity/PlayerActivityData.java | 2 +- .../activity/condition/ActivityCondition.java | 33 +- .../ActivityConditionBaseHandler.java | 44 +- .../condition/ActivityConditionExecutor.java | 20 +- .../condition/ActivityConditions.java | 102 +- .../AllActivityConditionBuilder.java | 123 +-- .../BasicActivityConditionExecutor.java | 146 +-- .../PlayerActivityDataMappingBuilder.java | 161 +-- .../game/activity/condition/all/DayLess.java | 33 +- .../condition/all/DaysGreatEqual.java | 42 +- .../activity/condition/all/FinishWatcher.java | 49 +- .../activity/condition/all/NotFinishTalk.java | 43 +- ...elGreatEqualActivityActivityCondition.java | 35 +- .../activity/condition/all/QuestFinished.java | 44 +- .../condition/all/SalesmanCanDeliver.java | 39 +- .../all/UnknownActivityConditionHandler.java | 35 +- .../TrialAvatarActivityChallengeTrigger.java | 71 +- .../TrialAvatarActivityHandler.java | 308 +++--- .../trialavatar/TrialAvatarPlayerData.java | 180 ++-- .../emu/grasscutter/game/avatar/Avatar.java | 232 ++++- .../game/avatar/AvatarStorage.java | 4 +- .../dungeons/BasicDungeonSettleListener.java | 28 +- .../game/dungeons/DungeonEndStats.java | 40 +- .../game/dungeons/DungeonManager.java | 647 ++++++------ .../game/dungeons/DungeonSettleListener.java | 14 +- .../game/dungeons/DungeonSystem.java | 41 +- .../game/dungeons/DungeonTrialTeam.java | 27 +- .../game/dungeons/DungeonValue.java | 21 +- .../dungeons/challenge/DungeonChallenge.java | 268 ++--- .../challenge/enums/ChallengeCondType.java | 38 +- .../enums/ChallengeEventMarkType.java | 18 +- .../challenge/enums/ChallengeRecordType.java | 12 +- .../challenge/enums/ChallengeType.java | 54 +- .../enums/FatherChallengeProperty.java | 18 +- .../KillAndGuardChallengeFactoryHandler.java | 76 +- ...llMonsterCountChallengeFactoryHandler.java | 71 +- ...lMonsterInTimeChallengeFactoryHandler.java | 73 +- ...illMonsterTimeChallengeFactoryHandler.java | 77 +- .../SurviveChallengeFactoryHandler.java | 73 +- .../TriggerInTimeChallengeFactoryHandler.java | 79 +- .../challenge/trigger/ForTimeTrigger.java | 26 +- .../trigger/KillMonsterCountTrigger.java | 47 +- .../trigger/TriggerGroupTriggerTrigger.java | 61 +- .../dungeon_results/BaseDungeonResult.java | 151 +-- .../dungeons/dungeon_results/TowerResult.java | 104 +- .../TrialAvatarDungeonResult.java | 49 +- .../DungeonEntrySatisfiedConditionType.java | 14 +- .../dungeons/enums/DungeonInvolveType.java | 14 +- .../enums/DungeonPassConditionType.java | 55 +- .../game/dungeons/enums/DungeonPlayType.java | 15 +- .../game/dungeons/enums/DungeonSubType.java | 18 +- .../game/dungeons/enums/DungeonType.java | 98 +- .../game/dungeons/enums/DungunEntryType.java | 24 +- .../game/dungeons/enums/SettleShowType.java | 34 +- .../dungeons/handlers/DungeonBaseHandler.java | 18 +- .../pass_condition/BaseCondition.java | 33 +- .../ConditionFinishChallenge.java | 30 +- .../pass_condition/ConditionFinishQuest.java | 30 +- .../pass_condition/ConditionInTime.java | 30 +- .../ConditionKillGroupMonster.java | 30 +- .../pass_condition/ConditionKillMonster.java | 30 +- .../ConditionKillMonsterCount.java | 30 +- .../ConditionKillTypeMonster.java | 30 +- .../grasscutter/game/entity/EntityAvatar.java | 4 +- .../game/entity/EntityMonster.java | 4 +- .../game/entity/gadget/GadgetAbility.java | 76 +- .../entity/gadget/platform/AbilityRoute.java | 56 +- .../entity/gadget/platform/BaseRoute.java | 167 ++-- .../entity/gadget/platform/ConfigRoute.java | 61 +- .../gadget/platform/PointArrayRoute.java | 64 +- .../grasscutter/game/inventory/GameItem.java | 4 +- .../managers/blossom/BlossomActivity.java | 4 +- .../game/managers/energy/EnergyManager.java | 4 +- .../emu/grasscutter/game/player/Player.java | 357 +++---- .../game/player/PlayerBuffManager.java | 32 +- .../grasscutter/game/player/PlayerCodex.java | 2 +- .../game/player/PlayerProgress.java | 123 ++- .../game/player/PlayerProgressManager.java | 3 +- .../grasscutter/game/player/TeamManager.java | 379 ++++++- .../grasscutter/game/props/ActivityType.java | 12 +- .../props/ItemUseAction/ItemUseAddEnergy.java | 2 +- .../grasscutter/game/props/RefreshType.java | 87 +- .../grasscutter/game/quest/GameMainQuest.java | 933 +++++++++--------- .../emu/grasscutter/game/quest/GameQuest.java | 170 ++-- .../game/quest/QuestEncryptionKey.java | 24 +- .../game/quest/QuestGroupSuite.java | 34 +- .../grasscutter/game/quest/QuestManager.java | 265 +++-- .../grasscutter/game/quest/QuestSystem.java | 72 +- .../game/quest/QuestValueCond.java | 21 +- .../game/quest/QuestValueContent.java | 21 +- .../game/quest/QuestValueExec.java | 21 +- .../grasscutter/game/quest/RewindData.java | 2 +- .../grasscutter/game/quest/TeleportData.java | 70 +- .../game/quest/conditions/BaseCondition.java | 22 +- .../conditions/BaseConditionQuestVar.java | 89 +- .../conditions/ConditionActivityCond.java | 44 +- .../conditions/ConditionActivityEnd.java | 42 +- .../conditions/ConditionActivityOpen.java | 42 +- .../conditions/ConditionCompleteTalk.java | 34 +- .../ConditionHistoryGotAnyItem.java | 40 +- .../quest/conditions/ConditionIsDaytime.java | 44 +- .../conditions/ConditionItemNumLessThan.java | 46 +- .../quest/conditions/ConditionLuaNotify.java | 27 +- .../game/quest/conditions/ConditionNone.java | 36 +- .../conditions/ConditionOpenStateEqual.java | 42 +- .../conditions/ConditionPackHaveItem.java | 46 +- .../ConditionPersonalLineUnlock.java | 40 +- .../ConditionPlayerLevelEqualGreater.java | 24 +- .../ConditionQuestGlobalVarEqual.java | 29 +- .../ConditionQuestGlobalVarGreater.java | 29 +- .../ConditionQuestGlobalVarLess.java | 29 +- .../conditions/ConditionQuestVarEqual.java | 20 +- .../conditions/ConditionQuestVarGreater.java | 20 +- .../conditions/ConditionQuestVarLess.java | 20 +- .../quest/conditions/ConditionStateEqual.java | 32 +- .../conditions/ConditionStateNotEqual.java | 33 +- .../ConditionTimeVarGreaterOrEqual.java | 55 +- .../conditions/ConditionTimeVarPassDay.java | 65 +- .../game/quest/content/BaseContent.java | 12 +- .../content/ContentAddQuestProgress.java | 45 +- .../content/ContentAnyManualTransport.java | 31 +- .../content/ContentClearGroupMonster.java | 39 +- .../quest/content/ContentCompleteAnyTalk.java | 44 +- .../quest/content/ContentCompleteTalk.java | 29 +- .../quest/content/ContentDestroyGadget.java | 31 +- .../quest/content/ContentEnterDungeon.java | 16 +- .../quest/content/ContentEnterMyWorld.java | 34 +- .../content/ContentEnterMyWorldScene.java | 34 +- .../game/quest/content/ContentEnterRoom.java | 16 +- .../quest/content/ContentEnterVehicle.java | 31 +- .../quest/content/ContentFailDungeon.java | 36 +- .../quest/content/ContentFinishDungeon.java | 36 +- .../game/quest/content/ContentFinishPlot.java | 21 +- .../quest/content/ContentGameTimeTick.java | 42 +- .../quest/content/ContentInteractGadget.java | 16 +- .../quest/content/ContentItemLessThan.java | 31 +- .../quest/content/ContentKillMonster.java | 31 +- .../game/quest/content/ContentLeaveScene.java | 16 +- .../game/quest/content/ContentLuaNotify.java | 16 +- .../game/quest/content/ContentMonsterDie.java | 31 +- .../quest/content/ContentNotFinishPlot.java | 27 +- .../game/quest/content/ContentObtainItem.java | 39 +- .../quest/content/ContentPlayerLevelUp.java | 31 +- .../quest/content/ContentQuestStateEqual.java | 16 +- .../content/ContentQuestStateNotEqual.java | 12 +- .../quest/content/ContentQuestVarEqual.java | 12 +- .../quest/content/ContentQuestVarGreater.java | 12 +- .../quest/content/ContentQuestVarLess.java | 12 +- .../game/quest/content/ContentSkill.java | 11 +- .../content/ContentTimeVarMoreOrEqual.java | 51 +- .../quest/content/ContentTimeVarPassDay.java | 61 +- .../quest/content/ContentTriggerFire.java | 12 +- .../game/quest/content/ContentUnlockArea.java | 31 +- .../content/ContentUnlockTransPoint.java | 12 +- .../game/quest/content/ContentUseItem.java | 31 +- .../quest/content/ContentWorktopSelect.java | 31 +- .../game/quest/enums/LogicType.java | 53 + .../game/quest/enums/QuestCond.java | 241 +++-- .../game/quest/enums/QuestContent.java | 233 +++-- .../game/quest/enums/QuestExec.java | 226 ++--- .../game/quest/enums/QuestState.java | 4 +- .../game/quest/enums/QuestTrigger.java | 261 +---- .../quest/exec/ExecAddCurAvatarEnergy.java | 34 +- .../game/quest/exec/ExecAddQuestProgress.java | 11 +- .../quest/exec/ExecChangeAvatarElemet.java | 65 +- .../game/quest/exec/ExecClearTimeVar.java | 38 +- .../quest/exec/ExecDecQuestGlobalVar.java | 6 +- .../game/quest/exec/ExecDecQuestVar.java | 32 +- .../game/quest/exec/ExecDelPackItem.java | 34 +- .../game/quest/exec/ExecDelPackItemBatch.java | 52 +- .../game/quest/exec/ExecGrantTrialAvatar.java | 48 +- .../quest/exec/ExecIncQuestGlobalVar.java | 6 +- .../game/quest/exec/ExecIncQuestVar.java | 32 +- .../game/quest/exec/ExecInitTimeVar.java | 36 +- .../game/quest/exec/ExecNotifyGroupLua.java | 52 +- .../quest/exec/ExecRefreshGroupMonster.java | 37 +- .../quest/exec/ExecRefreshGroupSuite.java | 35 +- .../quest/exec/ExecRegisterDynamicGroup.java | 77 +- .../quest/exec/ExecRemoveTrialAvatar.java | 44 +- .../quest/exec/ExecRollbackParentQuest.java | 48 +- .../game/quest/exec/ExecRollbackQuest.java | 52 +- .../game/quest/exec/ExecSetOpenState.java | 45 +- .../quest/exec/ExecSetQuestGlobalVar.java | 6 +- .../game/quest/exec/ExecSetQuestVar.java | 32 +- .../game/quest/exec/ExecUnlockArea.java | 6 +- .../game/quest/exec/ExecUnlockPoint.java | 44 +- .../exec/ExecUnregisterDynamicGroup.java | 74 +- .../game/quest/handlers/QuestBaseHandler.java | 5 +- .../game/systems/InventorySystem.java | 6 +- .../grasscutter/game/tower/TowerManager.java | 36 +- .../grasscutter/game/tower/TowerSystem.java | 2 +- .../game/world/GroupReplacementData.java | 20 +- .../emu/grasscutter/game/world/Scene.java | 84 +- .../game/world/SceneGroupInstance.java | 171 ++-- .../emu/grasscutter/game/world/World.java | 283 ++++-- .../game/world/WorldDataSystem.java | 2 +- .../game/world/data/TeleportProperties.java | 38 +- .../EntityControllerScriptManager.java | 107 +- .../scripts/SceneScriptManager.java | 4 +- .../emu/grasscutter/scripts/ScriptLib.java | 2 +- .../scripts/constants/GroupKillPolicy.java | 18 +- .../scripts/constants/IntValueEnum.java | 10 +- .../scripts/constants/SealBattleType.java | 14 +- .../grasscutter/scripts/data/SceneGadget.java | 9 +- .../scripts/data/SceneReplaceable.java | 24 +- .../data/controller/EntityController.java | 171 ++-- .../event/player/PlayerTeleportEvent.java | 23 +- .../documentation/HandbookRequestHandler.java | 4 +- .../packet/recv/HandlerAddCustomTeamReq.java | 28 +- .../HandlerAvatarChangeElementTypeReq.java | 4 +- .../packet/recv/HandlerChangeGameTimeReq.java | 12 +- .../packet/recv/HandlerChangeHomeBgmReq.java | 52 +- .../packet/recv/HandlerCheckUgcStateReq.java | 44 +- .../packet/recv/HandlerCheckUgcUpdateReq.java | 39 +- .../recv/HandlerDungeonPlayerDieReq.java | 53 +- ...dlerDungeonSlipRevivePointActivateReq.java | 51 +- .../HandlerDungeonWayPointActivateReq.java | 51 +- ...lerEnterTrialAvatarActivityDungeonReq.java | 73 +- .../recv/HandlerEvtDoSkillSuccNotify.java | 57 +- .../recv/HandlerExecuteGadgetLuaReq.java | 59 +- .../packet/recv/HandlerFireWorkReq.java | 41 +- .../packet/recv/HandlerFireworkSetReq.java | 44 +- .../packet/recv/HandlerGadgetInteractReq.java | 3 +- .../recv/HandlerGetUgcBriefInfoReq.java | 66 +- .../server/packet/recv/HandlerGetUgcReq.java | 87 +- .../packet/recv/HandlerHomeUnknown2Req.java | 39 +- .../server/packet/recv/HandlerNpcTalkReq.java | 7 +- .../packet/recv/HandlerPostEnterSceneReq.java | 3 +- .../recv/HandlerQuestCreateEntityReq.java | 125 ++- .../recv/HandlerQuestDestroyEntityReq.java | 53 +- .../recv/HandlerQuestDestroyNpcReq.java | 39 +- .../packet/recv/HandlerQuestTransmitReq.java | 73 +- ...rReceivedTrialAvatarActivityRewardReq.java | 69 +- .../recv/HandlerRemoveCustomTeamReq.java | 32 +- .../server/packet/recv/HandlerSaveUgcReq.java | 181 ++-- .../packet/send/PacketAddCustomTeamRsp.java | 42 +- .../PacketAddNoGachaAvatarCardNotify.java | 81 +- .../packet/send/PacketAvatarDelNotify.java | 38 +- .../send/PacketAvatarTeamUpdateNotify.java | 7 + .../PacketBeginCameraSceneLookNotify.java | 123 +-- .../send/PacketChangeHomeBgmNotify.java | 35 +- .../packet/send/PacketChangeHomeBgmRsp.java | 35 +- .../packet/send/PacketCheckUgcStateRsp.java | 33 +- .../packet/send/PacketCheckUgcUpdateRsp.java | 38 +- .../send/PacketCloseCommonTipsNotify.java | 26 +- .../send/PacketCustomTeamListNotify.java | 55 +- .../send/PacketCutsceneBeginNotify.java | 30 +- .../packet/send/PacketDelQuestNotify.java | 37 +- .../send/PacketDungeonPlayerDieNotify.java | 57 +- .../send/PacketDungeonPlayerDieRsp.java | 37 +- ...cketDungeonSlipRevivePointActivateRsp.java | 36 +- .../PacketDungeonWayPointActivateRsp.java | 36 +- .../send/PacketDungeonWayPointNotify.java | 36 +- .../send/PacketEndCameraSceneLookNotify.java | 28 +- ...ketEnterTrialAvatarActivityDungeonRsp.java | 49 +- .../send/PacketExecuteGadgetLuaRsp.java | 35 +- .../packet/send/PacketFireworkNotify.java | 40 +- .../server/packet/send/PacketFireworkRsp.java | 23 +- .../packet/send/PacketFireworkSetNotify.java | 40 +- .../packet/send/PacketFireworkSetRsp.java | 24 +- .../PacketGetDailyDungeonEntryInfoRsp.java | 2 +- .../packet/send/PacketGetUgcBriefInfoRsp.java | 66 +- .../server/packet/send/PacketGetUgcRsp.java | 81 +- .../packet/send/PacketHomeUnknown1Notify.java | 36 +- .../packet/send/PacketHomeUnknown2Rsp.java | 23 +- .../send/PacketPlatformChangeRouteNotify.java | 46 +- .../send/PacketPlayerEnterSceneNotify.java | 42 +- .../send/PacketQuestCreateEntityRsp.java | 46 +- .../send/PacketQuestDestroyEntityRsp.java | 42 +- .../packet/send/PacketQuestDestroyNpcRsp.java | 41 +- .../packet/send/PacketQuestTransmitRsp.java | 37 +- ...tReceivedTrialAvatarActivityRewardRsp.java | 46 +- .../send/PacketRemoveCustomTeamRsp.java | 44 +- .../send/PacketSceneForceLockNotify.java | 48 +- .../send/PacketSceneForceUnlockNotify.java | 55 +- .../send/PacketScenePlayerSoundNotify.java | 63 +- .../packet/send/PacketSceneTimeNotify.java | 16 +- .../send/PacketShowClientGuideNotify.java | 33 +- .../send/PacketShowCommonTipsNotify.java | 35 +- .../send/PacketUnlockHomeBgmNotify.java | 35 +- .../send/PacketUnlockedHomeBgmNotify.java | 49 +- .../java/emu/grasscutter/tools/Tools.java | 4 +- .../grasscutter/utils/ConversionUtils.java | 24 + .../emu/grasscutter/utils/GridPosition.java | 231 +++-- .../java/emu/grasscutter/utils/KahnsSort.java | 134 +-- .../java/emu/grasscutter/utils/Language.java | 2 +- 381 files changed, 10285 insertions(+), 9150 deletions(-) delete mode 100644 src/main/java/emu/grasscutter/data/excels/DungeonData.java rename src/main/java/emu/grasscutter/data/excels/{ => achievement}/AchievementData.java (93%) rename src/main/java/emu/grasscutter/data/excels/{ => achievement}/AchievementGoalData.java (83%) rename src/main/java/emu/grasscutter/data/excels/{ => activity}/ActivityCondExcelConfigData.java (83%) rename src/main/java/emu/grasscutter/data/excels/{ => activity}/ActivityData.java (92%) rename src/main/java/emu/grasscutter/data/excels/{ => activity}/ActivityShopData.java (90%) rename src/main/java/emu/grasscutter/data/excels/{ => activity}/ActivityWatcherData.java (59%) rename src/main/java/emu/grasscutter/data/excels/{ => avatar}/AvatarCostumeData.java (91%) rename src/main/java/emu/grasscutter/data/excels/{ => avatar}/AvatarCurveData.java (91%) rename src/main/java/emu/grasscutter/data/excels/{ => avatar}/AvatarData.java (94%) rename src/main/java/emu/grasscutter/data/excels/{ => avatar}/AvatarFetterLevelData.java (87%) rename src/main/java/emu/grasscutter/data/excels/{ => avatar}/AvatarFlycloakData.java (87%) rename src/main/java/emu/grasscutter/data/excels/{ => avatar}/AvatarLevelData.java (86%) rename src/main/java/emu/grasscutter/data/excels/{ => avatar}/AvatarPromoteData.java (94%) rename src/main/java/emu/grasscutter/data/excels/{ => avatar}/AvatarReplaceCostumeData.java (63%) rename src/main/java/emu/grasscutter/data/excels/{ => avatar}/AvatarSkillData.java (91%) rename src/main/java/emu/grasscutter/data/excels/{ => avatar}/AvatarSkillDepotData.java (96%) rename src/main/java/emu/grasscutter/data/excels/{ => avatar}/AvatarTalentData.java (93%) rename src/main/java/emu/grasscutter/data/excels/{ => codex}/CodexAnimalData.java (90%) rename src/main/java/emu/grasscutter/data/excels/{ => codex}/CodexMaterialData.java (89%) rename src/main/java/emu/grasscutter/data/excels/{ => codex}/CodexQuestData.java (91%) rename src/main/java/emu/grasscutter/data/excels/{ => codex}/CodexReliquaryData.java (94%) rename src/main/java/emu/grasscutter/data/excels/{ => codex}/CodexWeaponData.java (89%) rename src/main/java/emu/grasscutter/data/excels/{ => dungeon}/DailyDungeonData.java (93%) rename src/main/java/emu/grasscutter/data/excels/{ => dungeon}/DungeonChallengeConfigData.java (70%) create mode 100644 src/main/java/emu/grasscutter/data/excels/dungeon/DungeonData.java rename src/main/java/emu/grasscutter/data/excels/{ => dungeon}/DungeonEntryData.java (86%) rename src/main/java/emu/grasscutter/data/excels/{ => dungeon}/DungeonPassConfigData.java (79%) rename src/main/java/emu/grasscutter/data/excels/{ => monster}/MonsterCurveData.java (91%) rename src/main/java/emu/grasscutter/data/excels/{ => monster}/MonsterData.java (94%) rename src/main/java/emu/grasscutter/data/excels/{ => monster}/MonsterDescribeData.java (88%) rename src/main/java/emu/grasscutter/data/excels/{ => monster}/MonsterSpecialNameData.java (83%) rename src/main/java/emu/grasscutter/data/excels/{ => reliquary}/ReliquaryAffixData.java (89%) rename src/main/java/emu/grasscutter/data/excels/{ => reliquary}/ReliquaryLevelData.java (93%) rename src/main/java/emu/grasscutter/data/excels/{ => reliquary}/ReliquaryMainPropData.java (88%) rename src/main/java/emu/grasscutter/data/excels/{ => reliquary}/ReliquarySetData.java (89%) rename src/main/java/emu/grasscutter/data/excels/{ => tower}/TowerFloorData.java (88%) rename src/main/java/emu/grasscutter/data/excels/{ => tower}/TowerLevelData.java (89%) rename src/main/java/emu/grasscutter/data/excels/{ => tower}/TowerScheduleData.java (92%) rename src/main/java/emu/grasscutter/data/excels/{ => trial}/TrialAvatarActivityData.java (83%) rename src/main/java/emu/grasscutter/data/excels/{ => trial}/TrialAvatarActivityDataData.java (79%) rename src/main/java/emu/grasscutter/data/excels/{ => trial}/TrialAvatarData.java (79%) rename src/main/java/emu/grasscutter/data/excels/{ => trial}/TrialAvatarTemplateData.java (81%) rename src/main/java/emu/grasscutter/data/excels/{ => trial}/TrialReliquaryData.java (81%) rename src/main/java/emu/grasscutter/data/excels/{ => weapon}/WeaponCurveData.java (91%) rename src/main/java/emu/grasscutter/data/excels/{ => weapon}/WeaponLevelData.java (87%) rename src/main/java/emu/grasscutter/data/excels/{ => weapon}/WeaponPromoteData.java (94%) rename src/main/java/emu/grasscutter/data/excels/{ => world}/WeatherData.java (91%) rename src/main/java/emu/grasscutter/data/excels/{ => world}/WorldAreaData.java (89%) rename src/main/java/emu/grasscutter/data/excels/{ => world}/WorldLevelData.java (86%) create mode 100644 src/main/java/emu/grasscutter/utils/ConversionUtils.java diff --git a/src/main/java/emu/grasscutter/command/commands/AchievementCommand.java b/src/main/java/emu/grasscutter/command/commands/AchievementCommand.java index 932580b3a..738d7414f 100644 --- a/src/main/java/emu/grasscutter/command/commands/AchievementCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AchievementCommand.java @@ -3,7 +3,7 @@ package emu.grasscutter.command.commands; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.AchievementData; +import emu.grasscutter.data.excels.achievement.AchievementData; import emu.grasscutter.game.achievement.AchievementControlReturns; import emu.grasscutter.game.achievement.Achievements; import emu.grasscutter.game.player.Player; @@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger; permissionTargeted = "player.achievement.others", targetRequirement = Command.TargetRequirement.PLAYER, threading = true) -public class AchievementCommand implements CommandHandler { +public final class AchievementCommand implements CommandHandler { private static void sendSuccessMessage(Player sender, String cmd, Object... args) { CommandHandler.sendTranslatedMessage( sender, AchievementControlReturns.Return.SUCCESS.getKey() + cmd, args); diff --git a/src/main/java/emu/grasscutter/command/commands/EntityCommand.java b/src/main/java/emu/grasscutter/command/commands/EntityCommand.java index bd6a930a4..4ed18b21a 100644 --- a/src/main/java/emu/grasscutter/command/commands/EntityCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/EntityCommand.java @@ -1,137 +1,139 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.entity.*; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.ElementType; -import emu.grasscutter.game.props.FightProperty; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.server.event.entity.EntityDamageEvent; -import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; -import lombok.Setter; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.function.BiConsumer; -import java.util.regex.Pattern; - -import static emu.grasscutter.command.CommandHelpers.*; -import static emu.grasscutter.utils.Language.translate; - -@Command( - label = "entity", - usage = { - " [state] [maxhp] [hp(0 for infinite)] [atk] [def]", - " [ai] [maxhp] [hp(0 for infinite)] [atk] [def]"}, - permission = "server.entity") -public final class EntityCommand implements CommandHandler { - private static final Map> intCommandHandlers = Map.ofEntries( - Map.entry(stateRegex, EntityParameters::setState), - Map.entry(maxHPRegex, EntityParameters::setMaxHP), - Map.entry(hpRegex, EntityParameters::setHp), - Map.entry(defRegex, EntityParameters::setDef), - Map.entry(atkRegex, EntityParameters::setAtk), - Map.entry(aiRegex, EntityParameters::setAi) - ); - - @Override - public void execute(Player sender, Player targetPlayer, List args) { - EntityParameters param = new EntityParameters(); - - parseIntParameters(args, param, intCommandHandlers); - - // At this point, first remaining argument MUST be the id and the rest the pos - if (args.size() != 1) { - sendUsageMessage(sender); // Reachable if someone does `/give lv90` or similar - throw new IllegalArgumentException(); - } - - try { - param.configId = Integer.parseInt(args.get(0)); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.cfgId")); - } - - param.scene = targetPlayer.getScene(); - var entity = param.scene.getEntityByConfigId(param.configId); - - if(entity == null){ - CommandHandler.sendMessage(sender, translate(sender, "commands.entity.not_found_error")); - return; - } - applyFightProps(entity, param); - applyGadgetParams(entity, param); - applyMonsterParams(entity, param); - - CommandHandler.sendMessage(sender, translate(sender, "commands.status.success")); - } - - - - private void applyGadgetParams(GameEntity entity, EntityParameters param) { - if(!(entity instanceof EntityGadget)){ - return; - } - if(param.state != -1 ){ - ((EntityGadget) entity).updateState(param.state); - } - - } - private void applyMonsterParams(GameEntity entity, EntityParameters param) { - if(!(entity instanceof EntityMonster)){ - return; - } - - if(param.ai != -1 ){ - ((EntityMonster) entity).setAiId(param.ai); - //TODO notify - } - } - - private void applyFightProps(GameEntity entity, EntityParameters param) { - var changedFields = new ArrayList(); - if (param.maxHP != -1) { - setFightProperty(entity, FightProperty.FIGHT_PROP_MAX_HP, param.maxHP, changedFields); - } - if (param.hp != -1) { - float targetHp = param.hp == 0 ? Float.MAX_VALUE : param.hp; - float oldHp = entity.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP); - setFightProperty(entity, FightProperty.FIGHT_PROP_CUR_HP, targetHp, changedFields); - EntityDamageEvent event = new EntityDamageEvent(entity, oldHp-targetHp, ElementType.None, null); - callHPEvents(entity, event); - } - if (param.atk != -1) { - setFightProperty(entity, FightProperty.FIGHT_PROP_ATTACK, param.atk, changedFields); - setFightProperty(entity, FightProperty.FIGHT_PROP_CUR_ATTACK, param.atk, changedFields); - } - if (param.def != -1) { - setFightProperty(entity, FightProperty.FIGHT_PROP_DEFENSE, param.def, changedFields); - setFightProperty(entity, FightProperty.FIGHT_PROP_CUR_DEFENSE, param.def, changedFields); - } - if(!changedFields.isEmpty()) { - entity.getScene().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, changedFields)); - } - } - - private void callHPEvents(GameEntity entity, EntityDamageEvent event){ - entity.callLuaHPEvent(event); - } - - private void setFightProperty(GameEntity entity, FightProperty property, float value, List modifiedProps){ - entity.setFightProperty(property, value); - modifiedProps.add(property); - } - - private static class EntityParameters { - @Setter public int configId = -1; - @Setter public int state = -1; - @Setter public int hp = -1; - @Setter public int maxHP = -1; - @Setter public int atk = -1; - @Setter public int def = -1; - @Setter public int ai = -1; - public Scene scene = null; - } -} +package emu.grasscutter.command.commands; + +import static emu.grasscutter.command.CommandHelpers.*; +import static emu.grasscutter.utils.Language.translate; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.entity.*; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ElementType; +import emu.grasscutter.game.props.FightProperty; +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.server.event.entity.EntityDamageEvent; +import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.regex.Pattern; +import lombok.Setter; + +@Command( + label = "entity", + usage = { + " [state] [maxhp] [hp(0 for infinite)] [atk] [def]", + " [ai] [maxhp] [hp(0 for infinite)] [atk] [def]" + }, + permission = "server.entity") +public final class EntityCommand implements CommandHandler { + private static final Map> intCommandHandlers = + Map.ofEntries( + Map.entry(stateRegex, EntityParameters::setState), + Map.entry(maxHPRegex, EntityParameters::setMaxHP), + Map.entry(hpRegex, EntityParameters::setHp), + Map.entry(defRegex, EntityParameters::setDef), + Map.entry(atkRegex, EntityParameters::setAtk), + Map.entry(aiRegex, EntityParameters::setAi)); + + @Override + public void execute(Player sender, Player targetPlayer, List args) { + EntityParameters param = new EntityParameters(); + + parseIntParameters(args, param, intCommandHandlers); + + // At this point, first remaining argument MUST be the id and the rest the pos + if (args.size() != 1) { + sendUsageMessage(sender); // Reachable if someone does `/give lv90` or similar + throw new IllegalArgumentException(); + } + + try { + param.configId = Integer.parseInt(args.get(0)); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.cfgId")); + } + + param.scene = targetPlayer.getScene(); + var entity = param.scene.getEntityByConfigId(param.configId); + + if (entity == null) { + CommandHandler.sendMessage(sender, translate(sender, "commands.entity.not_found_error")); + return; + } + applyFightProps(entity, param); + applyGadgetParams(entity, param); + applyMonsterParams(entity, param); + + CommandHandler.sendMessage(sender, translate(sender, "commands.status.success")); + } + + private void applyGadgetParams(GameEntity entity, EntityParameters param) { + if (!(entity instanceof EntityGadget)) { + return; + } + if (param.state != -1) { + ((EntityGadget) entity).updateState(param.state); + } + } + + private void applyMonsterParams(GameEntity entity, EntityParameters param) { + if (!(entity instanceof EntityMonster)) { + return; + } + + if (param.ai != -1) { + ((EntityMonster) entity).setAiId(param.ai); + // TODO notify + } + } + + private void applyFightProps(GameEntity entity, EntityParameters param) { + var changedFields = new ArrayList(); + if (param.maxHP != -1) { + setFightProperty(entity, FightProperty.FIGHT_PROP_MAX_HP, param.maxHP, changedFields); + } + if (param.hp != -1) { + float targetHp = param.hp == 0 ? Float.MAX_VALUE : param.hp; + float oldHp = entity.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP); + setFightProperty(entity, FightProperty.FIGHT_PROP_CUR_HP, targetHp, changedFields); + EntityDamageEvent event = + new EntityDamageEvent(entity, oldHp - targetHp, ElementType.None, null); + callHPEvents(entity, event); + } + if (param.atk != -1) { + setFightProperty(entity, FightProperty.FIGHT_PROP_ATTACK, param.atk, changedFields); + setFightProperty(entity, FightProperty.FIGHT_PROP_CUR_ATTACK, param.atk, changedFields); + } + if (param.def != -1) { + setFightProperty(entity, FightProperty.FIGHT_PROP_DEFENSE, param.def, changedFields); + setFightProperty(entity, FightProperty.FIGHT_PROP_CUR_DEFENSE, param.def, changedFields); + } + if (!changedFields.isEmpty()) { + entity + .getScene() + .broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, changedFields)); + } + } + + private void callHPEvents(GameEntity entity, EntityDamageEvent event) { + entity.callLuaHPEvent(event); + } + + private void setFightProperty( + GameEntity entity, FightProperty property, float value, List modifiedProps) { + entity.setFightProperty(property, value); + modifiedProps.add(property); + } + + private static class EntityParameters { + @Setter public int configId = -1; + @Setter public int state = -1; + @Setter public int hp = -1; + @Setter public int maxHP = -1; + @Setter public int atk = -1; + @Setter public int def = -1; + @Setter public int ai = -1; + public Scene scene = null; + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java index 6e597bc20..7dc1b928f 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java @@ -4,10 +4,10 @@ import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameDepot; -import emu.grasscutter.data.excels.AvatarData; +import emu.grasscutter.data.excels.avatar.AvatarData; import emu.grasscutter.data.excels.ItemData; -import emu.grasscutter.data.excels.ReliquaryAffixData; -import emu.grasscutter.data.excels.ReliquaryMainPropData; +import emu.grasscutter.data.excels.reliquary.ReliquaryAffixData; +import emu.grasscutter.data.excels.reliquary.ReliquaryMainPropData; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.ItemType; diff --git a/src/main/java/emu/grasscutter/command/commands/GroupCommand.java b/src/main/java/emu/grasscutter/command/commands/GroupCommand.java index a200dbdf4..790986a05 100644 --- a/src/main/java/emu/grasscutter/command/commands/GroupCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GroupCommand.java @@ -1,72 +1,72 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.world.SceneGroupInstance; - -import java.util.List; - -import static emu.grasscutter.utils.Language.translate; - -@Command(label = "group", - aliases = {"g"}, - usage = {"(refresh) [] []"}, - permission = "player.group", - permissionTargeted = "player.group.others") -public final class GroupCommand implements CommandHandler { - - @Override - public void execute(Player sender, Player targetPlayer, List args) { - if (args.isEmpty()) { - return; - } - String cmd = args.remove(0).toLowerCase(); - - int groupId = 0; - int suiteId = 0; - switch (args.size()){ - case 2: - try { - suiteId = Integer.parseInt(args.get(1)); - } - catch (Exception e) { - CommandHandler.sendMessage(sender, translate(sender, "commands.group.invalid_suiteid")); - return; - } // Fallthrough - case 1: - try { - groupId = Integer.parseInt(args.get(0)); - } - catch (Exception e) { - CommandHandler.sendMessage(sender, translate(sender, "commands.group.invalid_groupid")); - return; - } - break; - default: - sendUsageMessage(sender); - return; - } - - switch (cmd) { - case "refresh" -> { - SceneGroupInstance groupInstance = targetPlayer.getScene().getScriptManager().getGroupInstanceById(groupId); - if(groupInstance == null) { - CommandHandler.sendMessage(sender, translate(sender, "commands.group.group_not_found", groupId)); - return; - } - - if(args.size() >= 2) { - targetPlayer.getScene().getScriptManager().refreshGroup(groupInstance, suiteId, false); - } else { - targetPlayer.getScene().getScriptManager().refreshGroup(groupInstance); - } - - CommandHandler.sendMessage(sender, translate(sender, "commands.group.refreshed", groupId)); - } - default -> { - sendUsageMessage(sender); - } - } - } -} +package emu.grasscutter.command.commands; + +import static emu.grasscutter.utils.Language.translate; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.world.SceneGroupInstance; +import java.util.List; + +@Command( + label = "group", + aliases = {"g"}, + usage = {"(refresh) [] []"}, + permission = "player.group", + permissionTargeted = "player.group.others") +public final class GroupCommand implements CommandHandler { + + @Override + public void execute(Player sender, Player targetPlayer, List args) { + if (args.isEmpty()) { + return; + } + String cmd = args.remove(0).toLowerCase(); + + int groupId = 0; + int suiteId = 0; + switch (args.size()) { + case 2: + try { + suiteId = Integer.parseInt(args.get(1)); + } catch (Exception e) { + CommandHandler.sendMessage(sender, translate(sender, "commands.group.invalid_suiteid")); + return; + } // Fallthrough + case 1: + try { + groupId = Integer.parseInt(args.get(0)); + } catch (Exception e) { + CommandHandler.sendMessage(sender, translate(sender, "commands.group.invalid_groupid")); + return; + } + break; + default: + sendUsageMessage(sender); + return; + } + + switch (cmd) { + case "refresh" -> { + SceneGroupInstance groupInstance = + targetPlayer.getScene().getScriptManager().getGroupInstanceById(groupId); + if (groupInstance == null) { + CommandHandler.sendMessage( + sender, translate(sender, "commands.group.group_not_found", groupId)); + return; + } + + if (args.size() >= 2) { + targetPlayer.getScene().getScriptManager().refreshGroup(groupInstance, suiteId, false); + } else { + targetPlayer.getScene().getScriptManager().refreshGroup(groupInstance); + } + + CommandHandler.sendMessage(sender, translate(sender, "commands.group.refreshed", groupId)); + } + default -> { + sendUsageMessage(sender); + } + } + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java index 04f5e79f4..bc525ade4 100644 --- a/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java @@ -9,7 +9,7 @@ import emu.grasscutter.command.CommandHandler; import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.GadgetData; import emu.grasscutter.data.excels.ItemData; -import emu.grasscutter.data.excels.MonsterData; +import emu.grasscutter.data.excels.monster.MonsterData; import emu.grasscutter.game.entity.*; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.EntityType; diff --git a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java index 9b19a7596..379c517a8 100644 --- a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java @@ -3,7 +3,7 @@ package emu.grasscutter.command.commands; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.AvatarSkillDepotData; +import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.player.Player; import emu.grasscutter.utils.Language; diff --git a/src/main/java/emu/grasscutter/command/commands/TrialAvatarActivityCommand.java b/src/main/java/emu/grasscutter/command/commands/TrialAvatarActivityCommand.java index 981a5d2dd..1cc4e387d 100644 --- a/src/main/java/emu/grasscutter/command/commands/TrialAvatarActivityCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TrialAvatarActivityCommand.java @@ -1,125 +1,156 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.activity.trialavatar.TrialAvatarActivityHandler; -import emu.grasscutter.game.activity.trialavatar.TrialAvatarPlayerData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.ActivityType; -import emu.grasscutter.net.proto.ActivityInfoOuterClass.ActivityInfo; -import emu.grasscutter.server.packet.send.PacketActivityInfoNotify; -import emu.grasscutter.utils.JsonUtils; - -import java.util.List; -import lombok.val; - -import static emu.grasscutter.utils.Language.translate; - -@Command( - label = "trialAvatarActivity", - aliases = {"taa"}, - usage = {"change ", "toggleDungeon ", "toggleReward "}, - permission = "player.trialavataractivity", - permissionTargeted = "player.trialavataractivity.others") -public final class TrialAvatarActivityCommand implements CommandHandler { - @Override - public void execute(Player sender, Player targetPlayer, List args) { - if (args.size() < 2) { - sendUsageMessage(sender); - return; - } - - String action = args.get(0).toLowerCase(); - String param = args.get(1); - - val playerDataOption = targetPlayer.getActivityManager() - .getPlayerActivityDataByActivityType(ActivityType.NEW_ACTIVITY_TRIAL_AVATAR); - if (playerDataOption == null) { - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.not_found")); - return; - } - val playerData = playerDataOption.get(); - if (playerData == null) { - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.not_found")); - return; - } - var handler = (TrialAvatarActivityHandler) playerData.getActivityHandler(); - if (handler == null) { - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.not_found")); - return; - } - TrialAvatarPlayerData trialAvatarPlayerData = JsonUtils.decode(playerData.getDetail(), TrialAvatarPlayerData.class); - if (trialAvatarPlayerData == null) { - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.not_found")); - return; - } - - switch (action) { - default -> { - sendUsageMessage(sender); - } - case "change" -> { - if (!param.chars().allMatch(Character::isDigit)) { // if its not number - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.invalid_param")); - return; - } - if (TrialAvatarPlayerData.getAvatarIdList(Integer.parseInt(param)).isEmpty()) { - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.schedule_not_found", Integer.parseInt(param))); - return; - } - playerData.setDetail(TrialAvatarPlayerData.create(Integer.parseInt(param))); - playerData.save(); - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.success_schedule", Integer.parseInt(param))); - } - case "toggledungeon" -> { - if (param.chars().allMatch(Character::isDigit)) { // if its number - if (Integer.parseInt(param)-1 >= trialAvatarPlayerData.getRewardInfoList().size() - || Integer.parseInt(param)-1 <= 0) { - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.invalid_param")); - return; - } - TrialAvatarPlayerData.RewardInfoItem rewardInfo = trialAvatarPlayerData.getRewardInfoList().get(Integer.parseInt(param)-1); - rewardInfo.setPassedDungeon(!rewardInfo.isPassedDungeon()); - playerData.setDetail(trialAvatarPlayerData); - playerData.save(); - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.success_dungeon", Integer.parseInt(param))); - } else { - if (!param.equals("all")) { - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.invalid_param")); - return; - } - trialAvatarPlayerData.getRewardInfoList().forEach(r -> r.setPassedDungeon(!r.isPassedDungeon())); - playerData.setDetail(trialAvatarPlayerData); - playerData.save(); - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.success_dungeon_all")); - } - } - case "togglereward" -> { - if (param.chars().allMatch(Character::isDigit)) { // if its number - if (Integer.parseInt(param)-1 >= trialAvatarPlayerData.getRewardInfoList().size() - || Integer.parseInt(param)-1 <= 0) { - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.invalid_param")); - return; - } - TrialAvatarPlayerData.RewardInfoItem rewardInfo = trialAvatarPlayerData.getRewardInfoList().get(Integer.parseInt(param)-1); - rewardInfo.setReceivedReward(!rewardInfo.isReceivedReward()); - playerData.setDetail(trialAvatarPlayerData); - playerData.save(); - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.success_reward", Integer.parseInt(param))); - } else { - if (!param.toLowerCase().equals("all")) { - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.invalid_param")); - return; - } - trialAvatarPlayerData.getRewardInfoList().forEach(r -> r.setReceivedReward(!r.isReceivedReward())); - playerData.setDetail(trialAvatarPlayerData); - playerData.save(); - CommandHandler.sendMessage(sender, translate(sender, "commands.trialAvatarActivity.success_reward_all")); - } - } - } - targetPlayer.sendPacket(new PacketActivityInfoNotify(handler.toProto(playerData, targetPlayer.getActivityManager().getConditionExecutor()))); - } -} +package emu.grasscutter.command.commands; + +import static emu.grasscutter.utils.Language.translate; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.activity.trialavatar.TrialAvatarActivityHandler; +import emu.grasscutter.game.activity.trialavatar.TrialAvatarPlayerData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActivityType; +import emu.grasscutter.server.packet.send.PacketActivityInfoNotify; +import emu.grasscutter.utils.JsonUtils; +import java.util.List; + +@Command( + label = "trialAvatarActivity", + aliases = {"taa"}, + usage = { + "change ", + "toggleDungeon ", + "toggleReward " + }, + permission = "player.trialavataractivity", + permissionTargeted = "player.trialavataractivity.others") +public final class TrialAvatarActivityCommand implements CommandHandler { + @Override + public void execute(Player sender, Player targetPlayer, List args) { + if (args.size() < 2) { + sendUsageMessage(sender); + return; + } + + var action = args.get(0).toLowerCase(); + var param = args.get(1); + + var playerDataOption = + targetPlayer + .getActivityManager() + .getPlayerActivityDataByActivityType(ActivityType.NEW_ACTIVITY_TRIAL_AVATAR); + if (playerDataOption.isEmpty()) { + CommandHandler.sendMessage( + sender, translate(sender, "commands.trialAvatarActivity.not_found")); + return; + } + + var playerData = playerDataOption.get(); + var handler = (TrialAvatarActivityHandler) playerData.getActivityHandler(); + if (handler == null) { + CommandHandler.sendMessage( + sender, translate(sender, "commands.trialAvatarActivity.not_found")); + return; + } + + var trialAvatarPlayerData = + JsonUtils.decode(playerData.getDetail(), TrialAvatarPlayerData.class); + if (trialAvatarPlayerData == null) { + CommandHandler.sendMessage( + sender, translate(sender, "commands.trialAvatarActivity.not_found")); + return; + } + + switch (action) { + default -> this.sendUsageMessage(sender); + case "change" -> { + if (!param.chars().allMatch(Character::isDigit)) { // if its not number + CommandHandler.sendMessage( + sender, translate(sender, "commands.trialAvatarActivity.invalid_param")); + return; + } + if (TrialAvatarPlayerData.getAvatarIdList(Integer.parseInt(param)).isEmpty()) { + CommandHandler.sendMessage( + sender, + translate( + sender, + "commands.trialAvatarActivity.schedule_not_found", + Integer.parseInt(param))); + return; + } + playerData.setDetail(TrialAvatarPlayerData.create(Integer.parseInt(param))); + playerData.save(); + CommandHandler.sendMessage( + sender, + translate( + sender, "commands.trialAvatarActivity.success_schedule", Integer.parseInt(param))); + } + case "toggledungeon" -> { + if (param.chars().allMatch(Character::isDigit)) { // if its number + if (Integer.parseInt(param) - 1 >= trialAvatarPlayerData.getRewardInfoList().size() + || Integer.parseInt(param) - 1 <= 0) { + CommandHandler.sendMessage( + sender, translate(sender, "commands.trialAvatarActivity.invalid_param")); + return; + } + TrialAvatarPlayerData.RewardInfoItem rewardInfo = + trialAvatarPlayerData.getRewardInfoList().get(Integer.parseInt(param) - 1); + rewardInfo.setPassedDungeon(!rewardInfo.isPassedDungeon()); + playerData.setDetail(trialAvatarPlayerData); + playerData.save(); + CommandHandler.sendMessage( + sender, + translate( + sender, "commands.trialAvatarActivity.success_dungeon", Integer.parseInt(param))); + } else { + if (!param.equals("all")) { + CommandHandler.sendMessage( + sender, translate(sender, "commands.trialAvatarActivity.invalid_param")); + return; + } + trialAvatarPlayerData + .getRewardInfoList() + .forEach(r -> r.setPassedDungeon(!r.isPassedDungeon())); + playerData.setDetail(trialAvatarPlayerData); + playerData.save(); + CommandHandler.sendMessage( + sender, translate(sender, "commands.trialAvatarActivity.success_dungeon_all")); + } + } + case "togglereward" -> { + if (param.chars().allMatch(Character::isDigit)) { // if its number + if (Integer.parseInt(param) - 1 >= trialAvatarPlayerData.getRewardInfoList().size() + || Integer.parseInt(param) - 1 <= 0) { + CommandHandler.sendMessage( + sender, translate(sender, "commands.trialAvatarActivity.invalid_param")); + return; + } + TrialAvatarPlayerData.RewardInfoItem rewardInfo = + trialAvatarPlayerData.getRewardInfoList().get(Integer.parseInt(param) - 1); + rewardInfo.setReceivedReward(!rewardInfo.isReceivedReward()); + playerData.setDetail(trialAvatarPlayerData); + playerData.save(); + CommandHandler.sendMessage( + sender, + translate( + sender, "commands.trialAvatarActivity.success_reward", Integer.parseInt(param))); + } else { + if (!param.toLowerCase().equals("all")) { + CommandHandler.sendMessage( + sender, translate(sender, "commands.trialAvatarActivity.invalid_param")); + return; + } + trialAvatarPlayerData + .getRewardInfoList() + .forEach(r -> r.setReceivedReward(!r.isReceivedReward())); + playerData.setDetail(trialAvatarPlayerData); + playerData.save(); + CommandHandler.sendMessage( + sender, translate(sender, "commands.trialAvatarActivity.success_reward_all")); + } + } + } + + targetPlayer.sendPacket( + new PacketActivityInfoNotify( + handler.toProto(playerData, targetPlayer.getActivityManager().getConditionExecutor()))); + } +} diff --git a/src/main/java/emu/grasscutter/data/GameData.java b/src/main/java/emu/grasscutter/data/GameData.java index 6b92c1dd5..f409fc706 100644 --- a/src/main/java/emu/grasscutter/data/GameData.java +++ b/src/main/java/emu/grasscutter/data/GameData.java @@ -2,19 +2,41 @@ package emu.grasscutter.data; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.binout.*; +import emu.grasscutter.data.binout.config.*; +import emu.grasscutter.data.binout.routes.*; +import emu.grasscutter.data.custom.*; import emu.grasscutter.data.excels.*; -import emu.grasscutter.game.quest.QuestEncryptionKey; +import emu.grasscutter.data.excels.achievement.*; +import emu.grasscutter.data.excels.activity.*; +import emu.grasscutter.data.excels.avatar.*; +import emu.grasscutter.data.excels.codex.*; +import emu.grasscutter.data.excels.dungeon.*; +import emu.grasscutter.data.excels.monster.*; +import emu.grasscutter.data.excels.reliquary.*; +import emu.grasscutter.data.excels.tower.*; +import emu.grasscutter.data.excels.trial.*; +import emu.grasscutter.data.excels.weapon.*; +import emu.grasscutter.data.excels.world.*; +import emu.grasscutter.data.server.*; +import emu.grasscutter.game.dungeons.*; +import emu.grasscutter.game.quest.*; +import emu.grasscutter.game.world.*; import emu.grasscutter.utils.Utils; import it.unimi.dsi.fastutil.ints.*; import java.lang.reflect.Field; import java.util.*; +import javax.annotation.Nullable; import lombok.Getter; -import lombok.experimental.Tolerate; +import lombok.val; -public class GameData { - protected static final Map abilityDataMap = new HashMap<>(); - protected static final Int2ObjectMap scenePointEntryMap = +@SuppressWarnings({"unused", "MismatchedQueryAndUpdateOfCollection"}) +public final class GameData { + @Getter private static final Map abilityDataMap = new HashMap<>(); + + @Getter + private static final Int2ObjectMap scenePointEntryMap = new Int2ObjectOpenHashMap<>(); + // BinOutputs @Getter private static final Int2ObjectMap homeworldDefaultSaveData = @@ -29,16 +51,28 @@ public class GameData { @Getter private static final Map gadgetConfigData = new HashMap<>(); @Getter private static final Map openConfigEntries = new HashMap<>(); - @Deprecated(forRemoval = true) - @Getter - private static final Map scenePointEntries = new HashMap<>(); - private static final Int2ObjectMap mainQuestData = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap questsKeys = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap npcBornData = new Int2ObjectOpenHashMap<>(); private static final Map abilityEmbryos = new HashMap<>(); // ExcelConfigs + @Getter + private static final Int2ObjectMap activityCondExcelConfigDataMap = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap dungeonPassConfigDataMap = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap dungeonChallengeConfigDataMap = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap> sceneRouteData = + new Int2ObjectOpenHashMap<>(); + @Getter private static final ArrayList codexReliquaryArrayList = new ArrayList<>(); @@ -276,6 +310,26 @@ public class GameData { private static final Int2ObjectMap triggerExcelConfigDataMap = new Int2ObjectOpenHashMap<>(); + @Getter + private static final Int2ObjectMap trialAvatarDataMap = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap trialAvatarActivityDataMap = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap trialAvatarActivityDataDataMap = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap trialAvatarTemplateDataMap = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap trialReliquaryDataMap = + new Int2ObjectOpenHashMap<>(); + @Getter private static final Int2ObjectMap weaponCurveDataMap = new Int2ObjectOpenHashMap<>(); @@ -299,6 +353,16 @@ public class GameData { private static final Int2ObjectMap worldLevelDataMap = new Int2ObjectOpenHashMap<>(); + @Getter + private static final Int2ObjectMap rewindDataMap = new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap teleportDataMap = new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap refreshPolicyExcelConfigDataMap = + new Int2ObjectOpenHashMap<>(); + private static final Int2ObjectMap avatarPromoteDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap fetterDataMap = new Int2ObjectOpenHashMap<>(); @@ -306,6 +370,7 @@ public class GameData { new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap shopGoodsDataMap = new Int2ObjectOpenHashMap<>(); + // The following are accessed via getMapByResourceDef, and will show as unused private static final Int2ObjectMap codexMaterialDataMap = new Int2ObjectOpenHashMap<>(); @@ -316,34 +381,65 @@ public class GameData { private static final Int2ObjectMap codexWeaponDataMap = new Int2ObjectOpenHashMap<>(); + // Custom community server resources + @Getter + private static final Int2ObjectMap> dungeonDropDataMap = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap gadgetMappingMap = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap activityCondGroupMap = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap groupReplacements = + new Int2ObjectOpenHashMap<>(); + // Cache @Getter private static final IntList scenePointIdList = new IntArrayList(); @Getter private static final List openStateList = new ArrayList<>(); @Getter private static final Map> scenePointsPerScene = new HashMap<>(); @Getter private static final Map scriptSceneDataMap = new HashMap<>(); - protected static Int2ObjectMap proudSkillGroupLevels = new Int2ObjectOpenHashMap<>(); - protected static Int2IntMap proudSkillGroupMaxLevels = new Int2IntOpenHashMap(); - protected static Int2ObjectMap avatarSkillLevels = new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Map configLevelEntityDataMap = new HashMap<>(); + + @Getter + private static final Int2ObjectMap proudSkillGroupLevels = new Int2ObjectOpenHashMap<>(); + + @Getter private static final Int2IntMap proudSkillGroupMaxLevels = new Int2IntOpenHashMap(); + + @Getter + private static final Int2ObjectMap avatarSkillLevels = new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Map> beginCondQuestMap = + new HashMap<>(); // cache filled by QuestData + + @Getter private static final Map questTalkMap = new HashMap<>(); + + @Getter + private static final Int2ObjectMap trialAvatarCustomData = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Map trialAvatarActivityCustomData = + new HashMap<>(); + + @Getter + private static final Map trialAvatarActivityDataCustomData = + new HashMap<>(); + + @Getter + private static final Int2IntMap trialAvatarIndexIdTrialActivityDataDataMap = + new Int2IntOpenHashMap(); + private static final Map> fetters = new HashMap<>(); private static final Map> shopGoods = new HashMap<>(); - // Getters with wrong names, remove later - @Deprecated(forRemoval = true) - public static Int2ObjectMap getcodexReliquaryIdMap() { - return codexReliquaryDataIdMap; - } - - @Deprecated(forRemoval = true) - public static Int2ObjectMap getDungeonEntryDatatMap() { - return dungeonEntryDataMap; - } - - @Deprecated(forRemoval = true) - @Tolerate - public static ArrayList getcodexReliquaryArrayList() { - return codexReliquaryArrayList; - } - // Getters with different names that stay for now public static Int2ObjectMap getMainQuestDataMap() { return mainQuestData; @@ -468,6 +564,33 @@ public class GameData { return shopGoods; } + /** + * Fetches the route data for a scene by ID. + * + * @param sceneId The ID of the scene to fetch the route data for. + * @return The route data for the scene, or an empty map if the scene has no route data. + */ + public static Int2ObjectMap getSceneRoutes(int sceneId) { + return sceneRouteData.computeIfAbsent(sceneId, k -> new Int2ObjectOpenHashMap<>()); + } + + /** + * Fetches the trial data + * + * @param trialAvatarIndexId + * @return + */ + @Nullable public static TrialAvatarActivityDataData getTrialAvatarActivityDataByAvatarIndex( + int trialAvatarIndexId) { + // prefer custom data over official data + val dataId = trialAvatarIndexIdTrialActivityDataDataMap.get(trialAvatarIndexId); + val datamap = + GameData.getTrialAvatarActivityDataCustomData().isEmpty() + ? GameData.getTrialAvatarActivityDataDataMap() + : GameData.getTrialAvatarActivityDataCustomData(); + return datamap.get(dataId); + } + public static Int2ObjectMap getAchievementDataMap() { AchievementData.divideIntoGroups(); return achievementDataMap; diff --git a/src/main/java/emu/grasscutter/data/GameDepot.java b/src/main/java/emu/grasscutter/data/GameDepot.java index 7cf771d1f..338088b70 100644 --- a/src/main/java/emu/grasscutter/data/GameDepot.java +++ b/src/main/java/emu/grasscutter/data/GameDepot.java @@ -2,8 +2,8 @@ package emu.grasscutter.data; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.ResourceLoader.AvatarConfig; -import emu.grasscutter.data.excels.ReliquaryAffixData; -import emu.grasscutter.data.excels.ReliquaryMainPropData; +import emu.grasscutter.data.excels.reliquary.ReliquaryAffixData; +import emu.grasscutter.data.excels.reliquary.ReliquaryMainPropData; import emu.grasscutter.game.managers.blossom.BlossomConfig; import emu.grasscutter.game.world.SpawnDataEntry; import emu.grasscutter.utils.WeightedList; diff --git a/src/main/java/emu/grasscutter/data/ResourceLoader.java b/src/main/java/emu/grasscutter/data/ResourceLoader.java index e0f49d7e0..768eedb3b 100644 --- a/src/main/java/emu/grasscutter/data/ResourceLoader.java +++ b/src/main/java/emu/grasscutter/data/ResourceLoader.java @@ -221,14 +221,13 @@ public class ResourceLoader { pointData.setId(pointId); GameData.getScenePointIdList().add(pointId); - GameData.getScenePointEntries().put(scenePoint.getName(), scenePoint); - GameData.scenePointEntryMap.put((sceneId << 16) + pointId, scenePoint); + GameData.getScenePointEntryMap().put((sceneId << 16) + pointId, scenePoint); pointData.updateDailyDungeon(); }); GameData.getScenePointsPerScene().put(sceneId, scenePoints); }); - } catch (IOException e) { + } catch (IOException ignored) { Grasscutter.getLogger() .error("Scene point files cannot be found, you cannot use teleport waypoints!"); } @@ -239,19 +238,23 @@ public class ResourceLoader { GameData.getProudSkillDataMap() .forEach( (id, data) -> - GameData.proudSkillGroupLevels + GameData.getProudSkillGroupLevels() .computeIfAbsent(data.getProudSkillGroupId(), i -> new IntArraySet()) .add(data.getLevel())); // All known levels, keyed by avatarSkillId GameData.getAvatarSkillDataMap() .forEach( (id, data) -> - GameData.avatarSkillLevels.put( - (int) id, GameData.proudSkillGroupLevels.get(data.getProudSkillGroupId()))); + GameData.getAvatarSkillLevels() + .put( + (int) id, + GameData.getProudSkillGroupLevels().get(data.getProudSkillGroupId()))); // Maximum known levels, keyed by proudSkillGroupId - GameData.proudSkillGroupLevels.forEach( - (id, set) -> - GameData.proudSkillGroupMaxLevels.put((int) id, set.intStream().max().getAsInt())); + GameData.getProudSkillGroupLevels() + .forEach( + (id, set) -> + GameData.getProudSkillGroupMaxLevels() + .put((int) id, set.intStream().max().orElse(-1))); } private static void loadAbilityEmbryos() { @@ -266,42 +269,41 @@ public class ResourceLoader { if (embryoList == null) { // Load from BinOutput - val pattern = Pattern.compile("ConfigAvatar_(.+?)\\.json"); + var pattern = Pattern.compile("ConfigAvatar_(.+?)\\.json"); - val l = new ArrayList(); - try { - Files.newDirectoryStream(getResourcePath("BinOutput/Avatar/"), "ConfigAvatar_*.json") - .forEach( - path -> { - val matcher = pattern.matcher(path.getFileName().toString()); - if (!matcher.find()) return; - String avatarName = matcher.group(1); - AvatarConfig config; + var entries = new ArrayList(); + try (var stream = + Files.newDirectoryStream(getResourcePath("BinOutput/Avatar/"), "ConfigAvatar_*.json")) { - try { - config = JsonUtils.loadToClass(path, AvatarConfig.class); - } catch (Exception e) { - Grasscutter.getLogger().error("Error loading player ability embryos:", e); - return; - } + stream.forEach( + path -> { + var matcher = pattern.matcher(path.getFileName().toString()); + if (!matcher.find()) return; - if (config.abilities == null) return; + var avatarName = matcher.group(1); + AvatarConfig config; + try { + config = JsonUtils.loadToClass(path, AvatarConfig.class); + } catch (Exception e) { + Grasscutter.getLogger().error("Error loading player ability embryos:", e); + return; + } - int s = config.abilities.size(); - AbilityEmbryoEntry al = - new AbilityEmbryoEntry( - avatarName, - config.abilities.stream() - .map(Object::toString) - .toArray(size -> new String[s])); - l.add(al); - }); + if (config.abilities == null) return; + + entries.add( + new AbilityEmbryoEntry( + avatarName, + config.abilities.stream() + .map(Object::toString) + .toArray(size -> new String[config.abilities.size()]))); + }); } catch (IOException e) { Grasscutter.getLogger().error("Error loading ability embryos: no files found"); return; } - embryoList = l; + embryoList = entries; try { GameDepot.setPlayerAbilities( @@ -351,7 +353,7 @@ public class ResourceLoader { } private static void loadAbilityData(AbilityData data) { - GameData.abilityDataMap.put(data.abilityName, data); + GameData.getAbilityDataMap().put(data.abilityName, data); val modifiers = data.modifiers; if (modifiers == null || modifiers.size() == 0) return; diff --git a/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityAvatar.java b/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityAvatar.java index e99d08238..f2ad06c58 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityAvatar.java +++ b/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityAvatar.java @@ -1,4 +1,3 @@ -package emu.grasscutter.data.binout.config; - -public class ConfigEntityAvatar extends ConfigEntityBase { -} +package emu.grasscutter.data.binout.config; + +public class ConfigEntityAvatar extends ConfigEntityBase {} diff --git a/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityBase.java b/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityBase.java index c44cd2b9b..ac6933dae 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityBase.java +++ b/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityBase.java @@ -1,21 +1,17 @@ -package emu.grasscutter.data.binout.config; - -import emu.grasscutter.data.binout.config.fields.ConfigAbilityData; -import emu.grasscutter.data.binout.config.fields.ConfigCombat; -import emu.grasscutter.data.binout.config.fields.ConfigCommon; -import emu.grasscutter.data.binout.config.fields.ConfigGlobalValue; -import lombok.Data; - -import javax.annotation.Nullable; -import java.util.Collection; - -@Data -public class ConfigEntityBase { - @Nullable - ConfigCommon configCommon; - @Nullable - ConfigCombat combat; - Collection abilities; - ConfigGlobalValue globalValue; // used for SGV in monsters and Gadgets - -} +package emu.grasscutter.data.binout.config; + +import emu.grasscutter.data.binout.config.fields.ConfigAbilityData; +import emu.grasscutter.data.binout.config.fields.ConfigCombat; +import emu.grasscutter.data.binout.config.fields.ConfigCommon; +import emu.grasscutter.data.binout.config.fields.ConfigGlobalValue; +import java.util.Collection; +import javax.annotation.Nullable; +import lombok.Data; + +@Data +public class ConfigEntityBase { + @Nullable ConfigCommon configCommon; + @Nullable ConfigCombat combat; + Collection abilities; + ConfigGlobalValue globalValue; // used for SGV in monsters and Gadgets +} diff --git a/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityGadget.java b/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityGadget.java index cdd2fcd99..bd03a65b7 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityGadget.java +++ b/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityGadget.java @@ -1,11 +1,11 @@ -package emu.grasscutter.data.binout.config; - -import lombok.AccessLevel; -import lombok.Data; -import lombok.experimental.FieldDefaults; - -@Data -@FieldDefaults(level = AccessLevel.PRIVATE) -public class ConfigEntityGadget extends ConfigEntityBase { - // There are more values that can be added that might be useful in the json -} +package emu.grasscutter.data.binout.config; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +public class ConfigEntityGadget extends ConfigEntityBase { + // There are more values that can be added that might be useful in the json +} diff --git a/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityMonster.java b/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityMonster.java index 93cad56c9..445622f02 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityMonster.java +++ b/src/main/java/emu/grasscutter/data/binout/config/ConfigEntityMonster.java @@ -1,7 +1,6 @@ -package emu.grasscutter.data.binout.config; - -import lombok.Data; - -@Data -public class ConfigEntityMonster extends ConfigEntityBase { -} +package emu.grasscutter.data.binout.config; + +import lombok.Data; + +@Data +public class ConfigEntityMonster extends ConfigEntityBase {} diff --git a/src/main/java/emu/grasscutter/data/binout/config/ConfigLevelEntity.java b/src/main/java/emu/grasscutter/data/binout/config/ConfigLevelEntity.java index 4b5b582a2..792050a09 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/ConfigLevelEntity.java +++ b/src/main/java/emu/grasscutter/data/binout/config/ConfigLevelEntity.java @@ -1,14 +1,13 @@ -package emu.grasscutter.data.binout.config; - -import java.util.List; - -import emu.grasscutter.data.binout.config.fields.ConfigAbilityData; -import lombok.Getter; - -public class ConfigLevelEntity { - - @Getter private List abilities; //monster abilities - @Getter private List avatarAbilities; - @Getter private List teamAbilities; - @Getter private List preloadMonsterEntityIDs; -} +package emu.grasscutter.data.binout.config; + +import emu.grasscutter.data.binout.config.fields.ConfigAbilityData; +import java.util.List; +import lombok.Getter; + +public class ConfigLevelEntity { + + @Getter private List abilities; // monster abilities + @Getter private List avatarAbilities; + @Getter private List teamAbilities; + @Getter private List preloadMonsterEntityIDs; +} diff --git a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigAbilityData.java b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigAbilityData.java index b2dfed900..c832aed0b 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigAbilityData.java +++ b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigAbilityData.java @@ -1,10 +1,10 @@ -package emu.grasscutter.data.binout.config.fields; - -import lombok.Data; - -@Data -public class ConfigAbilityData { - public String abilityID; - public String abilityName; - public String abilityOverride; -} +package emu.grasscutter.data.binout.config.fields; + +import lombok.Data; + +@Data +public class ConfigAbilityData { + public String abilityID; + public String abilityName; + public String abilityOverride; +} diff --git a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigAiBeta.java b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigAiBeta.java index 5707e4e3d..36d8930c5 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigAiBeta.java +++ b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigAiBeta.java @@ -1,8 +1,8 @@ -package emu.grasscutter.data.binout.config.fields; - -import lombok.Data; - -@Data -public class ConfigAiBeta { - boolean enable; -} +package emu.grasscutter.data.binout.config.fields; + +import lombok.Data; + +@Data +public class ConfigAiBeta { + boolean enable; +} diff --git a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombat.java b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombat.java index 011e43606..cb1c04cb2 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombat.java +++ b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombat.java @@ -1,12 +1,12 @@ -package emu.grasscutter.data.binout.config.fields; - -import lombok.AccessLevel; -import lombok.Data; -import lombok.experimental.FieldDefaults; - -@Data -@FieldDefaults(level = AccessLevel.PRIVATE) -public class ConfigCombat { - // There are more values that can be added that might be useful in the json - ConfigCombatProperty property; -} +package emu.grasscutter.data.binout.config.fields; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +public class ConfigCombat { + // There are more values that can be added that might be useful in the json + ConfigCombatProperty property; +} diff --git a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombatDie.java b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombatDie.java index ae1d96247..b4ddbcaa4 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombatDie.java +++ b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombatDie.java @@ -1,15 +1,18 @@ -package emu.grasscutter.data.binout.config.fields; - -import com.google.gson.annotations.SerializedName; -import lombok.AccessLevel; -import lombok.Data; -import lombok.experimental.FieldDefaults; - -@Data -@FieldDefaults(level = AccessLevel.PRIVATE) -public class ConfigCombatDie { - @SerializedName(value="dieEndTime", alternate={"HGGPMFGGBNC"}) - double dieEndTime; - double dieForceDisappearTime; - boolean hasAnimatorDie; -} +package emu.grasscutter.data.binout.config.fields; + +import com.google.gson.annotations.SerializedName; +import lombok.AccessLevel; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +public class ConfigCombatDie { + @SerializedName( + value = "dieEndTime", + alternate = {"HGGPMFGGBNC"}) + double dieEndTime; + + double dieForceDisappearTime; + boolean hasAnimatorDie; +} diff --git a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombatProperty.java b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombatProperty.java index 995747762..fcc939718 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombatProperty.java +++ b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCombatProperty.java @@ -1,18 +1,18 @@ -package emu.grasscutter.data.binout.config.fields; - -import lombok.AccessLevel; -import lombok.Data; -import lombok.experimental.FieldDefaults; - -@Data -@FieldDefaults(level = AccessLevel.PRIVATE) -public class ConfigCombatProperty { - float HP; - boolean isLockHP; - boolean isInvincible; - boolean isGhostToAllied; - float attack; - float defence; - float weight; - boolean useCreatorProperty; -} +package emu.grasscutter.data.binout.config.fields; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +public class ConfigCombatProperty { + float HP; + boolean isLockHP; + boolean isInvincible; + boolean isGhostToAllied; + float attack; + float defence; + float weight; + boolean useCreatorProperty; +} diff --git a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCommon.java b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCommon.java index bc11e257e..88f3e9550 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCommon.java +++ b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigCommon.java @@ -1,7 +1,6 @@ -package emu.grasscutter.data.binout.config.fields; - -import lombok.Data; - -@Data -public class ConfigCommon { -} +package emu.grasscutter.data.binout.config.fields; + +import lombok.Data; + +@Data +public class ConfigCommon {} diff --git a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigGlobalValue.java b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigGlobalValue.java index 660adb35e..4a6992951 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigGlobalValue.java +++ b/src/main/java/emu/grasscutter/data/binout/config/fields/ConfigGlobalValue.java @@ -1,15 +1,12 @@ -package emu.grasscutter.data.binout.config.fields; - -import lombok.Data; - -import java.util.Map; -import java.util.Set; - -/** - * Contains information about the entities SGVs - */ -@Data -public class ConfigGlobalValue { - Set serverGlobalValues; - Map initServerGlobalValues; -} +package emu.grasscutter.data.binout.config.fields; + +import java.util.Map; +import java.util.Set; +import lombok.Data; + +/** Contains information about the entities SGVs */ +@Data +public class ConfigGlobalValue { + Set serverGlobalValues; + Map initServerGlobalValues; +} diff --git a/src/main/java/emu/grasscutter/data/binout/routes/RotAngleType.java b/src/main/java/emu/grasscutter/data/binout/routes/RotAngleType.java index 8d3e56ee9..9eb10afe1 100644 --- a/src/main/java/emu/grasscutter/data/binout/routes/RotAngleType.java +++ b/src/main/java/emu/grasscutter/data/binout/routes/RotAngleType.java @@ -1,23 +1,22 @@ -package emu.grasscutter.data.binout.routes; - -//import emu.grasscutter.scripts.constants.IntValueEnum; -import lombok.Getter; - -public enum RotAngleType /*implements IntValueEnum */{ - ROT_NONE(-1), - ROT_ANGLE_X(0), - ROT_ANGLE_Y(1), - ROT_ANGLE_Z(2); - - @Getter - private final int id; - - RotAngleType(int id) { - this.id = id; - } - - //@Override - public int getValue() { - return id; - } -} +package emu.grasscutter.data.binout.routes; + +// import emu.grasscutter.scripts.constants.IntValueEnum; +import lombok.Getter; + +public enum RotAngleType /*implements IntValueEnum */ { + ROT_NONE(-1), + ROT_ANGLE_X(0), + ROT_ANGLE_Y(1), + ROT_ANGLE_Z(2); + + @Getter private final int id; + + RotAngleType(int id) { + this.id = id; + } + + // @Override + public int getValue() { + return id; + } +} diff --git a/src/main/java/emu/grasscutter/data/binout/routes/RotType.java b/src/main/java/emu/grasscutter/data/binout/routes/RotType.java index fc7c7621f..c2771d5df 100644 --- a/src/main/java/emu/grasscutter/data/binout/routes/RotType.java +++ b/src/main/java/emu/grasscutter/data/binout/routes/RotType.java @@ -1,7 +1,7 @@ -package emu.grasscutter.data.binout.routes; - -public enum RotType { - ROT_NONE, - ROT_ANGLE, - ROT_ROUND -} +package emu.grasscutter.data.binout.routes; + +public enum RotType { + ROT_NONE, + ROT_ANGLE, + ROT_ROUND +} diff --git a/src/main/java/emu/grasscutter/data/binout/routes/Route.java b/src/main/java/emu/grasscutter/data/binout/routes/Route.java index b78fd31b4..32a4da6c7 100644 --- a/src/main/java/emu/grasscutter/data/binout/routes/Route.java +++ b/src/main/java/emu/grasscutter/data/binout/routes/Route.java @@ -1,31 +1,29 @@ -package emu.grasscutter.data.binout.routes; - -import emu.grasscutter.net.proto.RouteOuterClass; -import lombok.AccessLevel; -import lombok.Data; -import lombok.experimental.FieldDefaults; -import lombok.val; - -@Data -@FieldDefaults(level = AccessLevel.PRIVATE) -public class Route { - private int localId; - private String name; - private RouteType type = RouteType.Unknown; - private RoutePoint[] points; - private float arriveRange; // optional - private RotType rotType; // optional - private RotAngleType rotAngleType; // optional - - public RouteOuterClass.Route toProto(){ - val builder = RouteOuterClass.Route.newBuilder() - .setRouteType(type.getValue()); - if(points !=null){ - for(var routePoint : points){ - builder.addRoutePoints(routePoint.toProto() - .setArriveRange(arriveRange)); - } - } - return builder.build(); - } -} +package emu.grasscutter.data.binout.routes; + +import emu.grasscutter.net.proto.RouteOuterClass; +import lombok.AccessLevel; +import lombok.Data; +import lombok.experimental.FieldDefaults; +import lombok.val; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +public class Route { + private int localId; + private String name; + private RouteType type = RouteType.Unknown; + private RoutePoint[] points; + private float arriveRange; // optional + private RotType rotType; // optional + private RotAngleType rotAngleType; // optional + + public RouteOuterClass.Route toProto() { + val builder = RouteOuterClass.Route.newBuilder().setRouteType(type.getValue()); + if (points != null) { + for (var routePoint : points) { + builder.addRoutePoints(routePoint.toProto().setArriveRange(arriveRange)); + } + } + return builder.build(); + } +} diff --git a/src/main/java/emu/grasscutter/data/binout/routes/RoutePoint.java b/src/main/java/emu/grasscutter/data/binout/routes/RoutePoint.java index 9c98c9faa..7a69db4c9 100644 --- a/src/main/java/emu/grasscutter/data/binout/routes/RoutePoint.java +++ b/src/main/java/emu/grasscutter/data/binout/routes/RoutePoint.java @@ -1,34 +1,31 @@ -package emu.grasscutter.data.binout.routes; - -import emu.grasscutter.net.proto.RoutePointOuterClass; -import emu.grasscutter.utils.Position; -import lombok.AccessLevel; -import lombok.Data; -import lombok.Getter; -import lombok.experimental.FieldDefaults; -import lombok.val; - -@Data -@FieldDefaults(level = AccessLevel.PRIVATE) -public class RoutePoint { - private Position pos; - private int speedLevel; //optional - private float waitTime; //optional - private float targetVelocity; //optional - private boolean hasReachEvent; //optional - // rotRoundReachDir //optional Pos with optional values - // rotRoundLeaveDir //optional Pos with optional values - - public RoutePointOuterClass.RoutePoint.Builder toProto(){ - val builder = RoutePointOuterClass.RoutePoint.newBuilder() - .setPosition(pos.toProto()); - if(waitTime!=0){ - builder.setTime(waitTime); - } else if(targetVelocity!=0){ - builder.setVelocity(targetVelocity); - } - - - return builder; - } -} +package emu.grasscutter.data.binout.routes; + +import emu.grasscutter.net.proto.RoutePointOuterClass; +import emu.grasscutter.utils.Position; +import lombok.AccessLevel; +import lombok.Data; +import lombok.experimental.FieldDefaults; +import lombok.val; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +public class RoutePoint { + private Position pos; + private int speedLevel; // optional + private float waitTime; // optional + private float targetVelocity; // optional + private boolean hasReachEvent; // optional + // rotRoundReachDir //optional Pos with optional values + // rotRoundLeaveDir //optional Pos with optional values + + public RoutePointOuterClass.RoutePoint.Builder toProto() { + val builder = RoutePointOuterClass.RoutePoint.newBuilder().setPosition(pos.toProto()); + if (waitTime != 0) { + builder.setTime(waitTime); + } else if (targetVelocity != 0) { + builder.setVelocity(targetVelocity); + } + + return builder; + } +} diff --git a/src/main/java/emu/grasscutter/data/binout/routes/RouteType.java b/src/main/java/emu/grasscutter/data/binout/routes/RouteType.java index afea31311..f251137cf 100644 --- a/src/main/java/emu/grasscutter/data/binout/routes/RouteType.java +++ b/src/main/java/emu/grasscutter/data/binout/routes/RouteType.java @@ -1,23 +1,22 @@ -package emu.grasscutter.data.binout.routes; - -//import emu.grasscutter.scripts.constants.IntValueEnum; -import lombok.Getter; - -public enum RouteType /*implements IntValueEnum*/ { - Unknown(-1), - OneWay(0), - Reciprocate(1), - Loop(2); - - @Getter - private final int id; - - RouteType(int id) { - this.id = id; - } - - //@Override - public int getValue() { - return id; - } -} +package emu.grasscutter.data.binout.routes; + +// import emu.grasscutter.scripts.constants.IntValueEnum; +import lombok.Getter; + +public enum RouteType /*implements IntValueEnum*/ { + Unknown(-1), + OneWay(0), + Reciprocate(1), + Loop(2); + + @Getter private final int id; + + RouteType(int id) { + this.id = id; + } + + // @Override + public int getValue() { + return id; + } +} diff --git a/src/main/java/emu/grasscutter/data/binout/routes/SceneRoutes.java b/src/main/java/emu/grasscutter/data/binout/routes/SceneRoutes.java index 38e0ab95f..134b9e5e3 100644 --- a/src/main/java/emu/grasscutter/data/binout/routes/SceneRoutes.java +++ b/src/main/java/emu/grasscutter/data/binout/routes/SceneRoutes.java @@ -1,15 +1,13 @@ -package emu.grasscutter.data.binout.routes; - -import lombok.AccessLevel; -import lombok.Data; -import lombok.Getter; -import lombok.experimental.FieldDefaults; - -import javax.annotation.Nullable; - -@Data -@FieldDefaults(level = AccessLevel.PRIVATE) -public class SceneRoutes { - private int sceneId; - @Nullable private Route[] routes; -} +package emu.grasscutter.data.binout.routes; + +import javax.annotation.Nullable; +import lombok.AccessLevel; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +public class SceneRoutes { + private int sceneId; + @Nullable private Route[] routes; +} diff --git a/src/main/java/emu/grasscutter/data/common/BaseTrialActivityData.java b/src/main/java/emu/grasscutter/data/common/BaseTrialActivityData.java index aad93a03c..a0aa59d0e 100644 --- a/src/main/java/emu/grasscutter/data/common/BaseTrialActivityData.java +++ b/src/main/java/emu/grasscutter/data/common/BaseTrialActivityData.java @@ -1,8 +1,9 @@ -package emu.grasscutter.data.common; - -import java.util.List; - -public interface BaseTrialActivityData { - List getAvatarIndexIdList(); - List getRewardIdList(); -} +package emu.grasscutter.data.common; + +import java.util.List; + +public interface BaseTrialActivityData { + List getAvatarIndexIdList(); + + List getRewardIdList(); +} diff --git a/src/main/java/emu/grasscutter/data/common/PointData.java b/src/main/java/emu/grasscutter/data/common/PointData.java index f8e6bc254..47ba64b45 100644 --- a/src/main/java/emu/grasscutter/data/common/PointData.java +++ b/src/main/java/emu/grasscutter/data/common/PointData.java @@ -3,7 +3,7 @@ package emu.grasscutter.data.common; import com.google.gson.annotations.SerializedName; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.DailyDungeonData; +import emu.grasscutter.data.excels.dungeon.DailyDungeonData; import emu.grasscutter.utils.Position; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; diff --git a/src/main/java/emu/grasscutter/data/custom/TrialAvatarActivityCustomData.java b/src/main/java/emu/grasscutter/data/custom/TrialAvatarActivityCustomData.java index 5ed215826..2d8e67f05 100644 --- a/src/main/java/emu/grasscutter/data/custom/TrialAvatarActivityCustomData.java +++ b/src/main/java/emu/grasscutter/data/custom/TrialAvatarActivityCustomData.java @@ -1,17 +1,17 @@ -package emu.grasscutter.data.custom; - -import emu.grasscutter.data.common.BaseTrialActivityData; -import lombok.*; -import java.util.List; - -@Data -public class TrialAvatarActivityCustomData implements BaseTrialActivityData { - private int ScheduleId; - private List AvatarIndexIdList; - private List RewardIdList; - - public void onLoad() { - this.AvatarIndexIdList = AvatarIndexIdList.stream().filter(x -> x > 0).toList(); - this.RewardIdList = RewardIdList.stream().filter(x -> x > 0).toList(); - } -} +package emu.grasscutter.data.custom; + +import emu.grasscutter.data.common.BaseTrialActivityData; +import java.util.List; +import lombok.*; + +@Data +public class TrialAvatarActivityCustomData implements BaseTrialActivityData { + private int ScheduleId; + private List AvatarIndexIdList; + private List RewardIdList; + + public void onLoad() { + this.AvatarIndexIdList = AvatarIndexIdList.stream().filter(x -> x > 0).toList(); + this.RewardIdList = RewardIdList.stream().filter(x -> x > 0).toList(); + } +} diff --git a/src/main/java/emu/grasscutter/data/custom/TrialAvatarCustomData.java b/src/main/java/emu/grasscutter/data/custom/TrialAvatarCustomData.java index bcee82fc2..d958c3352 100644 --- a/src/main/java/emu/grasscutter/data/custom/TrialAvatarCustomData.java +++ b/src/main/java/emu/grasscutter/data/custom/TrialAvatarCustomData.java @@ -1,16 +1,16 @@ -package emu.grasscutter.data.custom; - -import lombok.*; -import java.util.List; - -@Data -public class TrialAvatarCustomData { - private int trialAvatarId; - private List trialAvatarParamList; - private int coreProudSkillLevel; - private int skillDepotId; - - public void onLoad() { - this.trialAvatarParamList = trialAvatarParamList.stream().filter(x -> !x.isBlank()).toList(); - } -} +package emu.grasscutter.data.custom; + +import java.util.List; +import lombok.*; + +@Data +public class TrialAvatarCustomData { + private int trialAvatarId; + private List trialAvatarParamList; + private int coreProudSkillLevel; + private int skillDepotId; + + public void onLoad() { + this.trialAvatarParamList = trialAvatarParamList.stream().filter(x -> !x.isBlank()).toList(); + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/DungeonData.java b/src/main/java/emu/grasscutter/data/excels/DungeonData.java deleted file mode 100644 index c558e2620..000000000 --- a/src/main/java/emu/grasscutter/data/excels/DungeonData.java +++ /dev/null @@ -1,33 +0,0 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import lombok.Getter; - -@ResourceType(name = "DungeonExcelConfigData.json") -public class DungeonData extends GameResource { - @Getter(onMethod_ = @Override) - private int id; - - @Getter private int sceneId; - @Getter private int showLevel; - private int passRewardPreviewID; - private String involveType; // TODO enum - - private RewardPreviewData previewData; - - @Getter private int statueCostID; - @Getter private int statueCostCount; - - public RewardPreviewData getRewardPreview() { - return previewData; - } - - @Override - public void onLoad() { - if (this.passRewardPreviewID > 0) { - this.previewData = GameData.getRewardPreviewDataMap().get(this.passRewardPreviewID); - } - } -} diff --git a/src/main/java/emu/grasscutter/data/excels/GuideTriggerData.java b/src/main/java/emu/grasscutter/data/excels/GuideTriggerData.java index ee6c0e47a..23a9af4b6 100644 --- a/src/main/java/emu/grasscutter/data/excels/GuideTriggerData.java +++ b/src/main/java/emu/grasscutter/data/excels/GuideTriggerData.java @@ -1,26 +1,27 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data @EqualsAndHashCode(callSuper=false) -@ResourceType(name = "GuideTriggerExcelConfigData.json") -public class GuideTriggerData extends GameResource { - // more like open state guide than quest guide - private int id; // dont use, just to prevent resource loader from not functioning - private String guideName; - private String type; - private String openState; - - @Override - public int getId() { - return this.id; - } - - public void onLoad() { - GameData.getGuideTriggerDataStringMap().put(getGuideName(), this); - } -} +package emu.grasscutter.data.excels; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = false) +@ResourceType(name = "GuideTriggerExcelConfigData.json") +public class GuideTriggerData extends GameResource { + // more like open state guide than quest guide + private int id; // dont use, just to prevent resource loader from not functioning + private String guideName; + private String type; + private String openState; + + @Override + public int getId() { + return this.id; + } + + public void onLoad() { + GameData.getGuideTriggerDataStringMap().put(getGuideName(), this); + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/QuestData.java b/src/main/java/emu/grasscutter/data/excels/QuestData.java index 010fc6b17..452661596 100644 --- a/src/main/java/emu/grasscutter/data/excels/QuestData.java +++ b/src/main/java/emu/grasscutter/data/excels/QuestData.java @@ -1,109 +1,121 @@ package emu.grasscutter.data.excels; import com.google.gson.annotations.SerializedName; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; -import emu.grasscutter.game.quest.enums.LogicType; -import emu.grasscutter.game.quest.enums.QuestTrigger; +import emu.grasscutter.game.quest.enums.*; +import java.util.ArrayList; import java.util.List; -import lombok.AccessLevel; -import lombok.Data; -import lombok.Getter; -import lombok.ToString; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import lombok.*; import lombok.experimental.FieldDefaults; @ResourceType(name = "QuestExcelConfigData.json") @Getter @ToString public class QuestData extends GameResource { - private int subId; - private int mainId; - private int order; - private long descTextMapHash; + @Getter private int subId; + @Getter private int mainId; + @Getter private int order; + @Getter private long descTextMapHash; - private boolean finishParent; - private boolean isRewind; + @Getter private boolean finishParent; + @Getter private boolean isRewind; - private LogicType acceptCondComb; - private LogicType finishCondComb; - private LogicType failCondComb; + @Getter private LogicType acceptCondComb; + @Getter private LogicType finishCondComb; + @Getter private LogicType failCondComb; - private List acceptCond; - private List finishCond; - private List failCond; - private List beginExec; - private List finishExec; - private List failExec; - private Guide guide; + @Getter private List acceptCond; + @Getter private List finishCond; + @Getter private List failCond; + @Getter private List beginExec; + @Getter private List finishExec; + @Getter private List failExec; + @Getter private Guide guide; + @Getter private List trialAvatarList; + + public static String questConditionKey( + @Nonnull Enum type, int firstParam, @Nullable String paramsStr) { + return type.name() + firstParam + (paramsStr != null ? paramsStr : ""); + } // ResourceLoader not happy if you remove getId() ~~ public int getId() { return subId; } - // Added getSubId() for clarity - public int getSubId() { - return subId; - } - - public int getMainId() { - return mainId; - } - - public int getOrder() { - return order; - } - - public long getDescTextMapHash() { - return descTextMapHash; - } - - public boolean finishParent() { - return finishParent; - } - - public boolean isRewind() { - return isRewind; - } - - public LogicType getAcceptCondComb() { - return acceptCondComb == null ? LogicType.LOGIC_NONE : acceptCondComb; - } - - public List getAcceptCond() { - return acceptCond; - } - - public LogicType getFinishCondComb() { - return finishCondComb == null ? LogicType.LOGIC_NONE : finishCondComb; - } - - public List getFinishCond() { - return finishCond; - } - - public LogicType getFailCondComb() { - return failCondComb == null ? LogicType.LOGIC_NONE : failCondComb; - } - - public List getFailCond() { - return failCond; - } - public void onLoad() { - this.acceptCond = acceptCond.stream().filter(p -> p.type != null).toList(); - this.finishCond = finishCond.stream().filter(p -> p.type != null).toList(); - this.failCond = failCond.stream().filter(p -> p.type != null).toList(); + this.acceptCond = acceptCond.stream().filter(p -> p.getType() != null).toList(); + this.finishCond = finishCond.stream().filter(p -> p.getType() != null).toList(); + this.failCond = failCond.stream().filter(p -> p.getType() != null).toList(); this.beginExec = beginExec.stream().filter(p -> p.type != null).toList(); this.finishExec = finishExec.stream().filter(p -> p.type != null).toList(); this.failExec = failExec.stream().filter(p -> p.type != null).toList(); + + if (this.acceptCondComb == null) this.acceptCondComb = LogicType.LOGIC_NONE; + + if (this.finishCondComb == null) this.finishCondComb = LogicType.LOGIC_NONE; + + if (this.failCondComb == null) this.failCondComb = LogicType.LOGIC_NONE; + + addToCache(); + } + + private void addToCache() { + if (this.acceptCond == null) { + Grasscutter.getLogger().warn("missing AcceptConditions for quest {}", getSubId()); + return; + } + + var cacheMap = GameData.getBeginCondQuestMap(); + if (getAcceptCond().isEmpty()) { + var list = + cacheMap.computeIfAbsent( + QuestData.questConditionKey(QuestCond.QUEST_COND_NONE, 0, null), + e -> new ArrayList<>()); + list.add(this); + } else { + this.getAcceptCond() + .forEach( + questCondition -> { + if (questCondition.getType() == null) { + Grasscutter.getLogger().warn("null accept type for quest {}", getSubId()); + return; + } + + var key = questCondition.asKey(); + var list = cacheMap.computeIfAbsent(key, e -> new ArrayList<>()); + list.add(this); + }); + } } @Data - public static class QuestCondition { + @FieldDefaults(level = AccessLevel.PRIVATE) + public static class QuestExecParam { @SerializedName("_type") - private QuestTrigger type; + QuestExec type; + + @SerializedName("_param") + String[] param; + + @SerializedName("_count") + String count; + } + + public static class QuestAcceptCondition extends QuestCondition {} + + public static class QuestContentCondition extends QuestCondition {} + + @Data + public static class QuestCondition & QuestTrigger> { + @SerializedName("_type") + private TYPE type; @SerializedName("_param") private int[] param; @@ -112,7 +124,11 @@ public class QuestData extends GameResource { private String paramStr; @SerializedName("_count") - private String count; + private int count; + + public String asKey() { + return questConditionKey(getType(), getParam()[0], getParamStr()); + } } @Data @@ -121,17 +137,4 @@ public class QuestData extends GameResource { private List param; private int guideScene; } - - @Data - @FieldDefaults(level = AccessLevel.PRIVATE) - public class QuestExecParam { - @SerializedName("_type") - QuestTrigger type; - - @SerializedName("_param") - String[] param; - - @SerializedName("_count") - String count; - } } diff --git a/src/main/java/emu/grasscutter/data/excels/RefreshPolicyExcelConfigData.java b/src/main/java/emu/grasscutter/data/excels/RefreshPolicyExcelConfigData.java index 70dc56806..a4b0d81bb 100644 --- a/src/main/java/emu/grasscutter/data/excels/RefreshPolicyExcelConfigData.java +++ b/src/main/java/emu/grasscutter/data/excels/RefreshPolicyExcelConfigData.java @@ -1,81 +1,85 @@ -package emu.grasscutter.data.excels; - -import java.util.Arrays; -import java.util.List; - -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import emu.grasscutter.game.props.RefreshType; -import emu.grasscutter.game.world.World; -import lombok.Getter; - -@ResourceType(name = "RefreshPolicyExcelConfigData.json") -public class RefreshPolicyExcelConfigData extends GameResource { - @Getter private int id; - @Getter private RefreshType type; - @Getter private String time; - - private static int upperBound(List list, int low, int high, int value) { - while (low < high) { - int middle = (high + low) / 2; - if(list.size() >= middle) return low; //Just in case - if (list.get(middle) > value) { - high = middle; - } else { - low = middle + 1; - } - } - return low; - } - - public int getIntervalInSeconds(World world) { - if(time.isEmpty()) return -1; - - var currentTimestamp = world.getTotalGameTimeMinutes(); - - try { - List paramsStr = Arrays.asList(time.split(";")); - List params = paramsStr.stream().map(Integer::parseInt).toList(); - - switch(type) { - case REFRESH_NONE: - return -1; - case REFRESH_INTERVAL: - if(params.isEmpty()) return -1; - return params.get(0); - case REFRESH_DAILY: - { - var dayTime = (world.getTotalGameTimeMinutes() / (24 * 60)) * 24 * 60 * 60; - var temp = currentTimestamp - dayTime; - var upper_bound_idx = upperBound(params, (int)params.get(0), (int)params.get(params.size() - 1), (int)temp); - var upper_bound = params.get(upper_bound_idx); - if(params.get(params.size() - 1) == upper_bound) { - return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; - } else if(params.get(0) == upper_bound) { - return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; - } - return (params.get(upper_bound_idx - 1) - params.get(0)); - } - case REFRESH_WEEKlY: - if(params.size() < 2) return -1; - { - var weekTime = (world.getTotalGameTimeDays() / 7) * 60 * 60 * 24 * 7; - var temp = currentTimestamp - weekTime; - var upper_bound_idx = upperBound(params, (int)params.get(0), (int)params.get(params.size() - 1), (int)temp); - var upper_bound = params.get(upper_bound_idx); - if(params.get(params.size() - 1) == upper_bound) { - return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; - } else if(params.get(0) == upper_bound) { - return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; - } - return (params.get(upper_bound_idx - 1) - params.get(0)); - } - case REFRESH_DAYBEGIN_INTERVAL: - if(params.size() == 0) return -1; - return params.get(0) * 60 * 60 * 24; - } - } catch(Exception e) {} - - return -1; - } -} +package emu.grasscutter.data.excels; + +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.game.props.RefreshType; +import emu.grasscutter.game.world.World; +import java.util.Arrays; +import java.util.List; +import lombok.Getter; + +@ResourceType(name = "RefreshPolicyExcelConfigData.json") +public class RefreshPolicyExcelConfigData extends GameResource { + @Getter private int id; + @Getter private RefreshType type; + @Getter private String time; + + private static int upperBound(List list, int low, int high, int value) { + while (low < high) { + int middle = (high + low) / 2; + if (list.size() >= middle) return low; // Just in case + if (list.get(middle) > value) { + high = middle; + } else { + low = middle + 1; + } + } + return low; + } + + public int getIntervalInSeconds(World world) { + if (time.isEmpty()) return -1; + + var currentTimestamp = world.getTotalGameTimeMinutes(); + + try { + List paramsStr = Arrays.asList(time.split(";")); + List params = paramsStr.stream().map(Integer::parseInt).toList(); + + switch (type) { + case REFRESH_NONE: + return -1; + case REFRESH_INTERVAL: + if (params.isEmpty()) return -1; + return params.get(0); + case REFRESH_DAILY: + { + var dayTime = (world.getTotalGameTimeMinutes() / (24 * 60)) * 24 * 60 * 60; + var temp = currentTimestamp - dayTime; + var upper_bound_idx = + upperBound( + params, (int) params.get(0), (int) params.get(params.size() - 1), (int) temp); + var upper_bound = params.get(upper_bound_idx); + if (params.get(params.size() - 1) == upper_bound) { + return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; + } else if (params.get(0) == upper_bound) { + return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; + } + return (params.get(upper_bound_idx - 1) - params.get(0)); + } + case REFRESH_WEEKlY: + if (params.size() < 2) return -1; + { + var weekTime = (world.getTotalGameTimeDays() / 7) * 60 * 60 * 24 * 7; + var temp = currentTimestamp - weekTime; + var upper_bound_idx = + upperBound( + params, (int) params.get(0), (int) params.get(params.size() - 1), (int) temp); + var upper_bound = params.get(upper_bound_idx); + if (params.get(params.size() - 1) == upper_bound) { + return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; + } else if (params.get(0) == upper_bound) { + return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; + } + return (params.get(upper_bound_idx - 1) - params.get(0)); + } + case REFRESH_DAYBEGIN_INTERVAL: + if (params.size() == 0) return -1; + return params.get(0) * 60 * 60 * 24; + } + } catch (Exception e) { + } + + return -1; + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/SceneData.java b/src/main/java/emu/grasscutter/data/excels/SceneData.java index 8c933354b..426765ecb 100644 --- a/src/main/java/emu/grasscutter/data/excels/SceneData.java +++ b/src/main/java/emu/grasscutter/data/excels/SceneData.java @@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; import emu.grasscutter.game.props.SceneType; +import java.util.List; import lombok.Getter; @ResourceType(name = "SceneExcelConfigData.json") @@ -16,4 +17,6 @@ public class SceneData extends GameResource { private SceneType sceneType; private String scriptData; + private String levelEntityConfig; + private List specifiedAvatarList; } diff --git a/src/main/java/emu/grasscutter/data/excels/AchievementData.java b/src/main/java/emu/grasscutter/data/excels/achievement/AchievementData.java similarity index 93% rename from src/main/java/emu/grasscutter/data/excels/AchievementData.java rename to src/main/java/emu/grasscutter/data/excels/achievement/AchievementData.java index e3e1d7c9c..4a28620cf 100644 --- a/src/main/java/emu/grasscutter/data/excels/AchievementData.java +++ b/src/main/java/emu/grasscutter/data/excels/achievement/AchievementData.java @@ -1,9 +1,10 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.achievement; import com.github.davidmoten.guavamini.Lists; import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; +import emu.grasscutter.data.excels.BattlePassMissionData; import java.util.HashSet; import java.util.List; import java.util.Set; diff --git a/src/main/java/emu/grasscutter/data/excels/AchievementGoalData.java b/src/main/java/emu/grasscutter/data/excels/achievement/AchievementGoalData.java similarity index 83% rename from src/main/java/emu/grasscutter/data/excels/AchievementGoalData.java rename to src/main/java/emu/grasscutter/data/excels/achievement/AchievementGoalData.java index e5f1f3035..6266791bb 100644 --- a/src/main/java/emu/grasscutter/data/excels/AchievementGoalData.java +++ b/src/main/java/emu/grasscutter/data/excels/achievement/AchievementGoalData.java @@ -1,13 +1,13 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import lombok.Getter; - -@Getter -@ResourceType(name = "AchievementGoalExcelConfigData.json") -public class AchievementGoalData extends GameResource { - private int id; - private long nameTextMapHash; - private int finishRewardId; -} +package emu.grasscutter.data.excels.achievement; + +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import lombok.Getter; + +@Getter +@ResourceType(name = "AchievementGoalExcelConfigData.json") +public class AchievementGoalData extends GameResource { + private int id; + private long nameTextMapHash; + private int finishRewardId; +} diff --git a/src/main/java/emu/grasscutter/data/excels/ActivityCondExcelConfigData.java b/src/main/java/emu/grasscutter/data/excels/activity/ActivityCondExcelConfigData.java similarity index 83% rename from src/main/java/emu/grasscutter/data/excels/ActivityCondExcelConfigData.java rename to src/main/java/emu/grasscutter/data/excels/activity/ActivityCondExcelConfigData.java index 54defc4f8..5fc02a762 100644 --- a/src/main/java/emu/grasscutter/data/excels/ActivityCondExcelConfigData.java +++ b/src/main/java/emu/grasscutter/data/excels/activity/ActivityCondExcelConfigData.java @@ -1,41 +1,38 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import emu.grasscutter.game.activity.condition.ActivityConditions; -import emu.grasscutter.game.quest.enums.LogicType; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.experimental.FieldDefaults; - -import java.util.List; - -@ResourceType(name = "NewActivityCondExcelConfigData.json") -@Getter -@FieldDefaults(level = AccessLevel.PRIVATE) -public class ActivityCondExcelConfigData extends GameResource { - int condId; - LogicType condComb; - List cond; - - public static class ActivityConfigCondition { - @Getter - private ActivityConditions type; - @Getter - private List param; - - public int[] paramArray() { - return param.stream().mapToInt(Integer::intValue).toArray(); - } - } - - @Override - public int getId() { - return condId; - } - - @Override - public void onLoad() { - cond.removeIf(c -> c.type == null); - } -} +package emu.grasscutter.data.excels.activity; + +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.game.activity.condition.ActivityConditions; +import emu.grasscutter.game.quest.enums.LogicType; +import java.util.List; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.experimental.FieldDefaults; + +@ResourceType(name = "NewActivityCondExcelConfigData.json") +@Getter +@FieldDefaults(level = AccessLevel.PRIVATE) +public class ActivityCondExcelConfigData extends GameResource { + int condId; + LogicType condComb; + List cond; + + public static class ActivityConfigCondition { + @Getter private ActivityConditions type; + @Getter private List param; + + public int[] paramArray() { + return param.stream().mapToInt(Integer::intValue).toArray(); + } + } + + @Override + public int getId() { + return condId; + } + + @Override + public void onLoad() { + cond.removeIf(c -> c.type == null); + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/ActivityData.java b/src/main/java/emu/grasscutter/data/excels/activity/ActivityData.java similarity index 92% rename from src/main/java/emu/grasscutter/data/excels/ActivityData.java rename to src/main/java/emu/grasscutter/data/excels/activity/ActivityData.java index 5f71ec31b..5b8aa2ca0 100644 --- a/src/main/java/emu/grasscutter/data/excels/ActivityData.java +++ b/src/main/java/emu/grasscutter/data/excels/activity/ActivityData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.activity; import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameResource; diff --git a/src/main/java/emu/grasscutter/data/excels/ActivityShopData.java b/src/main/java/emu/grasscutter/data/excels/activity/ActivityShopData.java similarity index 90% rename from src/main/java/emu/grasscutter/data/excels/ActivityShopData.java rename to src/main/java/emu/grasscutter/data/excels/activity/ActivityShopData.java index 052e0572f..de5015a39 100644 --- a/src/main/java/emu/grasscutter/data/excels/ActivityShopData.java +++ b/src/main/java/emu/grasscutter/data/excels/activity/ActivityShopData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.activity; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/ActivityWatcherData.java b/src/main/java/emu/grasscutter/data/excels/activity/ActivityWatcherData.java similarity index 59% rename from src/main/java/emu/grasscutter/data/excels/ActivityWatcherData.java rename to src/main/java/emu/grasscutter/data/excels/activity/ActivityWatcherData.java index 6259edc4a..e77a0b611 100644 --- a/src/main/java/emu/grasscutter/data/excels/ActivityWatcherData.java +++ b/src/main/java/emu/grasscutter/data/excels/activity/ActivityWatcherData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.activity; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; @@ -23,9 +23,10 @@ public class ActivityWatcherData extends GameResource { @Override public void onLoad() { - triggerConfig.paramList = - triggerConfig.paramList.stream().filter(x -> (x != null) && !x.isBlank()).toList(); - triggerConfig.watcherTriggerType = WatcherTriggerType.getTypeByName(triggerConfig.triggerType); + this.triggerConfig.paramList = + this.triggerConfig.paramList.stream().filter(x -> (x != null) && !x.isBlank()).toList(); + this.triggerConfig.watcherTriggerType = + WatcherTriggerType.getTypeByName(this.triggerConfig.triggerType); } @Getter @@ -35,5 +36,10 @@ public class ActivityWatcherData extends GameResource { List paramList; transient WatcherTriggerType watcherTriggerType; + + public void onLoad() { + this.paramList = this.paramList.stream().filter(x -> (x != null) && !x.isBlank()).toList(); + this.watcherTriggerType = WatcherTriggerType.getTypeByName(this.triggerType); + } } } diff --git a/src/main/java/emu/grasscutter/data/excels/AvatarCostumeData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCostumeData.java similarity index 91% rename from src/main/java/emu/grasscutter/data/excels/AvatarCostumeData.java rename to src/main/java/emu/grasscutter/data/excels/avatar/AvatarCostumeData.java index 99d7cfb1d..3563d735c 100644 --- a/src/main/java/emu/grasscutter/data/excels/AvatarCostumeData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCostumeData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.avatar; import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.GameData; diff --git a/src/main/java/emu/grasscutter/data/excels/AvatarCurveData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCurveData.java similarity index 91% rename from src/main/java/emu/grasscutter/data/excels/AvatarCurveData.java rename to src/main/java/emu/grasscutter/data/excels/avatar/AvatarCurveData.java index cf23fcf1b..673b62464 100644 --- a/src/main/java/emu/grasscutter/data/excels/AvatarCurveData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCurveData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.avatar; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/AvatarData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarData.java similarity index 94% rename from src/main/java/emu/grasscutter/data/excels/AvatarData.java rename to src/main/java/emu/grasscutter/data/excels/avatar/AvatarData.java index 3fb1383b7..a4253ff4d 100644 --- a/src/main/java/emu/grasscutter/data/excels/AvatarData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.avatar; import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameResource; @@ -173,16 +173,22 @@ public class AvatarData extends GameResource { */ // Cache abilities - String[] split = this.iconName.split("_"); + this.buildEmbryo(); + } + + /** + * Create ability embryos. + */ + public void buildEmbryo() { + var split = this.iconName.split("_"); if (split.length > 0) { this.name = split[split.length - 1]; - AbilityEmbryoEntry info = GameData.getAbilityEmbryoInfo().get(this.name); + var info = GameData.getAbilityEmbryoInfo().get(this.name); if (info != null) { this.abilities = new IntArrayList(info.getAbilities().length); - for (String ability : info.getAbilities()) { + for (var ability : info.getAbilities()) this.abilities.add(Utils.abilityHash(ability)); - } } } } diff --git a/src/main/java/emu/grasscutter/data/excels/AvatarFetterLevelData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarFetterLevelData.java similarity index 87% rename from src/main/java/emu/grasscutter/data/excels/AvatarFetterLevelData.java rename to src/main/java/emu/grasscutter/data/excels/avatar/AvatarFetterLevelData.java index 21fe202fa..36cdbb8fb 100644 --- a/src/main/java/emu/grasscutter/data/excels/AvatarFetterLevelData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarFetterLevelData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.avatar; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/AvatarFlycloakData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarFlycloakData.java similarity index 87% rename from src/main/java/emu/grasscutter/data/excels/AvatarFlycloakData.java rename to src/main/java/emu/grasscutter/data/excels/avatar/AvatarFlycloakData.java index dbcd4b4cb..2018f61ee 100644 --- a/src/main/java/emu/grasscutter/data/excels/AvatarFlycloakData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarFlycloakData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.avatar; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/AvatarLevelData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarLevelData.java similarity index 86% rename from src/main/java/emu/grasscutter/data/excels/AvatarLevelData.java rename to src/main/java/emu/grasscutter/data/excels/avatar/AvatarLevelData.java index e2bb9bccf..1a87a20c2 100644 --- a/src/main/java/emu/grasscutter/data/excels/AvatarLevelData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarLevelData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.avatar; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/AvatarPromoteData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarPromoteData.java similarity index 94% rename from src/main/java/emu/grasscutter/data/excels/AvatarPromoteData.java rename to src/main/java/emu/grasscutter/data/excels/avatar/AvatarPromoteData.java index ad16eccdd..fc4f306ba 100644 --- a/src/main/java/emu/grasscutter/data/excels/AvatarPromoteData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarPromoteData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.avatar; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/AvatarReplaceCostumeData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarReplaceCostumeData.java similarity index 63% rename from src/main/java/emu/grasscutter/data/excels/AvatarReplaceCostumeData.java rename to src/main/java/emu/grasscutter/data/excels/avatar/AvatarReplaceCostumeData.java index 18bff17b3..003aa8c9f 100644 --- a/src/main/java/emu/grasscutter/data/excels/AvatarReplaceCostumeData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarReplaceCostumeData.java @@ -1,22 +1,24 @@ -package emu.grasscutter.data.excels; - -import com.google.gson.annotations.SerializedName; -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@ResourceType(name = "AvatarReplaceCostumeExcelConfigData.json") -@EqualsAndHashCode(callSuper=false) -public class AvatarReplaceCostumeData extends GameResource { - private int avatarId; - @SerializedName(value = "costumeId", alternate={"MGLCOPOIJIC", "BDBMOBGKIAP"}) - private int costumeId; - - @Override - public int getId() { - return costumeId; - } -} +package emu.grasscutter.data.excels.avatar; + +import com.google.gson.annotations.SerializedName; +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@ResourceType(name = "AvatarReplaceCostumeExcelConfigData.json") +@EqualsAndHashCode(callSuper = false) +public class AvatarReplaceCostumeData extends GameResource { + private int avatarId; + + @SerializedName( + value = "costumeId", + alternate = {"MGLCOPOIJIC", "BDBMOBGKIAP"}) + private int costumeId; + + @Override + public int getId() { + return costumeId; + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/AvatarSkillData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillData.java similarity index 91% rename from src/main/java/emu/grasscutter/data/excels/AvatarSkillData.java rename to src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillData.java index c0f4f289e..7e96ef68f 100644 --- a/src/main/java/emu/grasscutter/data/excels/AvatarSkillData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.avatar; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/AvatarSkillDepotData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillDepotData.java similarity index 96% rename from src/main/java/emu/grasscutter/data/excels/AvatarSkillDepotData.java rename to src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillDepotData.java index 36818138b..978580694 100644 --- a/src/main/java/emu/grasscutter/data/excels/AvatarSkillDepotData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillDepotData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.avatar; import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameDepot; diff --git a/src/main/java/emu/grasscutter/data/excels/AvatarTalentData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarTalentData.java similarity index 93% rename from src/main/java/emu/grasscutter/data/excels/AvatarTalentData.java rename to src/main/java/emu/grasscutter/data/excels/avatar/AvatarTalentData.java index ea71bef91..9c5a76c14 100644 --- a/src/main/java/emu/grasscutter/data/excels/AvatarTalentData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarTalentData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.avatar; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/CodexAnimalData.java b/src/main/java/emu/grasscutter/data/excels/codex/CodexAnimalData.java similarity index 90% rename from src/main/java/emu/grasscutter/data/excels/CodexAnimalData.java rename to src/main/java/emu/grasscutter/data/excels/codex/CodexAnimalData.java index dc7ed944a..e71214d75 100644 --- a/src/main/java/emu/grasscutter/data/excels/CodexAnimalData.java +++ b/src/main/java/emu/grasscutter/data/excels/codex/CodexAnimalData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.codex; import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.GameResource; diff --git a/src/main/java/emu/grasscutter/data/excels/CodexMaterialData.java b/src/main/java/emu/grasscutter/data/excels/codex/CodexMaterialData.java similarity index 89% rename from src/main/java/emu/grasscutter/data/excels/CodexMaterialData.java rename to src/main/java/emu/grasscutter/data/excels/codex/CodexMaterialData.java index 3ab32be5c..fd781bf9e 100644 --- a/src/main/java/emu/grasscutter/data/excels/CodexMaterialData.java +++ b/src/main/java/emu/grasscutter/data/excels/codex/CodexMaterialData.java @@ -1,29 +1,29 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; - -@ResourceType(name = {"MaterialCodexExcelConfigData.json"}) -public class CodexMaterialData extends GameResource { - private int Id; - private int materialId; - private int sortOrder; - - public int getSortOrder() { - return sortOrder; - } - - public int getMaterialId() { - return materialId; - } - - public int getId() { - return Id; - } - - @Override - public void onLoad() { - GameData.getCodexMaterialDataIdMap().put(this.getMaterialId(), this); - } -} +package emu.grasscutter.data.excels.codex; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; + +@ResourceType(name = {"MaterialCodexExcelConfigData.json"}) +public class CodexMaterialData extends GameResource { + private int Id; + private int materialId; + private int sortOrder; + + public int getSortOrder() { + return sortOrder; + } + + public int getMaterialId() { + return materialId; + } + + public int getId() { + return Id; + } + + @Override + public void onLoad() { + GameData.getCodexMaterialDataIdMap().put(this.getMaterialId(), this); + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/CodexQuestData.java b/src/main/java/emu/grasscutter/data/excels/codex/CodexQuestData.java similarity index 91% rename from src/main/java/emu/grasscutter/data/excels/CodexQuestData.java rename to src/main/java/emu/grasscutter/data/excels/codex/CodexQuestData.java index a78361df4..be94b9f65 100644 --- a/src/main/java/emu/grasscutter/data/excels/CodexQuestData.java +++ b/src/main/java/emu/grasscutter/data/excels/codex/CodexQuestData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.codex; import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameResource; diff --git a/src/main/java/emu/grasscutter/data/excels/CodexReliquaryData.java b/src/main/java/emu/grasscutter/data/excels/codex/CodexReliquaryData.java similarity index 94% rename from src/main/java/emu/grasscutter/data/excels/CodexReliquaryData.java rename to src/main/java/emu/grasscutter/data/excels/codex/CodexReliquaryData.java index 47c1631ff..b4e1fc02c 100644 --- a/src/main/java/emu/grasscutter/data/excels/CodexReliquaryData.java +++ b/src/main/java/emu/grasscutter/data/excels/codex/CodexReliquaryData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.codex; import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameResource; diff --git a/src/main/java/emu/grasscutter/data/excels/CodexWeaponData.java b/src/main/java/emu/grasscutter/data/excels/codex/CodexWeaponData.java similarity index 89% rename from src/main/java/emu/grasscutter/data/excels/CodexWeaponData.java rename to src/main/java/emu/grasscutter/data/excels/codex/CodexWeaponData.java index 7b08290ec..6ca25aa1e 100644 --- a/src/main/java/emu/grasscutter/data/excels/CodexWeaponData.java +++ b/src/main/java/emu/grasscutter/data/excels/codex/CodexWeaponData.java @@ -1,29 +1,29 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; - -@ResourceType(name = {"WeaponCodexExcelConfigData.json"}) -public class CodexWeaponData extends GameResource { - private int Id; - private int weaponId; - private int sortOrder; - - public int getSortOrder() { - return sortOrder; - } - - public int getWeaponId() { - return weaponId; - } - - public int getId() { - return Id; - } - - @Override - public void onLoad() { - GameData.getCodexWeaponDataIdMap().put(this.getWeaponId(), this); - } -} +package emu.grasscutter.data.excels.codex; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; + +@ResourceType(name = {"WeaponCodexExcelConfigData.json"}) +public class CodexWeaponData extends GameResource { + private int Id; + private int weaponId; + private int sortOrder; + + public int getSortOrder() { + return sortOrder; + } + + public int getWeaponId() { + return weaponId; + } + + public int getId() { + return Id; + } + + @Override + public void onLoad() { + GameData.getCodexWeaponDataIdMap().put(this.getWeaponId(), this); + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/DailyDungeonData.java b/src/main/java/emu/grasscutter/data/excels/dungeon/DailyDungeonData.java similarity index 93% rename from src/main/java/emu/grasscutter/data/excels/DailyDungeonData.java rename to src/main/java/emu/grasscutter/data/excels/dungeon/DailyDungeonData.java index db6701f17..f823f7bcd 100644 --- a/src/main/java/emu/grasscutter/data/excels/DailyDungeonData.java +++ b/src/main/java/emu/grasscutter/data/excels/dungeon/DailyDungeonData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.dungeon; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/DungeonChallengeConfigData.java b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonChallengeConfigData.java similarity index 70% rename from src/main/java/emu/grasscutter/data/excels/DungeonChallengeConfigData.java rename to src/main/java/emu/grasscutter/data/excels/dungeon/DungeonChallengeConfigData.java index 8186e26ff..3bdb43f29 100644 --- a/src/main/java/emu/grasscutter/data/excels/DungeonChallengeConfigData.java +++ b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonChallengeConfigData.java @@ -1,72 +1,82 @@ -package emu.grasscutter.data.excels; - -import com.google.gson.annotations.SerializedName; -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; - -import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; -import lombok.Getter; - -import java.util.HashSet; - -@Getter -@ResourceType(name = "DungeonChallengeConfigData.json") -public class DungeonChallengeConfigData extends GameResource { - private int id; - private ChallengeType challengeType; - private boolean noSuccessHint; - private boolean noFailHint; - private boolean isBlockTopTimer; - private int subChallengeFadeOutDelayTime; - private int activitySkillId; - private HashSet teamAbilityGroupList; - - private SubChallengeFadeOutType subChallengeFadeOutRule; - private SubChallengeBannerType subChallengeBannerRule; - private InterruptButtonType interruptButtonType; - - @SerializedName(value = "subChallengeSortType", alternate={"PNCLDNBHKDJ"}) - private SubChallengeSortType subChallengeSortType; - @SerializedName(value = "animationOnSubStart", alternate={"DNFAFNMMMDP"}) - private AllowAnimationType animationOnSubStart; - @SerializedName(value = "animationOnSubSuccess", alternate={"ENONHOGJDDN"}) - private AllowAnimationType animationOnSubSuccess; - @SerializedName(value = "animationOnSubFail", alternate={"NJBJIKAIENN"}) - private AllowAnimationType animationOnSubFail; - - public int getId() { - return id; - } - - public enum InterruptButtonType{ - INTERRUPT_BUTTON_TYPE_NONE, - INTERRUPT_BUTTON_TYPE_HOST, - INTERRUPT_BUTTON_TYPE_ALL - } - - public enum SubChallengeFadeOutType{ - SUBCHALLENGE_FADEOUT_TYPE_NONE, - SUBCHALLENGE_FADEOUT_TYPE_SUCCESS, - SUBCHALLENGE_FADEOUT_TYPE_FAIL, - SUBCHALLENGE_FADEOUT_TYPE_FINISH - } - - public enum SubChallengeBannerType{ - SUBCHALLENGE_BANNER_TYPE_NONE, - SUBCHALLENGE_BANNER_TYPE_SUCCESS, - SUBCHALLENGE_BANNER_TYPE_FAIL, - SUBCHALLENGE_BANNER_TYPE_HIDE_FINAL, - SUBCHALLENGE_BANNER_TYPE_SHOW_FINAL - } - public enum SubChallengeSortType{ - SUB_CHALLENGE_SORT_TYPE_DEFAULT, - SUB_CHALLENGE_SORT_TYPE_CHALLENGEINDEX - } - - public enum AllowAnimationType{ - SUB_CHALLENGE_ANIM_TYPE_DEFAULT, - SUB_CHALLENGE_ANIM_TYPE_FORBID, - SUB_CHALLENGE_ANIM_TYPE_SUCCESS, - SUB_CHALLENGE_ANIM_TYPE_FAIL - } -} +package emu.grasscutter.data.excels.dungeon; + +import com.google.gson.annotations.SerializedName; +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; +import java.util.HashSet; +import lombok.Getter; + +@Getter +@ResourceType(name = "DungeonChallengeConfigData.json") +public class DungeonChallengeConfigData extends GameResource { + private int id; + private ChallengeType challengeType; + private boolean noSuccessHint; + private boolean noFailHint; + private boolean isBlockTopTimer; + private int subChallengeFadeOutDelayTime; + private int activitySkillId; + private HashSet teamAbilityGroupList; + + private SubChallengeFadeOutType subChallengeFadeOutRule; + private SubChallengeBannerType subChallengeBannerRule; + private InterruptButtonType interruptButtonType; + + @SerializedName( + value = "subChallengeSortType", + alternate = {"PNCLDNBHKDJ"}) + private SubChallengeSortType subChallengeSortType; + + @SerializedName( + value = "animationOnSubStart", + alternate = {"DNFAFNMMMDP"}) + private AllowAnimationType animationOnSubStart; + + @SerializedName( + value = "animationOnSubSuccess", + alternate = {"ENONHOGJDDN"}) + private AllowAnimationType animationOnSubSuccess; + + @SerializedName( + value = "animationOnSubFail", + alternate = {"NJBJIKAIENN"}) + private AllowAnimationType animationOnSubFail; + + public int getId() { + return id; + } + + public enum InterruptButtonType { + INTERRUPT_BUTTON_TYPE_NONE, + INTERRUPT_BUTTON_TYPE_HOST, + INTERRUPT_BUTTON_TYPE_ALL + } + + public enum SubChallengeFadeOutType { + SUBCHALLENGE_FADEOUT_TYPE_NONE, + SUBCHALLENGE_FADEOUT_TYPE_SUCCESS, + SUBCHALLENGE_FADEOUT_TYPE_FAIL, + SUBCHALLENGE_FADEOUT_TYPE_FINISH + } + + public enum SubChallengeBannerType { + SUBCHALLENGE_BANNER_TYPE_NONE, + SUBCHALLENGE_BANNER_TYPE_SUCCESS, + SUBCHALLENGE_BANNER_TYPE_FAIL, + SUBCHALLENGE_BANNER_TYPE_HIDE_FINAL, + SUBCHALLENGE_BANNER_TYPE_SHOW_FINAL + } + + public enum SubChallengeSortType { + SUB_CHALLENGE_SORT_TYPE_DEFAULT, + SUB_CHALLENGE_SORT_TYPE_CHALLENGEINDEX + } + + public enum AllowAnimationType { + SUB_CHALLENGE_ANIM_TYPE_DEFAULT, + SUB_CHALLENGE_ANIM_TYPE_FORBID, + SUB_CHALLENGE_ANIM_TYPE_SUCCESS, + SUB_CHALLENGE_ANIM_TYPE_FAIL + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonData.java b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonData.java new file mode 100644 index 000000000..6e3e0b037 --- /dev/null +++ b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonData.java @@ -0,0 +1,71 @@ +package emu.grasscutter.data.excels.dungeon; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.data.excels.RewardPreviewData; +import emu.grasscutter.game.dungeons.enums.*; +import java.util.List; +import lombok.Getter; + +@ResourceType(name = "DungeonExcelConfigData.json") +public class DungeonData extends GameResource { + + @Getter(onMethod = @__(@Override)) + private int id; + + @Getter private int sceneId; + @Getter private int showLevel; + private DungeonType type; + private DungeonSubType subType; + private DungeonPlayType playType; + private DungeonInvolveType involveType; + @Getter private int limitLevel; + @Getter private int passCond; + @Getter private int reviveMaxCount; + @Getter private int settleCountdownTime; + @Getter private int failSettleCountdownTime; + @Getter private int quitSettleCountdownTime; + @Getter private List settleShows; + @Getter private int passRewardPreviewID; + @Getter private int statueCostID; + @Getter private int statueCostCount; + + // not part of DungeonExcelConfigData + @Getter private RewardPreviewData rewardPreviewData; + + public DungeonType getType() { + if (type == null) { + return DungeonType.DUNGEON_NONE; + } + return type; + } + + public DungeonSubType getSubType() { + if (subType == null) { + return DungeonSubType.DUNGEON_SUB_NONE; + } + return subType; + } + + public DungeonPlayType getPlayType() { + if (playType == null) { + return DungeonPlayType.DUNGEON_PLAY_TYPE_NONE; + } + return playType; + } + + public DungeonInvolveType getInvolveType() { + if (involveType == null) { + return DungeonInvolveType.INVOLVE_NONE; + } + return involveType; + } + + @Override + public void onLoad() { + if (this.passRewardPreviewID > 0) { + this.rewardPreviewData = GameData.getRewardPreviewDataMap().get(this.passRewardPreviewID); + } + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/DungeonEntryData.java b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonEntryData.java similarity index 86% rename from src/main/java/emu/grasscutter/data/excels/DungeonEntryData.java rename to src/main/java/emu/grasscutter/data/excels/dungeon/DungeonEntryData.java index 3b21cd97e..8c2e77f24 100644 --- a/src/main/java/emu/grasscutter/data/excels/DungeonEntryData.java +++ b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonEntryData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.dungeon; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/DungeonPassConfigData.java b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonPassConfigData.java similarity index 79% rename from src/main/java/emu/grasscutter/data/excels/DungeonPassConfigData.java rename to src/main/java/emu/grasscutter/data/excels/dungeon/DungeonPassConfigData.java index 2702483a8..79b39328b 100644 --- a/src/main/java/emu/grasscutter/data/excels/DungeonPassConfigData.java +++ b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonPassConfigData.java @@ -1,28 +1,26 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; - -import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; -import emu.grasscutter.game.quest.enums.LogicType; -import lombok.Getter; - -import java.util.List; - -@ResourceType(name = "DungeonPassExcelConfigData.json") -public class DungeonPassConfigData extends GameResource { - @Getter private int id; - @Getter private LogicType logicType; - @Getter private List conds; - - public static class DungeonPassCondition{ - @Getter private DungeonPassConditionType condType; - @Getter int[] param; - } - - @Override - public void onLoad() { - super.onLoad(); - conds = conds.stream().filter(condition -> condition.getCondType()!=null).toList(); - } -} +package emu.grasscutter.data.excels.dungeon; + +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import emu.grasscutter.game.quest.enums.LogicType; +import java.util.List; +import lombok.Getter; + +@ResourceType(name = "DungeonPassExcelConfigData.json") +public class DungeonPassConfigData extends GameResource { + @Getter private int id; + @Getter private LogicType logicType; + @Getter private List conds; + + public static class DungeonPassCondition { + @Getter private DungeonPassConditionType condType; + @Getter int[] param; + } + + @Override + public void onLoad() { + super.onLoad(); + conds = conds.stream().filter(condition -> condition.getCondType() != null).toList(); + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/MonsterCurveData.java b/src/main/java/emu/grasscutter/data/excels/monster/MonsterCurveData.java similarity index 91% rename from src/main/java/emu/grasscutter/data/excels/MonsterCurveData.java rename to src/main/java/emu/grasscutter/data/excels/monster/MonsterCurveData.java index e7e0370f9..d52fd053a 100644 --- a/src/main/java/emu/grasscutter/data/excels/MonsterCurveData.java +++ b/src/main/java/emu/grasscutter/data/excels/monster/MonsterCurveData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.monster; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/MonsterData.java b/src/main/java/emu/grasscutter/data/excels/monster/MonsterData.java similarity index 94% rename from src/main/java/emu/grasscutter/data/excels/MonsterData.java rename to src/main/java/emu/grasscutter/data/excels/monster/MonsterData.java index 6498d1cf1..03dd10682 100644 --- a/src/main/java/emu/grasscutter/data/excels/MonsterData.java +++ b/src/main/java/emu/grasscutter/data/excels/monster/MonsterData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.monster; import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.GameData; @@ -6,6 +6,7 @@ import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; import emu.grasscutter.data.ResourceType.LoadPriority; import emu.grasscutter.data.common.PropGrowCurve; +import emu.grasscutter.data.excels.GadgetData; import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.MonsterType; import java.util.List; diff --git a/src/main/java/emu/grasscutter/data/excels/MonsterDescribeData.java b/src/main/java/emu/grasscutter/data/excels/monster/MonsterDescribeData.java similarity index 88% rename from src/main/java/emu/grasscutter/data/excels/MonsterDescribeData.java rename to src/main/java/emu/grasscutter/data/excels/monster/MonsterDescribeData.java index c5847d6b0..f20d001ae 100644 --- a/src/main/java/emu/grasscutter/data/excels/MonsterDescribeData.java +++ b/src/main/java/emu/grasscutter/data/excels/monster/MonsterDescribeData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.monster; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/MonsterSpecialNameData.java b/src/main/java/emu/grasscutter/data/excels/monster/MonsterSpecialNameData.java similarity index 83% rename from src/main/java/emu/grasscutter/data/excels/MonsterSpecialNameData.java rename to src/main/java/emu/grasscutter/data/excels/monster/MonsterSpecialNameData.java index 698bd0ac3..be8cbae58 100644 --- a/src/main/java/emu/grasscutter/data/excels/MonsterSpecialNameData.java +++ b/src/main/java/emu/grasscutter/data/excels/monster/MonsterSpecialNameData.java @@ -1,21 +1,21 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import emu.grasscutter.data.ResourceType.LoadPriority; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@ResourceType(name = "MonsterSpecialNameExcelConfigData.json", loadPriority = LoadPriority.HIGH) -@EqualsAndHashCode(callSuper=false) -@Data -public class MonsterSpecialNameData extends GameResource { - private int specialNameId; - private int specialNameLabId; - private long specialNameTextMapHash; - - @Override - public int getId() { - return specialNameId; - } -} +package emu.grasscutter.data.excels.monster; + +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.data.ResourceType.LoadPriority; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ResourceType(name = "MonsterSpecialNameExcelConfigData.json", loadPriority = LoadPriority.HIGH) +@EqualsAndHashCode(callSuper = false) +@Data +public class MonsterSpecialNameData extends GameResource { + private int specialNameId; + private int specialNameLabId; + private long specialNameTextMapHash; + + @Override + public int getId() { + return specialNameId; + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/ReliquaryAffixData.java b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryAffixData.java similarity index 89% rename from src/main/java/emu/grasscutter/data/excels/ReliquaryAffixData.java rename to src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryAffixData.java index 65863eee3..9b6a80119 100644 --- a/src/main/java/emu/grasscutter/data/excels/ReliquaryAffixData.java +++ b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryAffixData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.reliquary; import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.GameResource; diff --git a/src/main/java/emu/grasscutter/data/excels/ReliquaryLevelData.java b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryLevelData.java similarity index 93% rename from src/main/java/emu/grasscutter/data/excels/ReliquaryLevelData.java rename to src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryLevelData.java index e0dec94ed..ae1472c68 100644 --- a/src/main/java/emu/grasscutter/data/excels/ReliquaryLevelData.java +++ b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryLevelData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.reliquary; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/ReliquaryMainPropData.java b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryMainPropData.java similarity index 88% rename from src/main/java/emu/grasscutter/data/excels/ReliquaryMainPropData.java rename to src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryMainPropData.java index 8280b1dcf..b3d577b93 100644 --- a/src/main/java/emu/grasscutter/data/excels/ReliquaryMainPropData.java +++ b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryMainPropData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.reliquary; import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.GameResource; diff --git a/src/main/java/emu/grasscutter/data/excels/ReliquarySetData.java b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquarySetData.java similarity index 89% rename from src/main/java/emu/grasscutter/data/excels/ReliquarySetData.java rename to src/main/java/emu/grasscutter/data/excels/reliquary/ReliquarySetData.java index 603d987ef..f59b25786 100644 --- a/src/main/java/emu/grasscutter/data/excels/ReliquarySetData.java +++ b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquarySetData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.reliquary; import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.GameResource; diff --git a/src/main/java/emu/grasscutter/data/excels/TowerFloorData.java b/src/main/java/emu/grasscutter/data/excels/tower/TowerFloorData.java similarity index 88% rename from src/main/java/emu/grasscutter/data/excels/TowerFloorData.java rename to src/main/java/emu/grasscutter/data/excels/tower/TowerFloorData.java index e3e55238d..62c9c3770 100644 --- a/src/main/java/emu/grasscutter/data/excels/TowerFloorData.java +++ b/src/main/java/emu/grasscutter/data/excels/tower/TowerFloorData.java @@ -1,21 +1,21 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import lombok.Getter; - -@ResourceType(name = "TowerFloorExcelConfigData.json") -@Getter -public class TowerFloorData extends GameResource { - private int floorId; - private int floorIndex; - private int levelGroupId; - private int overrideMonsterLevel; - private int teamNum; - private int floorLevelConfigId; - - @Override - public int getId() { - return this.floorId; - } -} +package emu.grasscutter.data.excels.tower; + +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import lombok.Getter; + +@ResourceType(name = "TowerFloorExcelConfigData.json") +@Getter +public class TowerFloorData extends GameResource { + private int floorId; + private int floorIndex; + private int levelGroupId; + private int overrideMonsterLevel; + private int teamNum; + private int floorLevelConfigId; + + @Override + public int getId() { + return this.floorId; + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/TowerLevelData.java b/src/main/java/emu/grasscutter/data/excels/tower/TowerLevelData.java similarity index 89% rename from src/main/java/emu/grasscutter/data/excels/TowerLevelData.java rename to src/main/java/emu/grasscutter/data/excels/tower/TowerLevelData.java index c6bec8c07..f9f96f89b 100644 --- a/src/main/java/emu/grasscutter/data/excels/TowerLevelData.java +++ b/src/main/java/emu/grasscutter/data/excels/tower/TowerLevelData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.tower; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/TowerScheduleData.java b/src/main/java/emu/grasscutter/data/excels/tower/TowerScheduleData.java similarity index 92% rename from src/main/java/emu/grasscutter/data/excels/TowerScheduleData.java rename to src/main/java/emu/grasscutter/data/excels/tower/TowerScheduleData.java index 4c55a7a36..6cfa25ef1 100644 --- a/src/main/java/emu/grasscutter/data/excels/TowerScheduleData.java +++ b/src/main/java/emu/grasscutter/data/excels/tower/TowerScheduleData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.tower; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/TrialAvatarActivityData.java b/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarActivityData.java similarity index 83% rename from src/main/java/emu/grasscutter/data/excels/TrialAvatarActivityData.java rename to src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarActivityData.java index 8c718c46e..073d09362 100644 --- a/src/main/java/emu/grasscutter/data/excels/TrialAvatarActivityData.java +++ b/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarActivityData.java @@ -1,21 +1,21 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import emu.grasscutter.data.common.BaseTrialActivityData; -import lombok.*; -import java.util.List; - -@ResourceType(name = "TrialAvatarActivityExcelConfigData.json") -@EqualsAndHashCode(callSuper=false) -@Data -public class TrialAvatarActivityData extends GameResource implements BaseTrialActivityData { - private int ScheduleId; - private List AvatarIndexIdList; - private List RewardIdList; - - @Override - public int getId() { - return ScheduleId; - } -} +package emu.grasscutter.data.excels.trial; + +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.data.common.BaseTrialActivityData; +import java.util.List; +import lombok.*; + +@ResourceType(name = "TrialAvatarActivityExcelConfigData.json") +@EqualsAndHashCode(callSuper = false) +@Data +public class TrialAvatarActivityData extends GameResource implements BaseTrialActivityData { + private int ScheduleId; + private List AvatarIndexIdList; + private List RewardIdList; + + @Override + public int getId() { + return ScheduleId; + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/TrialAvatarActivityDataData.java b/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarActivityDataData.java similarity index 79% rename from src/main/java/emu/grasscutter/data/excels/TrialAvatarActivityDataData.java rename to src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarActivityDataData.java index 1ec230f97..327a996f3 100644 --- a/src/main/java/emu/grasscutter/data/excels/TrialAvatarActivityDataData.java +++ b/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarActivityDataData.java @@ -1,29 +1,31 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import lombok.*; -import lombok.experimental.FieldDefaults; - -@ResourceType(name = "TrialAvatarActivityDataExcelConfigData.json") -@EqualsAndHashCode(callSuper=false) -@Data -@FieldDefaults(level = AccessLevel.PRIVATE) -public class TrialAvatarActivityDataData extends GameResource { - @Getter(onMethod = @__(@Override)) - private int id; - private int trialAvatarIndexId; - private int trialAvatarId; - private int dungeonId; - private String battleAvatarsList; - private int firstPassReward; - private ActivityWatcherData.WatcherTrigger triggerConfig; - private int progress; - - @Override - public void onLoad() { - triggerConfig.onLoad(); - GameData.getTrialAvatarIndexIdTrialActivityDataDataMap().put(trialAvatarIndexId, id); - } -} +package emu.grasscutter.data.excels.trial; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.data.excels.activity.ActivityWatcherData; +import lombok.*; +import lombok.experimental.FieldDefaults; + +@ResourceType(name = "TrialAvatarActivityDataExcelConfigData.json") +@EqualsAndHashCode(callSuper = false) +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +public class TrialAvatarActivityDataData extends GameResource { + @Getter(onMethod = @__(@Override)) + private int id; + + private int trialAvatarIndexId; + private int trialAvatarId; + private int dungeonId; + private String battleAvatarsList; + private int firstPassReward; + private ActivityWatcherData.WatcherTrigger triggerConfig; + private int progress; + + @Override + public void onLoad() { + this.triggerConfig.onLoad(); + GameData.getTrialAvatarIndexIdTrialActivityDataDataMap().put(trialAvatarIndexId, id); + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/TrialAvatarData.java b/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarData.java similarity index 79% rename from src/main/java/emu/grasscutter/data/excels/TrialAvatarData.java rename to src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarData.java index 165f1a78c..a856e82bc 100644 --- a/src/main/java/emu/grasscutter/data/excels/TrialAvatarData.java +++ b/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarData.java @@ -1,19 +1,19 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import lombok.*; -import java.util.List; - -@ResourceType(name = "TrialAvatarExcelConfigData.json") -@EqualsAndHashCode(callSuper=false) -@Data -public class TrialAvatarData extends GameResource { - private int trialAvatarId; - private List trialAvatarParamList; - - @Override - public int getId() { - return trialAvatarId; - } -} +package emu.grasscutter.data.excels.trial; + +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import java.util.List; +import lombok.*; + +@ResourceType(name = "TrialAvatarExcelConfigData.json") +@EqualsAndHashCode(callSuper = false) +@Data +public class TrialAvatarData extends GameResource { + private int trialAvatarId; + private List trialAvatarParamList; + + @Override + public int getId() { + return trialAvatarId; + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/TrialAvatarTemplateData.java b/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarTemplateData.java similarity index 81% rename from src/main/java/emu/grasscutter/data/excels/TrialAvatarTemplateData.java rename to src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarTemplateData.java index 63c08c6fa..16bdf331e 100644 --- a/src/main/java/emu/grasscutter/data/excels/TrialAvatarTemplateData.java +++ b/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarTemplateData.java @@ -1,20 +1,20 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import lombok.*; -import java.util.List; - -@ResourceType(name = "TrialAvatarTemplateExcelConfigData.json") -@EqualsAndHashCode(callSuper=false) -@Data -public class TrialAvatarTemplateData extends GameResource { - private int TrialAvatarLevel; - private List TrialReliquaryList; - private int TrialAvatarSkillLevel; - - @Override - public int getId() { - return TrialAvatarLevel; - } -} +package emu.grasscutter.data.excels.trial; + +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import java.util.List; +import lombok.*; + +@ResourceType(name = "TrialAvatarTemplateExcelConfigData.json") +@EqualsAndHashCode(callSuper = false) +@Data +public class TrialAvatarTemplateData extends GameResource { + private int TrialAvatarLevel; + private List TrialReliquaryList; + private int TrialAvatarSkillLevel; + + @Override + public int getId() { + return TrialAvatarLevel; + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/TrialReliquaryData.java b/src/main/java/emu/grasscutter/data/excels/trial/TrialReliquaryData.java similarity index 81% rename from src/main/java/emu/grasscutter/data/excels/TrialReliquaryData.java rename to src/main/java/emu/grasscutter/data/excels/trial/TrialReliquaryData.java index 3dcfb8297..34d6db2ba 100644 --- a/src/main/java/emu/grasscutter/data/excels/TrialReliquaryData.java +++ b/src/main/java/emu/grasscutter/data/excels/trial/TrialReliquaryData.java @@ -1,22 +1,22 @@ -package emu.grasscutter.data.excels; - -import emu.grasscutter.data.GameResource; -import emu.grasscutter.data.ResourceType; -import lombok.*; -import java.util.List; - -@ResourceType(name = "TrialReliquaryExcelConfigData.json") -@EqualsAndHashCode(callSuper=false) -@Data -public class TrialReliquaryData extends GameResource { - private int Id; - private int ReliquaryId; - private int Level; - private int MainPropId; - private List AppendPropList; - - @Override - public int getId() { - return Id; - } -} +package emu.grasscutter.data.excels.trial; + +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import java.util.List; +import lombok.*; + +@ResourceType(name = "TrialReliquaryExcelConfigData.json") +@EqualsAndHashCode(callSuper = false) +@Data +public class TrialReliquaryData extends GameResource { + private int Id; + private int ReliquaryId; + private int Level; + private int MainPropId; + private List AppendPropList; + + @Override + public int getId() { + return Id; + } +} diff --git a/src/main/java/emu/grasscutter/data/excels/WeaponCurveData.java b/src/main/java/emu/grasscutter/data/excels/weapon/WeaponCurveData.java similarity index 91% rename from src/main/java/emu/grasscutter/data/excels/WeaponCurveData.java rename to src/main/java/emu/grasscutter/data/excels/weapon/WeaponCurveData.java index 92fe9c097..4f7efd353 100644 --- a/src/main/java/emu/grasscutter/data/excels/WeaponCurveData.java +++ b/src/main/java/emu/grasscutter/data/excels/weapon/WeaponCurveData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.weapon; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/WeaponLevelData.java b/src/main/java/emu/grasscutter/data/excels/weapon/WeaponLevelData.java similarity index 87% rename from src/main/java/emu/grasscutter/data/excels/WeaponLevelData.java rename to src/main/java/emu/grasscutter/data/excels/weapon/WeaponLevelData.java index 24375d286..89600c174 100644 --- a/src/main/java/emu/grasscutter/data/excels/WeaponLevelData.java +++ b/src/main/java/emu/grasscutter/data/excels/weapon/WeaponLevelData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.weapon; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/WeaponPromoteData.java b/src/main/java/emu/grasscutter/data/excels/weapon/WeaponPromoteData.java similarity index 94% rename from src/main/java/emu/grasscutter/data/excels/WeaponPromoteData.java rename to src/main/java/emu/grasscutter/data/excels/weapon/WeaponPromoteData.java index ce8da7747..ec527b783 100644 --- a/src/main/java/emu/grasscutter/data/excels/WeaponPromoteData.java +++ b/src/main/java/emu/grasscutter/data/excels/weapon/WeaponPromoteData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.weapon; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/WeatherData.java b/src/main/java/emu/grasscutter/data/excels/world/WeatherData.java similarity index 91% rename from src/main/java/emu/grasscutter/data/excels/WeatherData.java rename to src/main/java/emu/grasscutter/data/excels/world/WeatherData.java index 9f5a639b5..e2d685df8 100644 --- a/src/main/java/emu/grasscutter/data/excels/WeatherData.java +++ b/src/main/java/emu/grasscutter/data/excels/world/WeatherData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.world; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/WorldAreaData.java b/src/main/java/emu/grasscutter/data/excels/world/WorldAreaData.java similarity index 89% rename from src/main/java/emu/grasscutter/data/excels/WorldAreaData.java rename to src/main/java/emu/grasscutter/data/excels/world/WorldAreaData.java index 320a2c8ba..8b9fa73e3 100644 --- a/src/main/java/emu/grasscutter/data/excels/WorldAreaData.java +++ b/src/main/java/emu/grasscutter/data/excels/world/WorldAreaData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.world; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/excels/WorldLevelData.java b/src/main/java/emu/grasscutter/data/excels/world/WorldLevelData.java similarity index 86% rename from src/main/java/emu/grasscutter/data/excels/WorldLevelData.java rename to src/main/java/emu/grasscutter/data/excels/world/WorldLevelData.java index 6febcad91..40ed98a90 100644 --- a/src/main/java/emu/grasscutter/data/excels/WorldLevelData.java +++ b/src/main/java/emu/grasscutter/data/excels/world/WorldLevelData.java @@ -1,4 +1,4 @@ -package emu.grasscutter.data.excels; +package emu.grasscutter.data.excels.world; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; diff --git a/src/main/java/emu/grasscutter/data/server/ActivityCondGroup.java b/src/main/java/emu/grasscutter/data/server/ActivityCondGroup.java index 1d0087249..7f40ad88f 100644 --- a/src/main/java/emu/grasscutter/data/server/ActivityCondGroup.java +++ b/src/main/java/emu/grasscutter/data/server/ActivityCondGroup.java @@ -1,11 +1,10 @@ -package emu.grasscutter.data.server; - -import lombok.Data; - -import java.util.List; - -@Data -public class ActivityCondGroup { - int condGroupId; - List condIds; -} +package emu.grasscutter.data.server; + +import java.util.List; +import lombok.Data; + +@Data +public class ActivityCondGroup { + int condGroupId; + List condIds; +} diff --git a/src/main/java/emu/grasscutter/data/server/GadgetMapping.java b/src/main/java/emu/grasscutter/data/server/GadgetMapping.java index f3c125419..1fc4a9adc 100644 --- a/src/main/java/emu/grasscutter/data/server/GadgetMapping.java +++ b/src/main/java/emu/grasscutter/data/server/GadgetMapping.java @@ -1,9 +1,9 @@ -package emu.grasscutter.data.server; - -import lombok.Data; - -@Data -public class GadgetMapping { - private int gadgetId; - private String serverController; -} +package emu.grasscutter.data.server; + +import lombok.Data; + +@Data +public class GadgetMapping { + private int gadgetId; + private String serverController; +} diff --git a/src/main/java/emu/grasscutter/data/server/Grid.java b/src/main/java/emu/grasscutter/data/server/Grid.java index e4379bf60..8a9f5d6b9 100644 --- a/src/main/java/emu/grasscutter/data/server/Grid.java +++ b/src/main/java/emu/grasscutter/data/server/Grid.java @@ -1,34 +1,34 @@ -package emu.grasscutter.data.server; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.utils.GridPosition; -import emu.grasscutter.utils.Position; - -public class Grid { - public Map> grid; - - public Set getNearbyGroups(int vision_level, Position position) { - int width = Grasscutter.getConfig().server.game.visionOptions[vision_level].gridWidth; - int vision_range = Grasscutter.getConfig().server.game.visionOptions[vision_level].visionRange; - int vision_range_grid = vision_range / width; - - GridPosition pos = new GridPosition(position, width); - - Set nearbyGroups = new HashSet<>(); - //construct a nearby pisition list, add 1 more because a player can be in an edge case, this should not affect much the loading - for(int x = 0; x < vision_range_grid + 1; x++) { - for(int z = 0; z < vision_range_grid + 1; z++) { - nearbyGroups.addAll(grid.getOrDefault(pos.addClone( x, z), new HashSet<>())); - nearbyGroups.addAll(grid.getOrDefault(pos.addClone(-x, z), new HashSet<>())); - nearbyGroups.addAll(grid.getOrDefault(pos.addClone( x, -z), new HashSet<>())); - nearbyGroups.addAll(grid.getOrDefault(pos.addClone(-x, -z), new HashSet<>())); - } - } - - return nearbyGroups; - } -} +package emu.grasscutter.data.server; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.utils.GridPosition; +import emu.grasscutter.utils.Position; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class Grid { + public Map> grid; + + public Set getNearbyGroups(int vision_level, Position position) { + int width = Grasscutter.getConfig().server.game.visionOptions[vision_level].gridWidth; + int vision_range = Grasscutter.getConfig().server.game.visionOptions[vision_level].visionRange; + int vision_range_grid = vision_range / width; + + GridPosition pos = new GridPosition(position, width); + + Set nearbyGroups = new HashSet<>(); + // construct a nearby pisition list, add 1 more because a player can be in an edge case, this + // should not affect much the loading + for (int x = 0; x < vision_range_grid + 1; x++) { + for (int z = 0; z < vision_range_grid + 1; z++) { + nearbyGroups.addAll(grid.getOrDefault(pos.addClone(x, z), new HashSet<>())); + nearbyGroups.addAll(grid.getOrDefault(pos.addClone(-x, z), new HashSet<>())); + nearbyGroups.addAll(grid.getOrDefault(pos.addClone(x, -z), new HashSet<>())); + nearbyGroups.addAll(grid.getOrDefault(pos.addClone(-x, -z), new HashSet<>())); + } + } + + return nearbyGroups; + } +} diff --git a/src/main/java/emu/grasscutter/game/ability/AbilityManager.java b/src/main/java/emu/grasscutter/game/ability/AbilityManager.java index 570a00095..89c6fc16c 100644 --- a/src/main/java/emu/grasscutter/game/ability/AbilityManager.java +++ b/src/main/java/emu/grasscutter/game/ability/AbilityManager.java @@ -9,6 +9,7 @@ import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.gadget.GadgetGatherObject; import emu.grasscutter.game.player.BasePlayerManager; import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.enums.QuestContent; import emu.grasscutter.net.proto.AbilityInvokeEntryHeadOuterClass.AbilityInvokeEntryHead; import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; import emu.grasscutter.net.proto.AbilityMetaModifierChangeOuterClass.AbilityMetaModifierChange; @@ -39,6 +40,7 @@ public final class AbilityManager extends BasePlayerManager { case ABILITY_INVOKE_ARGUMENT_META_MODIFIER_CHANGE -> this.handleModifierChange(invoke); case ABILITY_INVOKE_ARGUMENT_MIXIN_COST_STAMINA -> this.handleMixinCostStamina(invoke); case ABILITY_INVOKE_ARGUMENT_ACTION_GENERATE_ELEM_BALL -> this.handleGenerateElemBall(invoke); + case ABILITY_INVOKE_ARGUMENT_META_GLOBAL_FLOAT_VALUE -> this.handleGlobalFloatValue(invoke); default -> {} } } @@ -202,6 +204,22 @@ public final class AbilityManager extends BasePlayerManager { this.player.getEnergyManager().handleGenerateElemBall(invoke); } + /** + * Handles a float value ability entry. + * + * @param invoke The ability invoke entry. + */ + private void handleGlobalFloatValue(AbilityInvokeEntry invoke) + throws InvalidProtocolBufferException { + var entry = AbilityScalarValueEntry.parseFrom(invoke.getAbilityData()); + if (entry.getKey().hasStr() + && entry.hasFloatValue() + && entry.getFloatValue() == 2.0f + && entry.getKey().getStr().equals("_ABILITY_UziExplode_Count")) { + player.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_SKILL, 10006); + } + } + private void invokeAction( AbilityModifierAction action, GameEntity target, GameEntity sourceEntity) { switch (action.type) { diff --git a/src/main/java/emu/grasscutter/game/achievement/Achievements.java b/src/main/java/emu/grasscutter/game/achievement/Achievements.java index f11c6ac5d..e292e1bc3 100644 --- a/src/main/java/emu/grasscutter/game/achievement/Achievements.java +++ b/src/main/java/emu/grasscutter/game/achievement/Achievements.java @@ -6,7 +6,7 @@ import dev.morphia.annotations.Id; import dev.morphia.annotations.Transient; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.AchievementData; +import emu.grasscutter.data.excels.achievement.AchievementData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.player.Player; diff --git a/src/main/java/emu/grasscutter/game/activity/ActivityConfigItem.java b/src/main/java/emu/grasscutter/game/activity/ActivityConfigItem.java index 88232bfab..34d233fe2 100644 --- a/src/main/java/emu/grasscutter/game/activity/ActivityConfigItem.java +++ b/src/main/java/emu/grasscutter/game/activity/ActivityConfigItem.java @@ -14,7 +14,19 @@ public class ActivityConfigItem { int scheduleId; List meetCondList; Date beginTime; + Date openTime; + Date closeTime; Date endTime; transient ActivityHandler activityHandler; + + void onLoad() { + if (openTime == null) { + this.openTime = beginTime; + } + + if (closeTime == null) { + this.closeTime = endTime; + } + } } diff --git a/src/main/java/emu/grasscutter/game/activity/ActivityHandler.java b/src/main/java/emu/grasscutter/game/activity/ActivityHandler.java index 993d0189c..0141fba86 100644 --- a/src/main/java/emu/grasscutter/game/activity/ActivityHandler.java +++ b/src/main/java/emu/grasscutter/game/activity/ActivityHandler.java @@ -2,9 +2,12 @@ package emu.grasscutter.game.activity; import com.esotericsoftware.reflectasm.ConstructorAccess; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.ActivityData; +import emu.grasscutter.data.excels.activity.ActivityData; +import emu.grasscutter.data.server.ActivityCondGroup; +import emu.grasscutter.game.activity.condition.ActivityConditionExecutor; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.WatcherTriggerType; +import emu.grasscutter.game.quest.enums.QuestCond; import emu.grasscutter.net.proto.ActivityInfoOuterClass; import emu.grasscutter.utils.DateHelper; import java.util.*; @@ -19,9 +22,9 @@ import lombok.experimental.FieldDefaults; @FieldDefaults(level = AccessLevel.PRIVATE) public abstract class ActivityHandler { /** Must set before initWatchers */ - ActivityConfigItem activityConfigItem; + @Getter ActivityConfigItem activityConfigItem; - ActivityData activityData; + @Getter ActivityData activityData; Map> watchersMap = new HashMap<>(); public abstract void onProtoBuild( @@ -57,6 +60,43 @@ public abstract class ActivityHandler { }); } + protected void triggerCondEvents(Player player) { + if (activityData == null) { + return; + } + + var questManager = player.getQuestManager(); + activityData + .getCondGroupId() + .forEach( + condGroupId -> { + var condGroup = GameData.getActivityCondGroupMap().get((int) condGroupId); + condGroup + .getCondIds() + .forEach( + condition -> + questManager.queueEvent(QuestCond.QUEST_COND_ACTIVITY_COND, condition)); + }); + } + + private List getActivityConditions() { + if (activityData == null) { + return new ArrayList<>(); + } + + return activityData.getCondGroupId().stream() + .map(condGroupId -> GameData.getActivityCondGroupMap().get((int) condGroupId)) + .filter(Objects::nonNull) + .map(ActivityCondGroup::getCondIds) + .flatMap(Collection::stream) + .toList(); + } + + // TODO handle possible overwrites + private List getMeetConditions(ActivityConditionExecutor conditionExecutor) { + return conditionExecutor.getMeetActivitiesConditions(getActivityConditions()); + } + private Map initWatchersDataForPlayer() { return watchersMap.values().stream() .flatMap(Collection::stream) @@ -76,7 +116,8 @@ public abstract class ActivityHandler { return playerActivityData; } - public ActivityInfoOuterClass.ActivityInfo toProto(PlayerActivityData playerActivityData) { + public ActivityInfoOuterClass.ActivityInfo toProto( + PlayerActivityData playerActivityData, ActivityConditionExecutor conditionExecutor) { var proto = ActivityInfoOuterClass.ActivityInfo.newBuilder(); proto .setActivityId(activityConfigItem.getActivityId()) @@ -85,7 +126,7 @@ public abstract class ActivityHandler { .setBeginTime(DateHelper.getUnixTime(activityConfigItem.getBeginTime())) .setFirstDayStartTime(DateHelper.getUnixTime(activityConfigItem.getBeginTime())) .setEndTime(DateHelper.getUnixTime(activityConfigItem.getEndTime())) - .addAllMeetCondList(activityConfigItem.getMeetCondList()); + .addAllMeetCondList(getMeetConditions(conditionExecutor)); if (playerActivityData != null) { proto.addAllWatcherInfoList(playerActivityData.getAllWatcherInfoList()); diff --git a/src/main/java/emu/grasscutter/game/activity/ActivityManager.java b/src/main/java/emu/grasscutter/game/activity/ActivityManager.java index 6a7c8c8be..f1ac1b67f 100644 --- a/src/main/java/emu/grasscutter/game/activity/ActivityManager.java +++ b/src/main/java/emu/grasscutter/game/activity/ActivityManager.java @@ -4,6 +4,7 @@ import com.esotericsoftware.reflectasm.ConstructorAccess; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.DataLoader; import emu.grasscutter.data.GameData; +import emu.grasscutter.game.activity.condition.*; import emu.grasscutter.game.player.BasePlayerManager; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.ActivityType; @@ -12,6 +13,7 @@ import emu.grasscutter.net.proto.ActivityInfoOuterClass; import emu.grasscutter.server.packet.send.PacketActivityScheduleInfoNotify; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; import lombok.Getter; import org.reflections.Reflections; @@ -19,6 +21,8 @@ import org.reflections.Reflections; public class ActivityManager extends BasePlayerManager { private static final Map activityConfigItemMap; @Getter private static final Map scheduleActivityConfigMap; + private final Map playerActivityDataMap; + private final ActivityConditionExecutor conditionExecutor; static { activityConfigItemMap = new HashMap<>(); @@ -26,30 +30,6 @@ public class ActivityManager extends BasePlayerManager { loadActivityConfigData(); } - private final Map playerActivityDataMap; - - public ActivityManager(Player player) { - super(player); - - playerActivityDataMap = new ConcurrentHashMap<>(); - // load data for player - activityConfigItemMap - .values() - .forEach( - item -> { - var data = PlayerActivityData.getByPlayer(player, item.getActivityId()); - if (data == null) { - data = item.getActivityHandler().initPlayerActivityData(player); - data.save(); - } - data.setPlayer(player); - data.setActivityHandler(item.getActivityHandler()); - playerActivityDataMap.put(item.getActivityId(), data); - }); - - player.sendPacket(new PacketActivityScheduleInfoNotify(activityConfigItemMap.values())); - } - private static void loadActivityConfigData() { // scan activity type handler & watcher type var activityHandlerTypeMap = new HashMap>(); @@ -75,6 +55,7 @@ public class ActivityManager extends BasePlayerManager { DataLoader.loadList("ActivityConfig.json", ActivityConfigItem.class) .forEach( item -> { + item.onLoad(); var activityData = GameData.getActivityDataMap().get(item.getActivityId()); if (activityData == null) { Grasscutter.getLogger().warn("activity {} not exist.", item.getActivityId()); @@ -104,6 +85,36 @@ public class ActivityManager extends BasePlayerManager { } } + public ActivityManager(Player player) { + super(player); + + playerActivityDataMap = new ConcurrentHashMap<>(); + // load data for player + activityConfigItemMap + .values() + .forEach( + item -> { + var data = PlayerActivityData.getByPlayer(player, item.getActivityId()); + if (data == null) { + data = item.getActivityHandler().initPlayerActivityData(player); + data.save(); + } + data.setPlayer(player); + data.setActivityHandler(item.getActivityHandler()); + playerActivityDataMap.put(item.getActivityId(), data); + }); + + player.sendPacket(new PacketActivityScheduleInfoNotify(activityConfigItemMap.values())); + + conditionExecutor = + new BasicActivityConditionExecutor( + activityConfigItemMap, + GameData.getActivityCondExcelConfigDataMap(), + PlayerActivityDataMappingBuilder.buildPlayerActivityDataByActivityCondId( + playerActivityDataMap), + AllActivityConditionBuilder.buildActivityConditions()); + } + /** trigger activity watcher */ public void triggerWatcher(WatcherTriggerType watcherTriggerType, String... params) { var watchers = @@ -124,11 +135,71 @@ public class ActivityManager extends BasePlayerManager { params)); } + public boolean isActivityActive(int activityId) { + var activityConfig = activityConfigItemMap.get(activityId); + if (activityConfig == null) { + return false; + } + + var now = new Date(); + return now.after(activityConfig.getBeginTime()) && now.before(activityConfig.getEndTime()); + } + + public boolean hasActivityEnded(int activityId) { + var activityConfig = activityConfigItemMap.get(activityId); + if (activityConfig == null) { + return true; + } + + return new Date().after(activityConfig.getEndTime()); + } + + public boolean isActivityOpen(int activityId) { + var activityConfig = activityConfigItemMap.get(activityId); + if (activityConfig == null) { + return false; + } + + var now = new Date(); + return now.after(activityConfig.getOpenTime()) && now.before(activityConfig.getCloseTime()); + } + + public int getOpenDay(int activityId) { + var activityConfig = activityConfigItemMap.get(activityId); + if (activityConfig == null) { + return 0; + } + + var now = new Date(); + return (int) + TimeUnit.DAYS.convert( + now.getTime() - activityConfig.getOpenTime().getTime(), TimeUnit.MILLISECONDS) + + 1; + } + + public boolean isActivityClosed(int activityId) { + var activityConfig = activityConfigItemMap.get(activityId); + if (activityConfig == null) { + return false; + } + + var now = new Date(); + return now.after(activityConfig.getCloseTime()); + } + + public boolean meetsCondition(int activityCondId) { + return conditionExecutor.meetsCondition(activityCondId); + } + + public void triggerActivityConditions() { + activityConfigItemMap.forEach((k, v) -> v.getActivityHandler().triggerCondEvents(player)); + } + public ActivityInfoOuterClass.ActivityInfo getInfoProtoByActivityId(int activityId) { var activityHandler = activityConfigItemMap.get(activityId).getActivityHandler(); var activityData = playerActivityDataMap.get(activityId); - return activityHandler.toProto(activityData); + return activityHandler.toProto(activityData, conditionExecutor); } public Optional getActivityHandler(ActivityType type) { @@ -138,7 +209,6 @@ public class ActivityManager extends BasePlayerManager { .findFirst(); } - @SuppressWarnings("unchecked") public Optional getActivityHandlerAs( ActivityType type, Class clazz) { return getActivityHandler(type).map(x -> (T) x); diff --git a/src/main/java/emu/grasscutter/game/activity/ActivityWatcher.java b/src/main/java/emu/grasscutter/game/activity/ActivityWatcher.java index ec5fca27f..f1f14d56e 100644 --- a/src/main/java/emu/grasscutter/game/activity/ActivityWatcher.java +++ b/src/main/java/emu/grasscutter/game/activity/ActivityWatcher.java @@ -1,6 +1,6 @@ package emu.grasscutter.game.activity; -import emu.grasscutter.data.excels.ActivityWatcherData; +import emu.grasscutter.data.excels.activity.ActivityWatcherData; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/emu/grasscutter/game/activity/PlayerActivityData.java b/src/main/java/emu/grasscutter/game/activity/PlayerActivityData.java index b97a94533..8fdbd7370 100644 --- a/src/main/java/emu/grasscutter/game/activity/PlayerActivityData.java +++ b/src/main/java/emu/grasscutter/game/activity/PlayerActivityData.java @@ -5,7 +5,7 @@ import dev.morphia.annotations.Id; import dev.morphia.annotations.Transient; import emu.grasscutter.data.GameData; import emu.grasscutter.data.common.ItemParamData; -import emu.grasscutter.data.excels.ActivityWatcherData; +import emu.grasscutter.data.excels.activity.ActivityWatcherData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.player.Player; diff --git a/src/main/java/emu/grasscutter/game/activity/condition/ActivityCondition.java b/src/main/java/emu/grasscutter/game/activity/condition/ActivityCondition.java index 46b6f739a..66e051291 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/ActivityCondition.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/ActivityCondition.java @@ -1,17 +1,16 @@ -package emu.grasscutter.game.activity.condition; - -import emu.grasscutter.data.excels.ActivityCondExcelConfigData; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - - -/** - * This annotation marks condition types for NewActivityCondExcelConfigData.json ({@link ActivityCondExcelConfigData}). To use it you should mark - * class that extends ActivityConditionBaseHandler, and it will be automatically picked during activity manager initiation. - * - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface ActivityCondition { - ActivityConditions value(); -} +package emu.grasscutter.game.activity.condition; + +import emu.grasscutter.data.excels.activity.ActivityCondExcelConfigData; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * This annotation marks condition types for NewActivityCondExcelConfigData.json ({@link + * ActivityCondExcelConfigData}). To use it you should mark class that extends + * ActivityConditionBaseHandler, and it will be automatically picked during activity manager + * initiation. + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface ActivityCondition { + ActivityConditions value(); +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionBaseHandler.java b/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionBaseHandler.java index ef7a2181c..76fade7c9 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionBaseHandler.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionBaseHandler.java @@ -1,21 +1,23 @@ -package emu.grasscutter.game.activity.condition; - -import emu.grasscutter.data.excels.ActivityCondExcelConfigData; -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.game.activity.PlayerActivityData; - -/** - * Base handler for all activity conditions that are listed in NewActivityCondExcelConfigData.json ({@link ActivityCondExcelConfigData}) - */ -public abstract class ActivityConditionBaseHandler { - - /** - * Execute activity condition handler and return result of it's calculation - * - * @param activityData {@link PlayerActivityData} object containing info about activity - * @param activityConfig - * @param params params for handler - * @return result of condition calculation - */ - public abstract boolean execute(PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params); -} +package emu.grasscutter.game.activity.condition; + +import emu.grasscutter.data.excels.activity.ActivityCondExcelConfigData; +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.game.activity.PlayerActivityData; + +/** + * Base handler for all activity conditions that are listed in NewActivityCondExcelConfigData.json + * ({@link ActivityCondExcelConfigData}) + */ +public abstract class ActivityConditionBaseHandler { + + /** + * Execute activity condition handler and return result of it's calculation + * + * @param activityData {@link PlayerActivityData} object containing info about activity + * @param activityConfig + * @param params params for handler + * @return result of condition calculation + */ + public abstract boolean execute( + PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params); +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionExecutor.java b/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionExecutor.java index f2f512118..6aa606e6e 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionExecutor.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionExecutor.java @@ -1,10 +1,10 @@ -package emu.grasscutter.game.activity.condition; - -import java.util.List; - -public interface ActivityConditionExecutor { - - List getMeetActivitiesConditions(List condIds); - - boolean meetsCondition(int activityCondId); -} +package emu.grasscutter.game.activity.condition; + +import java.util.List; + +public interface ActivityConditionExecutor { + + List getMeetActivitiesConditions(List condIds); + + boolean meetsCondition(int activityCondId); +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditions.java b/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditions.java index c42efa5b7..0a35c1494 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditions.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditions.java @@ -1,51 +1,51 @@ -package emu.grasscutter.game.activity.condition; - -public enum ActivityConditions { - NEW_ACTIVITY_COND_PLAYER_LEVEL_GREAT_EQUAL, - NEW_ACTIVITY_COND_NOT_FINISH_TALK, - NEW_ACTIVITY_COND_SALESMAN_CAN_DELIVER, - NEW_ACTIVITY_COND_FINISH_PHOTO_POS_ID, - NEW_ACTIVITY_COND_HACHI_FINISH_STEALTH_STAGE_EQUAL, - NEW_ACTIVITY_COND_UNLOCKED_ALL_LISTED_SCENE_POINTS, - NEW_ACTIVITY_COND_DAYS_GREAT_EQUAL, - NEW_ACTIVITY_COND_FINISH_BARTENDER_LEVEL, - NEW_ACTIVITY_COND_FINISH_HACHI_STAGE, - NEW_ACTIVITY_COND_FINISH_ANY_INSTABLE_SPRAY_CHALLENGE_STAGE, - NEW_ACTIVITY_COND_HACHI_FINISH_BATTLE_STAGE_EQUAL, - NEW_ACTIVITY_COND_FINISH_CHANNELLER_SLAB_APPOINTED_STAGE_ALL_CAMP, - NEW_ACTIVITY_COND_FINISH_WATCHER, - NEW_ACTIVITY_COND_FINISH_REGION_SEARCH, - NEW_ACTIVITY_COND_FINISH_WATER_SPIRIT_PHASE, - NEW_ACTIVITY_COND_SEA_LAMP_POPULARIT, - NEW_ACTIVITY_COND_FINISH_DIG_ACTIVITY, - NEW_ACTIVITY_COND_FINISH_FIND_HILICHURL_LEVEL_EQUAL, - NEW_ACTIVITY_COND_GACHA_CAN_CREATE_ROBOT, - NEW_ACTIVITY_COND_FINISH_SALVAGE_STAGE, - NEW_ACTIVITY_COND_FINISH_MUSIC_GAME_ALL_LEVEL, - NEW_ACTIVITY_COND_DAYS_LESS, - NEW_ACTIVITY_COND_QUEST_FINISH, - NEW_ACTIVITY_COND_QUEST_GLOBAL_VAR_EQUAL, - NEW_ACTIVITY_COND_GROUP_BUNDLE_FINISHED, - NEW_ACTIVITY_COND_SEA_LAMP_PHASE, - NEW_ACTIVITY_COND_FINISH_CHANNELLER_SLAB_ANY_STAGE_ALL_CAMP, - NEW_ACTIVITY_COND_LUMINANCE_STONE_CHALLENGE_FINAL_GALLERY_COMPLETE, - NEW_ACTIVITY_COND_PLANT_FLOWER_CAN_DELIVER, - NEW_ACTIVITY_COND_LUMINANCE_STONE_CHALLENGE_STAGE_GREAT_EQUAL, - NEW_ACTIVITY_COND_FINISH_ANY_ARENA_CHALLENGE_LEVEL, - NEW_ACTIVITY_COND_FINISH_CUSTOM_DUNGEON_OFFICIAL, - NEW_ACTIVITY_COND_SCENE_MP_PLAY_ACTIVATED, - NEW_ACTIVITY_COND_FINISH_FIND_HILICHURL_LEVEL_LESS, - NEW_ACTIVITY_COND_TIME_GREATER, - NEW_ACTIVITY_COND_CREATE_NPC, - NEW_ACTIVITY_COND_TREASURE_SEELIE_FINISH_REGION, - NEW_ACTIVITY_COND_LUNA_RITE_ATMOSPHERE, - NEW_ACTIVITY_COND_OFFERING_LEVEL_GREAT_EQUAL, - NEW_ACTIVITY_COND_FINISH_CHANNELLER_SLAB_ANY_ONEOFF_DUNGEON, - NEW_ACTIVITY_COND_QUEST_FINISH_ALLOW_QUICK_OPEN, - NEW_ACTIVITY_COND_FINISH_POTION_ANY_LEVEL, - NEW_ACTIVITY_COND_MECHANICUS_OPEN, - NEW_ACTIVITY_COND_PLAYER_LEVEL_GREATER, - NEW_ACTIVITY_COND_SALESMAN_CAN_GET_REWARD, - NEW_ACTIVITY_COND_FINISH_REGION_SEARCH_LOGIC, - NEW_ACTIVITY_COND_FINISH_CHANNELLER_SLAB_ONEOFF_DUNGEON_IN_STAGE -} +package emu.grasscutter.game.activity.condition; + +public enum ActivityConditions { + NEW_ACTIVITY_COND_PLAYER_LEVEL_GREAT_EQUAL, + NEW_ACTIVITY_COND_NOT_FINISH_TALK, + NEW_ACTIVITY_COND_SALESMAN_CAN_DELIVER, + NEW_ACTIVITY_COND_FINISH_PHOTO_POS_ID, + NEW_ACTIVITY_COND_HACHI_FINISH_STEALTH_STAGE_EQUAL, + NEW_ACTIVITY_COND_UNLOCKED_ALL_LISTED_SCENE_POINTS, + NEW_ACTIVITY_COND_DAYS_GREAT_EQUAL, + NEW_ACTIVITY_COND_FINISH_BARTENDER_LEVEL, + NEW_ACTIVITY_COND_FINISH_HACHI_STAGE, + NEW_ACTIVITY_COND_FINISH_ANY_INSTABLE_SPRAY_CHALLENGE_STAGE, + NEW_ACTIVITY_COND_HACHI_FINISH_BATTLE_STAGE_EQUAL, + NEW_ACTIVITY_COND_FINISH_CHANNELLER_SLAB_APPOINTED_STAGE_ALL_CAMP, + NEW_ACTIVITY_COND_FINISH_WATCHER, + NEW_ACTIVITY_COND_FINISH_REGION_SEARCH, + NEW_ACTIVITY_COND_FINISH_WATER_SPIRIT_PHASE, + NEW_ACTIVITY_COND_SEA_LAMP_POPULARIT, + NEW_ACTIVITY_COND_FINISH_DIG_ACTIVITY, + NEW_ACTIVITY_COND_FINISH_FIND_HILICHURL_LEVEL_EQUAL, + NEW_ACTIVITY_COND_GACHA_CAN_CREATE_ROBOT, + NEW_ACTIVITY_COND_FINISH_SALVAGE_STAGE, + NEW_ACTIVITY_COND_FINISH_MUSIC_GAME_ALL_LEVEL, + NEW_ACTIVITY_COND_DAYS_LESS, + NEW_ACTIVITY_COND_QUEST_FINISH, + NEW_ACTIVITY_COND_QUEST_GLOBAL_VAR_EQUAL, + NEW_ACTIVITY_COND_GROUP_BUNDLE_FINISHED, + NEW_ACTIVITY_COND_SEA_LAMP_PHASE, + NEW_ACTIVITY_COND_FINISH_CHANNELLER_SLAB_ANY_STAGE_ALL_CAMP, + NEW_ACTIVITY_COND_LUMINANCE_STONE_CHALLENGE_FINAL_GALLERY_COMPLETE, + NEW_ACTIVITY_COND_PLANT_FLOWER_CAN_DELIVER, + NEW_ACTIVITY_COND_LUMINANCE_STONE_CHALLENGE_STAGE_GREAT_EQUAL, + NEW_ACTIVITY_COND_FINISH_ANY_ARENA_CHALLENGE_LEVEL, + NEW_ACTIVITY_COND_FINISH_CUSTOM_DUNGEON_OFFICIAL, + NEW_ACTIVITY_COND_SCENE_MP_PLAY_ACTIVATED, + NEW_ACTIVITY_COND_FINISH_FIND_HILICHURL_LEVEL_LESS, + NEW_ACTIVITY_COND_TIME_GREATER, + NEW_ACTIVITY_COND_CREATE_NPC, + NEW_ACTIVITY_COND_TREASURE_SEELIE_FINISH_REGION, + NEW_ACTIVITY_COND_LUNA_RITE_ATMOSPHERE, + NEW_ACTIVITY_COND_OFFERING_LEVEL_GREAT_EQUAL, + NEW_ACTIVITY_COND_FINISH_CHANNELLER_SLAB_ANY_ONEOFF_DUNGEON, + NEW_ACTIVITY_COND_QUEST_FINISH_ALLOW_QUICK_OPEN, + NEW_ACTIVITY_COND_FINISH_POTION_ANY_LEVEL, + NEW_ACTIVITY_COND_MECHANICUS_OPEN, + NEW_ACTIVITY_COND_PLAYER_LEVEL_GREATER, + NEW_ACTIVITY_COND_SALESMAN_CAN_GET_REWARD, + NEW_ACTIVITY_COND_FINISH_REGION_SEARCH_LOGIC, + NEW_ACTIVITY_COND_FINISH_CHANNELLER_SLAB_ONEOFF_DUNGEON_IN_STAGE +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/AllActivityConditionBuilder.java b/src/main/java/emu/grasscutter/game/activity/condition/AllActivityConditionBuilder.java index d5eddc2d4..85cdf2a76 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/AllActivityConditionBuilder.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/AllActivityConditionBuilder.java @@ -1,60 +1,63 @@ -package emu.grasscutter.game.activity.condition; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.excels.ActivityCondExcelConfigData; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; -import org.reflections.Reflections; - -import java.util.AbstractMap; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * Class that used for scanning classpath, picking up all activity conditions (for NewActivityCondExcelConfigData.json {@link ActivityCondExcelConfigData}) - * and saving them to map. Check for more info {@link ActivityCondition} - */ -public class AllActivityConditionBuilder { - - /** - * Build activity conditions handlers - * - * @return map containing all condition handlers for NewActivityCondExcelConfigData.json - */ - static public Map buildActivityConditions() { - return new AllActivityConditionBuilder().initActivityConditions(); - } - - private Map initActivityConditions() { - Reflections reflector = Grasscutter.reflector; - return reflector.getTypesAnnotatedWith(ActivityCondition.class).stream() - .map(this::newInstance) - .map(h -> new AbstractMap.SimpleEntry<>(extractActionType(h), h)) - .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)); - } - - private ActivityConditions extractActionType(ActivityConditionBaseHandler e) { - ActivityCondition condition = e.getClass().getAnnotation(ActivityCondition.class); - if (condition == null) { - Grasscutter.getLogger().error("Failed to read command type for class {}", e.getClass().getName()); - return null; - } - - return condition.value(); - } - - private ActivityConditionBaseHandler newInstance(Class clazz) { - try { - Object result = clazz.getDeclaredConstructor().newInstance(); - if (result instanceof ActivityConditionBaseHandler) { - return (ActivityConditionBaseHandler) result; - } - Grasscutter.getLogger().error("Failed to initiate activity condition: {}, object have wrong type", clazz.getName()); - } catch (Exception e) { - String message = String.format("Failed to initiate activity condition: %s, %s", clazz.getName(), e.getMessage()); - Grasscutter.getLogger().error(message, e); - } - return null; - } - - -} +package emu.grasscutter.game.activity.condition; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.excels.activity.ActivityCondExcelConfigData; +import java.util.AbstractMap; +import java.util.Map; +import java.util.stream.Collectors; +import org.reflections.Reflections; + +/** + * Class that used for scanning classpath, picking up all activity conditions (for + * NewActivityCondExcelConfigData.json {@link ActivityCondExcelConfigData}) and saving them to map. + * Check for more info {@link ActivityCondition} + */ +public class AllActivityConditionBuilder { + + /** + * Build activity conditions handlers + * + * @return map containing all condition handlers for NewActivityCondExcelConfigData.json + */ + public static Map buildActivityConditions() { + return new AllActivityConditionBuilder().initActivityConditions(); + } + + private Map initActivityConditions() { + Reflections reflector = Grasscutter.reflector; + return reflector.getTypesAnnotatedWith(ActivityCondition.class).stream() + .map(this::newInstance) + .map(h -> new AbstractMap.SimpleEntry<>(extractActionType(h), h)) + .collect( + Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)); + } + + private ActivityConditions extractActionType(ActivityConditionBaseHandler e) { + ActivityCondition condition = e.getClass().getAnnotation(ActivityCondition.class); + if (condition == null) { + Grasscutter.getLogger() + .error("Failed to read command type for class {}", e.getClass().getName()); + return null; + } + + return condition.value(); + } + + private ActivityConditionBaseHandler newInstance(Class clazz) { + try { + Object result = clazz.getDeclaredConstructor().newInstance(); + if (result instanceof ActivityConditionBaseHandler) { + return (ActivityConditionBaseHandler) result; + } + Grasscutter.getLogger() + .error( + "Failed to initiate activity condition: {}, object have wrong type", clazz.getName()); + } catch (Exception e) { + String message = + String.format( + "Failed to initiate activity condition: %s, %s", clazz.getName(), e.getMessage()); + Grasscutter.getLogger().error(message, e); + } + return null; + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/BasicActivityConditionExecutor.java b/src/main/java/emu/grasscutter/game/activity/condition/BasicActivityConditionExecutor.java index ac06b9036..89749c61e 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/BasicActivityConditionExecutor.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/BasicActivityConditionExecutor.java @@ -1,71 +1,75 @@ -package emu.grasscutter.game.activity.condition; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.excels.ActivityCondExcelConfigData; -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.activity.condition.all.UnknownActivityConditionHandler; -import emu.grasscutter.game.quest.enums.LogicType; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; - -import java.util.List; -import java.util.Map; -import java.util.function.BooleanSupplier; -import java.util.stream.Collectors; - -public class BasicActivityConditionExecutor implements ActivityConditionExecutor { - - private final Map activityConfigItemMap; - private final Int2ObjectMap activityConditions; - - private final Int2ObjectMap playerActivityDataByActivityCondId; - private final Map activityConditionsHandlers; - - private static final UnknownActivityConditionHandler UNKNOWN_CONDITION_HANDLER = new UnknownActivityConditionHandler(); - - public BasicActivityConditionExecutor(Map activityConfigItemMap, - Int2ObjectMap activityConditions, - Int2ObjectMap playerActivityDataByActivityCondId, - Map activityConditionsHandlers) { - this.activityConfigItemMap = activityConfigItemMap; - this.activityConditions = activityConditions; - this.playerActivityDataByActivityCondId = playerActivityDataByActivityCondId; - this.activityConditionsHandlers = activityConditionsHandlers; - } - - @Override - public List getMeetActivitiesConditions(List condIds) { - return condIds.stream() - .filter(this::meetsCondition) - .collect(Collectors.toList()); - } - - @Override - public boolean meetsCondition(int activityCondId) { - ActivityCondExcelConfigData condData = activityConditions.get(activityCondId); - - if (condData == null) { - Grasscutter.getLogger().error("Could not find condition for activity with id = {}", activityCondId); - return false; - } - - LogicType condComb = condData.getCondComb(); - if (condComb == null) { - condComb = LogicType.LOGIC_AND; - } - - PlayerActivityData activity = playerActivityDataByActivityCondId.get(activityCondId); - if(activity==null){ - return false; - } - ActivityConfigItem activityConfig = activityConfigItemMap.get(activity.getActivityId()); - List predicates = condData.getCond() - .stream() - .map(c -> (BooleanSupplier) () -> - activityConditionsHandlers - .getOrDefault(c.getType(), UNKNOWN_CONDITION_HANDLER).execute(activity, activityConfig, c.paramArray())) - .collect(Collectors.toList()); - - return LogicType.calculate(condComb, predicates); - } -} +package emu.grasscutter.game.activity.condition; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.excels.activity.ActivityCondExcelConfigData; +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.game.activity.condition.all.UnknownActivityConditionHandler; +import emu.grasscutter.game.quest.enums.LogicType; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import java.util.List; +import java.util.Map; +import java.util.function.BooleanSupplier; +import java.util.stream.Collectors; + +public class BasicActivityConditionExecutor implements ActivityConditionExecutor { + + private final Map activityConfigItemMap; + private final Int2ObjectMap activityConditions; + + private final Int2ObjectMap playerActivityDataByActivityCondId; + private final Map activityConditionsHandlers; + + private static final UnknownActivityConditionHandler UNKNOWN_CONDITION_HANDLER = + new UnknownActivityConditionHandler(); + + public BasicActivityConditionExecutor( + Map activityConfigItemMap, + Int2ObjectMap activityConditions, + Int2ObjectMap playerActivityDataByActivityCondId, + Map activityConditionsHandlers) { + this.activityConfigItemMap = activityConfigItemMap; + this.activityConditions = activityConditions; + this.playerActivityDataByActivityCondId = playerActivityDataByActivityCondId; + this.activityConditionsHandlers = activityConditionsHandlers; + } + + @Override + public List getMeetActivitiesConditions(List condIds) { + return condIds.stream().filter(this::meetsCondition).collect(Collectors.toList()); + } + + @Override + public boolean meetsCondition(int activityCondId) { + ActivityCondExcelConfigData condData = activityConditions.get(activityCondId); + + if (condData == null) { + Grasscutter.getLogger() + .error("Could not find condition for activity with id = {}", activityCondId); + return false; + } + + LogicType condComb = condData.getCondComb(); + if (condComb == null) { + condComb = LogicType.LOGIC_AND; + } + + PlayerActivityData activity = playerActivityDataByActivityCondId.get(activityCondId); + if (activity == null) { + return false; + } + ActivityConfigItem activityConfig = activityConfigItemMap.get(activity.getActivityId()); + List predicates = + condData.getCond().stream() + .map( + c -> + (BooleanSupplier) + () -> + activityConditionsHandlers + .getOrDefault(c.getType(), UNKNOWN_CONDITION_HANDLER) + .execute(activity, activityConfig, c.paramArray())) + .collect(Collectors.toList()); + + return LogicType.calculate(condComb, predicates); + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/PlayerActivityDataMappingBuilder.java b/src/main/java/emu/grasscutter/game/activity/condition/PlayerActivityDataMappingBuilder.java index 6c0bba497..d56f2c4f2 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/PlayerActivityDataMappingBuilder.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/PlayerActivityDataMappingBuilder.java @@ -1,80 +1,81 @@ -package emu.grasscutter.game.activity.condition; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.ActivityCondExcelConfigData; -import emu.grasscutter.game.activity.PlayerActivityData; -import it.unimi.dsi.fastutil.ints.AbstractInt2ObjectMap.BasicEntry; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; - -import java.util.Map; - -/** - * This class is used for building mapping for PlayerActivityData - */ -public class PlayerActivityDataMappingBuilder { - - - private final Map playerActivityDataMap; - - private final Int2ObjectMap activityCondMap; - - /** - * Build mapping for PlayerActivityData. - * - * @return mapping for activity data. Key is condId from NewActivityCondExcelConfigData.json ({@link ActivityCondExcelConfigData}) resource, - * value is {@link PlayerActivityData} class for related activity. - */ - public static Int2ObjectMap buildPlayerActivityDataByActivityCondId(Map activities) { - return new PlayerActivityDataMappingBuilder(activities).buildMappings(); - } - - public PlayerActivityDataMappingBuilder(Map playerActivityDataMap) { - this.playerActivityDataMap = playerActivityDataMap; - activityCondMap = GameData.getActivityCondExcelConfigDataMap(); - } - - private Int2ObjectMap buildMappings() { - Int2ObjectMap result = new Int2ObjectRBTreeMap<>(); - - activityCondMap - .int2ObjectEntrySet() - .stream() - .map(entry -> new BasicEntry<>(entry.getIntKey(), getPlayerActivityDataByCondId(entry.getIntKey()))) - .filter(entry -> entry.getValue() != null) - .forEach(entry -> result.put(entry.getIntKey(), entry.getValue())); - - return result; - } - - private PlayerActivityData getPlayerActivityDataByCondId(Integer key) { - return playerActivityDataMap.get(detectActivityDataIdByCondId(key)); - } - - /** - * Detect activity data id by cond id. Cond id comes from condId field from NewActivityCondExcelConfigData.json. - * See {@link ActivityCondExcelConfigData} for condId. - *

- * Generally, there are 3 cases: - *

    - *
  1. Activity data id >= 5003. Then cond id will be activity data id plus 3 additional digits. - * For example: activity data id = 5087, cond id = 5087xxx (x - any digit)
  2. - *
  3. Activity data id = 5001. Then cond id will be activity data id plus 2 additional digits. - * For example: activity data id = 5001, cond id = 5001xx (x - any digit)
  4. - *
  5. Activity data id one of [1001]. Then cond id will be activity data id plus 2 additional digits. - * This also applied to activity data id = 1002. For example: activity data id = 1001, cond id = 1001x (x - any digit>
  6. - *
- * - * @param key cond id for which activity data id should be defined - * @return activity data for given cond id. Returns -1 if activity was not found. - */ - private Integer detectActivityDataIdByCondId(Integer key) { - if (key / 10 == 1001 || key / 10 == 1002) { - return 1001; - } else if (key / 100 == 5001) { - return key / 100; - } else { - return key / 1000; - } - } -} +package emu.grasscutter.game.activity.condition; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.excels.activity.ActivityCondExcelConfigData; +import emu.grasscutter.game.activity.PlayerActivityData; +import it.unimi.dsi.fastutil.ints.AbstractInt2ObjectMap.BasicEntry; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; +import java.util.Map; + +/** This class is used for building mapping for PlayerActivityData */ +public class PlayerActivityDataMappingBuilder { + + private final Map playerActivityDataMap; + + private final Int2ObjectMap activityCondMap; + + /** + * Build mapping for PlayerActivityData. + * + * @return mapping for activity data. Key is condId from NewActivityCondExcelConfigData.json + * ({@link ActivityCondExcelConfigData}) resource, value is {@link PlayerActivityData} class + * for related activity. + */ + public static Int2ObjectMap buildPlayerActivityDataByActivityCondId( + Map activities) { + return new PlayerActivityDataMappingBuilder(activities).buildMappings(); + } + + public PlayerActivityDataMappingBuilder(Map playerActivityDataMap) { + this.playerActivityDataMap = playerActivityDataMap; + activityCondMap = GameData.getActivityCondExcelConfigDataMap(); + } + + private Int2ObjectMap buildMappings() { + Int2ObjectMap result = new Int2ObjectRBTreeMap<>(); + + activityCondMap.int2ObjectEntrySet().stream() + .map( + entry -> + new BasicEntry<>( + entry.getIntKey(), getPlayerActivityDataByCondId(entry.getIntKey()))) + .filter(entry -> entry.getValue() != null) + .forEach(entry -> result.put(entry.getIntKey(), entry.getValue())); + + return result; + } + + private PlayerActivityData getPlayerActivityDataByCondId(Integer key) { + return playerActivityDataMap.get(detectActivityDataIdByCondId(key)); + } + + /** + * Detect activity data id by cond id. Cond id comes from condId field from + * NewActivityCondExcelConfigData.json. See {@link ActivityCondExcelConfigData} for condId. + * + *

Generally, there are 3 cases: + * + *

    + *
  1. Activity data id >= 5003. Then cond id will be activity data id plus 3 additional digits. + * For example: activity data id = 5087, cond id = 5087xxx (x - any digit) + *
  2. Activity data id = 5001. Then cond id will be activity data id plus 2 additional digits. + * For example: activity data id = 5001, cond id = 5001xx (x - any digit) + *
  3. Activity data id one of [1001]. Then cond id will be activity data id plus 2 additional + * digits. This also applied to activity data id = 1002. For example: activity data id = + * 1001, cond id = 1001x (x - any digit> + *
+ * + * @param key cond id for which activity data id should be defined + * @return activity data for given cond id. Returns -1 if activity was not found. + */ + private Integer detectActivityDataIdByCondId(Integer key) { + if (key / 10 == 1001 || key / 10 == 1002) { + return 1001; + } else if (key / 100 == 5001) { + return key / 100; + } else { + return key / 1000; + } + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/all/DayLess.java b/src/main/java/emu/grasscutter/game/activity/condition/all/DayLess.java index ef6c8263f..e77b658cf 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/all/DayLess.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/all/DayLess.java @@ -1,16 +1,17 @@ -package emu.grasscutter.game.activity.condition.all; - -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.activity.condition.ActivityCondition; -import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; - -import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_DAYS_LESS; - -@ActivityCondition(NEW_ACTIVITY_COND_DAYS_LESS) -public class DayLess extends ActivityConditionBaseHandler { - @Override - public boolean execute(PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { - return true; //TODO implement this and add possibility to always return true - } -} +package emu.grasscutter.game.activity.condition.all; + +import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_DAYS_LESS; + +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.game.activity.condition.ActivityCondition; +import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; + +@ActivityCondition(NEW_ACTIVITY_COND_DAYS_LESS) +public class DayLess extends ActivityConditionBaseHandler { + @Override + public boolean execute( + PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { + return true; // TODO implement this and add possibility to always return true + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/all/DaysGreatEqual.java b/src/main/java/emu/grasscutter/game/activity/condition/all/DaysGreatEqual.java index 0377372ce..a5db210c2 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/all/DaysGreatEqual.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/all/DaysGreatEqual.java @@ -1,21 +1,21 @@ -package emu.grasscutter.game.activity.condition.all; - -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.activity.condition.ActivityCondition; -import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; - -import java.util.Date; - -import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_DAYS_GREAT_EQUAL; - -@ActivityCondition(NEW_ACTIVITY_COND_DAYS_GREAT_EQUAL) -public class DaysGreatEqual extends ActivityConditionBaseHandler { - @Override - public boolean execute(PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { - Date activityBeginTime = activityConfig.getBeginTime(); - long timeDiff = System.currentTimeMillis() - activityBeginTime.getTime(); - int days = (int) (timeDiff / (1000 * 60 * 60 * 24L)); - return days + 1 >= params[0]; - } -} +package emu.grasscutter.game.activity.condition.all; + +import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_DAYS_GREAT_EQUAL; + +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.game.activity.condition.ActivityCondition; +import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; +import java.util.Date; + +@ActivityCondition(NEW_ACTIVITY_COND_DAYS_GREAT_EQUAL) +public class DaysGreatEqual extends ActivityConditionBaseHandler { + @Override + public boolean execute( + PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { + Date activityBeginTime = activityConfig.getBeginTime(); + long timeDiff = System.currentTimeMillis() - activityBeginTime.getTime(); + int days = (int) (timeDiff / (1000 * 60 * 60 * 24L)); + return days + 1 >= params[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/all/FinishWatcher.java b/src/main/java/emu/grasscutter/game/activity/condition/all/FinishWatcher.java index 5b775f4a9..109848fd3 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/all/FinishWatcher.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/all/FinishWatcher.java @@ -1,24 +1,25 @@ -package emu.grasscutter.game.activity.condition.all; - -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.activity.condition.ActivityCondition; -import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; -import emu.grasscutter.game.activity.condition.ActivityConditions; -import lombok.val; - -@ActivityCondition(ActivityConditions.NEW_ACTIVITY_COND_FINISH_WATCHER) -public class FinishWatcher extends ActivityConditionBaseHandler { - - @Override - public boolean execute(PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { - val watcherMap = activityData.getWatcherInfoMap(); - for (int param : params) { - val watcher = watcherMap.get(param); - if(watcher == null || !watcher.isFinished()){ - return false; - } - } - return true; - } -} +package emu.grasscutter.game.activity.condition.all; + +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.game.activity.condition.ActivityCondition; +import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; +import emu.grasscutter.game.activity.condition.ActivityConditions; +import lombok.val; + +@ActivityCondition(ActivityConditions.NEW_ACTIVITY_COND_FINISH_WATCHER) +public class FinishWatcher extends ActivityConditionBaseHandler { + + @Override + public boolean execute( + PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { + val watcherMap = activityData.getWatcherInfoMap(); + for (int param : params) { + val watcher = watcherMap.get(param); + if (watcher == null || !watcher.isFinished()) { + return false; + } + } + return true; + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/all/NotFinishTalk.java b/src/main/java/emu/grasscutter/game/activity/condition/all/NotFinishTalk.java index b863b3885..96c176867 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/all/NotFinishTalk.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/all/NotFinishTalk.java @@ -1,22 +1,21 @@ -package emu.grasscutter.game.activity.condition.all; - -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.activity.condition.ActivityCondition; -import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; - -import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_NOT_FINISH_TALK; - -@ActivityCondition(NEW_ACTIVITY_COND_NOT_FINISH_TALK) -public class NotFinishTalk extends ActivityConditionBaseHandler { - @Override - public boolean execute(PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { - return activityData - .getPlayer() - .getQuestManager() - .getMainQuests() - .int2ObjectEntrySet() - .stream() - .noneMatch(q -> q.getValue().getTalks().get(params[0]) != null); //FIXME taken from ContentCompleteTalk - } -} +package emu.grasscutter.game.activity.condition.all; + +import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_NOT_FINISH_TALK; + +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.game.activity.condition.ActivityCondition; +import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; + +@ActivityCondition(NEW_ACTIVITY_COND_NOT_FINISH_TALK) +public class NotFinishTalk extends ActivityConditionBaseHandler { + @Override + public boolean execute( + PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { + return activityData.getPlayer().getQuestManager().getMainQuests().int2ObjectEntrySet().stream() + .noneMatch( + q -> + q.getValue().getTalks().get(params[0]) + != null); // FIXME taken from ContentCompleteTalk + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/all/PlayerLevelGreatEqualActivityActivityCondition.java b/src/main/java/emu/grasscutter/game/activity/condition/all/PlayerLevelGreatEqualActivityActivityCondition.java index 9d03da1a1..8fa24a91c 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/all/PlayerLevelGreatEqualActivityActivityCondition.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/all/PlayerLevelGreatEqualActivityActivityCondition.java @@ -1,17 +1,18 @@ -package emu.grasscutter.game.activity.condition.all; - -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.activity.condition.ActivityCondition; -import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; - -import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_PLAYER_LEVEL_GREAT_EQUAL; - -@ActivityCondition(NEW_ACTIVITY_COND_PLAYER_LEVEL_GREAT_EQUAL) -public class PlayerLevelGreatEqualActivityActivityCondition extends ActivityConditionBaseHandler { - - @Override - public boolean execute(PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { - return activityData.getPlayer().getLevel() >= params[0]; - } -} +package emu.grasscutter.game.activity.condition.all; + +import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_PLAYER_LEVEL_GREAT_EQUAL; + +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.game.activity.condition.ActivityCondition; +import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; + +@ActivityCondition(NEW_ACTIVITY_COND_PLAYER_LEVEL_GREAT_EQUAL) +public class PlayerLevelGreatEqualActivityActivityCondition extends ActivityConditionBaseHandler { + + @Override + public boolean execute( + PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { + return activityData.getPlayer().getLevel() >= params[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/all/QuestFinished.java b/src/main/java/emu/grasscutter/game/activity/condition/all/QuestFinished.java index cb2bea414..5b5a53318 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/all/QuestFinished.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/all/QuestFinished.java @@ -1,23 +1,21 @@ -package emu.grasscutter.game.activity.condition.all; - -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.activity.condition.ActivityCondition; -import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.enums.QuestState; - -import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_QUEST_FINISH; - -@ActivityCondition(NEW_ACTIVITY_COND_QUEST_FINISH) -public class QuestFinished extends ActivityConditionBaseHandler { - @Override - public boolean execute(PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { - GameQuest quest = activityData - .getPlayer() - .getQuestManager() - .getQuestById(params[0]); - - return quest != null && quest.getState() == QuestState.QUEST_STATE_FINISHED; - } -} +package emu.grasscutter.game.activity.condition.all; + +import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_QUEST_FINISH; + +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.game.activity.condition.ActivityCondition; +import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.enums.QuestState; + +@ActivityCondition(NEW_ACTIVITY_COND_QUEST_FINISH) +public class QuestFinished extends ActivityConditionBaseHandler { + @Override + public boolean execute( + PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { + GameQuest quest = activityData.getPlayer().getQuestManager().getQuestById(params[0]); + + return quest != null && quest.getState() == QuestState.QUEST_STATE_FINISHED; + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/all/SalesmanCanDeliver.java b/src/main/java/emu/grasscutter/game/activity/condition/all/SalesmanCanDeliver.java index 52e24f7d2..549c1e2e6 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/all/SalesmanCanDeliver.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/all/SalesmanCanDeliver.java @@ -1,19 +1,20 @@ -package emu.grasscutter.game.activity.condition.all; - -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.activity.condition.ActivityCondition; -import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; - -import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_SALESMAN_CAN_DELIVER; - -@ActivityCondition(NEW_ACTIVITY_COND_SALESMAN_CAN_DELIVER) -public class SalesmanCanDeliver extends ActivityConditionBaseHandler { - @Override - public boolean execute(PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { - //TODO need to reverse engineer this logic. - //This condition appears only in one condition "condId": 5003001 - //and this condition accept no params. I have no idea how to implement it - return false; - } -} +package emu.grasscutter.game.activity.condition.all; + +import static emu.grasscutter.game.activity.condition.ActivityConditions.NEW_ACTIVITY_COND_SALESMAN_CAN_DELIVER; + +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.game.activity.condition.ActivityCondition; +import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; + +@ActivityCondition(NEW_ACTIVITY_COND_SALESMAN_CAN_DELIVER) +public class SalesmanCanDeliver extends ActivityConditionBaseHandler { + @Override + public boolean execute( + PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { + // TODO need to reverse engineer this logic. + // This condition appears only in one condition "condId": 5003001 + // and this condition accept no params. I have no idea how to implement it + return false; + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/condition/all/UnknownActivityConditionHandler.java b/src/main/java/emu/grasscutter/game/activity/condition/all/UnknownActivityConditionHandler.java index 740cabf59..5f331c708 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/all/UnknownActivityConditionHandler.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/all/UnknownActivityConditionHandler.java @@ -1,18 +1,17 @@ -package emu.grasscutter.game.activity.condition.all; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; - -/** - * This class is used when condition was not found - */ -public class UnknownActivityConditionHandler extends ActivityConditionBaseHandler { - - @Override - public boolean execute(PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { - Grasscutter.getLogger().error("Called unknown condition handler"); - return false; - } -} +package emu.grasscutter.game.activity.condition.all; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.game.activity.condition.ActivityConditionBaseHandler; + +/** This class is used when condition was not found */ +public class UnknownActivityConditionHandler extends ActivityConditionBaseHandler { + + @Override + public boolean execute( + PlayerActivityData activityData, ActivityConfigItem activityConfig, int... params) { + Grasscutter.getLogger().error("Called unknown condition handler"); + return false; + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java index b470b046d..8d6c1e4a3 100644 --- a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java +++ b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java @@ -1,36 +1,35 @@ -package emu.grasscutter.game.activity.trialavatar; - -import emu.grasscutter.game.activity.ActivityWatcher; -import emu.grasscutter.game.activity.ActivityWatcherType; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.props.WatcherTriggerType; - -import lombok.val; -import java.util.stream.Stream; - -@ActivityWatcherType(WatcherTriggerType.TRIGGER_FINISH_CHALLENGE) -public class TrialAvatarActivityChallengeTrigger extends ActivityWatcher { - @Override - protected boolean isMeet(String... param) { - if(param.length < 3) return false; - - val handler = (TrialAvatarActivityHandler) getActivityHandler(); - if(handler == null) return false; - - val paramList = handler.getTriggerParamList(); - if(paramList.isEmpty()) return false; - - val paramCond = Stream.of(paramList.get(0).split(",")).toList(); - return Stream.of(param).allMatch(x -> paramCond.contains(x)); - } - - @Override - public void trigger(PlayerActivityData playerActivityData, String... param) { - if (!isMeet(param)) return; - - val handler = (TrialAvatarActivityHandler) getActivityHandler(); - if(handler == null) return; - - handler.setPassDungeon(playerActivityData); - } -} +package emu.grasscutter.game.activity.trialavatar; + +import emu.grasscutter.game.activity.ActivityWatcher; +import emu.grasscutter.game.activity.ActivityWatcherType; +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.game.props.WatcherTriggerType; +import java.util.stream.Stream; +import lombok.val; + +@ActivityWatcherType(WatcherTriggerType.TRIGGER_FINISH_CHALLENGE) +public class TrialAvatarActivityChallengeTrigger extends ActivityWatcher { + @Override + protected boolean isMeet(String... param) { + if (param.length < 3) return false; + + val handler = (TrialAvatarActivityHandler) getActivityHandler(); + if (handler == null) return false; + + val paramList = handler.getTriggerParamList(); + if (paramList.isEmpty()) return false; + + val paramCond = Stream.of(paramList.get(0).split(",")).toList(); + return Stream.of(param).allMatch(x -> paramCond.contains(x)); + } + + @Override + public void trigger(PlayerActivityData playerActivityData, String... param) { + if (!isMeet(param)) return; + + val handler = (TrialAvatarActivityHandler) getActivityHandler(); + if (handler == null) return; + + handler.setPassDungeon(playerActivityData); + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityHandler.java b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityHandler.java index 1c20991a4..5f81a9cb2 100644 --- a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityHandler.java +++ b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityHandler.java @@ -1,144 +1,164 @@ -package emu.grasscutter.game.activity.trialavatar; - -import com.esotericsoftware.reflectasm.ConstructorAccess; -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.RewardData; -import emu.grasscutter.game.activity.ActivityWatcher; -import emu.grasscutter.game.activity.DefaultWatcher; -import emu.grasscutter.game.dungeons.DungeonTrialTeam; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.game.props.WatcherTriggerType; -import emu.grasscutter.game.activity.ActivityHandler; -import emu.grasscutter.game.activity.GameActivity; -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.game.props.ActivityType; -import emu.grasscutter.net.proto.ActivityInfoOuterClass.ActivityInfo; -import emu.grasscutter.net.proto.TrialAvatarGrantRecordOuterClass.TrialAvatarGrantRecord.GrantReason; -import emu.grasscutter.server.packet.send.PacketActivityInfoNotify; -import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify; -import emu.grasscutter.utils.JsonUtils; - -import java.util.*; -import java.util.stream.*; -import lombok.*; - -@GameActivity(ActivityType.NEW_ACTIVITY_TRIAL_AVATAR) -public class TrialAvatarActivityHandler extends ActivityHandler { - @Getter @Setter private int selectedTrialAvatarIndex; - - @Override - public void onInitPlayerActivityData(PlayerActivityData playerActivityData) { - TrialAvatarPlayerData trialAvatarPlayerData = TrialAvatarPlayerData.create(getActivityConfigItem().getScheduleId()); - - playerActivityData.setDetail(trialAvatarPlayerData); - } - - @Override - public void onProtoBuild(PlayerActivityData playerActivityData, ActivityInfo.Builder activityInfo) { - TrialAvatarPlayerData trialAvatarPlayerData = getTrialAvatarPlayerData(playerActivityData); - - activityInfo.setTrialAvatarInfo(trialAvatarPlayerData.toProto()); - } - - @Override - public void initWatchers(Map> activityWatcherTypeMap) { - var watcherType = activityWatcherTypeMap.get(WatcherTriggerType.TRIGGER_FINISH_CHALLENGE); - ActivityWatcher watcher; - if(watcherType != null){ - watcher = (ActivityWatcher) watcherType.newInstance(); - }else{ - watcher = new DefaultWatcher(); - } - - watcher.setActivityHandler(this); - getWatchersMap().computeIfAbsent(WatcherTriggerType.TRIGGER_FINISH_CHALLENGE, k -> new ArrayList<>()); - getWatchersMap().get(WatcherTriggerType.TRIGGER_FINISH_CHALLENGE).add(watcher); - } - - public TrialAvatarPlayerData getTrialAvatarPlayerData(PlayerActivityData playerActivityData) { - if (playerActivityData.getDetail() == null || playerActivityData.getDetail().isBlank()) { - onInitPlayerActivityData(playerActivityData); - playerActivityData.save(); - } - - return JsonUtils.decode(playerActivityData.getDetail(), TrialAvatarPlayerData.class); - } - - public int getTrialActivityDungeonId(int trialAvatarIndexId) { - val data = GameData.getTrialAvatarActivityDataByAvatarIndex(trialAvatarIndexId); - return data!=null ? data.getDungeonId() : -1; - } - - public List getTriggerParamList() { - val data = GameData.getTrialAvatarActivityDataByAvatarIndex(getSelectedTrialAvatarIndex()); - return data!=null ? data.getTriggerConfig().getParamList() : Collections.emptyList(); - } - - public boolean enterTrialDungeon(Player player, int trialAvatarIndexId, int enterPointId) { - // TODO, not sure if this will cause problem in MP, since we are entering trial activity dungeon - player.sendPacket(new PacketScenePlayerLocationNotify(player.getScene())); // official does send this - - if (!player.getServer().getDungeonSystem().enterDungeon( - player, - enterPointId, - getTrialActivityDungeonId(trialAvatarIndexId))) return false; - - setSelectedTrialAvatarIndex(trialAvatarIndexId); - - return true; - } - - public List getBattleAvatarsList() { - val activityData = GameData.getTrialAvatarActivityDataByAvatarIndex(getSelectedTrialAvatarIndex()); - if (activityData == null || activityData.getBattleAvatarsList().isBlank()) return List.of(); - return Stream.of(activityData.getBattleAvatarsList().split(",")).map(Integer::parseInt).toList(); - } - - public DungeonTrialTeam getTrialAvatarDungeonTeam(){ - List battleAvatarsList = getBattleAvatarsList(); - if (battleAvatarsList.isEmpty()) return null; - - return new DungeonTrialTeam(battleAvatarsList, GrantReason.GRANT_REASON_BY_TRIAL_AVATAR_ACTIVITY); - } - - public void unsetTrialAvatarTeam(Player player) { - if (getSelectedTrialAvatarIndex() <= 0) return; - player.removeTrialAvatarForActivity(); - setSelectedTrialAvatarIndex(0); - } - - public boolean getReward(Player player, int trialAvatarIndexId) { - val playerActivityData = player.getActivityManager().getPlayerActivityDataByActivityType(ActivityType.NEW_ACTIVITY_TRIAL_AVATAR); - - if(playerActivityData.isEmpty()){ - return false; - } - - TrialAvatarPlayerData trialAvatarPlayerData = getTrialAvatarPlayerData(playerActivityData.get()); - TrialAvatarPlayerData.RewardInfoItem rewardInfo = trialAvatarPlayerData.getRewardInfo(trialAvatarIndexId); - if (rewardInfo == null) return false; - - RewardData rewardParam = GameData.getRewardDataMap().get(rewardInfo.getRewardId()); - if (rewardParam == null) return false; - - player.getInventory().addItemParamDatas(rewardParam.getRewardItemList(), ActionReason.TrialAvatarActivityFirstPassReward); - rewardInfo.setReceivedReward(true); - playerActivityData.get().setDetail(trialAvatarPlayerData); - playerActivityData.get().save(); - return true; - } - - public void setPassDungeon(PlayerActivityData playerActivityData) { - TrialAvatarPlayerData trialAvatarPlayerData = getTrialAvatarPlayerData(playerActivityData); - TrialAvatarPlayerData.RewardInfoItem rewardInfo = trialAvatarPlayerData.getRewardInfo(getSelectedTrialAvatarIndex()); - if (rewardInfo == null) return; - - rewardInfo.setPassedDungeon(true); - playerActivityData.setDetail(trialAvatarPlayerData); - playerActivityData.save(); - Player player = Grasscutter.getGameServer().getPlayerByUid(playerActivityData.getUid()); - player.sendPacket(new PacketActivityInfoNotify(toProto(playerActivityData, player.getActivityManager().getConditionExecutor()))); - } -} +package emu.grasscutter.game.activity.trialavatar; + +import com.esotericsoftware.reflectasm.ConstructorAccess; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.excels.RewardData; +import emu.grasscutter.game.activity.ActivityHandler; +import emu.grasscutter.game.activity.ActivityWatcher; +import emu.grasscutter.game.activity.DefaultWatcher; +import emu.grasscutter.game.activity.GameActivity; +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.game.dungeons.DungeonTrialTeam; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.game.props.ActivityType; +import emu.grasscutter.game.props.WatcherTriggerType; +import emu.grasscutter.net.proto.ActivityInfoOuterClass.ActivityInfo; +import emu.grasscutter.net.proto.TrialAvatarGrantRecordOuterClass.TrialAvatarGrantRecord.GrantReason; +import emu.grasscutter.server.packet.send.PacketActivityInfoNotify; +import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify; +import emu.grasscutter.utils.JsonUtils; +import java.util.*; +import java.util.stream.*; +import lombok.*; + +@GameActivity(ActivityType.NEW_ACTIVITY_TRIAL_AVATAR) +public class TrialAvatarActivityHandler extends ActivityHandler { + @Getter @Setter private int selectedTrialAvatarIndex; + + @Override + public void onInitPlayerActivityData(PlayerActivityData playerActivityData) { + TrialAvatarPlayerData trialAvatarPlayerData = + TrialAvatarPlayerData.create(getActivityConfigItem().getScheduleId()); + + playerActivityData.setDetail(trialAvatarPlayerData); + } + + @Override + public void onProtoBuild( + PlayerActivityData playerActivityData, ActivityInfo.Builder activityInfo) { + TrialAvatarPlayerData trialAvatarPlayerData = getTrialAvatarPlayerData(playerActivityData); + + // TODO: Apply trial avatar info. + // activityInfo.setTrialAvatarInfo(trialAvatarPlayerData.toProto()); + } + + @Override + public void initWatchers(Map> activityWatcherTypeMap) { + var watcherType = activityWatcherTypeMap.get(WatcherTriggerType.TRIGGER_FINISH_CHALLENGE); + ActivityWatcher watcher; + if (watcherType != null) { + watcher = (ActivityWatcher) watcherType.newInstance(); + } else { + watcher = new DefaultWatcher(); + } + + watcher.setActivityHandler(this); + getWatchersMap() + .computeIfAbsent(WatcherTriggerType.TRIGGER_FINISH_CHALLENGE, k -> new ArrayList<>()); + getWatchersMap().get(WatcherTriggerType.TRIGGER_FINISH_CHALLENGE).add(watcher); + } + + public TrialAvatarPlayerData getTrialAvatarPlayerData(PlayerActivityData playerActivityData) { + if (playerActivityData.getDetail() == null || playerActivityData.getDetail().isBlank()) { + onInitPlayerActivityData(playerActivityData); + playerActivityData.save(); + } + + return JsonUtils.decode(playerActivityData.getDetail(), TrialAvatarPlayerData.class); + } + + public int getTrialActivityDungeonId(int trialAvatarIndexId) { + val data = GameData.getTrialAvatarActivityDataByAvatarIndex(trialAvatarIndexId); + return data != null ? data.getDungeonId() : -1; + } + + public List getTriggerParamList() { + val data = GameData.getTrialAvatarActivityDataByAvatarIndex(getSelectedTrialAvatarIndex()); + return data != null ? data.getTriggerConfig().getParamList() : Collections.emptyList(); + } + + public boolean enterTrialDungeon(Player player, int trialAvatarIndexId, int enterPointId) { + // TODO, not sure if this will cause problem in MP, since we are entering trial activity dungeon + player.sendPacket( + new PacketScenePlayerLocationNotify(player.getScene())); // official does send this + + if (!player + .getServer() + .getDungeonSystem() + .enterDungeon(player, enterPointId, getTrialActivityDungeonId(trialAvatarIndexId))) + return false; + + setSelectedTrialAvatarIndex(trialAvatarIndexId); + + return true; + } + + public List getBattleAvatarsList() { + val activityData = + GameData.getTrialAvatarActivityDataByAvatarIndex(getSelectedTrialAvatarIndex()); + if (activityData == null || activityData.getBattleAvatarsList().isBlank()) return List.of(); + return Stream.of(activityData.getBattleAvatarsList().split(",")) + .map(Integer::parseInt) + .toList(); + } + + public DungeonTrialTeam getTrialAvatarDungeonTeam() { + List battleAvatarsList = getBattleAvatarsList(); + if (battleAvatarsList.isEmpty()) return null; + + return new DungeonTrialTeam( + battleAvatarsList, GrantReason.GRANT_REASON_BY_TRIAL_AVATAR_ACTIVITY); + } + + public void unsetTrialAvatarTeam(Player player) { + if (this.getSelectedTrialAvatarIndex() <= 0) return; + player.getTeamManager().removeTrialAvatar(); + this.setSelectedTrialAvatarIndex(0); + } + + public boolean getReward(Player player, int trialAvatarIndexId) { + val playerActivityData = + player + .getActivityManager() + .getPlayerActivityDataByActivityType(ActivityType.NEW_ACTIVITY_TRIAL_AVATAR); + + if (playerActivityData.isEmpty()) { + return false; + } + + TrialAvatarPlayerData trialAvatarPlayerData = + getTrialAvatarPlayerData(playerActivityData.get()); + TrialAvatarPlayerData.RewardInfoItem rewardInfo = + trialAvatarPlayerData.getRewardInfo(trialAvatarIndexId); + if (rewardInfo == null) return false; + + RewardData rewardParam = GameData.getRewardDataMap().get(rewardInfo.getRewardId()); + if (rewardParam == null) return false; + + player + .getInventory() + .addItemParamDatas( + rewardParam.getRewardItemList(), ActionReason.TrialAvatarActivityFirstPassReward); + rewardInfo.setReceivedReward(true); + playerActivityData.get().setDetail(trialAvatarPlayerData); + playerActivityData.get().save(); + return true; + } + + public void setPassDungeon(PlayerActivityData playerActivityData) { + TrialAvatarPlayerData trialAvatarPlayerData = getTrialAvatarPlayerData(playerActivityData); + TrialAvatarPlayerData.RewardInfoItem rewardInfo = + trialAvatarPlayerData.getRewardInfo(getSelectedTrialAvatarIndex()); + if (rewardInfo == null) return; + + rewardInfo.setPassedDungeon(true); + playerActivityData.setDetail(trialAvatarPlayerData); + playerActivityData.save(); + Player player = Grasscutter.getGameServer().getPlayerByUid(playerActivityData.getUid()); + player.sendPacket( + new PacketActivityInfoNotify( + toProto(playerActivityData, player.getActivityManager().getConditionExecutor()))); + } +} diff --git a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarPlayerData.java b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarPlayerData.java index 1001d1858..15efd495a 100644 --- a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarPlayerData.java +++ b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarPlayerData.java @@ -1,90 +1,90 @@ -package emu.grasscutter.game.activity.trialavatar; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.common.BaseTrialActivityData; -import emu.grasscutter.net.proto.TrialAvatarActivityDetailInfoOuterClass.TrialAvatarActivityDetailInfo; -import emu.grasscutter.net.proto.TrialAvatarActivityRewardDetailInfoOuterClass.TrialAvatarActivityRewardDetailInfo; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Data; -import lombok.experimental.FieldDefaults; -import lombok.val; - -import java.util.List; -import java.util.stream.*; - -@Data -@FieldDefaults(level = AccessLevel.PRIVATE) -@Builder(builderMethodName = "of") -public class TrialAvatarPlayerData { - List rewardInfoList; - - private static BaseTrialActivityData getActivityData(int scheduleId){ - // prefer custom data over official data - return GameData.getTrialAvatarActivityCustomData().isEmpty() ? GameData.getTrialAvatarActivityDataMap().get(scheduleId) - : GameData.getTrialAvatarActivityCustomData().get(scheduleId); - } - - public static List getAvatarIdList(int scheduleId) { - val activityData = getActivityData(scheduleId); - return activityData != null ? activityData.getAvatarIndexIdList() : List.of(); - } - - public static List getRewardIdList(int scheduleId) { - val activityData = getActivityData(scheduleId); - return activityData != null ? activityData.getRewardIdList() : List.of(); - } - - public static TrialAvatarPlayerData create(int scheduleId) { - List avatarIds = getAvatarIdList(scheduleId); - List rewardIds = getRewardIdList(scheduleId); - return TrialAvatarPlayerData.of() - .rewardInfoList(IntStream.range(0, avatarIds.size()) - .filter(i -> avatarIds.get(i) > 0 && rewardIds.get(i) > 0) - .mapToObj(i -> RewardInfoItem.create( - avatarIds.get(i), - rewardIds.get(i))) - .collect(Collectors.toList())) - .build(); - } - - public TrialAvatarActivityDetailInfo toProto() { - return TrialAvatarActivityDetailInfo.newBuilder() - .addAllRewardInfoList(getRewardInfoList().stream() - .map(RewardInfoItem::toProto).toList()) - .build(); - } - - public RewardInfoItem getRewardInfo(int trialAvatarIndexId) { - return getRewardInfoList().stream().filter(x -> x.getTrialAvatarIndexId() == trialAvatarIndexId) - .findFirst().orElse(null); - } - - @Data - @FieldDefaults(level = AccessLevel.PRIVATE) - @Builder(builderMethodName = "of") - public static class RewardInfoItem { - int trialAvatarIndexId; - int rewardId; - boolean passedDungeon; - boolean receivedReward; - - public static RewardInfoItem create(int trialAvatarIndexId, int rewardId) { - return RewardInfoItem.of() - .trialAvatarIndexId(trialAvatarIndexId) - .rewardId(rewardId) - .passedDungeon(false) - .receivedReward(false) - .build(); - } - - public TrialAvatarActivityRewardDetailInfo toProto() { - return TrialAvatarActivityRewardDetailInfo.newBuilder() - .setTrialAvatarIndexId(getTrialAvatarIndexId()) - .setRewardId(getRewardId()) - .setPassedDungeon(isPassedDungeon()) - .setReceivedReward(isReceivedReward()) - .build(); - } - } -} +package emu.grasscutter.game.activity.trialavatar; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.common.BaseTrialActivityData; +import emu.grasscutter.net.proto.TrialAvatarActivityDetailInfoOuterClass.TrialAvatarActivityDetailInfo; +import emu.grasscutter.net.proto.TrialAvatarActivityRewardDetailInfoOuterClass.TrialAvatarActivityRewardDetailInfo; +import java.util.List; +import java.util.stream.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.experimental.FieldDefaults; +import lombok.val; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +@Builder(builderMethodName = "of") +public class TrialAvatarPlayerData { + List rewardInfoList; + + private static BaseTrialActivityData getActivityData(int scheduleId) { + // prefer custom data over official data + return GameData.getTrialAvatarActivityCustomData().isEmpty() + ? GameData.getTrialAvatarActivityDataMap().get(scheduleId) + : GameData.getTrialAvatarActivityCustomData().get(scheduleId); + } + + public static List getAvatarIdList(int scheduleId) { + val activityData = getActivityData(scheduleId); + return activityData != null ? activityData.getAvatarIndexIdList() : List.of(); + } + + public static List getRewardIdList(int scheduleId) { + val activityData = getActivityData(scheduleId); + return activityData != null ? activityData.getRewardIdList() : List.of(); + } + + public static TrialAvatarPlayerData create(int scheduleId) { + List avatarIds = getAvatarIdList(scheduleId); + List rewardIds = getRewardIdList(scheduleId); + return TrialAvatarPlayerData.of() + .rewardInfoList( + IntStream.range(0, avatarIds.size()) + .filter(i -> avatarIds.get(i) > 0 && rewardIds.get(i) > 0) + .mapToObj(i -> RewardInfoItem.create(avatarIds.get(i), rewardIds.get(i))) + .collect(Collectors.toList())) + .build(); + } + + public TrialAvatarActivityDetailInfo toProto() { + return TrialAvatarActivityDetailInfo.newBuilder() + .addAllRewardInfoList(getRewardInfoList().stream().map(RewardInfoItem::toProto).toList()) + .build(); + } + + public RewardInfoItem getRewardInfo(int trialAvatarIndexId) { + return getRewardInfoList().stream() + .filter(x -> x.getTrialAvatarIndexId() == trialAvatarIndexId) + .findFirst() + .orElse(null); + } + + @Data + @FieldDefaults(level = AccessLevel.PRIVATE) + @Builder(builderMethodName = "of") + public static class RewardInfoItem { + int trialAvatarIndexId; + int rewardId; + boolean passedDungeon; + boolean receivedReward; + + public static RewardInfoItem create(int trialAvatarIndexId, int rewardId) { + return RewardInfoItem.of() + .trialAvatarIndexId(trialAvatarIndexId) + .rewardId(rewardId) + .passedDungeon(false) + .receivedReward(false) + .build(); + } + + public TrialAvatarActivityRewardDetailInfo toProto() { + return TrialAvatarActivityRewardDetailInfo.newBuilder() + .setTrialAvatarIndexId(getTrialAvatarIndexId()) + .setRewardId(getRewardId()) + .setPassedDungeon(isPassedDungeon()) + .setReceivedReward(isReceivedReward()) + .build(); + } + } +} diff --git a/src/main/java/emu/grasscutter/game/avatar/Avatar.java b/src/main/java/emu/grasscutter/game/avatar/Avatar.java index bfe84a0ed..5ad30bf92 100644 --- a/src/main/java/emu/grasscutter/game/avatar/Avatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/Avatar.java @@ -9,8 +9,19 @@ import emu.grasscutter.data.binout.OpenConfigEntry; import emu.grasscutter.data.binout.OpenConfigEntry.SkillPointModifier; import emu.grasscutter.data.common.FightPropData; import emu.grasscutter.data.excels.*; -import emu.grasscutter.data.excels.AvatarSkillDepotData.InherentProudSkillOpens; import emu.grasscutter.data.excels.ItemData.WeaponProperty; +import emu.grasscutter.data.excels.avatar.AvatarData; +import emu.grasscutter.data.excels.avatar.AvatarSkillData; +import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; +import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData.InherentProudSkillOpens; +import emu.grasscutter.data.excels.avatar.AvatarTalentData; +import emu.grasscutter.data.excels.reliquary.ReliquaryAffixData; +import emu.grasscutter.data.excels.reliquary.ReliquaryLevelData; +import emu.grasscutter.data.excels.reliquary.ReliquaryMainPropData; +import emu.grasscutter.data.excels.reliquary.ReliquarySetData; +import emu.grasscutter.data.excels.trial.TrialAvatarTemplateData; +import emu.grasscutter.data.excels.weapon.WeaponCurveData; +import emu.grasscutter.data.excels.weapon.WeaponPromoteData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.inventory.EquipType; @@ -25,11 +36,14 @@ import emu.grasscutter.net.proto.FetterDataOuterClass.FetterData; import emu.grasscutter.net.proto.ShowAvatarInfoOuterClass; import emu.grasscutter.net.proto.ShowAvatarInfoOuterClass.ShowAvatarInfo; import emu.grasscutter.net.proto.ShowEquipOuterClass.ShowEquip; +import emu.grasscutter.net.proto.TrialAvatarGrantRecordOuterClass.TrialAvatarGrantRecord; +import emu.grasscutter.net.proto.TrialAvatarInfoOuterClass.TrialAvatarInfo; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.ProtoHelper; import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; import lombok.val; @@ -43,7 +57,7 @@ public class Avatar { @Id private ObjectId id; @Indexed @Getter private int ownerId; // Id of player that this avatar belongs to @Transient private Player owner; - @Transient @Getter private AvatarData data; + @Transient @Getter private AvatarData avatarData; @Transient @Getter private AvatarSkillDepotData skillDepot; @Transient @Getter private long guid; // Player unique id @Getter private int avatarId; // Id of avatar @@ -81,6 +95,17 @@ public class Avatar { @Getter @Setter private int nameCardRewardId; @Getter @Setter private int nameCardId; + // trial avatar property + @Getter @Setter private int trialAvatarId = 0; + // cannot store to db if grant reason is not integer + @Getter @Setter + private int grantReason = TrialAvatarGrantRecord.GrantReason.GRANT_REASON_INVALID.getNumber(); + + @Getter @Setter private int fromParentQuestId = 0; + // so far no outer class or prop value has information of this, but from packet: + // 1 = normal, 2 = trial avatar + @Getter @Setter private int avatarType = Type.NORMAL.getNumber(); + @Deprecated // Do not use. Morhpia only! public Avatar() { this.equips = new Int2ObjectOpenHashMap<>(); @@ -100,7 +125,7 @@ public class Avatar { this.avatarId = data.getId(); this.nameCardRewardId = data.getNameCardRewardId(); this.nameCardId = data.getNameCardId(); - this.data = data; + this.avatarData = data; this.bornTime = (int) (System.currentTimeMillis() / 1000); this.flyCloak = 140001; @@ -154,16 +179,12 @@ public class Avatar { } public ObjectId getObjectId() { - return id; - } - - public AvatarData getAvatarData() { - return data; + return this.id; } protected void setAvatarData(AvatarData data) { - if (this.data != null) return; - this.data = data; // Used while loading this from the database + if (this.avatarData != null) return; + this.avatarData = data; // Used while loading this from the database } public void setOwner(Player player) { @@ -680,7 +701,7 @@ public class Avatar { this.skillExtraChargeMap.clear(); // Sanity checks - if (this.data == null || this.skillDepot == null) { + if (this.avatarData == null || this.skillDepot == null) { return; } @@ -1001,6 +1022,186 @@ public class Avatar { return showAvatarInfo.build(); } + /** + * Converts this avatar into a trial avatar. + * + * @param level The avatar's level. + * @param avatarId The ID of the avatar. + * @param grantReason The reason for granting the avatar. + * @param questId The ID of the quest that granted the avatar. + */ + public void setTrialAvatarInfo( + int level, int avatarId, TrialAvatarGrantRecord.GrantReason grantReason, int questId) { + this.setLevel(level); + this.setPromoteLevel(getMinPromoteLevel(level)); + this.setTrialAvatarId(avatarId); + this.setGrantReason(grantReason.getNumber()); + this.setFromParentQuestId(questId); + this.setAvatarType(Type.TRIAL.getNumber()); + this.applyTrialSkillLevels(); + this.applyTrialItems(); + } + + /** + * Gets the gear template based on the avatar's level. + * + * @return The avatar's template. + */ + private int getTrialTemplate() { + return this.getLevel() <= 9 + ? 1 + : (int) + (Math.floor(this.getLevel() / 10f) * 10); // round trial level to fit template levels + } + + /** + * @return The level to be used for the avatar's skills (talents). + */ + public int getTrialSkillLevel() { + // Use default data if custom data not available. + if (GameData.getTrialAvatarCustomData().isEmpty()) { + var template = getTrialTemplate(); // round trial level to fit template levels + + var templateData = GameData.getTrialAvatarTemplateDataMap().get(template); + return templateData == null ? 1 : templateData.getTrialAvatarSkillLevel(); + } + + // Use custom data. + var trialData = GameData.getTrialAvatarCustomData().get(this.getTrialAvatarId()); + if (trialData == null) return 1; + + return trialData.getCoreProudSkillLevel(); // enhanced version of weapon + } + + /** Applies the correct skill level for the trial avatar. */ + public void applyTrialSkillLevels() { + this.getSkillLevelMap() + .keySet() + .forEach(skill -> this.setSkillLevel(skill, this.getTrialSkillLevel())); + } + + /** + * @return The weapon to use with the avatar. + */ + public int getTrialWeaponId() { + // Use default data if custom data not available. + if (GameData.getTrialAvatarCustomData().isEmpty()) { + if (GameData.getTrialAvatarDataMap().get(this.getTrialAvatarId()) == null) + return this.getAvatarData().getInitialWeapon(); + + return GameData.getItemDataMap().get(this.getAvatarData().getInitialWeapon() + 100) == null + ? getAvatarData().getInitialWeapon() + : getAvatarData().getInitialWeapon() + 100; // enhanced version of weapon + } + + // Use custom data. + var trialData = GameData.getTrialAvatarCustomData().get(this.getTrialAvatarId()); + if (trialData == null) return 0; + + var trialCustomParams = trialData.getTrialAvatarParamList(); + return trialCustomParams.size() < 2 + ? getAvatarData().getInitialWeapon() + : Integer.parseInt(trialCustomParams.get(1).split(";")[0]); + } + + /** + * @return A list of artifact IDs to use with the avatar. + */ + public List getTrialReliquary() { + // Use default data if custom data not available. + if (GameData.getTrialAvatarCustomData().isEmpty()) { + int trialAvatarTemplateLevel = getTrialTemplate(); + + TrialAvatarTemplateData templateData = + GameData.getTrialAvatarTemplateDataMap().get(trialAvatarTemplateLevel); + return templateData == null ? List.of() : templateData.getTrialReliquaryList(); + } + + // Use custom data. + var trialData = GameData.getTrialAvatarCustomData().get(this.getTrialAvatarId()); + if (trialData == null) return List.of(); + + var trialCustomParams = + GameData.getTrialAvatarCustomData().get(getTrialAvatarId()).getTrialAvatarParamList(); + return trialCustomParams.size() < 3 + ? List.of() + : Stream.of(trialCustomParams.get(2).split(";")).map(Integer::parseInt).toList(); + } + + /** Applies the correct items for the trial avatar. */ + public void applyTrialItems() { + // Use an enhanced version of the weapon if available. + var weapon = new GameItem(this.getTrialWeaponId()); + weapon.setLevel(this.getLevel()); + weapon.setExp(0); + weapon.setPromoteLevel(getMinPromoteLevel(this.getLevel())); + this.getEquips().put(weapon.getEquipSlot(), weapon); + + // Add artifacts for the trial avatar. + this.getTrialReliquary() + .forEach( + id -> { + var reliquaryData = GameData.getTrialReliquaryDataMap().get((int) id); + if (reliquaryData == null) return; + + var relic = new GameItem(reliquaryData.getReliquaryId()); + relic.setLevel(reliquaryData.getLevel()); + relic.setMainPropId(reliquaryData.getMainPropId()); + relic.getAppendPropIdList().addAll(reliquaryData.getAppendPropList()); + this.getEquips().put(relic.getEquipSlot(), relic); + }); + + // Add costume if avatar has a costume. + GameData.getAvatarCostumeDataItemIdMap() + .values() + .forEach( + costumeData -> { + if (costumeData.getCharacterId() != this.getAvatarId()) return; + this.setCostume(costumeData.getId()); + }); + } + + /** Equips the items applied from {@link Avatar#applyTrialItems()}. */ + public void equipTrialItems() { + var player = this.getPlayer(); + + this.getEquips() + .values() + .forEach( + item -> { + item.setEquipCharacter(this.getAvatarId()); + item.setOwner(player); + if (item.getItemData().getEquipType() == EquipType.EQUIP_WEAPON) { + item.setWeaponEntityId(player.getWorld().getNextEntityId(EntityIdType.WEAPON)); + player.sendPacket(new PacketAvatarEquipChangeNotify(this, item)); + } + }); + } + + /** + * Converts this (trial) avatar into a trial info protocol buffer. + * + * @return The trial info protocol buffer. + */ + public TrialAvatarInfo toTrialInfo() { + var trialAvatar = + TrialAvatarInfo.newBuilder() + .setTrialAvatarId(this.getTrialAvatarId()) + .setGrantRecord( + TrialAvatarGrantRecord.newBuilder() + .setGrantReason(this.getGrantReason()) + .setFromParentQuestId(this.getFromParentQuestId())); + + // Check if the avatar is a trial avatar. + if (this.getTrialAvatarId() > 0) { + // Add the artifacts & weapons for the avatar. + trialAvatar.addAllTrialEquipList( + this.getEquips().values().stream().map(GameItem::toProto).toList()); + } + + return trialAvatar.build(); + } + @PostLoad private void onLoad() {} @@ -1008,4 +1209,13 @@ public class Avatar { private void prePersist() { this.currentHp = this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP); } + + @AllArgsConstructor + @Getter + enum Type { + NORMAL(0), + TRIAL(1); + + final int number; + } } diff --git a/src/main/java/emu/grasscutter/game/avatar/AvatarStorage.java b/src/main/java/emu/grasscutter/game/avatar/AvatarStorage.java index abe0c11d8..34700a477 100644 --- a/src/main/java/emu/grasscutter/game/avatar/AvatarStorage.java +++ b/src/main/java/emu/grasscutter/game/avatar/AvatarStorage.java @@ -1,8 +1,8 @@ package emu.grasscutter.game.avatar; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.AvatarData; -import emu.grasscutter.data.excels.AvatarSkillDepotData; +import emu.grasscutter.data.excels.avatar.AvatarData; +import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.inventory.GameItem; diff --git a/src/main/java/emu/grasscutter/game/dungeons/BasicDungeonSettleListener.java b/src/main/java/emu/grasscutter/game/dungeons/BasicDungeonSettleListener.java index 5b5e243bd..68d2d87c8 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/BasicDungeonSettleListener.java +++ b/src/main/java/emu/grasscutter/game/dungeons/BasicDungeonSettleListener.java @@ -1,14 +1,14 @@ -package emu.grasscutter.game.dungeons; - -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.server.packet.send.PacketDungeonSettleNotify; -import emu.grasscutter.utils.Utils; - -public class BasicDungeonSettleListener implements DungeonSettleListener { - - @Override - public void onDungeonSettle(Scene scene) { - scene.setAutoCloseTime(Utils.getCurrentSeconds() + 1000); - scene.broadcastPacket(new PacketDungeonSettleNotify(scene.getChallenge())); - } -} +package emu.grasscutter.game.dungeons; + +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.server.packet.send.PacketDungeonSettleNotify; +import emu.grasscutter.utils.Utils; + +public class BasicDungeonSettleListener implements DungeonSettleListener { + + @Override + public void onDungeonSettle(Scene scene) { + scene.setAutoCloseTime(Utils.getCurrentSeconds() + 1000); + scene.broadcastPacket(new PacketDungeonSettleNotify(scene.getChallenge())); + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonEndStats.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonEndStats.java index 6943ab5a3..216163c9d 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonEndStats.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonEndStats.java @@ -1,18 +1,22 @@ -package emu.grasscutter.game.dungeons; - -import emu.grasscutter.game.dungeons.dungeon_results.BaseDungeonResult; -import lombok.Getter; - -public class DungeonEndStats { - @Getter private int killedMonsters; - @Getter private int timeTaken; - @Getter private int openChestCount; - @Getter private BaseDungeonResult.DungeonEndReason dungeonResult; - - public DungeonEndStats(int killedMonsters, int timeTaken, int openChestCount, BaseDungeonResult.DungeonEndReason dungeonResult){ - this.killedMonsters = killedMonsters; - this.timeTaken = timeTaken; - this.dungeonResult = dungeonResult; - this.openChestCount = openChestCount; - } -} +package emu.grasscutter.game.dungeons; + +import emu.grasscutter.game.dungeons.dungeon_results.BaseDungeonResult; +import lombok.Getter; + +public class DungeonEndStats { + @Getter private int killedMonsters; + @Getter private int timeTaken; + @Getter private int openChestCount; + @Getter private BaseDungeonResult.DungeonEndReason dungeonResult; + + public DungeonEndStats( + int killedMonsters, + int timeTaken, + int openChestCount, + BaseDungeonResult.DungeonEndReason dungeonResult) { + this.killedMonsters = killedMonsters; + this.timeTaken = timeTaken; + this.dungeonResult = dungeonResult; + this.openChestCount = openChestCount; + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java index c6ba88b02..d97668bbd 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonManager.java @@ -1,315 +1,332 @@ -package emu.grasscutter.game.dungeons; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.common.ItemParamData; -import emu.grasscutter.data.excels.DungeonData; -import emu.grasscutter.data.excels.DungeonPassConfigData; -import emu.grasscutter.game.activity.trialavatar.TrialAvatarActivityHandler; -import emu.grasscutter.game.dungeons.dungeon_results.BaseDungeonResult; -import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.game.props.ActivityType; -import emu.grasscutter.game.props.WatcherTriggerType; -import emu.grasscutter.game.quest.enums.LogicType; -import emu.grasscutter.game.quest.enums.QuestContent; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.scripts.constants.EventType; -import emu.grasscutter.scripts.data.ScriptArgs; -import emu.grasscutter.server.packet.send.PacketDungeonWayPointNotify; -import emu.grasscutter.server.packet.send.PacketGadgetAutoPickDropInfoNotify; -import emu.grasscutter.utils.Position; -import emu.grasscutter.utils.Utils; -import it.unimi.dsi.fastutil.ints.IntOpenHashSet; -import it.unimi.dsi.fastutil.ints.IntSet; -import lombok.Getter; -import lombok.NonNull; -import lombok.val; - -import javax.annotation.Nullable; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -/** - * TODO handle time limits - * TODO handle respawn points - * TODO handle team wipes and respawns - * TODO check monster level and levelConfigMap - */ -public class DungeonManager { - - @Getter private final Scene scene; - @Getter private final DungeonData dungeonData; - @Getter private final DungeonPassConfigData passConfigData; - - @Getter private final int[] finishedConditions; - private final IntSet rewardedPlayers = new IntOpenHashSet(); - private final Set activeDungeonWayPoints = new HashSet<>(); - private boolean ended = false; - private int newestWayPoint = 0; - @Getter private int startSceneTime = 0; - - DungeonTrialTeam trialTeam = null; - - public DungeonManager(@NonNull Scene scene, @NonNull DungeonData dungeonData) { - this.scene = scene; - this.dungeonData = dungeonData; - this.passConfigData = GameData.getDungeonPassConfigDataMap().get(dungeonData.getPassCond()); - this.finishedConditions = new int[passConfigData.getConds().size()]; - this.scene.setDungeonManager(this); - } - - public void triggerEvent(DungeonPassConditionType conditionType, int... params) { - if (ended) { - return; - } - for (int i = 0; i < passConfigData.getConds().size(); i++) { - var cond = passConfigData.getConds().get(i); - if (conditionType == cond.getCondType()) { - if (getScene().getWorld().getServer().getDungeonSystem().triggerCondition(cond, params)) { - finishedConditions[i] = 1; - } - - } - } - - if (isFinishedSuccessfully()) { - finishDungeon(); - } - - } - - public boolean isFinishedSuccessfully() { - return LogicType.calculate(passConfigData.getLogicType(), finishedConditions); - } - - public int getLevelForMonster(int id) { - //TODO should use levelConfigMap? and how? - return dungeonData.getShowLevel(); - } - - public boolean activateRespawnPoint(int pointId) { - val respawnPoint = GameData.getScenePointEntryById(scene.getId(), pointId); - - if (respawnPoint == null) { - Grasscutter.getLogger().warn("trying to activate unknown respawn point {}", pointId); - return false; - } - - scene.broadcastPacket(new PacketDungeonWayPointNotify(activeDungeonWayPoints.add(pointId), activeDungeonWayPoints)); - newestWayPoint = pointId; - - Grasscutter.getLogger().debug("[unimplemented respawn] activated respawn point {}", pointId); - return true; - } - - @Nullable - public Position getRespawnLocation() { - if (newestWayPoint == 0) { // validity is checked before setting it, so if != 0 its always valid - return null; - } - val pointData = GameData.getScenePointEntryById(scene.getId(), newestWayPoint).getPointData(); - return pointData.getTranPos() != null ? pointData.getTranPos() : pointData.getPos(); - } - - public Position getRespawnRotation() { - if (newestWayPoint == 0) { // validity is checked before setting it, so if != 0 its always valid - return null; - } - val pointData = GameData.getScenePointEntryById(scene.getId(), newestWayPoint).getPointData(); - return pointData.getRot() != null ? pointData.getRot() : null; - } - - public boolean getStatueDrops(Player player, boolean useCondensed, int groupId) { - if (!isFinishedSuccessfully() || dungeonData.getRewardPreviewData() == null || dungeonData.getRewardPreviewData().getPreviewItems().length == 0) { - return false; - } - - // Already rewarded - if (rewardedPlayers.contains(player.getUid())) { - return false; - } - - - if (!handleCost(player, useCondensed)) { - return false; - } - - // Get and roll rewards. - List rewards = new ArrayList<>(this.rollRewards(useCondensed)); - // Add rewards to player and send notification. - player.getInventory().addItems(rewards, ActionReason.DungeonStatueDrop); - player.sendPacket(new PacketGadgetAutoPickDropInfoNotify(rewards)); - - rewardedPlayers.add(player.getUid()); - - scene.getScriptManager().callEvent(new ScriptArgs(groupId, EventType.EVENT_DUNGEON_REWARD_GET)); - return true; - } - - public boolean handleCost(Player player, boolean useCondensed) { - int resinCost = dungeonData.getStatueCostCount() != 0 ? dungeonData.getStatueCostCount() : 20; - if (resinCost == 0) { - return true; - } - if (useCondensed) { - // Check if condensed resin is usable here. - // For this, we use the following logic for now: - // The normal resin cost of the dungeon has to be 20. - if (resinCost != 20) { - return false; - } - - // Spend the condensed resin and only proceed if the transaction succeeds. - return player.getResinManager().useCondensedResin(1); - } else if (dungeonData.getStatueCostID() == 106) { - // Spend the resin and only proceed if the transaction succeeds. - return player.getResinManager().useResin(resinCost); - } - return true; - } - - private List rollRewards(boolean useCondensed) { - List rewards = new ArrayList<>(); - int dungeonId = this.dungeonData.getId(); - // If we have specific drop data for this dungeon, we use it. - if (GameData.getDungeonDropDataMap().containsKey(dungeonId)) { - List dropEntries = GameData.getDungeonDropDataMap().get(dungeonId); - - // Roll for each drop group. - for (var entry : dropEntries) { - // Determine the number of drops we get for this entry. - int start = entry.getCounts().get(0); - int end = entry.getCounts().get(entry.getCounts().size() - 1); - var candidateAmounts = IntStream.range(start, end + 1).boxed().collect(Collectors.toList()); - - int amount = Utils.drawRandomListElement(candidateAmounts, entry.getProbabilities()); - - if (useCondensed) { - amount += Utils.drawRandomListElement(candidateAmounts, entry.getProbabilities()); - } - - // Double rewards in multiplay mode, if specified. - if (entry.isMpDouble() && this.getScene().getPlayerCount() > 1) { - amount *= 2; - } - - // Roll items for this group. - // Here, we have to handle stacking, or the client will not display results correctly. - // For now, we use the following logic: If the possible drop item are a list of multiple items, - // we roll them separately. If not, we stack them. This should work out in practice, at least - // for the currently existing set of dungeons. - if (entry.getItems().size() == 1) { - rewards.add(new GameItem(entry.getItems().get(0), amount)); - } else { - for (int i = 0; i < amount; i++) { - // int itemIndex = ThreadLocalRandom.current().nextInt(0, entry.getItems().size()); - // int itemId = entry.getItems().get(itemIndex); - int itemId = Utils.drawRandomListElement(entry.getItems(), entry.getItemProbabilities()); - rewards.add(new GameItem(itemId, 1)); - } - } - } - } - // Otherwise, we fall back to the preview data. - else { - Grasscutter.getLogger().info("No drop data found or dungeon {}, falling back to preview data ...", dungeonId); - for (ItemParamData param : dungeonData.getRewardPreviewData().getPreviewItems()) { - rewards.add(new GameItem(param.getId(), Math.max(param.getCount(), 1))); - } - } - - return rewards; - } - - public void applyTrialTeam(Player player) { - if (getDungeonData() == null) return; - - switch (getDungeonData().getType()) { - // case DUNGEON_PLOT is handled by quest execs - case DUNGEON_ACTIVITY -> { - switch (getDungeonData().getPlayType()) { - case DUNGEON_PLAY_TYPE_TRIAL_AVATAR -> { - val activityHandler = player.getActivityManager() - .getActivityHandlerAs(ActivityType.NEW_ACTIVITY_TRIAL_AVATAR, TrialAvatarActivityHandler.class); - activityHandler.ifPresent(trialAvatarActivityHandler -> - this.trialTeam = trialAvatarActivityHandler.getTrialAvatarDungeonTeam()); - } - } - } - case DUNGEON_ELEMENT_CHALLENGE -> {} // TODO - } - if(this.trialTeam != null) { - player.addTrialAvatarsForActivity(trialTeam.trialAvatarIds); - } - } - - public void unsetTrialTeam(Player player){ - if(this.trialTeam==null){ - return; - } - player.removeTrialAvatarForActivity(); - this.trialTeam = null; - } - - public void startDungeon() { - this.startSceneTime = scene.getSceneTimeSeconds(); - scene.getPlayers().forEach(p -> { - p.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_ENTER_DUNGEON, dungeonData.getId()); - applyTrialTeam(p); - }); - } - - public void finishDungeon() { - notifyEndDungeon(true); - endDungeon(BaseDungeonResult.DungeonEndReason.COMPLETED); - } - - public void notifyEndDungeon(boolean successfully) { - scene.getPlayers().forEach(p -> { - // Quest trigger - p.getQuestManager().queueEvent(successfully ? - QuestContent.QUEST_CONTENT_FINISH_DUNGEON : QuestContent.QUEST_CONTENT_FAIL_DUNGEON, - dungeonData.getId()); - - // Battle pass trigger - if (dungeonData.getType().isCountsToBattlepass() && successfully) { - p.getBattlePassManager().triggerMission(WatcherTriggerType.TRIGGER_FINISH_DUNGEON); - } - }); - scene.getScriptManager().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)); - } - ended = true; - } - - public void restartDungeon() { - this.scene.setKilledMonsterCount(0); - this.rewardedPlayers.clear(); - Arrays.fill(finishedConditions, 0); - this.ended = false; - this.activeDungeonWayPoints.clear(); - } - - public void cleanUpScene() { - this.scene.setDungeonManager(null); - this.scene.setKilledMonsterCount(0); - } -} +package emu.grasscutter.game.dungeons; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.common.ItemParamData; +import emu.grasscutter.data.excels.dungeon.DungeonData; +import emu.grasscutter.data.excels.dungeon.DungeonPassConfigData; +import emu.grasscutter.game.activity.trialavatar.TrialAvatarActivityHandler; +import emu.grasscutter.game.dungeons.dungeon_results.BaseDungeonResult; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.game.props.ActivityType; +import emu.grasscutter.game.props.WatcherTriggerType; +import emu.grasscutter.game.quest.enums.LogicType; +import emu.grasscutter.game.quest.enums.QuestContent; +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.scripts.constants.EventType; +import emu.grasscutter.scripts.data.ScriptArgs; +import emu.grasscutter.server.packet.send.PacketDungeonWayPointNotify; +import emu.grasscutter.server.packet.send.PacketGadgetAutoPickDropInfoNotify; +import emu.grasscutter.utils.Position; +import emu.grasscutter.utils.Utils; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import javax.annotation.Nullable; +import lombok.Getter; +import lombok.NonNull; +import lombok.val; + +/** + * TODO handle time limits TODO handle respawn points TODO handle team wipes and respawns TODO check + * monster level and levelConfigMap + */ +public class DungeonManager { + + @Getter private final Scene scene; + @Getter private final DungeonData dungeonData; + @Getter private final DungeonPassConfigData passConfigData; + + @Getter private final int[] finishedConditions; + private final IntSet rewardedPlayers = new IntOpenHashSet(); + private final Set activeDungeonWayPoints = new HashSet<>(); + private boolean ended = false; + private int newestWayPoint = 0; + @Getter private int startSceneTime = 0; + + DungeonTrialTeam trialTeam = null; + + public DungeonManager(@NonNull Scene scene, @NonNull DungeonData dungeonData) { + this.scene = scene; + this.dungeonData = dungeonData; + this.passConfigData = GameData.getDungeonPassConfigDataMap().get(dungeonData.getPassCond()); + this.finishedConditions = new int[passConfigData.getConds().size()]; + this.scene.setDungeonManager(this); + } + + public void triggerEvent(DungeonPassConditionType conditionType, int... params) { + if (ended) { + return; + } + for (int i = 0; i < passConfigData.getConds().size(); i++) { + var cond = passConfigData.getConds().get(i); + if (conditionType == cond.getCondType()) { + if (getScene().getWorld().getServer().getDungeonSystem().triggerCondition(cond, params)) { + finishedConditions[i] = 1; + } + } + } + + if (isFinishedSuccessfully()) { + finishDungeon(); + } + } + + public boolean isFinishedSuccessfully() { + return LogicType.calculate(passConfigData.getLogicType(), finishedConditions); + } + + public int getLevelForMonster(int id) { + // TODO should use levelConfigMap? and how? + return dungeonData.getShowLevel(); + } + + public boolean activateRespawnPoint(int pointId) { + val respawnPoint = GameData.getScenePointEntryById(scene.getId(), pointId); + + if (respawnPoint == null) { + Grasscutter.getLogger().warn("trying to activate unknown respawn point {}", pointId); + return false; + } + + scene.broadcastPacket( + new PacketDungeonWayPointNotify( + activeDungeonWayPoints.add(pointId), activeDungeonWayPoints)); + newestWayPoint = pointId; + + Grasscutter.getLogger().debug("[unimplemented respawn] activated respawn point {}", pointId); + return true; + } + + @Nullable public Position getRespawnLocation() { + if (newestWayPoint == 0) { // validity is checked before setting it, so if != 0 its always valid + return null; + } + val pointData = GameData.getScenePointEntryById(scene.getId(), newestWayPoint).getPointData(); + return pointData.getTranPos() != null ? pointData.getTranPos() : pointData.getPos(); + } + + public Position getRespawnRotation() { + if (newestWayPoint == 0) { // validity is checked before setting it, so if != 0 its always valid + return null; + } + val pointData = GameData.getScenePointEntryById(scene.getId(), newestWayPoint).getPointData(); + return pointData.getRot() != null ? pointData.getRot() : null; + } + + public boolean getStatueDrops(Player player, boolean useCondensed, int groupId) { + if (!isFinishedSuccessfully() + || dungeonData.getRewardPreviewData() == null + || dungeonData.getRewardPreviewData().getPreviewItems().length == 0) { + return false; + } + + // Already rewarded + if (rewardedPlayers.contains(player.getUid())) { + return false; + } + + if (!handleCost(player, useCondensed)) { + return false; + } + + // Get and roll rewards. + List rewards = new ArrayList<>(this.rollRewards(useCondensed)); + // Add rewards to player and send notification. + player.getInventory().addItems(rewards, ActionReason.DungeonStatueDrop); + player.sendPacket(new PacketGadgetAutoPickDropInfoNotify(rewards)); + + rewardedPlayers.add(player.getUid()); + + scene.getScriptManager().callEvent(new ScriptArgs(groupId, EventType.EVENT_DUNGEON_REWARD_GET)); + return true; + } + + public boolean handleCost(Player player, boolean useCondensed) { + int resinCost = dungeonData.getStatueCostCount() != 0 ? dungeonData.getStatueCostCount() : 20; + if (resinCost == 0) { + return true; + } + if (useCondensed) { + // Check if condensed resin is usable here. + // For this, we use the following logic for now: + // The normal resin cost of the dungeon has to be 20. + if (resinCost != 20) { + return false; + } + + // Spend the condensed resin and only proceed if the transaction succeeds. + return player.getResinManager().useCondensedResin(1); + } else if (dungeonData.getStatueCostID() == 106) { + // Spend the resin and only proceed if the transaction succeeds. + return player.getResinManager().useResin(resinCost); + } + return true; + } + + private List rollRewards(boolean useCondensed) { + List rewards = new ArrayList<>(); + int dungeonId = this.dungeonData.getId(); + // If we have specific drop data for this dungeon, we use it. + if (GameData.getDungeonDropDataMap().containsKey(dungeonId)) { + List dropEntries = GameData.getDungeonDropDataMap().get(dungeonId); + + // Roll for each drop group. + for (var entry : dropEntries) { + // Determine the number of drops we get for this entry. + int start = entry.getCounts().get(0); + int end = entry.getCounts().get(entry.getCounts().size() - 1); + var candidateAmounts = IntStream.range(start, end + 1).boxed().collect(Collectors.toList()); + + int amount = Utils.drawRandomListElement(candidateAmounts, entry.getProbabilities()); + + if (useCondensed) { + amount += Utils.drawRandomListElement(candidateAmounts, entry.getProbabilities()); + } + + // Double rewards in multiplay mode, if specified. + if (entry.isMpDouble() && this.getScene().getPlayerCount() > 1) { + amount *= 2; + } + + // Roll items for this group. + // Here, we have to handle stacking, or the client will not display results correctly. + // For now, we use the following logic: If the possible drop item are a list of multiple + // items, + // we roll them separately. If not, we stack them. This should work out in practice, at + // least + // for the currently existing set of dungeons. + if (entry.getItems().size() == 1) { + rewards.add(new GameItem(entry.getItems().get(0), amount)); + } else { + for (int i = 0; i < amount; i++) { + // int itemIndex = ThreadLocalRandom.current().nextInt(0, entry.getItems().size()); + // int itemId = entry.getItems().get(itemIndex); + int itemId = + Utils.drawRandomListElement(entry.getItems(), entry.getItemProbabilities()); + rewards.add(new GameItem(itemId, 1)); + } + } + } + } + // Otherwise, we fall back to the preview data. + else { + Grasscutter.getLogger() + .info("No drop data found or dungeon {}, falling back to preview data ...", dungeonId); + for (ItemParamData param : dungeonData.getRewardPreviewData().getPreviewItems()) { + rewards.add(new GameItem(param.getId(), Math.max(param.getCount(), 1))); + } + } + + return rewards; + } + + public void applyTrialTeam(Player player) { + if (getDungeonData() == null) return; + + switch (getDungeonData().getType()) { + // case DUNGEON_PLOT is handled by quest execs + case DUNGEON_ACTIVITY -> { + switch (getDungeonData().getPlayType()) { + case DUNGEON_PLAY_TYPE_TRIAL_AVATAR -> { + val activityHandler = + player + .getActivityManager() + .getActivityHandlerAs( + ActivityType.NEW_ACTIVITY_TRIAL_AVATAR, TrialAvatarActivityHandler.class); + activityHandler.ifPresent( + trialAvatarActivityHandler -> + this.trialTeam = trialAvatarActivityHandler.getTrialAvatarDungeonTeam()); + } + } + } + case DUNGEON_ELEMENT_CHALLENGE -> {} // TODO + } + if (this.trialTeam != null) { + player.getTeamManager().addTrialAvatars(trialTeam.trialAvatarIds); + } + } + + public void unsetTrialTeam(Player player) { + if (this.trialTeam == null) { + return; + } + player.getTeamManager().removeTrialAvatar(); + this.trialTeam = null; + } + + public void startDungeon() { + this.startSceneTime = scene.getSceneTimeSeconds(); + scene + .getPlayers() + .forEach( + p -> { + p.getQuestManager() + .queueEvent(QuestContent.QUEST_CONTENT_ENTER_DUNGEON, dungeonData.getId()); + applyTrialTeam(p); + }); + } + + public void finishDungeon() { + notifyEndDungeon(true); + endDungeon(BaseDungeonResult.DungeonEndReason.COMPLETED); + } + + public void notifyEndDungeon(boolean successfully) { + scene + .getPlayers() + .forEach( + p -> { + // Quest trigger + p.getQuestManager() + .queueEvent( + successfully + ? QuestContent.QUEST_CONTENT_FINISH_DUNGEON + : QuestContent.QUEST_CONTENT_FAIL_DUNGEON, + dungeonData.getId()); + + // Battle pass trigger + if (dungeonData.getType().isCountsToBattlepass() && successfully) { + p.getBattlePassManager().triggerMission(WatcherTriggerType.TRIGGER_FINISH_DUNGEON); + } + }); + scene + .getScriptManager() + .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)); + } + ended = true; + } + + public void restartDungeon() { + this.scene.setKilledMonsterCount(0); + this.rewardedPlayers.clear(); + Arrays.fill(finishedConditions, 0); + this.ended = false; + this.activeDungeonWayPoints.clear(); + } + + public void cleanUpScene() { + this.scene.setDungeonManager(null); + this.scene.setKilledMonsterCount(0); + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonSettleListener.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonSettleListener.java index 2eb389e05..45f36a7b4 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonSettleListener.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonSettleListener.java @@ -1,7 +1,7 @@ -package emu.grasscutter.game.dungeons; - -import emu.grasscutter.game.world.Scene; - -public interface DungeonSettleListener { - void onDungeonSettle(Scene scene); -} +package emu.grasscutter.game.dungeons; + +import emu.grasscutter.game.world.Scene; + +public interface DungeonSettleListener { + void onDungeonSettle(Scene scene); +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java index 30cf583da..67963c90b 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java @@ -3,12 +3,8 @@ package emu.grasscutter.game.dungeons; import emu.grasscutter.GameConstants; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.binout.ScenePointEntry; -import emu.grasscutter.data.excels.DungeonData; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.SceneType; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.world.Scene; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.server.game.BaseGameSystem; @@ -18,7 +14,7 @@ import emu.grasscutter.server.packet.send.PacketPlayerEnterDungeonRsp; import emu.grasscutter.utils.Position; import java.util.List; -public class DungeonSystem extends BaseGameSystem { +public final class DungeonSystem extends BaseGameSystem { private static final BasicDungeonSettleListener basicDungeonSettleObserver = new BasicDungeonSettleListener(); @@ -27,7 +23,7 @@ public class DungeonSystem extends BaseGameSystem { } public void getEntryInfo(Player player, int pointId) { - ScenePointEntry entry = GameData.getScenePointEntryById(player.getScene().getId(), pointId); + var entry = GameData.getScenePointEntryById(player.getScene().getId(), pointId); if (entry == null) { // Error @@ -39,24 +35,24 @@ public class DungeonSystem extends BaseGameSystem { } public boolean enterDungeon(Player player, int pointId, int dungeonId) { - DungeonData data = GameData.getDungeonDataMap().get(dungeonId); - + var data = GameData.getDungeonDataMap().get(dungeonId); if (data == null) { return false; } + Grasscutter.getLogger() - .info( + .debug( "{}({}) is trying to enter dungeon {}", player.getNickname(), player.getUid(), dungeonId); - int sceneId = data.getSceneId(); + var sceneId = data.getSceneId(); player.getScene().setPrevScene(sceneId); if (player.getWorld().transferPlayerToScene(player, sceneId, data)) { player.getScene().addDungeonSettleObserver(basicDungeonSettleObserver); - player.getQuestManager().triggerEvent(QuestTrigger.QUEST_CONTENT_ENTER_DUNGEON, data.getId()); + player.getQuestManager().triggerEvent(QuestContent.QUEST_CONTENT_ENTER_DUNGEON, data.getId()); } player.getScene().setPrevScenePoint(pointId); @@ -67,13 +63,13 @@ public class DungeonSystem extends BaseGameSystem { /** used in tower dungeons handoff */ public boolean handoffDungeon( Player player, int dungeonId, List dungeonSettleListeners) { - DungeonData data = GameData.getDungeonDataMap().get(dungeonId); - + var data = GameData.getDungeonDataMap().get(dungeonId); if (data == null) { return false; } + Grasscutter.getLogger() - .info( + .debug( "{}({}) is trying to enter tower dungeon {}", player.getNickname(), player.getUid(), @@ -82,30 +78,32 @@ public class DungeonSystem extends BaseGameSystem { if (player.getWorld().transferPlayerToScene(player, data.getSceneId(), data)) { dungeonSettleListeners.forEach(player.getScene()::addDungeonSettleObserver); } + return true; } public void exitDungeon(Player player) { - Scene scene = player.getScene(); + var scene = player.getScene(); if (scene == null || scene.getSceneType() != SceneType.SCENE_DUNGEON) { return; } // Get previous scene - int prevScene = scene.getPrevScene() > 0 ? scene.getPrevScene() : 3; + var prevScene = scene.getPrevScene() > 0 ? scene.getPrevScene() : 3; // Get previous position - DungeonData dungeonData = scene.getDungeonData(); - Position prevPos = new Position(GameConstants.START_POSITION); + var dungeonData = scene.getDungeonData(); + var prevPos = new Position(GameConstants.START_POSITION); if (dungeonData != null) { - ScenePointEntry entry = GameData.getScenePointEntryById(prevScene, scene.getPrevScenePoint()); + var entry = GameData.getScenePointEntryById(prevScene, scene.getPrevScenePoint()); if (entry != null) { prevPos.set(entry.getPointData().getTranPos()); } } + // clean temp team if it has player.getTeamManager().cleanTemporaryTeam(); player.getTowerManager().clearEntry(); @@ -114,9 +112,4 @@ public class DungeonSystem extends BaseGameSystem { player.getWorld().transferPlayerToScene(player, prevScene, prevPos); player.sendPacket(new BasePacket(PacketOpcodes.PlayerQuitDungeonRsp)); } - - public void updateDailyDungeons() { - GameData.getScenePointEntries() - .forEach((id, entry) -> entry.getPointData().updateDailyDungeon()); - } } diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonTrialTeam.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonTrialTeam.java index 74f1bea47..58635e2a5 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonTrialTeam.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonTrialTeam.java @@ -1,14 +1,13 @@ -package emu.grasscutter.game.dungeons; - -import emu.grasscutter.net.proto.TrialAvatarGrantRecordOuterClass.TrialAvatarGrantRecord; -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.util.List; - -@Data -@AllArgsConstructor -public class DungeonTrialTeam { - List trialAvatarIds; - TrialAvatarGrantRecord.GrantReason grantReason; -} +package emu.grasscutter.game.dungeons; + +import emu.grasscutter.net.proto.TrialAvatarGrantRecordOuterClass.TrialAvatarGrantRecord; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class DungeonTrialTeam { + List trialAvatarIds; + TrialAvatarGrantRecord.GrantReason grantReason; +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonValue.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonValue.java index d9788cc41..9454117ad 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonValue.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonValue.java @@ -1,11 +1,10 @@ -package emu.grasscutter.game.dungeons; - -import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Retention(RetentionPolicy.RUNTIME) -public @interface DungeonValue { - DungeonPassConditionType value(); -} +package emu.grasscutter.game.dungeons; + +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface DungeonValue { + DungeonPassConditionType value(); +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/DungeonChallenge.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/DungeonChallenge.java index 8be5ca139..a9582a813 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/DungeonChallenge.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/DungeonChallenge.java @@ -1,213 +1,55 @@ -package emu.grasscutter.game.dungeons.challenge; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.DataLoader; -import emu.grasscutter.data.common.ItemParamData; -import emu.grasscutter.data.excels.DungeonData; -import emu.grasscutter.game.dungeons.DungeonDrop; -import emu.grasscutter.game.dungeons.DungeonDropEntry; -import emu.grasscutter.game.dungeons.challenge.trigger.ChallengeTrigger; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.game.props.WatcherTriggerType; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq; -import emu.grasscutter.net.proto.ResinCostTypeOuterClass; -import emu.grasscutter.scripts.constants.EventType; -import emu.grasscutter.scripts.data.SceneGroup; -import emu.grasscutter.scripts.data.ScriptArgs; -import emu.grasscutter.server.packet.send.PacketGadgetAutoPickDropInfoNotify; -import emu.grasscutter.utils.Utils; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.ints.IntOpenHashSet; -import it.unimi.dsi.fastutil.ints.IntSet; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -public class DungeonChallenge extends WorldChallenge { - - private static final Int2ObjectMap> dungeonDropData = - new Int2ObjectOpenHashMap<>(); - /** has more challenge */ - private boolean stage; - - private IntSet rewardedPlayers; - - public DungeonChallenge( - Scene scene, - SceneGroup group, - int challengeId, - int challengeIndex, - List paramList, - int timeLimit, - int goal, - List challengeTriggers) { - super(scene, group, challengeId, challengeIndex, paramList, timeLimit, goal, challengeTriggers); - this.setRewardedPlayers(new IntOpenHashSet()); - } - - public static void initialize() { - // Read the data we need for dungeon rewards drops. - try { - DataLoader.loadList("DungeonDrop.json", DungeonDrop.class) - .forEach( - entry -> { - dungeonDropData.put(entry.getDungeonId(), entry.getDrops()); - }); - Grasscutter.getLogger().debug("Loaded {} dungeon drop data entries.", dungeonDropData.size()); - } catch (Exception ex) { - Grasscutter.getLogger().error("Unable to load dungeon drop data.", ex); - } - } - - public boolean isStage() { - return stage; - } - - public void setStage(boolean stage) { - this.stage = stage; - } - - public IntSet getRewardedPlayers() { - return rewardedPlayers; - } - - public void setRewardedPlayers(IntSet rewardedPlayers) { - this.rewardedPlayers = rewardedPlayers; - } - - @Override - public void done() { - super.done(); - if (this.isSuccess()) { - // Settle - settle(); - } - } - - private void settle() { - if (!stage) { - var scene = this.getScene(); - scene.getDungeonSettleListeners().forEach(o -> o.onDungeonSettle(getScene())); - scene - .getScriptManager() - .callEvent(EventType.EVENT_DUNGEON_SETTLE, new ScriptArgs(this.isSuccess() ? 1 : 0)); - // Battle pass trigger - scene - .getPlayers() - .forEach( - p -> - p.getBattlePassManager() - .triggerMission(WatcherTriggerType.TRIGGER_FINISH_DUNGEON)); - } - } - - private List rollRewards(boolean useCondensed) { - List rewards = new ArrayList<>(); - int dungeonId = this.getScene().getDungeonData().getId(); - // If we have specific drop data for this dungeon, we use it. - if (dungeonDropData.containsKey(dungeonId)) { - List dropEntries = dungeonDropData.get(dungeonId); - - // Roll for each drop group. - for (var entry : dropEntries) { - // Determine the number of drops we get for this entry. - int start = entry.getCounts().get(0); - int end = entry.getCounts().get(entry.getCounts().size() - 1); - var candidateAmounts = IntStream.range(start, end + 1).boxed().collect(Collectors.toList()); - - int amount = Utils.drawRandomListElement(candidateAmounts, entry.getProbabilities()); - - if (useCondensed) { - amount += Utils.drawRandomListElement(candidateAmounts, entry.getProbabilities()); - } - - // Double rewards in multiplay mode, if specified. - if (entry.isMpDouble() && this.getScene().getPlayerCount() > 1) { - amount *= 2; - } - - // Roll items for this group. - // Here, we have to handle stacking, or the client will not display results correctly. - // For now, we use the following logic: If the possible drop item are a list of multiple - // items, - // we roll them separately. If not, we stack them. This should work out in practice, at - // least - // for the currently existing set of dungeons. - if (entry.getItems().size() == 1) { - rewards.add(new GameItem(entry.getItems().get(0), amount)); - } else { - for (int i = 0; i < amount; i++) { - // int itemIndex = ThreadLocalRandom.current().nextInt(0, entry.getItems().size()); - // int itemId = entry.getItems().get(itemIndex); - int itemId = - Utils.drawRandomListElement(entry.getItems(), entry.getItemProbabilities()); - rewards.add(new GameItem(itemId, 1)); - } - } - } - } - // Otherwise, we fall back to the preview data. - else { - Grasscutter.getLogger() - .info("No drop data found or dungeon {}, falling back to preview data ...", dungeonId); - for (ItemParamData param : getScene().getDungeonData().getRewardPreview().getPreviewItems()) { - rewards.add(new GameItem(param.getId(), Math.max(param.getCount(), 1))); - } - } - - return rewards; - } - - public void getStatueDrops(Player player, GadgetInteractReq request) { - DungeonData dungeonData = getScene().getDungeonData(); - int resinCost = dungeonData.getStatueCostCount() != 0 ? dungeonData.getStatueCostCount() : 20; - - if (!isSuccess() - || dungeonData == null - || dungeonData.getRewardPreview() == null - || dungeonData.getRewardPreview().getPreviewItems().length == 0) { - return; - } - - // Already rewarded - if (getRewardedPlayers().contains(player.getUid())) { - return; - } - - // Get rewards. - List rewards = new ArrayList<>(); - - if (request.getResinCostType() - == ResinCostTypeOuterClass.ResinCostType.RESIN_COST_TYPE_CONDENSE) { - // Check if condensed resin is usable here. - // For this, we use the following logic for now: - // The normal resin cost of the dungeon has to be 20. - if (resinCost != 20) { - return; - } - - // Spend the condensed resin and only proceed if the transaction succeeds. - if (!player.getResinManager().useCondensedResin(1)) return; - - // Roll rewards. - rewards.addAll(this.rollRewards(true)); - } else { - // Spend the resin and only proceed if the transaction succeeds. - if (!player.getResinManager().useResin(resinCost)) return; - - // Roll rewards. - rewards.addAll(this.rollRewards(false)); - } - - // Add rewards to player and send notification. - player.getInventory().addItems(rewards, ActionReason.DungeonStatueDrop); - player.sendPacket(new PacketGadgetAutoPickDropInfoNotify(rewards)); - - getRewardedPlayers().add(player.getUid()); - } -} +package emu.grasscutter.game.dungeons.challenge; + +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import emu.grasscutter.game.dungeons.challenge.trigger.ChallengeTrigger; +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.scripts.data.SceneGroup; + +import java.util.List; + +public final class DungeonChallenge extends WorldChallenge { + + /** + * has more challenge + */ + private boolean stage; + + public DungeonChallenge(Scene scene, SceneGroup group, + int challengeId, int challengeIndex, + List paramList, + int timeLimit, int goal, + List challengeTriggers) { + super(scene, group, challengeId, challengeIndex, paramList, timeLimit, goal, challengeTriggers); + } + + public boolean isStage() { + return stage; + } + + public void setStage(boolean stage) { + this.stage = stage; + } + + @Override + public void done() { + super.done(); + this.getScene().triggerDungeonEvent( + DungeonPassConditionType.DUNGEON_COND_FINISH_CHALLENGE, + this.getChallengeId(), this.getChallengeIndex()); + + if (this.isSuccess()) + this.settle(); + } + + private void settle() { + if (!stage) { + var scene = this.getScene(); + /*if(this.isSuccess()){ + scene.getDungeonManager().finishDungeon(); + } else { + scene.getDungeonManager().failDungeon(); + }*/ + } + } + +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeCondType.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeCondType.java index fa5c38adc..aa67ad9b8 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeCondType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeCondType.java @@ -1,19 +1,19 @@ -package emu.grasscutter.game.dungeons.challenge.enums; - -public enum ChallengeCondType { - CHALLENGE_COND_NONE, //00 - CHALLENGE_COND_IN_TIME, //01 - CHALLENGE_COND_ALL_TIME, //02 - CHALLENGE_COND_KILL_COUNT, //03 - CHALLENGE_COND_SURVIVE, //04 - CHALLENGE_COND_TIME_INC, //05 - CHALLENGE_COND_KILL_FAST, //06 - CHALLENGE_COND_DOWN_LESS, //07 - CHALLENGE_COND_BEATEN_LESS , //08 - CHALLENGE_COND_UNNATURAL_COUNT , //09 - CHALLENGE_COND_FROZEN_LESS , //10 - CHALLENGE_COND_KILL_MONSTER , //11 - CHALLENGE_COND_TRIGGER , //12 - CHALLENGE_COND_GUARD_HP , //13 - CHALLENGE_COND_TIME_DEC , //14 -} +package emu.grasscutter.game.dungeons.challenge.enums; + +public enum ChallengeCondType { + CHALLENGE_COND_NONE, // 00 + CHALLENGE_COND_IN_TIME, // 01 + CHALLENGE_COND_ALL_TIME, // 02 + CHALLENGE_COND_KILL_COUNT, // 03 + CHALLENGE_COND_SURVIVE, // 04 + CHALLENGE_COND_TIME_INC, // 05 + CHALLENGE_COND_KILL_FAST, // 06 + CHALLENGE_COND_DOWN_LESS, // 07 + CHALLENGE_COND_BEATEN_LESS, // 08 + CHALLENGE_COND_UNNATURAL_COUNT, // 09 + CHALLENGE_COND_FROZEN_LESS, // 10 + CHALLENGE_COND_KILL_MONSTER, // 11 + CHALLENGE_COND_TRIGGER, // 12 + CHALLENGE_COND_GUARD_HP, // 13 + CHALLENGE_COND_TIME_DEC, // 14 +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeEventMarkType.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeEventMarkType.java index 2674df680..b360c31d3 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeEventMarkType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeEventMarkType.java @@ -1,9 +1,9 @@ -package emu.grasscutter.game.dungeons.challenge.enums; - -public enum ChallengeEventMarkType { - CHALLENGE_EVENT_NONE, - FLIGHT_TIME, - FLIGHT_GATHER_POINT, - SUMMER_TIME_SPRINT_BOAT_TIME, - SUMMER_TIME_SPRINT_BOAT_GATHER_POINT, -} +package emu.grasscutter.game.dungeons.challenge.enums; + +public enum ChallengeEventMarkType { + CHALLENGE_EVENT_NONE, + FLIGHT_TIME, + FLIGHT_GATHER_POINT, + SUMMER_TIME_SPRINT_BOAT_TIME, + SUMMER_TIME_SPRINT_BOAT_GATHER_POINT, +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeRecordType.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeRecordType.java index c763903b1..c4208c0ba 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeRecordType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeRecordType.java @@ -1,6 +1,6 @@ -package emu.grasscutter.game.dungeons.challenge.enums; - -public enum ChallengeRecordType { - CHALLENGE_RECORD_TYPE_NONE, - CHALLENGE_RECORD_TYPE_IN_TIME -} +package emu.grasscutter.game.dungeons.challenge.enums; + +public enum ChallengeRecordType { + CHALLENGE_RECORD_TYPE_NONE, + CHALLENGE_RECORD_TYPE_IN_TIME +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeType.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeType.java index c59dbd240..abfdad515 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/ChallengeType.java @@ -1,27 +1,27 @@ -package emu.grasscutter.game.dungeons.challenge.enums; - -public enum ChallengeType { - CHALLENGE_NONE, //00 - CHALLENGE_KILL_COUNT, //01 - CHALLENGE_KILL_COUNT_IN_TIME, //02 - CHALLENGE_SURVIVE, //03 - CHALLENGE_TIME_FLY, //04 - CHALLENGE_KILL_COUNT_FAST, //05 - CHALLENGE_KILL_COUNT_FROZEN_LESS, //06 - CHALLENGE_KILL_MONSTER_IN_TIME, //07 - CHALLENGE_TRIGGER_IN_TIME, //08 - CHALLENGE_GUARD_HP, //09 - CHALLENGE_KILL_COUNT_GUARD_HP, //10 - CHALLENGE_TRIGGER_IN_TIME_FLY , //11 - //unknown if position and time match from here on - CHALLENGE_TRIGGER2_AVOID_TRIGGER1, - CHALLENGE_FATHER_SUCC_IN_TIME, - CHALLENGE_MONSTER_DAMAGE_COUNT, - CHALLENGE_ELEMENT_REACTION_COUNT, - CHALLENGE_FREEZE_ENEMY_IN_TIME, - CHALLENGE_CRYSTAL_ELEMENT_REACTION_COUNT, - CHALLENGE_SHEILD_ABSORB_DAMAGE_COUNT, - CHALLENGE_SWIRL_ELEMENT_REACTION_COUNT, - CHALLENGE_DIE_LESS_IN_TIME, - CHALLENGE_TRIGGER_COUNT, -} +package emu.grasscutter.game.dungeons.challenge.enums; + +public enum ChallengeType { + CHALLENGE_NONE, // 00 + CHALLENGE_KILL_COUNT, // 01 + CHALLENGE_KILL_COUNT_IN_TIME, // 02 + CHALLENGE_SURVIVE, // 03 + CHALLENGE_TIME_FLY, // 04 + CHALLENGE_KILL_COUNT_FAST, // 05 + CHALLENGE_KILL_COUNT_FROZEN_LESS, // 06 + CHALLENGE_KILL_MONSTER_IN_TIME, // 07 + CHALLENGE_TRIGGER_IN_TIME, // 08 + CHALLENGE_GUARD_HP, // 09 + CHALLENGE_KILL_COUNT_GUARD_HP, // 10 + CHALLENGE_TRIGGER_IN_TIME_FLY, // 11 + // unknown if position and time match from here on + CHALLENGE_TRIGGER2_AVOID_TRIGGER1, + CHALLENGE_FATHER_SUCC_IN_TIME, + CHALLENGE_MONSTER_DAMAGE_COUNT, + CHALLENGE_ELEMENT_REACTION_COUNT, + CHALLENGE_FREEZE_ENEMY_IN_TIME, + CHALLENGE_CRYSTAL_ELEMENT_REACTION_COUNT, + CHALLENGE_SHEILD_ABSORB_DAMAGE_COUNT, + CHALLENGE_SWIRL_ELEMENT_REACTION_COUNT, + CHALLENGE_DIE_LESS_IN_TIME, + CHALLENGE_TRIGGER_COUNT, +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/FatherChallengeProperty.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/FatherChallengeProperty.java index 8a4763831..b231bbb96 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/FatherChallengeProperty.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/enums/FatherChallengeProperty.java @@ -1,9 +1,9 @@ -package emu.grasscutter.game.dungeons.challenge.enums; - -public enum FatherChallengeProperty { - DURATION, - CUR_SUCC, - CUR_FAIL, - SUM_SUCC, - SUM_FAIL -} +package emu.grasscutter.game.dungeons.challenge.enums; + +public enum FatherChallengeProperty { + DURATION, + CUR_SUCC, + CUR_FAIL, + SUM_SUCC, + SUM_FAIL +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillAndGuardChallengeFactoryHandler.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillAndGuardChallengeFactoryHandler.java index 69857f42e..c311128ee 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillAndGuardChallengeFactoryHandler.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillAndGuardChallengeFactoryHandler.java @@ -1,34 +1,42 @@ -package emu.grasscutter.game.dungeons.challenge.factory; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; -import emu.grasscutter.game.dungeons.challenge.trigger.GuardTrigger; -import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterCountTrigger; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.scripts.data.SceneGroup; -import lombok.val; - -import java.util.List; - -import static emu.grasscutter.game.dungeons.challenge.enums.ChallengeType.CHALLENGE_KILL_COUNT_GUARD_HP; - -public class KillAndGuardChallengeFactoryHandler implements ChallengeFactoryHandler{ - @Override - public boolean isThisType(ChallengeType challengeType) { - // ActiveChallenge with 1,188,234101003,12,3030,0 - return challengeType == CHALLENGE_KILL_COUNT_GUARD_HP; - } - - @Override /*TODO check param4 == monstesToKill*/ - public WorldChallenge build(int challengeIndex, int challengeId, int groupId, int monstersToKill, int gadgetCFGId, int unused, Scene scene, SceneGroup group) { - val realGroup = scene.getScriptManager().getGroupById(groupId); - return new WorldChallenge( - scene, realGroup, - challengeId, // Id - challengeIndex, // Index - List.of(monstersToKill, 0), - 0, // Limit - monstersToKill, // Goal - List.of(new KillMonsterCountTrigger(), new GuardTrigger(gadgetCFGId))); - } -} +package emu.grasscutter.game.dungeons.challenge.factory; + +import static emu.grasscutter.game.dungeons.challenge.enums.ChallengeType.CHALLENGE_KILL_COUNT_GUARD_HP; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; +import emu.grasscutter.game.dungeons.challenge.trigger.GuardTrigger; +import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterCountTrigger; +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.scripts.data.SceneGroup; +import java.util.List; +import lombok.val; + +public class KillAndGuardChallengeFactoryHandler implements ChallengeFactoryHandler { + @Override + public boolean isThisType(ChallengeType challengeType) { + // ActiveChallenge with 1,188,234101003,12,3030,0 + return challengeType == CHALLENGE_KILL_COUNT_GUARD_HP; + } + + @Override /*TODO check param4 == monstesToKill*/ + public WorldChallenge build( + int challengeIndex, + int challengeId, + int groupId, + int monstersToKill, + int gadgetCFGId, + int unused, + Scene scene, + SceneGroup group) { + val realGroup = scene.getScriptManager().getGroupById(groupId); + return new WorldChallenge( + scene, + realGroup, + challengeId, // Id + challengeIndex, // Index + List.of(monstersToKill, 0), + 0, // Limit + monstersToKill, // Goal + List.of(new KillMonsterCountTrigger(), new GuardTrigger(gadgetCFGId))); + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterCountChallengeFactoryHandler.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterCountChallengeFactoryHandler.java index 0866a38d7..fc5ba5add 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterCountChallengeFactoryHandler.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterCountChallengeFactoryHandler.java @@ -1,32 +1,39 @@ -package emu.grasscutter.game.dungeons.challenge.factory; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; -import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterCountTrigger; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.scripts.data.SceneGroup; -import lombok.val; - -import java.util.List; - -public class KillMonsterCountChallengeFactoryHandler implements ChallengeFactoryHandler{ - @Override - public boolean isThisType(ChallengeType challengeType) { - // ActiveChallenge with 1, 1, 241033003, 15, 0, 0 - return challengeType == ChallengeType.CHALLENGE_KILL_COUNT; - } - - @Override - public WorldChallenge build(int challengeIndex, int challengeId, int groupId, int goal, int param5, int param6, Scene scene, SceneGroup group) { - val realGroup = scene.getScriptManager().getGroupById(groupId); - return new WorldChallenge( - scene, realGroup, - challengeId, // Id - challengeIndex, // Index - List.of(goal, groupId), - 0, // Limit - goal, // Goal - List.of(new KillMonsterCountTrigger()) - ); - } -} +package emu.grasscutter.game.dungeons.challenge.factory; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; +import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterCountTrigger; +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.scripts.data.SceneGroup; +import java.util.List; +import lombok.val; + +public class KillMonsterCountChallengeFactoryHandler implements ChallengeFactoryHandler { + @Override + public boolean isThisType(ChallengeType challengeType) { + // ActiveChallenge with 1, 1, 241033003, 15, 0, 0 + return challengeType == ChallengeType.CHALLENGE_KILL_COUNT; + } + + @Override + public WorldChallenge build( + int challengeIndex, + int challengeId, + int groupId, + int goal, + int param5, + int param6, + Scene scene, + SceneGroup group) { + val realGroup = scene.getScriptManager().getGroupById(groupId); + return new WorldChallenge( + scene, + realGroup, + challengeId, // Id + challengeIndex, // Index + List.of(goal, groupId), + 0, // Limit + goal, // Goal + List.of(new KillMonsterCountTrigger())); + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterInTimeChallengeFactoryHandler.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterInTimeChallengeFactoryHandler.java index 38b617ebb..36ebef1af 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterInTimeChallengeFactoryHandler.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterInTimeChallengeFactoryHandler.java @@ -1,33 +1,40 @@ -package emu.grasscutter.game.dungeons.challenge.factory; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; -import emu.grasscutter.game.dungeons.challenge.trigger.InTimeTrigger; -import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterTrigger; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.scripts.data.SceneGroup; -import lombok.val; - -import java.util.List; - -public class KillMonsterInTimeChallengeFactoryHandler implements ChallengeFactoryHandler{ - @Override - public boolean isThisType(ChallengeType challengeType) { - // ActiveChallenge with 180, 72, 240, 133220161, 133220161, 0 - return challengeType == ChallengeType.CHALLENGE_KILL_MONSTER_IN_TIME; - } - - @Override - public WorldChallenge build(int challengeIndex, int challengeId, int timeLimit, int groupId, int targetCfgId, int param6, Scene scene, SceneGroup group) { - val realGroup = scene.getScriptManager().getGroupById(groupId); - return new WorldChallenge( - scene, realGroup, - challengeId, // Id - challengeIndex, // Index - List.of(timeLimit), - timeLimit, // Limit - 0, // Goal - List.of(new KillMonsterTrigger(targetCfgId), new InTimeTrigger()) - ); - } -} +package emu.grasscutter.game.dungeons.challenge.factory; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; +import emu.grasscutter.game.dungeons.challenge.trigger.InTimeTrigger; +import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterTrigger; +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.scripts.data.SceneGroup; +import java.util.List; +import lombok.val; + +public class KillMonsterInTimeChallengeFactoryHandler implements ChallengeFactoryHandler { + @Override + public boolean isThisType(ChallengeType challengeType) { + // ActiveChallenge with 180, 72, 240, 133220161, 133220161, 0 + return challengeType == ChallengeType.CHALLENGE_KILL_MONSTER_IN_TIME; + } + + @Override + public WorldChallenge build( + int challengeIndex, + int challengeId, + int timeLimit, + int groupId, + int targetCfgId, + int param6, + Scene scene, + SceneGroup group) { + val realGroup = scene.getScriptManager().getGroupById(groupId); + return new WorldChallenge( + scene, + realGroup, + challengeId, // Id + challengeIndex, // Index + List.of(timeLimit), + timeLimit, // Limit + 0, // Goal + List.of(new KillMonsterTrigger(targetCfgId), new InTimeTrigger())); + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java index 8ca87518b..303a2d7bf 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java @@ -1,35 +1,42 @@ -package emu.grasscutter.game.dungeons.challenge.factory; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; -import emu.grasscutter.game.dungeons.challenge.trigger.InTimeTrigger; -import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterCountTrigger; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.scripts.data.SceneGroup; -import lombok.val; - -import java.util.List; - -public class KillMonsterTimeChallengeFactoryHandler implements ChallengeFactoryHandler{ - @Override - public boolean isThisType(ChallengeType challengeType) { - // ActiveChallenge with 180,180,45,133108061,1,0 - // ActiveChallenge Fast with 1001, 5, 15, 240004005, 10, 0 - return challengeType == ChallengeType.CHALLENGE_KILL_COUNT_IN_TIME || - challengeType == ChallengeType.CHALLENGE_KILL_COUNT_FAST; - } - - @Override - public WorldChallenge build(int challengeIndex, int challengeId, int timeLimit, int groupId, int targetCount, int param6, Scene scene, SceneGroup group) { - val realGroup = scene.getScriptManager().getGroupById(groupId); - return new WorldChallenge( - scene, realGroup, - challengeId, // Id - challengeIndex, // Index - List.of(targetCount, timeLimit), - timeLimit, // Limit - targetCount, // Goal - List.of(new KillMonsterCountTrigger(), new InTimeTrigger()) - ); - } -} +package emu.grasscutter.game.dungeons.challenge.factory; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; +import emu.grasscutter.game.dungeons.challenge.trigger.InTimeTrigger; +import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterCountTrigger; +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.scripts.data.SceneGroup; +import java.util.List; +import lombok.val; + +public class KillMonsterTimeChallengeFactoryHandler implements ChallengeFactoryHandler { + @Override + public boolean isThisType(ChallengeType challengeType) { + // ActiveChallenge with 180,180,45,133108061,1,0 + // ActiveChallenge Fast with 1001, 5, 15, 240004005, 10, 0 + return challengeType == ChallengeType.CHALLENGE_KILL_COUNT_IN_TIME + || challengeType == ChallengeType.CHALLENGE_KILL_COUNT_FAST; + } + + @Override + public WorldChallenge build( + int challengeIndex, + int challengeId, + int timeLimit, + int groupId, + int targetCount, + int param6, + Scene scene, + SceneGroup group) { + val realGroup = scene.getScriptManager().getGroupById(groupId); + return new WorldChallenge( + scene, + realGroup, + challengeId, // Id + challengeIndex, // Index + List.of(targetCount, timeLimit), + timeLimit, // Limit + targetCount, // Goal + List.of(new KillMonsterCountTrigger(), new InTimeTrigger())); + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/SurviveChallengeFactoryHandler.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/SurviveChallengeFactoryHandler.java index 5a1934ff5..9653f3ce9 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/SurviveChallengeFactoryHandler.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/SurviveChallengeFactoryHandler.java @@ -1,33 +1,40 @@ -package emu.grasscutter.game.dungeons.challenge.factory; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; -import emu.grasscutter.game.dungeons.challenge.trigger.ForTimeTrigger; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.scripts.data.SceneGroup; - -import java.util.List; - -import static emu.grasscutter.game.dungeons.challenge.enums.ChallengeType.CHALLENGE_SURVIVE; - -public class SurviveChallengeFactoryHandler implements ChallengeFactoryHandler { - @Override - public boolean isThisType(ChallengeType challengeType) { - // grp 201055005 - // ActiveChallenge with 100, 56, 60, 0, 0, 0 - return challengeType == CHALLENGE_SURVIVE; - } - - @Override - public WorldChallenge build(int challengeIndex, int challengeId, int timeToSurvive, int unused4, int unused5, int unused6, Scene scene, SceneGroup group) { - return new WorldChallenge( - scene, group, - challengeId, // Id - challengeIndex, // Index - List.of(timeToSurvive), - timeToSurvive, // Limit - 0, // Goal - List.of(new ForTimeTrigger()) - ); - } -} +package emu.grasscutter.game.dungeons.challenge.factory; + +import static emu.grasscutter.game.dungeons.challenge.enums.ChallengeType.CHALLENGE_SURVIVE; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; +import emu.grasscutter.game.dungeons.challenge.trigger.ForTimeTrigger; +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.scripts.data.SceneGroup; +import java.util.List; + +public class SurviveChallengeFactoryHandler implements ChallengeFactoryHandler { + @Override + public boolean isThisType(ChallengeType challengeType) { + // grp 201055005 + // ActiveChallenge with 100, 56, 60, 0, 0, 0 + return challengeType == CHALLENGE_SURVIVE; + } + + @Override + public WorldChallenge build( + int challengeIndex, + int challengeId, + int timeToSurvive, + int unused4, + int unused5, + int unused6, + Scene scene, + SceneGroup group) { + return new WorldChallenge( + scene, + group, + challengeId, // Id + challengeIndex, // Index + List.of(timeToSurvive), + timeToSurvive, // Limit + 0, // Goal + List.of(new ForTimeTrigger())); + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/TriggerInTimeChallengeFactoryHandler.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/TriggerInTimeChallengeFactoryHandler.java index 15aeccbec..79d2d0bce 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/TriggerInTimeChallengeFactoryHandler.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/TriggerInTimeChallengeFactoryHandler.java @@ -1,36 +1,43 @@ -package emu.grasscutter.game.dungeons.challenge.factory; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; -import emu.grasscutter.game.dungeons.challenge.trigger.InTimeTrigger; -import emu.grasscutter.game.dungeons.challenge.trigger.TriggerGroupTriggerTrigger; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.scripts.data.SceneGroup; - -import java.util.List; - -import static emu.grasscutter.game.dungeons.challenge.enums.ChallengeType.CHALLENGE_TRIGGER_IN_TIME; - -public class TriggerInTimeChallengeFactoryHandler implements ChallengeFactoryHandler { - @Override - public boolean isThisType(ChallengeType challengeType) { - // kill gadgets(explosive barrel) in time - // ActiveChallenge with 56,201,20,2,201,4 - // open chest in time - // ActiveChallenge with 666,202,30,7,202,1 - return challengeType == CHALLENGE_TRIGGER_IN_TIME; - } - - @Override - public WorldChallenge build(int challengeIndex, int challengeId, int timeLimit, int param4, int triggerTag, int triggerCount, Scene scene, SceneGroup group) { - return new WorldChallenge( - scene, group, - challengeId, // Id - challengeIndex, // Index - List.of(timeLimit, triggerCount), - timeLimit, // Limit - triggerCount, // Goal - List.of(new InTimeTrigger(), new TriggerGroupTriggerTrigger(Integer.toString(triggerTag))) - ); - } -} +package emu.grasscutter.game.dungeons.challenge.factory; + +import static emu.grasscutter.game.dungeons.challenge.enums.ChallengeType.CHALLENGE_TRIGGER_IN_TIME; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; +import emu.grasscutter.game.dungeons.challenge.trigger.InTimeTrigger; +import emu.grasscutter.game.dungeons.challenge.trigger.TriggerGroupTriggerTrigger; +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.scripts.data.SceneGroup; +import java.util.List; + +public class TriggerInTimeChallengeFactoryHandler implements ChallengeFactoryHandler { + @Override + public boolean isThisType(ChallengeType challengeType) { + // kill gadgets(explosive barrel) in time + // ActiveChallenge with 56,201,20,2,201,4 + // open chest in time + // ActiveChallenge with 666,202,30,7,202,1 + return challengeType == CHALLENGE_TRIGGER_IN_TIME; + } + + @Override + public WorldChallenge build( + int challengeIndex, + int challengeId, + int timeLimit, + int param4, + int triggerTag, + int triggerCount, + Scene scene, + SceneGroup group) { + return new WorldChallenge( + scene, + group, + challengeId, // Id + challengeIndex, // Index + List.of(timeLimit, triggerCount), + timeLimit, // Limit + triggerCount, // Goal + List.of(new InTimeTrigger(), new TriggerGroupTriggerTrigger(Integer.toString(triggerTag)))); + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/ForTimeTrigger.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/ForTimeTrigger.java index 6b272c34b..6a5c93741 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/ForTimeTrigger.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/ForTimeTrigger.java @@ -1,13 +1,13 @@ -package emu.grasscutter.game.dungeons.challenge.trigger; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; - -public class ForTimeTrigger extends ChallengeTrigger{ - @Override - public void onCheckTimeout(WorldChallenge challenge) { - var current = challenge.getScene().getSceneTimeSeconds(); - if(current - challenge.getStartedAt() > challenge.getTimeLimit()){ - challenge.done(); - } - } -} +package emu.grasscutter.game.dungeons.challenge.trigger; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; + +public class ForTimeTrigger extends ChallengeTrigger { + @Override + public void onCheckTimeout(WorldChallenge challenge) { + var current = challenge.getScene().getSceneTimeSeconds(); + if (current - challenge.getStartedAt() > challenge.getTimeLimit()) { + challenge.done(); + } + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/KillMonsterCountTrigger.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/KillMonsterCountTrigger.java index cc1b02cf0..ce7e7491e 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/KillMonsterCountTrigger.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/KillMonsterCountTrigger.java @@ -1,23 +1,24 @@ -package emu.grasscutter.game.dungeons.challenge.trigger; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.game.entity.EntityMonster; -import emu.grasscutter.server.packet.send.PacketChallengeDataNotify; - -public class KillMonsterCountTrigger extends ChallengeTrigger{ - @Override - public void onBegin(WorldChallenge challenge) { - challenge.getScene().broadcastPacket(new PacketChallengeDataNotify(challenge, 1, challenge.getScore().get())); - } - - @Override - public void onMonsterDeath(WorldChallenge challenge, EntityMonster monster) { - var newScore = challenge.increaseScore(); - challenge.getScene().broadcastPacket(new PacketChallengeDataNotify(challenge, 1, newScore)); - - if(newScore >= challenge.getGoal()){ - challenge.done(); - } - - } -} +package emu.grasscutter.game.dungeons.challenge.trigger; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.game.entity.EntityMonster; +import emu.grasscutter.server.packet.send.PacketChallengeDataNotify; + +public class KillMonsterCountTrigger extends ChallengeTrigger { + @Override + public void onBegin(WorldChallenge challenge) { + challenge + .getScene() + .broadcastPacket(new PacketChallengeDataNotify(challenge, 1, challenge.getScore().get())); + } + + @Override + public void onMonsterDeath(WorldChallenge challenge, EntityMonster monster) { + var newScore = challenge.increaseScore(); + challenge.getScene().broadcastPacket(new PacketChallengeDataNotify(challenge, 1, newScore)); + + if (newScore >= challenge.getGoal()) { + challenge.done(); + } + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/TriggerGroupTriggerTrigger.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/TriggerGroupTriggerTrigger.java index 82aae8140..987762329 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/TriggerGroupTriggerTrigger.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/TriggerGroupTriggerTrigger.java @@ -1,30 +1,31 @@ -package emu.grasscutter.game.dungeons.challenge.trigger; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.game.entity.EntityGadget; -import emu.grasscutter.scripts.data.SceneTrigger; -import emu.grasscutter.server.packet.send.PacketChallengeDataNotify; -import lombok.AllArgsConstructor; - -@AllArgsConstructor -public class TriggerGroupTriggerTrigger extends ChallengeTrigger{ - String triggerTag; - - @Override - public void onBegin(WorldChallenge challenge) { - challenge.getScene().broadcastPacket(new PacketChallengeDataNotify(challenge, 2, challenge.getScore().get())); - } - - @Override - public void onGroupTrigger(WorldChallenge challenge, SceneTrigger trigger) { - if(!triggerTag.equals(trigger.getTag())) { - return; - } - - var newScore = challenge.increaseScore(); - challenge.getScene().broadcastPacket(new PacketChallengeDataNotify(challenge, 2, newScore)); - if(newScore >= challenge.getGoal()){ - challenge.done(); - } - } -} +package emu.grasscutter.game.dungeons.challenge.trigger; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.scripts.data.SceneTrigger; +import emu.grasscutter.server.packet.send.PacketChallengeDataNotify; +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public class TriggerGroupTriggerTrigger extends ChallengeTrigger { + String triggerTag; + + @Override + public void onBegin(WorldChallenge challenge) { + challenge + .getScene() + .broadcastPacket(new PacketChallengeDataNotify(challenge, 2, challenge.getScore().get())); + } + + @Override + public void onGroupTrigger(WorldChallenge challenge, SceneTrigger trigger) { + if (!triggerTag.equals(trigger.getTag())) { + return; + } + + var newScore = challenge.increaseScore(); + challenge.getScene().broadcastPacket(new PacketChallengeDataNotify(challenge, 2, newScore)); + if (newScore >= challenge.getGoal()) { + challenge.done(); + } + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/BaseDungeonResult.java b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/BaseDungeonResult.java index 9cf616159..18c4f46ec 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/BaseDungeonResult.java +++ b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/BaseDungeonResult.java @@ -1,74 +1,77 @@ -package emu.grasscutter.game.dungeons.dungeon_results; - -import emu.grasscutter.data.excels.DungeonData; -import emu.grasscutter.game.dungeons.DungeonEndStats; -import emu.grasscutter.net.proto.DungeonSettleNotifyOuterClass.DungeonSettleNotify; -import emu.grasscutter.net.proto.ParamListOuterClass; -import emu.grasscutter.utils.Utils; -import lombok.Getter; - -public class BaseDungeonResult { - @Getter DungeonData dungeonData; - @Getter - DungeonEndStats dungeonStats; - - public BaseDungeonResult(DungeonData dungeonData, DungeonEndStats dungeonStats){ - this.dungeonData = dungeonData; - this.dungeonStats = dungeonStats; - } - - protected void onProto(DungeonSettleNotify.Builder builder){ } - - public final DungeonSettleNotify.Builder getProto(){ - var success = dungeonStats.getDungeonResult().isSuccess(); - var builder = DungeonSettleNotify.newBuilder() - .setDungeonId(dungeonData.getId()) - .setIsSuccess(success) - .setCloseTime(getCloseTime()) - .setResult(success ? 1 : 0); - - // TODO check - if(dungeonData.getSettleShows()!=null) { - for (int i = 0; i < dungeonData.getSettleShows().size(); i++) { - var settle = dungeonData.getSettleShows().get(i); - builder.putSettleShow(i + 1,switch (settle) { - case SETTLE_SHOW_TIME_COST -> ParamListOuterClass.ParamList.newBuilder() - .addParamList(settle.getId()) - .addParamList(dungeonStats.getTimeTaken()) - .build(); - case SETTLE_SHOW_KILL_MONSTER_COUNT -> ParamListOuterClass.ParamList.newBuilder() - .addParamList(settle.getId()) - .addParamList(dungeonStats.getKilledMonsters()) - .build(); - default -> ParamListOuterClass.ParamList.newBuilder() - .addParamList(settle.getId()) - .build(); - }); - } - } - - //TODO handle settle show - - onProto(builder); - - return builder; - } - - public int getCloseTime(){ - return Utils.getCurrentSeconds() + switch (dungeonStats.getDungeonResult()){ - case COMPLETED -> dungeonData.getSettleCountdownTime(); - case FAILED -> dungeonData.getFailSettleCountdownTime(); - case QUIT -> dungeonData.getQuitSettleCountdownTime(); - }; - } - - public enum DungeonEndReason{ - COMPLETED, - FAILED, - QUIT; - - public boolean isSuccess(){ - return this == COMPLETED; - } - } -} +package emu.grasscutter.game.dungeons.dungeon_results; + +import emu.grasscutter.data.excels.dungeon.DungeonData; +import emu.grasscutter.game.dungeons.DungeonEndStats; +import emu.grasscutter.net.proto.DungeonSettleNotifyOuterClass.DungeonSettleNotify; +import emu.grasscutter.net.proto.ParamListOuterClass; +import emu.grasscutter.utils.Utils; +import lombok.Getter; + +public class BaseDungeonResult { + @Getter DungeonData dungeonData; + @Getter DungeonEndStats dungeonStats; + + public BaseDungeonResult(DungeonData dungeonData, DungeonEndStats dungeonStats) { + this.dungeonData = dungeonData; + this.dungeonStats = dungeonStats; + } + + protected void onProto(DungeonSettleNotify.Builder builder) {} + + public final DungeonSettleNotify.Builder getProto() { + var success = dungeonStats.getDungeonResult().isSuccess(); + var builder = + DungeonSettleNotify.newBuilder() + .setDungeonId(dungeonData.getId()) + .setIsSuccess(success) + .setCloseTime(getCloseTime()) + .setResult(success ? 1 : 0); + + // TODO check + if (dungeonData.getSettleShows() != null) { + for (int i = 0; i < dungeonData.getSettleShows().size(); i++) { + var settle = dungeonData.getSettleShows().get(i); + builder.putSettleShow( + i + 1, + switch (settle) { + case SETTLE_SHOW_TIME_COST -> ParamListOuterClass.ParamList.newBuilder() + .addParamList(settle.getId()) + .addParamList(dungeonStats.getTimeTaken()) + .build(); + case SETTLE_SHOW_KILL_MONSTER_COUNT -> ParamListOuterClass.ParamList.newBuilder() + .addParamList(settle.getId()) + .addParamList(dungeonStats.getKilledMonsters()) + .build(); + default -> ParamListOuterClass.ParamList.newBuilder() + .addParamList(settle.getId()) + .build(); + }); + } + } + + // TODO handle settle show + + onProto(builder); + + return builder; + } + + public int getCloseTime() { + return Utils.getCurrentSeconds() + + switch (dungeonStats.getDungeonResult()) { + case COMPLETED -> dungeonData.getSettleCountdownTime(); + case FAILED -> dungeonData.getFailSettleCountdownTime(); + case QUIT -> dungeonData.getQuitSettleCountdownTime(); + }; + } + + public enum DungeonEndReason { + COMPLETED, + FAILED, + QUIT; + + public boolean isSuccess() { + return this == COMPLETED; + } + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TowerResult.java b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TowerResult.java index 46543a9bd..8e2b3a413 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TowerResult.java +++ b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TowerResult.java @@ -1,50 +1,54 @@ -package emu.grasscutter.game.dungeons.dungeon_results; - -import emu.grasscutter.data.excels.DungeonData; -import emu.grasscutter.game.dungeons.DungeonEndStats; -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.game.tower.TowerManager; -import emu.grasscutter.net.proto.DungeonSettleExhibitionInfoOuterClass; -import emu.grasscutter.net.proto.DungeonSettleNotifyOuterClass; -import emu.grasscutter.net.proto.ItemParamOuterClass; -import emu.grasscutter.net.proto.TowerLevelEndNotifyOuterClass.TowerLevelEndNotify.ContinueStateType; -import emu.grasscutter.net.proto.TowerLevelEndNotifyOuterClass.TowerLevelEndNotify; - -public class TowerResult extends BaseDungeonResult{ - WorldChallenge challenge; - boolean canJump; - boolean hasNextLevel; - int nextFloorId; - public TowerResult(DungeonData dungeonData, DungeonEndStats dungeonStats, TowerManager towerManager, WorldChallenge challenge) { - super(dungeonData, dungeonStats); - this.challenge = challenge; - this.canJump = towerManager.hasNextFloor(); - this.hasNextLevel = towerManager.hasNextLevel(); - this.nextFloorId = hasNextLevel ? 0 : towerManager.getNextFloorId(); - } - - @Override - protected void onProto(DungeonSettleNotifyOuterClass.DungeonSettleNotify.Builder builder) { - var continueStatus = ContinueStateType.CONTINUE_STATE_TYPE_CAN_NOT_CONTINUE_VALUE; - if(challenge.isSuccess() && canJump){ - continueStatus = hasNextLevel ? ContinueStateType.CONTINUE_STATE_TYPE_CAN_ENTER_NEXT_LEVEL_VALUE - : ContinueStateType.CONTINUE_STATE_TYPE_CAN_ENTER_NEXT_FLOOR_VALUE; - } - - var towerLevelEndNotify = TowerLevelEndNotify.newBuilder() - .setIsSuccess(challenge.isSuccess()) - .setContinueState(continueStatus) - .addFinishedStarCondList(1) - .addFinishedStarCondList(2) - .addFinishedStarCondList(3) - .addRewardItemList(ItemParamOuterClass.ItemParam.newBuilder() - .setItemId(201) - .setCount(1000) - .build()) - ; - if(nextFloorId > 0 && canJump){ - towerLevelEndNotify.setNextFloorId(nextFloorId); - } - builder.setTowerLevelEndNotify(towerLevelEndNotify); - } -} +package emu.grasscutter.game.dungeons.dungeon_results; + +import emu.grasscutter.data.excels.dungeon.DungeonData; +import emu.grasscutter.game.dungeons.DungeonEndStats; +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.game.tower.TowerManager; +import emu.grasscutter.net.proto.DungeonSettleNotifyOuterClass; +import emu.grasscutter.net.proto.ItemParamOuterClass; +import emu.grasscutter.net.proto.TowerLevelEndNotifyOuterClass.TowerLevelEndNotify; +import emu.grasscutter.net.proto.TowerLevelEndNotifyOuterClass.TowerLevelEndNotify.ContinueStateType; + +public class TowerResult extends BaseDungeonResult { + WorldChallenge challenge; + boolean canJump; + boolean hasNextLevel; + int nextFloorId; + + public TowerResult( + DungeonData dungeonData, + DungeonEndStats dungeonStats, + TowerManager towerManager, + WorldChallenge challenge) { + super(dungeonData, dungeonStats); + this.challenge = challenge; + this.canJump = towerManager.hasNextFloor(); + this.hasNextLevel = towerManager.hasNextLevel(); + this.nextFloorId = hasNextLevel ? 0 : towerManager.getNextFloorId(); + } + + @Override + protected void onProto(DungeonSettleNotifyOuterClass.DungeonSettleNotify.Builder builder) { + var continueStatus = ContinueStateType.CONTINUE_STATE_TYPE_CAN_NOT_CONTINUE_VALUE; + if (challenge.isSuccess() && canJump) { + continueStatus = + hasNextLevel + ? ContinueStateType.CONTINUE_STATE_TYPE_CAN_ENTER_NEXT_LEVEL_VALUE + : ContinueStateType.CONTINUE_STATE_TYPE_CAN_ENTER_NEXT_FLOOR_VALUE; + } + + var towerLevelEndNotify = + TowerLevelEndNotify.newBuilder() + .setIsSuccess(challenge.isSuccess()) + .setContinueState(continueStatus) + .addFinishedStarCondList(1) + .addFinishedStarCondList(2) + .addFinishedStarCondList(3) + .addRewardItemList( + ItemParamOuterClass.ItemParam.newBuilder().setItemId(201).setCount(1000).build()); + if (nextFloorId > 0 && canJump) { + towerLevelEndNotify.setNextFloorId(nextFloorId); + } + builder.setTowerLevelEndNotify(towerLevelEndNotify); + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TrialAvatarDungeonResult.java b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TrialAvatarDungeonResult.java index 298925a8f..389eac3e4 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TrialAvatarDungeonResult.java +++ b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TrialAvatarDungeonResult.java @@ -1,23 +1,26 @@ -package emu.grasscutter.game.dungeons.dungeon_results; - -import emu.grasscutter.data.excels.DungeonData; -import emu.grasscutter.game.dungeons.DungeonEndStats; -import emu.grasscutter.net.proto.DungeonSettleNotifyOuterClass; -import emu.grasscutter.net.proto.TrialAvatarFirstPassDungeonNotifyOuterClass.TrialAvatarFirstPassDungeonNotify; - -public class TrialAvatarDungeonResult extends BaseDungeonResult { - int trialCharacterIndexId; - - public TrialAvatarDungeonResult(DungeonData dungeonData, DungeonEndStats dungeonStats, int trialCharacterIndexId) { - super(dungeonData, dungeonStats); - this.trialCharacterIndexId = trialCharacterIndexId; - } - - @Override - protected void onProto(DungeonSettleNotifyOuterClass.DungeonSettleNotify.Builder builder) { - if (dungeonStats.getDungeonResult() == DungeonEndReason.COMPLETED) { //TODO check if its the first pass(?) - builder.setTrialAvatarFirstPassDungeonNotify(TrialAvatarFirstPassDungeonNotify.newBuilder() - .setTrialAvatarIndexId(trialCharacterIndexId)); - } - } -} +package emu.grasscutter.game.dungeons.dungeon_results; + +import emu.grasscutter.data.excels.dungeon.DungeonData; +import emu.grasscutter.game.dungeons.DungeonEndStats; +import emu.grasscutter.net.proto.DungeonSettleNotifyOuterClass; +import emu.grasscutter.net.proto.TrialAvatarFirstPassDungeonNotifyOuterClass.TrialAvatarFirstPassDungeonNotify; + +public class TrialAvatarDungeonResult extends BaseDungeonResult { + int trialCharacterIndexId; + + public TrialAvatarDungeonResult( + DungeonData dungeonData, DungeonEndStats dungeonStats, int trialCharacterIndexId) { + super(dungeonData, dungeonStats); + this.trialCharacterIndexId = trialCharacterIndexId; + } + + @Override + protected void onProto(DungeonSettleNotifyOuterClass.DungeonSettleNotify.Builder builder) { + if (dungeonStats.getDungeonResult() + == DungeonEndReason.COMPLETED) { // TODO check if its the first pass(?) + builder.setTrialAvatarFirstPassDungeonNotify( + TrialAvatarFirstPassDungeonNotify.newBuilder() + .setTrialAvatarIndexId(trialCharacterIndexId)); + } + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonEntrySatisfiedConditionType.java b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonEntrySatisfiedConditionType.java index fce7da285..27e875e28 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonEntrySatisfiedConditionType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonEntrySatisfiedConditionType.java @@ -1,7 +1,7 @@ -package emu.grasscutter.game.dungeons.enums; - -public enum DungeonEntrySatisfiedConditionType { - DUNGEON_ENTRY_CONDITION_NONE, - DUNGEON_ENTRY_CONDITION_LEVEL, - DUNGEON_ENTRY_CONDITION_QUEST -} +package emu.grasscutter.game.dungeons.enums; + +public enum DungeonEntrySatisfiedConditionType { + DUNGEON_ENTRY_CONDITION_NONE, + DUNGEON_ENTRY_CONDITION_LEVEL, + DUNGEON_ENTRY_CONDITION_QUEST +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonInvolveType.java b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonInvolveType.java index 2e32e3496..5aca76345 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonInvolveType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonInvolveType.java @@ -1,7 +1,7 @@ -package emu.grasscutter.game.dungeons.enums; - -public enum DungeonInvolveType { - INVOLVE_NONE, - INVOLVE_ONLY_SINGLE, - INVOLVE_SINGLE_MULTIPLE -} +package emu.grasscutter.game.dungeons.enums; + +public enum DungeonInvolveType { + INVOLVE_NONE, + INVOLVE_ONLY_SINGLE, + INVOLVE_SINGLE_MULTIPLE +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPassConditionType.java b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPassConditionType.java index 33bac9fd3..1b9ab7b32 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPassConditionType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPassConditionType.java @@ -1,27 +1,28 @@ -package emu.grasscutter.game.dungeons.enums; - -import emu.grasscutter.scripts.constants.IntValueEnum; -import lombok.Getter; - -public enum DungeonPassConditionType implements IntValueEnum { - DUNGEON_COND_NONE(0), - DUNGEON_COND_KILL_MONSTER(3), - DUNGEON_COND_KILL_GROUP_MONSTER(5), - DUNGEON_COND_KILL_TYPE_MONSTER(7), - DUNGEON_COND_FINISH_QUEST(9), - DUNGEON_COND_KILL_MONSTER_COUNT(11), // TODO handle count - DUNGEON_COND_IN_TIME(13), // Missing triggers and tracking - DUNGEON_COND_FINISH_CHALLENGE(14), - DUNGEON_COND_END_MULTISTAGE_PLAY(15) // Missing - ; - - @Getter private final int id; - DungeonPassConditionType(int id){ - this.id = id; - } - - @Override - public int getValue() { - return id; - } -} +package emu.grasscutter.game.dungeons.enums; + +import emu.grasscutter.scripts.constants.IntValueEnum; +import lombok.Getter; + +public enum DungeonPassConditionType implements IntValueEnum { + DUNGEON_COND_NONE(0), + DUNGEON_COND_KILL_MONSTER(3), + DUNGEON_COND_KILL_GROUP_MONSTER(5), + DUNGEON_COND_KILL_TYPE_MONSTER(7), + DUNGEON_COND_FINISH_QUEST(9), + DUNGEON_COND_KILL_MONSTER_COUNT(11), // TODO handle count + DUNGEON_COND_IN_TIME(13), // Missing triggers and tracking + DUNGEON_COND_FINISH_CHALLENGE(14), + DUNGEON_COND_END_MULTISTAGE_PLAY(15) // Missing +; + + @Getter private final int id; + + DungeonPassConditionType(int id) { + this.id = id; + } + + @Override + public int getValue() { + return id; + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPlayType.java b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPlayType.java index e2d287894..22736b8b6 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPlayType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPlayType.java @@ -1,7 +1,8 @@ -package emu.grasscutter.game.dungeons.enums; -public enum DungeonPlayType { - DUNGEON_PLAY_TYPE_NONE, - DUNGEON_PLAY_TYPE_FOGGY_MAZE, - DUNGEON_PLAY_TYPE_MIST_TRIAL, - DUNGEON_PLAY_TYPE_TRIAL_AVATAR -} +package emu.grasscutter.game.dungeons.enums; + +public enum DungeonPlayType { + DUNGEON_PLAY_TYPE_NONE, + DUNGEON_PLAY_TYPE_FOGGY_MAZE, + DUNGEON_PLAY_TYPE_MIST_TRIAL, + DUNGEON_PLAY_TYPE_TRIAL_AVATAR +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonSubType.java b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonSubType.java index 111b9e2f3..eaa304e36 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonSubType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonSubType.java @@ -1,9 +1,9 @@ -package emu.grasscutter.game.dungeons.enums; - -public enum DungeonSubType { - DUNGEON_SUB_NONE, - DUNGEON_SUB_BOSS, - DUNGEON_SUB_TALENT, - DUNGEON_SUB_WEAPON, - DUNGEON_SUB_RELIQUARY -} +package emu.grasscutter.game.dungeons.enums; + +public enum DungeonSubType { + DUNGEON_SUB_NONE, + DUNGEON_SUB_BOSS, + DUNGEON_SUB_TALENT, + DUNGEON_SUB_WEAPON, + DUNGEON_SUB_RELIQUARY +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonType.java b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonType.java index 0864c2dce..451a3996e 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonType.java @@ -1,49 +1,49 @@ -package emu.grasscutter.game.dungeons.enums; - -import lombok.Getter; - -public enum DungeonType { - DUNGEON_NONE(false), - DUNGEON_PLOT(true), - DUNGEON_FIGHT(true), - DUNGEON_DAILY_FIGHT(false), - DUNGEON_WEEKLY_FIGHT(true), - DUNGEON_DISCARDED(false), - DUNGEON_TOWER(false), - DUNGEON_BOSS(true), - DUNGEON_ACTIVITY(false), - DUNGEON_EFFIGY(false), - DUNGEON_ELEMENT_CHALLENGE(true), - DUNGEON_THEATRE_MECHANICUS(false), - DUNGEON_FLEUR_FAIR(false), - DUNGEON_CHANNELLER_SLAB_LOOP(false), - DUNGEON_CHANNELLER_SLAB_ONE_OFF(false), - DUNGEON_BLITZ_RUSH(true), - DUNGEON_CHESS(false), - DUNGEON_SUMO_COMBAT(false), - DUNGEON_ROGUELIKE(false), - DUNGEON_HACHI(false), - DUNGEON_POTION(false), - DUNGEON_MINI_ELDRITCH(false), - DUNGEON_UGC(false), - DUNGEON_GCG(false), - DUNGEON_CRYSTAL_LINK(false), - DUNGEON_IRODORI_CHESS(false), - DUNGEON_ROGUE_DIARY(false), - DUNGEON_DREAMLAND(false), - DUNGEON_SUMMER_V2(true), - DUNGEON_MUQADAS_POTION(false), - DUNGEON_INSTABLE_SPRAY(false), - DUNGEON_WIND_FIELD(false), - DUNGEON_BIGWORLD_MIRROR(false), - DUNGEON_FUNGUS_FIGHTER_TRAINING(false), - DUNGEON_FUNGUS_FIGHTER_PLOT(false), - DUNGEON_EFFIGY_CHALLENGE_V2(false), - DUNGEON_CHAR_AMUSEMENT(false); - - @Getter private final boolean countsToBattlepass; - - DungeonType(boolean countsToBattlepass){ - this.countsToBattlepass = countsToBattlepass; - } -} +package emu.grasscutter.game.dungeons.enums; + +import lombok.Getter; + +public enum DungeonType { + DUNGEON_NONE(false), + DUNGEON_PLOT(true), + DUNGEON_FIGHT(true), + DUNGEON_DAILY_FIGHT(false), + DUNGEON_WEEKLY_FIGHT(true), + DUNGEON_DISCARDED(false), + DUNGEON_TOWER(false), + DUNGEON_BOSS(true), + DUNGEON_ACTIVITY(false), + DUNGEON_EFFIGY(false), + DUNGEON_ELEMENT_CHALLENGE(true), + DUNGEON_THEATRE_MECHANICUS(false), + DUNGEON_FLEUR_FAIR(false), + DUNGEON_CHANNELLER_SLAB_LOOP(false), + DUNGEON_CHANNELLER_SLAB_ONE_OFF(false), + DUNGEON_BLITZ_RUSH(true), + DUNGEON_CHESS(false), + DUNGEON_SUMO_COMBAT(false), + DUNGEON_ROGUELIKE(false), + DUNGEON_HACHI(false), + DUNGEON_POTION(false), + DUNGEON_MINI_ELDRITCH(false), + DUNGEON_UGC(false), + DUNGEON_GCG(false), + DUNGEON_CRYSTAL_LINK(false), + DUNGEON_IRODORI_CHESS(false), + DUNGEON_ROGUE_DIARY(false), + DUNGEON_DREAMLAND(false), + DUNGEON_SUMMER_V2(true), + DUNGEON_MUQADAS_POTION(false), + DUNGEON_INSTABLE_SPRAY(false), + DUNGEON_WIND_FIELD(false), + DUNGEON_BIGWORLD_MIRROR(false), + DUNGEON_FUNGUS_FIGHTER_TRAINING(false), + DUNGEON_FUNGUS_FIGHTER_PLOT(false), + DUNGEON_EFFIGY_CHALLENGE_V2(false), + DUNGEON_CHAR_AMUSEMENT(false); + + @Getter private final boolean countsToBattlepass; + + DungeonType(boolean countsToBattlepass) { + this.countsToBattlepass = countsToBattlepass; + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/enums/DungunEntryType.java b/src/main/java/emu/grasscutter/game/dungeons/enums/DungunEntryType.java index 5b7295c58..4e9e656c6 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/enums/DungunEntryType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/enums/DungunEntryType.java @@ -1,12 +1,12 @@ -package emu.grasscutter.game.dungeons.enums; - -public enum DungunEntryType { - DUNGEN_ENTRY_TYPE_NONE , - DUNGEN_ENTRY_TYPE_AVATAR_EXP , - DUNGEN_ENTRY_TYPE_WEAPON_PROMOTE, - DUNGEN_ENTRY_TYPE_AVATAR_TALENT , - DUNGEN_ENTRY_TYPE_RELIQUARY , - DUNGEN_ENTRY_TYPE_SCOIN , - DUNGEON_ENTRY_TYPE_OBSCURAE , - DUNGEON_ENTRY_TYPE_NORMAL -} +package emu.grasscutter.game.dungeons.enums; + +public enum DungunEntryType { + DUNGEN_ENTRY_TYPE_NONE, + DUNGEN_ENTRY_TYPE_AVATAR_EXP, + DUNGEN_ENTRY_TYPE_WEAPON_PROMOTE, + DUNGEN_ENTRY_TYPE_AVATAR_TALENT, + DUNGEN_ENTRY_TYPE_RELIQUARY, + DUNGEN_ENTRY_TYPE_SCOIN, + DUNGEON_ENTRY_TYPE_OBSCURAE, + DUNGEON_ENTRY_TYPE_NORMAL +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/enums/SettleShowType.java b/src/main/java/emu/grasscutter/game/dungeons/enums/SettleShowType.java index 3d5af54a8..7a238c786 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/enums/SettleShowType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/enums/SettleShowType.java @@ -1,17 +1,17 @@ -package emu.grasscutter.game.dungeons.enums; - -import lombok.Getter; - -public enum SettleShowType { - SETTLE_SHOW_NONE(0), - SETTLE_SHOW_TIME_COST(1), - SETTLE_SHOW_OPEN_CHEST_COUNT(2), - SETTLE_SHOW_KILL_MONSTER_COUNT(3), - SETTLE_SHOW_BLACKSCREEN(4); - - @Getter private final int id; - - SettleShowType(int id){ - this.id = id; - } -} +package emu.grasscutter.game.dungeons.enums; + +import lombok.Getter; + +public enum SettleShowType { + SETTLE_SHOW_NONE(0), + SETTLE_SHOW_TIME_COST(1), + SETTLE_SHOW_OPEN_CHEST_COUNT(2), + SETTLE_SHOW_KILL_MONSTER_COUNT(3), + SETTLE_SHOW_BLACKSCREEN(4); + + @Getter private final int id; + + SettleShowType(int id) { + this.id = id; + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/handlers/DungeonBaseHandler.java b/src/main/java/emu/grasscutter/game/dungeons/handlers/DungeonBaseHandler.java index 7c02b6199..092fa5ce4 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/handlers/DungeonBaseHandler.java +++ b/src/main/java/emu/grasscutter/game/dungeons/handlers/DungeonBaseHandler.java @@ -1,9 +1,9 @@ -package emu.grasscutter.game.dungeons.handlers; - -import emu.grasscutter.data.excels.DungeonPassConfigData; - -public abstract class DungeonBaseHandler { - - public abstract boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params); - -} +package emu.grasscutter.game.dungeons.handlers; + +import emu.grasscutter.data.excels.dungeon.DungeonPassConfigData; + +public abstract class DungeonBaseHandler { + + public abstract boolean execute( + DungeonPassConfigData.DungeonPassCondition condition, int... params); +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/BaseCondition.java b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/BaseCondition.java index edc795d41..e6a45ea0d 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/BaseCondition.java +++ b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/BaseCondition.java @@ -1,17 +1,16 @@ -package emu.grasscutter.game.dungeons.pass_condition; - -import emu.grasscutter.data.excels.DungeonPassConfigData; -import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; -import emu.grasscutter.game.dungeons.DungeonValue; -import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; - -@DungeonValue(DungeonPassConditionType.DUNGEON_COND_NONE) -public class BaseCondition extends DungeonBaseHandler { - - @Override - public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { - // TODO Auto-generated method stub - return false; - } - -} +package emu.grasscutter.game.dungeons.pass_condition; + +import emu.grasscutter.data.excels.dungeon.DungeonPassConfigData; +import emu.grasscutter.game.dungeons.DungeonValue; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; + +@DungeonValue(DungeonPassConditionType.DUNGEON_COND_NONE) +public class BaseCondition extends DungeonBaseHandler { + + @Override + public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { + // TODO Auto-generated method stub + return false; + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionFinishChallenge.java b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionFinishChallenge.java index 40dd40e29..4fdffc1dc 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionFinishChallenge.java +++ b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionFinishChallenge.java @@ -1,15 +1,15 @@ -package emu.grasscutter.game.dungeons.pass_condition; - -import emu.grasscutter.data.excels.DungeonPassConfigData; -import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; -import emu.grasscutter.game.dungeons.DungeonValue; -import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; - -@DungeonValue(DungeonPassConditionType.DUNGEON_COND_FINISH_CHALLENGE) -public class ConditionFinishChallenge extends DungeonBaseHandler { - - @Override - public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { - return params[0] == condition.getParam()[0] || params[1] == condition.getParam()[0]; - } -} +package emu.grasscutter.game.dungeons.pass_condition; + +import emu.grasscutter.data.excels.dungeon.DungeonPassConfigData; +import emu.grasscutter.game.dungeons.DungeonValue; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; + +@DungeonValue(DungeonPassConditionType.DUNGEON_COND_FINISH_CHALLENGE) +public class ConditionFinishChallenge extends DungeonBaseHandler { + + @Override + public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { + return params[0] == condition.getParam()[0] || params[1] == condition.getParam()[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionFinishQuest.java b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionFinishQuest.java index 0e18dddeb..576387902 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionFinishQuest.java +++ b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionFinishQuest.java @@ -1,15 +1,15 @@ -package emu.grasscutter.game.dungeons.pass_condition; - -import emu.grasscutter.data.excels.DungeonPassConfigData; -import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; -import emu.grasscutter.game.dungeons.DungeonValue; -import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; - -@DungeonValue(DungeonPassConditionType.DUNGEON_COND_FINISH_QUEST) -public class ConditionFinishQuest extends DungeonBaseHandler { - - @Override - public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { - return params[0] == condition.getParam()[0]; - } -} +package emu.grasscutter.game.dungeons.pass_condition; + +import emu.grasscutter.data.excels.dungeon.DungeonPassConfigData; +import emu.grasscutter.game.dungeons.DungeonValue; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; + +@DungeonValue(DungeonPassConditionType.DUNGEON_COND_FINISH_QUEST) +public class ConditionFinishQuest extends DungeonBaseHandler { + + @Override + public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { + return params[0] == condition.getParam()[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionInTime.java b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionInTime.java index b387cde26..dd2a969d8 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionInTime.java +++ b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionInTime.java @@ -1,15 +1,15 @@ -package emu.grasscutter.game.dungeons.pass_condition; - -import emu.grasscutter.data.excels.DungeonPassConfigData; -import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; -import emu.grasscutter.game.dungeons.DungeonValue; -import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; - -@DungeonValue(DungeonPassConditionType.DUNGEON_COND_IN_TIME) -public class ConditionInTime extends DungeonBaseHandler { - - @Override - public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { - return params[0] <= condition.getParam()[0]; - } -} +package emu.grasscutter.game.dungeons.pass_condition; + +import emu.grasscutter.data.excels.dungeon.DungeonPassConfigData; +import emu.grasscutter.game.dungeons.DungeonValue; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; + +@DungeonValue(DungeonPassConditionType.DUNGEON_COND_IN_TIME) +public class ConditionInTime extends DungeonBaseHandler { + + @Override + public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { + return params[0] <= condition.getParam()[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillGroupMonster.java b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillGroupMonster.java index a72eef9da..4359cfd4f 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillGroupMonster.java +++ b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillGroupMonster.java @@ -1,15 +1,15 @@ -package emu.grasscutter.game.dungeons.pass_condition; - -import emu.grasscutter.data.excels.DungeonPassConfigData; -import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; -import emu.grasscutter.game.dungeons.DungeonValue; -import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; - -@DungeonValue(DungeonPassConditionType.DUNGEON_COND_KILL_GROUP_MONSTER) -public class ConditionKillGroupMonster extends DungeonBaseHandler { - - @Override - public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { - return params[0] == condition.getParam()[0]; - } -} +package emu.grasscutter.game.dungeons.pass_condition; + +import emu.grasscutter.data.excels.dungeon.DungeonPassConfigData; +import emu.grasscutter.game.dungeons.DungeonValue; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; + +@DungeonValue(DungeonPassConditionType.DUNGEON_COND_KILL_GROUP_MONSTER) +public class ConditionKillGroupMonster extends DungeonBaseHandler { + + @Override + public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { + return params[0] == condition.getParam()[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillMonster.java b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillMonster.java index 8faea3740..8bd31d962 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillMonster.java +++ b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillMonster.java @@ -1,15 +1,15 @@ -package emu.grasscutter.game.dungeons.pass_condition; - -import emu.grasscutter.data.excels.DungeonPassConfigData; -import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; -import emu.grasscutter.game.dungeons.DungeonValue; -import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; - -@DungeonValue(DungeonPassConditionType.DUNGEON_COND_KILL_MONSTER) -public class ConditionKillMonster extends DungeonBaseHandler { - - @Override - public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { - return params[0] == condition.getParam()[0]; - } -} +package emu.grasscutter.game.dungeons.pass_condition; + +import emu.grasscutter.data.excels.dungeon.DungeonPassConfigData; +import emu.grasscutter.game.dungeons.DungeonValue; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; + +@DungeonValue(DungeonPassConditionType.DUNGEON_COND_KILL_MONSTER) +public class ConditionKillMonster extends DungeonBaseHandler { + + @Override + public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { + return params[0] == condition.getParam()[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillMonsterCount.java b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillMonsterCount.java index e12342a52..3ef8d9810 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillMonsterCount.java +++ b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillMonsterCount.java @@ -1,15 +1,15 @@ -package emu.grasscutter.game.dungeons.pass_condition; - -import emu.grasscutter.data.excels.DungeonPassConfigData; -import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; -import emu.grasscutter.game.dungeons.DungeonValue; -import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; - -@DungeonValue(DungeonPassConditionType.DUNGEON_COND_KILL_MONSTER_COUNT) -public class ConditionKillMonsterCount extends DungeonBaseHandler { - - @Override - public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { - return params[0] >= condition.getParam()[0]; - } -} +package emu.grasscutter.game.dungeons.pass_condition; + +import emu.grasscutter.data.excels.dungeon.DungeonPassConfigData; +import emu.grasscutter.game.dungeons.DungeonValue; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; + +@DungeonValue(DungeonPassConditionType.DUNGEON_COND_KILL_MONSTER_COUNT) +public class ConditionKillMonsterCount extends DungeonBaseHandler { + + @Override + public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { + return params[0] >= condition.getParam()[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillTypeMonster.java b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillTypeMonster.java index c5a834528..6ce57abd9 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillTypeMonster.java +++ b/src/main/java/emu/grasscutter/game/dungeons/pass_condition/ConditionKillTypeMonster.java @@ -1,15 +1,15 @@ -package emu.grasscutter.game.dungeons.pass_condition; - -import emu.grasscutter.data.excels.DungeonPassConfigData; -import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; -import emu.grasscutter.game.dungeons.DungeonValue; -import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; - -@DungeonValue(DungeonPassConditionType.DUNGEON_COND_KILL_TYPE_MONSTER) -public class ConditionKillTypeMonster extends DungeonBaseHandler { - - @Override - public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { - return params[0] == condition.getParam()[0]; - } -} +package emu.grasscutter.game.dungeons.pass_condition; + +import emu.grasscutter.data.excels.dungeon.DungeonPassConfigData; +import emu.grasscutter.game.dungeons.DungeonValue; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; +import emu.grasscutter.game.dungeons.handlers.DungeonBaseHandler; + +@DungeonValue(DungeonPassConditionType.DUNGEON_COND_KILL_TYPE_MONSTER) +public class ConditionKillTypeMonster extends DungeonBaseHandler { + + @Override + public boolean execute(DungeonPassConfigData.DungeonPassCondition condition, int... params) { + return params[0] == condition.getParam()[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java b/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java index 49c21bd90..529f2dc00 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java @@ -2,8 +2,8 @@ package emu.grasscutter.game.entity; import emu.grasscutter.GameConstants; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.AvatarData; -import emu.grasscutter.data.excels.AvatarSkillDepotData; +import emu.grasscutter.data.excels.avatar.AvatarData; +import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.inventory.EquipType; import emu.grasscutter.game.inventory.GameItem; diff --git a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java index 830490413..3896ed674 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java @@ -3,8 +3,8 @@ package emu.grasscutter.game.entity; import emu.grasscutter.data.GameData; import emu.grasscutter.data.common.PropGrowCurve; import emu.grasscutter.data.excels.EnvAnimalGatherConfigData; -import emu.grasscutter.data.excels.MonsterCurveData; -import emu.grasscutter.data.excels.MonsterData; +import emu.grasscutter.data.excels.monster.MonsterCurveData; +import emu.grasscutter.data.excels.monster.MonsterData; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.*; import emu.grasscutter.game.world.Scene; diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetAbility.java b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetAbility.java index 30f03e574..7555b31dd 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetAbility.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetAbility.java @@ -1,39 +1,37 @@ -package emu.grasscutter.game.entity.gadget; - -import java.util.Arrays; - -import emu.grasscutter.game.entity.EntityClientGadget; -import emu.grasscutter.game.entity.EntityGadget; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.proto.AbilityGadgetInfoOuterClass; -import emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq; -import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo; -import lombok.val; - -public class GadgetAbility extends GadgetContent { - private EntityClientGadget parent; - - public GadgetAbility(EntityGadget gadget, EntityClientGadget parent) { - super(gadget); - this.parent = parent; - } - - public boolean onInteract(Player player, GadgetInteractReq req) { - return false; - } - - public void onBuildProto(SceneGadgetInfo.Builder gadgetInfo) { - if (this.parent == null) { - return; - } - - val abilityGadgetInfo = AbilityGadgetInfoOuterClass.AbilityGadgetInfo.newBuilder() - .setCampId(parent.getCampId()) - .setCampTargetType(parent.getCampType()) - .setTargetEntityId(parent.getId()) - .build(); - - gadgetInfo.setAbilityGadget(abilityGadgetInfo); - } - -} +package emu.grasscutter.game.entity.gadget; + +import emu.grasscutter.game.entity.EntityClientGadget; +import emu.grasscutter.game.entity.EntityGadget; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.proto.AbilityGadgetInfoOuterClass; +import emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq; +import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo; +import lombok.val; + +public class GadgetAbility extends GadgetContent { + private EntityClientGadget parent; + + public GadgetAbility(EntityGadget gadget, EntityClientGadget parent) { + super(gadget); + this.parent = parent; + } + + public boolean onInteract(Player player, GadgetInteractReq req) { + return false; + } + + public void onBuildProto(SceneGadgetInfo.Builder gadgetInfo) { + if (this.parent == null) { + return; + } + + val abilityGadgetInfo = + AbilityGadgetInfoOuterClass.AbilityGadgetInfo.newBuilder() + .setCampId(parent.getCampId()) + .setCampTargetType(parent.getCampType()) + .setTargetEntityId(parent.getId()) + .build(); + + gadgetInfo.setAbilityGadget(abilityGadgetInfo); + } +} diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/platform/AbilityRoute.java b/src/main/java/emu/grasscutter/game/entity/gadget/platform/AbilityRoute.java index 44f07cb0b..c8d571a61 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/platform/AbilityRoute.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/platform/AbilityRoute.java @@ -1,28 +1,28 @@ -package emu.grasscutter.game.entity.gadget.platform; - -import emu.grasscutter.net.proto.MathQuaternionOuterClass.MathQuaternion; -import emu.grasscutter.net.proto.MovingPlatformTypeOuterClass; -import emu.grasscutter.net.proto.PlatformInfoOuterClass; -import emu.grasscutter.utils.Position; - -/** - * TODO mostly hardcoded for EntitySolarIsotomaElevatorPlatform, should be more generic - */ -public class AbilityRoute extends BaseRoute { - - private final Position basePosition; - - public AbilityRoute(Position startRot, boolean startRoute, boolean isActive, Position basePosition) { - super(startRot, startRoute, isActive); - this.basePosition = basePosition; - } - - @Override - public PlatformInfoOuterClass.PlatformInfo.Builder toProto() { - return super.toProto() - .setStartRot(MathQuaternion.newBuilder().setW(1.0F)) - .setPosOffset(basePosition.toProto()) - .setRotOffset(MathQuaternion.newBuilder().setW(1.0F)) - .setMovingPlatformType(MovingPlatformTypeOuterClass.MovingPlatformType.MOVING_PLATFORM_TYPE_ABILITY); - } -} +package emu.grasscutter.game.entity.gadget.platform; + +import emu.grasscutter.net.proto.MathQuaternionOuterClass.MathQuaternion; +import emu.grasscutter.net.proto.MovingPlatformTypeOuterClass; +import emu.grasscutter.net.proto.PlatformInfoOuterClass; +import emu.grasscutter.utils.Position; + +/** TODO mostly hardcoded for EntitySolarIsotomaElevatorPlatform, should be more generic */ +public class AbilityRoute extends BaseRoute { + + private final Position basePosition; + + public AbilityRoute( + Position startRot, boolean startRoute, boolean isActive, Position basePosition) { + super(startRot, startRoute, isActive); + this.basePosition = basePosition; + } + + @Override + public PlatformInfoOuterClass.PlatformInfo.Builder toProto() { + return super.toProto() + .setStartRot(MathQuaternion.newBuilder().setW(1.0F)) + .setPosOffset(basePosition.toProto()) + .setRotOffset(MathQuaternion.newBuilder().setW(1.0F)) + .setMovingPlatformType( + MovingPlatformTypeOuterClass.MovingPlatformType.MOVING_PLATFORM_TYPE_ABILITY); + } +} diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/platform/BaseRoute.java b/src/main/java/emu/grasscutter/game/entity/gadget/platform/BaseRoute.java index 6ea1ddd58..d6b425055 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/platform/BaseRoute.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/platform/BaseRoute.java @@ -1,84 +1,83 @@ -package emu.grasscutter.game.entity.gadget.platform; - -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.net.proto.MathQuaternionOuterClass.MathQuaternion; -import emu.grasscutter.net.proto.PlatformInfoOuterClass.PlatformInfo; -import emu.grasscutter.scripts.data.SceneGadget; -import emu.grasscutter.utils.Position; -import lombok.Getter; -import lombok.Setter; -import lombok.val; - -public abstract class BaseRoute { - @Getter @Setter private boolean isStarted; - @Getter @Setter private boolean isActive; - @Getter @Setter private Position startRot; - @Getter @Setter private int startSceneTime; - @Getter @Setter private int stopSceneTime; - - BaseRoute(Position startRot, boolean isStarted, boolean isActive) { - this.startRot = startRot; - this.isStarted = isStarted; - this.isActive = isActive; - } - - BaseRoute(SceneGadget gadget) { - this.startRot = gadget.rot; - this.isStarted = gadget.start_route; - this.isActive = gadget.start_route; - } - - public static BaseRoute fromSceneGadget(SceneGadget sceneGadget) { - if (sceneGadget.route_id != 0) { - return new ConfigRoute(sceneGadget); - } else if (sceneGadget.is_use_point_array) { - return new PointArrayRoute(sceneGadget); - } - return null; - } - - public boolean startRoute(Scene scene) { - if (this.isStarted) { - return false; - } - this.isStarted = true; - this.isActive = true; - this.startSceneTime = scene.getSceneTime()+300; - - return true; - } - - public boolean stopRoute(Scene scene) { - if (!this.isStarted) { - return false; - } - this.isStarted = false; - this.isActive = false; - this.startSceneTime = scene.getSceneTime(); - this.stopSceneTime = scene.getSceneTime(); - - return true; - } - - private MathQuaternion.Builder rotAsMathQuaternion() { - val result = MathQuaternion.newBuilder(); - if (startRot != null) { - result.setX(startRot.getX()) - .setY(startRot.getY()) - .setZ(startRot.getZ()); - } - return result; - } - - public PlatformInfo.Builder toProto() { - val result = PlatformInfo.newBuilder() - .setIsStarted(isStarted) - .setIsActive(isActive) - .setStartRot(rotAsMathQuaternion()) - .setStartSceneTime(startSceneTime); - if (!isStarted) { - result.setStopSceneTime(stopSceneTime); - } - return result; - } -} +package emu.grasscutter.game.entity.gadget.platform; + +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.net.proto.MathQuaternionOuterClass.MathQuaternion; +import emu.grasscutter.net.proto.PlatformInfoOuterClass.PlatformInfo; +import emu.grasscutter.scripts.data.SceneGadget; +import emu.grasscutter.utils.Position; +import lombok.Getter; +import lombok.Setter; +import lombok.val; + +public abstract class BaseRoute { + @Getter @Setter private boolean isStarted; + @Getter @Setter private boolean isActive; + @Getter @Setter private Position startRot; + @Getter @Setter private int startSceneTime; + @Getter @Setter private int stopSceneTime; + + BaseRoute(Position startRot, boolean isStarted, boolean isActive) { + this.startRot = startRot; + this.isStarted = isStarted; + this.isActive = isActive; + } + + BaseRoute(SceneGadget gadget) { + this.startRot = gadget.rot; + this.isStarted = gadget.start_route; + this.isActive = gadget.start_route; + } + + public static BaseRoute fromSceneGadget(SceneGadget sceneGadget) { + if (sceneGadget.route_id != 0) { + return new ConfigRoute(sceneGadget); + } else if (sceneGadget.is_use_point_array) { + return new PointArrayRoute(sceneGadget); + } + return null; + } + + public boolean startRoute(Scene scene) { + if (this.isStarted) { + return false; + } + this.isStarted = true; + this.isActive = true; + this.startSceneTime = scene.getSceneTime() + 300; + + return true; + } + + public boolean stopRoute(Scene scene) { + if (!this.isStarted) { + return false; + } + this.isStarted = false; + this.isActive = false; + this.startSceneTime = scene.getSceneTime(); + this.stopSceneTime = scene.getSceneTime(); + + return true; + } + + private MathQuaternion.Builder rotAsMathQuaternion() { + val result = MathQuaternion.newBuilder(); + if (startRot != null) { + result.setX(startRot.getX()).setY(startRot.getY()).setZ(startRot.getZ()); + } + return result; + } + + public PlatformInfo.Builder toProto() { + val result = + PlatformInfo.newBuilder() + .setIsStarted(isStarted) + .setIsActive(isActive) + .setStartRot(rotAsMathQuaternion()) + .setStartSceneTime(startSceneTime); + if (!isStarted) { + result.setStopSceneTime(stopSceneTime); + } + return result; + } +} diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/platform/ConfigRoute.java b/src/main/java/emu/grasscutter/game/entity/gadget/platform/ConfigRoute.java index 60659e2c3..cea3bbc92 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/platform/ConfigRoute.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/platform/ConfigRoute.java @@ -1,30 +1,31 @@ -package emu.grasscutter.game.entity.gadget.platform; - -import emu.grasscutter.net.proto.MovingPlatformTypeOuterClass; -import emu.grasscutter.net.proto.PlatformInfoOuterClass; -import emu.grasscutter.scripts.data.SceneGadget; -import emu.grasscutter.utils.Position; -import lombok.Getter; -import lombok.Setter; - -public class ConfigRoute extends BaseRoute { - - @Getter @Setter private int routeId; - - public ConfigRoute(SceneGadget gadget) { - super(gadget); - this.routeId = gadget.route_id; - } - - public ConfigRoute(Position startRot, boolean startRoute, boolean isActive, int routeId) { - super(startRot, startRoute, isActive); - this.routeId = routeId; - } - - @Override - public PlatformInfoOuterClass.PlatformInfo.Builder toProto() { - return super.toProto() - .setRouteId(routeId) - .setMovingPlatformType(MovingPlatformTypeOuterClass.MovingPlatformType.MOVING_PLATFORM_TYPE_USE_CONFIG); - } -} +package emu.grasscutter.game.entity.gadget.platform; + +import emu.grasscutter.net.proto.MovingPlatformTypeOuterClass; +import emu.grasscutter.net.proto.PlatformInfoOuterClass; +import emu.grasscutter.scripts.data.SceneGadget; +import emu.grasscutter.utils.Position; +import lombok.Getter; +import lombok.Setter; + +public class ConfigRoute extends BaseRoute { + + @Getter @Setter private int routeId; + + public ConfigRoute(SceneGadget gadget) { + super(gadget); + this.routeId = gadget.route_id; + } + + public ConfigRoute(Position startRot, boolean startRoute, boolean isActive, int routeId) { + super(startRot, startRoute, isActive); + this.routeId = routeId; + } + + @Override + public PlatformInfoOuterClass.PlatformInfo.Builder toProto() { + return super.toProto() + .setRouteId(routeId) + .setMovingPlatformType( + MovingPlatformTypeOuterClass.MovingPlatformType.MOVING_PLATFORM_TYPE_USE_CONFIG); + } +} diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/platform/PointArrayRoute.java b/src/main/java/emu/grasscutter/game/entity/gadget/platform/PointArrayRoute.java index 84b1c6620..00b6d0191 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/platform/PointArrayRoute.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/platform/PointArrayRoute.java @@ -1,32 +1,32 @@ -package emu.grasscutter.game.entity.gadget.platform; - -import emu.grasscutter.net.proto.MovingPlatformTypeOuterClass; -import emu.grasscutter.net.proto.PlatformInfoOuterClass; -import emu.grasscutter.scripts.data.SceneGadget; -import emu.grasscutter.utils.Position; -import lombok.Getter; -import lombok.Setter; - -/** - * TODO implement point array routes, read from missing resources - */ -public class PointArrayRoute extends BaseRoute { - - @Getter @Setter int currentPoint; - @Getter @Setter int pointArrayId; - - public PointArrayRoute(SceneGadget gadget) { - super(gadget); - } - - public PointArrayRoute(Position startRot, boolean startRoute, boolean isActive, int pointArrayId) { - super(startRot, startRoute, isActive); - this.pointArrayId = pointArrayId; - } - - @Override - public PlatformInfoOuterClass.PlatformInfo.Builder toProto() { - return super.toProto() - .setMovingPlatformType(MovingPlatformTypeOuterClass.MovingPlatformType.MOVING_PLATFORM_TYPE_ROUTE); - } -} +package emu.grasscutter.game.entity.gadget.platform; + +import emu.grasscutter.net.proto.MovingPlatformTypeOuterClass; +import emu.grasscutter.net.proto.PlatformInfoOuterClass; +import emu.grasscutter.scripts.data.SceneGadget; +import emu.grasscutter.utils.Position; +import lombok.Getter; +import lombok.Setter; + +/** TODO implement point array routes, read from missing resources */ +public class PointArrayRoute extends BaseRoute { + + @Getter @Setter int currentPoint; + @Getter @Setter int pointArrayId; + + public PointArrayRoute(SceneGadget gadget) { + super(gadget); + } + + public PointArrayRoute( + Position startRot, boolean startRoute, boolean isActive, int pointArrayId) { + super(startRot, startRoute, isActive); + this.pointArrayId = pointArrayId; + } + + @Override + public PlatformInfoOuterClass.PlatformInfo.Builder toProto() { + return super.toProto() + .setMovingPlatformType( + MovingPlatformTypeOuterClass.MovingPlatformType.MOVING_PLATFORM_TYPE_ROUTE); + } +} diff --git a/src/main/java/emu/grasscutter/game/inventory/GameItem.java b/src/main/java/emu/grasscutter/game/inventory/GameItem.java index 58516e6d7..421700775 100644 --- a/src/main/java/emu/grasscutter/game/inventory/GameItem.java +++ b/src/main/java/emu/grasscutter/game/inventory/GameItem.java @@ -5,8 +5,8 @@ import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameDepot; import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.excels.ItemData; -import emu.grasscutter.data.excels.ReliquaryAffixData; -import emu.grasscutter.data.excels.ReliquaryMainPropData; +import emu.grasscutter.data.excels.reliquary.ReliquaryAffixData; +import emu.grasscutter.data.excels.reliquary.ReliquaryMainPropData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.FightProperty; diff --git a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomActivity.java b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomActivity.java index 55a62f124..fab2e029a 100644 --- a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomActivity.java +++ b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomActivity.java @@ -1,8 +1,8 @@ package emu.grasscutter.game.managers.blossom; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.MonsterData; -import emu.grasscutter.data.excels.WorldLevelData; +import emu.grasscutter.data.excels.monster.MonsterData; +import emu.grasscutter.data.excels.world.WorldLevelData; import emu.grasscutter.game.dungeons.challenge.WorldChallenge; import emu.grasscutter.game.dungeons.challenge.trigger.ChallengeTrigger; import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterTrigger; diff --git a/src/main/java/emu/grasscutter/game/managers/energy/EnergyManager.java b/src/main/java/emu/grasscutter/game/managers/energy/EnergyManager.java index 422e7d629..b5aff68d2 100644 --- a/src/main/java/emu/grasscutter/game/managers/energy/EnergyManager.java +++ b/src/main/java/emu/grasscutter/game/managers/energy/EnergyManager.java @@ -6,9 +6,9 @@ import com.google.protobuf.InvalidProtocolBufferException; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.DataLoader; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.AvatarSkillDepotData; import emu.grasscutter.data.excels.ItemData; -import emu.grasscutter.data.excels.MonsterData.HpDrops; +import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; +import emu.grasscutter.data.excels.monster.MonsterData.HpDrops; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.entity.*; import emu.grasscutter.game.player.BasePlayerManager; diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index ea89153e5..0189a96ba 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -5,7 +5,7 @@ import emu.grasscutter.GameConstants; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.PlayerLevelData; -import emu.grasscutter.data.excels.WeatherData; +import emu.grasscutter.data.excels.world.WeatherData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.Account; import emu.grasscutter.game.CoopRequest; @@ -44,6 +44,7 @@ import emu.grasscutter.game.props.ClimateType; import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.WatcherTriggerType; import emu.grasscutter.game.quest.QuestManager; +import emu.grasscutter.game.quest.enums.QuestContent; import emu.grasscutter.game.quest.enums.QuestTrigger; import emu.grasscutter.game.shop.ShopLimit; import emu.grasscutter.game.tower.TowerData; @@ -93,235 +94,122 @@ import static emu.grasscutter.config.Configuration.GAME_OPTIONS; @Entity(value = "players", useDiscriminator = false) public class Player { - private transient final Int2ObjectMap coopRequests; // Synchronized getter - @Getter - private transient final Queue attackResults; - @Getter - private transient final InvokeHandler combatInvokeHandler; - @Getter - private transient final InvokeHandler abilityInvokeHandler; - @Getter - private transient final InvokeHandler clientAbilityInitFinishHandler; - @Id - private int id; - @Indexed(options = @IndexOptions(unique = true)) - private String accountId; - @Setter - private transient Account account; - @Getter - @Setter - private transient GameSession session; - @Getter - private String nickname; - @Getter - private String signature; - @Getter - private int headImage; - @Getter - private int nameCardId = 210001; - @Getter - private final Position position; - @Getter - @Setter - private Position prevPos; - @Getter - private final Position rotation; - @Getter - private PlayerBirthday birthday; - @Getter - private PlayerCodex codex; - @Getter - @Setter - private boolean showAvatars; - @Getter - @Setter - private List showAvatarList; - @Getter - @Setter - private List showNameCardList; - @Getter - private final Map properties; - @Getter - @Setter - private int currentRealmId; - @Getter - @Setter - private int widgetId; - @Getter - @Setter - private int sceneId; - @Getter - @Setter - private int regionId; - @Getter - private int mainCharacterId; - @Setter - private boolean godmode; // Getter is inGodmode + @Id private int id; + @Indexed(options = @IndexOptions(unique = true)) private String accountId; + @Setter private transient Account account; + @Getter @Setter private transient GameSession session; + + @Getter private String nickname; + @Getter private String signature; + @Getter private int headImage; + @Getter private int nameCardId = 210001; + @Getter private Position position; + @Getter @Setter private Position prevPos; + @Getter private Position rotation; + @Getter private PlayerBirthday birthday; + @Getter private PlayerCodex codex; + @Getter @Setter private boolean showAvatars; + @Getter @Setter private List showAvatarList; + @Getter @Setter private List showNameCardList; + @Getter private Map properties; + @Getter @Setter private int currentRealmId; + @Getter @Setter private int widgetId; + @Getter @Setter private int sceneId; + @Getter @Setter private int regionId; + @Getter private int mainCharacterId; + @Setter private boolean godmode; // Getter is inGodmode private boolean stamina; // Getter is getUnlimitedStamina, Setter is setUnlimitedStamina - @Getter - private final Set nameCardList; - @Getter - private final Set flyCloakList; - @Getter - private final Set costumeList; - @Getter - @Setter - private Set rewardedLevels; - @Getter - @Setter - private Set homeRewardedLevels; - @Getter - @Setter - private Set realmList; - @Getter - @Setter - private Set seenRealmList; - @Getter - private final Set unlockedForgingBlueprints; - @Getter - private final Set unlockedCombines; - @Getter - private final Set unlockedFurniture; - @Getter - private final Set unlockedFurnitureSuite; - @Getter - private final Map expeditionInfo; - @Getter - private final Map unlockedRecipies; - @Getter - private final List activeForges; - @Getter - private final Map activeCookCompounds; - @Getter - private final Map questGlobalVariables; - @Getter - private final Map openStates; - @Getter - @Setter - private Map> unlockedSceneAreas; - @Getter - @Setter - private Map> unlockedScenePoints; - @Getter - @Setter - private List chatEmojiIdList; - @Transient - private long nextGuid = 0; - @Transient - @Getter - @Setter - private int peerId; - @Transient - private World world; // Synchronized getter and setter - @Transient - private Scene scene; // Synchronized getter and setter - @Transient - @Getter - private int weatherId = 0; - @Transient - @Getter - private ClimateType climate = ClimateType.CLIMATE_SUNNY; + + @Getter private Set nameCardList; + @Getter private Set flyCloakList; + @Getter private Set costumeList; + @Getter @Setter private Set rewardedLevels; + @Getter @Setter private Set homeRewardedLevels; + @Getter @Setter private Set realmList; + @Getter @Setter private Set seenRealmList; + @Getter private Set unlockedForgingBlueprints; + @Getter private Set unlockedCombines; + @Getter private Set unlockedFurniture; + @Getter private Set unlockedFurnitureSuite; + @Getter private Map expeditionInfo; + @Getter private Map unlockedRecipies; + @Getter private List activeForges; + @Getter private Map activeCookCompounds; + @Getter private Map questGlobalVariables; + @Getter private Map openStates; + @Getter @Setter private Map> unlockedSceneAreas; + @Getter @Setter private Map> unlockedScenePoints; + @Getter @Setter private List chatEmojiIdList; + + @Transient private long nextGuid = 0; + @Transient @Getter @Setter private int peerId; + @Transient private World world; // Synchronized getter and setter + @Transient private Scene scene; // Synchronized getter and setter + @Transient @Getter private int weatherId = 0; + @Transient @Getter private ClimateType climate = ClimateType.CLIMATE_SUNNY; + // Player managers go here - @Getter - private final transient AvatarStorage avatars; - @Getter - private final transient Inventory inventory; - @Getter - private final transient FriendsList friendsList; - @Getter - private final transient MailHandler mailHandler; - @Getter - @Setter - private transient MessageHandler messageHandler; - @Getter - private final transient AbilityManager abilityManager; - @Getter - @Setter - private transient QuestManager questManager; - @Getter - private final transient TowerManager towerManager; - @Getter - private transient SotSManager sotsManager; - @Getter - private transient MapMarksManager mapMarksManager; - @Getter - private transient StaminaManager staminaManager; - @Getter - private transient EnergyManager energyManager; - @Getter - private transient ResinManager resinManager; - @Getter - private transient ForgingManager forgingManager; - @Getter - private transient DeforestationManager deforestationManager; - @Getter - private transient FurnitureManager furnitureManager; - @Getter - private transient BattlePassManager battlePassManager; - @Getter - private transient CookingManager cookingManager; - @Getter - private transient CookingCompoundManager cookingCompoundManager; - @Getter - private transient ActivityManager activityManager; - @Getter - private final transient PlayerBuffManager buffManager; - @Getter - private transient PlayerProgressManager progressManager; - @Getter - private transient SatiationManager satiationManager; + @Getter private transient AvatarStorage avatars; + @Getter private transient Inventory inventory; + @Getter private transient FriendsList friendsList; + @Getter private transient MailHandler mailHandler; + @Getter @Setter private transient MessageHandler messageHandler; + @Getter private transient AbilityManager abilityManager; + @Getter @Setter private transient QuestManager questManager; + @Getter private transient TowerManager towerManager; + @Getter private transient SotSManager sotsManager; + @Getter private transient MapMarksManager mapMarksManager; + @Getter private transient StaminaManager staminaManager; + @Getter private transient EnergyManager energyManager; + @Getter private transient ResinManager resinManager; + @Getter private transient ForgingManager forgingManager; + @Getter private transient DeforestationManager deforestationManager; + @Getter private transient FurnitureManager furnitureManager; + @Getter private transient BattlePassManager battlePassManager; + @Getter private transient CookingManager cookingManager; + @Getter private transient CookingCompoundManager cookingCompoundManager; + @Getter private transient ActivityManager activityManager; + @Getter private transient PlayerBuffManager buffManager; + @Getter private transient PlayerProgressManager progressManager; + @Getter private transient SatiationManager satiationManager; + // Manager data (Save-able to the database) - @Getter - private transient Achievements achievements; + @Getter private transient Achievements achievements; private PlayerProfile playerProfile; // Getter has null-check - @Getter - private TeamManager teamManager; + @Getter private TeamManager teamManager; private TowerData towerData; // Getter has null-check - @Getter - private final PlayerGachaInfo gachaInfo; + @Getter private PlayerGachaInfo gachaInfo; private PlayerCollectionRecords collectionRecordStore; // Getter has null-check - @Getter - private final ArrayList shopLimit; - @Getter - private transient GameHome home; - @Setter - private boolean moonCard; // Getter is inMoonCard - @Getter - @Setter - private Date moonCardStartTime; - @Getter - @Setter - private int moonCardDuration; - @Getter - @Setter - private Set moonCardGetTimes; - @Transient - @Getter - private boolean paused; - @Transient - @Getter - @Setter - private int enterSceneToken; - @Transient - @Getter - @Setter - private SceneLoadState sceneLoadState = SceneLoadState.NONE; - @Transient - private boolean hasSentLoginPackets; - @Transient - private long nextSendPlayerLocTime = 0; - @Getter - @Setter - private long springLastUsed; + @Getter private ArrayList shopLimit; + + @Getter private transient GameHome home; + + @Setter private boolean moonCard; // Getter is inMoonCard + @Getter @Setter private Date moonCardStartTime; + @Getter @Setter private int moonCardDuration; + @Getter @Setter private Set moonCardGetTimes; + + @Transient @Getter private boolean paused; + @Transient @Getter @Setter private int enterSceneToken; + @Transient @Getter @Setter private SceneLoadState sceneLoadState = SceneLoadState.NONE; + @Transient private boolean hasSentLoginPackets; + @Transient private long nextSendPlayerLocTime = 0; + + private transient final Int2ObjectMap coopRequests; // Synchronized getter + @Getter private transient final Queue attackResults; + @Getter private transient final InvokeHandler combatInvokeHandler; + @Getter private transient final InvokeHandler abilityInvokeHandler; + @Getter private transient final InvokeHandler clientAbilityInitFinishHandler; + + @Getter @Setter private long springLastUsed; private HashMap mapMarks; // Getter makes an empty hashmap - maybe do this elsewhere? - @Getter - @Setter - private int nextResinRefresh; - @Getter - @Setter - private int lastDailyReset; - @Getter - private final transient MpSettingType mpSetting = MpSettingType.MP_SETTING_TYPE_ENTER_AFTER_APPLY; // TODO + @Getter @Setter private int nextResinRefresh; + @Getter @Setter private int lastDailyReset; + @Getter private transient MpSettingType mpSetting = MpSettingType.MP_SETTING_TYPE_ENTER_AFTER_APPLY; + @Getter private long playerGameTime = 0; + + @Getter private PlayerProgress playerProgress; + @Getter private Set activeQuestTimers; @Deprecated @SuppressWarnings({"rawtypes", "unchecked"}) // Morphia only! @@ -432,6 +320,18 @@ public class Player { this.satiationManager = new SatiationManager(this); } + /** + * Updates the player's game time if it has changed. + * + * @param gameTime The new game time. + */ + public void updatePlayerGameTime(long gameTime) { + if (this.playerGameTime == gameTime) return; + this.playerGameTime = gameTime; + + this.save(); + } + public int getUid() { return id; } @@ -717,7 +617,8 @@ public class Player { // If trigger hasn't been fired yet if (!Boolean.TRUE.equals(quest.getTriggers().put("ENTER_REGION_" + region.config_id, true))) { //getSession().send(new PacketServerCondMeetQuestListUpdateNotify()); - getQuestManager().triggerEvent(QuestTrigger.QUEST_CONTENT_TRIGGER_FIRE, quest.getTriggerData().get("ENTER_REGION_" + region.config_id).getId(), 0); + getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_TRIGGER_FIRE, + quest.getTriggerData().get("ENTER_REGION_" + region.config_id).getId(), 0); } } }); @@ -730,7 +631,8 @@ public class Player { // If trigger hasn't been fired yet if (!Boolean.TRUE.equals(quest.getTriggers().put("LEAVE_REGION_" + region.config_id, true))) { getSession().send(new PacketServerCondMeetQuestListUpdateNotify()); - getQuestManager().triggerEvent(QuestTrigger.QUEST_CONTENT_TRIGGER_FIRE, quest.getTriggerData().get("LEAVE_REGION_" + region.config_id).getId(), 0); + getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_TRIGGER_FIRE, + quest.getTriggerData().get("LEAVE_REGION_" + region.config_id).getId(), 0); } } }); @@ -959,6 +861,11 @@ public class Player { this.sendPacket(new PacketSetNameCardRsp(nameCardId)); } + /** + * Sends a message to this player. + * + * @param message The message to send. + */ public void dropMessage(Object message) { if (this.messageHandler != null) { this.messageHandler.append(message.toString()); diff --git a/src/main/java/emu/grasscutter/game/player/PlayerBuffManager.java b/src/main/java/emu/grasscutter/game/player/PlayerBuffManager.java index 9761d3f31..98587c455 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerBuffManager.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerBuffManager.java @@ -1,6 +1,5 @@ package emu.grasscutter.game.player; -import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.excels.BuffData; @@ -17,13 +16,14 @@ import java.util.Objects; import java.util.Optional; import lombok.Getter; -public class PlayerBuffManager extends BasePlayerManager { +public final class PlayerBuffManager extends BasePlayerManager { private final List pendingBuffs; private final Int2ObjectMap buffs; // Server buffs private int nextBuffUid; public PlayerBuffManager(Player player) { super(player); + this.buffs = new Int2ObjectOpenHashMap<>(); this.pendingBuffs = new ArrayList<>(); } @@ -92,42 +92,40 @@ public class PlayerBuffManager extends BasePlayerManager { */ public synchronized boolean addBuff(int buffId, float duration, Avatar target) { // Get buff excel data - BuffData buffData = GameData.getBuffDataMap().get(buffId); + var buffData = GameData.getBuffDataMap().get(buffId); if (buffData == null) return false; - boolean success = false; - // Perform onAdded actions - success |= + var success = Optional.ofNullable(GameData.getAbilityData(buffData.getAbilityName())) .map(data -> data.modifiers.get(buffData.getModifierName())) .map(modifier -> modifier.onAdded) .map( onAdded -> { - var s = false; - for (var a : onAdded) { - Grasscutter.getLogger().debug("onAdded exists"); - if (Objects.requireNonNull(a.type) == AbilityModifierAction.Type.HealHP) { - Grasscutter.getLogger().debug("Attempting heal"); + var shouldHeal = false; + for (var ability : onAdded) { + if (Objects.requireNonNull(ability.type) == AbilityModifierAction.Type.HealHP) { if (target == null) continue; + var maxHp = target.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); - var amount = a.amount.get() + a.amountByTargetMaxHPRatio.get() * maxHp; + var amount = + ability.amount.get() + ability.amountByTargetMaxHPRatio.get() * maxHp; + target.getAsEntity().heal(amount); - s = true; - Grasscutter.getLogger().debug("Healed {}", amount); + shouldHeal = true; } } - return s; + + return shouldHeal; }) .orElse(false); - Grasscutter.getLogger().debug("Oh no"); // Set duration if (duration < 0f) { duration = buffData.getTime(); } - // Dont add buff if duration is equal or less than 0 + // Don't add buff if duration is equal or less than 0 if (duration <= 0) { return success; } diff --git a/src/main/java/emu/grasscutter/game/player/PlayerCodex.java b/src/main/java/emu/grasscutter/game/player/PlayerCodex.java index b3ad08d1e..9d78aee58 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerCodex.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerCodex.java @@ -3,7 +3,7 @@ package emu.grasscutter.game.player; import dev.morphia.annotations.Entity; import dev.morphia.annotations.Transient; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.CodexAnimalData; +import emu.grasscutter.data.excels.codex.CodexAnimalData; import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.inventory.GameItem; diff --git a/src/main/java/emu/grasscutter/game/player/PlayerProgress.java b/src/main/java/emu/grasscutter/game/player/PlayerProgress.java index ee08959dd..611011c2a 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerProgress.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerProgress.java @@ -1,63 +1,60 @@ -package emu.grasscutter.game.player; - -import dev.morphia.annotations.Entity; -import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.val; - -import java.util.Map; - -/** - * Tracks progress the player made in the world, like obtained items, seen characters and more - */ -@Entity -public class PlayerProgress { - - @Getter private Map itemHistory; - - // keep track of EXEC_ADD_QUEST_PROGRESS count, will be used in CONTENT_ADD_QUEST_PROGRESS - // not sure where to put this, this should be saved to DB but not to individual quest, since - // it will be hard to loop and compare - private Map questProgressCountMap; - - public PlayerProgress(){ - this.questProgressCountMap = new Int2IntOpenHashMap(); - this.itemHistory = new Int2ObjectOpenHashMap<>(); - } - - public boolean hasPlayerObtainedItemHistorically(int itemId){ - return itemHistory.containsKey(itemId); - } - - public int addToItemHistory(int itemId, int count){ - val itemEntry = itemHistory.computeIfAbsent(itemId, (key) -> new ItemEntry(itemId)); - return itemEntry.addToObtainedCount(count); - } - - public int getCurrentProgress(int progressId){ - return questProgressCountMap.getOrDefault(progressId, -1); - } - - public int addToCurrentProgress(int progressId, int count){ - return questProgressCountMap.merge(progressId, count, Integer::sum); - } - - @Entity - @NoArgsConstructor - public static class ItemEntry{ - @Getter private int itemId; - @Getter @Setter private int obtainedCount; - - ItemEntry(int itemId){ - this.itemId = itemId; - } - - int addToObtainedCount(int amount){ - this.obtainedCount+=amount; - return this.obtainedCount; - } - } -} +package emu.grasscutter.game.player; + +import dev.morphia.annotations.Entity; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import java.util.Map; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.val; + +/** Tracks progress the player made in the world, like obtained items, seen characters and more */ +@Entity +public class PlayerProgress { + + @Getter private Map itemHistory; + + // keep track of EXEC_ADD_QUEST_PROGRESS count, will be used in CONTENT_ADD_QUEST_PROGRESS + // not sure where to put this, this should be saved to DB but not to individual quest, since + // it will be hard to loop and compare + private Map questProgressCountMap; + + public PlayerProgress() { + this.questProgressCountMap = new Int2IntOpenHashMap(); + this.itemHistory = new Int2ObjectOpenHashMap<>(); + } + + public boolean hasPlayerObtainedItemHistorically(int itemId) { + return itemHistory.containsKey(itemId); + } + + public int addToItemHistory(int itemId, int count) { + val itemEntry = itemHistory.computeIfAbsent(itemId, (key) -> new ItemEntry(itemId)); + return itemEntry.addToObtainedCount(count); + } + + public int getCurrentProgress(int progressId) { + return questProgressCountMap.getOrDefault(progressId, -1); + } + + public int addToCurrentProgress(int progressId, int count) { + return questProgressCountMap.merge(progressId, count, Integer::sum); + } + + @Entity + @NoArgsConstructor + public static class ItemEntry { + @Getter private int itemId; + @Getter @Setter private int obtainedCount; + + ItemEntry(int itemId) { + this.itemId = itemId; + } + + int addToObtainedCount(int amount) { + this.obtainedCount += amount; + return this.obtainedCount; + } + } +} diff --git a/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java b/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java index 2fa7f29ba..6fd5cf339 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java @@ -6,7 +6,6 @@ import emu.grasscutter.data.excels.OpenStateData; import emu.grasscutter.data.excels.OpenStateData.OpenStateCondType; import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.quest.enums.QuestState; -import emu.grasscutter.game.quest.enums.QuestTrigger; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; import emu.grasscutter.server.packet.send.*; import java.util.Set; @@ -222,7 +221,7 @@ public class PlayerProgressManager extends BasePlayerDataManager { // Fire quest trigger for trans point unlock. this.player .getQuestManager() - .triggerEvent(QuestTrigger.QUEST_CONTENT_UNLOCK_TRANS_POINT, sceneId, pointId); + .triggerEvent(QuestContent.QUEST_CONTENT_UNLOCK_TRANS_POINT, sceneId, pointId); // Send packet. this.player.sendPacket(new PacketScenePointUnlockNotify(sceneId, pointId)); diff --git a/src/main/java/emu/grasscutter/game/player/TeamManager.java b/src/main/java/emu/grasscutter/game/player/TeamManager.java index e3d7139ca..0e5d76cac 100644 --- a/src/main/java/emu/grasscutter/game/player/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/player/TeamManager.java @@ -5,14 +5,17 @@ import static emu.grasscutter.config.Configuration.GAME_OPTIONS; import dev.morphia.annotations.Entity; import dev.morphia.annotations.Transient; import emu.grasscutter.GameConstants; +import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.AvatarSkillDepotData; +import emu.grasscutter.data.binout.config.fields.ConfigAbilityData; +import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityBaseGadget; import emu.grasscutter.game.props.ElementType; import emu.grasscutter.game.props.EnterReason; import emu.grasscutter.game.props.FightProperty; +import emu.grasscutter.game.world.Scene; import emu.grasscutter.game.world.World; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; @@ -20,18 +23,21 @@ import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType; import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState; import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import emu.grasscutter.net.proto.TrialAvatarGrantRecordOuterClass.TrialAvatarGrantRecord.GrantReason; +import emu.grasscutter.net.proto.VisionTypeOuterClass; import emu.grasscutter.server.event.player.PlayerTeamDeathEvent; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Utils; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import java.util.*; +import java.util.stream.Stream; import lombok.Getter; import lombok.Setter; +import lombok.val; @Entity public class TeamManager extends BasePlayerDataManager { @@ -45,8 +51,16 @@ public class TeamManager extends BasePlayerDataManager { @Getter @Setter private int currentCharacterIndex; @Transient @Getter @Setter private TeamInfo mpTeam; @Transient @Getter @Setter private int entityId; + @Transient private int useTemporarilyTeamIndex = -1; @Transient private List temporaryTeam; // Temporary Team for tower + @Transient @Getter @Setter private boolean usingTrialTeam; + @Transient @Getter @Setter private TeamInfo trialAvatarTeam; + // hold trial avatars for later use in rebuilding active team + @Transient @Getter @Setter private Map trialAvatars; + + @Transient @Getter @Setter + private int previousIndex = -1; // index of character selection in team before adding trial avatar public TeamManager() { this.mpTeam = new TeamInfo(); @@ -270,6 +284,18 @@ public class TeamManager extends BasePlayerDataManager { } } + /** Updates all properties of the active team. */ + public void updateTeamProperties() { + this.updateTeamResonances(); // Update team resonances. + this.getPlayer() + .sendPacket(new PacketSceneTeamUpdateNotify(this.getPlayer())); // Notify the player. + + // Skill charges packet - Yes, this is official server behavior as of 2.6.0 + this.getActiveTeam().stream() + .map(EntityAvatar::getAvatar) + .forEach(Avatar::sendSkillExtraChargeMap); + } + public void updateTeamEntities(BasePacket responsePacket) { // Sanity check - Should never happen if (this.getCurrentTeamInfo().getAvatars().size() <= 0) { @@ -277,9 +303,9 @@ public class TeamManager extends BasePlayerDataManager { } // If current team has changed - EntityAvatar currentEntity = this.getCurrentAvatarEntity(); - Int2ObjectMap existingAvatars = new Int2ObjectOpenHashMap<>(); - int prevSelectedAvatarIndex = -1; + var currentEntity = this.getCurrentAvatarEntity(); + var existingAvatars = new Int2ObjectOpenHashMap(); + var prevSelectedAvatarIndex = -1; for (EntityAvatar entity : this.getActiveTeam()) { existingAvatars.put(entity.getAvatar().getAvatarId(), entity); @@ -290,9 +316,8 @@ public class TeamManager extends BasePlayerDataManager { // Add back entities into team for (int i = 0; i < this.getCurrentTeamInfo().getAvatars().size(); i++) { - int avatarId = this.getCurrentTeamInfo().getAvatars().get(i); + var avatarId = (int) this.getCurrentTeamInfo().getAvatars().get(i); EntityAvatar entity; - if (existingAvatars.containsKey(avatarId)) { entity = existingAvatars.get(avatarId); existingAvatars.remove(avatarId); @@ -309,7 +334,7 @@ public class TeamManager extends BasePlayerDataManager { } // Unload removed entities - for (EntityAvatar entity : existingAvatars.values()) { + for (var entity : existingAvatars.values()) { this.getPlayer().getScene().removeEntity(entity); entity.getAvatar().save(); } @@ -323,18 +348,11 @@ public class TeamManager extends BasePlayerDataManager { } this.currentCharacterIndex = prevSelectedAvatarIndex; - // Update team resonances - this.updateTeamResonances(); + // Update properties. + // Notify player. + this.updateTeamProperties(); - // Packets - this.getPlayer().getWorld().broadcastPacket(new PacketSceneTeamUpdateNotify(this.getPlayer())); - - // Skill charges packet - Yes, this is official server behavior as of 2.6.0 - this.getActiveTeam().stream() - .map(EntityAvatar::getAvatar) - .forEach(Avatar::sendSkillExtraChargeMap); - - // Run callback + // Send response packet. if (responsePacket != null) { this.getPlayer().sendPacket(responsePacket); } @@ -402,6 +420,138 @@ public class TeamManager extends BasePlayerDataManager { this.addAvatarsToTeam(teamInfo, newTeam); } + /** + * Setup avatars for a trial avatar team. + * + * @param save Should the original team be saved? + */ + public void setupTrialAvatars(boolean save) { + this.setPreviousIndex(this.getCurrentCharacterIndex()); + + if (save) { + var originalTeam = getCurrentTeamInfo(); + this.getTrialAvatarTeam().copyFrom(originalTeam); + } else this.getActiveTeam().clear(); + + this.usingTrialTeam = true; + } + + /** Displays the trial avatars. Picks the last avatar in the team. */ + public void trialAvatarTeamPostUpdate() { + this.trialAvatarTeamPostUpdate(this.getActiveTeam().size() - 1); + } + + /** + * Displays the trial avatars. + * + * @param newCharacterIndex The avatar to equip. + */ + public void trialAvatarTeamPostUpdate(int newCharacterIndex) { + this.setCurrentCharacterIndex(Math.min(newCharacterIndex, this.getActiveTeam().size() - 1)); + + this.updateTeamProperties(); + this.getPlayer().getScene().addEntity(this.getCurrentAvatarEntity()); + } + + /** + * Adds an avatar to the trial team. + * + * @param trialAvatar The avatar to add. + */ + public void addAvatarToTrialTeam(Avatar trialAvatar) { + // Remove the existing team's avatars. + this.getActiveTeam() + .forEach( + x -> + this.getPlayer() + .getScene() + .removeEntity(x, VisionTypeOuterClass.VisionType.VISION_TYPE_REMOVE)); + // Remove the existing avatar from the teams if it exists. + this.getActiveTeam().removeIf(x -> x.getAvatar().getAvatarId() == trialAvatar.getAvatarId()); + this.getCurrentTeamInfo().getAvatars().removeIf(x -> x == trialAvatar.getAvatarId()); + // Add the avatar to the teams. + this.getActiveTeam().add(new EntityAvatar(this.getPlayer().getScene(), trialAvatar)); + this.getCurrentTeamInfo().addAvatar(trialAvatar); + this.getTrialAvatars().put(trialAvatar.getAvatarId(), trialAvatar); + } + + /** + * Get the GUID of a trial avatar. + * + * @param avatarId The avatar ID. + * @return The GUID of the avatar. + */ + public long getTrialAvatarGuid(int avatarId) { + return getTrialAvatars().values().stream() + .filter(avatar -> avatar.getTrialAvatarId() == avatarId) + .map(avatar -> avatar.getGuid()) + .findFirst() + .orElse(0L); + } + + /** Rollback changes from using a trial avatar team. */ + public void unsetTrialAvatarTeam() { + this.trialAvatarTeamPostUpdate(this.getPreviousIndex()); + this.setPreviousIndex(-1); + } + + /** Removes all avatars from the trial avatar team. */ + public void removeTrialAvatarTeam() { + this.removeTrialAvatarTeam( + this.getActiveTeam().stream().map(avatar -> avatar.getAvatar().getAvatarId()).toList()); + } + + /** + * Removes one avatar from the trial avatar team. + * + * @param avatarId The avatar ID to remove. + */ + public void removeTrialAvatarTeam(int avatarId) { + this.removeTrialAvatarTeam(List.of(avatarId)); + } + + /** + * Removes a collection of avatars from the trial avatar team. + * + * @param avatarIds The avatar IDs to remove. + */ + public void removeTrialAvatarTeam(List avatarIds) { + var player = this.getPlayer(); + + // Disable the trial team. + this.usingTrialTeam = false; + this.trialAvatarTeam = new TeamInfo(); + + // Remove the avatars from the team. + avatarIds.forEach( + avatarId -> { + this.getActiveTeam() + .forEach( + x -> + player + .getScene() + .removeEntity(x, VisionTypeOuterClass.VisionType.VISION_TYPE_REMOVE)); + this.getActiveTeam().removeIf(x -> x.getAvatar().getTrialAvatarId() == avatarId); + this.getTrialAvatars().values().removeIf(x -> x.getTrialAvatarId() == avatarId); + }); + + // Re-add the avatars to the team. + var index = 0; + for (var avatar : this.getCurrentTeamInfo().getAvatars()) { + if (this.getActiveTeam().stream() + .map(entity -> entity.getAvatar().getAvatarId()) + .toList() + .contains(avatar)) return; + + this.getActiveTeam() + .add( + index++, + new EntityAvatar(player.getScene(), player.getAvatars().getAvatarById(avatar))); + } + + this.unsetTrialAvatarTeam(); + } + public void setupTemporaryTeam(List> guidList) { this.temporaryTeam = guidList.stream() @@ -725,4 +875,195 @@ public class TeamManager extends BasePlayerDataManager { player.sendPacket(new PacketAvatarTeamAllDataNotify(player)); player.sendPacket(new PacketDelBackupAvatarTeamRsp(id)); } + + /** + * Applies abilities for the currently selected team. These abilities are sourced from the scene. + * + * @param scene The scene with the abilities to apply. + */ + public void applyAbilities(Scene scene) { + try { + var levelEntityConfig = scene.getSceneData().getLevelEntityConfig(); + var config = GameData.getConfigLevelEntityDataMap().get(levelEntityConfig); + if (config == null) return; + + var avatars = this.getPlayer().getAvatars(); + var avatarIds = scene.getSceneData().getSpecifiedAvatarList(); + var specifiedAvatarList = this.getActiveTeam(); + + if (avatarIds != null && avatarIds.size() > 0) { + // certain scene could limit specific avatars' entry + specifiedAvatarList.clear(); + for (int id : avatarIds) { + var avatar = avatars.getAvatarById(id); + if (avatar == null) continue; + + specifiedAvatarList.add(new EntityAvatar(scene, avatar)); + } + } + + for (var entityAvatar : specifiedAvatarList) { + var avatarData = entityAvatar.getAvatar().getAvatarData(); + if (avatarData == null) { + continue; + } + + avatarData.buildEmbryo(); // Create avatar abilities. + if (config.getAvatarAbilities() == null) { + continue; // continue and not break because has to rebuild ability for the next avatar if + // any + } + + for (ConfigAbilityData abilities : config.getAvatarAbilities()) { + avatarData.getAbilities().add(Utils.abilityHash(abilities.getAbilityName())); + } + } + } catch (Exception e) { + Grasscutter.getLogger() + .error( + "Error applying level entity config for scene {}", scene.getSceneData().getId(), e); + } + } + + public List getTrialAvatarParam(int trialAvatarId) { + if (GameData.getTrialAvatarCustomData() + .isEmpty()) { // use default data if custom data not available + if (GameData.getTrialAvatarDataMap().get(trialAvatarId) == null) return List.of(); + + return GameData.getTrialAvatarDataMap().get(trialAvatarId).getTrialAvatarParamList(); + } + // use custom data + if (GameData.getTrialAvatarCustomData().get(trialAvatarId) == null) return List.of(); + + val trialCustomParams = + GameData.getTrialAvatarCustomData().get(trialAvatarId).getTrialAvatarParamList(); + return trialCustomParams.isEmpty() + ? List.of() + : Stream.of(trialCustomParams.get(0).split(";")).map(Integer::parseInt).toList(); + } + + /** + * Adds a trial avatar to the player's team. + * + * @param avatarId The ID of the avatar. + * @param questMainId The quest ID associated with the quest. + * @param reason The reason for granting the avatar. + * @return True if the avatar was added, false otherwise. + */ + public boolean addTrialAvatar(int avatarId, int questMainId, GrantReason reason) { + List trialAvatarBasicParam = getTrialAvatarParam(avatarId); + if (trialAvatarBasicParam.isEmpty()) return false; + + var avatar = new Avatar(trialAvatarBasicParam.get(0)); + if (avatar.getAvatarData() == null || !this.getPlayer().hasSentLoginPackets()) return false; + + avatar.setOwner(this.getPlayer()); + // Add trial weapons and relics. + avatar.setTrialAvatarInfo(trialAvatarBasicParam.get(1), avatarId, reason, questMainId); + avatar.equipTrialItems(); + // Re-calculate stats + avatar.recalcStats(); + + // Packet, mimic official server behaviour, add to player's bag but not saving to database. + this.getPlayer().sendPacket(new PacketAvatarAddNotify(avatar, false)); + // Add to avatar to the temporary trial team. + this.addAvatarToTrialTeam(avatar); + return true; + } + + /** + * Adds a trial avatar to the player's team. + * + * @param avatarId The ID of the avatar. + * @param questMainId The quest ID associated with the quest. + */ + public void addTrialAvatar(int avatarId, int questMainId) { + this.addTrialAvatars(List.of(avatarId), questMainId, true); + + // Packet, mimic official server behaviour, necessary to stop player from modifying team. + this.getPlayer().sendPacket(new PacketAvatarTeamUpdateNotify(this.getPlayer())); + } + + /** + * Adds a collection of trial avatars to the player's team. + * + * @param avatarIds List of trial avatar IDs. + */ + public void addTrialAvatars(List avatarIds) { + this.addTrialAvatars(avatarIds, 0, false); + } + + /** + * Adds a collection of trial avatars to the player's team. + * + * @param avatarIds List of trial avatar IDs. + * @param save Whether to retain the currently equipped avatars. + */ + public void addTrialAvatars(List avatarIds, boolean save) { + this.addTrialAvatars(avatarIds, 0, save); + } + + /** + * Adds a list of trial avatars to the player's team. + * + * @param avatarIds List of trial avatar IDs. + * @param questId The ID of the quest this trial team is associated with. + * @param save Whether to retain the currently equipped avatars. + */ + public void addTrialAvatars(List avatarIds, int questId, boolean save) { + this.setupTrialAvatars(save); // Perform initial setup. + + // Add the avatars to the team. + avatarIds.forEach( + avatarId -> { + var result = + this.addTrialAvatar( + avatarId, + questId, + questId == 0 + ? GrantReason.GRANT_REASON_BY_QUEST + : GrantReason.GRANT_REASON_BY_TRIAL_AVATAR_ACTIVITY); + + if (!result) throw new RuntimeException("Unable to add trial avatar to team."); + }); + + // Update the team. + this.trialAvatarTeamPostUpdate(questId == 0 ? getActiveTeam().size() - 1 : 0); + } + + /** Removes all trial avatars from the player's team. */ + public void removeTrialAvatar() { + this.removeTrialAvatar( + this.getActiveTeam().stream() + .map(EntityAvatar::getAvatar) + .map(Avatar::getAvatarId) + .toList()); + } + + /** + * Removes a trial avatar from the player's team. Additionally, unlocks the ability to change the + * team configuration. + * + * @param avatarId The ID of the avatar. + */ + public void removeTrialAvatar(int avatarId) { + this.removeTrialAvatar(List.of(avatarId)); + } + + /** + * Removes a collection of trial avatars from the player's team. + * + * @param avatarIds List of trial avatar IDs. + */ + public void removeTrialAvatar(List avatarIds) { + if (!this.isUsingTrialTeam()) throw new RuntimeException("Player is not using a trial team."); + + this.getPlayer() + .sendPacket( + new PacketAvatarDelNotify(avatarIds.stream().map(this::getTrialAvatarGuid).toList())); + this.removeTrialAvatarTeam(avatarIds); + + // Update the team. + if (avatarIds.size() == 1) this.getPlayer().sendPacket(new PacketAvatarTeamUpdateNotify()); + } } diff --git a/src/main/java/emu/grasscutter/game/props/ActivityType.java b/src/main/java/emu/grasscutter/game/props/ActivityType.java index a8264f2c9..6114485f9 100644 --- a/src/main/java/emu/grasscutter/game/props/ActivityType.java +++ b/src/main/java/emu/grasscutter/game/props/ActivityType.java @@ -12,9 +12,17 @@ import lombok.Getter; @AllArgsConstructor public enum ActivityType { NONE(0), + NEW_ACTIVITY_TRIAL_AVATAR(4), + NEW_ACTIVITY_PERSONAL_LIINE(8), + NEW_ACTIVITY_SALESMAN_MP(1205), + NEW_ACTIVITY_SUMMER_TIME(1600), + NEW_ACTIVITY_GENERAL_BANNER(2100), NEW_ACTIVITY_MUSIC_GAME(2202), - ; + NEW_ACTIVITY_PHOTO(2603), + NEW_ACTIVITY_FUNGUS_FIGHTER(3201), + NEW_ACTIVITY_EFFIGY_CHALLENGE_V2(3203); + private final int value; private static final Int2ObjectMap map = new Int2ObjectOpenHashMap<>(); private static final Map stringMap = new HashMap<>(); @@ -27,8 +35,6 @@ public enum ActivityType { }); } - private final int value; - public static ActivityType getTypeByValue(int value) { return map.getOrDefault(value, NONE); } diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddEnergy.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddEnergy.java index 149ef3bbd..468190c5f 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddEnergy.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddEnergy.java @@ -1,6 +1,6 @@ package emu.grasscutter.game.props.ItemUseAction; -import emu.grasscutter.data.excels.AvatarSkillDepotData; +import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.props.ElementType; import emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason; diff --git a/src/main/java/emu/grasscutter/game/props/RefreshType.java b/src/main/java/emu/grasscutter/game/props/RefreshType.java index cb88dbba3..6df43baae 100644 --- a/src/main/java/emu/grasscutter/game/props/RefreshType.java +++ b/src/main/java/emu/grasscutter/game/props/RefreshType.java @@ -1,43 +1,44 @@ -package emu.grasscutter.game.props; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Stream; - -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; - -public enum RefreshType { - REFRESH_NONE (0), - REFRESH_INTERVAL (1), - REFRESH_DAILY (2), - REFRESH_WEEKlY (3), - REFRESH_DAYBEGIN_INTERVAL (4); - - private final int value; - private static final Int2ObjectMap map = new Int2ObjectOpenHashMap<>(); - private static final Map stringMap = new HashMap<>(); - - static { - Stream.of(values()).forEach(e -> { - map.put(e.getValue(), e); - stringMap.put(e.name(), e); - }); - } - - private RefreshType(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - public static RefreshType getTypeByValue(int value) { - return map.getOrDefault(value, REFRESH_NONE); - } - - public static RefreshType getTypeByName(String name) { - return stringMap.getOrDefault(name, REFRESH_NONE); - } -} +package emu.grasscutter.game.props; + +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +public enum RefreshType { + REFRESH_NONE(0), + REFRESH_INTERVAL(1), + REFRESH_DAILY(2), + REFRESH_WEEKlY(3), + REFRESH_DAYBEGIN_INTERVAL(4); + + private final int value; + private static final Int2ObjectMap map = new Int2ObjectOpenHashMap<>(); + private static final Map stringMap = new HashMap<>(); + + static { + Stream.of(values()) + .forEach( + e -> { + map.put(e.getValue(), e); + stringMap.put(e.name(), e); + }); + } + + private RefreshType(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public static RefreshType getTypeByValue(int value) { + return map.getOrDefault(value, REFRESH_NONE); + } + + public static RefreshType getTypeByName(String name) { + return stringMap.getOrDefault(name, REFRESH_NONE); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java b/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java index 449fadd68..ddc7b509c 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java @@ -1,443 +1,490 @@ -package emu.grasscutter.game.quest; - -import dev.morphia.annotations.Entity; -import dev.morphia.annotations.Id; -import dev.morphia.annotations.Indexed; -import dev.morphia.annotations.Transient; -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.binout.MainQuestData; -import emu.grasscutter.data.binout.MainQuestData.SubQuestData; -import emu.grasscutter.data.binout.MainQuestData.TalkData; -import emu.grasscutter.data.binout.ScriptSceneData; -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.data.excels.RewardData; -import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.game.quest.enums.LogicType; -import emu.grasscutter.game.quest.enums.ParentQuestState; -import emu.grasscutter.game.quest.enums.QuestState; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.net.proto.ChildQuestOuterClass.ChildQuest; -import emu.grasscutter.net.proto.ParentQuestOuterClass.ParentQuest; -import emu.grasscutter.scripts.ScriptLoader; -import emu.grasscutter.server.packet.send.PacketCodexDataUpdateNotify; -import emu.grasscutter.server.packet.send.PacketFinishedParentQuestUpdateNotify; -import emu.grasscutter.server.packet.send.PacketQuestProgressUpdateNotify; -import emu.grasscutter.utils.Position; -import java.util.*; -import javax.script.Bindings; -import javax.script.CompiledScript; -import javax.script.ScriptException; -import lombok.Getter; -import org.bson.types.ObjectId; - -@Entity(value = "quests", useDiscriminator = false) -public class GameMainQuest { - @Getter List questGroupSuites; - @Getter int[] suggestTrackMainQuestList; - @Id private ObjectId id; - @Indexed @Getter private int ownerUid; - @Transient @Getter private Player owner; - @Transient @Getter private QuestManager questManager; - @Getter private Map childQuests; - @Getter private int parentQuestId; - @Getter private int[] questVars; - // QuestUpdateQuestVarReq is sent in two stages... - @Getter private List questVarsUpdate; - @Getter private ParentQuestState state; - @Getter private boolean isFinished; - @Getter private Map talks; - // key is subId - private Map rewindPositions; - private Map rewindRotations; - - @Deprecated // Morphia only. Do not use. - public GameMainQuest() {} - - public GameMainQuest(Player player, int parentQuestId) { - this.owner = player; - this.ownerUid = player.getUid(); - this.questManager = player.getQuestManager(); - this.parentQuestId = parentQuestId; - this.childQuests = new HashMap<>(); - this.talks = new HashMap<>(); - // official server always has a list of 5 questVars, with default value 0 - this.questVars = new int[] {0, 0, 0, 0, 0}; - this.state = ParentQuestState.PARENT_QUEST_STATE_NONE; - this.questGroupSuites = new ArrayList<>(); - this.rewindPositions = new HashMap<>(); - this.rewindRotations = new HashMap<>(); - addAllChildQuests(); - addRewindPoints(); - } - - private void addAllChildQuests() { - List subQuestIds = - Arrays.stream(GameData.getMainQuestDataMap().get(this.parentQuestId).getSubQuests()) - .map(SubQuestData::getSubId) - .toList(); - for (Integer subQuestId : subQuestIds) { - QuestData questConfig = GameData.getQuestDataMap().get(subQuestId); - this.childQuests.put(subQuestId, new GameQuest(this, questConfig)); - } - } - - public void setOwner(Player player) { - if (player.getUid() != this.getOwnerUid()) return; - this.owner = player; - } - - public int getQuestVar(int i) { - return questVars[i]; - } - - public void setQuestVar(int i, int value) { - int previousValue = this.questVars[i]; - this.questVars[i] = value; - Grasscutter.getLogger() - .debug("questVar {} value changed from {} to {}", i, previousValue, value); - } - - public void incQuestVar(int i, int inc) { - int previousValue = this.questVars[i]; - this.questVars[i] += inc; - Grasscutter.getLogger() - .debug( - "questVar {} value incremented from {} to {}", i, previousValue, previousValue + inc); - } - - public void decQuestVar(int i, int dec) { - int previousValue = this.questVars[i]; - this.questVars[i] -= dec; - Grasscutter.getLogger() - .debug( - "questVar {} value decremented from {} to {}", i, previousValue, previousValue - dec); - } - - public GameQuest getChildQuestById(int id) { - return this.getChildQuests().get(id); - } - - public GameQuest getChildQuestByOrder(int order) { - return this.getChildQuests().values().stream() - .filter(p -> p.getQuestData().getOrder() == order) - .toList() - .get(0); - } - - public void finish() { - this.isFinished = true; - this.state = ParentQuestState.PARENT_QUEST_STATE_FINISHED; - - this.getOwner().getSession().send(new PacketFinishedParentQuestUpdateNotify(this)); - this.getOwner().getSession().send(new PacketCodexDataUpdateNotify(this)); - - this.save(); - - // Add rewards - MainQuestData mainQuestData = GameData.getMainQuestDataMap().get(this.getParentQuestId()); - if (mainQuestData != null && mainQuestData.getRewardIdList() != null) { - for (int rewardId : mainQuestData.getRewardIdList()) { - RewardData rewardData = GameData.getRewardDataMap().get(rewardId); - - if (rewardData == null) { - continue; - } - - getOwner() - .getInventory() - .addItemParamDatas(rewardData.getRewardItemList(), ActionReason.QuestReward); - } - } - - // handoff main quest - if (mainQuestData.getSuggestTrackMainQuestList() != null) { - Arrays.stream(mainQuestData.getSuggestTrackMainQuestList()) - .forEach(getQuestManager()::startMainQuest); - } - } - - // TODO - public void fail() {} - - public void cancel() {} - - // Rewinds to the last finished/unfinished rewind quest, and returns the avatar rewind position - // (if it exists) - public List rewind() { - if (this.questManager == null) { - this.questManager = getOwner().getQuestManager(); - } - List sortedByOrder = - new ArrayList<>( - getChildQuests().values().stream().filter(q -> q.getQuestData().isRewind()).toList()); - sortedByOrder.sort( - (a, b) -> { - if (a == b) { - return 0; - } - return a.getQuestData().getOrder() > b.getQuestData().getOrder() ? 1 : -1; - }); - boolean didRewind = false; - for (GameQuest quest : sortedByOrder) { - int i = sortedByOrder.indexOf(quest); - if ((i + 1) >= sortedByOrder.size()) { - didRewind = quest.rewind(null); - } else { - didRewind = quest.rewind(sortedByOrder.get(i + 1)); - } - if (didRewind) { - break; - } - } - List rewindQuests = - getChildQuests().values().stream() - .filter( - p -> - (p.getState() == QuestState.QUEST_STATE_UNFINISHED - || p.getState() == QuestState.QUEST_STATE_FINISHED) - && p.getQuestData().isRewind()) - .toList(); - for (GameQuest quest : rewindQuests) { - if (rewindPositions.containsKey(quest.getSubQuestId())) { - List posAndRot = new ArrayList<>(); - posAndRot.add(0, rewindPositions.get(quest.getSubQuestId())); - posAndRot.add(1, rewindRotations.get(quest.getSubQuestId())); - return posAndRot; - } - } - return null; - } - - public void addRewindPoints() { - Bindings bindings = ScriptLoader.getEngine().createBindings(); - String script = "Quest/Share/Q" + getParentQuestId() + "ShareConfig.lua"; - CompiledScript cs = ScriptLoader.getScript(script); - - // mainQuest 303 doesn't have a ShareConfig - if (cs == null) { - Grasscutter.getLogger().debug("Couldn't find " + script); - return; - } - - // Eval script - try { - cs.eval(bindings); - - var rewindDataMap = - ScriptLoader.getSerializer().toMap(RewindData.class, bindings.get("rewind_data")); - for (String subId : rewindDataMap.keySet()) { - RewindData questRewind = rewindDataMap.get(subId); - if (questRewind != null) { - RewindData.AvatarData avatarData = questRewind.getAvatar(); - if (avatarData != null) { - String avatarPos = avatarData.getPos(); - QuestData.Guide guide = - GameData.getQuestDataMap().get(Integer.valueOf(subId)).getGuide(); - if (guide != null) { - int sceneId = guide.getGuideScene(); - ScriptSceneData fullGlobals = - GameData.getScriptSceneDataMap().get("flat.luas.scenes.full_globals.lua.json"); - if (fullGlobals != null) { - ScriptSceneData.ScriptObject dummyPointScript = - fullGlobals - .getScriptObjectList() - .get(sceneId + "/scene" + sceneId + "_dummy_points.lua"); - if (dummyPointScript != null) { - Map> dummyPointMap = dummyPointScript.getDummyPoints(); - if (dummyPointMap != null) { - List avatarPosPos = dummyPointMap.get(avatarPos + ".pos"); - if (avatarPosPos != null) { - Position pos = - new Position( - avatarPosPos.get(0), avatarPosPos.get(1), avatarPosPos.get(2)); - List avatarPosRot = dummyPointMap.get(avatarPos + ".rot"); - Position rot = - new Position( - avatarPosRot.get(0), avatarPosRot.get(1), avatarPosRot.get(2)); - rewindPositions.put(Integer.valueOf(subId), pos); - rewindRotations.put(Integer.valueOf(subId), rot); - Grasscutter.getLogger() - .debug("Succesfully loaded rewind position for subQuest {}", subId); - } - } - } - } - } - } - } - } - - } catch (ScriptException e) { - Grasscutter.getLogger().error("An error occurred while loading rewind positions"); - } - } - - public void tryAcceptSubQuests(QuestTrigger condType, String paramStr, int... params) { - try { - List subQuestsWithCond = - getChildQuests().values().stream() - .filter(p -> p.getState() == QuestState.QUEST_STATE_UNSTARTED) - .filter( - p -> - p.getQuestData().getAcceptCond().stream() - .anyMatch(q -> q.getType() == condType)) - .toList(); - - for (GameQuest subQuestWithCond : subQuestsWithCond) { - List acceptCond = subQuestWithCond.getQuestData().getAcceptCond(); - int[] accept = new int[acceptCond.size()]; - - for (int i = 0; i < subQuestWithCond.getQuestData().getAcceptCond().size(); i++) { - QuestData.QuestCondition condition = acceptCond.get(i); - boolean result = - this.getOwner() - .getServer() - .getQuestSystem() - .triggerCondition(subQuestWithCond, condition, paramStr, params); - accept[i] = result ? 1 : 0; - } - - boolean shouldAccept = - LogicType.calculate(subQuestWithCond.getQuestData().getAcceptCondComb(), accept); - - if (shouldAccept) { - subQuestWithCond.start(); - getQuestManager().getAddToQuestListUpdateNotify().add(subQuestWithCond); - } - } - this.save(); - } catch (Exception e) { - Grasscutter.getLogger().error("An error occurred while trying to accept quest.", e); - } - } - - public void tryFailSubQuests(QuestTrigger condType, String paramStr, int... params) { - try { - List subQuestsWithCond = - getChildQuests().values().stream() - .filter(p -> p.getState() == QuestState.QUEST_STATE_UNFINISHED) - .filter( - p -> - p.getQuestData().getFailCond().stream() - .anyMatch(q -> q.getType() == condType)) - .toList(); - - for (GameQuest subQuestWithCond : subQuestsWithCond) { - List failCond = subQuestWithCond.getQuestData().getFailCond(); - - for (int i = 0; i < subQuestWithCond.getQuestData().getFailCond().size(); i++) { - QuestData.QuestCondition condition = failCond.get(i); - if (condition.getType() == condType) { - boolean result = - this.getOwner() - .getServer() - .getQuestSystem() - .triggerContent(subQuestWithCond, condition, paramStr, params); - subQuestWithCond.getFailProgressList()[i] = result ? 1 : 0; - if (result) { - getOwner().getSession().send(new PacketQuestProgressUpdateNotify(subQuestWithCond)); - } - } - } - - boolean shouldFail = - LogicType.calculate( - subQuestWithCond.getQuestData().getFailCondComb(), - subQuestWithCond.getFailProgressList()); - - if (shouldFail) { - subQuestWithCond.fail(); - getQuestManager().getAddToQuestListUpdateNotify().add(subQuestWithCond); - } - } - - } catch (Exception e) { - Grasscutter.getLogger().error("An error occurred while trying to fail quest.", e); - } - } - - public void tryFinishSubQuests(QuestTrigger condType, String paramStr, int... params) { - try { - List subQuestsWithCond = - getChildQuests().values().stream() - // There are subQuests with no acceptCond, but can be finished (example: 35104) - .filter( - p -> - p.getState() == QuestState.QUEST_STATE_UNFINISHED - && p.getQuestData().getAcceptCond() != null) - .filter( - p -> - p.getQuestData().getFinishCond().stream() - .anyMatch(q -> q.getType() == condType)) - .toList(); - - for (GameQuest subQuestWithCond : subQuestsWithCond) { - List finishCond = subQuestWithCond.getQuestData().getFinishCond(); - - for (int i = 0; i < finishCond.size(); i++) { - QuestData.QuestCondition condition = finishCond.get(i); - if (condition.getType() == condType) { - boolean result = - this.getOwner() - .getServer() - .getQuestSystem() - .triggerContent(subQuestWithCond, condition, paramStr, params); - subQuestWithCond.getFinishProgressList()[i] = result ? 1 : 0; - if (result) { - getOwner().getSession().send(new PacketQuestProgressUpdateNotify(subQuestWithCond)); - } - } - } - - boolean shouldFinish = - LogicType.calculate( - subQuestWithCond.getQuestData().getFinishCondComb(), - subQuestWithCond.getFinishProgressList()); - - if (shouldFinish) { - subQuestWithCond.finish(); - getQuestManager().getAddToQuestListUpdateNotify().add(subQuestWithCond); - } - } - } catch (Exception e) { - Grasscutter.getLogger().debug("An error occurred while trying to finish quest.", e); - } - } - - public void save() { - DatabaseHelper.saveQuest(this); - } - - public void delete() { - DatabaseHelper.deleteQuest(this); - } - - public ParentQuest toProto() { - ParentQuest.Builder proto = - ParentQuest.newBuilder().setParentQuestId(getParentQuestId()).setIsFinished(isFinished()); - - proto - .setParentQuestState(getState().getValue()) - .setVideoKey(QuestManager.getQuestKey(parentQuestId)); - for (GameQuest quest : this.getChildQuests().values()) { - if (quest.getState() != QuestState.QUEST_STATE_UNSTARTED) { - ChildQuest childQuest = - ChildQuest.newBuilder() - .setQuestId(quest.getSubQuestId()) - .setState(quest.getState().getValue()) - .build(); - - proto.addChildQuestList(childQuest); - } - } - - for (int i : getQuestVars()) { - proto.addQuestVar(i); - } - - return proto.build(); - } -} +package emu.grasscutter.game.quest; + +import dev.morphia.annotations.Entity; +import dev.morphia.annotations.Id; +import dev.morphia.annotations.Indexed; +import dev.morphia.annotations.Transient; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.binout.MainQuestData; +import emu.grasscutter.data.binout.MainQuestData.SubQuestData; +import emu.grasscutter.data.binout.MainQuestData.TalkData; +import emu.grasscutter.data.binout.ScriptSceneData; +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.data.excels.RewardData; +import emu.grasscutter.database.DatabaseHelper; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.game.quest.enums.*; +import emu.grasscutter.game.world.World; +import emu.grasscutter.net.proto.ChildQuestOuterClass.ChildQuest; +import emu.grasscutter.net.proto.ParentQuestOuterClass.ParentQuest; +import emu.grasscutter.server.packet.send.PacketCodexDataUpdateNotify; +import emu.grasscutter.server.packet.send.PacketFinishedParentQuestUpdateNotify; +import emu.grasscutter.server.packet.send.PacketQuestProgressUpdateNotify; +import emu.grasscutter.utils.ConversionUtils; +import emu.grasscutter.utils.Position; +import lombok.Getter; +import lombok.val; +import org.bson.types.ObjectId; + +import java.util.*; + +@Entity(value = "quests", useDiscriminator = false) +public class GameMainQuest { + @Id private ObjectId id; + @Indexed @Getter private int ownerUid; + @Transient @Getter private Player owner; + @Transient @Getter private QuestManager questManager; + @Getter private Map childQuests; + @Getter private int parentQuestId; + @Getter private int[] questVars; + @Getter private long[] timeVar; + //QuestUpdateQuestVarReq is sent in two stages... + @Getter private List questVarsUpdate; + @Getter private ParentQuestState state; + @Getter private boolean isFinished; + @Getter List questGroupSuites; + + @Getter int[] suggestTrackMainQuestList; + @Getter private Map talks; + + @Deprecated // Morphia only. Do not use. + public GameMainQuest() {} + + public GameMainQuest(Player player, int parentQuestId) { + this.owner = player; + this.ownerUid = player.getUid(); + this.questManager = player.getQuestManager(); + this.parentQuestId = parentQuestId; + this.childQuests = new HashMap<>(); + this.talks = new HashMap<>(); + //official server always has a list of 5 questVars, with default value 0 + this.questVars = new int[] {0,0,0,0,0}; + this.timeVar = new long[] {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; // theoretically max is 10 here + this.state = ParentQuestState.PARENT_QUEST_STATE_NONE; + this.questGroupSuites = new ArrayList<>(); + addAllChildQuests(); + } + + private void addAllChildQuests() { + List subQuestIds = Arrays.stream(GameData.getMainQuestDataMap().get(this.parentQuestId).getSubQuests()).map(SubQuestData::getSubId).toList(); + for (Integer subQuestId : subQuestIds) { + QuestData questConfig = GameData.getQuestDataMap().get(subQuestId); + this.childQuests.put(subQuestId, new GameQuest(this, questConfig)); + } + } + + public Collection getActiveQuests(){ + return childQuests.values().stream() + .filter(q->q.getState().getValue() == QuestState.QUEST_STATE_UNFINISHED.getValue()) + .toList(); + } + + public void setOwner(Player player) { + if (player.getUid() != this.getOwnerUid()) return; + this.owner = player; + } + + public int getQuestVar(int i) { + return questVars[i]; + } + public void setQuestVar(int i, int value) { + int previousValue = this.questVars[i]; + this.questVars[i] = value; + Grasscutter.getLogger().debug("questVar {} value changed from {} to {}", i, previousValue, value); + } + + public void incQuestVar(int i, int inc) { + int previousValue = this.questVars[i]; + this.questVars[i] += inc; + Grasscutter.getLogger().debug("questVar {} value incremented from {} to {}", i, previousValue, previousValue + inc); + } + + public void decQuestVar(int i, int dec) { + int previousValue = this.questVars[i]; + this.questVars[i] -= dec; + Grasscutter.getLogger().debug("questVar {} value decremented from {} to {}", i, previousValue, previousValue - dec); + } + + + public GameQuest getChildQuestById(int id) { + return this.getChildQuests().get(id); + } + public GameQuest getChildQuestByOrder(int order) { + return this.getChildQuests().values().stream().filter(p -> p.getQuestData().getOrder() == order).toList().get(0); + } + + public void finish() { + // Avoid recursion from child finish() in GameQuest + // when auto finishing all child quests with QUEST_STATE_UNFINISHED (below) + if (this.isFinished) { + Grasscutter.getLogger().debug("Skip main quest finishing because it's already finished"); + return; + } + + this.isFinished = true; + this.state = ParentQuestState.PARENT_QUEST_STATE_FINISHED; + + /* + We also need to check for unfinished childQuests in this MainQuest + force them to complete and send a packet about this to the user, + because at some points there are special "invisible" child quests that control + some situations. + + For example, subQuest 35312 is responsible for the event of leaving the territory + of the island with a statue and automatically returns the character back, + quest 35311 completes the main quest line 353 and starts 35501 from + new MainQuest 355 but if 35312 is not completed after the completion + of the main quest 353 - the character will not be able to leave place + (return again and again) + */ + this + .getChildQuests() + .values() + .stream() + .filter(p -> p.state != QuestState.QUEST_STATE_FINISHED) + .forEach(GameQuest::finish); + + this.getOwner().getSession().send(new PacketFinishedParentQuestUpdateNotify(this)); + this.getOwner().getSession().send(new PacketCodexDataUpdateNotify(this)); + + this.save(); + + // Add rewards + MainQuestData mainQuestData = GameData.getMainQuestDataMap().get(this.getParentQuestId()); + if(mainQuestData.getRewardIdList()!=null) { + for (int rewardId : mainQuestData.getRewardIdList()) { + RewardData rewardData = GameData.getRewardDataMap().get(rewardId); + + if (rewardData == null) { + continue; + } + + getOwner().getInventory().addItemParamDatas(rewardData.getRewardItemList(), ActionReason.QuestReward); + } + } + + // handoff main quest + if (mainQuestData.getSuggestTrackMainQuestList() != null) { + Arrays.stream(mainQuestData.getSuggestTrackMainQuestList()) + .forEach(getQuestManager()::startMainQuest); + } + } + //TODO + public void fail() {} + public void cancel() {} + + + public List rewindTo(GameQuest targetQuest, boolean notifyDelete){ + if(targetQuest == null || !targetQuest.rewind(notifyDelete)){ + return null; + } + + /*if(rewindPositions.isEmpty()){ + addRewindPoints(); + }*/ + + List posAndRot = new ArrayList<>(); + if(hasRewindPosition(targetQuest.getSubQuestId(), posAndRot)){ + return posAndRot; + } + + List rewindQuests = getChildQuests().values().stream() + .filter(p -> (p.getState() == QuestState.QUEST_STATE_UNFINISHED || p.getState() == QuestState.QUEST_STATE_FINISHED) && + p.getQuestData() != null && p.getQuestData().isRewind()).toList(); + + for (GameQuest quest : rewindQuests) { + if (hasRewindPosition(quest.getSubQuestId(), posAndRot)) { + return posAndRot; + } + + } + return null; + } + + // Rewinds to the last finished/unfinished rewind quest, and returns the avatar rewind position (if it exists) + public List rewind() { + if (this.questManager == null) { + this.questManager = getOwner().getQuestManager(); + } + var activeQuests = getActiveQuests(); + var highestActiveQuest = activeQuests.stream() + .filter(q -> q.getQuestData() != null) + .max(Comparator.comparing(q -> q.getQuestData().getOrder())) + .orElse(null); + + if (highestActiveQuest == null) { + var firstUnstarted = getChildQuests().values().stream() + .filter(q -> q.getQuestData() != null && q.getState().getValue() != QuestState.FINISHED.getValue()) + .min(Comparator.comparingInt(a -> a.getQuestData().getOrder())); + if(firstUnstarted.isEmpty()){ + // all quests are probably finished, do don't rewind and maybe also set the mainquest to finished? + return null; + } + highestActiveQuest = firstUnstarted.get(); + //todo maybe try to accept quests if there is no active quest and no rewind target? + //tryAcceptSubQuests(QuestTrigger.QUEST_COND_NONE, "", 0); + } + + var highestOrder = highestActiveQuest.getQuestData().getOrder(); + var rewindTarget = getChildQuests().values().stream() + .filter(q -> q.getQuestData() != null) + .filter(q -> q.getQuestData().isRewind() && q.getQuestData().getOrder() <= highestOrder) + .max(Comparator.comparingInt(a -> a.getQuestData().getOrder())) + .orElse(null); + + return rewindTo(rewindTarget!=null? rewindTarget : highestActiveQuest, false); + } + + public boolean hasRewindPosition(int subId, List posAndRot){ + RewindData questRewind = GameData.getRewindDataMap().get(subId); + if (questRewind == null) return false; + + RewindData.AvatarData avatarData = questRewind.getAvatar(); + if (avatarData == null) return false; + + String avatarPos = avatarData.getPos(); + QuestData.Guide guide = GameData.getQuestDataMap().get(subId).getGuide(); + if (guide == null) return false; + + int sceneId = guide.getGuideScene(); + ScriptSceneData fullGlobals = GameData.getScriptSceneDataMap().get("flat.luas.scenes.full_globals.lua.json"); + if (fullGlobals == null) return false; + + ScriptSceneData.ScriptObject dummyPointScript = fullGlobals.getScriptObjectList().get(sceneId + "/scene" + sceneId + "_dummy_points.lua"); + if (dummyPointScript == null) return false; + + Map> dummyPointMap = dummyPointScript.getDummyPoints(); + if (dummyPointMap == null) return false; + + List avatarPosPos = dummyPointMap.get(avatarPos + ".pos"); + List avatarPosRot = dummyPointMap.get(avatarPos + ".rot"); + if (avatarPosPos == null) return false; + + posAndRot.add(0, new Position(avatarPosPos.get(0),avatarPosPos.get(1),avatarPosPos.get(2))); // position + posAndRot.add(1, new Position(avatarPosRot.get(0),avatarPosRot.get(1),avatarPosRot.get(2))); //rotation + Grasscutter.getLogger().info("Succesfully loaded rewind data for subQuest {}", subId); + return true; + } + + public boolean hasTeleportPostion(int subId, List posAndRot){ + TeleportData questTransmit = GameData.getTeleportDataMap().get(subId); + if (questTransmit == null) return false; + + TeleportData.TransmitPoint transmitPoint = questTransmit.getTransmit_points().size() > 0 ? questTransmit.getTransmit_points().get(0) : null; + if (transmitPoint == null) return false; + + String transmitPos = transmitPoint.getPos(); + int sceneId = transmitPoint.getScene_id(); + ScriptSceneData fullGlobals = GameData.getScriptSceneDataMap().get("flat.luas.scenes.full_globals.lua.json"); + if (fullGlobals == null) return false; + + ScriptSceneData.ScriptObject dummyPointScript = fullGlobals.getScriptObjectList().get(sceneId + "/scene" + sceneId + "_dummy_points.lua"); + if (dummyPointScript == null) return false; + + Map> dummyPointMap = dummyPointScript.getDummyPoints(); + if (dummyPointMap == null) return false; + + List transmitPosPos = dummyPointMap.get(transmitPos + ".pos"); + List transmitPosRot = dummyPointMap.get(transmitPos + ".rot"); + if (transmitPosPos == null) return false; + + posAndRot.add(0, new Position(transmitPosPos.get(0), transmitPosPos.get(1), transmitPosPos.get(2))); // position + posAndRot.add(1, new Position(transmitPosRot.get(0), transmitPosRot.get(1), transmitPosRot.get(2))); // rotation + Grasscutter.getLogger().info("Succesfully loaded teleport data for subQuest {}", subId); + return true; + } + + public void checkProgress(){ + for (var quest : getChildQuests().values()){ + if(quest.getState() == QuestState.QUEST_STATE_UNFINISHED) { + questManager.checkQuestAlreadyFullfilled(quest); + } + } + } + + public void tryAcceptSubQuests(QuestCond condType, String paramStr, int... params) { + try { + List subQuestsWithCond = getChildQuests().values().stream() + .filter(p -> p.getState() == QuestState.QUEST_STATE_UNSTARTED || p.getState() == QuestState.UNFINISHED) + .filter(p -> p.getQuestData().getAcceptCond().stream().anyMatch(q -> condType == QuestCond.QUEST_COND_NONE || q.getType() == condType)) + .toList(); + var questSystem = owner.getServer().getQuestSystem(); + + for (GameQuest subQuestWithCond : subQuestsWithCond) { + var acceptCond = subQuestWithCond.getQuestData().getAcceptCond(); + int[] accept = new int[acceptCond.size()]; + + for (int i = 0; i < subQuestWithCond.getQuestData().getAcceptCond().size(); i++) { + var condition = acceptCond.get(i); + boolean result = questSystem.triggerCondition(getOwner(), subQuestWithCond.getQuestData(), condition, paramStr, params); + accept[i] = result ? 1 : 0; + } + + boolean shouldAccept = LogicType.calculate(subQuestWithCond.getQuestData().getAcceptCondComb(), accept); + + if (shouldAccept) + subQuestWithCond.start(); + } + this.save(); + } catch (Exception e) { + Grasscutter.getLogger().error("An error occurred while trying to accept quest.", e); + } + + } + + public void tryFailSubQuests(QuestContent condType, String paramStr, int... params) { + try { + List subQuestsWithCond = getChildQuests().values().stream() + .filter(p -> p.getState() == QuestState.QUEST_STATE_UNFINISHED) + .filter(p -> p.getQuestData().getFailCond().stream().anyMatch(q -> q.getType() == condType)) + .toList(); + + for (GameQuest subQuestWithCond : subQuestsWithCond) { + val failCond = subQuestWithCond.getQuestData().getFailCond(); + + for (int i = 0; i < subQuestWithCond.getQuestData().getFailCond().size(); i++) { + val condition = failCond.get(i); + if (condition.getType() == condType) { + boolean result = this.getOwner().getServer().getQuestSystem().triggerContent(subQuestWithCond, condition, paramStr, params); + subQuestWithCond.getFailProgressList()[i] = result ? 1 : 0; + if (result) { + getOwner().getSession().send(new PacketQuestProgressUpdateNotify(subQuestWithCond)); + } + } + } + + boolean shouldFail = LogicType.calculate(subQuestWithCond.getQuestData().getFailCondComb(), subQuestWithCond.getFailProgressList()); + + if (shouldFail) + subQuestWithCond.fail(); + } + + } catch (Exception e) { + Grasscutter.getLogger().error("An error occurred while trying to fail quest.", e); + } + } + + public void tryFinishSubQuests(QuestContent condType, String paramStr, int... params) { + try { + List subQuestsWithCond = getChildQuests().values().stream() + //There are subQuests with no acceptCond, but can be finished (example: 35104) + .filter(p -> p.getState() == QuestState.QUEST_STATE_UNFINISHED && p.getQuestData().getAcceptCond() != null) + .filter(p -> p.getQuestData().getFinishCond().stream().anyMatch(q -> q.getType() == condType)) + .toList(); + + for (GameQuest subQuestWithCond : subQuestsWithCond) { + val finishCond = subQuestWithCond.getQuestData().getFinishCond(); + + for (int i = 0; i < finishCond.size(); i++) { + val condition = finishCond.get(i); + if (condition.getType() == condType) { + boolean result = this.getOwner().getServer().getQuestSystem().triggerContent(subQuestWithCond, condition, paramStr, params); + subQuestWithCond.getFinishProgressList()[i] = result ? 1 : 0; + if (result) { + getOwner().getSession().send(new PacketQuestProgressUpdateNotify(subQuestWithCond)); + } + } + } + + boolean shouldFinish = LogicType.calculate(subQuestWithCond.getQuestData().getFinishCondComb(), subQuestWithCond.getFinishProgressList()); + + if (shouldFinish) + subQuestWithCond.finish(); + } + } catch (Exception e) { + Grasscutter.getLogger().debug("An error occurred while trying to finish quest.", e); + } + } + + public void save() { + DatabaseHelper.saveQuest(this); + } + + public void delete() { + DatabaseHelper.deleteQuest(this); + } + + public ParentQuest toProto(boolean withChildQuests) { + var proto = ParentQuest.newBuilder() + .setParentQuestId(getParentQuestId()) + .setIsFinished(isFinished()) + .setParentQuestState(getState().getValue()) + .setVideoKey(QuestManager.getQuestKey(parentQuestId)); + + if (withChildQuests) { + for (var quest : this.getChildQuests().values()) { + if (quest.getState() != QuestState.QUEST_STATE_UNSTARTED) { + var childQuest = ChildQuest.newBuilder() + .setQuestId(quest.getSubQuestId()) + .setState(quest.getState().getValue()) + .build(); + + proto.addChildQuestList(childQuest); + } + } + } + + for (int i : getQuestVars()) { + proto.addQuestVar(i); + } + + return proto.build(); + } + + // TimeVar handling TODO check if ingame or irl time + public boolean initTimeVar(int index){ + if(index >= this.timeVar.length){ + Grasscutter.getLogger().error("Trying to init out of bounds time var {} for quest {}", index, this.parentQuestId); + return false; + } + this.timeVar[index] = owner.getWorld().getTotalGameTimeMinutes(); + owner.getActiveQuestTimers().add(this.parentQuestId); + return true; + } + + public boolean clearTimeVar(int index){ + if(index >= this.timeVar.length){ + Grasscutter.getLogger().error("Trying to clear out of bounds time var {} for quest {}", index, this.parentQuestId); + return false; + } + this.timeVar[index] = -1; + if(!checkActiveTimers()){ + owner.getActiveQuestTimers().remove(this.parentQuestId); + } + return true; + } + + public boolean checkActiveTimers(){ + return Arrays.stream(timeVar).anyMatch(value -> value!=-1); + } + + public long getDaysSinceTimeVar(int index){ + if(index >= this.timeVar.length){ + Grasscutter.getLogger().error("Trying to get days for out of bounds time var {} for quest {}", index, this.parentQuestId); + return -1; + } + val varTime = timeVar[index]; + + if(varTime == -1){ + return 0; + } + + return owner.getWorld().getTotalGameTimeDays() - ConversionUtils.gameTimeToDays(varTime); + } + + public long getHoursSinceTimeVar(int index){ + if(index >= this.timeVar.length){ + Grasscutter.getLogger().error("Trying to get hours for out of bounds time var {} for quest {}", index, this.parentQuestId); + return -1; + } + val varTime = timeVar[index]; + + if(varTime == -1){ + return 0; + } + + return owner.getWorld().getTotalGameTimeDays() - ConversionUtils.gameTimeToDays(varTime); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/GameQuest.java b/src/main/java/emu/grasscutter/game/quest/GameQuest.java index a66abb991..fb92013bc 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameQuest.java @@ -7,20 +7,25 @@ import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.ChapterData; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.data.excels.TriggerExcelConfigData; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.game.quest.enums.QuestCond; +import emu.grasscutter.game.quest.enums.QuestContent; import emu.grasscutter.game.quest.enums.QuestState; -import emu.grasscutter.game.quest.enums.QuestTrigger; import emu.grasscutter.net.proto.ChapterStateOuterClass; import emu.grasscutter.net.proto.QuestOuterClass.Quest; import emu.grasscutter.scripts.data.SceneGroup; import emu.grasscutter.server.packet.send.PacketChapterStateNotify; +import emu.grasscutter.server.packet.send.PacketDelQuestNotify; +import emu.grasscutter.server.packet.send.PacketQuestListUpdateNotify; import emu.grasscutter.utils.Utils; import java.util.HashMap; -import java.util.List; import java.util.Map; import javax.script.Bindings; import lombok.Getter; import lombok.Setter; +import lombok.val; @Entity public class GameQuest { @@ -29,12 +34,14 @@ public class GameQuest { @Getter private int subQuestId; @Getter private int mainQuestId; - @Getter @Setter private QuestState state; + @Getter @Setter public QuestState state; @Getter @Setter private int startTime; @Getter @Setter private int acceptTime; @Getter @Setter private int finishTime; + @Getter @Setter private long startGameDay; + @Getter private int[] finishProgressList; @Getter private int[] failProgressList; @Transient @Getter private Map triggerData; @@ -55,15 +62,17 @@ public class GameQuest { } public void start() { + clearProgress(false); this.acceptTime = Utils.getCurrentSeconds(); this.startTime = this.acceptTime; + this.startGameDay = getOwner().getWorld().getTotalGameTimeDays(); this.state = QuestState.QUEST_STATE_UNFINISHED; - List triggerCond = + val triggerCond = questData.getFinishCond().stream() - .filter(p -> p.getType() == QuestTrigger.QUEST_CONTENT_TRIGGER_FIRE) + .filter(p -> p.getType() == QuestContent.QUEST_CONTENT_TRIGGER_FIRE) .toList(); if (triggerCond.size() > 0) { - for (QuestData.QuestCondition cond : triggerCond) { + for (val cond : triggerCond) { TriggerExcelConfigData newTrigger = GameData.getTriggerExcelConfigDataMap().get(cond.getParam()[0]); if (newTrigger != null) { @@ -81,21 +90,10 @@ public class GameQuest { } } - if (questData.getFinishCond() != null && questData.getFinishCond().size() != 0) { - this.finishProgressList = new int[questData.getFinishCond().size()]; - } - - if (questData.getFailCond() != null && questData.getFailCond().size() != 0) { - this.failProgressList = new int[questData.getFailCond().size()]; - } - - getQuestData() - .getBeginExec() - .forEach(e -> getOwner().getServer().getQuestSystem().triggerExec(this, e, e.getParam())); + getOwner().sendPacket(new PacketQuestListUpdateNotify(this)); if (ChapterData.beginQuestChapterMap.containsKey(subQuestId)) { - mainQuest - .getOwner() + getOwner() .sendPacket( new PacketChapterStateNotify( ChapterData.beginQuestChapterMap.get(subQuestId).getId(), @@ -104,24 +102,24 @@ public class GameQuest { // Some subQuests and talks become active when some other subQuests are unfinished (even from // different MainQuests) - this.getOwner() + getOwner() .getQuestManager() - .triggerEvent( - QuestTrigger.QUEST_CONTENT_QUEST_STATE_EQUAL, - this.getSubQuestId(), - this.getState().getValue(), + .queueEvent( + QuestContent.QUEST_CONTENT_QUEST_STATE_EQUAL, + getSubQuestId(), + getState().getValue(), 0, 0, 0); - this.getOwner() + getOwner() .getQuestManager() - .triggerEvent( - QuestTrigger.QUEST_COND_STATE_EQUAL, - this.getSubQuestId(), - this.getState().getValue(), - 0, - 0, - 0); + .queueEvent( + QuestCond.QUEST_COND_STATE_EQUAL, getSubQuestId(), getState().getValue(), 0, 0, 0); + + getQuestData() + .getBeginExec() + .forEach(e -> getOwner().getServer().getQuestSystem().triggerExec(this, e, e.getParam())); + getOwner().getQuestManager().checkQuestAlreadyFullfilled(this); Grasscutter.getLogger().debug("Quest {} is started", subQuestId); } @@ -141,7 +139,7 @@ public class GameQuest { } public void setConfig(QuestData config) { - if (getSubQuestId() != config.getId()) return; + if (config == null || getSubQuestId() != config.getId()) return; this.questData = config; } @@ -153,11 +151,37 @@ public class GameQuest { failProgressList[index] = value; } + public boolean clearProgress(boolean notifyDelete) { + // TODO improve + var oldState = state; + if (questData.getFinishCond() != null && questData.getFinishCond().size() != 0) { + this.finishProgressList = new int[questData.getFinishCond().size()]; + } + + if (questData.getFailCond() != null && questData.getFailCond().size() != 0) { + this.failProgressList = new int[questData.getFailCond().size()]; + } + setState(QuestState.QUEST_STATE_UNSTARTED); + finishTime = 0; + acceptTime = 0; + startTime = 0; + if (oldState == QuestState.QUEST_STATE_UNSTARTED) { + return false; + } + if (notifyDelete) { + getOwner().sendPacket(new PacketDelQuestNotify(getSubQuestId())); + } + save(); + return true; + } + public void finish() { this.state = QuestState.QUEST_STATE_FINISHED; this.finishTime = Utils.getCurrentSeconds(); - if (getQuestData().finishParent()) { + getOwner().sendPacket(new PacketQuestListUpdateNotify(this)); + + if (getQuestData().isFinishParent()) { // This quest finishes the questline - the main quest will also save the quest to db, so we // don't have to call save() here getMainQuest().finish(); @@ -169,8 +193,8 @@ public class GameQuest { // Some subQuests have conditions that subQuests are finished (even from different MainQuests) getOwner() .getQuestManager() - .triggerEvent( - QuestTrigger.QUEST_CONTENT_QUEST_STATE_EQUAL, + .queueEvent( + QuestContent.QUEST_CONTENT_QUEST_STATE_EQUAL, this.subQuestId, this.state.getValue(), 0, @@ -178,8 +202,16 @@ public class GameQuest { 0); getOwner() .getQuestManager() - .triggerEvent( - QuestTrigger.QUEST_COND_STATE_EQUAL, this.subQuestId, this.state.getValue(), 0, 0, 0); + .queueEvent(QuestContent.QUEST_CONTENT_FINISH_PLOT, this.subQuestId, 0); + getOwner() + .getQuestManager() + .queueEvent( + QuestCond.QUEST_COND_STATE_EQUAL, this.subQuestId, this.state.getValue(), 0, 0, 0); + getOwner() + .getScene() + .triggerDungeonEvent(DungeonPassConditionType.DUNGEON_COND_FINISH_QUEST, getSubQuestId()); + + getOwner().getProgressManager().tryUnlockOpenStates(); if (ChapterData.endQuestChapterMap.containsKey(subQuestId)) { mainQuest @@ -190,6 +222,10 @@ public class GameQuest { ChapterStateOuterClass.ChapterState.CHAPTER_STATE_END)); } + // hard coding to give amber + if (getQuestData().getSubId() == 35402) { + getOwner().getInventory().addItem(1021, 1, ActionReason.QuestItem); // amber item id + } Grasscutter.getLogger().debug("Quest {} is finished", subQuestId); } @@ -198,43 +234,47 @@ public class GameQuest { this.state = QuestState.QUEST_STATE_FAILED; this.finishTime = Utils.getCurrentSeconds(); - getQuestData() - .getFailExec() - .forEach(e -> getOwner().getServer().getQuestSystem().triggerExec(this, e, e.getParam())); + this.getOwner().sendPacket(new PacketQuestListUpdateNotify(this)); + // Some subQuests have conditions that subQuests fail (even from different MainQuests) - getOwner() + this.getOwner() .getQuestManager() - .triggerEvent( - QuestTrigger.QUEST_CONTENT_QUEST_STATE_EQUAL, + .queueEvent( + QuestContent.QUEST_CONTENT_QUEST_STATE_EQUAL, this.subQuestId, this.state.getValue(), 0, 0, 0); - getOwner() + this.getOwner() .getQuestManager() - .triggerEvent( - QuestTrigger.QUEST_COND_STATE_EQUAL, this.subQuestId, this.state.getValue(), 0, 0, 0); + .queueEvent( + QuestCond.QUEST_COND_STATE_EQUAL, this.subQuestId, this.state.getValue(), 0, 0, 0); + + this.getQuestData() + .getFailExec() + .forEach(e -> getOwner().getServer().getQuestSystem().triggerExec(this, e, e.getParam())); + + if (this.getQuestData().getTrialAvatarList() != null) { + this.getQuestData() + .getTrialAvatarList() + .forEach(t -> this.getOwner().getTeamManager().removeTrialAvatar(t)); + } + + Grasscutter.getLogger().debug("Quest {} is failed", subQuestId); } - // Return true if ParentQuest should rewind to this childQuest - public boolean rewind(GameQuest nextRewind) { - if (questData.isRewind()) { - if (nextRewind == null) { - return true; - } - // if the next isRewind subQuest is none or unstarted, reset all subQuests with order higher - // than this one, and restart this quest - if (nextRewind.getState() == QuestState.QUEST_STATE_NONE - || nextRewind.getState() == QuestState.QUEST_STATE_UNSTARTED) { - getMainQuest().getChildQuests().values().stream() - .filter(p -> p.getQuestData().getOrder() > this.getQuestData().getOrder()) - .forEach(q -> q.setState(QuestState.QUEST_STATE_UNSTARTED)); - this.start(); - return true; - } - } - return false; + // Return true if it did the rewind + public boolean rewind(boolean notifyDelete) { + getMainQuest().getChildQuests().values().stream() + .filter(p -> p.getQuestData().getOrder() > this.getQuestData().getOrder()) + .forEach( + q -> { + q.clearProgress(notifyDelete); + }); + clearProgress(notifyDelete); + this.start(); + return true; } public void save() { diff --git a/src/main/java/emu/grasscutter/game/quest/QuestEncryptionKey.java b/src/main/java/emu/grasscutter/game/quest/QuestEncryptionKey.java index 9d01bbb64..aaca8f831 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestEncryptionKey.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestEncryptionKey.java @@ -1,12 +1,12 @@ -package emu.grasscutter.game.quest; - -import lombok.AccessLevel; -import lombok.Data; -import lombok.experimental.FieldDefaults; - -@Data -@FieldDefaults(level = AccessLevel.PRIVATE) -public class QuestEncryptionKey { - int mainQuestId; - long encryptionKey; -} +package emu.grasscutter.game.quest; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +public class QuestEncryptionKey { + int mainQuestId; + long encryptionKey; +} diff --git a/src/main/java/emu/grasscutter/game/quest/QuestGroupSuite.java b/src/main/java/emu/grasscutter/game/quest/QuestGroupSuite.java index 9865f6d1e..501d55c55 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestGroupSuite.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestGroupSuite.java @@ -1,17 +1,17 @@ -package emu.grasscutter.game.quest; - -import dev.morphia.annotations.Entity; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Data; -import lombok.experimental.FieldDefaults; - -@Entity -@Data -@Builder(builderMethodName = "of") -@FieldDefaults(level = AccessLevel.PRIVATE) -public class QuestGroupSuite { - int scene; - int group; - int suite; -} +package emu.grasscutter.game.quest; + +import dev.morphia.annotations.Entity; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Entity +@Data +@Builder(builderMethodName = "of") +@FieldDefaults(level = AccessLevel.PRIVATE) +public class QuestGroupSuite { + int scene; + int group; + int suite; +} diff --git a/src/main/java/emu/grasscutter/game/quest/QuestManager.java b/src/main/java/emu/grasscutter/game/quest/QuestManager.java index 02fa2c937..23215e74c 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestManager.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestManager.java @@ -8,34 +8,47 @@ import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.player.BasePlayerManager; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.quest.enums.ParentQuestState; +import emu.grasscutter.game.quest.enums.QuestCond; +import emu.grasscutter.game.quest.enums.QuestContent; import emu.grasscutter.game.quest.enums.QuestState; -import emu.grasscutter.game.quest.enums.QuestTrigger; import emu.grasscutter.server.packet.send.PacketFinishedParentQuestUpdateNotify; -import emu.grasscutter.server.packet.send.PacketQuestListUpdateNotify; import emu.grasscutter.utils.Position; +import io.netty.util.concurrent.FastThreadLocalThread; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import lombok.Getter; +import lombok.val; import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; public class QuestManager extends BasePlayerManager { - private static final Set newPlayerMainQuests = Set.of(303, 318, 348, 349, 350, 351, 416, 500, - 501, 502, 503, 504, 505, 506, 507, 508, 509, 20000, 20507, 20509, 21004, 21005, 21010, 21011, 21016, 21017, - 21020, 21021, 21025, 40063, 70121, 70124, 70511, 71010, 71012, 71013, 71015, 71016, 71017, 71555); - @Getter - private final Player player; - @Getter - private final Int2ObjectMap mainQuests; + @Getter private final Player player; + @Getter private final Int2ObjectMap mainQuests; + + private long lastHourCheck = 0; + private long lastDayCheck = 0; + + public static final ExecutorService eventExecutor; + static { + eventExecutor = new ThreadPoolExecutor(4, 4, + 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(1000), + FastThreadLocalThread::new, new ThreadPoolExecutor.AbortPolicy()); + } /* On SetPlayerBornDataReq, the server sends FinishedParentQuestNotify, with this exact parentQuestList. Captured on Game version 2.7 Note: quest 40063 is already set to finished, with childQuest 4006406's state set to 3 */ - @Getter - private final List addToQuestListUpdateNotify; + + private static Set newPlayerMainQuests = Set.of(303,318,348,349,350,351,416,500, + 501,502,503,504,505,506,507,508,509,20000,20507,20509,21004,21005,21010,21011,21016,21017, + 21020,21021,21025,40063,70121,70124,70511,71010,71012,71013,71015,71016,71017,71555); /* On SetPlayerBornDataReq, the server sends ServerCondMeetQuestListUpdateNotify, with this exact @@ -62,74 +75,119 @@ public class QuestManager extends BasePlayerManager { */ + public static long getQuestKey(int mainQuestId) { + QuestEncryptionKey questEncryptionKey = GameData.getMainQuestEncryptionMap().get(mainQuestId); + return questEncryptionKey != null ? questEncryptionKey.getEncryptionKey() : 0L; + } public QuestManager(Player player) { super(player); this.player = player; this.mainQuests = new Int2ObjectOpenHashMap<>(); - this.addToQuestListUpdateNotify = new ArrayList<>(); } - public static long getQuestKey(int mainQuestId) { - QuestEncryptionKey questEncryptionKey = GameData.getMainQuestEncryptionMap().get(mainQuestId); - return questEncryptionKey != null ? questEncryptionKey.getEncryptionKey() : 0L; - } - - public void onNewPlayerCreate() { + public void onPlayerBorn() { + // TODO scan the quest and start the quest with acceptCond fulfilled + // The off send 3 request in that order: 1. FinishedParentQuestNotify, 2. QuestListNotify, 3. ServerCondMeetQuestListUpdateNotify List newQuests = this.addMultMainQuests(newPlayerMainQuests); - //getPlayer().sendPacket(new PacketServerCondMeetQuestListUpdateNotify(newPlayerServerCondMeetQuestListUpdateNotify)); + for (GameMainQuest mainQuest : newQuests) { + startMainQuest(mainQuest.getParentQuestId()); + } + //getPlayer().sendPacket(new PacketFinishedParentQuestUpdateNotify(newQuests)); - - + //getPlayer().sendPacket(new PacketQuestListNotify(subQuests)); + //getPlayer().sendPacket(new PacketServerCondMeetQuestListUpdateNotify(newPlayerServerCondMeetQuestListUpdateNotify)); } public void onLogin() { List activeQuests = getActiveMainQuests(); + List activeSubs = new ArrayList<>(activeQuests.size()); for (GameMainQuest quest : activeQuests) { List rewindPos = quest.rewind(); // + var activeQuest = quest.getActiveQuests(); if (rewindPos != null) { getPlayer().getPosition().set(rewindPos.get(0)); getPlayer().getRotation().set(rewindPos.get(1)); } + if(activeQuest!=null && rewindPos!=null){ + //activeSubs.add(activeQuest); + //player.sendPacket(new PacketQuestProgressUpdateNotify(activeQuest)); + } + quest.checkProgress(); } } + public void onTick(){ + checkTimeVars(); + + // trigger game time tick for quests + queueEvent(QuestContent.QUEST_CONTENT_GAME_TIME_TICK, + player.getWorld().getGameTimeHours() , // hours + 0); + } + + private void checkTimeVars(){ + val currentDays = player.getWorld().getTotalGameTimeDays(); + val currentHours = player.getWorld().getTotalGameTimeHours(); + boolean checkDays = currentDays != lastDayCheck; + boolean checkHours = currentHours != lastHourCheck; + + if(!checkDays && !checkHours){ + return; + } + + this.lastDayCheck = currentDays; + this.lastHourCheck = currentHours; + player.getActiveQuestTimers().forEach(mainQuestId -> { + if(checkHours) { + queueEvent(QuestCond.QUEST_COND_TIME_VAR_GT_EQ, mainQuestId); + queueEvent(QuestContent.QUEST_CONTENT_TIME_VAR_GT_EQ, mainQuestId); + } + if(checkDays) { + queueEvent(QuestCond.QUEST_COND_TIME_VAR_PASS_DAY, mainQuestId); + queueEvent(QuestContent.QUEST_CONTENT_TIME_VAR_PASS_DAY, mainQuestId); + } + }); + } + private List addMultMainQuests(Set mainQuestIds) { List newQuests = new ArrayList<>(); for (Integer id : mainQuestIds) { - getMainQuests().put(id.intValue(), new GameMainQuest(this.player, id)); + getMainQuests().put(id.intValue(),new GameMainQuest(this.player, id)); getMainQuestById(id).save(); newQuests.add(getMainQuestById(id)); } return newQuests; } + public void enableQuests() { + onPlayerBorn(); + } + /* Looking through mainQuests 72201-72208 and 72174, we can infer that a questGlobalVar's default value is 0 */ public Integer getQuestGlobalVarValue(Integer variable) { - return getPlayer().getQuestGlobalVariables().getOrDefault(variable, 0); + return getPlayer().getQuestGlobalVariables().getOrDefault(variable,0); } public void setQuestGlobalVarValue(Integer variable, Integer value) { - Integer previousValue = getPlayer().getQuestGlobalVariables().put(variable, value); - Grasscutter.getLogger().debug("Changed questGlobalVar {} value from {} to {}", variable, previousValue == null ? 0 : previousValue, value); + Integer previousValue = getPlayer().getQuestGlobalVariables().put(variable,value); + Grasscutter.getLogger().debug("Changed questGlobalVar {} value from {} to {}", variable, previousValue==null ? 0: previousValue, value); } - public void incQuestGlobalVarValue(Integer variable, Integer inc) { // - Integer previousValue = getPlayer().getQuestGlobalVariables().getOrDefault(variable, 0); - getPlayer().getQuestGlobalVariables().put(variable, previousValue + inc); + Integer previousValue = getPlayer().getQuestGlobalVariables().getOrDefault(variable,0); + getPlayer().getQuestGlobalVariables().put(variable,previousValue + inc); Grasscutter.getLogger().debug("Incremented questGlobalVar {} value from {} to {}", variable, previousValue, previousValue + inc); } - //In MainQuest 998, dec is passed as a positive integer public void decQuestGlobalVarValue(Integer variable, Integer dec) { // - Integer previousValue = getPlayer().getQuestGlobalVariables().getOrDefault(variable, 0); - getPlayer().getQuestGlobalVariables().put(variable, previousValue - dec); + Integer previousValue = getPlayer().getQuestGlobalVariables().getOrDefault(variable,0); + getPlayer().getQuestGlobalVariables().put(variable,previousValue - dec); Grasscutter.getLogger().debug("Decremented questGlobalVar {} value from {} to {}", variable, previousValue, previousValue - dec); } @@ -137,6 +195,11 @@ public class QuestManager extends BasePlayerManager { return getMainQuests().get(mainQuestId); } + public GameMainQuest getMainQuestByTalkId(int talkId) { + int mainQuestId = GameData.getQuestTalkMap().getOrDefault(talkId, talkId / 100); + return getMainQuestById(mainQuestId); + } + public GameQuest getQuestById(int questId) { QuestData questConfig = GameData.getQuestDataMap().get(questId); if (questConfig == null) { @@ -188,6 +251,7 @@ public class QuestManager extends BasePlayerManager { public GameQuest addQuest(int questId) { QuestData questConfig = GameData.getQuestDataMap().get(questId); + if (questConfig == null) { return null; } @@ -205,14 +269,7 @@ public class QuestManager extends BasePlayerManager { // Forcefully start quest.start(); - - // Save main quest - mainQuest.save(); - - // Send packet - getPlayer().sendPacket(new PacketQuestListUpdateNotify(mainQuest.getChildQuests().values().stream() - .filter(p -> p.getState() != QuestState.QUEST_STATE_UNSTARTED) - .toList())); + checkQuestAlreadyFullfilled(quest); return quest; } @@ -228,84 +285,79 @@ public class QuestManager extends BasePlayerManager { .min(Comparator.comparingInt(MainQuestData.SubQuestData::getOrder)) .map(MainQuestData.SubQuestData::getSubId) .ifPresent(this::addQuest); + //TODO find a better way then hardcoding to detect needed required quests + if(mainQuestId == 355){ + startMainQuest(361); + startMainQuest(418); + startMainQuest(423); + startMainQuest(20509); + + } + } + public void queueEvent(QuestCond condType, int... params) { + queueEvent(condType, "", params); + } + public void queueEvent(QuestContent condType, int... params) { + queueEvent(condType, "", params); } - public void triggerEvent(QuestTrigger condType, int... params) { - triggerEvent(condType, "", params); + public void queueEvent(QuestContent condType, String paramStr, int... params) { + eventExecutor.submit(() -> triggerEvent(condType, paramStr, params)); + } + public void queueEvent(QuestCond condType, String paramStr, int... params) { + eventExecutor.submit(() -> triggerEvent(condType, paramStr, params)); } - //TODO - public void triggerEvent(QuestTrigger condType, String paramStr, int... params) { + //QUEST_EXEC are handled directly by each subQuest + + public void triggerEvent(QuestCond condType, String paramStr, int... params) { Grasscutter.getLogger().debug("Trigger Event {}, {}, {}", condType, paramStr, params); List checkMainQuests = this.getMainQuests().values().stream() .filter(i -> i.getState() != ParentQuestState.PARENT_QUEST_STATE_FINISHED) .toList(); - switch (condType) { - //accept Conds - case QUEST_COND_STATE_EQUAL: - case QUEST_COND_STATE_NOT_EQUAL: - case QUEST_COND_COMPLETE_TALK: - case QUEST_COND_LUA_NOTIFY: - case QUEST_COND_QUEST_VAR_EQUAL: - case QUEST_COND_QUEST_VAR_GREATER: - case QUEST_COND_QUEST_VAR_LESS: - case QUEST_COND_PLAYER_LEVEL_EQUAL_GREATER: - case QUEST_COND_QUEST_GLOBAL_VAR_EQUAL: - case QUEST_COND_QUEST_GLOBAL_VAR_GREATER: - case QUEST_COND_QUEST_GLOBAL_VAR_LESS: - for (GameMainQuest mainquest : checkMainQuests) { - mainquest.tryAcceptSubQuests(condType, paramStr, params); - } - break; - - //fail Conds - case QUEST_CONTENT_NOT_FINISH_PLOT: - for (GameMainQuest mainquest : checkMainQuests) { - mainquest.tryFailSubQuests(condType, paramStr, params); - } - break; - //finish Conds - case QUEST_CONTENT_COMPLETE_TALK: - case QUEST_CONTENT_FINISH_PLOT: - case QUEST_CONTENT_COMPLETE_ANY_TALK: - case QUEST_CONTENT_LUA_NOTIFY: - case QUEST_CONTENT_QUEST_VAR_EQUAL: - case QUEST_CONTENT_QUEST_VAR_GREATER: - case QUEST_CONTENT_QUEST_VAR_LESS: - case QUEST_CONTENT_ENTER_DUNGEON: - case QUEST_CONTENT_ENTER_ROOM: - case QUEST_CONTENT_INTERACT_GADGET: - case QUEST_CONTENT_TRIGGER_FIRE: - case QUEST_CONTENT_UNLOCK_TRANS_POINT: - case QUEST_CONTENT_SKILL: - for (GameMainQuest mainQuest : checkMainQuests) { - mainQuest.tryFinishSubQuests(condType, paramStr, params); - } - break; - - //finish Or Fail Conds - case QUEST_CONTENT_GAME_TIME_TICK: - case QUEST_CONTENT_QUEST_STATE_EQUAL: - case QUEST_CONTENT_ADD_QUEST_PROGRESS: - case QUEST_CONTENT_LEAVE_SCENE: - for (GameMainQuest mainQuest : checkMainQuests) { - mainQuest.tryFailSubQuests(condType, paramStr, params); - mainQuest.tryFinishSubQuests(condType, paramStr, params); - } - break; - //QUEST_EXEC are handled directly by each subQuest - - //Unused - case QUEST_CONTENT_QUEST_STATE_NOT_EQUAL: - case QUEST_COND_PLAYER_CHOOSE_MALE: - default: - Grasscutter.getLogger().error("Unhandled QuestTrigger {}", condType); + for (GameMainQuest mainquest : checkMainQuests) { + mainquest.tryAcceptSubQuests(condType, paramStr, params); } - if (this.addToQuestListUpdateNotify.size() != 0) { - this.getPlayer().getSession().send(new PacketQuestListUpdateNotify(this.addToQuestListUpdateNotify)); - this.addToQuestListUpdateNotify.clear(); + } + public void triggerEvent(QuestContent condType, String paramStr, int... params) { + Grasscutter.getLogger().debug("Trigger Event {}, {}, {}", condType, paramStr, params); + List checkMainQuests = this.getMainQuests().values().stream() + .filter(i -> i.getState() != ParentQuestState.PARENT_QUEST_STATE_FINISHED) + .toList(); + for (GameMainQuest mainQuest : checkMainQuests) { + mainQuest.tryFailSubQuests(condType, paramStr, params); + mainQuest.tryFinishSubQuests(condType, paramStr, params); } + } + /** + * TODO maybe trigger them delayed to allow basic communication finish first + * @param quest + */ + public void checkQuestAlreadyFullfilled(GameQuest quest){ + Grasscutter.getGameServer().getScheduler().scheduleDelayedTask(() -> { + for(var condition : quest.getQuestData().getFinishCond()){ + switch (condition.getType()) { + case QUEST_CONTENT_OBTAIN_ITEM, QUEST_CONTENT_ITEM_LESS_THAN -> { + //check if we already own enough of the item + var item = getPlayer().getInventory().getItemByGuid(condition.getParam()[0]); + queueEvent(condition.getType(), condition.getParam()[0], item != null ? item.getCount() : 0); + } + case QUEST_CONTENT_UNLOCK_TRANS_POINT -> { + var scenePoints = getPlayer().getUnlockedScenePoints().get(condition.getParam()[0]); + if (scenePoints != null && scenePoints.contains(condition.getParam()[1])) { + queueEvent(condition.getType(), condition.getParam()[0], condition.getParam()[1]); + } + } + case QUEST_CONTENT_UNLOCK_AREA -> { + var sceneAreas = getPlayer().getUnlockedSceneAreas().get(condition.getParam()[0]); + if (sceneAreas != null && sceneAreas.contains(condition.getParam()[1])) { + queueEvent(condition.getType(), condition.getParam()[0], condition.getParam()[1]); + } + } + } + } + }, 1); } public List getSceneGroupSuite(int sceneId) { @@ -317,7 +369,6 @@ public class QuestManager extends BasePlayerManager { .filter(i -> i.getScene() == sceneId) .toList(); } - public void loadFromDatabase() { List quests = DatabaseHelper.getAllQuests(getPlayer()); diff --git a/src/main/java/emu/grasscutter/game/quest/QuestSystem.java b/src/main/java/emu/grasscutter/game/quest/QuestSystem.java index b6e32a447..6a4443b95 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestSystem.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestSystem.java @@ -1,9 +1,13 @@ package emu.grasscutter.game.quest; import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.excels.QuestData.QuestCondition; +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.data.excels.QuestData.QuestAcceptCondition; +import emu.grasscutter.data.excels.QuestData.QuestContentCondition; import emu.grasscutter.data.excels.QuestData.QuestExecParam; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.conditions.BaseCondition; +import emu.grasscutter.game.quest.content.BaseContent; import emu.grasscutter.game.quest.handlers.QuestExecHandler; import emu.grasscutter.server.game.BaseGameSystem; import emu.grasscutter.server.game.GameServer; @@ -13,8 +17,8 @@ import org.reflections.Reflections; @SuppressWarnings("unchecked") public class QuestSystem extends BaseGameSystem { - private final Int2ObjectMap condHandlers; - private final Int2ObjectMap contHandlers; + private final Int2ObjectMap condHandlers; + private final Int2ObjectMap contHandlers; private final Int2ObjectMap execHandlers; public QuestSystem(GameServer server) { @@ -29,9 +33,9 @@ public class QuestSystem extends BaseGameSystem { public void registerHandlers() { this.registerHandlers( - this.condHandlers, "emu.grasscutter.game.quest.conditions", QuestBaseHandler.class); + this.condHandlers, "emu.grasscutter.game.quest.conditions", BaseCondition.class); this.registerHandlers( - this.contHandlers, "emu.grasscutter.game.quest.content", QuestBaseHandler.class); + this.contHandlers, "emu.grasscutter.game.quest.content", BaseContent.class); this.registerHandlers( this.execHandlers, "emu.grasscutter.game.quest.exec", QuestExecHandler.class); } @@ -47,13 +51,25 @@ public class QuestSystem extends BaseGameSystem { public void registerPacketHandler(Int2ObjectMap map, Class handlerClass) { try { - QuestValue opcode = handlerClass.getAnnotation(QuestValue.class); - - if (opcode == null || opcode.value().getValue() <= 0) { + int value = 0; + if (handlerClass.isAnnotationPresent(QuestValueExec.class)) { + QuestValueExec opcode = handlerClass.getAnnotation(QuestValueExec.class); + value = opcode.value().getValue(); + } else if (handlerClass.isAnnotationPresent(QuestValueContent.class)) { + QuestValueContent opcode = handlerClass.getAnnotation(QuestValueContent.class); + value = opcode.value().getValue(); + } else if (handlerClass.isAnnotationPresent(QuestValueCond.class)) { + QuestValueCond opcode = handlerClass.getAnnotation(QuestValueCond.class); + value = opcode.value().getValue(); + } else { return; } - map.put(opcode.value().getValue(), handlerClass.getDeclaredConstructor().newInstance()); + if (value <= 0) { + return; + } + + map.put(value, handlerClass.getDeclaredConstructor().newInstance()); } catch (Exception e) { e.printStackTrace(); } @@ -62,24 +78,25 @@ public class QuestSystem extends BaseGameSystem { // TODO make cleaner public boolean triggerCondition( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { - QuestBaseHandler handler = condHandlers.get(condition.getType().getValue()); + Player owner, + QuestData questData, + QuestAcceptCondition condition, + String paramStr, + int... params) { + BaseCondition handler = condHandlers.get(condition.getType().getValue()); - if (handler == null || quest.getQuestData() == null) { + if (handler == null || questData == null) { Grasscutter.getLogger() - .debug( - "Could not trigger condition {} at {}", - condition.getType().getValue(), - quest.getQuestData()); + .debug("Could not trigger condition {} at {}", condition.getType().getValue(), questData); return false; } - return handler.execute(quest, condition, paramStr, params); + return handler.execute(owner, questData, condition, paramStr, params); } public boolean triggerContent( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { - QuestBaseHandler handler = contHandlers.get(condition.getType().getValue()); + GameQuest quest, QuestContentCondition condition, String paramStr, int... params) { + BaseContent handler = contHandlers.get(condition.getType().getValue()); if (handler == null || quest.getQuestData() == null) { Grasscutter.getLogger() @@ -93,7 +110,7 @@ public class QuestSystem extends BaseGameSystem { return handler.execute(quest, condition, paramStr, params); } - public boolean triggerExec(GameQuest quest, QuestExecParam execParam, String... params) { + public void triggerExec(GameQuest quest, QuestExecParam execParam, String... params) { QuestExecHandler handler = execHandlers.get(execParam.getType().getValue()); if (handler == null || quest.getQuestData() == null) { @@ -102,9 +119,18 @@ public class QuestSystem extends BaseGameSystem { "Could not trigger exec {} at {}", execParam.getType().getValue(), quest.getQuestData()); - return false; + return; } - return handler.execute(quest, execParam, params); + QuestManager.eventExecutor.submit( + () -> { + if (!handler.execute(quest, execParam, params)) { + Grasscutter.getLogger() + .debug( + "exec trigger failed {} at {}", + execParam.getType().getValue(), + quest.getQuestData()); + } + }); } } diff --git a/src/main/java/emu/grasscutter/game/quest/QuestValueCond.java b/src/main/java/emu/grasscutter/game/quest/QuestValueCond.java index 3701a9fa0..c5d1723d0 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestValueCond.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestValueCond.java @@ -1,11 +1,10 @@ -package emu.grasscutter.game.quest; - -import emu.grasscutter.game.quest.enums.QuestCond; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Retention(RetentionPolicy.RUNTIME) -public @interface QuestValueCond { - QuestCond value(); -} +package emu.grasscutter.game.quest; + +import emu.grasscutter.game.quest.enums.QuestCond; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface QuestValueCond { + QuestCond value(); +} diff --git a/src/main/java/emu/grasscutter/game/quest/QuestValueContent.java b/src/main/java/emu/grasscutter/game/quest/QuestValueContent.java index 751db4a55..103ca8cde 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestValueContent.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestValueContent.java @@ -1,11 +1,10 @@ -package emu.grasscutter.game.quest; - -import emu.grasscutter.game.quest.enums.QuestContent; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Retention(RetentionPolicy.RUNTIME) -public @interface QuestValueContent { - QuestContent value(); -} +package emu.grasscutter.game.quest; + +import emu.grasscutter.game.quest.enums.QuestContent; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface QuestValueContent { + QuestContent value(); +} diff --git a/src/main/java/emu/grasscutter/game/quest/QuestValueExec.java b/src/main/java/emu/grasscutter/game/quest/QuestValueExec.java index bd5f0ffcc..8324fc0c8 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestValueExec.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestValueExec.java @@ -1,11 +1,10 @@ -package emu.grasscutter.game.quest; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import emu.grasscutter.game.quest.enums.QuestExec; - -@Retention(RetentionPolicy.RUNTIME) -public @interface QuestValueExec { - QuestExec value(); -} +package emu.grasscutter.game.quest; + +import emu.grasscutter.game.quest.enums.QuestExec; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface QuestValueExec { + QuestExec value(); +} diff --git a/src/main/java/emu/grasscutter/game/quest/RewindData.java b/src/main/java/emu/grasscutter/game/quest/RewindData.java index 7769fd773..5d8b4cdc3 100644 --- a/src/main/java/emu/grasscutter/game/quest/RewindData.java +++ b/src/main/java/emu/grasscutter/game/quest/RewindData.java @@ -15,7 +15,7 @@ public class RewindData { } @Data - private static class Npc { + public static class Npc { private String script; private int room_id; private int data_index; diff --git a/src/main/java/emu/grasscutter/game/quest/TeleportData.java b/src/main/java/emu/grasscutter/game/quest/TeleportData.java index 83c143f5c..1b789f423 100644 --- a/src/main/java/emu/grasscutter/game/quest/TeleportData.java +++ b/src/main/java/emu/grasscutter/game/quest/TeleportData.java @@ -1,35 +1,35 @@ -package emu.grasscutter.game.quest; - -import java.util.List; -import lombok.Data; - -@Data -public class TeleportData { - List transmit_points; - List npcs; - List gadgets; - - @Data - public static class TransmitPoint { - private int point_id; - private int scene_id; - private String pos; - } - - @Data - public static class Npc { - private int data_index; - private int room_id; - private int scene_id; - private int id; - private String alias; - private String script; - private String pos; - } - - @Data - public static class Gadget { - private int id; - private String pos; - } -} +package emu.grasscutter.game.quest; + +import java.util.List; +import lombok.Data; + +@Data +public class TeleportData { + List transmit_points; + List npcs; + List gadgets; + + @Data + public static class TransmitPoint { + private int point_id; + private int scene_id; + private String pos; + } + + @Data + public static class Npc { + private int data_index; + private int room_id; + private int scene_id; + private int id; + private String alias; + private String script; + private String pos; + } + + @Data + public static class Gadget { + private int id; + private String pos; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/BaseCondition.java b/src/main/java/emu/grasscutter/game/quest/conditions/BaseCondition.java index 262bbe8eb..9f789f9d1 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/BaseCondition.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/BaseCondition.java @@ -1,18 +1,20 @@ package emu.grasscutter.game.quest.conditions; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_UNKNOWN; -@QuestValue(QuestTrigger.QUEST_CONTENT_NONE) -public class BaseCondition extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; + +@QuestValueCond(QUEST_COND_UNKNOWN) +public class BaseCondition { - @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { - // TODO Auto-generated method stub + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { return false; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/BaseConditionQuestVar.java b/src/main/java/emu/grasscutter/game/quest/conditions/BaseConditionQuestVar.java index 9d94317c7..12b569862 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/BaseConditionQuestVar.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/BaseConditionQuestVar.java @@ -1,40 +1,49 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import lombok.val; - -public abstract class BaseConditionQuestVar extends BaseCondition { - - protected abstract boolean doCompare(int variable, int cond); - - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val index = condition.getParam()[0]; - val targetValue = condition.getParam()[1]; - val questVarValue = getQuestVar(owner, questData, index); - - Grasscutter.getLogger().debug("questVar {} : {}", index, questVarValue); - - if (questVarValue < 0) { - return false; - } - return doCompare(questVarValue, targetValue); - } - - protected int getQuestVar(Player owner, QuestData questData, int index) { - val mainQuest = owner.getQuestManager().getMainQuestById(questData.getMainId()); - if (mainQuest == null) { - Grasscutter.getLogger().debug("mainQuest for quest var not available yet"); - return -1; - } - val questVars = mainQuest.getQuestVars(); - if (index >= questVars.length) { - Grasscutter.getLogger().error("questVar out of bounds for {} index {} size {}", questData.getSubId(), index, questVars.length); - return -2; - } - return questVars[index]; - } - -} +package emu.grasscutter.game.quest.conditions; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import lombok.val; + +public abstract class BaseConditionQuestVar extends BaseCondition { + + protected abstract boolean doCompare(int variable, int cond); + + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val index = condition.getParam()[0]; + val targetValue = condition.getParam()[1]; + val questVarValue = getQuestVar(owner, questData, index); + + Grasscutter.getLogger().debug("questVar {} : {}", index, questVarValue); + + if (questVarValue < 0) { + return false; + } + return doCompare(questVarValue, targetValue); + } + + protected int getQuestVar(Player owner, QuestData questData, int index) { + val mainQuest = owner.getQuestManager().getMainQuestById(questData.getMainId()); + if (mainQuest == null) { + Grasscutter.getLogger().debug("mainQuest for quest var not available yet"); + return -1; + } + val questVars = mainQuest.getQuestVars(); + if (index >= questVars.length) { + Grasscutter.getLogger() + .error( + "questVar out of bounds for {} index {} size {}", + questData.getSubId(), + index, + questVars.length); + return -2; + } + return questVars[index]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityCond.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityCond.java index 4ec0603d5..4421a4d11 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityCond.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityCond.java @@ -1,20 +1,24 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import lombok.val; - -import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_ACTIVITY_COND; - -@QuestValueCond(QUEST_COND_ACTIVITY_COND) -public class ConditionActivityCond extends BaseCondition { - - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val activityCondId = condition.getParam()[0]; - val targetState = condition.getParam()[1]; // only 1 for now - return owner.getActivityManager().meetsCondition(activityCondId) == (targetState == 1); - } - -} +package emu.grasscutter.game.quest.conditions; + +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_ACTIVITY_COND; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; + +@QuestValueCond(QUEST_COND_ACTIVITY_COND) +public class ConditionActivityCond extends BaseCondition { + + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val activityCondId = condition.getParam()[0]; + val targetState = condition.getParam()[1]; // only 1 for now + return owner.getActivityManager().meetsCondition(activityCondId) == (targetState == 1); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityEnd.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityEnd.java index 34c31be7f..b218aef93 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityEnd.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityEnd.java @@ -1,19 +1,23 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import lombok.val; - -import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_ACTIVITY_END; - -@QuestValueCond(QUEST_COND_ACTIVITY_END) -public class ConditionActivityEnd extends BaseCondition { - - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val activityId = condition.getParam()[0]; - return owner.getActivityManager().hasActivityEnded(activityId); - } - -} +package emu.grasscutter.game.quest.conditions; + +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_ACTIVITY_END; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; + +@QuestValueCond(QUEST_COND_ACTIVITY_END) +public class ConditionActivityEnd extends BaseCondition { + + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val activityId = condition.getParam()[0]; + return owner.getActivityManager().hasActivityEnded(activityId); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityOpen.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityOpen.java index 10d857261..2e509be06 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityOpen.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionActivityOpen.java @@ -1,19 +1,23 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import lombok.val; - -import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_ACTIVITY_OPEN; - -@QuestValueCond(QUEST_COND_ACTIVITY_OPEN) -public class ConditionActivityOpen extends BaseCondition { - - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val activityId = condition.getParam()[0]; - return owner.getActivityManager().isActivityActive(activityId); - } - -} +package emu.grasscutter.game.quest.conditions; + +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_ACTIVITY_OPEN; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; + +@QuestValueCond(QUEST_COND_ACTIVITY_OPEN) +public class ConditionActivityOpen extends BaseCondition { + + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val activityId = condition.getParam()[0]; + return owner.getActivityManager().isActivityActive(activityId); + } +} 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 d80be6cb4..856a8c3b9 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionCompleteTalk.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionCompleteTalk.java @@ -1,33 +1,35 @@ 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.binout.MainQuestData; import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameMainQuest; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; -@QuestValue(QuestTrigger.QUEST_COND_COMPLETE_TALK) -public class ConditionCompleteTalk extends QuestBaseHandler { +@QuestValueCond(QUEST_COND_COMPLETE_TALK) +public class ConditionCompleteTalk extends BaseCondition { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { - GameMainQuest checkMainQuest = - quest.getOwner().getQuestManager().getMainQuestById(condition.getParam()[0] / 100); + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + 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", - condition.getParam()[0] / 100); + .debug("Warning: mainQuest {} hasn't been started yet, or has no talks", talkId / 100); return false; } - MainQuestData.TalkData talkData = checkMainQuest.getTalks().get(Integer.valueOf(params[0])); - return talkData != null || checkMainQuest.getChildQuestById(params[0]) != null; + val talkData = checkMainQuest.getTalks().get(talkId); + return talkData != null || checkMainQuest.getChildQuestById(talkId) != null; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionHistoryGotAnyItem.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionHistoryGotAnyItem.java index bc8997326..8457cfe7f 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionHistoryGotAnyItem.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionHistoryGotAnyItem.java @@ -1,18 +1,22 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import emu.grasscutter.game.quest.enums.QuestCond; -import lombok.val; - -@QuestValueCond(QuestCond.QUEST_COND_HISTORY_GOT_ANY_ITEM) -public class ConditionHistoryGotAnyItem extends BaseCondition { - - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val itemId = condition.getParam()[0]; - return owner.getPlayerProgress().hasPlayerObtainedItemHistorically(itemId); - } - -} +package emu.grasscutter.game.quest.conditions; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import emu.grasscutter.game.quest.enums.QuestCond; +import lombok.val; + +@QuestValueCond(QuestCond.QUEST_COND_HISTORY_GOT_ANY_ITEM) +public class ConditionHistoryGotAnyItem extends BaseCondition { + + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val itemId = condition.getParam()[0]; + return owner.getPlayerProgress().hasPlayerObtainedItemHistorically(itemId); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionIsDaytime.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionIsDaytime.java index c51c9398d..ca0430c4d 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionIsDaytime.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionIsDaytime.java @@ -1,20 +1,24 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import emu.grasscutter.game.quest.enums.QuestCond; -import lombok.val; - -@QuestValueCond(QuestCond.QUEST_COND_IS_DAYTIME) -public class ConditionIsDaytime extends BaseCondition{ - - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val daytime = condition.getParam()[0] == 1; - val currentTime = owner.getWorld().getGameTimeHours(); - // TODO is this the real timeframe? - return (currentTime >=6 && currentTime<=18) == daytime; - } - -} +package emu.grasscutter.game.quest.conditions; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import emu.grasscutter.game.quest.enums.QuestCond; +import lombok.val; + +@QuestValueCond(QuestCond.QUEST_COND_IS_DAYTIME) +public class ConditionIsDaytime extends BaseCondition { + + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val daytime = condition.getParam()[0] == 1; + val currentTime = owner.getWorld().getGameTimeHours(); + // TODO is this the real timeframe? + return (currentTime >= 6 && currentTime <= 18) == daytime; + } +} 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 3c4d6b7c2..61bbdc93b 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionItemNumLessThan.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionItemNumLessThan.java @@ -1,21 +1,25 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import lombok.val; - -import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_ITEM_NUM_LESS_THAN; - -@QuestValueCond(QUEST_COND_ITEM_NUM_LESS_THAN) -public class ConditionItemNumLessThan extends BaseCondition { - - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, 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; - } - -} +package emu.grasscutter.game.quest.conditions; + +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_ITEM_NUM_LESS_THAN; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; + +@QuestValueCond(QUEST_COND_ITEM_NUM_LESS_THAN) +public class ConditionItemNumLessThan extends BaseCondition { + + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + 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; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionLuaNotify.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionLuaNotify.java index 71f0a4f70..f87d893c7 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionLuaNotify.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionLuaNotify.java @@ -1,17 +1,24 @@ package emu.grasscutter.game.quest.conditions; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_LUA_NOTIFY; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; + +@QuestValueCond(QUEST_COND_LUA_NOTIFY) +public class ConditionLuaNotify extends BaseCondition { -@QuestValue(QuestTrigger.QUEST_COND_LUA_NOTIFY) -public class ConditionLuaNotify extends QuestBaseHandler { - // Wrong implementation. Example: 7010226 has no paramStr @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == Integer.parseInt(paramStr); + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val triggerId = Integer.parseInt(paramStr); + val targetTrigger = condition.getParam()[0]; + return targetTrigger == triggerId; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionNone.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionNone.java index 23dd4a07a..4477a8c51 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionNone.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionNone.java @@ -1,16 +1,20 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import emu.grasscutter.game.quest.enums.QuestCond; - -@QuestValueCond(QuestCond.QUEST_COND_NONE) -public class ConditionNone extends BaseCondition{ - - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - return true; - } - -} +package emu.grasscutter.game.quest.conditions; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import emu.grasscutter.game.quest.enums.QuestCond; + +@QuestValueCond(QuestCond.QUEST_COND_NONE) +public class ConditionNone extends BaseCondition { + + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + return true; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionOpenStateEqual.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionOpenStateEqual.java index 1869f7e48..0ea6f7382 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionOpenStateEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionOpenStateEqual.java @@ -1,19 +1,23 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import emu.grasscutter.game.quest.enums.QuestCond; -import lombok.val; - -@QuestValueCond(QuestCond.QUEST_COND_OPEN_STATE_EQUAL) -public class ConditionOpenStateEqual extends BaseCondition { - - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val openStateId = condition.getParam()[0]; - val requiredState = condition.getParam()[1]; - return owner.getProgressManager().getOpenState(openStateId) == requiredState; - } - -} +package emu.grasscutter.game.quest.conditions; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import emu.grasscutter.game.quest.enums.QuestCond; +import lombok.val; + +@QuestValueCond(QuestCond.QUEST_COND_OPEN_STATE_EQUAL) +public class ConditionOpenStateEqual extends BaseCondition { + + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val openStateId = condition.getParam()[0]; + val requiredState = condition.getParam()[1]; + return owner.getProgressManager().getOpenState(openStateId) == requiredState; + } +} 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 86e40bf33..003b5e59c 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPackHaveItem.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPackHaveItem.java @@ -1,21 +1,25 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import lombok.val; - -import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_PACK_HAVE_ITEM; - -@QuestValueCond(QUEST_COND_PACK_HAVE_ITEM) -public class ConditionPackHaveItem extends BaseCondition { - - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, 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; - } - -} +package emu.grasscutter.game.quest.conditions; + +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_PACK_HAVE_ITEM; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; + +@QuestValueCond(QUEST_COND_PACK_HAVE_ITEM) +public class ConditionPackHaveItem extends BaseCondition { + + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + 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; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPersonalLineUnlock.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPersonalLineUnlock.java index 739420cb2..38f012171 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPersonalLineUnlock.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPersonalLineUnlock.java @@ -1,18 +1,22 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import emu.grasscutter.game.quest.enums.QuestCond; -import lombok.val; - -@QuestValueCond(QuestCond.QUEST_COND_PERSONAL_LINE_UNLOCK) -public class ConditionPersonalLineUnlock extends BaseCondition { - - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val personalLineId = condition.getParam()[0]; - return owner.getPersonalLineList().contains(personalLineId); - } - -} +package emu.grasscutter.game.quest.conditions; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import emu.grasscutter.game.quest.enums.QuestCond; +import lombok.val; + +@QuestValueCond(QuestCond.QUEST_COND_PERSONAL_LINE_UNLOCK) +public class ConditionPersonalLineUnlock extends BaseCondition { + + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val personalLineId = condition.getParam()[0]; + return owner.getPersonalLineList().contains(personalLineId); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPlayerLevelEqualGreater.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPlayerLevelEqualGreater.java index da8420f31..4a4f2b8da 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPlayerLevelEqualGreater.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionPlayerLevelEqualGreater.java @@ -1,17 +1,23 @@ package emu.grasscutter.game.quest.conditions; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_PLAYER_LEVEL_EQUAL_GREATER; -@QuestValue(QuestTrigger.QUEST_COND_PLAYER_LEVEL_EQUAL_GREATER) -public class ConditionPlayerLevelEqualGreater extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; + +@QuestValueCond(QUEST_COND_PLAYER_LEVEL_EQUAL_GREATER) +public class ConditionPlayerLevelEqualGreater extends BaseCondition { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { - return quest.getOwner().getLevel() >= params[0]; + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val minLevel = condition.getParam()[0]; + return owner.getLevel() >= minLevel; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarEqual.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarEqual.java index 696dbf7a2..86cb25367 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarEqual.java @@ -1,21 +1,28 @@ package emu.grasscutter.game.quest.conditions; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_QUEST_GLOBAL_VAR_EQUAL; + import emu.grasscutter.Grasscutter; import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; -@QuestValue(QuestTrigger.QUEST_COND_QUEST_GLOBAL_VAR_EQUAL) -public class ConditionQuestGlobalVarEqual extends QuestBaseHandler { +@QuestValueCond(QUEST_COND_QUEST_GLOBAL_VAR_EQUAL) +public class ConditionQuestGlobalVarEqual extends BaseCondition { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { - Integer questGlobalVarValue = - quest.getMainQuest().getQuestManager().getQuestGlobalVarValue(Integer.valueOf(params[0])); - Grasscutter.getLogger().debug("questGlobarVar {} : {}", params[0], questGlobalVarValue); - return questGlobalVarValue.intValue() == params[1]; + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val questId = condition.getParam()[0]; + val targetValue = condition.getParam()[1]; + Integer questGlobalVarValue = owner.getQuestManager().getQuestGlobalVarValue(questId); + Grasscutter.getLogger() + .debug("questGlobarVar {} {} : {}", questId, targetValue, questGlobalVarValue); + return questGlobalVarValue == targetValue; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarGreater.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarGreater.java index 098b27a6a..debc8dad5 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarGreater.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarGreater.java @@ -1,21 +1,28 @@ package emu.grasscutter.game.quest.conditions; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_QUEST_GLOBAL_VAR_GREATER; + import emu.grasscutter.Grasscutter; import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; -@QuestValue(QuestTrigger.QUEST_COND_QUEST_GLOBAL_VAR_GREATER) -public class ConditionQuestGlobalVarGreater extends QuestBaseHandler { +@QuestValueCond(QUEST_COND_QUEST_GLOBAL_VAR_GREATER) +public class ConditionQuestGlobalVarGreater extends BaseCondition { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { - Integer questGlobalVarValue = - quest.getMainQuest().getQuestManager().getQuestGlobalVarValue(Integer.valueOf(params[0])); - Grasscutter.getLogger().debug("questGlobarVar {} : {}", params[0], questGlobalVarValue); - return questGlobalVarValue.intValue() > params[1]; + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val questId = condition.getParam()[0]; + val minValue = condition.getParam()[1]; + Integer questGlobalVarValue = owner.getQuestManager().getQuestGlobalVarValue(questId); + Grasscutter.getLogger() + .debug("questGlobarVar {} {} : {}", questId, minValue, questGlobalVarValue); + return questGlobalVarValue > minValue; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarLess.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarLess.java index ef85abe3c..1edcf14db 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarLess.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestGlobalVarLess.java @@ -1,21 +1,28 @@ package emu.grasscutter.game.quest.conditions; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_QUEST_GLOBAL_VAR_LESS; + import emu.grasscutter.Grasscutter; import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; -@QuestValue(QuestTrigger.QUEST_COND_QUEST_GLOBAL_VAR_LESS) -public class ConditionQuestGlobalVarLess extends QuestBaseHandler { +@QuestValueCond(QUEST_COND_QUEST_GLOBAL_VAR_LESS) +public class ConditionQuestGlobalVarLess extends BaseCondition { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { - Integer questGlobalVarValue = - quest.getMainQuest().getQuestManager().getQuestGlobalVarValue(Integer.valueOf(params[0])); - Grasscutter.getLogger().debug("questGlobarVar {} : {}", params[0], questGlobalVarValue); - return questGlobalVarValue.intValue() < params[1]; + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val questId = condition.getParam()[0]; + val maxValue = condition.getParam()[1]; + Integer questGlobalVarValue = owner.getQuestManager().getQuestGlobalVarValue(questId); + Grasscutter.getLogger() + .debug("questGlobarVar {} {} : {}", questId, maxValue, questGlobalVarValue); + return questGlobalVarValue < maxValue; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarEqual.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarEqual.java index ede9ff631..5255b16fa 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarEqual.java @@ -1,20 +1,14 @@ package emu.grasscutter.game.quest.conditions; -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_QUEST_VAR_EQUAL; -@QuestValue(QuestTrigger.QUEST_COND_QUEST_VAR_EQUAL) -public class ConditionQuestVarEqual extends QuestBaseHandler { +import emu.grasscutter.game.quest.QuestValueCond; + +@QuestValueCond(QUEST_COND_QUEST_VAR_EQUAL) +public class ConditionQuestVarEqual extends BaseConditionQuestVar { @Override - public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { - int questVarValue = quest.getMainQuest().getQuestVars()[params[0]]; - Grasscutter.getLogger().debug("questVar {} : {}", params[0], questVarValue); - return questVarValue == params[1]; + protected boolean doCompare(int variable, int cond) { + return variable == cond; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarGreater.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarGreater.java index 2952e2bd8..dc84c88d3 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarGreater.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarGreater.java @@ -1,20 +1,14 @@ package emu.grasscutter.game.quest.conditions; -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_QUEST_VAR_GREATER; -@QuestValue(QuestTrigger.QUEST_COND_QUEST_VAR_GREATER) -public class ConditionQuestVarGreater extends QuestBaseHandler { +import emu.grasscutter.game.quest.QuestValueCond; + +@QuestValueCond(QUEST_COND_QUEST_VAR_GREATER) +public class ConditionQuestVarGreater extends BaseConditionQuestVar { @Override - public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { - int questVarValue = quest.getMainQuest().getQuestVars()[params[0]]; - Grasscutter.getLogger().debug("questVar {} : {}", params[0], questVarValue); - return questVarValue > params[1]; + protected boolean doCompare(int variable, int cond) { + return variable > cond; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarLess.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarLess.java index 9a8678eba..e1e2fb0ef 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarLess.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionQuestVarLess.java @@ -1,20 +1,14 @@ package emu.grasscutter.game.quest.conditions; -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_QUEST_VAR_LESS; -@QuestValue(QuestTrigger.QUEST_COND_QUEST_VAR_LESS) -public class ConditionQuestVarLess extends QuestBaseHandler { +import emu.grasscutter.game.quest.QuestValueCond; + +@QuestValueCond(QUEST_COND_QUEST_VAR_LESS) +public class ConditionQuestVarLess extends BaseConditionQuestVar { @Override - public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { - int questVarValue = quest.getMainQuest().getQuestVars()[params[0]]; - Grasscutter.getLogger().debug("questVar {} : {}", params[0], questVarValue); - return questVarValue < params[1]; + protected boolean doCompare(int variable, int cond) { + return variable < cond; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateEqual.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateEqual.java index 37a8867ae..8c1916457 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateEqual.java @@ -1,26 +1,34 @@ package emu.grasscutter.game.quest.conditions; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_STATE_EQUAL; -@QuestValue(QuestTrigger.QUEST_COND_STATE_EQUAL) -public class ConditionStateEqual extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; + +@QuestValueCond(QUEST_COND_STATE_EQUAL) +public class ConditionStateEqual extends BaseCondition { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { - GameQuest checkQuest = quest.getOwner().getQuestManager().getQuestById(condition.getParam()[0]); + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val questId = condition.getParam()[0]; + val questStateValue = condition.getParam()[1]; + GameQuest checkQuest = owner.getQuestManager().getQuestById(questId); if (checkQuest == null) { /* Will spam the console - //Grasscutter.getLogger().debug("Warning: quest {} hasn't been started yet!", condition.getParam()[0]); - */ + // Grasscutter.getLogger().debug("Warning: quest {} hasn't been started yet!", + // condition.getParam()[0]); return false; } - return checkQuest.getState().getValue() == condition.getParam()[1]; + return checkQuest.getState().getValue() == questStateValue; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateNotEqual.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateNotEqual.java index 58751a388..eefaaa20d 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateNotEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionStateNotEqual.java @@ -1,26 +1,35 @@ package emu.grasscutter.game.quest.conditions; -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_STATE_NOT_EQUAL; -@QuestValue(QuestTrigger.QUEST_COND_STATE_NOT_EQUAL) -public class ConditionStateNotEqual extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueCond; +import lombok.val; + +@QuestValueCond(QUEST_COND_STATE_NOT_EQUAL) +public class ConditionStateNotEqual extends BaseCondition { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { - GameQuest checkQuest = quest.getOwner().getQuestManager().getQuestById(condition.getParam()[0]); + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val questId = condition.getParam()[0]; + val questStateValue = condition.getParam()[1]; + GameQuest checkQuest = owner.getQuestManager().getQuestById(questId); if (checkQuest == null) { /* Will spam the console - //Grasscutter.getLogger().debug("Warning: quest {} hasn't been started yet!", condition.getParam()[0]); - */ + // Grasscutter.getLogger().debug("Warning: quest {} hasn't been started yet!", + // condition.getParam()[0]); + return false; } - return checkQuest.getState().getValue() != condition.getParam()[1]; + return checkQuest.getState().getValue() != questStateValue; } } diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionTimeVarGreaterOrEqual.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionTimeVarGreaterOrEqual.java index 8484a42af..eef2bd4ce 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionTimeVarGreaterOrEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionTimeVarGreaterOrEqual.java @@ -1,25 +1,30 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import emu.grasscutter.game.quest.enums.QuestCond; -import lombok.val; - -@QuestValueCond(QuestCond.QUEST_COND_TIME_VAR_GT_EQ) -public class ConditionTimeVarGreaterOrEqual extends BaseCondition{ - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val mainQuestId = condition.getParam()[0]; - val timeVarIndex = condition.getParam()[1]; - val minTime = condition.getParam()[2]; - - val mainQuest = owner.getQuestManager().getMainQuestById(mainQuestId); - - if(mainQuest == null){ - return false; - } - - return mainQuest.getHoursSinceTimeVar(timeVarIndex) >= minTime; - } -} +package emu.grasscutter.game.quest.conditions; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import emu.grasscutter.game.quest.enums.QuestCond; +import lombok.val; + +@QuestValueCond(QuestCond.QUEST_COND_TIME_VAR_GT_EQ) +public class ConditionTimeVarGreaterOrEqual extends BaseCondition { + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val mainQuestId = condition.getParam()[0]; + val timeVarIndex = condition.getParam()[1]; + val minTime = condition.getParam()[2]; + + val mainQuest = owner.getQuestManager().getMainQuestById(mainQuestId); + + if (mainQuest == null) { + return false; + } + + return mainQuest.getHoursSinceTimeVar(timeVarIndex) >= minTime; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionTimeVarPassDay.java b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionTimeVarPassDay.java index 5dbd75cc6..ee7a69c94 100644 --- a/src/main/java/emu/grasscutter/game/quest/conditions/ConditionTimeVarPassDay.java +++ b/src/main/java/emu/grasscutter/game/quest/conditions/ConditionTimeVarPassDay.java @@ -1,30 +1,35 @@ -package emu.grasscutter.game.quest.conditions; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.QuestValueCond; -import emu.grasscutter.game.quest.enums.QuestCond; -import lombok.val; - -@QuestValueCond(QuestCond.QUEST_COND_TIME_VAR_PASS_DAY) -public class ConditionTimeVarPassDay extends BaseCondition{ - @Override - public boolean execute(Player owner, QuestData questData, QuestData.QuestAcceptCondition condition, String paramStr, int... params) { - val mainQuestId = condition.getParam()[0]; - val timeVarIndex = condition.getParam()[1]; - val minDays = condition.getParam()[2]; - - val mainQuest = owner.getQuestManager().getMainQuestById(mainQuestId); - - if(mainQuest == null){ - return false; - } - - val daysSinceTimeVar = mainQuest.getDaysSinceTimeVar(timeVarIndex); - if(daysSinceTimeVar == -1){ - return false; - } - - return daysSinceTimeVar >= minDays; - } -} +package emu.grasscutter.game.quest.conditions; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.QuestValueCond; +import emu.grasscutter.game.quest.enums.QuestCond; +import lombok.val; + +@QuestValueCond(QuestCond.QUEST_COND_TIME_VAR_PASS_DAY) +public class ConditionTimeVarPassDay extends BaseCondition { + @Override + public boolean execute( + Player owner, + QuestData questData, + QuestData.QuestAcceptCondition condition, + String paramStr, + int... params) { + val mainQuestId = condition.getParam()[0]; + val timeVarIndex = condition.getParam()[1]; + val minDays = condition.getParam()[2]; + + val mainQuest = owner.getQuestManager().getMainQuestById(mainQuestId); + + if (mainQuest == null) { + return false; + } + + val daysSinceTimeVar = mainQuest.getDaysSinceTimeVar(timeVarIndex); + if (daysSinceTimeVar == -1) { + return false; + } + + return daysSinceTimeVar >= minDays; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/BaseContent.java b/src/main/java/emu/grasscutter/game/quest/content/BaseContent.java index 39b7a282c..eab889078 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/BaseContent.java +++ b/src/main/java/emu/grasscutter/game/quest/content/BaseContent.java @@ -1,17 +1,17 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.excels.QuestData.QuestCondition; +import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; +import emu.grasscutter.game.quest.QuestValueContent; +import emu.grasscutter.game.quest.enums.QuestContent; import emu.grasscutter.game.quest.handlers.QuestBaseHandler; -@QuestValue(QuestTrigger.QUEST_CONTENT_NONE) -public class BaseContent extends QuestBaseHandler { +@QuestValueContent(QuestContent.QUEST_CONTENT_NONE) +public class BaseContent extends QuestBaseHandler { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { // TODO Auto-generated method stub return false; } 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 d9b1a975c..192f118f8 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentAddQuestProgress.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentAddQuestProgress.java @@ -1,22 +1,23 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; - -@QuestValue(QuestTrigger.QUEST_CONTENT_ADD_QUEST_PROGRESS) -public class ContentAddQuestProgress extends QuestBaseHandler { - - @Override - public boolean execute(GameQuest quest, QuestCondition condition, String paramStr, int... params) { - /* - //paramStr is a lua group, params[0] may also be a lua group! - questid = xxxxxx lua group = xxxxxxyy - count seems relevant only for lua group - */ - return condition.getParam()[0] == params[0]; //missing params[1], paramStr, and count - } - -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ADD_QUEST_PROGRESS; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; +import lombok.val; + +@QuestValueContent(QUEST_CONTENT_ADD_QUEST_PROGRESS) +public class ContentAddQuestProgress extends BaseContent { + + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + val progressId = condition.getParam()[0]; + val currentCount = quest.getOwner().getPlayerProgress().getCurrentProgress(progressId); + + // 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(); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentAnyManualTransport.java b/src/main/java/emu/grasscutter/game/quest/content/ContentAnyManualTransport.java index 9da4fcb41..76a810f19 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentAnyManualTransport.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentAnyManualTransport.java @@ -1,15 +1,16 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ANY_MANUAL_TRANSPORT; - -@QuestValueContent(QUEST_CONTENT_ANY_MANUAL_TRANSPORT) -public class ContentAnyManualTransport extends BaseContent { - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return true; - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ANY_MANUAL_TRANSPORT; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_ANY_MANUAL_TRANSPORT) +public class ContentAnyManualTransport extends BaseContent { + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return true; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentClearGroupMonster.java b/src/main/java/emu/grasscutter/game/quest/content/ContentClearGroupMonster.java index b9ca961a7..ee9bec60b 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentClearGroupMonster.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentClearGroupMonster.java @@ -1,19 +1,20 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; -import lombok.val; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_CLEAR_GROUP_MONSTER; - -@QuestValueContent(QUEST_CONTENT_CLEAR_GROUP_MONSTER) -public class ContentClearGroupMonster extends BaseContent { - - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - val groupId = condition.getParam()[0]; - - return quest.getOwner().getScene().getScriptManager().isClearedGroupMonsters(groupId); - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_CLEAR_GROUP_MONSTER; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; +import lombok.val; + +@QuestValueContent(QUEST_CONTENT_CLEAR_GROUP_MONSTER) +public class ContentClearGroupMonster extends BaseContent { + + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + val groupId = condition.getParam()[0]; + + return quest.getOwner().getScene().getScriptManager().isClearedGroupMonsters(groupId); + } +} 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 5a8de37e1..fa70da14a 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteAnyTalk.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteAnyTalk.java @@ -1,27 +1,33 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.binout.MainQuestData; -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameMainQuest; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_ANY_TALK; -@QuestValue(QuestTrigger.QUEST_CONTENT_COMPLETE_ANY_TALK) -public class ContentCompleteAnyTalk extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; +import java.util.Arrays; +import lombok.val; + +@QuestValueContent(QUEST_CONTENT_COMPLETE_ANY_TALK) +public class ContentCompleteAnyTalk extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { - GameMainQuest checkMainQuest = - quest.getOwner().getQuestManager().getMainQuestById(params[0] / 100); - if (checkMainQuest == null) { - return false; - } - MainQuestData.TalkData talkData = checkMainQuest.getTalks().get(Integer.valueOf(paramStr)); - return talkData == null - || condition.getParamStr().contains(paramStr) - || checkMainQuest.getChildQuestById(params[0]) != null; + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + val talkId = params[0]; + val conditionTalk = + Arrays.stream(condition.getParamStr().split(",")).mapToInt(Integer::parseInt).toArray(); + return Arrays.stream(conditionTalk).anyMatch(tids -> tids == talkId) + || Arrays.stream(conditionTalk) + .anyMatch( + tids -> { + val checkMainQuest = + quest.getOwner().getQuestManager().getMainQuestByTalkId(tids); + if (checkMainQuest == null) { + return false; + } + val talkData = checkMainQuest.getTalks().get(talkId); + return talkData != null; + }); } } 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 14b1cf284..d04a06d89 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteTalk.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentCompleteTalk.java @@ -1,30 +1,25 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.binout.MainQuestData; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameMainQuest; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_TALK; -@QuestValue(QuestTrigger.QUEST_CONTENT_COMPLETE_TALK) -public class ContentCompleteTalk extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; +import lombok.val; + +@QuestValueContent(QUEST_CONTENT_COMPLETE_TALK) +public class ContentCompleteTalk extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { - GameMainQuest checkMainQuest = - quest.getOwner().getQuestManager().getMainQuestById(params[0] / 100); + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + val talkId = condition.getParam()[0]; + val checkMainQuest = quest.getOwner().getQuestManager().getMainQuestByTalkId(talkId); if (checkMainQuest == null) { return false; } - MainQuestData.TalkData talkData = checkMainQuest.getTalks().get(condition.getParam()[0]); + val talkData = checkMainQuest.getTalks().get(talkId); return talkData != null; - - // This expression makes zero sense. - // return talkData == null || condition.getParamStr().contains(paramStr) || - // checkMainQuest.getChildQuestById(params[0]) != null; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentDestroyGadget.java b/src/main/java/emu/grasscutter/game/quest/content/ContentDestroyGadget.java index 61981436f..af594206d 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentDestroyGadget.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentDestroyGadget.java @@ -1,15 +1,16 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_DESTROY_GADGET; - -@QuestValueContent(QUEST_CONTENT_DESTROY_GADGET) -public class ContentDestroyGadget extends BaseContent { - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0]; - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_DESTROY_GADGET; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_DESTROY_GADGET) +public class ContentDestroyGadget extends BaseContent { + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterDungeon.java b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterDungeon.java index 7d137f58b..9004f3225 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterDungeon.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterDungeon.java @@ -1,17 +1,17 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ENTER_DUNGEON; -@QuestValue(QuestTrigger.QUEST_CONTENT_ENTER_DUNGEON) -public class ContentEnterDungeon extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_ENTER_DUNGEON) +public class ContentEnterDungeon extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { return condition.getParam()[0] == params[0]; // missing params[1] } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorld.java b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorld.java index d214f926e..07f83bdc7 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorld.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorld.java @@ -1,17 +1,17 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ENTER_MY_WORLD; - -@QuestValueContent(QUEST_CONTENT_ENTER_MY_WORLD) -public class ContentEnterMyWorld extends BaseContent { - // params[0] scene ID - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0]; - } - -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ENTER_MY_WORLD; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_ENTER_MY_WORLD) +public class ContentEnterMyWorld extends BaseContent { + // params[0] scene ID + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorldScene.java b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorldScene.java index 43a06e425..1100f6c16 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorldScene.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterMyWorldScene.java @@ -1,17 +1,17 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ENTER_MY_WORLD_SCENE; - -@QuestValueContent(QUEST_CONTENT_ENTER_MY_WORLD_SCENE) -public class ContentEnterMyWorldScene extends BaseContent { - // params[0] scene ID - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0]; - } - -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ENTER_MY_WORLD_SCENE; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_ENTER_MY_WORLD_SCENE) +public class ContentEnterMyWorldScene extends BaseContent { + // params[0] scene ID + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterRoom.java b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterRoom.java index 5c9ff80ed..49abedf14 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterRoom.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterRoom.java @@ -1,17 +1,17 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ENTER_ROOM; -@QuestValue(QuestTrigger.QUEST_CONTENT_ENTER_ROOM) -public class ContentEnterRoom extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_ENTER_ROOM) +public class ContentEnterRoom extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { return condition.getParam()[0] == params[0]; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterVehicle.java b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterVehicle.java index e027ec2dc..d5d56f00f 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentEnterVehicle.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentEnterVehicle.java @@ -1,15 +1,16 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ENTER_VEHICLE; - -@QuestValueContent(QUEST_CONTENT_ENTER_VEHICLE) -public class ContentEnterVehicle extends BaseContent { - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0]; - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ENTER_VEHICLE; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_ENTER_VEHICLE) +public class ContentEnterVehicle extends BaseContent { + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentFailDungeon.java b/src/main/java/emu/grasscutter/game/quest/content/ContentFailDungeon.java index 29da1d0fb..a09153d58 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentFailDungeon.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentFailDungeon.java @@ -1,18 +1,18 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_FAIL_DUNGEON; - -@QuestValueContent(QUEST_CONTENT_FAIL_DUNGEON) -public class ContentFailDungeon extends BaseContent { - - // params[0] dungeon ID - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0]; - } - -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_FAIL_DUNGEON; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_FAIL_DUNGEON) +public class ContentFailDungeon extends BaseContent { + + // params[0] dungeon ID + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentFinishDungeon.java b/src/main/java/emu/grasscutter/game/quest/content/ContentFinishDungeon.java index a0a787c09..918b09ae9 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentFinishDungeon.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentFinishDungeon.java @@ -1,18 +1,18 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_FINISH_DUNGEON; - -@QuestValueContent(QUEST_CONTENT_FINISH_DUNGEON) -public class ContentFinishDungeon extends BaseContent { - - // params[0] dungeon ID, params[1] unknown - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0]; - } - -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_FINISH_DUNGEON; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_FINISH_DUNGEON) +public class ContentFinishDungeon extends BaseContent { + + // params[0] dungeon ID, params[1] unknown + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentFinishPlot.java b/src/main/java/emu/grasscutter/game/quest/content/ContentFinishPlot.java index 7afaf4c0a..32c16b3bc 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentFinishPlot.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentFinishPlot.java @@ -1,21 +1,22 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.binout.MainQuestData; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_FINISH_PLOT; -@QuestValue(QuestTrigger.QUEST_CONTENT_FINISH_PLOT) -public class ContentFinishPlot extends QuestBaseHandler { +import emu.grasscutter.data.binout.MainQuestData; +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_FINISH_PLOT) +public class ContentFinishPlot extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { MainQuestData.TalkData talkData = quest.getMainQuest().getTalks().get(Integer.valueOf(params[0])); GameQuest subQuest = quest.getMainQuest().getChildQuestById(params[0]); - return talkData != null || subQuest != null; + return talkData != null && subQuest != null + || condition.getParamStr().equals(paramStr) && condition.getParam()[0] == params[0]; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentGameTimeTick.java b/src/main/java/emu/grasscutter/game/quest/content/ContentGameTimeTick.java index 1b584476f..4c9f04203 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentGameTimeTick.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentGameTimeTick.java @@ -1,22 +1,38 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_GAME_TIME_TICK; -@QuestValue(QuestTrigger.QUEST_CONTENT_GAME_TIME_TICK) -public class ContentGameTimeTick extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; +import lombok.val; + +@QuestValueContent(QUEST_CONTENT_GAME_TIME_TICK) +public class ContentGameTimeTick extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { - var range = condition.getParamStr().split(","); - var min = Math.min(Integer.parseInt(range[0]), Integer.parseInt(range[1])); - var max = Math.max(Integer.parseInt(range[0]), Integer.parseInt(range[1])); + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + val daysSinceStart = + quest.getOwner().getWorld().getTotalGameTimeDays() - quest.getStartGameDay(); + val currentHour = quest.getOwner().getWorld().getGameTimeHours(); - // params[0] is clock, params[1] is day - return params[0] >= min && params[0] <= max && params[1] >= condition.getParam()[0]; + // params[0] is days since start, str is hours of day + val range = condition.getParamStr().split(","); + val from = Integer.parseInt(range[0]); + val to = Integer.parseInt(range[1]); + + val daysToPass = condition.getParam()[0]; + // if to is at the beginning of the day, we need to pass it one more time + val daysMod = to < from && daysToPass > 0 && currentHour < to ? 1 : 0; + + val isTimeMet = + from < to + ? currentHour >= from && currentHour < to + : currentHour < to || currentHour >= from; + + val isDaysSinceMet = daysSinceStart >= daysToPass + daysMod; + + return isTimeMet && isDaysSinceMet; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentInteractGadget.java b/src/main/java/emu/grasscutter/game/quest/content/ContentInteractGadget.java index 598c6e066..4a7ea7a99 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentInteractGadget.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentInteractGadget.java @@ -1,17 +1,17 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_INTERACT_GADGET; -@QuestValue(QuestTrigger.QUEST_CONTENT_INTERACT_GADGET) -public class ContentInteractGadget extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_INTERACT_GADGET) +public class ContentInteractGadget extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { return params[0] == condition.getParam()[0]; } } 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 9384252d3..8513ad81f 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentItemLessThan.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentItemLessThan.java @@ -1,15 +1,16 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ITEM_LESS_THAN; - -@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]; - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_ITEM_LESS_THAN; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@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]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentKillMonster.java b/src/main/java/emu/grasscutter/game/quest/content/ContentKillMonster.java index 7739be1e9..b45690e8a 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentKillMonster.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentKillMonster.java @@ -1,15 +1,16 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_KILL_MONSTER; - -@QuestValueContent(QUEST_CONTENT_KILL_MONSTER) -public class ContentKillMonster extends BaseContent { - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0]; - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_KILL_MONSTER; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_KILL_MONSTER) +public class ContentKillMonster extends BaseContent { + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentLeaveScene.java b/src/main/java/emu/grasscutter/game/quest/content/ContentLeaveScene.java index 4c43b646f..b8ff77a0b 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentLeaveScene.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentLeaveScene.java @@ -1,17 +1,17 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_LEAVE_SCENE; -@QuestValue(QuestTrigger.QUEST_CONTENT_LEAVE_SCENE) -public class ContentLeaveScene extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_LEAVE_SCENE) +public class ContentLeaveScene extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { return quest.getOwner().getScene().getPrevScene() == params[0]; } } 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 ba230097c..929d80e46 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentLuaNotify.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentLuaNotify.java @@ -1,17 +1,17 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_LUA_NOTIFY; -@QuestValue(QuestTrigger.QUEST_CONTENT_LUA_NOTIFY) -public class ContentLuaNotify extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_LUA_NOTIFY) +public class ContentLuaNotify extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { return condition.getParamStr().equals(paramStr); } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentMonsterDie.java b/src/main/java/emu/grasscutter/game/quest/content/ContentMonsterDie.java index 72de7f4c0..271e29198 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentMonsterDie.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentMonsterDie.java @@ -1,15 +1,16 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_MONSTER_DIE; - -@QuestValueContent(QUEST_CONTENT_MONSTER_DIE) -public class ContentMonsterDie extends BaseContent { - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0]; - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_MONSTER_DIE; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_MONSTER_DIE) +public class ContentMonsterDie extends BaseContent { + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentNotFinishPlot.java b/src/main/java/emu/grasscutter/game/quest/content/ContentNotFinishPlot.java index 0a7d05138..d06c7f993 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentNotFinishPlot.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentNotFinishPlot.java @@ -1,25 +1,24 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.binout.MainQuestData; -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameMainQuest; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_NOT_FINISH_PLOT; -@QuestValue(QuestTrigger.QUEST_CONTENT_NOT_FINISH_PLOT) -public class ContentNotFinishPlot extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; +import lombok.val; + +@QuestValueContent(QUEST_CONTENT_NOT_FINISH_PLOT) +public class ContentNotFinishPlot extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { - GameMainQuest checkMainQuest = - quest.getOwner().getQuestManager().getMainQuestById(params[0] / 100); + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + val talkId = condition.getParam()[0]; + val checkMainQuest = quest.getOwner().getQuestManager().getMainQuestByTalkId(talkId); if (checkMainQuest == null) { - return false; + return true; } - MainQuestData.TalkData talkData = checkMainQuest.getTalks().get(Integer.valueOf(params[0])); + val talkData = checkMainQuest.getTalks().get(talkId); return talkData == null; } } 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 93c3ea2ac..a60cf6d75 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentObtainItem.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentObtainItem.java @@ -1,19 +1,20 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_OBTAIN_ITEM; - -@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; - } - return condition.getParam()[0] == params[0] && targetCount <= params[1]; - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_OBTAIN_ITEM; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@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; + } + return condition.getParam()[0] == params[0] && targetCount <= params[1]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentPlayerLevelUp.java b/src/main/java/emu/grasscutter/game/quest/content/ContentPlayerLevelUp.java index f9ae864be..d555d411e 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentPlayerLevelUp.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentPlayerLevelUp.java @@ -1,15 +1,16 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_PLAYER_LEVEL_UP; - -@QuestValueContent(QUEST_CONTENT_PLAYER_LEVEL_UP) -public class ContentPlayerLevelUp extends BaseContent { - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return quest.getOwner().getLevel() >= condition.getCount(); - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_PLAYER_LEVEL_UP; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_PLAYER_LEVEL_UP) +public class ContentPlayerLevelUp extends BaseContent { + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return quest.getOwner().getLevel() >= condition.getCount(); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentQuestStateEqual.java b/src/main/java/emu/grasscutter/game/quest/content/ContentQuestStateEqual.java index 1c84bb6f4..8e5973a99 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentQuestStateEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentQuestStateEqual.java @@ -1,17 +1,17 @@ package emu.grasscutter.game.quest.content; -import emu.grasscutter.data.excels.QuestData.QuestCondition; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_QUEST_STATE_EQUAL; -@QuestValue(QuestTrigger.QUEST_CONTENT_QUEST_STATE_EQUAL) -public class ContentQuestStateEqual extends QuestBaseHandler { +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_QUEST_STATE_EQUAL) +public class ContentQuestStateEqual extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { GameQuest checkQuest = quest.getOwner().getQuestManager().getQuestById(condition.getParam()[0]); if (checkQuest == null) { return false; diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentQuestStateNotEqual.java b/src/main/java/emu/grasscutter/game/quest/content/ContentQuestStateNotEqual.java index fe4c10605..522ba593b 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentQuestStateNotEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentQuestStateNotEqual.java @@ -1,17 +1,17 @@ package emu.grasscutter.game.quest.content; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_QUEST_STATE_NOT_EQUAL; + import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import emu.grasscutter.game.quest.QuestValueContent; -@QuestValue(QuestTrigger.QUEST_CONTENT_QUEST_STATE_NOT_EQUAL) -public class ContentQuestStateNotEqual extends QuestBaseHandler { +@QuestValueContent(QUEST_CONTENT_QUEST_STATE_NOT_EQUAL) +public class ContentQuestStateNotEqual extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { GameQuest checkQuest = quest.getOwner().getQuestManager().getQuestById(params[0]); if (checkQuest != null) { diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarEqual.java b/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarEqual.java index 75d9b0457..c05f897c0 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarEqual.java @@ -1,18 +1,18 @@ package emu.grasscutter.game.quest.content; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_QUEST_VAR_EQUAL; + import emu.grasscutter.Grasscutter; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import emu.grasscutter.game.quest.QuestValueContent; -@QuestValue(QuestTrigger.QUEST_CONTENT_QUEST_VAR_EQUAL) -public class ContentQuestVarEqual extends QuestBaseHandler { +@QuestValueContent(QUEST_CONTENT_QUEST_VAR_EQUAL) +public class ContentQuestVarEqual extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { int questVarValue = quest.getMainQuest().getQuestVars()[params[0]]; Grasscutter.getLogger().debug("questVar {} : {}", params[0], questVarValue); return questVarValue == params[1]; diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarGreater.java b/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarGreater.java index 432a9f800..9d9217b0a 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarGreater.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarGreater.java @@ -1,18 +1,18 @@ package emu.grasscutter.game.quest.content; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_QUEST_VAR_GREATER; + import emu.grasscutter.Grasscutter; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import emu.grasscutter.game.quest.QuestValueContent; -@QuestValue(QuestTrigger.QUEST_CONTENT_QUEST_VAR_GREATER) -public class ContentQuestVarGreater extends QuestBaseHandler { +@QuestValueContent(QUEST_CONTENT_QUEST_VAR_GREATER) +public class ContentQuestVarGreater extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { int questVarValue = quest.getMainQuest().getQuestVars()[params[0]]; Grasscutter.getLogger().debug("questVar {} : {}", params[0], questVarValue); return questVarValue > params[1]; diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarLess.java b/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarLess.java index f642f5749..f234105a3 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarLess.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentQuestVarLess.java @@ -1,18 +1,18 @@ package emu.grasscutter.game.quest.content; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_QUEST_VAR_LESS; + import emu.grasscutter.Grasscutter; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import emu.grasscutter.game.quest.QuestValueContent; -@QuestValue(QuestTrigger.QUEST_CONTENT_QUEST_VAR_LESS) -public class ContentQuestVarLess extends QuestBaseHandler { +@QuestValueContent(QUEST_CONTENT_QUEST_VAR_LESS) +public class ContentQuestVarLess extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { int questVarValue = quest.getMainQuest().getQuestVars()[params[0]]; Grasscutter.getLogger().debug("questVar {} : {}", params[0], questVarValue); return questVarValue < params[1]; diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentSkill.java b/src/main/java/emu/grasscutter/game/quest/content/ContentSkill.java index 8f00a074f..42b04d8c8 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentSkill.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentSkill.java @@ -1,15 +1,16 @@ package emu.grasscutter.game.quest.content; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_SKILL; + import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; +import emu.grasscutter.game.quest.QuestValueContent; -@QuestValue(QuestTrigger.QUEST_CONTENT_SKILL) +@QuestValueContent(QUEST_CONTENT_SKILL) public class ContentSkill extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { - return (condition.getParam()[0] == params[0]) && (condition.getParam()[1] == params[1]); + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0]; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentTimeVarMoreOrEqual.java b/src/main/java/emu/grasscutter/game/quest/content/ContentTimeVarMoreOrEqual.java index cd3b330da..0d6881293 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentTimeVarMoreOrEqual.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentTimeVarMoreOrEqual.java @@ -1,25 +1,26 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; -import emu.grasscutter.game.quest.enums.QuestContent; -import lombok.val; - -@QuestValueContent(QuestContent.QUEST_CONTENT_TIME_VAR_GT_EQ) -public class ContentTimeVarMoreOrEqual extends BaseContent{ - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - val mainQuestId = condition.getParam()[0]; - val timeVarIndex = condition.getParam()[1]; - val minTime = Integer.parseInt(condition.getParamStr()); - - val mainQuest = quest.getOwner().getQuestManager().getMainQuestById(mainQuestId); - - if(mainQuest == null){ - return false; - } - - return mainQuest.getHoursSinceTimeVar(timeVarIndex) >= minTime; - } -} +package emu.grasscutter.game.quest.content; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; +import emu.grasscutter.game.quest.enums.QuestContent; +import lombok.val; + +@QuestValueContent(QuestContent.QUEST_CONTENT_TIME_VAR_GT_EQ) +public class ContentTimeVarMoreOrEqual extends BaseContent { + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + val mainQuestId = condition.getParam()[0]; + val timeVarIndex = condition.getParam()[1]; + val minTime = Integer.parseInt(condition.getParamStr()); + + val mainQuest = quest.getOwner().getQuestManager().getMainQuestById(mainQuestId); + + if (mainQuest == null) { + return false; + } + + return mainQuest.getHoursSinceTimeVar(timeVarIndex) >= minTime; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentTimeVarPassDay.java b/src/main/java/emu/grasscutter/game/quest/content/ContentTimeVarPassDay.java index e0b814820..c0b8fefd1 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentTimeVarPassDay.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentTimeVarPassDay.java @@ -1,30 +1,31 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; -import emu.grasscutter.game.quest.enums.QuestContent; -import lombok.val; - -@QuestValueContent(QuestContent.QUEST_CONTENT_TIME_VAR_PASS_DAY) -public class ContentTimeVarPassDay extends BaseContent{ - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - val mainQuestId = condition.getParam()[0]; - val timeVarIndex = condition.getParam()[1]; - val minDays = Integer.parseInt(condition.getParamStr()); - - val mainQuest = quest.getOwner().getQuestManager().getMainQuestById(mainQuestId); - - if(mainQuest == null){ - return false; - } - - val daysSinceTimeVar = mainQuest.getDaysSinceTimeVar(timeVarIndex); - if(daysSinceTimeVar == -1){ - return false; - } - - return daysSinceTimeVar >= minDays; - } -} +package emu.grasscutter.game.quest.content; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; +import emu.grasscutter.game.quest.enums.QuestContent; +import lombok.val; + +@QuestValueContent(QuestContent.QUEST_CONTENT_TIME_VAR_PASS_DAY) +public class ContentTimeVarPassDay extends BaseContent { + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + val mainQuestId = condition.getParam()[0]; + val timeVarIndex = condition.getParam()[1]; + val minDays = Integer.parseInt(condition.getParamStr()); + + val mainQuest = quest.getOwner().getQuestManager().getMainQuestById(mainQuestId); + + if (mainQuest == null) { + return false; + } + + val daysSinceTimeVar = mainQuest.getDaysSinceTimeVar(timeVarIndex); + if (daysSinceTimeVar == -1) { + return false; + } + + return daysSinceTimeVar >= minDays; + } +} 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 fb926fded..643b52fbf 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentTriggerFire.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentTriggerFire.java @@ -1,18 +1,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.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import emu.grasscutter.game.quest.QuestValueContent; -@QuestValue(QuestTrigger.QUEST_CONTENT_TRIGGER_FIRE) -public class ContentTriggerFire extends QuestBaseHandler { +@QuestValueContent(QUEST_CONTENT_TRIGGER_FIRE) +public class ContentTriggerFire extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { + 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])); diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentUnlockArea.java b/src/main/java/emu/grasscutter/game/quest/content/ContentUnlockArea.java index 60f245b6f..f54ae2b64 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentUnlockArea.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentUnlockArea.java @@ -1,15 +1,16 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_UNLOCK_AREA; - -@QuestValueContent(QUEST_CONTENT_UNLOCK_AREA) -public class ContentUnlockArea extends BaseContent { - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0] || condition.getParam()[1] == params[1]; - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_UNLOCK_AREA; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_UNLOCK_AREA) +public class ContentUnlockArea extends BaseContent { + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0] || condition.getParam()[1] == params[1]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentUnlockTransPoint.java b/src/main/java/emu/grasscutter/game/quest/content/ContentUnlockTransPoint.java index a8dad8d25..131bece5b 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentUnlockTransPoint.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentUnlockTransPoint.java @@ -1,16 +1,16 @@ package emu.grasscutter.game.quest.content; +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_UNLOCK_TRANS_POINT; + import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestBaseHandler; +import emu.grasscutter.game.quest.QuestValueContent; -@QuestValue(QuestTrigger.QUEST_CONTENT_UNLOCK_TRANS_POINT) -public class ContentUnlockTransPoint extends QuestBaseHandler { +@QuestValueContent(QUEST_CONTENT_UNLOCK_TRANS_POINT) +public class ContentUnlockTransPoint extends BaseContent { @Override public boolean execute( - GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { return condition.getParam()[0] == params[0] && condition.getParam()[1] == params[1]; } } diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentUseItem.java b/src/main/java/emu/grasscutter/game/quest/content/ContentUseItem.java index e0d68fd9b..88e3b1851 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentUseItem.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentUseItem.java @@ -1,15 +1,16 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_USE_ITEM; - -@QuestValueContent(QUEST_CONTENT_USE_ITEM) -public class ContentUseItem extends BaseContent { - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0]; - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_USE_ITEM; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_USE_ITEM) +public class ContentUseItem extends BaseContent { + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentWorktopSelect.java b/src/main/java/emu/grasscutter/game/quest/content/ContentWorktopSelect.java index 3a5a8b202..8edbcc526 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentWorktopSelect.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentWorktopSelect.java @@ -1,15 +1,16 @@ -package emu.grasscutter.game.quest.content; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueContent; - -import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_WORKTOP_SELECT; - -@QuestValueContent(QUEST_CONTENT_WORKTOP_SELECT) -public class ContentWorktopSelect extends BaseContent { - @Override - public boolean execute(GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { - return condition.getParam()[0] == params[0] || condition.getParam()[1] == params[1]; - } -} +package emu.grasscutter.game.quest.content; + +import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_WORKTOP_SELECT; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueContent; + +@QuestValueContent(QUEST_CONTENT_WORKTOP_SELECT) +public class ContentWorktopSelect extends BaseContent { + @Override + public boolean execute( + GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { + return condition.getParam()[0] == params[0] || condition.getParam()[1] == params[1]; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/enums/LogicType.java b/src/main/java/emu/grasscutter/game/quest/enums/LogicType.java index 468b9b5c3..f131d630d 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/LogicType.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/LogicType.java @@ -1,6 +1,10 @@ package emu.grasscutter.game.quest.enums; +import emu.grasscutter.Grasscutter; import java.util.Arrays; +import java.util.List; +import java.util.function.BooleanSupplier; +import org.jetbrains.annotations.NotNull; public enum LogicType { LOGIC_NONE(0), @@ -20,6 +24,10 @@ public enum LogicType { } public static boolean calculate(LogicType logicType, int[] progress) { + if (progress.length == 0) { + return true; + } + if (logicType == null) { return progress[0] == 1; } @@ -31,12 +39,57 @@ public enum LogicType { case LOGIC_OR -> { return Arrays.stream(progress).anyMatch(i -> i == 1); } + case LOGIC_NOT -> { + return Arrays.stream(progress).noneMatch(i -> i == 1); + } + case LOGIC_A_AND_ETCOR -> { + return progress[0] == 1 && Arrays.stream(progress).skip(1).anyMatch(i -> i == 1); + } + case LOGIC_A_AND_B_AND_ETCOR -> { + return progress[0] == 1 + && progress[1] == 1 + && Arrays.stream(progress).skip(2).anyMatch(i -> i == 1); + } + case LOGIC_A_OR_ETCAND -> { + return progress[0] == 1 || Arrays.stream(progress).skip(1).allMatch(i -> i == 1); + } + case LOGIC_A_OR_B_OR_ETCAND -> { + return progress[0] == 1 + || progress[1] == 1 + || Arrays.stream(progress).skip(2).allMatch(i -> i == 1); + } + case LOGIC_A_AND_B_OR_ETCAND -> { + return progress[0] == 1 && progress[1] == 1 + || Arrays.stream(progress).skip(2).allMatch(i -> i == 1); + } default -> { return Arrays.stream(progress).anyMatch(i -> i == 1); } } } + /** + * Apply logic type to all predicates + * + * @param logicType type of logic that should be applied to predicates + * @param predicates list of predicates for which logicType will be applied + * @return result of applying logicType to predicates + */ + public static boolean calculate(@NotNull LogicType logicType, List predicates) { + switch (logicType) { + case LOGIC_AND -> { + return predicates.stream().allMatch(BooleanSupplier::getAsBoolean); + } + case LOGIC_OR -> { + return predicates.stream().anyMatch(BooleanSupplier::getAsBoolean); + } + default -> { + Grasscutter.getLogger().error("Unimplemented logic operation was called"); + return false; + } + } + } + public int getValue() { return value; } diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestCond.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestCond.java index 95c5c955d..e5e548359 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestCond.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestCond.java @@ -1,121 +1,120 @@ -package emu.grasscutter.game.quest.enums; - -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Stream; - -public enum QuestCond implements QuestTrigger { - QUEST_COND_NONE (0), - QUEST_COND_STATE_EQUAL (1), - QUEST_COND_STATE_NOT_EQUAL (2), - QUEST_COND_PACK_HAVE_ITEM (3), - QUEST_COND_AVATAR_ELEMENT_EQUAL (4), // missing, currently unused - QUEST_COND_AVATAR_ELEMENT_NOT_EQUAL (5), // missing, only NPC groups - QUEST_COND_AVATAR_CAN_CHANGE_ELEMENT (6), // missing, only NPC groups - QUEST_COND_CITY_LEVEL_EQUAL_GREATER (7), // missing, currently unused - QUEST_COND_ITEM_NUM_LESS_THAN (8), - QUEST_COND_DAILY_TASK_START (9), // missing - QUEST_COND_OPEN_STATE_EQUAL (10), - QUEST_COND_DAILY_TASK_OPEN (11), // missing, only NPC groups - QUEST_COND_DAILY_TASK_REWARD_CAN_GET (12), // missing, only NPC groups/talks - QUEST_COND_DAILY_TASK_REWARD_RECEIVED (13), // missing, only NPC groups/talks - QUEST_COND_PLAYER_LEVEL_REWARD_CAN_GET (14), // missing, only NPC groups/talks - QUEST_COND_EXPLORATION_REWARD_CAN_GET (15), // missing, only NPC groups/talks - QUEST_COND_IS_WORLD_OWNER (16), // missing, only NPC groups/talks - QUEST_COND_PLAYER_LEVEL_EQUAL_GREATER (17), - QUEST_COND_SCENE_AREA_UNLOCKED (18), // missing, only NPC groups/talks - QUEST_COND_ITEM_GIVING_ACTIVED (19), // missing - QUEST_COND_ITEM_GIVING_FINISHED (20), // missing - QUEST_COND_IS_DAYTIME (21), // only NPC groups - QUEST_COND_CURRENT_AVATAR (22), // missing - QUEST_COND_CURRENT_AREA (23), // missing - QUEST_COND_QUEST_VAR_EQUAL (24), - QUEST_COND_QUEST_VAR_GREATER (25), - QUEST_COND_QUEST_VAR_LESS (26), - QUEST_COND_FORGE_HAVE_FINISH (27), // missing, only NPC groups - QUEST_COND_DAILY_TASK_IN_PROGRESS (28), // missing - QUEST_COND_DAILY_TASK_FINISHED (29), // missing, currently unused - QUEST_COND_ACTIVITY_COND (30), - QUEST_COND_ACTIVITY_OPEN (31), - QUEST_COND_DAILY_TASK_VAR_GT (32), // missing - QUEST_COND_DAILY_TASK_VAR_EQ (33), // missing - QUEST_COND_DAILY_TASK_VAR_LT (34), // missing - QUEST_COND_BARGAIN_ITEM_GT (35), // missing, currently unused - QUEST_COND_BARGAIN_ITEM_EQ (36), // missing, currently unused - QUEST_COND_BARGAIN_ITEM_LT (37), // missing, currently unused - QUEST_COND_COMPLETE_TALK (38), - QUEST_COND_NOT_HAVE_BLOSSOM_TALK (39), // missing, only NPC groups - QUEST_COND_IS_CUR_BLOSSOM_TALK (40), // missing, only Blossom groups - QUEST_COND_QUEST_NOT_RECEIVE (41), // missing - QUEST_COND_QUEST_SERVER_COND_VALID (42), // missing, only NPC groups - QUEST_COND_ACTIVITY_CLIENT_COND (43), // missing, only NPC and Activity groups - QUEST_COND_QUEST_GLOBAL_VAR_EQUAL (44), - QUEST_COND_QUEST_GLOBAL_VAR_GREATER (45), - QUEST_COND_QUEST_GLOBAL_VAR_LESS (46), - QUEST_COND_PERSONAL_LINE_UNLOCK (47), - QUEST_COND_CITY_REPUTATION_REQUEST (48), // missing - QUEST_COND_MAIN_COOP_START (49), // missing - QUEST_COND_MAIN_COOP_ENTER_SAVE_POINT (50), // missing - QUEST_COND_CITY_REPUTATION_LEVEL (51), // missing, only NPC groups - QUEST_COND_CITY_REPUTATION_UNLOCK (52), // missing, currently unused - QUEST_COND_LUA_NOTIFY (53), - QUEST_COND_CUR_CLIMATE (54), - QUEST_COND_ACTIVITY_END (55), - QUEST_COND_COOP_POINT_RUNNING (56), // missing, currently unused - QUEST_COND_GADGET_TALK_STATE_EQUAL (57), // missing, only Gadget groups - QUEST_COND_AVATAR_FETTER_GT (58), // missing, only NPC groups/talks - QUEST_COND_AVATAR_FETTER_EQ (59), // missing, only talks - QUEST_COND_AVATAR_FETTER_LT (60), // missing, only talks - QUEST_COND_NEW_HOMEWORLD_MOUDLE_UNLOCK (61), // missing, only Gadget groups - QUEST_COND_NEW_HOMEWORLD_LEVEL_REWARD (62), // missing, only Gadget groups - QUEST_COND_NEW_HOMEWORLD_MAKE_FINISH (63), // missing, only Gadget groups - QUEST_COND_HOMEWORLD_NPC_EVENT (64), // missing, only NPC groups - QUEST_COND_TIME_VAR_GT_EQ (65), // currently unused - QUEST_COND_TIME_VAR_PASS_DAY (66), - QUEST_COND_HOMEWORLD_NPC_NEW_TALK (67), // missing, only NPC groups - QUEST_COND_PLAYER_CHOOSE_MALE (68), // missing, only talks - QUEST_COND_HISTORY_GOT_ANY_ITEM (69), - QUEST_COND_LEARNED_RECIPE (70), // missing, currently unused - QUEST_COND_LUNARITE_REGION_UNLOCKED (71), // missing, only NPC groups - QUEST_COND_LUNARITE_HAS_REGION_HINT_COUNT (72), // missing, only NPC groups - QUEST_COND_LUNARITE_COLLECT_FINISH (73), // missing, only NPC groups - QUEST_COND_LUNARITE_MARK_ALL_FINISH (74), // missing, only NPC groups - QUEST_COND_NEW_HOMEWORLD_SHOP_ITEM (75), // missing, only Gadget groups - QUEST_COND_SCENE_POINT_UNLOCK (76), // missing, only NPC groups - QUEST_COND_SCENE_LEVEL_TAG_EQ (77), // missing - QUEST_COND_PLAYER_ENTER_REGION (78), // missing - QUEST_COND_UNKNOWN (9999); - - private final int value; - - QuestCond(int id) { - this.value = id; - } - - public int getValue() { - return value; - } - - - private static final Int2ObjectMap contentMap = new Int2ObjectOpenHashMap<>(); - private static final Map contentStringMap = new HashMap<>(); - - static { - Stream.of(values()) - .forEach(e -> { - contentMap.put(e.getValue(), e); - contentStringMap.put(e.name(), e); - }); - } - - public static QuestCond getContentTriggerByValue(int value) { - return contentMap.getOrDefault(value, QUEST_COND_NONE); - } - - public static QuestCond getContentTriggerByName(String name) { - return contentStringMap.getOrDefault(name, QUEST_COND_NONE); - } -} +package emu.grasscutter.game.quest.enums; + +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +public enum QuestCond implements QuestTrigger { + QUEST_COND_NONE(0), + QUEST_COND_STATE_EQUAL(1), + QUEST_COND_STATE_NOT_EQUAL(2), + QUEST_COND_PACK_HAVE_ITEM(3), + QUEST_COND_AVATAR_ELEMENT_EQUAL(4), // missing, currently unused + QUEST_COND_AVATAR_ELEMENT_NOT_EQUAL(5), // missing, only NPC groups + QUEST_COND_AVATAR_CAN_CHANGE_ELEMENT(6), // missing, only NPC groups + QUEST_COND_CITY_LEVEL_EQUAL_GREATER(7), // missing, currently unused + QUEST_COND_ITEM_NUM_LESS_THAN(8), + QUEST_COND_DAILY_TASK_START(9), // missing + QUEST_COND_OPEN_STATE_EQUAL(10), + QUEST_COND_DAILY_TASK_OPEN(11), // missing, only NPC groups + QUEST_COND_DAILY_TASK_REWARD_CAN_GET(12), // missing, only NPC groups/talks + QUEST_COND_DAILY_TASK_REWARD_RECEIVED(13), // missing, only NPC groups/talks + QUEST_COND_PLAYER_LEVEL_REWARD_CAN_GET(14), // missing, only NPC groups/talks + QUEST_COND_EXPLORATION_REWARD_CAN_GET(15), // missing, only NPC groups/talks + QUEST_COND_IS_WORLD_OWNER(16), // missing, only NPC groups/talks + QUEST_COND_PLAYER_LEVEL_EQUAL_GREATER(17), + QUEST_COND_SCENE_AREA_UNLOCKED(18), // missing, only NPC groups/talks + QUEST_COND_ITEM_GIVING_ACTIVED(19), // missing + QUEST_COND_ITEM_GIVING_FINISHED(20), // missing + QUEST_COND_IS_DAYTIME(21), // only NPC groups + QUEST_COND_CURRENT_AVATAR(22), // missing + QUEST_COND_CURRENT_AREA(23), // missing + QUEST_COND_QUEST_VAR_EQUAL(24), + QUEST_COND_QUEST_VAR_GREATER(25), + QUEST_COND_QUEST_VAR_LESS(26), + QUEST_COND_FORGE_HAVE_FINISH(27), // missing, only NPC groups + QUEST_COND_DAILY_TASK_IN_PROGRESS(28), // missing + QUEST_COND_DAILY_TASK_FINISHED(29), // missing, currently unused + QUEST_COND_ACTIVITY_COND(30), + QUEST_COND_ACTIVITY_OPEN(31), + QUEST_COND_DAILY_TASK_VAR_GT(32), // missing + QUEST_COND_DAILY_TASK_VAR_EQ(33), // missing + QUEST_COND_DAILY_TASK_VAR_LT(34), // missing + QUEST_COND_BARGAIN_ITEM_GT(35), // missing, currently unused + QUEST_COND_BARGAIN_ITEM_EQ(36), // missing, currently unused + QUEST_COND_BARGAIN_ITEM_LT(37), // missing, currently unused + QUEST_COND_COMPLETE_TALK(38), + QUEST_COND_NOT_HAVE_BLOSSOM_TALK(39), // missing, only NPC groups + QUEST_COND_IS_CUR_BLOSSOM_TALK(40), // missing, only Blossom groups + QUEST_COND_QUEST_NOT_RECEIVE(41), // missing + QUEST_COND_QUEST_SERVER_COND_VALID(42), // missing, only NPC groups + QUEST_COND_ACTIVITY_CLIENT_COND(43), // missing, only NPC and Activity groups + QUEST_COND_QUEST_GLOBAL_VAR_EQUAL(44), + QUEST_COND_QUEST_GLOBAL_VAR_GREATER(45), + QUEST_COND_QUEST_GLOBAL_VAR_LESS(46), + QUEST_COND_PERSONAL_LINE_UNLOCK(47), + QUEST_COND_CITY_REPUTATION_REQUEST(48), // missing + QUEST_COND_MAIN_COOP_START(49), // missing + QUEST_COND_MAIN_COOP_ENTER_SAVE_POINT(50), // missing + QUEST_COND_CITY_REPUTATION_LEVEL(51), // missing, only NPC groups + QUEST_COND_CITY_REPUTATION_UNLOCK(52), // missing, currently unused + QUEST_COND_LUA_NOTIFY(53), + QUEST_COND_CUR_CLIMATE(54), + QUEST_COND_ACTIVITY_END(55), + QUEST_COND_COOP_POINT_RUNNING(56), // missing, currently unused + QUEST_COND_GADGET_TALK_STATE_EQUAL(57), // missing, only Gadget groups + QUEST_COND_AVATAR_FETTER_GT(58), // missing, only NPC groups/talks + QUEST_COND_AVATAR_FETTER_EQ(59), // missing, only talks + QUEST_COND_AVATAR_FETTER_LT(60), // missing, only talks + QUEST_COND_NEW_HOMEWORLD_MOUDLE_UNLOCK(61), // missing, only Gadget groups + QUEST_COND_NEW_HOMEWORLD_LEVEL_REWARD(62), // missing, only Gadget groups + QUEST_COND_NEW_HOMEWORLD_MAKE_FINISH(63), // missing, only Gadget groups + QUEST_COND_HOMEWORLD_NPC_EVENT(64), // missing, only NPC groups + QUEST_COND_TIME_VAR_GT_EQ(65), // currently unused + QUEST_COND_TIME_VAR_PASS_DAY(66), + QUEST_COND_HOMEWORLD_NPC_NEW_TALK(67), // missing, only NPC groups + QUEST_COND_PLAYER_CHOOSE_MALE(68), // missing, only talks + QUEST_COND_HISTORY_GOT_ANY_ITEM(69), + QUEST_COND_LEARNED_RECIPE(70), // missing, currently unused + QUEST_COND_LUNARITE_REGION_UNLOCKED(71), // missing, only NPC groups + QUEST_COND_LUNARITE_HAS_REGION_HINT_COUNT(72), // missing, only NPC groups + QUEST_COND_LUNARITE_COLLECT_FINISH(73), // missing, only NPC groups + QUEST_COND_LUNARITE_MARK_ALL_FINISH(74), // missing, only NPC groups + QUEST_COND_NEW_HOMEWORLD_SHOP_ITEM(75), // missing, only Gadget groups + QUEST_COND_SCENE_POINT_UNLOCK(76), // missing, only NPC groups + QUEST_COND_SCENE_LEVEL_TAG_EQ(77), // missing + QUEST_COND_PLAYER_ENTER_REGION(78), // missing + QUEST_COND_UNKNOWN(9999); + + private final int value; + + QuestCond(int id) { + this.value = id; + } + + public int getValue() { + return value; + } + + private static final Int2ObjectMap contentMap = new Int2ObjectOpenHashMap<>(); + private static final Map contentStringMap = new HashMap<>(); + + static { + Stream.of(values()) + .forEach( + e -> { + contentMap.put(e.getValue(), e); + contentStringMap.put(e.name(), e); + }); + } + + public static QuestCond getContentTriggerByValue(int value) { + return contentMap.getOrDefault(value, QUEST_COND_NONE); + } + + public static QuestCond getContentTriggerByName(String name) { + return contentStringMap.getOrDefault(name, QUEST_COND_NONE); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestContent.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestContent.java index 32d67bd55..330c3d33b 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestContent.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestContent.java @@ -1,117 +1,116 @@ -package emu.grasscutter.game.quest.enums; - -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Stream; - -public enum QuestContent implements QuestTrigger { - QUEST_CONTENT_NONE (0), - QUEST_CONTENT_KILL_MONSTER (1), // currently unused - QUEST_CONTENT_COMPLETE_TALK (2), - QUEST_CONTENT_MONSTER_DIE (3), - QUEST_CONTENT_FINISH_PLOT (4), - QUEST_CONTENT_OBTAIN_ITEM (5), - QUEST_CONTENT_TRIGGER_FIRE (6), - QUEST_CONTENT_CLEAR_GROUP_MONSTER (7), - QUEST_CONTENT_NOT_FINISH_PLOT (8), // missing triggers, fail - QUEST_CONTENT_ENTER_DUNGEON (9), - QUEST_CONTENT_ENTER_MY_WORLD (10), - QUEST_CONTENT_FINISH_DUNGEON (11), - QUEST_CONTENT_DESTROY_GADGET (12), - QUEST_CONTENT_OBTAIN_MATERIAL_WITH_SUBTYPE (13), // missing, finish - QUEST_CONTENT_NICK_NAME (14), // missing, currently unused - QUEST_CONTENT_WORKTOP_SELECT (15), // currently unused - QUEST_CONTENT_SEAL_BATTLE_RESULT (16), // missing, currently unused - QUEST_CONTENT_ENTER_ROOM (17), - QUEST_CONTENT_GAME_TIME_TICK (18), - QUEST_CONTENT_FAIL_DUNGEON (19), - QUEST_CONTENT_LUA_NOTIFY (20), - QUEST_CONTENT_TEAM_DEAD (21), // missing, fail - QUEST_CONTENT_COMPLETE_ANY_TALK (22), - QUEST_CONTENT_UNLOCK_TRANS_POINT (23), - QUEST_CONTENT_ADD_QUEST_PROGRESS (24), - QUEST_CONTENT_INTERACT_GADGET (25), - QUEST_CONTENT_DAILY_TASK_COMP_FINISH (26), // missing, currently unused - QUEST_CONTENT_FINISH_ITEM_GIVING (27), // missing, finish - QUEST_CONTENT_SKILL (107), - QUEST_CONTENT_CITY_LEVEL_UP (109), // missing, finish - QUEST_CONTENT_PATTERN_GROUP_CLEAR_MONSTER (110), // missing, finish, for random quests - QUEST_CONTENT_ITEM_LESS_THAN (111), - QUEST_CONTENT_PLAYER_LEVEL_UP (112), - QUEST_CONTENT_DUNGEON_OPEN_STATUE (113), // missing, currently unused - QUEST_CONTENT_UNLOCK_AREA (114), // currently unused - QUEST_CONTENT_OPEN_CHEST_WITH_GADGET_ID (115), // missing, currently unused - QUEST_CONTENT_UNLOCK_TRANS_POINT_WITH_TYPE (116), // missing, currently unused - QUEST_CONTENT_FINISH_DAILY_DUNGEON (117), // missing, currently unused - QUEST_CONTENT_FINISH_WEEKLY_DUNGEON (118), // missing, currently unused - QUEST_CONTENT_QUEST_VAR_EQUAL (119), - QUEST_CONTENT_QUEST_VAR_GREATER (120), - QUEST_CONTENT_QUEST_VAR_LESS (121), - QUEST_CONTENT_OBTAIN_VARIOUS_ITEM (122), // missing, finish - QUEST_CONTENT_FINISH_TOWER_LEVEL (123), // missing, currently unused - QUEST_CONTENT_BARGAIN_SUCC (124), // missing, finish - QUEST_CONTENT_BARGAIN_FAIL (125),// missing, fail - QUEST_CONTENT_ITEM_LESS_THAN_BARGAIN (126),// missing, fail - QUEST_CONTENT_ACTIVITY_TRIGGER_FAILED (127),// missing, fail - QUEST_CONTENT_MAIN_COOP_ENTER_SAVE_POINT (128),// missing, finish - QUEST_CONTENT_ANY_MANUAL_TRANSPORT (129), - QUEST_CONTENT_USE_ITEM (130), - QUEST_CONTENT_MAIN_COOP_ENTER_ANY_SAVE_POINT (131),// missing, finish and fail - QUEST_CONTENT_ENTER_MY_HOME_WORLD (132),// missing, finish and fail - QUEST_CONTENT_ENTER_MY_WORLD_SCENE (133),// missing, finish - QUEST_CONTENT_TIME_VAR_GT_EQ (134), - QUEST_CONTENT_TIME_VAR_PASS_DAY (135), - QUEST_CONTENT_QUEST_STATE_EQUAL (136), - QUEST_CONTENT_QUEST_STATE_NOT_EQUAL (137), - QUEST_CONTENT_UNLOCKED_RECIPE (138),// missing, finish - QUEST_CONTENT_NOT_UNLOCKED_RECIPE (139),// missing, finish - QUEST_CONTENT_FISHING_SUCC (140),// missing, finish - QUEST_CONTENT_ENTER_ROGUE_DUNGEON (141),// missing, finish - QUEST_CONTENT_USE_WIDGET (142),// missing, finish, only in unreleased quest - QUEST_CONTENT_CAPTURE_SUCC (143),// missing, currently unused - QUEST_CONTENT_CAPTURE_USE_CAPTURETAG_LIST (144),// missing, currently unused - QUEST_CONTENT_CAPTURE_USE_MATERIAL_LIST (145),// missing, finish - QUEST_CONTENT_ENTER_VEHICLE (147), - QUEST_CONTENT_SCENE_LEVEL_TAG_EQ (148),// missing, finish - QUEST_CONTENT_LEAVE_SCENE (149), - QUEST_CONTENT_LEAVE_SCENE_RANGE (150),// missing, fail - QUEST_CONTENT_IRODORI_FINISH_FLOWER_COMBINATION (151),// missing, finish - QUEST_CONTENT_IRODORI_POETRY_REACH_MIN_PROGRESS (152),// missing, finish - QUEST_CONTENT_IRODORI_POETRY_FINISH_FILL_POETRY (153),// missing, finish - QUEST_CONTENT_ACTIVITY_TRIGGER_UPDATE(154), // missing - QUEST_CONTENT_GADGET_STATE_CHANGE(155), // missing - QUEST_CONTENT_UNKNOWN (9999); - - private final int value; - - QuestContent(int id) { - this.value = id; - } - - public int getValue() { - return value; - } - - - private static final Int2ObjectMap contentMap = new Int2ObjectOpenHashMap<>(); - private static final Map contentStringMap = new HashMap<>(); - - static { - Stream.of(values()) - .forEach(e -> { - contentMap.put(e.getValue(), e); - contentStringMap.put(e.name(), e); - }); - } - - public static QuestContent getContentTriggerByValue(int value) { - return contentMap.getOrDefault(value, QUEST_CONTENT_NONE); - } - - public static QuestContent getContentTriggerByName(String name) { - return contentStringMap.getOrDefault(name, QUEST_CONTENT_NONE); - } -} +package emu.grasscutter.game.quest.enums; + +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +public enum QuestContent implements QuestTrigger { + QUEST_CONTENT_NONE(0), + QUEST_CONTENT_KILL_MONSTER(1), // currently unused + QUEST_CONTENT_COMPLETE_TALK(2), + QUEST_CONTENT_MONSTER_DIE(3), + QUEST_CONTENT_FINISH_PLOT(4), + QUEST_CONTENT_OBTAIN_ITEM(5), + QUEST_CONTENT_TRIGGER_FIRE(6), + QUEST_CONTENT_CLEAR_GROUP_MONSTER(7), + QUEST_CONTENT_NOT_FINISH_PLOT(8), // missing triggers, fail + QUEST_CONTENT_ENTER_DUNGEON(9), + QUEST_CONTENT_ENTER_MY_WORLD(10), + QUEST_CONTENT_FINISH_DUNGEON(11), + QUEST_CONTENT_DESTROY_GADGET(12), + QUEST_CONTENT_OBTAIN_MATERIAL_WITH_SUBTYPE(13), // missing, finish + QUEST_CONTENT_NICK_NAME(14), // missing, currently unused + QUEST_CONTENT_WORKTOP_SELECT(15), // currently unused + QUEST_CONTENT_SEAL_BATTLE_RESULT(16), // missing, currently unused + QUEST_CONTENT_ENTER_ROOM(17), + QUEST_CONTENT_GAME_TIME_TICK(18), + QUEST_CONTENT_FAIL_DUNGEON(19), + QUEST_CONTENT_LUA_NOTIFY(20), + QUEST_CONTENT_TEAM_DEAD(21), // missing, fail + QUEST_CONTENT_COMPLETE_ANY_TALK(22), + QUEST_CONTENT_UNLOCK_TRANS_POINT(23), + QUEST_CONTENT_ADD_QUEST_PROGRESS(24), + QUEST_CONTENT_INTERACT_GADGET(25), + QUEST_CONTENT_DAILY_TASK_COMP_FINISH(26), // missing, currently unused + QUEST_CONTENT_FINISH_ITEM_GIVING(27), // missing, finish + QUEST_CONTENT_SKILL(107), + QUEST_CONTENT_CITY_LEVEL_UP(109), // missing, finish + QUEST_CONTENT_PATTERN_GROUP_CLEAR_MONSTER(110), // missing, finish, for random quests + QUEST_CONTENT_ITEM_LESS_THAN(111), + QUEST_CONTENT_PLAYER_LEVEL_UP(112), + QUEST_CONTENT_DUNGEON_OPEN_STATUE(113), // missing, currently unused + QUEST_CONTENT_UNLOCK_AREA(114), // currently unused + QUEST_CONTENT_OPEN_CHEST_WITH_GADGET_ID(115), // missing, currently unused + QUEST_CONTENT_UNLOCK_TRANS_POINT_WITH_TYPE(116), // missing, currently unused + QUEST_CONTENT_FINISH_DAILY_DUNGEON(117), // missing, currently unused + QUEST_CONTENT_FINISH_WEEKLY_DUNGEON(118), // missing, currently unused + QUEST_CONTENT_QUEST_VAR_EQUAL(119), + QUEST_CONTENT_QUEST_VAR_GREATER(120), + QUEST_CONTENT_QUEST_VAR_LESS(121), + QUEST_CONTENT_OBTAIN_VARIOUS_ITEM(122), // missing, finish + QUEST_CONTENT_FINISH_TOWER_LEVEL(123), // missing, currently unused + QUEST_CONTENT_BARGAIN_SUCC(124), // missing, finish + QUEST_CONTENT_BARGAIN_FAIL(125), // missing, fail + QUEST_CONTENT_ITEM_LESS_THAN_BARGAIN(126), // missing, fail + QUEST_CONTENT_ACTIVITY_TRIGGER_FAILED(127), // missing, fail + QUEST_CONTENT_MAIN_COOP_ENTER_SAVE_POINT(128), // missing, finish + QUEST_CONTENT_ANY_MANUAL_TRANSPORT(129), + QUEST_CONTENT_USE_ITEM(130), + QUEST_CONTENT_MAIN_COOP_ENTER_ANY_SAVE_POINT(131), // missing, finish and fail + QUEST_CONTENT_ENTER_MY_HOME_WORLD(132), // missing, finish and fail + QUEST_CONTENT_ENTER_MY_WORLD_SCENE(133), // missing, finish + QUEST_CONTENT_TIME_VAR_GT_EQ(134), + QUEST_CONTENT_TIME_VAR_PASS_DAY(135), + QUEST_CONTENT_QUEST_STATE_EQUAL(136), + QUEST_CONTENT_QUEST_STATE_NOT_EQUAL(137), + QUEST_CONTENT_UNLOCKED_RECIPE(138), // missing, finish + QUEST_CONTENT_NOT_UNLOCKED_RECIPE(139), // missing, finish + QUEST_CONTENT_FISHING_SUCC(140), // missing, finish + QUEST_CONTENT_ENTER_ROGUE_DUNGEON(141), // missing, finish + QUEST_CONTENT_USE_WIDGET(142), // missing, finish, only in unreleased quest + QUEST_CONTENT_CAPTURE_SUCC(143), // missing, currently unused + QUEST_CONTENT_CAPTURE_USE_CAPTURETAG_LIST(144), // missing, currently unused + QUEST_CONTENT_CAPTURE_USE_MATERIAL_LIST(145), // missing, finish + QUEST_CONTENT_ENTER_VEHICLE(147), + QUEST_CONTENT_SCENE_LEVEL_TAG_EQ(148), // missing, finish + QUEST_CONTENT_LEAVE_SCENE(149), + QUEST_CONTENT_LEAVE_SCENE_RANGE(150), // missing, fail + QUEST_CONTENT_IRODORI_FINISH_FLOWER_COMBINATION(151), // missing, finish + QUEST_CONTENT_IRODORI_POETRY_REACH_MIN_PROGRESS(152), // missing, finish + QUEST_CONTENT_IRODORI_POETRY_FINISH_FILL_POETRY(153), // missing, finish + QUEST_CONTENT_ACTIVITY_TRIGGER_UPDATE(154), // missing + QUEST_CONTENT_GADGET_STATE_CHANGE(155), // missing + QUEST_CONTENT_UNKNOWN(9999); + + private final int value; + + QuestContent(int id) { + this.value = id; + } + + public int getValue() { + return value; + } + + private static final Int2ObjectMap contentMap = new Int2ObjectOpenHashMap<>(); + private static final Map contentStringMap = new HashMap<>(); + + static { + Stream.of(values()) + .forEach( + e -> { + contentMap.put(e.getValue(), e); + contentStringMap.put(e.name(), e); + }); + } + + public static QuestContent getContentTriggerByValue(int value) { + return contentMap.getOrDefault(value, QUEST_CONTENT_NONE); + } + + public static QuestContent getContentTriggerByName(String name) { + return contentStringMap.getOrDefault(name, QUEST_CONTENT_NONE); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java index 0e67b0030..2a8dccc30 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java @@ -1,112 +1,114 @@ -package emu.grasscutter.game.quest.enums; - -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Stream; - -public enum QuestExec implements QuestTrigger { - QUEST_EXEC_NONE (0), - QUEST_EXEC_DEL_PACK_ITEM (1), - QUEST_EXEC_UNLOCK_POINT (2), - QUEST_EXEC_UNLOCK_AREA (3), - QUEST_EXEC_UNLOCK_FORCE (4), // missing, currently unused - QUEST_EXEC_LOCK_FORCE (5), // missing, currently unused - QUEST_EXEC_CHANGE_AVATAR_ELEMET (6), - QUEST_EXEC_REFRESH_GROUP_MONSTER (7), - QUEST_EXEC_SET_IS_FLYABLE (8), // missing, maybe gives glider - QUEST_EXEC_SET_IS_WEATHER_LOCKED (9), // missing - QUEST_EXEC_SET_IS_GAME_TIME_LOCKED (10), // missing - QUEST_EXEC_SET_IS_TRANSFERABLE (11), // missing, currently unused - QUEST_EXEC_GRANT_TRIAL_AVATAR (12), - QUEST_EXEC_OPEN_BORED (13), // missing, currently unused - QUEST_EXEC_ROLLBACK_QUEST (14), - QUEST_EXEC_NOTIFY_GROUP_LUA (15), - QUEST_EXEC_SET_OPEN_STATE (16), - QUEST_EXEC_LOCK_POINT (17), // missing - QUEST_EXEC_DEL_PACK_ITEM_BATCH (18), - QUEST_EXEC_REFRESH_GROUP_SUITE (19), - QUEST_EXEC_REMOVE_TRIAL_AVATAR (20), - QUEST_EXEC_SET_GAME_TIME (21), // missing - QUEST_EXEC_SET_WEATHER_GADGET (22), // missing - QUEST_EXEC_ADD_QUEST_PROGRESS (23), - QUEST_EXEC_NOTIFY_DAILY_TASK (24), // missing - QUEST_EXEC_CREATE_PATTERN_GROUP (25), // missing, used for random quests - QUEST_EXEC_REMOVE_PATTERN_GROUP (26), // missing, used for random quests - QUEST_EXEC_REFRESH_GROUP_SUITE_RANDOM (27), // missing - QUEST_EXEC_ACTIVE_ITEM_GIVING (28), // missing - QUEST_EXEC_DEL_ALL_SPECIFIC_PACK_ITEM (29), // missing - QUEST_EXEC_ROLLBACK_PARENT_QUEST (30), - QUEST_EXEC_LOCK_AVATAR_TEAM (31), // missing - QUEST_EXEC_UNLOCK_AVATAR_TEAM (32), // missing - QUEST_EXEC_UPDATE_PARENT_QUEST_REWARD_INDEX (33), // missing - QUEST_EXEC_SET_DAILY_TASK_VAR (34), // missing - QUEST_EXEC_INC_DAILY_TASK_VAR (35), // missing - QUEST_EXEC_DEC_DAILY_TASK_VAR (36), // missing, currently unused - QUEST_EXEC_ACTIVE_ACTIVITY_COND_STATE (37), // missing - QUEST_EXEC_INACTIVE_ACTIVITY_COND_STATE (38), // missing - QUEST_EXEC_ADD_CUR_AVATAR_ENERGY (39), - QUEST_EXEC_START_BARGAIN (41), // missing - QUEST_EXEC_STOP_BARGAIN (42), // missing - QUEST_EXEC_SET_QUEST_GLOBAL_VAR (43), - QUEST_EXEC_INC_QUEST_GLOBAL_VAR (44), - QUEST_EXEC_DEC_QUEST_GLOBAL_VAR (45), - QUEST_EXEC_REGISTER_DYNAMIC_GROUP (46), // test, maybe the dynamic should be saved on a list and when you enter the view range this loads it again - QUEST_EXEC_UNREGISTER_DYNAMIC_GROUP (47), // test, same for this - QUEST_EXEC_SET_QUEST_VAR (48), - QUEST_EXEC_INC_QUEST_VAR (49), - QUEST_EXEC_DEC_QUEST_VAR (50), - QUEST_EXEC_RANDOM_QUEST_VAR (51), // missing - QUEST_EXEC_ACTIVATE_SCANNING_PIC (52), // missing, currently unused - QUEST_EXEC_RELOAD_SCENE_TAG (53), // missing - QUEST_EXEC_REGISTER_DYNAMIC_GROUP_ONLY (54), // missing - QUEST_EXEC_CHANGE_SKILL_DEPOT (55), // missing - QUEST_EXEC_ADD_SCENE_TAG (56), // missing - QUEST_EXEC_DEL_SCENE_TAG (57), // missing - QUEST_EXEC_INIT_TIME_VAR (58), - QUEST_EXEC_CLEAR_TIME_VAR (59), - QUEST_EXEC_MODIFY_CLIMATE_AREA (60), // missing - QUEST_EXEC_GRANT_TRIAL_AVATAR_AND_LOCK_TEAM (61), // missing - QUEST_EXEC_CHANGE_MAP_AREA_STATE (62), // missing - QUEST_EXEC_DEACTIVE_ITEM_GIVING (63), // missing - QUEST_EXEC_CHANGE_SCENE_LEVEL_TAG (64), // missing - QUEST_EXEC_UNLOCK_PLAYER_WORLD_SCENE (65), // missing - QUEST_EXEC_LOCK_PLAYER_WORLD_SCENE (66), // missing - QUEST_EXEC_FAIL_MAINCOOP (67), // missing - QUEST_EXEC_MODIFY_WEATHER_AREA (68), // missing - QUEST_EXEC_MODIFY_ARANARA_COLLECTION_STATE (69), // missing - QUEST_EXEC_GRANT_TRIAL_AVATAR_BATCH_AND_LOCK_TEAM (70), // missing - QUEST_EXEC_UNKNOWN (9999); - - private final int value; - - QuestExec(int id) { - this.value = id; - } - - public int getValue() { - return value; - } - - private static final Int2ObjectMap contentMap = new Int2ObjectOpenHashMap<>(); - private static final Map contentStringMap = new HashMap<>(); - - static { - Stream.of(values()) - .filter(e -> e.name().startsWith("QUEST_CONTENT_")) - .forEach(e -> { - contentMap.put(e.getValue(), e); - contentStringMap.put(e.name(), e); - }); - } - - public static QuestExec getContentTriggerByValue(int value) { - return contentMap.getOrDefault(value, QUEST_EXEC_NONE); - } - - public static QuestExec getContentTriggerByName(String name) { - return contentStringMap.getOrDefault(name, QUEST_EXEC_NONE); - } -} +package emu.grasscutter.game.quest.enums; + +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +public enum QuestExec implements QuestTrigger { + QUEST_EXEC_NONE(0), + QUEST_EXEC_DEL_PACK_ITEM(1), + QUEST_EXEC_UNLOCK_POINT(2), + QUEST_EXEC_UNLOCK_AREA(3), + QUEST_EXEC_UNLOCK_FORCE(4), // missing, currently unused + QUEST_EXEC_LOCK_FORCE(5), // missing, currently unused + QUEST_EXEC_CHANGE_AVATAR_ELEMET(6), + QUEST_EXEC_REFRESH_GROUP_MONSTER(7), + QUEST_EXEC_SET_IS_FLYABLE(8), // missing, maybe gives glider + QUEST_EXEC_SET_IS_WEATHER_LOCKED(9), // missing + QUEST_EXEC_SET_IS_GAME_TIME_LOCKED(10), // missing + QUEST_EXEC_SET_IS_TRANSFERABLE(11), // missing, currently unused + QUEST_EXEC_GRANT_TRIAL_AVATAR(12), + QUEST_EXEC_OPEN_BORED(13), // missing, currently unused + QUEST_EXEC_ROLLBACK_QUEST(14), + QUEST_EXEC_NOTIFY_GROUP_LUA(15), + QUEST_EXEC_SET_OPEN_STATE(16), + QUEST_EXEC_LOCK_POINT(17), // missing + QUEST_EXEC_DEL_PACK_ITEM_BATCH(18), + QUEST_EXEC_REFRESH_GROUP_SUITE(19), + QUEST_EXEC_REMOVE_TRIAL_AVATAR(20), + QUEST_EXEC_SET_GAME_TIME(21), // missing + QUEST_EXEC_SET_WEATHER_GADGET(22), // missing + QUEST_EXEC_ADD_QUEST_PROGRESS(23), + QUEST_EXEC_NOTIFY_DAILY_TASK(24), // missing + QUEST_EXEC_CREATE_PATTERN_GROUP(25), // missing, used for random quests + QUEST_EXEC_REMOVE_PATTERN_GROUP(26), // missing, used for random quests + QUEST_EXEC_REFRESH_GROUP_SUITE_RANDOM(27), // missing + QUEST_EXEC_ACTIVE_ITEM_GIVING(28), // missing + QUEST_EXEC_DEL_ALL_SPECIFIC_PACK_ITEM(29), // missing + QUEST_EXEC_ROLLBACK_PARENT_QUEST(30), + QUEST_EXEC_LOCK_AVATAR_TEAM(31), // missing + QUEST_EXEC_UNLOCK_AVATAR_TEAM(32), // missing + QUEST_EXEC_UPDATE_PARENT_QUEST_REWARD_INDEX(33), // missing + QUEST_EXEC_SET_DAILY_TASK_VAR(34), // missing + QUEST_EXEC_INC_DAILY_TASK_VAR(35), // missing + QUEST_EXEC_DEC_DAILY_TASK_VAR(36), // missing, currently unused + QUEST_EXEC_ACTIVE_ACTIVITY_COND_STATE(37), // missing + QUEST_EXEC_INACTIVE_ACTIVITY_COND_STATE(38), // missing + QUEST_EXEC_ADD_CUR_AVATAR_ENERGY(39), + QUEST_EXEC_START_BARGAIN(41), // missing + QUEST_EXEC_STOP_BARGAIN(42), // missing + QUEST_EXEC_SET_QUEST_GLOBAL_VAR(43), + QUEST_EXEC_INC_QUEST_GLOBAL_VAR(44), + QUEST_EXEC_DEC_QUEST_GLOBAL_VAR(45), + QUEST_EXEC_REGISTER_DYNAMIC_GROUP( + 46), // test, maybe the dynamic should be saved on a list and when you enter the view range + // this loads it again + QUEST_EXEC_UNREGISTER_DYNAMIC_GROUP(47), // test, same for this + QUEST_EXEC_SET_QUEST_VAR(48), + QUEST_EXEC_INC_QUEST_VAR(49), + QUEST_EXEC_DEC_QUEST_VAR(50), + QUEST_EXEC_RANDOM_QUEST_VAR(51), // missing + QUEST_EXEC_ACTIVATE_SCANNING_PIC(52), // missing, currently unused + QUEST_EXEC_RELOAD_SCENE_TAG(53), // missing + QUEST_EXEC_REGISTER_DYNAMIC_GROUP_ONLY(54), // missing + QUEST_EXEC_CHANGE_SKILL_DEPOT(55), // missing + QUEST_EXEC_ADD_SCENE_TAG(56), // missing + QUEST_EXEC_DEL_SCENE_TAG(57), // missing + QUEST_EXEC_INIT_TIME_VAR(58), + QUEST_EXEC_CLEAR_TIME_VAR(59), + QUEST_EXEC_MODIFY_CLIMATE_AREA(60), // missing + QUEST_EXEC_GRANT_TRIAL_AVATAR_AND_LOCK_TEAM(61), // missing + QUEST_EXEC_CHANGE_MAP_AREA_STATE(62), // missing + QUEST_EXEC_DEACTIVE_ITEM_GIVING(63), // missing + QUEST_EXEC_CHANGE_SCENE_LEVEL_TAG(64), // missing + QUEST_EXEC_UNLOCK_PLAYER_WORLD_SCENE(65), // missing + QUEST_EXEC_LOCK_PLAYER_WORLD_SCENE(66), // missing + QUEST_EXEC_FAIL_MAINCOOP(67), // missing + QUEST_EXEC_MODIFY_WEATHER_AREA(68), // missing + QUEST_EXEC_MODIFY_ARANARA_COLLECTION_STATE(69), // missing + QUEST_EXEC_GRANT_TRIAL_AVATAR_BATCH_AND_LOCK_TEAM(70), // missing + QUEST_EXEC_UNKNOWN(9999); + + private final int value; + + QuestExec(int id) { + this.value = id; + } + + public int getValue() { + return value; + } + + private static final Int2ObjectMap contentMap = new Int2ObjectOpenHashMap<>(); + private static final Map contentStringMap = new HashMap<>(); + + static { + Stream.of(values()) + .filter(e -> e.name().startsWith("QUEST_CONTENT_")) + .forEach( + e -> { + contentMap.put(e.getValue(), e); + contentStringMap.put(e.name(), e); + }); + } + + public static QuestExec getContentTriggerByValue(int value) { + return contentMap.getOrDefault(value, QUEST_EXEC_NONE); + } + + public static QuestExec getContentTriggerByName(String name) { + return contentStringMap.getOrDefault(name, QUEST_EXEC_NONE); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestState.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestState.java index 0856469ea..3fa314a37 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestState.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestState.java @@ -1,6 +1,8 @@ package emu.grasscutter.game.quest.enums; -public enum QuestState { +import emu.grasscutter.scripts.constants.IntValueEnum; + +public enum QuestState implements IntValueEnum { QUEST_STATE_NONE(0), QUEST_STATE_UNSTARTED(1), QUEST_STATE_UNFINISHED(2), diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestTrigger.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestTrigger.java index f20158929..cdd8d43ec 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestTrigger.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestTrigger.java @@ -1,262 +1,5 @@ package emu.grasscutter.game.quest.enums; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Stream; - -public enum QuestTrigger { - QUEST_COND_NONE(0), - QUEST_COND_STATE_EQUAL(1), - QUEST_COND_STATE_NOT_EQUAL(2), - QUEST_COND_PACK_HAVE_ITEM(3), - QUEST_COND_AVATAR_ELEMENT_EQUAL(4), - QUEST_COND_AVATAR_ELEMENT_NOT_EQUAL(5), - QUEST_COND_AVATAR_CAN_CHANGE_ELEMENT(6), - QUEST_COND_CITY_LEVEL_EQUAL_GREATER(7), - QUEST_COND_ITEM_NUM_LESS_THAN(8), - QUEST_COND_DAILY_TASK_START(9), - QUEST_COND_OPEN_STATE_EQUAL(10), - QUEST_COND_DAILY_TASK_OPEN(11), - QUEST_COND_DAILY_TASK_REWARD_CAN_GET(12), - QUEST_COND_DAILY_TASK_REWARD_RECEIVED(13), - QUEST_COND_PLAYER_LEVEL_REWARD_CAN_GET(14), - QUEST_COND_EXPLORATION_REWARD_CAN_GET(15), - QUEST_COND_IS_WORLD_OWNER(16), - QUEST_COND_PLAYER_LEVEL_EQUAL_GREATER(17), - QUEST_COND_SCENE_AREA_UNLOCKED(18), - QUEST_COND_ITEM_GIVING_ACTIVED(19), - QUEST_COND_ITEM_GIVING_FINISHED(20), - QUEST_COND_IS_DAYTIME(21), - QUEST_COND_CURRENT_AVATAR(22), - QUEST_COND_CURRENT_AREA(23), - QUEST_COND_QUEST_VAR_EQUAL(24), - QUEST_COND_QUEST_VAR_GREATER(25), - QUEST_COND_QUEST_VAR_LESS(26), - QUEST_COND_FORGE_HAVE_FINISH(27), - QUEST_COND_DAILY_TASK_IN_PROGRESS(28), - QUEST_COND_DAILY_TASK_FINISHED(29), - QUEST_COND_ACTIVITY_COND(30), - QUEST_COND_ACTIVITY_OPEN(31), - QUEST_COND_DAILY_TASK_VAR_GT(32), - QUEST_COND_DAILY_TASK_VAR_EQ(33), - QUEST_COND_DAILY_TASK_VAR_LT(34), - QUEST_COND_BARGAIN_ITEM_GT(35), - QUEST_COND_BARGAIN_ITEM_EQ(36), - QUEST_COND_BARGAIN_ITEM_LT(37), - QUEST_COND_COMPLETE_TALK(38), - QUEST_COND_NOT_HAVE_BLOSSOM_TALK(39), - QUEST_COND_IS_CUR_BLOSSOM_TALK(40), - QUEST_COND_QUEST_NOT_RECEIVE(41), - QUEST_COND_QUEST_SERVER_COND_VALID(42), - QUEST_COND_ACTIVITY_CLIENT_COND(43), - QUEST_COND_QUEST_GLOBAL_VAR_EQUAL(44), - QUEST_COND_QUEST_GLOBAL_VAR_GREATER(45), - QUEST_COND_QUEST_GLOBAL_VAR_LESS(46), - QUEST_COND_PERSONAL_LINE_UNLOCK(47), - QUEST_COND_CITY_REPUTATION_REQUEST(48), - QUEST_COND_MAIN_COOP_START(49), - QUEST_COND_MAIN_COOP_ENTER_SAVE_POINT(50), - QUEST_COND_CITY_REPUTATION_LEVEL(51), - QUEST_COND_CITY_REPUTATION_UNLOCK(52), - QUEST_COND_LUA_NOTIFY(53), - QUEST_COND_CUR_CLIMATE(54), - QUEST_COND_ACTIVITY_END(55), - QUEST_COND_COOP_POINT_RUNNING(56), - QUEST_COND_GADGET_TALK_STATE_EQUAL(57), - QUEST_COND_AVATAR_FETTER_GT(58), - QUEST_COND_AVATAR_FETTER_EQ(59), - QUEST_COND_AVATAR_FETTER_LT(60), - QUEST_COND_NEW_HOMEWORLD_MOUDLE_UNLOCK(61), - QUEST_COND_NEW_HOMEWORLD_LEVEL_REWARD(62), - QUEST_COND_NEW_HOMEWORLD_MAKE_FINISH(63), - QUEST_COND_HOMEWORLD_NPC_EVENT(64), - QUEST_COND_TIME_VAR_GT_EQ(65), - QUEST_COND_TIME_VAR_PASS_DAY(66), - QUEST_COND_HOMEWORLD_NPC_NEW_TALK(67), - QUEST_COND_PLAYER_CHOOSE_MALE(68), - QUEST_COND_HISTORY_GOT_ANY_ITEM(69), - QUEST_COND_LEARNED_RECIPE(70), - QUEST_COND_LUNARITE_REGION_UNLOCKED(71), - QUEST_COND_LUNARITE_HAS_REGION_HINT_COUNT(72), - QUEST_COND_LUNARITE_COLLECT_FINISH(73), - QUEST_COND_LUNARITE_MARK_ALL_FINISH(74), - QUEST_COND_NEW_HOMEWORLD_SHOP_ITEM(75), - QUEST_COND_SCENE_POINT_UNLOCK(76), - QUEST_COND_SCENE_LEVEL_TAG_EQ(77), - - QUEST_CONTENT_NONE(0), - QUEST_CONTENT_KILL_MONSTER(1), - QUEST_CONTENT_COMPLETE_TALK(2), - QUEST_CONTENT_MONSTER_DIE(3), - QUEST_CONTENT_FINISH_PLOT(4), - QUEST_CONTENT_OBTAIN_ITEM(5), - QUEST_CONTENT_TRIGGER_FIRE(6), - QUEST_CONTENT_CLEAR_GROUP_MONSTER(7), - QUEST_CONTENT_NOT_FINISH_PLOT(8), - QUEST_CONTENT_ENTER_DUNGEON(9), - QUEST_CONTENT_ENTER_MY_WORLD(10), - QUEST_CONTENT_FINISH_DUNGEON(11), - QUEST_CONTENT_DESTROY_GADGET(12), - QUEST_CONTENT_OBTAIN_MATERIAL_WITH_SUBTYPE(13), - QUEST_CONTENT_NICK_NAME(14), - QUEST_CONTENT_WORKTOP_SELECT(15), - QUEST_CONTENT_SEAL_BATTLE_RESULT(16), - QUEST_CONTENT_ENTER_ROOM(17), - QUEST_CONTENT_GAME_TIME_TICK(18), - QUEST_CONTENT_FAIL_DUNGEON(19), - QUEST_CONTENT_LUA_NOTIFY(20), - QUEST_CONTENT_TEAM_DEAD(21), - QUEST_CONTENT_COMPLETE_ANY_TALK(22), - QUEST_CONTENT_UNLOCK_TRANS_POINT(23), - QUEST_CONTENT_ADD_QUEST_PROGRESS(24), - QUEST_CONTENT_INTERACT_GADGET(25), - QUEST_CONTENT_DAILY_TASK_COMP_FINISH(26), - QUEST_CONTENT_FINISH_ITEM_GIVING(27), - QUEST_CONTENT_SKILL(107), - QUEST_CONTENT_CITY_LEVEL_UP(109), - QUEST_CONTENT_PATTERN_GROUP_CLEAR_MONSTER(110), - QUEST_CONTENT_ITEM_LESS_THAN(111), - QUEST_CONTENT_PLAYER_LEVEL_UP(112), - QUEST_CONTENT_DUNGEON_OPEN_STATUE(113), - QUEST_CONTENT_UNLOCK_AREA(114), - QUEST_CONTENT_OPEN_CHEST_WITH_GADGET_ID(115), - QUEST_CONTENT_UNLOCK_TRANS_POINT_WITH_TYPE(116), - QUEST_CONTENT_FINISH_DAILY_DUNGEON(117), - QUEST_CONTENT_FINISH_WEEKLY_DUNGEON(118), - QUEST_CONTENT_QUEST_VAR_EQUAL(119), - QUEST_CONTENT_QUEST_VAR_GREATER(120), - QUEST_CONTENT_QUEST_VAR_LESS(121), - QUEST_CONTENT_OBTAIN_VARIOUS_ITEM(122), - QUEST_CONTENT_FINISH_TOWER_LEVEL(123), - QUEST_CONTENT_BARGAIN_SUCC(124), - QUEST_CONTENT_BARGAIN_FAIL(125), - QUEST_CONTENT_ITEM_LESS_THAN_BARGAIN(126), - QUEST_CONTENT_ACTIVITY_TRIGGER_FAILED(127), - QUEST_CONTENT_MAIN_COOP_ENTER_SAVE_POINT(128), - QUEST_CONTENT_ANY_MANUAL_TRANSPORT(129), - QUEST_CONTENT_USE_ITEM(130), - QUEST_CONTENT_MAIN_COOP_ENTER_ANY_SAVE_POINT(131), - QUEST_CONTENT_ENTER_MY_HOME_WORLD(132), - QUEST_CONTENT_ENTER_MY_WORLD_SCENE(133), - QUEST_CONTENT_TIME_VAR_GT_EQ(134), - QUEST_CONTENT_TIME_VAR_PASS_DAY(135), - QUEST_CONTENT_QUEST_STATE_EQUAL(136), - QUEST_CONTENT_QUEST_STATE_NOT_EQUAL(137), - QUEST_CONTENT_UNLOCKED_RECIPE(138), - QUEST_CONTENT_NOT_UNLOCKED_RECIPE(139), - QUEST_CONTENT_FISHING_SUCC(140), - QUEST_CONTENT_ENTER_ROGUE_DUNGEON(141), - QUEST_CONTENT_USE_WIDGET(142), - QUEST_CONTENT_CAPTURE_SUCC(143), - QUEST_CONTENT_CAPTURE_USE_CAPTURETAG_LIST(144), - QUEST_CONTENT_CAPTURE_USE_MATERIAL_LIST(145), - QUEST_CONTENT_ENTER_VEHICLE(147), - QUEST_CONTENT_SCENE_LEVEL_TAG_EQ(148), - QUEST_CONTENT_LEAVE_SCENE(149), - QUEST_CONTENT_LEAVE_SCENE_RANGE(150), - QUEST_CONTENT_IRODORI_FINISH_FLOWER_COMBINATION(151), - QUEST_CONTENT_IRODORI_POETRY_REACH_MIN_PROGRESS(152), - QUEST_CONTENT_IRODORI_POETRY_FINISH_FILL_POETRY(153), - - QUEST_EXEC_NONE(0), - QUEST_EXEC_DEL_PACK_ITEM(1), - QUEST_EXEC_UNLOCK_POINT(2), - QUEST_EXEC_UNLOCK_AREA(3), - QUEST_EXEC_UNLOCK_FORCE(4), - QUEST_EXEC_LOCK_FORCE(5), - QUEST_EXEC_CHANGE_AVATAR_ELEMET(6), - QUEST_EXEC_REFRESH_GROUP_MONSTER(7), - QUEST_EXEC_SET_IS_FLYABLE(8), - QUEST_EXEC_SET_IS_WEATHER_LOCKED(9), - QUEST_EXEC_SET_IS_GAME_TIME_LOCKED(10), - QUEST_EXEC_SET_IS_TRANSFERABLE(11), - QUEST_EXEC_GRANT_TRIAL_AVATAR(12), - QUEST_EXEC_OPEN_BORED(13), - QUEST_EXEC_ROLLBACK_QUEST(14), - QUEST_EXEC_NOTIFY_GROUP_LUA(15), - QUEST_EXEC_SET_OPEN_STATE(16), - QUEST_EXEC_LOCK_POINT(17), - QUEST_EXEC_DEL_PACK_ITEM_BATCH(18), - QUEST_EXEC_REFRESH_GROUP_SUITE(19), - QUEST_EXEC_REMOVE_TRIAL_AVATAR(20), - QUEST_EXEC_SET_GAME_TIME(21), - QUEST_EXEC_SET_WEATHER_GADGET(22), - QUEST_EXEC_ADD_QUEST_PROGRESS(23), - QUEST_EXEC_NOTIFY_DAILY_TASK(24), - QUEST_EXEC_CREATE_PATTERN_GROUP(25), - QUEST_EXEC_REMOVE_PATTERN_GROUP(26), - QUEST_EXEC_REFRESH_GROUP_SUITE_RANDOM(27), - QUEST_EXEC_ACTIVE_ITEM_GIVING(28), - QUEST_EXEC_DEL_ALL_SPECIFIC_PACK_ITEM(29), - QUEST_EXEC_ROLLBACK_PARENT_QUEST(30), - QUEST_EXEC_LOCK_AVATAR_TEAM(31), - QUEST_EXEC_UNLOCK_AVATAR_TEAM(32), - QUEST_EXEC_UPDATE_PARENT_QUEST_REWARD_INDEX(33), - QUEST_EXEC_SET_DAILY_TASK_VAR(34), - QUEST_EXEC_INC_DAILY_TASK_VAR(35), - QUEST_EXEC_DEC_DAILY_TASK_VAR(36), - QUEST_EXEC_ACTIVE_ACTIVITY_COND_STATE(37), - QUEST_EXEC_INACTIVE_ACTIVITY_COND_STATE(38), - QUEST_EXEC_ADD_CUR_AVATAR_ENERGY(39), - QUEST_EXEC_START_BARGAIN(41), - QUEST_EXEC_STOP_BARGAIN(42), - QUEST_EXEC_SET_QUEST_GLOBAL_VAR(43), - QUEST_EXEC_INC_QUEST_GLOBAL_VAR(44), - QUEST_EXEC_DEC_QUEST_GLOBAL_VAR(45), - QUEST_EXEC_REGISTER_DYNAMIC_GROUP(46), - QUEST_EXEC_UNREGISTER_DYNAMIC_GROUP(47), - QUEST_EXEC_SET_QUEST_VAR(48), - QUEST_EXEC_INC_QUEST_VAR(49), - QUEST_EXEC_DEC_QUEST_VAR(50), - QUEST_EXEC_RANDOM_QUEST_VAR(51), - QUEST_EXEC_ACTIVATE_SCANNING_PIC(52), - QUEST_EXEC_RELOAD_SCENE_TAG(53), - QUEST_EXEC_REGISTER_DYNAMIC_GROUP_ONLY(54), - QUEST_EXEC_CHANGE_SKILL_DEPOT(55), - QUEST_EXEC_ADD_SCENE_TAG(56), - QUEST_EXEC_DEL_SCENE_TAG(57), - QUEST_EXEC_INIT_TIME_VAR(58), - QUEST_EXEC_CLEAR_TIME_VAR(59), - QUEST_EXEC_MODIFY_CLIMATE_AREA(60), - QUEST_EXEC_GRANT_TRIAL_AVATAR_AND_LOCK_TEAM(61), - QUEST_EXEC_CHANGE_MAP_AREA_STATE(62), - QUEST_EXEC_DEACTIVE_ITEM_GIVING(63), - QUEST_EXEC_CHANGE_SCENE_LEVEL_TAG(64), - QUEST_EXEC_UNLOCK_PLAYER_WORLD_SCENE(65), - QUEST_EXEC_LOCK_PLAYER_WORLD_SCENE(66), - QUEST_EXEC_FAIL_MAINCOOP(67), - QUEST_EXEC_MODIFY_WEATHER_AREA(68); - - private static final Int2ObjectMap contentMap = new Int2ObjectOpenHashMap<>(); - private static final Map contentStringMap = new HashMap<>(); - - static { - Stream.of(values()) - .filter(e -> e.name().startsWith("QUEST_CONTENT_")) - .forEach( - e -> { - contentMap.put(e.getValue(), e); - contentStringMap.put(e.name(), e); - }); - } - - private final int value; - - QuestTrigger(int id) { - this.value = id; - } - - public static QuestTrigger getContentTriggerByValue(int value) { - return contentMap.getOrDefault(value, QUEST_CONTENT_NONE); - } - - public static QuestTrigger getContentTriggerByName(String name) { - return contentStringMap.getOrDefault(name, QUEST_CONTENT_NONE); - } - - public int getValue() { - return value; - } +public interface QuestTrigger { + int getValue(); } diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecAddCurAvatarEnergy.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecAddCurAvatarEnergy.java index 45ba3d572..619fc6d38 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecAddCurAvatarEnergy.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecAddCurAvatarEnergy.java @@ -1,17 +1,17 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; -import emu.grasscutter.Grasscutter; - -@QuestValueExec(QuestExec.QUEST_EXEC_ADD_CUR_AVATAR_ENERGY) -public class ExecAddCurAvatarEnergy extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - Grasscutter.getLogger().info("Energy refilled"); - return quest.getOwner().getEnergyManager().refillEntityAvatarEnergy(); - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; + +@QuestValueExec(QuestExec.QUEST_EXEC_ADD_CUR_AVATAR_ENERGY) +public class ExecAddCurAvatarEnergy extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + Grasscutter.getLogger().info("Energy refilled"); + return quest.getOwner().getEnergyManager().refillEntityAvatarEnergy(); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecAddQuestProgress.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecAddQuestProgress.java index 5ed6c2d25..d3f0ef8c5 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecAddQuestProgress.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecAddQuestProgress.java @@ -2,22 +2,19 @@ package emu.grasscutter.game.quest.exec; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; import emu.grasscutter.game.quest.handlers.QuestExecHandler; import java.util.Arrays; -@QuestValue(QuestTrigger.QUEST_EXEC_ADD_QUEST_PROGRESS) +@QuestValueExec(QuestExec.QUEST_EXEC_ADD_QUEST_PROGRESS) public class ExecAddQuestProgress extends QuestExecHandler { @Override public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { var param = Arrays.stream(paramStr).filter(i -> !i.isBlank()).mapToInt(Integer::parseInt).toArray(); - quest - .getOwner() - .getQuestManager() - .triggerEvent(QuestTrigger.QUEST_CONTENT_ADD_QUEST_PROGRESS, param); + quest.getOwner().getProgressManager().addQuestProgress(param[0], param[1]); return true; } diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecChangeAvatarElemet.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecChangeAvatarElemet.java index 803722b89..6f155a622 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecChangeAvatarElemet.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecChangeAvatarElemet.java @@ -1,31 +1,34 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.props.ElementType; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; -import lombok.val; - -/** - * Changes the main avatar's element. First parameter is the elementType id - */ -@QuestValueExec(QuestExec.QUEST_EXEC_CHANGE_AVATAR_ELEMET) -public class ExecChangeAvatarElemet extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - val targetElement = ElementType.getTypeByValue(Integer.parseInt(paramStr[0])); - val owner = quest.getOwner(); - val mainAvatar = owner.getAvatars().getAvatarById(owner.getMainCharacterId()); - - if(mainAvatar == null){ - Grasscutter.getLogger().error("Failed to get main avatar for use {}", quest.getOwner().getUid()); - return false; - } - - Grasscutter.getLogger().info("Changing avatar element to {} for quest {}", targetElement.name(), quest.getSubQuestId()); - return mainAvatar.changeElement(targetElement); - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.props.ElementType; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; +import lombok.val; + +/** Changes the main avatar's element. First parameter is the elementType id */ +@QuestValueExec(QuestExec.QUEST_EXEC_CHANGE_AVATAR_ELEMET) +public class ExecChangeAvatarElemet extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + val targetElement = ElementType.getTypeByValue(Integer.parseInt(paramStr[0])); + val owner = quest.getOwner(); + val mainAvatar = owner.getAvatars().getAvatarById(owner.getMainCharacterId()); + + if (mainAvatar == null) { + Grasscutter.getLogger() + .error("Failed to get main avatar for use {}", quest.getOwner().getUid()); + return false; + } + + Grasscutter.getLogger() + .info( + "Changing avatar element to {} for quest {}", + targetElement.name(), + quest.getSubQuestId()); + return mainAvatar.changeElement(targetElement); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecClearTimeVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecClearTimeVar.java index e84c61bf5..4adbed69d 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecClearTimeVar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecClearTimeVar.java @@ -1,19 +1,19 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; -import lombok.val; - -@QuestValueExec(QuestExec.QUEST_EXEC_CLEAR_TIME_VAR) -public class ExecClearTimeVar extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - val mainQuestId = Integer.parseInt(condition.getParam()[0]); - val timeVarId = Integer.parseInt(condition.getParam()[1]); - val mainQuest = quest.getOwner().getQuestManager().getMainQuestById(mainQuestId); - return mainQuest.clearTimeVar(timeVarId); - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; +import lombok.val; + +@QuestValueExec(QuestExec.QUEST_EXEC_CLEAR_TIME_VAR) +public class ExecClearTimeVar extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + val mainQuestId = Integer.parseInt(condition.getParam()[0]); + val timeVarId = Integer.parseInt(condition.getParam()[1]); + val mainQuest = quest.getOwner().getQuestManager().getMainQuestById(mainQuestId); + return mainQuest.clearTimeVar(timeVarId); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestGlobalVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestGlobalVar.java index 5d29a8209..12f312d68 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestGlobalVar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestGlobalVar.java @@ -2,11 +2,11 @@ package emu.grasscutter.game.quest.exec; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; import emu.grasscutter.game.quest.handlers.QuestExecHandler; -@QuestValue(QuestTrigger.QUEST_EXEC_DEC_QUEST_GLOBAL_VAR) +@QuestValueExec(QuestExec.QUEST_EXEC_DEC_QUEST_GLOBAL_VAR) public class ExecDecQuestGlobalVar extends QuestExecHandler { @Override public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestVar.java index 7cfd54d22..438df4263 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestVar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestVar.java @@ -1,16 +1,16 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; - -@QuestValue(QuestTrigger.QUEST_EXEC_DEC_QUEST_VAR) -public class ExecDecQuestVar extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - quest.getMainQuest().decQuestVar(Integer.parseInt(paramStr[0]), Integer.parseInt(paramStr[1])); - return true; - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; + +@QuestValueExec(QuestExec.QUEST_EXEC_DEC_QUEST_VAR) +public class ExecDecQuestVar extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + quest.getMainQuest().decQuestVar(Integer.parseInt(paramStr[0]), Integer.parseInt(paramStr[1])); + return true; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecDelPackItem.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecDelPackItem.java index cd2286d1f..b3b30925a 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecDelPackItem.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecDelPackItem.java @@ -1,17 +1,17 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; - -@QuestValueExec(QuestExec.QUEST_EXEC_DEL_PACK_ITEM) -public class ExecDelPackItem extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - int itemId = Integer.parseInt(paramStr[0]); - int amount = Integer.parseInt(paramStr[1]); - return quest.getOwner().getInventory().removeItem(itemId, amount); - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; + +@QuestValueExec(QuestExec.QUEST_EXEC_DEL_PACK_ITEM) +public class ExecDelPackItem extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + int itemId = Integer.parseInt(paramStr[0]); + int amount = Integer.parseInt(paramStr[1]); + return quest.getOwner().getInventory().removeItem(itemId, amount); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecDelPackItemBatch.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecDelPackItemBatch.java index f06b52fe3..229429d73 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecDelPackItemBatch.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecDelPackItemBatch.java @@ -1,26 +1,26 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; - -@QuestValueExec(QuestExec.QUEST_EXEC_DEL_PACK_ITEM_BATCH) -public class ExecDelPackItemBatch extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - // input is like this: "100497:999,100498:999,100499:999" - var items = paramStr[0].split(","); - boolean success = true; - for (var itemString : items){ - var itemFields = itemString.split(":"); - var itemId = Integer.parseInt(itemFields[0]); - var amount = Integer.parseInt(itemFields[1]); - if(!quest.getOwner().getInventory().removeItem(itemId, amount)){ - success = false; - } - } - return success; - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; + +@QuestValueExec(QuestExec.QUEST_EXEC_DEL_PACK_ITEM_BATCH) +public class ExecDelPackItemBatch extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + // input is like this: "100497:999,100498:999,100499:999" + var items = paramStr[0].split(","); + boolean success = true; + for (var itemString : items) { + var itemFields = itemString.split(":"); + var itemId = Integer.parseInt(itemFields[0]); + var amount = Integer.parseInt(itemFields[1]); + if (!quest.getOwner().getInventory().removeItem(itemId, amount)) { + success = false; + } + } + return success; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecGrantTrialAvatar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecGrantTrialAvatar.java index 6b88e7333..e2c5e9da1 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecGrantTrialAvatar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecGrantTrialAvatar.java @@ -1,21 +1,27 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.Grasscutter; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; - -@QuestValueExec(QuestExec.QUEST_EXEC_GRANT_TRIAL_AVATAR) -public class ExecGrantTrialAvatar extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - if (quest.getOwner().addTrialAvatarForQuest(Integer.parseInt(paramStr[0]), quest.getMainQuestId())) { - Grasscutter.getLogger().info("Added trial avatar to team for quest {}", quest.getSubQuestId()); - return true; - } - return false; - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; + +@QuestValueExec(QuestExec.QUEST_EXEC_GRANT_TRIAL_AVATAR) +public class ExecGrantTrialAvatar extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + try { + quest + .getOwner() + .getTeamManager() + .addTrialAvatar(Integer.parseInt(paramStr[0]), quest.getMainQuestId()); + Grasscutter.getLogger() + .debug("Added trial avatar to team for quest {}", quest.getSubQuestId()); + + return true; + } catch (RuntimeException ignored) { + return false; + } + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestGlobalVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestGlobalVar.java index 4d1c32a8f..7fbdbfbeb 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestGlobalVar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestGlobalVar.java @@ -2,11 +2,11 @@ package emu.grasscutter.game.quest.exec; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; import emu.grasscutter.game.quest.handlers.QuestExecHandler; -@QuestValue(QuestTrigger.QUEST_EXEC_INC_QUEST_GLOBAL_VAR) +@QuestValueExec(QuestExec.QUEST_EXEC_INC_QUEST_GLOBAL_VAR) public class ExecIncQuestGlobalVar extends QuestExecHandler { @Override public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestVar.java index 3919b1e38..587a23e25 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestVar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestVar.java @@ -1,16 +1,16 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; - -@QuestValue(QuestTrigger.QUEST_EXEC_INC_QUEST_VAR) -public class ExecIncQuestVar extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - quest.getMainQuest().incQuestVar(Integer.parseInt(paramStr[0]), Integer.parseInt(paramStr[1])); - return true; - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; + +@QuestValueExec(QuestExec.QUEST_EXEC_INC_QUEST_VAR) +public class ExecIncQuestVar extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + quest.getMainQuest().incQuestVar(Integer.parseInt(paramStr[0]), Integer.parseInt(paramStr[1])); + return true; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecInitTimeVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecInitTimeVar.java index 476ea4326..96a838d4a 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecInitTimeVar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecInitTimeVar.java @@ -1,18 +1,18 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; -import lombok.val; - -@QuestValueExec(QuestExec.QUEST_EXEC_INIT_TIME_VAR) -public class ExecInitTimeVar extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - val timeVarId = Integer.parseInt(condition.getParam()[0]); - val mainQuest = quest.getMainQuest(); - return mainQuest.initTimeVar(timeVarId); - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; +import lombok.val; + +@QuestValueExec(QuestExec.QUEST_EXEC_INIT_TIME_VAR) +public class ExecInitTimeVar extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + val timeVarId = Integer.parseInt(condition.getParam()[0]); + val mainQuest = quest.getMainQuest(); + return mainQuest.initTimeVar(timeVarId); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecNotifyGroupLua.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecNotifyGroupLua.java index e0cf9edd3..960f6939f 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecNotifyGroupLua.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecNotifyGroupLua.java @@ -1,31 +1,59 @@ package emu.grasscutter.game.quest.exec; +import emu.grasscutter.Grasscutter; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; import emu.grasscutter.game.quest.enums.QuestState; -import emu.grasscutter.game.quest.enums.QuestTrigger; import emu.grasscutter.game.quest.handlers.QuestExecHandler; import emu.grasscutter.scripts.constants.EventType; import emu.grasscutter.scripts.data.ScriptArgs; +import lombok.val; -@QuestValue(QuestTrigger.QUEST_EXEC_NOTIFY_GROUP_LUA) +@QuestValueExec(QuestExec.QUEST_EXEC_NOTIFY_GROUP_LUA) public class ExecNotifyGroupLua extends QuestExecHandler { @Override public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - var sceneId = Integer.parseInt(paramStr[0]); - var groupId = Integer.parseInt(paramStr[1]); + val sceneId = Integer.parseInt(paramStr[0]); + val groupId = Integer.parseInt(paramStr[1]); - var scriptManager = quest.getOwner().getScene().getScriptManager(); + val scene = quest.getOwner().getScene(); + val scriptManager = scene.getScriptManager(); - if (quest.getOwner().getScene().getId() == sceneId) { - scriptManager.callEvent( - quest.getState() == QuestState.QUEST_STATE_FINISHED - ? EventType.EVENT_QUEST_FINISH - : EventType.EVENT_QUEST_START, - new ScriptArgs()); + if (scene.getId() != sceneId) { + return false; } + scene.runWhenFinished( + () -> { + val groupInstance = scriptManager.getGroupInstanceById(groupId); + + if (groupInstance != null) { + // workaround to make sure the triggers are still there todo find better way of trigger + // handling + scriptManager.refreshGroup(groupInstance); + Grasscutter.getLogger() + .debug( + "group: {} \ncondition: {} \nparamStr {}", + groupInstance.getLuaGroup(), + condition, + paramStr); + } else { + Grasscutter.getLogger() + .warn( + "notify, no group instance for:\n group: {} \ncondition: {} \nparamStr {}", + groupId, + condition, + paramStr); + } + + val eventType = + quest.getState() == QuestState.QUEST_STATE_FINISHED + ? EventType.EVENT_QUEST_FINISH + : EventType.EVENT_QUEST_START; + scriptManager.callEvent(new ScriptArgs(groupId, eventType, quest.getSubQuestId())); + }); return true; } diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecRefreshGroupMonster.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecRefreshGroupMonster.java index b0cf0bf1e..4674b6618 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecRefreshGroupMonster.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecRefreshGroupMonster.java @@ -1,19 +1,18 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; - -@QuestValueExec(QuestExec.QUEST_EXEC_REFRESH_GROUP_MONSTER) -public class ExecRefreshGroupMonster extends QuestExecHandler { - - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - var groupId = Integer.parseInt(paramStr[0]); - - return quest.getOwner().getScene().getScriptManager().refreshGroupMonster(groupId); - } - -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; + +@QuestValueExec(QuestExec.QUEST_EXEC_REFRESH_GROUP_MONSTER) +public class ExecRefreshGroupMonster extends QuestExecHandler { + + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + var groupId = Integer.parseInt(paramStr[0]); + + return quest.getOwner().getScene().getScriptManager().refreshGroupMonster(groupId); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecRefreshGroupSuite.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecRefreshGroupSuite.java index a79c62ad9..2920ed6c8 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecRefreshGroupSuite.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecRefreshGroupSuite.java @@ -2,34 +2,31 @@ package emu.grasscutter.game.quest.exec; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestGroupSuite; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; import emu.grasscutter.game.quest.handlers.QuestExecHandler; -import emu.grasscutter.server.packet.send.PacketGroupSuiteNotify; +import lombok.val; -@QuestValue(QuestTrigger.QUEST_EXEC_REFRESH_GROUP_SUITE) +@QuestValueExec(QuestExec.QUEST_EXEC_REFRESH_GROUP_SUITE) public class ExecRefreshGroupSuite extends QuestExecHandler { @Override public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - var sceneId = Integer.parseInt(paramStr[0]); - var groupId = Integer.parseInt(paramStr[1].split(",")[0]); - var suiteId = Integer.parseInt(paramStr[1].split(",")[1]); + val sceneId = Integer.parseInt(paramStr[0]); + val entries = paramStr[1].split(";"); + val scriptManager = quest.getOwner().getWorld().getSceneById(sceneId).getScriptManager(); - var scriptManager = quest.getOwner().getScene().getScriptManager(); + boolean result = true; + for (var entry : entries) { + val entryArray = entry.split(","); + val groupId = Integer.parseInt(entryArray[0]); + val suiteId = Integer.parseInt(entryArray[1]); - quest - .getMainQuest() - .getQuestGroupSuites() - .add(QuestGroupSuite.of().scene(sceneId).group(groupId).suite(suiteId).build()); - - // refresh immediately if player is in this scene - if (quest.getOwner().getScene().getId() == sceneId) { - scriptManager.refreshGroup(scriptManager.getGroupById(groupId), suiteId); - quest.getOwner().sendPacket(new PacketGroupSuiteNotify(groupId, suiteId)); + if (!scriptManager.refreshGroupSuite(groupId, suiteId, quest)) { + result = false; + } } - return true; + return result; } } diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecRegisterDynamicGroup.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecRegisterDynamicGroup.java index 37beb9550..0112d5524 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecRegisterDynamicGroup.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecRegisterDynamicGroup.java @@ -1,39 +1,38 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestGroupSuite; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; -import emu.grasscutter.game.world.Scene; - -@QuestValueExec(QuestExec.QUEST_EXEC_REGISTER_DYNAMIC_GROUP) -public class ExecRegisterDynamicGroup extends QuestExecHandler { - - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - var sceneId = Integer.parseInt(paramStr[0]); - var groupId = Integer.parseInt(paramStr[1]); - - Grasscutter.getLogger().warn("Registering group {}", groupId); - - Scene scene = quest.getOwner().getWorld().getSceneById(sceneId); - if(scene == null) return false; - - int suiteId = scene.loadDynamicGroup(groupId); - if(suiteId == -1) return false; - - quest.getMainQuest().getQuestGroupSuites().add(QuestGroupSuite.of() - .scene(sceneId) - .group(groupId) - .suite(suiteId) - .build()); - - Grasscutter.getLogger().warn("Registered group {}, suite {} in scene {}", groupId, suiteId, scene.getId()); - - return true; - } - -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestGroupSuite; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; +import emu.grasscutter.game.world.Scene; + +@QuestValueExec(QuestExec.QUEST_EXEC_REGISTER_DYNAMIC_GROUP) +public class ExecRegisterDynamicGroup extends QuestExecHandler { + + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + var sceneId = Integer.parseInt(paramStr[0]); + var groupId = Integer.parseInt(paramStr[1]); + + Grasscutter.getLogger().warn("Registering group {}", groupId); + + Scene scene = quest.getOwner().getWorld().getSceneById(sceneId); + if (scene == null) return false; + + int suiteId = scene.loadDynamicGroup(groupId); + if (suiteId == -1) return false; + + quest + .getMainQuest() + .getQuestGroupSuites() + .add(QuestGroupSuite.of().scene(sceneId).group(groupId).suite(suiteId).build()); + + Grasscutter.getLogger() + .warn("Registered group {}, suite {} in scene {}", groupId, suiteId, scene.getId()); + + return true; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecRemoveTrialAvatar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecRemoveTrialAvatar.java index afa425406..f715c059a 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecRemoveTrialAvatar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecRemoveTrialAvatar.java @@ -1,21 +1,23 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.Grasscutter; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; - -@QuestValueExec(QuestExec.QUEST_EXEC_REMOVE_TRIAL_AVATAR) -public class ExecRemoveTrialAvatar extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - if (quest.getOwner().removeTrialAvatarForQuest(Integer.parseInt(paramStr[0]))) { - Grasscutter.getLogger().info("Removed trial avatar from team for quest {}", quest.getSubQuestId()); - return true; - } - return false; - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; + +@QuestValueExec(QuestExec.QUEST_EXEC_REMOVE_TRIAL_AVATAR) +public class ExecRemoveTrialAvatar extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + try { + quest.getOwner().getTeamManager().removeTrialAvatar(Integer.parseInt(paramStr[0])); + Grasscutter.getLogger() + .debug("Removed trial avatar from team for quest {}", quest.getSubQuestId()); + return true; + } catch (RuntimeException ignored) { + return false; + } + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecRollbackParentQuest.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecRollbackParentQuest.java index 55622b5fd..8c96770b4 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecRollbackParentQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecRollbackParentQuest.java @@ -1,24 +1,24 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; -import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify; - -@QuestValueExec(QuestExec.QUEST_EXEC_ROLLBACK_PARENT_QUEST) -public class ExecRollbackParentQuest extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - var targetPosition = quest.getMainQuest().rewind(); - if(targetPosition == null){ - return false; - } - quest.getOwner().getPosition().set(targetPosition.get(0)); - quest.getOwner().getRotation().set(targetPosition.get(1)); - quest.getOwner().sendPacket(new PacketScenePlayerLocationNotify(quest.getOwner().getScene())); - // todo proper reset and warp - return true; - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; +import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify; + +@QuestValueExec(QuestExec.QUEST_EXEC_ROLLBACK_PARENT_QUEST) +public class ExecRollbackParentQuest extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + var targetPosition = quest.getMainQuest().rewind(); + if (targetPosition == null) { + return false; + } + quest.getOwner().getPosition().set(targetPosition.get(0)); + quest.getOwner().getRotation().set(targetPosition.get(1)); + quest.getOwner().sendPacket(new PacketScenePlayerLocationNotify(quest.getOwner().getScene())); + // todo proper reset and warp + return true; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecRollbackQuest.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecRollbackQuest.java index 109010e63..f3b67da4b 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecRollbackQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecRollbackQuest.java @@ -1,26 +1,26 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; -import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify; - -@QuestValueExec(QuestExec.QUEST_EXEC_ROLLBACK_QUEST) -public class ExecRollbackQuest extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - var targetQuestId = Integer.parseInt(paramStr[0]); - var targetQuest = quest.getOwner().getQuestManager().getQuestById(targetQuestId); - var targetPosition = targetQuest.getMainQuest().rewindTo(targetQuest, true); - if(targetPosition == null){ - return false; - } - quest.getOwner().getPosition().set(targetPosition.get(0)); - quest.getOwner().getRotation().set(targetPosition.get(1)); - quest.getOwner().sendPacket(new PacketScenePlayerLocationNotify(quest.getOwner().getScene())); - // todo proper reset and warp - return true; - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; +import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify; + +@QuestValueExec(QuestExec.QUEST_EXEC_ROLLBACK_QUEST) +public class ExecRollbackQuest extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + var targetQuestId = Integer.parseInt(paramStr[0]); + var targetQuest = quest.getOwner().getQuestManager().getQuestById(targetQuestId); + var targetPosition = targetQuest.getMainQuest().rewindTo(targetQuest, true); + if (targetPosition == null) { + return false; + } + quest.getOwner().getPosition().set(targetPosition.get(0)); + quest.getOwner().getRotation().set(targetPosition.get(1)); + quest.getOwner().sendPacket(new PacketScenePlayerLocationNotify(quest.getOwner().getScene())); + // todo proper reset and warp + return true; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecSetOpenState.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecSetOpenState.java index 5c2ca5005..d53bfbaa6 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecSetOpenState.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecSetOpenState.java @@ -1,24 +1,21 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; -import lombok.val; - -import java.util.Arrays; - -@QuestValueExec(QuestExec.QUEST_EXEC_SET_OPEN_STATE) -public class ExecSetOpenState extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - val param = Arrays.stream(paramStr) - .filter(i -> !i.isBlank()) - .mapToInt(Integer::parseInt) - .toArray(); - - quest.getOwner().getProgressManager().forceSetOpenState(param[0], param[1]); - return true; - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; +import java.util.Arrays; +import lombok.val; + +@QuestValueExec(QuestExec.QUEST_EXEC_SET_OPEN_STATE) +public class ExecSetOpenState extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + val param = + Arrays.stream(paramStr).filter(i -> !i.isBlank()).mapToInt(Integer::parseInt).toArray(); + + quest.getOwner().getProgressManager().forceSetOpenState(param[0], param[1]); + return true; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestGlobalVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestGlobalVar.java index 497faa14c..dcc4ec11b 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestGlobalVar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestGlobalVar.java @@ -2,11 +2,11 @@ package emu.grasscutter.game.quest.exec; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; import emu.grasscutter.game.quest.handlers.QuestExecHandler; -@QuestValue(QuestTrigger.QUEST_EXEC_SET_QUEST_GLOBAL_VAR) +@QuestValueExec(QuestExec.QUEST_EXEC_SET_QUEST_GLOBAL_VAR) public class ExecSetQuestGlobalVar extends QuestExecHandler { @Override public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestVar.java index 6219d913f..bfc0990b1 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestVar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestVar.java @@ -1,16 +1,16 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; - -@QuestValue(QuestTrigger.QUEST_EXEC_SET_QUEST_VAR) -public class ExecSetQuestVar extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - quest.getMainQuest().setQuestVar(Integer.parseInt(paramStr[0]), Integer.parseInt(paramStr[1])); - return true; - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; + +@QuestValueExec(QuestExec.QUEST_EXEC_SET_QUEST_VAR) +public class ExecSetQuestVar extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + quest.getMainQuest().setQuestVar(Integer.parseInt(paramStr[0]), Integer.parseInt(paramStr[1])); + return true; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecUnlockArea.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecUnlockArea.java index fcede0b46..e1620a493 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecUnlockArea.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecUnlockArea.java @@ -2,11 +2,11 @@ package emu.grasscutter.game.quest.exec; import emu.grasscutter.data.excels.QuestData; import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; import emu.grasscutter.game.quest.handlers.QuestExecHandler; -@QuestValue(QuestTrigger.QUEST_EXEC_UNLOCK_AREA) +@QuestValueExec(QuestExec.QUEST_EXEC_UNLOCK_AREA) public class ExecUnlockArea extends QuestExecHandler { @Override public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecUnlockPoint.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecUnlockPoint.java index 204cc1b44..fee1e683c 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecUnlockPoint.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecUnlockPoint.java @@ -1,23 +1,21 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValue; -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; - -@QuestValue(QuestTrigger.QUEST_EXEC_UNLOCK_POINT) -public class ExecUnlockPoint extends QuestExecHandler { - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - // Unlock the trans point for the player. - int sceneId = Integer.parseInt(paramStr[0]); - int pointId = Integer.parseInt(paramStr[1]); - boolean isStatue = quest.getMainQuestId() == 303 || quest.getMainQuestId() == 352; - - quest.getOwner().getProgressManager().unlockTransPoint(sceneId, pointId, isStatue); - - // Done. - return true; - } -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; + +@QuestValueExec(QuestExec.QUEST_EXEC_UNLOCK_POINT) +public class ExecUnlockPoint extends QuestExecHandler { + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + // Unlock the trans point for the player. + int sceneId = Integer.parseInt(paramStr[0]); + int pointId = Integer.parseInt(paramStr[1]); + boolean isStatue = quest.getMainQuestId() == 303 || quest.getMainQuestId() == 352; + + // Done. + return quest.getOwner().getProgressManager().unlockTransPoint(sceneId, pointId, isStatue); + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecUnregisterDynamicGroup.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecUnregisterDynamicGroup.java index 6c5ebc180..b250d15e6 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecUnregisterDynamicGroup.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecUnregisterDynamicGroup.java @@ -1,37 +1,37 @@ -package emu.grasscutter.game.quest.exec; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.excels.QuestData; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.game.quest.QuestValueExec; -import emu.grasscutter.game.quest.enums.QuestExec; -import emu.grasscutter.game.quest.handlers.QuestExecHandler; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.scripts.data.SceneBlock; -import emu.grasscutter.scripts.data.SceneGroup; -import lombok.val; - -@QuestValueExec(QuestExec.QUEST_EXEC_UNREGISTER_DYNAMIC_GROUP) -public class ExecUnregisterDynamicGroup extends QuestExecHandler { - - @Override - public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { - val groupId = Integer.parseInt(paramStr[0]); - val unknownParam = Integer.parseInt(paramStr[1]); //TODO: Goes from 0 to 1, maybe is a boolean. Investigate - val scene = quest.getOwner().getScene(); - - Grasscutter.getLogger().warn("Unregistering group {}", groupId); - - if(!scene.unregisterDynamicGroup(groupId)){ - return false; - } - - //Remove suites if they are registered - quest.getMainQuest().getQuestGroupSuites().removeIf(gs -> gs.getGroup() == groupId && gs.getScene() == scene.getId()); - - Grasscutter.getLogger().warn("Unregistered group {} in scene {}", groupId, scene.getId()); - - return true; - } - -} +package emu.grasscutter.game.quest.exec; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.excels.QuestData; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.game.quest.QuestValueExec; +import emu.grasscutter.game.quest.enums.QuestExec; +import emu.grasscutter.game.quest.handlers.QuestExecHandler; +import lombok.val; + +@QuestValueExec(QuestExec.QUEST_EXEC_UNREGISTER_DYNAMIC_GROUP) +public class ExecUnregisterDynamicGroup extends QuestExecHandler { + + @Override + public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, String... paramStr) { + val groupId = Integer.parseInt(paramStr[0]); + val unknownParam = + Integer.parseInt(paramStr[1]); // TODO: Goes from 0 to 1, maybe is a boolean. Investigate + val scene = quest.getOwner().getScene(); + + Grasscutter.getLogger().warn("Unregistering group {}", groupId); + + if (!scene.unregisterDynamicGroup(groupId)) { + return false; + } + + // Remove suites if they are registered + quest + .getMainQuest() + .getQuestGroupSuites() + .removeIf(gs -> gs.getGroup() == groupId && gs.getScene() == scene.getId()); + + Grasscutter.getLogger().warn("Unregistered group {} in scene {}", groupId, scene.getId()); + + return true; + } +} diff --git a/src/main/java/emu/grasscutter/game/quest/handlers/QuestBaseHandler.java b/src/main/java/emu/grasscutter/game/quest/handlers/QuestBaseHandler.java index 507777979..3365d4fe5 100644 --- a/src/main/java/emu/grasscutter/game/quest/handlers/QuestBaseHandler.java +++ b/src/main/java/emu/grasscutter/game/quest/handlers/QuestBaseHandler.java @@ -3,8 +3,7 @@ package emu.grasscutter.game.quest.handlers; import emu.grasscutter.data.excels.QuestData.QuestCondition; import emu.grasscutter.game.quest.GameQuest; -public abstract class QuestBaseHandler { +public abstract class QuestBaseHandler> { - public abstract boolean execute( - GameQuest quest, QuestCondition condition, String paramStr, int... params); + public abstract boolean execute(GameQuest quest, T condition, String paramStr, int... params); } diff --git a/src/main/java/emu/grasscutter/game/systems/InventorySystem.java b/src/main/java/emu/grasscutter/game/systems/InventorySystem.java index b5fb139c4..5447e5c80 100644 --- a/src/main/java/emu/grasscutter/game/systems/InventorySystem.java +++ b/src/main/java/emu/grasscutter/game/systems/InventorySystem.java @@ -3,10 +3,10 @@ package emu.grasscutter.game.systems; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; import emu.grasscutter.data.common.ItemParamData; -import emu.grasscutter.data.excels.AvatarPromoteData; -import emu.grasscutter.data.excels.AvatarSkillDepotData; import emu.grasscutter.data.excels.ItemData; -import emu.grasscutter.data.excels.WeaponPromoteData; +import emu.grasscutter.data.excels.avatar.AvatarPromoteData; +import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; +import emu.grasscutter.data.excels.weapon.WeaponPromoteData; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.ItemType; diff --git a/src/main/java/emu/grasscutter/game/tower/TowerManager.java b/src/main/java/emu/grasscutter/game/tower/TowerManager.java index 69a444afa..a9c36d70c 100644 --- a/src/main/java/emu/grasscutter/game/tower/TowerManager.java +++ b/src/main/java/emu/grasscutter/game/tower/TowerManager.java @@ -1,7 +1,7 @@ package emu.grasscutter.game.tower; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.TowerLevelData; +import emu.grasscutter.data.excels.tower.TowerLevelData; import emu.grasscutter.game.dungeons.DungeonSettleListener; import emu.grasscutter.game.dungeons.TowerDungeonSettleListener; import emu.grasscutter.game.player.BasePlayerManager; @@ -12,7 +12,6 @@ import java.util.List; import java.util.Map; public class TowerManager extends BasePlayerManager { - private static final List towerDungeonSettleListener = List.of(new TowerDungeonSettleListener()); @@ -21,20 +20,20 @@ public class TowerManager extends BasePlayerManager { } public TowerData getTowerData() { - return getPlayer().getTowerData(); + return this.getPlayer().getTowerData(); } public int getCurrentFloorId() { - return getTowerData().currentFloorId; + return this.getTowerData().currentFloorId; } public int getCurrentLevelId() { - return getTowerData().currentLevelId + getTowerData().currentLevel; + return this.getTowerData().currentLevelId + this.getTowerData().currentLevel; } /** form 1-3 */ public int getCurrentLevel() { - return getTowerData().currentLevel + 1; + return this.getTowerData().currentLevel + 1; } public Map getRecordMap() { @@ -103,7 +102,7 @@ public class TowerManager extends BasePlayerManager { } public void notifyCurLevelRecordChangeWhenDone(int stars) { - Map recordMap = getRecordMap(); + Map recordMap = this.getRecordMap(); int currentFloorId = getTowerData().currentFloorId; if (!recordMap.containsKey(currentFloorId)) { recordMap.put( @@ -114,9 +113,9 @@ public class TowerManager extends BasePlayerManager { currentFloorId, recordMap.get(currentFloorId).setLevelStars(getCurrentLevelId(), stars)); } - getTowerData().currentLevel++; + this.getTowerData().currentLevel++; - if (!hasNextLevel()) { + if (!this.hasNextLevel()) { // set up the next floor var nextFloorId = this.getNextFloorId(); recordMap.computeIfAbsent(nextFloorId, TowerLevelRecord::new); @@ -133,11 +132,18 @@ public class TowerManager extends BasePlayerManager { } public int getNextFloorId() { - return player.getServer().getTowerSystem().getNextFloorId(getTowerData().currentFloorId); + return this.player + .getServer() + .getTowerSystem() + .getNextFloorId(this.getTowerData().currentFloorId); } public boolean hasNextFloor() { - return player.getServer().getTowerSystem().getNextFloorId(getTowerData().currentFloorId) > 0; + return this.player + .getServer() + .getTowerSystem() + .getNextFloorId(this.getTowerData().currentFloorId) + > 0; } public void clearEntry() { @@ -145,11 +151,13 @@ public class TowerManager extends BasePlayerManager { } public boolean canEnterScheduleFloor() { - Map recordMap = getRecordMap(); - if (!recordMap.containsKey(player.getServer().getTowerSystem().getLastEntranceFloor())) { + Map recordMap = this.getRecordMap(); + if (!recordMap.containsKey(this.player.getServer().getTowerSystem().getLastEntranceFloor())) { return false; } - return recordMap.get(player.getServer().getTowerSystem().getLastEntranceFloor()).getStarCount() + return recordMap + .get(this.player.getServer().getTowerSystem().getLastEntranceFloor()) + .getStarCount() >= 6; } diff --git a/src/main/java/emu/grasscutter/game/tower/TowerSystem.java b/src/main/java/emu/grasscutter/game/tower/TowerSystem.java index f9aef2876..681f5e094 100644 --- a/src/main/java/emu/grasscutter/game/tower/TowerSystem.java +++ b/src/main/java/emu/grasscutter/game/tower/TowerSystem.java @@ -3,7 +3,7 @@ package emu.grasscutter.game.tower; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.DataLoader; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.TowerScheduleData; +import emu.grasscutter.data.excels.tower.TowerScheduleData; import emu.grasscutter.server.game.BaseGameSystem; import emu.grasscutter.server.game.GameServer; import java.util.ArrayList; diff --git a/src/main/java/emu/grasscutter/game/world/GroupReplacementData.java b/src/main/java/emu/grasscutter/game/world/GroupReplacementData.java index 13fd157de..f567aabfd 100644 --- a/src/main/java/emu/grasscutter/game/world/GroupReplacementData.java +++ b/src/main/java/emu/grasscutter/game/world/GroupReplacementData.java @@ -1,10 +1,10 @@ -package emu.grasscutter.game.world; - -import java.util.List; -import lombok.Data; - -@Data -public class GroupReplacementData { - int id; - List replace_groups; -} +package emu.grasscutter.game.world; + +import java.util.List; +import lombok.Data; + +@Data +public class GroupReplacementData { + int id; + List replace_groups; +} diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index e39f76d57..a59e5dff9 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -4,10 +4,16 @@ import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameDepot; import emu.grasscutter.data.binout.SceneNpcBornEntry; +import emu.grasscutter.data.binout.routes.Route; import emu.grasscutter.data.excels.*; +import emu.grasscutter.data.excels.codex.CodexAnimalData; +import emu.grasscutter.data.excels.monster.MonsterData; +import emu.grasscutter.data.excels.world.WorldLevelData; import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.dungeons.DungeonManager; import emu.grasscutter.game.dungeons.DungeonSettleListener; import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; import emu.grasscutter.game.entity.*; import emu.grasscutter.game.entity.gadget.GadgetWorktop; import emu.grasscutter.game.managers.blossom.BlossomManager; @@ -28,6 +34,7 @@ import emu.grasscutter.scripts.data.SceneGadget; import emu.grasscutter.scripts.data.SceneGroup; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.Position; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -43,21 +50,25 @@ public class Scene { @Getter private final Set spawnedEntities; @Getter private final Set deadSpawnedEntities; @Getter private final Set loadedBlocks; + @Getter private final Set loadedGroups; @Getter private final BlossomManager blossomManager; + private final HashSet unlockedForces; + private final List afterLoadedCallbacks = new ArrayList<>(); + private final long startWorldTime; + @Getter @Setter DungeonManager dungeonManager; + @Getter Int2ObjectMap sceneRoutes; private Set loadedGridBlocks; @Getter @Setter private boolean dontDestroyWhenEmpty; - - @Getter @Setter private int autoCloseTime; - @Getter @Setter private int time; - private final long startTime; - @Getter private final SceneScriptManager scriptManager; @Getter @Setter private WorldChallenge challenge; @Getter private List dungeonSettleListeners; - @Getter private DungeonData dungeonData; @Getter @Setter private int prevScene; // Id of the previous scene @Getter @Setter private int prevScenePoint; + @Getter @Setter private int killedMonsterCount; private Set npcBornEntrySet; + @Getter private boolean finishedLoading = false; + @Getter private int tickCount = 0; + @Getter private boolean isPaused = false; public Scene(World world, SceneData sceneData) { this.world = world; @@ -65,17 +76,20 @@ public class Scene { this.players = new CopyOnWriteArrayList<>(); this.entities = new ConcurrentHashMap<>(); - this.time = 8 * 60; - this.startTime = System.currentTimeMillis(); this.prevScene = 3; + this.sceneRoutes = GameData.getSceneRoutes(getId()); + + this.startWorldTime = world.getWorldTime(); this.spawnedEntities = ConcurrentHashMap.newKeySet(); this.deadSpawnedEntities = ConcurrentHashMap.newKeySet(); this.loadedBlocks = ConcurrentHashMap.newKeySet(); + this.loadedGroups = ConcurrentHashMap.newKeySet(); this.loadedGridBlocks = new HashSet<>(); this.npcBornEntrySet = ConcurrentHashMap.newKeySet(); this.scriptManager = new SceneScriptManager(this); this.blossomManager = new BlossomManager(this); + this.unlockedForces = new HashSet<>(); } public int getId() { @@ -101,31 +115,55 @@ public class Scene { .orElse(null); } - public void changeTime(int time) { - this.time = time % 1440; - } - - public int getSceneTime() { - return (int) (System.currentTimeMillis() - this.startTime); - } - - public void setDungeonData(DungeonData dungeonData) { - if (dungeonData == null - || this.dungeonData != null - || this.getSceneType() != SceneType.SCENE_DUNGEON - || dungeonData.getSceneId() != this.getId()) { - return; + /** + * Sets the scene's pause state. Sends the current scene's time to all players. + * + * @param paused The new pause state. + */ + public void setPaused(boolean paused) { + if (this.isPaused != paused) { + this.isPaused = paused; + this.broadcastPacket(new PacketSceneTimeNotify(this)); } - this.dungeonData = dungeonData; + } + + /** + * Gets the time in seconds since the scene started. + * + * @return The time in seconds since the scene started. + */ + public int getSceneTime() { + return (int) (this.getWorld().getWorldTime() - this.startWorldTime); + } + + /** + * Gets {@link Scene#getSceneTime()} in seconds. + * + * @return The time in seconds since the scene started. + */ + public int getSceneTimeSeconds() { + return this.getSceneTime() / 1000; } public void addDungeonSettleObserver(DungeonSettleListener dungeonSettleListener) { if (dungeonSettleListeners == null) { dungeonSettleListeners = new ArrayList<>(); } + dungeonSettleListeners.add(dungeonSettleListener); } + /** + * Triggers an event in the dungeon manager. + * + * @param conditionType The condition type to trigger. + * @param params The parameters to pass to the event. + */ + public void triggerDungeonEvent(DungeonPassConditionType conditionType, int... params) { + if (this.dungeonManager == null) return; + this.dungeonManager.triggerEvent(conditionType, params); + } + public boolean isInScene(GameEntity entity) { return this.entities.containsKey(entity.getId()); } diff --git a/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java b/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java index 18fc40ff8..fdf064809 100644 --- a/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java +++ b/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java @@ -1,86 +1,85 @@ -package emu.grasscutter.game.world; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -import org.bson.types.ObjectId; - -import dev.morphia.annotations.Entity; -import dev.morphia.annotations.Id; -import dev.morphia.annotations.Indexed; -import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.scripts.data.SceneGadget; -import emu.grasscutter.scripts.data.SceneGroup; -import lombok.Getter; -import lombok.Setter; - -@Entity(value = "group_instances", useDiscriminator = false) -public class SceneGroupInstance { - @Id private ObjectId id; - - @Indexed private int ownerUid; //This group is owned by the host player - @Getter private int groupId; - - @Getter private transient SceneGroup luaGroup; - @Getter @Setter private int targetSuiteId; - @Getter @Setter private int activeSuiteId; - @Getter private Set deadEntities; //Config_ids - private boolean isCached; - - @Getter private Map cachedGadgetStates; - @Getter private Map cachedVariables; - - @Getter @Setter private int lastTimeRefreshed; - - public SceneGroupInstance(SceneGroup group, Player owner) { - this.luaGroup = group; - this.groupId = group.id; - this.targetSuiteId = 0; - this.activeSuiteId = 0; - this.lastTimeRefreshed = 0; - this.ownerUid = owner.getUid(); - this.deadEntities = new HashSet<>(); - this.cachedGadgetStates = new ConcurrentHashMap<>(); - this.cachedVariables = new ConcurrentHashMap<>(); - - this.isCached = false; //This is true when the group is not loaded on scene but caches suite data - } - - @Deprecated // Morphia only! - SceneGroupInstance(){ - this.cachedVariables = new ConcurrentHashMap<>(); - this.deadEntities = new HashSet<>(); - this.cachedGadgetStates = new ConcurrentHashMap<>(); - } - - public void setLuaGroup(SceneGroup group) { - this.luaGroup = group; - this.groupId = group.id; - } - - public boolean isCached() { - return this.isCached; - } - - public void setCached(boolean value) { - this.isCached = value; - save(); //Save each time a group is registered or unregistered - } - - public void cacheGadgetState(SceneGadget g, int state) { - if(g.persistent) //Only cache when is persistent - cachedGadgetStates.put(g.config_id, state); - } - - public int getCachedGadgetState(SceneGadget g) { - Integer state = cachedGadgetStates.getOrDefault(g.config_id, null); - return (state == null) ? g.state : state; - } - - public void save() { - DatabaseHelper.saveGroupInstance(this); - } -} +package emu.grasscutter.game.world; + +import dev.morphia.annotations.Entity; +import dev.morphia.annotations.Id; +import dev.morphia.annotations.Indexed; +import emu.grasscutter.database.DatabaseHelper; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.scripts.data.SceneGadget; +import emu.grasscutter.scripts.data.SceneGroup; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import lombok.Getter; +import lombok.Setter; +import org.bson.types.ObjectId; + +@Entity(value = "group_instances", useDiscriminator = false) +public class SceneGroupInstance { + @Id private ObjectId id; + + @Indexed private int ownerUid; // This group is owned by the host player + @Getter private int groupId; + + @Getter private transient SceneGroup luaGroup; + @Getter @Setter private int targetSuiteId; + @Getter @Setter private int activeSuiteId; + @Getter private Set deadEntities; // Config_ids + private boolean isCached; + + @Getter private Map cachedGadgetStates; + @Getter private Map cachedVariables; + + @Getter @Setter private int lastTimeRefreshed; + + public SceneGroupInstance(SceneGroup group, Player owner) { + this.luaGroup = group; + this.groupId = group.id; + this.targetSuiteId = 0; + this.activeSuiteId = 0; + this.lastTimeRefreshed = 0; + this.ownerUid = owner.getUid(); + this.deadEntities = new HashSet<>(); + this.cachedGadgetStates = new ConcurrentHashMap<>(); + this.cachedVariables = new ConcurrentHashMap<>(); + + this.isCached = + false; // This is true when the group is not loaded on scene but caches suite data + } + + @Deprecated // Morphia only! + SceneGroupInstance() { + this.cachedVariables = new ConcurrentHashMap<>(); + this.deadEntities = new HashSet<>(); + this.cachedGadgetStates = new ConcurrentHashMap<>(); + } + + public void setLuaGroup(SceneGroup group) { + this.luaGroup = group; + this.groupId = group.id; + } + + public boolean isCached() { + return this.isCached; + } + + public void setCached(boolean value) { + this.isCached = value; + save(); // Save each time a group is registered or unregistered + } + + public void cacheGadgetState(SceneGadget g, int state) { + if (g.persistent) // Only cache when is persistent + cachedGadgetStates.put(g.config_id, state); + } + + public int getCachedGadgetState(SceneGadget g) { + Integer state = cachedGadgetStates.getOrDefault(g.config_id, null); + return (state == null) ? g.state : state; + } + + public void save() { + DatabaseHelper.saveGroupInstance(this); + } +} diff --git a/src/main/java/emu/grasscutter/game/world/World.java b/src/main/java/emu/grasscutter/game/world/World.java index e98e80ea0..c1e0a85c6 100644 --- a/src/main/java/emu/grasscutter/game/world/World.java +++ b/src/main/java/emu/grasscutter/game/world/World.java @@ -1,13 +1,16 @@ package emu.grasscutter.game.world; +import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT; + import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.DungeonData; -import emu.grasscutter.data.excels.SceneData; +import emu.grasscutter.data.excels.dungeon.DungeonData; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player.SceneLoadState; import emu.grasscutter.game.props.EnterReason; import emu.grasscutter.game.props.EntityIdType; import emu.grasscutter.game.props.SceneType; +import emu.grasscutter.game.quest.enums.QuestContent; +import emu.grasscutter.game.world.data.TeleportProperties; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType; import emu.grasscutter.scripts.data.SceneConfig; @@ -15,6 +18,7 @@ import emu.grasscutter.server.event.player.PlayerTeleportEvent; import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.packet.send.*; +import emu.grasscutter.utils.ConversionUtils; import emu.grasscutter.utils.Position; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; @@ -24,26 +28,33 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; +import lombok.Getter; +import lombok.val; public class World implements Iterable { - private final GameServer server; - private final Player owner; - private final List players; - private final Int2ObjectMap scenes; + @Getter private final GameServer server; + @Getter private final Player host; + @Getter private final List players; + @Getter private final Int2ObjectMap scenes; - private final int levelEntityId; + @Getter private final int levelEntityId; private int nextEntityId = 0; private int nextPeerId = 0; private int worldLevel; private final boolean isMultiplayer; + private long lastUpdateTime; + @Getter private int tickCount = 0; + @Getter private boolean isPaused = false; + @Getter private long currentWorldTime = 0; + public World(Player player) { this(player, false); } public World(Player player, boolean isMultiplayer) { - this.owner = player; + this.host = player; this.server = player.getServer(); this.players = Collections.synchronizedList(new ArrayList<>()); this.scenes = Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>()); @@ -52,26 +63,19 @@ public class World implements Iterable { this.worldLevel = player.getWorldLevel(); this.isMultiplayer = isMultiplayer; - this.owner.getServer().registerWorld(this); - } - - public Player getHost() { - return owner; - } - - public GameServer getServer() { - return server; - } - - public int getLevelEntityId() { - return levelEntityId; + this.lastUpdateTime = System.currentTimeMillis(); + this.currentWorldTime = host.getPlayerGameTime(); + + this.host.getServer().registerWorld(this); } + /** + * Gets the peer ID of the world's host. + * + * @return The peer ID of the world's host. 0 if the host is null. + */ public int getHostPeerId() { - if (this.getHost() == null) { - return 0; - } - return this.getHost().getPeerId(); + return this.getHost() == null ? 0 : this.getHost().getPeerId(); } public int getNextPeerId() { @@ -86,23 +90,21 @@ public class World implements Iterable { this.worldLevel = worldLevel; } - public List getPlayers() { - return players; - } - - public Int2ObjectMap getScenes() { - return this.scenes; - } - + /** + * Gets an associated scene by ID. Creates a new instance of the scene if it doesn't exist. + * + * @param sceneId The scene ID. + * @return The scene. + */ public Scene getSceneById(int sceneId) { // Get scene normally - Scene scene = this.getScenes().get(sceneId); + var scene = this.getScenes().get(sceneId); if (scene != null) { return scene; } - // Create scene from scene data if it doesnt exist - SceneData sceneData = GameData.getSceneDataMap().get(sceneId); + // Create scene from scene data if it doesn't exist + var sceneData = GameData.getSceneDataMap().get(sceneId); if (sceneData != null) { scene = new Scene(this, sceneData); this.registerScene(scene); @@ -120,6 +122,12 @@ public class World implements Iterable { return isMultiplayer; } + /** + * Gets the next entity ID for the specified entity type. + * + * @param idType The entity type. + * @return The next entity ID. + */ public int getNextEntityId(EntityIdType idType) { return (idType.getId() << 24) + ++this.nextEntityId; } @@ -231,80 +239,112 @@ public class World implements Iterable { TeleportType teleportType, DungeonData dungeonData, Position teleportTo) { + EnterReason enterReason = + switch (teleportType) { + // shouldn't affect the teleportation, but its clearer when inspecting the packets + // TODO add more conditions for different reason. + case INTERNAL -> EnterReason.TransPoint; + case WAYPOINT -> EnterReason.TransPoint; + case MAP -> EnterReason.TransPoint; + case COMMAND -> EnterReason.Gm; + case SCRIPT -> EnterReason.Lua; + case CLIENT -> EnterReason.ClientTransmit; + case DUNGEON -> EnterReason.DungeonEnter; + default -> EnterReason.None; + }; + return transferPlayerToScene( + player, sceneId, teleportType, enterReason, dungeonData, teleportTo); + } + + public boolean transferPlayerToScene( + Player player, + int sceneId, + TeleportType teleportType, + EnterReason enterReason, + DungeonData dungeonData, + Position teleportTo) { + // Get enter types + val teleportProps = + TeleportProperties.builder() + .sceneId(sceneId) + .teleportType(teleportType) + .enterReason(enterReason) + .teleportTo(teleportTo) + .enterType(EnterType.ENTER_TYPE_JUMP); + + val sceneData = GameData.getSceneDataMap().get(sceneId); + if (dungeonData != null) { + teleportProps.enterType(EnterType.ENTER_TYPE_DUNGEON).enterReason(EnterReason.DungeonEnter); + } else if (player.getSceneId() == sceneId) { + teleportProps.enterType(EnterType.ENTER_TYPE_GOTO); + } else if (sceneData != null && sceneData.getSceneType() == SceneType.SCENE_HOME_WORLD) { + // Home + teleportProps.enterType(EnterType.ENTER_TYPE_SELF_HOME).enterReason(EnterReason.EnterHome); + } + return transferPlayerToScene(player, teleportProps.build()); + } + + public boolean transferPlayerToScene(Player player, TeleportProperties teleportProperties) { // Call player teleport event. PlayerTeleportEvent event = - new PlayerTeleportEvent(player, teleportType, player.getPosition(), teleportTo); + new PlayerTeleportEvent(player, teleportProperties, player.getPosition()); // Call event & check if it was canceled. event.call(); if (event.isCanceled()) { return false; // Teleport was canceled. } - // Set the destination. - teleportTo = event.getDestination(); - - if (GameData.getSceneDataMap().get(sceneId) == null) { + if (GameData.getSceneDataMap().get(teleportProperties.getSceneId()) == null) { return false; } Scene oldScene = null; - if (player.getScene() != null) { oldScene = player.getScene(); // Don't deregister scenes if the player is going to tp back into them - if (oldScene.getId() == sceneId) { + if (oldScene.getId() == teleportProperties.getSceneId()) { oldScene.setDontDestroyWhenEmpty(true); } oldScene.removePlayer(player); } - Scene newScene = this.getSceneById(sceneId); - newScene.setDungeonData(dungeonData); + var newScene = this.getSceneById(teleportProperties.getSceneId()); newScene.addPlayer(player); + player.getTeamManager().applyAbilities(newScene); - // Dungeon SceneConfig config = newScene.getScriptManager().getConfig(); - if (teleportTo == null && config != null) { + if (teleportProperties.getTeleportTo() == null && config != null) { if (config.born_pos != null) { - teleportTo = newScene.getScriptManager().getConfig().born_pos; + teleportProperties.setTeleportTo(newScene.getScriptManager().getConfig().born_pos); } if (config.born_rot != null) { - player.getRotation().set(config.born_rot); + teleportProperties.setTeleportRot(config.born_rot); } } - // Set player position - if (teleportTo == null) { - teleportTo = player.getPosition(); + // Set player position and rotation + if (teleportProperties.getTeleportTo() != null) { + player.getPosition().set(teleportProperties.getTeleportTo()); + } + if (teleportProperties.getTeleportRot() != null) { + player.getRotation().set(teleportProperties.getTeleportRot()); } - player.getPosition().set(teleportTo); - - if (oldScene != null) { + if (oldScene != null && newScene != oldScene) { newScene.setPrevScene(oldScene.getId()); oldScene.setDontDestroyWhenEmpty(false); } - // Get enter types - EnterType enterType = EnterType.ENTER_TYPE_JUMP; - EnterReason enterReason = EnterReason.TransPoint; + // Teleport packet + player.sendPacket(new PacketPlayerEnterSceneNotify(player, teleportProperties)); - if (dungeonData != null) { - enterType = EnterType.ENTER_TYPE_DUNGEON; - enterReason = EnterReason.DungeonEnter; - } else if (oldScene == newScene) { - enterType = EnterType.ENTER_TYPE_GOTO; - } else if (newScene.getSceneType() == SceneType.SCENE_HOME_WORLD) { - // Home - enterReason = EnterReason.EnterHome; - enterType = EnterType.ENTER_TYPE_SELF_HOME; + if (teleportProperties.getTeleportType() != TeleportType.INTERNAL + && teleportProperties.getTeleportType() != SCRIPT) { + player.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_ANY_MANUAL_TRANSPORT); } - // Teleport packet - player.sendPacket( - new PacketPlayerEnterSceneNotify(player, enterType, enterReason, sceneId, teleportTo)); return true; } @@ -347,15 +387,114 @@ public class World implements Iterable { } } - // Returns true if the world should be deleted + /** + * Invoked every game tick. + * + * @return True if the world should be removed. + */ public boolean onTick() { + // Check if there are players in this world. if (this.getPlayerCount() == 0) return true; - this.scenes.forEach((k, scene) -> scene.onTick()); + // Tick all associated scenes. + this.getScenes().forEach((k, scene) -> scene.onTick()); + + // sync time every 10 seconds + if (this.tickCount % 10 == 0) { + this.getPlayers().forEach(p -> p.sendPacket(new PacketPlayerGameTimeNotify(p))); + } + + // store updated world time every 60 seconds. (in-game hour) + if (this.tickCount % 60 == 0) { + this.getHost().updatePlayerGameTime(currentWorldTime); + } + + this.tickCount++; return false; } public void close() {} + /** Returns the in-game world time in real milliseconds. */ + public long getWorldTime() { + if (!this.isPaused) { + var newUpdateTime = System.currentTimeMillis(); + this.currentWorldTime += (newUpdateTime - lastUpdateTime); + this.lastUpdateTime = newUpdateTime; + } + + return currentWorldTime; + } + + /** Returns the current in game days world time in ingame minutes (0-1439) */ + public int getGameTime() { + return (int) (getTotalGameTimeMinutes() % 1440); + } + + /** Returns the current in game days world time in ingame hours (0-23) */ + public int getGameTimeHours() { + return this.getGameTime() / 60; + } + + /** Returns the total number of in game days that got completed since the beginning of the game */ + public long getTotalGameTimeDays() { + return ConversionUtils.gameTimeToDays(getTotalGameTimeMinutes()); + } + + /** + * Returns the total number of in game hours that got completed since the beginning of the game + */ + public long getTotalGameTimeHours() { + return ConversionUtils.gameTimeToHours(getTotalGameTimeMinutes()); + } + + /** Returns the elapsed in-game minutes since the creation of the world. */ + public long getTotalGameTimeMinutes() { + return this.getWorldTime() / 1000; + } + + /** + * Sets the world's pause status. Updates players and scenes accordingly. + * + * @param paused True if the world should be paused. + */ + public void setPaused(boolean paused) { + this.getWorldTime(); // Update the world time. + + // If the world is being un-paused, update the last update time. + if (this.isPaused != paused && !paused) { + this.lastUpdateTime = System.currentTimeMillis(); + } + + this.isPaused = paused; + this.getPlayers().forEach(player -> player.setPaused(paused)); + this.getScenes().forEach((key, scene) -> scene.setPaused(paused)); + } + + /** + * Changes the time of the world. + * + * @param time The new time in minutes. + * @param days The number of days to add. + */ + public void changeTime(int time, int days) { + // Calculate time differences. + var currentTime = this.getGameTime(); + var diff = time - currentTime; + if (diff < 0) diff = 1440 + diff; + + // Update the world time. + this.currentWorldTime += days * 1440 * 1000L + diff * 1000L; + + // Update all players. + this.host.updatePlayerGameTime(currentWorldTime); + this.players.forEach( + player -> + player + .getQuestManager() + .queueEvent( + QuestContent.QUEST_CONTENT_GAME_TIME_TICK, this.getGameTimeHours(), days)); + } + @Override public Iterator iterator() { return this.getPlayers().iterator(); diff --git a/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java b/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java index 28da33333..ca4b79ba4 100644 --- a/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java +++ b/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java @@ -5,7 +5,7 @@ import emu.grasscutter.data.DataLoader; import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.InvestigationMonsterData; import emu.grasscutter.data.excels.RewardPreviewData; -import emu.grasscutter.data.excels.WorldLevelData; +import emu.grasscutter.data.excels.world.WorldLevelData; import emu.grasscutter.game.entity.gadget.chest.BossChestInteractHandler; import emu.grasscutter.game.entity.gadget.chest.ChestInteractHandler; import emu.grasscutter.game.entity.gadget.chest.NormalChestInteractHandler; diff --git a/src/main/java/emu/grasscutter/game/world/data/TeleportProperties.java b/src/main/java/emu/grasscutter/game/world/data/TeleportProperties.java index 283651120..74e8f390b 100644 --- a/src/main/java/emu/grasscutter/game/world/data/TeleportProperties.java +++ b/src/main/java/emu/grasscutter/game/world/data/TeleportProperties.java @@ -1,19 +1,19 @@ -package emu.grasscutter.game.world.data; - -import emu.grasscutter.game.props.EnterReason; -import emu.grasscutter.net.proto.EnterTypeOuterClass; -import emu.grasscutter.server.event.player.PlayerTeleportEvent; -import emu.grasscutter.utils.Position; -import lombok.Builder; -import lombok.Data; - -@Data -@Builder -public class TeleportProperties { - private final int sceneId; - private final PlayerTeleportEvent.TeleportType teleportType; - private final EnterReason enterReason; - private Position teleportTo; - private Position teleportRot; - private EnterTypeOuterClass.EnterType enterType; -} +package emu.grasscutter.game.world.data; + +import emu.grasscutter.game.props.EnterReason; +import emu.grasscutter.net.proto.EnterTypeOuterClass; +import emu.grasscutter.server.event.player.PlayerTeleportEvent; +import emu.grasscutter.utils.Position; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class TeleportProperties { + private final int sceneId; + private final PlayerTeleportEvent.TeleportType teleportType; + private final EnterReason enterReason; + private Position teleportTo; + private Position teleportRot; + private EnterTypeOuterClass.EnterType enterType; +} diff --git a/src/main/java/emu/grasscutter/scripts/EntityControllerScriptManager.java b/src/main/java/emu/grasscutter/scripts/EntityControllerScriptManager.java index fa3321bc0..6e1a9a539 100644 --- a/src/main/java/emu/grasscutter/scripts/EntityControllerScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/EntityControllerScriptManager.java @@ -1,53 +1,54 @@ -package emu.grasscutter.scripts; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.scripts.data.controller.EntityController; -import lombok.val; - -import javax.script.Bindings; -import javax.script.CompiledScript; -import java.io.IOException; -import java.nio.file.Files; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import static emu.grasscutter.utils.FileUtils.getScriptPath; - -public class EntityControllerScriptManager { - private static final Map gadgetController = new ConcurrentHashMap<>(); - - public static void load(){ - cacheGadgetControllers(); - } - - private static void cacheGadgetControllers(){ - try { - Files.newDirectoryStream(getScriptPath("Gadget/"), "*.lua").forEach(path -> { - val fileName = path.getFileName().toString(); - - if(!fileName.endsWith(".lua")) return; - - val controllerName = fileName.substring(0, fileName.length()-4); - CompiledScript cs = ScriptLoader.getScript("Gadget/"+fileName); - Bindings bindings = ScriptLoader.getEngine().createBindings(); - if (cs == null) return; - - try{ - cs.eval(bindings); - gadgetController.put(controllerName, new EntityController(cs, bindings)); - } catch (Throwable e){ - Grasscutter.getLogger().error("Error while loading gadget controller: {}", fileName); - } - }); - - Grasscutter.getLogger().info("Loaded {} gadget controllers", gadgetController.size()); - } catch (IOException e) { - Grasscutter.getLogger().error("Error loading gadget controller luas"); - } - } - - - public static EntityController getGadgetController(String name) { - return gadgetController.get(name); - } -} +package emu.grasscutter.scripts; + +import static emu.grasscutter.utils.FileUtils.getScriptPath; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.scripts.data.controller.EntityController; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import javax.script.Bindings; +import javax.script.CompiledScript; +import lombok.val; + +public class EntityControllerScriptManager { + private static final Map gadgetController = new ConcurrentHashMap<>(); + + public static void load() { + cacheGadgetControllers(); + } + + private static void cacheGadgetControllers() { + try { + Files.newDirectoryStream(getScriptPath("Gadget/"), "*.lua") + .forEach( + path -> { + val fileName = path.getFileName().toString(); + + if (!fileName.endsWith(".lua")) return; + + val controllerName = fileName.substring(0, fileName.length() - 4); + CompiledScript cs = ScriptLoader.getScript("Gadget/" + fileName); + Bindings bindings = ScriptLoader.getEngine().createBindings(); + if (cs == null) return; + + try { + cs.eval(bindings); + gadgetController.put(controllerName, new EntityController(cs, bindings)); + } catch (Throwable e) { + Grasscutter.getLogger() + .error("Error while loading gadget controller: {}", fileName); + } + }); + + Grasscutter.getLogger().info("Loaded {} gadget controllers", gadgetController.size()); + } catch (IOException e) { + Grasscutter.getLogger().error("Error loading gadget controller luas"); + } + } + + public static EntityController getGadgetController(String name) { + return gadgetController.get(name); + } +} diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index 94d4bc295..697a8f20c 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -4,8 +4,8 @@ import com.github.davidmoten.rtreemulti.RTree; import com.github.davidmoten.rtreemulti.geometry.Geometry; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.MonsterData; -import emu.grasscutter.data.excels.WorldLevelData; +import emu.grasscutter.data.excels.monster.MonsterData; +import emu.grasscutter.data.excels.world.WorldLevelData; import emu.grasscutter.game.entity.*; import emu.grasscutter.game.props.EntityType; import emu.grasscutter.game.world.Scene; diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLib.java b/src/main/java/emu/grasscutter/scripts/ScriptLib.java index 58be1a38b..b499ced19 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLib.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLib.java @@ -518,7 +518,7 @@ public class ScriptLib { for (var player : getSceneScriptManager().getScene().getPlayers()) { player.getQuestManager().triggerEvent(QuestTrigger.QUEST_COND_LUA_NOTIFY, var1); - player.getQuestManager().triggerEvent(QuestTrigger.QUEST_CONTENT_LUA_NOTIFY, var1); + player.getQuestManager().triggerEvent(QuestContent.QUEST_CONTENT_LUA_NOTIFY, var1); } return 0; diff --git a/src/main/java/emu/grasscutter/scripts/constants/GroupKillPolicy.java b/src/main/java/emu/grasscutter/scripts/constants/GroupKillPolicy.java index adc6485c9..f274fd98d 100644 --- a/src/main/java/emu/grasscutter/scripts/constants/GroupKillPolicy.java +++ b/src/main/java/emu/grasscutter/scripts/constants/GroupKillPolicy.java @@ -1,9 +1,9 @@ -package emu.grasscutter.scripts.constants; - -public enum GroupKillPolicy { - GROUP_KILL_NONE, - GROUP_KILL_ALL, - GROUP_KILL_MONSTER, - GROUP_KILL_GADGET, - GROUP_KILL_NPC -} +package emu.grasscutter.scripts.constants; + +public enum GroupKillPolicy { + GROUP_KILL_NONE, + GROUP_KILL_ALL, + GROUP_KILL_MONSTER, + GROUP_KILL_GADGET, + GROUP_KILL_NPC +} diff --git a/src/main/java/emu/grasscutter/scripts/constants/IntValueEnum.java b/src/main/java/emu/grasscutter/scripts/constants/IntValueEnum.java index 065465129..420b2c7e3 100644 --- a/src/main/java/emu/grasscutter/scripts/constants/IntValueEnum.java +++ b/src/main/java/emu/grasscutter/scripts/constants/IntValueEnum.java @@ -1,5 +1,5 @@ -package emu.grasscutter.scripts.constants; - -public interface IntValueEnum { - int getValue(); -} +package emu.grasscutter.scripts.constants; + +public interface IntValueEnum { + int getValue(); +} diff --git a/src/main/java/emu/grasscutter/scripts/constants/SealBattleType.java b/src/main/java/emu/grasscutter/scripts/constants/SealBattleType.java index 49af43c6b..b1381a4cc 100644 --- a/src/main/java/emu/grasscutter/scripts/constants/SealBattleType.java +++ b/src/main/java/emu/grasscutter/scripts/constants/SealBattleType.java @@ -1,7 +1,7 @@ -package emu.grasscutter.scripts.constants; - -public enum SealBattleType { - NONE, - ENERGY_CHARGE, - KILL_MONSTER -} +package emu.grasscutter.scripts.constants; + +public enum SealBattleType { + NONE, + ENERGY_CHARGE, + KILL_MONSTER +} diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java b/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java index d5de2beff..1f5a5936c 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java @@ -13,13 +13,10 @@ public class SceneGadget extends SceneObject { public int interact_id; public boolean isOneoff; public int draft_id; - public String drop_tag; - public boolean persistent; - public int mark_flag; public int route_id; - public Explore explore; - public int trigger_count; - public boolean showcutscene; + public boolean start_route = true; + public boolean is_use_point_array = false; + public boolean persistent = false; public void setIsOneoff(boolean isOneoff) { this.isOneoff = isOneoff; diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneReplaceable.java b/src/main/java/emu/grasscutter/scripts/data/SceneReplaceable.java index 1ffa1623e..a011e949b 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneReplaceable.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneReplaceable.java @@ -1,12 +1,12 @@ -package emu.grasscutter.scripts.data; - -import lombok.Setter; -import lombok.ToString; - -@ToString -@Setter -public class SceneReplaceable { - public boolean value; - public int version; - public boolean new_bin_only; -} +package emu.grasscutter.scripts.data; + +import lombok.Setter; +import lombok.ToString; + +@ToString +@Setter +public class SceneReplaceable { + public boolean value; + public int version; + public boolean new_bin_only; +} diff --git a/src/main/java/emu/grasscutter/scripts/data/controller/EntityController.java b/src/main/java/emu/grasscutter/scripts/data/controller/EntityController.java index e48831f94..b42aa5f07 100644 --- a/src/main/java/emu/grasscutter/scripts/data/controller/EntityController.java +++ b/src/main/java/emu/grasscutter/scripts/data/controller/EntityController.java @@ -1,67 +1,104 @@ -package emu.grasscutter.scripts.data.controller; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.game.props.ElementType; -import emu.grasscutter.scripts.ScriptLib; -import emu.grasscutter.scripts.ScriptLoader; -import org.luaj.vm2.LuaError; -import org.luaj.vm2.LuaValue; - -import javax.script.Bindings; -import javax.script.CompiledScript; - -public class EntityController { - private transient CompiledScript entityController; - private transient Bindings entityControllerBindings; - - public EntityController(CompiledScript entityController, Bindings entityControllerBindings){ - this.entityController = entityController; - this.entityControllerBindings = entityControllerBindings; - } - - public void onBeHurt(GameEntity entity, ElementType elementType, boolean isHost) { - callControllerScriptFunc(entity, "OnBeHurt", LuaValue.valueOf(elementType.getValue()), LuaValue.valueOf(0), LuaValue.valueOf(isHost)); - } - - public void onDie(GameEntity entity, ElementType elementType) { - callControllerScriptFunc(entity, "OnDie", LuaValue.valueOf(elementType.getValue()), LuaValue.valueOf(0)); - } - - public void onTimer(GameEntity entity, int now) { - callControllerScriptFunc(entity, "OnTimer", LuaValue.valueOf(now)); - } - - public int onClientExecuteRequest(GameEntity entity, int param1, int param2, int param3) { - Grasscutter.getLogger().debug("Request on {}, {}: {}", entity.getGroupId(), param1, entity.getPosition().toString()); - LuaValue value = callControllerScriptFunc(entity, "OnClientExecuteReq", LuaValue.valueOf(param1), LuaValue.valueOf(param2), LuaValue.valueOf(param3)); - if(value.isint() && value.toint() == 1) return 1; - - return 0; - } - - // TODO actual execution should probably be handle by EntityControllerScriptManager - private LuaValue callControllerScriptFunc(GameEntity entity, String funcName, LuaValue arg1) { return callControllerScriptFunc(entity, funcName, arg1, LuaValue.NIL, LuaValue.NIL); } - private LuaValue callControllerScriptFunc(GameEntity entity, String funcName, LuaValue arg1, LuaValue arg2) { return callControllerScriptFunc(entity, funcName, arg1, arg2, LuaValue.NIL); } - private LuaValue callControllerScriptFunc(GameEntity entity, String funcName, LuaValue arg1, LuaValue arg2, LuaValue arg3) { - LuaValue funcLua = null; - if (funcName != null && !funcName.isEmpty()) { - funcLua = (LuaValue) entityControllerBindings.get(funcName); - } - - LuaValue ret = LuaValue.ONE; - - if (funcLua != null) { - try { - ScriptLoader.getScriptLib().setCurrentEntity(entity); - ret = funcLua.invoke(new LuaValue[]{ScriptLoader.getScriptLibLua(), arg1, arg2, arg3}).arg1(); - }catch (LuaError error) { - ScriptLib.logger.error("[LUA] call function failed in gadget {} with {} {} {},{}", entity.getEntityTypeId(), funcName, arg1, arg2, arg3, error); - ret = LuaValue.valueOf(-1); - } - } else if(funcName != null && !funcName.equals("OnTimer")) { - ScriptLib.logger.error("[LUA] unknown func in gadget {} with {} {} {} {}", entity.getEntityTypeId(), funcName, arg1, arg2, arg3); - } - return ret; - } -} +package emu.grasscutter.scripts.data.controller; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.game.props.ElementType; +import emu.grasscutter.scripts.ScriptLib; +import emu.grasscutter.scripts.ScriptLoader; +import javax.script.Bindings; +import javax.script.CompiledScript; +import org.luaj.vm2.LuaError; +import org.luaj.vm2.LuaValue; + +public class EntityController { + private transient CompiledScript entityController; + private transient Bindings entityControllerBindings; + + public EntityController(CompiledScript entityController, Bindings entityControllerBindings) { + this.entityController = entityController; + this.entityControllerBindings = entityControllerBindings; + } + + public void onBeHurt(GameEntity entity, ElementType elementType, boolean isHost) { + callControllerScriptFunc( + entity, + "OnBeHurt", + LuaValue.valueOf(elementType.getValue()), + LuaValue.valueOf(0), + LuaValue.valueOf(isHost)); + } + + public void onDie(GameEntity entity, ElementType elementType) { + callControllerScriptFunc( + entity, "OnDie", LuaValue.valueOf(elementType.getValue()), LuaValue.valueOf(0)); + } + + public void onTimer(GameEntity entity, int now) { + callControllerScriptFunc(entity, "OnTimer", LuaValue.valueOf(now)); + } + + public int onClientExecuteRequest(GameEntity entity, int param1, int param2, int param3) { + Grasscutter.getLogger() + .debug( + "Request on {}, {}: {}", entity.getGroupId(), param1, entity.getPosition().toString()); + LuaValue value = + callControllerScriptFunc( + entity, + "OnClientExecuteReq", + LuaValue.valueOf(param1), + LuaValue.valueOf(param2), + LuaValue.valueOf(param3)); + if (value.isint() && value.toint() == 1) return 1; + + return 0; + } + + // TODO actual execution should probably be handle by EntityControllerScriptManager + private LuaValue callControllerScriptFunc(GameEntity entity, String funcName, LuaValue arg1) { + return callControllerScriptFunc(entity, funcName, arg1, LuaValue.NIL, LuaValue.NIL); + } + + private LuaValue callControllerScriptFunc( + GameEntity entity, String funcName, LuaValue arg1, LuaValue arg2) { + return callControllerScriptFunc(entity, funcName, arg1, arg2, LuaValue.NIL); + } + + private LuaValue callControllerScriptFunc( + GameEntity entity, String funcName, LuaValue arg1, LuaValue arg2, LuaValue arg3) { + LuaValue funcLua = null; + if (funcName != null && !funcName.isEmpty()) { + funcLua = (LuaValue) entityControllerBindings.get(funcName); + } + + LuaValue ret = LuaValue.ONE; + + if (funcLua != null) { + try { + ScriptLoader.getScriptLib().setCurrentEntity(entity); + ret = + funcLua + .invoke(new LuaValue[] {ScriptLoader.getScriptLibLua(), arg1, arg2, arg3}) + .arg1(); + } catch (LuaError error) { + ScriptLib.logger.error( + "[LUA] call function failed in gadget {} with {} {} {},{}", + entity.getEntityTypeId(), + funcName, + arg1, + arg2, + arg3, + error); + ret = LuaValue.valueOf(-1); + } + } else if (funcName != null && !funcName.equals("OnTimer")) { + ScriptLib.logger.error( + "[LUA] unknown func in gadget {} with {} {} {} {}", + entity.getEntityTypeId(), + funcName, + arg1, + arg2, + arg3); + } + return ret; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerTeleportEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerTeleportEvent.java index ea82b0e11..8eb038103 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerTeleportEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerTeleportEvent.java @@ -1,25 +1,24 @@ package emu.grasscutter.server.event.player; import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.world.data.TeleportProperties; import emu.grasscutter.server.event.Cancellable; import emu.grasscutter.server.event.types.PlayerEvent; import emu.grasscutter.utils.Position; public final class PlayerTeleportEvent extends PlayerEvent implements Cancellable { - private final TeleportType type; + private final TeleportProperties properties; private final Position from; - private Position to; - public PlayerTeleportEvent(Player player, TeleportType type, Position from, Position to) { + public PlayerTeleportEvent(Player player, TeleportProperties properties, Position from) { super(player); - this.type = type; + this.properties = properties; this.from = from; - this.to = to; } public TeleportType getTeleportType() { - return this.type; + return this.properties.getTeleportType(); } public Position getSource() { @@ -27,11 +26,11 @@ public final class PlayerTeleportEvent extends PlayerEvent implements Cancellabl } public Position getDestination() { - return this.to; + return this.properties.getTeleportTo(); } public void setDestination(Position to) { - this.to = to; + this.properties.setTeleportTo(to); } public enum TeleportType { @@ -48,6 +47,12 @@ public final class PlayerTeleportEvent extends PlayerEvent implements Cancellabl DUNGEON, /** The player has asked to teleport using the command. */ - COMMAND + COMMAND, + + /** A script has teleported the player. */ + SCRIPT, + + /** The client has requested to teleport. (script) */ + CLIENT } } diff --git a/src/main/java/emu/grasscutter/server/http/documentation/HandbookRequestHandler.java b/src/main/java/emu/grasscutter/server/http/documentation/HandbookRequestHandler.java index f4737df50..3c3c514f9 100644 --- a/src/main/java/emu/grasscutter/server/http/documentation/HandbookRequestHandler.java +++ b/src/main/java/emu/grasscutter/server/http/documentation/HandbookRequestHandler.java @@ -3,10 +3,10 @@ package emu.grasscutter.server.http.documentation; import emu.grasscutter.Grasscutter; import emu.grasscutter.command.CommandMap; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.AvatarData; import emu.grasscutter.data.excels.ItemData; -import emu.grasscutter.data.excels.MonsterData; import emu.grasscutter.data.excels.SceneData; +import emu.grasscutter.data.excels.avatar.AvatarData; +import emu.grasscutter.data.excels.monster.MonsterData; import emu.grasscutter.utils.FileUtils; import emu.grasscutter.utils.Language; import io.javalin.http.ContentType; diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAddCustomTeamReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAddCustomTeamReq.java index 1f056ec0f..cef3cd99f 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAddCustomTeamReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAddCustomTeamReq.java @@ -1,14 +1,14 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.AddCustomTeamReq) -public class HandlerAddCustomTeamReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.getPlayer().getTeamManager().addNewCustomTeam(); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.AddCustomTeamReq) +public class HandlerAddCustomTeamReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.getPlayer().getTeamManager().addNewCustomTeam(); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarChangeElementTypeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarChangeElementTypeReq.java index b942a491f..6baa9313e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarChangeElementTypeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarChangeElementTypeReq.java @@ -2,8 +2,8 @@ package emu.grasscutter.server.packet.recv; import emu.grasscutter.GameConstants; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.AvatarSkillDepotData; -import emu.grasscutter.data.excels.WorldAreaData; +import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; +import emu.grasscutter.data.excels.world.WorldAreaData; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.net.packet.Opcodes; diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeGameTimeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeGameTimeReq.java index 3081aff75..eb6a0820a 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeGameTimeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeGameTimeReq.java @@ -1,6 +1,5 @@ package emu.grasscutter.server.packet.recv; -import emu.grasscutter.game.quest.enums.QuestTrigger; import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketOpcodes; @@ -13,16 +12,9 @@ public class HandlerChangeGameTimeReq extends PacketHandler { @Override public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ChangeGameTimeReq req = ChangeGameTimeReq.parseFrom(payload); + var req = ChangeGameTimeReq.parseFrom(payload); - session.getPlayer().getScene().changeTime(req.getGameTime()); - session - .getPlayer() - .getQuestManager() - .triggerEvent( - QuestTrigger.QUEST_CONTENT_GAME_TIME_TICK, - req.getGameTime() / 60, // hours - req.getExtraDays()); // days + session.getPlayer().getWorld().changeTime(req.getGameTime(), req.getExtraDays()); session.getPlayer().sendPacket(new PacketChangeGameTimeRsp(session.getPlayer())); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeHomeBgmReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeHomeBgmReq.java index 0ce35064e..a703dcaa5 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeHomeBgmReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeHomeBgmReq.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.Unk2700BEDLIGJANCJClientReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketChangeHomeBgmNotify; -import emu.grasscutter.server.packet.send.PacketChangeHomeBgmRsp; - -@Opcodes(PacketOpcodes.Unk2700_BEDLIGJANCJ_ClientReq) -public class HandlerChangeHomeBgmReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = Unk2700BEDLIGJANCJClientReq.Unk2700_BEDLIGJANCJ_ClientReq.parseFrom(payload); - - int homeBgmId = req.getUnk2700BJHAMKKECEI(); - var home = session.getPlayer().getHome(); - - home.getHomeSceneItem(session.getPlayer().getSceneId()).setHomeBgmId(homeBgmId); - home.save(); - - session.send(new PacketChangeHomeBgmNotify(homeBgmId)); - session.send(new PacketChangeHomeBgmRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.Unk2700BEDLIGJANCJClientReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketChangeHomeBgmNotify; +import emu.grasscutter.server.packet.send.PacketChangeHomeBgmRsp; + +@Opcodes(PacketOpcodes.Unk2700_BEDLIGJANCJ_ClientReq) +public class HandlerChangeHomeBgmReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = Unk2700BEDLIGJANCJClientReq.Unk2700_BEDLIGJANCJ_ClientReq.parseFrom(payload); + + int homeBgmId = req.getUnk2700BJHAMKKECEI(); + var home = session.getPlayer().getHome(); + + home.getHomeSceneItem(session.getPlayer().getSceneId()).setHomeBgmId(homeBgmId); + home.save(); + + session.send(new PacketChangeHomeBgmNotify(homeBgmId)); + session.send(new PacketChangeHomeBgmRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCheckUgcStateReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCheckUgcStateReq.java index 174a022d9..ede1527d0 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCheckUgcStateReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCheckUgcStateReq.java @@ -1,23 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CheckUgcStateReqOuterClass.CheckUgcStateReq; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketCheckUgcStateRsp; -import lombok.val; - -@Opcodes(PacketOpcodes.CheckUgcStateReq) -public class HandlerCheckUgcStateReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - val req = CheckUgcStateReq.parseFrom(payload); - - session.send(new PacketCheckUgcStateRsp(Retcode.RET_SUCC)); - - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CheckUgcStateReqOuterClass.CheckUgcStateReq; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketCheckUgcStateRsp; +import lombok.val; + +@Opcodes(PacketOpcodes.CheckUgcStateReq) +public class HandlerCheckUgcStateReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + val req = CheckUgcStateReq.parseFrom(payload); + + session.send(new PacketCheckUgcStateRsp(Retcode.RET_SUCC)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCheckUgcUpdateReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCheckUgcUpdateReq.java index 59f034180..af0b86e28 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCheckUgcUpdateReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCheckUgcUpdateReq.java @@ -1,20 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CheckUgcUpdateReqOuterClass.CheckUgcUpdateReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketCheckUgcUpdateRsp; - -@Opcodes(PacketOpcodes.CheckUgcUpdateReq) -public class HandlerCheckUgcUpdateReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = CheckUgcUpdateReq.parseFrom(payload); - - session.send(new PacketCheckUgcUpdateRsp(req.getUgcType())); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CheckUgcUpdateReqOuterClass.CheckUgcUpdateReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketCheckUgcUpdateRsp; + +@Opcodes(PacketOpcodes.CheckUgcUpdateReq) +public class HandlerCheckUgcUpdateReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = CheckUgcUpdateReq.parseFrom(payload); + + session.send(new PacketCheckUgcUpdateRsp(req.getUgcType())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonPlayerDieReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonPlayerDieReq.java index 03996439b..ce08e2379 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonPlayerDieReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonPlayerDieReq.java @@ -1,28 +1,25 @@ - -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DungeonPlayerDieReqOuterClass.DungeonPlayerDieReq; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketDungeonPlayerDieRsp; -import lombok.val; - -@Opcodes(PacketOpcodes.DungeonPlayerDieReq) -public class HandlerDungeonPlayerDieReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - DungeonPlayerDieReq req = DungeonPlayerDieReq.parseFrom(payload); - - Player player = session.getPlayer(); - - boolean result = player.getScene().respawnPlayer(player); - - player.sendPacket(new PacketDungeonPlayerDieRsp(result ? Retcode.RET_SUCC : Retcode.RET_FAIL)); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonPlayerDieReqOuterClass.DungeonPlayerDieReq; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketDungeonPlayerDieRsp; + +@Opcodes(PacketOpcodes.DungeonPlayerDieReq) +public class HandlerDungeonPlayerDieReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + DungeonPlayerDieReq req = DungeonPlayerDieReq.parseFrom(payload); + + Player player = session.getPlayer(); + + boolean result = player.getScene().respawnPlayer(player); + + player.sendPacket(new PacketDungeonPlayerDieRsp(result ? Retcode.RET_SUCC : Retcode.RET_FAIL)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonSlipRevivePointActivateReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonSlipRevivePointActivateReq.java index 211029fcf..1c71eb881 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonSlipRevivePointActivateReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonSlipRevivePointActivateReq.java @@ -1,26 +1,25 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DungeonSlipRevivePointActivateReqOuterClass.DungeonSlipRevivePointActivateReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketDungeonSlipRevivePointActivateRsp; - -@Opcodes(PacketOpcodes.DungeonSlipRevivePointActivateReq) -public class HandlerDungeonSlipRevivePointActivateReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = DungeonSlipRevivePointActivateReq.parseFrom(payload); - var dungeonManager = session.getPlayer().getScene().getDungeonManager(); - - boolean success = false; - if (dungeonManager != null) { - success = dungeonManager.activateRespawnPoint(req.getSlipRevivePointId()); - } - - session.send(new PacketDungeonSlipRevivePointActivateRsp(success, req.getSlipRevivePointId())); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonSlipRevivePointActivateReqOuterClass.DungeonSlipRevivePointActivateReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketDungeonSlipRevivePointActivateRsp; + +@Opcodes(PacketOpcodes.DungeonSlipRevivePointActivateReq) +public class HandlerDungeonSlipRevivePointActivateReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = DungeonSlipRevivePointActivateReq.parseFrom(payload); + var dungeonManager = session.getPlayer().getScene().getDungeonManager(); + + boolean success = false; + if (dungeonManager != null) { + success = dungeonManager.activateRespawnPoint(req.getSlipRevivePointId()); + } + + session.send(new PacketDungeonSlipRevivePointActivateRsp(success, req.getSlipRevivePointId())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonWayPointActivateReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonWayPointActivateReq.java index cbea5854d..f5f5fdc6a 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonWayPointActivateReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonWayPointActivateReq.java @@ -1,26 +1,25 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DungeonWayPointActivateReqOuterClass.DungeonWayPointActivateReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketDungeonWayPointActivateRsp; - -@Opcodes(PacketOpcodes.DungeonWayPointActivateReq) -public class HandlerDungeonWayPointActivateReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = DungeonWayPointActivateReq.parseFrom(payload); - var dungeonManager = session.getPlayer().getScene().getDungeonManager(); - - boolean success = false; - if(dungeonManager != null){ - success = dungeonManager.activateRespawnPoint(req.getWayPointId()); - } - - session.send(new PacketDungeonWayPointActivateRsp(success, req.getWayPointId())); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonWayPointActivateReqOuterClass.DungeonWayPointActivateReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketDungeonWayPointActivateRsp; + +@Opcodes(PacketOpcodes.DungeonWayPointActivateReq) +public class HandlerDungeonWayPointActivateReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = DungeonWayPointActivateReq.parseFrom(payload); + var dungeonManager = session.getPlayer().getScene().getDungeonManager(); + + boolean success = false; + if (dungeonManager != null) { + success = dungeonManager.activateRespawnPoint(req.getWayPointId()); + } + + session.send(new PacketDungeonWayPointActivateRsp(success, req.getWayPointId())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterTrialAvatarActivityDungeonReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterTrialAvatarActivityDungeonReq.java index c93f9c651..c68d0bfaa 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterTrialAvatarActivityDungeonReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterTrialAvatarActivityDungeonReq.java @@ -1,33 +1,40 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.activity.trialavatar.TrialAvatarActivityHandler; -import emu.grasscutter.game.props.ActivityType; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.server.packet.send.PacketEnterTrialAvatarActivityDungeonRsp; -import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.EnterTrialAvatarActivityDungeonReqOuterClass.EnterTrialAvatarActivityDungeonReq; -import emu.grasscutter.server.game.GameSession; -import lombok.val; - -@Opcodes(PacketOpcodes.EnterTrialAvatarActivityDungeonReq) -public class HandlerEnterTrialAvatarActivityDungeonReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - val req = EnterTrialAvatarActivityDungeonReq.parseFrom(payload); - - val handler = session.getPlayer().getActivityManager() - .getActivityHandlerAs(ActivityType.NEW_ACTIVITY_TRIAL_AVATAR, TrialAvatarActivityHandler.class); - - boolean result = handler.isPresent() && handler.get().enterTrialDungeon(session.getPlayer(), req.getTrialAvatarIndexId(), req.getEnterPointId()); - - session.getPlayer().sendPacket(new PacketEnterTrialAvatarActivityDungeonRsp( - req.getActivityId(), - req.getTrialAvatarIndexId(), - result)); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.activity.trialavatar.TrialAvatarActivityHandler; +import emu.grasscutter.game.props.ActivityType; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EnterTrialAvatarActivityDungeonReqOuterClass.EnterTrialAvatarActivityDungeonReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketEnterTrialAvatarActivityDungeonRsp; +import lombok.val; + +@Opcodes(PacketOpcodes.EnterTrialAvatarActivityDungeonReq) +public class HandlerEnterTrialAvatarActivityDungeonReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + val req = EnterTrialAvatarActivityDungeonReq.parseFrom(payload); + + val handler = + session + .getPlayer() + .getActivityManager() + .getActivityHandlerAs( + ActivityType.NEW_ACTIVITY_TRIAL_AVATAR, TrialAvatarActivityHandler.class); + + boolean result = + handler.isPresent() + && handler + .get() + .enterTrialDungeon( + session.getPlayer(), req.getTrialAvatarIndexId(), req.getEnterPointId()); + + session + .getPlayer() + .sendPacket( + new PacketEnterTrialAvatarActivityDungeonRsp( + req.getActivityId(), req.getTrialAvatarIndexId(), result)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtDoSkillSuccNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtDoSkillSuccNotify.java index 41293f182..29ceb50a7 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtDoSkillSuccNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtDoSkillSuccNotify.java @@ -1,29 +1,28 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.quest.enums.QuestTrigger; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EvtDoSkillSuccNotifyOuterClass.EvtDoSkillSuccNotify; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.EvtDoSkillSuccNotify) -public class HandlerEvtDoSkillSuccNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - EvtDoSkillSuccNotify notify = EvtDoSkillSuccNotify.parseFrom(payload); - - var player = session.getPlayer(); - int skillId = notify.getSkillId(); - int casterId = notify.getCasterId(); - - // Call skill perform in the player's ability manager. - player.getAbilityManager().onSkillStart(session.getPlayer(), skillId, casterId); - - // Handle skill notify in other managers. - player.getStaminaManager().handleEvtDoSkillSuccNotify(session, skillId, casterId); - player.getEnergyManager().handleEvtDoSkillSuccNotify(session, skillId, casterId); - player.getQuestManager().triggerEvent(QuestTrigger.QUEST_CONTENT_SKILL, skillId, 0); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtDoSkillSuccNotifyOuterClass.EvtDoSkillSuccNotify; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.EvtDoSkillSuccNotify) +public class HandlerEvtDoSkillSuccNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + EvtDoSkillSuccNotify notify = EvtDoSkillSuccNotify.parseFrom(payload); + + var player = session.getPlayer(); + int skillId = notify.getSkillId(); + int casterId = notify.getCasterId(); + + // Call skill perform in the player's ability manager. + player.getAbilityManager().onSkillStart(session.getPlayer(), skillId, casterId); + + // Handle skill notify in other managers. + player.getStaminaManager().handleEvtDoSkillSuccNotify(session, skillId, casterId); + player.getEnergyManager().handleEvtDoSkillSuccNotify(session, skillId, casterId); + player.getQuestManager().triggerEvent(QuestContent.QUEST_CONTENT_SKILL, skillId, 0); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerExecuteGadgetLuaReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerExecuteGadgetLuaReq.java index fcaccbdf6..1ef70e3a1 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerExecuteGadgetLuaReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerExecuteGadgetLuaReq.java @@ -1,30 +1,29 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.game.entity.EntityGadget; -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ExecuteGadgetLuaReqOuterClass.ExecuteGadgetLuaReq; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketExecuteGadgetLuaRsp; - -@Opcodes(PacketOpcodes.ExecuteGadgetLuaReq) -public class HandlerExecuteGadgetLuaReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ExecuteGadgetLuaReq req = ExecuteGadgetLuaReq.parseFrom(payload); - - Player player = session.getPlayer(); - GameEntity entity = player.getScene().getEntities().get(req.getSourceEntityId()); - - int result = 1; - if(entity instanceof EntityGadget gadget) result = gadget.onClientExecuteRequest(req.getParam1(), req.getParam2(), req.getParam3()); - - player.sendPacket(new PacketExecuteGadgetLuaRsp(result)); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.entity.EntityGadget; +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ExecuteGadgetLuaReqOuterClass.ExecuteGadgetLuaReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketExecuteGadgetLuaRsp; + +@Opcodes(PacketOpcodes.ExecuteGadgetLuaReq) +public class HandlerExecuteGadgetLuaReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ExecuteGadgetLuaReq req = ExecuteGadgetLuaReq.parseFrom(payload); + + Player player = session.getPlayer(); + GameEntity entity = player.getScene().getEntities().get(req.getSourceEntityId()); + + int result = 1; + if (entity instanceof EntityGadget gadget) + result = gadget.onClientExecuteRequest(req.getParam1(), req.getParam2(), req.getParam3()); + + player.sendPacket(new PacketExecuteGadgetLuaRsp(result)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerFireWorkReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerFireWorkReq.java index aa7ea26e2..ec9edfb39 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerFireWorkReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerFireWorkReq.java @@ -1,21 +1,20 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.FireWorkReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketFireworkNotify; -import emu.grasscutter.server.packet.send.PacketFireworkRsp; - -@Opcodes(PacketOpcodes.FireworkReq) -public class HandlerFireWorkReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - - var req - = FireWorkReqOuterClass.FireWorkReq.parseFrom(payload); - session.send(new PacketFireworkNotify(req.getFireWorkData())); - session.send(new PacketFireworkRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.FireWorkReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketFireworkNotify; +import emu.grasscutter.server.packet.send.PacketFireworkRsp; + +@Opcodes(PacketOpcodes.FireworkReq) +public class HandlerFireWorkReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + + var req = FireWorkReqOuterClass.FireWorkReq.parseFrom(payload); + session.send(new PacketFireworkNotify(req.getFireWorkData())); + session.send(new PacketFireworkRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerFireworkSetReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerFireworkSetReq.java index ade4f4ced..7f46e6fa4 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerFireworkSetReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerFireworkSetReq.java @@ -1,23 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.FireworkSetReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketFireworkSetNotify; -import emu.grasscutter.server.packet.send.PacketFireworkSetRsp; - -@Opcodes(PacketOpcodes.FireworkSetReq) -public class HandlerFireworkSetReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - - var req - = FireworkSetReqOuterClass.FireworkSetReq.parseFrom(payload); - - - session.send(new PacketFireworkSetNotify(req.getData())); - session.send(new PacketFireworkSetRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.FireworkSetReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketFireworkSetNotify; +import emu.grasscutter.server.packet.send.PacketFireworkSetRsp; + +@Opcodes(PacketOpcodes.FireworkSetReq) +public class HandlerFireworkSetReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + + var req = FireworkSetReqOuterClass.FireworkSetReq.parseFrom(payload); + + session.send(new PacketFireworkSetNotify(req.getData())); + session.send(new PacketFireworkSetRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGadgetInteractReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGadgetInteractReq.java index 91be3e59c..10c6040f7 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGadgetInteractReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGadgetInteractReq.java @@ -1,6 +1,5 @@ package emu.grasscutter.server.packet.recv; -import emu.grasscutter.game.quest.enums.QuestTrigger; import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketOpcodes; @@ -17,7 +16,7 @@ public class HandlerGadgetInteractReq extends PacketHandler { session .getPlayer() .getQuestManager() - .triggerEvent(QuestTrigger.QUEST_CONTENT_INTERACT_GADGET, req.getGadgetId()); + .triggerEvent(QuestContent.QUEST_CONTENT_INTERACT_GADGET, req.getGadgetId()); session.getPlayer().interactWith(req.getGadgetEntityId(), req); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetUgcBriefInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetUgcBriefInfoReq.java index 4d7656ea7..69969f212 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetUgcBriefInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetUgcBriefInfoReq.java @@ -1,33 +1,33 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetUgcBriefInfoReqOuterClass; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.UgcTypeOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetUgcBriefInfoRsp; - -@Opcodes(PacketOpcodes.GetUgcBriefInfoReq) -public class HandlerGetUgcBriefInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = GetUgcBriefInfoReqOuterClass.GetUgcBriefInfoReq.parseFrom(payload); - - if(req.getUgcType() == UgcTypeOuterClass.UgcType.UGC_TYPE_MUSIC_GAME){ - var musicGameBeatmap = MusicGameBeatmap.getByShareId(req.getUgcGuid()); - - if(musicGameBeatmap != null){ - session.send(new PacketGetUgcBriefInfoRsp(musicGameBeatmap.toBriefProto().build(), req.getUgcType())); - return; - } - } - - session.send(new PacketGetUgcBriefInfoRsp(Retcode.RET_UGC_BRIEF_NOT_FOUND, req.getUgcType())); - - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetUgcBriefInfoReqOuterClass; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import emu.grasscutter.net.proto.UgcTypeOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetUgcBriefInfoRsp; + +@Opcodes(PacketOpcodes.GetUgcBriefInfoReq) +public class HandlerGetUgcBriefInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = GetUgcBriefInfoReqOuterClass.GetUgcBriefInfoReq.parseFrom(payload); + + if (req.getUgcType() == UgcTypeOuterClass.UgcType.UGC_TYPE_MUSIC_GAME) { + var musicGameBeatmap = MusicGameBeatmap.getByShareId(req.getUgcGuid()); + + if (musicGameBeatmap != null) { + session.send( + new PacketGetUgcBriefInfoRsp( + musicGameBeatmap.toBriefProto().build(), req.getUgcType())); + return; + } + } + + session.send(new PacketGetUgcBriefInfoRsp(Retcode.RET_UGC_BRIEF_NOT_FOUND, req.getUgcType())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetUgcReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetUgcReq.java index ff6ddd02b..e500dc99e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetUgcReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetUgcReq.java @@ -1,48 +1,39 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.UgcTypeOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetUgcRsp; -import emu.grasscutter.net.proto.GetUgcReqOuterClass.GetUgcReq; -import lombok.val; - -@Opcodes(PacketOpcodes.GetUgcReq) -public class HandlerGetUgcReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - val req = GetUgcReq.parseFrom(payload); - - PacketGetUgcRsp rsp = null; - - if(req.getUgcType() == UgcTypeOuterClass.UgcType.UGC_TYPE_MUSIC_GAME) { - val musicGameBeatmap = MusicGameBeatmap.getByShareId(req.getUgcGuid()); - - if (musicGameBeatmap != null) { - rsp = new PacketGetUgcRsp( - musicGameBeatmap.toBriefProto().build(), - musicGameBeatmap.toProto(), - req - ); - } else { - rsp = new PacketGetUgcRsp( - RetcodeOuterClass.Retcode.RET_UGC_DATA_NOT_FOUND, - req - ); - } - }else { - rsp = new PacketGetUgcRsp( - RetcodeOuterClass.Retcode.RET_UGC_DISABLED, - req - ); - } - - session.send(rsp); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetUgcReqOuterClass.GetUgcReq; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.UgcTypeOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetUgcRsp; +import lombok.val; + +@Opcodes(PacketOpcodes.GetUgcReq) +public class HandlerGetUgcReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + val req = GetUgcReq.parseFrom(payload); + + PacketGetUgcRsp rsp = null; + + if (req.getUgcType() == UgcTypeOuterClass.UgcType.UGC_TYPE_MUSIC_GAME) { + val musicGameBeatmap = MusicGameBeatmap.getByShareId(req.getUgcGuid()); + + if (musicGameBeatmap != null) { + rsp = + new PacketGetUgcRsp( + musicGameBeatmap.toBriefProto().build(), musicGameBeatmap.toProto(), req); + } else { + rsp = new PacketGetUgcRsp(RetcodeOuterClass.Retcode.RET_UGC_DATA_NOT_FOUND, req); + } + } else { + rsp = new PacketGetUgcRsp(RetcodeOuterClass.Retcode.RET_UGC_DISABLED, req); + } + + session.send(rsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUnknown2Req.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUnknown2Req.java index 467449067..3ca10158f 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUnknown2Req.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUnknown2Req.java @@ -1,20 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeUnknown2Rsp; - -@Opcodes(PacketOpcodes.Unk2700_ACILPONNGGK_ClientReq) -public class HandlerHomeUnknown2Req extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - /* - * This packet is about the edit mode - */ - session.send(new PacketHomeUnknown2Rsp()); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeUnknown2Rsp; + +@Opcodes(PacketOpcodes.Unk2700_ACILPONNGGK_ClientReq) +public class HandlerHomeUnknown2Req extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + /* + * This packet is about the edit mode + */ + session.send(new PacketHomeUnknown2Rsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerNpcTalkReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerNpcTalkReq.java index a95cd8c14..5ba4bd6bd 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerNpcTalkReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerNpcTalkReq.java @@ -3,7 +3,6 @@ package emu.grasscutter.server.packet.recv; import emu.grasscutter.data.GameData; import emu.grasscutter.data.binout.MainQuestData; import emu.grasscutter.data.binout.MainQuestData.TalkData; -import emu.grasscutter.game.quest.enums.QuestTrigger; import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketOpcodes; @@ -51,15 +50,15 @@ public class HandlerNpcTalkReq extends PacketHandler { .getPlayer() .getQuestManager() .triggerEvent( - QuestTrigger.QUEST_CONTENT_COMPLETE_ANY_TALK, String.valueOf(req.getTalkId()), 0, 0); + QuestContent.QUEST_CONTENT_COMPLETE_ANY_TALK, String.valueOf(req.getTalkId()), 0, 0); session .getPlayer() .getQuestManager() - .triggerEvent(QuestTrigger.QUEST_CONTENT_COMPLETE_TALK, req.getTalkId(), 0); + .triggerEvent(QuestContent.QUEST_CONTENT_COMPLETE_TALK, req.getTalkId(), 0); session .getPlayer() .getQuestManager() - .triggerEvent(QuestTrigger.QUEST_CONTENT_FINISH_PLOT, req.getTalkId(), 0); + .triggerEvent(QuestContent.QUEST_CONTENT_FINISH_PLOT, req.getTalkId(), 0); } session.send(new PacketNpcTalkRsp(req.getNpcEntityId(), req.getTalkId(), req.getEntityId())); diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPostEnterSceneReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPostEnterSceneReq.java index e6a1618e7..b1f1f7482 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPostEnterSceneReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPostEnterSceneReq.java @@ -1,7 +1,6 @@ package emu.grasscutter.server.packet.recv; import emu.grasscutter.game.props.SceneType; -import emu.grasscutter.game.quest.enums.QuestTrigger; import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketOpcodes; @@ -17,7 +16,7 @@ public class HandlerPostEnterSceneReq extends PacketHandler { session .getPlayer() .getQuestManager() - .triggerEvent(QuestTrigger.QUEST_CONTENT_ENTER_ROOM, session.getPlayer().getSceneId(), 0); + .triggerEvent(QuestContent.QUEST_CONTENT_ENTER_ROOM, session.getPlayer().getSceneId(), 0); } session.send(new PacketPostEnterSceneRsp(session.getPlayer())); diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestCreateEntityReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestCreateEntityReq.java index ff2c93e04..3172f9689 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestCreateEntityReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestCreateEntityReq.java @@ -1,63 +1,62 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.GadgetData; -import emu.grasscutter.data.excels.ItemData; -import emu.grasscutter.data.excels.MonsterData; -import emu.grasscutter.game.entity.*; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketQuestCreateEntityRsp; -import emu.grasscutter.utils.Position; -import lombok.val; -import emu.grasscutter.net.proto.QuestCreateEntityReqOuterClass.QuestCreateEntityReq; - -@Opcodes(PacketOpcodes.QuestCreateEntityReq) -public class HandlerQuestCreateEntityReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - val req = QuestCreateEntityReq.parseFrom(payload); - val entity = req.getEntity(); - val scene = session.getPlayer().getWorld().getSceneById(entity.getSceneId()); - - val pos = new Position(entity.getPos()); - val rot = new Position(entity.getRot()); - GameEntity gameEntity = null; - switch (entity.getEntityCase()){ - case GADGET_ID -> { - val gadgetId = entity.getGadgetId(); - val gadgetInfo = entity.getGadget(); - GadgetData gadgetData = GameData.getGadgetDataMap().get(gadgetId); - gameEntity = switch (gadgetData.getType()){ - case Vehicle -> new EntityVehicle(scene, session.getPlayer(), gadgetId, 0, pos, rot); - default -> new EntityGadget(scene, gadgetId, pos, rot); - }; - } - case ITEM_ID -> { - val itemId = entity.getItemId(); - ItemData itemData = GameData.getItemDataMap().get(itemId); - gameEntity = new EntityItem(scene, null, itemData, pos, 1, true); - } - case MONSTER_ID -> { - val monsterId = entity.getMonsterId(); - val level = entity.getLevel(); - MonsterData monsterData = GameData.getMonsterDataMap().get(monsterId); - gameEntity = new EntityMonster(scene, monsterData, pos, level); - } - case NPC_ID -> { - } - } - - if(gameEntity != null){ - scene.addEntity(gameEntity); - } - - val createdEntityId = gameEntity!=null ? gameEntity.getId() : -1; - - session.send(new PacketQuestCreateEntityRsp(createdEntityId, req)); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.excels.GadgetData; +import emu.grasscutter.data.excels.ItemData; +import emu.grasscutter.data.excels.monster.MonsterData; +import emu.grasscutter.game.entity.*; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestCreateEntityReqOuterClass.QuestCreateEntityReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketQuestCreateEntityRsp; +import emu.grasscutter.utils.Position; +import lombok.val; + +@Opcodes(PacketOpcodes.QuestCreateEntityReq) +public class HandlerQuestCreateEntityReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + val req = QuestCreateEntityReq.parseFrom(payload); + val entity = req.getEntity(); + val scene = session.getPlayer().getWorld().getSceneById(entity.getSceneId()); + + val pos = new Position(entity.getPos()); + val rot = new Position(entity.getRot()); + GameEntity gameEntity = null; + switch (entity.getEntityCase()) { + case GADGET_ID -> { + val gadgetId = entity.getGadgetId(); + val gadgetInfo = entity.getGadget(); + GadgetData gadgetData = GameData.getGadgetDataMap().get(gadgetId); + gameEntity = + switch (gadgetData.getType()) { + case Vehicle -> new EntityVehicle(scene, session.getPlayer(), gadgetId, 0, pos, rot); + default -> new EntityGadget(scene, gadgetId, pos, rot); + }; + } + case ITEM_ID -> { + val itemId = entity.getItemId(); + ItemData itemData = GameData.getItemDataMap().get(itemId); + gameEntity = new EntityItem(scene, null, itemData, pos, 1, true); + } + case MONSTER_ID -> { + val monsterId = entity.getMonsterId(); + val level = entity.getLevel(); + MonsterData monsterData = GameData.getMonsterDataMap().get(monsterId); + gameEntity = new EntityMonster(scene, monsterData, pos, level); + } + case NPC_ID -> {} + } + + if (gameEntity != null) { + scene.addEntity(gameEntity); + } + + val createdEntityId = gameEntity != null ? gameEntity.getId() : -1; + + session.send(new PacketQuestCreateEntityRsp(createdEntityId, req)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestDestroyEntityReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestDestroyEntityReq.java index 1e0f9b703..25891b5e7 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestDestroyEntityReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestDestroyEntityReq.java @@ -1,27 +1,26 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketQuestDestroyEntityRsp; -import lombok.val; -import emu.grasscutter.net.proto.QuestDestroyEntityReqOuterClass.QuestDestroyEntityReq; - -@Opcodes(PacketOpcodes.QuestDestroyEntityReq) -public class HandlerQuestDestroyEntityReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - val req = QuestDestroyEntityReq.parseFrom(payload); - val scene = session.getPlayer().getWorld().getSceneById(req.getSceneId()); - val entity = scene.getEntityById(req.getEntityId()); - - if(entity!=null){ - scene.removeEntity(entity); - } - - session.send(new PacketQuestDestroyEntityRsp(entity!=null, req)); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestDestroyEntityReqOuterClass.QuestDestroyEntityReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketQuestDestroyEntityRsp; +import lombok.val; + +@Opcodes(PacketOpcodes.QuestDestroyEntityReq) +public class HandlerQuestDestroyEntityReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + val req = QuestDestroyEntityReq.parseFrom(payload); + val scene = session.getPlayer().getWorld().getSceneById(req.getSceneId()); + val entity = scene.getEntityById(req.getEntityId()); + + if (entity != null) { + scene.removeEntity(entity); + } + + session.send(new PacketQuestDestroyEntityRsp(entity != null, req)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestDestroyNpcReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestDestroyNpcReq.java index 4e334724c..bbd39d658 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestDestroyNpcReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestDestroyNpcReq.java @@ -1,20 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.entity.EntityNPC; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketQuestDestroyNpcRsp; -import lombok.val; -import emu.grasscutter.net.proto.QuestDestroyNpcReqOuterClass.QuestDestroyNpcReq; - -@Opcodes(PacketOpcodes.QuestDestroyNpcReq) -public class HandlerQuestDestroyNpcReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - val req = QuestDestroyNpcReq.parseFrom(payload); - - session.send(new PacketQuestDestroyNpcRsp(req.getNpcId(), req.getParentQuestId(), 0)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestDestroyNpcReqOuterClass.QuestDestroyNpcReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketQuestDestroyNpcRsp; +import lombok.val; + +@Opcodes(PacketOpcodes.QuestDestroyNpcReq) +public class HandlerQuestDestroyNpcReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + val req = QuestDestroyNpcReq.parseFrom(payload); + + session.send(new PacketQuestDestroyNpcRsp(req.getNpcId(), req.getParentQuestId(), 0)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestTransmitReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestTransmitReq.java index 67979a344..eb95ce33a 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestTransmitReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestTransmitReq.java @@ -1,32 +1,41 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.game.quest.GameMainQuest; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketQuestTransmitRsp; -import emu.grasscutter.utils.Position; -import emu.grasscutter.net.proto.QuestTransmitReqOuterClass.QuestTransmitReq; - -import java.util.List; -import java.util.ArrayList; -import lombok.val; - -@Opcodes(PacketOpcodes.QuestTransmitReq) -public class HandlerQuestTransmitReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - val req = QuestTransmitReq.parseFrom(payload); - GameMainQuest mainQuest = session.getPlayer().getQuestManager().getMainQuestById(req.getQuestId() / 100); - List posAndRot = new ArrayList<>(); - boolean result = false; - if(mainQuest.hasTeleportPostion(req.getQuestId(), posAndRot)){ - int sceneId = GameData.getTeleportDataMap().get(req.getQuestId()).getTransmit_points().get(0).getScene_id(); - result = session.getPlayer().getWorld().transferPlayerToScene(session.getPlayer(), sceneId, posAndRot.get(0)); - } - session.send(new PacketQuestTransmitRsp(result, req)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.game.quest.GameMainQuest; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestTransmitReqOuterClass.QuestTransmitReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketQuestTransmitRsp; +import emu.grasscutter.utils.Position; +import java.util.ArrayList; +import java.util.List; +import lombok.val; + +@Opcodes(PacketOpcodes.QuestTransmitReq) +public class HandlerQuestTransmitReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + val req = QuestTransmitReq.parseFrom(payload); + GameMainQuest mainQuest = + session.getPlayer().getQuestManager().getMainQuestById(req.getQuestId() / 100); + List posAndRot = new ArrayList<>(); + boolean result = false; + if (mainQuest.hasTeleportPostion(req.getQuestId(), posAndRot)) { + int sceneId = + GameData.getTeleportDataMap() + .get(req.getQuestId()) + .getTransmit_points() + .get(0) + .getScene_id(); + result = + session + .getPlayer() + .getWorld() + .transferPlayerToScene(session.getPlayer(), sceneId, posAndRot.get(0)); + } + session.send(new PacketQuestTransmitRsp(result, req)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerReceivedTrialAvatarActivityRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerReceivedTrialAvatarActivityRewardReq.java index b0ce377e0..99dd72c19 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerReceivedTrialAvatarActivityRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerReceivedTrialAvatarActivityRewardReq.java @@ -1,32 +1,37 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.activity.trialavatar.TrialAvatarActivityHandler; -import emu.grasscutter.game.props.ActivityType; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.ReceivedTrialAvatarActivityRewardReqOuterClass.ReceivedTrialAvatarActivityRewardReq; -import emu.grasscutter.server.packet.send.PacketReceivedTrialAvatarActivityRewardRsp; - -import lombok.val; - -@Opcodes(PacketOpcodes.ReceivedTrialAvatarActivityRewardReq) -public class HandlerReceivedTrialAvatarActivityRewardReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - val req = ReceivedTrialAvatarActivityRewardReq.parseFrom(payload); - val player = session.getPlayer(); - val handler = player.getActivityManager().getActivityHandlerAs(ActivityType.NEW_ACTIVITY_TRIAL_AVATAR, TrialAvatarActivityHandler.class); - - boolean result = handler.isPresent() && handler.get().getReward(player, req.getTrialAvatarIndexId()); - - session.getPlayer().sendPacket(new PacketReceivedTrialAvatarActivityRewardRsp( - 5002, // trial activity id - req.getTrialAvatarIndexId(), - result)); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.activity.trialavatar.TrialAvatarActivityHandler; +import emu.grasscutter.game.props.ActivityType; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ReceivedTrialAvatarActivityRewardReqOuterClass.ReceivedTrialAvatarActivityRewardReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketReceivedTrialAvatarActivityRewardRsp; +import lombok.val; + +@Opcodes(PacketOpcodes.ReceivedTrialAvatarActivityRewardReq) +public class HandlerReceivedTrialAvatarActivityRewardReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + val req = ReceivedTrialAvatarActivityRewardReq.parseFrom(payload); + val player = session.getPlayer(); + val handler = + player + .getActivityManager() + .getActivityHandlerAs( + ActivityType.NEW_ACTIVITY_TRIAL_AVATAR, TrialAvatarActivityHandler.class); + + boolean result = + handler.isPresent() && handler.get().getReward(player, req.getTrialAvatarIndexId()); + + session + .getPlayer() + .sendPacket( + new PacketReceivedTrialAvatarActivityRewardRsp( + 5002, // trial activity id + req.getTrialAvatarIndexId(), + result)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerRemoveCustomTeamReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerRemoveCustomTeamReq.java index 9ea1fe4c0..81e9f1e5c 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerRemoveCustomTeamReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerRemoveCustomTeamReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RemoveCustomTeamReqOuterClass.RemoveCustomTeamReq; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.RemoveCustomTeamReq) -public class HandlerRemoveCustomTeamReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - RemoveCustomTeamReq req = RemoveCustomTeamReq.parseFrom(payload); - session.getPlayer().getTeamManager().removeCustomTeam(req.getId()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.RemoveCustomTeamReqOuterClass.RemoveCustomTeamReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.RemoveCustomTeamReq) +public class HandlerRemoveCustomTeamReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + RemoveCustomTeamReq req = RemoveCustomTeamReq.parseFrom(payload); + session.getPlayer().getTeamManager().removeCustomTeam(req.getId()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSaveUgcReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSaveUgcReq.java index 619394a58..1f3a183e2 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSaveUgcReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSaveUgcReq.java @@ -1,84 +1,97 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.game.activity.musicgame.MusicGameActivityHandler; -import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; -import emu.grasscutter.game.activity.musicgame.MusicGamePlayerData; -import emu.grasscutter.game.props.ActivityType; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.SaveUgcReqOuterClass; -import emu.grasscutter.net.proto.UgcTypeOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketActivityInfoNotify; -import emu.grasscutter.server.packet.send.PacketMusicGameCreateBeatmapRsp; -import emu.grasscutter.utils.Utils; -import lombok.val; - -import java.util.Objects; - -@Opcodes(PacketOpcodes.SaveUgcReq) -public class HandlerSaveUgcReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - val req = SaveUgcReqOuterClass.SaveUgcReq.parseFrom(payload); - - // We only support music game user generated content - if(req.getUgcType() != UgcTypeOuterClass.UgcType.UGC_TYPE_MUSIC_GAME){ - session.send(new PacketMusicGameCreateBeatmapRsp(RetcodeOuterClass.Retcode.RET_UGC_DISABLED, req.getUgcType())); - return; - } - val briefInfo = req.getMusicBriefInfo(); - - val musicGameBeatmap = MusicGameBeatmap.of() - .musicId(briefInfo.getMusicId()) - .musicNoteCount(briefInfo.getNoteCount()) - .savePosition(briefInfo.getSaveIdx()) - .savePageType(briefInfo.getSavePageType()) - .version(briefInfo.getVersion()) - .afterNoteList(briefInfo.getAfterNoteListList()) - .beforeNoteList(briefInfo.getBeforeNoteListList()) - .timeLineEditTime(briefInfo.getTimeLineEditTime()) - .publishTime(briefInfo.getPublishTime()) - .realTimeEditTime(briefInfo.getRealTimeEditTime()) - .maxScore(briefInfo.getMaxScore()) - .authorUid(session.getPlayer().getUid()) - .beatmap(MusicGameBeatmap.parse(req.getMusicRecord().getMusicTrackListList())) - .createTime(Utils.getCurrentSeconds()) - .build(); - - musicGameBeatmap.save(); - - val playerData = session.getPlayer().getActivityManager().getPlayerActivityDataByActivityType(ActivityType.NEW_ACTIVITY_MUSIC_GAME); - if(playerData.isEmpty()){ - session.send(new PacketMusicGameCreateBeatmapRsp(RetcodeOuterClass.Retcode.RET_UGC_DATA_NOT_FOUND, req.getUgcType())); - return; - } - - val handler = (MusicGameActivityHandler) playerData.get().getActivityHandler(); - val musicGamePlayerData = handler.getMusicGamePlayerData(playerData.get()); - - val oldBeatmap = musicGamePlayerData.getPersonalCustomBeatmapRecord().values().stream() - .map(MusicGamePlayerData.CustomBeatmapRecord::getMusicShareId) - .map(DatabaseHelper::getMusicGameBeatmap) - .filter(Objects::nonNull) - .filter(item -> item.getAuthorUid() == session.getPlayer().getUid()) - .filter(item -> item.getMusicId() == req.getMusicBriefInfo().getMusicId()) - .filter(item -> item.getSavePosition() == req.getMusicBriefInfo().getSaveIdx()) - .findFirst(); - - // delete old beatmap for player - // the old beatmap is still in database so that others can still play. - oldBeatmap.ifPresent(i -> handler.removePersonalBeatmap(playerData.get(), i)); - - // link this beatmap to player's personal data - handler.addPersonalBeatmap(playerData.get(), musicGameBeatmap); - - session.send(new PacketActivityInfoNotify(handler.toProto(playerData.get(), session.getPlayer().getActivityManager().getConditionExecutor()))); - session.send(new PacketMusicGameCreateBeatmapRsp(musicGameBeatmap.getMusicShareId(), req.getUgcType())); - } - -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.database.DatabaseHelper; +import emu.grasscutter.game.activity.musicgame.MusicGameActivityHandler; +import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; +import emu.grasscutter.game.activity.musicgame.MusicGamePlayerData; +import emu.grasscutter.game.props.ActivityType; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.SaveUgcReqOuterClass; +import emu.grasscutter.net.proto.UgcTypeOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketActivityInfoNotify; +import emu.grasscutter.server.packet.send.PacketMusicGameCreateBeatmapRsp; +import emu.grasscutter.utils.Utils; +import java.util.Objects; +import lombok.val; + +@Opcodes(PacketOpcodes.SaveUgcReq) +public class HandlerSaveUgcReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + val req = SaveUgcReqOuterClass.SaveUgcReq.parseFrom(payload); + + // We only support music game user generated content + if (req.getUgcType() != UgcTypeOuterClass.UgcType.UGC_TYPE_MUSIC_GAME) { + session.send( + new PacketMusicGameCreateBeatmapRsp( + RetcodeOuterClass.Retcode.RET_UGC_DISABLED, req.getUgcType())); + return; + } + val briefInfo = req.getMusicBriefInfo(); + + val musicGameBeatmap = + MusicGameBeatmap.of() + .musicId(briefInfo.getMusicId()) + .musicNoteCount(briefInfo.getNoteCount()) + .savePosition(briefInfo.getSaveIdx()) + .savePageType(briefInfo.getSavePageType()) + .version(briefInfo.getVersion()) + .afterNoteList(briefInfo.getAfterNoteListList()) + .beforeNoteList(briefInfo.getBeforeNoteListList()) + .timeLineEditTime(briefInfo.getTimeLineEditTime()) + .publishTime(briefInfo.getPublishTime()) + .realTimeEditTime(briefInfo.getRealTimeEditTime()) + .maxScore(briefInfo.getMaxScore()) + .authorUid(session.getPlayer().getUid()) + .beatmap(MusicGameBeatmap.parse(req.getMusicRecord().getMusicTrackListList())) + .createTime(Utils.getCurrentSeconds()) + .build(); + + musicGameBeatmap.save(); + + val playerData = + session + .getPlayer() + .getActivityManager() + .getPlayerActivityDataByActivityType(ActivityType.NEW_ACTIVITY_MUSIC_GAME); + if (playerData.isEmpty()) { + session.send( + new PacketMusicGameCreateBeatmapRsp( + RetcodeOuterClass.Retcode.RET_UGC_DATA_NOT_FOUND, req.getUgcType())); + return; + } + + val handler = (MusicGameActivityHandler) playerData.get().getActivityHandler(); + val musicGamePlayerData = handler.getMusicGamePlayerData(playerData.get()); + + val oldBeatmap = + musicGamePlayerData.getPersonalCustomBeatmapRecord().values().stream() + .map(MusicGamePlayerData.CustomBeatmapRecord::getMusicShareId) + .map(DatabaseHelper::getMusicGameBeatmap) + .filter(Objects::nonNull) + .filter(item -> item.getAuthorUid() == session.getPlayer().getUid()) + .filter(item -> item.getMusicId() == req.getMusicBriefInfo().getMusicId()) + .filter(item -> item.getSavePosition() == req.getMusicBriefInfo().getSaveIdx()) + .findFirst(); + + // delete old beatmap for player + // the old beatmap is still in database so that others can still play. + oldBeatmap.ifPresent(i -> handler.removePersonalBeatmap(playerData.get(), i)); + + // link this beatmap to player's personal data + handler.addPersonalBeatmap(playerData.get(), musicGameBeatmap); + + session.send( + new PacketActivityInfoNotify( + handler.toProto( + playerData.get(), + session.getPlayer().getActivityManager().getConditionExecutor()))); + session.send( + new PacketMusicGameCreateBeatmapRsp(musicGameBeatmap.getMusicShareId(), req.getUgcType())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAddCustomTeamRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAddCustomTeamRsp.java index 54cc022c9..67aa96494 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAddCustomTeamRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAddCustomTeamRsp.java @@ -1,22 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.AddCustomTeamRspOuterClass.AddCustomTeamRsp; - -public class PacketAddCustomTeamRsp extends BasePacket { - public PacketAddCustomTeamRsp(Retcode retcode) { - super(PacketOpcodes.AddCustomTeamRsp); - - AddCustomTeamRsp proto = AddCustomTeamRsp.newBuilder() - .setRetcode(retcode.getNumber()) - .build(); - - this.setData(proto); - } - - public PacketAddCustomTeamRsp() { - this(Retcode.RET_SUCC); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AddCustomTeamRspOuterClass.AddCustomTeamRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +public class PacketAddCustomTeamRsp extends BasePacket { + public PacketAddCustomTeamRsp(Retcode retcode) { + super(PacketOpcodes.AddCustomTeamRsp); + + AddCustomTeamRsp proto = AddCustomTeamRsp.newBuilder().setRetcode(retcode.getNumber()).build(); + + this.setData(proto); + } + + public PacketAddCustomTeamRsp() { + this(Retcode.RET_SUCC); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAddNoGachaAvatarCardNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAddNoGachaAvatarCardNotify.java index f2b73af96..564df182f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAddNoGachaAvatarCardNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAddNoGachaAvatarCardNotify.java @@ -1,40 +1,41 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.props.ActionReason; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AddNoGachaAvatarCardNotifyOuterClass.AddNoGachaAvatarCardNotify; - -public class PacketAddNoGachaAvatarCardNotify extends BasePacket { - - public PacketAddNoGachaAvatarCardNotify(Avatar avatar, ActionReason reason, GameItem item) { - super(PacketOpcodes.AddNoGachaAvatarCardNotify, true); - - AddNoGachaAvatarCardNotify proto = AddNoGachaAvatarCardNotify.newBuilder() - .setAvatarId(avatar.getAvatarId()) - .setReason(reason.getValue()) - .setInitialLevel(1) - .setItemId(item.getItemId()) - .setInitialPromoteLevel(0) - .build(); - - this.setData(proto); - } - - public PacketAddNoGachaAvatarCardNotify(int avatarId, ActionReason reason, GameItem item) { - super(PacketOpcodes.AddNoGachaAvatarCardNotify, true); - - AddNoGachaAvatarCardNotify proto = AddNoGachaAvatarCardNotify.newBuilder() - .setAvatarId(avatarId) - .setReason(reason.getValue()) - .setInitialLevel(1) - .setItemId(item.getItemId()) - .setInitialPromoteLevel(0) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AddNoGachaAvatarCardNotifyOuterClass.AddNoGachaAvatarCardNotify; + +public class PacketAddNoGachaAvatarCardNotify extends BasePacket { + + public PacketAddNoGachaAvatarCardNotify(Avatar avatar, ActionReason reason, GameItem item) { + super(PacketOpcodes.AddNoGachaAvatarCardNotify, true); + + AddNoGachaAvatarCardNotify proto = + AddNoGachaAvatarCardNotify.newBuilder() + .setAvatarId(avatar.getAvatarId()) + .setReason(reason.getValue()) + .setInitialLevel(1) + .setItemId(item.getItemId()) + .setInitialPromoteLevel(0) + .build(); + + this.setData(proto); + } + + public PacketAddNoGachaAvatarCardNotify(int avatarId, ActionReason reason, GameItem item) { + super(PacketOpcodes.AddNoGachaAvatarCardNotify, true); + + AddNoGachaAvatarCardNotify proto = + AddNoGachaAvatarCardNotify.newBuilder() + .setAvatarId(avatarId) + .setReason(reason.getValue()) + .setInitialLevel(1) + .setItemId(item.getItemId()) + .setInitialPromoteLevel(0) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDelNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDelNotify.java index 1c4229161..fd5bd38d1 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDelNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDelNotify.java @@ -1,20 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarDelNotifyOuterClass.AvatarDelNotify; - -import java.util.List; - -public class PacketAvatarDelNotify extends BasePacket { - - public PacketAvatarDelNotify(List avatarGuidList) { - super(PacketOpcodes.AvatarDelNotify); - - AvatarDelNotify proto = AvatarDelNotify.newBuilder() - .addAllAvatarGuidList(avatarGuidList) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarDelNotifyOuterClass.AvatarDelNotify; +import java.util.List; + +public class PacketAvatarDelNotify extends BasePacket { + + public PacketAvatarDelNotify(List avatarGuidList) { + super(PacketOpcodes.AvatarDelNotify); + + AvatarDelNotify proto = + AvatarDelNotify.newBuilder().addAllAvatarGuidList(avatarGuidList).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamUpdateNotify.java index d86904686..065301cb3 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamUpdateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamUpdateNotify.java @@ -19,4 +19,11 @@ public class PacketAvatarTeamUpdateNotify extends BasePacket { this.setData(proto); } + + /** Used for locking/unlocking team modification. */ + public PacketAvatarTeamUpdateNotify() { + super(PacketOpcodes.AvatarTeamUpdateNotify); + + this.setData(AvatarTeamUpdateNotify.newBuilder().build()); + } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketBeginCameraSceneLookNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketBeginCameraSceneLookNotify.java index c1e2133fb..c2be91f22 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketBeginCameraSceneLookNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketBeginCameraSceneLookNotify.java @@ -1,61 +1,62 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.BeginCameraSceneLookNotifyOuterClass.BeginCameraSceneLookNotify; -import emu.grasscutter.utils.Position; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.val; - -import java.util.ArrayList; -import java.util.Collection; - -public class PacketBeginCameraSceneLookNotify extends BasePacket { - - public PacketBeginCameraSceneLookNotify(CameraSceneLookNotify parameters) { - super(PacketOpcodes.BeginCameraSceneLookNotify); - val builder = BeginCameraSceneLookNotify.newBuilder() - .setLookPos(parameters.lookPos.toProto()) - .setFollowPos(parameters.followPos.toProto()) - .setDuration(parameters.duration) - .setIsAllowInput(parameters.isAllowInput) - .setIsSetFollowPos(parameters.setFollowPos) - .setIsSetScreenXy(parameters.isScreenXY) - .setIsRecoverKeepCurrent(parameters.recoverKeepCurrent) - .setIsChangePlayMode(parameters.isChangePlayMode) - .setScreenY(parameters.screenY) - .setScreenX(parameters.screenX) - .setIsForce(parameters.isForce) - .setIsForce(parameters.isForceWalk) - .setEntityId(parameters.entityId) - .addAllOtherParams(parameters.otherParams); - this.setData(builder); - } - - // TODO check default values - // todo find missing field usages: - // enum Unk2700_HIAKNNCKHJB (Unk2700_LNCHDDOOECD) - // Unk3000_MNLLCJMPMNH (uint32) - // Unk2700_DHAHEKOGHBJ (float) - // Unk3000_IEFIKMHCKDH (uint32) - // Unk3000_OGCLMFFADBD (float) - - @Data @NoArgsConstructor - public static class CameraSceneLookNotify{ - Position lookPos = new Position(); - Position followPos = new Position(); - float duration = 0.0f; - boolean isAllowInput = true; - boolean setFollowPos = false; - boolean isScreenXY = false; - boolean recoverKeepCurrent = true; - boolean isForceWalk = false; - boolean isForce = false; - boolean isChangePlayMode = false; - float screenY = 0.0f; - float screenX = 0.0f; - int entityId = 0; - Collection otherParams = new ArrayList<>(0); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.BeginCameraSceneLookNotifyOuterClass.BeginCameraSceneLookNotify; +import emu.grasscutter.utils.Position; +import java.util.ArrayList; +import java.util.Collection; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.val; + +public class PacketBeginCameraSceneLookNotify extends BasePacket { + + public PacketBeginCameraSceneLookNotify(CameraSceneLookNotify parameters) { + super(PacketOpcodes.BeginCameraSceneLookNotify); + val builder = + BeginCameraSceneLookNotify.newBuilder() + .setLookPos(parameters.lookPos.toProto()) + .setFollowPos(parameters.followPos.toProto()) + .setDuration(parameters.duration) + .setIsAllowInput(parameters.isAllowInput) + .setIsSetFollowPos(parameters.setFollowPos) + .setIsSetScreenXy(parameters.isScreenXY) + .setIsRecoverKeepCurrent(parameters.recoverKeepCurrent) + .setIsChangePlayMode(parameters.isChangePlayMode) + .setScreenY(parameters.screenY) + .setScreenX(parameters.screenX) + .setIsForce(parameters.isForce) + .setIsForce(parameters.isForceWalk) + .setEntityId(parameters.entityId) + .addAllOtherParams(parameters.otherParams); + this.setData(builder); + } + + // TODO check default values + // todo find missing field usages: + // enum Unk2700_HIAKNNCKHJB (Unk2700_LNCHDDOOECD) + // Unk3000_MNLLCJMPMNH (uint32) + // Unk2700_DHAHEKOGHBJ (float) + // Unk3000_IEFIKMHCKDH (uint32) + // Unk3000_OGCLMFFADBD (float) + + @Data + @NoArgsConstructor + public static class CameraSceneLookNotify { + Position lookPos = new Position(); + Position followPos = new Position(); + float duration = 0.0f; + boolean isAllowInput = true; + boolean setFollowPos = false; + boolean isScreenXY = false; + boolean recoverKeepCurrent = true; + boolean isForceWalk = false; + boolean isForce = false; + boolean isChangePlayMode = false; + float screenY = 0.0f; + float screenX = 0.0f; + int entityId = 0; + Collection otherParams = new ArrayList<>(0); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeHomeBgmNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeHomeBgmNotify.java index f61b05d25..3c5bb3aa8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeHomeBgmNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeHomeBgmNotify.java @@ -1,17 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.Unk2700FJEHHCPCBLGServerNotify; - -public class PacketChangeHomeBgmNotify extends BasePacket { - public PacketChangeHomeBgmNotify(int homeBgmId) { - super(PacketOpcodes.Unk2700_FJEHHCPCBLG_ServerNotify); - - var notify = Unk2700FJEHHCPCBLGServerNotify.Unk2700_FJEHHCPCBLG_ServerNotify.newBuilder() - .setUnk2700BJHAMKKECEI(homeBgmId) - .build(); - - this.setData(notify); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.Unk2700FJEHHCPCBLGServerNotify; + +public class PacketChangeHomeBgmNotify extends BasePacket { + public PacketChangeHomeBgmNotify(int homeBgmId) { + super(PacketOpcodes.Unk2700_FJEHHCPCBLG_ServerNotify); + + var notify = + Unk2700FJEHHCPCBLGServerNotify.Unk2700_FJEHHCPCBLG_ServerNotify.newBuilder() + .setUnk2700BJHAMKKECEI(homeBgmId) + .build(); + + this.setData(notify); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeHomeBgmRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeHomeBgmRsp.java index 19fb43c92..ef9668bc2 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeHomeBgmRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeHomeBgmRsp.java @@ -1,17 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.Unk2700OGHMHELMBNNServerRsp; - -public class PacketChangeHomeBgmRsp extends BasePacket { - public PacketChangeHomeBgmRsp() { - super(PacketOpcodes.Unk2700_OGHMHELMBNN_ServerRsp); - - var rsp = Unk2700OGHMHELMBNNServerRsp.Unk2700_OGHMHELMBNN_ServerRsp.newBuilder() - .setRetcode(0) - .build(); - - this.setData(rsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.Unk2700OGHMHELMBNNServerRsp; + +public class PacketChangeHomeBgmRsp extends BasePacket { + public PacketChangeHomeBgmRsp() { + super(PacketOpcodes.Unk2700_OGHMHELMBNN_ServerRsp); + + var rsp = + Unk2700OGHMHELMBNNServerRsp.Unk2700_OGHMHELMBNN_ServerRsp.newBuilder() + .setRetcode(0) + .build(); + + this.setData(rsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCheckUgcStateRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCheckUgcStateRsp.java index 3b9884ea3..41dcec388 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCheckUgcStateRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCheckUgcStateRsp.java @@ -1,18 +1,15 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CheckUgcStateRspOuterClass.CheckUgcStateRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -public class PacketCheckUgcStateRsp extends BasePacket { - - public PacketCheckUgcStateRsp(RetcodeOuterClass.Retcode ret) { - super(PacketOpcodes.CheckUgcStateRsp); - - this.setData(CheckUgcStateRsp.newBuilder() - .setRetcode(ret.getNumber()) - ); - } - -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CheckUgcStateRspOuterClass.CheckUgcStateRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass; + +public class PacketCheckUgcStateRsp extends BasePacket { + + public PacketCheckUgcStateRsp(RetcodeOuterClass.Retcode ret) { + super(PacketOpcodes.CheckUgcStateRsp); + + this.setData(CheckUgcStateRsp.newBuilder().setRetcode(ret.getNumber())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCheckUgcUpdateRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCheckUgcUpdateRsp.java index 87b491df4..0480c8254 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCheckUgcUpdateRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCheckUgcUpdateRsp.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CheckUgcUpdateRspOuterClass.CheckUgcUpdateRsp; -import emu.grasscutter.net.proto.UgcTypeOuterClass.UgcType; - -public class PacketCheckUgcUpdateRsp extends BasePacket { - - public PacketCheckUgcUpdateRsp(UgcType ugcType) { - super(PacketOpcodes.CheckUgcUpdateRsp); - - var proto = CheckUgcUpdateRsp.newBuilder(); - - proto.setUgcType(ugcType); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CheckUgcUpdateRspOuterClass.CheckUgcUpdateRsp; +import emu.grasscutter.net.proto.UgcTypeOuterClass.UgcType; + +public class PacketCheckUgcUpdateRsp extends BasePacket { + + public PacketCheckUgcUpdateRsp(UgcType ugcType) { + super(PacketOpcodes.CheckUgcUpdateRsp); + + var proto = CheckUgcUpdateRsp.newBuilder(); + + proto.setUgcType(ugcType); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCloseCommonTipsNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCloseCommonTipsNotify.java index 663aeb314..2b6661589 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCloseCommonTipsNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCloseCommonTipsNotify.java @@ -1,13 +1,13 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CloseCommonTipsNotifyOuterClass.CloseCommonTipsNotify; - -public class PacketCloseCommonTipsNotify extends BasePacket { - - public PacketCloseCommonTipsNotify() { - super(PacketOpcodes.CloseCommonTipsNotify); - this.setData(CloseCommonTipsNotify.newBuilder().build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CloseCommonTipsNotifyOuterClass.CloseCommonTipsNotify; + +public class PacketCloseCommonTipsNotify extends BasePacket { + + public PacketCloseCommonTipsNotify() { + super(PacketOpcodes.CloseCommonTipsNotify); + this.setData(CloseCommonTipsNotify.newBuilder().build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCustomTeamListNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCustomTeamListNotify.java index 182adb0fb..b6cace2e8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCustomTeamListNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCustomTeamListNotify.java @@ -1,26 +1,29 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CustomTeamListNotifyOuterClass.CustomTeamListNotify; - -public class PacketCustomTeamListNotify extends BasePacket { - public PacketCustomTeamListNotify(Player player) { - super(PacketOpcodes.CustomTeamListNotify); - - CustomTeamListNotify.Builder proto = CustomTeamListNotify.newBuilder(); - - // Add the id list for custom teams. - for (int id : player.getTeamManager().getTeams().keySet()) { - if (id > 4) { - proto.addCustomTeamIds(id); - } - } - - // Add the avatar lists for all the teams the player has. - player.getTeamManager().getTeams().forEach((id, teamInfo) -> proto.putAvatarTeamMap(id, teamInfo.toProto(player))); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CustomTeamListNotifyOuterClass.CustomTeamListNotify; + +public class PacketCustomTeamListNotify extends BasePacket { + public PacketCustomTeamListNotify(Player player) { + super(PacketOpcodes.CustomTeamListNotify); + + CustomTeamListNotify.Builder proto = CustomTeamListNotify.newBuilder(); + + // Add the id list for custom teams. + for (int id : player.getTeamManager().getTeams().keySet()) { + if (id > 4) { + proto.addCustomTeamIds(id); + } + } + + // Add the avatar lists for all the teams the player has. + player + .getTeamManager() + .getTeams() + .forEach((id, teamInfo) -> proto.putAvatarTeamMap(id, teamInfo.toProto(player))); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCutsceneBeginNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCutsceneBeginNotify.java index 2ccb7032a..ab8b37939 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCutsceneBeginNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCutsceneBeginNotify.java @@ -1,16 +1,14 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CutSceneBeginNotifyOuterClass.CutSceneBeginNotify; - -public class PacketCutsceneBeginNotify extends BasePacket { - - public PacketCutsceneBeginNotify(int cutsceneId) { - super(PacketOpcodes.CutSceneBeginNotify); - - setData(CutSceneBeginNotify.newBuilder() - .setCutsceneId(cutsceneId)); - } - -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CutSceneBeginNotifyOuterClass.CutSceneBeginNotify; + +public class PacketCutsceneBeginNotify extends BasePacket { + + public PacketCutsceneBeginNotify(int cutsceneId) { + super(PacketOpcodes.CutSceneBeginNotify); + + setData(CutSceneBeginNotify.newBuilder().setCutsceneId(cutsceneId)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDelQuestNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDelQuestNotify.java index c11a10b6c..c8002dd6b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDelQuestNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDelQuestNotify.java @@ -1,21 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import java.util.List; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.QuestDelNotifyOuterClass.QuestDelNotify; - -public class PacketDelQuestNotify extends BasePacket { - - public PacketDelQuestNotify(int questId) { - super(PacketOpcodes.QuestDelNotify); - - QuestDelNotify proto = QuestDelNotify.newBuilder() - .setQuestId(questId) - .build(); - - this.setData(proto); - } - -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestDelNotifyOuterClass.QuestDelNotify; + +public class PacketDelQuestNotify extends BasePacket { + + public PacketDelQuestNotify(int questId) { + super(PacketOpcodes.QuestDelNotify); + + QuestDelNotify proto = QuestDelNotify.newBuilder().setQuestId(questId).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonPlayerDieNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonPlayerDieNotify.java index d98e576f6..e227e67fd 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonPlayerDieNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonPlayerDieNotify.java @@ -1,25 +1,32 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType; -import emu.grasscutter.net.proto.DungeonPlayerDieNotifyOuterClass.DungeonPlayerDieNotify; - -public class PacketDungeonPlayerDieNotify extends BasePacket { - - public PacketDungeonPlayerDieNotify(PlayerDieType playerDieType, int killerId, int dungeonId, int waitTime, int reviveCount, boolean isGadget) { - super(PacketOpcodes.DungeonPlayerDieNotify); - - DungeonPlayerDieNotify.Builder proto = DungeonPlayerDieNotify.newBuilder() - .setDieType(playerDieType) - .setReviveCount(reviveCount) - .setWaitTime(waitTime) - .setDungeonId(dungeonId) - .setMurdererEntityId(killerId); - - if(isGadget) proto.setGadgetId(killerId); - else proto.setMonsterId(killerId); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonPlayerDieNotifyOuterClass.DungeonPlayerDieNotify; +import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType; + +public class PacketDungeonPlayerDieNotify extends BasePacket { + + public PacketDungeonPlayerDieNotify( + PlayerDieType playerDieType, + int killerId, + int dungeonId, + int waitTime, + int reviveCount, + boolean isGadget) { + super(PacketOpcodes.DungeonPlayerDieNotify); + + DungeonPlayerDieNotify.Builder proto = + DungeonPlayerDieNotify.newBuilder() + .setDieType(playerDieType) + .setReviveCount(reviveCount) + .setWaitTime(waitTime) + .setDungeonId(dungeonId) + .setMurdererEntityId(killerId); + + if (isGadget) proto.setGadgetId(killerId); + else proto.setMonsterId(killerId); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonPlayerDieRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonPlayerDieRsp.java index 44cf6c641..2d7199c6c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonPlayerDieRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonPlayerDieRsp.java @@ -1,19 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DungeonPlayerDieRspOuterClass.DungeonPlayerDieRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; - -public class PacketDungeonPlayerDieRsp extends BasePacket { - - public PacketDungeonPlayerDieRsp(Retcode retcode) { - super(PacketOpcodes.DungeonPlayerDieRsp); - - DungeonPlayerDieRsp proto = DungeonPlayerDieRsp.newBuilder() - .setRetcode(retcode.getNumber()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonPlayerDieRspOuterClass.DungeonPlayerDieRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +public class PacketDungeonPlayerDieRsp extends BasePacket { + + public PacketDungeonPlayerDieRsp(Retcode retcode) { + super(PacketOpcodes.DungeonPlayerDieRsp); + + DungeonPlayerDieRsp proto = + DungeonPlayerDieRsp.newBuilder().setRetcode(retcode.getNumber()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonSlipRevivePointActivateRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonSlipRevivePointActivateRsp.java index 2cd679963..a26df041e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonSlipRevivePointActivateRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonSlipRevivePointActivateRsp.java @@ -1,16 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DungeonSlipRevivePointActivateRspOuterClass.DungeonSlipRevivePointActivateRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -public class PacketDungeonSlipRevivePointActivateRsp extends BasePacket { - public PacketDungeonSlipRevivePointActivateRsp(boolean success, int pointId) { - super(PacketOpcodes.DungeonSlipRevivePointActivateRsp); - - this.setData(DungeonSlipRevivePointActivateRsp.newBuilder() - .setSlipRevivePointId(pointId) - .setRetcode(success ? RetcodeOuterClass.Retcode.RET_SUCC_VALUE : RetcodeOuterClass.Retcode.RET_FAIL_VALUE)); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonSlipRevivePointActivateRspOuterClass.DungeonSlipRevivePointActivateRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass; + +public class PacketDungeonSlipRevivePointActivateRsp extends BasePacket { + public PacketDungeonSlipRevivePointActivateRsp(boolean success, int pointId) { + super(PacketOpcodes.DungeonSlipRevivePointActivateRsp); + + this.setData( + DungeonSlipRevivePointActivateRsp.newBuilder() + .setSlipRevivePointId(pointId) + .setRetcode( + success + ? RetcodeOuterClass.Retcode.RET_SUCC_VALUE + : RetcodeOuterClass.Retcode.RET_FAIL_VALUE)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonWayPointActivateRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonWayPointActivateRsp.java index 7ec40a92c..f461b0553 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonWayPointActivateRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonWayPointActivateRsp.java @@ -1,16 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DungeonWayPointActivateRspOuterClass; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -public class PacketDungeonWayPointActivateRsp extends BasePacket { - public PacketDungeonWayPointActivateRsp(boolean success, int pointId) { - super(PacketOpcodes.DungeonWayPointActivateRsp); - - this.setData(DungeonWayPointActivateRspOuterClass.DungeonWayPointActivateRsp.newBuilder() - .setWayPointId(pointId) - .setRetcode(success ? RetcodeOuterClass.Retcode.RET_SUCC_VALUE : RetcodeOuterClass.Retcode.RET_FAIL_VALUE)); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonWayPointActivateRspOuterClass; +import emu.grasscutter.net.proto.RetcodeOuterClass; + +public class PacketDungeonWayPointActivateRsp extends BasePacket { + public PacketDungeonWayPointActivateRsp(boolean success, int pointId) { + super(PacketOpcodes.DungeonWayPointActivateRsp); + + this.setData( + DungeonWayPointActivateRspOuterClass.DungeonWayPointActivateRsp.newBuilder() + .setWayPointId(pointId) + .setRetcode( + success + ? RetcodeOuterClass.Retcode.RET_SUCC_VALUE + : RetcodeOuterClass.Retcode.RET_FAIL_VALUE)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonWayPointNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonWayPointNotify.java index 29bb640fa..06b7e3c14 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonWayPointNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonWayPointNotify.java @@ -1,19 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DungeonWayPointActivateRspOuterClass; -import emu.grasscutter.net.proto.DungeonWayPointNotifyOuterClass; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -import java.util.Set; - -public class PacketDungeonWayPointNotify extends BasePacket { - public PacketDungeonWayPointNotify(boolean added, Set activePointIds) { - super(PacketOpcodes.DungeonWayPointNotify); - - this.setData(DungeonWayPointNotifyOuterClass.DungeonWayPointNotify.newBuilder() - .addAllActiveWayPointList(activePointIds) - .setIsAdd(added)); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonWayPointNotifyOuterClass; +import java.util.Set; + +public class PacketDungeonWayPointNotify extends BasePacket { + public PacketDungeonWayPointNotify(boolean added, Set activePointIds) { + super(PacketOpcodes.DungeonWayPointNotify); + + this.setData( + DungeonWayPointNotifyOuterClass.DungeonWayPointNotify.newBuilder() + .addAllActiveWayPointList(activePointIds) + .setIsAdd(added)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEndCameraSceneLookNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEndCameraSceneLookNotify.java index de8914154..2fea7dc7d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEndCameraSceneLookNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEndCameraSceneLookNotify.java @@ -1,14 +1,14 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EndCameraSceneLookNotifyOuterClass.EndCameraSceneLookNotify; - -public class PacketEndCameraSceneLookNotify extends BasePacket { - - public PacketEndCameraSceneLookNotify() { - super(PacketOpcodes.EndCameraSceneLookNotify); - - this.setData(EndCameraSceneLookNotify.newBuilder()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EndCameraSceneLookNotifyOuterClass.EndCameraSceneLookNotify; + +public class PacketEndCameraSceneLookNotify extends BasePacket { + + public PacketEndCameraSceneLookNotify() { + super(PacketOpcodes.EndCameraSceneLookNotify); + + this.setData(EndCameraSceneLookNotify.newBuilder()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEnterTrialAvatarActivityDungeonRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEnterTrialAvatarActivityDungeonRsp.java index 1a5744635..013d9546f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEnterTrialAvatarActivityDungeonRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEnterTrialAvatarActivityDungeonRsp.java @@ -1,20 +1,29 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EnterTrialAvatarActivityDungeonRspOuterClass.EnterTrialAvatarActivityDungeonRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -public class PacketEnterTrialAvatarActivityDungeonRsp extends BasePacket { - - public PacketEnterTrialAvatarActivityDungeonRsp(int activityId, int trialAvatarIndexId, boolean success) { - this(activityId, trialAvatarIndexId, success ? RetcodeOuterClass.Retcode.RET_SUCC_VALUE : RetcodeOuterClass.Retcode.RET_FAIL_VALUE); - } - public PacketEnterTrialAvatarActivityDungeonRsp(int activityId, int trialAvatarIndexId, int retcodeVal) { - super(PacketOpcodes.EnterTrialAvatarActivityDungeonRsp); - this.setData(EnterTrialAvatarActivityDungeonRsp.newBuilder() - .setActivityId(activityId) - .setTrialAvatarIndexId(trialAvatarIndexId) - .setRetcode(retcodeVal)); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EnterTrialAvatarActivityDungeonRspOuterClass.EnterTrialAvatarActivityDungeonRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass; + +public class PacketEnterTrialAvatarActivityDungeonRsp extends BasePacket { + + public PacketEnterTrialAvatarActivityDungeonRsp( + int activityId, int trialAvatarIndexId, boolean success) { + this( + activityId, + trialAvatarIndexId, + success + ? RetcodeOuterClass.Retcode.RET_SUCC_VALUE + : RetcodeOuterClass.Retcode.RET_FAIL_VALUE); + } + + public PacketEnterTrialAvatarActivityDungeonRsp( + int activityId, int trialAvatarIndexId, int retcodeVal) { + super(PacketOpcodes.EnterTrialAvatarActivityDungeonRsp); + this.setData( + EnterTrialAvatarActivityDungeonRsp.newBuilder() + .setActivityId(activityId) + .setTrialAvatarIndexId(trialAvatarIndexId) + .setRetcode(retcodeVal)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketExecuteGadgetLuaRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketExecuteGadgetLuaRsp.java index 3ae98e150..52764557c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketExecuteGadgetLuaRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketExecuteGadgetLuaRsp.java @@ -1,19 +1,16 @@ - -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ExecuteGadgetLuaRspOuterClass.ExecuteGadgetLuaRsp; - -public class PacketExecuteGadgetLuaRsp extends BasePacket { - - public PacketExecuteGadgetLuaRsp(int result) { - super(PacketOpcodes.ExecuteGadgetLuaRsp, true); - - ExecuteGadgetLuaRsp proto = ExecuteGadgetLuaRsp.newBuilder() - .setRetcode(result) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ExecuteGadgetLuaRspOuterClass.ExecuteGadgetLuaRsp; + +public class PacketExecuteGadgetLuaRsp extends BasePacket { + + public PacketExecuteGadgetLuaRsp(int result) { + super(PacketOpcodes.ExecuteGadgetLuaRsp, true); + + ExecuteGadgetLuaRsp proto = ExecuteGadgetLuaRsp.newBuilder().setRetcode(result).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkNotify.java index 059194b02..0b8675742 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkNotify.java @@ -1,21 +1,19 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.FireWorkNotifyOuterClass; -import emu.grasscutter.net.proto.FireWorkDataOuterClass; - -public class PacketFireworkNotify extends BasePacket { - - public PacketFireworkNotify(FireWorkDataOuterClass.FireWorkData pinfo) { - super(PacketOpcodes.FireworkNotify); - - var proto - = FireWorkNotifyOuterClass.FireWorkNotify.newBuilder(); - - proto.addFireWorkData(pinfo); - - setData(proto.build()); - } - -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.FireWorkDataOuterClass; +import emu.grasscutter.net.proto.FireWorkNotifyOuterClass; + +public class PacketFireworkNotify extends BasePacket { + + public PacketFireworkNotify(FireWorkDataOuterClass.FireWorkData pinfo) { + super(PacketOpcodes.FireworkNotify); + + var proto = FireWorkNotifyOuterClass.FireWorkNotify.newBuilder(); + + proto.addFireWorkData(pinfo); + + setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkRsp.java index e5c7b3498..6f8db7b43 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkRsp.java @@ -1,12 +1,11 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; - -public class PacketFireworkRsp extends BasePacket { - - public PacketFireworkRsp() { - super(PacketOpcodes.FireworkRsp); - } - -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; + +public class PacketFireworkRsp extends BasePacket { + + public PacketFireworkRsp() { + super(PacketOpcodes.FireworkRsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkSetNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkSetNotify.java index 678573380..3a60cf735 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkSetNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkSetNotify.java @@ -1,21 +1,19 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.FireworkSetNotifyOuterClass; -import emu.grasscutter.net.proto.FireworkSetDataOuterClass; - -public class PacketFireworkSetNotify extends BasePacket { - - public PacketFireworkSetNotify(FireworkSetDataOuterClass.FireworkSetData notify) { - super(PacketOpcodes.FireworkSetNotify); - - var proto - = FireworkSetNotifyOuterClass.FireworkSetNotify.newBuilder(); - - proto.setCode(1).addData(notify); - - setData(proto.build()); - } - -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.FireworkSetDataOuterClass; +import emu.grasscutter.net.proto.FireworkSetNotifyOuterClass; + +public class PacketFireworkSetNotify extends BasePacket { + + public PacketFireworkSetNotify(FireworkSetDataOuterClass.FireworkSetData notify) { + super(PacketOpcodes.FireworkSetNotify); + + var proto = FireworkSetNotifyOuterClass.FireworkSetNotify.newBuilder(); + + proto.setCode(1).addData(notify); + + setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkSetRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkSetRsp.java index aad309164..14b951e19 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkSetRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketFireworkSetRsp.java @@ -1,13 +1,11 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; - -public class PacketFireworkSetRsp extends BasePacket { - - public PacketFireworkSetRsp() { - super(PacketOpcodes.FireworkSetRsp); - - } - -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; + +public class PacketFireworkSetRsp extends BasePacket { + + public PacketFireworkSetRsp() { + super(PacketOpcodes.FireworkSetRsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetDailyDungeonEntryInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetDailyDungeonEntryInfoRsp.java index fcfd4bb5b..e5c957900 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetDailyDungeonEntryInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetDailyDungeonEntryInfoRsp.java @@ -1,7 +1,7 @@ package emu.grasscutter.server.packet.send; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.DungeonEntryData; +import emu.grasscutter.data.excels.dungeon.DungeonEntryData; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.DailyDungeonEntryInfoOuterClass; diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetUgcBriefInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetUgcBriefInfoRsp.java index a884be7a6..23c163608 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetUgcBriefInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetUgcBriefInfoRsp.java @@ -1,35 +1,31 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetUgcBriefInfoRspOuterClass.GetUgcBriefInfoRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.UgcMusicBriefInfoOuterClass.UgcMusicBriefInfo; -import emu.grasscutter.net.proto.UgcTypeOuterClass.UgcType; - -public class PacketGetUgcBriefInfoRsp extends BasePacket { - - public PacketGetUgcBriefInfoRsp(RetcodeOuterClass.Retcode ret, UgcType unknownEnum1) { - super(PacketOpcodes.GetUgcBriefInfoRsp); - - var proto = GetUgcBriefInfoRsp.newBuilder(); - - proto.setRetcode(ret.getNumber()) - .setUgcType(unknownEnum1); - - this.setData(proto); - } - - public PacketGetUgcBriefInfoRsp(UgcMusicBriefInfo briefInfo, UgcType ugcType) { - super(PacketOpcodes.GetUgcBriefInfoRsp); - - var proto = GetUgcBriefInfoRsp.newBuilder(); - - proto.setMusicBriefInfo(briefInfo) - .setUgcType(ugcType); - - this.setData(proto); - } - - -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetUgcBriefInfoRspOuterClass.GetUgcBriefInfoRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.UgcMusicBriefInfoOuterClass.UgcMusicBriefInfo; +import emu.grasscutter.net.proto.UgcTypeOuterClass.UgcType; + +public class PacketGetUgcBriefInfoRsp extends BasePacket { + + public PacketGetUgcBriefInfoRsp(RetcodeOuterClass.Retcode ret, UgcType unknownEnum1) { + super(PacketOpcodes.GetUgcBriefInfoRsp); + + var proto = GetUgcBriefInfoRsp.newBuilder(); + + proto.setRetcode(ret.getNumber()).setUgcType(unknownEnum1); + + this.setData(proto); + } + + public PacketGetUgcBriefInfoRsp(UgcMusicBriefInfo briefInfo, UgcType ugcType) { + super(PacketOpcodes.GetUgcBriefInfoRsp); + + var proto = GetUgcBriefInfoRsp.newBuilder(); + + proto.setMusicBriefInfo(briefInfo).setUgcType(ugcType); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetUgcRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetUgcRsp.java index 6db0890ec..f7afba539 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetUgcRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetUgcRsp.java @@ -1,40 +1,41 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetUgcReqOuterClass.GetUgcReq; -import emu.grasscutter.net.proto.GetUgcRspOuterClass.GetUgcRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.UgcMusicBriefInfoOuterClass.UgcMusicBriefInfo; -import emu.grasscutter.net.proto.UgcMusicRecordOuterClass.UgcMusicRecord; - -public class PacketGetUgcRsp extends BasePacket { - - public PacketGetUgcRsp(UgcMusicBriefInfo briefInfo, UgcMusicRecord musicRecord, GetUgcReq req) { - super(PacketOpcodes.GetUgcRsp); - - var proto = GetUgcRsp.newBuilder(); - - proto - .setUgcGuid(briefInfo.getUgcGuid()) - .setUgcType(req.getUgcType()) - .setUgcRecordUsageValue(req.getUgcRecordUsageValue()) - .setMusicRecord(musicRecord) - .setMusicBriefInfo(briefInfo); - - this.setData(proto); - } - public PacketGetUgcRsp(Retcode errorCode, GetUgcReq req) { - super(PacketOpcodes.GetUgcRsp); - - var proto = GetUgcRsp.newBuilder(); - - proto - .setUgcGuid(req.getUgcGuid()) - .setUgcType(req.getUgcType()) - .setUgcRecordUsageValue(req.getUgcRecordUsageValue()) - .setRetcode(errorCode.getNumber()); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetUgcReqOuterClass.GetUgcReq; +import emu.grasscutter.net.proto.GetUgcRspOuterClass.GetUgcRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import emu.grasscutter.net.proto.UgcMusicBriefInfoOuterClass.UgcMusicBriefInfo; +import emu.grasscutter.net.proto.UgcMusicRecordOuterClass.UgcMusicRecord; + +public class PacketGetUgcRsp extends BasePacket { + + public PacketGetUgcRsp(UgcMusicBriefInfo briefInfo, UgcMusicRecord musicRecord, GetUgcReq req) { + super(PacketOpcodes.GetUgcRsp); + + var proto = GetUgcRsp.newBuilder(); + + proto + .setUgcGuid(briefInfo.getUgcGuid()) + .setUgcType(req.getUgcType()) + .setUgcRecordUsageValue(req.getUgcRecordUsageValue()) + .setMusicRecord(musicRecord) + .setMusicBriefInfo(briefInfo); + + this.setData(proto); + } + + public PacketGetUgcRsp(Retcode errorCode, GetUgcReq req) { + super(PacketOpcodes.GetUgcRsp); + + var proto = GetUgcRsp.newBuilder(); + + proto + .setUgcGuid(req.getUgcGuid()) + .setUgcType(req.getUgcType()) + .setUgcRecordUsageValue(req.getUgcRecordUsageValue()) + .setRetcode(errorCode.getNumber()); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUnknown1Notify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUnknown1Notify.java index 8fdaca533..467c9b50f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUnknown1Notify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUnknown1Notify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeUnknown1NotifyOuterClass; - -public class PacketHomeUnknown1Notify extends BasePacket { - - public PacketHomeUnknown1Notify(boolean isEnterEditMode) { - super(PacketOpcodes.Unk2700_JDMPECKFGIG_ServerNotify); - - var proto = HomeUnknown1NotifyOuterClass.HomeUnknown1Notify.newBuilder(); - - proto.setIsEnterEditMode(isEnterEditMode); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeUnknown1NotifyOuterClass; + +public class PacketHomeUnknown1Notify extends BasePacket { + + public PacketHomeUnknown1Notify(boolean isEnterEditMode) { + super(PacketOpcodes.Unk2700_JDMPECKFGIG_ServerNotify); + + var proto = HomeUnknown1NotifyOuterClass.HomeUnknown1Notify.newBuilder(); + + proto.setIsEnterEditMode(isEnterEditMode); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUnknown2Rsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUnknown2Rsp.java index 1aac1f721..31cef2efb 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUnknown2Rsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUnknown2Rsp.java @@ -1,12 +1,11 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; - -public class PacketHomeUnknown2Rsp extends BasePacket { - - public PacketHomeUnknown2Rsp() { - super(PacketOpcodes.Unk2700_KIIOGMKFNNP_ServerRsp); - - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; + +public class PacketHomeUnknown2Rsp extends BasePacket { + + public PacketHomeUnknown2Rsp() { + super(PacketOpcodes.Unk2700_KIIOGMKFNNP_ServerRsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlatformChangeRouteNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlatformChangeRouteNotify.java index c27275b8f..be3e25ca3 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlatformChangeRouteNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlatformChangeRouteNotify.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.EntityGadget; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlatformChangeRouteNotifyOuterClass.PlatformChangeRouteNotify; -import lombok.val; - -public class PacketPlatformChangeRouteNotify extends BasePacket { - - public PacketPlatformChangeRouteNotify(EntityGadget gadgetEntity) { - super(PacketOpcodes.PlatformChangeRouteNotify); - - val proto = PlatformChangeRouteNotify.newBuilder() - .setEntityId(gadgetEntity.getId()) - .setSceneTime(gadgetEntity.getScene().getSceneTime()) - .setPlatform(gadgetEntity.getPlatformInfo()) - .build(); - - this.setData(proto); - } - -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.EntityGadget; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlatformChangeRouteNotifyOuterClass.PlatformChangeRouteNotify; +import lombok.val; + +public class PacketPlatformChangeRouteNotify extends BasePacket { + + public PacketPlatformChangeRouteNotify(EntityGadget gadgetEntity) { + super(PacketOpcodes.PlatformChangeRouteNotify); + + val proto = + PlatformChangeRouteNotify.newBuilder() + .setEntityId(gadgetEntity.getId()) + .setSceneTime(gadgetEntity.getScene().getSceneTime()) + .setPlatform(gadgetEntity.getPlatformInfo()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java index 612386a90..8fc9c5dba 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java @@ -3,6 +3,7 @@ package emu.grasscutter.server.packet.send; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player.SceneLoadState; import emu.grasscutter.game.props.EnterReason; +import emu.grasscutter.game.world.data.TeleportProperties; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType; @@ -19,7 +20,7 @@ public class PacketPlayerEnterSceneNotify extends BasePacket { player.setSceneLoadState(SceneLoadState.LOADING); player.setEnterSceneToken(Utils.randomRange(1000, 99999)); - PlayerEnterSceneNotify.Builder proto = + var proto = PlayerEnterSceneNotify.newBuilder() .setSceneId(player.getSceneId()) .setPos(player.getPosition().toProto()) @@ -47,7 +48,10 @@ public class PacketPlayerEnterSceneNotify extends BasePacket { this(player, player, type, reason, newScene, newPos); } - // Teleport or go somewhere + public PacketPlayerEnterSceneNotify(Player player, TeleportProperties teleportProperties) { + this(player, player, teleportProperties); + } + public PacketPlayerEnterSceneNotify( Player player, Player target, @@ -55,34 +59,40 @@ public class PacketPlayerEnterSceneNotify extends BasePacket { EnterReason reason, int newScene, Position newPos) { - super(PacketOpcodes.PlayerEnterSceneNotify); + this( + player, + target, + TeleportProperties.builder() + .enterType(type) + .enterReason(reason) + .sceneId(newScene) + .teleportTo(newPos) + .build()); + } - // Set previous position - if (!(newScene == 3)) { // Hardcoded for now else weird positions will occur - // Don't update position within same scene or teapot - } else { - // Only used for exiting teapot currently - player.setPrevPos(player.getPosition()); - } + // Teleport or go somewhere + public PacketPlayerEnterSceneNotify( + Player player, Player target, TeleportProperties teleportProperties) { + super(PacketOpcodes.PlayerEnterSceneNotify); player.setSceneLoadState(SceneLoadState.LOADING); player.setEnterSceneToken(Utils.randomRange(1000, 99999)); - PlayerEnterSceneNotify.Builder proto = + var proto = PlayerEnterSceneNotify.newBuilder() .setPrevSceneId(player.getSceneId()) .setPrevPos(player.getPosition().toProto()) - .setSceneId(newScene) - .setPos(newPos.toProto()) + .setSceneId(teleportProperties.getSceneId()) + .setPos(teleportProperties.getTeleportTo().toProto()) .setSceneBeginTime(System.currentTimeMillis()) - .setType(type) + .setType(teleportProperties.getEnterType()) .setTargetUid(target.getUid()) .setEnterSceneToken(player.getEnterSceneToken()) .setWorldLevel(target.getWorld().getWorldLevel()) - .setEnterReason(reason.getValue()) + .setEnterReason(teleportProperties.getEnterReason().getValue()) .setWorldType(1) .setSceneTransaction( - newScene + teleportProperties.getSceneId() + "-" + target.getUid() + "-" diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestCreateEntityRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestCreateEntityRsp.java index e9dd110fc..d5fc3f645 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestCreateEntityRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestCreateEntityRsp.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.QuestCreateEntityReqOuterClass.QuestCreateEntityReq; -import emu.grasscutter.net.proto.QuestCreateEntityRspOuterClass.QuestCreateEntityRsp; - -public class PacketQuestCreateEntityRsp extends BasePacket { - - public PacketQuestCreateEntityRsp(int entityId, QuestCreateEntityReq req) { - super(PacketOpcodes.QuestCreateEntityRsp); - - this.setData(QuestCreateEntityRsp.newBuilder() - .setQuestId(req.getQuestId()) - .setEntity(req.getEntity()) - .setParentQuestId(req.getParentQuestId()) - .setIsRewind(req.getIsRewind()) - .setEntityId(entityId).setRetcode( - entityId!=-1 ? Retcode.RET_SUCC_VALUE : Retcode.RET_FAIL_VALUE)); - } - -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestCreateEntityReqOuterClass.QuestCreateEntityReq; +import emu.grasscutter.net.proto.QuestCreateEntityRspOuterClass.QuestCreateEntityRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +public class PacketQuestCreateEntityRsp extends BasePacket { + + public PacketQuestCreateEntityRsp(int entityId, QuestCreateEntityReq req) { + super(PacketOpcodes.QuestCreateEntityRsp); + + this.setData( + QuestCreateEntityRsp.newBuilder() + .setQuestId(req.getQuestId()) + .setEntity(req.getEntity()) + .setParentQuestId(req.getParentQuestId()) + .setIsRewind(req.getIsRewind()) + .setEntityId(entityId) + .setRetcode(entityId != -1 ? Retcode.RET_SUCC_VALUE : Retcode.RET_FAIL_VALUE)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestDestroyEntityRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestDestroyEntityRsp.java index 7fad0edb1..e5e637bc7 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestDestroyEntityRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestDestroyEntityRsp.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.QuestDestroyEntityRspOuterClass.QuestDestroyEntityRsp; -import emu.grasscutter.net.proto.QuestDestroyEntityReqOuterClass.QuestDestroyEntityReq; - -public class PacketQuestDestroyEntityRsp extends BasePacket { - - public PacketQuestDestroyEntityRsp(boolean success, QuestDestroyEntityReq req) { - super(PacketOpcodes.QuestDestroyEntityRsp); - - this.setData(QuestDestroyEntityRsp.newBuilder() - .setQuestId(req.getQuestId()) - .setEntityId(req.getEntityId()) - .setSceneId(req.getSceneId()) - .setRetcode(success ? Retcode.RET_SUCC_VALUE : Retcode.RET_FAIL_VALUE)); - } - -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestDestroyEntityReqOuterClass.QuestDestroyEntityReq; +import emu.grasscutter.net.proto.QuestDestroyEntityRspOuterClass.QuestDestroyEntityRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +public class PacketQuestDestroyEntityRsp extends BasePacket { + + public PacketQuestDestroyEntityRsp(boolean success, QuestDestroyEntityReq req) { + super(PacketOpcodes.QuestDestroyEntityRsp); + + this.setData( + QuestDestroyEntityRsp.newBuilder() + .setQuestId(req.getQuestId()) + .setEntityId(req.getEntityId()) + .setSceneId(req.getSceneId()) + .setRetcode(success ? Retcode.RET_SUCC_VALUE : Retcode.RET_FAIL_VALUE)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestDestroyNpcRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestDestroyNpcRsp.java index c0c9d1c4a..4b265152b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestDestroyNpcRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestDestroyNpcRsp.java @@ -1,20 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.QuestDestroyNpcRspOuterClass.QuestDestroyNpcRsp; - -public class PacketQuestDestroyNpcRsp extends BasePacket { - - public PacketQuestDestroyNpcRsp(int npcId, int parentQuestId, int retCode) { - super(PacketOpcodes.QuestDestroyNpcRsp, true); - - QuestDestroyNpcRsp proto = QuestDestroyNpcRsp.newBuilder() - .setNpcId(npcId) - .setParentQuestId(parentQuestId) - .setRetcode(retCode) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestDestroyNpcRspOuterClass.QuestDestroyNpcRsp; + +public class PacketQuestDestroyNpcRsp extends BasePacket { + + public PacketQuestDestroyNpcRsp(int npcId, int parentQuestId, int retCode) { + super(PacketOpcodes.QuestDestroyNpcRsp, true); + + QuestDestroyNpcRsp proto = + QuestDestroyNpcRsp.newBuilder() + .setNpcId(npcId) + .setParentQuestId(parentQuestId) + .setRetcode(retCode) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestTransmitRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestTransmitRsp.java index 4a47e1b78..0b3261eb8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestTransmitRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestTransmitRsp.java @@ -1,18 +1,19 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.QuestTransmitRspOuterClass.QuestTransmitRsp; -import emu.grasscutter.net.proto.QuestTransmitReqOuterClass.QuestTransmitReq; - -public class PacketQuestTransmitRsp extends BasePacket { - - public PacketQuestTransmitRsp(boolean result, QuestTransmitReq req) { - super(PacketOpcodes.QuestTransmitRsp); - this.setData(QuestTransmitRsp.newBuilder() - .setQuestId(req.getQuestId()) - .setPointId(req.getPointId()) - .setRetcode(result ? Retcode.RET_SUCC_VALUE : Retcode.RET_FAIL_VALUE)); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestTransmitReqOuterClass.QuestTransmitReq; +import emu.grasscutter.net.proto.QuestTransmitRspOuterClass.QuestTransmitRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +public class PacketQuestTransmitRsp extends BasePacket { + + public PacketQuestTransmitRsp(boolean result, QuestTransmitReq req) { + super(PacketOpcodes.QuestTransmitRsp); + this.setData( + QuestTransmitRsp.newBuilder() + .setQuestId(req.getQuestId()) + .setPointId(req.getPointId()) + .setRetcode(result ? Retcode.RET_SUCC_VALUE : Retcode.RET_FAIL_VALUE)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketReceivedTrialAvatarActivityRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketReceivedTrialAvatarActivityRewardRsp.java index 783fa25f6..cea70f144 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketReceivedTrialAvatarActivityRewardRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketReceivedTrialAvatarActivityRewardRsp.java @@ -1,21 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.ReceivedTrialAvatarActivityRewardRspOuterClass.ReceivedTrialAvatarActivityRewardRsp; - -public class PacketReceivedTrialAvatarActivityRewardRsp extends BasePacket { - - public PacketReceivedTrialAvatarActivityRewardRsp(int activityId, int trialAvatarId, boolean success) { - this(activityId, trialAvatarId, success ? Retcode.RET_SUCC_VALUE : Retcode.RET_FAIL_VALUE); - } - public PacketReceivedTrialAvatarActivityRewardRsp(int activityId, int trialAvatarId, int retcodeVal) { - super(PacketOpcodes.ReceivedTrialAvatarActivityRewardRsp); - this.setData(ReceivedTrialAvatarActivityRewardRsp.newBuilder() - .setActivityId(activityId) - .setTrialAvatarIndexId(trialAvatarId) - .setRetcode(retcodeVal) - .build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ReceivedTrialAvatarActivityRewardRspOuterClass.ReceivedTrialAvatarActivityRewardRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +public class PacketReceivedTrialAvatarActivityRewardRsp extends BasePacket { + + public PacketReceivedTrialAvatarActivityRewardRsp( + int activityId, int trialAvatarId, boolean success) { + this(activityId, trialAvatarId, success ? Retcode.RET_SUCC_VALUE : Retcode.RET_FAIL_VALUE); + } + + public PacketReceivedTrialAvatarActivityRewardRsp( + int activityId, int trialAvatarId, int retcodeVal) { + super(PacketOpcodes.ReceivedTrialAvatarActivityRewardRsp); + this.setData( + ReceivedTrialAvatarActivityRewardRsp.newBuilder() + .setActivityId(activityId) + .setTrialAvatarIndexId(trialAvatarId) + .setRetcode(retcodeVal) + .build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketRemoveCustomTeamRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketRemoveCustomTeamRsp.java index bbfa4b429..9f485cf31 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketRemoveCustomTeamRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketRemoveCustomTeamRsp.java @@ -1,23 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.RemoveCustomTeamRspOuterClass.RemoveCustomTeamRsp; - -public class PacketRemoveCustomTeamRsp extends BasePacket { - public PacketRemoveCustomTeamRsp(Retcode retcode, int id) { - super(PacketOpcodes.RemoveCustomTeamRsp); - - RemoveCustomTeamRsp proto = RemoveCustomTeamRsp.newBuilder() - .setRetcode(retcode.getNumber()) - .setId(id) - .build(); - - this.setData(proto); - } - - public PacketRemoveCustomTeamRsp(int id) { - this(Retcode.RET_SUCC, id); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.RemoveCustomTeamRspOuterClass.RemoveCustomTeamRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +public class PacketRemoveCustomTeamRsp extends BasePacket { + public PacketRemoveCustomTeamRsp(Retcode retcode, int id) { + super(PacketOpcodes.RemoveCustomTeamRsp); + + RemoveCustomTeamRsp proto = + RemoveCustomTeamRsp.newBuilder().setRetcode(retcode.getNumber()).setId(id).build(); + + this.setData(proto); + } + + public PacketRemoveCustomTeamRsp(int id) { + this(Retcode.RET_SUCC, id); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneForceLockNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneForceLockNotify.java index 790517a65..ba3d0fbab 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneForceLockNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneForceLockNotify.java @@ -1,25 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SceneForceLockNotifyOuterClass.SceneForceLockNotify; -import lombok.val; - -import java.util.Collection; - -public class PacketSceneForceLockNotify extends BasePacket { - public PacketSceneForceLockNotify(Collection locked) { - super(PacketOpcodes.SceneForceLockNotify); - val builder = SceneForceLockNotify.newBuilder() - .addAllForceIdList(locked); - - this.setData(builder); - } - public PacketSceneForceLockNotify(int locked) { - super(PacketOpcodes.SceneForceLockNotify); - val builder = SceneForceLockNotify.newBuilder() - .addForceIdList(locked); - - this.setData(builder); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneForceLockNotifyOuterClass.SceneForceLockNotify; +import java.util.Collection; +import lombok.val; + +public class PacketSceneForceLockNotify extends BasePacket { + public PacketSceneForceLockNotify(Collection locked) { + super(PacketOpcodes.SceneForceLockNotify); + val builder = SceneForceLockNotify.newBuilder().addAllForceIdList(locked); + + this.setData(builder); + } + + public PacketSceneForceLockNotify(int locked) { + super(PacketOpcodes.SceneForceLockNotify); + val builder = SceneForceLockNotify.newBuilder().addForceIdList(locked); + + this.setData(builder); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneForceUnlockNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneForceUnlockNotify.java index d5be59986..546d10fae 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneForceUnlockNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneForceUnlockNotify.java @@ -1,30 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SceneForceUnlockNotifyOuterClass.SceneForceUnlockNotify; -import lombok.val; - -import java.util.Collection; - -public class PacketSceneForceUnlockNotify extends BasePacket { - public PacketSceneForceUnlockNotify(Collection unlocked, boolean isAdd) { - super(PacketOpcodes.SceneForceUnlockNotify); - - val builder = SceneForceUnlockNotify.newBuilder() - .addAllForceIdList(unlocked) - .setIsAdd(isAdd); - - this.setData(builder); - } - - public PacketSceneForceUnlockNotify(int unlocked, boolean isAdd) { - super(PacketOpcodes.SceneForceUnlockNotify); - - val builder = SceneForceUnlockNotify.newBuilder() - .addForceIdList(unlocked) - .setIsAdd(isAdd); - - this.setData(builder); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneForceUnlockNotifyOuterClass.SceneForceUnlockNotify; +import java.util.Collection; +import lombok.val; + +public class PacketSceneForceUnlockNotify extends BasePacket { + public PacketSceneForceUnlockNotify(Collection unlocked, boolean isAdd) { + super(PacketOpcodes.SceneForceUnlockNotify); + + val builder = SceneForceUnlockNotify.newBuilder().addAllForceIdList(unlocked).setIsAdd(isAdd); + + this.setData(builder); + } + + public PacketSceneForceUnlockNotify(int unlocked, boolean isAdd) { + super(PacketOpcodes.SceneForceUnlockNotify); + + val builder = SceneForceUnlockNotify.newBuilder().addForceIdList(unlocked).setIsAdd(isAdd); + + this.setData(builder); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerSoundNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerSoundNotify.java index f32807c79..60d268a2f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerSoundNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerSoundNotify.java @@ -1,31 +1,32 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.utils.Position; -import emu.grasscutter.net.proto.ScenePlayerSoundNotifyOuterClass.ScenePlayerSoundNotify; -import emu.grasscutter.net.proto.ScenePlayerSoundNotifyOuterClass.ScenePlayerSoundNotify.PlaySoundType; -import emu.grasscutter.net.proto.VectorOuterClass.Vector; -import java.util.Objects; - -public class PacketScenePlayerSoundNotify extends BasePacket { - - public PacketScenePlayerSoundNotify(Position playPosition, String soundName, int playType) { - super(PacketOpcodes.ScenePlayerSoundNotify, true); - - ScenePlayerSoundNotify.Builder proto = ScenePlayerSoundNotify.newBuilder(); - if (!Objects.equals(playPosition, null)) { - proto.setPlayPos(Vector.newBuilder() - .setX(playPosition.getX()) - .setY(playPosition.getY()) - .setZ(playPosition.getZ()) - .build()); - } - if (!Objects.equals(soundName, null)) { - proto.setSoundName(soundName); - } - proto.setPlayType(PlaySoundType.forNumber(playType)); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ScenePlayerSoundNotifyOuterClass.ScenePlayerSoundNotify; +import emu.grasscutter.net.proto.ScenePlayerSoundNotifyOuterClass.ScenePlayerSoundNotify.PlaySoundType; +import emu.grasscutter.net.proto.VectorOuterClass.Vector; +import emu.grasscutter.utils.Position; +import java.util.Objects; + +public class PacketScenePlayerSoundNotify extends BasePacket { + + public PacketScenePlayerSoundNotify(Position playPosition, String soundName, int playType) { + super(PacketOpcodes.ScenePlayerSoundNotify, true); + + ScenePlayerSoundNotify.Builder proto = ScenePlayerSoundNotify.newBuilder(); + if (!Objects.equals(playPosition, null)) { + proto.setPlayPos( + Vector.newBuilder() + .setX(playPosition.getX()) + .setY(playPosition.getY()) + .setZ(playPosition.getZ()) + .build()); + } + if (!Objects.equals(soundName, null)) { + proto.setSoundName(soundName); + } + proto.setPlayType(PlaySoundType.forNumber(playType)); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTimeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTimeNotify.java index 64aa54ef8..490dfc641 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTimeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTimeNotify.java @@ -1,6 +1,7 @@ package emu.grasscutter.server.packet.send; import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.world.Scene; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.SceneTimeNotifyOuterClass.SceneTimeNotify; @@ -10,7 +11,7 @@ public class PacketSceneTimeNotify extends BasePacket { public PacketSceneTimeNotify(Player player) { super(PacketOpcodes.SceneTimeNotify); - SceneTimeNotify proto = + var proto = SceneTimeNotify.newBuilder() .setIsPaused(player.isPaused()) .setSceneId(player.getSceneId()) @@ -19,4 +20,17 @@ public class PacketSceneTimeNotify extends BasePacket { this.setData(proto); } + + public PacketSceneTimeNotify(Scene scene) { + super(PacketOpcodes.SceneTimeNotify); + + var proto = + SceneTimeNotify.newBuilder() + .setSceneId(scene.getId()) + .setSceneTime(scene.getSceneTime()) + .setIsPaused(scene.isPaused()) + .build(); + + this.setData(proto); + } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketShowClientGuideNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketShowClientGuideNotify.java index 68db81974..f699943fc 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketShowClientGuideNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketShowClientGuideNotify.java @@ -1,17 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ShowClientGuideNotifyOuterClass.ShowClientGuideNotify; - -public class PacketShowClientGuideNotify extends BasePacket { - - public PacketShowClientGuideNotify(String guideName) { - super(PacketOpcodes.ShowClientGuideNotify, true); - - ShowClientGuideNotify proto = ShowClientGuideNotify.newBuilder() - .setGuideName(guideName) - .build(); - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ShowClientGuideNotifyOuterClass.ShowClientGuideNotify; + +public class PacketShowClientGuideNotify extends BasePacket { + + public PacketShowClientGuideNotify(String guideName) { + super(PacketOpcodes.ShowClientGuideNotify, true); + + ShowClientGuideNotify proto = + ShowClientGuideNotify.newBuilder().setGuideName(guideName).build(); + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketShowCommonTipsNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketShowCommonTipsNotify.java index 7cf96abd0..360e4cbe1 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketShowCommonTipsNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketShowCommonTipsNotify.java @@ -1,17 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ShowCommonTipsNotifyOuterClass.ShowCommonTipsNotify; - -public class PacketShowCommonTipsNotify extends BasePacket { - - public PacketShowCommonTipsNotify(String title, String content, int closeTime) { - super(PacketOpcodes.ShowCommonTipsNotify); - this.setData(ShowCommonTipsNotify.newBuilder() - .setTitle(title) - .setContent(content) - .setCloseTime(closeTime) - .build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ShowCommonTipsNotifyOuterClass.ShowCommonTipsNotify; + +public class PacketShowCommonTipsNotify extends BasePacket { + + public PacketShowCommonTipsNotify(String title, String content, int closeTime) { + super(PacketOpcodes.ShowCommonTipsNotify); + this.setData( + ShowCommonTipsNotify.newBuilder() + .setTitle(title) + .setContent(content) + .setCloseTime(closeTime) + .build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockHomeBgmNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockHomeBgmNotify.java index 2bd5a7868..50d88a778 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockHomeBgmNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockHomeBgmNotify.java @@ -1,17 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.Unk2700MEBFPBDNPGOServerNotify; - -public class PacketUnlockHomeBgmNotify extends BasePacket { - public PacketUnlockHomeBgmNotify(int homeBgmId) { - super(PacketOpcodes.Unk2700_MEBFPBDNPGO_ServerNotify); - - var notify = Unk2700MEBFPBDNPGOServerNotify.Unk2700_MEBFPBDNPGO_ServerNotify.newBuilder() - .addUnk2700ELJPLMIHNIP(homeBgmId) - .build(); - - this.setData(notify); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.Unk2700MEBFPBDNPGOServerNotify; + +public class PacketUnlockHomeBgmNotify extends BasePacket { + public PacketUnlockHomeBgmNotify(int homeBgmId) { + super(PacketOpcodes.Unk2700_MEBFPBDNPGO_ServerNotify); + + var notify = + Unk2700MEBFPBDNPGOServerNotify.Unk2700_MEBFPBDNPGO_ServerNotify.newBuilder() + .addUnk2700ELJPLMIHNIP(homeBgmId) + .build(); + + this.setData(notify); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedHomeBgmNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedHomeBgmNotify.java index ad8c1e7c7..93e3c33ec 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedHomeBgmNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedHomeBgmNotify.java @@ -1,24 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.Unk2700LOHBMOKOPLHServerNotify; - -public class PacketUnlockedHomeBgmNotify extends BasePacket { - public PacketUnlockedHomeBgmNotify(Player player) { - super(PacketOpcodes.Unk2700_LOHBMOKOPLH_ServerNotify); - - if (player.getRealmList() == null) { - return; - } - - var unlocked = player.getHome().getUnlockedHomeBgmList(); - - var notify = Unk2700LOHBMOKOPLHServerNotify.Unk2700_LOHBMOKOPLH_ServerNotify.newBuilder() - .addAllUnk2700KMEKMNONMGE(unlocked) - .build(); - - this.setData(notify); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.Unk2700LOHBMOKOPLHServerNotify; + +public class PacketUnlockedHomeBgmNotify extends BasePacket { + public PacketUnlockedHomeBgmNotify(Player player) { + super(PacketOpcodes.Unk2700_LOHBMOKOPLH_ServerNotify); + + if (player.getRealmList() == null) { + return; + } + + var unlocked = player.getHome().getUnlockedHomeBgmList(); + + var notify = + Unk2700LOHBMOKOPLHServerNotify.Unk2700_LOHBMOKOPLH_ServerNotify.newBuilder() + .addAllUnk2700KMEKMNONMGE(unlocked) + .build(); + + this.setData(notify); + } +} diff --git a/src/main/java/emu/grasscutter/tools/Tools.java b/src/main/java/emu/grasscutter/tools/Tools.java index cc30db94c..c1e1a49eb 100644 --- a/src/main/java/emu/grasscutter/tools/Tools.java +++ b/src/main/java/emu/grasscutter/tools/Tools.java @@ -9,9 +9,9 @@ import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandMap; import emu.grasscutter.data.GameData; import emu.grasscutter.data.ResourceLoader; -import emu.grasscutter.data.excels.AchievementData; -import emu.grasscutter.data.excels.AvatarData; import emu.grasscutter.data.excels.ItemData; +import emu.grasscutter.data.excels.achievement.AchievementData; +import emu.grasscutter.data.excels.avatar.AvatarData; import emu.grasscutter.game.inventory.MaterialType; import emu.grasscutter.utils.Language; import emu.grasscutter.utils.Language.TextStrings; diff --git a/src/main/java/emu/grasscutter/utils/ConversionUtils.java b/src/main/java/emu/grasscutter/utils/ConversionUtils.java new file mode 100644 index 000000000..0b5a8967d --- /dev/null +++ b/src/main/java/emu/grasscutter/utils/ConversionUtils.java @@ -0,0 +1,24 @@ +package emu.grasscutter.utils; + +/* Various methods to convert from A -> B. */ +public interface ConversionUtils { + /** + * Converts in-game minutes to days. + * + * @param minutes The elapsed in-game minutes. + * @return The elapsed in-game days. + */ + static long gameTimeToDays(long minutes) { + return minutes / 1440; + } + + /** + * Converts in-game minutes to hours. + * + * @param minutes The elapsed in-game minutes. + * @return The elapsed in-game hours. + */ + static long gameTimeToHours(long minutes) { + return minutes / 60; + } +} diff --git a/src/main/java/emu/grasscutter/utils/GridPosition.java b/src/main/java/emu/grasscutter/utils/GridPosition.java index a2ba3c41d..1869186e8 100644 --- a/src/main/java/emu/grasscutter/utils/GridPosition.java +++ b/src/main/java/emu/grasscutter/utils/GridPosition.java @@ -1,118 +1,113 @@ -package emu.grasscutter.utils; - -import java.io.IOException; -import java.io.Serializable; -import java.util.List; - -import dev.morphia.annotations.Entity; -import lombok.Getter; -import lombok.Setter; - -@Entity -public class GridPosition implements Serializable { - private static final long serialVersionUID = -2001232300615923575L; - - @Getter @Setter private int x; - - @Getter @Setter private int z; - - @Getter @Setter private int width; - - public GridPosition() {} - - public GridPosition(int x, int y, int width) { - set(x, y, width); - } - - public GridPosition(GridPosition pos) { - this.set(pos); - } - - public GridPosition(Position pos, int width) { - this.set((int)(pos.getX() / width), (int)(pos.getZ() / width), width); - } - - public GridPosition(List xzwidth) { - this.width = xzwidth.get(2); - this.z = xzwidth.get(1); - this.x = xzwidth.get(0); - } - - public GridPosition(String str) throws IOException { - String[] listOfParams = str.replace(" ", "").replace("(", "").replace(")", "").split(","); - if(listOfParams.length != 3) - throw new IOException("invalid size on GridPosition definition - "); - try { - this.x = Integer.parseInt(listOfParams[0]); - this.z = Integer.parseInt(listOfParams[1]); - this.width = Integer.parseInt(listOfParams[2]); - } catch(NumberFormatException ignored) { - throw new IOException("invalid number on GridPosition definition - "); - } - } - - public GridPosition set(int x, int z) { - this.x = x; - this.z = z; - return this; - } - - public GridPosition set(int x, int z, int width) { - this.x = x; - this.z = z; - this.width = width; - return this; - } - - // Deep copy - public GridPosition set(GridPosition pos) { - return this.set(pos.getX(), pos.getZ(), pos.getWidth()); - } - - public GridPosition addClone(int x, int z) { - GridPosition pos = clone(); - pos.x += x; - pos.z += z; - return pos; - } - - @Override - public GridPosition clone() { - return new GridPosition(x, z, width); - } - - @Override - public String toString() { - return "(" + this.getX() + ", " + this.getZ() + ", " + this.getWidth() + ")"; - } - - public int[] toIntArray() { - return new int[]{ x, z, width }; - } - - public int[] toXZIntArray() { - return new int[]{ x, z }; - } - - @Override - public int hashCode() - { - int result = (int) (x ^ (x >>> 32)); - result = 31 * result + (int) (z ^ (z >>> 32)); - result = 31 * result + (int) (width ^ (width >>> 32)); - return result; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null) - return false; - if (getClass() != o.getClass()) - return false; - GridPosition pos = (GridPosition) o; - // field comparison - return pos.x == x && pos.z == z && pos.width == width; - } -} +package emu.grasscutter.utils; + +import dev.morphia.annotations.Entity; +import java.io.IOException; +import java.io.Serializable; +import java.util.List; +import lombok.Getter; +import lombok.Setter; + +@Entity +public class GridPosition implements Serializable { + private static final long serialVersionUID = -2001232300615923575L; + + @Getter @Setter private int x; + + @Getter @Setter private int z; + + @Getter @Setter private int width; + + public GridPosition() {} + + public GridPosition(int x, int y, int width) { + set(x, y, width); + } + + public GridPosition(GridPosition pos) { + this.set(pos); + } + + public GridPosition(Position pos, int width) { + this.set((int) (pos.getX() / width), (int) (pos.getZ() / width), width); + } + + public GridPosition(List xzwidth) { + this.width = xzwidth.get(2); + this.z = xzwidth.get(1); + this.x = xzwidth.get(0); + } + + public GridPosition(String str) throws IOException { + String[] listOfParams = str.replace(" ", "").replace("(", "").replace(")", "").split(","); + if (listOfParams.length != 3) + throw new IOException("invalid size on GridPosition definition - "); + try { + this.x = Integer.parseInt(listOfParams[0]); + this.z = Integer.parseInt(listOfParams[1]); + this.width = Integer.parseInt(listOfParams[2]); + } catch (NumberFormatException ignored) { + throw new IOException("invalid number on GridPosition definition - "); + } + } + + public GridPosition set(int x, int z) { + this.x = x; + this.z = z; + return this; + } + + public GridPosition set(int x, int z, int width) { + this.x = x; + this.z = z; + this.width = width; + return this; + } + + // Deep copy + public GridPosition set(GridPosition pos) { + return this.set(pos.getX(), pos.getZ(), pos.getWidth()); + } + + public GridPosition addClone(int x, int z) { + GridPosition pos = clone(); + pos.x += x; + pos.z += z; + return pos; + } + + @Override + public GridPosition clone() { + return new GridPosition(x, z, width); + } + + @Override + public String toString() { + return "(" + this.getX() + ", " + this.getZ() + ", " + this.getWidth() + ")"; + } + + public int[] toIntArray() { + return new int[] {x, z, width}; + } + + public int[] toXZIntArray() { + return new int[] {x, z}; + } + + @Override + public int hashCode() { + int result = (int) (x ^ (x >>> 32)); + result = 31 * result + (int) (z ^ (z >>> 32)); + result = 31 * result + (int) (width ^ (width >>> 32)); + return result; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null) return false; + if (getClass() != o.getClass()) return false; + GridPosition pos = (GridPosition) o; + // field comparison + return pos.x == x && pos.z == z && pos.width == width; + } +} diff --git a/src/main/java/emu/grasscutter/utils/KahnsSort.java b/src/main/java/emu/grasscutter/utils/KahnsSort.java index 7ee71bd76..aedad7253 100644 --- a/src/main/java/emu/grasscutter/utils/KahnsSort.java +++ b/src/main/java/emu/grasscutter/utils/KahnsSort.java @@ -1,66 +1,68 @@ -package emu.grasscutter.utils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Stack; - -public class KahnsSort { - public static class Node { - int source, dest; //Dest is a value, and source too - - public Node(int source, int dest) { - this.source = source; - this.dest = dest; - } - } - - public static class Graph { - Map> mainList; - Map degreeList; - - List nodeList; - - public Graph(List nodes, List nodeList) { - mainList = new HashMap<>(); - this.nodeList = nodeList; - - for(int i = 0; i < nodeList.size(); i++) mainList.put(nodeList.get(i), new ArrayList<>()); - - degreeList = new HashMap<>(); - for(int i = 0; i < nodeList.size(); i++) degreeList.put(nodeList.get(i), 0); - - for(Node node : nodes) { - mainList.get(node.source).add(node.dest); - degreeList.replace(node.dest, degreeList.get(node.dest) + 1); - } - } - } - - public static List doSort(Graph graph) { - List orderedList = new ArrayList<>(); - Map degreeList = graph.degreeList; - - Stack zeroStack = new Stack<>(); - degreeList.forEach((key, value) -> { - if(value == 0) zeroStack.add(key); - }); - - while(!zeroStack.isEmpty()) { - int element = zeroStack.pop(); - - //If the list is empty then this node - if(!graph.mainList.get(element).isEmpty()) orderedList.add(element); - for(int topElement : graph.mainList.get(element)) { - degreeList.replace(topElement, degreeList.get(topElement) - 1); - - if(degreeList.get(topElement) == 0) zeroStack.add(topElement); - } - } - - if(degreeList.values().stream().filter(value -> value != 0).count() != 0) return null; //Loop found - - return orderedList; - } -} +package emu.grasscutter.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +public class KahnsSort { + public static class Node { + int source, dest; // Dest is a value, and source too + + public Node(int source, int dest) { + this.source = source; + this.dest = dest; + } + } + + public static class Graph { + Map> mainList; + Map degreeList; + + List nodeList; + + public Graph(List nodes, List nodeList) { + mainList = new HashMap<>(); + this.nodeList = nodeList; + + for (int i = 0; i < nodeList.size(); i++) mainList.put(nodeList.get(i), new ArrayList<>()); + + degreeList = new HashMap<>(); + for (int i = 0; i < nodeList.size(); i++) degreeList.put(nodeList.get(i), 0); + + for (Node node : nodes) { + mainList.get(node.source).add(node.dest); + degreeList.replace(node.dest, degreeList.get(node.dest) + 1); + } + } + } + + public static List doSort(Graph graph) { + List orderedList = new ArrayList<>(); + Map degreeList = graph.degreeList; + + Stack zeroStack = new Stack<>(); + degreeList.forEach( + (key, value) -> { + if (value == 0) zeroStack.add(key); + }); + + while (!zeroStack.isEmpty()) { + int element = zeroStack.pop(); + + // If the list is empty then this node + if (!graph.mainList.get(element).isEmpty()) orderedList.add(element); + for (int topElement : graph.mainList.get(element)) { + degreeList.replace(topElement, degreeList.get(topElement) - 1); + + if (degreeList.get(topElement) == 0) zeroStack.add(topElement); + } + } + + if (degreeList.values().stream().filter(value -> value != 0).count() != 0) + return null; // Loop found + + return orderedList; + } +} diff --git a/src/main/java/emu/grasscutter/utils/Language.java b/src/main/java/emu/grasscutter/utils/Language.java index 3199d98b1..3ace8f010 100644 --- a/src/main/java/emu/grasscutter/utils/Language.java +++ b/src/main/java/emu/grasscutter/utils/Language.java @@ -8,7 +8,7 @@ import com.google.gson.JsonObject; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; import emu.grasscutter.data.ResourceLoader; -import emu.grasscutter.data.excels.AchievementData; +import emu.grasscutter.data.excels.achievement.AchievementData; import emu.grasscutter.game.player.Player; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;