72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
import random as _random
|
|
|
|
class BrSimPlayer():
|
|
|
|
def __init__(self, name, inventory= None):
|
|
self.name= name
|
|
self.health= 1
|
|
self.inventory= inventory or []
|
|
self.damage= 1 # this is the punch damage amount
|
|
self.max_weight= 5 # this is the max inventory weight
|
|
self.is_alive= True
|
|
self.agility= 10 # chance to avoid an hit
|
|
|
|
def is_alive(self):
|
|
return self.is_alive
|
|
|
|
def attack(self, target):
|
|
if not self.is_alive(): return
|
|
if not target.is_alive(): return
|
|
if target.try_to_avoid_hit(): return # print something like 'enemy doges the attacl'
|
|
|
|
target.accuses_damage(self.damage)
|
|
|
|
def accuses_damage(self, damage):
|
|
self.health -= damage
|
|
if self.health <= 0:
|
|
self.health = 0
|
|
self.is_alive = False
|
|
# show something like 'player is dead'
|
|
else:
|
|
# show something like 'get hit'
|
|
pass
|
|
|
|
def try_to_avoid_hit(self):
|
|
# maybe depend on the attack, if it is a gun shot it's quite impossible to dodge
|
|
rnd= _random.randint(0, 100)
|
|
# if rnd > self.agility: return True ## XXX this is strange, if the agility is high the chances to dodge are lower
|
|
if rnd < self.agility: return True
|
|
return False
|
|
|
|
def steal(self):
|
|
#XXX can steal from death players or from sleeping players
|
|
pass
|
|
|
|
def heal(self):
|
|
#XXX if you have a wound and you have a medikit item, you can heal your wound or sickness
|
|
pass
|
|
|
|
def get_inventory(self):
|
|
return self.inventory
|
|
|
|
def get_name(self):
|
|
return self.name
|
|
|
|
def get_health(self):
|
|
return self.health
|
|
|
|
def get_damage(self):
|
|
return self.damage
|
|
|
|
def get_agility(self):
|
|
return self.agility
|
|
|
|
def get_data(self):
|
|
return {
|
|
'name': self.get_name(),
|
|
'inventory': self.get_inventory(),
|
|
'health': self.get_health(),
|
|
'damage': self.get_damage(),
|
|
'agility': self.get_agility(),
|
|
}
|