1
0
Files
battle_royale_sim/entities/player.py

113 lines
2.8 KiB
Python

import random as _random
import uuid as _uuid
class BrSimPlayer():
def __init__(self, name, inventory= None):
self.id= str(_uuid.uuid4)
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.agility= 10 # chance to avoid an hit
self.kills= 0 # track the number of kills
self.survived_days= 0 # track the number of the survived days
self.equipped_weapon= None
### control methods
def get_id(self):
return self.id
def get_name(self):
return self.name
def get_inventory(self):
return self.inventory
def get_inventory_weight(self):
weight= 0
for inv in self.get_inventory():
weight+= inv.get_weight()
return weight
def get_max_weight(self):
return self.max_weight
def get_health(self):
return self.health
def get_damage(self):
if not self.equipped_weapon: return self.damage
return self.equipped_weapon.damage
def get_agility(self):
return self.agility
def get_data(self):
return {
'id': self.get_id(),
'name': self.get_name(),
'inventory': self.get_inventory(),
'inventory_weight': self.get_inventory_weight(),
'health': self.get_health(),
'damage': self.get_damage(),
'agility': self.get_agility(),
}
def is_alive(self):
return self.health > 0
### player actions
def _equip_weapon(self):
if not self.inventory: return
available_weapons= []
for inv in self.get_inventory():
# XXX
# i don't know yet if this is ok,
# we'll see it when weapon and items are defined
if not inv.damage: continue
available_weapons.append(inv)
self.equipped_weapon= random.sample(available_weapons, 1)[0]
def dodge(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
return False
def accuses_damage(self, damage):
self.health -= damage
if self.health > 0: return self.get_health()
self.health = 0
print('Guarino, perdonami se sono morto x.x')
return damage
def attack(self, target):
self._equip_weapon()
if target.dodge():
print('Ehhhh voleviiii!!! sei lentoo!')
return 0
target.accuses_damage(self.damage)
return self.damage
def get_item(self, item):
if self.get_inventory_weight() + item.get_weight() >= self.get_max_weight():
print('Sono sovraccarico, non posso prendere questo oggetto')
return False
self.inventory.append(item)
def escape(self):
# TODO It can run away from the fighting
return
def heal(self):
# TODO heal system
# if you have a wound and you have a medikit item,
# you can heal your wound or sickness
return