예제 #1
0
 private void RunOutputChanges(Agent agent, WorldObjectType.State newState, WorldObjectType.State currentState)
 {
     for (int i = 0; i < worldObjectType.statesOutputChanges.Count; i++)
     {
         OutputChange outputChange = worldObjectType.statesOutputChanges[i];
         // currentState can be null on Start
         if (newState.enterOutputChangesIndexes.Contains(i) || (currentState != null && currentState.exitOutputChangesIndexes.Contains(i)))
         {
             float amount = outputChange.outputChangeType.CalculateAmount(agent, this, outputChange, null);
             if (!outputChange.CheckConditions(this, agent, null, amount))
             {
                 Debug.Log(agent + ": WorldObject.RunOutputChanges - output conditions failed - " + this);
                 if (outputChange.stopType == OutputChange.StopType.OnOCCFailed)
                 {
                     return;
                 }
             }
             bool succeeded = outputChange.outputChangeType.MakeChange(agent, this, outputChange, null, amount, out bool forceStop);
             Debug.Log(agent + ": WorldObject.RunOutputChanges - output condition " + outputChange.outputChangeType.name + " - " + succeeded);
             if ((forceStop && !outputChange.blockMakeChangeForcedStop) ||
                 (outputChange.stopType == OutputChange.StopType.OnChangeFailed && !succeeded))
             {
                 return;
             }
         }
     }
 }
예제 #2
0
        // TODO: I think this should be in Start
        private new void Awake()
        {
            base.Awake();
            worldObjectType = (WorldObjectType)entityType;

            timeManager            = GameObject.Find("TimeManager").GetComponent <TimeManager>();
            animator               = GetComponent <Animator>();
            completePoints         = startCompletePoints;
            currentState           = null;
            currentSkinPrefabIndex = -1;

            ResetEntity();
        }
예제 #3
0
        public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop)
        {
            forceStop = false;
            WorldObject worldObject = target as WorldObject;

            WorldObjectType.State newState = worldObject.worldObjectType.states.Find(x => x.name == outputChange.stringValue);
            if (newState == null)
            {
                Debug.LogError(agent.name + ": " + worldObject.name + " '" + worldObject.currentState.name + "' WorldObjectStateOCT - Trying to switch" +
                               "to state '" + outputChange.stringValue + "' that doesn't exist.  Please check spelling.");
                return(false);
            }

            return(((WorldObject)target).ChangeState(agent, newState));
        }
예제 #4
0
        private IEnumerator StateTimedOut(float seconds)
        {
            yield return(new WaitForSeconds(seconds));

            WorldObjectType.State newState = worldObjectType.states.Find(x => x.name == currentState.nextStateName);

            if (newState == null)
            {
                Debug.LogError(name + ": '" + currentState.name + "' StateTimedOut - Trying to switch to state '" + currentState.nextStateName +
                               "' that doesn't exist.  Please check spelling.");
            }
            else
            {
                ChangeState(null, newState);
            }
        }
예제 #5
0
        // This is called after a completion change or damage change to see if a new state should be entered
        private void ChangeStateIfNeeded(bool dueToCompletionChange)
        {
            if (currentState == null)
            {
                return;
            }

            WorldObjectType.State newState = null;
            if (dueToCompletionChange)
            {
                if (completePoints >= currentState.minComplete && completePoints <= currentState.maxComplete)
                {
                    return;
                }
                foreach (WorldObjectType.State state in worldObjectType.states)
                {
                    if (completePoints >= state.minComplete && completePoints <= state.maxComplete)
                    {
                        newState = state;
                        break;
                    }
                }
            }
            else
            {
                if (damage >= currentState.minDamage && damage <= currentState.maxDamage)
                {
                    return;
                }
                foreach (WorldObjectType.State state in worldObjectType.states)
                {
                    if (damage >= state.minDamage && damage <= state.maxDamage)
                    {
                        newState = state;
                        break;
                    }
                }
            }

            if (newState != null)
            {
                ChangeState(null, newState);
            }
        }
예제 #6
0
        private void Start()
        {
            if (worldObjectType.states.Count > 0)
            {
                if (startState != null)
                {
                    // Have to refresh the start state from WOT since it might be stale (WO has a serialized copy saved)
                    startState = worldObjectType.states.Find(x => x.name == startState.name);
                    if (startState == null)
                    {
                        Debug.Log(name + ": Start State '" + startState.name + "' can't be found.  Please fix in inspector.  Setting to first state.");
                        startState = worldObjectType.states[0];
                    }
                    ChangeState(null, startState);
                }
                else
                {
                    ChangeState(null, worldObjectType.states[0]);
                }
            }

            if (worldObjectType.completeType == WorldObjectType.CompleteType.None || completePoints >= worldObjectType.pointsToComplete)
            {
                isComplete = true;
            }
            else
            {
                isComplete = false;
            }

            // If WorldObject grows and there are no states - start up the growth
            if (worldObjectType.completeType == WorldObjectType.CompleteType.Grows && worldObjectType.states.Count == 0)
            {
                StartCoroutine(GrowCoroutine());
            }

            ChangePrefabIfNeeded();
        }
예제 #7
0
        // Changes state if allowed - return true if a state change occurred
        public bool ChangeState(Agent agent, WorldObjectType.State newState)
        {
            if (newState != null && newState != currentState)
            {
                // currentState will be null when starting up so see if OutputChanges should be run on startup
                if ((currentState != null || runOutputChangesOnStart) &&
                    (newState.hasEnterOutputChanges || (currentState != null && currentState.hasExitOutputChanges)))
                {
                    RunOutputChanges(agent, newState, currentState);
                }

                Debug.Log(name + ": Changed State from " + (currentState == null ? "Null" : currentState.name) + " to " + newState.name);
                currentState = newState;
                ChangePrefabIfNeeded();

                // Start timer if this state is timed
                if (newState.isTimed)
                {
                    float time = newState.secondsUntilNextState;
                    if (newState.timeInGameMinutes)
                    {
                        time = newState.gameMinutesUntilNextState * timeManager.RealTimeSecondsPerGameMinute();
                    }

                    StartCoroutine(StateTimedOut(time));
                }

                if (worldObjectType.completeType == WorldObjectType.CompleteType.Grows && worldObjectType.states.Count > 0 && currentState.allowsCompletion)
                {
                    StartCoroutine(GrowCoroutine());
                }

                return(true);
            }
            return(false);
        }