Fix crash when the game attempts to spawn item drops. Release Build 9125.

pull/57/head
sigonasr2 7 months ago
parent f3f91f560e
commit 70906d5594
  1. 4
      Adventures in Lestoria/Monster.cpp
  2. 11
      Adventures in Lestoria/MonsterData.cpp
  3. 2
      Adventures in Lestoria/SpawnEncounterLabel.h
  4. 2
      Adventures in Lestoria/Version.h
  5. 2
      Adventures in Lestoria/assets/config/Monsters.txt
  6. BIN
      x64/Release/Adventures in Lestoria.exe

@ -67,7 +67,7 @@ std::map<std::string,Renderable*>MonsterData::imgs;
Monster::Monster(vf2d pos,MonsterData data,bool upperLevel,bool bossMob): Monster::Monster(vf2d pos,MonsterData data,bool upperLevel,bool bossMob):
pos(pos),spawnPos(pos),hp(data.GetHealth()),size(data.GetSizeMult()),targetSize(data.GetSizeMult()),strategy(data.GetAIStrategy()),name(data.GetDisplayName()),upperLevel(upperLevel),isBoss(bossMob),facingDirection(DOWN){ pos(pos),spawnPos(pos),hp(data.GetHealth()),size(data.GetSizeMult()),targetSize(data.GetSizeMult()),strategy(data.GetAIStrategy()),name(data.GetDisplayName()),upperLevel(upperLevel),isBoss(bossMob),facingDirection(DOWN){
for(const std::string&anim:data.GetAnimations()){ for(const std::string&anim:data.GetAnimations()){
animation.AddState(anim,ANIMATION_DATA[anim]); animation.AddState(anim,ANIMATION_DATA[std::format("{}_{}",name,anim)]);
} }
PerformIdleAnimation(); PerformIdleAnimation();
stats.A("Health")=data.GetHealth(); stats.A("Health")=data.GetHealth();
@ -705,7 +705,7 @@ std::map<ItemInfo*,uint16_t>Monster::SpawnDrops(){
int dropQuantity=int(data.minQty+std::round(util::random(float(data.maxQty-data.minQty)))); int dropQuantity=int(data.minQty+std::round(util::random(float(data.maxQty-data.minQty))));
for(int i=0;i<dropQuantity;i++){ for(int i=0;i<dropQuantity;i++){
ItemDrop::SpawnItem(&data.item,GetPos(),OnUpperLevel()); ItemDrop::SpawnItem(&data.item,GetPos(),OnUpperLevel());
drops.at(const_cast<ItemInfo*>(&data.item))++; drops[const_cast<ItemInfo*>(&data.item)]++;
} }
} }
} }

@ -52,7 +52,7 @@ std::map<std::string,MonsterData>MONSTER_DATA;
MonsterData::MonsterData() MonsterData::MonsterData()
:atk(0),collisionDmg(0),hp(0),moveSpd(0),size(0),strategy("Run Towards"){} :atk(0),collisionDmg(0),hp(0),moveSpd(0),size(0),strategy("Run Towards"){}
MonsterData::MonsterData(std::string name,int hp,int atk,const uint32_t xp,std::vector<MonsterDropData>drops,float moveSpd,float size,std::string strategy,int collisionDmg): MonsterData::MonsterData(std::string name,int hp,int atk,const uint32_t xp,std::vector<MonsterDropData>drops,float moveSpd,float size,std::string strategy,int collisionDmg):
name(name),hp(hp),atk(atk),xp(xp),moveSpd(moveSpd),size(size),strategy(strategy),animations(animations),dropData(drops),collisionDmg(collisionDmg){} name(name),hp(hp),atk(atk),xp(xp),moveSpd(moveSpd),size(size),strategy(strategy),dropData(drops),collisionDmg(collisionDmg){}
void MonsterData::InitializeMonsterData(){ void MonsterData::InitializeMonsterData(){
for(auto&[key,size]:DATA["Monsters"].GetKeys()){ for(auto&[key,size]:DATA["Monsters"].GetKeys()){
@ -173,12 +173,7 @@ void MonsterData::InitializeNPCData(){
if(MONSTER_DATA.count(key)){ if(MONSTER_DATA.count(key)){
ERR("WARNING! A monster with the name "<<key<<" already exists in the database! Duplicates are not allowed.") ERR("WARNING! A monster with the name "<<key<<" already exists in the database! Duplicates are not allowed.")
} }
std::vector<std::string>animations{ std::vector<std::string>animations;
NPCName+"_IDLE",
NPCName+"_JUMP",
NPCName+"_SPIT",
NPCName+"_DIE",
};
MonsterData::imgs[NPCName]=NEW Renderable(); MonsterData::imgs[NPCName]=NEW Renderable();
const rcode imgLoadResult=MonsterData::imgs[NPCName]->Load("assets/npcs/"+NPCName+".png"); const rcode imgLoadResult=MonsterData::imgs[NPCName]->Load("assets/npcs/"+NPCName+".png");
@ -270,7 +265,7 @@ void MonsterData::InitializeNPCData(){
MonsterData monster(NPCName,health,attack,xp,drops,moveSpd,size/100,strategyName,collisionDmg); MonsterData monster(NPCName,health,attack,xp,drops,moveSpd,size/100,strategyName,collisionDmg);
for(size_t animationRow=0;const std::string&animationName:animations){ for(size_t animationRow=0;const std::string&animationName:animations){
//if(!monster.animations.insert(animationName).second)ERR(std::format("WARNING! The Animation {} for Monster {} already exists! Animations should have unique names!",animationName,NPCName)); if(!monster.animations.insert(animationName).second)ERR(std::format("WARNING! The Animation {} for Monster {} already exists! Animations should have unique names!",animationName,NPCName));
switch(animationRow){ switch(animationRow){
case 0:monster.idleAnimation=animationName;break; case 0:monster.idleAnimation=animationName;break;

@ -52,7 +52,7 @@ class SpawnEncounterLabel:public MenuLabel{
public: public:
inline SpawnEncounterLabel(geom2d::rect<float>rect,std::string label,std::string monsterName) inline SpawnEncounterLabel(geom2d::rect<float>rect,std::string label,std::string monsterName)
:MenuLabel(rect,label),monsterName(monsterName){ :MenuLabel(rect,label),monsterName(monsterName){
anim.AddState("IDLE",ANIMATION_DATA.at(MONSTER_DATA.at(monsterName).GetIdleAnimation())); anim.AddState("IDLE",ANIMATION_DATA.at(std::format("{}_{}",monsterName,MONSTER_DATA.at(monsterName).GetIdleAnimation())));
anim.ChangeState(state,"IDLE"); anim.ChangeState(state,"IDLE");
anim.UpdateState(state,util::random(1)); anim.UpdateState(state,util::random(1));
} }

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1 #define VERSION_MAJOR 1
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 9115 #define VERSION_BUILD 9125
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

@ -256,7 +256,7 @@ Monsters
# Animations must be defined in the same order as they are in their sprite sheets # Animations must be defined in the same order as they are in their sprite sheets
# The First Four animations must represent a standing, walking, attack, and death animation. Their names are up to the creator. # The First Four animations must represent a standing, walking, attack, and death animation. Their names are up to the creator.
IDLE = 3, 0.2, PingPong IDLE = 3, 0.2, PingPong
JUMP = 4, 0.06, PingPong WALK = 4, 0.06, PingPong
SHOOT = 10, 0.1, OneShot SHOOT = 10, 0.1, OneShot
DEATH = 4, 0.1, OneShot DEATH = 4, 0.1, OneShot
} }

Loading…
Cancel
Save