From e85d269518a2b7465bb5259b10d3fec0a61c57d5 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sun, 23 Apr 2023 23:12:01 -0400 Subject: [PATCH] Run `spotlessApply` on previous commit --- .../grasscutter/data/binout/AbilityData.java | 78 +++-- .../data/binout/AbilityModifier.java | 292 ++++++++++++++---- .../emu/grasscutter/data/server/Grid.java | 10 +- .../emu/grasscutter/game/ability/Ability.java | 8 +- .../game/ability/AbilityAction.java | 3 +- .../game/ability/AbilityLocalIdGenerator.java | 16 +- .../game/ability/AbilityManager.java | 158 ++++++---- .../ability/AbilityModifierController.java | 4 +- .../ability/actions/ActionApplyModifier.java | 28 +- .../actions/ActionExecuteGadgetLua.java | 7 +- .../game/ability/actions/ActionKillSelf.java | 1 - .../game/activity/ActivityHandler.java | 11 +- .../grasscutter/game/entity/EntityGadget.java | 16 +- .../grasscutter/game/entity/GameEntity.java | 5 +- .../grasscutter/game/player/TeamManager.java | 6 +- .../emu/grasscutter/game/quest/GameQuest.java | 19 +- .../emu/grasscutter/game/world/Scene.java | 6 +- .../scripts/SceneScriptManager.java | 182 +++++++---- .../emu/grasscutter/utils/GridPosition.java | 5 +- 19 files changed, 579 insertions(+), 276 deletions(-) diff --git a/src/main/java/emu/grasscutter/data/binout/AbilityData.java b/src/main/java/emu/grasscutter/data/binout/AbilityData.java index 2a0e40425..9674e3d37 100644 --- a/src/main/java/emu/grasscutter/data/binout/AbilityData.java +++ b/src/main/java/emu/grasscutter/data/binout/AbilityData.java @@ -1,13 +1,12 @@ package emu.grasscutter.data.binout; +import static emu.grasscutter.game.ability.AbilityLocalIdGenerator.*; + import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.game.ability.AbilityLocalIdGenerator; - import java.util.HashMap; import java.util.Map; -import static emu.grasscutter.game.ability.AbilityLocalIdGenerator.*; - public class AbilityData { public String abilityName; public Map modifiers; @@ -19,44 +18,67 @@ public class AbilityData { // onAbilityStart // onKill - public final Map localIdToAction - = new HashMap<>(); + public final Map localIdToAction = new HashMap<>(); private boolean _initialized = false; + public void initialize() { - if(_initialized) return; + if (_initialized) return; _initialized = true; - if(modifiers == null) return; + if (modifiers == null) return; var _modifiers = modifiers.values().toArray(new AbilityModifier[0]); - var modifierIndex = 0; for (var modifier : _modifiers) { + var modifierIndex = 0; + for (var modifier : _modifiers) { long configIndex = 0L; - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onAdded, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onRemoved, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onBeingHit, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onAttackLanded, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onHittingOther, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onThinkInterval, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onKill, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onCrash, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onAvatarIn, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onAvatarOut, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onReconnect, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onChangeAuthority, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onVehicleIn, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onVehicleOut, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onZoneEnter, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onZoneExit, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onHeal, localIdToAction); - this.initializeActionSubCategory(modifierIndex, configIndex++, modifier.onBeingHealed, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onAdded, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onRemoved, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onBeingHit, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onAttackLanded, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onHittingOther, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onThinkInterval, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onKill, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onCrash, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onAvatarIn, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onAvatarOut, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onReconnect, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onChangeAuthority, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onVehicleIn, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onVehicleOut, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onZoneEnter, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onZoneExit, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onHeal, localIdToAction); + this.initializeActionSubCategory( + modifierIndex, configIndex++, modifier.onBeingHealed, localIdToAction); modifierIndex++; } } - private void initializeActionSubCategory(long modifierIndex, long configIndex, AbilityModifierAction[] actions, Map localIdToAction) { - if(actions == null) return; + private void initializeActionSubCategory( + long modifierIndex, + long configIndex, + AbilityModifierAction[] actions, + Map localIdToAction) { + if (actions == null) return; var generator = new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.MODIFIER_ACTION); generator.modifierIndex = modifierIndex; diff --git a/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java b/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java index 296e9a3b1..39a6b2507 100644 --- a/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java +++ b/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java @@ -1,19 +1,23 @@ package emu.grasscutter.data.binout; -import java.io.Serializable; - import com.google.gson.annotations.SerializedName; - import emu.grasscutter.data.common.DynamicFloat; import emu.grasscutter.game.props.ElementType; +import java.io.Serializable; public class AbilityModifier implements Serializable { private static final long serialVersionUID = -2001232313615923575L; - @SerializedName(value="onAdded", alternate={"KCICDEJLIJD"}) + @SerializedName( + value = "onAdded", + alternate = {"KCICDEJLIJD"}) public AbilityModifierAction[] onAdded; - @SerializedName(value="onThinkInterval", alternate={"PBDDACFFPOE"}) + + @SerializedName( + value = "onThinkInterval", + alternate = {"PBDDACFFPOE"}) public AbilityModifierAction[] onThinkInterval; + public AbilityModifierAction[] onRemoved; public AbilityModifierAction[] onBeingHit; public AbilityModifierAction[] onAttackLanded; @@ -38,74 +42,241 @@ public class AbilityModifier implements Serializable { public static class AbilityModifierAction implements Serializable { public enum Type { - ActCameraRadialBlur, ActCameraShake, AddAvatarSkillInfo, AddChargeBarValue, - AddClimateMeter, AddElementDurability, AddGlobalValue, AddGlobalValueToTarget, - AddRegionalPlayVarValue, ApplyModifier, AttachAbilityStateResistance, AttachBulletAimPoint, - AttachEffect, AttachEffectFirework, AttachElementTypeResistance, AttachModifier, - AttachUIEffect, AvatarCameraParam, AvatarEnterCameraShot, AvatarEnterFocus, - AvatarEnterViewBias, AvatarExitCameraShot, AvatarExitClimb, AvatarExitFocus, - AvatarExitViewBias, AvatarShareCDSkillStart, AvatarSkillStart, BroadcastNeuronStimulate, - CalcDvalinS04RebornPoint, CallLuaTask, ChangeEnviroWeather, ChangeFollowDampTime, - ChangeGadgetUIInteractHint, ChangePlayMode, ChangeTag, ChangeUGCRayTag, - ClearEndura, ClearGlobalPos, ClearGlobalValue, ClearLocalGadgets, - ClearLockTarget, ClearPos, ConfigAbilityAction, ControlEmotion, - CopyGlobalValue, CreateGadget, CreateMovingPlatform, CreateTile, - DamageByAttackValue, DebugLog, DestroyTile, DoBlink, - DoTileAction, DoWatcherSystemAction, DoWidgetSystemAction, DropSubfield, - DummyAction, DungeonFogEffects, ElementAttachForActivityGacha, EnableAIStealthy, - EnableAfterImage, EnableAvatarFlyStateTrail, EnableAvatarMoveOnWater, EnableBulletCollisionPluginTrigger, - EnableGadgetIntee, EnableHeadControl, EnableHitBoxByName, EnableMainInterface, - EnablePartControl, EnablePositionSynchronization, EnablePushColliderName, EnableRocketJump, - EnableSceneTransformByName, EnterCameraLock, EntityDoSkill, EquipAffixStart, - ExecuteGadgetLua, FireAISoundEvent, FireChargeBarEffect, FireEffect, - FireEffectFirework, FireEffectForStorm, FireFishingEvent, FireHitEffect, - FireSubEmitterEffect, FireUIEffect, FixedMonsterRushMove, ForceAirStateFly, - ForceEnableShakeOffButton, GenerateElemBall, GetFightProperty, GetInteractIdToGlobalValue, - GetPos, HealHP, HideUIBillBoard, IgnoreMoveColToRockCol, - KillGadget, KillPlayEntity, KillSelf, KillServerGadget, - LoseHP, ModifyAvatarSkillCD, ModifyVehicleSkillCD, PlayEmoSync, - Predicated, PushDvalinS01Process, PushInterActionByConfigPath, PushPos, - Randomed, ReTriggerAISkillInitialCD, RefreshUICombatBarLayout, RegisterAIActionPoint, - ReleaseAIActionPoint, RemoveAvatarSkillInfo, RemoveModifier, RemoveModifierByAbilityStateResistanceID, - RemoveServerBuff, RemoveUniqueModifier, RemoveVelocityForce, Repeated, - ResetAIAttackTarget, ResetAIResistTauntLevel, ResetAIThreatBroadcastRange, ResetAnimatorTrigger, - ReviveDeadAvatar, ReviveElemEnergy, ReviveStamina, SectorCityManeuver, - SendEffectTrigger, SendEffectTriggerToLineEffect, SendEvtElectricCoreMoveEnterP1, SendEvtElectricCoreMoveInterrupt, - ServerLuaCall, ServerLuaTriggerEvent, ServerMonsterLog, SetAIHitFeeling, - SetAISkillCDAvailableNow, SetAISkillCDMultiplier, SetAISkillGCD, SetAnimatorBool, - SetAnimatorFloat, SetAnimatorInt, SetAnimatorTrigger, SetAvatarCanShakeOff, - SetAvatarHitBuckets, SetCanDieImmediately, SetChargeBarValue, SetDvalinS01FlyState, - SetEmissionScaler, SetEntityScale, SetExtraAbilityEnable, SetExtraAbilityState, - SetGlobalDir, SetGlobalPos, SetGlobalValue, SetGlobalValueByTargetDistance, - SetGlobalValueToOverrideMap, SetKeepInAirVelocityForce, SetMaterialParamFloatByTransform, SetNeuronEnable, - SetOverrideMapValue, SetPartControlTarget, SetPoseBool, SetPoseFloat, - SetPoseInt, SetRandomOverrideMapValue, SetRegionalPlayVarValue, SetSelfAttackTarget, - SetSkillAnchor, SetSpecialCamera, SetSurroundAnchor, SetSystemValueToOverrideMap, - SetTargetNumToGlobalValue, SetUICombatBarAsh, SetUICombatBarSpark, SetVelocityIgnoreAirGY, - SetWeaponAttachPointRealName, SetWeaponBindState, ShowExtraAbility, ShowProgressBarAction, - ShowReminder, ShowScreenEffect, ShowTextMap, ShowUICombatBar, - StartDither, SumTargetWeightToSelfGlobalValue, Summon, SyncToStageScript, - TriggerAbility, TriggerAttackEvent, TriggerAttackTargetMapEvent, TriggerAudio, - TriggerAuxWeaponTrans, TriggerBullet, TriggerCreateGadgetToEquipPart, TriggerDropEquipParts, - TriggerFaceAnimation, TriggerGadgetInteractive, TriggerHideWeapon, TriggerSetCastShadow, - TriggerSetPassThrough, TriggerSetRenderersEnable, TriggerSetShadowRamp, TriggerSetVisible, - TriggerTaunt, TriggerThrowEquipPart, TriggerUGCGadgetMove, TryFindBlinkPoint, - TryFindBlinkPointByBorn, TryTriggerPlatformStartMove, TurnDirection, TurnDirectionToPos, - UpdateReactionDamage, UseSkillEliteSet, WidgetSkillStart; + ActCameraRadialBlur, + ActCameraShake, + AddAvatarSkillInfo, + AddChargeBarValue, + AddClimateMeter, + AddElementDurability, + AddGlobalValue, + AddGlobalValueToTarget, + AddRegionalPlayVarValue, + ApplyModifier, + AttachAbilityStateResistance, + AttachBulletAimPoint, + AttachEffect, + AttachEffectFirework, + AttachElementTypeResistance, + AttachModifier, + AttachUIEffect, + AvatarCameraParam, + AvatarEnterCameraShot, + AvatarEnterFocus, + AvatarEnterViewBias, + AvatarExitCameraShot, + AvatarExitClimb, + AvatarExitFocus, + AvatarExitViewBias, + AvatarShareCDSkillStart, + AvatarSkillStart, + BroadcastNeuronStimulate, + CalcDvalinS04RebornPoint, + CallLuaTask, + ChangeEnviroWeather, + ChangeFollowDampTime, + ChangeGadgetUIInteractHint, + ChangePlayMode, + ChangeTag, + ChangeUGCRayTag, + ClearEndura, + ClearGlobalPos, + ClearGlobalValue, + ClearLocalGadgets, + ClearLockTarget, + ClearPos, + ConfigAbilityAction, + ControlEmotion, + CopyGlobalValue, + CreateGadget, + CreateMovingPlatform, + CreateTile, + DamageByAttackValue, + DebugLog, + DestroyTile, + DoBlink, + DoTileAction, + DoWatcherSystemAction, + DoWidgetSystemAction, + DropSubfield, + DummyAction, + DungeonFogEffects, + ElementAttachForActivityGacha, + EnableAIStealthy, + EnableAfterImage, + EnableAvatarFlyStateTrail, + EnableAvatarMoveOnWater, + EnableBulletCollisionPluginTrigger, + EnableGadgetIntee, + EnableHeadControl, + EnableHitBoxByName, + EnableMainInterface, + EnablePartControl, + EnablePositionSynchronization, + EnablePushColliderName, + EnableRocketJump, + EnableSceneTransformByName, + EnterCameraLock, + EntityDoSkill, + EquipAffixStart, + ExecuteGadgetLua, + FireAISoundEvent, + FireChargeBarEffect, + FireEffect, + FireEffectFirework, + FireEffectForStorm, + FireFishingEvent, + FireHitEffect, + FireSubEmitterEffect, + FireUIEffect, + FixedMonsterRushMove, + ForceAirStateFly, + ForceEnableShakeOffButton, + GenerateElemBall, + GetFightProperty, + GetInteractIdToGlobalValue, + GetPos, + HealHP, + HideUIBillBoard, + IgnoreMoveColToRockCol, + KillGadget, + KillPlayEntity, + KillSelf, + KillServerGadget, + LoseHP, + ModifyAvatarSkillCD, + ModifyVehicleSkillCD, + PlayEmoSync, + Predicated, + PushDvalinS01Process, + PushInterActionByConfigPath, + PushPos, + Randomed, + ReTriggerAISkillInitialCD, + RefreshUICombatBarLayout, + RegisterAIActionPoint, + ReleaseAIActionPoint, + RemoveAvatarSkillInfo, + RemoveModifier, + RemoveModifierByAbilityStateResistanceID, + RemoveServerBuff, + RemoveUniqueModifier, + RemoveVelocityForce, + Repeated, + ResetAIAttackTarget, + ResetAIResistTauntLevel, + ResetAIThreatBroadcastRange, + ResetAnimatorTrigger, + ReviveDeadAvatar, + ReviveElemEnergy, + ReviveStamina, + SectorCityManeuver, + SendEffectTrigger, + SendEffectTriggerToLineEffect, + SendEvtElectricCoreMoveEnterP1, + SendEvtElectricCoreMoveInterrupt, + ServerLuaCall, + ServerLuaTriggerEvent, + ServerMonsterLog, + SetAIHitFeeling, + SetAISkillCDAvailableNow, + SetAISkillCDMultiplier, + SetAISkillGCD, + SetAnimatorBool, + SetAnimatorFloat, + SetAnimatorInt, + SetAnimatorTrigger, + SetAvatarCanShakeOff, + SetAvatarHitBuckets, + SetCanDieImmediately, + SetChargeBarValue, + SetDvalinS01FlyState, + SetEmissionScaler, + SetEntityScale, + SetExtraAbilityEnable, + SetExtraAbilityState, + SetGlobalDir, + SetGlobalPos, + SetGlobalValue, + SetGlobalValueByTargetDistance, + SetGlobalValueToOverrideMap, + SetKeepInAirVelocityForce, + SetMaterialParamFloatByTransform, + SetNeuronEnable, + SetOverrideMapValue, + SetPartControlTarget, + SetPoseBool, + SetPoseFloat, + SetPoseInt, + SetRandomOverrideMapValue, + SetRegionalPlayVarValue, + SetSelfAttackTarget, + SetSkillAnchor, + SetSpecialCamera, + SetSurroundAnchor, + SetSystemValueToOverrideMap, + SetTargetNumToGlobalValue, + SetUICombatBarAsh, + SetUICombatBarSpark, + SetVelocityIgnoreAirGY, + SetWeaponAttachPointRealName, + SetWeaponBindState, + ShowExtraAbility, + ShowProgressBarAction, + ShowReminder, + ShowScreenEffect, + ShowTextMap, + ShowUICombatBar, + StartDither, + SumTargetWeightToSelfGlobalValue, + Summon, + SyncToStageScript, + TriggerAbility, + TriggerAttackEvent, + TriggerAttackTargetMapEvent, + TriggerAudio, + TriggerAuxWeaponTrans, + TriggerBullet, + TriggerCreateGadgetToEquipPart, + TriggerDropEquipParts, + TriggerFaceAnimation, + TriggerGadgetInteractive, + TriggerHideWeapon, + TriggerSetCastShadow, + TriggerSetPassThrough, + TriggerSetRenderersEnable, + TriggerSetShadowRamp, + TriggerSetVisible, + TriggerTaunt, + TriggerThrowEquipPart, + TriggerUGCGadgetMove, + TryFindBlinkPoint, + TryFindBlinkPointByBorn, + TryTriggerPlatformStartMove, + TurnDirection, + TurnDirectionToPos, + UpdateReactionDamage, + UseSkillEliteSet, + WidgetSkillStart; } + @SerializedName("$type") public Type type; + public String target; + @SerializedName(value = "amount", alternate = "PDLLIFICICJ") public DynamicFloat amount = DynamicFloat.ZERO; + public DynamicFloat amountByCasterAttackRatio = DynamicFloat.ZERO; public DynamicFloat amountByCasterCurrentHPRatio = DynamicFloat.ZERO; public DynamicFloat amountByCasterMaxHPRatio = DynamicFloat.ZERO; public DynamicFloat amountByGetDamage = DynamicFloat.ZERO; public DynamicFloat amountByTargetCurrentHPRatio = DynamicFloat.ZERO; public DynamicFloat amountByTargetMaxHPRatio = DynamicFloat.ZERO; + @SerializedName(value = "ignoreAbilityProperty", alternate = "HHFGADCJJDI") public boolean ignoreAbilityProperty; + public String modifierName; public int param1; @@ -113,7 +284,8 @@ public class AbilityModifier implements Serializable { public int param3; } - //The following should be implemented into DynamicFloat if older resource formats need to be supported + // The following should be implemented into DynamicFloat if older resource formats need to be + // supported // public static class AbilityModifierValue { // public boolean isFormula; // public boolean isDynamic; diff --git a/src/main/java/emu/grasscutter/data/server/Grid.java b/src/main/java/emu/grasscutter/data/server/Grid.java index bf332b8ec..3a0ed2536 100644 --- a/src/main/java/emu/grasscutter/data/server/Grid.java +++ b/src/main/java/emu/grasscutter/data/server/Grid.java @@ -6,7 +6,6 @@ import emu.grasscutter.Grasscutter; import emu.grasscutter.scripts.SceneIndexManager; import emu.grasscutter.utils.GridPosition; import emu.grasscutter.utils.Position; - import java.util.*; public class Grid { @@ -15,14 +14,13 @@ public class Grid { public Map> grid = new LinkedHashMap<>(); - /** - * Creates an optimized cache of the grid. - */ + /** Creates an optimized cache of the grid. */ private void optimize() { if (this.gridOptimized == null) { var gridValues = new ArrayList>>(); this.grid.forEach((k, v) -> gridValues.add(new AbstractMap.SimpleEntry<>(k, v))); - this.gridOptimized = SceneIndexManager.buildIndex(2, gridValues, entry -> entry.getKey().toPoint()); + this.gridOptimized = + SceneIndexManager.buildIndex(2, gridValues, entry -> entry.getKey().toPoint()); } } @@ -57,7 +55,7 @@ public class Grid { // Construct a list of nearby groups. SceneIndexManager.queryNeighbors(gridOptimized, pos.toDoubleArray(), vision_range_grid + 1) - .forEach(e -> nearbyGroups.addAll(e.getValue())); + .forEach(e -> nearbyGroups.addAll(e.getValue())); return this.nearbyGroups; } } diff --git a/src/main/java/emu/grasscutter/game/ability/Ability.java b/src/main/java/emu/grasscutter/game/ability/Ability.java index f9f0f14d6..b77865c9e 100644 --- a/src/main/java/emu/grasscutter/game/ability/Ability.java +++ b/src/main/java/emu/grasscutter/game/ability/Ability.java @@ -1,12 +1,11 @@ package emu.grasscutter.game.ability; -import java.util.HashMap; -import java.util.Map; - import emu.grasscutter.data.binout.AbilityData; import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.server.event.entity.EntityDamageEvent; import emu.grasscutter.utils.Utils; +import java.util.HashMap; +import java.util.Map; import lombok.Getter; public final class Ability { @@ -14,8 +13,7 @@ public final class Ability { @Getter private GameEntity owner; @Getter private AbilityManager manager; - @Getter private Map modifiers - = new HashMap<>(); + @Getter private Map modifiers = new HashMap<>(); @Getter private int hash; diff --git a/src/main/java/emu/grasscutter/game/ability/AbilityAction.java b/src/main/java/emu/grasscutter/game/ability/AbilityAction.java index 508dffbed..42cd519b6 100644 --- a/src/main/java/emu/grasscutter/game/ability/AbilityAction.java +++ b/src/main/java/emu/grasscutter/game/ability/AbilityAction.java @@ -1,10 +1,9 @@ package emu.grasscutter.game.ability; +import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; - @Retention(RetentionPolicy.RUNTIME) public @interface AbilityAction { AbilityModifierAction.Type value(); diff --git a/src/main/java/emu/grasscutter/game/ability/AbilityLocalIdGenerator.java b/src/main/java/emu/grasscutter/game/ability/AbilityLocalIdGenerator.java index 51eb35298..c44fe9316 100644 --- a/src/main/java/emu/grasscutter/game/ability/AbilityLocalIdGenerator.java +++ b/src/main/java/emu/grasscutter/game/ability/AbilityLocalIdGenerator.java @@ -2,9 +2,8 @@ package emu.grasscutter.game.ability; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; -import lombok.AllArgsConstructor; - import java.util.Map; +import lombok.AllArgsConstructor; public final class AbilityLocalIdGenerator { public ConfigAbilitySubContainerType type; @@ -13,13 +12,12 @@ public final class AbilityLocalIdGenerator { public long mixinIndex = 0; private long actionIndex = 0; - public AbilityLocalIdGenerator(ConfigAbilitySubContainerType type) - { + public AbilityLocalIdGenerator(ConfigAbilitySubContainerType type) { this.type = type; } - public void initializeActionLocalIds(AbilityModifierAction[] actions, Map localIdToAction) - { + public void initializeActionLocalIds( + AbilityModifierAction[] actions, Map localIdToAction) { if (actions == null) return; actionIndex = 0; @@ -44,7 +42,11 @@ public final class AbilityLocalIdGenerator { return type.value + (modifierIndex << 3) + (configIndex << 9) + (actionIndex << 15); } case MODIFIER_MIXIN -> { - return type.value + (modifierIndex << 3) + (mixinIndex << 9) + (configIndex << 15) + (actionIndex << 21); + return type.value + + (modifierIndex << 3) + + (mixinIndex << 9) + + (configIndex << 15) + + (actionIndex << 21); } case NONE -> Grasscutter.getLogger().error("Ability local id generator using NONE type."); } diff --git a/src/main/java/emu/grasscutter/game/ability/AbilityManager.java b/src/main/java/emu/grasscutter/game/ability/AbilityManager.java index fec0df009..78e110624 100644 --- a/src/main/java/emu/grasscutter/game/ability/AbilityManager.java +++ b/src/main/java/emu/grasscutter/game/ability/AbilityManager.java @@ -13,29 +13,36 @@ import emu.grasscutter.game.player.BasePlayerManager; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.quest.enums.QuestContent; import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; +import emu.grasscutter.net.proto.AbilityMetaAddAbilityOuterClass.AbilityMetaAddAbility; import emu.grasscutter.net.proto.AbilityMetaModifierChangeOuterClass.AbilityMetaModifierChange; +import emu.grasscutter.net.proto.AbilityMetaModifierDurabilityChangeOuterClass.AbilityMetaModifierDurabilityChange; import emu.grasscutter.net.proto.AbilityMetaReInitOverrideMapOuterClass.AbilityMetaReInitOverrideMap; import emu.grasscutter.net.proto.AbilityMixinCostStaminaOuterClass.AbilityMixinCostStamina; import emu.grasscutter.net.proto.AbilityScalarValueEntryOuterClass.AbilityScalarValueEntry; import emu.grasscutter.net.proto.ModifierActionOuterClass.ModifierAction; import io.netty.util.concurrent.FastThreadLocalThread; -import lombok.Getter; -import org.reflections.Reflections; - import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import lombok.Getter; +import org.reflections.Reflections; public final class AbilityManager extends BasePlayerManager { public static final ExecutorService eventExecutor; static { - eventExecutor = new ThreadPoolExecutor(4, 4, - 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(1000), - FastThreadLocalThread::new, new ThreadPoolExecutor.AbortPolicy()); + eventExecutor = + new ThreadPoolExecutor( + 4, + 4, + 60, + TimeUnit.SECONDS, + new LinkedBlockingDeque<>(1000), + FastThreadLocalThread::new, + new ThreadPoolExecutor.AbortPolicy()); } private final HealAbilityManager healAbilityManager; @@ -52,9 +59,7 @@ public final class AbilityManager extends BasePlayerManager { this.registerHandlers(); } - /** - * Registers all present ability handlers. - */ + /** Registers all present ability handlers. */ private void registerHandlers() { var reflections = new Reflections("emu.grasscutter.game.ability.actions"); var handlerClasses = reflections.getSubTypesOf(AbilityActionHandler.class); @@ -77,22 +82,31 @@ public final class AbilityManager extends BasePlayerManager { var handler = actionHandlers.get(action.type); if (handler == null || ability == null) { - Grasscutter.getLogger().debug("Could not execute ability action {} at {}", action.type, ability); + Grasscutter.getLogger() + .debug("Could not execute ability action {} at {}", action.type, ability); return; } - eventExecutor.submit(() -> { - if (!handler.execute(ability, action)) { - Grasscutter.getLogger().debug("exec ability action failed {} at {}", action.type, ability); - } - }); + eventExecutor.submit( + () -> { + if (!handler.execute(ability, action)) { + Grasscutter.getLogger() + .debug("exec ability action failed {} at {}", action.type, ability); + } + }); } public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception { this.healAbilityManager.healHandler(invoke); if (invoke.getEntityId() == 67109298) { - Grasscutter.getLogger().info(invoke.getArgumentType() + " (" + invoke.getArgumentTypeValue() + "): " + invoke.getEntityId()); + Grasscutter.getLogger() + .info( + invoke.getArgumentType() + + " (" + + invoke.getArgumentTypeValue() + + "): " + + invoke.getEntityId()); } switch (invoke.getArgumentType()) { @@ -102,7 +116,8 @@ public final class AbilityManager extends BasePlayerManager { 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); - case ABILITY_INVOKE_ARGUMENT_META_MODIFIER_DURABILITY_CHANGE -> this.handleModifierDurabilityChange(invoke); + case ABILITY_INVOKE_ARGUMENT_META_MODIFIER_DURABILITY_CHANGE -> this + .handleModifierDurabilityChange(invoke); case ABILITY_INVOKE_ARGUMENT_META_ADD_NEW_ABILITY -> this.handleAddNewAbility(invoke); case ABILITY_INVOKE_ARGUMENT_NONE -> this.handleInvoke(invoke); default -> {} @@ -173,29 +188,39 @@ public final class AbilityManager extends BasePlayerManager { } var head = invoke.getHead(); - Grasscutter.getLogger().debug("{} {} {}", head.getInstancedAbilityId(), entity.getInstanceToHash(), head.getLocalId()); + Grasscutter.getLogger() + .debug( + "{} {} {}", + head.getInstancedAbilityId(), + entity.getInstanceToHash(), + head.getLocalId()); var hash = entity.getInstanceToHash().get(head.getInstancedAbilityId()); if (hash == null) { var abilities = entity.getAbilities().values().toArray(new Ability[0]); - if(head.getInstancedAbilityId() <= abilities.length) { + if (head.getInstancedAbilityId() <= abilities.length) { var ability = abilities[head.getInstancedAbilityId() - 1]; Grasscutter.getLogger().warn("-> {}", ability.getData().localIdToAction); var action = ability.getData().localIdToAction.get(head.getLocalId()); - if(action != null) ability.getManager().executeAction(ability, action); + if (action != null) ability.getManager().executeAction(ability, action); } return; } - var stream = entity.getAbilities().values().stream() - .filter(a -> a.getHash() == hash || - a.getData().abilityName == entity.getInstanceToName().get(head.getInstancedAbilityId())); - stream.forEach(ability -> { - var action = ability.getData().localIdToAction.get(head.getLocalId()); - if(action != null) ability.getManager().executeAction(ability, action); - }); + var stream = + entity.getAbilities().values().stream() + .filter( + a -> + a.getHash() == hash + || a.getData().abilityName + == entity.getInstanceToName().get(head.getInstancedAbilityId())); + stream.forEach( + ability -> { + var action = ability.getData().localIdToAction.get(head.getLocalId()); + if (action != null) ability.getManager().executeAction(ability, action); + }); } private void handleOverrideParam(AbilityInvokeEntry invoke) throws Exception { @@ -248,7 +273,7 @@ public final class AbilityManager extends BasePlayerManager { if (data.getAction() == ModifierAction.MODIFIER_ACTION_REMOVED) { var ability = target.getAbilities().get(data.getParentAbilityName().getStr()); - if(ability != null) { + if (ability != null) { var modifier = ability.getModifiers().get(head.getInstancedModifierId()); if (modifier != null) { modifier.onRemoved(); @@ -257,16 +282,26 @@ public final class AbilityManager extends BasePlayerManager { } } - if(data.getAction() == ModifierAction.MODIFIER_ACTION_ADDED) { + if (data.getAction() == ModifierAction.MODIFIER_ACTION_ADDED) { var modifierString = data.getParentAbilityName().getStr(); var hash = target.getInstanceToHash().get(head.getInstancedAbilityId()); - if(hash == null) return; + if (hash == null) return; - target.getAbilities().values().stream().filter(a -> a.getHash() == hash || a.getData().abilityName == target.getInstanceToName().get(head.getInstancedAbilityId())).forEach(a -> { - a.getModifiers().keySet().stream().filter(key -> key.compareTo(modifierString) == 0).forEach(key -> { - a.getModifiers().get(key).setLocalId(head.getInstancedModifierId()); - }); - }); + target.getAbilities().values().stream() + .filter( + a -> + a.getHash() == hash + || a.getData().abilityName + == target.getInstanceToName().get(head.getInstancedAbilityId())) + .forEach( + a -> { + a.getModifiers().keySet().stream() + .filter(key -> key.compareTo(modifierString) == 0) + .forEach( + key -> { + a.getModifiers().get(key).setLocalId(head.getInstancedModifierId()); + }); + }); } var sourceEntity = this.player.getScene().getEntityById(data.getApplyEntityId()); @@ -362,7 +397,8 @@ public final class AbilityManager extends BasePlayerManager { } } - private void handleModifierDurabilityChange(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException { + private void handleModifierDurabilityChange(AbilityInvokeEntry invoke) + throws InvalidProtocolBufferException { var target = this.player.getScene().getEntityById(invoke.getEntityId()); if (target == null) { return; @@ -374,41 +410,53 @@ public final class AbilityManager extends BasePlayerManager { } var head = invoke.getHead(); - if (head == null) { - return; - } - var hash = target.getInstanceToHash().get(head.getInstancedAbilityId()); - if(hash == null) return; - target.getAbilities().values().stream().filter(a -> a.getHash() == hash || a.getData().abilityName == target.getInstanceToName().get(head.getInstancedAbilityId())).forEach(a -> { - a.getModifiers().values().stream().filter(m -> m.getLocalId() == head.getInstancedModifierId()).forEach(modifier -> { - modifier.setElementDurability(data.getRemainDurability()); - }); - }); + if (hash == null) return; + target.getAbilities().values().stream() + .filter( + a -> + a.getHash() == hash + || a.getData().abilityName + == target.getInstanceToName().get(head.getInstancedAbilityId())) + .forEach( + a -> { + a.getModifiers().values().stream() + .filter(m -> m.getLocalId() == head.getInstancedModifierId()) + .forEach( + modifier -> { + modifier.setElementDurability(data.getRemainDurability()); + }); + }); } - private void handleAddNewAbility(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException { + private void handleAddNewAbility(AbilityInvokeEntry invoke) + throws InvalidProtocolBufferException { var data = AbilityMetaAddAbility.parseFrom(invoke.getAbilityData()); if (data == null) { return; -} + } - if(data.getAbility().getAbilityName().getHash() != 0) Grasscutter.getLogger().warn("Instancing {} in to {}", data.getAbility().getAbilityName().getHash(), data.getAbility().getInstancedAbilityId()); - else Grasscutter.getLogger().warn("Instancing {} in to {}", data.getAbility().getAbilityName().getStr(), data.getAbility().getInstancedAbilityId()); + var ability = data.getAbility(); + var abilityName = ability.getAbilityName(); + if (abilityName.getHash() != 0) + Grasscutter.getLogger() + .warn("Instancing {} in to {}", abilityName.getHash(), ability.getInstancedAbilityId()); + else + Grasscutter.getLogger() + .warn("Instancing {} in to {}", abilityName.getStr(), ability.getInstancedAbilityId()); - GameEntity target = this.player.getScene().getEntityById(invoke.getEntityId()); + var target = this.player.getScene().getEntityById(invoke.getEntityId()); if (target == null) { return; } - target.getInstanceToHash().put(data.getAbility().getInstancedAbilityId(), data.getAbility().getAbilityName().getHash()); - target.getInstanceToName().put(data.getAbility().getInstancedAbilityId(), data.getAbility().getAbilityName().getStr()); + target.getInstanceToHash().put(ability.getInstancedAbilityId(), abilityName.getHash()); + target.getInstanceToName().put(ability.getInstancedAbilityId(), abilityName.getStr()); } public void addAbilityToEntity(GameEntity entity, String name) { var data = GameData.getAbilityData(name); - if(data != null) - addAbilityToEntity(entity, data, name); + if (data != null) addAbilityToEntity(entity, data, name); } public void addAbilityToEntity(GameEntity entity, AbilityData abilityData, String id) { diff --git a/src/main/java/emu/grasscutter/game/ability/AbilityModifierController.java b/src/main/java/emu/grasscutter/game/ability/AbilityModifierController.java index f1914f95f..0a7cfe4dc 100644 --- a/src/main/java/emu/grasscutter/game/ability/AbilityModifierController.java +++ b/src/main/java/emu/grasscutter/game/ability/AbilityModifierController.java @@ -9,7 +9,7 @@ import lombok.Setter; public final class AbilityModifierController { @Getter private AbilityModifier data; - @Getter private Ability ability; //Owner ability instance + @Getter private Ability ability; // Owner ability instance @Getter private float elementDurability; @@ -54,7 +54,7 @@ public final class AbilityModifierController { if (event.getAttackElementType().equals(data.elementType)) { elementDurability -= event.getDamage(); - if(elementDurability <= 0) { + if (elementDurability <= 0) { onRemoved(); ability.getModifiers().values().removeIf(a -> a == this); } diff --git a/src/main/java/emu/grasscutter/game/ability/actions/ActionApplyModifier.java b/src/main/java/emu/grasscutter/game/ability/actions/ActionApplyModifier.java index 8c6d4c60a..79f278e09 100644 --- a/src/main/java/emu/grasscutter/game/ability/actions/ActionApplyModifier.java +++ b/src/main/java/emu/grasscutter/game/ability/actions/ActionApplyModifier.java @@ -18,9 +18,10 @@ public final class ActionApplyModifier extends AbilityActionHandler { return false; } - if (modifierData.stacking != null && modifierData.stacking.compareTo("Unique") == 0 && - ability.getModifiers().values().stream() - .anyMatch(m -> m.getData().equals(modifierData))) { + if (modifierData.stacking != null + && modifierData.stacking.compareTo("Unique") == 0 + && ability.getModifiers().values().stream() + .anyMatch(m -> m.getData().equals(modifierData))) { return true; } @@ -28,15 +29,18 @@ public final class ActionApplyModifier extends AbilityActionHandler { ability.getModifiers().put(action.modifierName, modifier); modifier.onAdded(); - if(modifierData.duration != DynamicFloat.ZERO) { - Grasscutter.getGameServer().getScheduler().scheduleAsyncTask(() -> { - try { - Thread.sleep((int)(modifierData.duration.get() * 1000)); - modifier.onRemoved(); - } catch (InterruptedException ignored) { - Grasscutter.getLogger().error("Failed to schedule ability modifier async task."); - } - }); + if (modifierData.duration != DynamicFloat.ZERO) { + Grasscutter.getGameServer() + .getScheduler() + .scheduleAsyncTask( + () -> { + try { + Thread.sleep((int) (modifierData.duration.get() * 1000)); + modifier.onRemoved(); + } catch (InterruptedException ignored) { + Grasscutter.getLogger().error("Failed to schedule ability modifier async task."); + } + }); } return true; diff --git a/src/main/java/emu/grasscutter/game/ability/actions/ActionExecuteGadgetLua.java b/src/main/java/emu/grasscutter/game/ability/actions/ActionExecuteGadgetLua.java index ab43569bb..c2143e2ca 100644 --- a/src/main/java/emu/grasscutter/game/ability/actions/ActionExecuteGadgetLua.java +++ b/src/main/java/emu/grasscutter/game/ability/actions/ActionExecuteGadgetLua.java @@ -4,7 +4,6 @@ import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.ability.AbilityAction; import emu.grasscutter.game.ability.AbilityActionHandler; -import emu.grasscutter.game.entity.GameEntity; @AbilityAction(AbilityModifierAction.Type.ExecuteGadgetLua) public final class ActionExecuteGadgetLua extends AbilityActionHandler { @@ -12,8 +11,10 @@ public final class ActionExecuteGadgetLua extends AbilityActionHandler { public boolean execute(Ability ability, AbilityModifierAction action) { var owner = ability.getOwner(); - if( owner.getEntityController() != null) { - owner.getEntityController().onClientExecuteRequest(owner, action.param1, action.param2, action.param3); + if (owner.getEntityController() != null) { + owner + .getEntityController() + .onClientExecuteRequest(owner, action.param1, action.param2, action.param3); return true; } diff --git a/src/main/java/emu/grasscutter/game/ability/actions/ActionKillSelf.java b/src/main/java/emu/grasscutter/game/ability/actions/ActionKillSelf.java index 010ef988b..ea9770a74 100644 --- a/src/main/java/emu/grasscutter/game/ability/actions/ActionKillSelf.java +++ b/src/main/java/emu/grasscutter/game/ability/actions/ActionKillSelf.java @@ -4,7 +4,6 @@ import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.ability.AbilityAction; import emu.grasscutter.game.ability.AbilityActionHandler; -import emu.grasscutter.game.entity.GameEntity; @AbilityAction(AbilityModifierAction.Type.KillSelf) public final class ActionKillSelf extends AbilityActionHandler { diff --git a/src/main/java/emu/grasscutter/game/activity/ActivityHandler.java b/src/main/java/emu/grasscutter/game/activity/ActivityHandler.java index 9d15cc7db..276120481 100644 --- a/src/main/java/emu/grasscutter/game/activity/ActivityHandler.java +++ b/src/main/java/emu/grasscutter/game/activity/ActivityHandler.java @@ -71,11 +71,12 @@ public abstract class ActivityHandler { .forEach( condGroupId -> { var condGroup = GameData.getActivityCondGroupMap().get((int) condGroupId); - if (condGroup != null) condGroup - .getCondIds() - .forEach( - condition -> - questManager.queueEvent(QuestCond.QUEST_COND_ACTIVITY_COND, condition)); + if (condGroup != null) + condGroup + .getCondIds() + .forEach( + condition -> + questManager.queueEvent(QuestCond.QUEST_COND_ACTIVITY_COND, condition)); }); } diff --git a/src/main/java/emu/grasscutter/game/entity/EntityGadget.java b/src/main/java/emu/grasscutter/game/entity/EntityGadget.java index 8976509f1..c80bd2bee 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityGadget.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityGadget.java @@ -105,22 +105,24 @@ public class EntityGadget extends EntityBaseGadget { this.addConfigAbilities(); } - private void addConfigAbilities(){ - if(this.configGadget != null && this.configGadget.getAbilities() != null) { + private void addConfigAbilities() { + if (this.configGadget != null && this.configGadget.getAbilities() != null) { for (var ability : this.configGadget.getAbilities()) { this.addConfigAbility(ability); } } } - private void addConfigAbility(ConfigAbilityData abilityData){ + private void addConfigAbility(ConfigAbilityData abilityData) { var data = GameData.getAbilityData(abilityData.getAbilityName()); - if(data != null) - getScene().getWorld().getHost().getAbilityManager().addAbilityToEntity( - this, data, abilityData.getAbilityID()); + if (data != null) + getScene() + .getWorld() + .getHost() + .getAbilityManager() + .addAbilityToEntity(this, data, abilityData.getAbilityID()); } - public void setState(int state) { this.state = state; // Cache the gadget state diff --git a/src/main/java/emu/grasscutter/game/entity/GameEntity.java b/src/main/java/emu/grasscutter/game/entity/GameEntity.java index dd12c37ae..04baa939a 100644 --- a/src/main/java/emu/grasscutter/game/entity/GameEntity.java +++ b/src/main/java/emu/grasscutter/game/entity/GameEntity.java @@ -24,11 +24,10 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2FloatMap; import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap; -import lombok.Getter; -import lombok.Setter; - import java.util.HashMap; import java.util.Map; +import lombok.Getter; +import lombok.Setter; public abstract class GameEntity { @Getter private final Scene scene; diff --git a/src/main/java/emu/grasscutter/game/player/TeamManager.java b/src/main/java/emu/grasscutter/game/player/TeamManager.java index 9ecaed5cd..b17313452 100644 --- a/src/main/java/emu/grasscutter/game/player/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/player/TeamManager.java @@ -487,7 +487,8 @@ public final class TeamManager extends BasePlayerDataManager { return this.getTrialAvatars().values().stream() .filter(avatar -> avatar.getTrialAvatarId() == trialAvatarId) .map(Avatar::getGuid) - .findFirst().orElse(0L); + .findFirst() + .orElse(0L); } /** Rollback changes from using a trial avatar team. */ @@ -1074,7 +1075,8 @@ public final class TeamManager extends BasePlayerDataManager { this.getPlayer() .sendPacket( - new PacketAvatarDelNotify(trialAvatarIds.stream().map(this::getTrialAvatarGuid).toList())); + new PacketAvatarDelNotify( + trialAvatarIds.stream().map(this::getTrialAvatarGuid).toList())); this.removeTrialAvatarTeam(trialAvatarIds); // Update the team. diff --git a/src/main/java/emu/grasscutter/game/quest/GameQuest.java b/src/main/java/emu/grasscutter/game/quest/GameQuest.java index c6696452f..10fc42178 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameQuest.java @@ -292,15 +292,16 @@ public class GameQuest { if (this.state != QuestState.UNFINISHED) return List.of(); return this.getQuestData().getFinishCond().stream() - .filter(cond -> cond.getType() == QuestContent.QUEST_CONTENT_ENTER_DUNGEON) - .map(condition -> { - var params = condition.getParam(); - // The first parameter is the ID of the dungeon. - // The second parameter is the dungeon entry's scene point. - // ex. [1, 1] = dungeon ID 1, scene point 1 or 'KaeyaDungeon'. - return new IntIntImmutablePair(params[0], params[1]); - }) - .toList(); + .filter(cond -> cond.getType() == QuestContent.QUEST_CONTENT_ENTER_DUNGEON) + .map( + condition -> { + var params = condition.getParam(); + // The first parameter is the ID of the dungeon. + // The second parameter is the dungeon entry's scene point. + // ex. [1, 1] = dungeon ID 1, scene point 1 or 'KaeyaDungeon'. + return new IntIntImmutablePair(params[0], params[1]); + }) + .toList(); } public void save() { diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 82e5e918c..05965048a 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -334,9 +334,7 @@ public final class Scene { List> parts = new ArrayList>(); final int N = list.size(); for (int i = 0; i < N; i += L) { - parts.add(new ArrayList( - list.subList(i, Math.min(N, i + L))) - ); + parts.add(new ArrayList(list.subList(i, Math.min(N, i + L)))); } return parts; } @@ -351,7 +349,7 @@ public final class Scene { this.addEntityDirectly(entity); } - for(var l : chopped(new ArrayList<>(entities), 100)) { + for (var l : chopped(new ArrayList<>(entities), 100)) { this.broadcastPacket(new PacketSceneEntityAppearNotify(l, visionType)); } } diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index fb8584deb..821f9e8a0 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -26,6 +26,8 @@ import emu.grasscutter.utils.GridPosition; import emu.grasscutter.utils.JsonUtils; 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 java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; @@ -35,9 +37,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.annotation.Nullable; - -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import kotlin.Pair; import lombok.val; import org.luaj.vm2.LuaError; @@ -64,8 +63,8 @@ public class SceneScriptManager { private ScriptMonsterSpawnService scriptMonsterSpawnService; /** blockid - loaded groupSet */ private final Map> loadedGroupSetPerBlock; - private static final Int2ObjectMap> groupGridsCache - = new Int2ObjectOpenHashMap<>(); + + private static final Int2ObjectMap> groupGridsCache = new Int2ObjectOpenHashMap<>(); public static final ExecutorService eventExecutor; static { @@ -118,8 +117,7 @@ public class SceneScriptManager { } @Nullable public Map getVariables(int group_id) { - if (this.getCachedGroupInstanceById(group_id) == null) - return Collections.emptyMap(); + if (this.getCachedGroupInstanceById(group_id) == null) return Collections.emptyMap(); return getCachedGroupInstanceById(group_id).getCachedVariables(); } @@ -200,11 +198,16 @@ public class SceneScriptManager { // } } - public int refreshGroup(SceneGroupInstance groupInstance, int suiteIndex, boolean excludePrevSuite) { + public int refreshGroup( + SceneGroupInstance groupInstance, int suiteIndex, boolean excludePrevSuite) { return this.refreshGroup(groupInstance, suiteIndex, excludePrevSuite, null); } - public int refreshGroup(SceneGroupInstance groupInstance, int suiteIndex, boolean excludePrevSuite, List entitiesAdded) { + public int refreshGroup( + SceneGroupInstance groupInstance, + int suiteIndex, + boolean excludePrevSuite, + List entitiesAdded) { SceneGroup group = groupInstance.getLuaGroup(); if (suiteIndex == 0) { if (excludePrevSuite) { @@ -434,7 +437,7 @@ public class SceneScriptManager { public List getGroupGrids() { int sceneId = scene.getId(); if (groupGridsCache.containsKey(sceneId) && groupGridsCache.get(sceneId) != null) { - Grasscutter.getLogger().debug("Hit cache for scene {}",sceneId); + Grasscutter.getLogger().debug("Hit cache for scene {}", sceneId); return groupGridsCache.get(sceneId); } else { var path = FileUtils.getCachePath("scene" + sceneId + "_grid.json"); @@ -442,70 +445,124 @@ public class SceneScriptManager { try { var groupGrids = JsonUtils.loadToList(path, Grid.class); groupGridsCache.put(sceneId, groupGrids); - if(groupGrids != null) return groupGrids; + if (groupGrids != null) return groupGrids; } catch (IOException e) { e.printStackTrace(); } } - //otherwise generate the grids + // otherwise generate the grids List>> groupPositions = new ArrayList<>(); for (int i = 0; i < 6; i++) groupPositions.add(new HashMap<>()); var visionOptions = Grasscutter.config.server.game.visionOptions; - meta.blocks.values().forEach(block -> { - block.load(sceneId, meta.context); - block.groups.values().stream().filter(g -> !g.dynamic_load).forEach(group -> { - group.load(this.scene.getId()); + meta.blocks + .values() + .forEach( + block -> { + block.load(sceneId, meta.context); + block.groups.values().stream() + .filter(g -> !g.dynamic_load) + .forEach( + group -> { + group.load(this.scene.getId()); - //Add all entities here - Set vision_levels = new HashSet<>(); + // Add all entities here + Set vision_levels = new HashSet<>(); - if (group.monsters != null) { - group.monsters.values().forEach(m -> { - addGridPositionToMap(groupPositions.get(m.vision_level), group.id, m.vision_level, m.pos); - vision_levels.add(m.vision_level); - }); - } else { - Grasscutter.getLogger().error("group.monsters null for group {}", group.id); - } - if (group.gadgets != null) { - group.gadgets.values().forEach(g -> { - int vision_level = Math.max(getGadgetVisionLevel(g.gadget_id), g.vision_level); - addGridPositionToMap(groupPositions.get(vision_level), group.id, vision_level, g.pos); - vision_levels.add(vision_level); - }); - } else { - Grasscutter.getLogger().error("group.gadgets null for group {}", group.id); - } + if (group.monsters != null) { + group + .monsters + .values() + .forEach( + m -> { + addGridPositionToMap( + groupPositions.get(m.vision_level), + group.id, + m.vision_level, + m.pos); + vision_levels.add(m.vision_level); + }); + } else { + Grasscutter.getLogger() + .error("group.monsters null for group {}", group.id); + } + if (group.gadgets != null) { + group + .gadgets + .values() + .forEach( + g -> { + int vision_level = + Math.max( + getGadgetVisionLevel(g.gadget_id), g.vision_level); + addGridPositionToMap( + groupPositions.get(vision_level), + group.id, + vision_level, + g.pos); + vision_levels.add(vision_level); + }); + } else { + Grasscutter.getLogger() + .error("group.gadgets null for group {}", group.id); + } - if (group.npcs != null) { - group.npcs.values().forEach(n -> addGridPositionToMap(groupPositions.get(n.vision_level), group.id, n.vision_level, n.pos)); - } else { - Grasscutter.getLogger().error("group.npcs null for group {}", group.id); - } + if (group.npcs != null) { + group + .npcs + .values() + .forEach( + n -> + addGridPositionToMap( + groupPositions.get(n.vision_level), + group.id, + n.vision_level, + n.pos)); + } else { + Grasscutter.getLogger().error("group.npcs null for group {}", group.id); + } - if (group.regions != null) { - group.regions.values().forEach(r -> addGridPositionToMap(groupPositions.get(0), group.id, 0, r.pos)); - } else { - Grasscutter.getLogger().error("group.regions null for group {}", group.id); - } + if (group.regions != null) { + group + .regions + .values() + .forEach( + r -> + addGridPositionToMap( + groupPositions.get(0), group.id, 0, r.pos)); + } else { + Grasscutter.getLogger() + .error("group.regions null for group {}", group.id); + } - if (group.garbages != null && group.garbages.gadgets != null) - group.garbages.gadgets.forEach(g -> addGridPositionToMap(groupPositions.get(g.vision_level), group.id, g.vision_level, g.pos)); + if (group.garbages != null && group.garbages.gadgets != null) + group.garbages.gadgets.forEach( + g -> + addGridPositionToMap( + groupPositions.get(g.vision_level), + group.id, + g.vision_level, + g.pos)); - int max_vision_level = -1; - if (!vision_levels.isEmpty()) { - for (int vision_level : vision_levels) { - if (max_vision_level == -1 || visionOptions[max_vision_level].visionRange < visionOptions[vision_level].visionRange) - max_vision_level = vision_level; - } - } - if (max_vision_level == -1) max_vision_level = 0; + int max_vision_level = -1; + if (!vision_levels.isEmpty()) { + for (int vision_level : vision_levels) { + if (max_vision_level == -1 + || visionOptions[max_vision_level].visionRange + < visionOptions[vision_level].visionRange) + max_vision_level = vision_level; + } + } + if (max_vision_level == -1) max_vision_level = 0; - addGridPositionToMap(groupPositions.get(max_vision_level), group.id, max_vision_level, group.pos); - }); - }); + addGridPositionToMap( + groupPositions.get(max_vision_level), + group.id, + max_vision_level, + group.pos); + }); + }); var groupGrids = new ArrayList(); for (int i = 0; i < 6; i++) { @@ -516,7 +573,8 @@ public class SceneScriptManager { try { Files.createDirectories(path.getParent()); - } catch (IOException ignored) {} + } catch (IOException ignored) { + } try (var file = new FileWriter(path.toFile())) { file.write(JsonUtils.encode(groupGrids)); Grasscutter.getLogger().info("Scene {} saved grid file.", getScene().getId()); @@ -658,7 +716,8 @@ public class SceneScriptManager { this.addGroupSuite(groupInstance, suite, null); } - public void addGroupSuite(SceneGroupInstance groupInstance, SceneSuite suite, List entities) { + public void addGroupSuite( + SceneGroupInstance groupInstance, SceneSuite suite, List entities) { // we added trigger first registerTrigger(suite.sceneTriggers); @@ -666,8 +725,7 @@ public class SceneScriptManager { var toCreate = new ArrayList(); toCreate.addAll(getGadgetsInGroupSuite(groupInstance, suite)); toCreate.addAll(getMonstersInGroupSuite(groupInstance, suite)); - if (entities != null) - entities.addAll(toCreate); + if (entities != null) entities.addAll(toCreate); else this.addEntities(toCreate); registerRegionInGroupSuite(group, suite); diff --git a/src/main/java/emu/grasscutter/utils/GridPosition.java b/src/main/java/emu/grasscutter/utils/GridPosition.java index 654195afa..59882d130 100644 --- a/src/main/java/emu/grasscutter/utils/GridPosition.java +++ b/src/main/java/emu/grasscutter/utils/GridPosition.java @@ -7,7 +7,6 @@ import java.io.Serializable; import java.util.List; import lombok.Getter; import lombok.Setter; -import lombok.SneakyThrows; @Entity public final class GridPosition implements Serializable { @@ -92,7 +91,7 @@ public final class GridPosition implements Serializable { } public double[] toDoubleArray() { - return new double[]{ x, z }; + return new double[] {x, z}; } public int[] toXZIntArray() { @@ -100,7 +99,7 @@ public final class GridPosition implements Serializable { } public Point toPoint() { - return Point.create(x,z); + return Point.create(x, z); } @Override