Esempio n. 1
0
        /// <summary>
        /// Finishes the item setup, adds it to the item databases, adds an encounter trackable
        /// blah, blah, blah
        /// </summary>
        public static void SetupItem(this PickupObject item, string shortDesc, string longDesc, string idPool = "ItemAPI")
        {
            try
            {
                item.encounterTrackable = null;

                ETGMod.Databases.Items.SetupItem(item, item.name);
                SpriteBuilder.AddToAmmonomicon(item.sprite.GetCurrentSpriteDef());
                item.encounterTrackable.journalData.AmmonomiconSprite = item.sprite.GetCurrentSpriteDef().name;

                item.SetName(item.name);
                item.SetShortDescription(shortDesc);
                item.SetLongDescription(longDesc);

                if (item is PlayerItem)
                {
                    (item as PlayerItem).consumable = false;
                }
                Gungeon.Game.Items.Add(idPool + ":" + item.name.ToLower().Replace(" ", "_"), item);
                ETGMod.Databases.Items.Add(item);
            }
            catch (Exception e)
            {
                ETGModConsole.Log(e.Message);
                ETGModConsole.Log(e.StackTrace);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a tk2dSprite component to an object and adds that sprite to the
        /// ammonomicon for later use. If obj is null, returns a new GameObject with the sprite
        /// </summary>
        public static GameObject AddSpriteToObject(string name, string resourcePath, GameObject obj = null)
        {
            GameObject spriteObject = SpriteBuilder.SpriteFromResource(resourcePath, obj);

            FakePrefab.MarkAsFakePrefab(spriteObject);
            obj.SetActive(false);

            spriteObject.name = name;
            return(spriteObject);
        }
Esempio n. 3
0
        public static tk2dSpriteAnimationClip BuildAnimation(AIAnimator aiAnimator, string name, string spriteDirectory, int fps)
        {
            tk2dSpriteCollectionData collection = aiAnimator.GetComponent <tk2dSpriteCollectionData>();

            if (!collection)
            {
                collection = SpriteBuilder.ConstructCollection(aiAnimator.gameObject, $"{aiAnimator.name}_collection");
            }

            string[]   resources = ResourceExtractor.GetResourceNames();
            List <int> indices   = new List <int>();

            for (int i = 0; i < resources.Length; i++)
            {
                if (resources[i].StartsWith(spriteDirectory.Replace('/', '.'), StringComparison.OrdinalIgnoreCase))
                {
                    indices.Add(SpriteBuilder.AddSpriteToCollection(resources[i], collection));
                }
            }
            tk2dSpriteAnimationClip clip = SpriteBuilder.AddAnimation(aiAnimator.spriteAnimator, collection, indices, name, tk2dSpriteAnimationClip.WrapMode.Loop);

            clip.fps = fps;
            return(clip);
        }
Esempio n. 4
0
        public static GameObject BuildPrefab(string name, string guid, string defaultSpritePath, IntVector2 hitboxOffset, IntVector2 hitBoxSize)
        {
            if (CompanionBuilder.companionDictionary.ContainsKey(guid))
            {
                ETGModConsole.Log("CompanionBuilder: Tried to create two companion prefabs with the same GUID!");
                return(null);
            }
            var prefab = GameObject.Instantiate(behaviorSpeculatorPrefab);

            prefab.name = name;

            //setup misc components
            var sprite = SpriteBuilder.SpriteFromResource(defaultSpritePath, prefab).GetComponent <tk2dSprite>();

            sprite.SetUpSpeculativeRigidbody(hitboxOffset, hitBoxSize).CollideWithOthers = false;
            prefab.AddComponent <tk2dSpriteAnimator>();
            prefab.AddComponent <AIAnimator>();


            //setup health haver
            var healthHaver = prefab.AddComponent <HealthHaver>();

            healthHaver.RegisterBodySprite(sprite);
            healthHaver.PreventAllDamage = true;
            healthHaver.SetHealthMaximum(15000);
            healthHaver.FullHeal();

            //setup AI Actor
            var aiActor = prefab.AddComponent <AIActor>();

            aiActor.State     = AIActor.ActorState.Normal;
            aiActor.EnemyGuid = guid;

            //setup behavior speculator
            var bs = prefab.GetComponent <BehaviorSpeculator>();

            bs.MovementBehaviors = new List <MovementBehaviorBase>();
            bs.AttackBehaviors   = new List <AttackBehaviorBase>();
            bs.TargetBehaviors   = new List <TargetBehaviorBase>();
            bs.OverrideBehaviors = new List <OverrideBehaviorBase>();
            bs.OtherBehaviors    = new List <BehaviorBase>();

            //Add to enemy database
            EnemyDatabaseEntry enemyDatabaseEntry = new EnemyDatabaseEntry()
            {
                myGuid          = guid,
                placeableWidth  = 2,
                placeableHeight = 2,
                isNormalEnemy   = false
            };

            EnemyDatabase.Instance.Entries.Add(enemyDatabaseEntry);
            CompanionBuilder.companionDictionary.Add(guid, prefab);


            //finalize
            GameObject.DontDestroyOnLoad(prefab);
            FakePrefab.MarkAsFakePrefab(prefab);
            prefab.SetActive(false);

            return(prefab);
        }