protected override void OnStateLogicInit(EntityInfo entity, long deltaTime)
 {
     AiStateInfo info = entity.GetAiStateInfo();
     info.Time = 0;
     info.HomePos = entity.GetMovementStateInfo().GetPosition3D();
     info.Target = 0;
 }
 internal static Msg_RC_NpcFace BuildNpcFaceMessage(EntityInfo npc)
 {
     Msg_RC_NpcFace npcFaceBuilder = new Msg_RC_NpcFace();
     npcFaceBuilder.npc_id = npc.GetId();
     npcFaceBuilder.face_direction = ProtoHelper.EncodeFloat(npc.GetMovementStateInfo().GetFaceDir());
     return npcFaceBuilder;
 }
 internal static Msg_RC_CampChanged BuildCampChangedMessage(EntityInfo obj)
 {
     Msg_RC_CampChanged msg = new Msg_RC_CampChanged();
     msg.obj_id = obj.GetId();
     msg.camp_id = obj.GetCampId();
     return msg;
 }
        internal static Msg_RC_CreateNpc BuildCreateNpcMessage(EntityInfo npc, int rate = -1)
        {
            Msg_RC_CreateNpc bder = new Msg_RC_CreateNpc();
            bder.npc_id = npc.GetId();
            bder.unit_id = npc.GetUnitId();
            ScriptRuntime.Vector3 pos = npc.GetMovementStateInfo().GetPosition3D();
            GameFrameworkMessage.Position pos_bd = new GameFrameworkMessage.Position();
            pos_bd.x = (float)pos.X;
            pos_bd.z = (float)pos.Z;
            bder.cur_pos = pos_bd;
            bder.face_direction = (float)npc.GetMovementStateInfo().GetFaceDir();
            bder.link_id = npc.GetLinkId();
            bder.camp_id = npc.GetCampId();
            if (npc.OwnerId > 0) {
                bder.owner_id = npc.OwnerId;
            }
            if (npc.GetAiStateInfo().LeaderID > 0) {
                bder.leader_id = npc.GetAiStateInfo().LeaderID;
            }
            User user = npc.CustomData as User;
            if (null != user) {
                bder.key = user.GetKey();
            }
            bder.level = npc.GetLevel();

            return bder;
        }
 private void OnCreateEntity(EntityInfo entity)
 {
     if (null != entity) {
     StorySystem.SendMessage("obj_created", entity.GetId());
     StorySystem.SendMessage(string.Format("npc_created:{0}", entity.GetUnitId()), entity.GetId());
     }
 }
예제 #6
0
 private void TickNpc(EntityInfo entity, long delta)
 {
     IAiStateLogic logic = AiLogicManager.Instance.GetNpcStateLogic(entity.GetAiStateInfo().AiLogic);
     if (null != logic) {
         logic.Execute(entity, delta);
     }
 }
 internal GfxSkillSenderInfo(TableConfig.Skill configData, int seq, int actorId, EntityInfo gfxObj, Scene scene)
 {
     m_Seq = seq;
     m_ConfigData = configData;
     m_ActorId = actorId;
     m_GfxObj = gfxObj;
     m_Scene = scene;
 }
 private void OnAiFace(EntityInfo entity)
 {
     if (null != entity && entity.EntityType != (int)EntityTypeEnum.Tower) {
         float dir = entity.GetMovementStateInfo().GetFaceDir();
         GameObject actor = EntityController.Instance.GetGameObject(entity.GetId());
         actor.transform.localRotation = Quaternion.Euler(0, Utility.RadianToDegree(dir), 0);
     }
 }
 private void DslLogicHandler(EntityInfo entity, long deltaTime)
 {
     AiStateInfo info = entity.GetAiStateInfo();
     if (null != info.AiStoryInstanceInfo) {
         long curTime = TimeUtility.GetLocalMilliseconds();
         info.AiStoryInstanceInfo.m_StoryInstance.Tick(curTime);
     }
 }
예제 #10
0
 public void AddObjForBuild(EntityInfo obj)
 {
     if (null == m_Objects[m_ObjectNum])
         m_Objects[m_ObjectNum] = new KdTreeObject(obj);
     else
         m_Objects[m_ObjectNum].CopyFrom(obj);
     ++m_ObjectNum;
 }
 protected override bool OnStateLogicCheck(EntityInfo npc, long deltaTime)
 {
     if (npc.IsDead()) {
         NotifyAiDead(npc);
         return false;
     }
     return true;
 }
 public static void RefixAttrByImpact(EntityInfo obj)
 {
     List<ImpactInfo> impacts = obj.GetSkillStateInfo().GetAllImpact();
     for (int i = 0; i < impacts.Count; ++i) {
         ImpactInfo impact = impacts[i];
         impact.RefixCharacterProperty(obj);
     }
 }
        public static void Calc(EntityInfo entity)
        {
            ResetBaseProperty(entity);
            RefixAttrByImpact(entity);

            int hpMax = entity.GetActualProperty().HpMax;
            entity.GetActualProperty().SetHpMax(Operate_Type.OT_Absolute, hpMax);
        }
 private void IdleHandler(EntityInfo entity, long deltaTime)
 {
     AiStateInfo info = entity.GetAiStateInfo();
     info.Time += deltaTime;
     if (info.Time > 100) {
         info.Time = 0;
         ChangeToState(entity, (int)AiStateId.DslLogic);
     }
 }
 private AiData_General GetAiData(EntityInfo entity)
 {
     AiData_General data = entity.GetAiStateInfo().AiDatas.GetData<AiData_General>();
     if (null == data) {
         data = new AiData_General();
         entity.GetAiStateInfo().AiDatas.AddData(data);
     }
     return data;
 }
 public static EntityInfo GetHearstTargetHelper(EntityInfo srcObj,float range,CharacterRelation relation, AiTargetType type)
 {
     EntityInfo nearstTarget = null;
     float minPowDist = 999999;
     srcObj.SceneContext.KdTree.Query(srcObj, range, (float distSqr, KdTreeObject kdTreeObj) => {
         StepCalcNearstTarget(srcObj, relation, type, distSqr, kdTreeObj.Object, ref minPowDist, ref nearstTarget);
     });
     return nearstTarget;
 }
 private void OnDestroyEntity(EntityInfo entity)
 {
     if (null != entity) {
     TableConfig.LevelMonster monster = entity.LevelMonsterData;
     if (null != monster) {
         ReloadMonstersQueue.Enqueue(monster);
     }
     }
 }
 public static EntityInfo GetLivingCharacterInfoHelper(EntityInfo srcObj, int id)
 {
     EntityInfo target = srcObj.EntityManager.GetEntityInfo(id);
     if (null != target) {
         if (target.IsDead())
             target = null;
     }
     return target;
 }
        private void CombatHandler(EntityInfo npc, long deltaTime)
        {
            if (npc.GetSkillStateInfo().IsSkillActivated()) {
                return;
            }

            AiStateInfo info = npc.GetAiStateInfo();
            Vector3 targetPos = info.HomePos;
            ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
            float distSqrToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
            if (distSqrToHome > npc.GohomeRange * npc.GohomeRange) {
                NotifyAiStopPursue(npc);
                ChangeToState(npc, (int)AiStateId.GoHome);
                return;
            }

            ///
            EntityInfo attackTarget = null;
            SkillStateInfo currSkInfo = npc.GetSkillStateInfo();
            ///找到可以使用的技能
            SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc, this.GetAiData(npc), true);
            NotifyAiSelectSkill(npc, skInfo);
            if (skInfo == null) {
                //没有可以使用的技能就切换到Idle状态
                ChangeToState(npc, (int)AiStateId.Idle);
                return;
            }

            CharacterRelation relation =
                    (skInfo.TargetType == SkillTargetType.Friend ||
                    skInfo.TargetType == SkillTargetType.RandFriend) ?
                    CharacterRelation.RELATION_FRIEND :
                    CharacterRelation.RELATION_ENEMY;

            attackTarget = AiLogicUtility.GetNearstTargetHelper(
                npc, skInfo.Distance, relation);

            if (attackTarget != null && null != skInfo) //攻击范围内找到可攻击目标
            {
                info.Target = attackTarget.GetId();
                NotifyAiStopPursue(npc);
                NotifyAiSkill(npc, skInfo.SkillId); //攻击目标
                return;
            }
            attackTarget = AiLogicUtility.GetNearstTargetHelper(
            npc, npc.ViewRange, relation);
            if (attackTarget != null) //视野范围内找到可攻击目标
            {
                NotifyAiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); // 追赶目标
                return;
            }

            currSkInfo.SetCurSkillInfo(0);
            NotifyAiStopPursue(npc);
            ChangeToState(npc, (int)AiStateId.GoHome);
        }
        private void CombatHandler(EntityInfo npc, long deltaTime)
        {
            AiStateInfo aiInfo = npc.GetAiStateInfo();
            AiData_Leader aiData = GetAiData(npc);
            if (npc.GetSkillStateInfo().IsSkillActivated()) {
                return;
            }
            ///
            SkillStateInfo currSkInfo = npc.GetSkillStateInfo();
            ///找到可以使用的技能
            SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc, this.GetAiData(npc), aiData.IsAutoOperate);
            NotifyAiSelectSkill(npc, skInfo);
            if (skInfo == null) {
                //没有可以使用的技能就切换到Idle状态
                ChangeToState(npc, (int)AiStateId.Idle);
                return;
            }

            CharacterRelation relation =
                    (skInfo.TargetType == SkillTargetType.Friend ||
                    skInfo.TargetType == SkillTargetType.RandFriend) ?
                    CharacterRelation.RELATION_FRIEND :
                    CharacterRelation.RELATION_ENEMY;
            EntityInfo attackTarget = AiLogicUtility.GetNearstAttackerHelper(npc, relation, aiData);
            if (null != attackTarget) {
                NotifyAiTarget(npc, attackTarget);
                if (Geometry.DistanceSquare(npc.GetMovementStateInfo().GetPosition3D(), attackTarget.GetMovementStateInfo().GetPosition3D()) < skInfo.Distance * skInfo.Distance) {
                    aiInfo.Target = attackTarget.GetId();
                    NotifyAiStopPursue(npc);
                    NotifyAiSkill(npc, skInfo.SkillId);
                    return;
                }
            }
            attackTarget = AiLogicUtility.GetNearstTargetHelper(npc, skInfo.Distance, relation);
            if (attackTarget != null && null != skInfo) { //攻击范围内找到可攻击目标
                NotifyAiTarget(npc, attackTarget);
                aiInfo.Target = attackTarget.GetId();
                NotifyAiStopPursue(npc);
                NotifyAiSkill(npc, skInfo.SkillId); //攻击目标
                return;
            }
            if (aiData.IsAutoOperate) {
                attackTarget = AiLogicUtility.GetNearstTargetHelper(npc, npc.ViewRange, relation);
                if (attackTarget != null && null != skInfo) { //视野内找到可攻击目标
                    NotifyAiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D());
                    return;
                }
            }

            ///退出战斗模式清理一下手动技能
            currSkInfo.SetCurSkillInfo(0);
            aiData.ManualSkillId = 0;
            NotifyAiStopPursue(npc);
            ChangeToState(npc, (int)AiStateId.Idle);
        }
 internal int GetBattleNpcCount(EntityInfo src, CharacterRelation relation)
 {
     int ct = 0;
     for (LinkedListNode<EntityInfo> linkNode = m_EntityMgr.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next) {
         EntityInfo info = linkNode.Value;
         if (null != info && !info.IsDead() && info.IsCombatNpc() && EntityInfo.GetRelation(src, info) == relation) {
             ++ct;
         }
     }
     return ct;
 }
 protected override bool OnStateLogicCheck(EntityInfo entity, long deltaTime)
 {
     if (entity.IsDead()) {
         if (entity.GetAiStateInfo().CurState != (int)AiStateId.Idle) {
             NotifyAiStopPursue(entity);
             ChangeToState(entity, (int)AiStateId.Idle);
         }
         return false;
     }
     return true;
 }
 private void OnAiAddImpact(EntityInfo entity, int impactId)
 {
     ImpactInfo impactInfo = new ImpactInfo(impactId);
     impactInfo.StartTime = TimeUtility.GetLocalMilliseconds();
     impactInfo.ImpactSenderId = entity.GetId();
     impactInfo.SkillId = 0;
     if (null != impactInfo.ConfigData) {
         entity.GetSkillStateInfo().AddImpact(impactInfo);
         int seq = impactInfo.Seq;
         if (GfxSkillSystem.Instance.StartSkill(entity.GetId(), impactInfo.ConfigData, seq)) {
         }
     }
 }
        internal static Msg_RC_NpcSkill BuildNpcSkillMessage(EntityInfo obj, int skillId)
        {
            MovementStateInfo msi = obj.GetMovementStateInfo();
            ScriptRuntime.Vector3 pos = msi.GetPosition3D();

            Msg_RC_NpcSkill msg = new Msg_RC_NpcSkill();
            msg.npc_id = obj.GetId();
            msg.skill_id = skillId;
            msg.stand_pos = ProtoHelper.EncodePosition2D(pos.X, pos.Z);
            msg.face_direction = ProtoHelper.EncodeFloat(msi.GetFaceDir());
            msg.target_id = obj.GetAiStateInfo().Target;

            return msg;
        }
 private void OnAiInitDslLogic(EntityInfo entity)
 {
     AiStateInfo aiInfo = entity.GetAiStateInfo();
     if (aiInfo.AiParam.Length >= 2) {
         string storyId = aiInfo.AiParam[0];
         string storyFile = aiInfo.AiParam[1];
         if (!string.IsNullOrEmpty(storyId) && !string.IsNullOrEmpty(storyFile)) {
             aiInfo.AiStoryInstanceInfo = GfxStorySystem.Instance.NewAiStoryInstance(storyId, string.Empty, storyFile);
             if (null != aiInfo.AiStoryInstanceInfo) {
                 aiInfo.AiStoryInstanceInfo.m_StoryInstance.SetVariable("@objid", entity.GetId());
                 aiInfo.AiStoryInstanceInfo.m_StoryInstance.Start();
             }
         }
     }
 }
 protected override bool OnStateLogicCheck(EntityInfo entity, long deltaTime)
 {
     if (entity.IsDead()) {
         if (entity.GetAiStateInfo().CurState != (int)AiStateId.Idle) {
             NotifyAiStopPursue(entity);
             ChangeToState(entity, (int)AiStateId.Idle);
         }
         return false;
     }
     if (IsLeaderDead(entity)) {
         entity.SetHp(Operate_Type.OT_Absolute, 0);
         return false;
     }
     return true;
 }
 internal static Msg_RC_NpcMove BuildNpcMoveMessage(EntityInfo npc)
 {
     ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
     Msg_RC_NpcMove npcMoveBuilder = new Msg_RC_NpcMove();
     if (npc.GetMovementStateInfo().IsMoving) {
         npcMoveBuilder.npc_id = npc.GetId();
         npcMoveBuilder.velocity = ProtoHelper.EncodeFloat(npc.GetActualProperty().MoveSpeed);
         ScriptRuntime.Vector3 targetPos = npc.GetMovementStateInfo().TargetPosition;
         npcMoveBuilder.target_pos = ProtoHelper.EncodePosition2D(targetPos.X, targetPos.Z);
         npcMoveBuilder.cur_pos = ProtoHelper.EncodePosition2D(srcPos.X, srcPos.Z);
     } else {
         npcMoveBuilder.npc_id = npc.GetId();
         npcMoveBuilder.cur_pos = ProtoHelper.EncodePosition2D(srcPos.X, srcPos.Z);
     }
     return npcMoveBuilder;
 }
 private void OnAiFace(EntityInfo npc)
 {
     if (npc.GetMovementStateInfo().IsFaceDirChanged) {
         npc.GetMovementStateInfo().IsFaceDirChanged = false;
         if (null != npc) {
             float dir = npc.GetMovementStateInfo().GetFaceDir();
             npc.GetMovementStateInfo().SetFaceDir(dir);
         }
         if (!npc.GetMovementStateInfo().IsMoving) {
             Scene scene = npc.SceneContext.CustomData as Scene;
             if (null != scene) {
                 Msg_RC_NpcFace npcFaceBuilder = DataSyncUtility.BuildNpcFaceMessage(npc);
                 if (null != npcFaceBuilder)
                     scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcFace, npcFaceBuilder);
             }
         }
     }
 }
        private void OnAiPursue(EntityInfo npc, ScriptRuntime.Vector3 target)
        {
            Scene scene = npc.SceneContext.CustomData as Scene;
            if (null != scene) {
                npc.GetMovementStateInfo().TargetPosition = target;
                float dir = Geometry.GetYRadian(npc.GetMovementStateInfo().GetPosition3D(), target);
                npc.GetMovementStateInfo().SetFaceDir(dir);
                npc.GetMovementStateInfo().SetMoveDir(dir);
                npc.GetMovementStateInfo().IsMoving = true;

                if (npc.GetMovementStateInfo().IsMoveStatusChanged) {
                    npc.GetMovementStateInfo().IsMoveStatusChanged = false;

                    Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(npc);
                    if (null != npcMoveBuilder)
                        scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder);
                }
            }
        }
예제 #30
0
 public void RefixCharacterProperty(EntityInfo entity)
 {
     if (DamageData.AddAttack != 0) {
         entity.GetActualProperty().SetAttackBase(Operate_Type.OT_Relative, DamageData.AddAttack);
     }
     if (DamageData.AddDefence != 0) {
         entity.GetActualProperty().SetDefenceBase(Operate_Type.OT_Relative, DamageData.AddDefence);
     }
     if (DamageData.AddRps != 0) {
         entity.GetActualProperty().SetRps(Operate_Type.OT_Relative, DamageData.AddRps);
     }
     if (DamageData.AddCritical != 0) {
         entity.GetActualProperty().SetCritical(Operate_Type.OT_Relative, DamageData.AddCritical);
     }
     if (DamageData.AddCriticalPow != 0) {
         entity.GetActualProperty().SetCriticalPow(Operate_Type.OT_Relative, DamageData.AddCriticalPow);
     }
     if (Math.Abs(DamageData.AddSpeed) > Geometry.c_FloatPrecision) {
         entity.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Relative, DamageData.AddSpeed);
     }
 }
        internal bool StartSkill(int actorId, TableConfig.Skill configData, int seq, params Dictionary <string, object>[] locals)
        {
            bool ret = false;

            if (null == configData)
            {
                LogSystem.Error("{0} can't cast skill, config is null !", actorId, seq);
                Helper.LogCallStack();
                return(false);
            }
            if (!m_Scene.EntityController.CanCastSkill(actorId, configData, seq))
            {
                m_Scene.EntityController.CancelCastSkill(actorId);
                LogSystem.Warn("{0} can't cast skill {1} {2}, cancel.", actorId, configData.id, seq);
                m_Scene.EntityController.CancelIfImpact(actorId, configData, seq);
                return(false);
            }
            GfxSkillSenderInfo senderInfo = m_Scene.EntityController.BuildSkillInfo(actorId, configData, seq, m_Scene);

            if (null != senderInfo && null != senderInfo.GfxObj)
            {
                int            skillId   = senderInfo.SkillId;
                EntityInfo     obj       = senderInfo.GfxObj;
                SkillLogicInfo logicInfo = m_SkillLogicInfos.Find(info => info.GfxObj == obj && info.SkillId == skillId && info.Seq == seq);
                if (logicInfo != null)
                {
                    LogSystem.Warn("{0} is casting skill {1} {2}, cancel.", actorId, skillId, seq);
                    m_Scene.EntityController.CancelIfImpact(actorId, configData, seq);
                    return(false);
                }
                SkillInstanceInfo inst          = null;
                SkillInstance     innerInstance = null;
                if (skillId == PredefinedSkill.c_EmitSkillId)
                {
                    for (int i = 0; i < locals.Length; ++i)
                    {
                        object instObj;
                        if (locals[i].TryGetValue("emitskill", out instObj))
                        {
                            innerInstance = instObj as SkillInstance;
                        }
                    }
                    if (null == innerInstance)
                    {
                        LogSystem.Warn("{0} use predefined skill {1} {2} but not found emitskill, cancel.", actorId, skillId, seq);
                        //m_Scene.EntityController.CancelIfImpact(actorId, configData, seq);
                        //return false;
                    }
                }
                else if (skillId == PredefinedSkill.c_HitSkillId)
                {
                    for (int i = 0; i < locals.Length; ++i)
                    {
                        object instObj;
                        if (locals[i].TryGetValue("hitskill", out instObj))
                        {
                            innerInstance = instObj as SkillInstance;
                        }
                    }
                    if (null == innerInstance)
                    {
                        LogSystem.Warn("{0} use predefined skill {1} {2} but not found hitskill, cancel.", actorId, skillId, seq);
                        //m_Scene.EntityController.CancelIfImpact(actorId, configData, seq);
                        //return false;
                    }
                }
                if (null == innerInstance)
                {
                    inst = NewSkillInstance(skillId, senderInfo.ConfigData);
                }
                else
                {
                    inst = NewInnerSkillInstance(skillId, innerInstance);
                }
                if (null != inst)
                {
                    m_SkillLogicInfos.Add(new SkillLogicInfo(senderInfo, inst));
                }
                else
                {
                    LogSystem.Warn("{0} cast skill {1} {2}, alloc failed.", actorId, skillId, seq);
                    m_Scene.EntityController.CancelIfImpact(actorId, configData, seq);
                    return(false);
                }

                logicInfo = m_SkillLogicInfos.Find(info => info.GfxObj == obj && info.SkillId == skillId && info.Seq == seq);
                if (null != logicInfo)
                {
                    if (null != locals)
                    {
                        int localCount = locals.Length;
                        for (int i = 0; i < localCount; ++i)
                        {
                            foreach (KeyValuePair <string, object> pair in locals[i])
                            {
                                logicInfo.SkillInst.SetVariable(pair.Key, pair.Value);
                            }
                        }
                    }
                    EntityInfo target = senderInfo.TargetGfxObj;
                    if (null != target && target != obj && configData.type == (int)SkillOrImpactType.Skill)
                    {
                        TriggerUtil.Lookat(m_Scene, obj, target.GetMovementStateInfo().GetPosition3D());
                    }
                    m_Scene.EntityController.ActivateSkill(actorId, skillId, seq);
                    logicInfo.SkillInst.Context = m_Scene;
                    logicInfo.SkillInst.Start(logicInfo.Sender);
                    ret = true;
                }
            }
            return(ret);
        }
예제 #32
0
        internal void ImpactDamage(int srcObjId, int targetId, int impactId, int seq, bool isFinal)
        {
            if (ClientModule.Instance.IsRoomScene)
            {
                return;
            }
            EntityViewModel view    = GetEntityViewById(targetId);
            EntityViewModel srcView = GetEntityViewById(srcObjId);

            if (null != view && null != view.Entity && null != view.Actor)
            {
                EntityInfo entity = view.Entity;
                EntityInfo srcNpc = null;
                if (null != srcView && null != srcView.Entity)
                {
                    srcNpc = srcView.Entity;
                }
                ImpactInfo impactInfo = entity.GetSkillStateInfo().GetImpactInfoBySeq(seq);
                if (null != impactInfo && impactId == impactInfo.ImpactId)
                {
                    TableConfig.Skill cfg = impactInfo.ConfigData;
                    int   targetType      = impactInfo.TargetType;
                    float damage          = impactInfo.DamageData.Damage;
                    int   addShield       = impactInfo.DamageData.AddShield;
                    int   hpRecover       = impactInfo.DamageData.HpRecover;

                    if (hpRecover != 0)
                    {
                        entity.SetHp(Operate_Type.OT_Relative, (int)impactInfo.DamageData.HpRecover);
                        entity.SetAttackerInfo(srcObjId, false, true, false, -impactInfo.DamageData.HpRecover, 0);
                    }
                    if (addShield != 0)
                    {
                        entity.SetShield(Operate_Type.OT_Relative, impactInfo.DamageData.AddShield);
                    }
                    if ((targetType == (int)SkillTargetType.Enemy || targetType == (int)SkillTargetType.RandEnemy) && damage != 0)
                    {
                        if (entity.EntityType == (int)EntityTypeEnum.Tower)
                        {
                            if (null != srcNpc && srcNpc.NormalSkillId != impactInfo.SkillId)
                            {
                                //技能打塔不产生伤害
                                return;
                            }
                        }
                        bool isKiller = false;
                        if (entity.Shield >= damage)
                        {
                            entity.SetShield(Operate_Type.OT_Relative, -(int)damage);
                        }
                        else if (entity.Shield > 0)
                        {
                            int leftDamage = (int)damage - entity.Shield;
                            entity.SetShield(Operate_Type.OT_Absolute, 0);
                            if (entity.GetId() == ClientModule.Instance.LeaderID && entity.Hp <= leftDamage)
                            {
                                //队长不死,demo专用代码
                            }
                            else
                            {
                                entity.SetHp(Operate_Type.OT_Relative, -(int)leftDamage);
                                if (entity.Hp <= 0)
                                {
                                    isKiller = true;
                                }
                            }
                        }
                        else
                        {
                            if (entity.GetId() == ClientModule.Instance.LeaderID && entity.Hp <= damage)
                            {
                                //队长不死,demo专用代码
                            }
                            else
                            {
                                entity.SetHp(Operate_Type.OT_Relative, -(int)damage);
                                if (entity.Hp <= 0)
                                {
                                    isKiller = true;
                                }
                            }
                        }
                        if (isKiller)
                        {
                            entity.GetCombatStatisticInfo().AddDeadCount(1);
                            if (null != srcNpc)
                            {
                                EntityInfo killer = srcNpc;
                                if (killer.SummonerId > 0)
                                {
                                    EntityViewModel npcViewModel = GetEntityViewById(killer.SummonerId);
                                    if (null != npcViewModel)
                                    {
                                        killer = npcViewModel.Entity;
                                    }
                                }
                                if (entity.EntityType == (int)EntityTypeEnum.Tower)
                                {
                                    killer.GetCombatStatisticInfo().AddKillTowerCount(1);
                                }
                                else if (entity.EntityType == (int)EntityTypeEnum.Hero)
                                {
                                    killer.GetCombatStatisticInfo().AddKillHeroCount(1);
                                    killer.GetCombatStatisticInfo().AddMultiKillCount(1);
                                }
                                else
                                {
                                    killer.GetCombatStatisticInfo().AddKillNpcCount(1);
                                }
                            }
                        }
                        entity.SetAttackerInfo(srcObjId, isKiller, true, false, (int)damage, 0);
                    }
                }
            }
        }
 private void WaitCommandHandler(EntityInfo entity, long deltaTime)
 {
 }
        private void CombatHandler(EntityInfo npc, long deltaTime)
        {
            if (npc.GetSkillStateInfo().IsSkillActivated())
            {
                return;
            }

            AiStateInfo info      = npc.GetAiStateInfo();
            Vector3     targetPos = info.HomePos;

            ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
            float distSqrToHome          = Geometry.DistanceSquare(srcPos, info.HomePos);

            if (distSqrToHome > npc.GohomeRange * npc.GohomeRange)
            {
                NotifyAiStopPursue(npc);
                ChangeToState(npc, (int)AiStateId.GoHome);
                return;
            }

            ///
            EntityInfo     attackTarget = null;
            SkillStateInfo currSkInfo   = npc.GetSkillStateInfo();
            ///找到可以使用的技能
            SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc, this.GetAiData(npc), true);

            NotifyAiSelectSkill(npc, skInfo);
            if (skInfo == null)
            {
                //没有可以使用的技能就切换到Idle状态
                ChangeToState(npc, (int)AiStateId.Idle);
                return;
            }

            CharacterRelation relation =
                (skInfo.TargetType == SkillTargetType.Friend ||
                 skInfo.TargetType == SkillTargetType.RandFriend) ?
                CharacterRelation.RELATION_FRIEND :
                CharacterRelation.RELATION_ENEMY;

            attackTarget = AiLogicUtility.GetNearstTargetHelper(
                npc, skInfo.Distance, relation);

            if (attackTarget != null && null != skInfo) //攻击范围内找到可攻击目标
            {
                info.Target = attackTarget.GetId();
                NotifyAiStopPursue(npc);
                NotifyAiSkill(npc, skInfo.SkillId); //攻击目标
                return;
            }
            attackTarget = AiLogicUtility.GetNearstTargetHelper(
                npc, npc.ViewRange, relation);
            if (attackTarget != null)                                                     //视野范围内找到可攻击目标
            {
                NotifyAiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); // 追赶目标
                return;
            }

            currSkInfo.SetCurSkillInfo(0);
            NotifyAiStopPursue(npc);
            ChangeToState(npc, (int)AiStateId.GoHome);
        }
 public static void ResetBaseProperty(EntityInfo obj)
 {
     obj.CalcBaseAttr();
 }
 internal GfxSkillSenderInfo(TableConfig.Skill configData, int seq, int actorId, EntityInfo gfxObj, int targetActorId, EntityInfo targetGfxObj, Scene scene)
     : this(configData, seq, actorId, gfxObj, scene)
 {
     m_TargetActorId = targetActorId;
     m_TargetGfxObj  = targetGfxObj;
 }
 internal GfxSkillSenderInfo(TableConfig.Skill configData, int seq, int actorId, EntityInfo gfxObj, Scene scene)
 {
     m_Seq        = seq;
     m_ConfigData = configData;
     m_ActorId    = actorId;
     m_GfxObj     = gfxObj;
     m_Scene      = scene;
 }
예제 #38
0
        public int GetDyingBattleNpcCount(int campId, CharacterRelation relation)
        {
            int ct = 0;

            for (LinkedListNode <EntityInfo> linkNode = m_EntityMgr.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                EntityInfo info = linkNode.Value;
                if (null != info && info.IsDead() && info.DeadTime != 0 && info.IsCombatNpc() && EntityInfo.GetRelation(campId, info.GetCampId()) == relation)
                {
                    ++ct;
                }
            }
            return(ct);
        }
예제 #39
0
        internal bool ExistGameObject(int objId)
        {
            EntityInfo obj = m_Scene.EntityManager.GetEntityInfo(objId);

            return(null != obj);
        }
 private void PatrolCommandHandler(EntityInfo entity, long deltaTime)
 {
     AiLogicUtility.DoPatrolCommandState(entity, deltaTime, this);
 }
예제 #41
0
        private void TickRunning()
        {
            TimeSnapshot.DoCheckPoint();

            m_KdTree.BeginBuild(m_EntityMgr.Entities.Count);
            for (LinkedListNode <EntityInfo> linkNode = m_EntityMgr.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                EntityInfo info = linkNode.Value;
                m_KdTree.AddObjForBuild(info);
            }
            m_KdTree.EndBuild();

            m_ServerDelayActionProcessor.HandleActions(100);
            m_SceneProfiler.DelayActionProcessorTime = TimeSnapshot.DoCheckPoint();

            m_MovementSystem.Tick();
            m_SceneProfiler.MovementSystemTime = TimeSnapshot.DoCheckPoint();

            TickAi();
            m_SceneProfiler.AiSystemTime = TimeSnapshot.DoCheckPoint();

            m_SceneLogicSystem.Tick();
            m_SceneProfiler.SceneLogicSystemTime = TimeSnapshot.DoCheckPoint();

            m_StorySystem.Tick();
            m_GmStorySystem.Tick();
            m_SceneProfiler.StorySystemTime = TimeSnapshot.DoCheckPoint();

            TickEntities();
            m_SceneProfiler.TickEntitiesTime = TimeSnapshot.DoCheckPoint();

            //属性同步
            if (0 == m_LastTickTimeForTickPerSecond)
            {
                m_LastTickTimeForTickPerSecond = TimeUtility.GetLocalMilliseconds();
                TickProperty();
            }
            else
            {
                long curTime = TimeUtility.GetLocalMilliseconds();
                if (curTime > m_LastTickTimeForTickPerSecond + c_IntervalPerSecond)
                {
                    m_LastTickTimeForTickPerSecond = curTime;
                    TickProperty();
                }
            }

            if (0 == m_LastTickTimeForTickPer5s)
            {
                m_LastTickTimeForTickPer5s = TimeUtility.GetLocalMilliseconds();
                ReloadObjects();
            }
            else
            {
                long curTime = TimeUtility.GetLocalMilliseconds();
                if (curTime > m_LastTickTimeForTickPer5s + c_IntervalPer5s)
                {
                    m_LastTickTimeForTickPer5s = curTime;
                    ReloadObjects();
                }
            }

            m_SceneProfiler.TickAttrRecoverTime = TimeSnapshot.DoCheckPoint();
            //空间信息调试
            TickDebugSpaceInfo();
            m_SceneProfiler.TickDebugSpaceInfoTime = TimeSnapshot.DoCheckPoint();
        }
예제 #42
0
        private void TickEntities()
        {
            m_DeletedEntities.Clear();
            for (LinkedListNode <EntityInfo> linkNode = m_EntityMgr.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                EntityInfo info = linkNode.Value;
                info.RetireAttackerInfos(60000);
                if (info.LevelChanged || info.GetSkillStateInfo().BuffChanged)
                {
                    AttrCalculator.Calc(info);
                    info.LevelChanged = false;
                    info.GetSkillStateInfo().BuffChanged = false;
                }
                if (info.IsBorning)
                {
                    if (info.BornTime <= 0)
                    {
                        SkillInfo skillInfo = info.GetSkillStateInfo().GetSkillInfoById(info.BornSkillId);
                        if (info.BornSkillId > 0 && null != skillInfo)
                        {
                            info.BornTime = TimeUtility.GetLocalMilliseconds();
                        }
                        else
                        {
                            info.IsBorning = false;
                            info.BornTime  = 0;
                            info.SetAIEnable(true);
                            info.RemoveState(CharacterPropertyEnum.x3009_无敌);
                        }
                    }
                    else if (info.BornTime + info.BornTimeout < TimeUtility.GetLocalMilliseconds())
                    {
                        info.IsBorning = false;
                        info.BornTime  = 0;
                        info.SetAIEnable(true);
                        info.RemoveState(CharacterPropertyEnum.x3009_无敌);
                    }
                }
                if (info.IsDead() && !info.NeedDelete)
                {
                    if (info.DeadTime <= 0)
                    {
                        CalcKillIncome(info);
                        //发送npc死亡消息
                        Msg_RC_NpcDead npcDeadBuilder = new Msg_RC_NpcDead();
                        npcDeadBuilder.npc_id = info.GetId();
                        NotifyAllUser(RoomMessageDefine.Msg_RC_NpcDead, npcDeadBuilder);

                        SkillInfo skillInfo = info.GetSkillStateInfo().GetSkillInfoById(info.DeadSkillId);
                        if (info.DeadSkillId > 0 && null != skillInfo)
                        {
                            info.DeadTime = TimeUtility.GetLocalMilliseconds();
                            OnEntityKilled(info);
                        }
                        else
                        {
                            if (null == info.CustomData as User)
                            {
                                info.DeadTime   = 0;
                                info.NeedDelete = true;
                                OnEntityKilled(info);
                            }
                            else
                            {
                                info.DeadTime = TimeUtility.GetLocalMilliseconds();
                            }
                        }
                    }
                    else
                    {
                        if (null == info.CustomData as User && info.DeadTime + info.DeadTimeout < TimeUtility.GetLocalMilliseconds())
                        {
                            info.DeadTime   = 0;
                            info.NeedDelete = true;

                            //重新发送npc死亡消息
                            Msg_RC_NpcDead npcDeadBuilder = new Msg_RC_NpcDead();
                            npcDeadBuilder.npc_id = info.GetId();
                            NotifyAllUser(RoomMessageDefine.Msg_RC_NpcDead, npcDeadBuilder);
                        }
                        else if (null != info.CustomData as User && info.DeadTime + info.ReliveTimeout < TimeUtility.GetLocalMilliseconds())
                        {
                            info.DeadTime = 0;
                            info.Hp       = info.HpMax;
                            info.Energy   = info.EnergyMax;

                            Msg_RC_SyncProperty npcProp = DataSyncUtility.BuildSyncPropertyMessage(info);
                            NotifyAllUser(RoomMessageDefine.Msg_RC_SyncProperty, npcProp);
                        }
                    }
                }
                if (info.NeedDelete)
                {
                    m_DeletedEntities.Add(info);
                }
            }
            if (m_DeletedEntities.Count > 0)
            {
                int enemyCt  = 0;
                int friendCt = 0;
                Msg_RC_DestroyNpc destroyNpcBuilder = new Msg_RC_DestroyNpc();
                for (int i = 0; i < m_DeletedEntities.Count; ++i)
                {
                    EntityInfo ni = m_DeletedEntities[i];
                    if (CharacterRelation.RELATION_ENEMY == EntityInfo.GetRelation((int)CampIdEnum.Blue, ni.GetCampId()))
                    {
                        ++enemyCt;
                    }
                    else if (CharacterRelation.RELATION_FRIEND == EntityInfo.GetRelation((int)CampIdEnum.Blue, ni.GetCampId()))
                    {
                        ++friendCt;
                    }
                    //发送npc消失消息
                    destroyNpcBuilder.npc_id = ni.GetId();
                    NotifyAllUser(RoomMessageDefine.Msg_RC_DestroyNpc, destroyNpcBuilder);
                    DestroyEntity(ni);
                }
                TryAllKilledOrAllDied(enemyCt > 0, friendCt > 0);
            }
            m_EntityMgr.ExecuteDelayAdd();
        }
예제 #43
0
        internal EntityInfo GetGameObject(int objId)
        {
            EntityInfo obj = m_Scene.EntityManager.GetEntityInfo(objId);

            return(obj);
        }
예제 #44
0
        internal void ImpactDamage(int srcObjId, int targetId, int impactId, int seq)
        {
            EntityInfo targetObj = m_Scene.EntityManager.GetEntityInfo(targetId);
            EntityInfo srcObj    = m_Scene.EntityManager.GetEntityInfo(srcObjId);

            if (null != targetObj && !targetObj.IsDead())
            {
                ImpactInfo impactInfo = targetObj.GetSkillStateInfo().GetImpactInfoBySeq(seq);
                if (null != impactInfo && impactId == impactInfo.ImpactId)
                {
                    TableConfig.Skill cfg = impactInfo.ConfigData;
                    int   targetType      = impactInfo.TargetType;
                    float damage          = impactInfo.DamageData.Damage;
                    int   addShield       = impactInfo.DamageData.AddShield;
                    int   hpRecover       = impactInfo.DamageData.HpRecover;

                    if (hpRecover != 0)
                    {
                        targetObj.SetHp(Operate_Type.OT_Relative, (int)impactInfo.DamageData.HpRecover);
                        targetObj.SetAttackerInfo(srcObjId, false, true, false, -impactInfo.DamageData.HpRecover, 0);
                    }
                    if (addShield != 0)
                    {
                        targetObj.SetShield(Operate_Type.OT_Relative, impactInfo.DamageData.AddShield);
                    }
                    if ((targetType == (int)SkillTargetType.Enemy || targetType == (int)SkillTargetType.RandEnemy) && damage != 0)
                    {
                        if (targetObj.EntityType == (int)EntityTypeEnum.Tower)
                        {
                            if (null != srcObj && srcObj.NormalSkillId != impactInfo.SkillId)
                            {
                                //技能打塔不产生伤害
                                return;
                            }
                        }
                        bool isKiller = false;
                        if (targetObj.Shield >= damage)
                        {
                            targetObj.SetShield(Operate_Type.OT_Relative, -(int)damage);
                        }
                        else if (targetObj.Shield > 0)
                        {
                            int leftDamage = (int)damage - targetObj.Shield;
                            targetObj.SetShield(Operate_Type.OT_Absolute, 0);
                            targetObj.SetHp(Operate_Type.OT_Relative, -(int)leftDamage);
                            if (targetObj.Hp <= 0)
                            {
                                isKiller = true;
                            }
                        }
                        else
                        {
                            targetObj.SetHp(Operate_Type.OT_Relative, -(int)damage);
                            if (targetObj.Hp <= 0)
                            {
                                isKiller = true;
                            }
                        }
                        if (isKiller)
                        {
                            targetObj.GetCombatStatisticInfo().AddDeadCount(1);
                            if (null != srcObj)
                            {
                                EntityInfo killer = srcObj;
                                if (killer.SummonerId > 0)
                                {
                                    killer = m_Scene.EntityManager.GetEntityInfo(killer.SummonerId);
                                }
                                if (targetObj.EntityType == (int)EntityTypeEnum.Tower)
                                {
                                    killer.GetCombatStatisticInfo().AddKillTowerCount(1);
                                }
                                else if (targetObj.EntityType == (int)EntityTypeEnum.Hero)
                                {
                                    killer.GetCombatStatisticInfo().AddKillHeroCount(1);
                                    killer.GetCombatStatisticInfo().AddMultiKillCount(1);
                                }
                                else
                                {
                                    killer.GetCombatStatisticInfo().AddKillNpcCount(1);
                                }
                            }
                        }
                        targetObj.SetAttackerInfo(srcObjId, isKiller, true, false, (int)damage, 0);
                    }
                }
            }
        }
예제 #45
0
        public void ImpactDamage(int srcObjId, int targetId, int impactId, int seq, bool isFinal)
        {
            if (!PluginFramework.Instance.IsBattleState)
            {
                return;
            }
            EntityViewModel view    = GetEntityViewById(targetId);
            EntityViewModel srcView = GetEntityViewById(srcObjId);

            if (null != view && null != view.Entity && null != view.Actor)
            {
                EntityInfo targetObj = view.Entity;
                EntityInfo srcObj    = null;
                if (null != srcView && null != srcView.Entity)
                {
                    srcObj = srcView.Entity;
                }
                if (null != targetObj && !view.Entity.IsDeadSkillCasting())
                {
                    ImpactInfo impactInfo = targetObj.GetSkillStateInfo().GetImpactInfoBySeq(seq);
                    if (null != impactInfo && impactId == impactInfo.ImpactId)
                    {
                        EntityInfo ownerObj = GetRootSummoner(srcObj);
                        int        ownerId  = 0;
                        if (null != ownerObj)
                        {
                            ownerId = ownerObj.GetId();
                        }
                        int addsc = impactInfo.DamageData.AddSc;
                        int adduc = impactInfo.DamageData.AddUc;

                        int index = impactInfo.CurDamageCount;
                        ++impactInfo.CurDamageCount;
                        int  multiple  = impactInfo.DamageData.GetMultiple(index);
                        int  damage    = impactInfo.DamageData.GetDamage(index);
                        long hitrate   = 0;
                        long critrate  = 0;
                        long blockrate = 0;
                        long phyDamage = 0;
                        long magDamage = 0;

                        hitrate   = AttrCalculator.Calc(targetObj.SceneContext, impactInfo.SenderProperty, targetObj.ActualProperty, "hitrate");
                        critrate  = AttrCalculator.Calc(targetObj.SceneContext, impactInfo.SenderProperty, targetObj.ActualProperty, "critrate");
                        blockrate = AttrCalculator.Calc(targetObj.SceneContext, impactInfo.SenderProperty, targetObj.ActualProperty, "blockrate");
                        long rnd        = Helper.Random.Next();
                        long critonoff  = 0;
                        long blockonoff = 0;
                        if (rnd <= critrate)
                        {
                            critonoff = 1;
                        }
                        else if (rnd > critrate && rnd <= critrate + blockrate)
                        {
                            blockonoff = 1;
                        }
                        impactInfo.DamageData.IsCritical = critonoff > 0;
                        impactInfo.DamageData.IsBlock    = blockonoff > 0;
                        phyDamage = AttrCalculator.Calc(targetObj.SceneContext, impactInfo.SenderProperty, targetObj.ActualProperty, "phydamage", multiple, damage, critonoff, blockonoff);
                        magDamage = AttrCalculator.Calc(targetObj.SceneContext, impactInfo.SenderProperty, targetObj.ActualProperty, "magdamage", multiple, damage, critonoff, blockonoff);

                        damage = (int)(phyDamage + magDamage);
                        if (damage < 0)
                        {
                            damage = 0;
                        }
                        int  vampire  = impactInfo.DamageData.GetVampire(index);
                        bool isKiller = false;
                        if (targetObj.Shield >= damage)
                        {
                            targetObj.Shield -= (int)damage;
                        }
                        else if (targetObj.Shield > 0)
                        {
                            int leftDamage = (int)damage - targetObj.Shield;
                            targetObj.Shield = 0;
                            targetObj.Hp    -= (int)leftDamage;
                            if (targetObj.Hp <= 0)
                            {
                                isKiller = true;
                            }
                        }
                        else
                        {
                            targetObj.Hp -= (int)damage;
                            if (targetObj.Hp <= 0)
                            {
                                isKiller = true;
                            }
                        }
                        if (isKiller)
                        {
                            targetObj.GetCombatStatisticInfo().AddDeadCount(1);
                            if (null != srcObj)
                            {
                                EntityInfo killer = srcObj;
                                if (killer.SummonerId > 0)
                                {
                                    EntityViewModel npcViewModel = GetEntityViewById(killer.SummonerId);
                                    if (null != npcViewModel)
                                    {
                                        killer = npcViewModel.Entity;
                                    }
                                }
                                if (targetObj.EntityType == (int)EntityTypeEnum.Tower)
                                {
                                    killer.GetCombatStatisticInfo().AddKillTowerCount(1);
                                }
                                else if (targetObj.EntityType == (int)EntityTypeEnum.Hero)
                                {
                                    killer.GetCombatStatisticInfo().AddKillHeroCount(1);
                                    killer.GetCombatStatisticInfo().AddMultiKillCount(1);
                                }
                                else
                                {
                                    killer.GetCombatStatisticInfo().AddKillNpcCount(1);
                                }
                            }
                        }
                        targetObj.SetAttackerInfo(srcObjId, isKiller, true, false, (int)damage, 0);
                    }
                }
            }
        }
예제 #46
0
        private void HandleChangeScene(Msg_LR_ChangeScene msg, PBChannel channel, int handle, uint seq)
        {
            ulong guid         = msg.UserGuid;
            int   roomid       = msg.RoomId;
            int   targetRoomId = msg.TargetRoomId;
            bool  isFieldThread;
            int   ix = GetActiveRoomThreadIndex(msg.RoomId, out isFieldThread);

            if (ix < 0)
            {
                Msg_RL_ChangeSceneResult replyBuilder = new Msg_RL_ChangeSceneResult();
                replyBuilder.UserGuid     = msg.UserGuid;
                replyBuilder.RoomId       = msg.RoomId;
                replyBuilder.TargetRoomId = msg.TargetRoomId;
                replyBuilder.Result       = (int)SceneOperationResultEnum.Cant_Find_Room;
                channel.Send(replyBuilder);
            }
            else
            {
                RoomThread roomThread;
                if (isFieldThread)
                {
                    roomThread = m_FieldRoomthreadList[ix];
                }
                else
                {
                    roomThread = m_RoomThreadList[ix];
                }
                bool targetIsFieldThread;
                int  targetIx = GetActiveRoomThreadIndex(targetRoomId, out targetIsFieldThread);
                if (null != roomThread)
                {
                    if (targetIx >= 0)
                    {
                        //同服切场景
                        roomThread.QueueAction(roomThread.RemoveUser, guid, roomid, false, (MyAction <bool, int, User>)((bool success, int sceneId, User user) => {
                            if (success)
                            {
                                PlayerGotoRoom(user, roomid, targetRoomId);
                            }
                            else
                            {
                                Msg_RL_ChangeSceneResult replyBuilder = new Msg_RL_ChangeSceneResult();
                                replyBuilder.UserGuid     = guid;
                                replyBuilder.RoomId       = roomid;
                                replyBuilder.TargetRoomId = targetRoomId;
                                replyBuilder.Result       = (int)SceneOperationResultEnum.Cant_Find_Room;
                                channel.Send(replyBuilder);
                            }
                        }));
                    }
                    else
                    {
                        //跨服切场景
                        roomThread.QueueAction(roomThread.RemoveUser, guid, roomid, true, (MyAction <bool, int, User>)((bool success, int sceneId, User user) => {
                            if (success)
                            {
                                Msg_RL_ChangeSceneResult replyBuilder = new Msg_RL_ChangeSceneResult();
                                EntityInfo info = user.Info;
                                if (null != info)
                                {
                                    replyBuilder.HP = info.Hp;
                                    replyBuilder.MP = info.Energy;
                                }
                                replyBuilder.UserGuid     = guid;
                                replyBuilder.RoomId       = roomid;
                                replyBuilder.TargetRoomId = targetRoomId;
                                replyBuilder.Result       = (int)SceneOperationResultEnum.Success;
                                channel.Send(replyBuilder);
                            }
                            else
                            {
                                Msg_RL_ChangeSceneResult replyBuilder = new Msg_RL_ChangeSceneResult();
                                replyBuilder.UserGuid     = guid;
                                replyBuilder.RoomId       = roomid;
                                replyBuilder.TargetRoomId = targetRoomId;
                                replyBuilder.Result       = (int)SceneOperationResultEnum.Cant_Find_Room;
                                channel.Send(replyBuilder);
                            }
                        }));
                    }
                }
            }
        }
예제 #47
0
        public ImpactInfo SendImpact(TableConfig.Skill cfg, int seq, int curObjId, int srcObjId, int targetId, int impactId, bool isFinal, Dictionary <string, object> args)
        {
            EntityViewModel view = GetEntityViewById(targetId);

            if (null != view && null != view.Entity && null != view.Actor && !view.Entity.IsDeadSkillCasting())
            {
                EntityInfo npc = view.Entity;
                if (null != cfg)
                {
                    UnityEngine.Quaternion hitEffectRotation = UnityEngine.Quaternion.identity;
                    UnityEngine.GameObject srcObj            = GetGameObject(srcObjId);
                    UnityEngine.GameObject targetObj         = view.Actor;
                    if (null != srcObj && null != targetObj)
                    {
                        hitEffectRotation = srcObj.transform.localRotation;
                    }
                    var addArgs = new Dictionary <string, object> {
                        { "hitEffectRotation", hitEffectRotation }
                    };
                    ImpactInfo impactInfo = null;
                    if (impactId <= 0 || impactId >= SkillInstance.c_FirstInnerHitSkillId)
                    {
                        impactInfo = new ImpactInfo(PredefinedSkill.Instance.HitSkillCfg);
                        impactId   = PredefinedSkill.c_HitSkillId;
                    }
                    else
                    {
                        impactInfo = new ImpactInfo(impactId);
                    }
                    if (null != impactInfo.ConfigData)
                    {
                        if (TryInitImpactInfo(impactInfo, cfg, seq, curObjId, srcObjId, args))
                        {
                            if (impactInfo.ConfigData.type == (int)SkillOrImpactType.Buff)
                            {
                                ImpactInfo oldImpactInfo = npc.GetSkillStateInfo().FindImpactInfoById(impactInfo.ImpactId);
                                if (null != oldImpactInfo)
                                {
                                    oldImpactInfo.DurationTime += impactInfo.DurationTime;
                                    return(oldImpactInfo);
                                }
                            }
                            impactInfo.DamageData.IsFinal = isFinal;
                            npc.GetSkillStateInfo().AddImpact(impactInfo);
                            SkillInfo skillInfo = npc.GetSkillStateInfo().GetCurSkillInfo();
                            if (null != skillInfo && cfg.skillData.isInterrupt)
                            {
                                GfxSkillSystem.Instance.StopSkill(targetId, skillInfo.SkillId, 0, true);
                            }
                            GfxSkillSystem.Instance.StartSkill(targetId, impactInfo.ConfigData, impactInfo.Seq, args, addArgs);
                            return(impactInfo);
                        }
                    }
                    else
                    {
                        LogSystem.Error("impact {0} config can't found !", impactInfo.ImpactId);
                    }
                }
            }
            return(null);
        }
        private void CombatHandler(EntityInfo npc, long deltaTime)
        {
            AiStateInfo   aiInfo = npc.GetAiStateInfo();
            AiData_Leader aiData = GetAiData(npc);

            if (npc.GetSkillStateInfo().IsSkillActivated())
            {
                return;
            }
            ///
            SkillStateInfo currSkInfo = npc.GetSkillStateInfo();
            ///找到可以使用的技能
            SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc, this.GetAiData(npc), aiData.IsAutoOperate);

            NotifyAiSelectSkill(npc, skInfo);
            if (skInfo == null)
            {
                //没有可以使用的技能就切换到Idle状态
                ChangeToState(npc, (int)AiStateId.Idle);
                return;
            }

            CharacterRelation relation =
                (skInfo.TargetType == SkillTargetType.Friend ||
                 skInfo.TargetType == SkillTargetType.RandFriend) ?
                CharacterRelation.RELATION_FRIEND :
                CharacterRelation.RELATION_ENEMY;
            EntityInfo attackTarget = AiLogicUtility.GetNearstAttackerHelper(npc, relation, aiData);

            if (null != attackTarget)
            {
                NotifyAiTarget(npc, attackTarget);
                if (Geometry.DistanceSquare(npc.GetMovementStateInfo().GetPosition3D(), attackTarget.GetMovementStateInfo().GetPosition3D()) < skInfo.Distance * skInfo.Distance)
                {
                    aiInfo.Target = attackTarget.GetId();
                    NotifyAiStopPursue(npc);
                    NotifyAiSkill(npc, skInfo.SkillId);
                    return;
                }
            }
            attackTarget = AiLogicUtility.GetNearstTargetHelper(npc, skInfo.Distance, relation);
            if (attackTarget != null && null != skInfo)   //攻击范围内找到可攻击目标
            {
                NotifyAiTarget(npc, attackTarget);
                aiInfo.Target = attackTarget.GetId();
                NotifyAiStopPursue(npc);
                NotifyAiSkill(npc, skInfo.SkillId); //攻击目标
                return;
            }
            if (aiData.IsAutoOperate)
            {
                attackTarget = AiLogicUtility.GetNearstTargetHelper(npc, npc.ViewRange, relation);
                if (attackTarget != null && null != skInfo)   //视野内找到可攻击目标
                {
                    NotifyAiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D());
                    return;
                }
            }

            ///退出战斗模式清理一下手动技能
            currSkInfo.SetCurSkillInfo(0);
            aiData.ManualSkillId = 0;
            NotifyAiStopPursue(npc);
            ChangeToState(npc, (int)AiStateId.Idle);
        }