Compare commits
21 Commits
18bccfded8
...
master_ite
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
f80edfff83 | ||
|
|
4c2864634b | ||
|
|
b4c8d94c8c | ||
|
|
a56d931304 | ||
|
|
b001c9312a | ||
| 05e219ad18 | |||
| 0d36f1dd52 | |||
| 13bb11eb8c | |||
| af7f0019ec | |||
| 804a3961c9 | |||
|
|
cdb69699ab | ||
|
|
6c3fe6326f | ||
|
|
2550f0b262 | ||
|
|
3cc6966d86 | ||
| 62c7c7f2c2 | |||
|
|
aa245700c6 | ||
|
|
7f36158c40 | ||
|
|
171b9fe787 | ||
|
|
eb3b7da07a | ||
|
|
8ed1bd3c4f | ||
|
|
0379a3f935 |
13
README.md
13
README.md
@@ -7,7 +7,9 @@ You can find the Official Bot here:
|
|||||||
|
|
||||||
Feel free to fork the project and make your own Bot
|
Feel free to fork the project and make your own Bot
|
||||||
|
|
||||||
# Bot Instrictions
|
This game is inspired to this Hunger Games Simulator: https://brantsteele.net/hungergames/reaping.php
|
||||||
|
|
||||||
|
# Bot Instructions (Telegram)
|
||||||
|
|
||||||
1. start a chat with the bot: https://t.me/Brsimgen_Bot
|
1. start a chat with the bot: https://t.me/Brsimgen_Bot
|
||||||
2. open the bot keyboard
|
2. open the bot keyboard
|
||||||
@@ -24,6 +26,13 @@ Feel free to fork the project and make your own Bot
|
|||||||
- Get Alive Players: (list of alive players)
|
- Get Alive Players: (list of alive players)
|
||||||
- Get Death Players: (list of death players)
|
- Get Death Players: (list of death players)
|
||||||
- Get Ranking Players: (this is the leaderboard, based on number of kills)
|
- Get Ranking Players: (this is the leaderboard, based on number of kills)
|
||||||
|
- Show Map UTF8 or Show Map Image (show Players/Items position on the map)
|
||||||
|
|
||||||
|
# Bot Instructions (CLI)
|
||||||
|
|
||||||
|
1. open a python shell
|
||||||
|
2. `import debug`
|
||||||
|
3. `debug.init_debug_simulation()`
|
||||||
|
|
||||||
# Fork Instructions
|
# Fork Instructions
|
||||||
|
|
||||||
@@ -45,6 +54,8 @@ TOKEN = 'your-bot-token'
|
|||||||
|
|
||||||
BOT_PATH= '/the/path/of/the/project'
|
BOT_PATH= '/the/path/of/the/project'
|
||||||
|
|
||||||
|
LOG_PATH= '/the/path/where/you/want/put/game/daily/logs'
|
||||||
|
|
||||||
BOT_EXEC_CMD= 'python3 bot.py' # or any other way you start the bot
|
BOT_EXEC_CMD= 'python3 bot.py' # or any other way you start the bot
|
||||||
|
|
||||||
SUPER_USERS= [ your_chat_id ]
|
SUPER_USERS= [ your_chat_id ]
|
||||||
|
|||||||
@@ -7,8 +7,21 @@ EVENTS = [
|
|||||||
'success_percentage' : 80,
|
'success_percentage' : 80,
|
||||||
'fail_percentage' : 19,
|
'fail_percentage' : 19,
|
||||||
'extreme_fail_percentage' : 1,
|
'extreme_fail_percentage' : 1,
|
||||||
'required_items' : [],
|
'requirements' : {},
|
||||||
'weight' : 1,
|
'weight' : 1,
|
||||||
'number_of_players' : 2,
|
'affected_players' : 1, #NOTE, what is it? to why it could be integer or list?
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id' : 'BOMB_EXPLOSION',
|
||||||
|
'text' : '{Player1} ha attacato {player2}',
|
||||||
|
'resolve_text' : '{Player1} ha causato {effetto_collaterale}',
|
||||||
|
'fail_text' : '{Player1} ha fallito, {player2} è indenne',
|
||||||
|
'success_percentage' : 80,
|
||||||
|
'fail_percentage' : 19,
|
||||||
|
'extreme_fail_percentage' : 1,
|
||||||
|
'requirements' : {
|
||||||
|
'weapons' : ['BOMB']
|
||||||
|
},
|
||||||
|
'affected_players' : [2,3,4],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os as _os
|
import os as _os
|
||||||
|
from utils import logs as _logs
|
||||||
|
|
||||||
_MISSING_LOCAL_SETTINGS= """
|
_MISSING_LOCAL_SETTINGS= """
|
||||||
=============== ERROR ===============
|
=============== ERROR ===============
|
||||||
@@ -20,7 +21,7 @@ _MISSING_LOCAL_SETTINGS= """
|
|||||||
try:
|
try:
|
||||||
from local_settings import TOKEN as _token
|
from local_settings import TOKEN as _token
|
||||||
TOKEN= _token
|
TOKEN= _token
|
||||||
except: print(_MISSING_LOCAL_SETTINGS)
|
except: _logs.log_debug(_MISSING_LOCAL_SETTINGS)
|
||||||
try:
|
try:
|
||||||
from local_settings import BOT_PATH as _bot_path
|
from local_settings import BOT_PATH as _bot_path
|
||||||
BOT_PATH= _os.path.expanduser(_bot_path)
|
BOT_PATH= _os.path.expanduser(_bot_path)
|
||||||
@@ -86,13 +87,13 @@ MAP_UTF8_DEATH_PLAYER= '💀'
|
|||||||
MAP_UTF8_ITEM= '📦'
|
MAP_UTF8_ITEM= '📦'
|
||||||
|
|
||||||
MAP_UTF8_LEGEND= f"""*Legenda*:
|
MAP_UTF8_LEGEND= f"""*Legenda*:
|
||||||
\- *{MAP_UTF8_FIELD}*: Cella *libera* per muoversi
|
- *{MAP_UTF8_FIELD}*: Cella *libera* per muoversi
|
||||||
\- *{MAP_UTF8_MOUNTAIN}*: Bordo della mappa, *non raggiungibile*
|
- *{MAP_UTF8_MOUNTAIN}*: Bordo della mappa, *non raggiungibile*
|
||||||
\- *{MAP_UTF8_PLAYER_MALE}*: Posizione di un *giocatore Maschio*
|
- *{MAP_UTF8_PLAYER_MALE}*: Posizione di un *giocatore Maschio*
|
||||||
\- *{MAP_UTF8_PLAYER_FEMALE}*: Posizione di una *giocatorice Femmina*
|
- *{MAP_UTF8_PLAYER_FEMALE}*: Posizione di una *giocatorice Femmina*
|
||||||
\- *{MAP_UTF8_PLAYER_NONBINARY}*: Posizione di un *giocatore non binario*
|
- *{MAP_UTF8_PLAYER_NONBINARY}*: Posizione di un *giocatore non binario*
|
||||||
\- *{MAP_UTF8_DEATH_PLAYER}*: Posizione di un *giocatore morto*
|
- *{MAP_UTF8_DEATH_PLAYER}*: Posizione di un *giocatore morto*
|
||||||
\- *{MAP_UTF8_ITEM}*: Posizione di un *oggetto* \(non ancora implementato\)
|
- *{MAP_UTF8_ITEM}*: Posizione di un *oggetto* (non ancora implementato)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
MAP_IMAGE_FIELD= (0, 255, 0) # green
|
MAP_IMAGE_FIELD= (0, 255, 0) # green
|
||||||
@@ -104,11 +105,11 @@ MAP_IMAGE_DEATH_PLAYER= (160, 160, 160) # grey
|
|||||||
MAP_IMAGE_ITEM= (255, 255, 255) # white
|
MAP_IMAGE_ITEM= (255, 255, 255) # white
|
||||||
|
|
||||||
MAP_IMAGE_LEGEND= r"""*Legenda*:
|
MAP_IMAGE_LEGEND= r"""*Legenda*:
|
||||||
\- *Verde*: Cella *libera* per muoversi
|
- *Verde*: Cella *libera* per muoversi
|
||||||
\- *Nero*: Bordo della mappa, *non raggiungibile*
|
- *Nero*: Bordo della mappa, *non raggiungibile*
|
||||||
\- *Blue*: Posizione di un *giocatore Maschio*
|
- *Blue*: Posizione di un *giocatore Maschio*
|
||||||
\- *Rosso*: Posizione di una *giocatorice Femmina*
|
- *Rosso*: Posizione di una *giocatorice Femmina*
|
||||||
\- *Giallo*: Posizione di un *giocatore non binario*
|
- *Giallo*: Posizione di un *giocatore non binario*
|
||||||
\- *Grigio*: Posizione di un *giocatore morto*
|
- *Grigio*: Posizione di un *giocatore morto*
|
||||||
\- *Bianco*: Posizione di un *oggetto* \(non ancora implementato\)
|
- *Bianco*: Posizione di un *oggetto* (non ancora implementato)
|
||||||
"""
|
"""
|
||||||
|
|||||||
92
debug.py
92
debug.py
@@ -1,39 +1,22 @@
|
|||||||
import time as _time
|
import time as _time
|
||||||
import random as _rand
|
import random as _rand
|
||||||
import main as _main
|
import main as _main
|
||||||
|
from utils import logs as _logs
|
||||||
|
from bot_libs import syms as _syms
|
||||||
|
|
||||||
def _debug_data():
|
def _debug_data():
|
||||||
players= [
|
players= _syms.COLORS_NAMES
|
||||||
{
|
|
||||||
'name': 'Elara',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'Kaelen',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'Zephyr',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'Lyra',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'Orion',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'Seraphina',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
weapons= []
|
weapons= []
|
||||||
|
|
||||||
Arena= _main.init_arena(players, weapons)
|
Arena= _main.init_arena()
|
||||||
print(f'Players: {Arena.get_players()}')
|
for player in players:
|
||||||
print(f'Weapons: {Arena.get_weapons()}')
|
Arena.add_player(player)
|
||||||
return Arena
|
return Arena
|
||||||
|
|
||||||
def _end_game_debug(alive_players, day):
|
def _end_game_debug(alive_players, day):
|
||||||
last_player= alive_players[0]
|
last_player= alive_players[0]
|
||||||
msg= f'{last_player.get_name()} sopravvive e vince dopo {day} lunghi Giorni, conquistando l\'amore eterno di Guarino'
|
msg= f'{last_player.get_name()} sopravvive e vince dopo {day} lunghi Giorni, conquistando l\'amore eterno di Guarino'
|
||||||
print(msg)
|
_logs.log_debug(msg)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def _random_action(Arena, Player_one):
|
def _random_action(Arena, Player_one):
|
||||||
@@ -41,31 +24,37 @@ def _random_action(Arena, Player_one):
|
|||||||
1: 'attack',
|
1: 'attack',
|
||||||
2: 'move',
|
2: 'move',
|
||||||
}
|
}
|
||||||
action= _rand.randint(1, len(_RANDOM_ACTIONS))
|
Map= Arena.get_map()
|
||||||
|
avail_actions= Map.get_player_available_actions(Player_one)
|
||||||
|
_logs.log_debug(f'{Player_one.get_name()}:{Player_one.get_coordinates()}, avail_actions: {avail_actions}')
|
||||||
msg= ''
|
msg= ''
|
||||||
if action == 1:
|
if 1 in avail_actions:
|
||||||
# XXX maybe in future this action is available only if you are near to another player
|
# XXX maybe in future this action is available only if you are near to another player
|
||||||
# so Player_two is no more random, but will be a random near player
|
# so Player_two is no more random, but will be a random near player
|
||||||
Player_two= _rand.sample(Arena.get_alive_players(), 1)[0]
|
preys= avail_actions[1]
|
||||||
while Player_one.get_id() == Player_two.get_id():
|
Player_two= _rand.sample(preys, 1)[0]
|
||||||
Player_two= _rand.sample(Arena.get_alive_players(), 1)[0]
|
while Player_one.get_id() == Player_two.get_id() and not Player_two.is_alive():
|
||||||
|
Player_two= _rand.sample(preys, 1)[0]
|
||||||
_dmg, msg= Player_one.attack(Player_two)
|
_dmg, msg= Player_one.attack(Player_two)
|
||||||
elif action == 2:
|
elif 2 in avail_actions:
|
||||||
Map= Arena.get_map()
|
Map= Arena.get_map()
|
||||||
available_movements= Map.get_player_available_directions(Player_one)
|
available_movements= Map.get_player_available_directions(Player_one)
|
||||||
if not available_movements: return f'{Player_one.get_name()} Pensa a Guarino tutto il giorno' # XXX probably should skip this action and look for another action
|
_logs.log_debug(f'{Player_one.get_name()}:{Player_one.get_coordinates()}, avail_movements: {available_movements}')
|
||||||
|
if not available_movements:
|
||||||
|
# XXX probably should skip this action and look for another action
|
||||||
|
return f'{Player_one.get_name()} Pensa a Guarino tutto il giorno'
|
||||||
_rand.shuffle(available_movements)
|
_rand.shuffle(available_movements)
|
||||||
x, y, direction= available_movements[0]
|
x, y, direction= available_movements[0]
|
||||||
Player_one.move(x, y)
|
Player_one.move(x, y)
|
||||||
Map.init_map_matrix()
|
Map.init_map_matrix()
|
||||||
print(Map.get_renderized_map())
|
_logs.log_debug(Map.get_renderized_map())
|
||||||
msg= f'{Player_one.get_name()} Si muove a: {direction}'
|
msg= f'{Player_one.get_name()} Si muove verso »»» {direction}'
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def play_one_day_debug(Arena):
|
def play_one_day_debug(Arena):
|
||||||
if not Arena.get_players(): return
|
if not Arena.get_players(): return
|
||||||
print(f'Giorno #{Arena.day}')
|
_logs.log_debug(f'Giorno #{Arena.day}')
|
||||||
alive_players= Arena.get_alive_players()
|
alive_players= Arena.get_alive_players()
|
||||||
if len(alive_players) == 1:
|
if len(alive_players) == 1:
|
||||||
day= Arena.day
|
day= Arena.day
|
||||||
@@ -89,7 +78,20 @@ def play_one_day_debug(Arena):
|
|||||||
#_dmg, msg= p_one.attack(p_two)
|
#_dmg, msg= p_one.attack(p_two)
|
||||||
#return msg
|
#return msg
|
||||||
|
|
||||||
def init_debug_loop():
|
def init_debug_simulation():
|
||||||
|
Arena= _debug_data()
|
||||||
|
while (len(Arena.get_alive_players()) > 1):
|
||||||
|
events= play_one_day_debug(Arena)
|
||||||
|
_logs.log_debug('#################')
|
||||||
|
_logs.log_debug('#################')
|
||||||
|
_logs.log_debug('#################')
|
||||||
|
_logs.log_debug(events)
|
||||||
|
_logs.log_debug('#################')
|
||||||
|
_logs.log_debug('#################')
|
||||||
|
_logs.log_debug('#################')
|
||||||
|
_time.sleep(0.3)
|
||||||
|
|
||||||
|
def init_debug_attack_loop():
|
||||||
Arena= _debug_data()
|
Arena= _debug_data()
|
||||||
while (len(Arena.get_alive_players()) > 1):
|
while (len(Arena.get_alive_players()) > 1):
|
||||||
alive_players= Arena.get_alive_players()
|
alive_players= Arena.get_alive_players()
|
||||||
@@ -102,16 +104,30 @@ def init_debug_loop():
|
|||||||
Arena.next_day()
|
Arena.next_day()
|
||||||
_time.sleep(0.3)
|
_time.sleep(0.3)
|
||||||
#End of day
|
#End of day
|
||||||
|
Map= Arena.get_map()
|
||||||
|
_logs.log_debug(Map.get_renderized_map())
|
||||||
|
|
||||||
last_player= Arena.get_alive_players()[0]
|
last_player= Arena.get_alive_players()[0]
|
||||||
print(f'{last_player.get_name()} sopravvive e vince dopo {Arena.day} lunghi Giorni, conquistando l\'amore eterno di Guarino')
|
_logs.log_debug(f'{last_player.get_name()} sopravvive e vince dopo {Arena.day} lunghi Giorni, conquistando l\'amore eterno di Guarino')
|
||||||
|
|
||||||
|
def init_debug_event_loop():
|
||||||
|
Arena= _debug_data()
|
||||||
|
while (len(Arena.get_alive_players()) > 1):
|
||||||
|
Arena.do_random_event()
|
||||||
|
_time.sleep(0.3)
|
||||||
|
#End of day
|
||||||
|
|
||||||
|
last_player= Arena.get_alive_players()[0]
|
||||||
|
_logs.log_debug(f'{last_player.get_name()} sopravvive e vince dopo {Arena.day} lunghi Giorni, conquistando l\'amore eterno di Guarino')
|
||||||
|
|
||||||
def debug_random_map():
|
def debug_random_map():
|
||||||
from entities import map as _map;
|
from entities import map as _map;
|
||||||
from entities import player;
|
from entities import player;
|
||||||
M= _map.BrSimMap(players= [player.BrSimPlayer(i) for i in range(20)]);
|
M= _map.BrSimMap(players= [player.BrSimPlayer(i) for i in range(20)]);
|
||||||
res= M.get_renderized_map()
|
res= M.get_renderized_map()
|
||||||
print(res)
|
_logs.log_debug(res)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
init_debug()
|
init_debug_simulation()
|
||||||
|
#init_debug_attack_loop()
|
||||||
|
#init_debug_event_loop()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from entities import player as _player
|
|||||||
from entities import event_picker as _events
|
from entities import event_picker as _events
|
||||||
from entities import gamemap as _map
|
from entities import gamemap as _map
|
||||||
from entities.items import weapons as _weapons
|
from entities.items import weapons as _weapons
|
||||||
|
from utils import logs as _logs
|
||||||
|
|
||||||
class BrSimArena():
|
class BrSimArena():
|
||||||
|
|
||||||
@@ -30,13 +31,13 @@ class BrSimArena():
|
|||||||
|
|
||||||
def next_day(self):
|
def next_day(self):
|
||||||
self.day+= 1
|
self.day+= 1
|
||||||
print(f'Giorno: {self.day}')
|
_logs.log_debug(f'Giorno: {self.day}')
|
||||||
alive_players_str= ', '.join([p.get_name() for p in self.get_alive_players()])
|
alive_players_str= ', '.join([p.get_name() for p in self.get_alive_players()])
|
||||||
print(f'Giocatori vivi: {alive_players_str}')
|
_logs.log_debug(f'Giocatori vivi: {alive_players_str}')
|
||||||
death_players= self.get_death_players()
|
death_players= self.get_death_players()
|
||||||
if (death_players):
|
if (death_players):
|
||||||
death_players_str= ', '.join([p.get_name() for p in death_players])
|
death_players_str= ', '.join([p.get_name() for p in death_players])
|
||||||
print(f'Giocatori morti: {death_players_str}')
|
_logs.log_debug(f'Giocatori morti: {death_players_str}')
|
||||||
|
|
||||||
def get_alive_players(self):
|
def get_alive_players(self):
|
||||||
res= []
|
res= []
|
||||||
@@ -102,7 +103,8 @@ class BrSimArena():
|
|||||||
|
|
||||||
def do_random_event(self):
|
def do_random_event(self):
|
||||||
#XXX random player does random action according to his inventory health, wounds, available weapons on the world, etc...
|
#XXX random player does random action according to his inventory health, wounds, available weapons on the world, etc...
|
||||||
pass
|
self.eventClass.resolve_event()
|
||||||
|
self.next_day()
|
||||||
|
|
||||||
def supporter_donation(self):
|
def supporter_donation(self):
|
||||||
#XXX supporter donate a random item or weapon to a random player
|
#XXX supporter donate a random item or weapon to a random player
|
||||||
|
|||||||
5
entities/event.py
Normal file
5
entities/event.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class Event():
|
||||||
|
def __init__(self, event_settings, the_player, affected_players = []):
|
||||||
|
# this will be the class that manage the event, so the result and what ahppens to the players
|
||||||
|
# will do it later
|
||||||
|
pass
|
||||||
@@ -7,7 +7,80 @@ class ArenaEventPicker():
|
|||||||
self.event_list = EVENTS
|
self.event_list = EVENTS
|
||||||
self.already_picked_players = []
|
self.already_picked_players = []
|
||||||
|
|
||||||
def pick_event():
|
def pick_a_player(self):
|
||||||
pass
|
the_player = _random.choice(self.players)
|
||||||
|
the_player_id = the_player.get_id()
|
||||||
|
|
||||||
|
self.players = list(filter(lambda x : x.get_id() != the_player_id, self.players))
|
||||||
|
|
||||||
|
self.already_picked_players.append(the_player)
|
||||||
|
|
||||||
|
return the_player
|
||||||
|
|
||||||
|
def pick_event(self, the_player):
|
||||||
|
|
||||||
|
player_inventory = the_player.get_inventory()
|
||||||
|
status = the_player.get_health()
|
||||||
|
reputation = the_player.get_reputation()
|
||||||
|
|
||||||
|
elegible_events = []
|
||||||
|
for event in EVENTS:
|
||||||
|
requirements = event['requirements']
|
||||||
|
|
||||||
|
keys_to_check = ['item', 'weapon', 'status', 'reputation', 'affected_players']
|
||||||
|
|
||||||
|
for check in keys_to_check:
|
||||||
|
if requirements.get(check) and check == 'item':
|
||||||
|
needed_items = requirements.get('check')
|
||||||
|
if needed_items in player_inventory:
|
||||||
|
elegible_events.append(event)
|
||||||
|
|
||||||
|
if requirements.get(check) and check == 'weapon':
|
||||||
|
needed_weapons = requirements.get('check')
|
||||||
|
if needed_items in player_inventory:
|
||||||
|
elegible_events.append(event)
|
||||||
|
|
||||||
|
if requirements.get(check) and check == 'status':
|
||||||
|
needed_health = requirements.get('check')
|
||||||
|
if '>' in requirements.get(check) and requirements.get(check) > needed_health:
|
||||||
|
elegible_events.append(event)
|
||||||
|
if '<' in requirements.get(check) and requirements.get(check) < needed_health:
|
||||||
|
elegible_events.append(event)
|
||||||
|
|
||||||
|
if requirements.get(check) and check == 'reputation':
|
||||||
|
needed_reputation = requirements.get('reputation')
|
||||||
|
if '>' in requirements.get(check) and requirements.get(check) > needed_reputation:
|
||||||
|
elegible_events.append(event)
|
||||||
|
if '<' in requirements.get(check) and requirements.get(check) < needed_reputation:
|
||||||
|
elegible_events.append(event)
|
||||||
|
|
||||||
|
if check == 'affected_players':
|
||||||
|
needed_players = event.get('affected_players')
|
||||||
|
#NOTE: this is only to compensate a double type of needed_players
|
||||||
|
# check NOTE on assets/events.py
|
||||||
|
if isinstance(needed_players, list):
|
||||||
|
if len(needed_players) < len(self.players):
|
||||||
|
elegible_events.append(event)
|
||||||
|
else:
|
||||||
|
if needed_players < len(self.players):
|
||||||
|
elegible_events.append(event)
|
||||||
|
|
||||||
|
the_event = _random.choice(elegible_events)
|
||||||
|
return the_event
|
||||||
|
|
||||||
|
def pick_targets(self, number_of_targets):
|
||||||
|
_random.shuffle(self.players)
|
||||||
|
return list(self.players[0:number_of_targets])
|
||||||
|
|
||||||
|
def resolve_event(self):
|
||||||
|
playing_player = self.pick_a_player()
|
||||||
|
assigned_event = self.pick_event(playing_player)
|
||||||
|
|
||||||
|
affected_players = assigned_event['affected_players']
|
||||||
|
if isinstance(affected_players,list):
|
||||||
|
affected_players = _random.choice(affected_players)
|
||||||
|
|
||||||
|
targeted_players = self.pick_targets(affected_players)
|
||||||
|
|
||||||
|
# FIXME this is not implemented
|
||||||
|
#event_instance = _event.Event(assigned_event, playing_player)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from PIL import ImageDraw as _ImageDraw
|
|||||||
from utils import logs as _logs
|
from utils import logs as _logs
|
||||||
from bot_libs import syms as _bot_syms
|
from bot_libs import syms as _bot_syms
|
||||||
from entities import resource as _resource
|
from entities import resource as _resource
|
||||||
|
from utils import logs as _logs
|
||||||
|
|
||||||
|
|
||||||
class BrSimMap():
|
class BrSimMap():
|
||||||
@@ -66,49 +67,101 @@ class BrSimMap():
|
|||||||
self.game_map[p_coord_y][p_coord_x]= item
|
self.game_map[p_coord_y][p_coord_x]= item
|
||||||
#self.game_map[i_coord_y][i_coord_x]= self.item_sym
|
#self.game_map[i_coord_y][i_coord_x]= self.item_sym
|
||||||
|
|
||||||
def _set_coordinates(self, target):
|
def _put_resource_on_map(self, target):
|
||||||
x= _random.randint(1, self.world_width -2) # from 1 to width-2 because 1 cell is occupied by the mountain
|
#x= _random.randint(1, self.world_width -2) # from 1 to width-2 because 1 cell is occupied by the mountain
|
||||||
y= _random.randint(1, self.world_height -2)
|
#y= _random.randint(1, self.world_height -2)
|
||||||
|
x= _random.randint(0, self.world_width -1)
|
||||||
|
y= _random.randint(0, self.world_height -1)
|
||||||
resource= self.get_map_matrix()[y][x]
|
resource= self.get_map_matrix()[y][x]
|
||||||
while resource:
|
while resource:
|
||||||
#while self.get_map_matrix()[y][x] != self.field_sym:
|
#while self.get_map_matrix()[y][x] != self.field_sym:
|
||||||
_logs.log_debug('_set_coordinates: collision, regenerate coordinates')
|
_logs.log_debug('_put_resource_on_map: collision, regenerate coordinates')
|
||||||
x= _random.randint(1, self.world_width -2)
|
x= _random.randint(0, self.world_width -1)
|
||||||
y= _random.randint(1, self.world_height -2)
|
y= _random.randint(0, self.world_height -1)
|
||||||
|
resource= self.get_map_matrix()[y][x]
|
||||||
|
_logs.log_debug(f'{target.get_name()} >>> ({x},{y})')
|
||||||
target.set_coordinates(x, y)
|
target.set_coordinates(x, y)
|
||||||
|
self.get_map_matrix()[y][x]= target
|
||||||
|
|
||||||
def init_players_coordinates(self):
|
def init_players_coordinates(self):
|
||||||
for player in self.players:
|
for player in self.players:
|
||||||
self._set_coordinates(player)
|
self._put_resource_on_map(player)
|
||||||
|
|
||||||
def init_items_coordinates(self):
|
def init_items_coordinates(self):
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
self._set_coordinates(item)
|
self._put_resource_on_map(item)
|
||||||
|
|
||||||
def add_player_to_map(self, player):
|
def add_player_to_map(self, player):
|
||||||
self.players.append(player)
|
self.players.append(player)
|
||||||
self._set_coordinates(player)
|
self._put_resource_on_map(player)
|
||||||
|
|
||||||
def add_item_to_map(self, item):
|
def add_item_to_map(self, item):
|
||||||
self.items.append(item)
|
self.items.append(item)
|
||||||
self._set_coordinates(item)
|
self._put_resource_on_map(item)
|
||||||
|
|
||||||
def get_map_matrix(self):
|
def get_map_matrix(self):
|
||||||
return self.game_map
|
return self.game_map
|
||||||
|
|
||||||
def get_player_available_directions(self, Player):
|
def get_player_available_directions(self, Player):
|
||||||
coord_x, coord_y= Player.get_player_coordinates()
|
coord_x, coord_y= Player.get_coordinates()
|
||||||
avail_directions= []
|
avail_directions= []
|
||||||
if self.get_map_matrix()[coord_x - 1][coord_y] not in [self.mountain_sym]:
|
#XXX for now move only on available cells, no over other players/items
|
||||||
avail_directions.append((-1, 0, 'left'))
|
for shift in [-1, 1]:
|
||||||
if self.get_map_matrix()[coord_x + 1][coord_y] not in [self.mountain_sym]:
|
x= coord_x + shift
|
||||||
avail_directions.append((1, 0, 'right'))
|
if x < 0 or x > self.world_width -1: continue
|
||||||
if self.get_map_matrix()[coord_x][coord_y - 1] not in [self.mountain_sym]:
|
resource= self.get_map_matrix()[coord_y][x]
|
||||||
avail_directions.append((0, -1, 'up'))
|
direction= shift == -1 and 'sinistra' or 'destra'
|
||||||
if self.get_map_matrix()[coord_x][coord_y + 1] not in [self.mountain_sym]:
|
if not resource: avail_directions.append((shift, 0, direction))
|
||||||
avail_directions.append((0, 1, 'bottom'))
|
for shift in [-1, 1]:
|
||||||
|
y= coord_y + shift
|
||||||
|
if y < 0 or y > self.world_height -1: continue
|
||||||
|
resource= self.get_map_matrix()[y][coord_x]
|
||||||
|
direction= shift == -1 and 'su' or 'giu\''
|
||||||
|
if not resource: avail_directions.append((0, shift, direction))
|
||||||
return avail_directions
|
return avail_directions
|
||||||
|
|
||||||
|
def check_near_players(self, Player):
|
||||||
|
# TODO Implement me
|
||||||
|
# 1. range weapons like arch can attack from distance
|
||||||
|
# 2. knife, sword and punch can attack only on immediate near cell
|
||||||
|
|
||||||
|
coord_x, coord_y= Player.get_coordinates()
|
||||||
|
attackable_players= []
|
||||||
|
for shift in [-1, 1]:
|
||||||
|
x= coord_x + shift
|
||||||
|
if x < 0 or x >= self.world_width -1: continue
|
||||||
|
resource= self.get_map_matrix()[coord_y][x]
|
||||||
|
if resource and resource.is_player() and resource.is_alive(): attackable_players.append(resource)
|
||||||
|
for shift in [-1, 1]:
|
||||||
|
y= coord_y + shift
|
||||||
|
if y < 0 or y >= self.world_height -1: continue
|
||||||
|
resource= self.get_map_matrix()[y][coord_x]
|
||||||
|
if resource and resource.is_player() and resource.is_alive(): attackable_players.append(resource)
|
||||||
|
|
||||||
|
return attackable_players
|
||||||
|
|
||||||
|
def check_near_items(self, Player):
|
||||||
|
# TODO Implement me
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_player_available_actions(self, Player):
|
||||||
|
# TODO: define actions list
|
||||||
|
coord_x, coord_y= Player.get_coordinates()
|
||||||
|
avail_actions= {}
|
||||||
|
|
||||||
|
attack= self.check_near_players(Player)
|
||||||
|
if attack:
|
||||||
|
_logs.log_debug(f'{Player.get_name()} can attack {[a.get_name() for a in attack]}')
|
||||||
|
#avail_actions.append(1) #XXX replace with attack action (or maybe other actions on players)
|
||||||
|
avail_actions[1]= attack #XXX replace with attack action (or maybe other actions on players)
|
||||||
|
if self.get_player_available_directions(Player):
|
||||||
|
avail_actions[2]= True #XXX replace with action move
|
||||||
|
items= self.check_near_items(Player)
|
||||||
|
if items:
|
||||||
|
avail_actions[3]= items #XXX replace with get item action
|
||||||
|
|
||||||
|
return avail_actions
|
||||||
|
|
||||||
def get_renderized_map(self):
|
def get_renderized_map(self):
|
||||||
res= ''
|
res= ''
|
||||||
self.populate_map()
|
self.populate_map()
|
||||||
@@ -118,7 +171,8 @@ class BrSimMap():
|
|||||||
if not x: el= self.field_sym
|
if not x: el= self.field_sym
|
||||||
#XXX how to manage mountains?
|
#XXX how to manage mountains?
|
||||||
elif x.is_player():
|
elif x.is_player():
|
||||||
if x.player_gender_is_male(): el= self.player_male_sym
|
if not x.is_alive(): el= self.dead_player_sym
|
||||||
|
elif x.player_gender_is_male(): el= self.player_male_sym
|
||||||
elif x.player_gender_is_female(): el= self.player_female_sym
|
elif x.player_gender_is_female(): el= self.player_female_sym
|
||||||
else: el= self.player_nonbinary_sym
|
else: el= self.player_nonbinary_sym
|
||||||
elif x.is_item():
|
elif x.is_item():
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from entities.items import weapon_syms as _syms
|
|||||||
class BrSimWeapon(_item.BrSimItem):
|
class BrSimWeapon(_item.BrSimItem):
|
||||||
|
|
||||||
def __init__(self, wtype= None):
|
def __init__(self, wtype= None):
|
||||||
self.weapon= _syms.WEAPONS[wtype or _random.randint(1,2)]
|
self.weapon= _syms.WEAPONS.get(wtype) or _syms.WEAPONS.get(_random.choice(list(_syms.WEAPONS.keys())))
|
||||||
self.name= self.weapon['name']
|
self.name= self.weapon['name']
|
||||||
self.damage= self.weapon['damage']
|
self.damage= self.weapon['damage']
|
||||||
self.weight= self.weapon['weight']
|
self.weight= self.weapon['weight']
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import random as _random
|
import random as _random
|
||||||
import uuid as _uuid
|
import uuid as _uuid
|
||||||
from entities import resource as _resource
|
from entities import resource as _resource
|
||||||
|
from utils import logs as _logs
|
||||||
|
|
||||||
class BrSimPlayer(_resource.BrSimResource):
|
class BrSimPlayer(_resource.BrSimResource):
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ class BrSimPlayer(_resource.BrSimResource):
|
|||||||
self.id= str(_uuid.uuid4())
|
self.id= str(_uuid.uuid4())
|
||||||
self.name= name
|
self.name= name
|
||||||
self.stats= ''
|
self.stats= ''
|
||||||
self.health= _random.randint(1,3)
|
self.health= _random.randint(1,1)
|
||||||
self.inventory= inventory or []
|
self.inventory= inventory or []
|
||||||
self.damage= _random.randint(1,2) # this is the punch damage amount
|
self.damage= _random.randint(1,2) # 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
|
||||||
@@ -137,11 +138,11 @@ class BrSimPlayer(_resource.BrSimResource):
|
|||||||
|
|
||||||
self.health= 0
|
self.health= 0
|
||||||
if self.player_gender_is_male():
|
if self.player_gender_is_male():
|
||||||
print(f'[{self.get_name_and_stats()}]: Guarino, perdonami se sono morto x.x')
|
_logs.log_debug(f'[{self.get_name_and_stats()}]: Guarino, perdonami se sono morto x.x')
|
||||||
elif self.player_gender_is_female():
|
elif self.player_gender_is_female():
|
||||||
print(f'[{self.get_name_and_stats()}]: Guarino, perdonami se sono morta x.x')
|
_logs.log_debug(f'[{self.get_name_and_stats()}]: Guarino, perdonami se sono morta x.x')
|
||||||
else:
|
else:
|
||||||
print(f'[{self.get_name_and_stats()}]: Guarino, perdonami se sono mort* x.x')
|
_logs.log_debug(f'[{self.get_name_and_stats()}]: Guarino, perdonami se sono mort* x.x')
|
||||||
return damage
|
return damage
|
||||||
|
|
||||||
def attack(self, target):
|
def attack(self, target):
|
||||||
@@ -166,11 +167,11 @@ class BrSimPlayer(_resource.BrSimResource):
|
|||||||
def get_item(self, item):
|
def get_item(self, item):
|
||||||
if self.get_inventory_weight() + item.get_weight() >= self.get_max_weight():
|
if self.get_inventory_weight() + item.get_weight() >= self.get_max_weight():
|
||||||
if self.player_gender_is_male():
|
if self.player_gender_is_male():
|
||||||
print(f'Sono sovraccarico, {self.get_name_and_stats} non puo\' prendere questo oggetto')
|
_logs.log_debug(f'Sono sovraccarico, {self.get_name_and_stats} non puo\' prendere questo oggetto')
|
||||||
elif self.player_gender_is_female():
|
elif self.player_gender_is_female():
|
||||||
print(f'Sono sovraccarica, {self.get_name_and_stats} non puo\' prendere questo oggetto')
|
_logs.log_debug(f'Sono sovraccarica, {self.get_name_and_stats} non puo\' prendere questo oggetto')
|
||||||
else:
|
else:
|
||||||
print(f'Sono sovraccaric#, {self.get_name_and_stats} non puo\' prendere questo oggetto')
|
_logs.log_debug(f'Sono sovraccaric#, {self.get_name_and_stats} non puo\' prendere questo oggetto')
|
||||||
return False
|
return False
|
||||||
self.inventory.append(item)
|
self.inventory.append(item)
|
||||||
|
|
||||||
|
|||||||
@@ -19,17 +19,16 @@ def get_log_name():
|
|||||||
|
|
||||||
def _create_file_handler():
|
def _create_file_handler():
|
||||||
global file_handler
|
global file_handler
|
||||||
print('### create file handler')
|
|
||||||
current_log_file = get_log_name()
|
current_log_file = get_log_name()
|
||||||
file_handler = _logging.FileHandler(current_log_file, encoding='utf-8')
|
file_handler = _logging.FileHandler(current_log_file, encoding='utf-8')
|
||||||
formatter = _logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
formatter = _logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
||||||
file_handler.setFormatter(formatter)
|
file_handler.setFormatter(formatter)
|
||||||
logger.addHandler(file_handler)
|
logger.addHandler(file_handler)
|
||||||
logger.setLevel(_logging.INFO)
|
#logger.setLevel(_logging.INFO)
|
||||||
|
logger.setLevel(_logging.DEBUG)
|
||||||
return file_handler
|
return file_handler
|
||||||
|
|
||||||
def _setup_logging_file():
|
def _setup_logging_file():
|
||||||
print('### setup logging')
|
|
||||||
current_log_file = get_log_name()
|
current_log_file = get_log_name()
|
||||||
|
|
||||||
if not file_handler: return _create_file_handler()
|
if not file_handler: return _create_file_handler()
|
||||||
@@ -40,6 +39,7 @@ def _setup_logging_file():
|
|||||||
_create_file_handler()
|
_create_file_handler()
|
||||||
|
|
||||||
def log_debug(txt):
|
def log_debug(txt):
|
||||||
|
print(txt)
|
||||||
_setup_logging_file()
|
_setup_logging_file()
|
||||||
logger.debug(txt)
|
logger.debug(txt)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user