Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function MightyDiamondOfPower()
- globalMsg("MIGHTY DIAMOND OF POWER");
- end
- function TriangleOfTrepidation()
- globalMsg("TRIANGLE OF TREPIDATION");
- end
- function DemonicDiamondOfDoom()
- globalMsg("DEMONIC DIAMOND OF DOOM");
- end
- function SquareOfSquidward()
- globalMsg("SQUARE OF SQUIDWARD");
- end
- function HourglassOfIneptitude()
- globalMsg("HOURGLASS OF INEPTITUDE");
- end
- function CrossOfCuring()
- globalMsg("CROSS OF CURING");
- end
- function MaximusJump()
- globalMsg("MAXIMUS JUMP");
- end
- --os.time is slow, so 0.1 approximately equals 1 second.
- local recharge = 0;
- local senseTime = 1;
- --{nil, nil, {600, 100000}}, {0.1,0.5,0.1},
- --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.
- local runes = {
- --{{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},
- --{{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},
- {{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},
- --{{270}, {-1,0.3, 0.1}, {30}, {0,1,0.1}, {150}, {0,1,0.1}, {270}, {0,1,0.1}, TriangleOfTrepidation},
- --{{90}, {-1,0.3, 0.1}, {270}, {0,0.5,0.1}, {nil, nil, {1000, 100000}}, {0,0.25,0}, MaximusJump},
- --{{270}, {-1,0.3, 0.1}, {90}, {0,0.5,0.1}, {nil, nil, {1000, 100000}}, {0,0.25,0}, MaximusJump},
- --{{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},
- --{{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},
- };
- local playerdata = {};
- local mysticmessages =
- {
- " senses a wayning flow...",
- " captures that flow!",
- " nurtures their flow into strength...",
- "'s flow is strong!",
- "'s flow continues to grow!",
- " feels their power strengthening incredibly...",
- " is approaching their peak...",
- "'s power exponentiates!",
- " has tapped into deep, dark power!",
- };
- function main()
- --globalMsg("Hi");
- subscribe(Event.PlayerJoined);
- subscribe(Event.PlayerLeft);
- subscribe(Event.Tick);
- end
- function onTick()
- --globalMsg(_VERSION);
- DetectPlayers();
- local players = GameInfo():getPlayers();
- for player in values(players) do
- if not player:isRobot() and player:getShip() ~= nil then
- ProcessRunes(player);
- end
- end
- end
- function ProcessRunes(playerinfo)
- local n = playerinfo:getName();
- if (playerdata[n] ~= nil and (os.clock()-playerdata[n]["LastFire"]) > recharge) then
- local gprogress = 0;
- local status = GetStatus(playerinfo, playerdata[n]["StatusData"]);
- local possibilities = playerdata[n]["PossibleRunes"];
- local i = 1;
- local nextTime = playerdata[n]["LastTime"];
- --Go through the array, and remove items that we are too late for, or too early for
- --Then, advance our progress for any items we are ready for.
- --We also detect here if we are actually at the end of a rune (the rune is complete)
- --If we make it to the end of the rune, we execute that rune.
- local hasAdvanced = false;
- while (true) do
- if (i > #possibilities) then break end
- local prog = possibilities[i][2];
- local crune = runes[possibilities[i][1]];
- --readyForNext
- local readyForNext = CheckStatus(status, crune[(prog+1)*2 - 1], playerdata[n]["StatusData"]);
- local time = os.clock()-playerdata[n]["LastTime"];
- local timing = crune[(prog+1)*2];
- if ((time < timing[1] and readyForNext) or (time > timing[2] and not readyForNext)) then --We were too early, or too late, remove this possibility
- table.remove(possibilities, i);
- i = i - 1;
- elseif (readyForNext) then -- We are ready to move on!
- --Okay, we are in position, but we have to stay in position for a period of time for it to work.
- if (not possibilities[i][4]) then
- possibilities[i][4] = true;
- possibilities[i][3] = os.clock();
- else
- if ((os.clock() - possibilities[i][3]) > timing[3]) then
- possibilities[i][4] = false;
- hasAdvanced = true;
- possibilities[i][2] = prog+1;
- nextTime = os.clock();
- playerdata[n]["StatusData"] = WriteStatusData(playerinfo);
- if ((prog+1)*2 >= #crune-1) then
- playerdata[n]["LastFire"] = os.clock();
- crune[#crune]();
- Reset(n);
- return;
- end
- end
- end
- else
- possibilities[i][4] = false;
- end
- i = i + 1;
- gprogress = math.max(gprogress, prog);
- end
- if (hasAdvanced and ((os.clock() - playerdata[n]["LastSense"]) > senseTime or gprogress ~= 0)) then
- if (gprogress == 0) then
- playerdata[n]["LastSense"] = os.clock();
- end
- playerdata[n]["LastWasFail"] = false;
- if (gprogress > playerdata[n]["LastProg"] or gprogress == 0) then
- if (gprogress == 0) then
- AglobalMsg(n .. mysticmessages[gprogress+1]);
- end
- end
- playerdata[n]["LastProg"] = gprogress;
- end
- playerdata[n]["LastTime"] = nextTime;
- --If at this point, there are zero possibilities, we failed. Reset.
- if (#possibilities == 0 ) then
- if (not playerdata[n]["LastWasFail"] and playerdata[n]["LastProg"] ~= -1) then
- playerdata[n]["LastWasFail"] = true;
- globalMsg(n .. " failed to act on their flow");
- end
- Reset(n);
- end
- end
- end
- --write data needed for status checking, etc.
- function WriteStatusData(playerinfo)
- local ship = playerinfo:getShip();
- return {ship:getLoc()}
- end
- function GetStatus(playerinfo, statusdata)
- local ship = playerinfo:getShip();
- local diff = point.new(0,0);
- local ang = 0;
- if (statusdata ~= nil) then
- diff = ship:getLoc()-statusdata[1];
- ang = math.deg(point.angleTo(point.new(0,0), diff));
- while (ang < 0) do
- ang = ang + 360;
- end
- --globalMsg(ang);
- end
- return {math.deg(ship:getAngle()), ang, diff}
- end
- function CheckStatus(statusa, baseline, laststatus)
- --globalMsg("Checking " .. tostring(delta));
- local diffgood = true;
- if (baseline[1] ~= nil) then
- local diff = math.abs(statusa[1]-baseline[1]);
- while (diff > 180) do diff = math.abs(diff-360); end
- diffgood = diff < 20;
- end
- local anglegood = true;
- if (baseline[2] ~= nil) then
- --logprint(statusa[2]);
- anglegood = IsClockwiseTo(statusa[2],baseline[2][1]) and not IsClockwiseTo(statusa[2],baseline[2][2]);
- end
- local distancegood = true;
- if (baseline[3] ~= nil) then
- local dst = point.length(statusa[3]);
- distancegood = dst > baseline[3][1] and dst < baseline[3][2];
- end
- return diffgood and anglegood and distancegood;
- end
- function IsClockwiseTo(anglea, angleb)
- angleb = angleb-anglea;
- while (angleb < 0) do angleb = angleb + 360; end
- return angleb > 180;
- end
- function DetectPlayers()
- local players = GameInfo():getPlayers();
- for player in values(players) do
- if not player:isRobot() then
- if (playerdata[player:getName()] == nil) then
- onPlayerJoined(player);
- end
- end
- end
- end
- function onPlayerJoined(playerinfo)
- globalMsg("Hi"..#runes);
- local n = playerinfo:getName();
- playerdata[n] = {};
- playerdata[n]["StatusData"] = nil;
- playerdata[n]["LastSense"] = 0;
- playerdata[n]["LastFire"] = 0;
- playerdata[n]["LastWasFail"] = false;
- playerdata[n]["LastProg"] = -1;
- Reset(n);
- end
- function Reset(n)
- --logprint(tprint(playerdata[n]));
- playerdata[n]["StatusData"] = nil;
- playerdata[n]["PossibleRunes"] = BlankPossibilities(1, #runes);
- playerdata[n]["LastTime"] = os.clock();
- end
- function BlankPossibilities(sstart, send)
- local i = sstart;
- local k = 1;
- local ret = {};
- while (true) do
- if (i > send) then break end
- ret[k] = {i, 0, 0, false};
- i = i + 1;
- k = k + 1;
- end
- return ret;
- end
- function onPlayerLeft(playerinfo)
- playerdata[n] = nil;
- end
- function tprint (tbl, indent)
- if not indent then indent = 0 end
- local str = "";
- for k, v in pairs(tbl) do
- formatting = string.rep(" ", indent) .. k .. ": "
- if type(v) == "table" then
- str = str.. formatting;
- str = str .. tprint(v, indent+1)
- else
- str = str .. (formatting .. tostring(v));
- end
- end
- return str;
- end
Advertisement
Add Comment
Please, Sign In to add comment