Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public static GameObject BuildPrefab(string name, string guid, string defaultSpritePath, IntVector2 hitboxOffset, IntVector2 hitBoxSize, bool HasAiShooter, bool UsesAttackGroup = false)
        {
            if (HasAiShooter)
            {
                var actor = EnemyDatabase.GetOrLoadByGuid("3cadf10c489b461f9fb8814abc1a09c1");
                behaviorSpeculatorPrefab = GameObject.Instantiate(actor.gameObject);
                foreach (Transform child in behaviorSpeculatorPrefab.transform)
                {
                    if (child != behaviorSpeculatorPrefab.transform)
                    {
                        GameObject.DestroyImmediate(child);
                    }
                }
                foreach (var comp in behaviorSpeculatorPrefab.GetComponents <Component>())
                {
                    if (comp.GetType() != typeof(BehaviorSpeculator))
                    {
                        GameObject.DestroyImmediate(comp);
                    }
                }
                GameObject.DontDestroyOnLoad(behaviorSpeculatorPrefab);
                FakePrefab.MarkAsFakePrefab(behaviorSpeculatorPrefab);
                behaviorSpeculatorPrefab.SetActive(false);
            }
            if (EnemyBuilder.Dictionary.ContainsKey(guid))
            {
                ETGModConsole.Log("EnemyBuilder: Yea something went wrong. Complain to Neighborino about it.");
                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 = true;
            prefab.AddComponent <tk2dSpriteAnimator>();
            prefab.AddComponent <AIAnimator>();

            //setup knockback
            var knockback = prefab.AddComponent <KnockbackDoer>();

            knockback.weight = 1;

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

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

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

            aiActor.State            = AIActor.ActorState.Normal;
            aiActor.EnemyGuid        = guid;
            aiActor.CanTargetPlayers = true;
            aiActor.HasShadow        = false;
            aiActor.specRigidbody.CollideWithOthers  = true;
            aiActor.specRigidbody.CollideWithTileMap = true;
            aiActor.specRigidbody.PixelColliders.Clear();
            aiActor.specRigidbody.PixelColliders.Add(new PixelCollider

            {
                ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                CollisionLayer         = CollisionLayer.EnemyCollider,
                IsTrigger = false,
                BagleUseFirstFrameOnly = false,
                SpecifyBagelFrame      = string.Empty,
                BagelColliderNumber    = 0,
                ManualOffsetX          = 0,
                ManualOffsetY          = 0,
                ManualWidth            = 15,
                ManualHeight           = 17,
                ManualDiameter         = 0,
                ManualLeftX            = 0,
                ManualLeftY            = 0,
                ManualRightX           = 0,
                ManualRightY           = 0
            });
            aiActor.specRigidbody.PixelColliders.Add(new PixelCollider
            {
                ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                CollisionLayer         = CollisionLayer.EnemyHitBox,
                IsTrigger = false,
                BagleUseFirstFrameOnly = false,
                SpecifyBagelFrame      = string.Empty,
                BagelColliderNumber    = 0,
                ManualOffsetX          = 0,
                ManualOffsetY          = 0,
                ManualWidth            = 15,
                ManualHeight           = 17,
                ManualDiameter         = 0,
                ManualLeftX            = 0,
                ManualLeftY            = 0,
                ManualRightX           = 0,
                ManualRightY           = 0,
            });
            aiActor.CorpseObject        = EnemyDatabase.GetOrLoadByGuid("01972dee89fc4404a5c408d50007dad5").CorpseObject;
            aiActor.PreventBlackPhantom = false;
            //setup behavior speculator
            var bs = prefab.GetComponent <BehaviorSpeculator>();

            prefab.AddComponent <Tint>();
            bs.MovementBehaviors = new List <MovementBehaviorBase>();
            bs.TargetBehaviors   = new List <TargetBehaviorBase>();
            bs.OverrideBehaviors = new List <OverrideBehaviorBase>();
            bs.OtherBehaviors    = new List <BehaviorBase>();
            if (UsesAttackGroup)
            {
                bs.AttackBehaviorGroup.AttackBehaviors = new List <AttackBehaviorGroup.AttackGroupItem>();
            }
            else
            {
                bs.AttackBehaviors = new List <AttackBehaviorBase>();
            }
            //allows enemies to be tinted
            prefab.AddComponent <AIBulletBank>();
            //Add to enemy database
            EnemyDatabaseEntry enemyDatabaseEntry = new EnemyDatabaseEntry()
            {
                myGuid          = guid,
                placeableWidth  = 2,
                placeableHeight = 2,
                isNormalEnemy   = true
            };

            EnemyDatabase.Instance.Entries.Add(enemyDatabaseEntry);
            EnemyBuilder.Dictionary.Add(guid, prefab);
            //finalize
            GameObject.DontDestroyOnLoad(prefab);
            FakePrefab.MarkAsFakePrefab(prefab);
            prefab.SetActive(false);

            return(prefab);
        }
Ejemplo n.º 3
0
        public static GameObject BuildPrefab(string name, string guid, string defaultSpritePath, IntVector2 hitboxOffset, IntVector2 hitBoxSize, bool HasAiShooter)
        {
            if (EnemyBuilder.Dictionary.ContainsKey(guid))
            {
                ETGModConsole.Log("EnemyBuilder: Yea something went wrong. Complain to Neighborino about it.");
                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 = true;
            prefab.AddComponent <tk2dSpriteAnimator>();
            prefab.AddComponent <AIAnimator>();

            //setup knockback
            var knockback = prefab.AddComponent <KnockbackDoer>();

            knockback.weight = 1;


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

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

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

            aiActor.State     = AIActor.ActorState.Normal;
            aiActor.EnemyGuid = guid;
            AIBulletBank aibulletBank = prefab.AddComponent <AIBulletBank>();

            //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>();

            if (HasAiShooter)
            {
                var actor = EnemyDatabase.GetOrLoadByGuid("01972dee89fc4404a5c408d50007dad5");
                behaviorSpeculatorPrefab = GameObject.Instantiate(actor.gameObject);
                foreach (Transform child in behaviorSpeculatorPrefab.transform)
                {
                    if (child != behaviorSpeculatorPrefab.transform)
                    {
                        GameObject.DestroyImmediate(child);
                    }
                }

                foreach (var comp in behaviorSpeculatorPrefab.GetComponents <Component>())
                {
                    if (comp.GetType() != typeof(BehaviorSpeculator))
                    {
                        GameObject.DestroyImmediate(comp);
                    }
                }

                GameObject.DontDestroyOnLoad(behaviorSpeculatorPrefab);
                FakePrefab.MarkAsFakePrefab(behaviorSpeculatorPrefab);
                behaviorSpeculatorPrefab.SetActive(false);
            }

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

            EnemyDatabase.Instance.Entries.Add(enemyDatabaseEntry);
            EnemyBuilder.Dictionary.Add(guid, prefab);


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

            return(prefab);
        }