Exemplo n.º 1
0
        public void OnOpenBook(Character sender)
        {
            Rag2Collection items = new Rag2Collection();

            foreach (Rag2Item c in Singleton.Itemdrops.FindItemDropsById(this.ModelId, sender._DropRate))
            {
                items.Add(c);
            }
            this.loottable.Add(sender.id, items);
        }
Exemplo n.º 2
0
        public Rag2Collection GetLootList(Character target)
        {
            Rag2Collection items;

            if (!loottable.TryGetValue(target.id, out items))
            {
                items = new Rag2Collection();
            }

            return(items);
        }
Exemplo n.º 3
0
 void IDisposable.Dispose()
 {
     GC.SuppressFinalize(this);
     isdisposed = true;
     lootlist   = null;
 }
Exemplo n.º 4
0
 public void Dispose()
 {
     isdisposed = true;
     lootlist   = null;
 }
Exemplo n.º 5
0
 private LootCollection()
 {
     this.lootlist = new Rag2Collection();
 }
Exemplo n.º 6
0
        /// <summary>
        /// Occurs when a player selects a drop from the droplist.
        /// </summary>
        /// <param name="cpkt"></param>
        private void CM_DROPSELECT(CMSG_DROPSELECT cpkt)
        {
            try
            {
                MapObject      target = null;
                Rag2Collection list   = null;
                LootCollection loot   = this.character.Tag as LootCollection;

                //Corpse disappeared already
                if (!Regiontree.TryFind(cpkt.ActorID, this.character, out target))
                {
                    SMSG_NPCDROPLISTRESULT spkt = new SMSG_NPCDROPLISTRESULT();
                    spkt.ActorID   = cpkt.ActorID;
                    spkt.Result    = 0;
                    spkt.SessionId = this.character.id;
                    this.Send((byte[])spkt);
                    return;
                }
                //Uknown looting error (not implamented itseems)
                else if (loot == null)
                {
                    SMSG_NPCDROPLISTRESULT spkt = new SMSG_NPCDROPLISTRESULT();
                    spkt.ActorID   = cpkt.ActorID;
                    spkt.Result    = 4;
                    spkt.SessionId = this.character.id;
                    this.Send((byte[])spkt);
                    return;
                }
                else
                {
                    list = loot.Lootlist;
                }



                //OBTAIN THE REQUIRED ITEMS FROM THE MERCHANT
                Rag2Item item = list[cpkt.Index];
                if (item == null)
                {
                    return;
                }

                //TEMP HELPER VARIABLES
                int        nstacked     = 0;
                List <int> update_queue = new List <int>();

                //WALKTHROUGH EVERY ITEM AND CHECK IF IT CAN BE STACKED
                foreach (int index in this.character.container.FindAllItems(item.info.item))
                {
                    Rag2Item invItem = this.character.container[index];
                    nstacked += Math.Min(0, (item.info.max_stack - invItem.count));
                    if (invItem.count < item.info.max_stack)
                    {
                        update_queue.Add(index);
                    }
                }

                //CALCULATE THE AMOUNT OF NEW SLOTS REQUIRED
                int req_hslot = (int)item.count % (int)this.character.container.Capacity;
                int req_slots = item.count;
                //int max_stack = (item.info.max_stack == 0) ? 1 : item.info.max_stack;
                if (item.info.max_stack > 0)
                {
                    int div_rem  = (int)((item.count - nstacked) / item.info.max_stack);
                    int div_rem2 = (req_hslot > 0) ? 1 : 0;
                    req_slots = div_rem + div_rem2;
                }

                if (this.character.container.Count + req_slots > this.character.container.Capacity)
                {
                    SMSG_NPCDROPLISTRESULT spkt = new SMSG_NPCDROPLISTRESULT();
                    spkt.ActorID   = cpkt.ActorID;
                    spkt.Result    = 3;
                    spkt.SessionId = this.character.id;
                    this.Send((byte[])spkt);
                    return;
                }


                //AMOUNT USED IN DECREMENT CALCULATIONS
                int amount = (int)item.count;

                //ITERATE THROUGH ALL AVAILABLE ITEM THAT CAN BE PROCESSED FOR UPDATES
                foreach (int invIndex in update_queue)
                {
                    Rag2Item invItem  = this.character.container[invIndex];
                    int      leftover = item.info.max_stack - invItem.count;
                    leftover       = Math.Max(0, Math.Min(amount, leftover));
                    invItem.count += leftover;
                    amount        -= leftover;

                    SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM();
                    spkt.Index        = (byte)invIndex;
                    spkt.UpdateReason = (byte)ItemUpdateReason.Obtained;
                    spkt.UpdateType   = 4;
                    spkt.Container    = 2;
                    spkt.Amount       = (byte)invItem.count;
                    spkt.SessionId    = this.character.id;
                    this.Send((byte[])spkt);
                }

                //ITERATE THROUGH EVERY FREE INDEX AND PROCESS IT
                foreach (int invIndex in this.character.container.FindFreeIndexes())
                {
                    if (amount == 0)
                    {
                        break;
                    }
                    int      leftover = Math.Min(amount, item.info.max_stack);
                    Rag2Item invItem  = item.Clone(leftover);
                    this.character.container[invIndex] = invItem;
                    amount -= leftover;

                    SMSG_ADDITEM spkt = new SMSG_ADDITEM();
                    spkt.Container    = 2;
                    spkt.UpdateReason = (byte)ItemUpdateReason.Obtained;
                    spkt.SetItem(invItem, invIndex);
                    spkt.SessionId = this.character.id;
                    this.Send((byte[])spkt);
                }

                //CHECK THE LIST
                if (amount == 0)
                {
                    list.RemoveAt(cpkt.Index);
                }
                else
                {
                    item.count = amount;
                }

                //REFRESH THE INVENTORY
                loot.Open(this.character, target);
                QuestBase.UserObtainedItem(item.info.item, this.character);

                if (this.character.sessionParty != null)
                {
                    for (int i = 0; i < this.character.sessionParty._Characters.Count; i++)
                    {
                        Character partyTarget = this.character.sessionParty._Characters[i];
                        if (partyTarget.id == this.character.id)
                        {
                            continue;
                        }
                        SMSG_PARTYMEMBERLOOT spkt2 = new SMSG_PARTYMEMBERLOOT();
                        spkt2.SessionId = partyTarget.id;
                        spkt2.Index     = (byte)(i + 1);
                        spkt2.ActorId   = this.character.id;
                        spkt2.ItemId    = item.info.item;
                        partyTarget.client.Send((byte[])spkt2);
                    }
                }
            }
            //CATCH ALL UNKNOWN ERRORS
            catch (Exception e)
            {
                SMSG_NPCDROPLISTRESULT spkt = new SMSG_NPCDROPLISTRESULT();
                spkt.ActorID   = cpkt.ActorID;
                spkt.Result    = 5;
                spkt.SessionId = this.character.id;
                this.Send((byte[])spkt);
                Console.WriteLine(e);
            }
        }