Implement custom attributes for monsters.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
fc65c8bcdf
commit
9a367d3386
@ -254,9 +254,7 @@ bool Monster::Hurt(int damage,bool onUpperLevel){
|
|||||||
if(!IsAlive()){
|
if(!IsAlive()){
|
||||||
animation.ChangeState(internal_animState,GetDeathAnimationName());
|
animation.ChangeState(internal_animState,GetDeathAnimationName());
|
||||||
}
|
}
|
||||||
if(GetStrategy()=="Slime King"&&phase==5){
|
iframe_timer=GET_FLOAT(Attribute::IFRAME_TIME_UPON_HIT);
|
||||||
iframe_timer=iframeTimeUponHit;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,3 +380,7 @@ void Monster::SetSize(float newSize,bool immediate){
|
|||||||
targetSize=newSize;
|
targetSize=newSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Monster::Set(_ATTRIBUTE a,std::variant<VARIANTS>val){
|
||||||
|
attributes[a]=val;
|
||||||
|
}
|
@ -5,6 +5,13 @@
|
|||||||
#include "Buff.h"
|
#include "Buff.h"
|
||||||
#include "olcUTIL_Animate2D.h"
|
#include "olcUTIL_Animate2D.h"
|
||||||
#include "DamageNumber.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;
|
struct Player;
|
||||||
|
|
||||||
@ -87,8 +94,8 @@ private:
|
|||||||
std::shared_ptr<DamageNumber>damageNumberPtr;
|
std::shared_ptr<DamageNumber>damageNumberPtr;
|
||||||
int phase=0;
|
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.
|
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;
|
float targetSize=0;
|
||||||
|
std::map<_ATTRIBUTE,std::variant<VARIANTS>>attributes;
|
||||||
protected:
|
protected:
|
||||||
public:
|
public:
|
||||||
Monster()=delete;
|
Monster()=delete;
|
||||||
@ -134,6 +141,28 @@ public:
|
|||||||
float GetZ();
|
float GetZ();
|
||||||
std::string GetStrategy();
|
std::string GetStrategy();
|
||||||
void SetSize(float newSize,bool immediate=true);
|
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:
|
private:
|
||||||
struct STRATEGY{
|
struct STRATEGY{
|
||||||
static int _GetInt(Monster&m,std::string param,int strategyNumber,int index=0);
|
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:{
|
case 0:{
|
||||||
m.size=ConfigInt("Phase1.Size")/100;
|
m.size=ConfigInt("Phase1.Size")/100;
|
||||||
m.diesNormally=false;
|
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;
|
m.phase=1;
|
||||||
}break;
|
}break;
|
||||||
case 1:{
|
case 1:{
|
||||||
@ -36,6 +37,7 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe
|
|||||||
case 4:{
|
case 4:{
|
||||||
if(m.hp<=0){
|
if(m.hp<=0){
|
||||||
m.phase=5;
|
m.phase=5;
|
||||||
|
m.Set(Attribute::IFRAME_TIME_UPON_HIT,1);
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user