Item Rolling Function for Heart of Stone
This C-like function handles the rolling of the 'Heart of Stone' item in a game based on various difficulty settings and modifiers. It includes automatic variable declarations and sets calculated chances for item drops, adjusting based on whether amplification is enabled for normal difficulty.unknown
c_cpp
9 months ago
4.7 kB
11
Indexable
void gf_ItemRollHeartofStone () {
// Automatic Variable Declarations
// Implementation
// Variable Declaration
int lv_random; // Holds the random roll result
text lv_RNG; // Used to display the random number as text (for testing/debug purposes)
fixed lv_amplificationModifier; // Modifier based on difficulty and amplification options
fixed lv_chance; // Calculated chance range for rolling the item drop
// Set the amplification modifier based on game difficulty and whether amplification is enabled
if ((gv_DifficultyNormal) && (gv_amplifyNormal)) {
// On Normal difficulty with amplification enabled, increase the chance
lv_amplificationModifier = 0.8;
}
else if (gv_DifficultyNormal) {
// On Normal difficulty without amplification, use the standard chance
lv_amplificationModifier = 1.0;
}
else {
// On other difficulties (likely harder ones), lower the chance
lv_amplificationModifier = 1.35;
}
// Determine the drop chance based on the unit's attributes (heroic, structure, or other)
if (UnitTypeTestAttribute(UnitGetType(EventUnit()), c_unitAttributeHeroic) == true) {
// For a heroic unit, double the drop chance
lv_chance = (Round((10000.0) * lv_amplificationModifier) * 0.5);
// Generate a random integer between 1 and the calculated chance
lv_random = RandomInt(1, FixedToInt(lv_chance));
}
else if (UnitTypeTestAttribute(UnitGetType(EventUnit()), c_unitAttributeStructure) == true) {
// For a structure, decrease the drop chance by doubling the calculated value
lv_chance = (Round((10000.0) * lv_amplificationModifier) * 2.0);
// Generate a random integer between 1 and the calculated chance
lv_random = RandomInt(1, FixedToInt(lv_chance));
}
else {
// For all other unit types, use the base chance.
lv_chance = (Round((10000.0) * lv_amplificationModifier));
// Generate a random integer between 1 and the calculated chance
lv_random = RandomInt(1, FixedToInt(lv_chance));
}
// If running on a test map, output debug messages to show the roll and chance details.
if ((GameIsTestMap(false) == true)) {
// Convert the random roll result to text
lv_RNG = IntToText(lv_random);
// Set up tokens to build a message that displays the roll and chance range
TextExpressionSetToken("DOCSTR_RNG", "A", StringToText("Heart of Stone rolled a "));
TextExpressionSetToken("DOCSTR_RNG", "B", lv_RNG);
TextExpressionSetToken("DOCSTR_RNG", "C", StringToText(" out of "));
TextExpressionSetToken("DOCSTR_RNG", "D", StringToText(FixedToString(lv_chance, 2)));
// Display the assembled message
UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, TextExpressionAssemble("DOCSTR_RNG"));
// Display an additional message indicating which unit type was processed (for debugging)
UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, StringToText(UnitGetType(EventUnit()) + " was the puss that got murdered."));
}
else {
// In normal gameplay, if the random roll is less than or equal to 10, the drop is successful
if ((lv_random <= 10)) {
// Display a congratulatory message to all players
UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, (PlayerName(UnitGetOwner(libNtve_gf_KillingUnit())) + StringToText(" just found a Heart of Stone!")));
// Create the "Heart of Stone" item in the hero player's inventory
UnitInventoryCreate(gv_heroPlayer[UnitGetOwner(libNtve_gf_KillingUnit())], "HeartofStone");
// Increment the count of the value of the array assigned to Heart of Stone in the global variable gv_legendaryItemPlayers for the player
gv_legendaryItemPlayer[217][UnitGetOwner(libNtve_gf_KillingUnit())] = (gv_legendaryItemPlayer[217][UnitGetOwner(libNtve_gf_KillingUnit())] + 1);
// Load the player's bank data
BankLoad("tssbank", UnitGetOwner(libNtve_gf_KillingUnit()));
BankOptionSet(BankLastCreated(), c_bankOptionSignature, true);
// Update the bank with the new Heart of Stone count for the player
BankValueSetFromInt(BankLastCreated(), "tssplayers", "tssitem217", gv_legendaryItemPlayer[217][UnitGetOwner(libNtve_gf_KillingUnit())]);
// Save the updated bank data
BankSave(BankLastCreated());
}
}
}Editor is loading...
Leave a Comment