예제 #1
0
    private void HarvestFarmWork_onAreaChanged(HarvestFarmWork work, Vector3 point, float radius)
    {
        food.Clear();

        status = HarvestFarmWorkStatus.INFO_COLLECT;
        if (cheif != null)
        {
            InfoCollectJob(point, radius);
        }
    }
예제 #2
0
    private void Update()
    {
        bool noUIcontrolsInUse = EventSystem.current.currentSelectedGameObject == null;

        if (!noUIcontrolsInUse)
        {
            return;
        }

        var selectedNPCLogic = RTSSelector.GetSelectedAsNPCLogic();

        if (selectedNPCLogic.Count == 0)
        {
            return;                              // if 0 npc's chosen exit update method
        }
        if (Input.GetKey(KeyCode.RightShift) && selectedNPCLogic.Count >= 0)
        {
            for (int i = 0; i < 9; i++)
            {
                if (Input.GetKey(KeyCode.RightShift) && Input.GetKey((KeyCode)(49 + i)) && selectedNPCLogic.Count >= 0)// Ctrl+Num grouping

                {
                    group[i].Clear();
                    foreach (var npcLogic in selectedNPCLogic)
                    {
                        if (npcLogic != null)
                        {
                            group[i].Add(npcLogic);
                        }
                    }
                    break;
                }
            }
        }
        for (int i = 0; i < 9; i++)
        {
            if (!Input.anyKey)
            {
                if (Input.GetKeyUp((KeyCode)(49 + i)))// Group choosing
                {
                    RTSSelector.ClearSelected();
                    foreach (var npc in group[i])
                    {
                        var npcselect = npc.GetComponent <Selectable>();
                        RTSSelector.UpdateSelection(npcselect, true);
                    }
                    break;
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.H))               // if H key pressed
        {
            foreach (var npc in selectedNPCLogic)      // For all Npc's
            {
                npc.SetJob(new Job(Job.JobType.HALT)); // Sets Halt Job
            }
        }

        if (Input.GetKeyDown(KeyCode.R) && selectedNPCLogic.Count >= 0)
        {
            foreach (var npc in selectedNPCLogic)
            {
                ToggleRunCommand(npc);
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (woodWork == null)
            {
                woodWork = FindObjectOfType <HarvestWoodWork>();
            }
            if (woodWork.cheif == null && selectedNPCLogic.Count == 1)
            {
                woodWork.SetCheif(selectedNPCLogic[0]);
            }
            else if (woodWork.cheif != null)
            {
                foreach (var npc in selectedNPCLogic)
                {
                    woodWork.AddWorker(npc);
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.RightAlt))
        {
            if (stoneWork == null)
            {
                stoneWork = FindObjectOfType <HarvestStoneWork>();
            }
            if (stoneWork.cheif == null && selectedNPCLogic.Count == 1)
            {
                stoneWork.SetCheif(selectedNPCLogic[0]);
            }
            else if (stoneWork.cheif != null)
            {
                foreach (var npc in selectedNPCLogic)
                {
                    stoneWork.AddWorker(npc);
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.F))
        {
            if (farmWork == null)
            {
                farmWork = FindObjectOfType <HarvestFarmWork>();
            }
            if (farmWork.cheif == null && selectedNPCLogic.Count == 1)
            {
                farmWork.SetCheif(selectedNPCLogic[0]);
            }
            else if (farmWork.cheif != null)
            {
                foreach (var npc in selectedNPCLogic)
                {
                    farmWork.AddWorker(npc);
                }
            }
        }

        if (Input.GetMouseButtonDown(1) && RTSSelector.GetSelected().Count >= 0)
        {
            Ray        mouseToWorldRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;
            if (Physics.Raycast(mouseToWorldRay, out hitInfo))
            {
                GameObject    go    = hitInfo.collider.gameObject;
                Vector3       point = hitInfo.point;
                Pickupable    item;
                NPCLogic      otherGuy;
                Building      building;
                WoodTree      tree;
                StoneMountain stone;
                GrainField    food;
                if (go.tag.Equals("ground"))
                {
                    Vector3 x = new Vector3(0, 0, 0);
                    Vector3 z = new Vector3(0, 0, 0);
                    foreach (var npcLogic in selectedNPCLogic)
                    {
                        if (selectedNPCLogic.Count == 1)
                        {
                            MoveCommand(npcLogic, point);
                        }
                        else if (selectedNPCLogic.Count > 1)
                        {
                            if (x.x > Math.Sqrt(selectedNPCLogic.Count))
                            {
                                z.z++;
                                x.x = 0;
                            }
                            MoveCommand(npcLogic, point - new Vector3(x.x, 1, z.z));

                            x.x++;
                            //Debug.Log(x.x + " " + z.z + " " + Math.Sqrt(selectedNPCLogic.Count) + " " + npcLogic.name);
                        }
                    }
                }
                else if ((item = go.GetComponent <Pickupable>()) != null)
                {
                    foreach (var npcLogic in selectedNPCLogic)
                    {
                        PickUpCommand(npcLogic, item);
                    }
                }
                else if ((tree = go.GetComponent <WoodTree>()) != null)
                {
                    if (selectedNPCLogic.Count == 1 && Input.GetKey(KeyCode.C))
                    {
                        TestGiveWoodCutOrderCommand(selectedNPCLogic[0], tree);
                    }
                    else
                    {
                        foreach (var npcLogic in selectedNPCLogic)
                        {
                            WoodCuttingCommand(npcLogic, tree);
                        }
                    }
                }
                else if ((stone = go.GetComponent <StoneMountain>()) != null)
                {
                    if (selectedNPCLogic.Count == 1 && Input.GetKey(KeyCode.C))
                    {
                        TestGiveStoneCutOrderCommand(selectedNPCLogic[0], stone);
                    }
                    else
                    {
                        foreach (var npcLogic in selectedNPCLogic)
                        {
                            StoneMiningCommand(npcLogic, stone);
                        }
                    }
                }
                else if ((food = go.GetComponent <GrainField>()) != null)
                {
                    if (selectedNPCLogic.Count == 1 && Input.GetKey(KeyCode.C))
                    {
                        TestGiveFoodCutOrderCommand(selectedNPCLogic[0], food);
                    }
                    else
                    {
                        foreach (var npcLogic in selectedNPCLogic)
                        {
                            FoodFarmingCommand(npcLogic, food);
                        }
                    }
                }

                else if ((otherGuy = go.GetComponent <NPCLogic>()) != null)
                {
                    foreach (var npcLogic in selectedNPCLogic)
                    {
                        ItemTransfer(npcLogic, otherGuy);
                    }
                }
                else if ((building = go.GetComponent <Building>()) != null)
                {
                    foreach (var npcLogic in selectedNPCLogic)
                    {
                        BuildingActionCommand();
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.F) && selectedNPCLogic.Count >= 0)
        {
            foreach (var npcLogic in selectedNPCLogic)
            {
                DropCommand(npcLogic);
            }
        }
    }