Skill.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /// <reference path="PersonStat.ts" />
  2. interface SkillBearer {
  3. getSkill (attr : Skill) : number;
  4. setSkill (attr : Skill, value : number) : void;
  5. }
  6. class Skill extends PersonStat {
  7. public defaultValue : number = 0;
  8. public maxValue : number = 5;
  9. public constructor (id : string, description? : string | Say | ((value : number) => string | Say)) {
  10. super(id, description);
  11. Skill.Skills[id] = this;
  12. }
  13. private static Skills : {[id : string] : Skill} = {};
  14. public static getSkills () {
  15. let skills = [];
  16. for (let key in Skill.Skills) {
  17. skills.push(Skill.Skills[key]);
  18. }
  19. skills.sort((a : Skill, b : Skill) => {
  20. let na = a.id.toUpperCase();
  21. let nb = b.id.toUpperCase();
  22. if (na > nb) return 1;
  23. if (na < nb) return -1;
  24. return 0;
  25. });
  26. return skills;
  27. }
  28. public static getSkill (id : string) {
  29. return Skill.Skills[id];
  30. }
  31. }
  32. module Skills {
  33. export let Survival = new Skill(
  34. "Survival",
  35. (value) => {
  36. switch (value) {
  37. case 5: return "";
  38. case 4: return "";
  39. case 3: return "";
  40. case 2: return "";
  41. case 1: return "Alert Chihuahua";
  42. }
  43. }
  44. );
  45. }