Skip to content

Commit

Permalink
Set SkillSystem.playerAlive to match player's alive status
Browse files Browse the repository at this point in the history
  • Loading branch information
starfi5h committed Jul 1, 2024
1 parent 69ae317 commit 98357aa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
40 changes: 21 additions & 19 deletions NebulaPatcher/Patches/Dynamic/SkillSystem_Common_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ public static bool GeneralShieldBurst_Prefix(ref GeneralShieldBurst __instance,
return false;
}

static void SwtichPlayerState(int playerId)
static void SwitchPlayerState(int playerId)
{
if (!Multiplayer.Session.Combat.IndexByPlayerId.TryGetValue(playerId, out var index)) return;

ref var playerData = ref Multiplayer.Session.Combat.Players[index];
var skillSystem = GameMain.data.spaceSector.skillSystem;
skillSystem.mecha = playerData.mecha;
skillSystem.playerAlive = playerData.isAlive;
skillSystem.playerSkillTargetL = playerData.skillTargetL;
skillSystem.playerSkillTargetULast = playerData.skillTargetULast;
skillSystem.playerSkillTargetU = playerData.skillTargetU;
Expand All @@ -49,13 +50,14 @@ static void SwtichPlayerState(int playerId)
skillSystem.playerSkillCastRightU = playerData.skillTargetU;
}

static void SwtichTargetPlayerWithCollider(int playerId)
static void SwitchTargetPlayerWithCollider(int playerId)
{
if (!Multiplayer.Session.Combat.IndexByPlayerId.TryGetValue(playerId, out var index)) return;

ref var playerData = ref Multiplayer.Session.Combat.Players[index];
var skillSystem = GameMain.data.spaceSector.skillSystem;
skillSystem.mecha = playerData.mecha;
skillSystem.playerAlive = playerData.isAlive;
skillSystem.playerSkillTargetL = playerData.skillTargetL;
skillSystem.playerSkillTargetULast = playerData.skillTargetULast;
skillSystem.playerSkillTargetU = playerData.skillTargetU;
Expand All @@ -66,78 +68,78 @@ static void SwtichTargetPlayerWithCollider(int playerId)
public static void GeneralExpImpProjectile_Prefix(ref GeneralExpImpProjectile __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichTargetPlayerWithCollider(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchTargetPlayerWithCollider(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(GeneralMissile), nameof(GeneralMissile.TickSkillLogic))]
public static void GeneralProjectile_Prefix(ref GeneralMissile __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichTargetPlayerWithCollider(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchTargetPlayerWithCollider(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(GeneralProjectile), nameof(GeneralProjectile.TickSkillLogic))]
public static void GeneralProjectile_Prefix(ref GeneralProjectile __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichTargetPlayerWithCollider(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchTargetPlayerWithCollider(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(LocalGeneralProjectile), nameof(LocalGeneralProjectile.TickSkillLogic))]
public static void LocalGeneralProjectile_Prefix(ref LocalGeneralProjectile __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichTargetPlayerWithCollider(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchTargetPlayerWithCollider(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(LocalLaserContinuous), nameof(LocalLaserContinuous.TickSkillLogic))]
public static void LocalLaserContinuous_Prefix(ref LocalLaserContinuous __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichPlayerState(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchPlayerState(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(LocalLaserOneShot), nameof(LocalLaserOneShot.TickSkillLogic))]
public static void LocalLaserOneShot_Prefix(ref LocalLaserOneShot __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichPlayerState(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchPlayerState(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(LocalCannonade), nameof(LocalCannonade.TickSkillLogic))]
public static void LocalCannonade_Prefix(ref LocalCannonade __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(SpaceLaserOneShot), nameof(SpaceLaserOneShot.TickSkillLogic))]
public static void SpaceLaserOneShot_Prefix(ref SpaceLaserOneShot __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichPlayerState(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchPlayerState(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(SpaceLaserSweep), nameof(SpaceLaserSweep.TickSkillLogic))]
public static void SpaceLaserSweep_Prefix(ref SpaceLaserSweep __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if ((__instance.mask & ETargetTypeMask.Player) != 0) SwtichTargetPlayerWithCollider(Multiplayer.Session.LocalPlayer.Id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if ((__instance.mask & ETargetTypeMask.Player) != 0) SwitchTargetPlayerWithCollider(Multiplayer.Session.LocalPlayer.Id);
}
}
11 changes: 11 additions & 0 deletions NebulaPatcher/Patches/Dynamic/SkillSystem_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public static bool Import_Prefix(SkillSystem __instance, BinaryReader r)
return false;
}

[HarmonyPostfix]
[HarmonyPatch(nameof(SkillSystem.CollectPlayerStates))]
public static void CollectPlayerStates_Postfix(SkillSystem __instance)
{
if (!Multiplayer.IsActive) return;

// Set those flags to false so AddSpaceEnemyHatred can add threat correctly for client's skill in host
__instance.playerIsSailing = false;
__instance.playerIsWarping = false;
}

[HarmonyPostfix]
[HarmonyPatch(nameof(SkillSystem.AfterTick))]
public static void AfterTick_Postfix(SkillSystem __instance)
Expand Down

0 comments on commit 98357aa

Please sign in to comment.