Une version rudimentaire de Slay The Spire dans le terminal - retour accueil
git clone git://bebou.netlib.re/sts-term
Log | Files | Refs | README |
commit e7efe9ad0a9a497b6c9fb140301861ea22c600a5 parent 550fccb1dbb57f7739a7d4ea0ec98ec28833de6a Auterice: Arthur Pons <arthur.pons@unistra.fr> Date: Thu, 20 Jun 2024 20:21:28 +0200 Gestion du décompte des status Bon ça commence à devenir compliqué Faudrait séparer utils en plusieurs fichiers Logique des statuts à revoir (genre quand on fait le décompte on révérifie si le status existe dans __status alors que c'est forcément vrai breeeeef) Diffstat:
M | utils | | | 80 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------- |
1 file changed, 63 insertions(+), 17 deletions(-)
diff --git a/utils b/utils @@ -158,12 +158,6 @@ _gameover() { ./reset } -_hasstatus() { - target="${1:?need target}" - status="$2" - grep -Eq "^(de)?bufs.*$status,[0-9]+" "$target" -} - _dodamage() { ffplay -nodisp -autoexit -loglevel panic -i sounds/hit.ogg damage="$1";target="$2" @@ -186,17 +180,6 @@ _attack() { done; } -_status() { - status="$1" - nbturns="$2" - target="$3" - case "$status" in - ('vulnerable') type="debufs";; - ('*') type="bufs";; - esac - sed --follow-symlinks -i -E "/^$type/ s/$/ $status,$nbturns/" "$target" -} - _defend() { ffplay -nodisp -autoexit -loglevel panic -i sounds/block.ogg block="$1" @@ -255,11 +238,13 @@ _heal() { _setstat fight/player health $(( $newhealth > $maxhealth ? $maxhealth : $newhealth )) } + endturn() { _setstat fight/ennemies/* block 0 _execnextmove _setstat fight/player block 0 _setstat fight/player energy 3 + _decreasestatuses _nextmove _newhand echo "$(( $(cat fight/turn) + 1 ))" > fight/turn @@ -303,6 +288,67 @@ _refreshUI() { } ##### +# Statuses +##### + +_status() { + stat="$1" + nbturns="$2" + target="$3" + case "$stat" in + ('vulnerable') type="debufs";; + ('*') type="bufs";; + esac + if $(_hasstatus "$target" "$stat");then + remturn=$(_getremainingstatusturns "$target" "$stat") + totturns=$(( $nbturns + ${remturn:-0} )) + if [ "$totturns" = "0" ];then + _removestatus "$target" "$stat" + else + sed --follow-symlinks -i -E "/^$type/ s/$stat,[0-9]+/$stat,$totturns/" "$target" + fi + else + sed --follow-symlinks -i -E "/^$type/ s/$/ $stat,$nbturns/" "$target" + fi +} + +_getstatuses() { + target="$1" + grep -E '^(de)?bufs ' "$target" | + cut -f2- | + tr ' ' '\n' | + cut -d',' -f1 +} + +_decreasestatuses() { + find fight/ennemies/* -type l | + while read ennemy;do + statuses=$(_getstatuses "$ennemy") + [ -z "$statuses" ] && continue + for stat in "$statuses";do + _status "$stat" -1 "$ennemy" + done + done +} + +_hasstatus() { + target="${1:?need target}" + stat="$2" + grep -Eq "^(de)?bufs.*$stat,[0-9]+" "$target" +} + +_getremainingstatusturns() { + target="$1";stat="$2" + grep -Eo " $stat,[0-9]+" "$target" | cut -d',' -f2 +} + +_removestatus() { + target="$1" + stat="$2" + sed -i -E --follow-symlinks "/^(de)?bufs/ s/ $stat,[0-9]+//" "$target" +} + +##### # Ennemies #####