コード例 #1
0
ファイル: BattleManager.cs プロジェクト: rider02/enburoku
    /// <summary>
    /// 戦闘開始前の処理メソッド
    /// </summary>
    ///
    //200814 自分ターンに敵を選択した時、敵AIの攻撃時に呼んで、戦闘ウィンドウを初期化する
    public void MapOpenBattleView(PlayerModel playerModel, EnemyModel enemyModel, bool isPlayerAttack)
    {
        //プレイヤーからの攻撃か否かを設定
        this.isPlayerAttack = isPlayerAttack;

        Unit  unit  = playerModel.unit;
        Enemy enemy = enemyModel.enemy;

        //210219 戦闘に地形効果を追加
        //ユニット、敵のセル情報を取得する
        Main_Cell unitCell  = mainMap.Cells.FirstOrDefault(c => c.X == playerModel.x && c.Y == playerModel.z);
        Main_Cell enemyCell = mainMap.Cells.FirstOrDefault(c => c.X == enemyModel.x && c.Y == enemyModel.y);

        //通常は有り得ない
        if (unitCell == null)
        {
            Debug.Log($"ERROR:ユニットの座標のセル情報が有りません X:{playerModel.x},Y:{playerModel.z}");
        }
        if (enemyCell == null)
        {
            Debug.Log($"ERROR:敵の座標のセル情報が有りません X:{enemyModel.x},Y:{enemyModel.y}");
        }

        //戦闘に使用する数値の計算を実施してUIに表示
        var battleParameterDTO = battleCalculator.CalculateBattleParameter(unit, unit.equipWeapon, unitCell, enemy, enemyCell, isPlayerAttack);

        battleView.GetComponent <BattleView>().UpdateText(battleParameterDTO);

        //戦闘UI表示
        battleView.SetActive(true);

        //本クラスに戦闘するプレイヤーと敵を設定
        BattleInit(unit, enemy);

        //プレイヤー攻撃時のみ確認ウィンドウを表示してフォーカス
        if (isPlayerAttack)
        {
            //第二引数は攻撃ならtrue
            battleConfirmWindow.GetComponent <BattleConfirmWindow>().UpdateConfirmtext("戦闘開始して良いですか?", true);
            battleConfirmWindow.SetActive(true);
            EventSystem.current.SetSelectedGameObject(null);
            EventSystem.current.SetSelectedGameObject(battleConfirmWindow.transform.Find("ButtonLayout/StartButton").gameObject);
        }
        else
        {
            //敵から攻撃された時、武器の回数が減らない場合があるバグ対応
            foreach (Item item in unit.carryItem)
            {
                if (item.ItemType == ItemType.WEAPON && item.isEquip)
                {
                    item.weapon = unit.equipWeapon;
                }
            }
            //敵の攻撃時は確認せずに戦闘開始
            battleConfirmWindow.SetActive(false);
            BattleStart();
        }
    }