battleman.py: Implemented healing surges, and refactored the combatant selection code in Battle
This commit is contained in:
parent
423d6975b4
commit
617c635206
65
battleman.py
65
battleman.py
|
@ -11,7 +11,11 @@
|
||||||
# for resuming a battle later
|
# for resuming a battle later
|
||||||
# * an option for passing in multiple files that contain combatant definitions
|
# * an option for passing in multiple files that contain combatant definitions
|
||||||
# * down combatants go into a separate list
|
# * down combatants go into a separate list
|
||||||
# * implement temporary hit points!
|
|
||||||
|
# dependencies:
|
||||||
|
# * second wind
|
||||||
|
# ** conditions
|
||||||
|
|
||||||
|
|
||||||
from dice import Dice
|
from dice import Dice
|
||||||
import sys
|
import sys
|
||||||
|
@ -156,6 +160,17 @@ class Combatant():
|
||||||
print('{} ({}) is still bloodied.'.format(self.name, self.index))
|
print('{} ({}) is still bloodied.'.format(self.name, self.index))
|
||||||
|
|
||||||
|
|
||||||
|
def use_surge(self, heal=True):
|
||||||
|
if self.surges <= 0:
|
||||||
|
print 'Error: {} has no healing surges'.format(self.name)
|
||||||
|
return
|
||||||
|
|
||||||
|
self.surges -= 1
|
||||||
|
print '{} spent a healing surge'.format(self)
|
||||||
|
if (heal):
|
||||||
|
self.heal(self.max_hp / 4)
|
||||||
|
|
||||||
|
|
||||||
def is_bloodied(self):
|
def is_bloodied(self):
|
||||||
return self.hp <= self.max_hp / 2
|
return self.hp <= self.max_hp / 2
|
||||||
|
|
||||||
|
@ -242,6 +257,15 @@ class Battle():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def choose_combatant(self):
|
||||||
|
print self.format_combatants()
|
||||||
|
index = input_int('choose combatant')
|
||||||
|
if index not in self.combatant_hash.keys():
|
||||||
|
print 'Error: {} is not a valid index'.format(index)
|
||||||
|
return self.choose_combatant()
|
||||||
|
return self.combatant_hash[index]
|
||||||
|
|
||||||
|
|
||||||
def begin(self):
|
def begin(self):
|
||||||
if self.is_started():
|
if self.is_started():
|
||||||
print("Error: battle is already running")
|
print("Error: battle is already running")
|
||||||
|
@ -319,16 +343,6 @@ class Battle():
|
||||||
print('Beginning round {}'.format(self.round))
|
print('Beginning round {}'.format(self.round))
|
||||||
|
|
||||||
|
|
||||||
def deal_damage(self, index, amount):
|
|
||||||
c = self.combatant_hash[index]
|
|
||||||
c.damage(amount)
|
|
||||||
|
|
||||||
|
|
||||||
def heal_damage(self, index, amount):
|
|
||||||
c = self.combatant_hash[index]
|
|
||||||
c.heal(amount)
|
|
||||||
|
|
||||||
|
|
||||||
def validate_started(self):
|
def validate_started(self):
|
||||||
if not self.is_started():
|
if not self.is_started():
|
||||||
print('Error: you can only run this command after starting the battle')
|
print('Error: you can only run this command after starting the battle')
|
||||||
|
@ -380,6 +394,10 @@ def do_prompt():
|
||||||
elif comm == 'h':
|
elif comm == 'h':
|
||||||
do_heal()
|
do_heal()
|
||||||
elif comm == 's':
|
elif comm == 's':
|
||||||
|
do_surge()
|
||||||
|
elif comm == 'so':
|
||||||
|
do_surge(heal=False)
|
||||||
|
elif comm == 'sw':
|
||||||
print('Sorry, this is still a stub function.')
|
print('Sorry, this is still a stub function.')
|
||||||
elif comm == 'c':
|
elif comm == 'c':
|
||||||
print('Sorry, this is still a stub function.')
|
print('Sorry, this is still a stub function.')
|
||||||
|
@ -394,17 +412,20 @@ def do_prompt():
|
||||||
|
|
||||||
|
|
||||||
def do_damage():
|
def do_damage():
|
||||||
print battle.format_combatants()
|
c = battle.choose_combatant()
|
||||||
index = input_int('choose combatant')
|
|
||||||
amount = input_int('damage')
|
amount = input_int('damage')
|
||||||
battle.deal_damage(index, amount)
|
c.damage(amount)
|
||||||
|
|
||||||
|
|
||||||
def do_heal():
|
def do_heal():
|
||||||
print battle.format_combatants()
|
c = battle.choose_combatant()
|
||||||
index = input_int('choose combatant')
|
|
||||||
amount = input_int('amount')
|
amount = input_int('amount')
|
||||||
battle.heal_damage(index, amount)
|
c.heal(amount)
|
||||||
|
|
||||||
|
|
||||||
|
def do_surge(heal=True):
|
||||||
|
c = battle.choose_combatant()
|
||||||
|
c.use_surge(heal)
|
||||||
|
|
||||||
|
|
||||||
def do_help():
|
def do_help():
|
||||||
|
@ -415,12 +436,14 @@ b - begin the battle
|
||||||
l - list combatants
|
l - list combatants
|
||||||
p - print info for combatant/group with initiative
|
p - print info for combatant/group with initiative
|
||||||
d - deal damage to someone
|
d - deal damage to someone
|
||||||
h - heal someone [stub]
|
h - heal someone
|
||||||
s - let someone use a healing surge [stub]
|
t - add temporary hit points to someone [stub]
|
||||||
sw -
|
s - use a healing surge
|
||||||
|
so - use a healing surge, but don't regain hit points
|
||||||
|
sw - use your second wind (current combat group only) [stub]
|
||||||
c - apply a condition [stub]
|
c - apply a condition [stub]
|
||||||
r - remove a condition (this can also happen automatically) [stub]
|
r - remove a condition (this can also happen automatically) [stub]
|
||||||
n - next (end the current combat group's turn) [stub]
|
n - next (end the current combat group's turn)
|
||||||
w - wait (remove a combatant from the initiative order and into a separate pool) [stub]
|
w - wait (remove a combatant from the initiative order and into a separate pool) [stub]
|
||||||
q - quit""")
|
q - quit""")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user