Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.08 KB | None | 0 0
  1.  
  2.  
  3. //Javascript widget for Moongates. Last edit 2008-03-24 22:26
  4.  
  5. //Author: Kakurady
  6.  
  7. //星月门脚本。最后更新 2008-03-24 22:26
  8.  
  9. //作者: 卡库拉迪
  10.  
  11.  
  12.  
  13. var date; //current time
  14.  
  15. var timePerErinnHour = 90000; //1 min 30 s
  16.  
  17. var timePerErinnMinute = 1500; //1.5 s
  18.  
  19. var timePerErinnDay = 2160000; //36 min
  20.  
  21.  
  22.  
  23. var serverTime; //current timeof server since unix epoch
  24.  
  25. var serverDate; //for display of server time only
  26.  
  27.  
  28.  
  29. var erinnDay;
  30.  
  31. var erinnHour;
  32.  
  33. var erinnMinute;
  34.  
  35. var i; // iterator for moongate labels
  36.  
  37. var nGatesShown = 6;
  38.  
  39. var nGatesChanged = false;
  40.  
  41. var nPryceShown = 2;
  42.  
  43. var nPryceChanged = false;
  44.  
  45. var nRuaShown = 2;
  46.  
  47. var nRuaChanged = false;
  48.  
  49.  
  50.  
  51. var moongateTime; // a number
  52.  
  53. var moongateDate; // a Date
  54.  
  55.  
  56.  
  57. var moonGate;
  58.  
  59. var lastmoonGate;
  60.  
  61. var pryce;
  62.  
  63. var lastPryce;
  64.  
  65. var rua;
  66.  
  67. var lastRua;
  68.  
  69.  
  70.  
  71. ///server-specific code for: NA(G10)
  72.  
  73.  
  74.  
  75. //This value should be modified with regards to DST
  76.  
  77. var serverOffset = -7 * 60 * 60 * 1000 - (60 * 1000 * 60); //GMT - 7
  78.  
  79. var moonGateEpoch = Date.parse("Mar 23, 2008 22:21:00 GMT");
  80.  
  81. var pryceEpoch = Date.parse("Mar 24, 2008 00:00:00 GMT");
  82.  
  83. //List of Moongate locations
  84.  
  85. var moonGateList = [
  86.  
  87. 5, 6, 0, 4, 3, 5, 1, 7, 2, 3, 5, 0,
  88.  
  89. 4, 6, 3, 5, 2, 1, 7, 5, 4, 0, 1, 2];
  90.  
  91.  
  92.  
  93. var pryceList = [0,1,2,3,4,5,6,7,8,9,10,11,12,1];
  94.  
  95. var ruaList = [0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,0,1,1,1,0,0,0,0,0,0,0,1,0,1,0,0,1,0,0,0,1,0,0,0,1,0,0,1];
  96.  
  97. ///End server-specific code
  98.  
  99. ///Language-specific code for: en
  100.  
  101.  
  102.  
  103. var msg = [
  104.  
  105. 'Tir Chonaill', 'Dunbarton', 'Bangor', 'Emain Macha',
  106.  
  107. 'Taillteann', "Tara", 'Ceo', 'Port Ceann'
  108.  
  109. ];
  110.  
  111. var pmsg = [
  112.  
  113. 'Outside Tir Chonaill Inn',
  114.  
  115. 'Dugald Aisle Logging Camp Hut',
  116.  
  117. 'Dunbarton East Potato Field',
  118.  
  119. 'Dragon Ruins - House at 5`o clock ',
  120.  
  121. 'Bangor Bar',
  122.  
  123. 'Sen Mag 5th house from West',
  124.  
  125. 'Emain Macha - Alley Behind Weapon Shop',
  126.  
  127. 'Ceo island',
  128.  
  129. 'Emain Macha - Island in South Pathway',
  130.  
  131. 'Sen Mag 5th house from West',
  132.  
  133. 'Dragon Ruins - House at 5`o clock',
  134.  
  135. 'Outside Barri Dungeon',
  136.  
  137. 'Dunbarton School Stairway'
  138.  
  139. ];
  140.  
  141.  
  142.  
  143. var rmsg = [
  144.  
  145. 'Resting',
  146.  
  147. 'Working'
  148.  
  149. ];
  150.  
  151.  
  152.  
  153. var day=" day";
  154.  
  155. var days=" days";
  156.  
  157.  
  158.  
  159. var today="Today";
  160.  
  161. var next="Next";
  162.  
  163.  
  164.  
  165. ///End Language-specific code
  166.  
  167.  
  168.  
  169. function doSomething(){
  170.  
  171. date = new Date();
  172.  
  173.  
  174.  
  175. //add the offset (in milliseconds) to UTC to get server time
  176.  
  177. serverTime = date.getTime() + serverOffset;
  178.  
  179.  
  180.  
  181. //game time
  182.  
  183. erinnHour = Math.floor(serverTime / timePerErinnHour) % 24;
  184.  
  185. erinnMinute = Math.floor(serverTime / timePerErinnMinute) % 60;
  186.  
  187.  
  188.  
  189. //erinnDay = Math.floor(serverTime / timePerErinnDay) % 40;
  190.  
  191.  
  192.  
  193. //moongate target
  194.  
  195. moonGate = Math.floor(
  196.  
  197. (serverTime - moonGateEpoch) / timePerErinnDay % moonGateList.length
  198.  
  199. ); if (moonGate < 0){moonGate += moonGateList.length;};
  200.  
  201. pryce = Math.floor(
  202.  
  203. (serverTime - pryceEpoch) / timePerErinnDay % pryceList.length
  204.  
  205. ); if (pryce < 0){pryce += pryceList.length;};
  206.  
  207. rua = Math.floor(
  208.  
  209. (serverTime - moonGateEpoch) / timePerErinnDay % ruaList.length
  210.  
  211. ); if (rua < 0){rua += ruaList.length;};
  212.  
  213.  
  214.  
  215. //convert the milliseconds back to Date for easy displaying
  216.  
  217. serverDate = new Date(serverTime);
  218.  
  219.  
  220.  
  221.  
  222.  
  223. //access the document
  224.  
  225. //textContent is not supported by IE 7
  226.  
  227. document.getElementById("tGameTime").firstChild.nodeValue = erinnHour + ((erinnMinute < 10)?":0":":") + erinnMinute ;
  228.  
  229. document.getElementById("trealtime1").firstChild.nodeValue = date.getHours() + ((date.getMinutes() < 10)?":0":":") + date.getMinutes();
  230.  
  231. document.getElementById("trealtime2").firstChild.nodeValue = serverDate.getUTCHours() + ((serverDate.getUTCMinutes() < 10)?":0":":") + serverDate.getUTCMinutes();
  232.  
  233. // document.getElementById("date").firstChild.nodeValue = "Day "+ erinnDay;
  234.  
  235.  
  236.  
  237. //TODO: adjust how many moongate we have easier
  238.  
  239. //TODO: No need to parse the gates each time this runs.
  240.  
  241. if(nGatesChanged || moonGate != lastmoonGate){
  242.  
  243.  
  244.  
  245. moongateTime = serverTime - Math.floor(serverTime % timePerErinnDay); //the server time for the current Erinn day's midnight
  246.  
  247. moongateTime += (
  248.  
  249. (erinnHour < 6)? //yesterday's gate?
  250.  
  251. -6*timePerErinnHour :
  252.  
  253. 18*timePerErinnHour)
  254.  
  255. - serverOffset; // so it's UTC again
  256.  
  257.  
  258.  
  259. for(i=0; i < nGatesShown ; moongateTime += timePerErinnDay, i++){
  260.  
  261. moongateDate = new Date(moongateTime); // so as not to worry about converting dates!
  262.  
  263.  
  264.  
  265. //Moongate Time
  266.  
  267. document.getElementById("mgtm"+i).firstChild.nodeValue = moongateDate.getHours() + ((moongateDate.getMinutes() < 10)?":0":":") + moongateDate.getMinutes();
  268.  
  269. //Moongate Destination
  270.  
  271. document.getElementById("mgtxt"+i).firstChild.nodeValue = msg[moonGateList[(moonGate + i) % moonGateList.length]];
  272.  
  273. }
  274.  
  275. for(i=0; i<moonGateList.length; i++){
  276.  
  277. if (moonGateList[(moonGate + i) % moonGateList.length] == 6){ // ceo
  278.  
  279. document.getElementById("mgtxtceo").firstChild.nodeValue = i + ((i==1)?day: days);
  280.  
  281. break;
  282.  
  283. }
  284.  
  285. }
  286.  
  287.  
  288.  
  289. lastmoonGate = moonGate;
  290.  
  291. nGatesChanged = false;
  292.  
  293. }
  294.  
  295. if(nPryceChanged|| pryce != lastPryce){
  296.  
  297.  
  298.  
  299. moongateTime = serverTime - Math.floor(serverTime % timePerErinnDay); //the server time for the current Erinn day's midnight
  300.  
  301. moongateTime -= serverOffset;
  302.  
  303.  
  304.  
  305. for(i=0; i < nPryceShown ; moongateTime += timePerErinnDay, i++){
  306.  
  307. moongateDate = new Date(moongateTime); // so as not to worry about converting dates!
  308.  
  309.  
  310.  
  311. //Moongate Time
  312.  
  313. document.getElementById("prtm"+i).firstChild.nodeValue = moongateDate.getHours() + ((moongateDate.getMinutes() < 10)?":0":":") + moongateDate.getMinutes();
  314.  
  315. //Moongate Destination
  316.  
  317. document.getElementById("prtxt"+i).firstChild.nodeValue = pmsg[pryceList[(pryce + i) % pryceList.length]];
  318.  
  319. }
  320.  
  321. lastPryce = pryce;
  322.  
  323. nPryceChanged = false;
  324.  
  325. }
  326.  
  327. //setContent(s, d.getTime());
  328.  
  329.  
  330.  
  331. if(nRuaChanged|| rua != lastRua){
  332.  
  333.  
  334.  
  335. moongateTime = serverTime - Math.floor(serverTime % timePerErinnDay); //the server time for the current Erinn day's midnight
  336.  
  337. moongateTime += (
  338.  
  339. (erinnHour < 6)? //yesterday's gate?
  340.  
  341. -6*timePerErinnHour :
  342.  
  343. 18*timePerErinnHour)
  344.  
  345. - serverOffset; // so it's UTC again
  346.  
  347.  
  348.  
  349. for(i=0; i < nRuaShown; moongateTime += timePerErinnDay, i++){
  350.  
  351.  
  352.  
  353. moongateDate = new Date(moongateTime); // so as not to worry about converting dates!
  354.  
  355.  
  356.  
  357. //Rua Time
  358.  
  359. document.getElementById("ruatm"+i).firstChild.nodeValue = moongateDate.getHours() + ((moongateDate.getMinutes() < 10)?":0":":") + moongateDate.getMinutes();
  360.  
  361. //Rua Status
  362.  
  363. document.getElementById("ruatxt"+i).firstChild.nodeValue = rmsg[ruaList[(rua + i) % ruaList.length]];
  364.  
  365. }
  366.  
  367. lastRua = rua;
  368.  
  369. nRuaChanged = false;
  370.  
  371. }
  372.  
  373. }
  374.  
  375.  
  376.  
  377. function addRow(myTop, myPrefix){
  378.  
  379. var myRow; var myCell1; var myCell2; var myCell3;
  380.  
  381. var myShown;
  382.  
  383. switch (myPrefix){
  384.  
  385. case "mg":myShown = nGatesShown; break;
  386.  
  387. case "pr":myShown = nPryceShown; break;
  388.  
  389. case "rua":myShown = nRuaShown; break;
  390.  
  391. default:
  392.  
  393. }
  394.  
  395. myRow = document.createElement("TR");
  396.  
  397. myRow.id=myPrefix+"Row"+myShown;
  398.  
  399. myRow.className="mgrow";
  400.  
  401. //myCell1 = document.createElement("TD");
  402.  
  403. //myCell1.id=myPrefix+"lbl"+myShown;
  404.  
  405. //myCell1.className="mglabel";
  406.  
  407. myCell2 = document.createElement("TD");
  408.  
  409. myCell2.id=myPrefix+"tm"+myShown;
  410.  
  411. myCell2.className="mglabel2";
  412.  
  413. myCell3 = document.createElement("TD");
  414.  
  415. myCell3.id=myPrefix+"txt"+myShown;
  416.  
  417. myCell3.className="mgtext";
  418.  
  419.  
  420.  
  421. //myCell1.appendChild( document.createTextNode("in " + myShown + " days") );
  422.  
  423. myCell2.appendChild( document.createTextNode("one") );
  424.  
  425. myCell3.appendChild( document.createTextNode("moment...") );
  426.  
  427. //myRow.appendChild(myCell1);
  428.  
  429. myRow.appendChild(myCell2);
  430.  
  431. myRow.appendChild(myCell3);
  432.  
  433.  
  434.  
  435. document.getElementById(myTop).appendChild(myRow);
  436.  
  437. switch (myPrefix){
  438.  
  439. case "mg":
  440.  
  441. nGatesShown++;
  442.  
  443. nGatesChanged = true; break;
  444.  
  445. case "pr":
  446.  
  447. nPryceShown++;
  448.  
  449. nPryceChanged = true; break;
  450.  
  451. case "rua":
  452.  
  453. nRuaShown++;
  454.  
  455. nRuaChanged = true; break;
  456.  
  457. default:
  458.  
  459. }
  460.  
  461. doSomething();
  462.  
  463. }
  464.  
  465. function removeRow(){
  466.  
  467. //TODO:Check if rows can be removed
  468.  
  469. var myRow;
  470.  
  471.  
  472.  
  473. if (nGatesShown > 2){
  474.  
  475. nGatesShown--;
  476.  
  477. myRow = document.getElementById("mgRow"+nGatesShown);
  478.  
  479. document.getElementById("mgtblbody0").removeChild(myRow);
  480.  
  481. nGatesChanged = true;
  482.  
  483. }
  484.  
  485. }
  486.  
  487. function removeRow1(){
  488.  
  489. //TODO:Check if rows can be removed
  490.  
  491. var myRow;
  492.  
  493.  
  494.  
  495. if (nPryceShown > 2){
  496.  
  497. nPryceShown--;
  498.  
  499. myRow = document.getElementById("prRow"+nPryceShown);
  500.  
  501. document.getElementById("prtblbody0").removeChild(myRow);
  502.  
  503. nPryceChanged = true;
  504.  
  505. }
  506.  
  507. }
  508.  
  509.  
  510.  
  511. function removeRow2(){
  512.  
  513. //TODO:Check if rows can be removed
  514.  
  515. var myRow;
  516.  
  517.  
  518.  
  519. if (nRuaShown > 2){
  520.  
  521. nRuaShown--;
  522.  
  523. myRow = document.getElementById("ruaRow"+nRuaShown);
  524.  
  525. document.getElementById("ruatblbody0").removeChild(myRow);
  526.  
  527. nRuaChanged = true;
  528.  
  529. }
  530.  
  531. }
  532.  
  533.  
  534.  
  535. window.setInterval(doSomething, 200);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement