Exemplo n.º 1
0
        /// <summary>
        /// 输入一个活动单位,返回该活动单位可以活动的区域。
        /// </summary>
        /// <param name="_unit">单位</param>
        /// <returns></returns>
        public TileSaveData[] CalculateMovingRange(ActivitiesUnit _unit)
        {
            // 初始化
            foreach (var v in tileList.Where(x => x.pixelValue[0] != -1))
            {
                v.SetPixelValue(-1);
                v.InitAliasName();
            }
            // 抓取部分数据
            List <TileSaveData> cacheData = tileList.Where(x => x.widthHeighValue.Vector3IntRangeValue(_unit.currentPos) <= _unit.moveRangeValue[0]).ToList();

            int tempIndex = 1;

            // 地形移动力消耗值
            foreach (var v in cacheData)
            {
                if (v.widthHeighValue.Vector3IntRangeValue(_unit.currentPos) != 0)
                {
                    v.aliasName = string.Concat("T", tempIndex++);
                }
                if (activitiesManager.GetUnitPosContains(v.widthHeighValue) &&
                    !activitiesManager.GetUnitPosContainsOtherTroop(v.widthHeighValue, _unit.managerKeyName))
                {
                    v.SetPixelValue(99);
                }
                else
                {
                    v.SetPixelValue(environmentConfig.GetConsumeValue(_unit.movingType,
                                                                      GetSprite(v.widthHeighValue)));
                }
            }
            // 单位当前位置
            var currentSaveData =
                tileList.FirstOrDefault(x => x.widthHeighValue.Vector3IntRangeValue(_unit.currentPos) == 0);

            currentSaveData.SetPixelValue(0);
            currentSaveData.aliasName = "T0";
            currentSaveData.path      = "T0";
            currentSaveData.isChange  = true;

            if (_unit.movingType != TerrainActionType.瞬行)
            {
                PressureAlgorithm(currentSaveData.widthHeighValue, _unit.moveRangeValue[0]);

                while (cacheData.Any(x => x.pixelValue[0] < _unit.moveRangeValue[0] && x.pixelValue[0] > 0 && x.isChange))
                {
                    foreach (var v in cacheData.Where(x =>
                                                      x.pixelValue[0] < _unit.moveRangeValue[0] && x.pixelValue[0] > 0 && x.isChange))
                    {
                        PressureAlgorithm(v.widthHeighValue, _unit.moveRangeValue[0]);
                    }
                }

                // 去除所有数值低于移动力的方格 与没计算过的方格.
                cacheSaveData = cacheData.Where(x =>
                                                x.pixelValue[0] <= _unit.moveRangeValue[0] && x.isChange).ToArray();
            }
            else
            {
                cacheSaveData = cacheData.Where(x => x.pixelValue[0] <= _unit.moveRangeValue[0]).ToArray();
            }

            // 去除所有 已有单位的方格
            cacheSaveData = cacheSaveData.Where(x =>
                                                (!activitiesManager.GetUnitPosContains(x.widthHeighValue) ||
                                                 x.widthHeighValue.Vector3IntRangeValue(_unit.currentPos) == 0)).ToArray();

            return(cacheSaveData);
        }