Exemplo n.º 1
0
        public void ExecuteThrowWeeklyArenaStateNotContainsAvatarAddressException()
        {
            var targetAddress = _avatar2Address;

            var previousWeeklyArenaState = _initialState.GetWeeklyArenaState(_weeklyArenaAddress);

            previousWeeklyArenaState.Remove(targetAddress);

            var previousState = _initialState.SetState(
                _weeklyArenaAddress,
                previousWeeklyArenaState.Serialize());

            var action = new RankingBattle9
            {
                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,
                });
            });
        }
Exemplo n.º 2
0
        public void Rehearsal()
        {
            var action = new RankingBattle9
            {
                avatarAddress      = _avatar1Address,
                enemyAddress       = _avatar2Address,
                weeklyArenaAddress = _weeklyArenaAddress,
                costumeIds         = new List <Guid>(),
                equipmentIds       = new List <Guid>(),
                consumableIds      = new List <Guid>(),
            };

            var updatedAddresses = new List <Address>()
            {
                _avatar1Address,
                _weeklyArenaAddress,
                _avatar1Address.Derive(LegacyInventoryKey),
                _avatar1Address.Derive(LegacyWorldInformationKey),
                _avatar1Address.Derive(LegacyQuestListKey),
            };

            var state = new State();

            var nextState = action.Execute(new ActionContext()
            {
                PreviousStates = state,
                Signer         = _agent1Address,
                BlockIndex     = 0,
                Rehearsal      = true,
            });

            Assert.Equal(updatedAddresses.ToImmutableHashSet(), nextState.UpdatedAddresses);
        }
Exemplo n.º 3
0
        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 RankingBattle9
            {
                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,
                });
            });
        }
Exemplo n.º 4
0
        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.AddItem(equipment);
            }

            var state = _initialState.SetState(_avatar1Address, previousAvatarState.Serialize());

            var action = new RankingBattle9
            {
                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,
            }));
        }
Exemplo n.º 5
0
        public void ExecuteThrowFailedLoadStateException(int caseIndex)
        {
            Address signer        = default;
            Address avatarAddress = default;
            Address enemyAddress  = default;

            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 RankingBattle9
            {
                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,
                });
            });
        }
Exemplo n.º 6
0
        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 RankingBattle9
            {
                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,
                });
            });
        }
Exemplo n.º 7
0
        public void ExecuteThrowInvalidAddressException()
        {
            var action = new RankingBattle9
            {
                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,
                });
            });
        }
Exemplo n.º 8
0
        public void Execute(bool isNew, bool avatarBackward, bool enemyBackward)
        {
            var previousWeeklyState  = _initialState.GetWeeklyArenaState(0);
            var previousAvatar1State = _initialState.GetAvatarState(_avatar1Address);

            previousAvatar1State.level = 10;
            var prevScore = previousWeeklyState[_avatar1Address].Score;

            if (isNew)
            {
                previousWeeklyState.Remove(_avatar1Address);
            }

            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.AddItem(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.AddItem(enemyCostume);

            if (avatarBackward)
            {
                previousState =
                    previousState.SetState(_avatar1Address, previousAvatar1State.Serialize());
            }
            else
            {
                previousState = previousState
                                .SetState(
                    _avatar1Address.Derive(LegacyInventoryKey),
                    previousAvatar1State.inventory.Serialize())
                                .SetState(
                    _avatar1Address.Derive(LegacyWorldInformationKey),
                    previousAvatar1State.worldInformation.Serialize())
                                .SetState(
                    _avatar1Address.Derive(LegacyQuestListKey),
                    previousAvatar1State.questList.Serialize())
                                .SetState(_avatar1Address, previousAvatar1State.SerializeV2());
            }

            if (enemyBackward)
            {
                previousState =
                    previousState.SetState(_avatar2Address, enemyAvatarState.Serialize());
            }
            else
            {
                previousState = previousState
                                .SetState(
                    _avatar2Address.Derive(LegacyInventoryKey),
                    enemyAvatarState.inventory.Serialize())
                                .SetState(
                    _avatar2Address.Derive(LegacyWorldInformationKey),
                    enemyAvatarState.worldInformation.Serialize())
                                .SetState(
                    _avatar2Address.Derive(LegacyQuestListKey),
                    enemyAvatarState.questList.Serialize())
                                .SetState(_avatar2Address, enemyAvatarState.SerializeV2());
            }

            var action = new RankingBattle9
            {
                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.GetAvatarStateV2(_avatar1Address);
            var nextWeeklyState  = nextState.GetWeeklyArenaState(0);

            Assert.Contains(nextAvatar1State.inventory.Materials, i => itemIds.Contains(i.Id));
            Assert.NotNull(action.Result);
            Assert.NotNull(action.ArenaInfo);
            Assert.NotNull(action.EnemyArenaInfo);
            Assert.NotNull(action.EnemyAvatarState);
            Assert.Contains(typeof(GetReward), action.Result.Select(e => e.GetType()));
            Assert.Equal(BattleLog.Result.Win, action.Result.result);
            Assert.True(nextWeeklyState[_avatar1Address].Score > prevScore);

            // Check simulation result equal.
            var simulator = new RankingSimulator(
                new TestRandom(),
                previousAvatar1State,
                action.EnemyAvatarState,
                action.consumableIds,
                _tableSheets.GetRankingSimulatorSheets(),
                RankingBattle9.StageId,
                action.ArenaInfo,
                action.EnemyArenaInfo,
                _tableSheets.CostumeStatSheet);

            simulator.Simulate();

            BattleLog log    = simulator.Log;
            BattleLog result = action.Result;

            Assert.Equal(result.score, log.score);
            Assert.Equal(result.Count, log.Count);
            Assert.Equal(result.result, log.result);
        }