private void Update() { switch (nowState) { case BattleSceneState.BATTLE_START: OnBattleStart?.Invoke(this, EventArgs.Empty); nowState = BattleSceneState.PLAYER_TURN_START; OnPlayerTurnStart?.Invoke(this, EventArgs.Empty); break; case BattleSceneState.PLAYER_TURN_START: if (!BattleEventManager.Instance.Execute()) { nowState = BattleSceneState.PLAYER_TURN_UPDATE; } break; case BattleSceneState.PLAYER_TURN_UPDATE: break; case BattleSceneState.PLAYER_TURN_END: if (!BattleEventManager.Instance.Execute()) { nowState = BattleSceneState.ENEMY_TURN_START; OnEnemyTurnStart?.Invoke(this, EventArgs.Empty); } break; case BattleSceneState.ENEMY_TURN_START: if (!BattleEventManager.Instance.Execute()) { nowState = BattleSceneState.ENEMY_TURN_UPDATE; } break; case BattleSceneState.ENEMY_TURN_UPDATE: if (!BattleEventManager.Instance.Execute()) { nowState = BattleSceneState.ENEMY_TURN_END; OnEnemyTurnEnd?.Invoke(this, EventArgs.Empty); } break; case BattleSceneState.ENEMY_TURN_END: if (!BattleEventManager.Instance.Execute()) { nowState = BattleSceneState.PLAYER_TURN_START; OnPlayerTurnStart?.Invoke(this, EventArgs.Empty); } break; case BattleSceneState.BATTLE_END: break; } }
public void ExecuteTurn() { if (currentState == State.END) { return; } // Don't do anything if battle is over if (currentState == State.START) { //Add effects of all Pokemon Abilities in battle foreach (Team team in Teams) { foreach (Slot slot in team) { RegisterEffect(slot.Pokemon.Ability.newEffect(this, slot.Pokemon)); } } OnBattleStart?.Invoke(this, BattleArgs); currentState = State.IN_PROGRESS; } OnTurnStart?.Invoke(this, BattleArgs); /* First we enqueue BattleActionRequests for all battle slots that are still in play. The * purpose of this is to allow move effects to trigger based on the enqueue'ing of the * BattleActionRequests. This allows effects from moves like Taunt modify which battlers * we make BattleActionRequests for. */ foreach (Team team in Teams) { foreach (Slot slot in team) { if (slot.IsInPlay) { MessageQueue.Enqueue(new Request(slot)); } } } actionRequests.Clear(); Flush(); RequestInputEventArgs requestInputEventArgs = new RequestInputEventArgs(this, actionRequests); OnRequestInput?.Invoke(this, requestInputEventArgs); List <IAction> actions = new List <IAction>(InputProvider.ProvideActions(this, actionRequests)); InputReceivedEventArgs inputReceivedEventArgs = new InputReceivedEventArgs(this, actionRequests, actions); OnInputReceived?.Invoke(this, inputReceivedEventArgs); actions.Sort(ActionComparer); foreach (IAction action in actions) { MessageQueue.Enqueue(action); } while (true) { Flush(); List <Request> requests = new List <Request>(); foreach (Team team in Teams) { foreach (Slot slot in team) { if (slot.Pokemon.HasFainted() && !slot.Participant.HasLost()) { requests.Add(new Request(slot)); } } } if (requests.Count == 0) { break; } IList <SwapPokemon> swapPokemonActions = InputProvider.ProvideSwapPokemon(this, requests); foreach (SwapPokemon swapPokemonAction in swapPokemonActions) { MessageQueue.Enqueue(swapPokemonAction); } } CurrentWeather.DecrementTurnCounter(); if (CurrentWeather.IsComplete) { WeatherCompletedEventArgs weatherCompletedEventArgs = new WeatherCompletedEventArgs(this, CurrentWeather); OnWeatherCompleted?.Invoke(this, weatherCompletedEventArgs); MessageQueue.AddFirst(new WeatherChange(SurroundingWeather, -1)); Broadcast(); } OnTurnEnd?.Invoke(this, BattleArgs); /* * Why is this loop run after OnTurnEnd is called? * We need to be able to process events that occur just before the end of the turn. */ while (true) { Flush(); List <Request> requests = new List <Request>(); foreach (Team team in Teams) { foreach (Slot slot in team) { if (slot.Pokemon.HasFainted() && !slot.Participant.HasLost()) { requests.Add(new Request(slot)); } } } if (requests.Count == 0) { break; } IList <SwapPokemon> swapPokemonActions = InputProvider.ProvideSwapPokemon(this, requests); foreach (SwapPokemon swapPokemonAction in swapPokemonActions) { MessageQueue.Enqueue(swapPokemonAction); } } if (this.IsComplete()) { BattleEndEventArgs battleEndEventArgs = new BattleEndEventArgs(this, this.Winner()); OnBattleEnd?.Invoke(this, battleEndEventArgs); currentState = State.END; } TurnCounter += 1; }
public void OnJoinedRoom() { OnFinishFinalize = null; OnFinishFinalize += () => { _resultHudController.gameObject.SetActive(false); PhotonNetwork.LeaveRoom(); }; OnChangeGameSequence = null; OnChangeGameSequence += (GameSequence newGameSequence) => { switch (newGameSequence) { case GameSequence.GameStart: LocalInitialize(); break; case GameSequence.Battle: // RPC通信による初期化はプレイヤーが揃ってから行う _playerBarController.RpcRename(newObjName: $"Player{_playerIndex}Bar"); _playerController.RpcRename(newObjName: $"Player{_playerIndex}Controller"); _playerController.RpcInitialize( myBar: _playerBarController , myGoal: _playerGoalList[_playerIndex], playerId: _playerIndex); _playerController.OnAddPoint += currentPoint => { _ballController.RpcEnableCollision(false); _ballController.RpcSetCanMove(false); if (currentPoint >= _winRequiredVictoryNum) { OnGameEnd?.Invoke(); } RpcApplyPlayerPointHudText(point: currentPoint, playerId: _playerIndex); }; RpcApplyPlayerPointHudText(point: 0, playerId: _playerController.PlayerId); _ballController.LocalInitialize(); OnBattleStart?.Invoke(); break; case GameSequence.GameEnd: Debug.Log("Game End"); _ballController.RpcSetCanMove(false); break; } }; Room room = PhotonNetwork.room; _playerIndex = room.PlayerCount - 1; if (room.PlayerCount == room.MaxPlayers) { var cp = room.CustomProperties; cp["WaitPlayer"] = false; room.SetCustomProperties(cp); } LocalShowResultHud(false); LocalSetGameSequence((int)GameSequence.GameStart); }