Пример #1
0
 public static void SetProjectileSpriteRight(Projectile proj, string name, int pixelWidth, int pixelHeight, bool lightened = true, tk2dBaseSprite.Anchor anchor = tk2dBaseSprite.Anchor.LowerLeft, bool anchorChangesCollider = true,
                                             bool fixesScale = false, int?overrideColliderPixelWidth = null, int?overrideColliderPixelHeight = null, int?overrideColliderOffsetX = null, int?overrideColliderOffsetY = null, Projectile overrideProjectileToCopyFrom = null)
 {
     try
     {
         proj.GetAnySprite().spriteId = ETGMod.Databases.Items.ProjectileCollection.inst.GetSpriteIdByName(name);
         tk2dSpriteDefinition def     = SetupDefinitionForProjectileSprite(name, proj.GetAnySprite().spriteId, pixelWidth, pixelHeight, lightened, overrideColliderPixelWidth, overrideColliderPixelHeight, overrideColliderOffsetX,
                                                                           overrideColliderOffsetY, overrideProjectileToCopyFrom);
         LichsBookItem.ConstructOffsetsFromAnchor(def, anchor, def.position3, fixesScale, anchorChangesCollider);
         proj.GetAnySprite().scale = new Vector3(1f, 1f, 1f);
         proj.transform.localScale = new Vector3(1f, 1f, 1f);
         proj.GetAnySprite().transform.localScale = new Vector3(1f, 1f, 1f);
         proj.AdditionalScaleMultiplier = 1f;
     }
     catch (Exception ex)
     {
         ETGModConsole.Log("Ooops! Seems like something got very, Very, VERY wrong. Here's the exception:");
         ETGModConsole.Log(ex.ToString());
     }
 }
Пример #2
0
 public static void BuildSynergyPrefab()
 {
     if (synergyPrefab == null && !CompanionBuilder.companionDictionary.ContainsKey("Synergy_Cross_Chamber"))
     {
         synergyPrefab = CompanionBuilder.BuildPrefab("Synergy Cross Chamber", "Synergy_Cross_Chamber", "LichItems/Resources/CrossChamber/IdleRight/tomb_idle_right_001", new IntVector2(0, 0), new IntVector2(14, 16));
         var           companion = synergyPrefab.AddComponent <CompanionController>();
         PixelCollider collider  = new PixelCollider();
         collider.ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual;
         collider.CollisionLayer         = CollisionLayer.PlayerHitBox;
         collider.ManualWidth            = 14;
         collider.ManualHeight           = 16;
         collider.ManualOffsetX          = 0;
         collider.ManualOffsetY          = 0;
         KnockbackDoer knockback = companion.gameObject.GetOrAddComponent <KnockbackDoer>();
         knockback.weight = 100f;
         companion.aiActor.IsNormalEnemy = false;
         companion.CanInterceptBullets   = true;
         companion.specRigidbody.PrimaryPixelCollider.CollisionLayer = CollisionLayer.PlayerCollider;
         companion.specRigidbody.PixelColliders.Add(collider);
         companion.gameObject.AddComponent <IgnoreEnemyCollisions>();
         companion.specRigidbody.AddCollisionLayerIgnoreOverride(CollisionMask.LayerToMask(CollisionLayer.EnemyHitBox));
         companion.specRigidbody.AddCollisionLayerIgnoreOverride(CollisionMask.LayerToMask(CollisionLayer.EnemyCollider));
         companion.specRigidbody.CollideWithOthers = true;
         companion.aiActor.CollisionDamage         = 0f;
         companion.aiActor.MovementSpeed           = 3f;
         companion.aiActor.CanDropCurrency         = false;
         companion.healthHaver.PreventAllDamage    = false;
         GameObject gunAttachPointObject = new GameObject("GunAttachPoint");
         FakePrefab.MarkAsFakePrefab(gunAttachPointObject);
         UnityEngine.Object.DontDestroyOnLoad(gunAttachPointObject);
         Transform gunAttachPoint = gunAttachPointObject.transform;
         gunAttachPoint.parent        = synergyPrefab.transform;
         gunAttachPoint.localPosition = new Vector3(-0.1250f, 0.3125f, 0f);
         GameObject hand = SpriteBuilder.SpriteFromResource("LichItems/Resources/CrossChamber/Hand/hand_001", new GameObject("SynergyCrossChamberHand"));
         FakePrefab.MarkAsFakePrefab(hand);
         UnityEngine.Object.DontDestroyOnLoad(hand);
         LichsBookItem.ConstructOffsetsFromAnchor(hand.GetComponent <tk2dBaseSprite>().GetCurrentSpriteDef(), tk2dBaseSprite.Anchor.MiddleCenter);
         PlayerHandController handController = hand.AddComponent <PlayerHandController>();
         handController.ForceRenderersOff = false;
         handController.attachPoint       = null;
         handController.handHeightFromGun = 0.05f;
         SetupBasicAIShooter(synergyPrefab, 38 /*38 is the id of magnum*/, gunAttachPoint, hand);
         synergyPrefab.AddAnimation("idle_right", "LichItems/Resources/CrossChamber/IdleRight", 4, AnimationType.Idle, DirectionType.TwoWayHorizontal);
         synergyPrefab.AddAnimation("idle_left", "LichItems/Resources/CrossChamber/IdleLeft", 4, AnimationType.Idle, DirectionType.TwoWayHorizontal);
         synergyPrefab.AddAnimation("run_right", "LichItems/Resources/CrossChamber/MoveRight", 10, AnimationType.Move, DirectionType.TwoWayHorizontal);
         synergyPrefab.AddAnimation("run_left", "LichItems/Resources/CrossChamber/MoveLeft", 10, AnimationType.Move, DirectionType.TwoWayHorizontal);
         synergyPrefab.AddAnimation("hit_left", "LichItems/Resources/CrossChamber/HitLeft", 6, AnimationType.Hit, DirectionType.TwoWayHorizontal).wrapMode   = tk2dSpriteAnimationClip.WrapMode.Once;
         synergyPrefab.AddAnimation("hit_right", "LichItems/Resources/CrossChamber/HitRight", 6, AnimationType.Hit, DirectionType.TwoWayHorizontal).wrapMode = tk2dSpriteAnimationClip.WrapMode.Once;
         BehaviorSpeculator component = CrossChamber.synergyPrefab.GetComponent <BehaviorSpeculator>();
         component.MovementBehaviors.Add(new CompanionFollowPlayerBehavior
         {
             IdleAnimations = new string[]
             {
                 "idle"
             },
             DisableInCombat = false
         });
         component.TargetBehaviors = new List <TargetBehaviorBase>
         {
             new TargetPlayerBehavior
             {
                 Radius              = 35f,
                 LineOfSight         = true,
                 ObjectPermanence    = true,
                 SearchInterval      = 0.25f,
                 PauseOnTargetSwitch = false,
                 PauseTime           = 0.25f
             }
         };
         component.AttackBehaviors = new List <AttackBehaviorBase>
         {
             new ShootGunBehavior()
             {
                 GroupCooldownVariance        = -1f,
                 LineOfSight                  = true,
                 WeaponType                   = WeaponType.AIShooterProjectile,
                 OverrideBulletName           = "default",
                 BulletScript                 = null,
                 FixTargetDuringAttack        = false,
                 StopDuringAttack             = false,
                 LeadAmount                   = 0f,
                 LeadChance                   = 1f,
                 RespectReload                = true,
                 MagazineCapacity             = 6,
                 ReloadSpeed                  = 2f,
                 EmptiesClip                  = false,
                 SuppressReloadAnim           = false,
                 TimeBetweenShots             = -1f,
                 PreventTargetSwitching       = false,
                 OverrideAnimation            = string.Empty,
                 OverrideDirectionalAnimation = string.Empty,
                 HideGun                      = false,
                 UseLaserSight                = false,
                 UseGreenLaser                = false,
                 PreFireLaserTime             = -1f,
                 AimAtFacingDirectionWhenSafe = false
             }
         };
         AIBulletBank bulletBank = synergyPrefab.GetOrAddComponent <AIBulletBank>();
         bulletBank.Bullets = new List <AIBulletBank.Entry>
         {
             new AIBulletBank.Entry()
             {
                 Name = "default",
                 OverrideProjectile = true,
                 ProjectileData     = new ProjectileData()
                 {
                     damage  = 10f,
                     speed   = 16f,
                     range   = 60f,
                     force   = 20f,
                     damping = 0f,
                     UsesCustomAccelerationCurve     = false,
                     AccelerationCurve               = null,
                     CustomAccelerationCurveDuration = 0f,
                     IgnoreAccelCurveTime            = 0f,
                     onDestroyBulletScript           = null
                 },
                 BulletObject = null
             }
         };
         bulletBank.useDefaultBulletIfMissing = false;
         bulletBank.transforms = new List <Transform>
         {
             synergyPrefab.transform
         };
         bulletBank.rampBullets                   = false;
         bulletBank.rampStartHeight               = 0f;
         bulletBank.rampTime                      = 0f;
         bulletBank.OverrideGun                   = null;
         bulletBank.OnProjectileCreated           = null;
         bulletBank.OnProjectileCreatedWithSource = null;
         bulletBank.FixedPlayerPosition           = null;
     }
 }
Пример #3
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);
        }