Weapon.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /// <reference path="../Clothing.ts" />
  2. /// <reference path="../Person/Attribute.ts" />
  3. interface WeaponOptions extends ClothingOptions {
  4. leftHand : boolean;
  5. rightHand : boolean;
  6. attribute? : Attribute;
  7. baseDamage? : number;
  8. attackCost? : number;
  9. }
  10. class Weapon extends Clothing {
  11. private baseDamage : number = 0;
  12. private attribute = undefined;
  13. public attackCost = 1;
  14. constructor (t : WeaponOptions) {
  15. super(t);
  16. if (t.leftHand) {
  17. this.slots.push(Humanoid.SLOT_LEFTHAND);
  18. }
  19. if (t.rightHand) {
  20. this.slots.push(Humanoid.SLOT_RIGHTHAND);
  21. }
  22. this.baseDamage = t.baseDamage == undefined ? 0 : t.baseDamage;
  23. this.attackCost = t.attackCost == undefined ? 1 : t.attackCost;
  24. this.attribute = t.attribute;
  25. }
  26. public getDamage () {
  27. let damage = this.baseDamage;
  28. let wielder = <Person> this.getWearOne();
  29. let attrValue : number;
  30. if (this.attribute != undefined) {
  31. attrValue = wielder.getStat(this.attribute);
  32. } else {
  33. attrValue = 0;
  34. }
  35. // TODO: Reconsider RNG.
  36. let result = attrValue + (1 + Math.floor(Math.random() * damage));
  37. if (this.slots.length == 2) {
  38. return Math.floor(result * 5 / 3); // Twohanded modifier
  39. } else {
  40. return Math.floor(result * 2 / 3); // One-handed modifier
  41. }
  42. }
  43. }