Пример #1
0
        private void CmdSelectAbilityRequest(ActorController actorController, int actionTypeInt)
        {
            ActorData actor = actorController.gameObject.GetComponent <ActorData>();

            AbilityData.ActionType actionType = (AbilityData.ActionType)actionTypeInt;

            if (!GameFlowData.Get().IsInDecisionState())
            {
                Log.Info($"Recieved CmdSelectAbilityRequest not in desicion state! {actor.DisplayName} {actionType}");
                return;
            }

            Log.Info($"CmdSelectAbilityRequest {actor.DisplayName} {actionType}");

            if (!actor.QueuedMovementAllowsAbility &&
                actor.GetAbilityData().GetAbilityOfActionType(actionType).GetMovementAdjustment() != Ability.MovementAdjustment.FullMovement)
            {
                Log.Info($"CmdSelectAbilityRequest - Clearing movement for {actor.DisplayName}");
                ArtemisServerMovementManager.Get().ClearMovementRequest(actor, true);
            }

            AbilityData abilityData = actor.gameObject.GetComponent <AbilityData>();

            abilityData.Networkm_selectedActionForTargeting = actionType;
            SetAbilityRequest(actor, actionType, null);
        }
Пример #2
0
        private void PlaceCharacters()
        {
            // TODO
            Log.Info("Placing characters");
            int x = 16;
            int y = 9;

            foreach (var player in GameFlowData.Get().GetPlayers())
            {
                //UnityUtils.DumpGameObject(player);

                ActorData actorData = player.GetComponent <ActorData>();
                var       atsd      = actorData.TeamSensitiveData_authority;
                if (atsd == null)
                {
                    continue;
                }

                BoardSquare start     = Board.Get().GetSquare(x++, y);
                GridPosProp startProp = GridPosProp.FromGridPos(start.GetGridPosition());

                atsd.CallRpcMovement(GameEventManager.EventType.Invalid,
                                     startProp, startProp,
                                     null, ActorData.MovementType.Teleport, false, false);

                actorData.ServerLastKnownPosSquare = start;
                actorData.InitialMoveStartSquare   = start;
                actorData.MoveFromBoardSquare      = start;
                Log.Info($"Placing {actorData.DisplayName} at {startProp.m_x}, {startProp.m_y}");  // PATCH internal -> public ActorData.DisplayName
            }
            Log.Info("Done placing characters");
        }
Пример #3
0
        private IEnumerator ActionResolution()
        {
            foreach (ActorData actor in GameFlowData.Get().GetActors())
            {
                var turnSm = actor.gameObject.GetComponent <ActorTurnSM>();
                turnSm.CallRpcTurnMessage((int)TurnMessage.BEGIN_RESOLVE, 0);
            }
            yield return(0);

            Artemis.ArtemisServer.Get().SharedActionBuffer.Networkm_actionPhase = ActionBufferPhase.Abilities;
            GameFlowData.Get().gameState = GameState.BothTeams_Resolve;
            // TODO update ATSDs on a separate tick
            yield return(new WaitForSeconds(1));

            bool hasNextPhase = true;

            while (hasNextPhase)
            {
                hasNextPhase = ArtemisServerResolutionManager.Get().ResolveNextPhase();
                yield return(ArtemisServerResolutionManager.Get().WaitForTheatrics());
            }
            yield return(new WaitForSeconds(1));

            foreach (ActorData actor in GameFlowData.Get().GetActors())
            {
                var turnSm = actor.gameObject.GetComponent <ActorTurnSM>();
                turnSm.CallRpcTurnMessage((int)TurnMessage.CLIENTS_RESOLVED_ABILITIES, 0);
            }
        }
Пример #4
0
        private void CmdGUITurnMessage(ActorTurnSM actorTurnSM, int msgEnum, int extraData)
        {
            ActorData   actor = actorTurnSM.gameObject.GetComponent <ActorData>();
            TurnMessage msg   = (TurnMessage)msgEnum;

            if (!GameFlowData.Get().IsInDecisionState())
            {
                Log.Info($"Recieved CmdGuiTurnMessage not in desicion state! {actor.DisplayName} {msg} ({extraData})");
                return;
            }

            Log.Info($"CmdGuiTurnMessage {actor.DisplayName} {msg} ({extraData})");
            if (msg == TurnMessage.CANCEL_BUTTON_CLICKED)
            {
                // TODO distinguish CANCEL button and ability cancelling
                // actor.TeamSensitiveData_authority.SetToggledAction(actionType, false);
                // if (DONE) make undone
                // else if (targeting action) set toggled action(false)
                actorTurnSM.CallRpcTurnMessage((int)TurnMessage.CANCEL_BUTTON_CLICKED, 0);
            }
            else if (msg == TurnMessage.DONE_BUTTON_CLICKED)
            {
                actorTurnSM.CallRpcTurnMessage((int)TurnMessage.DONE_BUTTON_CLICKED, 0);
            }
            // TODO: Timebanks. Notice that client sends CANCEL msg when selecting ability after confirmed
            // (but we still should have a fallback if it doesn't) but doesn't send one when updating movement.
        }
Пример #5
0
        private IEnumerator MovementResolution()
        {
            Artemis.ArtemisServer.Get().SharedActionBuffer.Networkm_actionPhase = ActionBufferPhase.Movement;

            ArtemisServerMovementManager.Get().ResolveMovement();
            yield return(new WaitForSeconds(6)); // TODO ActorMovement.CalculateMoveTimeout() -- do we need some server version of ProcessMovement?

            foreach (ActorData actor in GameFlowData.Get().GetActors())
            {
                var turnSm = actor.gameObject.GetComponent <ActorTurnSM>();

                //ArtemisServerMovementManager.Get().UpdatePlayerMovement(actor, false);
                turnSm.CallRpcTurnMessage((int)TurnMessage.MOVEMENT_RESOLVED, 0);
                //actor.GetActorMovement().UpdateSquaresCanMoveTo();
            }

            // TODO repeat all of the above for movement_chase
            yield return(null);

            Artemis.ArtemisServer.Get().SharedActionBuffer.Networkm_actionPhase = ActionBufferPhase.MovementChase;
            // ....
            yield return(null);

            Artemis.ArtemisServer.Get().SharedActionBuffer.Networkm_actionPhase = ActionBufferPhase.MovementWait;
            yield return(null);

            Artemis.ArtemisServer.Get().SharedActionBuffer.Networkm_actionPhase = ActionBufferPhase.Done;
        }
Пример #6
0
        private IEnumerator TurnDecision()
        {
            GameFlowData.Get().gameState = GameState.BothTeams_Decision;
            // TODO timebanks
            GameFlowData.Get().Networkm_willEnterTimebankMode           = false;
            GameFlowData.Get().Networkm_timeRemainingInDecisionOverflow = 0;

            foreach (ActorData actor in GameFlowData.Get().GetActors())
            {
                var turnSm = actor.gameObject.GetComponent <ActorTurnSM>();
                ArtemisServerGameManager.Get().ClearAbilityRequests(actor);
                actor.AppearAtBoardSquare(actor.TeamSensitiveData_authority.MoveFromBoardSquare);
                ArtemisServerMovementManager.Get().ClearMovementRequest(actor, true);
                turnSm.CallRpcTurnMessage((int)TurnMessage.TURN_START, 0);
            }
            ArtemisServerMovementManager.Get().UpdateTurn();
            ArtemisServerBarrierManager.Get().UpdateTurn();
            SharedEffectBarrierManager.Get().UpdateTurn();

            Log.Info("TurnDecision");

            while (GameFlowData.Get().GetTimeRemainingInDecision() > 0)
            {
                Log.Info($"Time remaining: {GameFlowData.Get().GetTimeRemainingInDecision()}");

                GameFlowData.Get().CallRpcUpdateTimeRemaining(GameFlowData.Get().GetTimeRemainingInDecision());
                yield return(new WaitForSeconds(2));
            }
        }
Пример #7
0
        private IEnumerator EndTurn()
        {
            GameFlowData.Get().gameState = GameState.EndingTurn;
            ArtemisServerResolutionManager.Get().ApplyActions();

            // Update statuses
            foreach (ActorData actor in GameFlowData.Get().GetActors())
            {
                var actorStatus = actor.GetActorStatus();
                for (StatusType status = 0; status < StatusType.NUM; status++)
                {
                    if (actorStatus.HasStatus(status))
                    {
                        int duration = Math.Max(0, actorStatus.GetDurationOfStatus(status) - 1);
                        actorStatus.UpdateStatusDuration(status, duration);
                        if (duration == 0)
                        {
                            do
                            {
                                actorStatus.RemoveStatus(status);
                            } while (actorStatus.HasStatus(status));
                            Log.Info($"{actor.DisplayName}'s {status} status has expired.");
                        }
                    }
                }
            }
            yield return(null);
        }
 private void SendToAll(short msgType, MessageBase msg)
 {
     foreach (ActorData actor in GameFlowData.Get().GetActors())
     {
         //if (!actor.GetPlayerDetails().IsHumanControlled) { continue; }
         actor.connectionToClient?.Send(msgType, msg);
     }
 }
        public void OnClientResolutionPhaseCompleted(NetworkConnection conn, GameMessageManager.ClientResolutionPhaseCompleted msg)
        {
            Player    player = GameFlow.Get().GetPlayerFromConnectionId(conn.connectionId);
            ActorData actor  = GameFlowData.Get().FindActorByActorIndex(msg.ActorIndex);

            if (actor.gameObject.GetComponent <PlayerData>().m_player.m_connectionId != conn.connectionId)
            {
                Log.Warning($"OnClientResolutionPhaseCompleted: {actor.DisplayName} does not belong to player {player.m_accountId}!");
            }

            TheatricsPendingClients.Remove(player.m_accountId);
        }
Пример #10
0
        private IEnumerator PrepareForGame()
        {
            Log.Info("Preparing for game");

            //GameFlowData.Get().enabled = true;
            GameFlowData.Get().gameState = GameState.Deployment;
            yield return(new WaitForSeconds(5));

            GameFlow.Get().CallRpcSetMatchTime(0);
            GameFlowData.Get().Networkm_currentTurn = 0;
            Log.Info("Done preparing for game");
        }
Пример #11
0
        public void ClientLoaded(NetworkConnection connection, int playerIndex)
        {
            Player player = GameFlow.Get().GetPlayerFromConnectionId(connection.connectionId);

            foreach (ActorData playerActor in GameFlowData.Get().GetAllActorsForPlayer(playerIndex))
            {
                GameObject character = playerActor.gameObject;
                character.GetComponent <PlayerData>().m_player = player;  // PATCH internal -> public PlayerData::m_player
                GameFlow.Get().playerDetails[player]?.m_gameObjects.Add(character);
                Log.Info($"Registered player with account id {player.m_accountId} as player {playerIndex} ({character.name})");
                NetworkServer.AddPlayerForConnection(connection, character, 0);
            }
        }
Пример #12
0
 public bool IsVisible(BoardSquare square)
 {
     // no actual edits
     if (!NetworkServer.active && m_owner != GameFlowData.Get().activeOwnedActorData)
     {
         Log.Warning("Calling FogOfWar::IsVisible(BoardSquare square) on a client for not-the-client actor.");
     }
     if (square == null)
     {
         return(false);
     }
     return(m_visibleSquares.ContainsKey(square));
 }
 private void SendActions()
 {
     // TODO friendly/hostile visibility
     Log.Info($"Sending {ActionsThisPhase.Count} actions");
     foreach (ClientResolutionAction action in ActionsThisPhase)
     {
         Log.Info($"Sending action: {action.GetDebugDescription()}, Caster actor: {action.GetCaster()?.ActorIndex}, Action: {action.GetSourceAbilityActionType()}");
         SendToAll((short)MyMsgType.SingleResolutionAction, new SingleResolutionAction()
         {
             TurnIndex  = GameFlowData.Get().CurrentTurn,
             PhaseIndex = (int)Phase,
             Action     = action
         });
     }
     ActionsThisTurn.AddRange(ActionsThisPhase);
 }
Пример #14
0
        private void CmdRequestCancelAction(ActorTurnSM actorTurnSM, int actionTypeInt, bool hasIncomingRequest)
        {
            ActorData actor = actorTurnSM.gameObject.GetComponent <ActorData>();

            AbilityData.ActionType actionType = (AbilityData.ActionType)actionTypeInt;

            if (!GameFlowData.Get().IsInDecisionState())
            {
                Log.Info($"Recieved CmdRequestCancelAction not in desicion state! {actor.DisplayName} {actionType} ({hasIncomingRequest})");
                return;
            }

            Log.Info($"CmdRequestCancelAction {actor.DisplayName} {actionType} ({hasIncomingRequest})");
            ClearAbilityRequest(actor, actionType);
            ArtemisServerMovementManager.Get().UpdatePlayerRemainingMovement(actor, !hasIncomingRequest);
        }
Пример #15
0
        protected virtual void Awake()
        {
            if (instance == null)
            {
                instance = this;
            }

            foreach (var player in GameFlowData.Get().GetPlayers())
            {
                ActorTurnSM actorTurnSM = player.GetComponent <ActorTurnSM>();
                actorTurnSM.OnCmdGUITurnMessageCallback      += CmdGUITurnMessage;
                actorTurnSM.OnCmdRequestCancelActionCallback += CmdRequestCancelAction;
                ActorController actorController = player.GetComponent <ActorController>();
                actorController.OnCmdSelectAbilityRequestCallback += CmdSelectAbilityRequest;
            }
        }
        public void SendMovementActions(List <ClientResolutionAction> actions)
        {
            if (Phase != AbilityPriority.INVALID)
            {
                Log.Error($"SendMovementActions called in {Phase} phase! Ignoring");
                return;
            }

            SendToAll((short)MyMsgType.StartResolutionPhase, new StartResolutionPhase()
            {
                CurrentTurnIndex              = GameFlowData.Get().CurrentTurn,
                CurrentAbilityPhase           = Phase,
                NumResolutionActionsThisPhase = actions.Count
            });
            ActionsThisPhase = actions;
            SendActions();
        }
Пример #17
0
 protected virtual void OnDestroy()
 {
     if (instance == this)
     {
         instance = null;
     }
     if (GameFlowData.Get() != null)
     {
         foreach (var player in GameFlowData.Get().GetPlayers())
         {
             ActorTurnSM actorTurnSM = player.GetComponent <ActorTurnSM>();
             if (actorTurnSM != null)
             {
                 actorTurnSM.OnCmdGUITurnMessageCallback -= CmdGUITurnMessage;
             }
             ActorController actorController = player.GetComponent <ActorController>();
             if (actorController != null)
             {
                 actorController.OnCmdSelectAbilityRequestCallback -= CmdSelectAbilityRequest;
             }
         }
     }
 }
Пример #18
0
        private IEnumerator EndTurn()
        {
            GameFlowData.Get().gameState = GameState.EndingTurn;
            ArtemisServerResolutionManager.Get().ApplyActions();

            // Iterate over each player in the game
            foreach (ActorData actor in GameFlowData.Get().GetActors())
            {
                // Update statuses
                var actorStatus = actor.GetActorStatus();
                for (StatusType status = 0; status < StatusType.NUM; status++)
                {
                    if (actorStatus.HasStatus(status))
                    {
                        int duration = Math.Max(0, actorStatus.GetDurationOfStatus(status) - 1);
                        actorStatus.UpdateStatusDuration(status, duration);
                        if (duration == 0)
                        {
                            do
                            {
                                actorStatus.RemoveStatus(status);
                            } while (actorStatus.HasStatus(status));
                            Log.Info($"{actor.DisplayName}'s {status} status has expired.");
                        }
                    }
                }
                // Progress the cooldowns
                AbilityData actorAbilityData = actor.GetAbilityData();
                actorAbilityData.ProgressCooldowns();

                // Apply energy/tech point regen effects
                int newTechPoints = actor.TechPoints + actor.m_techPointRegen;
                Log.Info($"{actor.DisplayName} regens ${actor.m_techPointRegen} tech points");
                actor.SetTechPoints(newTechPoints);
            }
            yield return(null);
        }
Пример #19
0
        internal void OnCastAbility(NetworkConnection conn, int casterIndex, int actionTypeInt, List <AbilityTarget> targets)
        {
            Player      player = GameFlow.Get().GetPlayerFromConnectionId(conn.connectionId);
            ActorData   actor  = GameFlowData.Get().FindActorByActorIndex(casterIndex);
            ActorTurnSM turnSm = actor.gameObject.GetComponent <ActorTurnSM>();

            AbilityData.ActionType actionType = (AbilityData.ActionType)actionTypeInt;

            if (actor.gameObject.GetComponent <PlayerData>().m_player.m_connectionId != conn.connectionId)
            {
                Log.Error($"Illegal OnCastAbility: {actor.DisplayName} does not belong to player {player.m_accountId}!");
                turnSm.CallRpcTurnMessage((int)TurnMessage.ABILITY_REQUEST_REJECTED, 0);
                ClearAbilityRequest(actor, actionType);
                return;
            }

            Log.Info($"OnCastAbility {actor.DisplayName} {actionType} ({targets.Count} targets)");

            // TODO AbilityData.ValidateAbilityOnTarget
            turnSm.CallRpcTurnMessage((int)TurnMessage.ABILITY_REQUEST_ACCEPTED, 0);
            SetAbilityRequest(actor, actionType, targets);

            ArtemisServerMovementManager.Get().UpdatePlayerRemainingMovement(actor);
        }
Пример #20
0
        private void InitializeGame(Scene scene)
        {
            GameManager.Get().SetTeamInfo(TeamInfo);
            GameManager.Get().SetGameInfo(GameInfo);

            SpawnObject("ApplicationSingletonsNetId");
            var gameSceneSingletons = SpawnObject("GameSceneSingletons");

            gameSceneSingletons.SetActive(true);
            //var cameraMan = gameSceneSingletons.GetComponent<CameraManager>();
            //if (cameraMan != null)
            //{
            //    GameObject.Destroy(cameraMan);
            //}
            //else
            //{
            //    Log.Info("CameraManager is null");
            //}
            var SharedEffectBarrierManager = SpawnObject("SharedEffectBarrierManager");
            var SharedActionBufferObject   = SpawnObject("SharedActionBuffer");

            SharedActionBuffer = SharedActionBufferObject.GetComponent <SharedActionBuffer>();
            SharedActionBuffer.Networkm_actionPhase = ActionBufferPhase.Done;

            foreach (GameObject sceneObject in scene.GetRootGameObjects())
            {
                if (sceneObject.GetComponent <NetworkIdentity>() != null && !sceneObject.activeSelf)
                {
                    Log.Info($"Activating scene object '{sceneObject.name}'");
                    sceneObject.SetActive(true);
                    NetworkServer.Spawn(sceneObject);
                }
            }

            GameFlowData.Get().gameState = GameState.SpawningPlayers;

            bool destroyVisualsLoader = false;

            if (destroyVisualsLoader)
            {
                GameObject visualsLoader = GameObject.Find("VisualsLoader");
                if (visualsLoader != null)
                {
                    Log.Info("Trying to destroy VisualsLoader");
                    GameObject.Destroy(visualsLoader);
                }
            }

            Log.Info("Board is " + Board.Get());

            List <LobbyPlayerInfo> playerInfoList = GameManager.Get().TeamInfo.TeamPlayerInfo;

            IsMapLoaded = true;
            for (int i = 0; i < playerInfoList.Count; i++)
            {
                LobbyPlayerInfo playerInfo = playerInfoList[i];
                AddCharacterActor(playerInfo);
            }

            GameFlowData.Get().Networkm_currentTurn = 0;
            GameFlowData.Get().gameState            = GameState.StartingGame;

            // Show what objects are present in the current scene
            UnityUtils.DumpSceneObjects();

            WebsocketManager.ReportGameReady(); // Not sure where exactly it is supposed to happen
        }
Пример #21
0
 private IEnumerator EndGame()
 {
     GameFlowData.Get().gameState = GameState.EndingGame;
     yield break;
 }