Advertisement
ecco7777

poke turtle wireless

Jun 4th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.66 KB | None | 0 0
  1. rednet.open("right")
  2. sides={"top","bottom","back","front","left","right"}
  3. typeEffectiv= {{1,2,1,1,0.5,0.5,0.5,0.5,2,1,1,1,0.5,2,1,0.5,1},{1,0.5,1,1,0.5,1,1,2,1,1,1,1,1,2,1,0.5,1},{1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,0.5,1},{1,1,0.5,0.5,1,1,2,1,0.5,0,1,1,1,1,1,1,2},{0.5,2,1,1,1,1,0.5,0,1,1,2,2,0.5,0.5,2,2,1},{2,1,0.5,1,1,0.5,1,1,2,1,2,1,1,1,0.5,2,0.5},{2,1,1,0.5,2,1,1,1,2,1,1,1,1,1,0.5,0.5,1},{1,0.5,1,1,1,1,1,2,1,1,1,0,1,2,1,0.5,1},{0.5,1,0.5,1,1,0.5,0.5,1,0.5,2,1,1,0.5,1,2,0.5,2},{0.5,1,1,2,1,2,0,1,0.5,1,1,1,2,1,2,2,1},{1,1,2,1,1,0.5,2,1,2,2,0.5,1,1,1,1,0.5,0.5},{1,1,1,1,1,1,1,0,1,1,1,1,1,1,0.5,0.5,1},{1,1,1,1,1,1,1,0.5,2,0.5,1,1,0.5,1,0.5,0,1},{1,0,1,1,2,1,1,1,1,1,1,1,2,0.5,1,0.5,1},{2,1,1,1,0.5,2,2,1,1,0.5,2,1,1,1,1,0.5,1},{1,1,1,0.5,1,0.5,1,1,1,1,2,1,1,1,2,0.5,0.5},{1,1,0.5,1,1,2,1,1,0.5,2,1,1,1,1,2,1,0.5}}
  4.  
  5. pokeData={}
  6. battle={}
  7. for i=1,6 do if peripheral.getType(sides[i]) == "modem" then w=peripheral.wrap(sides[i]) end end
  8. for i=1,6 do if peripheral.getType(sides[i]) == "chat" then c=peripheral.wrap(sides[i]) end end
  9.  
  10.  
  11. function fileToTable(file)
  12. if fs.exists(file)~=true then
  13. print("file"..file.." not found")
  14. return(false)
  15. end
  16. fp=fs.open(file,"r")
  17. line={}
  18. i=1
  19. line[i]=fp.readLine()
  20. if line[i]==nil then return(false) end
  21. while line[i]~=nil do
  22. i=i+1
  23. line[i]=fp.readLine()
  24. end
  25. return(line)
  26. end
  27.  
  28. function resetPokemon()
  29. shell.run("rm myPokemon")
  30. shell.run("rm pokeList")
  31. shell.run("pastebin get 4c40MLFT pokeList")
  32. term.clear()
  33. term.setCursorPos(1,1)
  34. print("avarible Pokemon:")
  35. pokeBase=fileToTable("pokeList")
  36. i=1
  37. while pokeBase[i]~=nil do
  38. print(tostring((i+14)/15).." "..pokeBase[i])
  39. i=i+15
  40. end
  41. fp=fs.open("myPokemon","w")
  42. i=io.read()
  43. i=tonumber((i)-1)*15
  44. pokeData["name"]=pokeBase[i+1]
  45. pokeData["type1"]=pokeBase[i+2]
  46. pokeData["type2"]=pokeBase[i+3]
  47. pokeData["attack1"]=pokeBase[i+4]
  48. pokeData["attack2"]=pokeBase[i+5]
  49. pokeData["attack3"]=pokeBase[i+6]
  50. pokeData["attack4"]=pokeBase[i+7]
  51. pokeData["hpMax"]=tonumber(pokeBase[i+8])
  52. pokeData["hpBase"]=tonumber(pokeBase[i+9])
  53. pokeData["attack"]=tonumber(pokeBase[i+10])
  54. pokeData["defence"]=tonumber(pokeBase[i+11])
  55. pokeData["speed"]=tonumber(pokeBase[i+12])
  56. pokeData["owner"]=pokeBase[i+13]
  57. pokeData["level"]=tonumber(pokeBase[i+14])
  58. pokeData["exp"]=tonumber(pokeBase[i+15])
  59. fp.writeLine(textutils.serialize(pokeData))
  60. fp.close()
  61. end
  62.  
  63. function printStats()
  64. term.clear()
  65. term.setCursorPos(1,1)
  66. print("Name: "..pokeData["name"])
  67. print("Type: "..pokeData["type1"].."/"..pokeData["type2"])
  68. print("HP: "..math.floor(100/pokeData["hpMax"]*pokeData["hpBase"]).."%/100% "..pokeData["hpBase"].."HP/"..pokeData["hpMax"].."HP")
  69. print("Level: "..pokeData["level"])
  70. print("Taste Drücken zum fortfahren")
  71. os.pullEvent("key")
  72. end
  73.  
  74. function getData()
  75. fp=fs.open("myPokemon","r")
  76. pokeData=textutils.unserialize(fp.readLine())
  77. fp.close()
  78. end
  79.  
  80. function saveData()
  81. fp=fs.open("myPokemon","w")
  82. fp.writeLine(textutils.serialize(pokeData))
  83. fp.close()
  84. end
  85.  
  86. if fs.exists("myPokemon")==false then
  87. resetPokemon()
  88. end
  89.  
  90. if fs.exists("attacks")==false then
  91. shell.run("pastebin get cmPKgDsi attacks")
  92. end
  93. shell.run("rm attacks")
  94. shell.run("pastebin get cmPKgDsi attacks")
  95. shell.run("attacks")
  96.  
  97. function attack()
  98. term.clear()
  99. term.setCursorPos(1,1) term.write(battle["pokeData1"]["name"].." "..math.floor(100/battle["pokeData1"]["hpMax"]*battle["pokeData1"]["hpBase"]).."%/100% HP")
  100. term.setCursorPos(1,2) term.write(battle["pokeData2"]["name"].." "..math.floor(100/battle["pokeData2"]["hpMax"]*battle["pokeData2"]["hpBase"]).."%/100% HP")
  101. term.setCursorPos(1,3) term.write("1 "..pokeData["attack1"])
  102. term.setCursorPos(1,4) term.write("2 "..pokeData["attack2"])
  103. term.setCursorPos(1,5) term.write("3 "..pokeData["attack3"])
  104. term.setCursorPos(1,6) term.write("4 "..pokeData["attack4"])
  105. term.setCursorPos(1,7)
  106. action=read()
  107. if action=="1" then battle["attack"..tostring(battleId)]=pokeData["attack1"] end
  108. if action=="2" then battle["attack"..tostring(battleId)]=pokeData["attack2"] end
  109. if action=="3" then battle["attack"..tostring(battleId)]=pokeData["attack3"] end
  110. if action=="4" then battle["attack"..tostring(battleId)]=pokeData["attack4"] end
  111. end
  112.  
  113. function setStats()
  114. if battle["pokeData1"]["speed"]>=battle["pokeData1"]["speed"] then
  115. attacks[battle["attack1"]]()
  116. pokeDataMem=pokeData1
  117. pokeData1=pokeData0
  118. pokeData0=pokeDataMem
  119. attacks[battle["attack0"]]()
  120. pokeDataMem=pokeData1
  121. pokeData1=pokeData0
  122. pokeData0=pokeDataMem
  123. else
  124.  
  125. end
  126. end
  127.  
  128. function fight()
  129. print("Bitte warten")
  130. rednet.broadcast(textutils.serialize(battle))
  131. id, message = rednet.receive()
  132. if textutils.unserialize(message)~=nil then
  133. battle=textutils.unserialize(message)
  134. if battleId==1 then attack() setStats() end
  135. if battleId==0 then  attack() end
  136. end
  137. end
  138.  
  139. function sendRequest()
  140. term.clear()
  141. print("Warte auf Annahme")
  142. battle["pokeData1"]=pokeData
  143. battleId=1
  144. while true do
  145. fight()
  146. end
  147. end
  148.  
  149. function waitForRequest()
  150. term.clear()
  151. print("Warte auf Anfrage")
  152. battleId=0
  153. id, message = rednet.receive()
  154. if textutils.unserialize(message)~=nil then
  155. battle=textutils.unserialize(message)
  156. battle["pokeData2"]=pokeData
  157. if battleId==1 then attack() setStats() end
  158. if battleId==0 then  attack() end
  159. end
  160. while true do
  161. fight()
  162. end
  163. end
  164.  
  165. getData()
  166.  
  167. function menu()
  168. term.clear()
  169. term.setCursorPos(1,3) term.write("1 Kampanfrage senden")
  170. term.setCursorPos(1,4) term.write("2 Auf Kampf anfrage warten")
  171. term.setCursorPos(1,5) term.write("3 Resette Pokemon")
  172. term.setCursorPos(1,6) term.write("4 Pokemon Info")
  173. term.setCursorPos(1,7)
  174. action=read()
  175. if action=="1" then sendRequest() end
  176. if action=="2" then waitForRequest() end
  177. if action=="3" then resetPokemon() end
  178. if action=="4" then printStats() end
  179. end
  180.  
  181. while true do
  182. menu()
  183. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement