Exemplo n.º 1
0
 // Sends units to complete actions in plannedActions list with a small delay between each unit being sent out (just so they don't all spawn at the same time)
 IEnumerator ExecutePlannedActions()
 {
     while (plannedActions.Count > 0)
     {
         if (isNightActions && !SceneController.Instance.togglePseudoPause && !SceneController.Instance.togglePause)
         {
             if (availableUnits > 0)
             {
                 PlannedAction  planned  = plannedActions[0];
                 BaseController baseCont = planned.objectForAction.GetComponent <BaseController>();
                 if ((planned.action == Actions.repair20 || planned.action == Actions.repair50 || planned.action == Actions.repairFull) && baseCont.IsFullHealth())
                 {
                     PopupController._instance.SetPopupText("Structure already at full health. Skipping...");
                     plannedActions.RemoveAt(0);
                     Destroy(plannedActionRemovalIcons[0]);
                     plannedActionRemovalIcons.RemoveAt(0);
                 }
                 else if ((planned.action == Actions.repair20 || planned.action == Actions.repair50 || planned.action == Actions.repairFull) && (ResourceStorage._instance.wood < 3 || ResourceStorage._instance.stone < 3))
                 {
                     PopupController._instance.SetPopupText("Not enough resources to repair. Skipping...");
                     plannedActions.RemoveAt(0);
                     Destroy(plannedActionRemovalIcons[0]);
                     plannedActionRemovalIcons.RemoveAt(0);
                 }
                 else
                 {
                     availableUnits--;
                     NavMeshHit hit;
                     if (NavMesh.SamplePosition(spawnPoint.position, out hit, 10f, NavMesh.AllAreas))
                     {
                         SpawnUnit(hit.position, planned.objectForAction, planned.action);
                         plannedActions.RemoveAt(0);
                         Destroy(plannedActionRemovalIcons[0]);
                         plannedActionRemovalIcons.RemoveAt(0);
                         yield return(new WaitForSeconds(0.5f));
                     }
                 }
             }
             else
             {
                 yield return(null);
             }
         }
         else
         {
             PopupController._instance.SetPopupText("Cannot sent units out during the day. Pausing remaining actions...");
             yield break;
         }
     }
     yield return(null);
 }
Exemplo n.º 2
0
    // Add action + specified object to the plannedActions list for execution once the night cycle comes
    public void PlanAction(Actions action)
    {
        if (plannedActions.Count < 30)
        {
            PlannedAction planned = new PlannedAction();
            planned.action          = action;
            planned.objectForAction = selectedObj;
            plannedActions.Add(planned);

            switch (action)
            {
            case Actions.collect:
                switch (selectedObj.tag)
                {
                case "Wood":
                    AddPlannedAction(ActionIconNames.collectWood);
                    break;

                case "Stone":
                    AddPlannedAction(ActionIconNames.collectStone);
                    break;

                case "Gold":
                    AddPlannedAction(ActionIconNames.collectGold);
                    break;

                default:
                    break;
                }
                break;

            case Actions.partialFeed:
                AddPlannedAction(ActionIconNames.partialFeed);
                break;

            case Actions.fullFeed:
                AddPlannedAction(ActionIconNames.fullFeed);
                break;

            case Actions.convert:
                AddPlannedAction(ActionIconNames.convert);
                break;

            case Actions.repair20:
            case Actions.repair50:
            case Actions.repairFull:
                AddPlannedAction(ActionIconNames.repair);
                break;

            case Actions.subjugate:
                AddPlannedAction(ActionIconNames.subjugate);
                break;

            default:
                break;
            }
        }
        else
        {
            PopupController._instance.SetPopupText("Max 30 planned actions");
        }
    }