Implement custom attributes for monsters.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
a69be08a1a
commit
b39bed3958
@ -254,9 +254,7 @@ bool Monster::Hurt(int damage,bool onUpperLevel){
|
||||
if(!IsAlive()){
|
||||
animation.ChangeState(internal_animState,GetDeathAnimationName());
|
||||
}
|
||||
if(GetStrategy()=="Slime King"&&phase==5){
|
||||
iframe_timer=iframeTimeUponHit;
|
||||
}
|
||||
iframe_timer=GET_FLOAT(Attribute::IFRAME_TIME_UPON_HIT);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -381,4 +379,8 @@ void Monster::SetSize(float newSize,bool immediate){
|
||||
}else{
|
||||
targetSize=newSize;
|
||||
}
|
||||
}
|
||||
|
||||
void Monster::Set(_ATTRIBUTE a,std::variant<VARIANTS>val){
|
||||
attributes[a]=val;
|
||||
}
|
@ -5,6 +5,13 @@
|
||||
#include "Buff.h"
|
||||
#include "olcUTIL_Animate2D.h"
|
||||
#include "DamageNumber.h"
|
||||
#include <variant>
|
||||
#include "MonsterAttribute.h"
|
||||
|
||||
#define GET_FLOAT(attribute) _Get<float>(attribute);
|
||||
#define GET_INT(attribute) _Get<int>(attribute);
|
||||
#define GET_STRING(attribute) _Get<std::string>(attribute);
|
||||
#define GET_BOOL(attribute) _Get<bool>(attribute);
|
||||
|
||||
struct Player;
|
||||
|
||||
@ -87,8 +94,8 @@ private:
|
||||
std::shared_ptr<DamageNumber>damageNumberPtr;
|
||||
int phase=0;
|
||||
bool diesNormally=true; //If set to false, the monster death is handled in a special way. Set it to true when it's time to die.
|
||||
float iframeTimeUponHit=0;
|
||||
float targetSize=0;
|
||||
std::map<_ATTRIBUTE,std::variant<VARIANTS>>attributes;
|
||||
protected:
|
||||
public:
|
||||
Monster()=delete;
|
||||
@ -134,6 +141,28 @@ public:
|
||||
float GetZ();
|
||||
std::string GetStrategy();
|
||||
void SetSize(float newSize,bool immediate=true);
|
||||
void Set(_ATTRIBUTE a,std::variant<VARIANTS>val);
|
||||
template<typename T>
|
||||
T _Get(_ATTRIBUTE a){
|
||||
if(attributes.count(a)>0){
|
||||
return std::get<T>(attributes[a]);
|
||||
}else{
|
||||
switch(a.type){
|
||||
case Attribute::TYPE::FLOAT:{
|
||||
return 0;
|
||||
}break;
|
||||
case Attribute::TYPE::INT:{
|
||||
return 0;
|
||||
}break;
|
||||
case Attribute::TYPE::STRING:{
|
||||
return "";
|
||||
}break;
|
||||
case Attribute::TYPE::BOOL:{
|
||||
return false;
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
struct STRATEGY{
|
||||
static int _GetInt(Monster&m,std::string param,int strategyNumber,int index=0);
|
||||
|
20
Crawler/MonsterAttribute.h
Normal file
20
Crawler/MonsterAttribute.h
Normal file
@ -0,0 +1,20 @@
|
||||
#define VARIANTS float,int,std::string,bool
|
||||
#define CREATE_ATTRIBUTE(variable,type) _ATTRIBUTE variable{Attribute::TYPE::type};
|
||||
|
||||
namespace Attribute{
|
||||
enum class TYPE{
|
||||
FLOAT,
|
||||
INT,
|
||||
STRING,
|
||||
BOOL,
|
||||
};
|
||||
}
|
||||
|
||||
struct _ATTRIBUTE{
|
||||
Attribute::TYPE type;
|
||||
};
|
||||
|
||||
namespace Attribute{
|
||||
CREATE_ATTRIBUTE(IFRAME_TIME_UPON_HIT,FLOAT);
|
||||
CREATE_ATTRIBUTE(SHOOT_RING_TIMER,FLOAT);
|
||||
}
|
@ -12,7 +12,8 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe
|
||||
case 0:{
|
||||
m.size=ConfigInt("Phase1.Size")/100;
|
||||
m.diesNormally=false;
|
||||
m.iframeTimeUponHit=ConfigFloat("Phase5.IframeTimePerHit");
|
||||
m.Set(Attribute::IFRAME_TIME_UPON_HIT,0);
|
||||
m.iframe_timer=ConfigFloat("Phase5.IframeTimePerHit");
|
||||
m.phase=1;
|
||||
}break;
|
||||
case 1:{
|
||||
@ -36,6 +37,7 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe
|
||||
case 4:{
|
||||
if(m.hp<=0){
|
||||
m.phase=5;
|
||||
m.Set(Attribute::IFRAME_TIME_UPON_HIT,1);
|
||||
}
|
||||
}break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user