Core/Items: Addes support for calculating item level & cleanup iterating over items.

Based on https://github.com/TrinityCore/TrinityCore/pull/26276
This commit is contained in:
hondacrx
2021-03-24 15:44:49 -04:00
parent 62ec699ec6
commit cad2a7fa88
6 changed files with 362 additions and 603 deletions
+6 -6
View File
@@ -759,13 +759,13 @@ namespace Framework.Constants
public enum ItemSearchLocation
{
InEquipment = 0x01,
InInventory = 0x02,
InBank = 0x04,
InReagentBank = 0x08,
Equipment = 0x01,
Inventory = 0x02,
Bank = 0x04,
ReagentBank = 0x08,
Default = InEquipment | InInventory,
Everywhere = InEquipment | InInventory | InBank | InReagentBank
Default = Equipment | Inventory,
Everywhere = Equipment | Inventory | Bank | ReagentBank
}
public enum ZonePVPTypeOverride
File diff suppressed because it is too large Load Diff
+23 -23
View File
@@ -302,7 +302,7 @@ namespace Game.Entities
if (msg == InventoryResult.Ok)
{
RemoveItem(InventorySlots.Bag0, i, true);
pItem = StoreItem(sDest, pItem, true);
StoreItem(sDest, pItem, true);
}
}
}
@@ -1854,7 +1854,7 @@ namespace Game.Entities
public uint GetStartLevel(Race race, Class playerClass, Optional<uint> characterTemplateId = default)
{
uint startLevel = WorldConfig.GetUIntValue(WorldCfg.StartPlayerLevel);
if (CliDB.ChrRacesStorage.LookupByKey(race).GetFlags().HasFlag(ChrRacesFlag.AlliedRace))
if (CliDB.ChrRacesStorage.LookupByKey(race).GetFlags().HasAnyFlag(ChrRacesFlag.AlliedRace))
startLevel = WorldConfig.GetUIntValue(WorldCfg.StartAlliedRaceLevel);
if (playerClass == Class.Deathknight)
@@ -2345,8 +2345,8 @@ namespace Game.Entities
if (canTalk)
{
string strOptionText = "";
string strBoxText = "";
string strOptionText;
string strBoxText;
BroadcastTextRecord optionBroadcastText = CliDB.BroadcastTextStorage.LookupByKey(menuItems.OptionBroadcastTextId);
BroadcastTextRecord boxBroadcastText = CliDB.BroadcastTextStorage.LookupByKey(menuItems.BoxBroadcastTextId);
Locale locale = GetSession().GetSessionDbLocaleIndex();
@@ -4024,7 +4024,7 @@ namespace Game.Entities
return false;
}
public override bool IsNeverVisibleFor(WorldObject seer)
{
if (base.IsNeverVisibleFor(seer))
@@ -4807,7 +4807,7 @@ namespace Game.Entities
if (pet != null)
pet.RemoveAurasDueToSpell(petSpell.GetAura(pet.GetEntry()));
}
public bool InArena()
{
Battleground bg = GetBattleground();
@@ -4955,7 +4955,7 @@ namespace Game.Entities
reward.ItemChoices.Add(rewardEntry);
}
playerChoiceResponse.Reward.Set(reward);
displayPlayerChoice.Responses[i] = playerChoiceResponse;
}
@@ -6141,7 +6141,7 @@ namespace Game.Entities
{
ushort areaLevel = (ushort)Math.Min(Math.Max((ushort)GetLevel(), areaLevels.Value.MinLevel), areaLevels.Value.MaxLevel);
int diff = (int)(GetLevel()) - areaLevel;
uint XP = 0;
uint XP;
if (diff < -5)
{
XP = (uint)(Global.ObjectMgr.GetBaseXP(GetLevel() + 5) * WorldConfig.GetFloatValue(WorldCfg.RateXpExplore));
@@ -6523,13 +6523,13 @@ namespace Game.Entities
switch (modGroup)
{
case BaseModGroup.CritPercentage:
UpdateCritPercentage(WeaponAttackType.BaseAttack);
case BaseModGroup.CritPercentage:
UpdateCritPercentage(WeaponAttackType.BaseAttack);
break;
case BaseModGroup.RangedCritPercentage:
UpdateCritPercentage(WeaponAttackType.RangedAttack);
case BaseModGroup.RangedCritPercentage:
UpdateCritPercentage(WeaponAttackType.RangedAttack);
break;
case BaseModGroup.OffhandCritPercentage:
case BaseModGroup.OffhandCritPercentage:
UpdateCritPercentage(WeaponAttackType.OffAttack);
break;
default:
@@ -6558,7 +6558,7 @@ namespace Game.Entities
return m_auraBaseFlatMod[(int)modGroup] * m_auraBasePctMod[(int)modGroup];
}
public void AddComboPoints(sbyte count, Spell spell = null)
{
if (count == 0)
@@ -7208,15 +7208,12 @@ namespace Game.Entities
}
public static WeaponAttackType GetAttackBySlot(byte slot, InventoryType inventoryType)
{
switch (slot)
return slot switch
{
case EquipmentSlot.MainHand:
return inventoryType != InventoryType.Ranged && inventoryType != InventoryType.RangedRight ? WeaponAttackType.BaseAttack : WeaponAttackType.RangedAttack;
case EquipmentSlot.OffHand:
return WeaponAttackType.OffAttack;
default:
return WeaponAttackType.Max;
}
EquipmentSlot.MainHand => inventoryType != InventoryType.Ranged && inventoryType != InventoryType.RangedRight ? WeaponAttackType.BaseAttack : WeaponAttackType.RangedAttack,
EquipmentSlot.OffHand => WeaponAttackType.OffAttack,
_ => WeaponAttackType.Max,
};
}
public void AutoUnequipOffhandIfNeed(bool force = false)
{
@@ -7290,6 +7287,9 @@ namespace Game.Entities
public void RemovePlayerFlagEx(PlayerFlagsEx flags) { RemoveUpdateFieldFlagValue(m_values.ModifyValue(m_playerData).ModifyValue(m_playerData.PlayerFlagsEx), (uint)flags); }
public void SetPlayerFlagsEx(PlayerFlagsEx flags) { SetUpdateFieldValue(m_values.ModifyValue(m_playerData).ModifyValue(m_playerData.PlayerFlagsEx), (uint)flags); }
public void UpdateAverageItemLevelTotal(float newItemLevel) { SetUpdateFieldValue(ref m_values.ModifyValue(m_playerData).ModifyValue(m_playerData.AvgItemLevel, 0), newItemLevel); }
public void UpdateAverageItemLevelEquipped(float newItemLevel) { SetUpdateFieldValue(ref m_values.ModifyValue(m_playerData).ModifyValue(m_playerData.AvgItemLevel, 1), newItemLevel); }
public uint GetCustomizationChoice(uint chrCustomizationOptionId)
{
int choiceIndex = m_playerData.Customizations.FindIndexIf(choice =>
@@ -7317,7 +7317,7 @@ namespace Game.Entities
AddDynamicUpdateFieldValue(m_values.ModifyValue(m_playerData).ModifyValue(m_playerData.Customizations), newChoice);
}
}
public Gender GetNativeSex() { return (Gender)(byte)m_playerData.NativeSex; }
public void SetNativeSex(Gender sex) { SetUpdateFieldValue(m_values.ModifyValue(m_playerData).ModifyValue(m_playerData.NativeSex), (byte)sex); }
public void SetPvpTitle(byte pvpTitle) { SetUpdateFieldValue(m_values.ModifyValue(m_playerData).ModifyValue(m_playerData.PvpTitle), pvpTitle); }
+1 -1
View File
@@ -66,7 +66,7 @@ namespace Game.Entities
public float ModMeleeHitChance { get; set; }
public float ModRangedHitChance { get; set; }
public float ModSpellHitChance { get; set; }
bool m_canDualWield;
public bool m_canDualWield;
public int BaseSpellCritChance { get; set; }
public uint RegenTimer { get; set; }
uint combatTimer;
+1 -1
View File
@@ -65,7 +65,7 @@ namespace Game
ActivateEssenceFailed activateEssenceResult = new();
activateEssenceResult.AzeriteEssenceID = azeriteEssenceActivateEssence.AzeriteEssenceID;
Item item = _player.GetItemByEntry(PlayerConst.ItemIdHeartOfAzeroth, ItemSearchLocation.InEquipment);
Item item = _player.GetItemByEntry(PlayerConst.ItemIdHeartOfAzeroth, ItemSearchLocation.Equipment);
if (item == null)
{
activateEssenceResult.Reason = AzeriteEssenceActivateResult.NotEquipped;
+3
View File
@@ -1024,6 +1024,9 @@ namespace Game
if (!pCurrChar.IsStandState() && !pCurrChar.HasUnitState(UnitState.Stunned))
pCurrChar.SetStandState(UnitStandStateType.Stand);
pCurrChar.UpdateAverageItemLevelTotal();
pCurrChar.UpdateAverageItemLevelEquipped();
m_playerLoading.Clear();
Global.ScriptMgr.OnPlayerLogin(pCurrChar);