//Adds item to inventory and dispatches hide message to sprite compo. private void AddToInventory(Entity entity) { if (!containedEntities.Contains(entity) && containedEntities.Count < maxSlots) { Entity holder = null; if (entity.HasComponent(ComponentFamily.Item)) { holder = ((BasicItemComponent)entity.GetComponent(ComponentFamily.Item)).CurrentHolder; } if (holder == null && entity.HasComponent(ComponentFamily.Equippable)) { holder = ((EquippableComponent)entity.GetComponent(ComponentFamily.Equippable)).currentWearer; } if (holder != null) { holder.SendMessage(this, ComponentMessageType.DisassociateEntity, entity); } else { Owner.SendMessage(this, ComponentMessageType.DisassociateEntity, entity); } containedEntities.Add(entity); HandleAdded(entity); Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null, ComponentMessageType.InventoryUpdateRequired); } }
/// <summary> /// Entry point for interactions between an item and this object /// Basically, the actor uses an item on this object /// </summary> /// <param name="actor">the actor entity</param> protected void HandleItemToLargeObjectInteraction(Entity actor) { //Get the item ComponentReplyMessage reply = actor.SendMessage(this, ComponentFamily.Hands, ComponentMessageType.GetActiveHandItem); if (reply.MessageType != ComponentMessageType.ReturnActiveHandItem) { return; // No item in actor's active hand. This shouldn't happen. } var item = (Entity)reply.ParamsList[0]; reply = item.SendMessage(this, ComponentFamily.Item, ComponentMessageType.ItemGetCapabilityVerbPairs); if (reply.MessageType == ComponentMessageType.ItemReturnCapabilityVerbPairs) { var verbs = (Lookup <ItemCapabilityType, ItemCapabilityVerb>)reply.ParamsList[0]; if (verbs.Count == 0 || verbs == null) { RecieveItemInteraction(actor, item); } else { RecieveItemInteraction(actor, item, verbs); } } }
private void PlaceItem(Entity actor, Entity item) { var rnd = new Random(); actor.SendMessage(this, ComponentMessageType.DropItemInCurrentHand); item.GetComponent <SpriteComponent>(ComponentFamily.Renderable).drawDepth = DrawDepth.ItemsOnTables; //TODO Unsafe, fix. item.GetComponent <TransformComponent>(ComponentFamily.Transform).TranslateByOffset( new Vector2(rnd.Next(-28, 28), rnd.Next(-28, 15))); }
/// <summary> /// Put the specified entity in the specified hand /// </summary> /// <param name="entity"></param> private void Pickup(Entity entity, InventoryLocation hand) { if (entity != null && IsEmpty(hand)) { RemoveFromOtherComps(entity); SetEntity(hand, entity); Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null, ComponentMessageType.HandsPickedUpItem, entity.Uid, hand); entity.SendMessage(this, ComponentMessageType.PickedUp, Owner, hand); } }
private void ActivateItemInHand() { InventoryLocation h = GetCurrentHand(); if (!IsEmpty(h)) { Entity e = GetEntity(h); if (e != null) { e.SendMessage(this, ComponentFamily.Item, ComponentMessageType.Activate); } } }
public override void HandleInstantiationMessage(NetConnection netConnection) { foreach (EquipmentSlot p in equippedEntities.Keys) { if (!IsEmpty(p)) { Entity e = equippedEntities[p]; e.SendMessage(this, ComponentMessageType.ItemEquipped, Owner); //Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, netConnection, // EquipmentComponentNetMessage.ItemEquipped, p, e.Uid); } } }
// Equips Entity e to Part part private void EquipEntityToPart(EquipmentSlot part, Entity e) { if (equippedEntities.ContainsValue(e)) //Its already equipped? Unequip first. This shouldnt happen. { UnEquipEntity(e); } if (CanEquip(e)) //If the part is empty, the part exists on this mob, and the entity specified is not null { RemoveFromOtherComps(e); equippedEntities.Add(part, e); e.SendMessage(this, ComponentMessageType.ItemEquipped, Owner); //Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null, // EquipmentComponentNetMessage.ItemEquipped, part, e.Uid); } }
// Equips Entity e and automatically finds the appropriate part private void EquipEntity(Entity e) { if (equippedEntities.ContainsValue(e)) //Its already equipped? Unequip first. This shouldnt happen. { UnEquipEntity(e); } if (CanEquip(e)) { ComponentReplyMessage reply = e.SendMessage(this, ComponentFamily.Equippable, ComponentMessageType.GetWearLoc); if (reply.MessageType == ComponentMessageType.ReturnWearLoc) { RemoveFromOtherComps(e); EquipEntityToPart((EquipmentSlot)reply.ParamsList[0], e); } } }
private bool CanEquip(Entity e) { if (!e.HasComponent(ComponentFamily.Equippable)) { return(false); } ComponentReplyMessage reply = e.SendMessage(this, ComponentFamily.Equippable, ComponentMessageType.GetWearLoc); if (reply.MessageType == ComponentMessageType.ReturnWearLoc) { if (IsItem(e) && IsEmpty((EquipmentSlot)reply.ParamsList[0]) && e != null && activeSlots.Contains((EquipmentSlot)reply.ParamsList[0])) { return(true); } } return(false); }
private void RemoveFromOtherComps(Entity entity) { Entity holder = null; if (entity.HasComponent(ComponentFamily.Item)) { holder = ((BasicItemComponent)entity.GetComponent(ComponentFamily.Item)).CurrentHolder; } if (holder == null && entity.HasComponent(ComponentFamily.Equippable)) { holder = ((EquippableComponent)entity.GetComponent(ComponentFamily.Equippable)).currentWearer; } if (holder != null) { holder.SendMessage(this, ComponentMessageType.DisassociateEntity, entity); } else { Owner.SendMessage(this, ComponentMessageType.DisassociateEntity, entity); } }
/// <summary> /// Entry point for interactions between an item and this object /// Basically, the actor uses an item on this object /// </summary> /// <param name="actor">the actor entity</param> protected void HandleItemToLargeObjectInteraction(Entity actor) { //Get the item ComponentReplyMessage reply = actor.SendMessage(this, ComponentFamily.Hands, ComponentMessageType.GetActiveHandItem); if (reply.MessageType != ComponentMessageType.ReturnActiveHandItem) return; // No item in actor's active hand. This shouldn't happen. var item = (Entity) reply.ParamsList[0]; reply = item.SendMessage(this, ComponentFamily.Item, ComponentMessageType.ItemGetCapabilityVerbPairs); if (reply.MessageType == ComponentMessageType.ItemReturnCapabilityVerbPairs) { var verbs = (Lookup<ItemCapabilityType, ItemCapabilityVerb>) reply.ParamsList[0]; if (verbs.Count == 0 || verbs == null) RecieveItemInteraction(actor, item); else RecieveItemInteraction(actor, item, verbs); } }
public void LoadEntity(XElement e) { float X = float.Parse(e.Attribute("X").Value, CultureInfo.InvariantCulture); float Y = float.Parse(e.Attribute("Y").Value, CultureInfo.InvariantCulture); var dir = Direction.South; if (e.Attribute("direction") != null) { dir = (Direction)Enum.Parse(typeof(Direction), e.Attribute("direction").Value, true); } string template = e.Attribute("template").Value; string name = e.Attribute("name").Value; Entity ent = SpawnEntity(template); ent.Name = name; ent.GetComponent <TransformComponent>(ComponentFamily.Transform).TranslateTo(new Vector2(X, Y)); ent.GetComponent <DirectionComponent>(ComponentFamily.Direction).Direction = dir; ent.SendMessage(this, ComponentMessageType.WallMountSearch); //Tell wall mounted compos to look for a tile to attach to. I hate to do this here but i have to. }
// Equips Entity e to Part part private void EquipEntityToPart(EquipmentSlot part, Entity e) { if (equippedEntities.ContainsValue(e)) //Its already equipped? Unequip first. This shouldnt happen. UnEquipEntity(e); if (CanEquip(e)) //If the part is empty, the part exists on this mob, and the entity specified is not null { RemoveFromOtherComps(e); equippedEntities.Add(part, e); e.SendMessage(this, ComponentMessageType.ItemEquipped, Owner); //Owner.SendDirectedComponentNetworkMessage(this, NetDeliveryMethod.ReliableOrdered, null, // EquipmentComponentNetMessage.ItemEquipped, part, e.Uid); } }
private void HandleAdded(Entity entity) { entity.SendMessage(this, ComponentMessageType.PickedUp, Owner, Hand.None); entity.SendMessage(this, ComponentMessageType.SetVisible, false); }
private void HandleRemoved(Entity entity) { entity.SendMessage(this, ComponentMessageType.Dropped); entity.SendMessage(this, ComponentMessageType.SetVisible, true); }
/// <summary> /// Entry point for interactions between an empty hand and this item /// Basically, the actor touches this item with an empty hand /// </summary> /// <param name="actor"></param> public virtual void HandleEmptyHandToItemInteraction(Entity actor) { //Pick up the item actor.SendMessage(this, ComponentMessageType.PickUpItem, Owner); }
private bool CanEquip(Entity e) { if (!e.HasComponent(ComponentFamily.Equippable)) return false; ComponentReplyMessage reply = e.SendMessage(this, ComponentFamily.Equippable, ComponentMessageType.GetWearLoc); if (reply.MessageType == ComponentMessageType.ReturnWearLoc) { if (IsItem(e) && IsEmpty((EquipmentSlot) reply.ParamsList[0]) && e != null && activeSlots.Contains((EquipmentSlot) reply.ParamsList[0])) { return true; } } return false; }
// Equips Entity e and automatically finds the appropriate part private void EquipEntity(Entity e) { if (equippedEntities.ContainsValue(e)) //Its already equipped? Unequip first. This shouldnt happen. UnEquipEntity(e); if (CanEquip(e)) { ComponentReplyMessage reply = e.SendMessage(this, ComponentFamily.Equippable, ComponentMessageType.GetWearLoc); if (reply.MessageType == ComponentMessageType.ReturnWearLoc) { RemoveFromOtherComps(e); EquipEntityToPart((EquipmentSlot) reply.ParamsList[0], e); } } }