samspade
Member
Not sure if this should go here or in the programming forum.
In rogue likes you often have something like a relic (as in Slay the Spire) or passive item (BOI) mods (Nova Drift) that modifies core elements of the game, reduce all damage, increase the rewards gained, give special attributes to things and so on. What is the best way to structure this in code?
The most straight forward way is what I'm currently using. Keep a list of mods gained, have a way of checking that list, and if one exists provide different rules. A simple example:
It's simple, but this solution really fractures the code. The effect of the relic is in an entirely different place and for each relic will be somewhere else. Nothing will be centralized and if you add or change them you'll have to remember where they're located (in theory not super bad since you'd be able to search the function has_relic) but it seems inelegant.
But I can't really think of a solution that isn't more complicated in other ways.
In rogue likes you often have something like a relic (as in Slay the Spire) or passive item (BOI) mods (Nova Drift) that modifies core elements of the game, reduce all damage, increase the rewards gained, give special attributes to things and so on. What is the best way to structure this in code?
The most straight forward way is what I'm currently using. Keep a list of mods gained, have a way of checking that list, and if one exists provide different rules. A simple example:
GML:
function add_scrap(_value) {
if (has_relic("Scrap Relic")) {
_value *= 2;
}
with (run_manager) {
scrap_amount += _value;
}
}
But I can't really think of a solution that isn't more complicated in other ways.