Exemple #1
0
 public static void RemoveTask(UnitTask task)
 {
     if (task == null)
     {
         return;
     }
     task.DestroyTask();
     Tasks.Remove(task);
 }
Exemple #2
0
    public void SetTask(UnitTask theTask)
    {
        _taskSetup = false;
        _gotItem   = false;
        PlayOrderSound();

        switch (_vType)
        {
        case VehicleType.smallDrill:
            if (theTask != null)
            {
                if (theTask._taskType == UnitTask.TaskType.Mine || theTask._taskType == UnitTask.TaskType.RechargeVehicle || theTask._taskType == UnitTask.TaskType.Walk)
                {
                    if (_currentTask != null)
                    {
                        if (_currentTask._taskType != UnitTask.TaskType.RechargeVehicle)
                        {
                            if (_currentTask._taskType == UnitTask.TaskType.Mine)
                            {
                                TaskList.AddTaskToGlobalTaskList(_currentTask);
                            }
                            _currentTask = theTask;
                        }
                    }
                    else
                    {
                        _currentTask = theTask;
                    }
                }
            }
            break;

        case VehicleType.smallTransport:
            if (theTask._taskType == UnitTask.TaskType.Pickup || theTask._taskType == UnitTask.TaskType.RechargeVehicle || theTask._taskType == UnitTask.TaskType.Walk)
            {
                if (_currentTask != null)
                {
                    if (_currentTask._taskType != UnitTask.TaskType.RechargeVehicle)
                    {
                        if (_currentTask._taskType == UnitTask.TaskType.Pickup)
                        {
                            TaskList.AddTaskToGlobalTaskList(_currentTask);
                        }
                        _currentTask = theTask;
                    }
                }
                else
                {
                    _currentTask = theTask;
                }
            }
            break;
        }
    }
Exemple #3
0
 void SetupBuildingIcon(UnitTask Task)
 {
     if (Task._targetBuilding == null)
     {
         SetIcon(ConvertTaskToOrderType(Task._taskType));
         return;
     }
     CurrnetType = OrderVisualType.Build;
     _decal.Mat.SetTexture("_BaseColorMap", TileLibrary.Get().GetBuildingTexture((Tile.TileTypeID)Task._targetBuilding.GetID()));
     _decal.enabled = (CurrnetType != OrderVisualType.None);
 }
Exemple #4
0
 //得到某个单位的任务
 public Task GetTask(TUnit unit)
 {
     if (unit == null)
     {
         return(null);
     }
     if (UnitTask.ContainsKey(unit))
     {
         return(UnitTask[unit]);
     }
     return(null);
 }
Exemple #5
0
    /// <summary>
    /// When selecting to enter a vehicle, create and set get in vehicle task
    /// </summary>
    public void EnterVehicle()
    {
        UnitTask tempTask = TaskLibrary.Get().CreateTask(UnitTask.TaskType.GetInVehicle, _vehicle.transform.position, _vehicle.gameObject);

        if (_worker != null)
        {
            _worker.SetTask(tempTask);
        }
        else
        {
            TaskList.AddTaskToGlobalTaskList(tempTask);
        }
    }
Exemple #6
0
 public static void InsertTaskToBeginning(UnitTask task)
 {
     if (task == null)
     {
         return;
     }
     if (DoesTaskExist(task))
     {
         return;
     }
     task.UpdateTask();
     Tasks.Insert(0, task);
 }
Exemple #7
0
 public static void AddTaskToGlobalTaskList(UnitTask task)
 {
     if (task == null)
     {
         return;
     }
     if (DoesTaskExist(task))
     {
         return;
     }
     task.UpdateTask();
     Tasks.Add(task);
 }
Exemple #8
0
    private void Start()
    {
        planetScript = planet.GetComponent <Planet>();
        planetRadius = planetScript.shapeSettings.radius;

        transform.position = new Vector3(0, planetRadius + 1, 0);

        gameObject.name = $"({++unitCount}) Unit";

        AddRandomForce(0.00001f);

        unitTask = UnitTask.Idle;

        unitsLayerMask = LayerMask.GetMask("Units");
    }
Exemple #9
0
    bool TryAddOrder(Tile tile, UnitTask.TaskType type)
    {
        if (type == UnitTask.TaskType.none)
        {
            tile.CancelTilesTasks();
            return(true);
        }
        UnitTask task = TaskLibrary.Get().CreateTask(type, tile.transform.position, tile.gameObject);

        if (task == null || !task.IsValid())
        {
            return(false);
        }
        TaskList.AddTaskToGlobalTaskList(task);
        return(true);
    }
Exemple #10
0
    /// <summary>
    /// Check if an exisitng pick up resource task exists for this resource
    /// </summary>
    /// <returns>Bool if task exists</returns>
    bool PickUpResourceTaskExists()
    {
        foreach (Unit unit in WorldController.GetWorldController._workers)
        {
            Worker worker = unit.GetComponent <Worker>();
            if (worker != null)
            {
                UnitTask workerTask = worker.GetCurrentTask();
                if (workerTask != null && (workerTask._taskType == UnitTask.TaskType.Pickup && workerTask._itemToPickUp == (_ore != null ? _ore.gameObject : _energyCrystal.gameObject)))
                {
                    return(true);
                }
            }
        }

        return(TaskList.Tasks.Find(task => task._taskType == UnitTask.TaskType.Pickup && task._itemToPickUp == (_ore != null ? _ore.gameObject : _energyCrystal.gameObject)) != null);
    }
Exemple #11
0
    /// <summary>
    /// Check if an exisitng clear rubble task exists for this rubble
    /// </summary>
    /// <returns>Bool if task exists</returns>
    bool ClearRubbleTaskExists()
    {
        foreach (Unit unit in WorldController.GetWorldController._workers)
        {
            Worker worker = unit.GetComponent <Worker>();
            if (worker != null)
            {
                UnitTask workerTask = worker.GetCurrentTask();
                if (workerTask != null && (workerTask._taskType == UnitTask.TaskType.ClearRubble && workerTask._targetRubble == _rubble))
                {
                    return(true);
                }
            }
        }

        return(TaskList.Tasks.Find(task => task._targetRubble == _rubble && task._taskType == UnitTask.TaskType.ClearRubble) != null);
    }
    public void UpdateOrderMarker(GameObject G, UnitTask task)
    {
        if (task != null)
        {
            if (OrderVisualizer.ConvertTaskToOrderType(task._taskType) == OrderVisualizer.OrderVisualType.None)
            {
                //this task has no icon.
                return;
            }
        }
        OrderVisualizer OV = G.GetComponentInParent <OrderVisualizer>();

        if (OV != null)
        {
            OV.UpdateVisuals(task);
        }
    }
Exemple #13
0
    /// <summary>
    /// Check if an exisitng burn cluster task exists for this mushroom
    /// </summary>
    /// <returns>Bool if task exists</returns>
    bool BurnClusterTaskExists()
    {
        foreach (Unit unit in WorldController.GetWorldController._workers)
        {
            Worker worker = unit.GetComponent <Worker>();
            if (worker != null)
            {
                UnitTask workerTask = worker.GetCurrentTask();
                if (workerTask != null && (workerTask._taskType == UnitTask.TaskType.flameTarget && workerTask._targetMushroom == _mushroomCluster))
                {
                    return(true);
                }
            }
        }

        return(TaskList.Tasks.Find(task => task._targetMushroom == _mushroomCluster && task._taskType == UnitTask.TaskType.flameTarget) != null);
    }
        /// <summary>
        /// Set the action to the passed parameters
        /// </summary>
        public void setAction(UnitTask ut)
        {
            actionButton.gameObject.SetActive(true);
            actionTitleText.gameObject.SetActive(true);
            apCostText.gameObject.SetActive(true);

            // Make sure nothing else is on the listener to avoid repeated usage
            actionButton.onClick.RemoveAllListeners();

            // Set the display title
            actionTitleText.text = ut.displayName;

            // Set the cost display of the action
            apCostText.text = $"Cost: {ut.APcost}";

            // Set the onclick to call back to the function
            actionButton.onClick.AddListener(ut.ua);
        }
Exemple #15
0
    public void CheckEnergy()
    {
        _targetBuilding = FindClosestBuildingWithTag("GARAGE", "");
        if (_targetBuilding != null)
        {
            int   currentSetting = (int)SettingScript.instance.RiskLevel;
            float timeToGen      = Vector3.Distance(transform.position, _targetBuilding.transform.position) / _speed;

            if (timeToGen > (Energy - (currentSetting + 10)))
            {
                if (_currentTask != null)
                {
                    if (_currentTask._taskType != UnitTask.TaskType.RechargeVehicle)
                    {
                        UnitTask temptask = new UnitTask
                        {
                            _location        = _targetBuilding.transform.position,
                            _taskType        = UnitTask.TaskType.RechargeVehicle,
                            _taskDescription = "Recharging Vehicle"
                        };

                        SetTask(temptask);
                    }
                }
                else
                {
                    UnitTask temptask = new UnitTask
                    {
                        _location        = _targetBuilding.transform.position,
                        _taskType        = UnitTask.TaskType.RechargeVehicle,
                        _taskDescription = "Recharging Vehicle"
                    };

                    SetTask(temptask);
                }
            }
        }

        if (Energy <= 0 && _occupied)
        {
            Disembark();
        }
    }
Exemple #16
0
    // Start is called before the first frame update
    void Start()
    {
        UnitTask tempTask = new UnitTask
        {
            _location        = transform.position,
            _taskType        = UnitTask.TaskType.Build,
            _targetBuilding  = building,
            _requiredTool    = Unit.UnitTool.Hammer,
            _taskDescription = "Build a building"
        };

        TaskList.AddTaskToGlobalTaskList(tempTask);
        foreach (VisualEffect smokeVFX in smokeVFXList)
        {
            if (smokeVFX)
            {
                smokeVFX.Stop();
            }
        }
    }
Exemple #17
0
 public void UpdateVisuals(UnitTask Task)
 {
     if (!IsSetup)
     {
         Start();
     }
     if (Task == null)
     {
         SetIcon(OrderVisualType.None);
         return;
     }
     if (Task._taskType == UnitTask.TaskType.Build)
     {
         SetupBuildingIcon(Task);
     }
     else
     {
         SetIcon(ConvertTaskToOrderType(Task._taskType));
     }
     LinkedTask = Task;
 }
Exemple #18
0
 public static bool DoesTaskExist(UnitTask task, out UnitTask outtask)
 {
     outtask = null;
     if (task == null || !task.IsValid())
     {
         return(false);
     }
     for (int i = 0; i < TaskList.Tasks.Count; i++)
     {
         if (TaskMenuScript.AreTasksSame(TaskList.Tasks[i], task))
         {
             outtask = TaskList.Tasks[i];
             return(true);
         }
     }
     foreach (Unit unit in WorldController.GetWorldController._workers)
     {
         Worker w = unit.GetComponent <Worker>();
         if (w != null)
         {
             if (w.GetCurrentTask() != null)
             {
                 if (TaskMenuScript.AreTasksSame(w.GetCurrentTask(), task))
                 {
                     outtask = w.GetCurrentTask();
                     return(true);
                 }
             }
             foreach (UnitTask t in w._localTaskList)
             {
                 if (TaskMenuScript.AreTasksSame(t, task))
                 {
                     outtask = t;
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Exemple #19
0
    bool AddTaskToVehicle(UnitTask.TaskType t, Vehicle V, Vector3 Pos, GameObject OBJ, bool set = false)
    {
        UnitTask newTask = TaskLibrary.Get().CreateTask(t, Pos, OBJ);

        if (newTask == null)
        {
            return(false);
        }
        if (!TaskLibrary.CanVehicleExecuteTask(t, V))
        {
            return(false);
        }
        if (set)
        {
            V.SetTask(newTask);
        }
        else
        {
            V.AddTask(newTask);
        }
        return(true);
    }
Exemple #20
0
    bool AddTaskToWorker(UnitTask.TaskType t, Worker W, Vector3 Pos, GameObject OBJ, bool set = false)
    {
        UnitTask newTask = TaskLibrary.Get().CreateTask(t, Pos, OBJ);

        if (newTask == null)
        {
            return(false);
        }
        if (!TaskLibrary.CanWorkerExecuteTask(t, W))
        {
            return(false);
        }
        if (set)
        {
            W.SetTask(newTask, ShouldPlaySound());
        }
        else
        {
            W.AddTask(newTask);
        }
        return(true);
    }
Exemple #21
0
        //移除指定的执行者
        void RemoveUnitFromTask(TUnit unit)
        {
            if (unit == null)
            {
                return;
            }
            if (!UnitTask.ContainsKey(unit))
            {
                return;
            }
            var objective = UnitTask[unit];

            UnitTask.Remove(unit);
            var units = TaskUnit[objective];

            units.Remove(unit);
            if (units.Count <= 0)
            {
                TaskUnit.Remove(objective);
                AssignedTask[objective.EnumIndex].Remove(objective);
                GlobalObjer?.RemoveTarget(objective);
            }
        }
Exemple #22
0
    // Update is called once per frame
    void Update()
    {
        _ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (_currentSelectedObject != null)
        {
            _selectionRing.transform.position = _currentSelectedObject.transform.position;
        }
        else
        {
            _selectionRing.transform.position = new Vector3(0, -100, 0);
        }

        if (Physics.Raycast(_ray, out _hit))
        {
            Debug.DrawRay(_ray.origin, _ray.direction * _hit.distance, Color.yellow);
            _mouseWorldLocation = _hit.point;

            if (ControlScript.instance.GetControl("Select").InputDown)
            {
                if (!EventSystem.current.IsPointerOverGameObject())
                {
                    RadialMenuScript.instance.CloseMenu();
                }

                switch (_hit.transform.tag)
                {
                case TagLibrary.WORKER_TAG:
                    if (_currentSelectedObject != null)
                    {
                        _currentSelectedObject._selected = false;
                        _currentSelectedObject           = null;
                    }

                    _currentSelectedObject           = _hit.transform.gameObject.GetComponent <SelectableObject>();
                    _currentSelectedObject._selected = true;

                    WorkerInfoPanelScript.instance.Open(_hit.transform.GetComponent <Worker>());
                    break;

                default:

                    if (_currentSelectedObject != null)
                    {
                        _currentSelectedObject._selected = false;
                        _currentSelectedObject           = null;
                    }
                    WorkerInfoPanelScript.instance.Close();
                    break;
                }
            }
            else if (ControlScript.instance.GetControl("Order Modifier").AnyInput&& ControlScript.instance.GetControl("Order").InputDown)
            {
                if (_currentSelectedObject != null)
                {
                    switch (_hit.transform.tag)
                    {
                    case "Floor":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker   tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();
                            UnitTask tempTask   = new UnitTask
                            {
                                _location        = _mouseWorldLocation,
                                _taskType        = UnitTask.TaskType.Walk,
                                _taskDescription = "Walking to location",
                                _requiredTool    = Unit.UnitTool.none
                            };
                            tempWorker.AddTask(tempTask);
                        }

                        break;

                    case "RockTile":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker     tempWorker = _currentSelectedObject.gameObject.GetComponent <Worker>();
                            RockScript tempRock   = _hit.transform.gameObject.GetComponentInParent <RockScript>();

                            if (tempWorker._currentTool == Unit.UnitTool.Hammer)
                            {
                                UnitTask tempTask = new UnitTask
                                {
                                    _location        = _hit.transform.position,
                                    _taskType        = UnitTask.TaskType.Reinforce,
                                    _targetRock      = tempRock,
                                    _requiredTool    = Unit.UnitTool.Hammer,
                                    _taskDescription = "Reinforcing a wall"
                                };
                                tempWorker.AddTask(tempTask);
                            }
                            else
                            {
                                if (tempRock.RockType == RockScript.Type.Dirt || (tempRock.RockType == RockScript.Type.LooseRock && (int)WorldController.GetWorldController._miningLevel >= 1) || (tempRock.RockType == RockScript.Type.HardRock && (int)WorldController.GetWorldController._miningLevel == 2))
                                {
                                    UnitTask tempTask = new UnitTask
                                    {
                                        _location        = _hit.transform.position,
                                        _taskType        = UnitTask.TaskType.Mine,
                                        _targetRock      = tempRock,
                                        _requiredTool    = Unit.UnitTool.MiningTool,
                                        _taskDescription = "Mining a wall"
                                    };
                                    tempWorker.SetTask(tempTask);
                                }
                            }
                        }
                        break;

                    case "Rubble":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker       tempWorker = _currentSelectedObject.gameObject.GetComponent <Worker>();
                            RubbleScript tempRubble = _hit.transform.gameObject.GetComponentInParent <RubbleScript>();

                            UnitTask tempTask = new UnitTask
                            {
                                _location        = tempRubble.transform.position,
                                _taskType        = UnitTask.TaskType.ClearRubble,
                                _targetRubble    = tempRubble,
                                _requiredTool    = Unit.UnitTool.Shovel,
                                _taskDescription = "Clearing rubble"
                            };
                            tempWorker.SetTask(tempTask);
                        }
                        break;

                    case "Ore":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker   tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();
                            UnitTask tempTask   = new UnitTask
                            {
                                _location        = _hit.transform.position,
                                _taskType        = UnitTask.TaskType.Pickup,
                                _itemToPickUp    = _hit.transform.gameObject,
                                _itemType        = UnitTask.ItemType.Ore,
                                _taskDescription = "Transporting Ore",
                                _requiredTool    = Unit.UnitTool.none
                            };
                            tempWorker.AddTask(tempTask);
                        }
                        break;

                    case "EnergyCrystal":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker   tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();
                            UnitTask tempTask   = new UnitTask
                            {
                                _location        = _hit.transform.position,
                                _taskType        = UnitTask.TaskType.Pickup,
                                _itemToPickUp    = _hit.transform.gameObject,
                                _itemType        = UnitTask.ItemType.EnergyCrystal,
                                _taskDescription = "Transporting an Energy crystal",
                                _requiredTool    = Unit.UnitTool.none
                            };
                            tempWorker.AddTask(tempTask);
                        }
                        break;

                    case "HQ":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            //RadialMenuScript.instance.ShowToolOptions(_currentSelectedObject.transform.gameObject.GetComponent<Worker>(), _hit.transform.position);
                        }
                        break;

                    case "SKIP":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();

                            //check if building needs building

                            UnitTask tempTask = new UnitTask
                            {
                                _location        = _hit.transform.position,
                                _taskType        = UnitTask.TaskType.Build,
                                _itemToPickUp    = _hit.transform.gameObject,
                                _requiredTool    = Unit.UnitTool.Hammer,
                                _taskDescription = "Building A Skip"
                            };
                            tempWorker.AddTask(tempTask);
                        }
                        break;

                    case "GEN":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();

                            //check if building needs building

                            UnitTask tempTask = new UnitTask
                            {
                                _location        = _hit.transform.position,
                                _taskType        = UnitTask.TaskType.Build,
                                _itemToPickUp    = _hit.transform.gameObject,
                                _requiredTool    = Unit.UnitTool.Hammer,
                                _taskDescription = "Building An Oxegen Generator"
                            };
                            tempWorker.AddTask(tempTask);
                        }
                        break;

                    case "Monster":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();

                            if ((int)WorldController.GetWorldController._miningLevel >= 1)
                            {
                                UnitTask tempTask = new UnitTask
                                {
                                    _location        = _hit.transform.position,
                                    _taskType        = UnitTask.TaskType.Attack,
                                    _requiredTool    = Unit.UnitTool.Weapon,
                                    _taskDescription = "Attacking monster"
                                };
                                tempWorker.SetTask(tempTask);
                            }
                        }
                        break;
                    }
                }
            }
            else if (ControlScript.instance.GetControl("Order").InputDown)
            {
                if (_currentSelectedObject == null || (_currentSelectedObject != null && _currentSelectedObject == _hit.transform.GetComponentInParent <SelectableObject>()))
                {
                    switch (_hit.transform.tag)
                    {
                    case "Worker":
                        Worker worker = _hit.transform.GetComponent <Worker>();
                        //RadialMenuScript.instance.ShowWorkerOptions(worker);
                        break;

                    case "RockTile":
                        RockScript rock = _hit.transform.gameObject.GetComponentInParent <RockScript>();
                        RadialMenuScript.instance.ShowRockOptions(rock);
                        break;

                    case "Rubble":
                        RubbleScript rubble = _hit.transform.gameObject.GetComponentInParent <RubbleScript>();
                        RadialMenuScript.instance.ShowRubbleOptions(rubble);
                        break;

                    case "Monster":
                        Monster monster = _hit.transform.GetComponentInParent <Monster>();
                        RadialMenuScript.instance.ShowEnemyOptions(monster);
                        break;

                    case "HQ":
                        HQ hq = _hit.transform.GetComponentInParent <HQ>();
                        RadialMenuScript.instance.ShowHQOptions(hq);
                        break;

                    case "GEN":
                    case "BLOCK":
                        Building building = _hit.transform.GetComponentInParent <Building>();
                        RadialMenuScript.instance.ShowBuildingOptions(building);
                        break;

                    case "Ore":
                        Ore ore = _hit.transform.GetComponentInParent <Ore>();
                        RadialMenuScript.instance.ShowResourceOptionsOre(ore);
                        break;

                    case "EnergyCrystal":
                        EnergyCrystal energyCrystal = _hit.transform.GetComponentInParent <EnergyCrystal>();
                        RadialMenuScript.instance.ShowResourceOptionsEnergyCrystal(energyCrystal);
                        break;
                    }
                }
                else if (_currentSelectedObject != null)
                {
                    switch (_hit.transform.tag)
                    {
                    case "Floor":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker   tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();
                            UnitTask tempTask   = new UnitTask
                            {
                                _location        = _mouseWorldLocation,
                                _taskType        = UnitTask.TaskType.Walk,
                                _taskDescription = "Walking to location",
                                _requiredTool    = Unit.UnitTool.none
                            };
                            tempWorker.SetTask(tempTask);
                        }

                        break;

                    case "RockTile":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker     tempWorker = _currentSelectedObject.gameObject.GetComponent <Worker>();
                            RockScript tempRock   = _hit.transform.gameObject.GetComponentInParent <RockScript>();

                            if (tempWorker._currentTool == Unit.UnitTool.Hammer)
                            {
                                UnitTask tempTask = new UnitTask
                                {
                                    _location        = _hit.transform.position,
                                    _taskType        = UnitTask.TaskType.Reinforce,
                                    _targetRock      = tempRock,
                                    _requiredTool    = Unit.UnitTool.Hammer,
                                    _taskDescription = "Reinforcing a wall"
                                };
                                tempWorker.SetTask(tempTask);
                            }
                            else
                            {
                                if (tempRock.RockType == RockScript.Type.Dirt || (tempRock.RockType == RockScript.Type.LooseRock && (int)WorldController.GetWorldController._miningLevel >= 1) || (tempRock.RockType == RockScript.Type.HardRock && (int)WorldController.GetWorldController._miningLevel == 2))
                                {
                                    UnitTask tempTask = new UnitTask
                                    {
                                        _location        = _hit.transform.position,
                                        _taskType        = UnitTask.TaskType.Mine,
                                        _targetRock      = tempRock,
                                        _requiredTool    = Unit.UnitTool.MiningTool,
                                        _taskDescription = "Mining a wall"
                                    };
                                    tempWorker.SetTask(tempTask);
                                }
                            }
                        }
                        break;

                    case "Rubble":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker       tempWorker = _currentSelectedObject.gameObject.GetComponent <Worker>();
                            RubbleScript tempRubble = _hit.transform.gameObject.GetComponentInParent <RubbleScript>();

                            if (tempWorker._currentTool == Unit.UnitTool.Shovel)
                            {
                                UnitTask tempTask = new UnitTask
                                {
                                    _location        = tempRubble.transform.position,
                                    _taskType        = UnitTask.TaskType.ClearRubble,
                                    _targetRubble    = tempRubble,
                                    _requiredTool    = Unit.UnitTool.Shovel,
                                    _taskDescription = "Clearing rubble"
                                };
                                tempWorker.SetTask(tempTask);
                            }
                            else
                            {
                                UnitTask tempTask = new UnitTask
                                {
                                    _location        = _mouseWorldLocation,
                                    _taskType        = UnitTask.TaskType.Walk,
                                    _taskDescription = "Walking to location",
                                    _requiredTool    = Unit.UnitTool.none
                                };
                                tempWorker.SetTask(tempTask);
                            }
                        }
                        break;

                    case "Ore":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker   tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();
                            UnitTask tempTask   = new UnitTask
                            {
                                _location        = _hit.transform.position,
                                _taskType        = UnitTask.TaskType.Pickup,
                                _itemToPickUp    = _hit.transform.gameObject,
                                _itemType        = UnitTask.ItemType.Ore,
                                _taskDescription = "Transporting Ore",
                                _requiredTool    = Unit.UnitTool.none
                            };
                            tempWorker.SetTask(tempTask);
                        }
                        break;

                    case "EnergyCrystal":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker   tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();
                            UnitTask tempTask   = new UnitTask
                            {
                                _location        = _hit.transform.position,
                                _taskType        = UnitTask.TaskType.Pickup,
                                _itemToPickUp    = _hit.transform.gameObject,
                                _itemType        = UnitTask.ItemType.EnergyCrystal,
                                _taskDescription = "Transporting an Energy crystal",
                                _requiredTool    = Unit.UnitTool.none
                            };
                            tempWorker.SetTask(tempTask);
                        }
                        break;

                    case "HQ":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            //RadialMenuScript.instance.ShowToolOptions(_currentSelectedObject.transform.gameObject.GetComponent<Worker>(), _hit.transform.position);
                        }
                        break;

                    case "SKIP":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();

                            //check if building needs building

                            UnitTask tempTask = new UnitTask
                            {
                                _location        = _hit.transform.position,
                                _taskType        = UnitTask.TaskType.Build,
                                _itemToPickUp    = _hit.transform.gameObject,
                                _requiredTool    = Unit.UnitTool.Hammer,
                                _taskDescription = "Building A Skip"
                            };
                            tempWorker.AddTask(tempTask);
                        }
                        break;

                    case "GEN":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();

                            //check if building needs building

                            UnitTask tempTask = new UnitTask
                            {
                                _location        = _hit.transform.position,
                                _taskType        = UnitTask.TaskType.Build,
                                _itemToPickUp    = _hit.transform.gameObject,
                                _requiredTool    = Unit.UnitTool.Hammer,
                                _taskDescription = "Building An Oxegen Generator"
                            };
                            tempWorker.AddTask(tempTask);
                        }
                        break;

                    case "Monster":
                        if (_currentSelectedObject.transform.tag == "Worker")
                        {
                            Worker tempWorker = _currentSelectedObject.transform.gameObject.GetComponent <Worker>();

                            if ((int)WorldController.GetWorldController._miningLevel >= 1)
                            {
                                UnitTask tempTask = new UnitTask
                                {
                                    _location        = _hit.transform.position,
                                    _taskType        = UnitTask.TaskType.Attack,
                                    _requiredTool    = Unit.UnitTool.Weapon,
                                    _taskDescription = "Attacking monster"
                                };
                                tempWorker.SetTask(tempTask);
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
Exemple #23
0
 public ActionResult GetTaskStatus(string statusName, String taskName)
 {
     unitTask = TaskSwitch(taskName);
     return(View(unitTask));
 }
Exemple #24
0
        //添加单位到下一个任务中
        protected bool AddUnitToTask(Task objAction, TUnit specificUnit = null)
        {
            if (objAction == null)
            {
                return(false);
            }
            TUnit unit      = null;
            int   enumIndex = objAction.EnumIndex;
            TEnum enumType  = objAction.Type;

            //从空闲列表里面取出一个
            if (specificUnit == null)
            {
                if (PreTask != objAction)
                {
                    //排序Unit
                    var calcImport = ConfigData[enumIndex].CalcUnitImport;
                    foreach (var item in TypeIdles[enumIndex])
                    {
                        item.Importance = calcImport(item, objAction);
                    }
                    TypeIdles[enumIndex].Sort((x, y) => { return(x.Importance > y.Importance ? -1 : 1); });
                }
                unit = TypeIdles[enumIndex].FirstOrDefault();
            }
            //填入指定的Unit
            else if (TypeIdles[enumIndex].Contains(specificUnit))
            {
                unit = specificUnit;
            }
            if (unit == null)
            {
                return(false);
            }
            PreTask = objAction;
            //添加单位任务映射
            if (!UnitTask.ContainsKey(unit))
            {
                UnitTask.Add(unit, objAction);
            }
            else
            {
                UnitTask[unit] = objAction;
            }
            //添加任务单位映射表
            if (!TaskUnit.ContainsKey(objAction))
            {
                TaskUnit.Add(objAction, new HashSet <TUnit>());
            }
            var units = TaskUnit[objAction];

            units.Add(unit);
            //标记已经被分配任务
            AssignedTask[enumIndex].Add(objAction);
            GlobalObjer?.AddTarget(objAction);
            //删除已经被分配的空闲单位
            Enum <TEnum> .ForIndex(e =>
            {
                TypeIdles[e].Remove(unit);
            });

            return(true);
        }
Exemple #25
0
 public void MoveToTarget(Vector3 target)
 {
     unitTask    = UnitTask.MoveToTarget;
     this.target = target;
 }
Exemple #26
0
 /// <summary>
 /// Adds a task to the end of the Workers task list
 /// </summary>
 /// <param name="theTask">Task to be Added</param>
 public void AddTask(UnitTask theTask)
 {
     theTask.UpdateTask();
     _localTaskList.Add(theTask);
 }
Exemple #27
0
 public void Idle() =>
 unitTask = UnitTask.Idle;
    public UnitTask CreateTask(UnitTask.TaskType t, Vector3 pos, GameObject Data)
    {
        UnitTask newTask = null;

        switch (t)
        {
        case UnitTask.TaskType.Mine:
            RockScript Rock = Data.GetComponentInParent <RockScript>();
            if (CanMineTarget(Rock))
            {
                newTask = new UnitTask
                {
                    _location        = pos,
                    _taskType        = UnitTask.TaskType.Mine,
                    _targetRock      = Rock,
                    _requiredTool    = Unit.UnitTool.MiningTool,
                    _taskDescription = "Mining " + Rock.RockType
                };
            }
            break;

        case UnitTask.TaskType.Pickup:
            Ore O = Data.GetComponent <Ore>();
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.Pickup,
                _itemToPickUp    = Data,
                _itemType        = (O != null) ? UnitTask.ItemType.Ore : UnitTask.ItemType.EnergyCrystal,
                _taskDescription = (O != null) ? "Transporting an Ore" : "Transporting an Energy crystal",
                _requiredTool    = Unit.UnitTool.none
            };
            break;

        case UnitTask.TaskType.Walk:
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.Walk,
                _taskDescription = "Walking to location",
                _requiredTool    = Unit.UnitTool.none
            };
            break;

        case UnitTask.TaskType.Attack:
            Monster tempMonster = Data.GetComponent <Monster>();
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.Attack,
                _requiredTool    = Unit.UnitTool.Weapon,
                _taskDescription = "Attacking " + tempMonster._type,
                _targetMonster   = Data.GetComponent <Monster>()
            };
            break;

        case UnitTask.TaskType.flameTarget:
            MushroomCluster mushroom = Data.GetComponentInParent <MushroomCluster>();
            if (mushroom == null)
            {
                return(null);
            }
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.flameTarget,
                _requiredTool    = Unit.UnitTool.FlameThrower,
                _taskDescription = "Burning things",
                _targetMushroom  = mushroom
            };
            break;

        case UnitTask.TaskType.Reinforce:
            break;

        case UnitTask.TaskType.Build:
            Building tempBuilding = Data.GetComponentInParent <Building>();
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.Build,
                _targetBuilding  = Data.GetComponentInParent <Building>(),
                _requiredTool    = Unit.UnitTool.Hammer,
                _taskDescription = "Building a " + tempBuilding.name
            };
            break;

        case UnitTask.TaskType.GetTool:
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.GetTool,
                _taskDescription = "Getting " + RadialMenuScript.instance.NewTool.ToString(),
                _requiredTool    = RadialMenuScript.instance.NewTool
            };
            break;

        case UnitTask.TaskType.RefillOxygen:
            Building closestOxyGen = null;
            foreach (Building building in WorldController.GetWorldController._buildings)
            {
                if (building.tag == TagLibrary.GEN_TAG && building._Built)
                {
                    if (closestOxyGen == null || Vector3.Distance(Data.transform.position, building.transform.position) < Vector3.Distance(Data.transform.position, closestOxyGen.transform.position))
                    {
                        closestOxyGen = building;
                    }
                }
            }
            if (closestOxyGen == null)
            {
                return(null);
            }
            newTask = new UnitTask
            {
                _location        = closestOxyGen.transform.position,
                _taskType        = UnitTask.TaskType.RefillOxygen,
                _taskDescription = "Refilling Oxygen",
                _targetBuilding  = closestOxyGen
            };
            break;

        case UnitTask.TaskType.RefillEnergy:
            Building tempBuidling = Data.GetComponent <Building>();
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.RefillEnergy,
                _targetBuilding  = tempBuidling,
                _taskDescription = "Refilling " + tempBuidling.name + " energy"
            };
            break;

        case UnitTask.TaskType.ClearRubble:
            RubbleScript tempRubble = Data.GetComponentInParent <RubbleScript>();
            if (tempRubble == null)
            {
                return(null);
            }
            newTask = new UnitTask
            {
                _location        = tempRubble.transform.position,
                _taskType        = UnitTask.TaskType.ClearRubble,
                _targetRubble    = tempRubble,
                _requiredTool    = Unit.UnitTool.Shovel,
                _taskDescription = "Clearing rubble"
            };
            break;

        case UnitTask.TaskType.GetInVehicle:
            Vehicle tempVehicle = Data.GetComponent <Vehicle>();
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.GetInVehicle,
                _targetVehicle   = tempVehicle,
                _taskDescription = "Entering vehicle"
            };
            break;

        case UnitTask.TaskType.RechargeVehicle:
            newTask = new UnitTask
            {
                _location        = pos,
                _taskType        = UnitTask.TaskType.RechargeVehicle,
                _taskDescription = "Recharging vehicle"
            };
            break;

        case UnitTask.TaskType.Idle:
        case UnitTask.TaskType.none:
        default:
            Debug.LogError("Invalid Task for Create Task: " + t.ToString());
            break;
        }
        if (newTask == null || !newTask.IsValid())
        {
            return(null);
        }
        return(newTask);
    }
Exemple #29
0
    public static void LogTask(UnitTask t)
    {
#if VALIDATE_TASK
        Debug.Log("Task of type" + t._taskType.ToString() + " Is dupe");
#endif
    }
Exemple #30
0
 public void NotifyAboutTask(UnitTask t)
 {
     //clean up old refs;
     TaskThatTargetThis.Add(t);
 }