Merge branch 'dev-world-scripts' of https://github.com/Grasscutters/Grasscutter into dev-world-scripts

This commit is contained in:
Melledy
2022-05-18 02:24:00 -07:00
14 changed files with 382 additions and 64 deletions

View File

@@ -24,6 +24,7 @@ public class ScriptLib {
public ScriptLib(SceneScriptManager sceneScriptManager) {
this.sceneScriptManager = sceneScriptManager;
this.currentGroup = new ThreadLocal<>();
}
public SceneScriptManager getSceneScriptManager() {
@@ -39,7 +40,17 @@ public class ScriptLib {
sb.append("}");
return sb.toString();
}
private final ThreadLocal<SceneGroup> currentGroup;
public void setCurrentGroup(SceneGroup currentGroup){
logger.debug("current {}", currentGroup);
this.currentGroup.set(currentGroup);
}
public Optional<SceneGroup> getCurrentGroup(){
return Optional.ofNullable(this.currentGroup.get());
}
public void removeCurrentGroup(){
this.currentGroup.remove();
}
public int SetGadgetStateByConfigId(int configId, int gadgetState) {
logger.debug("[LUA] Call SetGadgetStateByConfigId with {},{}",
configId,gadgetState);
@@ -102,7 +113,12 @@ public class ScriptLib {
return 0;
}
public int SetWorktopOptions(LuaTable table){
logger.debug("[LUA] Call SetWorktopOptions with {}", printTable(table));
// TODO
return 0;
}
public int DelWorktopOptionByGroupId(int groupId, int configId, int option) {
logger.debug("[LUA] Call DelWorktopOptionByGroupId with {},{},{}",groupId,configId,option);
@@ -273,7 +289,8 @@ public class ScriptLib {
var1);
return (int) getSceneScriptManager().getScene().getEntities().values().stream()
.filter(e -> e instanceof EntityMonster && e.getGroupId() == getSceneScriptManager().getCurrentGroup().id)
.filter(e -> e instanceof EntityMonster &&
e.getGroupId() == getCurrentGroup().map(sceneGroup -> sceneGroup.id).orElse(-1))
.count();
}
public int SetMonsterBattleByGroup(int var1, int var2, int var3){
@@ -335,7 +352,11 @@ public class ScriptLib {
var configId = table.get("config_id").toint();
var delayTime = table.get("delay_time").toint();
getSceneScriptManager().spawnMonstersByConfigId(configId, delayTime);
if(getCurrentGroup().isEmpty()){
return 1;
}
getSceneScriptManager().spawnMonstersByConfigId(getCurrentGroup().get(), configId, delayTime);
return 0;
}
@@ -354,7 +375,13 @@ public class ScriptLib {
printTable(table));
var configId = table.get("config_id").toint();
//TODO
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;
}
@@ -377,14 +404,42 @@ public class ScriptLib {
.filter(g -> g.getConfigId() == configId)
.findFirst();
if(gadget.isEmpty()){
return 0;
return 1;
}
var stat = ((EntityGadget)gadget.get()).getState();
return stat;
return ((EntityGadget)gadget.get()).getState();
}
public int SetGadgetStateByConfigId(int configId, LuaTable gadgetState){
logger.debug("[LUA] Call SetGadgetStateByConfigId with {},{}",
configId, printTable(gadgetState));
public int MarkPlayerAction(int var1, int var2, int var3, int var4){
logger.debug("[LUA] Call MarkPlayerAction with {},{}",
var1, var2);
return 0;
}
public int AddQuestProgress(String var1){
logger.debug("[LUA] Call AddQuestProgress with {}",
var1);
return 0;
}
/**
* change the state of gadget
*/
public int ChangeGroupGadget(LuaTable table){
logger.debug("[LUA] Call ChangeGroupGadget with {}",
printTable(table));
var configId = table.get("config_id").toint();
var state = table.get("state").toint();
var entity = getSceneScriptManager().getScene().getEntityByConfigId(configId);
if(entity == null){
return 1;
}
if(entity instanceof EntityGadget entityGadget){
getSceneScriptManager().getScene().updateGadgetState(entityGadget, state);
}
return 0;
}