mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 21:40:05 +00:00
Move some stuff from playerTick to player combat step
This commit is contained in:
parent
29024e9351
commit
457c320d48
@ -9,7 +9,7 @@ void Buff::tick(time_t currTime) {
|
|||||||
auto it = stacks.begin();
|
auto it = stacks.begin();
|
||||||
while(it != stacks.end()) {
|
while(it != stacks.end()) {
|
||||||
BuffStack& stack = *it;
|
BuffStack& stack = *it;
|
||||||
if(onTick) onTick(self, this, currTime);
|
//if(onTick) onTick(self, this, currTime);
|
||||||
|
|
||||||
if(stack.durationTicks == 0) {
|
if(stack.durationTicks == 0) {
|
||||||
BuffStack deadStack = stack;
|
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() {
|
void Buff::clear() {
|
||||||
while(!stacks.empty()) {
|
while(!stacks.empty()) {
|
||||||
BuffStack stack = stacks.back();
|
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 */
|
/* This will practically never do anything important, but it's here just in case */
|
||||||
void Buff::updateCallbacks(BuffCallback<int, BuffStack*> fOnUpdate, BuffCallback<time_t> fonTick) {
|
void Buff::updateCallbacks(BuffCallback<int, BuffStack*> fOnUpdate, BuffCallback<time_t> fOnCombatTick) {
|
||||||
if(!onUpdate) onUpdate = fOnUpdate;
|
if(!onUpdate) onUpdate = fOnUpdate;
|
||||||
if(!onTick) onTick = fonTick;
|
if(!onCombatTick) onCombatTick = fOnCombatTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma region Handlers
|
#pragma region Handlers
|
||||||
|
@ -48,10 +48,11 @@ public:
|
|||||||
int id;
|
int id;
|
||||||
/* called just after a stack is added or removed */
|
/* called just after a stack is added or removed */
|
||||||
BuffCallback<int, BuffStack*> onUpdate;
|
BuffCallback<int, BuffStack*> onUpdate;
|
||||||
/* called when the buff is ticked */
|
/* called when the buff is combat-ticked */
|
||||||
BuffCallback<time_t> onTick;
|
BuffCallback<time_t> onCombatTick;
|
||||||
|
|
||||||
void tick(time_t);
|
void tick(time_t);
|
||||||
|
void combatTick(time_t);
|
||||||
void clear();
|
void clear();
|
||||||
void addStack(BuffStack* stack);
|
void addStack(BuffStack* stack);
|
||||||
|
|
||||||
@ -76,8 +77,8 @@ public:
|
|||||||
|
|
||||||
void updateCallbacks(BuffCallback<int, BuffStack*> fOnUpdate, BuffCallback<time_t> fonTick);
|
void updateCallbacks(BuffCallback<int, BuffStack*> fOnUpdate, BuffCallback<time_t> fonTick);
|
||||||
|
|
||||||
Buff(int iid, EntityRef pSelf, BuffCallback<int, BuffStack*> fOnUpdate, BuffCallback<time_t> fOnTick, BuffStack* firstStack)
|
Buff(int iid, EntityRef pSelf, BuffCallback<int, BuffStack*> fOnUpdate, BuffCallback<time_t> fOnCombatTick, BuffStack* firstStack)
|
||||||
: self(pSelf), id(iid), onUpdate(fOnUpdate), onTick(fOnTick) {
|
: self(pSelf), id(iid), onUpdate(fOnUpdate), onCombatTick(fOnCombatTick) {
|
||||||
addStack(firstStack);
|
addStack(firstStack);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -116,7 +116,37 @@ EntityRef Player::getRef() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Player::step(time_t currTime) {
|
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
|
#pragma endregion
|
||||||
|
|
||||||
@ -765,6 +795,7 @@ static void projectileHit(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
static void playerTick(CNServer *serv, time_t currTime) {
|
static void playerTick(CNServer *serv, time_t currTime) {
|
||||||
static time_t lastHealTime = 0;
|
static time_t lastHealTime = 0;
|
||||||
|
static time_t lastCombatTIme = 0;
|
||||||
|
|
||||||
for (auto& pair : PlayerManager::players) {
|
for (auto& pair : PlayerManager::players) {
|
||||||
CNSocket *sock = pair.first;
|
CNSocket *sock = pair.first;
|
||||||
@ -790,39 +821,21 @@ static void playerTick(CNServer *serv, time_t currTime) {
|
|||||||
plr->healCooldown -= 4000;
|
plr->healCooldown -= 4000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// combat tick
|
||||||
|
if(currTime - lastCombatTIme >= 2000) {
|
||||||
|
plr->step(currTime);
|
||||||
|
transmit = true;
|
||||||
|
}
|
||||||
|
|
||||||
// nanos
|
// nanos
|
||||||
for (int i = 0; i < 3; i++) {
|
if (plr->activeNano != 0) { // tick active nano
|
||||||
if (plr->activeNano != 0 && plr->equippedNanos[i] == plr->activeNano) { // tick active nano
|
sNano* nano = plr->getActiveNano();
|
||||||
sNano& nano = plr->Nanos[plr->activeNano];
|
if (Abilities::SkillTable.find(nano->iSkillID) != Abilities::SkillTable.end()) {
|
||||||
int drainRate = 0;
|
|
||||||
|
|
||||||
if (Abilities::SkillTable.find(nano.iSkillID) != Abilities::SkillTable.end()) {
|
|
||||||
// nano has skill data
|
// nano has skill data
|
||||||
SkillData* skill = &Abilities::SkillTable[nano.iSkillID];
|
SkillData* skill = &Abilities::SkillTable[nano->iSkillID];
|
||||||
int boost = Nanos::getNanoBoost(plr);
|
if (skill->drainType == SkillDrainType::PASSIVE)
|
||||||
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);
|
Nanos::applyNanoBuff(skill, plr);
|
||||||
}
|
// ^ composite condition calculation is separate from combat for responsiveness
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -850,7 +863,6 @@ static void playerTick(CNServer *serv, time_t currTime) {
|
|||||||
}
|
}
|
||||||
else it++;
|
else it++;
|
||||||
}
|
}
|
||||||
//
|
|
||||||
|
|
||||||
if (transmit) {
|
if (transmit) {
|
||||||
INITSTRUCT(sP_FE2CL_REP_PC_TICK, pkt);
|
INITSTRUCT(sP_FE2CL_REP_PC_TICK, pkt);
|
||||||
@ -866,9 +878,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)
|
if (currTime - lastHealTime >= 4000)
|
||||||
lastHealTime = currTime;
|
lastHealTime = currTime;
|
||||||
|
if(currTime - lastCombatTIme >= 2000)
|
||||||
|
lastCombatTIme = currTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Combat::init() {
|
void Combat::init() {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#define REGISTER_SHARD_PACKET(pactype, handlr) CNShardServer::ShardPackets[pactype] = handlr;
|
#define REGISTER_SHARD_PACKET(pactype, handlr) CNShardServer::ShardPackets[pactype] = handlr;
|
||||||
#define REGISTER_SHARD_TIMER(handlr, delta) CNShardServer::Timers.push_back(TimerEvent(handlr, delta));
|
#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 {
|
class CNShardServer : public CNServer {
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user