123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- /// <reference path="../../../_shared/Initializing.ts"/>
- const personalityScaleHistoryMaxsize = 10;
- class PersonalityScale extends Initializing implements PersonalityScaleDefinition{
- id:string;
- start:number;
- hidden?: boolean;
- interval: number[];
- label: string | string[];
- desc?: string;
- image?: string;
- msg_tooHigh?: string;
- msg_tooLow?: string;
- functions?: { [key: string]: (any: any) => any; };
- #pc: PlayerCharacter;
- static get(scaleId:string,pc:PlayerCharacter):PersonalityScale{
- const newScale = new PersonalityScale(PersonalityScale.#staticData(scaleId));
- newScale.id = scaleId;
- newScale.#pc = pc;
- return newScale;
- }
- static #staticData(scaleId:string):{ [key: string]: any; }{
- return setup.personalityScales[scaleId];
- }
- get current():number{
- return this.#dataEntry.history[0][1];
- }
- set current(v:number){
- v = Math.clamp(v,this.interval[0],this.interval[1]);
- this.#dataEntry.history[0][1] = v;
- }
- get currentYesterday(){
- return this.#dataEntry.history[1][1];
- }
- get #dataEntry(){
- const daystartS = State.variables.time.daystartS;
- let dataEntry = this.#pc._personalityValues[this.id];
- if(dataEntry.history[0][0] != daystartS)
- dataEntry.history.unshift([daystartS,dataEntry.history[0][1]]);
- if(dataEntry.history.length > personalityScaleHistoryMaxsize)
- dataEntry.history.pop();
- return dataEntry;
- }
- moveTo(v:number):number{
- const current = this.current;
- const diffference = v - current;
- const inreaseRaw = diffference / 10;
- const increaseEffective = Math.ceilAbs(inreaseRaw);
- this.current += increaseEffective;
- return this.current;
- }
- requiredWillpower(targetValue:number){
- /*let effecitveDifference = Math.max(0,targetValue-this.#value);
- if(effecitveDifference <= 30)
- return Math.ceil(Math.pow(2,effecitveDifference/10)*10)-10;
- return Infinity;*/
- }
- constructor(ps={}){
- super();
- this.init(ps);
- }
-
- }
- setup.PersonalityScale = PersonalityScale;
- setup.personalityScales = {};
|