PersonalityScale.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /// <reference path="../../../_shared/Initializing.ts"/>
  2. const personalityScaleHistoryMaxsize = 10;
  3. class PersonalityScale extends Initializing implements PersonalityScaleDefinition{
  4. id:string;
  5. start:number;
  6. hidden?: boolean;
  7. interval: number[];
  8. label: string | string[];
  9. desc?: string;
  10. image?: string;
  11. msg_tooHigh?: string;
  12. msg_tooLow?: string;
  13. functions?: { [key: string]: (any: any) => any; };
  14. #pc: PlayerCharacter;
  15. static get(scaleId:string,pc:PlayerCharacter):PersonalityScale{
  16. const newScale = new PersonalityScale(PersonalityScale.#staticData(scaleId));
  17. newScale.id = scaleId;
  18. newScale.#pc = pc;
  19. return newScale;
  20. }
  21. static #staticData(scaleId:string):{ [key: string]: any; }{
  22. return setup.personalityScales[scaleId];
  23. }
  24. get current():number{
  25. return this.#dataEntry.history[0][1];
  26. }
  27. set current(v:number){
  28. v = Math.clamp(v,this.interval[0],this.interval[1]);
  29. this.#dataEntry.history[0][1] = v;
  30. }
  31. get currentYesterday(){
  32. return this.#dataEntry.history[1][1];
  33. }
  34. get #dataEntry(){
  35. const daystartS = State.variables.time.daystartS;
  36. let dataEntry = this.#pc._personalityValues[this.id];
  37. if(dataEntry.history[0][0] != daystartS)
  38. dataEntry.history.unshift([daystartS,dataEntry.history[0][1]]);
  39. if(dataEntry.history.length > personalityScaleHistoryMaxsize)
  40. dataEntry.history.pop();
  41. return dataEntry;
  42. }
  43. moveTo(v:number):number{
  44. const current = this.current;
  45. const diffference = v - current;
  46. const inreaseRaw = diffference / 10;
  47. const increaseEffective = Math.ceilAbs(inreaseRaw);
  48. this.current += increaseEffective;
  49. return this.current;
  50. }
  51. requiredWillpower(targetValue:number){
  52. /*let effecitveDifference = Math.max(0,targetValue-this.#value);
  53. if(effecitveDifference <= 30)
  54. return Math.ceil(Math.pow(2,effecitveDifference/10)*10)-10;
  55. return Infinity;*/
  56. }
  57. constructor(ps={}){
  58. super();
  59. this.init(ps);
  60. }
  61. }
  62. setup.PersonalityScale = PersonalityScale;
  63. setup.personalityScales = {};