Exemplo n.º 1
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!");
     }
 }
Exemplo n.º 2
0
    public void InitSession()
    {
        // Init Camera
        CameraManager.Instance.OnEnterBattle(this);

        // Init Map
        _map = new BattleMap();
        _map.Init(BattleProcedure.CurSessionVO.MapVO);

        // Init Field
        _field = new BattleField();
        _field.Init();

        //Init FSM
        _battleFSM = new FSM();
        _battleFSM.RegisterState((int)SessionState.IdleState, new SessionIdleState());
        _battleFSM.RegisterState((int)SessionState.PerformState, new SessionPerformState());
        _battleFSM.RegisterState((int)SessionState.PlayCardState, new SessionPlayCardState());
        _battleFSM.SwitchToState((int)SessionState.IdleState);

        // Init OrderController
        _orderController = new BattleOrderController();

        // Init Performer
        _performer = new BattlePerformer();

        // Event
        EventManager.Instance.On(EventConst.ON_SELECT_OP_UNIT, OnSelectUnit);
        EventManager.Instance.On(EventConst.REQ_PLAYCARD_PARAMS, OnReqPlaycardParams);
        EventManager.Instance.On(EventConst.ON_CONFIRM_PLAYCARD, OnConfirmPlayCard);
        EventManager.Instance.On(EventConst.ON_PERFORM_START, OnPerformStart);
    }
    public void Save()
    {
        string path = inputFieldFilePath.text;

        StreamWriter writer = new StreamWriter(path, false, Encoding.GetEncoding(ENCODING));

        // 一行目はサイズ
        BattleMap battleMap = holder.BattleMap;

        BattleMapTile[,] tiles = battleMap.BattleMapTiles;
        int x = tiles.GetLength(0);
        int y = tiles.GetLength(1);

        writer.WriteLine(x + SEP + y);

        // 一行ずつ書き出す
        foreach (BattleMapTile bmt in tiles)
        {
            string str = bmt.ToFileString(SEP);
            writer.WriteLine(str);
        }

        writer.Close();

        Debug.Log("Save Successful!");
    }
Exemplo n.º 4
0
    // Functions for checking if the character can do stuff.
    #region Can do stuff

    /// <summary>
    /// Takes the range of the character's weapons and checks if any enemy is in range.
    /// </summary>
    /// <returns></returns>
    public bool CanAttack()
    {
        WeaponRange range = inventory.GetReach(ItemCategory.WEAPON);

        if (range.max == 0)
        {
            return(false);
        }
        for (int i = 0; i < enemyList.values.Count; i++)
        {
            if (!enemyList.values[i].IsAlive() || enemyList.values[i].hasEscaped)
            {
                continue;
            }
            int distance = BattleMap.DistanceTo(this, enemyList.values[i]);
            if (range.InRange(distance))
            {
                return(true);
            }
        }
        for (int i = 0; i < battleMap.breakables.Count; i++)
        {
            if (!battleMap.breakables[i].blockMove.IsAlive())
            {
                continue;
            }
            int distance = BattleMap.DistanceTo(this, battleMap.breakables[i]);
            if (range.InRange(distance))
            {
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 5
0
    private void AttackVictory(Land attackLand, Land defenceLand)
    {
        int winLandLeftUnit = 0;

        //显示上重新绘制防守地块上的Tile
        BattleMap.ResetCampTile(defenceLand.CoordinateInMap, CurCamp.campTile);
        //从防守地块列表中删除该地块
        CampDic[defenceLand.CampID].ownedLands.Remove(defenceLand);
        Cannon oldCannon = attackLand.cannon;

        //给攻下的这块地重新赋值,土遁:高炮转移术!
        winLandLeftUnit = attackLand.BattleUnit - 1;
        defenceLand.SetLandInfo(attackLand.CampID, winLandLeftUnit, oldCannon);
        //新地设置成有炮的tile
        //todo
        BattleMap.SetCannonTile(defenceLand.CoordinateInMap, CurCamp.cannonTile);
        //防守失败,卡牌有啥表示没?
        defenceLand.AfterFightCardEffect(BattleCardTriggerTime.DEFENCE_LOSE);
        //进攻成功,阵营有buff加成否?
        if (CurCamp.hasCardBuff && CurCamp.CampBuffCardEffect.VictoryCB != null)
        {
            CurCamp.CampBuffCardEffect.VictoryCB(defenceLand);
        }
        //进攻地块留守一个单位
        attackLand.SetLandInfo(attackLand.CampID, 1, new Cannon());
        //替换成没有炮的tile
        //todo
        BattleMap.SetCannonTile(attackLand.CoordinateInMap, null);
        //给进攻地块列表加上攻下的这块地
        CurCamp.ownedLands.Add(defenceLand);
    }
Exemplo n.º 6
0
    /// <summary>
    /// マップを作成
    /// </summary>
    /// <returns></returns>
    public BattleMap Create(int[,] map)
    {
        BattleMap battleMap = new BattleMap(map);

        int sizeX = map.GetLength(0);
        int sizeY = map.GetLength(1);

        battleMap.BattleMapTiles      = new BattleMapTile[sizeX, sizeY];
        battleMap.BattleMapObjectSets = new BattleMapObjectSet[sizeX, sizeY];

        for (int x = 0; x < sizeX; x++)
        {
            for (int y = 0; y < sizeY; y++)
            {
                BattleMapTile bmt = new BattleMapTile(x, y, map[x, y]);
                battleMap.BattleMapTiles[x, y] = bmt;
            }
        }

        // 隣接するタイルを設定
        SetJointTile(battleMap);

        // マスクを作成
        CreateMask(battleMap);

        return(battleMap);
    }
Exemplo n.º 7
0
 public static void DrawMap(BattleMap map)
 {
     for (int j = 0; j <= map.Tiles.Max(y => y.YCoord); j++)
     {
         for (int i = 0; i <= map.Tiles.Max(x => x.XCoord); i++)
         {
             var tile = map.Tiles.Where(x => x.XCoord == i).FirstOrDefault(y => y.YCoord == j);
             if (map.SpawnPoints.Where(x => x.XCoord == tile?.XCoord).Any(y => y.YCoord == tile?.YCoord))
             {
                 Console.Write("{");
             }
             else if (map.SpawnPoints.Where(x => x.XCoord == (i - 1)).Any(y => y.YCoord == j))
             {
                 Console.Write("}");
             }
             else
             {
                 Console.Write("|");
             }
             Console.Write(tile?.Height.ToString() ?? "X");
         }
         Console.Write("|");
         Console.WriteLine();
     }
 }
Exemplo n.º 8
0
        public AttackResult BestAttack(UnitMapPath currentUnitMapPath, BattleMap battleMap, Unit currentUnit)
        {
            Vector2 bestTarget        = currentUnitMapPath.Enemies.First();
            Vector2 tileToMove        = new Vector2();
            var     maxDamagePerDeath = 0;

            foreach (var enemy in currentUnitMapPath.Enemies)
            {
                var neigh = BattleMap.GetNeighbours(enemy.X, enemy.Y, true);
                foreach (var free in currentUnitMapPath.FreeTiles)
                {
                    if (neigh.Contains(free))
                    {
                        var enemyUnitData         = battleMap.GetUnitData((int)enemy.X, (int)enemy.Y);
                        var remainEnemyUnits      = ((enemyUnitData.Health * enemyUnitData.StackSize) - (currentUnit.UnitData.MinimumDamage * currentUnit.UnitData.StackSize)) / enemyUnitData.Health;
                        var enemyUnitsKilledForce = (enemyUnitData.StackSize - remainEnemyUnits) * enemyUnitData.MinimumDamage;
                        if (enemyUnitsKilledForce > maxDamagePerDeath)
                        {
                            bestTarget        = enemy;
                            tileToMove        = free;
                            maxDamagePerDeath = enemyUnitsKilledForce;
                        }
                        break;
                    }
                }
            }
            return(new AttackResult()
            {
                AttackTile = tileToMove, AttackBenefict = maxDamagePerDeath, Target = bestTarget
            });
        }
Exemplo n.º 9
0
        public void Initialize()
        {
            Global.camera.X = 0;
            Global.camera.Y = 0;
            //the first two indices are obviously x and y, although the third is NOT z!
            //the third stores any number of tiles when z can be queryed.
            //Note that this is not inefficient for the GraphicsCard since
            //the TileMap takes the three-dimensional and skips the null cells
            //when copying the vertices.
            TileMapParser mapLoader = new TileMapParser();
            TileMap       demoMap   = mapLoader.LoadMap("DemoMap");

            demoMap.player = new OWPlayer("Images/Characters/nickOW", new int[3] {
                1, 1, 0
            }, Tile.Direction.SOUTH);
            demoMap.Initialize();
            tileMaps.Add("DemoMap", demoMap);
            TileMap stairMap = mapLoader.LoadMap("StairMap");

            tileMaps.Add("StairMap", stairMap);
            tileMap = demoMap;

            battleMaps = new Dictionary <string, BattleMap>();
            Battler[] battlers = new Battler[1];
            battlers[0] = new Battler("Images/Characters/nickBattle", new Vector3(0, 0, 0));
            BattleMap testMap = new BattleMap("Ice_Path", battlers, 0);

            testMap.Initialize();
            battleMaps.Add("Ice_Path", testMap);
            battleMap = testMap;

            dialog = new Dialog();
            dialog.Initialize();
        }
Exemplo n.º 10
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!");
        }
    }
Exemplo n.º 11
0
    private bool CheckReq(TacticsMove user, TacticsMove enemy)
    {
        bool terrainOk = false;

        for (int i = 0; i < terrainReq.Count; i++)
        {
            if (user.currentTile.terrain == terrainReq[i])
            {
                terrainOk = true;
                break;
            }
        }

        int  dist    = BattleMap.DistanceTo(user, enemy);
        bool rangeOk = (range <= dist && dist <= rangeMax);

        bool retaliateOk = (enemyCanAttack == EnemyCanAttack.BOTH);

        if (enemyCanAttack != EnemyCanAttack.BOTH)
        {
            InventoryTuple tuple   = enemy.GetEquippedWeapon(ItemCategory.WEAPON);
            bool           inRange = (!string.IsNullOrEmpty(tuple.uuid) && tuple.InRange(range));
            retaliateOk = ((inRange && enemyCanAttack == EnemyCanAttack.ATTACK) ||
                           (!inRange && enemyCanAttack == EnemyCanAttack.NO_ATTACK));
        }

        return(retaliateOk && (terrainOk || rangeOk));
    }
Exemplo n.º 12
0
        public DelaunayGenerator(BattleMap map, object optionsObj)
        {
            _options = (DelaunayGeneratorOptions)optionsObj;
            _map     = map;

            Reset();
        }
 public ActionPanelPickUpHealthCrate(BattleMap Map, HealthCrate Owner, Squad ActiveSquad)
     : base(PanelName, Map.ListActionMenuChoice, null, false)
 {
     this.Map         = Map;
     this.Owner       = Owner;
     this.ActiveSquad = ActiveSquad;
 }
Exemplo n.º 14
0
    public void SpawnPlayerUnits()
    {
        int offsetX = (map.mapSizeX / 2) - (map.mapSizeX / 4);
        int offsetZ = 7;

        for (int i = 0; i < playerUnits.units.Count; i++)
        {
            if (playerUnits.isOnBattleField[i])
            {
                CreachureStats creachure = playerUnits.units[i];
                GameObject     spawned   = GameObject.Instantiate(Resources.Load("BattlePlayerUnit")) as GameObject;

                BattleUnit battleUnit = spawned.GetComponent <BattleUnit>();
                PlayerBattleList.Add(battleUnit);
                BattleOrder.Add(battleUnit);

                int tileX = playerUnits.BattleFieldIndex[i] / 6 + offsetX;
                int tileZ = playerUnits.BattleFieldIndex[i] % 6 + offsetZ;

                battleUnit.tileX       = tileX;
                battleUnit.tileZ       = tileZ;
                battleUnit.UnitStats   = creachure;
                battleUnit.visionRange = creachure.VisionRange;

                spawned.transform.position = BattleMap.ConvertTileCoordToWorld(battleUnit.tileX, battleUnit.tileZ);
                map.tiles[tileX, tileZ].mapObjects.Add(battleUnit);
                map.visibleObjects.Add(battleUnit);
            }
        }
    }
Exemplo n.º 15
0
    public void Init(int width, int height, List <string> teamA, List <string> teamB)
    {
        //将Grid铺起来,但并未连接渲染器
        BattleMap = BattleMapCreator.Instance.Create(width, height);

        //生成战斗单位小组,加GridUnit加入Team中
        GenerateBattleTeam(teamA, teamB);
    }
Exemplo n.º 16
0
 private void BattleMap_Click(object sender, RoutedEventArgs e)
 {
     BattleMap battleMap = new BattleMap
     {
         Visibility = Visibility.Visible,
         IsEnabled  = true
     };
 }
Exemplo n.º 17
0
 public void CopyData(TacticsMove other)
 {
     battleMap = other.battleMap;
     posx      = other.posx;
     posy      = other.posy;
     stats     = other.stats;
     inventory = other.inventory;
     skills    = other.skills;
 }
Exemplo n.º 18
0
 public void OnRecycle()
 {
     if (battleMap != null)
     {
         battleMap.Return();
         battleMap = null;
     }
     RemoveAllBattleUntis();
 }
Exemplo n.º 19
0
 private void DefenceVictory(Land attackLand)
 {
     //给进攻失败这块地重新赋值,我炮没了
     attackLand.SetLandInfo(attackLand.CampID, 1, new Cannon());
     //替换成没有炮的tile
     //todo
     BattleMap.SetCannonTile(attackLand.CoordinateInMap, null);
     //进攻失败,卡牌有啥表示没
     attackLand.AfterFightCardEffect(BattleCardTriggerTime.ATTACK_LOSE);
 }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        if (GUILayout.Button("Regenerate Map"))
        {
            BattleMap MyMap = (BattleMap)this.target;
            MyMap.buildMesh();
        }
    }
Exemplo n.º 21
0
 public void Load(BattleMap map, bool destroyUnits)
 {
     CreateMap(map.cellCountX, map.cellCountY, false, false, destroyUnits);
     for (int i = 0; i < map.cells.Length; i++)
     {
         Cells[i].Load(map.cells[i], this);
     }
     ShowGameGrid(gameGridStatus);
     Debug.Log("Map loaded");
 }
Exemplo n.º 22
0
        public MemRowColumnMap(string map, int tile)
        {
            bMap        = BattleMapBook.GetMap(map);
            CardSize    = stageWidth / bMap.XCount;
            RowCount    = bMap.YCount;
            ColumnCount = bMap.XCount;

            InitCells(tile);

            isDirty = true;
        }
Exemplo n.º 23
0
 public void Start()
 {
     Init();
     //generateWeaponTemplate();
     //generateUnitTypeTemplate();
     generateBattleMapTemplate();
     map = new BattleMap(this, battleMapTemplates[0]);
     string[] names = { "janek", "tomek", "kuba", "artur", "sergiej", "bob" };
     allUnits.Add(new Unit(names[Random.Range(0, 5)], unitTypes[0], this));
     //Debug.Log(map.Tiles[0,0]+"+"+ map.Tiles[0, 1] + "+"+ map.Tiles[0, 2]);
 }
Exemplo n.º 24
0
    /// <summary>
    /// 隣接するタイルを設定
    /// </summary>
    /// <param name="battleMap"></param>
    public void SetJointTile(BattleMap battleMap)
    {
        foreach (BattleMapTile tile in battleMap.BattleMapTiles)
        {
            // 接続を作成
            List <BattleMapTilePointAndType> patList = MapUtils.GetJoinTile(battleMap.MapPoints, tile.X, tile.Y);

            // 接続情報を作成
            tile.JointInfo = CreateJointInfo(battleMap.BattleMapTiles, patList);
        }
    }
Exemplo n.º 25
0
        protected override void Initialize()
        {
            base.Initialize();
            BattleMap     testMap  = new BattleMap(40, 40);
            BattleMapView view     = new BattleMapView(testMap);
            UIViewport    viewport = new UIViewport(0, 0, GraphicsDevice.DisplayMode.Width, GraphicsDevice.DisplayMode.Height, view, this);

            ActiveState.UI.Add(viewport);

            LoadData();
        }
Exemplo n.º 26
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Debug.Log("More than 1 instance " + this.GetType().ToString());
         Destroy(this);
     }
 }
Exemplo n.º 27
0
    public void Start()
    {
        BattleMap map = Instantiate(battleMap, new Vector3(Screen.width / 2, Screen.height / 2, 490), Quaternion.identity);

        map.controller       = controller;
        map.playercontroller = playerController;
        map.turnOrder        = CheckTurnOrder();
        for (int l = 0; l < TurnOrder.Count; l++)
        {
            Debug.Log(TurnOrder[l]);
        }
    }
Exemplo n.º 28
0
    void ButtonPressed(Button button)
    {
        if (button == this.uiRefs.undoButton)
        {
            this.UndoHistoryEvent(this.lastHistoryEventNode.Value);
            this.lastHistoryEventNode = this.lastHistoryEventNode.Previous;

            this.UpdateUI();
        }
        else if (button == this.uiRefs.redoButton)
        {
            if (this.lastHistoryEventNode != null)
            {
                this.lastHistoryEventNode = this.lastHistoryEventNode.Next;
            }
            else
            {
                this.lastHistoryEventNode = this.historyEvents.First;
            }
            this.DoHistoryEvent(this.lastHistoryEventNode.Value);

            this.UpdateUI();
        }
        else if (button == this.uiRefs.selectNoneButton)
        {
            var historyEvent = new SelectionChangeHistoryEvent();
            historyEvent.oldSelectedTiles = new List <Vector2i>(this.selectedTiles.Select(x => x.pos));
            historyEvent.newSelectedTiles = new List <Vector2i>();
            this.AddNewHistoryEvent(historyEvent);
        }
        else if (button == this.uiRefs.saveButton)
        {
            string jsonText = JsonUtility.ToJson(this.map, true);
            var    sw       = new StreamWriter("Maps/" + this.uiRefs.mapNameTextbox.text + ".json");
            sw.Write(jsonText);
            sw.Close();
        }
        else if (button == this.uiRefs.loadButton)
        {
            StreamReader sr       = new StreamReader("Maps/" + this.uiRefs.mapNameTextbox.text + ".json");
            string       jsonText = sr.ReadToEnd();
            sr.Close();

            this.map = JsonUtility.FromJson <BattleMap>(jsonText);

            this.selectedTiles        = new List <MapTile>();
            this.historyEvents        = new LinkedList <BaseHistoryEvent>();
            this.lastHistoryEventNode = null;

            this.RebuildMapDisplay();
            this.UpdateUI();
        }
    }
Exemplo n.º 29
0
        public override void ReinitializeMembers(Unit InitializedUnitBase)
        {
            UnitMagic Other = (UnitMagic)InitializedUnitBase;

            Map = Other.Map;

            if (OriginalUnit == null)
            {
                OriginalUnit = FromFullName(OriginalUnitName, Map.Content, Map.DicUnitType, Map.DicRequirement, Map.DicEffect);
                _UnitStat    = OriginalUnit.UnitStat;
            }
        }
Exemplo n.º 30
0
    public void BeginWar(Vector2Int size, List <BattleUnit> battleUnits)
    {
        BattleManager.Instance.existingBattle = this;
        this.battleUnits = battleUnits;
        _battleMap       = new BattleMap(size);

        Dictionary <int, int> hasTeams = new  Dictionary <int, int>();

        teams = new List <List <BattleUnit> >();

        foreach (var unit in battleUnits)
        {
            unit.StartBattle(_battleMap);
            int team = unit.team.teamIndex;

            if (!hasTeams.ContainsKey(team))
            {
                hasTeams.Add(team, teams.Count);
                var units = new List <BattleUnit> {
                    unit
                };
                teams.Add(units);
            }
            else
            {
                var units = teams[hasTeams[team]];
                units.Add(unit);
            }
        }

        var offset = 0;
        var x      = 0;
        var y      = 0;

        //init map and teams
        foreach (var team in teams)
        {
            foreach (var unit in team)
            {
                unit.pos = new Vector2Int(x + offset, y);
                y        = (y + 1) % _battleMap.size.y;
                _battleMap.map[unit.pos.x, unit.pos.y] = unit;
            }

            offset += 6;
        }



        BattleManager.Instance.StartCoroutine(UnitActions());
        warStarted = true;
    }