Removes persistence of items through changing species when not allowed to (#70008)

* Removes persistence of species-restricted items through changing

Makes use of item's mob_can_equip instead of mob's can_equip, making it take the item's restrictions into account.

Also, fixes the inventory's color, so it's properly red when you can't equip such an item, by making it also use mob_can_equip.

Finally, expands the species clothing unit test to take that into account, to prevent it breaking in the future.
This commit is contained in:
John Willard
2022-09-21 13:32:33 -04:00
committed by GitHub
parent 1f4e8eaab8
commit a0442ee002
9 changed files with 32 additions and 32 deletions
@@ -1,16 +1,29 @@
///Gives a Human lizard-incompatible shoes, then changes their species over to see if they drop the now incompatible shoes.
///Gives a Human lizard-incompatible shoes, then changes their species over to see if they drop the now incompatible shoes, testing if Digitigrade feet works.
///Gives a Monkey a collar, then changes their species to Human to see if item's restrictions works on species change.
/datum/unit_test/species_change_clothing
/datum/unit_test/species_change_clothing/Run()
// Test lizards as their own thing so we can get more coverage on their features
var/mob/living/carbon/human/human_to_lizard = allocate(/mob/living/carbon/human/dummy/consistent)
human_to_lizard.equipOutfit(/datum/outfit/job/assistant/consistent)
human_to_lizard.dna.features["legs"] = DIGITIGRADE_LEGS //you WILL have digitigrade legs
var/mob/living/carbon/human/morphing_human = allocate(/mob/living/carbon/human/dummy/consistent)
var/obj/item/human_shoes = human_to_lizard.get_item_by_slot(ITEM_SLOT_FEET)
morphing_human.equipOutfit(/datum/outfit/job/assistant/consistent)
morphing_human.dna.features["legs"] = DIGITIGRADE_LEGS //you WILL have digitigrade legs
var/obj/item/human_shoes = morphing_human.get_item_by_slot(ITEM_SLOT_FEET)
human_shoes.supports_variations_flags = NONE //do not fit lizards at all costs.
morphing_human.set_species(/datum/species/lizard)
var/obj/item/lizard_shoes = morphing_human.get_item_by_slot(ITEM_SLOT_FEET)
human_to_lizard.set_species(/datum/species/lizard)
var/obj/item/lizard_shoes = human_to_lizard.get_item_by_slot(ITEM_SLOT_FEET)
TEST_ASSERT_NOTEQUAL(human_shoes, lizard_shoes, "Lizard still has shoes after changing species.")
// Testing whether item-species restrictions properly blocks changing into a blacklisted species.
morphing_human.set_species(/datum/species/monkey)
var/obj/item/clothing/neck/petcollar/collar = new
morphing_human.equip_to_slot_or_del(collar, ITEM_SLOT_NECK)
var/obj/item/equipped_collar = morphing_human.get_item_by_slot(ITEM_SLOT_NECK)
morphing_human.set_species(/datum/species/human)
var/obj/item/human_collar = morphing_human.get_item_by_slot(ITEM_SLOT_NECK)
TEST_ASSERT_NOTEQUAL(equipped_collar, human_collar, "Human still has a Monkey collar after changing species.")