Item Drops implemented on monster kills.
This commit is contained in:
parent
e7f60c01d3
commit
a3ac1243d7
@ -420,7 +420,7 @@ void Crawler::HandleUserInput(float fElapsedTime){
|
|||||||
Menu::OpenMenu(INVENTORY);
|
Menu::OpenMenu(INVENTORY);
|
||||||
}
|
}
|
||||||
if(GetKey(O).bPressed){
|
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;
|
gravity="ItemDrop.Item Drop Gravity"_F;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemDrop::ItemDrop(ItemInfo*item,vf2d pos)
|
ItemDrop::ItemDrop(ItemInfo*item,vf2d pos,bool isUpper)
|
||||||
:item(item),pos(pos){
|
: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.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];
|
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;
|
zSpeed="ItemDrop.Item Drop Initial Rise Speed"_F;
|
||||||
@ -102,8 +102,9 @@ void ItemDrop::UpdateDrops(float fElapsedTime){
|
|||||||
vf2d pointVel=lineTo.vector().norm();
|
vf2d pointVel=lineTo.vector().norm();
|
||||||
if((1.f/dist)*200*fElapsedTime>dist){
|
if((1.f/dist)*200*fElapsedTime>dist){
|
||||||
drop.pos=game->GetPlayer()->GetPos();
|
drop.pos=game->GetPlayer()->GetPos();
|
||||||
|
drop.collected=true;
|
||||||
}else{
|
}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
|
#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(){
|
float ItemDrop::GetZ(){
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemDrop::SpawnItem(ItemInfo*item,vf2d pos){
|
void ItemDrop::SpawnItem(ItemInfo*item,vf2d pos,bool isUpper){
|
||||||
drops.push_back(ItemDrop{item,pos});
|
drops.push_back(ItemDrop{item,pos,isUpper});
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemInfo*ItemDrop::GetItem(){
|
||||||
|
return item;
|
||||||
}
|
}
|
@ -47,7 +47,8 @@ class ItemDrop{
|
|||||||
bool upperLevel=false;
|
bool upperLevel=false;
|
||||||
static float gravity;
|
static float gravity;
|
||||||
static std::vector<ItemDrop>drops;
|
static std::vector<ItemDrop>drops;
|
||||||
ItemDrop(ItemInfo*item,vf2d pos);
|
bool collected=false;
|
||||||
|
ItemDrop(ItemInfo*item,vf2d pos,bool isUpper);
|
||||||
public:
|
public:
|
||||||
static void Initialize();
|
static void Initialize();
|
||||||
vf2d GetPos();
|
vf2d GetPos();
|
||||||
@ -55,5 +56,6 @@ public:
|
|||||||
void Draw();
|
void Draw();
|
||||||
static void UpdateDrops(float fElapsedTime);
|
static void UpdateDrops(float fElapsedTime);
|
||||||
float GetZ();
|
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 "MonsterStrategyHelpers.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "MonsterAttribute.h"
|
#include "MonsterAttribute.h"
|
||||||
|
#include "ItemDrop.h"
|
||||||
|
|
||||||
INCLUDE_ANIMATION_DATA
|
INCLUDE_ANIMATION_DATA
|
||||||
INCLUDE_MONSTER_DATA
|
INCLUDE_MONSTER_DATA
|
||||||
@ -294,10 +295,7 @@ bool Monster::Hurt(int damage,bool onUpperLevel,float z){
|
|||||||
}
|
}
|
||||||
lastHitTimer=0.05;
|
lastHitTimer=0.05;
|
||||||
if(!IsAlive()){
|
if(!IsAlive()){
|
||||||
animation.ChangeState(internal_animState,GetDeathAnimationName());
|
OnDeath();
|
||||||
if(isBoss){
|
|
||||||
game->ReduceBossEncounterMobCount();
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
hp=std::max(1,hp); //Make sure it stays alive if it's supposed to be alive...
|
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){
|
void Monster::SetStrategyDrawFunction(std::function<void(Crawler*)>func){
|
||||||
strategyDraw=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.
|
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;
|
float targetSize=0;
|
||||||
bool isBoss=false;
|
bool isBoss=false;
|
||||||
|
void OnDeath();
|
||||||
protected:
|
protected:
|
||||||
public:
|
public:
|
||||||
Monster()=delete;
|
Monster()=delete;
|
||||||
|
@ -35,7 +35,7 @@ SUCH DAMAGE.
|
|||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 1
|
#define VERSION_PATCH 1
|
||||||
#define VERSION_BUILD 3073
|
#define VERSION_BUILD 3077
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<properties>
|
||||||
<property name="Level Type" propertytype="LevelType" value="Dungeon"/>
|
<property name="Level Type" propertytype="LevelType" value="Dungeon"/>
|
||||||
</properties>
|
</properties>
|
||||||
@ -1969,6 +1969,6 @@
|
|||||||
</properties>
|
</properties>
|
||||||
<point/>
|
<point/>
|
||||||
</object>
|
</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>
|
</objectgroup>
|
||||||
</map>
|
</map>
|
||||||
|
@ -54,7 +54,7 @@ Monsters
|
|||||||
DeathAnimation = 10, 0.1, OneShot
|
DeathAnimation = 10, 0.1, OneShot
|
||||||
|
|
||||||
# Drop Item Name, Drop Percentage(0-100%), Drop Min Quantity, Drop Max Quantity
|
# 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
|
DROP[1] = Small Health Potion,5%,1,1
|
||||||
|
|
||||||
#Additional custom animations go down below. Start with ANIMATION[0]
|
#Additional custom animations go down below. Start with ANIMATION[0]
|
||||||
@ -83,7 +83,7 @@ Monsters
|
|||||||
DeathAnimation = 10, 0.1, OneShot
|
DeathAnimation = 10, 0.1, OneShot
|
||||||
|
|
||||||
# Drop Item Name, Drop Percentage(0-100%), Drop Min Quantity, Drop Max Quantity
|
# 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
|
DROP[1] = Small Health Potion,5%,1,1
|
||||||
|
|
||||||
#Additional custom animations go down below. Start with ANIMATION[0]
|
#Additional custom animations go down below. Start with ANIMATION[0]
|
||||||
|
@ -15,6 +15,9 @@ ItemDrop
|
|||||||
# Item drop suction range
|
# Item drop suction range
|
||||||
Item Drop Suction Range = 48
|
Item Drop Suction Range = 48
|
||||||
|
|
||||||
|
# Item drop suction strength
|
||||||
|
Item Drop Suction Strength = 350
|
||||||
|
|
||||||
# Item drop initial rise speed
|
# Item drop initial rise speed
|
||||||
Item Drop Initial Rise Speed = 10
|
Item Drop Initial Rise Speed = 10
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user