Exemple #1
0
        public void Rehearsal()
        {
            var action = new RankingBattle
            {
                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);
        }
Exemple #2
0
        public void SerializeWithDotnetAPI()
        {
            var action = new RankingBattle
            {
                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 = (RankingBattle)formatter.Deserialize(ms);

            Assert.Equal(action.PlainValue, deserialized.PlainValue);
        }
Exemple #3
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 RankingBattle
            {
                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,
                });
            });
        }
Exemple #4
0
        public void ExecuteThrowWeeklyArenaStateAlreadyEndedException()
        {
            var previousWeeklyArenaState = _initialState.GetWeeklyArenaState(_weeklyArenaAddress);

            previousWeeklyArenaState.Ended = true;

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

            var action = new RankingBattle
            {
                AvatarAddress      = _avatar1Address,
                EnemyAddress       = _avatar2Address,
                WeeklyArenaAddress = _weeklyArenaAddress,
                costumeIds         = new List <int>(),
                equipmentIds       = new List <Guid>(),
                consumableIds      = new List <Guid>(),
            };

            Assert.Throws <WeeklyArenaStateAlreadyEndedException>(() =>
            {
                action.Execute(new ActionContext()
                {
                    PreviousStates = previousState,
                    Signer         = _agent1Address,
                    Random         = new ItemEnhancementTest.TestRandom(),
                    Rehearsal      = false,
                });
            });
        }
Exemple #5
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 RankingBattle
            {
                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,
                });
            });
        }
Exemple #6
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 RankingBattle
            {
                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 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 action = new RankingBattle
            {
                AvatarAddress      = _avatar1Address,
                EnemyAddress       = _avatar2Address,
                WeeklyArenaAddress = _weeklyArenaAddress,
                costumeIds         = new List <int>(),
                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);
        }
        public void ExecuteThrowNotEnoughFungibleAssetValueException()
        {
            var previousWeeklyArenaState = _initialState.GetWeeklyArenaState(_weeklyArenaAddress);
            var arenaInfo = previousWeeklyArenaState.GetArenaInfo(_avatar1Address);

            previousWeeklyArenaState.Update(new ArenaInfo(arenaInfo));

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

            var goldCurrency           = new Currency("NCG", 2, Addresses.GoldCurrency);
            var previousAgentGoldState = _initialState.GetBalance(
                _agent1Address,
                goldCurrency);

            if (previousAgentGoldState.Sign > 0)
            {
                previousState = _initialState.TransferAsset(
                    _agent1Address,
                    Addresses.GoldCurrency,
                    previousAgentGoldState);
            }

            var action = new RankingBattle
            {
                AvatarAddress      = _avatar1Address,
                EnemyAddress       = _avatar2Address,
                WeeklyArenaAddress = _weeklyArenaAddress,
                costumeIds         = new List <int>(),
                equipmentIds       = new List <Guid>(),
                consumableIds      = new List <Guid>(),
            };

            Assert.Throws <NotEnoughFungibleAssetValueException>(() =>
            {
                action.Execute(new ActionContext()
                {
                    PreviousStates = previousState,
                    Signer         = _agent1Address,
                    Random         = new TestRandom(),
                    Rehearsal      = false,
                });
            });
        }
Exemple #9
0
        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 RankingBattle
            {
                AvatarAddress      = _avatar1Address,
                EnemyAddress       = _avatar2Address,
                WeeklyArenaAddress = _weeklyArenaAddress,
                costumeIds         = new List <int>(),
                equipmentIds       = new List <Guid>(),
                consumableIds      = new List <Guid>(),
            };

            Assert.Throws <WeeklyArenaStateNotContainsAvatarAddressException>(() =>
            {
                action.Execute(new ActionContext()
                {
                    PreviousStates = previousState,
                    Signer         = _agent1Address,
                    Random         = new ItemEnhancementTest.TestRandom(),
                    Rehearsal      = false,
                });
            });
        }
Exemple #10
0
        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 RankingBattle
            {
                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,
                });
            });
        }
Exemple #11
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 RankingBattle
            {
                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,
                });
            });
        }
Exemple #12
0
        public void ExecuteThrowInvalidAddressException()
        {
            var action = new RankingBattle
            {
                avatarAddress      = _avatar1Address,
                enemyAddress       = _avatar1Address,
                weeklyArenaAddress = _weeklyArenaAddress,
                costumeIds         = new List <Guid>(),
                equipmentIds       = new List <Guid>(),
            };

            Assert.Throws <InvalidAddressException>(() =>
            {
                action.Execute(new ActionContext
                {
                    PreviousStates = _initialState,
                    Signer         = _agent1Address,
                    Random         = new TestRandom(),
                    Rehearsal      = false,
                });
            });
        }
Exemple #13
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 RankingBattle
            {
                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.Contains(typeof(GetReward), action.Result.Select(e => e.GetType()));
            Assert.Equal(BattleLog.Result.Win, action.Result.result);
            Assert.True(nextWeeklyState[_avatar1Address].Score > prevScore);
        }
Exemple #14
0
        public void Execute_Backward_Compatible(bool isNew, bool avatarBackward, bool enemyBackward)
        {
            var previousWeeklyState  = _initialState.GetWeeklyArenaState(ArenaIndex);
            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);

            Address worldInformationAddress = _avatar1Address.Derive(LegacyWorldInformationKey);

            if (avatarBackward)
            {
                previousState =
                    previousState.SetState(_avatar1Address, previousAvatar1State.Serialize());
            }
            else
            {
                previousState = previousState
                                .SetState(
                    _avatar1Address.Derive(LegacyInventoryKey),
                    previousAvatar1State.inventory.Serialize())
                                .SetState(
                    worldInformationAddress,
                    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 RankingBattle
            {
                avatarAddress      = _avatar1Address,
                enemyAddress       = _avatar2Address,
                weeklyArenaAddress = _weeklyArenaAddress,
                costumeIds         = new List <Guid> {
                    costume.ItemId
                },
                equipmentIds = new List <Guid>(),
            };

            var nextState = action.Execute(new ActionContext
            {
                PreviousStates = previousState,
                Signer         = _agent1Address,
                Random         = new TestRandom(),
                Rehearsal      = false,
                BlockIndex     = RankingBattle.UpdateTargetBlockIndex - 1,
            });

            var nextAvatar1State = nextState.GetAvatarStateV2(_avatar1Address);
            var nextWeeklyState  = nextState.GetWeeklyArenaState(ArenaIndex);
            var nextArenaInfo    = nextWeeklyState[_avatar1Address];

            Assert.Contains(nextAvatar1State.inventory.Materials, i => itemIds.Contains(i.Id));
            Assert.NotNull(action.ArenaInfo);
            Assert.NotNull(action.EnemyArenaInfo);
            Assert.True(nextArenaInfo.Score > prevScore);

            // Check simulation result equal.
            var player = new Player(
                previousAvatar1State,
                _tableSheets.CharacterSheet,
                _tableSheets.CharacterLevelSheet,
                _tableSheets.EquipmentItemSetEffectSheet);
            var simulator = new RankingSimulator(
                new TestRandom(),
                player,
                action.EnemyPlayerDigest,
                new List <Guid>(),
                _tableSheets.GetRankingSimulatorSheets(),
                RankingBattle.StageId,
                action.ArenaInfo,
                action.EnemyArenaInfo,
                _tableSheets.CostumeStatSheet);

            simulator.Simulate();

            Assert.Equal(nextArenaInfo.Score, simulator.Log.score);
            Assert.Equal(previousAvatar1State.SerializeV2(), nextAvatar1State.SerializeV2());
            Assert.Equal(previousAvatar1State.worldInformation.Serialize(), nextAvatar1State.worldInformation.Serialize());
        }
        public void TargetBlock()
        {
            var rb = new RankingBattle
            {
                avatarAddress      = _avatar1Address,
                enemyAddress       = _avatar3Address,
                weeklyArenaAddress = _weeklyArenaAddress,
                costumeIds         = new List <Guid>(),
                equipmentIds       = new List <Guid>(),
            };

            var arenaInfoAddress  = _weeklyArenaAddress.Derive(_avatar1Address.ToByteArray());
            var arenaInfo2Address = _weeklyArenaAddress.Derive(_avatar2Address.ToByteArray());
            var arenaInfo3Address = _weeklyArenaAddress.Derive(_avatar3Address.ToByteArray());
            var listAddress       = _weeklyArenaAddress.Derive("address_list");

            Assert.False(_initialState.TryGetState(arenaInfoAddress, out Dictionary _));
            Assert.False(_initialState.TryGetState(arenaInfo2Address, out Dictionary _));
            Assert.False(_initialState.TryGetState(arenaInfo3Address, out Dictionary _));
            Assert.False(_initialState.TryGetState(listAddress, out List _));

            var testRandom = new TestRandom();
            var blockIndex = RankingBattle.UpdateTargetBlockIndex;
            var nextState  = rb.Execute(new ActionContext
            {
                PreviousStates = _initialState,
                Signer         = _agent1Address,
                Random         = testRandom,
                Rehearsal      = false,
                BlockIndex     = blockIndex,
            });

            Assert.True(nextState.TryGetState(arenaInfoAddress, out Dictionary rawInfo));
            Assert.True(nextState.TryGetState(arenaInfo3Address, out Dictionary _));
            Assert.True(nextState.TryGetState(listAddress, out List rawList));

            var info        = new ArenaInfo(rawInfo);
            var addressList = rawList.ToList(StateExtensions.ToAddress);

            Assert.Equal(4, info.DailyChallengeCount);
            Assert.Contains(_avatar1Address, addressList);
            Assert.DoesNotContain(_avatar2Address, addressList);
            Assert.Contains(_avatar3Address, addressList);

            var rg = new RewardGold();

            var updatedState = rg.Execute(new ActionContext
            {
                PreviousStates = nextState,
                Signer         = _agent1Address,
                Random         = testRandom,
                Rehearsal      = false,
                BlockIndex     = blockIndex,
            });

            Assert.True(updatedState.TryGetState(arenaInfoAddress, out Dictionary updatedRawInfo));
            Assert.True(updatedState.TryGetState(arenaInfo2Address, out Dictionary _));
            Assert.True(updatedState.TryGetState(arenaInfo3Address, out Dictionary _));
            Assert.True(updatedState.TryGetState(listAddress, out List updatedRawList));

            var updatedInfo        = new ArenaInfo(updatedRawInfo);
            var updatedAddressList = updatedRawList.ToList(StateExtensions.ToAddress);

            Assert.Equal(5, updatedInfo.DailyChallengeCount);
            Assert.Contains(_avatar1Address, updatedAddressList);
            Assert.Contains(_avatar2Address, updatedAddressList);
            Assert.Contains(_avatar3Address, updatedAddressList);
        }
Exemple #16
0
        public void Execute()
        {
            var tableSheets  = TableSheets.FromTableSheetsState(_tableSheetsState);
            var itemId       = tableSheets.WeeklyArenaRewardSheet.Values.First().Reward.ItemId;
            var privateKey   = new PrivateKey();
            var agentAddress = privateKey.PublicKey.ToAddress();
            var agent        = new AgentState(agentAddress);

            var avatarAddress = agentAddress.Derive("avatar");
            var avatarState   = new AvatarState(avatarAddress, agentAddress, 0, tableSheets, new GameConfigState())
            {
                level = 10,
            };

            avatarState.worldInformation.ClearStage(
                1,
                GameConfig.RequireClearedStageLevel.ActionsInRankingBoard,
                1,
                tableSheets.WorldSheet,
                tableSheets.WorldUnlockSheet
                );
            agent.avatarAddresses.Add(0, avatarAddress);

            Assert.False(avatarState.inventory.HasItem(itemId));

            var avatarAddress2 = agentAddress.Derive("avatar2");
            var avatarState2   = new AvatarState(avatarAddress2, agentAddress, 0, tableSheets, new GameConfigState());

            avatarState2.worldInformation.ClearStage(
                1,
                GameConfig.RequireClearedStageLevel.ActionsInRankingBoard,
                1,
                tableSheets.WorldSheet,
                tableSheets.WorldUnlockSheet
                );
            agent.avatarAddresses.Add(1, avatarAddress);

            var weekly = new WeeklyArenaState(0);

            weekly.Set(avatarState, tableSheets.CharacterSheet);
            weekly[avatarAddress].Activate();
            weekly.Set(avatarState2, tableSheets.CharacterSheet);
            weekly[avatarAddress2].Activate();

            var state = new State(ImmutableDictionary <Address, IValue> .Empty
                                  .Add(_tableSheetsState.address, _tableSheetsState.Serialize())
                                  .Add(weekly.address, weekly.Serialize())
                                  .Add(agentAddress, agent.Serialize())
                                  .Add(avatarAddress, avatarState.Serialize())
                                  .Add(avatarAddress2, avatarState2.Serialize()));

            var action = new RankingBattle
            {
                AvatarAddress      = avatarAddress,
                EnemyAddress       = avatarAddress2,
                WeeklyArenaAddress = weekly.address,
                costumeIds         = new List <int>(),
                equipmentIds       = new List <Guid>(),
                consumableIds      = new List <Guid>(),
            };

            Assert.Null(action.Result);

            var nextState = action.Execute(new ActionContext()
            {
                PreviousStates = state,
                Signer         = agentAddress,
                Random         = new ItemEnhancementTest.TestRandom(),
                Rehearsal      = false,
            });

            var newState = nextState.GetAvatarState(avatarAddress);

            var newWeeklyState = nextState.GetWeeklyArenaState(0);

            Assert.True(newState.inventory.HasItem(itemId));
            Assert.NotNull(action.Result);
            Assert.Contains(typeof(GetReward), action.Result.Select(e => e.GetType()));
            Assert.Equal(BattleLog.Result.Win, action.Result.result);
            Assert.True(newWeeklyState[avatarAddress].Score > weekly[avatarAddress].Score);
        }