forked from otland/forgottenserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move world time and light to lua (otland#4583)
* Move world time and light to lua * Some fix * Remove duplicated checks and move return to last fn line * Move world packet to lua
- Loading branch information
1 parent
561d7b0
commit 3877aa9
Showing
12 changed files
with
144 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
local event = CreatureEvent("WorldTimeAndLight") | ||
|
||
function event.onLogin(player) | ||
local worldTime = Game.getWorldTime() | ||
player:sendWorldTime(worldTime) | ||
|
||
local worldLightColor, worldLightLevel = Game.getWorldLight() | ||
player:sendWorldLight(worldLightColor, worldLightLevel) | ||
return true | ||
end | ||
|
||
event:register() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
local event = GlobalEvent("WorldLight") | ||
|
||
local lightConfig = { | ||
day = 250, | ||
night = 40 | ||
} | ||
|
||
local worldConfig = { | ||
sunrise = 360, | ||
dayTime = 480, | ||
sunset = 1080, | ||
nightTime = 1200 | ||
} | ||
|
||
local lightChange = { | ||
sunrise = math.floor((lightConfig.day - lightConfig.night) / (worldConfig.dayTime - worldConfig.sunrise) * 100) / 100, | ||
sunset = math.floor((lightConfig.day - lightConfig.night) / (worldConfig.nightTime - worldConfig.sunset) * 100) / 100 | ||
} | ||
|
||
do | ||
-- load default values | ||
local defaultColor = 215 | ||
local defaultLevel = lightConfig.day | ||
Game.setWorldLight(defaultColor, defaultLevel) | ||
end | ||
|
||
local function calculateWorldLightLevel() | ||
local worldTime = Game.getWorldTime() | ||
if worldTime >= worldConfig.sunrise and worldTime <= worldConfig.dayTime then | ||
return ((worldConfig.dayTime - worldConfig.sunrise) - (worldConfig.dayTime - worldTime)) * lightChange.sunrise + lightConfig.night | ||
elseif worldTime >= worldConfig.sunset and worldTime <= worldConfig.nightTime then | ||
return lightConfig.day - ((worldTime - worldConfig.sunset) * lightChange.sunset) | ||
elseif worldTime >= worldConfig.nightTime or worldTime < worldConfig.sunrise then | ||
return lightConfig.night | ||
end | ||
return lightConfig.day | ||
end | ||
|
||
function event.onTime(interval) | ||
if not configManager.getBoolean(configKeys.DEFAULT_WORLD_LIGHT) then | ||
return true | ||
end | ||
|
||
local worldLightColor, worldLightLevel = Game.getWorldLight() | ||
local level = calculateWorldLightLevel() | ||
Game.setWorldLight(worldLightColor, level) | ||
return true | ||
end | ||
|
||
event:interval(10000) -- 10 seconds | ||
event:register() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
local event = GlobalEvent("WorldTime") | ||
|
||
-- 1h realtime = 1day worldtime | ||
-- 2.5s realtime = 1min worldtime | ||
-- worldTime is calculated in minutes | ||
|
||
function event.onTime(interval) | ||
local currentTime = os.time() | ||
local time = os.date("*t", currentTime) | ||
local worldTime = (time.sec + (time.min * 60)) / 2.5 | ||
Game.setWorldTime(worldTime) | ||
return true | ||
end | ||
|
||
event:interval(2500) -- 2.5 seconds | ||
event:register() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.