-
Notifications
You must be signed in to change notification settings - Fork 1
/
encounter.py
153 lines (112 loc) · 4.2 KB
/
encounter.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
151
152
153
"""
This program aims to provide a simple and efficient way to run encounters in
the Edge of the Empire roleplaying game. Doing this from paper can be confusing
and even frustrating at times, because there is a lot to keep track of such as
distances, critical hits, temporary modifiers, initiative slots and more.
Star Wars: Edge of the Empire is a roleplaying game by Fantasy Flight Games.
Credits go to them for developing the dice system. Apart from that, I don't
know anything about copyrighting, so please FFG, don't sue me.
"""
__author__ = "Stephen Swatman"
__credits__ = ["Fantasy Flight Games"]
__license__ = "Unlicense"
__version__ = "0.0.1"
__email__ = "stephenswat@gmail.com"
import json
import dice
class Modifier(object):
pass
class Weapon(object):
pass
class Actor(object):
MINION = 0
RIVAL = 1
NEMESIS = 2
def __init__(self, data, player=False):
self.player = player
self.attributes = data['attributes']
self.type = Actor.type_from_string(data.get('type', 'minion'))
self.name = data.get('name', '[UNNAMED ACTOR]')
self.soak = data['soak']
self.skills = data.get('skills', {})
self.initiative = None
def take_damage(self, damage):
pass
def move(self, target, distance):
pass
def attack(self, target):
pass
def kill(self):
pass
def save(self, file_name):
pass
def add_modifier(self, modifier):
pass
def roll_initiative(self, init_type=0):
if init_type == Encounter.VIGILANCE:
values = [self.skills.get('vigilance', 0), self.attributes['willpower']]
elif init_type == Encounter.VIGILANCE:
values = [self.skills.get('cool', 0), self.attributes['presence']]
values.sort(reverse=True)
roll = dice.DicePool('%ia%ip' % (values[0] - values[1], values[1])).roll()
self.set_initiative(roll['success'], roll['advantage'])
def set_initiative(self, success, advantage):
self.initiative = (success, advantage)
@staticmethod
def type_from_string(string):
if string.lower() == 'minion':
return Actor.MINION
elif string.lower() == 'rival':
return Actor.RIVAL
elif string.lower() == 'nemesis':
return Actor.NEMESIS
else:
raise ValueError("invalid VillainType enum.")
class Vehicle(Actor):
pass
class Infantry(Actor):
pass
class Encounter(object):
VIGILANCE = 0
COOL = 1
def __init__(self):
self.actors = []
def add_actor(self, actor):
if isinstance(actor, Actor):
self.actors.append(actor)
elif isinstance(actor, list):
assert all(isinstance(x, Actor) for x in actor)
self.actors += actor
else:
raise ValueError("add_actor takes either an Actor or a list.")
class EncounterInterface(object):
def __init__(self, data, **kwargs):
self.encounter = kwargs.get('encounter', Encounter(**kwargs))
assert isinstance(data, dict), "type of encounter data must be a dict."
self.encounter.add_actor([Actor(x) for x in data['npcs']])
self.encounter.add_actor([Actor([], player=True) for _ in range(int(data['players']))])
self.determine_initiative()
self.sort_initiative()
def sort_initiative(self):
pass
def determine_initiative(self):
for actor in self.encounter.actors:
if actor.player:
actor.set_initiative(*self.query_initiative())
else:
actor.roll_initiative()
@staticmethod
def query_initiative():
return (int(x) for x in input("Enter initiative as <success>,<advantage>\n > ").split(','))
if __name__ == "__main__":
import argparse, sys
PARSER = argparse.ArgumentParser()
PARSER.add_argument('-p', help='number of player characters to enter',
metavar='players', default=0, type=int)
PARSER.add_argument('file', help='an encounter file to load')
ARGS = PARSER.parse_args(sys.argv[1:])
with open(ARGS.file) as f:
ENCOUNTER = EncounterInterface(json.load(f))
for x in ENCOUNTER.encounter.actors:
print(x)
print(x.initiative)