Guest User

Untitled

a guest
Jul 26th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.67 KB | None | 0 0
  1. function MightyDiamondOfPower()
  2. globalMsg("MIGHTY DIAMOND OF POWER");
  3. end
  4.  
  5. function TriangleOfTrepidation()
  6. globalMsg("TRIANGLE OF TREPIDATION");
  7. end
  8.  
  9.  
  10. function DemonicDiamondOfDoom()
  11. globalMsg("DEMONIC DIAMOND OF DOOM");
  12. end
  13.  
  14.  
  15. function SquareOfSquidward()
  16. globalMsg("SQUARE OF SQUIDWARD");
  17. end
  18.  
  19.  
  20. function HourglassOfIneptitude()
  21. globalMsg("HOURGLASS OF INEPTITUDE");
  22. end
  23.  
  24. function CrossOfCuring()
  25. globalMsg("CROSS OF CURING");
  26. end
  27.  
  28.  
  29. function MaximusJump()
  30. globalMsg("MAXIMUS JUMP");
  31. end
  32.  
  33. --os.time is slow, so 0.1 approximately equals 1 second.
  34. local recharge = 0;
  35. local senseTime = 1;
  36.  
  37. --{nil, nil, {600, 100000}}, {0.1,0.5,0.1},
  38. --Never use a delta in the first step of the rune -- deltas are relative to the last step. Instead, use a rotation sequence of some sort.
  39. local runes = {
  40. --{{90}, {-1,0.3, 0.1}, {180}, {0,0.5,0.1}, {270}, {0.1,0.5,0.1}, {360}, {0.1,0.5,0.1}, {90}, {0.1,0.5,0.1}, MightyDiamondOfPower},
  41. --{{90}, {-1,0.3, 0.1}, {0}, {0,0.5,0.1}, {270}, {0.1,0.5,0.1}, {180}, {0.1,0.5,0.1}, {90}, {0.1,0.5,0.1}, DemonicDiamondOfDoom},
  42. {{90-45}, {-1,0.3, 0.1}, {180-45}, {0,0.5,0.1}, {270-45}, {0,0.5,0.1}, {360-45}, {0,0.5,0.1}, {90-45}, {0,0.5,0.1}, SquareOfSquidward},
  43. --{{270}, {-1,0.3, 0.1}, {30}, {0,1,0.1}, {150}, {0,1,0.1}, {270}, {0,1,0.1}, TriangleOfTrepidation},
  44. --{{90}, {-1,0.3, 0.1}, {270}, {0,0.5,0.1}, {nil, nil, {1000, 100000}}, {0,0.25,0}, MaximusJump},
  45. --{{270}, {-1,0.3, 0.1}, {90}, {0,0.5,0.1}, {nil, nil, {1000, 100000}}, {0,0.25,0}, MaximusJump},
  46. --{{90}, {-1,0.3, 0.1}, {nil, {180-10, 180+10}, {300, 100000}}, {0,0.25,0}, {nil, {315-45, 315+45}, {300, 100000}}, {0,0.5,0}, {nil, {180-45, 180+45}, {300, 100000}},{0,0.5,0}, {nil, {45-45, 45+45}, {300, 100000}}, {0,0.25,0}, HourglassOfIneptitude},
  47. --{{90}, {-1,0.3, 0.1}, {nil, {270-10, 270+10}, {300, 100000}}, {0,0.5,0}, {nil, {90-10, 90+10}, {300, 100000}}, {0,0.5,0}, {nil, {180-45, 180+45}, {300, 100000}} , {0,0.5,0}, {nil, {350, 10}, {300, 100000}} , {0,0.5,0}, {nil, {90-45, 90+45}, {300, 100000}}, {0,0.5,0}, {nil, {270-10, 270+10}, {300, 100000}}, {0,0.5,0}, {nil, {315, 45}, {300, 100000}}, {0,0.5,0},CrossOfCuring},
  48. };
  49. local playerdata = {};
  50.  
  51.  
  52. local mysticmessages =
  53. {
  54. " senses a wayning flow...",
  55. " captures that flow!",
  56. " nurtures their flow into strength...",
  57. "'s flow is strong!",
  58. "'s flow continues to grow!",
  59. " feels their power strengthening incredibly...",
  60. " is approaching their peak...",
  61. "'s power exponentiates!",
  62. " has tapped into deep, dark power!",
  63. };
  64.  
  65.  
  66.  
  67.  
  68.  
  69. function main()
  70. --globalMsg("Hi");
  71. subscribe(Event.PlayerJoined);
  72. subscribe(Event.PlayerLeft);
  73. subscribe(Event.Tick);
  74. end
  75.  
  76. function onTick()
  77. --globalMsg(_VERSION);
  78. DetectPlayers();
  79. local players = GameInfo():getPlayers();
  80. for player in values(players) do
  81. if not player:isRobot() and player:getShip() ~= nil then
  82. ProcessRunes(player);
  83. end
  84. end
  85. end
  86.  
  87.  
  88. function ProcessRunes(playerinfo)
  89. local n = playerinfo:getName();
  90. if (playerdata[n] ~= nil and (os.clock()-playerdata[n]["LastFire"]) > recharge) then
  91. local gprogress = 0;
  92. local status = GetStatus(playerinfo, playerdata[n]["StatusData"]);
  93. local possibilities = playerdata[n]["PossibleRunes"];
  94.  
  95. local i = 1;
  96. local nextTime = playerdata[n]["LastTime"];
  97.  
  98. --Go through the array, and remove items that we are too late for, or too early for
  99. --Then, advance our progress for any items we are ready for.
  100. --We also detect here if we are actually at the end of a rune (the rune is complete)
  101. --If we make it to the end of the rune, we execute that rune.
  102.  
  103. local hasAdvanced = false;
  104. while (true) do
  105. if (i > #possibilities) then break end
  106.  
  107. local prog = possibilities[i][2];
  108. local crune = runes[possibilities[i][1]];
  109.  
  110. --readyForNext
  111. local readyForNext = CheckStatus(status, crune[(prog+1)*2 - 1], playerdata[n]["StatusData"]);
  112. local time = os.clock()-playerdata[n]["LastTime"];
  113. local timing = crune[(prog+1)*2];
  114. if ((time < timing[1] and readyForNext) or (time > timing[2] and not readyForNext)) then --We were too early, or too late, remove this possibility
  115. table.remove(possibilities, i);
  116. i = i - 1;
  117. elseif (readyForNext) then -- We are ready to move on!
  118.  
  119. --Okay, we are in position, but we have to stay in position for a period of time for it to work.
  120. if (not possibilities[i][4]) then
  121. possibilities[i][4] = true;
  122. possibilities[i][3] = os.clock();
  123. else
  124. if ((os.clock() - possibilities[i][3]) > timing[3]) then
  125. possibilities[i][4] = false;
  126. hasAdvanced = true;
  127. possibilities[i][2] = prog+1;
  128. nextTime = os.clock();
  129.  
  130.  
  131.  
  132. playerdata[n]["StatusData"] = WriteStatusData(playerinfo);
  133.  
  134. if ((prog+1)*2 >= #crune-1) then
  135. playerdata[n]["LastFire"] = os.clock();
  136. crune[#crune]();
  137. Reset(n);
  138. return;
  139. end
  140. end
  141. end
  142.  
  143. else
  144. possibilities[i][4] = false;
  145. end
  146. i = i + 1;
  147.  
  148. gprogress = math.max(gprogress, prog);
  149. end
  150.  
  151.  
  152. if (hasAdvanced and ((os.clock() - playerdata[n]["LastSense"]) > senseTime or gprogress ~= 0)) then
  153. if (gprogress == 0) then
  154. playerdata[n]["LastSense"] = os.clock();
  155. end
  156. playerdata[n]["LastWasFail"] = false;
  157. if (gprogress > playerdata[n]["LastProg"] or gprogress == 0) then
  158. if (gprogress == 0) then
  159. AglobalMsg(n .. mysticmessages[gprogress+1]);
  160. end
  161. end
  162. playerdata[n]["LastProg"] = gprogress;
  163. end
  164.  
  165. playerdata[n]["LastTime"] = nextTime;
  166.  
  167.  
  168. --If at this point, there are zero possibilities, we failed. Reset.
  169. if (#possibilities == 0 ) then
  170. if (not playerdata[n]["LastWasFail"] and playerdata[n]["LastProg"] ~= -1) then
  171. playerdata[n]["LastWasFail"] = true;
  172. globalMsg(n .. " failed to act on their flow");
  173. end
  174. Reset(n);
  175. end
  176. end
  177. end
  178.  
  179. --write data needed for status checking, etc.
  180. function WriteStatusData(playerinfo)
  181. local ship = playerinfo:getShip();
  182. return {ship:getLoc()}
  183. end
  184.  
  185.  
  186. function GetStatus(playerinfo, statusdata)
  187. local ship = playerinfo:getShip();
  188. local diff = point.new(0,0);
  189. local ang = 0;
  190.  
  191. if (statusdata ~= nil) then
  192. diff = ship:getLoc()-statusdata[1];
  193. ang = math.deg(point.angleTo(point.new(0,0), diff));
  194. while (ang < 0) do
  195. ang = ang + 360;
  196. end
  197. --globalMsg(ang);
  198. end
  199.  
  200. return {math.deg(ship:getAngle()), ang, diff}
  201. end
  202.  
  203. function CheckStatus(statusa, baseline, laststatus)
  204. --globalMsg("Checking " .. tostring(delta));
  205.  
  206. local diffgood = true;
  207. if (baseline[1] ~= nil) then
  208. local diff = math.abs(statusa[1]-baseline[1]);
  209. while (diff > 180) do diff = math.abs(diff-360); end
  210. diffgood = diff < 20;
  211. end
  212.  
  213. local anglegood = true;
  214. if (baseline[2] ~= nil) then
  215. --logprint(statusa[2]);
  216. anglegood = IsClockwiseTo(statusa[2],baseline[2][1]) and not IsClockwiseTo(statusa[2],baseline[2][2]);
  217. end
  218.  
  219.  
  220. local distancegood = true;
  221. if (baseline[3] ~= nil) then
  222. local dst = point.length(statusa[3]);
  223. distancegood = dst > baseline[3][1] and dst < baseline[3][2];
  224. end
  225.  
  226.  
  227. return diffgood and anglegood and distancegood;
  228. end
  229.  
  230. function IsClockwiseTo(anglea, angleb)
  231. angleb = angleb-anglea;
  232. while (angleb < 0) do angleb = angleb + 360; end
  233. return angleb > 180;
  234. end
  235.  
  236.  
  237. function DetectPlayers()
  238. local players = GameInfo():getPlayers();
  239. for player in values(players) do
  240. if not player:isRobot() then
  241. if (playerdata[player:getName()] == nil) then
  242. onPlayerJoined(player);
  243. end
  244. end
  245. end
  246. end
  247.  
  248. function onPlayerJoined(playerinfo)
  249. globalMsg("Hi"..#runes);
  250. local n = playerinfo:getName();
  251. playerdata[n] = {};
  252. playerdata[n]["StatusData"] = nil;
  253. playerdata[n]["LastSense"] = 0;
  254. playerdata[n]["LastFire"] = 0;
  255. playerdata[n]["LastWasFail"] = false;
  256. playerdata[n]["LastProg"] = -1;
  257. Reset(n);
  258. end
  259.  
  260.  
  261. function Reset(n)
  262. --logprint(tprint(playerdata[n]));
  263. playerdata[n]["StatusData"] = nil;
  264. playerdata[n]["PossibleRunes"] = BlankPossibilities(1, #runes);
  265. playerdata[n]["LastTime"] = os.clock();
  266. end
  267.  
  268. function BlankPossibilities(sstart, send)
  269. local i = sstart;
  270. local k = 1;
  271. local ret = {};
  272. while (true) do
  273. if (i > send) then break end
  274. ret[k] = {i, 0, 0, false};
  275. i = i + 1;
  276. k = k + 1;
  277. end
  278. return ret;
  279. end
  280.  
  281.  
  282. function onPlayerLeft(playerinfo)
  283. playerdata[n] = nil;
  284. end
  285.  
  286.  
  287. function tprint (tbl, indent)
  288. if not indent then indent = 0 end
  289. local str = "";
  290.  
  291. for k, v in pairs(tbl) do
  292. formatting = string.rep(" ", indent) .. k .. ": "
  293. if type(v) == "table" then
  294. str = str.. formatting;
  295. str = str .. tprint(v, indent+1)
  296. else
  297. str = str .. (formatting .. tostring(v));
  298. end
  299. end
  300. return str;
  301. end
Advertisement
Add Comment
Please, Sign In to add comment