ConceptCreator/src/app/project/game-model/gamesystems/conditions/ScriptAccountCondition.ts
Sebastian Böckelmann bcd06d894f
All checks were successful
E2E Testing / test (push) Successful in 1m32s
Implement Interactionstructure
2024-05-11 17:11:13 +02:00

46 lines
1.7 KiB
TypeScript

import {ScriptAccount} from "../../scriptAccounts/ScriptAccount";
import {Condition} from "../../interactions/condition/Condition";
import {CharacterDependency} from "../../interactions/CharacterDependency";
export class ScriptAccountCondition extends Condition{
scriptAccount: ScriptAccount
minValue: number
maxValue: number
private constructor(scriptAccount: ScriptAccount, minValue: number, maxValue: number) {
super(CharacterDependency.NONE);
this.scriptAccount = scriptAccount;
this.minValue = minValue;
this.maxValue = maxValue;
}
static constructScriptAccountCondition(scriptAccount: ScriptAccount, minValue: number, maxValue: number) {
if(scriptAccount == undefined || minValue == undefined || maxValue == undefined || minValue > maxValue) return undefined
return new ScriptAccountCondition(scriptAccount, minValue, maxValue)
}
extendCondition(condition: ScriptAccountCondition) {
if(!this.isContradicting(condition) && this.scriptAccount === condition.scriptAccount) {
this.minValue = Math.min(this.minValue, condition.minValue);
this.maxValue = Math.max(this.maxValue, condition.maxValue);
}
}
combineCondition(condition: ScriptAccountCondition) {
if(condition.scriptAccount === this.scriptAccount) {
const scriptAccount = new ScriptAccountCondition(this.scriptAccount, this.minValue, this.maxValue);
scriptAccount.extendCondition(condition);
return scriptAccount;
}
return undefined;
}
isContradicting(condition: ScriptAccountCondition) {
return condition.scriptAccount === this.scriptAccount &&
(this.maxValue < condition.minValue || this.minValue > condition.maxValue)
}
}