fix group logic

This commit is contained in:
in0finite 2021-09-12 23:03:53 +02:00
parent e0f89e1e47
commit d2fe1b1cfb

View file

@ -87,11 +87,11 @@ namespace SanAndreasUnity.Behaviours
{ {
Ped attackerPed = dmgInfo.GetAttackerPed(); Ped attackerPed = dmgInfo.GetAttackerPed();
if (attackerPed != null)
_enemyPeds.AddIfNotPresent(attackerPed);
if (this.Action == PedAIAction.Following) if (this.Action == PedAIAction.Following)
{ {
if (null == attackerPed)
return;
if (attackerPed == this.TargetPed) if (attackerPed == this.TargetPed)
{ {
// our leader attacked us // our leader attacked us
@ -100,9 +100,18 @@ namespace SanAndreasUnity.Behaviours
return; return;
} }
if (!this.IsMemberOfOurGroup(attackerPed))
{
_enemyPeds.AddIfNotPresent(attackerPed);
return;
}
return; return;
} }
if (attackerPed != null)
_enemyPeds.AddIfNotPresent(attackerPed);
if (this.Action == PedAIAction.Idle || this.Action == PedAIAction.WalkingAround) if (this.Action == PedAIAction.Idle || this.Action == PedAIAction.WalkingAround)
{ {
var hitPed = this.MyPed; var hitPed = this.MyPed;
@ -131,15 +140,8 @@ namespace SanAndreasUnity.Behaviours
if (this.Action == PedAIAction.Following) if (this.Action == PedAIAction.Following)
{ {
bool isAttackerPartOfOurGroup = true; if (this.IsMemberOfOurGroup(attackerPed))
var attackerPedAi = attackerPed.GetComponent<PedAI>();
if (null == attackerPedAi || attackerPedAi.Action != PedAIAction.Following || attackerPedAi.TargetPed != this.TargetPed)
isAttackerPartOfOurGroup = false;
if (isAttackerPartOfOurGroup)
{
return; return;
}
if (this.TargetPed == otherPed) if (this.TargetPed == otherPed)
{ {
@ -149,8 +151,7 @@ namespace SanAndreasUnity.Behaviours
return; return;
} }
var otherPedAi = otherPed.GetComponent<PedAI>(); if (this.IsMemberOfOurGroup(otherPed))
if (otherPedAi != null && otherPedAi.Action == PedAIAction.Following && otherPedAi.TargetPed == this.TargetPed)
{ {
// attacked ped is member of our group // attacked ped is member of our group
// his enemy will be also our enemy // his enemy will be also our enemy
@ -163,6 +164,21 @@ namespace SanAndreasUnity.Behaviours
} }
bool IsMemberOfOurGroup(Ped ped)
{
if (this.Action != PedAIAction.Following || this.TargetPed == null) // we are not part of any group
return false;
if (this.TargetPed == ped) // our leader
return true;
var pedAI = ped.GetComponent<PedAI>();
if (pedAI != null && pedAI.Action == PedAIAction.Following && pedAI.TargetPed == this.TargetPed)
return true;
return false;
}
void Update() void Update()
{ {
this.MyPed.ResetInput(); this.MyPed.ResetInput();