Beispiel #1
0
        private void Query(Entity entity,
                           ref HexBase.Component hex,
                           ref HexPower.Component power,
                           ref Position.Component position,
                           ref SpatialEntityId entityId)
        {
            if (hex.Attribute.IsTargetable() == false)
            {
                return;
            }

            if (hexDic.ContainsKey(hex.Index) == false)
            {
                hexDic[hex.Index] = new HexLocalInfo();
            }

            hexDic[hex.Index].Index    = hex.Index;
            hexDic[hex.Index].HexId    = hex.HexId;
            hexDic[hex.Index].Side     = hex.Side;
            hexDic[hex.Index].EntityId = entityId;
            hexDic[hex.Index].Powers   = power.SidePowers;
            hexDic[hex.Index].isActive = power.IsActive;
        }
Beispiel #2
0
        private void PowerQuery(Entity entity,
                                ref HexPower.Component power,
                                ref HexBase.Component hex,
                                ref SpatialEntityId entityId)
        {
            var hexSide = hex.Side;

            if (hexSide == UnitSide.None)
            {
                return;
            }

            power.SidePowers.TryGetValue(hexSide, out var current);

            if (current <= 0)
            {
                power.SidePowers[hexSide] = 0;
                current = 0;
            }

            if (resourceDictionary.TryGetValue(hex.Index, out var resourceValue))
            {
                power.SidePowers[hexSide] = current + (float)(resourceValue * deltaTime);
            }

            var ids = HexUtils.GetNeighborHexIndexes(hex.Index);

            targetIds.Clear();
            foreach (var id in ids)
            {
                if (base.HexDic.ContainsKey(id) == false)
                {
                    continue;
                }

                var  h      = base.HexDic[id];
                bool isFlow = false;
                if (h.Side == hexSide)
                {
                    if (current > h.CurrentPower + current * flowValueRate)
                    {
                        isFlow = true;
                    }
                }
                else if (h.Side == UnitSide.None)
                {
                    isFlow = true;
                }

                if (isFlow)
                {
                    targetIds.Add(id);
                }
            }

            var totalFlow = (float)(flowValueRate * deltaTime * current);
            var count     = targetIds.Count;
            var flow      = totalFlow / count;

            foreach (var id in targetIds)
            {
                float val = flow;
                if (power.SidePowers[hexSide] > flow)
                {
                    power.SidePowers[hexSide] -= flow;
                }
                else
                {
                    val = power.SidePowers[hexSide];
                    power.SidePowers[hexSide] = 0;
                }

                var h   = base.HexDic[id];
                var key = h.EntityId.EntityId;
                if (flowDictionary.ContainsKey(key))
                {
                    var powerDic = flowDictionary[key];
                    if (powerDic.ContainsKey(hexSide))
                    {
                        powerDic[hexSide] += val;
                    }
                    else
                    {
                        powerDic[hexSide] = val;
                    }
                }
                else
                {
                    flowDictionary[key] = new Dictionary <UnitSide, float>();
                    flowDictionary[key].Add(hexSide, val);
                }
            }
        }