public CollectorCollectingSuperState(NPCStateMachine stateMachine) : base(stateMachine) { // Add state on to stack this.stateMachine.PushStateOnStack(this); this.guardsInSight = new List<NPCDriver>(); }
protected override void Init() { canTransitionInto = new StateMachine.States[] { StateMachine.States.Idle, StateMachine.States.Incapacitated, StateMachine.States.FightOrFlight, StateMachine.States.Dead }; npc = (NPCStateMachine)stateMachine; }
public override void OnPoolInstantiation() { // Stats MoveSpeed = 100.0f; DrawColor = Color.White; Animator = new Animator(); EnemyAnimations = EnemyDirector.Instance.BaldAnimations; // Position = new Vector2(0); stateMachine = new NPCStateMachine(this); // Create the states IdleState idle = new IdleState("idle"); FleeState flee = new FleeState("flee"); ChaseState chase = new ChaseState("chase"); PowerupState powerup = new PowerupState("powerup", 5.0f); ChargeState charge = new ChargeState("charge", 10.0f); // Transitions // From Ideal // From Chase chase.AddTransition(new Transition(powerup, () => (EnemyDirector.Instance.SqrDistanceToHeroFrom(Position)) <= Math.Pow(distanceToBeginPowerup, 2))); // From Powerup powerup.AddTransition(new Transition(charge, () => powerup.Done)); // From Charge charge.AddTransition(new Transition(chase, () => charge.Done)); // Dead Player - All states back to idle // ? // Add the created states to the FSM // stateMachine.AddState(idle); // stateMachine.AddState(flee); stateMachine.AddState(chase); stateMachine.AddState(powerup); stateMachine.AddState(charge); // Collider Related colliderSize = new Vector2Int(2, 2); BoundingRect = new Rectangle((int)Position.X, (int)Position.Y, colliderSize.X, colliderSize.Y); base.OnPoolInstantiation(); }
public static List<NPCDriver> FindGuardsInSight(NPCStateMachine npcStateMachine) { List<NPCDriver> result = new List<NPCDriver>(); foreach (NPCDriver guard in GameManager.Guards) { if (npcStateMachine.NPC.VisibleNPCs.Contains(guard)) { result.Add(guard); } } return result; }
// Places NPC Buttons into the game world void npcButtons() { foreach (GameObject npc in npcList) { GameObject npcNewButton = Instantiate(npcButton) as GameObject; NPC_ButtonSelect npcButtonSelect = npcNewButton.GetComponent <NPC_ButtonSelect>(); npcButtonSelect.NPC_Prefab = npc; NPCStateMachine currentNPC = npc.GetComponent <NPCStateMachine>(); Text buttonText = npcNewButton.transform.GetComponentInChildren <Text>(); buttonText.text = currentNPC.NPC.name; npcNewButton.transform.SetParent(Spacer, false); } }
public static List<NPCDriver> FindGuardsInFleeRange(NPCStateMachine npcStateMachine) { List<NPCDriver> result = new List<NPCDriver>(); GameObject thisNPC = npcStateMachine.NPC.Instance; List<NPCDriver> guardsInSight = FindGuardsInSight(npcStateMachine); foreach (NPCDriver guard in guardsInSight) { if (NPCStateHelper.GetShortestPathDistance(thisNPC, guard.Instance) <= CollectorStateMachine.FLEE_RANGE) { result.Add(guard); } } return result; }
public override void OnPoolInstantiation() { // Stats MoveSpeed = 100.0f; DrawColor = Color.White; Animator = new Animator(); EnemyAnimations = EnemyDirector.Instance.DarkAnimations; // Position = new Vector2(0); stateMachine = new NPCStateMachine(this); // Create the states IdleState idle = new IdleState("idle"); ChaseState chase = new ChaseState("chase"); ShootState shoot = new ShootState("shoot", 200, 2, true, EnemyDirector.Instance.EnemyBulletTexture); // Transitions idle.AddTransition(new Transition(chase, () => (Math.Pow(distanceToBeginChase, 2) >= EnemyDirector.Instance.SqrDistanceToHeroFrom(Position)))); chase.AddTransition(new Transition(shoot, () => (Math.Pow(distanceToBeginShoot, 2) >= EnemyDirector.Instance.SqrDistanceToHeroFrom(Position)))); chase.AddTransition(new Transition(idle, () => (Math.Pow(distanceToBeginChase, 2) < EnemyDirector.Instance.SqrDistanceToHeroFrom(Position)))); shoot.AddTransition(new Transition(chase, () => (Math.Pow(distanceToBeginShoot, 2) < EnemyDirector.Instance.SqrDistanceToHeroFrom(Position)) && !shoot.InAttack)); // Dead Player - All states back to idle // ? // Add the created states to the FSM stateMachine.AddState(idle); stateMachine.AddState(chase); stateMachine.AddState(shoot); // Collider Related colliderSize = new Vector2Int(2, 2); BoundingRect = new Rectangle((int)Position.X, (int)Position.Y, colliderSize.X, colliderSize.Y); base.OnPoolInstantiation(); }
public static bool SoulsInCollectibleRange(NPCStateMachine npcStateMachine) { GameObject thisNPC = npcStateMachine.NPC.Instance; float collectibleRange = CollectorStateMachine.SOUL_COLLECTIBLE_RANGE_FOR_STATE_TRIGGER; List<GameObject> soulsInSight = FindVisibleSouls(npcStateMachine.NPC); Vector3 npcGroundLevelPos = thisNPC.transform.position; npcGroundLevelPos.y = 0.0f; foreach (GameObject soul in soulsInSight) { Vector3 soulGroundLevelPos = soul.transform.position; soulGroundLevelPos.y = 0.0f; if (Vector3.Distance(npcGroundLevelPos, soulGroundLevelPos) <= collectibleRange) { return true; } } return false; }
public override void OnPoolInstantiation() { // Stats MoveSpeed = 100.0f; DrawColor = Color.White; Animator = new Animator(); EnemyAnimations = EnemyDirector.Instance.DogeAnimations; // Position = new Vector2(0); stateMachine = new NPCStateMachine(this); // Create the states IdleState idle = new IdleState("idle"); ChaseState chase = new ChaseState("chase"); ShortRangeAttackState shortRangeAttack = new ShortRangeAttackState("shortRangeAttack", 2.0f, 1.5f, true); // Create the transitions between the states idle.AddTransition(new Transition(chase, () => (Math.Pow(distanceToBeginChase, 2) >= EnemyDirector.Instance.SqrDistanceToHeroFrom(Position)))); chase.AddTransition(new Transition(shortRangeAttack, () => (Math.Pow(distanceToBeginAttack, 2) >= EnemyDirector.Instance.SqrDistanceToHeroFrom(Position)))); chase.AddTransition(new Transition(idle, () => (Math.Pow(distanceToBeginChase, 2) < EnemyDirector.Instance.SqrDistanceToHeroFrom(Position)))); shortRangeAttack.AddTransition(new Transition(chase, () => (Math.Pow(distanceToBeginAttack, 2) < EnemyDirector.Instance.SqrDistanceToHeroFrom(Position)) && !shortRangeAttack.InAttack)); // Add the created states to the FSM stateMachine.AddState(idle); stateMachine.AddState(chase); stateMachine.AddState(shortRangeAttack); //// Set the starting state of the FSM //stateMachine.Initialise("idle"); // Collider Related colliderSize = new Vector2Int(2, 2); BoundingRect = new Rectangle((int)Position.X, (int)Position.Y, colliderSize.X, colliderSize.Y); base.OnPoolInstantiation(); }
public static bool GuardsInFleeRange(NPCStateMachine npcStateMachine, CollectorStateMachine.FleeRangeType range) // Range should be "default" for default flee range or "emergency" for emergency flee range { GameObject thisNPC = npcStateMachine.NPC.Instance; float fleeRange = CollectorStateMachine.FLEE_RANGE; // Default flee range List<NPCDriver> guardsInSight = FindGuardsInSight(npcStateMachine); // Get emergency range based on inputted string if (range == CollectorStateMachine.FleeRangeType.Emergency) { fleeRange = CollectorStateMachine.EMERGENCY_FLEE_RANGE; } foreach (NPCDriver guard in guardsInSight) { if (NPCStateHelper.GetShortestPathDistance(thisNPC, guard.Instance) <= fleeRange) { return true; } } return false; }
public CollectorAnswerHelpCallState(NPCStateMachine stateMachine, SoulTree targetTree, CollectorStateMachine callerStateMachine) : base(stateMachine) { this.targetTree = targetTree; this.callerStateMachine = callerStateMachine; }
public static Node FindNodeForRememberedTreePosition(NPCStateMachine npcStateMachine) { GameObject treePosition = null; foreach (GameObject tree in npcStateMachine.TreesFound) { if (tree == npcStateMachine.StrategicSoulTreeTarget) continue; treePosition = tree; } npcStateMachine.StrategicSoulTreeTarget = treePosition; if (treePosition == null) return GameManager.AllNodes[UnityEngine.Random.Range(0, GameManager.AllNodes.Count - 1)]; return NPCStateHelper.FindClosestNode(treePosition.GetComponent<SoulTree>().TreeButtons[0]); }
public GuardStrategicPositionState(NPCStateMachine stateMachine) : base(stateMachine) { }
public CollectorImmortalState(NPCStateMachine stateMachine) : base(stateMachine) { }
public CollectorCallForHelpState(NPCStateMachine stateMachine, SoulTree targetTree) : base(stateMachine) { this.targetTree = targetTree; }
// Every frame... void Update() { // switch_one: a battle state handler switch (currentHandlerState) { case (BattleHandlerState.WAIT): if (performList.Count > 0) { currentHandlerState = BattleHandlerState.TAKEACTION; } break; case (BattleHandlerState.TAKEACTION): GameObject performer = GameObject.Find(performList[0].activistName); if (performList[0].characterType == "NPC") { NPCStateMachine npcSM = performer.GetComponent <NPCStateMachine>(); npcSM.playerToInteract = performList[0].activistFocus; npcSM.currentState = NPCStateMachine.TurnState.ACTION; } if (performList[0].characterType == "Player") { //Add functionality //PlayerCharacterStateMachine pcSM = performer.GetComponent<PlayerCharacterStateMachine>(); //pcSM.npcToInteract = performList[0].activistFocus; //pcSM.currentState = PlayerCharacterStateMachine.TurnState.ACTION; playersToManage.Add(performer); } currentHandlerState = BattleHandlerState.PERFORMACTION; break; case (BattleHandlerState.PERFORMACTION): break; } // switch_two: a player choice handler switch (currentPlayerState) { case (playerChoiceState.ACTIVATE): // Debug.Log("For example..."); if (playersToManage.Count > 0) { playersToManage[0].transform.Find("Selector").gameObject.SetActive(true); // playerSelectedChoice = new TurnHandler(); actionPanel.SetActive(true); currentPlayerState = playerChoiceState.WAIT; } break; case (playerChoiceState.WAIT): break; case (playerChoiceState.DONE): Debug.Log("Taking action!"); PlayerCharacterStateMachine pcSM = playersToManage[0].GetComponent <PlayerCharacterStateMachine>(); pcSM.npcToInteract = performList[0].activistFocus; pcSM.currentState = PlayerCharacterStateMachine.TurnState.ACTION; PlayerInputDone(); break; } }
public CollectorFindMultipleTreeState(NPCStateMachine stateMachine) : base(stateMachine) { }
public CollectorFleeState(NPCStateMachine stateMachine) : base(stateMachine) { }
public CollectorFindSingleTreeState(NPCStateMachine stateMachine) : base(stateMachine) { }
private float dropAllSoulsTimer = 3f; // After this amount of time in the state, all souls should be dropped for max speed public CollectorEmergencyFleeState(NPCStateMachine stateMachine) : base(stateMachine) { }
public CollectorSearchSoulsState(NPCStateMachine stateMachine) : base(stateMachine) { }
public GuardSearchState(NPCStateMachine stateMachine) : base(stateMachine) { }
public GuardFlankPursueState(NPCStateMachine stateMachine) : base(stateMachine) { }
public GuardLungeState(NPCStateMachine stateMachine) : base(stateMachine) { }
public GuardDirectPursueState(NPCStateMachine stateMachine) : base(stateMachine) { }
public NPCState(NPCStateMachine stateMachine) { this.stateMachine = stateMachine; }