2022-04-29 05:19:14 +00:00
|
|
|
package emu.grasscutter.scripts;
|
|
|
|
|
2022-05-23 12:55:22 +00:00
|
|
|
import emu.grasscutter.game.dungeons.challenge.DungeonChallenge;
|
2022-04-29 05:19:14 +00:00
|
|
|
import emu.grasscutter.game.entity.EntityGadget;
|
|
|
|
import emu.grasscutter.game.entity.EntityMonster;
|
|
|
|
import emu.grasscutter.game.entity.GameEntity;
|
2022-05-18 09:21:34 +00:00
|
|
|
import emu.grasscutter.game.entity.gadget.GadgetWorktop;
|
2022-05-23 12:55:22 +00:00
|
|
|
import emu.grasscutter.game.dungeons.challenge.factory.ChallengeFactory;
|
2022-07-03 07:56:18 +00:00
|
|
|
import emu.grasscutter.game.props.EntityType;
|
|
|
|
import emu.grasscutter.game.quest.enums.QuestState;
|
|
|
|
import emu.grasscutter.game.quest.enums.QuestTrigger;
|
2022-04-29 05:19:14 +00:00
|
|
|
import emu.grasscutter.scripts.data.SceneGroup;
|
2022-04-30 08:08:38 +00:00
|
|
|
import emu.grasscutter.scripts.data.SceneRegion;
|
2022-05-07 13:47:13 +00:00
|
|
|
import emu.grasscutter.server.packet.send.PacketCanUseSkillNotify;
|
2022-07-03 07:56:18 +00:00
|
|
|
import emu.grasscutter.server.packet.send.PacketDungeonShowReminderNotify;
|
2022-04-29 05:19:14 +00:00
|
|
|
import emu.grasscutter.server.packet.send.PacketWorktopOptionNotify;
|
2022-05-19 03:15:40 +00:00
|
|
|
import io.netty.util.concurrent.FastThreadLocal;
|
2022-05-07 13:47:13 +00:00
|
|
|
import org.luaj.vm2.LuaTable;
|
|
|
|
import org.luaj.vm2.LuaValue;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.util.Optional;
|
2022-04-29 05:19:14 +00:00
|
|
|
|
|
|
|
public class ScriptLib {
|
2022-05-07 13:47:13 +00:00
|
|
|
public static final Logger logger = LoggerFactory.getLogger(ScriptLib.class);
|
2022-05-19 03:15:40 +00:00
|
|
|
private final FastThreadLocal<SceneScriptManager> sceneScriptManager;
|
|
|
|
private final FastThreadLocal<SceneGroup> currentGroup;
|
|
|
|
public ScriptLib() {
|
|
|
|
this.sceneScriptManager = new FastThreadLocal<>();
|
|
|
|
this.currentGroup = new FastThreadLocal<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSceneScriptManager(SceneScriptManager sceneScriptManager){
|
|
|
|
this.sceneScriptManager.set(sceneScriptManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeSceneScriptManager(){
|
|
|
|
this.sceneScriptManager.remove();
|
2022-04-29 05:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public SceneScriptManager getSceneScriptManager() {
|
2022-05-19 03:15:40 +00:00
|
|
|
// normally not null
|
|
|
|
return Optional.of(sceneScriptManager.get()).get();
|
2022-04-29 05:19:14 +00:00
|
|
|
}
|
2022-05-09 07:39:49 +00:00
|
|
|
|
|
|
|
private String printTable(LuaTable table){
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append("{");
|
|
|
|
for(var meta : table.keys()){
|
|
|
|
sb.append(meta).append(":").append(table.get(meta)).append(",");
|
|
|
|
}
|
|
|
|
sb.append("}");
|
|
|
|
return sb.toString();
|
|
|
|
}
|
2022-05-18 07:13:31 +00:00
|
|
|
public void setCurrentGroup(SceneGroup currentGroup){
|
|
|
|
this.currentGroup.set(currentGroup);
|
|
|
|
}
|
|
|
|
public Optional<SceneGroup> getCurrentGroup(){
|
2022-05-19 03:15:40 +00:00
|
|
|
return Optional.of(this.currentGroup.get());
|
2022-05-18 07:13:31 +00:00
|
|
|
}
|
|
|
|
public void removeCurrentGroup(){
|
|
|
|
this.currentGroup.remove();
|
|
|
|
}
|
2022-04-29 05:19:14 +00:00
|
|
|
public int SetGadgetStateByConfigId(int configId, int gadgetState) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call SetGadgetStateByConfigId with {},{}",
|
|
|
|
configId,gadgetState);
|
2022-04-29 05:19:14 +00:00
|
|
|
Optional<GameEntity> entity = getSceneScriptManager().getScene().getEntities().values().stream()
|
|
|
|
.filter(e -> e.getConfigId() == configId).findFirst();
|
|
|
|
|
|
|
|
if (entity.isEmpty()) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-05-20 05:46:00 +00:00
|
|
|
|
|
|
|
if (entity.get() instanceof EntityGadget entityGadget) {
|
|
|
|
entityGadget.updateState(gadgetState);
|
|
|
|
return 0;
|
2022-04-29 05:19:14 +00:00
|
|
|
}
|
2022-05-20 05:46:00 +00:00
|
|
|
|
|
|
|
return 1;
|
2022-04-29 05:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int SetGroupGadgetStateByConfigId(int groupId, int configId, int gadgetState) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call SetGroupGadgetStateByConfigId with {},{},{}",
|
|
|
|
groupId,configId,gadgetState);
|
2022-05-20 05:46:00 +00:00
|
|
|
|
|
|
|
getSceneScriptManager().getScene().getEntities().values().stream()
|
|
|
|
.filter(e -> e.getGroupId() == groupId)
|
|
|
|
.filter(e -> e instanceof EntityGadget)
|
|
|
|
.map(e -> (EntityGadget)e)
|
|
|
|
.forEach(e -> e.updateState(gadgetState));
|
2022-04-29 05:19:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int SetWorktopOptionsByGroupId(int groupId, int configId, int[] options) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call SetWorktopOptionsByGroupId with {},{},{}",
|
|
|
|
groupId,configId,options);
|
2022-05-18 09:21:34 +00:00
|
|
|
|
2022-04-29 05:19:14 +00:00
|
|
|
Optional<GameEntity> entity = getSceneScriptManager().getScene().getEntities().values().stream()
|
|
|
|
.filter(e -> e.getConfigId() == configId && e.getGroupId() == groupId).findFirst();
|
|
|
|
|
2022-05-18 09:21:34 +00:00
|
|
|
|
|
|
|
if (entity.isEmpty() || !(entity.get() instanceof EntityGadget gadget)) {
|
2022-04-29 05:19:14 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2022-05-18 09:21:34 +00:00
|
|
|
|
|
|
|
if (!(gadget.getContent() instanceof GadgetWorktop worktop)) {
|
2022-04-29 05:19:14 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-05-18 09:21:34 +00:00
|
|
|
worktop.addWorktopOptions(options);
|
2022-04-29 05:19:14 +00:00
|
|
|
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));
|
2022-05-18 09:21:34 +00:00
|
|
|
|
2022-04-29 05:19:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2022-05-18 07:13:31 +00:00
|
|
|
|
|
|
|
public int SetWorktopOptions(LuaTable table){
|
|
|
|
logger.debug("[LUA] Call SetWorktopOptions with {}", printTable(table));
|
|
|
|
// TODO
|
|
|
|
return 0;
|
|
|
|
}
|
2022-04-29 05:19:14 +00:00
|
|
|
public int DelWorktopOptionByGroupId(int groupId, int configId, int option) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call DelWorktopOptionByGroupId with {},{},{}",groupId,configId,option);
|
|
|
|
|
2022-04-29 05:19:14 +00:00
|
|
|
Optional<GameEntity> entity = getSceneScriptManager().getScene().getEntities().values().stream()
|
|
|
|
.filter(e -> e.getConfigId() == configId && e.getGroupId() == groupId).findFirst();
|
|
|
|
|
2022-05-18 09:21:34 +00:00
|
|
|
if (entity.isEmpty() || !(entity.get() instanceof EntityGadget gadget)) {
|
2022-04-29 05:19:14 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2022-05-18 09:21:34 +00:00
|
|
|
|
|
|
|
if (!(gadget.getContent() instanceof GadgetWorktop worktop)) {
|
2022-04-29 05:19:14 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-05-18 09:21:34 +00:00
|
|
|
worktop.removeWorktopOption(option);
|
2022-04-29 05:19:14 +00:00
|
|
|
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));
|
2022-05-18 09:21:34 +00:00
|
|
|
|
2022-04-29 05:19:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some fields are guessed
|
2022-05-07 13:47:13 +00:00
|
|
|
public int AutoMonsterTide(int challengeIndex, int groupId, Integer[] ordersConfigId, int tideCount, int sceneLimit, int param6) {
|
|
|
|
logger.debug("[LUA] Call AutoMonsterTide with {},{},{},{},{},{}",
|
|
|
|
challengeIndex,groupId,ordersConfigId,tideCount,sceneLimit,param6);
|
|
|
|
|
2022-04-29 05:19:14 +00:00
|
|
|
SceneGroup group = getSceneScriptManager().getGroupById(groupId);
|
2022-05-08 09:11:02 +00:00
|
|
|
|
2022-04-29 05:19:14 +00:00
|
|
|
if (group == null || group.monsters == null) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-05-07 13:47:13 +00:00
|
|
|
|
2022-05-09 07:39:49 +00:00
|
|
|
this.getSceneScriptManager().startMonsterTideInGroup(group, ordersConfigId, tideCount, sceneLimit);
|
2022-04-29 05:19:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-29 09:38:25 +00:00
|
|
|
public int AddExtraGroupSuite(int groupId, int suite) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call AddExtraGroupSuite with {},{}",
|
|
|
|
groupId,suite);
|
2022-04-29 07:52:40 +00:00
|
|
|
SceneGroup group = getSceneScriptManager().getGroupById(groupId);
|
|
|
|
|
|
|
|
if (group == null || group.monsters == null) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-05-23 12:55:22 +00:00
|
|
|
var suiteData = group.getSuiteByIndex(suite);
|
|
|
|
if(suiteData == null){
|
|
|
|
return 1;
|
|
|
|
}
|
2022-05-09 16:05:01 +00:00
|
|
|
// avoid spawn wrong monster
|
|
|
|
if(getSceneScriptManager().getScene().getChallenge() != null)
|
|
|
|
if(!getSceneScriptManager().getScene().getChallenge().inProgress() ||
|
|
|
|
getSceneScriptManager().getScene().getChallenge().getGroup().id != groupId){
|
|
|
|
return 0;
|
|
|
|
}
|
2022-05-23 12:55:22 +00:00
|
|
|
this.getSceneScriptManager().addGroupSuite(group, suiteData);
|
|
|
|
|
2022-04-29 07:49:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2022-05-23 12:55:22 +00:00
|
|
|
public int GoToGroupSuite(int groupId, int suite) {
|
|
|
|
logger.debug("[LUA] Call GoToGroupSuite with {},{}",
|
|
|
|
groupId,suite);
|
2022-04-29 05:19:14 +00:00
|
|
|
SceneGroup group = getSceneScriptManager().getGroupById(groupId);
|
2022-05-23 12:55:22 +00:00
|
|
|
if (group == null || group.monsters == null) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
var suiteData = group.getSuiteByIndex(suite);
|
|
|
|
if(suiteData == null){
|
|
|
|
return 1;
|
|
|
|
}
|
2022-05-07 13:47:13 +00:00
|
|
|
|
2022-05-23 12:55:22 +00:00
|
|
|
for(var suiteItem : group.suites){
|
|
|
|
if(suiteData == suiteItem){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
this.getSceneScriptManager().removeGroupSuite(group, suiteItem);
|
2022-05-07 13:47:13 +00:00
|
|
|
}
|
2022-05-23 12:55:22 +00:00
|
|
|
this.getSceneScriptManager().addGroupSuite(group, suiteData);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
public int RemoveExtraGroupSuite(int groupId, int suite) {
|
|
|
|
logger.debug("[LUA] Call RemoveExtraGroupSuite with {},{}",
|
|
|
|
groupId,suite);
|
|
|
|
|
|
|
|
SceneGroup group = getSceneScriptManager().getGroupById(groupId);
|
2022-04-29 05:19:14 +00:00
|
|
|
if (group == null || group.monsters == null) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-05-23 12:55:22 +00:00
|
|
|
var suiteData = group.getSuiteByIndex(suite);
|
|
|
|
if(suiteData == null){
|
|
|
|
return 1;
|
|
|
|
}
|
2022-05-08 09:11:02 +00:00
|
|
|
|
2022-05-23 12:55:22 +00:00
|
|
|
this.getSceneScriptManager().removeGroupSuite(group, suiteData);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
public int KillExtraGroupSuite(int groupId, int suite) {
|
|
|
|
logger.debug("[LUA] Call KillExtraGroupSuite with {},{}",
|
|
|
|
groupId,suite);
|
|
|
|
|
|
|
|
SceneGroup group = getSceneScriptManager().getGroupById(groupId);
|
|
|
|
if (group == null || group.monsters == null) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
var suiteData = group.getSuiteByIndex(suite);
|
|
|
|
if(suiteData == null){
|
|
|
|
return 1;
|
2022-05-08 09:11:02 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 12:55:22 +00:00
|
|
|
this.getSceneScriptManager().removeGroupSuite(group, suiteData);
|
2022-05-09 16:05:01 +00:00
|
|
|
|
2022-05-23 12:55:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// param3 (probably time limit for timed dungeons)
|
|
|
|
public int ActiveChallenge(int challengeId, int challengeIndex, int timeLimitOrGroupId, int groupId, int objectiveKills, int param5) {
|
|
|
|
logger.debug("[LUA] Call ActiveChallenge with {},{},{},{},{},{}",
|
|
|
|
challengeId,challengeIndex,timeLimitOrGroupId,groupId,objectiveKills,param5);
|
|
|
|
|
|
|
|
var challenge = ChallengeFactory.getChallenge(
|
|
|
|
challengeId,
|
|
|
|
challengeIndex,
|
|
|
|
timeLimitOrGroupId,
|
|
|
|
groupId,
|
|
|
|
objectiveKills,
|
|
|
|
param5,
|
|
|
|
getSceneScriptManager().getScene(),
|
|
|
|
getCurrentGroup().get()
|
|
|
|
);
|
|
|
|
|
|
|
|
if(challenge == null){
|
|
|
|
return 1;
|
|
|
|
}
|
2022-05-09 16:05:01 +00:00
|
|
|
|
2022-05-23 12:55:22 +00:00
|
|
|
if(challenge instanceof DungeonChallenge dungeonChallenge){
|
|
|
|
// set if tower first stage (6-1)
|
|
|
|
dungeonChallenge.setStage(getSceneScriptManager().getVariables().getOrDefault("stage", -1) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
getSceneScriptManager().getScene().setChallenge(challenge);
|
2022-04-29 05:19:14 +00:00
|
|
|
challenge.start();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-29 09:38:25 +00:00
|
|
|
public int GetGroupMonsterCountByGroupId(int groupId) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call GetGroupMonsterCountByGroupId with {}",
|
|
|
|
groupId);
|
2022-04-29 09:38:25 +00:00
|
|
|
return (int) getSceneScriptManager().getScene().getEntities().values().stream()
|
|
|
|
.filter(e -> e instanceof EntityMonster && e.getGroupId() == groupId)
|
|
|
|
.count();
|
|
|
|
}
|
|
|
|
|
2022-04-29 10:06:33 +00:00
|
|
|
public int GetGroupVariableValue(String var) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call GetGroupVariableValue with {}",
|
|
|
|
var);
|
2022-04-29 10:06:33 +00:00
|
|
|
return getSceneScriptManager().getVariables().getOrDefault(var, 0);
|
2022-04-29 09:38:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-04 06:13:42 +00:00
|
|
|
public int SetGroupVariableValue(String var, int value) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call SetGroupVariableValue with {},{}",
|
|
|
|
var, value);
|
2022-04-29 09:38:25 +00:00
|
|
|
getSceneScriptManager().getVariables().put(var, value);
|
2022-05-04 06:13:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LuaValue ChangeGroupVariableValue(String var, int value) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call ChangeGroupVariableValue with {},{}",
|
|
|
|
var, value);
|
|
|
|
|
2022-05-04 06:13:42 +00:00
|
|
|
getSceneScriptManager().getVariables().put(var, getSceneScriptManager().getVariables().get(var) + value);
|
2022-04-29 09:38:25 +00:00
|
|
|
return LuaValue.ZERO;
|
|
|
|
}
|
2022-05-09 07:39:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the actions and triggers to designated group
|
|
|
|
*/
|
2022-04-29 05:19:14 +00:00
|
|
|
public int RefreshGroup(LuaTable table) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call RefreshGroup with {}",
|
2022-05-09 07:39:49 +00:00
|
|
|
printTable(table));
|
2022-04-29 09:38:25 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2022-05-09 07:39:49 +00:00
|
|
|
getSceneScriptManager().refreshGroup(group, suite);
|
2022-04-29 09:38:25 +00:00
|
|
|
|
2022-04-29 05:19:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2022-06-23 07:59:17 +00:00
|
|
|
|
2022-04-30 08:08:38 +00:00
|
|
|
public int GetRegionEntityCount(LuaTable table) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call GetRegionEntityCount with {}",
|
2022-05-23 12:55:22 +00:00
|
|
|
printTable(table));
|
2022-04-30 08:08:38 +00:00
|
|
|
int regionId = table.get("region_eid").toint();
|
|
|
|
int entityType = table.get("entity_type").toint();
|
|
|
|
|
2022-06-23 07:59:17 +00:00
|
|
|
var region = this.getSceneScriptManager().getRegionById(regionId);
|
|
|
|
|
2022-04-30 08:08:38 +00:00
|
|
|
if (region == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-23 07:59:17 +00:00
|
|
|
return (int) region.getEntities().stream().filter(e -> e >> 24 == entityType).count();
|
2022-04-30 08:08:38 +00:00
|
|
|
}
|
2022-06-23 07:59:17 +00:00
|
|
|
|
2022-04-29 05:19:14 +00:00
|
|
|
public void PrintContextLog(String msg) {
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.info("[LUA] " + msg);
|
2022-04-29 05:19:14 +00:00
|
|
|
}
|
2022-05-06 16:15:23 +00:00
|
|
|
|
2022-05-07 13:47:13 +00:00
|
|
|
public int TowerCountTimeStatus(int isDone, int var2){
|
|
|
|
logger.debug("[LUA] Call TowerCountTimeStatus with {},{}",
|
|
|
|
isDone,var2);
|
|
|
|
// TODO record time
|
2022-05-06 16:15:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2022-05-23 12:55:22 +00:00
|
|
|
public int GetGroupMonsterCount(){
|
|
|
|
logger.debug("[LUA] Call GetGroupMonsterCount ");
|
2022-05-07 13:47:13 +00:00
|
|
|
|
|
|
|
return (int) getSceneScriptManager().getScene().getEntities().values().stream()
|
2022-05-18 07:13:31 +00:00
|
|
|
.filter(e -> e instanceof EntityMonster &&
|
|
|
|
e.getGroupId() == getCurrentGroup().map(sceneGroup -> sceneGroup.id).orElse(-1))
|
2022-05-07 13:47:13 +00:00
|
|
|
.count();
|
2022-05-06 16:15:23 +00:00
|
|
|
}
|
|
|
|
public int SetMonsterBattleByGroup(int var1, int var2, int var3){
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call SetMonsterBattleByGroup with {},{},{}",
|
|
|
|
var1,var2,var3);
|
2022-05-09 07:39:49 +00:00
|
|
|
// TODO
|
2022-05-06 16:15:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int CauseDungeonFail(int var1){
|
2022-05-07 13:47:13 +00:00
|
|
|
logger.debug("[LUA] Call CauseDungeonFail with {}",
|
|
|
|
var1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2022-05-09 07:39:49 +00:00
|
|
|
|
2022-05-08 09:11:02 +00:00
|
|
|
public int GetGroupVariableValueByGroup(String name, int groupId){
|
|
|
|
logger.debug("[LUA] Call GetGroupVariableValueByGroup with {},{}",
|
|
|
|
name,groupId);
|
2022-05-07 13:47:13 +00:00
|
|
|
|
2022-05-08 09:11:02 +00:00
|
|
|
return getSceneScriptManager().getVariables().getOrDefault(name, 0);
|
2022-05-07 13:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int SetIsAllowUseSkill(int canUse, int var2){
|
|
|
|
logger.debug("[LUA] Call SetIsAllowUseSkill with {},{}",
|
|
|
|
canUse,var2);
|
|
|
|
|
|
|
|
getSceneScriptManager().getScene().broadcastPacket(new PacketCanUseSkillNotify(canUse == 1));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int KillEntityByConfigId(LuaTable table){
|
|
|
|
logger.debug("[LUA] Call KillEntityByConfigId with {}",
|
2022-05-09 07:39:49 +00:00
|
|
|
printTable(table));
|
2022-05-07 13:47:13 +00:00
|
|
|
var configId = table.get("config_id");
|
|
|
|
if(configId == LuaValue.NIL){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
var entity = getSceneScriptManager().getScene().getEntityByConfigId(configId.toint());
|
|
|
|
if(entity == null){
|
2022-05-23 12:55:22 +00:00
|
|
|
return 0;
|
2022-05-07 13:47:13 +00:00
|
|
|
}
|
|
|
|
getSceneScriptManager().getScene().killEntity(entity, 0);
|
2022-05-06 16:15:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2022-05-07 13:47:13 +00:00
|
|
|
|
2022-05-08 09:11:02 +00:00
|
|
|
public int SetGroupVariableValueByGroup(String key, int value, int groupId){
|
|
|
|
logger.debug("[LUA] Call SetGroupVariableValueByGroup with {},{},{}",
|
|
|
|
key,value,groupId);
|
|
|
|
|
2022-05-09 07:39:49 +00:00
|
|
|
getSceneScriptManager().getVariables().put(key, value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int CreateMonster(LuaTable table){
|
|
|
|
logger.debug("[LUA] Call CreateMonster with {}",
|
|
|
|
printTable(table));
|
|
|
|
var configId = table.get("config_id").toint();
|
|
|
|
var delayTime = table.get("delay_time").toint();
|
|
|
|
|
2022-05-18 07:13:31 +00:00
|
|
|
if(getCurrentGroup().isEmpty()){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
getSceneScriptManager().spawnMonstersByConfigId(getCurrentGroup().get(), configId, delayTime);
|
2022-05-09 07:39:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int TowerMirrorTeamSetUp(int team, int var1) {
|
|
|
|
logger.debug("[LUA] Call TowerMirrorTeamSetUp with {},{}",
|
|
|
|
team,var1);
|
|
|
|
|
2022-05-09 16:05:01 +00:00
|
|
|
getSceneScriptManager().unloadCurrentMonsterTide();
|
2022-05-09 07:39:49 +00:00
|
|
|
getSceneScriptManager().getScene().getPlayers().get(0).getTowerManager().mirrorTeamSetUp(team-1);
|
|
|
|
|
2022-05-08 09:11:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-05-09 16:05:01 +00:00
|
|
|
public int CreateGadget(LuaTable table){
|
|
|
|
logger.debug("[LUA] Call CreateGadget with {}",
|
|
|
|
printTable(table));
|
|
|
|
var configId = table.get("config_id").toint();
|
|
|
|
|
2022-05-18 07:13:31 +00:00
|
|
|
var group = getCurrentGroup();
|
2022-05-18 12:33:00 +00:00
|
|
|
|
|
|
|
if (group.isEmpty()) {
|
2022-05-18 07:13:31 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2022-05-18 12:33:00 +00:00
|
|
|
|
2022-05-18 07:13:31 +00:00
|
|
|
var gadget = group.get().gadgets.get(configId);
|
|
|
|
var entity = getSceneScriptManager().createGadget(group.get().id, group.get().block_id, gadget);
|
2022-05-18 12:33:00 +00:00
|
|
|
|
2022-05-18 07:13:31 +00:00
|
|
|
getSceneScriptManager().addEntity(entity);
|
2022-05-09 16:05:01 +00:00
|
|
|
|
2022-05-15 11:19:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
public int CheckRemainGadgetCountByGroupId(LuaTable table){
|
|
|
|
logger.debug("[LUA] Call CheckRemainGadgetCountByGroupId with {}",
|
|
|
|
printTable(table));
|
|
|
|
var groupId = table.get("group_id").toint();
|
|
|
|
|
|
|
|
var count = getSceneScriptManager().getScene().getEntities().values().stream()
|
|
|
|
.filter(g -> g instanceof EntityGadget entityGadget && entityGadget.getGroupId() == groupId)
|
|
|
|
.count();
|
|
|
|
return (int)count;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetGadgetStateByConfigId(int groupId, int configId){
|
|
|
|
logger.debug("[LUA] Call GetGadgetStateByConfigId with {},{}",
|
|
|
|
groupId, configId);
|
2022-05-23 12:55:22 +00:00
|
|
|
|
|
|
|
if(groupId == 0){
|
|
|
|
groupId = getCurrentGroup().get().id;
|
|
|
|
}
|
|
|
|
final int realGroupId = groupId;
|
2022-05-15 11:19:24 +00:00
|
|
|
var gadget = getSceneScriptManager().getScene().getEntities().values().stream()
|
2022-05-23 12:55:22 +00:00
|
|
|
.filter(g -> g instanceof EntityGadget entityGadget && entityGadget.getGroupId() == realGroupId)
|
2022-05-15 11:19:24 +00:00
|
|
|
.filter(g -> g.getConfigId() == configId)
|
|
|
|
.findFirst();
|
|
|
|
if(gadget.isEmpty()){
|
2022-05-18 07:13:31 +00:00
|
|
|
return 1;
|
2022-05-15 11:19:24 +00:00
|
|
|
}
|
2022-05-18 07:13:31 +00:00
|
|
|
return ((EntityGadget)gadget.get()).getState();
|
2022-05-15 11:19:24 +00:00
|
|
|
}
|
2022-05-18 07:13:31 +00:00
|
|
|
|
|
|
|
public int MarkPlayerAction(int var1, int var2, int var3, int var4){
|
2022-05-23 12:55:22 +00:00
|
|
|
logger.debug("[LUA] Call MarkPlayerAction with {},{},{},{}",
|
|
|
|
var1, var2,var3,var4);
|
2022-05-18 07:13:31 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int AddQuestProgress(String var1){
|
|
|
|
logger.debug("[LUA] Call AddQuestProgress with {}",
|
|
|
|
var1);
|
|
|
|
|
2022-07-05 12:41:07 +00:00
|
|
|
for(var player : getSceneScriptManager().getScene().getPlayers()){
|
|
|
|
player.getQuestManager().triggerEvent(QuestTrigger.QUEST_COND_LUA_NOTIFY, var1);
|
|
|
|
player.getQuestManager().triggerEvent(QuestTrigger.QUEST_CONTENT_LUA_NOTIFY, var1);
|
|
|
|
}
|
|
|
|
|
2022-05-18 07:13:31 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-05-18 09:36:50 +00:00
|
|
|
if (entity instanceof EntityGadget entityGadget) {
|
|
|
|
entityGadget.updateState(state);
|
2022-05-20 05:46:00 +00:00
|
|
|
return 0;
|
2022-05-18 07:13:31 +00:00
|
|
|
}
|
2022-05-15 11:19:24 +00:00
|
|
|
|
2022-05-20 05:46:00 +00:00
|
|
|
return 1;
|
2022-05-09 16:05:01 +00:00
|
|
|
}
|
2022-07-03 07:56:18 +00:00
|
|
|
|
|
|
|
public int GetEntityType(int entityId){
|
|
|
|
var entity = getSceneScriptManager().getScene().getEntityById(entityId);
|
|
|
|
if(entity == null){
|
|
|
|
return EntityType.None.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return entity.getEntityType();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetQuestState(int entityId, int questId){
|
|
|
|
var player = getSceneScriptManager().getScene().getWorld().getHost();
|
|
|
|
|
|
|
|
var quest = player.getQuestManager().getQuestById(questId);
|
|
|
|
if(quest == null){
|
|
|
|
return QuestState.QUEST_STATE_NONE.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return quest.getState().getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int ShowReminder(int reminderId){
|
|
|
|
getSceneScriptManager().getScene().broadcastPacket(new PacketDungeonShowReminderNotify(reminderId));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int RemoveEntityByConfigId(int groupId, int entityType, int configId){
|
|
|
|
logger.debug("[LUA] Call RemoveEntityByConfigId");
|
|
|
|
|
|
|
|
var entity = getSceneScriptManager().getScene().getEntities().values().stream()
|
|
|
|
.filter(e -> e.getGroupId() == groupId)
|
|
|
|
.filter(e -> e.getEntityType() == entityType)
|
|
|
|
.filter(e -> e.getConfigId() == configId)
|
|
|
|
.findFirst();
|
|
|
|
|
|
|
|
if(entity.isEmpty()){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
getSceneScriptManager().getScene().removeEntity(entity.get());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2022-04-29 05:19:14 +00:00
|
|
|
}
|