void Awake() { if (GameObject.FindGameObjectsWithTag("UICtrl").Length > 1) { Destroy(gameObject); } else { shopCanvas = transform.Find("ShopCanvas").gameObject; RankCanvas = transform.Find("RankCanvas").gameObject; uiStateMachine = new UIStateMachine(); GameStartState gameStartState = new GameStartState(transform); uiStateMachine.AddState(gameStartState); GameSceneState gameSceneState = new GameSceneState(transform); uiStateMachine.AddState(gameSceneState); GameLoadingState gameLoadingState = new GameLoadingState(transform); uiStateMachine.AddState(gameLoadingState); uiStateMachine.ChangeState(typeof(GameLoadingState)); DontDestroyOnLoad(gameObject); } }
public static GameStartState GetInstance() { if (_instance == null) { _instance = new GameStartState(); } return(_instance); }
public void Init(GameStartState startState) { m_terrainView.Init(startState); foreach (var av in m_actors) { Destroy(av.Value.gameObject); } m_actors.Clear(); foreach (var a in startState.change.actors) { HandleActor(a); } }
public GameStartState GenerateStartState() { var state = new GameStartState() { config = config, change = new StateChange() { actors = m_actors, frame = frame, killedActors = new List <Actor>(), terrainChange = m_terrain.changeSinceStart } }; return(state); }
public void Init(GameStartState startState) { foreach (var v in m_activeViews.Values) { Destroy(v.gameObject); } m_activeViews.Clear(); m_size = startState.config.mapSize; m_terrain = new Terrain(startState.config); m_terrain.Generate(startState.config.seed); foreach (var change in startState.change.terrainChange) { ApplyChange(change); } }
public ConnectionStateMachine(MixedManager game) { _game = game; var startState = new GameStartState(this, _game); var connectingState = new GameConnectingState(this, _game); var connectedState = new GameConnectedState(this, _game); var disconnectedState = new GameDisconnectedState(this, _game); var roomState = new GameRoomState(this, _game); var stateList = new Dictionary <ConnectionFSMStateEnum.StateEnum, IFsmState> { { ConnectionFSMStateEnum.StateEnum.START, startState }, { ConnectionFSMStateEnum.StateEnum.CONNECTING, connectingState }, { ConnectionFSMStateEnum.StateEnum.CONNECTED, connectedState }, { ConnectionFSMStateEnum.StateEnum.DISCONNECTED, disconnectedState }, { ConnectionFSMStateEnum.StateEnum.ROOM, roomState }, }; SetStates(stateList); var allowedTransitions = new Dictionary <ConnectionFSMStateEnum.StateEnum, IList <ConnectionFSMStateEnum.StateEnum> >(); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.START, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.CONNECTING, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.CONNECTING, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.CONNECTED, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.CONNECTED, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.ROOM, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.DISCONNECTED, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.ROOM, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, }); SetTransitions(allowedTransitions); }
void Awake() { Instance = this; startState = new GameStartState(); globalState = new GlobalState(); mainState = new MainState(); fighterEnterState = new FighterEnterState(); fighterOverState = new FighterOverState(); fighting = new FightingState(); loginState = new LoginState(); startupAuditorState = new StartupAuditorState(); OpenGlobalState(); State = GameStateType.GameStartState; ChangeState(startState); }
public void Start() { StateGameStart = new GameStartState(this); StateIdle = new IdleState(this); StateBattle = new BattleState(this); StateGameOver = new GameOverState(this); ChangeState(StateGameStart); if (IsMainMenu) { return; } foreach (var member in CurrentPartyMembers) { CoreUIManager.Instance.AddPlayerBox(member.GetComponent <RPGActor>()); } }
private void StateMachine_OnTransition( StateMachine <GameRuleState, GameRuleStateTrigger> .Transition transition) { RoundTime = TimeSpan.Zero; try { switch (transition.Trigger) { case GameRuleStateTrigger.StartPrepare: Room.IsPreparing = true; foreach (var plr in Room.TeamManager.Players.Where(plr => plr.RoomInfo.IsReady || Room.Master == plr || plr.RoomInfo.Mode == PlayerGameMode.Spectate)) { plr.Session.SendAsync(new RoomGameLoadingAckMessage()); plr.Session.SendAsync(new RoomBeginRoundAckMessage()); plr.RoomInfo.State = PlayerState.Waiting; } PrepareState = GameStartState.Loading; Room.GameState = GameState.Loading; Room.Broadcast(new GameChangeStateAckMessage(Room.GameState)); return; } switch (transition.Destination) { case GameRuleState.FullGame: Room.HasStarted = true; Room.GameState = GameState.Playing; foreach (var team in Room.TeamManager.Values) { team.Score = 0; } foreach (var plr in Room.TeamManager.PlayersPlaying) { plr.Session.SendAsync(new RoomGameStartAckMessage()); plr.RoomInfo.State = plr.RoomInfo.Mode == PlayerGameMode.Spectate ? PlayerState.Spectating : PlayerState.Alive; } Room.Broadcast(new GameChangeStateAckMessage(Room.GameState)); break; case GameRuleState.FirstHalf: Room.HasStarted = true; Room.GameState = GameState.Playing; Room.SubGameState = GameTimeState.FirstHalf; UpdateTime(TimeSpan.FromMilliseconds(-5)); foreach (var team in Room.TeamManager.Values) { team.Score = 0; } foreach (var plr in Room.TeamManager.PlayersPlaying) { plr.Session.SendAsync(new RoomGameStartAckMessage()); plr.RoomInfo.State = plr.RoomInfo.Mode == PlayerGameMode.Spectate ? PlayerState.Spectating : PlayerState.Alive; } Room.Broadcast(new GameChangeStateAckMessage(Room.GameState)); break; case GameRuleState.HalfTime: foreach (var plr in Room.TeamManager.PlayersPlaying) { plr.RoomInfo.State = PlayerState.Waiting; } Room.SubGameState = GameTimeState.HalfTime; Room.Broadcast(new GameChangeSubStateAckMessage(Room.SubGameState)); break; case GameRuleState.SecondHalf: foreach (var plr in Room.TeamManager.PlayersPlaying) { plr.RoomInfo.State = plr.RoomInfo.Mode == PlayerGameMode.Spectate ? PlayerState.Spectating : PlayerState.Alive; } Room.SubGameState = GameTimeState.SecondHalf; Room.Broadcast(new GameChangeSubStateAckMessage(Room.SubGameState)); break; case GameRuleState.Result: foreach (var plr in Room.TeamManager.Players.Where(plr => plr.RoomInfo.State != PlayerState.Lobby)) { plr.RoomInfo.State = PlayerState.Waiting; } var winners = new List <Player>(); foreach (var plr in Room.GameRuleManager.GameRule.Briefing.GetWinnerTeam().Keys) { if (CountMatch) { plr.stats.Won++; } winners.Add(plr); } if (CountMatch) { foreach (Player item7 in Room.TeamManager.PlayersPlaying) { if (!winners.Contains(item7)) { item7.stats.Loss++; } foreach (Character item8 in item7.CharacterManager) { int loss = (int)(item7.RoomInfo.CharacterPlayTime[item8.Slot].TotalMinutes * (double)Config.Instance.Game.DurabilityLossPerMinute + (double)(item7.RoomInfo.Stats.Deaths * Config.Instance.Game.DurabilityLossPerDeath)); item8.CharacterManager.DecreaseDurability(loss); } MPFill(item7); } } Room.HasStarted = false; Room.GameState = GameState.Result; Room.SubGameState = GameTimeState.None; Room.Broadcast(new GameChangeStateAckMessage(Room.GameState)); Room.BroadcastBriefing(true); break; case GameRuleState.Waiting: foreach (var team in Room.TeamManager.Values) { team.Score = 0; } foreach (var plr in Room.TeamManager.Players) { plr.RoomInfo.Reset(); plr.RoomInfo.State = PlayerState.Lobby; OnRoomJoinCompleted(plr); } Reload(); Room.HasStarted = false; Room.GameState = GameState.Waiting; Room.SubGameState = GameTimeState.None; Room.Broadcast(new GameChangeStateAckMessage(Room.GameState)); PrepareState = GameStartState.Waiting; Room.BroadcastBriefing(); break; } } catch (Exception e) { Logger.Error(e.ToString()); } }
public virtual void Update(AccurateDelta delta) { RoundTime += delta.delta; Room.RoundTime = RoundTime; #region PrepareGame if (StateMachine.IsInState(GameRuleState.Preparing)) { switch (PrepareState) { case GameStartState.Loading: if (Room.RoundTime > GameLoadMaxTime) { foreach (var player in Room.Players.Values.Where(x => (x.RoomInfo.IsReady || Room.Master == x) && !x.RoomInfo.HasLoaded)) { player.RoomInfo.IsReady = false; player.Room?.Leave(player); } } if (Room.Players.Values.Count(x => x.RoomInfo.HasLoaded) >= Room.Players.Values.Count(x => x.RoomInfo.IsReady || Room.Master == x) || Room.RoundTime > GameLoadMaxTime) { GameStartTime = Room.RoundTime; if (GameRule == GameRule.Chaser || GameRule == GameRule.Practice || GameRule == GameRule.CombatTrainingDM || GameRule == GameRule.CombatTrainingTD) { PrepareState = GameStartState.ReadyToStart; } else { PrepareState = GameStartState.Countdown; foreach (var member in Room.Players.Values) { if (member.RoomInfo.HasLoaded) { member.Session.SendAsync( new RoomGamePlayCountDownAckMessage( (int)GameStartWaitTime.TotalMilliseconds)); member.Session.SendAsync(new GameRefreshGameRuleInfoAckMessage(Room.GameState, GameTimeState.StartGameCounter, Room.Options.TimeLimit.TotalMilliseconds)); } } } } break; case GameStartState.Countdown: if ((Room.RoundTime - GameStartTime).TotalMilliseconds > GameStartWaitTime.TotalMilliseconds + 500) { PrepareState = GameStartState.ReadyToStart; } break; case GameStartState.ReadyToStart: if (StateMachine.CanFire(GameRuleStateTrigger.StartGame)) { Room.IsPreparing = false; RoundTime = TimeSpan.Zero; PrepareState = GameStartState.Playing; StateMachine.Fire(GameRuleStateTrigger.StartGame); } break; } } #endregion #region Playing if (StateMachine.IsInState(GameRuleState.Playing)) { foreach (var plr in Room.TeamManager.PlayersPlaying) { plr.RoomInfo.PlayTime += delta.delta; plr.RoomInfo.CharacterPlayTime[plr.CharacterManager.CurrentSlot] += delta.delta; } } #endregion #region HalfTime if (StateMachine.IsInState(GameRuleState.EnteringHalfTime)) { if (RoundTime >= PreHalfTimeWaitTime) { if (StateMachine.CanFire(GameRuleStateTrigger.StartHalfTime)) { RoundTime = TimeSpan.Zero; StateMachine.Fire(GameRuleStateTrigger.StartHalfTime); } } else { foreach (var plr in Room.TeamManager.PlayersPlaying) { var message = ((int)(PreHalfTimeWaitTime - RoundTime).TotalSeconds + 1).ToString(); plr.Session.SendAsync(new GameEventMessageAckMessage(GameEventMessage.HalfTimeIn, 2, 0, 0, message)); } } } if (StateMachine.IsInState(GameRuleState.HalfTime) && RoundTime >= HalfTimeWaitTime) { StateMachine.Fire(GameRuleStateTrigger.StartSecondHalf); } #endregion #region Result if (StateMachine.IsInState(GameRuleState.EnteringResult)) { if (RoundTime >= PreResultWaitTime) { RoundTime = TimeSpan.Zero; StateMachine.Fire(GameRuleStateTrigger.StartResult); } else { foreach (var plr in Room.TeamManager.PlayersPlaying) { var message = (int)(PreResultWaitTime - RoundTime).TotalSeconds + 1 + " second(s)"; plr.Session?.SendAsync(new GameEventMessageAckMessage(GameEventMessage.ResultIn, 3, 0, 0, message)); } } } if (StateMachine.IsInState(GameRuleState.Result) && RoundTime >= ResultWaitTime) { if (StateMachine.CanFire(GameRuleStateTrigger.EndGame)) { RoundTime = TimeSpan.Zero; StateMachine.Fire(GameRuleStateTrigger.EndGame); } } #endregion #region CoinBuff if (this.StateMachine.IsInState(GameRuleState.Playing)) { foreach (var plr in this.Room.TeamManager.PlayersPlaying) { plr.PlayerCoinBuff.Update(1); } } #endregion }
public ConnectionStateMachine(ClientManager game) { _game = game; var startState = new GameStartState(this, _game); var playFabLoginState = new GamePlayFabLoginState(this, _game); var playFabRegisterState = new GamePlayFabRegisterState(this, _game); var connectingState = new GameConnectingState(this, _game); var connectedState = new GameConnectedState(this, _game); var disconnectedState = new GameDisconnectedState(this, _game); var resultState = new GameResultState(this, _game); var playingState = new GamePlayingState(this, _game); var stateList = new Dictionary <ConnectionFSMStateEnum.StateEnum, IFsmState> { { ConnectionFSMStateEnum.StateEnum.START, startState }, { ConnectionFSMStateEnum.StateEnum.PLAYFAB_LOGIN, playFabLoginState }, { ConnectionFSMStateEnum.StateEnum.PLAYFAB_REGISTER, playFabRegisterState }, { ConnectionFSMStateEnum.StateEnum.CONNECTING, connectingState }, { ConnectionFSMStateEnum.StateEnum.CONNECTED, connectedState }, { ConnectionFSMStateEnum.StateEnum.DISCONNECTED, disconnectedState }, { ConnectionFSMStateEnum.StateEnum.RESULT, resultState }, { ConnectionFSMStateEnum.StateEnum.PLAYING, playingState }, }; SetStates(stateList); var allowedTransitions = new Dictionary <ConnectionFSMStateEnum.StateEnum, IList <ConnectionFSMStateEnum.StateEnum> >(); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.START, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.PLAYFAB_LOGIN, ConnectionFSMStateEnum.StateEnum.PLAYFAB_REGISTER, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.PLAYFAB_LOGIN, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, ConnectionFSMStateEnum.StateEnum.CONNECTING, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.PLAYFAB_REGISTER, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, ConnectionFSMStateEnum.StateEnum.CONNECTING, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.CONNECTING, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.CONNECTED, ConnectionFSMStateEnum.StateEnum.DISCONNECTED, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.CONNECTED, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.PLAYING, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.DISCONNECTED, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.RESULT, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.PLAYING, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, }); SetTransitions(allowedTransitions); }