Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

456 Zeilen
10 KiB

  1. define([
  2. ], function(
  3. ) {
  4. return {
  5. type: 'stats',
  6. values: {
  7. mana: 10,
  8. manaMax: 10,
  9. hp: 5,
  10. hpMax: 5,
  11. xpTotal: 0,
  12. xp: 0,
  13. xpMax: 0,
  14. level: 1,
  15. str: 0,
  16. int: 0,
  17. dex: 0,
  18. magicFind: 0,
  19. regenHp: 0,
  20. regenMana: 10,
  21. addCritChance: 0,
  22. critChance: 5,
  23. armor: 0,
  24. dmgPercent: 0,
  25. elementArcanePercent: 0,
  26. elementFrostPercent: 0,
  27. elementFirePercent: 0,
  28. elementHolyPercent: 0,
  29. elementPhysicalPercent: 0,
  30. elementPoisonPercent: 0,
  31. elementArcaneResist: 0,
  32. elementFrostResist: 0,
  33. elementFireResist: 0,
  34. elementHolyResist: 0,
  35. elementPhysicalResist: 0,
  36. elementPoisonResist: 0,
  37. elementAllResist: 0,
  38. sprintChance: 0,
  39. xpIncrease: 0
  40. },
  41. vitScale: 10,
  42. syncer: null,
  43. stats: {
  44. logins: 0,
  45. played: 0
  46. },
  47. dead: false,
  48. init: function(blueprint) {
  49. this.syncer = this.obj.instance.syncer;
  50. var values = (blueprint || {}).values || {};
  51. for (var v in values) {
  52. this.values[v] = values[v];
  53. }
  54. this.calcXpMax();
  55. },
  56. resetHp: function() {
  57. var values = this.values;
  58. values.hp = values.hpMax;
  59. this.obj.syncer.setObject(false, 'stats', 'values', 'hp', values.hp);
  60. },
  61. update: function() {
  62. if ((this.obj.mob) || (this.dead))
  63. return;
  64. var regen = {
  65. success: true
  66. };
  67. this.obj.fireEvent('beforeRegen', regen);
  68. if (!regen.success)
  69. return;
  70. var values = this.values;
  71. var isInCombat = (this.obj.aggro.list.length > 0);
  72. var regenHp = 0;
  73. var regenMana = 0;
  74. regenMana = (values.manaMax / 200) + (values.regenMana / 200);
  75. if (!isInCombat)
  76. regenHp = values.hpMax / 100;
  77. else
  78. regenHp = values.regenHp * 0.3;
  79. if (values.hp < values.hpMax) {
  80. values.hp += regenHp;
  81. this.obj.syncer.setObject(false, 'stats', 'values', 'hp', this.values.hp);
  82. }
  83. if (values.hp > values.hpMax) {
  84. values.hp = values.hpMax;
  85. this.obj.syncer.setObject(false, 'stats', 'values', 'hp', values.hp);
  86. }
  87. if (values.mana < values.manaMax) {
  88. values.mana += regenMana;
  89. //Show others what mana is?
  90. var onlySelf = true;
  91. if (this.obj.player)
  92. onlySelf = false;
  93. this.obj.syncer.setObject(onlySelf, 'stats', 'values', 'mana', values.mana);
  94. }
  95. if (values.mana > values.manaMax) {
  96. values.mana = values.manaMax;
  97. if (this.obj.player)
  98. onlySelf = false;
  99. this.obj.syncer.setObject(onlySelf, 'stats', 'values', 'mana', values.mana);
  100. }
  101. },
  102. addStat: function(stat, value) {
  103. this.values[stat] += value;
  104. var sendOnlyToSelf = (['hp', 'hpMax', 'mana', 'manaMax'].indexOf(stat) == -1);
  105. this.obj.syncer.setObject(sendOnlyToSelf, 'stats', 'values', stat, this.values[stat]);
  106. if (stat == 'addCritChance') {
  107. this.values.critChance += (0.05 * value);
  108. this.obj.syncer.setObject(true, 'stats', 'values', 'critChance', this.values.critChance);
  109. } else if (stat == 'vit') {
  110. this.values.hpMax += (value * this.vitScale);
  111. this.obj.syncer.setObject(true, 'stats', 'values', 'hpMax', this.values.hpMax);
  112. } else if (stat == 'allAttributes') {
  113. ['int', 'str', 'dex'].forEach(function(s) {
  114. this.values[s] += value;
  115. this.obj.syncer.setObject(true, 'stats', 'values', s, this.values[s]);
  116. }, this);
  117. }
  118. },
  119. calcXpMax: function() {
  120. var level = this.values.level;
  121. this.values.xpMax = ~~(level * 10 * Math.pow(level, 1.75));
  122. this.obj.syncer.setObject(true, 'stats', 'values', 'xpMax', this.values.xpMax);
  123. },
  124. getXp: function(amount) {
  125. amount = ~~(amount * (1 + (this.values.xpIncrease / 100)));
  126. this.values.xpTotal = ~~(this.values.xpTotal + amount);
  127. this.values.xp = ~~(this.values.xp + amount);
  128. this.syncer.queue('onGetDamage', {
  129. id: this.obj.id,
  130. event: true,
  131. text: '+' + amount + ' xp'
  132. });
  133. var syncO = {};
  134. var didLevelUp = false;
  135. while (this.values.xp >= this.values.xpMax) {
  136. didLevelUp = true;
  137. this.values.xp -= this.values.xpMax;
  138. this.values.level++;
  139. this.values.hpMax += 40;
  140. this.syncer.queue('onGetDamage', {
  141. id: this.obj.id,
  142. event: true,
  143. text: 'level up'
  144. });
  145. this.obj.syncer.setObject(true, 'stats', 'values', 'level', this.values.level);
  146. this.obj.syncer.setObject(true, 'stats', 'values', 'hpMax', this.values.hpMax);
  147. syncO.level = this.values.level;
  148. this.calcXpMax();
  149. }
  150. if (didLevelUp)
  151. this.obj.auth.doSave();
  152. this.obj.syncer.setObject(true, 'stats', 'values', 'xp', this.values.xp);
  153. process.send({
  154. method: 'object',
  155. serverId: this.obj.serverId,
  156. obj: syncO
  157. });
  158. },
  159. kill: function(target) {
  160. var level = target.stats.values.level;
  161. //Who should get xp?
  162. var aggroList = target.aggro.list;
  163. var hpMax = target.stats.values.hpMax;
  164. var aLen = aggroList.length;
  165. for (var i = 0; i < aLen; i++) {
  166. var a = aggroList[i];
  167. var dmg = a.damage;
  168. if (dmg <= 0)
  169. continue;
  170. var mult = 1;
  171. //How many party members contributed
  172. // Remember, maybe one of the aggro-ees might be a mob too
  173. var party = a.obj.social ? a.obj.social.party : null;
  174. if (party) {
  175. var partySize = aggroList.filter(function(f) {
  176. return ((a.damage > 0) && (party.indexOf(f.obj.serverId) > -1));
  177. }).length;
  178. partySize--;
  179. mult = (1 + (partySize * 0.1));
  180. }
  181. if (a.obj.stats) {
  182. //Scale xp by source level so you can't just farm low level mobs (or get boosted on high level mobs).
  183. //Mobs that are farther then 10 levels from you, give no xp
  184. //We don't currently do this for quests/herb gathering
  185. var sourceLevel = a.obj.stats.values.level;
  186. var levelDelta = level - sourceLevel;
  187. var amount = level * 10 * mult;
  188. if (Math.abs(levelDelta) <= 10)
  189. amount = ~~(((sourceLevel + levelDelta) * 10) * Math.pow(1 - (Math.abs(levelDelta) / 10), 2) * mult);
  190. a.obj.stats.getXp(amount, this.obj);
  191. }
  192. a.obj.fireEvent('afterKillMob', target);
  193. }
  194. target.fireEvent('afterDeath');
  195. },
  196. die: function(source) {
  197. this.values.hp = this.values.hpMax;
  198. this.values.mana = this.values.manaMax;
  199. this.obj.syncer.setObject(false, 'stats', 'values', 'hp', this.values.hp);
  200. this.obj.syncer.setObject(false, 'stats', 'values', 'mana', this.values.mana);
  201. this.syncer.queue('onGetDamage', {
  202. id: this.obj.id,
  203. event: true,
  204. text: 'death'
  205. });
  206. this.syncer.queue('onDeath', {
  207. x: this.obj.x,
  208. y: this.obj.y,
  209. source: source.name
  210. }, [this.obj.serverId]);
  211. },
  212. takeDamage: function(damage, threatMult, source) {
  213. source.fireEvent('beforeDealDamage', damage, this.obj);
  214. this.obj.fireEvent('beforeTakeDamage', damage, source);
  215. //Maybe the attacker was stunned?
  216. if (damage.failed)
  217. return;
  218. //Maybe something else killed this mob already?
  219. if (this.obj.destroyed)
  220. return;
  221. var amount = damage.amount;
  222. if (amount > this.values.hp)
  223. amount = this.values.hp;
  224. this.values.hp -= amount;
  225. var recipients = [];
  226. if (this.obj.serverId != null)
  227. recipients.push(this.obj.serverId);
  228. if (source.serverId != null)
  229. recipients.push(source.serverId);
  230. if (recipients.length > 0) {
  231. this.syncer.queue('onGetDamage', {
  232. id: this.obj.id,
  233. source: source.id,
  234. crit: damage.crit,
  235. amount: amount
  236. }, recipients);
  237. }
  238. this.obj.aggro.tryEngage(source, amount, threatMult);
  239. var died = (this.values.hp <= 0);
  240. if (died) {
  241. var death = {
  242. success: true
  243. };
  244. this.obj.fireEvent('beforeDeath', death);
  245. if (death.success) {
  246. var deathEvent = {};
  247. if (source.player)
  248. source.stats.kill(this.obj);
  249. else
  250. this.obj.fireEvent('afterDeath', deathEvent);
  251. if (this.obj.player) {
  252. this.obj.syncer.setObject(false, 'stats', 'values', 'hp', this.values.hp);
  253. if (deathEvent.permadeath) {
  254. this.obj.auth.permadie();
  255. this.syncer.queue('onPermadeath', {
  256. source: source.name
  257. }, [this.obj.serverId]);
  258. } else
  259. this.values.hp = 0;
  260. this.obj.player.die(source, deathEvent.permadeath);
  261. } else {
  262. this.obj.effects.die();
  263. if (this.obj.spellbook)
  264. this.obj.spellbook.die();
  265. this.obj.destroyed = true;
  266. if (this.obj.inventory) {
  267. var aggroList = this.obj.aggro.list;
  268. var aLen = aggroList.length;
  269. var done = [];
  270. for (var i = 0; i < aLen; i++) {
  271. var a = aggroList[i].obj;
  272. if (done.some(d => d == a.serverId))
  273. continue;
  274. if ((a.social) && (a.social.party)) {
  275. a.social.party.forEach(function(p) {
  276. if (done.some(d => d == p))
  277. return;
  278. this.obj.inventory.dropBag(p, source);
  279. done.push(p);
  280. }, this);
  281. } else {
  282. if (a.serverId == null)
  283. continue;
  284. this.obj.inventory.dropBag(a.serverId, source);
  285. done.push(a.serverId);
  286. }
  287. }
  288. }
  289. }
  290. }
  291. } else {
  292. source.aggro.tryEngage(this.obj, 0);
  293. this.obj.syncer.setObject(false, 'stats', 'values', 'hp', this.values.hp);
  294. }
  295. source.fireEvent('afterDealDamage', damage, this.obj);
  296. },
  297. getHp: function(heal, source) {
  298. var values = this.values;
  299. var hpMax = values.hpMax;
  300. if (values.hp >= hpMax)
  301. return;
  302. var amount = heal.amount;
  303. if (hpMax - values.hp < amount)
  304. amount = hpMax - values.hp;
  305. values.hp += amount;
  306. if (values.hp > hpMax)
  307. values.hp = hpMax;
  308. var recipients = [];
  309. if (this.obj.serverId != null)
  310. recipients.push(this.obj.serverId);
  311. if (source.serverId != null)
  312. recipients.push(source.serverId);
  313. if (recipients.length > 0) {
  314. this.syncer.queue('onGetDamage', {
  315. id: this.obj.id,
  316. source: source.id,
  317. heal: true,
  318. amount: amount,
  319. crit: heal.crit
  320. }, recipients);
  321. }
  322. //Add aggro to all our attackers
  323. var threat = amount * 0.4;
  324. var aggroList = this.obj.aggro.list;
  325. var aLen = aggroList.length;
  326. for (var i = 0; i < aLen; i++) {
  327. var a = aggroList[i].obj;
  328. a.aggro.tryEngage(source, threat);
  329. }
  330. this.obj.syncer.setObject(false, 'stats', 'values', 'hp', values.hp);
  331. },
  332. save: function() {
  333. if (this.sessionDuration) {
  334. this.stats.played = ~~(this.stats.played + this.sessionDuration);
  335. delete this.sessionDuration;
  336. }
  337. return {
  338. type: 'stats',
  339. values: this.values,
  340. stats: this.stats
  341. };
  342. },
  343. simplify: function(self) {
  344. var values = this.values;
  345. if (!self) {
  346. var result = {
  347. type: 'stats',
  348. values: {
  349. hp: values.hp,
  350. hpMax: values.hpMax,
  351. mana: values.mana,
  352. manaMax: values.manaMax,
  353. level: values.level
  354. }
  355. };
  356. return result
  357. }
  358. return {
  359. type: 'stats',
  360. values: values,
  361. stats: this.stats,
  362. vitScale: this.vitScale
  363. };
  364. }
  365. };
  366. });