Esempio n. 1
0
        public static Entity CreateItem(ItemTemplate data, int level)
        {
            var entity = Entity.New(data.ID);

            entity.Add(new TypeId(data.ID));
            entity.Add(new StatsContainer());
            if (!string.IsNullOrEmpty(data.Icon))
            {
                entity.Add(new IconComponent(UnityDirs.ItemIcons, data.Icon));
            }
            entity.Add(new EntityLevelComponent(level));
            entity.Add(new TooltipComponent());
            entity.Add(new StatusUpdateComponent());
            var dataDescr = entity.Add(new DataDescriptionComponent());

            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, out DataEntry prefix, out DataEntry suffix);
            StringBuilder sbName  = new StringBuilder();
            StringBuilder sbDescr = new StringBuilder();

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

            sbName.Append(data.Name);
            if (suffix != null)
            {
                var suffixLabel = suffix.TryGetValue(DatabaseFields.Name, "");
                if (!string.IsNullOrEmpty(suffixLabel))
                {
                    sbName.Append(" ");
                    sbName.Append(suffixLabel);
                }
                var suffixDescr = suffix.TryGetValue(DatabaseFields.Description, "");
                if (!string.IsNullOrEmpty(suffixDescr))
                {
                    sbDescr.NewLine();
                    sbDescr.Append(suffixDescr);
                }
            }
            entity.Add(new LabelComponent(sbName.ToString()));
            entity.Add(new DescriptionComponent(sbDescr.ToString()));
            entity.Post(new DataDescriptionUpdating(dataDescr));
            return(entity);
        }
Esempio n. 2
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);
        }