コード例 #1
0
ファイル: DataManager.cs プロジェクト: uvbs/OmegaBot
        public ItemDataType(String file)
        {
            m_items = new List<ItemEntry>();
            Dictionary<String, Item.ClassificationType> classificationMap = new Dictionary<string, Item.ClassificationType>();
            classificationMap["Amazon Bow"] = Item.ClassificationType.amazon_bow;
            classificationMap["Amazon Javelin"] = Item.ClassificationType.amazon_javelin;
            classificationMap["Amazon Spear"] = Item.ClassificationType.amazon_spear;
            classificationMap["Amulet"] = Item.ClassificationType.amulet;
            classificationMap["Antidote Potion"] = Item.ClassificationType.antidote_potion;
            classificationMap["Armor"] = Item.ClassificationType.armor;
            classificationMap["Arrows"] = Item.ClassificationType.arrows;
            classificationMap["Assassin Katar"] = Item.ClassificationType.assassin_katar;
            classificationMap["Axe"] = Item.ClassificationType.axe;
            classificationMap["Barbarian Helm"] = Item.ClassificationType.barbarian_helm;
            classificationMap["Belt"] = Item.ClassificationType.belt;
            classificationMap["Body Part"] = Item.ClassificationType.body_part;
            classificationMap["Bolts"] = Item.ClassificationType.bolts;
            classificationMap["Boots"] = Item.ClassificationType.boots;
            classificationMap["Bow"] = Item.ClassificationType.bow;
            classificationMap["Circlet"] = Item.ClassificationType.circlet;
            classificationMap["Club"] = Item.ClassificationType.club;
            classificationMap["Crossbow"] = Item.ClassificationType.crossbow;
            classificationMap["Dagger"] = Item.ClassificationType.dagger;
            classificationMap["Druid Pelt"] = Item.ClassificationType.druid_pelt;
            classificationMap["Ear"] = Item.ClassificationType.ear;
            classificationMap["Elixir"] = Item.ClassificationType.elixir;
            classificationMap["Gem"] = Item.ClassificationType.gem;
            classificationMap["Gloves"] = Item.ClassificationType.gloves;
            classificationMap["Gold"] = Item.ClassificationType.gold;
            classificationMap["Grand Charm"] = Item.ClassificationType.grand_charm;
            classificationMap["Hammer"] = Item.ClassificationType.hammer;
            classificationMap["Health Potion"] = Item.ClassificationType.health_potion;
            classificationMap["Helm"] = Item.ClassificationType.helm;
            classificationMap["Herb"] = Item.ClassificationType.herb;
            classificationMap["Javelin"] = Item.ClassificationType.javelin;
            classificationMap["Jewel"] = Item.ClassificationType.jewel;
            classificationMap["Key"] = Item.ClassificationType.key;
            classificationMap["Large Charm"] = Item.ClassificationType.large_charm;
            classificationMap["Mace"] = Item.ClassificationType.mace;
            classificationMap["Mana Potion"] = Item.ClassificationType.mana_potion;
            classificationMap["Necromancer Shrunken Head"] = Item.ClassificationType.necromancer_shrunken_head;
            classificationMap["Paladin Shield"] = Item.ClassificationType.paladin_shield;
            classificationMap["Polearm"] = Item.ClassificationType.polearm;
            classificationMap["Quest Item"] = Item.ClassificationType.quest_item;
            classificationMap["Rejuvenation Potion"] = Item.ClassificationType.rejuvenation_potion;
            classificationMap["Ring"] = Item.ClassificationType.ring;
            classificationMap["Rune"] = Item.ClassificationType.rune;
            classificationMap["Scepter"] = Item.ClassificationType.scepter;
            classificationMap["Scroll"] = Item.ClassificationType.scroll;
            classificationMap["Shield"] = Item.ClassificationType.shield;
            classificationMap["Small Charm"] = Item.ClassificationType.small_charm;
            classificationMap["Sorceress Orb"] = Item.ClassificationType.sorceress_orb;
            classificationMap["Spear"] = Item.ClassificationType.spear;
            classificationMap["Staff"] = Item.ClassificationType.staff;
            classificationMap["Stamina Potion"] = Item.ClassificationType.stamina_potion;
            classificationMap["Sword"] = Item.ClassificationType.sword;
            classificationMap["Thawing Potion"] = Item.ClassificationType.thawing_potion;
            classificationMap["Throwing Axe"] = Item.ClassificationType.throwing_axe;
            classificationMap["Throwing Knife"] = Item.ClassificationType.throwing_knife;
            classificationMap["Throwing Potion"] = Item.ClassificationType.throwing_potion;
            classificationMap["Tome"] = Item.ClassificationType.tome;
            classificationMap["Torch"] = Item.ClassificationType.torch;
            classificationMap["Wand"] = Item.ClassificationType.wand;

            List<string> lines = new List<string>();

            using (StreamReader r = new StreamReader(file))
            {
                string line;
                while ((line = r.ReadLine()) != null)
                {
                    lines.Add(line);
                }
            }

            foreach (string line in lines)
            {
                try
                {
                    String[] tokens = line.Split('|');
                    if (tokens.Length == 0)
                        continue;
                    if (tokens.Length != 8)
                    {
                        Console.WriteLine("Invalid Token Count: {0}", tokens.Length);
                        throw new Exception("Unable to parse item data");
                    }
                    String name = tokens[0];
                    String code = tokens[1];
                    String classification_string = tokens[2];
                    UInt16 width = UInt16.Parse(tokens[3]);
                    UInt16 height = UInt16.Parse(tokens[4]);
                    bool stackable = UInt32.Parse(tokens[5]) != 0;
                    bool usable = UInt32.Parse(tokens[6]) != 0;
                    bool throwable = UInt32.Parse(tokens[7]) != 0;
                    Item.ClassificationType classification;
                    if (!classificationMap.TryGetValue(classification_string, out classification))
                        throw new Exception("Unable to parse item classification");
                    ItemEntry i = new ItemEntry(name, code, classification, width, height, stackable, usable, throwable);
                    m_items.Add(i);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error parsing ItemDataType: {0}", e.ToString());
                }
            }
        }
コード例 #2
0
ファイル: DataManager.cs プロジェクト: uvbs/OmegaBot
        public Boolean Get(String code, out ItemEntry output)
        {
            var items = from n in m_items where n.Type == code select n;

            foreach (ItemEntry i in items)
            {
                output = i;
                return true;
            }
            output = null;
            return false;
        }
コード例 #3
0
        public ItemDataType(String file)
        {
            m_items = new List <ItemEntry>();
            Dictionary <String, Item.ClassificationType> classificationMap = new Dictionary <string, Item.ClassificationType>();

            classificationMap["Amazon Bow"]                = Item.ClassificationType.amazon_bow;
            classificationMap["Amazon Javelin"]            = Item.ClassificationType.amazon_javelin;
            classificationMap["Amazon Spear"]              = Item.ClassificationType.amazon_spear;
            classificationMap["Amulet"]                    = Item.ClassificationType.amulet;
            classificationMap["Antidote Potion"]           = Item.ClassificationType.antidote_potion;
            classificationMap["Armor"]                     = Item.ClassificationType.armor;
            classificationMap["Arrows"]                    = Item.ClassificationType.arrows;
            classificationMap["Assassin Katar"]            = Item.ClassificationType.assassin_katar;
            classificationMap["Axe"]                       = Item.ClassificationType.axe;
            classificationMap["Barbarian Helm"]            = Item.ClassificationType.barbarian_helm;
            classificationMap["Belt"]                      = Item.ClassificationType.belt;
            classificationMap["Body Part"]                 = Item.ClassificationType.body_part;
            classificationMap["Bolts"]                     = Item.ClassificationType.bolts;
            classificationMap["Boots"]                     = Item.ClassificationType.boots;
            classificationMap["Bow"]                       = Item.ClassificationType.bow;
            classificationMap["Circlet"]                   = Item.ClassificationType.circlet;
            classificationMap["Club"]                      = Item.ClassificationType.club;
            classificationMap["Crossbow"]                  = Item.ClassificationType.crossbow;
            classificationMap["Dagger"]                    = Item.ClassificationType.dagger;
            classificationMap["Druid Pelt"]                = Item.ClassificationType.druid_pelt;
            classificationMap["Ear"]                       = Item.ClassificationType.ear;
            classificationMap["Elixir"]                    = Item.ClassificationType.elixir;
            classificationMap["Gem"]                       = Item.ClassificationType.gem;
            classificationMap["Gloves"]                    = Item.ClassificationType.gloves;
            classificationMap["Gold"]                      = Item.ClassificationType.gold;
            classificationMap["Grand Charm"]               = Item.ClassificationType.grand_charm;
            classificationMap["Hammer"]                    = Item.ClassificationType.hammer;
            classificationMap["Health Potion"]             = Item.ClassificationType.health_potion;
            classificationMap["Helm"]                      = Item.ClassificationType.helm;
            classificationMap["Herb"]                      = Item.ClassificationType.herb;
            classificationMap["Javelin"]                   = Item.ClassificationType.javelin;
            classificationMap["Jewel"]                     = Item.ClassificationType.jewel;
            classificationMap["Key"]                       = Item.ClassificationType.key;
            classificationMap["Large Charm"]               = Item.ClassificationType.large_charm;
            classificationMap["Mace"]                      = Item.ClassificationType.mace;
            classificationMap["Mana Potion"]               = Item.ClassificationType.mana_potion;
            classificationMap["Necromancer Shrunken Head"] = Item.ClassificationType.necromancer_shrunken_head;
            classificationMap["Paladin Shield"]            = Item.ClassificationType.paladin_shield;
            classificationMap["Polearm"]                   = Item.ClassificationType.polearm;
            classificationMap["Quest Item"]                = Item.ClassificationType.quest_item;
            classificationMap["Rejuvenation Potion"]       = Item.ClassificationType.rejuvenation_potion;
            classificationMap["Ring"]                      = Item.ClassificationType.ring;
            classificationMap["Rune"]                      = Item.ClassificationType.rune;
            classificationMap["Scepter"]                   = Item.ClassificationType.scepter;
            classificationMap["Scroll"]                    = Item.ClassificationType.scroll;
            classificationMap["Shield"]                    = Item.ClassificationType.shield;
            classificationMap["Small Charm"]               = Item.ClassificationType.small_charm;
            classificationMap["Sorceress Orb"]             = Item.ClassificationType.sorceress_orb;
            classificationMap["Spear"]                     = Item.ClassificationType.spear;
            classificationMap["Staff"]                     = Item.ClassificationType.staff;
            classificationMap["Stamina Potion"]            = Item.ClassificationType.stamina_potion;
            classificationMap["Sword"]                     = Item.ClassificationType.sword;
            classificationMap["Thawing Potion"]            = Item.ClassificationType.thawing_potion;
            classificationMap["Throwing Axe"]              = Item.ClassificationType.throwing_axe;
            classificationMap["Throwing Knife"]            = Item.ClassificationType.throwing_knife;
            classificationMap["Throwing Potion"]           = Item.ClassificationType.throwing_potion;
            classificationMap["Tome"]                      = Item.ClassificationType.tome;
            classificationMap["Torch"]                     = Item.ClassificationType.torch;
            classificationMap["Wand"]                      = Item.ClassificationType.wand;

            List <string> lines = new List <string>();

            using (StreamReader r = new StreamReader(file))
            {
                string line;
                while ((line = r.ReadLine()) != null)
                {
                    lines.Add(line);
                }
            }

            foreach (string line in lines)
            {
                try
                {
                    String[] tokens = line.Split('|');
                    if (tokens.Length == 0)
                    {
                        continue;
                    }
                    if (tokens.Length != 8)
                    {
                        Console.WriteLine("Invalid Token Count: {0}", tokens.Length);
                        throw new Exception("Unable to parse item data");
                    }
                    String name = tokens[0];
                    String code = tokens[1];
                    String classification_string = tokens[2];
                    UInt32 width     = UInt32.Parse(tokens[3]);
                    UInt32 height    = UInt32.Parse(tokens[4]);
                    bool   stackable = UInt32.Parse(tokens[5]) != 0;
                    bool   usable    = UInt32.Parse(tokens[6]) != 0;
                    bool   throwable = UInt32.Parse(tokens[7]) != 0;
                    Item.ClassificationType classification;
                    if (!classificationMap.TryGetValue(classification_string, out classification))
                    {
                        throw new Exception("Unable to parse item classification");
                    }
                    ItemEntry i = new ItemEntry(name, code, classification, width, height, stackable, usable, throwable);
                    m_items.Add(i);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error parsing ItemDataType: {0}", e.ToString());
                }
            }
        }