-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
world light to lua / effect & mastereffect
- Loading branch information
1 parent
4e7231e
commit f52b7dc
Showing
19 changed files
with
210 additions
and
205 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ continuation_indent_width: 1 | |
use_tab: true | ||
tab_width: 4 | ||
chop_down_table: true | ||
column_limit: 130 | ||
column_limit: 100 |
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,44 @@ | ||
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 math.floor(((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,17 @@ | ||
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 sec = os.date("%S", currentTime) | ||
local min = os.date("%M", currentTime) | ||
local worldTime = (sec + (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
Oops, something went wrong.