コード例 #1
0
        private bool COTFHit(Collider other)
        {
            //----------------HIT DAMAGE
            float outputdmg = 0;

            if (animControl.smashBool)
            {
                outputdmg = smashDamage;
            }
            else
            {
                outputdmg = weaponDamage;
            }
            outputdmg += ModdedPlayer.Stats.meleeFlatDmg + SpellActions.GetParryCounterStrikeDmg();

            outputdmg *= ModdedPlayer.Stats.RandomCritDamage * ModdedPlayer.Stats.MeleeDamageMult;

            if (hitReactions.kingHitBool || fsmHeavyAttackBool.Value)
            {
                outputdmg *= ModdedPlayer.Stats.heavyAttackDmg * 3;
            }
            if (animControl.smashBool)
            {
                outputdmg *= ModdedPlayer.Stats.smashDamage;
            }

            if (ModdedPlayer.Stats.perk_danceOfFiregod && Effects.BlackFlame.IsOn)
            {
                outputdmg *= 1 + LocalPlayer.Rigidbody.velocity.magnitude;
            }
            if (outputdmg < 0)
            {
                outputdmg = -outputdmg;
            }
            //----------------HIT DAMAGE

            if (other.CompareTag("enemyCollide") || other.CompareTag("enemyRoot"))
            {
                ModdedPlayer.instance.OnHit();
                ModdedPlayer.instance.OnHit_Melee(other.transform);
                if (GameSetup.IsMpClient)
                {
                    var entity = other.GetComponentInParent <BoltEntity>();
                    if (entity != null)
                    {
                        var phe = PlayerHitEnemy.Create(GlobalTargets.OnlyServer);
                        phe.Target             = entity;
                        phe.getAttackerType    = 4 + DamageMath.CONVERTEDFLOATattackerType;
                        phe.Hit                = DamageMath.GetSendableDamage(outputdmg);
                        phe.HitAxe             = axe;
                        phe.hitFallDown        = fsmHeavyAttackBool.Value && axe;
                        phe.getAttackDirection = animator.GetInteger("hitDirection");
                        phe.takeDamage         = 1;
                        phe.getCombo           = 3;
                        phe.Burn               = (fireStick && Random.value > 0.8f) || AlwaysIgnite || Effects.BlackFlame.IsOn;
                        phe.explosion          = fsmJumpAttackBool.Value && LocalPlayer.FpCharacter.jumpingTimer > 1.2f && !chainSaw;
                        phe.Send();

                        ulong packed = entity.networkId.PackedValue;
                        if (ModdedPlayer.Stats.TotalMeleeArmorPiercing > 0)
                        {
                            EnemyProgression.ReduceArmor(entity, ModdedPlayer.Stats.TotalMeleeArmorPiercing);
                        }
                        if ((hitReactions.kingHitBool || fsmHeavyAttackBool.Value) && ModdedPlayer.Stats.perk_chargedAtkKnockback)
                        {
                            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                            {
                                using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(stream))
                                {
                                    Vector3 dir = other.transform.position - LocalPlayer.Transform.position;
                                    dir.y = 0;
                                    w.Write(43);
                                    w.Write(packed);
                                    w.Write(dir.x);
                                    w.Write(dir.y);
                                    w.Write(dir.z);
                                    w.Write(1f);
                                    w.Close();
                                }
                                Network.NetworkManager.SendLine(stream.ToArray(), NetworkManager.Target.OnlyServer);

                                stream.Close();
                            }
                        }
                        if (Effects.BlackFlame.IsOn)
                        {
                            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                            {
                                using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(stream))
                                {
                                    w.Write(27);
                                    w.Write(packed);
                                    w.Write(Effects.BlackFlame.FireDamageBonus);
                                    w.Write(20f);
                                    w.Write(1);
                                    w.Close();
                                }
                                Network.NetworkManager.SendLine(stream.ToArray(), NetworkManager.Target.OnlyServer);

                                stream.Close();
                            }
                            if (BlackFlame.GiveAfterburn && Random.value < 0.1f)
                            {
                                int id = 121 + 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(packed);
                                        w.Write(id);
                                        w.Write(1.15f);
                                        w.Write(25f);
                                        w.Close();
                                    }
                                    AsyncHit.SendCommandDelayed(1, answerStream.ToArray(), NetworkManager.Target.OnlyServer);
                                    answerStream.Close();
                                }
                            }
                        }
                        if (ModdedPlayer.Stats.perk_fireDmgIncreaseOnHit)
                        {
                            int   myID    = 2000 + ModReferences.Players.IndexOf(LocalPlayer.GameObject);
                            float fireDmg = 1 + ModdedPlayer.Stats.spellFlatDmg / 3;
                            fireDmg *= ModdedPlayer.Stats.TotalMagicDamageMultiplier;
                            fireDmg *= ModdedPlayer.Stats.fireDamage + 1;
                            fireDmg *= 0.35f;
                            using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                            {
                                using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                                {
                                    w.Write(27);
                                    w.Write(packed);
                                    w.Write(fireDmg);
                                    w.Write(15);
                                    w.Write(myID);
                                    w.Close();
                                }
                                AsyncHit.SendCommandDelayed(2, answerStream.ToArray(), NetworkManager.Target.OnlyServer);
                                answerStream.Close();
                            }
                        }
                        if (ModdedPlayer.Stats.i_HammerStun && PlayerInventoryMod.EquippedModel == BaseItem.WeaponModelType.Hammer)
                        {
                            using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                            {
                                using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                                {
                                    w.Write(22);
                                    w.Write(packed);
                                    w.Write(ModdedPlayer.Stats.i_HammerStunAmount);
                                    w.Write(ModdedPlayer.Stats.i_HammerStunDuration);
                                    w.Write(40);
                                    w.Close();
                                }
                                AsyncHit.SendCommandDelayed(2, answerStream.ToArray(), NetworkManager.Target.OnlyServer);
                                answerStream.Close();
                            }
                        }
                        SpellActions.Bash(packed, outputdmg);

                        AfterHit();
                        return(true);
                    }
                }
                else                        //is singleplayer or host
                {
                    if (EnemyManager.enemyByTransform.ContainsKey(other.transform.root))
                    {
                        var progression = EnemyManager.enemyByTransform[other.transform.root];
                        progression.HitPhysical(outputdmg);

                        progression.HealthScript.getCombo(3);
                        var hitDirection = animator.GetInteger("hitDirection");
                        progression.HealthScript.getAttackDirection(hitDirection);
                        progression.setup.hitReceiver.getAttackDirection(hitDirection);
                        progression.setup.hitReceiver.getCombo(3);
                        if (fsmJumpAttackBool.Value && LocalPlayer.FpCharacter.jumpingTimer > 1.2f && !chainSaw)
                        {
                            progression.HealthScript.Explosion(-1f);
                        }


                        if (ModdedPlayer.Stats.TotalMeleeArmorPiercing > 0)
                        {
                            progression.ReduceArmor(ModdedPlayer.Stats.TotalMeleeArmorPiercing);
                        }

                        if ((hitReactions.kingHitBool || fsmHeavyAttackBool.Value) && ModdedPlayer.Stats.perk_chargedAtkKnockback)
                        {
                            Vector3 dir = other.transform.position - LocalPlayer.Transform.position;
                            progression.AddKnockbackByDistance(dir, 1);
                        }

                        if (Effects.BlackFlame.IsOn)
                        {
                            progression.FireDebuff(40, Effects.BlackFlame.FireDamageBonus, 20);
                            if (BlackFlame.GiveAfterburn && Random.value < 0.1f)
                            {
                                progression.DmgTakenDebuff(120, 1.15f, 25);
                            }
                        }
                        if (ModdedPlayer.Stats.perk_fireDmgIncreaseOnHit)
                        {
                            int   myID    = 2000 + ModReferences.Players.IndexOf(LocalPlayer.GameObject);
                            float fireDmg = 1 + ModdedPlayer.Stats.spellFlatDmg / 3;
                            fireDmg *= ModdedPlayer.Stats.TotalMagicDamageMultiplier;
                            fireDmg *= ModdedPlayer.Stats.fireDamage + 1;
                            fireDmg *= 0.35f;
                            progression.FireDebuff(2000, fireDmg, 14);
                        }
                        if (ModdedPlayer.Stats.i_HammerStun && PlayerInventoryMod.EquippedModel == BaseItem.WeaponModelType.Hammer)
                        {
                            progression.Slow(40, ModdedPlayer.Stats.i_HammerStunAmount, ModdedPlayer.Stats.i_HammerStunDuration);
                        }

                        SpellActions.Bash(progression, outputdmg);


                        if ((fireStick && Random.value > 0.8f) || AlwaysIgnite || Effects.BlackFlame.IsOn)
                        {
                            progression.HealthScript.Burn();
                        }


                        AfterHit();
                        return(true);
                    }
                }
            }
            else if (other.gameObject.CompareTag("PlayerNet") && (mainTrigger || (!mainTrigger && (animControl.smashBool || chainSaw))))
            {
                if (ModSettings.FriendlyFire)
                {
                    BoltEntity component3 = other.GetComponent <BoltEntity>();
                    BoltEntity component4 = base.GetComponent <BoltEntity>();
                    if (!object.ReferenceEquals(component3, component4) && lastPlayerHit + 0.2f < Time.time)
                    {
                        other.transform.root.SendMessage("getClientHitDirection", animator.GetInteger("hitDirection"), SendMessageOptions.DontRequireReceiver);
                        other.transform.root.SendMessage("StartPrediction", SendMessageOptions.DontRequireReceiver);
                        lastPlayerHit = Time.time;
                        if (BoltNetwork.isRunning)
                        {
                            ModdedPlayer.instance.OnHit();
                            ModdedPlayer.instance.OnHit_Melee(other.transform);

                            DamageMath.ReduceDamageToSendOverNet(2f * (WeaponDamage + ModdedPlayer.Stats.meleeFlatDmg + SpellActions.GetParryCounterStrikeDmg()) * ModdedPlayer.Stats.MeleeDamageMult * ModdedPlayer.Stats.RandomCritDamage, out int dmg, out int repetitions);

                            HitPlayer hitPlayer = HitPlayer.Create(component3, EntityTargets.Everyone);
                            hitPlayer.damage = dmg;
                            for (int i = 0; i < repetitions; i++)
                            {
                                hitPlayer.Send();
                            }
                        }
                    }

                    AfterHit();
                }
                return(true);
            }
            return(false);
        }
コード例 #2
0
 private void Start()
 {
     instance = this;
 }
コード例 #3
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);
            }
        }
コード例 #4
0
        public override void CheckHit(Vector3 position, Transform target, bool isTrigger, Collider targetCollider)
        {
            if (ignoreCollisionEvents(targetCollider) && !target.CompareTag("enemyRoot"))
            {
                return;
            }
            if (!isTrigger)
            {
                Molotov componentInParent = transform.GetComponentInParent <Molotov>();
                if ((bool)componentInParent)
                {
                    componentInParent.IncendiaryBreak();
                    return;
                }
            }
            bool headDamage = false;

            if (target.gameObject.layer == LayerMask.NameToLayer("Water"))
            {
                FMODCommon.PlayOneshotNetworked(hitWaterEvent, base.transform, FMODCommon.NetworkRole.Any);
                return;
            }
            else if (target.CompareTag("SmallTree"))
            {
                FMODCommon.PlayOneshotNetworked(hitBushEvent, base.transform, FMODCommon.NetworkRole.Any);
                return;
            }
            else if (target.CompareTag("PlaneHull"))
            {
                FMODCommon.PlayOneshotNetworked(hitMetalEvent, base.transform, FMODCommon.NetworkRole.Any);
                return;
            }
            else if (target.CompareTag("Tree") || target.root.CompareTag("Tree") || target.CompareTag("Target"))
            {
                if (spearType)
                {
                    base.StartCoroutine(HitTree(hit.point - base.transform.forward * 2.1f));
                }
                else if (hitPointUpdated)
                {
                    base.StartCoroutine(HitTree(hit.point - base.transform.forward * 0.35f));
                }
                else
                {
                    base.StartCoroutine(HitTree(base.transform.position - base.transform.forward * 0.35f));
                }
                disableLive();
                if (target.CompareTag("Tree") || target.root.CompareTag("Tree"))
                {
                    TreeHealth component = target.GetComponent <TreeHealth>();
                    if (!(bool)component)
                    {
                        component = target.root.GetComponent <TreeHealth>();
                    }
                    if ((bool)component)
                    {
                        component.LodTree.AddTreeCutDownTarget(base.gameObject);
                    }
                }
                return;
            }
            else if (target.CompareTag("enemyCollide") || target.tag == "lb_bird" || target.CompareTag("animalCollide") || target.CompareTag("Fish") || target.CompareTag("enemyRoot") || target.CompareTag("animalRoot"))
            {
                if (lastPierced != null)
                {
                    if (target.root == lastPierced)
                    {
                        Physics.IgnoreCollision(base.GetComponent <Collider>(), targetCollider);
                        return;
                    }
                }
                bool  pierce       = false;
                float pierceChance = ModdedPlayer.Stats.projectilePierceChance - pierceCount;
                if (pierceChance > 0)
                {
                    if (pierceChance >= 1 || pierceChance < Random.value)
                    {
                        Physics.IgnoreCollision(base.GetComponent <Collider>(), targetCollider);
                        pierceCount++;
                        lastPierced = target.root;
                        Invoke("ForgetLastPierced", 0.125f);
                        pierce = true;
                    }
                }
                if (crossbowBoltType)
                {
                }
                else if (flintLockAmmoType)
                {
                }
                else if (spearType)
                {
                }
                else
                {
                    if (ModdedPlayer.Stats.i_CrossfireQuiver.value)
                    {
                        if (Time.time - ModdedPlayer.instance._lastCrossfireTime > 10 * ModdedPlayer.Stats.cooldown)
                        {
                            ModdedPlayer.instance._lastCrossfireTime = Time.time;
                            Vector3 pos = Camera.main.transform.position + Camera.main.transform.right * 5;
                            Vector3 dir = transform.position - pos;
                            dir.Normalize();
                            SpellActions.CastMagicArrow(pos, dir);
                        }
                    }
                }

                arrowStickToTarget arrowStickToTarget = target.GetComponent <arrowStickToTarget>();
                if (!(bool)arrowStickToTarget)
                {
                    arrowStickToTarget = target.root.GetComponentInChildren <arrowStickToTarget>();
                }

                bool isbird   = target.tag == "lb_bird" || target.CompareTag("lb_bird");
                bool isfish   = target.CompareTag("Fish");
                bool isanimal = target.CompareTag("animalCollide") || target.CompareTag("animalRoot");
                if (!spearType && !flintLockAmmoType && !isfish)
                {
                    if (arrowStickToTarget && arrowStickToTarget.enabled)
                    {
                        if (isbird)
                        {
                            EventRegistry.Achievements.Publish(TfEvent.Achievements.BirdArrowKill, null);
                        }
                        arrowStickToTarget.CreatureType(isanimal, isbird, isfish);
                        if (SpellActions.SeekingArrow_ChangeTargetOnHit)
                        {
                            startposition = transform.position;
                        }

                        if (BoltNetwork.isRunning)
                        {
                            if (at && at._boltEntity && at._boltEntity.isAttached && at._boltEntity.isOwner)
                            {
                                if (pierce)
                                {
                                    headDamage = ((XArrowStickToTargetMod)arrowStickToTarget).checkHeadDamage(transform);
                                }
                                else
                                {
                                    headDamage = arrowStickToTarget.stickArrowToNearestBone(base.transform);
                                }
                            }
                        }
                        else
                        {
                            if (pierce)
                            {
                                headDamage = ((XArrowStickToTargetMod)arrowStickToTarget).checkHeadDamage(transform);
                            }
                            headDamage = arrowStickToTarget.stickArrowToNearestBone(base.transform);
                        }
                    }
                    if ((bool)arrowStickToTarget && !pierce)
                    {
                        Destroy(parent.gameObject);
                    }
                }
                else
                {
                    if (SpellActions.SeekingArrow_ChangeTargetOnHit)
                    {
                        ModdedPlayer.Stats.spell_seekingArrow.value = true;
                        SpellActions.SeekingArrow_Target.gameObject.SetActive(true);
                        SpellActions.SeekingArrow_Target.parent   = target.transform;
                        SpellActions.SeekingArrow_Target.position = new Vector3(target.transform.position.x, transform.position.y - 0.075f, target.transform.position.z);
                        SpellActions.SeekingArrow_TimeStamp       = Time.time;
                        startposition = transform.position;
                        SpellActions.SeekingArrow_ChangeTargetOnHit = false;
                    }
                }
                if (headDamage && !flintLockAmmoType && ModdedPlayer.Stats.perk_trueAim && ModdedPlayer.Stats.spell_seekingArrow)
                {
                    //True aim ability
                    float dist = (startposition - transform.position).sqrMagnitude;
                    if (dist >= 3600f)
                    {
                        OutputDmg *= 4;
                        NewHitAi(target, isbird || isanimal, headDamage);
                        ModdedPlayer.instance.DoAreaDamage(target.root, OutputDmg);
                        ModdedPlayer.instance.OnHit();
                        ModdedPlayer.instance.OnHit_Ranged(target);
                        BuffDB.AddBuff(28, 104, 1.20f, 5);                              //crit chance
                        if (ModdedPlayer.Stats.perk_trueAimUpgrade && dist >= 14400f)
                        {
                            OutputDmg *= 10;

                            NewHitAi(target, isbird || isanimal, headDamage);
                            NewHitAi(target, isbird || isanimal, headDamage);
                            ModdedPlayer.instance.DoAreaDamage(target.root, OutputDmg);
                            ModdedPlayer.instance.OnHit();
                            ModdedPlayer.instance.OnHit_Ranged(target);
                            ModdedPlayer.instance.DoAreaDamage(target.root, OutputDmg);
                            ModdedPlayer.instance.OnHit();
                            ModdedPlayer.instance.OnHit_Ranged(target);
                        }
                    }
                }



                NewHitAi(target, isbird || isanimal, headDamage);
                ModdedPlayer.instance.DoAreaDamage(target.root, OutputDmg);
                ModdedPlayer.instance.OnHit();
                ModdedPlayer.instance.OnHit_Ranged(target);
                BoltEntity be = target.GetComponentInParent <BoltEntity>();
                if (be == null)
                {
                    be = target.GetComponent <BoltEntity>();
                }

                if (ModdedPlayer.Stats.perk_fireDmgIncreaseOnHit)
                {
                    int   myID = 1000 + ModReferences.Players.IndexOf(LocalPlayer.GameObject);
                    float dmg  = 1 + ModdedPlayer.Stats.spellFlatDmg / 3;
                    dmg *= ModdedPlayer.Stats.TotalMagicDamageMultiplier;
                    dmg *= ModdedPlayer.Stats.fireDamage + 1;
                    dmg *= 0.3f;
                    if (GameSetup.IsSinglePlayer || GameSetup.IsMpServer)
                    {
                        target.GetComponentInParent <EnemyProgression>()?.FireDebuff(myID, dmg, 14);
                    }
                    else
                    {
                        if (be != null)
                        {
                            using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                            {
                                using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                                {
                                    w.Write(27);
                                    w.Write(be.networkId.PackedValue);
                                    w.Write(dmg);
                                    w.Write(14.5f);
                                    w.Write(1);
                                    w.Close();
                                }
                                ChampionsOfForest.Network.NetworkManager.SendLine(answerStream.ToArray(), ChampionsOfForest.Network.NetworkManager.Target.OnlyServer);
                                answerStream.Close();
                            }
                        }
                    }
                }
                if (ModdedPlayer.Stats.TotalRangedArmorPiercing > 0 && target.gameObject.CompareTag("enemyCollide"))
                {
                    if (ModdedPlayer.Stats.perk_thrownSpearExtraArmorReduction && spearType)
                    {
                        if (BoltNetwork.isClient)
                        {
                            if (be != null)
                            {
                                EnemyProgression.ReduceArmor(be, ModdedPlayer.Stats.TotalRangedArmorPiercing * 2 + ModdedPlayer.Stats.TotalMeleeArmorPiercing);
                            }
                        }
                        else if (EnemyManager.enemyByTransform.ContainsKey(target.root))
                        {
                            var prog = EnemyManager.enemyByTransform[target.root];
                            prog.ReduceArmor(ModdedPlayer.Stats.TotalRangedArmorPiercing * 2 + ModdedPlayer.Stats.TotalMeleeArmorPiercing);
                        }
                    }
                    else
                    {
                        if (BoltNetwork.isClient)
                        {
                            if (be != null)
                            {
                                EnemyProgression.ReduceArmor(be, ModdedPlayer.Stats.TotalRangedArmorPiercing);
                            }
                        }
                        else if (EnemyManager.enemyByTransform.ContainsKey(target.root))
                        {
                            var prog = EnemyManager.enemyByTransform[target.root];
                            prog.ReduceArmor(ModdedPlayer.Stats.TotalRangedArmorPiercing);
                        }
                    }
                }
                if (isfish)
                {
                    base.StartCoroutine(HitFish(target, hit.point - base.transform.forward * 0.35f));
                }
                //check piercing

                if (pierce)
                {
                    return;
                }
                Live = false;
                disableLive();
                DisableFlight();
            }
            else if (target.CompareTag("PlayerNet"))
            {
                if (BoltNetwork.isRunning)
                {
                    BoltEntity be = target.GetComponentInParent <BoltEntity>();
                    if (!(bool)be)
                    {
                        be = target.GetComponent <BoltEntity>();
                    }

                    if (be)
                    {
                        if (ModdedPlayer.Stats.i_ArchangelBow && GreatBow.isEnabled)
                        {
                            float lifePerSecond = (ModdedPlayer.Stats.healthRecoveryPerSecond) * ModdedPlayer.Stats.allRecoveryMult * (ModdedPlayer.Stats.healthPerSecRate) * 2;
                            using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                            {
                                using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                                {
                                    w.Write(39);
                                    w.Write(be.GetState <IPlayerState>().name);
                                    w.Write(lifePerSecond);
                                    w.Write(ModdedPlayer.Stats.TotalMaxHealth * 0.2f);
                                    w.Close();
                                }
                                AsyncHit.SendCommandDelayed(1, answerStream.ToArray(), Network.NetworkManager.Target.OnlyServer);
                                answerStream.Close();
                            }
                            BuffDB.AddBuff(25, 91, lifePerSecond, 10);
                        }
                        else if (ModSettings.FriendlyFire)
                        {
                            float dmgUnclamped = this.OutputDmg;
                            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);
                                }
                            }

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

                            DamageMath.ReduceDamageToSendOverNet(dmgUnclamped, out int sendDamage, out int reps);

                            HitPlayer HP = HitPlayer.Create(be, EntityTargets.Everyone);
                            HP.damage = sendDamage;
                            for (int i = 0; i < reps; i++)
                            {
                                HP.Send();
                            }
                            //check piercing
                            float pierceChance = ModdedPlayer.Stats.projectilePierceChance - pierceCount;
                            if (pierceChance > 0)
                            {
                                if (pierceChance >= 1 || pierceChance < Random.value)
                                {
                                    Physics.IgnoreCollision(base.GetComponent <Collider>(), targetCollider);
                                    pierceCount++;
                                    return;
                                }
                            }
                            disableLive();
                            DisableFlight();
                        }
                    }
                }
            }
            else if (target.CompareTag("TerrainMain") && !LocalPlayer.IsInCaves)
            {
                if (ignoreTerrain)
                {
                    ignoreTerrain = false;
                    base.StartCoroutine(RevokeIgnoreTerrain());
                }
                else
                {
                    if (spearType)
                    {
                        if ((bool)bodyCollider)
                        {
                            bodyCollider.isTrigger = true;
                        }
                        base.StartCoroutine(HitStructure(base.transform.position - base.transform.forward * 2.1f, false));
                    }
                    else
                    {
                        Vector3 position2 = base.transform.position - base.transform.forward * -0.8f;
                        float   num       = Terrain.activeTerrain.SampleHeight(base.transform.position);
                        Vector3 position3 = Terrain.activeTerrain.transform.position;
                        float   num2      = num + position3.y;
                        Vector3 position4 = base.transform.position;
                        if (position4.y < num2)
                        {
                            position2.y = num2 + 0.5f;
                        }
                        base.StartCoroutine(HitStructure(position2, false));
                    }
                    disableLive();
                    FMODCommon.PlayOneshotNetworked(hitGroundEvent, base.transform, FMODCommon.NetworkRole.Any);
                }
            }
            else if (target.CompareTag("structure") || target.CompareTag("jumpObject") || target.CompareTag("SLTier1") || target.CompareTag("SLTier2") || target.CompareTag("SLTier3") || target.CompareTag("UnderfootWood"))
            {
                if ((bool)target.transform.parent)
                {
                    if ((bool)target.transform.parent.GetComponent <StickFenceChunkArchitect>())
                    {
                        return;
                    }
                    if ((bool)target.transform.parent.GetComponent <BoneFenceChunkArchitect>())
                    {
                        return;
                    }
                }
                if (!isTrigger)
                {
                    if (spearType)
                    {
                        base.StartCoroutine(HitStructure(hit.point - base.transform.forward * 2.1f, true));
                    }
                    else
                    {
                        base.StartCoroutine(HitStructure(hit.point - base.transform.forward * 0.35f, true));
                    }
                    disableLive();
                }
            }
            else if (target.CompareTag("CaveDoor"))
            {
                ignoreTerrain = true;
                Physics.IgnoreCollision(base.GetComponent <Collider>(), Terrain.activeTerrain.GetComponent <Collider>(), true);
            }
            else if (flintLockAmmoType && (target.CompareTag("BreakableWood") || target.CompareTag("BreakableRock")))
            {
                target.SendMessage("Hit", 40, SendMessageOptions.DontRequireReceiver);
            }
            if (!Live)
            {
                destroyThisAmmo();
                parent.BroadcastMessage("OnArrowHit", SendMessageOptions.DontRequireReceiver);
            }
        }
コード例 #5
0
        private void NewHitAi(Transform target, bool hitDelay, bool headDamage)
        {
            float dmgUnclamped = this.OutputDmg;

            if (SpellActions.SeekingArrow)
            {
                float dist = Vector3.Distance(target.position, startposition);
                dmgUnclamped *= 1 + dist * SpellActions.SeekingArrow_DamagePerDistance;
            }
            if (spearType)
            {
                if (ModdedPlayer.instance.SpearhellChance > 0 && Random.value <= ModdedPlayer.instance.SpearhellChance && OutputDmg > 1)
                {
                    var obj = Instantiate(PhysicBody, Camera.main.transform.position + Vector3.up * 2f, Quaternion.LookRotation(Camera.main.transform.forward));
                    obj.velocity = PhysicBody.velocity * 1.05f;
                    Destroy(obj.gameObject, 30);
                }
            }
            else
            {
                if (headDamage)
                {
                    if (ModdedPlayer.instance.EruptionBow && GreatBow.isEnabled)
                    {
                        //if (GameSetup.IsMultiplayer)
                        //{
                        BoltNetwork.Instantiate(BoltPrefabs.instantDynamite, transform.position, Quaternion.identity);
                        //}
                    }
                }
            }

            if (headDamage || (flintLockAmmoType && Random.value <= ModdedPlayer.instance.BulletCritChance) || (spearType && Random.value <= ModdedPlayer.instance.SpearCritChance))
            {
                headDamage    = true;
                dmgUnclamped *= ModdedPlayer.instance.HeadShotDamage;
                dmgUnclamped *= SpellActions.FocusOnHeadShot();
                if (SpellActions.SeekingArrow)
                {
                    dmgUnclamped *= SpellActions.SeekingArrow_HeadDamage;
                }
            }
            else
            {
                dmgUnclamped *= SpellActions.FocusOnBodyShot();
            }
            if (GreatBow.isEnabled)
            {
                dmgUnclamped *= 2.1f;
            }
            dmgUnclamped *= ModdedPlayer.instance.RangedAMP * ModdedPlayer.instance.CritDamageBuff;
            if (ModdedPlayer.instance.ProjectileDamageIncreasedBySize)
            {
                dmgUnclamped *= ModdedPlayer.instance.ProjectileSizeRatio;
            }
            DamageMath.DamageClamp(dmgUnclamped, out int sendDamage, out Repetitions);


            if (this.PhysicBody)
            {
                this.PhysicBody.velocity = Vector3.zero;
            }

            if (this.spearType)
            {
                this.PhysicBody.isKinematic = false;
                this.PhysicBody.useGravity  = true;
                this.disableLive();
                if (this.MyPickUp)
                {
                    this.MyPickUp.SetActive(true);
                }
            }
            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 componentInParent  = target.GetComponentInParent <BoltEntity>();
                if (!componentInParent)
                {
                    componentInParent = target.GetComponent <BoltEntity>();
                }



                if (BoltNetwork.isClient && componentInParent)
                {
                    ModdedPlayer.instance.OnHitEffectsClient(componentInParent, 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(componentInParent.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 (SpellActions.Focus && headDamage)
                    {
                        if (SpellActions.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(componentInParent.networkId.PackedValue);
                                    w.Write(SpellActions.FocusSlowAmount);
                                    w.Write(SpellActions.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 (SpellActions.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(componentInParent.networkId.PackedValue);
                                w.Write(SpellActions.SeekingArrow_SlowAmount);
                                w.Write(SpellActions.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(componentInParent.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      = componentInParent;
                        playerHitEnemy.Weapon      = component;
                        playerHitEnemy.getAttacker = 10;
                        if (target.gameObject.CompareTag("animalRoot"))
                        {
                            playerHitEnemy.getAttackDirection = animalHitDirection;
                        }
                        else
                        {
                            playerHitEnemy.getAttackDirection = 3;
                        }
                        playerHitEnemy.getAttackerType = 4;
                        playerHitEnemy.Hit             = sendDamage;
                        if (GreatBow.isEnabled && ModdedPlayer.instance.GreatBowIgnites)
                        {
                            playerHitEnemy.Burn = true;
                        }
                        AsyncHit.SendPlayerHitEnemy(playerHitEnemy, Repetitions);
                    }
                    else
                    {
                        target.transform.SendMessageUpwards("getClientHitDirection", 6, SendMessageOptions.DontRequireReceiver);
                        target.transform.SendMessageUpwards("StartPrediction", SendMessageOptions.DontRequireReceiver);
                        PlayerHitEnemy playerHitEnemy2 = PlayerHitEnemy.Create(GlobalTargets.OnlyServer);
                        playerHitEnemy2.Target = componentInParent;
                        if (target.gameObject.CompareTag("animalRoot"))
                        {
                            playerHitEnemy2.getAttackDirection = animalHitDirection;
                        }
                        else
                        {
                            playerHitEnemy2.getAttackDirection = 3;
                        }
                        playerHitEnemy2.getAttackerType = 4;
                        if (ignite || GreatBow.isEnabled && ModdedPlayer.instance.GreatBowIgnites)
                        {
                            playerHitEnemy2.Burn = true;
                        }
                        playerHitEnemy2.Hit = sendDamage;
                        AsyncHit.SendPlayerHitEnemy(playerHitEnemy2, Repetitions);
                    }
                }
                else
                {
                    if (target.gameObject.CompareTag("enemyRoot") || target.gameObject.CompareTag("enemyCollide"))
                    {
                        var ep = target.gameObject.GetComponentInParent <EnemyProgression>();
                        if (ep == null)
                        {
                            ep = target.gameObject.GetComponent <EnemyProgression>();
                            if (ep == null)
                            {
                                ep = target.gameObject.GetComponentInChildren <EnemyProgression>();
                            }
                        }
                        if (ignite)
                        {
                            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 (SpellActions.Focus && headDamage)
                        {
                            if (SpellActions.FocusBonusDmg == 0)
                            {
                                //slow enemy by 80%
                                ep.Slow(90, SpellActions.FocusSlowAmount, SpellActions.FocusSlowDuration);
                            }
                        }
                        else if (SpellActions.SeekingArrow)
                        {
                            ep.Slow(91, SpellActions.SeekingArrow_SlowAmount, SpellActions.SeekingArrow_SlowDuration);
                        }
                    }
                    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("lb_bird") || target.gameObject.CompareTag("animalRoot") || target.gameObject.CompareTag("enemyRoot") || target.gameObject.CompareTag("PlayerNet"))
                    {
                        if (target.gameObject.CompareTag("enemyRoot"))
                        {
                            EnemyHealth componentInChildren = target.GetComponentInChildren <EnemyHealth>();
                            if (componentInChildren)
                            {
                                componentInChildren.getAttackDirection(3);
                                componentInChildren.setSkinDamage(2);
                                mutantTargetSwitching componentInChildren2 = target.GetComponentInChildren <mutantTargetSwitching>();
                                if (componentInChildren2)
                                {
                                    componentInChildren2.getAttackerType(4);
                                    componentInChildren2.getAttacker(closestPlayerFromPos);
                                }
                                for (int i = 0; i < Repetitions; i++)
                                {
                                    componentInChildren.Hit(sendDamage);
                                }
                            }
                        }
                        else
                        {
                            if (target.gameObject.CompareTag("animalRoot"))
                            {
                                Repetitions = 1;
                                target.gameObject.SendMessage("ApplyAnimalSkinDamage", animalHitDirection, SendMessageOptions.DontRequireReceiver);
                            }
                            AsyncHit.SendPlayerHitEnemy(target, Repetitions, sendDamage);
                            if (ignite || GreatBow.isEnabled && ModdedPlayer.instance.GreatBowIgnites)
                            {
                                target.gameObject.SendMessage("Burn", SendMessageOptions.DontRequireReceiver);
                            }
                            target.gameObject.SendMessage("getSkinHitPosition", base.transform, SendMessageOptions.DontRequireReceiver);
                        }
                    }
                    else
                    {
                        if (target.gameObject.CompareTag("animalCollide"))
                        {
                            Repetitions = 1;
                            target.gameObject.SendMessageUpwards("ApplyAnimalSkinDamage", animalHitDirection, SendMessageOptions.DontRequireReceiver);
                        }
                        AsyncHit.SendPlayerHitEnemy(target, Repetitions, sendDamage);
                        if (GreatBow.isEnabled && ModdedPlayer.instance.GreatBowIgnites)
                        {
                            target.gameObject.SendMessage("Burn", SendMessageOptions.DontRequireReceiver);
                        }
                        target.gameObject.SendMessageUpwards("getSkinHitPosition", base.transform, SendMessageOptions.DontRequireReceiver);
                    }
                }
            }
            if (this.MyPickUp)
            {
                this.MyPickUp.SetActive(true);
            }
            FMODCommon.PlayOneshotNetworked(this.hitAiEvent, base.transform, FMODCommon.NetworkRole.Any);
        }
コード例 #6
0
        public override void CheckHit(Vector3 position, Transform target, bool isTrigger, Collider targetCollider)
        {
            if (ignoreCollisionEvents(targetCollider) && !target.CompareTag("enemyRoot"))
            {
                return;
            }
            if (!isTrigger)
            {
                Molotov componentInParent = transform.GetComponentInParent <Molotov>();
                if ((bool)componentInParent)
                {
                    componentInParent.IncendiaryBreak();
                }
            }
            bool headDamage = false;

            if (target.gameObject.layer == LayerMask.NameToLayer("Water"))
            {
                FMODCommon.PlayOneshotNetworked(hitWaterEvent, base.transform, FMODCommon.NetworkRole.Any);
            }
            else if (target.CompareTag("SmallTree"))
            {
                FMODCommon.PlayOneshotNetworked(hitBushEvent, base.transform, FMODCommon.NetworkRole.Any);
            }
            if (target.CompareTag("PlaneHull"))
            {
                FMODCommon.PlayOneshotNetworked(hitMetalEvent, base.transform, FMODCommon.NetworkRole.Any);
            }
            if (target.CompareTag("Tree") || target.root.CompareTag("Tree") || target.CompareTag("Target"))
            {
                if (spearType)
                {
                    base.StartCoroutine(HitTree(hit.point - base.transform.forward * 2.1f));
                }
                else if (hitPointUpdated)
                {
                    base.StartCoroutine(HitTree(hit.point - base.transform.forward * 0.35f));
                }
                else
                {
                    base.StartCoroutine(HitTree(base.transform.position - base.transform.forward * 0.35f));
                }
                disableLive();
                if (target.CompareTag("Tree") || target.root.CompareTag("Tree"))
                {
                    TreeHealth component = target.GetComponent <TreeHealth>();
                    if (!(bool)component)
                    {
                        component = target.root.GetComponent <TreeHealth>();
                    }
                    if ((bool)component)
                    {
                        component.LodTree.AddTreeCutDownTarget(base.gameObject);
                    }
                }
            }
            else if (target.CompareTag("enemyCollide") || target.tag == "lb_bird" || target.CompareTag("animalCollide") || target.CompareTag("Fish") || target.CompareTag("enemyRoot") || target.CompareTag("animalRoot"))
            {
                if (crossbowBoltType)
                {
                }
                else if (flintLockAmmoType)
                {
                }
                else if (spearType)
                {
                }
                else
                {
                    if (ModdedPlayer.instance.IsCrossfire)
                    {
                        if (Time.time - ModdedPlayer.instance.LastCrossfireTime > 10)
                        {
                            ModdedPlayer.instance.LastCrossfireTime = Time.time;
                            float damage1 = 55 + ModdedPlayer.instance.SpellDamageBonus * 1.25f;
                            damage1 = damage1 * ModdedPlayer.instance.SpellAMP;
                            Vector3 pos = Camera.main.transform.position + Camera.main.transform.right * 5;
                            Vector3 dir = transform.position - pos;
                            dir.Normalize();
                            if (GameSetup.IsSinglePlayer || GameSetup.IsMpServer)
                            {
                                MagicArrow.Create(pos, dir, damage1, ModReferences.ThisPlayerID, SpellActions.MagicArrowDuration, SpellActions.MagicArrowDoubleSlow, SpellActions.MagicArrowDmgDebuff);
                                if (BoltNetwork.isRunning)
                                {
                                    using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                                    {
                                        using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                                        {
                                            w.Write(3);
                                            w.Write(7);
                                            w.Write(pos.x);
                                            w.Write(pos.y);
                                            w.Write(pos.z);
                                            w.Write(dir.x);
                                            w.Write(dir.y);
                                            w.Write(dir.z);
                                            w.Write(damage1);
                                            w.Write(ModReferences.ThisPlayerID);
                                            w.Write(SpellActions.MagicArrowDuration);
                                            w.Write(SpellActions.MagicArrowDoubleSlow);
                                            w.Write(SpellActions.MagicArrowDmgDebuff);

                                            w.Close();
                                        }
                                        ChampionsOfForest.Network.NetworkManager.SendLine(answerStream.ToArray(), ChampionsOfForest.Network.NetworkManager.Target.Others);
                                        answerStream.Close();
                                    }
                                }
                            }
                            else if (GameSetup.IsMpClient)
                            {
                                MagicArrow.CreateEffect(pos, dir, SpellActions.MagicArrowDmgDebuff, SpellActions.MagicArrowDuration);
                                using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                                {
                                    using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                                    {
                                        w.Write(3);
                                        w.Write(7);
                                        w.Write(pos.x);
                                        w.Write(pos.y);
                                        w.Write(pos.z);
                                        w.Write(dir.x);
                                        w.Write(dir.y);
                                        w.Write(dir.z);
                                        w.Write(damage1);
                                        w.Write(ModReferences.ThisPlayerID);
                                        w.Write(SpellActions.MagicArrowDuration);
                                        w.Write(SpellActions.MagicArrowDoubleSlow);
                                        w.Write(SpellActions.MagicArrowDmgDebuff);

                                        w.Close();
                                    }
                                    ChampionsOfForest.Network.NetworkManager.SendLine(answerStream.ToArray(), ChampionsOfForest.Network.NetworkManager.Target.Others);
                                    answerStream.Close();
                                }
                            }
                        }
                    }
                }
                bool flag  = target.tag == "lb_bird" || target.CompareTag("lb_bird");
                bool flag2 = target.CompareTag("Fish");
                bool flag3 = target.CompareTag("animalCollide") || target.CompareTag("animalRoot");
                arrowStickToTarget arrowStickToTarget = target.GetComponent <arrowStickToTarget>();
                if (!(bool)arrowStickToTarget)
                {
                    arrowStickToTarget = target.root.GetComponentInChildren <arrowStickToTarget>();
                }
                if (!spearType && !flintLockAmmoType && !flag2)
                {
                    if (arrowStickToTarget && arrowStickToTarget.enabled)
                    {
                        if (flag)
                        {
                            EventRegistry.Achievements.Publish(TfEvent.Achievements.BirdArrowKill, null);
                        }
                        arrowStickToTarget.CreatureType(flag3, flag, flag2);
                        if (BoltNetwork.isRunning)
                        {
                            if (at && at._boltEntity && at._boltEntity.isAttached && at._boltEntity.isOwner)
                            {
                                headDamage = arrowStickToTarget.stickArrowToNearestBone(base.transform);
                            }
                        }
                        else
                        {
                            headDamage = arrowStickToTarget.stickArrowToNearestBone(base.transform);
                        }
                    }
                    if ((bool)arrowStickToTarget)
                    {
                        base.Invoke("destroyMe", 0.1f);
                    }
                }
                if (SpellActions.SeekingArrow_ChangeTargetOnHit)
                {
                    SpellActions.SeekingArrow = true;
                    SpellActions.SeekingArrow_Target.gameObject.SetActive(true);
                    SpellActions.SeekingArrow_Target.transform.parent   = target.transform;
                    SpellActions.SeekingArrow_Target.transform.position = new Vector3(target.transform.position.x, transform.position.y - 0.075f, target.transform.position.z);
                    SpellActions.SeekingArrow_TimeStamp = Time.time;
                    startposition = transform.position;
                    SpellActions.SeekingArrow_ChangeTargetOnHit = false;
                }
                if (headDamage && !flintLockAmmoType && ModdedPlayer.instance.TrueAim && SpellActions.SeekingArrow)
                {
                    float dist = (startposition - transform.position).sqrMagnitude;
                    if (dist >= 3600f)
                    {
                        OutputDmg *= 4;
                        NewHitAi(target, flag || flag3, headDamage);
                        ModdedPlayer.instance.DoAreaDamage(target.root, OutputDmg);
                        ModdedPlayer.instance.OnHit();
                        ModdedPlayer.instance.OnHit_Ranged(target);
                        if (ModdedPlayer.instance.TrueAimUpgrade && dist >= 14400f)
                        {
                            OutputDmg *= 10;

                            NewHitAi(target, flag || flag3, headDamage);
                            NewHitAi(target, flag || flag3, headDamage);
                            ModdedPlayer.instance.DoAreaDamage(target.root, OutputDmg);
                            ModdedPlayer.instance.OnHit();
                            ModdedPlayer.instance.OnHit_Ranged(target);
                            ModdedPlayer.instance.DoAreaDamage(target.root, OutputDmg);
                            ModdedPlayer.instance.OnHit();
                            ModdedPlayer.instance.OnHit_Ranged(target);
                        }
                    }
                }

                NewHitAi(target, flag || flag3, headDamage);
                ModdedPlayer.instance.DoAreaDamage(target.root, OutputDmg);
                ModdedPlayer.instance.OnHit();
                ModdedPlayer.instance.OnHit_Ranged(target);
                BoltEntity be = target.GetComponentInParent <BoltEntity>();
                if (be == null)
                {
                    be = target.GetComponent <BoltEntity>();
                }

                if (ModdedPlayer.instance.SpellAmpFireDmg)
                {
                    int   myID = 1000 + ModReferences.Players.IndexOf(LocalPlayer.GameObject);
                    float dmg  = 1 + ModdedPlayer.instance.SpellDamageBonus / 3;
                    dmg *= ModdedPlayer.instance.SpellAMP;
                    dmg *= ModdedPlayer.instance.FireAmp + 1;
                    dmg *= 0.3f;
                    if (GameSetup.IsSinglePlayer || GameSetup.IsMpServer)
                    {
                        target.GetComponentInParent <EnemyProgression>()?.FireDebuff(myID, dmg, 14);
                    }
                    else
                    {
                        if (be != null)
                        {
                            using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                            {
                                using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                                {
                                    w.Write(27);
                                    w.Write(be.networkId.PackedValue);
                                    w.Write(dmg);
                                    w.Write(14.5f);
                                    w.Write(1);
                                    w.Close();
                                }
                                ChampionsOfForest.Network.NetworkManager.SendLine(answerStream.ToArray(), ChampionsOfForest.Network.NetworkManager.Target.OnlyServer);
                                answerStream.Close();
                            }
                        }
                    }
                }
                if (ModdedPlayer.instance.RangedArmorReduction > 0 && target.gameObject.CompareTag("enemyCollide"))
                {
                    if (BoltNetwork.isClient)
                    {
                        if (be != null)
                        {
                            EnemyProgression.ReduceArmor(be, ModdedPlayer.instance.RangedArmorReduction);
                        }
                    }
                    else
                    {
                        target.transform.SendMessageUpwards("ReduceArmor", ModdedPlayer.instance.RangedArmorReduction, SendMessageOptions.DontRequireReceiver);
                    }
                }
                if (flag2)
                {
                    base.StartCoroutine(HitFish(target, hit.point - base.transform.forward * 0.35f));
                }
                disableLive();
            }
            else if (target.CompareTag("PlayerNet"))
            {
                if (BoltNetwork.isRunning)
                {
                    BoltEntity be = target.GetComponentInParent <BoltEntity>();
                    if (!(bool)be)
                    {
                        be = target.GetComponent <BoltEntity>();
                    }



                    if (be)
                    {
                        if (ModdedPlayer.instance.ArchangelBow && GreatBow.isEnabled)
                        {
                            using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                            {
                                using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                                {
                                    w.Write(39);
                                    w.Write(be.GetState <IPlayerState>().name);
                                    w.Write((ModdedPlayer.instance.LifeRegen) * ModdedPlayer.instance.HealingMultipier * (1 + ModdedPlayer.instance.HealthRegenPercent));
                                    w.Write(ModdedPlayer.instance.MaxHealth * 0.25f);
                                    w.Close();
                                }
                                AsyncHit.SendCommandDelayed(1, answerStream.ToArray(), Network.NetworkManager.Target.OnlyServer);
                                answerStream.Close();
                            }
                        }
                        else if (ModSettings.FriendlyFire)
                        {
                            float dmgUnclamped = this.OutputDmg;
                            if (SpellActions.SeekingArrow)
                            {
                                float dist = Vector3.Distance(target.position, startposition);
                                dmgUnclamped *= 1 + dist * SpellActions.SeekingArrow_DamagePerDistance;
                            }
                            if (spearType)
                            {
                                if (ModdedPlayer.instance.SpearhellChance > 0 && Random.value <= ModdedPlayer.instance.SpearhellChance && OutputDmg > 1)
                                {
                                    var obj = Instantiate(PhysicBody, Camera.main.transform.position + Vector3.up * 2f, Quaternion.LookRotation(Camera.main.transform.forward));
                                    obj.velocity = PhysicBody.velocity * 1.05f;
                                    Destroy(obj.gameObject, 30);
                                }
                            }
                            else
                            {
                                if (headDamage)
                                {
                                    if (ModdedPlayer.instance.EruptionBow && GreatBow.isEnabled)
                                    {
                                        //if (GameSetup.IsMultiplayer)
                                        //{
                                        BoltNetwork.Instantiate(BoltPrefabs.instantDynamite, transform.position, Quaternion.identity);
                                        //}
                                    }
                                }
                            }

                            if (headDamage || (flintLockAmmoType && Random.value <= ModdedPlayer.instance.BulletCritChance) || (spearType && Random.value <= ModdedPlayer.instance.SpearCritChance))
                            {
                                headDamage    = true;
                                dmgUnclamped *= ModdedPlayer.instance.HeadShotDamage;
                                dmgUnclamped *= SpellActions.FocusOnHeadShot();
                                if (SpellActions.SeekingArrow)
                                {
                                    dmgUnclamped *= SpellActions.SeekingArrow_HeadDamage;
                                }
                            }
                            else
                            {
                                dmgUnclamped *= SpellActions.FocusOnBodyShot();
                            }
                            if (GreatBow.isEnabled)
                            {
                                dmgUnclamped *= 2.1f;
                            }
                            dmgUnclamped *= ModdedPlayer.instance.RangedAMP * ModdedPlayer.instance.CritDamageBuff;
                            if (ModdedPlayer.instance.ProjectileDamageIncreasedBySize)
                            {
                                dmgUnclamped *= ModdedPlayer.instance.ProjectileSizeRatio;
                            }

                            DamageMath.DamageClamp(dmgUnclamped, out int sendDamage, out Repetitions);



                            HitPlayer HP = HitPlayer.Create(be, EntityTargets.Everyone);
                            HP.damage = sendDamage;
                            for (int i = 0; i < Repetitions; i++)
                            {
                                HP.Send();
                            }
                            disableLive();
                        }
                    }
                }
            }
            else if (target.CompareTag("TerrainMain") && !LocalPlayer.IsInCaves)
            {
                if (ignoreTerrain)
                {
                    ignoreTerrain = false;
                    base.StartCoroutine(RevokeIgnoreTerrain());
                }
                else
                {
                    if (spearType)
                    {
                        if ((bool)bodyCollider)
                        {
                            bodyCollider.isTrigger = true;
                        }
                        base.StartCoroutine(HitStructure(base.transform.position - base.transform.forward * 2.1f, false));
                    }
                    else
                    {
                        Vector3 position2 = base.transform.position - base.transform.forward * -0.8f;
                        float   num       = Terrain.activeTerrain.SampleHeight(base.transform.position);
                        Vector3 position3 = Terrain.activeTerrain.transform.position;
                        float   num2      = num + position3.y;
                        Vector3 position4 = base.transform.position;
                        if (position4.y < num2)
                        {
                            position2.y = num2 + 0.5f;
                        }
                        base.StartCoroutine(HitStructure(position2, false));
                    }
                    disableLive();
                    FMODCommon.PlayOneshotNetworked(hitGroundEvent, base.transform, FMODCommon.NetworkRole.Any);
                }
            }
            else if (target.CompareTag("structure") || target.CompareTag("jumpObject") || target.CompareTag("SLTier1") || target.CompareTag("SLTier2") || target.CompareTag("SLTier3") || target.CompareTag("UnderfootWood"))
            {
                if ((bool)target.transform.parent)
                {
                    if ((bool)target.transform.parent.GetComponent <StickFenceChunkArchitect>())
                    {
                        return;
                    }
                    if ((bool)target.transform.parent.GetComponent <BoneFenceChunkArchitect>())
                    {
                        return;
                    }
                }
                if (!isTrigger)
                {
                    if (spearType)
                    {
                        base.StartCoroutine(HitStructure(hit.point - base.transform.forward * 2.1f, true));
                    }
                    else
                    {
                        base.StartCoroutine(HitStructure(hit.point - base.transform.forward * 0.35f, true));
                    }
                    disableLive();
                }
            }
            else if (target.CompareTag("CaveDoor"))
            {
                ignoreTerrain = true;
                Physics.IgnoreCollision(base.GetComponent <Collider>(), Terrain.activeTerrain.GetComponent <Collider>(), true);
            }
            else if (flintLockAmmoType && (target.CompareTag("BreakableWood") || target.CompareTag("BreakableRock")))
            {
                target.SendMessage("Hit", 40, SendMessageOptions.DontRequireReceiver);
            }
            if (!Live)
            {
                destroyThisAmmo();
                parent.BroadcastMessage("OnArrowHit", SendMessageOptions.DontRequireReceiver);
            }
        }