DnD_Tools/time.sh

148 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
#tool for having time reference in your DnD game.
#It tracks time, date and moon phase
#1h of real time equals to 12h ingame
HOUR=8
MINUTE=0
SECOND=0
DOW="Mon"
MOON=0
MOON_DIR="D"
MOON_CNTR=$((12744*$MOON))
DAY=1
MONTH=1
YEAR=2300
#check arguments
for (( i=1; i<=$#; i++))
do
if [[ "${!i}" =~ "H" ]]; then
j=$((i+1))
HOUR=${!j}
elif [[ "${!i}" =~ "m" ]]; then
j=$((i+1))
MINUTE=${!j}
elif [[ "${!i}" =~ "s" ]]; then
j=$((i+1))
SECOND=${!j}
elif [[ "${!i}" =~ "d" ]]; then
j=$((i+1))
DOW=${!j}
elif [[ "${!i}" =~ "l" ]]; then
j=$((i+1))
k=$((i+2))
MOON=${!j}
MOON_DIR=${!k}
MOON_CNTR=$((12744*$MOON))
elif [[ "${!i}" =~ "D" ]]; then
j=$((i+1))
DAY=${!j}
elif [[ "${!i}" =~ "M" ]]; then
j=$((i+1))
MONTH=${!j}
elif [[ "${!i}" =~ "Y" ]]; then
j=$((i+1))
YEAR=${!j}
elif [[ "${!i}" =~ "h" ]]; then
echo "Author: Angoosh Leviocki"
echo "Script Usage:"
echo "DnD_time.sh [OPTIONS]"
echo "if options are empty, default time will be used"
echo ""
echo "OPTIONS:"
echo "-H sets hour"
echo "-m sets minute"
echo "-s sets second"
echo "-d sets day of week (Mon, Tue, Wed, Thu, Fri, Sat, Sun"
echo "-l sets moon phase in % and direction (D,C)"
echo "-D sets date day"
echo "-M sets date month"
echo "-Y sets date year"
echo "-h prints this help"
exit 0
fi
done
#1h = 12h in game
#708h = moon phase period = 3.54h = 1% = 12744s
#internal time counter for moon in seconds
clear
while true
do
if [[ $MOON_DIR = "D" ]]; then
MOON_CNTR=$((MOON_CNTR+12))
if [[ $MOON_CNTR -ge 1274400 ]]; then
MOON_DIR="C"
fi
else
MOON_CNTR=$((MOON_CNTR-12))
if [[ $MOON_CNTR -le 0 ]]; then
MOON_DIR="D"
fi
fi
#MOON=$(($MOON_CNTR / 1274400))
MOON=$(echo "scale=2; ($MOON_CNTR*100)/1274400" | bc)
SECOND=$((SECOND+12))
if [[ $SECOND -ge 60 ]]; then
SECOND=0
MINUTE=$((MINUTE+1))
fi
if [[ $MINUTE -ge 60 ]]; then
MINUTE=0
HOUR=$((HOUR+1))
fi
if [[ $HOUR -ge 24 ]]; then
HOUR=0
if [[ $DOW = "Mon" ]]; then
DOW="Tue"
elif [[ $DOW = "Tue" ]]; then
DOW="Wed"
elif [[ $DOW = "Wed" ]]; then
DOW="Thu"
elif [[ $DOW = "Thu" ]]; then
DOW="Fri"
elif [[ $DOW = "Fri" ]]; then
DOW="Sat"
elif [[ $DOW = "Sat" ]]; then
DOW="Sun"
elif [[ $DOW = "Sun" ]]; then
DOW="Mon"
fi
DAY=$((DAY+1))
if [[ $MONTH -eq 1 || $MONTH -eq 3 || $MONTH -eq 5 || $MONTH -eq 7 || $MONTH -eq 9 || $MONTH -eq 11 ]]; then
if [[ $DAY -gt 31 ]]; then
MONTH=$((MONTH+1))
DAY=1
fi
elif [[ $MONTH -eq 2 ]]; then
if [[ $DAY -gt 28 ]]; then
MONTH=$((MONTH+1))
DAY=1
fi
else
if [[ $DAY -gt 30 ]]; then
MONTH=$((MONTH+1))
DAY=1
fi
fi
if [[ $MONTH -gt 12 ]]; then
MONTH=1
YEAR=$((YEAR+1))
fi
fi
echo -e "\e[3A\e[KDATE: ${DOW} ${DAY}-${MONTH}-${YEAR}"
echo -e "\e[KTIME: ${HOUR}:${MINUTE}:${SECOND}"
echo -e "\e[KMOON: $MOON_DIR ${MOON}%"
sleep 1
done