public bool RemoveEntity(Entity user, Entity inventory, Entity toRemove, InventoryLocation location = InventoryLocation.Any) { var comHands = inventory.GetComponent <HumanHandsComponent>(ComponentFamily.Hands); var comEquip = inventory.GetComponent <EquipmentComponent>(ComponentFamily.Equipment); var comInv = inventory.GetComponent <InventoryComponent>(ComponentFamily.Inventory); if (location == InventoryLocation.Any) { return(RemoveEntity(user, inventory, toRemove, GetEntityLocationInEntity(inventory, toRemove))); } if ((location == InventoryLocation.Inventory) && comInv != null) { if (comInv.RemoveEntity(user, toRemove)) { //Do sprite stuff and detaching return(true); } } else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null) { if (comHands.RemoveEntity(user, toRemove)) { // TODO Find a better way FreeMovementAndSprite(toRemove); toRemove.SendMessage(this, ComponentMessageType.Dropped); return(true); } } else if ((location == InventoryLocation.Equipment) && comEquip != null) { if (comEquip.RemoveEntity(user, toRemove)) { //Do sprite stuff and detaching EquippableComponent eqCompo = toRemove.GetComponent <EquippableComponent>(ComponentFamily.Equippable); if (eqCompo != null) { eqCompo.currentWearer = null; } FreeMovementAndSprite(toRemove); // TODO Find a better way toRemove.SendMessage(this, ComponentMessageType.ItemUnEquipped); return(true); } } return(false); }
public bool AddEntity(Entity user, Entity inventory, Entity toAdd, InventoryLocation location = InventoryLocation.Any) { if (EntityIsInEntity(inventory, toAdd)) { RemoveEntity(user, inventory, toAdd, InventoryLocation.Any); } var comHands = inventory.GetComponent <HumanHandsComponent>(ComponentFamily.Hands); var comEquip = inventory.GetComponent <EquipmentComponent>(ComponentFamily.Equipment); var comInv = inventory.GetComponent <InventoryComponent>(ComponentFamily.Inventory); if ((location == InventoryLocation.Inventory) && comInv != null) { if (comInv.CanAddEntity(user, toAdd)) { HideEntity(toAdd); return(comInv.AddEntity(user, toAdd)); } } else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null) { if (comHands.CanAddEntity(user, toAdd, location)) { comHands.AddEntity(user, toAdd, location); ShowEntity(toAdd); //Do sprite stuff and attaching EnslaveMovementAndSprite(inventory, toAdd); toAdd.GetComponent <BasicItemComponent>(ComponentFamily.Item).HandlePickedUp(inventory, location); // TODO Find a better way toAdd.SendMessage(this, ComponentMessageType.PickedUp); return(true); } } else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null) { if (comEquip.CanAddEntity(user, toAdd)) { comEquip.AddEntity(user, toAdd); ShowEntity(toAdd); EnslaveMovementAndSprite(inventory, toAdd); EquippableComponent eqCompo = toAdd.GetComponent <EquippableComponent>(ComponentFamily.Equippable); eqCompo.currentWearer = user; toAdd.SendMessage(this, ComponentMessageType.ItemEquipped); //Do sprite stuff and attaching. return(true); } } else if (location == InventoryLocation.Any) { //Do sprite stuff and attaching. bool done = false; if (comInv != null) { done = comInv.AddEntity(user, toAdd); } if (comEquip != null && !done) { done = comEquip.AddEntity(user, toAdd); } if (comHands != null && !done) { done = comHands.AddEntity(user, toAdd, location); } return(done); } return(false); }
public bool AddEntity(Entity user, Entity inventory, Entity toAdd, InventoryLocation location = InventoryLocation.Any) { var comHands = inventory.GetComponent <HumanHandsComponent>(ComponentFamily.Hands); var comEquip = inventory.GetComponent <EquipmentComponent>(ComponentFamily.Equipment); var comInv = inventory.GetComponent <InventoryComponent>(ComponentFamily.Inventory); if ((location == InventoryLocation.Inventory) && comInv != null) { if (comInv.AddEntity(user, toAdd)) { //Do sprite stuff and attaching return(true); } } else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null) { if (comHands.AddEntity(user, toAdd, location)) { //Do sprite stuff and attaching toAdd.RemoveComponent(ComponentFamily.Mover); toAdd.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent <SlaveMoverComponent>()); toAdd.GetComponent <SlaveMoverComponent>(ComponentFamily.Mover).Attach(inventory); if (toAdd.HasComponent(ComponentFamily.Renderable) && inventory.HasComponent(ComponentFamily.Renderable)) { toAdd.GetComponent <IRenderableComponent>(ComponentFamily.Renderable).SetMaster(inventory); } toAdd.GetComponent <BasicItemComponent>(ComponentFamily.Item).HandlePickedUp(inventory, location); return(true); } } else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null) { if (comEquip.AddEntity(user, toAdd)) { EquippableComponent eqCompo = toAdd.GetComponent <EquippableComponent>(ComponentFamily.Equippable); eqCompo.currentWearer = user; //Do sprite stuff and attaching. return(true); } } else if (location == InventoryLocation.Any) { //Do sprite stuff and attaching. bool done = false; if (comInv != null) { done = comInv.AddEntity(user, toAdd); } if (comEquip != null && !done) { done = comEquip.AddEntity(user, toAdd); } if (comHands != null && !done) { done = comHands.AddEntity(user, toAdd, location); } return(done); } return(false); }
public bool RemoveEntity(Entity user, Entity inventory, Entity toRemove, InventoryLocation location = InventoryLocation.Any) { var comHands = inventory.GetComponent <HumanHandsComponent>(ComponentFamily.Hands); var comEquip = inventory.GetComponent <EquipmentComponent>(ComponentFamily.Equipment); var comInv = inventory.GetComponent <InventoryComponent>(ComponentFamily.Inventory); if ((location == InventoryLocation.Inventory) && comInv != null) { if (comInv.RemoveEntity(user, toRemove)) { //Do sprite stuff and detaching return(true); } } else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null) { if (comHands.RemoveEntity(user, toRemove)) { //Do sprite stuff and attaching var toRemoveSlaveMover = toRemove.GetComponent <SlaveMoverComponent>(ComponentFamily.Mover); if (toRemoveSlaveMover != null) { toRemoveSlaveMover.Detach(); } if (toRemove.HasComponent(ComponentFamily.Renderable)) { toRemove.GetComponent <IRenderableComponent>(ComponentFamily.Renderable).UnsetMaster(); } toRemove.RemoveComponent(ComponentFamily.Mover); toRemove.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent <BasicMoverComponent>()); toRemove.GetComponent <BasicItemComponent>(ComponentFamily.Item).HandleDropped(); return(true); } } else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null) { if (comEquip.RemoveEntity(user, toRemove)) { //Do sprite stuff and detaching EquippableComponent eqCompo = toRemove.GetComponent <EquippableComponent>(ComponentFamily.Equippable); if (eqCompo != null) { eqCompo.currentWearer = null; } return(true); } } else if (location == InventoryLocation.Any) { //Do sprite stuff and detaching bool done = false; if (comInv != null) { done = comInv.RemoveEntity(user, toRemove); } if (comEquip != null && !done) { done = comEquip.RemoveEntity(user, toRemove); } if (comHands != null && !done) { done = comHands.RemoveEntity(user, toRemove); } return(done); } return(false); }