// Start is called before the first frame update void Start() { parameters.Clear(); detect = new Parameter(Parameter.ParamTypes.BOOLEAN, "DetectPlayer"); life = new Parameter(Parameter.ParamTypes.INTEGER, "Life"); parameters.Add(detect); parameters.Add(life); //States IDLE_STATE waitForPlayer = new IDLE_STATE(); waitForPlayer.name = "WaitForPlayer"; tranformToDemon = new TRANSFORM_STATE(); tranformToDemon.name = "BECOME DEMON"; ATTACK_STATE attackPlayer = new ATTACK_STATE(); attackPlayer.name = "AttackPlayer"; FLEE_STATE fleeFromPlayer = new FLEE_STATE(); fleeFromPlayer.name = "FLEE"; returnBackToNormal = new TRANSFORM_STATE(); returnBackToNormal.name = "BECOME HUMAN"; deathReturnNormalForm = new TRANSFORM_STATE(); deathReturnNormalForm.name = "REVERT FORM"; IDLE_STATE deadDemon = new IDLE_STATE(); deadDemon.name = "DEAD"; //Transitions Transition waitToTransform_T = new Transition(); waitToTransform_T.nextState = tranformToDemon; Transition transformToAttack_T = new Transition(); transformToAttack_T.nextState = attackPlayer; //Return back transition Transition AttackToNormalForm_T = new Transition(); AttackToNormalForm_T.nextState = returnBackToNormal; Transition AttackToFlee_T = new Transition(); AttackToFlee_T.nextState = fleeFromPlayer; Transition normalFormToWait_T = new Transition(); normalFormToWait_T.nextState = waitForPlayer; Transition attackToRevertForm_T = new Transition(); attackToRevertForm_T.nextState = deathReturnNormalForm; Transition fleeToReverForm_T = new Transition(); fleeToReverForm_T = new Transition(); fleeToReverForm_T.nextState = deathReturnNormalForm; Transition RevertFormToDeath_T = new Transition(); RevertFormToDeath_T.nextState = deadDemon; //Condition Condition checkDetectPlayer_CON = new Condition(Condition.ConditionTypes.TRUE, detect); //PLUG CONDITIONS TO TRANSITIONS waitToTransform_T.conditions.Add(checkDetectPlayer_CON); waitForPlayer.transitions.Add(waitToTransform_T); tranformToDemon.transitions.Add(transformToAttack_T); //waitToAttack_T.conditions.Add(checkDetectPlayer_CON); //waitForPlayer.transitions.Add(waitToAttack_T); //------------------- Condition checkLostPlayer_CON = new Condition(Condition.ConditionTypes.FALSE, detect); AttackToNormalForm_T.conditions.Add(checkLostPlayer_CON); //normalFormToWait.conditions.Add(checkLostPlayer_CON); attackPlayer.transitions.Add(AttackToNormalForm_T); returnBackToNormal.transitions.Add(normalFormToWait_T); Condition checkLife_CON = new Condition(Condition.ConditionTypes.EQUAL, life); checkLife_CON.intValue = 0; attackToRevertForm_T.conditions.Add(checkLife_CON); attackPlayer.transitions.Add(attackToRevertForm_T); deathReturnNormalForm.transitions.Add(RevertFormToDeath_T); Condition LowLifeFlee_CON = new Condition(Condition.ConditionTypes.LESS, life); LowLifeFlee_CON.intValue = 2; AttackToFlee_T.conditions.Add(LowLifeFlee_CON); attackPlayer.transitions.Add(AttackToFlee_T); fleeToReverForm_T.conditions.Add(checkLife_CON); fleeFromPlayer.transitions.Add(fleeToReverForm_T); //Piece them together currentState = waitForPlayer; states.Add(waitForPlayer); states.Add(attackPlayer); states.Add(tranformToDemon); states.Add(returnBackToNormal); states.Add(fleeFromPlayer); states.Add(deathReturnNormalForm); states.Add(deadDemon); //parameters.Add() }
// Start is called before the first frame update void Start() { states.Clear(); Debug.Log("DERPADERPA"); manager = GameObject.FindGameObjectWithTag("GAMEMANAGER").GetComponent <GameManager>(); //Define States IDLE_STATE sleep = new IDLE_STATE(); sleep.name = "SLEEP"; SETSLEEP_STATE awaken = new SETSLEEP_STATE(); awaken.name = "WAKEY WAKEY"; awaken.value = false; WALKROUTE_STATE goWork = new WALKROUTE_STATE(); goWork.name = "Goto Work"; WALKROUTE_STATE goHome = new WALKROUTE_STATE(); goHome.name = "GO HOME"; SETSLEEP_STATE FallAsleep = new SETSLEEP_STATE(); FallAsleep.name = "SLEEPY"; FallAsleep.value = true; TOGGLEOBJECT_STATE openShop = new TOGGLEOBJECT_STATE(); openShop.name = "OPEN SHOP"; TOGGLEOBJECT_STATE closeShop = new TOGGLEOBJECT_STATE(); closeShop.name = "CLOSE SHOP"; //SELECT THE SHOP OBJECT openShop.AddSelectedObjects(new int[] { 0 }); closeShop.AddSelectedObjects(new int[] { 0 }); //SELECT ROUTE HOME goWork.selectedRoute = 0; goHome.selectedRoute = 1; //Define Transitions Transition sleepToAwaken_T = new Transition(); Transition AwakenToWork_T = new Transition(); Transition workToOpenShop_T = new Transition(); Transition openShopToCloseShop_T = new Transition(); Transition closeShopToHome_T = new Transition(); Transition HomeToFallAsleep_T = new Transition(); Transition FallAsleepToSleep_T = new Transition(); //Check if Hour>5 (START WORK AT 6AM) Condition checkWorkTime_CON = new Condition(); checkWorkTime_CON.p = parameters[HOUR_PARAM]; checkWorkTime_CON.type = Condition.ConditionTypes.GREATER; checkWorkTime_CON.intValue = 5; //Check if I already worked today Condition checkIfWorkedToday_CON = new Condition(); checkIfWorkedToday_CON.p = parameters[HASWORKED_PARAM]; checkIfWorkedToday_CON.type = Condition.ConditionTypes.FALSE; //Check if Sunday Condition checkifNotSunday_CON = new Condition(); checkifNotSunday_CON.p = parameters[DAY_PARAM]; checkifNotSunday_CON.type = Condition.ConditionTypes.NOTEQUAL; checkifNotSunday_CON.intValue = 6; //Check if Hour>15 (END WORK AT 4PM) Condition checkEndWorkTime_CON = new Condition(); checkEndWorkTime_CON.p = parameters[HOUR_PARAM]; checkEndWorkTime_CON.type = Condition.ConditionTypes.GREATER; checkEndWorkTime_CON.intValue = 15; //Prepare Transition sleepToAwaken_T.conditions.Add(checkWorkTime_CON); sleepToAwaken_T.conditions.Add(checkIfWorkedToday_CON); sleepToAwaken_T.conditions.Add(checkifNotSunday_CON); sleepToAwaken_T.nextState = awaken; AwakenToWork_T.nextState = goWork; workToOpenShop_T.nextState = openShop; openShopToCloseShop_T.nextState = closeShop; openShopToCloseShop_T.conditions.Add(checkEndWorkTime_CON); //closeShopToHome_T.conditions.Add(checkEndWorkTime_CON); closeShopToHome_T.nextState = goHome; HomeToFallAsleep_T.nextState = FallAsleep; FallAsleepToSleep_T.nextState = sleep; //Add Transition to State sleep.transitions.Add(sleepToAwaken_T); awaken.transitions.Add(AwakenToWork_T); goWork.transitions.Add(workToOpenShop_T); openShop.transitions.Add(openShopToCloseShop_T); closeShop.transitions.Add(closeShopToHome_T); //goWork.transitions.Add(openShopToHome_T); goHome.transitions.Add(HomeToFallAsleep_T); FallAsleep.transitions.Add(FallAsleepToSleep_T); //BEGIN sleep.Initialize(this); goWork.Initialize(this); openShop.Initialize(this); closeShop.Initialize(this); goHome.Initialize(this); awaken.Initialize(this); FallAsleep.Initialize(this); currentState = sleep; currentState.OnStateEnter(this); states.Add(sleep); states.Add(goWork); states.Add(openShop); states.Add(closeShop); states.Add(goHome); states.Add(awaken); states.Add(FallAsleep); Debug.Log(states.Count); }
public override void Update() { if (Application.IsPlaying(gameObject)) { parameters[HOUR_PARAM].intType = (int)manager.hour; parameters[DAY_PARAM].intType = (int)manager.currentDate; if (manager.hour > 15) { parameters[HASWORKED_PARAM].boolType = true; } if ((int)manager.hour == 0) { Debug.Log("NEW DAY"); parameters[HASWORKED_PARAM].boolType = false; } base.Update(); } else { if (!loaded) { states.Clear(); Debug.Log("DERPADERPA"); manager = GameObject.FindGameObjectWithTag("GAMEMANAGER").GetComponent <GameManager>(); //Define States IDLE_STATE sleep = new IDLE_STATE(); sleep.name = "SLEEP"; WALKROUTE_STATE goWork = new WALKROUTE_STATE(); goWork.name = "Goto Work"; WALKROUTE_STATE goHome = new WALKROUTE_STATE(); goHome.name = "GO HOME"; //SELECT ROUTE HOME goWork.selectedRoute = 0; goHome.selectedRoute = 1; //Define Transitions Transition sleepToWork_T = new Transition(); Transition WorkToHome_T = new Transition(); Transition HomeToSleep_T = new Transition(); //Check if Hour>5 (START WORK AT 6AM) Condition checkWorkTime_CON = new Condition(); checkWorkTime_CON.p = parameters[HOUR_PARAM]; checkWorkTime_CON.type = Condition.ConditionTypes.GREATER; checkWorkTime_CON.intValue = 5; //Check if I already worked today Condition checkIfWorkedToday_CON = new Condition(); checkIfWorkedToday_CON.p = parameters[HASWORKED_PARAM]; checkIfWorkedToday_CON.type = Condition.ConditionTypes.FALSE; //Check if Sunday Condition checkifNotSunday_CON = new Condition(); checkifNotSunday_CON.p = parameters[DAY_PARAM]; checkifNotSunday_CON.type = Condition.ConditionTypes.NOTEQUAL; checkifNotSunday_CON.intValue = 6; //Check if Hour>15 (END WORK AT 4PM) Condition checkEndWorkTime_CON = new Condition(); checkEndWorkTime_CON.p = parameters[HOUR_PARAM]; checkEndWorkTime_CON.type = Condition.ConditionTypes.GREATER; checkEndWorkTime_CON.intValue = 15; //Prepare Transition sleepToWork_T.conditions.Add(checkWorkTime_CON); sleepToWork_T.conditions.Add(checkIfWorkedToday_CON); sleepToWork_T.conditions.Add(checkifNotSunday_CON); sleepToWork_T.nextState = goWork; WorkToHome_T.conditions.Add(checkEndWorkTime_CON); WorkToHome_T.nextState = goHome; HomeToSleep_T.nextState = sleep; //Add Transition to State sleep.transitions.Add(sleepToWork_T); goWork.transitions.Add(WorkToHome_T); goHome.transitions.Add(HomeToSleep_T); //BEGIN sleep.Initialize(this); goWork.Initialize(this); goHome.Initialize(this); currentState = sleep; currentState.OnStateEnter(this); states.Add(sleep); states.Add(goWork); states.Add(goHome); Debug.Log(states.Count); loaded = true; } } }
// Start is called before the first frame update public override void Start() { ai = GetComponentInParent <AiCore>(); ai.OnStunned.AddListener(InterruptEvent); ai.OnExitStun.AddListener(EndInterruptEvent); manager = GameObject.FindGameObjectWithTag("GAMEMANAGER").GetComponent <GameManager>(); Parameter workParam = new Parameter(Parameter.ParamTypes.BOOLEAN, "GOWORK"); InterruptParam = new Parameter(Parameter.ParamTypes.TRIGGER, "STUN"); JudgeParam = new Parameter(Parameter.ParamTypes.TRIGGER, "JUDGE"); HourParam = new Parameter(Parameter.ParamTypes.INTEGER, "TIME"); EnergyParam = new Parameter(Parameter.ParamTypes.FLOAT, "ENERGY"); EnergyParam.floatType = ai.Energy; lowEnergyParam = new Parameter(Parameter.ParamTypes.TRIGGER, "LOWENERGY"); parameters.Add(workParam); parameters.Add(InterruptParam); parameters.Add(JudgeParam); parameters.Add(HourParam); parameters.Add(EnergyParam); parameters.Add(lowEnergyParam); REST_STATE sleep = new REST_STATE(); sleep.name = "SLEEP"; sleep.multiplier = 6; WORK_STATE work = new WORK_STATE(); work.name = "WORK"; work.workStation = workStation; work.directory = areaDirectory; work.workArea = AreaDirectory.COFEESHOP_AREA; work.ShopMenu = ShopMenu; WORK_STATE home = new WORK_STATE(); home.name = "HOME"; home.workStation = homeStation; home.directory = areaDirectory; home.workArea = AreaDirectory.HOME_ROOM1_AREA; IDLE_STATE Interrupted = new IDLE_STATE(); Interrupted.name = "INTERRUPTED"; IDLE_STATE Judge = new IDLE_STATE(); Judge.name = "JUDGE"; REST_STATE Rest = new REST_STATE(); Rest.name = "REST"; Rest.searchBench = true; sleep.CreateTransition(work, new Condition(Condition.ConditionTypes.GREATER, HourParam, 6), new Condition(Condition.ConditionTypes.LESS, HourParam, 16)); work.CreateTransition(home, new Condition(Condition.ConditionTypes.GREATER, HourParam, 15)); home.CreateTransition(sleep, new Condition(Condition.ConditionTypes.LESS, HourParam, 1)); Rest.CreateTransition(Judge, new Condition(Condition.ConditionTypes.GREATER, EnergyParam, 50f)); //sleep.CreateTransition(work, new Condition(Condition.ConditionTypes.TRUE, workParam, true)); Interrupted.CreateTransition(Judge, new Condition(Condition.ConditionTypes.TRUE, JudgeParam, true)); Judge.CreateTransition(work, new Condition(Condition.ConditionTypes.GREATER, HourParam, 6), new Condition(Condition.ConditionTypes.LESS, HourParam, 17)); Judge.CreateTransition(home, new Condition(Condition.ConditionTypes.GREATER, HourParam, 15)); CreateImpulseTransition(Interrupted, new Condition(Condition.ConditionTypes.TRUE, InterruptParam, true)); CreateImpulseTransition(Rest, new Condition(Condition.ConditionTypes.TRUE, lowEnergyParam, true)); sleep.Initialize(this); work.Initialize(this); home.Initialize(this); Interrupted.Initialize(this); Judge.Initialize(this); Rest.Initialize(this); AddToStateList(sleep, work, home, Interrupted, Judge, Rest); currentState = sleep; base.Start(); }