Skip to content

Commit

Permalink
Release 1.3.1
Browse files Browse the repository at this point in the history
Fix lifetime initialization on newly discovered scrapyards
  • Loading branch information
ctcDNightmare committed Oct 2, 2017
2 parents 9060990 + d40493f commit b1e8d83
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### Version 1.3.1 *"unassimilable-demodulator"*
* fixed lifetime initialization on newly discovered scrapyards

#### Version 1.3.0 *"preelementary-reptile"*
* restructured file-layout
* changed nicerNumbers helper to vanilla equivalent
Expand Down
2 changes: 1 addition & 1 deletion mods/ScrapyardPlus/config/ScrapyardPlus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ScrapyardPlus.author = "DNightmare"
ScrapyardPlus.homepage = "https://github.com/ctcDNightmare"
ScrapyardPlus.tags = {"scrapyard", "overhaul", "server", "client", "events", "lifetime-license" }
ScrapyardPlus.version = {
major=1, minor=3, patch = 0,
major=1, minor=3, patch = 1,
string = function()
return ScrapyardPlus.version.major .. '.' ..
ScrapyardPlus.version.minor .. '.' ..
Expand Down
53 changes: 32 additions & 21 deletions mods/ScrapyardPlus/scripts/entity/merchants/scrapyard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ local typeAlliance = 'ALLIANCE'
local typeSolo = 'SOLO'

-- server
local licenses
local illegalActions
local legalActions
local licenses = {}
local illegalActions = {}
local legalActions = {}
local newsBroadcastCounter = 0
local highTrafficSystem = false
local highTrafficTimer = 0
Expand Down Expand Up @@ -256,6 +256,10 @@ function Scrapyard.initialize()
highTrafficSystem = false
end

-- check for lifetime reached
local experience = Scrapyard.loadExperience(Faction().index)
local lifetimeReached = (experience[Faction().index] >= modConfig.lifetimeExpRequired)

end

if onClient() then
Expand All @@ -265,8 +269,8 @@ function Scrapyard.initialize()
EntityIcon().icon = "data/textures/icons/pixel/scrapyard_fat.png"
InteractionText().text = Dialog.generateStationInteractionText(Entity(), random())
end
invokeServerFunction("checkLifetime", Player().index)
end

end

function Scrapyard.initUI()
Expand Down Expand Up @@ -570,6 +574,7 @@ function Scrapyard.updateServer(timeStep)
disasterTimer = 0
end

if not illegalActions then illegalActions = {} end
for factionIndex, actions in pairs(illegalActions) do

actions = actions - 1
Expand All @@ -585,16 +590,20 @@ function Scrapyard.updateServer(timeStep)
legalActions = {}
end

if not licenses then licenses = {} end
for factionIndex, time in pairs(licenses) do
local faction = Faction(factionIndex)
if not faction then return end

-- check for lifetime reached

local experience = Scrapyard.loadExperience(factionIndex)
local lifetimeReached = (experience[Faction().index] >= modConfig.lifetimeExpRequired)

if not lifetimeReached then
if lifetimeReached then
if time < 3600 then -- lock time at 1 hr as 'lifetime'
time = 3600
end
else
time = time - timeStep
end

Expand Down Expand Up @@ -908,6 +917,22 @@ function Scrapyard.onBuyLicenseButtonPressed(button)
end
end

function Scrapyard.checkLifetime(playerIndex)
local player = Player(playerIndex)
local soloExperience = Scrapyard.loadExperience(player.index)
if soloExperience[Faction().index] >= modConfig.lifetimeExpRequired then
licenses[player.index] = 3600
end

local alliance = player.allianceIndex
if alliance then
local allianceExperience = Scrapyard.loadExperience(alliance)
if allianceExperience[Faction().index] >= modConfig.lifetimeExpRequired then
licenses[alliance] = 3600
end
end
end

function Scrapyard.getMaxLicenseDuration(player)
local currentReputation = player:getRelations(Faction().index)
local reputationBonusFactor = math.floor(currentReputation / 10000)
Expand Down Expand Up @@ -998,22 +1023,8 @@ function Scrapyard.allowedDamaging(faction)
if actions >= modConfig.lifetimeExpTicks then
local reputation = faction:getRelations(scrapyardFaction.index)
if reputation >= modConfig.lifetimeRepRequired then
local experience
local serialized = faction:getValue(MODULE .. FS .. 'experience')
if serialized ~= nil then
experience = loadstring(serialized)()
if type(experience) ~= 'table' then
experience = {}
end
else
experience = {}
end

if experience[scrapyardFaction.index] == nil then
experience[scrapyardFaction.index] = 0
end
local experience = Scrapyard.loadExperience(faction.index)
local current = experience[scrapyardFaction.index]

local newExp
if current < modConfig.lifetimeExpRequired then
newExp = Scrapyard.calculateNewExperience(current)
Expand Down

0 comments on commit b1e8d83

Please sign in to comment.