public IPointOfInterest Visit(FightAction fight) { var attacker = fight.Fight.InitialPhase.Initiator; var defender = fight.Fight.InitialPhase.Receiver; return(new FightPointOfInterest(_dimensions, attacker, defender)); }
public static UnitAction ActionFromJson(JsonElement elem) { JsonElement jsonData = elem.GetProperty(nameof(JsonData)); string unitGuid = elem.GetProperty(nameof(UnitGuid)).GetString(); string unitActionType = jsonData.GetProperty("UnitActionType").GetString(); switch (unitActionType) { case nameof(MoveAction): return(MoveAction.FromJson(unitGuid, jsonData)); case nameof(FightAction): return(FightAction.FromJson(unitGuid, jsonData)); case nameof(SpawnAction): return(SpawnAction.FromJson(unitGuid, jsonData)); case nameof(DieAction): // Do nothing for now. If a unit dies, it was probably the // result of some other action (fight, etc) // therefore, we don't need to DieAction because it will happen // automatically default: throw Global.Error(string.Format("{0} is not a valid UnitActionType", unitActionType)); } }
void StopUsingSkill() { foreach (BattleUnit unit in UsingSkill.Validtargets) { unit.HighlightDisable(); } UsingSkill.Validtargets.Clear(); UsingSkill = null; isUsingSkill = false; }
public override void Execute() { var skillDatabase = new SkillDatabase(Model.Map); var finalizer = new FightFinalizer(skillDatabase); var finalizedFight = finalizer.Finalize(Model.FightForecast, new BasicRandomizer()); var fightAction = new FightAction(finalizedFight); Model.PendingAction = fightAction; Model.State = BattleUIState.Fighting; }
public void Test_NoTargets() { var you = YouInARoom(out IWorld w); var f = new FightAction(you); Assert.IsFalse(f.HasTargets(you)); var other = new Npc("ff", you.CurrentLocation); Assert.IsTrue(f.HasTargets(you)); }
public void TestSingleFight() { var map = new Map(); var random = new BasicRandomizer(); var turnOrder = new List <ArmyType> { ArmyType.Friendly, ArmyType.Enemy, ArmyType.Other }; var references = new List <CombatantDatabase.CombatantReference> { new CombatantDatabase.CombatantReference { Position = new Vector2(), Name = "Liat", Army = ArmyType.Friendly }, new CombatantDatabase.CombatantReference { Position = new Vector2(1, 0), Name = "Janek", Army = ArmyType.Enemy } }; var database = new CombatantDatabase(references, new EmptySaveGameRepository()); var battle = new Models.Fighting.Battle.Battle(map, random, database, turnOrder, new List <IObjective> { new Rout() }, EmptyMapConfig); var liat = database.GetCombatantsByArmy(ArmyType.Friendly)[0]; var janek = database.GetCombatantsByArmy(ArmyType.Enemy)[0]; var moveAction = new MoveAction(map, liat, new Vector2(1, 1)); battle.SubmitAction(moveAction); Assert.AreEqual(new Vector2(1, 1), liat.Position); var forecast = battle.ForecastFight(liat, janek, SkillType.Melee); var finalizedFight = battle.FinalizeFight(forecast); var liatInitialHealth = liat.Health; var janekInitialHealth = janek.Health; var fightAction = new FightAction(liat, janek, finalizedFight); battle.SubmitAction(fightAction); var janekDamage = finalizedFight.InitialPhase.Effects.GetDefenderDamage(); var liatDamage = finalizedFight.CounterPhase.Effects.GetDefenderDamage(); Assert.AreEqual(janekInitialHealth - janekDamage, janek.Health); Assert.AreEqual(liatInitialHealth - liatDamage, liat.Health); Assert.IsTrue(battle.CanMove(liat)); Assert.IsFalse(battle.CanAct(liat)); }
public void Next() { GameReplay gReplay = ((GameReplay)game); if (gReplay.Action[gReplay.NbAction].GetType() == typeof(FightAction)) { FightAction actionf = (FightAction)gReplay.Action[gReplay.NbAction]; FightingBox = "Dégâts reçus : " + actionf.Damage; OnPropertyChanged("FightingBox"); } gReplay.NextAction(); ReloadMap(); }
public void TestAdvanceNoKill() { var map = new Map(); var random = new BasicRandomizer(); var turnOrder = new List <ArmyType> { ArmyType.Friendly, ArmyType.Enemy, ArmyType.Other }; var references = new List <CombatantDatabase.CombatantReference> { new CombatantDatabase.CombatantReference { Position = new Vector2(), Name = "Liat", Army = ArmyType.Friendly }, new CombatantDatabase.CombatantReference { Position = new Vector2(1, 0), Name = "Janek", Army = ArmyType.Enemy } }; var database = new CombatantDatabase(references, new EmptySaveGameRepository()); var battle = new Models.Fighting.Battle.Battle(map, random, database, turnOrder, new List <IObjective> { new Rout() }, EmptyMapConfig); var liat = database.GetCombatantsByArmy(ArmyType.Friendly)[0]; var janek = database.GetCombatantsByArmy(ArmyType.Enemy)[0]; var moveAction = new MoveAction(map, liat, new Vector2(1, 1)); battle.SubmitAction(moveAction); Assert.AreEqual(new Vector2(1, 1), liat.Position); var forecast = battle.ForecastFight(liat, janek, SkillType.Advance); var finalizedFight = battle.FinalizeFight(forecast); var numEffects = finalizedFight.InitialPhase.Effects.ReceiverEffects.Count; Assert.AreEqual(1, numEffects); var initialLiatPosition = liat.Position; var fightAction = new FightAction(liat, janek, finalizedFight); battle.SubmitAction(fightAction); Assert.AreEqual(liat.Position, initialLiatPosition); }
/// <summary> /// User and Enemy attack each other until one dies. /// </summary> public void startFight() { //attacks back and forth until someone dies while (Enemy.isAlive()) { FightAction FA = getPlayerWeapon(); FA.Use(Player.getInstance(), Enemy); if (Enemy.isAlive()) { Enemy.attack(Player.getInstance()); } } CIO.Print("you defeated " + Enemy.getName()); Player.getInstance().GiveXP(Enemy.XPOnDeath()); }
public void TestObstructedKnockback() { var map = new Map(); var random = new BasicRandomizer(); var turnOrder = new List <ArmyType> { ArmyType.Friendly, ArmyType.Enemy, ArmyType.Other }; var references = new List <CombatantDatabase.CombatantReference> { new CombatantDatabase.CombatantReference { Position = new Vector2(), Name = "Liat", Army = ArmyType.Friendly }, new CombatantDatabase.CombatantReference { Position = new Vector2(1, 0), Name = "Janek", Army = ArmyType.Enemy } }; var database = new CombatantDatabase(references, new EmptySaveGameRepository()); var battle = new Models.Fighting.Battle.Battle(map, random, database, turnOrder, new List <IObjective> { new Rout() }, EmptyMapConfig); var liat = database.GetCombatantsByArmy(ArmyType.Friendly)[0]; var janek = database.GetCombatantsByArmy(ArmyType.Enemy)[0]; map.AddObstruction(new Vector2(1, 2)); var moveAction = new MoveAction(map, liat, new Vector2(1, 1)); battle.SubmitAction(moveAction); Assert.AreEqual(new Vector2(1, 1), liat.Position); var forecast = battle.ForecastFight(janek, liat, SkillType.Knockback); var finalizedFight = battle.FinalizeFight(forecast); var fightAction = new FightAction(liat, janek, finalizedFight); battle.SubmitAction(fightAction); Assert.AreEqual(liat.Position, new Vector2(1, 1)); }
//Sets the next message to a corresponding player shout private void ResolvePlayerAction(FightAction action) { Debug.Log("fight aciton " + action); switch (action) { case FightAction.ThroatBite: //Debug.Log ("\"Go for the Throat, '" + dog1 + "'!\""); nextMessage = "\"Go for the Throat, '" + dog1 + "'!\""; break; case FightAction.LockBite: //Debug.Log("\"Lock your jaws around its neck, '" + dog1 + "'!\""); nextMessage = "\"Lock your jaws around its neck, '" + dog1 + "'!\""; break; case FightAction.Scratch: //Debug.Log ("\"Scratch it, '" + dog1 + "'!\""); nextMessage = "\"Scratch it, '" + dog1 + "'!\""; break; case FightAction.Tackle: //Debug.Log ("\"Tackle it, '" + dog1 + "'!\""); nextMessage = "\"Tackle it, '" + dog1 + "'!\""; break; case FightAction.Run: //Debug.Log ("You try to run from the fight, but one of the gangsters grabs you by the neck, and forces you to stay and watch."); nextMessage = "You try to run from the fight, but one of the gangsters grabs you by the neck, and forces you to stay and watch."; break; case FightAction.UseItem: break; case FightAction.SwitchDog: break; case FightAction.NoAction: return; default: break; } }
public void Round(FightAction chosenAction) { if (fightRunning) { // ACTION RESOLUTION ResolvePlayerAction(chosenAction); } else { if (!GameManager.PlayerDog.alive) { Defeat(); } else { EndFight(); } } }
public void AddPointsToPlayer(FightAction action, int score) { switch (action) { case FightAction.Damage: Points += score / 10; break; case FightAction.CriticalStrike: Points += score / 8; break; case FightAction.Lifesteal: Points += score / 2; break; case FightAction.EnemyDeath: Points += score / 10; break; } }
public static void DisplayFightAction(string subjectName, FightAction action, int actionNumber = 0, string objectName = "") { switch (action) { case FightAction.Damage: Program.MessageService.ShowMessage(new Message($"{subjectName} наносит {actionNumber} урона {objectName}", ConsoleColor.Cyan)); break; case FightAction.CriticalStrike: Program.MessageService.ShowMessage(new Message($"{subjectName} наносит {actionNumber} урона сокрушительным ударом по {objectName}!", ConsoleColor.Yellow)); break; case FightAction.Lifesteal: if (actionNumber < 1) { break; } Program.MessageService.ShowMessage(new Message($"{subjectName} восстанавливает {actionNumber} здоровья от вампиризма", ConsoleColor.Cyan)); break; case FightAction.EnemyDeath: Program.MessageService.ShowMessage(new Message($"{subjectName} поражен!", ConsoleColor.Yellow)); break; case FightAction.PlayerDeath: Program.MessageService.ShowMessage(new Message($"{subjectName} погиб!", ConsoleColor.Red)); Thread.Sleep(3000); break; case FightAction.Block: Program.MessageService.ShowMessage(new Message($"{subjectName} блокирует удар от {objectName} и получает {actionNumber} урона", ConsoleColor.Yellow)); break; case FightAction.Evade: Program.MessageService.ShowMessage(new Message($"{subjectName} уворачивается от удара {objectName}!", ConsoleColor.Yellow)); break; } }
public static List <UnitAction> TransformFromJson(List <JsonElement> unitActions) { List <UnitAction> actions = new List <UnitAction>(); foreach (JsonElement elem in unitActions) { JsonElement jsonData = elem.GetProperty(nameof(JsonData)); string unitGuid = elem.GetProperty(nameof(UnitGuid)).GetString(); string unitActionType = jsonData.GetProperty("UnitActionType").GetString(); switch (unitActionType) { case nameof(MoveAction): actions.Add(MoveAction.FromJson(unitGuid, jsonData)); break; case nameof(FightAction): actions.Add(FightAction.FromJson(unitGuid, jsonData)); break; case nameof(SpawnAction): actions.Add(SpawnAction.FromJson(unitGuid, jsonData)); break; case nameof(DieAction): // Do nothing for now. If a unit dies, it was probably the // result of some other action (fight, etc) // therefore, we don't need to DieAction because it will happen // automatically break; default: throw Global.Error(string.Format("{0} is not a valid UnitActionType", unitActionType)); } } return(actions); }
object PartOne(string input) { var inputValues = input.Lines() .Select(s => s.Split(':')) .ToDictionary(a => a[0].Trim(), a => int.Parse(a[1])); var boss = new Mob { HitPoints = inputValues["Hit Points"], Damage = inputValues["Damage"] }; var player = new Mob() { HitPoints = 50, Mana = 500 }; var magicMissile = new FightAction(53, f => { boss.HitPoints -= 4; }); var drain = new FightAction(73, f => { boss.HitPoints -= 2; player.HitPoints += 2; }); var shield = new FightAction(113, f => { player.Armor += 7; f.Effects.Add(new Effect(6, turns => { if (turns == 0) { player.Armor -= 7; } })); }); var poison = new FightAction(173, f => { f.Effects.Add(new Effect(6, turns => { boss.HitPoints -= 3; })); }); var recharge = new FightAction(229, f => { f.Effects.Add(new Effect(5, turns => { player.Mana += 101; })); }); var hit = new FightAction(0, f => { f.First.Attack(f.Second); }); var fight = new Fight(player, boss); fight.Run(f => { if (f.First == boss) { return(hit); } // How do we pick the best action? return(magicMissile); }); var playerWinLose = player.HasLost ? "Lost" : "Won"; Console.WriteLine($"Player: {playerWinLose}"); return(player.ManaSpent); }
private IEnumerator AnimateFight(FightAction action) { yield return(StartCoroutine(View.AnimateFight(action.Fight))); ActionAnimationCompleteSignal.Dispatch(action); }
public void TestKill() { var map = new Map(); var random = new BasicRandomizer(); var turnOrder = new List <ArmyType> { ArmyType.Friendly, ArmyType.Enemy, ArmyType.Other }; var references = new List <CombatantDatabase.CombatantReference> { new CombatantDatabase.CombatantReference { Position = new Vector2(), Name = "Liat", Army = ArmyType.Friendly }, new CombatantDatabase.CombatantReference { Position = new Vector2(1, 0), Name = "Janek", Army = ArmyType.Enemy } }; var liatStats = new CharacterBuilder() .Id("Liat") .Name("Liat") .Attributes(new AttributesBuilder() .Health(15) .Move(6) .Skill(99) .Defense(2) .Special(0) .Speed(13) .Strength(70) .Build()) .Stats(new StatsBuilder() .ParryChance(0) .Build()) .Weapons("Campaign Backblade", "Slim Recurve") .Build(); var janekStats = new CharacterBuilder() .Id("Janek") .Name("Janek") .Attributes(new AttributesBuilder() .Health(1) .Skill(12) .Move(6) .Defense(2) .Special(0) .Speed(13) .Strength(7) .Build()) .Stats(new StatsBuilder() .ParryChance(0) .Build()) .Weapons("Chained Mace") .Build(); var saveGame = new DefaultSaveGame(new List <ICharacter> { liatStats, janekStats }); var saveGameRepo = new EmptySaveGameRepository { CurrentSave = saveGame }; var database = new CombatantDatabase(references, saveGameRepo); var battle = new Models.Fighting.Battle.Battle(map, random, database, turnOrder, new List <IObjective> { new Rout() }, EmptyMapConfig); var liat = database.GetCombatantsByArmy(ArmyType.Friendly)[0]; var janek = database.GetCombatantsByArmy(ArmyType.Enemy)[0]; var forecast = battle.ForecastFight(liat, janek, SkillType.Melee); var finalizedFight = battle.FinalizeFight(forecast); Assert.IsNull(finalizedFight.CounterPhase); var fightAction = new FightAction(liat, janek, finalizedFight); battle.SubmitAction(fightAction); Assert.IsFalse(janek.IsAlive); }
public async Task <PathMinDisplayed> CreatePath(PathModel path) { int mapId = 0; List <string> zones = new List <string>(); string userId = User.Claims.First(c => c.Type == "UserID").Value; var user = await _userManager.FindByIdAsync(userId); TrajetDB trajetDB = new TrajetDB() { Name = path.Name, Type = (TypePath)path.Type, GroupLevelMax = path.GroupLevelMax, GroupLevelMin = path.GroupLevelMin, CaptureItem = path.CaptureItem, Fk_User = new Guid(userId), MaxPod = path.MaxPod, MonsterQuantityMin = path.MonsterQuantityMin, MonsterQuantityMax = path.MonsterQuantityMax, LeaderBank = path.LeaderBank, IsCapture = path.IsCapture, ListRessource = path.ListRessource, Key = Guid.NewGuid() }; foreach (var monstreLevel in path.MonsterLevel) { if (trajetDB.MonsterLevel == null) { trajetDB.MonsterLevel = new List <SpecificMonsterLevel>(); } trajetDB.MonsterLevel.Add(new SpecificMonsterLevel() { MonsterId = monstreLevel.MonsterId, MonsterLevelMax = monstreLevel.MonsterLevelmax, MonsterLevelMin = monstreLevel.MonsterLevelMin }); } foreach (var monstreQuantity in path.MonsterQuantity) { if (trajetDB.MonsterQuantity == null) { trajetDB.MonsterQuantity = new List <SpecificMonsterQuantity>(); } trajetDB.MonsterQuantity.Add(new SpecificMonsterQuantity() { MonsterId = monstreQuantity.MonsterId, MonsterQuantityMax = monstreQuantity.MonsterQuantityMax, MontserQuantityMin = monstreQuantity.MonsterQuantityMin }); } foreach (var monstreCapture in path.MonsterCapture) { if (trajetDB.MonsterCapture == null) { trajetDB.MonsterCapture = new List <CaptureMonsterQuantity>(); } trajetDB.MonsterCapture.Add(new CaptureMonsterQuantity() { MonsterId = monstreCapture.MonsterId, MonsterQuantity = monstreCapture.MonsterQuantity }); } /* actions du trajet */ trajetDB.PathAction = new List <PathAction>(); foreach (PathActionModel action in path.PathAction) { PathAction pathActionToCreate = new PathAction(); if (!ListBank.Contains(action.MapPos)) { MapDB map = Database.Maps.Find(o => o.Coordinate == ("[" + action.MapPos.Replace(';', ',') + "]")).First(); mapId = map.Key; if (!zones.Contains(map.AreaName)) { zones.Add(map.AreaName); } pathActionToCreate.MapId = mapId; foreach (MapActionModel item in action.Actions) { if (pathActionToCreate.Actions == null) { pathActionToCreate.Actions = new List <MapAction>(); } if (item.FightAction != null) { FightAction fightActionToCreate = new FightAction() { Order = item.Order, IsAlone = item.FightAction.IsAlone }; pathActionToCreate.Actions.Add(fightActionToCreate); } else if (item.GatherAction != null) { GatherAction GatherActionToCreate = new GatherAction() { Order = item.Order }; pathActionToCreate.Actions.Add(GatherActionToCreate); } else if (item.InteractionAction != null) { InteractionAction InteractionActionToCreate = new InteractionAction() { Order = item.Order, InteractiveIdObject = item.InteractionAction.InteractiveidObject, InteractiveIdResponse = item.InteractionAction.InteractiveIdResponse, ToBackBank = item.InteractionAction.ToBackBank, ToGoBank = item.InteractionAction.ToGoBank }; pathActionToCreate.Actions.Add(InteractionActionToCreate); } else if (item.moveAction != null) { MoveAction MoveActionToCreate = new MoveAction() { Order = item.Order, ToBackBank = item.moveAction.ToBackBank, ToGoBank = item.moveAction.ToGoBank, CellId = item.moveAction.Cellid }; if (item.moveAction.Direction != null) { foreach (string direc in item.moveAction.Direction) { if (MoveActionToCreate.Direction == null) { MoveActionToCreate.Direction = new List <MovementDirectionEnum>(); } MoveActionToCreate.Direction.Add((MovementDirectionEnum)System.Enum.Parse(typeof(MovementDirectionEnum), direc.ToUpper())); } } pathActionToCreate.Actions.Add(MoveActionToCreate); } else if (item.UseItemAction != null) { UseItemAction UseItemActionToCreate = new UseItemAction() { Order = item.Order, ItemId = item.UseItemAction.ItemId, ToBackBank = item.UseItemAction.ToBackBank, ToGoBank = item.UseItemAction.ToGoBank }; pathActionToCreate.Actions.Add(UseItemActionToCreate); } else if (item.ZaapAction != null) { int zaapDestination = Database.Maps.Find(o => o.Coordinate == ("[" + action.MapPos.Replace(';', ',') + "]")).First().Key; ZaapAction UseItemActionctionToCreate = new ZaapAction() { Order = item.Order, Destination = zaapDestination, ZaapId = item.ZaapAction.ZaapId, ToBackBank = item.ZaapAction.ToBackBank, ToGoBank = item.ZaapAction.ToGoBank }; pathActionToCreate.Actions.Add(UseItemActionctionToCreate); } else if (item.ZaapiAction != null) { int zaapiDestination = Database.Maps.Find(o => o.Coordinate == ("[" + action.MapPos.Replace(';', ',') + "]")).First().Key; ZaapAction UseItemActionctionToCreate = new ZaapAction() { Order = item.Order, Destination = zaapiDestination, ZaapId = item.ZaapiAction.ZaapiId, ToBackBank = item.ZaapiAction.ToBackBank, ToGoBank = item.ZaapiAction.ToGoBank }; pathActionToCreate.Actions.Add(UseItemActionctionToCreate); } } trajetDB.PathAction.Add(pathActionToCreate); } else { foreach (MapActionModel item in action.Actions) { pathActionToCreate = new PathAction(); if (item.moveAction != null) { mapId = item.moveAction.MapId.Value; pathActionToCreate.MapId = mapId; MoveAction MoveActionToCreate = new MoveAction() { Order = item.Order, ToBackBank = item.moveAction.ToBackBank, ToGoBank = item.moveAction.ToGoBank, CellId = item.moveAction.Cellid, MapId = mapId }; if (item.moveAction.Direction != null) { foreach (string direc in item.moveAction.Direction) { if (MoveActionToCreate.Direction == null) { MoveActionToCreate.Direction = new List <MovementDirectionEnum>(); } MoveActionToCreate.Direction.Add((MovementDirectionEnum)System.Enum.Parse(typeof(MovementDirectionEnum), direc.ToUpper())); } } if (trajetDB.PathAction.Exists(o => o.MapId == mapId)) { trajetDB.PathAction.Find(o => o.MapId == mapId).Actions.Add(MoveActionToCreate); } else { pathActionToCreate.Actions = new List <MapAction>(); pathActionToCreate.Actions.Add(MoveActionToCreate); trajetDB.PathAction.Add(pathActionToCreate); } } else if (item.BankAction != null) { mapId = item.BankAction.MapId.Value; pathActionToCreate.MapId = mapId; BankAction BankActionToCreate = new BankAction() { MapId = mapId, Order = item.Order }; if (trajetDB.PathAction.Exists(o => o.MapId == mapId)) { trajetDB.PathAction.Find(o => o.MapId == mapId).Actions.Add(BankActionToCreate); } else { pathActionToCreate.Actions = new List <MapAction>(); pathActionToCreate.Actions.Add(BankActionToCreate); trajetDB.PathAction.Add(pathActionToCreate); } } } } } trajetDB.Zones = zones; PathMinDisplayed retourPath = new PathMinDisplayed() { IsCapture = trajetDB.IsCapture, Key = trajetDB.Key, Name = trajetDB.Name, Type = trajetDB.Type, UsedNumber = 0, Zones = trajetDB.Zones }; await Database.Paths.InsertOneAsync(trajetDB); return(retourPath); }