Attacks can apply a force to the target (i.e. monsters can throw characters around)
This commit is contained in:
@@ -78,11 +78,11 @@ namespace Barotrauma
|
||||
if (attacker!=null) aiController.OnAttacked(attacker, amount);
|
||||
}
|
||||
|
||||
public override AttackResult AddDamage(IDamageable attacker, Vector2 position, Attack attack, float deltaTime, bool playSound = false)
|
||||
public override AttackResult AddDamage(IDamageable attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = false)
|
||||
{
|
||||
AttackResult result = base.AddDamage(attacker, position, attack, deltaTime, playSound);
|
||||
AttackResult result = base.AddDamage(attacker, worldPosition, attack, deltaTime, playSound);
|
||||
|
||||
aiController.OnAttacked(attacker, (result.Damage + result.Bleeding)/Math.Max(health,1.0f));
|
||||
aiController.OnAttacked(attacker, (result.Damage + result.Bleeding) / Math.Max(health,1.0f));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ namespace Barotrauma
|
||||
|
||||
public readonly float Force;
|
||||
|
||||
public readonly float TargetForce;
|
||||
|
||||
private Sound sound;
|
||||
|
||||
private ParticleEmitterPrefab particleEmitterPrefab;
|
||||
@@ -105,6 +107,8 @@ namespace Barotrauma
|
||||
|
||||
Force = ToolBox.GetAttributeFloat(element,"force", 0.0f);
|
||||
|
||||
TargetForce = ToolBox.GetAttributeFloat(element, "targetforce", 0.0f);
|
||||
|
||||
Stun = ToolBox.GetAttributeFloat(element, "stun", 0.0f);
|
||||
|
||||
string soundPath = ToolBox.GetAttributeString(element, "sound", "");
|
||||
|
||||
@@ -1200,9 +1200,7 @@ namespace Barotrauma
|
||||
|
||||
public virtual AttackResult AddDamage(IDamageable attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = false)
|
||||
{
|
||||
|
||||
|
||||
var attackResult = AddDamage(worldPosition, attack.DamageType, attack.GetDamage(deltaTime), attack.GetBleedingDamage(deltaTime), attack.Stun, playSound);
|
||||
var attackResult = AddDamage(worldPosition, attack.DamageType, attack.GetDamage(deltaTime), attack.GetBleedingDamage(deltaTime), attack.Stun, playSound, attack.TargetForce);
|
||||
|
||||
var attackingCharacter = attacker as Character;
|
||||
if (attackingCharacter != null && attackingCharacter.AIController == null)
|
||||
@@ -1213,28 +1211,28 @@ namespace Barotrauma
|
||||
return attackResult;
|
||||
}
|
||||
|
||||
public AttackResult AddDamage(Vector2 simPosition, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound)
|
||||
public AttackResult AddDamage(Vector2 worldPosition, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound, float attackForce = 0.0f)
|
||||
{
|
||||
StartStun(stun);
|
||||
|
||||
|
||||
Limb closestLimb = null;
|
||||
float closestDistance = 0.0f;
|
||||
foreach (Limb limb in AnimController.Limbs)
|
||||
{
|
||||
float distance = Vector2.Distance(simPosition, limb.SimPosition);
|
||||
float distance = Vector2.Distance(worldPosition, limb.WorldPosition);
|
||||
if (closestLimb == null || distance < closestDistance)
|
||||
{
|
||||
closestLimb = limb;
|
||||
closestDistance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
if (Math.Abs(attackForce) > 0.0f)
|
||||
{
|
||||
closestLimb.body.ApplyForce((closestLimb.WorldPosition - worldPosition) * attackForce);
|
||||
}
|
||||
|
||||
Vector2 pull = simPosition - closestLimb.SimPosition;
|
||||
if (pull != Vector2.Zero) pull = Vector2.Normalize(pull);
|
||||
closestLimb.body.ApplyForce(pull*Math.Min(amount*100.0f, 100.0f));
|
||||
|
||||
|
||||
AttackResult attackResult = closestLimb.AddDamage(simPosition, damageType, amount, bleedingAmount, playSound);
|
||||
AttackResult attackResult = closestLimb.AddDamage(worldPosition, damageType, amount, bleedingAmount, playSound);
|
||||
|
||||
AddDamage(damageType == DamageType.Burn ? CauseOfDeath.Burn : causeOfDeath, attackResult.Damage, null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user