Implement min/max quantity rolling for stage loot configuration

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
pull/35/head
Nic0Nic0Nii 10 months ago
parent 3f0bfb6919
commit 7b0c83824d
  1. 4
      Adventures in Lestoria/AdventuresInLestoria.cpp
  2. 11
      Adventures in Lestoria/ItemMapData.h
  3. 7
      Adventures in Lestoria/State_LevelComplete.cpp
  4. 22
      Adventures in Lestoria/assets/config/levels.txt

@ -1636,7 +1636,9 @@ void AiL::InitializeLevel(std::string mapFile,MapName map){
for(auto&[key,size]:DATA["Levels"][map]){
if(key.starts_with("Loot")){
datafile data=DATA["Levels"][map][key];
MAP_DATA[map].stageLoot.push_back(ItemMapData(data.GetString(0U),data.GetInt(1U),data.GetInt(2U)));
int pctChance=100;
if(data.GetValueCount()>3)pctChance=data.GetInt(3U);
MAP_DATA[map].stageLoot.push_back(ItemMapData(data.GetString(0U),data.GetInt(1U),data.GetInt(2U),pctChance));
}
}

@ -30,7 +30,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2023 The FreeType
Portions of this software are copyright <EFBFBD> 2023 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
@ -40,8 +40,11 @@ All rights reserved.
struct ItemMapData{
IT item;
uint8_t amt;
uint8_t minAmt;
uint8_t maxAmt;
int chance;
inline ItemMapData(IT item,uint8_t amt,int chance)
:item(item),amt(amt),chance(chance){}
inline ItemMapData(IT item,uint8_t minAmt,uint8_t maxAmt,int chance)
:item(item),minAmt(minAmt),maxAmt(maxAmt),chance(chance){
if(minAmt>maxAmt)ERR(std::format("WARNING! The max amount specified for item {} is less than the minimum amount! {} > {}!",item,minAmt,maxAmt));
}
};

@ -52,7 +52,12 @@ void State_LevelComplete::OnStateChange(GameState*prevState){
Component<MenuLabel>(MenuType::LEVEL_COMPLETE,"Level EXP Gain Outline")->SetLabel(std::format("+{} Exp",game->GetPlayer()->GetAccumulatedXP()));
game->GetPlayer()->AddXP(game->GetPlayer()->GetAccumulatedXP());
for(const ItemMapData&data:game->GetCurrentMap().stageLoot){
for(uint8_t rolls=0;rolls<data.amt;rolls++){
uint8_t amountDiff=data.maxAmt-data.minAmt;
uint8_t randomAmt=data.maxAmt;
if(amountDiff>0){ //This check avoids division by zero.
randomAmt=util::random()%(amountDiff+1)+data.minAmt;
}
for(uint8_t rolls=0;rolls<randomAmt;rolls++){
if(util::random(1.0f)<data.chance/100.f){
Inventory::AddItem(data.item,1U);
}

@ -11,9 +11,9 @@ Levels
{
Map File = 1_1_v2.tmx
# Specify item and number of items. Optionally specify a % drop chance per item.
Loot[0] = Berries, 5, 100%
Loot[1] = Minor Mana Potion, 1, 100%
# Specify item, min quantity, and max quantity of items. Optionally specify a % drop chance per item.
Loot[0] = Berries, 3, 5, 100%
Loot[1] = Minor Mana Potion, 0, 1, 100%
}
BOSS_1
{
@ -23,43 +23,43 @@ Levels
CAMPAIGN_1_2
{
Map File = 1_2.tmx
# Specify item and number of items. Optionally specify a % drop chance per item.
# Loot[0] = Berries, 5, 100%
# Specify item, min quantity, and max quantity of items. Optionally specify a % drop chance per item.
# Loot[0] = Berries, 3, 5, 100%
}
CAMPAIGN_1_3
{
Map File = 1_3.tmx
# Specify item and number of items. Optionally specify a % drop chance per item.
# Specify item, min quantity, and max quantity of items. Optionally specify a % drop chance per item.
# Loot[0] = Berries, 5, 100%
}
CAMPAIGN_1_4
{
Map File = 1_4.tmx
# Specify item and number of items. Optionally specify a % drop chance per item.
# Specify item, min quantity, and max quantity of items. Optionally specify a % drop chance per item.
# Loot[0] = Berries, 5, 100%
}
CAMPAIGN_1_5
{
Map File = 1_5.tmx
# Specify item and number of items. Optionally specify a % drop chance per item.
# Specify item, min quantity, and max quantity of items. Optionally specify a % drop chance per item.
# Loot[0] = Berries, 5, 100%
}
CAMPAIGN_1_6
{
Map File = 1_6.tmx
# Specify item and number of items. Optionally specify a % drop chance per item.
# Specify item, min quantity, and max quantity of items. Optionally specify a % drop chance per item.
# Loot[0] = Berries, 5, 100%
}
CAMPAIGN_1_7
{
Map File = 1_7.tmx
# Specify item and number of items. Optionally specify a % drop chance per item.
# Specify item, min quantity, and max quantity of items. Optionally specify a % drop chance per item.
# Loot[0] = Berries, 5, 100%
}
CAMPAIGN_1_8
{
Map File = 1_8.tmx
# Specify item and number of items. Optionally specify a % drop chance per item.
# Specify item, min quantity, and max quantity of items. Optionally specify a % drop chance per item.
# Loot[0] = Berries, 5, 100%
}
}
Loading…
Cancel
Save