From b28032ba8b2084a6109e6b5381e38720d1f3a1e2 Mon Sep 17 00:00:00 2001 From: christides11 <29593332+christides11@users.noreply.github.com> Date: Mon, 28 Sep 2020 22:54:16 -0700 Subject: [PATCH] feat: Added HurtInfoBase to store hurt information. BREAKING CHANGE: Instead of passing the huirt variables directly in OnHurt, instead allow the user to define what should be passed in their own HurtInfoBase. Avoids assuming how the user will implement this method. --- Assets/CAF/Combat/Boxes/Hitbox2D.cs | 22 +++++++++++++--- Assets/CAF/Combat/Boxes/Hitbox3D.cs | 26 +++++++++++++++++++ Assets/CAF/Combat/Boxes/HitboxBase.cs | 18 +++++-------- .../Combat/{ => Boxes}/HitboxForceRelation.cs | 0 .../{ => Boxes}/HitboxForceRelation.cs.meta | 0 .../CAF/Combat/{ => Boxes}/HitboxForceType.cs | 0 .../{ => Boxes}/HitboxForceType.cs.meta | 0 Assets/CAF/Combat/Info.meta | 8 ++++++ Assets/CAF/Combat/{ => Info}/HealInfoBase.cs | 0 .../Combat/{ => Info}/HealInfoBase.cs.meta | 0 Assets/CAF/Combat/{ => Info}/HitInfo.cs | 0 Assets/CAF/Combat/{ => Info}/HitInfo.cs.meta | 0 Assets/CAF/Combat/{ => Info}/HitInfoBase.cs | 0 .../CAF/Combat/{ => Info}/HitInfoBase.cs.meta | 0 Assets/CAF/Combat/Info/HurtInfo2D.cs | 24 +++++++++++++++++ Assets/CAF/Combat/Info/HurtInfo2D.cs.meta | 11 ++++++++ Assets/CAF/Combat/Info/HurtInfo3D.cs | 24 +++++++++++++++++ Assets/CAF/Combat/Info/HurtInfo3D.cs.meta | 11 ++++++++ Assets/CAF/Combat/Info/HurtInfoBase.cs | 21 +++++++++++++++ Assets/CAF/Combat/Info/HurtInfoBase.cs.meta | 11 ++++++++ Assets/CAF/Combat/Interfaces/IHurtable.cs | 2 +- .../Entities/Managers/EntityCombatManager.cs | 4 +-- .../Boxer/Moveset/Ground/Ground A.asset | 8 +++--- .../Entities/Managers/EntityCombatManager.cs | 11 ++++---- CAF.csproj | 13 ++++++---- 25 files changed, 182 insertions(+), 32 deletions(-) rename Assets/CAF/Combat/{ => Boxes}/HitboxForceRelation.cs (100%) rename Assets/CAF/Combat/{ => Boxes}/HitboxForceRelation.cs.meta (100%) rename Assets/CAF/Combat/{ => Boxes}/HitboxForceType.cs (100%) rename Assets/CAF/Combat/{ => Boxes}/HitboxForceType.cs.meta (100%) create mode 100644 Assets/CAF/Combat/Info.meta rename Assets/CAF/Combat/{ => Info}/HealInfoBase.cs (100%) rename Assets/CAF/Combat/{ => Info}/HealInfoBase.cs.meta (100%) rename Assets/CAF/Combat/{ => Info}/HitInfo.cs (100%) rename Assets/CAF/Combat/{ => Info}/HitInfo.cs.meta (100%) rename Assets/CAF/Combat/{ => Info}/HitInfoBase.cs (100%) rename Assets/CAF/Combat/{ => Info}/HitInfoBase.cs.meta (100%) create mode 100644 Assets/CAF/Combat/Info/HurtInfo2D.cs create mode 100644 Assets/CAF/Combat/Info/HurtInfo2D.cs.meta create mode 100644 Assets/CAF/Combat/Info/HurtInfo3D.cs create mode 100644 Assets/CAF/Combat/Info/HurtInfo3D.cs.meta create mode 100644 Assets/CAF/Combat/Info/HurtInfoBase.cs create mode 100644 Assets/CAF/Combat/Info/HurtInfoBase.cs.meta diff --git a/Assets/CAF/Combat/Boxes/Hitbox2D.cs b/Assets/CAF/Combat/Boxes/Hitbox2D.cs index aecd3311..e034bca5 100644 --- a/Assets/CAF/Combat/Boxes/Hitbox2D.cs +++ b/Assets/CAF/Combat/Boxes/Hitbox2D.cs @@ -107,18 +107,34 @@ protected virtual void CheckForHurtboxes(Collider2D other) protected override void HurtHurtable(IHurtable ih) { + ih.Hurt(BuildHurtInfo()); + } + + protected override HurtInfoBase BuildHurtInfo() + { + HurtInfo2D hurtInfo; + int faceDirection = GetFaceDirection(); switch (hitInfo.forceRelation) { case HitboxForceRelation.ATTACKER: - ih.Hurt(directionOwner.position, directionOwner.right, directionOwner.right, hitInfo); + hurtInfo = new HurtInfo2D(hitInfo, directionOwner.position, faceDirection); break; case HitboxForceRelation.HITBOX: - ih.Hurt(transform.position, transform.right, transform.right, hitInfo); + hurtInfo = new HurtInfo2D(hitInfo, transform.position, faceDirection); break; case HitboxForceRelation.WORLD: - ih.Hurt(transform.position, Vector3.right, Vector3.right, hitInfo); + hurtInfo = new HurtInfo2D(hitInfo, transform.position, faceDirection); + break; + default: + hurtInfo = new HurtInfo2D(); break; } + return hurtInfo; + } + + private int GetFaceDirection() + { + return directionOwner.localScale.x > 0 ? 1 : -1; } } } \ No newline at end of file diff --git a/Assets/CAF/Combat/Boxes/Hitbox3D.cs b/Assets/CAF/Combat/Boxes/Hitbox3D.cs index 67d7b93f..1b4f97a5 100644 --- a/Assets/CAF/Combat/Boxes/Hitbox3D.cs +++ b/Assets/CAF/Combat/Boxes/Hitbox3D.cs @@ -107,5 +107,31 @@ protected virtual void CheckForHurtboxes(Collider other) } } } + + protected override void HurtHurtable(IHurtable ih) + { + ih.Hurt(BuildHurtInfo()); + } + + protected override HurtInfoBase BuildHurtInfo() + { + HurtInfo3D hurtInfo; + switch (hitInfo.forceRelation) + { + case HitboxForceRelation.ATTACKER: + hurtInfo = new HurtInfo3D(hitInfo, directionOwner.position, directionOwner.forward, directionOwner.right); + break; + case HitboxForceRelation.HITBOX: + hurtInfo = new HurtInfo3D(hitInfo, transform.position, transform.forward, transform.right); + break; + case HitboxForceRelation.WORLD: + hurtInfo = new HurtInfo3D(hitInfo, transform.position, Vector3.forward, Vector3.right); + break; + default: + hurtInfo = new HurtInfo3D(); + break; + } + return hurtInfo; + } } } \ No newline at end of file diff --git a/Assets/CAF/Combat/Boxes/HitboxBase.cs b/Assets/CAF/Combat/Boxes/HitboxBase.cs index 8ca1ca25..e2266fd9 100644 --- a/Assets/CAF/Combat/Boxes/HitboxBase.cs +++ b/Assets/CAF/Combat/Boxes/HitboxBase.cs @@ -70,18 +70,12 @@ protected virtual void CheckHurtables() protected virtual void HurtHurtable(IHurtable ih) { - switch (hitInfo.forceRelation) - { - case HitboxForceRelation.ATTACKER: - ih.Hurt(directionOwner.position, directionOwner.forward, directionOwner.right, hitInfo); - break; - case HitboxForceRelation.HITBOX: - ih.Hurt(transform.position, transform.forward, transform.right, hitInfo); - break; - case HitboxForceRelation.WORLD: - ih.Hurt(transform.position, Vector3.forward, Vector3.right, hitInfo); - break; - } + ih.Hurt(BuildHurtInfo()); + } + + protected virtual HurtInfoBase BuildHurtInfo() + { + return new HurtInfoBase(hitInfo); } } } \ No newline at end of file diff --git a/Assets/CAF/Combat/HitboxForceRelation.cs b/Assets/CAF/Combat/Boxes/HitboxForceRelation.cs similarity index 100% rename from Assets/CAF/Combat/HitboxForceRelation.cs rename to Assets/CAF/Combat/Boxes/HitboxForceRelation.cs diff --git a/Assets/CAF/Combat/HitboxForceRelation.cs.meta b/Assets/CAF/Combat/Boxes/HitboxForceRelation.cs.meta similarity index 100% rename from Assets/CAF/Combat/HitboxForceRelation.cs.meta rename to Assets/CAF/Combat/Boxes/HitboxForceRelation.cs.meta diff --git a/Assets/CAF/Combat/HitboxForceType.cs b/Assets/CAF/Combat/Boxes/HitboxForceType.cs similarity index 100% rename from Assets/CAF/Combat/HitboxForceType.cs rename to Assets/CAF/Combat/Boxes/HitboxForceType.cs diff --git a/Assets/CAF/Combat/HitboxForceType.cs.meta b/Assets/CAF/Combat/Boxes/HitboxForceType.cs.meta similarity index 100% rename from Assets/CAF/Combat/HitboxForceType.cs.meta rename to Assets/CAF/Combat/Boxes/HitboxForceType.cs.meta diff --git a/Assets/CAF/Combat/Info.meta b/Assets/CAF/Combat/Info.meta new file mode 100644 index 00000000..747dc22b --- /dev/null +++ b/Assets/CAF/Combat/Info.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 16045472dd132654a917602133531f0e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/CAF/Combat/HealInfoBase.cs b/Assets/CAF/Combat/Info/HealInfoBase.cs similarity index 100% rename from Assets/CAF/Combat/HealInfoBase.cs rename to Assets/CAF/Combat/Info/HealInfoBase.cs diff --git a/Assets/CAF/Combat/HealInfoBase.cs.meta b/Assets/CAF/Combat/Info/HealInfoBase.cs.meta similarity index 100% rename from Assets/CAF/Combat/HealInfoBase.cs.meta rename to Assets/CAF/Combat/Info/HealInfoBase.cs.meta diff --git a/Assets/CAF/Combat/HitInfo.cs b/Assets/CAF/Combat/Info/HitInfo.cs similarity index 100% rename from Assets/CAF/Combat/HitInfo.cs rename to Assets/CAF/Combat/Info/HitInfo.cs diff --git a/Assets/CAF/Combat/HitInfo.cs.meta b/Assets/CAF/Combat/Info/HitInfo.cs.meta similarity index 100% rename from Assets/CAF/Combat/HitInfo.cs.meta rename to Assets/CAF/Combat/Info/HitInfo.cs.meta diff --git a/Assets/CAF/Combat/HitInfoBase.cs b/Assets/CAF/Combat/Info/HitInfoBase.cs similarity index 100% rename from Assets/CAF/Combat/HitInfoBase.cs rename to Assets/CAF/Combat/Info/HitInfoBase.cs diff --git a/Assets/CAF/Combat/HitInfoBase.cs.meta b/Assets/CAF/Combat/Info/HitInfoBase.cs.meta similarity index 100% rename from Assets/CAF/Combat/HitInfoBase.cs.meta rename to Assets/CAF/Combat/Info/HitInfoBase.cs.meta diff --git a/Assets/CAF/Combat/Info/HurtInfo2D.cs b/Assets/CAF/Combat/Info/HurtInfo2D.cs new file mode 100644 index 00000000..bcdc8fd5 --- /dev/null +++ b/Assets/CAF/Combat/Info/HurtInfo2D.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace CAF.Combat +{ + public class HurtInfo2D : HurtInfoBase + { + public Vector2 center; + public int faceDirection = 1; + + public HurtInfo2D() : base() + { + + } + + public HurtInfo2D(HitInfoBase hitInfo, Vector2 center, int faceDirection) + { + this.hitInfo = hitInfo; + this.center = center; + this.faceDirection = faceDirection; + } + } +} \ No newline at end of file diff --git a/Assets/CAF/Combat/Info/HurtInfo2D.cs.meta b/Assets/CAF/Combat/Info/HurtInfo2D.cs.meta new file mode 100644 index 00000000..4a42eb62 --- /dev/null +++ b/Assets/CAF/Combat/Info/HurtInfo2D.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 96b5da3b4d0e3d74e8dc84ff96c93e0a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/CAF/Combat/Info/HurtInfo3D.cs b/Assets/CAF/Combat/Info/HurtInfo3D.cs new file mode 100644 index 00000000..b6a7f4fa --- /dev/null +++ b/Assets/CAF/Combat/Info/HurtInfo3D.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace CAF.Combat +{ + public class HurtInfo3D : HurtInfoBase + { + public Vector3 center, forward, right; + + public HurtInfo3D() : base() + { + + } + + public HurtInfo3D(HitInfoBase hitInfo, Vector3 center, Vector3 forward, Vector3 right) + { + this.hitInfo = hitInfo; + this.center = center; + this.forward = forward; + this.right = right; + } + } +} \ No newline at end of file diff --git a/Assets/CAF/Combat/Info/HurtInfo3D.cs.meta b/Assets/CAF/Combat/Info/HurtInfo3D.cs.meta new file mode 100644 index 00000000..5830a039 --- /dev/null +++ b/Assets/CAF/Combat/Info/HurtInfo3D.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e7722e9bc01523948aafe3683c6d4272 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/CAF/Combat/Info/HurtInfoBase.cs b/Assets/CAF/Combat/Info/HurtInfoBase.cs new file mode 100644 index 00000000..81922468 --- /dev/null +++ b/Assets/CAF/Combat/Info/HurtInfoBase.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace CAF.Combat +{ + public class HurtInfoBase + { + public HitInfoBase hitInfo; + + public HurtInfoBase() + { + + } + + public HurtInfoBase(HitInfoBase hitInfo) + { + this.hitInfo = hitInfo; + } + } +} \ No newline at end of file diff --git a/Assets/CAF/Combat/Info/HurtInfoBase.cs.meta b/Assets/CAF/Combat/Info/HurtInfoBase.cs.meta new file mode 100644 index 00000000..cd5700c7 --- /dev/null +++ b/Assets/CAF/Combat/Info/HurtInfoBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d00030596bdb3514481c98348de969d6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/CAF/Combat/Interfaces/IHurtable.cs b/Assets/CAF/Combat/Interfaces/IHurtable.cs index 8ea20e59..54ffc514 100644 --- a/Assets/CAF/Combat/Interfaces/IHurtable.cs +++ b/Assets/CAF/Combat/Interfaces/IHurtable.cs @@ -7,7 +7,7 @@ namespace CAF.Combat public interface IHurtable { int GetTeam(); - HitReaction Hurt(Vector3 center, Vector3 forward, Vector3 right, HitInfoBase hitInfo); + HitReaction Hurt(HurtInfoBase hurtInfo); void Heal(HealInfoBase healInfo); } } \ No newline at end of file diff --git a/Assets/CAF/Entities/Managers/EntityCombatManager.cs b/Assets/CAF/Entities/Managers/EntityCombatManager.cs index eaeb1096..9660ebd7 100644 --- a/Assets/CAF/Entities/Managers/EntityCombatManager.cs +++ b/Assets/CAF/Entities/Managers/EntityCombatManager.cs @@ -353,11 +353,11 @@ public virtual void IncrementChargeLevelCharge() OnChargeLevelChargeChanged?.Invoke(manager, CurrentChargeLevelCharge-1); } - public virtual HitReaction Hurt(Vector3 center, Vector3 forward, Vector3 right, HitInfoBase hitInfo) + public virtual HitReaction Hurt(HurtInfoBase hurtInfoBase) { HitReaction hr = new HitReaction(); hr.reactionType = HitReactionType.Hit; - OnHit?.Invoke(null, manager, hitInfo); + OnHit?.Invoke(null, manager, hurtInfoBase.hitInfo); return hr; } diff --git a/Assets/CAF/Samples/TDAction/Characters/Boxer/Moveset/Ground/Ground A.asset b/Assets/CAF/Samples/TDAction/Characters/Boxer/Moveset/Ground/Ground A.asset index 1744e9d4..890cb189 100644 --- a/Assets/CAF/Samples/TDAction/Characters/Boxer/Moveset/Ground/Ground A.asset +++ b/Assets/CAF/Samples/TDAction/Characters/Boxer/Moveset/Ground/Ground A.asset @@ -62,9 +62,9 @@ MonoBehaviour: spaceBetweenHits: 0 opponentResetXForce: 1 opponentResetYForce: 1 - attackerHitstop: 0 - hitstop: 0 - hitstun: 0 + attackerHitstop: 4 + hitstop: 4 + hitstun: 30 forceType: 0 forceRelation: 0 breakArmor: 0 @@ -78,7 +78,7 @@ MonoBehaviour: damageOnBlock: 0 causesTumble: 0 opponentForceMagnitude: 1 - opponentForceDir: {x: 0, y: 0, z: 1} + opponentForceDir: {x: 1, y: 0, z: 0} forceIncludeYForce: 0 opponentMaxMagnitude: 1 opponentMinMagnitude: 1 diff --git a/Assets/CAF/Samples/TDAction/Scripts/Entities/Managers/EntityCombatManager.cs b/Assets/CAF/Samples/TDAction/Scripts/Entities/Managers/EntityCombatManager.cs index aab46af4..6f3f61b0 100644 --- a/Assets/CAF/Samples/TDAction/Scripts/Entities/Managers/EntityCombatManager.cs +++ b/Assets/CAF/Samples/TDAction/Scripts/Entities/Managers/EntityCombatManager.cs @@ -21,9 +21,10 @@ public override int GetTeam() return (int)team; } - public override HitReaction Hurt(Vector3 center, Vector3 forward, Vector3 right, HitInfoBase hitInfo) + public override HitReaction Hurt(HurtInfoBase hurtInfoBase) { - HitInfo hInfo = (HitInfo)hitInfo; + HurtInfo2D hurtInfo2D = (HurtInfo2D)hurtInfoBase; + HitInfo hInfo = (HitInfo)hurtInfo2D.hitInfo; HitReaction hitReaction = new HitReaction(); hitReaction.reactionType = HitReactionType.Hit; @@ -35,7 +36,7 @@ public override HitReaction Hurt(Vector3 center, Vector3 forward, Vector3 right, return hitReaction; } // Got hit, apply stun, damage, and forces. - LastHitBy = hitInfo; + LastHitBy = hInfo; SetHitStop(hInfo.hitstop); SetHitStun(hInfo.hitstun); @@ -44,14 +45,14 @@ public override HitReaction Hurt(Vector3 center, Vector3 forward, Vector3 right, { case HitboxForceType.SET: Vector2 baseForce = hInfo.opponentForceDir * hInfo.opponentForceMagnitude; - Vector3 forces = (forward * baseForce.x); + Vector3 forces = new Vector3(baseForce.x * hurtInfo2D.faceDirection, 0, 0); forces.y = baseForce.y; manager.PhysicsManager.forceGravity.y = baseForce.y; forces.y = 0; manager.PhysicsManager.forceMovement = forces; break; case HitboxForceType.PULL: - Vector3 dir = transform.position - center; + Vector2 dir = (Vector2)transform.position - hurtInfo2D.center; if (!hInfo.forceIncludeYForce) { dir.y = 0; diff --git a/CAF.csproj b/CAF.csproj index 498fc1b6..06c6a107 100644 --- a/CAF.csproj +++ b/CAF.csproj @@ -77,18 +77,21 @@ + + - - - - - + + + + + +