Exemple #1
0
        public void UseLotteryItem(short nPOS, int nItemID)
        {
            if (Parent.Stats.nHP <= 0)
            {
                return;
            }

            var pItemRaw = InventoryManipulator.GetItem(Parent, ItemConstants.GetInventoryType(nItemID), nPOS);             // TODO determine if we can hardcode the inventory type

            var itemResult = MasterManager.CreateItem(RandomBoxes.GetRandom(nItemID));

            if (itemResult != null && pItemRaw is GW_ItemSlotBundle pItem)
            {
                if (InventoryManipulator.CountFreeSlots(Parent, InventoryType.Equip) > 0 && InventoryManipulator.CountFreeSlots(Parent, InventoryType.Consume) > 0)
                {
                    InventoryManipulator.RemoveFrom(Parent, pItemRaw.InvType, nPOS);
                    InventoryManipulator.InsertInto(Parent, itemResult);
                }
                else
                {
                    Parent.SendMessage("Please make some room in your inventory.");
                }
            }
            else
            {
                Parent.SendMessage("This item has not been implemented yet. If you believe this to be an error, please report it on the discord server.");
            }
        }
Exemple #2
0
        /// <summary>
        /// Move an item from the character's account cash locker to the character's storage.
        /// </summary>
        /// <param name="c"></param>
        /// <param name="p"></param>
        public static void MoveLToS(WvsShopClient c, CInPacket p)
        {
            if (p.Available < 8)
            {
                return;
            }

            var sn = p.Decode8();

            var cashItem = c.CashLocker.GetBySN(sn);

            // unable to find item
            if (cashItem == null)
            {
                return;
            }

            var nTargetSlot = InventoryManipulator.InsertInto(c.Character, cashItem.Item);

            // item insertion failed
            if (nTargetSlot == 0)
            {
                return;                               // TODO proper error code/response
            }
            c.CashLocker.Remove(cashItem);

            c.SendPacket(CPacket.CCashShop.MoveLtoSResponse(cashItem, nTargetSlot));
        }
Exemple #3
0
        public static void Attempt(Character c)
        {
            if (Constants.Rand.NextDouble() > Constants.MobDeathRoulette_Odds)
            {
                return;
            }

            var roulette = new MobDeathRoulette();

            for (int i = -1; i < 3; i++)
            {
                var effect = new FieldEffectPacket(FieldEffect.Screen)
                {
                    sName = roulette.GetEffectString(i)
                };

                effect.Broadcast(c, true);
            }

            var pItem = MasterManager.CreateItem(roulette.nScrollItemID);

            pItem.nNumber = 1;

            // todo delay this
            InventoryManipulator.InsertInto(c, pItem);
        }
        public bool AddRandomMasteryBook(int nJobID = -1)
        {
            int bookid;

            if (nJobID == -1)
            {
                bookid = MasterManager.ItemTemplates
                         .MasteryBooks()
                         .Random()                // grab random set
                         .Random();               // grab random item from set
            }
            else
            {
                bookid = MasterManager.ItemTemplates
                         .MasteryBooksByJob(PlayerJob)
                         .Random();
            }

            if (bookid <= 0)
            {
                return(false);
            }

            var item = MasterManager.CreateItem(bookid);

            var slot = InventoryManipulator.InsertInto(Character, item);

            return(slot != 0);
        }
        public void OnLostQuestItem(CInPacket p, short nQuestID)
        {
            var nLostCount = p.Decode4();

            var pAct = MasterManager.QuestTemplates[nQuestID].StartAct;

            if (pAct is null)
            {
                return;                           // invalid quest ID
            }
            if (nLostCount <= 0 || pAct.Items.Length <= 0)
            {
                return;                                                        // TODO trigger AB, close socket
            }
            var aLostItem = p.DecodeIntArray(nLostCount);

            foreach (var item in pAct.Items)
            {
                if (!aLostItem.Contains(item.Item.ItemID))
                {
                    continue;                                                        // TODO trigger AB?
                }
                if (ItemConstants.GetInventoryType(item.Item.ItemID) == InventoryType.Equip)
                {
                    Parent.SendMessage("Not currently supported. Check again later.");
                    return;                     // TODO
                }

                if (!MasterManager.ItemTemplates[item.Item.ItemID]?.Quest ?? true)
                {
                    continue;
                }

                if (InventoryManipulator.HasSpace(Parent, item.Item.ItemID, (short)item.Item.Count))
                {
                    var itemToAdd = MasterManager.CreateItem(item.Item.ItemID);
                    itemToAdd.nNumber = (short)item.Item.Count;
                    InventoryManipulator.InsertInto(Parent, itemToAdd);
                }
                else
                {
                    // TODO proper response packet
                    Parent.SendMessage("Please make space in your inventory.");
                    return;
                }
            }

            // TODO
            // if ( aChangedItem.a && *(aChangedItem.a - 1) > 0u )
            //		CUser::PostQuestEffect(&v16->vfptr, 1, &aChangedItem, 0, 0);
        }
        public void AddItem(int itemId, short amount = 1)
        {
            var item = MasterManager.CreateItem(itemId);

            if (item is GW_ItemSlotBundle isb)
            {
                if (item.IsRechargeable == false)
                {
                    isb.nNumber = Math.Max((short)1, amount);
                }
            }

            InventoryManipulator.InsertInto(Character, item);

            Character.SendPacket(CPacket.DropPickUpMessage_Item(itemId, amount, true));
        }
Exemple #7
0
        private void Handle_CashShopCheckCouponRequest(WvsShopClient c, CInPacket p)
        {
            p.Decode2();             // something

            var code = p.DecodeString();

            var coupon = new CouponCode(code, c);

            if (coupon.Invalid)
            {
                c.SendPacket(CPacket.CCashShop.CouponFail(CashItemFailed.InvalidCoupon));
            }
            else if (coupon.Used)
            {
                c.SendPacket(CPacket.CCashShop.CouponFail(CashItemFailed.UsedCoupon));
            }
            else if (coupon.IncorrectAccount)
            {
                c.SendPacket(CPacket.CCashShop.CouponFail(CashItemFailed.NotAvailableCoupon));
            }
            else if (coupon.Expired)
            {
                c.SendPacket(CPacket.CCashShop.CouponFail(CashItemFailed.ExpiredCoupon));
            }
            else if (coupon.Items != null && !InventoryManipulator.HasSpace(c.Character, coupon.Items))
            {
                c.SendPacket(CPacket.CCashShop.CouponFail(CashItemFailed.NoEmptyPos));                 // TODO fix this
            }
            else
            {
                if (coupon.Items != null)
                {
                    foreach (var item in coupon.Items)
                    {
                        InventoryManipulator.InsertInto(c.Character, MasterManager.CreateItem(item, false));
                        CPacket.CCashShop.CouponAddItem(item);
                    }
                }

                c.Account.AccountData.NX_Prepaid += coupon.NX;
                coupon.Dispose();
                c.Account.Save();
            }

            c.EnableActions();
        }
        /// <summary>
        /// Transfer items from a temp inventory to a character inventory.
        /// No validation is done to see if the items will fit.
        /// At the end of this method the temp inventory is cleared.
        /// </summary>
        /// <param name="pChar">Character to transfer items to.</param>
        /// <param name="pTempInv">Inventory to transfer items from.</param>
        /// <param name="bSubtractFee">If the money being transferred should have the trade fee deducted.</param>
        private void TransferItems(Character pChar, TempInventory pTempInv, bool bSubtractFee)
        {
            foreach (var item in pTempInv.GetAll())
            {
                InventoryManipulator.InsertInto(pChar, item.Item);
            }

            if (pTempInv.Meso > 0)
            {
                if (bSubtractFee)
                {
                    pTempInv.Meso -= Fee((int)pTempInv.Meso);
                }

                pChar?.Modify.GainMeso((int)pTempInv.Meso);
            }

            pTempInv.Clear();
        }
Exemple #9
0
        /// <summary>
        /// Performs consume on pickup logic and inserts item into inventory
        ///		if it fits. Will return false if item does not fit.
        /// Some field child classes change drop pickup behavior.
        /// If returns true, the drop pool will remove the drop and display
        ///		proper drop pickup messages, else calling function will return.
        /// </summary>
        /// <param name="pUser">Character picking up the item</param>
        /// <param name="pDrop">Item being picked up</param>
        public virtual bool TryDropPickup(Character pUser, CDrop pDrop)
        {
            if (pDrop.Item.Template is ConsumeItemTemplate template)
            {
                if (template.MonsterBook)
                {
                    pUser.MonsterBook.AddCard(pDrop.ItemId);
                    pUser.SendMessage("You have found a monster book card!");
                    pUser.Modify.GainNX(1000);

                    return(false);
                }

                if (template.ConsumeOnPickup)
                {
                    pUser.Buffs.AddItemBuff(template.TemplateId);
                    return(false);
                }
            }

            return(InventoryManipulator.InsertInto(pUser, pDrop.Item) > 0);
        }
Exemple #10
0
        public override void Execute(CommandCtx ctx)
        {
            var itemId = ctx.NextInt();

            var sCount = !ctx.Empty ? ctx.NextString() : null;
            var nCount = 1;

            if (sCount is object)
            {
                if (!int.TryParse(sCount, out nCount))
                {
                    ctx.Character.SendMessage("Unable to parse count.");
                    return;
                }
            }

            var character = ctx.Character;

            var nInvType = ItemConstants.GetInventoryType(itemId);

            if (InventoryManipulator.CountFreeSlots(character, nInvType) > 0)
            {
                var item = MasterManager.CreateItem(itemId);

                if (item is null)
                {
                    return;
                }

                if (item is GW_ItemSlotBundle isb)
                {
                    isb.nNumber = (short)Math.Min(nCount, item.SlotMax);
                }

                InventoryManipulator.InsertInto(character, item);
                character.SendPacket(CPacket.DropPickUpMessage_Item(itemId, nCount, true));
            }
        }
Exemple #11
0
        public void RemoveItem(CInPacket p)
        {
            // Recv [CP_MiniRoom] [90 00] [26] 01 00

            var nShopSlot = p.Decode2();

            var tItem = Inventory.GetAndRemove(nShopSlot);

            if (tItem is null)
            {
                // do nothing
            }
            else if (InventoryManipulator.CountFreeSlots(Parent, tItem.Item.InvType) <= 0)
            {
                Parent.SendMessage("Please make room in your inventory.");
            }
            else
            {
                InventoryManipulator.InsertInto(Parent, tItem.Item);
            }

            Refresh(Parent);
        }
Exemple #12
0
        private static void BuyItem(Character pChar, short nPos, int nItemId, short nCount)
        {
            var cShop = pChar.Socket.ActiveShop;

            // price is 0 for invis items
            if (!cShop.ContainsItem(nItemId) ||
                cShop.GetItemPrice(nItemId) <= 0 ||
                cShop.GetItemLevelLimited(nItemId) > pChar.Stats.nLevel)
            {
                pChar.SendMessage("Trying to buy an item that doesn't exist in the shop.");
                pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.BuyUnknown));
                return;
            }

            nCount = ItemConstants.is_treat_singly(nItemId) ? (short)1 : nCount;

            var nPricePerCount = cShop.GetItemPrice(nItemId);
            var nFinalPrice    = nPricePerCount * nCount;

            if (nFinalPrice > pChar.Stats.nMoney)
            {
                pChar.SendMessage("Trying to buy an item without enough money.");
                pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.BuyNoMoney));
                return;
            }

            var nInvType = ItemConstants.GetInventoryType(nItemId);

            if (InventoryManipulator.CountFreeSlots(pChar, nInvType) < 1)
            {
                pChar.SendMessage("Please make some space in your inventory.");
                pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.BuyUnknown));
                return;
            }

            var pItem = MasterManager.CreateItem(nItemId, false);

            var slotmax = pItem.SlotMax;

            if (pChar.Skills.Get(false,
                                 (int)Skills.NIGHTWALKER_JAVELIN_MASTERY,
                                 (int)Skills.ASSASSIN_JAVELIN_MASTERY) is SkillEntry se)
            {
                slotmax += (short)se.Y_Effect;
            }

            if (slotmax < nCount * cShop.GetItemQuantity(nItemId))
            {
                pChar.SendMessage("Unable to purchase more than one slot of items at a time.");
                pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.BuyUnknown));
                return;
            }

            pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.BuySuccess));

            pItem.nNumber = (short)(pItem.IsRechargeable ? slotmax : nCount * cShop.GetItemQuantity(nItemId));

            pChar.SendMessage("final price: " + nFinalPrice);

            InventoryManipulator.InsertInto(pChar, pItem);
            pChar.Modify.GainMeso(-nFinalPrice, false);
        }
Exemple #13
0
        public void SellItem(Character c, CInPacket p)
        {
            var nShopSlot = p.Decode1();
            var nQuantity = Math.Max((byte)1, p.Decode2());

            var pItem = Inventory.GetItemInSlot(nShopSlot);

            if (pItem is null || pItem.Item is null)
            {
                return; // some kind of fuckery is going on
            }

            var nFinalQuantity = nQuantity * pItem.ItemsInBundle;
            var nFinalPrice    = nFinalQuantity * pItem.Price;

            if (nFinalPrice > c.Stats.nMoney)
            {
                c.SendMessage("no monies");
                return;
            }

            if (nFinalQuantity > pItem.NumberOfBundles * pItem.ItemsInBundle)
            {
                c.SendMessage("no items");
                return;
            }

            if (InventoryManipulator.CountFreeSlots(c, pItem.Item.InvType) <= 0)
            {
                c.SendMessage("no space make space pls");
                return;
            }

            GW_ItemSlotBase iToAdd;

            if (pItem.Item is GW_ItemSlotEquip)
            {
                iToAdd = pItem.Item;
                pItem.NumberOfBundles = 0;
            }
            else
            {
                iToAdd         = pItem.Item.DeepCopy();
                iToAdd.nNumber = (short)nFinalQuantity;

                pItem.NumberOfBundles -= (short)nFinalQuantity;
            }

            c.Modify.GainMeso(-nFinalPrice);
            c.Stats.MerchantMesos += GetTax(nFinalPrice) + nFinalPrice;
            InventoryManipulator.InsertInto(c, iToAdd);

            ItemsSold.Add(new SoldItemData
            {
                BuyerName = c.Stats.sCharacterName,
                nItemID   = iToAdd.nItemID,
                Quantity  = (short)nFinalQuantity,
                Price     = nFinalPrice
            });

            Parent?.SendMessage($"Player '{c.Stats.sCharacterName}' has purchased an item from your shop for {nFinalPrice} mesos! You have {pItem.NumberOfBundles} quantity remaining.");
        }
        private static void HandleCreateItemOp(Character pChar, int nItemID, bool bStimulantUsed, List <int> aGems)
        {
            // BEGIN VERIFICATION

            //var pMakerItem = MasterManager.EtcTemplates.MakerData(nItemID);
            var makerItem = MasterManager.ItemMakeTemplates[nItemID];

            // verify maker item exists
            if (makerItem is null)
            {
                pChar.SendMessage("Null item maker template.");
                return;
            }

            // verify player is high enough level to use recipe
            if (makerItem.ReqLevel > pChar.Stats.nLevel + 6)
            {
                pChar.SendMessage("Verify the item level you're trying to craft is no more than 6 above your own.");
                return;
            }

            // verify player has enough meso
            if (makerItem.Meso > pChar.Stats.nMoney)
            {
                pChar.SendMessage("Verify you have the correct amount of mesos.");
                return;
            }

            var pCharMakerSkill = pChar.Skills.Get(Common.GameLogic.SkillLogic.get_novice_skill_as_race(Common.GameLogic.SkillLogic.NoviceSkillID.MakerSkill, pChar.Stats.nJob));

            // verify player maker skill level is high enough
            if (makerItem.ReqSkillLevel > (pCharMakerSkill?.nSLV ?? 0))
            {
                pChar.SendMessage($"Verify maker skill level. {makerItem.ReqSkillLevel} < {(pCharMakerSkill?.nSLV ?? 0)}");
                return;
            }

            var(nStimulantItemSlot, pStimulantItem) = InventoryManipulator.GetAnyItem(pChar, InventoryType.Etc, makerItem.CatalystID);

            // verify stimulant (catalyst) exists in player inventory
            if (bStimulantUsed && pStimulantItem is null)
            {
                pChar.SendMessage("Verify you possess the correct stimulant item.");
                return;
            }

            // verify equip slot availability
            if (InventoryManipulator.CountFreeSlots(pChar, InventoryType.Equip) < 1)
            {
                pChar.SendMessage("Please make more room in your equip inventory.");
                return;
            }

            if (InventoryManipulator.CountFreeSlots(pChar, InventoryType.Etc) < makerItem.RandomReward.Length)
            {
                pChar.SendMessage("Please make more room in your etc inventory.");
                return;
            }

            // verify required items exist in player inventory
            if (makerItem.Recipe.Any(item => !InventoryManipulator.ContainsItem(pChar, item.ItemID, (short)item.Count)))
            {
                pChar.SendMessage("Verify you possess all the required components.");
                return;
            }

            var aGemItemIds   = new List <int>();
            var aGemItemTypes = new List <int>();

            // remove duplicate items/types and get item slots for gems
            foreach (var entry in aGems)
            {
                var(nGemSlot, pGemItem) = InventoryManipulator.GetAnyItem(pChar, InventoryType.Etc, entry);

                if (pGemItem is null || nGemSlot == 0 || !(pGemItem.Template is GemEffectTemplate))
                {
                    continue;
                }

                // idk how it would be 0 but we check anyway
                if (!aGemItemTypes.Contains(entry / 100) &&
                    !aGemItemIds.Contains(pGemItem.nItemID) &&
                    pGemItem.nNumber > 0)
                {
                    aGemItemIds.Add(pGemItem.nItemID);
                    aGemItemTypes.Add(entry / 100);
                }
            }

            // END VERIFICATION

            // BEGIN RECIPE PROCESSING

            // remove meso cost from inventory
            if (makerItem.Meso > 0)
            {
                pChar.Modify.GainMeso(-makerItem.Meso);
            }

            // remove stimulant from inventory
            if (bStimulantUsed)
            {
                InventoryManipulator.RemoveQuantity(pChar, pStimulantItem.nItemID, 1);
            }

            // remove recipe items from inventory
            foreach (var item in makerItem.Recipe)
            {
                InventoryManipulator.RemoveQuantity(pChar, item.ItemID, (short)item.Count);
            }

            var bSuccess = true;

            if (bStimulantUsed && Constants.Rand.Next(100) >= 90)
            {
                bSuccess = false;
            }
            else
            {
                // BEGIN MAKER ITEM CREATION

                var pNewItemRaw = MasterManager.CreateItem(makerItem.TemplateId);

                if (pNewItemRaw is GW_ItemSlotEquip pNewItemEquip)
                {
                    pNewItemEquip.RemainingUpgradeCount = (byte)makerItem.TUC;

                    // remove gems from inventory
                    foreach (var nGemItemId in aGemItemIds)
                    {
                        var pGemItemRaw = InventoryManipulator.GetAnyItem(pChar, InventoryType.Etc, nGemItemId).Item2;

                        if (pGemItemRaw.Template is GemEffectTemplate pGemItem)
                        {
                            // gems only have one modifier each
                            if (pGemItem.incPAD > 0)
                            {
                                pNewItemEquip.niPAD += (short)(pGemItem.incPAD * (bStimulantUsed ? 2 : 1));
                            }
                            else if (pGemItem.incPDD > 0)
                            {
                                pNewItemEquip.niPDD += (short)(pGemItem.incPDD * (bStimulantUsed ? 2 : 1));
                            }
                            else if (pGemItem.incMAD > 0)
                            {
                                pNewItemEquip.niMAD += (short)(pGemItem.incMAD * (bStimulantUsed ? 2 : 1));
                            }
                            else if (pGemItem.incMDD > 0)
                            {
                                pNewItemEquip.niMDD += (short)(pGemItem.incMDD * (bStimulantUsed ? 2 : 1));
                            }

                            else if (pGemItem.incSTR > 0)
                            {
                                pNewItemEquip.niSTR += (short)(pGemItem.incSTR * (bStimulantUsed ? 2 : 1));
                            }
                            else if (pGemItem.incINT > 0)
                            {
                                pNewItemEquip.niINT += (short)(pGemItem.incINT * (bStimulantUsed ? 2 : 1));
                            }
                            else if (pGemItem.incDEX > 0)
                            {
                                pNewItemEquip.niDEX += (short)(pGemItem.incDEX * (bStimulantUsed ? 2 : 1));
                            }
                            else if (pGemItem.incLUK > 0)
                            {
                                pNewItemEquip.niLUK += (short)(pGemItem.incLUK * (bStimulantUsed ? 2 : 1));
                            }

                            else if (pGemItem.incACC > 0)
                            {
                                pNewItemEquip.niACC += (short)(pGemItem.incACC * (bStimulantUsed ? 2 : 1));
                            }
                            else if (pGemItem.incEVA > 0)
                            {
                                pNewItemEquip.niEVA += (short)(pGemItem.incEVA * (bStimulantUsed ? 2 : 1));
                            }
                            else if (pGemItem.incMaxHP > 0)
                            {
                                pNewItemEquip.niMaxHP += (short)(pGemItem.incMaxHP * (bStimulantUsed ? 2 : 1));
                            }
                            else if (pGemItem.incMaxMP > 0)
                            {
                                pNewItemEquip.niMaxMP += (short)(pGemItem.incMaxMP * (bStimulantUsed ? 2 : 1));
                            }

                            else if (pGemItem.incJump > 0)
                            {
                                pNewItemEquip.niJump += (short)(pGemItem.incJump * (bStimulantUsed ? 2 : 1));
                            }
                            else if (pGemItem.incSpeed > 0)
                            {
                                pNewItemEquip.niSpeed += (short)(pGemItem.incSpeed * (bStimulantUsed ? 2 : 1));
                            }

                            else if (pGemItem.incReqLevel < 0)
                            {
                                pNewItemEquip.nLevel = (byte)(pNewItemEquip.nLevel + (pGemItem.incReqLevel * (bStimulantUsed ? 2 : 1)));
                            }

                            else if (pGemItem.RandOption > 0)
                            {
                                var gX = new GaussianRandom();

                                var nRange = pGemItem.RandOption * (bStimulantUsed ? 2 : 1);

                                if (pNewItemEquip.niMaxHP > 0)
                                {
                                    pNewItemEquip.niMaxHP = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niMaxHP, nRange, false));
                                }
                                if (pNewItemEquip.niMaxMP > 0)
                                {
                                    pNewItemEquip.niMaxMP = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niMaxMP, nRange, false));
                                }

                                if (pNewItemEquip.niPAD > 0)
                                {
                                    pNewItemEquip.niPAD = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niPAD, nRange, false));
                                }
                                if (pNewItemEquip.niMAD > 0)
                                {
                                    pNewItemEquip.niMAD = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niMAD, nRange, false));
                                }
                                if (pNewItemEquip.niPDD > 0)
                                {
                                    pNewItemEquip.niPDD = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niPDD, nRange, false));
                                }
                                if (pNewItemEquip.niMDD > 0)
                                {
                                    pNewItemEquip.niMDD = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niMDD, nRange, false));
                                }

                                if (pNewItemEquip.niSpeed > 0)
                                {
                                    pNewItemEquip.niSpeed = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niSpeed, nRange, false));
                                }
                                if (pNewItemEquip.niJump > 0)
                                {
                                    pNewItemEquip.niJump = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niJump, nRange, false));
                                }
                            }
                            // pNewItemEquip.ApplyRandStatOption(pGemItem.RandOption * (bStimulantUsed ? 2 : 1), false);
                            else if (pGemItem.RandStat > 0)
                            {
                                var gX = new GaussianRandom();

                                var nRange = pGemItem.RandStat * (bStimulantUsed ? 2 : 1);

                                if (pNewItemEquip.niSTR > 0)
                                {
                                    pNewItemEquip.niSTR = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niSTR, nRange, false));
                                }
                                if (pNewItemEquip.niLUK > 0)
                                {
                                    pNewItemEquip.niLUK = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niLUK, nRange, false));
                                }
                                if (pNewItemEquip.niINT > 0)
                                {
                                    pNewItemEquip.niINT = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niINT, nRange, false));
                                }
                                if (pNewItemEquip.niDEX > 0)
                                {
                                    pNewItemEquip.niDEX = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niDEX, nRange, false));
                                }

                                if (pNewItemEquip.niACC > 0)
                                {
                                    pNewItemEquip.niACC = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niACC, nRange, false));
                                }
                                if (pNewItemEquip.niEVA > 0)
                                {
                                    pNewItemEquip.niEVA = (short)Math.Max(0, gX.GaussianDistributionVariation(pNewItemEquip.niEVA, nRange, false));
                                }
                            }
                        }
                    }

                    InventoryManipulator.InsertInto(pChar, pNewItemEquip);
                }
                else
                {
                    pNewItemRaw.nNumber = (short)makerItem.ItemNum;
                    InventoryManipulator.InsertInto(pChar, pNewItemRaw);
                }

                // remove gems if any
                foreach (var nGemItemId in aGemItemIds)
                {
                    InventoryManipulator.RemoveQuantity(pChar, nGemItemId, 1);                     //InventoryManipulator.RemoveFrom(pChar, (byte)InventoryType.Etc, itemSlot, 1);
                }

                foreach (var entry in makerItem.RandomReward)
                {
                    if (Constants.Rand.Next(100) >= entry.Prob)
                    {
                        continue;
                    }

                    var pRandRewardItem = MasterManager.CreateItem(entry.ItemID);

                    pRandRewardItem.nNumber = (short)entry.ItemNum;

                    InventoryManipulator.InsertInto(pChar, pRandRewardItem);
                }

                // END MAKER ITEM CREATION
            }

            // END RECIPE PROCESSING

            // SEND RESPONSE PACKETS

            pChar.SendPacket(CreateItemResponse(bSuccess, bStimulantUsed, makerItem, aGemItemIds));

            pChar.SendPacket(MakerItemEffectLocal(bSuccess));
            pChar.Field.Broadcast(MakerItemEffectRemote(pChar.dwId, bSuccess));
        }
        public QuestResultType TryExchange(int nIncMoney, QuestAct.ActItem[] aActItem)
        {
            if (nIncMoney == 0 && aActItem.Length <= 0)
            {
                return(QuestResultType.Success);
            }

            if (nIncMoney < 0 &&
                Parent.Stats.nMoney < nIncMoney)
            {
                return(QuestResultType.Failed_Meso);
            }

            foreach (var item in aActItem)
            {
                if (item.Item.Count > 0)
                {
                    if (!InventoryManipulator.HasSpace(Parent, item.Item.ItemID, (short)item.Item.Count))
                    {
                        return(QuestResultType.Failed_Inventory);                        // -> Etc inventory is full
                    }
                }
                else
                {
                    if (!InventoryManipulator.ContainsItem(Parent, item.Item.ItemID, (short)item.Item.Count))
                    {
                        return(QuestResultType.Failed_Unknown);                        // idk what code to give them
                    }
                }
            }

            Parent.Modify.GainMeso(nIncMoney);

            var weight = 0;

            foreach (var item in aActItem)
            {
                if (item.ProbRate != 0)
                {
                    weight += item.ProbRate;
                }
            }

            var itemGiven = false;

            foreach (var item in aActItem.Shuffle())
            {
                if (item.Item.Count < 0)
                {
                    InventoryManipulator.RemoveQuantity(Parent, item.Item.ItemID, (short)item.Item.Count);
                }
                else
                {
                    if (item.ProbRate == 0)
                    {
                        var newItem = MasterManager.CreateItem(item.Item.ItemID, false);
                        if (!newItem.IsEquip)
                        {
                            newItem.nNumber = (short)item.Item.Count;
                        }

                        InventoryManipulator.InsertInto(Parent, newItem);
                    }
                    else if (!itemGiven)
                    {
                        var rand = Constants.Rand.Next(0, weight);

                        if (rand < item.ProbRate)
                        {
                            var newItem = MasterManager.CreateItem(item.Item.ItemID, false);
                            if (!newItem.IsEquip)
                            {
                                newItem.nNumber = (short)item.Item.Count;
                            }

                            InventoryManipulator.InsertInto(Parent, newItem);
                            itemGiven = true;
                        }
                        else
                        {
                            weight -= item.ProbRate;
                        }
                    }
                }
            }

            return(QuestResultType.Success);
        }
Exemple #16
0
        public override bool TryDropPickup(Character pUser, CDrop pDrop)
        {
            if (!aTeams.ContainsKey(pUser.dwId))
            {
                return(false);
            }

            var bUserIsWolf = aTeams[pUser.dwId] == BattlefieldData.BattlefieldTeams.Wolves;

            var bKeepItem = true;

            switch ((BattlefieldData.BattleItems)pDrop.Item.nItemID)
            {
            // let sheep pick these up
            case BattlefieldData.BattleItems.CryOfLamb:
            case BattlefieldData.BattleItems.LambSurpriseAttack:
            case BattlefieldData.BattleItems.SoundOfSheepBells:
            {
                bKeepItem = !bUserIsWolf;
            }
            break;

            case BattlefieldData.BattleItems.GreatConfusion:
            case BattlefieldData.BattleItems.WoundOfWolfBells:
            case BattlefieldData.BattleItems.WolfThreat:
            {
                bKeepItem = bUserIsWolf;
            }
            break;

            case BattlefieldData.BattleItems.FineWool:
            {
                if (!bUserIsWolf)
                {
                    bKeepItem = false;

                    var user = Convert.ToInt32(pDrop.QR);

                    if (aTeams.ContainsKey(user))
                    {
                        ChangePlayerTeam(user, BattlefieldData.BattlefieldTeams.Sheep);

                        aSheepPoints[user] += 1;

                        if (aSheepPoints[user] > POINTS_PER_SHEEP)
                        {
                            aSheepPoints[user] = POINTS_PER_SHEEP;
                        }
                    }
                }
                else
                {
                    // player keeps item, score is reduced if player is still in
                    if (aTeams.ContainsKey(Convert.ToInt32(pDrop.QR)))
                    {
                        UpdateScore(BattlefieldData.BattlefieldTeams.Sheep, -1);
                    }
                }
            }
            break;

            case BattlefieldData.BattleItems.ShepherdBoysLunch:
            {
                if (bUserIsWolf)
                {
                    bKeepItem = false;
                }
                else
                {
                    // else player keeps item, score is reduced
                    UpdateScore(BattlefieldData.BattlefieldTeams.Wolves, -1);
                }
            }
            break;
            }

            if (bKeepItem)
            {
                if (InventoryManipulator.InsertInto(pUser, pDrop.Item) <= 0)
                {
                    return(false);
                }
            }
            else
            {
                Drops.Remove(pDrop);
                return(false);
            }

            return(true);
        }
        public override void Execute(CommandCtx ctx)
        {
            if (ctx.Empty)
            {
                ctx.Character.SendMessage("!test <ftype | event | makerskill>");
            }
            else
            {
                switch (ctx.NextString().ToLowerInvariant())
                {
                case "instance":
                    ctx.Character.SendMessage($"Instance: {ctx.Character.Field.nInstanceID}");
                    break;

                case "potential":
                    if (ctx.Empty)
                    {
                        return;
                    }

                    var itemid = ctx.NextInt();

                    var pots = new int[3];

                    var i = 0;
                    while (!ctx.Empty)
                    {
                        pots[i] = ctx.NextInt();
                        i      += 1;
                    }

                    var pItem = MasterManager.CreateItem(itemid, false) as GW_ItemSlotEquip;

                    if (pItem is null)
                    {
                        return;
                    }

                    pItem.nGrade = PotentialGradeCode.Visible_Unique;

                    pItem.nOption1 = (short)pots[0];
                    pItem.nOption2 = (short)pots[1];
                    pItem.nOption3 = (short)pots[2];

                    InventoryManipulator.InsertInto(ctx.Character, pItem);

                    break;

                case "sheepranch":
                    ctx.Character.Action.SetFieldInstance(BattlefieldData.BattleMap, 1);
                    break;

                case "sethorns":
                    ctx.Character.Buffs.AddSkillBuff((int)Skills.BOWMASTER_SHARP_EYES, 30);
                    ctx.Character.Buffs.AddSkillBuff((int)Skills.DUAL5_THORNS_EFFECT, 30);
                    break;

                case "makerskill":
                    ctx.Character.Skills.Add(new SkillEntry(1007)
                    {
                        nSLV = 1
                    });
                    break;

                case "ftype":
                    ctx.Character.SendMessage("Map Field Type: " + Enum.GetName(typeof(FieldType), ctx.Character.Field.Template.FieldType));
                    break;

                case "event":
                    MasterManager.EventManager.TryDoEvent(true);
                    break;

                case "shop":
                {
                    var pShop = new CShop(69);

                    pShop.Items.Add(new CShopItem(0));

                    pShop.AddDefaultItems();

                    MasterManager.ShopManager.InitUserShop(ctx.Character, 9900000, pShop);
                }
                break;

                case "balloon":
                    ctx.SendPacket(CPacket.BalloonMessage("Hello World!", 96));
                    break;

                default:
                    ctx.Character.SendMessage("No test command with that argument.");
                    break;
                }
            }

            return;

            foreach (var mob in ctx.Character.Field.Mobs)
            {
                ctx.Character.SendMessage($"{mob.nMobTemplateId}");
            }
            return;

            int imob = 0;

            foreach (var mob in ctx.Character.Field.Mobs.aMobGen)
            {
                if (mob.FH == 0)
                {
                    imob += 1;
                }
            }
            ctx.Character.SendMessage($"Mobs with FH 0: {imob}");
            ctx.Character.SendMessage($"Mobs In Map: {ctx.Character.Field.Mobs.Count} || Spawns: {ctx.Character.Field.Mobs.aMobGen.Count}");
            return;

            //foreach(var reactor in ctx.Character.Field.Reactors)
            //{
            //	reactor.IncreaseReactorState(0, 0);
            //}

            //return;
            ctx.Character.Action.SetFieldInstance(240060200, Constants.Rand.Next(), 0);

            return;

            var drop = new CDrop(ctx.Character.Position, ctx.Character.dwId)
            {
                ItemId = 100
            };

            drop.Position.X = drop.StartPosX;
            drop.CalculateY(ctx.Character.Field, drop.StartPosY);

            ctx.Character.Field.Drops.Add(drop);

            return;

            ctx.Character.SendMessage("" + Enum.GetName(typeof(FieldType), ctx.Character.Field.Template.FieldType));

            return;

            var p    = new COutPacket(SendOps.LP_Clock);
            var type = ctx.NextInt();

            p.Encode1((byte)type);
            switch (type)
            {
            case 0:                       // OnEventTimer
                p.Encode4(ctx.NextInt()); // nDuration

                break;

            case 1:                             // Clock
                p.Encode1((byte)ctx.NextInt()); // nHour
                p.Encode1((byte)ctx.NextInt()); // nMin
                p.Encode1((byte)ctx.NextInt()); // nSec

                break;

            case 2:                       // Timer
                p.Encode4(ctx.NextInt()); // tDuration (0 to disable the clock)

                break;

            case 3:                             // some kind of event timer also
                p.Encode1((byte)ctx.NextInt()); // bool (on/off)
                p.Encode4(ctx.NextInt());       // tDuration

                break;

            case 100:                           // cakepie event timer
                p.Encode1((byte)ctx.NextInt()); // bool (timer on/off)
                p.Encode1((byte)ctx.NextInt()); // nTimerType
                p.Encode4(ctx.NextInt());       // tDuration

                break;
            }

            ctx.Character.SendPacket(p);

            for (int i = 0; i < 2; i++)
            {
                var p2 = new COutPacket(SendOps.LP_CakePieEventResult);
                p2.Encode1(1);                         // bool -> continue while loop
                p2.Encode4(ctx.Character.Field.MapId); // fieldid
                p2.Encode4(4220176);                   // itemid
                p2.Encode1(25);                        // percentage
                p2.Encode1((byte)ctx.NextInt());       // eventstatus
                p2.Encode1((byte)(i + 1));             // nwinnerteam
                p2.Encode1(0);                         // end while loop

                ctx.SendPacket(p2);
            }

            return;

            //var poo = ctx.Character.Pets.Pets[0];

            //if (poo != null)
            //{
            //	ctx.Character.SendMessage($"{poo.Position.X} || {poo.Position.Y}");
            //}

            //var p = new COutPacket(SendOps.LP_AvatarMegaphoneUpdateMessage);
            //var x = new AvatarMegaphone
            //{
            //	nItemID = 05390000,
            //	sName = "pooodop",
            //	sMsgs = new string[5] { "one", "  two", " three", "    four", " five" },
            //	nChannelNumber = 1,
            //	bWhisper = true,
            //	alSender = ctx.Character.GetLook()
            //};

            //x.Encode(p);

            //MasterManager.CharacterPool.Broadcast(p);

            //var nItemID = ctx.NextInt();

            //ctx.Character.Modify.Inventory(inv =>
            //{
            //	for (short i = 1; i <= ctx.Character.InventoryEquip.SlotLimit; i++)
            //	{
            //		ctx.Character.InventoryEquip.Remove(i);
            //		var newItem = MasterManager.CreateItem(nItemID) as GW_ItemSlotEquip;
            //		newItem.nGrade = PotentialGradeCode.Visible_Unique;
            //		newItem.nOption1 = (int)PotentialLineIDs.LEARN_SKILL_HASTE;
            //		ctx.Character.InventoryEquip.Add(i, newItem);
            //		inv.Add(InventoryType.Equip, i, newItem);
            //	}

            //	var magnifyingGlass = MasterManager.CreateItem(02460003) as GW_ItemSlotBundle;
            //	magnifyingGlass.nNumber = 500; // pretty sure i can override the 100 slotmax lol
            //	ctx.Character.InventoryConsume.Remove(15);
            //	ctx.Character.InventoryConsume.Add(15, magnifyingGlass);

            //	inv.Remove(InventoryType.Consume, 15);
            //	inv.Add(InventoryType.Consume, 15, magnifyingGlass);

            //});

            //return;

            //foreach (var item in ctx.Character.InventoryEquip)
            //{
            //	ctx.Character.Action.ConsumeItem.UseMagnifyingGlass(15, item.Key);
            //	item.Value.sTitle = $"{item.Value.nOption1}|{item.Value.nOption2}";
            //}

            //ctx.Character.InventoryEquip.RemoveAllItems(ctx.Character); // gotta cc for this to take effect so we can look then cc to clean inv

            // ctx.Character.SendPacket(CPacket.UserOpenUI((UIWindow)ctx.NextInt()));

            //ctx.Character.Field.bPauseSpawn = !ctx.Character.Field.bPauseSpawn;

            //ctx.Character.Modify.Stats(mod => mod.SP += (short)ctx.NextInt());

            //var p = new COutPacket(SendOps.LP_UserEffectLocal);

            //for (int i = 8; i >= 1; i--)
            //{
            //    p.Encode4(i == statup.getPosition() ? statup.getValue() : 0);
            //}

            //p.Encode1(1); // skill use
            //p.Encode4(22160000); // skillID
            //p.Encode1(100); // nCharLevel
            //p.Encode1(1); // nSLV
            //p.Encode1(1);

            //ctx.SendPacket(p);

            //ctx.Character.SendMessage($"You have {ctx.Character.Buffs.Count} buffs.");

            //var pChar = ctx.Character;

            //if (pChar.PlayerGuild == null)
            //{
            //    var name = ctx.NextString();
            //    MasterManager.GuildManager.Add(new Guild(name, pChar.dwId));
            //}
            //else
            //{
            //    var p = new COutPacket(SendOps.LP_GuildResult);
            //    p.Encode1((byte)ctx.NextInt());

            //    pChar.SendPacket(p);
            //}
            //var storage = ServerApp.Container.Resolve<CenterStorage>();
            //var sub = storage.Multiplexer().GetSubscriber();

            //sub.Publish("donate", $"{character.AccId}/5000");

            // character.Modify.GainNX(1000);

            // character.SendPacket(CPacket.OpenClassCompetitionPage());

            //var stat = new SecondaryStat();

            //var entry = new SecondaryStatEntry()
            //{
            //    nValue = 10,
            //    rValue = 2001002,
            //    tValue = 110000,
            //};

            //stat.Add(SecondaryStatType.MagicGuard, entry);
            //stat.Add(SecondaryStatType.Flying, entry);

            //character.SendPacket(CPacket.TemporaryStatSetLocal(stat));
            //character.Field.Broadcast(CPacket.UserTemporaryStatSet(stat, character.CharId));

            //var summon = new CSummon();
            //summon.Parent = character;
            //summon.dwSummonedId = 2330810;
            //summon.nSkillID = 14001005;

            //summon.Position.Position.X = character.Position.Position.X;
            //summon.Position.Position.Y = character.Position.Position.Y;
            //summon.Position.Foothold = character.Position.Foothold;

            //summon.nCharLevel = character.Stats.nLevel;
            //summon.nSLV = 1;
            //summon.bMoveAbility = 1;
            //summon.bAssistType = 1;
            //summon.nEnterType = 1;

            //character.Summons.Add(summon);

            //character.SendPacket(CPacket.TradeMoneyLimit(true));
            //character.SendPacket(CPacket.WarnMessage("YEOOOOOO THIS IS A WARNING BOY"));
            //character.SendPacket(CPacket.AdminShopCommodity(9900000));
            //character.SendPacket(CPacket.StandAloneMode(true));
            //character.SendPacket(CPacket.LogoutGift());

            //character.SendPacket(CPacket.UserHireTutor(true));
            //character.SendPacket(CPacket.UserTutorMsg(Constants.ServerMessage2,400,60000));

            //character.SendPacket(CPacket.HontaleTimer(0,5));
            //character.SendPacket(CPacket.HontaleTimer(1, 5));
            //character.SendPacket(CPacket.HontaleTimer(2, 5));
            //character.SendPacket(CPacket.HontaleTimer(3, 5));

            //character.SendPacket(CPacket.HontailTimer(0,69));
            //character.SendPacket(CPacket.HontailTimer(1, 69));
            //character.SendPacket(CPacket.HontailTimer(0, 0));

            //var town = new CTownPortal();
            //town.dwCharacterID = character.dwId;
            //town.Position.X = character.Position.X;
            //town.Position.Y = character.Position.Y;

            //character.Field.TownPortals.Add(town);

            //character.SendPacket(CPacket.DragonEnterField(character.dwId, character.Position.X, character.Position.Y, 0, 2218));
            //character.Dragon = new CDragon(character);
            //character.Dragon.JobCode = 2218;
            //character.Dragon.Position.X = character.Position.X;
            //character.Dragon.Position.Y = character.Position.Y;


            //    var gate1 = new COpenGate()
            //    {
            //        dwCharacterID = character.dwId,
            //    };

            //    gate1.Position.X = character.Position.X;
            //    gate1.Position.Y = character.Position.Y;

            //    character.Field.OpenGates1.Add(gate1);

            //    var gate2 = new COpenGate()
            //    {
            //        dwCharacterID = character.dwId,
            //    };

            //    gate2.Position.X = character.Position.X;
            //    gate2.Position.X -= 250;

            //    gate2.Position.Y = character.Position.Y;

            //    character.Field.OpenGates2.Add(gate2);


            //character.SendPacket(CPacket.StageChange("ThemeBack1.img", 0));

            //character.Field.Employees.RemoveAt(0);

            //character.SendPacket(CPacket.SetBackgroundEffect(2, 100000000, 1, 30 * 1000));

            //character.SendPacket(CPacket.Desc(true));

            //character.SendPacket(CPacket.StalkResult(character.dwId, character.Stats.sCharacterName, character.Position.X, character.Position.Y));

            //character.SendPacket(CPacket.PlayJukeBox("Hydromorph"));
            //character.SendPacket(CPacket.BlowWeather(0, 5120000, "Hello Twitch!!!"));

            //character.SendPacket(CPacket.AntiMacroResult(6, "SnitchNigga")); //Crash
            //character.SendPacket(CPacket.AntiMacroResult(7, "SnitchNigga")); //This dude reported you !

            //Diemension mirror reeeeeeeeeeeeeee
            //var p = NpcScript.ScriptMessageHeader(0, 9900000, ScriptMsgType.AskSlideMenu);
            //p.Encode4(0); //dlg type
            //p.Encode4(0); //index?
            //p.EncodeString("Hello World");
            //character.SendPacket(p);

            //var pet = new CPet(ctx.Character);
            //pet.nIdx = 0;
            //pet.liPetLockerSN = 9001;
            //pet.dwTemplateID = 5000102;
            //pet.sName = "Charlie";
            //pet.Position.X = character.Position.X;
            //pet.Position.Y = character.Position.Y;

            //ctx.Character.Pets.Add(pet.liPetLockerSN, pet);
        }