Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. echo "Joining game..."
  2. portdata=`nc localhost 3336`
  3. port=`echo $portdata | awk '{print $2;}'`
  4. player=`echo $portdata | awk '{print $1;}'`
  5. p=$((player*9))
  6. echo $USER| nc localhost $port
  7. echo "You are Player $player"
  8. echo "Waiting for your turn..."
  9. stats(){
  10. clear
  11. (printf "Side Player Money Cities Colonies Favor Reserve Engaged XP\n"; \
  12. for ((x=0;x<${#g[@]};x+=9)); do echo; \
  13. echo "$((x/9)) ${g[@]:$x:8}"; done ) | column -t
  14. echo
  15. }
  16. while ((1))
  17. do
  18. gamedata=`nc -l $port`
  19. count=0
  20. for a in $gamedata
  21. do
  22. g[count]=$a
  23. ((count++))
  24. done
  25. g[$((p+1))]=$((g[p+1]+g[p+2]*50*g[p+4]/100+g[p+3]*10*g[p+4]/100))
  26. ((g[p+5]+=g[p+6]))&&((g[p+6]=0))
  27. clear
  28. (printf "${g[p+8]}"; echo "**Press q to start your turn**")| sed s'/_/ /g' | less
  29. g[$((p+8))]="EVENTS:\n"
  30. choice=0
  31. while ((choice!=8))
  32. do
  33. clear
  34. echo "Player $player Your Gold: ${g[$((p+1))]} ****------MAIN MENU------****"
  35. echo "---------------------------------------------------------------"
  36. echo " 1.)Stats"
  37. echo " 2.)Build Colony **COSTS 50g**"
  38. echo " 3.)Build City **COSTS 100g & REQUIRES COLONY**"
  39. echo " 4.)Cloak and Dagger"
  40. echo " 5.)Troop Menu"
  41. echo " 6.)Battle Menu"
  42. echo " 7.)Message"
  43. echo " 8.)End Turn"
  44. echo
  45. echo
  46. read choice
  47. case "$choice" in
  48. "1")
  49. stats
  50. read blank
  51. ;;
  52. "2")
  53. if ((g[$((p+1))]>=50))
  54. then
  55. ((g[$((p+1))]-=50))
  56. ((g[$((p+3))]++))
  57. else
  58. echo "Not enough gold for colony"
  59. sleep 1
  60. fi
  61. ;;
  62. "3")
  63. if ((g[$((p+1))]>=100&&g[$((p+3))]>0))
  64. then
  65. ((g[$((p+1))]-=100))
  66. ((g[$((p+2))]++))
  67. ((g[$((p+3))]--))
  68. else
  69. echo "Not enough gold or you don't have colonies to make city"
  70. sleep 1
  71. fi
  72. ;;
  73. "4")
  74. stats
  75. echo "Enter target (Side):"
  76. read target
  77. clear
  78. echo "Target: $target Your Gold: ${g[$((p+1))]} ****------CLOAK AND DAGGER------****"
  79. echo "---------------------------------------------------------------"
  80. echo "1.) KILL POLITICAL ENEMIES - 50g +3 FAVOR"
  81. echo "2.) ASSASSINATE FAMILY MEMBER- 50g -3 FAVOR"
  82. echo "3.) SET PALACE ON FIRE -100g -6 FAVOR"
  83. echo "4.) CANCEL"
  84. echo
  85. echo "Assassin: What is your bidding, my master?"
  86. read option
  87. case "$option" in
  88. "1")
  89. if((g[$((p+1))]>=50))
  90. then
  91. echo "Assassin: Excellent choice."
  92. sleep 1
  93. ((g[$((p+1))]-=50))
  94. ((g[$((target*9+4))]+=3))
  95. g[$((target*9+8))]="${g[$((target*9+8))]}Your_enemies_have_been_killed_by_$USER._+3_FAVOR\n"
  96. else
  97. echo "Assassin: Sadly I do not operate in the absence of funds."
  98. sleep 1
  99. fi
  100. ;;
  101. "2")
  102. if((g[$((p+1))]>=50))
  103. then
  104. echo "Assassin: Excellent choice."
  105. sleep 1
  106. ((g[$((p+1))]-=50))
  107. ((g[$((target*9+4))]-=3))
  108. g[$((target*9+8))]="${g[$((target*9+8))]}Your_family_has_been_murdered_by_$USER._-3_FAVOR\n"
  109. else
  110. echo "Assassin: Sadly I do not operate in the absence of funds."
  111. sleep 1
  112. fi
  113. ;;
  114. "3")
  115. if((g[$((p+1))]>=100))
  116. then
  117. echo "Assassin: Excellent choice."
  118. sleep 1
  119. ((g[$((p+1))]-=100))
  120. ((g[$((target*9+4))]-=6))
  121. g[$((target*9+8))]="${g[$((target*9+8))]}Your_palace_has_been_murdered_by_$USER._-6_FAVOR\n"
  122. else
  123. echo "Assassin: Sadly I do not operate in the absence of funds."
  124. sleep 1
  125. fi
  126. ;;
  127. esac
  128. ;;
  129. "5")
  130. clear
  131. echo "Player $player Your Gold: ${g[$((p+1))]} Reserve: ${g[$((p+5))]} ****------TROOP MENU------****"
  132. echo "---------------------------------------------------------------"
  133. echo " 1.)Build Troops **COSTS 1g**"
  134. echo " 2.)Train Troops **Makes them Engaged**"
  135. echo " 3.)Cancel"
  136. echo
  137. echo
  138. read tchoice
  139. case "$tchoice" in
  140. "1")
  141. echo "How many?"
  142. read tnumber
  143. if((tnumber<=g[$((p+1))]))
  144. then
  145. ((g[$((p+1))]-=tnumber))
  146. ((g[$((p+5))]+=tnumber))
  147. ((g[$((p+7))]-=tnumber*25/(g[$((p+6))]+g[$((p+5))])))
  148. (((g[$((p+7))]<0)&&(g[$((p+7))]=0)))
  149. echo "$tnumber Troops Drafted"
  150. echo "XP: ${g[$((p+7))]}"
  151. sleep 1
  152. else
  153. echo "You don't have enough gold."
  154. fi
  155. ;;
  156. "2")
  157. echo "How many?"
  158. read tnumber
  159. if((tnumber<=g[$((p+5))]))
  160. then
  161. ((g[$((p+5))]-=tnumber))
  162. ((g[$((p+6))]+=tnumber))
  163. ((g[$((p+7))]+=tnumber*50/(g[$((p+6))]+g[$((p+5))])))
  164. (((g[$((p+7))]>100)&&(g[$((p+7))]=100)))
  165. echo "$tnumber Troops Trained"
  166. echo "XP: ${g[$((p+7))]}"
  167. sleep 1
  168. else
  169. echo "You don't have enough troops."
  170. fi
  171. ;;
  172. esac
  173. ;;
  174. "6")
  175. stats
  176. echo "Enter target (Side):"
  177. read target
  178. t=$((target*9))
  179. clear
  180. echo "Player $player Reserve: ${g[$((p+5))]} ****------BATTLE MENU------****"
  181. echo "---------------------------------------------------------------"
  182. echo " 1.)CONQUER **(Very hard if there are still cities)**"
  183. ((g[$((t+2))]>0)) && echo " 2.)CAPTURE CITY **(There is a +100 troop bonus to defenders)**"
  184.  
  185. ((g[$((t+3))]>0)) && echo " 3.)RAID COLONY **(50% Enemy Defensive Strength)**"
  186. echo
  187. echo
  188. read bchoice
  189. case "$bchoice" in
  190. "2")
  191. echo "How many troops?"
  192. read bnum
  193. if((bnum<=g[$((p+5))]))
  194. then
  195. aforce=$((bnum*g[p+4]/100+bnum*g[p+7]/100))
  196. dnum=$((aforce*100/(g[t+4]+g[t+7])))
  197. dif=$((g[t+5]-dnum))
  198. ((dif<0))&&((dnum+=dif))
  199. dforce=$(((dnum+100)*g[t+4]/100+(dnum+100)*g[t+7]/100))
  200. battle=$((aforce-dforce))
  201. dk=$dnum
  202. ak=$bnum
  203. if((battle>0))
  204. then
  205. ak=$((bnum-(battle*100/(g[t+4]+g[t+7]))))
  206. echo "You captured ${g[t]}'s city."
  207. echo "+5 Favor"
  208. ((g[t+2]--))
  209. ((g[p+2]++))
  210. ((g[p+4]+=5))
  211. ((g[p+7]+=10))
  212. (((g[p+7]+10)<=100))&&((g[p+7]=100))
  213. echo "XP=${g[$((p+7))]}"
  214. elif((battle<0))
  215. then
  216. dk=$((dnum+(battle*100/(g[t+4]+g[t+7]))))
  217. echo "You Lost"
  218. fi
  219. ((g[p+5]-=bnum))
  220. ((g[p+6]+=(bnum-ak)))
  221. ((g[t+5]-=dnum))
  222. ((g[t+6]+=(dnum-dk)))
  223.  
  224. g[$((t+8))]="${g[$((t+8))]}Your_city_has_been_attacked_by_$USER!\nAttackers:_${bnum}_KIA:_${ak}\nDefenders:_${dnum}_KIA:_${dk}\n"
  225. sleep 1
  226. else
  227. echo "You don't have that many troops"
  228. fi
  229. ;;
  230. "3")
  231. echo "How many troops?"
  232. read bnum
  233. if((bnum<=g[$((p+5))]))
  234. then
  235. aforce=$((bnum*g[p+4]/100+bnum*g[p+7]/100))
  236. dnum=$((aforce*100/(g[t+4]+g[t+7])+50))
  237. dif=$((g[t+5]/2-dnum))
  238. ((dif<0))&&((dnum+=dif))
  239. dforce=$((dnum*g[t+4]/100+dnum*g[t+7]/100))
  240. battle=$((aforce-dforce))
  241. dk=$dnum
  242. ak=$bnum
  243. if((battle>0))
  244. then
  245. ak=$((bnum-(battle*100/(g[t+4]+g[t+7]))))
  246. echo "You destroyed ${g[t]}'s colony."
  247. echo "+2 Favor"
  248. ((g[t+3]--))
  249. ((g[p+4]+=2))
  250. ((g[p+7]+=5))
  251. (((g[p+7]+5)<=100))&&((g[p+7]=100))
  252. echo "XP=${g[$((p+7))]}"
  253. elif((battle<0))
  254. then
  255. dk=$((dnum+(battle*100/(g[t+4]+g[t+7]))))
  256. echo "You Lost"
  257. fi
  258. ((g[p+5]-=bnum))
  259. ((g[p+6]+=(bnum-ak)))
  260. ((g[t+5]-=dnum))
  261. ((g[t+6]+=(dnum-dk)))
  262.  
  263. g[$((t+8))]="${g[$((t+8))]}Your_colony_has_been_attacked_by_$USER!\nAttackers:_${bnum}_KIA:_${ak}\nDefenders:_${dnum}_KIA:_${dk}\n"
  264. sleep 1
  265. else
  266. echo "You don't have that many troops"
  267. fi
  268. ;;
  269. esac
  270.  
  271. esac
  272.  
  273. done
  274. echo ${g[@]} | nc localhost $port
  275. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement