25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

488 satır
9.2 KiB

  1. define([
  2. 'config/roles',
  3. 'world/atlas',
  4. 'items/generator',
  5. 'misc/random',
  6. 'items/config/slots',
  7. 'security/io',
  8. 'config/factions',
  9. 'security/connections'
  10. ], function (
  11. roles,
  12. atlas,
  13. generator,
  14. random,
  15. configSlots,
  16. io,
  17. factions,
  18. connections
  19. ) {
  20. var commandRoles = {
  21. //Regular players
  22. join: 0,
  23. leave: 0,
  24. unEq: 0,
  25. //Mods
  26. mute: 5,
  27. unmute: 5,
  28. //Admin
  29. getItem: 10,
  30. getGold: 10,
  31. setLevel: 10,
  32. godMode: 10,
  33. clearInventory: 10,
  34. completeQuests: 10,
  35. getReputation: 10,
  36. loseReputation: 10,
  37. setStat: 10,
  38. die: 10,
  39. getXp: 10
  40. };
  41. var localCommands = [
  42. 'join',
  43. 'leave',
  44. 'mute',
  45. 'unmute'
  46. ];
  47. return {
  48. customChannels: [],
  49. roleLevel: null,
  50. init: function (blueprint) {
  51. if (this.customChannels) {
  52. this.customChannels = this.customChannels
  53. .filter((c, i) => (this.customChannels.indexOf(c) == i));
  54. }
  55. this.roleLevel = roles.getRoleLevel(this.obj);
  56. },
  57. onBeforeChat: function (msg) {
  58. var messageText = msg.message;
  59. if (messageText[0] != '/')
  60. return;
  61. messageText = messageText.substr(1).split(' ');
  62. var actionName = messageText.splice(0, 1)[0].toLowerCase();
  63. actionName = Object.keys(commandRoles).find(a => (a.toLowerCase() == actionName));
  64. if (!actionName)
  65. return;
  66. else if (this.roleLevel < commandRoles[actionName])
  67. return;
  68. msg.ignore = true;
  69. var config = {};
  70. if ((messageText.length == 1) && (messageText[0].indexOf('=') == -1))
  71. config = messageText[0];
  72. else {
  73. messageText.forEach(function (m) {
  74. m = m.split('=');
  75. config[m[0]] = m[1];
  76. });
  77. }
  78. if (localCommands.indexOf(actionName) > -1) {
  79. this[actionName].call(this, config);
  80. } else {
  81. atlas.performAction(this.obj, {
  82. cpn: 'social',
  83. method: actionName,
  84. data: config
  85. });
  86. }
  87. },
  88. //actions
  89. join: function (value) {
  90. if (typeof (value) != 'string')
  91. return;
  92. value = value.split(' ').join('');
  93. if (value.lengh == 0)
  94. return;
  95. var obj = this.obj;
  96. var channels = obj.auth.customChannels;
  97. if (!channels.some(c => (c == value)))
  98. channels.push(value);
  99. else
  100. return;
  101. channels.push(value);
  102. var charname = obj.auth.charname;
  103. io.set({
  104. ent: charname,
  105. field: 'customChannels',
  106. value: JSON.stringify(channels)
  107. });
  108. obj.socket.emit('events', {
  109. onGetMessages: [{
  110. messages: [{
  111. class: 'color-yellowB',
  112. message: 'joined channel: ' + value,
  113. type: 'info'
  114. }]
  115. }]
  116. });
  117. obj.socket.emit('event', {
  118. event: 'onJoinChannel',
  119. data: value
  120. });
  121. },
  122. leave: function (value) {
  123. if (typeof (value) != 'string')
  124. return;
  125. var obj = this.obj;
  126. var channels = obj.auth.customChannels;
  127. if (!channels.some(c => (c == value))) {
  128. obj.socket.emit('events', {
  129. onGetMessages: [{
  130. messages: [{
  131. class: 'color-redA',
  132. message: 'you are not currently in that channel',
  133. type: 'info'
  134. }]
  135. }]
  136. });
  137. return;
  138. }
  139. var channels = obj.auth.customChannels;
  140. channels.spliceWhere(c => (c == value));
  141. var charname = obj.auth.charname;
  142. io.set({
  143. ent: charname,
  144. field: 'customChannels',
  145. value: JSON.stringify(channels)
  146. });
  147. obj.socket.emit('event', {
  148. event: 'onLeaveChannel',
  149. data: value
  150. });
  151. this.obj.socket.emit('events', {
  152. onGetMessages: [{
  153. messages: [{
  154. class: 'color-yellowB',
  155. message: 'left channel: ' + value,
  156. type: 'info'
  157. }]
  158. }]
  159. });
  160. },
  161. isInChannel: function (character, channel) {
  162. return character.auth.customChannels.some(c => (c == channel));
  163. },
  164. unEq: function () {
  165. var eq = this.obj.equipment;
  166. Object.keys(eq.eq).forEach(function (slot) {
  167. eq.unequip(eq.eq[slot]);
  168. });
  169. },
  170. mute: function (target, reason) {
  171. if (typeof (target) == 'object') {
  172. var keys = Object.keys(target);
  173. target = keys[0];
  174. reason = keys[1];
  175. }
  176. if (target == this.obj.name)
  177. return;
  178. var o = connections.players.find(o => (o.name == target));
  179. if (!o)
  180. return;
  181. var role = roles.getRoleLevel(o);
  182. if (role >= this.roleLevel)
  183. return;
  184. var social = o.social;
  185. if (social.muted) {
  186. this.sendMessage('That player has already been muted', 'color-redA');
  187. return;
  188. }
  189. var reasonMsg = '';
  190. if (reason)
  191. reasonMsg = ' (' + reason + ')';
  192. social.muted = true;
  193. this.sendMessage('Successfully muted ' + target, 'color-yellowB');
  194. this.sendMessage('You have been muted' + reasonMsg, 'color-yellowB', o);
  195. atlas.updateObject(o, {
  196. components: [{
  197. type: 'social',
  198. muted: true
  199. }]
  200. });
  201. io.set({
  202. ent: new Date(),
  203. field: 'modLog',
  204. value: JSON.stringify({
  205. source: this.obj.name,
  206. command: 'mute',
  207. target: target,
  208. reason: reason
  209. })
  210. });
  211. },
  212. unmute: function (target, reason) {
  213. if (typeof (target) == 'object') {
  214. var keys = Object.keys(target);
  215. target = keys[0];
  216. reason = keys[1];
  217. }
  218. if (target == this.obj.name)
  219. return;
  220. var o = connections.players.find(o => (o.name == target));
  221. if (!o)
  222. return;
  223. var role = roles.getRoleLevel(o);
  224. if (role >= this.roleLevel)
  225. return;
  226. var social = o.social;
  227. if (!social.muted) {
  228. this.sendMessage('That player is not muted', 'color-redA');
  229. return;
  230. }
  231. var reasonMsg = '';
  232. if (reason)
  233. reasonMsg = ' (' + reason + ')';
  234. delete social.muted;
  235. this.sendMessage('Successfully unmuted ' + target, 'color-yellowB');
  236. this.sendMessage('You have been unmuted' + reasonMsg, 'color-yellowB', o);
  237. atlas.updateObject(o, {
  238. components: [{
  239. type: 'social',
  240. muted: null
  241. }]
  242. });
  243. io.set({
  244. ent: new Date(),
  245. field: 'modLog',
  246. value: JSON.stringify({
  247. source: this.obj.name,
  248. command: 'unmute',
  249. target: target,
  250. reason: reason
  251. })
  252. })
  253. },
  254. clearInventory: function () {
  255. var inventory = this.obj.inventory;
  256. inventory.items
  257. .filter(i => !i.eq)
  258. .map(i => i.id)
  259. .forEach(i => inventory.destroyItem(i, null, true));
  260. },
  261. getItem: function (config) {
  262. if (config.slot == 'set') {
  263. configSlots.slots.forEach(function (s) {
  264. if (s == 'tool')
  265. return;
  266. var newConfig = extend(true, {}, config, {
  267. slot: s
  268. });
  269. this.getItem(newConfig);
  270. }, this);
  271. return;
  272. }
  273. if (config.stats)
  274. config.stats = config.stats.split(',');
  275. if (config.name)
  276. config.name = config.name.split('_').join(' ');
  277. if (config.type)
  278. config.type = config.type.split('_').join(' ');
  279. if (config.sprite)
  280. config.sprite = config.sprite.split('_');
  281. var spritesheet = config.spritesheet;
  282. delete config.spritesheet;
  283. var factions = (config.factions || '').split(',');
  284. delete config.factions;
  285. var safe = config.safe;
  286. delete config.safe;
  287. var eq = config.eq;
  288. delete config.eq;
  289. var item = generator.generate(config);
  290. if (safe) {
  291. item.noDrop = true;
  292. item.noDestroy = true;
  293. item.noSalvage = true;
  294. }
  295. factions.forEach(function (f) {
  296. if (f == '')
  297. return;
  298. var faction = factions.getFaction(f);
  299. faction.uniqueStat.generate(item);
  300. item.factions = [];
  301. item.factions.push({
  302. id: f,
  303. tier: 3
  304. });
  305. });
  306. if (spritesheet)
  307. item.spritesheet = spritesheet;
  308. var newItem = this.obj.inventory.getItem(item);
  309. if (eq)
  310. this.obj.equipment.equip(newItem.id);
  311. },
  312. getGold: function (amount) {
  313. this.obj.trade.gold += ~~amount;
  314. this.obj.syncer.set(true, 'trade', 'gold', this.obj.trade.gold);
  315. },
  316. setLevel: function (level) {
  317. var obj = this.obj;
  318. var syncer = obj.syncer;
  319. level = Math.max(1, ~~level);
  320. var stats = obj.stats;
  321. var values = stats.values;
  322. var oldLevel = values.level;
  323. values.level = level;
  324. var delta = level - oldLevel;
  325. values.hpMax += (40 * delta);
  326. syncer.setObject(true, 'stats', 'values', 'level', level);
  327. syncer.setObject(true, 'stats', 'values', 'hpMax', values.hpMax);
  328. process.send({
  329. method: 'object',
  330. serverId: obj.serverId,
  331. obj: {
  332. level: level
  333. }
  334. });
  335. stats.calcXpMax();
  336. },
  337. godMode: function () {
  338. var obj = this.obj;
  339. var statValues = obj.stats.values;
  340. var newValues = {
  341. int: 10000000,
  342. str: 10000000,
  343. dex: 10000000,
  344. hpMax: 10000000,
  345. hp: 10000000,
  346. manaMax: 10000000,
  347. mana: 10000000,
  348. sprintChance: 100,
  349. vit: 10000000
  350. };
  351. var syncer = obj.syncer;
  352. for (var s in newValues) {
  353. var newValue = newValues[s];
  354. statValues[s] = newValue;
  355. syncer.setObject(true, 'stats', 'values', s, newValue);
  356. }
  357. obj.spellbook.calcDps();
  358. },
  359. completeQuests: function () {
  360. var obj = this.obj;
  361. var quests = obj.quests;
  362. quests.quests.forEach(function (q) {
  363. q.isReady = true;
  364. q.complete();
  365. }, this);
  366. quests.quests = [];
  367. obj.instance.questBuilder.obtain(obj);
  368. },
  369. getReputation: function (faction) {
  370. if (typeof (faction) != 'string')
  371. return;
  372. this.obj.reputation.getReputation(faction, 50000);
  373. },
  374. loseReputation: function (faction) {
  375. if (typeof (faction) != 'string')
  376. return;
  377. this.obj.reputation.getReputation(faction, -50000);
  378. },
  379. setStat: function (config) {
  380. this.obj.stats.values[config.stat] = ~~config.value;
  381. },
  382. getXp: function (amount) {
  383. this.obj.stats.getXp(amount, this.obj, this.obj);
  384. },
  385. die: function () {
  386. this.obj.stats.takeDamage({
  387. amount: 99999
  388. }, 1, this.obj);
  389. }
  390. };
  391. });