Exemple #1
0
    private void EngageDivision(ControlledDivision Host)
    {
        var rememberedTarget = GetRememberedDivisionFromHost(Host, RememberedTargetId);

        //if the target has been destroyed do nothing and to end the order
        if (rememberedTarget.HasBeenDestroyed)
        {
            OngoingOrder = new EmptyOrder();
            Canceled     = true;
            return;
        }

        if (Host.FindVisibleDivision(RememberedTargetId, out ControlledDivision division))
        {
            var distanceToTarget = (division.Controller.transform.position - Host.Controller.transform.position).magnitude;

            //need to move closer
            if (distanceToTarget > Host.MaxHitRange)
            {
                StartOrder(Host, new Move(Host, CommanderSendingOrderId, division.Position, Host.MaxHitRange * .5f));
            }
            else
            {
                //if the target is within range attack
                StartOrder(Host, new AttackOrder(Host, CommanderSendingOrderId, division.DivisionId, Host.MaxHitRange));
            }
        }
        else
        {
            //else go find him again
            StartOrder(Host, new FindDivision(Host, CommanderSendingOrderId, RememberedTargetId, Host.MaxSightDistance));
        }
    }
    public override void Proceed(ControlledDivision Host)
    {
        if (!IsFinished && Host.FindVisibleDivision(RememberedTargetId, out ControlledDivision division))
        {
            var distanceToTarget = (division.Controller.transform.position - Host.Controller.transform.position).magnitude;
            if (distanceToTarget > Host.MaxHitRange)
            {
                IsFinished = true;
                return;
            }

            float totalAttackerDamage = 0;
            for (int i = 0; i < Host.Soldiers.Count; i++)
            {
                Soldier soldier = Host.Soldiers[i];

                if (distanceToTarget > soldier.MinRange && distanceToTarget < soldier.MaxRange)
                {
                    var result = soldier.Attack(ref division, distanceToTarget);
                    totalAttackerDamage += result.DamageToDefender;
                }
            }


            bool isDestroyed     = division.CheckDamageDone(Host);
            bool isHostDestroyed = Host.CheckDamageDone(division);
            if (isDestroyed)
            {
                RememberedDivision RememberedTarget = GetRememberedDivisionFromHost(Host, RememberedTargetId);
                RememberedTarget.HasBeenDestroyed = true;
                RememberedTarget.TimeStamp        = GameManager.Instance.GameTime;
                IsFinished = true;
            }
        }
    }
 public override void Proceed(ControlledDivision Host)
 {
     if (Host.FindVisibleDivision(TargetId, out ControlledDivision divisionToMergeWith))
     {
         Host.ShareMapInformation(divisionToMergeWith);
         FinishedSharing = true;
     }
 }
    public override void Proceed(ControlledDivision Host)
    {
        if (Host.FindVisibleDivision(RememberedTargetId, out _visibleTarget))
        {
            if (RememberedTargetId == _endTargetId)
            {
                _visibleTarget.ReceiveOrders(_message);
            }
            else
            {
                _visibleTarget.SendOrdersTo(GetRememberedDivisionFromHost(_visibleTarget, _endTargetId),
                                            _message, ref _visibleTarget.RememberedDivisions);
            }

            _hasFoundTarget = true;
        }
    }
Exemple #5
0
    public override bool TestIfFinished(ControlledDivision Host)
    {
        ControlledDivision visibleTarget;

        if (Host.FindVisibleDivision(RememberedTargetId, out visibleTarget))
        {
            if (visibleTarget.HasBeenDestroyed)
            {
                return(true);
            }

            Vector3 currLoc          = Host.Controller.transform.position;
            float   distanceToFinish = (visibleTarget.Controller.transform.position - currLoc).magnitude;
            if (distanceToFinish < _thresholdDistance)
            {
                return(true);
            }
        }

        return(false);
    }