Beispiel #1
0
        BehaveResult Tick(Tree sender)
        {
            if (attackEnemy == null || attackEnemy.entityTarget == null || attackEnemy.entityTarget.target == null)
            {
                return(BehaveResult.Failure);
            }

            Enemy TargetEnemy = attackEnemy.entityTarget.target.GetAttackEnemy();

            if (TargetEnemy == null)
            {
                return(BehaveResult.Failure);
            }

            if (!NpcTypeDb.CanRun(NpcCmdId, ENpcControlType.Dodge))
            {
                return(BehaveResult.Failure);
            }

            if (attackEnemy.SqrDistanceXZ < 1.0f && attackEnemy.entityTarget.IsAttacking && TargetEnemy.entityTarget == entity)          //) //&& Random.value >= 0.3f
            {
                float   value = Random.value > 0.5f ? -1.0f : 1.0f;
                Vector3 ward  = Random.value > 0.5f ?  value * transform.right : -transform.forward;

                if (Random.value >= 0.3f && attackEnemy.entityTarget.IsAttacking)
                {
                    PEActionParamV param = PEActionParamV.param;
                    param.vec = ward;
                    DoAction(PEActionType.Step, param);
                }

                return(BehaveResult.Success);
            }
            return(BehaveResult.Failure);
        }
Beispiel #2
0
        BehaveResult Tick(Tree sender)
        {
            if (Random.value <= 0.7f)
            {
                return(BehaveResult.Failure);
            }

            if (!NpcTypeDb.CanRun(NpcCmdId, ENpcControlType.Block))
            {
                return(BehaveResult.Failure);
            }

            DoAction(PEActionType.HoldShield);
            return(BehaveResult.Success);
        }
Beispiel #3
0
        BehaveResult Init(Tree sender)
        {
            if (!NpcTypeDb.CanRun(NpcCmdId, ENpcControlType.Recourse))
            {
                return(BehaveResult.Failure);
            }

            float Hp    = GetAttribute(AttribType.Hp);
            float HpMax = GetAttribute(AttribType.HpMax);

//			Request req = GetRequest(EReqType.FollowPath) as RQFollowPath;
//			if(req != null && !req.CanRun())
//			{
//				specialRecurse = true;
//				specialRecursestartTime = Time.time;
//			}
//			else
//			{
//				specialRecurse = false;
//				specialRecursestartTime = -1;
//				if(req != null && req.CanRun())
//				{
//					if(entity.target != null && entity.target.GetAttackEnemy() != null)
//						entity.target.ClearEnemy();
//
//					return BehaveResult.Success;
//				}
//			}

            if (Hp / HpMax > 0.25f)          //!specialRecurse
            {
                return(BehaveResult.Failure);
            }

            if (PeCreature.Instance != null && PeCreature.Instance.mainPlayer != null && playerTrans == null)
            {
                playerTrans = PeCreature.Instance.mainPlayer.peTrans;
            }

            SetCambat(false);
            hideStarTime  = Time.time;
            checkStarTime = Time.time;
            mfind         = new Pathea.FindHidePos(8.0f, false);
            return(BehaveResult.Running);
        }
Beispiel #4
0
        BehaveResult Tick(Tree sender)
        {
            if (!NpcTypeDb.CanRun(NpcCmdId, ENpcControlType.Recourse))
            {
                return(BehaveResult.Failure);
            }

//			Request req = GetRequest(EReqType.FollowPath) as RQFollowPath;
//			if(req != null && !req.CanRun())
//			{
//				specialRecurse = true;
//			}
//			else
//			{
//				specialRecurse = false;
//			}


            if (Enemy.IsNullOrInvalid(attackEnemy))
            {
                return(BehaveResult.Success);
            }

            if (Time.time - checkStarTime > Check_TIME)
            {
                checkStarTime = Time.time;
                if (!entity.NpcCmpt.HasEnemyLocked())
                {
                    entity.target.ClearEnemy();
                }
            }

            float Hp    = GetAttribute(AttribType.Hp);
            float HpMax = GetAttribute(AttribType.HpMax);

            if (Hp / HpMax >= 0.3f)         //!specialRecurse &&
            {
                return(BehaveResult.Success);
            }

            if (Time.time - hideStarTime > HIDE_TIME)
            {
                mdir         = mfind.GetHideDir(playerTrans.position, position, Enemies);
                hideStarTime = Time.time;
            }

            Vector3 dirPos = position + mdir.normalized * 10.0f;

            if (mfind.bNeedHide)
            {
                MoveToPosition(dirPos, SpeedState.Run);
            }
            else
            {
                StopMove();
                FaceDirection(playerTrans.position - position);
            }

            //吃到了合适的属性值或者没有合适的药品时停止
            ItemAsset.ItemObject mEatItem;
            if (NpcEatDb.IsContinueEat(entity, out mEatItem))
            {
                if (entity.UseItem.GetCdByItemProtoId(mEatItem.protoId) < PETools.PEMath.Epsilon)
                {
                    UseItem(mEatItem);
                }
            }
            SetCambat(false);
            return(BehaveResult.Running);
        }
Beispiel #5
0
    // Update NPC reference for sub UIs
    void UpdateNPCRef(CSPersonnel npc)
    {
        m_NPCInfoUI.RefNpc      = npc;
        m_NPCEquipUI.RefNpc     = npc != null ? npc.NPC : null;
        m_NPCOccupaUI.RefNpc    = npc;
        m_NPCWorkerUI.RefNpc    = npc;
        m_NPCFarmerUI.RefNpc    = npc;
        m_NPCSoldierUI.RefNpc   = npc;
        m_NPCFollowerUI.RefNpc  = npc;
        m_NPCProcessorUI.RefNpc = npc;
        m_NpcDoctorUI.RefNpc    = npc;
        m_NpcInstructor.RefNpc  = npc;

        if (npc != null)
        {
            if (npc.m_Occupation == CSConst.potWorker)
            {
                m_NPCWorkerUI.gameObject.SetActive(true);
                m_NPCFarmerUI.gameObject.SetActive(false);
                m_NPCSoldierUI.gameObject.SetActive(false);
                m_NPCFollowerUI.gameObject.SetActive(false);
                m_NPCProcessorUI.gameObject.SetActive(false);
                m_NpcDoctorUI.gameObject.SetActive(false);
                m_NpcInstructor.gameObject.SetActive(false);
            }
            else if (npc.m_Occupation == CSConst.potFarmer)
            {
                m_NPCWorkerUI.gameObject.SetActive(false);
                m_NPCFarmerUI.gameObject.SetActive(true);
                m_NPCSoldierUI.gameObject.SetActive(false);
                m_NPCFollowerUI.gameObject.SetActive(false);
                m_NPCProcessorUI.gameObject.SetActive(false);
                m_NpcDoctorUI.gameObject.SetActive(false);
                m_NpcInstructor.gameObject.SetActive(false);
            }
            else if (npc.m_Occupation == CSConst.potSoldier)
            {
                m_NPCWorkerUI.gameObject.SetActive(false);
                m_NPCFarmerUI.gameObject.SetActive(false);
                m_NPCSoldierUI.gameObject.SetActive(true);
                m_NPCFollowerUI.gameObject.SetActive(false);
                m_NPCProcessorUI.gameObject.SetActive(false);
                m_NpcDoctorUI.gameObject.SetActive(false);
                m_NpcInstructor.gameObject.SetActive(false);
            }
            else if (npc.m_Occupation == CSConst.potFollower)
            {
                m_NPCWorkerUI.gameObject.SetActive(false);
                m_NPCFarmerUI.gameObject.SetActive(false);
                m_NPCSoldierUI.gameObject.SetActive(false);
                m_NPCFollowerUI.gameObject.SetActive(true);
                m_NPCProcessorUI.gameObject.SetActive(false);
                m_NpcDoctorUI.gameObject.SetActive(false);
                m_NpcInstructor.gameObject.SetActive(false);
            }
            else if (npc.m_Occupation == CSConst.potProcessor)
            {
                m_NPCWorkerUI.gameObject.SetActive(false);
                m_NPCFarmerUI.gameObject.SetActive(false);
                m_NPCSoldierUI.gameObject.SetActive(false);
                m_NPCFollowerUI.gameObject.SetActive(false);
                m_NPCProcessorUI.gameObject.SetActive(true);
                m_NpcDoctorUI.gameObject.SetActive(false);
                m_NpcInstructor.gameObject.SetActive(false);
            }
            else if (npc.m_Occupation == CSConst.potDoctor)
            {
                m_NPCWorkerUI.gameObject.SetActive(false);
                m_NPCFarmerUI.gameObject.SetActive(false);
                m_NPCSoldierUI.gameObject.SetActive(false);
                m_NPCFollowerUI.gameObject.SetActive(false);
                m_NPCProcessorUI.gameObject.SetActive(false);
                m_NpcDoctorUI.gameObject.SetActive(true);
                m_NpcInstructor.gameObject.SetActive(false);
            }
            else if (npc.m_Occupation == CSConst.potTrainer)
            {
                m_NPCWorkerUI.gameObject.SetActive(false);
                m_NPCFarmerUI.gameObject.SetActive(false);
                m_NPCSoldierUI.gameObject.SetActive(false);
                m_NPCFollowerUI.gameObject.SetActive(false);
                m_NPCProcessorUI.gameObject.SetActive(false);
                m_NpcDoctorUI.gameObject.SetActive(false);
                m_NpcInstructor.gameObject.SetActive(true);
            }
            else
            {
                m_NPCWorkerUI.gameObject.SetActive(false);
                m_NPCFarmerUI.gameObject.SetActive(false);
                m_NPCSoldierUI.gameObject.SetActive(false);
                m_NPCFollowerUI.gameObject.SetActive(false);
                m_NPCProcessorUI.gameObject.SetActive(false);
                m_NpcDoctorUI.gameObject.SetActive(false);
                m_NpcInstructor.gameObject.SetActive(false);
            }

            //lz-2016.09.20 npc在任务中的时候提示在任务中,不能正常工作
            if (npc.m_Occupation != CSConst.potDweller)
            {
                bool canwork = NpcTypeDb.CanRun(npc.NPC.NpcCmpt.NpcControlCmdId, ENpcControlType.Work);
                if (!canwork)
                {
                    CSUI_MainWndCtrl.ShowStatusBar(PELocalization.GetString(8000703));
                }
            }
        }
        else
        {
            m_NPCWorkerUI.gameObject.SetActive(false);
            m_NPCFarmerUI.gameObject.SetActive(false);
            m_NPCSoldierUI.gameObject.SetActive(false);
            m_NPCFollowerUI.gameObject.SetActive(false);
            m_NPCProcessorUI.gameObject.SetActive(false);
            m_NpcDoctorUI.gameObject.SetActive(false);
            m_NpcInstructor.gameObject.SetActive(false);
        }
    }