public static bool TryGetAgentAvatarStatesV2( this IAccountStateDelta states, Address agentAddress, Address avatarAddress, out AgentState agentState, out AvatarState avatarState ) { avatarState = null; agentState = states.GetAgentState(agentAddress); if (agentState is null) { return(false); } if (!agentState.avatarAddresses.ContainsValue(avatarAddress)) { throw new AgentStateNotContainsAvatarAddressException( $"The avatar {avatarAddress.ToHex()} does not belong to the agent {agentAddress.ToHex()}."); } try { avatarState = states.GetAvatarStateV2(avatarAddress); } catch (FailedLoadStateException) { // BackWardCompatible. avatarState = states.GetAvatarState(avatarAddress); } return(!(avatarState is null)); }
public void Execute() { var agentAddress = new PrivateKey().ToAddress(); var avatarAddress = new PrivateKey().ToAddress(); var avatarState = new AvatarState( avatarAddress, agentAddress, 0, _tableSheets.GetAvatarSheets(), new GameConfigState(), default ); var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 }; var admin = new Address("8d9f76aF8Dc5A812aCeA15d8bf56E2F790F47fd7"); var state = new State(ImmutableDictionary <Address, IValue> .Empty .Add(AdminState.Address, new AdminState(admin, 100).Serialize()) .Add(avatarAddress, avatarState.SerializeV2()) ); var action = new MigrationAvatarState { avatarStates = new List <Dictionary> { (Dictionary)avatarState.Serialize(), }, }; IAccountStateDelta nextState = action.Execute(new ActionContext() { PreviousStates = state, Signer = admin, BlockIndex = 1, }); var nextAvatarState = nextState.GetAvatarStateV2(avatarAddress); Assert.NotNull(nextAvatarState.inventory); Assert.NotNull(nextAvatarState.worldInformation); Assert.NotNull(nextAvatarState.questList); }
public void Execute(int avatarLevel, int worldId, int stageId, int playCount, bool backward, bool isLock, bool isClearedBefore) { Assert.True(_tableSheets.WorldSheet.TryGetValue(worldId, out var worldRow)); Assert.True(stageId >= worldRow.StageBegin); Assert.True(stageId <= worldRow.StageEnd); Assert.True(_tableSheets.StageSheet.TryGetValue(stageId, out _)); var previousAvatarState = _initialState.GetAvatarStateV2(_avatarAddress); previousAvatarState.level = avatarLevel; var clearedStageId = _tableSheets.StageSheet.First?.Id ?? 0; clearedStageId = isClearedBefore ? Math.Max(clearedStageId, stageId - 1) : stageId - 1; clearedStageId = playCount > 1 ? clearedStageId + 1 : clearedStageId; previousAvatarState.worldInformation = new WorldInformation( 0, _tableSheets.WorldSheet, clearedStageId); List <Guid> costumes = new List <Guid>(); IRandom random = new TestRandom(); if (avatarLevel >= GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot) { var costumeId = _tableSheets .CostumeItemSheet .Values .First(r => r.ItemSubType == ItemSubType.FullCostume) .Id; var costume = (Costume)ItemFactory.CreateItem( _tableSheets.ItemSheet[costumeId], random); previousAvatarState.inventory.AddItem(costume); costumes.Add(costume.ItemId); } List <Guid> equipments = new List <Guid>(); if (avatarLevel >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotWeapon) { var weaponId = _tableSheets .EquipmentItemSheet .Values .Where(r => r.ItemSubType == ItemSubType.Weapon) .OrderBy(r => r.Stat.ValueAsInt) .Last() .Id; var weapon = ItemFactory.CreateItem( _tableSheets.EquipmentItemSheet[weaponId], random) as Equipment; equipments.Add(weapon.ItemId); OrderLock?orderLock = null; if (isLock) { orderLock = new OrderLock(Guid.NewGuid()); } previousAvatarState.inventory.AddItem(weapon, iLock: orderLock); } if (avatarLevel >= GameConfig.RequireCharacterLevel.CharacterEquipmentSlotArmor) { var armorId = _tableSheets .EquipmentItemSheet .Values .Where(r => r.ItemSubType == ItemSubType.Armor) .OrderBy(r => r.Stat.ValueAsInt) .Last() .Id; var armor = ItemFactory.CreateItem( _tableSheets.EquipmentItemSheet[armorId], random) as Equipment; equipments.Add(armor.ItemId); previousAvatarState.inventory.AddItem(armor); } var mailEquipmentRow = _tableSheets.EquipmentItemSheet.Values.First(); var mailEquipment = ItemFactory.CreateItemUsable(mailEquipmentRow, default, 0);