From 00b0394d01c1ea12e7fe690f5a3bf63987a24f93 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 12 Aug 2013 20:30:38 -0400 Subject: [PATCH] include zone restrictions in item conflict checks That is, Neopets.com will raise an error when you try to equip a Kyrii Mage Cape to a pet who's already wearing Ceremonial Shenkuu Warrior Armour, since the armor restricts the Collar zone which the cape occupies. DTI, however, would just hide the Collar zone, as if it were biology. Now, however, DTI will unwear the armor when you wear the cape, and vice-versa (despite the restriction relationship being one-directional). --- app/assets/javascripts/wardrobe.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/wardrobe.js b/app/assets/javascripts/wardrobe.js index 60ac03fa..54fb912b 100644 --- a/app/assets/javascripts/wardrobe.js +++ b/app/assets/javascripts/wardrobe.js @@ -342,15 +342,29 @@ function Wardrobe() { new_items = [], new_worn_item_ids = []; if(added_item) { // now that we've loaded, check for conflicts on the added item + + // Construct the presence map of zones that this added item uses. + var item_zones_presence_map = {}; item_zones = added_item.getAssetsFitting(outfit.pet_type).mapProperty('zone_id'); - item_zones_length = item_zones.length; + item_zones = item_zones.concat(added_item.restricted_zones); + for(var i = 0; i < item_zones.length; i++) { + item_zones_presence_map[item_zones[i]] = true; + } + + // Filter the existing items to those that do not use the same zones as + // the added item. Items that restrict or are restricted by the added + // item are also filtered out, despite not occupying any of the same + // zones. (Neopets.com shows an error message on restriction conflicts + // rather than unwearing, but that behavioral difference doesn't affect + // the set of possible outfits.) for(var i = 0; i < outfit.worn_items.length; i++) { existing_item = outfit.worn_items[i]; existing_item_zones = existing_item.getAssetsFitting(outfit.pet_type).mapProperty('zone_id'); + existing_item_zones = existing_item_zones.concat(existing_item.restricted_zones); passed = true; if(existing_item != added_item) { - for(var j = 0; j < item_zones_length; j++) { - if($.inArray(item_zones[j], existing_item_zones) != -1) { + for(var j = 0; j < existing_item_zones.length; j++) { + if(existing_item_zones[j] in item_zones_presence_map) { passed = false; break; }