Beispiel #1
0
    void Update()
    {
        if (dialogWindow.isOpen == false)
        {
            if (Input.mouseScrollDelta.y != 0 || Input.GetKeyDown(KeyCode.Space))      //switch hands
            {
                currentHand = SwapActiveHand();
                SetHandColor();
            }
            else if (Input.GetKeyDown(KeyCode.Q))
            {
                actionPanel.OnDropClick();
            }
            //else if (Input.GetKeyDown(KeyCode.Q))   //switch to left hand
            //{
            //    currentHand = left_hand_btn;
            //    SetHandColor();
            //}
            //else if (Input.GetKeyDown(KeyCode.E))   //switch to right hand
            //{
            //    currentHand = right_hand_btn;
            //    SetHandColor();
            //}
            else if (Input.GetKeyDown(KeyCode.Tab)) // open bag
            {
                if (isBagOpen == true)
                {
                    CloseOpenContainer(bag_panel, ref isBagOpen);
                    return;
                }

                if (IsEmpty(bag_btn) == true)
                {
                    return;
                }

                Item bag = bag_btn.GetComponent <ItemCell>().item;

                CloseOpenContainer(bag_panel, ref isBagOpen);

                if (isBagOpen == true)
                {
                    isBagOpenWithTab = true;
                    ContainerContentInit(bag.innerItems, bag_panel);
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                eventController.OnMouseClickEvent.Invoke();

                mousePosRight = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                Vector2        mousePos2D = new Vector2(mousePosRight.x, mousePosRight.y);
                RaycastHit2D[] hits       = Physics2D.RaycastAll(mousePos2D, Vector2.zero);

                foreach (var hit in hits)
                {
                    if (hit.collider.name.Contains(Global.DROPED_ITEM_PREFIX) && IsInActionRadius(hit.transform.position, player.position, actioPlayerRadius))
                    {
                        Item itemInWorld = hit.collider.GetComponent <ItemCell>().item;
                        if (itemInWorld.itemSubstitution.IsUsable(GetItemInHand(currentHand)))
                        {
                            itemInWorld.itemSubstitution.Substitute(hit.collider.gameObject);

                            return;
                        }
                    }

                    if (hit.collider.tag == "substitudeItem")
                    {
                        Item itemToDrop = hit.collider.GetComponent <SubstitudeCell>().item;

                        actionPanel.SpawnItem(hit.transform.position, itemToDrop);
                        Destroy(hit.collider.gameObject);

                        return;
                    }

                    if (hit.collider.gameObject.tag == "table" && hit.collider.GetComponent <TableController>().isCraftTable)
                    {
                        bool removeTool = craftController.Craft_Table(hits, GetItemInHand(currentHand),
                                                                      CraftType.Cooking,
                                                                      CraftTable.Table);

                        if (removeTool)
                        {
                            SetDefaultItem(currentHand);
                        }

                        return;
                    }

                    if (hit.collider.gameObject.tag == "microwave")
                    {
                        MicrowaveController microwave = hit.collider.GetComponent <MicrowaveController>();

                        craftController.Craft_Microwave(microwave, GetItemInHand(currentHand),
                                                        CraftType.Cooking,
                                                        CraftTable.Microwave);

                        eventController.OnEnvChangeShapeEvent.Invoke();

                        return;
                    }

                    if (hit.collider.gameObject.tag == "oven")
                    {
                        MicrowaveController microwave = hit.collider.GetComponent <MicrowaveController>();

                        craftController.Craft_Microwave(microwave, GetItemInHand(currentHand),
                                                        CraftType.Cooking,
                                                        CraftTable.Oven);

                        eventController.OnEnvChangeShapeEvent.Invoke();

                        return;
                    }

                    if (hit.collider.gameObject.tag == "printer")
                    {
                        PrinterController printerController = hit.collider.GetComponent <PrinterController>();

                        printerController.OnPrinterClick();
                    }

                    if (hit.collider.gameObject.tag == "pc")
                    {
                        PCController pcController = hit.collider.GetComponent <PCController>();

                        pcController.OnPc_Disck(currentHand);
                    }

                    if (hit.collider.gameObject.tag == "tv")
                    {
                        TVController tvController = hit.collider.GetComponent <TVController>();

                        tvController.NextChanel();
                    }

                    if (hit.collider.gameObject.name.Contains(Global.ITEM_SWITCH_PREFIX))
                    {
                        ISwitchItem switchItem = hit.collider.GetComponent <ISwitchItem>();
                        switchItem.SwitchItem(GetItemInHand(currentHand), currentHand);
                        //ItemSwitchController itemSwitchController = hit.collider.GetComponent<ItemSwitchController>();

                        //itemSwitchController.SwitchItem(GetItemInHand(currentHand), currentHand);
                    }

                    /*                  */
                    /*      QUESTS      */
                    /*                  */

                    if (hit.collider.gameObject.name.Contains("bus_spawn"))
                    {
                        Debug.Log("bus");
                        BusController bus = hit.collider.GetComponent <BusController>();
                        bus.GiveTicket(currentHand);
                        return;
                    }
                }

                eventController.OnRightButtonClickEvent.Invoke(hits, mousePos2D);
            }

            if (Input.GetMouseButtonDown(0) || ((isOptMouseInput = Input.GetKeyDown(KeyCode.E)) &&
                                                terminalController.isOpen == false))
            {
                eventController.OnMouseClickEvent.Invoke();
                // не детектить нажатие пробела вовремя работы в терминале
                //isOptMouseInput = !terminalController.isOpen;

                if (isOptMouseInput == false)
                {
                    mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                }
                else
                {
                    mousePos = player.position + (playerMovement.GetTurnSide() / 2);
                }

                Vector2        mousePos2D = new Vector2(mousePos.x, mousePos.y);
                RaycastHit2D[] hits       = Physics2D.RaycastAll(mousePos2D, Vector2.zero);

                //isSpacePressed = false;

                if (IsInActionRadius(mousePos, player.position, actioPlayerRadius))
                {
                    Item itemInHand = GetItemInHand(currentHand);
                    itemInHand.itemUseData.use.Use_On_Env(hits, mousePos, currentHand, GetAnotherHand());
                }

                foreach (var hit in hits)
                {
                    if (hit.collider != null && IsInActionRadius(mousePos, player.position, actioPlayerRadius))
                    {
                        // ели на полу айтем и в руках не чего нет
                        if (hit.collider.name.Contains(Global.DROPED_ITEM_PREFIX) &&
                            IsEmpty(currentHand))
                        {
                            GameObject itemGo = hit.collider.gameObject;
                            ItemPickUp(itemGo);
                            return; // приоритет что бы не взять айтем и не положить его потом на стол если он был уже на столе
                        }

                        /*   клик по игроку   */
                        if (hit.collider.gameObject.tag == "playerAction")
                        {
                            Item item = currentHand.GetComponent <ItemCell>().item;
                            eventController.OnUseOnPlayerEvent.Invoke(item);
                            item.itemUseData.use.Use_On_Player(null, item);

                            if (item.isDestroyOnPlayerUse)
                            {
                                SetDefaultItem(currentHand);
                            }
                            else
                            {
                                if (item.afterOnPlayerUseItem != null)
                                {
                                    Item afterUseItemClone = Instantiate(item.afterOnPlayerUseItem);
                                    DressCell(currentHand, afterUseItemClone);
                                }
                            }
                        }

                        if (hit.collider.tag == "substitudeItem")
                        {
                            BaseConection baseConection = hit.collider.GetComponent <BaseConection>();

                            if (baseConection != null)
                            {
                                PCController pcController = baseConection.FindPcInRadius();

                                if (pcController != null)
                                {
                                    baseConection.ProcessConection(pcController);
                                }

                                return;
                            }
                        }

                        if (hit.collider.gameObject.tag == "tapWater")
                        {
                            TabWaterController tabWaterController = hit.collider.GetComponent <TabWaterController>();
                            Button             btn_itemInHand     = IsEmpty(currentHand) ? null : currentHand;
                            tabWaterController.OnWaterTap_Click(btn_itemInHand);
                        }

                        if (hit.collider.gameObject.tag == "envObj")
                        {
                            BaseActionWindowConntroller baseAction = hit.collider.GetComponent <BaseActionWindowConntroller>();
                            baseAction.Open(hit.collider.gameObject);
                        }

                        if (hit.collider.gameObject.tag == "pc")
                        {
                            PCController pcController = hit.collider.GetComponent <PCController>();
                            Item         itemInHand   = IsEmpty(currentHand) ? null : GetItemInHand(currentHand);
                            pcController.OnPc_ClicK(itemInHand);
                        }

                        if (hit.collider.gameObject.tag == "tv")
                        {
                            TVController tVController = hit.collider.GetComponent <TVController>();
                            tVController.OnTvClick();
                        }

                        if (hit.collider.gameObject.tag == "microwave" || hit.collider.gameObject.tag == "oven")
                        {
                            Item itemInHand = IsEmpty(currentHand) ? null : GetItemInHand(currentHand);
                            MicrowaveController microwaveController = hit.collider.GetComponent <MicrowaveController>();

                            MicrowaveController.MicrowaveStatus status = microwaveController.OnMicrowaveClick(itemInHand, mousePos);

                            if (status == MicrowaveController.MicrowaveStatus.PutItem)
                            {
                                SetDefaultItem(currentHand);
                            }
                            else if (status == MicrowaveController.MicrowaveStatus.TakeItem)
                            {
                                DressCell(currentHand, microwaveController.itemInside);
                                microwaveController.itemInside = null;
                            }

                            eventController.OnEnvChangeShapeEvent.Invoke();
                        }

                        if (hit.collider.gameObject.tag == "door")
                        {
                            Item itemInHand = GetItemInHand(currentHand);
                            // использовать айтем как ключ
                            //eventController.OnDoorEvent.Invoke(itemInHand, mousePos, hit.collider, hit.collider.GetComponent<DoorController>().isLocked);
                            hit.collider.GetComponent <DoorController>().OnDoorClick(itemInHand, mousePos, hit.collider, hit.collider.GetComponent <DoorController>().isLocked);
                            itemInHand.itemUseData.use.Use_To_Open(null, itemInHand);
                        }

                        if (hit.collider.gameObject.tag == "case" || hit.collider.gameObject.tag == "printer")
                        {
                            CaseItem  caseItem     = hit.collider.GetComponent <CaseItem>();
                            Transform casePosition = hit.collider.transform;

                            // важно соблюдать очередность, сначало открывается сундук потом панэль
                            hit.collider.GetComponent <CaseController>().OnCaseCloseOpen(casePosition.position);

                            eventController.OnStaticCaseItemEvent.Invoke(caseItem, casePosition);
                            eventController.OnEnvChangeShapeEvent.Invoke();
                        }

                        if (hit.collider.gameObject.tag == "table")
                        {
                            hit.collider.GetComponent <TableController>().OnTableClick(hit.transform.position,
                                                                                       IsEmpty(currentHand) ? null : GetItemInHand(currentHand));
                        }

                        /*                  */
                        /*      QUESTS      */
                        /*                  */
                        if (hit.collider.gameObject.name.Contains("bus_spawn"))
                        {
                            Debug.Log("bus");
                            BusController bus = hit.collider.GetComponent <BusController>();
                            bus.Activate();
                            return;
                        }
                    }
                }
            }
        }
    }
Beispiel #2
0
    void Update()
    {
        if (!actionWindow.isOpen && !dialogWindow.isOpen)
        {
            if (Input.mouseScrollDelta.y != 0)
            {
                currentHand = SwapActiveHand();
                SetHandColor();
                //currentHand.GetComponentInChildren<Text>().text = "*";
            }

            if (Input.GetMouseButtonDown(1))
            {
                eventController.OnMouseClickEvent.Invoke();

                mousePosRight = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                Vector2        mousePos2D = new Vector2(mousePosRight.x, mousePosRight.y);
                RaycastHit2D[] hits       = Physics2D.RaycastAll(mousePos2D, Vector2.zero);

                foreach (var hit in hits)
                {
                    if (hit.collider.gameObject.tag == "table" && hit.collider.GetComponent <TableController>().isCraftTable)
                    {
                        bool removeTool = craftController.Craft_Table(hits, GetItemInHand(currentHand),
                                                                      CraftType.Cooking,
                                                                      CraftTable.Table);

                        if (removeTool)
                        {
                            SetDefaultItem(currentHand);
                        }

                        return;
                    }

                    if (hit.collider.gameObject.tag == "microwave")
                    {
                        MicrowaveController microwave = hit.collider.GetComponent <MicrowaveController>();

                        craftController.Craft_Microwave(microwave, GetItemInHand(currentHand),
                                                        CraftType.Cooking,
                                                        CraftTable.Microwave);

                        eventController.OnEnvChangeShapeEvent.Invoke();

                        return;
                    }

                    if (hit.collider.gameObject.tag == "oven")
                    {
                        MicrowaveController microwave = hit.collider.GetComponent <MicrowaveController>();

                        craftController.Craft_Microwave(microwave, GetItemInHand(currentHand),
                                                        CraftType.Cooking,
                                                        CraftTable.Oven);

                        eventController.OnEnvChangeShapeEvent.Invoke();

                        return;
                    }

                    if (hit.collider.gameObject.tag == "printer")
                    {
                        PrinterController printerController = hit.collider.GetComponent <PrinterController>();

                        printerController.OnPrinterClick();
                    }

                    if (hit.collider.gameObject.tag == "pc")
                    {
                        PCController pcController = hit.collider.GetComponent <PCController>();

                        pcController.OnPc_Disck(currentHand);
                    }

                    if (hit.collider.gameObject.tag == "tv")
                    {
                        TVController tvController = hit.collider.GetComponent <TVController>();

                        tvController.NextChanel();
                    }

                    if (hit.collider.gameObject.name.Contains(Global.ITEM_SWITCH_PREFIX))
                    {
                        ItemSwitchController itemSwitchController = hit.collider.GetComponent <ItemSwitchController>();

                        itemSwitchController.SwitchItem(GetItemInHand(currentHand), currentHand);
                    }

                    /*                  */
                    /*      QUESTS      */
                    /*                  */

                    if (hit.collider.gameObject.name.Contains("bus_spawn"))
                    {
                        Debug.Log("bus");
                        BusController bus = hit.collider.GetComponent <BusController>();
                        bus.GiveTicket(currentHand);
                        return;
                    }
                }

                eventController.OnRightButtonClickEvent.Invoke(hits, mousePos2D);
            }

            if (Input.GetMouseButtonDown(0))
            {
                eventController.OnMouseClickEvent.Invoke();

                mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                Vector2        mousePos2D = new Vector2(mousePos.x, mousePos.y);
                RaycastHit2D[] hits       = Physics2D.RaycastAll(mousePos2D, Vector2.zero);

                if (IsInActionRadius(mousePos, player.position, actioPlayerRadius))
                {
                    Item itemInHand = GetItemInHand(currentHand);
                    itemInHand.itemUseData.use.Use_On_Env(hits, mousePos, currentHand, GetAnotherHand());
                }

                foreach (var hit in hits)
                {
                    if (hit.collider != null && IsInActionRadius(mousePos, player.position, actioPlayerRadius))
                    {
                        // ели на полу айтем и в руках не чего нет
                        if (hit.collider.name.Contains(Global.DROPED_ITEM_PREFIX) &&
                            IsEmpty(currentHand))
                        {
                            GameObject itemGo = hit.collider.gameObject;
                            ItemPickUp(itemGo);
                            return; // приоритет что бы не взять айтем и не положить его потом на стол если он был уже на столе
                        }

                        if (hit.collider.gameObject.tag == "player")
                        {
                            Item item = currentHand.GetComponent <ItemCell>().item;
                            item.itemUseData.use.Use_On_Player(statInit.stats, item);

                            if (item.isDestroyOnPlayerUse)
                            {
                                SetDefaultItem(currentHand);
                            }
                            else
                            {
                                if (item.afterOnPlayerUseItem != null)
                                {
                                    Item afterUseItemClone = Instantiate(item.afterOnPlayerUseItem);
                                    DressCell(currentHand, afterUseItemClone);
                                }
                            }
                        }

                        if (hit.collider.gameObject.tag == "tapWater")
                        {
                            TabWaterController tabWaterController = hit.collider.GetComponent <TabWaterController>();
                            Button             btn_itemInHand     = IsEmpty(currentHand) ? null : currentHand;
                            tabWaterController.OnWaterTap_Click(btn_itemInHand);
                        }

                        if (hit.collider.gameObject.tag == "envObj")
                        {
                            BaseActionWindowConntroller baseAction = hit.collider.GetComponent <BaseActionWindowConntroller>();
                            baseAction.Open(hit.collider.gameObject);
                        }

                        if (hit.collider.gameObject.tag == "pc")
                        {
                            PCController pcController = hit.collider.GetComponent <PCController>();
                            Item         itemInHand   = IsEmpty(currentHand) ? null : GetItemInHand(currentHand);
                            pcController.OnPc_ClicK(itemInHand, mousePos);
                        }

                        if (hit.collider.gameObject.tag == "tv")
                        {
                            TVController tVController = hit.collider.GetComponent <TVController>();
                            tVController.OnTvClick();
                        }

                        if (hit.collider.gameObject.tag == "microwave" || hit.collider.gameObject.tag == "oven")
                        {
                            Item itemInHand = IsEmpty(currentHand) ? null : GetItemInHand(currentHand);
                            MicrowaveController microwaveController = hit.collider.GetComponent <MicrowaveController>();

                            MicrowaveController.MicrowaveStatus status = microwaveController.OnMicrowaveClick(itemInHand, mousePos);

                            if (status == MicrowaveController.MicrowaveStatus.PutItem)
                            {
                                SetDefaultItem(currentHand);
                            }
                            else if (status == MicrowaveController.MicrowaveStatus.TakeItem)
                            {
                                DressCell(currentHand, microwaveController.itemInside);
                                microwaveController.itemInside = null;
                            }

                            eventController.OnEnvChangeShapeEvent.Invoke();
                        }

                        if (hit.collider.gameObject.tag == "door")
                        {
                            Item itemInHand = GetItemInHand(currentHand);
                            // использовать айтем как ключ
                            //eventController.OnDoorEvent.Invoke(itemInHand, mousePos, hit.collider, hit.collider.GetComponent<DoorController>().isLocked);
                            hit.collider.GetComponent <DoorController>().OnDoorClick(itemInHand, mousePos, hit.collider, hit.collider.GetComponent <DoorController>().isLocked);
                            itemInHand.itemUseData.use.Use_To_Open(statInit.stats, itemInHand);
                        }

                        if (hit.collider.gameObject.tag == "case" || hit.collider.gameObject.tag == "printer")
                        {
                            CaseItem  caseItem     = hit.collider.GetComponent <CaseItem>();
                            Transform casePosition = hit.collider.transform;

                            // важно соблюдать очередность, сначало открывается сундук потом панэль
                            hit.collider.GetComponent <CaseController>().OnCaseCloseOpen(casePosition.position);
                            eventController.OnStaticCaseItemEvent.Invoke(caseItem, casePosition);

                            eventController.OnEnvChangeShapeEvent.Invoke();
                        }

                        if (hit.collider.gameObject.tag == "table")
                        {
                            hit.collider.GetComponent <TableController>().OnTableClick(hit.transform.position,
                                                                                       IsEmpty(currentHand) ? null : GetItemInHand(currentHand));
                        }

                        /*                  */
                        /*      QUESTS      */
                        /*                  */
                        if (hit.collider.gameObject.name.Contains("bus_spawn"))
                        {
                            Debug.Log("bus");
                            BusController bus = hit.collider.GetComponent <BusController>();
                            bus.Activate();
                            return;
                        }
                    }
                }
            }
        }
    }