Crossfire Server, Trunk
banquet.py
Go to the documentation of this file.
1 # Script for the Unforgettable Banquet of Lursendis item.
2 # Idea courtesy Yann Chachkoff.
3 #
4 # Copyright 2007 Nicolas Weeger
5 # Released as GPL
6 #
7 # This script will teleport the player to a food-filled map. It only works
8 # once a (ingame) day.
9 # Applying the tome while in the map will teleport the player back to his starting place.
10 # Book can only be applied when in player's inventory, so player can get back to the world.
11 #
12 # Map is generated by the script itself, and given a unique name to avoid collision.
13 #
14 # Player is replaced with a statue so the spot stays free during his trip.
15 # To avoid colliding with an existing map, created map will have a unique map.
16 # Everything in the map is randomly chosen.
17 
18 import Crossfire
19 import random
20 import os.path
21 
22 # map sizes
23 size_x = 15
24 size_y = 15
25 
26 # what foods to put in the map
27 foods = [ 'fishfood', 'food', 'bag_popcorn', 'apple', 'cheeseburger', 'loaf', 'tomato', 'waybread', 'roast_bird', 'orange', 'leg_mutton' ]
28 # what floors can be used
29 floors = [ 'woodfloor', 'flagstone', 'dirtfloor' ]
30 # what walls can be used - only put the base name
31 walls = [ 'flagstone', 'dwall', 'timberwall', 'stwall' ]
32 
33 # what to replace the player with. Should block all movement
34 replace_with = [ 'd_statue', 'statue', 'statue2' ]
35 
36 def get_one(what):
37  '''Return a random choice in what, which should be an array.'''
38  return what[ random.randint( 1, len(what) ) - 1 ]
39 
41  '''Teleport player back to bed of reality. Only in emergency.'''
42  flags = 0
43  if (act.BedMap.find(Crossfire.PlayerDirectory()) != -1):
44  # Unique map
45  flags = 2
46  dest = Crossfire.ReadyMap(act.BedMap, flags)
47  if (dest == None):
48  # Ok, this is real bad. Let player handle the situation - worse case, call to DMs or WoR manually.
49  act.Message('The %s whines really loudly.'%l.Name)
50  return
51 
52  act.Teleport(dest, act.BedX, act.BedY)
53 
54 def do_back():
55  '''Teleport the player back to his starting point.'''
56  x = l.ReadKey('banquet_x')
57  y = l.ReadKey('banquet_y')
58  mn = l.ReadKey('banquet_map')
59  rw = l.ReadKey('banquet_rw')
60 
61  l.WriteKey('banquet_x', '', 0)
62  l.WriteKey('banquet_y', '', 0)
63  l.WriteKey('banquet_map', '', 0)
64  l.WriteKey('banquet_rw', '', 0)
65 
66  if x == '' or y == '' or mn == '':
67  # Logic error, but can't be helped - teleport player back to his bed of reality
68  act.Message('You feel a distorsion of reality!')
70  return
71 
72  # find and remove statue in the map
73  dest = Crossfire.ReadyMap(mn)
74  if (dest == None):
75  # Random map, probably? Let the player teleport back him/herself.
76  act.Message('The %s whines something. You barely understand it can\'t take you back to your starting point.'%l.Name)
78  return
79 
80  # Remove statue - let's assume it's found, or was removed due to map reset.
81  st = dest.ObjectAt(int(x), int(y))
82  while st != None:
83  if (st.ArchName != rw):
84  st = st.Above
85  continue
86  st.Remove()
87  break
88 
89  act.Message('You feel a powerful force engulf you.')
90  act.Teleport(dest, int(x), int(y))
91 
92 def do_banquet():
93  '''Teleports the player to the banquet map, if not used since one day. '''
94 
95  now = str(Crossfire.GetTime()[0]) + '-' + str(Crossfire.GetTime()[1]) + '-' + str(Crossfire.GetTime()[2])
96 
97  l = Crossfire.WhoAmI()
98  act = Crossfire.WhoIsActivator()
99 
100  last = l.ReadKey('banquet_last')
101 
102 
103  if (last == now):
104  act.Message('You read the %s but nothing happens.'%l.Name)
105  return
106 
107  l.WriteKey('banquet_last', now, 1)
108 
109  # map generation
110  m = Crossfire.CreateMap(size_x, size_y)
111  m.Path = os.path.join(Crossfire.ScriptName(), Crossfire.WhoIsActivator().Name)
112  floor = get_one(floors)
113 
114  # First, let's put the floors
115  for x in range(size_x):
116  for y in range(size_y):
117  fl = Crossfire.CreateObjectByName(floor)
118  fl.Teleport(m, x, y)
119 
120  # Put walls.
121  wall = get_one(walls)
122  # top left
123  m.CreateObject(wall + '_2_2_2', 0, 0)
124  # top right
125  m.CreateObject(wall + '_2_2_3', size_x - 1, 0)
126  # bottom left
127  m.CreateObject(wall + '_2_2_1', 0, size_y - 1)
128  # bottom right
129  m.CreateObject(wall + '_2_2_4', size_x - 1, size_y - 1)
130  # top and bottom parts
131  for x in range(size_x - 2):
132  m.CreateObject(wall + '_2_1_2', x + 1, 0)
133  m.CreateObject(wall + '_2_1_2', x + 1, size_y - 1)
134  # left and right parts
135  for y in range(size_y - 2):
136  m.CreateObject(wall + '_2_1_1', 0, y + 1)
137  m.CreateObject(wall + '_2_1_1', size_x - 1, y + 1)
138 
139  # Food itself
140  for x in range(size_x-2):
141  for y in range(size_y-2):
142  m.CreateObject(get_one(foods), x + 1, y + 1).GodGiven = 1
143 
144  # Store player's current location
145  x = act.X
146  y = act.Y
147  im = act.Map
148  rw = get_one(replace_with)
149 
150  l.WriteKey('banquet_x', str(x), 1)
151  l.WriteKey('banquet_y', str(y), 1)
152  l.WriteKey('banquet_map', im.Path, 1)
153  l.WriteKey('banquet_rw', rw, 1)
154 
155  # Teleport
156  act.Message('You feel grabbed by some powerful force.')
157  act.Teleport(m, int(( size_x - 1 ) / 2), int((size_y - 1) / 2))
158 
159  # Keep free spot by putting a statue
160  statue = im.CreateObject(rw, x, y)
161  statue.Name = '%s\'s statue'%act.Name
162  statue.Message = 'Gone eating.'
163 
164 l = Crossfire.WhoAmI()
165 act = Crossfire.WhoIsActivator()
166 
167 if l.Env != act:
168  act.Message('You try to open the %s, but it seems to flee from you.'%l.Name)
169 elif (act.Map.Path.find(Crossfire.ScriptName()) != -1):
170  do_back()
171 else:
172  do_banquet()
173 
174 Crossfire.SetReturnValue(1)
banquet.do_back
def do_back()
Definition: banquet.py:54
make_face_from_files.str
str
Definition: make_face_from_files.py:30
banquet.do_banquet
def do_banquet()
Definition: banquet.py:92
make_face_from_files.int
int
Definition: make_face_from_files.py:32
banquet.return_to_bed
def return_to_bed()
Definition: banquet.py:40
banquet.get_one
def get_one(what)
Definition: banquet.py:36