Beispiel #1
0
        public float GetWeight(DiplomacyAction action, DiplomaticMood mood, object type = null)
        {
            if (DiplomacyActionWeights.RequiresType(action) && type == null)
            {
                throw new Exception("Action requires a type.");
            }
            DiplomacyActionWeights.DiplomacyActionWeight diplomacyActionWeight = type != null?this.Weights.FirstOrDefault <DiplomacyActionWeights.DiplomacyActionWeight>((Func <DiplomacyActionWeights.DiplomacyActionWeight, bool>)(x =>
            {
                if (x.DiplomacyAction == action && x.Mood == mood)
                {
                    return(x.Type.Equals(type));
                }
                return(false);
            })) : this.Weights.FirstOrDefault <DiplomacyActionWeights.DiplomacyActionWeight>((Func <DiplomacyActionWeights.DiplomacyActionWeight, bool>)(x =>
            {
                if (x.DiplomacyAction == action)
                {
                    return(x.Mood == mood);
                }
                return(false);
            }));

            if (diplomacyActionWeight == null)
            {
                return(1f);
            }
            return(diplomacyActionWeight.Value);
        }
Beispiel #2
0
        public static void SyncPlayerCard(App game, string panelName, PlayerInfo pi)
        {
            if (pi == null)
            {
                return;
            }
            game.UI.SetPropertyString(game.UI.Path(panelName, StarmapUI.UIPlayerCardName), "text", pi.Name);
            game.UI.SetPropertyString(game.UI.Path(panelName, StarmapUI.UIPlayerCardAvatar), "sprite", Path.GetFileNameWithoutExtension(pi.AvatarAssetPath));
            game.UI.SetPropertyString(game.UI.Path(panelName, StarmapUI.UIPlayerCardBadge), "sprite", Path.GetFileNameWithoutExtension(pi.BadgeAssetPath));
            DiplomaticMood diplomaticMood = game.GameDatabase.GetDiplomacyInfo(pi.ID, game.Game.LocalPlayer.ID).GetDiplomaticMood();

            game.UI.SetVisible(game.UI.Path(panelName, StarmapUI.UIPlayerCardRelation), true);
            if (diplomaticMood == DiplomaticMood.Love && pi.ID != game.LocalPlayer.ID)
            {
                game.UI.SetPropertyString(game.UI.Path(panelName, StarmapUI.UIPlayerCardRelation), "sprite", "Love");
            }
            else if (diplomaticMood == DiplomaticMood.Hatred && pi.ID != game.LocalPlayer.ID)
            {
                game.UI.SetPropertyString(game.UI.Path(panelName, StarmapUI.UIPlayerCardRelation), "sprite", "Hate");
            }
            else
            {
                game.UI.SetVisible(game.UI.Path(panelName, StarmapUI.UIPlayerCardRelation), false);
            }
        }
Beispiel #3
0
        public float GetCumulativeWeight(DiplomacyAction action, DiplomaticMood mood)
        {
            float num1 = 0.0f;
            float num2;

            switch (action)
            {
            case DiplomacyAction.REQUEST:
                Array values1 = Enum.GetValues(typeof(RequestType));
                foreach (object type in values1)
                {
                    num1 += this.GetWeight(action, mood, type);
                }
                num2 = num1 / (float)values1.Length;
                break;

            case DiplomacyAction.DEMAND:
                Array values2 = Enum.GetValues(typeof(DemandType));
                foreach (object type in values2)
                {
                    num1 += this.GetWeight(action, mood, type);
                }
                num2 = num1 / (float)values2.Length;
                break;

            case DiplomacyAction.TREATY:
                Array values3 = Enum.GetValues(typeof(TreatyType));
                Array values4 = Enum.GetValues(typeof(LimitationTreatyType));
                foreach (object type in values3)
                {
                    if ((TreatyType)type != TreatyType.Limitation)
                    {
                        num1 += this.GetWeight(action, mood, type);
                    }
                }
                foreach (object type in values4)
                {
                    num1 += this.GetWeight(action, mood, type);
                }
                num2 = num1 / (float)(values3.Length + values4.Length);
                break;

            case DiplomacyAction.LOBBY:
                Array values5 = Enum.GetValues(typeof(LobbyType));
                foreach (object type in values5)
                {
                    num1 += this.GetWeight(action, mood, type);
                }
                num2 = num1 / (float)values5.Length;
                break;

            default:
                num2 = num1 + this.GetWeight(action, mood, (object)null);
                break;
            }
            return(num2);
        }
Beispiel #4
0
        public Dictionary <DiplomacyAction, float> GetCumulativeWeights(
            DiplomaticMood mood)
        {
            Dictionary <DiplomacyAction, float> dictionary = new Dictionary <DiplomacyAction, float>();

            foreach (object obj in Enum.GetValues(typeof(DiplomacyAction)))
            {
                float cumulativeWeight = this.GetCumulativeWeight((DiplomacyAction)obj, mood);
                dictionary.Add((DiplomacyAction)obj, cumulativeWeight);
            }
            return(dictionary);
        }
Beispiel #5
0
        public static string GetDiplomaticMoodSprite(DiplomaticMood mood)
        {
            switch (mood)
            {
            case DiplomaticMood.Hatred:
                return("Hate");

            case DiplomaticMood.Love:
                return("Love");

            default:
                return(null);
            }
        }
Beispiel #6
0
        public static void SyncDiplomacyPopup(App game, string panelName, int playerId)
        {
            PlayerInfo     playerInfo     = game.GameDatabase.GetPlayerInfo(playerId);
            DiplomaticMood diplomaticMood = game.GameDatabase.GetDiplomacyInfo(playerInfo.ID, game.Game.LocalPlayer.ID).GetDiplomaticMood();

            game.UI.SetVisible(DiplomacyUI.UIRelation, true);
            switch (diplomaticMood)
            {
            case DiplomaticMood.Hatred:
                game.UI.SetPropertyString(DiplomacyUI.UIRelation, "sprite", "Hate");
                break;

            case DiplomaticMood.Love:
                game.UI.SetPropertyString(DiplomacyUI.UIRelation, "sprite", "Love");
                break;

            default:
                game.UI.SetVisible(DiplomacyUI.UIRelation, false);
                break;
            }
            DiplomacyUI.SyncPanelColor(game, game.UI.Path(panelName, DiplomacyUI.UIPanelBackground), playerInfo.PrimaryColor);
            game.UI.SetPropertyString(game.UI.Path(panelName, DiplomacyUI.UIAvatar), "sprite", Path.GetFileNameWithoutExtension(playerInfo.AvatarAssetPath));
            game.UI.SetPropertyString(game.UI.Path(panelName, DiplomacyUI.UIBadge), "sprite", Path.GetFileNameWithoutExtension(playerInfo.BadgeAssetPath));
            game.UI.SetPropertyString(game.UI.Path(panelName, DiplomacyUI.UICardPlayerName), "text", playerInfo.Name);
            if (!(panelName == DiplomacyUI.UILobbyPanel))
            {
                return;
            }
            foreach (PlayerInfo standardPlayerInfo in game.GameDatabase.GetStandardPlayerInfos())
            {
                if (standardPlayerInfo.ID != playerId)
                {
                    float num1 = (float)game.GameDatabase.GetDiplomacyInfo(playerInfo.ID, standardPlayerInfo.ID).Relations / 2000f;
                    float num2 = ((float)((!(game.GameDatabase.GetPlayerFaction(standardPlayerInfo.ID).Name == "morrigi") || standardPlayerInfo.ID != game.Game.LocalPlayer.ID ? 0.0 : (double)game.AssetDatabase.GetTechBonus <float>("PSI_Lesser_Glamour", "diplomaticoffering") * 0.5) + (game.GameDatabase.PlayerHasTech(game.Game.LocalPlayer.ID, "PSI_Lesser_Glamour") ? (double)game.AssetDatabase.GetTechBonus <float>("PSI_Lesser_Glamour", "diplomaticoffering") : 0.0)) + num1) * 100f;
                    game.UI.AddItem(DiplomacyUI.UILobbyPlayerList, "", standardPlayerInfo.ID, standardPlayerInfo.Name + " (" + (object)(int)num2 + "% Chance)");
                }
            }
            game.UI.SetSelection(DiplomacyUI.UILobbyPlayerList, game.LocalPlayer.ID);
        }
Beispiel #7
0
        public DiplomacyActionWeights(XmlDocument doc)
        {
            foreach (XmlElement source in doc[nameof(DiplomacyActionWeights)].OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name == "DiplomacyReaction")))
            {
                DiplomaticMood diplomaticMood = (DiplomaticMood)Enum.Parse(typeof(DiplomaticMood), source.GetAttribute("value"));
                foreach (XmlElement element in source.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name == "Action")))
                {
                    DiplomacyActionWeights.DiplomacyActionWeight weight = new DiplomacyActionWeights.DiplomacyActionWeight();
                    weight.Mood            = diplomaticMood;
                    weight.DiplomacyAction = (DiplomacyAction)Enum.Parse(typeof(DiplomacyAction), element.GetAttribute("id"));
                    weight.Value           = float.Parse(element.GetAttribute("value"));
                    if (DiplomacyActionWeights.RequiresType(weight.DiplomacyAction) && !element.HasAttribute("type"))
                    {
                        throw new Exception(string.Format("XML node for diplomatic action type: {0} requires a type.", (object)weight.DiplomacyAction.ToString()));
                    }
                    switch (weight.DiplomacyAction)
                    {
                    case DiplomacyAction.REQUEST:
                        this.ProcessRequest(element, weight);
                        break;

                    case DiplomacyAction.DEMAND:
                        this.ProcessDemand(element, weight);
                        break;

                    case DiplomacyAction.TREATY:
                        this.ProcessTreaty(element, weight);
                        break;

                    case DiplomacyAction.LOBBY:
                        this.ProcessLobby(element, weight);
                        break;
                    }
                    this.Weights.Add(weight);
                }
            }
        }
Beispiel #8
0
        public Dictionary <object, float> GetWeights(
            DiplomacyAction action,
            DiplomaticMood mood)
        {
            Dictionary <object, float> dictionary = new Dictionary <object, float>();
            List <Type> types = DiplomacyActionWeights.GetTypes(action);

            if (types != null)
            {
                foreach (Type enumType in types)
                {
                    foreach (object obj in Enum.GetValues(enumType))
                    {
                        dictionary.Add(obj, this.GetWeight(action, mood, obj));
                    }
                }
            }
            else
            {
                float weight = this.GetWeight(action, mood, (object)null);
                dictionary.Add((object)action, weight);
            }
            return(dictionary);
        }
Beispiel #9
0
        protected override void UICommChannel_OnPanelMessage(
            string panelName,
            string msgType,
            string[] msgParams)
        {
            if (msgType == "dialog_closed")
            {
                if (this._mode == DiplomacyScreenState.DiplomacyMode.Independent)
                {
                    DiplomacyUI.SyncIndyDiplomacyCard(this.App, "pnlIndyPlayerSummary", this._selectedIndy);
                }
                else
                {
                    this.SyncPlayerDiplomacyCard(this._playerId, false);
                }
            }
            else if (msgType == "list_sel_changed")
            {
                if (panelName == "factionList" && !string.IsNullOrEmpty(msgParams[0]))
                {
                    this._selectedIndy = int.Parse(msgParams[0]);
                    this.App.UI.SetVisible("pnlIndyPlayerSummary", true);
                    DiplomacyUI.SyncIndyDiplomacyCard(this.App, "pnlIndyPlayerSummary", this._selectedIndy);
                }
                else if (panelName == DiplomacyUI.UILobbyPlayerList)
                {
                    int playerID = int.Parse(msgParams[0]);
                    this._selectedLobbyPlayer = playerID;
                    PlayerInfo     playerInfo     = this.App.GameDatabase.GetPlayerInfo(playerID);
                    DiplomaticMood diplomaticMood = this.App.GameDatabase.GetDiplomacyInfo(playerInfo.ID, this._playerId).GetDiplomaticMood();
                    this.App.UI.SetVisible(this.App.UI.Path(DiplomacyUI.UILobbyPanel, "imgOtherRelation"), true);
                    switch (diplomaticMood)
                    {
                    case DiplomaticMood.Hatred:
                        this.App.UI.SetPropertyString(this.App.UI.Path(DiplomacyUI.UILobbyPanel, "imgOtherRelation"), "sprite", "Hate");
                        break;

                    case DiplomaticMood.Love:
                        this.App.UI.SetPropertyString(this.App.UI.Path(DiplomacyUI.UILobbyPanel, "imgOtherRelation"), "sprite", "Love");
                        break;

                    default:
                        this.App.UI.SetVisible(this.App.UI.Path(DiplomacyUI.UILobbyPanel, "imgOtherRelation"), false);
                        break;
                    }
                    this.App.UI.SetPropertyString(this.App.UI.Path(DiplomacyUI.UILobbyPanel, "imgOtherAvatar"), "sprite", Path.GetFileNameWithoutExtension(playerInfo.AvatarAssetPath));
                    this.App.UI.SetPropertyString(this.App.UI.Path(DiplomacyUI.UILobbyPanel, "imgOtherBadge"), "sprite", Path.GetFileNameWithoutExtension(playerInfo.BadgeAssetPath));
                }
            }
            if (!(msgType == "button_clicked"))
            {
                return;
            }
            if (panelName == "gameTutorialButton")
            {
                this.App.UI.SetVisible("DiplomacyScreenTutorial", true);
            }
            else if (panelName == "diplomacyScreenTutImage")
            {
                this.App.UI.SetVisible("DiplomacyScreenTutorial", false);
            }
            else if (panelName == "btnEmpiresButton")
            {
                this._mode = DiplomacyScreenState.DiplomacyMode.Standard;
                this.App.UI.SetVisible("pnlStandardDiplomacy", true);
                this.App.UI.SetVisible("pnlIndyDiplomacy", false);
            }
            else if (panelName == "btnIndependentsButton")
            {
                this._mode = DiplomacyScreenState.DiplomacyMode.Independent;
                this.App.UI.SetVisible("pnlIndyDiplomacy", true);
                this.App.UI.SetVisible("pnlStandardDiplomacy", false);
            }
            else if (panelName == "btnBackButton")
            {
                this.App.SwitchGameState <StarMapState>();
            }
            else if (panelName == DiplomacyUI.UISurpriseAttackOk)
            {
                this.App.Game.DeclareWarInformally(this.App.Game.LocalPlayer.ID, this._playerId);
                this.App.UI.SetVisible(DiplomacyUI.UISurpriseAttackPanel, false);
                if (this._mode == DiplomacyScreenState.DiplomacyMode.Independent)
                {
                    DiplomacyUI.SyncIndyDiplomacyCard(this.App, "pnlIndyPlayerSummary", this._selectedIndy);
                }
                else
                {
                    this.SyncPlayerDiplomacyCard(this._playerId, true);
                }
            }
            else if (panelName == DiplomacyUI.UISurpriseAttackCancel)
            {
                this.App.UI.SetVisible(DiplomacyUI.UISurpriseAttackPanel, false);
            }
            else if (panelName == DiplomacyUI.UIDeclareWarOk)
            {
                this.App.Game.DeclareWarFormally(this.App.Game.LocalPlayer.ID, this._playerId);
                this.App.UI.SetVisible(DiplomacyUI.UIDeclareWarPanel, false);
                this.App.GameDatabase.SpendDiplomacyPoints(this.App.GameDatabase.GetPlayerInfo(this.App.Game.LocalPlayer.ID), this.App.GameDatabase.GetPlayerFactionID(this._playerId), this.App.Game.GetDiplomacyActionCost(DiplomacyAction.DECLARATION, new RequestType?(), new DemandType?()).Value);
                if (this._mode == DiplomacyScreenState.DiplomacyMode.Independent)
                {
                    DiplomacyUI.SyncIndyDiplomacyCard(this.App, "pnlIndyPlayerSummary", this._selectedIndy);
                }
                else
                {
                    this.SyncPlayerDiplomacyCard(this._playerId, true);
                }
            }
            else if (panelName == DiplomacyUI.UIDeclareWarCancel)
            {
                this.App.UI.SetVisible(DiplomacyUI.UIDeclareWarPanel, false);
            }
            else if (panelName == DiplomacyUI.UIDemandOk)
            {
                this.App.UI.SetVisible(DiplomacyUI.UIDemandPanel, false);
            }
            else if (panelName == DiplomacyUI.UIDemandCancel)
            {
                this.App.UI.SetVisible(DiplomacyUI.UIDemandPanel, false);
            }
            else if (panelName == DiplomacyUI.UIRequestOk)
            {
                this.App.UI.SetVisible(DiplomacyUI.UIRequestPanel, false);
            }
            else if (panelName == DiplomacyUI.UIRequestCancel)
            {
                this.App.UI.SetVisible(DiplomacyUI.UIRequestPanel, false);
            }
            else if (panelName == DiplomacyUI.UITreatyOk)
            {
                this.App.UI.SetVisible(DiplomacyUI.UITreatyPanel, false);
            }
            else if (panelName == DiplomacyUI.UITreatyCancel)
            {
                this.App.UI.SetVisible(DiplomacyUI.UITreatyPanel, false);
            }
            else if (panelName == DiplomacyUI.UILobbyRelationImprovebtn)
            {
                this._lobbyimprove = true;
                this.App.UI.SetChecked(this.App.UI.Path(DiplomacyUI.UILobbyPanel, DiplomacyUI.UILobbyRelationDegradebtn), false);
                this.App.UI.SetChecked(this.App.UI.Path(DiplomacyUI.UILobbyPanel, DiplomacyUI.UILobbyRelationImprovebtn), true);
            }
            else if (panelName == DiplomacyUI.UILobbyRelationDegradebtn)
            {
                this._lobbyimprove = false;
                this.App.UI.SetChecked(this.App.UI.Path(DiplomacyUI.UILobbyPanel, DiplomacyUI.UILobbyRelationDegradebtn), true);
                this.App.UI.SetChecked(this.App.UI.Path(DiplomacyUI.UILobbyPanel, DiplomacyUI.UILobbyRelationImprovebtn), false);
            }
            else if (panelName == DiplomacyUI.UILobbyOk)
            {
                this.App.Game.DoLobbyAction(this.App.LocalPlayer.ID, this._playerId, this._selectedLobbyPlayer, this._lobbyimprove);
                this.App.UI.SetVisible(DiplomacyUI.UILobbyPanel, false);
            }
            else if (panelName == DiplomacyUI.UILobbyCancel)
            {
                this.App.UI.SetVisible(DiplomacyUI.UILobbyPanel, false);
            }
            else if (panelName.EndsWith(DiplomacyUI.UIIntelButton))
            {
                IntelMissionDialog intelMissionDialog = new IntelMissionDialog(this.App.Game, this.PlayerSlots[int.Parse(panelName.Split('|')[0].Replace("Player", ""))]);
                this._playerId = this.GetPlayerId(panelName);
                this.App.UI.CreateDialog((Dialog)intelMissionDialog, null);
            }
            else if (panelName.EndsWith(DiplomacyUI.UICounterIntelButton))
            {
                int playerSlot = this.PlayerSlots[int.Parse(panelName.Split('|')[0].Replace("Player", ""))];
                this._playerId = this.GetPlayerId(panelName);
                this.App.UI.CreateDialog((Dialog) new CounterIntelMissionDialog(this.App.Game, playerSlot), null);
            }
            else if (panelName.EndsWith(DiplomacyUI.UIOperationsButton))
            {
                int playerSlot1 = this.PlayerSlots[int.Parse(panelName.Split('|')[0].Replace("Player", ""))];
            }
            else if (panelName.EndsWith(DiplomacyUI.UICardPreviousState))
            {
                string panelName1 = panelName.Split('|')[0];
                this._playerId = this.PlayerSlots[int.Parse(panelName1.Replace("Player", ""))];
                this.LastDiplomacyCardState[this._playerId] = DiplomacyUI.GetPreviousDiplomacyCardState(this.LastDiplomacyCardState[this._playerId]);
                DiplomacyUI.SyncPlayerDiplomacyCard(this.App, panelName1, this._playerId, this.LastDiplomacyCardState[this._playerId], false);
            }
            else if (panelName.EndsWith(DiplomacyUI.UICardNextState))
            {
                string panelName1 = panelName.Split('|')[0];
                this._playerId = this.PlayerSlots[int.Parse(panelName1.Replace("Player", ""))];
                this.LastDiplomacyCardState[this._playerId] = DiplomacyUI.GetNextDiplomacyCardState(this.LastDiplomacyCardState[this._playerId]);
                DiplomacyUI.SyncPlayerDiplomacyCard(this.App, panelName1, this._playerId, this.LastDiplomacyCardState[this._playerId], false);
            }
            else if (panelName.EndsWith(DiplomacyUI.UISurpriseAttackButton))
            {
                this._playerId = this.GetPlayerId(panelName);
                DiplomacyUI.SyncDiplomacyPopup(this.App, DiplomacyUI.UISurpriseAttackPanel, this._playerId);
                this.App.UI.SetVisible(DiplomacyUI.UISurpriseAttackPanel, true);
            }
            else if (panelName.EndsWith(DiplomacyUI.UIDeclareButton))
            {
                this._playerId = this.GetPlayerId(panelName);
                DiplomacyUI.SyncDiplomacyPopup(this.App, DiplomacyUI.UIDeclareWarPanel, this._playerId);
                this.App.UI.SetVisible(DiplomacyUI.UIDeclareWarPanel, true);
            }
            else if (panelName.EndsWith(DiplomacyUI.UIDemandButton))
            {
                this._playerId = this.GetPlayerId(panelName);
                this.App.UI.CreateDialog((Dialog) new DemandTypeDialog(this.App, this._playerId, "dialogDemandType"), null);
            }
            else if (panelName.EndsWith(DiplomacyUI.UIRequestButton))
            {
                this._playerId = this.GetPlayerId(panelName);
                this.App.UI.CreateDialog((Dialog) new RequestTypeDialog(this.App, this._playerId, "dialogRequestType"), null);
            }
            else if (panelName.EndsWith(DiplomacyUI.UITreatyButton))
            {
                this._playerId = this.GetPlayerId(panelName);
                this.App.UI.CreateDialog((Dialog) new TreatiesPopup(this.App, this._playerId, "TreatiesPopup"), null);
            }
            else if (panelName.EndsWith(DiplomacyUI.UILobbyButton))
            {
                this._playerId = this.GetPlayerId(panelName);
                DiplomacyUI.SyncDiplomacyPopup(this.App, DiplomacyUI.UILobbyPanel, this._playerId);
                this._lobbyimprove = true;
                this.App.UI.SetChecked(this.App.UI.Path(DiplomacyUI.UILobbyPanel, DiplomacyUI.UILobbyRelationDegradebtn), false);
                this.App.UI.SetChecked(this.App.UI.Path(DiplomacyUI.UILobbyPanel, DiplomacyUI.UILobbyRelationImprovebtn), true);
                this.App.UI.SetVisible(DiplomacyUI.UILobbyPanel, true);
            }
            else
            {
                if (!panelName.EndsWith(DiplomacyUI.UIGiveButton))
                {
                    return;
                }
                this._playerId = this.GetPlayerId(panelName);
                this.App.UI.CreateDialog((Dialog) new GiveTypeDialog(this.App, this._playerId, "dialogGiveType"), null);
            }
        }