Skip to content

Instantly share code, notes, and snippets.

@justin-carver
Last active December 14, 2021 07:40
Show Gist options
  • Save justin-carver/974d4b5c8dd371198a6fba9a5c825cbf to your computer and use it in GitHub Desktop.
Save justin-carver/974d4b5c8dd371198a6fba9a5c825cbf to your computer and use it in GitHub Desktop.
Pre-Mysteria API Idea Written in Python
Barbarian
Bard
Cleric
Druid
Fighter
Monk
Paladin
Ranger
Rogue
Sorcerer
Warlock
Wizard
Warden
Crusader
Blackguard
Dragon Knight
Gladiator
Warlord
Mimic
Necromancer
Illusionist
Shaman
Bandit
Witch Doctor
Battle Priest
Templar
Beast Master
Cantor
Skald
Alchemist
Gunslinger
Gun Mage
Psychic
Scholar
import random
import world
import time
from file import CustomFile
global entity_id, god_count, creature_count, legendary_creature_count, god_count
legendary_creature_count = 0
god_count = 0
class creature:
global psychopathy
global isCreatureLegendary
global doesCreatureNemesis
global creature_name_prefix
creature_name_prefix = ['God']
master_creature_list = CustomFile.readFileToObj("races.txt")
master_class_list = CustomFile.readFileToObj("class_names.txt")
master_generic_name_list = CustomFile.readFileToObj("names.txt")
assigned_chunk = None
# some creatures can now spawn psychopathicor with mental disorders.
## possibly replace arguments with **kwargs
def __init__(self, entityid, creatureName, creatureType, creatureClass,
creatureLevel, verbose):
self.name = creatureName
self.type_ = creatureType
self.level = creatureLevel
self.entity_id = entityid
self.cclass = creatureClass
isCreatureLegendary = False
psychopathy = False
doesCreatureNemesis = False
# Very random chance to become deity.
if random.randint(0, 5000) <= 1:
print('Something very strange is happening...')
time.sleep(2)
print('White light swirls around', self.name, '!')
time.sleep(2)
self.name = creature_name_prefix[0] + " " + self.name
print(self.name, 'has become a diety! All hail', self.name, '!')
time.sleep(2)
global god_count
god_count += 1
if random.randint(0, 100) <= 1:
# Less than 5 percent chance. Make creature psychopath.
psychopathy = True
if random.randint(0, 500) <= 5:
global legendary_creature_count
legendary_creature_count += 1
isCreatureLegendary = True
if random.randint(0, 500) <= 1:
doesCreatureNemesis = True
if verbose:
if isCreatureLegendary:
print('Legendary', end=" ")
print('Creature: ', self.name, 'the', self.cclass, self.type_,
'creature, level', self.level, 'has been spawned.')
if psychopathy and verbose:
print('\t-> Creature is psychopathic.')
if doesCreatureNemesis:
# Creature has claimed a nemesis!
random_nemesis = world._master_entity_list[random.randrange(
0, len(world._master_entity_list))]
print('LOG:\t', self.name, 'has announced', random_nemesis.name,
'as their nemesis!')
def getLegendaryCreatureCount():
return legendary_creature_count
def getGodCount():
return god_count
def fightEntity(self, entityobj):
# creature will begin to fight this entity!
print(self.name, 'will begin to fight', entityobj.name, '!')
import random
import file
content = None
class CustomFile:
@staticmethod
def readFileToObj(fname):
with open(fname) as f:
global content
content = f.readlines()
content = [x.strip() for x in content]
return content
import world
import playerInput
from player import Player
global playerobj
def cartographerEnterPoint():
world.__generateWorld(True)
world.__populateWorld(1000, True)
playerobj = Player(playerName="Justin", playerLevel=1, playerMaxHealth=100, playerCurrentHealth=100, playerMaxMana=100, playerCurrentMana=100)
playerobj.createPlayer()
playerInput.passPlayerObject(playerobj)
#world.__simulateHistory(False)
cartographerEnterPoint()
playerInput.primitivePlayerInput()
Aseir
Haseid
Kheed
Zasheir
Fodel
Glar
Grigor
Igan
Ivor
Kosef
Mival
Pavel
Sergor
Darvin
Dorn
Evendur
Gorstag
Helm
Morn
Randal
Stedd
Ander
Blath
Bran
Frath
Geth
Lander
Luth
Malcer
Stor
Taman
Bareris
Kethoth
Mumed
Urhur
Borivik
Faurgar
Jandar
Kanithar
Madislak
Ralmevik
Shaumar
Vladislak
Chen
Chi
Fai
Jiang
Jun
Lian
Long
Meng
Shan
Wen
Anton
Diero
Marcon
Pieron
Rimardo
Romero
Salazar
Umbero
# The ultimate player python file
import random
from file import CustomFile
class Player:
# Setting globals.
global playerName, playerClass, playerLevel, playerMaxHealth, playerCurrentHealth, playerMaxMana, playerCurrentMana
# Spawn the player. Give him all the basics of everything.
# We'll use kwargs with the player since there will be only one instance of the class, and they can be flexible.
def __init__(self, **kwargs):
self.playerName = kwargs.get("playerName")
self.playerClass = kwargs.get("playerClass")
self.playerLevel = kwargs.get("playerLevel")
self.playerMaxHealth = kwargs.get("playerMaxHealth")
self.playerCurrentHealth = kwargs.get("playerCurrentHealth")
self.playerMaxMana = kwargs.get("playerMaxMana")
self.playerCurrentMana = kwargs.get("playerCurrentMana")
def createPlayer(self):
# if the player doesn't choose a class.
player_classes = CustomFile.readFileToObj("class_names.txt")
if self.playerClass == None: self.playerClass = player_classes[random.randrange(0, len(player_classes))]
self.playerName = input('Creating character. What shall be your name?\n')
print(self.playerName, 'the human', self.playerClass, 'has been born. Long live the cause!')
import world
import os
from player import Player
# We need to pass the specific player object instance to this input class.
def passPlayerObject(object):
global passed_player_object
passed_player_object = object
def primitivePlayerInput():
playerInput = input("> ")
parsePlayerInput(playerInput)
def clearScreen():
print('\n' * 100)
def parsePlayerInput(plinput):
# all used commands must be put into this list to check later.
approved_commands = [
"region_count", "list_creature_regions", "simulate_history", "select",
"!", "clear", "cls", "help", "list_creature_details", "inventory"
]
# let's try something with multiple words.
split_plinput = plinput.split()
# fix case sensitivty
# saving the old variable.
pre_lower = plinput
plinput = plinput.lower()
##
# Start attempting to parse input.
##
if split_plinput[0] == "select":
if len(split_plinput) > 1:
# if theres something more than just the first world
# "If you select something, what do you want to do with it?"
# if split_plinput[1] is type(creature):
return
# help
if plinput == "help": print(", ".join(approved_commands))
# clear / cls, just push the screen up.
if plinput == "clear" or plinput == "cls": clearScreen()
# substring variable manipulation?
if plinput[:1] == "!":
temp_string = pre_lower[1:]
# !giveLevel - Gives player one level.
if temp_string == "giveLevel":
passed_player_object.playerLevel += 1
print(passed_player_object.playerName, 'has gained 1 level.')
print(passed_player_object.playerName, 'is now level', passed_player_object.playerLevel)
# !changePlayerName - Changes the players name.
elif temp_string == "changePlayerName":
passed_player_object.playerName = input('What would you like your new name to be?')
print('Light shines down from above. You feel like a new person. You are now', passed_player_object.playerName)
else:
print(
'The debug cmd does not currently exist. Remember, debug cmds are case sensitive.'
)
# now we're going to try to use some stuff.
if split_plinput[0] == "use":
# if split_plinput[1] is in passed_player_object.inventory:
if split_plinput[1] in range(2):
if split_plinput[1] == '1':
print('You drink the Elixer of Life.')
else:
print('You cannot use that item.')
# list_creature_details - Lists all creatures that have currently been generated in the world and lists their: name, level, type, and class.
if plinput == "inventory":
# Start to display inventory stuff.
# should we clear the screen?
# clearScreen()
print('You open up your Bag of Holding...')
print('|[ 1. Elixer of Life ]|', 'Drinking this potion gives the player 25 life points back instantly.')
print('|[ 2. Scroll of Protection ]|', 'Using an action to read the scroll encloses you in a invisible barrier that extends from you to form a 5-foot-radius, 10-foot-high cylinder.')
if plinput == "list_creature_details":
for creatureobj in world._master_entity_list:
print(creatureobj.name, 'the level', creatureobj.level, creatureobj.type_, creatureobj.cclass)
if plinput == "region_count":
print(world._chunks_population)
if plinput == "list_creature_regions":
for creatureobj in world._master_entity_list:
print(creatureobj.name, '[' + str(creatureobj.entity_id) + ']',
'is located in', creatureobj.assigned_chunk.chunk_name)
if plinput == "simulate_history":
world.__simulateHistory(True)
# If command does not exist.
if plinput not in approved_commands:
if split_plinput[0] not in approved_commands:
if plinput[:1] not in approved_commands:
print('Incorrect command.')
# We exit the function by recursion.
primitivePlayerInput()
Dragonborn
Dwarf
Eladrin
Elf
Half-Elf
Orc
Half-Orc
Halfing
Human
Tiefling
Undead
Bullman
Centaur
Changeling
Feral Tiefling
Aarakocra
Goliath
Golbin
Gnome
Demon
Hobgoblin
Angel
Kenku
Kobold
Lizardfolk
Foxfolk
Minotaur
Warforged
import random
from entity import creature
global world_map
global world_season
class worldChunk:
def __init__(self, chunkX, chunkY, chunkName):
self.chunk_x = chunkX
self.chunk_y = chunkY
self.chunk_name = chunkName
## world.py
# Hard-coded temporarily before getting file reading in.
_master_chunk_name_modifier = ['Ruins of']
_master_chunk_name_list = [
'Stallon\'s Reach', 'Kaz\'ad\'yol', 'Dur\'dum', 'Endesdroga', 'Saradum',
'Xerexella', 'Fort Sancticus', 'Emerging Fate', 'Stalwok'
]
_master_entity_list = []
_selected_chunk_names = []
world_map = []
def __generateWorld(verbose):
print('Preparing world for generation...')
# Anything you need to do prior, you better do it here.
print('Generating world using default world seed in project folder...')
# The world will consist of a small grid to start
# 0,0 | 1,0 | 2, 0
# 0,1 | 1,1 | 2, 1
# 0,2 | 1,2 | 2, 2
# We're going to genreate the world through a for loop. We know that our world will consist 9 small 'chunks'.
print('Grabbing world parameters...')
for chunk_idx in range(3):
for chunk_idy in range(3):
# Generate random chunkname.
temp_rnd_chunkname = _master_chunk_name_list[random.randrange(
0, len(_master_chunk_name_list))]
# if the name is inside the selected names array, run a while loop.
if temp_rnd_chunkname in _selected_chunk_names:
if verbose: print('[v:] Name already taken! Trying another name...')
# while the generated name is in the array, look for another name.
while temp_rnd_chunkname in _selected_chunk_names:
temp_rnd_chunkname = _master_chunk_name_list[
random.randrange(0, len(_master_chunk_name_list))]
# Create the chunk with the random, non-taken name.
chunkObj = worldChunk(chunk_idx, chunk_idy, temp_rnd_chunkname)
# Add that chunk to the world and chunk name to the list.
world_map.append(chunkObj)
_selected_chunk_names.append(temp_rnd_chunkname)
print('Creating chunk \'' + chunkObj.chunk_name +
'\' at location: (' + str(chunkObj.chunk_x) + ', ' +
str(chunkObj.chunk_y) + ').')
# Initialize the _chunk_population variable by creating a dynamic dictionary.
# This will be used during __populateWorld as a simple tally.
global _chunks_population
_chunks_population = {}
for chunks in world_map:
_chunks_population[chunks.chunk_name] = 0
print('COMPLETE: World generation has completed with no errors.')
def __populateWorld(populationSize, verbose):
# Defaults
total_population_size = populationSize
print('Attempting to populate the world...')
print('Using default pop size:', total_population_size)
for entity in range(total_population_size):
# create and spawn a creature with: name, creatureType, creatureClass, and Level.
_master_entity_list.append(
creature(
entity, creature.master_generic_name_list[random.randrange(
0, len(creature.master_generic_name_list))],
creature.master_creature_list[random.randrange(
0, len(creature.master_creature_list))],
creature.master_class_list[random.randrange(
0, len(creature.master_class_list))], 1, False))
# assign creature to region.
_master_entity_list[entity].assigned_chunk = world_map[
random.randrange(0, len(world_map))]
# increase population of that region.
_chunks_population[_master_entity_list[entity].assigned_chunk.
chunk_name] += 1
print('World has been populated.', populationSize,
'total have been spawned. Including',
creature.getLegendaryCreatureCount(), 'legendary creatures and',
creature.getGodCount(), 'godly deities.')
if creature.getGodCount() == 0: print('The world is currently Godless.')
# verbose stuff.
if verbose: print("[v:]", _chunks_population)
def __simulateHistory(verbose):
# Simulating minor histroic events.
creature.fightEntity(
_master_entity_list[0],
entityobj=_master_entity_list[random.randrange(
0, len(_master_entity_list))])
# iterate through list, and give everyone a turn to 'do something'.
for entity in _master_entity_list:
# give them an option to choose from
entity_actions = ["wander", "fight", "idle", "converse"]
random_action = entity_actions[random.randrange(
0, len(entity_actions))]
if verbose: print("[v:]", entity.name, "has decided to", random_action)
if random_action == "wander":
print(entity.name, 'begins to wander around.')
# perform move function to move to another zone after a couple of wanders
if random_action == "fight":
print(
entity.name, 'has started fighting with',
_master_entity_list[random.randrange(
0, len(_master_entity_list))].name + '!')
# perform move function to move to another zone after a couple of wanders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment