Exemplo n.º 1
0
        public virtual void Process(float dt)
        {
            float sqrClosestDist = float.MaxValue;

            PotentialOps.Clear();

            CurTarget = null;

            PotentialOps = Owner.Sensor.GetRecentlySensedOpponents();

            for (int i = 0; i < PotentialOps.Count; i++)
            {
                if (PotentialOps[i].IsAlive &&
                    (!System.Object.ReferenceEquals(PotentialOps[i], Owner)) &&
                    PotentialOps[i] != Owner)
                {
                    if (PotentialOps[i].ID == Owner.ID)
                    {
                        int j = 0;
                    }

                    float sqrDist = Vector3.SqrMagnitude(Owner.Position -
                                                         PotentialOps[i].Position);

                    if (sqrDist < sqrClosestDist)
                    {
                        sqrClosestDist = sqrDist;
                        CurTarget      = PotentialOps[i];
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void AddSoldier(BaseSoldier soldier)
 {
     if (CurCount < MaxCount)
     {
         Soldiers.Add(soldier);
         soldier.TentID        = ID;
         soldier.OnSoldierDie += OnSoldierDie;
         CurCount++;
     }
 }
Exemplo n.º 3
0
        public void OnTargetGet(BaseRole target)
        {
            if (target != null)
            {
                AttackWilling = 1.0f;
            }
            else
            {
                AttackWilling = 0.1f;
            }

            CurTarget = (BaseSoldier)target;
        }
Exemplo n.º 4
0
        public FSMSoldierStateMachine(BaseSoldier owner) : base()
        {
            Owner = owner;

            FSMSoldierAlertState  alertState  = new FSMSoldierAlertState(owner);
            FSMSoldierAttackState attackState = new FSMSoldierAttackState(owner);

            AddNode(alertState);
            AddNode(attackState);

            CurState = alertState;

            //FSMSoldierTransition<BaseSoldier> trans1 = new FSMSoldierTransition<BaseSoldier>();
            //trans1.Src = alertState.ID;
            //trans1.Dst = attackState.ID;
            //trans1.TransitCondition((BaseSoldier par) => {
            //    return par.TargetSys.CurTarget &&
            //        CombatHolder.Instance.IsInAlertRange(par, par.TargetSys.CurTarget, 30.0f);
            //});
            //AddEdge(trans1);

            //FSMSoldierTransition<BaseSoldier> trans2 = new FSMSoldierTransition<BaseSoldier>();
            //trans2.TransitCondition((BaseSoldier par) => {
            //    return par.TargetSys.CurTarget == null ||
            //        !CombatHolder.Instance.IsInAlertRange(par, par.TargetSys.CurTarget, 30.0f);
            //});

            BaseTransition trans1 = new BaseTransition();

            trans1.Src = alertState.ID;
            trans1.Dst = attackState.ID;
            trans1.TransitCondition(() => {
                return(Owner.TargetSys.CurTarget != null && Owner.TargetSys.CurTarget.IsAlive);
                //&&
                //    CombatHolder.Instance.IsInAlertRange(Owner, Owner.TargetSys.CurTarget, 30.0f);
            });
            AddEdge(trans1);

            BaseTransition trans2 = new BaseTransition();

            trans2.TransitCondition(() => {
                return(Owner.TargetSys.CurTarget == null || !Owner.TargetSys.CurTarget.IsAlive);
                //||
                //    !CombatHolder.Instance.IsInAlertRange(Owner, Owner.TargetSys.CurTarget, 30.0f);
            });
            trans2.Src = attackState.ID;
            trans2.Dst = alertState.ID;
            AddEdge(trans2);
        }
Exemplo n.º 5
0
 public TargetSystem(BaseSoldier owner)
 {
     Owner = owner;
 }
Exemplo n.º 6
0
 public virtual void ClearTarget()
 {
     CurTarget = null;
 }
Exemplo n.º 7
0
 public FSMSoldierAlertState(BaseSoldier owner)// : base(owner)
 {
     Owner = owner;
 }
Exemplo n.º 8
0
 public FSMSoldierAttackState(BaseSoldier owner)// : base(owner)
 {
     Owner = owner;
 }