Advertisement
Kreagingmeaar

crossfire_open_chests_sh : Script for Crossfire RPG

Mar 22nd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 62.08 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Who:
  4. # Created by Karl Reimer Godt
  5. # First version 2018-01-06
  6. # Time elapsed for the crossfire client
  7. # while writing the script was 3,5 hours.
  8. # Most time took error fixes after testing the script.
  9. # Bugs are still likely :( !
  10. #
  11. # About:
  12. # Script to open chests in bulk mode
  13. # for the roleplaying game Crossfire.
  14. # Simple script that does not finetune
  15. # trap handling.
  16. # In case of detonating a trap while
  17. # disarming, it does just exit.
  18. #
  19. # Reason:
  20. # I wrote this script because of lazyness,
  21. # since such scripts to open chests already exist
  22. # in my repositories, but I was too lazy to
  23. # search for these similar scripts.
  24. #
  25. # Style:
  26. # This script was written mainly from memory,
  27. # but used the function _check_if_on_cauldron()
  28. # with modifications for _check_if_on_chest()
  29. # from the cf_functions.sh already available.
  30. # Also used the existing functions
  31. # _is, _draw, _debug, _log, _set_global_variables,
  32. # _say_start_msg, _say_end_msg from cf_functions.sh .
  33. # Added __debug() function to cf_functions.sh
  34. # to draw multiple lines given.
  35.  
  36. VERSION=0.0
  37. VERSION=0.1 # added parameter processing
  38. # added help and version message
  39. # added script run time message
  40. # reordered some code lines
  41. # early exit if rare ball lightning
  42. # do not break for 'You search the area' message,
  43. #  since that seems to not be in sync with other messages
  44. VERSION=0.2 # code reorderings, smaller bugfixes
  45. VERSION=0.3 # instead using _debug now using a MSGLEVEL
  46. # using PL_SPEED variable before dropping chests and after
  47. #  dropping chests and using a middle value of both
  48. VERSION=0.4 # code cleanup 2018-01-08
  49.  
  50. VERSION=1.0 # added options to choose between
  51. # use_skill, cast and invoke to disarm traps
  52. VERSION=1.1 # added NUMBER option
  53. # Recognize *help and *version options
  54. VERSION=1.2 # if no DIRECTION then default to invoke
  55. # if cast was given
  56. VERSION=1.3 # handle chest as permanent container: exit.
  57. # handle portal of elementals: exit.
  58. VERSION=1.3.1 # count opened chests
  59. VERSION=2.0 # use sourced functions files
  60. VERSION=2.1 # implement -M option
  61. VERSION=2.1.1 # bugfixes
  62. VERSION=2.2 # more alternative functions
  63. VERSION=2.2.1 # bugfixes
  64. VERSION=3.0 # made the whole script standalone possible
  65. # functions got *_stdalone post-syllable
  66. VERSION=3.1 # code cleanup
  67. VERSION=3.1.1 # false variable names fixed
  68. VERSION=3.2 # fix missings and end msg when using funcs libraries files
  69. VERSION=3.3 # exit early if already running or no DRAWINFO
  70. VERSION=3.4 # bugfixing
  71. VERSION=3.5 # Use standard sound directories
  72.  
  73. SEARCH_ATTEMPTS_DEFAULT=9
  74. #DISARM variable set to skill, invokation OR cast
  75. DISARM=skill
  76. PICKUP_ALL_MODE=5  # set pickup 4 or 5
  77.  
  78. # Log file path in /tmp
  79. MY_SELF=`realpath "$0"` ## needs to be in main script
  80. MY_BASE=${MY_SELF##*/}  ## needs to be in main script
  81. MY_DIR=${MY_SELF%/*}
  82.  
  83. #DEBUG=1
  84. #LOGGING=1
  85. MSGLEVEL=6 # Message Levels 1-7 to print to the msg pane
  86.  
  87. _say_help_stdalone(){
  88. _draw_stdalone 6  "$MY_BASE"
  89. _draw_stdalone 7  "Script to search for traps,"
  90. _draw_stdalone 7  "disarming them,"
  91. _draw_stdalone 7  "and open chest(s)."
  92. _draw_stdalone 2  "To be used in the crossfire roleplaying game client."
  93. _draw_stdalone 6  "Syntax:"
  94. _draw_stdalone 7  "$0 <<NUMBER>> <<Options>>"
  95. _draw_stdalone 8  "Options:"
  96. _draw_stdalone 10 "Simple number as first parameter:Just open NUMBER chests."
  97. _draw_stdalone 10 "-C # :like above, just open NUMBER chests."
  98. _draw_stdalone 9  "-S # :Number of search attempts, default $SEARCH_ATTEMPTS_DEFAULT"
  99. _draw_stdalone 10 "-M   :Do not break search when found first trap,"
  100. _draw_stdalone 10 "      usefull if chests have more than one trap."
  101. _draw_stdalone 11 "-V   :Print version information."
  102. _draw_stdalone 12 "-c   :cast spell disarm"
  103. _draw_stdalone 12 "-i   :invoke spell disarm"
  104. _draw_stdalone 12 "-u   :use_skill disarm"
  105. _draw_stdalone 10 "-d   :Print debugging to msgpane."
  106. _draw_stdalone 10 "-L   :Turn on logging."
  107. exit ${1:-2}
  108. }
  109.  
  110. _say_help(){
  111. _draw 6  "$MY_BASE"
  112. _draw 7  "Script to search for traps,"
  113. _draw 7  "disarming them,"
  114. _draw 7  "and open chest(s)."
  115. _draw 2  "To be used in the crossfire roleplaying game client."
  116. _draw 6  "Syntax:"
  117. _draw 7  "$0 <<NUMBER>> <<Options>>"
  118. _draw 8  "Options:"
  119. _draw 10 "Simple number as first parameter:Just open NUMBER chests."
  120. _draw 10 "-C # :like above, just open NUMBER chests."
  121. _draw 9  "-S # :Number of search attempts, default $SEARCH_ATTEMPTS_DEFAULT"
  122. _draw 10 "-M   :Do not break search when found first trap,"
  123. _draw 10 "      usefull if chests have more than one trap."
  124. _draw 11 "-V   :Print version information."
  125. _draw 12 "-c   :cast spell disarm"
  126. _draw 12 "-i   :invoke spell disarm"
  127. _draw 12 "-u   :use_skill disarm"
  128. _draw 10 "-d   :Print debugging to msgpane."
  129. _draw 10 "-L   :Turn on logging."
  130. exit ${1:-2}
  131. }
  132.  
  133. _say_version_stdalone(){
  134. _draw_stdalone 6 "$MY_BASE Version:$VERSION"
  135. exit ${1:-2}
  136. }
  137.  
  138. _set_global_variables_stdalone(){
  139. LOGGING=${LOGGING:-''}  #bool, set to ANYTHING ie "1" to enable, empty to disable
  140. #DEBUG=${DEBUG:-''}      #bool, set to ANYTHING ie "1" to enable, empty to disable
  141. MSGLEVEL=${MSGLEVEL:-6} #integer 1 emergency - 7 debug
  142. #case $MSGLEVEL in
  143. #7) DEBUG=${DEBUG:-1};; 6) INFO=${INFO:-1};; 5) NOTICE=${NOTICE:-1};; 4) WARN=${WARN:-1};;
  144. #3) ERROR=${ERROR:-1};; 2) ALERT=${ALERT:-1};; 1) EMERG=${EMERG:-1};;
  145. #esac
  146. DEBUG=1; INFO=1; NOTICE=1; WARN=1; ERROR=1; ALERT=1; EMERG=1; Q=-q; VERB=-v
  147. case $MSGLEVEL in
  148. 7) unset Q;; 6) unset DEBUG Q;; 5) unset DEBUG INFO VERB;; 4) unset DEBUG INFO NOTICE VERB;;
  149. 3) unset DEBUG INFO NOTICE WARN VERB;; 2) unset DEBUG INFO NOTICE WARN ERROR VERB;;
  150. 1) unset DEBUG INFO NOTICE WARN ERROR ALERT VERB;;
  151. *) _error_stdalone "MSGLEVEL variable not set from 1 - 7";;
  152. esac
  153.  
  154. TMOUT=${TMOUT:-1}      # read -t timeout, integer, seconds
  155. SLEEP=${SLEEP:-1}      #default sleep value, float, seconds, refined in _get_player_speed()
  156. DELAY_DRAWINFO=${DELAY_DRAWINFO:-2}  #default pause to sync, float, seconds, refined in _get_player_speed()
  157.  
  158. DRAWINFO=${DRAWINFO:-drawinfo} #older clients <= 1.12.0 use drawextinfo , newer clients drawinfo
  159. FUNCTION_CHECK_FOR_SPACE=_check_for_space_stdalone # request map pos works
  160. case $* in
  161. *-version" "*) CLIENT_VERSION="$2"
  162. case $CLIENT_VERSION in 0.*|1.[0-9].*|1.1[0-2].*)
  163. DRAWINFO=drawextinfo #older clients <= 1.12.0 use drawextinfo , newer clients drawinfo
  164.                      #     except use_skill alchemy :watch drawinfo 0 The cauldron emits sparks.
  165.                      # and except apply             :watch drawinfo 0 You open cauldron.
  166.                      #
  167.                      # and probably more ...? TODO!
  168. FUNCTION_CHECK_FOR_SPACE=_check_for_space_old_client_stdalone # needs request map near
  169. ;;
  170. esac
  171. ;;
  172. esac
  173.  
  174. COUNT_CHECK_FOOD=${COUNT_CHECK_FOOD:-10} # number between attempts to check foodlevel.
  175.                     #  1 would mean check every single time, which is too much
  176. EAT_FOOD=${EAT_FOOD:-waybread}   # set to desired food to eat ie food, mushroom, booze, .. etc.
  177. FOOD_DEF=haggis     # default
  178. MIN_FOOD_LEVEL_DEF=${MIN_FOOD_LEVEL_DEF:-300} # default minimum. 200 starts to beep.
  179.                        # waybread has foodvalue of 500
  180.                        # 999 is max foodlevel
  181.  
  182. HP_MIN_DEF=${HP_MIN_DEF:-20}          # minimum HP to return home. Lowlevel charakters probably need this set.
  183.  
  184. DIRB=${DIRB:-west}  # direction back to go
  185. case $DIRB in
  186. west)      DIRF=east;;
  187. east)      DIRF=west;;
  188. north)     DIRF=south;;
  189. northwest) DIRF=southeast;;
  190. northeast) DIRF=southwest;;
  191. south)     DIRF=north;;
  192. southwest) DIRF=northeast;;
  193. southeast) DIRF=northwest;;
  194. esac
  195.  
  196. # *** Color numbers found in common/shared/newclient.h : *** #
  197. NDI_BLACK=0
  198. NDI_WHITE=1
  199. NDI_NAVY=2
  200. NDI_RED=3
  201. NDI_ORANGE=4
  202. NDI_BLUE=5       #/**< Actually, it is Dodger Blue */
  203. NDI_DK_ORANGE=6  #/**< DarkOrange2 */
  204. NDI_GREEN=7      #/**< SeaGreen */
  205. NDI_LT_GREEN=8   #/**< DarkSeaGreen, which is actually paler
  206. #                  *   than seagreen - also background color. */
  207. NDI_GREY=9
  208. NDI_BROWN=10     #/**< Sienna. */
  209. NDI_GOLD=11
  210. NDI_TAN=12       #/**< Khaki. */
  211. #define NDI_MAX_COLOR   12      /**< Last value in. */
  212.  
  213. CF_DATADIR=/usr/local/share/crossfire-client
  214. SOUND_DIR="$HOME"/.crossfire/cf_sounds
  215. USER_SOUNDS_PATH="$HOME"/.crossfire/sound.cache
  216. CF_SOUND_DIR="$CF_DATADIR"/sounds
  217.  
  218. # Log file path in /tmp
  219. #MY_SELF=`realpath "$0"` ## needs to be in main script
  220. #MY_BASE=${MY_SELF##*/}  ## needs to be in main script
  221. TMP_DIR=/tmp/crossfire_client
  222. mkdir -p "$TMP_DIR"
  223.     LOGFILE=${LOGFILE:-"$TMP_DIR"/"$MY_BASE".$$.log}
  224.   REPLY_LOG="$TMP_DIR"/"$MY_BASE".$$.rpl
  225. REQUEST_LOG="$TMP_DIR"/"$MY_BASE".$$.req
  226.      ON_LOG="$TMP_DIR"/"$MY_BASE".$$.ion
  227.     INV_LOG="$TMP_DIR"/"$MY_BASE".$$.inv
  228.   ERROR_LOG="$TMP_DIR"/"$MY_BASE".$$.err
  229. exec 2>>"$ERROR_LOG"
  230. }
  231.  
  232. # *** EXIT FUNCTIONS *** #
  233. _exit_stdalone(){
  234. case $1 in
  235. [0-9]|[0-9][0-9]|[0-9][0-9][0-9]) RV=$1; shift;;
  236. esac
  237.  
  238. _is_stdalone 1 1 fire_stop
  239. _move_back_and_forth_stdalone 2
  240. _sleep_stdalone
  241.  
  242. test "$*" && _draw_stdalone 3 $@
  243. _draw_stdalone 3 "Exiting $0. PID was $$"
  244. _unwatch_stdalone ""
  245. _beep_std_stdalone
  246. test ${RV//[0-9]/} && RV=3
  247. exit ${RV:-0}
  248. }
  249.  
  250. _just_exit_stdalone(){
  251. _draw_stdalone 3 "Exiting $0."
  252. _is_stdalone 1 1 fire_stop
  253. _unwatch_stdalone
  254. _beep_std_stdalone
  255. exit ${1:-0}
  256. }
  257.  
  258. _emergency_exit_stdalone(){
  259. RV=${1:-4}; shift
  260. local lRETURN_ITEM=${*:-"$RETURN_ITEM"}
  261.  
  262. _is_stdalone 1 1 fire_stop
  263.  
  264. case $lRETURN_ITEM in
  265. ''|*rod*|*staff*|*wand*|*horn*)
  266. _is_stdalone 1 1 apply -u ${lRETURN_ITEM:-'rod of word of recall'}
  267. _is_stdalone 1 1 apply -a ${lRETURN_ITEM:-'rod of word of recall'}
  268. _is_stdalone 1 1 fire center
  269. _is_stdalone 1 1 fire_stop
  270. ;;
  271. *scroll*) _is_stdalone 1 1 apply ${lRETURN_ITEM};;
  272. *) _is_stdalone 1 1 invoke "$lRETURN_ITEM";; # assuming spell
  273. esac
  274.  
  275. _draw_stdalone 3 "Emergency Exit $0 !"
  276. _unwatch_stdalone
  277.  
  278. # apply bed of reality
  279.  sleep 6
  280. _is_stdalone 1 1 apply
  281.  
  282. _beep_std_stdalone
  283. exit ${RV:-0}
  284. }
  285.  
  286. _exit_no_space_stdalone(){
  287. _draw_stdalone 3 "On position $nr $DIRB there is something ($IS_WALL)!"
  288. _draw_stdalone 3 "Remove that item and try again."
  289. _draw_stdalone 3 "If this is a wall, try on another place."
  290. _beep_std_stdalone
  291. exit ${1:-0}
  292. }
  293.  
  294. _draw_stdalone(){
  295.     local lCOLOUR="${1:-$COLOUR}"
  296.     lCOLOUR=${lCOLOUR:-1} #set default
  297.     shift
  298.     echo draw $lCOLOUR $@ # no double quotes here,
  299. # multiple lines are drawn using __draw below
  300. }
  301.  
  302. __draw_stdalone(){
  303. case $1 in [0-9]|1[0-2])
  304.     lCOLOUR="$1"; shift;; esac
  305.     local lCOLOUR=${lCOLOUR:-1} #set default
  306. dcnt=0
  307. echo -e "$*" | while read line
  308. do
  309. dcnt=$((dcnt+1))
  310.     echo draw $lCOLOUR "$line"
  311. done
  312. unset dcnt line
  313. }
  314.  
  315. _debug_stdalone(){
  316. test "$DEBUG" || return 0
  317.     echo draw 10 "DEBUG:"$@
  318. }
  319.  
  320. __debug_stdalone(){  ##+++2018-01-06
  321. test "$DEBUG" || return 0
  322. cnt=0
  323. echo "$*" | while read line
  324. do
  325. cnt=$((cnt+1))
  326.     echo draw 3 "__DEBUG:$cnt:$line"
  327. done
  328. unset cnt line
  329. }
  330.  
  331. __msg_stdalone(){  ##+++2018-01-08
  332. local LVL=$1; shift
  333. case $LVL in
  334. 7|debug) test "$DEBUG"  && _debug_stdalone  "$*";;
  335. 6|info)  test "$INFO"   && _info_stdalone   "$*";;
  336. 5|note)  test "$NOTICE" && _notice_stdalone "$*";;
  337. 4|warn)  test "$WARN"   && _warn_stdalone   "$*";;
  338. 3|err)   test "$ERROR"  && _error_stdalone  "$*";;
  339. 2|alert) test "$ALERT"  && _alert_stdalone  "$*";;
  340. 1|emerg) test "$EMERG"  && _emerg_stdalone  "$*";;
  341. *) _debug_stdalone "$*";;
  342. esac
  343. }
  344.  
  345. _msg_stdalone(){  ##+++2018-01-08
  346. local LVL=$1; shift
  347. case $LVL in
  348. 7|debug) _debug_stdalone  "$*";;
  349. 6|info)  _info_stdalone   "$*";;
  350. 5|note)  _notice_stdalone "$*";;
  351. 4|warn)  _warn_stdalone   "$*";;
  352. 3|err)   _error_stdalone  "$*";;
  353. 2|alert) _alert_stdalone  "$*";;
  354. 1|emerg) _emerg_stdalone  "$*";;
  355. *) _debug_stdalone "$*";;
  356. esac
  357. }
  358.  
  359. _info_stdalone(){
  360. test "$INFO" || return 0
  361.     echo draw 7 "INFO:"$@
  362. }
  363.  
  364. _notice_stdalone(){
  365. test "$NOTICE" || return 0
  366.     echo draw 2 "NOTICE:"$@
  367. }
  368.  
  369. _warn_stdalone(){
  370. test "$WARN" || return 0
  371.     echo draw 6 "WARNING:"$@
  372. }
  373.  
  374. _error_stdalone(){
  375. test "$ERROR" || return 0
  376.     echo draw 4 "ERROR:"$@
  377. }
  378.  
  379. _alert_stdalone(){
  380. test "$ALERT" || return 0
  381.     echo draw 3 "ALERT:"$@
  382. }
  383.  
  384. _ermerg_stdalone(){
  385. test "$EMERG" || return 0
  386.     echo draw 3 "EMERGENCY:"$@
  387. }
  388.  
  389. _log_stdalone(){
  390.     test "$LOGGING" || return 0
  391.     local lFILE
  392.     test "$2" && {
  393.     lFILE="$1"; shift; } || lFILE="$LOGFILE"
  394.    echo "$*" >>"$lFILE"
  395. }
  396.  
  397. _set_sound_stdalone(){
  398. if test -e "$SOUND_DIR"/${1}.raw; then
  399.  alias _sound_stdalone=_sound_stdalone
  400. else
  401.  alias _sound_stdalone=_beep_std_stdalone
  402. fi
  403. }
  404.  
  405. _sound_or_beep_stdalone(){
  406.     local lDUR
  407. test "$2" && { lDUR="$1"; shift; }
  408. lDUR=${lDUR:-0}
  409. #test -e "$SOUND_DIR"/${1}.raw && \
  410. #           aplay $Q $VERB -d $lDUR "$SOUND_DIR"/${1}.raw
  411.  
  412. if test "$APLAY_ERR"; then
  413.  _beep_std_stdalone
  414. elif test -e "$SOUND_DIR"/${1}.raw; then
  415.  aplay $Q $VERB -d $lDUR "$SOUND_DIR"/${1}.raw || APLAY_ERR=$?
  416.  test "$APLAY_ERR" && _beep_std_stdalone
  417. else
  418.  _beep_std_stdalone
  419. fi
  420. }
  421.  
  422. _sound_stdalone(){
  423.     local lDUR
  424. test "$2" && { lDUR="$1"; shift; }
  425. lDUR=${lDUR:-0}
  426. #test -e "$SOUND_DIR"/${1}.raw && \
  427. #           aplay $Q $VERB -d $lDUR "$SOUND_DIR"/${1}.raw
  428. if   test -e                 "$SOUND_DIR"/${1}.raw; then
  429.      aplay $Q $VERB -d $lDUR "$SOUND_DIR"/${1}.raw
  430. elif test -e                 "$USER_SOUNDS_PATH"/${1}.raw; then
  431.      aplay $Q $VERB -d $lDUR "$USER_SOUNDS_PATH"/${1}.raw
  432. elif test -e                 "$CF_SOUND_DIR"/${1}.raw; then
  433.      aplay $Q $VERB -d $lDUR "$CF_SOUND_DIR"/${1}.raw
  434. fi
  435. }
  436.  
  437. _fanfare_stdalone(){
  438.  _sound_stdalone 0 su-fanf
  439. }
  440.  
  441. _beep_std_stdalone(){
  442. beep -l 1000 -f 700
  443. }
  444.  
  445. # ** In case of an early break out of a read loop
  446. # **  and not setting unwatch, the pipeline of fd/0
  447. # **  may still contain (masses!) of lines from the previous
  448. # **  watch, thus making it hard for the next reads of fd/0
  449. # **  to catch the correct line(s) -- especially for request
  450. # ** This function just reads the input-fd ** #
  451. _empty_message_stream_stdalone(){
  452. local lREPLY
  453. while :;
  454. do
  455. read -t $TMOUT lREPLY
  456. _log_stdalone "$REPLY_LOG" "_empty_message_stream_stdalone:$lREPLY"
  457. test "$lREPLY" || break
  458. case $lREPLY in
  459. *scripttell*break*)     break ${lREPLY##*?break};;
  460. *scripttell*exit*)      _exit_stdalone 1 $lREPLY;;
  461. *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  462. esac
  463. _msg_stdalone 7 "_empty_message_stream_stdalone:$lREPLY"
  464. unset lREPLY
  465.  sleep 0.01
  466. done
  467. }
  468.  
  469. _watch_stdalone(){
  470. echo unwatch ${*:-$DRAWINFO}
  471. sleep 0.4
  472. echo   watch ${*:-$DRAWINFO}
  473. }
  474.  
  475. _unwatch_stdalone(){
  476. echo unwatch ${*:-$DRAWINFO}
  477. }
  478.  
  479. _is_stdalone(){
  480. # issue <repeat> <must_send> <command> - send
  481. #  <command> to server on behalf of client.
  482. #  <repeat> is the number of times to execute command
  483. #  <must_send> tells whether or not the command must sent at all cost (1 or 0).
  484. #  <repeat> and <must_send> are optional parameters.
  485.     _msg_stdalone 7 "issue $*"
  486.     echo issue "$@"
  487.     sleep 0.2
  488. }
  489.  
  490. __is_stdalone(){
  491. _msg_stdalone 7 "$*"
  492. Z1=$1; shift
  493. Z2=$1; shift
  494. _msg_stdalone 7 "$*"
  495. echo issue $Z1 $Z2 $*
  496. unset Z1 Z2
  497. sleep 0.2
  498. }
  499.  
  500. _drop_chest_stdalone(){
  501. local lITEM="$*"
  502. _is_stdalone 0 0 drop ${lITEM:-chest}
  503. sleep 3
  504. }
  505.  
  506. _drop_stdalone(){
  507.  _sound_stdalone 0 drip &
  508.  #_is_stdalone 1 1 drop "$@" #01:58 There are only 1 chests.
  509.   _is_stdalone 0 0 drop "$@"
  510. }
  511.  
  512. _set_pickup_stdalone(){
  513. # Usage: pickup <0-7> or <value_density> .
  514. # pickup 0:Don't pick up.
  515. # pickup 1:Pick up one item.
  516. # pickup 2:Pick up one item and stop.
  517. # pickup 3:Stop before picking up.
  518. # pickup 4:Pick up all items.
  519. # pickup 5:Pick up all items and stop.
  520. # pickup 6:Pick up all magic items.
  521. # pickup 7:Pick up all coins and gems
  522. #
  523. #TODO: In pickup 4 and 5 mode
  524. # seems to pick up only
  525. # one piece of the topmost item, if more than one
  526. # piece of the item, as 4 coins or 23 arrows
  527. # but all items below the topmost item get
  528. # picked up wholly
  529. # in _open_chests() ..?
  530. #_is_stdalone 0 0 pickup ${*:-0}
  531. #_is_stdalone 1 0 pickup ${*:-0}
  532. #_is_stdalone 0 1 pickup ${*:-0}
  533.  _is_stdalone 1 1 pickup ${*:-0}
  534. }
  535.  
  536. _move_back_stdalone(){  ##+++2018-01-08
  537. test "$DIRB" || return 0
  538. for i in `seq 1 1 ${1:-1}`
  539. do
  540. _is_stdalone 1 1 $DIRB
  541. _sleep_stdalone
  542. done
  543. }
  544.  
  545. _move_forth_stdalone(){  ##+++2018-01-08
  546. test "$DIRF" || return 0
  547. for i in `seq 1 1 ${1:-1}`
  548. do
  549. _is_stdalone 1 1 $DIRF
  550. _sleep_stdalone
  551. done
  552. }
  553.  
  554. _move_back_and_forth_stdalone(){  ##+++2018-01-08
  555. STEPS=${1:-1}
  556.  
  557. #test "$DIRB" -a "$DIRF" || return 0
  558. test "$DIRB" || return 0
  559. for i in `seq 1 1 $STEPS`
  560. do
  561. _is_stdalone 1 1 $DIRB
  562. _sleep_stdalone
  563. done
  564.  
  565. if test "$2"; then shift
  566.  while test "$1";
  567.  do
  568.  COMMANDS=`echo "$1" | tr ';' '\n'`
  569.  test "$COMMANDS" || break 1
  570.   echo "$COMMANDS" | while read line
  571.   do
  572.   $line
  573.   sleep 0.1
  574.   done
  575.  
  576.  shift
  577.  sleep 0.1
  578.  done
  579. fi
  580.  
  581. test "$DIRF" || return 0
  582. for i in `seq 1 1 $STEPS`
  583. do
  584. _is_stdalone 1 1 $DIRF
  585. _sleep_stdalone
  586. done
  587. }
  588.  
  589. _check_for_space_stdalone(){
  590. # *** Check for [4] empty space to DIRB *** #
  591. _msg_stdalone 7 "_check_for_space_stdalone:$*"
  592.  
  593. local REPLY_MAP OLD_REPLY NUMBERT
  594. test "$1" && NUMBERT="$1"
  595. NUMBERT=${NUMBERT:-4}
  596. test "${NUMBERT//[[:digit:]]/}" && _exit_stdalone 2 "_check_for_space_stdalone: Need a digit. Invalid parameter passed:$*"
  597.  
  598. _draw_stdalone 5 "Checking for space to move..."
  599.  
  600. _empty_message_stream_stdalone
  601. echo request map pos
  602.  
  603. # client v.1.70.0 request map pos 280 231 ##cauldron adventurers guild stoneville
  604. # client v.1.10.0 request map pos 272 225 ##cauldron adventurers guild stoneville
  605.  
  606. while :; do
  607. read -t $TMOUT REPLY_MAP
  608. #echo "request map pos:$REPLY_MAP" >>"$REPLY_LOG"
  609. _log_stdalone "$REPLY_LOG" "_check_for_space_stdalone:request map pos:$REPLY_MAP"
  610. _msg_stdalone 7 "$REPLY_MAP"
  611. test "$REPLY_MAP" || break
  612. test "$REPLY_MAP" = "$OLD_REPLY" && break
  613. OLD_REPLY="$REPLY_MAP"
  614. sleep 0.1s
  615. done
  616.  
  617. PL_POS_X=`echo "$REPLY_MAP" | awk '{print $4}'` #request map pos:request map pos 280 231
  618. PL_POS_Y=`echo "$REPLY_MAP" | awk '{print $5}'`
  619.  
  620. if test "$PL_POS_X" -a "$PL_POS_Y"; then
  621.  
  622. if test ! "${PL_POS_X//[[:digit:]]/}" -a ! "${PL_POS_Y//[[:digit:]]/}"; then
  623.  
  624. for nr in `seq 1 1 $NUMBERT`; do
  625.  
  626. case $DIRB in
  627. west)
  628. R_X=$((PL_POS_X-nr))
  629. R_Y=$PL_POS_Y
  630. ;;
  631. northwest)
  632. R_X=$((PL_POS_X-nr))
  633. R_Y=$((PL_POS_Y-nr))
  634. ;;
  635. east)
  636. R_X=$((PL_POS_X+nr))
  637. R_Y=$PL_POS_Y
  638. ;;
  639. northeast)
  640. R_X=$((PL_POS_X+nr))
  641. R_Y=$((PL_POS_Y-nr))
  642. ;;
  643. north)
  644. R_X=$PL_POS_X
  645. R_Y=$((PL_POS_Y-nr))
  646. ;;
  647. south)
  648. R_X=$PL_POS_X
  649. R_Y=$((PL_POS_Y+nr))
  650. ;;
  651. southwest)
  652. R_X=$((PL_POS_X-nr))
  653. R_Y=$((PL_POS_Y+nr))
  654. ;;
  655. southeast)
  656. R_X=$((PL_POS_X+nr))
  657. R_Y=$((PL_POS_Y+nr))
  658. ;;
  659. esac
  660.  
  661. _empty_message_stream_stdalone
  662. echo request map $R_X $R_Y
  663.  
  664. while :; do
  665. read -t $TMOUT
  666. _log_stdalone "$REPLY_LOG" "_check_for_space_stdalone:request map '$R_X' '$R_Y':$REPLY"
  667. _msg_stdalone 7 "$REPLY"
  668. test "$REPLY" && IS_WALL=`echo "$REPLY" | awk '{print $16}'`
  669.  
  670. _log_stdalone "$REPLY_LOG" "IS_WALL=$IS_WALL"
  671. _msg_stdalone 7 "IS_WALL=$IS_WALL"
  672. test "$IS_WALL" = 0 || _exit_no_space_stdalone 1
  673.  
  674. test "$REPLY" || break
  675. unset REPLY
  676. sleep 0.1s
  677. done
  678.  
  679. done
  680.  
  681.  else
  682.   _exit_stdalone 1 "Received Incorrect X Y parameters from server."
  683.  fi
  684.  
  685. else
  686.  _exit_stdalone 1 "Could not get X and Y position of player."
  687. fi
  688.  
  689. _draw_stdalone 7 "OK."
  690. }
  691.  
  692. _check_for_space_old_client_stdalone(){
  693. # *** Check for 4 empty space to DIRB *** #
  694. _msg_stdalone 7 "_check_for_space_old_client_stdalone:$*"
  695.  
  696. local REPLY_MAP OLD_REPLY NUMBERT cm
  697. test "$1" && NUMBERT="$1"
  698. NUMBERT=${NUMBERT:-4}
  699. test "${NUMBERT//[[:digit:]]/}" && _exit_stdalone 2 "_check_for_space_old_client_stdalone: Need a digit. Invalid parameter passed:$*"
  700.  
  701. _draw_stdalone 5 "Checking for space to move..."
  702.  
  703. _empty_message_stream_stdalone
  704. echo request map near
  705.  
  706. # client v.1.70.0 request map pos:request map pos 280 231 ##cauldron adventurers guild stoneville
  707. # client v.1.10.0                 request map pos 272 225 ##cauldron adventurers guild stoneville
  708. #                request map near:request map     279 231  0 n n n n smooth 30 0 0 heads 4854 825 0 tails 0 0 0
  709. cm=0
  710. while :; do
  711. cm=$((cm+1))
  712. read -t $TMOUT REPLY_MAP
  713. _log_stdalone "$REPLY_LOG" "_check_for_space_old_client_stdalone:request map near:$REPLY_MAP"
  714. _msg_stdalone 7 "$REPLY_MAP"
  715. test "$cm" = 5 && break
  716. test "$REPLY_MAP" || break
  717. test "$REPLY_MAP" = "$OLD_REPLY" && break
  718. OLD_REPLY="$REPLY_MAP"
  719. sleep 0.1s
  720. done
  721.  
  722. _empty_message_stream_stdalone
  723.  
  724. PL_POS_X=`echo "$REPLY_MAP" | awk '{print $3}'` #request map near:request map 278 230  0 n n n n smooth 30 0 0 heads 4854 0 0 tails 0 0 0
  725. PL_POS_Y=`echo "$REPLY_MAP" | awk '{print $4}'`
  726.  
  727. if test "$PL_POS_X" -a "$PL_POS_Y"; then
  728.  
  729. if test ! "${PL_POS_X//[[:digit:]]/}" -a ! "${PL_POS_Y//[[:digit:]]/}"; then
  730.  
  731. for nr in `seq 1 1 $NUMBERT`; do
  732.  
  733. case $DIRB in
  734. west)
  735. R_X=$((PL_POS_X-nr))
  736. R_Y=$PL_POS_Y
  737. ;;
  738. east)
  739. R_X=$((PL_POS_X+nr))
  740. R_Y=$PL_POS_Y
  741. ;;
  742. north)
  743. R_X=$PL_POS_X
  744. R_Y=$((PL_POS_Y-nr))
  745. ;;
  746. northwest)
  747. R_X=$((PL_POS_X-nr))
  748. R_Y=$((PL_POS_Y-nr))
  749. ;;
  750. northeast)
  751. R_X=$((PL_POS_X+nr))
  752. R_Y=$((PL_POS_Y-nr))
  753. ;;
  754. south)
  755. R_X=$PL_POS_X
  756. R_Y=$((PL_POS_Y+nr))
  757. ;;
  758. southwest)
  759. R_X=$((PL_POS_X-nr))
  760. R_Y=$((PL_POS_Y+nr))
  761. ;;
  762. southeast)
  763. R_X=$((PL_POS_X+nr))
  764. R_Y=$((PL_POS_Y+nr))
  765. ;;
  766. esac
  767.  
  768. _empty_message_stream_stdalone
  769. echo request map $R_X $R_Y
  770.  
  771. while :; do
  772. read -t $TMOUT
  773. _log_stdalone "$REPLY_LOG" "_check_for_space_old_client_stdalone:request map '$R_X' '$R_Y':$REPLY"
  774. _msg_stdalone 7 "$REPLY"
  775. test "$REPLY" && IS_WALL=`echo "$REPLY" | awk '{print $16}'`
  776.  
  777. _log_stdalone "$REPLY_LOG" "IS_WALL=$IS_WALL"
  778. _msg_stdalone 7 "IS_WALL=$IS_WALL"
  779. test "$IS_WALL" = 0 || _exit_no_space_stdalone 1
  780.  
  781. test "$REPLY" || break
  782. unset REPLY
  783. sleep 0.1s
  784. done
  785.  
  786. done
  787.  
  788.  else
  789.   _exit_stdalone 1 "Received Incorrect X Y parameters from server."
  790.  fi
  791.  
  792. else
  793.  _exit_stdalone 1 "Could not get X and Y position of player."
  794. fi
  795.  
  796. _draw_stdalone 7 "OK."
  797. }
  798.  
  799. _check_if_on_item_stdalone(){
  800. _msg_stdalone 7 "_check_if_on_item_stdalone:$*"
  801.  
  802. local DO_LOOP TOPMOST lMSG lRV
  803. unset DO_LOOP TOPMOST lMSG lRV
  804.  
  805. while [ "$1" ]; do
  806. case $1 in
  807. -l) DO_LOOP=1;;
  808. -t) TOPMOST=1;;
  809. -lt|-tl) DO_LOOP=1; TOPMOST=1;;
  810. *) break;;
  811. esac
  812. shift
  813. done
  814.  
  815. local lITEM=${*:-"$ITEM"}
  816. test "$lITEM" || return 254
  817.  
  818. _draw_stdalone 5 "Checking if standing on $lITEM ..."
  819. UNDER_ME='';
  820. UNDER_ME_LIST='';
  821.  
  822. _empty_message_stream_stdalone
  823. echo request items on
  824.  
  825. while :; do
  826. read -t $TMOUT UNDER_ME
  827. _log_stdalone "$ON_LOG" "_check_if_on_item_stdalone:$UNDER_ME"
  828. _msg_stdalone 7 "$UNDER_ME"
  829.  
  830. case $UNDER_ME in
  831. '') continue;;
  832. *request*items*on*end*) break 1;;
  833. *scripttell*break*)     break ${REPLY##*?break};;
  834. *scripttell*exit*)      _exit_stdalone 1 $REPLY;;
  835. *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  836. *bed*to*reality*)   _just_exit_stdalone;;
  837. esac
  838.  
  839. UNDER_ME_LIST="$UNDER_ME
  840. $UNDER_ME_LIST"
  841.  
  842. unset UNDER_ME
  843. sleep 0.1s
  844. done
  845.  
  846. UNDER_ME_LIST=`echo "$UNDER_ME_LIST" | sed 's%^$%%'`
  847.  
  848. __debug_stdalone "UNDER_ME_LIST='$UNDER_ME_LIST'"
  849.  
  850. NUMBER_ITEM=`echo "$UNDER_ME_LIST" | grep -iE " $lITEM| ${lITEM}s| ${lITEM}es| ${lITEM// /[s ]+}" | wc -l`
  851.  
  852. unset TOPMOST_MSG
  853. case "$UNDER_ME_LIST" in
  854. *"$lITEM"|*"${lITEM}s"|*"${lITEM}es"|*"${lITEM// /?*}")
  855.  TOPMOST_MSG='some'
  856. ;;
  857. esac
  858. test "$TOPMOST" && { UNDER_ME_LIST=`echo "$UNDER_ME_LIST" | tail -n1`; TOPMOST_MSG=${TOPMOST_MSG:-topmost}; }
  859.  
  860. case "$UNDER_ME_LIST" in
  861. *"$lITEM"|*"${lITEM}s"|*"${lITEM}es"|*"${lITEM// /?*}")
  862.    lRV=0;;
  863. *) lMSG="You appear not to stand on $TOPMOST_MSG $lITEM!"
  864.    lRV=1;;
  865. esac
  866.  
  867. if test $lRV = 0; then
  868.  case "$UNDER_ME_LIST" in
  869.  *cursed*)
  870.    lMSG="You appear to stand upon $TOPMOST_MSG cursed $lITEM!"
  871.    lRV=1;;
  872.  *damned*)
  873.    lMSG="You appear to stand upon $TOPMOST_MSG damned $lITEM!"
  874.    lRV=1;;
  875.  esac
  876. fi
  877.  
  878. test "$lRV" = 0 && return 0
  879.  
  880. _beep_std_stdalone
  881. _draw_stdalone 3 $lMSG
  882. test "$DO_LOOP" && return 1 || _exit_stdalone 1
  883. }
  884.  
  885. _check_if_on_item_examine_stdalone(){
  886. # Using 'examine' directly after dropping
  887. # the item examines the bottommost tile
  888. # as 'That is marble'
  889. _msg_stdalone 7 "_check_if_on_item_examine_stdalone:$*"
  890.  
  891. local DO_LOOP TOPMOST LIST
  892. unset DO_LOOP TOPMOST LIST
  893.  
  894. while [ "$1" ]; do
  895. case $1 in
  896. -l) DO_LOOP=1;;
  897. -t) TOPMOST=1;;
  898. -lt|-tl) DO_LOOP=1; TOPMOST=1;;
  899. *) break;;
  900. esac
  901. shift
  902. done
  903.  
  904. local lITEM=${*:-"$ITEM"}
  905. test "$lITEM" || return 254
  906.  
  907. _draw_stdalone 5 "Checking if standing on $lITEM ..."
  908.  
  909. _watch_stdalone $DRAWINFO
  910. while :; do unset REPLY
  911. _is_stdalone 0 0 examine
  912. _sleep_stdalone
  913. read -t $TMOUT
  914.  _log_stdalone "_check_if_on_item_examine_stdalone:$REPLY"
  915.  _msg_stdalone 7 "$REPLY"
  916.  
  917.  case $REPLY in
  918.   *"That is"*"$lITEM"*|*"Those are"*"$lITEM"*|*"Those are"*"${lITEM// /?*}"*) break 1;;
  919.   *"That is"*|*"Those are"*) break 1;;
  920.   *scripttell*break*)     break ${REPLY##*?break};;
  921.   *scripttell*exit*)    _exit_stdalone 1 $REPLY;;
  922.   *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  923.   '') break 1;;
  924.   *) continue;; #:;;
  925.  esac
  926.  
  927. LIST="$LIST
  928. $REPLY"
  929. sleep 0.01
  930. done
  931.  
  932. _unwatch_stdalone
  933. _empty_message_stream_stdalone
  934.  
  935. LIST=`echo "$LIST" | sed 'sI^$II'`
  936.  
  937. if test "$TOPMOST"; then
  938.  echo "${LIST:-$REPLY}"  | tail -n1 | grep -q -i -E " $lITEM| ${lITEM}s| ${lITEM}es| ${lITEM// /[s ]+}"
  939. else
  940.  echo "$REPLY"                      | grep -q -i -E " $lITEM| ${lITEM}s| ${lITEM}es| ${lITEM// /[s ]+}"
  941. fi
  942. local lRV=$?
  943. test "$lRV" = 0 && return $lRV
  944.  
  945. if test "$DO_LOOP"; then
  946.  return ${lRV:-3}
  947. else
  948.   _exit_stdalone ${lRV:-3} "$lITEM not here or not on top of stack."
  949. fi
  950. }
  951.  
  952. __check_if_on_chest_request_items_on_stdalone(){
  953. _msg_stdalone 7 "__check_if_on_chest_request_items_on_stdalone:$*"
  954.  
  955. #local DO_LOOP TOPMOST
  956. #unset DO_LOOP TOPMOST
  957. #
  958. #while [ "$1" ]; do
  959. #case $1 in
  960. #-l) DO_LOOP=1;;
  961. #-t) TOPMOST=1;;
  962. #-lt|-tl) DO_LOOP=1; TOPMOST=1;;
  963. #*) break;;
  964. #esac
  965. #shift
  966. #done
  967.  
  968. #_draw_stdalone 5 "Checking if standing on chests ..."
  969. UNDER_ME='';
  970. UNDER_ME_LIST='';
  971.  
  972. _empty_message_stream_stdalone
  973. echo request items on
  974.  
  975. while :; do
  976. read -t $TMOUT UNDER_ME
  977. _log_stdalone "$ON_LOG" "__check_if_on_chest_request_items_on_stdalone:$UNDER_ME"
  978. _msg_stdalone 7 "$UNDER_ME"
  979.  
  980. case $UNDER_ME in
  981. '') continue;;
  982. *request*items*on*end*) break 1;;
  983. *scripttell*break*)     break ${REPLY##*?break};;
  984. *scripttell*exit*)    _exit_stdalone 1 $REPLY;;
  985. *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  986. *bed*to*reality*)   _just_exit_stdalone;;
  987. *) :;;
  988. esac
  989.  
  990. UNDER_ME_LIST="$UNDER_ME
  991. $UNDER_ME_LIST"
  992.  
  993. unset UNDER_ME
  994. sleep 0.01s
  995. done
  996.  
  997. UNDER_ME_LIST=`echo "$UNDER_ME_LIST" | sed 's%^$%%'`
  998.  
  999. __debug_stdalone "UNDER_ME_LIST='$UNDER_ME_LIST'"
  1000.  
  1001. NUMBER_CHEST=`echo "$UNDER_ME_LIST" | grep 'chest' | wc -l`
  1002.  
  1003. test "`echo "$UNDER_ME_LIST" | grep 'chest.*cursed'`" && {
  1004. _draw_stdalone 3 "You appear to stand upon some cursed chest!"
  1005. _beep_std_stdalone
  1006. test "$1" && return 1 || exit 1
  1007. }
  1008.  
  1009. test "`echo "$UNDER_ME_LIST" | grep -E 'chest$|chests$'`" || {
  1010. _draw_stdalone 3 "You appear not to stand on some chest!"
  1011. _beep_std_stdalone
  1012. test "$1" && return 1 || exit 1
  1013. }
  1014.  
  1015. test "`echo "$UNDER_ME_LIST" | tail -n1 | grep 'chest.*cursed'`" && {
  1016. _draw_stdalone 3 "Topmost chest appears to be cursed!"
  1017. _beep_std_stdalone
  1018. test "$1" && return 1 || exit 1
  1019. }
  1020.  
  1021. test "`echo "$UNDER_ME_LIST" | tail -n1 | grep -E 'chest$|chests$'`" || {
  1022. _draw_stdalone 3 "Chest appears not topmost!"
  1023. _beep_std_stdalone
  1024. test "$1" && return 1 || exit 1
  1025. }
  1026.  
  1027. return 0
  1028. }
  1029.  
  1030. _check_if_on_chest_request_items_on_stdalone(){
  1031. _msg_stdalone 7 "_check_if_on_chest_request_items_on_stdalone:$*"
  1032.  
  1033. local DO_LOOP TOPMOST lRV
  1034. unset DO_LOOP TOPMOST lRV
  1035.  
  1036. while [ "$1" ]; do
  1037. case $1 in
  1038. -l) DO_LOOP=1;;
  1039. -t) TOPMOST=1;;
  1040. -lt|-tl) DO_LOOP=1; TOPMOST=1;;
  1041. *) break;;
  1042. esac
  1043. shift
  1044. done
  1045.  
  1046. #_draw_stdalone 5 "Checking if standing on chests ..."
  1047. UNDER_ME='';
  1048. UNDER_ME_LIST='';
  1049.  
  1050. _empty_message_stream_stdalone
  1051. echo request items on
  1052.  
  1053. while :; do
  1054. read -t $TMOUT UNDER_ME
  1055. _log_stdalone "$ON_LOG" "_check_if_on_chest_request_items_on_stdalone:$UNDER_ME"
  1056. _msg_stdalone 7 "$UNDER_ME"
  1057.  
  1058. case $UNDER_ME in
  1059. '') continue;;
  1060. *request*items*on*end*) break 1;;
  1061. *scripttell*break*)     break ${REPLY##*?break};;
  1062. *scripttell*exit*)      _exit_stdalone 1 $REPLY;;
  1063. *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  1064. esac
  1065.  
  1066. UNDER_ME_LIST="$UNDER_ME
  1067. $UNDER_ME_LIST"
  1068.  
  1069. unset UNDER_ME
  1070. sleep 0.1s
  1071. done
  1072.  
  1073. UNDER_ME_LIST=`echo "$UNDER_ME_LIST" | sed 's%^$%%'`
  1074.  
  1075. __debug_stdalone "UNDER_ME_LIST='$UNDER_ME_LIST'"
  1076.  
  1077. NUMBER_CHEST=`echo "$UNDER_ME_LIST" | grep 'chest' | wc -l`
  1078.  
  1079. test "`echo "$UNDER_ME_LIST" | grep -E 'chest.*cursed|chest.*damned'`" && lRV=5
  1080. test "`echo "$UNDER_ME_LIST" | grep -E 'chest$|chests$'`" || lRV=6
  1081.  
  1082. if test "$TOPMOST"; then
  1083. test "`echo "$UNDER_ME_LIST" | tail -n1 | grep -E 'chest.*cursed|chest.*damned'`" && lRV=7
  1084. test "`echo "$UNDER_ME_LIST" | tail -n1 | grep -E 'chest$|chests$'`" || lRV=${lRV:-8}
  1085. fi
  1086.  
  1087. return ${lRV:-0}
  1088. }
  1089.  
  1090. _eval_check_if_on_chest_request_items_on_stdalone(){
  1091. _msg_stdalone 7 "_eval_check_if_on_chest_request_items_on_stdalone:$*"
  1092.  
  1093.  #__check_if_on_chest_request_items_on_stdalone $1
  1094.    _check_if_on_chest_request_items_on_stdalone $1
  1095.   local lRV=$?
  1096. case $lRV in
  1097. 5) _draw_stdalone 3 "You appear to stand upon some cursed chest!";;
  1098. 6) _draw_stdalone 3 "You appear not to stand on some chest!";;
  1099. 7) _draw_stdalone 3 "Topmost chest appears to be cursed!";;
  1100. 8) _draw_stdalone 3 "Chest appears not topmost!";;
  1101. 0) return 0;;
  1102. *) _warn "_eval_check_if_on_chest_request_items_on_stdalone:Unhandled return value '$lRV'";;
  1103. esac
  1104. _beep_std_stdalone
  1105. case $1 in -l|-lt|-tl) return 1;; *) _just_exit_stdalone 1;; esac
  1106. }
  1107.  
  1108. _check_if_on_chest_stdalone(){  ###+++2018-01-19
  1109. _msg_stdalone 7 "_check_if_on_chest_stdalone:$*"
  1110.  
  1111. #local DO_LOOP TOPMOST
  1112. #unset DO_LOOP TOPMOST
  1113. #
  1114. #while [ "$1" ]; do
  1115. #case $1 in
  1116. #-l) DO_LOOP=1;;
  1117. #-t) TOPMOST=1;;
  1118. #-lt|-tl) DO_LOOP=1; TOPMOST=1;;
  1119. #*) break;;
  1120. #esac
  1121. #shift
  1122. #done
  1123.  
  1124. _draw_stdalone 5 "Checking if standing on chests ..."
  1125.  
  1126. #_check_if_on_item_examine_stdalone $1 chest       && return 0
  1127. #_check_if_on_chest_request_items_on_stdalone $1 && return 0
  1128.  
  1129.   _check_if_on_chest_request_items_on_stdalone $1
  1130.   local lRV=$?
  1131. case $lRV in
  1132. 5) _draw_stdalone 3 "You appear to stand upon some cursed chest!";;
  1133. 6) _draw_stdalone 3 "You appear not to stand on some chest!";;
  1134. 7) _draw_stdalone 3 "Topmost chest appears to be cursed!";;
  1135. 8) _draw_stdalone 3 "Chest appears not topmost!";;
  1136. 0) return 0;;
  1137. *) _warn "_check_if_on_chest_stdalone:Unhandled return value '$lRV'";;
  1138. esac
  1139. _beep_std_stdalone
  1140. case $1 in -l|-lt|-tl) return 1;; *) _just_exit_stdalone 1;; esac
  1141. }
  1142.  
  1143. _check_if_on_chest_stdalone(){
  1144. _msg_stdalone 7 "_check_if_on_chest_stdalone:$*"
  1145.  
  1146. #local DO_LOOP TOPMOST
  1147. #unset DO_LOOP TOPMOST
  1148. #
  1149. #while [ "$1" ]; do
  1150. #case $1 in
  1151. #-l) DO_LOOP=1;;
  1152. #-t) TOPMOST=1;;
  1153. #-lt|-tl) DO_LOOP=1; TOPMOST=1;;
  1154. #*) break;;
  1155. #esac
  1156. #shift
  1157. #done
  1158.  
  1159. _draw_stdalone 5 "Checking if standing on chests ..."
  1160.  
  1161. #_check_if_on_item_examine_stdalone $1 chest
  1162. #_check_if_on_chest_request_items_on_stdalone $1
  1163. _eval_check_if_on_chest_request_items_on_stdalone $1
  1164. }
  1165.  
  1166. _search_traps_stdalone(){
  1167. _msg_stdalone 7 "_search_traps_stdalone:$*"
  1168.  
  1169. cnt=${*:-$SEARCH_ATTEMPTS}
  1170. cnt=${cnt:-$SEARCH_ATTEMPTS_DEFAULT}
  1171. test "$cnt" -gt 0 || return 0
  1172.  
  1173. _draw_stdalone 5 "Searching traps ..."
  1174. TRAPS_ALL_OLD=0
  1175. TRAPS_ALL=$TRAPS_ALL_OLD
  1176.  
  1177. while :
  1178. do
  1179.  
  1180. _draw_stdalone 5 "Searching traps $cnt time(s) ..."
  1181.  
  1182. _watch_stdalone ${DRAWINFO}
  1183. _sleep_stdalone
  1184. _is_stdalone 0 0 search
  1185. _sleep_stdalone
  1186.  
  1187.  unset cnt0 FOUND_TRAP
  1188.  while :
  1189.  do
  1190.  cnt0=$((cnt0+1))
  1191.  unset REPLY
  1192.  read -t $TMOUT
  1193.  _log_stdalone "_search_traps_stdalone:$cnt0:$REPLY"
  1194.  _msg_stdalone 7 "$cnt0:$REPLY"
  1195.  
  1196. #You spot a Rune of Burning Hands!
  1197. #You spot a poison needle!
  1198. #You spot a spikes!
  1199. #You spot a Rune of Shocking!
  1200. #You spot a Rune of Icestorm!
  1201. #You search the area.
  1202. #You spot a Rune of Ball Lightning!
  1203.  case $REPLY in
  1204.  *'You spot a Rune of Ball Lightning!'*) _just_exit_stdalone 0;;
  1205.  *'You spot a Rune of Create Bomb!'*)    _just_exit_stdalone 0;;
  1206.  *' spot '*) FOUND_TRAP=$((FOUND_TRAP+1));;
  1207.  *'You search the area.'*) SEARCH_MSG=$((SEARCH_MSG+1));; # break 1;;
  1208.  *scripttell*break*)   break ${REPLY##*?break};;
  1209.  *scripttell*exit*)    _exit_stdalone 1 $REPLY;;
  1210.  *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  1211.  '') break 1;;
  1212.  *) :;;
  1213.  esac
  1214.  
  1215.  sleep 0.1
  1216.  done
  1217.  
  1218. test "$FOUND_TRAP" && _draw_stdalone 2 "Found $FOUND_TRAP trap(s)."
  1219. TRAPS_ALL=${FOUND_TRAP:-$TRAPS_ALL}
  1220. _msg_stdalone 7 "TRAPS_ALL=$TRAPS_ALL"
  1221. test "$TRAPS_ALL_OLD" -gt $TRAPS_ALL && TRAPS_ALL=$TRAPS_ALL_OLD
  1222. _msg_stdalone 7 "TRAPS_ALL=$TRAPS_ALL"
  1223. TRAPS_ALL_OLD=${TRAPS_ALL:-0}
  1224. _msg_stdalone 7 "FOUND_TRAP=$FOUND_TRAP TRAPS_ALL_OLD=$TRAPS_ALL_OLD"
  1225.  
  1226. _unwatch_stdalone $DRAWINFO
  1227. _sleep_stdalone
  1228.  
  1229. test "$MULTIPLE_TRAPS" || {
  1230.     test "$TRAPS_ALL" -ge 1 && break 1; }
  1231.  
  1232. cnt=$((cnt-1))
  1233. test "$cnt" -gt 0 || break 1
  1234.  
  1235. done
  1236.  
  1237. unset cnt
  1238. }
  1239.  
  1240. _cast_disarm_stdalone(){
  1241. _msg_stdalone 7 "_cast_disarm_stdalone:$*"
  1242.  
  1243. test "$TRAPS_ALL" || return 0
  1244. test "${TRAPS_ALL//[0-9]/}" && return 2
  1245. test "$TRAPS_ALL" -gt 0     || return 0
  1246.  
  1247. TRAPS=$TRAPS_ALL
  1248.  
  1249. while :
  1250. do
  1251. _draw_stdalone 5 "${TRAPS:-0} trap(s) to disarm ..."
  1252.  
  1253. # TODO: checks for enough mana
  1254. _watch_stdalone $DRAWINFO
  1255. _is_stdalone 0 0 cast disarm
  1256. _sleep_stdalone
  1257. _is_stdalone 0 0 fire 0
  1258. _is_stdalone 0 0 fire_stop
  1259. _sleep_stdalone
  1260.  
  1261.  unset REPLY OLD_REPLY cnt0
  1262.  while :
  1263.  do
  1264.  cnt0=$((cnt0+1))
  1265.  read -t $TMOUT
  1266.  _log_stdalone "_cast_disarm:$cnt0:$REPLY"
  1267.  _msg_stdalone 7 "$cnt0:$REPLY"
  1268.  
  1269.  case $REPLY in
  1270.  *'You successfully disarm'*) TRAPS=$((TRAPS-1)); break 1;;
  1271.  *'You fail to disarm'*) break 1;;
  1272.  *"There's nothing there!"*) break 2;;
  1273.  *'Something blocks your spellcasting.') _exit_stdalone 1;;
  1274.  *scripttell*break*)   break 2;;
  1275.  *scripttell*exit*)    _exit_stdalone 1 $REPLY;;
  1276.  *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  1277.  *) :;;
  1278.  esac
  1279.  
  1280.  sleep 0.1
  1281.  done
  1282.  
  1283. _unwatch_stdalone $DRAWINFO
  1284. _sleep_stdalone
  1285.  
  1286. test "$TRAPS" -gt 0 || break 1
  1287. done
  1288.  
  1289. _unwatch_stdalone $DRAWINFO
  1290. }
  1291.  
  1292. _invoke_disarm_stdalone(){ ## invoking does to a direction
  1293. _msg_stdalone 7 "_invoke_disarm_stdalone:$*"
  1294. _log_stdalone   "_invoke_disarm_stdalone:$*"
  1295.  
  1296. test "$TRAPS_ALL" || return 0
  1297. test "${TRAPS_ALL//[0-9]/}" && return 2
  1298. test "$TRAPS_ALL" -gt 0     || return 0
  1299.  
  1300. TRAPS=$TRAPS_ALL
  1301.  
  1302. _move_back_stdalone 2
  1303. _move_forth_stdalone 1
  1304. _sleep_stdalone
  1305.  
  1306. while :
  1307. do
  1308. _draw_stdalone 5 "${TRAPS:-0} trap(s) to disarm ..."
  1309.  
  1310. _watch_stdalone $DRAWINFO
  1311. _is_stdalone 0 0 invoke disarm
  1312. _sleep_stdalone
  1313.  
  1314. #There's nothing there!
  1315. #You fail to disarm the diseased needle.
  1316. #You successfully disarm the diseased needle!
  1317.  unset REPLY OLD_REPLY cnt0
  1318.  while :
  1319.  do
  1320.  cnt0=$((cnt0+1))
  1321.  read -t $TMOUT
  1322.  _log_stdalone "_invoke_disarm_stdalone:$cnt0:$REPLY"
  1323.  _msg_stdalone 7 "$cnt0:$REPLY"
  1324.  
  1325.  case $REPLY in
  1326.  *'You successfully disarm'*) TRAPS=$((TRAPS-1)); break 1;;
  1327.  *'You fail to disarm'*) break 1;;
  1328.  # Here there could be a trap next to the stack of chests ...
  1329.  # so invoking disarm towards the stack of chests would not
  1330.  # work to disarm the traps elsewhere on tiles around
  1331.  *"There's nothing there!"*) break 2;;
  1332.  *'Something blocks your spellcasting.') _exit_stdalone 1;;
  1333.  *scripttell*break*)   break 2;;
  1334.  *scripttell*exit*)    _exit_stdalone 1 $REPLY;;
  1335.  *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  1336.  *) :;;
  1337.  esac
  1338.  done
  1339.  
  1340. _unwatch_stdalone $DRAWINFO
  1341. _sleep_stdalone
  1342.  
  1343. test "$TRAPS" -gt 0 || break 1
  1344. done
  1345.  
  1346. _unwatch_stdalone $DRAWINFO
  1347. _move_forth_stdalone 1
  1348. }
  1349.  
  1350. _use_skill_disarm_stdalone(){
  1351. _msg_stdalone 7 "_use_skill_disarm_stdalone:$*"
  1352.  
  1353. test "$TRAPS_ALL" || return 0
  1354. test "${TRAPS_ALL//[0-9]/}" && return 2
  1355. test "$TRAPS_ALL" -gt 0     || return 0
  1356.  
  1357. TRAPS=$TRAPS_ALL
  1358.  
  1359. while :
  1360. do
  1361. _draw_stdalone 5 "${TRAPS:-0} trap(s) to disarm ..."
  1362.  
  1363. _watch_stdalone $DRAWINFO
  1364. _is_stdalone 0 0 use_skill disarm
  1365. _sleep_stdalone
  1366.  
  1367.  unset REPLY OLD_REPLY cnt0
  1368.  while :
  1369.  do
  1370.  cnt0=$((cnt0+1))
  1371.  read -t $TMOUT
  1372.  _log_stdalone "_use_skill_disarm_stdalone:$cnt0:$REPLY"
  1373.  _msg_stdalone 7 "$cnt0:$REPLY"
  1374.  
  1375. #You fail to disarm the Rune of Burning Hands.
  1376. #In fact, you set it off!
  1377. #You detonate a Rune of Burning Hands!
  1378. #You successfully disarm the spikes!
  1379. #You fail to disarm the Rune of Icestorm.
  1380.  
  1381.  case $REPLY in
  1382.  *'You successfully disarm'*)  TRAPS=$((TRAPS-1));;
  1383.  *'You fail to disarm'*) :;;
  1384.  *'In fact, you set it off!'*) TRAPS=$((TRAPS-1));;
  1385.  *'You detonate'*) _just_exit_stdalone 1;;
  1386.  *'A portal opens up, and screaming hordes pour'*) _just_exit_stdalone 1;;
  1387.  *'through!'*)     _just_exit_stdalone 1;;
  1388.  *"RUN!  The timer's ticking!"*) _just_exit_stdalone 1;;
  1389.  *'You are pricked'*) :;;
  1390.  *'You are stabbed'*) :;;
  1391.  *scripttell*break*)  break ${REPLY##*?break};;
  1392.  *scripttell*exit*)   _exit_stdalone 1 $REPLY;;
  1393.  *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  1394.  '') break 1;;
  1395.  *) :;;
  1396.  esac
  1397.  
  1398.  _sleep_stdalone
  1399.  test "$OLD_REPLY" = "$REPLY" && break 1
  1400.  OLD_REPLY=$REPLY
  1401.  done
  1402.  
  1403. _move_back_and_forth_stdalone 2
  1404.  
  1405. _unwatch_stdalone $DRAWINFO
  1406. _sleep_stdalone
  1407.  
  1408. test "$TRAPS" -gt 0 || break 1
  1409. done
  1410.  
  1411. unset OLD_REPLY
  1412. }
  1413.  
  1414. _disarm_traps_stdalone(){
  1415. _msg_stdalone 7 "_disarm_traps_stdalone:$*"
  1416. _draw_stdalone 5 "Disarming ${TRAPS_ALL:-0} traps ..."
  1417. case "$DISARM" in
  1418. invokation) _invoke_disarm_stdalone;;
  1419. cast|spell) #case "$DIRECTION" in '') _invoke_disarm_stdalone;; *) _cast_disarm_stdalone;; esac;;
  1420.             _cast_disarm_stdalone;;
  1421. skill|'') _use_skill_disarm_stdalone;;
  1422. *) _error "DISARM variable set not to skill, invokation OR cast'";;
  1423. esac
  1424. }
  1425.  
  1426. _open_chests_stdalone(){
  1427. _msg_stdalone 7 "_open_chests_stdalone:$*"
  1428.  
  1429. _draw_stdalone 5 "Opening chests ..."
  1430.  
  1431. unset one
  1432. while :
  1433. do
  1434. one=$((one+1))
  1435.  
  1436. _drop_stdalone chest
  1437. _sleep_stdalone
  1438. _move_back_and_forth_stdalone 2
  1439.  
  1440. _check_if_on_chest_stdalone -lt || break 1
  1441. _sleep_stdalone
  1442.  
  1443. _draw_stdalone 5 "${NUMBER_CHEST:-?} chest(s) to open ..."
  1444.  
  1445. _watch_stdalone
  1446. _is_stdalone 1 1 apply
  1447.  
  1448.  unset OPEN_COUNT
  1449.  while :; do unset REPLY
  1450.  read -t ${TMOUT:-1}
  1451.  _log_stdalone "_open_chests_stdalone:$REPLY"
  1452.  _msg_stdalone 7 "$REPLY"
  1453.  case $REPLY in
  1454.  *'You find'*)   OPEN_COUNT=1;;
  1455.  *empty*)        OPEN_COUNT=1;;
  1456.  *'You open chest.'*) break 2;; # permanent container
  1457.  *scripttell*break*)  break ${REPLY##*?break};;
  1458.  *scripttell*exit*)   _exit_stdalone 1 $REPLY;;
  1459.  *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  1460.  '') break 1;;
  1461.  esac
  1462.  sleep 0.01
  1463.  done
  1464. _unwatch_stdalone
  1465. test "$OPEN_COUNT" && CHEST_COUNT=$((CHEST_COUNT+1))
  1466. # TODO : You find*Rune of*
  1467. #You find Blades trap in the chest.
  1468. #You set off a Blades trap!
  1469. #You find silver coins in the chest.
  1470. #You find booze in the chest.
  1471. #You find Rune of Shocking in the chest.
  1472. #You detonate a Rune of Shocking
  1473. #The chest was empty.
  1474. #11:50 You open chest.
  1475. #11:50 You close chest (open) (active).
  1476.  
  1477. _move_back_and_forth_stdalone 2 "_set_pickup_stdalone ${PICKUP_ALL_MODE:-4};_sleep_stdalone;"
  1478.  
  1479. if _check_counter_stdalone; then
  1480. _check_food_level_stdalone
  1481. _check_hp_and_return_home_stdalone $HP
  1482. fi
  1483.  
  1484. _is_stdalone 0 0 get all
  1485.  
  1486. _set_pickup_stdalone 0
  1487. _sleep_stdalone
  1488.  
  1489. case $NUMBER in $one) break 1;; esac
  1490.  
  1491. done
  1492. }
  1493.  
  1494. #** we may get attacked and die **#
  1495. _check_hp_and_return_home_stdalone(){
  1496. _msg_stdalone 7 "_check_hp_and_return_home_stdalone:$*"
  1497.  
  1498. local currHP currHPMin
  1499. currHP=${1:-$HP}
  1500. currHPMin=${2:-$HP_MIN_DEF}
  1501. currHPMin=${currHPMin:-$((MHP/10))}
  1502.  
  1503. _msg_stdalone 7 "currHP=$currHP currHPMin=$currHPMin"
  1504. if test "$currHP" -le ${currHPMin:-20}; then
  1505.  
  1506.  __old_recall(){
  1507.  _empty_message_stream_stdalone
  1508.  _is_stdalone 1 1 apply -u ${RETURN_ITEM:-'rod of word of recall'}
  1509.  _is_stdalone 1 1 apply -a ${RETURN_ITEM:-'rod of word of recall'}
  1510.  _empty_message_stream_stdalone
  1511.  
  1512.  _is_stdalone 1 1 fire center ## TODO: check if already applied and in inventory
  1513.  _is_stdalone 1 1 fire_stop
  1514.  
  1515.  _empty_message_stream_stdalone
  1516.  _unwatch_stdalone $DRAWINFO
  1517.  exit 5
  1518.  }
  1519.  
  1520. _emergency_exit_stdalone
  1521. fi
  1522.  
  1523. unset HP
  1524. }
  1525.  
  1526. _check_food_level_stdalone(){
  1527. _msg_stdalone 7 "_check_food_level_stdalone:$*"
  1528.  
  1529. test "$*" && MIN_FOOD_LEVEL="$@"
  1530. MIN_FOOD_LEVEL=${MIN_FOOD_LEVEL:-$MIN_FOOD_LEVEL_DEF}
  1531. MIN_FOOD_LEVEL=${MIN_FOOD_LEVEL:-300}
  1532.  
  1533. local FOOD_LVL=''
  1534. local REPLY
  1535.  
  1536. _empty_message_stream_stdalone
  1537. _sleep_stdalone
  1538.  
  1539. echo request stat hp   #hp,maxhp,sp,maxsp,grace,maxgrace,food
  1540. while :;
  1541. do
  1542. unset HP MHP SP MSP GR MGR FOOD_LVL
  1543. read -t ${TMOUT:-1} Re Stat Hp HP MHP SP MSP GR MGR FOOD_LVL
  1544.    _log_stdalone "HP=$HP $MHP $SP $MSP $GR $MGR FOOD_LVL=$FOOD_LVL"
  1545.  _msg_stdalone 7 "HP=$HP $MHP $SP $MSP $GR $MGR FOOD_LVL=$FOOD_LVL" #DEBUG
  1546.  
  1547. test "$Re" = request || continue
  1548. test "$FOOD_LVL" || break
  1549. test "${FOOD_LVL//[[:digit:]]/}" && break
  1550.  
  1551. if test "$FOOD_LVL" -lt $MIN_FOOD_LEVEL; then
  1552.  #_eat_food_from_inventory
  1553.  _cast_create_food_and_eat_stdalone $EAT_FOOD || _eat_food_from_inventory_stdalone $EAT_FOOD
  1554.  
  1555.  _sleep_stdalone
  1556.  _empty_message_stream_stdalone
  1557.  _sleep_stdalone
  1558.  echo request stat hp   #hp,maxhp,sp,maxsp,grace,maxgrace,food
  1559.  _sleep_stdalone
  1560.  read -t ${TMOUT:-1} Re2 Stat2 Hp2 HP2 MHP2 SP2 MSP2 GR2 MGR2 FOOD_LVL
  1561.    _log_stdalone "HP=$HP2 $MHP2 $SP2 $MSP2 $GR2 $MGR2 FOOD_LVL=$FOOD_LVL"
  1562.  _msg_stdalone 7 "HP=$HP2 $MHP2 $SP2 $MSP2 $GR2 $MGR2 FOOD_LVL=$FOOD_LVL" #DEBUG
  1563.  break
  1564. fi
  1565.  
  1566. test "${FOOD_LVL//[[:digit:]]/}" || break
  1567. test "$FOOD_LVL" && break
  1568. test "$oF" = "$FOOD_LVL" && break
  1569.  
  1570. oF="$FOOD_LVL"
  1571. sleep 0.1
  1572. done
  1573. }
  1574.  
  1575. _check_mana_for_create_food_stdalone(){
  1576. _msg_stdalone 7 "_check_mana_for_create_food_stdalone:$*"
  1577.  
  1578. local lSP=${*:-$SP}
  1579. test "$lSP" || return 254
  1580.  
  1581. local REPLY
  1582.  
  1583. # This function forces drawing of
  1584. # all spells that start witch 'create'
  1585. # to the message panel and the reads the
  1586. # drawinfo lines.
  1587. # It needs the SP variable set by
  1588. # _check_food_level()
  1589. _watch_stdalone
  1590. _is_stdalone 1 0 cast create
  1591.  
  1592. while :;
  1593. do
  1594.  
  1595. read -t ${TMOUT:-1}
  1596.    _log_stdalone "_check_mana_for_create_food_stdalone:$REPLY"
  1597.  _msg_stdalone 7 "_check_mana_for_create_food_stdalone:$REPLY"
  1598.  
  1599.  case $REPLY in
  1600.  *ready*the*spell*create*food*) return 0;;
  1601.  *create*food*)
  1602.  MANA_NEEDED=`echo "$REPLY" | awk '{print $NF}'`
  1603.  _msg_stdalone 7 "MANA_NEEDED=$MANA_NEEDED"
  1604.  test "$lSP" -ge "$MANA_NEEDED" && return 0 || break 1
  1605.  ;;
  1606.  *'Something blocks your spellcasting.'*) _exit_stdalone 1;;
  1607.  *scripttell*break*) break ${REPLY##*?break};;
  1608.  *scripttell*exit*)  _exit_stdalone 1 $REPLY;;
  1609.  *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  1610.  '') break 1;;
  1611.  *) :;;
  1612.  esac
  1613.  
  1614. sleep 0.01
  1615. unset REPLY
  1616. done
  1617.  
  1618. _unwatch_stdalone
  1619. return 1
  1620. }
  1621.  
  1622. _cast_create_food_and_eat_stdalone(){
  1623. _msg_stdalone 7 "_cast_create_food_and_eat_stdalone:$*"
  1624.  
  1625. local lEAT_FOOD BUNGLE
  1626.  
  1627. lEAT_FOOD="${*:-$EAT_FOOD}"
  1628. lEAT_FOOD=${lEAT_FOOD:-"$FOOD_DEF"}
  1629. lEAT_FOOD=${lEAT_FOOD:-food}
  1630.  
  1631.  _set_pickup_stdalone 0
  1632.  
  1633. _unwatch_stdalone $DRAWINFO
  1634. _empty_message_stream_stdalone
  1635. _watch_stdalone $DRAWINFO
  1636.  
  1637. unset HAVE_NOT_SPELL
  1638. # TODO: Check MANA
  1639. _is_stdalone 1 1 cast create food $lEAT_FOOD
  1640. while :;
  1641.  do
  1642.  unset REPLY
  1643.  read -t $TMOUT
  1644.  _log_stdalone "_cast_create_food_and_eat_stdalone:$REPLY"
  1645.  _msg_stdalone 7 "$REPLY"
  1646.  case $REPLY in
  1647.  *Cast*what*spell*) HAVE_NOT_SPELL=1; break 1;; #Cast what spell?  Choose one of:
  1648.  *ready*the*spell*)  break 1;;                  #You ready the spell create food
  1649.  '')                 break 1;;
  1650.  *scripttell*break*) break ${REPLY##*?break};;
  1651.  *scripttell*exit*)  _exit_stdalone 1 $REPLY;;
  1652.  *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  1653.  *) :;;
  1654.  esac
  1655. sleep 0.01
  1656. done
  1657.  
  1658. test "$HAVE_NOT_SPELL" && return 253
  1659.  
  1660. _empty_message_stream_stdalone
  1661.  
  1662. while :;
  1663. do
  1664. _is_stdalone 1 1 fire_stop # precaution
  1665. sleep 0.1
  1666.  
  1667.  while :;
  1668.  do
  1669.   _check_mana_for_create_food_stdalone && break
  1670.   sleep 10
  1671.  done
  1672.  
  1673. # _check_mana_for_create_food_stdalone returns early
  1674. _unwatch_stdalone $DRAWINFO
  1675. _empty_message_stream_stdalone
  1676. sleep 0.2
  1677.  
  1678. _watch_stdalone $DRAWINFO
  1679. _is_stdalone 1 1 fire center ## TODO: handle bungling the spell
  1680. _is_stdalone 1 1 fire_stop
  1681.  
  1682.  while :; do
  1683.   unset BUNGLE
  1684.   read -t $TMOUT BUNGLE
  1685.   _log_stdalone "_cast_create_food_and_eat_stdalone:$BUNGLE"
  1686.   _msg_stdalone 7 "BUNGLE=$BUNGLE"
  1687.   case $BUNGLE in
  1688.   *bungle*|*fumble*) break 1;;
  1689.   '') break 2;;
  1690.   *scripttell*break*) break ${BUNGLE##*?break};;
  1691.   *scripttell*exit*)  _exit_stdalone 1 $BUNGLE;;
  1692.   *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  1693.   *) :;;
  1694.   esac
  1695.  sleep 0.01
  1696.  done
  1697.  
  1698. sleep 0.2
  1699. done
  1700.  
  1701. _unwatch_stdalone $DRAWINFO
  1702. _is_stdalone 1 1 fire_stop
  1703. _empty_message_stream_stdalone
  1704. _sleep_stdalone
  1705.  
  1706. _check_if_on_item_stdalone -l ${lEAT_FOOD:-haggis} && _is_stdalone 1 1 apply ## TODO: check if food is there on tile
  1707. _empty_message_stream_stdalone
  1708. }
  1709.  
  1710. _eat_food_from_inventory_stdalone(){
  1711. _msg_stdalone 7 "_eat_food_from_inventory_stdalone:$*"
  1712.  
  1713. local lEAT_FOOD="${@:-$EAT_FOOD}"
  1714. lEAT_FOOD=${lEAT_FOOD:-"$FOOD_DEF"}
  1715. test "$lEAT_FOOD" || return 254
  1716.  
  1717. #_check_food_in_inventory_stdalone ## Todo: check if food is in INV
  1718. _check_have_item_in_inventory_stdalone $lEAT_FOOD && _is_stdalone 1 1 apply $lEAT_FOOD
  1719. #_is_stdalone 1 1 apply $lEAT_FOOD
  1720. }
  1721.  
  1722. _check_have_item_in_inventory_stdalone(){
  1723. _msg_stdalone 7 "_check_have_item_in_inventory_stdalone:$*"
  1724.  
  1725. local oneITEM oldITEM ITEMS ITEMSA lITEM
  1726. lITEM=${*:-"$ITEM"}
  1727. test "$lITEM" || return 254
  1728.  
  1729. TIMEB=`date +%s`
  1730.  
  1731. unset oneITEM oldITEM ITEMS ITEMSA
  1732.  
  1733. _empty_message_stream_stdalone
  1734. echo request items inv
  1735. while :;
  1736. do
  1737. read -t ${TMOUT:-1} oneITEM
  1738.  _log_stdalone "_check_have_item_in_inventory_stdalone:$oneITEM"
  1739.  _msg_stdalone 7 "$oneITEM"
  1740.  
  1741.  case $oneITEM in
  1742.  $oldITEM|'') break 1;;
  1743.  *"$lITEM"*|*"${lITEM// /?*}"*) _draw_stdalone 7 "Got that item $lITEM in inventory.";;
  1744.  *scripttell*break*)  break ${oneITEM##*?break};;
  1745.  *scripttell*exit*)   _exit_stdalone 1 $oneITEM;;
  1746.  *'YOU HAVE DIED.'*) _just_exit_stdalone;;
  1747.  *) :;;
  1748.  esac
  1749.  ITEMS="${ITEMS}${oneITEM}\n"
  1750.  oldITEM="$oneITEM"
  1751. sleep 0.01
  1752. done
  1753. unset oldITEM oneITEM
  1754.  
  1755.  
  1756. TIMEE=`date +%s`
  1757. TIME=$((TIMEE-TIMEB))
  1758. _msg_stdalone 7 "Fetching Inventory List: Elapsed $TIME sec."
  1759.  
  1760. echo -e "$ITEMS" | grep -q -i -E " $lITEM| ${lITEM}s| ${lITEM}es| ${lITEM// /[s ]+}"
  1761. }
  1762.  
  1763. _check_if_already_running_ps_stdalone(){
  1764.  
  1765. local lPROGS=`ps -o pid,ppid,args | grep -w $PPID | grep -v -w $$`
  1766. __debug_stdalone "$lPROGS"
  1767. lPROGS=`echo "$lPROGS" | grep -vE "^$PPID[[:blank:]]+|^[[:blank:]]+$PPID[[:blank:]]+" | grep -vE '<defunct>|grep|cfsndserv'`
  1768. __debug_stdalone "$lPROGS"
  1769. test ! "$lPROGS"
  1770. }
  1771.  
  1772. _say_start_msg_stdalone(){
  1773. # *** Here begins program *** #
  1774. _draw_stdalone 2 "$0 has started.."
  1775. _draw_stdalone 2 "PID is $$ - parentPID is $PPID"
  1776.  
  1777. _check_if_already_running_ps_stdalone || _exit_stdalone 1 "Another instance of $MY_BASE already running."
  1778. _check_drawinfo_stdalone || _exit_stdalone 1 "Unable to fetch the DRAWINFO variable. Please try again."
  1779.  
  1780. # *** Check for parameters *** #
  1781. _draw_stdalone 5 "Checking the parameters ($*)..."
  1782. }
  1783.  
  1784. _check_drawinfo_stdalone(){  ##+++2018-01-08
  1785. _msg_stdalone 7 "_check_drawinfo_stdalone:$*"
  1786.  
  1787. oDEBUG=$DEBUG;       DEBUG=${DEBUG:-''}
  1788. oLOGGING=$LOGGING; LOGGING=${LOGGING:-1}
  1789.  
  1790. _draw_stdalone 2 "Checking drawinfo ..."
  1791.  
  1792. echo watch
  1793.  
  1794. while :;
  1795. do
  1796.  
  1797. # I use search here to provoke
  1798. # a response from the server
  1799. # like You search the area.
  1800. # It could be something else,
  1801. # but I have no better idea for the moment.
  1802. _is_stdalone 0 0 search
  1803. _is_stdalone 0 0 examine
  1804.  
  1805.  unset cnt0 TICKS
  1806.  while :
  1807.  do
  1808.  cnt0=$((cnt0+1))
  1809.  read -t $TMOUT
  1810.  _log_stdalone "_check_drawinfo_stdalone:$cnt0:$REPLY"
  1811.  _msg_stdalone 7 "$cnt0:$REPLY"
  1812.  
  1813.  case $REPLY in
  1814.  *drawinfo*'You search'*|*drawinfo*'You spot'*)       DRAWINFO0=drawinfo;    break 2;;
  1815.  *drawextinfo*'You search'*|*drawextinfo*'You spot'*) DRAWINFO0=drawextinfo; break 2;;
  1816.  *drawinfo*'That is'*|*drawinfo*'Those are'*)         DRAWINFO0=drawinfo;    break 2;;
  1817.  *drawextinfo*'That is'*|*drawextinfo*'Those are'*)   DRAWINFO0=drawextinfo; break 2;;
  1818.  *drawinfo*'This is'*|*drawinfo*'These are'*)         DRAWINFO0=drawinfo;    break 2;;
  1819.  *drawextinfo*'This is'*|*drawextinfo*'These are'*)   DRAWINFO0=drawextinfo; break 2;;
  1820.  *tick*) TICKS=$((TICKS+1)); test "$TICKS" -gt 19 && break 1;;
  1821.  '') break 1;;
  1822.  *) :;;
  1823.  esac
  1824.  
  1825.  sleep 0.001
  1826.  done
  1827.  
  1828. _sleep_stdalone
  1829. done
  1830.  
  1831. echo unwatch
  1832. _empty_message_stream_stdalone
  1833. unset cnt0
  1834.  
  1835. test "$DRAWINFO0" = "$DRAWINFO" || {
  1836.     _msg_stdalone 5 "Changing internally from $DRAWINFO to $DRAWINFO0"
  1837.     DRAWINFO=$DRAWINFO0
  1838. }
  1839.  
  1840. DEBUG=$oDEBUG
  1841. LOGGING=$oLOGGING
  1842. _draw_stdalone 6 "Done."
  1843. }
  1844.  
  1845. _do_parameters_stdalone(){
  1846. _msg_stdalone 7 "_do_parameters_stdalone:$*"
  1847. _log_stdalone   "_do_parameters_stdalone:$*"
  1848.  
  1849. # dont forget to pass parameters when invoking this function
  1850. test "$*" || return 0
  1851.  
  1852. case $1 in
  1853. *help)    _say_help_stdalone 0;;
  1854. *version) _say_version_stdalone 0;;
  1855. --?*)  _exit_stdalone 3 "No other long options than help and version recognized.";;
  1856. --*)   _exit_stdalone 3 "Unhandled first parameter '$1' .";;
  1857. -?*) :;;
  1858. [0-9]*) NUMBER=$1
  1859.         test "${NUMBER//[[:digit:]]/}" && _exit_stdalone 3 "NUMBER '$1' is not an integer digit."
  1860.         shift;;
  1861. *) _exit_stdalone 3 "Unknown first parameter '$1' .";;
  1862. esac
  1863.  
  1864. # S # :Search attempts
  1865. # u   :use_skill
  1866. # c   :cast disarm
  1867. # i   :invoke disarm
  1868. # d   :debugging output
  1869. while getopts C:S:ciudLMVhabdefgjklmnopqrstvwxyzABDEFGHIJKNOPQRTUWXYZ oneOPT
  1870. do
  1871. case $oneOPT in
  1872. C) NUMBER=$OPTARG;;
  1873. S) SEARCH_ATTEMPTS=${OPTARG:-$SEARCH_ATTEMPTS_DEFAULT};;
  1874. L) LOGGING=$((LOGGING+1));;
  1875. M) MULTIPLE_TRAPS=$((MULTIPLE_TRAPS+1));;
  1876. c) DISARM=cast;;
  1877. i) DISARM=invokation;;
  1878. u) DISARM=skill;;
  1879. d) DEBUG=$((DEBUG+1)); MSGLEVEL=7;;
  1880. h) _say_help_stdalone 0;;
  1881. V) _say_version_stdalone 0;;
  1882.  
  1883. '') _draw_stdalone 2 "FIXME: Empty positional parameter ...?";;
  1884. *) _draw_stdalone 3 "Unrecognized parameter '$oneOPT' .";;
  1885. esac
  1886.  
  1887. sleep 0.1
  1888. done
  1889.  
  1890. }
  1891.  
  1892. _do_parameters(){
  1893. _debug "_do_parameters:$*"
  1894. _log   "_do_parameters:$*"
  1895.  
  1896. # dont forget to pass parameters when invoking this function
  1897. test "$*" || return 0
  1898.  
  1899. case $1 in
  1900. *help)    _say_help 0;;
  1901. *version) _say_version 0;;
  1902. --?*)  _exit 3 "No other long options than help and version recognized.";;
  1903. --*)   _exit 3 "Unhandled first parameter '$1' .";;
  1904. -?*) :;;
  1905. [0-9]*) NUMBER=$1
  1906.         test "${NUMBER//[[:digit:]]/}" && _exit 3 "NUMBER '$1' is not an integer digit."
  1907.         shift;;
  1908. *) _exit 3 "Unknown first parameter '$1' .";;
  1909. esac
  1910.  
  1911. # S # :Search attempts
  1912. # u   :use_skill
  1913. # c   :cast disarm
  1914. # i   :invoke disarm
  1915. # d   :debugging output
  1916. while getopts C:S:ciudLMVhabdefgjklmnopqrstvwxyzABDEFGHIJKNOPQRTUWXYZ oneOPT
  1917. do
  1918. case $oneOPT in
  1919. C) NUMBER=$OPTARG;;
  1920. S) SEARCH_ATTEMPTS=${OPTARG:-$SEARCH_ATTEMPTS_DEFAULT};;
  1921. L) LOGGING=$((LOGGING+1));;
  1922. M) MULTIPLE_TRAPS=$((MULTIPLE_TRAPS+1));;
  1923. c) DISARM=cast;;
  1924. i) DISARM=invokation;;
  1925. u) DISARM=skill;;
  1926. d) DEBUG=$((DEBUG+1)); MSGLEVEL=7;;
  1927. h) _say_help 0;;
  1928. V) _say_version 0;;
  1929.  
  1930. '') _draw 2 "FIXME: Empty positional parameter ...?";;
  1931. *) _draw 3 "Unrecognized parameter '$oneOPT' .";;
  1932. esac
  1933.  
  1934. sleep 0.1
  1935. done
  1936.  
  1937. }
  1938.  
  1939. _tell_script_time_stdalone(){
  1940. test "$TIMEA" || return 1
  1941.  
  1942.  TIMEE=`date +%s`
  1943.  TIME=$((TIMEE-TIMEA))
  1944.  TIMEM=$((TIME/60))
  1945.  TIMES=$(( TIME - (TIMEM*60) ))
  1946.  _draw_stdalone 4 "Loop of script had run a total of $TIMEM minutes and $TIMES seconds."
  1947. }
  1948.  
  1949. _say_script_time_stdalone(){ ##+++2018-01-07
  1950. TIME_ELAPSED=`ps -o pid,etime,args | grep -w "$$" | grep -vwE "grep|ps|${TMP_DIR:-/tmp}"`
  1951. __debug_stdalone "$TIME_ELAPSED"
  1952. TIME_ELAPSED=`echo "$TIME_ELAPSED" | awk '{print $2}'`
  1953. __debug_stdalone "$TIME_ELAPSED"
  1954. case $TIME_ELAPSED in
  1955. *:*:*) _draw_stdalone 5 "Script had run a time of $TIME_ELAPSED h:m:s .";;
  1956. *:*)   _draw_stdalone 5 "Script had run a time of $TIME_ELAPSED m:s .";;
  1957. *)     _draw_stdalone 5 "Script had run a time of $TIME_ELAPSED s .";;
  1958. esac
  1959. }
  1960.  
  1961. _say_end_msg_stdalone(){
  1962. # *** Here ends program *** #
  1963. _is_stdalone 1 1 fire_stop
  1964. test -f "$SOUND_DIR"/su-fanf.raw && aplay $Q "$SOUND_DIR"/su-fanf.raw & aPID=$!
  1965.  
  1966. _tell_script_time_stdalone || _say_script_time_stdalone
  1967.  
  1968. test "$DEBUG" || { test -s "$ERROR_LOG" || rm -f "$ERROR_LOG"; }
  1969. test "$DEBUG" -o "$INFO" || rm -f "$TMP_DIR"/*.$$*
  1970.  
  1971. test "$aPID" && wait $aPID
  1972. _draw_stdalone 2  "$0 $$ has finished."
  1973. }
  1974.  
  1975. _get_player_speed_stdalone(){
  1976. _msg_stdalone 7 "_get_player_speed_stdalone:$*"
  1977. _log_stdalone   "_get_player_speed_stdalone:$*"
  1978.  
  1979. if test "$1" = '-l'; then # loop counter
  1980.  _check_counter_stdalone || return 1
  1981.  shift
  1982. fi
  1983.  
  1984.   __old_req(){
  1985.   local reqANSWER OLD_ANSWER PL_SPEED
  1986.   reqANSWER=
  1987.   OLD_ANSWER=
  1988.  
  1989.   while :; do
  1990.   read -t $TMOUT reqANSWER
  1991.   #read -t $TMOUT r s c WC AC DAM PL_SPEED WP_SPEED
  1992.   #reqANSWER="$r $s $c $WC $AC $DAM $PL_SPEED $WP_SPEED"
  1993.   _log_stdalone "$REQUEST_LOG" "_get_player_speed:__old_req:$reqANSWER"
  1994.   _msg_stdalone 7 "$reqANSWER"
  1995.   test "$reqANSWER" || break
  1996.   test "$reqANSWER" = "$OLD_ANSWER" && break
  1997.   OLD_ANSWER="$reqANSWER"
  1998.   sleep 0.1
  1999.   done
  2000.  
  2001.   #PL_SPEED=`awk '{print $7}' <<<"$reqANSWER"`    # *** bash
  2002.   test "$reqANSWER" && PL_SPEED0=`echo "$reqANSWER" | awk '{print $7}'` # *** ash + bash
  2003.   PL_SPEED=${PL_SPEED0:-$PL_SPEED}
  2004.   }
  2005.  
  2006.   __new_req(){
  2007.   read -t $TMOUT r s c WC AC DAM PL_SPEED WP_SPEED
  2008.   _log_stdalone "$REQUEST_LOG" "_get_player_speed_stdalone:__new_req:$r $s $c $WC $AC $DAM PL_SPPED=$PL_SPEED $WP_SPEED"
  2009.   _msg_stdalone 7 "$r $s $c $WC $AC $DAM PL_SPPED=$PL_SPEED $WP_SPEED"
  2010.   }
  2011.  
  2012.  _use_old_funcs(){
  2013.  _empty_message_stream_stdalone
  2014.  echo request stat cmbt # only one line
  2015.  #__old_req
  2016.  __new_req
  2017.  }
  2018.  
  2019.  _use_new_funcs(){
  2020.  #__request_stdalone stat cmbt
  2021.   _request_stdalone stat cmbt
  2022.  test "$ANSWER" && PL_SPEED0=`echo "$ANSWER" | awk '{print $7}'`
  2023.  PL_SPEED=${PL_SPEED0:-$PL_SPEED}
  2024.  }
  2025.  
  2026. _draw_stdalone 5 "Processing Player's speed..."
  2027. #_use_old_funcs
  2028. _use_new_funcs
  2029.  
  2030. PL_SPEED=${PL_SPEED:-50000} # 0.50
  2031.  
  2032. _player_speed_to_human_readable_stdalone $PL_SPEED
  2033. _msg_stdalone 6 "Using player speed '$PL_SPEED1'"
  2034.  
  2035. _draw_stdalone 6 "Done."
  2036. return 0
  2037. }
  2038.  
  2039. _check_counter_stdalone(){
  2040. ckc=$((ckc+1))
  2041. test "$ckc" -lt ${COUNT_CHECK_FOOD:-11} && return 1
  2042. ckc=0
  2043. return 0
  2044. }
  2045.  
  2046. __request_stdalone(){ # for multi-line replies
  2047. _msg_stdalone 7 "__request_stdalone:$*"
  2048. _log_stdalone   "__request_stdalone:$*"
  2049.  
  2050. test "$*" || return 254
  2051.  
  2052. local lANSWER lOLD_ANSWER
  2053. lANSWER=
  2054. lOLD_ANSWER=
  2055.  
  2056. _empty_message_stream_stdalone
  2057. echo request $*
  2058. while :; do
  2059.  read -t $TMOUT lANSWER
  2060.  _log_stdalone "$REQUEST_LOG" "__request_stdalone $*:$lANSWER"
  2061.  _msg_stdalone 7 "$lANSWER"
  2062.  case $lANSWER in ''|$lOLD_ANSWER|*request*end) break 1;; esac
  2063.  ANSWER="$ANSWER
  2064. $lANSWER"
  2065. lOLD_ANSWER="$lANSWER"
  2066. sleep 0.01
  2067. done
  2068. ANSWER=`echo "$ANSWER" | sed 'sI^$II'`
  2069. test "$ANSWER"
  2070. }
  2071.  
  2072. _request_stdalone(){  # for one line replies
  2073. _msg_stdalone 7 "_request_stdalone:$*"
  2074. _log_stdalone   "_request_stdalone:$*"
  2075.  
  2076. test "$*" || return 254
  2077.  
  2078. local lANSWER=''
  2079.  
  2080. _empty_message_stream_stdalone
  2081. echo request $*
  2082. read -t $TMOUT lANSWER
  2083.  _log_stdalone "$REQUEST_LOG" "_request_stdalone $*:$lANSWER"
  2084.  _msg_stdalone 7 "$lANSWER"
  2085.  
  2086. ANSWER="$lANSWER"
  2087. test "$ANSWER"
  2088. }
  2089.  
  2090. _player_speed_to_human_readable_stdalone(){
  2091. _msg_stdalone 7 "_player_speed_to_human_readable_stdalone:$*"
  2092. _log_stdalone   "_player_speed_to_human_readable_stdalone:$*"
  2093.  
  2094. local lPL_SPEED=${1:-$PL_SPEED}
  2095. test "$lPL_SPEED" || return 254
  2096.  
  2097. local PL_SPEED_PRE PL_SPEED_POST
  2098.  
  2099. oLC_NUMERIC=$oLC_NUMERIC
  2100. LC_NUMERIC=C
  2101. case ${#lPL_SPEED} in
  2102. 7) PL_SPEED1="${lPL_SPEED:0:5}"; PL_SPEED1=`dc $PL_SPEED1 1000 \/ p`;;
  2103. 6) PL_SPEED1="${lPL_SPEED:0:4}"; PL_SPEED1=`dc $PL_SPEED1 1000 \/ p`;;
  2104. 5) PL_SPEED1="0.${lPL_SPEED:0:3}";;
  2105. 4) PL_SPEED1="0.0.${lPL_SPEED:0:2}";;
  2106. *) :;;
  2107. esac
  2108.  
  2109. _msg_stdalone 7 "Player speed is '$PL_SPEED1'"
  2110.  
  2111. case $PL_SPEED1 in
  2112. *.*)
  2113. PL_SPEED_PRE="${PL_SPEED1%.*}."
  2114. PL_SPEED_POST="${PL_SPEED1##*.}"
  2115. ;;
  2116. *,*)
  2117. PL_SPEED_PRE="${PL_SPEED1%,*},"
  2118. PL_SPEED_POST="${PL_SPEED1##*,}"
  2119. ;;
  2120. [0-9]*)
  2121. PL_SPEED_PRE="${PL_SPEED1}."
  2122. PL_SPEED_POST=00
  2123. ;;
  2124. esac
  2125. case ${#PL_SPEED_POST} in 1) PL_SPEED_POST="${PL_SPEED_POST}0";; esac
  2126.  
  2127. PL_SPEED_POST=`_round_up_and_down_stdalone $PL_SPEED_POST`
  2128. _msg_stdalone 7 "Rounded Player speed is '${PL_SPEED_PRE}$PL_SPEED_POST'"
  2129. PL_SPEED_POST=${PL_SPEED_POST:0:2}
  2130. _msg_stdalone 7 "Rounded Player speed is '${PL_SPEED_PRE}$PL_SPEED_POST'"
  2131.  
  2132. PL_SPEED1="${PL_SPEED_PRE}${PL_SPEED_POST}"
  2133. _msg_stdalone 7 "Rounded Player speed is '$PL_SPEED1'"
  2134.  
  2135. PL_SPEED1=`echo "$PL_SPEED1" | sed 's!\.!!g;s!\,!!g;s!^0*!!'`
  2136. LC_NUMERIC=$oLC_NUMERIC
  2137. }
  2138.  
  2139. _round_up_and_down_stdalone(){  ##+++2018-01-08
  2140. [ "$DEBUG" ] && echo "_round_up_and_down_stdalone:$1" >&2
  2141.                #123
  2142. STELLEN=${#1}  #3
  2143. [ "$DEBUG" ] && echo "STELLEN=$STELLEN" >&2
  2144.  
  2145. LETZTSTELLE=${1:$((STELLEN-1))} #123:2
  2146. [ "$DEBUG" ] && echo "LETZTSTELLE=$LETZTSTELLE" >&2
  2147.  
  2148. VORLETZTSTELLE=${1:$((STELLEN-2)):1} #123:1:1
  2149. [ "$DEBUG" ] && echo "VORLETZTSTELLE=$VORLETZTSTELLE" >&2
  2150.  
  2151. GERUNDET_BASIS=${1:0:$((STELLEN-1))} #123:0:2
  2152. [ "$DEBUG" ] && echo "GERUNDET_BASIS=$GERUNDET_BASIS" >&2
  2153.  
  2154. case $LETZTSTELLE in
  2155. 0)     GERUNDET="${GERUNDET_BASIS}0";;
  2156. [5-9]) GERUNDET="$((GERUNDET_BASIS+1))0";;
  2157. [1-4]) GERUNDET="${GERUNDET_BASIS}0";;
  2158. *) :;;
  2159. esac
  2160.  
  2161. echo $GERUNDET
  2162. }
  2163.  
  2164. _set_sync_sleep_stdalone(){
  2165. _msg_stdalone 7 "_set_sync_sleep_stdalone:$*"
  2166. _log_stdalone   "_set_sync_sleep_stdalone:$*"
  2167.  
  2168. local lPL_SPEED=${1:-$PL_SPEED}
  2169. lPL_SPEED=${lPL_SPEED:-50000}
  2170.  
  2171.   if test "$lPL_SPEED"  =  "";    then
  2172. _draw_stdalone 3 "WARNING: Could not set player speed. Using defaults."
  2173. elif test "$lPL_SPEED" -gt 60000; then
  2174. SLEEP=0.4; DELAY_DRAWINFO=1.0; TMOUT=1
  2175. elif test "$lPL_SPEED" -gt 55000; then
  2176. SLEEP=0.5; DELAY_DRAWINFO=1.1; TMOUT=1
  2177. elif test "$lPL_SPEED" -gt 50000; then
  2178. SLEEP=0.6; DELAY_DRAWINFO=1.2; TMOUT=1
  2179. elif test "$lPL_SPEED" -gt 45000; then
  2180. SLEEP=0.7; DELAY_DRAWINFO=1.4; TMOUT=1
  2181. elif test "$lPL_SPEED" -gt 40000; then
  2182. SLEEP=0.8; DELAY_DRAWINFO=1.6; TMOUT=1
  2183. elif test "$lPL_SPEED" -gt 35000; then
  2184. SLEEP=1.0; DELAY_DRAWINFO=2.0; TMOUT=2
  2185. elif test "$lPL_SPEED" -gt 30000; then
  2186. SLEEP=1.5; DELAY_DRAWINFO=3.0; TMOUT=2
  2187. elif test "$lPL_SPEED" -gt 25000; then
  2188. SlEEP=2.0; DELAY_DRAWINFO=4.0; TMOUT=2
  2189. elif test "$lPL_SPEED" -gt 20000; then
  2190. SlEEP=2.5; DELAY_DRAWINFO=5.0; TMOUT=2
  2191. elif test "$lPL_SPEED" -gt 15000; then
  2192. SLEEP=3.0; DELAY_DRAWINFO=6.0; TMOUT=2
  2193. elif test "$lPL_SPEED" -gt 10000; then
  2194. SLEEP=4.0; DELAY_DRAWINFO=8.0; TMOUT=2
  2195. elif test "$lPL_SPEED" -ge 0;  then
  2196. SLEEP=5.0; DELAY_DRAWINFO=10.0; TMOUT=2
  2197. else
  2198. _exit_stdalone 1 "ERROR while processing player speed."
  2199. fi
  2200.  
  2201. _info_stdalone "Setting SLEEP=$SLEEP ,TMOUT=$TMOUT ,DELAY_DRAWINFO=$DELAY_DRAWINFO"
  2202. }
  2203.  
  2204. __set_sync_sleep_stdalone(){
  2205. _msg_stdalone 7 "__set_sync_sleep_stdalone:$*"
  2206. _log_stdalone   "__set_sync_sleep_stdalone:$*"
  2207.  
  2208. local lPL_SPEED=${1:-$PL_SPEED1}
  2209. lPL_SPEED=${lPL_SPEED:-50}
  2210.  
  2211.   if test "$lPL_SPEED" = "";   then
  2212. _draw_stdalone 3 "WARNING: Could not set player speed. Using defaults."
  2213. elif test "$lPL_SPEED" -gt 60; then
  2214. SLEEP=0.4; DELAY_DRAWINFO=1.0; TMOUT=1
  2215. elif test "$lPL_SPEED" -gt 55; then
  2216. SLEEP=0.5; DELAY_DRAWINFO=1.1; TMOUT=1
  2217. elif test "$lPL_SPEED" -gt 50; then
  2218. SLEEP=0.6; DELAY_DRAWINFO=1.2; TMOUT=1
  2219. elif test "$lPL_SPEED" -gt 45; then
  2220. SLEEP=0.7; DELAY_DRAWINFO=1.4; TMOUT=1
  2221. elif test "$lPL_SPEED" -gt 40; then
  2222. SLEEP=0.8; DELAY_DRAWINFO=1.6; TMOUT=1
  2223. elif test "$lPL_SPEED" -gt 35; then
  2224. SLEEP=1.0; DELAY_DRAWINFO=2.0; TMOUT=2
  2225. elif test "$lPL_SPEED" -gt 30; then
  2226. SLEEP=1.5; DELAY_DRAWINFO=3.0; TMOUT=2
  2227. elif test "$lPL_SPEED" -gt 25; then
  2228. SlEEP=2.0; DELAY_DRAWINFO=4.0; TMOUT=2
  2229. elif test "$lPL_SPEED" -gt 20; then
  2230. SlEEP=2.5; DELAY_DRAWINFO=5.0; TMOUT=2
  2231. elif test "$lPL_SPEED" -gt 15; then
  2232. SLEEP=3.0; DELAY_DRAWINFO=6.0; TMOUT=2
  2233. elif test "$lPL_SPEED" -gt 10; then
  2234. SLEEP=4.0; DELAY_DRAWINFO=8.0; TMOUT=2
  2235. elif test "$lPL_SPEED" -ge 0;  then
  2236. SLEEP=5.0; DELAY_DRAWINFO=10.0; TMOUT=2
  2237. else
  2238. _exit_stdalone 1 "ERROR while processing player speed."
  2239. fi
  2240.  
  2241. _info_stdalone "Setting SLEEP=$SLEEP ,TMOUT=$TMOUT ,DELAY_DRAWINFO=$DELAY_DRAWINFO"
  2242. }
  2243.  
  2244. _sleep_stdalone(){
  2245. SLEEP=${SLEEP//,/.}
  2246. sleep ${SLEEP:-1}
  2247. }
  2248.  
  2249. _set_pickup_stdalone(){
  2250. # Usage: pickup <0-7> or <value_density> .
  2251. # pickup 0:Don't pick up.
  2252. # pickup 1:Pick up one item.
  2253. # pickup 2:Pick up one item and stop.
  2254. # pickup 3:Stop before picking up.
  2255. # pickup 4:Pick up all items.
  2256. # pickup 5:Pick up all items and stop.
  2257. # pickup 6:Pick up all magic items.
  2258. # pickup 7:Pick up all coins and gems
  2259. #
  2260. #TODO: In pickup 4 and 5 mode
  2261. # seems to pick up only
  2262. # one piece of the topmost item, if more than one
  2263. # piece of the item, as 4 coins or 23 arrows
  2264. # but all items below the topmost item get
  2265. # picked up wholly
  2266. # in _open_chests() ..?
  2267.  
  2268. #_is_stdalone 0 0 pickup ${*:-0}
  2269. #_is_stdalone 1 0 pickup ${*:-0}
  2270. #_is_stdalone 0 1 pickup ${*:-0}
  2271.  _is_stdalone 1 1 pickup ${*:-0}
  2272. }
  2273.  
  2274. _drop(){
  2275.  _sound_stdalone 0 drip &
  2276.  #_is_stdalone 1 1 drop "$@" #01:58 There are only 1 chests.
  2277.   _is_stdalone 0 0 drop "$@"
  2278. }
  2279.  
  2280.  
  2281. #MAIN
  2282.  
  2283. _main_open_chests_func(){
  2284.  
  2285. _source_library_files(){
  2286. . $MY_DIR/cf_funcs_common.sh   || { echo draw 3 "$MY_DIR/cf_funcs_common.sh   failed to load."; exit 4; }
  2287. . $MY_DIR/cf_funcs_food.sh     ||       _exit 5 "$MY_DIR/cf_funcs_food.sh     failed to load."
  2288. . $MY_DIR/cf_funcs_traps.sh    ||       _exit 6 "$MY_DIR/cf_funcs_traps.sh    failed to load."
  2289. . $MY_DIR/cf_funcs_move.sh     ||       _exit 7 "$MY_DIR/cf_funcs_move.sh     failed to load."
  2290. . $MY_DIR/cf_funcs_chests.sh   ||       _exit 8 "$MY_DIR/cf_funcs_chests.sh   failed to load."
  2291. . $MY_DIR/cf_funcs_requests.sh ||      _exit 12 "$MY_DIR/cf_funcs_requests.sh failed to load."
  2292. }
  2293. _source_library_files
  2294.  
  2295. _debug "_main_open_chests_func:$*"
  2296. _log   "_main_open_chests_func:$*"
  2297.  
  2298. _set_global_variables $*
  2299. _say_start_msg $*
  2300. _do_parameters $*
  2301.  
  2302. test "$FUNCTION_CHECK_FOR_SPACE" && $FUNCTION_CHECK_FOR_SPACE 2
  2303. _sleep
  2304.  
  2305. _get_player_speed
  2306. PL_SPEED2=$PL_SPEED1
  2307. _sleep
  2308.  
  2309. _drop chest
  2310. _sleep
  2311. _set_pickup 0
  2312. _move_back_and_forth 2 # this is needed for _check_if_on_item_examine
  2313.  
  2314. _get_player_speed
  2315. PL_SPEED3=$PL_SPEED1
  2316. _sleep
  2317. PL_SPEED4=$(( (PL_SPEED2+PL_SPEED3) / 2 ))
  2318. test "$PL_SPEED4" && __set_sync_sleep ${PL_SPEED4} || _set_sync_sleep "$PL_SPEED"
  2319.  
  2320. #_check_if_on_item_examine chest || return 1
  2321. #_check_if_on_chest_request_items_on || return 1
  2322. _check_if_on_chest -l || return 1
  2323.  
  2324. _sleep
  2325.  
  2326. _search_traps
  2327. _disarm_traps
  2328. _open_chests
  2329. }
  2330.  
  2331. _main_open_chests_stdalone(){
  2332. _msg_stdalone 7 "_main_open_chests_stdalone:$*"
  2333. _log_stdalone   "_main_open_chests_stdalone:$*"
  2334.  
  2335. _set_global_variables_stdalone $*
  2336. _do_parameters_stdalone $*
  2337.  
  2338. if test "$ATTACKS_SPOT" -a "$COUNT_CHECK_FOOD"; then
  2339.  COUNT_CHECK_FOOD=$((COUNT_CHECK_FOOD/ATTACKS_SPOT))
  2340.  test "$COUNT_CHECK_FOOD" -le 0 && COUNT_CHECK_FOOD=1
  2341. fi
  2342.  
  2343. _say_start_msg_stdalone $*
  2344. #_do_parameters_stdalone $*
  2345.  
  2346. test "$FUNCTION_CHECK_FOR_SPACE" && $FUNCTION_CHECK_FOR_SPACE 2
  2347. _sleep_stdalone
  2348.  
  2349. _get_player_speed_stdalone
  2350. PL_SPEED2=$PL_SPEED1
  2351. _sleep_stdalone
  2352.  
  2353. _drop_stdalone chest
  2354. _sleep_stdalone
  2355. _set_pickup_stdalone 0
  2356. _move_back_and_forth_stdalone 2 # this is needed for _check_if_on_item_examine_stdalone
  2357.  
  2358. _get_player_speed_stdalone
  2359. PL_SPEED3=$PL_SPEED1
  2360. _sleep_stdalone
  2361. PL_SPEED4=$(( (PL_SPEED2+PL_SPEED3) / 2 ))
  2362. test "$PL_SPEED4" && __set_sync_sleep_stdalone ${PL_SPEED4} || _set_sync_sleep_stdalone "$PL_SPEED"
  2363.  
  2364. #_check_if_on_item_examine_stdalone chest || return 1
  2365. #_check_if_on_chest_request_items_on_stdalone || return 1
  2366.  _check_if_on_chest_stdalone -l || return 1
  2367.  
  2368. _sleep_stdalone
  2369.  
  2370. _search_traps_stdalone
  2371. _disarm_traps_stdalone
  2372. _open_chests_stdalone
  2373. }
  2374.  
  2375.  _main_open_chests_func "$@" && _draw 8 "You opened ${CHEST_COUNT:-0} chest(s)."
  2376.  _say_end_msg
  2377. #_main_open_chests_stdalone "$@" && _draw_stdalone 8 "You opened ${CHEST_COUNT:-0} chest(s)."
  2378. #_say_end_msg_stdalone
  2379.  
  2380. ###END###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement