Skip to content

Commit

Permalink
Merge pull request #193 from esoviscode/actual-stats
Browse files Browse the repository at this point in the history
actual stats changes (i. a. resolves #188)
  • Loading branch information
gitesthuman authored May 7, 2023
2 parents 88baea1 + 6252d1b commit 6b8d9bc
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 22 deletions.
2 changes: 1 addition & 1 deletion dnd-bot/dnd_bot/database/database_creature.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def add_creature(x: int = 0, y: int = 0, name: str = 'Creature', hp: int = 0, st
level, hp, strength, dexterity, intelligence,
charisma, perception, initiative, action_points,
drop_money, id_entity, experience),
"creature")
"creature") # TODO add max_hp
return id_creature

@staticmethod
Expand Down
6 changes: 3 additions & 3 deletions dnd-bot/dnd_bot/dc/ui/message_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def stats_message_template(player):
desc += f'Charisma: {player.charisma}\n'
desc += f'Perception: {player.perception}\n'
desc += f'Initiative: {player.initiative}\n'
desc += f'Action Points: {player.action_points}\n'
desc += f'Action Points: {player.initial_action_points}\n'

embed = nextcord.Embed(title="Your Stats:", description=desc)
return embed
Expand All @@ -142,8 +142,8 @@ async def creature_turn_embed(token, user_id, recent_action=''):
active_creature = Multiverse.get_game(token).get_active_creature()

embed = nextcord.Embed(title=f'Position: ({player.x}, {player.y}) | Action points: {player.action_points}/'
f'{player.initial_action_points} | '
f'HP: {player.hp}/{player.max_hp}', description=recent_action)
f'{player.initial_action_points} | HP: {player.hp}/{player.max_hp}',
description=recent_action)
if isinstance(active_creature, Player):
active_user = await get_user_by_id(active_creature.discord_identity)
active_user_icon = active_user.display_avatar.url
Expand Down
6 changes: 3 additions & 3 deletions dnd-bot/dnd_bot/logic/game/initialize_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ def add_player(x: int = 0, y: int = 0, name: str = '', discord_identity: int = 0
alignment=alignment, hp=hp, strength=strength, dexterity=dexterity, intelligence=intelligence,
charisma=charisma, perception=perception, initiative=initiative, action_points=action_points,
character_race=character_race, character_class=character_class)
id_player = DatabasePlayer.add_player(p.x, p.y, p.name, p.hp, p.strength, p.dexterity,
p.intelligence, p.charisma, p.perception, p.initiative,
id_player = DatabasePlayer.add_player(p.x, p.y, p.name, p.hp, p.base_strength, p.base_dexterity,
p.base_intelligence, p.base_charisma, p.base_perception, p.initiative,
p.action_points, p.level, p.discord_identity, p.alignment,
p.backstory, id_game=game_id, character_race=p.character_race,
character_class=p.creature_class) # TODO add race and class
character_class=p.creature_class)
p.id = id_player

# TODO change location of adding equipment/items
Expand Down
54 changes: 45 additions & 9 deletions dnd-bot/dnd_bot/logic/prototype/creature.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,61 @@ def __init__(self, x=0, y=0, sprite: str = '', name: str = 'Creature', hp: int =
drop_money = []
if drops is None:
drops = []

self.hp = hp
self.max_hp = hp
self.strength = strength
self.dexterity = dexterity
self.intelligence = intelligence
self.charisma = charisma
self.perception = perception
self.base_strength = strength
self.base_dexterity = dexterity
self.base_intelligence = intelligence
self.base_charisma = charisma
self.base_perception = perception

self.initiative = initiative
self.action_points = action_points
self.level = level
self.equipment = equipment
self.drop_money = drop_money
self.initial_action_points = action_points
self.equipment = equipment
self.level = level
self.experience = experience
self.creature_class = creature_class

self.drop_money = drop_money
self.drops = drops

self.ai = ai
self.move_queue = []

# ----------------------------------------------------- properties -----------------------------------------------------
def eq_stats(self, stat):
"""returns additional "stat" value that comes from items in equipment"""
from dnd_bot.logic.prototype.items.item import Item
return sum([i.__getattribute__(stat) if isinstance(i, Item) else 0 for i in self.equipment.__dict__.values()])

# future development
# def effects_stats(self, stat):
# return sum([e.__getattribute__(stat) for e in self.effects])

@property
def strength(self):
return self.base_strength + self.eq_stats("strength")

@property
def dexterity(self):
return self.base_dexterity + self.eq_stats("dexterity")

@property
def intelligence(self):
return self.base_intelligence + self.eq_stats("intelligence")

@property
def charisma(self):
return self.base_charisma + self.eq_stats("charisma")

@property
def perception(self):
return self.base_perception + self.eq_stats("perception")

# ----------------------------------------------------- properties -----------------------------------------------------

async def ai_action(self):
"""perform certain ai action and returns its response
:return: string"""
Expand Down Expand Up @@ -183,7 +218,8 @@ def choose_aggro(self, foes):
:return target: tuple (Player object, path)"""
from dnd_bot.logic.prototype.multiverse import Multiverse

intelligence = "high" if self.intelligence >= 10 else ("low" if self.intelligence <= 3 else "medium")
intelligence = "high" if self.intelligence >= 10 else \
("low" if self.intelligence <= 3 else "medium")
if intelligence != "low":
class_priority = ["Mage", "Ranger", "Warrior"]
sorted_foes = []
Expand Down
4 changes: 2 additions & 2 deletions dnd-bot/dnd_bot/logic/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_player_view(game: Game, player: Player, attack_mode=False):
player_view = copy.deepcopy(game.sprite)

# pasting entities in vision
points_in_range = generate_circle_points(player.perception, Mv.view_range)
points_in_range = generate_circle_points(min(player.perception, 4), Mv.view_range)
entities = [e for e in sum(game.entities, []) if e and e.fragile
and (e.x - player.x, e.y - player.y) in points_in_range]

Expand All @@ -180,7 +180,7 @@ def get_player_view(game: Game, player: Player, attack_mode=False):
from_x * Mv.square_size:to_x * Mv.square_size]

# cropping mask
mask = Mv.masks[player.perception][
mask = Mv.masks[min(player.perception, 4)][
-min(0, player.y - Mv.view_range) * Mv.square_size:
((Mv.view_range * 2 + 1) + min(0, (game.world_height - 1 - player.y - Mv.view_range))) * Mv.square_size,
-min(0, player.x - Mv.view_range) * Mv.square_size:
Expand Down
8 changes: 4 additions & 4 deletions dnd-bot/dnd_bot/tests/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def test_add_player(postgresql):
game_token='12345', character_class='MAGE', character_race='HUMAN')

game_id = DatabaseGame.get_id_game_from_game_token('12345')
id_player = DatabasePlayer.add_player(x=p.x, y=p.y, name=p.name, hp=p.hp, strength=p.strength,
dexterity=p.dexterity, intelligence=p.intelligence, charisma=p.charisma,
perception=p.perception, initiative=p.initiative,
action_points=p.action_points,
id_player = DatabasePlayer.add_player(x=p.x, y=p.y, name=p.name, hp=p.hp, strength=p.base_strength,
dexterity=p.base_dexterity, intelligence=p.base_intelligence,
charisma=p.base_charisma, perception=p.base_perception,
initiative=p.initiative, action_points=p.action_points,
level=p.level, discord_identity=p.discord_identity, alignment=p.alignment,
backstory=p.backstory, id_game=game_id,
character_race=p.character_race, character_class=p.creature_class)
Expand Down

0 comments on commit 6b8d9bc

Please sign in to comment.