Item Drops implemented on monster kills.

pull/28/head
sigonasr2 1 year ago
parent e7f60c01d3
commit a3ac1243d7
  1. 2
      Crawler/Crawler.cpp
  2. 23
      Crawler/ItemDrop.cpp
  3. 6
      Crawler/ItemDrop.h
  4. 23
      Crawler/Monster.cpp
  5. 1
      Crawler/Monster.h
  6. 2
      Crawler/Version.h
  7. 4
      Crawler/assets/Campaigns/1_1_v2.tmx
  8. 4
      Crawler/assets/config/Monsters.txt
  9. 3
      Crawler/assets/config/items/items.txt

@ -420,7 +420,7 @@ void Crawler::HandleUserInput(float fElapsedTime){
Menu::OpenMenu(INVENTORY);
}
if(GetKey(O).bPressed){
ItemDrop::SpawnItem(&ITEM_DATA.at("Green Slime Remains"),player->GetPos());
ItemDrop::SpawnItem(&ITEM_DATA.at("Green Slime Remains"),player->GetPos(),player->OnUpperLevel());
}
}

@ -45,8 +45,8 @@ void ItemDrop::Initialize(){
gravity="ItemDrop.Item Drop Gravity"_F;
}
ItemDrop::ItemDrop(ItemInfo*item,vf2d pos)
:item(item),pos(pos){
ItemDrop::ItemDrop(ItemInfo*item,vf2d pos,bool isUpper)
:item(item),pos(pos),upperLevel(isUpper){
speed.x=util::random("ItemDrop.Item Drop Horizontal Speed"_f[1]-"ItemDrop.Item Drop Horizontal Speed"_f[0])+"ItemDrop.Item Drop Horizontal Speed"_f[0];
speed.y=util::random("ItemDrop.Item Drop Vertical Speed"_f[1]-"ItemDrop.Item Drop Vertical Speed"_f[0])+"ItemDrop.Item Drop Vertical Speed"_f[0];
zSpeed="ItemDrop.Item Drop Initial Rise Speed"_F;
@ -102,8 +102,9 @@ void ItemDrop::UpdateDrops(float fElapsedTime){
vf2d pointVel=lineTo.vector().norm();
if((1.f/dist)*200*fElapsedTime>dist){
drop.pos=game->GetPlayer()->GetPos();
drop.collected=true;
}else{
drop.pos+=pointVel*(1.f/dist)*200*fElapsedTime;
drop.pos+=pointVel*(1.f/dist)*"ItemDrop.Item Drop Suction Strength"_F*fElapsedTime;
}
}
}
@ -125,12 +126,24 @@ void ItemDrop::UpdateDrops(float fElapsedTime){
}
#pragma endregion
}
std::erase_if(drops,[](ItemDrop&drop){
if(drop.collected){
Inventory::AddItem(drop.GetItem()->Name(),1,true);
return true;
}
return false;
});
}
float ItemDrop::GetZ(){
return z;
}
void ItemDrop::SpawnItem(ItemInfo*item,vf2d pos){
drops.push_back(ItemDrop{item,pos});
void ItemDrop::SpawnItem(ItemInfo*item,vf2d pos,bool isUpper){
drops.push_back(ItemDrop{item,pos,isUpper});
}
ItemInfo*ItemDrop::GetItem(){
return item;
}

@ -47,7 +47,8 @@ class ItemDrop{
bool upperLevel=false;
static float gravity;
static std::vector<ItemDrop>drops;
ItemDrop(ItemInfo*item,vf2d pos);
bool collected=false;
ItemDrop(ItemInfo*item,vf2d pos,bool isUpper);
public:
static void Initialize();
vf2d GetPos();
@ -55,5 +56,6 @@ public:
void Draw();
static void UpdateDrops(float fElapsedTime);
float GetZ();
static void SpawnItem(ItemInfo*item,vf2d pos);
static void SpawnItem(ItemInfo*item,vf2d pos,bool isUpper);
ItemInfo*GetItem();
};

@ -41,6 +41,7 @@ SUCH DAMAGE.
#include "MonsterStrategyHelpers.h"
#include "util.h"
#include "MonsterAttribute.h"
#include "ItemDrop.h"
INCLUDE_ANIMATION_DATA
INCLUDE_MONSTER_DATA
@ -294,10 +295,7 @@ bool Monster::Hurt(int damage,bool onUpperLevel,float z){
}
lastHitTimer=0.05;
if(!IsAlive()){
animation.ChangeState(internal_animState,GetDeathAnimationName());
if(isBoss){
game->ReduceBossEncounterMobCount();
}
OnDeath();
}else{
hp=std::max(1,hp); //Make sure it stays alive if it's supposed to be alive...
}
@ -441,4 +439,21 @@ void Monster::SetZ(float z){
void Monster::SetStrategyDrawFunction(std::function<void(Crawler*)>func){
strategyDraw=func;
}
void Monster::OnDeath(){
animation.ChangeState(internal_animState,GetDeathAnimationName());
if(isBoss){
game->ReduceBossEncounterMobCount();
}
for(MonsterDropData data:MONSTER_DATA.at(id).GetDropData()){
if(util::random(100)<=data.dropChance){
//This isn't necessarily fair odds for each quantity dropped.
int dropQuantity=data.minQty+std::round(util::random(data.maxQty-data.minQty));
for(int i=0;i<dropQuantity;i++){
ItemDrop::SpawnItem(data.item,GetPos(),OnUpperLevel());
}
}
}
}

@ -143,6 +143,7 @@ private:
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 targetSize=0;
bool isBoss=false;
void OnDeath();
protected:
public:
Monster()=delete;

@ -35,7 +35,7 @@ SUCH DAMAGE.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 3073
#define VERSION_BUILD 3077
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" class="Map" orientation="orthogonal" renderorder="right-down" width="205" height="205" tilewidth="24" tileheight="24" infinite="0" backgroundcolor="#475500" nextlayerid="9" nextobjectid="141">
<map version="1.10" tiledversion="1.10.1" class="Map" orientation="orthogonal" renderorder="right-down" width="205" height="205" tilewidth="24" tileheight="24" infinite="0" backgroundcolor="#475500" nextlayerid="9" nextobjectid="142">
<properties>
<property name="Level Type" propertytype="LevelType" value="Dungeon"/>
</properties>
@ -1969,6 +1969,6 @@
</properties>
<point/>
</object>
<object id="137" name="Player Spawn" type="PlayerSpawnLocation" x="4812" y="2274" width="24" height="24"/>
<object id="141" name="Player Spawn" type="PlayerSpawnLocation" x="600" y="4272" width="24" height="24"/>
</objectgroup>
</map>

@ -54,7 +54,7 @@ Monsters
DeathAnimation = 10, 0.1, OneShot
# Drop Item Name, Drop Percentage(0-100%), Drop Min Quantity, Drop Max Quantity
DROP[0] = Green Slime Remains,65%,1,2
DROP[0] = Blue Slime Remains,65%,1,2
DROP[1] = Small Health Potion,5%,1,1
#Additional custom animations go down below. Start with ANIMATION[0]
@ -83,7 +83,7 @@ Monsters
DeathAnimation = 10, 0.1, OneShot
# Drop Item Name, Drop Percentage(0-100%), Drop Min Quantity, Drop Max Quantity
DROP[0] = Green Slime Remains,65%,1,2
DROP[0] = Red Slime Remains,65%,1,2
DROP[1] = Small Health Potion,5%,1,1
#Additional custom animations go down below. Start with ANIMATION[0]

@ -15,6 +15,9 @@ ItemDrop
# Item drop suction range
Item Drop Suction Range = 48
# Item drop suction strength
Item Drop Suction Strength = 350
# Item drop initial rise speed
Item Drop Initial Rise Speed = 10

Loading…
Cancel
Save