[ScriptLib] Added and refactored some handler methods and added uid to ScriptArgs

Added:
* CauseDungeonSuccess
* updateBundleMarkShowStateByGroupId
* ExecuteActiveGroupLua
* ExecuteGroupLua
* ExecuteGadgetLua

Refactored:
* SendServerMessageByLuaKey
* MovePlayerToPos
* TransPlayerToPos
This commit is contained in:
hartie95 2023-12-09 23:25:12 +01:00
parent 301c524c6e
commit 6a219ea971
3 changed files with 148 additions and 33 deletions

View File

@ -1,14 +1,17 @@
package org.anime_game_servers.gi_lua.models;
import lombok.Getter;
public class ScriptArgs {
public int param1;
public int param2;
public int param3;
@Getter public int param1;
@Getter int param2;
@Getter int param3;
public int source_eid; // Source entity
public int target_eid;
public int group_id;
public String source; // source string, used for timers
public int type; // lua event type, used by scripts and the ScriptManager
@Getter public int uid; // uid of the player triggering the event
public ScriptArgs(int groupId, int eventType) {
this(groupId, eventType, 0,0);
@ -25,28 +28,16 @@ public class ScriptArgs {
this.group_id = groupId;
}
public int getParam1() {
return param1;
}
public ScriptArgs setParam1(int param1) {
this.param1 = param1;
return this;
}
public int getParam2() {
return param2;
}
public ScriptArgs setParam2(int param2) {
this.param2 = param2;
return this;
}
public int getParam3() {
return param3;
}
public ScriptArgs setParam3(int param3) {
this.param3 = param3;
return this;
@ -56,8 +47,8 @@ public class ScriptArgs {
return source_eid;
}
public ScriptArgs setSourceEntityId(int source_eid) {
this.source_eid = source_eid;
public ScriptArgs setSourceEntityId(int sourceEId) {
this.source_eid = sourceEId;
return this;
}
@ -65,8 +56,8 @@ public class ScriptArgs {
return target_eid;
}
public ScriptArgs setTargetEntityId(int target_eid) {
this.target_eid = target_eid;
public ScriptArgs setTargetEntityId(int targetEId) {
this.target_eid = targetEId;
return this;
}
@ -87,8 +78,13 @@ public class ScriptArgs {
return group_id;
}
public ScriptArgs setGroupId(int group_id) {
this.group_id = group_id;
public ScriptArgs setGroupId(int groupId) {
this.group_id = groupId;
return this;
}
public ScriptArgs setUid(int uid) {
this.uid = uid;
return this;
}
}

View File

@ -10,6 +10,9 @@ import org.anime_game_servers.gi_lua.models.constants.temporary.GalleryProgressS
import org.anime_game_servers.gi_lua.models.constants.temporary.GalleryProgressScoreUIType;
import org.anime_game_servers.lua.engine.LuaTable;
import java.util.ArrayList;
import static org.anime_game_servers.gi_lua.utils.ScriptUtils.luaToPos;
import static org.anime_game_servers.gi_lua.utils.ScriptUtils.posToLua;
public class ScriptLib {
@ -228,6 +231,10 @@ public class ScriptLib {
return context.getScriptLibHandler().CauseDungeonFail(context);
}
public static int CauseDungeonSuccess(GroupEventLuaContext context){
return context.getScriptLibHandler().CauseDungeonSuccess(context);
}
public static int SetEntityServerGlobalValueByConfigId(GroupEventLuaContext context, int cfgId, String sgvName, int value){
return context.getScriptLibHandler().SetEntityServerGlobalValueByConfigId(context, cfgId, sgvName, value);
}
@ -361,6 +368,10 @@ public class ScriptLib {
return context.getScriptLibHandler().sendCloseCommonTipsToClient(context);
}
public static int updateBundleMarkShowStateByGroupId(GroupEventLuaContext context, int groupId, boolean val2){
return context.getScriptLibHandler().updateBundleMarkShowStateByGroupId(context, groupId, val2);
}
public static int CreateFatherChallenge(GroupEventLuaContext context, int challengeIndex, int challengeId, int timeLimit, Object conditionTable){
val conditionLuaTable = context.getEngine().getTable(conditionTable);
return context.getScriptLibHandler().CreateFatherChallenge(context, challengeIndex, challengeId, timeLimit, conditionLuaTable);
@ -608,9 +619,9 @@ public class ScriptLib {
return context.getScriptLibHandler().UnlockFloatSignal(context, groupId, gadgetSignalId);
}
public static int SendServerMessageByLuaKey(GroupEventLuaContext context, String var1, Object var2Table){
var var2 = context.getEngine().getTable(var2Table);
return context.getScriptLibHandler().SendServerMessageByLuaKey(context, var1, var2);
public static int SendServerMessageByLuaKey(GroupEventLuaContext context, String stringKey, Object targetsTable){
var targets = context.getEngine().getTable(targetsTable);
return context.getScriptLibHandler().SendServerMessageByLuaKey(context, stringKey, targets.getAsIntArray());
}
public static int TryReallocateEntityAuthority(GroupEventLuaContext context, int uid, int endConfig, int var3){
@ -638,14 +649,46 @@ public class ScriptLib {
return context.getScriptLibHandler().MoveAvatarByPointArray(context, uid, targetId, var3, var4);
}
public static int MovePlayerToPos(GroupEventLuaContext context, Object rawTable) {
val table = context.getEngine().getTable(rawTable);
return context.getScriptLibHandler().MovePlayerToPos(context, table);
public static int MovePlayerToPos(GroupEventLuaContext context, Object transportationParamsTable) {
val transportationParams = context.getEngine().getTable(transportationParamsTable);
val targetsTable = transportationParams.getTable("uid_list");
val luaPos = transportationParams.getTable("pos");
val luaRot = transportationParams.getTable("rot");
val radius = transportationParams.optInt("radius", -1);
val isSkipUi = transportationParams.optBoolean("is_skip_ui", false);
if(targetsTable==null || targetsTable.getSize()==0 || luaPos == null){
scriptLogger.error(() -> "[TransPlayerToPos] Invalid params, either missing uid_list or pos");
return 1;
}
val pos = luaToPos(luaPos);
val rot = luaToPos(luaRot);
val targets = targetsTable.getAsIntArray();
return context.getScriptLibHandler().MovePlayerToPos(context, targets, pos, rot, radius, isSkipUi);
}
public static int TransPlayerToPos(GroupEventLuaContext context, Object rawTable) {
val var1 = context.getEngine().getTable(rawTable);
return context.getScriptLibHandler().TransPlayerToPos(context, var1);
public static int TransPlayerToPos(GroupEventLuaContext context, Object transportationParamsTable) {
val transportationParams = context.getEngine().getTable(transportationParamsTable);
val targetsTable = transportationParams.getTable("uid_list");
val luaPos = transportationParams.getTable("pos");
val luaRot = transportationParams.getTable("rot");
val radius = transportationParams.optInt("radius", -1);
val isSkipUi = transportationParams.optBoolean("is_skip_ui", false);
if(targetsTable==null || targetsTable.getSize()==0 || luaPos == null){
scriptLogger.error(() -> "[TransPlayerToPos] Invalid params, either missing uid_list or pos");
return 1;
}
val pos = luaToPos(luaPos);
val rot = luaToPos(luaRot);
val targets = targetsTable.getAsIntArray();
return context.getScriptLibHandler().TransPlayerToPos(context, targets, pos, rot, radius, isSkipUi);
}
public static int PlayCutScene(GroupEventLuaContext context, int cutsceneId, int var2){
@ -967,6 +1010,47 @@ public class ScriptLib {
}
/**
* TODO better parameter handling and verify active handling
* Calls a lua function in the specified group if the group is active. The call parameters are passed to the called parameters like this:
* [new context], [this function calls context], [call parameter 1], [call parameter 2]...
* @param groupId group id of the group to call the function in
* @param functionName name of the function to call
* @param callParamsTable lua array containing the parameters to pass to the function on call
*/
public static int ExecuteActiveGroupLua(GroupEventLuaContext context, int groupId, String functionName, Object callParamsTable){
val callParams = context.getEngine().getTable(callParamsTable);
return context.getScriptLibHandler().ExecuteActiveGroupLua(context, groupId, functionName, callParams);
}
/**
* TODO better parameter handling
* Calls a lua function in the specified group. The call parameters are passed to the called parameters like this:
* [new context], [this function calls context], [call parameter 1], [call parameter 2]...
* @param groupId group id of the group to call the function in
* @param functionName name of the function to call
* @param callParamsTable lua array containing the parameters to pass to the function on call
*/
public static int ExecuteGroupLua(GroupEventLuaContext context, int groupId, String functionName, Object callParamsTable){
val callParams = context.getEngine().getTable(callParamsTable);
return context.getScriptLibHandler().ExecuteGroupLua(context, groupId, functionName, callParams);
}
/**
* // TODO identify unknown parameters and exact behaviour
* Executes a lua function on a gadgets lua controller.
* This seems to be used in only the Crucible activity and might also trigger OnClientExecuteReq
* @param groupId group to find the gadget in
* @param gadgetCfgId cfg id of the gadget in the group to execute lua in
* @param activityType seems to be an activity type
* @param var4 TODO
* @param val5 TODO
*/
public static int ExecuteGadgetLua(GroupEventLuaContext context, int groupId, int gadgetCfgId, int activityType, int var4, int val5){
return context.getScriptLibHandler().ExecuteGadgetLua(context, groupId, gadgetCfgId, activityType, var4, val5);
}
/**
* Methods used in EntityControllers/using ControllerLuaContext
*/

View File

@ -1,5 +1,6 @@
package org.anime_game_servers.gi_lua.script_lib;
import lombok.val;
import org.anime_game_servers.gi_lua.models.Position;
import org.anime_game_servers.gi_lua.models.constants.*;
import org.anime_game_servers.gi_lua.models.constants.ExhibitionPlayType;
@ -94,6 +95,7 @@ public interface ScriptLibHandler<GroupEventContext extends GroupEventLuaContext
int SetMonsterBattleByGroup(GroupEventContext context, int configId, int groupId);
int CauseDungeonFail(GroupEventContext context);
int CauseDungeonSuccess(GroupEventContext context);
int SetEntityServerGlobalValueByConfigId(GroupEventContext context, int cfgId, String sgvName, int value);
@ -143,6 +145,7 @@ public interface ScriptLibHandler<GroupEventContext extends GroupEventLuaContext
int sendShowCommonTipsToClient(GroupEventContext context, String title, String content, int closeTime);
int sendCloseCommonTipsToClient(GroupEventContext context);
int updateBundleMarkShowStateByGroupId(GroupEventContext context, int groupId, boolean val2);
int CreateFatherChallenge(GroupEventContext context, int challengeIndex, int challengeId, int timeLimit, LuaTable conditionTable);
int StartFatherChallenge(GroupEventContext context, int challengeIndex);
int ModifyFatherChallengeProperty(GroupEventContext context, int challengeId, FatherChallengeProperty propertyTypeIndex, int value);
@ -207,7 +210,7 @@ public interface ScriptLibHandler<GroupEventContext extends GroupEventLuaContext
int UnlockFloatSignal(GroupEventContext context, int groupId, int gadgetSignalId);
int SendServerMessageByLuaKey(GroupEventContext context, String var1, LuaTable var2);
int SendServerMessageByLuaKey(GroupEventContext context, String messageKey, int[] targets);
int TryReallocateEntityAuthority(GroupEventContext context, int uid, int endConfig, int var3);
@ -219,9 +222,9 @@ public interface ScriptLibHandler<GroupEventContext extends GroupEventLuaContext
int MoveAvatarByPointArray(GroupEventContext context, int uid, int targetId, LuaTable var3, String var4);
int MovePlayerToPos(GroupEventContext context, LuaTable table);
int MovePlayerToPos(GroupEventContext context, int[] targetUIds, Position pos, Position rot, int radius, boolean isSkipUi);
int TransPlayerToPos(GroupEventContext context, LuaTable table);
int TransPlayerToPos(GroupEventContext context, int[] targetUIds, Position pos, Position rot, int radius, boolean isSkipUi);
int PlayCutScene(GroupEventContext context, int cutsceneId, int var2);
@ -379,6 +382,38 @@ public interface ScriptLibHandler<GroupEventContext extends GroupEventLuaContext
*/
int AssignPlayerUidOpNotify(GroupEventContext context, LuaTable param1Table);
/**
* TODO better parameter handling and verify active handling
* Calls a lua function in the specified group if the group is active. The call parameters are passed to the called parameters like this:
* [new context], [this function calls context], [call parameter 1], [call parameter 2]...
* @param groupId group id of the group to call the function in
* @param functionName name of the function to call
* @param callParamsTable lua array containing the parameters to pass to the function on call
*/
int ExecuteActiveGroupLua(GroupEventLuaContext context, int groupId, String functionName, LuaTable callParamsTable);
/**
* TODO better parameter handling
* Calls a lua function in the specified group. The call parameters are passed to the called parameters like this:
* [new context], [this function calls context], [call parameter 1], [call parameter 2]...
* @param groupId group id of the group to call the function in
* @param functionName name of the function to call
* @param callParamsTable lua array containing the parameters to pass to the function on call
*/
int ExecuteGroupLua(GroupEventLuaContext context, int groupId, String functionName, LuaTable callParamsTable);
/**
* // TODO identify unknown parameters and exact behaviour
* Executes a lua function on a gadgets lua controller.
* This seems to be used in only the Crucible activity
* @param groupId group to find the gadget in
* @param gadgetCfgId cfg id of the gadget in the group to execute lua in
* @param activityType seems to be an activity type
* @param var4 TODO
* @param val5 TODO
*/
int ExecuteGadgetLua(GroupEventLuaContext context, int groupId, int gadgetCfgId, int activityType, int var4, int val5);
/**
* Methods used in EntityControllers/using ControllerEventContext