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

View File

@ -1,5 +1,9 @@
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.reflect.TypeToken;
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.IntArrayList;
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.InputStreamReader;
import java.nio.file.Files;
@ -49,10 +47,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static emu.grasscutter.utils.FileUtils.getDataPath;
import static emu.grasscutter.utils.FileUtils.getResourcePath;
import static emu.grasscutter.utils.lang.Language.translate;
import javax.script.Bindings;
import javax.script.CompiledScript;
import lombok.SneakyThrows;
import lombok.val;
import org.reflections.Reflections;
public final class ResourceLoader {
@ -230,11 +229,15 @@ public final class ResourceLoader {
});
}
private static void loadGlobalCombatConfig(){
private static void loadGlobalCombatConfig() {
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) {
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,13 +432,19 @@ public final class ResourceLoader {
private static void loadTalents() {
// Load from BinOutput
try (var paths = Files.walk(getResourcePath("BinOutput/Talent/AvatarTalents/"))) {
paths.filter(Files::isDirectory).forEach((folderPath) -> {
try (var paths2 = Files.walk(folderPath)) {
paths2.filter(Files::isRegularFile).filter(path -> path.toString().endsWith(".json")).forEach(ResourceLoader::loadTalent);
} catch (IOException e) {
Grasscutter.getLogger().error("Error loading talents: ", e);
}
});
paths
.filter(Files::isDirectory)
.forEach(
(folderPath) -> {
try (var paths2 = Files.walk(folderPath)) {
paths2
.filter(Files::isRegularFile)
.filter(path -> path.toString().endsWith(".json"))
.forEach(ResourceLoader::loadTalent);
} catch (IOException e) {
Grasscutter.getLogger().error("Error loading talents: ", e);
}
});
} catch (IOException e) {
Grasscutter.getLogger().error("Error loading talents: ", e);
}
@ -443,9 +452,13 @@ public final class ResourceLoader {
private static void loadTalent(Path path) {
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) {
Grasscutter.getLogger().error("Error loading ability modifiers from path " + path.toString() + ": ", e);
Grasscutter.getLogger()
.error("Error loading ability modifiers from path " + path.toString() + ": ", e);
}
}
@ -815,8 +828,9 @@ public final class ResourceLoader {
var monsterMap = GameData.getMonsterMappingMap();
try {
JsonUtils.loadToList(getResourcePath("Server/MonsterMapping.json"), MonsterMapping.class)
.forEach(entry -> monsterMap.put(entry.getMonsterId(), entry));
} catch (IOException | NullPointerException ignored) {}
.forEach(entry -> monsterMap.put(entry.getMonsterId(), entry));
} catch (IOException | NullPointerException ignored) {
}
Grasscutter.getLogger().debug("Loaded {} monster mappings.", monsterMap.size());
} catch (Exception e) {
@ -965,7 +979,8 @@ public final class ResourceLoader {
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;
}
}

View File

@ -3,7 +3,6 @@ package emu.grasscutter.data.binout;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.AbilityLocalIdGenerator;
import emu.grasscutter.game.ability.AbilityLocalIdGenerator.ConfigAbilitySubContainerType;
import java.util.HashMap;
import java.util.Map;
@ -45,7 +44,8 @@ public class AbilityData {
}
private void initializeActions() {
AbilityLocalIdGenerator generator = new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.ACTION);
AbilityLocalIdGenerator generator =
new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.ACTION);
generator.configIndex = 0;
generator.initializeActionLocalIds(onAdded, localIdToAction);
@ -76,8 +76,9 @@ public class AbilityData {
}
private void initializeMixins() {
if(abilityMixins != null) {
AbilityLocalIdGenerator generator = new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.MIXIN);
if (abilityMixins != null) {
AbilityLocalIdGenerator generator =
new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.MIXIN);
generator.modifierIndex = 0;
generator.configIndex = 0;
@ -86,33 +87,53 @@ public class AbilityData {
}
private void initializeModifiers() {
if(modifiers == null) return;
if (modifiers == null) return;
var _modifiers = modifiers.entrySet().stream()
.sorted(Map.Entry.comparingByKey()).map(Map.Entry::getValue)
.toList();
var _modifiers =
modifiers.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.map(Map.Entry::getValue)
.toList();
var modifierIndex = 0;
for (AbilityModifier abilityModifier : _modifiers) {
long configIndex = 0L;
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onAdded, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onRemoved, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onBeingHit, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onAttackLanded, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onHittingOther, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onThinkInterval, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onKill, localIdToAction);
this.initializeActionSubCategory(modifierIndex, configIndex++, abilityModifier.onCrash, localIdToAction);
this.initializeActionSubCategory(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);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onAdded, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onRemoved, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onBeingHit, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onAttackLanded, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onHittingOther, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onThinkInterval, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onKill, localIdToAction);
this.initializeActionSubCategory(
modifierIndex, configIndex++, abilityModifier.onCrash, localIdToAction);
this.initializeActionSubCategory(
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) {
var generator = new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.MODIFIER_MIXIN);

View File

@ -1,41 +1,35 @@
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.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
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.reflect.TypeToken;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
public class AbilityMixinData implements Serializable {
private static final long serialVersionUID = -2001232313615923575L;
public enum Type {
AttachToGadgetStateMixin, AttachToStateIDMixin, ShieldBarMixin, TileAttackManagerMixin;
AttachToGadgetStateMixin,
AttachToStateIDMixin,
ShieldBarMixin,
TileAttackManagerMixin;
}
@SerializedName("$type")
public Type type;
private JsonElement modifierName;
public List<String> getModifierNames() {
if(modifierName.isJsonArray()) {
java.lang.reflect.Type listType = (new TypeToken<List<String>>() {
}).getType();
if (modifierName.isJsonArray()) {
java.lang.reflect.Type listType = (new TypeToken<List<String>>() {}).getType();
List<String> list = (new Gson()).fromJson(modifierName, listType);
return list;
} else {
return Arrays.asList(modifierName.getAsString());
}
}
}

View File

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

View File

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

View File

@ -1,13 +1,12 @@
package emu.grasscutter.data.binout.config;
import java.util.List;
import lombok.Data;
@Data
public class ConfigGlobalCombat {
private DefaultAbilities defaultAbilities;
//TODO: Add more indices
// TODO: Add more indices
@Data
public class DefaultAbilities {

View File

@ -1,8 +1,7 @@
package emu.grasscutter.data.binout.config;
import java.util.List;
import emu.grasscutter.data.binout.config.fields.ConfigAbilityData;
import java.util.List;
import lombok.Getter;
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.objects.Object2FloatArrayMap;
import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import lombok.Getter;
import lombok.val;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import lombok.Getter;
import lombok.val;
@Getter
public class DynamicFloat {
@ -80,19 +79,19 @@ public class DynamicFloat {
}
try {
return fl.popFloat(); // well-formed data will always have only one value left at this point
} catch(NoSuchElementException e) {
return fl.popFloat(); // well-formed data will always have only one value left at this point
} catch (NoSuchElementException e) {
return defaultValue;
}
}
public float get(ProudSkillData skill) {
//Construct the map
// Construct the map
return get(skill.getParamListMap(), 0f);
}
public float get(ProudSkillData skill, float defaultValue) {
//Construct the map
// Construct the map
return get(skill.getParamListMap(), defaultValue);
}

View File

@ -1,9 +1,7 @@
package emu.grasscutter.data.excels;
import java.util.ArrayList;
import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType;
import emu.grasscutter.data.common.FightPropData;
import lombok.Getter;
@ResourceType(name = "MonsterAffixExcelConfigData.json")
@ -12,7 +10,7 @@ public class MonsterAffixData extends GameResource {
private int id;
@Getter private String affix;
@Getter private String comment;
@Getter private String[] abilityName; //Declared as list but used as single element
@Getter private String[] abilityName; // Declared as list but used as single element
@Getter private boolean isCommon;
@Getter private boolean preAdd;
@Getter public String isLegal;

View File

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

View File

@ -1,8 +1,5 @@
package emu.grasscutter.game.ability;
import java.util.HashMap;
import java.util.Map;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.AbilityData;
import emu.grasscutter.game.entity.GameEntity;
@ -11,6 +8,8 @@ import emu.grasscutter.net.proto.AbilityStringOuterClass.AbilityString;
import emu.grasscutter.utils.Utils;
import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
public class Ability {
@ -23,7 +22,8 @@ public class Ability {
@Getter private Map<String, AbilityModifierController> modifiers = new HashMap<>();
@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;
@ -33,13 +33,13 @@ public class Ability {
this.manager = owner.getWorld().getHost().getAbilityManager();
if (this.data.abilitySpecials != null) {
for(var entry : this.data.abilitySpecials.entrySet())
for (var entry : this.data.abilitySpecials.entrySet())
abilitySpecials.put(entry.getKey(), entry.getValue().floatValue());
}
//if(abilitySpecialsModified.containsKey(this.data.abilityName)) {//Modify talent data
// if(abilitySpecialsModified.containsKey(this.data.abilityName)) {//Modify talent data
// abilitySpecials.putAll(abilitySpecialsModified.get(this.data.abilityName));
//}
// }
this.playerOwner = playerOwner;
@ -50,8 +50,7 @@ public class Ability {
public static String getAbilityName(AbilityString abString) {
if (abString.hasStr()) return abString.getStr();
if (abString.hasHash())
return GameData.getAbilityHashes().get(abString.getHash());
if (abString.hasHash()) return GameData.getAbilityHashes().get(abString.getHash());
return null;
}

View File

@ -3,9 +3,8 @@ package emu.grasscutter.game.ability;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.AbilityMixinData;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import lombok.AllArgsConstructor;
import java.util.Map;
import lombok.AllArgsConstructor;
@SuppressWarnings("ALL")
public class AbilityLocalIdGenerator {
@ -26,13 +25,12 @@ public class AbilityLocalIdGenerator {
public long mixinIndex = 0;
private long actionIndex = 0;
public AbilityLocalIdGenerator(ConfigAbilitySubContainerType type)
{
public AbilityLocalIdGenerator(ConfigAbilitySubContainerType type) {
this.type = type;
}
public void initializeActionLocalIds(AbilityModifierAction[] actions, Map<Integer, AbilityModifierAction> localIdToAction)
{
public void initializeActionLocalIds(
AbilityModifierAction[] actions, Map<Integer, AbilityModifierAction> localIdToAction) {
if (actions == null) return;
actionIndex = 0;
for (AbilityModifierAction action : actions) {
@ -44,8 +42,8 @@ public class AbilityLocalIdGenerator {
actionIndex = 0;
}
public void initializeMixinsLocalIds(AbilityMixinData[] mixins, Map<Integer, AbilityMixinData> localIdToAction)
{
public void initializeMixinsLocalIds(
AbilityMixinData[] mixins, Map<Integer, AbilityMixinData> localIdToAction) {
if (mixins == null) return;
mixinIndex = 0;
for (AbilityMixinData mixin : mixins) {
@ -58,8 +56,7 @@ public class AbilityLocalIdGenerator {
mixinIndex = 0;
}
public long GetLocalId()
{
public long GetLocalId() {
switch (type) {
case ACTION -> {
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);
}
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.");
}

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.ModifierActionOuterClass.ModifierAction;
import io.netty.util.concurrent.FastThreadLocalThread;
import lombok.Getter;
import org.reflections.Reflections;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import lombok.Getter;
import org.reflections.Reflections;
public final class AbilityManager extends BasePlayerManager {
private final static HashMap<AbilityModifierAction.Type, AbilityActionHandler> actionHandlers = new HashMap<>();
private final static HashMap<AbilityMixinData.Type, AbilityMixinHandler> mixinHandlers = new HashMap<>();
private static final HashMap<AbilityModifierAction.Type, AbilityActionHandler> actionHandlers =
new HashMap<>();
private static final HashMap<AbilityMixinData.Type, AbilityMixinHandler> mixinHandlers =
new HashMap<>();
public static final ExecutorService eventExecutor;
static {
eventExecutor = new ThreadPoolExecutor(4, 4,
60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(1000),
FastThreadLocalThread::new, new ThreadPoolExecutor.AbortPolicy());
eventExecutor =
new ThreadPoolExecutor(
4,
4,
60,
TimeUnit.SECONDS,
new LinkedBlockingDeque<>(1000),
FastThreadLocalThread::new,
new ThreadPoolExecutor.AbortPolicy());
registerHandlers();
}
@ -86,52 +94,81 @@ 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);
if (handler == null || ability == null) {
Grasscutter.getLogger().debug("Could not execute ability action {} at {}", action.type, ability);
Grasscutter.getLogger()
.debug("Could not execute ability action {} at {}", action.type, ability);
return;
}
eventExecutor.submit(() -> {
if (!handler.execute(ability, action, abilityData, target)) {
Grasscutter.getLogger().debug("Execute ability action failed {} at {}", action.type, ability);
}
});
eventExecutor.submit(
() -> {
if (!handler.execute(ability, action, abilityData, target)) {
Grasscutter.getLogger()
.debug("Execute ability action failed {} at {}", action.type, ability);
}
});
}
public void executeMixin(Ability ability, AbilityMixinData mixinData, ByteString abilityData) {
AbilityMixinHandler handler = mixinHandlers.get(mixinData.type);
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;
}
eventExecutor.submit(() -> {
if (!handler.execute(ability, mixinData, abilityData)) {
Grasscutter.getLogger().error("exec ability action failed {} at {}", mixinData.type, ability);
}
});
eventExecutor.submit(
() -> {
if (!handler.execute(ability, mixinData, abilityData)) {
Grasscutter.getLogger()
.error("exec ability action failed {} at {}", mixinData.type, ability);
}
});
}
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());
if (entity != null) {
Grasscutter.getLogger().trace("Entity {} has a group of {} and a config of {}.",
invoke.getEntityId(), entity.getGroupId(), entity.getConfigId());
Grasscutter.getLogger()
.trace(
"Entity {} has a group of {} and a config of {}.",
invoke.getEntityId(),
entity.getGroupId(),
entity.getConfigId());
Grasscutter.getLogger().trace("Invoke type of {} ({}) has entity {}.",
invoke.getArgumentType(), invoke.getArgumentTypeValue(), entity.getId());
Grasscutter.getLogger()
.trace(
"Invoke type of {} ({}) has entity {}.",
invoke.getArgumentType(),
invoke.getArgumentTypeValue(),
entity.getId());
} else {
Grasscutter.getLogger().debug("Invoke type of {} ({}) has no entity. (referring to {})",
invoke.getArgumentType(), invoke.getArgumentTypeValue(), invoke.getEntityId());
Grasscutter.getLogger()
.debug(
"Invoke type of {} ({}) has no entity. (referring to {})",
invoke.getArgumentType(),
invoke.getArgumentTypeValue(),
invoke.getEntityId());
}
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) {
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_ACTION_GENERATE_ELEM_BALL -> this.handleGenerateElemBall(invoke);
case ABILITY_INVOKE_ARGUMENT_META_GLOBAL_FLOAT_VALUE -> this.handleGlobalFloatValue(invoke);
case ABILITY_INVOKE_ARGUMENT_META_MODIFIER_DURABILITY_CHANGE -> this.handleModifierDurabilityChange(invoke);
case ABILITY_INVOKE_ARGUMENT_META_MODIFIER_DURABILITY_CHANGE -> this
.handleModifierDurabilityChange(invoke);
case ABILITY_INVOKE_ARGUMENT_META_ADD_NEW_ABILITY -> this.handleAddNewAbility(invoke);
default -> {}
}
@ -161,47 +199,60 @@ public final class AbilityManager extends BasePlayerManager {
}
var target = this.player.getScene().getEntityById(head.getTargetId());
if(target == null) target = entity;
if (target == null) target = entity;
Ability ability = null;
// Seems that target is used, but need to be sure, TODO: Research
// 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();
}
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);
}
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;
}
//Time to reach the handlers
// Time to reach the handlers
var action = ability.getData().localIdToAction.get(head.getLocalId());
if (action != null) {
//Executing action
// Executing action
this.executeAction(ability, action, invoke.getAbilityData(), target);
return;
} else {
var mixin = ability.getData().localIdToMixin.get(head.getLocalId());
if(mixin != null) {
if (mixin != null) {
executeMixin(ability, mixin, invoke.getAbilityData());
return;
}
}
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.
*
* @param player The player who started the skill.
* @param skillId The skill ID.
* @param casterId The caster ID.
@ -233,6 +284,7 @@ public final class AbilityManager extends BasePlayerManager {
/**
* Invoked when a player ends a skill.
*
* @param player The player who started the skill.
*/
public void onSkillEnd(Player player) {
@ -251,33 +303,38 @@ public final class AbilityManager extends BasePlayerManager {
}
private void setAbilityOverrideValue(Ability ability, AbilityScalarValueEntry valueChange) {
if(valueChange.getValueType() != AbilityScalarType.ABILITY_SCALAR_TYPE_FLOAT) {
if (valueChange.getValueType() != AbilityScalarType.ABILITY_SCALAR_TYPE_FLOAT) {
Grasscutter.getLogger().trace("Scalar type not supported: {}", valueChange.getValueType());
return;
}
if(!valueChange.getKey().hasStr()) {
if (!valueChange.getKey().hasStr()) {
Grasscutter.getLogger().trace("TODO: Calculate all the ability value hashes");
return;
}
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 {
var entity = this.player.getScene().getEntityById(invoke.getEntityId());
var head = invoke.getHead();
if(entity == null) {
if (entity == null) {
Grasscutter.getLogger().trace("Entity not found: {}", invoke.getEntityId());
return;
}
var instancedAbilityIndex = head.getInstancedAbilityId() - 1;
if(instancedAbilityIndex >= entity.getInstancedAbilities().size()) {
if (instancedAbilityIndex >= entity.getInstancedAbilities().size()) {
Grasscutter.getLogger().error("Ability not found {}", head.getInstancedAbilityId());
return;
}
@ -292,13 +349,13 @@ public final class AbilityManager extends BasePlayerManager {
var entity = this.player.getScene().getEntityById(invoke.getEntityId());
var head = invoke.getHead();
if(entity == null) {
if (entity == null) {
Grasscutter.getLogger().trace("Entity not found: {}", invoke.getEntityId());
return;
}
var instancedAbilityIndex = head.getInstancedAbilityId() - 1;
if(instancedAbilityIndex >= entity.getInstancedAbilities().size()) {
if (instancedAbilityIndex >= entity.getInstancedAbilities().size()) {
Grasscutter.getLogger().error("Ability not found {}", head.getInstancedAbilityId());
return;
}
@ -311,15 +368,15 @@ public final class AbilityManager extends BasePlayerManager {
}
private void handleModifierChange(AbilityInvokeEntry invoke) throws Exception {
//TODO:
// TODO:
var modChange = AbilityMetaModifierChange.parseFrom(invoke.getAbilityData());
var head = invoke.getHead();
if (head.getInstancedAbilityId() == 0 ||
head.getInstancedModifierId() > 2000) return; // Error: TODO: display error
if (head.getInstancedAbilityId() == 0 || head.getInstancedModifierId() > 2000)
return; // Error: TODO: display error
if (head.getIsServerbuffModifier()) {
//TODO
// TODO
Grasscutter.getLogger().trace("TODO: Handle serverbuff modifier");
return;
}
@ -335,18 +392,19 @@ public final class AbilityManager extends BasePlayerManager {
Ability instancedAbility = null;
if (head.getTargetId() != 0) {
//Get ability from target entity
// Get ability from target entity
var targetEntity = this.player.getScene().getEntityById(head.getTargetId());
if (targetEntity != null) {
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 (instancedAbilityData == null) {
//search on entity base id
// search on entity base id
if (entity != null) {
if ((head.getInstancedAbilityId() - 1) < entity.getInstancedAbilities().size()) {
instancedAbility = entity.getInstancedAbilities().get(head.getInstancedAbilityId() - 1);
@ -356,95 +414,112 @@ public final class AbilityManager extends BasePlayerManager {
}
if (instancedAbilityData == null) {
//Search for the parent ability
// Search for the parent ability
//TODO: Research about hash
// TODO: Research about hash
instancedAbilityData = GameData.getAbilityData(modChange.getParentAbilityName().getStr());
}
if (instancedAbilityData == null) {
Grasscutter.getLogger().trace("No ability found");
return; //TODO: Display error message
return; // TODO: Display error message
}
var modifierArray = instancedAbilityData.modifiers.values().toArray();
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;
}
var modifierData = (AbilityModifier)modifierArray[modChange.getModifierLocalId()];
var modifierData = (AbilityModifier) modifierArray[modChange.getModifierLocalId()];
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 {
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);
//TODO: Add all the ability modifier property change
} 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()));
// TODO: Add all the ability modifier property change
} 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()));
//TODO: Add debug log
// TODO: Add debug log
entity.getInstancedModifiers().remove(head.getInstancedModifierId());
} else {
//TODO: Display error message
// TODO: Display error message
Grasscutter.getLogger().debug("Unknown action");
}
}
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());
if(entity == null) return;
if (entity == null) return;
var entry = AbilityScalarValueEntry.parseFrom(invoke.getAbilityData());
if(entry == null || !entry.hasFloatValue()) return;
if (entry == null || !entry.hasFloatValue()) return;
String key = null;
if(entry.getKey().hasStr())
key = entry.getKey().getStr();
else if(entry.getKey().hasHash())
if (entry.getKey().hasStr()) key = entry.getKey().getStr();
else if (entry.getKey().hasHash())
key = GameData.getAbilityHashes().get(entry.getKey().getHash());
if(key == null) return;
if (key == null) return;
if(key.startsWith("SGV_")) return; //Server does not allow to change this variables I think
switch(entry.getValueType().getNumber()) {
if (key.startsWith("SGV_")) return; // Server does not allow to change this variables I think
switch (entry.getValueType().getNumber()) {
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;
case AbilityScalarType.ABILITY_SCALAR_TYPE_UINT_VALUE:
entity.getGlobalAbilityValues().put(key, (float)entry.getUintValue());
entity.getGlobalAbilityValues().put(key, (float) entry.getUintValue());
break;
default:
return;
}
}
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());
if(entity == null) {
if (entity == null) {
Grasscutter.getLogger().trace("Entity not found: {}", invoke.getEntityId());
return;
}
@ -454,24 +529,27 @@ public final class AbilityManager extends BasePlayerManager {
var abilityName = Ability.getAbilityName(addAbility.getAbility().getAbilityName());
var ability = GameData.getAbilityData(abilityName);
if(ability == null) {
if (ability == null) {
Grasscutter.getLogger().trace("Ability not found: {}", abilityName);
return;
}
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) {
AbilityData data = GameData.getAbilityData(name);
if(data != null)
addAbilityToEntity(entity, data);
if (data != null) addAbilityToEntity(entity, data);
}
public void addAbilityToEntity(GameEntity entity, AbilityData abilityData) {
Ability ability = new Ability(abilityData, entity, this.player);
entity.getInstancedAbilities().add(ability); //This are in order
entity.getInstancedAbilities().add(ability); // This are in order
}
}

View File

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

View File

@ -1,13 +1,12 @@
package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.GameEntity;
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,37 +1,35 @@
package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.ability.AbilityModifierController;
import emu.grasscutter.game.entity.GameEntity;
@AbilityAction(AbilityModifierAction.Type.ApplyModifier)
public class ActionApplyModifier extends AbilityActionHandler {
@Override
public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
//var modifierData = ability.getData().modifiers.get(action.modifierName);
//if(modifierData == null) {
public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
// var modifierData = ability.getData().modifiers.get(action.modifierName);
// if(modifierData == null) {
// Grasscutter.getLogger().debug("Modifier {} not found", action.modifierName);
// return false;
//}
//
//if(modifierData.stacking != null && modifierData.stacking.compareTo("Unique") == 0 &&
// ability.getModifiers().values().stream().filter(m -> m.getData().equals(modifierData)).count() != 0) {
// }
//
// if(modifierData.stacking != null && modifierData.stacking.compareTo("Unique") == 0 &&
// ability.getModifiers().values().stream().filter(m ->
// m.getData().equals(modifierData)).count() != 0) {
// return true;
//}
//
////TODO: Check predicates before executing all of these actions
//
//AbilityModifierController modifier = new AbilityModifierController(ability, modifierData);
//ability.getModifiers().put(action.modifierName, modifier);
//modifier.onAdded();
//
//return true;
// }
//
//// TODO: Check predicates before executing all of these actions
//
// AbilityModifierController modifier = new AbilityModifierController(ability, modifierData);
// ability.getModifiers().put(action.modifierName, modifier);
// modifier.onAdded();
//
// return true;
return false; //TODO
return false; // TODO
}
}

View File

@ -2,22 +2,22 @@ package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.props.CampTargetType;
import emu.grasscutter.net.proto.AbilityActionCreateGadgetOuterClass.AbilityActionCreateGadget;
import emu.grasscutter.game.world.Position;
import emu.grasscutter.net.proto.AbilityActionCreateGadgetOuterClass.AbilityActionCreateGadget;
@AbilityAction(AbilityModifierAction.Type.CreateGadget)
public class ActionCreateGadget extends AbilityActionHandler {
@Override
public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
if(!action.byServer) {
public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
if (!action.byServer) {
Grasscutter.getLogger().debug("Action not executed by server");
return true;
@ -31,17 +31,26 @@ public class ActionCreateGadget extends AbilityActionHandler {
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());
if(action.ownerIsTarget)
entityCreated.setOwner(target);
else
entityCreated.setOwner(entity);
var entityCreated =
new EntityGadget(
entity.getScene(),
action.gadgetID,
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);
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;
}
}

View File

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

View File

@ -1,7 +1,6 @@
package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability;
@ -12,20 +11,30 @@ import emu.grasscutter.game.props.FightProperty;
@AbilityAction(AbilityModifierAction.Type.HealHP)
public final class ActionHealHP extends AbilityActionHandler {
@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");
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) {
owner = ownerGadget.getScene().getEntityById(ownerGadget.getOwnerEntityId()); // Caster for EntityClientGadget
Grasscutter.getLogger().debug("Owner {} has top owner {}: {}", ability.getOwner(), ownerGadget.getOwnerEntityId(), owner);
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;
ability.getAbilitySpecials().forEach((k, v) ->
Grasscutter.getLogger().trace(">>> {}: {}", k, v));
ability
.getAbilitySpecials()
.forEach((k, v) -> Grasscutter.getLogger().trace(">>> {}: {}", k, v));
var amountByCasterMaxHPRatio = action.amountByCasterMaxHPRatio.get(ability);
var amountByCasterAttackRatio = action.amountByCasterAttackRatio.get(ability);
@ -42,27 +51,35 @@ public final class ActionHealHP extends AbilityActionHandler {
var amountToRegenerate = action.amount.get(ability);
Grasscutter.getLogger().trace("Base amount: " + amountToRegenerate);
amountToRegenerate += amountByCasterMaxHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
amountToRegenerate += amountByCasterAttackRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK);
amountToRegenerate += amountByCasterCurrentHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
amountToRegenerate +=
amountByCasterMaxHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
amountToRegenerate +=
amountByCasterAttackRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK);
amountToRegenerate +=
amountByCasterCurrentHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
Grasscutter.getLogger().trace("amountToRegenerate: " + amountToRegenerate);
var abilityRatio = 1.0f;
Grasscutter.getLogger().trace("Base abilityRatio: " + abilityRatio);
if (!action.ignoreAbilityProperty) abilityRatio +=
target.getFightProperty(FightProperty.FIGHT_PROP_HEAL_ADD) +
target.getFightProperty(FightProperty.FIGHT_PROP_HEALED_ADD);
if (!action.ignoreAbilityProperty)
abilityRatio +=
target.getFightProperty(FightProperty.FIGHT_PROP_HEAL_ADD)
+ target.getFightProperty(FightProperty.FIGHT_PROP_HEALED_ADD);
Grasscutter.getLogger().trace("abilityRatio: " + abilityRatio);
Grasscutter.getLogger().trace("Sub-regenerate amount: " + amountToRegenerate);
amountToRegenerate += amountByTargetCurrentHPRatio * target.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
amountToRegenerate += amountByTargetMaxHPRatio * target.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
amountToRegenerate +=
amountByTargetCurrentHPRatio * target.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
amountToRegenerate +=
amountByTargetMaxHPRatio * target.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
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;
}

View File

@ -1,7 +1,6 @@
package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.GameEntity;
@ -9,7 +8,8 @@ import emu.grasscutter.game.entity.GameEntity;
@AbilityAction(AbilityModifierAction.Type.KillSelf)
public class ActionKillSelf extends AbilityActionHandler {
@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();
owner.getScene().killEntity(owner);

View File

@ -10,11 +10,15 @@ import emu.grasscutter.game.props.FightProperty;
@AbilityAction(AbilityModifierAction.Type.LoseHP)
public class ActionLoseHP extends AbilityActionHandler {
@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();
// handle client gadgets, that the effective caster is the current local avatar
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
if (ownerGadget.getOwner().getAbilityManager().isAbilityInvulnerable()) return true;
@ -25,21 +29,26 @@ public class ActionLoseHP extends AbilityActionHandler {
return true;
}
if (action.disableWhenLoading && target.getScene().getWorld().getHost().getSceneLoadState().getValue() < 2) {
if (action.disableWhenLoading
&& target.getScene().getWorld().getHost().getSceneLoadState().getValue() < 2) {
return true;
}
var amountByCasterMaxHPRatio = action.amountByCasterMaxHPRatio.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 amountByTargetMaxHPRatio = action.amountByTargetMaxHPRatio.get(ability);
var limboByTargetMaxHPRatio = action.limboByTargetMaxHPRatio.get(ability);
var amountToLose = action.amount.get(ability);
amountToLose += amountByCasterMaxHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
amountToLose += amountByCasterAttackRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK);
amountToLose += amountByCasterCurrentHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
amountToLose +=
amountByCasterMaxHPRatio * owner.getFightProperty(FightProperty.FIGHT_PROP_MAX_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 maxHp = target.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
@ -47,10 +56,13 @@ public class ActionLoseHP extends AbilityActionHandler {
amountToLose += amountByTargetMaxHPRatio * maxHp;
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)
amountToLose = 0;
if (currentHp < (amountToLose + 0.01) && !action.lethal) amountToLose = 0;
target.damage(amountToLose);

View File

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

View File

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

View File

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

View File

@ -1,12 +1,11 @@
package emu.grasscutter.game.ability.mixins;
import com.google.protobuf.ByteString;
import emu.grasscutter.data.binout.AbilityMixinData;
import emu.grasscutter.game.ability.Ability;
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.server.packet.send.PacketActivityUpdateWatcherNotify;
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.List;
import java.util.Map;
import java.util.Optional;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
@Entity("activities")
@Data
@ -113,8 +112,7 @@ public class PlayerActivityData {
public static WatcherInfo init(ActivityWatcher watcher) {
var watcherData = watcher.getActivityWatcherData();
var progress = watcherData != null ?
watcherData.getProgress() : 0;
var progress = watcherData != null ? watcherData.getProgress() : 0;
return WatcherInfo.of()
.watcherId(watcher.getWatcherId())

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.avatar;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import dev.morphia.annotations.*;
import emu.grasscutter.GameConstants;
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.WeaponPromoteData;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.inventory.EquipType;
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.utils.helpers.ProtoHelper;
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.Getter;
import lombok.Setter;
import lombok.val;
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)
public class Avatar {
@Transient @Getter private final Int2ObjectMap<GameItem> equips;
@ -284,7 +282,7 @@ public class Avatar {
.forEach(proudSkillId -> this.proudSkillList.add(proudSkillId));
this.recalcStats();
if (notify){
if (notify) {
owner.sendPacket(new PacketAvatarSkillDepotChangeNotify(this));
}
}

View File

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

View File

@ -7,27 +7,37 @@ import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterCountTrigger;
import emu.grasscutter.game.dungeons.challenge.trigger.KillMonsterTimeIncTrigger;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.scripts.data.SceneGroup;
import java.util.List;
import lombok.val;
import java.util.List;
public class KillMonsterCountInTimeIncChallengeFactoryHandler implements ChallengeFactoryHandler{
public class KillMonsterCountInTimeIncChallengeFactoryHandler implements ChallengeFactoryHandler {
@Override
public boolean isThisType(ChallengeType challengeType) {
return challengeType == ChallengeType.CHALLENGE_TIME_FLY;
}
@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);
return new WorldChallenge(
scene, realGroup,
challengeId, // Id
challengeIndex, // Index
List.of(monsterCount, timeLimit, timeInc),
timeLimit, // Limit
monsterCount, // Goal
List.of(new KillMonsterCountTrigger(), new InTimeTrigger(), new KillMonsterTimeIncTrigger(timeInc))
);
scene,
realGroup,
challengeId, // Id
challengeIndex, // Index
List.of(monsterCount, timeLimit, timeInc),
timeLimit, // Limit
monsterCount, // Goal
List.of(
new KillMonsterCountTrigger(),
new InTimeTrigger(),
new KillMonsterTimeIncTrigger(timeInc)));
}
}

View File

@ -4,7 +4,7 @@ import emu.grasscutter.game.dungeons.challenge.WorldChallenge;
import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.server.packet.send.PacketChallengeDataNotify;
public class KillMonsterTimeIncTrigger extends ChallengeTrigger{
public class KillMonsterTimeIncTrigger extends ChallengeTrigger {
private int increment;
@ -14,7 +14,8 @@ public class KillMonsterTimeIncTrigger extends ChallengeTrigger{
@Override
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

View File

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

View File

@ -29,7 +29,8 @@ public abstract class EntityBaseGadget extends GameEntity {
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);
this.position = position != null ? position.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;
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.id = notify.getEntityId();
this.gadgetId = notify.getConfigId();
@ -67,18 +72,16 @@ public class EntityClientGadget extends EntityBaseGadget {
@Override
public void initAbilities() {
if(this.configGadget != null && this.configGadget.getAbilities() != null) {
if (this.configGadget != null && this.configGadget.getAbilities() != null) {
for (var ability : this.configGadget.getAbilities()) {
addConfigAbility(ability);
}
}
}
private void addConfigAbility(ConfigAbilityData abilityData){
var data = GameData.getAbilityData(abilityData.getAbilityName());
if (data != null)
owner.getAbilityManager().addAbilityToEntity(
this, data);
private void addConfigAbility(ConfigAbilityData abilityData) {
var data = GameData.getAbilityData(abilityData.getAbilityName());
if (data != null) owner.getAbilityManager().addAbilityToEntity(this, data);
}
@Override

View File

@ -39,14 +39,13 @@ import emu.grasscutter.server.packet.send.PacketSceneTimeNotify;
import emu.grasscutter.utils.helpers.ProtoHelper;
import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@ToString(callSuper = true)
public class EntityGadget extends EntityBaseGadget {
@Getter private final GadgetData gadgetData;
@ -85,15 +84,24 @@ public class EntityGadget extends EntityBaseGadget {
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);
}
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);
}
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);
this.gadgetData = GameData.getGadgetDataMap().get(gadgetId);
@ -119,15 +127,15 @@ public class EntityGadget extends EntityBaseGadget {
this.initAbilities(); // TODO: move this
}
private void addConfigAbility(ConfigAbilityData abilityData){
var data = GameData.getAbilityData(abilityData.getAbilityName());
if(data != null) this.getScene().getWorld().getHost()
.getAbilityManager().addAbilityToEntity(this, data);
private void addConfigAbility(ConfigAbilityData abilityData) {
var data = GameData.getAbilityData(abilityData.getAbilityName());
if (data != null)
this.getScene().getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data);
}
@Override
public void initAbilities() {
//TODO: handle pre-dynamic, static and dynamic here
// TODO: handle pre-dynamic, static and dynamic here
if (this.configGadget != null && this.configGadget.getAbilities() != null) {
for (var ability : this.configGadget.getAbilities()) {
this.addConfigAbility(ability);
@ -137,7 +145,8 @@ public class EntityGadget extends EntityBaseGadget {
public void setInteractEnabled(boolean 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) {
@ -308,13 +317,14 @@ public class EntityGadget extends EntityBaseGadget {
addAllFightPropsToEntityInfo(entityInfo);
}
var gadgetInfo = SceneGadgetInfo.newBuilder()
.setGadgetId(this.getGadgetId())
.setGroupId(this.getGroupId())
.setConfigId(this.getConfigId())
.setGadgetState(this.getState())
.setIsEnableInteract(this.interactEnabled)
.setAuthorityPeerId(this.getScene().getWorld().getHostPeerId());
var gadgetInfo =
SceneGadgetInfo.newBuilder()
.setGadgetId(this.getGadgetId())
.setGroupId(this.getGroupId())
.setConfigId(this.getConfigId())
.setGadgetState(this.getState())
.setIsEnableInteract(this.interactEnabled)
.setAuthorityPeerId(this.getScene().getWorld().getHostPeerId());
if (this.metaGadget != null) {
gadgetInfo.setDraftId(this.metaGadget.draft_id);

View File

@ -2,10 +2,9 @@ package emu.grasscutter.game.entity;
import emu.grasscutter.data.GameData;
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.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
import emu.grasscutter.game.world.Position;
import it.unimi.dsi.fastutil.ints.Int2FloatArrayMap;
import it.unimi.dsi.fastutil.ints.Int2FloatMap;
@ -18,12 +17,12 @@ public class EntityScene extends GameEntity {
@Override
public void initAbilities() {
//Load abilities from levelElementAbilities
for(var ability : GameData.getConfigGlobalCombat().getDefaultAbilities().getLevelElementAbilities()) {
AbilityData data = GameData.getAbilityData(ability);
if(data != null)
getScene().getWorld().getHost().getAbilityManager().addAbilityToEntity(
this, data);
// Load abilities from levelElementAbilities
for (var ability :
GameData.getConfigGlobalCombat().getDefaultAbilities().getLevelElementAbilities()) {
AbilityData data = GameData.getAbilityData(ability);
if (data != null)
getScene().getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data);
}
}
@ -34,7 +33,7 @@ public class EntityScene extends GameEntity {
@Override
public Int2FloatMap getFightProperties() {
//TODO
// TODO
return new Int2FloatArrayMap();
}
@ -53,5 +52,4 @@ public class EntityScene extends GameEntity {
public SceneEntityInfo toProto() {
return null;
}
}

View File

@ -4,9 +4,9 @@ import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.AbilityData;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.EntityIdType;
import emu.grasscutter.game.world.Position;
import emu.grasscutter.game.world.World;
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.Int2FloatMap;
@ -22,14 +22,13 @@ public class EntityTeam extends GameEntity {
@Override
public void initAbilities() {
//Load abilities from levelElementAbilities
// Load abilities from levelElementAbilities
var defaultAbilities = GameData.getConfigGlobalCombat().getDefaultAbilities();
if(defaultAbilities.getDefaultTeamAbilities() != null)
for(var ability : defaultAbilities.getDefaultTeamAbilities()) {
AbilityData data = GameData.getAbilityData(ability);
if(data != null)
player.getWorld().getHost().getAbilityManager().addAbilityToEntity(
this, data);
if (defaultAbilities.getDefaultTeamAbilities() != null)
for (var ability : defaultAbilities.getDefaultTeamAbilities()) {
AbilityData data = GameData.getAbilityData(ability);
if (data != null)
player.getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data);
}
}
@ -45,7 +44,7 @@ public class EntityTeam extends GameEntity {
@Override
public Int2FloatMap getFightProperties() {
//TODO
// TODO
return new Int2FloatArrayMap();
}
@ -64,5 +63,4 @@ public class EntityTeam extends GameEntity {
public SceneEntityInfo toProto() {
return null;
}
}

View File

@ -29,12 +29,11 @@ public class EntityWorld extends GameEntity {
@Override
public void initAbilities() {
//Load abilities from levelElementAbilities
for (var ability : GameData.getConfigGlobalCombat()
.getDefaultAbilities().getDefaultMPLevelAbilities()) {
var data = GameData.getAbilityData(ability);
if (data != null) world.getHost()
.getAbilityManager().addAbilityToEntity(this, data);
// Load abilities from levelElementAbilities
for (var ability :
GameData.getConfigGlobalCombat().getDefaultAbilities().getDefaultMPLevelAbilities()) {
var data = GameData.getAbilityData(ability);
if (data != null) world.getHost().getAbilityManager().addAbilityToEntity(this, data);
}
}
@ -45,7 +44,7 @@ public class EntityWorld extends GameEntity {
@Override
public Int2FloatMap getFightProperties() {
//TODO
// TODO
return new Int2FloatArrayMap();
}

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.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
public abstract class GameEntity {
@Getter private final Scene scene;
@ -53,7 +50,11 @@ public abstract class GameEntity {
@Getter private ElementType lastAttackType = ElementType.None;
@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<>();
public GameEntity(Scene scene) {

View File

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

View File

@ -1,32 +1,33 @@
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 it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
public enum CampTargetType implements IntValueEnum{
None (0),
Alliance (1),
Enemy (2),
Self (3),
SelfCamp (4),
All (5),
AllExceptSelf (6),
AllianceIncludeSelf (7);
public enum CampTargetType implements IntValueEnum {
None(0),
Alliance(1),
Enemy(2),
Self(3),
SelfCamp(4),
All(5),
AllExceptSelf(6),
AllianceIncludeSelf(7);
private final int value;
private static final Int2ObjectMap<CampTargetType> map = new Int2ObjectOpenHashMap<>();
private static final Map<String, CampTargetType> stringMap = new HashMap<>();
static {
Stream.of(values()).forEach(e -> {
map.put(e.getValue(), e);
stringMap.put(e.name(), e);
});
Stream.of(values())
.forEach(
e -> {
map.put(e.getValue(), e);
stringMap.put(e.name(), e);
});
}
private CampTargetType(int value) {

View File

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

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.world;
import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.dungeon.DungeonData;
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.Int2ObjectMaps;
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.Collections;
import java.util.Iterator;
import java.util.List;
import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT;
import lombok.Getter;
import lombok.val;
import org.jetbrains.annotations.NotNull;
public class World implements Iterable<Player> {
@Getter private final GameServer server;
@ -154,7 +153,7 @@ public class World implements Iterable<Player> {
// Set player variables
player.setPeerId(this.getNextPeerId());
player.getTeamManager().setEntity(new EntityTeam(player));
//player.getTeamManager().setEntityId(this.getNextEntityId(EntityIdType.TEAM));
// player.getTeamManager().setEntityId(this.getNextEntityId(EntityIdType.TEAM));
// Copy main team to multiplayer team
if (this.isMultiplayer()) {
@ -182,12 +181,13 @@ public class World implements Iterable<Player> {
player.sendPacket(
new PacketDelTeamEntityNotify(
player.getSceneId(),
this.getPlayers().stream()
.map(p ->
p.getTeamManager().getEntity() == null ? 0 :
p.getTeamManager().getEntity().getId()).toList()
)
);
this.getPlayers().stream()
.map(
p ->
p.getTeamManager().getEntity() == null
? 0
: p.getTeamManager().getEntity().getId())
.toList()));
// Deregister
this.getPlayers().remove(player);

View File

@ -1,10 +1,9 @@
package emu.grasscutter.scripts.data;
import java.util.List;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
@ToString
@Setter
public class SceneMonster extends SceneObject {
@ -15,6 +14,6 @@ public class SceneMonster extends SceneObject {
public int title_id;
public int special_name_id;
public String drop_tag;
public List<Integer> affix;
public boolean isElite;
public List<Integer> affix;
public boolean isElite;
}

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.MapType;
import emu.grasscutter.Grasscutter;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import java.io.IOException;
import java.util.*;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
public class LuaTableJacksonSerializer extends JsonSerializer<LuaTable> implements Serializer {
@ -22,10 +21,11 @@ public class LuaTableJacksonSerializer extends JsonSerializer<LuaTable> implemen
public LuaTableJacksonSerializer() {
if (objectMapper == null) {
objectMapper = JsonMapper.builder()
.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.build();
objectMapper =
JsonMapper.builder()
.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.build();
objectMapper
.configOverride(List.class)
.setSetterInfo(JsonSetter.Value.forContentNulls(Nulls.AS_EMPTY));

View File

@ -2,27 +2,27 @@ package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry;
import emu.grasscutter.net.proto.ClientAbilitiesInitFinishCombineNotifyOuterClass.ClientAbilitiesInitFinishCombineNotify;
import emu.grasscutter.net.proto.EntityAbilityInvokeEntryOuterClass.EntityAbilityInvokeEntry;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.utils.Utils;
@Opcodes(PacketOpcodes.ClientAbilitiesInitFinishCombineNotify)
public class HandlerClientAbilitiesInitFinishCombineNotify extends PacketHandler {
@Override
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();
// Call skill end in the player's ability manager.
player.getAbilityManager().onSkillEnd(player);
for(EntityAbilityInvokeEntry entry : notif.getEntityInvokeListList()) {
for (EntityAbilityInvokeEntry entry : notif.getEntityInvokeListList()) {
for (AbilityInvokeEntry ability : entry.getInvokesList()) {
player.getAbilityManager().onAbilityInvoke(ability);
player.getClientAbilityInitFinishHandler().addEntry(ability.getForwardType(), ability);

View File

@ -2,34 +2,38 @@ package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.MonsterAlertChangeNotifyOuterClass.MonsterAlertChangeNotify;
import emu.grasscutter.scripts.constants.EventType;
import emu.grasscutter.scripts.data.ScriptArgs;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.game.GameSession;
@Opcodes(PacketOpcodes.MonsterAlertChangeNotify)
public class HandlerMonsterAlertChangeNotify extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var notify = MonsterAlertChangeNotify.parseFrom(payload);
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var notify = MonsterAlertChangeNotify.parseFrom(payload);
var player = session.getPlayer();
if(notify.getIsAlert() != 0) {
if (notify.getIsAlert() != 0) {
for (var monsterId : notify.getMonsterEntityListList()) {
var monster = (EntityMonster)player.getScene().getEntityById(monsterId);
if(monster != null && monster.getPlayerOnBattle().isEmpty()) {
monster.getScene().getScriptManager().callEvent(new ScriptArgs(monster.getGroupId(), EventType.EVENT_MONSTER_BATTLE, monster.getConfigId()));
var monster = (EntityMonster) player.getScene().getEntityById(monsterId);
if (monster != null && monster.getPlayerOnBattle().isEmpty()) {
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);
}
}
//TODO: Research invisible monsters
}
// TODO: Research invisible monsters
}
}

View File

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

View File

@ -1,23 +1,18 @@
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.PacketOpcodes;
import emu.grasscutter.net.proto.MonsterForceAlertNotifyOuterClass.MonsterForceAlertNotify;
//Sets openState to value
// Sets openState to value
public class PacketMonsterForceAlertNotify extends BasePacket {
public PacketMonsterForceAlertNotify(int monsterId) {
super(PacketOpcodes.MonsterForceAlertNotify);
MonsterForceAlertNotify proto = MonsterForceAlertNotify.newBuilder()
.setMonsterEntityId(monsterId)
.build();
MonsterForceAlertNotify proto =
MonsterForceAlertNotify.newBuilder().setMonsterEntityId(monsterId).build();
this.setData(proto);
}
}

View File

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

View File

@ -13,13 +13,12 @@ import emu.grasscutter.game.world.Position;
import it.unimi.dsi.fastutil.floats.FloatArrayList;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import lombok.val;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;
import lombok.val;
public interface JsonAdapters {
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)) {
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;
import static emu.grasscutter.utils.Utils.nonRegexSplit;
import com.google.gson.*;
import com.google.gson.annotations.SerializedName;
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.Int2ObjectSortedMap;
import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
import lombok.val;
import java.io.IOException;
import java.lang.reflect.*;
import java.nio.charset.StandardCharsets;
@ -19,8 +19,7 @@ import java.util.*;
import java.util.function.Function;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static emu.grasscutter.utils.Utils.nonRegexSplit;
import lombok.val;
// 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.