Example #1
0
 /// <summary>
 /// Can be called on server or local player to equip an item
 /// to the main attachment slot.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="unequipIfOccupied"></param>
 public void Equip(UsableItem item,  bool unequipIfOccupied = false)
 {
     if (isLocalPlayer)
         Equip(GetMainInput(), item, unequipIfOccupied);
     else if(isServer)
     {
         // todo...
         //RpcEquipToMain(item.gameObject);
     }
 }
Example #2
0
 protected AttachmentSlot FindAttachmentSlot(UsableItem item)
 {
     return(_attachmentSlots.Find(x => x.item == item));
 }
Example #3
0
 protected virtual void OnUnequip(UsableItem item)
 {
 }
Example #4
0
        protected void UnequipLocal(UsableItem item)
        {
            var slot = FindAttachmentSlot(item);
            if (slot == null)
                return;

            slot.item = null;

            Debug.Log("UNEQUIPPING item");

            item.Detach();
            item.ClearOwner();
            item.ReleaseAuthority();
        }
Example #5
0
 /// <summary>
 /// Called when ever one of our controllers drops a UsableItem
 /// </summary>
 /// <param name="input"></param>
 /// <param name="item"></param>
 void ItemDropped(PlayerInput input, UsableItem item)
 {
     Unequip(item);
 }
 protected override void OnUnequip(UsableItem item)
 {
     _currentlyEquipped = null;
 }
Example #7
0
        /// <summary>
        /// Can be called on client or server to unequip an item
        /// </summary>
        /// <param name="item"></param>
        public void Unequip(UsableItem item)
        {
            if (isLocalPlayer)
            {
                var slot = FindAttachmentSlot(item);
                if (slot == null)
                {
                    Debug.LogWarning("GamePlayer: Trying to unequip an item that wasn't equipped!");
                    return;
                }

                // notify everyone about the unequipped item
                CmdOnUnequip(item.gameObject);
            }
            else if(isServer)
            {
                // todo...
                // unsure if we need to separate server and client code here
            }
        }
Example #8
0
 protected override void OnUnequip(UsableItem item)
 {
     throw new NotImplementedException();
 }
Example #9
0
 /// <summary>
 /// Called when ever one of our controllers drops a UsableItem
 /// </summary>
 /// <param name="input"></param>
 /// <param name="item"></param>
 void ItemDropped(PlayerInput input, UsableItem item)
 {
     Unequip(item);
 }
Example #10
0
 /// <summary>
 /// Called when ever one of our controllers picks up a UsableItem
 /// </summary>
 /// <param name="input"></param>
 /// <param name="item"></param>
 void ItemPickedUp(PlayerInput input, UsableItem item)
 {
     Equip(input, item, false);
 }
Example #11
0
 protected override void OnUnequip(UsableItem item)
 {
 }
Example #12
0
 protected override void OnUnequip(UsableItem item)
 {
     _currentlyEquipped = null;
 }
Example #13
0
 protected override void OnEquip(AttachmentSlot slot)
 {
     _currentlyEquipped = slot.item;
 }
Example #14
0
 protected bool IsItemEquipped(UsableItem item)
 {
     return(FindAttachmentSlot(item) != null);
 }
Example #15
0
        protected void Equip(PlayerInput input, UsableItem item, bool unequipIfOccupied = false)
        {
            if (item.isInUse)
            {
                Debug.LogError("GamePlayer: Trying to equip an item that is already in use!");
                return;
            }

            if (!isLocalPlayer)
            {
                Debug.LogError("GamePlayer: GamePlayer.Equip(input, item, unequipIfOccupied) can't be called from non local clients!");
                return;
            }

            var slot = FindAttachmentSlot(input);
            if(slot == null) {
                Debug.LogWarning("GamePlayer: Trying to add an item to a non existant attachment slot");
                return;
            }

            // already an item equipped to that slot
            if(slot.item != null && unequipIfOccupied) {
                // unequip the current item
                // todo: can we be sure that unequip will be executed on
                //       all clients?
                Unequip(slot.item);
            }

            // notify everyone about the equipped item
            CmdOnEquip(item.gameObject, GetSlotIndex(slot));
        }
Example #16
0
 protected virtual void OnUnequip(UsableItem item)
 {
 }
Example #17
0
 protected AttachmentSlot FindAttachmentSlot(UsableItem item)
 {
     return _attachmentSlots.Find(x => x.item == item);
 }
Example #18
0
 /// <summary>
 /// Called when ever one of our controllers picks up a UsableItem
 /// </summary>
 /// <param name="input"></param>
 /// <param name="item"></param>
 void ItemPickedUp(PlayerInput input, UsableItem item)
 {
     Equip(input, item, false);
 }
Example #19
0
 protected bool IsItemEquipped(UsableItem item)
 {
     return FindAttachmentSlot(item) != null;
 }
Example #20
0
 protected override void OnUnequip(UsableItem item)
 {
 }
Example #21
0
 protected override void OnEquip(AttachmentSlot slot)
 {
     _currentlyEquipped = slot.item;
 }