Beispiel #1
0
    void RefreshCells()
    {
        var sz   = MG.Room.MapSize;
        var cols = (int)sz.x;
        var rows = (int)sz.y;
        var n    = 0;
        var cm   = transform.Find("Cell").gameObject;

        FC.For2(cols, rows, (x, y) =>
        {
            if (MG.Room.CheckSpareSpace(x, y, 1))
            {
                return;
            }

            if (n >= cells.Count)
            {
                var c = Instantiate(cm) as GameObject;
                c.SetActive(true);
                c.transform.SetParent(transform, false);
                cells.Add(c);
            }

            cells[n++].transform.localPosition = new Vector3(x, 0.1f, y);
        });

        FC.For(n, cells.Count, (i) => { cells[i].SetActive(false); });
    }
Beispiel #2
0
 public void BuildMapGrids()
 {
     JudgeMapStatus();
     if (!IsMapCreated)
     {
         Map   = new BattleMap(10, 6, (x, y) => TileType.Grass);
         Tiles = new MapTile[Map.Width, Map.Height];
         FC.For2(Map.Width, Map.Height, (x, y) =>
         {
             var tile = Instantiate(MapTile);
             tile.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("TestRes/BattleMap/MapTile");
             tile.transform.SetParent(MapRoot);
             tile.X = x;
             tile.Y = y;
             tile.transform.Find("Material").GetComponent <SpriteRenderer>().sortingOrder = y + 2;
             tile.gameObject.SetActive(true);
             Tiles[x, y] = tile;
             MapTilesList.Add(tile);
         });
         IsMapCreated = true;
     }
     else
     {
         Debug.Log("Map is already created!");
     }
 }
Beispiel #3
0
        // 检查战斗结束条件,0 表示尚未结束,否则返回值表示胜利玩家
        // 检查战斗结束条件
        public virtual int CheckEndCondition()
        {
            // 双方至少各存活一个角色
            var team1Survived = false;
            var team2Survived = false;

            FC.For2(Map.Width, Map.Height, (x, y) =>
            {
                var warrior = Map.GetAt <Warrior>(x, y);
                if (warrior != null && !warrior.IsDead)
                {
                    if (warrior.Team == 1)
                    {
                        team1Survived = true;
                    }
                    else
                    {
                        team2Survived = true;
                    }
                }
            }, () => !team1Survived || !team2Survived);

            if (team1Survived && !team2Survived)
            {
                return(1);
            }
            else if (team2Survived && !team1Survived)
            {
                return(2);
            }
            else
            {
                return(0);
            }
        }
Beispiel #4
0
    // 构建新的地块层
    public void BuildMapGrids()
    {
        JudgeMapStatus();
        if (!IsMapCreated)
        {
            Map = new BattleMap(10, 6, (x, y) => TileType.None);
            FC.For2(Map.Width, Map.Height, (x, y) =>
            {
                var tile = Instantiate(MapTile);
                tile.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("TestRes/BattleMap/MapTile");
                tile.transform.SetParent(MapRoot);
                tile.X                    = x;
                tile.Y                    = y;
                var material              = tile.transform.Find("Material").GetComponent <SpriteRenderer>();
                var respawnPlace          = tile.transform.Find("RespawnPlace").GetComponent <SpriteRenderer>();
                material.sortingOrder     = y + 2;
                respawnPlace.sortingOrder = y + 3;
                tile.gameObject.SetActive(true);
                MapTilesList.Add(tile);

                // MapData没有new之前就传递是值传递
                tile.GetComponent <MapTile>().MapData = new MapData(x, y, TileType.None, material.sortingOrder, respawnPlace.sortingOrder);
                var mapData = tile.GetComponent <MapTile>().MapData;
                MapInfo.Add(mapData);
            });
            IsMapCreated = true;
            isNewMap     = true;
        }
        else
        {
            Debug.Log("Map is already created!");
        }
    }
Beispiel #5
0
 // 构建寻路器
 void BuildPathFinder()
 {
     pathNodes = new PathNode[Width, Height];
     FC.For2(Width, Height, (x, y) => pathNodes[x, y] = new PathNode(x, y, CheckSpareSpace));
     pathFinder = new SpatialAStar <PathNode, KeyValuePair <int, int> >(pathNodes)
     {
         Only4Adjacent = true
     };
 }
Beispiel #6
0
        // 遍历指定区域
        void ForArea(int cx, int cy, int r, Action <int, int> fun, Func <bool> continueCondition = null)
        {
            if (r <= 0)
            {
                return;
            }

            r--;
            FC.For2(cx - r, cx + r + 1, cy - r, cy + r + 1, fun, continueCondition);
        }
Beispiel #7
0
 // 迭代所有非空道具
 public void ForeachObjs(Action <int, int, BattleMapObj> act, Func <BattleMapObj, bool> filter = null, Func <bool> continueCondition = null)
 {
     FC.For2(Width, Height, (x, y) =>
     {
         var obj = objs[x, y];
         if (obj != null && (filter == null || filter(obj)))
         {
             act(x, y, obj);
         }
     }, continueCondition);
 }
Beispiel #8
0
    public void ForeachMapTile(Action <int, int, MapTile> act, Func <bool> continueCondition = null)
    {
        FC.For2(Map.Width, Map.Height, (x, y) =>
        {
            var tile = Tiles[x, y];
            if (tile == null)
            {
                return;
            }

            act(x, y, tile);
        }, continueCondition);
    }
Beispiel #9
0
    public void ForeachItem(Action <int, int, MapItem> act, Func <bool> continueCondition = null)
    {
        FC.For2(Map.Width, Map.Height, (x, y) =>
        {
            var item = Items[x, y];
            if (item == null)
            {
                return;
            }

            act(x, y, item);
        }, continueCondition);
    }
Beispiel #10
0
    public void ForeachAvatar(Action <int, int, MapAvatar> act, Func <bool> continueCondition = null)
    {
        FC.For2(Map.Width, Map.Height, (x, y) =>
        {
            var avatar = Avatars[x, y];
            if (avatar == null)
            {
                return;
            }

            act(x, y, avatar);
        }, continueCondition);
    }
Beispiel #11
0
 void BuildMapGrids()
 {
     Tiles = new MapTile[Map.Width, Map.Height];
     FC.For2(Map.Width, Map.Height, (x, y) =>
     {
         var tile = Instantiate(MapTile);
         tile.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("TestRes/BattleMap/MapTile");
         tile.transform.SetParent(MapRoot);
         tile.X = x;
         tile.Y = y;
         Map.SetMapTileInfo(tile);
         SetMapTile(tile);
         tile.GetComponent <SpriteRenderer>().sortingOrder = y + 1;
         tile.gameObject.SetActive(true);
         Tiles[x, y] = tile;
     });
 }
Beispiel #12
0
 // 显示攻击范围
 public void ShowAttackRange(float x, float y, Warrior worrior)
 {
     Debug.Assert(pathATKRange.Count == 0, "path range is not empty now.");
     FC.For(worrior.AttackRange.Length, (i) =>
     {
         int minX = (x - worrior.AttackRange[i]) < 0 ? 0 : (int)(x - worrior.AttackRange[i]);
         int maxX = (x + worrior.AttackRange[i]) >= BattleStage.Map.Width ? BattleStage.Map.Width : (int)(x + worrior.AttackRange[i] + 1);
         int minY = (y - worrior.AttackRange[i]) < 0 ? 0 : (int)(y - worrior.AttackRange[i]);
         int maxY = (y + worrior.AttackRange[i]) >= BattleStage.Map.Height ? BattleStage.Map.Height : (int)(y + worrior.AttackRange[i] + 1);
         FC.For2(minX, maxX, minY, maxY, (tx, ty) =>
         {
             if (MU.ManhattanDist((int)x, (int)y, tx, ty) == worrior.AttackRange[i])
             {
                 var tile = BattleStage.CreateMapTile(tx, ty);
                 pathATKRange.Add(tile);
                 var avatar = BattleStage.GetAvatarAt(tx, ty);
                 if (avatar != null && avatar.Warrior.Team != worrior.Team)
                 {
                     avatar.AttackHint.SetActive(true);
                 }
             }
         });
     });
 }
Beispiel #13
0
 // 构建寻路器
 void BuildPathFinder()
 {
     pathNodes = new PathNode[w, h];
     FC.For2(w, h, (x, y) => pathNodes[x, y] = new PathNode(x, y, CheckSpareSpace));
     pathFinder = new SpatialAStar <PathNode, KeyValuePair <int, T[]> >(pathNodes);
 }
Beispiel #14
0
 public void ResetTiles(Func <int, int, TileType> fun)
 {
     FC.For2(Width, Height, (x, y) => Tiles[x, y] = fun(x, y));
 }