|
@@ -1,56 +1,80 @@
|
|
|
/// <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; };
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #value = 0;
|
|
|
-
|
|
|
- static get(scaleId:string,playerValue:number=0):PersonalityScale{
|
|
|
- return (new PersonalityScale(PersonalityScale.#staticData(scaleId))).apply(playerValue).init({id:scaleId});
|
|
|
- }
|
|
|
-
|
|
|
- static #staticData(scaleId:string):{ [key: string]: any; }{
|
|
|
- return setup.personalityScales[scaleId];
|
|
|
- }
|
|
|
-
|
|
|
- apply(playerValue:number){
|
|
|
- this.#value = playerValue;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- get current():number{
|
|
|
- return this.#value;
|
|
|
- }
|
|
|
- set current(v:number){
|
|
|
- v = Math.clamp(v,this.interval[0],this.interval[1]);
|
|
|
- this.#value = v;
|
|
|
- State.variables.pc.personalitySet(this.id,v);
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
+ 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;
|