Add a "go to sleep" script based on time of day

git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@7928 282e977c-c81d-0410-88c4-b93c2d0d6712
master
tchize 2007-12-16 12:52:24 +00:00
parent b6a71597ae
commit 0e5dbc2d13
2 changed files with 244 additions and 75 deletions

View File

@ -0,0 +1,76 @@
# sleep.py
#
# Copyright 2007 by David Delbecq
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# Uses JSON notation for parameters
#
# This script makes the monster it is attached to (use EVENT_TIME to attach it)
# sleep at certain periods of the day/month/year. Note that it will
# triggers only once per period change. That mean a sleeping monster awaken
# by a PC will not all of sudden go to sleep. Also, remember that most moster
# awaken and attack when a player is nearby. So effects of this script might be
# limited.
#
# exemple
#
# arch event_time
# title Python
# slaying /python/tod/sleep.py
# msg
# {
# "when":["Dawn","Night"]
# "match":"one"
# }
# endmsg
# arch beholder
# end
# end
#
import Crossfire
import string
from CFTimeOfDay import TimeOfDay
import cjson
event = Crossfire.WhatIsEvent()
parameters = cjson.decode(event.Message)
alreadymatched = (event.Value!=0)
inverse = parameters.has_key("inverse") and parameters["inverse"] == True
match = False
if not parameters.has_key("match"):
Crossfire.Log(Crossfire.LogError,"Script sleep.py didn't get a 'match' parameter. Only got %s" %parameters)
elif string.lower(parameters["match"]) == "one":
match=TimeOfDay().matchAny(parameters["when"]) != inverse
elif string.lower(parameters["match"]) == "all":
match=TimeOfDay().matchAll(parameters["when"]) != inverse
else:
Crossfire.Log(Crossfire.LogError,"Script sleep.py didn't get a 'match' parameter. Only got %s" %parameters)
if ( match != alreadymatched ):
Crossfire.Log(Crossfire.LogDebug, "sleep")
event = Crossfire.WhatIsEvent()
current = Crossfire.WhoAmI()
if (current):
if (alreadymatched):
event.Value=0
current.Sleeping=0
Crossfire.Log(Crossfire.LogDebug, "Awaken %s" %current.Name)
else:
event.Value=1
current.Sleeping=1
Crossfire.Log(Crossfire.LogDebug, "Put %s to sleep" %current.Name)

243
test/tod
View File

@ -5,7 +5,7 @@ width 20
height 20
msg
Created: 2007-11-11 tchize
Modified: 2007-11-19 tchize
Modified: 2007-12-16 tchize
endmsg
end
arch brush
@ -196,14 +196,14 @@ x 2
y 3
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"The Season of New Year",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -218,14 +218,14 @@ x 2
y 4
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"The Season of Growth",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -240,14 +240,14 @@ x 2
y 5
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"The Season of Harvest",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -262,14 +262,14 @@ x 2
y 6
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"The Season of Decay",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -284,14 +284,14 @@ x 2
y 7
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"The Season of the Blizzard",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch marble
@ -467,14 +467,14 @@ x 4
y 3
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of Winter",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -489,14 +489,14 @@ x 4
y 4
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of the Ice Dragon",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -511,14 +511,14 @@ x 4
y 5
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of the Frost Giant",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -533,14 +533,14 @@ x 4
y 6
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of Valriel",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -555,14 +555,14 @@ x 4
y 7
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of Lythander",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -577,14 +577,14 @@ x 4
y 8
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of the Harvest",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -599,14 +599,14 @@ x 4
y 9
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of Gaea",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -621,14 +621,14 @@ x 4
y 10
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of Futility",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -643,14 +643,14 @@ x 4
y 11
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of the Dragon",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -665,14 +665,14 @@ x 4
y 12
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of the Sun",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -687,14 +687,14 @@ x 4
y 13
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of the Great Infernus",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -709,14 +709,14 @@ x 4
y 14
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of Ruggilli",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -731,14 +731,14 @@ x 4
y 15
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of the Dark Shades",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -753,14 +753,14 @@ x 4
y 16
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of the Devourers",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -775,14 +775,14 @@ x 4
y 17
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of Sorig",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -797,14 +797,14 @@ x 4
y 18
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of the Ancient Darkness",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -819,14 +819,14 @@ x 4
y 19
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Month of Gorokh",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -954,14 +954,14 @@ x 6
y 3
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"the Day of the Moon",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -976,14 +976,14 @@ x 6
y 4
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"the Day of the Bull",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -998,14 +998,14 @@ x 6
y 5
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"the Day of the Deception",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -1020,14 +1020,14 @@ x 6
y 6
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"the Day of Thunder",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -1042,14 +1042,14 @@ x 6
y 7
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"the Day of Freedom",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -1064,14 +1064,14 @@ x 6
y 8
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"the Day of the Great Gods",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -1086,14 +1086,14 @@ x 6
y 9
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"the Day of the Sun",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch marble
@ -1203,26 +1203,50 @@ arch brush
x 7
y 14
end
arch swall_2_2_2
x 7
y 14
end
arch brush
x 7
y 15
end
arch swall_2_1_1
x 7
y 15
end
arch brush
x 7
y 16
end
arch swall_2_1_1
x 7
y 16
end
arch brush
x 7
y 17
end
arch swall_2_1_1
x 7
y 17
end
arch brush
x 7
y 18
end
arch swall_2_1_1
x 7
y 18
end
arch brush
x 7
y 19
end
arch swall_2_2_1
x 7
y 19
end
arch brush
x 8
end
@ -1255,14 +1279,14 @@ x 8
y 3
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Night",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -1277,14 +1301,14 @@ x 8
y 4
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Dawn",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -1299,14 +1323,14 @@ x 8
y 5
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Morning",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -1321,14 +1345,14 @@ x 8
y 6
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Noon",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -1343,14 +1367,14 @@ x 8
y 7
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Evening",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -1365,14 +1389,14 @@ x 8
y 8
move_on walk fly_low fly_high
arch event_trigger
title Python
slaying /python/tod/filter.py
msg
{
"when":"Dusk",
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch marble
@ -1399,6 +1423,10 @@ arch brush
x 8
y 14
end
arch swall_2_1_2
x 8
y 14
end
arch brush
x 8
y 15
@ -1419,6 +1447,10 @@ arch brush
x 8
y 19
end
arch swall_2_1_2
x 8
y 19
end
arch brush
x 9
end
@ -1482,10 +1514,21 @@ arch brush
x 9
y 13
end
arch sign
msg
This monster sleeps during Night and Dawn.
endmsg
x 9
y 13
end
arch brush
x 9
y 14
end
arch swall_2_1_2
x 9
y 14
end
arch brush
x 9
y 15
@ -1494,6 +1537,20 @@ arch brush
x 9
y 16
end
arch kobold
x 9
y 16
arch event_time
title Python
slaying /python/tod/sleep.py
msg
{
"when" : ["Night","Dawn"],
"match" : "all"
}
endmsg
end
end
arch brush
x 9
y 17
@ -1506,6 +1563,10 @@ arch brush
x 9
y 19
end
arch swall_2_1_2
x 9
y 19
end
arch brush
x 10
end
@ -1565,6 +1626,10 @@ arch brush
x 10
y 14
end
arch swall_2_1_2
x 10
y 14
end
arch brush
x 10
y 15
@ -1585,6 +1650,10 @@ arch brush
x 10
y 19
end
arch swall_2_1_2
x 10
y 19
end
arch brush
x 11
end
@ -1648,26 +1717,50 @@ arch brush
x 11
y 14
end
arch swall_2_2_3
x 11
y 14
end
arch brush
x 11
y 15
end
arch swall_2_1_1
x 11
y 15
end
arch brush
x 11
y 16
end
arch swall_2_1_1
x 11
y 16
end
arch brush
x 11
y 17
end
arch swall_2_1_1
x 11
y 17
end
arch brush
x 11
y 18
end
arch swall_2_1_1
x 11
y 18
end
arch brush
x 11
y 19
end
arch swall_2_2_4
x 11
y 19
end
arch brush
x 12
end
@ -2450,14 +2543,14 @@ arch light_sword
name Day sword
x 19
arch event_attack
title Python
slaying /python/tod/filter.py
msg
{
"when":["Morning","Noon","Evening"],
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush
@ -2482,14 +2575,14 @@ name Night sword
x 19
y 2
arch event_attack
title Python
slaying /python/tod/filter.py
msg
{
"when":["Night","Dawn","Dusk"],
"match":"one"
}
endmsg
title Python
slaying /python/tod/filter.py
end
end
arch brush