public void performCurrentTask() { _previousActionSteps = currentActionSteps; // DO TASK // ActionStep currentStep = currentActionSteps[_currentStepNum]; //Debug.LogWarning("Current action - " + currentStep.getAction()); currentStep.performAction(creature); // TASK UPDATE COMPLETE - Check status // if (currentStep.isStatus(Tasks.TASK_STATUS.Complete)) { //Debug.LogWarning("Step complete - " + currentStep.getAction()); // Next step // if (_currentStepNum != currentActionSteps.Length - 1) { ActionStep previousStep = currentActionSteps[_currentStepNum]; _currentStepNum++; currentStep = currentActionSteps[_currentStepNum]; // If the new step doesn't have a target, and this one did, copy it over, For example Locate // if (!currentStep.HasTargetThing() && previousStep.HasTargetThing()) { currentStep.SetTarget(previousStep._targetThing); } else if (!currentStep.HasTargetPosition() && previousStep.HasTargetPosition()) { currentStep.SetTargetPosition(previousStep._targetPosition); } else { //Debug.LogWarning("No step target from previous, currentstep-previousstep " + currentStep.getAction() + "-" + previousStep.getAction()); } creature.SetNavMeshAgentDestination(currentStep._targetPosition); taskStatus = Tasks.TASK_STATUS.Incomplete; } else { taskStatus = Tasks.TASK_STATUS.Complete; creature.RequestObservationUpdate(); } return; } // FAILED // else if (currentStep.isStatus(Tasks.TASK_STATUS.Failed)) { // Notify creature of failure to record/discard as needed // creature.SoThisFailed(currentStep); ActionStep[] steps = CreatureConstants.GetExceptionActions(taskType, currentStep.failReason, creature); if (steps != null) { _previousActionSteps = currentActionSteps; currentActionSteps = steps; _currentStepNum = 0; taskStatus = Tasks.TASK_STATUS.Started; } else { taskStatus = Tasks.TASK_STATUS.Cancelled; } return; } }
public void CancelTask() { taskStatus = Tasks.TASK_STATUS.Cancelled; }
// MAIN METHOD // public void performAction(Creature performer) { elapsedTime += Time.deltaTime; //Debug.LogWarning("Elapsed Time - " + elapsedTime + " Max - " + maxAllowedTime); if (elapsedTime > maxAllowedTime) { DebugMenu.AppendLine(performer.thingName + " has exceeded task time for task. Resetting"); Debug.Log(performer.thingName + " has exceeded task time for task. Resetting"); status = Tasks.TASK_STATUS.Failed; failReason = FailReason.ExceededTimeLimit; if (_targetThing != null) { _targetThing.MakeAvailable(performer); } return; } //Debug.Log("Performing action " + action + " For Task - " + associatedTask); // LOCATE // if (action == Actions.Locate) { // LOCATE EAT // if (associatedTask == Tasks.CreatureTasks.EAT) { //Debug.LogWarning("Locating consumeable"); Thing target = performer.GetClosestKnownReachableConsumable(); if (target == null) { // Target doesn't know of any consumables // failReason = FailReason.NoKnownFood; status = Tasks.TASK_STATUS.Failed; return; } else { _targetThing = target; _targetPosition = target.transform.position; _targetThing.MakeUnavailable(); //Debug.LogWarning("Locate task complete with target - " + _targetThing.name); status = Tasks.TASK_STATUS.Complete; } } // LOCATE SLEEP // else if (associatedTask == Tasks.CreatureTasks.SLEEP) { // Search for target ground // float boxSizeMult = performer.miscVariables[MiscVariables.CreatureMiscVariables.Agent_Locate_Sleep_Area_BoxCast_Size_Multipler]; Vector3 raycastHit = performer.BoxCastNotMeGetClosestPoint(5, Vector3.down); if (raycastHit != Vector3.positiveInfinity) { raycastHit.y = performer.transform.position.y; _targetPosition = raycastHit; performer.GetCreatureAgent().SetDestination(_targetPosition); creatureAgentDestinationHasBeenSet = true; status = Tasks.TASK_STATUS.Complete; return; } else { // Get's picked up by the TaskManager Update() // status = Tasks.TASK_STATUS.Failed; failReason = FailReason.InfinityDistance; } } // LOCATE EXPLORE // else if (associatedTask == Tasks.CreatureTasks.EXPLORE) { //Debug.LogWarning("Locating explore sector"); GridSector sector = performer.GetClosestUnexploredSector(); if (sector != null) { Vector3 explorePoint = sector.GetRandomPositionInSector; _targetPosition = explorePoint; } else { //Debug.Log("No unexplored sectors!"); _targetPosition = performer.GetRandomKnownSectorPosition(); } performer.GetCreatureAgent().SetDestination(_targetPosition); creatureAgentDestinationHasBeenSet = true; status = Tasks.TASK_STATUS.Complete; return; } // LOCATE GATHER // else if (associatedTask == Tasks.CreatureTasks.GATHER) { //Thing target = performer.GetClosestKnownReachableThing(targetBaseType); } } // MOVE TO // else if (action == Actions.MoveTo) { Debug.DrawLine(performer.transform.position, _targetPosition, Color.cyan, .5f); // The agent should have a destination before getting to this point // if (!creatureAgentDestinationHasBeenSet) { failReason = FailReason.MoveToWithNoDestination; Debug.LogError("ERROR MoveTo with no destination"); status = Tasks.TASK_STATUS.Failed; return; } else // Needs to be an else since it takes a frame for the remaining distance to calculate { if (performer.getDistanceFromDestination() == Mathf.Infinity) { Debug.Log("Infinity distance"); failReason = FailReason.InfinityDistance; status = Tasks.TASK_STATUS.Failed; return; } if (associatedTask == Tasks.CreatureTasks.MOVE_AND_OBSERVE) { performer.RequestObservationUpdate(); } // Raycast if we're close enough to the target to where we should be able to see it // float distanceBeforeRayCastCheckOnTarget = performer.miscVariables [MiscVariables.CreatureMiscVariables.Agent_MoveTo_Raycast_For_Target_When_Distance_Below]; // Arrived // float distanceToCompleteArrival; if (associatedTask != Tasks.CreatureTasks.EXPLORE) { distanceToCompleteArrival = performer.getCreatureStats().getDistanceFromTargetBeforeConsideredReached(); } else { distanceToCompleteArrival = 50; } if (performer.getDistanceFromDestination() <= distanceToCompleteArrival) { status = Tasks.TASK_STATUS.Complete; return; } // Haven't arrived yet else if (_targetThing != null) { // Check if we're close enough to start raycasting // if (performer.getDistanceFromDestination() < distanceBeforeRayCastCheckOnTarget) { if (_targetThing != null) { // Raycast forward // if (!performer.IsTargetInFrontOfMe(_targetThing)) { performer.GetCreatureAgent().SetIgnoreCollisions(false); } else { performer.GetCreatureAgent().SetIgnoreCollisions(true); } } } // Not close enough, make sure orbiting is disabled // else { performer.GetCreatureAgent().SetIgnoreCollisions(false); } } } } // ADD // else if (action == Actions.Add) { CreatureAgent agent = performer.GetCreatureAgent(); // Tractor Beam // if (agent.grabType == CreatureGrabType.TractorBeam) { // Touching Target // if (Vector3.Distance(_targetThing.transform.position, performer.transform.position) < .5f) { if (performer.AddThingToInventory(_targetThing)) { performer.GetCreatureAgent().CollisionRemoveIfPresent(_targetThing.transform); _targetThing.transform.SetParent(performer.transform); status = Tasks.TASK_STATUS.Complete; return; } else { Debug.LogWarning("Failed adding thing to inventory"); failReason = FailReason.FailureAddingToInventory; status = Tasks.TASK_STATUS.Failed; return; } } } } // EAT // else if (action == Actions.Eat) { if (_targetThing.beConsumed(performer)) { performer.PlayOneShot(); performer.ConsumeThing(_targetThing); status = Tasks.TASK_STATUS.Complete; return; } } // Land // else if (action == Actions.Land) { CreatureAgent agent = performer.GetCreatureAgent(); if (!agent.IsLanding()) { // Landing failed // agent.Land(); return; } return; } // DEACTIVATE SELF // else if (action == Actions.Sleep) { if (performer.GetCurrentState() != Creature.CREATURE_STATE.SLEEP) { performer.GetCreatureAgent().Sleep(); } if (!performer.StillNeedsSleep()) { status = Tasks.TASK_STATUS.Complete; } } }
public bool isStatus(Tasks.TASK_STATUS status) { return(status == this.taskStatus); }
public bool isStatus(Tasks.TASK_STATUS status) { return(this.status == status); }