[refactor] Active power handling

This commit is contained in:
gsemaj
2022-11-27 17:36:47 -05:00
committed by gsemaj
parent 4ece1bb89b
commit 82bee2051a
17 changed files with 330 additions and 247 deletions

View File

@@ -21,6 +21,9 @@ std::map<int32_t, std::map<int8_t, Bullet>> Combat::Bullets;
#pragma region Player
bool Player::addBuff(int buffId, BuffCallback<int, BuffStack*> onUpdate, BuffCallback<time_t> onTick, BuffStack* stack) {
if(!isAlive())
return false;
EntityRef self = PlayerManager::getSockFromID(iID);
if(!hasBuff(buffId)) {
@@ -51,6 +54,7 @@ void Player::removeBuff(int buffId) {
void Player::removeBuff(int buffId, int buffClass) {
if(hasBuff(buffId)) {
buffs[buffId]->clear((BuffClass)buffClass);
// buff might not be stale since another buff class might remain
if(buffs[buffId]->isStale()) {
delete buffs[buffId];
buffs.erase(buffId);
@@ -58,6 +62,17 @@ void Player::removeBuff(int buffId, int buffClass) {
}
}
void Player::clearBuffs(bool force) {
for(auto buff : buffs) {
if(!force) {
removeBuff(buff.first);
} else {
delete buff.second;
}
}
buffs.clear();
}
bool Player::hasBuff(int buffId) {
auto buff = buffs.find(buffId);
return buff != buffs.end() && !buff->second->isStale();
@@ -173,6 +188,8 @@ void CombatNPC::removeBuff(int buffId) { /* stubbed */ }
void CombatNPC::removeBuff(int buffId, int buffClass) { /* stubbed */ }
void CombatNPC::clearBuffs(bool force) { /* stubbed */ }
bool CombatNPC::hasBuff(int buffId) { /* stubbed */
return false;
}
@@ -874,9 +891,12 @@ static void playerTick(CNServer *serv, time_t currTime) {
if (Abilities::SkillTable.find(nano->iSkillID) != Abilities::SkillTable.end()) {
// nano has skill data
SkillData* skill = &Abilities::SkillTable[nano->iSkillID];
if (skill->drainType == SkillDrainType::PASSIVE)
Nanos::applyNanoBuff(skill, plr);
// ^ composite condition calculation is separate from combat for responsiveness
if (skill->drainType == SkillDrainType::PASSIVE) {
ICombatant* src = dynamic_cast<ICombatant*>(plr);
int32_t targets[] = { plr->iID };
std::vector<ICombatant*> affectedCombatants = Abilities::matchTargets(src, skill, 1, targets);
Abilities::useNanoSkill(sock, skill, *nano, affectedCombatants);
}
}
}