wyvern.lib.properties
Class GuildSkills

java.lang.Object
  extended bywyvern.lib.properties.GuildSkills
All Implemented Interfaces:
AddRemoveNotify, Command, MethodHookCallback, SelfExternalizable

public abstract class GuildSkills
extends java.lang.Object
implements AddRemoveNotify, Command, SelfExternalizable, MethodHookCallback

The superclass of all bean property objects that implement Guild skills.

Version:
1.0, Mar 02, 2003
Author:
Steve Yegge

Field Summary
protected  int guildXP_
          How much guild XP the player currently has.
static int[] XPCHART
          We're going with 10 guild levels, so we use an exponential chart.
 
Constructor Summary
GuildSkills()
           
 
Method Summary
 void adjustGuildXP(int xp)
          Awards some guild XP to the player, for killing a monster or doing some other task.
 int adjustXPForDeath(int percent)
          Lose guild XP when you die.
 void advanceLevel(int level)
          Does the stuff needed for advancing the agent a level.
 void announce(java.lang.String message)
          Sends a message to all the guild members online.
abstract  boolean awardXP(DamageEvent event)
          Returns true if the specified DamageEvent should result in the guild member getting guild XP.
 CommandEvent createEvent(CommandEvent initial)
          Creates the command event.
 int crossedLevelBoundary(int oldxp, int newxp)
          Determines whether the player went up a level.
 boolean execute(CommandEvent event)
          Executes the event.
 Player getAgent()
          Reutrns the player we're modifying, if it's been set.
 int getGuildLevel()
          Returns the guild level for our agent.
static int getGuildLevel(int xp)
          Returns the guild level for the given amount of XP.
 int getGuildLevel(Player agent)
          Returns the level in the guild that this player has attained, based on settings in their guild skills object.
abstract  java.lang.String getGuildName()
          Returns the official name for the guild, minus "Guild".
abstract  java.lang.String getGuildPluralName()
          Returns the short, plural name for the guild, such as "Paladins" or "Axemen", used in phrases like "There are 20 Axemen online.".
abstract  java.lang.String getGuildShortName()
          Returns the short name for the guild, such as "mage", "paladin", or "archer".
abstract  java.lang.String getGuildTag()
          Returns the tag-property saying which guild this person is in, such as "paladin-guild" or "mages-guild".
abstract  java.lang.String getGuildTitle()
          Returns the generic guild title to show in the high-score list, such as "Mage" or "Paladin".
 int getGuildXP()
          Returns the guild XP associated with this GuildSkills object - i.e. the total amount of guild XP this player has received.
abstract  java.lang.String getTellCommand()
          Returns the name of the command to use for guild-tell.
abstract  java.lang.String getTitle(Player p)
          Returns the Guild Title to use for the player.
abstract  java.lang.String getWhoCommand()
          Returns the name of the command to use for guild-who.
 boolean guildScore(CommandEvent event)
          Shows current guild XP.
 boolean guildtell(Player agent, java.lang.String verb, java.lang.String message)
          Tells a message to the other guild-members online.
 boolean guildwho(Commandable agent, CommandEvent event)
          Shows who's logged in.
 boolean isInGuild(Player p)
          Returns true if the specified player is in this guild.
 boolean knowsCommand(java.lang.String command)
          Returns true if we want to handle this command.
 void methodCalled(java.lang.String hookName, MethodHookable target, java.lang.Object data)
          Notifies us that one of our method-hooks of interest was run.
 void notifyAdd(PropertyList obj)
          The Guild object is being attached to the player - either from first joining the guild, or from logging in.
 void notifyRemove(PropertyList obj)
          Notifies the property that it's being removed.
 void playerDoneLoading()
          We've finished loading the player from the player file.
 void readData(org.w3c.dom.Node bean)
          Tells the object to parse its externalized representation from a list of lines.
 void setGuildXP(int xp)
          Sets the guild XP on this object - used when reading it from the map or player file.
 boolean shouldWrite()
          Allows the object to determine whether it wants to be written out at all.
abstract  void shutdown()
          Removes any guild abilities from the player.
abstract  void startup()
          Sets up the guild abilities for the player.
 java.util.List writeData()
          Tells the object to write its properties out to a text file.
 int xpForLevel(int level)
          Returns XP required to reach the specified level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XPCHART

public static final int[] XPCHART
We're going with 10 guild levels, so we use an exponential chart.


guildXP_

protected int guildXP_
How much guild XP the player currently has. The Guild object can figure out what level this translates to; that way you can change the xp per level on the fly without backfilling the player base.

Constructor Detail

GuildSkills

public GuildSkills()
Method Detail

startup

public abstract void startup()
Sets up the guild abilities for the player. Called when the player first joins the guild, and every time the player logs in.

This is where your GuildSkills subclass can register commands, add itself to hooks, adjust the player's stats and properties based on their guild level, and so on.

You should normally never adjust permanent properties on the player, and use transient ones instead. That way you won't accidentally wind up with bugs causing players to get 1000 hp or other accumulations. It also makes it much easier to tweak the guild abilities, since you don't have to go back and change all existing players.

In particular, you shouldn't store the player's guild level in the player's property list. You should get their level by calling getGuildLevel(), whenever you need to use it for calculations.


shutdown

public abstract void shutdown()
Removes any guild abilities from the player. Called when the player quits the guild, and when they log out.


getGuildName

public abstract java.lang.String getGuildName()
Returns the official name for the guild, minus "Guild". Examples, "Paladins", "Mages", "Axemans", "Archers".

Returns:
the official guild name

getGuildShortName

public abstract java.lang.String getGuildShortName()
Returns the short name for the guild, such as "mage", "paladin", or "archer". Used for constructing the "tell" and "who" commands, e.g. "guildwho", "magetell", and various other things.

Returns:
"paladin", "mage", or whatever (lowercase!)

getGuildPluralName

public abstract java.lang.String getGuildPluralName()
Returns the short, plural name for the guild, such as "Paladins" or "Axemen", used in phrases like "There are 20 Axemen online.".

Returns:
"Paladins", "Mages", "Axemen", "Monks", etc.

getGuildTitle

public abstract java.lang.String getGuildTitle()
Returns the generic guild title to show in the high-score list, such as "Mage" or "Paladin". Stored in a property on the guild member called "guild-name".

Returns:
the guild title - usually the guild name in singular form, but not always.

getGuildTag

public abstract java.lang.String getGuildTag()
Returns the tag-property saying which guild this person is in, such as "paladin-guild" or "mages-guild". Used by guild-only armor, and anything else needing to check if you're in a specific guild. It's not printed to the player, so it can be pretty much anything you want, but it's usually guildname + "-guild".

Returns:
"paladin-guild", "axemans-guild", "archers-guild", etc.

getTitle

public abstract java.lang.String getTitle(Player p)
Returns the Guild Title to use for the player. Some guilds have different titles based on sub-specializations in the guild, so we don't have a generic "getTitle()" method that just takes a level as an argument.

Parameters:
p - the guild member
Returns:
"Warlock", "Champion", "Big Dude", or whatever. Shows up in the Who list. If the player isn't a member of the guild, just return "Adventurer".

getWhoCommand

public abstract java.lang.String getWhoCommand()
Returns the name of the command to use for guild-who.

Returns:
"paladinwho", "axewho", "monkwho", etc.

getTellCommand

public abstract java.lang.String getTellCommand()
Returns the name of the command to use for guild-tell.

Returns:
"paladintell", "axetell", "monktell", etc.

awardXP

public abstract boolean awardXP(DamageEvent event)
Returns true if the specified DamageEvent should result in the guild member getting guild XP.

Parameters:
event - a DamageEvent (may or may not have killed the monster, but assume that it has).

The passed event can be null in some (rare) cases, so check if it's null and don't award any guild XP in that case.

Properties set on the event include:

  • "member" - the guild member, who can be a member of a group that participated in killing the opponent.
  • "xp" - the regular xp being awarded to this member
  • "total-xp" - the total regular xp for the kill, shared by the whole group (if no group, member gets it all)
  • getTarget() - the thing that was killed
  • getAgent() - the event agent (not always the guild member, but it's the player/monster that delivered the final blow)
  • getDamageTypes() - a wyvern.kernel.combat.DamageType[]
  • getDamageAmounts() - the damages done by each damage type in dtypes
  • getTotalDamage() - the total damage done in the event
  • getHitLocation() - the BodyPart hit location for the attack
  • getAttackerMessage() - message to print to the attacker
  • getDefenderMessage() - message to print to the defender
  • getWeapon() - the game object (spell or weapon) used in the attack. NOTE: This is the attack used by the player who killed the opponent, who is not necessarily the member getting awarded experience in this call. If the killer is different from the member, then you have no way of knowing if they used their guild skill to fight the monster. It's OK to assume that they did, though. For fighter classes, you can check the @attacks list on the member to see if they're wielding a weapon of the correct type, if you want.

The event is reused to give XP to every group member, so don't modify the event - treat it as read-only.

The property can be null, so make sure to do null checks on the values after you extract them from the event.

Returns:
true if the DamageType and/or Attack in the event,

adjustXPForDeath

public int adjustXPForDeath(int percent)
Lose guild XP when you die.

Parameters:
percent - the percent of 10% that they lost from regular XP. It's normally 100 (i.e. they lose 10%) unless the player has a nonzero spirit-travelling skill.
Returns:
the amount of xp actually lost

notifyAdd

public void notifyAdd(PropertyList obj)
The Guild object is being attached to the player - either from first joining the guild, or from logging in.

Specified by:
notifyAdd in interface AddRemoveNotify
Parameters:
obj - the player

notifyRemove

public void notifyRemove(PropertyList obj)
Notifies the property that it's being removed. Unregisters the "shift" command from the player.

Specified by:
notifyRemove in interface AddRemoveNotify
Parameters:
obj - the GameObject whose property list we're being removed from (in this case, the naga player)

methodCalled

public void methodCalled(java.lang.String hookName,
                         MethodHookable target,
                         java.lang.Object data)
Notifies us that one of our method-hooks of interest was run. In particular, we handle the "init" hook by calling startup().

Specified by:
methodCalled in interface MethodHookCallback
Parameters:
hookName - the name of the hook being run
target - the object on which the method was invoked: a GameMap or GameObject.
data - a method-specific data object; can be null. Check the documentation for the method hook to see if any data is passed to the callbacks.

playerDoneLoading

public void playerDoneLoading()
We've finished loading the player from the player file. All the properties and inventory are now present. Subclasses may need to do special checks here, e.g. to see if the player is wearing the correct type of armor.

Be sure to call the superclass version in your version!


getAgent

public Player getAgent()
Reutrns the player we're modifying, if it's been set.


setGuildXP

public void setGuildXP(int xp)
Sets the guild XP on this object - used when reading it from the map or player file.


getGuildXP

public int getGuildXP()
Returns the guild XP associated with this GuildSkills object - i.e. the total amount of guild XP this player has received.


adjustGuildXP

public void adjustGuildXP(int xp)
Awards some guild XP to the player, for killing a monster or doing some other task. Called by awardXP() if the attack was a result of the guild member using their primary guild skill.

Parameters:
xp - the xp to add (can be negative)

advanceLevel

public void advanceLevel(int level)
Does the stuff needed for advancing the agent a level.

Parameters:
level - the level they're advancing to

crossedLevelBoundary

public int crossedLevelBoundary(int oldxp,
                                int newxp)
Determines whether the player went up a level.

Parameters:
oldxp - the old guild experience they had
newxp - the new guild experience they have, after getting an adjustment.
Returns:
the level boundary they crossed, or -1 if none was crossed.

getGuildLevel

public int getGuildLevel(Player agent)
Returns the level in the guild that this player has attained, based on settings in their guild skills object.


getGuildLevel

public int getGuildLevel()
Returns the guild level for our agent.

Returns:
-1 if we have no agent set

getGuildLevel

public static int getGuildLevel(int xp)
Returns the guild level for the given amount of XP.


knowsCommand

public boolean knowsCommand(java.lang.String command)
Returns true if we want to handle this command.

Specified by:
knowsCommand in interface Command
Parameters:
command - the command the player typed
Returns:
true if we're handling it

createEvent

public CommandEvent createEvent(CommandEvent initial)
Creates the command event.

Specified by:
createEvent in interface Command
Parameters:
initial - a "blank" CommandEvent containing only the command text and the agent who's performing the command. This initial event is created by the originator of the event (e.g. the AI or player's command preprocessor).
Returns:
a CommandEvent subclass encapsulating this command's execution parameters and state. It should copy in the fields from the passed-in event.

execute

public boolean execute(CommandEvent event)
Executes the event.

Specified by:
execute in interface Command
Parameters:
event - the event
Returns:
true if the event executed successfully

guildScore

public boolean guildScore(CommandEvent event)
Shows current guild XP.


guildwho

public boolean guildwho(Commandable agent,
                        CommandEvent event)
Shows who's logged in.


guildtell

public boolean guildtell(Player agent,
                         java.lang.String verb,
                         java.lang.String message)
Tells a message to the other guild-members online.

Returns:
true if successful

announce

public void announce(java.lang.String message)
Sends a message to all the guild members online.


isInGuild

public boolean isInGuild(Player p)
Returns true if the specified player is in this guild. True if their "guild" object has the same class as the class of this object.


xpForLevel

public int xpForLevel(int level)
Returns XP required to reach the specified level.

Parameters:
level - guild level (1-10)
Returns:
xp for that level

readData

public void readData(org.w3c.dom.Node bean)
              throws java.lang.Exception
Tells the object to parse its externalized representation from a list of lines.

Specified by:
readData in interface SelfExternalizable
Parameters:
bean - the XML DOM representation of the externalized bean object. Its child could be a text node, in which case the bean has to do all the parsing for the data. It could also wrap a series of elements (e.g. archetypes), in which case the bean may wish to leverage the XML parsing utilities that the game provides in the ArchetypeManager.

Throws:
java.lang.Exception

writeData

public java.util.List writeData()
                         throws java.lang.Exception
Tells the object to write its properties out to a text file.

Specified by:
writeData in interface SelfExternalizable
Returns:
a list of lines to be written to the text file, formatted appropriately. The lines include everything except the and tags, which are constructed and written automatically.
Throws:
java.lang.Exception

shouldWrite

public boolean shouldWrite()
Allows the object to determine whether it wants to be written out at all. If the object determines that it's the equivalent of a null value (e.g. an item list with no items in it), it can return false and it won't go into the output file.

Specified by:
shouldWrite in interface SelfExternalizable
Returns:
true to write the object, false to skip it