public void AMonsterMissesAHero() { Game game = GivenGame(); Hero wizard = GivenWizard(game); wizard.Treasure.Add(new Treasure()); game.Dice.WhenRoll(1); game.Dice.WhenRoll(4); Monster goblin = Monster.NewGoblin(game); goblin.Attack(wizard); wizard.Treasure.Count.Should().Be(1); }
void AddAttack() { mOwner.Attack(0.1f); //Throw Bomb if (this.transform.localScale.y < 0.0f) { MonsterManager.GetInstance().CreateMonster(SpawnMonsterID, new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(0.0f, 1.0f), true); } else { MonsterManager.GetInstance().CreateMonster(SpawnMonsterID, new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(0.0f, 1.0f)); } }
public void StartBattle() { audiosr = this.gameObject.AddComponent <AudioSource>(); audiosr.playOnAwake = false; audiohit = Resources.Load <AudioClip>("hitcut"); audiobuff = Resources.Load <AudioClip>("buffcut"); this.StartButton.SetActive(false); this.StartText.SetActive(false); this.Cover.SetActive(false); this.turn = 1; team.PowerIncrease(this.turn); APs[0].sprite = Resources.Load <Sprite>("yellowap"); APs[1].sprite = Resources.Load <Sprite>("yellowap"); monster = gameObject.GetComponent <Monster>(); monster.Attack(); }
public void Start() { Hero hero = new Hero(); Monster monster = new Monster(); Console.WriteLine("You are facing a Monster!"); Console.ReadKey(); Console.Clear(); do { DisplayBattle(hero, monster); switch (GetChoice()) { case BattleChoice.Attack: hero.Attack(monster); break; case BattleChoice.Defend: hero.Defend(); break; case BattleChoice.Heal: hero.Heal(400); break; default: Console.WriteLine("Monster took a cheap shot!"); break; } if (monster.IsAlive) { monster.Attack(hero); } Console.WriteLine("Press Enter to Continue"); Console.ReadLine(); Console.Clear(); }while(hero.IsAlive && monster.IsAlive); DisplayBattleResult(hero); Console.ReadLine(); }
public void AMonsterWoundsAHero() { Game game = GivenGame(); Hero wizard = GivenWizard(game); wizard.Treasure.Add(new Treasure()); wizard.Move(); wizard.Move(); game.Dice.WhenRoll(4); game.Dice.WhenRoll(4); Monster goblin = Monster.NewGoblin(game); goblin.Attack(wizard); wizard.Treasure.Count.Should().Be(0); wizard.LostTurns.Should().Be(1); wizard.Space.Should().Be(_northCorridor); }
private void Bash() { if (Monster.IsFrozen || Monster.IsSleeping || Monster.IsBlind || Monster.IsConfused) { return; } var obj = Monster.GetInfront(1); if (obj == null) { return; } if (Monster.Target != null) { if (!Monster.Facing(Target.X, Target.Y, out var direction)) { Monster.Direction = (byte)direction; Monster.Turn(); } } if (Target == null || Target.CurrentHp == 0) { ClearTarget(); return; } if (Monster != null && Monster.Target != null && SkillScripts.Count > 0) { var idx = _random.Next(SkillScripts.Count); if (_random.Next(1, 101) < ServerContext.Config.MonsterSkillSuccessRate) { SkillScripts[idx].OnUse(Monster); } } Monster?.Attack(Target); }
void Start() { Monster m1 = new Monster(); m1.name = "monster1"; m1.age = 10; m1.power = 1; m1.Attack(); Monster m2 = new Monster("monster2"); m2.age = 20; m2.power = 2; m2.Run(); Monster m3 = new Monster("monster3", 30); m3.power = 3; m3.Attack(); }
public void AMonsterKillsAHero() { Game game = GivenGame(); Hero wizard = GivenWizard(game); for (int i = 0; i < 7; ++i) { wizard.Treasure.Add(new Treasure()); } wizard.Move(); wizard.Move(); game.Dice.WhenRoll(6); game.Dice.WhenRoll(6); Monster goblin = Monster.NewGoblin(game); goblin.Attack(wizard); wizard.IsDestroyed.Should().BeTrue("The goblin should have killed the wizard."); wizard.Treasure.Count.Should().Be(0); }
public void AMonsterSerioulyWoundsAHero() { Game game = GivenGame(); Hero wizard = GivenWizard(game); for (int i = 0; i < 7; ++i) { wizard.Treasure.Add(new Treasure()); } wizard.Move(); wizard.Move(); game.Dice.WhenRoll(5); game.Dice.WhenRoll(6); Monster goblin = Monster.NewGoblin(game); goblin.Attack(wizard); wizard.Treasure.Count.Should().Be(3); wizard.LostTurns.Should().Be(0); wizard.Space.Should().Be(game.Board.Start); }
private void MonsterAction(Monster monster) { var offset = monster.Position.GetOffsetTowards(_yoloTeam.Position); var nextPosition = monster.Position + offset; var nextTile = _room.Tiles[nextPosition.X, nextPosition.Y]; if (nextTile.Type == TileType.Wall) { return; } if (nextPosition.Equals(_yoloTeam.Position)) { monster.Attack(_yoloTeam); _logger.LogFight(monster, _yoloTeam); return; } monster.Move(offset); }
public void MonsterSecond() { System.Random rd = new System.Random(); for (int i = 0; i < monster.atktime; i++) { if (monster.list[i].type == (int)SkillType.NearAT || monster.list[i].type == (int)SkillType.FarAT || monster.list[i].type == (int)SkillType.Magic) { double extra = rd.Next(90, 110) / 100.0; int damage = (int)(monster.list[i].skillpower * monster.atkall * extra * (1 - 0.2f * team.guardlevel)); team.nowhp -= damage; team.nowhp = Math.Max(0, team.nowhp); DamagePopUp.Create(DamageEffect, MsDamage, damage, transform); audiosr.PlayOneShot(audiohit); UpdateUsHp(); } else if (monster.list[i].type == (int)SkillType.Heal) { double extra = rd.Next(90, 110) / 100.0; monster.nowhp += (int)(monster.list[i].skillpower * monster.atkall * extra); UpdateMsHp(); } } monster.Attack(); }
/// <summary> /// Attack Logic method for monsters, attacks the character and finds a new target if the character it waas attacking got downed /// </summary> private void MonsterAttackLogic() { // cast both the owner and target so we can access the Character / Monster properties Monster owner_cast = owner as Monster; Character target_cast = targetedObject as Character; owner_cast.Attack(); // The Character is downed so we want to target a new Character if (target_cast.IsDowned) { foreach (Character target in targetList.Children) { // If the target is down, we do not want to target it so we continue to the next iteration in the loop. if (target.IsDowned) { continue; } else { targetedObject = target; } } } }
void AddAttack() { mOwner.Attack(1.0f); }
public void Open() { m.Attack(); }
public void BlockAbilityUnitTest() { Player player = new Player("test", PlayerClassType.Warrior) { MaxRagePoints = 100, RagePoints = 100, InCombat = true, MaxHitPoints = 100, HitPoints = 100, DodgeChance = 0, Level = 3 }; OutputHelper.Display.ClearUserOutput(); Monster monster = new Monster(3, MonsterType.Zombie) { HitPoints = 100, MaxHitPoints = 100, InCombat = true }; MonsterBuilder.BuildMonster(monster); monster.MonsterWeapon.CritMultiplier = 1; int abilityIndex = player.Abilities.FindIndex( f => f.WarAbilityCategory == WarriorAbility.Block); string[] inputInfo = new[] { "ability", "block" }; PlayerHelper.AbilityInfo(player, inputInfo); Assert.AreEqual("Block", OutputHelper.Display.Output[0][2]); Assert.AreEqual("Rank: 1", OutputHelper.Display.Output[1][2]); Assert.AreEqual("Rage Cost: 25", OutputHelper.Display.Output[2][2]); Assert.AreEqual("Block Damage: 50", OutputHelper.Display.Output[3][2]); const string blockInfoString = "Block damage will prevent incoming damage from opponent until block damage is used up."; Assert.AreEqual(blockInfoString, OutputHelper.Display.Output[4][2]); string[] input = new[] { "use", "block" }; string abilityName = InputHelper.ParseInput(input); Assert.AreEqual("block", abilityName); player.UseAbility(monster, input); int?rageCost = player.Abilities[abilityIndex].RageCost; Assert.AreEqual(player.MaxRagePoints - rageCost, player.RagePoints); int blockAmount = player.Abilities[abilityIndex].Defensive.BlockDamage; string blockString = $"You start blocking your opponent's attacks! You will block {blockAmount} damage."; Assert.AreEqual(blockString, OutputHelper.Display.Output[5][2]); OutputHelper.Display.ClearUserOutput(); Assert.AreEqual(true, player.Effects[0] is BlockDamageEffect); Assert.AreEqual(player.MaxHitPoints, player.HitPoints); BlockDamageEffect blockDmgEffect = player.Effects[0] as BlockDamageEffect; int blockAmountRemaining = blockDmgEffect.BlockAmount; Assert.AreEqual(blockAmount, blockAmountRemaining); int i = 0; while (blockAmountRemaining > 0) { monster.MonsterWeapon.Durability = 100; int blockAmountBefore = blockAmountRemaining; monster.Attack(player); blockAmountRemaining = player.Effects.Any() ? blockDmgEffect.BlockAmount : 0; if (blockAmountRemaining > 0) { Assert.AreEqual(player.MaxHitPoints, player.HitPoints); string blockRoundString = $"Your defensive move blocked {(blockAmountBefore - blockAmountRemaining)} damage!"; Assert.AreEqual(blockRoundString, OutputHelper.Display.Output[i + (i * 1)][2]); } else { GameHelper.RemovedExpiredEffectsAsync(player); int attackAmount = monster.MonsterWeapon.Attack() - blockAmountBefore; Assert.AreEqual(player.MaxHitPoints - attackAmount, player.HitPoints); const string blockEndString = "You are no longer blocking damage!"; Assert.AreEqual(blockEndString, OutputHelper.Display.Output[i + 3][2]); Thread.Sleep(1000); Assert.AreEqual(false, player.Effects.Any()); string hitString = $"The {monster.Name} hits you for {attackAmount} physical damage."; Assert.AreEqual(hitString, OutputHelper.Display.Output[i + 4][2]); } i++; } }
private void Button_Attack_Click(object sender, RoutedEventArgs e) { currentPlayer = (Player)playerQueue.Dequeue(); //int i = 0; //while (currentPlayer.Health<=0 && i <4) //{ // i++; // if (i== 4) // { // GameOver gameOver = new GameOver(); // gameOver.ShowDialog(); // } // currentPlayer = (Player)playerQueue.Dequeue(); //} //if (playerDeaths == 4) //{ // GameOver gameOver = new GameOver(); // gameOver.ShowDialog(); //} playerQueue.Enqueue(currentPlayer); if (currentPlayer.Health > 0) { Label_Info.Content = currentPlayer.Attack(currentMonster); Label_MonsterHealth.Content = $"Health:{currentMonster.Health}"; if (currentMonster.Health > 0) { Random rand = new Random(); int random = rand.Next(1, 5); switch (random) { case 1: Label_Info.Content += Environment.NewLine + (currentMonster.Attack(playerOne)); Label_P1Health.Content = $"Health :{playerOne.Health}"; Label_P1Name.Content = playerOne.Name; if (playerOne.Health < 0) { Label_P1Health.Content = "DEAD"; playerDeaths++; } break; case 2: Label_Info.Content += Environment.NewLine + (currentMonster.Attack(playerTwo)); Label_P2Name.Content = playerTwo.Name; Label_P2Health.Content = $"Health :{playerTwo.Health}"; if (playerTwo.Health < 0) { Label_P2Health.Content = "DEAD"; playerDeaths++; } break; case 3: Label_Info.Content += Environment.NewLine + (currentMonster.Attack(playerThree)); Label_P3Name.Content = playerThree.Name; Label_P3Health.Content = $"Health :{playerThree.Health}"; if (playerThree.Health < 0) { Label_P3Health.Content = "DEAD"; playerDeaths++; } break; case 4: Label_Info.Content += Environment.NewLine + (currentMonster.Attack(playerFour)); Label_P4Name.Content = playerFour.Name; Label_P4Health.Content = $"Health :{playerFour.Health}"; if (playerFour.Health < 0) { Label_P4Health.Content = "DEAD"; playerDeaths++; } break; } } else { killCount++; Label_Kills.Content = $"Monster Kills: {killCount}"; currentMonster = dm.RandomMonster(); Label_MonsterName.Content = $"Monster: {currentMonster.Name}"; Label_MonsterHealth.Content = $"Health:{currentMonster.Health}"; } turnsPassed++; Label_Current_Turn.Content = $"Turn: {turnsPassed}"; } }
public static void StartCombat(Player player, Monster monster) { Console.Clear(); string fightStartString = $"{player.Name}, you have encountered a {monster.Name}. Time to fight!"; OutputHelper.Display.StoreUserOutput( Settings.FormatSuccessOutputText(), Settings.FormatDefaultBackground(), fightStartString); while (monster.HitPoints > 0 && player.HitPoints > 0 && player.InCombat && monster.InCombat) { GameHelper.RemovedExpiredEffectsAsync(player); GameHelper.RemovedExpiredEffectsAsync(monster); bool isInputValid = false; // Get input and check to see if input is valid, and if not, keep trying to get input from user while (!isInputValid) { // Show initial output that announces start of fight OutputHelper.ShowUserOutput(player, monster); OutputHelper.Display.ClearUserOutput(); // Player will attack, use ability, cast spells, etc. to cause damage _input = InputHelper.GetFormattedInput(Console.ReadLine()); Console.Clear(); isInputValid = ProcessPlayerInput(player, monster); } if (player.Effects.Any()) { ProcessPlayerEffects(player); } if (_fleeSuccess) { return; } // Check to see if player attack killed monster if (monster.HitPoints <= 0) { monster.MonsterDeath(player); return; } if (monster.Effects.Any()) { ProcessOpponentEffects(monster); } // Check to see if damage over time effects killed monster if (monster.HitPoints <= 0) { monster.MonsterDeath(player); return; } if (monster.IsStunned) { continue; } monster.Attack(player); // Check at end of round to see if monster was killed by combat round if (monster.HitPoints > 0) { continue; } monster.MonsterDeath(player); return; } }
void Update() { switch (StateMachine.GetCurrentStateName("Round")) { case "RoundStart": if (isPlayerTurn) { isPlayerTurn = false; } else { isPlayerTurn = true; } StateMachine.ChangeState("Round", "BeforeAttack"); break; case "BeforeAttack": StateMachine.ChangeState("Round", "Attack"); break; case "Attack": bool ret; if (isPlayerTurn) { ret = player.Attack(monster); } else { ret = monster.Attack(player); } if (battleSound && Game.sound && !pass) { battleSound.Play(); } if (ret) { StateMachine.ChangeState("Round", "BeforeDamage"); } else { StateMachine.ChangeState("Round", "AfterAttack"); } break; case "BeforeDamage": StateMachine.ChangeState("Round", "Damaged"); break; case "Damaged": Damage.AciveAllDamages(); StateMachine.ChangeState("Round", "AfterDamage"); break; case "AfterDamage": StateMachine.ChangeState("Round", "AfterAttack"); break; case "AfterAttack": if (monster.hpComponent.GetCurrentHp() <= 0) { StateMachine.ChangeState("Round", "BattleEnd"); StateMachine.ChangeState("Battle", "Win"); } else if (player.hpComponent.GetCurrentHp() <= 0) { StateMachine.ChangeState("Round", "BattleEnd"); StateMachine.ChangeState("Battle", "Fail"); } else { StateMachine.ChangeState("Round", "RoundEnd"); } break; case "RoundEnd": if (UnityEngine.Time.time - lastRoundTime > roundSpace || pass) { StateMachine.ChangeState("Round", "RoundStart"); } else { StateMachine.ChangeState("Round", "RoundWait"); } //StateMachine.ChangeState("Round", "BattleEnd"); break; case "RoundWait": if (UnityEngine.Time.time - lastRoundTime > roundSpace) { StateMachine.ChangeState("Round", "RoundStart"); } break; default: break; } }
public void FrostboltSpellUnitTest() { Player player = new Player("test", PlayerClassType.Mage) { HitPoints = 200, MaxHitPoints = 200, FrostResistance = 0 }; OutputHelper.Display.ClearUserOutput(); Monster monster = new Monster(1, MonsterType.Skeleton); while (monster.SkeletonCategory != SkeletonType.Mage) { monster = new Monster(1, MonsterType.Skeleton); } MonsterBuilder.BuildMonster(monster); monster.MonsterWeapon.CritMultiplier = 1; // Remove crit chance to remove "noise" in test int spellIndex = monster.Spellbook.FindIndex( f => f.SpellCategory == SpellType.Frostbolt); foreach (IItem item in player.Inventory.Where(item => item is IEquipment eItem && eItem.Equipped)) { IEquipment eItem = item as IEquipment; eItem.Equipped = false; } monster.Spellbook[spellIndex].CastFrostOffense(monster, player, spellIndex); int spellCost = monster.Spellbook[spellIndex].EnergyCost; Assert.AreEqual(monster.MaxEnergyPoints - spellCost, monster.EnergyPoints); int spellDamage = monster.Spellbook[spellIndex].Offensive.Amount; Assert.AreEqual(player.MaxHitPoints - spellDamage, player.HitPoints); int spellMaxRounds = monster.Spellbook[spellIndex].Offensive.AmountMaxRounds; Assert.AreEqual(spellMaxRounds, player.Effects[0].MaxRound); string attackString = $"The {monster.Name} conjures up a frostbolt and launches it at you!"; Assert.AreEqual(attackString, OutputHelper.Display.Output[0][2]); string attackSuccessString = $"The {monster.Name} hits you for {spellDamage} frost damage."; Assert.AreEqual(attackSuccessString, OutputHelper.Display.Output[1][2]); const string frozenString = "You are frozen. Physical, frost and arcane damage to you will be increased by 50%!"; Assert.AreEqual(frozenString, OutputHelper.Display.Output[2][2]); Assert.AreEqual(true, player.Effects[0] is FrozenEffect); FrozenEffect frozenEffect = player.Effects[0] as FrozenEffect; // Remove all spells after casting to make monster decide to use physical attack for unit test monster.Spellbook = null; for (int i = 2; i < 4; i++) { int playerHitPointsBefore = player.HitPoints; double multiplier = frozenEffect.EffectMultiplier; int baseDamage = monster.MonsterWeapon.RegDamage; int frozenDamage = (int)(monster.MonsterWeapon.RegDamage * multiplier); Assert.AreEqual(frozenDamage, baseDamage * multiplier, 1); monster.MonsterWeapon.Durability = 100; monster.Attack(player); Assert.AreEqual(i, player.Effects[0].CurrentRound); Assert.AreEqual(frozenString, OutputHelper.Display.Output[i][2]); Assert.AreEqual(playerHitPointsBefore - frozenDamage, player.HitPoints, 7); } GameHelper.RemovedExpiredEffectsAsync(player); Thread.Sleep(1000); Assert.AreEqual(false, player.Effects.Any()); }
private static async void MobTimer() { while (true) { int Time = Environment.TickCount; foreach (Mapping.Map M in Kernel.Maps.Values) { if (M.Players.Count == 0) { continue; } foreach (Entities.Monster Monster in M.Monsters.Values) { if (Monster.HitPoints == 0) { if (Monster.OnScreen && Monster.DeathStamp + 2000 < Time) { Monster.OnScreen = false; foreach (SocketClient Client in Monster.Screen.Values) { Client.Character.Screen.Remove(Monster.UniqueID); } } else if (Monster.DeathStamp + Monster.RespawnDelay < Time) { Monster.HitPoints = Monster.Info.MaxHealth; Monster.OnScreen = true; int X, Y; Monster.Spawn.GetLocation(out X, out Y); Monster.X = (ushort)X; Monster.Y = (ushort)Y; byte[] Data = Packets.ToSend.StringPacket(Monster.UniqueID, 10, 1, "MBStandard"); foreach (SocketClient Client in Monster.Screen.Values) { if (Calculations.GetDistance(Client.Character.X, Client.Character.Y, Monster.X, Monster.Y) <= Constants.ScreenDistance) { Client.Character.Screen.Insert(Monster); if (!Client.Lagging) { Client.Send(Data); } } } } } else if (Monster.Target != null) { if (!Monster.Target.Character.Dead) { double dist = Calculations.GetDistance(Monster.X, Monster.Y, Monster.Target.Character.X, Monster.Target.Character.Y); if (dist <= Monster.Info.ViewRange && !Monster.Info.IsGuard) { if (dist <= Monster.Info.AttackRange) { Monster.Attack(); } else { byte ToDir = (byte)(((7 - (Math.Floor(Calculations.Direction(Monster.X, Monster.Y, Monster.Target.Character.X, Monster.Target.Character.Y) / 45 % 8)) - 1 % 8)) % 8); Monster.Walk(ToDir); } } } else if (Monster.X != Monster.SpawnX && Monster.Y != Monster.SpawnY) { byte ToDir = (byte)(((7 - (Math.Floor(Calculations.Direction(Monster.X, Monster.Y, Monster.SpawnX, Monster.SpawnY) / 45 % 8)) - 1 % 8)) % 8); Monster.Walk(ToDir); } } } } await Task.Delay(1000); } }
void AddAttack() { mOwner.Attack(0.5f); }
public override void Update(TimeSpan elapsedTime) { if (Monster != null && Monster.isAlive) { Monster.WalkTimer.Update(elapsedTime); Monster.BashTimer.Update(elapsedTime); if (Monster.Target != null) { if (Monster.Target is Aisling) { if ((Monster.Target as Aisling).Invisible) { Monster.Target = null; } } } if (Monster.BashTimer.Elapsed) { if (Monster.BashEnabled) { if (Monster.Target == null) { Monster.BashEnabled = false; } else { int direction; if (this.Monster.Facing(Monster.Target.X, Monster.Target.Y, out direction)) { Monster.Attack(); } else { if (!this.Monster.Facing(Monster.Target.X, Monster.Target.Y, out direction)) { this.Monster.Direction = (byte)direction; this.Monster.Turn(); } } } } Monster.BashTimer.Reset(); } if (Monster.WalkTimer.Elapsed) { if (Monster.WalkEnabled && !Monster.Attacked) { Monster.Wander(); } else { if (Monster.Target != null) { if (this.Monster.NextTo(Monster.Target.X, Monster.Target.Y)) { int direction; if (this.Monster.Facing(Monster.Target.X, Monster.Target.Y, out direction)) { this.Monster.BashEnabled = true; this.Monster.CastEnabled = true; } else { this.Monster.BashEnabled = false; this.Monster.CastEnabled = true; this.Monster.Direction = (byte)direction; this.Monster.Turn(); } } else { int direction; if (!this.Monster.Facing(Monster.Target.X, Monster.Target.Y, out direction)) { this.Monster.Direction = (byte)direction; this.Monster.Turn(); } this.Monster.BashEnabled = false; this.Monster.CastEnabled = false; this.Monster.WalkTo(Monster.Target.X, Monster.Target.Y); } } } Monster.WalkTimer.Reset(); } } }
public void execute(Player player, Monster monster) { monster.Attack(player); //player.Life -= monster.damagePoints; }