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 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 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)); }