示例#1
0
        public override void PerformAction(CommandSystem commandSystem)
        {
            var fullyHealBehavior    = new FullyHeal();
            var runAwayBehavior      = new RunAway();
            var shoutForHelpBehavior = new ShoutForHelp();

            if (_turnsSpentRunning.HasValue && _turnsSpentRunning.Value > 15)
            {
                fullyHealBehavior.Act(this, commandSystem);
                _turnsSpentRunning = null;
            }
            else if (Health < MaxHealth)
            {
                runAwayBehavior.Act(this, commandSystem);
                if (_turnsSpentRunning.HasValue)
                {
                    _turnsSpentRunning += 1;
                }
                else
                {
                    _turnsSpentRunning = 1;
                }

                if (!_shoutedForHelp)
                {
                    _shoutedForHelp = shoutForHelpBehavior.Act(this, commandSystem);
                }
            }
            else
            {
                base.PerformAction(commandSystem);
            }
        }
示例#2
0
    private void Awake()
    {
        var navMeshAgent = GetComponent <NavMeshAgent>();

        _stateMachine = new StateMachine();

        inputReader = GetComponent <InputReader>();
        rb          = GetComponent <Rigidbody>();

        var idle    = new Idle(this, slowRate);
        var move    = new Move(this, inputReader, speed);
        var jump    = new Jump(this, jumpSpeed);
        var fall    = new Fall();
        var runAway = new RunAway(this, runAwayDestination);

        At(idle, move, () => HasMoveInput());
        At(move, idle, () => !HasMoveInput());
        At(idle, jump, () => HasJumpInput() && isGrounded);
        At(move, jump, () => HasJumpInput() && isGrounded);
        At(jump, fall, () => isFalling());
        At(fall, idle, () => isGrounded);
        At(runAway, idle, () => !isRunningAway);

        _stateMachine.AddAnyTransition(runAway, () => isRunningAway);

        _stateMachine.SetState(fall);

        void At(IState from, IState to, Func <bool> condition) => _stateMachine.AddTransition(from, to, condition);
    }
示例#3
0
 public static RunAway Instance()
 {
     if (RunAway.singleton == null)
     {
         RunAway.singleton = new RunAway();
     }
     return(RunAway.singleton);
 }
示例#4
0
 public override void Update()
 {
     if (Vector3.Distance(agent.transform.position, enemy.transform.position) < 5)
     {
         nextState = new RunAway(npc, agent, animator, enemy);
         base.Exit();
     }
     if (agent.remainingDistance < 1)
     {
         if (currentIndex >= GameEnvironment.Singleton.Checkpoints.Count - 1)
         {
             currentIndex = 0;
         }
         else
         {
             currentIndex++;
         }
         agent.SetDestination(GameEnvironment.Singleton.Checkpoints[currentIndex].transform.position);
     }
 }
示例#5
0
    void ContinueAction()
    {
        // make counter list
        for (int j = 0; j < reportAction_.counters_.Length; ++j)
        {
            counterLst_.Add(reportAction_.counters_[j]);
        }

        /// add state
        for (int i = 0; i < reportAction_.stateIds_.Length; ++i)
        {
            BattleActor actor = Battle.Instance.GetActorByInstId(reportAction_.stateIds_[i].ownerId_);
            //如果大于1 则延迟加buff
            if (reportAction_.stateIds_[i].addQueue_ > 0)
            {
                //如果目标是自己 加到行动后state列表,否则加到延迟state列表
                if (reportAction_.stateIds_[i].ownerId_ == m_PlayerID)
                {
                    afterActionBuff.Add(reportAction_.stateIds_[i]);
                }
                else
                {
                    actor.ControlEntity.lagStateList.Add(reportAction_.stateIds_[i]);
                }
                continue;
            }
            if (reportAction_.stateIds_[i].add_)
            {
                actor.ControlEntity.AddState(reportAction_.stateIds_[i]);
            }
            else
            {
                actor.ControlEntity.RemoveState((int)reportAction_.stateIds_[i].stateId_);
            }
        }

        /// deal self state.
        ExcuteState(StateInst.ExcuteType.ET_Action, (COM_ReportActionCounter counter) =>
        {
            /// do action
            BattleActor caster = Battle.Instance.GetActorByInstId(reportAction_.casterId_);
            if (caster == null)
            {
                //DealAfterActionState();
                return;
            }
            SkillData data = null;
            data           = SkillData.GetData((int)reportAction_.skill_, (int)reportAction_.skillLevel_);
            /// extra skill
            if (data == null)
            {
                if (reportAction_.status_ == OrderStatus.OS_Weapon)
                {
                    COM_Item inst = new COM_Item();
                    inst.itemId_  = (uint)reportAction_.itemId_;
                    inst.instId_  = (uint)reportAction_.weaponInstId_;
                    if (inst.itemId_ != 0)
                    {
                        Battle.Instance.GetActorByInstId(reportAction_.casterId_).wearEquip(inst);
                    }
                    else
                    {
                        Battle.Instance.GetActorByInstId(reportAction_.casterId_).demontWeapon();
                    }
                }
                DealAfterActionState();
                return;
            }
            else
            {
                if (data._SkillType == SkillType.SKT_DefaultSecPassive || data._SkillType == SkillType.SKT_Passive)
                {
                    DealAfterActionState();
                    return;
                }
                switch (data._Passive_type)
                {
                case PassiveType.PAT_Runaway:
                    RunAway ra = new RunAway();
                    ra.Run(caster, Battle.Instance.GetActorByInstId(reportAction_.babyId_), reportAction_.status_.Equals(OrderStatus.OS_RunawayOk), (ParamData pdata) =>
                    {
                        DealAfterActionState();
                    });
                    return;

                case PassiveType.PAT_Change:
                    ChangePosition cp = new ChangePosition();
                    cp.ChangePos((int)reportAction_.bp0_, (int)reportAction_.bp1_, (ParamData pdata) =>
                    {
                        DealAfterActionState();
                    });
                    return;

                case PassiveType.PAT_BabyInnout:
                    BabyInnOut bio = new BabyInnOut();
                    bio.Excute(caster, reportAction_.status_, reportAction_.babyId_, reportAction_.baby_, DealAfterActionState);
                    ClearState();
                    return;

                case PassiveType.PAT_SecKill:
                    Seckill sk      = new Seckill();
                    SkillData sdata = SkillData.GetData((int)reportAction_.skill_, (int)reportAction_.skillLevel_);
                    if (sdata._Cast_effectID != -1)
                    {
                        EffectAPI.Play((EFFECT_ID)sdata._Cast_effectID, caster.ControlEntity.ActorObj, null, null, (int iVal) =>
                        {
                            if (reportAction_.targets_ == null || reportAction_.targets_.Length == 0)
                            {
                                ClientLog.Instance.Log("Sec Kill has no target!");
                                return;
                            }
                            sk.Do(caster, Battle.Instance.GetActorByIdx((int)reportAction_.targets_[0].position_), DealAfterActionState);
                        });
                    }
                    else
                    {
                        if (reportAction_.targets_ == null || reportAction_.targets_.Length == 0)
                        {
                            ClientLog.Instance.Log("Sec Kill has no target!");
                            return;
                        }
                        sk.Do(caster, Battle.Instance.GetActorByIdx((int)reportAction_.targets_[0].position_), DealAfterActionState);
                    }
                    return;

                default:
                    if (reportAction_.status_ == OrderStatus.OS_None)
                    {
                        DealAfterActionState();
                        return;
                    }
                    else if (reportAction_.status_ == OrderStatus.OS_Zhuachong)
                    {
                        CatchBaby cb = new CatchBaby();
                        cb.Catch(reportAction_, DealAfterActionState);
                        return;
                    }
                    else if (reportAction_.status_ == OrderStatus.OS_Summon)
                    {
//                        List<COM_Entity> entities = new List<COM_Entity>(reportAction_.dynamicEntities_);
//                        Battle.Instance.AddNewActor(entities.ToArray());//, () =>
////							 {
////								DealAfterActionState();
////							 }, reportAction_.dynamicEntities_.Length);
//                        DealAfterActionState();
//                            return;
                        break;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (reportAction_.targets_.Length == 0)
            {
                if (reportAction_.status_ == OrderStatus.OS_Summon)
                {
                    mainSkillInst = new SkillInst();
                    mainSkillInst.Cast(reportAction_.skill_, reportAction_.skillLevel_, caster, null, reportAction_.targets_, FinishShow, DealCounterAction);
                }
                else
                {
                    DealAfterActionState();
                }
                return;
            }

            /// normal skill
            List <BattleActor> aims = new List <BattleActor>();
            for (int i = 0; i < reportAction_.targets_.Length; ++i)
            {
                BattleActor item = Battle.Instance.GetActorByIdx((int)reportAction_.targets_[i].position_);
                //				if( null == item || item.isDead ) continue;
                aims.Add(item);
            }

            //TODO for temp
            if (aims.Count == 0)
            {
                aims.Add(Battle.Instance.GetActorByInstId(reportAction_.casterId_));
            }
            ///////
            for (int i = 0; i < aims.Count; ++i)
            {
                if (aims[i] == null)
                {
                    continue;
                }
                aims[i].ForGuardPos = (int)reportAction_.huweiPosition_;
            }
            mainSkillInst = new SkillInst();
            //ClientLog.Instance.Log("宠物 No!  Cast: " + reportAction_.skill_ + "  caster : " + caster.InstName + " aim: " + aims[0].InstName + " len:" + aims.Count + " target: " + reportAction_.targets_[0].position_ + " len:" + reportAction_.targets_.Length);
            mainSkillInst.Cast(reportAction_.skill_, reportAction_.skillLevel_, caster, aims.ToArray(), reportAction_.targets_, FinishShow, DealCounterAction);
        });

        //// 处理需要除掉的actor
        //DealEraseActor();
    }
示例#6
0
 private void Awake()
 {
     alertState = new AlertState(this);
     patrol     = new Patrol(this);
     runAway    = new RunAway(this);
 }
示例#7
0
 public static RunAway creaRunAway()
 {
     return(RunAway.Instance());
 }