Implement scripting: SetEntityServerGlobalValueByConfigId

w/ help from: Moistcrafter#9172
This commit is contained in:
KingRainbow44 2023-04-11 21:07:29 -04:00
parent c1ea2b04ec
commit 71a8ca2a8a
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 25 additions and 2 deletions

View File

@ -512,8 +512,14 @@ public class ScriptLib {
} }
public int SetEntityServerGlobalValueByConfigId(int cfgId, String sgvName, int value){ public int SetEntityServerGlobalValueByConfigId(int cfgId, String sgvName, int value){
logger.warn("[LUA] Call unimplemented SetEntityServerGlobalValueByConfigId with {} {} {}", cfgId, sgvName, value); var scriptManager = this.getSceneScriptManager();
//TODO implement if (scriptManager == null) return 1;
var entity = scriptManager.getScene().getEntityByConfigId(cfgId);
if (entity == null) return 2;
scriptManager.getScene().getWorld().broadcastPacket(
new PacketServerGlobalValueChangeNotify(entity, sgvName, value));
return 0; return 0;
} }

View File

@ -0,0 +1,17 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ServerGlobalValueChangeNotifyOuterClass.ServerGlobalValueChangeNotify;
import emu.grasscutter.utils.Utils;
public final class PacketServerGlobalValueChangeNotify extends BasePacket {
public PacketServerGlobalValueChangeNotify(GameEntity entity, String abilityHash, int value) {
super(PacketOpcodes.ServerGlobalValueChangeNotify);
this.setData(ServerGlobalValueChangeNotify.newBuilder()
.setEntityId(entity.getId()).setValue(value)
.setKeyHash(Utils.abilityHash(abilityHash)));
}
}