1
Fork 0
mirror of https://github.com/Steffo99/royalspells.git synced 2024-11-25 01:14:20 +00:00

First commit

This commit is contained in:
Steffo 2019-03-25 12:21:59 +01:00
commit 59f34c4591
5 changed files with 209 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.idea/
__pycache__
venv/

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# `royalspells`
A package to procedurally generate useless spells!

3
royalspells/__init__.py Normal file
View file

@ -0,0 +1,3 @@
from .main import SpellType, DamageComponent, HealingComponent, StatsComponent, StatusEffectComponent, Spell
__all__ = ["SpellType", "DamageComponent", "HealingComponent", "StatsComponent", "StatusEffectComponent", "Spell"]

176
royalspells/main.py Normal file
View file

@ -0,0 +1,176 @@
import random
import math
import enum
class SpellType(enum.Flag):
DAMAGING = enum.auto()
HEALING = enum.auto()
STATS = enum.auto()
STATUS_EFFECT = enum.auto()
class DamageComponent:
dice_type_distribution = ([4] * 7) + \
([6] * 12) + \
([8] * 32) + \
([10] * 30) + \
([12] * 12) + \
([20] * 6) + \
([100] * 1)
all_damage_types = ["da fuoco", "da freddo", "elettrici", "sonici", "necrotici", "magici",
"da acido", "divini", "nucleari", "psichici", "fisici", "puri", "da taglio",
"da perforazione", "da impatto", "da caduta", "gelato", "onnipotenti", "oscuri",
"di luce", "da velocità", "da cactus", "dannosi", "da radiazione",
"tuamammici", "da maledizione", "pesanti", "leggeri", "immaginari", "da laser",
"da neutrini", "galattici", "cerebrali", "ritardati", "ritardanti", "morali", "materiali",
"energetici", "esplosivi", "energetici", "finanziari", "radianti", "sonori", "spaggiaritici",
"interiori", "endocrini", "invisibili", "inesistenti", "eccellenti", "bosonici",
"gellificanti", "terminali"]
repeat_distribution = ([1] * 8) + \
([2] * 1) + \
([3] * 1)
damage_types_distribution = ([1] * 6) + \
([2] * 3) + \
([3] * 1)
def __init__(self):
# ENSURE THE SEED IS ALREADY SET WHEN CREATING THIS COMPONENT!!!
self.dice_number = random.randrange(1, 21)
self.dice_type = random.sample(self.dice_type_distribution, 1)[0]
self.constant = random.randrange(math.floor(-self.dice_type / 4), math.ceil(self.dice_type / 4) + 1)
self.miss_chance = random.randrange(50, 101)
self.repeat = random.sample(self.repeat_distribution, 1)[0]
self.damage_types_qty = random.sample(self.damage_types_distribution, 1)[0]
self.damage_types = random.sample(self.all_damage_types, self.damage_types_qty)
def __repr__(self):
return f"<DamageComponent>"
@property
def avg(self):
return (self.dice_number * (self.dice_type + 1) / 2) + self.constant
class HealingComponent:
dice_type_distribution = ([4] * 12) + \
([6] * 38) + \
([8] * 30) + \
([10] * 12) + \
([12] * 6) + \
([20] * 1) + \
([100] * 1)
def __init__(self):
# ENSURE THE SEED IS ALREADY SET WHEN CREATING THIS COMPONENT!!!
self.dice_number = random.randrange(1, 11)
self.dice_type = random.sample(self.dice_type_distribution, 1)[0]
self.constant = random.randrange(math.floor(-self.dice_type / 4), math.ceil(self.dice_type / 4) + 1)
def __repr__(self):
return f"<HealingComponent>"
@property
def avg(self):
return (self.dice_number * (self.dice_type + 1) / 2) + self.constant
class StatsComponent:
all_stats = ["Attacco", "Difesa", "Velocità", "Elusione", "Tenacia", "Rubavita",
"Vampirismo", "Forza", "Destrezza", "Costituzione", "Intelligenza",
"Saggezza", "Carisma", "Attacco Speciale", "Difesa Speciale",
"Eccellenza", "Immaginazione", "Cromosomi", "Timidezza", "Sonno",
"Elasticità", "Peso", "Sanità", "Appetito", "Fortuna", "Percezione",
"Determinazione"]
change_distribution = (["--"] * 1) + \
(["-"] * 2) + \
(["+"] * 2) + \
(["++"] * 1)
multistat_distribution = ([1] * 16) + \
([2] * 8) + \
([3] * 4) + \
([5] * 2) + \
([8] * 1)
def __init__(self):
# ENSURE THE SEED IS ALREADY SET WHEN CREATING THIS COMPONENT!!!
self.stat_changes = {}
self.stat_number = random.sample(self.multistat_distribution, 1)[0]
available_stats = self.all_stats.copy()
for _ in range(self.stat_number):
stat = random.sample(available_stats, 1)[0]
available_stats.remove(stat)
change = random.sample(self.change_distribution, 1)[0]
self.stat_changes[stat] = change
def __repr__(self):
return f"<StatsComponent>"
class StatusEffectComponent:
all_status_effects = ["Bruciatura", "Sanguinamento", "Paralisi", "Veleno",
"Congelamento", "Iperveleno", "Sonno", "Stordimento",
"Rallentamento", "Radicamento", "Rigenerazione", "Morte",
"Affaticamento", "Glitch", "Accecamento", "Silenzio",
"Esilio", "Invisibilità", "Rapidità", "Splendore"]
def __init__(self):
# ENSURE THE SEED IS ALREADY SET WHEN CREATING THIS COMPONENT!!!
self.chance = random.randrange(1, 101)
self.effect = random.sample(self.all_status_effects, 1)[0]
def __repr__(self):
return f"<StatusEffectComponent>"
class Spell:
version = "3.2"
damaging_spell_chance = 0.9
healing_spell_chance = 0.9 # If not a damaging spell
additional_stats_chance = 0.1 # In addition to the damage/healing
additional_status_effect_chance = 0.1 # In addition to the rest
def __init__(self, name: str):
seed = name.capitalize()
random.seed(seed)
# Spell name
self.name = seed
# Find the spell type
self.spell_type = SpellType(0)
if random.random() < self.damaging_spell_chance:
self.spell_type |= SpellType.DAMAGING
elif random.random() < self.healing_spell_chance:
self.spell_type |= SpellType.HEALING
if random.random() < self.additional_stats_chance:
self.spell_type |= SpellType.STATS
if random.random() < self.additional_status_effect_chance:
self.spell_type |= SpellType.STATUS_EFFECT
# Damaging spells
if self.spell_type & SpellType.DAMAGING:
self.damage_component = DamageComponent()
else:
self.damage_component = None
# Healing spells
if self.spell_type & SpellType.HEALING:
self.healing_component = HealingComponent()
else:
self.healing_component = None
# Stats spells
if self.spell_type & SpellType.STATS:
self.stats_component = StatsComponent()
else:
self.stats_component = None
# Status effect spells
if self.spell_type & SpellType.STATUS_EFFECT:
self.status_effect_component = StatusEffectComponent()
else:
self.status_effect_component = None
def __repr__(self):
return f"<Spell {self.name}>"

24
setup.py Normal file
View file

@ -0,0 +1,24 @@
import setuptools
with open("README.md", "r") as f:
long_description = f.read()
setuptools.setup(
name="royalspells",
version="3.2a1",
author="Stefano Pigozzi",
author_email="ste.pigozzi@gmail.com",
description="A package to procedurally generate useless spells!",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/Steffo99/royalspells",
packages=setuptools.find_packages(),
install_requires=[],
python_requires="~=3.6",
classifiers=[
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.6",
]
)