Skip to content

Commit

Permalink
Add static tooltip functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dairymoose committed Nov 30, 2023
1 parent 912cd46 commit bd2413f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
33 changes: 33 additions & 0 deletions DamageSimulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "PriorityActionList.h"
#include "Enemy.h"
#include <random>
#include <regex>

#define FLOATING_POINT_SMALL_NUMBER 1E-3f

Expand Down Expand Up @@ -46,6 +47,38 @@ class DamageSimulation
static int32_t totalDotDamageFromOneTick(int32_t oneTickDamage, float tickPeriod, float totalDuration) {
return DamageSimulation::Round(totalDuration*oneTickDamage/tickPeriod);
}
static int32_t getDamageForAbility(Ability *ability, PlayerCharacter *PC) {
float damage = ability->getDamage(PC);
damage *= PC->calculateGlobalDamageBonus();
return DamageSimulation::Round(damage);
}
static std::string regexReplaceTooltipDirectDamage(std::string tooltipText, Ability *ability, PlayerCharacter *PC) {
std::stringstream ssDmg;
bool avg = PC->getAlwaysUseAverageDamage();
PC->setAlwaysUseAverageDamage(true);
ssDmg<<DamageSimulation::getDamageForAbility(ability, PC);
PC->setAlwaysUseAverageDamage(avg);
return std::regex_replace(tooltipText, std::regex("<dmg>"), ssDmg.str());
}
static std::string regexReplaceTooltipDotDamage(std::string tooltipText, Ability *ability, PlayerCharacter *PC) {
std::stringstream ssDmg;
float duration = DamageSimulation::getDotDuration(ability, PC);
ssDmg<<DamageSimulation::totalDotDamageFromOneTick(
ability->getGrantedDebuff()->getOnDotTickDamage()(PC, PC, ability->getRank(), 1, duration),
ability->getGrantedDebuff()->getOnCalculateDotTickPeriod()(PC),
duration);
return std::regex_replace(tooltipText, std::regex("<dmg>"), ssDmg.str());
}
static std::string regexReplaceTooltipDotDuration(std::string tooltipText, Ability *ability, PlayerCharacter *PC) {
std::stringstream ssDuration;
float duration = DamageSimulation::getDotDuration(ability, PC);
ssDuration<<duration;
return std::regex_replace(tooltipText, std::regex("<time>"), ssDuration.str());
}
static int32_t getDotDuration(Ability *ability, PlayerCharacter *PC) {
float duration = ability->getGrantedDebuff()->getOnCalculateDuration()(PC, ability->getRank());
return duration;
}
std::vector<Enemy *>& getEnemyList();
GlobalAbilityList *getGlobalAbilityList() const;
void setGlobalAbilityList(GlobalAbilityList *value);
Expand Down
27 changes: 3 additions & 24 deletions GlobalAbilityList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,7 @@ GlobalAbilityList::GlobalAbilityList()
this->Rend->setGrantedDebuff(RendDebuff);
this->Rend->setTooltipText("Wounds the target causing them to bleed for <dmg> damage over <time> sec.");
this->Rend->setOnGetTooltip([](std::string tooltipText, float timestamp, PlayerCharacter *PC, Ability *ability){
std::stringstream ssDmg;
std::stringstream ssDuration;
float duration = ability->getGrantedDebuff()->getOnCalculateDuration()(PC, ability->getRank());
ssDuration<<duration;
ssDmg<<DamageSimulation::totalDotDamageFromOneTick(
ability->getGrantedDebuff()->getOnDotTickDamage()(PC, PC, ability->getRank(), 1, duration),
ability->getGrantedDebuff()->getOnCalculateDotTickPeriod()(PC),
duration);
std::string r = std::regex_replace(tooltipText, std::regex("<dmg>"), ssDmg.str());
return std::regex_replace(r, std::regex("<time>"), ssDuration.str());
return DamageSimulation::regexReplaceTooltipDotDuration(DamageSimulation::regexReplaceTooltipDotDamage(tooltipText, ability, PC), ability, PC);
});

this->BattleShout = new Ability("Battle Shout");
Expand Down Expand Up @@ -136,13 +127,7 @@ GlobalAbilityList::GlobalAbilityList()
this->Whirlwind->setAoeMaxTargets(4);
this->Whirlwind->setTooltipText("In a whirlwind of steel you attack up to 4 enemies within 8 yards, causing weapon damage to each enemy. (<dmg> damage)");
this->Whirlwind->setOnGetTooltip([](std::string tooltipText, float timestamp, PlayerCharacter *PC, Ability *ability){
std::stringstream ssDmg;
bool avg = PC->getAlwaysUseAverageDamage();
PC->setAlwaysUseAverageDamage(true);
ssDmg<<ability->getDamage(PC);
PC->setAlwaysUseAverageDamage(avg);
std::string r = std::regex_replace(tooltipText, std::regex("<dmg>"), ssDmg.str());
return r;
return DamageSimulation::regexReplaceTooltipDirectDamage(tooltipText, ability, PC);
});

this->MortalStrike = new Ability("Mortal Strike");
Expand All @@ -157,13 +142,7 @@ GlobalAbilityList::GlobalAbilityList()
this->MortalStrike->setResourceCost(30);
this->MortalStrike->setTooltipText("A vicious strike that deals <dmg> damage and wounds the target, reducing the effectiveness of any healing by 50% for 10 sec.");
this->MortalStrike->setOnGetTooltip([](std::string tooltipText, float timestamp, PlayerCharacter *PC, Ability *ability){
std::stringstream ssDmg;
bool avg = PC->getAlwaysUseAverageDamage();
PC->setAlwaysUseAverageDamage(true);
ssDmg<<ability->getDamage(PC);
PC->setAlwaysUseAverageDamage(avg);
std::string r = std::regex_replace(tooltipText, std::regex("<dmg>"), ssDmg.str());
return r;
return DamageSimulation::regexReplaceTooltipDirectDamage(tooltipText, ability, PC);
});

this->Slam = new Ability("Slam");
Expand Down
5 changes: 3 additions & 2 deletions PriorityAction.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "PriorityAction.h"
#include "PlayerCharacter.h"
#include "DamageSimulation.h"
#include "Ability.h"

Ability *PriorityAction::getAbility() const
{
Expand All @@ -25,8 +27,7 @@ void PriorityAction::execute(PlayerCharacter *PC, std::vector<Enemy *> &enemyLis
{
if (this->getAbility() != nullptr) {
this->getAbility()->triggerResourceCost(PC, timestamp);
float damage = this->getAbility()->getDamage(PC);
damage *= PC->calculateGlobalDamageBonus();
int32_t damage = DamageSimulation::getDamageForAbility(this->getAbility(), PC);
bool isCritical;
damage = PC->maybeApplyCritDamage(this->getAbility(), damage, isCritical);

Expand Down

0 comments on commit bd2413f

Please sign in to comment.