Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Programming RPG Special Attacks and Complex Rules  (Read 2521 times)

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Programming RPG Special Attacks and Complex Rules
« on: May 06, 2012, 07:49:58 pm »

With the semester winding to a close, a friend and I are planning to use the summer to build up our game-design portfolios a bit.  We have a basic theme, setting, mechanics, etc, though much of it is still being discussed and fleshed out, and no code's been written yet.  However, in our most recent discussion we touched on one of the problems we may run into.  Namely, special attacks and complex rules.  Over the course of the game, the player will control a variety of different creatures, and between his/her own powers, and those of the varied creatures, we will need to model an equally wide variety of special attacks, and potentially complex rules.

Where we've run into trouble is determining how to do this.  Simple things like damage ranges/types, armor, and the like are simple enough - even attribute damaging attacks could be written simply by adding another damage type or so on.  But for effects lasting over several turns, or overlapping effects, or effects which depend on the type/race/etc of the creatures involved, etc would be far, far more complicated to model in such a static way.  The way I see it, we have a few options for these more complex/dynamic parts:

  • Hard-code the specials/rules
  • Define the specials/rules with an external scripting language (I.E. Lua, python, etc)
  • Model these rules with predicates

The first option would work, and would probably be the simplest to write initially, but maintaining and expanding would be a pain, and would result in rather deep nests of ifs/switches/etc.  The second might work as well, but as we're working in C#, and hopefully deploying to the Xbox, we would have to find one which compiled with the rest of the code, or ran on the Xbox as well as a PC.  Additionally, figuring out which scripts to attach and when, and in what order could also be rather tricky.

The third option I like the sound of, but to be honest I have no idea how to even begin to implement it in C#  There was an interesting discussion on this particular method over in the RPGCodex forums, but they are, if I understand from my skimming, discussing the implementation in LISP or a similar language.

Also considering a combination of the third and second - that is, a list of conditions (I.E. if attack deals fire damage, defender is a plant-like creature) and then a script to go with them (dmg*=2), though I'm not quite sure how I'd want to implement this one either....

Any thoughts or input would be very welcome.
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming RPG Special Attacks and Complex Rules
« Reply #1 on: May 06, 2012, 10:48:44 pm »

Hmm, I would go with 1.
Not that I'm an experienced programmer or stuff, but using switch/case (unless C# doesn't have it) it should be pretty reasonable to hard-code a bunch of templates/qualities/whatever and ... do stuff.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

malloc

  • Bay Watcher
    • View Profile
Re: Programming RPG Special Attacks and Complex Rules
« Reply #2 on: May 07, 2012, 03:57:36 am »

From what I can read, you have obviously still not determined anything significant when it comes to game mechanics.

First determine how flexible you want the system to be. If you are going to have 10 different types, then hard coding it would work just fine.

IF you are going for a more flexible approach, then adding some system for dynamically adding types would probably be a good idea. How you would implement it? Well determine some format you want your type to be stored in. This can be done in a variety of ways. Simple text files could work. If you want to make it even more advanced, you could store it in some XML format, or even binary files, if you are good enough programmers.

An external scripting solution would probably make for the most flexible system. But, you have to keep in mind that adding a scripting language is not easy, and it will add a layer of complexity to development as relevant functions will need to be exposed to the scripting API and scripts will have to be written.
Determining which scripts to execute when will not be the hardest problem with this approach. But rather implementing it in a good way and finding a good workflow.

Lastly, I would really suggest you tried making something a little easier than a fully fledged RPG. You don't seem to have a lot of practical programming experience. That alone could potentially keep you from finishing anything. (Remember I might be reading a bit into things, as I have no idea how good you guys even are with programming)

Either way, before thinking to much about implementation. Go back to the drawing board and figure out exactly what you want in the game, and how exactly you want the mechanics to be. That way you should have a much easier time figuring out how to implement your mechanics.
Logged

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Re: Programming RPG Special Attacks and Complex Rules
« Reply #3 on: May 07, 2012, 08:31:41 am »

@Skyrunner - True, it would work, just not sure I like the messy and straightforward option :P

@Malloc - You're right on the first count - at this point I'm just tossing ideas around, and figured I'd post and get some input.  But while the type and damage is quite easy, and in fact I've fleshed out the bare-bones combat in python as a mock-up already, I'm more concerned about specific bonuses beyond those things which are common to all creatures.  Say, a "big" creature might get a damage bonus and accuracy debuff when attacking a "small" creature, even though size isn't directly implemented - or something specific to interactions between one specific creature and another, etc.

I've actually already designed a simple language for such purposes in the past, and implemented the parser in both Python and C# (though the C# version is a bit behind, and may need a bit of updating), and I've done saving/loading of both save-data and game data from all the mentioned formats at least once, so I'm not too worried about that yet.  Mostly just trying to find a high-level conceptual way to manage all the rules and exceptions for a complex combat system.

The scripting would work, and I implemented LUA scripting for that purpose in a Rogue-like I built some time ago (still haven't posted it here... really should do that later), and it's not too difficult in C#, given all the available wrappers.  Main worry there is compatibility with the Xbox, haven't honestly looked into that yet, been rather busy with finals between brain-storming sessions xP

I do very much appreciate the advice - and I've given that same advice several times myself xP  In this particular case though, we both have several years of practical experience, and multiple smaller game project under our belts.   I know this one seems vague, and to be honest, it is, still brain-storming stage.

That is a good point though, I'll see what I can do to nail down some more of the specifics, and get back on that....  Thanks!
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: Programming RPG Special Attacks and Complex Rules
« Reply #4 on: May 07, 2012, 02:46:47 pm »

There's no implementation of Lua that'll work for the Xbox 360 as far as I know. They all wrap it with C++/CLI so can't be used with XNA -_-
« Last Edit: May 07, 2012, 02:51:48 pm by MorleyDev »
Logged

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Re: Programming RPG Special Attacks and Complex Rules
« Reply #5 on: May 07, 2012, 08:28:37 pm »

That is a pity... I think I may look around and see if there are and scripting languages that work well on both PC and Xbox, if only to satisfy my curiosity :P

[EDIT]: There really isn't much to work with there xP  Thinking I may end up modeling it as a Rule class with two delegates - one predicate (takes in, say, attack and defender, returns true if the rule applies false if it doesn't) and one with no return that executes the effect of the rule... this would allow them to be easily edited in a level/rule/creature editor if such becomes worth the time it would take to build, and even if I don't, it lets me work with compiled C# without having to worry about Xbox compatibility and the like, still reserving all the power of a "scripting" language....
« Last Edit: May 07, 2012, 09:49:19 pm by timmeh »
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: Programming RPG Special Attacks and Complex Rules
« Reply #6 on: May 08, 2012, 01:06:59 am »

you might be able to make a set of rules using enums in C# with the [flags] statement before the beginning of the enum declaration, and using ENUM_CONST = 0x## for the members. Have a enum of weaknesses:
Code: [Select]
[flags]
enum WEAKNESSES{
   FIRE = 0x01,
   WATER = 0x02,
   WIND = 0x04,
   EARTH = 0x08,
   .
   .
   .
   ETC = 0x##;
}
with that you could have something in the entity information a list of weaknesses or just a value that represents a unique list of weaknesses. And example of the latter would be something along the lines of Weaknesses = 15 which would represent the first 4 weakness types all at once, 0x01 + 0x02 + 0x04 + 0x08 = 0x15 = 15. It would be a simple arithmetic way of representing the weaknesses available to the entity so long as the bit flags are created in a way that no combination can have the same value when put together. For this it is generally best to keep to a base 2 standard: 0 = none, 1, 2, 4, 8, 16, 32, 64, etc.

This may in some ways restrict the number of individual weakness or other damage affecting types that an entity may inherit but it might be a good way to quickly and easily evaluate that an entity has a specific set of stats.
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Microcline

  • Bay Watcher
    • View Profile
Re: Programming RPG Special Attacks and Complex Rules
« Reply #7 on: May 08, 2012, 10:27:16 pm »

I tend to like hardcoding the engine rules and then loading the content from XML files.  For instance, you might have an XML file containing the name of a monster, its hit points and other stats, a list of races/types it counts as, a list of elemental affinities and their magnitudes (i.e. FIRE 2.0 for double damage from fire and ICE -.5 for absorbing half damage from ice), and a list of attack names. 

Attacks would be loaded from attack XML files and would contain the name of the attack, a value for how it is applied, i.e. ALLENEMIES, ALLALLIES, SINGLETARGET, RANDOMTARGET..., a hit rate, a base damage value, a list of element types, and a list of special effect structures (which would contain a status effect name, a magnitude value, and an application rate).  All of the XML files would be loaded into dictionaries at startup.

How these tags are handled would be hardcoded, so things like checking whether the target is appropriate or applying the damage multiplier would be in the C# battle engine.  Having the battle engine rely heavily on external scripting would likely be unnecessary unless you really need to include modding.

If you're doing an RPG you'll probably want to make an editor to pump out XML files for things like monsters, attacks, maps, and items.


Ultimately, the best option is whatever you can get working fastest and is dependent on what you're trying to make.  The more rules you have, and the more complex those rules are, the greater benefit you gain from using a predicate logic resolver instead of a mess of nested conditionals.  I wouldn't think it worthwhile for most cRPGs (both eastern and western), but if you were trying to make an adaptation of a PnP RPG or wargame I could see how it would be helpful.
Logged

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Re: Programming RPG Special Attacks and Complex Rules
« Reply #8 on: July 30, 2012, 08:43:51 pm »

My thanks to all who contributed.  Ended up going with a combination - type weaknesses and other standard features are simply hard-coded in a specific order, while more complicated attacks/abilities can use a predicate system for non-standard effects.
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.