rollConfiguration. Migrations. 2

This commit is contained in:
tcaxle 2020-04-11 15:15:05 +01:00
parent 0b9ac811ee
commit fe35f3b63d
4 changed files with 91 additions and 38 deletions

View File

@ -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'),
),
]

View File

@ -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:
if die in listExplodingDisappearing:
if die in listSuccess:
listExploded.append(die)
die = 0
if die in listDisappearing:
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 ----------------------------------#
#==============================================================================#