Hello , Recently I have been struggling for 3 days to find a way on how to handle the status/efffects for my game ( i know it seems silly )
I have managed to create a state machine for my game core , like on turn start , on turn end , and another one. Now lets talk about effect/status
For Generic effects susch boosting stats for certain number of turns are eazy to handle and i dont have any problem with, but for effects/status (such as stun that should not allow you to play turn , or thorns that should reflect 20% of the damage to the opponet , BattleCry effect that increase your damage for 20%during attack, and cloack effecti that makes you untargetable) How do you handle it? i want to hardcode as mininmum as i can, i was planning to use state machine but i donât think they are enough here.
So in short , if youâd please:
Give me some ideas on state machines that could help me such as onattack and so on
how to hoandle special effect/status
before i dive into this i actually have a confession, im not using this language but anotherone called lua if you knoww it, just want to confirm, is this what turn base gamme devs mostly use?
This may not be as straightforward as it seems. Imagine a character with an attack value of 10. You apply a RaiseAttack effect that increases this value by 2 for a few turns, and a BattleCry effect that increases it by 20%.
You need to decide the order in which modifiers are calculated, because this not only affects the final value but also determines what happens when an effect ends and its modifier is removed.
For example:
If you apply RaiseAttack first and then BattleCry, the result is:
(10+2)Ă1.2=14.4 attack.
If you reverse the order, the result is:
(10Ă1.2)+2=14 attack.
Having different values for the same effects depending on the order theyâre applied can be very confusing. This becomes even more problematic if the effects come from equipping items. In that case, players might feel forced to unequip everything, then re-equip items one by one, just to find the order that gives the best result.
The same issue arises when effects are removed. In the first example, if RaiseAttack ends and you subtract 2, the calculation would give:
14.4 â 2 = 12.4 attack.
But the correct result should be 12, because the only remaining modifier is BattleCry, which gives a 20% boost to the base 10.
There are also nuances around how percentage modifiers are defined. Should they be applied to the current modified value or the original base value? For instance, a character with a speed of 10 slowed by 50% would have a speed of 5. If another effect applies an additional 50% slow, does the final speed become 0 or 2.5?
To avoid confusion, check tutorials on flat, additive, and multiplicative modifiers, and consider applying modifiers in a predefined order that has been determined by the game design.
im using another game engine
but dont worry i can translate it from c# into lua since i havee heard lua camee from c#
why asked here,well because the engine im useing its developper discussion website is not thag helpful
Right, but depending on the architecture of the engine youâre using, a lot of our suggestions might be entirely useless, such as Kurtâs suggestion of scriptable objects.
about ordering i think the player can choose it depending on what buffs he chose,when a buff is applied i was planing on storing the added/subtracted amount whether raw or percentage then when the effect ends , it will remove that stored effect with its amount being callculated laater
Itâs not just about the programming language. Scriptable Objects are a feature specific to the Unity game engine. Effectively custom assets you can write, make instances of, and author said data of.
Then plenty of other aspects we might write in a hypothetical example that will also depend on Unityâs component system.
Youâve not said what engine youâre using. All our examples would be based in how the Unity engine works and might be completely useless in whatever engine youâre using.
So as an example, every time I apply an effect I might create a new Effect instance that contains a blackboard and list of behavior trees (grouped effects like poison and burn for 3 turns). Then add this to a list of effects for that character. Iâd give each effect itâs own blackboard since the data can be specific for the effect e.g. apply poison damage for 3 turns and allow offset poison stacking. This way the graph can handle:
Trigger/End conditions: apply poison for 3 turns, next attack does double damage, next time attacked reflect damage once, on cure remove poison.
Effects: on turn apply poison damage, add green effect to character if any poison effect is active.
Conditions: there is a 50% chance of reflecting damage.
Flow / time control: thorns effect active, on attacked: play thorn particles, make attacker play hit by thorns animation, time delay, apply damage, play sound, play particles etc.
For any buffs Iâd normally apply them to multiplier and addition totals.
I think ultimately it comes down to providing the right hooks so different kinds of status effects all have what they need to work.
If you have a state machine to proceed the flow of a turn based game, then I might have a separate system that hook into procession of the turn and handles status effects; meaning all status effects are all handled by the one system rather than each character/entity separately.
And then have a system that these can be registered to, and calls the right methods at the right time.
Needless to say what the status effects do is a separate matter altogether, and you will likely need multiple other systems to make various types of effects and such work.
It depends on the game and status effects, I would argue that 95% of the âclassicâ status effects (like buffs, de-buffs, heal per turn, damage per turn, shields, etc) can be implemented as simple stat values which are changed by the status effect and implemented in some general âstat systemâ instead of adding a implementation for the status effects.
If you have more complex status effects like âdeal 30% damage but only during full moon and if you are fighting against 3+ ratsâ then itâs a different story, but a âdeal 10% more physical damageâ or âdeal 3 dmg per turnâ is a simple stat value.
well for now i only have 3 states that control the flow of the battle , but im struggling on what states should i create for the game action , for example i was thinking on using onattack,ondefense , but then i realised that this feels more like hardcoding, because imagine if the player doesnt attack but heal insteas
from what i have understood, what u suggested to me is a way to handle the functions of an effect thaat are under the player, i aam not actually struggling here, but on how to do that function, like i said do i use hooks/states or what
I think for status effects you care less about the actual stages of the turn, but instead the procession of stages throughout the turn. You care about when the turn starts or ends. You care about when a character attacks, or is attacked. And so on and so forth.
Thatâs what I mean about creating the necessary hooks, so that other systems can hook into the turn sequence and simply do their thing when the time comes around. To be literal, Iâm referring to using delegates/events that you subscribe to, or interfaces in C#'s case, that objects can implement and register themselves under.
these processions of the stage , what are they called? for this reply i will use states because i truly donât know what i should call thel
like i said i was thinking of useing the onattack, attackedplayer satetes untill i realised that i will end up hardcoing some states , for example when a player heals himself/his teamates , do i make a state out of it like the onheal, what about recieving a buff/fdebuff , thats where im stuck , if you could only please help me with this using an example of unityâs language iâd truly apperciate it ,
What Iâm saying is you care more about when the stages of a turn change, often not what the stages actually are. In some cases you will care about particular stages, but thatâs also a simple hook to create.
I donât think a state machine is a very good idea for a turn-based game to be honest. Unless youâre designing something whacky, turn-based-games have a loop of predictable stages, all of which can be abstracted as such that you donât need to design a âstateâ for every action in the game. Or for something like Baulderâs Gate 3 (aka DnD), itâs more of a queue.
Even then you still want the stages to be abstracted in such a way that you arenât coding every stage down to the minutia.
Your confusion about how to travel down this path should make it clear to you that this isnât the best approach to take.
You donât need to make states for each action. They are simply that actions. When the player heals themselves or an ally, you just need to do said action, and then provide the means for other things to be listening for that kind of event.