public void RemoveAll(int id, MapleClient cl)
        {
            var possessed =
                cl.Player.Inventorys[MapleItemInformationProvider.Instance.GetInventoryType(id).Value].CountById(id);

            if (possessed > 0)
            {
                MapleInventoryManipulator.RemoveById(cl, MapleItemInformationProvider.Instance.GetInventoryType(id), id,
                                                     possessed, true, false);
                cl.Send(PacketCreator.GetShowItemGain(id, (short)-possessed, true));
            }
        }
        /**
         * remove all items of type from party; combination of haveItem and gainItem
         */

        public void RemoveFromParty(int id, List <MapleCharacter> party)
        {
            foreach (var chr in party)
            {
                var cl       = chr.Client;
                var type     = MapleItemInformationProvider.Instance.GetInventoryType(id);
                var iv       = cl.Player.Inventorys[type.Value];
                var possesed = iv.CountById(id);

                if (possesed > 0)
                {
                    MapleInventoryManipulator.RemoveById(Client,
                                                         MapleItemInformationProvider.Instance.GetInventoryType(id), id, possesed, true, false);
                    cl.Send(PacketCreator.GetShowItemGain(id, (short)-possesed, true));
                }
            }
        }
        /**
         * PQ methods: give items/exp to all party members
         */

        public void GivePartyItems(int id, short quantity, List <MapleCharacter> party)
        {
            foreach (var chr in party)
            {
                var cl = chr.Client;
                if (quantity >= 0)
                {
                    string logInfo =
                        $"{cl.Player.Name} received {quantity} from event {chr.EventInstanceManager.Name}";

                    MapleInventoryManipulator.AddById(cl, id, quantity, logInfo);
                }
                else
                {
                    MapleInventoryManipulator.RemoveById(cl, MapleItemInformationProvider.Instance.GetInventoryType(id),
                                                         id, -quantity, true, false);
                }
                cl.Send(PacketCreator.GetShowItemGain(id, quantity, true));
            }
        }
        public bool AddItem(int id, short quantity, bool randomStats)
        {
            if (quantity >= 0)
            {
                var    ii      = MapleItemInformationProvider.Instance;
                var    item    = ii.GetEquipById(id);
                var    type    = ii.GetInventoryType(id);
                string logInfo =
                    $"{Player.Name} received {quantity} frome a scripted PlayerInteraction ({ToString()})";

                if (!MapleInventoryManipulator.CheckSpace(Client, id, quantity, ""))
                {
                    var invtype = ii.GetInventoryType(id);
                    Client.Send(PacketCreator.ServerNotice(PacketCreator.ServerMessageType.Popup, "你的背包已满"));
                    return(false);
                }
                if (type == MapleInventoryType.Equip && !ii.IsThrowingStar(item.ItemId) && !ii.IsBullet(item.ItemId))
                {
                    if (randomStats)
                    {
                        MapleInventoryManipulator.AddFromDrop(Client, ii.RandomizeStats((Equip)item), false, logInfo);
                    }
                    else
                    {
                        MapleInventoryManipulator.AddFromDrop(Client, (Equip)item, false, logInfo);
                    }
                }
                else
                {
                    MapleInventoryManipulator.AddById(Client, id, quantity, logInfo);
                }
            }
            else
            {
                MapleInventoryManipulator.RemoveById(Client, MapleItemInformationProvider.Instance.GetInventoryType(id),
                                                     id, -quantity, true, false);
            }
            Client.Send(PacketCreator.GetShowItemGain(id, quantity, true));
            return(true);
        }
예제 #5
0
        public void Run(MapleCharacter c, int?extSelection)
        {
            MapleQuestStatus status;

            switch (Type)
            {
            case MapleQuestActionType.Exp:
                status = c.GetQuest(m_quest);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                c.GainExp(MapleDataTool.GetInt(Data) * c.Client.ChannelServer.ExpRate, true, true);
                break;

            case MapleQuestActionType.Item:
                var ii    = MapleItemInformationProvider.Instance;
                var props = new Dictionary <int, int>();
                foreach (var iEntry in Data.Children)
                {
                    if (iEntry.GetChildByPath("prop") != null &&
                        MapleDataTool.GetInt(iEntry.GetChildByPath("prop")) != -1 && CanGetItem(iEntry, c))
                    {
                        for (var i = 0; i < MapleDataTool.GetInt(iEntry.GetChildByPath("prop")); i++)
                        {
                            props.Add(props.Count, MapleDataTool.GetInt(iEntry.GetChildByPath("id")));
                        }
                    }
                }
                var selection = 0;
                var extNum    = 0;
                if (props.Any())
                {
                    props.TryGetValue((int)(Randomizer.NextDouble() * props.Count), out selection);
                }
                foreach (var iEntry in Data.Children)
                {
                    if (!CanGetItem(iEntry, c))
                    {
                        continue;
                    }
                    if (iEntry.GetChildByPath("prop") != null)
                    {
                        if (MapleDataTool.GetInt(iEntry.GetChildByPath("prop")) == -1)
                        {
                            if (extSelection.HasValue && extSelection.Value != extNum++)
                            {
                                continue;
                            }
                        }
                        else if (MapleDataTool.GetInt(iEntry.GetChildByPath("id")) != selection)
                        {
                            continue;
                        }
                    }
                    if (MapleDataTool.GetInt(iEntry.GetChildByPath("count"), 0) < 0)
                    {
                        // remove items

                        var itemId   = MapleDataTool.GetInt(iEntry.GetChildByPath("id"));
                        var iType    = ii.GetInventoryType(itemId);
                        var quantity = (short)(MapleDataTool.GetInt(iEntry.GetChildByPath("count"), 0) * -1);
                        try
                        {
                            //MapleInventoryManipulator.removeById(c.Client, iType, itemId, quantity, true, false);
                        }
                        catch
                        {
                            Console.WriteLine("Completing a quest without meeting the requirements");
                        }
                        c.Client.Send(PacketCreator.GetShowItemGain(itemId,
                                                                    (short)MapleDataTool.GetInt(iEntry.GetChildByPath("count"), 0), true));
                    }
                    else
                    {
                        // add items

                        var itemId   = MapleDataTool.GetInt(iEntry.GetChildByPath("id"));
                        var quantity = (short)MapleDataTool.GetInt(iEntry.GetChildByPath("count"), 0);
                        var logInfo  = new StringBuilder(c.Name);
                        logInfo.Append(" received ");
                        logInfo.Append(quantity);
                        logInfo.Append(" as reward from a quest");
                        // MapleInventoryManipulator.addById(c.Client, itemId, quantity, logInfo.ToString(), null, -1);
                        c.Client.Send(PacketCreator.GetShowItemGain(itemId, quantity, true));
                    }
                }
                break;

            case MapleQuestActionType.Nextquest:
                status = c.GetQuest(m_quest);
                var nextQuest = MapleDataTool.GetInt(Data);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                c.Client.Send(PacketCreator.UpdateQuestFinish((short)m_quest.GetQuestId(), status.Npcid,
                                                              (short)nextQuest));
                MapleQuest.GetInstance(nextQuest).Start(c, status.Npcid);
                break;

            case MapleQuestActionType.Meso:
                status = c.GetQuest(m_quest);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                c.GainMeso(MapleDataTool.GetInt(Data), true, false, true);
                break;

            case MapleQuestActionType.Quest:
                foreach (var qEntry in Data)
                {
                    var questid = MapleDataTool.GetInt(qEntry.GetChildByPath("id"));
                    var stat    = MapleDataTool.GetInt(qEntry.GetChildByPath("state"), 0);
                    c.UpdateQuest(new MapleQuestStatus(MapleQuest.GetInstance(questid), (MapleQuestStatusType)stat));
                }
                break;

            case MapleQuestActionType.Skill:
                foreach (var sEntry in Data)
                {
                    var skillid        = MapleDataTool.GetInt(sEntry.GetChildByPath("id"));
                    var skillLevel     = (byte)MapleDataTool.GetInt(sEntry.GetChildByPath("skillLevel"));
                    var masterLevel    = (byte)MapleDataTool.GetInt(sEntry.GetChildByPath("masterLevel"));
                    var skillObject    = SkillFactory.GetSkill(skillid);
                    var shouldLearn    = false;
                    var applicableJobs = sEntry.GetChildByPath("job");
                    foreach (var applicableJob in applicableJobs)
                    {
                        var job = MapleJob.GetByJobId(MapleDataTool.GetShort(applicableJob));
                        if (c.Job == job)
                        {
                            shouldLearn = true;
                            break;
                        }
                    }
                    if (skillObject.IsBeginnerSkill)
                    {
                        shouldLearn = true;
                    }
                    skillLevel  = Math.Max(skillLevel, c.GetSkillLevel(skillObject));
                    masterLevel = Math.Max(masterLevel, skillObject.MaxLevel);
                    if (shouldLearn)
                    {
                        c.ChangeSkillLevel(skillObject, skillLevel, masterLevel);
                        c.DropMessage(
                            $"你已获得 {SkillFactory.GetSkillName(skillid)} 当前等级 {skillLevel} 最高等级 {masterLevel}");
                    }
                }
                break;

            case MapleQuestActionType.Fame:
                status = c.GetQuest(m_quest);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                c.Fame += MapleDataTool.GetShort(Data);
                c.UpdateSingleStat(MapleStat.Fame, c.Fame);
                var fameGain = MapleDataTool.GetInt(Data);
                c.Client.Send(PacketCreator.GetShowFameGain(fameGain));
                break;

            case MapleQuestActionType.Buff:
                status = c.GetQuest(m_quest);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                var mii = MapleItemInformationProvider.Instance;
                //mii.GetItemEffect(MapleDataTool.GetInt(data)).applyTo(c);
                break;

            case MapleQuestActionType.Petskill:
                status = c.GetQuest(m_quest);
                if (status.Status == MapleQuestStatusType.NotStarted && status.Forfeited > 0)
                {
                    break;
                }
                var flag = MapleDataTool.GetInt("petskill", Data);
                //c.getPet(0).setFlag((byte)(c.getPet(0).getFlag() | InventoryConstants.Items.Flags.getFlagByInt(flag)));
                break;

            default:
                break;
            }
        }
예제 #6
0
        public static bool AddFromDrop(MapleClient c, IMapleItem item, bool show, string loginfo = "")
        {
            var ii   = MapleItemInformationProvider.Instance;
            var type = ii.GetInventoryType(item.ItemId);

            if (!c.ChannelServer.AllowMoreThanOne && ii.IsPickupRestricted(item.ItemId) &&
                c.Player.HaveItem(item.ItemId, 1, true, false))
            {
                c.Send(PacketCreator.GetInventoryFull());
                c.Send(PacketCreator.ShowItemUnavailable());
                return(false);
            }
            var quantity = item.Quantity;

            if (quantity >= 4000 || quantity < 0)
            {
                AutobanManager.Instance.Autoban(c, $"XSource| PE Item: {quantity} x {item.ItemId}");
                return(false);
            }
            if (type != MapleInventoryType.Equip)
            {
                var slotMax  = ii.GetSlotMax(c, item.ItemId);
                var existing = c.Player.Inventorys[type.Value].ListById(item.ItemId);
                if (!ii.IsThrowingStar(item.ItemId) && !ii.IsBullet(item.ItemId))
                {
                    if (existing.Any())
                    {
                        var i = existing.GetEnumerator();
                        while (quantity > 0)
                        {
                            if (i.MoveNext())
                            {
                                var eItem = (Item)i.Current;
                                if (eItem != null)
                                {
                                    var oldQ = eItem.Quantity;
                                    if (oldQ < slotMax && item.Owner == eItem.Owner)
                                    {
                                        var newQ = (short)Math.Min(oldQ + quantity, slotMax);
                                        quantity      -= (short)(newQ - oldQ);
                                        eItem.Quantity = newQ;
                                        c.Send(PacketCreator.UpdateInventorySlot(type, eItem, true));
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    // add new slots if there is still something left
                    while (quantity > 0 || ii.IsThrowingStar(item.ItemId) || ii.IsBullet(item.ItemId))
                    {
                        var newQ = Math.Min(quantity, slotMax);
                        quantity -= newQ;
                        var nItem = new Item(item.ItemId, 0, newQ)
                        {
                            Owner = item.Owner
                        };
                        var newSlot = c.Player.Inventorys[type.Value].AddItem(nItem);
                        if (newSlot == 0xFF)
                        {
                            c.Send(PacketCreator.GetInventoryFull());
                            c.Send(PacketCreator.GetShowInventoryFull());
                            item.Quantity = (short)(quantity + newQ);
                            return(false);
                        }
                        c.Send(PacketCreator.AddInventorySlot(type, nItem, true));
                    }
                }
                else
                {
                    // Throwing Stars and Bullets - Add all into one slot regardless of quantity.
                    var nItem   = new Item(item.ItemId, 0, quantity);
                    var newSlot = c.Player.Inventorys[type.Value].AddItem(nItem);
                    if (newSlot == 0xFF)
                    {
                        c.Send(PacketCreator.GetInventoryFull());
                        c.Send(PacketCreator.GetShowInventoryFull());
                        return(false);
                    }
                    c.Send(PacketCreator.AddInventorySlot(type, nItem));
                    c.Send(PacketCreator.EnableActions());
                }
            }
            else
            {
                if (quantity == 1)
                {
                    var newSlot = c.Player.Inventorys[type.Value].AddItem(item);

                    if (newSlot == 0xFF)
                    {
                        c.Send(PacketCreator.GetInventoryFull());
                        c.Send(PacketCreator.GetShowInventoryFull());
                        return(false);
                    }
                    c.Send(PacketCreator.AddInventorySlot(type, item, true));
                }
                else
                {
                    throw new Exception("Trying to create equip with non-one quantity");
                }
            }
            if (show)
            {
                c.Send(PacketCreator.GetShowItemGain(item.ItemId, item.Quantity));
            }
            return(true);
        }