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.
 
 
 

222 lines
5.2 KiB

  1. define([
  2. 'config/animations',
  3. 'items/generator',
  4. 'combat/combat'
  5. ], function(
  6. animations,
  7. itemGenerator,
  8. combat
  9. ) {
  10. return {
  11. build: function(mob, blueprint, scaleDrops, type) {
  12. var typeDefinition = blueprint[type];
  13. var drops = typeDefinition.drops;
  14. mob.isMob = true;
  15. mob.scaleDrops = scaleDrops;
  16. if (blueprint.nonSelectable)
  17. mob.nonSelectable = true;
  18. mob.addComponent('effects');
  19. if (type != 'regular') {
  20. mob.effects.addEffect({
  21. type: type
  22. });
  23. mob['is' + type[0].toUpperCase() + type.substr(1)] = true;
  24. mob.baseName = mob.name;
  25. mob.name = typeDefinition.name || mob.baseName;
  26. }
  27. mob.addComponent('stats', {
  28. values: {
  29. level: blueprint.level
  30. }
  31. });
  32. var cpnMob = mob.addComponent('mob');
  33. cpnMob.walkDistance = blueprint.walkDistance;
  34. cpnMob.hpMult = typeDefinition.hpMult;
  35. cpnMob.dmgMult = typeDefinition.dmgMult;
  36. cpnMob.grantRep = blueprint.grantRep;
  37. cpnMob.deathRep = blueprint.deathRep;
  38. var spells = extend(true, [], blueprint.spells);
  39. spells.forEach(function(s) {
  40. if (!s.animation) {
  41. if ((mob.sheetName == 'mobs') && (animations.mobs[mob.cell])) {
  42. s.animation = 'basic';
  43. }
  44. }
  45. });
  46. mob.addComponent('spellbook', {
  47. spells: spells,
  48. dmgMult: typeDefinition.dmgMult
  49. });
  50. var attackable = blueprint.attackable;
  51. if ((attackable === undefined) || (attackable === true)) {
  52. mob.addComponent('aggro', {
  53. faction: blueprint.faction
  54. });
  55. }
  56. mob.addComponent('equipment');
  57. mob.addComponent('inventory', drops);
  58. if (this.zone) {
  59. var chats = this.zone.chats;
  60. if ((chats) && (chats[mob.name.toLowerCase()])) {
  61. mob.addComponent('chatter', {
  62. chats: chats[mob.name.toLowerCase()]
  63. });
  64. }
  65. var dialogues = this.zone.dialogues;
  66. if ((dialogues) && (dialogues[mob.name.toLowerCase()])) {
  67. mob.addComponent('dialogue', {
  68. config: dialogues[mob.name.toLowerCase()]
  69. });
  70. }
  71. }
  72. if ((blueprint.properties) && (blueprint.properties.cpnTrade))
  73. mob.addComponent('trade', blueprint.properties.cpnTrade);
  74. this.scale(mob, blueprint.level);
  75. },
  76. scale: function(mob, level) {
  77. if ((mob.aggro) && (mob.aggro.list > 0))
  78. return;
  79. var drops = mob.inventory.blueprint || {};
  80. var statValues = mob.stats.values;
  81. var preferStat = ['str', 'dex', 'int'][~~(Math.random() * 3)];
  82. var elementType = ['physical', 'poison', 'frost', 'fire', 'holy', 'arcane'][~~(Math.random() * 6)];
  83. mob.equipment.unequipAll();
  84. mob.inventory.clear();
  85. var hp = 10 + (level * 120);
  86. statValues.hpMax = hp;
  87. statValues.level = level;
  88. if (!drops.blueprints) {
  89. [
  90. 'head',
  91. 'chest',
  92. 'neck',
  93. 'hands',
  94. 'waist',
  95. 'legs',
  96. 'feet',
  97. 'finger',
  98. 'trinket',
  99. 'twoHanded'
  100. ].forEach(function(slot) {
  101. var item = itemGenerator.generate({
  102. noSpell: true,
  103. level: level,
  104. slot: slot,
  105. forceStats: [preferStat]
  106. });
  107. mob.inventory.getItem(item);
  108. mob.equipment.autoEquip(item.id);
  109. }, this);
  110. } else {
  111. //TODO: Don't give the mob these items: he'll drop them anyway
  112. drops.blueprints.forEach(function(d) {
  113. var drop = extend(true, {}, d);
  114. d.level = level;
  115. mob.inventory.getItem(itemGenerator.generate(drop));
  116. }, this);
  117. }
  118. var spellCount = (mob.isRare ? 1 : 0) + (mob.isChampion ? 2 : 0);
  119. for (var i = 0; i < spellCount; i++) {
  120. var rune = itemGenerator.generate({
  121. spell: true
  122. });
  123. rune.eq = true;
  124. if (i == 0)
  125. rune.spell.cdMult = 5;
  126. mob.inventory.getItem(rune);
  127. }
  128. /*var rune = itemGenerator.generate({
  129. spell: true,
  130. spellName: 'crystal spikes',
  131. spellProperties: {
  132. radius: 4,
  133. attackTemplate: '0 x x x x x x x 0 x 1 x x x x x 1 x x x 2 x x x 2 x x x x x 3 x 3 x x x x x x x 4 x x x x x x x 3 x 3 x x x x x 2 x x x 2 x x x 1 x x x x x 1 x 0 x x x x x x x 0'
  134. }
  135. });
  136. rune.eq = true;
  137. if (i == 0)
  138. rune.spell.cdMult = 1;
  139. mob.inventory.getItem(rune);
  140. rune = itemGenerator.generate({
  141. spell: true,
  142. spellName: 'magic missile'
  143. });
  144. rune.eq = true;
  145. if (i == 0)
  146. rune.spell.cdMult = 1;
  147. mob.inventory.getItem(rune);*/
  148. var dmgMult = 4;
  149. var hpMult = 1;
  150. if (level < 10) {
  151. hpMult *= [0.005, 0.01, 0.1, 0.2, 0.5, 0.65, 0.75, 0.85, 0.95][level - 1];
  152. dmgMult *= [0.2, 0.45, 0.7, 0.8, 0.9, 0.92, 0.94, 0.96, 0.98][level - 1]
  153. }
  154. if (mob.isRare) {
  155. dmgMult *= 1.25;
  156. hpMult *= 1.25;
  157. }
  158. if (mob.isChampion) {
  159. dmgMult *= 2;
  160. hpMult *= 3;
  161. }
  162. statValues.hpMax *= hpMult;
  163. statValues.hp = statValues.hpMax;
  164. statValues.mana = statValues.manaMax;
  165. mob.spellbook.spells.forEach(function(s) {
  166. s.dmgMult = dmgMult;
  167. s.statType = preferStat;
  168. s.element = elementType;
  169. s.manaCost = 0;
  170. var damage = combat.getDamage({
  171. source: mob,
  172. target: mob,
  173. damage: (s.damage || s.healing) * (s.dmgMult || 1),
  174. cd: s.cdMax,
  175. element: s.element,
  176. statType: s.statType,
  177. statMult: s.statMult,
  178. noMitigate: false
  179. });
  180. }, this);
  181. ['hp', 'hpMax', 'mana', 'manaMax', 'level'].forEach(function(s) {
  182. mob.syncer.setObject(false, 'stats', 'values', s, statValues[s]);
  183. });
  184. }
  185. };
  186. });