Beispiel #1
0
    public static bool SwapItem(UI_ItemSlot itemSlot)
    {
        var CurrentSlot = PlayerManager.LocalPlayerScript.DynamicItemStorage.GetActiveHandSlot();

        if (isValidPlayer())
        {
            if (CurrentSlot != itemSlot.ItemSlot)
            {
                if (CurrentSlot.Item == null)
                {
                    if (itemSlot.Item != null)
                    {
                        Inventory.ClientRequestTransfer(itemSlot.ItemSlot, CurrentSlot);
                        return(true);
                    }
                }
                else
                {
                    if (itemSlot.Item == null)
                    {
                        Inventory.ClientRequestTransfer(CurrentSlot, itemSlot.ItemSlot);
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
 public static void Remove(UI_ItemSlot item)
 {
     if (InventorySlots.Contains(item))
     {
         InventorySlots.Remove(item);
     }
 }
    /// Throw mode toggle. Actual throw is in
    /// <see cref="InputController.CheckThrow()"/>
    public void Throw()
    {
        PlayerScript lps         = PlayerManager.LocalPlayerScript;
        UI_ItemSlot  currentSlot = UIManager.Hands.CurrentSlot;

        if (!lps || lps.canNotInteract() || !currentSlot.CanPlaceItem())
        {
            UIManager.IsThrow = false;
            throwImage.sprite = throwSprites[0];
            return;
        }

        SoundManager.Play("Click01");
//			Logger.Log("Throw Button");

        if (!UIManager.IsThrow)
        {
            UIManager.IsThrow = true;
            throwImage.sprite = throwSprites[1];
        }
        else
        {
            UIManager.IsThrow = false;
            throwImage.sprite = throwSprites[0];
        }
    }
Beispiel #4
0
 /// <summary>
 /// Swap the item in the current slot to itemSlot
 /// </summary>
 public bool SwapItem(UI_ItemSlot itemSlot)
 {
     if (IsValidPlayer())
     {
         if (CurrentSlot != itemSlot)
         {
             if (CurrentSlot.Item == null)
             {
                 if (itemSlot.Item != null)
                 {
                     Inventory.ClientRequestTransfer(itemSlot.ItemSlot, CurrentSlot.ItemSlot);
                     return(true);
                 }
             }
             else
             {
                 if (itemSlot.Item == null)
                 {
                     Inventory.ClientRequestTransfer(CurrentSlot.ItemSlot, itemSlot.ItemSlot);
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
    public override void Interact(GameObject originator, Vector3 position, string hand)
    {
        if (!allowSell && deniedMessage != null && !GameData.Instance.testServer && !GameData.IsHeadlessServer)
        {
            UIManager.Chat.AddChatEvent(new ChatEvent(deniedMessage, ChatChannel.Examine));
        }
        // Client pre-approval
        else if (!isServer && allowSell)
        {
            allowSell = false;
            UI_ItemSlot slot = UIManager.Hands.CurrentSlot;
            UIManager.Chat.AddChatEvent(new ChatEvent(interactionMessage, ChatChannel.Examine));
            //Client informs server of interaction attempt
            InteractMessage.Send(gameObject, position, slot.eventName);
            StartCoroutine(VendorInputCoolDown());
        }
        else if (allowSell)
        {
            allowSell = false;
            if (!GameData.Instance.testServer && !GameData.IsHeadlessServer)
            {
                UIManager.Chat.AddChatEvent(new ChatEvent(interactionMessage, ChatChannel.Examine));
            }

            ServerVendorInteraction(originator, position, hand);
            StartCoroutine(VendorInputCoolDown());
        }
    }
    public override void Interact(GameObject originator, Vector3 position, string hand)
    {
        if (!isServer)
        {
            UI_ItemSlot slot = UIManager.Hands.CurrentSlot;

            // Client pre-approval
            if (slot.CanPlaceItem())
            {
                //Client informs server of interaction attempt
                InteractMessage.Send(gameObject, position, slot.eventName);
                //Client simulation
                //				var placedOk = slot.PlaceItem(gameObject.transform.position);
                //				if ( !placedOk )
                //				{
                //					Logger.Log("Client placing error");
                //				}
            }
        }
        else
        {
            //Server actions
            if (!ValidateTableInteraction(originator, position, hand))
            {
                //Rollback prediction here
                //				originator.GetComponent<PlayerNetworkActions>().RollbackPrediction(hand);
            }
        }
    }
Beispiel #7
0
    /// <summary>
    /// General function to try to equip the item in the active hand
    /// </summary>
    public void Equip()
    {
        // Is the player allowed to interact? (not a ghost)
        if (!isValidPlayer())
        {
            return;
        }

        // Is there an item to equip?
        if (!CurrentSlot.IsFull)
        {
            return;
        }

        //This checks which UI slot the item can be equiped to and swaps it there
        UI_ItemSlot itemSlot = InventorySlotCache.GetSlotByItemType(CurrentSlot.Item);

        if (itemSlot != null)
        {
            // If we couldn't equip item into pocket, let's try the other pocket!
            if (!SwapItem(itemSlot) && itemSlot.eventName == "storage02")
            {
                SwapItem(InventorySlotCache.GetSlotByEvent("storage01"));
            }
        }
        else
        {
            Logger.LogError("No slot type was found for this object for auto equip", Category.UI);
        }
    }
Beispiel #8
0
 /// <summary>
 /// Swaps the two slots
 /// </summary>
 private void Swap(UI_ItemSlot slot1, UI_ItemSlot slot2)
 {
     if (isValidPlayer())
     {
         UIManager.TryUpdateSlot(new UISlotObject(slot1.inventorySlot.UUID, slot2.Item, slot2.inventorySlot.UUID));
     }
 }
Beispiel #9
0
    /// <summary>
    /// General function to try to equip the item in the active hand
    /// </summary>
    public void Equip()
    {
        // Is the player allowed to interact? (not a ghost)
        if (!isValidPlayer())
        {
            return;
        }

        // Is there an item to equip?
        if (!CurrentSlot.IsFull)
        {
            return;
        }

        //This checks which UI slot the item can be equiped to and swaps it there
        ItemType    type       = Slots.GetItemType(CurrentSlot.Item);
        SpriteType  masterType = Slots.GetItemMasterType(CurrentSlot.Item);
        UI_ItemSlot itemSlot   = InventorySlotCache.GetSlotByItemType(CurrentSlot.Item);

        if (itemSlot != null)
        {
            SwapItem(itemSlot);
        }
        else
        {
            Logger.LogError("No slot type was found for this object for auto equip", Category.UI);
        }
    }
Beispiel #10
0
 public void ResetSelectedSlot()
 {
     if (nowSelectedSlot != null)
     {
         nowSelectedSlot.SelectOnOff(false);
     }
     nowSelectedSlot = null;
 }
Beispiel #11
0
 /// <summary>
 /// Swaps the two slots
 /// </summary>
 private bool Swap(UI_ItemSlot slot1, UI_ItemSlot slot2)
 {
     if (isValidPlayer())
     {
         return(UIManager.TryUpdateSlot(new UISlotObject(slot1.inventorySlot.UUID, slot2.Item, slot2.inventorySlot.UUID)));
     }
     return(false);
 }
        public override void ClientAction()
        {
            UI_ItemSlot slot = UIManager.Hands.CurrentSlot;

            // Client pre-approval
            if (slot.CanPlaceItem())
            {
                InteractMessage.Send(gameObject, position, slot.eventName);
            }
        }
    public static UI_ItemSlot GetSlotByUUID(string UUID)
    {
        UI_ItemSlot slot  = null;
        int         index = InventorySlots.FindLastIndex(x => x.inventorySlot.UUID == UUID);

        if (index != -1)
        {
            slot = InventorySlots[index];
        }
        return(slot);
    }
Beispiel #14
0
 public void UI_ItemDrag(UI_ItemSlot itemSlot)
 {
     if (itemSlot.Item != null)
     {
         ItemSlotCache          = itemSlot;
         isDragging             = true;
         dragDummy.enabled      = true;
         dragDummy.sprite       = itemSlot.image.sprite;
         itemSlot.image.enabled = false;
         ItemCache = itemSlot.Item;
     }
 }
Beispiel #15
0
 public void UI_ItemDrag(UI_ItemSlot fromSlot)
 {
     if (fromSlot.Item != null && !isDragging)
     {
         DropInteracted    = false;
         FromSlotCache     = fromSlot;
         isDragging        = true;
         dragDummy.enabled = true;
         dragDummy.sprite  = fromSlot.Image.sprite;
         fromSlot.Clear();
         DraggedItem = fromSlot.ItemObject;
     }
 }
Beispiel #16
0
    private void Swap(UI_ItemSlot slot1, UI_ItemSlot slot2)
    {
        if (PlayerManager.LocalPlayerScript != null)
        {
            if (!PlayerManager.LocalPlayerScript.playerMove.allowInput ||
                PlayerManager.LocalPlayerScript.playerMove.isGhost)
            {
                return;
            }
        }

        UIManager.TryUpdateSlot(new UISlotObject(slot1.inventorySlot.UUID, slot2.Item, slot2.inventorySlot.UUID));
    }
Beispiel #17
0
    public void SetSelectSlot(UI_ItemSlot slot)
    {
        if (slot == null)
        {
            return;
        }

        //기존 선택 항목 해제
        if (nowSelectedSlot != null)
        {
            nowSelectedSlot.SelectOnOff(false);
        }

        //새로 선택 항목으로 갱신
        slot.SelectOnOff(true);
        nowSelectedSlot = slot;
    }
Beispiel #18
0
 /// <summary>
 /// Swap the item in the current slot to itemSlot
 /// </summary>
 public void SwapItem(UI_ItemSlot itemSlot)
 {
     if (isValidPlayer())
     {
         if (CurrentSlot != itemSlot)
         {
             if (!CurrentSlot.IsFull)
             {
                 Swap(CurrentSlot, itemSlot);
             }
             else
             {
                 Swap(itemSlot, CurrentSlot);
             }
         }
     }
 }
Beispiel #19
0
    public static bool CanPutItemToSlot(UISlotObject proposedSlotInfo)
    {
        if (proposedSlotInfo.IsEmpty() || !SendUpdateAllowed(proposedSlotInfo.SlotContents))
        {
            return(false);
        }
        UI_ItemSlot  uiItemSlot = InventorySlots[proposedSlotInfo.Slot];
        PlayerScript lps        = PlayerManager.LocalPlayerScript;

        if (!lps || lps.canNotInteract() ||
            uiItemSlot == null || uiItemSlot.IsFull ||
            !uiItemSlot.CheckItemFit(proposedSlotInfo.SlotContents))
        {
            return(false);
        }
        return(true);
    }
    public override void Interact(GameObject originator, Vector3 position, string hand)
    {
        if (!isServer)
        {
            UI_ItemSlot slot = UIManager.Hands.CurrentSlot;

            // Client pre-approval
            if (!microwave.Cooking && slot.CanPlaceItem())
            {
                //Client informs server of interaction attempt
                InteractMessage.Send(gameObject, position, slot.eventName);
            }
        }
        else
        {
            ValidateMicrowaveInteraction(originator, position, hand);
        }
    }
Beispiel #21
0
    public void MakeSlot()
    {
        if (slotPrefab == null)
        {
            return;
        }
        GameObject loadObj = Instantiate(slotPrefab, grid.transform);

        if (loadObj != null)
        {
            UI_ItemSlot slot = loadObj.GetComponent <UI_ItemSlot>();
            if (slot != null)
            {
                slot.LinkInventoryUi(this);
                itemSlots.Add(slot);
            }
        }
    }
Beispiel #22
0
    /// <summary>
    /// Perform the drop action
    /// </summary>
    public void Drop()
    {
        // if (!Validations.CanInteract(PlayerManager.LocalPlayerScript, NetworkSide.Client, allowCuffed: true)); Commented out because it does... nothing?
        UI_ItemSlot currentSlot = UIManager.Hands.CurrentSlot;

        if (currentSlot.Item == null)
        {
            return;
        }

        if (UIManager.IsThrow)
        {
            Throw();
        }
        PlayerManager.LocalPlayerScript.playerNetworkActions.CmdDropItem(currentSlot.NamedSlot);
        SoundManager.Play("Click01");
        Logger.Log("Drop Button", Category.UI);
    }
Beispiel #23
0
 /// <summary>
 /// Swap the item in the current slot to itemSlot
 /// </summary>
 public bool SwapItem(UI_ItemSlot itemSlot)
 {
     if (isValidPlayer())
     {
         if (CurrentSlot != itemSlot)
         {
             if (!CurrentSlot.IsFull)
             {
                 return(Swap(CurrentSlot, itemSlot));
             }
             else
             {
                 return(Swap(itemSlot, CurrentSlot));
             }
         }
     }
     return(false);
 }
Beispiel #24
0
    /// <summary>
    /// Perform the drop action
    /// </summary>
    public void Drop()
    {
        PlayerScript lps = PlayerManager.LocalPlayerScript;

        if (!lps || lps.canNotInteract())
        {
            return;
        }
        UI_ItemSlot currentSlot = UIManager.Hands.CurrentSlot;

        //			Vector3 dropPos = lps.gameObject.transform.position;
        if (!currentSlot.CanPlaceItem())
        {
            return;
        }
        //            if ( isNotMovingClient(lps) )
        //            {
        //               // Full client simulation(standing still)
        //                var placedOk = currentSlot.PlaceItem(dropPos);
        //                if ( !placedOk )
        //                {
        //                    Logger.Log("Client dropping error");
        //                }
        //            }
        //            else
        //            {
        //Only clear slot(while moving, as prediction is shit in this situation)
        //			GameObject dropObj = currentSlot.Item;
        //			CustomNetTransform cnt = dropObj.GetComponent<CustomNetTransform>();
        //			It is converted to LocalPos in transformstate struct
        //			cnt.AppearAtPosition(PlayerManager.LocalPlayer.transform.position);
        //            }
        //Message

        if (UIManager.IsThrow == true)
        {
            Throw();             // Disable throw
        }
        UIManager.CheckStorageHandlerOnMove(currentSlot.Item);
        //forceClientInform = true because we aren't doing prediction any more.
        lps.playerNetworkActions.RequestDropItem(currentSlot.inventorySlot.UUID, true);
        SoundManager.Play("Click01");
        Logger.Log("Drop Button", Category.UI);
    }
Beispiel #25
0
    /// <summary>
    /// Swap the item in the current slot to itemSlot
    /// </summary>
    public bool SwapItem(UI_ItemSlot itemSlot)
    {
        if (isValidPlayer())
        {
            if (CurrentSlot != itemSlot)
            {
                var pna = PlayerManager.LocalPlayerScript.playerNetworkActions;

                if (CurrentSlot.Item == null)
                {
                    if (itemSlot.Item != null)
                    {
                        if (itemSlot.inventorySlot.IsUISlot)
                        {
                            pna.CmdUpdateSlot(CurrentSlot.equipSlot, itemSlot.equipSlot);
                        }
                        else
                        {
                            StoreItemMessage.Send(itemSlot.inventorySlot.Owner, PlayerManager.LocalPlayerScript.gameObject, CurrentSlot.equipSlot, false, itemSlot.equipSlot);
                        }
                        return(true);
                    }
                }
                else
                {
                    if (itemSlot.Item == null)
                    {
                        if (itemSlot.inventorySlot.IsUISlot)
                        {
                            pna.CmdUpdateSlot(itemSlot.equipSlot, CurrentSlot.equipSlot);
                        }
                        else
                        {
                            StoreItemMessage.Send(itemSlot.inventorySlot.Owner, PlayerManager.LocalPlayerScript.gameObject, CurrentSlot.equipSlot, true);
                        }
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Beispiel #26
0
    public static bool CanPutItemToSlot(UISlotObject proposedSlotInfo)
    {
        if (proposedSlotInfo.IsEmpty() || !SendUpdateAllowed(proposedSlotInfo.SlotContents))
        {
            return(false);
        }

        InventorySlot invSlot = InventoryManager.GetSlotFromUUID(proposedSlotInfo.SlotUUID, false);
        PlayerScript  lps     = PlayerManager.LocalPlayerScript;

        if (!lps || lps.canNotInteract() || invSlot.Item != null)
        {
            return(false);
        }

        UI_ItemSlot uiItemSlot = InventorySlotCache.GetSlotByUUID(invSlot.UUID);

        if (uiItemSlot == null)
        {
            //Could it be a storage obj that is closed?
            ItemSize checkMaxSizeOfStorage;
            if (SlotIsFromClosedBag(invSlot, out checkMaxSizeOfStorage))
            {
                var itemAtts = proposedSlotInfo.SlotContents.GetComponent <ItemAttributes>();
                if (itemAtts != null)
                {
                    if (itemAtts.size <= checkMaxSizeOfStorage)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }

        if (!uiItemSlot.CheckItemFit(proposedSlotInfo.SlotContents))
        {
            return(false);
        }
        return(true);
    }
Beispiel #27
0
    public void Use()
    {
        if (PlayerManager.LocalPlayerScript != null)
        {
            if (!PlayerManager.LocalPlayerScript.playerMove.allowInput ||
                PlayerManager.LocalPlayerScript.playerMove.isGhost)
            {
                return;
            }
        }

        if (!CurrentSlot.IsFull)
        {
            return;
        }

        //Is the item edible?
        if (CheckEdible())
        {
            return;
        }

        //This checks which UI slot the item can be equiped too and swaps it there
        ItemType   type       = Slots.GetItemType(CurrentSlot.Item);
        SpriteType masterType = Slots.GetItemMasterType(CurrentSlot.Item);

        switch (masterType)
        {
        case SpriteType.Clothing:
            UI_ItemSlot slot = Slots.GetSlotByItem(CurrentSlot.Item);
            SwapItem(slot);
            break;

        case SpriteType.Items:
            UI_ItemSlot itemSlot = Slots.GetSlotByItem(CurrentSlot.Item);
            SwapItem(itemSlot);
            break;

        case SpriteType.Guns:
            break;
        }
    }
Beispiel #28
0
    /// <summary>
    /// General function to try to equip the item in the active hand
    /// </summary>
    public void Equip()
    {
        // Is the player allowed to interact? (not a ghost)
        if (!isValidPlayer())
        {
            return;
        }

        // Is there an item to equip?
        if (CurrentSlot.Item == null)
        {
            Logger.Log("!CurrentSlot.IsFull");
            return;
        }

        //This checks which UI slot the item can be equiped to and swaps it there
        UI_ItemSlot itemSlot = InventorySlotCache.GetSlotByItemType(CurrentSlot.Item);

        if (itemSlot != null)
        {
            //Try to equip the item into the appropriate slot
            if (!SwapItem(itemSlot))
            {
                //If we couldn't equip the item into it's primary slot, try the pockets!
                if (!SwapItem(InventorySlotCache.GetSlotByEvent(EquipSlot.storage01)))
                {
                    //We couldn't equip the item in pocket 1. Try pocket2!
                    //This swap fails if both pockets are full, do nothing if fail
                    SwapItem(InventorySlotCache.GetSlotByEvent(EquipSlot.storage02));
                }
            }
        }

        else
        {
            Logger.LogError("No slot type was found for this object for auto equip", Category.UI);
        }
    }
    public void Drop()
    {
        PlayerScript lps = PlayerManager.LocalPlayerScript;

        if (!lps || lps.canNotInteract())
        {
            return;
        }
        UI_ItemSlot currentSlot = UIManager.Hands.CurrentSlot;

//			Vector3 dropPos = lps.gameObject.transform.position;
        if (!currentSlot.CanPlaceItem())
        {
            return;
        }
        //            if ( isNotMovingClient(lps) )
        //            {
        //               // Full client simulation(standing still)
        //                var placedOk = currentSlot.PlaceItem(dropPos);
        //                if ( !placedOk )
        //                {
        //                    Logger.Log("Client dropping error");
        //                }
        //            }
        //            else
        //            {
        //Only clear slot(while moving, as prediction is shit in this situation)
//			GameObject dropObj = currentSlot.Item;
//			CustomNetTransform cnt = dropObj.GetComponent<CustomNetTransform>();
//			It is converted to LocalPos in transformstate struct
//			cnt.AppearAtPosition(PlayerManager.LocalPlayer.transform.position);
        currentSlot.Clear();
        //            }
        //Message
        lps.playerNetworkActions.RequestDropItem(currentSlot.eventName, false);
        SoundManager.Play("Click01");
        Logger.Log("Drop Button", Category.UI);
    }
    public override void OnInspectorGUI()
    {
        UI_ItemSlot itemSlot = (UI_ItemSlot)target;

        itemSlot.eventName = EditorGUILayout.TextField("Event Name", itemSlot.eventName);

        itemSlot.allowAllItems = EditorGUILayout.Toggle("Allow All Items", itemSlot.allowAllItems);

        if (itemSlot.allowAllItems)
        {
            itemSlot.maxItemSize = (ItemSize)EditorGUILayout.EnumPopup("Maximal Item Size", itemSlot.maxItemSize);
        }
        else
        {
            SerializedProperty tps = serializedObject.FindProperty("allowedItemTypes");
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(tps, true);
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
    }