public Fire(int Turns, int Damage, Point Position, Point SpawnPosition, Map Map, MainGameWindow main) : base("Fire", SpawnPosition, Resources.Fire, Map, Turns, main, render: false) { //Can it actually exist? if (Map.map.Get(Position).type.FType == FieldType.water) { //Destroy it BaseDelete(); Delete(); return; } //Set position to actual position - to create effect that the mage created the fireball this.Position = Position; main.RenderMap(); damage = Damage; this.main.PlayerMoved += Main_PlayerMoved; //Check if put on position of entity List <Troop> f = Map.troops.Where(t => t.Position == Position).ToList(); if (f.Count != 0) { Player player = main.players.First(p => p.troop == f[0]); string playerName = player.Name; main.WriteConsole($"{playerName} has been put on fire!"); f[0].statuses.Add(new FireStatus(turns + 2, damage, main, player)); if (playerName == main.humanPlayer.Name) { main.UpdatePlayerView(); } } }
public static int IDcounter = 0; //The id of an effect is used to identify the render object it is linked to public Effect(string Name, Point Position, Bitmap Image, Map Map, int Turns, MainGameWindow main, bool Blocking = false, bool render = true) : base(Name + IDcounter.ToString(), Position, Image, Blocking, Map) { ID = IDcounter; IDcounter++; //DEBUG Test -- check that there is no race condition occuring and that names are being set correctly if (Name + ID.ToString() != base.Name) { throw new Exception("Setting of effect name went wrong!"); } map = Map; map.entities.Add(this); lock (map.RenderController) { map.renderObjects.Add(new EntityRenderObject(this, new TeleportPointAnimation(new Point(0, 0), Position))); } if (render) { main.RenderMap(); } turns = Turns; this.main = main; main.Turn += Main_Turn; }
private void RunMission(int difficulty, Mission.Mission selected, StartMission action = null) { World.Instance.campaign.mission = selected; MapBiome biome = new GrasslandMapBiome(); if (mapBiomes.ContainsKey(World.Instance.worldMap[player.WorldPosition.X, player.WorldPosition.Y].type)) { biome = mapBiomes[World.Instance.worldMap[player.WorldPosition.X, player.WorldPosition.Y].type]; } Map map = World.Instance.campaign.GenerateMap(biome); player.map = map; player.troop.Map = map; MainGameWindow mainGame = new MainGameWindow(map, player, selected, World.Instance.trees, difficulty, World.WORLD_DIFFICULTY); biome.ManipulateMission(mainGame, selected); mainGame.RenderMap(true, true, true); controller.Stop(); mainGame.ShowDialog(); if (action != null) { action.MissionEnded(mainGame.giveReward); } if (mainGame.dead) { //as player is dead campaign is over Close(); return; } if (mainGame.giveReward) { //Now give reward MissionResult r = CampaignController.GenerateRewardAndHeal(player, mainGame, selected, player.vitality.Value, (player.level / 25d).Cut(0, 1), "Close"); r.ShowDialog(); } if (running) { controller.Start(); } World.Instance.missionsCompleted++; World.Instance.actors.RemoveAll(p => (p is MissionWorldPlayer wp) && wp.WorldPosition == player.WorldPosition); World.Instance.GenerateNewMission(); Render(); }
public override void PlayTurn(MainGameWindow main, bool SingleTurn) { DistanceGraphCreator distanceGraph = new DistanceGraphCreator(this, troop.Position.X, troop.Position.Y, map, false); Thread path = new Thread(distanceGraph.CreateGraph); path.Start(); path.Join(); int damageDealt = 0; int dodged = 0; while (actionPoints.Value > 0) { Point playerPos = enemies[0].troop.Position; //Check if it can attack player int playerDistance = AIUtility.Distance(playerPos, troop.Position); if (playerDistance <= troop.activeWeapon.range && troop.activeWeapon.Attacks() > 0) { //Attack var(damage, killed, hit) = main.Attack(this, enemies[0]); damageDealt += damage; if (!hit) { dodged++; } if (killed) { map.overlayObjects.Add(new OverlayText(enemies[0].troop.Position.X * MapCreator.fieldSize, enemies[0].troop.Position.Y * MapCreator.fieldSize, Color.Red, $"-{damageDealt}")); main.PlayerDied($"You have been killed by {Name}!"); break; } actionPoints.RawValue--; troop.activeWeapon.UseWeapon(enemies[0], main); main.RenderMap(); continue; } else if (troop.weapons.Exists(t => t.range >= playerDistance && t.Attacks() > 0)) { //Change weapon Weapon best = troop.weapons.FindAll(t => t.range >= playerDistance) .Aggregate((t1, t2) => t1.range > t2.range ? t1 : t2); troop.activeWeapon = best; continue; } Point closestField = new Point(-1, -1); try { // Try finding closer field to player closestField = AIUtility.FindClosestField(distanceGraph, playerPos, movementPoints.Value, map, (List <(Point point, double cost, double height)> list) => { list.Sort((o1, o2) => { double diffCost = o1.cost - o2.cost; double heightDiff = o1.height - o2.height; if (Math.Abs(diffCost) >= 1) //assume that using the weapon costs 1 action point { return(diffCost < 0 ? -1 : 1); } else if (heightDiff != 0) { return(diffCost < 0 ? -1 : 1); } return(0); }); return(list.First().point); }); }