def check(self, char: Character, state: State): target = state.getChar(self.targetShort) if self.relationship == RelationCheck.ALLY and char.isAllyOf(target): return True if self.relationship == RelationCheck.ENEMY and not char.isAllyOf(target): return True return False
def getCharEmbed(char: Character, title="", description="", color=MISCORANGE) -> Embed: """ Initializes an Embed based on the given Character. Defaults to making the title the .string() of the Character, making the description empty, and making the color orange. """ embed = Embed(title=char.string() if not title else title, description=description, color=color) url = char.getPicture() if url: embed.set_thumbnail(url=url) return embed
def perform(self, char: Character, state: State): toAlly = state.getChar(self.charShort) if char.isAlone() and toAlly.isAlone(): alliance = [] char.joinAlliance(alliance) toAlly.joinAlliance(alliance) return f"allied with: {toAlly}" elif not char.isAlone(): alliance = char.getAlliance() toAlly.leaveAlliance() toAlly.joinAlliance(alliance) return f"alliance joined by: {toAlly}" elif not toAlly.isAlone(): alliance = toAlly.getAlliance() char.leaveAlliance() char.joinAlliance(alliance) return f"joined alliance of: {toAlly}"
def chooseFromEvents(self, char: Character, events: list[Event] = None, state: State = None) -> Optional[Event]: if not events: events = self.events.values() possibleEvents: list[Event] = [] totalChance = 0 defaultEvent: Optional[Event] = None for event in events: if event.prepare(char, self.tributes, state): if event.getChance() == 0: defaultEvent = event continue totalChance += event.getChance() possibleEvents.append(event) print(f"Character: {char}") print(f" alive:\t{char.alive}") print(f" age:\t{char.age}") print(f" location:\t{char.location}") print(f" status:\t{char.status}") print(f" tags:") [print(f" {tag}") for tag in char.tags] print(f" inventory:\t{char.items}") print(f" alliance:\t{char.alliance}") print(f"Possible events: {possibleEvents}") print(f"Default event: {defaultEvent}\n") if not possibleEvents: if defaultEvent: return defaultEvent else: raise Exception("No events matched when choosing from events") choice = randint(0, totalChance - 1) count = 0 for event in possibleEvents: if choice >= count and choice < (count + event.getChance()): return event count = count + event.getChance() if not char.isAlive(): return None raise Exception( f"Invalid choice when choosing from events ({choice} out of {totalChance})" )
def characterFromYaml(name: str, data: tuple[str, str]) -> Character: if not len(data) >= 2: raise LoadException( f"Couldn't load character {name}, too few elements in list ({data})" ) gender = data[0] if gender == "male": pronouns = ["he", "him", "his", "his", "himself"] elif gender == "female": pronouns = ["she", "her", "her", "hers", "herself"] elif gender == "nonbinary": pronouns = ["they", "them", "their", "theirs", "themself"] else: pronouns = data[0].split(" ") if len(pronouns) != 5: raise LoadException( f"Couldn't load Character {name}, there were not 5 values for the Character's pronouns ({pronouns})" ) imgSrc = data[1] return Character(name, imgSrc, pronouns)
def perform(self, char: Character, state: State): char.addTag(self.tag, self.tagAge) return f"added tag: {self.tag}"
def perform(self, char: Character, state: State): char.kill() return f"killed: {char.string()}"
def perform(self, char: Character, state: State): char.revive() return f"revived: {char.string()}"
def perform(self, char: Character, state: State): item = state.getItem(self.itemShort) char.takeItem(item) return f"consumed item: {item}"
def perform(self, char: Character, state: State): if self.zone: char.move(self.zone) else: char.moveRandom() return f"moved to zone: {char.getLocation().name}"
def perform(self, char: Character, state: State) -> str: char.clearStatus() return "cleared status"
def get(self, char: Character): return char.getItemByTags(self.itemTags)
def check(self, char: Character, state: State) -> bool: if self.state == AloneCheck.ALONE and char.isAlone(): return True if self.state == AloneCheck.ALLIED and not char.isAlone(): return True return False
def getVal(self, char: Character) -> int: return char.getTagAge(self.tag)
def check(self, char: Character, state: State) -> bool: if self.state == DistanceCheck.NEARBY: target = state.getChar(self.targetShort) return char.isNearby(target) else: return True
def check(self, char: Character, state: State) -> bool: if self.aState == AliveCheck.ALIVE: return char.isAlive() else: return not char.isAlive()
def check(self, char: Character, state: State) -> bool: return char.isIn(self.locName)
def check(self, char: Character, state: State) -> bool: return char.getItemByTags(self.itemTags) == False
def get(self, char: Character): return char.getItemByName(self.itemName)
def perform(self, char: Character, state: State): char.removeTag(self.tag) return f"removed tag: {self.tag}"
def check(self, char: Character, state: State) -> bool: if not char.hasStatus(self.status): return False super().check(char, state)
def perform(self, char: Character, state: State) -> str: char.makeStatus(self.status) return f"set status: {self.status}"
def perform(self, char: Character, state: State): char.leaveAlliance() return "left alliance"
def perform(self, char: Character, state: State): item = state.getItem(self.itemShort) char.copyAndGiveItem(item) return f"gave item: {item}"
def check(self, char: Character, state: State) -> bool: if not char.hasTag(self.tag): return True if self.flip else False res = super().check(char, state) return (not res) if self.flip else res
from game.Character import Character print("Mr Blin is an idiot!") lion = Character("Lion") print("Here is %s" % lion.name)
def getVal(self, char: Character) -> int: return char.getStatusAge()