Crossfire JXClient, Trunk  R20561
DefaultScriptProcess.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.scripts;
23 
41 import java.io.BufferedReader;
42 import java.io.IOException;
43 import java.io.InputStream;
44 import java.io.InputStreamReader;
45 import java.io.OutputStreamWriter;
46 import java.io.UnsupportedEncodingException;
47 import java.nio.ByteBuffer;
48 import org.jetbrains.annotations.NotNull;
49 import org.jetbrains.annotations.Nullable;
50 
56 public class DefaultScriptProcess implements Runnable, ScriptProcess {
57 
61  private final int scriptId;
62 
66  @NotNull
67  private final String filename;
68 
72  @NotNull
73  private final CommandQueue commandQueue;
74 
78  @NotNull
80 
84  @NotNull
85  private final Stats stats;
86 
90  @NotNull
91  private final FloorView floorView;
92 
96  @NotNull
97  private final ItemSet itemSet;
98 
102  @NotNull
103  private final Iterable<Spell> spellsManager;
104 
108  @NotNull
110 
114  @NotNull
115  private final SkillSet skillSet;
116 
120  @NotNull
121  private final Process process;
122 
126  @NotNull
127  private final InputStream in;
128 
132  @NotNull
133  private final OutputStreamWriter osw;
134 
138  @NotNull
140 
144  @NotNull
146 
150  private boolean isMonitoring;
151 
155  private boolean killed;
156 
161  @NotNull
163 
164  @Override
165  public void connecting() {
166  // ignore
167  }
168 
169  @Override
170  public void connected() {
171  // ignore
172  }
173 
174  @Override
175  public void packetReceived(@NotNull final ByteBuffer packet) {
176  // ignore
177  }
178 
179  @Override
180  public void packetSent(@NotNull final byte[] buf, final int len) {
181  final String cmd;
182  try {
183  cmd = new String(buf, 0, len, "ISO-8859-1");
184  } catch (final UnsupportedEncodingException ex) {
185  throw new AssertionError(ex); // will never happen: every JVM must implement ISO-8859-1
186  }
187  commandSent(cmd);
188  }
189 
190  @Override
191  public void disconnecting(@NotNull final String reason, final boolean isError) {
192  // ignore
193  }
194 
195  @Override
196  public void disconnected(@NotNull final String reason) {
197  // ignore
198  }
199 
200  };
201 
216  public DefaultScriptProcess(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 Iterable<Spell> spellsManager, @NotNull final MapUpdaterState mapUpdaterState, @NotNull final SkillSet skillSet) throws IOException {
217  this.scriptId = scriptId;
218  this.filename = filename;
219  this.commandQueue = commandQueue;
220  this.crossfireServerConnection = crossfireServerConnection;
221  this.stats = stats;
222  this.floorView = floorView;
223  this.itemSet = itemSet;
224  this.spellsManager = spellsManager;
225  this.mapUpdaterState = mapUpdaterState;
226  this.skillSet = skillSet;
227  packetWatcher = new PacketWatcher(crossfireServerConnection, this);
228  final Runtime rt = Runtime.getRuntime();
229  process = rt.exec(filename);
230  in = process.getInputStream();
231  //noinspection IOResourceOpenedButNotSafelyClosed
232  osw = new OutputStreamWriter(process.getOutputStream());
233  }
234 
238  @Override
239  public int getScriptId() {
240  return scriptId;
241  }
242 
246  @NotNull
247  @Override
248  public String getFilename() {
249  return filename;
250  }
251 
255  @Override
256  public void run() {
257  @Nullable String result = "unexpected";
258  try {
259  try {
260  try (final InputStreamReader isr = new InputStreamReader(in)) {
261  try (final BufferedReader br = new BufferedReader(isr)) {
262  while (true) {
263  final String line = br.readLine();
264  if (line == null) {
265  break;
266  }
267 
268  runScriptCommand(line);
269  }
270  }
271  }
272  try {
273  final int exitStatus = process.waitFor();
274  result = exitStatus == 0 ? null : "exit "+exitStatus;
275  } catch (final InterruptedException ex) {
276  result = ex.getMessage();
277  }
278  } catch (final IOException ex) {
279  result = ex.getMessage();
280  }
281  crossfireServerConnection.removeClientSocketListener(clientSocketListener);
282  } finally {
283  if (isMonitoring) {
284  crossfireServerConnection.removeClientSocketListener(clientSocketListener);
285  }
286  packetWatcher.destroy();
287  for (final ScriptProcessListener scriptProcessListener : scriptProcessListeners) {
288  scriptProcessListener.scriptTerminated(result);
289  }
290  }
291  }
292 
296  @Override
297  public void commandSent(@NotNull final String cmd) {
298  if (killed) {
299  return;
300  }
301 
302  try {
303  osw.write(cmd+"\n");
304  osw.flush();
305  } catch (final IOException ex) {
306  reportError(ex.getMessage());
307  killScript();
308  }
309  }
310 
316  private void commandSentItem(@NotNull final String cmd, @NotNull final CfItem item) {
317  int flags = 0;
318  if (item.isMagic()) {
319  flags |= 0x100;
320  }
321  if (item.isCursed()) {
322  flags |= 0x80;
323  }
324  if (item.isDamned()) {
325  flags |= 0x40;
326  }
327  if (item.isUnpaid()) {
328  flags |= 0x20;
329  }
330  if (item.isLocked()) {
331  flags |= 0x10;
332  }
333  if (item.isApplied()) {
334  flags |= 0x08;
335  }
336  if (item.isOpen()) {
337  flags |= 0x04;
338  }
339  final int nrof = Math.max(1, item.getNrOf());
340  final String name = nrof <= 1 ? item.getName() : nrof+" "+item.getName();
341  commandSent(cmd+" "+item.getTag()+" "+nrof+" "+Math.max(0, item.getWeight())+" "+flags+" "+item.getType()+" "+name);
342  }
343 
350  private void commandSentMap(@NotNull final CfMap map, final int x, final int y) {
351  final StringBuilder sb = new StringBuilder("request map ");
352  //noinspection SynchronizationOnLocalVariableOrMethodParameter
353  synchronized (map) {
354  final CfMapSquare square = map.getMapSquare(x, y);
355  sb.append(x);
356  sb.append(' ');
357  sb.append(y);
358  sb.append(' ');
359  sb.append(square.getDarkness());
360  sb.append(" n y n "); // XXX: smoothing
361  sb.append(square.isFogOfWar() ? 'y' : 'n');
362  sb.append(" smooth 0 0 0 heads"); // XXX: smoothing
363  for (int i = 0; i < 3; i++) {
364  sb.append(' ');
365  final Face face = square.getFace(i);
366  //noinspection ConstantConditions
367  sb.append(face == CfMapSquare.DEFAULT_FACE ? 0 : face.getFaceNum());
368  }
369  sb.append(" tails");
370  for (int i = 0; i < 3; i++) {
371  final CfMapSquare headSquare = square.getHeadMapSquare(i);
372  if (headSquare == null) {
373  sb.append(" 0");
374  } else {
375  sb.append(' ');
376  final Face face = headSquare.getFace(i);
377  //noinspection ConstantConditions
378  sb.append(face == CfMapSquare.DEFAULT_FACE ? 0 : face.getFaceNum());
379  }
380  }
381  }
382  commandSent(sb.toString());
383  }
384 
388  @NotNull
389  @Override
390  public String toString() {
391  return scriptId+" "+filename;
392  }
393 
398  private void cmdRequest(@NotNull final String params) {
399  if (params.equals("player")) {
400  commandSent("request player "+itemSet.getPlayer().getTag()+" "+stats.getTitle());
401  } else if (params.equals("range")) {
402  commandSent("request range "+stats.getRange());
403  } else if (params.equals("weight")) {
404  commandSent("request weight "+stats.getStat(Stats.CS_STAT_WEIGHT_LIM)+" "+itemSet.getPlayer().getWeight());
405  } else if (params.equals("stat stats")) {
406  commandSent("request stat stats "+stats.getStat(Stats.CS_STAT_STR)+" "+stats.getStat(Stats.CS_STAT_CON)+" "+stats.getStat(Stats.CS_STAT_DEX)+" "+stats.getStat(Stats.CS_STAT_INT)+" "+stats.getStat(Stats.CS_STAT_WIS)+" "+stats.getStat(Stats.CS_STAT_POW)+" "+stats.getStat(Stats.CS_STAT_CHA));
407  } else if (params.equals("stat stats_race")) {
409  } else if (params.equals("stat stats_base")) {
411  } else if (params.equals("stat stats_applied")) {
413  } else if (params.equals("stat cmbt")) {
414  commandSent("request stat cmbt "+stats.getStat(Stats.CS_STAT_WC)+" "+stats.getStat(Stats.CS_STAT_AC)+" "+stats.getStat(Stats.CS_STAT_DAM)+" "+stats.getStat(Stats.CS_STAT_SPEED)+" "+stats.getStat(Stats.CS_STAT_WEAP_SP));
415  } else if (params.equals("stat hp")) {
416  commandSent("request stat hp "+stats.getStat(Stats.CS_STAT_HP)+" "+stats.getStat(Stats.CS_STAT_MAXHP)+" "+stats.getStat(Stats.CS_STAT_SP)+" "+stats.getStat(Stats.CS_STAT_MAXSP)+" "+stats.getStat(Stats.CS_STAT_GRACE)+" "+stats.getStat(Stats.CS_STAT_MAXGRACE)+" "+stats.getStat(Stats.CS_STAT_FOOD));
417  } else if (params.equals("stat xp")) {
418  final StringBuilder sb = new StringBuilder("request stat xp ");
419  sb.append(stats.getStat(Stats.CS_STAT_LEVEL));
420  sb.append(' ').append(stats.getExperience());
422  final Skill skill = skillSet.getSkill(i);
423  if (skill == null) {
424  sb.append(" 0 0");
425  } else {
426  sb.append(' ').append(skill.getLevel());
427  sb.append(' ').append(skill.getExperience());
428  }
429  }
430  commandSent(sb.toString());
431  } else if (params.equals("stat resists")) {
432  final StringBuilder sb = new StringBuilder("request stat resists");
433  for (int i = Stats.CS_STAT_RESIST_START; i <= Stats.CS_STAT_RESIST_END; i++) {
434  sb.append(' ');
435  sb.append(stats.getStat(i));
436  }
437  // add dummy values for GTK client compatibility
438  for (int i = Stats.CS_STAT_RESIST_END+1-Stats.CS_STAT_RESIST_START; i < 30; i++) {
439  sb.append(" 0");
440  }
441  commandSent(sb.toString());
442  } else if (params.equals("stat paths")) {
444  } else if (params.equals("flags")) {
445  commandSent("request flags "+stats.getStat(Stats.CS_STAT_FLAGS)+" "+(commandQueue.checkFire() ? "1" : "0")+" "+(commandQueue.checkRun() ? "1" : "0")+" 0");
446  } else if (params.equals("items inv")) {
447  for (final CfItem item : itemSet.getPlayerInventory()) {
448  commandSentItem("request items inv", item);
449  }
450  commandSent("request items inv end");
451  } else if (params.equals("items actv")) {
452  for (final CfItem item : itemSet.getPlayerInventory()) {
453  if (item.isApplied()) {
454  commandSentItem("request items actv", item);
455  }
456  }
457  commandSent("request items actv end");
458  } else if (params.equals("items on")) {
459  for (final CfItem item : itemSet.getItemsByLocation(0)) {
460  commandSentItem("request items on", item);
461  }
462  commandSent("request items on end");
463  } else if (params.equals("items cont")) {
464  final int containerTag = floorView.getCurrentFloor();
465  if (containerTag != 0) {
466  for (final CfItem item : itemSet.getItemsByLocation(containerTag)) {
467  commandSentItem("request items cont", item);
468  }
469  }
470  commandSent("request items cont end");
471  } else if (params.equals("map pos")) {
472  commandSent("request map pos "+mapUpdaterState.getMapWidth()/2+" "+mapUpdaterState.getMapHeight()/2);
473  } else if (params.equals("map near")) {
474  final CfMap map = mapUpdaterState.getMap();
475  final int centerX = mapUpdaterState.getMapWidth()/2;
476  final int centerY = mapUpdaterState.getMapHeight()/2;
477  for (int y = -1; y <= +1; y++) {
478  for (int x = -1; x <= +1; x++) {
479  commandSentMap(map, centerX+x, centerY+y);
480  }
481  }
482  } else if (params.equals("map all")) {
483  final CfMap map = mapUpdaterState.getMap();
484  final int width = mapUpdaterState.getMapWidth()/2;
485  final int height = mapUpdaterState.getMapHeight()/2;
486  for (int y = 0; y < height; y++) {
487  for (int x = 0; x < width; x++) {
488  commandSentMap(map, x, y);
489  }
490  }
491  } else if (params.startsWith("map ")) {
492  final String[] tmp = params.split(" +");
493  if (tmp.length != 3) {
494  reportError("syntax error: request "+params);
495  return;
496  }
497 
498  final int x;
499  try {
500  x = Integer.parseInt(tmp[1]);
501  } catch (final NumberFormatException ignored) {
502  reportError("syntax error: request "+params);
503  return;
504  }
505 
506  final int y;
507  try {
508  y = Integer.parseInt(tmp[2]);
509  } catch (final NumberFormatException ignored) {
510  reportError("syntax error: request "+params);
511  return;
512  }
513 
514  commandSentMap(mapUpdaterState.getMap(), x, y);
515  } else if (params.equals("skills")) {
517  final Object skill = skillSet.getSkill(i);
518  if (skill != null) {
519  commandSent("request skills "+i+" "+skill);
520  }
521  }
522  commandSent("request skills end");
523  } else if (params.equals("spells")) {
524  for (final Spell spell : spellsManager) {
525  commandSent("request spells "+spell.getTag()+" "+spell.getLevel()+" "+spell.getMana()+" "+spell.getGrace()+" "+spell.getSkill()+" "+spell.getPath()+" "+spell.getCastingTime()+" "+spell.getDamage()+" "+spell.getName());
526  }
527  commandSent("request spells end");
528  } else {
529  reportError("syntax error: request "+params);
530  }
531  }
532 
537  private void cmdIssueMark(@NotNull final String params) {
538  final int tag;
539  try {
540  tag = Integer.parseInt(params);
541  } catch (final NumberFormatException ignored) {
542  reportError("syntax error: issue mark "+params);
543  return;
544  }
545  crossfireServerConnection.sendMark(tag);
546  }
547 
552  private void cmdIssueLock(@NotNull final String params) {
553  final String[] tmp = params.split(" +", 2);
554  if (tmp.length != 2) {
555  reportError("syntax error: issue lock "+params);
556  return;
557  }
558  final int val;
559  final int tag;
560  try {
561  val = Integer.parseInt(tmp[0]);
562  tag = Integer.parseInt(tmp[1]);
563  } catch (final NumberFormatException ignored) {
564  reportError("syntax error: issue lock "+params);
565  return;
566  }
567  if (val < 0 || val > 1) {
568  reportError("syntax error: issue lock "+params);
569  return;
570  }
571  crossfireServerConnection.sendLock(val != 0, tag);
572  }
573 
578  private void cmdIssue(@NotNull final String params) {
579  final String[] pps = params.split(" +", 3);
580  if (pps.length != 3) {
581  reportError("syntax error: issue "+params);
582  return;
583  }
584  final int repeat;
585  final int tmp;
586  try {
587  repeat = Integer.parseInt(pps[0]);
588  tmp = Integer.parseInt(pps[1]);
589  } catch (final NumberFormatException ignored) {
590  reportError("syntax error: issue "+params);
591  return;
592  }
593  if (tmp < 0 || tmp > 1) {
594  reportError("syntax error: issue "+params);
595  return;
596  }
597  final boolean mustSend = tmp != 0;
598  final String command = pps[2];
599  commandQueue.sendNcom(mustSend, repeat, command);
600  }
601 
606  private void cmdDraw(@NotNull final String params) {
607  final String[] pps = params.split(" +", 2);
608  if (pps.length != 2) {
609  reportError("syntax error: draw "+params);
610  return;
611  }
612  final int color;
613  try {
614  color = Integer.parseInt(pps[0]);
615  } catch (final NumberFormatException ignored) {
616  reportError("syntax error: draw "+params);
617  return;
618  }
619  crossfireServerConnection.drawInfo(pps[1], color);
620  }
621 
625  private void cmdMonitor() {
626  if (!isMonitoring) {
627  isMonitoring = true;
628  crossfireServerConnection.addClientSocketListener(clientSocketListener);
629  }
630  }
631 
635  private void cmdUnmonitor() {
636  if (isMonitoring) {
637  isMonitoring = false;
638  crossfireServerConnection.removeClientSocketListener(clientSocketListener);
639  }
640  }
641 
646  private void runScriptCommand(@NotNull final String cmdLine) {
647  final String[] tmp = cmdLine.split(" +", 2);
648  switch (tmp[0]) {
649  case "watch":
650  if (tmp.length == 1) {
651  packetWatcher.addCommand("");
652  } else if (tmp[1].indexOf(' ') != -1) {
653  reportError("syntax error: "+cmdLine);
654  } else {
655  packetWatcher.addCommand(tmp[1]);
656  }
657  break;
658 
659  case "unwatch":
660  packetWatcher.removeCommand(tmp.length >= 2 ? tmp[1] : "");
661  break;
662 
663  case "request":
664  if (tmp.length == 2) {
665  cmdRequest(tmp[1]);
666  } else {
667  reportError("syntax error: "+cmdLine);
668  }
669  break;
670 
671  case "issue":
672  if (tmp.length != 2) {
673  reportError("syntax error: "+cmdLine);
674  } else if (tmp[1].startsWith("mark ")) {
675  cmdIssueMark(tmp[1].substring(5));
676  } else if (tmp[1].startsWith("lock ")) {
677  cmdIssueLock(tmp[1].substring(5));
678  } else {
679  cmdIssue(tmp[1]);
680  }
681  break;
682 
683  case "draw":
684  if (tmp.length == 2) {
685  cmdDraw(tmp[1]);
686  } else {
687  reportError("syntax error: "+cmdLine);
688  }
689  break;
690 
691  case "monitor":
692  if (tmp.length == 1) {
693  cmdMonitor();
694  } else {
695  reportError("The 'monitor' command does not take arguments.");
696  }
697  break;
698 
699  case "unmonitor":
700  if (tmp.length == 1) {
701  cmdUnmonitor();
702  } else {
703  reportError("The 'unmonitor' command does not take arguments.");
704  }
705  break;
706 
707  default:
708  reportError("unrecognized command from script: "+cmdLine);
709  break;
710  }
711  }
712 
717  private void reportError(@NotNull final String string) {
718  crossfireServerConnection.drawInfo(string, CrossfireDrawinfoListener.NDI_RED);
719  }
720 
724  @Override
725  public void addScriptProcessListener(@NotNull final ScriptProcessListener scriptProcessListener) {
726  scriptProcessListeners.add(scriptProcessListener);
727  }
728 
732  @Override
733  public void killScript() {
734  killed = true;
735  process.destroy();
736  }
737 
741  @Override
742  public int compareTo(@NotNull final ScriptProcess o) {
743  if (scriptId < o.getScriptId()) {
744  return -1;
745  }
746  if (scriptId > o.getScriptId()) {
747  return +1;
748  }
749  return 0;
750  }
751 
755  @Override
756  public int hashCode() {
757  return scriptId;
758  }
759 
763  @Override
764  public boolean equals(@Nullable final Object obj) {
765  if (!(obj instanceof ScriptProcess)) {
766  return false;
767  }
768 
769  final ScriptProcess scriptProcess = (ScriptProcess)obj;
770  return scriptProcess.getScriptId() == scriptId;
771  }
772 
773 }
final OutputStreamWriter osw
The OutputStreamWriter associated with process.
boolean checkRun()
Returns whether the character is running.
final int scriptId
The script ID identifying this script instance.
static final int CS_STAT_RACE_CHA
The race&#39;s maximum charisma primary stat.
Definition: Stats.java:239
CfMapSquare getHeadMapSquare(final int layer)
Returns the map square of the head of a multi-square object.
void cmdDraw(@NotNull final String params)
Processes a "draw" command from the script process.
int getMapHeight()
Returns the height of the visible map area.
static final int CS_STAT_DEX
The Dexterity Primary stat.
Definition: Stats.java:83
static final int CS_STAT_SPELL_ATTUNE
Attuned spell paths of a spell.
Definition: Stats.java:199
boolean isMonitoring
Whether a "monitor" command is active.
int getMapWidth()
Returns the width of the visible map area.
void commandSentItem(@NotNull final String cmd, @NotNull final CfItem item)
Sends an item info message to the script process.
Represents a square in a CfMap.
void runScriptCommand(@NotNull final String cmdLine)
Processes a line received from the script process.
List< CfItem > getItemsByLocation(final int location)
Returns a list of items in a given location.
Definition: ItemSet.java:130
CfMap getMap()
Returns the current map instance.
void sendNcom(final boolean mustSend, @NotNull final String command)
Sends an "ncom" command to the server.
void cmdUnmonitor()
Processes an "unmonitor" command from the script process.
static final int CS_STAT_SPELL_DENY
Denied spell paths of a spell.
Definition: Stats.java:209
Iterable< CfItem > getPlayerInventory()
Returns the player&#39;s inventory.
Definition: ItemSet.java:312
Represents a map (as seen by the client).
Definition: CfMap.java:45
Interface for listeners interested in drawinfo messages received from the Crossfire server...
int getScriptId()
Returns the script ID identifying this script instance.
static final int CS_STAT_APPLIED_CON
The constitution primary stat changes due to gear or skills.
Definition: Stats.java:304
static final int CS_STAT_RESIST_START
Beginning index of the resistances.
Definition: Stats.java:329
String getFilename()
Returns the script&#39;s filename.the script&#39;s filename
static final int CS_STAT_BASE_POW
The power primary stat without boosts or depletions.
Definition: Stats.java:279
void sendLock(boolean val, int tag)
Sends a "lock" command to the server.
static final int CS_STAT_POW
The Power Primary stat.
Definition: Stats.java:164
void commandSent(@NotNull final String cmd)
Sends a message to the script process.the message to send
int getDarkness()
Returns the darkness value of this square.
static final int CS_STAT_APPLIED_INT
The integer primary stat changes due to gear or skills.
Definition: Stats.java:289
final SkillSet skillSet
The SkillSet for looking up skill names.
long getExperience()
Returns the amount of global experience.
Definition: Stats.java:722
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...
Definition: Stats.java:447
int getLevel()
Returns the skill level.
Definition: Skill.java:97
Implements the map model which is shown in the map and magic map views.
Definition: CfMap.java:22
void destroy()
Releases allocated resources.
static final int CS_STAT_HP
The Hit Points stat.
Definition: Stats.java:48
DefaultScriptProcess(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 Iterable< Spell > spellsManager, @NotNull final MapUpdaterState mapUpdaterState, @NotNull final SkillSet skillSet)
Creates a new instance.
static final int CS_STAT_LEVEL
The Global Level stat.
Definition: Stats.java:108
void sendMark(int tag)
Sends a "mark" command to the server.
void addScriptProcessListener(@NotNull final ScriptProcessListener scriptProcessListener)
Adds a ScriptProcessListener to be notified.the listener to add
void removeClientSocketListener(@NotNull ClientSocketListener clientSocketListener)
Removes a ClientSocketListener to notify.
Interface for listeners interested in ScriptProcess related events.
static final int CS_STAT_MAXHP
The Maximum Hit Points stat.
Definition: Stats.java:53
static final int CS_STAT_RACE_WIS
The race&#39;s maximum wisdom primary stat.
Definition: Stats.java:224
Manages image information ("faces") needed to display the map view, items, and spell icons...
static final int CS_STAT_DAM
The Damage stat.
Definition: Stats.java:123
static final int CS_STAT_STR
The Strength Primary stat.
Definition: Stats.java:68
static final int CS_STAT_AC
The Armor Class stat.
Definition: Stats.java:118
static final int CS_STAT_FOOD
The Food stat.
Definition: Stats.java:138
static final int CS_STAT_WIS
The Wisdom Primary stat.
Definition: Stats.java:78
void killScript()
Kills the script process.Does nothing if the process is not running.
static final int CS_STAT_BASE_INT
The integer primary stat without boosts or depletions.
Definition: Stats.java:254
final CommandQueue commandQueue
The CommandQueue for sending commands.
void drawInfo(@NotNull String message, int color)
Pretends that a drawinfo message has been received.
static final int CS_STAT_SP
The Spell Points stat.
Definition: Stats.java:58
void addCommand(@NotNull final String command)
Adds a command to watch for.
final PacketWatcher packetWatcher
The PacketWatcher to process "watch" commands.
One skill of the character.
Definition: Skill.java:32
void addClientSocketListener(@NotNull ClientSocketListener clientSocketListener)
Adds a ClientSocketListener to notify.
static final int CS_STAT_RACE_CON
The race&#39;s maximum constitution primary stat.
Definition: Stats.java:234
void cmdIssueLock(@NotNull final String params)
Processes a "issue lock" command from the script process.
static final int CS_STAT_WEIGHT_LIM
The Weight Limit stat.
Definition: Stats.java:184
static final int CS_STAT_APPLIED_STR
The strength primary stat changes due to gear or skills.
Definition: Stats.java:284
static final int CS_STAT_BASE_STR
The strength primary stat without boosts or depletions.
Definition: Stats.java:249
static final int CS_STAT_SKILLINFO
CS_STAT_SKILLINFO is used as the starting index point.
Definition: Stats.java:454
long getExperience()
Returns the skill experience.
Definition: Skill.java:89
Describes a Crossfire spell.
Definition: Spell.java:36
static final int CS_STAT_CON
The Constitution Primary stat.
Definition: Stats.java:88
void reportError(@NotNull final String string)
Reports an error while executing client commands.
static final int CS_STAT_RACE_STR
The race&#39;s maximum strength primary stat.
Definition: Stats.java:214
static final int CS_STAT_APPLIED_DEX
The dexterity primary stat changes due to gear or skills.
Definition: Stats.java:299
void commandSentMap(@NotNull final CfMap map, final int x, final int y)
Sends info about one map cell to the script process.
void removeCommand(@NotNull final String command)
Removes a command to watch for.
String getRange()
Returns the current content of the range stat.
Definition: Stats.java:659
Update a CfMap model from protocol commands.
boolean isFogOfWar()
Determines if the square is not up-to-date.
void add(@NotNull final T listener)
Adds a listener.
Implements the "watch" function for client-sided scripts.
final Iterable< Spell > spellsManager
The SpellsManager instance to use.
final Process process
The Process instance for the executed child process.
static final int CS_STAT_RACE_INT
The race&#39;s maximum intelligence primary stat.
Definition: Stats.java:219
static final int CS_STAT_MAXGRACE
The Maximum Grace stat.
Definition: Stats.java:174
Skill getSkill(final int id)
Returns the given skill as a Skill object.
Definition: SkillSet.java:172
Interface for listeners interested in ClientSocket related events.
final EventListenerList2< ScriptProcessListener > scriptProcessListeners
The ScriptProcessListeners to notify.
static final int CS_STAT_RACE_DEX
The race&#39;s maximum dexterity primary stat.
Definition: Stats.java:229
int getWeight()
Returns the weight.
Definition: CfItem.java:284
static final int CS_STAT_BASE_CON
The constitution primary stat without boosts or depletions.
Definition: Stats.java:269
static final int CS_STAT_CHA
The Charisma Primary stat.
Definition: Stats.java:93
static final Face DEFAULT_FACE
The default face value for newly creates squares.
final ClientSocketListener clientSocketListener
The ClientSocketListener attached to crossfireServerConnection to track commands sent to the server...
int getScriptId()
Returns the script ID identifying this script instance.the script ID
final CrossfireServerConnection crossfireServerConnection
The connection instance.
static final int CS_STAT_APPLIED_CHA
The charisma primary stat changes due to gear or skills.
Definition: Stats.java:309
static final int CS_STAT_SPELL_REPEL
Repelled spell paths of a spell.
Definition: Stats.java:204
static final int CS_STAT_WC
The Weapon Class stat.
Definition: Stats.java:113
final MapUpdaterState mapUpdaterState
The MapUpdaterState instance to use.
CfItem getPlayer()
Returns the player object this client controls.
Definition: ItemSet.java:284
static final int CS_STAT_BASE_WIS
The wisdom primary stat without boosts or depletions.
Definition: Stats.java:259
static final int CS_STAT_BASE_DEX
The dexterity primary stat without boosts or depletions.
Definition: Stats.java:264
static final int CS_STAT_RESIST_END
End index of the resistances.
Definition: Stats.java:334
An external command executed as a client-sided script.
Face getFace(final int layer)
Returns the face of a layer.
boolean checkFire()
Returns whether the character is firing.
static final int CS_STAT_RACE_POW
The race&#39;s maximum power primary stat.
Definition: Stats.java:244
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
Model class maintaining the CfItems known to the player.
Definition: ItemSet.java:43
static final int CS_STAT_INT
The Intelligence Primary stat.
Definition: Stats.java:73
Maintains the pending (ncom) commands sent to the server.
void cmdMonitor()
Processes a "monitor" command from the script process.
static final int CS_STAT_FLAGS
The various flags used in stats.
Definition: Stats.java:179
This is the representation of all the statistics of a player, like its speed or its experience...
Definition: Stats.java:43
static final int CS_STAT_WEAP_SP
The Weapon Speed stat.
Definition: Stats.java:148
void cmdIssue(@NotNull final String params)
Processes a regular "issue" command from the script process.
Maintain the set of skills as sent by the server.
Definition: SkillSet.java:38
static final int CS_STAT_MAXSP
The Maximum Spell Points stat.
Definition: Stats.java:63
The representation of a Crossfire Item, client-side.
Definition: CfItem.java:36
static final int CS_STAT_APPLIED_POW
The power primary stat changes due to gear or skills.
Definition: Stats.java:314
int getFaceNum()
Returns the unique face id.
Definition: Face.java:105
String getTitle()
Returns the current title.
Definition: Stats.java:649
static final int CS_STAT_SPEED
The Speed stat.
Definition: Stats.java:133
final String filename
The script command including arguments.
int getCurrentFloor()
Returns the current floor location.
Definition: FloorView.java:135
static final int CS_STAT_GRACE
The Grace stat.
Definition: Stats.java:169
void cmdRequest(@NotNull final String params)
Processes a "request" command from the script process.
static final int CS_STAT_BASE_CHA
The charisma primary stat without boosts or depletions.
Definition: Stats.java:274
void cmdIssueMark(@NotNull final String params)
Processes a "issue mark" command from the script process.
Provides a view to all items comprising the current floor view.
Definition: FloorView.java:35
static final int CS_STAT_APPLIED_WIS
The wisdom primary stat changes due to gear or skills.
Definition: Stats.java:294
int getStat(final int statNo)
Returns the numerical value of the given statistic.
Definition: Stats.java:615