r/howdidtheycodeit • • Mar 12 '24
Question Pokémon Battles, specifically complicated interactions between abilities/move side effects/items/etc.
I enjoy reading books.
16
Upvotes
r/howdidtheycodeit • • Mar 12 '24
I enjoy reading books.
14
u/MyPunsSuck Mar 12 '24 edited Mar 12 '24
Smogon is open source, and I can only imagine however they do it is either identical to how GameFreak does it, or smarter. If you're not able to find what you're looking for in the code, they'd be the people to ask in their discord or whatever
sim.ts is probably the file you're looking for. Nice clean typescript
10
u/Lonchenzo Mar 12 '24
Something along lines of queuing up all the event triggers for abilities and items then sorting through the effects that the move should have after 'something I can't think of that's not just a set time period' :D
6
u/DarkAlatreon Mar 12 '24
Perhaps have every item/ability/effect have a numbered priority? Handlers could be then sorted by priority and resolved accordingly.
6
u/MaddoScientisto Mar 12 '24
Unfortunately this is not first hand knowledge but this is the best I got: I once asked some pokemon rom hackers how the battle system work and I was told that, at least in gen 3, every move is implemented through some sort of scripting engine, much like LUA for instance. I'm guessing that game freak writes scripts for moves through a scripting language which then gets compiled into code.
So this is how I would do it: I'd implement a scripting language interpreter such as LUA, then add bindings for executing the animations, calculating damage, applying it etc and then code every complex move through it, perhaps have a base config that specifies animation, buffs/debuffs/etc for every ability and use the scripts to do any advanced calculation
4
u/assassinbooyeah Mar 12 '24
I used to code a pokemon game. I thought of it like a pachinko machine where the player input (move, item) was the ball that then went through many many paths before I final output was determined. Coding the paths to output correctly was time consuming!
4
u/AgentLym Mar 12 '24
I'm no professional, but I had a thought. What about some kind of "priority consume" system, where certain items/abilities can be given priority and are always executed, then "consume" the event (or just pieces of the event). Then anything that wasn't consumed gets used by items/abilities that don't have priority.
1
u/falconfetus8 Mar 29 '24
How do you know the absorb bulb/water absorb interaction is intentional? That could very well just be an edge case they hadn't thought of. If so, then having both activate wouldn't necessarily be "wrong".
Since you're asking how I would code it, I would use the event handling approach you described, and then accept any unforeseen interactions as emergent gameplay. I would avoid designing any interactions that don't fit neatly into that event structure---eg, in my world, water absorb would not nullify absorb bulb. They'd both activate, and that would be a feature.
0
u/[deleted] Mar 12 '24
[deleted] — view deleted comment