public void ExecuteThrowWeeklyArenaStateAlreadyEndedException() { var previousWeeklyArenaState = _initialState.GetWeeklyArenaState(_weeklyArenaAddress); previousWeeklyArenaState.Ended = true; var previousState = _initialState.SetState( _weeklyArenaAddress, previousWeeklyArenaState.Serialize()); var action = new RankingBattle3 { AvatarAddress = _avatar1Address, EnemyAddress = _avatar2Address, WeeklyArenaAddress = _weeklyArenaAddress, costumeIds = new List <Guid>(), equipmentIds = new List <Guid>(), consumableIds = new List <Guid>(), }; Assert.Throws <WeeklyArenaStateAlreadyEndedException>(() => { action.Execute(new ActionContext() { PreviousStates = previousState, Signer = _agent1Address, Random = new TestRandom(), Rehearsal = false, }); }); }
public void SerializeWithDotnetAPI() { var action = new RankingBattle3 { AvatarAddress = _avatar1Address, EnemyAddress = _avatar2Address, WeeklyArenaAddress = _weeklyArenaAddress, costumeIds = new List <Guid>(), equipmentIds = new List <Guid>(), consumableIds = new List <Guid>(), }; action.Execute(new ActionContext() { PreviousStates = _initialState, Signer = _agent1Address, Random = new TestRandom(), Rehearsal = false, }); var formatter = new BinaryFormatter(); using var ms = new MemoryStream(); formatter.Serialize(ms, action); ms.Seek(0, SeekOrigin.Begin); var deserialized = (RankingBattle3)formatter.Deserialize(ms); Assert.Equal(action.PlainValue, deserialized.PlainValue); }
public void ExecuteThrowNotEnoughClearedStageLevelException() { var previousAvatar1State = _initialState.GetAvatarState(_avatar1Address); previousAvatar1State.worldInformation = new WorldInformation( 0, _tableSheets.WorldSheet, false ); var previousState = _initialState.SetState( _avatar1Address, previousAvatar1State.Serialize()); var action = new RankingBattle3 { AvatarAddress = _avatar1Address, EnemyAddress = _avatar2Address, WeeklyArenaAddress = _weeklyArenaAddress, costumeIds = new List <Guid>(), equipmentIds = new List <Guid>(), consumableIds = new List <Guid>(), }; Assert.Throws <NotEnoughClearedStageLevelException>(() => { action.Execute(new ActionContext() { PreviousStates = previousState, Signer = _agent1Address, Random = new TestRandom(), Rehearsal = false, }); }); }
public void MultipleEquipmentTest(ItemSubType type, int maxCount) { var previousAvatarState = _initialState.GetAvatarState(_avatar1Address); var maxLevel = _tableSheets.CharacterLevelSheet.Max(row => row.Value.Level); var expRow = _tableSheets.CharacterLevelSheet[maxLevel]; var maxLevelExp = expRow.Exp; previousAvatarState.level = maxLevel; previousAvatarState.exp = maxLevelExp; var weaponRows = _tableSheets .EquipmentItemSheet .Values .Where(r => r.ItemSubType == type) .Take(maxCount + 1); var equipments = new List <Guid>(); foreach (var row in weaponRows) { var equipment = ItemFactory.CreateItem( _tableSheets.EquipmentItemSheet[row.Id], new TestRandom()) as Equipment; equipments.Add(equipment.ItemId); previousAvatarState.inventory.AddItem2(equipment); } var state = _initialState.SetState(_avatar1Address, previousAvatarState.Serialize()); var action = new RankingBattle3 { AvatarAddress = _avatar1Address, EnemyAddress = _avatar2Address, WeeklyArenaAddress = _weeklyArenaAddress, costumeIds = new List <Guid>(), equipmentIds = equipments, consumableIds = new List <Guid>(), }; Assert.Null(action.Result); Assert.Throws <DuplicateEquipmentException>(() => action.Execute(new ActionContext { PreviousStates = state, Signer = _agent1Address, Random = new TestRandom(), Rehearsal = false, })); }
public void ExecuteThrowWeeklyArenaStateNotContainsAvatarAddressException( int caseIndex) { Address targetAddress; switch (caseIndex) { case 0: targetAddress = _avatar1Address; break; case 1: targetAddress = _avatar2Address; break; } var previousWeeklyArenaState = _initialState.GetWeeklyArenaState(_weeklyArenaAddress); previousWeeklyArenaState.Remove(targetAddress); var previousState = _initialState.SetState( _weeklyArenaAddress, previousWeeklyArenaState.Serialize()); var action = new RankingBattle3 { AvatarAddress = _avatar1Address, EnemyAddress = _avatar2Address, WeeklyArenaAddress = _weeklyArenaAddress, costumeIds = new List <Guid>(), equipmentIds = new List <Guid>(), consumableIds = new List <Guid>(), }; Assert.Throws <WeeklyArenaStateNotContainsAvatarAddressException>(() => { action.Execute(new ActionContext() { PreviousStates = previousState, Signer = _agent1Address, Random = new TestRandom(), Rehearsal = false, }); }); }
public void ExecuteThrowFailedLoadStateException(int caseIndex) { Address signer; Address avatarAddress; Address enemyAddress; switch (caseIndex) { case 0: signer = new PrivateKey().ToAddress(); avatarAddress = _avatar1Address; enemyAddress = _avatar2Address; break; case 1: signer = _agent1Address; avatarAddress = _avatar1Address; enemyAddress = new PrivateKey().ToAddress(); break; } var action = new RankingBattle3 { AvatarAddress = avatarAddress, EnemyAddress = enemyAddress, WeeklyArenaAddress = _weeklyArenaAddress, costumeIds = new List <Guid>(), equipmentIds = new List <Guid>(), consumableIds = new List <Guid>(), }; Assert.Throws <FailedLoadStateException>(() => { action.Execute(new ActionContext() { PreviousStates = _initialState, Signer = signer, Random = new TestRandom(), Rehearsal = false, }); }); }
public void ExecuteThrowNotEnoughWeeklyArenaChallengeCountException() { var previousAvatarState = _initialState.GetAvatarState(_avatar1Address); var previousWeeklyArenaState = _initialState.GetWeeklyArenaState(_weeklyArenaAddress); while (true) { var arenaInfo = previousWeeklyArenaState.GetArenaInfo(_avatar1Address); arenaInfo.UpdateV3(previousAvatarState, arenaInfo, BattleLog.Result.Lose); if (arenaInfo.DailyChallengeCount == 0) { break; } } var previousState = _initialState.SetState( _weeklyArenaAddress, previousWeeklyArenaState.Serialize()); var action = new RankingBattle3 { AvatarAddress = _avatar1Address, EnemyAddress = _avatar2Address, WeeklyArenaAddress = _weeklyArenaAddress, costumeIds = new List <Guid>(), equipmentIds = new List <Guid>(), consumableIds = new List <Guid>(), }; Assert.Throws <NotEnoughWeeklyArenaChallengeCountException>(() => { action.Execute(new ActionContext() { PreviousStates = previousState, Signer = _agent1Address, Random = new TestRandom(), Rehearsal = false, }); }); }
public void ExecuteThrowInvalidAddressException() { var action = new RankingBattle3 { AvatarAddress = _avatar1Address, EnemyAddress = _avatar1Address, WeeklyArenaAddress = _weeklyArenaAddress, costumeIds = new List <Guid>(), equipmentIds = new List <Guid>(), consumableIds = new List <Guid>(), }; Assert.Throws <InvalidAddressException>(() => { action.Execute(new ActionContext() { PreviousStates = _initialState, Signer = _agent1Address, Random = new TestRandom(), Rehearsal = false, }); }); }
public void Execute() { var previousWeeklyState = _initialState.GetWeeklyArenaState(0); var previousAvatar1State = _initialState.GetAvatarState(_avatar1Address); previousAvatar1State.level = 10; var previousState = _initialState.SetState( _avatar1Address, previousAvatar1State.Serialize()); var itemIds = _tableSheets.WeeklyArenaRewardSheet.Values .Select(r => r.Reward.ItemId) .ToList(); Assert.All(itemIds, id => Assert.False(previousAvatar1State.inventory.HasItem(id))); var row = _tableSheets.CostumeStatSheet.Values.First(r => r.StatType == StatType.ATK); var costume = (Costume)ItemFactory.CreateItem( _tableSheets.ItemSheet[row.CostumeId], new TestRandom()); costume.equipped = true; previousAvatar1State.inventory.AddItem2(costume); var row2 = _tableSheets.CostumeStatSheet.Values.First(r => r.StatType == StatType.DEF); var enemyCostume = (Costume)ItemFactory.CreateItem( _tableSheets.ItemSheet[row2.CostumeId], new TestRandom()); enemyCostume.equipped = true; var enemyAvatarState = _initialState.GetAvatarState(_avatar2Address); enemyAvatarState.inventory.AddItem2(enemyCostume); previousState = previousState .SetState(_avatar1Address, previousAvatar1State.Serialize()) .SetState(_avatar2Address, enemyAvatarState.Serialize()); var action = new RankingBattle3 { AvatarAddress = _avatar1Address, EnemyAddress = _avatar2Address, WeeklyArenaAddress = _weeklyArenaAddress, costumeIds = new List <Guid> { costume.ItemId }, equipmentIds = new List <Guid>(), consumableIds = new List <Guid>(), }; Assert.Null(action.Result); var nextState = action.Execute(new ActionContext() { PreviousStates = previousState, Signer = _agent1Address, Random = new TestRandom(), Rehearsal = false, }); var nextAvatar1State = nextState.GetAvatarState(_avatar1Address); var nextWeeklyState = nextState.GetWeeklyArenaState(0); Assert.Contains(nextAvatar1State.inventory.Materials, i => itemIds.Contains(i.Id)); Assert.NotNull(action.Result); Assert.Contains(typeof(GetReward), action.Result.Select(e => e.GetType())); Assert.Equal(BattleLog.Result.Win, action.Result.result); Assert.True(nextWeeklyState[_avatar1Address].Score > previousWeeklyState[_avatar1Address].Score); }