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 {
@ -232,9 +231,13 @@ public final class ResourceLoader {
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,9 +432,15 @@ 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) -> {
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);
paths2
.filter(Files::isRegularFile)
.filter(path -> path.toString().endsWith(".json"))
.forEach(ResourceLoader::loadTalent);
} 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);
}
}
@ -816,7 +829,8 @@ public final class ResourceLoader {
try {
JsonUtils.loadToList(getResourcePath("Server/MonsterMapping.json"), MonsterMapping.class)
.forEach(entry -> monsterMap.put(entry.getMonsterId(), entry));
} catch (IOException | NullPointerException ignored) {}
} 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);
@ -77,7 +77,8 @@ public class AbilityData {
private void initializeMixins() {
if (abilityMixins != null) {
AbilityLocalIdGenerator generator = new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.MIXIN);
AbilityLocalIdGenerator generator =
new AbilityLocalIdGenerator(ConfigAbilitySubContainerType.MIXIN);
generator.modifierIndex = 0;
generator.configIndex = 0;
@ -88,31 +89,51 @@ public class AbilityData {
private void initializeModifiers() {
if (modifiers == null) return;
var _modifiers = modifiers.entrySet().stream()
.sorted(Map.Entry.comparingByKey()).map(Map.Entry::getValue)
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,27 +1,23 @@
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;
@ -29,13 +25,11 @@ public class AbilityMixinData implements Serializable {
public List<String> getModifierNames() {
if (modifierName.isJsonArray()) {
java.lang.reflect.Type listType = (new TypeToken<List<String>>() {
}).getType();
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,7 +1,6 @@
package emu.grasscutter.data.binout.config;
import java.util.List;
import lombok.Data;
@Data

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 {

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")

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;
@ -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,17 +94,21 @@ public final class AbilityManager extends BasePlayerManager {
}
}
public void executeAction(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
public void executeAction(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
AbilityActionHandler handler = actionHandlers.get(action.type);
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(() -> {
eventExecutor.submit(
() -> {
if (!handler.execute(ability, action, abilityData, target)) {
Grasscutter.getLogger().debug("Execute ability action failed {} at {}", action.type, ability);
Grasscutter.getLogger()
.debug("Execute ability action failed {} at {}", action.type, ability);
}
});
}
@ -105,33 +117,58 @@ public final class AbilityManager extends BasePlayerManager {
AbilityMixinHandler handler = mixinHandlers.get(mixinData.type);
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(() -> {
eventExecutor.submit(
() -> {
if (!handler.execute(ability, mixinData, abilityData)) {
Grasscutter.getLogger().error("exec ability action failed {} at {}", mixinData.type, ability);
Grasscutter.getLogger()
.error("exec ability action failed {} at {}", mixinData.type, ability);
}
});
}
public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception {
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 -> {}
}
@ -168,16 +206,23 @@ public final class AbilityManager extends BasePlayerManager {
// 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;
}
@ -197,11 +242,17 @@ public final class AbilityManager extends BasePlayerManager {
}
}
Grasscutter.getLogger().trace("Action or mixin not found: local_id {} ability {} actions to ids {}", head.getLocalId(), ability.getData().abilityName, ability.getData().localIdToAction.toString());
Grasscutter.getLogger()
.trace(
"Action or mixin not found: local_id {} ability {} actions to ids {}",
head.getLocalId(),
ability.getData().abilityName,
ability.getData().localIdToAction.toString());
}
/**
* Invoked when a player starts a skill.
*
* @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) {
@ -264,7 +316,12 @@ public final class AbilityManager extends BasePlayerManager {
}
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 {
@ -315,8 +372,8 @@ public final class AbilityManager extends BasePlayerManager {
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
@ -339,7 +396,8 @@ public final class AbilityManager extends BasePlayerManager {
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();
}
}
@ -369,24 +427,43 @@ public final class AbilityManager extends BasePlayerManager {
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()];
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()));
Grasscutter.getLogger()
.trace(
"Removed on entity {} modifier id {}: {}",
invoke.getEntityId(),
head.getInstancedModifierId(),
entity.getInstancedModifiers().get(head.getInstancedModifierId()));
// TODO: Add debug log
@ -397,15 +474,14 @@ public final class AbilityManager extends BasePlayerManager {
}
}
private void handleMixinCostStamina(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
private void handleMixinCostStamina(AbilityInvokeEntry invoke)
throws InvalidProtocolBufferException {}
}
private void handleGenerateElemBall(AbilityInvokeEntry invoke)
throws InvalidProtocolBufferException {}
private void handleGenerateElemBall(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
}
private void handleGlobalFloatValue(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
private void handleGlobalFloatValue(AbilityInvokeEntry invoke)
throws InvalidProtocolBufferException {
var entity = this.player.getScene().getEntityById(invoke.getEntityId());
if (entity == null) return;
@ -413,8 +489,7 @@ public final class AbilityManager extends BasePlayerManager {
if (entry == null || !entry.hasFloatValue()) return;
String key = null;
if(entry.getKey().hasStr())
key = entry.getKey().getStr();
if (entry.getKey().hasStr()) key = entry.getKey().getStr();
else if (entry.getKey().hasHash())
key = GameData.getAbilityHashes().get(entry.getKey().getHash());
@ -423,7 +498,8 @@ public final class AbilityManager extends BasePlayerManager {
if (key.startsWith("SGV_")) return; // Server does not allow to change this variables I think
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());
@ -433,15 +509,14 @@ public final class AbilityManager extends BasePlayerManager {
}
}
private void invokeAction(AbilityModifierAction action, GameEntity target, GameEntity sourceEntity) {
private void invokeAction(
AbilityModifierAction action, GameEntity target, GameEntity sourceEntity) {}
}
private void handleModifierDurabilityChange(AbilityInvokeEntry invoke)
throws InvalidProtocolBufferException {}
private void handleModifierDurabilityChange(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
}
private void handleAddNewAbility(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
private void handleAddNewAbility(AbilityInvokeEntry invoke)
throws InvalidProtocolBufferException {
var entity = this.player.getScene().getEntityById(invoke.getEntityId());
if (entity == null) {
@ -461,13 +536,16 @@ public final class AbilityManager extends BasePlayerManager {
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) {

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,18 +1,15 @@
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) {
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);
@ -20,7 +17,8 @@ public class ActionApplyModifier extends AbilityActionHandler {
// }
//
// if(modifierData.stacking != null && modifierData.stacking.compareTo("Unique") == 0 &&
// ability.getModifiers().values().stream().filter(m -> m.getData().equals(modifierData)).count() != 0) {
// ability.getModifiers().values().stream().filter(m ->
// m.getData().equals(modifierData)).count() != 0) {
// return true;
// }
//

View File

@ -2,21 +2,21 @@ 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) {
public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
if (!action.byServer) {
Grasscutter.getLogger().debug("Action not executed by server");
@ -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
if (owner.getEntityController() != null) {
owner.getEntityController().onClientExecuteRequest(owner, action.param1, action.param2, action.param3);
owner
.getEntityController()
.onClientExecuteRequest(owner, action.param1, action.param2, action.param3);
return true;
}

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
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,7 +8,8 @@ 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) {
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,21 +10,20 @@ 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) {
public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
// TODO:
var entity = target;
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) {

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;

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,9 +7,8 @@ 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 lombok.val;
import java.util.List;
import lombok.val;
public class KillMonsterCountInTimeIncChallengeFactoryHandler implements ChallengeFactoryHandler {
@Override
@ -18,16 +17,27 @@ public class KillMonsterCountInTimeIncChallengeFactoryHandler implements Challe
}
@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,
scene,
realGroup,
challengeId, // Id
challengeIndex, // Index
List.of(monsterCount, timeLimit, timeInc),
timeLimit, // Limit
monsterCount, // Goal
List.of(new KillMonsterCountTrigger(), new InTimeTrigger(), new KillMonsterTimeIncTrigger(timeInc))
);
List.of(
new KillMonsterCountTrigger(),
new InTimeTrigger(),
new KillMonsterTimeIncTrigger(timeInc)));
}
}

View File

@ -14,7 +14,8 @@ public class KillMonsterTimeIncTrigger extends ChallengeTrigger{
@Override
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) {
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();
@ -76,9 +81,7 @@ public class EntityClientGadget extends EntityBaseGadget {
private void addConfigAbility(ConfigAbilityData abilityData) {
var data = GameData.getAbilityData(abilityData.getAbilityName());
if (data != null)
owner.getAbilityManager().addAbilityToEntity(
this, data);
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);
@ -121,8 +129,8 @@ public class EntityGadget extends EntityBaseGadget {
private void addConfigAbility(ConfigAbilityData abilityData) {
var data = GameData.getAbilityData(abilityData.getAbilityName());
if(data != null) this.getScene().getWorld().getHost()
.getAbilityManager().addAbilityToEntity(this, data);
if (data != null)
this.getScene().getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data);
}
@Override
@ -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,7 +317,8 @@ public class EntityGadget extends EntityBaseGadget {
addAllFightPropsToEntityInfo(entityInfo);
}
var gadgetInfo = SceneGadgetInfo.newBuilder()
var gadgetInfo =
SceneGadgetInfo.newBuilder()
.setGadgetId(this.getGadgetId())
.setGroupId(this.getGroupId())
.setConfigId(this.getConfigId())

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;
@ -19,11 +18,11 @@ public class EntityScene extends GameEntity {
@Override
public void initAbilities() {
// Load abilities from levelElementAbilities
for(var ability : GameData.getConfigGlobalCombat().getDefaultAbilities().getLevelElementAbilities()) {
for (var ability :
GameData.getConfigGlobalCombat().getDefaultAbilities().getLevelElementAbilities()) {
AbilityData data = GameData.getAbilityData(ability);
if (data != null)
getScene().getWorld().getHost().getAbilityManager().addAbilityToEntity(
this, data);
getScene().getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data);
}
}
@ -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;
@ -28,8 +28,7 @@ public class EntityTeam extends GameEntity {
for (var ability : defaultAbilities.getDefaultTeamAbilities()) {
AbilityData data = GameData.getAbilityData(ability);
if (data != null)
player.getWorld().getHost().getAbilityManager().addAbilityToEntity(
this, data);
player.getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data);
}
}
@ -64,5 +63,4 @@ public class EntityTeam extends GameEntity {
public SceneEntityInfo toProto() {
return null;
}
}

View File

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

View File

@ -23,15 +23,12 @@ import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import it.unimi.dsi.fastutil.ints.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,12 +1,11 @@
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),
@ -23,7 +22,9 @@ public enum CampTargetType implements IntValueEnum{
private static final Map<String, CampTargetType> stringMap = new HashMap<>();
static {
Stream.of(values()).forEach(e -> {
Stream.of(values())
.forEach(
e -> {
map.put(e.getValue(), e);
stringMap.put(e.name(), e);
});

View File

@ -41,15 +41,14 @@ import emu.grasscutter.server.event.player.PlayerTeleportEvent;
import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.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;
@ -183,11 +182,12 @@ public class World implements Iterable<Player> {
new PacketDelTeamEntityNotify(
player.getSceneId(),
this.getPlayers().stream()
.map(p ->
p.getTeamManager().getEntity() == null ? 0 :
p.getTeamManager().getEntity().getId()).toList()
)
);
.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 {

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,7 +21,8 @@ public class LuaTableJacksonSerializer extends JsonSerializer<LuaTable> implemen
public LuaTableJacksonSerializer() {
if (objectMapper == null) {
objectMapper = JsonMapper.builder()
objectMapper =
JsonMapper.builder()
.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.build();

View File

@ -2,20 +2,20 @@ 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();

View File

@ -2,11 +2,11 @@ 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)
@ -22,7 +22,12 @@ public class HandlerMonsterAlertChangeNotify extends PacketHandler {
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()));
monster
.getScene()
.getScriptManager()
.callEvent(
new ScriptArgs(
monster.getGroupId(), EventType.EVENT_MONSTER_BATTLE, monster.getConfigId()));
}
if (monster != null) monster.getPlayerOnBattle().add(player);
@ -31,5 +36,4 @@ public class HandlerMonsterAlertChangeNotify extends PacketHandler {
// TODO: Research invisible monsters
}
}

View File

@ -1,20 +1,18 @@
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);
ClientAbilitiesInitFinishCombineNotify proto = ClientAbilitiesInitFinishCombineNotify.newBuilder()
.addAllEntityInvokeList(entries)
.build();
ClientAbilitiesInitFinishCombineNotify proto =
ClientAbilitiesInitFinishCombineNotify.newBuilder().addAllEntityInvokeList(entries).build();
this.setData(proto);
}

View File

@ -1,8 +1,5 @@
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;
@ -13,11 +10,9 @@ 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,20 +1,20 @@
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);
SceneEntityUpdateNotify.Builder proto = SceneEntityUpdateNotify.newBuilder()
SceneEntityUpdateNotify.Builder proto =
SceneEntityUpdateNotify.newBuilder()
.setAppearType(VisionType.VISION_TYPE_BORN)
.addEntityList(entity.toProto());
@ -24,7 +24,8 @@ public class PacketSceneEntityUpdateNotify extends BasePacket {
public PacketSceneEntityUpdateNotify(GameEntity entity, VisionType vision, int param) {
super(PacketOpcodes.SceneEntityUpdateNotify, true);
SceneEntityUpdateNotify.Builder proto = SceneEntityUpdateNotify.newBuilder()
SceneEntityUpdateNotify.Builder proto =
SceneEntityUpdateNotify.newBuilder()
.setAppearType(vision)
.setParam(param)
.addEntityList(entity.toProto());
@ -36,11 +37,12 @@ public class PacketSceneEntityUpdateNotify extends BasePacket {
this(player.getTeamManager().getCurrentAvatarEntity());
}
public PacketSceneEntityUpdateNotify(Collection<? extends GameEntity> entities, VisionType visionType) {
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()));

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.