Skip to content

Commit

Permalink
Fix FlingObjectsFromGlobalPoolTime action networking and improve en…
Browse files Browse the repository at this point in the history
…tities
  • Loading branch information
Extremelyd1 committed Dec 22, 2023
1 parent 6894cd0 commit 479d8f3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 76 deletions.
32 changes: 13 additions & 19 deletions HKMP/Game/Client/Entity/Action/EntityFsmActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2701,28 +2701,10 @@ IEnumerator Behaviour() {
#region FlingObjectsFromGlobalPoolTime

private static bool GetNetworkDataFromAction(EntityNetworkData data, FlingObjectsFromGlobalPoolTime action) {
data.Packet.Write(action.angleMin.Value);
data.Packet.Write(action.angleMax.Value);

return true;
}

private static void ApplyNetworkDataFromAction(EntityNetworkData data, FlingObjectsFromGlobalPoolTime action) {
var angleMin = data.Packet.ReadFloat();
var angleMax = data.Packet.ReadFloat();

var position = Vector3.zero;

var spawnPoint = action.spawnPoint.Value;
if (spawnPoint != null) {
position = spawnPoint.transform.position;
if (!action.position.IsNone) {
position += action.position.Value;
}
} else if (!action.position.IsNone) {
position = action.position.Value;
}

var coroutine = MonoBehaviourUtil.Instance.StartCoroutine(Behaviour());

new ActionInState {
Expand All @@ -2739,6 +2721,18 @@ IEnumerator Behaviour() {
break;
}

var position = Vector3.zero;

var spawnPoint = action.spawnPoint.Value;
if (spawnPoint != null) {
position = spawnPoint.transform.position;
if (!action.position.IsNone) {
position += action.position.Value;
}
} else if (!action.position.IsNone) {
position = action.position.Value;
}

var numSpawns = Random.Range(action.spawnMin.Value, action.spawnMax.Value + 1);
for (var i = 0; i < numSpawns; i++) {
var gameObject = action.gameObject.Value.Spawn(position, Quaternion.Euler(Vector3.zero));
Expand All @@ -2759,7 +2753,7 @@ IEnumerator Behaviour() {
}

var speed = Random.Range(action.speedMin.Value, action.speedMax.Value);
var angle = Random.Range(angleMin, angleMax);
var angle = Random.Range(action.angleMin.Value, action.angleMax.Value);

var x = speed * Mathf.Cos(angle * ((float) System.Math.PI / 180f));
var y = speed * Mathf.Sin(angle * ((float) System.Math.PI / 180f));
Expand Down
118 changes: 61 additions & 57 deletions HKMP/Game/Client/Entity/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,11 +1149,11 @@ public void UpdateHostFsmData(Dictionary<byte, EntityHostFsmData> hostFsmData) {
continue;
}

var fsm = _fsms.Host[fsmIndex];
var hostFsm = _fsms.Host[fsmIndex];
var snapshot = _fsmSnapshots[fsmIndex];

if (data.Types.Contains(EntityHostFsmData.Type.State)) {
var states = fsm.FsmStates;
var states = hostFsm.FsmStates;
if (states.Length <= data.CurrentState) {
Logger.Warn($"Tried to update host FSM state for unknown state index: {data.CurrentState}");
} else {
Expand All @@ -1167,6 +1167,8 @@ public void UpdateHostFsmData(Dictionary<byte, EntityHostFsmData> hostFsmData) {
}
}

var fsms = new[] { hostFsm, _fsms.Client[fsmIndex] };

void CondUpdateVars<FsmType, BaseType>(
EntityHostFsmData.Type type,
Dictionary<byte, BaseType> dataDict,
Expand All @@ -1183,61 +1185,63 @@ Action<byte, FsmType, BaseType> setValueAction
}
}
}

CondUpdateVars(
EntityHostFsmData.Type.Floats,
data.Floats,
fsm.FsmVariables.FloatVariables,
(index, fsmVar, value) => {
fsmVar.Value = value;
snapshot.Floats[index] = value;
}
);
CondUpdateVars(
EntityHostFsmData.Type.Ints,
data.Ints,
fsm.FsmVariables.IntVariables,
(index, fsmVar, value) => {
fsmVar.Value = value;
snapshot.Ints[index] = value;
}
);
CondUpdateVars(
EntityHostFsmData.Type.Bools,
data.Bools,
fsm.FsmVariables.BoolVariables,
(index, fsmVar, value) => {
fsmVar.Value = value;
snapshot.Bools[index] = value;
}
);
CondUpdateVars(
EntityHostFsmData.Type.Strings,
data.Strings,
fsm.FsmVariables.StringVariables,
(index, fsmVar, value) => {
fsmVar.Value = value;
snapshot.Strings[index] = value;
}
);
CondUpdateVars(
EntityHostFsmData.Type.Vector2s,
data.Vec2s,
fsm.FsmVariables.Vector2Variables,
(index, fsmVar, value) => {
fsmVar.Value = (UnityEngine.Vector2) value;
snapshot.Vector2s[index] = (UnityEngine.Vector2) value;
}
);
CondUpdateVars(
EntityHostFsmData.Type.Vector3s,
data.Vec3s,
fsm.FsmVariables.Vector3Variables,
(index, fsmVar, value) => {
fsmVar.Value = (Vector3) value;
snapshot.Vector3s[index] = (Vector3) value;
}
);

foreach (var fsm in fsms) {
CondUpdateVars(
EntityHostFsmData.Type.Floats,
data.Floats,
fsm.FsmVariables.FloatVariables,
(index, fsmVar, value) => {
fsmVar.Value = value;
snapshot.Floats[index] = value;
}
);
CondUpdateVars(
EntityHostFsmData.Type.Ints,
data.Ints,
fsm.FsmVariables.IntVariables,
(index, fsmVar, value) => {
fsmVar.Value = value;
snapshot.Ints[index] = value;
}
);
CondUpdateVars(
EntityHostFsmData.Type.Bools,
data.Bools,
fsm.FsmVariables.BoolVariables,
(index, fsmVar, value) => {
fsmVar.Value = value;
snapshot.Bools[index] = value;
}
);
CondUpdateVars(
EntityHostFsmData.Type.Strings,
data.Strings,
fsm.FsmVariables.StringVariables,
(index, fsmVar, value) => {
fsmVar.Value = value;
snapshot.Strings[index] = value;
}
);
CondUpdateVars(
EntityHostFsmData.Type.Vector2s,
data.Vec2s,
fsm.FsmVariables.Vector2Variables,
(index, fsmVar, value) => {
fsmVar.Value = (UnityEngine.Vector2) value;
snapshot.Vector2s[index] = (UnityEngine.Vector2) value;
}
);
CondUpdateVars(
EntityHostFsmData.Type.Vector3s,
data.Vec3s,
fsm.FsmVariables.Vector3Variables,
(index, fsmVar, value) => {
fsmVar.Value = (Vector3) value;
snapshot.Vector3s[index] = (Vector3) value;
}
);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions HKMP/Resource/action-registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,8 @@
},
{
"type": "ChaseObjectGround"
},
{
"type": "FlingObjectsFromGlobalPoolTime"
}
]

0 comments on commit 479d8f3

Please sign in to comment.