Core/Achievements: Defined all modifier tree types and implemented many of them

Port From (https://github.com/TrinityCore/TrinityCore/commit/d0be92ec0ad0334c38b4073a7e24a571982b17da)
This commit is contained in:
hondacrx
2021-06-07 13:13:46 -04:00
parent 9c58042e07
commit 1941148d8f
18 changed files with 1677 additions and 674 deletions
@@ -59,6 +59,11 @@ namespace Game.Achievements
return _achievementPoints;
}
public ICollection<uint> GetCompletedAchievementIds()
{
return _completedAchievements.Keys;
}
public override bool CanUpdateCriteriaTree(Criteria criteria, CriteriaTree tree, Player referencePlayer)
{
AchievementRecord achievement = tree.Achievement;
File diff suppressed because it is too large Load Diff
@@ -319,6 +319,15 @@ namespace Game.BattlePets
return (byte)_pets.Values.Count(battlePet => battlePet.PacketInfo.Species == species && battlePet.SaveInfo != BattlePetSaveInfo.Removed);
}
public uint GetPetUniqueSpeciesCount()
{
HashSet<uint> speciesIds = new();
foreach (var pair in _pets)
speciesIds.Add(pair.Value.PacketInfo.Species);
return (uint)speciesIds.Count;
}
public void UnlockSlot(byte slot)
{
if (!_slots[slot].Locked)
@@ -460,6 +469,8 @@ namespace Game.BattlePets
public ushort GetTrapLevel() { return _trapLevel; }
public List<BattlePetSlot> GetSlots() { return _slots; }
public bool HasJournalLock() { return true; }
WorldSession _owner;
ushort _trapLevel;
Dictionary<ulong, BattlePet> _pets = new();
+11
View File
@@ -1463,6 +1463,17 @@ namespace Game.DataStorage
return bonusListIDs;
}
public List<uint> GetAllItemBonusTreeBonuses(uint itemBonusTreeId)
{
List<uint> bonusListIDs = new List<uint>();
VisitItemBonusTree(itemBonusTreeId, true, bonusTreeNode =>
{
if (bonusTreeNode.ChildItemBonusListID != 0)
bonusListIDs.Add(bonusTreeNode.ChildItemBonusListID);
});
return bonusListIDs;
}
void LoadAzeriteEmpoweredItemUnlockMappings(MultiMap<uint, AzeriteUnlockMappingRecord> azeriteUnlockMappingsBySet, uint itemId)
{
var itemIdRange = _itemToBonusTree.LookupByKey(itemId);
+24
View File
@@ -2089,6 +2089,30 @@ namespace Game.Entities
}
}
public uint GetTotalUnlockedArtifactPowers()
{
uint purchased = GetTotalPurchasedArtifactPowers();
ulong artifactXp = m_itemData.ArtifactXP;
uint currentArtifactTier = GetModifier(ItemModifier.ArtifactTier);
uint extraUnlocked = 0;
do
{
ulong xpCost = 0;
var cost = CliDB.ArtifactLevelXPGameTable.GetRow(purchased + extraUnlocked + 1);
if (cost != null)
xpCost = (ulong)(currentArtifactTier == PlayerConst.MaxArtifactTier ? cost.XP2 : cost.XP);
if (artifactXp < xpCost)
break;
artifactXp -= xpCost;
++extraUnlocked;
} while (true);
return purchased + extraUnlocked;
}
public uint GetTotalPurchasedArtifactPowers()
{
uint purchasedRanks = 0;
@@ -728,7 +728,7 @@ namespace Game.Entities
{
int transmogSlot = Item.ItemTransmogrificationSlots[(int)item.inventoryType];
if (transmogSlot >= 0)
_owner.GetPlayer().UpdateCriteria(CriteriaTypes.AppearanceUnlockedBySlot, (ulong)transmogSlot, 1);
_owner.GetPlayer().UpdateCriteria(CriteriaTypes.AppearanceUnlockedBySlot, (ulong)transmogSlot, itemModifiedAppearance.Id);
}
var sets = Global.DB2Mgr.GetTransmogSetsForItemModifiedAppearance(itemModifiedAppearance.Id);
@@ -20,6 +20,7 @@ using Game.Achievements;
using Game.DataStorage;
using Game.Guilds;
using Game.Scenarios;
using System.Collections.Generic;
namespace Game.Entities
{
@@ -39,6 +40,12 @@ namespace Game.Entities
{
return m_achievementSys.GetAchievementPoints();
}
public ICollection<uint> GetCompletedAchievementIds()
{
return m_achievementSys.GetCompletedAchievementIds();
}
public bool HasAchieved(uint achievementId)
{
return m_achievementSys.HasAchieved(achievementId);
+71 -25
View File
@@ -1511,7 +1511,7 @@ namespace Game.Entities
InventoryResult res = InventoryResult.Ok;
uint tempcount = 0;
bool result = ForEachStorageItem(ItemSearchLocation.Equipment, pItem =>
bool result = ForEachItem(ItemSearchLocation.Equipment, pItem =>
{
if (pItem.GetEntry() == item)
{
@@ -2615,7 +2615,7 @@ namespace Game.Entities
public Item GetItemByGuid(ObjectGuid guid)
{
Item result = null;
ForEachStorageItem(ItemSearchLocation.Everywhere, item =>
ForEachItem(ItemSearchLocation.Everywhere, item =>
{
if (item.GetGUID() == guid)
{
@@ -2637,7 +2637,7 @@ namespace Game.Entities
location |= ItemSearchLocation.Bank;
uint count = 0;
ForEachStorageItem(location, pItem =>
ForEachItem(location, pItem =>
{
if (pItem != skipItem)
{
@@ -2684,7 +2684,7 @@ namespace Game.Entities
public Item GetItemByEntry(uint entry, ItemSearchLocation where = ItemSearchLocation.Default)
{
Item result = null;
ForEachStorageItem(where, item =>
ForEachItem(where, item =>
{
if (item.GetEntry() == entry)
{
@@ -2704,7 +2704,7 @@ namespace Game.Entities
location |= ItemSearchLocation.Bank;
List<Item> itemList = new();
ForEachStorageItem(location, item =>
ForEachItem(location, item =>
{
if (item.GetEntry() == entry)
itemList.Add(item);
@@ -2721,7 +2721,7 @@ namespace Game.Entities
location |= ItemSearchLocation.Bank;
uint currentCount = 0;
return !ForEachStorageItem(location, pItem =>
return !ForEachItem(location, pItem =>
{
if (pItem && pItem.GetEntry() == item && !pItem.IsInTrade())
{
@@ -2791,7 +2791,7 @@ namespace Game.Entities
public Item GetChildItemByGuid(ObjectGuid guid)
{
Item result = null;
ForEachStorageItem(ItemSearchLocation.Equipment | ItemSearchLocation.Inventory, item =>
ForEachItem(ItemSearchLocation.Equipment | ItemSearchLocation.Inventory, item =>
{
if (item.GetGUID() == guid)
{
@@ -2807,7 +2807,7 @@ namespace Game.Entities
uint GetItemCountWithLimitCategory(uint limitCategory, Item skipItem)
{
uint count = 0;
ForEachStorageItem(ItemSearchLocation.Everywhere, item =>
ForEachItem(ItemSearchLocation.Everywhere, item =>
{
if (item != skipItem)
{
@@ -3428,23 +3428,16 @@ namespace Game.Entities
return false;
}
uint GetMaxPersonalArenaRatingRequirement(uint minarenaslot)
public uint GetMaxPersonalArenaRatingRequirement(uint minarenaslot)
{
// returns the maximal personal arena rating that can be used to purchase items requiring this condition
// the personal rating of the arena team must match the required limit as well
// so return max[in arenateams](min(personalrating[teamtype], teamrating[teamtype]))
// so return max[in arenateams](personalrating[teamtype])
uint max_personal_rating = 0;
for (byte i = (byte)minarenaslot; i < SharedConst.MaxArenaSlot; ++i)
{
ArenaTeam at = Global.ArenaTeamMgr.GetArenaTeamById(GetArenaTeamId(i));
if (at != null)
{
uint p_rating = GetArenaPersonalRating(i);
uint t_rating = at.GetRating();
p_rating = p_rating < t_rating ? p_rating : t_rating;
if (max_personal_rating < p_rating)
max_personal_rating = p_rating;
}
uint p_rating = GetArenaPersonalRating(i);
if (max_personal_rating < p_rating)
max_personal_rating = p_rating;
}
return max_personal_rating;
}
@@ -4469,7 +4462,60 @@ namespace Game.Entities
{
return StoreItem(dest, pItem, update);
}
public uint GetFreeInventorySlotCount(ItemSearchLocation location = ItemSearchLocation.Inventory)
{
uint freeSlotCount = 0;
if (location.HasFlag(ItemSearchLocation.Equipment))
for (byte i = EquipmentSlot.Start; i < EquipmentSlot.End; ++i)
if (GetItemByPos(InventorySlots.Bag0, i) == null)
++freeSlotCount;
if (location.HasFlag(ItemSearchLocation.Inventory))
{
int inventoryEnd = InventorySlots.ItemStart + GetInventorySlotCount();
for (byte i = InventorySlots.ItemStart; i < inventoryEnd; ++i)
if (GetItemByPos(InventorySlots.Bag0, i) == null)
++freeSlotCount;
for (byte i = InventorySlots.BagStart; i < InventorySlots.BagEnd; ++i)
{
Bag bag = GetBagByPos(i);
if (bag != null)
{
for (byte j = 0; j < bag.GetBagSize(); ++j)
if (bag.GetItemByPos(j) == null)
++freeSlotCount;
}
}
}
if (location.HasFlag(ItemSearchLocation.Bank))
{
for (byte i = InventorySlots.BankItemStart; i < InventorySlots.BankItemEnd; ++i)
if (GetItemByPos(InventorySlots.Bag0, i) == null)
++freeSlotCount;
for (byte i = InventorySlots.BankBagStart; i < InventorySlots.BankBagEnd; ++i)
{
Bag bag = GetBagByPos(i);
if (bag != null)
{
for (byte j = 0; j < bag.GetBagSize(); ++j)
if (bag.GetItemByPos(j) == null)
++freeSlotCount;
}
}
}
if (location.HasFlag(ItemSearchLocation.ReagentBank))
for (byte i = InventorySlots.ReagentStart; i < InventorySlots.ReagentEnd; ++i)
if (GetItemByPos(InventorySlots.Bag0, i) == null)
++freeSlotCount;
return freeSlotCount;
}
//Bags
public Bag GetBagByPos(byte bag)
{
@@ -5242,7 +5288,7 @@ namespace Game.Entities
ItemTemplate pProto = Global.ObjectMgr.GetItemTemplate(item);
bool includeGems = pProto?.GetGemProperties() != 0;
return !ForEachStorageItem(ItemSearchLocation.Equipment, pItem =>
return !ForEachItem(ItemSearchLocation.Equipment, pItem =>
{
if (pItem.GetSlot() != except_slot)
{
@@ -5261,7 +5307,7 @@ namespace Game.Entities
bool HasItemWithLimitCategoryEquipped(uint limitCategory, uint count, byte except_slot)
{
uint tempcount = 0;
return !ForEachStorageItem(ItemSearchLocation.Equipment, pItem =>
return !ForEachItem(ItemSearchLocation.Equipment, pItem =>
{
if (pItem.GetSlot() == except_slot)
return true;
@@ -5280,7 +5326,7 @@ namespace Game.Entities
bool HasGemWithLimitCategoryEquipped(uint limitCategory, uint count, byte except_slot)
{
uint tempcount = 0;
return !ForEachStorageItem(ItemSearchLocation.Equipment, pItem =>
return !ForEachItem(ItemSearchLocation.Equipment, pItem =>
{
if (pItem.GetSlot() == except_slot)
return true;
@@ -6555,7 +6601,7 @@ namespace Game.Entities
// @todo other types of power scaling such as timewalking
}
bool ForEachStorageItem(ItemSearchLocation location, Func<Item, bool> callback)
public bool ForEachItem(ItemSearchLocation location, Func<Item, bool> callback)
{
if (location.HasAnyFlag(ItemSearchLocation.Equipment))
{
@@ -6720,7 +6766,7 @@ namespace Game.Entities
(InventoryType inventoryType, uint itemLevel, ObjectGuid guid)[] bestItemLevels = new (InventoryType inventoryType, uint itemLevel, ObjectGuid guid)[EquipmentSlot.End];
float sum = 0;
ForEachStorageItem(ItemSearchLocation.Everywhere, item =>
ForEachItem(ItemSearchLocation.Everywhere, item =>
{
ItemTemplate itemTemplate = item.GetTemplate();
if (itemTemplate != null)
+17 -7
View File
@@ -5015,7 +5015,7 @@ namespace Game.Entities
return true;
}
bool CanEnableWarModeInArea()
public bool CanEnableWarModeInArea()
{
var area = CliDB.AreaTableStorage.LookupByKey(GetAreaId());
if (area == null || !IsFriendlyArea(area))
@@ -5878,6 +5878,16 @@ namespace Game.Entities
return reputationMgr;
}
public void SetReputation(uint factionentry, int value)
{
GetReputationMgr().SetReputation(CliDB.FactionStorage.LookupByKey(factionentry), value);
}
public int GetReputation(uint factionentry)
{
return GetReputationMgr().GetReputation(CliDB.FactionStorage.LookupByKey(factionentry));
}
#region Sends / Updates
void BeforeVisibilityDestroy(WorldObject obj, Player p)
{
@@ -6423,12 +6433,12 @@ namespace Game.Entities
SendMovementSetCollisionHeight(scale * GetCollisionHeight(), UpdateCollisionHeightReason.Scale);
}
bool HasRaceChanged() { return m_ExtraFlags.HasFlag(PlayerExtraFlags.HasRaceChanged); }
void SetHasRaceChanged() { m_ExtraFlags |= PlayerExtraFlags.HasRaceChanged; }
bool HasBeenGrantedLevelsFromRaF() { return m_ExtraFlags.HasFlag(PlayerExtraFlags.GrantedLevelsFromRaf); }
void SetBeenGrantedLevelsFromRaF() { m_ExtraFlags |= PlayerExtraFlags.GrantedLevelsFromRaf; }
bool HasLevelBoosted() { return m_ExtraFlags.HasFlag(PlayerExtraFlags.LevelBoosted); }
void SetHasLevelBoosted() { m_ExtraFlags |= PlayerExtraFlags.LevelBoosted; }
public bool HasRaceChanged() { return m_ExtraFlags.HasFlag(PlayerExtraFlags.HasRaceChanged); }
public void SetHasRaceChanged() { m_ExtraFlags |= PlayerExtraFlags.HasRaceChanged; }
public bool HasBeenGrantedLevelsFromRaF() { return m_ExtraFlags.HasFlag(PlayerExtraFlags.GrantedLevelsFromRaf); }
public void SetBeenGrantedLevelsFromRaF() { m_ExtraFlags |= PlayerExtraFlags.GrantedLevelsFromRaf; }
public bool HasLevelBoosted() { return m_ExtraFlags.HasFlag(PlayerExtraFlags.LevelBoosted); }
public void SetHasLevelBoosted() { m_ExtraFlags |= PlayerExtraFlags.LevelBoosted; }
public uint GetXP() { return m_activePlayerData.XP; }
public uint GetXPForNextLevel() { return m_activePlayerData.NextLevelXP; }
+1 -1
View File
@@ -310,7 +310,7 @@ namespace Game.Garrisons
return _plots.Values;
}
Plot GetPlot(uint garrPlotInstanceId)
public Plot GetPlot(uint garrPlotInstanceId)
{
return _plots.LookupByKey(garrPlotInstanceId);
}
+1 -1
View File
@@ -123,7 +123,7 @@ namespace Game
while (result.NextRow());
}
charResult.IsAlliedRacesCreationAllowed = GetAccountExpansion() >= Expansion.BattleForAzeroth;
charResult.IsAlliedRacesCreationAllowed = CanAccessAlliedRaces();
foreach (var requirement in Global.ObjectMgr.GetRaceUnlockRequirements())
{
+1 -1
View File
@@ -182,7 +182,7 @@ namespace Game
return GetForcedRankIfAny(factionTemplateEntry.Faction);
}
int GetParagonLevel(uint paragonFactionId)
public int GetParagonLevel(uint paragonFactionId)
{
return GetParagonLevel(CliDB.FactionStorage.LookupByKey(paragonFactionId));
}
+31 -15
View File
@@ -35,8 +35,8 @@ namespace Game.Scenarios
//ASSERT(_data);
foreach (var step in _data.Steps)
SetStepState(step.Value, ScenarioStepState.NotStarted);
foreach (var scenarioStep in _data.Steps.Values)
SetStepState(scenarioStep, ScenarioStepState.NotStarted);
ScenarioStepRecord firstStep = GetFirstStep();
if (firstStep != null)
@@ -80,16 +80,16 @@ namespace Game.Scenarios
return;
ScenarioStepRecord newStep = null;
foreach (var _step in _data.Steps.Values)
foreach (var scenarioStep in _data.Steps.Values)
{
if (_step.IsBonusObjective())
if (scenarioStep.IsBonusObjective())
continue;
if (GetStepState(_step) == ScenarioStepState.Done)
if (GetStepState(scenarioStep) == ScenarioStepState.Done)
continue;
if (newStep == null || _step.OrderIndex < newStep.OrderIndex)
newStep = _step;
if (newStep == null || scenarioStep.OrderIndex < newStep.OrderIndex)
newStep = scenarioStep;
}
SetStep(newStep);
@@ -129,12 +129,12 @@ namespace Game.Scenarios
bool IsComplete()
{
foreach (var step in _data.Steps.Values)
foreach (var scenarioStep in _data.Steps.Values)
{
if (step.IsBonusObjective())
if (scenarioStep.IsBonusObjective())
continue;
if (GetStepState(step) != ScenarioStepState.Done)
if (GetStepState(scenarioStep) != ScenarioStepState.Done)
return false;
}
@@ -278,6 +278,22 @@ namespace Game.Scenarios
return firstStep;
}
public ScenarioStepRecord GetLastStep()
{
// Do it like this because we don't know what order they're in inside the container.
ScenarioStepRecord lastStep = null;
foreach (var scenarioStep in _data.Steps.Values)
{
if (scenarioStep.IsBonusObjective())
continue;
if (lastStep == null || scenarioStep.OrderIndex > lastStep.OrderIndex)
lastStep = scenarioStep;
}
return lastStep;
}
public void SendScenarioState(Player player)
{
ScenarioState scenarioState = new();
@@ -288,16 +304,16 @@ namespace Game.Scenarios
List<BonusObjectiveData> GetBonusObjectivesData()
{
List<BonusObjectiveData> bonusObjectivesData = new();
foreach (var step in _data.Steps.Values)
foreach (var scenarioStep in _data.Steps.Values)
{
if (!step.IsBonusObjective())
if (!scenarioStep.IsBonusObjective())
continue;
if (Global.CriteriaMgr.GetCriteriaTree(step.CriteriaTreeId) != null)
if (Global.CriteriaMgr.GetCriteriaTree(scenarioStep.CriteriaTreeId) != null)
{
BonusObjectiveData bonusObjectiveData;
bonusObjectiveData.BonusObjectiveID = (int)step.Id;
bonusObjectiveData.ObjectiveComplete = GetStepState(step) == ScenarioStepState.Done;
bonusObjectiveData.BonusObjectiveID = (int)scenarioStep.Id;
bonusObjectiveData.ObjectiveComplete = GetStepState(scenarioStep) == ScenarioStepState.Done;
bonusObjectivesData.Add(bonusObjectiveData);
}
}
+5
View File
@@ -676,6 +676,11 @@ namespace Game
{
return _transactionCallbacks.AddCallback(callback);
}
public bool CanAccessAlliedRaces()
{
return GetAccountExpansion() >= Expansion.BattleForAzeroth;
}
void InitWarden(BigInteger k)
{