Skip to content

Commit 4189b84

Browse files
committed
Added RuleGroup model (temp. name for RuleSet)
1 parent 9e81c91 commit 4189b84

File tree

11 files changed

+189
-19
lines changed

11 files changed

+189
-19
lines changed

api_v2/management/commands/buildindex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def load_v1_content(self, model):
5555

5656
def load_v2_content(self, model):
5757
results = []
58-
standard_v2_models = ['Item','Spell','Creature','CharacterClass','Race','Feat','Condition','Background','Environment']
58+
standard_v2_models = ['Item','Spell','Creature','CharacterClass','Race','Feat','Condition','Background','Environment', 'Rule']
5959

6060
if model.__name__ in standard_v2_models:
6161
for o in model.objects.all():
@@ -147,6 +147,7 @@ def handle(self, *args, **options):
147147
self.load_content(v2.Condition,"v2")
148148
self.load_content(v2.Background,"v2")
149149
self.load_content(v2.Environment,"v2")
150+
self.load_content(v2.Rule, "v2")
150151

151152
# Take the content table's current data and load it into the index.
152153
self.load_index()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 3.2.20 on 2024-09-25 10:20
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('api_v2', '0116_alter_rule_next'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='rule',
16+
name='document',
17+
field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='api_v2.document'),
18+
preserve_default=False,
19+
),
20+
]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Generated by Django 3.2.20 on 2024-10-08 12:06
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('api_v2', '0117_rule_document'),
11+
]
12+
13+
operations = [
14+
migrations.RemoveField(
15+
model_name='rule',
16+
name='next',
17+
),
18+
migrations.AddField(
19+
model_name='rule',
20+
name='index',
21+
field=models.IntegerField(default=1),
22+
),
23+
migrations.CreateModel(
24+
name='RuleGroup',
25+
fields=[
26+
('name', models.CharField(help_text='Name of the item.', max_length=100)),
27+
('desc', models.TextField(help_text='Description of the game content item. Markdown.')),
28+
('key', models.CharField(help_text='Unique key for the Document.', max_length=100, primary_key=True, serialize=False)),
29+
('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api_v2.document')),
30+
],
31+
options={
32+
'abstract': False,
33+
},
34+
),
35+
migrations.AddField(
36+
model_name='rule',
37+
name='ruleset',
38+
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='rules', to='api_v2.rulegroup'),
39+
preserve_default=False,
40+
),
41+
]

api_v2/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@
5858

5959
from .speed import HasSpeed
6060

61-
from .rules import Rule
61+
from .rules import Rule, RuleGroup

api_v2/models/rules.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
from django.db import models
22
from .abstracts import HasName, HasDescription, key_field
3+
from .document import FromDocument
34

4-
class Rule(HasName, HasDescription):
5-
""""
6-
This Model is used to represent game content in the form of rules and
7-
articles.
5+
6+
# TODO it has been agreed that this model should be called 'RuleSet' and that
7+
# existant the 'RuleSet' should be renamed to 'GameSystem'.
8+
#
9+
# This change be handled in its own PR, as it represents a significant
10+
# expansion of the initial issue and will likely touch many files, causing
11+
# headaches for whichever poor soul ends up reviewing it
12+
13+
class RuleGroup(HasName, HasDescription, FromDocument):
14+
"""
15+
The RuleGroup model contains a set of Rules as part of a larger article, or
16+
as a chapter of a book.
817
"""
918
key = key_field()
1019

11-
next = models.ForeignKey(
12-
'self',
13-
blank=True,
14-
null=True,
15-
on_delete=models.SET_NULL,
16-
related_name="previous"
20+
21+
class Rule(HasName, HasDescription, FromDocument):
22+
""""
23+
The Rule model contains information about a single rule from a larger RuleGroup.
24+
Each Rule is typically a paragraph or two long and might contain tables.
25+
"""
26+
key = key_field()
27+
index = models.IntegerField(default=1)
28+
ruleset = models.ForeignKey(
29+
RuleGroup,
30+
on_delete=models.CASCADE,
31+
related_name='rules'
1732
)
1833

1934
initialHeaderLevel = models.IntegerField(

api_v2/serializers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
from .ability import AbilitySerializer
4949
from .ability import SkillSerializer
5050

51-
from .rule import RuleSerializer
51+
from .rule import RuleSerializer, RuleGroupSerializer

api_v2/serializers/rule.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
from .abstracts import GameContentSerializer
88

9-
class RuleSerializer(serializers.ModelSerializer):
9+
class RuleSerializer(GameContentSerializer):
1010
class Meta:
1111
model = models.Rule
12-
fields = '__all__'
12+
fields = '__all__'
13+
14+
class RuleGroupSerializer(GameContentSerializer):
15+
class Meta:
16+
model = models.RuleGroup
17+
fields = ['name', 'key', 'document', 'desc', 'rules']

api_v2/views/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
from .size import SizeViewSet
4040

41-
from .rule import RuleViewSet
41+
from .rule import RuleSectionViewSet, RuleGroupViewSet
4242

4343
from .enum import get_enums
4444

api_v2/views/rule.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from api_v2 import models
66
from api_v2 import serializers
77

8-
class RuleViewSet(viewsets.ReadOnlyModelViewSet):
8+
class RuleSectionViewSet(viewsets.ReadOnlyModelViewSet):
99
queryset = models.Rule.objects.all()
10-
serializer_class = serializers.RuleSerializer
10+
serializer_class = serializers.RuleSerializer
11+
12+
class RuleGroupViewSet(viewsets.ReadOnlyModelViewSet):
13+
queryset = models.RuleGroup.objects.all()
14+
serializer_class = serializers.RuleGroupSerializer
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
[
2+
{
3+
"model": "api_v2.rulegroup",
4+
"pk": "srd_damage-and-healing",
5+
"fields": {
6+
"name": "Damage and Healing",
7+
"document": "srd",
8+
"desc": "Injury and the risk of death are constant companions of those who explore fantasy gaming worlds. The thrust of a sword, a well-placed arrow, or a blast of flame from a srd:fireball spell all have the potential to damage, or even kill, the hardiest of creatures."
9+
}
10+
},
11+
{
12+
"model": "api_v2.rule",
13+
"pk": "srd_damage-and-healing_hit-points",
14+
"fields": {
15+
"ruleset": "srd_damage-and-healing",
16+
"document": "srd",
17+
"name": "Hit Points",
18+
"index": 1,
19+
"initialHeaderLevel": 2,
20+
"desc": "Hit points represent a combination of physical and mental durability, the will to live, and luck. Creatures with more hit points are more difficult to kill. Those with fewer hit points are more fragile.\n\nA creature's current hit points (usually just called hit points) can be any number from the creature's hit point maximum down to 0. This number changes frequently as a creature takes damage or receives healing.\n\nWhenever a creature takes damage, that damage is subtracted from its hit points. The loss of hit points has no effect on a creature's capabilities until the creature drops to 0 hit points.\n\n## Damage Rolls\n\nEach weapon, spell, and harmful monster ability specifies the damage it deals. You roll the damage die or dice, add any modifiers, and apply the damage to your target. Magic weapons, special abilities, and other factors can grant a bonus to damage. With a penalty, it is possible to deal 0 damage, but never negative damage. When attacking with a **weapon**, you add your ability modifier---the same modifier used for the attack roll---to the damage. A **spell** tells you which dice to roll for damage and whether to add any modifiers.\n\nIf a spell or other effect deals damage to **more** **than one target** at the same time, roll the damage once for all of them. For example, when a wizard casts srd:fireball or a cleric casts srd:flame-strike, the spell's damage is rolled once for all creatures caught in the blast."
21+
}
22+
},
23+
{
24+
"model": "api_v2.rule",
25+
"pk": "srd_damage-and-healing_damage-rolls",
26+
"fields": {
27+
"ruleset": "srd_damage-and-healing",
28+
"document": "srd",
29+
"name": "Damage Rolls",
30+
"index": 2,
31+
"initialHeaderLevel": 2,
32+
"desc": "Each weapon, spell, and harmful monster ability specifies the damage it deals. You roll the damage die or dice, add any modifiers, and apply the damage to your target. Magic weapons, special abilities, and other factors can grant a bonus to damage. With a penalty, it is possible to deal 0 damage, but never negative damage. When attacking with a **weapon**, you add your ability modifier---the same modifier used for the attack roll---to the damage. A **spell** tells you which dice to roll for damage and whether to add any modifiers.\n\nIf a spell or other effect deals damage to **more** **than one target** at the same time, roll the damage once for all of them. For example, when a wizard casts srd:fireball or a cleric casts srd:flame-strike, the spell's damage is rolled once for all creatures caught in the blast."
33+
}
34+
},
35+
{
36+
"model": "api_v2.rule",
37+
"pk": "srd_damage-and-healing_critical-hits",
38+
"fields": {
39+
"ruleset": "srd_damage-and-healing",
40+
"document": "srd",
41+
"name": "Critical Hits",
42+
"index": 3,
43+
"initialHeaderLevel": 3,
44+
"desc": "Each weapon, spell, and harmful monster ability specifies the damage it deals. You roll the damage die or dice, add any modifiers, and apply the damage to your target. Magic weapons, special abilities, and other factors can grant a bonus to damage. With a penalty, it is possible to deal 0 damage, but never negative damage. When attacking with a **weapon**, you add your ability modifier---the same modifier used for the attack roll---to the damage. A **spell** tells you which dice to roll for damage and whether to add any modifiers.\n\nIf a spell or other effect deals damage to **more** **than one target** at the same time, roll the damage once for all of them. For example, when a wizard casts srd:fireball or a cleric casts srd:flame-strike, the spell's damage is rolled once for all creatures caught in the blast."
45+
}
46+
},
47+
{
48+
"model": "api_v2.rule",
49+
"pk": "srd_damage-and-healing_damage-types",
50+
"fields": {
51+
"ruleset": "srd_damage-and-healing",
52+
"document": "srd",
53+
"name": "Damage Types",
54+
"index": 4,
55+
"initialHeaderLevel": 3,
56+
"desc": "Different attacks, damaging spells, and other harmful effects deal different types of damage. Damage types have no rules of their own, but other rules, such as damage resistance, rely on the types.\n\nThe damage types follow, with examples to help a GM assign a damage type to a new effect.\n\n**Acid.** The corrosive spray of a black dragon's breath and the dissolving enzymes secreted by a black pudding deal acid damage.\n\n**Bludgeoning.** Blunt force attacks---hammers, falling, constriction, and the like---deal bludgeoning damage.\n\n**Cold.** The infernal chill radiating from an ice devil's spear and the frigid blast of a white dragon's breath deal cold damage.\n\n**Fire.** Red dragons breathe fire, and many spells conjure flames to deal fire damage.\n\n**Force.** Force is pure magical energy focused into a damaging form. Most effects that deal force damage are spells, including _magic missile_ and _spiritual weapon_.\n\n**Lightning.** A _lightning bolt_ spell and a blue dragon's breath deal lightning damage.\n\n**Necrotic.** Necrotic damage, dealt by certain undead and a spell such as _chill touch_, withers matter and even the soul.\n\n**Piercing.** Puncturing and impaling attacks, including spears and monsters' bites, deal piercing damage.\n\n**Poison.** Venomous stings and the toxic gas of a green dragon's breath deal poison damage.\n\n**Psychic.** Mental abilities such as a mind flayer's psionic blast deal psychic damage.\n\n**Radiant.** Radiant damage, dealt by a cleric's _flame strike_ spell or an angel's smiting weapon, sears the flesh like fire and overloads the spirit with power.\n\n**Slashing.** Swords, axes, and monsters' claws deal slashing damage.\n\n**Thunder.** A concussive burst of sound, such as the effect of the srd:thunderwave spell, deals thunder damage."
57+
}
58+
},
59+
{
60+
"model": "api_v2.rule",
61+
"pk": "srd_damage-and-healing_damage-types",
62+
"fields": {
63+
"ruleset": "srd_damage-and-healing",
64+
"document": "srd",
65+
"name": "Damage Types",
66+
"index": 5,
67+
"initialHeaderLevel": 3,
68+
"desc": "Different attacks, damaging spells, and other harmful effects deal different types of damage. Damage types have no rules of their own, but other rules, such as damage resistance, rely on the types.\n\nThe damage types follow, with examples to help a GM assign a damage type to a new effect.\n\n**Acid.** The corrosive spray of a black dragon's breath and the dissolving enzymes secreted by a black pudding deal acid damage.\n\n**Bludgeoning.** Blunt force attacks---hammers, falling, constriction, and the like---deal bludgeoning damage.\n\n**Cold.** The infernal chill radiating from an ice devil's spear and the frigid blast of a white dragon's breath deal cold damage.\n\n**Fire.** Red dragons breathe fire, and many spells conjure flames to deal fire damage.\n\n**Force.** Force is pure magical energy focused into a damaging form. Most effects that deal force damage are spells, including _magic missile_ and _spiritual weapon_.\n\n**Lightning.** A _lightning bolt_ spell and a blue dragon's breath deal lightning damage.\n\n**Necrotic.** Necrotic damage, dealt by certain undead and a spell such as _chill touch_, withers matter and even the soul.\n\n**Piercing.** Puncturing and impaling attacks, including spears and monsters' bites, deal piercing damage.\n\n**Poison.** Venomous stings and the toxic gas of a green dragon's breath deal poison damage.\n\n**Psychic.** Mental abilities such as a mind flayer's psionic blast deal psychic damage.\n\n**Radiant.** Radiant damage, dealt by a cleric's _flame strike_ spell or an angel's smiting weapon, sears the flesh like fire and overloads the spirit with power.\n\n**Slashing.** Swords, axes, and monsters' claws deal slashing damage.\n\n**Thunder.** A concussive burst of sound, such as the effect of the srd:thunderwave spell, deals thunder damage."
69+
}
70+
},
71+
{
72+
"model": "api_v2.rule",
73+
"pk": "srd_damage-and-healing_resistance-and-vulnerability",
74+
"fields": {
75+
"ruleset": "srd_damage-and-healing",
76+
"document": "srd",
77+
"name": "Damage Resistance and Vulnerability",
78+
"index": 6,
79+
"initialHeaderLevel": 2,
80+
"desc": "Some creatures and objects are exceedingly difficult or unusually easy to hurt with certain types of damage.\n\nIf a creature or an object has **resistance** to a damage type, damage of that type is halved against it. If a creature or an object has **vulnerability** to a damage type, damage of that type is doubled against it.\n\nResistance and then vulnerability are applied after all other modifiers to damage. For example, a creature has resistance to bludgeoning damage and is hit by an attack that deals 25 bludgeoning damage. The creature is also within a magical aura that reduces all damage by 5. The 25 damage is first reduced by 5 and then halved, so the creature takes 10 damage.\n\nMultiple instances of resistance or vulnerability that affect the same damage type count as only one instance. For example, if a creature has resistance to fire damage as well as resistance to all nonmagical damage, the damage of a nonmagical fire is reduced by half against the creature, not reduced by three--- quarters."
81+
}
82+
}
83+
]

0 commit comments

Comments
 (0)