Пример #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);
        }
Пример #2
0
        private void ProcessRequest(
            XmlElement element,
            DiplomacyActionWeights.DiplomacyActionWeight weight)
        {
            RequestType requestType = (RequestType)Enum.Parse(typeof(RequestType), element.GetAttribute("type"));

            weight.Type = (object)requestType;
        }
Пример #3
0
        private void ProcessLobby(
            XmlElement element,
            DiplomacyActionWeights.DiplomacyActionWeight weight)
        {
            LobbyType lobbyType = (LobbyType)Enum.Parse(typeof(LobbyType), element.GetAttribute("type"));

            weight.Type = (object)lobbyType;
        }
Пример #4
0
        private void ProcessDemand(
            XmlElement element,
            DiplomacyActionWeights.DiplomacyActionWeight weight)
        {
            DemandType demandType = (DemandType)Enum.Parse(typeof(DemandType), element.GetAttribute("type"));

            weight.Type = (object)demandType;
        }
Пример #5
0
        private void ProcessTreaty(
            XmlElement element,
            DiplomacyActionWeights.DiplomacyActionWeight weight)
        {
            string attribute = element.GetAttribute("type");

            if (attribute.Contains("Limitation"))
            {
                LimitationTreatyType limitationTreatyType = (LimitationTreatyType)Enum.Parse(typeof(LimitationTreatyType), attribute.Replace("Limitation", ""));
                weight.Type = (object)limitationTreatyType;
            }
            else
            {
                int num = (int)Enum.Parse(typeof(TreatyType), attribute);
            }
        }
Пример #6
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);
                }
            }
        }