merge the various Christmas modules into one file, make them trigger on a turn, reduce spam

This commit is contained in:
Enno Rehling 2015-11-26 21:13:01 +01:00
parent 6c2f4be4af
commit 8cf62ee236
9 changed files with 105 additions and 142 deletions

View file

@ -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'),

View file

@ -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')

View file

@ -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'),

42
scripts/eressea/xmas.lua Normal file
View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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