canary
canary copied to clipboard
fix: stats after transcendance effect
close: #2595
In spell remove this... ( --)
void Player::triggerTranscendance() {
if (wheel()->getOnThinkTimer(WheelOnThink_t::AVATAR_FORGE) > OTSYS_TIME()) {
return;
}
auto item = getInventoryItem(CONST_SLOT_LEGS);
if (item == nullptr) {
return;
}
double_t chance = item->getTranscendenceChance();
double_t randomChance = uniform_random(0, 10000) / 100.;
if (getZoneType() != ZONE_PROTECTION && checkLastAggressiveActionWithin(2000) && ((OTSYS_TIME() / 1000) % 2) == 0 && chance > 0 && randomChance < chance) {
int64_t duration = g_configManager().getNumber(TRANSCENDANCE_AVATAR_DURATION, __FUNCTION__);
auto outfitCondition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_OUTFIT, duration, 0)->static_self_cast<ConditionOutfit>();
Outfit_t outfit;
outfit.lookType = getVocation()->getAvatarLookType();
outfitCondition->setOutfit(outfit);
addCondition(outfitCondition);
wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR_FORGE, OTSYS_TIME() + duration);
g_game().addMagicEffect(getPosition(), CONST_ME_AVATAR_APPEAR);
sendSkills();
sendStats();
sendBasicData();
sendTextMessage(MESSAGE_ATTENTION, "Transcendance was triggered.");
// Send player data after transcendance timer expire
const auto &task = createPlayerTask(
std::max<uint32_t>(SCHEDULER_MINTICKS, duration),
[playerId = getID()] {
auto player = g_game().getPlayerByID(playerId);
if (player) {
player->sendSkills();
player->sendStats();
player->sendBasicData();
}
}, "Player::updateStatusAfterTranscendance"
);
g_dispatcher().scheduleEvent(task);
wheel()->sendGiftOfLifeCooldown();
g_game().reloadCreature(getPlayer());
}
}
This refactoring of the triggerTranscendance() function significantly improves the modularity and clarity of the player's transformation process. By explicitly scheduling future updates and decoupling them from the immediate logic, the code becomes not only more readable but also more flexible for future expansions or modifications.
Additionally, the revised approach simplifies the complexity of the include file by eliminating unnecessary pointers and variables when the system is on cooldown, which enhances performance. By checking the cooldown status at the beginning and exiting early if it's active, the system avoids creating and managing resources that would not be used. This efficient handling significantly reduces the overhead during cooldown periods, leading to better overall performance.
Please test to ensure everything is functioning as expected. Note that my review was solely based on the code, so there may be aspects that require further verification.
updated, thanks @dudantas