選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

327 行
7.4 KiB

  1. define([
  2. 'items/generators/quality'
  3. ], function (
  4. qualityGenerator
  5. ) {
  6. return {
  7. type: 'gatherer',
  8. nodes: [],
  9. gathering: null,
  10. gatheringTtl: 0,
  11. gatheringTtlMax: 7,
  12. defaultTtlMax: 7,
  13. simplify: function () {
  14. return {
  15. type: 'gatherer'
  16. };
  17. },
  18. gather: function () {
  19. if (this.gathering != null)
  20. return;
  21. var nodes = this.nodes;
  22. if (nodes.length == 0)
  23. return;
  24. var firstNode = nodes[0];
  25. this.gathering = firstNode;
  26. var ttlMax = firstNode.resourceNode.ttl || this.defaultTtlMax;
  27. if (firstNode.resourceNode.nodeType == 'fish') {
  28. var rod = this.obj.equipment.eq.tool;
  29. if (!rod) {
  30. process.send({
  31. method: 'events',
  32. data: {
  33. 'onGetAnnouncement': [{
  34. obj: {
  35. msg: 'You need a fishing rod to fish'
  36. },
  37. to: [this.obj.serverId]
  38. }]
  39. }
  40. });
  41. this.gathering = null;
  42. return;
  43. }
  44. rod = this.obj.inventory.findItem(rod);
  45. var statCatchSpeed = Math.min(150, this.obj.stats.values.catchSpeed);
  46. ttlMax *= (1 - (statCatchSpeed / 200));
  47. }
  48. this.gatheringTtlMax = ttlMax;
  49. this.gatheringTtl = this.gatheringTtlMax;
  50. },
  51. update: function () {
  52. var gathering = this.gathering;
  53. if (!gathering)
  54. return;
  55. if (gathering.destroyed) {
  56. this.gathering = null;
  57. this.gatheringTtl = 0;
  58. this.obj.syncer.set(false, 'gatherer', 'progress', 100);
  59. this.obj.syncer.set(true, 'gatherer', 'progress', 100);
  60. this.obj.syncer.set(true, 'gatherer', 'action', 'Fishing');
  61. return;
  62. }
  63. var isFish = (gathering.resourceNode.nodeType == 'fish');
  64. if (this.gatheringTtl > 0) {
  65. if ((this.gatheringTtl == this.gatheringTtlMax) && (gathering.width)) {
  66. ['x', 'y', 'width', 'height'].forEach(function (p) {
  67. this.obj.syncer.set(false, 'gatherer', p, gathering[p]);
  68. }, this);
  69. }
  70. this.gatheringTtl--;
  71. var progress = 100 - ~~((this.gatheringTtl / this.gatheringTtlMax) * 100);
  72. this.obj.syncer.set(true, 'gatherer', 'progress', progress);
  73. if (isFish)
  74. this.obj.syncer.set(true, 'gatherer', 'action', 'Fishing');
  75. return;
  76. }
  77. var resourceNode = gathering.resourceNode;
  78. var gatherResult = extend(true, {
  79. obj: gathering
  80. }, {
  81. nodeType: resourceNode.nodeType,
  82. blueprint: resourceNode.blueprint,
  83. xp: resourceNode.xp,
  84. items: gathering.inventory.items
  85. });
  86. this.obj.instance.eventEmitter.emitNoSticky('beforeGatherResource', gatherResult, this.obj);
  87. this.obj.fireEvent('beforeGatherResource', gatherResult, this.obj);
  88. this.obj.syncer.set(false, 'gatherer', 'progress', 100);
  89. if (isFish) {
  90. var rod = this.obj.equipment.eq.tool;
  91. rod = this.obj.inventory.findItem(rod);
  92. var catchChance = 40 + this.obj.stats.values.catchChance;
  93. if (~~(Math.random() * 100) >= catchChance) {
  94. process.send({
  95. method: 'events',
  96. data: {
  97. 'onGetAnnouncement': [{
  98. obj: {
  99. msg: 'The fish got away'
  100. },
  101. to: [this.obj.serverId]
  102. }]
  103. }
  104. });
  105. this.gathering = null;
  106. return;
  107. }
  108. gatherResult.items.forEach(function (g) {
  109. delete g.quantity;
  110. qualityGenerator.generate(g, {
  111. //100 x 2.86 = 2000 (chance for a common)
  112. bonusMagicFind: this.obj.stats.values.fishRarity * 2.82
  113. });
  114. g.name = {
  115. '0': '',
  116. '1': 'Big ',
  117. '2': 'Giant ',
  118. '3': 'Trophy ',
  119. '4': 'Fabled '
  120. }[g.quality] + g.name;
  121. var statFishWeight = 1 + (this.obj.stats.values.fishWeight / 100);
  122. var weight = ~~((gatherResult.blueprint.baseWeight + g.quality + (Math.random() * statFishWeight)) * 100) / 100;
  123. g.stats = {
  124. weight: weight
  125. };
  126. g.worth = ~~(weight * 10);
  127. }, this);
  128. }
  129. if (isFish) {
  130. var rod = this.obj.equipment.eq.tool;
  131. rod = this.obj.inventory.findItem(rod);
  132. var itemChance = 1 + this.obj.stats.values.fishItems;
  133. if (~~(Math.random() * 100) < itemChance) {
  134. gatherResult.items = [{
  135. name: 'Cerulean Pearl',
  136. material: true,
  137. quantity: 1,
  138. quality: 3,
  139. sprite: [11, 9]
  140. }];
  141. }
  142. }
  143. var blueprint = gatherResult.blueprint;
  144. gatherResult.items.forEach(function (item, i) {
  145. delete item.pos;
  146. if (i == 0) {
  147. if (blueprint.itemName)
  148. item.name = blueprint.itemName;
  149. if (blueprint.itemAmount)
  150. item.quantity = ~~(Math.random() * blueprint.itemAmount[1]) + blueprint.itemAmount[0];
  151. }
  152. this.obj.inventory.getItem(item);
  153. if (item.material)
  154. this.obj.fireEvent('afterGatherResource', gatherResult);
  155. }, this);
  156. if (!gatherResult.noChangeAmount)
  157. resourceNode.gather();
  158. this.obj.stats.getXp(gatherResult.xp, this.obj, gatherResult.obj);
  159. if (gathering.destroyed) {
  160. if (isFish) {
  161. process.send({
  162. method: 'events',
  163. data: {
  164. 'onGetAnnouncement': [{
  165. obj: {
  166. msg: 'The school has been depleted'
  167. },
  168. to: [this.obj.serverId]
  169. }]
  170. }
  171. });
  172. }
  173. this.nodes.spliceWhere(n => (n == gathering));
  174. }
  175. this.gathering = null;
  176. },
  177. enter: function (node) {
  178. var gatherResult = extend(true, {
  179. nodeName: node.name
  180. });
  181. this.obj.instance.eventEmitter.emitNoSticky('beforeEnterPool', gatherResult, this.obj);
  182. var nodeType = node.resourceNode.nodeType;
  183. var msg = `Press G to $ (${gatherResult.nodeName})`;
  184. msg = msg.replace('$', {
  185. herb: 'gather',
  186. fish: 'fish for'
  187. }[nodeType]);
  188. var success = true;
  189. if (nodeType == 'fish') {
  190. var rod = this.obj.equipment.eq.tool;
  191. if (rod == null) {
  192. success = false;
  193. msg = 'You need a fishing rod to fish'
  194. }
  195. }
  196. process.send({
  197. method: 'events',
  198. data: {
  199. 'onGetAnnouncement': [{
  200. obj: {
  201. msg: msg
  202. },
  203. to: [this.obj.serverId]
  204. }]
  205. }
  206. });
  207. this.nodes.spliceWhere(n => (n == node));
  208. this.nodes.push(node);
  209. },
  210. exit: function (node) {
  211. this.nodes.spliceWhere(n => (n == node));
  212. },
  213. events: {
  214. beforeRezone: function () {
  215. this.events.beforeMove.call(this);
  216. },
  217. beforeMove: function () {
  218. if (!this.gathering)
  219. return;
  220. ['x', 'y', 'width', 'height'].forEach(function (p) {
  221. this.obj.syncer.delete(false, 'gatherer', p);
  222. }, this);
  223. this.obj.syncer.set(true, 'gatherer', 'progress', 100);
  224. this.obj.syncer.set(false, 'gatherer', 'progress', 100);
  225. if (this.gathering.resourceNode.nodeType == 'fish')
  226. this.obj.syncer.set(true, 'gatherer', 'action', 'Fishing');
  227. this.gathering = null;
  228. },
  229. afterEquipItem: function (item) {
  230. var nodes = this.nodes;
  231. var nLen = nodes.length;
  232. for (var i = 0; i < nLen; i++) {
  233. var node = nodes[i];
  234. if (item.slot != 'tool')
  235. continue;
  236. if (node.resourceNode.nodeType == 'fish') {
  237. var rod = this.obj.equipment.eq.tool;
  238. if (rod == null) {
  239. process.send({
  240. method: 'events',
  241. data: {
  242. 'onGetAnnouncement': [{
  243. obj: {
  244. msg: 'You need a fishing rod to fish'
  245. },
  246. to: [this.obj.serverId]
  247. }]
  248. }
  249. });
  250. if (this.gathering == node) {
  251. if (this.gathering.resourceNode.nodeType == 'fish')
  252. this.obj.syncer.set(true, 'gatherer', 'action', 'Fishing');
  253. this.gathering = null;
  254. this.obj.syncer.set(true, 'gatherer', 'progress', 100);
  255. this.obj.syncer.set(false, 'gatherer', 'progress', 100);
  256. }
  257. }
  258. }
  259. }
  260. },
  261. afterUnequipItem: function (item) {
  262. this.events.afterEquipItem.call(this, item);
  263. }
  264. }
  265. };
  266. });