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:
@@ -56,8 +56,6 @@ namespace Subsurface.Items.Components
|
||||
if (!character.GetInputState(InputType.SecondaryHeld) || reload > 0.0f) return false;
|
||||
isActive = true;
|
||||
reload = 1.0f;
|
||||
|
||||
bool failed = DoesUseFail(character);
|
||||
|
||||
List<Body> limbBodies = new List<Body>();
|
||||
foreach (Limb l in character.AnimController.Limbs)
|
||||
@@ -68,6 +66,15 @@ namespace Subsurface.Items.Components
|
||||
Item[] containedItems = item.ContainedItems;
|
||||
if (containedItems == null || !containedItems.Any()) return false;
|
||||
|
||||
float degreeOfFailure = (100.0f - DegreeOfSuccess(character))/100.0f;
|
||||
|
||||
degreeOfFailure *= degreeOfFailure;
|
||||
|
||||
if (degreeOfFailure > Rand.Range(0.0f, 1.0f))
|
||||
{
|
||||
ApplyStatusEffects(ActionType.OnFailure, 1.0f, character);
|
||||
}
|
||||
|
||||
foreach (Item projectile in containedItems)
|
||||
{
|
||||
if (projectile == null) continue;
|
||||
@@ -76,35 +83,28 @@ namespace Subsurface.Items.Components
|
||||
//so that the player can't shoot himself
|
||||
Projectile projectileComponent= projectile.GetComponent<Projectile>();
|
||||
if (projectileComponent == null) continue;
|
||||
|
||||
|
||||
projectile.body.ResetDynamics();
|
||||
projectile.SetTransform(TransformedBarrelPos,
|
||||
(item.body.Dir == 1.0f) ? item.body.Rotation : item.body.Rotation - MathHelper.Pi);
|
||||
((item.body.Dir == 1.0f) ? item.body.Rotation : item.body.Rotation - MathHelper.Pi)
|
||||
+ Rand.Range(-degreeOfFailure, degreeOfFailure));
|
||||
|
||||
projectile.Use(deltaTime);
|
||||
|
||||
|
||||
if (failed)
|
||||
{
|
||||
Vector2 modifiedVelocity = projectile.body.LinearVelocity;
|
||||
modifiedVelocity.X *= Rand.Range(0.0f, 0.5f);
|
||||
modifiedVelocity.Y *= Rand.Range(0.0f, 0.5f);
|
||||
|
||||
projectile.body.LinearVelocity = modifiedVelocity;
|
||||
projectile.body.ApplyTorque(projectile.body.Mass * Rand.Range(-10.0f, 10.0f));
|
||||
projectile.body.ApplyTorque(projectile.body.Mass * degreeOfFailure * Rand.Range(-10.0f, 10.0f));
|
||||
|
||||
//recoil
|
||||
//item.body.ApplyLinearImpulse(
|
||||
// new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * item.body.Mass * -10.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.body.ApplyLinearImpulse(
|
||||
new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * item.body.Mass * -50.0f);
|
||||
|
||||
//else
|
||||
//{
|
||||
projectileComponent.ignoredBodies = limbBodies;
|
||||
|
||||
//recoil
|
||||
//item.body.ApplyLinearImpulse(
|
||||
// new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * -item.body.Mass);
|
||||
}
|
||||
//}
|
||||
|
||||
item.RemoveContained(projectile);
|
||||
|
||||
|
||||
@@ -104,13 +104,21 @@ namespace Subsurface.Items.Components
|
||||
if (character == null) return false;
|
||||
if (!character.GetInputState(InputType.SecondaryHeld)) return false;
|
||||
|
||||
if (DoesUseFail(character)) return false;
|
||||
//if (DoesUseFail(character)) return false;
|
||||
|
||||
isActive = true;
|
||||
|
||||
Vector2 targetPosition = item.body.SimPosition;
|
||||
//targetPosition = targetPosition.X, -targetPosition.Y);
|
||||
|
||||
float degreeOfSuccess = DegreeOfSuccess(character);
|
||||
|
||||
if (Rand.Range(0.0f, 1.0f) > degreeOfSuccess * degreeOfSuccess)
|
||||
{
|
||||
ApplyStatusEffects(ActionType.OnFailure, 1.0f, character);
|
||||
return false;
|
||||
}
|
||||
|
||||
targetPosition += new Vector2(
|
||||
(float)Math.Cos(item.body.Rotation),
|
||||
(float)Math.Sin(item.body.Rotation)) * range * item.body.Dir;
|
||||
@@ -118,6 +126,7 @@ namespace Subsurface.Items.Components
|
||||
List<Body> ignoredBodies = new List<Body>();
|
||||
foreach (Limb limb in character.AnimController.Limbs)
|
||||
{
|
||||
if (Rand.Range(0.0f, 1.0f) > degreeOfSuccess) continue;
|
||||
ignoredBodies.Add(limb.body.FarseerBody);
|
||||
}
|
||||
|
||||
|
||||
@@ -426,24 +426,44 @@ namespace Subsurface.Items.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
protected bool DoesUseFail(Character character)
|
||||
/// <summary>
|
||||
/// Returns 0.0f-1.0f based on how well the character can use the itemcomponent
|
||||
/// </summary>
|
||||
/// <returns>0.5f if all the skills meet the skill requirements exactly, 1.0f if they're way above and 0.0f if way less</returns>
|
||||
protected float DegreeOfSuccess(Character character)
|
||||
{
|
||||
foreach (Skill skill in requiredSkills)
|
||||
{
|
||||
int characterLevel = character.GetSkillLevel(skill.Name);
|
||||
if (characterLevel > skill.Level) continue;
|
||||
if (requiredSkills.Count == 0) return 100.0f;
|
||||
|
||||
if (Rand.Int(characterLevel) - skill.Level < 0)
|
||||
{
|
||||
item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, character);
|
||||
//Item.ApplyStatusEffects();
|
||||
return true;
|
||||
}
|
||||
float[] skillSuccess = new float[requiredSkills.Count];
|
||||
|
||||
for (int i = 0; i < requiredSkills.Count; i++ )
|
||||
{
|
||||
int characterLevel = character.GetSkillLevel(requiredSkills[i].Name);
|
||||
|
||||
skillSuccess[i] = (characterLevel - requiredSkills[i].Level);
|
||||
}
|
||||
|
||||
return false;
|
||||
float average = skillSuccess.Average();
|
||||
|
||||
return (average+100.0f)/2.0f;
|
||||
}
|
||||
|
||||
//public bool CheckFailure(Character character)
|
||||
//{
|
||||
// foreach (Skill skill in requiredSkills)
|
||||
// {
|
||||
// int characterLevel = character.GetSkillLevel(skill.Name);
|
||||
// if (characterLevel > skill.Level) continue;
|
||||
|
||||
// item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, character);
|
||||
// //Item.ApplyStatusEffects();
|
||||
// return true;
|
||||
|
||||
// }
|
||||
|
||||
// return false;
|
||||
//}
|
||||
|
||||
public bool HasRequiredContainedItems(bool addMessage)
|
||||
{
|
||||
List<RelatedItem> requiredContained = requiredItems.FindAll(ri=> ri.Type == RelatedItem.RelationType.Contained);
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
if (powerOnSound == null)
|
||||
{
|
||||
powerOnSound = Sound.Load("Content/Items/Electricity/powerOn.ogg");
|
||||
powerOnSound = Sound.Load("Content/Items/Electricity/powerOn.ogg", false);
|
||||
}
|
||||
|
||||
if (sparkSounds == null)
|
||||
@@ -81,7 +81,7 @@ namespace Subsurface.Items.Components
|
||||
string dir = Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\";
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
sparkSounds[i] = Sound.Load("Content/Items/Electricity/zap" + (i + 1) + ".ogg");
|
||||
sparkSounds[i] = Sound.Load("Content/Items/Electricity/zap" + (i + 1) + ".ogg", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,35 @@ namespace Subsurface.Items.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == null || character!=user) return false;
|
||||
|
||||
var powered = item.GetComponent<Powered>();
|
||||
if (powered != null)
|
||||
{
|
||||
if (powered.Voltage < 0.1f) return false;
|
||||
}
|
||||
|
||||
float degreeOfSuccess = DegreeOfSuccess(character);
|
||||
if (Rand.Range(0.0f, 0.5f) < degreeOfSuccess) return false;
|
||||
|
||||
item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, character);
|
||||
|
||||
//Vector2 baseVel = Rand.Vector(300.0f);
|
||||
//for (int i = 0; i < 10; i++)
|
||||
//{
|
||||
// var particle = GameMain.ParticleManager.CreateParticle("spark", item.Position,
|
||||
// baseVel + Rand.Vector(100.0f), 0.0f);
|
||||
|
||||
// if (particle != null) particle.Size *= Rand.Range(0.5f, 1.0f);
|
||||
//}
|
||||
|
||||
//character.AddDamage(item.SimPosition, DamageType.None, Math.Abs(degreeOfSuccess-100.0f)/10.0f, 0.0f, 3.0f, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Load(XElement element)
|
||||
{
|
||||
base.Load(element);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
@@ -26,6 +27,34 @@ namespace Subsurface.Items.Components
|
||||
LimbType[] limbType;
|
||||
Limb[] limb;
|
||||
|
||||
private float armorValue;
|
||||
|
||||
private Vector2 armorSector;
|
||||
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
public float ArmorValue
|
||||
{
|
||||
get { return armorValue; }
|
||||
set { armorValue = MathHelper.Clamp(value, 0.0f, 100.0f); }
|
||||
}
|
||||
|
||||
[HasDefaultValue("0.0,360.0", false)]
|
||||
public string ArmorSector
|
||||
{
|
||||
get { return ToolBox.Vector2ToString(armorSector); }
|
||||
set
|
||||
{
|
||||
armorSector = ToolBox.ParseToVector2(value);
|
||||
armorSector.X = MathHelper.ToRadians(armorSector.X);
|
||||
armorSector.Y = MathHelper.ToRadians(armorSector.Y);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 ArmorSectorLimits
|
||||
{
|
||||
get { return armorSector; }
|
||||
}
|
||||
|
||||
public Wearable (Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
@@ -76,7 +105,7 @@ namespace Subsurface.Items.Components
|
||||
if (equipLimb == null) continue;
|
||||
|
||||
//something is already on the limb -> unequip it
|
||||
if (equipLimb.WearingItem != null && equipLimb.WearingItem != item)
|
||||
if (equipLimb.WearingItem != null && equipLimb.WearingItem != this)
|
||||
{
|
||||
equipLimb.WearingItem.Unequip(character);
|
||||
}
|
||||
@@ -88,7 +117,7 @@ namespace Subsurface.Items.Components
|
||||
isActive = true;
|
||||
|
||||
limb[i] = equipLimb;
|
||||
equipLimb.WearingItem = item;
|
||||
equipLimb.WearingItem = this;
|
||||
equipLimb.WearingItemSprite = wearableSprite[i];
|
||||
}
|
||||
}
|
||||
@@ -111,7 +140,7 @@ namespace Subsurface.Items.Components
|
||||
Limb equipLimb = character.AnimController.GetLimb(limbType[i]);
|
||||
if (equipLimb == null) continue;
|
||||
|
||||
if (equipLimb.WearingItem != item) continue;
|
||||
if (equipLimb.WearingItem != this) continue;
|
||||
|
||||
limb[i] = null;
|
||||
equipLimb.WearingItem = null;
|
||||
|
||||
Reference in New Issue
Block a user