public override void StateExit() { //Revive any dead party members foreach (var unit in gameManager.CurrentPartyMembers) { RPGActor actor = unit.GetComponent <RPGActor>(); if (actor.Properties.CurrentHealth == 0) { actor.RestoreHP(20, true); } //Potentially check against the state of the unit (i.e: Dead) and clear status ailments,... } }
//Happens every frame public void Update() { if (actor.State == ActorState.Engaged && actor.TargetObject != null && actor.Target.State != ActorState.Dead) { //Rotate leader towards target when we're not moving ourselves if (actor.IsLeader && !GetComponent <PlayerMove>().IsMoving) { rotateTowardsTarget(); } else if (!GetComponent <RPGActor>().IsLeader) //rotate other party members and enemies to target too { rotateTowardsTarget(); } UpdateLoop(); // var heading = actor.TargetObject.transform.position - this.transform.position; var distance = heading.magnitude; var direction = heading / distance; // This is now the normalized direction. float engageDist = 15; float minEngageDist = 5; EngageZone targetZone = actor.TargetObject.GetComponent <EngageZone>(); if (targetZone != null) { engageDist = targetZone.EngageZoneDistance; minEngageDist = targetZone.EngageZoneDistanceClosest; } //Too far, move towards enemy if (CanFollowTarget && Mathf.Abs(distance) >= engageDist) { thisRelativeToEnemy = PositionTowardsEnemy.TooFarAway; } //We're in the right range if (CanFollowTarget && Mathf.Abs(distance) < engageDist) { thisRelativeToEnemy = PositionTowardsEnemy.JustRight; } //Too close, move back if (CanFollowTarget && Mathf.Abs(distance) < minEngageDist) { thisRelativeToEnemy = PositionTowardsEnemy.TooClose; } //If we can't move, then just attack regardless of position (i.e for static enemies only) if (!CanFollowTarget) { thisRelativeToEnemy = PositionTowardsEnemy.JustRight; } switch (thisRelativeToEnemy) { case PositionTowardsEnemy.TooFarAway: HandleTooFar(); break; case PositionTowardsEnemy.JustRight: HandleJustRight(); break; case PositionTowardsEnemy.TooClose: HandleTooClose(); break; default: break; } } //Restore health at same interval as auto-attack tick when we're not in battle (so when we're idle) if (actor.State == ActorState.Idle && actor.Properties.CurrentHealth != actor.Properties.MaxHealth) { //Gradually restore our health currentAttackTimer -= Time.deltaTime; if (currentAttackTimer <= 0) { actor.RestoreHP(25, true); currentAttackTimer = AttackTimer; } } }