Contact me to be added to this repository. Push the creations you make for D&D, and they will be displayed in a nice website. See the website for how to contribute.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

61 lines
1.3 KiB

from random import randint
DFLT = 0
BLOODY = 1
DEAD = 2
class CombatEntity(object):
def __init__(self,name,hp,init):
self.name = name
self.hp = hp
self.hpmax = hp
self.status = []
self.init = init
def damage(self,amt):
self.hp -= amt
if self.hp < 0:
return DEAD
if self.hp < self.hpmax/2 and self.hp+amt >= self.hpmax/2:
return BLOODY
return DFLT
def heal(self,amt):
self.hp += amt
if self.hp > self.hpmax:
self.hp = self.hpmax
def apply_status(self,sts):
if sts in self.status:
return
self.status.append(sts)
def remove_status(self,sts):
self.status = [s for s in self.status if not s == sts]
def clear_status(self,sts):
self.status = []
def __repr__(self):
return self.name + " " + str(self.hp) + "/" + str(self.hpmax)
class Combat(object):
def __init__(self,entities):
self.entities = sorted(entities,key=lambda e: randint(1,20)+e.init,reverse=True)
self.turn = 0
self.log = []
def __repr__(self):
return str(self.entities)
if __name__ == "__main__":
a = CombatEntity("a",10,3)
b = CombatEntity("b",11,5)
c = CombatEntity("c",9,-4)
cmbt = Combat([a,b,c])
print("Combat:")
print(cmbt)