private void SpawnEnemies() { Random r = new Random((int)DateTime.Now.ToOADate()); float x, z; int count = 5; x = 30; z = 30; c = (EnemyCruiser)GetEnemyCruiser(new Vector3(x + 10, 15 + 0, z + 0)); physicsManager.AddNewObject(c); for (int i = 0; i < count; i++) { x = (float)(r.NextDouble() - .5); z = (float)(r.NextDouble() - .5); x = x * 250; z = z * 250; EnemyFighter fighter = (EnemyFighter)GetEnemyFighter(new Vector3(x, 15, z)); //fighter.AddCollisionCallback(new JigLibX.Collision.CollisionCallbackFn(EnemyHit)); fighter.Init(new Vector3(x, 15, z), Matrix.Identity); physicsManager.AddNewObject(fighter); } }
private void LoadFighters(Resources res, GameHandler gameHandler) { for (int i = 0; i < /*this.enemyIDs.Count()*/ 1; i++) { this.enemies.Add(new EnemyFighter(this.enemyIDs[i], gameHandler.lastEncounteredEnemy.level, enemyScreenPositions[i])); this.enemies[i].LoadContent(res); this.aliveEnemyPositions.Add(i); } this.enemyTemplate = enemies[0]; this.removedCounter = 0; this.player = new PlayerFighter(playerScreenPos); this.player.attackList = MoveLoader.ConvertIDsToMoves(gameHandler.worldData.unlockedSkillIDs); for (int i = 0; i < this.player.attackList.Count(); i++) { List <FrameAnim> primaryAnims = new List <FrameAnim>(); for (int j = 0; j < res.MovePrimaryAnimsPerMove[Move.ID_DICT[this.player.attackList[i].moveName]].Count(); j++) { primaryAnims.Add(res.MovePrimaryAnims[res.MovePrimaryAnimsPerMove[Move.ID_DICT[this.player.attackList[i].moveName]][j]]); } this.player.attackList[i].LoadContent(primaryAnims, res.MoveSecondaryAnims[Move.ID_DICT[player.attackList[i].moveName]]); this.player.attackList[i].PrimeMove(player.standbyScreenPos, enemies[0].curScreenPos, 50, .35); } }
public void Team_TestAddRange_CorrectlyUpdatesDisplayNames() { Goblin goblin1 = (Goblin)FighterFactory.GetFighter(FighterType.Goblin, 1); Goblin goblin2 = (Goblin)FighterFactory.GetFighter(FighterType.Goblin, 1); Goblin goblin3 = (Goblin)FighterFactory.GetFighter(FighterType.Goblin, 1); Goblin goblin4 = (Goblin)FighterFactory.GetFighter(FighterType.Goblin, 1); Team testTeam = new Team(TestMenuManager.GetTestMenuManager(), goblin1 ); List <Goblin> goblinsToAdd = new List <Goblin> { goblin2, goblin3, goblin4 }; testTeam.AddRange(goblinsToAdd); for (var i = 0; i < 4; ++i) { EnemyFighter enemy = testTeam.Fighters[i] as EnemyFighter; char expectedAppendedChar = (char)('A' + i); string expectedAppendStr = $"{expectedAppendedChar}"; Assert.AreEqual(expectedAppendStr, enemy?.AppendText); } }
private void Awake() { mover = GetComponent <EnemyMover>(); fighter = GetComponent <EnemyFighter>(); health = GetComponent <Health>(); player = GameObject.FindWithTag("Player").transform; playerController = player.gameObject.GetComponent <PlayerController>(); }
public EnemyFighter GetEnemy(string key) { var prototype = _prototypes[key]; var fighter = new EnemyFighter(); fighter.Name = prototype.Name; fighter.SetLevel(prototype.Level); return fighter; }
public static bool IsNearTargetPosition(EnemyFighter fighter, EnemyCruiser cruiser) { float dist = Vector3.Distance(fighter.Position, cruiser.Position + fighter.OffsetFromCruiser); if (dist < TargetPositionRange) { return(true); } return(false); }
private void BuildMenu(IMenu menu, List <TerrainInteractable> terrainInteractables = null) { _player = (HumanFighter)FighterFactory.GetFighter(FighterType.HumanControlledPlayer, 1); var playerTeam = new Team(_menuManager, _player); _enemy = (EnemyFighter)FighterFactory.GetFighter(FighterType.Goblin, 1); var enemyTeam = new Team(_menuManager, _enemy); menu.Build(_player, playerTeam, enemyTeam, terrainInteractables ?? new List <TerrainInteractable>()); }
public static EnemyFighter MakeBeaver() { var beaver = new EnemyFighter { Name = "Beaver", Level = 1 }; return(beaver); }
public void StartCombat() { foreach (Button button in playerActionButtons) { button.interactable = false; } playerFighter = Instantiate(playerFighterPrefab); enemyFighter = Instantiate(enemyFighterPrefab); StartCoroutine(BattleFlow()); }
private static MagicType GetFighterMagicType(EnemyFighter fighter) { MagicType ret = MagicType.None; IMagicEnemy fighterAsMagicEnemy = fighter as IMagicEnemy; if (fighterAsMagicEnemy != null) { ret = fighterAsMagicEnemy.MagicType; } return(ret); }
public void StartCombat() { playerFighter = Instantiate(playerFighterPrefab); enemyFighter = Instantiate(enemyFighterPrefab); fighters = new List <Fighter>() { playerFighter, enemyFighter }; if (UnityEngine.Random.value > .5f) { fighters.Reverse(); } StartCoroutine(BattleFlow()); }
public void addBoid(Vector3 position, EnemyType type) { AEnemys ship; switch (type) { case EnemyType.Fighter: ship = new EnemyFighter(position); ship.LoadContent(fighterModel); break; case EnemyType.Fighter2: ship = new EnemyFighter2(position); ship.LoadContent(fighter2Model); break; case EnemyType.Fighter3: ship = new EnemyFighter3(position); ship.LoadContent(fighter3Model); break; case EnemyType.Bomber: ship = new EnemyBomber(position); ship.LoadContent(bomberModel); break; case EnemyType.Bomber2: ship = new EnemyBomber2(position); ship.LoadContent(bomber2Model); break; case EnemyType.Boss: ship = new EnemyBoss(position); ship.LoadContent(bossModel); break; default: ship = new EnemyFighter(position); ship.LoadContent(fighterModel); break; } ship.flyingAwayFromDrone = false; ship.flyingAwayFromStation = false; _ships.Add(ship); }
public void AddFigther(ContentManager pContent, Vector2 pPosition, Vector2 pDestination) { int i = 0; if (EnemyFighter.Count != 0) { while (i < EnemyFighter.Count && EnemyFighter[i] != null) { i++; } } Fighter var = new Fighter(pContent, this, i); EnemyFighter.Insert(i, var); EnemyFighter[i].SpawnAt(pPosition); EnemyFighter[i].SetDestination(pDestination); EnemyFighter[i].SetTarget(new Vector2(640, 360)); }
public void Constructor_CorrectlySetsDisplayNames_TeamEntirelyComprisedOfHumanControlledEnemies() { HumanControlledEnemyFighter humanControlledEnemy1 = (HumanControlledEnemyFighter)FighterFactory.GetFighter(FighterType.HumanControlledEnemy, 1); EnemyFighter enemy1 = (EnemyFighter)FighterFactory.GetFighter(FighterType.Goblin, 1); humanControlledEnemy1.SetEnemy(enemy1); HumanControlledEnemyFighter humanControlledEnemy2 = (HumanControlledEnemyFighter)FighterFactory.GetFighter(FighterType.HumanControlledEnemy, 1); EnemyFighter enemy2 = (EnemyFighter)FighterFactory.GetFighter(FighterType.Goblin, 1); humanControlledEnemy2.SetEnemy(enemy2); HumanControlledEnemyFighter humanControlledEnemy3 = (HumanControlledEnemyFighter)FighterFactory.GetFighter(FighterType.HumanControlledEnemy, 1); EnemyFighter enemy3 = (EnemyFighter)FighterFactory.GetFighter(FighterType.Fairy, 1); humanControlledEnemy3.SetEnemy(enemy3); HumanControlledEnemyFighter humanControlledEnemy4 = (HumanControlledEnemyFighter)FighterFactory.GetFighter(FighterType.HumanControlledEnemy, 1); EnemyFighter enemy4 = (EnemyFighter)FighterFactory.GetFighter(FighterType.Fairy, 1); humanControlledEnemy4.SetEnemy(enemy4); List <IFighter> fighters = new List <IFighter> { humanControlledEnemy1, humanControlledEnemy2, humanControlledEnemy3, humanControlledEnemy4, }; Team team = new Team(_menuManager, fighters); for (var i = 0; i < 4; ++i) { IFighter fighter = team.Fighters[i]; char expectedChar = (char)('A' + (i % 2)); Assert.AreEqual($"{expectedChar}", fighter.AppendText); } }
public void Build(HumanControlledEnemyFighter owner, Team ownTeam, Team enemyTeam, List <TerrainInteractable> terrainInteractables) { Owner = owner; _ownTeam = ownTeam; _enemyTeam = enemyTeam; _hasBeenBuilt = true; EnemyFighter ownerAsEnemyFighter = owner.Fighter; if (ownerAsEnemyFighter == null) { throw new ArgumentException("HumanControlledEnemyMenu should only be built with an instance of Enemy Fighter", nameof(owner)); } MenuActions = ownerAsEnemyFighter.AvailableMoves.Select( move => new MenuAction(move.Description, subMenu: _menuFactory.GetMenu(MenuType.ChooseTargetMenu, _input, _output), move: move)) .ToList(); foreach (var menuAction in MenuActions) { menuAction.SubMenu?.Build(owner, ownTeam, enemyTeam, terrainInteractables); } }
public void Constructor_CorrectlySetsDisplayNames_TeamComprisedOfMixOfNormalEnemiesAndHumanControlledEnemies() { HumanControlledEnemyFighter humanControlledEnemy1 = (HumanControlledEnemyFighter)FighterFactory.GetFighter(FighterType.HumanControlledEnemy, 1); EnemyFighter enemy1 = (EnemyFighter)FighterFactory.GetFighter(FighterType.Goblin, 1); humanControlledEnemy1.SetEnemy(enemy1); HumanControlledEnemyFighter humanControlledEnemy2 = (HumanControlledEnemyFighter)FighterFactory.GetFighter(FighterType.HumanControlledEnemy, 1); EnemyFighter enemy2 = (EnemyFighter)FighterFactory.GetFighter(FighterType.Goblin, 1); humanControlledEnemy2.SetEnemy(enemy2); HumanControlledEnemyFighter humanControlledEnemy3 = (HumanControlledEnemyFighter)FighterFactory.GetFighter(FighterType.HumanControlledEnemy, 1); EnemyFighter enemy3 = (EnemyFighter)FighterFactory.GetFighter(FighterType.Fairy, 1); humanControlledEnemy3.SetEnemy(enemy3); HumanControlledEnemyFighter humanControlledEnemy4 = (HumanControlledEnemyFighter)FighterFactory.GetFighter(FighterType.HumanControlledEnemy, 1); EnemyFighter enemy4 = (EnemyFighter)FighterFactory.GetFighter(FighterType.Fairy, 1); humanControlledEnemy4.SetEnemy(enemy4); HumanControlledEnemyFighter humanControlledEnemy5 = (HumanControlledEnemyFighter)FighterFactory.GetFighter(FighterType.HumanControlledEnemy, 1); EnemyFighter enemy9 = (EnemyFighter)FighterFactory.GetFighter(FighterType.Warrior, 1); humanControlledEnemy5.SetEnemy(enemy9); IFighter enemy5 = FighterFactory.GetFighter(FighterType.Goblin, 1); IFighter enemy6 = FighterFactory.GetFighter(FighterType.Goblin, 1); IFighter enemy7 = FighterFactory.GetFighter(FighterType.Fairy, 1); IFighter enemy8 = FighterFactory.GetFighter(FighterType.Fairy, 1); IFighter enemy10 = FighterFactory.GetFighter(FighterType.Golem, 1); List <IFighter> fighters = new List <IFighter> { humanControlledEnemy1, humanControlledEnemy2, enemy5, enemy6, humanControlledEnemy3, humanControlledEnemy4, enemy7, enemy8, humanControlledEnemy5, enemy10 }; Team team = new Team(_menuManager, fighters); IFighter fighter; for (var i = 0; i < 8; ++i) { fighter = team.Fighters[i]; char expectedChar = (char)('A' + (i % 4)); Assert.AreEqual($"{expectedChar}", fighter.AppendText, $"i: {i}"); } fighter = team.Fighters[8]; Assert.AreEqual("", fighter.AppendText); fighter = team.Fighters[9]; Assert.AreEqual("", fighter.AppendText); }
private void Gameplay_Update(int GameState, GameTime pGameTime, ContentManager Content) { if (keyboard != previousKeyboard && keyboard.IsKeyDown(Keys.Escape) && pause) { this.Game_State = 0; } if (keyboard.IsKeyDown(Keys.Escape)) { pause = true; this.Pause = mstate.Position; } if (keyboard != previousKeyboard && keyboard.IsKeyDown(Keys.Enter) && pause) { pause = false; Mouse.SetPosition(Pause.X, Pause.Y); } if (!pause) { foreach (Enemy var1 in enemyFighter) { var1.Update(pGameTime); } foreach (Sprite HUD in hud) { HUD.Update(pGameTime); } foreach (Right_HUD R_H in R_hud) { R_H.Update(pGameTime); } SSV.Update(pGameTime); cone.Update(pGameTime); //Enemies Update foreach (Fighter Enemies in EnemyFighter) { Point ID = Enemies.Update(pGameTime); if (ID != Point.Zero) { TargetID = ID; } Enemies.UpdatePositionAngle(cone); if (Enemies.FireWeapon) { int i = 0; if (EnemyMissile.Count != 0) { while (i < EnemyMissile.Count && EnemyMissile[i] != null) { i++; } } Missile var = new Missile(content, this, i, new Point(0, 0)); EnemyMissile.Insert(i, var); EnemyMissile[i].SpawnAt(Enemies.Position); EnemyMissile[i].SetDestination(new Vector2(640, 360)); Enemies.FireWeapon = false; } if (!Enemies.IsActive) { EnemyFighterDump.Add(Enemies); } } EnemyFighter = EnemyFighter.Except(EnemyFighterDump).ToList(); foreach (Frigate Enemies in EnemyFrigate) { Point ID = Enemies.Update(pGameTime); if (ID != Point.Zero) { TargetID = ID; } Enemies.UpdatePositionAngle(cone); if (Enemies.FireWeapon) { int i = 0; if (EnemySlug.Count != 0) { while (i < EnemySlug.Count && EnemySlug[i] != null) { i++; } } Slug var = new Slug(content, this); EnemySlug.Insert(i, var); EnemySlug[i].SpawnAt(Enemies.Position); EnemySlug[i].SetDestination(new Vector2(640, 360)); Enemies.FireWeapon = false; } if (!Enemies.IsActive) { EnemyFrigateDump.Add(Enemies); } } EnemyFrigate = EnemyFrigate.Except(EnemyFrigateDump).ToList(); foreach (Carrier Enemies in EnemyCarrier) { Point ID = Enemies.Update(pGameTime); if (ID != Point.Zero) { TargetID = ID; } Enemies.UpdatePositionAngle(cone); if (Enemies.FireWeapon) { AddFigther(content, Enemies.Position, new Vector2(640, 360)); Enemies.FireWeapon = false; } if (!Enemies.IsActive) { EnemyCarrierDump.Add(Enemies); } } EnemyCarrier = EnemyCarrier.Except(EnemyCarrierDump).ToList(); foreach (Dreadnought Enemies in EnemyDreadnought) { Point ID = Enemies.Update(pGameTime); if (ID != Point.Zero) { TargetID = ID; } Enemies.UpdatePositionAngle(cone); if (Enemies.FireWeapon) { int i = 0; if (EnemyCannon.Count != 0) { while (i < EnemyCannon.Count && EnemyCannon[i] != null) { i++; } } Cannon var = new Cannon(content, this, new Point(0, 0), 10); EnemyCannon.Insert(i, var); EnemyCannon[i].SpawnAt(Enemies.Position); Enemies.FireWeapon = false; } if (!Enemies.IsActive) { EnemyDreadnoughtDump.Add(Enemies); } } EnemyDreadnought = EnemyDreadnought.Except(EnemyDreadnoughtDump).ToList(); //endEnemies Update //Weapons Update foreach (Missile Missile in EnemyMissile) { Point ID = Missile.Update(GetPositionByID(Missile.TargetID)); if (ID != Point.Zero) { TargetID = ID; } if (Missile.Friendly == false && Missile.IsMoving == false) { Missile.Destroy = true; enemyMissileDump.Add(Missile); HB_hp -= 1; } else if (Missile.Friendly && !Missile.IsMoving) { DamageTarget(Missile.TargetID, 1); } } enemyMissile = enemyMissile.Except(enemyMissileDump).ToList(); foreach (Laser Lsr in Lasers) { Lsr.Update(); } foreach (Slug Slug in EnemySlug) { Slug.Update(); if (Slug.Friendly == false && Slug.IsMoving == false) { Slug.Destroy = true; enemySlugDump.Add(Slug); HB_hp -= 5; } else if (Slug.Friendly && !Slug.IsMoving) { DamageTarget(Slug.TargetID, 2); } } enemySlug = enemySlug.Except(enemySlugDump).ToList(); foreach (Cannon Cannon in EnemyCannon) { Cannon.Update(); //Add destroy here. } enemySlug = enemySlug.Except(enemySlugDump).ToList(); //endWeapons Update ladar.Update(pGameTime, cone.Lockin, cone.stopAngle_M); if (SpawnBlock == 200) { SpawnEnemy(Content); SpawnBlock = 0; } else { SpawnBlock += 1; } //PlayerWeapons PlayerWpn[0].Update(); PlayerWpn[1].Update(); PlayerWpn[2].Update(); PlayerWpn[3].Update(); PlayerWpn[4].Update(); if (keyboard.IsKeyDown(Keys.D1)) { if (PlayerWpn[0].CanFire) { int i = 0; if (EnemyMissile.Count != 0) { while (i < EnemyMissile.Count && EnemyMissile[i] != null) { i++; } } Missile var = new Missile(content, this, i, TargetID); EnemyMissile.Insert(i, var); EnemyMissile[i].SpawnAt(new Vector2(640, 360)); EnemyMissile[i].SetDestination(GetPositionByID(TargetID)); EnemyMissile[i].Friendly = true; PlayerWpn[0].FireWeapon(); } } else if (keyboard.IsKeyDown(Keys.D2)) { if (PlayerWpn[1].CanFire) { int i = 0; if (Lasers.Count != 0) { while (i < Lasers.Count && Lasers[i] != null) { i++; } } Laser var = new Laser(content, this, TargetID, 10); Lasers.Insert(i, var); Lasers[i].SpawnAt(new Vector2(640, 360)); PlayerWpn[1].FireWeapon(); } } else if (keyboard.IsKeyDown(Keys.D3)) { if (PlayerWpn[2].CanFire) { int i = 0; if (EnemySlug.Count != 0) { while (i < EnemySlug.Count && EnemySlug[i] != null) { i++; } } Slug var = new Slug(content, this); EnemySlug.Insert(i, var); EnemySlug[i].SpawnAt(new Vector2(640, 360)); EnemySlug[i].SetDestination(GetPositionByID(TargetID)); PlayerWpn[2].FireWeapon(); } } else if (keyboard.IsKeyDown(Keys.D4)) { if (PlayerWpn[3].CanFire) { int i = 0; if (EnemyCannon.Count != 0) { while (i < EnemyCannon.Count && EnemyCannon[i] != null) { i++; } } Cannon var = new Cannon(content, this, TargetID, 10); EnemyCannon.Insert(i, var); EnemyCannon[i].SpawnAt(new Vector2(640, 360)); PlayerWpn[3].FireWeapon(); DamageTarget(TargetID, 3); } } else if (keyboard.IsKeyDown(Keys.D5)) { if (PlayerWpn[4].CanFire) { foreach (Fighter var1 in EnemyFighter) { DamageTarget(var1.ID, 4); } foreach (Frigate var1 in EnemyFrigate) { DamageTarget(var1.ID, 4); } foreach (Carrier var1 in EnemyCarrier) { DamageTarget(var1.ID, 4); } foreach (Dreadnought var1 in EnemyDreadnought) { DamageTarget(var1.ID, 4); } } } //End Player Weapons //Dreadnought Countdown foreach (Dreadnought Dreadnought in EnemyDreadnought) { if (Dreadnought.IsMoving == false) { Dreadnought.cannonCountdown -= 1; //Console.WriteLine(Dreadnought.cannonCountdown); } if (Dreadnought.cannonCountdown == 0) { Dreadnought.cannonCountdown = 100; } } //end Dreadnought Countdown } }
public Team GetTeam(MenuManager menuManager, IInput input, IOutput output, out BattleConfigurationSpecialFlag battleFlag) { List <IFighter> fighters = new List <IFighter> { null, null, null, null, null }; bool continuer = true; battleFlag = BattleConfigurationSpecialFlag.None; ConfirmationMenu humanControlledTeamConfirmationMenu = new ConfirmationMenu(false, "Do you want this team to be human controlled?", input, output); MenuSelection confirmationInput = humanControlledTeamConfirmationMenu.GetInput(); bool isHumanControlledTeam = confirmationInput.Description == "yes"; for (var i = 0; i < 5 && continuer;) { SelectEnemyFighterMenu menu = Menus[i]; MenuSelection menuSelection = menu.GetInput(); if (i > 0 && menuSelection.Description == "back") { --i; } else { SelectEnemyFighterMenuSelection selectEnemyMenuSelection = menuSelection as SelectEnemyFighterMenuSelection; if (selectEnemyMenuSelection == null) { throw new InvalidOperationException( "SelectEnemyFighterMenu.GetInput() didn't return a SelectEnemyFighterMenuSelection"); } FighterFactory.SetInput(input); FighterFactory.SetOutput(output); IFighter returnedEnemy = FighterFactory.GetFighter(selectEnemyMenuSelection.FighterType, selectEnemyMenuSelection.FighterLevel); if (!(returnedEnemy is EnemyFighter)) { throw new InvalidOperationException( $"The selected FighterType {selectEnemyMenuSelection.FighterType} cannot be cast to an EnemyFighter"); } EnemyFighter enemy = (EnemyFighter)returnedEnemy; IFighter fighterToAdd; if (isHumanControlledTeam) { HumanControlledEnemyFighter humanControlledEnemy = (HumanControlledEnemyFighter)FighterFactory.GetFighter(FighterType.HumanControlledEnemy, 1); humanControlledEnemy.SetEnemy(enemy); fighterToAdd = humanControlledEnemy; } else { fighterToAdd = enemy; } fighters[i] = fighterToAdd; if (selectEnemyMenuSelection.SpecialFlag != BattleConfigurationSpecialFlag.None && battleFlag == BattleConfigurationSpecialFlag.None) { battleFlag = selectEnemyMenuSelection.SpecialFlag; } if (i < 4) { ConfirmationMenu addAnotherFighrerConfirmationMenu = new ConfirmationMenu(false, "Do you want to add another fighter?", input, output); confirmationInput = addAnotherFighrerConfirmationMenu.GetInput(); if (confirmationInput.Description == "no") { continuer = false; } } ++i; } } fighters = fighters.Where(f => f != null).ToList(); Team ret = new Team(menuManager, fighters); return(ret); }
public static void Update(EnemyFighter fighter, Entity cruiser, Entity player) { switch (fighter.mode) { case EnemyFighter.Modes.Patrol: fighter.PositionTarget = cruiser.Position + fighter.OffsetFromCruiser; // if we are near our destination if (IsNearTargetPosition(fighter, cruiser as EnemyCruiser)) { float scale = 25; float bubblesize = 10; fighter.OffsetFromCruiser = new Vector3((float)r.NextDouble() - .5f, (float)r.NextDouble() - .5f, (float)r.NextDouble() - .5f); fighter.OffsetFromCruiser *= scale; Vector3 dir = Vector3.Normalize(fighter.OffsetFromCruiser); fighter.OffsetFromCruiser += (dir * bubblesize); // stay in range of the cruiser if (IsNearCuiser(fighter, cruiser)) { } else { } } // this should really be picking a heading. // what heading we pick depends on the environment. // if targets, attack if (isTargetNear(fighter, player)) { fighter.mode = EnemyFighter.Modes.Attack; } // if hit, evade if (hitRecently()) { fighter.mode = EnemyFighter.Modes.Evade; } break; case EnemyFighter.Modes.Attack: // if hit, evade if (hitRecently()) { fighter.mode = EnemyFighter.Modes.Evade; } if (isTargetNear(fighter, player)) { // align to attack } else // if no targets, patrol { fighter.mode = EnemyFighter.Modes.Patrol; } break; case EnemyFighter.Modes.Evade: if (hitRecently()) { // evade in some direction, once. // clear hit recently. } // if clear, patrol if (!isTargetNear(fighter, player)) { fighter.mode = EnemyFighter.Modes.Patrol; } break; default: break; } fighter.Update(); }
/// <summary> /// A helper method to be called to ensure all Enemy /// </summary> public void SetupDisplayNames() { //TODO: have some way to check if an enemy has the "default" name. If there's a goblin named Eurdar the Wise, we don't want them to become Eurdar the Wise A List <EnemyFighter> enemies = GetEnemyFighters().ToList(); //List<HumanControlledEnemyFighter> humanControlledEnemies = enemies.OfType<HumanControlledEnemyFighter>().ToList(); // //IEnumerable<IGrouping<Type, EnemyFighter>> groupedEnemies = humanControlledEnemies.GroupBy(e => e.Fighter.GetType()); // //enemies = enemies.Except(humanControlledEnemies).ToList(); // ////names only need to be set for enemies for which there are multiple types //groupedEnemies = groupedEnemies.Concat(enemies.GroupBy(e => e.GetType())); // //groupedEnemies = groupedEnemies.Where(g => g.Count() > 1); //IEnumerable<IGrouping<Type, EnemyFighter>> groupedEnemies = enemies.GroupBy(e => IEnumerable <IGrouping <Tuple <Type, MagicType>, EnemyFighter> > groupedEnemies = enemies.GroupBy(e => { Type type; MagicType magicType; HumanControlledEnemyFighter humanControlled = e as HumanControlledEnemyFighter; if (humanControlled != null) { EnemyFighter fighter = humanControlled.Fighter; magicType = GetFighterMagicType(fighter); type = fighter.GetType(); } else { type = e.GetType(); magicType = GetFighterMagicType(e); } return(new Tuple <Type, MagicType>(type, magicType)); }).Where(g => g.Count() > 1); foreach (IGrouping <Tuple <Type, MagicType>, EnemyFighter> group in groupedEnemies) { int i = 0; foreach (EnemyFighter enemy in group) { string appendText; if (i < 26) { appendText = $"{(char)('A' + i)}"; } else { int firstIndex = (i / 26) - 1; int secondIndex = i % 26; char firstChar = (char)('A' + firstIndex); char secondChar = (char)('A' + secondIndex); appendText = $"{firstChar}{secondChar}"; } enemy.SetAppendText(appendText); ++i; } } }