Exemplo n.º 1
0
    public void SubmitTurn()
    {
        if (hasFinished)
        {
            SceneManager.LoadScene(0);
        }
        else
        {
            advanceButton.interactable = false;
            advanceButtonText.text     = "Wait";

            var clientGameLogicManager = ClientGameLogicManager.GetClientLogicFromScene();

            var actions = clientGameLogicManager.QueuedGameActionsPlanning;
            if (clientGameLogicManager.CurrentServerSideState.CurrentPhase == GamePhase.Revision)
            {
                actions = clientGameLogicManager.QueuedGameActionsRevision;
            }

            ClientNetworkingManager.GetClientNetworkingManager().SendActions(actions);

            clientGameLogicManager.QueuedGameActionsRevision =
                new List <GameAction>(clientGameLogicManager.QueuedGameActionsPlanning);

            UnitController[] unitControllers = FindObjectsOfType <UnitController>();
            for (int i = 0; i < unitControllers.Length; i++)
            {
                unitControllers[i].SetDestinationTileController(null);
            }
        }
    }
Exemplo n.º 2
0
    public void OnPointerClick(PointerEventData eventData)
    {
        if (!isDead &&
            !IngameSubmitButtonManager.GetIngameSubmitButtonManager().IsWaiting() &&
            ClientNetworkingManager.GetClientNetworkingManager().PlayerId == unitData.owningPlayerId)
        {
            ClientGameLogicManager logicManager = ClientGameLogicManager.GetClientLogicFromScene();
            if (logicManager.CurrentServerSideState.CurrentPhase == GamePhase.Planning)
            {
                if (destination == null)
                {
                    SelectedUnit = this;
                }
                else
                {
                    SetDestinationTileController(null);
                }
                playClickedSound();
            }
            else if (logicManager.CurrentServerSideState.CurrentPhase == GamePhase.Revision)
            {
                List <GameAction> gameActions = logicManager.QueuedGameActionsRevision;
                for (int i = 0; i < gameActions.Count; i++)
                {
                    if (gameActions[i].UnitId == unitData.unitId)
                    {
                        gameActions[i].moveToPositions.Clear();
                    }
                }

                // CLICK IT!
                FindObjectOfType <IngameSubmitButtonManager>().SubmitTurn();
            }
        }
    }
Exemplo n.º 3
0
    public void ReceivedNewGameState(GameState gameState)
    {
        var isClient = ClientNetworkingManager.GetClientNetworkingManager().PlayerId > 0;

        CurrentServerSideState = gameState;
        Debug.Log(CurrentServerSideState.CurrentPhase);
        _resultActionQueue = new List <GameResultAction>(CurrentServerSideState.ResultsFromLastPhase);

        Debug.Log("didInitializeUnits / isClient =  " + didInitializeUnits + " " + isClient);
        if (!didInitializeUnits && isClient)
        {
            // kill all the units
            var parent = GameObject.Find("UnitContainer");
            foreach (var child in parent.transform)
            {
                Destroy((child as Transform).gameObject);
            }
        }
        // Update unit controllers with new game state
        foreach (Player player in CurrentServerSideState.players.Values)
        {
            foreach (Unit unit in player.units.Values)
            {
                if (!didInitializeUnits && isClient)
                {
                    var parent = GameObject.Find("UnitContainer");

                    var unitPrefabName = "";
                    unitPrefabName += player.id == 0 ? "Blue_" : "Red_";
                    unitPrefabName += unit.Definition.type + "_Unit";

                    Debug.Log("sudo make me a " + unitPrefabName);

                    var child = GetComponent <MapGenerator>().InstantiatePrefab(unitPrefabName);
                    child.name = Unit.UnitControllerNameForId(unit.unitId);
                    var unitController = child.GetComponent <UnitController>();
                    unitController.unitData  = unit;
                    child.transform.position = new Vector3(unit.position.x, unit.position.y, -2.0f);
                    child.transform.parent   = parent.transform;
                }
                else
                {
                    var unitController = FindUnitControllerById(unit.unitId);
                    unitController.unitData = unit;
                }
            }
        }

        didInitializeUnits = true;

        // invoke the first animation which will go through the queue via callbacks
        PlayNextAnimation();

        Debug.LogError("New game state phase is " + gameState.CurrentPhase);
        if (StateUpdatedHandler != null)
        {
            StateUpdatedHandler();
        }
    }