From 8cf62ee2365e363f8b7e721f27825fbd03ed0cf6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Nov 2015 21:13:01 +0100 Subject: [PATCH] merge the various Christmas modules into one file, make them trigger on a turn, reduce spam --- scripts/eressea/e2/init.lua | 5 ++- scripts/eressea/e3/init.lua | 3 +- scripts/eressea/e4/init.lua | 2 +- scripts/eressea/xmas.lua | 42 +++++++++++++++++++++++++ scripts/eressea/xmas2004.lua | 24 --------------- scripts/eressea/xmas2005.lua | 30 ------------------ scripts/eressea/xmas2006.lua | 53 -------------------------------- scripts/eressea/xmas2009.lua | 30 ------------------ scripts/eressea/xmasitems.lua | 58 +++++++++++++++++++++++++++++++++++ 9 files changed, 105 insertions(+), 142 deletions(-) create mode 100644 scripts/eressea/xmas.lua delete mode 100644 scripts/eressea/xmas2004.lua delete mode 100644 scripts/eressea/xmas2005.lua delete mode 100644 scripts/eressea/xmas2006.lua delete mode 100644 scripts/eressea/xmas2009.lua create mode 100644 scripts/eressea/xmasitems.lua diff --git a/scripts/eressea/e2/init.lua b/scripts/eressea/e2/init.lua index dd01a06d4..7193a721b 100644 --- a/scripts/eressea/e2/init.lua +++ b/scripts/eressea/e2/init.lua @@ -4,9 +4,8 @@ eressea.log.debug("rules for game E2") return { require('eressea'), require('eressea.autoseed'), - require('eressea.xmas2004'), - require('eressea.xmas2005'), - require('eressea.xmas2006'), + require('eressea.xmas'), + require('eressea.xmasitems'), require('eressea.wedding'), require('eressea.embassy'), require('eressea.eternath'), diff --git a/scripts/eressea/e3/init.lua b/scripts/eressea/e3/init.lua index 3132e63f5..cb91b4713 100644 --- a/scripts/eressea/e3/init.lua +++ b/scripts/eressea/e3/init.lua @@ -5,7 +5,8 @@ eressea.log.debug("rules for game E3") return { require('eressea'), - require('eressea.xmas2009'), + require('eressea.xmas'), + require('eressea.xmasitems'), require('eressea.markets'), require('eressea.frost'), require('eressea.ents') diff --git a/scripts/eressea/e4/init.lua b/scripts/eressea/e4/init.lua index 26018debe..e5e617c55 100644 --- a/scripts/eressea/e4/init.lua +++ b/scripts/eressea/e4/init.lua @@ -1,7 +1,7 @@ require 'eressea.e3.rules' require 'eressea.spells' -eressea.log.debug("rules for game E3") +eressea.log.debug("rules for game E4") return { require('eressea'), diff --git a/scripts/eressea/xmas.lua b/scripts/eressea/xmas.lua new file mode 100644 index 000000000..52fcf4c4e --- /dev/null +++ b/scripts/eressea/xmas.lua @@ -0,0 +1,42 @@ +local gifts = { + e2 = { + -- { year = 2015, turn = 960, item = 'snowglobe' }, + { year = 2009, turn = 624, key = 'xm09', item = 'xmastree' }, + { year = 2006, turn = 468, key = 'xm06', item = 'snowman' }, + { year = 2005, turn = 416, key = 'xm05', item = 'stardust' }, + { year = 2004, turn = 364, key = 'xm04', item = 'speedsail' } + }, + e3 = { + -- { year = 2015, turn = 338, item = 'snowglobe' }, + { year = 2009, turn = 26, key = 'xm09', item = 'xmastree' } + } +} + +local function give_gifts(gift) + eressea.log.info("Es weihnachtet sehr (" .. gift.year .. ")") + if gift.item then + for f in factions() do + f:add_item(gift.item, 1) + f:add_notice("santa" .. gift.year) + end + end +end + +local self = {} + +function self.init() + local turn = get_turn() + local tbl = gifts[config.rules] + if tbl then + for _, gift in ipairs(tbl) do + if turn == gift.turn then + give_gifts(gift) + elseif gift.key and not get_key(gift.key) then + give_gifts(gift) + set_key(gift.key) + end + end + end +end + +return self diff --git a/scripts/eressea/xmas2004.lua b/scripts/eressea/xmas2004.lua deleted file mode 100644 index 79d2b0665..000000000 --- a/scripts/eressea/xmas2004.lua +++ /dev/null @@ -1,24 +0,0 @@ -function use_snowman(u, amount) - if amount>0 and u.region.terrain == "glacier" then - local man = unit.create(u.faction, u.region) - man.race = "snowman" - man.number = amount - return amount - end - return -4 -end - -local self = {} - -function self.update() - if not get_key("xm04") then - eressea.log.debug("Es weihnachtet sehr (2004)") - set_key("xm04", true) - for f in factions() do - f:add_item("speedsail", 1) - f:add_notice("santa2004") - end - end -end - -return self diff --git a/scripts/eressea/xmas2005.lua b/scripts/eressea/xmas2005.lua deleted file mode 100644 index 9bc0ac723..000000000 --- a/scripts/eressea/xmas2005.lua +++ /dev/null @@ -1,30 +0,0 @@ -function usepotion_message(u, potion) - msg = message.create("usepotion") - msg:set_unit("unit", u) - msg:set_resource("potion", potion) - return msg -end - -function use_stardust(u, amount) - local p = u.region:get_resource("peasant") - p = math.ceil(1.5 * p) - u.region:set_resource("peasant", p) - local msg = usepotion_message(u, "stardust") - msg:send_region(u.region) - return amount -end - -local self = {} - -function self.update() - if not get_key("xm05") then - print("Es weihnachtet sehr (2005)") - set_key("xm05", true) - for f in factions() do - f:add_item("stardust", 1) - f:add_notice("santa2005") - end - end -end - -return self diff --git a/scripts/eressea/xmas2006.lua b/scripts/eressea/xmas2006.lua deleted file mode 100644 index 85a8b3d98..000000000 --- a/scripts/eressea/xmas2006.lua +++ /dev/null @@ -1,53 +0,0 @@ -function use_xmastree(u, amount) - u.region:set_key("xm06", true) - local msg = message.create("usepotion") - msg:set_unit("unit", u) - msg:set_resource("potion", "xmastree") - msg:send_region(u.region) - return amount -end - -local self = {} - -function self.update() - local turn = get_turn() - local season = get_season(turn) - if season == "calendar::winter" then - eressea.log.debug("it is " .. season .. ", the christmas trees do their magic") - local msg = message.create("xmastree_effect") - for r in regions() do - if r:get_key("xm06") then - trees = r:get_resource("tree") - if trees*0.1>=1 then - r:set_resource("tree", trees * 1.1) - msg:send_region(r) - end - if clear then - end - end - end - else - local prevseason = get_season(turn-1) - if prevseason == "calendar::winter" then - -- we celebrate knut and kick out the trees. - for r in regions() do - if r:get_key("xm06") then - r:set_key("xm06", false) - end - end - end - end -end - -function self.init() - if not get_key("xm06") then - print("Es weihnachtet sehr (2006)") - set_key("xm06", true) - for f in factions() do - f:add_item("xmastree", 1) - f:add_notice("santa2006") - end - end -end - -return self diff --git a/scripts/eressea/xmas2009.lua b/scripts/eressea/xmas2009.lua deleted file mode 100644 index 64bcd7762..000000000 --- a/scripts/eressea/xmas2009.lua +++ /dev/null @@ -1,30 +0,0 @@ -function use_xmastree(u, amount) - if u.region.herb~=nil then - -- TODO: else? - local trees = u.region:get_resource("tree") - u.region:set_resource("tree", 10+trees) - local msg = message.create("usepotion") - msg:set_unit("unit", u) - msg:set_resource("potion", "xmastree") - msg:send_region(u.region) - return amount - end - return 0 -end - -local xmas = {} - -function xmas.update() - if not get_key("xm09") then - print("Es weihnachtet sehr (2009)") - set_key("xm09", true) - for f in factions() do - f:add_item("xmastree", 1) - local msg = message.create("msg_event") - msg:set_string("string", translate("santa2006")) - msg:send_faction(f) - end - end -end - -return xmas diff --git a/scripts/eressea/xmasitems.lua b/scripts/eressea/xmasitems.lua new file mode 100644 index 000000000..8bfb1c8bb --- /dev/null +++ b/scripts/eressea/xmasitems.lua @@ -0,0 +1,58 @@ +function use_snowman(u, amount) + if amount>0 and u.region.terrain == "glacier" then + local man = unit.create(u.faction, u.region) + man.race = "snowman" + man.number = amount + return amount + end + return -4 +end + +function use_xmastree(u, amount) + if u.region.herb~=nil then + -- TODO: else? + local trees = u.region:get_resource("tree") + u.region:set_key("xm06", true) + u.region:set_resource("tree", 10+trees) + local msg = message.create("usepotion") + msg:set_unit("unit", u) + msg:set_resource("potion", "xmastree") + msg:send_region(u.region) + return amount + end + return 0 +end + +local self = {} + +function self.update() + local turn = get_turn() + local season = get_season(turn) + if season == "calendar::winter" then + eressea.log.debug("it is " .. season .. ", the christmas trees do their magic") + local msg = message.create("xmastree_effect") + for r in regions() do + if r:get_key("xm06") then + trees = r:get_resource("tree") + if trees*0.1>=1 then + r:set_resource("tree", trees * 1.1) + msg:send_region(r) + end + if clear then + end + end + end + else + local prevseason = get_season(turn-1) + if prevseason == "calendar::winter" then + -- we celebrate knut and kick out the trees. + for r in regions() do + if r:get_key("xm06") then + r:set_key("xm06", false) + end + end + end + end +end + +return self