Programming.html

guides/Programming.html · 387.7 KB

From the archive CoffeeMud_5_5_5.zip

Download the archive   « Back to the archive contents

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>







    
  
  
  
  
  
  
  <meta name="generator" content="HTML Tidy, see www.w3.org" />








    
    
  
  
  
  
  
  
  
  
  
  
  
  
  
  <title>Programming for CoffeeMud 5.5</title><link rel="StyleSheet" href="style.css" type="text/css" media="screen" /><!-- Modified by Josh Mueller, 2006-5-6, fix validation problems, reformat, fix spelling errors --></head>
<body>







    
<center>
      
<table border="1" cellpadding="10" cellspacing="0" width="90%">







        <tbody>







          <tr>







            <td colspan="2" align="left" bgcolor="#dfdfdf" width="100%">
              
      
      
      
      
      
      
      <h1>Programming for CoffeeMud 5.5</h1>







            </td>







          </tr>








          <tr>







            <td align="left" valign="top" width="20%">
              
      
      
      
      
      
      
      <ul>







                <li><a href="#overview">Overview</a></li>








                <li>
                  <a href="#BUILD">Building</a> 

                  
          
          
          
          
          
          
          <ul>







                    <li><a href="#buildwin">Windows</a></li>








                    <li><a href="#buildunix">Unix</a></li>








                    <li><a href="#external">External Components</a></li>








                    <li><a href="#IMPORTS">Default Import List</a></li>







                  
          
          
          
          
          
          
          </ul>







                </li>








                <li>
                  <a href="#TEXT">Text</a> 

                  
          
          
          
          
          
          
          <ul>







                    <li><a href="#nametag">Target Info Tag</a></li>








                    <li><a href="#textcolor">Color</a></li>







                  
          
          
          
          
          
          
          </ul>







                </li>








                <li>
                  <a href="#javascript">JavaScripting</a> 

                  
          
          
          
          
          
          
          <ul>







                    <li><a href="#writingjavascript">Writing Your First Javascript</a></li>







                  
          
          
          
          
          
          
          </ul>







                </li>








                <li>
                  <a href="#DIG1">Core Topic 1: Message Passing</a> 

                  
          
          
          
          
          
          
          <ul>







                    <li><a href="#majorcode">Major Code Bitmask</a></li>








                    <li><a href="#messagepreview">Message Previewing</a></li>








                    <li><a href="#messageflagging">Message Flagging and Modification</a></li>








                    <li><a href="#messageexecution">Message Execution</a></li>








                    <li><a href="#messagetrailers">Message Trailers</a></li>







                  
          
          
          
          
          
          
          </ul>







                </li>








                <li>
                  <a href="#DIG2">Core Topic 2: State Layers</a> 

                  
          
          
          
          
          
          
          <ul>







                    <li><a href="#envstats">EnvStats fields</a></li>








                    <li><a href="#charstats">CharStats codes</a></li>








                    <li><a href="#charstate">CharState</a></li>







                  
          
          
          
          
          
          
          </ul>







                </li>








                <li><a href="#DIG3">Core Topic 3: Threading</a></li>








                <li>
                  <a href="#DIG4">Core Topic 4: Core Libraries</a> 

                  
          
          
          
          
          
          
          <ul>







                    <li><a href="#corepurpose">Core class purposes</a></li>








                    <li><a href="#corelibrarymap">Library mappings</a></li>








                    <li><a href="#corecommon">Common Classes</a></li>







                  
          
          
          
          
          
          
          </ul>







                </li>








                






                <li><a href="#CMDS">Commands</a></li>








                <li>
                  <a href="#MOBS">MOBs</a> 

                  
          
          
          
          
          
          
          <ul>







                    <li><a href="#mobcoding">Coding a new MOB</a></li>








                    <li><a href="#moblife">Life and Death</a></li>







                  
          
          
          
          
          
          
          </ul>







                </li>








                <li>
                  <a href="#ITEMS">Items</a> 

                  
          
          
          
          
          
          
          <ul>







                    <li><a href="#itemlife">Creation and Destruction</a></li>







                  
          
          
          
          
          
          
          </ul>







                </li>








                <li><a href="#BEHAVS">Behaviors</a></li>








                <li><a href="#CLASSES">Character Classes</a></li>








                <li><a href="#RACES">Races</a></li>








                <li><a href="#EXITS">Exits</a></li>








                <li><a href="#LOCALES">Locales</a></li>








                <li><a href="#AREAS">Areas</a></li>








                <li><a href="#PROPS">Properties</a></li>








                <li>
                  <a href="#SKILLS">Skills</a> 

                  
          
          
          
          
          
          
          <ul>







                    <li><a href="#skillquality">Skill Nature Flags</a></li>








                    <li><a href="#skillflags">Skill Affect Flags</a></li>







                  
          
          
          
          
          
          
          </ul>







                </li>








                <li>
                  <a href="#SPC">Spells, Prayers, and Chants</a> 

                  
          
          
          
          
          
          
          <ul>







                    <li><a href="#spells">Spells</a></li>








                    <li><a href="#spelldomain">Spell Domains</a></li>








                    <li><a href="#prayers">Prayers</a></li>








                    <li><a href="#chants">Chants</a></li>







                  
          
          
          
          
          
          
          </ul>







                </li>








                <li><a href="#SONGS">Songs</a></li>








                <li>
                  <a href="#COMMON">Common Skills</a> 

                  
          
          
          
          
          
          
          <ul>







                    <li><a href="#skillgathering">Gathering Skill</a></li>








                    <li><a href="#skillcrafting">Crafting Skill</a></li>







                  
          
          
          
          
          
          
          </ul>







                </li>








                <li><a href="#POISON">Poisons</a></li>








                <li><a href="#DISEASE">Diseases</a></li>








                <li><a href="#TRAPS">Traps &amp; Bombs</a></li>








                <li><a href="#LANGS">Languages</a></li>







              
      
      
      
      
      
      
      </ul>







            </td>








            <td align="left" valign="top">
              <img src="images/mug.jpg" alt="CoffeeMud logo" /> 

              
      
      
      
      
      
      
      <h2><a name="overview" id="overview">Overview</a></h2>








              
      
      
      
      
      
      
      <p>The purpose of this document is to assist those who wish to
add custom Items, MOBs, Behaviors, Properties, or other objects to
CoffeeMud. The reader should be familiar with Java programming, and
should be experienced with writing and compiling Java classes. The
object oriented notions of class inheritance and polymorphism, as well
as the Java constructs of interfaces should be at least vaguely
familiar to you before attempting to build classes for CoffeeMud. Also,
it is expected that all of the ideas presented in the <a href="ArchonGuide.html">Archons Guide</a> and <a href="GameBuildersGuide.html">Game Builders Guide</a>
are completely familiar. The difference between a GenItem and a
StdItem, or a GenMob and a GenPostman will not be explained in this
document.</p>








              
      
      
      
      
      
      
      <p>It is not expected that someone would wish to dive in and make
wholesale changes to the CoffeeMud system right away, but is more
likely wanting to fill in a functional gap in the system for their own
needs. For this reason, this document is not organized as a
comprehensive guide to programming CoffeeMud. Instead, it is designed
to be a quick reference for those who wish to create the spot MOB,
Behavior, Item, or Property for use on their maps.</p>








              
      
      
      
      
      
      
      <p>With this in mind then, let's start out with some brief development instructions, and then and in no particular order, discuss
              the several essential object types in CoffeeMud are presented.</p>







              <img src="images/sprockets.jpg" alt="Recompiling" /> 

              
      
      
      
      
      
      
      <h2><a name="BUILD" id="BUILD">Rebuilding CoffeeMud</a></h2>








              
      
      
      
      
      
      
      <h3><a name="buildwin" id="buildwin">In Microsoft Windows</a></h3>








              
      
      
      
      
      
      
      <ul>







                <li>
                  
          
          
          
          
          
          
          <p>Go to your coffeemud directory and edit the make.bat, the first line will be something like: <code>SET JAVACPATH=
                  C:\jdk1.6.0_17\bin\javac</code> This might be different for you depending on where your java development package is
                  installed.</p>







                </li>








                <li>
                  
          
          
          
          
          
          
          <p>Save the bat file.</p>







                </li>








                <li>
                  
          
          
          
          
          
          
          <p>Run the bat file by double clicking on it. This will compile the mud, making all the .class files.</p>







                </li>







              
      
      
      
      
      
      
      </ul>








              
      
      
      
      
      
      
      <h3><a name="buildunix" id="buildunix">In Unix</a></h3>








              
      
      
      
      
      
      
      <ul>







                <li>
                  
          
          
          
          
          
          
          <p>Go to your coffeemud directory and edit the makeUNIX.sh, the first line will be something like:
                  <code>Java_Home=/home/knoppix/jdk1.6.0_17</code> This might be different for you depending on where your java development
                  package is installed.</p>







                </li>








                <li>
                  
          
          
          
          
          
          
          <p>Save the shell script.</p>







                </li>








                <li>
                  
          
          
          
          
          
          
          <p>Issue this command: <code>chmod 755 makeUNIX.sh</code></p>







                </li>








                <li>
                  
          
          
          
          
          
          
          <p>Execute the shell script. This will compile the mud, making all the .class files.</p>







                </li>







              
      
      
      
      
      
      
      </ul>








              
      
      
      
      
      
      
      <h3><a name="external" id="external">Introducing External Components</a></h3>








              
      
      
      
      
      
      
      <p>If you perused the coffeemud.ini file as mentioned in the Installation Guide, you may have noticed and wondered about the
              section at the end which lists the default load paths for the several CoffeeMud objects.</p>








              
      
      
      
      
      
      
      <p>By default, the CoffeeMud engine dynamically loads the vast majority of its object code at boot time by referring to the paths
              specified in the coffeemud.ini file. The value <code>%DEFAULT%</code> is always used as a substitute for the default CoffeeMud
              object path. For instance, if you installed CoffeeMud at "<code>C:\CoffeeMud\</code>", then "<code>BEHAVIORS=%DEFAULT%</code>" in
              the ini file would load "<code>C:\CoffeeMud\com\planet_ink\coffee_mud\Behaviors\*.class</code>" into its behavior set.</p>








              
      
      
      
      
      
      
      <p>This default object boot paths may be removed or added-to
using semicolon delimited paths, or even replaced with your own object
boot directories. In fact, when adding objects to your CoffeeMud boot
sequence, it is recommended that you place your objects in a separate
directory path inside your CoffeeMud folder and add its path to the
coffeemud.ini file under the proper setting. The order in which you
place multiple paths in a single entry is also significant, as the
CoffeeMud ClassLoader will load the files in the order in which they
appear listed. For instance:</p>







      
      
      
      
      
      
      <pre>MOBS=%DEFAULT%;/resources/examples/MyClass.class;/resources/otherclasses<br /></pre>








              
      
      
      
      
      
      
      <p>Will cause the default CoffeeMud versions of the mob classes
to be loaded first, followed by MyClass.class, followed by all the
class files in the resources/otherclasses folder in your CoffeeMud
package. Also notice that the ClassLoader follows the rules of the CMFS
described in the Archons Guide, meaning that the forward slash is
always the proper path separator, and that no folder outside of your
CoffeeMud package may be referenced. Also bear in mind that case is
sensitive when naming Java class files, even in these boot paths.</p>








              
      
      
      
      
      
      
      <p>When writing these custom classes for your special object boot directory(s), it is important to keep a number of things in
              mind:</p>








              
      
      
      
      
      
      
      <ul>







                <li>
                  
          
          
          
          
          
          
          <p>Do not mix your object types in the same directory! Never try to boot custom items from the same directory from which you
                  boot your custom mobs. It will only confuse you and CoffeeMud.</p>







                </li>








                <li>
                  
          
          
          
          
          
          
          <p>Java Packaging is irrelevant, you may package your classes or not.</p>







                </li>








                <li>
                  
          
          
          
          
          
          
          <p>Implement or extend a class that implements the proper
interfaces. If you are coding mobs, this would mean the MOB interface.
If you are coding locales, the Room interface, etc, etc. See the
section on the object type you are coding for the proper interface to
implement. You may get around this requirement by extending one of the
base classes, such as StdItem, StdMOB, StdContainer, StdRoom,
StdAbility, GenMob, GenItem, GenContainer, etc.</p>







                </li>








                <li>
                  
          
          
          
          
          
          
          <p>Make sure the <code>ID()</code> method in your classes always matches the name of your class. You will understand this
                  better as you reference the object sections below.</p>







                </li>








                <li>
                  
          
          
          
          
          
          
          <p>Try to make the <code>name()</code> methods in your
classes return name values unique among all objects, especially objects
of that type. This is not a hard fast rule, and breaking it will not
cause malfunction in the system, but breaking this rule WILL make
writing help files impossible.</p>







                </li>








                <li>
                  
          
          
          
          
          
          
          <p>Class files loaded directly in the CoffeeMud classpath can not be reloaded at run-time using the <code>UNLOAD</code> and
                  <code>LOAD</code> commands. If you plan on making changes to your classes during run-time, place them in their own
                  directories.</p>







                </li>








                <li>
                  
          
          
          
          
          
          
          <p>As a general rule, you may import any "<code>interfaces.*</code>" packages in the base CoffeeMud structure, any core Java
                  packages, the CoffeeMud "<code>core.*</code>"
package, and any single base CoffeeMud class you may be extending. Do
not import more than that. Use the CMClass getter methods if you need
to create new instances of CoffeeMud classes, and use the CMLib methods
to access her code libraries.</p>







                </li>







              
      
      
      
      
      
      
      </ul>








              
      
      
      
      
      
      
      <h3><a name="IMPORTS" id="IMPORTS">Complete Default Import List</a></h3>







      
      
      
      
      
      
      <pre>import com.planet_ink.coffee_mud.core.*;<br />import com.planet_ink.coffee_mud.core.interfaces.*;<br />import com.planet_ink.coffee_mud.Abilities.interfaces.*;<br />import com.planet_ink.coffee_mud.Areas.interfaces.*;<br />import com.planet_ink.coffee_mud.Behaviors.interfaces.*;<br />import com.planet_ink.coffee_mud.CharClasses.interfaces.*;<br />import com.planet_ink.coffee_mud.Commands.interfaces.*;<br />import com.planet_ink.coffee_mud.Common.interfaces.*;<br />import com.planet_ink.coffee_mud.Exits.interfaces.*;<br />import com.planet_ink.coffee_mud.Items.interfaces.*;<br />import com.planet_ink.coffee_mud.Locales.interfaces.*;<br />import com.planet_ink.coffee_mud.MOBS.interfaces.*;<br />import com.planet_ink.coffee_mud.Races.interfaces.*;<br />import com.planet_ink.coffee_mud.Libraries.interfaces.*;<br />import java.io.IOException;<br />import java.util.*;<br /></pre>







              <img src="images/rainbow.jpg" alt="Text" /> 

              
      
      
      
      
      
      
      <h2><a name="TEXT" id="TEXT">Text</a></h2>








              
      
      
      
      
      
      
      <p>Before we get started with objects, needs must the topic of
text display be covered. Throughout the system you will see text being
sent to the user. Since a mud is a text producing engine, this should
be no great surprise. However, within that text you will often see
different kinds of codes and tags which affect the output. For
instance, consider the following lines:</p>







      
      
      
      
      
      
      <pre>msg=CMClass.newMsg(mob,target,this,affectType,"&lt;S-NAME&gt; reach(es) for &lt;T-NAMESELF&gt;.");<br />mob.location().show(mob,null,CMMsg.MSG_OK_ACTION,"&lt;S-NAME&gt; regain(s) &lt;S-HIS-HER&gt; feet.");<br /><br /></pre>








              
      
      
      
      
      
      
      <p>Focusing only on the text for a moment, you will notice that
special tags are used to designate a player name, or the name of the
target of a spell. You will also notice that (s) and (es) is used to
modify the proper form of a verb. These are key features of the
CoffeeMud text engine. Here is a more complete list of available tags:</p>







              <a name="nametag" id="nametag"></a> 

              
      
      
      
      
      
      
      <table bgcolor="#ffffcc" border="1">







                <tbody>







                  <tr>







                    <td><code>&lt;S-HIS-HER&gt;</code> </td>








                    <td>Outputs 'Your' if Observer=Source, otherwise 'His'/'Her'.</td>







                  </tr>








                  <tr>







                    <td><code>&lt;S-HIM-HER&gt;</code> </td>








                    <td>Outputs 'You' if Observer=Source, otherwise 'Him'/'Her'.</td>







                  </tr>








                  <tr>







                    <td><code>&lt;S-NAME&gt;</code> </td>








                    <td>Outputs 'You' if Observer=Source, otherwise the Name.</td>







                  </tr>








                  <tr>







                    <td><code>&lt;S-NAMESELF&gt;</code> </td>








                    <td>Outputs 'Yourself' if Observer=Source, otherwise the Name</td>







                  </tr>








                  <tr>







                    <td><code>&lt;S-NAMENOART&gt;</code> </td>








                    <td>Outputs 'You' if Observer=Source, otherwise the Name minus any prefix articles (a, an, some, etc..).</td>







                  </tr>








                  <tr>







                    <td><code>&lt;S-HE-SHE&gt;</code> </td>








                    <td>Outputs 'You' if Observer=Source, otherwise 'He'/'She'</td>







                  </tr>








                  <tr>







                    <td><code>&lt;S-SIRMADAM&gt;</code> </td>








                    <td>Outputs 'Sir'/'Madam'</td>







                  </tr>








                  <tr>







                    <td><code>&lt;S-IS-ARE&gt;</code> </td>








                    <td>Outputs 'Are' if Observer=Source, otherwise 'Is'.</td>







                  </tr>








                  <tr>







                    <td><code>&lt;S-HAS-HAVE&gt;</code> </td>








                    <td>Outputs 'Have' if Observer=Source, otherwise 'Has'.</td>







                  </tr>








                  <tr>







                    <td><code>&lt;S-YOUPOSS&gt;</code> </td>








                    <td>Outputs 'Your' if Observer=Source, otherwise the Name`s</td>







                  </tr>








                  <tr>







                    <td><code>&lt;S-HIM-HERSELF&gt;</code> </td>








                    <td>Outputs 'Yourself' if Observer=Source, otherwise the 'Himself'/'Herself'</td>







                  </tr>








                  <tr>







                    <td><code>&lt;S-HIS-HERSELF&gt;</code> </td>








                    <td>Outputs 'Yourself' if Observer=Source, otherwise the 'Hisself'/'Herself'</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-HIS-HER&gt;</code> </td>








                    <td>Outputs 'You' if Observer=Target, otherwise 'His'/'Her'.</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-HIM-HER&gt;</code> </td>








                    <td>Outputs 'You' if Observer=Target, otherwise 'Him'/'Her'.</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-NAME&gt;</code> </td>








                    <td>Outputs 'You' if Observer=Target, otherwise the Name.</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-NAMESELF&gt;</code> </td>








                    <td>Outputs 'Yourself' if Observer=Target, otherwise the Name</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-NAMENOART&gt;</code> </td>








                    <td>Outputs 'You' if Observer=Target, otherwise the Name minus any prefix articles (a, an, some, etc..).</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-HE-SHE&gt;</code> </td>








                    <td>Outputs 'You' if Observer=Target, otherwise 'He'/'She'</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-SIRMADAM&gt;</code> </td>








                    <td>Outputs 'Sir'/'Madam'</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-IS-ARE&gt;</code> </td>








                    <td>Outputs 'Are' if Observer=Target, otherwise 'Is'.</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-HAS-HAVE&gt;</code> </td>








                    <td>Outputs 'Have' if Observer=Target, otherwise 'Has'.</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-YOUPOSS&gt;</code> </td>








                    <td>Outputs 'Your' if Observer=Target, otherwise the Name with an '`s'</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-HIM-HERSELF&gt;</code> </td>








                    <td>Outputs 'Yourself' if Observer=Source, otherwise the 'Himself'/'Herself'</td>







                  </tr>








                  <tr>







                    <td><code>&lt;T-HIS-HERSELF&gt;</code> </td>








                    <td>Outputs 'Yourself' if Observer=Source, otherwise the 'Hisself'/'Herself'</td>







                  </tr>







                
        
        
        
        
        
        
        </tbody>
              
      
      
      
      
      
      
      </table>








              
      
      
      
      
      
      
      <p>Occasionally, you will find color/font codes embedded in system strings. For instance:</p>







      
      
      
      
      
      
      <pre>msg.append("^!You are thirsty.^?\n\r");<br /></pre>








              
      
      
      
      
      
      
      <p>These codes are as follows:</p>







              <a name="textcolor" id="textcolor"></a> 

              
      
      
      
      
      
      
      <table bgcolor="#ccffff" border="1">







                <tbody>







                  <tr>







                    <td><code>^N</code> </td>








                    <td>Normal</td>







                  </tr>








                  <tr>







                    <td><code>^!</code> </td>








                    <td>Bold</td>







                  </tr>








                  <tr>







                    <td><code>^H</code> </td>








                    <td>Highlight</td>







                  </tr>








                  <tr>







                    <td><code>^_</code> </td>








                    <td>Underline</td>







                  </tr>








                  <tr>







                    <td><code>^*</code> </td>








                    <td>Blink</td>







                  </tr>








                  <tr>







                    <td><code>^/</code> </td>








                    <td>Italics</td>







                  </tr>








                  <tr>







                    <td><code>^.</code> </td>








                    <td>Reset (turns off reverse)</td>







                  </tr>








                  <tr>







                    <td><code>^^</code> </td>








                    <td>Generates an untranslated "^" character</td>







                  </tr>








                  <tr>







                    <td><code>^?</code> </td>








                    <td>Restores previous color</td>







                  </tr>








                  <tr>







                    <td><code>^f</code> </td>








                    <td>You-Fight</td>







                  </tr>








                  <tr>







                    <td><code>^e</code> </td>








                    <td>Fight-You</td>







                  </tr>








                  <tr>







                    <td><code>^F</code> </td>








                    <td>Fight</td>







                  </tr>








                  <tr>







                    <td><code>^S</code> </td>








                    <td>Spell</td>







                  </tr>








                  <tr>







                    <td><code>^E</code> </td>








                    <td>Emote</td>







                  </tr>








                  <tr>







                    <td><code>^T</code> </td>








                    <td>Talk</td>







                  </tr>








                  <tr>







                    <td><code>^Q</code> </td>








                    <td>Channel Background</td>







                  </tr>








                  <tr>







                    <td><code>^q</code> </td>








                    <td>Channel Foreground</td>







                  </tr>








                  <tr>







                    <td><code>^x</code> </td>








                    <td>Important message 1</td>







                  </tr>








                  <tr>







                    <td><code>^X</code> </td>








                    <td>Important message 2</td>







                  </tr>








                  <tr>







                    <td><code>^Z</code> </td>








                    <td>Important message 3</td>







                  </tr>








                  <tr>







                    <td><code>^O</code> </td>








                    <td>Room Title</td>







                  </tr>








                  <tr>







                    <td><code>^L</code> </td>








                    <td>Room Description</td>







                  </tr>








                  <tr>







                    <td><code>^J</code> </td>








                    <td>Weather</td>







                  </tr>








                  <tr>







                    <td><code>^D</code> </td>








                    <td>Direction</td>







                  </tr>








                  <tr>







                    <td><code>^d</code> </td>








                    <td>Door</td>







                  </tr>








                  <tr>







                    <td><code>^I</code> </td>








                    <td>Item</td>







                  </tr>








                  <tr>







                    <td><code>^M</code> </td>








                    <td>MOB</td>







                  </tr>








                  <tr>







                    <td><code>^U</code> </td>








                    <td>Unexplored Direction</td>







                  </tr>








                  <tr>







                    <td><code>^u</code> </td>








                    <td>Unexplored Door</td>







                  </tr>








                  <tr>







                    <td><code>^w</code> </td>








                    <td>White</td>







                  </tr>








                  <tr>







                    <td><code>^g</code> </td>








                    <td>Green</td>







                  </tr>








                  <tr>







                    <td><code>^b</code> </td>








                    <td>Blue</td>







                  </tr>








                  <tr>







                    <td><code>^r</code> </td>








                    <td>Red</td>







                  </tr>








                  <tr>







                    <td><code>^y</code> </td>








                    <td>Yellow</td>







                  </tr>








                  <tr>







                    <td><code>^c</code> </td>








                    <td>Cyan</td>







                  </tr>








                  <tr>







                    <td><code>^p</code> </td>








                    <td>Purple</td>







                  </tr>








                  <tr>







                    <td><code>^W</code> </td>








                    <td>Dark White</td>







                  </tr>








                  <tr>







                    <td><code>^G</code> </td>








                    <td>Dark Green</td>







                  </tr>








                  <tr>







                    <td><code>^B</code> </td>








                    <td>Dark Blue</td>







                  </tr>








                  <tr>







                    <td><code>^R</code> </td>








                    <td>Dark Red</td>







                  </tr>








                  <tr>







                    <td><code>^Y</code> </td>








                    <td>Dark Yellow</td>







                  </tr>








                  <tr>







                    <td><code>^C</code> </td>








                    <td>Dark Cyan</td>







                  </tr>








                  <tr>







                    <td><code>^P</code> </td>








                    <td>Dark Purple</td>







                  </tr>








                  <tr>







                    <td><code>^&lt;</code> </td>








                    <td>&lt; character. Used for MXP tags only.</td>







                  </tr>








                  <tr>







                    <td><code>^&gt;</code> </td>








                    <td>&gt; character. Used for MXP tags only.</td>







                  </tr>








                  <tr>







                    <td><code>^&amp;</code> </td>








                    <td>&amp; character. Used for MXP tags only.</td>







                  </tr>







                
        
        
        
        
        
        
        </tbody>
              
      
      
      
      
      
      
      </table>








              
      
      
      
      
      
      
      <p>As you might have guessed, it is preferred that the system colors (the last 16 codes) be used sparingly, in favor of the more
              customizable codes above.</p>







              <img src="images/mozilla.jpg" alt="Mozilla Javascript" /> 

              
      
      
      
      
      
      
      <h2><a name="javascript" id="javascript">JavaScripting:</a></h2>








              
      
      
      
      
      
      
      <p>JavaScript is an interpreted scripting language which is used
in various parts of CoffeeMud. The CoffeeMud engine integrates the
Rhino Javascript interpretor package from Mozilla in such places as the
Scriptable behavior, the JRun command, the ClassLoader, the Quest
engine, and the web server.</p>








              
      
      
      
      
      
      
      <p>In lieu of a complete write up on the syntax of this language, it is suggested that you read the documentation available from
              the authors of the interpretor here: <a href="http://www.mozilla.org/js/">http://www.mozilla.org/js/</a> and <a href="http://www.mozilla.org/rhino/">http://www.mozilla.org/rhino/</a>.</p>








              
      
      
      
      
      
      
      <p>If you are familiar with writing Javascript for web browsers,
there are several differences you will need to adjust to when using
Javascript in CoffeeMud. A minor difference is that the Rhino
interpretor requires that all variables be declared before use. A more
important difference is that Javascript Strings are not the same as
Java String objects, and that confusing them can lead to errors. To get
around this problem, all of the implementations of Javascript in
CoffeeMud, with the exception of the ClassLoader, Javascript in
CoffeeMud, with the exception of the ClassLoader, provide a special
method to convert Javascript strings into Java Strings before passing
them to Java methods or objects which will require them. An example is
below:</p>







      
      
      
      
      
      
      <pre>var javascriptstring=' this is a javascript string ';<br />var javastring=toJavaString(javascriptstring);<br />// and now javastring is a real-live Java-compliant and Java-friendly string<br /></pre>








              
      
      
      
      
      
      
      <p>When writing Java classes in JavaScript, however, this method is only available through the CMLib object in the core package.
              This is how you would access the <code>toJavaString()</code> method from a class written in JavaScript:</p>







      
      
      
      
      
      
      <pre>var javascriptstring=' this is a javascript string ';<br />var javastring=Packages.com.planet_ink.coffee_mud.core.CMLib.toJavaString(javascriptstring);<br />// and now javastring is a real-live Java-compliant and Java-friendly string<br /></pre>








              
      
      
      
      
      
      
      <p>The most important difference between coding Javascript for
CoffeeMud and for browsers is that there is no HTML DOM (Document
Object Model), and therefore several of the libraries you are used to
are probably missing, such as Math. For this reason, it is necessary
for you to learn the CoffeeMud object packages in order to get access
to useful data and useful libraries. And now you understand why the
JavaScripting notes are kept in the Programming guide. :)</p>








              
      
      
      
      
      
      
      <p>To access the CoffeeMud object packages, you will need to make
use of the Packages object to reference external packages. So long as
the imported objects are in your CoffeeMud classpath, they can be
accessed and used. For instance, to use the CoffeeMud <code>pow(x,y)</code> function in CMParms.java:</p>







      
      
      
      
      
      
      <pre>var lib=Packages.com.planet_ink.coffee_mud.core.CMLib;<br />// the above creates a reference to the CoffeeMud Library as a shortcut<br />var value=lib.math().pow(4,2);<br />// now we can access the math() library from our shortcut.<br /></pre>








              
      
      
      
      
      
      
      <p>Depending upon the context from which your script runs (the
Scriptable behavior, JRun command, the Quest engine, or the http/web
server), certain other objects are made available to assist scripts in
properly interacting with their environment. When writing Java classes
in JavaScript for the ClassLoader, however, you must always use the <code>Packages.com.planet_ink.coffee_mud.core.CMLib</code> reference to access special methods such as the toJavaString method
              discussed above.</p>








              
      
      
      
      
      
      
      <p>In the Scriptable behavior, several methods are made available to access objects which are related to the event which
              triggered the scripted code. These methods include <code>MOB source(), Environmental target(), Environmental host(), Item
              item1(), Item item2(), String message(),</code> and <code>MOB monster()</code>. The JRun command provides the methods <code>MOB
              mob(), int numParms(), String getParm(int i),</code> and <code>String getParms()</code>. The web server makes the
              <code>ExternalHTTPRequests request()</code> object available, as well as the method <code>void write(String s)</code>. The quest
              engine makes the current running Quest object available from the method <code>Quest quest()</code> and the current state of the
              quest setup script available in a custom QuestState object referencing method called <code>QuestState setupState()</code></p>








              
      
      
      
      
      
      
      <p>The last piece of general information about JavaScript in
CoffeeMud concerns writing Java classes for the CoffeeMud ClassLoader.
Any JavaScript file *.js included in the ClassLoader boot paths (see
the previous section) will be loaded and treated just like any Java
compiled *.class file. The JavaScript file would be parsed, compiled,
and loaded at boot time. For the most part, writing Java Classes in
JavaScript is extremely similar to writing Java Classes in Java. Base
classes may be extended (using the special CoffeeMud <code>//extends</code> command in your JavaScript), interfaces may be implemented (using the special
              CoffeeMud <code>//implements</code> command in your JavaScript), super class variables and methods may be accessed (using the
              <code>this.variableName</code> and <code>this.super$methodname()</code>
syntax), and super class methods may be overridden by JavaScript
functions of the same name and number of parameters. Class files
written in Javascript *.js files may also be loaded and unloaded at
runtime using the LOAD and UNLOAD Archon commands, which gives them a
step up on native Java classes in the JVM classpath.</p>








              
      
      
      
      
      
      
      <h3><a name="writingjavascript" id="writingjavascript">Writing your first JavaScript</a></h3>








              
      
      
      
      
      
      
      <p>Below is an example of a Java Class written in JavaScript.
Examples of Embedded JavaScript in CoffeeMud Virtual Pages (cmvp) web
files can be found in the Web Server Guide. Examples of Embedded
JavaScript in a Scriptable MOBPROG script can be found in the Scripting
Guide.</p>








              
      
      
      
      
      
      
      <p>Our Java Class example is called GenLemming.js. It is a sample
MOB class to demonstrate extending the GenMob class to create a type of
modifiable mob for your maps. In this example, we add functionality to
make all mobs in the world created from the GenLemming base suicidal.
To use this class, save the code somewhere in our CoffeeMud folder
under the name "GenLemming.js", and add an object path reference to it
in the MOBS entry in your coffeemud.ini file, as described in section
one.</p>







      
      
      
      
      
      
      <pre>//extends com.planet_ink.coffee_mud.MOBS.GenMob<br /><br />function ID(){return "GenLemming";}<br /><br />var lib=Packages.com.planet_ink.coffee_mud.core.CMLib;<br /></pre>








              
      
      
      
      
      
      
      <p>The first lines of our class include the special //extends command which informs the CoffeeMud ClassLoader that this
              JavaScript class will extend GenMob, thereby inhereting all functionality of the maleable GenMob.</p>








              
      
      
      
      
      
      
      <p>The <code>ID()</code> method is required in all CoffeeMud
classes. It must be the simple name of the class, and must match the
name of the JavaScript file containing it. For example, GenLemming.js
contains class GenLemming and returns an ID of "GenLemming". They all
match exactly.</p>








              
      
      
      
      
      
      
      <p>Lastly, we define the variable "lib" to act as a shortcut to the CoffeeMud core Libraries.</p>








              
      
      
      
      
      
      
      <p>Now, moving on; since we don't have the ability to write constructors in JavaScript, any initial fields we need to set
              whenever a new instance of our class is created must be done in the CoffeeMud <code>newInstance()</code> method as shown
              here:</p>







      
      
      
      
      
      
      <pre>function newInstance()<br />{<br />    var lemm=this.super$newInstance();<br />    lemm.setName("a generic lemming");<br />    lemm.setDisplayText("a generic lemming is waiting to commit suicide");<br />    return lemm;<br />}<br /></pre>








              
      
      
      
      
      
      
      <p>There are several interesting points to make here. One is to
notice that the function has no explicit return type, which is part of
the JavaScript standard of being "weakly typed". Also notice the syntax
for calling the SuperClass version of the <code>newInstance()</code> method -- <code>this.super$newInstance()</code>. This is very different from Java syntax and should be
              noted.</p>








              
      
      
      
      
      
      
      <p>And now we move on to overriding our first GenMob method, tick.</p>







      
      
      
      
      
      
      <pre>var countdown = 10;<br /><br />function tick( host, tickID )<br />{<br />  if( !this.amDead() )<br />  {<br />    countdown--;<br />    if( countdown &lt;= 0 )<br />    {<br />      lib.combat().postDeath( null, this, null );<br />      countdown = 10;<br />    }<br />  }<br />  return this.super$tick( host, tickID );<br />}<br />     <br /></pre>








              
      
      
      
      
      
      
      <p>The <code>public boolean tick(Tickable host, int tickID)</code>
method from the standard MOB interface is designed to be called every
CoffeeMud tick (about 4 seconds). Now, the tick method in StdMOB, which
is extended by GenMob, handles things like recovering hit points,
automatic combat rounds, and other important periodic activities. It is
explained further in Core Topic 3.</p>








              
      
      
      
      
      
      
      <p>For our GenLemming, we create a variable to count down the ticks from 10 to 0. When the countdown variable reaches 0, we call
              the <code>postDeath(MOB killer, MOB killed, CMMsg msg)</code>
method, which is part of the CombatLibrary in the core libraries. "lib"
is the variable we defined above as a shortcut to our core libraries.
The last thing we do is return control to the SuperClass version of the
tick method.</p>








              
      
      
      
      
      
      
      <p>Now we'll get creative and implement a message previewer (see
the Core Topic 1 below for more information on message previewing and
handling). This method will be called when any event happens in the
same room as the GenLemming mob. We will use this fact to look for,
capture, and modify the message string which will inform the room of
our impending death. Since it is the previewing method, it will be
called BEFORE the activity actually takes place, giving us a chance to
make our modifications before anyone actually sees the message strings.</p>







      
      
      
      
      
      
      <pre>function okMessage(host,msg)<br />{<br />  if( ( msg.isSource( this ) )<br />      &amp;&amp;( msg.isOthers( "DEATH" ) )<br />      &amp;&amp;( msg.othersMessage() != null )<br />    )<br />  {<br />    msg.setOthersMessage("&lt;S-NAME&gt; jumps off a cliff!!!");<br />  }<br /><br />  return this.super$okMessage(host,msg);<br />}<br /></pre>








              
      
      
      
      
      
      
      <p>In our message previewing method, we will check every message that comes our way, acting only if this particular GenLemming is
              the source of the message, that he appears to be dying to others in the room <code>( isOthers( "DEATH" ) )</code>
and that the message being given to others in the room is a non-null
string. In these conditions, we modify the message which others in the
room see. When our condition is not met, we return control to the
SuperClass-GenMob version of okMessage.</p>







              <img src="images/kiss.jpg" alt="Getting the Message" /> 

              
      
      
      
      
      
      
      <h2><a name="DIG1" id="DIG1">Core Topic 1: Getting the Message:</a></h2>








              
      
      
      
      
      
      
      <p>CoffeeMud is essentially a distributed message passing and
handling system, where the actions and events that occur in the system
are represented as messages (Common.interfaces.CMMsg) which are then
previewed, modified, cancelled, and/or reacted to by handlers.
Understanding this idea is key to fully understanding how CoffeeMud
really works, so let's take a second and peruse this concept in more
detail.</p>








              
      
      
      
      
      
      
      <p>Messages in CoffeeMud, at least as we are talking about them
here, always represent Events. Events such as a mob picking up an item,
swinging a sword at an opponent, taking damage from a fireball, or
getting pricked by a poisonous needle. These events can never actually
occur in CoffeeMud unless a proper message is generated for them first.
These messages, in the code, implement the interface <code>Common.interfaces.CMMsg</code>, and are typically an instance of the class
              <code>Common.DefaultMessage</code>.</p>








              
      
      
      
      
      
      
      <p>Messages are created at the moment that the event needs to
occur. This moment can be triggered by the player entering a command
into their telnet client and pressing Enter. It can also by triggered
by the mindless algorithms which animate the mobs. Either way, when the
moment has come, a message is created, and it looks like this:</p>







      
      
      
      
      
      
      <pre>CMMsg msg = CMClass.getMsg(mob, targetMOB, this,<br />     CMMsg.MSG_CAST_ATTACK_VERBAL_SPELL,"^S&lt;S-NAME&gt; invoke a spell at &lt;T-NAME&gt;s feet..^?",<br />     CMMsg.MSG_CAST_ATTACK_VERBAL_SPELL,"^S&lt;S-NAME&gt; invoke(s) a spell at your feet.^?",<br />     CMMsg.MSG_CAST_ATTACK_VERBAL_SPELL,"^S&lt;S-NAME&gt; invokes a spell at &lt;T-NAME&gt;s feet.^?"<br />     );<br /><br /></pre>








              
      
      
      
      
      
      
      <p>The above message was taken from the code for the Grease spell, which calls the <code>core.CMClass.getMsg</code>
method to construct a CMMsg object. Constructing the CMMsg object does
not actually make anything happen, but it is the vital first step. The
message we constructed here, in this case, utilizes every major
component of a message. These components are, in order:</p>








              
      
      
      
      
      
      
      <ul>







                <li>
                  Source 

                  
          
          
          
          
          
          
          <p>The source of any message must always be a valid reference
to an instance of the MOB interface. In short, all events that occur in
the system are a direct result of the activity of a MOB. This is on the
theory that the universe is controlled and governed by sentience. In
the extremely rare instances where a mob is not readily available to
provide a message source, one should be instantiated -- even if it is
just a blank, new StdMOB.</p>







                </li>








                <li>
                  Target 

                  
          
          
          
          
          
          
          <p>The target of a message may be null, or any valid
reference to an instance of the Environmental interface, which includes
Items, MOBs, Rooms, Exits, etc. The type and context of message you
wish to generate will typically tell you intuitively whether the source
is doing something to someone or something else, or is acting
independently. This is usually another mob or an item, but you will
find examples of all kinds of targets in the code.</p>







                </li>








                <li>
                  Tool 

                  
          
          
          
          
          
          
          <p>The tool of a message may be null, or any valid reference
to an instance of the Environmental interface, which includes Items,
Abilities, MOBs, Rooms, Exits, etc. The tool represents something which
the source is utilizing to accomplish the task or generate the event.
This is typically either an Ability object (like a Spell or Skill being
used), or an Item object (like a weapon in an attack event).</p>







                </li>








                <li>
                  Source Code 

                  
          
          
          
          
          
          
          <p>This is an encoded integer which represents what the source MOB is actually doing. We'll break down this code below.</p>







                </li>








                <li>
                  Source Message 

                  
          
          
          
          
          
          
          <p>This is the string which the source MOB will see should the event occur successfully.</p>







                </li>








                <li>
                  Target Code 

                  
          
          
          
          
          
          
          <p>This is an encoded integer which represents what is happening to the target. If there is no target, this number will
                  typically have the value of 0 (CMMsg.NOEFFECT).</p>







                </li>








                <li>
                  Target Message 

                  
          
          
          
          
          
          
          <p>This is the string which the target MOB (if it is a MOB) will see should the event occur successfully. If there is no
                  target, this string is null.</p>







                </li>








                <li>
                  Others Code 

                  
          
          
          
          
          
          
          <p>This is an encoded integer which represents how any other
objects (such as MOBs, Items, Rooms, Exits) other than the source and
target, in the same room, perceive the event. If the event is
completely imperceptible by anything other than the source, it may be 0
(CMMsg.NOEFFECT)</p>







                </li>








                <li>
                  Others Message 

                  
          
          
          
          
          
          
          <p>This is the string which other MOBs in the same room as the source and target MOBs will see should the event occur
                  successfully. If the event is completely imperceptible by other MOBs, it may be null.</p>







                </li>







              
      
      
      
      
      
      
      </ul>








              
      
      
      
      
      
      
      <p>The Source Code, Target Code, and Others Code is easily the
most complicated aspect of a Message. For this reason, numerous
pre-configured message codes have been created in the CMMsg interface,
all of which begin with the characters MSG_. Although we will not go
into the meaning of each of these messages (that will be left to the
reader to search the code for instances of messages which use the
codes, and learn from the context in which they are used), we can at
least break down these codes so that they can be better understood.</p>








              
      
      
      
      
      
      
      <p>These coded integers all have two parts, the Major aspect (or the Major Code) and the Minor aspect (or the Minor Code). They
              may be referenced off of an already constructed CMMsg object using such methods as <code>sourceMajor()</code> and
              <code>sourceMinor()</code>. These methods will automaticallyy break down a <code>sourceCode()</code> into the components we will
              discuss.</p>








              
      
      
      
      
      
      
      <p>The Major code is a series of significant bits in the integer, each of which gives some new meaning to the message. These bits
              are as follows:</p>







              <a name="majorcode" id="majorcode"></a> 

              
      
      
      
      
      
      
      <table bgcolor="#ffccff" border="1">







                <thead>
                  <tr>







                    <th width="15%">Bit mask</th>








                    <th width="30%">CMMsg Equate Variable(s)</th>








                    <th>Meaning</th>







                  </tr>







                </thead>

                <tbody>







                  <tr>







                    <td>2048</td>








                    <td>
                      
            
            
            
            
            
            
            <p>MASK_HANDS</p>







                    </td>








                    <td>Message includes small movements.</td>







                  </tr>








                  <tr>







                    <td>4096</td>








                    <td>
                      
            
            
            
            
            
            
            <p>MASK_MOVE</p>







                    </td>








                    <td>Message includes large, full-body movements.</td>







                  </tr>








                  <tr>







                    <td>8192</td>








                    <td>MASK_EYES</td>








                    <td>Message includes visual information.</td>







                  </tr>








                  <tr>







                    <td>16384</td>








                    <td>MASK_MOUTH</td>








                    <td>Message include mouth movement, or consumption.</td>







                  </tr>








                  <tr>







                    <td>32768</td>








                    <td>MASK_SOUND, MASK_SOUNDEDAT</td>








                    <td>Message includes auditory information.</td>







                  </tr>








                  <tr>







                    <td>65536</td>








                    <td>MASK_ALWAYS</td>








                    <td>Override mask which flags the message as something which Must occur, regardless of the state of the source or
                    target.</td>







                  </tr>








                  <tr>







                    <td>131072</td>








                    <td>MASK_MAGIC</td>








                    <td>Message has a magical nature.</td>







                  </tr>








                  <tr>







                    <td>262144</td>








                    <td>MASK_DELICATE</td>








                    <td>Message includes very fine, delicate movements, such as thief skills.</td>







                  </tr>








                  <tr>







                    <td>524288</td>








                    <td>MASK_MALICIOUS</td>








                    <td>Message represents an attack of some sort.</td>







                  </tr>








                  <tr>







                    <td>1048576</td>








                    <td>MASK_CHANNEL</td>








                    <td>Message is part of public channel conversation.</td>







                  </tr>








                  <tr>







                    <td>2097152</td>








                    <td>MASK_OPTIMIZE</td>








                    <td>Message implementation should be optimized for repetition.</td>







                  </tr>







                
        
        
        
        
        
        
        </tbody>
              
      
      
      
      
      
      
      </table>








              
      
      
      
      
      
      
      <p>The above masks can be quite confusing. It is best to examine
the several MSG_ equates in the CMMsg interface to see how they are
properly or improperly used. Remember a MSG_ equate is a completely
constructed Code, complete with the appropriate Major and Minor aspects.</p>








              
      
      
      
      
      
      
      <p>The Minor Code represents the more specific activity being
performed, and is a simple integer ranging from 0 (NO EFFECT) to 2047.
The officially recognized Minor codes are exhaustively listed in the
CMMsg interface, and all begin with the prefix TYP_. These types cover
every sort of major event which occurs in the CoffeeMud engine,
including getting items, casting spells, entering or leaving rooms,
etc, etc..</p>







      
      
      
      
      
      
      <pre>CMMsg msg = CMClass.getMsg(attacker,target,weapon,CMMsg.MSG_WEAPONATTACK,<br />          "&lt;S-NAME&gt;attack(s) &lt;T-NAME&gt;!");<br /></pre>








              
      
      
      
      
      
      
      <p>The core.CMClass has many different getMsg signatures to make
message construction quick and painless. The above is an example where
only a single Code and a single message text are provided. In
constructors where only one Code or message text field are provided, it
is assumed that the code and message texts will be the same for source,
target (if any) and others.</p>








              
      
      
      
      
      
      
      <p>CMMsg objects also have <code>value()</code> and <code>setValue(int)</code>
methods for modifying an integer not found in the constructor. This
number is used for several different purposes in message construction,
from the amount of damage in a TYP_DAMAGE message, to the amount of
experience in a TYP_EXPCHANGE message. This number is also used to
determine whether or not a standard saving throw was made. Value
defaults to 0, but, after running through a message which contains a
savable event, the value will be &gt;0 if the save was made.</p>








              
      
      
      
      
      
      
      <h3><a name="messagepreview" id="messagepreview">Message Previewing</a></h3>








              
      
      
      
      
      
      
      <p>Once a Message has been constructed, it is time to actually
put the message out into the system. There is a standard form for the
sending of almost all messages. If the source of the message is a MOB
called "SourceMOB", this standard form looks like this:</p>







      
      
      
      
      
      
      <pre>CMMsg msg = CMClass.getMsg(SourceMOB,TargetMOB,weapon,CMMsg.MSG_WEAPONATTACK,<br />          "&lt;S-NAME&gt;attack(s) &lt;T-NAME&gt;!");<br /><br />if(SourceMOB.location().okMessage(SourceMOB,msg))<br />{<br />     SourceMOB.location().send(SourceMOB,msg);<br />}<br /></pre>








              
      
      
      
      
      
      
      <p>The <code>location()</code> field on a MOB refers to the Room
in which the mob is. Room's are always the top level at which messages
are previewed, and then executed or sent. The first line (where the
message is constructed) has already been examined. The second line, in
which the Room method <code>okMessage()</code> is called, is the preview step. In this step, the message is
              evaluated before it actually happens. The first parameter to <code>okMessage()</code>
is called the "host" object, and it refers to the object to which the
one you are sending the message should refer back to. This parameter is
rarely used, except by Behaviors, and it is always safe to use the
source of your message as this value. The second parameter to <code>okMessage()</code> is the message we constructed. The third line, where the Room <code>send()</code> method is called, is
              the execution step.</p>








              
      
      
      
      
      
      
      <p>In the preview step, the room object will examine the message
to see if there is anything which it might not like, wish to modify, or
wish to flag about the Message it has been handed. If the Room object
does not like the message, it will return false. Returning false from <code>okMessage()</code> is always an order to cancel, and not execute the message. Under any other
              circumstances, true may be returned to allow the message to go forward. The Room will also make calls to the
              <code>okMessage()</code> methods on every other MOB in the room, Exit from the room, Item in the room, spell effects which may be
              on the room, and behaviors of the room. The MOB who receives the <code>okMessage()</code> call will, in turn, pass the Message to
              the <code>okMessage()</code> methods in every Item the MOB is carrying or wearing, every spell effect on the MOB, and every
              behavior of the MOB. Items wills also make <code>okMessage()</code>
calls on their spell effects. Any of these calls may modify or flag the
message they receive. Any of these calls may also return false. If any
object which previews a message returns false, the Room <code>okMessage()</code> method will also return false, ordering the message to be totally canceled. For this reason,
              <code>okMessage()</code> methods are careful about returning true unless they have a really good reason not to.</p>








              
      
      
      
      
      
      
      <p>Inside the <code>okMessage()</code> methods of every Item,
MOB, Behavior, Ability (spell effect), Exit, and Room the Messages may
(as we mentioned) be examined and modified, flagged, or canceled. As we
have already covered how Messages are canceled (by returning false).
Let us turn now to the manner in which Messages are modified or flagged.</p>








              
      
      
      
      
      
      
      <h3><a name="messageflagging" id="messageflagging">Message Flagging and Modification</a></h3>








              
      
      
      
      
      
      
      <p>Message modification is very rare. When it happens though, it is done by calling one of the several <code>modify()</code>
methods on the Common.interfaces.CMMsg object. These methods allow the
source, target, and all other fields to be updated. Message
modification should also happen during the preview step so that any
changes made to the message are made before the message is executed. It
is also often wise, after making a change to a message, to recursively
call the okMessage method on the room again so that the modifications
can be previewed, but this is not always necessary.</p>








              
      
      
      
      
      
      
      <p>Message flagging is somewhat less rare. Messages may be
flagged when a combat strike is successful, or when a saving throw is
made against a spell Effect, or for any other reason the Message
constructing code may wish. Flagging is done by calling the
aforementioned <code>CMMsg.setValue(int)</code> method, and using it to change the value to something other than the default of
              0. Flagging using the <code>setValue()</code>
method lets the code which constructed the Message know that something
significant with relation to the Message has occurred. The meaning of
this value will vary depending upon the type of message being
generated, and upon the purpose to which the creator of the message
wishes to put it. The value is read using the <code>int
              value()</code> method on CMMsg.</p>








              
      
      
      
      
      
      
      <h3><a name="messageexecution" id="messageexecution">Message Execution</a></h3>








              
      
      
      
      
      
      
      <p>Once the <code>okMessage()</code> method on a Room object has
returned true, and any code which may need to check or handle
modifications to the Message have executed, the Message is sent. The
proper way to send a Message is through the Room objects, by calling
one of the following Messages: <code>Room.send(MOB SourceMOB, CMMsg msg)</code> or <code>Room.sendOthers(MOB SourceMOB,
              CMMsg msg)</code>. The first method handles a standard Execution, while the second allows every relevant object except the
              SourceMOB to handle Execution. The first method should almost always be called.</p>








              
      
      
      
      
      
      
      <p>The <code>send()</code> methods will then begin calling other methods in other objects. These other methods are called the
              <code>executeMsg()</code> methods, and are usually of the form <code>public void executeMsg(Environmental myHost, CMMsg
              msg);</code>. These methods are responsible for Executing the contents of the message. The Room method will make
              <code>executeMsg()</code> method calls on itself, and on every Exit, Item, MOB, spell effects (Ability object), and Behavior
              associated with that Room. As in the <code>okMessage()</code> case, the MOBs will in turn call the <code>executeMsg()</code>
              methods on their own Items and spell effects. Items will then call the <code>executeMsg()</code> methods on their own spell
              effects, and so on.</p>








              
      
      
      
      
      
      
      <p>Of course, not every object in your game will handle and react
to the Execution of every Message sent. Most of the time, a given
object will be ignoring the Message altogether. However, each object
knows precisely which Messages are important for it, and watch
carefully for them in both their <code>okMessage()</code> and <code>executeMsg()</code> methods. In general, every
              Message which is previewed in an objects <code>okMessage()</code> method is handled in the <code>executeMsg()</code>
method of the same object, though this is by no means always true. In
general, the following object types handle the following types of
Messages:</p>








              
      
      
      
      
      
      
      <ul>







                <li>
                  MOBs 

                  
          
          
          
          
          
          
          <p>Any Message which has the mob instance as a target is both Previewed and Executed. Any Message which has the mob as a
                  source is typically Previewed, and (lacking a target) may also be Executed.</p>







                </li>








                <li>
                  Items 

                  
          
          
          
          
          
          
          <p>Any Message which has the item instance as a target.</p>







                </li>








                <li>
                  Exits 

                  
          
          
          
          
          
          
          <p>Any Message which has the exit instance as a target or tool.</p>







                </li>








                <li>
                  Rooms 

                  
          
          
          
          
          
          
          <p>Any Message which has the room instance as a target.</p>







                </li>








                <li>
                  Ability(spell effects) 

                  
          
          
          
          
          
          
          <p>Any Message pertaining to the MOB or Item which is affected by the spell or skill.</p>







                </li>








                <li>
                  Behavior 

                  
          
          
          
          
          
          
          <p>Any Message pertaining to the object instance which has this behavior.</p>







                </li>







              
      
      
      
      
      
      
      </ul>








              
      
      
      
      
      
      
      <p>Now that you are completely confused, it will make you at least a bit happier to know that Room objects have several short-cut
              methods for creating, previewing, and executing messages. They include the following:</p>







      
      
      
      
      
      
      <pre>public boolean show( MOB source,<br />                     Environmental target,<br />                     int allCode,<br />                     String allMessage<br />                   );<br /><br />public boolean show( MOB source,<br />                     Environmental target,<br />                     Environmental tool,<br />                     int allCode,<br />                     String allMessage<br />                   );<br /><br />public boolean show( MOB source,<br />                     Environmental target,<br />                     Environmental tool,<br />                     int srcCode,<br />                     int tarCode,<br />                     int othCode,<br />                     String allMessage<br />                   );<br /><br />public boolean show( MOB source,<br />                     Environmental target,<br />                     Environmental tool,<br />                     int srcCode,<br />                     String srcMessage,<br />                     int tarCode,<br />                     String tarMessage,<br />                     int othCode,<br />                     String othMessage<br />                   );<br /><br />public boolean show( MOB source,<br />                     Environmental target,<br />                     Environmental tool,<br />                     int allCode,<br />                     String srcMessage,<br />                     String tarMessage,<br />                     String othMessage<br />                   );<br /><br />public boolean showOthers( MOB source,<br />                           Environmental target,<br />                           int allCode,<br />                           String allMessage<br />                         );<br /><br />public boolean showOthers( MOB source,<br />                           Environmental target,<br />                           Environmental tool,<br />                           int allCode,<br />                           String allMessage<br />                         );<br /><br />public boolean showSource( MOB source,<br />                           Environmental target,<br />                           int allCode,<br />                           String allMessage<br />                         );<br /><br />public boolean showSource( MOB source,<br />                           Environmental target,<br />                           Environmental tool,<br />                           int allCode,<br />                           String allMessage<br />                         );<br /><br />public void showHappens(int allCode, String allMessage);<br /><br />public void showHappens( int allCode,<br />                         Environmental like,<br />                         String allMessage<br />                       );<br /></pre>








              
      
      
      
      
      
      
      <p>The first methods (show) is very commonly used; it constructs a message with the given source and target (no tool), and with
              the given Code and text message applying to source, target, and others. The <code>showHappens()</code>
methods will do the same, but will also construct a blank MOB object to
act as the source, for those instances where a source MOB is not
readily available. The <code>showOthers()</code> methods behave like the first, but do not allow the source MOB to preview or execute the message,
              while the <code>showSource()</code> methods ONLY allows the source MOB to preview and execute the message.</p>








              
      
      
      
      
      
      
      <p>All four of those methods will construct a CMMsg object, give
the Message to the Room object for previewing ("okMessage"), and then,
if the Message is not canceled, will call the Room "send" method for
execution and return true. If the Message was canceled, false will be
returned.</p>








              
      
      
      
      
      
      
      <h3><a name="messagetrailers">Message Trailers</a></h3>








              
      
      
      
      
      
      
      <p>The final subject we will discuss in the area of Messages and Message handling regards another rare technique called Message
              Trailer adding. Message Trailers are CMMsg objects which have been added to another CMMsg instance using the
              <code>CMMsg.addTrailerMsg(CMMsg msg)</code>
method. The Message passed to this method is constructed in the usual
way. This method may be properly called at any point during the Preview
or Execution stage of Message handling, by any Previewing or Executing
object. When it is performed is not important, because any Messages
added using this method are not Previewed or Executed until after the
Room object has completely finished sending the host Message to all
interested objects.</p>








              
      
      
      
      
      
      
      <p>Constructing and adding messages which act as message trailers
can serve many purposes, but the most important of which is that the
trailer messages only happen IF the host message also happens, and only
happen AFTER the host message happens. This can be useful for the
timing of subsequent messages which are dependent on others.</p>







              <img src="images/temple.jpg" alt="The State of Things" /> 

              
      
      
      
      
      
      
      <h2><a name="DIG2" id="DIG2">Core Topic 2: The State of Things:</a></h2>








              
      
      
      
      
      
      
      <p>In most systems, it is typical for all of the data variables
which describe a particular object to be coded directly inside that
object. While this is also true in CoffeeMud, many important data
fields, along with the appropriate "getter" and "setter" methods, are
stored in separate special data-storage, or state objects. These
data-storage objects provide access to numerous important properties
for those objects. These storage/state objects are routinely copied and
then the copies are modified by other objects which have a spacial
relationship with them. For instance, a MOB object may copy one or more
of its state objects, and then allow the local Room object, or his
inventory Item objects, or spell Effect objects to modify the copy, The
copied state object modifications are stacked on each other. Confused?
Well, keep reading!</p>








              
      
      
      
      
      
      
      <p>Each instance of the several Environmental objects (MOBs,
Items, Exits, Rooms) have a particular storage/state object called
their Environmental Stats. This object implements the
Common.interfaces.EnvStats interface, and is typically an instance of
the Common.DefaultEnvStats class. Access to this state object is
available through each core.interfaces.Environmental objects <code>EnvStats baseEnvStats()</code> and <code>EnvStats envStats()</code> method calls. Since Rooms, MOBS, Items, Exits, and
              Areas are all Environmental objects, that means that they all have baseEnvStats and envStats methods as well.</p>








              
      
      
      
      
      
      
      <h3><a name="envstats" id="envstats">EnvStats state object fields</a></h3>








              
      
      
      
      
      
      
      <table bgcolor="#ccccff" border="1">







                <thead>
                  <tr>







                    <th>Field name</th>








                    <th>Relevant objects</th>








                    <th>Meaning</th>







                  </tr>







                </thead>

                <tbody>







                  <tr>







                    <td>level</td>








                    <td>Item, MOB, Exit</td>








                    <td>Experience level (see Archon's Guide)</td>







                  </tr>








                  <tr>







                    <td>ability</td>








                    <td>Item, MOB</td>








                    <td>Magical level (see Archon's Guide)</td>







                  </tr>








                  <tr>







                    <td>rejuv</td>








                    <td>Item, MOB</td>








                    <td>Rejuvenation rate (see Archon's Guide)</td>







                  </tr>








                  <tr>







                    <td>weight</td>








                    <td>Item, MOB</td>








                    <td>Weight of the object</td>







                  </tr>








                  <tr>







                    <td>height</td>








                    <td>Armor, MOB</td>








                    <td>Size of the object</td>







                  </tr>








                  <tr>







                    <td>armor</td>








                    <td>Item, MOB</td>








                    <td>Protection level (see Archon's Guide)</td>







                  </tr>








                  <tr>







                    <td>damage</td>








                    <td>Item, MOB</td>








                    <td>Damaging ability</td>







                  </tr>








                  <tr>







                    <td>speed</td>








                    <td>Item, MOB</td>








                    <td>Attack speed</td>







                  </tr>








                  <tr>







                    <td>attackAdjustment</td>








                    <td>Item, MOB</td>








                    <td>Attack level</td>







                  </tr>








                  <tr>







                    <td>replacementName</td>








                    <td>Item, MOB, Exit</td>








                    <td>New displayable name of the object</td>







                  </tr>








                  <tr>







                    <td>sensesMask</td>








                    <td>Item, MOB, Exit, Room</td>








                    <td>Bit mask of relevant sensory abilities.</td>







                  </tr>








                  <tr>







                    <td>disposition</td>








                    <td>Item, MOB, Exit, Room</td>








                    <td>Bit mask of relevant disposition state</td>







                  </tr>







                
        
        
        
        
        
        
        </tbody>
              
      
      
      
      
      
      
      </table>








              
      
      
      
      
      
      
      <p>Although most of these fields are better described in the
Archon's Guide, there are two whose nature may not be readily apparent:
the sensesMask and the disposition. These two integers are bitmaps. The
value of each bit is defined by equates in the
Common.interfaces.EnvStats interface. The equates which refer to the
bits for sensesMask all begin with "CAN_", while the equates which
refer to the bits for disposition all begin with "IS_".</p>








              
      
      
      
      
      
      
      <p>Now, as mentioned previously, all Environmental objects have two methods for accessing their EnvStats. One is
              <code>core.interfaces.Environmental.baseEnvStats()</code> and the other is <code>core.interfaces.Environmental.envStats()</code>.
The difference between these two methods is very significant. The
EnvStats state object returned by the "baseEnvStats" method refers to
the permanent, unmodified, "base" state of the Environmental object.
The "envStats" method, however, returns the modified, less permanent,
"current" state of the Environmental object. The EnvStats object
returned by the "envStats" method is always copied and derived from the
"baseEnvStats" values, after all relevant modifications have been made
to it. How the current state object goes from its base values
(baseEnvStats) to its current values (envStats) is our next topic.</p>








              
      
      
      
      
      
      
      <p>We must now introduce two other Environmental interface methods significant to this topic. One is the
              <code>recoverEnvStats()</code> method, while the other is the <code>affectEnvStats(Environmental affected, EnvStats
              affectableStats)</code> method. The "recoverEnvStats" method is also located on every Environmental (Item, MOB, Exit, etc) object
              and is the method which turns the <code>baseEnvStats()</code> values into their current <code>envStats()</code>
values. This method call works by copying the base values into the
current values and then allowing certain other objects to have an
opportunity to affect the copy. Only after all opportunities to modify
the copied values have been exhausted, does the <code>recoverEnvStats()</code> method return. In essence, <code>recoverEnvStats()</code> allows the Environmental objects
              <code>baseEnvStats()</code> to be updated, with that updated state object made available through <code>envStats()</code>.</p>








              
      
      
      
      
      
      
      <p>The way in which the current EnvStats state object is modified by the <code>recoverEnvStats()</code> method call is by making
              repeated internal calls to the <code>affectEnvStats(Environmental affected, EnvStats affectedStats)</code>
methods on other relevant objects. These methods will then have the
opportunity to change the values in the current state object
(affectedStats parameter) however they wish. The relevant objects which
may change the state of an Environmental are as follows:</p>








              
      
      
      
      
      
      
      <ul>







                <li>
                  MOBs 

                  
          
          
          
          
          
          
          <p>Room object being occupied, something being Ridden, the MOBs Character Class object, the MOBs Race object, the Items in
                  the MOBs inventory, and finally the Ability objects which are affecting the MOB (spell effects).</p>







                </li>








                <li>
                  Items, Exits, Areas 

                  
          
          
          
          
          
          
          <p>Ability objects which are affecting it (spell effects).</p>







                </li>








                <li>
                  Rooms 

                  
          
          
          
          
          
          
          <p>Area object which this room is a part of, Ability objects which are affecting it (spell effects), Items in the Room, and
                  MOBs in the Room.</p>







                </li>







              
      
      
      
      
      
      
      </ul>








              
      
      
      
      
      
      
      <p>Here is an example:</p>








              
      
      
      
      
      
      
      <p>Gunker the Thief wears Full Plate Armor (Item), and has the
Shield spell cast on him. His base Armor rating is 100. When he puts on
the Plate Armor, the "recoverEnvStats" method is called on Gunker's MOB
object. That method in turn calls the "affectEnvStats" method on the
Plate Armor and the Shield spell Effect. Both of those methods improve
the Armor rating on Gunker's MOB's current EnvStats by some number.
Thus, Gunker becomes harder to hit in combat. Also, when Gunker picked
up the Plate armor, the weight of the armor was added to Gunker's
overall carried weight by increasing the weight value in Gunker's
EnvStats object.</p>








              
      
      
      
      
      
      
      <p>I know, this is probably still confusing.</p>








              
      
      
      
      
      
      
      <p>Confusing or not, however, we still have to consider two other state objects, both of which are only available from the MOB
              object. One of which is the CharStats object, and the other of which is the CharState object.</p>








              
      
      
      
      
      
      
      <p>The CharStats objects are most closely analogous to the EnvStats objects. For instance, there are <code>CharStats
              baseCharStats()</code> and <code>CharStats charStats()</code> method calls from a MOB object, as well as a
              <code>recoverCharStats()</code>
method call. All of these work similarly to the ones described above
for EnvStats. The fields on a Common.interfaces.CharStats object are
somewhat more straight forward however. Most of the fields of a
CharStats object are referenced using the <code>int getStat(int)</code> and <code>setStat(int,int)</code>
methods on a CharStats object. Both of these methods require, as their
first parameter, an integer code which corresponds to the specific stat
being set or read. These stat parameters are defined as equates within
the CharStats interface, and include:</p>








              
      
      
      
      
      
      
      <p><a name="charstats" id="charstats"></a> STAT_STRENGTH,
STAT_INTELLIGENCE, STAT_DEXTERITY, STAT_CONSTITUTION, STAT_CHARISMA,
STAT_WISDOM, STAT_GENDER, STAT_SAVE_PARALYSIS, STAT_SAVE_FIRE,
STAT_SAVE_COLD, STAT_SAVE_WATER, STAT_SAVE_GAS, STAT_SAVE_MIND,
STAT_SAVE_GENERAL, STAT_SAVE_JUSTICE, STAT_SAVE_ACID,
STAT_SAVE_ELECTRIC, STAT_SAVE_POISON, STAT_SAVE_UNDEAD,
STAT_SAVE_MAGIC, STAT_SAVE_DISEASE, STAT_SAVE_TRAPS,
STAT_MAX_STRENGTH_ADJ, STAT_MAX_INTELLIGENCE_ADJ,
STAT_MAX_DEXTERITY_ADJ, STAT_MAX_CONSTITUTION_ADJ,
STAT_MAX_CHARISMA_ADJ, STAT_MAX_WISDOM_ADJ, STAT_AGE,
STAT_SAVE_DETECTION, STAT_SAVE_OVERLOOKING.</p>








              
      
      
      
      
      
      
      <p>In addition to these equates defined and read through the <code>getStat()</code> and <code>setStat()</code> methods, there is
              also the Race object available through <code>getMyRace()</code> and <code>setMyRace()</code>
methods, as well as Character Class and Character Class level methods.
See the Common.interfaces.CharStats java file for more information on
those methods and how they work.</p>








              
      
      
      
      
      
      
      <p>Like the EnvStats above, those objects listed as able to
modify the EnvStats current state object are the same objects which are
able to modify the CharStats state objects. Rereading the section on
EnvStats will make clear how the CharStats objects are modified in the
same analogous manner, using repeated calls to<code>affectCharStats(MOB affected, CharStats affectedStats)</code>
              methods on related objects.</p>








              
      
      
      
      
      
      
      <p><a name="charstate" id="charstate"></a> The last state object
to consider is the Common.interfaces.CharState objects on MOBs. The
CharState object represents those fields which are constantly in flux:
Hit Points, Mana, Movement, Hunger, Fatigue, and Thirst.</p>








              
      
      
      
      
      
      
      <p>Unlike EnvStats and CharStats, there are three CharState objects to consider for MOBs: the base CharState object (available
              through<code>CharState baseState()</code> method, the adjusted base CharState (or max state) object available through the
              <code>CharState maxState()</code> method and modified by <code>recoverMaxState(MOB affected, CharState affectedState)</code>
              methods on related objects, and lastly the current CharState object available through the <code>CharState curState()</code> and
              refreshed or reset to maximums using the MOBs <code>resetToMaxState()</code> method.</p>








              
      
      
      
      
      
      
      <p>The relationship between the above objects is as follows: The
base CharState object represents the maximum values for the state
variables BEFORE modification by magical armor or spells. The adjusted
base CharState object (Max State) represents the maximum values for the
state variables AFTER modification by magical armor or spells. The
current CharState object (curState) represents the current hit points,
mana points, etc available to the MOB.</p>








              
      
      
      
      
      
      
      <p>In the case of the CharState objects, adjustment by relevant objects is initiated by calling the MOBs
              <code>recoverMaxState()</code> method. This method allows the same objects who modify the EnvStats and CharStats above to modify
              the maximum CharState values as well.</p>








              
      
      
      
      
      
      
      <p>Once again, to understand one of them fully is to understand them all.</p>







              <img src="images/time.jpg" alt="Tick Tock" /> 

              
      
      
      
      
      
      
      <h3><a name="DIG3" id="DIG3">Core Topic 3: Tick Tock</a></h3>








              
      
      
      
      
      
      
      <p>Our last Core Topic will cover the ability of the mobs, items, exits, abilities, spell effects, behaviors, and other objects
              to perform tasks on a regular, timed, basis. The tasks to be performed are always located within an method called <code>boolean
              tick(Tickable ticking, int tickID)</code>. All Environmental objects define this method, and Behavior objects do as well.</p>








              
      
      
      
      
      
      
      <p>These methods are called on a regular, timed basis whenever
the object instance in question has been properly set up to do so, and
at a defined frequency and interval. The "ticking" parameter is usually
a reference to the object itself, or to the host object in the case of
Behaviors. The "tickID" parameter describes what sort of regular timed
event is occurring. These events are defined as equates in the
core.interfaces.Tickable interface, and inc

Showing the first 100 KB of 387.7 KB. Download the archive for the full file.

Site Stats

Snippets: 1791
Codebases: 571