Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private static List <Type> GetTypes(DiplomacyAction action)
        {
            List <Type> typeList = new List <Type>();

            switch (action)
            {
            case DiplomacyAction.REQUEST:
                typeList.Add(typeof(RequestType));
                break;

            case DiplomacyAction.DEMAND:
                typeList.Add(typeof(DemandType));
                break;

            case DiplomacyAction.TREATY:
                typeList.Add(typeof(TreatyType));
                typeList.Add(typeof(LimitationTreatyType));
                break;

            case DiplomacyAction.LOBBY:
                typeList.Add(typeof(LobbyType));
                break;

            default:
                return((List <Type>)null);
            }
            return(typeList);
        }
Ejemplo n.º 3
0
 public static bool RequiresType(DiplomacyAction action)
 {
     if (action != DiplomacyAction.DEMAND && action != DiplomacyAction.LOBBY && action != DiplomacyAction.REQUEST)
     {
         return(action == DiplomacyAction.TREATY);
     }
     return(true);
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }