[ogs-changes] dist/java/ogs/core BodyPart.java,NONE,1.1 Strength.java,NONE,1.1 Abilities.java,1.4,1.
Status: Alpha
Brought to you by:
elemings
Update of /cvsroot/ogs/dist/java/ogs/core
In directory sc8-pr-cvs1:/tmp/cvs-serv9450/java/ogs/core
Modified Files:
Abilities.java Ability.java CClass.java Creature.java
Feat.java Feature.java Skill.java
Added Files:
BodyPart.java Strength.java
Log Message:
See ChangeLog files (Apr 3-4) for details.
--- NEW FILE: BodyPart.java ---
/*
* BodyPart.java -- class declaration for body parts
* Copyright (C) 2003 Eric Lemings <ele...@us...>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA
*
* RCS: $Id: BodyPart.java,v 1.1 2003/04/04 20:22:50 elemings Exp $
*/
package ogs.core;
import java.util.Collection;
import java.util.Vector;
import ogs.core.Creature;
import ogs.core.Item;
/**
* A part of the body where items can be equipped. An eqipped item is
* worn, held, or used somehow. The body part determines how many items
* can be equipped and how they are equipped. A normal human hand for
* example can wear one glove, five rings, and hold one item. This
* class defines humanoid body parts. Body parts of other creatures
*(such as tails, wings, horns, whatever) may be defined by other
* classes.
*/
public class BodyPart {
public static final byte HEAD = 1;
public static final byte EYES = 2;
public static final byte LEFT_EYE = 3;
public static final byte RIGHT_EYE = 4;
public static final byte NECK = 5;
public static final byte TORSO = 6;
public static final byte BACK = 7;
public static final byte ARMS = 8;
public static final byte LEFT_ARM = 9;
public static final byte RIGHT_ARM = 10;
public static final byte HANDS = 11;
public static final byte LEFT_HAND = 12;
public static final byte RIGHT_HAND = 13;
public static final byte WAIST = 14;
public static final byte LEGS = 15;
public static final byte LEFT_LEG = 16;
public static final byte RIGHT_LEG = 17;
public static final byte LEFT_FOOT = 18;
public static final byte RIGHT_FOOT = 19;
private Creature creature = null;
private byte type = 0;
private Vector items = null;
/**
* Create a new body part. The type of body part does not have to be
* one of the predefined humanoid body parts. It can be any body part
* specific to a particular creature such as tails, wings, horns, or
* whatever. The type value of the body part however must not
* conflict with one of the predefined types. The new body part has
* not equipped items.
*
* @param creature Creature that this body part belongs to.
* @param type Type of body part.
*/
public BodyPart (Creature creature, byte type) {
this.creature = creature;
this.type = type;
this.items = new Vector ();
}
/**
* Determine the creature that this body part belongs to.
*
* @return Creature that this body part belongs to.
*/
public Creature getCreature () {
return (this.creature);
}
/**
* Determine the type of this body part.
*
* @return Type of body part.
*/
public byte getType () {
return (this.type);
}
/**
* Determine the equipped items for this body part.
*
* @return An array of equipped items for this body part.
*/
public Collection getItems () {
return ((Collection) items);
}
/**
* Equip an item on this body part. If the item cannot be equipped,
* this function will return false.
*
* @param item Item to be equipped on this body part.
* @return True if item is equipped on this body part.
*/
public boolean equipItem (Item item) {
return (false); // TODO: Implement this function.
}
/**
* Drop an item from this body part. If the item cannot be dropped
* (maybe it is cursed or grafted onto the body part), this function
* will return false.
*
* @return True if item is dropped from this body part.
*/
public boolean dropItem (Item item) {
return (true); // TODO: Implement this function.
}
}
--- NEW FILE: Strength.java ---
/*
* Strength.java -- class declaration for Strength scores
* Copyright (C) 2003 Eric Lemings <ele...@us...>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA
*
* RCS: $Id: Strength.java,v 1.1 2003/04/04 20:22:51 elemings Exp $
*/
package ogs.core;
import ogs.core.Ability;
import ogs.core.Size;
/**
* An ability that determines physical power and force. A Strength
* modifier is added to attack rolls with melee weapons and damage
* rolls with melee weapons, thrown weapons, and specially designed
* projectile weapons. Strength is a special ability that has
* additional operations for determining carrying capacities.
*/
public class Strength extends Ability {
/**
* Create a new Strength score. The Strength score is rolled using
* the standard method.
*/
public Strength () {
super (Ability.STR);
}
/**
* Create a new Strength score using a method. The default method for
* generating a Strength score is the standard method.
*
* @param method Method used to generate score.
*/
public Strength (Ability.Method method) {
super (Ability.STR, method);
}
/**
* Determine the limit of light loads for this ability.
*
* @param sizeType Size type of creature.
* @return Weight in pounds.
*/
public double getLightLoad (char sizeType) {
return (getHeavyLoad (sizeType) / 3);
}
/**
* Determine the limit of medium loads for this ability.
*
* @param sizeType Size type of creature.
* @return Weight in pounds.
*/
public double getMediumLoad (char sizeType) {
return ((2 * getHeavyLoad (sizeType)) / 3);
}
/**
* Determine the limit of heavy loads for this ability.
*
* @param sizeType Size type of creature.
* @return Weight in pounds.
*/
public double getHeavyLoad (char sizeType) {
return (getMediumSizeHeavyLoad () * getLoadFactor (sizeType));
}
private static double table11To19 [] = {
115, 130, 150, 175, 200, 230, 260, 300, 350, 400,
};
private static double table20AndAbove [] = {
400, 460, 520, 600, 700, 800, 920, 1040, 1200, 1400
};
/**
* Determine the limit of heavy loads for a medium-size creature.
*
* @return Weight in pounds.
*/
private double getMediumSizeHeavyLoad () {
int score = getCurrentScore ();
double load = 0.0;
if (score < 11) {
load = score * 10.0;
} else if (score < 20) {
load = table11To19 [score - 11];
} else {
load = table20AndAbove [score % 10];
int factor = (score - 20) / 10;
load *= Math.pow (4.0, factor);
}
return (load);
}
/**
* Determine the load factor of a size.
*
* @param sizeType Size type of creature.
* @return Load factor of size.
*/
private double getLoadFactor (char sizeType) {
return (sizeType == Size.FINE? (0.125): // 1/8
sizeType == Size.DIMINUITIVE? (0.25):
sizeType == Size.TINY? (0.5):
sizeType == Size.SMALL? (0.75):
sizeType == Size.LARGE? 2.0:
sizeType == Size.HUGE? 4.0:
sizeType == Size.GARGANTUAN? 8.0:
sizeType == Size.COLLOSAL? 16.0: 1.0);
}
}
Index: Abilities.java
===================================================================
RCS file: /cvsroot/ogs/dist/java/ogs/core/Abilities.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Abilities.java 27 Feb 2003 22:42:19 -0000 1.4
--- Abilities.java 4 Apr 2003 20:22:50 -0000 1.5
***************
*** 23,97 ****
package ogs.core;
! import ogs.core.abilities.*;
/**
* A set of ability scores. A set of ability scores normally consists
! * of one score for each type of ability. Some entities however may not
! * possess all six abilities. Certain creatures by their very nature
! * may lack for example Intelligence, Constitution, Strength, or some
! * other ability.
! *
! * @see ogs.core.abilities
*/
public class Abilities {
! /** A Charisma score. */
! public Charisma cha;
! /** A Constitution score. */
! public Constitution con;
! /** A Dexterity score. */
! public Dexterity dex;
/**
! * An Intelligence score. Note the difference in naming convention
! * since <code>int</code> is a reserved word in Java.
*/
! public Intelligence intl;
! /** A Strength score. */
! public Strength str;
! /** A Wisdom score. */
! public Wisdom wis;
/**
! * Create a new set of ability scores. The ability scores are rolled
! * with the standard method.
*/
! public Abilities () {
! this.cha = new Charisma ();
! this.con = new Constitution ();
! this.dex = new Dexterity ();
! this.intl = new Intelligence ();
! this.str = new Strength ();
! this.wis = new Wisdom ();
}
/**
! * Determine which ability in this set is an instance of an ability
! * class. This method will return null if the class is not derived
! * from the <code>Ability</code> class or if the ability does not
! * exist in the set.
*
! * @param abilityClass A class dervied from <code>Ability</code>.
! * @return An ability from the set or null.
*/
! public Ability getAbility (Class abilityClass) {
! Ability ability = null;
! if (Ability.class.isAssignableFrom (abilityClass)) {
! if (abilityClass.isInstance (this.cha)) {
! ability = this.cha;
! } else if (abilityClass.isInstance (this.con)) {
! ability = this.con;
! } else if (abilityClass.isInstance (this.dex)) {
! ability = this.dex;
! } else if (abilityClass.isInstance (this.intl)) {
! ability = this.intl;
! } else if (abilityClass.isInstance (this.str)) {
! ability = this.str;
! } else if (abilityClass.isInstance (this.wis)) {
! ability = this.wis;
! }
! }
! return (ability);
}
--- 23,128 ----
package ogs.core;
! import java.util.Map;
! import java.util.HashMap;
! import java.util.Iterator;
! import java.util.Set;
!
! import ogs.core.Ability;
! import ogs.core.Strength;
/**
* A set of ability scores. A set of ability scores normally consists
! * of one score for each ability. Some entities however may not possess
! * all six abilities. Certain creatures for example may lack
! * Intelligence, Constitution, Strength, or some other ability by their
! * very nature.
*/
public class Abilities {
! private Map map = null;
!
/**
! * Create a new set of ability scores. This constructor uses the
! * standard method to create a complete set of all six ability scores.
*/
! public Abilities () {
! this.map = new HashMap (Ability.NUM);
! Ability ability = new Ability (Ability.CHA);
! this.map.put (new Integer (Ability.CHA), ability);
! ability = new Ability (Ability.CON);
! this.map.put (new Integer (Ability.CON), ability);
! ability = new Ability (Ability.DEX);
! this.map.put (new Integer (Ability.DEX), ability);
! ability = new Ability (Ability.INT);
! this.map.put (new Integer (Ability.INT), ability);
! ability = new Strength ();
! this.map.put (new Integer (Ability.STR), ability);
! ability = new Ability (Ability.WIS);
! this.map.put (new Integer (Ability.WIS), ability);
! }
/**
! * Create a new set of ability scores using a method. This
! * constructor uses the provided method to create a complete set of
! * all six ability scores.
! *
! * @param method A method for generating ability scores.
*/
! public Abilities (Ability.Method method) {
! this.map = new HashMap (Ability.NUM);
! Ability ability = new Ability (Ability.CHA);
! this.map.put (new Integer (Ability.CHA), ability);
! ability = new Ability (Ability.CON);
! this.map.put (new Integer (Ability.CON), ability);
! ability = new Ability (Ability.DEX);
! this.map.put (new Integer (Ability.DEX), ability);
! ability = new Ability (Ability.INT);
! this.map.put (new Integer (Ability.INT), ability);
! ability = new Strength (method);
! this.map.put (new Integer (Ability.STR), ability);
! ability = new Ability (Ability.WIS);
! this.map.put (new Integer (Ability.WIS), ability);
}
/**
! * Determine the iterator for this set of abilities.
*
! * @return Iterator for this set of abilities.
*/
! public Iterator getIterator () {
! Set set = this.map.entrySet ();
! return (set.iterator ());
! }
! /**
! * Determine the ability for a given type. If an ability for the type
! * does not exist in this set, this operator returns null.
! *
! * @param abilityType Type of ability.
! * @return An ability or null if the ability does not exist.
! */
! public Ability getAbility (int abilityType) {
! Object object = new Integer (abilityType);
! return ((Ability) this.map.get (object));
! }
! /**
! * Remove an ability from this set of abilities.
! *
! * @param abilityType Type of ability to be removed.
! */
! public void removeAbility (int abilityType) {
! Object object = new Integer (abilityType);
! this.map.remove (object);
! }
!
! /**
! * Determine if this set is a complete set of abilities. A complete
! * set of abilities contains all six ability scores.
! *
! * @return True if this set is a complete set of abilities.
! */
! public boolean isComplete () {
! return (map.size () == Ability.NUM);
}
***************
*** 141,179 ****
* @param score Highest score.
* @return True if this set of abilities can be rerolled.
- * @throw RuntimeException If all six abilities are not present.
*/
private boolean canReroll (int modifier, int score) {
! if (this.cha == null || this.con == null ||
! this.dex == null || this.intl == null ||
! this.str == null || this.wis == null) {
! String msg = "All six abilities required to perform this operation.";
! throw new RuntimeException (msg);
! } else {
! int total = 0;
! // TODO: Finish tranlsating from C++ implementation.
!
! int highest = this.cha.getOriginalScore ();
! if (this.con.getOriginalScore () > highest) {
! highest = this.con.getOriginalScore ();
! }
!
! if (this.dex.getOriginalScore () > highest) {
! highest = this.dex.getOriginalScore ();
! }
!
! if (this.intl.getOriginalScore () > highest) {
! highest = this.intl.getOriginalScore ();
! }
! if (this.str.getOriginalScore () > highest) {
! highest = this.str.getOriginalScore ();
! }
! if (this.wis.getOriginalScore () > highest) {
! highest = this.wis.getOriginalScore ();
}
! return (total <= modifier || highest <= score);
}
}
}
--- 172,201 ----
* @param score Highest score.
* @return True if this set of abilities can be rerolled.
*/
private boolean canReroll (int modifier, int score) {
! boolean canReroll = false;
! if (isComplete ()) {
! int total = 0;
! Ability ability = null;
! int highest = 0;
! int abilityTypes [] = {
! Ability.CHA, Ability.CON, Ability.DEX,
! Ability.INT, Ability.STR, Ability.WIS
! };
! for (int i = 0; i < Ability.NUM; ++i) {
! Object object = new Integer (abilityTypes [i]);
! ability = (Ability) this.map.get (object);
! total += (ability.getModifier ()).getValue ();
! if (ability.getOriginalScore () > highest) {
! highest = ability.getOriginalScore ();
! }
}
! canReroll = total <= modifier || highest <= score;
}
+
+ return (canReroll);
}
}
Index: Ability.java
===================================================================
RCS file: /cvsroot/ogs/dist/java/ogs/core/Ability.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Ability.java 27 Feb 2003 01:24:43 -0000 1.3
--- Ability.java 4 Apr 2003 20:22:50 -0000 1.4
***************
*** 30,74 ****
import ogs.core.Die;
import ogs.core.Modifier;
/**
! * A physical or mental characteristic of an entity. Abilities are
! * most often associated with creatures although certain entities, such
! * as powerful magic items, can also have abilities.. The value of an
! * ability is called an ability score. Ability scores can range from
! * 0 up to 20, 30, or 50 but rarely if ever rise above 100. An ability
! * can be modified by adding other modifiers to the original score of
! * the ability. The modified ability score or current score is used to
! * determine the ability modifier. Thus, an ability has two kinds of
! * modifiers: modifiers <I>to the original score</I> and a modifier
! * <I>from the current score</I>.
*/
! public abstract class Ability extends Object {
/**
! * The modifier resulting from the current score of an ability.
*/
! public class Modifier extends ogs.core.Modifier {
! /**
! * Create a new ability modifier.
! *
! * @param value Value of this modifier.
! */
! public Modifier (int value) {
! super (value);
! }
/**
! * Update the value of this modifier.
*
! * @param event The event that occurred.
*/
! protected void handleEvent (EventObject event) {
! setValue (getModifier (current));
! }
}
! private byte original;
! private Vector modifiers;
! private byte current;
! private Ability.Modifier modifier;
/**
--- 30,131 ----
import ogs.core.Die;
import ogs.core.Modifier;
+ import ogs.core.Modifiers;
/**
! * A basic characteristic of an entity. Abilities are most often
! * associated with creatures although certain entities, such as powerful
! * magic items, can also have abilities.. The value of an ability is
! * called an ability score. Ability scores are non-negative integer
! * values that can range from 0 up to 20, 30, or even 50 but rarely if
! * ever rise above 100. <P>
! *
! * An ability score can be modified by adding other modifiers to the
! * unmodified, original score of the ability. The modified, current
! * score is used to determine the ability modifier. Thus, an ability
! * has two kinds of modifiers: zero or more <I>score modifiers</I> that
! * are added to the original score and one <I>ability modifier</I>
! * resulting from the current score. <P>
*/
! public class Ability extends ogs.support.Object {
/**
! * An ability that determines physical power and force.
! *
! * @see ogs.core.Strength
*/
! public static final byte STR = 1;
!
! /**
! * An ability that determines agility and quickness. A Dexterity
! * modifier is added to ranged attacks with thrown weapons and
! * projectile weapons, defense ratings, and Reflex saving throws.
! *
! * @see Defense
! * @see Saves::ref
! */
! public static final byte DEX = 2;
+ /**
+ * An ability that determines fitness and vigor. A Constiution
+ * modifier is added to hit die rolls and Fortitude saving throws.
+ *
+ * @see Saves::fort
+ */
+ public static final byte CON = 3;
+
+ /** An ability that determines reasoning and deduction. */
+ public static final byte INT = 4;
+
+ /**
+ * An ability that determines intuition and judgement. The Wisdom
+ * modifier is added to all Will saving throws.
+ *
+ * @see Saves::will
+ */
+ public static final byte WIS = 5;
+
+ /** A ability that determines leadership and charm. */
+ public static final byte CHA = 6;
+
+ /** Number of ability types. */
+ public static final byte NUM = 6;
+
+ /**
+ * A function object that generates an ability score. Ability methods
+ * have at least one member: an operation that generates an ability
+ * score.
+ */
+ public abstract class Method {
/**
! * Generate an ability score for a type of ability. The type of
! * ability may be ignored if it is not needed to generate a score.
*
! * @param abilityType Type of ability score to generate.
! * @return A score for the given type of ability.
*/
! public abstract byte generateScore (int abilityType);
}
! /**
! * Determine if an integer value is a valid type of ability.
! *
! * @return True if integer value is a valid type of ability.
! */
! private boolean isValid (int i) {
! return (i == Ability.CHA || i == Ability.CON ||
! i == Ability.DEX || i == Ability.INT ||
! i == Ability.STR || i == Ability.WIS);
! }
!
! /**
! * A method that generates above-average ability scores. The
! * standard method rolls 4d6 and adds the highest three rolls to
! * generate an ability score. The standard method is normally used
! * to generate ability scores for player characters.
! */
! public class StandardMethod extends Method {
! public byte generateScore (int abilityType) {
! return (rollStandard ());
! }
! }
/**
***************
*** 81,85 ****
* @return An ability score.
*/
! public static byte rollStandard () {
int total = Die.roll (Die.d6);
int lowest = total;
--- 138,142 ----
* @return An ability score.
*/
! private static byte rollStandard () {
int total = Die.roll (Die.d6);
int lowest = total;
***************
*** 98,101 ****
--- 155,170 ----
/**
+ * A method that generates average ability scores. The average
+ * method rolls 3d6 to generate an ability score. The average
+ * method is nnormally used to generate ability scores for
+ * nonplayer characters.
+ */
+ public class AverageMethod extends Method {
+ public byte generateScore (int abilityType) {
+ return (rollAverage ());
+ }
+ }
+
+ /**
* Produce an ability score using the average method. With
* the average method, three d6 die are rolled and added together.
***************
*** 105,113 ****
* @return An ability score.
*/
! public static byte rollCommon () {
return ((byte) Die.roll (Die.d6, 3));
}
/**
* Produce an ability score using the high-powered method. With the
* high-powered method, five d6 die are rolled, the lowest two rolls
--- 174,194 ----
* @return An ability score.
*/
! private static byte rollAverage () {
return ((byte) Die.roll (Die.d6, 3));
}
/**
+ * A method that generates "high-powered" ability scores. The
+ * high-powered method rolls 5d6 and adds the highest three rolls to
+ * generate an ability score. The high-powered method is nnormally
+ * used to generate ability scores for high-level player characters
+ */
+ public class HighPoweredMethod extends Method {
+ public byte generateScore (int abilityType) {
+ return (rollHighPowered ());
+ }
+ }
+
+ /**
* Produce an ability score using the high-powered method. With the
* high-powered method, five d6 die are rolled, the lowest two rolls
***************
*** 118,122 ****
* @return An ability score.
*/
! public static byte rollHighPowered () {
int lowest1 = Die.roll (Die.d6);
int lowest2 = Die.roll (Die.d6);
--- 199,203 ----
* @return An ability score.
*/
! private static byte rollHighPowered () {
int lowest1 = Die.roll (Die.d6);
int lowest2 = Die.roll (Die.d6);
***************
*** 179,246 ****
/**
! * Determine the original ability score.
*/
! public byte getOriginalScore () {
! return (original);
}
/**
! * Change the original ability score.
*
! * @param original The original ability score.
*/
! public void setOriginalScore (byte original) {
! this.original = original;
! notifyListeners (null);
}
/**
! * Determine the current ability score.
*/
! public byte getCurrentScore () {
! return (current);
}
/**
! * Add a modifier to the ability score.
*
! * @param modifier An ability score modifier.
*/
! public void addModifier (Modifier modifier) {
! // Ability score needs to be updated if the modifier changes.
! modifier.addListener (this);
! modifiers.add (modifier);
! notifyListeners (null);
}
/**
! * Remove a modifier from the ability score.
*
! * @param modifier An ability score modifier.
*/
! public void removeModifier (Modifier modifier) {
! // TODO: See if the modifier is present first.
! modifier.removeListener (this);
! modifiers.remove (modifier);
! notifyListeners (null);
}
/**
! * Produce a copy of the ability modifier.
*/
! public Ability.Modifier getModifier () {
! return (modifier);
}
/**
! * Initialize an ability rolled using the standard method. Called
! * only by constructors of subclasses of the <code>Ability</code>
! * class.
*/
! protected Ability () {
! original = current = rollStandard ();
! modifiers = new Vector ();
! modifier = new Ability.Modifier (getModifier (current));
! this.addListener (modifier);
}
--- 260,371 ----
/**
! * The modifier resulting from the current score of an ability.
*/
! public class Modifier extends ogs.core.Modifier {
! /**
! * Create a new ability modifier.
! *
! * @param value Value of this modifier.
! */
! public Modifier (int value) {
! super (value);
! }
!
! /**
! * Update the value of this modifier.
! *
! * @param event The event that occurred.
! */
! protected void handleEvent (EventObject event) {
! setValue (getModifier (current));
! }
}
+ private int type;
+ private byte original;
+ private Modifiers modifiers;
+ private byte current;
+ private Ability.Modifier modifier;
+
/**
! * Create a new ability score using a method. The public constructors
! * are defined in terms of this constructor.
*
! * @param abilityType A type of ability.
! * @param method A method for generating an ability score.
! * @throws IllegalArgumentException If abilityType is not valid.
*/
! private void createAbility (int abilityType, Method method) {
! if (! isValid (abilityType)) {
! String s = "abilityType (" + abilityType +
! ") is not a valid type of ability";
! throw (new IllegalArgumentException (s));
! }
!
! this.type = abilityType;
! this.original = method.generateScore (abilityType);
! this.modifiers = new Modifiers ();
! this.current = this.original;
! this.modifier = new Ability.Modifier (getModifier (this.current));
! this.addListener (modifier);
}
/**
! * Create a new ability score. The ability score is generated using
! * the standard method.
! *
! * @param abilityType A type of ability.
! * @throws IllegalArgumentException If abilityType is not valid.
*/
! public Ability (int abilityType) {
! StandardMethod method = new StandardMethod ();
! createAbility (abilityType, method);
}
/**
! * Create a new ability score using a method.
*
! * @param abilityType A type of ability.
! * @param method A method for generating an ability score.
! * @throws IllegalArgumentException If abilityType is not valid.
*/
! public Ability (int abilityType, Method method) {
! createAbility (abilityType, method);
}
/**
! * Determine the original ability score.
*
! * @return The original score of this ability.
*/
! public byte getOriginalScore () {
! return (this.original);
}
/**
! * Determine the current ability score.
! *
! * @return The current score of this ability.
*/
! public byte getCurrentScore () {
! return (this.current);
}
/**
! * Determine the score modifiers for this ability.
! *
! * @return A list of score modifiers for this ability.
*/
! public Modifiers getModifiers () {
! return (this.modifiers);
! }
!
! /**
! * Determine the ability modifier for this ability.
! *
! * @return The ability modifier for this ability.
! */
! public Ability.Modifier getModifier () {
! return (this.modifier);
}
***************
*** 252,272 ****
*/
protected void handleEvent (EventObject event) {
! current = original;
!
! // Add all modifiers to current score.
! Iterator iterator = modifiers.iterator ();
! while (iterator.hasNext ()) {
! Modifier mod = (Modifier) iterator.next ();
! current += mod.getValue ();
! }
// No such thing as negative ability scores.
! if (current < 0) {
! current = 0;
}
notifyListeners (event);
}
-
}
--- 377,390 ----
*/
protected void handleEvent (EventObject event) {
! this.current = this.original;
! this.current += this.modifiers.getValue ();
// No such thing as negative ability scores.
! if (this.current < 0) {
! this.current = 0;
}
notifyListeners (event);
}
}
Index: CClass.java
===================================================================
RCS file: /cvsroot/ogs/dist/java/ogs/core/CClass.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CClass.java 24 Feb 2003 11:32:15 -0000 1.2
--- CClass.java 4 Apr 2003 20:22:50 -0000 1.3
***************
*** 154,158 ****
* different advvancement rate is required.
*/
! public int getBaseAttackValue () {
return (Experience.getAverageAttack (getLevel ()));
}
--- 154,158 ----
* different advvancement rate is required.
*/
! protected int getBaseAttackValue () {
return (Experience.getAverageAttack (getLevel ()));
}
***************
*** 164,168 ****
* this method if a different advancement rate is required.
*/
! public int getBaseFortSaveValue () {
return (Saves.getWeakBonus (getLevel ()));
}
--- 164,168 ----
* this method if a different advancement rate is required.
*/
! protected int getBaseFortSaveValue () {
return (Saves.getWeakBonus (getLevel ()));
}
***************
*** 174,178 ****
* a different advancement rate is required.
*/
! public int getBaseRefSaveValue () {
return (Saves.getWeakBonus (getLevel ()));
}
--- 174,178 ----
* a different advancement rate is required.
*/
! protected int getBaseRefSaveValue () {
return (Saves.getWeakBonus (getLevel ()));
}
***************
*** 184,188 ****
* a different advancement rate is required.
*/
! public int getBaseWillSaveValue () {
return (Saves.getWeakBonus (getLevel ()));
}
--- 184,188 ----
* a different advancement rate is required.
*/
! protected int getBaseWillSaveValue () {
return (Saves.getWeakBonus (getLevel ()));
}
Index: Creature.java
===================================================================
RCS file: /cvsroot/ogs/dist/java/ogs/core/Creature.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Creature.java 7 Jan 2003 07:20:33 -0000 1.1
--- Creature.java 4 Apr 2003 20:22:51 -0000 1.2
***************
*** 78,112 ****
/** The ability scores for this creature. */
! protected Abilities abilities;
/** The saving throw modifiers for this creature. */
! protected Saves saves = new Saves ();
/** The movement speed for this creature when walking. */
! protected double walk = 0.0;
/** The movement speed for this creature when climbing. */
! protected double climb = 0.0;
/** The movement speed for this creature when swimming. */
! protected double swim = 0.0;
/** The movement speed for this creature when flying. */
! protected double fly = 0.0;
/** The movement speed for this creature when burrowing. */
! protected double burrow = 0.0;
/** A list of skills for this creature. */
! protected Vector skills = new Vector ();
/** A list of feats for this creature. */
! protected Vector feats = new Vector ();
/** The initiative modifiers for this creature. */
! protected Modifiers init = new Modifiers ();
/** The hit dice for this creature. */
! protected Vector hitDice = new Vector ();
/**
--- 78,115 ----
/** The ability scores for this creature. */
! private Abilities abilities = null;
/** The saving throw modifiers for this creature. */
! private Saves saves = null;
/** The movement speed for this creature when walking. */
! private double walk = 0.0;
/** The movement speed for this creature when climbing. */
! private double climb = 0.0;
/** The movement speed for this creature when swimming. */
! private double swim = 0.0;
/** The movement speed for this creature when flying. */
! private double fly = 0.0;
/** The movement speed for this creature when burrowing. */
! private double burrow = 0.0;
/** A list of skills for this creature. */
! private Vector skills = null;
/** A list of feats for this creature. */
! private Vector feats = null;
/** The initiative modifiers for this creature. */
! private Modifiers init = null;
/** The hit dice for this creature. */
! private Vector hitDice = null;
!
! /** The body parts that compose the body of this creature. */
! private Vector body = null;
/**
***************
*** 119,125 ****
--- 122,156 ----
protected Creature () {
super ();
+
+ this.abilities = new Abilities ();
+ this.saves = new Saves ();
+ this.skills = new Vector ();
+ this.feats = new Vector ();
+ this.init = new Modifiers ();
+ this.hitDice = new Vector ();
+
addModifiers ();
}
+ private void addModifiers () {
+ Ability ability = abilities.getAbility (Ability.DEX);
+ if (ability != null) {
+ Modifier modifier = ability.getModifier ();
+ init.addModifier (modifier);
+ defense.addModifier (modifier);
+ saves.ref.addModifier (modifier);
+ }
+
+ ability = abilities.getAbility (Ability.CON);
+ if (ability != null) {
+ saves.fort.addModifier (ability.getModifier ());
+ }
+
+ ability = abilities.getAbility (Ability.WIS);
+ if (ability != null) {
+ saves.will.addModifier (ability.getModifier ());
+ }
+ }
+
/**
* Determine the ability scores for this creature.
***************
*** 199,203 ****
*/
public void addSkill (Skill skill) {
!
}
--- 230,234 ----
*/
public void addSkill (Skill skill) {
! // TODO: Implement this function.
}
***************
*** 208,212 ****
*/
public void removeSkill (Skill skill) {
!
}
--- 239,243 ----
*/
public void removeSkill (Skill skill) {
! // TODO: Implement this function.
}
***************
*** 226,230 ****
*/
public void addFeat (Feat feat) {
!
}
--- 257,261 ----
*/
public void addFeat (Feat feat) {
! // TODO: Implement this function.
}
***************
*** 235,249 ****
*/
public void removeFeat (Feat feat) {
!
}
! private void addModifiers () {
! init.addModifier (abilities.dex.getModifier ());
! defense.addModifier (abilities.dex.getModifier ());
!
! saves.fort.addModifier (abilities.con.getModifier ());
! saves.ref.addModifier (abilities.dex.getModifier ());
! saves.will.addModifier (abilities.wis.getModifier ());
}
}
--- 266,281 ----
*/
public void removeFeat (Feat feat) {
! // TODO: Implement this function.
}
! /**
! * Determine the body parts that compose the body of this creature.
! *
! * @return A collection of body parts for this creature.
! */
! public Collection getBody () {
! return ((Collection) this.body);
}
+
}
Index: Feat.java
===================================================================
RCS file: /cvsroot/ogs/dist/java/ogs/core/Feat.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Feat.java 27 Feb 2003 01:24:44 -0000 1.2
--- Feat.java 4 Apr 2003 20:22:51 -0000 1.3
***************
*** 23,26 ****
--- 23,31 ----
package ogs.core;
+ import java.util.Collection;
+ import java.util.Iterator;
+
+ import ogs.support.Object;
+ import ogs.core.Creature;
import ogs.core.Feature;
***************
*** 55,63 ****
/**
! * Determine the compatibility of this type of feat.
! *
! * @return EXCLUSIVE, REPEATBLE, or CUMULATIVE.
*/
! public abstract int getCompatibility ();
/**
--- 60,90 ----
/**
! * A general-purpose feat. General feats are feats that can be
! * used by all creatures and cclasses or apply to many different
! * situations.
*/
! public static final int GENERAL = 0;
!
! /**
! * A combat-use feat. Combat feats are feats that are
! * specifically designed for use in combat. The bonus feats
! * granted to fighters are limited to combat feats.
! */
! public static final int COMBAT = 1;
!
! /**
! * A magic-related feat. Magic feats include metamagic feats for
! * enhancing spells and item creation feats for creating magic
! * items. The bonus feats granted to wizards are limited to magic
! * feats.
! */
! public static final int MAGIC = 2;
!
! /**
! * A feat that does not belong to one of the other groups.
! * Special feats are feats that can only be selected only by
! * particular cclasses or creatures or used in certain situations.
! */
! public static final int SPECIAL = 3;
/**
***************
*** 88,91 ****
--- 115,177 ----
return (xpLevel);
+ }
+
+ /**
+ * Determine the compatibility of this type of feat.
+ *
+ * @return EXCLUSIVE, REPEATBLE, or CUMULATIVE.
+ */
+ public abstract int getCompatibility ();
+
+ /**
+ * Determine the group of this type of feat.
+ *
+ * @return GENERAL, COMBAT, MAGIC, or SPECIAL.
+ */
+ public abstract int getGroup ();
+
+ /**
+ * Determine if this feat can be attached to an object. Feats can
+ * only be attached to creatures. If the object is not a creature,
+ * this function will return false.
+ *
+ * @param object Object to attach this feature to.
+ * @return True if the feature is attached to the object.
+ */
+ protected boolean canAttach (Object object) {
+ return (super.canAttach (object) &&
+ Creature.class.isAssignableFrom (object.getClass ()));
+ }
+
+ /**
+ * Determine if a creature has a feat. If the specified object is not
+ * a creature, this method will return false.
+ *
+ * @param creatureObject Object (creature) to check for feat.
+ * @param featClass Class of feat.
+ * @return True if creature has an instance of the feat.
+ */
+ protected boolean findFeat (Object creatureObject, Class featClass) {
+ boolean found = false;
+
+ Creature creature = null;
+ try {
+ creature = (Creature) creatureObject;
+ } catch (ClassCastException exception) {
+ // Object not a creature? Feat not found.
+ }
+
+ if (creature != null) {
+ Collection feats = creature.getFeats ();
+ Iterator itor = feats.iterator ();
+ while (!found && itor.hasNext ()) {
+ Feat feat = (Feat) itor.next ();
+ if (featClass.isAssignableFrom (feat.getClass ())) {
+ found = true;
+ }
+ }
+ }
+
+ return (found);
}
}
Index: Feature.java
===================================================================
RCS file: /cvsroot/ogs/dist/java/ogs/core/Feature.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Feature.java 27 Feb 2003 22:42:19 -0000 1.3
--- Feature.java 4 Apr 2003 20:22:51 -0000 1.4
***************
*** 44,51 ****
/**
* Attach this feature to an object. This method should always be
! * called first by derived classes that override this method. It
! * simply makes sure that the feature is not being attached to
! * itself and then attaches the given object.
*
* @param object Object to attach this feature to.
--- 44,60 ----
/**
+ * Determine if this feature can be attached to an object. A feature
+ * can not be attached to itself or if it is already attached.
+ *
+ * @param object Object to attach this feature to.
+ * @return True if the feature is attached to the object.
+ */
+ protected boolean canAttach (Object object) {
+ return (this.object != null && object != this);
+ }
+
+ /**
* Attach this feature to an object. This method should always be
! * called first by derived classes that override this method.
*
* @param object Object to attach this feature to.
***************
*** 53,63 ****
*/
public boolean attachObject (Object object) {
! boolean success = false;
! // A feature can not be attached to itself.
! if (object != this) {
this.object = object;
}
return (true);
}
--- 62,81 ----
*/
public boolean attachObject (Object object) {
! boolean attached = canAttach (object);
! if (attached) {
this.object = object;
}
+ return (attached);
+ }
+
+ /**
+ * Determine if this feature can be detached to an object.
+ *
+ * @param object Object to detach this feature from.
+ * @return True if the feature is detached from the object.
+ */
+ protected boolean canDetach () {
return (true);
}
***************
*** 65,77 ****
/**
* Detach this feature from an object. This method should always be
! * called by derived classes that override this method. It should
! * <em>never</em> be called before a call to the {@link #getObject()}
! * method.
*
* @return True if the feature is detached from the object.
*/
public boolean detachObject () {
! this.object = null;
! return (true);
}
--- 83,98 ----
/**
* Detach this feature from an object. This method should always be
! * called by derived classes that override this method.
*
* @return True if the feature is detached from the object.
*/
public boolean detachObject () {
! boolean detached = canDetach ();
!
! if (detached) {
! this.object = null;
! }
!
! return (detached);
}
Index: Skill.java
===================================================================
RCS file: /cvsroot/ogs/dist/java/ogs/core/Skill.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Skill.java 27 Feb 2003 01:24:44 -0000 1.3
--- Skill.java 4 Apr 2003 20:22:51 -0000 1.4
***************
*** 89,96 ****
* Determine the key ability for this type of skill. The modifier of
* the key ability is always added to the skill check. Derived
! * classes must implement this method to return the appropriate class
! * of Ability.
*/
! public abstract Class getKeyAbility ();
/**
--- 89,98 ----
* Determine the key ability for this type of skill. The modifier of
* the key ability is always added to the skill check. Derived
! * classes must implement this method to return the appropriate type
! * of ability.
! *
! * @return Type of ability: STR, DEX, CON, INT, WIS, or CHA.
*/
! public abstract int getKeyAbility ();
/**
***************
*** 145,150 ****
*/
private Ability getKeyAbility (Abilities abilities) {
! Class keyAbility = getKeyAbility ();
! return (keyAbility == null? null:
abilities.getAbility (keyAbility));
}
--- 147,152 ----
*/
private Ability getKeyAbility (Abilities abilities) {
! int keyAbility = getKeyAbility ();
! return (keyAbility == 0? null:
abilities.getAbility (keyAbility));
}
|