2022-07-17 06:33:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "core/Core.hpp"
|
|
|
|
|
|
|
|
#include "Entities.hpp"
|
|
|
|
|
|
|
|
#include <vector>
|
2022-07-18 15:53:53 +00:00
|
|
|
#include <functional>
|
2022-07-17 06:33:57 +00:00
|
|
|
|
|
|
|
/* forward declaration(s) */
|
|
|
|
struct BuffStack;
|
|
|
|
|
|
|
|
#define CSB_FROM_ECSB(x) (1 << (x - 1))
|
|
|
|
|
|
|
|
enum class BuffClass {
|
2022-07-18 03:47:54 +00:00
|
|
|
NONE = ETBT_NONE,
|
|
|
|
NANO = ETBT_NANO,
|
|
|
|
GROUP_NANO = ETBT_GROUPNANO,
|
|
|
|
EGG = ETBT_SHINY,
|
|
|
|
ENVIRONMENT = ETBT_LANDEFFECT,
|
|
|
|
ITEM = ETBT_ITEM,
|
|
|
|
CASH_ITEM = ETBT_CASHITEM
|
2022-07-17 06:33:57 +00:00
|
|
|
};
|
|
|
|
|
2022-07-18 15:53:53 +00:00
|
|
|
typedef std::function<void(EntityRef, BuffStack*)> BuffCallback;
|
2022-07-17 06:33:57 +00:00
|
|
|
|
|
|
|
struct BuffStack {
|
|
|
|
int durationTicks;
|
2022-07-21 16:22:19 +00:00
|
|
|
int value;
|
2022-07-17 06:33:57 +00:00
|
|
|
EntityRef source;
|
2022-07-19 08:09:25 +00:00
|
|
|
BuffClass buffStackClass;
|
2022-07-17 06:33:57 +00:00
|
|
|
|
2022-07-18 15:53:53 +00:00
|
|
|
/* called just before the stack is added */
|
2022-07-17 06:33:57 +00:00
|
|
|
BuffCallback onApply;
|
2022-07-18 15:53:53 +00:00
|
|
|
|
|
|
|
/* called when the stack is ticked */
|
2022-07-17 06:33:57 +00:00
|
|
|
BuffCallback onTick;
|
2022-07-18 15:53:53 +00:00
|
|
|
|
|
|
|
/* called just after the stack is removed */
|
2022-07-17 06:33:57 +00:00
|
|
|
BuffCallback onExpire;
|
2022-07-19 08:09:25 +00:00
|
|
|
|
|
|
|
Buff* buff;
|
2022-07-17 06:33:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Buff {
|
|
|
|
private:
|
|
|
|
EntityRef self;
|
|
|
|
std::vector<BuffStack> stacks;
|
|
|
|
|
|
|
|
public:
|
2022-07-19 08:09:25 +00:00
|
|
|
int id;
|
|
|
|
|
2022-07-18 15:53:53 +00:00
|
|
|
void tick();
|
|
|
|
void clear();
|
2022-07-18 01:39:25 +00:00
|
|
|
void addStack(BuffStack* stack);
|
2022-07-17 06:33:57 +00:00
|
|
|
|
|
|
|
/*
|
2022-07-18 15:53:53 +00:00
|
|
|
* Sometimes we need to determine if a buff
|
|
|
|
* is covered by a certain class, ex: nano
|
|
|
|
* vs. coco egg in the case of infection protection
|
2022-07-17 06:33:57 +00:00
|
|
|
*/
|
2022-07-18 15:53:53 +00:00
|
|
|
bool hasClass(BuffClass buffClass);
|
|
|
|
BuffClass maxClass();
|
2022-07-17 06:33:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In general, a Buff object won't exist
|
|
|
|
* unless it has stacks. However, when
|
|
|
|
* popping stacks during iteration (onExpire),
|
|
|
|
* stacks will be empty for a brief moment
|
|
|
|
* when the last stack is popped.
|
|
|
|
*/
|
2022-07-18 01:39:25 +00:00
|
|
|
bool isStale();
|
2022-07-17 06:33:57 +00:00
|
|
|
|
2022-07-19 08:09:25 +00:00
|
|
|
Buff(int iid, EntityRef pSelf, BuffStack* firstStack)
|
|
|
|
: id(iid), self(pSelf) {
|
2022-07-17 06:33:57 +00:00
|
|
|
addStack(firstStack);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace Buffs {
|
2022-07-19 08:09:25 +00:00
|
|
|
void timeBuffUpdate(EntityRef self, BuffStack* stack, int status);
|
|
|
|
void timeBuffTimeoutViewable(EntityRef self, BuffStack* stack, int ct);
|
2022-07-17 06:33:57 +00:00
|
|
|
}
|