refactor(Scripts/Commands): Update cs_quest to the new model (#9267)

This commit is contained in:
Skjalf
2021-11-24 01:21:16 -03:00
committed by GitHub
parent 91552e240e
commit 2187470df7
12 changed files with 716 additions and 204 deletions

View File

@@ -116,3 +116,28 @@ ChatCommandResult Acore::Impl::ChatCommands::ArgInfo<SpellInfo const*>::TryConsu
return std::nullopt;
}
struct QuestVisitor
{
using value_type = Quest const*;
value_type operator()(Hyperlink<quest> quest_template) const { return quest_template->Quest; };
value_type operator()(uint32 questId) const { return sObjectMgr->GetQuestTemplate(questId); };
};
ChatCommandResult Acore::Impl::ChatCommands::ArgInfo<Quest const*>::TryConsume(Quest const*& data, ChatHandler const* handler, std::string_view args)
{
Variant<Hyperlink<quest>, uint32> val;
ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
if (!result || (data = val.visit(QuestVisitor())))
{
return result;
}
if (uint32* id = std::get_if<uint32>(&val))
{
return FormatAcoreString(handler, LANG_CMDPARSER_QUEST_NO_EXIST, *id);
}
return std::nullopt;
}

View File

@@ -319,6 +319,12 @@ namespace Acore::Impl::ChatCommands
static ChatCommandResult TryConsume(SpellInfo const*&, ChatHandler const*, std::string_view);
};
// Quest const* from quest id or link
template <>
struct AC_GAME_API ArgInfo<Quest const*>
{
static ChatCommandResult TryConsume(Quest const*&, ChatHandler const*, std::string_view);
};
}
#endif

View File

@@ -424,8 +424,9 @@ void PlayerMenu::SendQuestGiverQuestDetails(Quest const* quest, ObjectGuid npcGU
data << uint32(0);
}
data << uint32(quest->GetRewOrReqMoney(_session->GetPlayer()));
data << uint32(quest->XPValue(_session->GetPlayer()) * _session->GetPlayer()->GetQuestRate());
uint8 playerLevel = _session->GetPlayer() ? _session->GetPlayer()->getLevel() : 0;
data << uint32(quest->GetRewOrReqMoney(playerLevel));
data << uint32(quest->XPValue(playerLevel) * _session->GetPlayer()->GetQuestRate());
}
// rewarded honor points. Multiply with 10 to satisfy client
@@ -506,7 +507,7 @@ void PlayerMenu::SendQuestQueryResponse(Quest const* quest) const
if (quest->HasFlag(QUEST_FLAGS_HIDDEN_REWARDS))
data << uint32(0); // Hide money rewarded
else
data << uint32(quest->GetRewOrReqMoney(_session->GetPlayer())); // reward money (below max lvl)
data << uint32(quest->GetRewOrReqMoney(_session->GetPlayer() ? _session->GetPlayer()->getLevel() : 0)); // reward money (below max lvl)
data << uint32(quest->GetRewMoneyMaxLevel()); // used in XP calculation at client
data << uint32(quest->GetRewSpell()); // reward spell, this spell will display (icon) (cast if RewSpellCast == 0)
@@ -650,8 +651,10 @@ void PlayerMenu::SendQuestGiverOfferReward(Quest const* quest, ObjectGuid npcGUI
data << uint32(0);
}
data << uint32(quest->GetRewOrReqMoney(_session->GetPlayer()));
data << uint32(quest->XPValue(_session->GetPlayer()) * _session->GetPlayer()->GetQuestRate());
uint8 playerLevel = _session->GetPlayer() ? _session->GetPlayer()->getLevel() : 0;
data << uint32(quest->GetRewOrReqMoney(playerLevel));
data << uint32(quest->XPValue(playerLevel) * _session->GetPlayer()->GetQuestRate());
// rewarded honor points. Multiply with 10 to satisfy client
data << uint32(10 * quest->CalculateHonorGain(_session->GetPlayer()->GetQuestLevel(quest)));

View File

@@ -736,7 +736,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
bool rewarded = IsQuestRewarded(quest_id) && !quest->IsDFQuest();
// Not give XP in case already completed once repeatable quest
uint32 XP = rewarded ? 0 : uint32(quest->XPValue(this) * GetQuestRate());
uint32 XP = rewarded ? 0 : uint32(quest->XPValue(getLevel()) * GetQuestRate());
// handle SPELL_AURA_MOD_XP_QUEST_PCT auras
Unit::AuraEffectList const& ModXPPctAuras = GetAuraEffectsByType(SPELL_AURA_MOD_XP_QUEST_PCT);
@@ -754,7 +754,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
}
// Give player extra money if GetRewOrReqMoney > 0 and get ReqMoney if negative
if (int32 rewOrReqMoney = quest->GetRewOrReqMoney(this))
if (int32 rewOrReqMoney = quest->GetRewOrReqMoney(getLevel()))
{
moneyRew += rewOrReqMoney;
}
@@ -2292,12 +2292,12 @@ void Player::SendQuestReward(Quest const* quest, uint32 XP)
if (getLevel() < sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
{
data << uint32(XP);
data << uint32(quest->GetRewOrReqMoney(this));
data << uint32(quest->GetRewOrReqMoney(getLevel()));
}
else
{
data << uint32(0);
data << uint32(quest->GetRewOrReqMoney(this) + quest->GetRewMoneyMaxLevel());
data << uint32(quest->GetRewOrReqMoney(getLevel()) + quest->GetRewMoneyMaxLevel());
}
data << uint32(10 * quest->CalculateHonorGain(GetQuestLevel(quest)));

View File

@@ -204,9 +204,10 @@ void WorldSession::HandleLfgPlayerLockInfoRequestOpcode(WorldPacket& /*recvData*
if (quest)
{
uint8 playerLevel = GetPlayer() ? GetPlayer()->getLevel() : 0;
data << uint8(done);
data << uint32(quest->GetRewOrReqMoney(GetPlayer()));
data << uint32(quest->XPValue(GetPlayer()));
data << uint32(quest->GetRewOrReqMoney(playerLevel));
data << uint32(quest->XPValue(playerLevel));
data << uint32(0);
data << uint32(0);
data << uint8(quest->GetRewItemsCount());
@@ -491,13 +492,15 @@ void WorldSession::SendLfgPlayerReward(lfg::LfgPlayerRewardData const& rewardDat
uint8 itemNum = rewardData.quest->GetRewItemsCount();
uint8 playerLevel = GetPlayer() ? GetPlayer()->getLevel() : 0;
WorldPacket data(SMSG_LFG_PLAYER_REWARD, 4 + 4 + 1 + 4 + 4 + 4 + 4 + 4 + 1 + itemNum * (4 + 4 + 4));
data << uint32(rewardData.rdungeonEntry); // Random Dungeon Finished
data << uint32(rewardData.sdungeonEntry); // Dungeon Finished
data << uint8(rewardData.done);
data << uint32(1);
data << uint32(rewardData.quest->GetRewOrReqMoney(GetPlayer()));
data << uint32(rewardData.quest->XPValue(GetPlayer()));
data << uint32(rewardData.quest->GetRewOrReqMoney(playerLevel));
data << uint32(rewardData.quest->XPValue(playerLevel));
data << uint32(0);
data << uint32(0);
data << uint8(itemNum);

View File

@@ -1114,7 +1114,8 @@ enum AcoreStrings
LANG_CMDPARSER_ITEM_NO_EXIST = 1513,
LANG_CMDPARSER_SPELL_NO_EXIST = 1514,
LANG_CMDPARSER_EXACT_SEQ_MISMATCH = 1515,
// FREE IDS 1516-1499
LANG_CMDPARSER_QUEST_NO_EXIST = 1516,
// FREE IDS 1517-1499
// Ticket Strings 2000-2030
LANG_COMMAND_TICKETNEW = 2000,
@@ -1225,7 +1226,11 @@ enum AcoreStrings
LANG_COMMAND_CACHE_REFRESH = 5065,
LANG_COMMAND_CACHE_NOT_FOUND = 5066,
// Room for more strings 5063-9999
LANG_COMMAND_QUEST_ADD = 5067,
LANG_COMMAND_QUEST_NOT_FOUND_IN_LOG = 5068,
LANG_COMMAND_QUEST_NOT_COMPLETE = 5069,
// Room for more strings 5070-9999
// Level requirement notifications
LANG_SAY_REQ = 6604,

View File

@@ -184,38 +184,47 @@ void Quest::LoadQuestTemplateAddon(Field* fields)
Flags |= QUEST_FLAGS_AUTO_ACCEPT;
}
uint32 Quest::XPValue(Player* player) const
uint32 Quest::XPValue(uint8 playerLevel) const
{
if (player)
int32 quest_level = (Level == -1 ? playerLevel : Level);
const QuestXPEntry* xpentry = sQuestXPStore.LookupEntry(quest_level);
if (!xpentry)
{
int32 quest_level = (Level == -1 ? player->getLevel() : Level);
const QuestXPEntry* xpentry = sQuestXPStore.LookupEntry(quest_level);
if (!xpentry)
return 0;
int32 diffFactor = 2 * (quest_level - player->getLevel()) + 20;
if (diffFactor < 1)
diffFactor = 1;
else if (diffFactor > 10)
diffFactor = 10;
uint32 xp = diffFactor * xpentry->Exp[RewardXPDifficulty] / 10;
if (xp <= 100)
xp = 5 * ((xp + 2) / 5);
else if (xp <= 500)
xp = 10 * ((xp + 5) / 10);
else if (xp <= 1000)
xp = 25 * ((xp + 12) / 25);
else
xp = 50 * ((xp + 25) / 50);
return xp;
return 0;
}
return 0;
int32 diffFactor = 2 * (quest_level - playerLevel) + 20;
if (diffFactor < 1)
{
diffFactor = 1;
}
else if (diffFactor > 10)
{
diffFactor = 10;
}
uint32 xp = diffFactor * xpentry->Exp[RewardXPDifficulty] / 10;
if (xp <= 100)
{
xp = 5 * ((xp + 2) / 5);
}
else if (xp <= 500)
{
xp = 10 * ((xp + 5) / 10);
}
else if (xp <= 1000)
{
xp = 25 * ((xp + 12) / 25);
}
else
{
xp = 50 * ((xp + 25) / 50);
}
return xp;
}
int32 Quest::GetRewOrReqMoney(Player* player /*= nullptr*/) const
int32 Quest::GetRewOrReqMoney(uint8 playerLevel) const
{
int32 rewardedMoney = RewardMoney;
if (rewardedMoney < 0)
@@ -223,9 +232,9 @@ int32 Quest::GetRewOrReqMoney(Player* player /*= nullptr*/) const
return rewardedMoney;
}
if (player && RewardMoneyDifficulty)
if (playerLevel && RewardMoneyDifficulty)
{
if (uint32 questRewardedMoney = sObjectMgr->GetQuestMoneyReward(player->getLevel(), RewardMoneyDifficulty))
if (uint32 questRewardedMoney = sObjectMgr->GetQuestMoneyReward(playerLevel, RewardMoneyDifficulty))
{
rewardedMoney = questRewardedMoney;
}

View File

@@ -211,7 +211,7 @@ public:
void LoadQuestOfferReward(Field* fields);
void LoadQuestTemplateAddon(Field* fields);
uint32 XPValue(Player* player) const;
uint32 XPValue(uint8 playerLevel = 0) const;
[[nodiscard]] bool HasFlag(uint32 flag) const { return (Flags & flag) != 0; }
void SetFlag(uint32 flag) { Flags |= flag; }
@@ -260,7 +260,7 @@ public:
[[nodiscard]] std::string const& GetRequestItemsText() const { return RequestItemsText; }
[[nodiscard]] std::string const& GetAreaDescription() const { return AreaDescription; }
[[nodiscard]] std::string const& GetCompletedText() const { return CompletedText; }
[[nodiscard]] int32 GetRewOrReqMoney(Player* player = nullptr) const;
[[nodiscard]] int32 GetRewOrReqMoney(uint8 playerLevel = 0) const;
[[nodiscard]] uint32 GetRewHonorAddition() const { return RewardHonor; }
[[nodiscard]] float GetRewHonorMultiplier() const { return RewardKillHonor; }
[[nodiscard]] uint32 GetRewMoneyMaxLevel() const; // use in XP calculation at client