 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.scripts;
43 import java.io.IOException;
44 import java.nio.ByteBuffer;
45 import java.util.regex.Matcher;
46 import java.util.regex.Pattern;
47 import org.jetbrains.annotations.NotNull;
48 import org.jetbrains.annotations.Nullable;
62 private static final Pattern
PATTERN_ISSUE = Pattern.compile(
"(-?[0-9]+) +(-?[0-9]+) +(.+)");
158 public void connecting() {
163 public void connected() {
168 public void packetReceived(@NotNull
final ByteBuffer packet) {
178 public void disconnected(@NotNull
final String reason) {
224 @Nullable String result =
"unexpected";
246 }
catch (
final IOException ex) {
247 result = ex.getMessage();
255 scriptProcessListener.scriptTerminated(result);
306 }
catch (
final IOException ex) {
317 protected abstract void writeToScript(@NotNull
final String data)
throws IOException;
326 if (item.isMagic()) {
329 if (item.isCursed()) {
332 if (item.isDamned()) {
335 if (item.isUnpaid()) {
338 if (item.isLocked()) {
341 if (item.isApplied()) {
347 final int nrof = Math.max(1, item.getNrOf());
348 final String name = nrof <= 1 ? item.getName() : nrof+
" "+item.getName();
349 commandSent(cmd+
" "+item.getTag()+
" "+nrof+
" "+Math.max(0, item.getWeight())+
" "+flags+
" "+item.getType()+
" "+name);
359 final StringBuilder sb =
new StringBuilder(
"request map ");
368 sb.append(
" n y n ");
370 sb.append(
" smooth 0 0 0 heads");
371 for (
int i = 0; i < 3; i++) {
377 for (
int i = 0; i < 3; i++) {
379 if (headSquare ==
null) {
402 if (params.equals(
"player")) {
404 }
else if (params.equals(
"range")) {
406 }
else if (params.equals(
"weight")) {
408 }
else if (params.equals(
"stat stats")) {
410 }
else if (params.equals(
"stat stats_race")) {
412 }
else if (params.equals(
"stat stats_base")) {
414 }
else if (params.equals(
"stat stats_applied")) {
416 }
else if (params.equals(
"stat cmbt")) {
418 }
else if (params.equals(
"stat hp")) {
420 }
else if (params.equals(
"stat xp")) {
421 final StringBuilder sb =
new StringBuilder(
"request stat xp ");
429 sb.append(
' ').append(skill.
getLevel());
434 }
else if (params.equals(
"stat resists")) {
435 final StringBuilder sb =
new StringBuilder(
"request stat resists");
445 }
else if (params.equals(
"stat paths")) {
447 }
else if (params.equals(
"flags")) {
449 }
else if (params.equals(
"items inv")) {
454 }
else if (params.equals(
"items actv")) {
456 if (item.isApplied()) {
461 }
else if (params.equals(
"items on")) {
466 }
else if (params.equals(
"items cont")) {
468 if (containerTag != 0) {
474 }
else if (params.equals(
"map pos")) {
484 }
else if (params.equals(
"map near")) {
488 for (
int y = -1; y <= +1; y++) {
489 for (
int x = -1; x <= +1; x++) {
493 }
else if (params.equals(
"map all")) {
497 for (
int y = 0; y < height; y++) {
498 for (
int x = 0; x < width; x++) {
502 }
else if (params.startsWith(
"map ")) {
503 final String[] tmp = params.split(
" +");
504 if (tmp.length != 3) {
511 x = Integer.parseInt(tmp[1]);
512 }
catch (
final NumberFormatException ignored) {
519 y = Integer.parseInt(tmp[2]);
520 }
catch (
final NumberFormatException ignored) {
526 }
else if (params.equals(
"skills")) {
534 }
else if (params.equals(
"spells")) {
536 commandSent(
"request spells "+spell.getTag()+
" "+spell.getLevel()+
" "+spell.getMana()+
" "+spell.getGrace()+
" "+spell.getSkill()+
" "+spell.getPath()+
" "+spell.getCastingTime()+
" "+spell.getDamage()+
" "+spell.getName());
551 tag = Integer.parseInt(params);
552 }
catch (
final NumberFormatException ignored) {
564 final String[] tmp = params.split(
" +", 2);
565 if (tmp.length != 2) {
572 val = Integer.parseInt(tmp[0]);
573 tag = Integer.parseInt(tmp[1]);
574 }
catch (
final NumberFormatException ignored) {
578 if (val < 0 || val > 1) {
592 private void cmdIssueMove(@NotNull
final String params,
final int destTag, @NotNull
final String commandName) {
593 final String[] tmp = params.split(
" +", 2);
594 if (tmp.length != 1 && tmp.length != 2) {
595 reportError(
"syntax error: issue "+commandName+
" "+params);
601 tag = Integer.parseInt(tmp[0]);
602 count = tmp.length < 2 ? 0 : Integer.parseInt(tmp[1]);
603 }
catch (
final NumberFormatException ignored) {
604 reportError(
"syntax error: issue "+commandName+
" "+params);
617 tag = Integer.parseInt(params);
618 }
catch (
final NumberFormatException ignored) {
629 private void cmdIssue(@NotNull
final String params) {
631 if (!matcher.matches()) {
639 repeat = Integer.parseInt(matcher.group(1));
640 tmp = Integer.parseInt(matcher.group(2));
641 }
catch (
final NumberFormatException ignored) {
645 if (tmp < 0 || tmp > 1) {
649 final boolean mustSend = tmp != 0;
650 final String command = matcher.group(3);
658 private void cmdDraw(@NotNull
final String params) {
659 final String[] pps = params.split(
" +", 2);
660 if (pps.length != 2) {
666 color = Integer.parseInt(pps[0]);
667 }
catch (
final NumberFormatException ignored) {
699 final String[] tmp = cmdLine.split(
" +", 2);
702 if (tmp.length == 1) {
704 }
else if (tmp[1].indexOf(
' ') != -1) {
716 if (tmp.length == 2) {
724 if (tmp.length == 2) {
725 final String tmp2 = tmp[1].split(
" ", 2)[0];
726 if (tmp2.equalsIgnoreCase(
"mark")) {
728 }
else if (tmp2.equalsIgnoreCase(
"lock")) {
730 }
else if (tmp2.equalsIgnoreCase(
"take")) {
732 }
else if (tmp2.equalsIgnoreCase(
"drop")) {
734 }
else if (tmp2.equalsIgnoreCase(
"apply")) {
745 if (tmp.length == 2) {
753 if (tmp.length == 1) {
756 reportError(
"The 'monitor' command does not take arguments.");
761 if (tmp.length == 1) {
764 reportError(
"The 'unmonitor' command does not take arguments.");
769 reportError(
"unrecognized command from script: "+cmdLine);
789 return Integer.compare(
scriptId, o.getScriptId());
798 public boolean equals(@Nullable
final Object obj) {
An external command executed as a client-sided script.
long getExperience()
Returns the amount of global experience.
final String filename
The script command including arguments.
static final int CS_STAT_DEX
The Dexterity Primary stat.
List< CfItem > getItemsByLocation(final int location)
Returns a list of items in a given location.
final CommandQueue commandQueue
The CommandQueue for sending commands.
void sendMove(int to, int tag, int nrof)
Sends a "move" command to the server.
Interface for listeners interested in drawinfo messages received from the Crossfire server.
AbstractScriptProcess(final int scriptId, @NotNull final String filename, @NotNull final CommandQueue commandQueue, @NotNull final CrossfireServerConnection crossfireServerConnection, @NotNull final Stats stats, @NotNull final FloorView floorView, @NotNull final ItemSet itemSet, @NotNull final SpellsManager spellsManager, @NotNull final MapUpdaterState mapUpdaterState, @NotNull final SkillSet skillSet)
Creates a new instance.
void addCommand(@NotNull final String command)
Adds a command to watch for.
final EventListenerList2< ScriptProcessListener > scriptProcessListeners
The ScriptProcessListeners to notify.
void sendApply(int tag)
Sends an "apply" command to the server.
Model class maintaining the CfItems known to the player.
static final int CS_STAT_POW
The Power Primary stat.
static final int CS_STAT_SPELL_ATTUNE
Attuned spell paths of a spell.
static final int CS_STAT_WEAP_SP
The Weapon Speed stat.
void destroy()
Releases allocated resources.
void cmdMonitor()
Processes a "monitor" command from the script process.
void reportError(@NotNull final String string)
Reports an error while executing client commands.
Implements the map model which is shown in the map and magic map views.
int getCurrentFloorTag()
Returns the current floor location.
void addClientSocketListener(@NotNull ClientSocketListener clientSocketListener)
Adds a ClientSocketListener to notify.
int getFaceNum()
Returns the unique face id.
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
Iterable< CfItem > getPlayerInventory()
Returns the player's inventory.
static final int CS_STAT_APPLIED_CON
The constitution primary stat changes due to gear or skills.
boolean checkFire()
Returns whether the character is firing.
void addCrossfireMapScrollListener(@NotNull final MapScrollListener listener)
Adds a listener to notify about scrolled maps.
void cmdRequest(@NotNull final String params)
Processes a "request" command from the script process.
void removeCommand(@NotNull final String command)
Removes a command to watch for.
static final int CS_STAT_APPLIED_INT
The integer primary stat changes due to gear or skills.
static final int CS_STAT_WIS
The Wisdom Primary stat.
static final int CS_STAT_DAM
The Damage stat.
Interface for listeners interested in ScriptProcess related events.
Represents a map (as seen by the client).
static final int CS_STAT_SPELL_DENY
Denied spell paths of a spell.
static final int CS_STAT_FOOD
The Food stat.
static final int CS_STAT_APPLIED_STR
The strength primary stat changes due to gear or skills.
static final int CS_STAT_RACE_CHA
The race's maximum charisma primary stat.
static final int CS_NUM_SKILLS
CS_NUM_SKILLS does not match how many skills there really are - instead, it is used as a range of val...
int getWeight()
Returns the weight.
CfMapSquare getHeadMapSquare(final int layer)
Returns the map square of the head of a multi-square object.
void cmdIssueMove(@NotNull final String params, final int destTag, @NotNull final String commandName)
Processes an "issue take" or "issue drop" command from the script process.
static final int CS_STAT_SKILLINFO
CS_STAT_SKILLINFO is used as the starting index point.
final MapUpdaterState mapUpdaterState
The MapUpdaterState instance to use.
Manages image information ("faces") needed to display the map view, items, and spell icons.
static final int CS_STAT_RACE_CON
The race's maximum constitution primary stat.
static final Pattern PATTERN_ISSUE
Matches the arguments of an "issue" command with repeat and must_send parameters.
void mapScroll(final int dx, final int dy)
Called whenever the map contents have scrolled.
static final int CS_STAT_BASE_POW
The power primary stat without boosts or depletions.
static final int CS_STAT_RACE_WIS
The race's maximum wisdom primary stat.
static final int CS_STAT_STR
The Strength Primary stat.
void addCrossfireNewmapListener(@NotNull final NewmapListener listener)
Adds a listener to notify about cleared maps.
static final int CS_STAT_BASE_INT
The integer primary stat without boosts or depletions.
int posX
The current x position of the character within the map in tiles.
A list of event listeners.
static final int CS_STAT_AC
The Armor Class stat.
Manages all known spells.
void sendMark(int tag)
Sends a "mark" command to the server.
abstract void writeToScript(@NotNull final String data)
Sends some data to the script process.
static final int CS_STAT_RESIST_START
Beginning index of the resistances.
static final int CS_STAT_HP
The Hit Points stat.
Describes a Crossfire spell.
int NDI_RED
A message color.
static final int CS_STAT_MAXHP
The Maximum Hit Points stat.
final ItemSet itemSet
The ItemSet instance to use.
The representation of a Crossfire Item, client-side.
String getRange()
Returns the current content of the range stat.
static final int CS_STAT_APPLIED_CHA
The charisma primary stat changes due to gear or skills.
int getMapHeight()
Returns the height of the visible map area.
void cmdIssueApply(@NotNull final String params)
Processes an "issue apply" command from the script process.
CfMap getMap()
Returns the current map instance.
void killScript()
Kills the script process.
static final int CS_STAT_SP
The Spell Points stat.
static final int CS_STAT_SPELL_REPEL
Repelled spell paths of a spell.
int getScriptId()
Returns the script ID identifying this script instance.
int getTag()
Returns the tag.
One skill of the character.
static final int CS_STAT_LEVEL
The Global Level stat.
void sendNcom(final boolean mustSend, @NotNull final String command)
Sends a "ncom" command to the server.
void newmap()
Called whenever a "newmap" message has been received.
static final int CS_STAT_RACE_INT
The race's maximum intelligence primary stat.
static final int CS_STAT_RACE_STR
The race's maximum strength primary stat.
static final int CS_STAT_RACE_DEX
The race's maximum dexterity primary stat.
final int scriptId
The script ID identifying this script instance.
int getScriptId()
Returns the script ID identifying this script instance.
void runScriptCommand(@NotNull final String cmdLine)
Processes a line received from the script process.
static final int CS_STAT_CHA
The Charisma Primary stat.
static final int CS_STAT_WEIGHT_LIM
The Weight Limit stat.
final CrossfireServerConnection crossfireServerConnection
The connection instance.
Skill getSkill(final int id)
Returns the given skill as a Skill object.
Face getFace(final int layer)
Returns the face of a layer.
static final int CS_STAT_WC
The Weapon Class stat.
This is the representation of all the statistics of a player, like its speed or its experience.
static final Face DEFAULT_FACE
The default face value for newly creates squares.
static final int CS_STAT_MAXGRACE
The Maximum Grace stat.
boolean equals(@Nullable final Object obj)
void cmdIssue(@NotNull final String params)
Processes a regular "issue" command from the script process.
static final int CS_STAT_CON
The Constitution Primary stat.
void sendLock(boolean val, int tag)
Sends a "lock" command to the server.
static final int CS_STAT_BASE_CON
The constitution primary stat without boosts or depletions.
final PacketWatcher packetWatcher
The PacketWatcher to process "watch" commands.
CfItem getPlayer()
Returns the player object this client controls.
static final int CS_STAT_APPLIED_DEX
The dexterity primary stat changes due to gear or skills.
abstract String readFromScript()
Reads a line from the script process.
static final int CS_STAT_RESIST_END
End index of the resistances.
void commandSentItem(@NotNull final String cmd, @NotNull final CfItem item)
Sends an item info message to the script process.
int getDarkness()
Returns the darkness value of this square.
static final int CS_STAT_BASE_STR
The strength primary stat without boosts or depletions.
Implements the "watch" function for client-sided scripts.
final Stats stats
The Stats instance to watch.
void drawInfo(@NotNull String message, int color)
Pretends that a drawinfo message has been received.
static final int CS_STAT_INT
The Intelligence Primary stat.
String getTitle()
Returns the current title.
Interface for listeners interested in ClientSocket related events.
long getExperience()
Returns the skill experience.
void commandSentMap(@NotNull final CfMap map, final int x, final int y)
Sends info about one map cell to the script process.
void removeClientSocketListener(@NotNull ClientSocketListener clientSocketListener)
Removes a ClientSocketListener to notify.
void cmdIssueMark(@NotNull final String params)
Processes an "issue mark" command from the script process.
static final int CS_STAT_FLAGS
The various flags used in stats.
int posY
The current y position of the character within the map in tiles.
int getMapWidth()
Returns the width of the visible map area.
void cmdUnmonitor()
Processes an "unmonitor" command from the script process.
int compareTo(@NotNull final ScriptProcess o)
boolean isMonitoring
Whether a "monitor" command is active.
Interface for querying monitor commands for script processes.
void commandSent(@NotNull final String cmd)
Sends a message to the script process.
void removeCrossfireNewmapListener(@NotNull final NewmapListener listener)
Removes a listener to notify about cleared maps.
static final int CS_STAT_APPLIED_POW
The power primary stat changes due to gear or skills.
final FloorView floorView
The FloorView to use.
static final int CS_STAT_RACE_POW
The race's maximum power primary stat.
static final int CS_STAT_SPEED
The Speed stat.
Represents a square in a CfMap.
void cmdIssueLock(@NotNull final String params)
Processes an "issue lock" command from the script process.
static final int CS_STAT_GRACE
The Grace stat.
Default implementation for ScriptProcesses.
static final int CS_STAT_MAXSP
The Maximum Spell Points stat.
static final int CS_STAT_APPLIED_WIS
The wisdom primary stat changes due to gear or skills.
final SpellsManager spellsManager
The SpellsManager instance to use.
void cmdDraw(@NotNull final String params)
Processes a "draw" command from the script process.
Provides a view to all items comprising the current floor view.
Maintain the set of skills as sent by the server.
int getStat(final int statNo)
Returns the numerical value of the given statistic.
static final int CS_STAT_BASE_DEX
The dexterity primary stat without boosts or depletions.
Update a CfMap model from protocol commands.
String getFilename()
Returns the script's filename.
void addScriptProcessListener(@NotNull final ScriptProcessListener scriptProcessListener)
Adds a ScriptProcessListener to be notified.
int getLevel()
Returns the skill level.
boolean isFogOfWar()
Determines if the square is not up-to-date.
void sendRawString(@NotNull final String command)
Sends a raw command to the server.
final SkillSet skillSet
The SkillSet for looking up skill names.
Maintains the pending (ncom) commands sent to the server.
boolean checkRun()
Returns whether the character is running.
static final int CS_STAT_BASE_CHA
The charisma primary stat without boosts or depletions.
static final int CS_STAT_BASE_WIS
The wisdom primary stat without boosts or depletions.
final ClientSocketListener clientSocketListener
The ClientSocketListener attached to crossfireServerConnection to track commands sent to the server.
abstract String waitForTermination()
Waits until the script has terminated.
Collection< Spell > getAllSpells()
Returns all known spells.
void removeCrossfireMapScrollListener(@NotNull final MapScrollListener listener)
Removes a listener to notify about scrolled maps.