Skip to content

Commit

Permalink
added girlfriends property and updated relationship dict
Browse files Browse the repository at this point in the history
  • Loading branch information
KiloOscarSix committed May 6, 2023
1 parent 370d572 commit eb68877
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 41 deletions.
63 changes: 26 additions & 37 deletions CharacterService_ren.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from __future__ import annotations
from typing import Optional, TYPE_CHECKING
from typing import Optional
from game.characters.ICharacter_ren import ICharacter

import renpy.exports as renpy

from game.characters.Relationship_ren import Relationship
from game.characters.Moods_ren import Moods

if TYPE_CHECKING:
from game.characters.NonPlayableCharacter_ren import NonPlayableCharacter
from game.characters.PlayableCharacters_ren import PlayableCharacter, mc
from game.characters.PlayableCharacters_ren import mc

"""renpy
init python:
Expand All @@ -18,21 +17,21 @@
class CharacterService:
@staticmethod
def get_relationship(
character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None
character: ICharacter, target: Optional[ICharacter] = None
) -> Relationship:
if target is None:
target = mc

if not hasattr(character, "relationships"):
character.relationships = {}

return character.relationships.setdefault(target.name, Relationship.FRIEND)
return character.relationships.setdefault(target, Relationship.FRIEND)

@staticmethod
def has_relationship(
character: NonPlayableCharacter,
character: ICharacter,
relationship: Relationship,
target: Optional[PlayableCharacter] = None,
target: Optional[ICharacter] = None,
) -> bool:
if target is None:
target = mc
Expand All @@ -41,9 +40,9 @@ def has_relationship(

@staticmethod
def set_relationship(
character: NonPlayableCharacter,
character: ICharacter,
relationship: Relationship,
target: Optional[PlayableCharacter] = None,
target: Optional[ICharacter] = None,
) -> None:
if target is None:
target = mc
Expand All @@ -55,35 +54,35 @@ def set_relationship(
target.relationships = {}

if (
character.relationships.setdefault(target.name, Relationship.FRIEND)
character.relationships.setdefault(target, Relationship.FRIEND)
== relationship
):
return

character.relationships[target.name] = relationship
target.relationships[character.name] = relationship
character.relationships[target] = relationship
target.relationships[character] = relationship

@staticmethod
def get_mood(character: NonPlayableCharacter) -> Moods:
def get_mood(character: ICharacter) -> Moods:
return character.mood

@staticmethod
def has_mood(character: NonPlayableCharacter, mood: Moods) -> bool:
def has_mood(character: ICharacter, mood: Moods) -> bool:
return mood == character.mood or character.mood & mood == mood

@staticmethod
def set_mood(character: NonPlayableCharacter, mood: Moods) -> None:
def set_mood(character: ICharacter, mood: Moods) -> None:
if mood == character.mood:
return

character.mood = mood

@staticmethod
def reset_mood(character: NonPlayableCharacter) -> None:
def reset_mood(character: ICharacter) -> None:
character.mood = Moods.NORMAL

@staticmethod
def add_mood(character: NonPlayableCharacter, mood: Moods) -> None:
def add_mood(character: ICharacter, mood: Moods) -> None:
if mood == character.mood:
return

Expand All @@ -94,7 +93,7 @@ def add_mood(character: NonPlayableCharacter, mood: Moods) -> None:
character.mood = character.mood | mood

@staticmethod
def remove_mood(character: NonPlayableCharacter, mood: Moods) -> None:
def remove_mood(character: ICharacter, mood: Moods) -> None:
character.mood = character.mood & ~mood

@staticmethod
Expand All @@ -112,7 +111,7 @@ def get_profile_pictures(character_name: str) -> list[str]:

@staticmethod
def is_girlfriend(
character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None
character: ICharacter, target: Optional[ICharacter] = None
) -> bool:
if target is None:
target = mc
Expand All @@ -122,54 +121,44 @@ def is_girlfriend(
)

@staticmethod
def is_fwb(
character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None
) -> bool:
def is_fwb(character: ICharacter, target: Optional[ICharacter] = None) -> bool:
if target is None:
target = mc

return CharacterService.has_relationship(character, Relationship.FWB, target)

@staticmethod
def is_dating(
character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None
) -> bool:
def is_dating(character: ICharacter, target: Optional[ICharacter] = None) -> bool:
if target is None:
target = mc

return CharacterService.has_relationship(character, Relationship.DATING, target)

@staticmethod
def is_kissed(
character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None
) -> bool:
def is_kissed(character: ICharacter, target: Optional[ICharacter] = None) -> bool:
if target is None:
target = mc

return CharacterService.has_relationship(character, Relationship.KISSED, target)

@staticmethod
def is_friend(
character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None
) -> bool:
def is_friend(character: ICharacter, target: Optional[ICharacter] = None) -> bool:
if target is None:
target = mc

return CharacterService.has_relationship(character, Relationship.FRIEND, target)

@staticmethod
def is_ex(
character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None
) -> bool:
def is_ex(character: ICharacter, target: Optional[ICharacter] = None) -> bool:
if target is None:
target = mc

return CharacterService.has_relationship(character, Relationship.EX, target)

@staticmethod
def is_mad(character: NonPlayableCharacter) -> bool:
def is_mad(character: ICharacter) -> bool:
return CharacterService.has_mood(character, Moods.MAD)

@staticmethod
def is_threatened(character: NonPlayableCharacter) -> bool:
def is_threatened(character: ICharacter) -> bool:
return CharacterService.has_mood(character, Moods.THREATENED)
14 changes: 14 additions & 0 deletions ICharacter_ren.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import annotations
from abc import ABC
from game.characters.Moods_ren import Moods

from game.characters.Relationship_ren import Relationship

"""renpy
init python:
"""


class ICharacter(ABC):
relationships: dict[ICharacter, Relationship]
mood: Moods
5 changes: 3 additions & 2 deletions NonPlayableCharacter_ren.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from dataclasses import dataclass, field

from game.characters.CharacterService_ren import CharacterService
from game.characters.ICharacter_ren import ICharacter
from game.characters.Moods_ren import Moods
from game.characters.Relationship_ren import Relationship
from game.phone.Message_ren import Message
Expand All @@ -12,11 +13,11 @@


@dataclass
class NonPlayableCharacter:
class NonPlayableCharacter(ICharacter):
name: str
username: str = ""

relationships: dict[str, Relationship] = field(default_factory=dict)
relationships: dict[ICharacter, Relationship] = field(default_factory=dict)
mood: Moods = Moods.NORMAL

profile_pictures: list[str] = field(default_factory=list)
Expand Down
13 changes: 11 additions & 2 deletions PlayableCharacters_ren.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Optional, TYPE_CHECKING
from game.characters.ICharacter_ren import ICharacter

import renpy.exports as renpy

Expand All @@ -19,14 +20,14 @@


@dataclass
class PlayableCharacter:
class PlayableCharacter(ICharacter):
name: str = ""
username: str = ""
profile_pictures: list[str] = field(default_factory=list)
money: int = 0
inventory: list[str] = field(default_factory=list)
detective: Optional[Detective] = None
relationships: dict[str, Relationship] = field(default_factory=dict)
relationships: dict[ICharacter, Relationship] = field(default_factory=dict)
frat: Frat = Frat.WOLVES
daddy_name: str = "Daddy"

Expand All @@ -47,6 +48,14 @@ def __hash__(self) -> int:
def profile_picture(self) -> str:
return self.profile_pictures[0]

@property
def girlfriends(self) -> list[ICharacter]:
return [
npc
for npc in self.relationships
if self.relationships[npc] == Relationship.GIRLFRIEND
]

# @property
# def fighter(self):
# return self._fighter
Expand Down

0 comments on commit eb68877

Please sign in to comment.