diff --git a/Crawler/Monster.cpp b/Crawler/Monster.cpp index 01723f10..a7dd49c2 100644 --- a/Crawler/Monster.cpp +++ b/Crawler/Monster.cpp @@ -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::variantval){ + attributes[a]=val; } \ No newline at end of file diff --git a/Crawler/Monster.h b/Crawler/Monster.h index 0d38e940..4cd235ef 100644 --- a/Crawler/Monster.h +++ b/Crawler/Monster.h @@ -5,6 +5,13 @@ #include "Buff.h" #include "olcUTIL_Animate2D.h" #include "DamageNumber.h" +#include +#include "MonsterAttribute.h" + +#define GET_FLOAT(attribute) _Get(attribute); +#define GET_INT(attribute) _Get(attribute); +#define GET_STRING(attribute) _Get(attribute); +#define GET_BOOL(attribute) _Get(attribute); struct Player; @@ -87,8 +94,8 @@ private: std::shared_ptrdamageNumberPtr; 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>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::variantval); + template + T _Get(_ATTRIBUTE a){ + if(attributes.count(a)>0){ + return std::get(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); diff --git a/Crawler/MonsterAttribute.h b/Crawler/MonsterAttribute.h new file mode 100644 index 00000000..e6d62fbb --- /dev/null +++ b/Crawler/MonsterAttribute.h @@ -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); +} \ No newline at end of file diff --git a/Crawler/SlimeKing.cpp b/Crawler/SlimeKing.cpp index 153f9a52..14278ed4 100644 --- a/Crawler/SlimeKing.cpp +++ b/Crawler/SlimeKing.cpp @@ -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; }