Exemplo n.º 1
0
        // This function does damage to the enemy using the damage numbers given by the weapon type
        public static void HitEnemy(HealthManager targetHP, int damageDealt, HitInstance hitInstance, int soulGain, BulletBehaviour hpbb)
        {
            //TODO: this specifics might add up later, Moss Charger is just one of the few except and there maybe many more
            if (targetHP == null)
            {
                return;
            }

            int        cardinalDirection = DirectionUtils.GetCardinalDirection(hitInstance.GetActualDirection(targetHP.transform));
            GameObject blockHitPrefab    = targetHP.GetAttr <GameObject>("blockHitPrefab");

            bool specialEnemy = (targetHP.name.Contains("Charger"));

            if (targetHP.IsBlockingByDirection(cardinalDirection, AttackTypes.Nail) && !specialEnemy || damageDealt <= 0)
            {
                FSMUtility.SendEventToGameObject(targetHP.gameObject, "BLOCKED HIT", false);
                GameObject blockHit = blockHitPrefab.Spawn();
                blockHit.transform.position = targetHP.transform.position;
                blockHit.transform.Rotate(new Vector3(0, 0, 90 * cardinalDirection));
                return;
            }

            if (damageDealt <= 0)
            {
                return;
            }
            //bool specialEnemy = (targetHP.name.Contains("Moss Charger") || targetHP.name.Contains("Mushroom Brawler"));

            /*
             * if (targetHP.IsInvincible && !specialEnemy && !PlayerData.instance.equippedCharm_25)
             * {
             *  GameObject blockHit = blockHitPrefab.Spawn();
             *  blockHit.transform.position = targetHP.transform.position;
             * return;
             * }
             */

            if (targetHP.gameObject.name.Contains("Blocker")) //double damage baldurs
            {
                damageDealt = damageDealt * 4;
            }

            Recoil recoil = targetHP.gameObject.GetComponent <Recoil>();

            //if (recoil != null && PlayerData.instance.equippedCharm_15)
            if (recoil != null)
            {
                recoil.RecoilByDirection(cardinalDirection, 0.25f);
            }

            /*
             * Mostly code copied from the healthmanager class itself.
             */

            FSMUtility.SendEventToGameObject(targetHP.gameObject, "HIT", false);
            GameObject sendHitGO = targetHP.GetAttr <GameObject>("sendHitGO");

            if (sendHitGO != null)
            {
                FSMUtility.SendEventToGameObject(targetHP.gameObject, "HIT", false);
            }

            GameObject HitPrefab    = targetHP.GetAttr <GameObject>("strikeNailPrefab");
            GameObject ImpactPrefab = targetHP.GetAttr <GameObject>("slashImpactPrefab");
            Vector3?   effectOrigin = targetHP.GetAttr <Vector3?>("effectOrigin");

            if (HitPrefab != null && effectOrigin != null)
            {
                HitPrefab.Spawn(targetHP.transform.position + (Vector3)effectOrigin, Quaternion.identity).transform.SetPositionZ(0.0031f);
            }
            if (ImpactPrefab != null && effectOrigin != null)
            {
                ImpactPrefab.Spawn(targetHP.transform.position + (Vector3)effectOrigin, Quaternion.identity).transform.SetPositionZ(0.0031f);
            }

            SpriteFlash f = targetHP.gameObject.GetComponent <SpriteFlash>();

            if (f != null)
            {
                f.flashWhiteQuick();
            }

            //Log("SEVERITY: " + ds + " DAMAGE: " + damageDealt);

            FSMUtility.SendEventToGameObject(targetHP.gameObject, "TOOK DAMAGE", false);
            FSMUtility.SendEventToGameObject(targetHP.gameObject, "TAKE DAMAGE", false);

            FSMUtility.SendEventToGameObject(hitInstance.Source, "HIT LANDED", false);
            FSMUtility.SendEventToGameObject(hitInstance.Source, "DEALT DAMAGE", false);

            // Actually do damage to target.

            LoadAssets.sfxDictionary.TryGetValue("enemyhurt" + soundRandom.Next(1, 4) + ".wav", out AudioClip hurtSound);
            HeroController.instance.spellControl.gameObject.GetComponent <AudioSource>().PlayOneShot(hurtSound);

            if (targetHP.damageOverride)
            {
                targetHP.hp -= 1;
            }
            else
            {
                targetHP.hp -= damageDealt; // the actual damage

                //int sg = (ds.Equals(DamageSeverity.Minor)) ? 0 : soulGain;
                HeroController.instance.AddMPCharge(6);
                Stats.IncreaseAdrenalinePoints(damageDealt);
            }

            // Trigger Kill animation
            if (targetHP.hp <= 0f)
            {
                LoadAssets.sfxDictionary.TryGetValue("enemydead" + soundRandom.Next(1, 4) + ".wav", out AudioClip deadSound);
                HeroController.instance.spellControl.gameObject.GetComponent <AudioSource>().PlayOneShot(deadSound);
                targetHP.Die(cardinalDirection * 90, AttackTypes.Spell, true);
                HeroController.instance.AddMPCharge(4);
                GameManager.instance.FreezeMoment(1);
                return;
            }

            bool?  hasAlternateHitAnimation = targetHP.GetAttr <bool?>("hasAlternateHitAnimation");
            string alternateHitAnimation    = targetHP.GetAttr <string>("alternateHitAnimation");

            if (hasAlternateHitAnimation != null && (bool)hasAlternateHitAnimation && targetHP.GetComponent <tk2dSpriteAnimator>() && alternateHitAnimation != null)
            {
                targetHP.GetComponent <tk2dSpriteAnimator>().Play(alternateHitAnimation);
            }


            PlayMakerFSM stunControlFSM = targetHP.gameObject.GetComponents <PlayMakerFSM>().FirstOrDefault(component =>
                                                                                                            component.FsmName == "Stun Control" || component.FsmName == "Stun");

            if (stunControlFSM != null)
            {
                //stunControlFSM.SendEvent("STUN DAMAGE");
            }

            /*
             * Uncomment below for a sick looking enter the gungeon style freeze frame or for camera shake.
             */
        }
Exemplo n.º 2
0
        // This function does damage to the enemy using the damage numbers given by the weapon type
        public static void HitEnemy(HealthManager targetHP, int expectedDamage, HitInstance hitInstance, int soulGain)
        {
            int realDamage = expectedDamage;

            //TODO: this specifics might add up later, Moss Charger is just one of the few except and there maybe many more
            int        cardinalDirection = DirectionUtils.GetCardinalDirection(hitInstance.GetActualDirection(targetHP.transform));
            GameObject blockHitPrefab    = targetHP.GetAttr <GameObject>("blockHitPrefab");

            bool specialEnemy = (targetHP.name.Contains("Charger"));

            if (targetHP.IsBlockingByDirection(cardinalDirection, AttackTypes.Nail) && !specialEnemy || realDamage <= 0)
            {
                FSMUtility.SendEventToGameObject(targetHP.gameObject, "BLOCKED HIT", false);
                GameObject blockHit = blockHitPrefab.Spawn();
                blockHit.transform.position = targetHP.transform.position;
                blockHit.transform.Rotate(new Vector3(0, 0, 90 * cardinalDirection));
                return;
            }



            //bool specialEnemy = (targetHP.name.Contains("Moss Charger") || targetHP.name.Contains("Mushroom Brawler"));

            //if (targetHP.IsInvincible && !specialEnemy && !PlayerData.instance.equippedCharm_25)
            //{
            //    GameObject blockHit = blockHitPrefab.Spawn();
            //    blockHit.transform.position = targetHP.transform.position;
            //   return;
            //}

            if (targetHP.gameObject.name.Contains("Blocker"))
            {
                realDamage = realDamage * 4;
            }

            Recoil recoil = targetHP.gameObject.GetComponent <Recoil>();

            if (recoil != null && PlayerData.instance.equippedCharm_15)
            {
                recoil.RecoilByDirection(cardinalDirection, 0.8f);
            }

            if (realDamage <= 0)
            {
                return;
            }

            if (targetHP == null)
            {
                return;
            }

            /*
             * Play animations and such...
             * Mostly code copied from the healthmanager class itself.
             */

            //Modding.Logger.Log("Cardinal is " + cardinalDirection);
            FSMUtility.SendEventToGameObject(targetHP.gameObject, "HIT", false);
            GameObject sendHitGO = targetHP.GetAttr <GameObject>("sendHitGO");

            if (sendHitGO != null)
            {
                FSMUtility.SendEventToGameObject(targetHP.gameObject, "HIT", false);
            }

            GameObject HitPrefab    = targetHP.GetAttr <GameObject>("strikeNailPrefab");
            GameObject ImpactPrefab = targetHP.GetAttr <GameObject>("slashImpactPrefab");
            Vector3?   effectOrigin = targetHP.GetAttr <Vector3?>("effectOrigin");

            if (HitPrefab != null && effectOrigin != null)
            {
                HitPrefab.Spawn(targetHP.transform.position + (Vector3)effectOrigin, Quaternion.identity).transform.SetPositionZ(0.0031f);
            }
            if (ImpactPrefab != null && effectOrigin != null)
            {
                ImpactPrefab.Spawn(targetHP.transform.position + (Vector3)effectOrigin, Quaternion.identity).transform.SetPositionZ(0.0031f);
            }

            FSMUtility.SendEventToGameObject(targetHP.gameObject, "TOOK DAMAGE", false);
            FSMUtility.SendEventToGameObject(targetHP.gameObject, "TAKE DAMAGE", false);

            FSMUtility.SendEventToGameObject(hitInstance.Source, "HIT LANDED", false);
            FSMUtility.SendEventToGameObject(hitInstance.Source, "DEALT DAMAGE", false);


            // Actually do damage to target.
            try
            {
                //TODO: change this audio source
                //HeroController.instance.spellControl.gameObject.GetComponent<AudioSource>().PlayOneShot(LoadAssets.enemyHurtSFX[soundRandom.Next(0, 2)]);
                LoadAssets.sfxDictionary.TryGetValue("enemyhurt" + soundRandom.Next(1, 4) + ".wav", out AudioClip ac);
                HeroController.instance.spellControl.gameObject.GetComponent <AudioSource>().PlayOneShot(ac);
            }
            catch (Exception e)
            {
                Modding.Logger.Log("Enemy Hurt Exception Thrown " + e);
            }

            if (targetHP.damageOverride)
            {
                targetHP.hp -= 1;
            }
            else
            {
                targetHP.hp -= realDamage; // the actual damage
                HeroController.instance.AddMPCharge(soulGain);
            }

            // Trigger Kill animation
            if (targetHP.hp <= 0f)
            {
                LoadAssets.sfxDictionary.TryGetValue("enemydead" + soundRandom.Next(1, 4) + ".wav", out AudioClip ac);
                HeroController.instance.spellControl.gameObject.GetComponent <AudioSource>().PlayOneShot(ac);
                targetHP.Die(cardinalDirection * 90, AttackTypes.Spell, true);
                HeroController.instance.AddMPCharge(3);
                return;
            }


            bool?  hasAlternateHitAnimation = targetHP.GetAttr <bool?>("hasAlternateHitAnimation");
            string alternateHitAnimation    = targetHP.GetAttr <string>("alternateHitAnimation");

            if (hasAlternateHitAnimation != null && (bool)hasAlternateHitAnimation && targetHP.GetComponent <tk2dSpriteAnimator>() && alternateHitAnimation != null)
            {
                targetHP.GetComponent <tk2dSpriteAnimator>().Play(alternateHitAnimation);
            }


            PlayMakerFSM stunControlFSM = targetHP.gameObject.GetComponents <PlayMakerFSM>().FirstOrDefault(component =>
                                                                                                            component.FsmName == "Stun Control" || component.FsmName == "Stun");

            if (stunControlFSM != null)
            {
                //stunControlFSM.SendEvent("STUN DAMAGE");
            }

            /*
             * Uncomment below for a sick looking enter the gungeon style freeze frame or for camera shake.
             */
            //GameManager.instance.FreezeMoment(1);
            //GameCameras.instance.cameraShakeFSM.SendEvent("EnemyKillShake");
            SpriteFlash f = targetHP.gameObject.GetComponent <SpriteFlash>();

            if (f != null)
            {
                f.flashInfected();
            }
        }
Exemplo n.º 3
0
        //+++DAMAGE OVERRIDE+++
        public static void DamageEnemyOverride(HealthManager targetHP, int damageDealt, HitInstance hitInstance, int soulGain, BulletBehaviour hpbb)
        {
            //TODO: this specifics might add up later, Moss Charger is just one of the few except and there maybe many more
            if (targetHP == null)
            {
                return;
            }

            int        cardinalDirection = DirectionUtils.GetCardinalDirection(hitInstance.GetActualDirection(targetHP.transform));
            GameObject blockHitPrefab    = targetHP.GetAttr <GameObject>("blockHitPrefab");

            bool specialEnemy = (targetHP.name.Contains("Charger"));

            if (targetHP.IsBlockingByDirection(cardinalDirection, AttackTypes.Nail) && !specialEnemy)
            {
                FSMUtility.SendEventToGameObject(targetHP.gameObject, "BLOCKED HIT", false);
                GameObject blockHit = blockHitPrefab.Spawn();
                blockHit.transform.position = targetHP.transform.position;
                blockHit.transform.Rotate(new Vector3(0, 0, 90 * cardinalDirection));
                return;
            }

            if (false && !targetHP.IsInvincible) //enable disable damage overtime
            {
                EnemyDamageOvertime dm = targetHP.gameObject.GetComponent <EnemyDamageOvertime>();
                if (dm == null)
                {
                    targetHP.gameObject.AddComponent <EnemyDamageOvertime>();
                }
                else
                {
                    dm.IncreaseStack();
                }
            }

            //bool specialEnemy = (targetHP.name.Contains("Moss Charger") || targetHP.name.Contains("Mushroom Brawler"));

            /*
             * if (targetHP.IsInvincible && !specialEnemy && !PlayerData.instance.equippedCharm_25)
             * {
             *  GameObject blockHit = blockHitPrefab.Spawn();
             *  blockHit.transform.position = targetHP.transform.position;
             * return;
             * }
             */
            if (targetHP.gameObject.name.Contains("Blocker")) //double damage baldurs
            {
                damageDealt = damageDealt * 4;
            }

            Recoil recoil = targetHP.gameObject.GetComponent <Recoil>();

            //if (recoil != null && PlayerData.instance.equippedCharm_15)
            if (recoil != null)
            {
                recoil.RecoilByDirection(cardinalDirection, 0.25f);
            }

            /*
             * Mostly code copied from the healthmanager class itself.
             */

            FSMUtility.SendEventToGameObject(targetHP.gameObject, "HIT", false);
            GameObject sendHitGO = targetHP.GetAttr <GameObject>("sendHitGO");

            if (sendHitGO != null)
            {
                FSMUtility.SendEventToGameObject(targetHP.gameObject, "HIT", false);
            }

            GameObject HitPrefab    = targetHP.GetAttr <GameObject>("strikeNailPrefab");
            GameObject ImpactPrefab = targetHP.GetAttr <GameObject>("slashImpactPrefab");
            Vector3?   effectOrigin = targetHP.GetAttr <Vector3?>("effectOrigin");

            if (HitPrefab != null && effectOrigin != null)
            {
                HitPrefab.Spawn(targetHP.transform.position + (Vector3)effectOrigin, Quaternion.identity).transform.SetPositionZ(0.0031f);
            }
            if (ImpactPrefab != null && effectOrigin != null)
            {
                ImpactPrefab.Spawn(targetHP.transform.position + (Vector3)effectOrigin, Quaternion.identity).transform.SetPositionZ(0.0031f);
            }
            SpriteFlash f = targetHP.gameObject.GetComponent <SpriteFlash>();

            if (f != null)
            {
                f.flashWhiteQuick();
            }

            FSMUtility.SendEventToGameObject(targetHP.gameObject, "TOOK DAMAGE", false);
            FSMUtility.SendEventToGameObject(targetHP.gameObject, "TAKE DAMAGE", false);
            FSMUtility.SendEventToGameObject(hitInstance.Source, "HIT LANDED", false);
            FSMUtility.SendEventToGameObject(hitInstance.Source, "DEALT DAMAGE", false);

            // Actually do damage to target.
            LoadAssets.sfxDictionary.TryGetValue("enemyhurt" + rand.Next(1, 4) + ".wav", out AudioClip hurtSound);
            HeroController.instance.spellControl.gameObject.GetComponent <AudioSource>().PlayOneShot(hurtSound);

            if (targetHP.damageOverride)
            {
                targetHP.hp -= 1;
            }
            else
            {
                targetHP.hp -= damageDealt; // the actual damage
                if (hpbb.canGainEnergyCharges)
                {
                    HeroController.instance.AddMPCharge(Stats.instance.current_soulGainedPerHit);
                }
                Stats.instance.IncreaseAdrenalineChargeEnergy();
                //TODO: change this audio source location to the sound handler
                AudioHandler.instance.PlayMiscSoundEffect(AudioHandler.HollowPointSoundType.EnemyHitSFXGO);
            }
            // Trigger Enemy Kill
            if (targetHP.hp <= 0f)
            {
                EnemyDeathEvent(targetHP, cardinalDirection, true);
                return;
            }

            bool?  hasAlternateHitAnimation = targetHP.GetAttr <bool?>("hasAlternateHitAnimation");
            string alternateHitAnimation    = targetHP.GetAttr <string>("alternateHitAnimation");

            if (hasAlternateHitAnimation != null && (bool)hasAlternateHitAnimation && targetHP.GetComponent <tk2dSpriteAnimator>() && alternateHitAnimation != null)
            {
                targetHP.GetComponent <tk2dSpriteAnimator>().Play(alternateHitAnimation);
            }

            PlayMakerFSM stunControlFSM = targetHP.gameObject.GetComponents <PlayMakerFSM>().FirstOrDefault(component => component.FsmName == "Stun Control" || component.FsmName == "Stun");
            //if (stunControlFSM != null) stunControlFSM.SendEvent("STUN DAMAGE");
        }