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.
 
 
 

203 lines
4.8 KiB

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