/// <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); }
protected override void OnDeath() { if (m_brain != null) { m_brain.IsRunning = false; } if (m_Map != null || this != null) { var rcvrs = this.GetNearbyClients(false); var looter = CalcLooter(); Asda2Loot loot = null; if (looter != null && m_Map.DefenceTownEvent == null) { loot = Asda2LootMgr.GetOrCreateLoot(this, looter, Asda2LootEntryType.Npc); if (loot != null && Template != null) { loot.MonstrId = (short?)Template.Id; } } Loot = null; var map = m_Map; m_Map.CallDelayed(LastDamageDelay, () => { Asda2CombatHandler.SendMostrDeadToAreaResponse(rcvrs, (short) UniqIdOnMap, (short) Asda2Position. X, (short) Asda2Position. Y); map.OnNPCDied(this); var chr = LastKiller as Character; if (chr != null) { Asda2TitleChecker.OnNpcDeath(this, chr); if (chr.IsInGroup) { chr.Group.ForeachCharacter(x => KillMonsterEventManager.TryGiveReward(x, Template.Id)); } else { KillMonsterEventManager.TryGiveReward(chr, Template.Id); } } if (loot != null && loot.Lootable is NPC) { var npc = ((NPC)loot.Lootable); if (npc != null && npc.Map != null) { npc.Map.SpawnLoot(loot); } } if (m_entry != null && Entry != null && Template != null) { if (Entry.Rank >= CreatureRank.Boss) { if (LastKiller != null) { ChatMgr.SendGlobalMessageResponse(LastKiller.Name, ChatMgr.Asda2GlobalMessageType .HasDefeated, 0, 0, (short)Template.Id); } if (chr != null) { chr.GuildPoints += m_entry.MinLevel * CharacterFormulas.BossKillingGuildPointsPerLevel; } } else { if (chr != null && chr.Level < m_entry.MinLevel + 3) { chr.GuildPoints += CharacterFormulas.MobKillingGuildPoints; } } // notify events m_entry.NotifyDied(this); } EnterFinalState(); }); } //UnitFlags |= UnitFlags.SelectableNotAttackable; // send off the tamer if (m_currentTamer != null) { PetHandler.SendTameFailure(m_currentTamer, TameFailReason.TargetDead); CurrentTamer.SpellCast.Cancel(SpellFailedReason.Ok); } // reset spawn timer if (m_spawnPoint != null) { m_spawnPoint.SignalSpawnlingDied(this); } }
/// <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 (!(Lootable is NPC)) { return(false); } if (Group == null) { // we only have a single looter var looter = Looters.FirstOrDefault(); if (looter != null && looter.Owner != null) { // var items = new List<Asda2Item>(); foreach (var asda2LootItem in Items) { Asda2Item item = null; var result = looter.Owner.Asda2Inventory.TryAdd((int)asda2LootItem.Template.ItemId, asda2LootItem.Amount, true, ref item); Log.Create(Log.Types.ItemOperations, LogSourceType.Character, looter.Owner.EntryId) .AddAttribute("source", 0, "loot") .AddItemAttributes(item) .AddAttribute("map", (double)looter.Owner.MapId, looter.Owner.MapId.ToString()) .AddAttribute("x", looter.Owner.Asda2Position.X) .AddAttribute("y", looter.Owner.Asda2Position.Y) .AddAttribute("monstrId", (double)(MonstrId.HasValue?MonstrId:0)) .Write(); if (result != Asda2InventoryError.Ok) { Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.NoSpace, null, looter.Owner); break; } Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.Ok, item, looter.Owner); if (item.Template.Quality >= Asda2ItemQuality.Green) { ChatMgr.SendGlobalMessageResponse(looter.Owner.Name, ChatMgr.Asda2GlobalMessageType.HasObinedItem, item.ItemId); } // items.Add(item); asda2LootItem.Taken = true; } /*if (items.Count != 0) * Asda2InventoryHandler.SendBuyItemResponse(Asda2BuyItemStatus.Ok, looter.Owner, items.ToArray());*/ } } else { var looters = new List <Character>(); if (UsesRoundRobin) { // we only added the RoundRobin member, so we have to find everyone in the radius for the money now var looter = Looters.FirstOrDefault(); if (looter != null && looter.Owner != null) { looters.Add(looter.Owner); WorldObject center; if (Lootable is WorldObject) { center = (WorldObject)Lootable; } else { center = looter.Owner; } GroupMember otherMember; var chrs = center.GetObjectsInRadius(Asda2LootMgr.LootRadius, ObjectTypes.Player, false, 0); foreach (Character chr in chrs) { if (chr.IsAlive && (chr == looter.Owner || ((otherMember = chr.GroupMember) != null && otherMember.Group == Group))) { looters.Add(chr); } } } } else { foreach (var looter in Looters) { if (looter.m_owner != null) { looters.Add(looter.m_owner); } } } if (looters.Count > 0) { var loots = new List <List <Asda2LootItem> >(); var looterIndex = 0; if (looters.Count == 1) { loots.Add(new List <Asda2LootItem>(Items)); } else { foreach (var t in looters) { loots.Add(new List <Asda2LootItem>()); } foreach (var asda2LootItem in Items) { var index = Utility.Random(0, looters.Count - 1); loots[index].Add(asda2LootItem); } } foreach (var looter in looters) { /*var items = new List<Asda2Item>();*/ foreach (var asda2LootItem in loots[looterIndex]) { Asda2Item item = null; var result = looter.Asda2Inventory.TryAdd((int)asda2LootItem.Template.ItemId, asda2LootItem.Amount, true, ref item); Log.Create(Log.Types.ItemOperations, LogSourceType.Character, looter.EntryId) .AddAttribute("source", 0, "loot") .AddItemAttributes(item) .AddAttribute("map", (double)looter.MapId, looter.MapId.ToString()) .AddAttribute("x", looter.Asda2Position.X) .AddAttribute("y", looter.Asda2Position.Y) .AddAttribute("monstrId", (double)(MonstrId.HasValue ? MonstrId : 0)) .Write(); if (result != Asda2InventoryError.Ok) { Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.NoSpace, null, looter); break; } else { Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.Ok, item, looter); } //items.Add(item); asda2LootItem.Taken = true; } /*if (items.Count != 0) * Asda2InventoryHandler.SendBuyItemResponse(Asda2BuyItemStatus.Ok, looter, * items.ToArray());*/ looterIndex++; } } } if (IsAllItemsTaken) { Dispose(); return(true); } return(false); }