I've been working on a little snippet of code that equips and un-equips items by checking the layer they are on.

Code:
if (mUseItem is BaseArmor)
			{
				var Layer = mUseItem.Layer;
				Item RemoveItem = from.FindItemOnLayer(Layer);
				
				mPouch.DropItem(RemoveItem);
				
				from.EquipItem(mUseItem);
			}
			else if (mUseItem is BaseWeapon)
			{
				var Layer = mUseItem.Layer;
				Item RemoveItem = from.FindItemOnLayer(Layer);
				
				mPouch.DropItem(RemoveItem);
				
				from.EquipItem(mUseItem);
			}
Armor is working just great! But, I've noticed that weapons can have MANY possible layers,
I've seen FirstValid, OneHanded and TwoHanded so far.

I'm looking for help on how I could implement a check to see what weapon is equipped currently, regardless of layer. I'm not sure how to do that, or if it's a possible check that can be made.

Or, perhaps check all three of those layers and see if one comes back valid, and then remove it.

Would that be going too far? Any Advice?
 
Welp, I guess typing out the question I figured out the answer! It was to check the other Layers first!
It's working great. Here's what I did.

Code:
if (mUseItem is BaseArmor)
			{
				var Layer = mUseItem.Layer;
				Item RemoveItem = from.FindItemOnLayer(Layer);
				
				mPouch.DropItem(RemoveItem);
				
				from.EquipItem(mUseItem);
			}
			else if (mUseItem is BaseWeapon)
			{
				var Layer = mUseItem.Layer;
				var OneH = from.FindItemOnLayer(Layer.OneHanded);
				var TwoH = from.FindItemOnLayer(Layer.TwoHanded);
				if (OneH != null)
				{
					Item RemoveItem = from.FindItemOnLayer(Layer.OneHanded);
					mPouch.DropItem(RemoveItem);
				}	
				else if (TwoH != null)
				{
					Item RemoveItem = from.FindItemOnLayer(Layer.TwoHanded);
					mPouch.DropItem(RemoveItem);
				}
				
				
				
				from.EquipItem(mUseItem);
			}
 
FWIW, most major equipment have direct properties on the Mobile to access them, mob.Weapon for example and others such as mob.NeckArmor, mob.ChestArmor, etc. Perhaps using mob.Weapon will make things easier, even though you seem to have resolved your issue :p
mob.Weapon is an IWeapon, so you'd have to convert it to BaseWeapon to access it's Layer and such.
At any rate, good work on resolving your own issue :D
 
Back