-
Notifications
You must be signed in to change notification settings - Fork 40
feat: New loot table concept #890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,113 @@ | ||||||
| function find_loot(loot_data={}, loot_value = 200){ | ||||||
| var _possible_loots = {}; | ||||||
| var _total_lootables = 0; | ||||||
| var _all_loot_names = []; | ||||||
|
|
||||||
| var _loot_tags = struct_exists(loot_data ,"loot_tags") ? loot_data.loot_tags : []; | ||||||
|
|
||||||
| var _exclusives = struct_exists(loot_data ,"exclusives") ? loot_data.exclusives : false; | ||||||
|
|
||||||
| var _mults = struct_exists(loot_data ,"multipliers") ? loot_data.multipliers : false; | ||||||
|
|
||||||
| var _excludes = struct_exists(loot_data ,"excludes") ? loot_data.excludes : false; | ||||||
|
|
||||||
| var _weps = global.weapons; | ||||||
| var _armour = global.gear.armour; | ||||||
| var _mobi = global.gear.mobility; | ||||||
|
|
||||||
| var _all_items_table = array_join(struct_get_names(_weps), struct_get_names(_armour),struct_get_names(_mobi)); | ||||||
|
|
||||||
| for (var i=0;i<array_length(_all_items_table);i++){ | ||||||
| var _item = gear_weapon_data(,_all_items_table[i]); | ||||||
| if (_item == false){ | ||||||
| continue; | ||||||
| } | ||||||
| if (_exclusives != false){ | ||||||
| var _include = false; | ||||||
| for (var e = 0; e<array_length(_exclusives); e++){ | ||||||
| if (array_contains(_item.tags, _exclusives[e])){ | ||||||
| _include = true; | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
| if (!_include){ | ||||||
| continue; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if (_excludes != false){ | ||||||
| var _include = true; | ||||||
| for (var e =0;e<array_length(_excludes);e++){ | ||||||
| if (array_contains(_item.tags, _excludes[e])){ | ||||||
| _include = false; | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
| if (!_include){ | ||||||
| continue; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| var _loot_value = _item.loot.base; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential null reference accessing loot.base. If the item lacks a loot property, this will fail. Add defensive checks. + if (!struct_exists(_item, "loot") || !struct_exists(_item.loot, "base")) continue;
var _loot_value = _item.loot.base;
🤖 Prompt for AI Agents |
||||||
| for (var t = 0;t<array_length(_loot_tags);t++){ | ||||||
| if (struct_exists(_item.loot, _loot_tags[t])){ | ||||||
| if (_item.loot[$ _loot_tags[t]] > _loot_value){ | ||||||
| _loot_value = _item.loot[$ _loot_tags[t]]; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| var _loot_val = _loot_tags | ||||||
|
|
||||||
| if (_mults != false){ | ||||||
| var _mult_names = struct_get_names(_mults); | ||||||
| for (var e =0;e<array_length(_mult_names);e++){ | ||||||
| if (array_contains(_item.tags, _mult_names[e])){ | ||||||
| var _mult = _mults[$ _mult_names[e]]; | ||||||
| _loot_value *= _mult; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| _possible_loots[$_item.name] = [_total_lootables, _total_lootables+_loot_value]; | ||||||
| _total_lootables+=_loot_value; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| var _all_loot_names = struct_get_names(_possible_loots); | ||||||
|
|
||||||
| if (!array_length(_all_loot_names)){ | ||||||
| return {}; | ||||||
| } | ||||||
| var _final_loot = {}; | ||||||
| var _chosen_loot_val = 0 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing semicolon violates sacred syntax. The Omnissiah demands proper punctuation. - var _chosen_loot_val = 0
+ var _chosen_loot_val = 0;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| while (_chosen_loot_val < loot_value){ | ||||||
| var _new_loot = irandom(_total_lootables-1); | ||||||
| for (var i=0;i<array_length(_all_loot_names);i++){ | ||||||
| var _lootn = _all_loot_names[i]; | ||||||
| var _specific_loot_data = _possible_loots[$ _lootn]; | ||||||
| if (_new_loot>= _specific_loot_data[0] && _new_loot<_specific_loot_data[1]){ | ||||||
| var _chosen_piece = _lootn; | ||||||
| var _loot_val = max(100-(_specific_loot_data[1] - _specific_loot_data[0]),1); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flawed loot value calculation logic. The calculation - var _loot_val = max(100-(_specific_loot_data[1] - _specific_loot_data[0]),1);
+ var _loot_val = _specific_loot_data[1] - _specific_loot_data[0];📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| if (!struct_exists(_final_loot, _chosen_piece)){ | ||||||
| _final_loot[$ _chosen_piece] = 1; | ||||||
| } else { | ||||||
| _final_loot[$ _chosen_piece]++; | ||||||
| } | ||||||
| _chosen_loot_val += _loot_val; | ||||||
|
|
||||||
| var _add_more = irandom(2); | ||||||
| while (_add_more == 0 && _chosen_loot_val<loot_value){ | ||||||
| _final_loot[$ _chosen_piece]++; | ||||||
| _chosen_loot_val += _loot_val; | ||||||
| _add_more = irandom(2); | ||||||
| } | ||||||
|
|
||||||
| break; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return _final_loot; | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning: Loot value override cascade detected.
Your machine logic contains multiple separate if-else chains that can overwrite previous loot.base values. For example, an item with tags ["heavy_ranged", "terminator"] will have its loot.base set to 75, then overwritten to 10.
Consider consolidating into a single priority-based logic chain:
📝 Committable suggestion
🤖 Prompt for AI Agents