User Tools

Site Tools


user:karl:cauldron:cf_funcs_skills_sh

Bash functions for Skills

This function library contains bash shell functions related to skills .
Though it had been tested with the busybox ash shell, some functions might only work correctly in bash ( or the other way around ).

The functions use code from

These client side scripting files are suggested to be installed inside the user's “HOME/.crossfire/s/” folder,
with a shortcut link cf → to the .crossfire directory,
to do have not much typing to do in the client's commandline.

Functions are usually named _function(){ ;} , functions named _ _function and _ _ _function are usually alternatives to the _function.

The only function currently in it is _check_skill_available ,
to probe, if a player possesses a given skill or not.
Syntax : _check_skill_available <skill>
Example : _check_skill_available punching
Returns : 0 if read *'Readied skill: '“$lSKILL”* drawn inside the info messages window of the client,
greater than zero otherwise.

A little bit tricky is, when the skill is already made the foreground attack,
readying that skill again, does not draw anything in the info pane to be read,
to confirm that the skill is available and allowed to the player.
One way would be to use one of the Basic Skills , but the barbarians do not
possess all basic skills because of missing literacy .
Therefore the variables SKILL_NOT_PUNCHING and SKILL_NOT_THROWING can be set to an other skill.
The code falls back to SKILL_NOT_PUNCHING=throwing and SKILL_NOT_THROWING=punching if these are not set in calling scripts.

The Code

60 lines of code without much explanations…

#!/bin/ash
 
[ "$HAVE_FUNCS_SKILLS" ] && return 0
 
# depends :
[ "$HAVE_FUNCS_COMMON"   ] || . cf_funcs_common.sh
 
_check_skill_available(){
_debug "_check_skill_available:$*"
_log   "_check_skill_available:$*"
 
local lSKILL=${1:-"$SKILL"}
test "$lSKILL" || return 254
 
local lRV=
 
_empty_message_stream
_watch $DRAWINFO
case "$lSKILL" in
punch*) _is 1 1 ready_skill ${SKILL_NOT_PUNCHING:-throwing};;
throw*) _is 1 1 ready_skill ${SKILL_NOT_THROWING:-punching};;
*)      _is 1 1 ready_skill ${2:-punching};;  # force response, because when not changing
esac                                          # range attack, no message is printed
_is 1 1 ready_skill "$lSKILL"
 
while :; do unset REPLY
read -t $TMOUT
  _log "_check_skill_available:$REPLY"
_debug "$REPLY"
 
 case $REPLY in
 '') break 1;;
 *'Readied skill: '"$lSKILL"*) lRV=0; break 1;;   # if (!(aflags & AP_NOPRINT))
 # server/apply.c:          new_draw_info_format (NDI_UNIQUE, 0, who, "Readied skill: %s.",
 # server/apply.c-                    op->skill? op->skill:op->name);
 *'Unable to find skill '*)    lRV=1; break 1;; # new_draw_info_format(NDI_UNIQUE, 0, op,
 # server/skill_util.c:          "Unable to find skill %s", string);
 # server/skill_util.c- return 0;
 *scripttell*break*)     break ${REPLY##*?break};;
 *scripttell*exit*)    _exit 1 $REPLY;;
 *'YOU HAVE DIED.'*) _just_exit;;
 *) :;;
 esac
 
sleep 0.01
done
 
_unwatch $DRAWINFO
_empty_message_stream
 
return ${lRV:-3}
}
 
###END###
HAVE_FUNCS_SKILLS=1
user/karl/cauldron/cf_funcs_skills_sh.txt · Last modified: 2018/04/06 04:31 by karl