Crossfire Server, Trunk
age.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 #age.py
3 # This is one of the files that can be called by an npc_dialog,
4 # The following code runs when a dialog has a pre rule of 'age'
5 # The syntax is
6 # ["age", "agetoken", "years", "months", "days", "hours", "minutes"]
7 # To deliver a True verdict, the agetoken must correspond to a date
8 # that is was at least as long ago as the duration specified in the options.
9 
19 
20 import Crossfire
21 
22 class checkfailed(Exception):
23  pass
24 
25 # maximum months, days, hours, as defined by the server.
26 # minutes per hour is hardcoded to approximately 60
27 
28 try:
29  MAXTIMES = [Crossfire.Time.MONTHS_PER_YEAR, Crossfire.Time.WEEKS_PER_MONTH*Crossfire.Time.DAYS_PER_WEEK,
30  Crossfire.Time.HOURS_PER_DAY, 60]
31  # we have three times to consider, the old time, the current time, and the desired time difference.
32  if len(args) != 6:
33  raise checkfailed()
34  markername = args[0]
35  oldtime = self.getStatus(markername).split("-")
36  oldtime = list(map(int, oldtime))
37  if len(oldtime) !=5:
38  # The marker hasn't been set yet
39  raise checkfailed()
40 
41  desireddiff = list(map(int, args[1:]))
42  currenttime = (Crossfire.GetTime())[:5]
43  actualdiff = []
44 
45  for i in range(5):
46  actualdiff.append(currenttime[i]-oldtime[i])
47 
48  for i in range(4,0,-1):
49  # let's tidy up desireddiff first
50  if desireddiff[i] > MAXTIMES[i-1]:
51  desireddiff[i-1] += desireddiff[i] // MAXTIMES[i-1]
52  desireddiff[i] %= MAXTIMES[i-1]
53  # Then actualdiff
54  if actualdiff[i] < 0:
55  actualdiff[i] += MAXTIMES[i-1]
56  actualdiff[i-1] -=1
57  Crossfire.Log(Crossfire.LogDebug, "CFDialog: tidied up desired difference: %s actual difference %s" %(desireddiff, actualdiff))
58  for i in range(5):
59  if actualdiff[i] < desireddiff[i]:
60  raise checkfailed()
61 except checkfailed:
62  verdict = False
guildoracle.list
list
Definition: guildoracle.py:87
disinfect.map
map
Definition: disinfect.py:4
age.checkfailed
Definition: age.py:22
split
static std::vector< std::string > split(const std::string &field, const std::string &by)
Definition: mapper.cpp:2606