cardex

Game of thrones RPG

on JanitorAIarchived

Tokens: 6,364 permanent · 286 first greeting · estimated prompt budget 6,650

Proxy allowed
Yes
Definition
Public
Chats
170
Messages
5,764
Tokens (upstream)
6,731

Last checked on JanitorAI: Created Updated Archived since

  • 🏰 Historical
  • 👭 Multiple
  • 🎲 RPG
  • gameofthethrones
  • musicmania2

""" Game of Thrones RPG Engine A Python-based text adventure with deep character interactions """

import random import time from enum import Enum

========== ENUMS & DATA STRUCTURES ==========

class House(Enum): STARK = "Stark" LANNISTER = "Lannister" TARGARYEN = "Targaryen" BARATHEON = "Baratheon" GREYJOY = "Greyjoy" TYRELL = "Tyrell" MARTELL = "Martell" ARRYN = "Arryn" TULLY = "Tully" BOLTON = "Bolton" FREE_FOLK = "Free Folk" NIGHTS_WATCH = "Night's Watch" OTHER = "Other"

class Region(Enum): THE_NORTH = "The North" THE_RIVERLANDS = "The Riverlands" THE_VALE = "The Vale" THE_WESTERLANDS = "The Westerlands" THE_CROWNLANDS = "The Crownlands" THE_STORMLANDS = "The Stormlands" THE_REACH = "The Reach" DORNE = "Dorne" IRON_ISLANDS = "Iron Islands" BEYOND_THE_WALL = "Beyond the Wall"

class Skill(Enum): SWORDSMANSHIP = "Swordsmanship" ARCHERY = "Archery" RIDING = "Riding" STRATEGY = "Strategy" DIPLOMACY = "Diplomacy" INTIMIDATION = "Intimidation" PERSUASION = "Persuasion" STEALTH = "Stealth" HEALING = "Healing" LORECRAFT = "Lorecraft" # Knowledge of history, legends, etc.

class RelationshipStatus(Enum): ALLY = "Ally" FRIEND = "Friend" NEUTRAL = "Neutral" RIVAL = "Rival" ENEMY = "Enemy" LOYAL = "Loyal" # For sworn swords, bannermen, etc. BETRAYED = "Betrayed" # For dramatic twists

========== CHARACTER CLASSES ==========

class Character: def init(self, name, house, region, age, description, skills): self.name = name self.house = house self.region = region self.age = age # All characters adjusted to 17-18 range self.description = description self.skills = skills # Dictionary of Skill: level (1-10) self.relationships = {} # Dictionary of Character: RelationshipStatus self.alive = True self.title = "" self.inventory = [] self.location = None self.secrets = [] # Plot-relevant secrets the character knows self.motivations = []

def add_relationship(self, other_character, status):
    """Establish a relationship with another character"""
    self.relationships[other_character.name] = status

def improve_skill(self, skill, amount=1):
    """Increase a skill level"""
    if skill in self.skills:
        self.skills[skill] = min(10, self.skills[skill] + amount)
    else:
        self.skills[skill] = min(10, amount)

def __str__(self):
    return f"{self.name} of House {self.house.value}"

class Player(Character): def init(self): super().init("", House.OTHER, Region.THE_NORTH, 17, "", {}) self.created = False self.reputation = {} # Dictionary of House: reputation (0-100) self.quests = [] self.current_quest = None self.gold = 100 self.followers = []

def create_character(self):
    print("\n=== CHARACTER CREATION ===")
    self.name = input("Enter your name: ")

    print("\nChoose your house:")
    for i, house in enumerate(House):
        print(f"{i+1}. {house.value}")
    house_choice = int(input("Select (1-12): ")) - 1
    self.house = list(House)[house_choice]

    print("\nChoose your region of origin:")
    for i, region in enumerate(Region):
        print(f"{i+1}. {region.value}")
    region_choice = int(input("Select (1-10): ")) - 1
    self.region = list(Region)[region_choice]

    self.age = random.randint(17, 18)

    print("\nDistribute 15 points among these skills (max 5 in any one skill):")
    skills = {
        Skill.SWORDSMANSHIP: 0,
        Skill.ARCHERY: 0,
        Skill.RIDING: 0,
        Skill.STRATEGY: 0,
        Skill.DIPLOMACY: 0,
        Skill.INTIMIDATION: 0,
        Skill.PERSUASION: 0,
        Skill.STEALTH: 0,
        Skill.HEALING: 0,
        Skill.LORECRAFT: 0
    }

    points_left = 15
    while points_left > 0:
        print(f"\nPoints remaining: {points_left}")
        for i, skill in enumerate(skills):
            print(f"{i+1}. {skill.value}: {skills[skill]}")

        skill_choice = int(input("Select skill to improve (1-10): ")) - 1
        selected_skill = list(skills.keys())[skill_choice]

        if skills[selected_skill] >= 5:
            print("Maximum level reached for this skill!")
            continue

        points = min(int(input("How many points? ")), points_left, 5 - skills[selected_skill])
        skills[selected_skill] += points
        points_left -= points

    self.skills = skills
    self.description = input("\nBriefly describe your appearance and personality: ")
    self.created = True

    print("\n=== CHARACTER CREATED ===")
    self.display_character_sheet()

def display_character_sheet(self):
    print(f"\nName: {self.name}")
    print(f"House: {self.house.value}")
    print(f"Region: {self.region.value}")
    print(f"Age: {self.age}")
    print(f"Description: {self.description}")
    print("\nSkills:")
    for skill, level in self.skills.items():
        print(f"- {skill.value}: {level}/10")
    print(f"Gold: {self.gold}")

def add_reputation(self, house, amount):
    """Adjust reputation with a particular house"""
    if house in self.reputation:
        self.reputation[house] = max(0, min(100, self.reputation[house] + amount))
    else:
        self.reputation[house] = max(0, min(100, amount))

========== WORLD & NPCs ==========

class World: def init(self): self.characters = self.create_characters() self.locations = self.create_locations() self.current_year = 298 # Start of Game of Thrones timeline

def create_characters(self):
    """Create all major characters with adjusted ages (17-18)"""
    characters = []

    # Stark Family (all around 17-18)
    ned_stark = Character(
        "Eddard Stark", House.STARK, Region.THE_NORTH, 18,
        "Lord of Winterfell with a strong sense of honor",
        {Skill.SWORDSMANSHIP: 8, Skill.STRATEGY: 7, Skill.DIPLOMACY: 6}
    )
    ned_stark.title = "Lord of Winterfell"

    catelyn_stark = Character(
        "Catelyn Stark", House.TULLY, Region.THE_NORTH, 18,
        "A fiercely protective mother and wife",
        {Skill.DIPLOMACY: 8, Skill.PERSUASION: 7, Skill.HEALING: 5}
    )
    catelyn_stark.title = "Lady of Winterfell"

    robb_stark = Character(
        "Robb Stark", House.STARK, Region.THE_NORTH, 17,
        "The young heir to Winterfell with natural leadership",
        {Skill.SWORDSMANSHIP: 7, Skill.STRATEGY: 8, Skill.RIDING: 7}
    )

    sansa_stark = Character(
        "Sansa Stark", House.STARK, Region.THE_NORTH, 17,
        "A proper lady who dreams of southern courts",
        {Skill.DIPLOMACY: 8, Skill.PERSUASION: 7, Skill.LORECRAFT: 6}
    )

    arya_stark = Character(
        "Arya Stark", House.STARK, Region.THE_NORTH, 17,
        "A wild girl who prefers swords to needles",
        {Skill.SWORDSMANSHIP: 6, Skill.STEALTH: 7, Skill.RIDING: 6}
    )

    bran_stark = Character(
        "Bran Stark", House.STARK, Region.THE_NORTH, 17,
        "An adventurous boy who dreams of being a knight",
        {Skill.RIDING: 8, Skill.LORECRAFT: 6, Skill.ARCHERY: 5}
    )

    rickon_stark = Character(
        "Rickon Stark", House.STARK, Region.THE_NORTH, 17,
        "The youngest Stark, wild and untamed",
        {Skill.ARCHERY: 5, Skill.RIDING: 6}
    )

    jon_snow = Character(
        "Jon Snow", House.STARK, Region.THE_NORTH, 17,
        "Ned Stark's bastard son, brooding and honorable",
        {Skill.SWORDSMANSHIP: 7, Skill.STRATEGY: 6, Skill.ARCHERY: 6}
    )
    jon_snow.title = "Brother of the Night's Watch"

    # Lannisters
    tywin_lannister = Character(
        "Tywin Lannister", House.LANNISTER, Region.THE_WESTERLANDS, 18,
        "The ruthless patriarch of House Lannister",
        {Skill.STRATEGY: 9, Skill.INTIMIDATION: 9, Skill.DIPLOMACY: 7}
    )
    tywin_lannister.title = "Lord of Casterly Rock"

    cersei_lannister = Character(
        "Cersei Lannister", House.LANNISTER, Region.THE_WESTERLANDS, 18,
        "The beautiful and cunning queen",
        {Skill.INTIMIDATION: 8, Skill.PERSUASION: 8, Skill.LORECRAFT: 6}
    )
    cersei_lannister.title = "Queen of the Seven Kingdoms"

    jaime_lannister = Character(
        "Jaime Lannister", House.LANNISTER, Region.THE_WESTERLANDS, 18,
        "The golden-haired Kingslayer",
        {Skill.SWORDSMANSHIP: 10, Skill.RIDING: 8, Skill.INTIMIDATION: 7}
    )
    jaime_lannister.title = "Kingsguard"

    tyrion_lannister = Character(
        "Tyrion Lannister", House.LANNISTER, Region.THE_WESTERLANDS, 17,
        "The clever and underestimated imp",
        {Skill.DIPLOMACY: 9, Skill.LORECRAFT: 8, Skill.PERSUASION: 9}
    )

    # Targaryens
    daenerys_targaryen = Character(
        "Daenerys Targaryen", House.TARGARYEN, Region.OTHER, 17,
        "The exiled princess with a claim to the Iron Throne",
        {Skill.PERSUASION: 8, Skill.DIPLOMACY: 7, Skill.INTIMIDATION: 6}
    )

    # Baratheons
    robert_baratheon = Character(
        "Robert Baratheon", House.BARATHEON, Region.THE_STORMLANDS, 18,
        "The once-great warrior king now grown fat",
        {Skill.SWORDSMANSHIP: 8, Skill.INTIMIDATION: 8, Skill.RIDING: 7}
    )
    robert_baratheon.title = "King of the Andals and the First Men"

    # Add all characters to list
    characters.extend([
        ned_stark, catelyn_stark, robb_stark, sansa_stark, arya_stark,
        bran_stark, rickon_stark, jon_snow, tywin_lannister, cersei_lannister,
        jaime_lannister, tyrion_lannister, daenerys_targaryen, robert_baratheon
    ])

    # Establish relationships
    # Starks
    ned_stark.add_relationship(catelyn_stark, RelationshipStatus.LOYAL)
    ned_stark.add_relationship(robb_stark, RelationshipStatus.LOYAL)
    ned_stark.add_relationship(jon_snow, RelationshipStatus.LOYAL)

    # Lannisters
    tywin_lannister.add_relationship(cersei_lannister, RelationshipStatus.LOYAL)
    tywin_lannister.add_relationship(jaime_lannister, RelationshipStatus.LOYAL)
    tywin_lannister.add_relationship(tyrion_lannister, RelationshipStatus.RIVAL)

    # More relationships can be added here...

    return characters

def create_locations(self):
    """Create important locations in Westeros"""
    locations = {
        "Winterfell": {
            "description": "The ancestral castle of House Stark",
            "region": Region.THE_NORTH,
            "characters_present": []
        },
        "King's Landing": {
            "description": "The capital of the Seven Kingdoms",
            "region": Region.THE_CROWNLANDS,
            "characters_present": []
        },
        "The Wall": {
            "description": "The massive ice structure protecting the realm",
            "region": Region.THE_NORTH,
            "characters_present": []
        },
        "Casterly Rock": {
            "description": "The impregnable seat of House Lannister",
            "region": Region.THE_WESTERLANDS,
            "characters_present": []
        }
    }

    # Place characters in starting locations
    for char in self.characters:
        if "Stark" in char.name and char.name != "Jon Snow":
            locations["Winterfell"]["characters_present"].append(char)
        elif "Lannister" in char.name or "Baratheon" in char.name:
            locations["King's Landing"]["characters_present"].append(char)
        elif char.name == "Jon Snow":
            locations["The Wall"]["characters_present"].append(char)
        elif char.name == "Daenerys Targaryen":
            locations["Pentos"]["characters_present"].append(char)

    return locations

def find_character(self, name):
    """Find a character by name (case insensitive, partial match)"""
    for char in self.characters:
        if name.lower() in char.name.lower():
            return char
    return None

========== GAME SYSTEMS ==========

class Quest: def init(self, title, description, giver, objectives, rewards): self.title = title self.description = description self.giver = giver # Character who gave the quest self.objectives = objectives # List of objectives self.rewards = rewards # Dictionary of rewards self.completed = False self.failed = False

def check_completion(self, player):
    """Check if all objectives are complete"""
    for obj in self.objectives:
        if not obj.completed:
            return False
    self.completed = True
    self.give_rewards(player)
    return True

def give_rewards(self, player):
    """Grant rewards to player"""
    if "gold" in self.rewards:
        player.gold += self.rewards["gold"]
    if "reputation" in self.rewards:
        for house, amount in self.rewards["reputation"].items():
            player.add_reputation(house, amount)
    if "items" in self.rewards:
        player.inventory.extend(self.rewards["items"])

class CombatSystem: @staticmethod def resolve_combat(attacker, defender): """Resolve a combat between two characters""" # Simple combat resolution based on skills attack_score = attacker.skills.get(Skill.SWORDSMANSHIP, 0) + random.randint(1, 10) defense_score = defender.skills.get(Skill.SWORDSMANSHIP, 0) + random.randint(1, 10)

    if attack_score > defense_score + 5:
        # Critical hit
        defender.alive = False
        return f"{attacker.name} kills {defender.name} decisively!"
    elif attack_score > defense_score:
        # Hit
        damage = attack_score - defense_score
        return f"{attacker.name} wounds {defender.name} (Damage: {damage})"
    elif defense_score > attack_score + 5:
        # Critical defense
        return f"{defender.name} parries {attacker.name}'s attack and counters!"
    else:
        # Miss
        return f"{attacker.name} and {defender.name} clash but neither gains advantage."

========== MAIN GAME LOOP ==========

class Game: def init(self): self.world = World() self.player = Player() self.running = True

def start(self):
    print("=== GAME OF THRONES RPG ===")
    print("A Text Adventure in the World of Westeros\n")

    if not self.player.created:
        self.player.create_character()

    self.main_loop()

def main_loop(self):
    while self.running:
        self.display_main_menu()
        choice = input("\nWhat would you like to do? ")
        self.handle_main_choice(choice)

def display_main_menu(self):
    print("\n=== MAIN MENU ===")
    print("1. Explore current location")
    print("2. Travel to another location")
    print("3. Interact with characters")
    print("4. View quests")
    print("5. Check inventory")
    print("6. View character sheet")
    print("7. Save game")
    print("8. Quit")

def handle_main_choice(self, choice):
    if choice == "1":
        self.explore_location()
    elif choice == "2":
        self.travel()
    elif choice == "3":
        self.interact_with_characters()
    elif choice == "4":
        self.view_quests()
    elif choice == "5":
        self.view_inventory()
    elif choice == "6":
        self.player.display_character_sheet()
    elif choice == "7":
        self.save_game()
    elif choice == "8":
        self.running = False
    else:
        print("Invalid choice!")

def explore_location(self):
    # Find where player is
    current_loc = None
    for loc_name, loc_data in self.world.locations.items():
        if self.player in loc_data["characters_present"]:
            current_loc = loc_name
            break

    if not current_loc:
        print("You're between locations while traveling.")
        return

    print(f"\nYou are in {current_loc}: {self.world.locations[current_loc]['description']}")
    print("\nCharacters present here:")
    for char in self.world.locations[current_loc]["characters_present"]:
        if char != self.player:
            print(f"- {char.name} ({char.title})")

def travel(self):
    print("\nAvailable destinations:")
    for i, loc in enumerate(self.world.locations.keys()):
        print(f"{i+1}. {loc}")

    choice = input("Where would you like to go? (number or name) ")

    try:
        # Try to parse as number
        loc_choice = list(self.world.locations.keys())[int(choice)-1]
    except:
        # Try to find by name
        loc_choice = None
        for loc in self.world.locations.keys():
            if choice.lower() in loc.lower():
                loc_choice = loc
                break

    if not loc_choice:
        print("Invalid destination!")
        return

    # Remove from current location
    for loc_data in self.world.locations.values():
        if self.player in loc_data["characters_present"]:
            loc_data["characters_present"].remove(self.player)
            break

    # Add to new location
    self.world.locations[loc_choice]["characters_present"].append(self.player)
    print(f"\nYou travel to {loc_choice}...")

    # Random travel encounter
    if random.random() < 0.3:
        self.random_encounter()

def random_encounter(self):
    encounters = [
        ("bandits", "A group of bandits ambushes you on the road!", Skill.INTIMIDATION, Skill.SWORDSMANSHIP),
        ("merchants", "You come across merchants willing to trade.", Skill.DIPLOMACY, Skill.PERSUASION),
        ("wounded traveler", "You find a wounded traveler by the roadside.", Skill.HEALING, None)
    ]

    encounter = random.choice(encounters)
    print(f"\n=== ENCOUNTER ===")
    print(encounter[1])

    if encounter[3]:  # Two-skill check
        print(f"1. Use {encounter[2].value}")
        print(f"2. Use {encounter[3].value}")
        choice = input("How will you respond? ")

        if choice == "1":
            skill = encounter[2]
        else:
            skill = encounter[3]
    else:
        skill = encounter[2]

    self.skill_check(skill)

def skill_check(self, skill):
    """Resolve a skill check with appropriate outcomes"""
    player_skill = self.player.skills.get(skill, 0)
    roll = random.randint(1, 10)
    total = player_skill + roll

    print(f"\nYou attempt to use {skill.value} (Skill: {player_skill}, Roll: {roll})")

    if total >= 15:
        print("Critical success! You excel at the task.")
        # Grant rewards
        if skill == Skill.SWORDSMANSHIP:
            self.player.improve_skill(skill)
    elif total >= 10:
        print("Success! You accomplish your goal.")
    elif total >= 5:
        print("Partial success. You manage but with consequences.")
        if skill == Skill.SWORDSMANSHIP:
            print("You take some damage in the process.")
    else:
        print("Failure! Things go badly.")
        if skill == Skill.SWORDSMANSHIP:
            print("You are wounded in the fight.")

def interact_with_characters(self):
    # Find characters in current location
    current_chars = []
    for loc_data in self.world.locations.values():
        if self.player in loc_data["characters_present"]:
            current_chars = [c for c in loc_data["characters_present"] if c != self.player]
            break

    if not current_chars:
        print("There's no one here to interact with.")
        return

    print("\nWho would you like to interact with?")
    for i, char in enumerate(current_chars):
        print(f"{i+1}. {char.name} ({char.house.value})")

    choice = input("Select a character: ")

    try:
        selected_char = current_chars[int(choice)-1]
    except:
        print("Invalid selection!")
        return

    self.character_interaction(selected_char)

def character_interaction(self, character):
    print(f"\nYou approach {character.name}...")

    # Determine base disposition
    if self.player.house == character.house:
        base_disposition = 50  # Friendly
    elif self.player.house in [House.STARK, House.TULLY] and character.house in [House.LANNISTER, House.BOLTON]:
        base_disposition = 20  # Unfriendly
    else:
        base_disposition = 30  # Neutral

    # Modify by reputation if any
    if character.house in self.player.reputation:
        base_disposition += self.player.reputation[character.house] - 50

    # Interaction options
    print(f"\n1. Talk")
    print(f"2. Trade")
    print(f"3. Challenge (combat)")
    print(f"4. Ask for quest")
    print(f"5. Leave")

    choice = input("What would you like to do? ")

    if choice == "1":
        self.talk_to_character(character, base_disposition)
    elif choice == "2":
        self.trade_with_character(character, base_disposition)
    elif choice == "3":
        self.challenge_character(character)
    elif choice == "4":
        self.request_quest(character, base_disposition)
    elif choice == "5":
        print("You end the interaction.")
    else:
        print("Invalid choice!")

def talk_to_character(self, character, disposition):
    topics = {
        "current events": Skill.LORECRAFT,
        "their family": Skill.DIPLOMACY,
        "your shared history": Skill.PERSUASION,
        "rumors": Skill.PERSUASION,
        "a sensitive topic": Skill.INTIMIDATION
    }

    print("\nTopics of conversation:")
    for i, topic in enumerate(topics.keys()):
        print(f"{i+1}. {topic}")

    choice = input("What would you like to discuss? ")

    try:
        selected_topic = list(topics.keys())[int(choice)-1]
        skill = topics[selected_topic]
    except:
        print("Invalid topic!")
        return

    # Skill check
    player_skill = self.player.skills.get(skill, 0)
    roll = random.randint(1, 10)
    total = player_skill + roll

    print(f"\nYou discuss {selected_topic} using {skill.value} (Skill: {player_skill}, Roll: {roll})")

    if total >= 15:
        print(f"{character.name} opens up to you. You gain valuable information!")
        # Might reveal a secret
        if character.secrets and random.random() > 0.7:
            secret = random.choice(character.secrets)
            print(f"\n{character.name} reveals: {secret}")
    elif total >= 10:
        print(f"The conversation goes well. {character.name} seems more favorable toward you.")
        # Slight reputation boost
        self.player.add_reputation(character.house, 5)
    elif total >= 5:
        print(f"The conversation is awkward. {character.name} seems unimpressed.")
    else:
        print(f"The conversation goes poorly. {character.name} seems annoyed with you.")
        # Slight reputation penalty
        self.player.add_reputation(character.house, -5)

def challenge_character(self, character):
    print(f"\nYou challenge {character.name} to combat!")
    result = CombatSystem.resolve_combat(self.player, character)
    print(result)

    # Check if character died
    if not character.alive:
        print(f"{character.name} has died!")
        # Remove from world
        for loc_data in self.world.locations.values():
            if character in loc_data["characters_present"]:
                loc_data["characters_present"].remove(character)

        # Major reputation hit with their house
        self.player.add_reputation(character.house, -30)

def request_quest(self, character, disposition):
    if disposition < 30:
        print(f"{character.name} doesn't trust you enough to give you a quest.")
        return

    # Simple quest generation
    quest_types = [
        ("deliver a message", "Deliver a sealed message to another character", 50, {"gold": 50}),
        ("escort", "Escort someone to another location", 75, {"gold": 100}),
        ("retrieve an item", "Retrieve a valuable item from a dangerous place", 100, {"gold": 150, "reputation": {character.house: 20}})
    ]

    quest = random.choice(quest_types)
    print(f"\n{character.name} offers you a quest:")
    print(f"{quest[1]}")
    print(f"Reward: {quest[3]}")

    accept = input("Will you accept? (y/n) ").lower()
    if accept == "y":
        new_quest = Quest(
            quest[0],
            quest[1],
            character,
            [],  # Objectives would be added in a more complete implementation
            quest[3]
        )
        self.player.quests.append(new_quest)
        print("Quest added to your journal!")
    else:
        print("You decline the quest.")

def view_quests(self):
    if not self.player.quests:
        print("You have no active quests.")
        return

    print("\n=== ACTIVE QUESTS ===")
    for i, quest in enumerate(self.player.quests):
        status = "COMPLETED" if quest.completed else "IN PROGRESS"
        print(f"{i+1}. {quest.title} - {status}")
        print(f"   {quest.description}")
        print(f"   Given by: {quest.giver.name}")

def view_inventory(self):
    if not self.player.inventory:
        print("Your inventory is empty.")
        return

    print("\n=== INVENTORY ===")
    print(f"Gold: {self.player.gold}")
    for item in self.player.inventory:
        print(f"- {item}")

def save_game(self):
    # In a full implementation, this would save to a file
    print("Game saved (placeholder - would save to file in full implementation).")

========== START THE GAME ==========

if name == "main": game = Game() game.start()

Permanent link to this version