public void PerformTransition(ZombieTransition trans) { // Check for None Transition before changing the current state if (trans == ZombieTransition.None) { Debug.LogError("ZombieFSM Error: None Transition is not allowed for a real transition"); return; } // Check if the currentState has the transition passed as argument ZombieFSMStateID id = currentState.GetOutputState(trans); if (id == ZombieFSMStateID.None) { Debug.LogError("ZombieFSM Error: State " + currentStateID.ToString() + " doesn't have a target state for transition " + trans.ToString()); return; } // Update the currentState and currentStateID currentStateID = id; foreach (ZombieFSMState state in states) { if (state.ID == currentStateID) { // Do the post processing of the state before setting the new one currentState = state; // Reset the state to its desirec condition before it can reason or act break; } } }
public ZombieFSMStateID GetOutputState(ZombieTransition trans) { // Check if the map has this transition if (map.ContainsKey(trans)) { return(map[trans]); } return(ZombieFSMStateID.None); }
public ZombieTransition newTransition(Spawner s, bool addToList = true) { ZombieTransition trans = new ZombieTransition(s, currentLevel); if (addToList) { addTransition(trans); } return(trans); }
public void addMastarPhase() { ZombieTransition trans = new ZombieTransition(defaultSpawner, 3); trans.spawnComposition = constComposition((new List <ZombieType>()).addType(DeathZombie, 5).addType(DerangedZombie, 1)); trans.initialZombieCount = constInt(5); trans.initialTime = 20; trans.finalZombieCount = constInt(15); trans.finalTime = 30; trans.spawnRate = constInt(100); trans.minSpawnDistance = constInt(0); trans.maxSpawnDistance = constInt(30); trans.started = delegate(Script_ZombieZone.TeamState state) { state.wipeOut(); state.team.sendArenaMessage("mastar hasn't coded this far. Have a good next game."); state.zombieMessage("It is Time for those who DIE and DIE AGAIN - DIE ONCE MORE."); }; trans.final = delegate(Script_ZombieZone.TeamState state) { state.wipeOut(); state.team.sendArenaMessage("You've beaten the game somehow. Time to die/spec."); state.zombieMessage("The infection contained within all of us now emerges. They were doomed to failure from the start."); }; trans.ended = delegate(Script_ZombieZone.TeamState state) { foreach (Player player in state.team.ActivePlayers.ToList()) { player.inventoryModify(AssetManager.Manager.getItemByName("MinusHealth"), 500); } }; transitions.Add(trans); //specs them if the previous kill failed. 20 seconds after to clean up. trans = gracePeriod(2, false); trans.final = delegate(Script_ZombieZone.TeamState state) { foreach (Player player in state.team.ActivePlayers.ToList()) { if (!player.IsDead && !player.isZombie()) { player.spec("spec"); } } }; trans.finalTime = 20; transitions.Add(trans); }
//adds a grace period to the list public ZombieTransition gracePeriod(int seconds, bool addToList = true) { ZombieTransition grace = new ZombieTransition(emptySpawner(), currentLevel); grace.initialTime = seconds; if (addToList) { addTransition(grace); } return(grace); //returns it in case we want to add any messages to it }
public void DeleteTransition(ZombieTransition trans) { // Check for None Transition if (trans == ZombieTransition.None) { Debug.LogError("ZombieFSMState Error: None transition is not allowed"); return; } // Check if the pair is inside the map before deleting if (map.ContainsKey(trans)) { map.Remove(trans); return; } Debug.LogError("ZombieFSMState Error: Transition " + trans.ToString() + " passed to " + stateID.ToString() + "was not on the state's transition list"); }
// protected float curRotSpeed; // protected float curSpeed; // protected Vector3 desPos; public void AddTransition(ZombieTransition trans, ZombieFSMStateID id) { // Check if anyone of the args is invalid if (trans == ZombieTransition.None) { Debug.LogError("ZombieFSMState Error: None is not allowed for a real Transition"); return; } if (id == ZombieFSMStateID.None) { Debug.LogError("ZombieFSMState Error: None is not allowed for a real ID"); return; } // Since this is a Deterministic FSM, check fi the current transition was already inside the map if (map.ContainsKey(trans)) { Debug.LogError("ZombieFSMState Error: State " + stateID.ToString() + "already has transition" + trans.ToString() + " Impossible to assign to another state"); return; } map.Add(trans, id); }
public void SetTransition(ZombieTransition trans) { fsm.PerformTransition(trans); }
//adds transition to the back, prior to any class-defined final waves. public void addTransition(ZombieTransition newTransition) { transitions.Insert(transitions.Count - numFinalWaves, newTransition); }