private void PortalQuery(Unity.Entities.Entity entity,
                                 ref StrategyHexAccessPortal.Component portal)
        {
            if (isUpdated)
            {
                return;
            }

            var indexes = portal.HexIndexes;
            var hexes   = portal.FrontHexes;

            if (indexes.Count == 0 && hexes.Count == 0)
            {
                return;
            }

            this.hexIndexes.Clear();
            foreach (var i in indexes)
            {
                HexLocalInfo local = null;
                this.HexDic?.TryGetValue(i.Key, out local);
                this.hexIndexes.Add(i.Key, new HexIndexPower(i.Value, local));
            }

            this.frontHexes.Clear();
            foreach (var h in hexes)
            {
                this.frontHexes.Add(h.Key, h.Value);
            }

            isUpdated = true;
        }
 private void PortalQuery(Unity.Entities.Entity entity,
                          ref StrategyHexAccessPortal.Component portal)
 {
     hexIndexes = portal.HexIndexes;
 }
Ejemplo n.º 3
0
        private void PortalQuery(Entity entity,
                                 ref StrategyHexAccessPortal.Component portal)
        {
            var f = portal.FrontHexes;
            var h = portal.HexIndexes;

            DeepCopy(f, h);

            foreach (var side in HexUtils.AllSides)
            {
                Dictionary <uint, HexDetails> indexes = null;
                if (borderHexListDic.TryGetValue(side, out indexes) == false)
                {
                    if (fronts.ContainsKey(side))
                    {
                        fronts.Remove(side);
                    }
                    continue;
                }

                if (fronts.ContainsKey(side) == false)
                {
                    fronts[side] = new FrontHexInfo {
                        Indexes = new List <uint>()
                    }
                }
                ;

                var info = fronts[side];
                if (CompairList(info.Indexes, indexes))
                {
                    fronts[side] = info;
                }
            }

            foreach (var kvp in this.HexDic)
            {
                var index = kvp.Key;
                if (hexes.ContainsKey(index) == false)
                {
                    hexes[index] = new HexIndex();
                }

                var info = kvp.Value;
                var hex  = hexes[index];
                hex.Index    = info.Index;
                hex.EntityId = info.EntityId.EntityId;
                List <FrontLineInfo> frontLines = hex.FrontLines;

                if (borderHexListDic.TryGetValue(info.Side, out var borderList) &&
                    borderList != null &&
                    borderList.TryGetValue(index, out var detail))
                {
                    frontLines = detail.frontLines;
                }
                else
                {
                    frontLines = frontLines ?? new List <FrontLineInfo>();
                }

                hex.FrontLines = frontLines;
                hex.IsActive   = info.isActive;
                hex.Side       = info.Side;

                hexes[index] = hex;
            }

            if (CheckFrontsDiff(f))
            {
                portal.FrontHexes = fronts;
            }

            if (CheckHexesDiff(h))
            {
                portal.HexIndexes = hexes;
            }
        }