예제 #1
0
 internal void SetSprite(TintedSprite sprite)
 {
     if (sprite != null)
     {
         image.sprite = sprite.sprite;
     }
 }
예제 #2
0
        private void AddItems(ICoreApi coreApi)
        {
            // Create a sprite for the candy which points to the main custom item sprite sheet
            ISprite candySprite = new TintedSprite(coreApi.Items.CreateSprite(this.Helper.Content.Load <Texture2D>("assets/items/candy.png")), Color.Red);

            // Set the buffs for the candy
            BuffDescription candyBuffs = new BuffDescription(TimeSpan.FromMinutes(2.5), speed: 1);

            // Create the candy object manager
            ModFood candy = new ModFood(coreApi.TranslationHelper, candySprite, "candy", 20, 5, Category.Trash, false, candyBuffs);

            // Register the candy with the core API to add it as an object in the game
            coreApi.Items.CommonRegistry.Objects.Register("candy", candy);
        }
    public static TintedSprite GetTintedSprite(string name)
    {
        TintedSprite result = null;

        if (TintedSprites != null)
        {
            for (int i = 0; i < TintedSprites.Count; i++)
            {
                if (TintedSprites[i].sprite.name == name)
                {
                    result = TintedSprites[i];
                    break;
                }
            }
        }
        return(result);
    }
        private void LoadObjects(IContentPack contentPack, IContentSource contentSource, ICoreTranslationHelper translationHelper, IEnumerable <ContentPackDataInfo> sources)
        {
            var objects = (from source in sources
                           from entry in source.Content.Objects
                           select new { Source = source, Name = entry.Key, Data = entry.Value }).ToArray();

            // Create exceptions for conflicting item names
            Exception[] exceptions = (from itemGroup in this.GetDuplicateGroups(objects, item => item.Name)
                                      select new Exception($"Object '{itemGroup.Key}' is being registered by multiple content files: {string.Join(", ", itemGroup.Select(item => $"'{item.Source.FullPath}'"))}")).ToArray();

            // Throw the exceptions
            if (exceptions.Any())
            {
                if (exceptions.Length > 1)
                {
                    throw new AggregateException(exceptions);
                }

                throw exceptions.First();
            }

            // Create each object
            foreach (var obj in objects)
            {
                ItemKey key = new ItemKey(contentPack.Manifest, obj.Name);

                // Create the sprite for the object
                ISprite sprite = this.CreateSprite(contentSource, obj.Source, obj.Name, obj.Data);
                if (obj.Data.Tint != Color.White)
                {
                    sprite = new TintedSprite(sprite, obj.Data.Tint);
                }

                // Create the object's manager
                Category   category = new Category(obj.Data.CategoryNumber, obj.Data.CategoryName);
                IModObject manager  = obj.Data.Buffs.HasValue.Match <bool, IModObject>()
                                      .When(true, () => new ModFood(translationHelper, sprite, key.LocalKey, obj.Data.Cost, obj.Data.Edibility, category, false, obj.Data.Buffs.Value))
                                      .When(false, () => new ModObject(translationHelper, sprite, key.LocalKey, obj.Data.Cost, category, obj.Data.Edibility))
                                      .ElseThrow();

                // Register the object
                this._api.Items.CommonRegistry.Objects.Register(key, manager);
                this._api.Owner.Monitor.Log($" - {key} registered (object)", LogLevel.Trace);
            }
        }
        private void LoadWeapons(IContentPack contentPack, IContentSource contentSource, ICoreTranslationHelper translationHelper, IEnumerable <ContentPackDataInfo> sources)
        {
            var weapons = (from source in sources
                           from entry in source.Content.Weapons
                           select new { Source = source, Name = entry.Key, Data = entry.Value }).ToArray();

            // Create exceptions for conflicting item names
            Exception[] exceptions = (from itemGroup in this.GetDuplicateGroups(weapons, item => item.Name)
                                      select new Exception($"Weapon '{itemGroup.Key}' is being registered by multiple content files: {string.Join(", ", itemGroup.Select(item => $"'{item.Source.FullPath}'"))}")).ToArray();

            // Throw the exceptions
            if (exceptions.Any())
            {
                if (exceptions.Length > 1)
                {
                    throw new AggregateException(exceptions);
                }

                throw exceptions.First();
            }

            // Create each weapon
            foreach (var weapon in weapons)
            {
                ItemKey key = new ItemKey(contentPack.Manifest, weapon.Name);

                // Create the sprite for the object
                ISprite sprite = this.CreateSprite(contentSource, weapon.Source, weapon.Name, weapon.Data);
                if (weapon.Data.Tint != Color.White)
                {
                    sprite = new TintedSprite(sprite, weapon.Data.Tint);
                }

                // Create the weapon's manager
                ModWeapon manager = new ModWeapon(translationHelper, key.LocalKey, sprite, weapon.Data.Type, weapon.Data.MinDamage, weapon.Data.MaxDamage, weapon.Data.Knockback, weapon.Data.Speed, weapon.Data.Accuracy, weapon.Data.Defense, weapon.Data.AreaOfEffect, weapon.Data.CritChance, weapon.Data.CritMultiplier);

                // Register the object
                this._api.Items.CommonRegistry.Weapons.Register(key, manager);
                this._api.Owner.Monitor.Log($" - {key} registered (weapon)", LogLevel.Trace);
            }
        }