Exemple #1
0
        //Intercepts HealthManager's Hit method and allows me to override it with my own calculation
        public void HealthManager_HitHook(On.HealthManager.orig_Hit orig, HealthManager self, HitInstance hitInstance)
        {
            //Alternative hit damages from other sources like weaver or explosions
            string srcName = hitInstance.Source.name;

            if (srcName.Contains("Gas"))
            {
                //Explosion damage
                hitInstance.DamageDealt = 3 + (PlayerData.instance.nailSmithUpgrades * 5);
                orig(self, hitInstance);
                return;
            }
            if (srcName.Contains("Dung"))
            {
                //Explosion damage
                Log("Dung damage!");
                orig(self, hitInstance);
                return;
            }
            else if (srcName.Contains("Damager"))
            {
                //Glowing Womblings
                //HeroController.instance.AddMPCharge(15);
                orig(self, hitInstance);
                return;
            }
            else if (srcName.Contains("Great Slash") || srcName.Contains("Dash Slash"))
            {
                Log("Player is nail art... ing?");


                orig(self, hitInstance);
                return;
            }
            else if (srcName.Contains("Slash"))
            {
                Log("Player is slashing!");
                hitInstance.DamageDealt = 3 + (PlayerData.instance.nailSmithUpgrades * 3);
                orig(self, hitInstance);
                return;
            }
            else if (!srcName.Contains("bullet"))
            {
                orig(self, hitInstance);
                return;
            }

            BulletBehaviour hpbb = hitInstance.Source.GetComponent <BulletBehaviour>();
            Vector3         bulletOriginPosition = hitInstance.Source.GetComponent <BulletBehaviour>().bulletOriginPosition;
            int             cardinalDirection    = DirectionUtils.GetCardinalDirection(hitInstance.GetActualDirection(self.transform));

            int damage      = hpbb.bulletDamage + (PlayerData.instance.nailSmithUpgrades * hpbb.bulletDamageScale);
            int soulGainAmt = Stats.SoulGainPerHit();

            //StartCoroutine(SplatterBlood(self.gameObject.transform.position, 1, cardinalDirection * 90));
            if (hpbb.appliesDamageOvertime)
            {
                EnemyDamageOvertime edo = self.gameObject.GetComponent <EnemyDamageOvertime>();

                if (edo == null)
                {
                    self.gameObject.AddComponent <EnemyDamageOvertime>();
                }
                else
                {
                    edo.IncreaseStack();
                }
            }
            DamageEnemyOverride(self, damage, BulletBehaviour.bulletDummyHitInstance, soulGainAmt, hpbb);
        }
Exemple #2
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");
        }