Exemple #1
0
        private void NewHitAi(Transform target, bool hitDelay, bool headDamage)
        {
            float dmgUnclamped = this.OutputDmg;

            ModAPI.Console.Write("dmgUnclamped: " + dmgUnclamped);
            if (ModdedPlayer.Stats.spell_seekingArrow)
            {
                float dist = Vector3.Distance(target.position, startposition);
                dmgUnclamped *= 1 + dist * ModdedPlayer.Stats.spell_seekingArrow_DamagePerDistance;
            }
            if (spearType)
            {
                if (ModdedPlayer.Stats.perk_thrownSpearhellChance > 0 && Random.value <= ModdedPlayer.Stats.perk_thrownSpearhellChance && OutputDmg > 1)
                {
                    var obj = Instantiate(PhysicBody, Camera.main.transform.position + Vector3.up * 2f, Quaternion.LookRotation(PhysicBody.position - Camera.main.transform.position));
                    obj.velocity = PhysicBody.velocity.normalized * 90f * ModdedPlayer.Stats.projectileSpeed;
                    Destroy(obj.gameObject, 18);
                }
            }
            else
            {
                if (headDamage)
                {
                    if (ModdedPlayer.Stats.i_EruptionBow && GreatBow.isEnabled)
                    {
                        //if (GameSetup.IsMultiplayer)
                        //{
                        BoltNetwork.Instantiate(BoltPrefabs.instantDynamite, transform.position, Quaternion.identity);
                        //}
                    }
                }
            }

            if (headDamage || (flintLockAmmoType && Random.value <= ModdedPlayer.Stats.perk_bulletCritChance) || (spearType && Random.value <= ModdedPlayer.Stats.perk_thrownSpearCritChance))
            {
                headDamage    = true;
                dmgUnclamped *= ModdedPlayer.Stats.headShotDamage;
                dmgUnclamped *= SpellActions.FocusOnHeadShot();
                if (ModdedPlayer.Stats.spell_seekingArrow)
                {
                    dmgUnclamped *= ModdedPlayer.Stats.spell_seekingArrow_HeadDamage;
                }
            }
            else
            {
                dmgUnclamped *= SpellActions.FocusOnBodyShot();
            }



            if (target)
            {
                Vector3    vector             = target.transform.root.GetChild(0).InverseTransformPoint(base.transform.position);
                float      targetAngle        = Mathf.Atan2(vector.x, vector.z) * 57.29578f;
                int        animalHitDirection = animalHealth.GetAnimalHitDirection(targetAngle);
                BoltEntity entity             = target.GetComponentInParent <BoltEntity>();
                if (!entity)
                {
                    entity = target.GetComponent <BoltEntity>();
                }

                if (BoltNetwork.isClient && entity)
                {
                    ModdedPlayer.instance.OnHitEffectsClient(entity, dmgUnclamped);
                    if (ignite)
                    {
                        using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                        {
                            using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                            {
                                w.Write(27);
                                w.Write(entity.networkId.PackedValue);
                                w.Write(Effects.BlackFlame.FireDamageBonus);
                                w.Write(20f);
                                w.Write(2200);
                                w.Close();
                            }
                            AsyncHit.SendCommandDelayed(3, answerStream.ToArray(), NetworkManager.Target.OnlyServer);
                            answerStream.Close();
                        }
                    }
                    if (ModdedPlayer.Stats.spell_focus && headDamage)
                    {
                        if (ModdedPlayer.Stats.spell_focusBonusDmg == 0)
                        {
                            //slow enemy by 80%
                            using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                            {
                                using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                                {
                                    w.Write(22);
                                    w.Write(entity.networkId.PackedValue);
                                    w.Write(ModdedPlayer.Stats.spell_focusSlowAmount);
                                    w.Write(ModdedPlayer.Stats.spell_focusSlowDuration);
                                    w.Write(90);
                                    w.Close();
                                }
                                AsyncHit.SendCommandDelayed(1, answerStream.ToArray(), Network.NetworkManager.Target.OnlyServer);
                                answerStream.Close();
                            }
                            //Network.NetworkManager.SendLine(s, Network.NetworkManager.Target.OnlyServer);
                        }
                    }
                    else if (ModdedPlayer.Stats.spell_seekingArrow)
                    {
                        //slow enemy by 80%
                        using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                        {
                            using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                            {
                                w.Write(22);
                                w.Write(entity.networkId.PackedValue);
                                w.Write(ModdedPlayer.Stats.spell_seekingArrow_SlowAmount);
                                w.Write(ModdedPlayer.Stats.spell_seekingArrow_SlowDuration);
                                w.Write(91);
                                w.Close();
                            }
                            AsyncHit.SendCommandDelayed(2, answerStream.ToArray(), Network.NetworkManager.Target.OnlyServer);
                            answerStream.Close();
                        }
                    }
                    if (ignite)
                    {
                        if (BlackFlame.GiveAfterburn && Random.value < 0.1f)
                        {
                            int id = 120 + ModReferences.Players.IndexOf(LocalPlayer.GameObject);
                            using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                            {
                                using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                                {
                                    w.Write(34);
                                    w.Write(entity.networkId.PackedValue);
                                    w.Write(id);
                                    w.Write(1.15f);
                                    w.Write(25f);
                                    w.Close();
                                }
                                AsyncHit.SendCommandDelayed(1, answerStream.ToArray(), NetworkManager.Target.OnlyServer);
                                answerStream.Close();
                            }
                        }
                    }
                    if (hitDelay)
                    {
                        target.transform.SendMessageUpwards("getClientHitDirection", 6, SendMessageOptions.DontRequireReceiver);
                        target.transform.SendMessageUpwards("StartPrediction", SendMessageOptions.DontRequireReceiver);
                        BoltEntity     component      = this.parent.GetComponent <BoltEntity>();
                        PlayerHitEnemy playerHitEnemy = PlayerHitEnemy.Create(GlobalTargets.OnlyServer);
                        playerHitEnemy.Target      = entity;
                        playerHitEnemy.Weapon      = component;
                        playerHitEnemy.getAttacker = 10;
                        if (target.gameObject.CompareTag("animalRoot"))
                        {
                            playerHitEnemy.getAttackDirection = animalHitDirection;
                        }
                        else
                        {
                            playerHitEnemy.getAttackDirection = 3;
                        }
                        playerHitEnemy.getAttackerType = 4;
                        playerHitEnemy.Hit             = DamageMath.GetSendableDamage(dmgUnclamped);
                        if ((GreatBow.isEnabled && ModdedPlayer.Stats.i_greatBowIgnites) || (ignite && Random.value < 0.5f))
                        {
                            playerHitEnemy.Burn = true;
                        }
                        playerHitEnemy.getAttackerType += 1000000;
                        playerHitEnemy.Send();
                    }
                    else
                    {
                        target.transform.SendMessageUpwards("getClientHitDirection", 6, SendMessageOptions.DontRequireReceiver);
                        target.transform.SendMessageUpwards("StartPrediction", SendMessageOptions.DontRequireReceiver);
                        PlayerHitEnemy playerHitEnemy2 = PlayerHitEnemy.Create(GlobalTargets.OnlyServer);
                        playerHitEnemy2.Target = entity;
                        if (target.gameObject.CompareTag("animalRoot"))
                        {
                            playerHitEnemy2.getAttackDirection = animalHitDirection;
                        }
                        else
                        {
                            playerHitEnemy2.getAttackDirection = 3;
                        }
                        playerHitEnemy2.getAttackerType = 4;
                        if ((ignite && Random.value < 0.5f) || GreatBow.isEnabled && ModdedPlayer.Stats.i_greatBowIgnites)
                        {
                            playerHitEnemy2.Burn = true;
                        }
                        playerHitEnemy2.Hit              = DamageMath.GetSendableDamage(dmgUnclamped);
                        playerHitEnemy2.getAttackerType += DamageMath.CONVERTEDFLOATattackerType;
                        playerHitEnemy2.Send();
                    }
                    goto afterdamage;
                }
                else
                {
                    if (target.gameObject.CompareTag("enemyRoot") || target.gameObject.CompareTag("enemyCollide"))
                    {
                        if (EnemyManager.enemyByTransform.ContainsKey(target.root))
                        {
                            var ep = EnemyManager.enemyByTransform[target.root];

                            if (ignite)
                            {
                                if ((ignite && Random.value < 0.5f) || GreatBow.isEnabled && ModdedPlayer.Stats.i_greatBowIgnites)
                                {
                                    ep.HealthScript.Burn();
                                }
                                ep.FireDebuff(2200, Effects.BlackFlame.FireDamageBonus, 20);
                                if (BlackFlame.GiveAfterburn && Random.value < 0.1f)
                                {
                                    if (ep != null)
                                    {
                                        int id = 120 + ModReferences.Players.IndexOf(LocalPlayer.GameObject);
                                        ep.DmgTakenDebuff(id, 1.15f, 25);
                                    }
                                }
                            }
                            ModdedPlayer.instance.OnHitEffectsHost(ep, dmgUnclamped);
                            if (ModdedPlayer.Stats.spell_focus && headDamage)
                            {
                                if (ModdedPlayer.Stats.spell_focusBonusDmg == 0)
                                {
                                    //slow enemy by 80%
                                    ep.Slow(90, ModdedPlayer.Stats.spell_focusSlowAmount, ModdedPlayer.Stats.spell_focusSlowDuration);
                                }
                            }
                            else if (ModdedPlayer.Stats.spell_seekingArrow)
                            {
                                ep.Slow(91, ModdedPlayer.Stats.spell_seekingArrow_SlowAmount, ModdedPlayer.Stats.spell_seekingArrow_SlowDuration);
                            }
                            ep.HealthScript.getAttackDirection(3);
                            ep.HitPhysical(dmgUnclamped);
                            Debug.Log("HIT PHYSICAL");
                            goto afterdamage;
                        }
                    }
                    target.gameObject.SendMessageUpwards("getAttackDirection", 3, SendMessageOptions.DontRequireReceiver);
                    target.gameObject.SendMessageUpwards("getAttackerType", 4, SendMessageOptions.DontRequireReceiver);
                    GameObject closestPlayerFromPos = TheForest.Utils.Scene.SceneTracker.GetClosestPlayerFromPos(base.transform.position);
                    target.gameObject.SendMessageUpwards("getAttacker", closestPlayerFromPos, SendMessageOptions.DontRequireReceiver);
                    if (target.gameObject.CompareTag("enemyRoot") || target.gameObject.CompareTag("lb_bird") || target.gameObject.CompareTag("animalRoot"))
                    {
                        Debug.Log("HIT NORMAL");
                        if (target.gameObject.CompareTag("enemyRoot"))
                        {
                            EnemyHealth targetEnemyHealth = target.GetComponentInChildren <EnemyHealth>();
                            if (targetEnemyHealth)
                            {
                                targetEnemyHealth.getAttackDirection(3);
                                targetEnemyHealth.setSkinDamage(2);
                                mutantTargetSwitching componentInChildren2 = target.GetComponentInChildren <mutantTargetSwitching>();
                                if (componentInChildren2)
                                {
                                    componentInChildren2.getAttackerType(4);
                                    componentInChildren2.getAttacker(closestPlayerFromPos);
                                }

                                targetEnemyHealth.Hit((int)Mathf.Min((float)int.MaxValue, dmgUnclamped));

                                if ((ignite && Random.value < 0.5f) || GreatBow.isEnabled && ModdedPlayer.Stats.i_greatBowIgnites)
                                {
                                    targetEnemyHealth.Burn();
                                }
                            }
                        }
                        else
                        {
                            if (target.gameObject.CompareTag("animalRoot"))
                            {
                                target.gameObject.SendMessage("ApplyAnimalSkinDamage", animalHitDirection, SendMessageOptions.DontRequireReceiver);
                            }
                            target.SendMessageUpwards("Hit", (int)Mathf.Min(dmgUnclamped, int.MaxValue / 2), SendMessageOptions.DontRequireReceiver);
                            if ((ignite && Random.value < 0.5f) || GreatBow.isEnabled && ModdedPlayer.Stats.i_greatBowIgnites)
                            {
                                target.gameObject.SendMessage("Burn", SendMessageOptions.DontRequireReceiver);
                            }
                            target.gameObject.SendMessage("getSkinHitPosition", base.transform, SendMessageOptions.DontRequireReceiver);
                        }
                    }
                    else
                    {
                        if (target.gameObject.CompareTag("animalCollide"))
                        {
                            target.gameObject.SendMessageUpwards("ApplyAnimalSkinDamage", animalHitDirection, SendMessageOptions.DontRequireReceiver);
                        }
                        target.SendMessageUpwards("Hit", (int)Mathf.Min(dmgUnclamped, int.MaxValue / 2), SendMessageOptions.DontRequireReceiver);
                        if (GreatBow.isEnabled && ModdedPlayer.Stats.i_greatBowIgnites || (ignite && Random.value < 0.5f))
                        {
                            target.gameObject.SendMessage("Burn", SendMessageOptions.DontRequireReceiver);
                        }
                        target.gameObject.SendMessageUpwards("getSkinHitPosition", base.transform, SendMessageOptions.DontRequireReceiver);
                    }
                }
            }
afterdamage:

            if (ModdedPlayer.Stats.perk_projectileNoConsumeChance > 0.35f)
            {
                FMODCommon.PlayOneshotNetworked(this.hitAiEvent, base.transform, FMODCommon.NetworkRole.Any);
            }
        }