battleman.py: Implementing healing
This commit is contained in:
parent
84f66955a7
commit
fde1f34b30
41
battleman.py
41
battleman.py
|
@ -11,6 +11,7 @@
|
||||||
# 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!
|
||||||
|
|
||||||
from dice import Dice
|
from dice import Dice
|
||||||
import sys
|
import sys
|
||||||
|
@ -97,6 +98,7 @@ class Combatant():
|
||||||
self.name = name
|
self.name = name
|
||||||
self.max_hp = hp
|
self.max_hp = hp
|
||||||
self.hp = self.max_hp
|
self.hp = self.max_hp
|
||||||
|
self.temp_hp = 0
|
||||||
self.pc = pc
|
self.pc = pc
|
||||||
self.surges = surges
|
self.surges = surges
|
||||||
self.ap = ap
|
self.ap = ap
|
||||||
|
@ -121,6 +123,12 @@ class Combatant():
|
||||||
def damage(self, amount):
|
def damage(self, amount):
|
||||||
was_bloodied = self.is_bloodied()
|
was_bloodied = self.is_bloodied()
|
||||||
|
|
||||||
|
if self.temp_hp > 0:
|
||||||
|
self.temp_hp -= amount
|
||||||
|
if self.temp_hp < 0:
|
||||||
|
amount = abs(self.temp_hp)
|
||||||
|
self.temp_hp = 0
|
||||||
|
|
||||||
self.hp -= amount
|
self.hp -= amount
|
||||||
|
|
||||||
if self.is_down():
|
if self.is_down():
|
||||||
|
@ -129,6 +137,23 @@ class Combatant():
|
||||||
print('{} ({}) is bloodied! Remaining hp: {}'.format(self.name, self.index, self.hp))
|
print('{} ({}) is bloodied! Remaining hp: {}'.format(self.name, self.index, self.hp))
|
||||||
|
|
||||||
|
|
||||||
|
def heal(self, amount):
|
||||||
|
was_down = self.is_down()
|
||||||
|
was_bloodied = self.is_bloodied()
|
||||||
|
|
||||||
|
if self.hp < 0:
|
||||||
|
self.hp = 0
|
||||||
|
|
||||||
|
self.hp = min(self.hp + amount, self.max_hp + self.temp_hp)
|
||||||
|
|
||||||
|
if was_down:
|
||||||
|
print('{} ({}) is conscious.'.format(self.name, self.index))
|
||||||
|
if was_bloodied and not self.is_bloodied():
|
||||||
|
print('{} ({}) is no longer bloodied.'.format(self.name, self.index))
|
||||||
|
elif was_bloodied and self.is_bloodied():
|
||||||
|
print('{} ({}) is still bloodied.'.format(self.name, self.index))
|
||||||
|
|
||||||
|
|
||||||
def is_bloodied(self):
|
def is_bloodied(self):
|
||||||
return self.hp <= self.max_hp / 2
|
return self.hp <= self.max_hp / 2
|
||||||
|
|
||||||
|
@ -223,13 +248,13 @@ class Battle():
|
||||||
|
|
||||||
self.groups.sort(reverse=True, key=lambda group: group.init)
|
self.groups.sort(reverse=True, key=lambda group: group.init)
|
||||||
self.current = 0
|
self.current = 0
|
||||||
self.round = 1
|
|
||||||
|
|
||||||
print '\nInitiative Roster:\n'
|
print '\nInitiative Roster:\n'
|
||||||
for g in self.groups:
|
for g in self.groups:
|
||||||
print '{} ({})'.format(g.name, g.init)
|
print '{} ({})'.format(g.name, g.init)
|
||||||
print ''
|
print ''
|
||||||
|
|
||||||
|
self.next_round()
|
||||||
self.get_current_group().begin_turn()
|
self.get_current_group().begin_turn()
|
||||||
|
|
||||||
|
|
||||||
|
@ -293,6 +318,11 @@ class Battle():
|
||||||
c.damage(amount)
|
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')
|
||||||
|
@ -342,7 +372,7 @@ def do_prompt():
|
||||||
elif comm == 'd':
|
elif comm == 'd':
|
||||||
do_damage()
|
do_damage()
|
||||||
elif comm == 'h':
|
elif comm == 'h':
|
||||||
print('Sorry, this is still a stub function.')
|
do_heal()
|
||||||
elif comm == 's':
|
elif comm == 's':
|
||||||
print('Sorry, this is still a stub function.')
|
print('Sorry, this is still a stub function.')
|
||||||
elif comm == 'c':
|
elif comm == 'c':
|
||||||
|
@ -364,6 +394,13 @@ def do_damage():
|
||||||
battle.deal_damage(index, amount)
|
battle.deal_damage(index, amount)
|
||||||
|
|
||||||
|
|
||||||
|
def do_heal():
|
||||||
|
print battle.list_combatants()
|
||||||
|
index = input_int('choose combatant')
|
||||||
|
amount = input_int('amount')
|
||||||
|
battle.heal_damage(index, amount)
|
||||||
|
|
||||||
|
|
||||||
def do_help():
|
def do_help():
|
||||||
print("""Possible commands:
|
print("""Possible commands:
|
||||||
? - print this help menu (yay, you already figured that one out)
|
? - print this help menu (yay, you already figured that one out)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user