Ejemplo n.º 1
0
        public static void DropItem(string[] split, MapleClient c)
        {
            int itemId;

            if (int.TryParse(split[1], out itemId))
            {
                MapleCharacter chr = c.Account.Character;
                short          quantity;
                if (split.Length > 2)
                {
                    if (!short.TryParse(split[2], out quantity))
                    {
                        quantity = 1;
                    }
                }
                else
                {
                    quantity = 1;
                }
                MapleItem item = MapleItemCreator.CreateItem(itemId, "!dropitem by " + chr.Name, quantity);
                if (item == null)
                {
                    c.Account.Character.SendBlueMessage(String.Format("This item does not exist: {0}", itemId));
                }
                else
                {
                    Point targetPosition = chr.Map.GetDropPositionBelow(new Point(chr.Position.X, chr.Position.Y - 50), chr.Position);
                    chr.Map.SpawnMapItem(item, chr.Position, targetPosition, true, 0, chr);
                }
            }
        }
Ejemplo n.º 2
0
        public static void GetItem(string[] split, MapleClient c)
        {
            int itemId;

            if (int.TryParse(split[1], out itemId))
            {
                short quantity;
                if (split.Length > 2)
                {
                    if (!short.TryParse(split[2], out quantity))
                    {
                        quantity = 1;
                    }
                }
                else
                {
                    quantity = 1;
                }
                MapleItem item = MapleItemCreator.CreateItem(itemId, "!getitem by " + c.Account.Character.Name, quantity);
                if (item == null)
                {
                    c.Account.Character.SendBlueMessage(String.Format("This item does not exist: {0}", itemId));
                }
                else
                {
                    c.Account.Character.Inventory.AddItem(item, item.InventoryType, true);
                }
            }
        }
Ejemplo n.º 3
0
        public MapleItem TryGetStealableItem(int characterId, string characterName)
        {
            List <int> alreadyStolenItems;

            if (!stolenItems.TryGetValue(characterId, out alreadyStolenItems))
            {
                alreadyStolenItems = new List <int>();
            }
            int    potionId = IsBoss ? 2431835 : 2431835; //TODO: correct potion id
            string source   = string.Format("Steal skill from mob {0} by player {1}", WzInfo.MobId, characterName);

            if (!alreadyStolenItems.Contains(potionId))
            {
                MapleItem item = new MapleItem(potionId, source);
                AddStolenItem(characterId, potionId);
                return(item);
            }
            if (!IsBoss)
            {
                List <MobDrop> drops = DataBuffer.GetMobDropsById(WzInfo.MobId);
                foreach (MobDrop mobDrop in drops)
                {
                    if (mobDrop.QuestId > 0 || alreadyStolenItems.Contains(mobDrop.ItemId))
                    {
                        continue;
                    }
                    int chance = (int)(mobDrop.DropChance);
                    if (Functions.Random(0, 999999) <= chance)
                    {
                        int       amount = Functions.Random(mobDrop.MinQuantity, mobDrop.MaxQuantity);
                        MapleItem item   = MapleItemCreator.CreateItem(mobDrop.ItemId, source, (short)amount, true);
                        AddStolenItem(characterId, item.ItemId);
                        return(item);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        public static void HandleCraftDone(MapleClient c, PacketReader pr)
        {
            int            craftId    = pr.ReadInt();
            MapleCharacter Chr        = c.Account.Character;
            int            skillId    = (int)(10000 * Math.Floor((decimal)craftId / 10000));
            WzRecipe       recipeInfo = DataBuffer.GetCraftRecipeById(craftId);

            if (recipeInfo == null)
            {
                return;                     //Recipe not found, wierd, can happen due to packet edit
            }
            if (!EffectList.ContainsValue(skillId))
            {
                return;                                     //Should not happen unless if theres a packet edit or an update to the info compared to the code
            }
            if (!Chr.HasSkill(skillId) && Chr.HasSkill(recipeInfo.ReqSkill))
            {
                return;                                                              //Obviously packet edit
            }
            if (Chr.Map.MapId != 910001000 && (craftId % 92049000 > 7))
            {
                return;                                                         //Not in ardentmill, nor placing an extractor/fusing
            }
            if (Chr.GetSkillLevel(skillId) < recipeInfo.ReqSkillLevel)
            {
                return;                                                        //Not the correct level
            }
            if ((200 - Chr.Fatigue - recipeInfo.IncFatigue) < 0)
            {
                return;                    //Todo: show a message?
            }
            skillId = recipeInfo.ReqSkill; //Just to be sure

            Chr.Fatigue += recipeInfo.IncFatigue;
            if (craftId % 92049000 > 0 && craftId % 92049000 < 7)
            {
                //Todo: Add code for disassembling/fusing
                //Todo: Figure out what CraftId % 92049000 >= 2 do
                switch (craftId % 92049000)
                {
                case 0:
                    int  ExtractorId = pr.ReadInt();
                    int  ItemId      = pr.ReadInt();
                    long InventoryId = pr.ReadLong();
                    break;     //disassembling

                case 1:
                    ItemId      = pr.ReadInt();
                    InventoryId = pr.ReadLong();
                    long InventoryId2 = pr.ReadLong();
                    break;     //fusing
                }
                return;
            }
            if (recipeInfo.CreateItems.Count == 0)
            {
                return;
            }

            //Remove items
            bool HasItems = true;

            foreach (WzRecipe.Item Item in recipeInfo.ReqItems)
            {
                HasItems &= Chr.Inventory.HasItem(Item.ItemId, Item.Count);
            }
            if (!HasItems)
            {
                return;            //Todo: show message? "not enough items", though this smells like PE
            }
            foreach (WzRecipe.Item Item in recipeInfo.ReqItems)
            {
                Chr.Inventory.RemoveItemsById(Item.ItemId, Item.Count);
            }

            //Calculate what items to get
            //Todo: check with older sources to check if proccess aint missing any orignal functionality
            int TotalChance = recipeInfo.CreateItems.Where(x => x.Chance != 100).Sum(x => x.Chance);

            List <WzRecipe.Item> SuccesedItems = new List <WzRecipe.Item>();

            SuccesedItems.AddRange(recipeInfo.CreateItems.Where(x => x.Chance == 100));
            if (TotalChance == 0)
            {
                SuccesedItems.AddRange(recipeInfo.CreateItems.Where(x => x.Chance != 100));
            }
            else
            {
                Dictionary <int, int> ChanceCalc = new Dictionary <int, int>();
                int Last = 0;
                foreach (WzRecipe.Item Item in recipeInfo.CreateItems.Where(x => x.Chance != 100))
                {
                    if (ChanceCalc.ContainsKey(Item.ItemId))
                    {
                        continue;
                    }
                    ChanceCalc.Add(Item.ItemId, Item.Chance + Last);
                    Last += Item.Chance;
                }

                Random RandomCalc = new Random();
                int    PickItem   = RandomCalc.Next(TotalChance);
                SuccesedItems.Add(recipeInfo.CreateItems.FirstOrDefault(x => x.ItemId == ChanceCalc.FirstOrDefault(cc => cc.Value >= PickItem).Key));
            }

            if (SuccesedItems.Count == 0)
            {
                return;                           //Something went wrong
            }
            //Give character the new item(s)
            foreach (WzRecipe.Item Item in SuccesedItems)
            {
                MapleItem CreateItem = MapleItemCreator.CreateItem(Item.ItemId, "Crafting with skill " + skillId, Item.Count, true);
                Chr.Inventory.AddItem(CreateItem, CreateItem.InventoryType, true);
            }


            //Give character his Exp
            //Todo: check if character is given a junk item and lower the exp gained
            Skill CraftSkill = Chr.GetSkill(skillId);
            int   ReqLvlExp  = 50 * CraftSkill.Level ^ 2 + 200 * CraftSkill.Level;

            if (ReqLvlExp < CraftSkill.SkillExp + recipeInfo.IncProficiency)
            {
                int ExpLeft = (CraftSkill.SkillExp + recipeInfo.IncProficiency) % ReqLvlExp;
                Chr.SetSkillLevel(skillId, (byte)(CraftSkill.Level + 1));
                Chr.SetSkillExp(skillId, (short)ExpLeft);
                //Todo: broadcast levelup message
            }
            else
            {
                Chr.SetSkillExp(skillId, (short)(CraftSkill.SkillExp + recipeInfo.IncProficiency));
            }

            //Todo: figure out craftrankings
            MapleCharacter.UpdateSingleStat(c, MapleCharacterStat.Fatigue, recipeInfo.IncFatigue);
            Chr.Map.BroadcastPacket(ShowCraftComplete(Chr.Id, craftId, 23, SuccesedItems[0].ItemId, SuccesedItems[0].Count, recipeInfo.IncProficiency));
        }