I am currently trying to make something a lit similar to a 'gatcha' system for a project which I am working on, which is being built in VXAce. To be clear, the project is not a game as such, but a tool to help a DM with an adventure using maps and such made in VX Ace.
Right now, I've managed to work out how to make a function which works for a single wheel, where I input all the details into the function and call that function when the wheel is meant to be rolled, but I want to condense the code so that I don't have to write a function for every single wheel type, plus I want to take into account how some wheels may work differently.
The intent I have is for there to be four different kinds of wheels: one for 'normal' chest and ticket rewards where it rolls once uses weights, and you get the reward (unless you have a reroll ticket, in which case you can spend it to re-roll, unless the reward is considered a 'jackpot'), which is the function I currently have made; one which is similar but with no weights, just a list of items which one would be randomly chosen, but a re-roll can be done with them; a variant of the second where instead of the re-roll changing what's obtained, it adds to it, for the case of when rolling for hint types; and finally a roll which chooses three random options from a list, from which the player would choose one to take.
Below is the code I currently use which grants a ticket based on which tier is rolled, but I want to be able to convert this into code where all I need to give are identifiers for each reward, a weight for the reward, the message for each reward, the item in-game to give (using -1 or nil as a value to signify 'no item is given in-game') and if the reward is a jackpot and thus can't be rerolled:
In this case, the array I would want to use as a constant defined in a material module (which for now I'm calling "wheel_data") which the function would recieve as the table to use would be like this:
Right now, I've managed to work out how to make a function which works for a single wheel, where I input all the details into the function and call that function when the wheel is meant to be rolled, but I want to condense the code so that I don't have to write a function for every single wheel type, plus I want to take into account how some wheels may work differently.
The intent I have is for there to be four different kinds of wheels: one for 'normal' chest and ticket rewards where it rolls once uses weights, and you get the reward (unless you have a reroll ticket, in which case you can spend it to re-roll, unless the reward is considered a 'jackpot'), which is the function I currently have made; one which is similar but with no weights, just a list of items which one would be randomly chosen, but a re-roll can be done with them; a variant of the second where instead of the re-roll changing what's obtained, it adds to it, for the case of when rolling for hint types; and finally a roll which chooses three random options from a list, from which the player would choose one to take.
Below is the code I currently use which grants a ticket based on which tier is rolled, but I want to be able to convert this into code where all I need to give are identifiers for each reward, a weight for the reward, the message for each reward, the item in-game to give (using -1 or nil as a value to signify 'no item is given in-game') and if the reward is a jackpot and thus can't be rerolled:
Ruby:
def wheel_teamticket()
results = [:RU, :UU, :OU]
weights = [250, 25, 1]
total_weight = weights.inject(0, :+)
selected_tier = nil
catch (:reward) {
loop {
random_roll = rand(total_weight)
current_weight = 0
done = 0
weights.each_with_index do |weight, index|
current_weight += weight
if random_roll < current_weight
selected_tier = results[index]
break
end
end
case selected_tier #For this, we assume we add a ticket to the user of the type specified
when :RU
$game_message.add("You won a RU Ticket!")
when :UU
$game_message.add("Lucky!\nYou won an UU Ticket!")
when :OU
$game_message.add("JACKPOT!\nYou won an OU Ticket!")
throw :reward
end
#Item 12 is the current item for the reroll ticket, so this checks if you have one,
#and if so, allows you to reroll
if not ($game_party.has_item?($data_items[12])) then throw :reward end
$game_message.choices.push("Yes")
$game_message.choices.push("No")
$game_message.choice_cancel_type = 1
$game_message.choice_proc = Proc.new { |n|
case n
when 0
$game_party.lose_item($data_items[12], 1)
when 1
done = 1
end
}
$game_message.add("Do you want to use a Reroll Ticket to reroll?\nYou will forfeit your current reward if you do.")
Fiber.yield while $game_message.busy?
if (done == 1) then throw :reward end
}
}
#The rewards which are given in the 'game' would be given here. Other stuff would be noted
#by the DM on a character sheet.
case selected_tier
when :RU
$game_party.gain_item($data_items[3], 1)
when :UU
$game_party.gain_item($data_items[4], 1)
when :OU
$game_party.gain_item($data_items[5], 1)
end
end
In this case, the array I would want to use as a constant defined in a material module (which for now I'm calling "wheel_data") which the function would recieve as the table to use would be like this:
Ruby:
COMMONTEAMTABLE = [
["RU", 250, "You've won a RU Ticket!", 3, false],
["UU", 25, "Lucky!\nYou've won am UU Ticket!", 4, false],
["OU", 1, "JACKPOT!\nYou've won am OU Ticket!", 5, true]
]