Format code [skip actions]

This commit is contained in:
github-actions 2023-05-30 06:43:54 +00:00
parent f00c54cb95
commit a3c56dff7e
53 changed files with 691 additions and 531 deletions

View File

@ -47,14 +47,13 @@ import emu.grasscutter.game.quest.enums.QuestCond;
import emu.grasscutter.game.world.GroupReplacementData; import emu.grasscutter.game.world.GroupReplacementData;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import java.lang.reflect.Field;
import java.util.*;
import javax.annotation.Nullable;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.val; import lombok.val;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.*;
@SuppressWarnings({"unused", "MismatchedQueryAndUpdateOfCollection"}) @SuppressWarnings({"unused", "MismatchedQueryAndUpdateOfCollection"})
public final class GameData { public final class GameData {
@Getter private static final Map<String, AbilityData> abilityDataMap = new HashMap<>(); @Getter private static final Map<String, AbilityData> abilityDataMap = new HashMap<>();
@ -243,7 +242,9 @@ public final class GameData {
private static final Int2ObjectMap<EquipAffixData> equipAffixDataMap = private static final Int2ObjectMap<EquipAffixData> equipAffixDataMap =
new Int2ObjectOpenHashMap<>(); new Int2ObjectOpenHashMap<>();
@Getter private static final Int2ObjectMap<MonsterAffixData> monsterAffixDataMap = new Int2ObjectOpenHashMap<>(); @Getter
private static final Int2ObjectMap<MonsterAffixData> monsterAffixDataMap =
new Int2ObjectOpenHashMap<>();
@Getter @Getter
private static final Int2ObjectMap<FetterCharacterCardData> fetterCharacterCardDataMap = private static final Int2ObjectMap<FetterCharacterCardData> fetterCharacterCardDataMap =
@ -439,8 +440,7 @@ public final class GameData {
private static final Int2ObjectMap<CodexWeaponData> codexWeaponDataMap = private static final Int2ObjectMap<CodexWeaponData> codexWeaponDataMap =
new Int2ObjectOpenHashMap<>(); new Int2ObjectOpenHashMap<>();
@Getter @Setter @Getter @Setter private static ConfigGlobalCombat configGlobalCombat = null;
private static ConfigGlobalCombat configGlobalCombat = null;
// Custom community server resources // Custom community server resources
@Getter @Getter
@ -451,7 +451,8 @@ public final class GameData {
private static final Int2ObjectMap<GadgetMapping> gadgetMappingMap = private static final Int2ObjectMap<GadgetMapping> gadgetMappingMap =
new Int2ObjectOpenHashMap<>(); new Int2ObjectOpenHashMap<>();
@Getter private static final Int2ObjectMap<MonsterMapping> monsterMappingMap = @Getter
private static final Int2ObjectMap<MonsterMapping> monsterMappingMap =
new Int2ObjectOpenHashMap<>(); new Int2ObjectOpenHashMap<>();
@Getter @Getter

View File

@ -1,5 +1,9 @@
package emu.grasscutter.data; package emu.grasscutter.data;
import static emu.grasscutter.utils.FileUtils.getDataPath;
import static emu.grasscutter.utils.FileUtils.getResourcePath;
import static emu.grasscutter.utils.lang.Language.translate;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
@ -32,12 +36,6 @@ import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntArraySet; import it.unimi.dsi.fastutil.ints.IntArraySet;
import lombok.SneakyThrows;
import lombok.val;
import org.reflections.Reflections;
import javax.script.Bindings;
import javax.script.CompiledScript;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.file.Files; import java.nio.file.Files;
@ -49,10 +47,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.script.Bindings;
import static emu.grasscutter.utils.FileUtils.getDataPath; import javax.script.CompiledScript;
import static emu.grasscutter.utils.FileUtils.getResourcePath; import lombok.SneakyThrows;
import static emu.grasscutter.utils.lang.Language.translate; import lombok.val;
import org.reflections.Reflections;
public final class ResourceLoader { public final class ResourceLoader {
@ -232,9 +231,13 @@ public final class ResourceLoader {
private static void loadGlobalCombatConfig() { private static void loadGlobalCombatConfig() {
try { try {
GameData.setConfigGlobalCombat(JsonUtils.loadToClass(getResourcePath("BinOutput/Common/ConfigGlobalCombat.json"), ConfigGlobalCombat.class)); GameData.setConfigGlobalCombat(
JsonUtils.loadToClass(
getResourcePath("BinOutput/Common/ConfigGlobalCombat.json"),
ConfigGlobalCombat.class));
} catch (IOException e) { } catch (IOException e) {
Grasscutter.getLogger().error("Cannot load ConfigGlobalCombat.json, this error is important, fix it!"); Grasscutter.getLogger()
.error("Cannot load ConfigGlobalCombat.json, this error is important, fix it!");
} }
} }
@ -429,9 +432,15 @@ public final class ResourceLoader {
private static void loadTalents() { private static void loadTalents() {
// Load from BinOutput // Load from BinOutput
try (var paths = Files.walk(getResourcePath("BinOutput/Talent/AvatarTalents/"))) { try (var paths = Files.walk(getResourcePath("BinOutput/Talent/AvatarTalents/"))) {
paths.filter(Files::isDirectory).forEach((folderPath) -> { paths
.filter(Files::isDirectory)
.forEach(
(folderPath) -> {
try (var paths2 = Files.walk(folderPath)) { try (var paths2 = Files.walk(folderPath)) {
paths2.filter(Files::isRegularFile).filter(path -> path.toString().endsWith(".json")).forEach(ResourceLoader::loadTalent); paths2
.filter(Files::isRegularFile)
.filter(path -> path.toString().endsWith(".json"))
.forEach(ResourceLoader::loadTalent);
} catch (IOException e) { } catch (IOException e) {
Grasscutter.getLogger().error("Error loading talents: ", e); Grasscutter.getLogger().error("Error loading talents: ", e);
} }
@ -443,9 +452,13 @@ public final class ResourceLoader {
private static void loadTalent(Path path) { private static void loadTalent(Path path) {
try { try {
GameData.getTalents().putAll(JsonUtils.loadToMap(path, String.class, new TypeToken<List<TalentData>>() {}.getType())); GameData.getTalents()
.putAll(
JsonUtils.loadToMap(
path, String.class, new TypeToken<List<TalentData>>() {}.getType()));
} catch (IOException e) { } catch (IOException e) {
Grasscutter.getLogger().error("Error loading ability modifiers from path " + path.toString() + ": ", e); Grasscutter.getLogger()
.error("Error loading ability modifiers from path " + path.toString() + ": ", e);
} }
} }
@ -816,7 +829,8 @@ public final class ResourceLoader {
try { try {
JsonUtils.loadToList(getResourcePath("Server/MonsterMapping.json"), MonsterMapping.class) JsonUtils.loadToList(getResourcePath("Server/MonsterMapping.json"), MonsterMapping.class)
.forEach(entry -> monsterMap.put(entry.getMonsterId(), entry)); .forEach(entry -> monsterMap.put(entry.getMonsterId(), entry));
} catch (IOException | NullPointerException ignored) {} } catch (IOException | NullPointerException ignored) {
}
Grasscutter.getLogger().debug("Loaded {} monster mappings.", monsterMap.size()); Grasscutter.getLogger().debug("Loaded {} monster mappings.", monsterMap.size());
} catch (Exception e) { } catch (Exception e) {
@ -965,7 +979,8 @@ public final class ResourceLoader {
public int pointDelta; public int pointDelta;
} }
public static class ScenePointConfig { // Sadly this doesn't work as a local class in loadScenePoints() public static
class ScenePointConfig { // Sadly this doesn't work as a local class in loadScenePoints()
public Map<Integer, PointData> points; public Map<Integer, PointData> points;
} }
} }

View File

@ -3,7 +3,6 @@ package emu.grasscutter.data.binout;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.AbilityLocalIdGenerator; import emu.grasscutter.game.ability.AbilityLocalIdGenerator;
import emu.grasscutter.game.ability.AbilityLocalIdGenerator.ConfigAbilitySubContainerType; import emu.grasscutter.game.ability.AbilityLocalIdGenerator.ConfigAbilitySubContainerType;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -45,7 +44,8 @@ public class AbilityData {
} }
private void initializeActions() { private void initializeActions() {
AbilityLocalIdGenerator generator = new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.ACTION); AbilityLocalIdGenerator generator =
new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.ACTION);
generator.configIndex = 0; generator.configIndex = 0;
generator.initializeActionLocalIds(onAdded, localIdToAction); generator.initializeActionLocalIds(onAdded, localIdToAction);
@ -77,7 +77,8 @@ public class AbilityData {
private void initializeMixins() { private void initializeMixins() {
if (abilityMixins != null) { if (abilityMixins != null) {
AbilityLocalIdGenerator generator = new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.MIXIN); AbilityLocalIdGenerator generator =
new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.MIXIN);
generator.modifierIndex = 0; generator.modifierIndex = 0;
generator.configIndex = 0; generator.configIndex = 0;
@ -88,31 +89,51 @@ public class AbilityData {
private void initializeModifiers() { private void initializeModifiers() {
if (modifiers == null) return; if (modifiers == null) return;
var _modifiers = modifiers.entrySet().stream() var _modifiers =
.sorted(Map.Entry.comparingByKey()).map(Map.Entry::getValue) modifiers.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.map(Map.Entry::getValue)
.toList(); .toList();
var modifierIndex = 0; var modifierIndex = 0;
for (AbilityModifier abilityModifier : _modifiers) { for (AbilityModifier abilityModifier : _modifiers) {
long configIndex = 0L; long configIndex = 0L;
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onAdded, localIdToAction); this.initializeActionSubCategory(
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onRemoved, localIdToAction); modifierIndex, configIndex++, abilityModifier.onAdded, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onBeingHit, localIdToAction); this.initializeActionSubCategory(
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onAttackLanded, localIdToAction); modifierIndex, configIndex++, abilityModifier.onRemoved, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onHittingOther, localIdToAction); this.initializeActionSubCategory(
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onThinkInterval, localIdToAction); modifierIndex, configIndex++, abilityModifier.onBeingHit, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onKill, localIdToAction); this.initializeActionSubCategory(
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onCrash, localIdToAction); modifierIndex, configIndex++, abilityModifier.onAttackLanded, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onAvatarIn, localIdToAction); this.initializeActionSubCategory(
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onAvatarOut, localIdToAction); modifierIndex, configIndex++, abilityModifier.onHittingOther, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onReconnect, localIdToAction); this.initializeActionSubCategory(
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onChangeAuthority, localIdToAction); modifierIndex, configIndex++, abilityModifier.onThinkInterval, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onVehicleIn, localIdToAction); this.initializeActionSubCategory(
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onVehicleOut, localIdToAction); modifierIndex, configIndex++, abilityModifier.onKill, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onZoneEnter, localIdToAction); this.initializeActionSubCategory(
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onZoneExit, localIdToAction); modifierIndex, configIndex++, abilityModifier.onCrash, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onHeal, localIdToAction); this.initializeActionSubCategory(
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onBeingHealed, localIdToAction); modifierIndex, configIndex++, abilityModifier.onAvatarIn, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onAvatarOut, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onReconnect, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onChangeAuthority, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onVehicleIn, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onVehicleOut, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onZoneEnter, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onZoneExit, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onHeal, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onBeingHealed, localIdToAction);
if (abilityModifier.modifierMixins != null) { if (abilityModifier.modifierMixins != null) {
var generator = new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.MODIFIER_MIXIN); var generator = new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.MODIFIER_MIXIN);

View File

@ -1,27 +1,23 @@
package emu.grasscutter.data.binout; package emu.grasscutter.data.binout;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
public class AbilityMixinData implements Serializable { public class AbilityMixinData implements Serializable {
private static final long serialVersionUID = -2001232313615923575L; private static final long serialVersionUID = -2001232313615923575L;
public enum Type { public enum Type {
AttachToGadgetStateMixin, AttachToStateIDMixin, ShieldBarMixin, TileAttackManagerMixin; AttachToGadgetStateMixin,
AttachToStateIDMixin,
ShieldBarMixin,
TileAttackManagerMixin;
} }
@SerializedName("$type") @SerializedName("$type")
public Type type; public Type type;
@ -29,13 +25,11 @@ public class AbilityMixinData implements Serializable {
public List<String> getModifierNames() { public List<String> getModifierNames() {
if (modifierName.isJsonArray()) { if (modifierName.isJsonArray()) {
java.lang.reflect.Type listType = (new TypeToken<List<String>>() { java.lang.reflect.Type listType = (new TypeToken<List<String>>() {}).getType();
}).getType();
List<String> list = (new Gson()).fromJson(modifierName, listType); List<String> list = (new Gson()).fromJson(modifierName, listType);
return list; return list;
} else { } else {
return Arrays.asList(modifierName.getAsString()); return Arrays.asList(modifierName.getAsString());
} }
} }
} }

View File

@ -267,7 +267,9 @@ public class AbilityModifier implements Serializable {
public String target; public String target;
@SerializedName(value = "amount", alternate = {"PDLLIFICICJ", "cdRatio"}) @SerializedName(
value = "amount",
alternate = {"PDLLIFICICJ", "cdRatio"})
public DynamicFloat amount = DynamicFloat.ZERO; public DynamicFloat amount = DynamicFloat.ZERO;
@SerializedName(value = "amountByTargetCurrentHPRatio") @SerializedName(value = "amountByTargetCurrentHPRatio")
@ -276,7 +278,9 @@ public class AbilityModifier implements Serializable {
@SerializedName(value = "unused") @SerializedName(value = "unused")
public DynamicFloat amountByCasterCurrentHPRatio = DynamicFloat.ZERO; public DynamicFloat amountByCasterCurrentHPRatio = DynamicFloat.ZERO;
@SerializedName(value = "unknown", alternate = {"HFNJHOGGFKB", "GEJGGCIOLKN"}) @SerializedName(
value = "unknown",
alternate = {"HFNJHOGGFKB", "GEJGGCIOLKN"})
public DynamicFloat amountByCasterMaxHPRatio = DynamicFloat.ZERO; public DynamicFloat amountByCasterMaxHPRatio = DynamicFloat.ZERO;
public DynamicFloat amountByGetDamage = DynamicFloat.ZERO; public DynamicFloat amountByGetDamage = DynamicFloat.ZERO;

View File

@ -1,17 +1,21 @@
package emu.grasscutter.data.binout; package emu.grasscutter.data.binout;
import java.io.Serializable;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import emu.grasscutter.data.common.DynamicFloat; import emu.grasscutter.data.common.DynamicFloat;
import java.io.Serializable;
public class TalentData implements Serializable { public class TalentData implements Serializable {
public enum Type { public enum Type {
AddAbility, ModifySkillCD, UnlockTalentParam, AddTalentExtraLevel, ModifyAbility; AddAbility,
ModifySkillCD,
UnlockTalentParam,
AddTalentExtraLevel,
ModifyAbility;
} }
@SerializedName("$type") @SerializedName("$type")
public Type type; public Type type;
public String abilityName; public String abilityName;
public String talentParam; public String talentParam;
public int talentIndex; public int talentIndex;

View File

@ -1,7 +1,6 @@
package emu.grasscutter.data.binout.config; package emu.grasscutter.data.binout.config;
import java.util.List; import java.util.List;
import lombok.Data; import lombok.Data;
@Data @Data

View File

@ -1,8 +1,7 @@
package emu.grasscutter.data.binout.config; package emu.grasscutter.data.binout.config;
import java.util.List;
import emu.grasscutter.data.binout.config.fields.ConfigAbilityData; import emu.grasscutter.data.binout.config.fields.ConfigAbilityData;
import java.util.List;
import lombok.Getter; import lombok.Getter;
public class ConfigLevelEntity { public class ConfigLevelEntity {

View File

@ -5,12 +5,11 @@ import emu.grasscutter.game.ability.Ability;
import it.unimi.dsi.fastutil.floats.FloatArrayList; import it.unimi.dsi.fastutil.floats.FloatArrayList;
import it.unimi.dsi.fastutil.objects.Object2FloatArrayMap; import it.unimi.dsi.fastutil.objects.Object2FloatArrayMap;
import it.unimi.dsi.fastutil.objects.Object2FloatMap; import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import lombok.Getter;
import lombok.val;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Optional; import java.util.Optional;
import lombok.Getter;
import lombok.val;
@Getter @Getter
public class DynamicFloat { public class DynamicFloat {

View File

@ -1,9 +1,7 @@
package emu.grasscutter.data.excels; package emu.grasscutter.data.excels;
import java.util.ArrayList;
import emu.grasscutter.data.GameResource; import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType; import emu.grasscutter.data.ResourceType;
import emu.grasscutter.data.common.FightPropData;
import lombok.Getter; import lombok.Getter;
@ResourceType(name = "MonsterAffixExcelConfigData.json") @ResourceType(name = "MonsterAffixExcelConfigData.json")

View File

@ -7,10 +7,9 @@ import emu.grasscutter.data.common.FightPropData;
import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.common.ItemParamData;
import it.unimi.dsi.fastutil.objects.Object2FloatMap; import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap;
import lombok.Getter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.Getter;
@ResourceType(name = "ProudSkillExcelConfigData.json") @ResourceType(name = "ProudSkillExcelConfigData.json")
public class ProudSkillData extends GameResource { public class ProudSkillData extends GameResource {
@ -40,9 +39,7 @@ public class ProudSkillData extends GameResource {
public Iterable<ItemParamData> getTotalCostItems() { public Iterable<ItemParamData> getTotalCostItems() {
if (this.totalCostItems == null) { if (this.totalCostItems == null) {
List<ItemParamData> total = List<ItemParamData> total =
(this.costItems != null) ? (this.costItems != null) ? new ArrayList<>(this.costItems) : new ArrayList<>(1);
new ArrayList<>(this.costItems) :
new ArrayList<>(1);
if (this.coinCost > 0) total.add(new ItemParamData(202, this.coinCost)); if (this.coinCost > 0) total.add(new ItemParamData(202, this.coinCost));
this.totalCostItems = total; this.totalCostItems = total;
} }

View File

@ -1,8 +1,5 @@
package emu.grasscutter.game.ability; package emu.grasscutter.game.ability;
import java.util.HashMap;
import java.util.Map;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.AbilityData; import emu.grasscutter.data.binout.AbilityData;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
@ -11,6 +8,8 @@ import emu.grasscutter.net.proto.AbilityStringOuterClass.AbilityString;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import it.unimi.dsi.fastutil.objects.Object2FloatMap; import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter; import lombok.Getter;
public class Ability { public class Ability {
@ -23,7 +22,8 @@ public class Ability {
@Getter private Map<String, AbilityModifierController> modifiers = new HashMap<>(); @Getter private Map<String, AbilityModifierController> modifiers = new HashMap<>();
@Getter private Object2FloatMap<String> abilitySpecials = new Object2FloatOpenHashMap<>(); @Getter private Object2FloatMap<String> abilitySpecials = new Object2FloatOpenHashMap<>();
@Getter private static Map<String, Object2FloatMap<String>> abilitySpecialsModified = new HashMap<>(); @Getter
private static Map<String, Object2FloatMap<String>> abilitySpecialsModified = new HashMap<>();
@Getter private int hash; @Getter private int hash;
@ -50,8 +50,7 @@ public class Ability {
public static String getAbilityName(AbilityString abString) { public static String getAbilityName(AbilityString abString) {
if (abString.hasStr()) return abString.getStr(); if (abString.hasStr()) return abString.getStr();
if (abString.hasHash()) if (abString.hasHash()) return GameData.getAbilityHashes().get(abString.getHash());
return GameData.getAbilityHashes().get(abString.getHash());
return null; return null;
} }

View File

@ -3,9 +3,8 @@ package emu.grasscutter.game.ability;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.AbilityMixinData; import emu.grasscutter.data.binout.AbilityMixinData;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import lombok.AllArgsConstructor;
import java.util.Map; import java.util.Map;
import lombok.AllArgsConstructor;
@SuppressWarnings("ALL") @SuppressWarnings("ALL")
public class AbilityLocalIdGenerator { public class AbilityLocalIdGenerator {
@ -26,13 +25,12 @@ public class AbilityLocalIdGenerator {
public long mixinIndex = 0; public long mixinIndex = 0;
private long actionIndex = 0; private long actionIndex = 0;
public AbilityLocalIdGenerator(ConfigAbilitySubContainerType type) public AbilityLocalIdGenerator(ConfigAbilitySubContainerType type) {
{
this.type = type; this.type = type;
} }
public void initializeActionLocalIds(AbilityModifierAction[] actions, Map<Integer, AbilityModifierAction> localIdToAction) public void initializeActionLocalIds(
{ AbilityModifierAction[] actions, Map<Integer, AbilityModifierAction> localIdToAction) {
if (actions == null) return; if (actions == null) return;
actionIndex = 0; actionIndex = 0;
for (AbilityModifierAction action : actions) { for (AbilityModifierAction action : actions) {
@ -44,8 +42,8 @@ public class AbilityLocalIdGenerator {
actionIndex = 0; actionIndex = 0;
} }
public void initializeMixinsLocalIds(AbilityMixinData[] mixins, Map<Integer, AbilityMixinData> localIdToAction) public void initializeMixinsLocalIds(
{ AbilityMixinData[] mixins, Map<Integer, AbilityMixinData> localIdToAction) {
if (mixins == null) return; if (mixins == null) return;
mixinIndex = 0; mixinIndex = 0;
for (AbilityMixinData mixin : mixins) { for (AbilityMixinData mixin : mixins) {
@ -58,8 +56,7 @@ public class AbilityLocalIdGenerator {
mixinIndex = 0; mixinIndex = 0;
} }
public long GetLocalId() public long GetLocalId() {
{
switch (type) { switch (type) {
case ACTION -> { case ACTION -> {
return (long) type.value + (configIndex << 3) + (actionIndex << 9); return (long) type.value + (configIndex << 3) + (actionIndex << 9);
@ -71,7 +68,11 @@ public class AbilityLocalIdGenerator {
return (long) type.value + (modifierIndex << 3) + (configIndex << 9) + (actionIndex << 15); return (long) type.value + (modifierIndex << 3) + (configIndex << 9) + (actionIndex << 15);
} }
case MODIFIER_MIXIN -> { case MODIFIER_MIXIN -> {
return (long) type.value + (modifierIndex << 3) + (mixinIndex << 9) + (configIndex << 15) + (actionIndex << 21); return (long) type.value
+ (modifierIndex << 3)
+ (mixinIndex << 9)
+ (configIndex << 15)
+ (actionIndex << 21);
} }
case NONE -> Grasscutter.getLogger().error("Ability local id generator using NONE type."); case NONE -> Grasscutter.getLogger().error("Ability local id generator using NONE type.");
} }

View File

@ -23,25 +23,33 @@ import emu.grasscutter.net.proto.AbilityScalarTypeOuterClass.AbilityScalarType;
import emu.grasscutter.net.proto.AbilityScalarValueEntryOuterClass.AbilityScalarValueEntry; import emu.grasscutter.net.proto.AbilityScalarValueEntryOuterClass.AbilityScalarValueEntry;
import emu.grasscutter.net.proto.ModifierActionOuterClass.ModifierAction; import emu.grasscutter.net.proto.ModifierActionOuterClass.ModifierAction;
import io.netty.util.concurrent.FastThreadLocalThread; import io.netty.util.concurrent.FastThreadLocalThread;
import lombok.Getter;
import org.reflections.Reflections;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import lombok.Getter;
import org.reflections.Reflections;
public final class AbilityManager extends BasePlayerManager { public final class AbilityManager extends BasePlayerManager {
private final static HashMap<AbilityModifierAction.Type, AbilityActionHandler> actionHandlers = new HashMap<>(); private static final HashMap<AbilityModifierAction.Type, AbilityActionHandler> actionHandlers =
private final static HashMap<AbilityMixinData.Type, AbilityMixinHandler> mixinHandlers = new HashMap<>(); new HashMap<>();
private static final HashMap<AbilityMixinData.Type, AbilityMixinHandler> mixinHandlers =
new HashMap<>();
public static final ExecutorService eventExecutor; public static final ExecutorService eventExecutor;
static { static {
eventExecutor = new ThreadPoolExecutor(4, 4, eventExecutor =
60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(1000), new ThreadPoolExecutor(
FastThreadLocalThread::new, new ThreadPoolExecutor.AbortPolicy()); 4,
4,
60,
TimeUnit.SECONDS,
new LinkedBlockingDeque<>(1000),
FastThreadLocalThread::new,
new ThreadPoolExecutor.AbortPolicy());
registerHandlers(); registerHandlers();
} }
@ -86,17 +94,21 @@ public final class AbilityManager extends BasePlayerManager {
} }
} }
public void executeAction(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) { public void executeAction(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
AbilityActionHandler handler = actionHandlers.get(action.type); AbilityActionHandler handler = actionHandlers.get(action.type);
if (handler == null || ability == null) { 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; return;
} }
eventExecutor.submit(() -> { eventExecutor.submit(
() -> {
if (!handler.execute(ability, action, abilityData, target)) { if (!handler.execute(ability, action, abilityData, target)) {
Grasscutter.getLogger().debug("Execute ability action failed {} at {}", action.type, ability); Grasscutter.getLogger()
.debug("Execute ability action failed {} at {}", action.type, ability);
} }
}); });
} }
@ -105,33 +117,58 @@ public final class AbilityManager extends BasePlayerManager {
AbilityMixinHandler handler = mixinHandlers.get(mixinData.type); AbilityMixinHandler handler = mixinHandlers.get(mixinData.type);
if (handler == null || ability == null || mixinData == null) { if (handler == null || ability == null || mixinData == null) {
Grasscutter.getLogger().error("Could not execute ability mixin {} at {}", mixinData.type, ability); Grasscutter.getLogger()
.error("Could not execute ability mixin {} at {}", mixinData.type, ability);
return; return;
} }
eventExecutor.submit(() -> { eventExecutor.submit(
() -> {
if (!handler.execute(ability, mixinData, abilityData)) { if (!handler.execute(ability, mixinData, abilityData)) {
Grasscutter.getLogger().error("exec ability action failed {} at {}", mixinData.type, ability); Grasscutter.getLogger()
.error("exec ability action failed {} at {}", mixinData.type, ability);
} }
}); });
} }
public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception { public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception {
Grasscutter.getLogger().trace("Ability invoke: " + invoke + " " + invoke.getArgumentType() + " (" + invoke.getArgumentTypeValue() + "): " + this.player.getScene().getEntityById(invoke.getEntityId())); Grasscutter.getLogger()
.trace(
"Ability invoke: "
+ invoke
+ " "
+ invoke.getArgumentType()
+ " ("
+ invoke.getArgumentTypeValue()
+ "): "
+ this.player.getScene().getEntityById(invoke.getEntityId()));
var entity = this.player.getScene().getEntityById(invoke.getEntityId()); var entity = this.player.getScene().getEntityById(invoke.getEntityId());
if (entity != null) { if (entity != null) {
Grasscutter.getLogger().trace("Entity {} has a group of {} and a config of {}.", Grasscutter.getLogger()
invoke.getEntityId(), entity.getGroupId(), entity.getConfigId()); .trace(
"Entity {} has a group of {} and a config of {}.",
invoke.getEntityId(),
entity.getGroupId(),
entity.getConfigId());
Grasscutter.getLogger().trace("Invoke type of {} ({}) has entity {}.", Grasscutter.getLogger()
invoke.getArgumentType(), invoke.getArgumentTypeValue(), entity.getId()); .trace(
"Invoke type of {} ({}) has entity {}.",
invoke.getArgumentType(),
invoke.getArgumentTypeValue(),
entity.getId());
} else { } else {
Grasscutter.getLogger().debug("Invoke type of {} ({}) has no entity. (referring to {})", Grasscutter.getLogger()
invoke.getArgumentType(), invoke.getArgumentTypeValue(), invoke.getEntityId()); .debug(
"Invoke type of {} ({}) has no entity. (referring to {})",
invoke.getArgumentType(),
invoke.getArgumentTypeValue(),
invoke.getEntityId());
} }
if (invoke.getHead().getTargetId() != 0) { if (invoke.getHead().getTargetId() != 0) {
Grasscutter.getLogger().trace("Target: " + this.player.getScene().getEntityById(invoke.getHead().getTargetId())); Grasscutter.getLogger()
.trace("Target: " + this.player.getScene().getEntityById(invoke.getHead().getTargetId()));
} }
if (invoke.getHead().getLocalId() != 0) { if (invoke.getHead().getLocalId() != 0) {
this.handleServerInvoke(invoke); this.handleServerInvoke(invoke);
@ -145,7 +182,8 @@ public final class AbilityManager extends BasePlayerManager {
case ABILITY_INVOKE_ARGUMENT_MIXIN_COST_STAMINA -> this.handleMixinCostStamina(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_ACTION_GENERATE_ELEM_BALL -> this.handleGenerateElemBall(invoke);
case ABILITY_INVOKE_ARGUMENT_META_GLOBAL_FLOAT_VALUE -> this.handleGlobalFloatValue(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_META_ADD_NEW_ABILITY -> this.handleAddNewAbility(invoke);
default -> {} default -> {}
} }
@ -168,16 +206,23 @@ public final class AbilityManager extends BasePlayerManager {
// Seems that target is used, but need to be sure, TODO: Research // Seems that target is used, but need to be sure, TODO: Research
// Find ability or modifier's ability // Find ability or modifier's ability
if (head.getInstancedModifierId() != 0 && entity.getInstancedModifiers().containsKey(head.getInstancedModifierId())) { if (head.getInstancedModifierId() != 0
&& entity.getInstancedModifiers().containsKey(head.getInstancedModifierId())) {
ability = entity.getInstancedModifiers().get(head.getInstancedModifierId()).getAbility(); ability = entity.getInstancedModifiers().get(head.getInstancedModifierId()).getAbility();
} }
if (ability == null && head.getInstancedAbilityId() != 0 && (head.getInstancedAbilityId() - 1) < entity.getInstancedAbilities().size()) { if (ability == null
&& head.getInstancedAbilityId() != 0
&& (head.getInstancedAbilityId() - 1) < entity.getInstancedAbilities().size()) {
ability = entity.getInstancedAbilities().get(head.getInstancedAbilityId() - 1); ability = entity.getInstancedAbilities().get(head.getInstancedAbilityId() - 1);
} }
if (ability == null) { if (ability == null) {
Grasscutter.getLogger().trace("Ability not found: ability {} modifier {}", head.getInstancedAbilityId(), head.getInstancedModifierId()); Grasscutter.getLogger()
.trace(
"Ability not found: ability {} modifier {}",
head.getInstancedAbilityId(),
head.getInstancedModifierId());
return; return;
} }
@ -197,11 +242,17 @@ public final class AbilityManager extends BasePlayerManager {
} }
} }
Grasscutter.getLogger().trace("Action or mixin not found: local_id {} ability {} actions to ids {}", head.getLocalId(), ability.getData().abilityName, ability.getData().localIdToAction.toString()); Grasscutter.getLogger()
.trace(
"Action or mixin not found: local_id {} ability {} actions to ids {}",
head.getLocalId(),
ability.getData().abilityName,
ability.getData().localIdToAction.toString());
} }
/** /**
* Invoked when a player starts a skill. * Invoked when a player starts a skill.
*
* @param player The player who started the skill. * @param player The player who started the skill.
* @param skillId The skill ID. * @param skillId The skill ID.
* @param casterId The caster ID. * @param casterId The caster ID.
@ -233,6 +284,7 @@ public final class AbilityManager extends BasePlayerManager {
/** /**
* Invoked when a player ends a skill. * Invoked when a player ends a skill.
*
* @param player The player who started the skill. * @param player The player who started the skill.
*/ */
public void onSkillEnd(Player player) { public void onSkillEnd(Player player) {
@ -264,7 +316,12 @@ public final class AbilityManager extends BasePlayerManager {
} }
ability.getAbilitySpecials().put(valueChange.getKey().getStr(), valueChange.getFloatValue()); ability.getAbilitySpecials().put(valueChange.getKey().getStr(), valueChange.getFloatValue());
Grasscutter.getLogger().trace("Ability {} changed {} to {}", ability.getData().abilityName, valueChange.getKey().getStr(), valueChange.getFloatValue()); Grasscutter.getLogger()
.trace(
"Ability {} changed {} to {}",
ability.getData().abilityName,
valueChange.getKey().getStr(),
valueChange.getFloatValue());
} }
private void handleOverrideParam(AbilityInvokeEntry invoke) throws Exception { private void handleOverrideParam(AbilityInvokeEntry invoke) throws Exception {
@ -315,8 +372,8 @@ public final class AbilityManager extends BasePlayerManager {
var modChange = AbilityMetaModifierChange.parseFrom(invoke.getAbilityData()); var modChange = AbilityMetaModifierChange.parseFrom(invoke.getAbilityData());
var head = invoke.getHead(); var head = invoke.getHead();
if (head.getInstancedAbilityId() == 0 || if (head.getInstancedAbilityId() == 0 || head.getInstancedModifierId() > 2000)
head.getInstancedModifierId() > 2000) return; // Error: TODO: display error return; // Error: TODO: display error
if (head.getIsServerbuffModifier()) { if (head.getIsServerbuffModifier()) {
// TODO // TODO
@ -339,7 +396,8 @@ public final class AbilityManager extends BasePlayerManager {
var targetEntity = this.player.getScene().getEntityById(head.getTargetId()); var targetEntity = this.player.getScene().getEntityById(head.getTargetId());
if (targetEntity != null) { if (targetEntity != null) {
if ((head.getInstancedAbilityId() - 1) < targetEntity.getInstancedAbilities().size()) { if ((head.getInstancedAbilityId() - 1) < targetEntity.getInstancedAbilities().size()) {
instancedAbility = targetEntity.getInstancedAbilities().get(head.getInstancedAbilityId() - 1); instancedAbility =
targetEntity.getInstancedAbilities().get(head.getInstancedAbilityId() - 1);
if (instancedAbility != null) instancedAbilityData = instancedAbility.getData(); if (instancedAbility != null) instancedAbilityData = instancedAbility.getData();
} }
} }
@ -369,24 +427,43 @@ public final class AbilityManager extends BasePlayerManager {
var modifierArray = instancedAbilityData.modifiers.values().toArray(); var modifierArray = instancedAbilityData.modifiers.values().toArray();
if (modChange.getModifierLocalId() >= modifierArray.length) { if (modChange.getModifierLocalId() >= modifierArray.length) {
Grasscutter.getLogger().trace("Modifier local id {} not found", modChange.getModifierLocalId()); Grasscutter.getLogger()
.trace("Modifier local id {} not found", modChange.getModifierLocalId());
return; return;
} }
var modifierData = (AbilityModifier) modifierArray[modChange.getModifierLocalId()]; var modifierData = (AbilityModifier) modifierArray[modChange.getModifierLocalId()];
if (entity.getInstancedModifiers().containsKey(head.getInstancedModifierId())) { if (entity.getInstancedModifiers().containsKey(head.getInstancedModifierId())) {
Grasscutter.getLogger().trace("Replacing entity {} modifier id {} with ability {} modifier {}", invoke.getEntityId(), head.getInstancedModifierId(), instancedAbilityData.abilityName, modifierData); Grasscutter.getLogger()
.trace(
"Replacing entity {} modifier id {} with ability {} modifier {}",
invoke.getEntityId(),
head.getInstancedModifierId(),
instancedAbilityData.abilityName,
modifierData);
} else { } else {
Grasscutter.getLogger().trace("Adding entity {} modifier id {} with ability {} modifier {}", invoke.getEntityId(), head.getInstancedModifierId(), instancedAbilityData.abilityName, modifierData); Grasscutter.getLogger()
.trace(
"Adding entity {} modifier id {} with ability {} modifier {}",
invoke.getEntityId(),
head.getInstancedModifierId(),
instancedAbilityData.abilityName,
modifierData);
} }
AbilityModifierController modifier = new AbilityModifierController(instancedAbility, instancedAbilityData, modifierData); AbilityModifierController modifier =
new AbilityModifierController(instancedAbility, instancedAbilityData, modifierData);
entity.getInstancedModifiers().put(head.getInstancedModifierId(), modifier); entity.getInstancedModifiers().put(head.getInstancedModifierId(), modifier);
// TODO: Add all the ability modifier property change // TODO: Add all the ability modifier property change
} else if (modChange.getAction() == ModifierAction.MODIFIER_ACTION_REMOVED) { } else if (modChange.getAction() == ModifierAction.MODIFIER_ACTION_REMOVED) {
Grasscutter.getLogger().trace("Removed on entity {} modifier id {}: {}", invoke.getEntityId(), head.getInstancedModifierId(), entity.getInstancedModifiers().get(head.getInstancedModifierId())); Grasscutter.getLogger()
.trace(
"Removed on entity {} modifier id {}: {}",
invoke.getEntityId(),
head.getInstancedModifierId(),
entity.getInstancedModifiers().get(head.getInstancedModifierId()));
// TODO: Add debug log // TODO: Add debug log
@ -397,15 +474,14 @@ public final class AbilityManager extends BasePlayerManager {
} }
} }
private void handleMixinCostStamina(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException { private void handleMixinCostStamina(AbilityInvokeEntry invoke)
throws InvalidProtocolBufferException {}
} private void handleGenerateElemBall(AbilityInvokeEntry invoke)
throws InvalidProtocolBufferException {}
private void handleGenerateElemBall(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException { private void handleGlobalFloatValue(AbilityInvokeEntry invoke)
throws InvalidProtocolBufferException {
}
private void handleGlobalFloatValue(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
var entity = this.player.getScene().getEntityById(invoke.getEntityId()); var entity = this.player.getScene().getEntityById(invoke.getEntityId());
if (entity == null) return; if (entity == null) return;
@ -413,8 +489,7 @@ public final class AbilityManager extends BasePlayerManager {
if (entry == null || !entry.hasFloatValue()) return; if (entry == null || !entry.hasFloatValue()) return;
String key = null; String key = null;
if(entry.getKey().hasStr()) if (entry.getKey().hasStr()) key = entry.getKey().getStr();
key = entry.getKey().getStr();
else if (entry.getKey().hasHash()) else if (entry.getKey().hasHash())
key = GameData.getAbilityHashes().get(entry.getKey().getHash()); key = GameData.getAbilityHashes().get(entry.getKey().getHash());
@ -423,7 +498,8 @@ public final class AbilityManager extends BasePlayerManager {
if (key.startsWith("SGV_")) return; // Server does not allow to change this variables I think if (key.startsWith("SGV_")) return; // Server does not allow to change this variables I think
switch (entry.getValueType().getNumber()) { switch (entry.getValueType().getNumber()) {
case AbilityScalarType.ABILITY_SCALAR_TYPE_FLOAT_VALUE: case AbilityScalarType.ABILITY_SCALAR_TYPE_FLOAT_VALUE:
if(!Float.isNaN(entry.getFloatValue())) entity.getGlobalAbilityValues().put(key, entry.getFloatValue()); if (!Float.isNaN(entry.getFloatValue()))
entity.getGlobalAbilityValues().put(key, entry.getFloatValue());
break; break;
case AbilityScalarType.ABILITY_SCALAR_TYPE_UINT_VALUE: case AbilityScalarType.ABILITY_SCALAR_TYPE_UINT_VALUE:
entity.getGlobalAbilityValues().put(key, (float) entry.getUintValue()); entity.getGlobalAbilityValues().put(key, (float) entry.getUintValue());
@ -433,15 +509,14 @@ public final class AbilityManager extends BasePlayerManager {
} }
} }
private void invokeAction(AbilityModifierAction action, GameEntity target, GameEntity sourceEntity) { private void invokeAction(
AbilityModifierAction action, GameEntity target, GameEntity sourceEntity) {}
} private void handleModifierDurabilityChange(AbilityInvokeEntry invoke)
throws InvalidProtocolBufferException {}
private void handleModifierDurabilityChange(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException { private void handleAddNewAbility(AbilityInvokeEntry invoke)
throws InvalidProtocolBufferException {
}
private void handleAddNewAbility(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
var entity = this.player.getScene().getEntityById(invoke.getEntityId()); var entity = this.player.getScene().getEntityById(invoke.getEntityId());
if (entity == null) { if (entity == null) {
@ -461,13 +536,16 @@ public final class AbilityManager extends BasePlayerManager {
entity.getInstancedAbilities().add(new Ability(ability, entity, player)); entity.getInstancedAbilities().add(new Ability(ability, entity, player));
Grasscutter.getLogger().trace("Ability added to entity {} at index {}", entity.getId(), entity.getInstancedAbilities().size()); Grasscutter.getLogger()
.trace(
"Ability added to entity {} at index {}",
entity.getId(),
entity.getInstancedAbilities().size());
} }
public void addAbilityToEntity(GameEntity entity, String name) { public void addAbilityToEntity(GameEntity entity, String name) {
AbilityData data = GameData.getAbilityData(name); AbilityData data = GameData.getAbilityData(name);
if(data != null) if (data != null) addAbilityToEntity(entity, data);
addAbilityToEntity(entity, data);
} }
public void addAbilityToEntity(GameEntity entity, AbilityData abilityData) { public void addAbilityToEntity(GameEntity entity, AbilityData abilityData) {

View File

@ -10,7 +10,8 @@ public class AbilityModifierController {
@Getter private AbilityData abilityData; @Getter private AbilityData abilityData;
@Getter private AbilityModifier modifierData; @Getter private AbilityModifier modifierData;
public AbilityModifierController(Ability ability, AbilityData abilityData, AbilityModifier modifierData) { public AbilityModifierController(
Ability ability, AbilityData abilityData, AbilityModifier modifierData) {
this.ability = ability; this.ability = ability;
this.abilityData = abilityData; this.abilityData = abilityData;
this.modifierData = modifierData; this.modifierData = modifierData;

View File

@ -1,13 +1,12 @@
package emu.grasscutter.game.ability.actions; package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
public abstract class AbilityActionHandler { public abstract class AbilityActionHandler {
public abstract boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target); public abstract boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target);
} }

View File

@ -1,18 +1,15 @@
package emu.grasscutter.game.ability.actions; package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.ability.AbilityModifierController;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
@AbilityAction(AbilityModifierAction.Type.ApplyModifier) @AbilityAction(AbilityModifierAction.Type.ApplyModifier)
public class ActionApplyModifier extends AbilityActionHandler { public class ActionApplyModifier extends AbilityActionHandler {
@Override @Override
public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) { public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
// var modifierData = ability.getData().modifiers.get(action.modifierName); // var modifierData = ability.getData().modifiers.get(action.modifierName);
// if(modifierData == null) { // if(modifierData == null) {
// Grasscutter.getLogger().debug("Modifier {} not found", action.modifierName); // Grasscutter.getLogger().debug("Modifier {} not found", action.modifierName);
@ -20,7 +17,8 @@ public class ActionApplyModifier extends AbilityActionHandler {
// } // }
// //
// if(modifierData.stacking != null && modifierData.stacking.compareTo("Unique") == 0 && // if(modifierData.stacking != null && modifierData.stacking.compareTo("Unique") == 0 &&
// ability.getModifiers().values().stream().filter(m -> m.getData().equals(modifierData)).count() != 0) { // ability.getModifiers().values().stream().filter(m ->
// m.getData().equals(modifierData)).count() != 0) {
// return true; // return true;
// } // }
// //

View File

@ -2,21 +2,21 @@ package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.EntityGadget; import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.props.CampTargetType; import emu.grasscutter.game.props.CampTargetType;
import emu.grasscutter.net.proto.AbilityActionCreateGadgetOuterClass.AbilityActionCreateGadget;
import emu.grasscutter.game.world.Position; import emu.grasscutter.game.world.Position;
import emu.grasscutter.net.proto.AbilityActionCreateGadgetOuterClass.AbilityActionCreateGadget;
@AbilityAction(AbilityModifierAction.Type.CreateGadget) @AbilityAction(AbilityModifierAction.Type.CreateGadget)
public class ActionCreateGadget extends AbilityActionHandler { public class ActionCreateGadget extends AbilityActionHandler {
@Override @Override
public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) { public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
if (!action.byServer) { if (!action.byServer) {
Grasscutter.getLogger().debug("Action not executed by server"); Grasscutter.getLogger().debug("Action not executed by server");
@ -31,17 +31,26 @@ public class ActionCreateGadget extends AbilityActionHandler {
return false; return false;
} }
var entityCreated = new EntityGadget(entity.getScene(), action.gadgetID, new Position(createGadget.getPos()), new Position(createGadget.getRot()), action.campID, CampTargetType.getTypeByName(action.campTargetType).getValue()); var entityCreated =
if(action.ownerIsTarget) new EntityGadget(
entityCreated.setOwner(target); entity.getScene(),
else action.gadgetID,
entityCreated.setOwner(entity); new Position(createGadget.getPos()),
new Position(createGadget.getRot()),
action.campID,
CampTargetType.getTypeByName(action.campTargetType).getValue());
if (action.ownerIsTarget) entityCreated.setOwner(target);
else entityCreated.setOwner(entity);
entity.getScene().addEntity(entityCreated); entity.getScene().addEntity(entityCreated);
Grasscutter.getLogger().info("Gadget {} created at pos {} rot {}", action.gadgetID, entityCreated.getPosition(), entityCreated.getRotation()); Grasscutter.getLogger()
.info(
"Gadget {} created at pos {} rot {}",
action.gadgetID,
entityCreated.getPosition(),
entityCreated.getRotation());
return true; return true;
} }
} }

View File

@ -1,7 +1,6 @@
package emu.grasscutter.game.ability.actions; package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
@ -9,13 +8,16 @@ import emu.grasscutter.game.entity.GameEntity;
@AbilityAction(AbilityModifierAction.Type.ExecuteGadgetLua) @AbilityAction(AbilityModifierAction.Type.ExecuteGadgetLua)
public class ActionExecuteGadgetLua extends AbilityActionHandler { public class ActionExecuteGadgetLua extends AbilityActionHandler {
@Override @Override
public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) { public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
GameEntity owner = ability.getOwner(); GameEntity owner = ability.getOwner();
// Investigate if we need to use target // Investigate if we need to use target
if (owner.getEntityController() != null) { if (owner.getEntityController() != null) {
owner.getEntityController().onClientExecuteRequest(owner, action.param1, action.param2, action.param3); owner
.getEntityController()
.onClientExecuteRequest(owner, action.param1, action.param2, action.param3);
return true; return true;
} }

View File

@ -1,7 +1,6 @@
package emu.grasscutter.game.ability.actions; package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.ability.Ability;
@ -12,20 +11,30 @@ import emu.grasscutter.game.props.FightProperty;
@AbilityAction(AbilityModifierAction.Type.HealHP) @AbilityAction(AbilityModifierAction.Type.HealHP)
public final class ActionHealHP extends AbilityActionHandler { public final class ActionHealHP extends AbilityActionHandler {
@Override @Override
public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) { public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
Grasscutter.getLogger().debug("Heal ability action executing 1"); Grasscutter.getLogger().debug("Heal ability action executing 1");
var owner = ability.getOwner(); var owner = ability.getOwner();
// handle client gadgets, that the effective caster is the current local avatar // handle client gadgets, that the effective caster is the current local avatar
if (owner instanceof EntityClientGadget ownerGadget) { if (owner instanceof EntityClientGadget ownerGadget) {
owner = ownerGadget.getScene().getEntityById(ownerGadget.getOwnerEntityId()); // Caster for EntityClientGadget owner =
Grasscutter.getLogger().debug("Owner {} has top owner {}: {}", ability.getOwner(), ownerGadget.getOwnerEntityId(), owner); ownerGadget
.getScene()
.getEntityById(ownerGadget.getOwnerEntityId()); // Caster for EntityClientGadget
Grasscutter.getLogger()
.debug(
"Owner {} has top owner {}: {}",
ability.getOwner(),
ownerGadget.getOwnerEntityId(),
owner);
} }
if (owner == null) return false; if (owner == null) return false;
ability.getAbilitySpecials().forEach((k, v) -> ability
Grasscutter.getLogger().trace(">>> {}: {}", k, v)); .getAbilitySpecials()
.forEach((k, v) -> Grasscutter.getLogger().trace(">>> {}: {}", k, v));
var amountByCasterMaxHPRatio = action.amountByCasterMaxHPRatio.get(ability); var amountByCasterMaxHPRatio = action.amountByCasterMaxHPRatio.get(ability);
var amountByCasterAttackRatio = action.amountByCasterAttackRatio.get(ability); var amountByCasterAttackRatio = action.amountByCasterAttackRatio.get(ability);
@ -42,27 +51,35 @@ public final class ActionHealHP extends AbilityActionHandler {
var amountToRegenerate = action.amount.get(ability); var amountToRegenerate = action.amount.get(ability);
Grasscutter.getLogger().trace("Base amount: " + amountToRegenerate); Grasscutter.getLogger().trace("Base amount: " + amountToRegenerate);
amountToRegenerate += amountByCasterMaxHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); amountToRegenerate +=
amountToRegenerate += amountByCasterAttackRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK); amountByCasterMaxHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
amountToRegenerate += amountByCasterCurrentHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP); amountToRegenerate +=
amountByCasterAttackRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK);
amountToRegenerate +=
amountByCasterCurrentHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
Grasscutter.getLogger().trace("amountToRegenerate: " + amountToRegenerate); Grasscutter.getLogger().trace("amountToRegenerate: " + amountToRegenerate);
var abilityRatio = 1.0f; var abilityRatio = 1.0f;
Grasscutter.getLogger().trace("Base abilityRatio: " + abilityRatio); Grasscutter.getLogger().trace("Base abilityRatio: " + abilityRatio);
if (!action.ignoreAbilityProperty) abilityRatio += if (!action.ignoreAbilityProperty)
target.getFightProperty(FightProperty.FIGHT_PROP_HEAL_ADD) + abilityRatio +=
target.getFightProperty(FightProperty.FIGHT_PROP_HEALED_ADD); target.getFightProperty(FightProperty.FIGHT_PROP_HEAL_ADD)
+ target.getFightProperty(FightProperty.FIGHT_PROP_HEALED_ADD);
Grasscutter.getLogger().trace("abilityRatio: " + abilityRatio); Grasscutter.getLogger().trace("abilityRatio: " + abilityRatio);
Grasscutter.getLogger().trace("Sub-regenerate amount: " + amountToRegenerate); Grasscutter.getLogger().trace("Sub-regenerate amount: " + amountToRegenerate);
amountToRegenerate += amountByTargetCurrentHPRatio * target.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP); amountToRegenerate +=
amountToRegenerate += amountByTargetMaxHPRatio * target.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); amountByTargetCurrentHPRatio * target.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
amountToRegenerate +=
amountByTargetMaxHPRatio * target.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
Grasscutter.getLogger().debug(">>> Healing {} without ratios", amountToRegenerate); Grasscutter.getLogger().debug(">>> Healing {} without ratios", amountToRegenerate);
target.heal(amountToRegenerate * abilityRatio * action.healRatio.get(ability, 1f), action.muteHealEffect); target.heal(
amountToRegenerate * abilityRatio * action.healRatio.get(ability, 1f),
action.muteHealEffect);
return true; return true;
} }

View File

@ -1,7 +1,6 @@
package emu.grasscutter.game.ability.actions; package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
@ -9,7 +8,8 @@ import emu.grasscutter.game.entity.GameEntity;
@AbilityAction(AbilityModifierAction.Type.KillSelf) @AbilityAction(AbilityModifierAction.Type.KillSelf)
public class ActionKillSelf extends AbilityActionHandler { public class ActionKillSelf extends AbilityActionHandler {
@Override @Override
public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) { public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
GameEntity owner = ability.getOwner(); GameEntity owner = ability.getOwner();
owner.getScene().killEntity(owner); owner.getScene().killEntity(owner);

View File

@ -10,11 +10,15 @@ import emu.grasscutter.game.props.FightProperty;
@AbilityAction(AbilityModifierAction.Type.LoseHP) @AbilityAction(AbilityModifierAction.Type.LoseHP)
public class ActionLoseHP extends AbilityActionHandler { public class ActionLoseHP extends AbilityActionHandler {
@Override @Override
public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) { public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
GameEntity owner = ability.getOwner(); GameEntity owner = ability.getOwner();
// handle client gadgets, that the effective caster is the current local avatar // handle client gadgets, that the effective caster is the current local avatar
if (owner instanceof EntityClientGadget ownerGadget) { if (owner instanceof EntityClientGadget ownerGadget) {
owner = ownerGadget.getScene().getEntityById(ownerGadget.getOwnerEntityId()); //Caster for EntityClientGadget owner =
ownerGadget
.getScene()
.getEntityById(ownerGadget.getOwnerEntityId()); // Caster for EntityClientGadget
// TODO: Do this per entity, not just the player // TODO: Do this per entity, not just the player
if (ownerGadget.getOwner().getAbilityManager().isAbilityInvulnerable()) return true; if (ownerGadget.getOwner().getAbilityManager().isAbilityInvulnerable()) return true;
@ -25,21 +29,26 @@ public class ActionLoseHP extends AbilityActionHandler {
return true; return true;
} }
if (action.disableWhenLoading && target.getScene().getWorld().getHost().getSceneLoadState().getValue() < 2) { if (action.disableWhenLoading
&& target.getScene().getWorld().getHost().getSceneLoadState().getValue() < 2) {
return true; return true;
} }
var amountByCasterMaxHPRatio = action.amountByCasterMaxHPRatio.get(ability); var amountByCasterMaxHPRatio = action.amountByCasterMaxHPRatio.get(ability);
var amountByCasterAttackRatio = action.amountByCasterAttackRatio.get(ability); var amountByCasterAttackRatio = action.amountByCasterAttackRatio.get(ability);
var amountByCasterCurrentHPRatio = action.amountByCasterCurrentHPRatio.get(ability); //Seems unused on server var amountByCasterCurrentHPRatio =
action.amountByCasterCurrentHPRatio.get(ability); // Seems unused on server
var amountByTargetCurrentHPRatio = action.amountByTargetCurrentHPRatio.get(ability); var amountByTargetCurrentHPRatio = action.amountByTargetCurrentHPRatio.get(ability);
var amountByTargetMaxHPRatio = action.amountByTargetMaxHPRatio.get(ability); var amountByTargetMaxHPRatio = action.amountByTargetMaxHPRatio.get(ability);
var limboByTargetMaxHPRatio = action.limboByTargetMaxHPRatio.get(ability); var limboByTargetMaxHPRatio = action.limboByTargetMaxHPRatio.get(ability);
var amountToLose = action.amount.get(ability); var amountToLose = action.amount.get(ability);
amountToLose += amountByCasterMaxHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); amountToLose +=
amountToLose += amountByCasterAttackRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK); amountByCasterMaxHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
amountToLose += amountByCasterCurrentHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP); amountToLose +=
amountByCasterAttackRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK);
amountToLose +=
amountByCasterCurrentHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
var currentHp = target.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP); var currentHp = target.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
var maxHp = target.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); var maxHp = target.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
@ -47,10 +56,13 @@ public class ActionLoseHP extends AbilityActionHandler {
amountToLose += amountByTargetMaxHPRatio * maxHp; amountToLose += amountByTargetMaxHPRatio * maxHp;
if (limboByTargetMaxHPRatio > 1.192093e-07) if (limboByTargetMaxHPRatio > 1.192093e-07)
amountToLose = (float) Math.min(Math.max(currentHp - Math.max(limboByTargetMaxHPRatio * maxHp, 1.0), 0.0), amountToLose); amountToLose =
(float)
Math.min(
Math.max(currentHp - Math.max(limboByTargetMaxHPRatio * maxHp, 1.0), 0.0),
amountToLose);
if (currentHp < (amountToLose + 0.01) && !action.lethal) if (currentHp < (amountToLose + 0.01) && !action.lethal) amountToLose = 0;
amountToLose = 0;
target.damage(amountToLose); target.damage(amountToLose);

View File

@ -1,7 +1,6 @@
package emu.grasscutter.game.ability.actions; package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
@ -9,7 +8,8 @@ import emu.grasscutter.game.entity.GameEntity;
@AbilityAction(AbilityModifierAction.Type.Predicated) @AbilityAction(AbilityModifierAction.Type.Predicated)
public class ActionPredicated extends AbilityActionHandler { public class ActionPredicated extends AbilityActionHandler {
@Override @Override
public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) { public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
// This doesn't do nothing on server // This doesn't do nothing on server
return true; return true;
} }

View File

@ -1,7 +1,6 @@
package emu.grasscutter.game.ability.actions; package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.EntityClientGadget; import emu.grasscutter.game.entity.EntityClientGadget;
@ -11,21 +10,20 @@ import emu.grasscutter.game.entity.GameEntity;
@AbilityAction(AbilityModifierAction.Type.SetGlobalValueToOverrideMap) @AbilityAction(AbilityModifierAction.Type.SetGlobalValueToOverrideMap)
public class ActionSetGlobalValueToOverrideMap extends AbilityActionHandler { public class ActionSetGlobalValueToOverrideMap extends AbilityActionHandler {
@Override @Override
public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) { public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
// TODO: // TODO:
var entity = target; var entity = target;
if (action.isFromOwner) { if (action.isFromOwner) {
if (target instanceof EntityClientGadget gadget) if (target instanceof EntityClientGadget gadget)
entity = entity.getScene().getEntityById(gadget.getOwnerEntityId()); entity = entity.getScene().getEntityById(gadget.getOwnerEntityId());
else if(target instanceof EntityGadget gadget) else if (target instanceof EntityGadget gadget) entity = gadget.getOwner();
entity = gadget.getOwner();
} }
var globalValueKey = action.globalValueKey; var globalValueKey = action.globalValueKey;
var abilityFormula = action.abilityFormula; var abilityFormula = action.abilityFormula;
if(!entity.getGlobalAbilityValues().containsKey(globalValueKey)) if (!entity.getGlobalAbilityValues().containsKey(globalValueKey)) return false;
return false;
var globalValue = entity.getGlobalAbilityValues().getOrDefault(globalValueKey, 0.0f); var globalValue = entity.getGlobalAbilityValues().getOrDefault(globalValueKey, 0.0f);
if (abilityFormula.compareTo("DummyThrowSpeed") == 0) { if (abilityFormula.compareTo("DummyThrowSpeed") == 0) {

View File

@ -1,10 +1,9 @@
package emu.grasscutter.game.ability.mixins; package emu.grasscutter.game.ability.mixins;
import emu.grasscutter.data.binout.AbilityMixinData;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import emu.grasscutter.data.binout.AbilityMixinData;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface AbilityMixin { public @interface AbilityMixin {
AbilityMixinData.Type value(); AbilityMixinData.Type value();

View File

@ -1,12 +1,11 @@
package emu.grasscutter.game.ability.mixins; package emu.grasscutter.game.ability.mixins;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import emu.grasscutter.data.binout.AbilityMixinData; import emu.grasscutter.data.binout.AbilityMixinData;
import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.ability.Ability;
public abstract class AbilityMixinHandler { public abstract class AbilityMixinHandler {
public abstract boolean execute(Ability ability, AbilityMixinData mixinData, ByteString abilityData); public abstract boolean execute(
Ability ability, AbilityMixinData mixinData, ByteString abilityData);
} }

View File

@ -13,15 +13,14 @@ import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.net.proto.ActivityWatcherInfoOuterClass; import emu.grasscutter.net.proto.ActivityWatcherInfoOuterClass;
import emu.grasscutter.server.packet.send.PacketActivityUpdateWatcherNotify; import emu.grasscutter.server.packet.send.PacketActivityUpdateWatcherNotify;
import emu.grasscutter.utils.JsonUtils; import emu.grasscutter.utils.JsonUtils;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
@Entity("activities") @Entity("activities")
@Data @Data
@ -113,8 +112,7 @@ public class PlayerActivityData {
public static WatcherInfo init(ActivityWatcher watcher) { public static WatcherInfo init(ActivityWatcher watcher) {
var watcherData = watcher.getActivityWatcherData(); var watcherData = watcher.getActivityWatcherData();
var progress = watcherData != null ? var progress = watcherData != null ? watcherData.getProgress() : 0;
watcherData.getProgress() : 0;
return WatcherInfo.of() return WatcherInfo.of()
.watcherId(watcher.getWatcherId()) .watcherId(watcher.getWatcherId())

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.avatar; package emu.grasscutter.game.avatar;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import dev.morphia.annotations.*; import dev.morphia.annotations.*;
import emu.grasscutter.GameConstants; import emu.grasscutter.GameConstants;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
@ -22,7 +24,6 @@ import emu.grasscutter.data.excels.trial.TrialAvatarTemplateData;
import emu.grasscutter.data.excels.weapon.WeaponCurveData; import emu.grasscutter.data.excels.weapon.WeaponCurveData;
import emu.grasscutter.data.excels.weapon.WeaponPromoteData; import emu.grasscutter.data.excels.weapon.WeaponPromoteData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.inventory.EquipType; import emu.grasscutter.game.inventory.EquipType;
import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.GameItem;
@ -41,19 +42,16 @@ import emu.grasscutter.net.proto.TrialAvatarInfoOuterClass.TrialAvatarInfo;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.helpers.ProtoHelper; import emu.grasscutter.utils.helpers.ProtoHelper;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import java.util.*;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.val; import lombok.val;
import org.bson.types.ObjectId; import org.bson.types.ObjectId;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.stream.Stream;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
@Entity(value = "avatars", useDiscriminator = false) @Entity(value = "avatars", useDiscriminator = false)
public class Avatar { public class Avatar {
@Transient @Getter private final Int2ObjectMap<GameItem> equips; @Transient @Getter private final Int2ObjectMap<GameItem> equips;

View File

@ -13,11 +13,10 @@ import emu.grasscutter.scripts.data.SceneTrigger;
import emu.grasscutter.scripts.data.ScriptArgs; import emu.grasscutter.scripts.data.ScriptArgs;
import emu.grasscutter.server.packet.send.PacketDungeonChallengeBeginNotify; import emu.grasscutter.server.packet.send.PacketDungeonChallengeBeginNotify;
import emu.grasscutter.server.packet.send.PacketDungeonChallengeFinishNotify; import emu.grasscutter.server.packet.send.PacketDungeonChallengeFinishNotify;
import lombok.Getter;
import lombok.Setter;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import lombok.Getter;
import lombok.Setter;
@Getter @Getter
@Setter @Setter

View File

@ -7,9 +7,8 @@ import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterCountTrigger;
import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterTimeIncTrigger; import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterTimeIncTrigger;
import emu.grasscutter.game.world.Scene; import emu.grasscutter.game.world.Scene;
import emu.grasscutter.scripts.data.SceneGroup; import emu.grasscutter.scripts.data.SceneGroup;
import lombok.val;
import java.util.List; import java.util.List;
import lombok.val;
public class KillMonsterCountInTimeIncChallengeFactoryHandler implements ChallengeFactoryHandler { public class KillMonsterCountInTimeIncChallengeFactoryHandler implements ChallengeFactoryHandler {
@Override @Override
@ -18,16 +17,27 @@ public class KillMonsterCountInTimeIncChallengeFactoryHandler implements Challe
} }
@Override @Override
public WorldChallenge build(int challengeIndex, int challengeId, int groupId, int monsterCount, int timeLimit, int timeInc, Scene scene, SceneGroup group) { public WorldChallenge build(
int challengeIndex,
int challengeId,
int groupId,
int monsterCount,
int timeLimit,
int timeInc,
Scene scene,
SceneGroup group) {
val realGroup = scene.getScriptManager().getGroupById(groupId); val realGroup = scene.getScriptManager().getGroupById(groupId);
return new WorldChallenge( return new WorldChallenge(
scene, realGroup, scene,
realGroup,
challengeId, // Id challengeId, // Id
challengeIndex, // Index challengeIndex, // Index
List.of(monsterCount, timeLimit, timeInc), List.of(monsterCount, timeLimit, timeInc),
timeLimit, // Limit timeLimit, // Limit
monsterCount, // Goal monsterCount, // Goal
List.of(new KillMonsterCountTrigger(), new InTimeTrigger(), new KillMonsterTimeIncTrigger(timeInc)) List.of(
); new KillMonsterCountTrigger(),
new InTimeTrigger(),
new KillMonsterTimeIncTrigger(timeInc)));
} }
} }

View File

@ -14,7 +14,8 @@ public class KillMonsterTimeIncTrigger extends ChallengeTrigger{
@Override @Override
public void onBegin(WorldChallenge challenge) { public void onBegin(WorldChallenge challenge) {
//challenge.getScene().broadcastPacket(new PacketChallengeDataNotify(challenge, 0, challenge.getScore().get())); // challenge.getScene().broadcastPacket(new PacketChallengeDataNotify(challenge, 0,
// challenge.getScore().get()));
} }
@Override @Override

View File

@ -107,8 +107,7 @@ public class EntityAvatar extends GameEntity {
*/ */
public int getWeaponEntityId() { public int getWeaponEntityId() {
var avatar = this.getAvatar(); var avatar = this.getAvatar();
return avatar.getWeapon() == null ? 0 : return avatar.getWeapon() == null ? 0 : avatar.getWeapon().getWeaponEntityId();
avatar.getWeapon().getWeaponEntityId();
} }
@Override @Override
@ -129,13 +128,12 @@ public class EntityAvatar extends GameEntity {
} }
@Override @Override
public void initAbilities() { public void initAbilities() {}
}
private void addConfigAbility(String abilityName) { private void addConfigAbility(String abilityName) {
var data = GameData.getAbilityData(abilityName); var data = GameData.getAbilityData(abilityName);
if (data != null) this.getScene().getWorld() if (data != null)
.getHost().getAbilityManager().addAbilityToEntity(this, data); this.getScene().getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data);
} }
@Override @Override
@ -148,9 +146,16 @@ public class EntityAvatar extends GameEntity {
float healed = super.heal(amount, mute); float healed = super.heal(amount, mute);
if (healed > 0f) { if (healed > 0f) {
getScene().broadcastPacket( getScene()
new PacketEntityFightPropChangeReasonNotify(this, FightProperty.FIGHT_PROP_CUR_HP, healed, mute ? PropChangeReason.PROP_CHANGE_REASON_NONE : PropChangeReason.PROP_CHANGE_REASON_ABILITY, ChangeHpReason.CHANGE_HP_REASON_ADD_ABILITY) .broadcastPacket(
); new PacketEntityFightPropChangeReasonNotify(
this,
FightProperty.FIGHT_PROP_CUR_HP,
healed,
mute
? PropChangeReason.PROP_CHANGE_REASON_NONE
: PropChangeReason.PROP_CHANGE_REASON_ABILITY,
ChangeHpReason.CHANGE_HP_REASON_ADD_ABILITY));
} }
return healed; return healed;

View File

@ -29,7 +29,8 @@ public abstract class EntityBaseGadget extends GameEntity {
this(scene, position, rotation, 0, 0); this(scene, position, rotation, 0, 0);
} }
public EntityBaseGadget(Scene scene, Position position, Position rotation, int campId, int campType) { public EntityBaseGadget(
Scene scene, Position position, Position rotation, int campId, int campType) {
super(scene); super(scene);
this.position = position != null ? position.clone() : new Position(); this.position = position != null ? position.clone() : new Position();
this.rotation = rotation != null ? rotation.clone() : new Position(); this.rotation = rotation != null ? rotation.clone() : new Position();

View File

@ -42,7 +42,12 @@ public class EntityClientGadget extends EntityBaseGadget {
private ConfigEntityGadget configGadget; private ConfigEntityGadget configGadget;
public EntityClientGadget(Scene scene, Player player, EvtCreateGadgetNotify notify) { public EntityClientGadget(Scene scene, Player player, EvtCreateGadgetNotify notify) {
super(scene, new Position(notify.getInitPos()), new Position(notify.getInitEulerAngles()), notify.getCampId(), notify.getCampType()); super(
scene,
new Position(notify.getInitPos()),
new Position(notify.getInitEulerAngles()),
notify.getCampId(),
notify.getCampType());
this.owner = player; this.owner = player;
this.id = notify.getEntityId(); this.id = notify.getEntityId();
this.gadgetId = notify.getConfigId(); this.gadgetId = notify.getConfigId();
@ -76,9 +81,7 @@ public class EntityClientGadget extends EntityBaseGadget {
private void addConfigAbility(ConfigAbilityData abilityData) { private void addConfigAbility(ConfigAbilityData abilityData) {
var data = GameData.getAbilityData(abilityData.getAbilityName()); var data = GameData.getAbilityData(abilityData.getAbilityName());
if (data != null) if (data != null) owner.getAbilityManager().addAbilityToEntity(this, data);
owner.getAbilityManager().addAbilityToEntity(
this, data);
} }
@Override @Override

View File

@ -39,14 +39,13 @@ import emu.grasscutter.server.packet.send.PacketSceneTimeNotify;
import emu.grasscutter.utils.helpers.ProtoHelper; import emu.grasscutter.utils.helpers.ProtoHelper;
import it.unimi.dsi.fastutil.ints.Int2FloatMap; import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@ToString(callSuper = true) @ToString(callSuper = true)
public class EntityGadget extends EntityBaseGadget { public class EntityGadget extends EntityBaseGadget {
@Getter private final GadgetData gadgetData; @Getter private final GadgetData gadgetData;
@ -85,15 +84,24 @@ public class EntityGadget extends EntityBaseGadget {
this(scene, gadgetId, pos, rot, null); this(scene, gadgetId, pos, rot, null);
} }
public EntityGadget(Scene scene, int gadgetId, Position pos, Position rot, int campId, int campType) { public EntityGadget(
Scene scene, int gadgetId, Position pos, Position rot, int campId, int campType) {
this(scene, gadgetId, pos, rot, null, campId, campType); this(scene, gadgetId, pos, rot, null, campId, campType);
} }
public EntityGadget(Scene scene, int gadgetId, Position pos, Position rot, GadgetContent content) { public EntityGadget(
Scene scene, int gadgetId, Position pos, Position rot, GadgetContent content) {
this(scene, gadgetId, pos, rot, content, 0, 0); this(scene, gadgetId, pos, rot, content, 0, 0);
} }
public EntityGadget(Scene scene, int gadgetId, Position pos, Position rot, GadgetContent content, int campId, int campType) { public EntityGadget(
Scene scene,
int gadgetId,
Position pos,
Position rot,
GadgetContent content,
int campId,
int campType) {
super(scene, pos, rot, campId, campType); super(scene, pos, rot, campId, campType);
this.gadgetData = GameData.getGadgetDataMap().get(gadgetId); this.gadgetData = GameData.getGadgetDataMap().get(gadgetId);
@ -121,8 +129,8 @@ public class EntityGadget extends EntityBaseGadget {
private void addConfigAbility(ConfigAbilityData abilityData) { private void addConfigAbility(ConfigAbilityData abilityData) {
var data = GameData.getAbilityData(abilityData.getAbilityName()); var data = GameData.getAbilityData(abilityData.getAbilityName());
if(data != null) this.getScene().getWorld().getHost() if (data != null)
.getAbilityManager().addAbilityToEntity(this, data); this.getScene().getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data);
} }
@Override @Override
@ -137,7 +145,8 @@ public class EntityGadget extends EntityBaseGadget {
public void setInteractEnabled(boolean enable) { public void setInteractEnabled(boolean enable) {
this.interactEnabled = enable; this.interactEnabled = enable;
this.getScene().broadcastPacket(new PacketGadgetStateNotify(this, this.getState())); //Update the interact this.getScene()
.broadcastPacket(new PacketGadgetStateNotify(this, this.getState())); // Update the interact
} }
public void setState(int state) { public void setState(int state) {
@ -308,7 +317,8 @@ public class EntityGadget extends EntityBaseGadget {
addAllFightPropsToEntityInfo(entityInfo); addAllFightPropsToEntityInfo(entityInfo);
} }
var gadgetInfo = SceneGadgetInfo.newBuilder() var gadgetInfo =
SceneGadgetInfo.newBuilder()
.setGadgetId(this.getGadgetId()) .setGadgetId(this.getGadgetId())
.setGroupId(this.getGroupId()) .setGroupId(this.getGroupId())
.setConfigId(this.getConfigId()) .setConfigId(this.getConfigId())

View File

@ -2,10 +2,9 @@ package emu.grasscutter.game.entity;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.AbilityData; import emu.grasscutter.data.binout.AbilityData;
import emu.grasscutter.game.props.EntityIdType; import emu.grasscutter.game.world.Position;
import emu.grasscutter.game.world.Scene; import emu.grasscutter.game.world.Scene;
import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo; import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
import emu.grasscutter.game.world.Position;
import it.unimi.dsi.fastutil.ints.Int2FloatArrayMap; import it.unimi.dsi.fastutil.ints.Int2FloatArrayMap;
import it.unimi.dsi.fastutil.ints.Int2FloatMap; import it.unimi.dsi.fastutil.ints.Int2FloatMap;
@ -19,11 +18,11 @@ public class EntityScene extends GameEntity {
@Override @Override
public void initAbilities() { public void initAbilities() {
// Load abilities from levelElementAbilities // Load abilities from levelElementAbilities
for(var ability : GameData.getConfigGlobalCombat().getDefaultAbilities().getLevelElementAbilities()) { for (var ability :
GameData.getConfigGlobalCombat().getDefaultAbilities().getLevelElementAbilities()) {
AbilityData data = GameData.getAbilityData(ability); AbilityData data = GameData.getAbilityData(ability);
if (data != null) if (data != null)
getScene().getWorld().getHost().getAbilityManager().addAbilityToEntity( getScene().getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data);
this, data);
} }
} }
@ -53,5 +52,4 @@ public class EntityScene extends GameEntity {
public SceneEntityInfo toProto() { public SceneEntityInfo toProto() {
return null; return null;
} }
} }

View File

@ -4,9 +4,9 @@ import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.AbilityData; import emu.grasscutter.data.binout.AbilityData;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.EntityIdType; import emu.grasscutter.game.props.EntityIdType;
import emu.grasscutter.game.world.Position;
import emu.grasscutter.game.world.World; import emu.grasscutter.game.world.World;
import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo; import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
import emu.grasscutter.game.world.Position;
import it.unimi.dsi.fastutil.ints.Int2FloatArrayMap; import it.unimi.dsi.fastutil.ints.Int2FloatArrayMap;
import it.unimi.dsi.fastutil.ints.Int2FloatMap; import it.unimi.dsi.fastutil.ints.Int2FloatMap;
@ -28,8 +28,7 @@ public class EntityTeam extends GameEntity {
for (var ability : defaultAbilities.getDefaultTeamAbilities()) { for (var ability : defaultAbilities.getDefaultTeamAbilities()) {
AbilityData data = GameData.getAbilityData(ability); AbilityData data = GameData.getAbilityData(ability);
if (data != null) if (data != null)
player.getWorld().getHost().getAbilityManager().addAbilityToEntity( player.getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data);
this, data);
} }
} }
@ -64,5 +63,4 @@ public class EntityTeam extends GameEntity {
public SceneEntityInfo toProto() { public SceneEntityInfo toProto() {
return null; return null;
} }
} }

View File

@ -30,11 +30,10 @@ public class EntityWorld extends GameEntity {
@Override @Override
public void initAbilities() { public void initAbilities() {
// Load abilities from levelElementAbilities // Load abilities from levelElementAbilities
for (var ability : GameData.getConfigGlobalCombat() for (var ability :
.getDefaultAbilities().getDefaultMPLevelAbilities()) { GameData.getConfigGlobalCombat().getDefaultAbilities().getDefaultMPLevelAbilities()) {
var data = GameData.getAbilityData(ability); var data = GameData.getAbilityData(ability);
if (data != null) world.getHost() if (data != null) world.getHost().getAbilityManager().addAbilityToEntity(this, data);
.getAbilityManager().addAbilityToEntity(this, data);
} }
} }

View File

@ -23,15 +23,12 @@ import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import it.unimi.dsi.fastutil.ints.Int2FloatMap; import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; 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.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import lombok.Getter;
import lombok.Setter;
public abstract class GameEntity { public abstract class GameEntity {
@Getter private final Scene scene; @Getter private final Scene scene;
@ -53,7 +50,11 @@ public abstract class GameEntity {
@Getter private ElementType lastAttackType = ElementType.None; @Getter private ElementType lastAttackType = ElementType.None;
@Getter private List<Ability> instancedAbilities = new ArrayList<>(); @Getter private List<Ability> instancedAbilities = new ArrayList<>();
@Getter private Int2ObjectMap<AbilityModifierController> instancedModifiers = new Int2ObjectOpenHashMap<>();
@Getter
private Int2ObjectMap<AbilityModifierController> instancedModifiers =
new Int2ObjectOpenHashMap<>();
@Getter private Map<String, Float> globalAbilityValues = new HashMap<>(); @Getter private Map<String, Float> globalAbilityValues = new HashMap<>();
public GameEntity(Scene scene) { public GameEntity(Scene scene) {

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.player; package emu.grasscutter.game.player;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Transient; import dev.morphia.annotations.Transient;
import emu.grasscutter.GameConstants; import emu.grasscutter.GameConstants;
@ -32,15 +34,12 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.util.*;
import java.util.stream.Stream;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.val; import lombok.val;
import java.util.*;
import java.util.stream.Stream;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
@Entity @Entity
public final class TeamManager extends BasePlayerDataManager { public final class TeamManager extends BasePlayerDataManager {
@Transient private final List<EntityAvatar> avatars; @Transient private final List<EntityAvatar> avatars;

View File

@ -1,12 +1,11 @@
package emu.grasscutter.game.props; package emu.grasscutter.game.props;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
import emu.grasscutter.scripts.constants.IntValueEnum; import emu.grasscutter.scripts.constants.IntValueEnum;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
public enum CampTargetType implements IntValueEnum { public enum CampTargetType implements IntValueEnum {
None(0), None(0),
@ -23,7 +22,9 @@ public enum CampTargetType implements IntValueEnum{
private static final Map<String, CampTargetType> stringMap = new HashMap<>(); private static final Map<String, CampTargetType> stringMap = new HashMap<>();
static { static {
Stream.of(values()).forEach(e -> { Stream.of(values())
.forEach(
e -> {
map.put(e.getValue(), e); map.put(e.getValue(), e);
stringMap.put(e.name(), e); stringMap.put(e.name(), e);
}); });

View File

@ -41,15 +41,14 @@ import emu.grasscutter.server.event.player.PlayerTeleportEvent;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.objects.KahnsSort; import emu.grasscutter.utils.objects.KahnsSort;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import lombok.Getter;
import lombok.Setter;
import lombok.val;
import javax.annotation.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;
import lombok.val;
public final class Scene { public final class Scene {
@Getter private final World world; @Getter private final World world;
@ -119,12 +118,11 @@ public final class Scene {
public GameEntity getEntityById(int id) { public GameEntity getEntityById(int id) {
// Check if the scene's entity ID is referenced. // Check if the scene's entity ID is referenced.
if (id == 0x13800001) return this.sceneEntity; if (id == 0x13800001) return this.sceneEntity;
else if (id == this.getWorld().getLevelEntityId()) else if (id == this.getWorld().getLevelEntityId()) return this.getWorld().getEntity();
return this.getWorld().getEntity();
var teamEntityPlayer = players.stream().filter(p -> p.getTeamManager().getEntity().getId() == id).findAny(); var teamEntityPlayer =
if(teamEntityPlayer.isPresent()) players.stream().filter(p -> p.getTeamManager().getEntity().getId() == id).findAny();
return teamEntityPlayer.get().getTeamManager().getEntity(); if (teamEntityPlayer.isPresent()) return teamEntityPlayer.get().getTeamManager().getEntity();
var entity = this.entities.get(id); var entity = this.entities.get(id);
if (entity == null && (id >> 24) == EntityType.Avatar.getValue()) { if (entity == null && (id >> 24) == EntityType.Avatar.getValue()) {

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.world; package emu.grasscutter.game.world;
import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.dungeon.DungeonData; import emu.grasscutter.data.excels.dungeon.DungeonData;
import emu.grasscutter.game.entity.EntityTeam; import emu.grasscutter.game.entity.EntityTeam;
@ -23,16 +25,13 @@ import emu.grasscutter.utils.ConversionUtils;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import lombok.Getter;
import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT; import lombok.val;
import org.jetbrains.annotations.NotNull;
public class World implements Iterable<Player> { public class World implements Iterable<Player> {
@Getter private final GameServer server; @Getter private final GameServer server;
@ -183,11 +182,12 @@ public class World implements Iterable<Player> {
new PacketDelTeamEntityNotify( new PacketDelTeamEntityNotify(
player.getSceneId(), player.getSceneId(),
this.getPlayers().stream() this.getPlayers().stream()
.map(p -> .map(
p.getTeamManager().getEntity() == null ? 0 : p ->
p.getTeamManager().getEntity().getId()).toList() p.getTeamManager().getEntity() == null
) ? 0
); : p.getTeamManager().getEntity().getId())
.toList()));
// Deregister // Deregister
this.getPlayers().remove(player); this.getPlayers().remove(player);

View File

@ -1,10 +1,9 @@
package emu.grasscutter.scripts.data; package emu.grasscutter.scripts.data;
import java.util.List;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import java.util.List;
@ToString @ToString
@Setter @Setter
public class SceneMonster extends SceneObject { public class SceneMonster extends SceneObject {

View File

@ -10,11 +10,10 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.type.CollectionType; import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.MapType; import com.fasterxml.jackson.databind.type.MapType;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
public class LuaTableJacksonSerializer extends JsonSerializer<LuaTable> implements Serializer { public class LuaTableJacksonSerializer extends JsonSerializer<LuaTable> implements Serializer {
@ -22,7 +21,8 @@ public class LuaTableJacksonSerializer extends JsonSerializer<LuaTable> implemen
public LuaTableJacksonSerializer() { public LuaTableJacksonSerializer() {
if (objectMapper == null) { if (objectMapper == null) {
objectMapper = JsonMapper.builder() objectMapper =
JsonMapper.builder()
.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true) .configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.build(); .build();

View File

@ -2,20 +2,20 @@ package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry;
import emu.grasscutter.net.proto.ClientAbilitiesInitFinishCombineNotifyOuterClass.ClientAbilitiesInitFinishCombineNotify; import emu.grasscutter.net.proto.ClientAbilitiesInitFinishCombineNotifyOuterClass.ClientAbilitiesInitFinishCombineNotify;
import emu.grasscutter.net.proto.EntityAbilityInvokeEntryOuterClass.EntityAbilityInvokeEntry; import emu.grasscutter.net.proto.EntityAbilityInvokeEntryOuterClass.EntityAbilityInvokeEntry;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.utils.Utils;
@Opcodes(PacketOpcodes.ClientAbilitiesInitFinishCombineNotify) @Opcodes(PacketOpcodes.ClientAbilitiesInitFinishCombineNotify)
public class HandlerClientAbilitiesInitFinishCombineNotify extends PacketHandler { public class HandlerClientAbilitiesInitFinishCombineNotify extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
ClientAbilitiesInitFinishCombineNotify notif = ClientAbilitiesInitFinishCombineNotify.parseFrom(payload); ClientAbilitiesInitFinishCombineNotify notif =
ClientAbilitiesInitFinishCombineNotify.parseFrom(payload);
Player player = session.getPlayer(); Player player = session.getPlayer();

View File

@ -2,11 +2,11 @@ package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.MonsterAlertChangeNotifyOuterClass.MonsterAlertChangeNotify; import emu.grasscutter.net.proto.MonsterAlertChangeNotifyOuterClass.MonsterAlertChangeNotify;
import emu.grasscutter.scripts.constants.EventType; import emu.grasscutter.scripts.constants.EventType;
import emu.grasscutter.scripts.data.ScriptArgs; import emu.grasscutter.scripts.data.ScriptArgs;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
@Opcodes(PacketOpcodes.MonsterAlertChangeNotify) @Opcodes(PacketOpcodes.MonsterAlertChangeNotify)
@ -22,7 +22,12 @@ public class HandlerMonsterAlertChangeNotify extends PacketHandler {
for (var monsterId : notify.getMonsterEntityListList()) { for (var monsterId : notify.getMonsterEntityListList()) {
var monster = (EntityMonster) player.getScene().getEntityById(monsterId); var monster = (EntityMonster) player.getScene().getEntityById(monsterId);
if (monster != null && monster.getPlayerOnBattle().isEmpty()) { if (monster != null && monster.getPlayerOnBattle().isEmpty()) {
monster.getScene().getScriptManager().callEvent(new ScriptArgs(monster.getGroupId(), EventType.EVENT_MONSTER_BATTLE, monster.getConfigId())); monster
.getScene()
.getScriptManager()
.callEvent(
new ScriptArgs(
monster.getGroupId(), EventType.EVENT_MONSTER_BATTLE, monster.getConfigId()));
} }
if (monster != null) monster.getPlayerOnBattle().add(player); if (monster != null) monster.getPlayerOnBattle().add(player);
@ -31,5 +36,4 @@ public class HandlerMonsterAlertChangeNotify extends PacketHandler {
// TODO: Research invisible monsters // TODO: Research invisible monsters
} }
} }

View File

@ -1,20 +1,18 @@
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ClientAbilitiesInitFinishCombineNotifyOuterClass.ClientAbilitiesInitFinishCombineNotify; import emu.grasscutter.net.proto.ClientAbilitiesInitFinishCombineNotifyOuterClass.ClientAbilitiesInitFinishCombineNotify;
import emu.grasscutter.net.proto.EntityAbilityInvokeEntryOuterClass.EntityAbilityInvokeEntry; import emu.grasscutter.net.proto.EntityAbilityInvokeEntryOuterClass.EntityAbilityInvokeEntry;
import java.util.List;
public class PacketClientAbilitiesInitFinishCombineNotify extends BasePacket { public class PacketClientAbilitiesInitFinishCombineNotify extends BasePacket {
public PacketClientAbilitiesInitFinishCombineNotify(List<EntityAbilityInvokeEntry> entries) { public PacketClientAbilitiesInitFinishCombineNotify(List<EntityAbilityInvokeEntry> entries) {
super(PacketOpcodes.ClientAbilitiesInitFinishCombineNotify, true); super(PacketOpcodes.ClientAbilitiesInitFinishCombineNotify, true);
ClientAbilitiesInitFinishCombineNotify proto = ClientAbilitiesInitFinishCombineNotify.newBuilder() ClientAbilitiesInitFinishCombineNotify proto =
.addAllEntityInvokeList(entries) ClientAbilitiesInitFinishCombineNotify.newBuilder().addAllEntityInvokeList(entries).build();
.build();
this.setData(proto); this.setData(proto);
} }

View File

@ -1,8 +1,5 @@
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import java.util.Map;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.MonsterForceAlertNotifyOuterClass.MonsterForceAlertNotify; import emu.grasscutter.net.proto.MonsterForceAlertNotifyOuterClass.MonsterForceAlertNotify;
@ -13,11 +10,9 @@ public class PacketMonsterForceAlertNotify extends BasePacket {
public PacketMonsterForceAlertNotify(int monsterId) { public PacketMonsterForceAlertNotify(int monsterId) {
super(PacketOpcodes.MonsterForceAlertNotify); super(PacketOpcodes.MonsterForceAlertNotify);
MonsterForceAlertNotify proto = MonsterForceAlertNotify.newBuilder() MonsterForceAlertNotify proto =
.setMonsterEntityId(monsterId) MonsterForceAlertNotify.newBuilder().setMonsterEntityId(monsterId).build();
.build();
this.setData(proto); this.setData(proto);
} }
} }

View File

@ -1,20 +1,20 @@
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import java.util.Collection;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SceneEntityUpdateNotifyOuterClass.SceneEntityUpdateNotify; import emu.grasscutter.net.proto.SceneEntityUpdateNotifyOuterClass.SceneEntityUpdateNotify;
import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType; import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
import java.util.Collection;
public class PacketSceneEntityUpdateNotify extends BasePacket { public class PacketSceneEntityUpdateNotify extends BasePacket {
public PacketSceneEntityUpdateNotify(GameEntity entity) { public PacketSceneEntityUpdateNotify(GameEntity entity) {
super(PacketOpcodes.SceneEntityUpdateNotify, true); super(PacketOpcodes.SceneEntityUpdateNotify, true);
SceneEntityUpdateNotify.Builder proto = SceneEntityUpdateNotify.newBuilder() SceneEntityUpdateNotify.Builder proto =
SceneEntityUpdateNotify.newBuilder()
.setAppearType(VisionType.VISION_TYPE_BORN) .setAppearType(VisionType.VISION_TYPE_BORN)
.addEntityList(entity.toProto()); .addEntityList(entity.toProto());
@ -24,7 +24,8 @@ public class PacketSceneEntityUpdateNotify extends BasePacket {
public PacketSceneEntityUpdateNotify(GameEntity entity, VisionType vision, int param) { public PacketSceneEntityUpdateNotify(GameEntity entity, VisionType vision, int param) {
super(PacketOpcodes.SceneEntityUpdateNotify, true); super(PacketOpcodes.SceneEntityUpdateNotify, true);
SceneEntityUpdateNotify.Builder proto = SceneEntityUpdateNotify.newBuilder() SceneEntityUpdateNotify.Builder proto =
SceneEntityUpdateNotify.newBuilder()
.setAppearType(vision) .setAppearType(vision)
.setParam(param) .setParam(param)
.addEntityList(entity.toProto()); .addEntityList(entity.toProto());
@ -36,11 +37,12 @@ public class PacketSceneEntityUpdateNotify extends BasePacket {
this(player.getTeamManager().getCurrentAvatarEntity()); this(player.getTeamManager().getCurrentAvatarEntity());
} }
public PacketSceneEntityUpdateNotify(Collection<? extends GameEntity> entities, VisionType visionType) { public PacketSceneEntityUpdateNotify(
Collection<? extends GameEntity> entities, VisionType visionType) {
super(PacketOpcodes.SceneEntityUpdateNotify, true); super(PacketOpcodes.SceneEntityUpdateNotify, true);
SceneEntityUpdateNotify.Builder proto = SceneEntityUpdateNotify.newBuilder() SceneEntityUpdateNotify.Builder proto =
.setAppearType(visionType); SceneEntityUpdateNotify.newBuilder().setAppearType(visionType);
entities.forEach(e -> proto.addEntityList(e.toProto())); entities.forEach(e -> proto.addEntityList(e.toProto()));

View File

@ -13,13 +13,12 @@ import emu.grasscutter.game.world.Position;
import it.unimi.dsi.fastutil.floats.FloatArrayList; import it.unimi.dsi.fastutil.floats.FloatArrayList;
import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntList;
import lombok.val;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
import lombok.val;
public interface JsonAdapters { public interface JsonAdapters {
class DynamicFloatAdapter extends TypeAdapter<DynamicFloat> { class DynamicFloatAdapter extends TypeAdapter<DynamicFloat> {

View File

@ -116,9 +116,11 @@ public final class JsonUtils {
} }
} }
public static <T1,T2> Map<T1,T2> loadToMap(Path filename, Class<T1> keyType, Type valueType) throws IOException { public static <T1, T2> Map<T1, T2> loadToMap(Path filename, Class<T1> keyType, Type valueType)
throws IOException {
try (var fileReader = Files.newBufferedReader(filename, StandardCharsets.UTF_8)) { try (var fileReader = Files.newBufferedReader(filename, StandardCharsets.UTF_8)) {
return gson.fromJson(fileReader, TypeToken.getParameterized(Map.class, keyType, valueType).getType()); return gson.fromJson(
fileReader, TypeToken.getParameterized(Map.class, keyType, valueType).getType());
} }
} }

View File

@ -1,5 +1,7 @@
package emu.grasscutter.utils; package emu.grasscutter.utils;
import static emu.grasscutter.utils.Utils.nonRegexSplit;
import com.google.gson.*; import com.google.gson.*;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
@ -7,8 +9,6 @@ import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap; import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap;
import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
import lombok.val;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -19,8 +19,7 @@ import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import java.util.stream.Stream; import java.util.stream.Stream;
import lombok.val;
import static emu.grasscutter.utils.Utils.nonRegexSplit;
// Throughout this file, commented System.out.println debug log calls are left in. // Throughout this file, commented System.out.println debug log calls are left in.
// This is because the default logger will deadlock when operating on parallel streams. // This is because the default logger will deadlock when operating on parallel streams.