private void SetNewState(HandsComponentState state)
        {
            bool changed     = false;
            var  currentHand = Hand.None;

            if (state.ActiveHand == InventoryLocation.HandLeft)
            {
                currentHand = Hand.Left;
            }
            if (state.ActiveHand == InventoryLocation.HandRight)
            {
                currentHand = Hand.Right;
            }
            if (CurrentHand != currentHand)
            {
                changed     = true;
                CurrentHand = currentHand;
            }
            foreach (var handSlot in state.Slots.Keys)
            {
                var hand = inventoryLocationToHand(handSlot);
                if (!HandSlots.ContainsKey(hand))
                {
                    HandSlots.Add(hand, null);
                    changed = true;
                }
                var existingSlotUid = HandSlots[hand] == null ? null : (int?)HandSlots[hand].Uid;
                var newSlotUid      = state.Slots[handSlot];
                if (existingSlotUid == null)
                {
                    if (newSlotUid != null)
                    {
                        HandSlots[hand] = Owner.EntityManager.GetEntity((int)newSlotUid);
                        changed         = true;
                    }
                }
                else
                {
                    if (newSlotUid != existingSlotUid)
                    {
                        if (newSlotUid != null)
                        {
                            HandSlots[hand] = Owner.EntityManager.GetEntity((int)newSlotUid);
                        }
                        else
                        {
                            HandSlots[hand] = null;
                        }

                        changed = true;
                    }
                }
            }
            if (changed)
            {
                IoCManager.Resolve <IUserInterfaceManager>().ComponentUpdate(GuiComponentType.HandsUi);
            }
        }
        public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
        {
            var    type = (ComponentMessageType)message.MessageParameters[0];
            int    entityUid;
            Hand   usedHand;
            Entity item;

            switch (type)
            {
            case (ComponentMessageType.EntityChanged):
                //This is not sent atm. Commented out serverside for later use.
                entityUid = (int)message.MessageParameters[1];
                usedHand  = (Hand)message.MessageParameters[2];
                item      = Owner.EntityManager.GetEntity(entityUid);
                if (HandSlots.Keys.Contains(usedHand))
                {
                    HandSlots[usedHand] = item;
                }
                else
                {
                    HandSlots.Add(usedHand, item);
                }
                break;

            case (ComponentMessageType.HandsDroppedItem):
                //entityUid = (int)message.MessageParameters[1];
                usedHand = (Hand)message.MessageParameters[2];
                //item = EntityManager.Singleton.GetEntity(entityUid);
                //item.SendMessage(this, ComponentMessageType.Dropped, null);
                HandSlots.Remove(usedHand);
                break;

            case (ComponentMessageType.HandsPickedUpItem):
                entityUid = (int)message.MessageParameters[1];
                usedHand  = (Hand)message.MessageParameters[2];
                item      = Owner.EntityManager.GetEntity(entityUid);
                //item.SendMessage(this, ComponentMessageType.PickedUp, null, usedHand);
                HandSlots.Add(usedHand, item);
                break;

            case ComponentMessageType.ActiveHandChanged:
                SwitchHandTo((Hand)message.MessageParameters[1]);
                break;
            }

            IoCManager.Resolve <IUserInterfaceManager>().ComponentUpdate(GuiComponentType.HandsUi);
        }
 public bool IsHandEmpty(Hand hand)
 {
     return(!HandSlots.ContainsKey(hand));
 }
Ejemplo n.º 4
0
 public bool IsHandEmpty(InventoryLocation hand)
 {
     return(!HandSlots.ContainsKey(hand));
 }