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
3f5d85f322
commit
48bdcfe36f
@ -254,7 +254,7 @@ bool Monster::Hurt(int damage,bool onUpperLevel){
|
|||||||
if(!IsAlive()){
|
if(!IsAlive()){
|
||||||
animation.ChangeState(internal_animState,GetDeathAnimationName());
|
animation.ChangeState(internal_animState,GetDeathAnimationName());
|
||||||
}
|
}
|
||||||
iframe_timer=GET_FLOAT(Attribute::IFRAME_TIME_UPON_HIT);
|
iframe_timer=GetFloat(Attribute::IFRAME_TIME_UPON_HIT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,4 +383,52 @@ void Monster::SetSize(float newSize,bool immediate){
|
|||||||
|
|
||||||
void Monster::Set(_ATTRIBUTE a,std::variant<VARIANTS>val){
|
void Monster::Set(_ATTRIBUTE a,std::variant<VARIANTS>val){
|
||||||
attributes[a]=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 <variant>
|
||||||
#include "MonsterAttribute.h"
|
#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;
|
||||||
|
|
||||||
enum MonsterAnimation{
|
enum MonsterAnimation{
|
||||||
@ -142,27 +137,10 @@ public:
|
|||||||
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);
|
void Set(_ATTRIBUTE a,std::variant<VARIANTS>val);
|
||||||
template<typename T>
|
float GetFloat(_ATTRIBUTE a);
|
||||||
T _Get(_ATTRIBUTE a){
|
int GetInt(_ATTRIBUTE a);
|
||||||
if(attributes.count(a)>0){
|
std::string GetString(_ATTRIBUTE a);
|
||||||
return std::get<T>(attributes[a]);
|
bool GetBool(_ATTRIBUTE 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);
|
||||||
|
@ -12,7 +12,7 @@ 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.Set(Attribute::IFRAME_TIME_UPON_HIT,0);
|
m.Set(Attribute::IFRAME_TIME_UPON_HIT,0.f);
|
||||||
m.iframe_timer=ConfigFloat("Phase5.IframeTimePerHit");
|
m.iframe_timer=ConfigFloat("Phase5.IframeTimePerHit");
|
||||||
m.phase=1;
|
m.phase=1;
|
||||||
}break;
|
}break;
|
||||||
@ -37,7 +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);
|
m.Set(Attribute::IFRAME_TIME_UPON_HIT,1.f);
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user