Ejemplo n.º 1
0
        // Following function replaces the art for a Monster Train card
        // Largely inspired by Trainworks source code. By inspired I mean outright stolen.
        // The artPath string is relative to the DLL, such as "assets/Deadweight.jpg"
        public void ReplaceCardArt(CardData myCard, string artPath)
        {
            if (myCard == null || artPath == "")
            {
                Logger.LogError($"ReplaceCardArt() error in parameters");
                return;
            }

            var assetLoadingInfo = new AssetLoadingInfo()
            {
                FilePath   = artPath,
                PluginPath = this.assemblyPath,
                AssetType  = AssetRefBuilder.AssetTypeEnum.CardArt
            };
            var cardArtPrefabVariantRefBuilder = new AssetRefBuilder
            {
                AssetLoadingInfo = assetLoadingInfo
            };
            var cardArtPrefabVariantRef = cardArtPrefabVariantRefBuilder.BuildAndRegister();

            AccessTools.Field(typeof(CardData), "cardArtPrefabVariantRef").SetValue(myCard, cardArtPrefabVariantRef);
        }
        /// <summary>
        /// Builds the CharacterData represented by this builder's parameters recursively;
        /// all Builders represented in this class's various fields will also be built.
        /// </summary>
        /// <returns>The newly created CharacterData</returns>
        public CharacterData Build()
        {
            CharacterData characterData = ScriptableObject.CreateInstance <CharacterData>();

            characterData.name = this.CharacterID;

            foreach (var builder in this.TriggerBuilders)
            {
                this.Triggers.Add(builder.Build());
            }
            foreach (var builder in this.RoomModifierBuilders)
            {
                this.RoomModifiers.Add(builder.Build());
            }

            var guid = GUIDGenerator.GenerateDeterministicGUID(this.CharacterID);

            AccessTools.Field(typeof(CharacterData), "id").SetValue(characterData, guid);
            AccessTools.Field(typeof(CharacterData), "animationController").SetValue(characterData, this.AnimationController);
            AccessTools.Field(typeof(CharacterData), "ascendsTrainAutomatically").SetValue(characterData, this.AscendsTrainAutomatically);
            AccessTools.Field(typeof(CharacterData), "attackDamage").SetValue(characterData, this.AttackDamage);
            AccessTools.Field(typeof(CharacterData), "attackTeleportsToDefender").SetValue(characterData, this.AttackTeleportsToDefender);
            AccessTools.Field(typeof(CharacterData), "bossActionGroups").SetValue(characterData, this.BossActionGroups);
            AccessTools.Field(typeof(CharacterData), "bossRoomSpellCastVFX").SetValue(characterData, this.BossRoomSpellCastVFX);
            AccessTools.Field(typeof(CharacterData), "bossSpellCastVFX").SetValue(characterData, this.BossSpellCastVFX);
            AccessTools.Field(typeof(CharacterData), "canAttack").SetValue(characterData, this.CanAttack);
            AccessTools.Field(typeof(CharacterData), "canBeHealed").SetValue(characterData, this.CanBeHealed);
            AccessTools.Field(typeof(CharacterData), "characterChatterData").SetValue(characterData, this.CharacterChatterData);
            AccessTools.Field(typeof(CharacterData), "characterLoreTooltipKeys").SetValue(characterData, this.CharacterLoreTooltipKeys);
            if (this.CharacterPrefabVariantRef == null)
            {
                if (this.CharacterPrefabVariantRefBuilder == null)
                {
                    if (this.BundleLoadingInfo != null)
                    {
                        this.BundleLoadingInfo.PluginPath     = this.BaseAssetPath;
                        this.CharacterPrefabVariantRefBuilder = new AssetRefBuilder
                        {
                            AssetLoadingInfo = this.BundleLoadingInfo
                        };
                    }
                    else
                    {
                        var assetLoadingInfo = new AssetLoadingInfo()
                        {
                            FilePath   = this.AssetPath,
                            PluginPath = this.BaseAssetPath,
                            AssetType  = AssetRefBuilder.AssetTypeEnum.Character
                        };
                        this.CharacterPrefabVariantRefBuilder = new AssetRefBuilder
                        {
                            AssetLoadingInfo = assetLoadingInfo
                        };
                    }
                }
                this.CharacterPrefabVariantRef = this.CharacterPrefabVariantRefBuilder.BuildAndRegister();
            }
            AccessTools.Field(typeof(CharacterData), "characterPrefabVariantRef").SetValue(characterData, this.CharacterPrefabVariantRef);
            AccessTools.Field(typeof(CharacterData), "characterSoundData").SetValue(characterData, this.CharacterSoundData);
            AccessTools.Field(typeof(CharacterData), "characterSpriteCache").SetValue(characterData, this.CharacterSpriteCache);
            AccessTools.Field(typeof(CharacterData), "deathSlidesBackwards").SetValue(characterData, this.DeathSlidesBackwards);
            AccessTools.Field(typeof(CharacterData), "deathType").SetValue(characterData, this.DeathType);
            AccessTools.Field(typeof(CharacterData), "deathVFX").SetValue(characterData, this.DeathVFX);
            AccessTools.Field(typeof(CharacterData), "fallbackData").SetValue(characterData, this.FallBackData);
            AccessTools.Field(typeof(CharacterData), "health").SetValue(characterData, this.Health);
            AccessTools.Field(typeof(CharacterData), "impactVFX").SetValue(characterData, this.ImpactVFX);
            AccessTools.Field(typeof(CharacterData), "isMiniboss").SetValue(characterData, this.IsMiniboss);
            AccessTools.Field(typeof(CharacterData), "isOuterTrainBoss").SetValue(characterData, this.IsOuterTrainBoss);
            BuilderUtils.ImportStandardLocalization(this.NameKey, this.Name);
            AccessTools.Field(typeof(CharacterData), "nameKey").SetValue(characterData, this.NameKey);
            AccessTools.Field(typeof(CharacterData), "projectilePrefab").SetValue(characterData, this.ProjectilePrefab);
            AccessTools.Field(typeof(CharacterData), "roomModifiers").SetValue(characterData, this.RoomModifiers);
            AccessTools.Field(typeof(CharacterData), "size").SetValue(characterData, this.Size);
            AccessTools.Field(typeof(CharacterData), "startingStatusEffects").SetValue(characterData, this.StartingStatusEffects);
            AccessTools.Field(typeof(CharacterData), "statusEffectImmunities").SetValue(characterData, this.StatusEffectImmunities);
            //AccessTools.Field(typeof(CardData), "stringBuilder").SetValue(cardData, this.);
            if (this.PriorityDraw)
            {
                this.SubtypeKeys.Add("SubtypesData_Chosen");
            }
            AccessTools.Field(typeof(CharacterData), "subtypeKeys").SetValue(characterData, this.SubtypeKeys);
            AccessTools.Field(typeof(CharacterData), "triggers").SetValue(characterData, this.Triggers);

            return(characterData);
        }
        public static void RegisterCustomAsset(string assetGUID, AssetLoadingInfo loadingInfo)
        {
            var runtimeKey = Hash128.Parse(assetGUID);

            RuntimeKeyToAssetInfo[runtimeKey] = loadingInfo;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Builds the CardData represented by this builder's parameters recursively;
        /// i.e. all CardEffectBuilders in EffectBuilders will also be built.
        /// </summary>
        /// <returns>The newly created CardData</returns>
        public CardData Build()
        {
            foreach (var builder in this.EffectBuilders)
            {
                this.Effects.Add(builder.Build());
            }
            foreach (var builder in this.TraitBuilders)
            {
                this.Traits.Add(builder.Build());
            }
            foreach (var builder in this.EffectTriggerBuilders)
            {
                this.EffectTriggers.Add(builder.Build());
            }
            foreach (var builder in this.TriggerBuilders)
            {
                this.Triggers.Add(builder.Build());
            }

            var allGameData = ProviderManager.SaveManager.GetAllGameData();

            if (this.LinkedClass == null)
            {
                this.LinkedClass = CustomClassManager.GetClassDataByID(this.ClanID);
            }
            CardData cardData = ScriptableObject.CreateInstance <CardData>();
            var      guid     = GUIDGenerator.GenerateDeterministicGUID(this.CardID);

            AccessTools.Field(typeof(CardData), "id").SetValue(cardData, guid);
            cardData.name = this.CardID;
            if (this.CardArtPrefabVariantRef == null)
            {
                if (this.CardArtPrefabVariantRefBuilder == null)
                {
                    if (this.BundleLoadingInfo != null)
                    {
                        this.BundleLoadingInfo.PluginPath   = this.BaseAssetPath;
                        this.CardArtPrefabVariantRefBuilder = new AssetRefBuilder
                        {
                            AssetLoadingInfo = this.BundleLoadingInfo
                        };
                    }
                    else
                    {
                        var assetLoadingInfo = new AssetLoadingInfo()
                        {
                            FilePath   = this.AssetPath,
                            PluginPath = this.BaseAssetPath,
                            AssetType  = AssetRefBuilder.AssetTypeEnum.CardArt
                        };
                        this.CardArtPrefabVariantRefBuilder = new AssetRefBuilder
                        {
                            AssetLoadingInfo = assetLoadingInfo
                        };
                    }
                }
                this.CardArtPrefabVariantRef = this.CardArtPrefabVariantRefBuilder.BuildAndRegister();
            }
            AccessTools.Field(typeof(CardData), "cardArtPrefabVariantRef").SetValue(cardData, this.CardArtPrefabVariantRef);
            AccessTools.Field(typeof(CardData), "cardLoreTooltipKeys").SetValue(cardData, this.CardLoreTooltipKeys);
            AccessTools.Field(typeof(CardData), "cardType").SetValue(cardData, this.CardType);
            AccessTools.Field(typeof(CardData), "cost").SetValue(cardData, this.Cost);
            AccessTools.Field(typeof(CardData), "costType").SetValue(cardData, this.CostType);
            AccessTools.Field(typeof(CardData), "effects").SetValue(cardData, this.Effects);
            AccessTools.Field(typeof(CardData), "effectTriggers").SetValue(cardData, this.EffectTriggers);
            AccessTools.Field(typeof(CardData), "fallbackData").SetValue(cardData, this.FallbackData);
            AccessTools.Field(typeof(CardData), "ignoreWhenCountingMastery").SetValue(cardData, this.IgnoreWhenCountingMastery);
            AccessTools.Field(typeof(CardData), "linkedClass").SetValue(cardData, this.LinkedClass);
            AccessTools.Field(typeof(CardData), "linkedMasteryCard").SetValue(cardData, this.LinkedMasteryCard);
            if (this.Name != null)
            {
                // Use Name field for all languages
                // This should be changed in the future to add proper localization support to custom content
                CustomLocalizationManager.ImportSingleLocalization(this.NameKey, "Text", "", "", "", "", this.Name, this.Name, this.Name, this.Name, this.Name, this.Name);
            }
            AccessTools.Field(typeof(CardData), "nameKey").SetValue(cardData, this.NameKey);
            if (this.Description != null)
            {
                // Use Description field for all languages
                // This should be changed in the future to add proper localization support to custom content
                CustomLocalizationManager.ImportSingleLocalization(this.OverrideDescriptionKey, "Text", "", "", "", "", this.Description, this.Description, this.Description, this.Description, this.Description, this.Description);
            }
            AccessTools.Field(typeof(CardData), "overrideDescriptionKey").SetValue(cardData, this.OverrideDescriptionKey);
            AccessTools.Field(typeof(CardData), "rarity").SetValue(cardData, this.Rarity);
            AccessTools.Field(typeof(CardData), "sharedMasteryCards").SetValue(cardData, this.SharedMasteryCards);
            if (this.SpriteCache != null)
            {
                AccessTools.Field(typeof(CardData), "spriteCache").SetValue(cardData, this.SpriteCache);
            }
            AccessTools.Field(typeof(CardData), "startingUpgrades").SetValue(cardData, this.StartingUpgrades);
            AccessTools.Field(typeof(CardData), "targetless").SetValue(cardData, this.Targetless);
            AccessTools.Field(typeof(CardData), "targetsRoom").SetValue(cardData, this.TargetsRoom);
            foreach (CardTraitData cardTraitData in this.Traits)
            {
                AccessTools.Field(typeof(CardTraitData), "paramCardData").SetValue(cardTraitData, cardData);
            }
            AccessTools.Field(typeof(CardData), "traits").SetValue(cardData, this.Traits);
            AccessTools.Field(typeof(CardData), "triggers").SetValue(cardData, this.Triggers);
            AccessTools.Field(typeof(CardData), "unlockLevel").SetValue(cardData, this.UnlockLevel);

            return(cardData);
        }