示例#1
0
        public static void AddItem(ItemConfig item)
        {
            var itemTypeData = item.ItemType;

            if (itemTypeData != null)
            {
                if (!_itemsByType.TryGetValue(itemTypeData, out var list))
                {
                    list = new List <ItemConfig>();
                    _itemsByType.Add(itemTypeData, list);
                }
                list.Add(item);
            }
            _items.AddOrUpdate(item.ID, item);
            _itemsFullID.AddOrUpdate(item.FullID, item);
            var bagIndex = item.Rarity;
            var chance   = ((GameData.Enums[EnumTypes.ItemRarity].Count + 1) - bagIndex) * 100;

            AddToShuffleBag(_specificRarityBags, item, chance, bagIndex);
            for (int i = 0; i <= bagIndex; i++)
            {
                AddToShuffleBag(_maxRarityBags, item, chance, bagIndex);
            }
        }
示例#2
0
 private static void AddToShuffleBag(Dictionary <int, ShuffleBag <ItemConfig> > dict, ItemConfig item, int chance, int bagIndex)
 {
     if (!dict.TryGetValue(bagIndex, out var bag))
     {
         bag = new ShuffleBag <ItemConfig>();
         dict.Add(bagIndex, bag);
     }
     bag.Add(item, chance);
 }
 public ItemWrapper(ScriptableDatabase db, ItemConfig config) : base(db, config)
 {
     _item = config;
     _icon = config.GetPreviewTexture();
 }
示例#4
0
        public static Entity CreateItem(ItemConfig data, int level)
        {
            var entity = Entity.New(data.ID);

            entity.Add(new TypeId(data.ID));
            if (!string.IsNullOrEmpty(data.Icon))
            {
                entity.Add(new IconComponent(ItemPool.LoadAsset <Sprite>(UnityDirs.ItemIcons, data.Icon)));
            }
            else
            {
                entity.Add(new IconComponent(SpriteDatabase.Item));
            }
            entity.Add(new EntityLevelComponent(level));
            if (data.TypeComponents != null)
            {
                World.Get <DataFactory>().AddComponentList(entity, data.Data, data.TypeComponents);
            }
            if (data.Components != null)
            {
                World.Get <DataFactory>().AddComponentList(entity, data.Data, data.Components);
            }
            ItemModifierFactory.AddModifiers(data.ModifierGroup, level, entity);
            StringBuilder sbName  = new StringBuilder();
            StringBuilder sbDescr = new StringBuilder();

            sbDescr.Append(data.Description);
            var prefix = entity.Get <ItemModifierPrefix>();
            var suffix = entity.Get <ItemModifierSuffix>();

            if (prefix != null)
            {
                var prefixLabel = prefix.Data.TryGetValue(DatabaseFields.Name, "");
                if (!string.IsNullOrEmpty(prefixLabel))
                {
                    sbName.Append(prefixLabel);
                    sbName.Append(" ");
                }
                var prefixDescr = prefix.Data.TryGetValue(DatabaseFields.Description, "");
                if (!string.IsNullOrEmpty(prefixDescr))
                {
                    sbDescr.NewLine();
                    sbDescr.Append(prefixDescr);
                }
            }

            sbName.Append(data.Name);
            if (suffix != null)
            {
                var suffixLabel = suffix.Data.TryGetValue(DatabaseFields.Name, "");
                if (!string.IsNullOrEmpty(suffixLabel))
                {
                    sbName.Append(" ");
                    sbName.Append(suffixLabel);
                }
                var suffixDescr = suffix.Data.TryGetValue(DatabaseFields.Description, "");
                if (!string.IsNullOrEmpty(suffixDescr))
                {
                    sbDescr.NewLine();
                    sbDescr.Append(suffixDescr);
                }
            }
            entity.Add(new LabelComponent(sbName.ToString()));
            entity.Add(new DescriptionComponent(sbDescr.ToString()));
            var dataDescr = entity.Add(new DataDescriptionComponent());

            entity.Post(new DataDescriptionAdded(dataDescr));
            return(entity);
        }