Loaded sounds are properly freed, ObjectProperty optimization, expanded skill effects (rangedweapon accuracy, welding efficiency, electrical shocks), armored wearables + ballistic vest & helmet

This commit is contained in:
Regalis
2015-09-28 19:48:31 +03:00
parent 97c3ac1412
commit cc16bb3ad7
34 changed files with 411 additions and 183 deletions

View File

@@ -15,6 +15,7 @@ using System.Xml.Linq;
namespace Subsurface
{
class Character : Entity, IDamageable, IPropertyObject
{
public static List<Character> CharacterList = new List<Character>();
@@ -170,6 +171,12 @@ namespace Subsurface
}
}
public float Stun
{
get { return AnimController.StunTimer; }
set { StartStun(value); }
}
public float Health
{
get
@@ -873,8 +880,7 @@ namespace Subsurface
public AttackResult AddDamage(Vector2 simPosition, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound)
{
AnimController.StunTimer = Math.Max(AnimController.StunTimer, stun);
StartStun(stun);
if (controlled == this) CharacterHUD.TakeDamage();
Limb closestLimb = null;
@@ -901,14 +907,11 @@ namespace Subsurface
return attackResult;
}
public void Stun()
public void StartStun(float stunTimer)
{
//for (int i = 0; i < selectedItems.Length; i++ )
//{
// if (selectedItems[i] == null) continue;
// selectedItems[i].Drop();
// selectedItems[i] = null;
//}
if (stunTimer <= 0.0f) return;
AnimController.StunTimer = Math.Max(AnimController.StunTimer, stunTimer);
selectedConstruction = null;
}
@@ -1268,7 +1271,7 @@ namespace Subsurface
}
catch { return; }
AnimController.StunTimer = newStunTimer;
StartStun(newStunTimer);
Health = newHealth;
LargeUpdateTimer = 1;

View File

@@ -125,8 +125,7 @@ namespace Subsurface
//stun (= disable the animations) if the ragdoll receives a large enough impact
if (strongestImpact > 0.0f)
{
character.Stun();
stunTimer = MathHelper.Clamp(strongestImpact * 0.5f, stunTimer, 5.0f);
character.StartStun(MathHelper.Min(strongestImpact * 0.5f, 5.0f));
}
strongestImpact = 0.0f;

View File

@@ -62,7 +62,7 @@ namespace Subsurface
private Direction dir;
private Item wearingItem;
private Wearable wearingItem;
private WearableSprite wearingItemSprite;
private Vector2 animTargetPos;
@@ -92,6 +92,7 @@ namespace Subsurface
get { return body.Rotation; }
}
//where an animcontroller is trying to pull the limb, only used for debug visualization
public Vector2 AnimTargetPos
{
get { return animTargetPos; }
@@ -156,7 +157,7 @@ namespace Subsurface
// set { bleeding = MathHelper.Clamp(value, 0.0f, 100.0f); }
//}
public Item WearingItem
public Wearable WearingItem
{
get { return wearingItem; }
set { wearingItem = value; }
@@ -238,7 +239,7 @@ namespace Subsurface
armorSector.X = MathHelper.ToRadians(armorSector.X);
armorSector.Y = MathHelper.ToRadians(armorSector.Y);
armorValue = Math.Max(ToolBox.GetAttributeFloat(element, "armor", 1.0f), 1.0f);
armorValue = Math.Max(ToolBox.GetAttributeFloat(element, "armor", 0.0f), 0.0f);
body.BodyType = BodyType.Dynamic;
body.FarseerBody.AngularDamping = LimbAngularDamping;
@@ -290,27 +291,33 @@ namespace Subsurface
DamageSoundType damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.LimbBlunt : DamageSoundType.LimbSlash;
bool hitArmor = false;
if (armorSector != Vector2.Zero)
float totalArmorValue = 0.0f;
if (armorValue>0.0f && SectorHit(armorSector, simPosition))
{
float rot = body.Rotation;
if (Dir == -1) rot -= MathHelper.Pi;
Vector2 armorLimits = new Vector2(rot-armorSector.X*Dir, rot-armorSector.Y*Dir);
float mid = (armorLimits.X + armorLimits.Y) / 2.0f;
float angleDiff = MathUtils.GetShortestAngle(MathUtils.VectorToAngle(simPosition - SimPosition), mid);
if (Math.Abs(angleDiff) < (armorSector.Y - armorSector.X) / 2.0f)
{
hitArmor = true;
damageSoundType = DamageSoundType.LimbArmor;
amount /= armorValue;
bleedingAmount /= armorValue;
}
hitArmor = true;
totalArmorValue += armorValue;
}
if (playSound && amount>0.0f)
if (wearingItem!=null &&
wearingItem.ArmorValue>0.0f &&
SectorHit(wearingItem.ArmorSectorLimits, simPosition))
{
hitArmor = true;
totalArmorValue += wearingItem.ArmorValue;
}
if (hitArmor)
{
totalArmorValue = Math.Max(totalArmorValue, 0.0f);
damageSoundType = DamageSoundType.LimbArmor;
amount = Math.Max(0.0f, amount - totalArmorValue);
bleedingAmount = Math.Max(0.0f, bleedingAmount - totalArmorValue); ;
}
if (playSound)
{
AmbientSoundManager.PlayDamageSound(damageSoundType, amount, ConvertUnits.ToDisplayUnits(simPosition));
}
@@ -338,6 +345,21 @@ namespace Subsurface
return new AttackResult(amount, bleedingAmount, hitArmor);
}
public bool SectorHit(Vector2 armorSector, Vector2 simPosition)
{
if (armorSector == Vector2.Zero) return false;
float rot = body.Rotation;
if (Dir == -1) rot -= MathHelper.Pi;
Vector2 armorLimits = new Vector2(rot - armorSector.X * Dir, rot - armorSector.Y * Dir);
float mid = (armorLimits.X + armorLimits.Y) / 2.0f;
float angleDiff = MathUtils.GetShortestAngle(MathUtils.VectorToAngle(simPosition - SimPosition), mid);
return (Math.Abs(angleDiff) < (armorSector.Y - armorSector.X) / 2.0f);
}
public void Update(float deltaTime)
{
if (LinearVelocity.X>100.0f)
@@ -416,7 +438,7 @@ namespace Subsurface
float depth = sprite.Depth - 0.000001f;
if (wearingItemSprite.DepthLimb==LimbType.None)
if (wearingItemSprite.DepthLimb!=LimbType.None)
{
Limb depthLimb = character.AnimController.GetLimb(wearingItemSprite.DepthLimb);
if (depthLimb!=null)

View File

@@ -228,6 +228,7 @@ namespace Subsurface
if (type == typeof(float))
{
float floatValue = (float)value * deltaTime;
if (!setValue) floatValue += (float)property.GetValue();
property.TrySetValue(floatValue);
}
@@ -253,7 +254,6 @@ namespace Subsurface
{
DelayedEffect.List[i].Update(deltaTime);
}
}
}
}
}