/// <summary> /// Initializes a new instance of the <see cref="AIComponent"/> class. /// </summary> /// <param name="parent">Entity to wich the component belongs.</param> /// <param name="type">Definition of how to treat the entity based on <see cref="AiType"/>.</param> public AIComponent(IEntity parent, AiType type) { Parent = parent; parent?.AddComponent(this); TowerToDefend = -1; Type = type; }
private static void SingleGame() { Random rnd = new Random(Environment.TickCount); var game = Game.Create(AiType.Create <SimplePlusAI>(), AiType.Create <CooroperateAI>(), GameMode.HiddenInfo2ShipLarge, rnd); for (int i = 0; i < 100000; i++) { Console.Clear(); game.Render(); game.NextTurn(); Console.ReadKey(); if (game.GameResult != GameResult.GameNotEnded) { break; } } Console.WriteLine("Game result:{0}", game.GameResult); Console.WriteLine("Press N to continue"); while (true) { ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.N) { break; } } }
//設定AI public void SetAI(AiType type) { aiType = type; switch (type) { case AiType.智障: aiScript = new AI_Level0(); break; case AiType.簡單: aiScript = new AI_Level1(); break; case AiType.普通: aiScript = new AI_Level2((chessType == ChessType.黑子 ? 1 : 2)); break; case AiType.高手: aiScript = new AI_Level3((chessType == ChessType.黑子 ? 1 : 2)); break; case AiType.夭壽強: aiScript = new AI_Level4((chessType == ChessType.黑子 ? 1 : 2)); break; default: break; } }
/// <summary> /// Initializes a new instance of the <see cref="RoomBot" /> class. /// </summary> /// <param name="botId">The bot identifier.</param> /// <param name="ownerId">The owner identifier.</param> /// <param name="roomId">The room identifier.</param> /// <param name="aiType">Type of the ai.</param> /// <param name="walkingMode">The walking mode.</param> /// <param name="name">The name.</param> /// <param name="motto">The motto.</param> /// <param name="look">The look.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="z">The z.</param> /// <param name="rot">The rot.</param> /// <param name="speeches">The speeches.</param> /// <param name="responses">The responses.</param> /// <param name="gender">The gender.</param> /// <param name="dance">The dance.</param> /// <param name="botType"></param> internal RoomBot(uint botId, uint ownerId, uint roomId, AiType aiType, string walkingMode, string name, string motto, string look, int x, int y, double z, int rot, List <string> speeches, List <string> responses, string gender, uint dance, string botType) { OwnerId = ownerId; BotId = botId; RoomId = roomId; AiType = aiType; WalkingMode = walkingMode; Name = name; Motto = motto; Look = look; X = x; Y = y; Z = z; Rot = rot; Gender = gender.ToUpper(); VirtualId = -1; RoomUser = null; BotType = botType; DanceId = dance; RandomSpeech = speeches; Responses = responses; LastSpokenPhrase = 1; WasPicked = roomId == 0; }
public static ComponentAiSystem.AiState CreateBaseAiState(AiType aiType, float movementSpeed) { switch (aiType) { case AiType.AT_TestBot_1: return(new AiStateMoveBetweenPoints(new List <Vector2>() { new Vector2(-600, -100), new Vector2(600, -100) }, movementSpeed)); case AiType.AT_RaceBot_1: return(new AiStateTimedMoveBetweenPoints(new List <Vector2>() { new Vector2(-600, -200), new Vector2(600, -200) }, movementSpeed, 5)); case AiType.AT_RaceBot_2: return(new AiStateTimedMoveBetweenPoints(new List <Vector2>() { new Vector2(-600, -300), new Vector2(600, -300) }, movementSpeed, 5)); case AiType.AT_TestBot_Circle: return(new AiStateWalkInCircle(new Vector2(100, 300), 200, movementSpeed)); case AiType.AT_RandomBot: return(new AiStateMoveBetweenRandomPoints(new Vector2(-600, 100), new Vector2(-200, 500), movementSpeed)); default: return(null); } }
public Particle(Vector2 setPosition, Vector2 setVelocity, AiType setAiType, int setTimeLeft, Color setColor) { position = setPosition; velocity = setVelocity; ai = setAiType; timeLeft = setTimeLeft; maxTimeLeft = setTimeLeft; color = setColor; }
/// <summary> /// Initializes a new instance of the <see cref="RoomBot" /> class. /// </summary> /// <param name="botId">The bot identifier.</param> /// <param name="ownerId">The owner identifier.</param> /// <param name="aiType">Type of the ai.</param> /// <param name="botType"></param> internal RoomBot(uint botId, uint ownerId, AiType aiType, string botType) { OwnerId = ownerId; BotId = botId; AiType = aiType; VirtualId = -1; BotType = botType; RoomUser = null; LastSpokenPhrase = 1; }
//(按鈕事件)改變後手AI類型 public void Btn_ChangeGoteAiType(bool upOrDown) { int index = (int)whiteAi; int nextIndex = upOrDown ? ((index + 1) % (aiTypeList.Count)) : (index - 1 < 0 ? aiTypeList.Count - 1 : index - 1); tx_whiteAiType.text = aiTypeList[index]; tx_whiteAiType_hide.text = aiTypeList[nextIndex]; whiteAi = (AiType)nextIndex; animScript_changeWhiteAi.PlayAnimation(upOrDown ? "SelectionSwitchOver_TurnUp" : "SelectionSwitchOver_TurnDown", new AnimationBehavior(PlayMode.狀態延續), false); }
public Game(AiType blue, AiType red, GameMode gameMode, Random rnd) { BlueAiType = blue; RedAiType = red; this.gameMode = gameMode; List <IUnit> units = AddUnits(this.gameMode, rnd); Tuple <int, int> size = GetGameSize(this.gameMode); Map = new Map(size.Item1, size.Item2, rnd, units); }
/// <summary> /// Generates the bot ai. /// </summary> /// <param name="virtualId">The virtual identifier.</param> /// <param name="botId">The bot identifier.</param> /// <returns>BotAI.</returns> internal BotAi GenerateBotAi(int virtualId, int botId) { AiType aiType = AiType; if (aiType == AiType.Pet) { return(new PetBot(virtualId)); } return(new GenericBot(this, virtualId, SpeechInterval)); }
private static List <Player> GetNewPlayers(int numberOfPlayers, Random rnd) { List <Player> leaguePlayers = new List <Player>(); for (int i = 0; i < numberOfPlayers; i++) { leaguePlayers.Add( new Player( AiType.Create <NewMutableAI>(NewMutableParameters.RandomGens(rnd)))); } return(leaguePlayers); }
public Particle(Vector2 setPosition, Vector2 setVelocity, AiType setAiType, Color setColor) { position = setPosition; velocity = setVelocity; ai = setAiType; color = setColor; if (ai == AiType.BASIC) { timeLeft = 200; maxTimeLeft = 200; } }
private bool IsTower(int index) { AiType type = entities[index].GetComponent <AIComponent>().Type; switch (type) { case AiType.Tower: case AiType.Fortress: return(true); default: return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="GenericBot" /> class. /// </summary> /// <param name="roomBot">The room bot.</param> /// <param name="virtualId">The virtual identifier.</param> /// <param name="botId">The bot identifier.</param> /// <param name="type">The type.</param> /// <param name="isBartender">if set to <c>true</c> [is bartender].</param> /// <param name="speechInterval">The speech interval.</param> internal GenericBot(RoomBot roomBot, int virtualId, int botId, AiType type, bool isBartender, int speechInterval) { _id = botId; _virtualId = virtualId; _isBartender = isBartender; _speechInterval = speechInterval < 2 ? 2000 : speechInterval*1000; // Get random speach // @issue #80 //if (roomBot != null && roomBot.RandomSpeech != null && roomBot.RandomSpeech.Any()) _chatTimer = new Timer(ChatTimerTick, null, _speechInterval, _speechInterval); if (roomBot != null && roomBot.AutomaticChat && roomBot.RandomSpeech != null && roomBot.RandomSpeech.Any()) _chatTimer = new Timer(ChatTimerTick, null, _speechInterval, _speechInterval); _actionCount = Random.Next(10, 30 + virtualId); }
private bool IsArmy(int index) { AiType type = entities[index].GetComponent <AIComponent>().Type; switch (type) { case AiType.Army: case AiType.FastArmy: case AiType.RangedArmy: return(true); default: return(false); } }
private void PickAiType() { var rand = Random.value; if (rand < 0.2) { character = Catalogue.Character.A; } else if (rand < 0.4) { character = Catalogue.Character.H; } else if (rand < 0.6) { character = Catalogue.Character.D; } else if (rand < 0.8) { character = Catalogue.Character.M; } else if (rand < 1.0) { character = Catalogue.Character.O; } var values = Enum.GetValues(typeof(AiType)); _aiType = (AiType)values.GetValue(Random.Range(0, values.Length)); _wanderDirection = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized; }
public bool Matches(ushort buildingId) { Building building = BuildingManager.m_buildings.m_buffer[buildingId]; var info = building.Info; if (info == null) { return(false); } if (AiType != null && !AiType.IsInstanceOfType(info.GetAI())) { return(false); } return(Service.Equals(info.GetService()) && (AnySubService || SubService.Equals(info.GetSubService()))); }
void Start() { rider = this.transform.GetChild(0).gameObject; //find a group point GameObject[] g = GameObject.FindGameObjectsWithTag("Group"); float dist = float.MaxValue; foreach (GameObject G in g) { if (dist > Vector2.Distance(G.transform.position, transform.position)) { dist = Vector2.Distance(G.transform.position, transform.position); CurrentIdlePos = G.transform.position; } } GotoPos = FindNextPoint(CurrentIdlePos); //find the player player = GameObject.FindGameObjectWithTag("Player"); //if there isnt a player then still move if (player == null) { playerFound = false; } else { playerFound = true; } //random AI switch (Random.Range((int)0, (int)3)) { case 0: Ai = AiType.Circle; break; case 1: Ai = AiType.Follow; break; case 2: Ai = AiType.Intercept; break; } }
private List <Player> GetLeaguePlayers() { Random rnd = new Random((int)DateTime.Now.Ticks); List <Player> leaguePlayers = new List <Player> { new Player(AiType.Create <SimpleMutableAI>()), new Player(AiType.Create <ScanNFirePlusAI>()), new Player(AiType.Create <NewMutableAI>()), new Player(AiType.Create <DoNothingAI>()), new Player(AiType.Create <RandomAI>()), new Player(AiType.Create <RunAwayAI>()), new Player(AiType.Create <CryBabyAI>()), new Player(AiType.Create <FireAllTheTimeAI>()), new Player(AiType.Create <ScanNFireAI>()), new Player(AiType.Create <CooroperateAI>()), new Player(AiType.Create <SimplePlusAI>()), }; return(leaguePlayers); }
void Start() { rider = this.transform.GetChild(0).gameObject; //find a group point CurrentIdlePos = GameObject.FindGameObjectWithTag("Group").transform.position; //find the player player = GameObject.FindGameObjectWithTag("Player"); //if there isnt a player then still move if (player == null) { playerFound = false; } else { playerFound = true; } Ai = AiType.Circle;; DeathHealthImage = GameObject.Find("DeathHealthBar"); DeathHealthImage.SetActive(true); HealthBackgroundImage = GameObject.Find("BossHealthBarBackground"); HealthBackgroundImage.SetActive(true); }
void Start() { rider = this.transform.GetChild(0).gameObject; //find a group point CurrentIdlePos = GameObject.FindGameObjectWithTag("Group").transform.position; GotoPos = FindNextPoint(CurrentIdlePos); //find the player player = GameObject.FindGameObjectWithTag("Player"); //if there isnt a player then still move if (player == null) { playerFound = false; } else { playerFound = true; } //random AI switch (Random.Range((int)0, (int)3)) { case 0: Ai = AiType.Circle; break; case 1: Ai = AiType.Follow; break; case 2: Ai = AiType.Intercept; break; } prevtype = Ai; ConquestHealthImage = GameObject.Find("ConquestHealthBar"); ConquestHealthImage.SetActive(true); HealthBackgroundImage = GameObject.Find("BossHealthBarBackground"); HealthBackgroundImage.SetActive(true); }
void Start() { rider = this.transform.GetChild(0).gameObject; //find a group point CurrentIdlePos = GameObject.FindGameObjectWithTag("Group").transform.position; GotoPos = FindNextPoint(CurrentIdlePos); //find the player player = GameObject.FindGameObjectWithTag("Player"); //if there isnt a player then still move if (player == null) { playerFound = false; } else { playerFound = true; } //random AI Ai = AiType.Intercept; FamineHealthImage = GameObject.Find("FamineHealthBar"); FamineHealthImage.SetActive(true); HealthBackgroundImage = GameObject.Find("BossHealthBarBackground"); HealthBackgroundImage.SetActive(true); }
void Start() { rider = this.transform.GetChild (0).gameObject; //find a group point CurrentIdlePos = GameObject.FindGameObjectWithTag ("Group").transform.position; GotoPos = FindNextPoint (CurrentIdlePos); //find the player player = GameObject.FindGameObjectWithTag("Player"); //if there isnt a player then still move if (player == null) { playerFound = false; } else { playerFound = true; } //random AI Ai = AiType.Intercept; FamineHealthImage = GameObject.Find("FamineHealthBar"); FamineHealthImage.SetActive (true); HealthBackgroundImage = GameObject.Find("BossHealthBarBackground"); HealthBackgroundImage.SetActive (true); }
// Update is called once per frame void Update() { //Debug.Log ("Health " + health); if (mounted) { damage = 5 * (1f - ((float)health / 30f) + 0.5f); } else { damage = 0; } //move forwards if (Vector2.Distance(this.transform.position, player.transform.position) < 15) { Alert = true; } else { Alert = false; Itime = 5; rotateNow = false; attackTimer = 0; } if (health < 15) { Ai = AiType.Follow; } if (health > 0) { FamineHealthImage.GetComponent <Image> ().fillAmount = health / 30; if ((StateControl.State != StateControl.state.Pause)) { if (playerFound) { if (!Alert) { if (Vector2.Distance(transform.position, GotoPos) < 4) { GotoPos = FindNextPoint(CurrentIdlePos); } move(); } else { Vector2 DircetTowards; float angle; //if(!audio.isPlaying) //PlaySound(0); switch (Ai) { case AiType.Intercept: //player speed and our speed Vector2 pSpeed = player.rigidbody2D.velocity; Vector2 eSpeed = this.rigidbody2D.velocity; //player pos in x seconds GotoPos = (Vector2)player.transform.position - pSpeed.normalized + pSpeed * Itime; float dist = Vector2.Distance(GotoPos, this.transform.position); float TimeToIntercept = dist / eSpeed.magnitude; if (TimeToIntercept < Itime) { Itime -= 0.1f; } if (TimeToIntercept > Itime) { Itime += 0.1f; } if (AttackCool > 0) { AttackCool -= Time.deltaTime; } else { move(); } break; case AiType.Follow: //are we infront of the player? DircetTowards = this.transform.position - player.transform.position; angle = Vector2.Angle(player.transform.up, DircetTowards); if (angle > 90) { this.rigidbody2D.velocity = new Vector2(0, 0); //behind GotoPos = player.transform.position - player.transform.up * 3; } else { //infront //create points at either side of and behind the player Vector2 left = player.transform.position - (player.transform.right * 3) - player.transform.up; Vector2 right = player.transform.position + (player.transform.right * 3) - player.transform.up; if (Vector2.Distance(this.transform.position, left) > Vector2.Distance(this.transform.position, right)) { //on the right GotoPos = right; } else { //on the left GotoPos = left; } } move(); break; } } } } } else { FamineHealthImage.SetActive(false); HealthBackgroundImage.SetActive(false); if (destroyed == false) { destroyed = true; StartCoroutine(destroyFamine()); } //tell player death is dead GameObject[] forts = GameObject.FindGameObjectsWithTag("Fort"); GameObject fort = forts[0]; float dist = float.MaxValue; foreach (GameObject g in forts) { if (dist > Vector2.Distance(transform.position, g.transform.position)) { fort = g; dist = Vector2.Distance(transform.position, g.transform.position); } } fort.SendMessage("BossDefeated"); GUIScript.FamineKilled = true; } }
/// <summary> /// Initializes a new instance of the <see cref="RoomBot" /> class. /// </summary> /// <param name="botId">The bot identifier.</param> /// <param name="ownerId">The owner identifier.</param> /// <param name="roomId">The room identifier.</param> /// <param name="aiType">Type of the ai.</param> /// <param name="walkingMode">The walking mode.</param> /// <param name="name">The name.</param> /// <param name="motto">The motto.</param> /// <param name="look">The look.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="z">The z.</param> /// <param name="rot">The rot.</param> /// <param name="speeches">The speeches.</param> /// <param name="responses">The responses.</param> /// <param name="gender">The gender.</param> /// <param name="dance">The dance.</param> /// <param name="botType"></param> internal RoomBot(uint botId, uint ownerId, uint roomId, AiType aiType, string walkingMode, string name, string motto, string look, int x, int y, double z, int rot, List<string> speeches, List<string> responses, string gender, uint dance, string botType) { OwnerId = ownerId; BotId = botId; RoomId = roomId; AiType = aiType; WalkingMode = walkingMode; Name = name; Motto = motto; Look = look; X = x; Y = y; Z = z; Rot = rot; Gender = gender.ToUpper(); VirtualId = -1; RoomUser = null; BotType = botType; DanceId = dance; RandomSpeech = speeches; Responses = responses; LastSpokenPhrase = 1; WasPicked = roomId == 0; }
void Start() { rider = this.transform.GetChild (0).gameObject; //find a group point CurrentIdlePos = GameObject.FindGameObjectWithTag ("Group").transform.position; GotoPos = FindNextPoint (CurrentIdlePos); //find the player player = GameObject.FindGameObjectWithTag("Player"); //if there isnt a player then still move if (player == null) { playerFound = false; } else { playerFound = true; } //random AI switch (Random.Range ((int)0, (int)3)) { case 0: Ai = AiType.Circle; break; case 1: Ai = AiType.Follow; break; case 2: Ai = AiType.Intercept; break; } prevtype = Ai; ConquestHealthImage = GameObject.Find("ConquestHealthBar"); ConquestHealthImage.SetActive (true); HealthBackgroundImage = GameObject.Find("BossHealthBarBackground"); HealthBackgroundImage.SetActive (true); }
static void ReadPlayerData2(PrimitiveReader reader) { //System.Diagnostics.Debugger.Break(); string[] aiStrategies = new string[playersCount]; for (int i = 0; i < aiStrategies.Length; i++) { aiStrategies[i] = ReadUInt16LengthPrefixedString(reader); } string[] aiCityPlans = new string[playersCount]; for (int i = 0; i < aiCityPlans.Length; i++) { aiCityPlans[i] = ReadUInt16LengthPrefixedString(reader); } string[] aiNames = new string[playersCount]; for (int i = 0; i < aiNames.Length; i++) { aiNames[i] = ReadUInt16LengthPrefixedString(reader); } //System.Diagnostics.Debugger.Break(); AiFile[] aiFiles = new AiFile[playersCount]; for (int i = 0; i < aiFiles.Length; i++) { aiFiles[i].ReadData(reader, vv1, vv2); } if (minorVersion >= 18) { AiType[] aiTypes = new AiType[playersCount]; for (int i = 0; i < aiTypes.Length; i++) { aiTypes[i] = (AiType)reader.ReadUInt8(); } } #if DEBUG_ALPHA int count = 0; while (reader.ReadUInt8() != 0x9d) { count++; } reader.Stream.Seek(-1, SeekOrigin.Current); #endif uint separator = reader.ReadUInt32(); if (separator != 0xFFFFFF9D) { throw new InvalidDataException(); } PlayerResources[] resources = new PlayerResources[playersCount]; for (int i = 0; i < resources.Length; i++) { PlayerResources resource = new PlayerResources(); resource.GoldCount = reader.ReadUInt32(); resource.WoodCount = reader.ReadUInt32(); resource.FoodCount = reader.ReadUInt32(); resource.StoneCount = reader.ReadUInt32(); if (minorVersion2 >= 17) { resource.OreXCount = reader.ReadUInt32(); resource.OreYCount = reader.ReadUInt32(); } resources[i] = resource; } }
// Update is called once per frame void Update() { Debug.Log("conquest " + health); Debug.Log("player " + Player.PlayerHealth); swapTimer -= Time.deltaTime; if (swapTimer < 0) { while (Ai == prevtype) { switch (Random.Range((int)0, (int)3)) { case 0: Ai = AiType.Circle; break; case 1: Ai = AiType.Follow; break; case 2: Ai = AiType.Intercept; break; } } prevtype = Ai; swapTimer = 20; } if (mounted) { damage = 5; } else { damage = 0; } //move forwards if (Vector2.Distance(this.transform.position, player.transform.position) < 15) { Alert = true; } else { Alert = false; Itime = 5; rotateNow = false; attackTimer = 0; } if (playerFound) { if (!Alert) { if (Vector2.Distance(transform.position, GotoPos) < 4) { GotoPos = FindNextPoint(CurrentIdlePos); } move(); } else { Vector2 DircetTowards; float angle; switch (Ai) { case AiType.Intercept: //player speed and our speed Vector2 pSpeed = player.rigidbody2D.velocity; Vector2 eSpeed = this.rigidbody2D.velocity; //player pos in x seconds GotoPos = (Vector2)player.transform.position + pSpeed * Itime; float dist = Vector2.Distance(GotoPos, this.transform.position); float TimeToIntercept = dist / eSpeed.magnitude; if (TimeToIntercept < Itime) { Itime -= 0.1f; } if (TimeToIntercept > Itime) { Itime += 0.1f; } if (AttackCool > 0) { AttackCool -= Time.deltaTime; } else { move(); } break; case AiType.Follow: //are we infront of the player? DircetTowards = this.transform.position - player.transform.position; angle = Vector2.Angle(player.transform.up, DircetTowards); if (angle > 90) { this.rigidbody2D.velocity = new Vector2(0, 0); //behind GotoPos = player.transform.position - player.transform.up * 2; } else { //infront //create points at either side of and behind the player Vector2 left = player.transform.position - (player.transform.right * 3) - player.transform.up; Vector2 right = player.transform.position + (player.transform.right * 3) - player.transform.up; if (Vector2.Distance(this.transform.position, left) > Vector2.Distance(this.transform.position, right)) { //on the right GotoPos = right; } else { //on the left GotoPos = left; } } move(); //move around the player //attack in the rear break; case AiType.Circle: //are we infront of the player? DircetTowards = this.transform.position - player.transform.position; angle = Vector2.Angle(player.transform.up, DircetTowards); if (!rotateNow) { attacking = false; if (angle > 90) { Vector2 left = player.transform.position - (player.transform.right * 3); Vector2 right = player.transform.position + (player.transform.right * 3); if (Vector2.Distance(this.transform.position, left) > Vector2.Distance(this.transform.position, right)) { //on the right clockWise = false; GotoPos = right; if (Vector2.Distance(this.transform.position, right) < 4) { rotateNow = true; RotAngle = Mathf.Acos((right.x - player.transform.position.x) / 3); } } else { //on the left clockWise = true; GotoPos = left; if (Vector2.Distance(this.transform.position, left) < 4) { rotateNow = true; RotAngle = Mathf.Acos((left.x - player.transform.position.x) / 3); } } } else { //infront //create points at either side of and behind the player Vector2 left = player.transform.position - (player.transform.right * 3); Vector2 right = player.transform.position + (player.transform.right * 3); if (Vector2.Distance(this.transform.position, left) > Vector2.Distance(this.transform.position, right)) { //on the right clockWise = true; GotoPos = right; if (Vector2.Distance(this.transform.position, right) < 4) { rotateNow = true; RotAngle = Mathf.Acos((right.x - player.transform.position.x) / 3); } } else { //on the left clockWise = false; GotoPos = left; if (Vector2.Distance(this.transform.position, left) < 4) { rotateNow = true; RotAngle = Mathf.Acos((left.x - player.transform.position.x) / 3); } } } move(); } else { if (attackTimer <= 0) { attackTimer = Random.Range(10, 15); GotoPos = player.transform.position; Debug.Log("Attack!"); attacking = true; } if (!attacking) { GotoPos.x = player.transform.position.x + 7 * Mathf.Cos(RotAngle); GotoPos.y = player.transform.position.y + 7 * Mathf.Sin(RotAngle); if (Vector2.Distance(this.transform.position, GotoPos) < 2) { if (clockWise) { RotAngle += 20; } else { RotAngle -= 20; } } attackTimer -= Time.deltaTime; } else { GotoPos = player.transform.position; } move(); } break; } } } }
public AiParameters(AiParameters other) { aiType = other.aiType; attacks = new List <SkillID>(other.attacks); }
private static Player GetMutantet(String[] args, Random rnd) { return(new Player( AiType.Create <NewMutableAI>(NewMutableParameters.Mutate(args, rnd)))); }
public Player(AiType aiType) { AiType = aiType; Id = Guid.NewGuid(); }
void Start() { rider = this.transform.GetChild (0).gameObject; //find a group point CurrentIdlePos = GameObject.FindGameObjectWithTag ("Group").transform.position; //find the player player = GameObject.FindGameObjectWithTag("Player"); //if there isnt a player then still move if (player == null) { playerFound = false; } else { playerFound = true; } Ai = AiType.Circle;; DeathHealthImage = GameObject.Find("DeathHealthBar"); DeathHealthImage.SetActive (true); HealthBackgroundImage = GameObject.Find("BossHealthBarBackground"); HealthBackgroundImage.SetActive (true); }
// Update is called once per frame void Update() { Debug.Log ("conquest " + health); Debug.Log ("player " + Player.PlayerHealth); swapTimer -= Time.deltaTime; if (swapTimer < 0) { while(Ai == prevtype) { switch (Random.Range ((int)0, (int)3)) { case 0: Ai = AiType.Circle; break; case 1: Ai = AiType.Follow; break; case 2: Ai = AiType.Intercept; break; } } prevtype = Ai; swapTimer = 20; } if (mounted) { damage = 5; } else { damage = 0; } //move forwards if (Vector2.Distance (this.transform.position, player.transform.position) < 15) { Alert = true; } else { Alert = false; Itime = 5; rotateNow = false; attackTimer = 0; } if(playerFound) { if (!Alert) { if (Vector2.Distance (transform.position, GotoPos) < 4) { GotoPos = FindNextPoint (CurrentIdlePos); } move (); } else { Vector2 DircetTowards; float angle; switch(Ai) { case AiType.Intercept: //player speed and our speed Vector2 pSpeed = player.rigidbody2D.velocity; Vector2 eSpeed = this.rigidbody2D.velocity; //player pos in x seconds GotoPos = (Vector2)player.transform.position + pSpeed*Itime; float dist = Vector2.Distance(GotoPos, this.transform.position); float TimeToIntercept = dist/eSpeed.magnitude; if(TimeToIntercept <Itime) { Itime -=0.1f; } if(TimeToIntercept >Itime) { Itime +=0.1f; } if(AttackCool> 0) { AttackCool -= Time.deltaTime; } else { move (); } break; case AiType.Follow: //are we infront of the player? DircetTowards = this.transform.position- player.transform.position; angle = Vector2.Angle(player.transform.up, DircetTowards ); if(angle > 90) { this.rigidbody2D.velocity = new Vector2(0,0); //behind GotoPos = player.transform.position - player.transform.up*2; } else { //infront //create points at either side of and behind the player Vector2 left = player.transform.position -(player.transform.right*3) - player.transform.up; Vector2 right = player.transform.position +(player.transform.right*3) - player.transform.up; if(Vector2.Distance(this.transform.position,left)> Vector2.Distance(this.transform.position, right)) { //on the right GotoPos = right; } else { //on the left GotoPos = left; } } move (); //move around the player //attack in the rear break; case AiType.Circle: //are we infront of the player? DircetTowards = this.transform.position- player.transform.position; angle = Vector2.Angle(player.transform.up, DircetTowards ); if(!rotateNow) { attacking = false; if(angle > 90) { Vector2 left = player.transform.position -(player.transform.right*3); Vector2 right = player.transform.position +(player.transform.right*3); if(Vector2.Distance(this.transform.position,left)> Vector2.Distance(this.transform.position, right)) { //on the right clockWise = false; GotoPos = right; if(Vector2.Distance(this.transform.position,right)<4) { rotateNow = true; RotAngle = Mathf.Acos((right.x-player.transform.position.x)/3); } } else { //on the left clockWise = true; GotoPos = left; if(Vector2.Distance(this.transform.position,left)<4) { rotateNow = true; RotAngle = Mathf.Acos((left.x-player.transform.position.x)/3); } } } else { //infront //create points at either side of and behind the player Vector2 left = player.transform.position -(player.transform.right*3); Vector2 right = player.transform.position +(player.transform.right*3); if(Vector2.Distance(this.transform.position,left)> Vector2.Distance(this.transform.position, right)) { //on the right clockWise = true; GotoPos = right; if(Vector2.Distance(this.transform.position,right)<4) { rotateNow = true; RotAngle = Mathf.Acos((right.x-player.transform.position.x)/3); } } else { //on the left clockWise = false; GotoPos = left; if(Vector2.Distance(this.transform.position,left)<4) { rotateNow = true; RotAngle = Mathf.Acos((left.x-player.transform.position.x)/3); } } } move (); } else { if(attackTimer <= 0) { attackTimer = Random.Range(10,15); GotoPos = player.transform.position; Debug.Log("Attack!"); attacking = true; } if(!attacking) { GotoPos.x = player.transform.position.x +7*Mathf.Cos(RotAngle); GotoPos.y = player.transform.position.y +7*Mathf.Sin(RotAngle); if(Vector2.Distance(this.transform.position, GotoPos)<2) { if(clockWise) { RotAngle+= 20; } else { RotAngle-=20; } } attackTimer -= Time.deltaTime; } else { GotoPos = player.transform.position; } move(); } break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="RoomBot" /> class. /// </summary> /// <param name="botId">The bot identifier.</param> /// <param name="ownerId">The owner identifier.</param> /// <param name="aiType">Type of the ai.</param> /// <param name="bartender">if set to <c>true</c> [bartender].</param> internal RoomBot(uint botId, uint ownerId, AiType aiType, bool bartender) { OwnerId = ownerId; BotId = botId; AiType = aiType; VirtualId = -1; RoomUser = null; LastSpokenPhrase = 1; IsBartender = bartender; }
public static Game Create(AiType blue, AiType red, GameMode gameMode, Random rnd) { return(new Game(blue, red, gameMode, rnd)); }
// Update is called once per frame void Update() { //Debug.Log ("Health " + health); if (mounted) { damage = 5*(1f-((float)health / 30f) +0.5f); } else { damage = 0; } //move forwards if (Vector2.Distance (this.transform.position, player.transform.position) < 15) { Alert = true; } else { Alert = false; Itime = 5; rotateNow = false; attackTimer = 0; } if (health < 15) { Ai = AiType.Follow; } if (health > 0 ) { FamineHealthImage.GetComponent<Image> ().fillAmount = health / 30; if((StateControl.State != StateControl.state.Pause)) { if (playerFound) { if (!Alert) { if (Vector2.Distance (transform.position, GotoPos) < 4) { GotoPos = FindNextPoint (CurrentIdlePos); } move (); } else { Vector2 DircetTowards; float angle; //if(!audio.isPlaying) //PlaySound(0); switch (Ai) { case AiType.Intercept: //player speed and our speed Vector2 pSpeed = player.rigidbody2D.velocity; Vector2 eSpeed = this.rigidbody2D.velocity; //player pos in x seconds GotoPos = (Vector2)player.transform.position - pSpeed.normalized + pSpeed * Itime; float dist = Vector2.Distance (GotoPos, this.transform.position); float TimeToIntercept = dist / eSpeed.magnitude; if (TimeToIntercept < Itime) { Itime -= 0.1f; } if (TimeToIntercept > Itime) { Itime += 0.1f; } if (AttackCool > 0) { AttackCool -= Time.deltaTime; } else { move (); } break; case AiType.Follow: //are we infront of the player? DircetTowards = this.transform.position - player.transform.position; angle = Vector2.Angle (player.transform.up, DircetTowards); if (angle > 90) { this.rigidbody2D.velocity = new Vector2 (0, 0); //behind GotoPos = player.transform.position - player.transform.up * 3; } else { //infront //create points at either side of and behind the player Vector2 left = player.transform.position - (player.transform.right * 3) - player.transform.up; Vector2 right = player.transform.position + (player.transform.right * 3) - player.transform.up; if (Vector2.Distance (this.transform.position, left) > Vector2.Distance (this.transform.position, right)) { //on the right GotoPos = right; } else { //on the left GotoPos = left; } } move (); break; } } } } } else { FamineHealthImage.SetActive(false); HealthBackgroundImage.SetActive(false); if (destroyed == false) { destroyed = true; StartCoroutine(destroyFamine()); } //tell player death is dead GameObject[] forts = GameObject.FindGameObjectsWithTag("Fort"); GameObject fort = forts[0]; float dist = float.MaxValue; foreach(GameObject g in forts) { if(dist> Vector2.Distance(transform.position,g.transform.position)) { fort = g; dist = Vector2.Distance(transform.position,g.transform.position); } } fort.SendMessage("BossDefeated"); GUIScript.FamineKilled = true; } }
void Start() { rider = this.transform.GetChild (0).gameObject; //find a group point GameObject[] g = GameObject.FindGameObjectsWithTag ("Group"); float dist = float.MaxValue; foreach (GameObject G in g) { if(dist > Vector2.Distance(G.transform.position,transform.position)) { dist = Vector2.Distance(G.transform.position,transform.position); CurrentIdlePos = G.transform.position; } } GotoPos = FindNextPoint (CurrentIdlePos); //find the player player = GameObject.FindGameObjectWithTag("Player"); //if there isnt a player then still move if (player == null) { playerFound = false; } else { playerFound = true; } //random AI switch (Random.Range ((int)0, (int)3)) { case 0: Ai = AiType.Circle; break; case 1: Ai = AiType.Follow; break; case 2: Ai = AiType.Intercept; break; } }