public static void Init()
        {
            string     itemName     = "Imposter's Knife";
            string     resourceName = "ImposterItems/Resources/imposter_knife";
            GameObject obj          = new GameObject(itemName);
            var        item         = obj.AddComponent <ImpostersKnife>();

            ItemBuilder.AddSpriteToObject(itemName, resourceName, obj);
            string shortDesc = "Wasn't me";
            string longDesc  = "On use, deliver a quick short range, high damage stab towards a direction of your choosing.\n\nSharp, quick, reliable, and most importantly never runs out of ammo. It's no wonder why the knife is such an effective " +
                               "killing device, held back only for it's short range..maybe there's some kind of workaround to that...";

            ItemBuilder.SetupItem(item, shortDesc, longDesc, "spapi");
            ItemBuilder.SetCooldownType(item, ItemBuilder.CooldownType.Damage, 500);
            item.consumable = false;
            item.quality    = ItemQuality.SPECIAL;
            var cm = Instantiate((GameObject)BraveResources.Load("Global Prefabs/_ChallengeManager", ".prefab"));

            item.DarknessEffectShader = (cm.GetComponent <ChallengeManager>().PossibleChallenges.Where(c => c.challenge is DarknessChallengeModifier).First().challenge as DarknessChallengeModifier).DarknessEffectShader;
            VFXPool stabVFX = new VFXPool {
                type = VFXPoolType.All
            };
            VFXComplex complex = new VFXComplex();
            VFXObject  vfxObj  = new VFXObject
            {
                alignment       = VFXAlignment.Fixed,
                attached        = true,
                orphaned        = false,
                persistsOnDeath = false,
                destructible    = true,
                usesZHeight     = true,
                zHeight         = -0.25f
            };
            GameObject stabKnifeObj = SpriteBuilder.SpriteFromResource("ImposterItems/Resources/imposter_knife_stab", new GameObject("ImposterKnifeStab"));

            stabKnifeObj.SetActive(false);
            FakePrefab.MarkAsFakePrefab(stabKnifeObj);
            DontDestroyOnLoad(stabKnifeObj);
            tk2dSpriteAnimator animator = stabKnifeObj.AddComponent <tk2dSpriteAnimator>();

            SpriteBuilder.AddAnimation(animator, stabKnifeObj.GetComponent <tk2dBaseSprite>().Collection, new List <int> {
                stabKnifeObj.GetComponent <tk2dBaseSprite>().spriteId
            }, "stab", tk2dSpriteAnimationClip.WrapMode.Once).fps = 1;
            animator.playAutomatically = true;
            animator.DefaultClipId     = animator.GetClipIdByName("stab");
            SpriteAnimatorKiller killer = stabKnifeObj.AddComponent <SpriteAnimatorKiller>();

            killer.fadeTime             = -1f;
            killer.delayDestructionTime = -1f;
            killer.animator             = animator;
            ConstructOffsetsFromAnchor(stabKnifeObj.GetComponent <tk2dBaseSprite>().GetCurrentSpriteDef(), tk2dBaseSprite.Anchor.MiddleLeft);
            vfxObj.effect   = stabKnifeObj;
            complex.effects = new VFXObject[] { vfxObj };
            stabVFX.effects = new VFXComplex[] { complex };
            item.stabVfx    = stabVFX;
            Destroy(cm);
            ImpostersKnifeId = item.PickupObjectId;
            Game.Items.Rename("spapi:imposter's_knife", "spapi:imposters_knife");
        }
Example #2
0
        private void BeginState(FireState state)
        {
            switch (state)
            {
            case FireState.Idle:
                if (HideGun)
                {
                    m_aiShooter.ToggleGunAndHandRenderers(true, "ChargeBehavior");
                }
                m_aiActor.BehaviorOverridesVelocity = false;
                m_aiAnimator.LockFacingDirection    = false;
                break;

            case FireState.Priming:
                if (HideGun)
                {
                    m_aiShooter.ToggleGunAndHandRenderers(false, "ChargeBehavior");
                }
                m_aiAnimator.PlayUntilFinished(primeAnim, true, null, -1f, false);
                if (primeTime > 0f)
                {
                    m_timer = primeTime;
                }
                else
                {
                    m_timer = m_aiAnimator.CurrentClipLength;
                }
                if (stopDuringPrime)
                {
                    m_aiActor.ClearPath();
                    m_aiActor.BehaviorOverridesVelocity = true;
                    m_aiActor.BehaviorVelocity          = Vector2.zero;
                }
                else
                {
                    m_aiActor.BehaviorOverridesVelocity = true;
                    m_aiActor.BehaviorVelocity          = m_aiActor.specRigidbody.Velocity;
                }
                break;

            case FireState.Charging:
                if (HideGun)
                {
                    m_aiShooter.ToggleGunAndHandRenderers(false, "ChargeBehavior");
                }
                m_chargeTime = 0f;
                Vector2 vector = m_aiActor.TargetRigidbody.specRigidbody.GetUnitCenter(ColliderType.HitBox);
                if (leadAmount > 0f)
                {
                    Vector2 b = vector + m_aiActor.TargetRigidbody.specRigidbody.Velocity * 0.75f;
                    b      = BraveMathCollege.GetPredictedPosition(vector, m_aiActor.TargetVelocity, m_aiActor.specRigidbody.UnitCenter, chargeSpeed);
                    vector = Vector2.Lerp(vector, b, leadAmount);
                }
                m_aiActor.ClearPath();
                m_aiActor.BehaviorOverridesVelocity = true;
                m_currentSpeed                       = ((chargeAcceleration <= 0f) ? chargeSpeed : 0f);
                m_chargeDirection                    = (vector - m_aiActor.specRigidbody.UnitCenter).ToAngle();
                m_aiActor.BehaviorVelocity           = BraveMathCollege.DegreesToVector(m_chargeDirection, m_currentSpeed);
                m_aiAnimator.LockFacingDirection     = true;
                m_aiAnimator.FacingDirection         = m_chargeDirection;
                m_aiActor.CollisionKnockbackStrength = chargeKnockback;
                m_aiActor.CollisionDamage            = chargeDamage;
                if (hitVfx)
                {
                    VFXObject vfxobject = new VFXObject();
                    vfxobject.effect = hitVfx;
                    VFXComplex vfxcomplex = new VFXComplex();
                    vfxcomplex.effects = new VFXObject[] { vfxobject };
                    VFXPool vfxpool = new VFXPool();
                    vfxpool.type           = VFXPoolType.Single;
                    vfxpool.effects        = new VFXComplex[] { vfxcomplex };
                    m_aiActor.CollisionVFX = vfxpool;
                }
                if (nonActorHitVfx)
                {
                    VFXObject vfxobject2 = new VFXObject();
                    vfxobject2.effect = nonActorHitVfx;
                    VFXComplex vfxcomplex2 = new VFXComplex();
                    vfxcomplex2.effects = new VFXObject[] { vfxobject2 };
                    VFXPool vfxpool2 = new VFXPool();
                    vfxpool2.type    = VFXPoolType.Single;
                    vfxpool2.effects = new VFXComplex[] { vfxcomplex2 };
                    m_aiActor.NonActorCollisionVFX = vfxpool2;
                }
                m_aiActor.PathableTiles = (CellTypes.FLOOR | CellTypes.PIT);
                if (switchCollidersOnCharge)
                {
                    m_enemyCollider.CollisionLayer = CollisionLayer.TileBlocker;
                    m_enemyHitbox.Enabled          = false;
                    m_projectileCollider.Enabled   = true;
                }
                m_aiActor.DoDustUps      = chargeDustUps;
                m_aiActor.DustUpInterval = chargeDustUpInterval;
                m_aiAnimator.PlayUntilFinished(chargeAnim, true, null, -1f, false);
                if (launchVfx)
                {
                    SpawnManager.SpawnVFX(launchVfx, m_aiActor.specRigidbody.UnitCenter, Quaternion.identity);
                }
                if (trailVfx)
                {
                    m_trailVfx = SpawnManager.SpawnParticleSystem(trailVfx, m_aiActor.sprite.WorldCenter, Quaternion.Euler(0f, 0f, m_chargeDirection));
                    if (trailVfxParent)
                    {
                        m_trailVfx.transform.parent = trailVfxParent;
                    }
                    else
                    {
                        m_trailVfx.transform.parent = m_aiActor.transform;
                    }
                    ParticleKiller component = m_trailVfx.GetComponent <ParticleKiller>();
                    if (component != null)
                    {
                        component.Awake();
                    }
                }
                if (bulletScript != null && !bulletScript.IsNull)
                {
                    Fire();
                }
                m_aiActor.specRigidbody.ForceRegenerate(null, null);
                break;

            case FireState.Bouncing:
                m_aiAnimator.PlayUntilFinished(hitAnim, true, null, -1f, false);
                break;
            }
        }
Example #3
0
        public static void Init()
        {
            Gun gun = ETGMod.Databases.Items.NewGun("High-Quality Gun", "hd");

            Game.Items.Rename("outdated_gun_mods:high-quality_gun", "spapi:high_quality_gun");
            gun.gameObject.AddComponent <HDGun>();
            GunExt.SetShortDescription(gun, "HD!");
            GunExt.SetLongDescription(gun, "Bullets charm enemies.\n\nThis gun is just magnum, but but has 4 times more pixels. Because of that, it seems very weird among all other guns, but at the same time looks kinda cool!");
            GunExt.SetupSprite(gun, null, "hd_idle_001", 8);
            GunExt.SetAnimationFPS(gun, gun.shootAnimation, 13);
            GunExt.SetAnimationFPS(gun, gun.reloadAnimation, 12);
            GunExt.AddProjectileModuleFrom(gun, Toolbox.GetGunById(38), true, false);
            gun.gunSwitchGroup = "Magnum";
            VFXPool pool = new VFXPool();

            pool.type = VFXPoolType.All;
            VFXComplex complex = new VFXComplex();
            VFXObject  vfObj   = new VFXObject();
            GameObject obj     = new GameObject("hd_smoke");

            obj.SetActive(false);
            FakePrefab.MarkAsFakePrefab(obj);
            UnityEngine.Object.DontDestroyOnLoad(obj);
            tk2dSprite              sprite     = obj.AddComponent <tk2dSprite>();
            tk2dSpriteAnimator      animator   = obj.AddComponent <tk2dSpriteAnimator>();
            tk2dSpriteAnimationClip clip       = new tk2dSpriteAnimationClip();
            GameObject              origEffect = Toolbox.GetGunById(38).muzzleFlashEffects.effects[0].effects[0].effect;
            VFXObject origVfEffect             = Toolbox.GetGunById(38).muzzleFlashEffects.effects[0].effects[0];

            clip.fps    = origEffect.GetAnyComponent <tk2dSpriteAnimator>().DefaultClip.fps;
            clip.frames = new tk2dSpriteAnimationFrame[0];
            for (int i = 1; i < 4; i++)
            {
                tk2dSpriteAnimationFrame frame = new tk2dSpriteAnimationFrame();
                frame.spriteId = Toolbox.VFXCollection.GetSpriteIdByName("hd_smoke_00" + i);
                Toolbox.VFXCollection.inst.spriteDefinitions[frame.spriteId] = Toolbox.VFXCollection.inst.spriteDefinitions[origEffect.GetAnyComponent <tk2dSpriteAnimator>().DefaultClip.frames[i - 1].spriteId].CopyDefinitionFrom();
                frame.spriteCollection = Toolbox.VFXCollection;
                clip.frames            = clip.frames.Concat(new tk2dSpriteAnimationFrame[] { frame }).ToArray();
            }
            clip.wrapMode = tk2dSpriteAnimationClip.WrapMode.Once;
            clip.name     = "start";
            animator.spriteAnimator.Library       = animator.gameObject.AddComponent <tk2dSpriteAnimation>();
            animator.spriteAnimator.Library.clips = new tk2dSpriteAnimationClip[] { clip };
            animator.playAutomatically            = true;
            animator.DefaultClipId = animator.GetClipIdByName("start");
            SpriteAnimatorKiller kill = animator.gameObject.AddComponent <SpriteAnimatorKiller>();

            kill.fadeTime             = -1f;
            kill.animator             = animator;
            kill.delayDestructionTime = -1f;
            obj.gameObject.SetLayerRecursively(LayerMask.NameToLayer("Unpixelated"));
            vfObj.orphaned        = origVfEffect.orphaned;
            vfObj.attached        = origVfEffect.attached;
            vfObj.persistsOnDeath = origVfEffect.persistsOnDeath;
            vfObj.usesZHeight     = origVfEffect.usesZHeight;
            vfObj.zHeight         = origVfEffect.zHeight;
            vfObj.alignment       = origVfEffect.alignment;
            vfObj.destructible    = origVfEffect.destructible;
            vfObj.effect          = obj;
            VFXObject  vfObj2 = new VFXObject();
            GameObject obj2   = new GameObject("hd_flare");

            obj2.SetActive(false);
            FakePrefab.MarkAsFakePrefab(obj2);
            UnityEngine.Object.DontDestroyOnLoad(obj2);
            tk2dSprite              sprite2     = obj2.AddComponent <tk2dSprite>();
            tk2dSpriteAnimator      animator2   = obj2.AddComponent <tk2dSpriteAnimator>();
            tk2dSpriteAnimationClip clip2       = new tk2dSpriteAnimationClip();
            GameObject              origEffect2 = Toolbox.GetGunById(38).muzzleFlashEffects.effects[0].effects[1].effect;
            VFXObject origVfEffect2             = Toolbox.GetGunById(38).muzzleFlashEffects.effects[0].effects[1];

            clip2.fps    = origEffect2.GetAnyComponent <tk2dSpriteAnimator>().DefaultClip.fps;
            clip2.frames = new tk2dSpriteAnimationFrame[0];
            for (int i = 1; i < 6; i++)
            {
                tk2dSpriteAnimationFrame frame = new tk2dSpriteAnimationFrame();
                frame.spriteId = Toolbox.VFXCollection.GetSpriteIdByName("hd_flare_00" + i);
                Toolbox.VFXCollection.inst.spriteDefinitions[frame.spriteId] = Toolbox.VFXCollection.inst.spriteDefinitions[origEffect2.GetAnyComponent <tk2dSpriteAnimator>().DefaultClip.frames[i - 1].spriteId].CopyDefinitionFrom();
                frame.spriteCollection = Toolbox.VFXCollection;
                clip2.frames           = clip2.frames.Concat(new tk2dSpriteAnimationFrame[] { frame }).ToArray();
            }
            clip2.wrapMode = tk2dSpriteAnimationClip.WrapMode.Once;
            clip2.name     = "start";
            animator2.spriteAnimator.Library       = animator2.gameObject.AddComponent <tk2dSpriteAnimation>();
            animator2.spriteAnimator.Library.clips = new tk2dSpriteAnimationClip[] { clip2 };
            animator2.playAutomatically            = true;
            animator2.DefaultClipId = animator2.GetClipIdByName("start");
            SpriteAnimatorKiller kill2 = animator2.gameObject.AddComponent <SpriteAnimatorKiller>();

            kill2.fadeTime             = -1f;
            kill2.animator             = animator2;
            kill2.delayDestructionTime = -1f;
            obj2.gameObject.SetLayerRecursively(LayerMask.NameToLayer("Unpixelated"));
            vfObj2.orphaned        = origVfEffect2.orphaned;
            vfObj2.attached        = origVfEffect2.attached;
            vfObj2.persistsOnDeath = origVfEffect2.persistsOnDeath;
            vfObj2.usesZHeight     = origVfEffect2.usesZHeight;
            vfObj2.zHeight         = origVfEffect2.zHeight;
            vfObj2.alignment       = origVfEffect2.alignment;
            vfObj2.destructible    = origVfEffect2.destructible;
            vfObj2.effect          = obj2;
            complex.effects        = new VFXObject[] { vfObj, vfObj2 };
            pool.effects           = new VFXComplex[] { complex };
            gun.muzzleFlashEffects = pool;
            Projectile projectile = UnityEngine.Object.Instantiate <Projectile>((PickupObjectDatabase.GetById(38) as Gun).DefaultModule.projectiles[0]);

            projectile.gameObject.SetActive(false);
            FakePrefab.MarkAsFakePrefab(projectile.gameObject);
            UnityEngine.Object.DontDestroyOnLoad(projectile);
            gun.DefaultModule.projectiles[0] = projectile;
            gun.OverrideAngleSnap            = null;
            projectile.transform.parent      = gun.barrelOffset;
            projectile.AppliesCharm          = true;
            projectile.CharmApplyChance      = 100f;
            projectile.baseData.damage       = 20f;
            projectile.charmEffect           = (PickupObjectDatabase.GetById(527) as BulletStatusEffectItem).CharmModifierEffect;
            projectile.GetAnySprite().spriteId = ETGMod.Databases.Items.ProjectileCollection.inst.GetSpriteIdByName("hd_bullet_001");
            ETGMod.Databases.Items.ProjectileCollection.inst.spriteDefinitions[projectile.GetAnySprite().spriteId] =
                ETGMod.Databases.Items.ProjectileCollection.inst.spriteDefinitions[(PickupObjectDatabase.GetById(38) as Gun).DefaultModule.projectiles[0].GetAnySprite().spriteId].CopyDefinitionFrom();
            gun.DefaultModule.numberOfShotsInClip = 8;
            projectile.name = "Charmingly_HD_Projectile";
            gun.reloadTime  = 1.0f;
            gun.SetBaseMaxAmmo(280);
            gun.quality = PickupObject.ItemQuality.S;
            gun.encounterTrackable.EncounterGuid = "hd";
            gun.gunClass = GunClass.PISTOL;
            GameObject shellCasing = UnityEngine.Object.Instantiate(Toolbox.GetGunById(38).shellCasing);

            shellCasing.SetActive(false);
            FakePrefab.MarkAsFakePrefab(shellCasing);
            tk2dSpriteAnimator      gunAnim    = gun.GetComponent <tk2dSpriteAnimator>();
            tk2dSpriteAnimationClip reloadClip = gunAnim.GetClipByName(gun.reloadAnimation);

            reloadClip.frames = new tk2dSpriteAnimationFrame[0];
            foreach (string text in reloadFrames)
            {
                tk2dSpriteAnimationFrame frame = new tk2dSpriteAnimationFrame {
                    spriteCollection = ETGMod.Databases.Items.WeaponCollection, spriteId = ETGMod.Databases.Items.WeaponCollection.GetSpriteIdByName(text)
                };
                reloadClip.frames = reloadClip.frames.Concat(new tk2dSpriteAnimationFrame[] { frame }).ToArray();
            }
            UnityEngine.Object.DontDestroyOnLoad(shellCasing);
            shellCasing.GetAnyComponent <tk2dBaseSprite>().SetSprite(Toolbox.VFXCollection, Toolbox.VFXCollection.GetSpriteIdByName("hd_shell_001"));
            Toolbox.VFXCollection.spriteDefinitions[shellCasing.GetAnyComponent <tk2dBaseSprite>().spriteId] =
                Toolbox.GetGunById(38).shellCasing.GetAnyComponent <tk2dBaseSprite>().Collection.spriteDefinitions[Toolbox.GetGunById(38).shellCasing.GetAnyComponent <tk2dBaseSprite>().spriteId].CopyDefinitionFrom();
            shellCasing.AddComponent <AlwaysUnpixeledBehaviour>();
            gun.shellCasing            = shellCasing;
            gun.shellsToLaunchOnFire   = 0;
            gun.shellsToLaunchOnReload = 6;
            gun.reloadShellLaunchFrame = 2;
            gun.barrelOffset.transform.localPosition = new Vector3(1.0625f, 0.5625f, 0f);
            ETGMod.Databases.Items.Add(gun, null, "ANY");
            gun.AddToCursulaShop();
            gun.AddToBlacksmithShop();
            gun.RemovePeskyQuestionmark();
            gun.PlaceItemInAmmonomiconAfterItemById(38);
            ItemBuilder.AddPassiveStatModifier(gun, PlayerStats.StatType.Coolness, 3, StatModifier.ModifyMethod.ADDITIVE);
            tk2dSpriteDefinition ammonomiconDef = AmmonomiconController.ForceInstance.EncounterIconCollection.spriteDefinitions[AmmonomiconController.ForceInstance.EncounterIconCollection.GetSpriteIdByName("hd_idle_001")];

            ammonomiconDef.position1                  = new Vector3(ammonomiconDef.position1.x / 2, ammonomiconDef.position1.y / 2, ammonomiconDef.position1.z / 2);
            ammonomiconDef.position2                  = new Vector3(ammonomiconDef.position2.x / 2, ammonomiconDef.position2.y / 2, ammonomiconDef.position2.z / 2);
            ammonomiconDef.position3                  = new Vector3(ammonomiconDef.position3.x / 2, ammonomiconDef.position3.y / 2, ammonomiconDef.position3.z / 2);
            ammonomiconDef.boundsDataCenter           = new Vector3(ammonomiconDef.boundsDataCenter.x / 2, ammonomiconDef.boundsDataCenter.y / 2, ammonomiconDef.boundsDataCenter.z / 2);
            ammonomiconDef.boundsDataExtents          = new Vector3(ammonomiconDef.boundsDataExtents.x / 2, ammonomiconDef.boundsDataExtents.y / 2, ammonomiconDef.boundsDataExtents.z / 2);
            ammonomiconDef.untrimmedBoundsDataCenter  = new Vector3(ammonomiconDef.untrimmedBoundsDataCenter.x / 2, ammonomiconDef.untrimmedBoundsDataCenter.y / 2, ammonomiconDef.untrimmedBoundsDataCenter.z / 2);
            ammonomiconDef.untrimmedBoundsDataExtents = new Vector3(ammonomiconDef.untrimmedBoundsDataExtents.x / 2, ammonomiconDef.untrimmedBoundsDataExtents.y / 2, ammonomiconDef.untrimmedBoundsDataExtents.z / 2);
            List <tk2dSpriteDefinition> affected = new List <tk2dSpriteDefinition>();

            foreach (tk2dSpriteAnimationClip clip3 in gun.GetGunAnimationClips())
            {
                if (clip3.frames != null)
                {
                    foreach (tk2dSpriteAnimationFrame frame in clip3.frames)
                    {
                        if (frame != null && frame.spriteCollection != null)
                        {
                            tk2dSpriteDefinition def = frame.spriteCollection.spriteDefinitions[frame.spriteId];
                            if (def != null && !affected.Contains(def))
                            {
                                def.position1                  = new Vector3(def.position1.x / 2, def.position1.y / 2, def.position1.z / 2);
                                def.position2                  = new Vector3(def.position2.x / 2, def.position2.y / 2, def.position2.z / 2);
                                def.position3                  = new Vector3(def.position3.x / 2, def.position3.y / 2, def.position3.z / 2);
                                def.boundsDataCenter           = new Vector3(def.boundsDataCenter.x / 2, def.boundsDataCenter.y / 2, def.boundsDataCenter.z / 2);
                                def.boundsDataExtents          = new Vector3(def.boundsDataExtents.x / 2, def.boundsDataExtents.y / 2, def.boundsDataExtents.z / 2);
                                def.untrimmedBoundsDataCenter  = new Vector3(def.untrimmedBoundsDataCenter.x / 2, def.untrimmedBoundsDataCenter.y / 2, def.untrimmedBoundsDataCenter.z / 2);
                                def.untrimmedBoundsDataExtents = new Vector3(def.untrimmedBoundsDataExtents.x / 2, def.untrimmedBoundsDataExtents.y / 2, def.untrimmedBoundsDataExtents.z / 2);
                                def.RemoveOffset();
                                affected.Add(def);
                            }
                        }
                    }
                }
            }
            affected.Clear();
            int index = 0;

            foreach (tk2dSpriteAnimationFrame frame in gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.idleAnimation).frames)
            {
                tk2dSpriteDefinition def = frame.spriteCollection.spriteDefinitions[frame.spriteId];
                if (def != null && !affected.Contains(def))
                {
                    def.MakeOffset(offsets[0][index]);
                    affected.Add(def);
                }
                index++;
            }
            index = 0;
            foreach (tk2dSpriteAnimationFrame frame in gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.shootAnimation).frames)
            {
                tk2dSpriteDefinition def = frame.spriteCollection.spriteDefinitions[frame.spriteId];
                if (def != null && !affected.Contains(def))
                {
                    def.MakeOffset(offsets[1][index]);
                    affected.Add(def);
                }
                index++;
            }
            index = 0;
            foreach (tk2dSpriteAnimationFrame frame in gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.reloadAnimation).frames)
            {
                tk2dSpriteDefinition def = frame.spriteCollection.spriteDefinitions[frame.spriteId];
                if (def != null && !affected.Contains(def))
                {
                    def.MakeOffset(offsets[2][index]);
                    affected.Add(def);
                }
                index++;
            }
            AdvancedHoveringGunSynergyProcessor processor = gun.gameObject.AddComponent <AdvancedHoveringGunSynergyProcessor>();

            processor.RequiredSynergy              = "#LOW-QUALITY_HELP";
            processor.TargetGunID                  = 38;
            processor.UsesMultipleGuns             = false;
            processor.PositionType                 = HoveringGunController.HoverPosition.CIRCULATE;
            processor.AimType                      = HoveringGunController.AimType.PLAYER_AIM;
            processor.FireType                     = HoveringGunController.FireType.ON_RELOAD;
            processor.FireCooldown                 = 0.2f;
            processor.FireDuration                 = 0f;
            processor.OnlyOnEmptyReload            = false;
            processor.ShootAudioEvent              = "";
            processor.OnEveryShotAudioEvent        = "";
            processor.FinishedShootingAudioEvent   = "";
            processor.Trigger                      = AdvancedHoveringGunSynergyProcessor.TriggerStyle.CONSTANT;
            processor.NumToTrigger                 = 1;
            processor.TriggerDuration              = 0f;
            processor.ConsumesTargetGunAmmo        = false;
            processor.ChanceToConsumeTargetGunAmmo = 0f;
        }
Example #4
0
        /// <summary>
        /// Used to create new VFX. Place sprites inside of Mods/YourModFolder/sprites/VFX Collection, inside the EtG directory. Each parameter that is a list must have an entry for each sprite of the animation
        /// </summary>
        /// <param name="name">The name of the VFX</param>
        /// <param name="spriteNames">The name of the sprites for the VFX, like VFX_001, VFX_002, etc.</param>
        /// <param name="fps">The frame rate the animation will play at</param>
        /// <param name="spriteSizes">The size of each sprite in the animation. Must have an IntVector2 entry for each sprite in the animation</param>
        /// <param name="anchors">I don't know what exactly this does</param>
        /// <param name="manualOffsets">I don't know what exactly this does</param>
        /// <param name="orphaned">I don't know what exactly this does</param>
        /// <param name="attached">I don't know what exactly this does</param>
        /// <param name="persistsOnDeath">Best left false</param>
        /// <param name="usesZHeight">Change if needed</param>
        /// <param name="zHeight">Change if needed, but usually left at 0</param>
        /// <param name="alignment">Leave at Fixed</param>
        /// <param name="destructible">Always set to true</param>
        /// <param name="emissivePowers">Doesn't seem to work, set all entries at 0. Might cause bugs if tinkered with</param>
        /// <param name="emissiveColors">Does't seem to work, set all entries to VFXLibrary.emptyColor. Might cause bugs if tinkered with</param>
        /// <returns></returns>
        public static VFXPool CreateMuzzleflash(string name, List <string> spriteNames, int fps, List <IntVector2> spriteSizes, List <tk2dBaseSprite.Anchor> anchors, List <Vector2> manualOffsets, bool orphaned, bool attached, bool persistsOnDeath,
                                                bool usesZHeight, float zHeight, VFXAlignment alignment, bool destructible, List <float> emissivePowers, List <Color> emissiveColors)
        {
            VFXPool pool = new VFXPool();

            pool.type = VFXPoolType.All;
            VFXComplex complex = new VFXComplex();
            VFXObject  vfObj   = new VFXObject();
            GameObject obj     = new GameObject(name);

            obj.SetActive(false);
            FakePrefab.MarkAsFakePrefab(obj);
            UnityEngine.Object.DontDestroyOnLoad(obj);
            tk2dSprite              sprite   = obj.AddComponent <tk2dSprite>();
            tk2dSpriteAnimator      animator = obj.AddComponent <tk2dSpriteAnimator>();
            tk2dSpriteAnimationClip clip     = new tk2dSpriteAnimationClip();

            clip.fps    = fps;
            clip.frames = new tk2dSpriteAnimationFrame[0];
            for (int i = 0; i < spriteNames.Count; i++)
            {
                string                spriteName   = spriteNames[i];
                IntVector2            spriteSize   = spriteSizes[i];
                tk2dBaseSprite.Anchor anchor       = anchors[i];
                Vector2               manualOffset = manualOffsets[i];
                float emissivePower            = emissivePowers[i];
                Color emissiveColor            = emissiveColors[i];
                tk2dSpriteAnimationFrame frame = new tk2dSpriteAnimationFrame();
                frame.spriteId = VFXCollection.GetSpriteIdByName(spriteName);
                tk2dSpriteDefinition def = SetupDefinitionForShellSprite(spriteName, frame.spriteId, spriteSize.x, spriteSize.y);
                def.ConstructOffsetsFromAnchor(anchor, def.position3);
                def.MakeOffset(manualOffset);
                def.material.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
                def.material.SetFloat("_EmissiveColorPower", emissivePower);
                def.material.SetColor("_EmissiveColor", emissiveColor);
                def.material.SetTexture("_MainTex", def.material.GetTexture("_MainTex"));
                def.materialInst.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
                def.materialInst.SetFloat("_EmissiveColorPower", emissivePower);
                def.materialInst.SetColor("_EmissiveColor", emissiveColor);
                def.materialInst.SetTexture("_MainTex", def.materialInst.GetTexture("_MainTex"));
                frame.spriteCollection = VFXCollection;
                clip.frames            = clip.frames.Concat(new tk2dSpriteAnimationFrame[] { frame }).ToArray();
            }
            sprite.renderer.material.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
            sprite.renderer.material.SetFloat("_EmissiveColorPower", emissivePowers[0]);
            sprite.renderer.material.SetColor("_EmissiveColor", emissiveColors[0]);
            sprite.renderer.material.SetTexture("_MainTex", sprite.renderer.material.GetTexture("_MainTex"));
            clip.wrapMode = tk2dSpriteAnimationClip.WrapMode.Once;
            clip.name     = "start";
            animator.spriteAnimator.Library         = animator.gameObject.AddComponent <tk2dSpriteAnimation>();
            animator.spriteAnimator.Library.clips   = new tk2dSpriteAnimationClip[] { clip };
            animator.spriteAnimator.Library.enabled = true;
            SpriteAnimatorKiller kill = animator.gameObject.AddComponent <SpriteAnimatorKiller>();

            kill.fadeTime             = -1f;
            kill.animator             = animator;
            kill.delayDestructionTime = -1f;
            vfObj.orphaned            = orphaned;
            vfObj.attached            = attached;
            vfObj.persistsOnDeath     = persistsOnDeath;
            vfObj.usesZHeight         = usesZHeight;
            vfObj.zHeight             = zHeight;
            vfObj.alignment           = alignment;
            vfObj.destructible        = destructible;
            vfObj.effect               = obj;
            complex.effects            = new VFXObject[] { vfObj };
            pool.effects               = new VFXComplex[] { complex };
            animator.playAutomatically = true;
            animator.DefaultClipId     = animator.GetClipIdByName("start");
            return(pool);
        }
Example #5
0
        public static VFXPool CreateVFXPool(string name, List <string> spritePaths, int fps, IntVector2 Dimensions, tk2dBaseSprite.Anchor anchor, bool usesZHeight, float zHeightOffset, bool persist = false, VFXAlignment alignment = VFXAlignment.NormalAligned, float emissivePower = -1, Color?emissiveColour = null)
        {
            GameObject Obj  = new GameObject(name);
            VFXPool    pool = new VFXPool();

            pool.type = VFXPoolType.All;
            VFXComplex complex = new VFXComplex();
            VFXObject  vfObj   = new VFXObject();

            Obj.SetActive(false);
            FakePrefab.MarkAsFakePrefab(Obj);
            UnityEngine.Object.DontDestroyOnLoad(Obj);

            tk2dSpriteCollectionData VFXSpriteCollection = SpriteBuilder.ConstructCollection(Obj, (name + "_Collection"));
            int spriteID = SpriteBuilder.AddSpriteToCollection(spritePaths[0], VFXSpriteCollection);

            tk2dSprite sprite = Obj.GetOrAddComponent <tk2dSprite>();

            sprite.SetSprite(VFXSpriteCollection, spriteID);
            tk2dSpriteDefinition defaultDef = sprite.GetCurrentSpriteDef();

            defaultDef.colliderVertices = new Vector3[] {
                new Vector3(0f, 0f, 0f),
                new Vector3((Dimensions.x / 16), (Dimensions.y / 16), 0f)
            };

            tk2dSpriteAnimator  animator  = Obj.GetOrAddComponent <tk2dSpriteAnimator>();
            tk2dSpriteAnimation animation = Obj.GetOrAddComponent <tk2dSpriteAnimation>();

            animation.clips  = new tk2dSpriteAnimationClip[0];
            animator.Library = animation;
            tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
            {
                name = "start", frames = new tk2dSpriteAnimationFrame[0], fps = fps
            };
            List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();

            for (int i = 0; i < spritePaths.Count; i++)
            {
                tk2dSpriteCollectionData collection = VFXSpriteCollection;
                int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(spritePaths[i], collection);
                tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                frameDef.ConstructOffsetsFromAnchor(anchor);
                frameDef.colliderVertices = defaultDef.colliderVertices;
                if (emissivePower > 0)
                {
                    frameDef.material.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
                }
                if (emissivePower > 0)
                {
                    frameDef.material.SetFloat("_EmissiveColorPower", emissivePower);
                }
                if (emissiveColour != null)
                {
                    frameDef.material.SetColor("_EmissiveColor", (Color)emissiveColour);
                }
                if (emissivePower > 0)
                {
                    frameDef.materialInst.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
                }
                if (emissivePower > 0)
                {
                    frameDef.materialInst.SetFloat("_EmissiveColorPower", emissivePower);
                }
                if (emissiveColour != null)
                {
                    frameDef.materialInst.SetColor("_EmissiveColor", (Color)emissiveColour);
                }
                frames.Add(new tk2dSpriteAnimationFrame {
                    spriteId = frameSpriteId, spriteCollection = collection
                });
            }
            if (emissivePower > 0)
            {
                sprite.renderer.material.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
            }
            if (emissivePower > 0)
            {
                sprite.renderer.material.SetFloat("_EmissiveColorPower", emissivePower);
            }
            if (emissiveColour != null)
            {
                sprite.renderer.material.SetColor("_EmissiveColor", (Color)emissiveColour);
            }
            clip.frames     = frames.ToArray();
            clip.wrapMode   = tk2dSpriteAnimationClip.WrapMode.Once;
            animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
            if (!persist)
            {
                SpriteAnimatorKiller kill = animator.gameObject.AddComponent <SpriteAnimatorKiller>();
                kill.fadeTime             = -1f;
                kill.animator             = animator;
                kill.delayDestructionTime = -1f;
            }
            animator.playAutomatically = true;
            animator.DefaultClipId     = animator.GetClipIdByName("start");
            vfObj.attached             = true;
            vfObj.persistsOnDeath      = persist;
            vfObj.usesZHeight          = usesZHeight;
            vfObj.zHeight      = zHeightOffset;
            vfObj.alignment    = alignment;
            vfObj.destructible = false;
            vfObj.effect       = Obj;
            complex.effects    = new VFXObject[] { vfObj };
            pool.effects       = new VFXComplex[] { complex };
            return(pool);
        }
Example #6
0
        public static void Init()
        {
            Gun gun = ETGMod.Databases.Items.NewGun("Lich's Gun", "lichsgun");

            Game.Items.Rename("outdated_gun_mods:lich's_gun", "spapi:lichs_gun");
            GunExt.SetShortDescription(gun, "Bullet Dance");
            GunExt.SetLongDescription(gun, "This is Gun from Gungeon Master.");
            GunExt.SetupSprite(gun, null, "lichsgun_idle_001", 10);
            GunExt.SetAnimationFPS(gun, gun.shootAnimation, 12);
            GunExt.AddProjectileModuleFrom(gun, "klobb", true, false);
            gun.DefaultModule.shootStyle    = ProjectileModule.ShootStyle.SemiAutomatic;
            gun.DefaultModule.angleVariance = 0;
            gun.DefaultModule.ammoType      = GameUIAmmoType.AmmoType.MEDIUM_BULLET;
            InputGuidedProjectile projectile = CopyFields <InputGuidedProjectile>(UnityEngine.Object.Instantiate((PickupObjectDatabase.GetById(183) as Gun).DefaultModule.projectiles[0]));

            projectile.trackingSpeed = 500f;
            projectile.dumbfireTime  = -1f;
            projectile.gameObject.SetActive(false);
            FakePrefab.MarkAsFakePrefab(projectile.gameObject);
            UnityEngine.Object.DontDestroyOnLoad(projectile);
            gun.DefaultModule.projectiles[0] = projectile;
            projectile.baseData.damage       = 5f;
            projectile.shouldRotate          = true;
            projectile.name           = "LichsGun_Projectile";
            projectile.baseData.range = 18f;
            projectile.baseData.speed = 22f;
            SetProjectileSpriteRight(projectile, "lichsgun_projectile_001", 6, 6, false, tk2dBaseSprite.Anchor.MiddleCenter, true, false, null, null, null, null, (PickupObjectDatabase.GetById(183) as Gun).DefaultModule.projectiles[0]);
            gun.reloadClipLaunchFrame             = 0;
            gun.DefaultModule.cooldownTime        = 0.1f;
            gun.DefaultModule.numberOfShotsInClip = 6;
            for (int i = 0; i < gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.shootAnimation).frames.Length; i++)
            {
                gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.shootAnimation).frames[i].triggerEvent = true;
                tk2dSpriteDefinition def = gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.shootAnimation).frames[i].spriteCollection.spriteDefinitions[gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.shootAnimation).frames[i].spriteId];
                Vector2 offset           = new Vector2(((float)fireOffsets[i].x) / 16f, ((float)fireOffsets[i].y) / 16f);
                LichsBookItem.MakeOffset(def, offset);
            }
            for (int i = 0; i < gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.reloadAnimation).frames.Length; i++)
            {
                gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.reloadAnimation).frames[i].triggerEvent = true;
                tk2dSpriteDefinition def = gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.reloadAnimation).frames[i].spriteCollection.spriteDefinitions[gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.reloadAnimation).frames[i].spriteId];
                Vector2 offset           = new Vector2(((float)reloadOffsets[i].x) / 16f, ((float)reloadOffsets[i].y) / 16f);
                LichsBookItem.MakeOffset(def, offset);
            }
            tk2dSpriteAnimationClip reloadClip = gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.reloadAnimation);

            reloadClip.frames = new tk2dSpriteAnimationFrame[0];
            foreach (string text in reloadFrames)
            {
                tk2dSpriteAnimationFrame frame = new tk2dSpriteAnimationFrame {
                    spriteCollection = ETGMod.Databases.Items.WeaponCollection, spriteId = ETGMod.Databases.Items.WeaponCollection.GetSpriteIdByName(text)
                };
                reloadClip.frames = reloadClip.frames.Concat(new tk2dSpriteAnimationFrame[] { frame }).ToArray();
            }
            tk2dSpriteAnimationClip shootClip = gun.GetComponent <tk2dSpriteAnimator>().GetClipByName(gun.shootAnimation);

            shootClip.frames = new tk2dSpriteAnimationFrame[0];
            foreach (string text in shootFrames)
            {
                tk2dSpriteAnimationFrame frame = new tk2dSpriteAnimationFrame {
                    spriteCollection = ETGMod.Databases.Items.WeaponCollection, spriteId = ETGMod.Databases.Items.WeaponCollection.GetSpriteIdByName(text)
                };
                shootClip.frames = shootClip.frames.Concat(new tk2dSpriteAnimationFrame[] { frame }).ToArray();
            }
            VFXPool muzzleFlashVfx = new VFXPool {
                type = VFXPoolType.All
            };
            VFXComplex complex = new VFXComplex();
            VFXObject  vfxObj  = new VFXObject
            {
                alignment       = VFXAlignment.Fixed,
                attached        = false,
                orphaned        = true,
                persistsOnDeath = false,
                destructible    = true,
                usesZHeight     = true,
                zHeight         = -0.25f
            };
            List <int> muzzleFlashIds = new List <int>
            {
                VFXCollection.GetSpriteIdByName("lichsgun_vfx_001"),
                VFXCollection.GetSpriteIdByName("lichsgun_vfx_002"),
                VFXCollection.GetSpriteIdByName("lichsgun_vfx_003"),
                VFXCollection.GetSpriteIdByName("lichsgun_vfx_004")
            };
            GameObject muzzleFlashVfxObject = new GameObject("LichsGunMuzzleflash");

            muzzleFlashVfxObject.AddComponent <tk2dSprite>().SetSprite(VFXCollection, muzzleFlashIds[0]);
            muzzleFlashVfxObject.SetActive(false);
            FakePrefab.MarkAsFakePrefab(muzzleFlashVfxObject);
            UnityEngine.Object.DontDestroyOnLoad(muzzleFlashVfxObject);
            tk2dSpriteAnimator animator = muzzleFlashVfxObject.AddComponent <tk2dSpriteAnimator>();

            SpriteBuilder.AddAnimation(animator, muzzleFlashVfxObject.GetComponent <tk2dBaseSprite>().Collection, muzzleFlashIds, "flash", tk2dSpriteAnimationClip.WrapMode.Once).fps = 16;
            animator.playAutomatically = true;
            animator.DefaultClipId     = animator.GetClipIdByName("flash");
            SpriteAnimatorKiller killer = muzzleFlashVfxObject.AddComponent <SpriteAnimatorKiller>();

            killer.fadeTime             = -1f;
            killer.delayDestructionTime = -1f;
            killer.animator             = animator;
            foreach (int id in muzzleFlashIds)
            {
                LichsBookItem.ConstructOffsetsFromAnchor(VFXCollection.spriteDefinitions[id], tk2dBaseSprite.Anchor.MiddleLeft);
            }
            vfxObj.effect          = muzzleFlashVfxObject;
            complex.effects        = new VFXObject[] { vfxObj };
            muzzleFlashVfx.effects = new VFXComplex[] { complex };
            gun.gunSwitchGroup     = "SAA";
            gun.muzzleFlashEffects = muzzleFlashVfx;
            gun.reloadTime         = 1.1f;
            gun.SetBaseMaxAmmo(350);
            gun.quality = PickupObject.ItemQuality.D;
            gun.barrelOffset.transform.localPosition = new Vector3(1.1875f, 0.5625f, 0f);
            gun.gunClass = GunClass.PISTOL;
            ETGMod.Databases.Items.Add(gun, null, "ANY");
            InitSynergyForm(gun);
        }