Crates, some new chemicals, statuseffects that are triggered on impact, explosions can trigger "OnFire" statuseffects, applying impulses to items (and not just characters) when the submarine hits something
This commit is contained in:
@@ -12,13 +12,18 @@ using Barotrauma.Items.Components;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using FarseerPhysics.Dynamics.Contacts;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
|
||||
public enum ActionType
|
||||
{
|
||||
Always, OnPicked, OnWearing, OnContaining, OnContained, OnActive, OnUse, OnFailure, OnBroken, OnFire, InWater
|
||||
Always, OnPicked, OnUse,
|
||||
OnWearing, OnContaining, OnContained,
|
||||
OnActive, OnFailure, OnBroken,
|
||||
OnFire, InWater,
|
||||
OnImpact
|
||||
}
|
||||
|
||||
class Item : MapEntity, IDamageable, IPropertyObject
|
||||
@@ -109,6 +114,11 @@ namespace Barotrauma
|
||||
get { return prefab.Description; }
|
||||
}
|
||||
|
||||
public float ImpactTolerance
|
||||
{
|
||||
get { return prefab.ImpactTolerance; }
|
||||
}
|
||||
|
||||
public override Sprite Sprite
|
||||
{
|
||||
get { return prefab.sprite; }
|
||||
@@ -383,6 +393,12 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
//containers need to handle collision events to notify items inside them about the impact
|
||||
if (ImpactTolerance > 0.0f || GetComponent<ItemContainer>() != null)
|
||||
{
|
||||
if (body != null) body.FarseerBody.OnCollision += OnCollision;
|
||||
}
|
||||
|
||||
InsertToList();
|
||||
ItemList.Add(this);
|
||||
}
|
||||
@@ -729,6 +745,27 @@ namespace Barotrauma
|
||||
body.ApplyTorque(body.AngularVelocity * volume * -0.05f);
|
||||
}
|
||||
|
||||
private bool OnCollision(Fixture f1, Fixture f2, Contact contact)
|
||||
{
|
||||
Vector2 normal = contact.Manifold.LocalNormal;
|
||||
|
||||
float impact = Vector2.Dot(f1.Body.LinearVelocity, -normal);
|
||||
|
||||
if (ImpactTolerance > 0.0f && impact > ImpactTolerance) ApplyStatusEffects(ActionType.OnImpact, 1.0f);
|
||||
|
||||
var containedItems = ContainedItems;
|
||||
if (containedItems != null)
|
||||
{
|
||||
foreach (Item contained in containedItems)
|
||||
{
|
||||
if (contained.body == null) continue;
|
||||
contained.OnCollision(f1, f2, contact);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true)
|
||||
{
|
||||
Color color = (isSelected && editing) ? color = Color.Red : spriteColor;
|
||||
|
||||
Reference in New Issue
Block a user