void HandleArtifactAddPower(ArtifactAddPower artifactAddPower) { if (!_player.GetGameObjectIfCanInteractWith(artifactAddPower.ForgeGUID, GameObjectTypes.ArtifactForge)) { return; } Item artifact = _player.GetItemByGuid(artifactAddPower.ArtifactGUID); if (!artifact) { return; } ulong xpCost = 0; GtArtifactLevelXPRecord cost = CliDB.ArtifactLevelXPGameTable.GetRow(artifact.GetTotalPurchasedArtifactPowers() + 1); if (cost != null) { xpCost = (ulong)(artifact.GetModifier(ItemModifier.ArtifactTier) == 1 ? cost.XP2 : cost.XP); } if (xpCost > artifact.GetUInt64Value(ItemFields.ArtifactXp)) { return; } if (artifactAddPower.PowerChoices.Empty()) { return; } ItemDynamicFieldArtifactPowers artifactPower = artifact.GetArtifactPower(artifactAddPower.PowerChoices[0].ArtifactPowerID); if (artifactPower == null) { return; } ArtifactPowerRecord artifactPowerEntry = CliDB.ArtifactPowerStorage.LookupByKey(artifactPower.ArtifactPowerId); if (artifactPowerEntry == null) { return; } if (artifactAddPower.PowerChoices[0].Rank != artifactPower.PurchasedRank + 1 || artifactAddPower.PowerChoices[0].Rank > artifactPowerEntry.MaxRank) { return; } var artifactPowerLinks = Global.DB2Mgr.GetArtifactPowerLinks(artifactPower.ArtifactPowerId); if (artifactPowerLinks != null) { bool hasAnyLink = false; foreach (uint artifactPowerLinkId in artifactPowerLinks) { ArtifactPowerRecord artifactPowerLink = CliDB.ArtifactPowerStorage.LookupByKey(artifactPowerLinkId); if (artifactPowerLink == null) { continue; } ItemDynamicFieldArtifactPowers artifactPowerLinkLearned = artifact.GetArtifactPower(artifactPowerLinkId); if (artifactPowerLinkLearned == null) { continue; } if (artifactPowerLinkLearned.PurchasedRank >= artifactPowerLink.MaxRank) { hasAnyLink = true; break; } } if (!hasAnyLink) { return; } } ArtifactPowerRankRecord artifactPowerRank = Global.DB2Mgr.GetArtifactPowerRank(artifactPower.ArtifactPowerId, (byte)(artifactPower.CurrentRankWithBonus + 1 - 1)); // need data for next rank, but -1 because of how db2 data is structured if (artifactPowerRank == null) { return; } ItemDynamicFieldArtifactPowers newPower = artifactPower; ++newPower.PurchasedRank; ++newPower.CurrentRankWithBonus; artifact.SetArtifactPower(newPower); if (artifact.IsEquipped()) { _player.ApplyArtifactPowerRank(artifact, artifactPowerRank, true); foreach (ItemDynamicFieldArtifactPowers power in artifact.GetArtifactPowers()) { ArtifactPowerRecord scaledArtifactPowerEntry = CliDB.ArtifactPowerStorage.LookupByKey(power.ArtifactPowerId); if (!scaledArtifactPowerEntry.Flags.HasAnyFlag(ArtifactPowerFlag.ScalesWithNumPowers)) { continue; } ArtifactPowerRankRecord scaledArtifactPowerRank = Global.DB2Mgr.GetArtifactPowerRank(scaledArtifactPowerEntry.Id, 0); if (scaledArtifactPowerRank == null) { continue; } ItemDynamicFieldArtifactPowers newScaledPower = power; ++newScaledPower.CurrentRankWithBonus; artifact.SetArtifactPower(newScaledPower); _player.ApplyArtifactPowerRank(artifact, scaledArtifactPowerRank, false); _player.ApplyArtifactPowerRank(artifact, scaledArtifactPowerRank, true); } } artifact.SetUInt64Value(ItemFields.ArtifactXp, artifact.GetUInt64Value(ItemFields.ArtifactXp) - xpCost); artifact.SetState(ItemUpdateState.Changed, _player); }
void HandleConfirmArtifactRespec(ConfirmArtifactRespec confirmArtifactRespec) { if (!_player.GetNPCIfCanInteractWith(confirmArtifactRespec.NpcGUID, NPCFlags.ArtifactPowerRespec)) { return; } Item artifact = _player.GetItemByGuid(confirmArtifactRespec.ArtifactGUID); if (!artifact) { return; } ulong xpCost = 0; GtArtifactLevelXPRecord cost = CliDB.ArtifactLevelXPGameTable.GetRow(artifact.GetTotalPurchasedArtifactPowers() + 1); if (cost != null) { xpCost = (ulong)(artifact.GetModifier(ItemModifier.ArtifactTier) == 1 ? cost.XP2 : cost.XP); } if (xpCost > artifact.GetUInt64Value(ItemFields.ArtifactXp)) { return; } ulong newAmount = artifact.GetUInt64Value(ItemFields.ArtifactXp) - xpCost; for (uint i = 0; i <= artifact.GetTotalPurchasedArtifactPowers(); ++i) { GtArtifactLevelXPRecord cost1 = CliDB.ArtifactLevelXPGameTable.GetRow(i); if (cost1 != null) { newAmount += (ulong)(artifact.GetModifier(ItemModifier.ArtifactTier) == 1 ? cost1.XP2 : cost1.XP); } } foreach (ItemDynamicFieldArtifactPowers artifactPower in artifact.GetArtifactPowers()) { byte oldPurchasedRank = artifactPower.PurchasedRank; if (oldPurchasedRank == 0) { continue; } ItemDynamicFieldArtifactPowers newPower = artifactPower; newPower.PurchasedRank -= oldPurchasedRank; newPower.CurrentRankWithBonus -= oldPurchasedRank; artifact.SetArtifactPower(newPower); if (artifact.IsEquipped()) { ArtifactPowerRankRecord artifactPowerRank = Global.DB2Mgr.GetArtifactPowerRank(artifactPower.ArtifactPowerId, 0); if (artifactPowerRank != null) { _player.ApplyArtifactPowerRank(artifact, artifactPowerRank, false); } } } foreach (ItemDynamicFieldArtifactPowers power in artifact.GetArtifactPowers()) { ArtifactPowerRecord scaledArtifactPowerEntry = CliDB.ArtifactPowerStorage.LookupByKey(power.ArtifactPowerId); if (!scaledArtifactPowerEntry.Flags.HasAnyFlag(ArtifactPowerFlag.ScalesWithNumPowers)) { continue; } ArtifactPowerRankRecord scaledArtifactPowerRank = Global.DB2Mgr.GetArtifactPowerRank(scaledArtifactPowerEntry.Id, 0); if (scaledArtifactPowerRank == null) { continue; } ItemDynamicFieldArtifactPowers newScaledPower = power; newScaledPower.CurrentRankWithBonus = 0; artifact.SetArtifactPower(newScaledPower); _player.ApplyArtifactPowerRank(artifact, scaledArtifactPowerRank, false); } artifact.SetUInt64Value(ItemFields.ArtifactXp, newAmount); artifact.SetState(ItemUpdateState.Changed, _player); }