add mutations rolls to character generator

This commit is contained in:
Greg Gauthier 2024-06-22 19:32:17 +01:00
parent 796aac4d80
commit 4dc0bb94b4
3 changed files with 296 additions and 1 deletions

63
app.py
View File

@ -2,6 +2,7 @@ from flask import Flask
from flask_restx import Api, Resource
from marshmallow import Schema, fields, validate
from models import dice_model, ability_model, hp_model, character_model
from mutations import Mutations
import random
app = Flask(__name__)
@ -131,6 +132,12 @@ class GenerateCharacter(Resource):
character_sheet['hp'] = roll_hp(chartype, assigned_abilities['constitution'])
character_sheet['gold'] = roll_dices(4, 4, False).get('result')
character_sheet['domar'] = roll_dices(2, 4, False).get('result')
if chartype == 'mutant':
character_sheet['mutations'] = (
roll_mutations(assigned_abilities['constitution'], assigned_abilities['intelligence'])
)
return character_sheet, 200
@ -205,6 +212,7 @@ def assign_ability_scores(scores, char_emphasis):
return ability_scores
def roll_hp(chartype, conscore):
if chartype == 'human':
geometry = 8
@ -212,5 +220,60 @@ def roll_hp(chartype, conscore):
geometry = 6
return roll_dices(conscore, geometry, False).get('result')
def roll_mutations(conscore, intscore):
"""
:param conscore: modifier for physical mutation determination
:param intscore: modifier for mental mutation determination
:return: table of mutations (in json form)
"""
mutations_table = {}
mental_mutations_cnt = roll_dices(1,4, False).get('result')
physical_mutations_cnt = roll_dices(1, 4, False).get('result')
mutations_table['count'] = {'mental': mental_mutations_cnt, 'physical': physical_mutations_cnt}
mental_mutations_scores = []
physical_mutations_scores = []
for _ in range(mental_mutations_cnt):
mscore = roll_dices(1, 100, False).get('result') + intscore
if mscore in mental_mutations_scores:
mscore = mscore-3
if mscore > 100:
mscore = 100
mental_mutations_scores.append(mscore)
for _ in range(physical_mutations_cnt):
pscore = roll_dices(1, 100, False).get('result') + conscore
if pscore in physical_mutations_scores:
pscore = pscore-3
if pscore > 100:
pscore = 100
physical_mutations_scores.append(pscore)
mut = Mutations()
mmut = []
pmut = []
for score in mental_mutations_scores:
mutation = mut.get_mental_mutation(score)
mmut.append(mutation)
mutations_table['mental'] = mmut
for score in physical_mutations_scores:
mutation = mut.get_physical_mutation(score)
pmut.append(mutation)
mutations_table['physical'] = pmut
return mutations_table
if __name__ == '__main__':
app.run()

231
mutations.py Normal file
View File

@ -0,0 +1,231 @@
import pandas as pd
class Mutations(object):
def __init__(self):
self.raw_mutations_table = {
'Score': list(range(1, 101)),
'Physical': [
'No Nerve Endings',
'Poison Susceptibility',
'Poison Susceptibility',
'Dark Dependency',
'Dark Dependency',
'Arterial Weakness',
'Arterial Weakness',
'Diminished Sense',
'Energy Sensitivity',
'Doubled Pain',
'Heat Reaction',
'Insanity',
'Insanity',
'Insanity',
'Attraction Odor',
'Anti-Charisma',
'Anti-Charisma',
'Body Structure Change',
'Body Structure Change',
'Fat Cell Accumulation',
'Increased Metabolism',
'Inhibiting Field',
'Water Dependency',
'Weight Decrease',
'Vision Defect',
'Vision Defect',
'Light Dependency',
'Skin Structure Change',
'Narcolepsy',
'Bacterial Susceptibility',
'Phobia',
'Phobia',
'Phobia',
'Poor Duel Brain',
'Poor Respiration',
'Actual Metamorphosis',
'Kinetic Absorption',
'Kinetic Absorption',
'Sound Imitation',
'Bodily Control',
'Horns or Antlers',
'Heightened Physical Attribute',
'Heightened Physical Attribute',
'Heightened Physical Attribute',
'Heightened Physical Attribute',
'Heightened Sense',
'Heightened Sense',
'Heightened Precision',
'Heightened Precision',
'Heightened Precision',
'Heightened Precision',
'Heightened Precision',
'Modified Body Parts',
'Modified Body Parts',
'Multiplied Body Parts',
'Multiplied Body Parts',
'Multiplied Body Parts',
'Oversize Body Parts',
'New Body Parts',
'New Body Parts',
'Regeneration',
'Quills / Spines',
'Radar / Sonar',
'Ultra vision',
'Shorter',
'Electrical Generation',
'Gills',
'Taller',
'Photosynthetic Skin',
'Physical Reflection',
'Mane & Bristles',
'Skeletal Enhancement',
'Density Control (self)',
'Displacement',
'Wings',
'Gas Bags',
'Speed Increase',
'Carapace',
'Radiation Eyes',
'Chameleon Powers',
'Chameleon Powers',
'Light Generation',
'Shape change',
'Anti-Life Leach',
'Infra vision',
'Heightened Balance',
'Energy Absorption',
'Energy Metamorphosis',
'Gas Generation',
'Heat Generation',
'Hands of Power',
'Hands of Power',
'Dual Brain',
'Duality',
'Sonic Blast',
'YOU PICK ONE',
'YOU PICK ONE',
'YOU PICK ONE',
'YOU INVENT ONE',
'YOU INVENT ONE'
],
'Mental': [
'Attack Reversal',
'Mental Block',
'Mental Block',
'Seizures',
'Seizures',
'Fear Impulse',
'Fear Impulse',
'Hostility Field',
'Mental Defenselessness',
'Multiple Damage',
'Energy Sensitivity',
'Periodic Amnesia',
'Periodic Amnesia',
'Periodic Amnesia',
'Unconscious Summoning',
'Empathy',
'Empathy',
'Beguiling',
'Beguiling',
'Confusion',
'Psychometry',
'Directional Sense',
'Intuition',
'Precognition',
'Summoning',
'Summoning',
'Absorption',
'Time Suspension',
'Reflection',
'Devolution',
'Genius Capability',
'Genius Capability',
'Genius Capability',
'Repelling Force',
'Mass Mind',
'Magnetic Control',
'Heightened Brain Talent',
'Heightened Brain Talent',
'Heightened Intelligence',
'Density Control (Others)',
'Light Manipulation',
'Mental Blast',
'Mental Blast',
'Mental Blast',
'Mental Blast',
'Mental Shield',
'Mental Shield',
'Mental Control Of Body',
'Mental Control Of Body',
'Mental Control Of Body',
'Mental Control Of Body',
'Mental Control Of Body',
'Mental Multiplier',
'Mental Multiplier',
'Mental Control',
'Mental Control',
'Mental Control',
'Mental Paralysis',
'Fear Generation',
'Fear Generation',
'Force Field Generation',
'Illusion Generation',
'Molecular Sense',
'Molecular Disruption',
'Repulsion Field',
'Plant Control',
'Stunning Force',
'Telepathy',
'Pyro/Cryokinesis',
'Telekinesis',
'Telekinetic Arm',
'Telekinetic Flight',
'Symbiotic Attachment',
'Levitation',
'Temporal Fugue',
'Temporal Fugue',
'Teleport Object',
'Teleportation',
'Thought Imitation',
'The Gamma Eye',
'The Gamma Eye',
'Will Force',
'Total Healing',
'Time Manipulation',
'Time Manipulation',
'Weather Manipulation',
'Weather Manipulation',
'Time Distortion',
'Death Field Generation',
'Life Leach',
'Planar Travel',
'YOU PICK ONE',
'YOU PICK ONE',
'YOU PICK ONE',
'YOU PICK ONE',
'YOU PICK ONE',
'YOU PICK ONE',
'YOU PICK ONE',
'YOU INVENT ONE',
'YOU INVENT ONE'
]
}
self.mutations_table = pd.DataFrame(self.raw_mutations_table)
def get_physical_mutation(self, score):
mutation = self.mutations_table.loc[self.mutations_table['Score'] == score, 'Physical']
return mutation.iloc[0] if not mutation.empty else None
def get_mental_mutation(self, score):
mutation = self.mutations_table.loc[self.mutations_table['Score'] == score, 'Mental']
return mutation.iloc[0] if not mutation.empty else None
def get_table_shape(self):
return self.mutations_table.shape
def get_table_row_count(self):
return self.mutations_table.shape[0]
def get_table_column_count(self):
return self.mutations_table.shape[1]

View File

@ -1,3 +1,4 @@
Flask~=3.0.3
flask-restx~=1.3.0
marshmallow~=3.21.3
marshmallow~=3.21.3
pandas~=2.2.2