コード例 #1
0
    public static Reward GetRewardForProgressionLevel(int level)
    {
        Reward reward = new Reward();
        Dictionary <ProgressionUnlockCategory, string[]> unlockedIDsForLevel = Service.Get <ProgressionService>().GetUnlockedIDsForLevel(level);
        Dictionary <ProgressionUnlockCategory, ProgressionService.UnlockDefinition> unlockedDefinitionsForLevel = Service.Get <ProgressionService>().GetUnlockedDefinitionsForLevel(level);
        Dictionary <ProgressionUnlockCategory, int> unlockedCountsForLevel = Service.Get <ProgressionService>().GetUnlockedCountsForLevel(level);

        foreach (KeyValuePair <ProgressionUnlockCategory, string[]> item in unlockedIDsForLevel)
        {
            if (RewardableLoader.RewardableTypeMap.ContainsKey(item.Key.ToString()))
            {
                for (int i = 0; i < item.Value.Length; i++)
                {
                    reward.Add(RewardableLoader.GenerateRewardable(item.Key.ToString(), item.Value));
                }
            }
        }
        foreach (KeyValuePair <ProgressionUnlockCategory, ProgressionService.UnlockDefinition> item2 in unlockedDefinitionsForLevel)
        {
            string text        = item2.Key.ToString();
            Type   elementType = typeof(ProgressionUnlockDefinition).GetField(text).FieldType.GetElementType();
            if (elementType != null)
            {
                FieldInfo attributedField = StaticGameDataDefinitionIdAttribute.GetAttributedField(elementType);
                if (attributedField != null)
                {
                    if (RewardableLoader.RewardableTypeMap.ContainsKey(text) && item2.Value.Definitions.Length > 0)
                    {
                        Type  type  = attributedField.GetValue(item2.Value.Definitions[0]).GetType();
                        Type  type2 = typeof(List <>).MakeGenericType(type);
                        IList list  = (IList)Activator.CreateInstance(type2);
                        for (int i = 0; i < item2.Value.Definitions.Length; i++)
                        {
                            list.Add(attributedField.GetValue(item2.Value.Definitions[i]));
                        }
                        for (int i = 0; i < list.Count; i++)
                        {
                            reward.Add(RewardableLoader.GenerateRewardable(text, list[i]));
                        }
                    }
                }
                else
                {
                    Log.LogErrorFormatted(typeof(RewardUtils), "Could not find a StaticGameDataDefinitionId field on type {0}", elementType);
                }
            }
            else
            {
                Log.LogErrorFormatted(typeof(RewardUtils), "Could not find an element type for the field {0}, the field must be an array", text);
            }
        }
        foreach (KeyValuePair <ProgressionUnlockCategory, int> item3 in unlockedCountsForLevel)
        {
            if (RewardableLoader.RewardableTypeMap.ContainsKey(item3.Key.ToString()))
            {
                reward.Add(RewardableLoader.GenerateRewardable(item3.Key.ToString(), item3.Value));
            }
        }
        return(reward);
    }
コード例 #2
0
    private void onManifestLoaded <T>(string contentKey, Manifest manifest) where T : ScriptableObject
    {
        Content.TryPinBundle(contentKey);
        if (manifest == null || manifest.Assets == null)
        {
            Log.LogErrorFormatted(this, "Null Manifest {0} for type {1}", contentKey, typeof(T));
            return;
        }
        FieldInfo attributedField = StaticGameDataDefinitionIdAttribute.GetAttributedField(typeof(T));

        if (attributedField != null)
        {
            Type        type       = typeof(Dictionary <, >).MakeGenericType(attributedField.FieldType, typeof(T));
            IDictionary dictionary = (IDictionary)Activator.CreateInstance(type);
            for (int i = 0; i < manifest.Assets.Length; i++)
            {
                if (!(manifest.Assets[i] != null))
                {
                    continue;
                }
                T val = manifest.Assets[i] as T;
                if ((UnityEngine.Object)val != (UnityEngine.Object)null)
                {
                    object value = attributedField.GetValue(val);
                    if (value == null)
                    {
                        Log.LogErrorFormatted(manifest.Assets[i], "No {0} value found for asset {1} from manifest {2} at element {3}", attributedField, val, contentKey, i);
                    }
                    else if (dictionary.Contains(value))
                    {
                        Log.LogErrorFormatted(manifest.Assets[i], "Duplicate definition ID '{0}' for manifest type '{1}' was found.", value, typeof(T).FullName);
                    }
                    else
                    {
                        dictionary.Add(value, val);
                    }
                }
                else
                {
                    Log.LogErrorFormatted(manifest.Assets[i], "Could not convert this manifest entry to type {0}. Manifest {1} contains errors. Actual type was {2}", typeof(T), contentKey, manifest.Assets[i].GetType());
                }
            }
            dataMap[type] = dictionary;
        }
        else
        {
            T[] value2 = Array.ConvertAll(manifest.Assets, (ScriptableObject asset) => (T)asset);
            dataMap[typeof(T[])] = value2;
        }
    }
コード例 #3
0
    public static List <T> ToList <T>(StaticGameDataDefinition[] array, FieldInfo idField = null)
    {
        List <T> list = new List <T>();

        if (array != null)
        {
            foreach (object obj in array)
            {
                if (idField == null)
                {
                    idField = StaticGameDataDefinitionIdAttribute.GetAttributedField(obj.GetType());
                }
                list.Add((T)idField.GetValue(obj));
            }
        }
        return(list);
    }
コード例 #4
0
 public bool IsUnlocked(object definitionID, ProgressionUnlockCategory category)
 {
     for (int i = 0; i <= Level; i++)
     {
         if (unlockDefinitions.Length <= i || !unlockDefinitions[i].ContainsKey(category) || unlockDefinitions[i][category].Definitions.Length <= 0)
         {
             continue;
         }
         StaticGameDataDefinition[] definitions = unlockDefinitions[i][category].Definitions;
         FieldInfo attributedField = StaticGameDataDefinitionIdAttribute.GetAttributedField(definitions[0].GetType());
         for (int j = 0; j < definitions.Length; j++)
         {
             if (attributedField.GetValue(definitions[j]).Equals(definitionID))
             {
                 return(true);
             }
         }
     }
     if (rewardDefinitions.ContainsKey(category) && rewardDefinitions[category].Count > 0)
     {
         HashSet <StaticGameDataDefinition>             hashSet    = rewardDefinitions[category];
         HashSet <StaticGameDataDefinition> .Enumerator enumerator = hashSet.GetEnumerator();
         enumerator.MoveNext();
         FieldInfo attributedField = StaticGameDataDefinitionIdAttribute.GetAttributedField(enumerator.Current.GetType());
         if (attributedField.GetValue(enumerator.Current).Equals(definitionID))
         {
             return(true);
         }
         while (enumerator.MoveNext())
         {
             if (attributedField.GetValue(enumerator.Current).Equals(definitionID))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #5
0
        private void addRewardItem(string identifier, object item)
        {
            if (item == null)
            {
                return;
            }
            ProgressionUnlockCategory?progressionUnlockCategory = ProgressionUtils.RewardToProgressionCategory(identifier);

            if (!progressionUnlockCategory.HasValue)
            {
                return;
            }
            ProgressionUnlockCategory value = progressionUnlockCategory.Value;

            if (typeof(IList).IsAssignableFrom(item.GetType()))
            {
                IList list = (IList)item;
                if (list == null)
                {
                    return;
                }
                FieldInfo field = typeof(ProgressionUnlockDefinition).GetField(identifier);
                if (field.FieldType.IsArray)
                {
                    Type      elementType     = field.FieldType.GetElementType();
                    FieldInfo attributedField = StaticGameDataDefinitionIdAttribute.GetAttributedField(elementType);
                    if (attributedField == null)
                    {
                        Log.LogErrorFormatted(this, "The type {0} did not contain a field with the StaticGameDataDefinitionId attribute", elementType.Name);
                        return;
                    }
                    Type        fieldType  = attributedField.FieldType;
                    Type        type       = typeof(Dictionary <, >).MakeGenericType(fieldType, elementType);
                    IDictionary dictionary = (IDictionary)Service.Get <GameData>().Get(type);
                    List <StaticGameDataDefinition> list2 = new List <StaticGameDataDefinition>();
                    for (int i = 0; i < list.Count; i++)
                    {
                        StaticGameDataDefinition staticGameDataDefinition = dictionary[list[i]] as StaticGameDataDefinition;
                        if (staticGameDataDefinition != null)
                        {
                            list2.Add(staticGameDataDefinition);
                        }
                    }
                    if (rewardDefinitions.ContainsKey(value))
                    {
                        rewardDefinitions[value].UnionWith(list2);
                    }
                    else
                    {
                        rewardDefinitions[value] = new HashSet <StaticGameDataDefinition>(list2);
                    }
                }
                else if (rewardItems.ContainsKey(value))
                {
                    rewardItems[value].UnionWith((List <string>)list);
                }
                else
                {
                    rewardItems[value] = new HashSet <string>((List <string>)list);
                }
            }
            else
            {
                if (item.GetType() != typeof(int))
                {
                    return;
                }
                int num = (int)item;
                if (num > 0)
                {
                    if (rewardCounts.ContainsKey(value))
                    {
                        rewardCounts[value] += num;
                    }
                    else
                    {
                        rewardCounts[value] = num;
                    }
                }
            }
        }