2 dragon.py -- talking dragon that flies you places
5 This replaces the old dragon hangers, where every location that wanted a dragon
6 hanger needed to copy/paste a template map.
8 Usage: Put an event_say and event_apply handler that calls this script on a
17 world_map_path_matcher =
r"/world/world_(\d\d\d)_(\d\d\d)";
19 activator = Crossfire.WhoIsActivator()
20 event = Crossfire.WhatIsEvent()
21 whoami = Crossfire.WhoAmI()
23 price_per_worldmap_tile = 5*50
28 'Port Joseph': (
'/world/world_101_114', 16, 39),
29 'Red Town': (
'/pup_land/terminal', 10, 12),
30 'Wolfsburg': (
'/world/world_128_109', 35, 13),
31 'Brest': (
'/world/world_107_123', 32, 30),
32 'Navar': (
'/world/world_121_116', 37, 46),
33 'Darcap': (
'/world/world_116_102', 29, 37),
34 'Stoneville': (
'/world/world_103_127', 5, 15),
35 'Scorn': (
'/world/world_105_115', 5, 37),
36 'Lake Country': (
'/world/world_109_126', 16, 20),
37 'Santo Dominion': (
'/world/world_102_108', 17, 12),
43 for key, val
in destinations.items():
44 dest_searchable[key.upper()] = (key, val)
49 '/pup_land/terminal': (94, 115),
54 if name
in dest_searchable:
55 return dest_searchable[name]
60 """Try to extract the coordinates from a world map path."""
61 if path
in coord_override:
62 return coord_override[path]
63 groups = re.match(world_map_path_matcher, path)
64 if groups
is not None:
65 coords = groups.group(1, 2)
66 cx, cy =
int(coords[0]),
int(coords[1])
73 if curr_coord
is None or dest_coord
is None:
76 return min(max_fare,
dist_fare(curr_coord, dest_coord))
79 dist = math.hypot(end[0] - start[0], end[1] - start[1])
80 return math.ceil(dist * price_per_worldmap_tile)
84 state = Crossfire.GetPrivateDictionary()
87 msg = Crossfire.WhatIsMessage()
90 whoami.Say(
"Dragon Express can whisk you to one of %d locations for a small fee. Travel faster today!" % len(destinations))
92 elif text[0] ==
"where":
93 whoami.Say(
"We have %d exciting destinations: %s. Where would you like to go?" % (len(destinations),
", ".join(destinations.keys())))
95 elif text[0] ==
"yes" and activator.Name
in state:
96 dest_name = state[activator.Name][0]
97 price = state[activator.Name][1]
98 dest = destinations[dest_name]
99 m = Crossfire.ReadyMap(dest[0])
101 whoami.Say(
"Oops, it looks like the landing site there is not clear. Let's try to go somewhere else.")
102 elif activator.PayAmount(price):
103 activator.Message(
"You pay the %s %s" % (whoami.Name, Crossfire.CostStringFromValue(price)))
104 activator.Message(
"You hop on the %s and it takes off. You enjoy a pleasant ride above the clouds before arriving at %s." % (whoami.Name, dest_name))
105 activator.Teleport(m, dest[1], dest[2])
107 whoami.Say(
"It doesn't look like you can afford this trip. Please come back when you can.")
108 del(state[activator.Name])
116 whoami.Say(
"Alright, let's go to %s. That will cost %s. Is that okay?" % (dest_name, Crossfire.CostStringFromValue(price)))
117 Crossfire.AddReply(
"yes",
"Okay, let's go.")
118 Crossfire.AddReply(
"no",
"No thanks.")
119 state[activator.Name] = (dest_name, price)
121 whoami.Say(
"Welcome to Dragon Express. Where can I take you today?")
122 Crossfire.AddReply(
"what",
"What is Dragon Express?")
123 Crossfire.AddReply(
"where",
"Where can you take me?")
125 Crossfire.SetReturnValue(1)
126 if event.Subtype == Crossfire.EventType.SAY:
129 whoami.Say(
"Hey, you can't get on without paying!")