@@ -1421,6 +1421,7 @@ class StatDetailSerializer(serializers.ModelSerializer):
14211421 )
14221422 affecting_moves = serializers .SerializerMethodField ("get_moves_that_affect" )
14231423 affecting_natures = serializers .SerializerMethodField ("get_natures_that_affect" )
1424+ affecting_items = serializers .SerializerMethodField ("get_items_that_affect" )
14241425
14251426 class Meta :
14261427 model = Stat
@@ -1431,6 +1432,7 @@ class Meta:
14311432 "is_battle_only" ,
14321433 "affecting_moves" ,
14331434 "affecting_natures" ,
1435+ "affecting_items" ,
14341436 "characteristics" ,
14351437 "move_damage_class" ,
14361438 "names" ,
@@ -1569,6 +1571,80 @@ def get_natures_that_affect(self, obj):
15691571
15701572 return OrderedDict ([("increase" , increases ), ("decrease" , decreases )])
15711573
1574+ @extend_schema_field (
1575+ field = {
1576+ "type" : "array" ,
1577+ "items" : {
1578+ "type" : "object" ,
1579+ "required" : ["name" , "url" ],
1580+ "properties" : {
1581+ "name" : {
1582+ "type" : "string" ,
1583+ "examples" : ["protein" , "x-attack" ],
1584+ },
1585+ "url" : {
1586+ "type" : "string" ,
1587+ "format" : "uri" ,
1588+ "examples" : ["https://pokeapi.co/api/v2/item/46/" ],
1589+ },
1590+ },
1591+ },
1592+ }
1593+ )
1594+ def get_items_that_affect (self , obj ):
1595+ """
1596+ Get items that affect this stat (like vitamins, X-items, etc.)
1597+ """
1598+ # Map stat names to their corresponding vitamin items
1599+ stat_item_mapping = {
1600+ "hp" : ["hp-up" ],
1601+ "attack" : ["protein" ],
1602+ "defense" : ["iron" ],
1603+ "special-attack" : ["calcium" ],
1604+ "special-defense" : ["zinc" ],
1605+ "speed" : ["carbos" ],
1606+ }
1607+
1608+ # Get the stat name (lowercase)
1609+ stat_name = obj .name .lower ()
1610+
1611+ # Find items that affect this stat
1612+ affecting_items = []
1613+
1614+ # Check for vitamin items
1615+ if stat_name in stat_item_mapping :
1616+ for item_identifier in stat_item_mapping [stat_name ]:
1617+ try :
1618+ item = Item .objects .get (name = item_identifier )
1619+ affecting_items .append (
1620+ ItemSummarySerializer (item , context = self .context ).data
1621+ )
1622+ except Item .DoesNotExist :
1623+ pass
1624+
1625+ # Check for X-items (like X Attack, X Defense, etc.)
1626+ x_item_mapping = {
1627+ "attack" : ["x-attack" ],
1628+ "defense" : ["x-defense" ],
1629+ "special-attack" : ["x-sp-atk" ],
1630+ "special-defense" : ["x-sp-def" ],
1631+ "speed" : ["x-speed" ],
1632+ "accuracy" : ["x-accuracy" ],
1633+ "evasion" : ["x-evasion" ],
1634+ }
1635+
1636+ if stat_name in x_item_mapping :
1637+ for item_identifier in x_item_mapping [stat_name ]:
1638+ try :
1639+ item = Item .objects .get (name = item_identifier )
1640+ affecting_items .append (
1641+ ItemSummarySerializer (item , context = self .context ).data
1642+ )
1643+ except Item .DoesNotExist :
1644+ pass
1645+
1646+ return affecting_items
1647+
15721648
15731649#############################
15741650# ITEM POCKET SERIALIZERS #
0 commit comments