-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweapons.py
59 lines (49 loc) · 2.15 KB
/
weapons.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
import dice
import messages
from mechanics import DnDRuleset as R
class Weapon(object):
def __init__(self, name, damage, damage_type,
reach, to_hit, uses_per_turn=-1,
min_distance=0, ammo=0, ranged=False,
number_of_targets=1,
special=[], **kwargs):
self.type = 'weapon'
self.multiattack = False
self.ammo = ammo
self.min_distance = min_distance
self.ranged = ranged
self.name = name
self.damage_print = damage
self.damage = dice.parse_damage(damage)
self.damage_type = damage_type
self.reach = reach
self.to_hit = to_hit
self.number_of_targets = number_of_targets
self.special = special
self.max_uses_per_turn = uses_per_turn
self.uses_per_turn = uses_per_turn
def __repr__(self):
dmg = []
for i in range(0, len(self.damage)):
dmg.append(self.damage_print[i] \
+ " | (%s)" % self.damage_type[i] \
+ " | %i ft. reach" % self.reach \
+ " | %i ammo" % max(self.ammo, 0))
return "{name}: {dmg}".format(name=self.name.capitalize(),
dmg=", ".join(dmg))
def use(self, source, target, always_hit=False):
""" Roll d20 to hit """
hit, crit_multiplier, hitroll = R.roll_hit(source, target, self, always_hit)
""" Iterate all different damage types in weapon if successful """
if hit:
#total_damage = R.iterate_damage(source, target, self, crit_multiplier)
total_damage = R.roll_damage(source, target, self, crit_multiplier)
""" Apply weapon's special abilities on target unless the target is
already dead """
if self.special and not target.is_dead:
for on_hit_effect in self.special:
on_hit_effect.use(source, target, total_damage, crit_multiplier)
class MultiWeapon(Weapon):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.multiattack = True