Exemplo n.º 1
0
        public int MonsterCollect(
            [Range(0, 7)] int level,
            [Argument("PATH", Description = "A file path of base64 encoded action.")] string filePath
            )
        {
            try
            {
                Nekoyume.Action.MonsterCollect action = new MonsterCollect
                {
                    level = level
                };
                var encoded = new List(
                    new[]
                {
                    (Text)nameof(Nekoyume.Action.MonsterCollect),
                    action.PlainValue
                }
                    );

                byte[] raw = Codec.Encode(encoded);
                File.WriteAllText(filePath, Convert.ToBase64String(raw));
                return(0);
            }
            catch (Exception e)
            {
                _console.Error.WriteLine(e);
                return(-1);
            }
        }
Exemplo n.º 2
0
        public void MonsterCollect()
        {
            var filePath   = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
            var resultCode = _command.MonsterCollect(1, filePath);

            Assert.Equal(0, resultCode);
            var    rawAction = Convert.FromBase64String(File.ReadAllText(filePath));
            var    decoded   = (List)_codec.Decode(rawAction);
            string type      = (Text)decoded[0];

            Assert.Equal(nameof(Nekoyume.Action.MonsterCollect), type);

            Dictionary plainValue = (Dictionary)decoded[1];
            var        action     = new MonsterCollect();

            action.LoadPlainValue(plainValue);
            Assert.Equal(1, action.level);
        }
Exemplo n.º 3
0
        public void Execute(int balance, int?prevLevel, int level, long blockIndex, Type exc, int?expectedStakings)
        {
            Address            monsterCollectionAddress = MonsterCollectionState.DeriveAddress(_signer, 0);
            Currency           currency   = _initialState.GetGoldCurrency();
            FungibleAssetValue balanceFav = currency * balance;
            FungibleAssetValue staked     = currency * 0;

            if (prevLevel is { } prevLevelNotNull)
            {
                List <MonsterCollectionRewardSheet.RewardInfo> rewards = _tableSheets.MonsterCollectionRewardSheet[prevLevelNotNull].Rewards;
                var prevMonsterCollectionState = new MonsterCollectionState(
                    address: monsterCollectionAddress,
                    level: prevLevelNotNull,
                    blockIndex: 0,
                    monsterCollectionRewardSheet: _tableSheets.MonsterCollectionRewardSheet
                    );
                _initialState = _initialState.SetState(monsterCollectionAddress, prevMonsterCollectionState.Serialize());
                for (int i = 0; i < prevLevel; i++)
                {
                    MonsterCollectionSheet.Row row = _tableSheets.MonsterCollectionSheet[i + 1];
                    staked       += row.RequiredGold * currency;
                    _initialState = _initialState.MintAsset(monsterCollectionAddress, row.RequiredGold * currency);
                }
            }

            balanceFav -= staked;

            _initialState = _initialState.MintAsset(_signer, balanceFav);
            var action = new MonsterCollect
            {
                level = level,
            };

            if (exc is { } excType)
            {
                Assert.Throws(excType, () => action.Execute(new ActionContext
                {
                    PreviousStates = _initialState,
                    Signer         = _signer,
                    BlockIndex     = blockIndex,
                }));
            }