Simple_Combat/
Simple_Combat/cmd/
Simple_Combat/cmd/bmud/
Simple_Combat/lib/core/
This is an extremely simple combat system for TeensyMud(By Jon Lambert - aka Tyche). This snippet is written by Christopher Bailey and I wish no mention, credit or thanks. Feel free to use, modify, distribute or mock it however you please. Do keep in mind that this is meant more as an example on how to implement a combat system than something you can really use. It was my first attempt at writing a combat system in Teensy and I've decided to update it a bit and throw it out there incase someone is wondering how to implement something like it. Fair warning, I think I left *1* comment in 130 lines of poorly written code.

Features....if you want to call them that.

-Stances

 Players may select a fighting "stance" that modifies factors determining their chance to hit and how much damage they will do. The options are as follows.
  
  +Defensive - Increases your defense by 2 and lowers attack by 2.
  +Offensive - Increases your attack and damage by two by lowers your defense by 2.
  +Evasive   - Increases your defense by 2 and lowers damage by 2.
  +Relaxed   - Modifies nothing.

You may change your stance by typing stance followed by the one you choose.


-Targetable body parts.

 Players may select a body part to target when attacking. Doing so will modify your chance to hit and damage dealt as follows.

  +Head  - Increases your damage by 2 and decreases attack by 4.
  +Arms  - Increases your attack by 2 and decreases damage by 1.
  +Legs  - Increases your damage by 1 and decreases attack by 2.
  +Body  - Modifies nothing, this is the default.

You may attack another player by typing attack followed by their name. If you want to target a body part you would type "attack bob head". Not selecting a body part causes it to default to the body.


-Defeat, but not death.
 Players start with 10 health. If they are reduced to 0 they receive a message stating that they have been defeated and then they are fully regenerated. Why is that you ask? Because I haven't implemented death.





 Installation!

This snippet is extremely easy to install. If you have not modified your config.yaml or character.rb file you can simply extract the file over your TeensyMud directory. If you would like to do it manually it's about as simple.

Step one - Put the files in there!
 
 Copy the "bmud" directory and "bmud.yaml" file to the "cmd" folder in your TeensyMud directory.

Step two - Fix your config!

 Open up "config.yaml". It is located in your TeensyMud base directory. Scroll down to or search for "character_interface:" minus the quotes. Add "- bmud" to the list below "- tiny".

Step three - Setup character.rb

 Open up "/lib/core/character.rb". Scroll down to line 24 or search for "property :acctid". You want to add ":attributes" to that line. It will now say "property :acctid, :attributes". Do take note of the comma seperating the two properties. Now scroll down to line 41, in the initialize method of class Character. After the comments provided by Tyche we are going to add a hash called attributes to contain the players stance and health. It will look like follows.

def initialize(name,acctid)
  super(name, nil, options['home'] || 1)
  self.acctid = acctid
  @account = nil              # reference to the Account.  If nil this   
                              # character is not logged in.
                              # We could use get_object(acctid) but
                              # holding the reference is faster
  self.attributes = {
                     'stance'    =>  'relaxed',
                     'health'    =>  10
                    }
end


If you can't figure it out, look at the included character.rb file, it has the modification.



Now we have only one thing left to add, a method to damage our characters. Scroll down toward the end of the file and add this method below the show method.


def damage(stat,amount,xid)
  self.attributes[stat] -=amount
    if self.attributes['health'] <= 0
      add_event(id,xid,:show, "You have been defeated.")
      self.attributes['health'] = 10
    end
end


Once again, if you can't figure out, check out character.rb and make it match.



That's it! Start up your copy of Teensy, connect with two characters and try it out.