private void OnTriggerEnter2D(Collider2D coll) { LivingHealthBehaviour damageable = coll.GetComponent <LivingHealthBehaviour>(); //only harm others if it's not a suicide if (coll.gameObject == shooter && !isSuicide) { return; } //only harm the shooter if it's a suicide if (coll.gameObject != shooter && isSuicide) { return; } if (damageable == null || damageable.IsDead) { return; } var aim = isSuicide ? bodyAim : bodyAim.Randomize(); damageable.ApplyDamage(shooter, damage, damageType, aim); PostToChatMessage.SendItemAttackMessage(weapon.gameObject, shooter, coll.gameObject, damage, aim); Logger.LogTraceFormat("Hit {0} for {1} with HealthBehaviour! bullet absorbed", Category.Firearms, damageable.gameObject.name, damage); ReturnToPool(); }
//We need to slow the attack down because clients are behind server IEnumerator AttackFleshRoutine(Vector2 dir, LivingHealthBehaviour healthBehaviour) { if (healthBehaviour.connectionToClient == null) { yield break; } ServerDoLerpAnimation(dir); Debug.Log( $"CONN CLIENT TIME: {healthBehaviour.connectionToClient.lastMessageTime} Network time: {(float) NetworkTime.time}"); if (PlayerManager.LocalPlayerScript != null && PlayerManager.LocalPlayerScript.playerHealth != null && PlayerManager.LocalPlayerScript.playerHealth == healthBehaviour || healthBehaviour.RTT == 0f) { yield return(WaitFor.EndOfFrame); } else { Debug.Log($"WAIT FOR ATTACK: {healthBehaviour.RTT / 2f}"); yield return(WaitFor.Seconds(healthBehaviour.RTT / 2f)); } if (Vector3.Distance(transform.position, healthBehaviour.transform.position) < 1.5f) { healthBehaviour.ApplyDamageToBodypart(gameObject, hitDamage, AttackType.Melee, DamageType.Brute, defaultTarget.Randomize()); Chat.AddAttackMsgToChat(gameObject, healthBehaviour.gameObject, defaultTarget, null, attackVerb); SoundManager.PlayNetworkedAtPos("BladeSlice", transform.position, sourceObj: gameObject); } }
//We need to slow the attack down because clients are behind server private async Task AttackFleshRoutine(Vector2 dir, LivingHealthBehaviour targetHealth, LivingHealthMasterBase targetHealthV2, Vector3 worldPos, NetworkConnection ctc, float rtt) { if (targetHealth == null && targetHealthV2 == null) { return; } if (ctc == null) { return; } ServerDoLerpAnimation(dir); if (PlayerManager.LocalPlayerScript != null && PlayerManager.LocalPlayerScript.playerHealth != null && PlayerManager.LocalPlayerScript.playerHealth == targetHealthV2 || rtt < 0.02f) { //Wait until the end of the frame await Task.Delay(1); } else { //Wait until RTT/2 seconds? Logger.Log($"WAIT FOR ATTACK: {rtt / 2f}", Category.Mobs); await Task.Delay((int)(rtt * 500)); } if (Vector3.Distance(OriginTile.WorldPositionServer, worldPos) < 1.5f) { if (targetHealth != null) { targetHealth.ApplyDamageToBodyPart(gameObject, hitDamage, AttackType.Melee, DamageType.Brute, defaultTarget.Randomize()); Chat.AddAttackMsgToChat(gameObject, targetHealth.gameObject, defaultTarget, null, attackVerb); } else { targetHealthV2.ApplyDamageToBodyPart(gameObject, hitDamage, AttackType.Melee, DamageType.Brute, defaultTarget.Randomize()); Chat.AddAttackMsgToChat(gameObject, targetHealthV2.gameObject, defaultTarget, null, attackVerb); } SoundManager.PlayNetworkedAtPos(attackSound, OriginTile.WorldPositionServer, sourceObj: gameObject); } }
/// <summary> /// Invoked when BulletColliderBehavior passes the event up to us. /// </summary> public void HandleTriggerEnter2D(Collider2D coll) { //only harm others if it's not a suicide if (coll.gameObject == shooter && !isSuicide) { return; } //only harm the shooter if it's a suicide if (coll.gameObject != shooter && isSuicide) { return; } //body or object? var livingHealth = coll.GetComponent <LivingHealthBehaviour>(); var integrity = coll.GetComponent <Integrity>(); if (integrity != null) { //damage object integrity.ApplyDamage(damage, attackType, damageType); PostToChatMessage.SendAttackMessage(shooter, coll.gameObject, damage, BodyPartType.None, weapon.gameObject); Logger.LogTraceFormat("Hit {0} for {1} with HealthBehaviour! bullet absorbed", Category.Firearms, integrity.gameObject.name, damage); } else { //damage human if there is one if (livingHealth == null || livingHealth.IsDead) { return; } // Trigger for things like stuns GetComponent <BulletHitTrigger>()?.BulletHitInteract(coll.gameObject); var aim = isSuicide ? bodyAim : bodyAim.Randomize(); livingHealth.ApplyDamage(shooter, damage, attackType, damageType, aim); PostToChatMessage.SendAttackMessage(shooter, coll.gameObject, damage, aim, weapon.gameObject); Logger.LogTraceFormat("Hit {0} for {1} with HealthBehaviour! bullet absorbed", Category.Firearms, livingHealth.gameObject.name, damage); } ReturnToPool(); }
private void AttackFlesh(Vector2 dir, LivingHealthBehaviour healthBehaviour) { healthBehaviour.ApplyDamageToBodypart(gameObject, hitDamage, AttackType.Melee, DamageType.Brute, defaultTarget.Randomize()); Chat.AddAttackMsgToChat(gameObject, healthBehaviour.gameObject, defaultTarget, null, attackVerb); SoundManager.PlayNetworkedAtPos("BladeSlice", transform.position, sourceObj: gameObject); ServerDoLerpAnimation(dir); }