Exemple #1
0
        public static void PrintInfo(IHero[] heroes, string character)
        {
            int currentHeroIndex = -1;

            for (int i = 0; i < heroes.Length; i++)
            {
                if (character.ToLower().Equals(heroes[i].name.ToLower()))
                {
                    currentHeroIndex = i;
                    break;
                }
            }
            Type type = heroes[currentHeroIndex].GetType();                                       // Get the class of the current hero

            FieldInfo[] properties = type.GetFields(BindingFlags.Public | BindingFlags.Instance); // Get all of the fields of the current hero
            GameConsole.currentLog.Append("\n");
            foreach (FieldInfo property in properties)
            {
                Type propertyType = property.GetValue(heroes[currentHeroIndex]).GetType();
                if (propertyType == typeof(ItemPool.Item)) // If the current field is an item we need to print it diffrently
                {
                    ItemPool.Item item = FindItem(property.GetValue(heroes[currentHeroIndex]), propertyType);
                    GameConsole.currentLog.Append("\t" + property.Name + ": ");
                    PrintItem(item);
                }
                else
                {
                    GameConsole.currentLog.Append("\t" + property.Name + ": " + property.GetValue(heroes[currentHeroIndex]).ToString() + "\n");
                }
            }
            var abilities = type.GetFields(BindingFlags.Public | BindingFlags.Static);

            GameConsole.currentLog.Append("\tAbilities: \n");
            foreach (var ability in abilities)
            {
                Type abilityType  = ability.GetValue(abilities).GetType();
                var  abilityInfos = abilityType.GetFields();
                GameConsole.currentLog.Append("\t\t|" + ability.Name + " | ");
                foreach (var abilityInfo in abilityInfos)
                {
                    GameConsole.currentLog.Append(abilityInfo.Name + ": " + abilityInfo.GetValue(ability.GetValue(abilities)).ToString() + " | ");
                }
                GameConsole.currentLog.Append("\n");
            }
            GameConsole.currentLog.Append("\n");
        }
Exemple #2
0
        private static void PrintItem(ItemPool.Item item)
        {
            FieldInfo[] fields       = item.GetType().GetFields(); // Gets all of fields of the current item
            bool        isFirstField = true;

            foreach (var field in fields)
            {
                if (field.GetValue(item) == null)
                {
                    GameConsole.currentLog.Append("empty \n");
                    return;
                }
                var type = field.GetValue(item).GetType();
                if (type == typeof(ItemPool.ClassAbleToWearItem[])) //If the type of the current field is an array of classes able to wear an item we need to print them separately
                {
                    //Prints the classes able to wear the item
                    GameConsole.currentLog.Append("For: ");
                    object      array      = field.GetValue(item);
                    IEnumerable enumerable = array as IEnumerable;
                    if (enumerable != null)
                    {
                        foreach (object element in enumerable)
                        {
                            GameConsole.currentLog.Append(element.ToString() + " ");
                        }
                    }
                    GameConsole.currentLog.Append("| ");
                }
                else
                {
                    // Print item field info
                    if (isFirstField)
                    {
                        GameConsole.currentLog.Append("| " + field.GetValue(item).ToString() + " |");
                        isFirstField = false;
                    }
                    else if (field.GetValue(item).ToString() != "0")
                    {
                        GameConsole.currentLog.Append(field.Name + ": " + field.GetValue(item).ToString() + " | ");
                    }
                }
            }
            GameConsole.currentLog.Append("\n");
        }
Exemple #3
0
        private static void PrintInfo(string character)
        {
            int  currentHeroIndex = Test.GetHeroIndex(character);
            Type type             = Test.heroes[currentHeroIndex].GetType();                      // Get the class of the current hero

            FieldInfo[] properties = type.GetFields(BindingFlags.Public | BindingFlags.Instance); // Get all of the fields of the current hero
            Console.WriteLine();
            foreach (FieldInfo property in properties)
            {
                Type propertyType = property.GetValue(Test.heroes[currentHeroIndex]).GetType();
                if (propertyType == typeof(ItemPool.Item)) // If the current field is an item we need to print it diffrently
                {
                    ItemPool.Item item = FindItem(property.GetValue(Test.heroes[currentHeroIndex]), propertyType);
                    Console.Write("\t{0}: ", property.Name);
                    PrintItem(item);
                }
                else
                {
                    Console.WriteLine("\t{0}: {1}", property.Name, property.GetValue(Test.heroes[currentHeroIndex]).ToString());
                }
            }
            var abilities = type.GetFields(BindingFlags.Public | BindingFlags.Static);

            Console.WriteLine("\tAbilities:");
            foreach (var ability in abilities)
            {
                Type abilityType  = ability.GetValue(abilities).GetType();
                var  abilityInfos = abilityType.GetFields();
                Console.Write("\t\t|{0} | ", ability.Name);
                foreach (var abilityInfo in abilityInfos)
                {
                    Console.Write("{0}: {1} | ", abilityInfo.Name, abilityInfo.GetValue(ability.GetValue(abilities)).ToString());
                }
                Console.WriteLine();
            }
            //var abilities = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Select(x => x.Name).Distinct().OrderBy(x => x);
            //Console.WriteLine("\tAbilities: ");
            //Console.WriteLine("\t\tattack");
            //foreach (var methodName in abilities)
            //{
            //    Console.WriteLine("\t\t{0}", methodName);
            //}
            Console.WriteLine();
        }
 internal static ItemPool.Item FindItemWithName(string name)
 {
     ItemPool.Item currentItem = new ItemPool.Item();
     for (int i = 0; i < ItemPool.itemsPool.Count; i++)
     {
         if(ItemPool.itemsPool[i].name.Equals(name))
         {
             currentItem = ItemPool.itemsPool[i];
         }
     }
     return currentItem;
 }