mirror of
https://github.com/Threnklyn/dungeon-sheets.git
synced 2026-06-07 13:15:53 +02:00
Refactoring Agent, Character into Agent base class
This commit is contained in:
+62
-10
@@ -1,14 +1,16 @@
|
|||||||
from dungeonsheets.stats import Ability, ArmorClass, Initiative, Speed
|
from dungeonsheets.stats import Ability, ArmorClass, Initiative, Speed, Skill
|
||||||
|
|
||||||
|
|
||||||
class Agent:
|
class Agent:
|
||||||
"""An actor in an encounter"""
|
"""An actor in an encounter"""
|
||||||
|
|
||||||
strategies = ("Random", "Greedy", "KillWeakest")
|
# General attributes
|
||||||
strategy = "Greedy"
|
name = ""
|
||||||
|
alignment = "Neutral"
|
||||||
|
|
||||||
# Hit points
|
# Hit points
|
||||||
hp_max = None
|
hp_max = None
|
||||||
|
|
||||||
# Base stats (ability scores)
|
# Base stats (ability scores)
|
||||||
strength = Ability()
|
strength = Ability()
|
||||||
dexterity = Ability()
|
dexterity = Ability()
|
||||||
@@ -16,46 +18,96 @@ class Agent:
|
|||||||
intelligence = Ability()
|
intelligence = Ability()
|
||||||
wisdom = Ability()
|
wisdom = Ability()
|
||||||
charisma = Ability()
|
charisma = Ability()
|
||||||
|
|
||||||
|
# Numerical things
|
||||||
armor_class = ArmorClass()
|
armor_class = ArmorClass()
|
||||||
initiative = Initiative()
|
initiative = Initiative()
|
||||||
speed = Speed()
|
speed = Speed()
|
||||||
|
|
||||||
|
# Proficiencies and Languages
|
||||||
|
_saving_throw_proficiencies = tuple() # use to overwrite class proficiencies
|
||||||
|
other_weapon_proficiencies = tuple() # add to class/race proficiencies
|
||||||
|
skill_proficiencies = list()
|
||||||
|
skill_expertise = list()
|
||||||
languages = ""
|
languages = ""
|
||||||
|
|
||||||
|
# Skills
|
||||||
|
acrobatics = Skill(ability="dexterity")
|
||||||
|
animal_handling = Skill(ability="wisdom")
|
||||||
|
arcana = Skill(ability="intelligence")
|
||||||
|
athletics = Skill(ability="strength")
|
||||||
|
deception = Skill(ability="charisma")
|
||||||
|
history = Skill(ability="intelligence")
|
||||||
|
insight = Skill(ability="wisdom")
|
||||||
|
intimidation = Skill(ability="charisma")
|
||||||
|
investigation = Skill(ability="intelligence")
|
||||||
|
medicine = Skill(ability="wisdom")
|
||||||
|
nature = Skill(ability="intelligence")
|
||||||
|
perception = Skill(ability="wisdom")
|
||||||
|
performance = Skill(ability="charisma")
|
||||||
|
persuasion = Skill(ability="charisma")
|
||||||
|
religion = Skill(ability="intelligence")
|
||||||
|
sleight_of_hand = Skill(ability="dexterity")
|
||||||
|
stealth = Skill(ability="dexterity")
|
||||||
|
survival = Skill(ability="wisdom")
|
||||||
|
|
||||||
|
|
||||||
|
# Inventory
|
||||||
|
cp = 0
|
||||||
|
sp = 0
|
||||||
|
ep = 0
|
||||||
|
gp = 0
|
||||||
|
pp = 0
|
||||||
|
equipment = ""
|
||||||
|
weapons = list()
|
||||||
|
magic_items = list()
|
||||||
|
armor = None
|
||||||
|
shield = None
|
||||||
|
|
||||||
|
# Magic
|
||||||
|
spellcasting_ability = None
|
||||||
|
_spells = list()
|
||||||
|
_spells_prepared = list()
|
||||||
|
infusions = list()
|
||||||
|
|
||||||
|
# Features IN MAJOR DEVELOPMENT
|
||||||
|
custom_features = list()
|
||||||
|
feature_choices = list()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def actions(self):
|
def actions(self):
|
||||||
"""All the things I can do in a turn"""
|
"""All the things I can do in a turn"""
|
||||||
raise NotImplementedError()
|
return []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def free_actions(self):
|
def free_actions(self):
|
||||||
"""Stuff I can do as much as I want in a turn"""
|
"""Stuff I can do as much as I want in a turn"""
|
||||||
raise NotImplementedError()
|
return []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def movement(self):
|
def movement(self):
|
||||||
"""Where I can go in a turn"""
|
"""Where I can go in a turn"""
|
||||||
raise NotImplementedError()
|
return []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bonus_actions(self):
|
def bonus_actions(self):
|
||||||
"""Things I can do once in addition to an action"""
|
"""Things I can do once in addition to an action"""
|
||||||
raise NotImplementedError()
|
return []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def reactions(self):
|
def reactions(self):
|
||||||
"""Things I can do in response to an action"""
|
"""Things I can do in response to an action"""
|
||||||
raise NotImplementedError()
|
return []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def lair_actions(self):
|
def lair_actions(self):
|
||||||
"""Things I can do at initiative count 20"""
|
"""Things I can do at initiative count 20"""
|
||||||
raise NotImplementedError()
|
return []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def legendary_actions(self):
|
def legendary_actions(self):
|
||||||
"""Things I can do so many times in a turn after another agent acts"""
|
"""Things I can do so many times in a turn after another agent acts"""
|
||||||
raise NotImplementedError()
|
return []
|
||||||
@@ -149,54 +149,17 @@ def _resolve_mechanic(mechanic, module, SuperClass, warning_message=None):
|
|||||||
class Character(Agent):
|
class Character(Agent):
|
||||||
"""A generic player character."""
|
"""A generic player character."""
|
||||||
|
|
||||||
# General attirubtes
|
|
||||||
name = ""
|
|
||||||
player_name = ""
|
player_name = ""
|
||||||
alignment = "Neutral"
|
|
||||||
dungeonsheets_version = __version__
|
dungeonsheets_version = __version__
|
||||||
|
xp = 0
|
||||||
|
inspiration = False
|
||||||
|
attacks_and_spellcasting = ""
|
||||||
class_list = list()
|
class_list = list()
|
||||||
_race = None
|
_race = None
|
||||||
_background = None
|
_background = None
|
||||||
xp = 0
|
|
||||||
# Hit points
|
|
||||||
hp_max = None
|
|
||||||
# Base stats (ability scores)
|
|
||||||
strength = Ability()
|
|
||||||
dexterity = Ability()
|
|
||||||
constitution = Ability()
|
|
||||||
intelligence = Ability()
|
|
||||||
wisdom = Ability()
|
|
||||||
charisma = Ability()
|
|
||||||
armor_class = ArmorClass()
|
|
||||||
initiative = Initiative()
|
|
||||||
speed = Speed()
|
|
||||||
inspiration = False
|
|
||||||
_saving_throw_proficiencies = tuple() # use to overwrite class proficiencies
|
|
||||||
other_weapon_proficiencies = tuple() # add to class/race proficiencies
|
|
||||||
skill_proficiencies = list()
|
|
||||||
skill_expertise = list()
|
|
||||||
languages = ""
|
|
||||||
# Skills
|
|
||||||
acrobatics = Skill(ability="dexterity")
|
|
||||||
animal_handling = Skill(ability="wisdom")
|
|
||||||
arcana = Skill(ability="intelligence")
|
|
||||||
athletics = Skill(ability="strength")
|
|
||||||
deception = Skill(ability="charisma")
|
|
||||||
history = Skill(ability="intelligence")
|
|
||||||
insight = Skill(ability="wisdom")
|
|
||||||
intimidation = Skill(ability="charisma")
|
|
||||||
investigation = Skill(ability="intelligence")
|
|
||||||
medicine = Skill(ability="wisdom")
|
|
||||||
nature = Skill(ability="intelligence")
|
|
||||||
perception = Skill(ability="wisdom")
|
|
||||||
performance = Skill(ability="charisma")
|
|
||||||
persuasion = Skill(ability="charisma")
|
|
||||||
religion = Skill(ability="intelligence")
|
|
||||||
sleight_of_hand = Skill(ability="dexterity")
|
|
||||||
stealth = Skill(ability="dexterity")
|
|
||||||
survival = Skill(ability="wisdom")
|
|
||||||
# Characteristics
|
# Characteristics
|
||||||
attacks_and_spellcasting = ""
|
|
||||||
personality_traits = (
|
personality_traits = (
|
||||||
"TODO: Describe how your character behaves, interacts with others"
|
"TODO: Describe how your character behaves, interacts with others"
|
||||||
)
|
)
|
||||||
@@ -204,26 +167,8 @@ class Character(Agent):
|
|||||||
bonds = "TODO: Describe your character's commitments or ongoing quests."
|
bonds = "TODO: Describe your character's commitments or ongoing quests."
|
||||||
flaws = "TODO: Describe your character's interesting flaws."
|
flaws = "TODO: Describe your character's interesting flaws."
|
||||||
features_and_traits = "Describe any other features and abilities."
|
features_and_traits = "Describe any other features and abilities."
|
||||||
# Inventory
|
|
||||||
cp = 0
|
|
||||||
sp = 0
|
|
||||||
ep = 0
|
|
||||||
gp = 0
|
|
||||||
pp = 0
|
|
||||||
equipment = ""
|
|
||||||
weapons = list()
|
|
||||||
magic_items = list()
|
|
||||||
armor = None
|
|
||||||
shield = None
|
|
||||||
_proficiencies_text = list()
|
_proficiencies_text = list()
|
||||||
# Magic
|
|
||||||
spellcasting_ability = None
|
|
||||||
_spells = list()
|
|
||||||
_spells_prepared = list()
|
|
||||||
infusions = list()
|
|
||||||
# Features IN MAJOR DEVELOPMENT
|
|
||||||
custom_features = list()
|
|
||||||
feature_choices = list()
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
from dungeonsheets.encounter.encounter import Encounter
|
||||||
@@ -7,6 +7,7 @@ class Encounter:
|
|||||||
if len(parties) is not 2:
|
if len(parties) is not 2:
|
||||||
raise NotImplementedError("Haven't implemented AI for 3+ groups") # TODO: Implement this
|
raise NotImplementedError("Haven't implemented AI for 3+ groups") # TODO: Implement this
|
||||||
|
|
||||||
|
# Combine all parties into a single group
|
||||||
self.all_agents = parties[0]
|
self.all_agents = parties[0]
|
||||||
for party in parties[1:]:
|
for party in parties[1:]:
|
||||||
self.all_agents += party
|
self.all_agents += party
|
||||||
|
|||||||
@@ -240,3 +240,23 @@ class Initiative(NumericalInitiative):
|
|||||||
if has_advantage:
|
if has_advantage:
|
||||||
ini += "(A)"
|
ini += "(A)"
|
||||||
return ini
|
return ini
|
||||||
|
|
||||||
|
|
||||||
|
###########################
|
||||||
|
# STATUS
|
||||||
|
###########################
|
||||||
|
|
||||||
|
class CurrentHP:
|
||||||
|
"""A Numerical Representation of Current HP"""
|
||||||
|
|
||||||
|
def __get__(self, char, Character):
|
||||||
|
if not char.hp_max:
|
||||||
|
char.__set_hp_max()
|
||||||
|
return char.hp_max
|
||||||
|
|
||||||
|
|
||||||
|
class CurrentInitiative(NumericalInitiative):
|
||||||
|
"""A Numerical Representation of a Character's Rolled Initiative"""
|
||||||
|
|
||||||
|
def __get__(self, char, Character):
|
||||||
|
ini, has_advantage = super(CurrentInitiative, self).__get__(char, Character)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
def roll(d, n=1):
|
||||||
|
"""roll(6, 2) means roll 2d6"""
|
||||||
|
return sum([random.randint(1, d) for _ in range(n)])
|
||||||
@@ -3,17 +3,20 @@
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from dungeonsheets.character import Character
|
from dungeonsheets.character import Character
|
||||||
|
from dungeonsheets.encounter import Encounter
|
||||||
|
from dungeonsheets.monsters import Monster
|
||||||
|
from dungeonsheets.stats import Ability
|
||||||
|
|
||||||
|
|
||||||
class TestEncounter(TestCase):
|
class TestEncounter(TestCase):
|
||||||
"""Tests for features and feature-related activities."""
|
"""Tests for features and feature-related activities."""
|
||||||
|
|
||||||
def test_simulation():
|
def test_simulation(self):
|
||||||
"""Can I run an encounter against Schlangdedrosa Magentawrath?"""
|
"""Can I run an encounter against Schlangdedrosa Magentawrath?"""
|
||||||
char = Character()
|
char = Character()
|
||||||
char.set_attrs(name="Stravajiaxen")
|
char.set_attrs(name="Stravajiaxen")
|
||||||
char.set_attrs(weapons=["shortsword"])
|
char.set_attrs(weapons=["greataxe"])
|
||||||
char.set_attrs(armor="leather armor", shield="shield")
|
char.set_attrs(armor="split mail")
|
||||||
|
|
||||||
# Check that race gets set to an object
|
# Check that race gets set to an object
|
||||||
char.set_attrs(race="half orc")
|
char.set_attrs(race="half orc")
|
||||||
@@ -63,4 +66,5 @@ class TestEncounter(TestCase):
|
|||||||
|
|
||||||
schlang = SchlangdedrosaMagentawrath()
|
schlang = SchlangdedrosaMagentawrath()
|
||||||
|
|
||||||
battle = Encounter([])
|
battle = Encounter([char], [schlang])
|
||||||
|
results = battle.simulate()
|
||||||
Reference in New Issue
Block a user