Extra Statistics

Generate additional statistical data in the dungeon and duel report pages

  1. //-----------------------------------------------------------------------------
  2. // [WoD] Extra Statistics
  3. // Version 1.20, 2010-04-15
  4. // Copyright (c) Fenghou, Tomy
  5. // This script can generate additional statistical data in the dungeon and duel report pages.
  6. // When you entered the details or statistics page of reports, a new button will appear beside
  7. // the details button. At the details page, the new button is "Extra Stat", which will show
  8. // the statistics of the current level when you click it. At the statistics page, the new
  9. // button is "Entire Extra Stat", which will show the statistics of entire dungeon.
  10. //-----------------------------------------------------------------------------
  11.  
  12. //-----------------------------------------------------------------------------
  13. // If you want to add a new Stat table, you should create a new sub class of CInfoList,
  14. // and use CStat::RegInfoList() to register your new info list.
  15. // A detailed example is CILItemDamage.
  16. //-----------------------------------------------------------------------------
  17.  
  18. // ==UserScript==
  19. // @name Extra Statistics
  20. // @namespace fenghou
  21. // @version 1.20
  22. // @description Generate additional statistical data in the dungeon and duel report pages
  23. // @include http*://*.world-of-dungeons.*/wod/spiel/*dungeon/report.php*
  24. // @include http*://*.world-of-dungeons.*/wod/spiel/tournament/*duell.php*
  25. // @include file:///*f1.htm
  26. // ==/UserScript==
  27.  
  28.  
  29. // COMMON FUNCTIONS ///////////////////////////////////////////////////////////
  30.  
  31. function $(id) {return document.getElementById(id);}
  32.  
  33.  
  34. // Choose contents of the corresponding language
  35. // Contents: {Name1 : [lang1, lang2, ...], Name2 : [lang1, lang2, ...], ...}
  36. // return: Local contents, or null
  37. // It will edit the input contents directly, so the returned object is not necessary
  38. function GetLocalContents(Contents)
  39. {
  40. function GetLanguageId()
  41. {
  42. var langText = null;
  43. var allMetas = document.getElementsByTagName("meta");
  44. for (var i = 0; i < allMetas.length; ++i)
  45. {
  46. if (allMetas[i].httpEquiv == "Content-Language")
  47. {
  48. langText = allMetas[i].content;
  49. break;
  50. }
  51. }
  52. if (langText == null)
  53. return false;
  54.  
  55. switch (langText)
  56. {
  57. case "en":
  58. return 0;
  59. case "cn":
  60. return 1;
  61. default:
  62. return null;
  63. }
  64. }
  65.  
  66. var nLangId = GetLanguageId();
  67. if (nLangId == null)
  68. return null;
  69.  
  70. if (Contents instanceof Object)
  71. {
  72. for (var name in Contents)
  73. Contents[name] = Contents[name][nLangId];
  74. return Contents;
  75. }
  76. else
  77. return null;
  78. }
  79.  
  80.  
  81. function CompareString(a, b)
  82. {
  83. a = a || "";
  84. b = b || "";
  85. return a.toLowerCase().localeCompare( b.toLowerCase() );
  86. }
  87.  
  88.  
  89. function CreateElementHTML(Name, Content /* , [AttrName1, AttrValue1], [AttrName2, AttrValue2], ... */)
  90. {
  91. var HTML = '<' + Name;
  92.  
  93. for (var i = 2; i < arguments.length; ++i)
  94. HTML += ' ' + arguments[i][0] + '="' + arguments[i][1] + '"';
  95.  
  96. HTML += (Content != null && Content != "") ? ('>' + Content + '</' + Name + '>') : (' />');
  97.  
  98. return HTML;
  99. }
  100.  
  101.  
  102. function DbgMsg(Text) {if (DEBUG) alert(Text);}
  103.  
  104.  
  105. // EXTERN FUNCTIONS ///////////////////////////////////////////////////////////
  106.  
  107. /**
  108. * A utility function for defining JavaScript classes.
  109. *
  110. * This function expects a single object as its only argument. It defines
  111. * a new JavaScript class based on the data in that object and returns the
  112. * constructor function of the new class. This function handles the repetitive
  113. * tasks of defining classes: setting up the prototype object for correct
  114. * inheritance, copying methods from other types, and so on.
  115. *
  116. * The object passed as an argument should have some or all of the
  117. * following properties:
  118. *
  119. * name: The name of the class being defined.
  120. * If specified, this value will be stored in the classname
  121. * property of the prototype object.
  122. *
  123. * extend: The constructor of the class to be extended. If omitted,
  124. * the Object( ) constructor will be used. This value will
  125. * be stored in the superclass property of the prototype object.
  126. *
  127. * construct: The constructor function for the class. If omitted, a new
  128. * empty function will be used. This value becomes the return
  129. * value of the function, and is also stored in the constructor
  130. * property of the prototype object.
  131. *
  132. * methods: An object that specifies the instance methods (and other shared
  133. * properties) for the class. The properties of this object are
  134. * copied into the prototype object of the class. If omitted,
  135. * an empty object is used instead. Properties named
  136. * "classname", "superclass", and "constructor" are reserved
  137. * and should not be used in this object.
  138. *
  139. * statics: An object that specifies the static methods (and other static
  140. * properties) for the class. The properties of this object become
  141. * properties of the constructor function. If omitted, an empty
  142. * object is used instead.
  143. *
  144. * borrows: A constructor function or array of constructor functions.
  145. * The instance methods of each of the specified classes are copied
  146. * into the prototype object of this new class so that the
  147. * new class borrows the methods of each specified class.
  148. * Constructors are processed in the order they are specified,
  149. * so the methods of a class listed at the end of the array may
  150. * overwrite the methods of those specified earlier. Note that
  151. * borrowed methods are stored in the prototype object before
  152. * the properties of the methods object above. Therefore,
  153. * methods specified in the methods object can overwrite borrowed
  154. * methods. If this property is not specified, no methods are
  155. * borrowed.
  156. *
  157. * provides: A constructor function or array of constructor functions.
  158. * After the prototype object is fully initialized, this function
  159. * verifies that the prototype includes methods whose names and
  160. * number of arguments match the instance methods defined by each
  161. * of these classes. No methods are copied; this is simply an
  162. * assertion that this class "provides" the functionality of the
  163. * specified classes. If the assertion fails, this method will
  164. * throw an exception. If no exception is thrown, any
  165. * instance of the new class can also be considered (using "duck
  166. * typing") to be an instance of these other types. If this
  167. * property is not specified, no such verification is performed.
  168. **/
  169. function DefineClass(data) {
  170. // Extract the fields we'll use from the argument object.
  171. // Set up default values.
  172. var classname = data.name;
  173. var superclass = data.extend || Object;
  174. var constructor = data.construct || function(){};
  175. var methods = data.methods || {};
  176. var statics = data.statics || {};
  177. var borrows;
  178. var provides;
  179.  
  180. // Borrows may be a single constructor or an array of them.
  181. if (!data.borrows) borrows = [];
  182. else if (data.borrows instanceof Array) borrows = data.borrows;
  183. else borrows = [ data.borrows ];
  184.  
  185. // Ditto for the provides property.
  186. if (!data.provides) provides = [];
  187. else if (data.provides instanceof Array) provides = data.provides;
  188. else provides = [ data.provides ];
  189.  
  190. // Create the object that will become the prototype for our class.
  191. var proto = new superclass( );
  192.  
  193. // Delete any noninherited properties of this new prototype object.
  194. for(var p in proto)
  195. if (proto.hasOwnProperty(p)) delete proto[p];
  196.  
  197. // Borrow methods from "mixin" classes by copying to our prototype.
  198. for(var i = 0; i < borrows.length; i++) {
  199. var c = data.borrows[i];
  200. borrows[i] = c;
  201. // Copy method properties from prototype of c to our prototype
  202. for(var p in c.prototype) {
  203. if (typeof c.prototype[p] != "function") continue;
  204. proto[p] = c.prototype[p];
  205. }
  206. }
  207. // Copy instance methods to the prototype object
  208. // This may overwrite methods of the mixin classes
  209. for(var p in methods) proto[p] = methods[p];
  210.  
  211. // Set up the reserved "constructor", "superclass", and "classname"
  212. // properties of the prototype.
  213. proto.constructor = constructor;
  214. proto.superclass = superclass;
  215. // classname is set only if a name was actually specified.
  216. if (classname) proto.classname = classname;
  217.  
  218. // Verify that our prototype provides all of the methods it is supposed to.
  219. for(var i = 0; i < provides.length; i++) { // for each class
  220. var c = provides[i];
  221. for(var p in c.prototype) { // for each property
  222. if (typeof c.prototype[p] != "function") continue; // methods only
  223. if (p == "constructor" || p == "superclass") continue;
  224. // Check that we have a method with the same name and that
  225. // it has the same number of declared arguments. If so, move on
  226. if (p in proto &&
  227. typeof proto[p] == "function" &&
  228. proto[p].length == c.prototype[p].length) continue;
  229. // Otherwise, throw an exception
  230. throw new Error("Class " + classname + " does not provide method "+
  231. c.classname + "." + p);
  232. }
  233. }
  234.  
  235. // Associate the prototype object with the constructor function
  236. constructor.prototype = proto;
  237.  
  238. // Copy static properties to the constructor
  239. for(var p in statics) constructor[p] = statics[p];
  240.  
  241. // Finally, return the constructor function
  242. return constructor;
  243. }
  244.  
  245.  
  246. /**
  247. * Throughout, whitespace is defined as one of the characters
  248. * "\t" TAB \u0009
  249. * "\n" LF \u000A
  250. * "\r" CR \u000D
  251. * " " SPC \u0020
  252. *
  253. * This does not use Javascript's "\s" because that includes non-breaking
  254. * spaces (and also some other characters).
  255. */
  256.  
  257.  
  258. /**
  259. * Determine whether a node's text content is entirely whitespace.
  260. *
  261. * @param nod A node implementing the |CharacterData| interface (i.e.,
  262. * a |Text|, |Comment|, or |CDATASection| node
  263. * @return True if all of the text content of |nod| is whitespace,
  264. * otherwise false.
  265. */
  266. function is_all_ws( nod )
  267. {
  268. // Use ECMA-262 Edition 3 String and RegExp features
  269. return !(/[^\t\n\r ]/.test(nod.data));
  270. }
  271.  
  272.  
  273. /**
  274. * Determine if a node should be ignored by the iterator functions.
  275. *
  276. * @param nod An object implementing the DOM1 |Node| interface.
  277. * @return true if the node is:
  278. * 1) A |Text| node that is all whitespace
  279. * 2) A |Comment| node
  280. * and otherwise false.
  281. */
  282.  
  283. function is_ignorable( nod )
  284. {
  285. return ( nod.nodeType == 8) || // A comment node
  286. ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
  287. }
  288.  
  289. /**
  290. * Version of |previousSibling| that skips nodes that are entirely
  291. * whitespace or comments. (Normally |previousSibling| is a property
  292. * of all DOM nodes that gives the sibling node, the node that is
  293. * a child of the same parent, that occurs immediately before the
  294. * reference node.)
  295. *
  296. * @param sib The reference node.
  297. * @return Either:
  298. * 1) The closest previous sibling to |sib| that is not
  299. * ignorable according to |is_ignorable|, or
  300. * 2) null if no such node exists.
  301. */
  302. function node_before( sib )
  303. {
  304. while ((sib = sib.previousSibling)) {
  305. if (!is_ignorable(sib)) return sib;
  306. }
  307. return null;
  308. }
  309.  
  310. /**
  311. * Version of |nextSibling| that skips nodes that are entirely
  312. * whitespace or comments.
  313. *
  314. * @param sib The reference node.
  315. * @return Either:
  316. * 1) The closest next sibling to |sib| that is not
  317. * ignorable according to |is_ignorable|, or
  318. * 2) null if no such node exists.
  319. */
  320. function node_after( sib )
  321. {
  322. while ((sib = sib.nextSibling)) {
  323. if (!is_ignorable(sib)) return sib;
  324. }
  325. return null;
  326. }
  327.  
  328. /**
  329. * Version of |lastChild| that skips nodes that are entirely
  330. * whitespace or comments. (Normally |lastChild| is a property
  331. * of all DOM nodes that gives the last of the nodes contained
  332. * directly in the reference node.)
  333. *
  334. * @param par The reference node.
  335. * @return Either:
  336. * 1) The last child of |sib| that is not
  337. * ignorable according to |is_ignorable|, or
  338. * 2) null if no such node exists.
  339. */
  340. function last_child( par )
  341. {
  342. var res=par.lastChild;
  343. while (res) {
  344. if (!is_ignorable(res)) return res;
  345. res = res.previousSibling;
  346. }
  347. return null;
  348. }
  349.  
  350. /**
  351. * Version of |firstChild| that skips nodes that are entirely
  352. * whitespace and comments.
  353. *
  354. * @param par The reference node.
  355. * @return Either:
  356. * 1) The first child of |sib| that is not
  357. * ignorable according to |is_ignorable|, or
  358. * 2) null if no such node exists.
  359. */
  360. function first_child( par )
  361. {
  362. var res=par.firstChild;
  363. while (res) {
  364. if (!is_ignorable(res)) return res;
  365. res = res.nextSibling;
  366. }
  367. return null;
  368. }
  369.  
  370. /**
  371. * Version of |data| that doesn't include whitespace at the beginning
  372. * and end and normalizes all whitespace to a single space. (Normally
  373. * |data| is a property of text nodes that gives the text of the node.)
  374. *
  375. * @param txt The text node whose data should be returned
  376. * @return A string giving the contents of the text node with
  377. * whitespace collapsed.
  378. */
  379. function data_of( txt )
  380. {
  381. var data = txt.data;
  382. // Use ECMA-262 Edition 3 String and RegExp features
  383. data = data.replace(/[\t\n\r ]+/g, " ");
  384. if (data.charAt(0) == " ")
  385. data = data.substring(1, data.length);
  386. if (data.charAt(data.length - 1) == " ")
  387. data = data.substring(0, data.length - 1);
  388. return data;
  389. }
  390.  
  391.  
  392. // CLASSES ////////////////////////////////////////////////////////////////////
  393.  
  394. // NextNode: the node next to the statistics node when it is created
  395. function CStat(NextNode)
  396. {
  397. var NewSection = document.createElement("div");
  398. NewSection.id = "stat_all";
  399. this._Node = NextNode.parentNode.insertBefore(NewSection, NextNode);
  400.  
  401. this._HTML = '';
  402.  
  403. this._gInfoList = [];
  404.  
  405. this.nTotalPages = 0;
  406. this.nReadPages = 0;
  407. }
  408.  
  409. CStat.prototype._Write = function(Text) {this._HTML += Text;};
  410.  
  411. CStat.prototype._Flush = function() {this._Node.innerHTML = this._HTML;};
  412.  
  413. CStat.prototype.RegInfoList = function(InfoList)
  414. {
  415. if (InfoList instanceof CInfoList)
  416. {
  417. this._gInfoList.push(InfoList);
  418. return true;
  419. }
  420. return false;
  421. };
  422.  
  423. CStat.prototype.SaveInfo = function(Info)
  424. {
  425. for (var i = 0; i < this._gInfoList.length; ++i)
  426. this._gInfoList[i].SaveInfo(Info);
  427. };
  428.  
  429. CStat.prototype.Show = function()
  430. {
  431. this._Write("<hr />");
  432. for (var i = 0; i < this._gInfoList.length; ++i)
  433. this._Write( this._gInfoList[i].Show() );
  434. this._Write(this._OptionsHTML());
  435. this._Write("<hr />");
  436. this._Flush();
  437.  
  438. for (var i = 0; i < this._gInfoList.length; ++i)
  439. this._gInfoList[i].AddEvents();
  440. this._AddEvents();
  441. };
  442.  
  443. CStat.prototype.ShowProgress = function()
  444. {
  445. this._Node.innerHTML = '<hr /><h1>' + Local.Text_Loading + ' (' +
  446. this.nReadPages + '/' + this.nTotalPages + ') ...</h1><hr />';
  447. };
  448.  
  449. CStat.prototype._OptionsHTML = function()
  450. {
  451. var Str = '<div id="stat_options">' +
  452. '<div class="stat_header"><span class="stat_title">' + Local.Text_Options + '</span>';
  453. Str += CreateElementHTML("input", null, ["type", "button"], ["class", "button"],
  454. ["id", "stat_options_default"], ["value", Local.Text_Button_Default]);
  455. Str += '</div></div>';
  456. return Str;
  457. };
  458.  
  459. CStat.prototype._AddEvents = function()
  460. {
  461. function OnDelGMValues()
  462. {
  463. try {
  464. var ValueList = GM_listValues();
  465. for (var name in ValueList) {GM_deleteValue(ValueList[name]);}
  466. alert(Local.Text_DefaultMsg);
  467. }
  468. catch (e) {alert("OnDelGMValues(): " + e);}
  469. }
  470. $("stat_options_default").addEventListener("click", OnDelGMValues, false);
  471. };
  472.  
  473.  
  474. ///////////////////////////////////////////////////////////////////////////////
  475. function CTable(Title, Id, nColumns)
  476. {
  477. this._Title = Title;
  478. this._Id = Id;
  479. this._nColumns = nColumns;
  480. this._HeadCellContents = new Array(nColumns);
  481. this._BodyCellContentTypes = new Array(nColumns);
  482. this._BodyCellContents = [];
  483. this._HTML = '';
  484.  
  485. this._bShow = GM_getValue(Id, true);
  486. }
  487.  
  488. CTable._ContentAttrs = {
  489. string : '',
  490. number : 'align="right"',
  491. button : 'align="center"'};
  492.  
  493. CTable.prototype.SetHeadCellContents = function(/* Content1, Content2, ... */)
  494. {
  495. for (var i = 0; i < this._nColumns; ++i)
  496. this._HeadCellContents[i] = arguments[i] != null ? arguments[i] : "";
  497. };
  498.  
  499. // Type: a string that is the property name of CTable::ContentAttrs
  500. CTable.prototype.SetBodyCellContentTypes = function(/* Type1, Type2, ... */)
  501. {
  502. for (var i = 0; i < this._nColumns; ++i)
  503. this._BodyCellContentTypes[i] =
  504. arguments[i] != null ? CTable._ContentAttrs[arguments[i]] : "";
  505. };
  506.  
  507. CTable.prototype.SetBodyCellContents = function(/* Content1, Content2, ... */)
  508. {
  509. var Contents = new Array(this._nColumns);
  510. for (var i = 0; i < this._nColumns; ++i)
  511. Contents[i] = arguments[i] != null ? arguments[i] : "";
  512. this._BodyCellContents.push(Contents);
  513. };
  514.  
  515. CTable.prototype.CreateHTML = function()
  516. {
  517. this._HTML = '<div id="' + this._Id + '">' +
  518. '<div class="stat_header"><span class="stat_title clickable">' + this._Title + '</span></div>' +
  519. '<table class="content_table" ' + (this._bShow ? '' : 'hide="hide"') + '>' +
  520. '<tr class="content_table_header">';
  521.  
  522. for (var i = 0; i < this._nColumns; ++i)
  523. this._HTML += '<th class="content_table">' + this._HeadCellContents[i] + '</th>';
  524. this._HTML += '</tr>';
  525. for (var i = 0; i < this._BodyCellContents.length; ++i)
  526. {
  527. this._HTML += '<tr class="content_table_row_' + i % 2 + '">';
  528. for (var j = 0; j < this._nColumns; ++j)
  529. {
  530. this._HTML += '<td class="content_table" ' +
  531. this._BodyCellContentTypes[j] + '>' +
  532. this._BodyCellContents[i][j] + '</td>';
  533. }
  534. this._HTML += '</tr>';
  535. }
  536. this._HTML += '</table></div>';
  537.  
  538. return this._HTML;
  539. };
  540.  
  541. CTable.prototype.GetHTML = function()
  542. {return this._HTML;};
  543.  
  544. CTable.prototype.AddEvents = function()
  545. {
  546. var Title = $(this._Id).getElementsByTagName("span")[0];
  547. function Factory(Id) {return function(){CTable.OnClickTitle(Id);};}
  548. Title.addEventListener("click", Factory(this._Id), false);
  549. };
  550.  
  551. CTable.OnClickTitle = function(Id)
  552. {
  553. try {
  554. var Table = $(Id).getElementsByTagName("table")[0];
  555. if (Table.hasAttribute("hide"))
  556. {
  557. Table.removeAttribute("hide");
  558. GM_setValue(Id, true);
  559. }
  560. else
  561. {
  562. Table.setAttribute("hide", "hide");
  563. GM_setValue(Id, false);
  564. }
  565. }
  566. catch (e) {alert("CTable.OnClickTitle(): " + e);}
  567. };
  568.  
  569.  
  570. ///////////////////////////////////////////////////////////////////////////////
  571. function CActiveInfo()
  572. {
  573. this.nIniRoll;
  574. this.nCurrAction;
  575. this.nTotalActions;
  576. this.Char = new CChar();
  577. this.nCharId;
  578. this.ActionType = new CActionType();
  579. this.Skill = new CSkill();
  580. this.nAttackRoll;
  581. this.nSkillMP;
  582. this.gItem = new CKeyList();
  583. }
  584.  
  585.  
  586. function CPassiveInfo()
  587. {
  588. this.Char = new CChar();
  589. this.nCharId;
  590. this.Skill = new CSkill();
  591. this.nDefenceRoll;
  592. this.nSkillMP;
  593. this.gItem = new CKeyList();
  594. this.HitType = new CHitType();
  595. this.bStruckDown;
  596. this.gDamage = [];
  597. this.DamagedItem = new CItem();
  598. this.nItemDamage;
  599. this.nHealedHP;
  600. this.nHealedMP;
  601. }
  602.  
  603.  
  604. function CNavi(nLevel, nRoom, nRound, nRow)
  605. {
  606. this.nLevel = nLevel;
  607. this.nRoom = nRoom;
  608. this.nRound = nRound;
  609. this.nRow = nRow;
  610. }
  611.  
  612.  
  613. function CActionInfo(Navi)
  614. {
  615. this.Navi = Navi;
  616. this.Active = new CActiveInfo();
  617. this.gPassive = [];
  618. }
  619.  
  620.  
  621. ///////////////////////////////////////////////////////////////////////////////
  622. // Class: Key
  623. // Every key should have two function properties: compareTo() and toString(),
  624. // and can work without initialization parameters
  625.  
  626. var CKey = DefineClass({
  627. methods:
  628. {
  629. compareTo: function(that) {return this - that;},
  630. toString: function() {return "";}
  631. }
  632. });
  633.  
  634.  
  635. var CKeyList = DefineClass({
  636. extend: CKey,
  637. construct: function() {this._gKey = [];},
  638. methods:
  639. {
  640. push: function(Key) {return this._gKey.push(Key);},
  641. compareTo: function(that)
  642. {
  643. var result = this._gKey.length - that._gKey.length;
  644. if (result !== 0)
  645. return result;
  646.  
  647. var i = 0;
  648. while (i < this._gKey.length && this._gKey[i].compareTo(that._gKey[i]) === 0)
  649. ++i;
  650. if (i === this._gKey.length)
  651. return 0;
  652. else
  653. return this._gKey[i].compareTo(that._gKey[i]);
  654. },
  655. toString: function() {return this._gKey.join(", ");}
  656. }
  657. });
  658.  
  659.  
  660. var CChar = DefineClass({
  661. extend: CKey,
  662. construct: function(HTMLElement)
  663. {
  664. this._Name;
  665. this._Href;
  666. this._OnClick;
  667. this._Class;
  668. this._nType;
  669.  
  670. if (HTMLElement != null)
  671. {
  672. this._Name = HTMLElement.firstChild.data;
  673. this._Href = HTMLElement.getAttribute("href");
  674. this._OnClick = HTMLElement.getAttribute("onclick");
  675. this._Class = HTMLElement.className;
  676. this._nType = CChar._GetCharType(this._Class);
  677. if (this._nType === null)
  678. DbgMsg("CChar(): Unknown type: " + this._Class);
  679. }
  680. },
  681. methods:
  682. {
  683. GetType: function() {return this._nType;},
  684. compareTo: function(that)
  685. {
  686. var result = this._nType - that._nType;
  687. if (result !== 0)
  688. return result;
  689. return CompareString(this._Name, that._Name);
  690. },
  691. toString: function()
  692. {
  693. if (this._Name != null)
  694. return CreateElementHTML("a", this._Name, ["href", this._Href],
  695. ["onclick", this._OnClick], ["class", this._Class]);
  696. else
  697. return "";
  698. }
  699. },
  700. statics:
  701. {
  702. _GetCharType: function(Class)
  703. {
  704. switch (Class)
  705. {
  706. case "rep_hero":
  707. case "rep_myhero":
  708. return 0;
  709. case "rep_monster":
  710. case "rep_myhero_defender":
  711. return 1;
  712. default:
  713. return null;
  714. }
  715. }
  716. }
  717. });
  718.  
  719.  
  720. // In-round actions
  721. var CActionType = DefineClass({
  722. extend: CKey,
  723. construct: function(ActionText)
  724. {
  725. this._nType;
  726. this._nKind;
  727.  
  728. if (ActionText != null)
  729. {
  730. var ret = CActionType._GetActionTypeAndKind(ActionText);
  731. this._nType = ret[0];
  732. this._nKind = ret[1];
  733. }
  734. },
  735. methods:
  736. {
  737. GetType: function() {return this._nType;},
  738. GetKind: function() {return this._nKind;},
  739. compareTo: function(that) {return this._nType - that._nType;},
  740. toString: function()
  741. {
  742. switch (this._nKind)
  743. {
  744. case 0: return Local.TextList_AttackType[this._nType];
  745. case 1: return "heal";
  746. case 2: return "buff";
  747. case 3: return "wait";
  748. default: return "unknown";
  749. }
  750. }
  751. },
  752. statics:
  753. {
  754. // return: an array, [0]: _nType, [1]: _nKind
  755. _GetActionTypeAndKind: function(ActionText)
  756. {
  757. switch (ActionText)
  758. {
  759. case Local.OrigTextList_ActionType[0]: // melee
  760. return [0, 0];
  761. case Local.OrigTextList_ActionType[1]: // ranged
  762. return [1, 0];
  763. case Local.OrigTextList_ActionType[2]: // magic
  764. return [2, 0];
  765. case Local.OrigTextList_ActionType[3]: // social
  766. return [3, 0];
  767. case Local.OrigTextList_ActionType[4]: // ambush
  768. return [4, 0];
  769. case Local.OrigTextList_ActionType[5]: // trap
  770. return [5, 0];
  771. case Local.OrigTextList_ActionType[6]: // nature
  772. return [6, 0];
  773. case Local.OrigTextList_ActionType[7]: // disease
  774. return [7, 0];
  775. case Local.OrigTextList_ActionType[8]: // detonate
  776. return [8, 0];
  777. case Local.OrigTextList_ActionType[9]: // disarm trap
  778. return [9, 0];
  779. case Local.OrigTextList_ActionType[10]: // magic projectile
  780. return [10, 0];
  781. case Local.OrigTextList_ActionType[11]: // curse
  782. return [11, 0];
  783. case Local.OrigTextList_ActionType[12]: // scare
  784. return [12, 0];
  785. case Local.OrigTextList_ActionType[13]: // heal
  786. return [13, 1];
  787. case Local.OrigTextList_ActionType[14]: // buff
  788. return [14, 2];
  789. case Local.OrigTextList_ActionType[15]: // summon
  790. return [15, 2];
  791. case Local.OrigTextList_ActionType[16]: // do nothing
  792. return [16, 3];
  793. case Local.OrigTextList_ActionType[17]: // wait
  794. return [17, 3];
  795. default:
  796. return [null, null];
  797. }
  798. }
  799. }
  800. });
  801.  
  802.  
  803. var CSkill = DefineClass({
  804. extend: CKey,
  805. construct: function(HTMLElement)
  806. {
  807. this._Name;
  808. this._Href;
  809. this._OnClick;
  810.  
  811. if (HTMLElement != null)
  812. {
  813. this._Name = HTMLElement.firstChild.data;
  814. this._Href = HTMLElement.getAttribute("href");
  815. this._OnClick = HTMLElement.getAttribute("onclick");
  816. }
  817. },
  818. methods:
  819. {
  820. compareTo: function(that) {return CompareString(this._Name, that._Name);},
  821. toString: function()
  822. {
  823. if (this._Name != null)
  824. return CreateElementHTML("a", this._Name, ["href", this._Href],
  825. ["onclick", this._OnClick]);
  826. else
  827. return "";
  828. }
  829. }
  830. });
  831.  
  832.  
  833. var CItem = DefineClass({
  834. extend: CKey,
  835. construct: function(HTMLElement)
  836. {
  837. this._Name;
  838. this._Href;
  839. this._OnClick;
  840. this._Class;
  841.  
  842. if (HTMLElement != null)
  843. {
  844. this._Name = HTMLElement.firstChild.data;
  845. this._Href = HTMLElement.getAttribute("href");
  846. this._OnClick = HTMLElement.getAttribute("onclick");
  847. this._Class = HTMLElement.className;
  848. }
  849. },
  850. methods:
  851. {
  852. compareTo: function(that) {return CompareString(this._Name, that._Name);},
  853. toString: function()
  854. {
  855. if (this._Name != null)
  856. return CreateElementHTML("a", this._Name, ["href", this._Href],
  857. ["onclick", this._OnClick], ["class", this._Class]);
  858. else
  859. return "";
  860. }
  861. }
  862. });
  863.  
  864.  
  865. var CHitType = DefineClass({
  866. extend: CKey,
  867. construct: function(HitClassText)
  868. {
  869. this._nType;
  870.  
  871. if (HitClassText != null)
  872. {
  873. this._nType = CHitType._GetHitType(HitClassText);
  874. if (this._nType === null)
  875. DbgMsg("CHitType(): Unknown type: " + HitClassText);
  876. }
  877. },
  878. methods:
  879. {
  880. GetType: function() {return this._nType;},
  881. compareTo: function(that) {return this._nType - that._nType;},
  882. toString: function()
  883. {
  884. if (this._nType != null)
  885. return Local.TextList_HitType[this._nType];
  886. else
  887. return "";
  888. }
  889. },
  890. statics:
  891. {
  892. _GetHitType: function(Class)
  893. {
  894. switch (Class)
  895. {
  896. case "rep_miss":
  897. return 0;
  898. case "rep_hit":
  899. return 1;
  900. case "rep_hit_good":
  901. return 2;
  902. case "rep_hit_crit":
  903. return 3;
  904. default:
  905. return null;
  906. }
  907. }
  908. }
  909. });
  910.  
  911.  
  912. var CDamage = DefineClass({
  913. extend: CKey,
  914. construct: function(HTMLElement)
  915. {
  916. this._nBasicDmg;
  917. this._nActualDmg;
  918. this._nArmor;
  919. this._nType;
  920.  
  921. if (HTMLElement != null)
  922. {
  923. var Str;
  924. if (HTMLElement.nodeType != 3)
  925. {
  926. Str = HTMLElement.getAttribute("onmouseover");
  927. // \1 basic damage
  928. var Patt_BasicDamage = Local.Pattern_BasicDamage;
  929. var result = Patt_BasicDamage.exec(Str);
  930. if (result == null)
  931. throw "CDamage() :" + Str;
  932. this._nBasicDmg = Number(result[1]);
  933. Str = HTMLElement.firstChild.data;
  934. }
  935. else
  936. Str = HTMLElement.data;
  937.  
  938. // \1 actual damage
  939. // \2 armor
  940. // \3 damage type
  941. var Patt_Damage = Local.Pattern_Damage;
  942. var result = Patt_Damage.exec(Str);
  943. if (result == null)
  944. throw "CDamage() :" + Str;
  945. this._nActualDmg = Number(result[1]);
  946. this._nArmor = result[2] != null ? Number(result[2]) : 0;
  947. this._nType = CDamage._GetDamageType(result[3]);
  948.  
  949. if (this._nType === null)
  950. DbgMsg("CDamage(): Unknown type: " + result[3]);
  951. if (this._nBasicDmg == null)
  952. this._nBasicDmg = this._nActualDmg + this._nArmor;
  953. }
  954. },
  955. methods:
  956. {
  957. GetType: function() {return this._nType;},
  958. GetBasicDmg: function() {return this._nBasicDmg;},
  959. GetArmor: function() {return this._nArmor;},
  960. GetActualDmg: function() {return this._nActualDmg;},
  961. IsHPDamage: function() {return this._nType !== 11;},
  962. compareTo: function(that) {return this._nBasicDmg - that._nBasicDmg;},
  963. toString: function()
  964. {
  965. if (this._nType != null)
  966. {
  967. var Str = String(this._nBasicDmg);
  968. if (this._nArmor > 0)
  969. Str += " - " + this._nArmor + " -> " + this._nActualDmg;
  970. else if (this._nBasicDmg !== this._nActualDmg)
  971. Str += " -> " + this._nActualDmg;
  972. Str += " " + Local.OrigTextList_DamageType[this._nType] + " damage";
  973. return Str;
  974. }
  975. else
  976. return "";
  977. }
  978. },
  979. statics:
  980. {
  981. _GetDamageType: function(Text)
  982. {
  983. switch (Text)
  984. {
  985. case Local.OrigTextList_DamageType[0]: // crushing
  986. return 0;
  987. case Local.OrigTextList_DamageType[1]: // cutting
  988. return 1;
  989. case Local.OrigTextList_DamageType[2]: // piercing
  990. return 2;
  991. case Local.OrigTextList_DamageType[3]: // fire
  992. return 3;
  993. case Local.OrigTextList_DamageType[4]: // ice
  994. return 4;
  995. case Local.OrigTextList_DamageType[5]: // lightning
  996. return 5;
  997. case Local.OrigTextList_DamageType[6]: // poison
  998. return 6;
  999. case Local.OrigTextList_DamageType[7]: // acid
  1000. return 7;
  1001. case Local.OrigTextList_DamageType[8]: // psychological
  1002. return 8;
  1003. case Local.OrigTextList_DamageType[9]: // holy
  1004. return 9;
  1005. case Local.OrigTextList_DamageType[10]: // disarm trap
  1006. return 10;
  1007. case Local.OrigTextList_DamageType[11]: // mana
  1008. return 11;
  1009. default:
  1010. return null;
  1011. }
  1012. }
  1013. }
  1014. });
  1015.  
  1016.  
  1017. ///////////////////////////////////////////////////////////////////////////////
  1018. // Class: Value list
  1019. // Value list is a special key, it can contains any type of values, including keys
  1020.  
  1021. var CValueList = DefineClass({
  1022. extend: CKey,
  1023. construct: function()
  1024. {
  1025. this._gValue = [];
  1026. this._nAvgValue; // unsure type
  1027. },
  1028. methods:
  1029. {
  1030. GetLength: function() {return this._gValue.length;},
  1031. Calculate: function() {},
  1032. push: function(Value) {return this._gValue.push(Value);},
  1033. compareTo: function(that) {return this._nAvgValue - that._nAvgValue;},
  1034. AvgValueStr: function() {return String(this._nAvgValue);},
  1035. toString: function() {return this._gValue.join(", ");}
  1036. }
  1037. });
  1038.  
  1039.  
  1040. var CVLNumber = DefineClass({
  1041. extend: CValueList,
  1042. construct: function() {this.superclass();},
  1043. methods:
  1044. {
  1045. Calculate: function()
  1046. {
  1047. var nTotalValue = 0;
  1048. for (var i = 0; i < this._gValue.length; ++i)
  1049. nTotalValue += this._gValue[i];
  1050. this._nAvgValue = Number((nTotalValue / this._gValue.length).toFixed(2));
  1051. }
  1052. }
  1053. });
  1054.  
  1055.  
  1056. // value: [Number1, Number2]
  1057. var CVLPairNumber = DefineClass({
  1058. extend: CValueList,
  1059. construct: function() {this.superclass();},
  1060. methods:
  1061. {
  1062. Calculate: function()
  1063. {
  1064. var nTotalValue = [0, 0];
  1065. for (var i = 0; i < this._gValue.length; ++i)
  1066. {
  1067. nTotalValue[0] += this._gValue[i][0];
  1068. nTotalValue[1] += this._gValue[i][1];
  1069. }
  1070. this._nAvgValue = new Array(2);
  1071. this._nAvgValue[0] = Number((nTotalValue[0] / this._gValue.length).toFixed(2));
  1072. this._nAvgValue[1] = Number((nTotalValue[1] / this._gValue.length).toFixed(2));
  1073. },
  1074. compareTo: function(that)
  1075. {
  1076. if (this._nAvgValue[0] !== 0 || that._nAvgValue[0] !== 0)
  1077. return this._nAvgValue[0] - that._nAvgValue[0];
  1078. else
  1079. return this._nAvgValue[1] - that._nAvgValue[1];
  1080. },
  1081. AvgValueStr: function()
  1082. {
  1083. return '<table class="pair_value"><tr><td>' +
  1084. ((this._nAvgValue[0] !== 0) ? String(this._nAvgValue[0]) : '') +
  1085. '</td><td>' +
  1086. ((this._nAvgValue[1] !== 0) ? String(this._nAvgValue[1]) : '') +
  1087. '</td></tr></table>';
  1088. },
  1089. toString: function()
  1090. {
  1091. var Str = "";
  1092. for (var i = 0; i < this._gValue.length; ++i)
  1093. {
  1094. Str += (this._gValue[i][0] != null) ? this._gValue[i][0] : 0;
  1095. Str += "/";
  1096. Str += (this._gValue[i][1] != null) ? this._gValue[i][1] : 0;
  1097. if (i < this._gValue.length -1)
  1098. Str += ", ";
  1099. }
  1100. return Str;
  1101. }
  1102. }
  1103. });
  1104.  
  1105.  
  1106. // value: An Array of CDamage
  1107. var CVLDamage = DefineClass({
  1108. extend: CValueList,
  1109. construct: function() {this.superclass();},
  1110. methods:
  1111. {
  1112. Calculate: function()
  1113. {
  1114. var nTotalValue = [0, 0];
  1115. for (var i = 0; i < this._gValue.length; ++i)
  1116. {
  1117. for (var j = 0; j < this._gValue[i].length; ++j)
  1118. {
  1119. if (this._gValue[i][j].IsHPDamage())
  1120. {
  1121. nTotalValue[0] += this._gValue[i][j].GetBasicDmg();
  1122. nTotalValue[1] += this._gValue[i][j].GetActualDmg();
  1123. }
  1124. }
  1125. }
  1126. this._nAvgValue = new Array(2);
  1127. this._nAvgValue[0] = Number((nTotalValue[0] / this._gValue.length).toFixed(2));
  1128. this._nAvgValue[1] = Number((nTotalValue[1] / this._gValue.length).toFixed(2));
  1129. },
  1130. compareTo: function(that) {return this._nAvgValue[1] - that._nAvgValue[1];},
  1131. AvgValueStr: function()
  1132. {
  1133. return '<table class="pair_value"><tr><td>' +
  1134. this._nAvgValue[1] + '</td><td>' +
  1135. this._nAvgValue[0] + '</td></tr></table>';
  1136. },
  1137. toString: function()
  1138. {
  1139. var Str = "";
  1140. for (var i = 0; i < this._gValue.length; ++i)
  1141. {
  1142. var nTotalValue = [0, 0];
  1143. for (var j = 0; j < this._gValue[i].length; ++j)
  1144. {
  1145. if (this._gValue[i][j].IsHPDamage())
  1146. {
  1147. nTotalValue[0] += this._gValue[i][j].GetBasicDmg();
  1148. nTotalValue[1] += this._gValue[i][j].GetActualDmg();
  1149. }
  1150. }
  1151. Str += nTotalValue[1] + "/" + nTotalValue[0];
  1152. if (i < this._gValue.length -1)
  1153. Str += ", ";
  1154. }
  1155. return Str;
  1156. }
  1157. }
  1158. });
  1159.  
  1160.  
  1161. ///////////////////////////////////////////////////////////////////////////////
  1162. // Class: Info list
  1163.  
  1164. var CInfoList = DefineClass({
  1165. construct: function(nKeys, CValueList)
  1166. {
  1167. this._gInfo = [];
  1168. this._nKeys = nKeys;
  1169. this._CValueList = CValueList;
  1170. this._Table = null;
  1171. },
  1172. methods:
  1173. {
  1174. _CompareKeys: function(gKeyA, gKeyB)
  1175. {
  1176. for (var i = 0; i < this._nKeys; ++i)
  1177. {
  1178. var result = gKeyA[i].compareTo( gKeyB[i] );
  1179. if (result !== 0)
  1180. return result;
  1181. }
  1182. return 0;
  1183. },
  1184. _SetTableBodyCellContents: function()
  1185. {
  1186. for (var i = 0; i < this._gInfo.length; ++i)
  1187. {
  1188. var gBodyCellContent = [];
  1189. for (var j = 0; j < this._gInfo[i].gKey.length; ++j)
  1190. gBodyCellContent.push( this._gInfo[i].gKey[j] );
  1191.  
  1192. gBodyCellContent.push( this._gInfo[i].ValueList.AvgValueStr(),
  1193. String(this._gInfo[i].ValueList.GetLength()),
  1194. CreateElementHTML("input", null, ["type", "button"],
  1195. ["class", "button"], ["value", Local.Text_Button_Show],
  1196. ["onclick", 'alert(&quot;' + this._gInfo[i].ValueList.toString() + '&quot;);']) );
  1197.  
  1198. this._Table.SetBodyCellContents.apply(this._Table, gBodyCellContent);
  1199. }
  1200. },
  1201. SaveInfo: function(Info) {},
  1202. Show: function() {},
  1203. // Call this function when read all data, and before sort and export data
  1204. CalculateValue: function()
  1205. {
  1206. for (var i = 0; i < this._gInfo.length; ++i)
  1207. this._gInfo[i].ValueList.Calculate();
  1208. },
  1209. CreateTable: function(Title, Id, gKeyName)
  1210. {
  1211. // Key1, Key2, ..., AverageValue, Times, ValueList
  1212. this._Table = new CTable(Title, Id, this._nKeys + 3);
  1213.  
  1214. var gHeadCellContent = new Array(this._nKeys + 3);
  1215. for (var i = 0; i < this._nKeys; ++i)
  1216. gHeadCellContent[i] = gKeyName[i];
  1217. gHeadCellContent[this._nKeys] = Local.Text_Table_AvgRoll;
  1218. gHeadCellContent[this._nKeys + 1] = Local.Text_Table_Times;
  1219. gHeadCellContent[this._nKeys + 2] = Local.Text_Table_RollList;
  1220. this._Table.SetHeadCellContents.apply(this._Table, gHeadCellContent);
  1221.  
  1222. var gBodyCellContentType = new Array(this._nKeys + 3);
  1223. for (var i = 0; i < this._nKeys; ++i)
  1224. gBodyCellContentType[i] = "string";
  1225. gBodyCellContentType[this._nKeys] = "number";
  1226. gBodyCellContentType[this._nKeys + 1] = "number";
  1227. gBodyCellContentType[this._nKeys + 2] = "button";
  1228. this._Table.SetBodyCellContentTypes.apply(this._Table, gBodyCellContentType);
  1229.  
  1230. this._SetTableBodyCellContents();
  1231.  
  1232. return this._Table.CreateHTML();
  1233. },
  1234. // Call this function when edited the info list (for example, re-sorted it)
  1235. ReCreateTableHTML: function()
  1236. {
  1237. this._SetTableBodyCellContents();
  1238. return this._Table.CreateHTML();
  1239. },
  1240. GetTableHTML: function() {return this._Table.GetHTML();},
  1241. AddEvents: function() {if (this._Table != null) this._Table.AddEvents();},
  1242. push: function(gKey, Value)
  1243. {
  1244. for (var i = 0; i < this._gInfo.length; ++i)
  1245. {
  1246. if (this._CompareKeys(this._gInfo[i].gKey, gKey) === 0)
  1247. {
  1248. this._gInfo[i].ValueList.push(Value);
  1249. return this._gInfo.length;
  1250. }
  1251. }
  1252.  
  1253. var ValueList = new this._CValueList();
  1254. ValueList.push(Value);
  1255. return this._gInfo.push(new CInfoList._CInfo(gKey, ValueList));
  1256. },
  1257. sort: function(gSortKeyId)
  1258. {
  1259. function Factory(gId) {return function(A, B){return CInfoList._CompareInfo(A, B, gId);};}
  1260. return this._gInfo.sort(Factory(gSortKeyId));
  1261. }
  1262. },
  1263. statics:
  1264. {
  1265. _CInfo: function(gKey, ValueList)
  1266. {
  1267. this.gKey = gKey;
  1268. this.ValueList = ValueList;
  1269. },
  1270. // SortKeyId: Id of keys, or null
  1271. // The list will be sorted in this way: sort them by the first key, if there are
  1272. // elements are still equal, then sort them by the second key, and so on.
  1273. // If SortKeyId is null, then sort the list by value
  1274. // If gSortKeyId is null, then sort the list by default order of keys
  1275. _CompareInfo: function(InfoA, InfoB, gSortKeyId)
  1276. {
  1277. if (gSortKeyId == null)
  1278. {
  1279. for (var i = 0; i < InfoA.gKey.length; ++i)
  1280. {
  1281. var result = InfoA.gKey[i].compareTo(InfoB.gKey[i]);
  1282. if (result !== 0) return result;
  1283. }
  1284. return 0;
  1285. }
  1286. else
  1287. {
  1288. for (var i = 0; i < gSortKeyId.length; ++i)
  1289. {
  1290. var KeyId = gSortKeyId[i];
  1291. var result = (KeyId != null) ?
  1292. InfoA.gKey[KeyId].compareTo(InfoB.gKey[KeyId]) :
  1293. InfoA.ValueList.compareTo(InfoB.ValueList);
  1294. if (result !== 0) return result;
  1295. }
  1296. return 0;
  1297. }
  1298. }
  1299. }
  1300. });
  1301.  
  1302.  
  1303. ///////////////////////////////////////////////////////////////////////////////
  1304. // Sub classes of CInfoList
  1305. //
  1306. // var CIL_ = DefineClass({
  1307. // extend: CInfoList,
  1308. // construct: function(_nKeys, CValueList) {this.superclass(_nKeys, CValueList);},
  1309. // methods:
  1310. // {
  1311. // _SetTableBodyCellContents: function() {},
  1312. // SaveInfo: function(Info) {},
  1313. // Show: function() {},
  1314. // CreateTable: function(Title, Id, gKeyName) {}
  1315. // }
  1316. // });
  1317.  
  1318. var CILIni = DefineClass({
  1319. extend: CInfoList,
  1320. construct: function(nKeys, CValueList) {this.superclass(nKeys, CValueList);},
  1321. methods:
  1322. {
  1323. SaveInfo: function(Info)
  1324. {
  1325. if (Info.Active.nCurrAction === 1)
  1326. this.push([Info.Active.Char], Info.Active.nIniRoll);
  1327. },
  1328. Show: function()
  1329. {
  1330. if (this._gInfo.length > 0)
  1331. {
  1332. this.CalculateValue();
  1333. this.sort();
  1334. return this.CreateTable(Local.Text_Table_Ini, "stat_ini", [Local.Text_Table_Char]);
  1335. }
  1336. return "";
  1337. }
  1338. }
  1339. });
  1340.  
  1341.  
  1342. var CILAttackRoll = DefineClass({
  1343. extend: CInfoList,
  1344. construct: function(nKeys, CValueList) {this.superclass(nKeys, CValueList);},
  1345. methods:
  1346. {
  1347. SaveInfo: function(Info)
  1348. {
  1349. if (Info.Active.ActionType.GetKind() === 0 && Info.Active.nAttackRoll != null)
  1350. this.push([Info.Active.Char, Info.Active.ActionType, Info.Active.Skill, Info.Active.gItem],
  1351. Info.Active.nAttackRoll);
  1352. },
  1353. Show: function()
  1354. {
  1355. if (this._gInfo.length > 0)
  1356. {
  1357. this.CalculateValue();
  1358. this.sort();
  1359. return this.CreateTable( Local.Text_Table_Attack, "stat_attack",
  1360. [Local.Text_Table_Char, Local.Text_Table_AttackType, Local.Text_Table_Skill, Local.Text_Table_Item]);
  1361. }
  1362. return "";
  1363. }
  1364. }
  1365. });
  1366.  
  1367.  
  1368. var CILDefenceRoll = DefineClass({
  1369. extend: CInfoList,
  1370. construct: function(nKeys, CValueList) {this.superclass(nKeys, CValueList);},
  1371. methods:
  1372. {
  1373. SaveInfo: function(Info)
  1374. {
  1375. if (Info.Active.ActionType.GetKind() === 0)
  1376. {
  1377. for (var i = 0; i < Info.gPassive.length; ++i)
  1378. {
  1379. if (Info.gPassive[i].nDefenceRoll != null)
  1380. this.push([Info.gPassive[i].Char, Info.Active.ActionType,
  1381. Info.gPassive[i].Skill, Info.gPassive[i].gItem], Info.gPassive[i].nDefenceRoll);
  1382. }
  1383. }
  1384. },
  1385. Show: function()
  1386. {
  1387. if (this._gInfo.length > 0)
  1388. {
  1389. this.CalculateValue();
  1390. this.sort();
  1391. return this.CreateTable(Local.Text_Table_Defence, "stat_defence",
  1392. [Local.Text_Table_Char, Local.Text_Table_DefenceType, Local.Text_Table_Skill, Local.Text_Table_Item]);
  1393. }
  1394. return "";
  1395. }
  1396. }
  1397. });
  1398.  
  1399.  
  1400. var CILDamage = DefineClass({
  1401. extend: CInfoList,
  1402. construct: function(nKeys, CValueList) {this.superclass(nKeys, CValueList);},
  1403. methods:
  1404. {
  1405. SaveInfo: function(Info)
  1406. {
  1407. if (Info.Active.ActionType.GetKind() === 0)
  1408. {
  1409. for (var i = 0; i < Info.gPassive.length; ++i)
  1410. {
  1411. if (Info.gPassive[i].gDamage.length > 0)
  1412. this.push([Info.Active.Char, Info.Active.ActionType, Info.Active.Skill, Info.Active.gItem],
  1413. Info.gPassive[i].gDamage);
  1414. }
  1415. }
  1416. },
  1417. Show: function()
  1418. {
  1419. if (this._gInfo.length > 0)
  1420. {
  1421. this.CalculateValue();
  1422. this.sort();
  1423. return this.CreateTable(Local.Text_Table_Damage, "stat_damage",
  1424. [Local.Text_Table_Char, Local.Text_Table_AttackType, Local.Text_Table_Skill, Local.Text_Table_Item]);
  1425. }
  1426. return "";
  1427. }
  1428. }
  1429. });
  1430.  
  1431.  
  1432. var CILHeal = DefineClass({
  1433. extend: CInfoList,
  1434. construct: function(nKeys, CValueList) {this.superclass(nKeys, CValueList);},
  1435. methods:
  1436. {
  1437. SaveInfo: function(Info)
  1438. {
  1439. if (Info.Active.ActionType.GetKind() === 1)
  1440. {
  1441. for (var i = 0; i < Info.gPassive.length; ++i)
  1442. {
  1443. if (Info.gPassive[i].nHealedHP != null || Info.gPassive[i].nHealedMP != null)
  1444. this.push([Info.Active.Char, Info.Active.Skill, Info.Active.gItem],
  1445. [Info.gPassive[i].nHealedHP, Info.gPassive[i].nHealedMP]);
  1446. }
  1447. }
  1448. },
  1449. Show: function()
  1450. {
  1451. if (this._gInfo.length > 0)
  1452. {
  1453. this.CalculateValue();
  1454. this.sort();
  1455. return this.CreateTable(Local.Text_Table_Heal, "stat_heal",
  1456. [Local.Text_Table_Char, Local.Text_Table_Skill, Local.Text_Table_Item]);
  1457. }
  1458. return "";
  1459. }
  1460. }
  1461. });
  1462.  
  1463.  
  1464. var CILHealed = DefineClass({
  1465. extend: CInfoList,
  1466. construct: function(nKeys, CValueList) {this.superclass(nKeys, CValueList);},
  1467. methods:
  1468. {
  1469. SaveInfo: function(Info)
  1470. {
  1471. if (Info.Active.ActionType.GetKind() === 1)
  1472. {
  1473. for (var i = 0; i < Info.gPassive.length; ++i)
  1474. {
  1475. if (Info.gPassive[i].nHealedHP != null || Info.gPassive[i].nHealedMP != null)
  1476. this.push([Info.gPassive[i].Char],
  1477. [Info.gPassive[i].nHealedHP, Info.gPassive[i].nHealedMP]);
  1478. }
  1479. }
  1480. },
  1481. Show: function()
  1482. {
  1483. if (this._gInfo.length > 0)
  1484. {
  1485. this.CalculateValue();
  1486. this.sort();
  1487. return this.CreateTable(Local.Text_Table_Healed, "stat_healed", [Local.Text_Table_Char]);
  1488. }
  1489. return "";
  1490. }
  1491. }
  1492. });
  1493.  
  1494.  
  1495. var CILItemDamage = DefineClass({
  1496. extend: CInfoList,
  1497. construct: function(nKeys, CValueList) {this.superclass(nKeys, CValueList);},
  1498. methods:
  1499. {
  1500. _SetTableBodyCellContents: function()
  1501. {
  1502. for (var i = 0; i < this._gInfo.length; ++i)
  1503. {
  1504. var gBodyCellContent = [];
  1505. for (var j = 0; j < this._gInfo[i].gKey.length; ++j)
  1506. gBodyCellContent.push( this._gInfo[i].gKey[j] );
  1507.  
  1508. gBodyCellContent.push( this._gInfo[i].ValueList.AvgValueStr());
  1509.  
  1510. this._Table.SetBodyCellContents.apply(this._Table, gBodyCellContent);
  1511. }
  1512. },
  1513. SaveInfo: function(Info)
  1514. {
  1515. if (Info.Active.ActionType.GetKind() === 0)
  1516. {
  1517. for (var i = 0; i < Info.gPassive.length; ++i)
  1518. {
  1519. if (Info.gPassive[i].nItemDamage != null)
  1520. this.push([Info.gPassive[i].Char, Info.gPassive[i].DamagedItem],
  1521. Info.gPassive[i].nItemDamage);
  1522. }
  1523. }
  1524. },
  1525. Show: function()
  1526. {
  1527. if (this._gInfo.length > 0)
  1528. {
  1529. this.CalculateValue();
  1530. this.sort();
  1531. return this.CreateTable(Local.Text_Table_DamagedItems, "stat_item_damage",
  1532. [Local.Text_Table_Char, Local.Text_Table_Item]);
  1533. }
  1534. return "";
  1535. },
  1536. CreateTable: function(Title, Id, gKeyName)
  1537. {
  1538. // Key1, Key2, ..., nDamage
  1539. this._Table = new CTable(Title, Id, this._nKeys + 1);
  1540.  
  1541. var gHeadCellContent = new Array(this._nKeys + 1);
  1542. for (var i = 0; i < this._nKeys; ++i)
  1543. gHeadCellContent[i] = gKeyName[i];
  1544. gHeadCellContent[this._nKeys] = Local.Text_Table_ItemDamagePoints;
  1545. this._Table.SetHeadCellContents.apply(this._Table, gHeadCellContent);
  1546.  
  1547. var gBodyCellContentType = new Array(this._nKeys + 1);
  1548. for (var i = 0; i < this._nKeys; ++i)
  1549. gBodyCellContentType[i] = "string";
  1550. gBodyCellContentType[this._nKeys] = "number";
  1551. this._Table.SetBodyCellContentTypes.apply(this._Table, gBodyCellContentType);
  1552.  
  1553. this._SetTableBodyCellContents();
  1554.  
  1555. return this._Table.CreateHTML();
  1556. },
  1557. push: function(gKey, Value)
  1558. {
  1559. var ValueList = new this._CValueList();
  1560. ValueList.push(Value);
  1561. return this._gInfo.push(new CInfoList._CInfo(gKey, ValueList));
  1562. }
  1563. }
  1564. });
  1565.  
  1566.  
  1567. // FUNCTIONS //////////////////////////////////////////////////////////////////
  1568.  
  1569. function CountStat(Document, bLastSubPage)
  1570. {
  1571. // Read the last round only when reading the last sub page
  1572. if (!bLastSubPage) RemoveLastRound(Document);
  1573.  
  1574. var Navi = new CNavi(0, 0, 0, 0);
  1575.  
  1576. var allRows = Document.getElementsByTagName("tr");
  1577. for (var i = 0; i < allRows.length; ++i)
  1578. {
  1579. var Info = new CActionInfo(Navi);
  1580.  
  1581. var IniColumn = first_child(allRows[i]);
  1582. GetIniInfo(IniColumn, Info);
  1583. if (Info.Active.nIniRoll == null) // not a initiative column
  1584. continue;
  1585. ++Info.Navi.nRow;
  1586.  
  1587. var ActiveColumn = node_after(IniColumn);
  1588. GetActiveInfo(ActiveColumn, Info);
  1589.  
  1590. switch (Info.Active.ActionType.GetKind())
  1591. {
  1592. case 0: // Attack
  1593. {
  1594. var PassiveColumn = node_after(ActiveColumn);
  1595. GetAttackedInfo(PassiveColumn, Info);
  1596. break;
  1597. }
  1598. case 1: // Heal
  1599. case 2: // Buff
  1600. {
  1601. var PassiveColumn = node_after(ActiveColumn);
  1602. GetHealedBuffedInfo(PassiveColumn, Info);
  1603. break;
  1604. }
  1605. case 3: // Wait
  1606. default: // Unknown
  1607. ;
  1608. }
  1609. Stat.SaveInfo(Info);
  1610. }
  1611. }
  1612.  
  1613.  
  1614. function RemoveLastRound(Document)
  1615. {
  1616. var allRows = Document.getElementsByTagName("tr");
  1617. for (var i = 0; i < allRows.length; ++i)
  1618. {
  1619. if (allRows[i].className != null &&
  1620. allRows[i].className.indexOf("content_table_row_") === 0)
  1621. {
  1622. var allH1 = allRows[i].getElementsByTagName("h1");
  1623. if (allH1[0] != null &&
  1624. allH1[0].firstChild != null &&
  1625. allH1[0].firstChild.nodeType == 3 &&
  1626. allH1[0].firstChild.data == Local.OrigText_LastRound)
  1627. {
  1628. allRows[i].parentNode.removeChild(allRows[i]);
  1629. break;
  1630. }
  1631. }
  1632. }
  1633. }
  1634.  
  1635.  
  1636. // return: true: it's not a initiative column, or it's a initiative column and the format is right
  1637. // false: it's a initiative column but the format is wrong
  1638. function GetIniInfo(Node, Info)
  1639. {
  1640. if (Node == null || Node.className != "rep_initiative")
  1641. return true;
  1642.  
  1643. if (Node.innerHTML == "&nbsp;")
  1644. return true;
  1645.  
  1646. // \1 ini
  1647. // \2 current action
  1648. // \3 total actions
  1649. var Patt_Ini = Local.Pattern_Ini;
  1650. var result = Patt_Ini.exec(Node.innerHTML);
  1651. if (result == null)
  1652. {
  1653. DbgMsgAction(Info, "IniInfo: " + Node.innerHTML);
  1654. return false;
  1655. }
  1656.  
  1657. Info.Active.nIniRoll = Number(result[1]);
  1658. Info.Active.nCurrAction = Number(result[2]);
  1659. Info.Active.nTotalActions = Number(result[3]);
  1660. return true;
  1661. }
  1662.  
  1663.  
  1664. // return: whether the format is right
  1665. function GetActiveInfo(Node, Info)
  1666. {
  1667. if (Node == null)
  1668. {
  1669. DbgMsgAction(Info, "ActiveInfo: null");
  1670. return false;
  1671. }
  1672. var nStartNode = 0;
  1673. var Str = Node.innerHTML;
  1674.  
  1675. // \1 span node
  1676. // \2 npc Id
  1677. var Patt_Char = Local.Pattern_Active_Char;
  1678. var result = Patt_Char.exec(Str);
  1679. if (result == null)
  1680. {
  1681. DbgMsgAction(Info, "ActiveInfo (Char): " + Node.innerHTML);
  1682. return true;
  1683. }
  1684. var CharNode = result[1] != null ? Node.childNodes[nStartNode].childNodes[0] :
  1685. Node.childNodes[nStartNode];
  1686. Info.Active.Char = new CChar(CharNode);
  1687. Info.Active.nCharId = result[2] != null ? Number(result[2]) : null;
  1688. nStartNode += result[1] != null ? 1 : (result[2] != null ? 2 : 1);
  1689. Str = Str.substring(result[0].length);
  1690.  
  1691. // \1 attack
  1692. // \2 heal or buff
  1693. // \3 left parenthesis
  1694. var Patt_Action1 = Local.Pattern_Active_Action1;
  1695. result = Patt_Action1.exec(Str);
  1696. if (result == null)
  1697. {
  1698. // \1 other action
  1699. var Patt_Action2 = Local.Pattern_Active_Action2;
  1700. result = Patt_Action2.exec(Str);
  1701. if (result == null)
  1702. {
  1703. DbgMsgAction(Info, "ActiveInfo (Action2): " + Node.innerHTML);
  1704. return false;
  1705. }
  1706. Info.Active.ActionType = new CActionType(result[1]);
  1707. return true;
  1708. }
  1709. if (result[1] != null)
  1710. {
  1711. Info.Active.ActionType = new CActionType(result[1]);
  1712. if (Info.Active.ActionType.GetKind() !== 0)
  1713. {
  1714. DbgMsgAction(Info, "ActiveInfo (Attack Type): " + result[1]);
  1715. return false;
  1716. }
  1717. nStartNode += 1;
  1718. Str = Str.substring(result[0].length);
  1719. }
  1720. else
  1721. {
  1722. Info.Active.ActionType = new CActionType(result[2]);
  1723. if (Info.Active.ActionType.GetKind() !== 1 && Info.Active.ActionType.GetKind() !== 2)
  1724. {
  1725. DbgMsgAction(Info, "ActiveInfo (Heal/Buff Type): " + result[2]);
  1726. return false;
  1727. }
  1728. Info.Active.Skill = new CSkill(Node.childNodes[nStartNode + 1]);
  1729. if (result[3] == null)
  1730. return true;
  1731. nStartNode += 3;
  1732. Str = Str.substring(result[0].length);
  1733. }
  1734.  
  1735. switch (Info.Active.ActionType.GetKind())
  1736. {
  1737. case 0: // attack
  1738. {
  1739. // \1 single roll
  1740. // \2 position n
  1741. // \3 multiple roll n
  1742. // \4 MP
  1743. // \5 item list
  1744. var Patt_ActtackDetails = Local.Pattern_Active_AttackDetails;
  1745. result = Patt_ActtackDetails.exec(Str);
  1746. if (result == null)
  1747. {
  1748. DbgMsgAction(Info, "ActiveInfo (ActtackDetails): " + Node.innerHTML);
  1749. return false;
  1750. }
  1751. Info.Active.Skill = new CSkill(Node.childNodes[nStartNode]);
  1752. Info.Active.nAttackRoll = Number(result[1] != null ? result[1] : result[3]);
  1753. Info.Active.nSkillMP = result[4] != null ? Number(result[4]) : null;
  1754. if (result[5] != null)
  1755. {
  1756. Info.Active.gItem = new CKeyList();
  1757. nStartNode += result[4] != null ? 4 : 2;
  1758. var ItemNode;
  1759. while ((ItemNode = Node.childNodes[nStartNode]) != null)
  1760. {
  1761. Info.Active.gItem.push(new CItem(ItemNode));
  1762. nStartNode += 2;
  1763. }
  1764. }
  1765. return true;
  1766. }
  1767. case 1: // heal
  1768. case 2: // buff
  1769. {
  1770. // \1 MP
  1771. // \2 normal item list
  1772. // \3 magical potion
  1773. var Patt_HealBuffDetails = Local.Pattern_Active_HealBuffDetails;
  1774. result = Patt_HealBuffDetails.exec(Str);
  1775. if (result == null)
  1776. {
  1777. DbgMsgAction(Info, "ActiveInfo (HealBuffDetails): " + Node.innerHTML);
  1778. return false;
  1779. }
  1780. Info.Active.nSkillMP = result[1] != null ? Number(result[1]) : null;
  1781. if (result[2] != null)
  1782. {
  1783. Info.Active.gItem = new CKeyList();
  1784. nStartNode += result[1] != null ? 2 : 0;
  1785. var ItemNode;
  1786. while ((ItemNode = Node.childNodes[nStartNode]) != null)
  1787. {
  1788. Info.Active.gItem.push(new CItem(ItemNode));
  1789. nStartNode += 2;
  1790. }
  1791. }
  1792. else if (result[3] != null)
  1793. {
  1794. Info.Active.gItem = new CKeyList();
  1795. nStartNode += result[1] != null ? 2 : 0;
  1796. Info.Active.gItem.push(new CItem(Node.childNodes[nStartNode]));
  1797. // nStartNode: determine by the number of reagents
  1798. }
  1799. return true;
  1800. }
  1801. default:// impossible, the value can only be 0, 1, or 2
  1802. return false;
  1803. }
  1804. }
  1805.  
  1806.  
  1807. // return: whether the format is right
  1808. function GetAttackedInfo(Node, Info)
  1809. {
  1810. if (Node == null)
  1811. {
  1812. DbgMsgAction(Info, "AttackedInfo: null");
  1813. return false;
  1814. }
  1815. var nStartNode = 0;
  1816. var Str = Node.innerHTML;
  1817.  
  1818. // \1 char span node
  1819. // \2 char Id
  1820. // \3 skill
  1821. // \4 defence roll
  1822. // \5 MP
  1823. // \6 item list
  1824. // \7 hit type
  1825. // \8 struck down
  1826. // \9 damage list
  1827. // \10 item damage
  1828. // \11 next flag
  1829. var Patt_Attacked = Local.Pattern_Passive_Attacked;
  1830. var bEnd = false;
  1831. while (!bEnd)
  1832. {
  1833. var PassiveInfo = new CPassiveInfo();
  1834. var result = Patt_Attacked.exec(Str);
  1835. if (result == null)
  1836. {
  1837. DbgMsgAction(Info, "AttackedInfo: " + Node.innerHTML);
  1838. return true;
  1839. }
  1840. var CharNode = result[1] != null ? Node.childNodes[nStartNode].childNodes[0] :
  1841. Node.childNodes[nStartNode];
  1842. PassiveInfo.Char = new CChar(CharNode);
  1843. PassiveInfo.nCharId = result[2] != null ? Number(result[2]) : null;
  1844. nStartNode += result[1] != null ? 1 : (result[2] != null ? 2 : 1);
  1845. if (result[3] != null)
  1846. {
  1847. PassiveInfo.Skill = new CSkill(Node.childNodes[nStartNode +1]);
  1848. nStartNode += 2;
  1849. }
  1850. PassiveInfo.nDefenceRoll = Number(result[4]);
  1851. if (result[5] != null)
  1852. {
  1853. PassiveInfo.nSkillMP = Number(result[5]);
  1854. nStartNode += 2;
  1855. }
  1856. if (result[6] != null)
  1857. {
  1858. PassiveInfo.gItem = new CKeyList();
  1859. nStartNode += 1;
  1860. var ItemNode = Node.childNodes[nStartNode];
  1861. while (ItemNode != null && ItemNode.nodeName == "A")
  1862. {
  1863. PassiveInfo.gItem.push(new CItem(ItemNode));
  1864. nStartNode += 2;
  1865. ItemNode = Node.childNodes[nStartNode];
  1866. }
  1867. }
  1868. else
  1869. nStartNode += 1;
  1870. PassiveInfo.HitType = new CHitType(result[7]);
  1871. PassiveInfo.bStruckDown = (result[8] != null);
  1872. nStartNode += result[8] != null ? 2 : 1;
  1873. if (result[9] != null)
  1874. {
  1875. PassiveInfo.gDamage = [];
  1876. nStartNode += 1;
  1877. var DamageNode = Node.childNodes[nStartNode];
  1878. while (DamageNode != null && (DamageNode.nodeType == 3 ||
  1879. (DamageNode.nodeName == "SPAN" &&
  1880. DamageNode.firstChild != null && DamageNode.firstChild.nodeType == 3)))
  1881. {
  1882. PassiveInfo.gDamage.push(new CDamage(DamageNode));
  1883. nStartNode += 2;
  1884. DamageNode = Node.childNodes[nStartNode];
  1885. }
  1886. nStartNode -= 1;
  1887. }
  1888. if (result[10] != null)
  1889. {
  1890. PassiveInfo.DamagedItem = new CItem(Node.childNodes[nStartNode +1]);
  1891. PassiveInfo.nItemDamage = Number(result[10]);
  1892. nStartNode += 3;
  1893. }
  1894. if (result[11] != null)
  1895. nStartNode += 1;
  1896. else
  1897. bEnd = true;
  1898.  
  1899. Info.gPassive.push(PassiveInfo);
  1900. Str = Str.substring(result[0].length);
  1901. }
  1902. return true;
  1903. }
  1904.  
  1905.  
  1906. // return: whether the format is right
  1907. function GetHealedBuffedInfo(Node, Info)
  1908. {
  1909. if (Node == null)
  1910. {
  1911. DbgMsgAction(Info, "HealedBuffedInfo: null");
  1912. return false;
  1913. }
  1914. var nStartNode = 0;
  1915. var Str = Node.innerHTML;
  1916.  
  1917. // \1 span node
  1918. // \2 char Id
  1919. // \3 self
  1920. // \4 HP
  1921. // \5 MP
  1922. // \6 next flag
  1923. var Patt_HealedBuffed = Local.Pattern_Passive_Healed_Buffed;
  1924. var bEnd = false;
  1925. while (!bEnd)
  1926. {
  1927. var PassiveInfo = new CPassiveInfo();
  1928. var result = Patt_HealedBuffed.exec(Str);
  1929. if (result == null)
  1930. {
  1931. DbgMsgAction(Info, "HealedBuffedInfo: " + Node.innerHTML);
  1932. return true;
  1933. }
  1934. if (result[3] != null)
  1935. {
  1936. PassiveInfo.Char = Info.Active.Char;
  1937. PassiveInfo.nCharId = Info.Active.nCharId;
  1938. }
  1939. else
  1940. {
  1941. var CharNode = result[1] != null ? Node.childNodes[nStartNode].childNodes[0] :
  1942. Node.childNodes[nStartNode];
  1943. PassiveInfo.Char = new CChar(CharNode);
  1944. PassiveInfo.nCharId = result[2] != null ? Number(result[2]) : null;
  1945. nStartNode += result[1] != null ? 1 : (result[2] != null ? 2 : 1);
  1946. }
  1947. PassiveInfo.nHealedHP = result[4] != null ? Number(result[4]) : null;
  1948. PassiveInfo.nHealedMP = result[5] != null ? Number(result[5]) : null;
  1949. nStartNode += 1;
  1950. if (result[6] != null)
  1951. nStartNode += 1;
  1952. else
  1953. bEnd = true;
  1954.  
  1955. Info.gPassive.push(PassiveInfo);
  1956. Str = Str.substring(result[0].length);
  1957. }
  1958. return true;
  1959. }
  1960.  
  1961.  
  1962. function DbgMsgAction(Info, Text)
  1963. {
  1964. if (DEBUG)
  1965. alert("[" + Info.Navi.nLevel + "." + Info.Navi.nRoom + "." +
  1966. Info.Navi.nRound + "." + Info.Navi.nRow + "] " + Text);
  1967. }
  1968.  
  1969.  
  1970. // GLOBAL VARIABLES ///////////////////////////////////////////////////////////
  1971.  
  1972. var DEBUG = false;
  1973.  
  1974. var Contents = {
  1975. OrigText_Button_DungeonDetails : ["details",
  1976. "详细资料"],
  1977. OrigText_Button_DuelDetails : ["Details",
  1978. "详细"],
  1979. OrigText_Button_DungeonStat : ["statistics",
  1980. "统计表"],
  1981. OrigText_Level : ["Level",
  1982. "层数"],
  1983. OrigText_LastRound : ["Last round:",
  1984. "最后回合:"],
  1985. OrigTextList_ActionType : [["attacks", "ranged attacks", "attacks with magic", "socially attacks", "cunningly attacks", "activates on", "works as a force of nature upon", "infected", "casts an explosion at", "deactivated", "magic projectile", "curse", "scare", "heals with", "uses", "summons with", "is unable to do anything.", "looks around in boredom and waits."],
  1986. ["近战攻击", "远程攻击", "魔法攻击", "心理攻击", "偷袭", "触发", "作为自然灾害", "散布", "制造爆炸", "解除", "魔法投射", "诅咒", "恐吓", "治疗", "使用", "召唤", "不能执行任何动作.", "无聊的打量四周,等待着."]],
  1987. OrigTextList_DamageType : [["crushing damage", "cutting damage", "piercing damage", "fire damage", "ice damage", "lightning damage", "poison damage", "acid damage", "psychological damage", "holy damage", "disarm trap", "mana damage"],
  1988. ["粉碎伤害", "切割伤害", "穿刺伤害", "火焰伤害", "寒冰伤害", "闪电伤害", "毒素伤害", "酸性伤害", "心灵伤害", "神圣伤害", "陷阱伤害", "法力伤害"]],
  1989. Pattern_Ini : [/^Initiative ([\d]+)<br><span .*?>Action ([\d]+) of ([\d]+)<\/span>$/,
  1990. /^先攻([\d]+)<br><span .*?>第([\d]+)步行动 \/ 共([\d]+)步<\/span>$/],
  1991. Pattern_Active_Char : [/^(<span .*?>)?<a .*?>.*?<\/a>(?:<span .*?>([\d]+)<\/span>)?(?:<img .*?><\/span>)?/,
  1992. /^(<span .*?>)?<a .*?>.*?<\/a>(?:<span .*?>([\d]+)<\/span>)?(?:<img .*?><\/span>)?/],
  1993. Pattern_Active_Action1 : [/^\s*(?:([A-Za-z][A-Za-z ]+[A-Za-z]) +\(|([A-Za-z][A-Za-z ]+[A-Za-z]) +<a .*?>.*?<\/a>(?:( \()|$| on $))/,
  1994. /^\s*(?:([^\u0000-\u007F]+) +\(|([^\u0000-\u007F]+)<a .*?>.*?<\/a>(?:( \()|$|给$))/],
  1995. Pattern_Active_Action2 : [/^\s*([\S].*[\S])\s*$/,
  1996. /^\s*([\S].*[\S])\s*$/],
  1997. Pattern_Active_AttackDetails : [/^<a .*?>.*?<\/a>(?:\/([\d]+)|(?:\/([A-Za-z ]+): ([\d]+))+)(?:\/<span .*?>([\d]+) MP<\/span>)?(\/(?:<a .*?>.*?<\/a>,)*<a .*?>.*?<\/a>)?\)$/,
  1998. /^<a .*?>.*?<\/a>(?:\/([\d]+)|(?:\/([^\u0000-\u007F]+): ([\d]+))+)(?:\/<span .*?>([\d]+) 法力<\/span>)?(\/(?:<a .*?>.*?<\/a>,)*<a .*?>.*?<\/a>)?\)$/],
  1999. Pattern_Active_HealBuffDetails : [/^(?:<span .*?>([\d]+) MP<\/span>)?(?:\/)?(?:((<a .*?>.*?<\/a>,)*<a .*?>.*?<\/a>)|(<a .*?>.*?<\/a>\s+(?:<img .*?>)+))?\)(?: on )?$/,
  2000. /^(?:<span .*?>([\d]+) 法力<\/span>)?(?:\/)?(?:((<a .*?>.*?<\/a>,)*<a .*?>.*?<\/a>)|(<a .*?>.*?<\/a>\s+(?:<img .*?>)+))?\)(?:给)?$/],
  2001. Pattern_Passive_Attacked : [/^(<span .*?>)?<a .*?>.*?<\/a>(?:<span .*?>([\d]+)<\/span>)?(?:<img .*?><\/span>)?\s*\((<a .*?>.*?<\/a>\/)?([\d]+)(?:\/<span .*?>([\d]+) MP<\/span>)?(\/(?:<a .*?>.*?<\/a>,)*<a .*?>.*?<\/a>)?\): <span class="([A-Za-z_]+)">[A-Za-z ]+<\/span>( - [A-Za-z ]+)?(<br>(?:<span .*?>)?(?:-)?[\d]+ (?:\[(?:\+|-)[\d]+\] )?[A-Za-z ]+(?:<img .*?><\/span>)?)*(?:<br><a .*?>.*?<\/a> -([\d]+) HP)?(?:(<br>)|$)/,
  2002. /^(<span .*?>)?<a .*?>.*?<\/a>(?:<span .*?>([\d]+)<\/span>)?(?:<img .*?><\/span>)?\s*\((<a .*?>.*?<\/a>\/)?([\d]+)(?:\/<span .*?>([\d]+) 法力<\/span>)?(\/(?:<a .*?>.*?<\/a>,)*<a .*?>.*?<\/a>)?\): <span class="([A-Za-z_]+)">[^\u0000-\u007F]+<\/span>( - [^\u0000-\u007F]+ *)?(<br>(?:<span .*?>)?(?:-)?[\d]+ (?:\[(?:\+|-)[\d]+\] )?[^\u0000-\u007F]+(?:<img .*?><\/span>)?)*(?:<br><a .*?>.*?<\/a> -([\d]+) HP)?(?:(<br>)|$)/],
  2003. Pattern_BasicDamage : [/causes: <b>([\d]+)<\/b>/,
  2004. /造成: <b>([\d]+)<\/b>/],
  2005. Pattern_Damage : [/^((?:-)?[\d]+) (?:\[((?:\+|-)[\d]+)\] )?([A-Za-z][A-Za-z ]+[A-Za-z])$/,
  2006. /^((?:-)?[\d]+) (?:\[((?:\+|-)[\d]+)\] )?([^\u0000-\u007F]+)$/],
  2007. Pattern_Passive_Healed_Buffed : [/^(?:(<span .*?>)?<a .*?>.*?<\/a>(?:<span .*?>([\d]+)<\/span>)?(?:<img .*?><\/span>)?\s+|(themselves))(?: \+([\d]+) HP)?(?: \+([\d]+) MP)?(?:(<br>)|$)/,
  2008. /^(?:(<span .*?>)?<a .*?>.*?<\/a>(?:<span .*?>([\d]+)<\/span>)?(?:<img .*?><\/span>)?\s+|(自己))(?: \+([\d]+) HP)?(?: \+([\d]+) 法力)?(?:(<br>)|$)/],
  2009. Text_Button_ExtraStat : ["Extra Stat",
  2010. "额外统计"],
  2011. Text_Button_EntireStat : ["Entire Extra Stat",
  2012. "全城额外统计"],
  2013. Text_Button_Show : ["Show",
  2014. "显示"],
  2015. Text_Button_Default : ["Default",
  2016. "默认"],
  2017. TextList_AttackType : [["melee", "ranged", "spell", "social", "ambush", "trap", "nature", "disease", "detonate","disarm trap", "magic projectile", "curse", "scare"],
  2018. ["近战", "远程", "魔法", "心理", "偷袭", "陷阱", "自然", "疾病", "爆破", "解除陷阱", "魔法投射", "诅咒", "恐吓"]],
  2019. TextList_HitType : [["failed", "success", "good success", "critical success"],
  2020. ["闪避", "普通", "重击", "致命一击"]],
  2021. Text_Loading : ["Loading",
  2022. "载入中"],
  2023. Text_Options : ["Options:",
  2024. "选项:"],
  2025. Text_DefaultMsg : ["All the data this script stored in your machine has been cleared.",
  2026. "此脚本储存在你的机器上的所有数据已被清除。"],
  2027. Text_Table_Ini : ["Initiative",
  2028. "先攻权"],
  2029. Text_Table_Attack : ["Attack",
  2030. "攻击骰"],
  2031. Text_Table_Defence : ["Defence",
  2032. "防御骰"],
  2033. Text_Table_Damage : ["Damage",
  2034. "伤害"],
  2035. Text_Table_Heal : ["Healing By The Hero",
  2036. "给予治疗"],
  2037. Text_Table_Healed : ["Healing On The Hero",
  2038. "接受治疗"],
  2039. Text_Table_DamagedItems : ["Damaged Items",
  2040. "物品损坏"],
  2041. Text_Table_Char : ["Character",
  2042. "人物"],
  2043. Text_Table_AttackType : ["Attack type",
  2044. "攻击类型"],
  2045. Text_Table_DefenceType : ["Defence type",
  2046. "防御类型"],
  2047. Text_Table_Skill : ["Skill",
  2048. "技能"],
  2049. Text_Table_Item : ["Item",
  2050. "物品"],
  2051. Text_Table_AvgRoll : ["Average roll",
  2052. "平均值"],
  2053. Text_Table_Times : ["Times",
  2054. "次数"],
  2055. Text_Table_RollList : ["Roll list",
  2056. "数值列表"],
  2057. Text_Table_ItemDamagePoints : ["Damage Points",
  2058. "损坏点数"]
  2059. };
  2060.  
  2061. var Style = "div.stat_header {margin:1em auto 0.5em auto;} " +
  2062. "span.stat_title {margin: auto 1em auto 0em; font-size:20px; font-weight:bold; color:#FFF;} span.clickable {cursor:pointer;} " +
  2063. "table[hide] {display:none;} " +
  2064. "table.pair_value {width:100%;} table.pair_value td {width:50%; min-width:3em; text-align:right; color:#F8A400;} table.pair_value td + td {color:#00CC00;} ";
  2065.  
  2066. var Local;
  2067. var Stat;
  2068.  
  2069. try {Main();} catch(e) {alert("Main(): " + e);}
  2070.  
  2071.  
  2072. // FUNCTIONS //////////////////////////////////////////////////////////////////
  2073. if( typeof(GM_addStyle)=='undefined' ){function GM_addStyle(styles){
  2074. var S = document.createElement('style');
  2075. S.type = 'text/css';
  2076. var T = ''+styles+'';
  2077. T = document.createTextNode(T)
  2078. S.appendChild(T);
  2079. document.body.appendChild(S);
  2080. return;
  2081. }}
  2082.  
  2083. if (!this.GM_getValue || this.GM_getValue.toString().indexOf("not supported")>-1) {
  2084. this.GM_getValue=function (key,def) {
  2085. return localStorage[key] || def;
  2086. };
  2087. this.GM_setValue=function (key,value) {
  2088. return localStorage[key]=value;
  2089. };
  2090. }
  2091. function Main()
  2092. {
  2093. // Language selection
  2094. Local = GetLocalContents(Contents);
  2095. if (Local === null) return;
  2096. //GM_log(Local);
  2097. // Add CSS
  2098. GM_addStyle(Style);
  2099.  
  2100. // Add buttons
  2101. var KeyButton = AddButtonBesideDisabledButton(
  2102. [Local.OrigText_Button_DungeonDetails, Local.Text_Button_ExtraStat, OnCountStat],
  2103. [Local.OrigText_Button_DungeonStat, Local.Text_Button_EntireStat, OnCountEntireStat],
  2104. [Local.OrigText_Button_DuelDetails, Local.Text_Button_ExtraStat, OnCountStat]);
  2105. if (KeyButton === null) return;
  2106.  
  2107. // Stat initialization
  2108. Stat = new CStat( node_after(KeyButton.parentNode) );
  2109. Stat.RegInfoList(new CILIni( 1, CVLNumber));
  2110. Stat.RegInfoList(new CILAttackRoll( 4, CVLNumber));
  2111. Stat.RegInfoList(new CILDefenceRoll( 4, CVLNumber));
  2112. Stat.RegInfoList(new CILDamage( 4, CVLDamage));
  2113. Stat.RegInfoList(new CILHeal( 3, CVLPairNumber));
  2114. Stat.RegInfoList(new CILHealed( 1, CVLPairNumber));
  2115. Stat.RegInfoList(new CILItemDamage( 2, CVLNumber));
  2116. }
  2117.  
  2118.  
  2119. // It will only add the first eligible button
  2120. // return: the node of the first eligible disabled button, or null if didn't find anyone
  2121. function AddButtonBesideDisabledButton(/* [DisabledButtonText, ButtonText, ClickEvent], [...], ... */)
  2122. {
  2123. var allInputs = document.getElementsByTagName("input");
  2124. for (var i = 0; i < allInputs.length; ++i)
  2125. {
  2126. if (allInputs[i].className == "button_disabled")
  2127. {
  2128. for (var j = 0; j < arguments.length; ++j)
  2129. {
  2130. if (allInputs[i].getAttribute("value") == arguments[j][0])
  2131. {
  2132. AddButton(allInputs[i], arguments[j][1], arguments[j][2]);
  2133. return allInputs[i];
  2134. }
  2135. }
  2136. }
  2137. }
  2138. return null;
  2139. }
  2140.  
  2141.  
  2142. // Add a button to the end of the given node's parent node
  2143. function AddButton(SiblingNode, Value, OnClick)
  2144. {
  2145. var newButton = document.createElement("input");
  2146. newButton.setAttribute("type", "button");
  2147. newButton.setAttribute("class", "button");
  2148. newButton.setAttribute("value", Value);
  2149. newButton.addEventListener("click", OnClick, false);
  2150. var newBlank = document.createTextNode(" ");
  2151. SiblingNode.parentNode.appendChild(newBlank);
  2152. SiblingNode.parentNode.appendChild(newButton);
  2153. }
  2154.  
  2155.  
  2156. function OnCountStat()
  2157. {
  2158. try {
  2159. if (this.className == "button_disabled")
  2160. return;
  2161. else
  2162. this.className = "button_disabled";
  2163.  
  2164. Stat.nTotalPages = 1;
  2165. ReadPage(document, true);
  2166. }
  2167. catch (e) {alert("OnCountStat(): " + e);}
  2168. }
  2169.  
  2170.  
  2171. function OnCountEntireStat()
  2172. {
  2173. try {
  2174. if (this.className == "button_disabled")
  2175. return;
  2176. else
  2177. this.className = "button_disabled";
  2178.  
  2179. CountEntireStat();
  2180. }
  2181. catch (e) {alert("OnCountEntireStat(): " + e);}
  2182. }
  2183.  
  2184.  
  2185. function CountEntireStat()
  2186. {
  2187. var nCurrRepId = GetHiddenInfo(document, "report_id[0]", "");
  2188. var nMaxLevel = Stat.nTotalPages = GetStatPageMaxLevel(document, 1);
  2189.  
  2190. for (var CurrLevel = 1; CurrLevel <= nMaxLevel; ++CurrLevel)
  2191. GetPage(nCurrRepId, CurrLevel, 1, true);
  2192.  
  2193. Stat.ShowProgress();
  2194. }
  2195.  
  2196.  
  2197. function GetPage(nRepId, nLevel, nRepPage, bFirstRead)
  2198. {
  2199. var XmlHttp = new XMLHttpRequest();
  2200.  
  2201. XmlHttp.onreadystatechange = function ()
  2202. {
  2203. try {
  2204. if (XmlHttp.readyState == 4 && XmlHttp.status == 200)
  2205. {
  2206. var Page = document.createElement("div");
  2207. Page.innerHTML = XmlHttp.responseText;
  2208. ReadPage(Page, bFirstRead);
  2209. }
  2210. }
  2211. catch (e) {alert("XMLHttpRequest.onreadystatechange(): " + e);}
  2212. };
  2213.  
  2214. var URL = location.protocol + "//" + location.host + "/wod/spiel/dungeon/report.php" +
  2215. "?cur_rep_id=" + nRepId +
  2216. "&gruppe_id=&current_level=" + nLevel +
  2217. "&REPORT_PAGE=" + nRepPage +
  2218. "&IS_POPUP=1";
  2219.  
  2220. XmlHttp.open("GET", URL, true);
  2221. XmlHttp.send(null);
  2222. }
  2223.  
  2224.  
  2225. function ReadPage(Document, bFirstRead)
  2226. {
  2227. var ret = GetRepPageInfo(Document, [1, 1]);
  2228. var nCurrRepPage = ret[0];
  2229. var nMaxRepPage = ret[1];
  2230.  
  2231. if (bFirstRead && nMaxRepPage > 1)
  2232. {
  2233. var nRepId = GetHiddenInfo(Document, "report_id[0]", "");
  2234. var nLevel = GetHiddenInfo(Document, "current_level", 1);
  2235.  
  2236. Stat.nTotalPages += nMaxRepPage -1;
  2237. for (var i = 1; i <= nMaxRepPage; ++i)
  2238. {
  2239. if (i !== nCurrRepPage)
  2240. GetPage(nRepId, nLevel, i, false);
  2241. }
  2242. }
  2243.  
  2244. CountStat(Document, (nCurrRepPage === nMaxRepPage));
  2245. if (++Stat.nReadPages >= Stat.nTotalPages)
  2246. Stat.Show();
  2247. else
  2248. Stat.ShowProgress();
  2249. }
  2250.  
  2251.  
  2252. function GetHiddenInfo(Document, InfoName, DefaultValue)
  2253. {
  2254. var allInputs = Document.getElementsByTagName("input");
  2255. for (var i = 0; i < allInputs.length; ++i)
  2256. {
  2257. if (allInputs[i].getAttribute("type") == "hidden" &&
  2258. allInputs[i].name == InfoName)
  2259. return allInputs[i].value;
  2260. }
  2261. return DefaultValue;
  2262. }
  2263.  
  2264.  
  2265. function GetStatPageMaxLevel(Document, DefaultValue)
  2266. {
  2267. var allTds = Document.getElementsByTagName("td");
  2268. for (var i = 0; i < allTds.length; ++i)
  2269. {
  2270. if (first_child(allTds[i].parentNode) != allTds[i])
  2271. continue;
  2272. var LevelNode = first_child(allTds[i]);
  2273. if (LevelNode != null && LevelNode.nodeType == 3 && LevelNode.data == Local.OrigText_Level)
  2274. {
  2275. var Patt_Level = /^(?:<span .*?>)?(?:[\d]+)\/([\d]+)(?:<\/span>)?$/;
  2276. var result = Patt_Level.exec(node_after(allTds[i]).innerHTML);
  2277. if (result == null) return DefaultValue;
  2278. return Number(result[1]);
  2279. }
  2280. }
  2281. return DefaultValue;
  2282. }
  2283.  
  2284.  
  2285. // return: an array, [0]: nCurrRepPage, [1]: nMaxRepPage
  2286. function GetRepPageInfo(Document, DefaultValue)
  2287. {
  2288. var ret = [DefaultValue[0], DefaultValue[1]];
  2289.  
  2290. var SubPageIndexNode;
  2291. var allInputs = Document.getElementsByTagName("input");
  2292. for (var i = 0; i < allInputs.length; ++i)
  2293. {
  2294. if (allInputs[i].value.indexOf("=1=") !== -1)
  2295. {
  2296. SubPageIndexNode = allInputs[i];
  2297. break;
  2298. }
  2299. }
  2300. if (SubPageIndexNode == null)
  2301. return ret;
  2302.  
  2303. var bIndexEnd = false;
  2304. while (!bIndexEnd)
  2305. {
  2306. var IndexPatt = /=([\d]+)=/;
  2307. var target = (SubPageIndexNode.value == null)? SubPageIndexNode.firstChild.textContent:SubPageIndexNode.value;
  2308. var Result = IndexPatt.exec(target);
  2309. var nCurrIndex = Number(Result[1]);
  2310.  
  2311. if (SubPageIndexNode.className == "paginator_selected clickable")
  2312. ret[0] = nCurrIndex;
  2313.  
  2314. SubPageIndexNode = node_after(node_after(SubPageIndexNode));
  2315. if (SubPageIndexNode == null || SubPageIndexNode.nodeName != "A")
  2316. {
  2317. ret[1] = nCurrIndex;
  2318. bIndexEnd = true;
  2319. }
  2320. }
  2321.  
  2322. return ret;
  2323. }