1
0

basic player entity and debug module to quickly test player attack

This commit is contained in:
Crystal
2025-07-24 22:36:36 +02:00
parent 761cf794b4
commit 1c284bad97
3 changed files with 122 additions and 44 deletions

38
debug.py Normal file
View File

@@ -0,0 +1,38 @@
import time as _time
import random as _rand
import main as _main
from entities import weapon_syms as _wsyms
def init_debug():
players= [
{
'name': 'Elara',
},
{
'name': 'Kaelen',
},
{
'name': 'Zephyr',
}
]
w= _wsyms.KNIFE
#weapons= [{_wsyms.WEAPONS[w]['name' ]: 1}]
weapons= [{w: 1}]
Arena= _main.init_arena(players, weapons)
print(f'Players: {Arena.get_players()}')
print(f'Weapons: {Arena.get_weapons()}')
while (len(Arena.get_alive_players()) > 1):
alive_players= Arena.get_alive_players()
p_one, p_two= _rand.sample(alive_players, 2)
p_one.attack(p_two)
#Start a day
#At 23:59:
Arena.next_day()
_time.sleep(0.3)
#End of day
if __name__ == '__main__':
init_debug()

View File

@@ -1,72 +1,112 @@
import random as _random import random as _random
import uuid as _uuid
class BrSimPlayer(): class BrSimPlayer():
def __init__(self, name, inventory= None): def __init__(self, name, inventory= None):
self.id= str(_uuid.uuid4)
self.name= name self.name= name
self.health= 1 self.health= 1
self.inventory= inventory or [] self.inventory= inventory or []
self.damage= 1 # this is the punch damage amount self.damage= 1 # this is the punch damage amount
self.max_weight= 5 # this is the max inventory weight self.max_weight= 5 # this is the max inventory weight
self.agility= 10 # chance to avoid an hit 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
def is_alive(self): ### control methods
return self.health > 0
def attack(self, target): def get_id(self):
if not self.is_alive(): return return self.id
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): def get_name(self):
self.health -= damage return self.name
if self.health <= 0:
self.health = 0
# 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
return False
def steal(self):
#XXX can steal from death players or from sleeping players
pass
def escape(self):
#XXX It can run away from the fighting
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): def get_inventory(self):
return self.inventory return self.inventory
def get_name(self): def get_inventory_weight(self):
return self.name 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): def get_health(self):
return self.health return self.health
def get_damage(self): def get_damage(self):
return self.damage if not self.equipped_weapon: return self.damage
return self.equipped_weapon.damage
def get_agility(self): def get_agility(self):
return self.agility return self.agility
def get_data(self): def get_data(self):
return { return {
'id': self.get_id(),
'name': self.get_name(), 'name': self.get_name(),
'inventory': self.get_inventory(), 'inventory': self.get_inventory(),
'inventory_weight': self.get_inventory_weight(),
'health': self.get_health(), 'health': self.get_health(),
'damage': self.get_damage(), 'damage': self.get_damage(),
'agility': self.get_agility(), '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

14
main.py
View File

@@ -2,20 +2,20 @@ import random as _random
from entities import weapon_syms as _wsyms from entities import weapon_syms as _wsyms
from entities import arena as _arena from entities import arena as _arena
def init_arena(): def init_arena(players, weapons):
players= [{'name': 'Crystal'}, {'name': 'Andrea'}]
w= _wsyms.KNIFE
#weapons= [{_wsyms.WEAPONS[w]['name' ]: 1}]
weapons= [{w: 1}]
return _arena.BrSimArena(players, weapons) return _arena.BrSimArena(players, weapons)
def run_events(Arena): def run_events(Arena):
#A event for each player: #A event for each player:
pass pass
def local_debug(): def local_debug():
Arena= init_arena() players= [{'name': 'Crystal'}, {'name': 'Andrea'}]
w= _wsyms.KNIFE
#weapons= [{_wsyms.WEAPONS[w]['name' ]: 1}]
weapons= [{w: 1}]
Arena= init_arena(players, weapons)
print(f'Players: {Arena.get_players()}') print(f'Players: {Arena.get_players()}')
print(f'Weapons: {Arena.get_weapons()}') print(f'Weapons: {Arena.get_weapons()}')
while (len(Arena.get_alive_players()) > 1): while (len(Arena.get_alive_players()) > 1):