Esempio n. 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);
     }
 }
Esempio n. 2
0
 protected AttachmentSlot FindAttachmentSlot(UsableItem item)
 {
     return(_attachmentSlots.Find(x => x.item == item));
 }
Esempio n. 3
0
 protected virtual void OnUnequip(UsableItem item)
 {
 }
Esempio n. 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();
        }
Esempio n. 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);
 }
Esempio n. 6
0
 protected override void OnUnequip(UsableItem item)
 {
     _currentlyEquipped = null;
 }
Esempio n. 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
            }
        }
Esempio n. 8
0
 protected override void OnUnequip(UsableItem item)
 {
     throw new NotImplementedException();
 }
Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 11
0
 protected override void OnUnequip(UsableItem item)
 {
 }
Esempio n. 12
0
 protected override void OnUnequip(UsableItem item)
 {
     _currentlyEquipped = null;
 }
Esempio n. 13
0
 protected override void OnEquip(AttachmentSlot slot)
 {
     _currentlyEquipped = slot.item;
 }
Esempio n. 14
0
 protected bool IsItemEquipped(UsableItem item)
 {
     return(FindAttachmentSlot(item) != null);
 }
Esempio n. 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));
        }
Esempio n. 16
0
 protected virtual void OnUnequip(UsableItem item)
 {
 }
Esempio n. 17
0
 protected AttachmentSlot FindAttachmentSlot(UsableItem item)
 {
     return _attachmentSlots.Find(x => x.item == item);
 }
Esempio n. 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);
 }
Esempio n. 19
0
 protected bool IsItemEquipped(UsableItem item)
 {
     return FindAttachmentSlot(item) != null;
 }
Esempio n. 20
0
 protected override void OnUnequip(UsableItem item)
 {
 }
Esempio n. 21
0
 protected override void OnEquip(AttachmentSlot slot)
 {
     _currentlyEquipped = slot.item;
 }