예제 #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);
        }