/// <summary> /// 执行命令 /// </summary> /// <param name="entity">Entity.</param> /// <param name="command">Command.</param> private bool ExecuteCommand(Entity entity, Command command) { if (entity == null || command == null) { return(false); } _Running = true; string methodName = GetMethod(command.ID); if (methodName == null) { return(false); } if (command.Paramter == null) { entity.SendMessage(methodName); } else if (command.Paramter.Length == 1) { entity.SendMessage(methodName, command.Paramter[0]); } else { entity.SendMessage(methodName, command.Paramter); } return(true); }
private void GamePadUpProcess(object sender, GamePadEventArgs e) { Entity en = p_States.Buttons[(int)e.Button]; if (en != null) { if (e.Button == en.GamePadActions.Press) { en.SendMessage(Message.Click, new MouseEventArgs(new MouseState(), MouseButtons.None, Point.Zero)); } p_States.Click = -1; p_States.Buttons[(int)e.Button] = null; en.SendMessage(Message.GamePadUp, e); } }
private void KeyUpProcess(object sender, KeyEventArgs e) { Entity en = p_States.Buttons[(int)MouseButtons.None]; if (en != null) { if (e.Key == Keys.Space) { en.SendMessage(Message.Click, new MouseEventArgs(new MouseState(), MouseButtons.None, Point.Zero)); } p_States.Click = -1; p_States.Buttons[(int)MouseButtons.None] = null; en.SendMessage(Message.KeyUp, e); } }
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); }
//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); } }
private void SandHeldByEntity() { foreach (List <GameObject> list in BigList) { if (list == littleSand) { sandAmount = littleAmount; } if (list == mediumSand) { sandAmount = mediumAmount; } if (list == highSand) { sandAmount = highAmount; } if (list == extremeSand) { sandAmount = extremeAmount; } foreach (GameObject Entity in list) { Entity.SendMessage("DropSand", sandAmount); } } }
public ExamineWindow(Size size, Entity entity, IResourceManager resourceManager) : base(entity.Name, size, resourceManager) { _resourceManager = resourceManager; _entityDescription = new Label(entity.GetDescriptionString(), "CALIBRI", _resourceManager); components.Add(_entityDescription); ComponentReplyMessage reply = entity.SendMessage(entity, ComponentFamily.Renderable, ComponentMessageType.GetSprite); SetVisible(true); if (reply.MessageType == ComponentMessageType.CurrentSprite) { _entitySprite = (Sprite)reply.ParamsList[0]; _entityDescription.Position = new Point(10, (int)_entitySprite.Height + _entityDescription.ClientArea.Height + 10); } else { _entityDescription.Position = new Point(10, 10); } }
private void MouseUpProcess(object sender, MouseEventArgs e) { Entity en = p_States.Buttons[(int)e.Button]; if (en != null) { if (CheckPosition(en, e.Position) && CheckOrder(en, e.Position) && p_States.Click == (int)e.Button && CheckButtons((int)e.Button)) { en.SendMessage(Message.Click, e); } p_States.Click = -1; en.SendMessage(Message.MouseUp, e); p_States.Buttons[(int)e.Button] = null; MouseMoveProcess(sender, e); } }
/// <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 KeyPressProcess(object sender, KeyEventArgs e) { Entity en = p_States.Buttons[(int)MouseButtons.None]; if (en != null) { en.SendMessage(Message.KeyPress, e); if ((e.Key == Keys.Right || e.Key == Keys.Left || e.Key == Keys.Up || e.Key == Keys.Down) && !e.Handled && CheckButtons((int)MouseButtons.None)) { ProcessArrows(en, e, new GamePadEventArgs(PlayerIndex.One)); KeyDownProcess(sender, e); } else if (e.Key == Keys.Tab && !e.Shift && !e.Handled && CheckButtons((int)MouseButtons.None)) { TabNextEntity(en); KeyDownProcess(sender, e); } else if (e.Key == Keys.Tab && e.Shift && !e.Handled && CheckButtons((int)MouseButtons.None)) { TabPrevEntity(en); KeyDownProcess(sender, e); } } }
void Update() { for (int i = 0; i < timers.Count; i++) { var timer = timers[i]; if (timer.IsDone) { continue; } else if (timer.Counter >= timer.Message.Delay) { switch (timer.Message.Trigger) { case TriggerModes.Once: timer.IsDone = true; break; case TriggerModes.Repeat: timer.Counter -= timer.Message.Delay; break; } Entity.SendMessage(timer.Message.Message); } else { timer.Counter += Time.DeltaTime; } timers[i] = timer; } }
void Update() { for (int i = 0; i < Messages.Length; i++) { var message = Messages[i]; bool triggered = false; switch (message.Trigger) { case TriggerModes.Pressed: triggered = inputManager.GetKey(message.Player, message.Action); break; case TriggerModes.Down: triggered = inputManager.GetKeyDown(message.Player, message.Action); break; case TriggerModes.Up: triggered = inputManager.GetKeyUp(message.Player, message.Action); break; } if (triggered) { Entity.SendMessage(message.Message); } } }
private void GamePadPressProcess(object sender, GamePadEventArgs e) { Entity en = p_States.Buttons[(int)e.Button]; if (en != null) { en.SendMessage(Message.GamePadPress, e); if ((e.Button == en.GamePadActions.Right || e.Button == en.GamePadActions.Left || e.Button == en.GamePadActions.Up || e.Button == en.GamePadActions.Down) && !e.Handled && CheckButtons((int)e.Button)) { ProcessArrows(en, new KeyEventArgs(), e); GamePadDownProcess(sender, e); } else if (e.Button == en.GamePadActions.NextControl && !e.Handled && CheckButtons((int)e.Button)) { TabNextEntity(en); GamePadDownProcess(sender, e); } else if (e.Button == en.GamePadActions.PrevControl && !e.Handled && CheckButtons((int)e.Button)) { TabPrevEntity(en); GamePadDownProcess(sender, e); } } }
private void Collided(Entity other, Vector3 point) { Entity explos = Entity.Instantiate(); explos.Attach <TransformComponent>().Position = point; explos.Attach <ExplosionComponent>(); if (other.Has <AircraftComponent>()) { var aircraftPhysics = other.Get <PhysicsComponent>(); Vector3 velocity_missile = Physics.Velocity; aircraftPhysics.Force += velocity_missile * 5; Vector3 angler_force = Vector3.Outer(aircraftPhysics.Velocity, velocity_missile); aircraftPhysics.Torque += angler_force * 0.02f; aircraftPhysics.Velocity = aircraftPhysics.Velocity * 0.8f; var aircraft = other.Get <AircraftComponent>(); aircraft.Damage(Damage); if (this.FromPlayer) { if (aircraft.Armor > 0) { Entity.SendMessage(Entity.Find("ui"), "notice", "Hit"); } else { Entity.SendMessage(Entity.Find("ui"), "notice", "Destroyed"); } } } if (other.Name == "player") { Entity.SendMessage(Entity.Find("ui"), "notice", "Damaged"); } { Entity e = Entity.Instantiate(); e.Attach(this.Owner.Detach <MissileSmokeComponent>()); } { Entity e = Entity.Instantiate(); e.Attach(new TransformComponent() { Position = point }); e.Attach(new SoundComponent(ExplosionSound, true)); e.Attach(new TimerComponent() { CountSpeed = 0.001f, Repeat = false }); e.Get <TimerComponent>().Ticked += () => { Entity.Kill(e); }; } Entity.Kill(this.Owner); }
private bool DoEmptyHandToLargeObjectInteraction(Entity user, Entity obj) { // Send a message to obj that it has been clicked by user. obj.SendMessage(user, ComponentMessageType.ReceiveEmptyHandToLargeObjectInteraction, new object[1] { user }); return(true); }
private void Collided(Entity other, Vector3 point) { if (other.Has <AircraftComponent>()) { Entity e = Entity.Instantiate(); e.Attach(new TransformComponent() { Position = point }); //e.Attach<GunBulletSmokeComponent>(); e.Attach(new LimitedLifeTimeComponent() { CountSpeed = 0.04f }); var soundComponent = new SoundComponent(BulletHitSound); soundComponent.VolumeFactor = 0.5f; e.Attach(soundComponent); soundComponent.Play(); var aircraft = other.Get <AircraftComponent>(); aircraft.Damage(Damage); if (this.ShootedByPlayer) { if (aircraft.Armor > 0) { Entity.SendMessage(Entity.Find("ui"), "notice", "Hit"); } else { Entity.SendMessage(Entity.Find("ui"), "notice", "Destroyed"); } } if (other.Name == "player") { Entity.SendMessage(Entity.Find("ui"), "notice", "Damaged"); } } else if (other.Has <GroundComponent>()) { Entity e = Entity.Instantiate(); e.Attach(new TransformComponent() { Position = point }); e.Attach <GunBulletSmokeComponent>(); e.Attach(new LimitedLifeTimeComponent() { CountSpeed = 0.04f }); var soundComponent = new SoundComponent(BulletHitSound); soundComponent.VolumeFactor = 0.5f; e.Attach(soundComponent); soundComponent.Play(); } Entity.Kill(this.Owner); }
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))); }
private void Setup() { ComponentReplyMessage reply = assigned.SendMessage(this, ComponentFamily.Damageable, ComponentMessageType.GetCurrentLocationHealth, BodyPart.Head); if (reply.MessageType == ComponentMessageType.CurrentLocationHealth) { _head.Color = GetColor((int)reply.ParamsList[1], (int)reply.ParamsList[2]); } reply = assigned.SendMessage(this, ComponentFamily.Damageable, ComponentMessageType.GetCurrentLocationHealth, BodyPart.Torso); if (reply.MessageType == ComponentMessageType.CurrentLocationHealth) { _chest.Color = GetColor((int)reply.ParamsList[1], (int)reply.ParamsList[2]); } reply = assigned.SendMessage(this, ComponentFamily.Damageable, ComponentMessageType.GetCurrentLocationHealth, BodyPart.Left_Arm); if (reply.MessageType == ComponentMessageType.CurrentLocationHealth) { _arml.Color = GetColor((int)reply.ParamsList[1], (int)reply.ParamsList[2]); } reply = assigned.SendMessage(this, ComponentFamily.Damageable, ComponentMessageType.GetCurrentLocationHealth, BodyPart.Right_Arm); if (reply.MessageType == ComponentMessageType.CurrentLocationHealth) { _armr.Color = GetColor((int)reply.ParamsList[1], (int)reply.ParamsList[2]); } reply = assigned.SendMessage(this, ComponentFamily.Damageable, ComponentMessageType.GetCurrentLocationHealth, BodyPart.Groin); if (reply.MessageType == ComponentMessageType.CurrentLocationHealth) { _groin.Color = GetColor((int)reply.ParamsList[1], (int)reply.ParamsList[2]); } reply = assigned.SendMessage(this, ComponentFamily.Damageable, ComponentMessageType.GetCurrentLocationHealth, BodyPart.Left_Leg); if (reply.MessageType == ComponentMessageType.CurrentLocationHealth) { _legl.Color = GetColor((int)reply.ParamsList[1], (int)reply.ParamsList[2]); } reply = assigned.SendMessage(this, ComponentFamily.Damageable, ComponentMessageType.GetCurrentLocationHealth, BodyPart.Right_Leg); if (reply.MessageType == ComponentMessageType.CurrentLocationHealth) { _legr.Color = GetColor((int)reply.ParamsList[1], (int)reply.ParamsList[2]); } if (assigned.HasComponent(ComponentFamily.Damageable)) { var comp = (HealthComponent)assigned.GetComponent(ComponentFamily.Damageable); _overallHealth.Text = comp.GetHealth().ToString() + " / " + comp.GetMaxHealth().ToString(); } }
private void GamePadDownProcess(object sender, GamePadEventArgs e) { Entity en = FocusedControl; if (en != null && CheckState(en)) { if (p_States.Click == -1) { p_States.Click = (int)e.Button; } p_States.Buttons[(int)e.Button] = en; en.SendMessage(Message.GamePadDown, e); if (e.Button == en.GamePadActions.Click) { en.SendMessage(Message.Click, new MouseEventArgs(new MouseState(), MouseButtons.None, Point.Zero)); } } }
/// <summary> /// Try to create an entity in the given scene with the given class name /// </summary> /// <param name="className"></param> /// <param name="keyValues"></param> /// <param name="entity"></param> public bool TryCreateEntity(string className, IReadOnlyList <KeyValuePair <string, string> > keyValues, out Entity entity) { if (className == null) { throw new ArgumentNullException(nameof(className)); } if (keyValues == null) { throw new ArgumentNullException(nameof(keyValues)); } if (!Scene.EntitySystemMetaData.EntityFactories.TryGetValue(className, out var factory)) { entity = null; Logger.Warning("No entity factory for class {ClassName}", className); return(false); } entity = CreateUninitializedEntity(className, factory); entity.SendMessage(BuiltInComponentMethods.Initialize); if (!factory.Initialize(this, entity, keyValues)) { Scene.DestroyEntity(entity); entity = null; Logger.Warning("Failed to initialize entity of class {ClassName}", className); return(false); } //If the scene is already running, all components should be activated now if (EntitySystem.Scene.Running) { entity.SendMessage(BuiltInComponentMethods.Activate); } entity._activated = true; return(true); }
private void KeyDownProcess(object sender, KeyEventArgs e) { Entity en = FocusedControl; if (en != null && CheckState(en)) { if (p_States.Click == -1) { p_States.Click = (int)MouseButtons.None; } p_States.Buttons[(int)MouseButtons.None] = en; en.SendMessage(Message.KeyDown, e); if (e.Key == Keys.Enter) { en.SendMessage(Message.Click, new MouseEventArgs(new MouseState(), MouseButtons.None, Point.Zero)); } } }
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))); }
public ContextMenu(Entity entity, Vector2f creationPos, IResourceManager resourceManager, IUserInterfaceManager userInterfaceManager, bool showExamine = true) { _owningEntity = entity; _resourceManager = resourceManager; _userInterfaceManager = userInterfaceManager; var entries = new List<ContextMenuEntry>(); var replies = new List<ComponentReplyMessage>(); entity.SendMessage(this, ComponentMessageType.ContextGetEntries, replies); if (replies.Any()) entries = (List<ContextMenuEntry>) replies.First(x => x.MessageType == ComponentMessageType.ContextGetEntries).ParamsList[0]; if (showExamine) { var examineButton = new ContextMenuButton( new ContextMenuEntry {ComponentMessage = "examine", EntryName = "Examine", IconName = "context_eye"}, _buttonSize, _resourceManager); examineButton.Selected += ContextSelected; _buttons.Add(examineButton); examineButton.Update(0); } var sVarButton = new ContextMenuButton( new ContextMenuEntry {ComponentMessage = "svars", EntryName = "SVars", IconName = "context_eye"}, _buttonSize, _resourceManager); sVarButton.Selected += ContextSelected; _buttons.Add(sVarButton); sVarButton.Update(0); foreach (ContextMenuEntry entry in entries) { var newButton = new ContextMenuButton(entry, _buttonSize, _resourceManager); newButton.Selected += ContextSelected; _buttons.Add(newButton); newButton.Update(0); } float currY = creationPos.Y; foreach (ContextMenuButton button in _buttons) { button.Position = new Vector2i((int) creationPos.X, (int) currY); currY += _buttonSize.Y; } ClientArea = new IntRect((int) creationPos.X, (int) creationPos.Y, (int) _buttonSize.X, _buttons.Count()*(int) _buttonSize.Y); }
public static Sprite GetSpriteComponentSprite(Entity entity) { ComponentReplyMessage reply = entity.SendMessage(entity, ComponentFamily.Renderable, ComponentMessageType.GetSprite); if (reply.MessageType == ComponentMessageType.CurrentSprite) { var sprite = (Sprite) reply.ParamsList[0]; return sprite; } return null; }
void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Entity")) { Entity entity = other.GetComponent <Entity>(); if (entity.CurrentState == EntityState.Going_Home) { entity.SendMessage("EnterHome"); } } }
private void MousePressProcess(object sender, MouseEventArgs e) { Entity en = p_States.Buttons[(int)e.Button]; if (en != null) { if (CheckPosition(en, e.Position)) { en.SendMessage(Message.MousePress, e); } } }
public static Sprite GetSpriteComponentSprite(Entity entity) { ComponentReplyMessage reply = entity.SendMessage(entity, ComponentFamily.Renderable, ComponentMessageType.GetSprite); if (reply.MessageType == ComponentMessageType.CurrentSprite) { var sprite = (Sprite)reply.ParamsList[0]; return(sprite); } return(null); }
/// <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); } }
void SendMessage(UIEvents uiEvent, BaseEventData eventData) { for (int i = 0; i < Messages.Length; i++) { var message = Messages[i]; if (Active && Entity != null && (message.Events & uiEvent) != 0) { Entity.SendMessage(message.Message, eventData); } } }
void SendMessage <T>(PhysicsEvents behaviourEvent, T data) { for (int i = 0; i < Messages.Length; i++) { var message = Messages[i]; if (Active && Entity != null && (message.Events & behaviourEvent) != 0) { Entity.SendMessage(message.Message, data); } } }
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); } } }
public override bool Update(MonoBehaviour behaviour, Sequencer.StateInstance state) { bool done = true; Entity e = ((SceneController.StateData)state).entity; if (e != null) { e.SendMessage("OnSceneCounterCheck", state, SendMessageOptions.RequireReceiver); done = state.counter == counter; } return(done); }
/// <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 ExamineWindow(Size size, Entity entity, IResourceManager resourceManager) : base(entity.Name, size, resourceManager) { _resourceManager = resourceManager; _entityDescription = new Label(entity.GetDescriptionString(), "CALIBRI", _resourceManager); components.Add(_entityDescription); ComponentReplyMessage reply = entity.SendMessage(entity, ComponentFamily.Renderable, ComponentMessageType.GetSprite); SetVisible(true); if (reply.MessageType == ComponentMessageType.CurrentSprite) { _entitySprite = (CluwneSprite) reply.ParamsList[0]; _entityDescription.Position = new Point(10, (int) _entitySprite.Height + _entityDescription.ClientArea.Height + 10); } else _entityDescription.Position = new Point(10, 10); }
// Equips Entity e and automatically finds the appropriate part public 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); } } }
// Equips Entity e to Part part public 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); } }
/// <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; }
private void HandleAdded(Entity entity) { entity.SendMessage(this, ComponentMessageType.PickedUp, Owner, InventoryLocation.None); entity.SendMessage(this, ComponentMessageType.SetVisible, false); }
private void HandleRemoved(Entity entity) { entity.SendMessage(this, ComponentMessageType.Dropped); entity.SendMessage(this, ComponentMessageType.SetVisible, true); }
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; }