private void HandleBattle(BattleActorMessage message) { using(var container = GameLogic.Bootstrapper.BootstrapUnity()) { IPlugin battleInterop = container.Resolve<IPlugin>("JavascriptPlugin"); IJSScriptHelper scriptHelper = container.Resolve<IJSScriptHelper>(); IRandomHelper randomHelper = container.Resolve<IRandomHelper>(); Battle battle = new Battle(message.Teams, battleInterop, scriptHelper, randomHelper); List<string> battleLog = new List<string>(); while (battle.MoreThanOneTeamAlive()) { battle.TakeTurn(battleLog); } var winningTeam = battle.GetVictoriousTeam(); var losingTeam = battle.GetLosingTeam(); BattleEndMessage bem = new BattleEndMessage() { WinningUsers = winningTeam.Select(user => user.Name), LosingUsers = losingTeam.Select(user => user.Name) }; //SendMessageActor send bem } }
public void CalculateAllStats() { Battle battle = new Battle(new List<List<Character>>(), pluginInterop, scriptHelper, randomHelper); SpecificCharacter ch = new SpecificCharacter { Name = "test", Class = "Barbarian", Stats = new StatsObject { Level = 1, Strength = 10, HitPoints = 10, MagicPoints = 10 } }; StatsModifierCollection ret = battle.CalculateStats(ch); ret.HitPoints.Total.Should().Be(1400); ret.MagicPoints.Percent.Should().Be(180); }
public void CalculateStaticStatsTest() { Battle battle = new Battle(new List<List<Character>>(), pluginInterop, scriptHelper, randomHelper); SpecificCharacter ch = new SpecificCharacter { Name = "test", Class = "Archer", Personalities = "Brave1", Stats = new StatsObject { Level = 1, Constitution = 2, Intelligence = 3 } }; StatsModifierCollection ret = battle.CalculateStats(ch); ret.HitPoints.Total.Should().Be(142); ret.MagicPoints.Total.Should().Be(35); ret.Strength.Percent.Should().Be(5); }
public void MockedBattleCalculateStatsTest() { Mock<IPlugin> mockBattleInterop = new Mock<IPlugin>(); Mock<IJSScriptHelper> mockScriptHelper = new Mock<IJSScriptHelper>(); Mock<IRandomHelper> mockRandomHelper = new Mock<IRandomHelper>(); Mock<Jint.Engine> mockJintEngine = new Mock<Jint.Engine>(); Mock<JSEngine> mockEngine = new Mock<JSEngine>(mockJintEngine.Object); IEngine actualEngine = mockEngine.Object; mockBattleInterop.Setup(x => x.CreateEngineWithCommonScripts(It.IsAny<SpecificCharacter>())).Returns(mockEngine.Object); mockBattleInterop.Setup(x => x.InvokeFunctionWithHooks(mockEngine.Object, It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<SpecificCharacter>(), It.IsAny<StatsModifierCollection>())).Returns(new StatsModifierCollection { Agility = new StatsModifierObject { Percent = 5 } }); mockBattleInterop.Setup(x => x.InvokeFunction(mockEngine.Object, It.IsAny<string>(), It.IsAny<SpecificCharacter>(), It.IsAny<StatsModifierCollection>())).Returns(new StatsModifierCollection { Agility = new StatsModifierObject { Percent = 0 } }); mockBattleInterop.Setup(x => x.AddObjectToStatsModifierObject(It.IsAny<StatsModifierCollection>(), It.IsAny<StatsModifierCollection>())) .Returns((StatsModifierCollection a, StatsModifierCollection b) => a + b); mockScriptHelper.Setup(x => x.ExecuteScript(actualEngine, It.IsAny<string>(), It.IsAny<Dictionary<string, object>>())); Battle battle = new Battle(new List<List<Character>>(), mockBattleInterop.Object, mockScriptHelper.Object, mockRandomHelper.Object); SpecificCharacter ch = new SpecificCharacter { Name = "test", Class = "Archer1", Personalities = "Brave1;Haha;What", Stats = new StatsObject { Level = 1, Constitution = 2, Intelligence = 3 } }; StatsModifierCollection ret = battle.CalculateStats(ch); ret.Agility.Percent.Should().Be(40); mockBattleInterop.Verify(x => x.CreateEngineWithCommonScripts(It.IsAny<SpecificCharacter>()), Times.Exactly(1)); mockBattleInterop.Verify(x => x.InvokeFunctionWithHooks(mockEngine.Object, It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<SpecificCharacter>(), It.IsAny<StatsModifierCollection>()), Times.Exactly(8)); mockBattleInterop.Verify(x => x.AddObjectToStatsModifierObject(It.IsAny<StatsModifierCollection>(), It.IsAny<StatsModifierCollection>()), Times.Exactly(12)); mockScriptHelper.Verify(x => x.ExecuteScript(actualEngine, It.IsAny<string>(), It.IsAny<Dictionary<string, object>>()), Times.Exactly(4)); }