public void SupplyTradeInit()
    {
        // Hide trade panel and show trade panel.
        GameObject.Find("BottomPanel").GetComponent <BottomPanel>().OpenTradeTab(); // toggles the trade tab
        offersPanel.SetActive(true);

        confirmed = false;
        foreach (GameObject panel in localPanels)
        {
            panel.GetComponent <Image>().color = new Color(1f, 1f, 1f);
        }
        LockRemotePanel();


        clearRemoteButton.SetActive(true);

        trading            = true;
        this.tradeDeclined = false;
        supplyTrading      = true;
        yearOfPlenty       = false;

        this.AvailableCards = 0;

        this.senderId    = PhotonNetwork.LocalPlayer.ActorNumber;
        this.recepientId = SUPPLY_ID;

        // Set up player and supply name.
        localPlayerText.text  = ColourUtility.GetPlayerDisplayNameFromId(senderId) + "'s offer";
        remotePlayerText.text = "Available cards: 0";

        // Set up cards. Left ones are local, right ones are remote.

        foreach (Card card in localCards)
        {
            card.Init();
            card.SetVisible(true);
            card.SetInventory(inventory);
            card.UpdateCard(0);
        }

        foreach (Card card in remoteCards)
        {
            card.Init();
            card.SetVisible(true);
            card.SetInventory(inventory);
            card.UpdateCard(0);

            // Specifically for supply trading.
            card.SetEnabled(true);
        }

        GameObject.Find("EventTextController").GetComponent <EventTextController>().SendEvent(EventTextController.EventCode.TRADE_SUPPLY_INITIATED, PhotonNetwork.LocalPlayer);
    }
    public void YearOfPlentyInit()
    {
        offersPanel.SetActive(true);

        confirmed = false;
        foreach (GameObject panel in localPanels)
        {
            panel.GetComponent <Image>().color = new Color(1f, 1f, 1f);
        }
        LockRemotePanel();


        clearRemoteButton.SetActive(true);

        trading            = true;
        this.tradeDeclined = false;
        this.supplyTrading = false;
        this.yearOfPlenty  = true;

        // Set available cards instantly.
        this.AvailableCards = 2;

        this.senderId    = PhotonNetwork.LocalPlayer.ActorNumber;
        this.recepientId = SUPPLY_ID;

        // Set up player and supply name.
        localPlayerText.text  = ColourUtility.GetPlayerDisplayNameFromId(senderId) + "'s offer";
        remotePlayerText.text = "Available cards: 2";

        // Set up cards. Left ones are local, right ones are remote.

        foreach (Card card in localCards)
        {
            card.Init();
            card.SetVisible(false); // Local cards here cannot be clicked.
            card.SetInventory(inventory);
            card.UpdateCard(0);
        }

        foreach (Card card in remoteCards)
        {
            card.Init();
            card.SetVisible(true);
            card.SetInventory(inventory);
            card.UpdateCard(0);

            // Specifically for year of plenty  and supply trading.
            card.SetEnabled(true);
        }

        GameObject.Find("EventTextController").GetComponent <EventTextController>().SendEvent(EventTextController.EventCode.YEAR_OF_PLENTY_INITIATED, PhotonNetwork.LocalPlayer);
    }
    // Should be run only from the Tick functions.
    private void InitOffersPanel()
    {
        offersPanel.SetActive(true);

        confirmed = false;
        foreach (GameObject panel in localPanels)
        {
            panel.GetComponent <Image>().color = new Color(1f, 1f, 1f);
        }
        UnlockRemotePanel();

        trading            = true;
        this.tradeDeclined = false;
        supplyTrading      = false;
        yearOfPlenty       = false;
        clearRemoteButton.SetActive(false);

        // Set up player names.

        if (amRecepient)
        {
            localPlayerText.text  = ColourUtility.GetPlayerDisplayNameFromId(recepientId) + "'s offer";
            remotePlayerText.text = ColourUtility.GetPlayerDisplayNameFromId(senderId) + "'s offer";
        }
        else
        {
            localPlayerText.text  = ColourUtility.GetPlayerDisplayNameFromId(senderId) + "'s offer";
            remotePlayerText.text = ColourUtility.GetPlayerDisplayNameFromId(recepientId) + "'s offer";
        }

        // Set up cards. Left ones are local, right ones are remote.

        foreach (Card card in localCards)
        {
            card.Init();
            card.SetVisible(true);
            card.SetInventory(inventory);
            card.UpdateCard(0);
        }

        foreach (Card card in remoteCards)
        {
            card.Init();
            card.SetVisible(true);
            card.SetInventory(inventory);
            card.UpdateCard(0);
        }
    }
    // This is run on the sender of the trade request.
    private IEnumerator TradeSenderTick()
    {
        recepientResponded = false;
        TextMeshProUGUI panelText     = tradeRequestStatusPanel.transform.GetChild(0).GetComponent <TextMeshProUGUI>();
        string          recepientName = ColourUtility.GetPlayerDisplayNameFromId(recepientId);

        for (int i = 10; i > 0; i--)
        {
            if (recepientResponded)
            {
                break;
            }
            panelText.text = "Waiting for " + recepientName + " to accept your trade request... (" + i + ")";
            yield return(new WaitForSeconds(1f));
        }

        if (recepientResponded)
        {
            if (tradeDeclined)
            {
                panelText.text = ColourUtility.GetPlayerDisplayNameFromId(recepientId) + " has declined your trade request.";
                yield return(new WaitForSeconds(3));

                tradeRequestStatusPanel.SetActive(false);
                yield break;
            }
            else
            {
                // Trade accepted.
                // Do not delay the initialisation on the sender as compensation for the message sending.
                tradeRequestStatusPanel.SetActive(false);
                GameObject.Find("EventTextController").GetComponent <EventTextController>().SendEvent(EventTextController.EventCode.TRADE_PLAYERS_INITIATED, PhotonNetwork.LocalPlayer, recepientId);
                InitOffersPanel();
                yield break;
            }
        }
        else
        {
            panelText.text = "The trade request timed out.";
            yield return(new WaitForSeconds(3));

            tradeRequestStatusPanel.SetActive(false);
            yield break;
        }
    }
    // This is run on the recepient of the trade request.
    private IEnumerator ReceiverOfferTick()
    {
        recepientResponded = false;
        tradeRequestPopupPanel.SetActive(true);
        TextMeshProUGUI popupText = tradeRequestPopupPanel.transform.GetChild(0).gameObject.transform.GetChild(0).GetComponent <TextMeshProUGUI>();

        for (int i = 10; i > 0; i--)
        {
            if (recepientResponded)
            {
                break;
            }

            popupText.text = ColourUtility.GetPlayerDisplayNameFromId(senderId) + " sent you a trade request (" + i + ").";
            yield return(new WaitForSeconds(1));
        }

        if (recepientResponded)
        {
            // Close trade request popup panel.

            if (tradeDeclined)
            {
                tradeRequestPopupPanel.SetActive(false);
                yield break;
            }
            else
            {
                //yield return new WaitForSeconds(1);
                tradeRequestPopupPanel.SetActive(false);
                InitOffersPanel();
                yield break;
            }
        }
        else
        {
            tradeRequestPopupPanel.SetActive(false);
            yield break;
        }
    }
Exemple #6
0
    private string GetMessage(EventCode code, int actorNumber, params object[] additionalParams)
    {
        switch (code)
        {
        case EventCode.FIRST_TURN_PHASE_ONE:

            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " is placing their first settlement.");

        case EventCode.FIRST_TURN_PHASE_TWO:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " is placing their first road.");

        case EventCode.SECOND_TURN_PHASE_ONE:

            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " is placing their second settlement.");

        case EventCode.SECOND_TURN_PHASE_TWO:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " is placing their second road.");

        case EventCode.ROAD_CONSTRUCTED:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has constructed a road.");

        case EventCode.SETTLEMENT_CONSTRUCTED:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has constructed a settlement.");

        case EventCode.CITY_CONSTRUCTED:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has upgraded a settlement into a city.");

        case EventCode.PRE_DICE_ROLL:

            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " is rolling the dice.");

        case EventCode.DICE_ROLLED:
            int    diceValue       = (int)additionalParams[0];
            string diceValueString = "";
            if (diceValue == 7)
            {
                diceValueString = "<color=black>";
            }
            else if (diceValue == 6 || diceValue == 8)
            {
                diceValueString = "<color=red>";
            }

            diceValueString += diceValue;
            if (diceValue >= 6 && diceValue <= 8)
            {
                diceValueString += "</color>";
            }
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has rolled a " + diceValueString + ".");

        case EventCode.PLAYER_IDLE:

            return("Waiting for an action from " + ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + ".");

        case EventCode.RESOURCE_EARNED:

            int resourceType = (int)additionalParams[0];
            int amount       = (int)additionalParams[1];

            Debug.Log("resourceType = " + resourceType + ", amount = " + amount);

            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has earned " + amount + "x" + ColourUtility.GetResourceText((Inventory.UnitCode)resourceType) + ".");

        case EventCode.NO_RESOURCE_EARNED:

            return("No player has earned any resources from this roll.");

        case EventCode.TRADE_SUPPLY_INITIATED:

            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " is trading with the supply.");

        case EventCode.TRADE_PLAYERS_INITIATED:
            int secondPlayerId = (int)additionalParams[0];
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " is trading with " + ColourUtility.GetPlayerDisplayNameFromId(secondPlayerId) + ".");

        case EventCode.TRADE_CANCELLED:

            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has cancelled the trade.");

        case EventCode.TRADE_SUPPLY_COMPLETED:

            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has finished trading with the supply.");

        case EventCode.TRADE_PLAYERS_COMPLETED:
            secondPlayerId = (int)additionalParams[0];
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has finished trading with " + ColourUtility.GetPlayerDisplayNameFromId(secondPlayerId) + ".");

        case EventCode.SHOULD_DISCARD:

            string resultText = "Waiting for ";

            if (actorNumber == -1)
            {
                // Initial set.
                discardList = ((int[])additionalParams[0]).OfType <int>().ToList();

                bool first = true;
                for (int i = 0; i < discardList.Count; i++)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        resultText += ", ";
                    }
                    //discardlist[i] is null for some reason
                    resultText += ColourUtility.GetPlayerDisplayNameFromId(discardList[i]);
                }
                resultText += " to discard half of their resource cards.";
            }
            else
            {
                // Update. Remove the player from the discard list and then repeat.
                if (discardList.IndexOf(actorNumber) != -1)
                {
                    discardList.Remove(actorNumber);
                }

                bool first = true;
                for (int i = 0; i < discardList.Count; i++)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        resultText += ", ";
                    }
                    resultText += ColourUtility.GetPlayerDisplayNameFromId(discardList[i]);
                }
                resultText += " to discard half of their resource cards.";
            }

            Debug.Log(resultText);
            return(resultText);

        case EventCode.BANDIT_MOVE:
            return("Waiting for " + ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " to move the bandit to another hex.");

        case EventCode.SELECTING_STEAL_VICTIM:
            return("Waiting for " + ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " to select a player to steal from.");

        case EventCode.STEAL_NO_ADJACENT_PLAYER:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " had nobody to steal from.");

        case EventCode.NO_RESOURCE_STOLEN:
            Player stealPlayer = PhotonNetwork.CurrentRoom.GetPlayer((int)additionalParams[0]);
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " had no cards to steal from " + ColourUtility.GetPlayerDisplayName(stealPlayer) + ".");

        case EventCode.RESOURCE_STOLEN:
            stealPlayer = PhotonNetwork.CurrentRoom.GetPlayer((int)additionalParams[0]);
            string resourceText = (string)additionalParams[1];
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has stolen 1x" + resourceText + " from " + ColourUtility.GetPlayerDisplayName(stealPlayer) + ".");

        case EventCode.DEVELOPMENT_CARD_PURCHASED:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has purchased a development card from the supply.");

        case EventCode.DEVELOPMENT_CARD_PLAYED:
            Inventory.UnitCode cardCode = (Inventory.UnitCode)additionalParams[0];
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has played a " + ColourUtility.GetDevelopmentText(cardCode) + " card!");

        case EventCode.YEAR_OF_PLENTY_INITIATED:
            return("Waiting for " + ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " to take 2 free Resource cards.");

        case EventCode.YEAR_OF_PLENTY_COMPLETED:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has taken two resource cards.");

        case EventCode.MONOPOLY_COMPLETE:
            resourceText = (string)additionalParams[0];
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has stolen all " + resourceText + " cards from the other players!");

        case EventCode.LARGEST_ARMY_TAKE_FIRST_TIME:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has received the <color=black>Largest Army</color> card!");

        case EventCode.LARGEST_ARMY_STEAL:
            stealPlayer = PhotonNetwork.CurrentRoom.GetPlayer((int)additionalParams[0]);
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has stolen the <color=black>Largest Army</color> card from " + ColourUtility.GetPlayerDisplayName(stealPlayer) + "!");

        case EventCode.LONGEST_ROAD_TAKE_FIRST_TIME:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has received the <color=black>Longest Road</color> card!");

        case EventCode.LONGEST_ROAD_STEAL:
            stealPlayer = PhotonNetwork.CurrentRoom.GetPlayer((int)additionalParams[0]);
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has stolen the <color=black>Longest Road</color> card from " + ColourUtility.GetPlayerDisplayName(stealPlayer) + "!");

        case EventCode.LONGEST_ROAD_RETURNED:
            return("The <color=black>Longest Road</color> card no longer belongs to any player!");

        case EventCode.GAME_OVER:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has won the game! Press ESC to return to the main menu.");

        case EventCode.END_TURN:
            return(ColourUtility.GetPlayerDisplayNameFromId(actorNumber) + " has ended their turn.");
        }


        return("<invalid_text_code>");
    }
Exemple #7
0
 private void RPCSetCurrentPlayer(int playerId)
 {
     currentPlayerText.text = ColourUtility.GetPlayerDisplayNameFromId(playerId);
 }
Exemple #8
0
    public void PrepareStealing(List <int> playerIdList)
    {
        // The playerIdList size can be maximum 3.

        stealPanel.SetActive(true);

        // Reset buttons. Fill with player info top down.
        for (int i = 0; i < stealButtons.Length; i++)
        {
            if (playerIdList.Count == 0)
            {
                stealButtons[i].interactable = false;
                stealButtons[i].transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = "";

                playerStealIds[i] = -1;
            }
            else
            {
                int playerId = playerIdList[0];

                playerIdList.RemoveAt(0);
                stealButtons[i].interactable = true;
                stealButtons[i].transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = ColourUtility.GetPlayerDisplayNameFromId(playerId);

                playerStealIds[i] = playerId;
            }
        }
    }