/// <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); } }
protected AttachmentSlot FindAttachmentSlot(UsableItem item) { return(_attachmentSlots.Find(x => x.item == item)); }
protected virtual void OnUnequip(UsableItem item) { }
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(); }
/// <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; }
/// <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 } }
protected override void OnUnequip(UsableItem item) { throw new NotImplementedException(); }
/// <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); }
protected override void OnUnequip(UsableItem item) { }
protected override void OnEquip(AttachmentSlot slot) { _currentlyEquipped = slot.item; }
protected bool IsItemEquipped(UsableItem item) { return(FindAttachmentSlot(item) != null); }
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)); }
protected AttachmentSlot FindAttachmentSlot(UsableItem item) { return _attachmentSlots.Find(x => x.item == item); }
protected bool IsItemEquipped(UsableItem item) { return FindAttachmentSlot(item) != null; }