public void ExecuteThrowNotEnoughMaterialException() { var row = _tableSheets.ConsumableItemRecipeSheet.Values.First(); const int requiredStage = GameConfig.RequireClearedStageLevel.CombinationConsumableAction; for (var i = 1; i < requiredStage + 1; i++) { _avatarState.worldInformation.ClearStage(1, i, 0, _tableSheets.WorldSheet, _tableSheets.WorldUnlockSheet); } _initialState = _initialState .SetState(_avatarAddress, _avatarState.Serialize()) .SetState(_slotAddress, new CombinationSlotState(_slotAddress, requiredStage).Serialize()); var action = new CombinationConsumable() { AvatarAddress = _avatarAddress, recipeId = row.Id, slotIndex = 0, }; Assert.Throws <NotEnoughMaterialException>(() => action.Execute(new ActionContext() { PreviousStates = _initialState, Signer = _agentAddress, BlockIndex = 1, Random = _random, }) ); }
public void Execute() { var agentState = new AgentState(_agentAddress); agentState.avatarAddresses[0] = _avatarAddress; var gameConfigState = new GameConfigState(); var avatarState = new AvatarState( _avatarAddress, _agentAddress, 1, _tableSheets, gameConfigState ); var row = _tableSheets.ConsumableItemRecipeSheet.Values.First(); foreach (var materialInfo in row.Materials) { var materialRow = _tableSheets.MaterialItemSheet[materialInfo.Id]; var material = ItemFactory.CreateItem(materialRow); avatarState.inventory.AddItem(material, materialInfo.Count); } const int requiredStage = GameConfig.RequireClearedStageLevel.CombinationConsumableAction; for (var i = 1; i < requiredStage + 1; i++) { avatarState.worldInformation.ClearStage(1, i, 0, _tableSheets.WorldSheet, _tableSheets.WorldUnlockSheet); } var initialState = new State() .SetState(_agentAddress, agentState.Serialize()) .SetState(_avatarAddress, avatarState.Serialize()) .SetState(_slotAddress, new CombinationSlotState(_slotAddress, requiredStage).Serialize()) .SetState(TableSheetsState.Address, _tableSheetsState.Serialize()); var action = new CombinationConsumable() { AvatarAddress = _avatarAddress, recipeId = row.Id, slotIndex = 0, }; var nextState = action.Execute(new ActionContext() { PreviousStates = initialState, Signer = _agentAddress, BlockIndex = 1, Random = _random, }); var slotState = nextState.GetCombinationSlotState(_avatarAddress, 0); Assert.NotNull(slotState.Result); var consumable = (Consumable)slotState.Result.itemUsable; Assert.NotNull(consumable); }
public void UpdateV2() { Address avatarAddress = new PrivateKey().ToAddress(); Address agentAddress = new PrivateKey().ToAddress(); var avatarState = GetNewAvatarState(avatarAddress, agentAddress); var result = new CombinationConsumable.ResultModel() { id = default,
public SellCancellation2Test(ITestOutputHelper outputHelper) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.TestOutput(outputHelper) .CreateLogger(); _initialState = new State(); var sheets = TableSheetsImporter.ImportSheets(); foreach (var(key, value) in sheets) { _initialState = _initialState .SetState(Addresses.TableSheet.Derive(key), value.Serialize()); } var tableSheets = new TableSheets(sheets); var currency = new Currency("NCG", 2, minters: null); var goldCurrencyState = new GoldCurrencyState(currency); _agentAddress = new PrivateKey().ToAddress(); var agentState = new AgentState(_agentAddress); _avatarAddress = new PrivateKey().ToAddress(); var rankingMapAddress = new PrivateKey().ToAddress(); var avatarState = new AvatarState( _avatarAddress, _agentAddress, 0, tableSheets.GetAvatarSheets(), new GameConfigState(), rankingMapAddress) { worldInformation = new WorldInformation( 0, tableSheets.WorldSheet, GameConfig.RequireClearedStageLevel.ActionsInShop), }; agentState.avatarAddresses[0] = _avatarAddress; var equipment = ItemFactory.CreateItemUsable( tableSheets.EquipmentItemSheet.First, Guid.NewGuid(), 0); var shopState = new ShopState(); shopState.Register(new ShopItem( _agentAddress, _avatarAddress, Guid.NewGuid(), new FungibleAssetValue(goldCurrencyState.Currency, 100, 0), equipment)); var result = new CombinationConsumable.ResultModel() { id = default,
public void ExecuteThrowFailedLoadStateException() { var action = new CombinationConsumable() { AvatarAddress = _avatarAddress, recipeId = 1, slotIndex = 0, }; Assert.Throws <FailedLoadStateException>(() => action.Execute(new ActionContext() { PreviousStates = new State(), Signer = _agentAddress, BlockIndex = 1, Random = _random, }) ); }
public void ExecuteThrowNotEnoughClearedStageLevelException() { _initialState = _initialState .SetState(_slotAddress, new CombinationSlotState(_slotAddress, 0).Serialize()); var action = new CombinationConsumable() { AvatarAddress = _avatarAddress, recipeId = 1, slotIndex = 0, }; Assert.Throws <NotEnoughClearedStageLevelException>(() => action.Execute(new ActionContext() { PreviousStates = _initialState, Signer = _agentAddress, BlockIndex = 1, Random = _random, }) ); }
public IObservable <ActionBase.ActionEvaluation <CombinationConsumable> > CombinationConsumable( int recipeId, int slotIndex) { AnalyticsManager.Instance.OnEvent(AnalyticsManager.EventName.ActionCombination); var action = new CombinationConsumable { recipeId = recipeId, AvatarAddress = States.Instance.CurrentAvatarState.address, slotIndex = slotIndex, }; ProcessAction(action); return(_renderer.EveryRender <CombinationConsumable>() .Where(eval => eval.Action.Id.Equals(action.Id)) .Take(1) .Last() .ObserveOnMainThread() .Timeout(ActionTimeout) .DoOnError(e => HandleException(action.Id, e))); }
public void Execute(bool backward) { var avatarState = _initialState.GetAvatarState(_avatarAddress); var row = _tableSheets.ConsumableItemRecipeSheet.Values.First(); var costActionPoint = row.RequiredActionPoint; foreach (var materialInfo in row.Materials) { var materialRow = _tableSheets.MaterialItemSheet[materialInfo.Id]; var material = ItemFactory.CreateItem(materialRow, _random); avatarState.inventory.AddItem(material, materialInfo.Count); } var previousActionPoint = avatarState.actionPoint; var previousResultConsumableCount = avatarState.inventory.Equipments.Count(e => e.Id == row.ResultConsumableItemId); var previousMailCount = avatarState.mailBox.Count; avatarState.worldInformation = new WorldInformation( 0, _tableSheets.WorldSheet, GameConfig.RequireClearedStageLevel.CombinationConsumableAction); IAccountStateDelta previousState; if (backward) { previousState = _initialState.SetState(_avatarAddress, avatarState.Serialize()); } else { previousState = _initialState .SetState(_avatarAddress.Derive(LegacyInventoryKey), avatarState.inventory.Serialize()) .SetState(_avatarAddress.Derive(LegacyWorldInformationKey), avatarState.worldInformation.Serialize()) .SetState(_avatarAddress.Derive(LegacyQuestListKey), avatarState.questList.Serialize()) .SetState(_avatarAddress, avatarState.SerializeV2()); } var action = new CombinationConsumable { avatarAddress = _avatarAddress, recipeId = row.Id, slotIndex = 0, }; var nextState = action.Execute(new ActionContext { PreviousStates = previousState, Signer = _agentAddress, BlockIndex = 1, Random = _random, }); var slotState = nextState.GetCombinationSlotState(_avatarAddress, 0); Assert.NotNull(slotState.Result); Assert.NotNull(slotState.Result.itemUsable); var consumable = (Consumable)slotState.Result.itemUsable; Assert.NotNull(consumable); var nextAvatarState = nextState.GetAvatarStateV2(_avatarAddress); Assert.Equal(previousActionPoint - costActionPoint, nextAvatarState.actionPoint); Assert.Equal(previousMailCount + 1, nextAvatarState.mailBox.Count); Assert.IsType <CombinationMail>(nextAvatarState.mailBox.First()); Assert.Equal( previousResultConsumableCount + 1, nextAvatarState.inventory.Consumables.Count(e => e.Id == row.ResultConsumableItemId)); }