mirror of
https://github.com/Anime-Game-Servers/Grasscutter-Quests.git
synced 2024-11-26 22:10:26 +00:00
[Refactor/Lua] Allow Lua serializers to set private fields without setters in objects
* This is done by using reflection apis to use setAccessible to true for the fields * This allows removing setters from read only lua based objects
This commit is contained in:
parent
b28e4c65eb
commit
08cc307c1d
@ -50,7 +50,7 @@ public class TowerLevelData extends GameResource {
|
||||
@ToString
|
||||
public static class TowerChallengeCond {
|
||||
TowerCondType towerCondType;
|
||||
@SerializedName(value = "argumentListFirstHalf", alternate = {"OECDJKGBNFE"})
|
||||
@SerializedName(value = "argumentListFirstHalf", alternate = {"argument_list_upper","OECDJKGBNFE"})
|
||||
List<Integer> argumentListFirstHalf;
|
||||
@SerializedName(value = "argumentListSecondHalf", alternate = {"argumentList"})
|
||||
List<Integer> argumentListSecondHalf;
|
||||
|
@ -366,7 +366,7 @@ public final class AbilityManager extends BasePlayerManager {
|
||||
instancedAbilityData = GameData.getAbilityData(modChange.getParentAbilityName().getStr());
|
||||
}
|
||||
|
||||
if(instancedAbilityData == null) {
|
||||
if(instancedAbilityData == null || instancedAbilityData.modifiers == null) {
|
||||
logger.info("No ability found");
|
||||
return; //TODO: Display error message
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class WorldChallenge {
|
||||
* Get the monster group id spawned by the challenge
|
||||
*/
|
||||
public int getGroupId(){
|
||||
return Optional.ofNullable(getGroup()).map(g -> g.id).orElse(0);
|
||||
return group!=null ? group.getId() : 0;
|
||||
}
|
||||
|
||||
|
||||
@ -171,7 +171,9 @@ public class WorldChallenge {
|
||||
* @param monster Monster that belongs to the group spawned by the challenge
|
||||
*/
|
||||
public void onMonsterDeath(EntityMonster monster){
|
||||
if(!inProgress() || monster.getGroupId() != getGroupId()) return;
|
||||
if(!inProgress() || monster.getGroupId() != getGroupId())
|
||||
return;
|
||||
|
||||
|
||||
Optional.ofNullable(this.challengeTriggers.get(KillMonsterTrigger.class))
|
||||
.ifPresent(t -> t.onMonsterDeath(this, monster));
|
||||
@ -182,7 +184,7 @@ public class WorldChallenge {
|
||||
|
||||
public void onGroupTriggerDeath(SceneTrigger trigger){
|
||||
if(!inProgress()) return;
|
||||
if(Optional.ofNullable(trigger.getCurrentGroup()).filter(g -> g.id == getGroupId()).isEmpty()) return;
|
||||
if(Optional.ofNullable(trigger.getCurrentGroup()).filter(g -> g.getId() == getGroupId()).isEmpty()) return;
|
||||
|
||||
Optional.ofNullable(this.challengeTriggers.get(TriggerGroupTriggerTrigger.class))
|
||||
.ifPresent(t -> t.onGroupTrigger(this, trigger));
|
||||
|
@ -26,7 +26,7 @@ public class KillCountGuardTimeChallengeFactoryHandler extends ChallengeFactoryH
|
||||
@Override
|
||||
public WorldChallenge build(ChallengeType type, ChallengeInfo header, List<Integer> params, ChallengeScoreInfo scoreInfo, Scene scene, SceneGroup group) {
|
||||
val realGroup = scene.getScriptManager().getGroupById(params.get(1));
|
||||
int goal = realGroup == null || realGroup.monsters == null ? 0 : realGroup.monsters.size();
|
||||
int goal = realGroup == null || realGroup.getMonsters() == null ? 0 : realGroup.getMonsters().size();
|
||||
|
||||
return new WorldChallenge(
|
||||
scene, realGroup,
|
||||
|
@ -138,7 +138,7 @@ public class EntityGadget extends EntityBaseGadget implements ConfigAbilityDataA
|
||||
this.state = state;
|
||||
//Cache the gadget state
|
||||
if(metaGadget != null && metaGadget.group != null) {
|
||||
var instance = getScene().getScriptManager().getCachedGroupInstanceById(metaGadget.group.id);
|
||||
var instance = getScene().getScriptManager().getCachedGroupInstanceById(metaGadget.group.getId());
|
||||
if(instance != null) instance.cacheGadgetState(metaGadget, state);
|
||||
}
|
||||
}
|
||||
|
@ -102,8 +102,8 @@ public class EntityMonster extends GameEntity implements StringAbilityEntity {
|
||||
@Nullable
|
||||
private List<MonsterAffixData> getAffixes(@Nullable SceneGroup group){
|
||||
List<Integer> affixes = null;
|
||||
if(group != null) {
|
||||
SceneMonster monster = group.monsters.get(getConfigId());
|
||||
if(group != null && group.getMonsters() != null) {
|
||||
SceneMonster monster = group.getMonsters().get(getConfigId());
|
||||
if(monster != null) affixes = monster.affix;
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ public class EntityMonster extends GameEntity implements StringAbilityEntity {
|
||||
ArrayList<String> abilityNames = new ArrayList<>();
|
||||
val defaultAbilities = GameData.getConfigGlobalCombat().getDefaultAbilities();
|
||||
//Affix abilities
|
||||
Optional<SceneGroup> optionalGroup = getScene().getLoadedGroups().stream().filter(g -> g.id == getGroupId()).findAny();
|
||||
Optional<SceneGroup> optionalGroup = getScene().getLoadedGroups().stream().filter(g -> g.getId() == getGroupId()).findAny();
|
||||
List<MonsterAffixData> affixes = getAffixes(optionalGroup.orElse(null));
|
||||
|
||||
// first add pre add affix abilities
|
||||
@ -157,7 +157,7 @@ public class EntityMonster extends GameEntity implements StringAbilityEntity {
|
||||
}
|
||||
|
||||
optionalGroup.ifPresent(group -> {
|
||||
val monster = group.monsters.get(getConfigId());
|
||||
val monster = group.getMonsters().get(getConfigId());
|
||||
if(monster != null && monster.isElite) {
|
||||
abilityNames.add(defaultAbilities.getMonterEliteAbilityName());
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class EntityNPC extends GameEntity {
|
||||
super(scene);
|
||||
this.id = getScene().getWorld().getNextEntityId(EntityIdType.NPC);
|
||||
setConfigId(metaNPC.config_id);
|
||||
setGroupId(metaNPC.group.id);
|
||||
setGroupId(metaNPC.group.getId());
|
||||
setBlockId(blockId);
|
||||
this.suiteId = suiteId;
|
||||
this.position = metaNPC.pos.clone();
|
||||
|
@ -24,7 +24,7 @@ public class EntityRegion extends GameEntity{
|
||||
public EntityRegion(Scene scene, SceneRegion region) {
|
||||
super(scene);
|
||||
this.id = getScene().getWorld().getNextEntityId(EntityIdType.REGION);
|
||||
setGroupId(region.group.id);
|
||||
setGroupId(region.group.getId());
|
||||
setBlockId(region.group.block_id);
|
||||
setConfigId(region.config_id);
|
||||
this.position = region.pos.clone();
|
||||
|
@ -29,7 +29,16 @@ public class BossChestInteractHandler implements ChestInteractHandler{
|
||||
if (blossomRewards) return true;
|
||||
|
||||
val worldDataManager = chest.getGadget().getScene().getWorld().getServer().getWorldDataSystem();
|
||||
val monster = chest.getGadget().getMetaGadget().group.monsters.get(chest.getGadget().getMetaGadget().boss_chest.monster_config_id);
|
||||
val chestMetaGadget = chest.getGadget().getMetaGadget();
|
||||
val monsterCfgId = chestMetaGadget.boss_chest.monster_config_id;
|
||||
val groupMonsters = chestMetaGadget.getGroup().getMonsters();
|
||||
if(groupMonsters == null){
|
||||
Grasscutter.getLogger().warn("group monsters are null {} unable to get cfg id {}",
|
||||
chestMetaGadget.getGroup().getId(), monsterCfgId);
|
||||
return false;
|
||||
}
|
||||
val monster = groupMonsters.get(monsterCfgId);
|
||||
|
||||
val reward = worldDataManager.getRewardByBossId(monster.monster_id);
|
||||
|
||||
if (reward == null) {
|
||||
|
@ -53,7 +53,7 @@ public class BlossomSchedule implements BaseBlossomROSData {
|
||||
.orElse(3);
|
||||
|
||||
return Optional.ofNullable(SceneGroup.of(groupsData.getNewGroupId()).load(sceneId))
|
||||
.map(group -> group.gadgets)
|
||||
.map(SceneGroup::getGadgets)
|
||||
.map(Map::values)
|
||||
.stream().flatMap(Collection::stream)
|
||||
.filter(gadget -> gadget.gadget_id == baseData.getRefreshType().getGadgetId())
|
||||
|
@ -621,13 +621,13 @@ public class Scene {
|
||||
val visible = this.players.stream().map(this::getPlayerActiveGroups)
|
||||
.flatMap(Collection::stream).collect(Collectors.toSet());
|
||||
|
||||
this.loadedGroups.stream().filter(group -> !visible.contains(group.id) && !group.dynamic_load)
|
||||
.forEach(group -> unloadGroup(this.scriptManager.getBlocks().get(group.block_id), group.id));
|
||||
this.loadedGroups.stream().filter(group -> !visible.contains(group.getId()) && !group.isDynamic_load())
|
||||
.forEach(group -> unloadGroup(this.scriptManager.getBlocks().get(group.block_id), group.getId()));
|
||||
|
||||
val toLoad = visible.stream().filter(g -> this.loadedGroups.stream().noneMatch(gr -> gr.id == g))
|
||||
val toLoad = visible.stream().filter(g -> this.loadedGroups.stream().noneMatch(gr -> gr.getId() == g))
|
||||
.filter(g -> !this.replacedGroup.contains(g)).map(g -> Optional.ofNullable(this.scriptManager.getBlocks())
|
||||
.stream().map(Map::values).flatMap(Collection::stream).peek(this::loadBlock).map(b -> b.groups.get(g))
|
||||
.filter(Objects::nonNull).filter(group -> !group.dynamic_load).findFirst().orElse(null))
|
||||
.filter(Objects::nonNull).filter(group -> !group.isDynamic_load()).findFirst().orElse(null))
|
||||
.filter(Objects::nonNull).toList();
|
||||
|
||||
onLoadGroup(toLoad);
|
||||
@ -649,7 +649,7 @@ public class Scene {
|
||||
public int loadDynamicGroup(int groupId) {
|
||||
return this.scriptManager.getGroupInstanceById(groupId) != null || this.replacedGroup.contains(groupId) ? -1 :
|
||||
Optional.ofNullable(this.scriptManager.getGroupById(groupId))
|
||||
.map(group -> group.init_config).map(config -> config.suite).orElse(-1);
|
||||
.map(SceneGroup::getInit_config).map(config -> config.suite).orElse(-1);
|
||||
}
|
||||
|
||||
public boolean unregisterDynamicGroup(int groupId){
|
||||
@ -660,7 +660,7 @@ public class Scene {
|
||||
unloadGroup(block, groupId);
|
||||
|
||||
val toRestore = Optional.ofNullable(block.groups.get(groupId)).map(g -> g.getReplaceableGroups(block.groups.values()))
|
||||
.stream().flatMap(List::stream).filter(replacement -> this.replacedGroup.remove(replacement.id)).toList();
|
||||
.stream().flatMap(List::stream).filter(replacement -> this.replacedGroup.remove(replacement.getId())).toList();
|
||||
if (!toRestore.isEmpty()) {
|
||||
onLoadGroup(toRestore);
|
||||
Grasscutter.getLogger().info("Unregistered group: {}", groupId);
|
||||
@ -676,8 +676,8 @@ public class Scene {
|
||||
// Create the graph
|
||||
val groupList = new HashSet<Integer>();
|
||||
val nodes = GameData.getGroupReplacements().values().stream()
|
||||
.filter(replacement -> this.loadedGroups.stream().filter(group -> group.dynamic_load)
|
||||
.anyMatch(group -> group.id == replacement.id)) // dynamic groups
|
||||
.filter(replacement -> this.loadedGroups.stream().filter(group -> group.isDynamic_load())
|
||||
.anyMatch(group -> group.getId() == replacement.id)) // dynamic groups
|
||||
// .filter(replacement -> getReplacedGroup().stream().noneMatch(replacement.replace_groups::contains))
|
||||
.peek(replacement -> Grasscutter.getLogger().info("Graph ordering replacement {}", replacement))
|
||||
.peek(replacement -> groupList.add(replacement.id))
|
||||
@ -690,21 +690,21 @@ public class Scene {
|
||||
// Now we can start unloading and loading groups :D
|
||||
Optional.ofNullable(KahnsSort.doSort(new KahnsSort.Graph(
|
||||
nodes.stream().toList(), groupList.stream().toList()))).stream().flatMap(List::stream)
|
||||
.map(groupId -> this.loadedGroups.stream().filter(g -> g.id == groupId).findFirst()) // isGroupJoinReplacement
|
||||
.map(groupId -> this.loadedGroups.stream().filter(g -> g.getId() == groupId).findFirst()) // isGroupJoinReplacement
|
||||
.filter(Optional::isPresent).map(Optional::get)
|
||||
.map(targetGroup -> targetGroup.getReplaceableGroups(this.loadedGroups))
|
||||
.flatMap(List::stream)
|
||||
.filter(replacement -> !this.replacedGroup.contains(replacement.id))
|
||||
.peek(replacement -> this.replacedGroup.add(replacement.id))
|
||||
.peek(replacement -> Grasscutter.getLogger().info("Graph ordering: unloaded {}", replacement.id))
|
||||
.filter(replacement -> !this.replacedGroup.contains(replacement.getId()))
|
||||
.peek(replacement -> this.replacedGroup.add(replacement.getId()))
|
||||
.peek(replacement -> Grasscutter.getLogger().info("Graph ordering: unloaded {}", replacement.getId()))
|
||||
.peek(replacement -> Grasscutter.getLogger().info("Replaced groups: {}", this.replacedGroup))
|
||||
.forEach(replacement -> unloadGroup(this.scriptManager.getBlocks().get(replacement.block_id), replacement.id));
|
||||
.forEach(replacement -> unloadGroup(this.scriptManager.getBlocks().get(replacement.block_id), replacement.getId()));
|
||||
}
|
||||
|
||||
public void loadTriggerFromGroup(SceneGroup group, String triggerName) {
|
||||
//Load triggers and regions
|
||||
this.scriptManager.registerTrigger(group.triggers.values().stream().filter(p -> p.getName().contains(triggerName)).toList());
|
||||
group.regions.values().stream().filter(q -> q.config_id == Integer.parseInt(triggerName.substring(13)))
|
||||
this.scriptManager.registerTrigger(group.getTriggers().values().stream().filter(p -> p.getName().contains(triggerName)).toList());
|
||||
group.getRegions().values().stream().filter(q -> q.config_id == Integer.parseInt(triggerName.substring(13)))
|
||||
.map(region -> new EntityRegion(this, region)).forEach(this.scriptManager::registerRegion);
|
||||
}
|
||||
|
||||
@ -725,16 +725,16 @@ public class Scene {
|
||||
// TODO
|
||||
val entities = new ArrayList<GameEntity>();
|
||||
val entitiesBorn = new ArrayList<GameEntity>();
|
||||
groups.stream().filter(group -> !this.loadedGroups.contains(group)).filter(group -> group.init_config != null)
|
||||
.map(group -> Optional.ofNullable(this.scriptManager.getCachedGroupInstanceById(group.id))
|
||||
groups.stream().filter(group -> !this.loadedGroups.contains(group)).filter(group -> group.getInit_config() != null)
|
||||
.map(group -> Optional.ofNullable(this.scriptManager.getCachedGroupInstanceById(group.getId()))
|
||||
.stream().peek(cachedInstance -> cachedInstance.setLuaGroup(group))
|
||||
.findFirst().orElse(this.scriptManager.getGroupInstanceById(group.id)))
|
||||
.findFirst().orElse(this.scriptManager.getGroupInstanceById(group.getId())))
|
||||
.peek(gi -> this.loadedGroups.add(gi.getLuaGroup())) // Load suites
|
||||
.forEach(gi -> this.scriptManager.refreshGroup(gi, 0, false, entitiesBorn)); //This is what the official server does
|
||||
|
||||
this.scriptManager.meetEntities(entities);
|
||||
this.scriptManager.addEntities(entitiesBorn);
|
||||
groups.forEach(g -> this.scriptManager.callEvent(new ScriptArgs(g.id, EventType.EVENT_GROUP_LOAD, g.id)));
|
||||
groups.forEach(g -> this.scriptManager.callEvent(new ScriptArgs(g.getId(), EventType.EVENT_GROUP_LOAD, g.getId())));
|
||||
Grasscutter.getLogger().info("Scene {} loaded {} group(s)", getId(), groups.size());
|
||||
}
|
||||
|
||||
@ -748,11 +748,16 @@ public class Scene {
|
||||
removeEntities(this.entities.values().stream().filter(Objects::nonNull).filter(e ->
|
||||
e.getBlockId() == block.id && e.getGroupId() == groupId).toList(), VisionType.VISION_TYPE_REMOVE);
|
||||
|
||||
val group = block.groups.get(groupId);
|
||||
Optional.ofNullable(group.triggers).map(Map::values).stream().flatMap(Collection::stream)
|
||||
.forEach(this.scriptManager::deregisterTrigger);
|
||||
Optional.ofNullable(group.regions).map(Map::values).stream().flatMap(Collection::stream)
|
||||
.forEach(this.scriptManager::deregisterRegion);
|
||||
|
||||
SceneGroup group = block.groups.get(groupId);
|
||||
val triggers = group.getTriggers();
|
||||
if (triggers != null) {
|
||||
triggers.values().forEach(getScriptManager()::deregisterTrigger);
|
||||
}
|
||||
val regions = group.getRegions();
|
||||
if (regions != null) {
|
||||
regions.values().forEach(getScriptManager()::deregisterRegion);
|
||||
}
|
||||
|
||||
Optional.ofNullable(this.scriptManager.getLoadedGroupSetPerBlock().get(block.id)).ifPresent(s -> s.remove(group));
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class SceneGroupInstance {
|
||||
|
||||
public SceneGroupInstance(SceneGroup group, Player owner) {
|
||||
this.luaGroup = group;
|
||||
this.groupId = group.id;
|
||||
this.groupId = group.getId();
|
||||
this.targetSuiteId = 0;
|
||||
this.activeSuiteId = 0;
|
||||
this.lastTimeRefreshed = 0;
|
||||
@ -58,7 +58,7 @@ public class SceneGroupInstance {
|
||||
|
||||
public void setLuaGroup(SceneGroup group) {
|
||||
this.luaGroup = group;
|
||||
this.groupId = group.id;
|
||||
this.groupId = group.getId();
|
||||
}
|
||||
|
||||
public boolean isCached() {
|
||||
|
@ -100,11 +100,11 @@ public class WorldDataSystem extends BaseGameSystem {
|
||||
var sceneId = imd.getCityData().getSceneId();
|
||||
var group = getInvestigationGroup(sceneId, groupId);
|
||||
|
||||
if (group == null || group.monsters == null) {
|
||||
if (group == null || group.getMonsters() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var monster = group.monsters.values().stream()
|
||||
var monster = group.getMonsters().values().stream()
|
||||
.filter(x -> x.monster_id == monsterId)
|
||||
.findFirst();
|
||||
if (monster.isEmpty()) {
|
||||
|
@ -50,6 +50,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static emu.grasscutter.scripts.constants.EventType.*;
|
||||
import static emu.grasscutter.scripts.data.SceneTrigger.INF_TRIGGERS;
|
||||
|
||||
public class SceneScriptManager {
|
||||
private static final Logger logger = Loggers.getScriptSystem();
|
||||
@ -154,14 +155,14 @@ public class SceneScriptManager {
|
||||
}
|
||||
|
||||
public void resetTriggersForGroupSuite(SceneGroup group, int suiteIndex) {
|
||||
logger.debug("reset triggers for group {} suite {}", group.id, suiteIndex);
|
||||
logger.debug("reset triggers for group {} suite {}", group.getId(), suiteIndex);
|
||||
var suite = group.getSuiteByIndex(suiteIndex);
|
||||
if (suite == null) {
|
||||
logger.warn("Trying to load null suite Triggers for group {} with suiteindex {}", group.id, suiteIndex);
|
||||
logger.warn("Trying to load null suite Triggers for group {} with suiteindex {}", group.getId(), suiteIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
var groupSceneTriggers = triggersByGroupScene.get(group.id+"_"+suiteIndex);
|
||||
var groupSceneTriggers = triggersByGroupScene.get(group.getId()+"_"+suiteIndex);
|
||||
if(groupSceneTriggers == null){
|
||||
groupSceneTriggers = new HashSet<>();
|
||||
}
|
||||
@ -181,14 +182,14 @@ public class SceneScriptManager {
|
||||
.add(trigger);*/
|
||||
}
|
||||
}
|
||||
triggersByGroupScene.put(group.id+"_"+suiteIndex, groupSceneTriggers);
|
||||
triggersByGroupScene.put(group.getId()+"_"+suiteIndex, groupSceneTriggers);
|
||||
}
|
||||
|
||||
public void refreshGroup(int groupId, int suiteIndex, boolean excludePrevSuite) {
|
||||
refreshGroup(getGroupInstanceById(groupId));
|
||||
}
|
||||
public void refreshGroup(SceneGroupInstance groupInstance) {
|
||||
if(groupInstance == null || groupInstance.getLuaGroup().suites==null){
|
||||
if(groupInstance == null || groupInstance.getLuaGroup().getSuites()==null){
|
||||
return;
|
||||
}
|
||||
//for (int i = 1; i<= group.suites.size();i++){
|
||||
@ -217,7 +218,7 @@ public class SceneScriptManager {
|
||||
|
||||
var suiteData = group.getSuiteByIndex(suiteIndex);
|
||||
if (suiteData == null) {
|
||||
logger.warn("Group {} suite {} not found", group.id, suiteIndex);
|
||||
logger.warn("Group {} suite {} not found", group.getId(), suiteIndex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -235,7 +236,7 @@ public class SceneScriptManager {
|
||||
|
||||
if(waitForOne && (groupInstance.getTargetSuiteId() == 0 || prevSuiteIndex != groupInstance.getTargetSuiteId())) {
|
||||
groupInstance.setTargetSuiteId(suiteIndex);
|
||||
logger.debug("Group {} suite {} wating one more refresh", group.id, suiteIndex);
|
||||
logger.debug("Group {} suite {} wating one more refresh", group.getId(), suiteIndex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -250,7 +251,7 @@ public class SceneScriptManager {
|
||||
}
|
||||
|
||||
//Refesh variables here
|
||||
group.variables.forEach(variable -> {
|
||||
group.getVariables().forEach(variable -> {
|
||||
if(!variable.no_refresh)
|
||||
groupInstance.getCachedVariables().put(variable.name, variable.value);
|
||||
});
|
||||
@ -289,19 +290,25 @@ public class SceneScriptManager {
|
||||
}
|
||||
|
||||
public boolean refreshGroupMonster(int groupId) {
|
||||
var groupInstance = getGroupInstanceById(groupId);
|
||||
val groupInstance = getGroupInstanceById(groupId);
|
||||
if (groupInstance == null) {
|
||||
logger.warn("trying to refesh monster group in unloaded and uncached group {} in scene {}", groupId, getScene().getId());
|
||||
logger.warn("trying to refresh monster group in unloaded and uncached group {} in scene {}", groupId, getScene().getId());
|
||||
return false;
|
||||
}
|
||||
|
||||
var group = groupInstance.getLuaGroup();
|
||||
var monstersToSpawn = group.monsters.values().stream()
|
||||
val group = groupInstance.getLuaGroup();
|
||||
val monsters = group.getMonsters();
|
||||
|
||||
if (monsters == null){
|
||||
logger.warn("trying to refresh monster group without monsters {} in scene {}", groupId, getScene().getId());
|
||||
return false;
|
||||
}
|
||||
val monstersToSpawn = monsters.values().stream()
|
||||
.filter(m -> {
|
||||
var entity = scene.getEntityByConfigId(m.config_id);
|
||||
return (entity == null || entity.getGroupId()!=group.id);/*&& !groupInstance.getDeadEntities().contains(entity); */ //TODO: Investigate the usage of deadEntities
|
||||
return (entity == null || entity.getGroupId()!=group.getId());/*&& !groupInstance.getDeadEntities().contains(entity); */ //TODO: Investigate the usage of deadEntities
|
||||
})
|
||||
.map(mob -> createMonster(group.id, group.block_id, mob))
|
||||
.map(mob -> createMonster(group.getId(), group.block_id, mob))
|
||||
.toList();//TODO check if it interferes with bigworld or anything else
|
||||
this.addEntities(monstersToSpawn);
|
||||
|
||||
@ -435,44 +442,49 @@ public class SceneScriptManager {
|
||||
return;
|
||||
}
|
||||
logger.debug("Loading block grid " + block.id);
|
||||
block.groups.values().stream().filter(g -> !g.dynamic_load).forEach(group -> {
|
||||
block.groups.values().stream().filter(g -> !g.isDynamic_load()).forEach(group -> {
|
||||
group.load(this.scene.getId());
|
||||
|
||||
//Add all entities here
|
||||
Set<Integer> vision_levels = new HashSet<>();
|
||||
|
||||
if (group.monsters != null) {
|
||||
group.monsters.values().forEach(m -> {
|
||||
addGridPositionToMap(groupPositions.get(m.vision_level), group.id, m.vision_level, m.pos);
|
||||
val monsters = group.getMonsters();
|
||||
if (monsters != null) {
|
||||
monsters.values().forEach(m -> {
|
||||
addGridPositionToMap(groupPositions.get(m.vision_level), group.getId(), m.vision_level, m.pos);
|
||||
vision_levels.add(m.vision_level);
|
||||
});
|
||||
} else {
|
||||
logger.error("group.monsters null for group {}", group.id);
|
||||
logger.error("group.monsters null for group {}", group.getId());
|
||||
}
|
||||
if (group.gadgets != null) {
|
||||
group.gadgets.values().forEach(g -> {
|
||||
val gadgets = group.getGadgets();
|
||||
if (gadgets != null) {
|
||||
gadgets.values().forEach(g -> {
|
||||
int vision_level = Math.max(getGadgetVisionLevel(g.gadget_id), g.vision_level);
|
||||
addGridPositionToMap(groupPositions.get(vision_level), group.id, vision_level, g.pos);
|
||||
addGridPositionToMap(groupPositions.get(vision_level), group.getId(), vision_level, g.pos);
|
||||
vision_levels.add(vision_level);
|
||||
});
|
||||
} else {
|
||||
logger.error("group.gadgets null for group {}", group.id);
|
||||
logger.error("group.gadgets null for group {}", group.getId());
|
||||
}
|
||||
|
||||
if (group.npcs != null) {
|
||||
group.npcs.values().forEach(n -> addGridPositionToMap(groupPositions.get(n.vision_level), group.id, n.vision_level, n.pos));
|
||||
val npcs = group.getNpcs();
|
||||
if (npcs != null) {
|
||||
npcs.values().forEach(n -> addGridPositionToMap(groupPositions.get(n.vision_level), group.getId(), n.vision_level, n.pos));
|
||||
} else {
|
||||
logger.error("group.npcs null for group {}", group.id);
|
||||
logger.error("group.npcs null for group {}", group.getId());
|
||||
}
|
||||
|
||||
if (group.regions != null) {
|
||||
group.regions.values().forEach(r -> addGridPositionToMap(groupPositions.get(0), group.id, 0, r.pos));
|
||||
val regions = group.getRegions();
|
||||
if (regions != null) {
|
||||
regions.values().forEach(r -> addGridPositionToMap(groupPositions.get(0), group.getId(), 0, r.pos));
|
||||
} else {
|
||||
logger.error("group.regions null for group {}", group.id);
|
||||
logger.error("group.regions null for group {}", group.getId());
|
||||
}
|
||||
|
||||
if (group.garbages != null && group.garbages.gadgets != null)
|
||||
group.garbages.gadgets.forEach(g -> addGridPositionToMap(groupPositions.get(g.vision_level), group.id, g.vision_level, g.pos));
|
||||
// TODO should we add those to the grid?
|
||||
if (group.getGarbages() != null && group.getGarbages().gadgets != null)
|
||||
group.getGarbages().gadgets.forEach(g -> addGridPositionToMap(groupPositions.get(g.vision_level), group.getId(), g.vision_level, g.pos));
|
||||
|
||||
int max_vision_level = -1;
|
||||
if (!vision_levels.isEmpty()) {
|
||||
@ -483,7 +495,7 @@ public class SceneScriptManager {
|
||||
}
|
||||
if (max_vision_level == -1) max_vision_level = 0;
|
||||
|
||||
addGridPositionToMap(groupPositions.get(max_vision_level), group.id, max_vision_level, group.pos);
|
||||
addGridPositionToMap(groupPositions.get(max_vision_level), group.getId(), max_vision_level, group.getPos());
|
||||
});
|
||||
});
|
||||
|
||||
@ -518,21 +530,21 @@ public class SceneScriptManager {
|
||||
public void loadGroupFromScript(SceneGroup group) {
|
||||
group.load(getScene().getId());
|
||||
|
||||
this.sceneGroups.put(group.id, group);
|
||||
if(this.getCachedGroupInstanceById(group.id) != null) {
|
||||
this.sceneGroupsInstances.put(group.id, this.cachedSceneGroupsInstances.get(group.id));
|
||||
this.cachedSceneGroupsInstances.get(group.id).setCached(false);
|
||||
this.cachedSceneGroupsInstances.get(group.id).setLuaGroup(group);
|
||||
this.sceneGroups.put(group.getId(), group);
|
||||
if(this.getCachedGroupInstanceById(group.getId()) != null) {
|
||||
this.sceneGroupsInstances.put(group.getId(), this.cachedSceneGroupsInstances.get(group.getId()));
|
||||
this.cachedSceneGroupsInstances.get(group.getId()).setCached(false);
|
||||
this.cachedSceneGroupsInstances.get(group.getId()).setLuaGroup(group);
|
||||
} else {
|
||||
var instance = new SceneGroupInstance(group, getScene().getWorld().getHost());
|
||||
this.sceneGroupsInstances.put(group.id, instance);
|
||||
this.cachedSceneGroupsInstances.put(group.id, instance);
|
||||
this.sceneGroupsInstances.put(group.getId(), instance);
|
||||
this.cachedSceneGroupsInstances.put(group.getId(), instance);
|
||||
instance.save(); //Save the instance
|
||||
}
|
||||
|
||||
if (group.variables != null) {
|
||||
group.variables.forEach(variable -> {
|
||||
val variables = this.getVariables(group.id);
|
||||
if (group.getVariables() != null) {
|
||||
group.getVariables().forEach(variable -> {
|
||||
val variables = this.getVariables(group.getId());
|
||||
if(variables != null && !variables.containsKey(variable.name))
|
||||
variables.put(variable.name, variable.value);
|
||||
});
|
||||
@ -540,7 +552,7 @@ public class SceneScriptManager {
|
||||
}
|
||||
|
||||
public void unregisterGroup(SceneGroup group) {
|
||||
this.sceneGroups.remove(group.id);
|
||||
this.sceneGroups.remove(group.getId());
|
||||
this.sceneGroupsInstances.values().removeIf(i -> i.getLuaGroup().equals(group));
|
||||
this.cachedSceneGroupsInstances.values().stream().filter(i -> Objects.equals(i.getLuaGroup(),group)).forEach(s -> s.setCached(true));
|
||||
}
|
||||
@ -586,9 +598,9 @@ public class SceneScriptManager {
|
||||
return suite.sceneGadgets.stream()
|
||||
.filter(m -> {
|
||||
var entity = scene.getEntityByConfigId(m.config_id);
|
||||
return (entity == null || entity.getGroupId()!=group.id) && (!m.isOneoff || !m.persistent || !groupInstance.getDeadEntities().contains(m.config_id));
|
||||
return (entity == null || entity.getGroupId()!=group.getId()) && (!m.isOneoff || !m.persistent || !groupInstance.getDeadEntities().contains(m.config_id));
|
||||
})
|
||||
.map(g -> createGadget(group.id, group.block_id, g, groupInstance.getCachedGadgetState(g)))
|
||||
.map(g -> createGadget(group.getId(), group.block_id, g, groupInstance.getCachedGadgetState(g)))
|
||||
.peek(g -> groupInstance.cacheGadgetState(g.getMetaGadget(), g.getState()))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
@ -598,9 +610,9 @@ public class SceneScriptManager {
|
||||
return suite.sceneMonsters.stream()
|
||||
.filter(m -> {
|
||||
var entity = scene.getEntityByConfigId(m.config_id);
|
||||
return (entity == null || entity.getGroupId()!=group.id);/*&& !groupInstance.getDeadEntities().contains(entity); */ //TODO: Investigate the usage of deadEntities
|
||||
return (entity == null || entity.getGroupId()!=group.getId());/*&& !groupInstance.getDeadEntities().contains(entity); */ //TODO: Investigate the usage of deadEntities
|
||||
}) //TODO: Add persistent monster cached data
|
||||
.map(mob -> createMonster(group.id, group.block_id, mob))
|
||||
.map(mob -> createMonster(group.getId(), group.block_id, mob))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
}
|
||||
@ -665,15 +677,25 @@ public class SceneScriptManager {
|
||||
public void spawnMonstersByConfigId(SceneGroup group, int configId, int delayTime) {
|
||||
// TODO delay
|
||||
var entity = scene.getEntityByConfigId(configId);
|
||||
if(entity!=null && entity.getGroupId() == group.id){
|
||||
logger.debug("entity already exists failed in group {} with config {}", group.id, configId);
|
||||
if(entity!=null && entity.getGroupId() == group.getId()){
|
||||
logger.debug("entity already exists failed in group {} with config {}", group.getId(), configId);
|
||||
return;
|
||||
}
|
||||
entity = createMonster(group.id, group.block_id, group.monsters.get(configId));
|
||||
val groupMonsters = group.getMonsters();
|
||||
if(groupMonsters == null){
|
||||
logger.warn("monsters in group {} are null, unable to get configId {}", group.getId(), configId);
|
||||
return;
|
||||
}
|
||||
val monster = groupMonsters.get(configId);
|
||||
if(monster == null){
|
||||
logger.warn("configId {} not found in group {}", configId, group.getId());
|
||||
return;
|
||||
}
|
||||
entity = createMonster(group.getId(), group.block_id, monster);
|
||||
if(entity!=null){
|
||||
getScene().addEntity(entity);
|
||||
} else {
|
||||
logger.warn("failed to create entity with group {} and config {}", group.id, configId);
|
||||
logger.warn("failed to create entity with group {} and config {}", group.getId(), configId);
|
||||
}
|
||||
}
|
||||
// Events
|
||||
@ -693,18 +715,16 @@ public class SceneScriptManager {
|
||||
private void realCallEvent(@Nonnull ScriptArgs params) {
|
||||
try {
|
||||
int eventType = params.type;
|
||||
// TODO maybe find a better way to allow for event specific logic?
|
||||
Set<SceneTrigger> relevantTriggers = this.getTriggersByEvent(eventType).stream()
|
||||
.filter(t -> params.getGroupId() == 0 || t.getCurrentGroup().id == params.getGroupId())
|
||||
.filter(t -> params.getGroupId() == 0 || t.getCurrentGroup().getId() == params.getGroupId())
|
||||
.filter(t -> (t.getSource().isEmpty() || t.getSource().equals(params.getEventSource())))
|
||||
.filter(t-> t.getEvent()!= EVENT_ENTER_REGION && t.getEvent()!= EVENT_LEAVE_REGION || (t.getCondition().endsWith("_"+params.param1)))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
for (SceneTrigger trigger : relevantTriggers) {
|
||||
handleEventForTrigger(params, trigger);
|
||||
}
|
||||
} catch (Throwable throwable){
|
||||
logger.error("Condition Trigger "+ params.type +" triggered exception", throwable);
|
||||
logger.error("Condition Trigger {} triggered exception", params.type, throwable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -721,18 +741,24 @@ public class SceneScriptManager {
|
||||
return false;
|
||||
}
|
||||
catch (Throwable ex){
|
||||
logger.error("Condition Trigger "+trigger.getName()+" triggered exception", ex);
|
||||
logger.error("Condition Trigger {} triggered exception", trigger.getName(), ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the trigger has a condition and calls it if it does.
|
||||
* @param trigger
|
||||
* @param params
|
||||
* @return true if there is no condition, otherwise the result of the condition call as boolean
|
||||
*/
|
||||
private boolean evaluateTriggerCondition(SceneTrigger trigger, ScriptArgs params){
|
||||
logger.trace("Call Condition Trigger {}, [{},{},{}]", trigger.getCondition(), params.param1, params.source_eid, params.target_eid);
|
||||
val condition = trigger.getCondition();
|
||||
if(condition == null || condition.isBlank()){
|
||||
return true;
|
||||
}
|
||||
val ret = this.callScriptFunc(trigger.getCondition(), trigger.currentGroup, params);
|
||||
val ret = this.callScriptFunc(trigger.getCondition(), trigger.getCurrentGroup(), params);
|
||||
return ret.isBoolean() && ret.asBoolean();
|
||||
}
|
||||
|
||||
@ -741,7 +767,7 @@ public class SceneScriptManager {
|
||||
LuaValue callResult = BooleanLuaValue.TRUE;
|
||||
if(action != null && !action.isBlank()){
|
||||
// the SetGroupVariableValueByGroup in tower need the param to record the first stage time
|
||||
callResult = this.callScriptFunc(trigger.getAction(), trigger.currentGroup, params);
|
||||
callResult = this.callScriptFunc(trigger.getAction(), trigger.getCurrentGroup(), params);
|
||||
}
|
||||
|
||||
val invocationsCounter = triggerInvocations.get(trigger.getName());
|
||||
@ -763,11 +789,11 @@ public class SceneScriptManager {
|
||||
}
|
||||
|
||||
if(trigger.getEvent() == EVENT_TIMER_EVENT){
|
||||
cancelGroupTimerEvent(trigger.currentGroup.id, trigger.getSource());
|
||||
cancelGroupTimerEvent(trigger.getCurrentGroup().getId(), trigger.getSource());
|
||||
}
|
||||
// always deregister on error, otherwise only if the count is reached
|
||||
if(callResult.isBoolean() && !callResult.asBoolean() || callResult.isInteger() && callResult.asInteger()!=0
|
||||
|| trigger.getTrigger_count()>0 && invocations >= trigger.getTrigger_count()) {
|
||||
|| trigger.getTrigger_count() > INF_TRIGGERS && invocations >= trigger.getTrigger_count()) {
|
||||
deregisterTrigger(trigger);
|
||||
}
|
||||
}
|
||||
@ -792,7 +818,7 @@ public class SceneScriptManager {
|
||||
try{
|
||||
return script.callMethod(funcName, context, params);
|
||||
} catch (RuntimeException | ScriptException | NoSuchMethodException error){
|
||||
logger.error("[LUA] call trigger failed in group {} with {},{}",group.id,funcName,params,error);
|
||||
logger.error("[LUA] call trigger failed in group {} with {},{}",group.getId(),funcName,params,error);
|
||||
return new BooleanLuaValue(false);
|
||||
}
|
||||
}
|
||||
@ -813,7 +839,7 @@ public class SceneScriptManager {
|
||||
if (g.isOneoff) {
|
||||
var hasEntity = getScene().getEntities().values().stream()
|
||||
.filter(e -> e instanceof EntityGadget)
|
||||
.filter(e -> e.getGroupId() == g.group.id)
|
||||
.filter(e -> e.getGroupId() == g.group.getId())
|
||||
.filter(e -> e.getConfigId() == g.config_id)
|
||||
.findFirst();
|
||||
if (hasEntity.isPresent()) {
|
||||
@ -906,7 +932,7 @@ public class SceneScriptManager {
|
||||
.collect(Collectors.toSet());
|
||||
var toRemove = getScene().getEntities().values().stream()
|
||||
.filter(e -> e instanceof EntityMonster)
|
||||
.filter(e -> e.getGroupId() == group.id)
|
||||
.filter(e -> e.getGroupId() == group.getId())
|
||||
.filter(e -> configSet.contains(e.getConfigId()))
|
||||
.toList();
|
||||
|
||||
@ -918,7 +944,7 @@ public class SceneScriptManager {
|
||||
.collect(Collectors.toSet());
|
||||
var toRemove = getScene().getEntities().values().stream()
|
||||
.filter(e -> e instanceof EntityGadget)
|
||||
.filter(e -> e.getGroupId() == group.id)
|
||||
.filter(e -> e.getGroupId() == group.getId())
|
||||
.filter(e -> configSet.contains(e.getConfigId()))
|
||||
.toList();
|
||||
|
||||
@ -931,7 +957,7 @@ public class SceneScriptManager {
|
||||
.collect(Collectors.toSet());
|
||||
var toRemove = getScene().getEntities().values().stream()
|
||||
.filter(e -> e instanceof EntityMonster)
|
||||
.filter(e -> e.getGroupId() == group.id)
|
||||
.filter(e -> e.getGroupId() == group.getId())
|
||||
.filter(e -> configSet.contains(e.getConfigId()))
|
||||
.toList();
|
||||
|
||||
@ -943,7 +969,7 @@ public class SceneScriptManager {
|
||||
.collect(Collectors.toSet());
|
||||
var toRemove = getScene().getEntities().values().stream()
|
||||
.filter(e -> e instanceof EntityGadget)
|
||||
.filter(e -> e.getGroupId() == group.id)
|
||||
.filter(e -> e.getGroupId() == group.getId())
|
||||
.filter(e -> configSet.contains(e.getConfigId()))
|
||||
.toList();
|
||||
|
||||
@ -953,13 +979,13 @@ public class SceneScriptManager {
|
||||
public int createGroupTimerEvent(int groupID, String source, double time) {
|
||||
//TODO also remove timers when refreshing and test
|
||||
var group = getGroupById(groupID);
|
||||
if(group == null || group.triggers == null){
|
||||
if(group == null || group.getTriggers() == null){
|
||||
logger.warn("trying to create a timer for unknown group with id {} and source {}", groupID, source);
|
||||
return 1;
|
||||
}
|
||||
logger.info("creating group timer event for group {} with source {} and time {}",
|
||||
groupID, source, time);
|
||||
for(SceneTrigger trigger : group.triggers.values()){
|
||||
for(SceneTrigger trigger : group.getTriggers().values()){
|
||||
if(trigger.getEvent() == EVENT_TIMER_EVENT &&trigger.getSource().equals(source)){
|
||||
logger.warn("[LUA] Found timer trigger with source {} for group {} : {}",
|
||||
source, groupID, trigger.getName());
|
||||
@ -996,7 +1022,7 @@ public class SceneScriptManager {
|
||||
val groupInstance = getGroupInstanceById(groupId);
|
||||
if (groupInstance == null || groupInstance.getLuaGroup() == null) return false;
|
||||
|
||||
val monsters = groupInstance.getLuaGroup().monsters;
|
||||
val monsters = groupInstance.getLuaGroup().getMonsters();
|
||||
|
||||
if(monsters == null || monsters.isEmpty()) return true;
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class ScriptLib {
|
||||
private static void printLog(@Nullable LuaContext context, String source, String msg){
|
||||
if(context instanceof GroupEventLuaContext){
|
||||
var group = ((GroupEventLuaContext) context).getCurrentGroup();
|
||||
logger.debug("[LUA] {} {} {}", source, group.id, msg);
|
||||
logger.debug("[LUA] {} {} {}", source, group.getId(), msg);
|
||||
return;
|
||||
} else {
|
||||
logger.debug("[LUA] {} {}", source, msg);
|
||||
@ -83,10 +83,21 @@ public class ScriptLib {
|
||||
|
||||
|
||||
private static GameEntity createGadget(SceneScriptManager sceneScriptManager, int configId, SceneGroup group){
|
||||
var gadget = group.gadgets.get(configId);
|
||||
var entity = sceneScriptManager.createGadget(group.id, group.block_id, gadget);
|
||||
val groupGadgets = group.getGadgets();
|
||||
if (groupGadgets == null){
|
||||
logger.warn("[LUA] Create gadget called with cid: {} gid: {} bid: {}, but gadgets is null", configId, group.getId(), group.getBlock_id());
|
||||
return null;
|
||||
}
|
||||
|
||||
val gadget = groupGadgets.get(configId);
|
||||
if (gadget == null){
|
||||
logger.warn("[LUA] Create gadget called with cid: {} gid: {} bid: {}, but gadget is null", configId, group.getId(), group.getBlock_id());
|
||||
return null;
|
||||
}
|
||||
|
||||
val entity = sceneScriptManager.createGadget(group.getId(), group.getBlock_id(), gadget);
|
||||
if(entity==null){
|
||||
logger.warn("[LUA] Create gadget null with cid: {} gid: {} bid: {}", configId, group.id, group.block_id);
|
||||
logger.warn("[LUA] Create gadget null with cid: {} gid: {} bid: {}", configId, group.getId(), group.getBlock_id());
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -249,7 +260,7 @@ public class ScriptLib {
|
||||
|
||||
SceneGroup group = context.getSceneScriptManager().getGroupById(groupId);
|
||||
|
||||
if (group == null || group.monsters == null) {
|
||||
if (group == null || group.getMonsters() == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -264,7 +275,7 @@ public class ScriptLib {
|
||||
val scriptManager = context.getSceneScriptManager();
|
||||
SceneGroup group = scriptManager.getGroupById(groupId);
|
||||
SceneGroupInstance groupInstance = scriptManager.getGroupInstanceById(groupId);
|
||||
if (group == null || groupInstance == null || group.monsters == null) {
|
||||
if (group == null || groupInstance == null) {
|
||||
return 1;
|
||||
}
|
||||
var suiteData = group.getSuiteByIndex(suite);
|
||||
@ -294,7 +305,7 @@ public class ScriptLib {
|
||||
SceneGroup group = scriptManager.getGroupById(groupId);
|
||||
SceneGroupInstance groupInstance = scriptManager.getGroupInstanceById(groupId);
|
||||
|
||||
if (group == null || groupInstance == null || group.monsters == null) {
|
||||
if (group == null || groupInstance == null) {
|
||||
return 1;
|
||||
}
|
||||
var suiteData = group.getSuiteByIndex(suite);
|
||||
@ -311,7 +322,7 @@ public class ScriptLib {
|
||||
groupId,suite);
|
||||
|
||||
SceneGroup group = context.getSceneScriptManager().getGroupById(groupId);
|
||||
if (group == null || group.monsters == null) {
|
||||
if (group == null) {
|
||||
return 1;
|
||||
}
|
||||
var suiteData = group.getSuiteByIndex(suite);
|
||||
@ -328,7 +339,7 @@ public class ScriptLib {
|
||||
groupId,suite);
|
||||
|
||||
SceneGroup group = context.getSceneScriptManager().getGroupById(groupId);
|
||||
if (group == null || group.monsters == null) {
|
||||
if (group == null) {
|
||||
return 1;
|
||||
}
|
||||
var suiteData = group.getSuiteByIndex(suite);
|
||||
@ -496,7 +507,7 @@ public class ScriptLib {
|
||||
public static int GetGroupVariableValue(GroupEventLuaContext context, String var) {
|
||||
logger.debug("[LUA] Call GetGroupVariableValue with {}",
|
||||
var);
|
||||
return getGroupVariableValue(context.getSceneScriptManager(), context.getCurrentGroup().id, var);
|
||||
return getGroupVariableValue(context.getSceneScriptManager(), context.getCurrentGroup().getId(), var);
|
||||
}
|
||||
|
||||
public static int GetGroupVariableValueByGroup(GroupEventLuaContext context, String name, int groupId){
|
||||
@ -510,7 +521,7 @@ public class ScriptLib {
|
||||
logger.debug("[LUA] Call SetGroupVariableValue with {},{}",
|
||||
varName, value);
|
||||
|
||||
val groupId = context.getCurrentGroup().id;
|
||||
val groupId = context.getCurrentGroup().getId();
|
||||
return modifyGroupVariableValue(context.getSceneScriptManager(), groupId, varName, value, true);
|
||||
}
|
||||
|
||||
@ -525,7 +536,7 @@ public class ScriptLib {
|
||||
logger.debug("[LUA] Call ChangeGroupVariableValue with {},{}",
|
||||
varName, value);
|
||||
|
||||
val groupId = context.getCurrentGroup().id;
|
||||
val groupId = context.getCurrentGroup().getId();
|
||||
return modifyGroupVariableValue(context.getSceneScriptManager(), groupId, varName, value, false);
|
||||
}
|
||||
|
||||
@ -598,7 +609,7 @@ public class ScriptLib {
|
||||
|
||||
return (int) context.getSceneScriptManager().getScene().getEntities().values().stream()
|
||||
.filter(e -> e instanceof EntityMonster &&
|
||||
e.getGroupId() == context.getCurrentGroup().id)
|
||||
e.getGroupId() == context.getCurrentGroup().getId())
|
||||
.count();
|
||||
}
|
||||
|
||||
@ -846,8 +857,8 @@ public class ScriptLib {
|
||||
logger.warn("[LUA] Call SetGroupReplaceable with {} {}", groupId, value);
|
||||
|
||||
var group = context.getSceneScriptManager().getGroupById(groupId);
|
||||
if(group != null && group.is_replaceable != null) {
|
||||
group.is_replaceable.value = value;
|
||||
if(group != null && group.getIs_replaceable() != null) {
|
||||
group.getIs_replaceable().value = value;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -1005,15 +1016,15 @@ public class ScriptLib {
|
||||
val currentGroup = context.getSceneScriptManager().getGroupById(groupId);
|
||||
if (currentGroup == null) return 1;
|
||||
|
||||
val gadget = currentGroup.gadgets.get(chestConfigId);
|
||||
val chestGadget = context.getSceneScriptManager().createGadget(currentGroup.id, currentGroup.block_id, gadget);
|
||||
val gadget = currentGroup.getGadgets().get(chestConfigId);
|
||||
val chestGadget = context.getSceneScriptManager().createGadget(currentGroup.getId(), currentGroup.block_id, gadget);
|
||||
if (chestGadget == null) return 1;
|
||||
|
||||
val blossomManager = context.getSceneScriptManager().getScene().getWorld().getHost().getBlossomManager();
|
||||
val blossomSchedule = blossomManager.getBlossomSchedule().get(currentGroup.id);
|
||||
val blossomSchedule = blossomManager.getBlossomSchedule().get(currentGroup.getId());
|
||||
if (blossomSchedule == null) return 1;
|
||||
|
||||
blossomManager.getSpawnedChest().put(chestGadget.getConfigId(), currentGroup.id);
|
||||
blossomManager.getSpawnedChest().put(chestGadget.getConfigId(), currentGroup.getId());
|
||||
context.getSceneScriptManager().addEntity(chestGadget);
|
||||
context.getSceneScriptManager().getScene().broadcastPacket(
|
||||
new PacketBlossomChestCreateNotify(blossomSchedule.getRefreshId(), blossomSchedule.getCircleCampId()));
|
||||
@ -1023,7 +1034,7 @@ public class ScriptLib {
|
||||
logger.debug("[LUA] Call check GetBlossomScheduleStateByGroupId with {}", groupId);
|
||||
if (context.getCurrentGroup() == null) return -1;
|
||||
|
||||
val realGroupId = groupId == 0 ? context.getCurrentGroup().id : groupId;
|
||||
val realGroupId = groupId == 0 ? context.getCurrentGroup().getId() : groupId;
|
||||
val blossomManager = context.getSceneScriptManager().getScene().getWorld().getHost().getBlossomManager();
|
||||
return Optional.ofNullable(blossomManager.getBlossomSchedule().get(realGroupId))
|
||||
.map(BlossomSchedule::getState).orElse(-1);
|
||||
@ -1032,7 +1043,7 @@ public class ScriptLib {
|
||||
logger.debug("[LUA] Call check SetBlossomScheduleStateByGroupId with {} {}", groupId, state);
|
||||
|
||||
val blossomManager = context.getSceneScriptManager().getScene().getWorld().getHost().getBlossomManager();
|
||||
val realGroupId = groupId == 0 ? context.getCurrentGroup().id : groupId;
|
||||
val realGroupId = groupId == 0 ? context.getCurrentGroup().getId() : groupId;
|
||||
val result = blossomManager.setBlossomState(realGroupId, state);
|
||||
if (result && state == 1) { // there should only be one gadget of this blossom at this point, which is the operator
|
||||
context.getSceneScriptManager().getScene().getEntities().values().stream()
|
||||
@ -1046,23 +1057,23 @@ public class ScriptLib {
|
||||
logger.debug("[LUA] Call check RefreshBlossomGroup with {}", printTable(configTable));
|
||||
|
||||
int groupId = configTable.getInt("group_id");
|
||||
val group = context.getSceneScriptManager().getGroupById(groupId == 0 ? context.getCurrentGroup().id : groupId);
|
||||
val group = context.getSceneScriptManager().getGroupById(groupId == 0 ? context.getCurrentGroup().getId() : groupId);
|
||||
if (group == null) return 1;
|
||||
|
||||
val groupInstance = context.getSceneScriptManager().getGroupInstanceById(group.id);
|
||||
val groupInstance = context.getSceneScriptManager().getGroupInstanceById(group.getId());
|
||||
int suiteIndex = configTable.getInt("suite");
|
||||
val suite = group.getSuiteByIndex(suiteIndex);
|
||||
if (suite == null || groupInstance == null) return 1;
|
||||
|
||||
context.getSceneScriptManager().refreshGroup(groupInstance, suiteIndex, configTable.getBoolean("exclude_prev"));
|
||||
val blossomManager = context.getSceneScriptManager().getScene().getWorld().getHost().getBlossomManager();
|
||||
val schedule = blossomManager.getBlossomSchedule().get(group.id);
|
||||
val schedule = blossomManager.getBlossomSchedule().get(group.getId());
|
||||
if (schedule == null) return 0;
|
||||
|
||||
val spawnedChest = blossomManager.getSpawnedChest().values().stream()
|
||||
.filter(gid -> gid == schedule.getGroupId()).findFirst().orElse(null);
|
||||
context.getSceneScriptManager().callEvent(new ScriptArgs(
|
||||
group.id, spawnedChest == null ? EventType.EVENT_GROUP_REFRESH : EventType.EVENT_BLOSSOM_PROGRESS_FINISH));
|
||||
group.getId(), spawnedChest == null ? EventType.EVENT_GROUP_REFRESH : EventType.EVENT_BLOSSOM_PROGRESS_FINISH));
|
||||
return 0;
|
||||
}
|
||||
public static int RefreshBlossomDropRewardByGroupId(GroupEventLuaContext context, int groupId){
|
||||
@ -1078,7 +1089,7 @@ public class ScriptLib {
|
||||
public static int GetBlossomRefreshTypeByGroupId(GroupEventLuaContext context, int groupId){
|
||||
logger.debug("[LUA] Call check GetBlossomRefreshTypeByGroupId with {}", groupId);
|
||||
|
||||
val realGroupId = groupId == 0 ? context.getCurrentGroup().id : groupId;
|
||||
val realGroupId = groupId == 0 ? context.getCurrentGroup().getId() : groupId;
|
||||
val blossomManager = context.getSceneScriptManager().getScene().getWorld().getHost().getBlossomManager();
|
||||
return Optional.ofNullable(blossomManager.getBlossomSchedule().get(realGroupId))
|
||||
.map(BlossomSchedule::getRefreshType).map(BlossomRefreshType::getValue).orElse(2);
|
||||
@ -1669,7 +1680,7 @@ public class ScriptLib {
|
||||
|
||||
// kill targets if exists
|
||||
for(int cfgId : targets){
|
||||
var entity = sceneScriptManager.getScene().getEntityByConfigId(cfgId, group.id);
|
||||
var entity = sceneScriptManager.getScene().getEntityByConfigId(cfgId, group.getId());
|
||||
if (entity == null || cfgId == 0) {
|
||||
continue;
|
||||
}
|
||||
@ -1682,10 +1693,14 @@ public class ScriptLib {
|
||||
// get targets
|
||||
var targets = new ArrayList<SceneObject>();
|
||||
if(killPolicy==GROUP_KILL_MONSTER || killPolicy == GROUP_KILL_ALL){
|
||||
targets.addAll(group.monsters.values());
|
||||
val monsters = group.getMonsters();
|
||||
if(monsters != null)
|
||||
targets.addAll(monsters.values());
|
||||
}
|
||||
if(killPolicy == GROUP_KILL_GADGET || killPolicy == GROUP_KILL_ALL) {
|
||||
targets.addAll(group.gadgets.values());
|
||||
val gadgets = group.getGadgets();
|
||||
if(gadgets != null)
|
||||
targets.addAll(gadgets.values());
|
||||
}
|
||||
|
||||
// kill targets if exists
|
||||
|
@ -64,10 +64,10 @@ public class SceneBlock {
|
||||
|
||||
// Set groups
|
||||
this.groups = cs.getGlobalVariableList("groups", SceneGroup.class).stream()
|
||||
.collect(Collectors.toMap(x -> x.id, y -> y, (a, b) -> a));
|
||||
.collect(Collectors.toMap(x -> x.getId(), y -> y, (a, b) -> a));
|
||||
|
||||
this.groups.values().forEach(g -> g.block_id = this.id);
|
||||
this.sceneGroupIndex = SceneIndexManager.buildIndex(3, this.groups.values(), g -> g.pos.toPoint());
|
||||
this.sceneGroupIndex = SceneIndexManager.buildIndex(3, this.groups.values(), g -> g.getPos().toPoint());
|
||||
} catch (ScriptException exception) {
|
||||
Grasscutter.getLogger().error("An error occurred while loading block " + this.id + " in scene " + sceneId, exception);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package emu.grasscutter.scripts.data;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.game.world.GroupReplacementData;
|
||||
import emu.grasscutter.scripts.ScriptLoader;
|
||||
import emu.grasscutter.scripts.lua_engine.LuaScript;
|
||||
import emu.grasscutter.utils.Position;
|
||||
@ -9,52 +10,57 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.val;
|
||||
import emu.grasscutter.game.world.GroupReplacementData;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
@Getter
|
||||
public class SceneGroup {
|
||||
public transient int block_id; // Not an actual variable in the scripts but we will keep it here for reference
|
||||
|
||||
public int id;
|
||||
public int refresh_id;
|
||||
public Position pos;
|
||||
@Setter
|
||||
private int id;
|
||||
private int refresh_id;
|
||||
@Nullable
|
||||
private Position pos;
|
||||
|
||||
public Map<Integer,SceneMonster> monsters; // <ConfigId, Monster>
|
||||
public Map<Integer, SceneNPC> npcs; // <ConfigId, Npc>
|
||||
public Map<Integer, SceneGadget> gadgets; // <ConfigId, Gadgets>
|
||||
public Map<String, SceneTrigger> triggers;
|
||||
public Map<Integer, SceneRegion> regions;
|
||||
public List<SceneSuite> suites;
|
||||
public List<SceneVar> variables;
|
||||
@Nullable
|
||||
private Map<Integer, SceneMonster> monsters; // <ConfigId, Monster>
|
||||
@Nullable
|
||||
private Map<Integer, SceneNPC> npcs; // <ConfigId, Npc>
|
||||
@Nullable
|
||||
private Map<Integer, SceneGadget> gadgets; // <ConfigId, Gadgets>
|
||||
@Nullable
|
||||
private Map<String, SceneTrigger> triggers;
|
||||
@Nullable
|
||||
private Map<Integer, SceneRegion> regions;
|
||||
@Nullable
|
||||
private List<SceneSuite> suites;
|
||||
@Nullable
|
||||
private List<SceneVar> variables;
|
||||
|
||||
public SceneBusiness business;
|
||||
public SceneGarbage garbages;
|
||||
public SceneInitConfig init_config;
|
||||
@Getter public boolean dynamic_load = false;
|
||||
@Nullable
|
||||
private SceneBusiness business;
|
||||
@Nullable
|
||||
private SceneGarbage garbages;
|
||||
@Nullable
|
||||
private SceneInitConfig init_config;
|
||||
private final boolean dynamic_load = false;
|
||||
|
||||
public SceneReplaceable is_replaceable;
|
||||
@Nullable
|
||||
private SceneReplaceable is_replaceable;
|
||||
|
||||
private transient boolean loaded; // Not an actual variable in the scripts either
|
||||
private transient LuaScript script;
|
||||
//private transient Bindings bindings;
|
||||
|
||||
public static SceneGroup of(int groupId) {
|
||||
var group = new SceneGroup();
|
||||
group.id = groupId;
|
||||
return group;
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return this.loaded;
|
||||
}
|
||||
|
||||
public void setLoaded(boolean loaded) {
|
||||
this.loaded = loaded;
|
||||
}
|
||||
|
||||
public int getBusinessType() {
|
||||
return this.business == null ? 0 : this.business.type;
|
||||
}
|
||||
@ -63,12 +69,8 @@ public class SceneGroup {
|
||||
return this.garbages == null ? null : this.garbages.gadgets;
|
||||
}
|
||||
|
||||
public LuaScript getScript() {
|
||||
return this.script;
|
||||
}
|
||||
|
||||
public SceneSuite getSuiteByIndex(int index) {
|
||||
if(index < 1 || index > suites.size()) {
|
||||
if (index < 1 || index > suites.size()) {
|
||||
return null;
|
||||
}
|
||||
return this.suites.get(index - 1);
|
||||
@ -79,7 +81,7 @@ public class SceneGroup {
|
||||
return this;
|
||||
}
|
||||
// Set flag here so if there is no script, we don't call this function over and over again.
|
||||
this.setLoaded(true);
|
||||
this.loaded = true;
|
||||
|
||||
val cs = ScriptLoader.getScript("Scene/" + sceneId + "/scene" + sceneId + "_group" + this.id + ".lua");
|
||||
|
||||
@ -95,20 +97,20 @@ public class SceneGroup {
|
||||
|
||||
// Set
|
||||
this.monsters = cs.getGlobalVariableList("monsters", SceneMonster.class).stream()
|
||||
.collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a));
|
||||
.collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a));
|
||||
this.monsters.values().forEach(m -> m.group = this);
|
||||
|
||||
this.npcs = cs.getGlobalVariableList("npcs", SceneNPC.class).stream()
|
||||
.collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a));
|
||||
this.npcs = cs.getGlobalVariableList("npcs", SceneNPC.class).stream()
|
||||
.collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a));
|
||||
this.npcs.values().forEach(m -> m.group = this);
|
||||
|
||||
this.gadgets = cs.getGlobalVariableList("gadgets", SceneGadget.class).stream()
|
||||
.collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a));
|
||||
.collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a));
|
||||
this.gadgets.values().forEach(m -> m.group = this);
|
||||
|
||||
this.triggers = cs.getGlobalVariableList("triggers", SceneTrigger.class).stream()
|
||||
.collect(Collectors.toMap(SceneTrigger::getName, y -> y, (a, b) -> a));
|
||||
this.triggers.values().forEach(t -> t.currentGroup = this);
|
||||
.collect(Collectors.toMap(SceneTrigger::getName, y -> y, (a, b) -> a));
|
||||
this.triggers.values().forEach(t -> t.setCurrentGroup(this));
|
||||
|
||||
this.suites = cs.getGlobalVariableList("suites", SceneSuite.class);
|
||||
this.regions = cs.getGlobalVariableList("regions", SceneRegion.class).stream()
|
||||
@ -142,18 +144,18 @@ public class SceneGroup {
|
||||
}
|
||||
|
||||
public int findInitSuiteIndex(int exclude_index) { //TODO: Investigate end index
|
||||
if(init_config == null) return 1;
|
||||
if(init_config.io_type == 1) return init_config.suite; //IO TYPE FLOW
|
||||
if(init_config.rand_suite) {
|
||||
if(suites.size() == 1) {
|
||||
if (init_config == null) return 1;
|
||||
if (init_config.io_type == 1) return init_config.suite; //IO TYPE FLOW
|
||||
if (init_config.rand_suite) {
|
||||
if (suites.size() == 1) {
|
||||
return init_config.suite;
|
||||
} else {
|
||||
List<Integer> randSuiteList = new ArrayList<>();
|
||||
for(int i = 0; i < suites.size(); i++) {
|
||||
if(i == exclude_index) continue;
|
||||
for (int i = 0; i < suites.size(); i++) {
|
||||
if (i == exclude_index) continue;
|
||||
|
||||
var suite = suites.get(i);
|
||||
for(int j = 0; j < suite.rand_weight; j++) randSuiteList.add(Integer.valueOf(i + 1));
|
||||
for (int j = 0; j < suite.rand_weight; j++) randSuiteList.add(Integer.valueOf(i + 1));
|
||||
}
|
||||
return randSuiteList.get(new Random().nextInt(randSuiteList.size()));
|
||||
}
|
||||
@ -167,7 +169,7 @@ public class SceneGroup {
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public List<SceneGroup> getReplaceableGroups(Collection<SceneGroup> loadedGroups){
|
||||
public List<SceneGroup> getReplaceableGroups(Collection<SceneGroup> loadedGroups) {
|
||||
return this.is_replaceable == null ? List.of() :
|
||||
Optional.ofNullable(GameData.getGroupReplacements().get(this.id)).stream()
|
||||
.map(GroupReplacementData::getReplace_groups)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import emu.grasscutter.utils.Position;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -19,5 +20,5 @@ public class SceneObject {
|
||||
/**
|
||||
* not set by lua
|
||||
*/
|
||||
public transient SceneGroup group;
|
||||
@Getter public transient SceneGroup group;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class SceneRegion extends SceneObject{
|
||||
}
|
||||
|
||||
public int getGroupId() {
|
||||
return group.id;
|
||||
return group.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.val;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
@ -24,37 +25,41 @@ public class SceneSuite {
|
||||
public transient List<SceneRegion> sceneRegions = List.of();
|
||||
|
||||
public void init(SceneGroup sceneGroup) {
|
||||
if(sceneGroup.monsters != null){
|
||||
val monsters = sceneGroup.getMonsters();
|
||||
if(monsters != null){
|
||||
this.sceneMonsters = new ArrayList<>(
|
||||
this.monsters.stream()
|
||||
.filter(sceneGroup.monsters::containsKey)
|
||||
.map(sceneGroup.monsters::get)
|
||||
.filter(monsters::containsKey)
|
||||
.map(monsters::get)
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
|
||||
if(sceneGroup.gadgets != null){
|
||||
val gadgets = sceneGroup.getGadgets();
|
||||
if(gadgets != null){
|
||||
this.sceneGadgets = new ArrayList<>(
|
||||
this.gadgets.stream()
|
||||
.filter(sceneGroup.gadgets::containsKey)
|
||||
.map(sceneGroup.gadgets::get)
|
||||
.filter(gadgets::containsKey)
|
||||
.map(gadgets::get)
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
|
||||
if(sceneGroup.triggers != null) {
|
||||
val triggers = sceneGroup.getTriggers();
|
||||
if(triggers != null) {
|
||||
this.sceneTriggers = new ArrayList<>(
|
||||
this.triggers.stream()
|
||||
.filter(sceneGroup.triggers::containsKey)
|
||||
.map(sceneGroup.triggers::get)
|
||||
.filter(triggers::containsKey)
|
||||
.map(triggers::get)
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
if(sceneGroup.regions != null) {
|
||||
val regions = sceneGroup.getRegions();
|
||||
if(regions != null) {
|
||||
this.sceneRegions = new ArrayList<>(
|
||||
this.regions.stream()
|
||||
.filter(sceneGroup.regions::containsKey)
|
||||
.map(sceneGroup.regions::get)
|
||||
.filter(regions::containsKey)
|
||||
.map(regions::get)
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
|
@ -1,12 +1,18 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
// todo find way to deserialize from lua with final fields, maybe with the help of Builder?
|
||||
public class SceneTrigger {
|
||||
private String name;
|
||||
/**
|
||||
* When the trigger count is set to this, it only gets unregistered on a return of != 0 from the trigger function.
|
||||
*/
|
||||
public static final int INF_TRIGGERS = 0;
|
||||
|
||||
private String name;
|
||||
private int config_id;
|
||||
private int event;
|
||||
private int trigger_count = 1;
|
||||
@ -15,7 +21,7 @@ public class SceneTrigger {
|
||||
private String action;
|
||||
private String tag;
|
||||
private String tlog_tag;
|
||||
public boolean forbid_guest;
|
||||
private boolean forbid_guest;
|
||||
|
||||
public transient SceneGroup currentGroup;
|
||||
private transient SceneGroup currentGroup;
|
||||
}
|
||||
|
@ -2,11 +2,13 @@ package emu.grasscutter.scripts.lua_engine;
|
||||
|
||||
import com.esotericsoftware.reflectasm.ConstructorAccess;
|
||||
import com.esotericsoftware.reflectasm.MethodAccess;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
@ -49,11 +51,15 @@ public abstract class Serializer {
|
||||
var methodNameSet = new HashSet<>(Arrays.stream(methodAccess.getMethodNames()).toList());
|
||||
|
||||
Arrays.stream(type.getDeclaredFields())
|
||||
.filter(field -> methodNameSet.contains(getSetterName(field.getName())))
|
||||
.forEach(field -> {
|
||||
var setter = getSetterName(field.getName());
|
||||
var index = methodAccess.getIndex(setter);
|
||||
fieldMetaMap.put(field.getName(), new FieldMeta(field.getName(), setter, index, field.getType(), field));
|
||||
if(methodNameSet.contains(getSetterName(field.getName()))) {
|
||||
var setter = getSetterName(field.getName());
|
||||
var index = methodAccess.getIndex(setter);
|
||||
fieldMetaMap.put(field.getName(), new FieldMeta(field.getName(), setter, index, field.getType(), field));
|
||||
} else {
|
||||
field.setAccessible(true);
|
||||
fieldMetaMap.put(field.getName(), new FieldMeta(field.getName(), null, -1, field.getType(), field));
|
||||
}
|
||||
});
|
||||
|
||||
Arrays.stream(type.getFields())
|
||||
@ -69,6 +75,73 @@ public abstract class Serializer {
|
||||
return fieldMetaMap;
|
||||
}
|
||||
|
||||
protected void set(Object object, @Nonnull FieldMeta fieldMeta, @Nullable MethodAccess methodAccess, int value){
|
||||
try {
|
||||
if (methodAccess != null && fieldMeta.getSetter() != null) {
|
||||
methodAccess.invoke(object, fieldMeta.index, value);
|
||||
} else if(fieldMeta.field != null){
|
||||
fieldMeta.field.setInt(object, value);
|
||||
}
|
||||
} catch (Exception ex){
|
||||
Grasscutter.getLogger().warn("Failed to set field {} of type {} to value {}", fieldMeta.name, fieldMeta.type, value, ex);
|
||||
}
|
||||
}
|
||||
protected void set(Object object, @Nonnull FieldMeta fieldMeta, @Nullable MethodAccess methodAccess, double value){
|
||||
try {
|
||||
if (methodAccess != null && fieldMeta.getSetter() != null) {
|
||||
methodAccess.invoke(object, fieldMeta.index, value);
|
||||
} else if(fieldMeta.field != null) {
|
||||
fieldMeta.field.setDouble(object, value);
|
||||
}
|
||||
} catch (Exception ex){
|
||||
Grasscutter.getLogger().warn("Failed to set field {} of type {} to value {}", fieldMeta.name, fieldMeta.type, value, ex);
|
||||
}
|
||||
}
|
||||
protected void set(Object object, @Nonnull FieldMeta fieldMeta, @Nullable MethodAccess methodAccess, float value){
|
||||
try {
|
||||
if (methodAccess != null && fieldMeta.getSetter() != null) {
|
||||
methodAccess.invoke(object, fieldMeta.index, value);
|
||||
} else if(fieldMeta.field != null) {
|
||||
fieldMeta.field.setFloat(object, value);
|
||||
}
|
||||
} catch (Exception ex){
|
||||
Grasscutter.getLogger().warn("Failed to set field {} of type {} to value {}", fieldMeta.name, fieldMeta.type, value, ex);
|
||||
}
|
||||
}
|
||||
protected void set(Object object, @Nonnull FieldMeta fieldMeta, @Nullable MethodAccess methodAccess, long value){
|
||||
try {
|
||||
if (methodAccess != null && fieldMeta.getSetter() != null) {
|
||||
methodAccess.invoke(object, fieldMeta.index, value);
|
||||
} else if(fieldMeta.field != null) {
|
||||
fieldMeta.field.setLong(object, value);
|
||||
}
|
||||
} catch (Exception ex){
|
||||
Grasscutter.getLogger().warn("Failed to set field {} of type {} to value {}", fieldMeta.name, fieldMeta.type, value, ex);
|
||||
}
|
||||
}
|
||||
protected void set(Object object, @Nonnull FieldMeta fieldMeta, @Nullable MethodAccess methodAccess, boolean value){
|
||||
try {
|
||||
if (methodAccess != null && fieldMeta.getSetter() != null) {
|
||||
methodAccess.invoke(object, fieldMeta.index, value);
|
||||
} else if(fieldMeta.field != null) {
|
||||
fieldMeta.field.setBoolean(object, value);
|
||||
}
|
||||
} catch (Exception ex){
|
||||
Grasscutter.getLogger().warn("Failed to set field {} of type {} to value {}", fieldMeta.name, fieldMeta.type, value, ex);
|
||||
}
|
||||
}
|
||||
protected void set(Object object, @Nonnull FieldMeta fieldMeta, @Nullable MethodAccess methodAccess, Object value){
|
||||
try {
|
||||
if (methodAccess != null && fieldMeta.getSetter() != null) {
|
||||
methodAccess.invoke(object, fieldMeta.index, value);
|
||||
} else if(fieldMeta.field != null) {
|
||||
fieldMeta.field.set(object, value);
|
||||
}
|
||||
} catch (Exception ex){
|
||||
Grasscutter.getLogger().warn("Failed to set field {} of type {} to value {}", fieldMeta.name, fieldMeta.type, value, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@FieldDefaults(level = AccessLevel.PRIVATE)
|
||||
|
@ -122,7 +122,7 @@ public class JNLuaSerializer extends Serializer {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!methodAccessCache.containsKey(type)) {
|
||||
if (!fieldMetaCache.containsKey(type)) {
|
||||
cacheType(type);
|
||||
}
|
||||
var methodAccess = methodAccessCache.get(type);
|
||||
@ -145,22 +145,22 @@ public class JNLuaSerializer extends Serializer {
|
||||
var fieldMeta = fieldMetaMap.get(keyName);
|
||||
var keyValue = k.getValue();
|
||||
if (fieldMeta.getType().equals(float.class)) {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), getFloat(keyValue));
|
||||
set(object, fieldMeta, methodAccess, getFloat(keyValue));
|
||||
} else if (fieldMeta.getType().equals(double.class)) {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), (keyValue));
|
||||
set(object, fieldMeta, methodAccess, (double) keyValue);
|
||||
} else if (fieldMeta.getType().equals(int.class)) {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), getInt(keyValue));
|
||||
set(object, fieldMeta, methodAccess, getInt(keyValue));
|
||||
} else if (fieldMeta.getType().equals(String.class)) {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), keyValue);
|
||||
set(object, fieldMeta, methodAccess, keyValue);
|
||||
} else if (fieldMeta.getType().equals(boolean.class)) {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), keyValue);
|
||||
set(object, fieldMeta, methodAccess, (boolean) keyValue);
|
||||
} else if (fieldMeta.getType().equals(List.class)) {
|
||||
LuaValueProxy objTable = (LuaValueProxy) tableObj.get(k.getKey());
|
||||
Class<?> listType = getListType(type, fieldMeta.getField());
|
||||
List<?> listObj = serializeList(listType, objTable);
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), listObj);
|
||||
set(object, fieldMeta, methodAccess, listObj);
|
||||
} else {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), serialize(fieldMeta.getType(), fieldMeta.getField(), (LuaValueProxy) keyValue));
|
||||
set(object, fieldMeta, methodAccess, serialize(fieldMeta.getType(), fieldMeta.getField(), (LuaValueProxy) keyValue));
|
||||
//methodAccess.invoke(object, fieldMeta.index, keyValue);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
@ -137,7 +137,7 @@ public class LuaJSerializer extends Serializer {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!methodAccessCache.containsKey(type)) {
|
||||
if (!fieldMetaCache.containsKey(type)) {
|
||||
cacheType(type);
|
||||
}
|
||||
var methodAccess = methodAccessCache.get(type);
|
||||
@ -160,17 +160,17 @@ public class LuaJSerializer extends Serializer {
|
||||
LuaValue keyValue = table.get(k);
|
||||
|
||||
if (keyValue.istable()) {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), serialize(fieldMeta.getType(), fieldMeta.getField(), keyValue.checktable()));
|
||||
set(object, fieldMeta, methodAccess, serialize(fieldMeta.getType(), fieldMeta.getField(), keyValue.checktable()));
|
||||
} else if (fieldMeta.getType().equals(float.class)) {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), keyValue.tofloat());
|
||||
set(object, fieldMeta, methodAccess, keyValue.tofloat());
|
||||
} else if (fieldMeta.getType().equals(int.class)) {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), keyValue.toint());
|
||||
set(object, fieldMeta, methodAccess, keyValue.toint());
|
||||
} else if (fieldMeta.getType().equals(String.class)) {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), keyValue.tojstring());
|
||||
set(object, fieldMeta, methodAccess, keyValue.tojstring());
|
||||
} else if (fieldMeta.getType().equals(boolean.class)) {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), keyValue.toboolean());
|
||||
set(object, fieldMeta, methodAccess, keyValue.toboolean());
|
||||
} else {
|
||||
methodAccess.invoke(object, fieldMeta.getIndex(), keyValue.tojstring());
|
||||
set(object, fieldMeta, methodAccess, keyValue.tojstring());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LuaEngine.logger.error("Exception serializing", ex);
|
||||
|
@ -7,6 +7,7 @@ import emu.grasscutter.scripts.data.SceneGroup;
|
||||
import emu.grasscutter.scripts.data.SceneMonster;
|
||||
import emu.grasscutter.scripts.data.ScriptArgs;
|
||||
import emu.grasscutter.scripts.listener.ScriptMonsterListener;
|
||||
import lombok.val;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
@ -41,7 +42,7 @@ public class ScriptMonsterTideService {
|
||||
this.sceneScriptManager.getScriptMonsterSpawnService().addMonsterDeadListener(onMonsterDead);
|
||||
// spawn the first turn
|
||||
for (int i = 0; i < this.monsterSceneLimit; i++) {
|
||||
sceneScriptManager.addEntity(this.sceneScriptManager.createMonster(group.id, group.block_id, getNextMonster()));
|
||||
sceneScriptManager.addEntity(this.sceneScriptManager.createMonster(group.getId(), group.block_id, getNextMonster()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,12 +57,16 @@ public class ScriptMonsterTideService {
|
||||
}
|
||||
|
||||
public SceneMonster getNextMonster(){
|
||||
var nextId = this.monsterConfigOrders.poll();
|
||||
if(currentGroup.monsters.containsKey(nextId)){
|
||||
return currentGroup.monsters.get(nextId);
|
||||
val nextId = this.monsterConfigOrders.poll();
|
||||
val monsters = currentGroup.getMonsters();
|
||||
if (monsters == null) {
|
||||
return null;
|
||||
}
|
||||
if(monsters.containsKey(nextId)){
|
||||
return monsters.get(nextId);
|
||||
}
|
||||
// TODO some monster config_id do not exist in groups, so temporarily set it to the first
|
||||
return currentGroup.monsters.values().stream().findFirst().orElse(null);
|
||||
return monsters.values().stream().findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public class OnMonsterDead implements ScriptMonsterListener {
|
||||
@ -77,11 +82,11 @@ public class ScriptMonsterTideService {
|
||||
monsterKillCount.incrementAndGet();
|
||||
if (monsterTideCount.get() > 0) {
|
||||
// add more
|
||||
sceneScriptManager.addEntity(sceneScriptManager.createMonster(currentGroup.id, currentGroup.block_id, getNextMonster()));
|
||||
sceneScriptManager.addEntity(sceneScriptManager.createMonster(currentGroup.getId(), currentGroup.block_id, getNextMonster()));
|
||||
}
|
||||
// spawn the last turn of monsters
|
||||
// fix the 5-2
|
||||
sceneScriptManager.callEvent(new ScriptArgs(currentGroup.id, EventType.EVENT_MONSTER_TIDE_DIE, monsterKillCount.get())
|
||||
sceneScriptManager.callEvent(new ScriptArgs(currentGroup.getId(), EventType.EVENT_MONSTER_TIDE_DIE, monsterKillCount.get())
|
||||
.setEventSource(String.valueOf(challengeIndex)));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user