public void Attacked() { if (State != EntState.Player) { State = EntState.Active; } }
public void DoAITurn(Map map, Entity player) { if (State == EntState.Player) return; SetEntityStateTex(); bool vision = map.HasVision(Position, player.Position); if (vision) { State = EntState.Active; Goal = player.Position; } if (State == EntState.Idle) AP = 0; if (State == EntState.Awake) // awake only switches to investigate on turn start State = EntState.Investigate; // so you can't double-trigger investigate if (State == EntState.Investigate) { WalkTowardsGoal(map); if (map.HasVision(Position, player.Position)) State = EntState.Active; } else if (State == EntState.Active) //investigate or active not both, can't walk twice { var dist = (int)Vector2.Distance(Position, player.Position); // if can't see player, move towards goal if (!vision) { WalkTowardsGoal(map); Debug.Log(Name + ":no vision:1"); } else { // close to mark range if (dist > Weapon.Mark && AP >= MOVE_AP_COST) { WalkTowardsGoal(map); Debug.Log(Name + ":walk:2"); } else { if (dist <= Weapon.Mark && AP >= Weapon.APCost) { Attack(player); Debug.Log(Name + ":attack:3"); } else { if (dist > 1 && AP >= MOVE_AP_COST) { WalkTowardsGoal(map); Debug.Log(Name + ":walk:4"); } else { AP = 0; Debug.Log(Name + ":no move:5"); } } } } if (AP < MOVE_AP_COST) AP = 0; } if (Position == Goal) // reached goal { // check vision again if (!map.HasVision(Position, player.Position)) State = EntState.Idle; } SetEntityStateTex(); }
public void DoAITurn(Map map, Entity player) { if (State == EntState.Player) { return; } SetEntityStateTex(); bool vision = map.HasVision(Position, player.Position); if (vision) { State = EntState.Active; Goal = player.Position; } if (State == EntState.Idle) { AP = 0; } if (State == EntState.Awake) // awake only switches to investigate on turn start { State = EntState.Investigate; // so you can't double-trigger investigate } if (State == EntState.Investigate) { WalkTowardsGoal(map); if (map.HasVision(Position, player.Position)) { State = EntState.Active; } } else if (State == EntState.Active) //investigate or active not both, can't walk twice { var dist = (int)Vector2.Distance(Position, player.Position); // if can't see player, move towards goal if (!vision) { WalkTowardsGoal(map); Debug.Log(Name + ":no vision:1"); } else { // close to mark range if (dist > Weapon.Mark && AP >= MOVE_AP_COST) { WalkTowardsGoal(map); Debug.Log(Name + ":walk:2"); } else { if (dist <= Weapon.Mark && AP >= Weapon.APCost) { Attack(player); Debug.Log(Name + ":attack:3"); } else { if (dist > 1 && AP >= MOVE_AP_COST) { WalkTowardsGoal(map); Debug.Log(Name + ":walk:4"); } else { AP = 0; Debug.Log(Name + ":no move:5"); } } } } if (AP < MOVE_AP_COST) { AP = 0; } } if (Position == Goal) // reached goal { // check vision again if (!map.HasVision(Position, player.Position)) { State = EntState.Idle; } } SetEntityStateTex(); }
public void Attacked() { if (State != EntState.Player) State = EntState.Active; }