mirror of
https://github.com/YouHaveTrouble/GuildMaster.git
synced 2026-05-11 22:16:59 +00:00
somewhat closer to the final product quest phase system
This commit is contained in:
@@ -1,26 +1,29 @@
|
|||||||
import type {Adventurer} from "@/classes/Adventurer";
|
import type {Adventurer} from "@/classes/Adventurer";
|
||||||
import {PhaseType} from "@/classes/quests/QuestPhaseType";
|
import {PhaseType} from "@/classes/quests/QuestPhaseType";
|
||||||
|
|
||||||
export default abstract class QuestPhase {
|
export default class QuestPhase {
|
||||||
|
|
||||||
type: PhaseType;
|
types: Set<PhaseType>;
|
||||||
points: number;
|
points: number;
|
||||||
maxPoints: number;
|
maxPoints: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
type: PhaseType,
|
types: PhaseType[],
|
||||||
maxPoints: number = 1,
|
maxPoints: number,
|
||||||
points: number = 0,
|
points: number = 0,
|
||||||
) {
|
) {
|
||||||
this.type = type;
|
this.types = new Set<PhaseType>(types);
|
||||||
this.points = points;
|
this.points = Math.max(0, points);
|
||||||
this.maxPoints = maxPoints;
|
this.maxPoints = Math.max(1, maxPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get how many points should be added each tick based on adventurers on a task.
|
* Get how many points should be added each tick based on adventurers on a task.
|
||||||
*/
|
*/
|
||||||
abstract getPointIncrement(adventurers: Array<Adventurer>): number;
|
getPointIncrement(adventurers: Array<Adventurer>): number {
|
||||||
|
// TODO add point multiplier based on adventurer stats
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
public tick(adventurers: Array<Adventurer> = []) {
|
public tick(adventurers: Array<Adventurer> = []) {
|
||||||
if (this.completed()) return;
|
if (this.completed()) return;
|
||||||
@@ -32,4 +35,33 @@ export default abstract class QuestPhase {
|
|||||||
return this.points >= this.maxPoints;
|
return this.points >= this.maxPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public serialize(): string {
|
||||||
|
return JSON.stringify({
|
||||||
|
types: Array.from(this.types),
|
||||||
|
points: this.points,
|
||||||
|
maxPoints: this.maxPoints,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static deserialize(data: string): QuestPhase {
|
||||||
|
const parsedData = JSON.parse(data);
|
||||||
|
|
||||||
|
if (typeof parsedData?.points !== 'number') {
|
||||||
|
throw new Error("Invalid data: 'points' must be a number.");
|
||||||
|
}
|
||||||
|
if (typeof parsedData?.maxPoints !== 'number') {
|
||||||
|
throw new Error("Invalid data: 'maxPoints' must be a number.");
|
||||||
|
}
|
||||||
|
if (!Array.isArray(parsedData?.types)) {
|
||||||
|
throw new Error("Invalid data: 'types' must be an array.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const types = parsedData.types.map((type: string) => PhaseType[type as keyof typeof PhaseType]);
|
||||||
|
return new QuestPhase(
|
||||||
|
types,
|
||||||
|
parsedData.maxPoints,
|
||||||
|
parsedData.points
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user