The source project of this merge request has been removed.
Item Roulette library for Lua (itemroulette getter/setter, item roulette functions)
Summary
This branch exposes the item roulette system to Lua. It changes the following:
- Implements
itemlist_tas a member toitemroulette_t, acting as the type holding the item reel array, to better expose it as a metatable type to Lua. - Allows
itemroulettefromplayer_tto be get (not set) as well as get/set its members (exceptitemlistwhich cannot be set, see below) through Lua. - Refactored some code to create new methods (namely
K_CreateAndShuffleItemReel). - Exposes the following functions:
-
k_kart.hK_GetShieldFromItem(kartitems_t item)K_ItemResultToType(kartitems_t item)K_ItemResultToAmount(kartitems_t item)K_GetItemCooldown(kartitems_t item)K_SetItemCooldown(kartitems_t item, tic_t time)K_TimeAttackRules()K_CapsuleTimeAttackRules()
-
k_boss.hK_CheckBossIntro()
-
k_roulette.hK_ItemEnabled(kartitems_t item)K_ItemSingularity(kartitems_t item)K_GetBotItemPriority(kartitems_t item)K_AddItemToReel(player_t player/itemroulette_t roulette, [kartitems_t item/table items])K_PushToRouletteItemList(player_t player/itemroulette_t roulette, [kartitems_t item/table items])K_StartItemRoulette(player_t player, [boolean ringbox])K_StartEggmanRoulette(player_t player)K_StopRoulette(player_t player)K_KartGetItemResult(player_t player, kartitems_t item)K_GetItemRouletteDistance(player_t player, int numplayers)K_FindUseodds(player_t player)K_CreateAndShuffleItemReel(player_t player/itemroulette_t roulette, [boolean freeplay])K_ForcedSPB(player_t player)K_DenyShieldOdds(kartitems_t item)K_GetRouletteOffset(player_t player, [fixed_t renderDelta], [fixed_t fudge])K_GetSlotOffset(player_t player, [fixed_t renderDelta], [fixed_t fudge])K_CalculateRouletteSpeed(player_t player)K_ScaleItemDistance(int distance, int numplayers)K_ItemOddsScale(int playercount)
-
k_grandprix.hK_CanChangeRules()
-
- Creates the following Lua-only functions to interact with the roulette's item reel (as opposed to interacting with the table directly, providing encapsulation):
K_WipeItemsInReel(player_t player/itemroulette_t roulette)K_SetItemInReelByIndex(player_t player/itemroulette_t roulette, size_t index, kartitems_t item)K_AddItemToReelByIndex(player_t player/itemroulette_t roulette, size_t index, kartitems_t item, [boolean addrings])K_RemoveItemFromReelByIndex(player_t player/itemroulette_t roulette, size_t index)
- Creates the following Lua hooks to interact with how the item roulette populates the reel with items:
-
PreFillItemRoulette, function(player_t player, itemroulette_t roulette, boolean ringbox): Allows Lua to interact with the item roulette reel before any special conditions, but after speed calculations. Return true to completely override it, return false to allow it to continue. -
FillItemRoulette,function(player_t player, itemroulette_t roulette): Allows Lua to interact with the item roulette reel under normal circumstances (no special conditions met).
-
- Exposes
kartslotmachine_tvalues:KSM_BAR,KSM_DOUBLEBAR,KSM_TRIPLEBAR,KSM_RING,KSM_SEVEN,KSM_JACKPOT,KSM__MAX. - Exposes
itemflags_tvalues:IF_USERINGS,IF_ITEMOUT,IF_EGGMANOUT,IF_HOLDREADY. - Makes the item reel's contents dynamically allocated by default, allowing up to technically infinite items in the item reel.
Testing
The testing environment is ringracers_itemRouletteLib.exe -console -skipintro -warp RR_TESTRUN +addfile itemroulette.lua.
I used a script, itemroulette.lua, to test nearly all additions. Namely:
- Prints all exposed
KSM_andIF_values in the console. - Has a HUD hook that displays the values of all of the
itemroulette_tvalues, including items in the item reel if active, the values fromK_ScaleItemDistance,K_ItemOddsScale,K_GetRouletteOffsetandK_GetSlotOffset. - Has a command,
setroulettevalue, that allows theitemroulette_tsetter to be tested and its members changed to any value. - Has console variables,
enableprefillitemroulette,prefillroulettetype, andenablefillitemroulette, that allows you to play with the hook's roulette outcomes and test various functions.- If
prefillroulettetypeis set from 1 to 4 (andenableprefillitemrouletteis On), Ring Boxes will give you an item reel with a guaranteed Jackpot. - If
prefillroulettetypeis set to 1, Item Boxes will use the same functions used from the regular roulette code with no special outcomes to recreate that type of roulette. - If
prefillroulettetypeis set to 2, Item Boxes will provide you with this item reel:KITEM_SNEAKER, KITEM_ORBINAUT, KITEM_SPB, KITEM_GACHABOM, KRITEM_TRIPLESNEAKER. This tests adding items to the roulette using both the table and integer parameter types using K_AddItemToReel. - If
prefillroulettetypeis set to 3, ditto, but uses K_PushToRouletteItemList instead. - If
prefillroulettetypeis set to 4, the roulette is similar to 3, but will useK_ItemEnabledto check if the item should be in the reel. For the SPB, it will check if it is not under any cooldown usingK_GetItemCooldown. Afterwards, it will give the SPB a 4 second cooldown usingK_SetItemCooldown. It will also print some values related toK_ItemSingularity,K_GetBotItemPriority, andK_GetShieldFromItem. - If
enableprefillitemrouletteis Off, andenablefillitemrouletteis On, then it will use the functionsK_WipeItemsInReel,K_PushToRouletteItemList,K_SetItemInReelByIndex,K_AddItemToReelToIndexandK_RemoveItemFromReelToIndexto test those functions, specifically bounds checking. - If
prefillroulettetypeis set to 5, 1500 items will be added to the roulette (30 items * 50 iterations) to test dynamic allocation.
- If
-
userouletteasparamtoggles if the getter/setter debug HUD should be enabled, defaultOn. -
userouletteasparamtoggles if it uses the hooks'itemroulette_tobject instead of theplayer_tobject for all applicable function calls, defaultOff. - Various other commands exist to test miscellaneous functions:
-
myitems: If a roulette is ongoing, it will print on the console the items that reside on the item reel using theitemlist_tgetters. -
startroulette: Starts an item roulette usingK_StartItemRoulette.startroulette truewill start a Slot Reel instead of an Item Reel. -
starteggman: Starts an item roulette rigged by an Eggman Monitor usingK_StartEggmanRoulette. -
stoproulette: Stops an item roulette if one is ongoing usingK_StopRoulette. -
timeattacktest: Prints in console the results of theK_TimeAttackRulesandK_CapsuleTimeAttackRulesfunctions. -
testitemhelpers: Requires an item roulette index argument - it will use the methodsK_ItemResultToAmountandK_ItemResultToType` to print what the player would be getting out of the item roulette reel result. -
undefinedbehaviourtest: Tests an underfined behaviour bug on itemlist local variables not preserving between map changes. -
kartgetitemresult: UsesK_KartGetItemResultto give the player the item result from the arguemnt passed (a kartitems_t index). -
calcroulettespeed: If the roulette is ongoing,K_CalculateRouletteSpeedis used to recalculate the roulette speed. -
bossintro: Prints if a boss intro is ongoing usingK_CheckBossIntro. -
canchangerules: Prints if the rules can be changed (specific to Grand Prix) usingK_CanChangeRules.
-
Changelog
- Exposed almost all of the item roulette system to Lua, as well as functions and methods related to it.
Edited by JugadorXEI