Пример #1
0
        //获得与此节点链接的相关节点
        public HashList <GraphNode> GetConnections(GraphNode node)
        {
            HashList <GraphNode> ret = new HashList <GraphNode>();

            node.GetConnections(ret.Add);
            return(ret);
        }
Пример #2
0
        public HashList <BaseUnit> GetBlockerUnits(BaseUnit unit, bool isContainSelf = true)
        {
            if (unit == null)
            {
                return(null);
            }
            var selfNode            = unit.AStarMoveMgr.CurNode;
            var allBlockers         = GetBlocker(unit);
            HashList <BaseUnit> ret = new HashList <BaseUnit>();

            foreach (var item in allBlockers)
            {
                var units = GetBlockerUnits(item);
                if (units != null)
                {
                    foreach (var tempUnit in units)
                    {
                        if (!isContainSelf)
                        {
                            if (tempUnit != unit && tempUnit.AStarMoveMgr.CurNode != selfNode)
                            {
                                ret.Add(tempUnit);
                            }
                        }
                        else
                        {
                            ret.Add(tempUnit);
                        }
                    }
                }
            }
            return(ret);
        }
Пример #3
0
        public override void OnAllLoadEnd2()
        {
            base.OnAllLoadEnd2();
            //添加到全局属性表
            Type   type                = typeof(T);
            string enumName            = type.Name;
            List <TDBaseAttrData> data = new List <TDBaseAttrData>();
            Dictionary <string, TDBaseAttrData> dataDic = new Dictionary <string, TDBaseAttrData>();
            HashList <string> dataCategory = new HashList <string>();

            string[] names = Enum.GetNames(type);
            foreach (var item in names)
            {
                var val = Get(item);
                if (val == null || val.TDID.IsInv())
                {
                    CLog.Error("没有这个属性:{0}", item);
                    continue;
                }
                val.EnumName = enumName;
                data.Add(val);
                dataDic.Add(item, val);
                dataCategory.Add(val.Category);
            }
            AttrDataList.Add(type, data);
            AttrDataDic.Add(type, dataDic);
            AttrCategories.Add(type, dataCategory);
        }
Пример #4
0
 //创建谈判模板
 public void CreateNegotiationTemp(string id, HashList <string> selfExcludeArticle, HashList <string> targetExcludeArticle, params BaseDipPoint <TUnit, TWarData>[] ps)
 {
     if (NegotiationTemps.ContainsKey(id))
     {
         return;
     }
     NegotiationTemps.Add(id, new BaseNegotiationTemp <TUnit, TWarData>(selfExcludeArticle, targetExcludeArticle, ps));
 }
Пример #5
0
 public bool Contains(HashList<T> ent)
 {
     foreach (var item in ent)
     {
         if (Hash.Contains(item))
             return true;
     }
     return false;
 }
Пример #6
0
        void ParseTag(List <PartInfo> info, Dictionary <string, HashList <PartInfo> > sinfo)
        {
            foreach (var item2 in info)
            {
                //加入年龄Tag
                Enum <AgeRange> .For(x =>
                {
                    string tagAge = x.ToString();
                    HashList <PartInfo> temp;
                    if (sinfo.ContainsKey(tagAge))
                    {
                        temp = sinfo[tagAge];
                    }
                    else
                    {
                        temp = new HashList <PartInfo>();
                        sinfo.Add(tagAge, temp);
                    }
                    var addtionName = item2.Name + "_" + tagAge;
                    if (GRMgr.Head.IsHave(addtionName))
                    {
                        PartInfo newPartInfo = item2.Clone() as PartInfo;
                        newPartInfo.Name     = addtionName;
                        temp.Add(newPartInfo);
                    }
                });

                //加入自定义Tag
                if (item2.Tag == null)
                {
                    continue;
                }
                foreach (var tag in item2.Tag)
                {
                    HashList <PartInfo> temp;
                    if (sinfo.ContainsKey(tag))
                    {
                        temp = sinfo[tag];
                    }
                    else
                    {
                        temp = new HashList <PartInfo>();
                        sinfo.Add(tag, temp);
                    }
                    temp.Add(item2);

                    if (tag == Const.PTag_Rope)
                    {
                        Rope.Add(item2.Name);
                    }
                }
            }
            info.RemoveAll((x) =>
            {
                return(!x.IsIn);
            });
        }
Пример #7
0
 public BaseNegotiationTemp(HashList <string> selfExcludeArticle, HashList <string> targetExcludeArticle, params BaseDipPoint <TUnit, TWarData>[] ps)
 {
     SelfExcludeArticle   = selfExcludeArticle;
     TargetExcludeArticle = targetExcludeArticle;
     foreach (var item in ps)
     {
         DipPoints.Add(item);
     }
     DipPoints.Add(new DPArticle(1.0f));
 }
Пример #8
0
        public bool IsInConnection(BaseUnit target)
        {
            //如果没有链接,就返回
            HashList <GraphNode> blockers = AStarMgr.GetBlocker(SelfBaseUnit);

            if (!AStarMgr.IsConnection(blockers, target.AStarMoveMgr.CurNode))
            {
                return(false);
            }
            return(true);
        }
Пример #9
0
 public static T RandArray <T>(HashList <T> array)
 {
     if (array == null)
     {
         return(default(T));
     }
     if (array.Count <= 0)
     {
         return(default(T));
     }
     return(array[RangeArray(array.Count)]);
 }
Пример #10
0
 private HashList <PartInfo> GetPartInfo(string tag, HashList <PartInfo> pdata, Dictionary <string, HashList <PartInfo> > sdata)
 {
     if (tag == Const.PTag_Normal)
     {
         return(pdata);
     }
     if (sdata.ContainsKey(tag))
     {
         return(sdata[tag]);
     }
     return(pdata);
 }
Пример #11
0
        //获得与单位链接的一层Node
        public HashList <GraphNode> GetConnections(BaseUnit unit)
        {
            HashList <GraphNode> ret = new HashList <GraphNode>();
            var unitNode             = GetNode(unit);

            if (unitNode == null)
            {
                return(new HashList <GraphNode>());
            }
            unitNode.GetConnections(ret.Add);
            return(ret);
        }
Пример #12
0
        //获得所有与这些节点链接的节点
        public List <HashList <GraphNode> > GetAllConnections(HashList <GraphNode> nodes)
        {
            List <HashList <GraphNode> > ret = new List <HashList <GraphNode> >();

            if (nodes == null)
            {
                return(ret);
            }
            foreach (var item in nodes)
            {
                ret.Add(GetConnections(item));
            }
            return(ret);
        }
Пример #13
0
        public static List <long> GetUnitIDs(HashList <BaseUnit> entity)
        {
            List <long> ids = new List <long>();

            foreach (var item in entity)
            {
                if (item.IsInv())
                {
                    continue;
                }
                ids.Add(item.ID);
            }
            return(ids);
        }
Пример #14
0
        public static HashList <BaseUnit> GetUnit(List <long> ids)
        {
            HashList <BaseUnit> data = new HashList <BaseUnit>();

            foreach (var item in ids)
            {
                var entity = GetUnit(item);
                if (entity == null)
                {
                    continue;
                }
                data.Add(entity);
            }
            return(data);
        }
Пример #15
0
        // 设置阻挡得Node,输入Null表示清空
        public void SetBlockNode(BaseUnit unit, List <TNode> nodes)
        {
            if (unit == null)
            {
                return;
            }
            HashList <TNode> preNodes = null;

            if (BlockNodesUnit.ContainsKey(unit))
            {
                preNodes = BlockNodesUnit[unit];
            }

            //先清除之前残余得数据
            if (preNodes != null)
            {
                foreach (var item in preNodes)
                {
                    AllBlockers.Remove(item);
                    if (BlockNodes.ContainsKey(item))
                    {
                        BlockNodes[item].Remove(unit);
                    }
                    if (BlockNodes[item].Count == 0)
                    {
                        BlockNodes.Remove(item);
                    }
                }
                BlockNodesUnit.Remove(unit);
            }


            if (nodes != null)
            {
                HashList <TNode> newHashSetNodes = new HashList <TNode>(nodes);
                foreach (var item in nodes)
                {
                    AllBlockers.Add(item);
                    if (!BlockNodes.ContainsKey(item))
                    {
                        BlockNodes.Add(item, new HashList <BaseUnit>());
                    }
                    BlockNodes[item].Add(unit);
                }
                BlockNodesUnit.Add(unit, newHashSetNodes);
            }
        }
Пример #16
0
        public bool IsConnection(HashList <GraphNode> nodes, GraphNode target)
        {
            if (nodes == null || target == null)
            {
                return(false);
            }
            List <HashList <GraphNode> > connections = GetAllConnections(nodes);

            foreach (var list in connections)
            {
                if (list.Contains(target))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #17
0
        //移动范围是否可以链接到目标
        public bool IsCanConstantConnection(BaseUnit unit)
        {
            if (ConstantNodesMove == null || ConstantNodesMove.Count == 0)
            {
                return(false);
            }
            HashList <GraphNode> links = AStarMgr.GetConnectionsBlocker(unit);

            foreach (var item in links)
            {
                if (ConstantNodesMove.Contains(item))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #18
0
        // 移动一个单位到另一个单位的边上(随机位置)
        public bool RandArroundUnit(BaseUnit targetUnit, BaseUnit moveUnit, int range = 8)
        {
            var nodes = GetBFS(targetUnit.Pos, range, moveUnit.AStarMoveMgr.IsCanTraversal, true);
            HashList <GraphNode> RandNodes = new HashList <GraphNode>();

            //节点数量太少,无法摆放军团
            if (nodes.Count <= 1)
            {
                return(false);
            }
            //去掉中心Node
            nodes.RemoveAt(0);
            //获得备用Node
            GraphNode SpareNode = null;

            for (int i = nodes.Count - 1; i > 0; --i)
            {
                var item = nodes[i];
                if (!IsHaveUnit(item) && !IsBlocker(item))
                {
                    SpareNode = item;
                    RandNodes.Add(item);
                }
            }
            //获得随机Node
            GraphNode RandNode;

            RandNode = RandNodes.Rand();
            //获得Final Node
            GraphNode FinalNode = IsHaveUnit(RandNode) || IsBlocker(RandNode) ? SpareNode : RandNode;

            if (FinalNode != null)
            {
                moveUnit.AStarMoveMgr.SetToNode(FinalNode);
                moveUnit.MoveMgr.RandRotationY();
                return(true);
            }
            //进入递归
            else
            {
                return(RandArroundUnit(targetUnit, moveUnit, range + 1));
            }
        }
Пример #19
0
        public HashList <GraphNode> CalcConstant()
        {
            float range = CurMovePoint;

            ConstantNodesDraw.Clear();
            ConstantNodesMove.Clear();
            ConstantNodesMove = AStarMgr.GetDistanceRange(SelfBaseUnit.Pos, range, x => Traversal.CanTraverse(null, x));

            foreach (var item in ConstantNodesMove)
            {
                //过滤掉占有单位得节点,并且这个节点不是自身,防止重复绕路
                if (AStarMgr.IsHaveUnit(item))
                {
                    continue;
                }
                ConstantNodesDraw.Add(item);
            }
            return(ConstantNodesDraw);
        }
Пример #20
0
        public virtual bool Filter(GraphNode node)
        {
            bool defaulRet = node.Walkable;
            int  customRet = 0;
            HashList <BaseUnit> blockerUnits = AStarPathMgr.GetBlockerUnits(node);

            if (blockerUnits != null)
            {
                foreach (var item in blockerUnits)
                {
                    if (item != null)
                    {
                        if (!OnFilter(item))
                        {
                            customRet++;
                        }
                    }
                }
            }
            return(customRet == 0 && defaulRet);
        }
Пример #21
0
        //获得Blocker外围的一层链接Node
        public HashList <GraphNode> GetConnectionsBlocker(BaseUnit unit)
        {
            var blocker = GetBlocker(unit);

            if (blocker.Count == 0)
            {
                blocker.Add(GetNode(unit));
            }
            HashList <GraphNode> ret = new HashList <GraphNode>();

            foreach (var item in blocker)
            {
                item.GetConnections((x) =>
                {
                    if (!blocker.Contains(x))
                    {
                        ret.Add(x);
                    }
                });
            }
            return(ret);
        }
Пример #22
0
        //当前Unit的node是否可以连接到目标Unit的Blocker范围内,一般可以用来做攻击检测
        public bool IsInBlockerRange(BaseUnit unit)
        {
            HashList <GraphNode> connection = new HashList <GraphNode>();

            CurNode.GetConnections(connection.Add);
            HashList <GraphNode> targetUnitBlocker = AStarMgr.GetBlocker(unit);

            if (targetUnitBlocker != null)
            {
                foreach (var item in targetUnitBlocker)
                {
                    if (connection.Contains(item))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                CLog.Error("{0}:目标单位没有Blocker", unit.BaseConfig.GetName());
            }
            return(false);
        }
Пример #23
0
        // 获得最远距离的节点,符合以下条件:此节点没有单位,此节点可以穿越,此节点是可行走的
        public GraphNode GetDistNode(
            BaseUnit selfUnit,
            Vector3 pos,
            bool isMaxDistance     = true,
            bool isCanTraversal    = true,
            bool isNoUnit          = true,
            bool isNoBlocker       = false,
            bool isDistanceWithEnd = true)
        {
            HashSet <GraphNode> exclude = new HashSet <GraphNode>();

            return(GetCustomNode(pos));

            GraphNode GetCustomNode(Vector3 tempPos)
            {
                var target = GetSafeNode(tempPos);

                //如果种子节点符合条件就直接返回
                if (IsCondition(target))
                {
                    return(target);
                }
                GraphNode            defaultNode     = null;
                GraphNode            inConditionNode = null;
                GraphNode            unConditionNode = null;
                HashList <GraphNode> links           = new HashList <GraphNode>();

                target.GetConnections(x => { links.Add(x); });
                exclude.Add(target);

                float inConditionDistance = -1;
                float unConditionDistance = -1;

                if (isMaxDistance)
                {
                    inConditionDistance = -1;
                    unConditionDistance = -1;
                }
                else
                {
                    inConditionDistance = float.MaxValue;
                    unConditionDistance = float.MaxValue;
                }
                foreach (var item in links)
                {
                    defaultNode = item;
                    if (exclude.Contains(item))
                    {
                        continue;
                    }
                    exclude.Add(item);
                    var curDistance = 0.0f;
                    if (isDistanceWithEnd)
                    {
                        curDistance = MathUtil.XZSqrDistance((Vector3)target.position, (Vector3)item.position);
                    }
                    else
                    {
                        curDistance = MathUtil.XZSqrDistance(selfUnit.Pos, (Vector3)item.position);
                    }
                    if (IsCondition(item))
                    {
                        if (isMaxDistance)
                        {
                            if (curDistance > inConditionDistance)
                            {
                                inConditionDistance = curDistance;
                                inConditionNode     = item;
                            }
                        }
                        else
                        {
                            if (curDistance < inConditionDistance)
                            {
                                inConditionDistance = curDistance;
                                inConditionNode     = item;
                            }
                        }
                    }
                    else
                    {
                        if (isMaxDistance)
                        {
                            if (curDistance > unConditionDistance)
                            {
                                unConditionDistance = curDistance;
                                unConditionNode     = item;
                            }
                        }
                        else
                        {
                            if (curDistance < unConditionDistance)
                            {
                                unConditionDistance = curDistance;
                                unConditionNode     = item;
                            }
                        }
                    }
                }
                if (inConditionNode == null)
                {
                    if (unConditionNode == null)
                    {
                        return(defaultNode);
                    }
                    return(GetCustomNode((Vector3)unConditionNode.position));
                }
                else
                {
                    return(inConditionNode);
                }
            }

            bool IsCondition(GraphNode graphNode)
            {
                bool ret_isCanTraversal = true;
                bool ret_isNoUnit       = true;
                bool ret_isNoBlocker    = true;

                if (isCanTraversal)
                {
                    ret_isCanTraversal = selfUnit.AStarMoveMgr.IsCanTraversal(graphNode);
                }
                if (isNoUnit)
                {
                    ret_isNoUnit = !IsHaveUnit(graphNode);
                }
                if (isNoBlocker)
                {
                    ret_isNoBlocker = !IsBlocker(graphNode);
                }
                return(ret_isCanTraversal && ret_isNoUnit && ret_isNoBlocker);
            }
        }
Пример #24
0
        public Node GetSafeNode(BaseUnit selfUnit, Vector2 pos, bool isMaxDistance = true, bool isCanTraversal = true, bool noObstacle = true, bool noUnit = true, bool isDistanceWithEnd = true)
        {
            if (selfUnit.Pos.IsInv())
            {
                return(null);
            }
            var seed = GetSafeNode(pos);

            if (IsCondition(seed))
            {
                return(seed);
            }

            Node            finalNearNode = null;
            Node            noUnitNode    = null;
            Node            haveUnitNode  = null;
            HashList <Node> links         = new HashList <Node>();

            links = Ins.GetConnection(seed);
            float noUnitDistance   = -1;
            float haveUnitDistance = -1;

            if (isMaxDistance)
            {
                noUnitDistance   = -1;
                haveUnitDistance = -1;
            }
            else
            {
                noUnitDistance   = float.MaxValue;
                haveUnitDistance = float.MaxValue;
            }
            foreach (var item in links)
            {
                var curDistance = 0.0f;
                if (isDistanceWithEnd)
                {
                    curDistance = MathUtil.XZSqrDistance(seed.Pos, item.Pos);
                }
                else
                {
                    curDistance = MathUtil.XZSqrDistance(selfUnit.Pos, item.Pos);
                }
                if (IsCondition(item))
                {
                    noUnitNode = item;
                    if (isMaxDistance)
                    {
                        if (curDistance > noUnitDistance)
                        {
                            noUnitDistance = curDistance;
                            finalNearNode  = item;
                        }
                    }
                    else
                    {
                        if (curDistance < noUnitDistance)
                        {
                            noUnitDistance = curDistance;
                            finalNearNode  = item;
                        }
                    }
                }
                else
                {
                    if (isMaxDistance)
                    {
                        if (curDistance > haveUnitDistance)
                        {
                            haveUnitDistance = curDistance;
                            haveUnitNode     = item;
                        }
                    }
                    else
                    {
                        if (curDistance < haveUnitDistance)
                        {
                            haveUnitDistance = curDistance;
                            haveUnitNode     = item;
                        }
                    }
                }
            }
            if (finalNearNode == null)
            {
                return(GetSafeNode(selfUnit, haveUnitNode.Pos));
            }
            else
            {
                return(finalNearNode);
            }

            bool IsCondition(Node node)
            {
                if (noObstacle)
                {
                    if (Ins.IsObstacle(node.Index))
                    {
                        return(false);
                    }
                }
                if (noUnit)
                {
                    if (IsHaveUnit(node))
                    {
                        return(false);
                    }
                }
                if (isCanTraversal)
                {
                    if (!selfUnit.Move2DMgr.Traversal2D.Filter(node))
                    {
                        return(false);
                    }
                }
                return(true);
            }
        }
Пример #25
0
 public List <long> GetEntityIDs(HashList <BaseUnit> entity) => BaseGlobal.GetUnitIDs(entity);