mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-16 17:05:20 +01:00
Some fix about scene script and quest (#2029)
* [ScriptLib] Query player when not get entity from scene * Fix NPE when doing quests * Add QUEST_CONTENT_SKILL trigger Q353 need it * Add some missing fields that contain in scene scripts * Add a lua table serializer implement with jackson This do not replace the original one,it is useful when debug * Fix point_array type error * feat: fix space
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package emu.grasscutter.scripts;
|
||||
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.dungeons.challenge.DungeonChallenge;
|
||||
import emu.grasscutter.game.entity.EntityGadget;
|
||||
import emu.grasscutter.game.entity.EntityMonster;
|
||||
import emu.grasscutter.game.entity.GameEntity;
|
||||
import emu.grasscutter.game.entity.gadget.GadgetWorktop;
|
||||
import emu.grasscutter.game.dungeons.challenge.factory.ChallengeFactory;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.EntityType;
|
||||
import emu.grasscutter.game.quest.enums.QuestState;
|
||||
import emu.grasscutter.game.quest.enums.QuestTrigger;
|
||||
@@ -89,14 +91,14 @@ public class ScriptLib {
|
||||
.filter(e -> e instanceof EntityGadget)
|
||||
.map(e -> (EntityGadget)e)
|
||||
.forEach(e -> e.updateState(gadgetState));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public int SetWorktopOptionsByGroupId(int groupId, int configId, int[] options) {
|
||||
logger.debug("[LUA] Call SetWorktopOptionsByGroupId with {},{},{}",
|
||||
groupId,configId,options);
|
||||
|
||||
|
||||
Optional<GameEntity> entity = getSceneScriptManager().getScene().getEntities().values().stream()
|
||||
.filter(e -> e.getConfigId() == configId && e.getGroupId() == groupId).findFirst();
|
||||
|
||||
@@ -108,10 +110,10 @@ public class ScriptLib {
|
||||
if (!(gadget.getContent() instanceof GadgetWorktop worktop)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
worktop.addWorktopOptions(options);
|
||||
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -133,13 +135,13 @@ public class ScriptLib {
|
||||
if (!(gadget.getContent() instanceof GadgetWorktop worktop)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
worktop.removeWorktopOption(option);
|
||||
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Some fields are guessed
|
||||
public int AutoMonsterTide(int challengeIndex, int groupId, Integer[] ordersConfigId, int tideCount, int sceneLimit, int param6) {
|
||||
logger.debug("[LUA] Call AutoMonsterTide with {},{},{},{},{},{}",
|
||||
@@ -152,15 +154,15 @@ public class ScriptLib {
|
||||
}
|
||||
|
||||
this.getSceneScriptManager().startMonsterTideInGroup(group, ordersConfigId, tideCount, sceneLimit);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public int AddExtraGroupSuite(int groupId, int suite) {
|
||||
logger.debug("[LUA] Call AddExtraGroupSuite with {},{}",
|
||||
groupId,suite);
|
||||
SceneGroup group = getSceneScriptManager().getGroupById(groupId);
|
||||
|
||||
|
||||
if (group == null || group.monsters == null) {
|
||||
return 1;
|
||||
}
|
||||
@@ -263,7 +265,7 @@ public class ScriptLib {
|
||||
challenge.start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public int GetGroupMonsterCountByGroupId(int groupId) {
|
||||
logger.debug("[LUA] Call GetGroupMonsterCountByGroupId with {}",
|
||||
groupId);
|
||||
@@ -271,20 +273,20 @@ public class ScriptLib {
|
||||
.filter(e -> e instanceof EntityMonster && e.getGroupId() == groupId)
|
||||
.count();
|
||||
}
|
||||
|
||||
|
||||
public int GetGroupVariableValue(String var) {
|
||||
logger.debug("[LUA] Call GetGroupVariableValue with {}",
|
||||
var);
|
||||
return getSceneScriptManager().getVariables().getOrDefault(var, 0);
|
||||
}
|
||||
|
||||
|
||||
public int SetGroupVariableValue(String var, int value) {
|
||||
logger.debug("[LUA] Call SetGroupVariableValue with {},{}",
|
||||
var, value);
|
||||
getSceneScriptManager().getVariables().put(var, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public LuaValue ChangeGroupVariableValue(String var, int value) {
|
||||
logger.debug("[LUA] Call ChangeGroupVariableValue with {},{}",
|
||||
var, value);
|
||||
@@ -302,15 +304,15 @@ public class ScriptLib {
|
||||
// Kill and Respawn?
|
||||
int groupId = table.get("group_id").toint();
|
||||
int suite = table.get("suite").toint();
|
||||
|
||||
|
||||
SceneGroup group = getSceneScriptManager().getGroupById(groupId);
|
||||
|
||||
|
||||
if (group == null || group.monsters == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
getSceneScriptManager().refreshGroup(group, suite);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -430,14 +432,14 @@ public class ScriptLib {
|
||||
var configId = table.get("config_id").toint();
|
||||
|
||||
var group = getCurrentGroup();
|
||||
|
||||
|
||||
if (group.isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
var gadget = group.get().gadgets.get(configId);
|
||||
var entity = getSceneScriptManager().createGadget(group.get().id, group.get().block_id, gadget);
|
||||
|
||||
|
||||
getSceneScriptManager().addEntity(entity);
|
||||
|
||||
return 0;
|
||||
@@ -515,6 +517,12 @@ public class ScriptLib {
|
||||
public int GetEntityType(int entityId){
|
||||
var entity = getSceneScriptManager().getScene().getEntityById(entityId);
|
||||
if(entity == null){
|
||||
// check players
|
||||
Player player = DatabaseHelper.getPlayerByUid(entityId);
|
||||
if (player != null) {
|
||||
return EntityType.Avatar.getValue();
|
||||
}
|
||||
|
||||
return EntityType.None.getValue();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user