issues with item generation
This commit is contained in:
@@ -58,7 +58,7 @@ namespace game::resource::xml
|
||||
Rarity rarity{};
|
||||
|
||||
query_string_attribute(child, "Name", &rarity.name);
|
||||
child->QueryFloatAttribute("Chance", &rarity.chance);
|
||||
child->QueryFloatAttribute("Weight", &rarity.weight);
|
||||
query_bool_attribute(child, "IsHidden", &rarity.isHidden);
|
||||
|
||||
query_sound(child, "Sound", archive, soundRootPath, rarity.sound);
|
||||
@@ -183,11 +183,7 @@ namespace game::resource::xml
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)rarities.size(); i++)
|
||||
{
|
||||
rarityIDsSortedByChance.emplace_back(i);
|
||||
}
|
||||
std::stable_sort(rarityIDsSortedByChance.begin(), rarityIDsSortedByChance.end(),
|
||||
[&](int a, int b) { return rarities[a].chance > rarities[b].chance; });
|
||||
rarityIDs.emplace_back(i);
|
||||
|
||||
isValid = true;
|
||||
logger.info(std::format("Initialized item schema: {}", path.c_str()));
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace game::resource::xml
|
||||
struct Rarity
|
||||
{
|
||||
std::string name{UNDEFINED};
|
||||
float chance{};
|
||||
float weight{};
|
||||
bool isHidden{};
|
||||
Audio sound{};
|
||||
};
|
||||
@@ -87,7 +87,7 @@ namespace game::resource::xml
|
||||
std::vector<Entry> items{};
|
||||
std::vector<Anm2> anm2s{};
|
||||
|
||||
std::vector<int> rarityIDsSortedByChance{};
|
||||
std::vector<int> rarityIDs{};
|
||||
std::unordered_map<int, Pool> pools{};
|
||||
Pool skillCheckRewardItemPool{};
|
||||
|
||||
|
||||
@@ -9,13 +9,27 @@ namespace game::state::play::item
|
||||
int Reward::random_item_get(const resource::xml::Item& itemSchema, float chanceBonus)
|
||||
{
|
||||
const resource::xml::Item::Pool* pool{};
|
||||
auto totalWeight = 0.0f;
|
||||
|
||||
for (auto& id : itemSchema.rarityIDsSortedByChance)
|
||||
for (auto& id : itemSchema.rarityIDs)
|
||||
{
|
||||
auto& rarity = itemSchema.rarities[id];
|
||||
if (rarity.chance <= 0.0f) continue;
|
||||
if (rarity.weight <= 0.0f) continue;
|
||||
totalWeight += rarity.weight * chanceBonus;
|
||||
}
|
||||
|
||||
if (math::random_percent_roll(rarity.chance * chanceBonus))
|
||||
if (totalWeight <= 0.0f) return INVALID_ID;
|
||||
|
||||
auto roll = math::random_roll(totalWeight);
|
||||
|
||||
for (auto& id : itemSchema.rarityIDs)
|
||||
{
|
||||
auto& rarity = itemSchema.rarities[id];
|
||||
auto weight = rarity.weight * chanceBonus;
|
||||
if (weight <= 0.0f) continue;
|
||||
|
||||
roll -= weight;
|
||||
if (roll <= 0.0f)
|
||||
{
|
||||
pool = &itemSchema.pools.at(id);
|
||||
rarity.sound.play();
|
||||
@@ -40,8 +54,6 @@ namespace game::state::play::item
|
||||
const resource::xml::Item& itemSchema, const ImVec4& bounds, float rewardChance,
|
||||
float rewardRollCount, menu::ItemEffectManager::Mode mode)
|
||||
{
|
||||
if (!math::random_percent_roll(rewardChance)) return 0;
|
||||
|
||||
auto rollCountWhole = std::max(0, (int)std::floor(rewardRollCount));
|
||||
auto rollCountFraction = std::max(0.0f, rewardRollCount - (float)rollCountWhole);
|
||||
auto rollCount = rollCountWhole + (math::random_percent_roll(rollCountFraction) ? 1 : 0);
|
||||
@@ -49,6 +61,8 @@ namespace game::state::play::item
|
||||
|
||||
for (int i = 0; i < rollCount; i++)
|
||||
{
|
||||
if (!math::random_percent_roll(rewardChance)) continue;
|
||||
|
||||
auto itemID = random_item_get(itemSchema);
|
||||
if (itemID == INVALID_ID) continue;
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ namespace game::state::play::menu
|
||||
{
|
||||
case MENU:
|
||||
game_menu_draw(ORBIT);
|
||||
//game_menu_draw(DUNGEON);
|
||||
game_menu_draw(DUNGEON);
|
||||
game_menu_draw(SKILL_CHECK);
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user