|[ LiB ]|
Combat within the MUD is also pretty simple. There are a few things that must be considered . First of all, you're only allowed to attack enemies. Player Versus Player (PvP) combat is a somewhat more complex subject, so I'll tackle that in the more advanced MUD.
There are two parts to the attack phase: First, you need to see if you actually hit the enemy, and second, you need to calculate how much damage you did.
Both players and enemies have accuracy and dodging attributes. When a player is attacking, a random number from 0 to 99 is generated. The enemy's dodging attribute is subtracted from the player's accuracy attribute, and the result is compared to the random number. If the random number is below the calculated value, the enemy is hit.
Here is the basic formula:
if random(0,99) < (player.accuracy - enemy.dodging) then hit
For example, if the player's accuracy is 80%, and the enemy's dodging is 10%, the calculated value is 70, which means that the player hits the enemy about 70% of the time. The random number would need to be 069 to get a successful hit.
Note that by using this system, it's possible to have accuracies higher than 100%, which means that you'll have extraordinary accuracy against enemies with very low dodging attributes.
The next part is the damage calculation. Assuming you get a successful hit, you need to calculate how much damage it does. The first part of this is to calculate a random number within the range of your current weapon. If you are not using a weapon, it is assumed you are attacking with your fists, and a range of 13 is used automatically. Once a value has been calculated, the value of your strike damage attribute is added to it. Then, the value of the enemy's damage absorption attribute is subtracted from the result, and that value is compared to 1. If it is less than 1 (which is possible if the enemy has really tough armor ), the value is reset to 1. Finally, the calculated value is subtracted from the enemy's hitpoints. Here's the formula:
damage = random( weapon.min, weapon.max ) + player.SD - enemy.DA if damage < 1 then damage = 1
Now, obviously, this is just psuedocode; I'll show you the real code in Chapter 10, "Enemies, Combat, and the Game Loop," when I get to coding these algorithms.
Now, what happens when you kill an enemy? The game goes through all the enemy's possible droppable items and figures out if it drops any, as well as how much money it drops .
Enemies return your attacks by using the same formulas, so it's possible for you to die. What happens when you die? Some games give you a certain number of lives, which represent the number of times you can die before your character is permanently deleted. I don't like this method; it tends to make people freak out when they are running low on lives, or get system operators to cheat and give them more.
I like an approach that penalizes you by subtracting 10% of your experience points. This doesn't change your level, but it makes you further away from gaining another level. But that's not enough punishment . So in addition, you lose 10% of the money you're carrying and one item randomly chosen . I don't like players to lose everything when they die because it makes it far too easy for scavengers to steal all their hard-earned stuff. I tend to be generous, though; in your own MUDs, you're allowed to be devious bastards if you like. So after you've lost an item and your money, you're automatically transported back to the starting room in the world, and you're hoping you didn't lose an important item.
Some MUDs have a combat state, in which the game automatically attacks for you. This feature is somewhat advanced, and thus SimpleMUD doesn't have it. Every time you want to attack someone, you must manually enter the attack command. The game will notify the user if he has attacked , or if he still needs to wait for the next time he can attack, since it might be a few seconds before the user can attack again.
|[ LiB ]|