-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp
executable file
·277 lines (255 loc) · 8.54 KB
/
exp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/bash
#EXP leveling system, designed/written/maintained by: Will Russell (Scotchman0)
Version=v1.0
#Release date: 6/15/21
#define what is needed by the program:
exp_gain() {
# the basic building block of EXP_GEN, captures user defined 'e' value and applies it to logged exp value.
# the file ~/.exp_gen/my_exp is effectively a log that is wiped on level up to avoid an overflow
echo "$e" >> ~/.exp_gen/my_exp
}
status_check() {
echo "Current EXP:"
currentEXP=$(awk '{s+=$1} END {printf "%.0f", s}' ~/.exp_gen/my_exp) #sums the lines in ~/.exp_gen/my_exp
echo $currentEXP
echo ""
echo "Current Level:"
cat ~/.exp_gen/my_level
next_level
source ~/.exp_gen/exp_gen.conf
echo "exp needed until next level:"
echo $(($level_CAP - $currentEXP))
}
next_level() {
#tracks what level you are on and therefore evaluates what EXP gain is needed until next level
currentLEVEL=$(cat ~/.exp_gen/my_level)
if [ $currentLEVEL -le 10 ]
then level_CAP=100
elif [ $currentLEVEL -le 20 ]
then level_CAP=110
elif [ $currentLEVEL -le 30 ]
then level_CAP=125
elif [ $currentLEVEL -le 40 ]
then level_CAP=150
elif [ $currentLEVEL -le 50 ]
then level_CAP=175
elif [ $currentLEVEL -le 60 ]
then level_CAP=200
elif [ $currentLEVEL -le 70 ]
then level_CAP=225
elif [ $currentLEVEL -le 80 ]
then level_CAP=250
elif [ $currentLEVEL -le 90 ]
then level_CAP=275
elif [ $currentLEVEL -le 100 ]
then level_CAP=300
elif [ $currentLEVEL -le 150 ]
then level_CAP=325
elif [ $currentLEVEL -le 200 ]
then level_CAP=350
elif [ $currentLEVEL -le 250 ]
then level_CAP=375
elif [ $currentLEVEL -le 300 ]
then level_CAP=400
elif [ $currentLEVEL -le 400 ]
then level_CAP=425
elif [ $currentLEVEL -le 500 ]
then level_CAP=450
elif [ $currentLEVEL -le 600 ]
then level_CAP=475
elif [ $currentLEVEL -le 10000 ]
then level_CAP=500
fi
}
level_up() {
# When you hit a level cap and level_tracker rolls over, echo random line from "level_up.txt" +
# provide n value of break reward
echo "Level Up!" #placeholder
#shuf command shuffles random reward line
shuf -n 1 ~/.exp_gen/level_up.txt
LEVEL=$(cat ~/.exp_gen/my_level)
echo $((1+$LEVEL)) > ~/.exp_gen/my_level
echo "new level: $(cat ~/.exp_gen/my_level)"
echo "take a little break, you've earned it!"
#clear exp counter and keep rollover:
currentEXP=$(awk '{s+=$1} END {printf "%.0f", s}' ~/.exp_gen/my_exp)
echo $(($currentEXP-$level_CAP)) > ~/.exp_gen/my_exp
}
timer() {
# provides basic timer functionality (sleep/wait) n minutes and then adds defined 'e' exp gain
#convert wait time to seconds:
sleep_time=$(echo $(($wait_time * 60)))
echo "now waiting for '$sleep_time' seconds, press ctrl+c to cancel"
sleep $sleep_time
}
time_loop() {
# basic sleep timer but loops indefinitely, granting [e] exp every [n] minutes
# mostly designed to help encourage study blocks or project work time. Set it
# then return later and see those sick level gains.
while true; do
sleep_time=$(echo $(($wait_time * 60)))
echo "now waiting for '$sleep_time' seconds, press ctrl+c to cancel"
sleep $sleep_time
exp_gain
echo "gained +'$e' exp!"
done
}
first_run_setup(){
# checks to see if version grepped from exp is same as latest in git folder, if not copies latest to ~/bin/
# checks to see if ~/.exp_gen/exp_gen.conf exists, if not, creates it + copies in all reference files
mkdir ~/.exp_gen
touch ~/.exp_gen/exp_gen.conf
touch ~/.exp_gen/my_exp
echo 0 > ~/.exp_gen/my_exp
touch ~/.exp_gen/my_level
echo 0 > ~/.exp_gen/my_level
cp ./level_up.txt ~/.exp_gen/
echo "#!/bin/bash" > ~/.exp_gen/exp_gen.conf
echo "Version=$Version" >> ~/.exp_gen/exp_gen.conf
level_up_praise
}
reset_all() {
echo "clearing levels and exp gain"
echo "0" > ~/.exp_gen/my_level
> ~/.exp_gen/my_exp
}
uninstall () {
# confirms user wants to uninstall/delete all exp + level data then purges files:
# removes ~/.exp_gen/ recursively, clearing all install files
# removes copy of 'exp' from ~/bin
echo "uninstall completed"
rm ~/.exp_gen/my_level
rm ~/.exp_gen/my_exp
rm ~/.exp_gen/exp_gen.conf
rm ~/.exp_gen/level_up.txt
rmdir ~/.exp_gen
exit 0
}
#define praise array. There's WAY better ways to do this but this works so it's fine
level_up_praise(){
echo "Congrats!" >> ~/.exp_gen/level_up.txt
echo "Nice work!" >> ~/.exp_gen/level_up.txt
echo "Hell Yeah!" >> ~/.exp_gen/level_up.txt
echo "That's how it's done!" >> ~/.exp_gen/level_up.txt
echo "killin' it!" >> ~/.exp_gen/level_up.txt
echo "Crushing it!" >> ~/.exp_gen/level_up.txt
echo "Hard work's paying off!" >> ~/.exp_gen/level_up.txt
echo "That's the way!" >> ~/.exp_gen/level_up.txt
echo "Get it!" >> ~/.exp_gen/level_up.txt
echo "Outstanding!" >> ~/.exp_gen/level_up.txt
echo "Heck Yeah!" >> ~/.exp_gen/level_up.txt
echo "Look at you go!" >> ~/.exp_gen/level_up.txt
echo "Wow!" >> ~/.exp_gen/level_up.txt
echo "Great Job!" >> ~/.exp_gen/level_up.txt
echo "Show em how it's done!" >> ~/.exp_gen/level_up.txt
echo "Really solid work!" >> ~/.exp_gen/level_up.txt
echo "Damn fine Job!" >> ~/.exp_gen/level_up.txt
echo "Woooo!" >> ~/.exp_gen/level_up.txt
echo "Super-hero!" >> ~/.exp_gen/level_up.txt
echo "Amazing!" >> ~/.exp_gen/level_up.txt
}
########################BEGIN SCRIPT######################################
#CHECK FOR SETUP files (only relevant on first run ever)
FILENAME=~/.exp_gen/exp_gen.conf
if [ ! -f "$FILENAME" ]; then
first_run_setup
fi
#basic launch block to get this off the ground and help me start improving it:
while test $# -gt 0; do
case $1 in
help|h|-h)
echo "experience generator (exp_gen) help:"
echo "------------"
echo "basic command structure: $ exp [options] [e]"
echo "e = experience to gain (applicable with add|time|timeloop)"
echo "------------"
echo "options:"
echo ""
echo " help | -h | h ------- prints brief help, then exits"
echo " status ------- prints current exp ammount and current level"
echo " add | -a [e] ------- adds [e] ammount of exp immediately"
echo " timer | -t [e] ------- waits (in minutes) then adds [e]"
echo " timeloop | -tl [e] --- waits (in minutes) then adds [e]"
echo " easy_mode ------- sets level cap permanently at 50exp per level"
echo " normal_mode ------- sets level cap back to normal - see readme"
echo " reset_progress ------- sets level and exp back to 0"
echo ""
echo "reading the instructions! Love to see it, have some EXP:"
e=2
exp_gain
echo "earned '$e' exp!"
echo "check how much you have with: $ exp status"
break
;;
add|-a) #example: exp add 5
shift #this drops the word 'add', capturing only the value of 'e' that follows
if test $# -gt 0; then
e="$@"
exp_gain
echo "earned '$e' exp!"
fi
break
;;
timer|-t) #links to the timer command which counts down n minutes and grants EXP.
shift #drops the word time or -t
if test $# -gt 0; then
e="$@"
echo "wait how long before gaining '$e' exp? (in minutes - whole integers only)"
read wait_time
timer
exp_gain
echo "earned '$e' exp!"
fi
break
;;
timeloop|-tl) #links to the timeloop command which gains EXP every n minutes.
shift #drops the word timeloop or -tl
if test $# -gt 0; then
e="$@"
echo "wait how long before gaining '$e' exp? (in minutes - whole integers only)"
echo "this will loop forever until manually stopped with ctrl+c - good for study blocks"
read wait_time
time_loop
fi
break
;;
status) # example: exp level (outputs current tracking, shows nice graphical trace)
status_check
break
;;
reset_progress) #resets all levels and exp back to zero
reset_all
break
;;
easy_mode) #sets the level_CAP at 50XP permanently
echo "level_CAP=50" >> ~/.exp_gen/exp_gen.conf
break
;;
normal_mode) #basically rebuilds ~/.exp_gen/exp_gen.conf minus the level_cap value.
rm ~/.exp_gen/exp_gen.conf
touch ~/.exp_gen/exp_gen.conf
echo "#!/bin/bash" >> ~/.exp_gen/exp_gen.conf
echo "Version=$Version" >> ~/.exp_gen/exp_gen.conf
break
;;
uninstall_exp) #removal block to clear local ~/.exp_gen/*
uninstall
break
;;
*)
echo "try exp help for list of commands"
break
esac
done
#This part of the block is where the system checks for the following and determines if
#it's time to level up or not:
#sources the exp_gen.conf file in case easy-mode was enabled.
# check current EXP ammount:
currentEXP=$(awk '{s+=$1} END {printf "%.0f", s}' ~/.exp_gen/my_exp)
# check progress to next level
next_level #this defines the level_cap based on your current level
source ~/.exp_gen/exp_gen.conf #this includes a value that IF SET, will override next_level
if [ $currentEXP -ge $level_CAP ] #if your current EXP is greater than or equal to the level cap, level up
then
level_up
fi