Skip to content

Commit

Permalink
Merge pull request open5e#573 from open5e/572-api-v2-weapon-model-not…
Browse files Browse the repository at this point in the history
…-returning-properties-field-when-access-as-a-foreignkey-via-items-endpoint

Fixing some accumulated bugs.
  • Loading branch information
augustjohnson authored Oct 16, 2024
2 parents 730a662 + c3e6fc3 commit a7d9c91
Show file tree
Hide file tree
Showing 8 changed files with 16,080 additions and 487 deletions.
12 changes: 6 additions & 6 deletions api_v2/models/weapon.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,29 @@ def is_martial(self):
@property
def is_melee(self):
# Ammunition weapons can only be used as improvised melee weapons.
return not self.ammunition
return not self.requires_ammunition

@property
def ranged_attack_possible(self):
# Only ammunition or throw weapons can make ranged attacks.
return self.ammunition or self.thrown
return self.requires_ammunition or self.is_thrown

@property
def range_melee(self):
return self.range_reach
return self.reach

@property
def is_reach(self):
# A weapon with a longer reach than the default has the reach property.
return self.range_reach > 5
return self.reach > 5

@property
def properties(self):
properties = []

range_desc = "(range {}/{})".format(
str(self.range_normal),
str(self.range_long))
str(self.range),
str(self.long_range))

versatile_desc = "({})".format(self.versatile_dice)

Expand Down
2 changes: 2 additions & 0 deletions api_v2/serializers/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class Meta:
class ItemSerializer(GameContentSerializer):
key = serializers.ReadOnlyField()
is_magic_item = serializers.ReadOnlyField()
weapon = WeaponSerializer(read_only=True, context={'request':{}})
armor = ArmorSerializer(read_only=True, context={'request':{}})

class Meta:
model = models.Item
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{
"armor": "http://localhost:8000/v2/armor/srd_splint/",
"armor": {
"ac_add_dexmod": false,
"ac_base": 17,
"ac_cap_dexmod": null,
"ac_display": "17",
"document": "http://localhost:8000/v2/documents/srd/",
"grants_stealth_disadvantage": true,
"key": "srd_splint",
"name": "Splint",
"strength_score_required": 15,
"url": "http://localhost:8000/v2/armor/srd_splint/"
},
"armor_class": 0,
"category": "http://localhost:8000/v2/itemcategories/armor/",
"cost": "200.00",
Expand Down
Loading

0 comments on commit a7d9c91

Please sign in to comment.