processitems.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. var item_types = ['Potion', 'Ring', 'Rod', 'Scroll', 'Staff', 'Wand', 'Wondrous item'];
  2. /*
  3. Armor (chain shirt)
  4. Armor (light
  5. Armor (medium or heavy
  6. Armor (plate)
  7. Armor (scale mail)
  8. Armor (shield)
  9. Armor (studded leather)
  10. Weapon (any)
  11. Weapon (any ammunition)
  12. Weapon (any axe)
  13. Weapon (any axe or sword)
  14. Weapon (any sword)
  15. Weapon (any sword that deals slashing damage)
  16. Weapon (arrow)
  17. Weapon (dagger)
  18. Weapon (javelin)
  19. Weapon (longbow)
  20. Weapon (longsword)
  21. Weapon (mace)
  22. Weapon (maul)
  23. Weapon (scimitar)
  24. Weapon (trident)
  25. Weapon (warhammer)
  26. any
  27. any ammunition
  28. any axe
  29. any axe or sword
  30. any sword
  31. any sword that deals slashing damage
  32. arrow
  33. dagger
  34. javelin
  35. longbow
  36. longsword
  37. mace
  38. maul
  39. scimitar
  40. trident
  41. warhammer
  42. */
  43. var raw = require('./items_raw.js');
  44. var items = [];
  45. for(i in raw) {
  46. // console.log(i + ':');
  47. if(raw[i].ignore === true) continue; // irregular or special items
  48. for(j in raw[i]) {
  49. var jj = raw[i][j];
  50. if(j != 'content') continue;
  51. for(k in jj) { // loop the content
  52. var kk = jj[k];
  53. if(kk[0] == '*' && kk[1] != '*') {
  54. // console.log(i + ': ' + kk)
  55. // if(m) console.log(i + ': ' + m[1] + ' | ' + m[2]);
  56. // if(m) console.log( m[1] );
  57. var item = {
  58. name: i,
  59. magic_item: true,
  60. requires_attunement: false,
  61. };
  62. var m = kk.match(/^\*Weapon \(([^)]*)\)/);
  63. if(m) {
  64. // console.log(m[1]);
  65. continue;
  66. }
  67. var m = kk.match(/^\*Armor \(([^)]*)\)/);
  68. if(m) {
  69. // console.log(i + ': ' + m[1]);
  70. continue;
  71. }
  72. var m = kk.match(/^\*([^,]*), ([^*]*)\*$/);
  73. // if(!m) console.log(i + ': ' + kk)
  74. if(-1 == item_types.indexOf(m[1])) {
  75. console.log('empty: '+ m[1])
  76. }
  77. item.category = m[1];
  78. var m2 = m[2].match(/^(rare|very rare|uncommon|common|legendary)\s*(.*)$/);
  79. item.rarity = m2[1];
  80. if(m2[2] != '') {
  81. if(m2[2] == "(requires attunement)") {
  82. item.requires_attunement = true;
  83. }
  84. else {
  85. var m3 = m2[2].match(/\(requires attunement by a ([^)]*)\)/);
  86. item.requires_attunement = m3[1];
  87. }
  88. }
  89. item.content = jj.slice(1);
  90. items.push(item);
  91. }
  92. }
  93. }
  94. }
  95. for(i in raw) {
  96. var ii = raw[i];
  97. if(ii.ignore !== true) continue;
  98. // console.log(i);
  99. }
  100. // return;
  101. console.log("var item_list = {");
  102. for(var n of items) {
  103. var atn = '[atn: none]';
  104. if(n.requires_attunement === true) {
  105. atn = '[atn: any]';
  106. }
  107. else if(n.requires_attunement !== false) {
  108. atn = '[atn: '+n.requires_attunement+']';
  109. }
  110. // console.log(n.name +'; ' +n.category+ ' (' + n.rarity + ') '+ atn + ': ');
  111. console.log('\t"' +n.name+ '": '+JSON.stringify(n) + ',');
  112. }
  113. console.log("};");
  114. console.log("if(module && module.exports) module.exports = item_list;");