diff --git a/app/__pycache__/admin.cpython-38.pyc b/app/__pycache__/admin.cpython-38.pyc index 9c1e40b..6ae4697 100644 Binary files a/app/__pycache__/admin.cpython-38.pyc and b/app/__pycache__/admin.cpython-38.pyc differ diff --git a/app/__pycache__/models.cpython-38.pyc b/app/__pycache__/models.cpython-38.pyc index 6a5766c..94927ca 100644 Binary files a/app/__pycache__/models.cpython-38.pyc and b/app/__pycache__/models.cpython-38.pyc differ diff --git a/app/admin.py b/app/admin.py index 394fbea..3262720 100644 --- a/app/admin.py +++ b/app/admin.py @@ -1,6 +1,8 @@ from django.contrib import admin from .models import * +admin.site.register(rollConfiguration) + admin.site.register(modifierAttribute) admin.site.register(modifierAbility) admin.site.register(modifierStatic) diff --git a/app/migrations/0011_rollconfiguration.py b/app/migrations/0011_rollconfiguration.py new file mode 100644 index 0000000..dcdd186 --- /dev/null +++ b/app/migrations/0011_rollconfiguration.py @@ -0,0 +1,30 @@ +# Generated by Django 3.0.5 on 2020-04-11 13:55 + +import app.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0010_auto_20200411_1302'), + ] + + operations = [ + migrations.CreateModel( + name='rollConfiguration', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('r01', app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING', 'Exploding'), ('DISAPPEARING', 'Disappearing'), ('SUBTRACTING', 'Subtracting')], default='NONE', max_length=100, number=1, verbose_name='1s')), + ('r02', app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING', 'Exploding'), ('DISAPPEARING', 'Disappearing'), ('SUBTRACTING', 'Subtracting')], default='NONE', max_length=100, number=2, verbose_name='2s')), + ('r03', app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING', 'Exploding'), ('DISAPPEARING', 'Disappearing'), ('SUBTRACTING', 'Subtracting')], default='NONE', max_length=100, number=3, verbose_name='3s')), + ('r04', app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING', 'Exploding'), ('DISAPPEARING', 'Disappearing'), ('SUBTRACTING', 'Subtracting')], default='NONE', max_length=100, number=4, verbose_name='4s')), + ('r05', app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING', 'Exploding'), ('DISAPPEARING', 'Disappearing'), ('SUBTRACTING', 'Subtracting')], default='NONE', max_length=100, number=5, verbose_name='5s')), + ('r06', app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING', 'Exploding'), ('DISAPPEARING', 'Disappearing'), ('SUBTRACTING', 'Subtracting')], default='NONE', max_length=100, number=6, verbose_name='6s')), + ('r07', app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING', 'Exploding'), ('DISAPPEARING', 'Disappearing'), ('SUBTRACTING', 'Subtracting')], default='SUCCESS', max_length=100, number=7, verbose_name='7s')), + ('r08', app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING', 'Exploding'), ('DISAPPEARING', 'Disappearing'), ('SUBTRACTING', 'Subtracting')], default='SUCCESS', max_length=100, number=8, verbose_name='8s')), + ('r09', app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING', 'Exploding'), ('DISAPPEARING', 'Disappearing'), ('SUBTRACTING', 'Subtracting')], default='SUCCESS', max_length=100, number=9, verbose_name='9s')), + ('r10', app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING', 'Exploding'), ('DISAPPEARING', 'Disappearing'), ('SUBTRACTING', 'Subtracting')], default='DOUBLE', max_length=100, number=10, verbose_name='10s')), + ], + ), + ] diff --git a/app/migrations/__pycache__/0011_rollconfiguration.cpython-38.pyc b/app/migrations/__pycache__/0011_rollconfiguration.cpython-38.pyc new file mode 100644 index 0000000..10a2c7a Binary files /dev/null and b/app/migrations/__pycache__/0011_rollconfiguration.cpython-38.pyc differ diff --git a/app/models.py b/app/models.py index 656f4eb..32933f2 100644 --- a/app/models.py +++ b/app/models.py @@ -1,5 +1,6 @@ from django.db import models import multiselectfield +from random import randint #==============================================================================# #-------------------------------- OPTION LISTS --------------------------------# @@ -150,6 +151,15 @@ INTENSITIES = [ ("DEFINING", "Defining"), ] +DIE_TYPES = [ + ("NONE", "None"), + ("SUCCESS", "Success"), + ("DOUBLE", "Double"), + ("EXPLODING", "Exploding"), + ("DISAPPEARING", "Disappearing"), + ("SUBTRACTING", "Subtracting") +] + #==============================================================================# #------------------------------- CUSTOM MODELS --------------------------------# #==============================================================================# @@ -205,6 +215,96 @@ class NamedCharField(models.CharField): kwargs['max_length'] = 100 super().__init__(*args, **kwargs) +class DieField(models.CharField): + def __init__(self, verbose_name, number, default, *args, **kwargs): + self.number = number + kwargs['verbose_name'] = verbose_name + kwargs['default'] = default + kwargs['choices'] = DIE_TYPES + kwargs['blank'] = False + kwargs['max_length'] = 100 + super().__init__(*args, **kwargs) + + def deconstruct(self): + name, path, args, kwargs = super().deconstruct() + kwargs['number'] = self.number + return name, path, args, kwargs + +#==============================================================================# +#-------------------------------- DICE ROLLING --------------------------------# +#==============================================================================# +class rollConfiguration(models.Model): + r01 = DieField("1s", 1, "NONE") + r02 = DieField("2s", 2, "NONE") + r03 = DieField("3s", 3, "NONE") + r04 = DieField("4s", 4, "NONE") + r05 = DieField("5s", 5, "NONE") + r06 = DieField("6s", 6, "NONE") + r07 = DieField("7s", 7, "SUCCESS") + r08 = DieField("8s", 8, "SUCCESS") + r09 = DieField("9s", 9, "SUCCESS") + r10 = DieField("10s", 10, "DOUBLE") + + def listDice(self): + listDice = [ + self.r01, + self.r02, + self.r03, + self.r04, + self.r05, + self.r06, + self.r07, + self.r08, + self.r09, + self.r10, + ] + listSuccess = [] + listDouble = [] + listExploding = [] + listDisappearing = [] + listSubtracting = [] + for die in listDice: + if die == "SUCCESS": + listSuccess.append(die.number) + elif die == "DOUBLE": + listDouble.append(die.number) + elif die == "EXPLODING": + listExploding.append(die.number) + elif die == "DISAPPEARING": + listDisappearing.append(die.number) + elif die == "SUBTRACTING": + listSubtracting.append(die.number) + return listSuccess, listDouble, listExploding, listDisappearing, listSubtracting + + def roll(self, pool=1): + listSuccess, listDouble, listExploding, listDisappearing, listSubtracting = self.listDice() + successes = 0 + listExploded, listDisappeared = [], [] + listRoll = [0 for die in range(pool)] + while 0 in listRoll: + for die in listRoll: + if die == 0: + die = randint(1, 10) + if die in listExploding: + listExploded.append(die) + die = 0 + if die in listDisappearing: + listDisappeared.append(die) + die = 0 + for die in listRoll + listExploded: + if die in listSuccess: + successes += 1 + elif die in listDouble: + successes += 2 + elif die in listSubtracting: + successes -= 1 + if successes < 0: + successes = 0 + botch = (successes == 0) and (1 in listRoll) + return successes, botch, listRoll, listExploded, listDisappeared + + + #==============================================================================# #--------------------------------- MODIFIERS ----------------------------------#