mirror of
https://github.com/YouHaveTrouble/DiscipleOfLand.git
synced 2026-05-12 14:36:55 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
export default class Aetheryte {
|
||||
|
||||
readonly position: { x: number, y: number, zone: string };
|
||||
readonly name: {
|
||||
en: string,
|
||||
}
|
||||
|
||||
constructor(
|
||||
data: any,
|
||||
) {
|
||||
this.position = data.position;
|
||||
this.name = data.name.en;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
export default class Item {
|
||||
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly level: number;
|
||||
readonly scripType: ScripType;
|
||||
|
||||
constructor(id: string, data: any) {
|
||||
this.id = id;
|
||||
this.name = data?.name;
|
||||
this.level = data?.level;
|
||||
this.scripType = data?.scripType ? ScripType[data.scripType.toUpperCase()] : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum ScripType {
|
||||
WHITE = 'white',
|
||||
PURPLE = 'purple',
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import {Job} from "../enums/Job";
|
||||
import {NodeType} from "../enums/NodeType";
|
||||
import Item from "./Item";
|
||||
import Aetheryte from "./Aetheryte";
|
||||
import TimeRange from "./TimeRange";
|
||||
import EorzeaTime from "../util/EorzeaTime";
|
||||
|
||||
export default class Node {
|
||||
|
||||
readonly job: Job;
|
||||
readonly nodeType: NodeType;
|
||||
readonly location: { x: number, y: number, zone: string };
|
||||
readonly times: Array<TimeRange>;
|
||||
readonly nearestAetheryte: Aetheryte;
|
||||
readonly items: Item[];
|
||||
|
||||
constructor(
|
||||
job: Job,
|
||||
nodeType: NodeType,
|
||||
location: { x: number, y: number, zone: string },
|
||||
times: Array<TimeRange>,
|
||||
items: Item[],
|
||||
nearestAetheryte: Aetheryte,
|
||||
) {
|
||||
this.job = job;
|
||||
this.nodeType = nodeType;
|
||||
this.location = location;
|
||||
this.times = times;
|
||||
this.items = items;
|
||||
this.nearestAetheryte = nearestAetheryte;
|
||||
}
|
||||
|
||||
isActive(eorzeaTime: EorzeaTime): boolean {
|
||||
for (const timeRange of this.times) {
|
||||
if (timeRange.isWithinTimeFrame(eorzeaTime.getHours(), eorzeaTime.getMinutes())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getCountdownToActive(eorzeaTime: EorzeaTime): number {
|
||||
let countdown: number = Infinity;
|
||||
for (const timeRange of this.times) {
|
||||
const nextTimeFrame: number = timeRange.getNextTimeFrame(eorzeaTime);
|
||||
if (nextTimeFrame < countdown) countdown = nextTimeFrame;
|
||||
}
|
||||
return countdown;
|
||||
}
|
||||
|
||||
getNextActiveTime(eorzeaTime: EorzeaTime): EorzeaTime {
|
||||
let countdownTimeStamp: number = Infinity;
|
||||
for (const timeRange of this.times) {
|
||||
const nextTimeFrame: number = timeRange.getNextTimeFrame(eorzeaTime);
|
||||
if (nextTimeFrame < countdownTimeStamp) countdownTimeStamp = nextTimeFrame;
|
||||
}
|
||||
return EorzeaTime.fromEorzeaTime(new Date(this.getCountdownToActive(eorzeaTime)));
|
||||
}
|
||||
|
||||
getSecondsToNextActiveTime(eorzeaTime: EorzeaTime): number {
|
||||
return Math.floor((this.getNextActiveTime(eorzeaTime).realDate.getTime() - eorzeaTime.realDate.getTime()) / 1000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import EorzeaTime from "../util/EorzeaTime";
|
||||
|
||||
export default class TimeRange {
|
||||
|
||||
private readonly from: [number, number];
|
||||
private readonly to: [number, number];
|
||||
|
||||
constructor(fromHour: number, fromMinute: number, toHour: number, toMinute: number) {
|
||||
this.from = [fromHour, fromMinute];
|
||||
this.to = [toHour, toMinute];
|
||||
}
|
||||
|
||||
public isWithinTimeFrame(hour: number, minute: number): boolean {
|
||||
return (
|
||||
this.from[0] < hour || this.from[0] == hour && this.from[1] <= minute)
|
||||
&& (hour < this.to[0] || hour == this.to[0] && minute <= this.to[1]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a timestamp when the time range will be active again
|
||||
*/
|
||||
public getNextTimeFrame(eorzeaTimeFrom: EorzeaTime): number {
|
||||
const targetDate = new Date(eorzeaTimeFrom.eorzeaDate.getTime());
|
||||
targetDate.setUTCHours(this.from[0], 0, 0, 0);
|
||||
if (eorzeaTimeFrom.getHours() >= this.to[0]) {
|
||||
targetDate.setUTCHours(this.from[0] + 24);
|
||||
}
|
||||
return targetDate.getTime();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export default class Zone {
|
||||
|
||||
name: {
|
||||
en: string,
|
||||
}
|
||||
|
||||
constructor(data: any) {
|
||||
this.name = data.name;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user