Skip to content

Commit

Permalink
feat: Added HurtInfoBase to store hurt information.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
christides11 committed Sep 29, 2020
1 parent 48d7c65 commit b28032b
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 32 deletions.
22 changes: 19 additions & 3 deletions Assets/CAF/Combat/Boxes/Hitbox2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
26 changes: 26 additions & 0 deletions Assets/CAF/Combat/Boxes/Hitbox3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
18 changes: 6 additions & 12 deletions Assets/CAF/Combat/Boxes/HitboxBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions Assets/CAF/Combat/Info.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions Assets/CAF/Combat/Info/HurtInfo2D.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
11 changes: 11 additions & 0 deletions Assets/CAF/Combat/Info/HurtInfo2D.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Assets/CAF/Combat/Info/HurtInfo3D.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
11 changes: 11 additions & 0 deletions Assets/CAF/Combat/Info/HurtInfo3D.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Assets/CAF/Combat/Info/HurtInfoBase.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
11 changes: 11 additions & 0 deletions Assets/CAF/Combat/Info/HurtInfoBase.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/CAF/Combat/Interfaces/IHurtable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions Assets/CAF/Entities/Managers/EntityCombatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions CAF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,21 @@
<Compile Include="Assets\CAF\Combat\Boxes\Hitbox2D.cs" />
<Compile Include="Assets\CAF\Combat\Boxes\Hitbox3D.cs" />
<Compile Include="Assets\CAF\Combat\Boxes\HitboxBase.cs" />
<Compile Include="Assets\CAF\Combat\Boxes\HitboxForceRelation.cs" />
<Compile Include="Assets\CAF\Combat\Boxes\HitboxForceType.cs" />
<Compile Include="Assets\CAF\Combat\Boxes\Hurtbox.cs" />
<Compile Include="Assets\CAF\Combat\Boxes\HurtboxState.cs" />
<Compile Include="Assets\CAF\Combat\ChargeDefinition.cs" />
<Compile Include="Assets\CAF\Combat\ChargeLevel.cs" />
<Compile Include="Assets\CAF\Combat\ForceType.cs" />
<Compile Include="Assets\CAF\Combat\HealInfoBase.cs" />
<Compile Include="Assets\CAF\Combat\HitInfo.cs" />
<Compile Include="Assets\CAF\Combat\HitInfoBase.cs" />
<Compile Include="Assets\CAF\Combat\HitReaction.cs" />
<Compile Include="Assets\CAF\Combat\HitReactionType.cs" />
<Compile Include="Assets\CAF\Combat\HitboxForceRelation.cs" />
<Compile Include="Assets\CAF\Combat\HitboxForceType.cs" />
<Compile Include="Assets\CAF\Combat\Info\HealInfoBase.cs" />
<Compile Include="Assets\CAF\Combat\Info\HitInfo.cs" />
<Compile Include="Assets\CAF\Combat\Info\HitInfoBase.cs" />
<Compile Include="Assets\CAF\Combat\Info\HurtInfo2D.cs" />
<Compile Include="Assets\CAF\Combat\Info\HurtInfo3D.cs" />
<Compile Include="Assets\CAF\Combat\Info\HurtInfoBase.cs" />
<Compile Include="Assets\CAF\Combat\Interfaces\IHurtable.cs" />
<Compile Include="Assets\CAF\Combat\Interfaces\IStatusEffectable.cs" />
<Compile Include="Assets\CAF\Combat\Interfaces\ITargetable.cs" />
Expand Down

0 comments on commit b28032b

Please sign in to comment.