/// <summary> /// Try to loot the item at the given index of the current loot /// </summary> /// <returns>The looted Item or null if Item could not be taken</returns> public void TakeItem(LooterEntry entry, uint index, BaseInventory targetCont, int targetSlot) { LootItem lootItem = null; try { var chr = entry.Owner; if (chr != null && index < Items.Length) { lootItem = Items[index]; var err = CheckTakeItemConditions(entry, lootItem); if (err == InventoryError.OK) { HandoutItem(chr, lootItem, targetCont, targetSlot); } else { ItemHandler.SendInventoryError(chr.Client, null, null, err); } } } catch (Exception e) { LogUtil.ErrorException(e, "{0} threw an Exception while looting \"{1}\" (index = {2}) from {3}", entry.Owner, lootItem, index, targetCont); } }
protected void Dispose() { if (this.Looters == null) { return; } IList <LooterEntry> looters = this.Looters; this.Looters = (IList <LooterEntry>)null; for (int index = 0; index < looters.Count; ++index) { LooterEntry looterEntry = looters[index]; Character owner = looterEntry.Owner; if (owner != null) { LootHandler.SendLootReleaseResponse(owner, this); } if (looterEntry.Loot == this) { looterEntry.Loot = (Loot)null; } } this.OnDispose(); }
/// <summary> /// Returns whether the given looter may loot the given Item. /// Make sure the Looter is logged in before calling this Method. /// /// TODO: Find the right error messages /// TODO: Only give every MultiLoot item to everyone once! Also check for quest-dependencies etc. /// </summary> public InventoryError CheckTakeItemConditions(LooterEntry looter, LootItem item) { if (item.Taken) { return(InventoryError.ALREADY_LOOTED); } if (item.RollProgress != null) { return(InventoryError.DONT_OWN_THAT_ITEM); } if (!looter.MayLoot(this)) { return(InventoryError.DontReport); } ICollection <LooterEntry> multiLooters = item.MultiLooters; if (multiLooters != null) { if (multiLooters.Contains(looter)) { return(InventoryError.OK); } if (looter.Owner != null) { LootHandler.SendLootRemoved(looter.Owner, item.Index); } return(InventoryError.DONT_OWN_THAT_ITEM); } return(!item.Template.CheckLootConstraints(looter.Owner) || this.Method != LootMethod.FreeForAll && (item.Template.Quality > this.Group.LootThreshold && !item.Passed || this.Group.MasterLooter != null && this.Group.MasterLooter != looter.Owner.GroupMember) ? InventoryError.DONT_OWN_THAT_ITEM : InventoryError.OK); }
/// <summary> /// Try to loot the item at the given index of the current loot /// </summary> /// <returns>The looted Item or null if Item could not be taken</returns> public void TakeItem(LooterEntry entry, uint index, BaseInventory targetCont, int targetSlot) { LootItem lootItem = (LootItem)null; try { Character owner = entry.Owner; if (owner == null || (long)index >= (long)this.Items.Length) { return; } lootItem = this.Items[index]; InventoryError itemConditions = this.CheckTakeItemConditions(entry, lootItem); if (itemConditions == InventoryError.OK) { this.HandoutItem(owner, lootItem, targetCont, targetSlot); } else { ItemHandler.SendInventoryError((IPacketReceiver)owner.Client, (Item)null, (Item)null, itemConditions); } } catch (Exception ex) { LogUtil.ErrorException(ex, "{0} threw an Exception while looting \"{1}\" (index = {2}) from {3}", (object)entry.Owner, (object)lootItem, (object)index, (object)targetCont); } }
/// <summary> /// This gives the money to everyone involved. Will only work the first time its called. /// Afterwards <c>IsMoneyLooted</c> will be true. /// </summary> public void GiveMoney() { if (this.m_moneyLooted) { return; } if (this.Group == null) { LooterEntry looterEntry = this.Looters.FirstOrDefault <LooterEntry>(); if (looterEntry != null && looterEntry.Owner != null) { this.m_moneyLooted = true; this.SendMoney(looterEntry.Owner, this.Money); } } else { List <Character> characterList = new List <Character>(); if (this.UsesRoundRobin) { LooterEntry looterEntry = this.Looters.FirstOrDefault <LooterEntry>(); if (looterEntry != null && looterEntry.Owner != null) { characterList.Add(looterEntry.Owner); if (this.Lootable is WorldObject) { WorldObject lootable = (WorldObject)this.Lootable; } else { Character owner = looterEntry.Owner; } } } else { foreach (LooterEntry looter in (IEnumerable <LooterEntry>) this.Looters) { if (looter.m_owner != null) { characterList.Add(looter.m_owner); } } } if (characterList.Count > 0) { this.m_moneyLooted = true; uint amount = this.Money / (uint)characterList.Count; foreach (Character character in characterList) { this.SendMoney(character, amount); LootHandler.SendMoneyNotify(character, amount); } } } this.CheckFinished(); }
/// <summary> /// Returns whether the given looter may loot the given Item. /// Make sure the Looter is logged in before calling this Method. /// /// TODO: Find the right error messages /// TODO: Only give every MultiLoot item to everyone once! Also check for quest-dependencies etc. /// </summary> public InventoryError CheckTakeItemConditions(LooterEntry looter, LootItem item) { if (item.Taken) { return(InventoryError.ALREADY_LOOTED); } if (item.RollProgress != null) { // TODO: Still being rolled for return(InventoryError.DONT_OWN_THAT_ITEM); } if (!looter.MayLoot(this)) { return(InventoryError.DontReport); } var multiLooters = item.MultiLooters; if (multiLooters != null) { if (!multiLooters.Contains(looter)) { if (looter.Owner != null) { // make sure, Item cannot be seen by client anymore LootHandler.SendLootRemoved(looter.Owner, item.Index); } return(InventoryError.DONT_OWN_THAT_ITEM); } return(InventoryError.OK); } if (!item.Template.CheckLootConstraints(looter.Owner)) { return(InventoryError.DONT_OWN_THAT_ITEM); } if (Method != LootMethod.FreeForAll) { // definitely Group-Loot if ((item.Template.Quality > Group.LootThreshold && !item.Passed) || (Group.MasterLooter != null && Group.MasterLooter != looter.Owner.GroupMember)) { return(InventoryError.DONT_OWN_THAT_ITEM); } } return(InventoryError.OK); }
public void RemoveLooter(LooterEntry entry) { Looters.Remove(entry); }
/// <summary> /// Returns whether the given looter may loot the given Item. /// Make sure the Looter is logged in before calling this Method. /// /// TODO: Find the right error messages /// TODO: Only give every MultiLoot item to everyone once! Also check for quest-dependencies etc. /// </summary> public InventoryError CheckTakeItemConditions(LooterEntry looter, LootItem item) { if (item.Taken) { return InventoryError.ALREADY_LOOTED; } if (item.RollProgress != null) { // TODO: Still being rolled for return InventoryError.DONT_OWN_THAT_ITEM; } if (!looter.MayLoot(this)) { return InventoryError.DontReport; } var multiLooters = item.MultiLooters; if (multiLooters != null) { if (!multiLooters.Contains(looter)) { if (looter.Owner != null) { // make sure, Item cannot be seen by client anymore LootHandler.SendLootRemoved(looter.Owner, item.Index); } return InventoryError.DONT_OWN_THAT_ITEM; } return InventoryError.OK; } if (!item.Template.CheckLootConstraints(looter.Owner)) { return InventoryError.DONT_OWN_THAT_ITEM; } if (Method != LootMethod.FreeForAll) { // definitely Group-Loot if ((item.Template.Quality > Group.LootThreshold && !item.Passed) || (Group.MasterLooter != null && Group.MasterLooter != looter.Owner.GroupMember)) { return InventoryError.DONT_OWN_THAT_ITEM; } } return InventoryError.OK; }
/// <summary> /// Try to loot the item at the given index of the current loot /// </summary> /// <returns>The looted Item or null if Item could not be taken</returns> public void TakeItem(LooterEntry entry, uint index, BaseInventory targetCont, int targetSlot) { var chr = entry.Owner; if (chr != null && index < Items.Length) { var lootItem = Items[index]; var err = MayLoot(entry, lootItem); if (err == InventoryError.OK) { HandoutItem(chr, lootItem, targetCont, targetSlot); } else { ItemHandler.SendInventoryError(chr.Client, null, null, err); } } }