You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
5.6 KiB

  1. var generateUUID = (function() {
  2. "use strict";
  3. var a = 0, b = [];
  4. return function() {
  5. var c = (new Date()).getTime() + 0, d = c === a;
  6. a = c;
  7. for (var e = new Array(8), f = 7; 0 <= f; f--) {
  8. e[f] = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".charAt(c % 64);
  9. c = Math.floor(c / 64);
  10. }
  11. c = e.join("");
  12. if (d) {
  13. for (f = 11; 0 <= f && 63 === b[f]; f--) {
  14. b[f] = 0;
  15. }
  16. b[f]++;
  17. } else {
  18. for (f = 0; 12 > f; f++) {
  19. b[f] = Math.floor(64 * Math.random());
  20. }
  21. }
  22. for (f = 0; 12 > f; f++){
  23. c += "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".charAt(b[f]);
  24. }
  25. return c;
  26. };
  27. }()),
  28. generateRowID = function () {
  29. "use strict";
  30. return generateUUID().replace(/_/g, "Z");
  31. };
  32. var addAttr = function(char_id, name, value, max) {
  33. let obj = {
  34. name: name,
  35. current: value,
  36. characterid: char_id
  37. };
  38. if(max) {
  39. obj.max = max;
  40. }
  41. return createObj("attribute", obj);
  42. };
  43. on("chat:message", function(msg) {
  44. if(msg.type == "api" && msg.content.indexOf("!acksimport ") !== -1) {
  45. var data = msg.content.replace("!acksimport ", "");
  46. var npcs = JSON.parse(data);
  47. for(let c of npcs) {
  48. sendChat(msg.who, "Creating NPC: " + c.name);
  49. // Create the character sheet for this NPC
  50. let sheet = createObj("character", {
  51. name: c.name
  52. });
  53. sheet.set('bio', "A generated npc character.");
  54. sheet.set('gmnotes', "Generated by Atr0phyACKS");
  55. // Add all of their attributes and mods
  56. addAttr(sheet.id, "str", c.attributes.str, null);
  57. addAttr(sheet.id, "int", c.attributes.int, null);
  58. addAttr(sheet.id, "wis", c.attributes.wis, null);
  59. addAttr(sheet.id, "dex", c.attributes.dex, null);
  60. addAttr(sheet.id, "con", c.attributes.con, null);
  61. addAttr(sheet.id, "chr", c.attributes.chr, null);
  62. addAttr(sheet.id, "str_mod", c.attribute_mods.str, null);
  63. addAttr(sheet.id, "int_mod", c.attribute_mods.int, null);
  64. addAttr(sheet.id, "wis_mod", c.attribute_mods.wis, null);
  65. addAttr(sheet.id, "dex_mod", c.attribute_mods.dex, null);
  66. addAttr(sheet.id, "con_mod", c.attribute_mods.con, null);
  67. addAttr(sheet.id, "chr_mod", c.attribute_mods.chr, null);
  68. // Add their Hit Points
  69. addAttr(sheet.id, "hp", c.hp, c.hp);
  70. // Set the guild and level
  71. addAttr(sheet.id, "class", c.guild, null);
  72. addAttr(sheet.id, "level", c.level, null);
  73. addAttr(sheet.id, "align", c.alignment, null);
  74. // Set the AC and attack throw
  75. addAttr(sheet.id, "ac", c.armour.ac_mod, null);
  76. addAttr(sheet.id, "attack_throw", c.attack_throw, null);
  77. addAttr(sheet.id, "attack_throw_vis", c.attack_throw, null);
  78. // Set the saves
  79. addAttr(sheet.id, "save_pp", c.saves.pp, null);
  80. addAttr(sheet.id, "save_pd", c.saves.pd, null);
  81. addAttr(sheet.id, "save_bb", c.saves.bb, null);
  82. addAttr(sheet.id, "save_sw", c.saves.sw, null);
  83. addAttr(sheet.id, "save_sp", c.saves.sp, null);
  84. /* Add our Repeating Sections */
  85. // for armour
  86. let armour_name = "repeating_equipment_" + generateRowID();
  87. addAttr(sheet.id, armour_name + "_equipment_name", c.armour.name, null);
  88. // for weapons
  89. let melee_name = "repeating_attacks_" + generateRowID();
  90. addAttr(sheet.id, melee_name + "_attack_name", c.melee.name, null);
  91. addAttr(sheet.id, melee_name + "_attack_throw_mod", c.melee.throw_mod, null);
  92. addAttr(sheet.id, melee_name + "_attack_dmg", c.melee.damage, null);
  93. if(c.spells) {
  94. for(spell of c.spells) {
  95. let spell_name = "repeating_spells_" + generateRowID();
  96. addAttr(sheet.id, spell_name + "_spell_name", spell.name, null);
  97. addAttr(sheet.id, spell_name + "_spell_effect", Base64.decode(spell.description), null);
  98. addAttr(sheet.id, spell_name + "_spell_range", spell.range, null);
  99. addAttr(sheet.id, spell_name + "_spell_roll", spell.roll || 0, null);
  100. if(spell.is_arcane) {
  101. addAttr(sheet.id, spell_name + "_spell_school", "Arcane", null);
  102. addAttr(sheet.id, spell_name + "_spell_level", spell.arcane, null);
  103. }
  104. if(spell.is_divine) {
  105. addAttr(sheet.id, spell_name + "_spell_school", "Divine", null);
  106. addAttr(sheet.id, spell_name + "_spell_level", spell.divine, null);
  107. }
  108. }
  109. }
  110. }
  111. }
  112. if(msg.type == "api" && msg.content.indexOf("!acksdeleteall") !== -1) {
  113. let characters = findObjs({type: 'character'});
  114. for(let character of characters) {
  115. character.get('gmnotes', function(val) {
  116. if(val === "Generated by Atr0phyACKS") {
  117. sendChat(msg.who, "Deleting generated NPC: " + character.get('name'));
  118. character.remove();
  119. }
  120. });
  121. }
  122. }
  123. });