コード例 #1
0
    protected static void ReadPets()
    {
        Pets = IterateAllToDict(pFile.BaseNode["Item"]["Pet"], pNode =>
        {
            int ID = (int)Utils.ConvertNameToID(pNode.Name);
            var pd = new PetData
            {
                ID        = ID,
                Reactions = new Dictionary <byte, PetReactionData>()
            };

            foreach (var mNode in pNode["interact"])
            {
                var prd = new PetReactionData
                {
                    ReactionID = byte.Parse(mNode.Name),
                    Inc        = mNode["inc"].ValueByte(),
                    Prob       = mNode["prob"].ValueByte(),
                    LevelMin   = mNode["l0"].ValueByte(),
                    LevelMax   = mNode["l1"].ValueByte()
                };
                pd.Reactions.Add(prd.ReactionID, prd);
            }

            foreach (var node in pNode["info"])
            {
                switch (node.Name)
                {
                case "icon":
                case "iconD":
                case "iconRaw":
                case "iconRawD":
                case "cash":
                    break;

                case "hungry":
                    pd.Hungry = node.ValueByte();
                    break;

                case "life":
                    pd.Life = node.ValueByte();
                    break;

                default:
                    Console.WriteLine($"Unhandled Pet node {node.Name} for id {ID}");
                    break;
                }
            }
            return(pd);
        }, x => x.ID);

        foreach (var node in pFile.BaseNode["String"]["Item.img"]["Pet"])
        {
            var itemId = int.Parse(node.Name);
            if (!Pets.ContainsKey(itemId))
            {
                Pets[itemId].Name = node["name"].ValueString();
            }
        }
    }
コード例 #2
0
ファイル: PetShop.cs プロジェクト: alanbraithwaite/cspetshop
 public void AddPet(string type, Animal pet)
 {
     if (!Pets.ContainsKey(type))
     {
         Pets.Add(type, new List <Animal>());
     }
     Pets[type].Add(pet);
 }
コード例 #3
0
ファイル: PetShop.cs プロジェクト: alanbraithwaite/cspetshop
 public void PrintType(string type)
 {
     if (Pets.ContainsKey(type))
     {
         System.Console.WriteLine(type.ToUpper());
         Pets[type].ForEach(pet =>
         {
             System.Console.WriteLine(pet.Name);
         });
     }
 }
コード例 #4
0
 public static void ReadItemNames()
 {
     foreach (var node in pFile.BaseNode["String"]["Item.img"])
     {
         if (node.Name == "Eqp")
         {
             foreach (var cat in node)
             {
                 ProcessNames(cat, (i, s) =>
                 {
                     if (!Equips.ContainsKey(i))
                     {
                         Trace.WriteLine($"Found name {s} for equip {i}, but equip did not exist!");
                     }
                     else
                     {
                         Equips[i].Name = s;
                     }
                 });
             }
         }
         else if (node.Name == "Pet")
         {
             ProcessNames(node, (i, s) =>
             {
                 if (!Pets.ContainsKey(i))
                 {
                     Trace.WriteLine($"Found name {s} for pet {i}, but pet did not exist!");
                 }
                 else
                 {
                     Pets[i].Name = s;
                 }
             });
         }
         else
         {
             ProcessNames(node, (i, s) =>
             {
                 if (!Items.ContainsKey(i))
                 {
                     Trace.WriteLine($"Found name {s} for item {i}, but item did not exist!");
                 }
                 else
                 {
                     Items[i].Name = s;
                 }
             });
         }
     }
 }
コード例 #5
0
        public static void Reload()
        {
            bool unload = false;

            if (pFile == null)
            {
                StartInit();
                unload = true;
            }

            Commodity.Clear();

            foreach (var node in pFile.BaseNode["Etc"]["Commodity.img"])
            {
                var snId   = node["SN"].ValueInt32();
                var itemId = node["ItemId"].ValueInt32();


                var ci = Commodity[snId] = new CommodityInfo
                {
                    Count        = node["Count"].ValueInt16(),
                    Gender       = (CommodityGenders)node["Gender"].ValueByte(),
                    ItemID       = itemId,
                    Period       = node["Period"].ValueInt16(),
                    OnSale       = node["OnSale"].ValueBool(),
                    Price        = node["Price"].ValueInt16(),
                    SerialNumber = snId
                };

                if (!Items.ContainsKey(itemId) &&
                    !Equips.ContainsKey(itemId) &&
                    !Pets.ContainsKey(itemId))
                {
                    Program.MainForm.LogAppend("Ignoring commodity SN {0} as it contains unknown itemid {1}", snId, itemId);

                    ci.OnSale     = false;
                    ci.StockState = StockState.NotAvailable;
                }

                if (ci.Price == 18000 && ci.OnSale)
                {
                    Program.MainForm.LogAppend("Making SN {0} itemid {1} not OnSale because its price is 18k", ci.SerialNumber, ci.ItemID);
                    ci.OnSale     = false;
                    ci.StockState = StockState.NotAvailable;
                }
            }

            Program.MainForm.LogAppend("Loaded {0} commodity items!", Commodity.Count);

            Packages.Clear();


            foreach (var node in pFile.BaseNode["Etc"]["CashPackage.img"])
            {
                var sn       = int.Parse(node.Name);
                var contents = node["SN"].Select(x => x.ValueInt32()).ToArray();
                var error    = false;
                foreach (var commoditySN in contents)
                {
                    if (Commodity.ContainsKey(commoditySN) == false)
                    {
                        error = true;
                        Program.MainForm.LogAppend("Ignoring Package {0} as it contains invalid commodity id {1}", sn, commoditySN);
                        break;
                    }
                }
                if (!error)
                {
                    Packages[sn] = contents;
                }
            }


            Program.MainForm.LogAppend("Loaded {0} cash packages!", Packages.Count);

            if (unload)
            {
                FinishInit();
            }
        }