GetRelation() public static method

public static GetRelation ( EntityInfo pObj_A, EntityInfo pObj_B ) : CharacterRelation
pObj_A EntityInfo
pObj_B EntityInfo
return CharacterRelation
        public bool SkillCanFindTarget(int objId, int skillId)
        {
            bool       ret = false;
            EntityInfo obj = GetEntityById(objId);

            if (null != obj)
            {
                SkillInfo skillInfo = obj.GetSkillStateInfo().GetSkillInfoById(skillId);
                if (null != skillInfo)
                {
                    bool find = false;
                    KdTree.QueryWithFunc(obj, skillInfo.Distance, (float distSqr, KdTreeObject _obj) => {
                        EntityInfo target = _obj.Object;
                        if (CharacterRelation.RELATION_ENEMY == EntityInfo.GetRelation(obj, target) && !target.IsDead())
                        {
                            find = true;
                            return(false);
                        }
                        return(true);
                    });
                    ret = find;
                }
            }
            return(ret);
        }
示例#2
0
        public int GetRandFriendId(int campId, HashSet <int> history)
        {
            int        id  = 0;
            List <int> ids = new List <int>();

            for (LinkedListNode <EntityInfo> linkNode = PluginFramework.Instance.EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                EntityInfo info = linkNode.Value;
                if (EntityInfo.GetRelation(campId, info.GetCampId()) == CharacterRelation.RELATION_FRIEND && info.EntityType != (int)EntityTypeEnum.Tower)
                {
                    ids.Add(info.GetId());
                }
            }
            for (int ct = 0; ct < ids.Count; ++ct)
            {
                int index = Helper.Random.Next(ids.Count);
                if (index >= 0 && index < ids.Count)
                {
                    int _id = ids[index];
                    if (!history.Contains(id))
                    {
                        id = _id;
                        break;
                    }
                }
            }
            return(id);
        }
示例#3
0
        public int SelectTargetForSkill(string type, int actorId, TableConfig.Skill cfg, int seq, HashSet <int> history)
        {
            if (string.IsNullOrEmpty(type))
            {
                return(0);
            }
            EntityViewModel view = GetEntityViewById(actorId);

            if (null != view && null != view.Entity)
            {
                EntityInfo entity = view.Entity;
                int        campId = entity.GetCampId();
                if (type.CompareTo("minhp") == 0)
                {
                    int   targetId            = 0;
                    float minhp               = float.MaxValue;
                    ScriptRuntime.Vector3 pos = entity.GetMovementStateInfo().GetPosition3D();
                    PluginFramework.Instance.KdTree.QueryWithAction(pos, cfg.skillData.distance, (float distSqr, KdTreeObject kdObj) => {
                        if (minhp > kdObj.Object.Hp && EntityInfo.GetRelation(campId, kdObj.Object.GetCampId()) == CharacterRelation.RELATION_ENEMY)
                        {
                            int objId = kdObj.Object.GetId();
                            if (!history.Contains(objId))
                            {
                                minhp    = kdObj.Object.Hp;
                                targetId = objId;
                            }
                        }
                    });
                    return(targetId);
                }
                else if (type.CompareTo("maxdist") == 0)
                {
                    int   targetId            = 0;
                    float maxDistSqr          = 0;
                    ScriptRuntime.Vector3 pos = entity.GetMovementStateInfo().GetPosition3D();
                    PluginFramework.Instance.KdTree.QueryWithAction(pos, cfg.skillData.distance, (float distSqr, KdTreeObject kdObj) => {
                        if (maxDistSqr < distSqr && EntityInfo.GetRelation(campId, kdObj.Object.GetCampId()) == CharacterRelation.RELATION_ENEMY)
                        {
                            int objId = kdObj.Object.GetId();
                            if (!history.Contains(objId))
                            {
                                maxDistSqr = distSqr;
                                targetId   = objId;
                            }
                        }
                    });
                    return(targetId);
                }
                else if (type.CompareTo("randenemy") == 0)
                {
                    return(GetRandEnemyId(campId, history));
                }
                else if (type.CompareTo("randfriend") == 0)
                {
                    return(GetRandFriendId(campId, history));
                }
            }
            return(0);
        }
示例#4
0
        internal int SelectTargetForSkill(string type, int objId, TableConfig.Skill cfg, int seq, HashSet <int> history)
        {
            if (string.IsNullOrEmpty(type))
            {
                return(0);
            }
            EntityInfo entity = m_Scene.EntityManager.GetEntityInfo(objId);

            if (null != entity)
            {
                int campId = entity.GetCampId();
                if (type.CompareTo("minhp") == 0)
                {
                    int   targetId            = 0;
                    float minhp               = float.MaxValue;
                    ScriptRuntime.Vector3 pos = entity.GetMovementStateInfo().GetPosition3D();
                    m_Scene.KdTree.Query(pos, cfg.distance, (float distSqr, KdTreeObject kdObj) => {
                        if (minhp > kdObj.Object.Hp && EntityInfo.GetRelation(campId, kdObj.Object.GetCampId()) == CharacterRelation.RELATION_ENEMY)
                        {
                            int id = kdObj.Object.GetId();
                            if (!history.Contains(id))
                            {
                                minhp    = kdObj.Object.Hp;
                                targetId = id;
                            }
                        }
                    });
                    return(targetId);
                }
                else if (type.CompareTo("maxdist") == 0)
                {
                    int   targetId            = 0;
                    float maxDistSqr          = 0;
                    ScriptRuntime.Vector3 pos = entity.GetMovementStateInfo().GetPosition3D();
                    m_Scene.KdTree.Query(pos, cfg.distance, (float distSqr, KdTreeObject kdObj) => {
                        if (maxDistSqr < distSqr && EntityInfo.GetRelation(campId, kdObj.Object.GetCampId()) == CharacterRelation.RELATION_ENEMY)
                        {
                            int id = kdObj.Object.GetId();
                            if (!history.Contains(id))
                            {
                                maxDistSqr = distSqr;
                                targetId   = id;
                            }
                        }
                    });
                    return(targetId);
                }
                else if (type.CompareTo("randenemy") == 0)
                {
                    return(GetRandEnemyId(campId, history));
                }
                else if (type.CompareTo("randfriend") == 0)
                {
                    return(GetRandFriendId(campId, history));
                }
            }
            return(0);
        }
示例#5
0
        private void OnCreateEntity(EntityInfo entity)
        {
            if (null != entity)
            {
                GfxStorySystem.Instance.SendMessage("obj_created", entity.GetId());
                GfxStorySystem.Instance.SendMessage(string.Format("npc_created:{0}", entity.GetUnitId()), entity.GetId());

                bool isGreen = CharacterRelation.RELATION_FRIEND == EntityInfo.GetRelation(entity.GetCampId(), CampId);
                Utility.EventSystem.Publish("ui_add_actor", "ui", entity.GetId(), isGreen, entity.ConfigData);
            }
        }
示例#6
0
 public CharacterRelation GetRelation(EntityInfo one, EntityInfo other)
 {
     if (null == one || null == other)
     {
         return(CharacterRelation.RELATION_INVALID);
     }
     else
     {
         return(EntityInfo.GetRelation(one, other));
     }
 }
示例#7
0
        public CharacterRelation GetRelation(int one, int other)
        {
            EntityInfo entity1 = m_Scene.EntityManager.GetEntityInfo(one);
            EntityInfo entity2 = m_Scene.EntityManager.GetEntityInfo(other);

            if (null == entity1 || null == entity2)
            {
                return(CharacterRelation.RELATION_INVALID);
            }
            else
            {
                return(EntityInfo.GetRelation(entity1, entity2));
            }
        }
示例#8
0
        public CharacterRelation GetRelation(int one, int other)
        {
            EntityViewModel view1 = GetEntityViewById(one);
            EntityViewModel view2 = GetEntityViewById(other);

            if (null == view1 || null == view1.Entity || null == view2 || null == view2.Entity)
            {
                return(CharacterRelation.RELATION_INVALID);
            }
            else
            {
                return(EntityInfo.GetRelation(view1.Entity, view2.Entity));
            }
        }
示例#9
0
        public CharacterRelation GetRelation(UnityEngine.GameObject one, UnityEngine.GameObject other)
        {
            EntityViewModel view1 = GetEntityView(one);
            EntityViewModel view2 = GetEntityView(other);

            if (null == view1 || null == view1.Entity || null == view2 || null == view2.Entity)
            {
                return(CharacterRelation.RELATION_INVALID);
            }
            else
            {
                return(EntityInfo.GetRelation(view1.Entity, view2.Entity));
            }
        }
示例#10
0
        public int GetBattleNpcCount(EntityInfo src, CharacterRelation relation)
        {
            int ct = 0;

            for (LinkedListNode <EntityInfo> linkNode = m_EntityMgr.Entities.FirstNode; null != linkNode; linkNode = linkNode.Next)
            {
                EntityInfo info = linkNode.Value;
                if (null != info && !info.IsDead() && info.IsCombatNpc() && EntityInfo.GetRelation(src, info) == relation)
                {
                    ++ct;
                }
            }
            return(ct);
        }
示例#11
0
        internal int GetBattleNpcCount(int campId, CharacterRelation relation)
        {
            int ct = 0;

            for (LinkedListNode <EntityInfo> linkNode = m_EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                EntityInfo info = linkNode.Value;
                if (null != info && !info.IsDead() && info.IsCombatNpc() && EntityInfo.GetRelation(campId, info.GetCampId()) == relation)
                {
                    ++ct;
                }
            }
            return(ct);
        }
        private bool HaveNpcInRange(EntityInfo entity, CharacterRelation relation, float radius)
        {
            bool find = false;

            KdTree.QueryWithFunc(entity, radius, (float sqrDist, KdTreeObject obj) => {
                if (EntityInfo.GetRelation(entity, obj.Object) == relation)
                {
                    find = true;
                    return(false);
                }
                return(true);
            });
            return(find);
        }
示例#13
0
        public int GetRandEnemyId(int campId)
        {
            int        id  = 0;
            List <int> ids = new List <int>();

            for (LinkedListNode <EntityInfo> linkNode = PluginFramework.Instance.EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                EntityInfo info = linkNode.Value;
                if (EntityInfo.GetRelation(campId, info.GetCampId()) == CharacterRelation.RELATION_ENEMY && info.EntityType != (int)EntityTypeEnum.Tower)
                {
                    ids.Add(info.GetId());
                }
            }
            int index = Helper.Random.Next(ids.Count);

            if (index >= 0 && index < ids.Count)
            {
                id = ids[index];
            }
            return(id);
        }
示例#14
0
        internal int GetRandFriendId(int campId)
        {
            int        id  = 0;
            List <int> ids = new List <int>();

            for (LinkedListNode <EntityInfo> linkNode = m_Scene.EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                EntityInfo info = linkNode.Value;
                if (EntityInfo.GetRelation(campId, info.GetCampId()) == CharacterRelation.RELATION_FRIEND && info.EntityType != (int)EntityTypeEnum.Tower)
                {
                    ids.Add(info.GetId());
                }
            }
            int index = Helper.Random.Next(ids.Count);

            if (index >= 0 && index < ids.Count)
            {
                id = ids[index];
            }
            return(id);
        }
        private static void StepCalcNearstTarget(EntityInfo srcObj, CharacterRelation relation, AiTargetType type, float powDist, EntityInfo obj, ref float minPowDist, ref EntityInfo nearstTarget)
        {
            EntityInfo target = GetSeeingLivingCharacterInfoHelper(srcObj, obj.GetId());

            if (null != target && !target.IsDead())
            {
                if (!target.IsTargetNpc())
                {
                    return;
                }
                if (type == AiTargetType.HERO && target.EntityType != (int)EntityTypeEnum.Hero)
                {
                    return;
                }
                if (type == AiTargetType.TOWER && target.EntityType != (int)EntityTypeEnum.Tower)
                {
                    return;
                }
                if (type == AiTargetType.BOSS && target.EntityType != (int)EntityTypeEnum.Boss)
                {
                    return;
                }
                if (type == AiTargetType.NPC && target.EntityType != (int)EntityTypeEnum.Normal)
                {
                    return;
                }
                if (relation == EntityInfo.GetRelation(srcObj, target))
                {
                    if (powDist < minPowDist)
                    {
                        if (powDist > c_MaxViewRangeSqr || CanSee(srcObj, target))
                        {
                            nearstTarget = target;
                            minPowDist   = powDist;
                        }
                    }
                }
            }
        }
示例#16
0
        private void TickEntities()
        {
            m_DeletedEntities.Clear();
            for (LinkedListNode <EntityInfo> linkNode = m_EntityMgr.Entities.FirstNode; 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();
        }
示例#17
0
 private void TickEntities()
 {
     m_DeletedEntities.Clear();
     for (LinkedListNode <EntityInfo> linkNode = m_EntityManager.Entities.FirstValue; null != linkNode; linkNode = linkNode.Next)
     {
         EntityInfo info = linkNode.Value;
         info.RetireAttackerInfos(10000);
         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();
                     GfxSkillSystem.Instance.StartSkill(info.GetId(), skillInfo.ConfigData, 0);
                 }
                 else
                 {
                     info.IsBorning = false;
                     info.BornTime  = 0;
                     info.SetAIEnable(true);
                     info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible);
                 }
             }
             else if (info.BornTime + info.BornTimeout < TimeUtility.GetLocalMilliseconds())
             {
                 info.IsBorning = false;
                 info.BornTime  = 0;
                 info.SetAIEnable(true);
                 info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible);
             }
         }
         if (info.IsDead() && !info.NeedDelete)
         {
             if (info.CanDead)
             {
                 if (info.DeadTime <= 0)
                 {
                     SkillInfo skillInfo = info.GetSkillStateInfo().GetSkillInfoById(info.DeadSkillId);
                     if (info.DeadSkillId > 0 && null != skillInfo)
                     {
                         info.DeadTime = TimeUtility.GetLocalMilliseconds();
                         GfxSkillSystem.Instance.StopAllSkill(info.GetId(), true, false, true);
                         GfxSkillSystem.Instance.StartSkill(info.GetId(), skillInfo.ConfigData, 0);
                         OnEntityKilled(info);
                         EntityDrop(info); // 掉落
                     }
                     else
                     {
                         info.DeadTime   = 0;
                         info.NeedDelete = true;
                         OnEntityKilled(info);
                         EntityDrop(info); // 掉落
                     }
                 }
                 else if (info.DeadTime + info.DeadTimeout < TimeUtility.GetLocalMilliseconds())
                 {
                     info.DeadTime   = 0;
                     info.NeedDelete = true;
                 }
             }
             else
             {
                 info.CanDead = true;
             }
         }
         else
         {
             //每个tick复位CanDead,技能里需要鞭尸时应使用触发器每帧标记目标不可死亡(keeplive)
             info.CanDead = true;
         }
         if (info.NeedDelete)
         {
             m_DeletedEntities.Add(info);
         }
     }
     if (m_DeletedEntities.Count > 0)
     {
         int enemyCt  = 0;
         int friendCt = 0;
         for (int i = 0; i < m_DeletedEntities.Count; ++i)
         {
             EntityInfo ni = m_DeletedEntities[i];
             if (CharacterRelation.RELATION_ENEMY == EntityInfo.GetRelation(CampId, ni.GetCampId()))
             {
                 ++enemyCt;
             }
             else if (CharacterRelation.RELATION_FRIEND == EntityInfo.GetRelation(CampId, ni.GetCampId()))
             {
                 ++friendCt;
             }
             DestroyEntity(ni);
         }
         TryAllKilledOrAllDied(enemyCt > 0, friendCt > 0);
     }
 }