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]; } } } }
public void AddSoldier(BaseSoldier soldier) { if (CurCount < MaxCount) { Soldiers.Add(soldier); soldier.TentID = ID; soldier.OnSoldierDie += OnSoldierDie; CurCount++; } }
public void OnTargetGet(BaseRole target) { if (target != null) { AttackWilling = 1.0f; } else { AttackWilling = 0.1f; } CurTarget = (BaseSoldier)target; }
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); }
public TargetSystem(BaseSoldier owner) { Owner = owner; }
public virtual void ClearTarget() { CurTarget = null; }
public FSMSoldierAlertState(BaseSoldier owner)// : base(owner) { Owner = owner; }
public FSMSoldierAttackState(BaseSoldier owner)// : base(owner) { Owner = owner; }