const DNTIMESCALE = 2
export class daynightC extends ModuleC<daynightS, undefined>{
protected async onStart() {
Skybox.moonTextureID = "95626";
Skybox.sunTextureID = "185701";
setInterval(() => {
/**清晨 */
if (this.secondcountC == Math.round(360 * DNTIMESCALE)) {
this.changesky(-80, -90, 6, 1.8, -0.2, "108338", true, 5, 360 * DNTIMESCALE);
//this.nextstageC = "中午";
}
/**中午 */
if (this.secondcountC == Math.round(720 * DNTIMESCALE)) {
this.changesky(100, 0, 1, 0.6, 0.1, "59816", true, 1.5, 360 * DNTIMESCALE);
//this.nextstageC = "傍晚";
}
/**傍晚 */
if (this.secondcountC == Math.round(1080 * DNTIMESCALE)) {
this.changesky(-80, -90, 0.1, 0.2, -0.4, "59821", false, 0.8, 360 * DNTIMESCALE);
Skybox.skyDomeTextureID = "59832";
//this.nextstageC = "凌晨";
}
/**凌晨*/
if (this.secondcountC >= Math.round(1440 * DNTIMESCALE)) {
this.secondcountC = 0;
this.changesky(100, 0, 2, 0.6, -0.6, "108338", false, 0.8, 360 * DNTIMESCALE);
//this.nextstageC = "清晨";
}
this.secondcountC++;
}, 1000)
SystemUtil.onResume.add(() => {
this.server.net_callforsync()
})
}
private secondcountC = 0
//private nextstageC = "清晨"
net_sync_C(secondcount: number, nextstage: string) {
this.secondcountC = secondcount
//this.nextstageC = nextstage
const nextstagetime = Math.round(Math.round(360 * DNTIMESCALE) - (this.secondcountC % Math.round(360 * DNTIMESCALE)));
if (nextstage == "中午") {
this.changesky(100, 0, 2, 0.6, -0.6, "108338", false, 0.8, 0.02);
setTimeout(() => {
this.changesky(-80, -90, 6, 1.8, -0.2, "108338", true, 5, nextstagetime);
}, 60);
}
if (nextstage == "傍晚") {
this.changesky(-80, -90, 6, 1.8, -0.2, "108338", true, 5, 0.02);
setTimeout(() => {
this.changesky(100, 0, 1, 0.6, 0.1, "59816", true, 1.5, nextstagetime);
}, 60);
}
if (nextstage == "凌晨") {
this.changesky(100, 0, 1, 0.6, 0.1, "59816", true, 1.5, 0.02);
setTimeout(() => {
this.changesky(-80, -90, 0.1, 0.2, -0.4, "59821", false, 0.8, nextstagetime);
}, 60);
}
if (nextstage == "清晨") {
this.changesky(-80, -90, 0.1, 0.2, -0.4, "59821", false, 0.8, 0.02);
setTimeout(() => {
this.changesky(100, 0, 2, 0.6, -0.6, "108338", false, 0.8, nextstagetime);
}, 60);
}
}
private loop: number
/** [客户端]改天换日的核心方法,使用Tween动画实现,纯客户端调用
* @param yawAngle [瞬] 日月朝向角度
* @param pitchAngle [渐变] 俯仰角度
* @param Dir_intensity [渐变] 平行光强度(直射光
* @param Global_intensity [渐变] 天光强度(全局光
* @param Sky_intensity [渐变] 曝光补偿(O入光圈)
* @param SkyboxGUID [瞬] 结束时切换到哪张天空盒
* @param ChangeIntoSun [瞬] 切换太阳和月亮,T=切换进太阳,F=切换进月亮
* @param skyDomeIntensity [渐变] 天空盒亮度
* @param time [可选] 渐变时间秒
*/
private changesky(yawAngle: number, pitchAngle: number, Dir_intensity: number, Global_intensity: number, Sky_intensity: number, SkyboxGUID: string, ChangeIntoSun: boolean, skyDomeIntensity: number,
tweentime?: number) {
clearInterval(this.loop)
Lighting.yawAngle = yawAngle;
Skybox.sunVisible = ChangeIntoSun;
Skybox.moonVisible = !ChangeIntoSun;
if(tweentime) {
const delta_dir_intensity = (Dir_intensity - Lighting.directionalLightIntensity) / tweentime
const delta_pitchangle = (pitchAngle - Lighting.pitchAngle) / tweentime
const delta_skydomeintensity = (skyDomeIntensity - Skybox.skyDomeIntensity) / tweentime
const delta_sky_intensity = (Sky_intensity - Lighting.ev100) / tweentime
const delta_global_intensity = (Global_intensity - Lighting.skyLightIntensity) / tweentime
let clock = 0
this.loop = setInterval(() => {
Lighting.directionalLightIntensity = Lighting.directionalLightIntensity + delta_dir_intensity
Lighting.pitchAngle = Lighting.pitchAngle + delta_pitchangle
Skybox.skyDomeIntensity = Skybox.skyDomeIntensity + delta_skydomeintensity
Lighting.ev100 = Lighting.ev100 + delta_sky_intensity
Lighting.skyLightIntensity = Lighting.skyLightIntensity + delta_global_intensity
clock++
if(clock >= tweentime) {
clearInterval(this.loop)
Skybox.skyDomeTextureID = SkyboxGUID
}
}, 1000)
} else {
Lighting.directionalLightIntensity = Dir_intensity
Lighting.pitchAngle = pitchAngle
Skybox.skyDomeIntensity = skyDomeIntensity
Lighting.ev100 = Sky_intensity
Lighting.skyLightIntensity = Global_intensity
}
}
}
export class daynightS extends ModuleS<daynightC, undefined>{
private secondcount = 0
private nextstage: string = "清晨";
protected async onStart() {
setTimeout(() => {
if(Math.random() < 0.5) {
this.secondcount = Math.round(360 * DNTIMESCALE)
this.nextstage = "中午";
} else {
this.secondcount = Math.round(1080 * DNTIMESCALE)
this.nextstage = "凌晨";
}
setInterval(() => {
/**清晨 */
if (this.secondcount == Math.round(360 * DNTIMESCALE)) {
this.nextstage = "中午";
}
/**中午 */
if (this.secondcount == Math.round(720 * DNTIMESCALE)) {
this.nextstage = "傍晚";
}
/**傍晚 */
if (this.secondcount == Math.round(1080 * DNTIMESCALE)) {
this.nextstage = "凌晨";
}
/**凌晨*/
if (this.secondcount >= Math.round(1440 * DNTIMESCALE)) {
this.secondcount = 0;
this.nextstage = "清晨";
this.getAllClient().net_sync_C(this.secondcount, this.nextstage)
}
this.secondcount++;
}, 1000)
}, 2000);
}
protected onPlayerEnterGame(player: mw.Player): void {
setTimeout(() => {
if(player.character) {
this.getClient(player).net_sync_C(this.secondcount, this.nextstage);
}
}, 4000);
}
net_callforsync() {
this.getClient(this.currentPlayer).net_sync_C(this.secondcount, this.nextstage)
}
}
|