Beispiel #1
0
        public void HasItem(ItemType itemType, int itemCount)
        {
            ItemSheet.Row row       = null;
            var           inventory = new Inventory();

            switch (itemType)
            {
            case ItemType.Consumable:
                row = TableSheets.EquipmentItemSheet.First;
                break;

            case ItemType.Costume:
                row = TableSheets.CostumeItemSheet.First;
                break;

            case ItemType.Equipment:
                row = TableSheets.ConsumableItemSheet.First;
                break;

            case ItemType.Material:
                row = TableSheets.MaterialItemSheet.First;
                break;
            }

            Assert.NotNull(row);
            for (var i = 0; i < itemCount; i++)
            {
                inventory.AddItem(ItemFactory.CreateItem(row, new TestRandom()));
            }

            Assert.True(inventory.HasItem(row.Id, itemCount));
        }
Beispiel #2
0
        protected ItemUsable(ItemSheet.Row data, Guid id, long requiredBlockIndex) : base(data)
        {
            ItemId   = id;
            StatsMap = new StatsMap();

            switch (data)
            {
            case ConsumableItemSheet.Row consumableItemRow:
            {
                foreach (var statData in consumableItemRow.Stats)
                {
                    StatsMap.AddStatValue(statData.StatType, statData.Value);
                }

                break;
            }

            case EquipmentItemSheet.Row equipmentItemRow:
                StatsMap.AddStatValue(equipmentItemRow.Stat.Type, equipmentItemRow.Stat.Value);
                break;
            }

            Skills             = new List <Model.Skill.Skill>();
            BuffSkills         = new List <BuffSkill>();
            RequiredBlockIndex = requiredBlockIndex;
        }
Beispiel #3
0
 protected ItemBase(ItemSheet.Row data)
 {
     Id            = data.Id;
     Grade         = data.Grade;
     ItemType      = data.ItemType;
     ItemSubType   = data.ItemSubType;
     ElementalType = data.ElementalType;
 }
Beispiel #4
0
        public static ItemBase CreateItem(ItemSheet.Row row)
        {
            switch (row)
            {
            case CostumeItemSheet.Row costumeRow:
                return(CreateCostume(costumeRow));

            case MaterialItemSheet.Row materialRow:
                return(CreateMaterial(materialRow));

            default:
                return(CreateItemUsable(row, Guid.NewGuid(), 0));
            }
        }
Beispiel #5
0
        public static ItemBase CreateItem(ItemSheet.Row row, IRandom random)
        {
            switch (row)
            {
            case CostumeItemSheet.Row costumeRow:
                return(CreateCostume(costumeRow, random.GenerateRandomGuid()));

            case MaterialItemSheet.Row materialRow:
                return(CreateMaterial(materialRow));

            default:
                return(CreateItemUsable(row, random.GenerateRandomGuid(), 0));
            }
        }
Beispiel #6
0
        public static ItemUsable CreateItemUsable(ItemSheet.Row itemRow, Guid id,
                                                  long requiredBlockIndex, int level = 0)
        {
            Equipment equipment = null;

            switch (itemRow.ItemSubType)
            {
            // Consumable
            case ItemSubType.Food:
                return(new Consumable((ConsumableItemSheet.Row)itemRow, id,
                                      requiredBlockIndex));

            // Equipment
            case ItemSubType.Weapon:
                equipment = new Weapon((EquipmentItemSheet.Row)itemRow, id, requiredBlockIndex);
                break;

            case ItemSubType.Armor:
                equipment = new Armor((EquipmentItemSheet.Row)itemRow, id, requiredBlockIndex);
                break;

            case ItemSubType.Belt:
                equipment = new Belt((EquipmentItemSheet.Row)itemRow, id, requiredBlockIndex);
                break;

            case ItemSubType.Necklace:
                equipment = new Necklace((EquipmentItemSheet.Row)itemRow, id, requiredBlockIndex);
                break;

            case ItemSubType.Ring:
                equipment = new Ring((EquipmentItemSheet.Row)itemRow, id, requiredBlockIndex);
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          itemRow.Id.ToString(CultureInfo.InvariantCulture));
            }

            for (int i = 0; i < level; ++i)
            {
                equipment.LevelUp();
            }

            return(equipment);
        }
Beispiel #7
0
        public virtual void SetData(ItemSheet.Row itemRow)
        {
            if (itemRow is null)
            {
                Clear();
                return;
            }

            Sprite gradeSprite;

            switch (imageSizeType)
            {
            case ImageSizeType.Small:
                gradeSprite = SpriteHelper.GetSmallItemBackground(itemRow.Grade);
                break;

            case ImageSizeType.Middle:
                gradeSprite = SpriteHelper.GetItemBackground(itemRow.Grade);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(imageSizeType), imageSizeType, null);
            }
            gradeImage.overrideSprite = gradeSprite;

            var itemSprite = SpriteHelper.GetItemIcon(itemRow.Id);

            if (itemSprite is null)
            {
                throw new FailedToLoadResourceException <Sprite>(itemRow.Id.ToString());
            }

            iconImage.enabled        = true;
            iconImage.overrideSprite = itemSprite;
            iconImage.SetNativeSize();
        }
        public override IAccountStateDelta Execute(IActionContext context)
        {
            IAccountStateDelta states                  = context.PreviousStates;
            Address            inventoryAddress        = avatarAddress.Derive(LegacyInventoryKey);
            Address            worldInformationAddress = avatarAddress.Derive(LegacyWorldInformationKey);
            Address            questListAddress        = avatarAddress.Derive(LegacyQuestListKey);

            if (context.Rehearsal)
            {
                return(states
                       .SetState(avatarAddress, MarkChanged)
                       .SetState(inventoryAddress, MarkChanged)
                       .SetState(worldInformationAddress, MarkChanged)
                       .SetState(questListAddress, MarkChanged)
                       .SetState(MonsterCollectionState.DeriveAddress(context.Signer, 0), MarkChanged)
                       .SetState(MonsterCollectionState.DeriveAddress(context.Signer, 1), MarkChanged)
                       .SetState(MonsterCollectionState.DeriveAddress(context.Signer, 2), MarkChanged)
                       .SetState(MonsterCollectionState.DeriveAddress(context.Signer, 3), MarkChanged));
            }

            CheckObsolete(BlockChain.Policy.BlockPolicySource.V100080ObsoleteIndex, context);

            if (!states.TryGetAgentAvatarStatesV2(context.Signer, avatarAddress, out AgentState agentState, out AvatarState avatarState))
            {
                throw new FailedLoadStateException($"Aborted as the avatar state of the signer failed to load.");
            }

            Address collectionAddress = MonsterCollectionState.DeriveAddress(context.Signer, agentState.MonsterCollectionRound);

            if (!states.TryGetState(collectionAddress, out Dictionary stateDict))
            {
                throw new FailedLoadStateException($"Aborted as the monster collection state failed to load.");
            }

            var monsterCollectionState = new MonsterCollectionState(stateDict);
            List <MonsterCollectionRewardSheet.RewardInfo> rewards =
                monsterCollectionState.CalculateRewards(
                    states.GetSheet <MonsterCollectionRewardSheet>(),
                    context.BlockIndex
                    );

            if (rewards.Count == 0)
            {
                throw new RequiredBlockIndexException($"{collectionAddress} is not available yet");
            }

            Guid id     = context.Random.GenerateRandomGuid();
            var  result = new MonsterCollectionResult(id, avatarAddress, rewards);
            var  mail   = new MonsterCollectionMail(result, context.BlockIndex, id, context.BlockIndex);

            avatarState.Update(mail);

            ItemSheet itemSheet = states.GetItemSheet();

            foreach (MonsterCollectionRewardSheet.RewardInfo rewardInfo in rewards)
            {
                ItemSheet.Row row  = itemSheet[rewardInfo.ItemId];
                ItemBase      item = row is MaterialItemSheet.Row materialRow
                    ? ItemFactory.CreateTradableMaterial(materialRow)
                    : ItemFactory.CreateItem(row, context.Random);
                avatarState.inventory.AddItem2(item, rewardInfo.Quantity);
            }
            monsterCollectionState.Claim(context.BlockIndex);

            return(states
                   .SetState(avatarAddress, avatarState.SerializeV2())
                   .SetState(inventoryAddress, avatarState.inventory.Serialize())
                   .SetState(worldInformationAddress, avatarState.worldInformation.Serialize())
                   .SetState(questListAddress, avatarState.questList.Serialize())
                   .SetState(collectionAddress, monsterCollectionState.Serialize()));
        }
Beispiel #9
0
 public override void SetData(ItemSheet.Row itemRow)
 {
     base.SetData(itemRow);
     Data = itemRow;
 }
 public static string GetLocalizedName(this ItemSheet.Row value)
 {
     return(L10nManager.Localize($"ITEM_NAME_{value.Id}"));
 }