API merge final
This commit is contained in:
@@ -1,14 +1,42 @@
|
||||
# Game imports
|
||||
from serializable import Serializable
|
||||
from entities.entity import Entity
|
||||
from turn import Turn, TurnAction
|
||||
|
||||
# Native imports
|
||||
import json
|
||||
import uuid
|
||||
|
||||
class Event(Serializable):
|
||||
def __init__(self, location:str):
|
||||
def __init__(self, location:str, initial_description:str, entities:list[str]):
|
||||
super().__init__()
|
||||
self.id = str(uuid.uuid4())
|
||||
self.location = location
|
||||
self.description = ""
|
||||
self.id:str = str(uuid.uuid4())
|
||||
self.location:str = location
|
||||
self.initial_description:str = initial_description
|
||||
|
||||
self.entities:list[str] = entities
|
||||
self.turns:list[Turn] = []
|
||||
self.add_turn()
|
||||
|
||||
def remove_entity(self, entity_id:str):
|
||||
if entity_id in self.entities:
|
||||
self.entities.remove(entity_id)
|
||||
|
||||
def get_current_turn(self):
|
||||
idx = len(self.turns) - 1
|
||||
if idx < 0:
|
||||
raise IndexError("There is no turns yet, you should create one!")
|
||||
return self.turns[idx]
|
||||
|
||||
def add_turn(self):
|
||||
self.turns.append(Turn())
|
||||
|
||||
def perform_action(self, action:TurnAction, entity_id:str, description:str):
|
||||
current_turn = self.get_current_turn()
|
||||
current_turn.add_action(action_type=action, entity_id=entity_id, description=description)
|
||||
|
||||
if current_turn.is_finished():
|
||||
self.add_turn()
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
# Game import
|
||||
from serializable import Serializable
|
||||
|
||||
# Native imports
|
||||
from enum import Enum, IntEnum
|
||||
from enum import Enum
|
||||
|
||||
class Action(Enum):
|
||||
ATTACK = 'strength' # Physical Battle action
|
||||
FORCE = 'strength' # Actions that requires physical effort
|
||||
SPELL = 'intelligence' # Many kind of spell (battle or not)
|
||||
SCAN = 'wisdom' # Danger in environment or NPC's lies
|
||||
SPEECH = 'charisma' # To persuade or deceive
|
||||
AGILE = 'dexterity' # Avoid traps or incoming attacks & spell
|
||||
class TurnAction(Enum):
|
||||
DAMAGE = 'deal_damage'
|
||||
STATS = 'modify_stat'
|
||||
BASIC = 'basic_action'
|
||||
|
||||
class BonusAction(IntEnum):
|
||||
EQUIP_ITEM = 0
|
||||
USE_CONSUMMABLE = 1
|
||||
class Turn(Serializable):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.actions = {}
|
||||
|
||||
def add_action(self, action_type:TurnAction, entity_id:str, description:str):
|
||||
self.actions[entity_id] = f'[{action_type.value}]: ' + description
|
||||
|
||||
def is_finished(self, nb_entities:int):
|
||||
return len(self.actions.keys()) == nb_entities
|
||||
Reference in New Issue
Block a user