Ejemplo n.º 1
0
    public void OnRightClick(RaycastHit Point)
    {
        var         hasParent               = Point.transform.tag == "Rock" || Point.transform.tag == "Crystal" || Point.transform.tag == "Ore";
        var         Collectable             = false;
        var         TaskAvaliable           = true;
        Collectable CollectableObjectScript = new Collectable();
        GameObject  ClickedObject           = new GameObject();
        var         Drillable               = false;

        if (hasParent)
        {
            ClickedObject = Point.collider.gameObject.transform.parent.gameObject;
        }
        else
        {
            ClickedObject = Point.collider.gameObject;
        }

        if (ClickedObject.GetComponent <Collectable>() != null)
        {
            CollectableObjectScript             = ClickedObject.GetComponent <Collectable>();
            Collectable                         = true;
            CollectableObjectScript.HostChanged = false;
        }

        if (Point.transform.tag == "Rock")
        {
            var Rock_Type = ClickedObject.GetComponent <Work_Script>().RockProperties.RockType;
            Drillable = (Rock_Type == RockType.LooseRock || Rock_Type == RockType.SoftRock || Rock_Type == RockType.HardRock);
        }

        if (Point.transform.tag == "Terrain")
        {
            TaskAvaliable = false;
        }

        var PositionOfObject = new Vector3(ClickedObject.transform.position.x, 0, ClickedObject.transform.position.z);

        foreach (var Unit in SelectedGameObjects)
        {
            var Unit_ = Unit.GetComponent <Lego_Character>();
            Unit_.SetToDefault();
            Unit_.Arrived = false;

            if (TaskAvaliable)
            {
                if (Unit_.Items.Count > 0)
                {
                    Unit_.Items[0].GetComponent <Collectable>().DropItem();
                    Unit_.Items.Clear();
                }

                Unit_.TaskObject = ClickedObject;
                Unit_.MoveTo(PositionOfObject);
            }
            else
            {
                if (Unit_.Items.Count > 0)
                {
                    Unit_.CurrentTask = CurrentJob.WanderAroungWithItem;
                }
                else
                {
                    Unit_.CurrentTask = CurrentJob.WalkToPoint;
                }

                Unit_.MoveTo(Point.point);
            }

            if (Point.transform.tag == "Rubble")
            {
                Unit_.StartClearingProcess();
            }

            if (ClickedObject.transform.tag == "Rock")
            {
                if (Unit_.CanDrill && Drillable)
                {
                    Unit_.StartDrillingProcess();
                }
            }

            if (Collectable)
            {
                TaskAvaliable = false;
                //new host not been set
                if (CollectableObjectScript.HostChanged == false)
                {
                    //if another raider is going for it then make that raider drop it
                    if (CollectableObjectScript.Collector != null)
                    {
                        CollectableObjectScript.ClearAllCollectors();
                    }

                    Unit_.StartCollecting();
                    CollectableObjectScript.Collector = Unit_.gameObject;

                    if (Point.transform.tag == "Crystal")
                    {
                        Unit_.ItemType    = CollectableType.Crystal;
                        Unit_.TaskChassis = TaskChassis.GatherCrystals;
                    }

                    if (Point.transform.tag == "Ore")
                    {
                        Unit_.ItemType    = CollectableType.Ore;
                        Unit_.TaskChassis = TaskChassis.GatherOre;
                    }

                    CollectableObjectScript.HostChanged = true;
                }
            }
        }
    }