-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
131 lines (108 loc) · 3.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const { DateTime } = require("luxon");
const aeroData = require("./data/aero.json");
const tz = require("./data/tz.json");
const allowedTimeType = ["local", "server", "static"];
const allowedDayPart = ["night", "night-weather", "morning", "morning-weather", "day", "day-weather", "evening", "evening-weather"];
class DynamicDayTime {
constructor(mod) {
mod.game.initialize("me");
const serverTZ = tz[mod.publisher];
let intervalRef = undefined;
let lastAero = undefined;
let lastDayPart = undefined;
const sendAero = (aero, blendTime) => {
mod.send("S_AERO", 1, {
"enabled": true,
"blendTime": blendTime,
"aeroSet": aero
});
};
const resetAero = () => {
mod.send("S_SPAWN_NPC", mod.majorPatchVersion >= 101 ? 12 : 11, {
gameId: 696969696969,
templateId: 8005000,
huntingZoneId: 1023,
spawnScript: 105,
visible: true
})
mod.send("S_DESPAWN_NPC", 3, {
gameId: 696969696969,
type: 1
})
}
const applyAero = (aero, blendTime) => {
if(mod.game.me.inDungeon) return;
resetAero();
sendAero(aero, blendTime);
};
const getCurrentDayState = () => {
let hours = 0;
switch(mod.settings.timeType) {
case("local"): hours = DateTime.local().hour; break;
case("server"): hours = serverTZ ? DateTime.utc().setZone(serverTZ).hour : DateTime.local().hour; break;
case("static"): return mod.settings.staticTime;
default : hours = DateTime.local().hour; break;
}
if ((hours >= 23) || (hours <= 4)) return mod.settings.useWeather ? "night-weather" : "night";
else if (hours >= 5 && hours <= 10) return mod.settings.useWeather ? "morning-weather" :"morning";
else if (hours >= 11 && hours <= 16) return mod.settings.useWeather ? "day-weather" : "day";
else if (hours >= 17 && hours < 23) return mod.settings.useWeather ? "evening-weather" : "evening";
}
const generateAero = (force = false) => {
let newDayPart = getCurrentDayState();
if (!force && newDayPart === lastDayPart) return;
let arr = aeroData.enumAero[newDayPart];
let newAero = arr[Math.floor(Math.random() * arr.length)];
if (lastAero !== newAero) {
lastAero = newAero;
lastDayPart = newDayPart;
applyAero(newAero, mod.settings.transitionTime)
}
};
mod.hook("S_LOGIN", "event", () => {
intervalRef = mod.setInterval(generateAero, mod.settings.updateTryDelay);
});
mod.hook("S_RETURN_TO_LOBBY", "event", () => {
mod.clearInterval(intervalRef);
});
mod.hook("S_SPAWN_ME", "event", () => {
mod.setTimeout(()=> {
if(lastAero === undefined)
generateAero();
else
applyAero(lastAero, 1);
}, mod.settings.delayAtSpawn);
});
mod.command.add("dn", {
"type": (type) => {
if (!allowedTimeType.includes(type)) {
mod.command.message("Invalid time type parameter!");
return;
}
mod.settings.timeType = type;
mod.command.message(`Time type changed to "${mod.settings.timeType}"`)
},
"day": (daypart) => {
if(mod.settings.timeType !== "static") {
mod.command.message("You can't manually change current status - time type is not static");
return;
}
if(!allowedDayPart.includes(daypart)) {
mod.command.message("Invalid day type parameter!");
return;
}
mod.settings.staticTime = daypart;
generateAero(true);
},
"weather": () => {
mod.settings.useWeather = !mod.settings.useWeather;
mod.command.message(`Apply weather: ${mod.settings.useWeather}`);
},
"roll": () => {
mod.command.message("Applying different aero based on day time");
generateAero(true);
}
})
}
}
module.exports = DynamicDayTime;