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); }
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); } }