Okay, this is more sane. Templates removed and Set does a check to make sure it's the correct type.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
018bc49eb9
commit
39c4db9c6f
@ -254,7 +254,7 @@ bool Monster::Hurt(int damage,bool onUpperLevel){
|
||||
if(!IsAlive()){
|
||||
animation.ChangeState(internal_animState,GetDeathAnimationName());
|
||||
}
|
||||
iframe_timer=GET_FLOAT(Attribute::IFRAME_TIME_UPON_HIT);
|
||||
iframe_timer=GetFloat(Attribute::IFRAME_TIME_UPON_HIT);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -383,4 +383,52 @@ void Monster::SetSize(float newSize,bool immediate){
|
||||
|
||||
void Monster::Set(_ATTRIBUTE a,std::variant<VARIANTS>val){
|
||||
attributes[a]=val;
|
||||
//Error handling below!
|
||||
//The idea is if we cannot retrieve the value, the program errors out.
|
||||
switch(a.type){
|
||||
case Attribute::TYPE::FLOAT:{
|
||||
GetFloat(a);
|
||||
}break;
|
||||
case Attribute::TYPE::INT:{
|
||||
GetInt(a);
|
||||
}break;
|
||||
case Attribute::TYPE::STRING:{
|
||||
GetString(a);
|
||||
}break;
|
||||
case Attribute::TYPE::BOOL:{
|
||||
GetBool(a);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
float Monster::GetFloat(_ATTRIBUTE a){
|
||||
if(attributes.count(a)>0){
|
||||
return std::get<float>(attributes[a]);
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Monster::GetInt(_ATTRIBUTE a){
|
||||
if(attributes.count(a)>0){
|
||||
return std::get<int>(attributes[a]);
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Monster::GetString(_ATTRIBUTE a){
|
||||
if(attributes.count(a)>0){
|
||||
return std::get<std::string>(attributes[a]);
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool Monster::GetBool(_ATTRIBUTE a){
|
||||
if(attributes.count(a)>0){
|
||||
return std::get<bool>(attributes[a]);
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -8,11 +8,6 @@
|
||||
#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;
|
||||
|
||||
enum MonsterAnimation{
|
||||
@ -142,27 +137,10 @@ public:
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
float GetFloat(_ATTRIBUTE a);
|
||||
int GetInt(_ATTRIBUTE a);
|
||||
std::string GetString(_ATTRIBUTE a);
|
||||
bool GetBool(_ATTRIBUTE a);
|
||||
private:
|
||||
struct STRATEGY{
|
||||
static int _GetInt(Monster&m,std::string param,int strategyNumber,int index=0);
|
||||
|
@ -12,7 +12,7 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe
|
||||
case 0:{
|
||||
m.size=ConfigInt("Phase1.Size")/100;
|
||||
m.diesNormally=false;
|
||||
m.Set(Attribute::IFRAME_TIME_UPON_HIT,0);
|
||||
m.Set(Attribute::IFRAME_TIME_UPON_HIT,0.f);
|
||||
m.iframe_timer=ConfigFloat("Phase5.IframeTimePerHit");
|
||||
m.phase=1;
|
||||
}break;
|
||||
@ -37,7 +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);
|
||||
m.Set(Attribute::IFRAME_TIME_UPON_HIT,1.f);
|
||||
}
|
||||
}break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user