From f0bb90b547d6a5e21e8b2df17923979b0d019358 Mon Sep 17 00:00:00 2001 From: gsemaj Date: Sat, 30 Jul 2022 21:43:28 -0700 Subject: [PATCH] Move some stuff from playerTick to player combat step --- src/Buffs.cpp | 10 +++-- src/Buffs.hpp | 9 ++-- src/Combat.cpp | 84 ++++++++++++++++++++--------------- src/servers/CNShardServer.hpp | 2 +- 4 files changed, 62 insertions(+), 43 deletions(-) diff --git a/src/Buffs.cpp b/src/Buffs.cpp index 01f6a07..33760f6 100644 --- a/src/Buffs.cpp +++ b/src/Buffs.cpp @@ -9,7 +9,7 @@ void Buff::tick(time_t currTime) { auto it = stacks.begin(); while(it != stacks.end()) { BuffStack& stack = *it; - if(onTick) onTick(self, this, currTime); + //if(onTick) onTick(self, this, currTime); if(stack.durationTicks == 0) { BuffStack deadStack = stack; @@ -22,6 +22,10 @@ void Buff::tick(time_t currTime) { } } +void Buff::combatTick(time_t currTime) { + if(onCombatTick) onCombatTick(self, this, currTime); +} + void Buff::clear() { while(!stacks.empty()) { BuffStack stack = stacks.back(); @@ -84,9 +88,9 @@ bool Buff::isStale() { } /* This will practically never do anything important, but it's here just in case */ -void Buff::updateCallbacks(BuffCallback fOnUpdate, BuffCallback fonTick) { +void Buff::updateCallbacks(BuffCallback fOnUpdate, BuffCallback fOnCombatTick) { if(!onUpdate) onUpdate = fOnUpdate; - if(!onTick) onTick = fonTick; + if(!onCombatTick) onCombatTick = fOnCombatTick; } #pragma region Handlers diff --git a/src/Buffs.hpp b/src/Buffs.hpp index bc7f1f5..5f9bcbc 100644 --- a/src/Buffs.hpp +++ b/src/Buffs.hpp @@ -48,10 +48,11 @@ public: int id; /* called just after a stack is added or removed */ BuffCallback onUpdate; - /* called when the buff is ticked */ - BuffCallback onTick; + /* called when the buff is combat-ticked */ + BuffCallback onCombatTick; void tick(time_t); + void combatTick(time_t); void clear(); void addStack(BuffStack* stack); @@ -76,8 +77,8 @@ public: void updateCallbacks(BuffCallback fOnUpdate, BuffCallback fonTick); - Buff(int iid, EntityRef pSelf, BuffCallback fOnUpdate, BuffCallback fOnTick, BuffStack* firstStack) - : self(pSelf), id(iid), onUpdate(fOnUpdate), onTick(fOnTick) { + Buff(int iid, EntityRef pSelf, BuffCallback fOnUpdate, BuffCallback fOnCombatTick, BuffStack* firstStack) + : self(pSelf), id(iid), onUpdate(fOnUpdate), onCombatTick(fOnCombatTick) { addStack(firstStack); } }; diff --git a/src/Combat.cpp b/src/Combat.cpp index 4f7ee96..ef5075e 100644 --- a/src/Combat.cpp +++ b/src/Combat.cpp @@ -116,7 +116,37 @@ EntityRef Player::getRef() { } void Player::step(time_t currTime) { - // no-op + CNSocket* sock = getRef().sock; + + // nanos + for (int i = 0; i < 3; i++) { + if (activeNano != 0 && equippedNanos[i] == activeNano) { // tick active nano + sNano& nano = Nanos[activeNano]; + int drainRate = 0; + + if (Abilities::SkillTable.find(nano.iSkillID) != Abilities::SkillTable.end()) { + // nano has skill data + SkillData* skill = &Abilities::SkillTable[nano.iSkillID]; + int boost = Nanos::getNanoBoost(this); + if (skill->drainType == SkillDrainType::PASSIVE) + drainRate = skill->batteryUse[boost * 3]; + } + + nano.iStamina -= 1 + drainRate / 5; + if (nano.iStamina <= 0) + Nanos::summonNano(sock, -1, true); // unsummon nano silently + + } else if (Nanos[equippedNanos[i]].iStamina < 150) { // tick resting nano + sNano& nano = Nanos[equippedNanos[i]]; + if (nano.iStamina < 150) + nano.iStamina += 1; + } + } + + // buffs + for(auto buffEntry : buffs) { + buffEntry.second->combatTick(currTime); + } } #pragma endregion @@ -794,6 +824,7 @@ static void projectileHit(CNSocket* sock, CNPacketData* data) { static void playerTick(CNServer *serv, time_t currTime) { static time_t lastHealTime = 0; + static time_t lastCombatTIme = 0; for (auto& pair : PlayerManager::players) { CNSocket *sock = pair.first; @@ -819,39 +850,21 @@ static void playerTick(CNServer *serv, time_t currTime) { plr->healCooldown -= 4000; } + // combat tick + if(currTime - lastCombatTIme >= 2000) { + plr->step(currTime); + transmit = true; + } + // nanos - for (int i = 0; i < 3; i++) { - if (plr->activeNano != 0 && plr->equippedNanos[i] == plr->activeNano) { // tick active nano - sNano& nano = plr->Nanos[plr->activeNano]; - int drainRate = 0; - - if (Abilities::SkillTable.find(nano.iSkillID) != Abilities::SkillTable.end()) { - // nano has skill data - SkillData* skill = &Abilities::SkillTable[nano.iSkillID]; - int boost = Nanos::getNanoBoost(plr); - std::cout << "[SKILL] id " << nano.iSkillID << ", type " << skill->skillType << ", target " << (int)skill->targetType << std::endl; - - if (skill->drainType == SkillDrainType::PASSIVE) { - // apply passive buff - drainRate = skill->batteryUse[boost * 3]; - Nanos::applyNanoBuff(skill, plr); - } - } - - nano.iStamina -= 1 + drainRate / 5; - - if (nano.iStamina <= 0) - Nanos::summonNano(sock, -1, true); // unsummon nano silently - - transmit = true; - } else if (plr->Nanos[plr->equippedNanos[i]].iStamina < 150) { // tick resting nano - sNano& nano = plr->Nanos[plr->equippedNanos[i]]; - nano.iStamina += 1; - - if (nano.iStamina > 150) - nano.iStamina = 150; - - transmit = true; + if (plr->activeNano != 0) { // tick active nano + sNano* nano = plr->getActiveNano(); + 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 } } @@ -879,7 +892,6 @@ static void playerTick(CNServer *serv, time_t currTime) { } else it++; } - // if (transmit) { INITSTRUCT(sP_FE2CL_REP_PC_TICK, pkt); @@ -895,9 +907,11 @@ static void playerTick(CNServer *serv, time_t currTime) { } } - // if this was a heal tick, update the counter outside of the loop + // if this was a heal/combat tick, update the counters outside of the loop if (currTime - lastHealTime >= 4000) lastHealTime = currTime; + if(currTime - lastCombatTIme >= 2000) + lastCombatTIme = currTime; } void Combat::init() { diff --git a/src/servers/CNShardServer.hpp b/src/servers/CNShardServer.hpp index 8ab7360..c585428 100644 --- a/src/servers/CNShardServer.hpp +++ b/src/servers/CNShardServer.hpp @@ -7,7 +7,7 @@ #define REGISTER_SHARD_PACKET(pactype, handlr) CNShardServer::ShardPackets[pactype] = handlr; #define REGISTER_SHARD_TIMER(handlr, delta) CNShardServer::Timers.push_back(TimerEvent(handlr, delta)); -#define MS_PER_PLAYER_TICK 2000 +#define MS_PER_PLAYER_TICK 500 class CNShardServer : public CNServer { private: