diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 9dfa39e8..ea615cde 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -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()); } } diff --git a/Crawler/ItemDrop.cpp b/Crawler/ItemDrop.cpp index 38458a2a..3f5e9a84 100644 --- a/Crawler/ItemDrop.cpp +++ b/Crawler/ItemDrop.cpp @@ -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; } \ No newline at end of file diff --git a/Crawler/ItemDrop.h b/Crawler/ItemDrop.h index 88955f12..03141f18 100644 --- a/Crawler/ItemDrop.h +++ b/Crawler/ItemDrop.h @@ -47,7 +47,8 @@ class ItemDrop{ bool upperLevel=false; static float gravity; static std::vectordrops; - 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(); }; \ No newline at end of file diff --git a/Crawler/Monster.cpp b/Crawler/Monster.cpp index 215e6f1f..b73c9d97 100644 --- a/Crawler/Monster.cpp +++ b/Crawler/Monster.cpp @@ -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::functionfunc){ 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 - + @@ -1969,6 +1969,6 @@ - + diff --git a/Crawler/assets/config/Monsters.txt b/Crawler/assets/config/Monsters.txt index bac39c9c..4947c2e2 100644 --- a/Crawler/assets/config/Monsters.txt +++ b/Crawler/assets/config/Monsters.txt @@ -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] diff --git a/Crawler/assets/config/items/items.txt b/Crawler/assets/config/items/items.txt index 33782bfd..54d6ac6a 100644 --- a/Crawler/assets/config/items/items.txt +++ b/Crawler/assets/config/items/items.txt @@ -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