Below are some thoughts I had when working on a MUD server a while ago. You may not agree with everything below naturally, but at least consider the various aspects of combat / effects described below. They may give you ideas that will change the way you develop your MUD server. It is much easier to design things like this in from the start, then writing a combat system, and then going back and rewriting it because you hadn't allowed for something like casting time, or effects that occur over time.
Fighting, spells, potions, scrolls – all actions?
After writing some fighting code I have started to wonder whether fights, spell-casting etc. are not all part of some generic “action you take”.
For a start, it seems that fighting and casting damaging spells are variants of the same thing:
- They require knowledge (eg. swordsmanship, or the particular spell)
- They consume something (eg. arrows, mana, damage to sword)
- They take time to do
- The may or may not succeed (eg. the arrow may miss)
- The target might resist it (eg. armour, spell resistance)
Then we consider that a beneficial spell (eg. heal) is actually very similar to a damage spell (eg. fireball), except that one raises HP whilst the other lowers them.
Then you have things like scrolls, potions, wands, traps etc. which effectively do a similar thing.
Also, walking around is effectively much the same:
- You require something (to be awake)
- You consume something (movement points)
- It takes time to do (depending on the terrain and room size)
- It may not succeed (because of a locked door)
- It results in a status change (you end up in a new room)
Now it seems time-consuming and inconsistent to have hundreds of lines of code in the server which all do similar things:
- spells
- movement
- fighting
- healing
- scrolls
- potions
This leads me to propose that all of these things be defined as variants on a single thing – an “action” – that has some sort of “effect”.
Actions vs. Effects
To explain this last point a bit more, it seems to me that there are two major things here:
- Actions – something you do
- Effects – what happens when you do it
The distinction is important, I think. An action may or may not have an effect, for instance. You fire the arrow but it misses. You cast the spell but the target is immune. You try to open the door but it is locked. However a given effect (like “cure”) might be caused by different actions (potion, spell cast, healer).
Think of an action as a “verb”, and the effect of the action as a “noun”.
Effects and their resolution
I think the neatest way of separating actions from their effects is to define an action as having a “parcel of effects” (which might be a single effect).
For example, firing a poisoned, fiery arrow at someone might have the following effects (if it hits):
- They are physically hurt by the arrow
- They are poisoned for 60 seconds
- They take fire damage
Whether any of these effects actually happen depends a bit on the target rather than the person firing the arrow:
- They may be wearing armour and not be affected by the arrow
- They may be immune to poison
- They may be immune to fire
To work all this out we need an “effect resolution phase”, described later.
For now, let’s consider these three steps:
- Action
- Effect resolution
- Effect
Actions
Actions are things that characters (players, mobs) do which may or may not have an effect. Actions may even be initiated by things (eg. traps, portals). Actions may be directed at things too, eg. you attack a door in an attempt to break it open.
They have the following components (not all may apply in every case):
Knowledge
You need basic knowledge to use something (eg. swordsmanship, knowing a particular spell, swimming, climbing). You have the knowledge or you don’t. This knowledge may be innate (you have it immediately), taught (learned), purchased, acquired, bestowed etc.
Some knowledge may have pre-requisites (eg. require a level, need to learn one spell before you can learn another).
eg.
David knows “cure light wounds”.
John can swim.
Nick can pick locks.
Skill
Skill is a measurement of how well you can apply the knowledge. It may improve in time. Your skill level will affect how well the action is applied (chance of success).
eg.
bow and arrow require dexterity
swords require strength
spells require intelligence
Power
This measures how “hard” (or much) the action will be. For a sword, it might be how hard it hits, for an arrow how accurately it lands, for a spell how much power is in the spell. For movement it might affect how fast you walk.
eg.
bow and arrow – accuracy
sword – strength
spell – magic power
walking - strength, stamina
negotiation - charisma
Consumption (reagents)
The action will consume something - a reagent. If you don’t have (enough of) it to start with you cannot perform the action.
eg.
bows and arrows – arrows
swords – stamina, wear-and-tear on the sword
spells - mana
scrolls - the scroll itself
potions - the potion (or some of it)
movement - stamina or movement points
making a shirt - cloth
Requires - object (equipment)
Some actions may require the possession, equipping, or proximity to, an object. This would be different from an object that is consumed. For example, the bow is not consumed by firing an arrow.
eg.
archery - bow
spell - a wand
sailing - a boat
locked door - the appropriate key
mining - a pick
smelting - a forge
fishing - fishable water
Requires – flags
The enactor may need one or more “status flags” to perform this action. Some actions may require a “room flag” to be set.
eg.
to do most things you need to be awake.
to use a weapon you must be fighting
to swim you may need to be in a room with water in it
to fly you may need to be outdoors
to dig you may need to be outside where there is loose soil
Inhibit - flags
Some “status flags” will inhibit the action. Some “room flags” will also inhibit actions. For example, a “peaceful” room may inhibit fighting, a “quiet” room may inhibit spell casting.
eg.
sleep would inhibit most actions
silence would inhibit spell casters
blindness would inhibit archers
Performing an action
Preparation time (casting time)
This is the time needed to prepare the action.
eg.
fitting an arrow to a bow requires 2 seconds
preparing a spell requires 3 seconds
Interruption of action
It might be possible to be distracted during the preparation phase. The caster may be slowed or cancelled by interruptions, such as an attacker hitting you while you are casting a spell. These interruptions might simply extend the preparation time, or cancel the action altogether.
eg.
the kobold hits you, delaying the spell-cast by 1 second
the gnoll stuns you, cancelling the action
the mage silences you, making spell casting impossible for 5 seconds
Chance of preparation success
After the preparation time elapses you may be ready to perform the action. At this stage this is unaffected by the target. For example, you may spend 10 seconds preparing a spell to be cast at a target that happens to be immune to it.
Preparation success would be related to your skill level in this action.
eg.
Nick has 40% success of fitting an arrow to his bow.
David has 70% success of preparing the spell “fireball”.
Launch the action
This “commits” the action, so that it is performed and cannot be revoked. Any consumption cost is now incurred (eg. mana, arrow, wear-and-tear). Once the action is launched the enactor can start doing other things, once the recovery time is up.
eg.
Nick fires the arrow.
David casts the spell.
John walks East.
In-transit time
This is the time taken for the action to “reach the target”, or “be performed”. This may conceivably vary depending on the circumstances (eg. casting a spell on yourself may be quicker than casting it on someone else).
eg.
The arrow speeds towards the target for 3 seconds.
The fireball takes 2 seconds to reach the orc.
John takes 5 seconds to walk East.
There might be a case to be made that walking takes “preparation” time rather than “in-transit” time. I’m not sure about that.
Recovery time (cooldown)
This is the time taken for the action-taker to recover from the action. The preparation time and recovery time combined are basically to stop actions occuring ridiculously quickly.
During the recovery time the action-taker (enactor) may be limited in what s/he can do until recovery is over.
eg.
Nick rests after firing the arrow for 3 seconds.
David’s mind is a blank for 8 seconds after casting the spell.
John sits down after walking East.
Various actions may have individual cooldown times. A powerful spell may have a 10 minute cooldown, however a normal spell may be able to be recast immediately. You will need to consider whether various similar spells share a cooldown timer. That is, casting spell A also invokes the cooldown timer for spell B.
To stop players simply quickly switching between spells (or other actions) in order to defeat the cooldown mechanism, you probably need a "general cooldown" which is a short delay after every action, that prevents another one from occuring (say, 1/2 second or so). Otherwise players may program their clients to fire off 100 spells in 1 second.
Effect of action
After the in-transit time, the “action” has now (almost) reached the target.
Miss
The action may miss the target and do nothing. The chance of a miss would be dependant on the skill of the attacker, independent of the defender (unless the defender simply runs away).
eg.
The arrow misses the orc.
The spell misses the kobold.
John leaves the room before the fireball hits him.
Defend
The target may dodge or defend against the action. (The “miss” described above might be a variant of defense, although it seems to me that a badly-aimed arrow might miss even the most stupid creature).
Dodging would be dependant on the skill of the defender rather than the attacker, so this is separate from the "miss" calculation.
Alternatively the defender could block the attack, say by using a shield, or some sort of magic shield. The blocking could reduce the attack amount (eg. you block 20 out of 40 points of attack). Since blocking is effectively absorbing an attack onto a shield, the act of blocking should probably increase the wear amount for the shield.
There could be a formula for the “chance to hit” being a combination of the attack rating of the attacker, the defense rating of the defender, and their respective levels. The formula may be different for spells (and doors) but there would be cases where the action is ineffective.
eg.
The arrow glances off the orc.
The spell has no effect.
The door cannot be opened.
The lock cannot be forced.
Armour
Finally, assuming the blow has reached the target, and not missed, been dodged or blocked, there is a final mitigating factor - the armour of the defender. Armour may only defend against certain attacks (you would need to define those), for instance armour may not defend against magic, or being garotted.
Assuming the attack is the sort that armour defends against, then a simple muliplication of the armour defence amount by the amount of the attack should give the reduced attack.
eg.
You are hit for 40 hp.
Your armour absorbs 30%.
Resulting damage is 21 hp.
Susceptibility/resistance/immunity/absorption
If the action reaches its target its initial force (the action “force” as described earlier) may be modified for this particular target, based on its resistance etc. For example, a “ring of fire” cast into a room may affect creatures differently depending on what they are.
eg.
The orc is susceptible to fire and takes double damage.
The fire-worm absorbs the fire and becomes more powerful.
The gladiator resists the fire and takes half damage.
The metal box is immune to fire.
The ghost is immune to physical damage.
We will cover this later under “effect resolution”. Suffice to say that at this point the action has “succeeded” or “reached the target” and now the effects attached to the action need to be resolved.
Multiple effects
Actions may be defined as having multiple effects (see below for the description of the “parcel of effects” idea).
For weapons that deal a “double blow” this could be simply implemented by attaching two “hit” effects to a single action.
Effect – what the action does
Finally we reach the outcome of an action – the effect it causes. Without some sort of effect there isn’t much point to having actions in the first place.
An effect can basically be described as a “status change” - something changes in the target or their environment.
eg.
Nick gets better.
Nick gets sicker.
Nick is blinded.
Nick is cured of blindness.
Adam is now immune from future blindness attacks.
David has more gold.
David has less gold.
David has more stamina.
Adam falls asleep.
David’s accuracy increases.
John moves to a new room.
John obtains a “rod of healing”.
Adam learns “cure light wounds”.
Adam is no longer hungry.
To summarise, an effect might:
- Increase or decrease a stat immediately (eg. HP, stamina)
- Increase or decrease a stat over time (eg. HP gradually increases)
- Set or clear a status flag (eg. blindness, sleep)
- Provide immunity to future status changes (eg. immune to sleep)
- Give you something (eg. an object, gold, a ring, a scroll)
- Take something away (eg. an object)
- Give you knowledge (eg. a new spell)
- Change your location (eg. move you to a new room)
Effect resolution
Actions will have a “parcel of effects” attached to them - that is, one or more effects that potentially occur when the action succeeds, as described previously.
Taking each effect in turn (for each target, if there is more than one), we would consider:
Elemental considerations
Some effects may belong to “elemental groups” which are major groups of “types of things” that happen. These would be expandable by the MUD, but might be things like:
- Physical
- Magical
- Holy
- Fire
- Lighting
- Water
- Ice
- Nature
- Shadow
- Gravity
- Red
- Green
- Blue
- White
- Black
The “class of effect” (elemental group) may well affect the next section - susceptibility etc.
Susceptibility/resistance/immunity/absorption
This will be a multiplier which indicates the susceptibility of this particular target to this effect. The multiplier may vary by elemental group (eg. be susceptible to fire but resistant to ice).
eg.
Normal - takes 1.0 times the “normal” effect (in other words, normal damage taken)
Susceptible – take 1.5 (or some figure > 1) times the “normal” effect
Resistant - takes 0.5 (or some figure < 1) times the “normal” effect
Immune - the effect does nothing (ie. the multiplier is zero)
Absorb - takes -1.0 (or some negative figure) times the “normal” effect
The multiplier might be fixed (eg. always immune) or some chance factor (eg. 20% chance to resist 50% of an attack).
The multiplier may be dependant on respective levels (or statuses) of the attacker vs the defender. For example, being attacked by someone much lower level may give you a much higher chance of resisting the attack, conversly, if the attacker is much higher level your chance of resisting might be much lower.
Reflect
The target might reflect certain effects back at the originator of the effect (or someone else).
Triggers (bufs / debufs)
The target may be temporarily immune to the effect (as opposed to permanently immune because of its very nature). This could be because someone had previously applied a “prevent poison” or “sleep ward” spell, potion, or similar.
If so, the effect is cancelled, and the temporary immunity may be consumed (cancelled).
Putting this more generally, the target would be searched for “triggers” which match this effect. For example, a poison effect would search for “immune to poison” triggers.
This trigger would then modify the susceptibility/resistance/immunity/absorption for this particular effect. The trigger is then discarded.
A trigger might have "x charges" so that rather then being immediately discarded, a charge is used. For example, a "resist poison" trigger might have 5 charges, which resists 5 lots of poison, and then self-cancels.
Alternatively, a trigger might make you more susceptible to something (like poison) rather than less.
Triggers may be more general than that, I’m not sure how this would be implemented. For example, being hit with an arrow might teleport you somewhere else.
Power of effect
Some effects (those that change your status by a varying amount) will need to be given the power of the underlying action.
Example
An swordsman hits you with his sword. He is very strong, so the action “carries with it” a power of 30.
The “power of 30” is passed down to the “sword blow” effect.
The target is susceptible to sword blows by a factor of 1.5.
The resulting damage is 30 * 1.5 = 45 HP, which are subtracted from the target.
Effect application
Once past the effect resolution phase, we now have an effect that is “going to happen” (ie. the target is not immune), and has its power multiplied by an appropriate amount. The effect is now applied to the target.
The different ways effects might be applied are:
Immediate stats change
There is an immediate stats change (eg. HP increases) and the effect is then discarded.
Immediate flag change
The effect is attached to the player’s effect list as a “status change”.
eg.
You become blind.
You fall asleep.
Change stats for a time (buf / debuf)
There is an immediate change to your stats (eg. stamina increases) which stays static for a period of time, and then terminates (with the status change reversing back to normal). This could be used for temporary increases to strength, stamina etc.
This is done by attaching the effect to the player’s effect list, so that checks for his current stats take into account the temporary extra (or less) amount.
Change flags for a time
The effect is attached to the player’s effect list as a “status change”, which wears off after x seconds.
eg.
You become silent for 30 seconds.
Gradual change
There is no immediate change, but every x seconds (say, every 5 seconds) a status change occurs (eg. HP decreases by 5 points). This happens indefinitely until “cured” somehow.
Gradual change for a time
There is no immediate change, but every x seconds (say, every 5 seconds) a status change occurs (eg. HP decreases by 5 points). This happens until the time limit elapses (say, after 30 seconds).
Implementation of time-based effects
All effects that occur over a period of time and then automatically stop can be implemented by adding an “indefinite” effect, and also adding a “cancel this effect” event to the event queue. Once this event fires the effect will be removed (if it hasn’t already been removed by other means).
Trigger effect (bufs / debufs)
A “trigger” is installed which is searched for by other effects. (eg. “silence ward”) might have a chance of defeating the “silence” effect.
Trigger effects may be:
One (or more) shots (once used for x times they are discarded)
One (or more) shots, time limited (if not used after 2 minutes, they are discarded - during that time they can be used x times)
Unlimited (can be used indefinitely)
Multiple-use, time limited (can be used multiple times, but wear off after time)
Trigger effects may do various things if triggered.
Cancel an incoming effect (eg. “resist poison” cancels a “poison” effect)
Cause something else (eg. water-based spell causes bomb to explode)
Delayed effect
An effect may cause an action after x seconds.
eg.
The “death” spell will cause John to die if not removed within 3 minutes!
Implementation of trigger and delayed effects
Both of these are variations on a theme - an effect that happens later rather than now.
These can probably both be implemented as an effect that “converts” from its original type (trigger or delay) to its new type.
Removal of effects
Effects that occur over time (eg. poison, blindness) can be “cured” by defining a suitable “counter-effect” - one that removes it. This is really a different effect-type - the “remove other effect” type.
eg.
You are no longer blind.
You are no longer asleep.
Detection of effects
To see if a character has a “temporary status change” (eg. blindness, sleep) we would search the “effects list” for this player to see if that effect was present.
Giving things
An effect may be defined to give an object to the target.
eg.
The “cure hunger” spell gives Adam a loaf of bread.
Taking things
An effect may remove an object from the target.
eg.
The “destroy weapon” spell destroys your sword!
Transferring ownership
An effect may take something from the target and give it to someone else.
eg.
You steal a potion from the orc!
Acquiring money
An effect may transfer or create money.
eg.
The “pilfer gold” spell lets Adam steal 50 gold pieces from the goblin.
Acquiring knowledge
An effect may bestow knowledge.
eg.
You now know “cure heavy wounds”.