示例#1
0
    /// <summary>
    /// 新比赛开始
    /// 重设场景,比分清空,裁判历史数据清空
    /// </summary>
    public void StartMatch()
    {
        StartedMatch = false;

        ObjectManager.SetDefaultPostion();
        GlobalMatchInfo.Score    = new MatchScore();
        GlobalMatchInfo.PlayTime = 0;
        GlobalMatchInfo.Referee  = new Referee();

        StrategyManager.CheckReady_ex();
        StrategyManager.BeginBlue(GlobalMatchInfo);
        StrategyManager.BeginYellow(GlobalMatchInfo);

        StartedMatch = true;
        Event.Send(Event.EventType0.MatchStart);
    }
示例#2
0
    void UpdatePlacementToScene()
    {
        PlacementInfo blueInfo   = StrategyManager.PlacementBlue(GlobalMatchInfo);
        PlacementInfo yellowInfo = StrategyManager.PlacementYellow(GlobalMatchInfo);

        ObjectManager.SetBluePlacement(blueInfo);
        ObjectManager.SetYellowPlacement(yellowInfo);

        if (GlobalMatchInfo.WhosBall == 0)                        // 先摆后摆另考虑
        {
            ObjectManager.SetBallPlacement(blueInfo);
        }
        else
        {
            ObjectManager.SetBallPlacement(yellowInfo);
        }

        Event.Send(Event.EventType1.MatchInfoUpdate, GlobalMatchInfo);
    }
示例#3
0
    public void InRoundLoop()
    {
        if (PausedRound)
        {
            return;
        }

        try
        {
            // 检查策略
            StrategyManager.CheckBlueReady_ex();
            StrategyManager.CheckYellowReady_ex();

            // 广播信息
            Event.Send(Event.EventType1.MatchInfoUpdate, GlobalMatchInfo);

            // 裁判判断
            if (GlobalMatchInfo.Referee.Judge(GlobalMatchInfo))
            {
                InRound                 = false;
                InPlacement             = true;
                GlobalMatchInfo.Referee = new Referee();
                Event.Send(Event.EventType1.LogUpdate, "Foul : " + GlobalMatchInfo.GameState.ToString() + ". Blue team is" + ((Simuro5v5.Side)GlobalMatchInfo.WhosBall).ToString());
            }
            else
            {
                UpdateWheelsToScene();
                GlobalMatchInfo.PlayTime++;
            }
        }
        catch (Exception)
        {
            StopMatch();
            throw;
        }
    }
示例#4
0
    /// <summary>
    /// 维护比赛状态,根据裁判的判定结果执行不同的动作。<br/>
    /// 完整的一拍有三个步骤:
    /// 时间递增、更新输入(轮速或摆位)---> 物理引擎运行 ---> 触发事件。<br/>
    /// 这个函数会在每次“物理引擎运行”结束被调用,因此,一是需要处理上一拍的运行结果,二是作下一拍(本拍)的准备。<br/>
    /// </summary>
    public void InMatchLoop()
    {
        if (ManualPlacing)
        {
            throw new InvalidOperationException("manual placing");
        }
        if (!LoadSucceed || !Started || Paused)
        {
            return;
        }

        // 触发事件,作为上一拍的结束
        // 如果现在是阶段的第一拍,上一拍无意义,不用触发事件
        if (GlobalMatchInfo.TickPhase != 0)
        {
            Event.Send(Event.EventType1.MatchInfoUpdate, GlobalMatchInfo);
        }
        else
        {
            // 在第一拍做初始化
            placementCount    = 0;
            callbackCount     = 0;
            lastPlacementId   = 0;
            placementToIgnore = new Queue <int>();
        }

        /* 之前处理上一拍 */
        /* 之后为本拍做准备 */

        // 从裁判中获取下一拍的动作。
        JudgeResult judgeResult = GlobalMatchInfo.Referee.Judge(GlobalMatchInfo);

        // 时间加一
        GlobalMatchInfo.TickMatch++;
        GlobalMatchInfo.TickPhase++;

        switch (judgeResult.ResultType)
        {
        // 执行动作,更新输入
        case ResultType.GameOver:
            // 整场比赛结束

            // 可能最后一拍正好进球,需要判断
            switch (judgeResult.WhoGoal)
            {
            case Side.Blue:
                GlobalMatchInfo.Score.BlueScore++;
                break;

            case Side.Yellow:
                GlobalMatchInfo.Score.YellowScore++;
                break;
            }

            StopMatch();
            break;

        case ResultType.NextPhase:
            // 阶段结束
            // 这之后的物理引擎运行的一拍无意义,不用触发MatchInfoUpdate事件
            if (GlobalMatchInfo.MatchPhase == MatchPhase.FirstHalf)
            {
                SwitchRole();
            }

            GlobalMatchInfo.MatchPhase = GlobalMatchInfo.MatchPhase.NextPhase();
            GlobalMatchInfo.TickPhase  = 0;    // 时间指定为0,使得下一拍的裁判得知新阶段的开始
            OnNextPhase();
            // 通知策略
            switch (GlobalMatchInfo.MatchPhase)
            {
            case MatchPhase.FirstHalf:
                break;

            case MatchPhase.SecondHalf:
                StrategyManager.Blue.OnSecondHalfStart();
                StrategyManager.Yellow.OnSecondHalfStart();
                break;

            case MatchPhase.OverTime:
                StrategyManager.Blue.OnOvertimeStart();
                StrategyManager.Yellow.OnOvertimeStart();
                break;

            case MatchPhase.Penalty:
                StrategyManager.Blue.OnPenaltyShootoutHalfStart();
                StrategyManager.Yellow.OnPenaltyShootoutHalfStart();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            break;

        case ResultType.NormalMatch:
            // 正常比赛,输入轮速
            UpdateWheelsToScene();
            break;

        default:
            // 判断是否进球
            switch (judgeResult.WhoGoal)
            {
            case Side.Blue:
                GlobalMatchInfo.Score.BlueScore++;
                break;

            case Side.Yellow:
                GlobalMatchInfo.Score.YellowScore++;
                break;
            }


            // 手动摆位
            if (manualPlaceEnabled)
            {
                BroadcastJudgeResult(judgeResult);
                BeginManualPlace();
            }
            else
            {
                void Callback()
                {
                    #region Patch to placement

                    int callbackId = callbackCount;
                    callbackCount++;
                    if (callbackId == lastPlacementId)
                    {
                        lastPlacementId = 0;
                    }
                    else
                    {
                        Debug.Assert(placementToIgnore.Peek() == callbackId);
                        placementToIgnore.Dequeue();
                        return;
                    }

                    #endregion

                    BroadcastJudgeResult(judgeResult);
                    //Debug.Log($"callback placement {callbackId}");
                    UpdatePlacementToScene(judgeResult);
                    ObjectManager.SetStill();
                    Event.Send(Event.EventType1.AutoPlacement, GlobalMatchInfo);
                }

                #region Patch to placement

                int placementId = placementCount;
                placementCount++;
                if (lastPlacementId == 0)
                {
                    lastPlacementId = placementId;
                }
                else
                {
                    placementToIgnore.Enqueue(placementId);
                }

                #endregion

                if (GlobalMatchInfo.TickMatch > 1)
                {
                    //Debug.Log($"Will stop at {GlobalMatchInfo.TickMatch} {placementId}");
                    PauseForSeconds(2, Callback);
                }
                else
                {
                    Callback();
                }
            }

            break;
        }
    }
示例#5
0
 public void LoadReplayScene()
 {
     GUI_Replay.Recorder = recorder;
     Event.Send(Event.EventType0.PlaySceneExited);
     SceneManager.LoadScene("GameScene_Replay");
 }
示例#6
0
    // 以下为在编辑器中绑定的函数

    public void LoadMainScene()
    {
        Event.Send(Event.EventType0.PlaySceneExited);
        SceneManager.LoadScene("MainScene");
    }
示例#7
0
    /// <summary>
    /// 维护比赛状态,根据裁判的判定结果执行不同的动作。<br>
    /// 完整的一拍有三个步骤:
    /// 时间递增、更新输入(轮速或摆位)---> 物理引擎运行 ---> 触发事件。<br>
    /// 这个函数会在每次“物理引擎运行”结束被调用,因此,一是需要处理上一拍的运行结果,二是作下一拍(本拍)的准备。<br>
    /// </summary>
    public void InMatchLoop()
    {
        if (ManualPlacing)
        {
            throw new InvalidOperationException("manual placing");
        }
        if (!LoadSucceed || !Started || Paused)
        {
            return;
        }

        // 触发事件,作为上一拍的结束
        // 如果现在是阶段的第一拍,上一拍无意义,不用触发事件
        if (GlobalMatchInfo.TickPhase != 0)
        {
            Event.Send(Event.EventType1.MatchInfoUpdate, GlobalMatchInfo);
        }

        /* 之前处理上一拍 */
        /* 之后为本拍做准备 */

        // 从裁判中获取下一拍的动作。
        JudgeResult judgeResult = GlobalMatchInfo.Referee.Judge(GlobalMatchInfo);

        // 时间加一
        GlobalMatchInfo.TickMatch++;
        GlobalMatchInfo.TickPhase++;

        // 执行动作,更新输入
        if (judgeResult.ResultType == ResultType.GameOver)
        {
            // 整场比赛结束
            Debug.Log("Game Over");

            // 判断是否进球
            switch (judgeResult.WhoGoal)
            {
            case Side.Blue:
                GlobalMatchInfo.Score.BlueScore++;
                break;

            case Side.Yellow:
                GlobalMatchInfo.Score.YellowScore++;
                break;
            }

            StopMatch();
        }
        else if (judgeResult.ResultType == ResultType.NextPhase)
        {
            // 阶段结束
            // 这之后的物理引擎运行的一拍无意义,不用触发事件
            Debug.Log("next phase");
            if (GlobalMatchInfo.MatchPhase == MatchPhase.FirstHalf)
            {
                Debug.Log("switch role");
                SwitchRole();
            }
            GlobalMatchInfo.MatchPhase = GlobalMatchInfo.MatchPhase.NextPhase();
            GlobalMatchInfo.TickPhase  = 0;     // 时间指定为0,使得下一拍的裁判得知新阶段的开始
            OnNextPhase();
        }
        else if (judgeResult.ResultType == ResultType.NormalMatch)
        {
            // 正常比赛,输入轮速
            UpdateWheelsToScene();
        }
        else
        {
            // 摆位,输入摆位信息
            Debug.Log("placing...");

            // 判断是否进球
            switch (judgeResult.WhoGoal)
            {
            case Side.Blue:
                GlobalMatchInfo.Score.BlueScore++;
                break;

            case Side.Yellow:
                GlobalMatchInfo.Score.YellowScore++;
                break;
            }

            StrategyManager.Blue.OnJudgeResult(judgeResult);
            StrategyManager.Yellow.OnJudgeResult(new JudgeResult
            {
                Actor      = judgeResult.Actor.ToAnother(),
                ResultType = judgeResult.ResultType,
                Reason     = judgeResult.Reason
            });

            // 手动摆位
            if (manualPlaceEnabled)
            {
                Debug.Log("manual placing");
                BeginManualPlace();
            }
            else
            {
                Debug.Log("auto placing");

                void Callback()
                {
                    UpdatePlacementToScene(judgeResult);
                    ObjectManager.SetStill();
                    Event.Send(Event.EventType1.AutoPlacement, GlobalMatchInfo);

                    PauseForSeconds(2, () => { });
                }

                // TODO 考虑连续出现摆位的情况
                if (GlobalMatchInfo.TickMatch > 1)
                {
                    PauseForSeconds(2, Callback);
                }
                else
                {
                    Callback();
                }
            }
        }
    }