Esempio n. 1
0
        void HandleLootMoney(LootMoney lootMoney)
        {
            Player player = GetPlayer();

            foreach (var lootView in player.GetAELootView())
            {
                ObjectGuid guid       = lootView.Value;
                Loot       loot       = null;
                bool       shareMoney = true;

                switch (guid.GetHigh())
                {
                case HighGuid.GameObject:
                {
                    GameObject go = player.GetMap().GetGameObject(guid);

                    // do not check distance for GO if player is the owner of it (ex. fishing bobber)
                    if (go && ((go.GetOwnerGUID() == player.GetGUID() || go.IsWithinDistInMap(player, SharedConst.InteractionDistance))))
                    {
                        loot = go.loot;
                    }

                    break;
                }

                case HighGuid.Corpse:                                   // remove insignia ONLY in BG
                {
                    Corpse bones = ObjectAccessor.GetCorpse(player, guid);

                    if (bones && bones.IsWithinDistInMap(player, SharedConst.InteractionDistance))
                    {
                        loot       = bones.loot;
                        shareMoney = false;
                    }

                    break;
                }

                case HighGuid.Item:
                {
                    Item item = player.GetItemByGuid(guid);
                    if (item)
                    {
                        loot       = item.loot;
                        shareMoney = false;
                    }
                    break;
                }

                case HighGuid.Creature:
                case HighGuid.Vehicle:
                {
                    Creature creature    = player.GetMap().GetCreature(guid);
                    bool     lootAllowed = creature && creature.IsAlive() == (player.GetClass() == Class.Rogue && creature.loot.loot_type == LootType.Pickpocketing);
                    if (lootAllowed && creature.IsWithinDistInMap(player, AELootCreatureCheck.LootDistance))
                    {
                        loot = creature.loot;
                        if (creature.IsAlive())
                        {
                            shareMoney = false;
                        }
                    }
                    else
                    {
                        player.SendLootError(lootView.Key, guid, lootAllowed ? LootError.TooFar : LootError.DidntKill);
                    }
                    break;
                }

                default:
                    continue;                                             // unlootable type
                }

                if (loot == null)
                {
                    continue;
                }

                loot.NotifyMoneyRemoved();
                if (shareMoney && player.GetGroup() != null)      //item, pickpocket and players can be looted only single player
                {
                    Group group = player.GetGroup();

                    List <Player> playersNear = new List <Player>();
                    for (GroupReference refe = group.GetFirstMember(); refe != null; refe = refe.next())
                    {
                        Player member = refe.GetSource();
                        if (!member)
                        {
                            continue;
                        }

                        if (player.IsAtGroupRewardDistance(member))
                        {
                            playersNear.Add(member);
                        }
                    }

                    ulong goldPerPlayer = (ulong)(loot.gold / playersNear.Count);

                    foreach (var pl in playersNear)
                    {
                        ulong goldMod = MathFunctions.CalculatePct(goldPerPlayer, pl.GetTotalAuraModifierByMiscValue(AuraType.ModMoneyGain, 1));

                        pl.ModifyMoney((long)(goldPerPlayer + goldMod));
                        pl.UpdateCriteria(CriteriaTypes.LootMoney, goldPerPlayer);

                        LootMoneyNotify packet = new LootMoneyNotify();
                        packet.Money      = goldPerPlayer;
                        packet.MoneyMod   = goldMod;
                        packet.SoleLooter = playersNear.Count <= 1 ? true : false;
                        pl.SendPacket(packet);
                    }
                }
                else
                {
                    ulong goldMod = MathFunctions.CalculatePct(loot.gold, player.GetTotalAuraModifierByMiscValue(AuraType.ModMoneyGain, 1));

                    player.ModifyMoney((long)(loot.gold + goldMod));
                    player.UpdateCriteria(CriteriaTypes.LootMoney, loot.gold);

                    LootMoneyNotify packet = new LootMoneyNotify();
                    packet.Money      = loot.gold;
                    packet.MoneyMod   = goldMod;
                    packet.SoleLooter = true; // "You loot..."
                    SendPacket(packet);
                }

                loot.gold = 0;

                // Delete the money loot record from the DB
                if (!loot.containerID.IsEmpty())
                {
                    loot.DeleteLootMoneyFromContainerItemDB();
                }

                // Delete container if empty
                if (loot.isLooted() && guid.IsItem())
                {
                    player.GetSession().DoLootRelease(guid);
                }
            }
        }