/// <summary> /// Called when this entity is shot. /// </summary> public void NotifyHit(HitInfos _HitInfos) { // Screen Shake ScreenShake.instance.StartShake(.2f, .1f); m_OnShot.Invoke(_HitInfos); }
void OnTakeHit(HitInfos hit) { if (curVirgoState != VirgoState.Discovered) { GiveUpVirgo(); targetBody = hit.Attacker.LinkedThing.Body; } }
/// <summary> /// Makes the character shoot. /// If the character is currently shooting (its cooldown is running), the action is cancelled. /// If the hit object has a Shootable component, triggers OnShot event on that component. /// </summary> public void DoShoot() { // If the character is already shooting (its cooldown is running) or the action is frozen, cancel update if (IsShooting || m_FreezeShoot) { return; } Vector3 aimVector = AimVector.normalized; // Start the cooldown coroutine m_ShootCooldownCoroutine = StartCoroutine(ApplyShootCooldown(m_ShootRange, m_ShootCooldown)); // Call OnShoot event m_ShootEvents.OnShoot.Invoke(new ShootInfos { origin = transform.position, direction = aimVector, range = m_ShootRange, cooldown = m_ShootCooldown, damages = m_ShootDamages }); // If the shot hit something if (Physics.Raycast(transform.position, aimVector, out RaycastHit rayHit, m_ShootRange, m_ShootableObjectsLayer)) { HitInfos infos = new HitInfos { shooter = gameObject, target = rayHit.collider.gameObject, origin = transform.position, impact = rayHit.point, distance = rayHit.distance, damages = m_ShootDamages }; // Call OnHitTarget event m_ShootEvents.OnHitTarget.Invoke(infos); if (rayHit.collider.TryGetComponent(out Shootable shootable)) { shootable.NotifyHit(infos); // If this character can gain score if (m_Scorer != null && shootable.ScoreByShot != 0) { // Get score from the target if possible m_Scorer.GainScore(shootable.ScoreByShot); } } #if UNITY_EDITOR if (m_EnableDebugLines) { Debug.DrawLine(transform.position, transform.position + aimVector * rayHit.distance, Color.red, m_DebugLineDuration); } #endif }
public void TakeHit(HitInfos hitInfos, out float blood, out float madness) { if (CurLivingState == LivingState.Dead) { blood = 0f; madness = 0; return; } if (linkedThing.IA.CurAttackState == e_EnemyAI.AttackState.Attacking && linkedThing.IA.WeaponType == e_EnemyAI.WeaponTypeEnum.Metal) { linkedThing.IA.InterruptAttack(); if (linkedThing.IA.WeaponType == e_EnemyAI.WeaponTypeEnum.Metal && linkedThing.Visual.InverseTransformDirection(hitInfos.Direction).z > 0) { blood = 0f; madness = 0f; Debug.Log("MonsterParry"); return; } } float diffHealth = curHealth; base.TakeHit(hitInfos); linkedThing.Agent.velocity = hitInfos.AttackObject.transform.TransformVector(hitInfos.AttackStats.knockback); diffHealth -= curHealth;//here diffhealth = difference of life before and after hit blood = bloodFactor * diffHealth; float factor = 0; switch (linkedThing.Hostility) { case e_EnemyAI.HostilityType.Hostile: factor *= 1; break; case e_EnemyAI.HostilityType.Neutral: factor *= 2; break; case e_EnemyAI.HostilityType.Innocent: factor *= 3; break; } madness = madnessFactor * diffHealth * factor; if (CurLivingState == LivingState.Dead) { madness += madnessOnDie; blood += bloodOnDie; } }
public HitInfos(HitInfos knownInfos, Vector3 PointOrDirValue, bool PointOrDir) : this(knownInfos) { if (PointOrDir) { this.HitPoint = PointOrDirValue; } else { this.Direction = PointOrDirValue; } }
public void TakeHit(HitInfos hit) { StartCoroutine(attackCoroutine()); health -= hit.AttackStats.damages; if (health <= 0) { Die(hit); } }
private void Die(HitInfos hit) { for (int i = transform.childCount - 1; i >= 0; i--) { Transform t = transform.GetChild(i); t.gameObject.SetActive(true); t.GetComponent <Rigidbody>().velocity = (((t.position - hit.HitPoint).normalized * (hit.AttackStats.knockback.magnitude * .5f) + hit.AttackObject.transform.TransformVector(hit.AttackStats.knockback) * 0.5f) * (Vector3.Distance(t.position, hit.HitPoint) > 0 ? 1.5f - Vector3.Distance(t.position, hit.HitPoint) : 0)) * 5f; t.SetParent(Game_NG.PhysicsHolder); } Destroy(gameObject); }
void OnAttackHit(HitInfos hit) { if (hit.AttackObject == grabAttack) { curVirgoState = VirgoState.AttackSucceed; curAttackState = AttackState.Attacking; targetBody = hit.Attacked.LinkedThing.Body; Visual.LookAt(targetBody.position.SetY(Body.position.y)); Destroy(grabAttack.gameObject); Destroy(linkedVirgo.Find("TrapTrigger").gameObject); } }
public void Initialize(HitInfos hitInfos, AttackStats.AttackWeightType weight = AttackStats.AttackWeightType.SameAsStats) { if (weight != AttackStats.AttackWeightType.SameAsStats) { Weight = weight; } else { Weight = hitInfos.AttackStats.weight; } this.hitInfos = new HitInfos(hitInfos, this); maxHitTimes = hitInfos.AttackStats.maxHitTimes; }
public HitInfos(HitInfos knownInfos) { if (knownInfos.Attacker != null) { Attacker = knownInfos.Attacker; } if (knownInfos.Attacked != null) { Attacked = knownInfos.Attacked; } if (knownInfos.AttackStats != null) { AttackStats = knownInfos.AttackStats; } if (knownInfos.AttackObject != null) { AttackObject = knownInfos.AttackObject; } if (knownInfos.EnemyAttackStats != null) { EnemyAttackStats = knownInfos.EnemyAttackStats; } if (knownInfos.PlayerAttackStats != null) { PlayerAttackStats = knownInfos.PlayerAttackStats; } if (knownInfos.HitPoint != Vector3.zero) { HitPoint = knownInfos.HitPoint; } if (knownInfos.Direction != Vector3.zero) { Direction = knownInfos.Direction; } if (knownInfos.BloodGot != 0) { BloodGot = knownInfos.BloodGot; } if (knownInfos.MadnessGot != 0) { MadnessGot = knownInfos.MadnessGot; } }
public virtual void TakeHit(HitInfos hitInfos) { if (CurLivingState == LivingState.Dead) { return; } linkedThing.SendMessage("OnTakeHit", hitInfos, SendMessageOptions.DontRequireReceiver); hitInfos.AttackStats.stunForce = Utilities.SubtractFloat(hitInfos.AttackStats.stunForce, stunResistance); if (hitInfos.AttackStats.stunForce >= maxStunValue) { StopCoroutine("StunCoroutine"); StartCoroutine("StunCoroutine", hitInfos.AttackStats.stunTime); } AddHealth(-hitInfos.AttackStats.damages); if (curHealth == 0) { Die(); } }
public override void TakeHit(HitInfos hit) { if (CurLivingState == LivingState.Dead) { return; } if (linkedThing.AttackState == p_AttackController.e_AttackState.Attacking) { linkedThing.AC.InterruptAttack(); if (linkedThing.Visual.InverseTransformDirection(hit.Direction).z > 0) { Debug.Log("PlayerParry"); return; } } if (linkedThing != null) { Vector3 knockback = Utilities.SubtractMagnitude(hit.AttackStats.knockback, knockbackResistance); linkedThing.R.AddForce(hit.Direction.SetY(0).normalized *knockback.SetY(0).magnitude + Vector3.zero.SetY(knockback.y), ForceMode.VelocityChange); } hit.AttackStats.stunForce = Utilities.SubtractFloat(hit.AttackStats.stunForce, stunResistance); if (hit.AttackStats.stunForce >= maxStunValue) { StopCoroutine("StunCoroutine"); StartCoroutine("StunCoroutine", hit.AttackStats.stunTime); } AddHealth(-hit.AttackStats.damages); if (curHealth == 0) { Die(); } }
/// <summary> /// Called when this entity is shot. /// </summary> public void NotifyHit(HitInfos _HitInfos) { m_OnShot.Invoke(_HitInfos); }
/// <summary> /// Decrease the number of lives using the given Hit Infos. /// </summary> public void RemoveLives(HitInfos _HitInfos) { RemoveLives(_HitInfos.damages); }
public HitInfos(HitInfos knownInfos, float bloodGot, float madnessGot) : this(knownInfos) { this.BloodGot = bloodGot; this.MadnessGot = madnessGot; }
public HitInfos(HitInfos knownInfos, Vector3 HitPoint, Vector3 Direction) : this(knownInfos) { this.HitPoint = HitPoint; this.Direction = Direction; }
public void InstantiatePrefab(HitInfos p_Infos) { Instantiate(m_Prefab, p_Infos.impact, Quaternion.identity); }
public HitInfos(HitInfos knownInfos, LivingBeing Attacked) : this(knownInfos) { this.Attacked = Attacked; }
public HitInfos(HitInfos knownInfos, AttackObject AttackObject) : this(knownInfos) { this.AttackObject = AttackObject; }
private void OnTriggerEnter(Collider other) { LivingBeing thingHit = other.GetComponentInParent <LivingBeing>(); RaycastHit hit; Ray ray = new Ray(transform.position, (other.transform.position - transform.position)); if (thingHit != null) { if (alreadyHit.Contains(thingHit)) { return; } else { alreadyHit.Add(thingHit); } hitInfos = new HitInfos(hitInfos, ray.direction, false); if (AttackOwner is p_PlayerBeing) { Physics.Raycast(ray, out hit, 100f, Game_NG.EnemyLayerMask); hitInfos = new HitInfos(hitInfos, hit.point, true); float blood, madness; ((e_EnemyBeing)thingHit).TakeHit(hitInfos, out blood, out madness); hitInfos = new HitInfos(hitInfos, blood, madness); } else if (AttackOwner is e_EnemyBeing) { Physics.Raycast(ray, out hit, 100f, Game_NG.PlayerLayerMask); hitInfos = new HitInfos(hitInfos, hit.point, true); ((p_PlayerBeing)thingHit).TakeHit(hitInfos); } hitInfos = new HitInfos(hitInfos, thingHit); AttackOwner.SendMessage("OnAttackHit", new HitInfos(hitInfos, thingHit), SendMessageOptions.DontRequireReceiver); maxHitTimes--; if (maxHitTimes <= 0) { Destroy(gameObject); } FX.SpawnHitFX(hitInfos.HitPoint, -hitInfos.Direction, thingHit.transform.parent); } else { Breakable breakableHit = other.GetComponentInParent <Breakable>(); Physics.Raycast(ray, out hit, 100f, Game_NG.AttackableLayerMask); if (breakableHit != null) { breakableHit.TakeHit(new HitInfos(hitInfos, hit.point, ray.direction)); } } }
void OnAttackHit(HitInfos infos) { AddBlood(infos.BloodGot); AddMadness(infos.MadnessGot); }