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.
 
 
 

341 lines
9.8 KiB

  1. let itemGenerator = require('../../items/generator');
  2. module.exports = {
  3. mapFile: null,
  4. mapW: null,
  5. mapH: null,
  6. mapOffset: {
  7. x: 79,
  8. y: 32
  9. },
  10. init: function () {
  11. this.mapFile = require('./maps/fjolarok/map');
  12. this.mapW = this.mapFile.width;
  13. this.mapH = this.mapFile.height;
  14. //this.events.on('onBeforeGetDialogue', this.onBeforeGetDialogue.bind(this));
  15. this.events.on('onBeforeGetResourceList', this.onBeforeGetResourceList.bind(this));
  16. //this.events.on('onBeforeGetEventList', this.onBeforeGetEventList.bind(this));
  17. this.events.on('onBeforeGetCardReward', this.onBeforeGetCardReward.bind(this));
  18. this.events.on('onBeforeGetSkins', this.onBeforeGetSkins.bind(this));
  19. //this.events.on('onAfterGetZone', this.onAfterGetZone.bind(this));
  20. //this.events.on('onBeforeGetHerbConfig', this.onBeforeGetHerbConfig.bind(this));
  21. //this.events.on('onBeforeBuildLayerTile', this.onBeforeBuildLayerTile.bind(this));
  22. //this.events.on('onAfterGetLayerObjects', this.onAfterGetLayerObjects.bind(this));
  23. this.events.on('onBeforeGetFactions', this.onBeforeGetFactions.bind(this));
  24. this.events.on('onBeforeUseItem', this.onBeforeUseItem.bind(this));
  25. this.events.on('onBeforeGetEffect', this.onBeforeGetEffect.bind(this));
  26. this.events.on('onBeforeGetCardsConfig', this.onBeforeGetCardsConfig.bind(this));
  27. },
  28. onBeforeGetCardsConfig: function (config) {
  29. extend(true, config, {
  30. 'Cheer and Spear': {
  31. chance: 40,
  32. reward: 'Rare Festive Spear',
  33. setSize: 3,
  34. mobName: ['frost crab', 'rude holf'],
  35. spritesheet: 'server/mods/event-xmas/images/items.png',
  36. sprite: [0, 1],
  37. quality: 2
  38. },
  39. "Wizard's Vice": {
  40. reward: 'Scented Beard Oil'
  41. }
  42. });
  43. },
  44. onBeforeGetSkins: function (skins) {
  45. skins['3.1'] = {
  46. name: 'Bearded Wizard',
  47. sprite: [0, 0],
  48. spritesheet: `${this.folderName}/images/skins.png`
  49. };
  50. },
  51. onBeforeGetEffect: function (result) {
  52. if (result.type.toLowerCase() === 'merry')
  53. result.url = `${this.relativeFolderName}/effects/effectMerry.js`;
  54. },
  55. onBeforeUseItem: function (obj, item, result) {
  56. let handler = {
  57. 'Merrywinter Play Script': function (obj, item, result) {
  58. let lines = [
  59. 'A catch, a catch, our lines are taut, somebody grab the wheel',
  60. 'And when the catch was on the ship, all three stood \'round in awe',
  61. 'And with each present handed, and each snowflake landed, when the winter morn began',
  62. 'As each man got the things to which he\'d previously alluded',
  63. 'But it was still taut though it moved for naught, a truly curious sign',
  64. 'But then it passed, the mighty thrashing, their chance of food expired',
  65. 'Declared to all (or those who\'d hear), what passed the night before',
  66. 'Each one then, with their gift in hand, thanked the Winter Man',
  67. 'For not a man could gaze on it and believe that which he saw',
  68. 'For they were out, the three of them, fishing off the shore',
  69. 'I need to get back home sometime, before the moon\'s alighted',
  70. 'Inscribed on each in jet black ink, the recipient\'s relations',
  71. 'It started on a morning pale, with winter hardly come',
  72. 'Later they would cheerfully relate what the contents had included',
  73. 'My boy needs clothes, and books for school, but money\'s hard to find',
  74. 'My hooks are busted and rust encrusted, I know not how we\'ll eat',
  75. 'My wife has lost her silver ring, a gift from my dad',
  76. 'Reel it in, let\'s see this thing that had us so excited',
  77. 'So there they sat: dejected, silent, their moods now foul and gray',
  78. 'The first announced before he pounced to grab hold of the reel',
  79. 'The first then nodded and down, he plodded; a picture of defeat',
  80. 'The second chimed: Oh friends it seems, Ill luck is all we\'ve had',
  81. 'The third announced: My friends, my friends, I am in such a bind',
  82. 'The third looked on with a heartfelt sigh to see the broken line',
  83. 'Waterproof boxes wrapped in lints and colorful decorations',
  84. 'What happened there, are we to starve? The second then enquired',
  85. 'When fishermen beyond the vale, their bellies full of rum',
  86. 'When with a mighty shudder, and a trembling rudder, their boat shook on the bay'
  87. ];
  88. obj.syncer.set(false, 'chatter', 'color', 0x48edff);
  89. let pick = ~~(Math.random() * (lines.length - 1));
  90. obj.syncer.set(false, 'chatter', 'msg', lines[pick] + '\r\n' + lines[pick + 1]);
  91. },
  92. 'Sprig of Mistletoe': function (obj, item, result) {
  93. let ox = obj.x;
  94. let oy = obj.y;
  95. let objects = obj.instance.objects.objects.filter(o => (((o.mob) || (o.player)) && (o.name) && (o !== obj)));
  96. let closestDistance = 999;
  97. let closest = null;
  98. let oLen = objects.length;
  99. for (let i = 0; i < oLen; i++) {
  100. let m = objects[i];
  101. let distance = Math.max(Math.abs(ox - m.x), Math.abs(oy - m.y));
  102. if (distance < closestDistance) {
  103. closestDistance = distance;
  104. closest = m;
  105. }
  106. }
  107. if (!closest)
  108. return;
  109. let prefix = (closest.mob) ? 'the' : '';
  110. obj.syncer.set(false, 'chatter', 'color', 0xfc66f7);
  111. obj.syncer.set(false, 'chatter', 'msg', `...Smooches ${prefix} ${closest.name}...`);
  112. obj.instance.objects.buildObjects([{
  113. x: obj.x,
  114. y: obj.y,
  115. ttl: 10,
  116. properties: {
  117. cpnParticles: {
  118. simplify: function () {
  119. return {
  120. type: 'particles',
  121. blueprint: {
  122. color: {
  123. start: ['ff4252', 'ffc66f7', 'de43ae', 'd43346'],
  124. end: ['ff4252', 'ffc66f7', 'de43ae', 'd43346']
  125. },
  126. scale: {
  127. start: {
  128. min: 4,
  129. max: 10
  130. },
  131. end: {
  132. min: 4,
  133. max: 6
  134. }
  135. },
  136. speed: {
  137. start: {
  138. min: 0,
  139. max: 12
  140. },
  141. end: {
  142. min: 0,
  143. max: 4
  144. }
  145. },
  146. lifetime: {
  147. min: 1,
  148. max: 4
  149. },
  150. alpha: {
  151. start: 1,
  152. end: 0
  153. },
  154. randomScale: true,
  155. randomSpeed: true,
  156. chance: 0.3,
  157. randomColor: true,
  158. blendMode: 'add',
  159. spawnType: 'ring',
  160. spawnCircle: {
  161. r: 24,
  162. minR: 22
  163. }
  164. }
  165. };
  166. }
  167. }
  168. }
  169. }]);
  170. },
  171. 'Bottomless Eggnog': function (obj, item, result) {
  172. obj.effects.addEffect({
  173. type: 'merry',
  174. ttl: 514
  175. });
  176. },
  177. 'Scented Beard Oil': function (obj, item, result) {
  178. obj.syncer.set(false, 'chatter', 'color', 0xfc66f7);
  179. obj.syncer.set(false, 'chatter', 'msg', '...Rubs his beard throughtfully...');
  180. }
  181. }[item.name];
  182. if (!handler)
  183. return;
  184. handler(obj, item, result);
  185. },
  186. onBeforeGetFactions: function (mappings) {
  187. extend(true, mappings, {
  188. theWinterMan: `${this.relativeFolderName}/factions/theWinterMan`
  189. });
  190. },
  191. onAfterGetLayerObjects: function (info) {
  192. if (info.map !== 'fjolarok')
  193. return;
  194. let layer = this.mapFile.layers.find(l => (l.name === info.layer));
  195. if (layer) {
  196. let offset = this.mapOffset;
  197. let mapScale = this.mapFile.tilesets[0].tileheight;
  198. layer.objects.forEach(function (l) {
  199. let newO = extend(true, {}, l);
  200. newO.x += (offset.x * mapScale);
  201. newO.y += (offset.y * mapScale);
  202. info.objects.push(newO);
  203. }, this);
  204. }
  205. },
  206. onBeforeBuildLayerTile: function (info) {
  207. if (info.map !== 'fjolarok')
  208. return;
  209. let offset = this.mapOffset;
  210. let x = info.x;
  211. let y = info.y;
  212. if ((x - offset.x < 0) || (y - offset.y < 0) || (x - offset.x >= this.mapW) || (y - offset.y >= this.mapH))
  213. return;
  214. let i = ((y - offset.y) * this.mapW) + (x - offset.x);
  215. let layer = this.mapFile.layers.find(l => (l.name === info.layer));
  216. if (layer) {
  217. let cell = layer.data[i];
  218. if (cell)
  219. info.cell = layer.data[i];
  220. }
  221. },
  222. onAfterGetZone: function (zone, config) {
  223. try {
  224. let modZone = require('./maps/' + zone + '/zone.js');
  225. extend(true, config, modZone);
  226. } catch (e) {
  227. }
  228. },
  229. onBeforeGetHerbConfig: function (herbs) {
  230. extend(true, herbs, {
  231. 'Festive Gift': {
  232. sheetName: 'objects',
  233. cell: 166,
  234. itemSprite: [3, 0],
  235. itemName: 'Snowflake',
  236. itemSheet: `${this.folderName}/images/items.png`,
  237. itemAmount: [1, 2]
  238. },
  239. 'Giant Gift': {
  240. sheetName: 'bigObjects',
  241. cell: 14,
  242. itemSprite: [3, 0],
  243. itemName: 'Snowflake',
  244. itemSheet: `${this.folderName}/images/items.png`,
  245. itemAmount: [3, 5]
  246. },
  247. 'Gilded Gift': {
  248. sheetName: 'bigObjects',
  249. cell: 22,
  250. itemSprite: [3, 0],
  251. itemName: 'Snowflake',
  252. itemSheet: `${this.folderName}/images/items.png`,
  253. itemAmount: [5, 8]
  254. }
  255. });
  256. },
  257. onBeforeGetCardReward: function (msg) {
  258. if (msg.reward === 'Rare Festive Spear') {
  259. msg.handler = function (card) {
  260. return itemGenerator.generate({
  261. name: 'Festive Spear',
  262. level: [5, 15],
  263. noSpell: true,
  264. slot: 'twoHanded',
  265. type: 'Spear',
  266. quality: 2,
  267. stats: ['attackSpeed|10'],
  268. spritesheet: 'server/mods/event-xmas/images/items.png',
  269. sprite: [0, 0]
  270. });
  271. };
  272. } else if (msg.reward === 'Scented Beard Oil') {
  273. msg.handler = function (card) {
  274. return {
  275. name: 'Scented Beard Oil',
  276. type: 'toy',
  277. sprite: [3, 2],
  278. spritesheet: 'server/mods/event-xmas/images/items.png',
  279. description: 'For some extra \'ho\' in your holy vengeance.',
  280. worth: 0,
  281. cdMax: 300,
  282. noSalvage: true,
  283. noAugment: true
  284. };
  285. };
  286. }
  287. },
  288. onBeforeGetResourceList: function (list) {
  289. list.push(`${this.folderName}/images/mobs.png`);
  290. list.push(`${this.folderName}/images/skins.png`);
  291. },
  292. onBeforeGetEventList: function (zone, list) {
  293. if (zone !== 'fjolarok')
  294. return;
  295. list.push(this.relativeFolderName + '/maps/fjolarok/events/xmas.js');
  296. },
  297. onBeforeGetDialogue: function (zone, config) {
  298. try {
  299. let modDialogue = require('./maps/' + zone + '/dialogues.js');
  300. extend(true, config, modDialogue);
  301. } catch (e) {
  302. }
  303. }
  304. };