コード例 #1
0
        /**
         * Client sends cash item SN.
         * We index cash items by their serial number.
         * WZ files indexes cash items by a commodity ID.
         * The commodity ID (~12000 total) is not used for anything.
         */
        public static void Buy(WvsShopClient c, CInPacket p)
        {
            // validate packet length
            if (p.Available < 9)
            {
                return;
            }

            p.Decode1();             // 00
            var cashType     = (CashType)p.Decode4();
            var nCommoditySN = p.Decode4();

            var commodityInfo = MasterManager.CommodityProvider[nCommoditySN];

            if (commodityInfo == null)
            {
                return;
            }
            if (!commodityInfo.OnSale)
            {
                return;                                    // TODO proper error code/response
            }
            var item = MasterManager.CreateCashCommodityItem(nCommoditySN);

            if (item is null)
            {
                return;
            }

            if (!c.Account.HasCash(cashType, item.NXCost))
            {
                return;                                                        // TODO proper error code/response
            }
            if (ItemConstants.IsPet(item.nItemID) &&
                InventoryManipulator.GetItemByCashSN(c.Character, InventoryType.Cash, item.SN).Item2 != null)
            {
                return;                 // cant have two of the same pet cuz it screws up our indexing
            }
            c.CashLocker.Add(item);
#if DEBUG
            c.Account.ModifyCash(cashType, 10000);
            Log.Info($"{commodityInfo.CashItemSN}");
#else
            c.Account.ModifyCash(cashType, -commodityInfo.Price);
#endif
            item.dwAccountID   = c.Account.ID;
            item.dwCharacterID = c.dwCharId;

            c.SendPacket(CPacket.CCashShop.BuyResponse(item));
            // do best items/limited goods handling here
        }
コード例 #2
0
        public static GW_ItemSlotBase CreateItem(int nItemID, bool bRandStats = true)
        {
            if (nItemID <= 0)
            {
                return(null);
            }

            // TODO test the below
            if (ItemConstants.GetInventoryType(nItemID) != InventoryType.Equip)
            {
                GW_ItemSlotBase item;
                if (ItemConstants.IsPet(nItemID))
                {
                    item = new GW_ItemSlotPet(nItemID);
                    ((GW_ItemSlotPet)item).nRemainLife = 7776000;
                }
                else
                {
                    item = new GW_ItemSlotBundle(nItemID);
                }

                if (item.Template is null)
                {
                    throw new ArgumentOutOfRangeException(nameof(nItemID), "Doesn't exist in data files.");
                }

                if (ItemConstants.IsRechargeableItem(item.nItemID))
                {
                    item.nNumber = (short)item.Template.SlotMax;
                }
                else
                {
                    item.nNumber = 1;
                }

                item.tDateExpire = DateTime.MaxValue;

                return(item);
            }

            if (bRandStats)
            {
                return(CreateVariableStatEquip(nItemID));
            }

            return(CreateNormalStatEquip(nItemID));
        }
コード例 #3
0
        private void AddGridRow(DataGridView grid, object wzObject) {
            int id;
            string name = null;
            WzObject png;
            string properties = GetAllProperties(wzObject);

            if (wzObject is WzImage img) {
                id = int.Parse(Path.GetFileNameWithoutExtension(img.Name));
                WzImageProperty link = img.GetFromPath("info/link");
                if (link is WzStringProperty) {
                    string linkName = ((WzStringProperty) link).Value;
                    img = ((WzDirectory) img.Parent).GetChildImages().Find(p => p.Name.Equals(linkName + ".img"));
                    if (img == null) return;
                }

                png = img.GetFromPath("stand/0");
                if (img.WzFileParent.Name.StartsWith("Npc")) {
                    // icon path like: '{ID}/stand/0'
                    name = StringWz.GetNpc(id);
                } else if (img.WzFileParent.Name.StartsWith("Mob")) {
                    // icon path like: '{ID}/(move|stand|fly)/0'
                    name = StringWz.GetMob(id);
                    if (png == null) {
                        png = img.GetFromPath("fly/0") ??
                              img.GetFromPath("move/0"); // attempt to get image of the monster
                    }
                } else if (img.WzFileParent.Name.StartsWith("Reactor")) {
                    name = img.GetFromPath("action")?.GetString();
                    png = img.GetFromPath("0/0");
                } else if (img.WzFileParent.Name.StartsWith("Map")) {
                    name = StringWz.GetFieldFullName(id);
                    png = img.GetFromPath("miniMap/canvas");
                } else {
                    // for breadcrumb like: '{ID}.img/info/icon'
                    if (ItemConstants.IsEquip(id)) name = StringWz.GetEqp(id);
                    else if (ItemConstants.IsPet(id)) name = StringWz.GetPet(id);
                    png = img.GetFromPath("info/icon");
                }
            } else if (wzObject is WzSubProperty subProperty) {
                id = int.Parse(subProperty.Name);

                if (subProperty.WzFileParent.Name.StartsWith("Skill")) {
                    name = StringWz.GetSkill(subProperty.Name);
                    properties = GetAllProperties(subProperty);
                    png = subProperty.GetFromPath("icon");
                } else {
                    // for path like: 'category.img/{ID}/info/icon' (Etc.wz)
                    id = int.Parse(subProperty.Name);
                    if (ItemConstants.IsEtc(id)) name = StringWz.GetEtc(id);
                    else if (ItemConstants.IsCash(id)) name = StringWz.GetCash(id);
                    else if (ItemConstants.IsChair(id)) name = StringWz.GetChair(id);
                    else if (ItemConstants.IsConsume(id)) name = StringWz.GetConsume(id);

                    png = subProperty.GetFromPath("info/icon");
                }
            } else return;

            if (grid.Parent is DataViewport dv) {
                ((List<BinData>)dv.Tag)?.Add(new BinData(id, png?.GetBitmap(), name, properties));
            }
            grid.Rows.Add(id, png?.GetBitmap(), name, properties);
        }