mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 21:40:05 +00:00
CRLF purge in Buffs.cpp
This commit is contained in:
parent
daec7a33b7
commit
761581afd7
216
src/Buffs.cpp
216
src/Buffs.cpp
@ -1,108 +1,108 @@
|
|||||||
#include "Buffs.hpp"
|
#include "Buffs.hpp"
|
||||||
|
|
||||||
#include "PlayerManager.hpp"
|
#include "PlayerManager.hpp"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
using namespace Buffs;
|
using namespace Buffs;
|
||||||
|
|
||||||
void Buff::onTick() {
|
void Buff::onTick() {
|
||||||
assert(!stacks.empty());
|
assert(!stacks.empty());
|
||||||
|
|
||||||
std::set<BuffCallback> callbacks;
|
std::set<BuffCallback> callbacks;
|
||||||
auto it = stacks.begin();
|
auto it = stacks.begin();
|
||||||
while(it != stacks.end()) {
|
while(it != stacks.end()) {
|
||||||
BuffStack& stack = *it;
|
BuffStack& stack = *it;
|
||||||
if(stack.onTick != nullptr && callbacks.count(stack.onTick) == 0) {
|
if(stack.onTick != nullptr && callbacks.count(stack.onTick) == 0) {
|
||||||
// unique callback
|
// unique callback
|
||||||
stack.onTick(self, &stack);
|
stack.onTick(self, &stack);
|
||||||
callbacks.insert(stack.onTick);
|
callbacks.insert(stack.onTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(stack.durationTicks > 0) stack.durationTicks--;
|
if(stack.durationTicks > 0) stack.durationTicks--;
|
||||||
if(stack.durationTicks == 0) {
|
if(stack.durationTicks == 0) {
|
||||||
it = stacks.erase(it);
|
it = stacks.erase(it);
|
||||||
stack.onExpire(self, &stack);
|
stack.onExpire(self, &stack);
|
||||||
} else it++;
|
} else it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buff::onExpire() {
|
void Buff::onExpire() {
|
||||||
assert(!stacks.empty());
|
assert(!stacks.empty());
|
||||||
|
|
||||||
std::set<BuffCallback> callbacks;
|
std::set<BuffCallback> callbacks;
|
||||||
while(!stacks.empty()) {
|
while(!stacks.empty()) {
|
||||||
BuffStack stack = stacks.back();
|
BuffStack stack = stacks.back();
|
||||||
stacks.pop_back();
|
stacks.pop_back();
|
||||||
if(stack.onExpire != nullptr && callbacks.count(stack.onExpire) == 0) {
|
if(stack.onExpire != nullptr && callbacks.count(stack.onExpire) == 0) {
|
||||||
// execute unique callback
|
// execute unique callback
|
||||||
callbacks.insert(stack.onExpire);
|
callbacks.insert(stack.onExpire);
|
||||||
stack.onExpire(self, &stack);
|
stack.onExpire(self, &stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buff::addStack(BuffStack* stack) {
|
void Buff::addStack(BuffStack* stack) {
|
||||||
stacks.push_back(*stack);
|
stacks.push_back(*stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
BuffStack* Buff::getDominantBuff() {
|
BuffStack* Buff::getDominantBuff() {
|
||||||
assert(!stacks.empty());
|
assert(!stacks.empty());
|
||||||
|
|
||||||
BuffStack* dominant = nullptr;
|
BuffStack* dominant = nullptr;
|
||||||
for(BuffStack& stack : stacks) {
|
for(BuffStack& stack : stacks) {
|
||||||
if(stack.buffClass > dominant->buffClass)
|
if(stack.buffClass > dominant->buffClass)
|
||||||
dominant = &stack;
|
dominant = &stack;
|
||||||
}
|
}
|
||||||
return dominant;
|
return dominant;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Buff::isStale() {
|
bool Buff::isStale() {
|
||||||
return stacks.empty();
|
return stacks.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void timeBuffUpdate(EntityRef self, BuffStack* buff, int type) {
|
static void timeBuffUpdate(EntityRef self, BuffStack* buff, int type) {
|
||||||
|
|
||||||
if(self.kind != EntityKind::PLAYER)
|
if(self.kind != EntityKind::PLAYER)
|
||||||
return; // not implemented
|
return; // not implemented
|
||||||
|
|
||||||
Player* plr = (Player*)self.getEntity();
|
Player* plr = (Player*)self.getEntity();
|
||||||
if(plr == nullptr)
|
if(plr == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_PC_BUFF_UPDATE, pkt);
|
INITSTRUCT(sP_FE2CL_PC_BUFF_UPDATE, pkt);
|
||||||
pkt.eCSTB = buff->id; // eCharStatusTimeBuffID
|
pkt.eCSTB = buff->id; // eCharStatusTimeBuffID
|
||||||
pkt.eTBU = type; // eTimeBuffUpdate
|
pkt.eTBU = type; // eTimeBuffUpdate
|
||||||
pkt.eTBT = (int)buff->buffClass;
|
pkt.eTBT = (int)buff->buffClass;
|
||||||
pkt.iConditionBitFlag = plr->getCompositeCondition();
|
pkt.iConditionBitFlag = plr->getCompositeCondition();
|
||||||
self.sock->sendPacket((void*)&pkt, P_FE2CL_PC_BUFF_UPDATE, sizeof(sP_FE2CL_PC_BUFF_UPDATE));
|
self.sock->sendPacket((void*)&pkt, P_FE2CL_PC_BUFF_UPDATE, sizeof(sP_FE2CL_PC_BUFF_UPDATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void timeBuffTimeoutViewable(EntityRef self) {
|
static void timeBuffTimeoutViewable(EntityRef self) {
|
||||||
if(self.kind != EntityKind::PLAYER)
|
if(self.kind != EntityKind::PLAYER)
|
||||||
return; // not implemented
|
return; // not implemented
|
||||||
|
|
||||||
Player* plr = (Player*)self.getEntity();
|
Player* plr = (Player*)self.getEntity();
|
||||||
if(plr == nullptr)
|
if(plr == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT, pkt); // send a buff timeout to other players
|
INITSTRUCT(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT, pkt); // send a buff timeout to other players
|
||||||
pkt.eCT = 1;
|
pkt.eCT = 1;
|
||||||
pkt.iID = plr->iID;
|
pkt.iID = plr->iID;
|
||||||
pkt.iConditionBitFlag = plr->getCompositeCondition();
|
pkt.iConditionBitFlag = plr->getCompositeCondition();
|
||||||
PlayerManager::sendToViewable(self.sock, pkt, P_FE2CL_CHAR_TIME_BUFF_TIME_OUT);
|
PlayerManager::sendToViewable(self.sock, pkt, P_FE2CL_CHAR_TIME_BUFF_TIME_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffs::timeBuffUpdateAdd(EntityRef self, BuffStack* buff) {
|
void Buffs::timeBuffUpdateAdd(EntityRef self, BuffStack* buff) {
|
||||||
timeBuffUpdate(self, buff, ETBU_ADD);
|
timeBuffUpdate(self, buff, ETBU_ADD);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffs::timeBuffUpdateDelete(EntityRef self, BuffStack* buff) {
|
void Buffs::timeBuffUpdateDelete(EntityRef self, BuffStack* buff) {
|
||||||
timeBuffUpdate(self, buff, ETBU_DEL);
|
timeBuffUpdate(self, buff, ETBU_DEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffs::timeBuffTimeout(EntityRef self, BuffStack* buff) {
|
void Buffs::timeBuffTimeout(EntityRef self, BuffStack* buff) {
|
||||||
timeBuffUpdate(self, buff, ETBU_DEL);
|
timeBuffUpdate(self, buff, ETBU_DEL);
|
||||||
timeBuffTimeoutViewable(self);
|
timeBuffTimeoutViewable(self);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user