Core/Loot: Implemented personal loot and tag sharing for non-boss loot
Port From (https://github.com/TrinityCore/TrinityCore/commit/133334a902b705dae6f7e92bb1009b84cf1c51d2)
This commit is contained in:
@@ -90,9 +90,9 @@ namespace Game.Entities
|
||||
// vendor items
|
||||
List<VendorItemCount> m_vendorItemCounts = new();
|
||||
|
||||
public Loot loot;
|
||||
ObjectGuid m_lootRecipient;
|
||||
ObjectGuid m_lootRecipientGroup;
|
||||
internal Dictionary<ObjectGuid, Loot> m_personalLoot = new();
|
||||
public Loot _loot;
|
||||
List<ObjectGuid> m_tapList = new();
|
||||
}
|
||||
|
||||
public enum ObjectCellMoveState
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Game.Entities
|
||||
SetDeathState(DeathState.Dead);
|
||||
RemoveAllAuras();
|
||||
//DestroyForNearbyPlayers(); // old UpdateObjectVisibility()
|
||||
loot = null;
|
||||
_loot = null;
|
||||
uint respawnDelay = m_respawnDelay;
|
||||
CreatureAI ai = GetAI();
|
||||
if (ai != null)
|
||||
@@ -507,7 +507,10 @@ namespace Game.Entities
|
||||
if (IsEngaged())
|
||||
AIUpdateTick(diff);
|
||||
|
||||
loot?.Update();
|
||||
_loot?.Update();
|
||||
|
||||
foreach (var (playerOwner, loot) in m_personalLoot)
|
||||
loot.Update();
|
||||
|
||||
if (m_corpseRemoveTime <= GameTime.GetGameTime())
|
||||
{
|
||||
@@ -1165,24 +1168,8 @@ namespace Game.Entities
|
||||
}
|
||||
public void ResetPickPocketRefillTimer() { _pickpocketLootRestore = 0; }
|
||||
public bool CanGeneratePickPocketLoot() { return _pickpocketLootRestore <= GameTime.GetGameTime(); }
|
||||
public ObjectGuid GetLootRecipientGUID() { return m_lootRecipient; }
|
||||
|
||||
public Player GetLootRecipient()
|
||||
{
|
||||
if (m_lootRecipient.IsEmpty())
|
||||
return null;
|
||||
return Global.ObjAccessor.FindPlayer(m_lootRecipient);
|
||||
}
|
||||
|
||||
public Group GetLootRecipientGroup()
|
||||
{
|
||||
if (m_lootRecipientGroup.IsEmpty())
|
||||
return null;
|
||||
|
||||
return Global.GroupMgr.GetGroupByGUID(m_lootRecipientGroup);
|
||||
}
|
||||
|
||||
public void SetLootRecipient(Unit unit, bool withGroup = true)
|
||||
public void SetTappedBy(Unit unit, bool withGroup = true)
|
||||
{
|
||||
// set the player whose group should receive the right
|
||||
// to loot the creature after it dies
|
||||
@@ -1190,12 +1177,14 @@ namespace Game.Entities
|
||||
|
||||
if (unit == null)
|
||||
{
|
||||
m_lootRecipient.Clear();
|
||||
m_lootRecipientGroup.Clear();
|
||||
m_tapList.Clear();
|
||||
RemoveDynamicFlag(UnitDynFlags.Lootable | UnitDynFlags.Tapped);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_tapList.Count >= SharedConst.CreatureTappersSoftCap)
|
||||
return;
|
||||
|
||||
if (!unit.IsTypeId(TypeId.Player) && !unit.IsVehicle())
|
||||
return;
|
||||
|
||||
@@ -1203,31 +1192,62 @@ namespace Game.Entities
|
||||
if (player == null) // normal creature, no player involved
|
||||
return;
|
||||
|
||||
m_lootRecipient = player.GetGUID();
|
||||
m_tapList.Add(player.GetGUID());
|
||||
if (withGroup)
|
||||
{
|
||||
Group group = player.GetGroup();
|
||||
if (group)
|
||||
m_lootRecipientGroup = group.GetGUID();
|
||||
if (group != null)
|
||||
for (var itr = group.GetFirstMember(); itr != null; itr = itr.Next())
|
||||
if (GetMap().IsRaid() || group.SameSubGroup(player, itr.GetSource()))
|
||||
m_tapList.Add(itr.GetSource().GetGUID());
|
||||
}
|
||||
else
|
||||
m_lootRecipientGroup = ObjectGuid.Empty;
|
||||
|
||||
SetDynamicFlag(UnitDynFlags.Tapped);
|
||||
if (m_tapList.Count >= SharedConst.CreatureTappersSoftCap)
|
||||
SetDynamicFlag(UnitDynFlags.Tapped);
|
||||
}
|
||||
|
||||
public bool IsTappedBy(Player player)
|
||||
{
|
||||
if (player.GetGUID() == m_lootRecipient)
|
||||
return true;
|
||||
return m_tapList.Contains(player.GetGUID());
|
||||
}
|
||||
|
||||
Group playerGroup = player.GetGroup();
|
||||
if (!playerGroup || playerGroup != GetLootRecipientGroup()) // if we dont have a group we arent the recipient
|
||||
return false; // if creature doesnt have group bound it means it was solo killed by someone else
|
||||
public override Loot GetLootForPlayer(Player player)
|
||||
{
|
||||
if (m_personalLoot.Empty())
|
||||
return _loot;
|
||||
|
||||
var loot = m_personalLoot.LookupByKey(player.GetGUID());
|
||||
if (loot != null)
|
||||
return loot;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsFullyLooted()
|
||||
{
|
||||
if (_loot != null && !_loot.IsLooted())
|
||||
return false;
|
||||
|
||||
foreach (var (_, loot) in m_personalLoot)
|
||||
if (!loot.IsLooted())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsSkinnedBy(Player player)
|
||||
{
|
||||
Loot loot = GetLootForPlayer(player);
|
||||
if (loot != null)
|
||||
return loot.loot_type == LootType.Skinning;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<ObjectGuid> GetTapList() { return m_tapList; }
|
||||
public void SetTapList(List<ObjectGuid> tapList) { m_tapList = tapList; }
|
||||
public bool HasLootRecipient() { return !m_tapList.Empty(); }
|
||||
|
||||
public void SaveToDB()
|
||||
{
|
||||
// this should only be used when the creature has already been loaded
|
||||
@@ -1867,7 +1887,7 @@ namespace Game.Entities
|
||||
else
|
||||
SetSpawnHealth();
|
||||
|
||||
SetLootRecipient(null);
|
||||
SetTappedBy(null);
|
||||
ResetPlayerDamageReq();
|
||||
|
||||
SetCannotReachTarget(false);
|
||||
@@ -1926,7 +1946,7 @@ namespace Game.Entities
|
||||
Log.outDebug(LogFilter.Unit, "Respawning creature {0} ({1})", GetName(), GetGUID().ToString());
|
||||
m_respawnTime = 0;
|
||||
ResetPickPocketRefillTimer();
|
||||
loot = null;
|
||||
_loot = null;
|
||||
|
||||
if (m_originalEntry != GetEntry())
|
||||
UpdateEntry(m_originalEntry);
|
||||
@@ -2560,13 +2580,9 @@ namespace Game.Entities
|
||||
{
|
||||
return !_isMissingCanSwimFlagOutOfCombat;
|
||||
}
|
||||
|
||||
|
||||
public void AllLootRemovedFromCorpse()
|
||||
{
|
||||
if ((loot == null || loot.loot_type != LootType.Skinning) && !IsPet() && GetCreatureTemplate().SkinLootId != 0 && HasLootRecipient())
|
||||
if (LootStorage.Skinning.HaveLootFor(GetCreatureTemplate().SkinLootId))
|
||||
SetUnitFlag(UnitFlags.Skinnable);
|
||||
|
||||
long now = GameTime.GetGameTime();
|
||||
// Do not reset corpse remove time if corpse is already removed
|
||||
if (m_corpseRemoveTime <= now)
|
||||
@@ -2576,7 +2592,19 @@ namespace Game.Entities
|
||||
float decayRate = m_ignoreCorpseDecayRatio ? 1.0f : WorldConfig.GetFloatValue(WorldCfg.RateCorpseDecayLooted);
|
||||
|
||||
// corpse skinnable, but without skinning flag, and then skinned, corpse will despawn next update
|
||||
if (loot != null && loot.loot_type == LootType.Skinning)
|
||||
bool isFullySkinned()
|
||||
{
|
||||
if (_loot != null && _loot.loot_type == LootType.Skinning && _loot.IsLooted())
|
||||
return true;
|
||||
|
||||
foreach (var (_, loot) in m_personalLoot)
|
||||
if (loot.loot_type != LootType.Skinning || !loot.IsLooted())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isFullySkinned())
|
||||
m_corpseRemoveTime = now;
|
||||
else
|
||||
m_corpseRemoveTime = now + (uint)(m_corpseDelay * decayRate);
|
||||
@@ -3269,10 +3297,6 @@ namespace Game.Entities
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool HasLootRecipient() { return !m_lootRecipient.IsEmpty() || !m_lootRecipientGroup.IsEmpty(); }
|
||||
|
||||
public override Loot GetLootForPlayer(Player player) { return loot; }
|
||||
|
||||
public LootModes GetLootMode() { return m_LootMode; }
|
||||
public bool HasLootMode(LootModes lootMode) { return Convert.ToBoolean(m_LootMode & lootMode); }
|
||||
@@ -3343,7 +3367,6 @@ namespace Game.Entities
|
||||
|
||||
void SetDisableReputationGain(bool disable) { DisableReputationGain = disable; }
|
||||
public bool IsReputationGainDisabled() { return DisableReputationGain; }
|
||||
public bool IsDamageEnoughForLootingAndReward() { return m_creatureInfo.FlagsExtra.HasAnyFlag(CreatureFlagsExtra.NoPlayerDamageReq) || m_PlayerDamageReq == 0; }
|
||||
|
||||
// Part of Evade mechanics
|
||||
long GetLastDamagedTime() { return _lastDamagedTime; }
|
||||
|
||||
@@ -956,45 +956,47 @@ namespace Game.Entities
|
||||
|
||||
public Loot GetFishLoot(Player lootOwner)
|
||||
{
|
||||
uint zone, subzone;
|
||||
uint defaultzone = 1;
|
||||
GetZoneAndAreaId(out zone, out subzone);
|
||||
|
||||
Loot fishLoot = new(GetMap(), GetGUID(), LootType.Fishing, null);
|
||||
|
||||
// if subzone loot exist use it
|
||||
fishLoot.FillLoot(subzone, LootStorage.Fishing, lootOwner, true, true);
|
||||
if (fishLoot.Empty())
|
||||
uint areaId = GetAreaId();
|
||||
AreaTableRecord areaEntry;
|
||||
while ((areaEntry = CliDB.AreaTableStorage.LookupByKey(areaId)) != null)
|
||||
{
|
||||
//subzone no result,use zone loot
|
||||
fishLoot.FillLoot(zone, LootStorage.Fishing, lootOwner, true);
|
||||
//use zone 1 as default, somewhere fishing got nothing,becase subzone and zone not set, like Off the coast of Storm Peaks.
|
||||
if (fishLoot.Empty())
|
||||
fishLoot.FillLoot(defaultzone, LootStorage.Fishing, lootOwner, true, true);
|
||||
fishLoot.FillLoot(areaId, LootStorage.Fishing, lootOwner, true, true);
|
||||
if (!fishLoot.IsLooted())
|
||||
break;
|
||||
|
||||
areaId = areaEntry.ParentAreaID;
|
||||
}
|
||||
|
||||
if (fishLoot.IsLooted())
|
||||
fishLoot.FillLoot(defaultzone, LootStorage.Fishing, lootOwner, true, true);
|
||||
|
||||
return fishLoot;
|
||||
}
|
||||
|
||||
public Loot GetFishLootJunk(Player lootOwner)
|
||||
{
|
||||
uint zone, subzone;
|
||||
uint defaultzone = 1;
|
||||
GetZoneAndAreaId(out zone, out subzone);
|
||||
|
||||
Loot fishLoot = new(GetMap(), GetGUID(), LootType.FishingJunk, null);
|
||||
|
||||
// if subzone loot exist use it
|
||||
fishLoot.FillLoot(subzone, LootStorage.Fishing, lootOwner, true, true, LootModes.JunkFish);
|
||||
if (fishLoot.Empty()) //use this becase if zone or subzone has normal mask drop, then fishloot.FillLoot return true.
|
||||
uint areaId = GetAreaId();
|
||||
AreaTableRecord areaEntry;
|
||||
while ((areaEntry = CliDB.AreaTableStorage.LookupByKey(areaId)) != null)
|
||||
{
|
||||
//use zone loot
|
||||
fishLoot.FillLoot(zone, LootStorage.Fishing, lootOwner, true, true, LootModes.JunkFish);
|
||||
if (fishLoot.Empty())
|
||||
//use zone 1 as default
|
||||
fishLoot.FillLoot(defaultzone, LootStorage.Fishing, lootOwner, true, true, LootModes.JunkFish);
|
||||
fishLoot.FillLoot(areaId, LootStorage.Fishing, lootOwner, true, true, LootModes.JunkFish);
|
||||
if (!fishLoot.IsLooted())
|
||||
break;
|
||||
|
||||
areaId = areaEntry.ParentAreaID;
|
||||
}
|
||||
|
||||
if (fishLoot.IsLooted())
|
||||
fishLoot.FillLoot(defaultzone, LootStorage.Fishing, lootOwner, true, true, LootModes.JunkFish);
|
||||
|
||||
return fishLoot;
|
||||
}
|
||||
|
||||
@@ -2886,51 +2888,6 @@ namespace Game.Entities
|
||||
GetMap().InsertGameObjectModel(m_model);
|
||||
}
|
||||
|
||||
Player GetLootRecipient()
|
||||
{
|
||||
if (m_lootRecipient.IsEmpty())
|
||||
return null;
|
||||
return Global.ObjAccessor.FindPlayer(m_lootRecipient);
|
||||
}
|
||||
|
||||
Group GetLootRecipientGroup()
|
||||
{
|
||||
if (m_lootRecipientGroup.IsEmpty())
|
||||
return Global.GroupMgr.GetGroupByGUID(m_lootRecipientGroup);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetLootRecipient(Unit unit, Group group)
|
||||
{
|
||||
// set the player whose group should receive the right
|
||||
// to loot the creature after it dies
|
||||
// should be set to null after the loot disappears
|
||||
|
||||
if (unit == null)
|
||||
{
|
||||
m_lootRecipient.Clear();
|
||||
m_lootRecipientGroup = group ? group.GetGUID() : ObjectGuid.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!unit.IsTypeId(TypeId.Player) && !unit.IsVehicle())
|
||||
return;
|
||||
|
||||
Player player = unit.GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
if (player == null) // normal creature, no player involved
|
||||
return;
|
||||
|
||||
m_lootRecipient = player.GetGUID();
|
||||
|
||||
// either get the group from the passed parameter or from unit's one
|
||||
Group unitGroup = player.GetGroup();
|
||||
if (group)
|
||||
m_lootRecipientGroup = group.GetGUID();
|
||||
else if (unitGroup)
|
||||
m_lootRecipientGroup = unitGroup.GetGUID();
|
||||
}
|
||||
|
||||
public bool IsLootAllowedFor(Player player)
|
||||
{
|
||||
Loot loot = GetLootForPlayer(player);
|
||||
@@ -2942,15 +2899,8 @@ namespace Game.Entities
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_lootRecipient.IsEmpty() && m_lootRecipientGroup.IsEmpty())
|
||||
return true;
|
||||
|
||||
if (player.GetGUID() == m_lootRecipient)
|
||||
return true;
|
||||
|
||||
Group playerGroup = player.GetGroup();
|
||||
if (!playerGroup || playerGroup != GetLootRecipientGroup()) // if we dont have a group we arent the recipient
|
||||
return false; // if go doesnt have group bound it means it was solo killed by someone else
|
||||
if (HasLootRecipient())
|
||||
return m_tapList.Contains(player.GetGUID()); // if go doesnt have group bound it means it was solo killed by someone else
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -3444,7 +3394,10 @@ namespace Game.Entities
|
||||
public uint GetUseCount() { return m_usetimes; }
|
||||
uint GetUniqueUseCount() { return (uint)m_unique_users.Count; }
|
||||
|
||||
bool HasLootRecipient() { return !m_lootRecipient.IsEmpty() || !m_lootRecipientGroup.IsEmpty(); }
|
||||
List<ObjectGuid> GetTapList() { return m_tapList; }
|
||||
void SetTapList(List<ObjectGuid> tapList) { m_tapList = tapList; }
|
||||
|
||||
bool HasLootRecipient() { return !m_tapList.Empty(); }
|
||||
|
||||
public override uint GetLevelForTarget(WorldObject target)
|
||||
{
|
||||
@@ -3552,8 +3505,7 @@ namespace Game.Entities
|
||||
List<ObjectGuid> m_unique_users = new();
|
||||
uint m_usetimes;
|
||||
|
||||
ObjectGuid m_lootRecipient;
|
||||
ObjectGuid m_lootRecipientGroup;
|
||||
List<ObjectGuid> m_tapList = new();
|
||||
LootModes m_LootMode; // bitmask, default LOOT_MODE_DEFAULT, determines what loot will be lootable
|
||||
long m_packedRotation;
|
||||
Quaternion m_localRotation;
|
||||
|
||||
@@ -99,8 +99,6 @@ namespace Game.Entities
|
||||
Unit unit = obj.ToUnit();
|
||||
if (unit != null)
|
||||
{
|
||||
unitDynFlags &= ~(uint)UnitDynFlags.Tapped;
|
||||
|
||||
Creature creature = obj.ToCreature();
|
||||
if (creature != null)
|
||||
{
|
||||
@@ -109,6 +107,9 @@ namespace Game.Entities
|
||||
|
||||
if (!receiver.IsAllowedToLoot(creature))
|
||||
unitDynFlags &= ~(uint)UnitDynFlags.Lootable;
|
||||
|
||||
if ((unitDynFlags & (uint)UnitDynFlags.CanSkin) != 0 && creature.IsSkinnedBy(receiver))
|
||||
unitDynFlags &= ~(uint)UnitDynFlags.CanSkin;
|
||||
}
|
||||
|
||||
// unit UNIT_DYNFLAG_TRACK_UNIT should only be sent to caster of SPELL_AURA_MOD_STALKED auras
|
||||
@@ -1327,7 +1328,7 @@ namespace Game.Entities
|
||||
|
||||
data.WriteUInt32(GetViewerDependentFlags(this, owner, receiver));
|
||||
data.WriteUInt32(Flags2);
|
||||
data.WriteUInt32(Flags3);
|
||||
data.WriteUInt32(GetViewerDependentFlags3(this, owner, receiver));
|
||||
data.WriteUInt32(GetViewerDependentAuraState(this, owner, receiver));
|
||||
for (int i = 0; i < 2; ++i)
|
||||
data.WriteUInt32(AttackRoundBaseTime[i]);
|
||||
@@ -1712,7 +1713,7 @@ namespace Game.Entities
|
||||
}
|
||||
if (changesMask[45])
|
||||
{
|
||||
data.WriteUInt32(Flags3);
|
||||
data.WriteUInt32(GetViewerDependentFlags3(this, owner, receiver));
|
||||
}
|
||||
if (changesMask[46])
|
||||
{
|
||||
@@ -2308,6 +2309,14 @@ namespace Game.Entities
|
||||
|
||||
return flags;
|
||||
}
|
||||
uint GetViewerDependentFlags3(UnitData unitData, Unit unit, Player receiver)
|
||||
{
|
||||
uint flags = unitData.Flags3;
|
||||
if ((flags & (uint)UnitFlags3.AlreadySkinned) != 0 && unit.IsCreature() && !unit.ToCreature().IsSkinnedBy(receiver))
|
||||
flags &= ~(uint)UnitFlags3.AlreadySkinned;
|
||||
|
||||
return flags;
|
||||
}
|
||||
uint GetViewerDependentAuraState(UnitData unitData, Unit unit, Player receiver)
|
||||
{
|
||||
// Check per caster aura states to not enable using a spell in client if specified aura is not by target
|
||||
|
||||
@@ -21,14 +21,14 @@ using Game.Groups;
|
||||
using Game.Maps;
|
||||
using Game.Scenarios;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Entities
|
||||
{
|
||||
public class KillRewarder
|
||||
{
|
||||
Player _killer;
|
||||
Player[] _killers;
|
||||
Unit _victim;
|
||||
Group _group;
|
||||
float _groupRate;
|
||||
Player _maxNotGrayMember;
|
||||
uint _count;
|
||||
@@ -39,11 +39,10 @@ namespace Game.Entities
|
||||
bool _isBattleground;
|
||||
bool _isPvP;
|
||||
|
||||
public KillRewarder(Player killer, Unit victim, bool isBattleground)
|
||||
public KillRewarder(Player[] killers, Unit victim, bool isBattleground)
|
||||
{
|
||||
_killer = killer;
|
||||
_killers = killers;
|
||||
_victim = victim;
|
||||
_group = killer.GetGroup();
|
||||
_groupRate = 1.0f;
|
||||
_maxNotGrayMember = null;
|
||||
_count = 0;
|
||||
@@ -60,27 +59,37 @@ namespace Game.Entities
|
||||
// or if its owned by player and its not a vehicle
|
||||
else if (victim.GetCharmerOrOwnerGUID().IsPlayer())
|
||||
_isPvP = !victim.IsVehicle();
|
||||
|
||||
_InitGroupData();
|
||||
}
|
||||
|
||||
public void Reward()
|
||||
{
|
||||
// 3. Reward killer (and group, if necessary).
|
||||
if (_group)
|
||||
// 3.1. If killer is in group, reward group.
|
||||
_RewardGroup();
|
||||
else
|
||||
SortedSet<Group> processedGroups = new();
|
||||
foreach (Player killer in _killers)
|
||||
{
|
||||
// 3.2. Reward single killer (not group case).
|
||||
// 3.2.1. Initialize initial XP amount based on killer's level.
|
||||
_InitXP(_killer);
|
||||
// To avoid unnecessary calculations and calls,
|
||||
// proceed only if XP is not ZERO or player is not on Battleground
|
||||
// (Battlegroundrewards only XP, that's why).
|
||||
if (!_isBattleground || _xp != 0)
|
||||
// 3.2.2. Reward killer.
|
||||
_RewardPlayer(_killer, false);
|
||||
_InitGroupData(killer);
|
||||
|
||||
// 3. Reward killer (and group, if necessary).
|
||||
Group group = killer.GetGroup();
|
||||
if (group != null)
|
||||
{
|
||||
if (!processedGroups.Add(group))
|
||||
continue;
|
||||
|
||||
// 3.1. If killer is in group, reward group.
|
||||
_RewardGroup(group, killer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 3.2. Reward single killer (not group case).
|
||||
// 3.2.1. Initialize initial XP amount based on killer's level.
|
||||
_InitXP(killer, killer);
|
||||
// To avoid unnecessary calculations and calls,
|
||||
// proceed only if XP is not ZERO or player is not on battleground
|
||||
// (battleground rewards only XP, that's why).
|
||||
if (!_isBattleground || _xp != 0)
|
||||
// 3.2.2. Reward killer.
|
||||
_RewardPlayer(killer, false);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Credit instance encounter.
|
||||
@@ -99,25 +108,26 @@ namespace Game.Entities
|
||||
uint guildId = victim.GetMap().GetOwnerGuildId();
|
||||
var guild = Global.GuildMgr.GetGuildById(guildId);
|
||||
if (guild != null)
|
||||
guild.UpdateCriteria(CriteriaType.KillCreature, victim.GetEntry(), 1, 0, victim, _killer);
|
||||
guild.UpdateCriteria(CriteriaType.KillCreature, victim.GetEntry(), 1, 0, victim, _killers.First());
|
||||
|
||||
Scenario scenario = victim.GetScenario();
|
||||
if (scenario != null)
|
||||
scenario.UpdateCriteria(CriteriaType.KillCreature, victim.GetEntry(), 1, 0, victim, _killer);
|
||||
scenario.UpdateCriteria(CriteriaType.KillCreature, victim.GetEntry(), 1, 0, victim, _killers.First());
|
||||
}
|
||||
}
|
||||
|
||||
void _InitGroupData()
|
||||
void _InitGroupData(Player killer)
|
||||
{
|
||||
if (_group)
|
||||
Group group = killer.GetGroup();
|
||||
if (group != null)
|
||||
{
|
||||
// 2. In case when player is in group, initialize variables necessary for group calculations:
|
||||
for (GroupReference refe = _group.GetFirstMember(); refe != null; refe = refe.Next())
|
||||
for (GroupReference refe = group.GetFirstMember(); refe != null; refe = refe.Next())
|
||||
{
|
||||
Player member = refe.GetSource();
|
||||
if (member)
|
||||
if (member != null)
|
||||
{
|
||||
if (_killer == member || (member.IsAtGroupRewardDistance(_victim) && member.IsAlive()))
|
||||
if (killer == member || (member.IsAtGroupRewardDistance(_victim) && member.IsAlive()))
|
||||
{
|
||||
uint lvl = member.GetLevel();
|
||||
// 2.1. _count - number of alive group members within reward distance;
|
||||
@@ -143,14 +153,14 @@ namespace Game.Entities
|
||||
_count = 1;
|
||||
}
|
||||
|
||||
void _InitXP(Player player)
|
||||
void _InitXP(Player player, Player killer)
|
||||
{
|
||||
// Get initial value of XP for kill.
|
||||
// XP is given:
|
||||
// * on Battlegrounds;
|
||||
// * otherwise, not in PvP;
|
||||
// * not if killer is on vehicle.
|
||||
if (_isBattleground || (!_isPvP && _killer.GetVehicle() == null))
|
||||
if (_isBattleground || (!_isPvP && killer.GetVehicle() == null))
|
||||
_xp = Formulas.XPGain(player, _victim, _isBattleground);
|
||||
}
|
||||
|
||||
@@ -164,7 +174,7 @@ namespace Game.Entities
|
||||
void _RewardXP(Player player, float rate)
|
||||
{
|
||||
uint xp = _xp;
|
||||
if (_group)
|
||||
if (player.GetGroup() != null)
|
||||
{
|
||||
// 4.2.1. If player is in group, adjust XP:
|
||||
// * set to 0 if player's level is more than maximum level of not gray member;
|
||||
@@ -188,7 +198,7 @@ namespace Game.Entities
|
||||
Pet pet = player.GetPet();
|
||||
if (pet)
|
||||
// 4.2.4. If player has pet, reward pet with XP (100% for single player, 50% for group case).
|
||||
pet.GivePetXP(_group ? xp / 2 : xp);
|
||||
pet.GivePetXP(player.GetGroup() != null ? xp / 2 : xp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +212,7 @@ namespace Game.Entities
|
||||
void _RewardKillCredit(Player player)
|
||||
{
|
||||
// 4.4. Give kill credit (player must not be in group, or he must be alive or without corpse).
|
||||
if (!_group || player.IsAlive() || player.GetCorpse() == null)
|
||||
if (player.GetGroup() == null || player.IsAlive() || player.GetCorpse() == null)
|
||||
{
|
||||
Creature target = _victim.ToCreature();
|
||||
if (target != null)
|
||||
@@ -228,7 +238,7 @@ namespace Game.Entities
|
||||
// Give reputation and kill credit only in PvE.
|
||||
if (!_isPvP || _isBattleground)
|
||||
{
|
||||
float rate = _group ? _groupRate * player.GetLevel() / _sumLevel : 1.0f;
|
||||
float rate = player.GetGroup() != null ? _groupRate * player.GetLevel() / _sumLevel : 1.0f;
|
||||
if (_xp != 0)
|
||||
// 4.2. Give XP.
|
||||
_RewardXP(player, rate);
|
||||
@@ -241,34 +251,34 @@ namespace Game.Entities
|
||||
}
|
||||
}
|
||||
|
||||
void _RewardGroup()
|
||||
void _RewardGroup(Group group, Player killer)
|
||||
{
|
||||
if (_maxLevel != 0)
|
||||
{
|
||||
if (_maxNotGrayMember != null)
|
||||
// 3.1.1. Initialize initial XP amount based on maximum level of group member,
|
||||
// for whom victim is not gray.
|
||||
_InitXP(_maxNotGrayMember);
|
||||
_InitXP(_maxNotGrayMember, killer);
|
||||
// To avoid unnecessary calculations and calls,
|
||||
// proceed only if XP is not ZERO or player is not on Battleground
|
||||
// (Battlegroundrewards only XP, that's why).
|
||||
if (!_isBattleground || _xp != 0)
|
||||
{
|
||||
bool isDungeon = !_isPvP && CliDB.MapStorage.LookupByKey(_killer.GetMapId()).IsDungeon();
|
||||
bool isDungeon = !_isPvP && CliDB.MapStorage.LookupByKey(killer.GetMapId()).IsDungeon();
|
||||
if (!_isBattleground)
|
||||
{
|
||||
// 3.1.2. Alter group rate if group is in raid (not for Battlegrounds).
|
||||
bool isRaid = !_isPvP && CliDB.MapStorage.LookupByKey(_killer.GetMapId()).IsRaid() && _group.IsRaidGroup();
|
||||
bool isRaid = !_isPvP && CliDB.MapStorage.LookupByKey(killer.GetMapId()).IsRaid() && group.IsRaidGroup();
|
||||
_groupRate = Formulas.XPInGroupRate(_count, isRaid);
|
||||
}
|
||||
// 3.1.3. Reward each group member (even dead or corpse) within reward distance.
|
||||
for (GroupReference refe = _group.GetFirstMember(); refe != null; refe = refe.Next())
|
||||
for (GroupReference refe = group.GetFirstMember(); refe != null; refe = refe.Next())
|
||||
{
|
||||
Player member = refe.GetSource();
|
||||
if (member)
|
||||
{
|
||||
// Killer may not be at reward distance, check directly
|
||||
if (_killer == member || member.IsAtGroupRewardDistance(_victim))
|
||||
if (killer == member || member.IsAtGroupRewardDistance(_victim))
|
||||
_RewardPlayer(member, isDungeon);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,11 +44,6 @@ namespace Game.Entities
|
||||
}
|
||||
}
|
||||
|
||||
public void RewardPlayerAndGroupAtKill(Unit victim, bool isBattleground)
|
||||
{
|
||||
new KillRewarder(this, victim, isBattleground).Reward();
|
||||
}
|
||||
|
||||
public void RewardPlayerAndGroupAtEvent(uint creature_id, WorldObject pRewardSource)
|
||||
{
|
||||
if (pRewardSource == null)
|
||||
|
||||
@@ -3126,7 +3126,7 @@ namespace Game.Entities
|
||||
|
||||
public bool IsAllowedToLoot(Creature creature)
|
||||
{
|
||||
if (!creature.IsDead() || !creature.IsDamageEnoughForLootingAndReward())
|
||||
if (!creature.IsDead())
|
||||
return false;
|
||||
|
||||
if (HasPendingBind())
|
||||
@@ -3139,15 +3139,6 @@ namespace Game.Entities
|
||||
if (!loot.HasAllowedLooter(GetGUID()) || (!loot.HasItemForAll() && !loot.HasItemFor(this))) // no loot in creature for this player
|
||||
return false;
|
||||
|
||||
if (loot.loot_type == LootType.Skinning)
|
||||
return creature.GetLootRecipientGUID() == GetGUID();
|
||||
|
||||
Group thisGroup = GetGroup();
|
||||
if (!thisGroup)
|
||||
return this == creature.GetLootRecipient();
|
||||
else if (thisGroup != creature.GetLootRecipientGroup())
|
||||
return false;
|
||||
|
||||
switch (loot.GetLootMethod())
|
||||
{
|
||||
case LootMethod.PersonalLoot:// @todo implement personal loot (http://wow.gamepedia.com/Loot#Personal_Loot)
|
||||
|
||||
@@ -706,36 +706,16 @@ namespace Game.Entities
|
||||
|
||||
bool isRewardAllowed = true;
|
||||
if (creature != null)
|
||||
{
|
||||
isRewardAllowed = creature.IsDamageEnoughForLootingAndReward();
|
||||
if (!isRewardAllowed)
|
||||
creature.SetLootRecipient(null);
|
||||
}
|
||||
isRewardAllowed = !creature.GetTapList().Empty();
|
||||
|
||||
List<Player> tappers = new();
|
||||
if (isRewardAllowed && creature)
|
||||
{
|
||||
Player lootRecipient = creature.GetLootRecipient();
|
||||
if (lootRecipient != null)
|
||||
foreach (ObjectGuid tapperGuid in creature.GetTapList())
|
||||
{
|
||||
// Loot recipient can be in a different map
|
||||
if (!creature.IsInMap(lootRecipient))
|
||||
{
|
||||
Group group = creature.GetLootRecipientGroup();
|
||||
if (group != null)
|
||||
{
|
||||
for (GroupReference itr = group.GetFirstMember(); itr != null; itr = itr.Next())
|
||||
{
|
||||
Player member = itr.GetSource();
|
||||
if (!member || !creature.IsInMap(member))
|
||||
continue;
|
||||
|
||||
player = member;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
player = creature.GetLootRecipient();
|
||||
Player tapper = Global.ObjAccessor.GetPlayer(creature, tapperGuid);
|
||||
if (tapper != null)
|
||||
tappers.Add(tapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -745,64 +725,92 @@ namespace Game.Entities
|
||||
|
||||
// Reward player, his pets, and group/raid members
|
||||
// call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop)
|
||||
if (isRewardAllowed && player != null && player != victim)
|
||||
if (isRewardAllowed)
|
||||
{
|
||||
PartyKillLog partyKillLog = new();
|
||||
partyKillLog.Player = player.GetGUID();
|
||||
partyKillLog.Victim = victim.GetGUID();
|
||||
partyKillLog.Write();
|
||||
|
||||
Player looter = player;
|
||||
var group = player.GetGroup();
|
||||
if (group)
|
||||
HashSet<Group> groups = new();
|
||||
foreach (Player tapper in tappers)
|
||||
{
|
||||
group.BroadcastPacket(partyKillLog, group.GetMemberGroup(player.GetGUID()) != 0);
|
||||
|
||||
if (creature)
|
||||
Group tapperGroup = tapper.GetGroup();
|
||||
if (tapperGroup != null)
|
||||
{
|
||||
group.UpdateLooterGuid(creature, true);
|
||||
if (!group.GetLooterGuid().IsEmpty())
|
||||
if (groups.Add(tapperGroup))
|
||||
{
|
||||
looter = Global.ObjAccessor.FindPlayer(group.GetLooterGuid());
|
||||
if (looter)
|
||||
creature.SetLootRecipient(looter); // update creature loot recipient to the allowed looter.
|
||||
tapperGroup.BroadcastPacket(partyKillLog, tapperGroup.GetMemberGroup(tapper.GetGUID()) != 0);
|
||||
|
||||
if (creature)
|
||||
tapperGroup.UpdateLooterGuid(creature, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
tapper.SendPacket(partyKillLog);
|
||||
}
|
||||
else
|
||||
player.SendPacket(partyKillLog);
|
||||
|
||||
// Generate loot before updating looter
|
||||
if (creature)
|
||||
{
|
||||
creature.loot = new Loot(creature.GetMap(), creature.GetGUID(), LootType.Corpse, group);
|
||||
Loot loot = creature.loot;
|
||||
if (creature.GetMap().Is25ManRaid())
|
||||
loot.maxDuplicates = 3;
|
||||
|
||||
DungeonEncounterRecord dungeonEncounter = null;
|
||||
InstanceScript instance = creature.GetInstanceScript();
|
||||
if (instance != null)
|
||||
dungeonEncounter = instance.GetBossDungeonEncounter(creature);
|
||||
|
||||
if (creature.GetMap().IsDungeon())
|
||||
{
|
||||
DungeonEncounterRecord dungeonEncounter = instance.GetBossDungeonEncounter(creature);
|
||||
Group group = !groups.Empty() ? groups.First() : null;
|
||||
Player looter = group ? Global.ObjAccessor.GetPlayer(creature, group.GetLooterGuid()) : tappers[0];
|
||||
|
||||
Loot loot = new(creature.GetMap(), creature.GetGUID(), LootType.Corpse, dungeonEncounter != null ? group : null);
|
||||
|
||||
if (dungeonEncounter != null)
|
||||
loot.SetDungeonEncounterId(dungeonEncounter.Id);
|
||||
|
||||
uint lootid = creature.GetCreatureTemplate().LootId;
|
||||
if (lootid != 0)
|
||||
loot.FillLoot(lootid, LootStorage.Creature, looter, dungeonEncounter != null, false, creature.GetLootMode(), creature.GetMap().GetDifficultyLootItemContext());
|
||||
|
||||
if (creature.GetLootMode() > 0)
|
||||
loot.GenerateMoneyLoot(creature.GetCreatureTemplate().MinGold, creature.GetCreatureTemplate().MaxGold);
|
||||
|
||||
if (group)
|
||||
loot.NotifyLootList(creature.GetMap());
|
||||
|
||||
if (dungeonEncounter != null || groups.Empty())
|
||||
creature._loot = loot; // TODO: personal boss loot
|
||||
else
|
||||
creature.m_personalLoot[looter.GetGUID()] = loot; // trash mob loot is personal, generated with round robin rules
|
||||
|
||||
// Update round robin looter only if the creature had loot
|
||||
if (!loot.IsLooted())
|
||||
foreach (Group tapperGroup in groups)
|
||||
tapperGroup.UpdateLooterGuid(creature);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Player tapper in tappers)
|
||||
{
|
||||
Loot loot = new(creature.GetMap(), creature.GetGUID(), LootType.Corpse, null);
|
||||
|
||||
uint lootid = creature.GetCreatureTemplate().LootId;
|
||||
if (lootid != 0)
|
||||
loot.FillLoot(lootid, LootStorage.Creature, looter, false, false, creature.GetLootMode(), creature.GetMap().GetDifficultyLootItemContext());
|
||||
if (dungeonEncounter != null)
|
||||
loot.SetDungeonEncounterId(dungeonEncounter.Id);
|
||||
|
||||
if (creature.GetLootMode() > 0)
|
||||
loot.GenerateMoneyLoot(creature.GetCreatureTemplate().MinGold, creature.GetCreatureTemplate().MaxGold);
|
||||
uint lootid = creature.GetCreatureTemplate().LootId;
|
||||
if (lootid != 0)
|
||||
loot.FillLoot(lootid, LootStorage.Creature, tapper, true, false, creature.GetLootMode(), creature.GetMap().GetDifficultyLootItemContext());
|
||||
|
||||
loot.NotifyLootList(creature.GetMap());
|
||||
if (creature.GetLootMode() > 0)
|
||||
loot.GenerateMoneyLoot(creature.GetCreatureTemplate().MinGold, creature.GetCreatureTemplate().MaxGold);
|
||||
|
||||
// Update round robin looter only if the creature had loot
|
||||
if (group != null && !loot.Empty())
|
||||
group.UpdateLooterGuid(creature);
|
||||
creature.m_personalLoot[tapper.GetGUID()] = loot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.RewardPlayerAndGroupAtKill(victim, false);
|
||||
}
|
||||
new KillRewarder(tappers.ToArray(), victim, false).Reward();
|
||||
}
|
||||
|
||||
// Do KILL and KILLED procs. KILL proc is called only for the unit who landed the killing blow (and its owner - for pets and totems) regardless of who tapped the victim
|
||||
if (attacker != null && (attacker.IsPet() || attacker.IsTotem()))
|
||||
@@ -816,16 +824,10 @@ namespace Game.Entities
|
||||
if (!victim.IsCritter())
|
||||
{
|
||||
ProcSkillsAndAuras(attacker, victim, new ProcFlagsInit(ProcFlags.Kill), new ProcFlagsInit(ProcFlags.Heartbeat), ProcFlagsSpellType.MaskAll, ProcFlagsSpellPhase.None, ProcFlagsHit.None, null, null, null);
|
||||
if (player != null && player.GetGroup() != null)
|
||||
{
|
||||
for (GroupReference itr = player.GetGroup().GetFirstMember(); itr != null; itr = itr.Next())
|
||||
{
|
||||
Player member = itr.GetSource();
|
||||
if (member != null)
|
||||
if (member.IsAtGroupRewardDistance(victim))
|
||||
Unit.ProcSkillsAndAuras(member, victim, new ProcFlagsInit(ProcFlags.None, ProcFlags2.TargetDies), new ProcFlagsInit(ProcFlags.None), ProcFlagsSpellType.MaskAll, ProcFlagsSpellPhase.None, ProcFlagsHit.None, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Player tapper in tappers)
|
||||
if (tapper.IsAtGroupRewardDistance(victim))
|
||||
Unit.ProcSkillsAndAuras(tapper, victim, new ProcFlagsInit(ProcFlags.None, ProcFlags2.TargetDies), new ProcFlagsInit(), ProcFlagsSpellType.MaskAll, ProcFlagsSpellPhase.None, ProcFlagsHit.None, null, null, null);
|
||||
}
|
||||
|
||||
// Proc auras on death - must be before aura/combat remove
|
||||
@@ -849,9 +851,9 @@ namespace Game.Entities
|
||||
// Inform pets (if any) when player kills target)
|
||||
// MUST come after victim.setDeathState(JUST_DIED); or pet next target
|
||||
// selection will get stuck on same target and break pet react state
|
||||
if (player != null)
|
||||
foreach (Player tapper in tappers)
|
||||
{
|
||||
Pet pet = player.GetPet();
|
||||
Pet pet = tapper.GetPet();
|
||||
if (pet != null && pet.IsAlive() && pet.IsControlled())
|
||||
{
|
||||
if (pet.IsAIEnabled())
|
||||
@@ -899,10 +901,16 @@ namespace Game.Entities
|
||||
if (!creature.IsPet())
|
||||
{
|
||||
// must be after setDeathState which resets dynamic flags
|
||||
if (creature.loot != null && !creature.loot.IsLooted())
|
||||
if (!creature.IsFullyLooted())
|
||||
creature.SetDynamicFlag(UnitDynFlags.Lootable);
|
||||
else
|
||||
creature.AllLootRemovedFromCorpse();
|
||||
|
||||
if (LootStorage.Skinning.HaveLootFor(creature.GetCreatureTemplate().SkinLootId))
|
||||
{
|
||||
creature.SetDynamicFlag(UnitDynFlags.CanSkin);
|
||||
creature.SetUnitFlag(UnitFlags.Skinnable);
|
||||
}
|
||||
}
|
||||
|
||||
// Call KilledUnit for creatures, this needs to be called after the lootable flag is set
|
||||
|
||||
@@ -2574,8 +2574,7 @@ namespace Game.Entities
|
||||
|
||||
if (victim.GetTypeId() != TypeId.Player && (!victim.IsControlledByPlayer() || victim.IsVehicle()))
|
||||
{
|
||||
if (!victim.ToCreature().HasLootRecipient())
|
||||
victim.ToCreature().SetLootRecipient(attacker);
|
||||
victim.ToCreature().SetTappedBy(attacker);
|
||||
|
||||
if (attacker == null || attacker.IsControlledByPlayer())
|
||||
victim.ToCreature().LowerPlayerDamageReq(health < damage ? health : damage);
|
||||
|
||||
Reference in New Issue
Block a user