From 583a41ab2c4c48e332c018d3518e66e6229f67a6 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 01:54:08 +0000 Subject: [PATCH] Format code [skip actions] --- .../game/entity/EntityMonster.java | 236 +++++++++++------- .../scripts/SceneScriptManager.java | 17 +- .../grasscutter/scripts/data/SceneGroup.java | 4 +- .../event/game/SceneBlockLoadedEvent.java | 2 +- 4 files changed, 165 insertions(+), 94 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java index e25f847af..0ff36a614 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java @@ -1,5 +1,7 @@ package emu.grasscutter.game.entity; +import static emu.grasscutter.scripts.constants.EventType.EVENT_SPECIFIC_MONSTER_HP_CHANGE; + import emu.grasscutter.data.GameData; import emu.grasscutter.data.binout.config.ConfigEntityMonster; import emu.grasscutter.data.common.PropGrowCurve; @@ -28,12 +30,9 @@ import emu.grasscutter.scripts.data.*; import emu.grasscutter.server.event.entity.EntityDamageEvent; import emu.grasscutter.utils.helpers.ProtoHelper; import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap; -import lombok.*; - -import javax.annotation.Nullable; import java.util.*; - -import static emu.grasscutter.scripts.constants.EventType.EVENT_SPECIFIC_MONSTER_HP_CHANGE; +import javax.annotation.Nullable; +import lombok.*; public class EntityMonster extends GameEntity { @Getter(onMethod_ = @Override) @@ -41,8 +40,10 @@ public class EntityMonster extends GameEntity { @Getter(onMethod_ = @Override) private final Position position; + @Getter(onMethod_ = @Override) private final Position rotation; + @Getter private final MonsterData monsterData; @Getter private final ConfigEntityMonster configEntityMonster; @Getter private final Position bornPos; @@ -54,7 +55,8 @@ public class EntityMonster extends GameEntity { @Getter private List playerOnBattle; @Nullable @Getter @Setter private SceneMonster metaMonster; - public EntityMonster(Scene scene, MonsterData monsterData, Position pos, Position rot, int level) { + public EntityMonster( + Scene scene, MonsterData monsterData, Position pos, Position rot, int level) { super(scene); this.id = this.getWorld().getNextEntityId(EntityIdType.MONSTER); @@ -67,8 +69,9 @@ public class EntityMonster extends GameEntity { this.playerOnBattle = new ArrayList<>(); if (GameData.getMonsterMappingMap().containsKey(this.getMonsterId())) { - this.configEntityMonster = GameData.getMonsterConfigData().get( - GameData.getMonsterMappingMap().get(this.getMonsterId()).getMonsterJson()); + this.configEntityMonster = + GameData.getMonsterConfigData() + .get(GameData.getMonsterMappingMap().get(this.getMonsterId()).getMonsterJson()); } else { this.configEntityMonster = null; } @@ -77,7 +80,7 @@ public class EntityMonster extends GameEntity { if (getMonsterWeaponId() > 0) { this.weaponEntity = new EntityWeapon(scene, getMonsterWeaponId()); scene.getWeaponEntities().put(this.weaponEntity.getId(), this.weaponEntity); - //this.weaponEntityId = getWorld().getNextEntityId(EntityIdType.WEAPON); + // this.weaponEntityId = getWorld().getNextEntityId(EntityIdType.WEAPON); } this.recalcStats(); @@ -87,18 +90,15 @@ public class EntityMonster extends GameEntity { private void addConfigAbility(String name) { var data = GameData.getAbilityData(name); if (data != null) { - this.getWorld().getHost() - .getAbilityManager() - .addAbilityToEntity(this, data); + this.getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data); } } @Override public void initAbilities() { // Affix abilities - var optionalGroup = this.getScene().getLoadedGroups().stream() - .filter(g -> g.id == this.getGroupId()) - .findAny(); + var optionalGroup = + this.getScene().getLoadedGroups().stream().filter(g -> g.id == this.getGroupId()).findAny(); List affixes = null; if (optionalGroup.isPresent()) { var group = optionalGroup.get(); @@ -118,7 +118,7 @@ public class EntityMonster extends GameEntity { var affix = GameData.getMonsterAffixDataMap().get(affixId.intValue()); if (!affix.isPreAdd()) continue; - //Add the ability + // Add the ability for (var name : affix.getAbilityName()) { this.addConfigAbility(name); } @@ -126,14 +126,12 @@ public class EntityMonster extends GameEntity { } // TODO: Research if any monster is non humanoid - for(var ability : GameData.getConfigGlobalCombat() - .getDefaultAbilities() - .getNonHumanoidMoveAbilities()) { + for (var ability : + GameData.getConfigGlobalCombat().getDefaultAbilities().getNonHumanoidMoveAbilities()) { this.addConfigAbility(ability); } - if (this.configEntityMonster != null && - this.configEntityMonster.getAbilities() != null) { + if (this.configEntityMonster != null && this.configEntityMonster.getAbilities() != null) { for (var configAbilityData : this.configEntityMonster.getAbilities()) { this.addConfigAbility(configAbilityData.abilityName); } @@ -143,9 +141,8 @@ public class EntityMonster extends GameEntity { var group = optionalGroup.get(); var monster = group.monsters.get(getConfigId()); if (monster != null && monster.isElite) { - this.addConfigAbility(GameData.getConfigGlobalCombat() - .getDefaultAbilities() - .getMonterEliteAbilityName()); + this.addConfigAbility( + GameData.getConfigGlobalCombat().getDefaultAbilities().getMonterEliteAbilityName()); } } @@ -154,8 +151,8 @@ public class EntityMonster extends GameEntity { var affix = GameData.getMonsterAffixDataMap().get(affixId.intValue()); if (affix.isPreAdd()) continue; - //Add the ability - for(var name : affix.getAbilityName()) { + // Add the ability + for (var name : affix.getAbilityName()) { this.addConfigAbility(name); } } @@ -163,7 +160,7 @@ public class EntityMonster extends GameEntity { var levelEntityConfig = getScene().getSceneData().getLevelEntityConfig(); var config = GameData.getConfigLevelEntityDataMap().get(levelEntityConfig); - if (config == null){ + if (config == null) { return; } @@ -194,7 +191,8 @@ public class EntityMonster extends GameEntity { @Override public void onInteract(Player player, GadgetInteractReq interactReq) { - EnvAnimalGatherConfigData gatherData = GameData.getEnvAnimalGatherConfigDataMap().get(this.getMonsterData().getId()); + EnvAnimalGatherConfigData gatherData = + GameData.getEnvAnimalGatherConfigDataMap().get(this.getMonsterData().getId()); if (gatherData == null) { return; @@ -208,7 +206,11 @@ public class EntityMonster extends GameEntity { @Override public void onCreate() { // Lua event - getScene().getScriptManager().callEvent(new ScriptArgs(this.getGroupId(), EventType.EVENT_ANY_MONSTER_LIVE, this.getConfigId())); + getScene() + .getScriptManager() + .callEvent( + new ScriptArgs( + this.getGroupId(), EventType.EVENT_ANY_MONSTER_LIVE, this.getConfigId())); } @Override @@ -231,10 +233,17 @@ public class EntityMonster extends GameEntity { @Override public void runLuaCallbacks(EntityDamageEvent event) { super.runLuaCallbacks(event); - getScene().getScriptManager().callEvent(new ScriptArgs(this.getGroupId(), EVENT_SPECIFIC_MONSTER_HP_CHANGE, getConfigId(), monsterData.getId()) - .setSourceEntityId(getId()) - .setParam3((int) this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP)) - .setEventSource(getConfigId())); + getScene() + .getScriptManager() + .callEvent( + new ScriptArgs( + this.getGroupId(), + EVENT_SPECIFIC_MONSTER_HP_CHANGE, + getConfigId(), + monsterData.getId()) + .setSourceEntityId(getId()) + .setParam3((int) this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP)) + .setEventSource(getConfigId())); } @Override @@ -250,13 +259,17 @@ public class EntityMonster extends GameEntity { challenge.ifPresent(c -> c.onMonsterDeath(this)); if (scriptManager.isInit() && this.getGroupId() > 0) { - Optional.ofNullable(scriptManager.getScriptMonsterSpawnService()).ifPresent(s -> s.onMonsterDead(this)); + Optional.ofNullable(scriptManager.getScriptMonsterSpawnService()) + .ifPresent(s -> s.onMonsterDead(this)); // Ensure each EVENT_ANY_MONSTER_DIE runs to completion. // Multiple such events firing at the same time may cause // the same lua trigger to fire multiple times, when it // should happen only once. - var future = scriptManager.callEvent(new ScriptArgs(this.getGroupId(), EventType.EVENT_ANY_MONSTER_DIE, this.getConfigId())); + var future = + scriptManager.callEvent( + new ScriptArgs( + this.getGroupId(), EventType.EVENT_ANY_MONSTER_DIE, this.getConfigId())); try { future.get(); } catch (Exception e) { @@ -264,19 +277,45 @@ public class EntityMonster extends GameEntity { } } // Battle Pass trigger - scene.getPlayers().forEach(p -> p.getBattlePassManager().triggerMission(WatcherTriggerType.TRIGGER_MONSTER_DIE, this.getMonsterId(), 1)); + scene + .getPlayers() + .forEach( + p -> + p.getBattlePassManager() + .triggerMission( + WatcherTriggerType.TRIGGER_MONSTER_DIE, this.getMonsterId(), 1)); - scene.getPlayers().forEach(p -> p.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_MONSTER_DIE, this.getMonsterId())); - scene.getPlayers().forEach(p -> p.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_KILL_MONSTER, this.getMonsterId())); - scene.getPlayers().forEach(p -> p.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_CLEAR_GROUP_MONSTER, this.getGroupId())); + scene + .getPlayers() + .forEach( + p -> + p.getQuestManager() + .queueEvent(QuestContent.QUEST_CONTENT_MONSTER_DIE, this.getMonsterId())); + scene + .getPlayers() + .forEach( + p -> + p.getQuestManager() + .queueEvent(QuestContent.QUEST_CONTENT_KILL_MONSTER, this.getMonsterId())); + scene + .getPlayers() + .forEach( + p -> + p.getQuestManager() + .queueEvent(QuestContent.QUEST_CONTENT_CLEAR_GROUP_MONSTER, this.getGroupId())); - SceneGroupInstance groupInstance = scene.getScriptManager().getGroupInstanceById(this.getGroupId()); - if(groupInstance != null && metaMonster != null) + SceneGroupInstance groupInstance = + scene.getScriptManager().getGroupInstanceById(this.getGroupId()); + if (groupInstance != null && metaMonster != null) groupInstance.getDeadEntities().add(metaMonster.config_id); - scene.triggerDungeonEvent(DungeonPassConditionType.DUNGEON_COND_KILL_GROUP_MONSTER, this.getGroupId()); - scene.triggerDungeonEvent(DungeonPassConditionType.DUNGEON_COND_KILL_TYPE_MONSTER, this.getMonsterData().getType().getValue()); - scene.triggerDungeonEvent(DungeonPassConditionType.DUNGEON_COND_KILL_MONSTER, this.getMonsterId()); + scene.triggerDungeonEvent( + DungeonPassConditionType.DUNGEON_COND_KILL_GROUP_MONSTER, this.getGroupId()); + scene.triggerDungeonEvent( + DungeonPassConditionType.DUNGEON_COND_KILL_TYPE_MONSTER, + this.getMonsterData().getType().getValue()); + scene.triggerDungeonEvent( + DungeonPassConditionType.DUNGEON_COND_KILL_MONSTER, this.getMonsterId()); } public void recalcStats() { @@ -284,86 +323,107 @@ public class EntityMonster extends GameEntity { MonsterData data = this.getMonsterData(); // Get hp percent, set to 100% if none - float hpPercent = this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) <= 0 ? 1f : this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) / this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); + float hpPercent = + this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) <= 0 + ? 1f + : this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) + / this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); // Clear properties this.getFightProperties().clear(); // Base stats - MonsterData.definedFightProperties.forEach(prop -> this.setFightProperty(prop, data.getFightProperty(prop))); + MonsterData.definedFightProperties.forEach( + prop -> this.setFightProperty(prop, data.getFightProperty(prop))); // Level curve MonsterCurveData curve = GameData.getMonsterCurveDataMap().get(this.getLevel()); if (curve != null) { for (PropGrowCurve growCurve : data.getPropGrowCurves()) { FightProperty prop = FightProperty.getPropByName(growCurve.getType()); - this.setFightProperty(prop, this.getFightProperty(prop) * curve.getMultByProp(growCurve.getGrowCurve())); + this.setFightProperty( + prop, this.getFightProperty(prop) * curve.getMultByProp(growCurve.getGrowCurve())); } } // Set % stats - FightProperty.forEachCompoundProperty(c -> this.setFightProperty(c.getResult(), - this.getFightProperty(c.getFlat()) + (this.getFightProperty(c.getBase()) * (1f + this.getFightProperty(c.getPercent()))))); + FightProperty.forEachCompoundProperty( + c -> + this.setFightProperty( + c.getResult(), + this.getFightProperty(c.getFlat()) + + (this.getFightProperty(c.getBase()) + * (1f + this.getFightProperty(c.getPercent()))))); // Set current hp - this.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) * hpPercent); + this.setFightProperty( + FightProperty.FIGHT_PROP_CUR_HP, + this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) * hpPercent); } @Override public SceneEntityInfo toProto() { var data = this.getMonsterData(); - var authority = EntityAuthorityInfo.newBuilder() - .setAbilityInfo(AbilitySyncStateInfo.newBuilder()) - .setRendererChangedInfo(EntityRendererChangedInfo.newBuilder()) - .setAiInfo(SceneEntityAiInfo.newBuilder() - .setIsAiOpen(true) - .setBornPos(this.getBornPos().toProto())) - .setBornPos(this.getBornPos().toProto()) - .build(); + var authority = + EntityAuthorityInfo.newBuilder() + .setAbilityInfo(AbilitySyncStateInfo.newBuilder()) + .setRendererChangedInfo(EntityRendererChangedInfo.newBuilder()) + .setAiInfo( + SceneEntityAiInfo.newBuilder() + .setIsAiOpen(true) + .setBornPos(this.getBornPos().toProto())) + .setBornPos(this.getBornPos().toProto()) + .build(); - var entityInfo = SceneEntityInfo.newBuilder() - .setEntityId(this.getId()) - .setEntityType(ProtEntityType.PROT_ENTITY_TYPE_MONSTER) - .setMotionInfo(this.getMotionInfo()) - .addAnimatorParaList(AnimatorParameterValueInfoPair.newBuilder()) - .setEntityClientData(EntityClientData.newBuilder()) - .setEntityAuthorityInfo(authority) - .setLifeState(this.getLifeState().getValue()); + var entityInfo = + SceneEntityInfo.newBuilder() + .setEntityId(this.getId()) + .setEntityType(ProtEntityType.PROT_ENTITY_TYPE_MONSTER) + .setMotionInfo(this.getMotionInfo()) + .addAnimatorParaList(AnimatorParameterValueInfoPair.newBuilder()) + .setEntityClientData(EntityClientData.newBuilder()) + .setEntityAuthorityInfo(authority) + .setLifeState(this.getLifeState().getValue()); this.addAllFightPropsToEntityInfo(entityInfo); - entityInfo.addPropList(PropPair.newBuilder() - .setType(PlayerProperty.PROP_LEVEL.getId()) - .setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, this.getLevel())) - .build()); + entityInfo.addPropList( + PropPair.newBuilder() + .setType(PlayerProperty.PROP_LEVEL.getId()) + .setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, this.getLevel())) + .build()); - var monsterInfo = SceneMonsterInfo.newBuilder() - .setMonsterId(getMonsterId()) - .setGroupId(this.getGroupId()) - .setConfigId(this.getConfigId()) - .addAllAffixList(data.getAffix()) - .setAuthorityPeerId(this.getWorld().getHostPeerId()) - .setPoseId(this.getPoseId()) - .setBlockId(this.getScene().getId()) - .setBornType(MonsterBornType.MONSTER_BORN_TYPE_DEFAULT); + var monsterInfo = + SceneMonsterInfo.newBuilder() + .setMonsterId(getMonsterId()) + .setGroupId(this.getGroupId()) + .setConfigId(this.getConfigId()) + .addAllAffixList(data.getAffix()) + .setAuthorityPeerId(this.getWorld().getHostPeerId()) + .setPoseId(this.getPoseId()) + .setBlockId(this.getScene().getId()) + .setBornType(MonsterBornType.MONSTER_BORN_TYPE_DEFAULT); if (this.metaMonster != null) { if (this.metaMonster.special_name_id != 0) { - monsterInfo.setTitleId(this.metaMonster.title_id) - .setSpecialNameId(this.metaMonster.special_name_id); + monsterInfo + .setTitleId(this.metaMonster.title_id) + .setSpecialNameId(this.metaMonster.special_name_id); } else if (data.getDescribeData() != null) { - monsterInfo.setTitleId(data.getDescribeData().getTitleId()) - .setSpecialNameId(data.getSpecialNameId()); + monsterInfo + .setTitleId(data.getDescribeData().getTitleId()) + .setSpecialNameId(data.getSpecialNameId()); } } if (this.getMonsterWeaponId() > 0) { - SceneWeaponInfo weaponInfo = SceneWeaponInfo.newBuilder() - .setEntityId(this.getWeaponEntity() != null ? this.getWeaponEntity().getId() : 0) - .setGadgetId(this.getMonsterWeaponId()) - .setAbilityInfo(AbilitySyncStateInfo.newBuilder()) - .build(); + SceneWeaponInfo weaponInfo = + SceneWeaponInfo.newBuilder() + .setEntityId(this.getWeaponEntity() != null ? this.getWeaponEntity().getId() : 0) + .setGadgetId(this.getMonsterWeaponId()) + .setAbilityInfo(AbilitySyncStateInfo.newBuilder()) + .build(); monsterInfo.addWeaponList(weaponInfo); } diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index be6e2b63b..79cf61239 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -136,7 +136,9 @@ public class SceneScriptManager { public void registerTrigger(SceneTrigger trigger) { this.triggerInvocations.put(trigger.getName(), new AtomicInteger(0)); this.getTriggersByEvent(trigger.getEvent()).add(trigger); - Grasscutter.getLogger().trace("Registered trigger {} from group {}", trigger.getName(), trigger.getCurrentGroup().id); + Grasscutter.getLogger() + .trace( + "Registered trigger {} from group {}", trigger.getName(), trigger.getCurrentGroup().id); } public void deregisterTrigger(List triggers) { @@ -145,7 +147,11 @@ public class SceneScriptManager { public void deregisterTrigger(SceneTrigger trigger) { this.getTriggersByEvent(trigger.getEvent()).remove(trigger); - Grasscutter.getLogger().trace("deregistered trigger {} from group {}", trigger.getName(), trigger.getCurrentGroup().id); + Grasscutter.getLogger() + .trace( + "deregistered trigger {} from group {}", + trigger.getName(), + trigger.getCurrentGroup().id); } public void resetTriggers(int eventId) { @@ -468,7 +474,9 @@ public class SceneScriptManager { return groupGridsCache.get(sceneId); } else { var path = FileUtils.getCachePath("scene" + sceneId + "_grid.json"); - if (path.toFile().isFile() && !Grasscutter.config.server.game.cacheSceneEntitiesEveryRun && !noCacheGroupGridsToDisk) { + if (path.toFile().isFile() + && !Grasscutter.config.server.game.cacheSceneEntitiesEveryRun + && !noCacheGroupGridsToDisk) { try { var groupGrids = JsonUtils.loadToList(path, Grid.class); groupGridsCache.put(sceneId, groupGrids); @@ -607,7 +615,8 @@ public class SceneScriptManager { file.write(JsonUtils.encode(groupGrids)); Grasscutter.getLogger().info("Scene {} saved grid file.", getScene().getId()); } catch (Exception e) { - Grasscutter.getLogger().error("Scene {} unable to save grid file.", getScene().getId(), e); + Grasscutter.getLogger() + .error("Scene {} unable to save grid file.", getScene().getId(), e); } } return groupGrids; diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java b/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java index 433591da2..ce84e6fa3 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java @@ -92,7 +92,9 @@ public final class SceneGroup { if (overrideScriptPath != null && !overrideScriptPath.equals("")) { cs = ScriptLoader.getScript(overrideScriptPath, true); } else { - cs = ScriptLoader.getScript("Scene/%s/scene%s_group%s.lua".formatted(sceneId, sceneId, this.id)); + cs = + ScriptLoader.getScript( + "Scene/%s/scene%s_group%s.lua".formatted(sceneId, sceneId, this.id)); } if (cs == null) { diff --git a/src/main/java/emu/grasscutter/server/event/game/SceneBlockLoadedEvent.java b/src/main/java/emu/grasscutter/server/event/game/SceneBlockLoadedEvent.java index 15b9f23a2..1155b018b 100644 --- a/src/main/java/emu/grasscutter/server/event/game/SceneBlockLoadedEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/SceneBlockLoadedEvent.java @@ -1,7 +1,7 @@ package emu.grasscutter.server.event.game; -import emu.grasscutter.server.event.types.ServerEvent; import emu.grasscutter.scripts.data.SceneBlock; +import emu.grasscutter.server.event.types.ServerEvent; import lombok.*; @Getter