Ejemplo n.º 1
0
        public void UpdateTaskLauncherTasks(FactionEntity sourceEntity, TaskLauncher taskLauncher)
        {
            if (taskLauncher == null || taskLauncher.Initiated == false || taskLauncher.GetTasksCount() == 0) //if the task launcher is invalid or the source can't manage a task
            {
                return;
            }

            for (int taskID = 0; taskID < taskLauncher.GetTasksCount(); taskID++) //go through all tasks
            {
                FactionEntityTask task = taskLauncher.GetTask(taskID);
                if (task.IsEnabled() == true)
                {
                    TaskUI taskUI = Add(new TaskUIAttributes
                    {
                        ID           = taskID,
                        type         = task.GetTaskType(),
                        icon         = task.GetIcon(),
                        source       = sourceEntity,
                        taskLauncher = taskLauncher
                    }, task.GetTaskPanelCategory());

                    if (task.GetTaskType() == TaskTypes.createUnit) //if this is a unit creation task, check if it has reached its limit and change task ui image color accordinly
                    {
                        taskUI.GetComponent <Image>().color = sourceEntity.FactionMgr.HasReachedLimit(task.UnitCode, task.UnitCategory) == true ? Color.red : Color.white;
                    }
                }
            }

            UpdateInProgressTasks(taskLauncher); //show the in progress tasks
        }
        /// <summary>
        /// Adds a TaskLauncher instance to be tracked by the NPCUnitRegulator if it includes tasks that allow the regulated unit type.
        /// </summary>
        /// <param name="taskLauncher">TaskLauncher instance to add.</param>
        public void AddTaskLauncher(TaskLauncher taskLauncher)
        {
            if (unitCreators.ContainsKey(taskLauncher) || //if the task launcher is already registered
                taskLauncher.FactionEntity.FactionID != factionMgr.FactionID)    //or the task launcher doesn't belong to the same NPC faction.
            {
                return;
            }

            for (int taskID = 0; taskID < taskLauncher.GetTasksCount(); taskID++)
            {
                FactionEntityTask nextTask = taskLauncher.GetTask(taskID);
                //if the task's type is unit creation and it the unit to create code matches the code of unit type that is regulated by this component
                if (nextTask.GetTaskType() == TaskTypes.createUnit && nextTask.UnitCode == Code)
                {
                    if (unitCreators.TryGetValue(taskLauncher, out List <int> taskIDList)) //task launcher already is registered as key, just append value list
                    {
                        taskIDList.Add(taskID);
                    }
                    else //register task launcher as new key and task ID as the only element in the value list.
                    {
                        unitCreators.Add(taskLauncher, new List <int>(new int[] { taskID }));
                    }
                }
            }
        }
Ejemplo n.º 3
0
 //update an upgraded unit creation task's info:
 private void UpdateUnitCreationTask(TaskLauncher taskLauncher, string upgradedUnitCode, Unit targetUnitPrefab, Upgrade.NewTaskInfo newTaskInfo)
 {
     //go through the tasks:
     for (int i = 0; i < taskLauncher.GetTasksCount(); i++)
     {
         taskLauncher.GetTask(i).Update(upgradedUnitCode, targetUnitPrefab, newTaskInfo);
     }
 }
Ejemplo n.º 4
0
        //whenever a task launcher is added or removed, this method will be called to add/remove it to/from the upgrade tasks list:
        public void UpdateUpgradeTasks(TaskLauncher taskLauncher, bool add, Upgrade upgrade = null)
        {
            //if taskID is set to -1 and add = false, then all the tasks with the assigned task launcher will be removed
            //if taskID >= 0 is valid, then only the upgrade task with taskID in the task launcher will be removed.

            if (add == false) //if this task launcher is getting removed.
            {
                int i = 0;
                //go through all registerd task launchers in this component
                while (i < upgradeTasks.Count)
                {
                    if (upgradeTasks[i].taskLauncher == taskLauncher || (upgrade != null && IsUpgradeMatch(upgradeTasks[i].taskLauncher, upgradeTasks[i].taskID, upgrade) == true)) //if the task launcher matches:
                                                                                                                                                                                    //remove it:
                    {
                        upgradeTasks.RemoveAt(i);
                    }
                    else
                    {
                        i++; //move on
                    }
                }
            }
            else if (taskLauncher.GetTasksCount() > 0) //if we're adding tasks and this task launcher has tasks.
            {
                //loop through the task launcher's task
                for (int taskID = 0; taskID < taskLauncher.GetTasksCount(); taskID++)
                {
                    //if this is the upgrade task that we're looking for.
                    if (taskLauncher.GetTask(taskID).GetTaskType() == TaskTypes.upgrade)
                    {
                        //go ahead and add it:
                        UpgradeTask newUpgradeTask = new UpgradeTask
                        {
                            taskLauncher = taskLauncher,
                            taskID       = taskID
                        };
                        //add it to the list:
                        upgradeTasks.Add(newUpgradeTask);

                        //and activate the upgrade manager:
                        Activate();
                    }
                }
            }
        }
Ejemplo n.º 5
0
 //whenever a building is added or removed, this method will be called to add/remove it to the lists in the spawn units:
 public void UpdateUnitCreatorList(TaskLauncher taskLauncher, bool add)
 {
     if (add == false) //if this task launcher is getting removed.
     {
         int i = 0;
         //go through all registerd task launchers in this component
         while (i < unitCreatorList.Count)
         {
             if (unitCreatorList[i].taskLauncher == taskLauncher) //if the task launcher matches:
             //remove it:
             {
                 unitCreatorList.RemoveAt(i);
             }
             else
             {
                 i++; //move on
             }
         }
     }
     //Make sure that this task launcher can actually create units and that there units to spawn
     else if (taskLauncher.GetTasksCount() > 0) //if we're adding tasks and this task launcher has tasks.
     {
         //loop through the task launcher's tasks
         for (int taskID = 0; taskID < taskLauncher.GetTasksCount(); taskID++)
         {
             //if this is a unit creation task:
             if (taskLauncher.GetTask(taskID).GetTaskType() == TaskTypes.createUnit && taskLauncher.GetTask(taskID).UnitCode == code)
             {
                 //if the unit code is included in the list => that unit is managed by this regulator
                 //go ahead and add it:
                 UnitCreatorInfo newUnitCreator = new UnitCreatorInfo
                 {
                     //set the unit creator info:
                     taskLauncher = taskLauncher,
                     taskID       = taskID
                 };
                 //add it to the list:
                 unitCreatorList.Add(newUnitCreator);
             }
         }
     }
 }