예제 #1
0
        public void Tick()
        {
            long          curTime    = TimeUtility.GetServerMilliseconds();
            List <string> deleteKeys = new List <string>();

            foreach (KeyValuePair <string, long> kv in m_OperationTimeDict)
            {
                if (curTime - kv.Value > OperationIntervalMs)
                {
                    deleteKeys.Add(kv.Key);
                }
            }
            long startTime;

            foreach (string key in deleteKeys)
            {
                m_OperationTimeDict.TryRemove(key, out startTime);
            }
        }
예제 #2
0
 public void OnHit(long hit_count_id)
 {
     if (IsTriggered && TriggerTime + RemainTimeMS < TimeUtility.GetLocalMilliseconds())
     {
         Refresh();
         return;
     }
     if (IsTriggered && hit_count_id != TriggerHitCountId)
     {
         if (!IsAddCriticalHitRecord)
         {
             AddCriticalHitCountId  = hit_count_id;
             IsAddCriticalHitRecord = true;
         }
         else if (hit_count_id != AddCriticalHitCountId)
         {
             Refresh();
         }
     }
 }
        private void HandleSelfImpactAction(NpcInfo npc, CharacterInfo target, long deltaTime)
        {
            if (npc.GetSkillStateInfo().IsSkillActivated())
            {
                return;
            }
            NpcAiStateInfo         info = npc.GetAiStateInfo();
            AiData_Npc_ActionDrive data = GetAiData(npc);

            if (null != data && null != target)
            {
                Vector3      targetPos    = target.GetMovementStateInfo().GetPosition3D();
                AiActionInfo aiActionInfo = data.ActiveAction;
                if (null != aiActionInfo && !String.IsNullOrEmpty(aiActionInfo.Config.ActionParam))
                {
                    NotifyNpcAddImpact(npc, int.Parse(aiActionInfo.Config.ActionParam));
                }
                data.ActiveAction          = null;
                aiActionInfo.LastStartTime = TimeUtility.GetServerMilliseconds();
            }
        }
        private void SkillActionStartHandler(NpcInfo npc, CharacterInfo target)
        {
            NpcAiStateInfo         info = npc.GetAiStateInfo();
            AiData_Npc_ActionDrive data = GetAiData(npc);

            if (null != data && null != target)
            {
                AiActionInfo aiActionInfo = data.ActiveAction;
                if (null != aiActionInfo)
                {
                    AiSkillActionInfo aiSkillActionInfo = aiActionInfo as AiSkillActionInfo;
                    if (null != aiSkillActionInfo)
                    {
                        aiSkillActionInfo.CurSkillIndex = 0;
                        aiSkillActionInfo.CurSkillCombo = aiSkillActionInfo.GetSkillCombo();
                        //aiSkillActionInfo.LastStartTime = TimeUtility.GetServerMilliseconds();
                        aiSkillActionInfo.StartTime = TimeUtility.GetServerMilliseconds();
                    }
                }
            }
        }
예제 #5
0
        public NpcInfo AddNpc(int id, Data_Unit unit)
        {
            NpcInfo npc = NewNpcInfo(id);

            npc.SceneContext = m_SceneContext;
            npc.LoadData(unit);
            npc.IsBorning = true;
            npc.SetAIEnable(false);
            npc.SetStateFlag(Operate_Type.OT_AddBit, CharacterState_Type.CST_Invincible);
            npc.BornTime = TimeUtility.GetServerMilliseconds();
            m_Npcs.AddLast(npc.GetId(), npc);
            if (null != m_SceneContext && null != m_SceneContext.SpatialSystem)
            {
                m_SceneContext.SpatialSystem.AddObj(npc.SpaceObject);
            }
            if (null != m_SceneContext && null != m_SceneContext.SightManager)
            {
                m_SceneContext.SightManager.AddObject(npc);
            }
            return(npc);
        }
예제 #6
0
        private SkillNode AddQESkillNode(SkillCategory category)
        {
            float now = TimeUtility.GetLocalMilliseconds() / 1000.0f;

            if (m_CurSkillNode == null)
            {
                return(null);
            }
            SkillNode parent          = m_CurSkillNode;
            bool      isHaveWaiteNode = false;

            if (m_WaiteSkillBuffer.Count > 0)
            {
                parent          = m_WaiteSkillBuffer[m_WaiteSkillBuffer.Count - 1];
                isHaveWaiteNode = true;
            }
            if (parent == null)
            {
                return(null);
            }
            if (isHaveWaiteNode || now < GetWaitInputTime(m_CurSkillNode))
            {
                SkillNode target = null;
                if (category == SkillCategory.kSkillQ)
                {
                    target = parent.SkillQ;
                }
                if (category == SkillCategory.kSkillE)
                {
                    target = parent.SkillE;
                }
                if (target != null && !target.IsLocked)
                {
                    m_WaiteSkillBuffer.Add(target);
                    return(target);
                }
            }
            return(null);
        }
        public override bool StartSkill(SkillNode node)
        {
            if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene())
            {
                if (m_Owner.GetId() == WorldSystem.Instance.PlayerSelfId || m_Owner.OwnerId == WorldSystem.Instance.PlayerSelfId)
                {
                    Network.NetworkSystem.Instance.SyncPlayerSkill(m_Owner, node.SkillId);
                }
            }
            else
            {
                if (!MakeSkillCost(node))
                {
                    return(false);
                }
            }
            m_Owner.ResetCross2StandRunTime();
            m_Owner.GetSkillStateInfo().SetCurSkillInfo(node.SkillId);
            SkillInfo cur_skill = m_Owner.GetSkillStateInfo().GetCurSkillInfo();

            if (null == cur_skill)
            {
                LogSystem.Error("----------SkillError: {0} set cur skill {1} failed! it's not exist", m_Owner.GetId(), node.SkillId);
                return(false);
            }
            cur_skill.IsSkillActivated = true;
            cur_skill.IsInterrupted    = false;
            cur_skill.StartTime        = TimeUtility.GetLocalMilliseconds() / 1000.0f;
            UpdateSkillCD(node);
            //LogSystem.Debug("---start skill at {0}--{1}", cur_skill.SkillId, cur_skill.StartTime);
            CharacterView view = EntityManager.Instance.GetCharacterViewById(m_Owner.GetId());

            if (view != null)
            {
                GfxSystem.QueueGfxAction(m_GfxSkillSystem.StartSkill, view.Actor, node.SkillId, m_Owner.GetMovementStateInfo().GetWantFaceDir());
            }
            SimulateStartSkill(m_Owner, node.SkillId);
            return(true);
        }
예제 #8
0
        public void Tick()
        {
            if (0 == m_LastTickTime)
            {
                m_LastTickTime = TimeUtility.GetServerMilliseconds();
            }
            else
            {
                long delta = TimeUtility.GetServerMilliseconds() - m_LastTickTime;
                m_LastTickTime = TimeUtility.GetServerMilliseconds();
                for (LinkedListNode <SceneLogicInfo> node = m_SceneLogicInfoMgr.SceneLogicInfos.FirstValue; null != node; node = node.Next)
                {
                    SceneLogicInfo info = node.Value;
                    if (null != info)
                    {
                        ISceneLogic logic = SceneLogicManager.Instance.GetSceneLogic(info.LogicId);
                        if (null != logic)
                        {
                            logic.Execute(info, delta);
                        }
                        if (info.IsLogicFinished)
                        {
                            m_SceneLogicInfos.Add(info);
                        }
                    }
                }
                for (int i = 0; i < m_SceneLogicInfos.Count; i++)
                {
                    m_SceneLogicInfoMgr.RemoveSceneLogicInfo(m_SceneLogicInfos[i].GetId());
                }

                /*
                 * foreach (SceneLogicInfo info in m_SceneLogicInfos) {
                 * m_SceneLogicInfoMgr.RemoveSceneLogicInfo(info.GetId());
                 * }*/
                m_SceneLogicInfos.Clear();
                m_SceneLogicInfoMgr.ExecuteDelayAdd();
            }
        }
        public override bool ForceStartSkill(int skillid)
        {
            m_Owner.GetSkillStateInfo().SetCurSkillInfo(skillid);
            SkillInfo cur_skill = m_Owner.GetSkillStateInfo().GetCurSkillInfo();

            if (null == cur_skill)
            {
                LogSystem.Error("----------ForceStartSkillError: {0} set cur skill {1} failed! it's not exist", m_Owner.GetId(), skillid);
                return(false);
            }
            if (cur_skill.SkillId != skillid)
            {
                LogSystem.Debug("----------ForceStartSkillError: {0} set cur skill {1} failed! it's {2}", m_Owner.GetId(), skillid, cur_skill.SkillId);
                return(false);
            }
            if (null != cur_skill)
            {
                cur_skill.IsSkillActivated = true;
                cur_skill.IsInterrupted    = false;
                cur_skill.StartTime        = TimeUtility.GetLocalMilliseconds() / 1000.0f;
                //LogSystem.Debug("---force start skill at {0}--{1}", cur_skill.SkillId, cur_skill.StartTime);
                CharacterView view = EntityManager.Instance.GetCharacterViewById(m_Owner.GetId());
                if (view != null)
                {
                    GfxSystem.QueueGfxAction(m_GfxSkillSystem.StartSkill, view.Actor, skillid, m_Owner.GetMovementStateInfo().GetWantFaceDir());
                }
            }
            else
            {
                List <SkillInfo> skills = m_Owner.GetSkillStateInfo().GetAllSkill();
                LogSystem.Error("Can't find skill {0}, obj has {1} skills", skillid, skills.Count);
                foreach (SkillInfo info in skills)
                {
                    LogSystem.Error("\tskill {0}", info.SkillId);
                }
            }
            SimulateStartSkill(m_Owner, skillid);
            return(true);
        }
 public override bool BreakCurSkill(int breaktype, SkillCategory category)
 {
     if (category == m_CurSkillNode.Category)
     {
         bool result = StopSkill(m_CurSkillNode, breaktype);
         if (!result)
         {
             if (!m_CurSkillNode.IsAlreadyPressUp)
             {
                 m_CurSkillNode.IsAlreadyPressUp = true;
                 SkillNode head      = GetHead(m_CurSkillNode.Category);
                 SkillInfo skillInfo = m_Owner.GetSkillStateInfo().GetSkillInfoById(head.SkillId);
                 if (skillInfo != null)
                 {
                     skillInfo.CalcuteCastTime(TimeUtility.GetLocalMilliseconds() / 1000f, m_CurSkillNode.SkillId);
                 }
             }
             else
             {
                 SkillNode skillnode = m_WaiteSkillBuffer.Find(s => s.Category == category && s.IsAlreadyPressUp == false);
                 if (skillnode != null)
                 {
                     skillnode.IsAlreadyPressUp = true;
                 }
             }
         }
         return(result);
     }
     else
     {
         SkillNode skillnode = m_WaiteSkillBuffer.Find(s => s.Category == category && s.IsAlreadyPressUp == false);
         if (skillnode != null)
         {
             skillnode.IsAlreadyPressUp = true;
         }
     }
     return(false);
 }
예제 #11
0
        public void Tick()
        {
            long          curTime    = TimeUtility.GetServerMilliseconds();
            List <string> deleteKeys = new List <string>();

            foreach (KeyValuePair <string, TimeoutInfo> kv in m_TimeoutInfoDict)
            {
                if (kv.Value != null && curTime - kv.Value.StartTime > DefaultTimeoutMS)
                {
                    if (kv.Value.OnTimeout != null)
                    {
                        kv.Value.OnTimeout();
                    }
                    deleteKeys.Add(kv.Key);
                }
            }
            TimeoutInfo info = null;

            foreach (string key in deleteKeys)
            {
                m_TimeoutInfoDict.TryRemove(key, out info);
            }
        }
예제 #12
0
        public override void Adjust()
        {
            CharacterInfo info = WorldSystem.Instance.GetCharacterById(m_ObjId);

            if (null != info)
            {
                float curTime = TimeUtility.GetLocalMilliseconds();
                float delta   = curTime - m_LastTime;
                m_LastTime      = curTime;
                m_CurTotalTime += delta;
                float faceDir = info.GetMovementStateInfo().GetFaceDir();
                if (m_CurTotalTime >= m_TotalTime || Math.Abs(faceDir - m_FaceDir) <= 0.1f)
                {
                    info.GetMovementStateInfo().SetFaceDir(m_FaceDir);
                    m_IsTerminated = true;
                }
                else
                {
                    float offset = c_PI - (m_FaceDir + c_2PI - faceDir) % c_2PI;
                    if (offset * m_DeltaDir <= 0)
                    {
                        info.GetMovementStateInfo().SetFaceDir(m_FaceDir);
                        m_IsTerminated = true;
                    }
                    else
                    {
                        float newFaceDir = (faceDir + c_2PI + delta * m_DeltaDir / m_TotalTime) % c_2PI;
                        info.GetMovementStateInfo().SetFaceDir(newFaceDir);
                        //LogSystem.Debug("FaceController {0}, obj:{1}, faceDir:{2}->{3}, delta:{4} totalTime:{5} deltaDir:{6} targetDir:{7}", m_Id, m_ObjId, faceDir, newFaceDir, delta, m_TotalTime, m_DeltaDir, m_FaceDir);
                    }
                }
            }
            else
            {
                m_IsTerminated = true;
            }
        }
        private void HandleFleeAction(NpcInfo npc, CharacterInfo target, long deltaTime)
        {
            if (npc.GetSkillStateInfo().IsSkillActivated())
            {
                return;
            }
            NpcAiStateInfo         info = npc.GetAiStateInfo();
            AiData_Npc_ActionDrive data = GetAiData(npc);

            if (null != data && null != target)
            {
                Vector3      targetPos    = Vector3.Zero;
                AiActionInfo aiActionInfo = data.ActiveAction;
                if (null != aiActionInfo)
                {
                    float anglePlus = 0.0f;
                    float.TryParse(aiActionInfo.Config.ActionParam, out anglePlus);
                    if (GetEscapeTargetPos(npc, target, 3.0f, anglePlus, ref targetPos))
                    {
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            NotifyNpcRun(npc);
                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                        }
                    }
                }
                if ((!IsAiActionSatify(npc, target, aiActionInfo) && aiActionInfo.Config.CanInterrupt) || aiActionInfo.IsTimeOut(TimeUtility.GetServerMilliseconds()))
                {
                    data.ActiveAction = null;
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    aiActionInfo.LastStartTime = TimeUtility.GetServerMilliseconds();
                }
            }
        }
예제 #14
0
        public void Tick(CharacterInfo obj)
        {
            List <ImpactInfo> impactInfos = obj.GetSkillStateInfo().GetAllImpact();
            int ct = impactInfos.Count;

            for (int i = ct - 1; i >= 0; --i)
            {
                ImpactInfo   info  = impactInfos[i];
                IImpactLogic logic = ImpactLogicManager.Instance.GetImpactLogic(info.ConfigData.ImpactLogicId);
                if (info.m_IsActivated)
                {
                    if (null != logic)
                    {
                        logic.Tick(obj, info.m_ImpactId);
                    }
                }
                else
                {
                    logic.OnInterrupted(obj, info.m_ImpactId);
                    obj.GetSkillStateInfo().RemoveImpact(info.m_ImpactId);
                }
            }
            obj.GetSkillStateInfo().CleanupImpactInfoForCheck(TimeUtility.GetServerMilliseconds(), 5000);//用于校验的impact比正常时间晚5秒清除
        }
예제 #15
0
        private int GetCanCastSkillId(UserInfo user, float dis)
        {
            if (null == user)
            {
                return(-1);
            }
            List <int> skillsCanCast = new List <int>();
            int        start         = (int)SkillCategory.kAttack;
            int        end           = (int)SkillCategory.kSkillD;

            for (int i = start; i <= end; i++)
            {
                SkillNode node = user.SkillController.GetHead((SkillCategory)i);
                if (null != node)
                {
                    SkillInfo skillInfo = user.GetSkillStateInfo().GetSkillInfoById(node.SkillId);
                    if (null != skillInfo)
                    {
                        if (skillInfo.ConfigData.SkillRangeMax >= dis && skillInfo.ConfigData.SkillRangeMin <= dis)
                        {
                            if (!skillInfo.IsInCd(TimeUtility.GetServerMilliseconds()))
                            {
                                skillsCanCast.Add(i);
                            }
                        }
                    }
                }
            }
            int count = skillsCanCast.Count;

            if (count > 0)
            {
                return(skillsCanCast[CrossEngineHelper.Random.Next(count)]);
            }
            return(-1);
        }
        private void HandleStandAction(NpcInfo npc, CharacterInfo target, long delatTime)
        {
            if (npc.GetSkillStateInfo().IsSkillActivated())
            {
                return;
            }
            NpcAiStateInfo         info = npc.GetAiStateInfo();
            AiData_Npc_ActionDrive data = GetAiData(npc);

            if (null != data && null != target)
            {
                npc.GetMovementStateInfo().IsMoving = false;
                NotifyNpcMove(npc);
                AiActionInfo aiActionInfo = data.ActiveAction;
                if (null != aiActionInfo)
                {
                    if ((!IsAiActionSatify(npc, target, aiActionInfo) && aiActionInfo.Config.CanInterrupt) || aiActionInfo.IsTimeOut(TimeUtility.GetServerMilliseconds()))
                    {
                        data.ActiveAction          = null;
                        aiActionInfo.LastStartTime = TimeUtility.GetServerMilliseconds();
                    }
                }
            }
        }
예제 #17
0
 public void AlwaysClientTick()
 {
     if (0 == m_AlwaysClientLastTickTime)
     {
         m_AlwaysClientLastTickTime = TimeUtility.GetServerMilliseconds();
     }
     else
     {
         long delta = TimeUtility.GetServerMilliseconds() - m_AlwaysClientLastTickTime;
         m_AlwaysClientLastTickTime = TimeUtility.GetServerMilliseconds();
         if (null != m_NpcMgr)
         {
             for (LinkedListNode <NpcInfo> linkNode = m_NpcMgr.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next)
             {
                 NpcInfo        npc   = linkNode.Value;
                 INpcStateLogic logic = AiLogicManager.Instance.GetAlwaysClientNpcStateLogic(npc.GetAiStateInfo().AiLogic);
                 if (null != logic)
                 {
                     logic.Execute(npc, m_AiCommandDispatcher, delta);
                 }
             }
         }
         if (null != m_UserMgr)
         {
             for (LinkedListNode <UserInfo> linkNode = m_UserMgr.Users.FirstValue; null != linkNode; linkNode = linkNode.Next)
             {
                 UserInfo        user  = linkNode.Value;
                 IUserStateLogic logic = AiLogicManager.Instance.GetAlwaysClientUserStateLogic(user.GetAiStateInfo().AiLogic);
                 if (null != logic)
                 {
                     logic.Execute(user, m_AiCommandDispatcher, delta);
                 }
             }
         }
     }
 }
예제 #18
0
        protected void UpdateState()
        {
            if (GetOwner().IsDead())
            {
                return;
            }
            long now = TimeUtility.GetServerMilliseconds();

            if (IsInCombatState())
            {
                m_LastLeaveCombatTime   = now;
                m_IsCombat2IdleChanging = false;
                m_IsCombatState         = true;
            }
            else if (m_IsCombatState)
            {
                if (GetOwner().GetMovementStateInfo().IsMoving)
                {
                    m_LastLeaveCombatTime   = now;
                    m_IsCombat2IdleChanging = false;
                }
            }
            if (GetOwner().GetId() == WorldSystem.Instance.GetPlayerSelf().GetId())
            {
                if (m_LastLeaveCombatTime + GetOwner().Combat2IdleTime *GetOwner().Combat2IdleCoefficient * 1000 <= now && !m_IsCombat2IdleChanging)
                {
                    GetOwner().SkillController.PushSkill(SkillCategory.kCombat2Idle, Vector3.Zero);
                    m_IsCombat2IdleChanging = true;
                    GetOwner().ResetCombat2IdleCoefficient();
                }
            }
            if (m_IsCombatState && !m_IsWeaponMoved)
            {
                EnterCombatState();
            }
        }
예제 #19
0
            internal void Log(string format, params object[] args)
            {
                if (m_LogStream == null)
                {
                    return;
                }
                string msg = string.Format(format, args);

#if USE_DISK_LOG
                if (m_LogStream != null)
                {
                    m_LogStream.WriteLine(msg);
                    m_LogStream.Flush();
                }
#else
                m_LogQueue.Enqueue(msg);
                if (!m_IsInRequestFlush && m_LogQueue.Count >= c_FlushCount)
                {
                    m_LastFlushTime = TimeUtility.GetLocalMilliseconds();

                    RequestFlush();
                }
#endif
            }
예제 #20
0
        internal void UpdateLastLeaveCombatTime()
        {
            long now = TimeUtility.GetServerMilliseconds();

            m_LastLeaveCombatTime = now;
        }
        private void HandleRunAction(NpcInfo npc, CharacterInfo target, long deltaTime)
        {
            if (npc.GetSkillStateInfo().IsSkillActivated())
            {
                return;
            }
            NpcAiStateInfo         info = npc.GetAiStateInfo();
            AiData_Npc_ActionDrive data = GetAiData(npc);

            if (null != data && null != target)
            {
                Vector3      targetPos    = target.GetMovementStateInfo().GetPosition3D();
                AiActionInfo aiActionInfo = data.ActiveAction;
                if (null != aiActionInfo)
                {
                    info.Time += deltaTime;
                    if (info.Time > m_IntervalTime)
                    {
                        info.Time = 0;
                        NotifyNpcRun(npc);
                        AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                    }
                }
                if ((!IsAiActionSatify(npc, target, aiActionInfo) && aiActionInfo.Config.CanInterrupt) || aiActionInfo.IsTimeOut(TimeUtility.GetServerMilliseconds()))
                {
                    data.ActiveAction          = null;
                    aiActionInfo.LastStartTime = TimeUtility.GetServerMilliseconds();
                }
            }
        }
        private void HandleTauntAction(NpcInfo npc, CharacterInfo target, long deltaTime)
        {
            if (npc.GetSkillStateInfo().IsSkillActivated())
            {
                return;
            }
            NpcAiStateInfo         info = npc.GetAiStateInfo();
            AiData_Npc_ActionDrive data = GetAiData(npc);

            if (null != data && null != target)
            {
                Vector3      targetPos    = target.GetMovementStateInfo().GetPosition3D();
                AiActionInfo aiActionInfo = data.ActiveAction;
                if (null != aiActionInfo)
                {
                    npc.GetMovementStateInfo().IsMoving = false;
                    npc.IsTaunt = true;
                    TrySeeTarget(npc, target);
                }
                if ((!IsAiActionSatify(npc, target, aiActionInfo) && aiActionInfo.Config.CanInterrupt) || aiActionInfo.IsTimeOut(TimeUtility.GetServerMilliseconds()))
                {
                    npc.IsTaunt                = false;
                    data.ActiveAction          = null;
                    aiActionInfo.LastStartTime = TimeUtility.GetServerMilliseconds();
                }
            }
        }
        private void HandleSkillAction(NpcInfo npc, CharacterInfo target, long deltaTime)
        {
            NpcAiStateInfo         info = npc.GetAiStateInfo();
            AiData_Npc_ActionDrive data = GetAiData(npc);

            if (null != data && null != target)
            {
                Vector3      targetPos    = target.GetMovementStateInfo().GetPosition3D();
                AiActionInfo aiActionInfo = data.ActiveAction;
                if (null != aiActionInfo && !npc.GetSkillStateInfo().IsSkillActivated())
                {
                    AiSkillActionInfo skillActionInfo = aiActionInfo as AiSkillActionInfo;
                    if (null != skillActionInfo && skillActionInfo.CurSkillIndex < skillActionInfo.CurSkillCombo.Count)
                    {
                        int skillId = skillActionInfo.CurSkillCombo[skillActionInfo.CurSkillIndex];
                        if (AiLogicUtility.CanCastSkill(npc, skillId, target))
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            if (TryCastSkill(npc, skillId, target))
                            {
                                skillActionInfo.CurSkillIndex++;
                            }
                        }
                        else
                        {
                            info.Time += deltaTime;
                            if (info.Time > m_IntervalTime)
                            {
                                info.Time = 0;
                                if (AiLogicUtility.IsTooCloseToCastSkill(npc, target))
                                {
                                    Vector3 escapePos = Vector3.Zero;
                                    if (AiLogicUtility.GetEscapeTargetPos(npc, target, 3.0f, ref escapePos))
                                    {
                                        NotifyNpcRun(npc);
                                        AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, escapePos, m_IntervalTime, true, this);
                                    }
                                }
                                else
                                {
                                    NotifyNpcRun(npc);
                                    AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                }
                            }
                        }
                    }
                    else
                    {
                        skillActionInfo.CurSkillIndex = 0;
                        data.ActiveAction             = null;
                        aiActionInfo.LastStartTime    = TimeUtility.GetServerMilliseconds();
                    }
                }
                if ((!IsAiActionSatifyWithOutProbability(npc, target, aiActionInfo) && aiActionInfo.Config.CanInterrupt) || (aiActionInfo.IsTimeOut(TimeUtility.GetServerMilliseconds()) && !npc.GetSkillStateInfo().IsSkillActivated()))
                {
                    data.ActiveAction          = null;
                    aiActionInfo.LastStartTime = TimeUtility.GetServerMilliseconds();
                    NotifyNpcStopSkill(npc);
                }
            }
        }
예제 #24
0
        private void CombatHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (!CanAiControl(npc))
            {
                npc.GetMovementStateInfo().IsMoving = false;
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > m_IntervalTime)
            {
                AiData_Demo_Melee data = GetAiData(npc);
                if (null != data)
                {
                    data.Time += info.Time;
                    info.Time  = 0;
                    CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target);
                    //CharacterInfo target = AiLogicUtility.GetInterestestTargetHelper(npc, CharacterRelation.RELATION_ENEMY, AiTargetType.USER);
                    if (null != target)
                    {
                        float   dist          = (float)npc.GetActualProperty().AttackRange;
                        float   distGoHome    = (float)npc.GohomeRange;
                        Vector3 targetPos     = target.GetMovementStateInfo().GetPosition3D();
                        Vector3 srcPos        = npc.GetMovementStateInfo().GetPosition3D();
                        float   powDist       = Geometry.DistanceSquare(srcPos, targetPos);
                        float   powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                        if (powDist < dist * dist)
                        {
                            float rps     = npc.GetActualProperty().Rps;
                            long  curTime = TimeUtility.GetServerMilliseconds();
                            float dir     = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                            NotifyNpcFace(npc, dir);
                            //if (rps > 0.001f && curTime - data.LastUseSkillTime > 1000 / rps) {
                            data.Time             = 0;
                            data.LastUseSkillTime = curTime;
                            List <SkillInfo> skillInfos = npc.GetSkillStateInfo().GetAllSkill();
                            if (skillInfos.Count > 0)
                            {
                                int index = CrossEngineHelper.Random.Next(skillInfos.Count);
                                if (null != skillInfos[index])
                                {
                                    NotifyNpcSkill(npc, skillInfos[index].SkillId);
                                }
                            }
                            //}
                        }
                        else
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            info.Time = 0;
                            data.FoundPath.Clear();
                            ChangeToState(npc, (int)AiStateId.Pursuit);
                        }
                    }
                }
                else
                {
                    info.Time = 0;
                }
            }
        }
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (!CanAiControl(npc))
            {
                npc.GetMovementStateInfo().IsMoving = false;
                return;
            }
            NpcAiStateInfo    info = npc.GetAiStateInfo();
            AiData_Npc_Bluelf data = GetAiData(npc);

            if (null != data)
            {
                CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target);
                if (null != target)
                {
                    float   dist          = (float)npc.GetActualProperty().AttackRange;
                    float   distGoHome    = (float)npc.GohomeRange;
                    Vector3 targetPos     = target.GetMovementStateInfo().GetPosition3D();
                    Vector3 srcPos        = npc.GetMovementStateInfo().GetPosition3D();
                    float   powDist       = Geometry.DistanceSquare(srcPos, targetPos);
                    float   powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                    // 遇敌是播放特效, 逗留两秒。
                    if (data.WaitTime <= npc.MeetEnemyStayTime)
                    {
                        if (!data.HasMeetEnemy)
                        {
                            NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack);
                            data.HasMeetEnemy = true;
                        }
                        TrySeeTarget(npc, target);
                        data.WaitTime += deltaTime;
                        return;
                    }
                    // 走向目标1.5秒
                    if (data.MeetEnemyWalkTime < npc.MeetEnemyWalkTime)
                    {
                        data.MeetEnemyWalkTime += deltaTime;
                        NotifyNpcWalk(npc);
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            if (!npc.UnityPathFinding)
                            {
                                AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                            }
                            else
                            {
                                if (!npc.PathFindingFinished)
                                {
                                    GfxSystem.NpcCommonRangePathToTarget(npc, targetPos);
                                    ChangeToState(npc, (int)AiStateId.PathFinding);
                                }
                                else
                                {
                                    npc.PathFindingFinished = false;
                                    AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                }
                            }
                        }
                        return;
                    }

                    // 大于攻击距离 跑向目标
                    if (powDist > npc.ViewRange * npc.ViewRange && 0 == data.CurAiAction)
                    {
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            NotifyNpcRun(npc);
                            info.Time = 0;
                            if (!npc.UnityPathFinding)
                            {
                                AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                            }
                            else
                            {
                                if (!npc.PathFindingFinished)
                                {
                                    GfxSystem.NpcCommonRangePathToTarget(npc, targetPos);
                                    ChangeToState(npc, (int)AiStateId.PathFinding);
                                }
                                else
                                {
                                    npc.PathFindingFinished = false;
                                    AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                }
                            }
                        }
                    }
                    else /* if(powDist > m_EscapeRange * m_EscapeRange) */
                    {
                        //小于攻击距离
                        if (data.CurAiAction == (int)AiAction.NONE)
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            data.CurAiAction = (int)GetNextAction();
                        }
                        switch (data.CurAiAction)
                        {
                        case (int)AiAction.SKILL:
                            int skillId = GetCanCastSkillId(npc, (float)Math.Sqrt(powDist));
                            if (-1 == skillId)
                            {
                                info.Time += deltaTime;
                                if (info.Time > m_IntervalTime)
                                {
                                    info.Time = 0;
                                    if (AiLogicUtility.IsTooCloseToCastSkill(npc, target))
                                    {
                                        Vector3 escapePos = Vector3.Zero;
                                        if (AiLogicUtility.GetEscapeTargetPos(npc, target, 3.0f, ref escapePos))
                                        {
                                            NotifyNpcRun(npc);
                                            if (!npc.UnityPathFinding)
                                            {
                                                AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                            }
                                            else
                                            {
                                                if (!npc.PathFindingFinished)
                                                {
                                                    GfxSystem.NpcCommonRangePathToTarget(npc, targetPos);
                                                    ChangeToState(npc, (int)AiStateId.PathFinding);
                                                }
                                                else
                                                {
                                                    npc.PathFindingFinished = false;
                                                    AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        NotifyNpcRun(npc);
                                        if (!npc.UnityPathFinding)
                                        {
                                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                        }
                                        else
                                        {
                                            if (!npc.PathFindingFinished)
                                            {
                                                GfxSystem.NpcCommonRangePathToTarget(npc, targetPos);
                                                ChangeToState(npc, (int)AiStateId.PathFinding);
                                            }
                                            else
                                            {
                                                npc.PathFindingFinished = false;
                                                AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                npc.GetMovementStateInfo().IsMoving = false;
                                NotifyNpcMove(npc);
                                if (TryCastSkill(npc, skillId, target))
                                {
                                    data.CurAiAction = 0;
                                }
                            }
                            break;

                        case (int)AiAction.STAND:
                            data.ChaseStandTime += deltaTime;
                            TrySeeTarget(npc, target);
                            if (data.ChaseStandTime > m_ChaseStandMaxTime)
                            {
                                data.ChaseStandTime = 0;
                                data.CurAiAction    = 0;
                            }
                            break;

                        case (int)AiAction.TAUNT:
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            npc.IsTaunt     = true;
                            data.TauntTime += deltaTime;
                            TrySeeTarget(npc, target);
                            if (data.TauntTime > m_TauntTime)
                            {
                                npc.IsTaunt      = false;
                                data.TauntTime   = 0;
                                data.CurAiAction = 0;
                            }
                            break;

                        case (int)AiAction.WALK:
                            data.ChaseWalkTime += deltaTime;
                            info.Time          += deltaTime;
                            if (info.Time > m_IntervalTime)
                            {
                                info.Time = 0;
                                NotifyNpcWalk(npc);
                                if (!npc.UnityPathFinding)
                                {
                                    AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                }
                                else
                                {
                                    if (!npc.PathFindingFinished)
                                    {
                                        GfxSystem.NpcCommonRangePathToTarget(npc, targetPos);
                                        ChangeToState(npc, (int)AiStateId.PathFinding);
                                    }
                                    else
                                    {
                                        npc.PathFindingFinished = false;
                                        AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                    }
                                }
                            }
                            if (data.ChaseWalkTime > m_ChaseWalkMaxTime)
                            {
                                data.ChaseWalkTime = 0;
                                data.CurAiAction   = 0;
                            }
                            break;
                        }
                    }

                    long curTime = TimeUtility.GetServerMilliseconds();
                    if (powDist < m_EscapeRange * m_EscapeRange && (curTime - data.LastEscapeTime > m_EscapeCoolDown || m_EscapeCoolDown == 0))
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        data.LastEscapeTime = curTime;
                        data.ChaseStandTime = 0;
                        data.ChaseWalkTime  = 0;
                        data.TauntTime      = 0;
                        npc.IsTaunt         = false;
                        data.CurAiAction    = 0;
                        NotifyNpcMove(npc);
                        info.Time = 0;
                        ChangeToState(npc, (int)AiStateId.Escape);
                    }
                }
                else
                {
                    NotifyNpcTargetChange(npc);
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    ChangeToState(npc, (int)AiStateId.Idle);
                }
            }
        }
예제 #26
0
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                npc.GetMovementStateInfo().IsMoving = false;
                NotifyNpcMove(npc);
                return;
            }
            NpcAiStateInfo        info = npc.GetAiStateInfo();
            AiData_Npc_CommonBoss data = GetAiData(npc);

            if (null != data)
            {
                CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target);
                if (null != target)
                {
                    if (npc.GetSkillStateInfo().IsSkillActivated())
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);
                        data.LastUseSkillTime = TimeUtility.GetServerMilliseconds();
                        return;
                    }
                    if (npc.IsUnderControl())
                    {
                        data.ControlTime += deltaTime;
                        if (data.ControlTime >= m_MaxControlTime && npc.CanDisControl() && AiLogicUtility.CanCastSkill(npc, m_DisControlSkillId, target))
                        {
                            NotifyNpcAddImpact(npc, m_DisControlImpactId);
                            data.ControlTime = 0;
                            TryCastSkill(npc, m_DisControlSkillId, target, false);
                        }
                        return;
                    }
                    float   dist          = (float)npc.GetActualProperty().AttackRange;
                    float   distGoHome    = (float)npc.GohomeRange;
                    Vector3 targetPos     = target.GetMovementStateInfo().GetPosition3D();
                    Vector3 srcPos        = npc.GetMovementStateInfo().GetPosition3D();
                    float   powDist       = Geometry.DistanceSquare(srcPos, targetPos);
                    float   powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                    // 遇敌是播放特效, 逗留两秒。
                    if (data.WaitTime <= m_ResponseTime)
                    {
                        if (!data.HasMeetEnemy)
                        {
                            NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack);
                            data.HasMeetEnemy = true;
                        }
                        TrySeeTarget(npc, target);
                        data.WaitTime += deltaTime;
                        return;
                    }
                    int  skillId = GetCanCastSkillId(npc, (float)Math.Sqrt(powDist));
                    long curTime = TimeUtility.GetServerMilliseconds();
                    if (-1 != skillId && curTime - data.LastUseSkillTime > m_SkillInterval && AiLogicUtility.CanCastSkill(npc, skillId, target))
                    {
                        if (TryCastSkill(npc, skillId, target, true))
                        {
                            NotifyNpcAddImpact(npc, m_SuperArmorImpactId);
                        }
                    }
                    else
                    {
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                        }
                    }
                }
                else
                {
                    NotifyNpcTargetChange(npc);
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    ChangeToState(npc, (int)AiStateId.Idle);
                }
            }
        }
예제 #27
0
        internal void Tick()
        {
            long now = TimeUtility.GetServerMilliseconds();

            m_LastTickIntervalMs = now - m_LastTickTime;

            m_LastTickTime = now;

            if (WorldSystem.Instance.IsObserver && !WorldSystem.Instance.IsFollowObserver)
            {
                bool  keyPressed = false;
                float x = 0.5f, y = 0.5f;
                if (GfxSystem.IsKeyPressed(Keyboard.Code.A))
                {
                    x          = 0.1f;
                    keyPressed = true;
                }
                else if (GfxSystem.IsKeyPressed(Keyboard.Code.D))
                {
                    x          = 0.9f;
                    keyPressed = true;
                }
                if (GfxSystem.IsKeyPressed(Keyboard.Code.W))
                {
                    y          = 0.1f;
                    keyPressed = true;
                }
                else if (GfxSystem.IsKeyPressed(Keyboard.Code.S))
                {
                    y          = 0.9f;
                    keyPressed = true;
                }
                if (keyPressed)
                {
                    WorldSystem.Instance.UpdateObserverCamera(x, y);
                }
                return;
            }


            UserInfo playerself = WorldSystem.Instance.GetPlayerSelf();

            if (null == playerself)
            {
                return;
            }
            // if move input is disable
            // MotionStatus is MoveStop, and MotionChanged is reflect the change accordingly

            if (EnableMoveInput)
            {
                if (!IsKeyboardControl())
                {
                    CheckJoystickControl();
                }
            }

            if (!m_IsJoystickControl)
            {
                pm_.Update(EnableMoveInput);
            }
            MovementStateInfo msi = playerself.GetMovementStateInfo();
            Vector3           pos = msi.GetPosition3D();

            //LogSystem.Debug("Pos : {0}, Dir : {1}", pos.ToString(), playerself.GetMovementStateInfo().GetFaceDir());
            bool reface = false;

            if (m_LastTickIsSkillMoving && !msi.IsSkillMoving)
            {
                reface = true;
            }

            //操作同步机制改为发给服务器同时本地就开始执行(服务器转发给其它客户端,校验失败则同时发回原客户端进行位置调整)
            Vector3 mouse_pos = new Vector3(GfxSystem.GetMouseX(), GfxSystem.GetMouseY(), GfxSystem.GetMouseZ());

            if (pm_.MotionStatus == PlayerMovement.Motion.Moving || pm_.JoyStickMotionStatus == PlayerMovement.Motion.Moving)
            {
                if (pm_.MotionChanged || pm_.JoyStickMotionChanged || !m_LastTickIsMoving)
                {
                    StopAiMove();

                    playerself.SkillController.AddBreakSkillTask();
                    float moveDir = RoundMoveDir(pm_.MoveDir);

                    //GfxSystem.GfxLog("PlayerControl.Tick MoveDir:{0} RoundMoveDir:{1}", pm_.MoveDir, moveDir);

                    if (!m_LastTickIsMoving || !Geometry.IsSameFloat(moveDir, m_lastMoveDir))
                    {
                        msi.SetMoveDir(moveDir);
                        //ControlSystemOperation.AdjustCharacterMoveDir(playerself.GetId(), moveDir);
                        msi.IsMoving       = true;
                        msi.TargetPosition = Vector3.Zero;

                        if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene())
                        {
                            NetworkSystem.Instance.SyncPlayerMoveStart(moveDir);
                        }
                    }
                    if (EnableRotateInput)
                    {
                        if (reface || !m_LastTickIsMoving || !Geometry.IsSameFloat(pm_.MoveDir, m_lastDir))
                        {
                            msi.SetFaceDir(pm_.MoveDir);
                            //ControlSystemOperation.AdjustCharacterFaceDir(playerself.GetId(), pm_.MoveDir);
                            msi.SetWantFaceDir(pm_.MoveDir);

                            if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene())
                            {
                                NetworkSystem.Instance.SyncFaceDirection(pm_.MoveDir);
                            }
                        }
                    }
                    m_lastDir     = pm_.MoveDir;
                    m_lastMoveDir = moveDir;
                }
                m_LastTickIsMoving = true;
            }
            else
            {
                if (m_LastTickIsMoving)
                {
                    playerself.SkillController.CancelBreakSkillTask();
                    playerself.GetMovementStateInfo().IsMoving = false;
                    if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene())
                    {
                        NetworkSystem.Instance.SyncPlayerMoveStop();
                    }
                    if (EnableRotateInput)
                    {
                        if (reface)
                        {
                            msi.SetFaceDir(m_lastDir);
                            //ControlSystemOperation.AdjustCharacterFaceDir(playerself.GetId(), m_lastDir);
                            msi.SetWantFaceDir(m_lastDir);

                            if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene())
                            {
                                NetworkSystem.Instance.SyncFaceDirection(m_lastDir);
                            }
                        }
                    }
                }
                m_LastTickIsMoving = false;
            }
            m_LastTickIsSkillMoving = msi.IsSkillMoving;

            old_mouse_pos_ = mouse_pos_;
            mouse_pos_.X   = GfxSystem.GetMouseX();
            mouse_pos_.Y   = GfxSystem.GetMouseY();

            UserAiStateInfo aiInfo = playerself.GetAiStateInfo();

            if (null != aiInfo && (int)AiStateId.Idle == aiInfo.CurState)
            {
                m_lastSelectObjId = -1;
            }
        }
예제 #28
0
        private void SummonPartner(int key_code, int what)
        {
            RoleInfo roleself = LobbyClient.Instance.CurrentRole;

            if (null == roleself)
            {
                return;
            }
            UserInfo playerself = WorldSystem.Instance.GetPlayerSelf();

            if (null == playerself)
            {
                return;
            }
            ///
            if ((int)Keyboard.Event.Up == what)
            {
                // summonpartner
                PartnerInfo partnerInfo = roleself.PartnerStateInfo.GetActivePartner();
                if (null != partnerInfo)
                {
                    Data_Unit data = new Data_Unit();
                    data.m_Id         = -1;
                    data.m_LinkId     = partnerInfo.LinkId;
                    data.m_CampId     = playerself.GetCampId();
                    data.m_Pos        = playerself.GetMovementStateInfo().GetPosition3D();
                    data.m_RotAngle   = 0;
                    data.m_AiLogic    = partnerInfo.GetAiLogic();
                    data.m_AiParam[0] = "";
                    data.m_AiParam[1] = "";
                    data.m_AiParam[2] = partnerInfo.GetAiParam().ToString();
                    data.m_IsEnable   = true;
                    NpcInfo npc = WorldSystem.Instance.NpcManager.AddNpc(data);
                    if (null != npc)
                    {
                        AppendAttributeConfig aac       = AppendAttributeConfigProvider.Instance.GetDataById(partnerInfo.GetAppendAttrConfigId());
                        float inheritAttackAttrPercent  = partnerInfo.GetInheritAttackAttrPercent();
                        float inheritDefenceAttrPercent = partnerInfo.GetInheritDefenceAttrPercent();
                        if (null != aac)
                        {
                            // attack
                            npc.GetBaseProperty().SetAttackBase(Operate_Type.OT_Absolute, (int)(playerself.GetActualProperty().AttackBase *inheritAttackAttrPercent));
                            npc.GetBaseProperty().SetFireDamage(Operate_Type.OT_Absolute, playerself.GetActualProperty().FireDamage *inheritAttackAttrPercent);
                            npc.GetBaseProperty().SetIceDamage(Operate_Type.OT_Absolute, playerself.GetActualProperty().IceDamage *inheritAttackAttrPercent);
                            npc.GetBaseProperty().SetPoisonDamage(Operate_Type.OT_Absolute, playerself.GetActualProperty().PoisonDamage *inheritAttackAttrPercent);
                            // defence
                            npc.GetBaseProperty().SetHpMax(Operate_Type.OT_Absolute, (int)(playerself.GetActualProperty().HpMax *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetEnergyMax(Operate_Type.OT_Absolute, (int)(playerself.GetActualProperty().EnergyMax *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetADefenceBase(Operate_Type.OT_Absolute, (int)(playerself.GetActualProperty().ADefenceBase *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetMDefenceBase(Operate_Type.OT_Absolute, (int)(playerself.GetActualProperty().MDefenceBase *inheritDefenceAttrPercent));
                            npc.GetBaseProperty().SetFireERD(Operate_Type.OT_Absolute, playerself.GetActualProperty().FireERD *inheritDefenceAttrPercent);
                            npc.GetBaseProperty().SetIceERD(Operate_Type.OT_Absolute, playerself.GetActualProperty().IceERD *inheritDefenceAttrPercent);
                            npc.GetBaseProperty().SetPoisonERD(Operate_Type.OT_Absolute, playerself.GetActualProperty().PoisonERD *inheritDefenceAttrPercent);
                            // reset hp & energy
                            npc.SetHp(Operate_Type.OT_Absolute, npc.GetActualProperty().HpMax);
                            npc.SetEnergy(Operate_Type.OT_Absolute, npc.GetActualProperty().EnergyMax);
                        }
                        npc.SetAIEnable(true);
                        npc.GetSkillStateInfo().RemoveAllSkill();
                        npc.BornTime = TimeUtility.GetServerMilliseconds();
                        List <int> skillList = partnerInfo.GetSkillList();
                        if (null != skillList)
                        {
                            for (int i = 0; i < skillList.Count; ++i)
                            {
                                SkillInfo skillInfo = new SkillInfo(skillList[i]);
                                npc.GetSkillStateInfo().AddSkill(skillInfo);
                            }
                        }
                        npc.SkillController  = new SwordManSkillController(npc, GfxModule.Skill.GfxSkillSystem.Instance);
                        npc.OwnerId          = playerself.GetId();
                        playerself.PartnerId = npc.GetId();
                        EntityManager.Instance.CreateNpcView(npc.GetId());
                        if (partnerInfo.BornSkill > 0)
                        {
                            SkillInfo skillInfo = new SkillInfo(partnerInfo.BornSkill);
                            npc.GetSkillStateInfo().AddSkill(skillInfo);
                            npc.SkillController.ForceStartSkill(partnerInfo.BornSkill);
                        }
                        CharacterView view = EntityManager.Instance.GetCharacterViewById(npc.GetId());
                        if (null != view)
                        {
                            GfxSystem.SetLayer(view.Actor, "PhysicObj");
                        }
                    }
                }
            }
        }
예제 #29
0
        public void OnGfxHitTarget(int id, int impactId, int targetId, int hitCount,
                                   int skillId, int duration, float x,
                                   float y, float z, float dir, long hit_count_id)
        {
            CharacterInfo sender               = WorldSystem.Instance.GetCharacterById(id);
            CharacterInfo target               = WorldSystem.Instance.GetCharacterById(targetId);
            UserInfo      playerSelf           = WorldSystem.Instance.GetPlayerSelf();
            bool          hitCountChanged      = false;
            bool          playerHitCountChange = false;
            long          curTime              = TimeUtility.GetLocalMilliseconds();

            UpdateHitTalent(sender, hit_count_id);
            // 攻击
            if (hitCount > 0)
            {
                CombatStatisticInfo senderCombatInfo = sender.GetCombatStatisticInfo();
                int last_count = senderCombatInfo.MultiHitCount;
                if (IsImpactHaveDamage(impactId))
                {
                    hitCountChanged = senderCombatInfo.UpdateMultiHitCount(hit_count_id, hitCount, curTime);
                }
                if (id == WorldSystem.Instance.PlayerSelfId && null != playerSelf)
                {
                    if (senderCombatInfo.MultiHitCount >= 1 && last_count != senderCombatInfo.MultiHitCount)
                    {
                        GfxSystem.PublishGfxEvent("ge_hitcount", "ui", senderCombatInfo.MultiHitCount);
                        playerHitCountChange = hitCountChanged;
                    }
                }
                CombatStatisticInfo targetCombatInfo = target.GetCombatStatisticInfo();
                targetCombatInfo.HitCount += hitCount;
                if (targetId == WorldSystem.Instance.PlayerSelfId && null != playerSelf)
                {
                    if (WorldSystem.Instance.IsELiteScene())
                    {
                        RoleInfo      roleInfo = LobbyClient.Instance.CurrentRole;
                        SceneResource curScene = WorldSystem.Instance.GetCurScene();
                        if (null != roleInfo && null != curScene && roleInfo.GetSceneInfo(WorldSystem.Instance.GetCurSceneId()) == 2)
                        { //当前在挑战3星通关
                            GfxSystem.PublishGfxEvent("ge_pve_fightinfo", "ui", 0, targetCombatInfo.HitCount, curScene.SceneConfig.m_CompletedHitCount, 0);
                        }
                        playerHitCountChange = true;
                    }
                }
            }
            if (playerHitCountChange && null != playerSelf && (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene()))
            {
                CombatStatisticInfo combatInfo = playerSelf.GetCombatStatisticInfo();
                ArkCrossEngineMessage.Msg_CR_HitCountChanged msg = new ArkCrossEngineMessage.Msg_CR_HitCountChanged();
                msg.max_multi_hit_count = combatInfo.MaxMultiHitCount;
                msg.hit_count           = combatInfo.HitCount;
                Network.NetworkSystem.Instance.SendMessage(msg);
            }
            if (null != sender && null != target)
            {
                int hit_count = 0;
                hit_count = sender.GetCombatStatisticInfo().MultiHitCount;
                OnGfxStartImpact(sender.GetId(), impactId, target.GetId(), skillId, duration, new Vector3(x, y, z), dir,
                                 hit_count);
            }
        }
        private void PathToTarget(UserInfo user, AiPathData data, Vector3 pathTargetPos, long deltaTime)
        {
            UserAiStateInfo info = user.GetAiStateInfo();

            if (null != data)
            {
                data.UpdateTime += deltaTime;
                Vector3 srcPos        = user.GetMovementStateInfo().GetPosition3D();
                float   dir           = user.GetMovementStateInfo().GetMoveDir();
                bool    findObstacle  = false;
                bool    havePathPoint = data.HavePathPoint;
                if (havePathPoint)
                {//沿路点列表移动的逻辑
                    Vector3 targetPos = data.CurPathPoint;
                    if (!data.IsReached(srcPos))
                    {//向指定路点移动(避让移动过程)
                        user.GetMovementStateInfo().TargetPosition = targetPos;
                        float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                        if (!Geometry.IsSameDouble(angle, user.GetMovementStateInfo().GetMoveDir()))
                        {
                            user.GetMovementStateInfo().SetFaceDir(angle);
                            user.GetMovementStateInfo().SetMoveDir(angle);
                            user.GetMovementStateInfo().IsMoving = true;
                            NotifyUserMove(user);
                        }
                    }
                    else
                    {//改变路点或结束沿路点移动
                        data.UseNextPathPoint();
                        if (data.HavePathPoint)
                        {
                            targetPos = data.CurPathPoint;
                            user.GetMovementStateInfo().TargetPosition = targetPos;
                            float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                            user.GetMovementStateInfo().SetFaceDir(angle);
                            user.GetMovementStateInfo().SetMoveDir(angle);
                            user.GetMovementStateInfo().IsMoving = true;
                            NotifyUserMove(user);
                        }
                        else
                        {
                            data.Clear();
                        }
                    }
                }
                if (!user.UnityPathFinding)
                {
                    if (!havePathPoint || findObstacle)
                    {//获得路点过程(寻路)
                        data.Clear();
                        Vector3 targetPos = pathTargetPos;
                        if (Geometry.DistanceSquare(srcPos, targetPos) > 400)
                        {
                            targetPos = user.SpatialSystem.CalcNearstReachablePoint(srcPos, targetPos, 20);
                        }
                        bool canGo = true;

                        /*
                         * if (!user.SpatialSystem.GetCellMapView(user.AvoidanceRadius).CanPass(targetPos)) {
                         * if (!AiLogicUtility.GetWalkablePosition(user.SpatialSystem.GetCellMapView(user.AvoidanceRadius), targetPos, srcPos, ref targetPos))
                         *  canGo = false;
                         * }*/
                        if (canGo)
                        {
                            List <Vector3> posList = null;
                            if (user.SpatialSystem.CanPass(user.SpaceObject, targetPos))
                            {
                                posList = new List <Vector3>();
                                posList.Add(srcPos);
                                posList.Add(targetPos);
                            }
                            else
                            {
                                long stTime = TimeUtility.GetElapsedTimeUs();
                                posList = user.SpatialSystem.FindPath(srcPos, targetPos, user.AvoidanceRadius);
                                long endTime  = TimeUtility.GetElapsedTimeUs();
                                long calcTime = endTime - stTime;
                                if (calcTime > 1000)
                                {
                                    // LogSystem.Warn("pvp FindPath consume {0} us,user:{1} from:{2} to:{3} radius:{4} pos:{5}", calcTime, user.GetId(), srcPos.ToString(), targetPos.ToString(), user.AvoidanceRadius, user.GetMovementStateInfo().GetPosition3D().ToString());
                                }
                            }
                            if (posList.Count >= 2)
                            {
                                data.SetPathPoints(posList[0], posList, 1);
                                targetPos = data.CurPathPoint;
                                user.GetMovementStateInfo().TargetPosition = targetPos;
                                float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                                user.GetMovementStateInfo().SetFaceDir(angle);
                                user.GetMovementStateInfo().SetMoveDir(angle);
                                user.GetMovementStateInfo().IsMoving = true;
                                NotifyUserMove(user);
                            }
                            else
                            {
                                user.GetMovementStateInfo().IsMoving = false;
                                NotifyUserMove(user);
                            }
                        }
                        else
                        {
                            user.GetMovementStateInfo().IsMoving = false;
                            NotifyUserMove(user);
                        }
                    }
                }
                else
                {
                    if (!havePathPoint || findObstacle)
                    {
                        user.GetMovementStateInfo().IsMoving = false;
                        NotifyUserMove(user);
                    }
                }
            }
        }