Example #1
0
        private static LockerItem CreateLockerItem(int userId, CommodityInfo ci, string buyCharacterName)
        {
            var expiration = ci.Period > 0 ? Tools.GetFileTimeWithAddition(new TimeSpan(ci.Period, 0, 0, 0)) : BaseItem.NoItemExpiration;
            var item       = new LockerItem()
            {
                ItemId           = ci.ItemID,
                Amount           = ci.Count,
                CashId           = 0,                // Will be created on insert
                Expiration       = expiration,
                BuyCharacterName = buyCharacterName, // Empty, only set when gift
                CharacterId      = 0,                // 0, as its in the locker
                CommodityId      = ci.SerialNumber,
                GiftUnread       = string.IsNullOrEmpty(buyCharacterName) == false,
                UserId           = userId
            };

            return(item);
        }
        public static BaseItem CreateCashItem(LockerItem li, CommodityInfo ci)
        {
            li.CashId  = (long)((long)(Rand32.Next()) << 32 | Rand32.Next());
            li.CashId &= 0x00FFFFFFFFFFFFFF; // Get rid of the first byte

            var item = BaseItem.CreateFromItemID(li.ItemId);

            item.Amount     = li.Amount;
            item.CashId     = li.CashId;
            item.Expiration = li.Expiration;

            if (item is PetItem pi)
            {
                pi.Name      = DataProvider.Pets[pi.ItemID].Name;
                pi.Closeness = 0;
                pi.Fullness  = 100;
                pi.Level     = 1;
            }

            return(item);
        }
Example #3
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();
            }
        }