/// <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(Asda2LooterEntry looter, Asda2LootItem item) { if (item.Taken) { return(InventoryError.ALREADY_LOOTED); } if (!looter.MayLoot(this)) { return(InventoryError.DontReport); } ICollection <Asda2LooterEntry> 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); } if (!item.Template.CheckLootConstraints(looter.Owner)) { return(InventoryError.DONT_OWN_THAT_ITEM); } int method = (int)this.Method; return(InventoryError.OK); }
/// <summary>Client finished looting</summary> public static void HandleLootRelease(IRealmClient client, RealmPacketIn packet) { Asda2LooterEntry looterEntry = client.ActiveCharacter.LooterEntry; if (looterEntry.Loot == null) { return; } looterEntry.Loot = (Asda2Loot)null; }
/// <summary>A client wants to loot something (usually a corpse)</summary> public static void HandleLoot(IRealmClient client, RealmPacketIn packet) { EntityId id = packet.ReadEntityId(); Character activeCharacter = client.ActiveCharacter; Asda2LooterEntry looterEntry = activeCharacter.LooterEntry; WorldObject worldObject = activeCharacter.Map.GetObject(id); if (worldObject == null) { return; } looterEntry.TryLoot((IAsda2Lootable)worldObject); }
/// <summary> /// Gold is given automatically in group-looting. Client can only request gold when looting alone. /// </summary> public static void HandleLootMoney(IRealmClient client, RealmPacketIn packet) { Character activeCharacter = client.ActiveCharacter; Asda2LooterEntry looterEntry = activeCharacter.LooterEntry; activeCharacter.SpellCast.Cancel(SpellFailedReason.Interrupted); Asda2Loot loot = looterEntry.Loot; if (loot == null) { return; } loot.GiveMoney(); }
/// <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(Asda2LooterEntry looter, Asda2LootItem item) { if (item.Taken) { return(InventoryError.ALREADY_LOOTED); } 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(Asda2LooterEntry entry) { this.Looters.Remove(entry); }
/// <summary> /// This gives items to everyone involved. Will only work the first time its called. /// Afterwards <c>IsMoneyLooted</c> will be true. /// </summary> public bool GiveItems() { if (!(this.Lootable is NPC)) { return(false); } if (this.Group == null) { Asda2LooterEntry asda2LooterEntry = this.Looters.FirstOrDefault <Asda2LooterEntry>(); if (asda2LooterEntry != null && asda2LooterEntry.Owner != null) { foreach (Asda2LootItem asda2LootItem in this.Items) { Asda2Item asda2Item = (Asda2Item)null; Asda2InventoryError asda2InventoryError = asda2LooterEntry.Owner.Asda2Inventory.TryAdd((int)asda2LootItem.Template.ItemId, asda2LootItem.Amount, true, ref asda2Item, new Asda2InventoryType?(), (Asda2Item)null); Log.Create(Log.Types.ItemOperations, LogSourceType.Character, asda2LooterEntry.Owner.EntryId) .AddAttribute("source", 0.0, "loot").AddItemAttributes(asda2Item, "") .AddAttribute("map", (double)asda2LooterEntry.Owner.MapId, asda2LooterEntry.Owner.MapId.ToString()) .AddAttribute("x", (double)asda2LooterEntry.Owner.Asda2Position.X, "") .AddAttribute("y", (double)asda2LooterEntry.Owner.Asda2Position.Y, "") .AddAttribute("monstrId", (double)(this.MonstrId.HasValue ? this.MonstrId : new short?((short)0)).Value, "") .Write(); if (asda2InventoryError != Asda2InventoryError.Ok) { Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.NoSpace, (Asda2Item)null, asda2LooterEntry.Owner); break; } Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.Ok, asda2Item, asda2LooterEntry.Owner); if (asda2Item.Template.Quality >= Asda2ItemQuality.Green) { ChatMgr.SendGlobalMessageResponse(asda2LooterEntry.Owner.Name, ChatMgr.Asda2GlobalMessageType.HasObinedItem, asda2Item.ItemId, (short)0, (short)0); } asda2LootItem.Taken = true; } } } else { List <Character> characterList = new List <Character>(); if (this.UsesRoundRobin) { Asda2LooterEntry asda2LooterEntry = this.Looters.FirstOrDefault <Asda2LooterEntry>(); if (asda2LooterEntry != null && asda2LooterEntry.Owner != null) { characterList.Add(asda2LooterEntry.Owner); foreach (Character objectsInRadiu in (IEnumerable <WorldObject>)(!(this.Lootable is WorldObject) ? (WorldObject)asda2LooterEntry.Owner : (WorldObject)this.Lootable) .GetObjectsInRadius <WorldObject>(Asda2LootMgr.LootRadius, ObjectTypes.Player, false, 0)) { GroupMember groupMember; if (objectsInRadiu.IsAlive && (objectsInRadiu == asda2LooterEntry.Owner || (groupMember = objectsInRadiu.GroupMember) != null && groupMember.Group == this.Group)) { characterList.Add(objectsInRadiu); } } } } else { foreach (Asda2LooterEntry looter in (IEnumerable <Asda2LooterEntry>) this.Looters) { if (looter.m_owner != null) { characterList.Add(looter.m_owner); } } } if (characterList.Count > 0) { List <List <Asda2LootItem> > asda2LootItemListList = new List <List <Asda2LootItem> >(); int index1 = 0; if (characterList.Count == 1) { asda2LootItemListList.Add(new List <Asda2LootItem>((IEnumerable <Asda2LootItem>) this.Items)); } else { foreach (Character character in characterList) { asda2LootItemListList.Add(new List <Asda2LootItem>()); } foreach (Asda2LootItem asda2LootItem in this.Items) { int index2 = Utility.Random(0, characterList.Count - 1); asda2LootItemListList[index2].Add(asda2LootItem); } } foreach (Character chr in characterList) { foreach (Asda2LootItem asda2LootItem in asda2LootItemListList[index1]) { Asda2Item asda2Item = (Asda2Item)null; Asda2InventoryError asda2InventoryError = chr.Asda2Inventory.TryAdd((int)asda2LootItem.Template.ItemId, asda2LootItem.Amount, true, ref asda2Item, new Asda2InventoryType?(), (Asda2Item)null); Log.Create(Log.Types.ItemOperations, LogSourceType.Character, chr.EntryId) .AddAttribute("source", 0.0, "loot").AddItemAttributes(asda2Item, "") .AddAttribute("map", (double)chr.MapId, chr.MapId.ToString()) .AddAttribute("x", (double)chr.Asda2Position.X, "") .AddAttribute("y", (double)chr.Asda2Position.Y, "").AddAttribute("monstrId", (double)(this.MonstrId.HasValue ? this.MonstrId : new short?((short)0)).Value, "") .Write(); if (asda2InventoryError != Asda2InventoryError.Ok) { Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.NoSpace, (Asda2Item)null, chr); break; } Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.Ok, asda2Item, chr); asda2LootItem.Taken = true; } ++index1; } } } if (!this.IsAllItemsTaken) { return(false); } this.Dispose(); return(true); }
/// <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.Lootable is NPC) || this.m_moneyLooted) { return; } if (this.Group == null) { Asda2LooterEntry asda2LooterEntry = this.Looters.FirstOrDefault <Asda2LooterEntry>(); if (asda2LooterEntry != null && asda2LooterEntry.Owner != null) { this.m_moneyLooted = true; if (asda2LooterEntry.Owner.Level < ((Unit)this.Lootable).Level + 6) { this.SendMoney(asda2LooterEntry.Owner, this.Money); } } } else { List <Character> characterList = new List <Character>(); if (this.UsesRoundRobin) { Asda2LooterEntry asda2LooterEntry = this.Looters.FirstOrDefault <Asda2LooterEntry>(); if (asda2LooterEntry != null && asda2LooterEntry.Owner != null) { characterList.Add(asda2LooterEntry.Owner); foreach (Character objectsInRadiu in (IEnumerable <WorldObject>)(!(this.Lootable is WorldObject) ? (WorldObject)asda2LooterEntry.Owner : (WorldObject)this.Lootable) .GetObjectsInRadius <WorldObject>(Asda2LootMgr.LootRadius, ObjectTypes.Player, false, 0)) { GroupMember groupMember; if (objectsInRadiu.IsAlive && (objectsInRadiu == asda2LooterEntry.Owner || (groupMember = objectsInRadiu.GroupMember) != null && groupMember.Group == this.Group)) { characterList.Add(objectsInRadiu); } } } } else { foreach (Asda2LooterEntry looter in (IEnumerable <Asda2LooterEntry>) 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 receiver in characterList) { if (receiver.Level < ((Unit)this.Lootable).Level + 6) { this.SendMoney(receiver, amount); } } } } this.CheckFinished(); }