diff --git a/app/__pycache__/models.cpython-38.pyc b/app/__pycache__/models.cpython-38.pyc index 94927ca..85f5562 100644 Binary files a/app/__pycache__/models.cpython-38.pyc and b/app/__pycache__/models.cpython-38.pyc differ diff --git a/app/migrations/0012_auto_20200411_1414.py b/app/migrations/0012_auto_20200411_1414.py new file mode 100644 index 0000000..8486c03 --- /dev/null +++ b/app/migrations/0012_auto_20200411_1414.py @@ -0,0 +1,64 @@ +# Generated by Django 3.0.5 on 2020-04-11 14:14 + +import app.models +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0011_rollconfiguration'), + ] + + operations = [ + migrations.AlterField( + model_name='rollconfiguration', + name='r01', + field=app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING_DISAPPEARING', 'Exploding / Disappearing'), ('SUBTRACTING', 'Subtracting')], default=['NONE'], max_length=100, number=1, verbose_name='1s'), + ), + migrations.AlterField( + model_name='rollconfiguration', + name='r02', + field=app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING_DISAPPEARING', 'Exploding / Disappearing'), ('SUBTRACTING', 'Subtracting')], default=['NONE'], max_length=100, number=2, verbose_name='2s'), + ), + migrations.AlterField( + model_name='rollconfiguration', + name='r03', + field=app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING_DISAPPEARING', 'Exploding / Disappearing'), ('SUBTRACTING', 'Subtracting')], default=['NONE'], max_length=100, number=3, verbose_name='3s'), + ), + migrations.AlterField( + model_name='rollconfiguration', + name='r04', + field=app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING_DISAPPEARING', 'Exploding / Disappearing'), ('SUBTRACTING', 'Subtracting')], default=['NONE'], max_length=100, number=4, verbose_name='4s'), + ), + migrations.AlterField( + model_name='rollconfiguration', + name='r05', + field=app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING_DISAPPEARING', 'Exploding / Disappearing'), ('SUBTRACTING', 'Subtracting')], default=['NONE'], max_length=100, number=5, verbose_name='5s'), + ), + migrations.AlterField( + model_name='rollconfiguration', + name='r06', + field=app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING_DISAPPEARING', 'Exploding / Disappearing'), ('SUBTRACTING', 'Subtracting')], default=['NONE'], max_length=100, number=6, verbose_name='6s'), + ), + migrations.AlterField( + model_name='rollconfiguration', + name='r07', + field=app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING_DISAPPEARING', 'Exploding / Disappearing'), ('SUBTRACTING', 'Subtracting')], default=['SUCCESS'], max_length=100, number=7, verbose_name='7s'), + ), + migrations.AlterField( + model_name='rollconfiguration', + name='r08', + field=app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING_DISAPPEARING', 'Exploding / Disappearing'), ('SUBTRACTING', 'Subtracting')], default=['SUCCESS'], max_length=100, number=8, verbose_name='8s'), + ), + migrations.AlterField( + model_name='rollconfiguration', + name='r09', + field=app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING_DISAPPEARING', 'Exploding / Disappearing'), ('SUBTRACTING', 'Subtracting')], default=['SUCCESS'], max_length=100, number=9, verbose_name='9s'), + ), + migrations.AlterField( + model_name='rollconfiguration', + name='r10', + field=app.models.DieField(choices=[('NONE', 'None'), ('SUCCESS', 'Success'), ('DOUBLE', 'Double'), ('EXPLODING_DISAPPEARING', 'Exploding / Disappearing'), ('SUBTRACTING', 'Subtracting')], default=['SUCCESS', 'DOUBLE'], max_length=100, number=10, verbose_name='10s'), + ), + ] diff --git a/app/migrations/__pycache__/0012_auto_20200411_1414.cpython-38.pyc b/app/migrations/__pycache__/0012_auto_20200411_1414.cpython-38.pyc new file mode 100644 index 0000000..4f6a6c3 Binary files /dev/null and b/app/migrations/__pycache__/0012_auto_20200411_1414.cpython-38.pyc differ diff --git a/app/models.py b/app/models.py index 32933f2..9a60fed 100644 --- a/app/models.py +++ b/app/models.py @@ -155,8 +155,7 @@ DIE_TYPES = [ ("NONE", "None"), ("SUCCESS", "Success"), ("DOUBLE", "Double"), - ("EXPLODING", "Exploding"), - ("DISAPPEARING", "Disappearing"), + ("EXPLODING_DISAPPEARING", "Exploding / Disappearing"), ("SUBTRACTING", "Subtracting") ] @@ -215,7 +214,7 @@ class NamedCharField(models.CharField): kwargs['max_length'] = 100 super().__init__(*args, **kwargs) -class DieField(models.CharField): +class DieField(multiselectfield.MultiSelectField): def __init__(self, verbose_name, number, default, *args, **kwargs): self.number = number kwargs['verbose_name'] = verbose_name @@ -234,18 +233,18 @@ class DieField(models.CharField): #-------------------------------- 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") + 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, ["SUCCESS", "DOUBLE"]) - def listDice(self): + def roll(self, pool=1): listDice = [ self.r01, self.r02, @@ -260,24 +259,17 @@ class rollConfiguration(models.Model): ] listSuccess = [] listDouble = [] - listExploding = [] - listDisappearing = [] + listExplodingDisappearing = [] listSubtracting = [] for die in listDice: - if die == "SUCCESS": + if "SUCCESS" in die: listSuccess.append(die.number) - elif die == "DOUBLE": + if "DOUBLE" in die: listDouble.append(die.number) - elif die == "EXPLODING": - listExploding.append(die.number) - elif die == "DISAPPEARING": - listDisappearing.append(die.number) - elif die == "SUBTRACTING": + if "EXPLODING_DISAPPEARING" in die: + listExplodingDisappearing.append(die.number) + if "SUBTRACTING" in die: 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)] @@ -285,27 +277,24 @@ class rollConfiguration(models.Model): 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) + if die in listExplodingDisappearing: + if die in listSuccess: + listExploded.append(die) + else: + 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: + if die in listDouble: + successes += 1 + if die in listSubtracting: successes -= 1 if successes < 0: successes = 0 botch = (successes == 0) and (1 in listRoll) return successes, botch, listRoll, listExploded, listDisappeared - - - #==============================================================================# #--------------------------------- MODIFIERS ----------------------------------# #==============================================================================#