Broadcast global value changes

This commit is contained in:
KingRainbow44 2023-08-27 13:36:39 -04:00
parent 01766a0303
commit bd59da8853
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
4 changed files with 43 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.server.packet.send.PacketServerGlobalValueChangeNotify;
@AbilityAction(AbilityModifierAction.Type.CopyGlobalValue)
public final class ActionCopyGlobalValue extends AbilityActionHandler {
@ -30,6 +31,11 @@ public final class ActionCopyGlobalValue extends AbilityActionHandler {
// Apply the new global value.
destination.getGlobalAbilityValues().put(action.dstKey, value);
destination.onAbilityValueUpdate();
// Send a value update packet.
entity.getScene().getHost().sendPacket(
new PacketServerGlobalValueChangeNotify(entity, action.dstKey, value));
return true;
}
}

View File

@ -0,0 +1,29 @@
package emu.grasscutter.game.ability.actions;
import com.google.protobuf.ByteString;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.server.packet.send.PacketServerGlobalValueChangeNotify;
@AbilityAction(AbilityModifierAction.Type.SetGlobalValue)
public final class ActionSetGlobalValue extends AbilityActionHandler {
@Override
public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
// Get the key & value.
var valueKey = action.key;
var value = action.ratio;
// Set the global value.
target.getGlobalAbilityValues().put(valueKey, value.get(ability));
// Update the target.
target.onAbilityValueUpdate();
// Send a value update packet.
target.getScene().getHost().sendPacket(
new PacketServerGlobalValueChangeNotify(target, valueKey, value.get(ability)));
return false;
}
}

View File

@ -5,9 +5,10 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.game.ability.Ability;
import emu.grasscutter.game.entity.*;
import emu.grasscutter.server.packet.send.PacketServerGlobalValueChangeNotify;
@AbilityAction(AbilityModifierAction.Type.SetGlobalValueToOverrideMap)
public class ActionSetGlobalValueToOverrideMap extends AbilityActionHandler {
public final class ActionSetGlobalValueToOverrideMap extends AbilityActionHandler {
@Override
public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) {
@ -36,8 +37,11 @@ public class ActionSetGlobalValueToOverrideMap extends AbilityActionHandler {
ability
.getAbilitySpecials()
.put(action.overrideMapKey, globalValue.floatValue()); // Override our own.
entity.onAbilityValueUpdate();
// TODO: ChangeServerGlobalValueNotify
// Send a value update packet.
entity.getScene().getHost().sendPacket(
new PacketServerGlobalValueChangeNotify(entity, globalValueKey, globalValue));
return true;
}

View File

@ -7,7 +7,7 @@ import emu.grasscutter.net.proto.ServerGlobalValueChangeNotifyOuterClass.ServerG
import emu.grasscutter.utils.Utils;
public final class PacketServerGlobalValueChangeNotify extends BasePacket {
public PacketServerGlobalValueChangeNotify(GameEntity entity, String abilityHash, int value) {
public PacketServerGlobalValueChangeNotify(GameEntity entity, String abilityHash, float value) {
super(PacketOpcodes.ServerGlobalValueChangeNotify);
this.setData(
@ -17,7 +17,7 @@ public final class PacketServerGlobalValueChangeNotify extends BasePacket {
.setKeyHash(Utils.abilityHash(abilityHash)));
}
public PacketServerGlobalValueChangeNotify(int entityId, String abilityHash, int value) {
public PacketServerGlobalValueChangeNotify(int entityId, String abilityHash, float value) {
super(PacketOpcodes.ServerGlobalValueChangeNotify);
this.setData(