/
main.py
executable file
·150 lines (127 loc) · 5.39 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import arkham
import modules
class TUI (arkham.UI):
def setup_players (self, game):
for investigator in game.all_investigators ():
game.use_investigator (investigator)
break
def select_action (self, game, investigator, actions):
if len (actions) == 1:
action = actions[0]
print "(choosing the only available action, %s)" % action.name ()
return action
renames = {}
known_names = {}
renames = {}
known_names = {}
def dump_head (obj, level = 0):
prefix = " " * level
name = obj.name ()
first = True
if name in known_names:
if obj in renames:
name = renames[obj]
first = False
else:
known_names[name] += 1
nth = known_names[name]
def fmtnumber (n):
# hopefully we won't need more!
return {2:"II", 3:"III", 4:"IV",
5:"V", 6:"VI", 7:"VII",
8:"VIII",9:"IX", 10:"X"}[n]
name = "%s %s" % (name, fmtnumber (nth))
renames[obj] = name
else:
renames[obj] = name
known_names[name] = 1
print "%s+ %s%s" % (prefix, name,
((" (%s)" % obj.attributes ().fmt_flags ())
if first else ""))
return first
def dump_monster_info (monster, level):
if dump_head (monster, level):
prefix = " " * level
print "%s evade: %s" \
% (prefix,
monster.proto ().evade_check () \
.description (game, investigator))
print "%s horror: %s/%s" \
% (prefix,
monster.proto ().horror_check () \
.description (game, investigator),
monster.proto ().horror_harm () \
.description (game, investigator, monster))
print "%s combat: %s/%s" \
% (prefix,
monster.proto ().combat_check () \
.description (game, investigator),
monster.proto ().combat_harm () \
.description (game, investigator, monster))
print "%s location: %s" \
% (prefix, monster.location ().name ())
def dump_location_info (location, level):
if dump_head (location, level):
prefix = " " * level
for monster in game.monsters_at (location):
dump_monster_info (monster, level + 1)
def dump_item_info (item, level):
dump_head (item, level)
actions = actions + [arkham.GameplayAction_Quit ()]
print "======================================================="
print "%s: movement=%s, clues=%s, %s"\
% (investigator.name (),
investigator.movement_points (),
investigator.clues (),
", ".join ("%s=%s" % (aspect.name (),
investigator.health (aspect).cur ())
for aspect in investigator.health_aspects ()))
dump_location_info (investigator.location (), 1)
print "trophies:", ", ".join (trophy.name ()
for trophy in investigator.trophies ())
if investigator.wields_items ():
print "wields items:"
for item in investigator.wields_items ():
dump_item_info (item, 1)
while True:
print "-------------------------------------------------------"
id_act = list (enumerate (actions))
already_shown = set ()
for i, action in id_act:
print "%2s: %s" % (i, action.name ())
location = action.bound_location ()
if location:
if location not in already_shown:
dump_location_info (location, 3)
else:
dump_head (location, 3)
monster = action.bound_monster ()
if monster:
if monster not in already_shown:
dump_monster_info (monster, 3)
else:
dump_head (monster, 3)
already_shown.add (monster)
item = action.bound_item ()
if item:
if item not in already_shown:
dump_item_info (item, 3)
else:
dump_head (item, 3)
already_shown.add (item)
id_act = dict (id_act)
try:
sel = int (raw_input ())
except ValueError:
continue
if sel in id_act:
print "=>", id_act[sel].name ()
print "-------------------------------------------------------"
return id_act[sel]
idx = arkham.ModuleIndex ()
modules.discover_modules (idx)
idx.request ("ah")
game = arkham.Game (idx.requested_modules (), TUI ())
game.run ()