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);
804 public boolean equals(@Nullable
final Object obj) {
void cmdIssueMove(@NotNull final String params, final int destTag, @NotNull final String commandName)
void addClientSocketListener(@NotNull ClientSocketListener clientSocketListener)
void removeClientSocketListener(@NotNull ClientSocketListener clientSocketListener)
void sendLock(boolean val, int tag)
void removeCommand(@NotNull final String command)
static final int CS_STAT_LEVEL
static final int CS_NUM_SKILLS
static final int CS_STAT_BASE_POW
int compareTo(@NotNull final ScriptProcess o)
static final int CS_STAT_RACE_WIS
static final int CS_STAT_WEIGHT_LIM
final CommandQueue commandQueue
abstract void writeToScript(@NotNull final String data)
void removeCrossfireMapScrollListener(@NotNull final MapScrollListener listener)
static final int CS_STAT_RESIST_START
List< CfItem > getItemsByLocation(final int location)
static final int CS_STAT_APPLIED_STR
static final int CS_STAT_BASE_DEX
static final int CS_STAT_CHA
void sendMove(int to, int tag, int nrof)
void addCrossfireNewmapListener(@NotNull final NewmapListener listener)
static final int CS_STAT_BASE_WIS
static final Pattern PATTERN_ISSUE
boolean equals(@Nullable final Object obj)
void cmdIssue(@NotNull final String params)
static final int CS_STAT_FOOD
final CrossfireServerConnection crossfireServerConnection
void addCrossfireMapScrollListener(@NotNull final MapScrollListener listener)
static final int CS_STAT_APPLIED_DEX
void commandSent(@NotNull final String cmd)
static final int CS_STAT_MAXGRACE
static final Face DEFAULT_FACE
void commandSentItem(@NotNull final String cmd, @NotNull final CfItem item)
final SpellsManager spellsManager
static final int CS_STAT_SPELL_DENY
static final int CS_STAT_STR
void cmdRequest(@NotNull final String params)
void sendRawString(@NotNull final String command)
static final int CS_STAT_RACE_INT
static final int CS_STAT_MAXHP
static final int CS_STAT_SPELL_REPEL
void reportError(@NotNull final String string)
void runScriptCommand(@NotNull final String cmdLine)
int getStat(final int statNo)
static final int CS_STAT_APPLIED_CHA
void cmdDraw(@NotNull final String params)
static final int CS_STAT_WC
void addCommand(@NotNull final String command)
final MapUpdaterState mapUpdaterState
static final int CS_STAT_FLAGS
void addScriptProcessListener(@NotNull final ScriptProcessListener scriptProcessListener)
static final int CS_STAT_APPLIED_POW
abstract String readFromScript()
static final int CS_STAT_AC
static final int CS_STAT_RACE_DEX
void drawInfo(@NotNull String message, int color)
static final int CS_STAT_APPLIED_INT
static final int CS_STAT_SPELL_ATTUNE
void cmdIssueLock(@NotNull final String params)
static final int CS_STAT_BASE_CHA
Face getFace(final int layer)
static final int CS_STAT_RESIST_END
final ClientSocketListener clientSocketListener
Skill getSkill(final int id)
void mapScroll(final int dx, final int dy)
static final int CS_STAT_DEX
static final int CS_STAT_CON
final EventListenerList2< ScriptProcessListener > scriptProcessListeners
static final int CS_STAT_BASE_CON
static final int CS_STAT_BASE_STR
CfMapSquare getHeadMapSquare(final int layer)
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)
void cmdIssueApply(@NotNull final String params)
static final int CS_STAT_APPLIED_WIS
static final int CS_STAT_RACE_STR
static final int CS_STAT_HP
void commandSentMap(@NotNull final CfMap map, final int x, final int y)
abstract String waitForTermination()
static final int CS_STAT_DAM
static final int CS_STAT_POW
void sendNcom(final boolean mustSend, @NotNull final String command)
static final int CS_STAT_INT
void cmdIssueMark(@NotNull final String params)
static final int CS_STAT_RACE_CHA
static final int CS_STAT_WIS
final FloorView floorView
static final int CS_STAT_GRACE
static final int CS_STAT_SPEED
final PacketWatcher packetWatcher
void removeCrossfireNewmapListener(@NotNull final NewmapListener listener)
Iterable< CfItem > getPlayerInventory()
static final int CS_STAT_RACE_CON
static final int CS_STAT_BASE_INT
static final int CS_STAT_SP
static final int CS_STAT_RACE_POW
Collection< Spell > getAllSpells()
static final int CS_STAT_APPLIED_CON
static final int CS_STAT_SKILLINFO
static final int CS_STAT_WEAP_SP
static final int CS_STAT_MAXSP