コード例 #1
0
ファイル: SRC.play.cs プロジェクト: 7474/SRC
        private void CPUOperation(string uparty)
        {
            // CPUによるユニット操作
            for (var phase = 1; phase <= 5; phase++)
            {
                foreach (var u in UList.Items)
                {
                    // フェイズ中に行動するユニットを選択
                    Commands.SelectedUnit = u;
                    if (u.Status != "出撃")
                    {
                        continue;
                    }

                    if (u.Action == 0)
                    {
                        continue;
                    }

                    if ((u.Party ?? "") != (uparty ?? ""))
                    {
                        continue;
                    }

                    var phaseJudgeUnit = u;

                    // 他のユニットを護衛しているユニットは護衛対象と同じ順に行動
                    if (PList.IsDefined(u.Mode))
                    {
                        var p = PList.Item(u.Mode);
                        if (p.Unit != null)
                        {
                            if (p.Unit.Party == uparty)
                            {
                                phaseJudgeUnit = p.Unit;
                            }
                        }
                    }
                    // XXX 二段階走査してるってこと?
                    if (PList.IsDefined(phaseJudgeUnit.Mode))
                    {
                        var p = PList.Item(phaseJudgeUnit.Mode);
                        if (p.Unit != null)
                        {
                            if (p.Unit.Party == uparty)
                            {
                                phaseJudgeUnit = p.Unit;
                            }
                        }
                    }

                    switch (phase)
                    {
                    case 1:
                        // 最初にサポート能力を持たないザコユニットが行動
                        if (phaseJudgeUnit.BossRank >= 0)
                        {
                            continue;
                        }
                        if (phaseJudgeUnit.MainPilot().HasSupportSkill())
                        {
                            continue;
                        }

                        break;

                    case 2:
                        // 次にサポート能力を持たないボスユニットが行動
                        if (phaseJudgeUnit.MainPilot().HasSupportSkill())
                        {
                            continue;
                        }

                        break;

                    case 3:
                        // 次に統率能力を持つユニットが行動
                        if (!phaseJudgeUnit.MainPilot().IsSkillAvailable("統率"))
                        {
                            continue;
                        }
                        break;

                    case 4:
                        // 次にサポート能力を持つザコユニットが行動
                        if (phaseJudgeUnit.BossRank >= 0)
                        {
                            continue;
                        }
                        break;

                    case 5:
                        // 最後にサポート能力を持つボスユニットが行動
                        break;
                    }

                    while (Commands.SelectedUnit.Action > 0)
                    {
                        // 途中で状態が変更された場合
                        if (Commands.SelectedUnit.Status != "出撃")
                        {
                            break;
                        }

                        // 途中で陣営が変更された場合
                        if ((Commands.SelectedUnit.Party ?? "") != (uparty ?? ""))
                        {
                            break;
                        }

                        if (!GUI.IsRButtonPressed())
                        {
                            GUIStatus.DisplayUnitStatus(Commands.SelectedUnit);
                            GUI.Center(Commands.SelectedUnit.x, Commands.SelectedUnit.y);
                            GUI.RedrawScreen();
                            // XXX
                            //Application.DoEvents();
                        }

                        IsCanceled = false; // Cancelコマンドのクリア

                        // ユニットを行動させる
                        COM.OperateUnit();
                        if (IsScenarioFinished)
                        {
                            return;
                        }

                        // ハイパーモード・ノーマルモードの自動発動チェック
                        UList.CheckAutoHyperMode();
                        UList.CheckAutoNormalMode();

                        // Cancelコマンドが実行されたらここで終了
                        if (IsCanceled)
                        {
                            if (Commands.SelectedUnit is null)
                            {
                                break;
                            }

                            if (Commands.SelectedUnit.Status != "出撃")
                            {
                                break;
                            }

                            IsCanceled = false;
                        }

                        // 行動数を減少
                        Commands.SelectedUnit.UseAction();

                        // 接触イベント
                        {
                            var withBlock13 = Commands.SelectedUnit;
                            if (withBlock13.Status == "出撃" && withBlock13.x > 1)
                            {
                                if (Map.MapDataForUnit[withBlock13.x - 1, withBlock13.y] is object)
                                {
                                    Commands.SelectedTarget = Map.MapDataForUnit[withBlock13.x - 1, withBlock13.y];
                                    Event.HandleEvent("接触", withBlock13.MainPilot().ID, Map.MapDataForUnit[withBlock13.x - 1, withBlock13.y].MainPilot().ID);
                                    if (IsScenarioFinished)
                                    {
                                        return;
                                    }
                                }
                            }
                        }

                        {
                            var withBlock14 = Commands.SelectedUnit;
                            if (withBlock14.Status == "出撃" && withBlock14.x < Map.MapWidth)
                            {
                                if (Map.MapDataForUnit[withBlock14.x + 1, withBlock14.y] is object)
                                {
                                    Commands.SelectedTarget = Map.MapDataForUnit[withBlock14.x + 1, withBlock14.y];
                                    Event.HandleEvent("接触", withBlock14.MainPilot().ID, Map.MapDataForUnit[withBlock14.x + 1, withBlock14.y].MainPilot().ID);
                                    if (IsScenarioFinished)
                                    {
                                        return;
                                    }
                                }
                            }
                        }

                        {
                            var withBlock15 = Commands.SelectedUnit;
                            if (withBlock15.Status == "出撃" && withBlock15.y > 1)
                            {
                                if (Map.MapDataForUnit[withBlock15.x, withBlock15.y - 1] is object)
                                {
                                    Commands.SelectedTarget = Map.MapDataForUnit[withBlock15.x, withBlock15.y - 1];
                                    Event.HandleEvent("接触", withBlock15.MainPilot().ID, Map.MapDataForUnit[withBlock15.x, withBlock15.y - 1].MainPilot().ID);
                                    if (IsScenarioFinished)
                                    {
                                        return;
                                    }
                                }
                            }
                        }

                        {
                            var withBlock16 = Commands.SelectedUnit;
                            if (withBlock16.Status == "出撃" && withBlock16.y < Map.MapHeight)
                            {
                                if (Map.MapDataForUnit[withBlock16.x, withBlock16.y + 1] is object)
                                {
                                    Commands.SelectedTarget = Map.MapDataForUnit[withBlock16.x, withBlock16.y + 1];
                                    Event.HandleEvent("接触", withBlock16.MainPilot().ID, Map.MapDataForUnit[withBlock16.x, withBlock16.y + 1].MainPilot().ID);
                                    if (IsScenarioFinished)
                                    {
                                        return;
                                    }
                                }
                            }
                        }

                        // 進入イベント
                        {
                            var withBlock17 = Commands.SelectedUnit;
                            if (withBlock17.Status == "出撃")
                            {
                                Event.HandleEvent("進入", withBlock17.MainPilot().ID, "" + withBlock17.x, "" + withBlock17.y);
                                if (IsScenarioFinished)
                                {
                                    return;
                                }
                            }
                        }

                        // 行動終了イベント
                        {
                            var withBlock18 = Commands.SelectedUnit;
                            if (withBlock18.Status == "出撃")
                            {
                                Event.HandleEvent("行動終了", withBlock18.MainPilot().ID);
                                if (IsScenarioFinished)
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: SRC.play.cs プロジェクト: 7474/SRC
        // 陣営upartyのフェイズを実行
        public void StartTurn(string uparty)
        {
            // TODO Impl StartTurn
            Stage         = uparty;
            Sound.BossBGM = false;
            if (uparty == "味方")
            {
                do
                {
                    // 味方フェイズ
                    Stage = "味方";

                    // ターン数を進める
                    if (!Map.IsStatusView)
                    {
                        Turn      = Turn + 1;
                        TotalTurn = TotalTurn + 1;
                    }

                    // 状態回復
                    foreach (var currentUnit in UList.Items)
                    {
                        Commands.SelectedUnit = currentUnit;
                        switch (currentUnit.Status)
                        {
                        case "出撃":
                        case "格納":
                        {
                            if ((currentUnit.Party ?? "") == (uparty ?? ""))
                            {
                                if (Map.IsStatusView)
                                {
                                    currentUnit.UsedAction = 0;
                                }
                                else
                                {
                                    currentUnit.Rest();
                                }

                                if (IsScenarioFinished)
                                {
                                    GUI.UnlockGUI();
                                    return;
                                }
                            }
                            else
                            {
                                currentUnit.UsedAction = 0;
                            }

                            break;
                        }

                        case "旧主形態":
                        case "旧形態":
                        {
                            currentUnit.UsedAction = 0;
                            break;
                        }
                        }
                    }

                    // 味方が敵にかけたスペシャルパワーを解除
                    foreach (var currentU in UList.Items)
                    {
                        switch (currentU.Status)
                        {
                        case "出撃":
                        case "格納":
                        {
                            currentU.RemoveSpecialPowerInEffect("敵ターン");
                            break;
                        }
                        }
                    }

                    GUI.RedrawScreen();

                    // 味方フェイズ用BGMを演奏
                    if (!Map.IsStatusView)
                    {
                        var terrain = Map.Terrain(1, 1);
                        switch (terrain?.Class ?? "")
                        {
                        case "屋内":
                            Sound.StartBGM(Sound.BGMName("Map3"));
                            break;

                        case "宇宙":
                            Sound.StartBGM(Sound.BGMName("Map5"));
                            break;

                        default:
                            if (terrain?.Name == "壁")
                            {
                                Sound.StartBGM(Sound.BGMName("Map3"));
                            }
                            else
                            {
                                Sound.StartBGM(Sound.BGMName("Map1"));
                            }
                            break;
                        }
                    }

                    // ターンイベント
                    Event.IsUnitCenter = false;
                    Event.HandleEvent("ターン", Turn.ToString(), "味方");
                    if (IsScenarioFinished)
                    {
                        GUI.UnlockGUI();
                        return;
                    }

                    // 操作可能なユニットがいるかどうかチェック
                    if (UList.Items.Count(x => x.Party == "味方" && x.CanAction) > 0 ||
                        Expression.IsOptionDefined("味方フェイズ強制発動"))
                    {
                        break;
                    }

                    // CPUが操作するユニットがいるかどうかチェック
                    if (UList.Items.Count(x => x.Party != "味方" && x.Status == "出撃") > 0)
                    {
                        break;
                    }

                    // 敵フェイズ
                    StartTurn("敵");
                    if (IsScenarioFinished)
                    {
                        IsScenarioFinished = false;
                        return;
                    }

                    // 中立フェイズ
                    StartTurn("中立");
                    if (IsScenarioFinished)
                    {
                        IsScenarioFinished = false;
                        return;
                    }

                    // NPCフェイズ
                    StartTurn("NPC");
                    if (IsScenarioFinished)
                    {
                        IsScenarioFinished = false;
                        return;
                    }
                }while (true);
            }
            else
            {
                // 味方フェイズ以外

                // 状態回復
                foreach (var currentUnit in UList.Items)
                {
                    Commands.SelectedUnit = currentUnit;
                    switch (currentUnit.Status)
                    {
                    case "出撃":
                    case "格納":
                    {
                        if ((currentUnit.Party ?? "") == (uparty ?? ""))
                        {
                            currentUnit.Rest();
                            if (IsScenarioFinished)
                            {
                                GUI.UnlockGUI();
                                return;
                            }
                        }
                        else
                        {
                            currentUnit.UsedAction = 0;
                        }

                        break;
                    }

                    case "旧主形態":
                    case "旧形態":
                    {
                        currentUnit.UsedAction = 0;
                        break;
                    }
                    }
                }

                // 敵ユニットが味方にかけたスペシャルパワーを解除
                foreach (var currentUnit in UList.Items)
                {
                    switch (currentUnit.Status)
                    {
                    case "出撃":
                    case "格納":
                    {
                        currentUnit.RemoveSpecialPowerInEffect("敵ターン");
                        break;
                    }
                    }
                }

                GUI.RedrawScreen();

                // 敵(NPC)フェイズ用BGMを演奏
                var terrain = Map.Terrain(1, 1);
                if (Stage == "NPC")
                {
                    switch (terrain?.Class ?? "")
                    {
                    case "屋内":
                        Sound.StartBGM(Sound.BGMName("Map3"));
                        break;

                    case "宇宙":
                        Sound.StartBGM(Sound.BGMName("Map5"));
                        break;

                    default:
                        if (terrain?.Name == "壁")
                        {
                            Sound.StartBGM(Sound.BGMName("Map3"));
                        }
                        else
                        {
                            Sound.StartBGM(Sound.BGMName("Map1"));
                        }
                        break;
                    }
                }
                else
                {
                    switch (terrain?.Class ?? "")
                    {
                    case "屋内":
                        Sound.StartBGM(Sound.BGMName("Map4"));
                        break;

                    case "宇宙":
                        Sound.StartBGM(Sound.BGMName("Map6"));
                        break;

                    default:
                        if (terrain?.Name == "壁")
                        {
                            Sound.StartBGM(Sound.BGMName("Map4"));
                        }
                        else
                        {
                            Sound.StartBGM(Sound.BGMName("Map2"));
                        }
                        break;
                    }
                }

                // ターンイベント
                Event.HandleEvent("ターン", Turn.ToString(), uparty);
                if (IsScenarioFinished)
                {
                    GUI.UnlockGUI();
                    return;
                }
            }

            int  max_lv;
            Unit max_unit = null;

            if (uparty == "味方")
            {
                // 味方フェイズのプレイヤーによるユニット操作前の処理

                // ターン数を表示
                if (Turn > 1 && Expression.IsOptionDefined("デバッグ"))
                {
                    GUI.DisplayTelop("ターン" + SrcFormatter.Format(Turn));
                }

                // 通常のステージでは母艦ユニットまたはレベルがもっとも高い
                // ユニットを中央に配置
                if (!Map.IsStatusView && !Event.IsUnitCenter)
                {
                    foreach (Unit currentUnit in UList.Items)
                    {
                        if (currentUnit.Party == "味方" && currentUnit.Status == "出撃" && currentUnit.Action > 0)
                        {
                            if (currentUnit.IsFeatureAvailable("母艦"))
                            {
                                GUI.Center(currentUnit.x, currentUnit.y);
                                GUIStatus.DisplayUnitStatus(currentUnit);
                                GUI.RedrawScreen();
                                GUI.UnlockGUI();
                                return;
                            }
                        }
                    }

                    max_lv = 0;
                    foreach (Unit cuttentUnit in UList.Items)
                    {
                        if (cuttentUnit.Party == "味方" && cuttentUnit.Status == "出撃")
                        {
                            if (cuttentUnit.MainPilot().Level > max_lv)
                            {
                                max_unit = cuttentUnit;
                                max_lv   = cuttentUnit.MainPilot().Level;
                            }
                        }
                    }

                    if (max_unit != null)
                    {
                        GUI.Center(max_unit.x, max_unit.y);
                    }
                }

                // ステータスを表示
                if (!Map.IsStatusView)
                {
                    GUIStatus.DisplayGlobalStatus();
                }

                // プレイヤーによる味方ユニット操作に移行
                GUI.RedrawScreen();
                GUI.UnlockGUI();
                return;
            }

            GUI.LockGUI();

            CPUOperation(uparty);

            if (IsScenarioFinished)
            {
                return;
            }

            // ステータスウィンドウの表示を消去
            GUIStatus.ClearUnitStatus();
        }