Welding tool, plasma cutter & misc item fixes/improvements
This commit is contained in:
@@ -162,7 +162,7 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
if (hideItems) return;
|
||||
if (hideItems || (item.body!=null && !item.body.Enabled)) return;
|
||||
|
||||
Vector2 transformedItemPos = itemPos;
|
||||
Vector2 transformedItemInterval = itemInterval;
|
||||
@@ -175,7 +175,7 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
item.body.Enabled = true;
|
||||
//item.body.Enabled = true;
|
||||
|
||||
Matrix transform = Matrix.CreateRotationZ(item.body.Rotation);
|
||||
|
||||
|
||||
@@ -134,14 +134,14 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Use(Character activator = null)
|
||||
public override bool Use(float deltaTime, Character activator = null)
|
||||
{
|
||||
character = activator;
|
||||
foreach (MapEntity e in item.linkedTo)
|
||||
{
|
||||
Item linkedItem = e as Item;
|
||||
if (linkedItem == null) continue;
|
||||
linkedItem.Use(activator);
|
||||
linkedItem.Use(deltaTime, activator);
|
||||
}
|
||||
|
||||
ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
|
||||
@@ -149,7 +149,7 @@ namespace Subsurface.Items.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void SecondaryUse(Character character = null)
|
||||
public override void SecondaryUse(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == null) return;
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
Item linkedItem = e as Item;
|
||||
if (linkedItem == null) continue;
|
||||
linkedItem.SecondaryUse(character);
|
||||
linkedItem.SecondaryUse(deltaTime, character);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,21 @@ namespace Subsurface.Items.Components
|
||||
ConvexHull convexHull;
|
||||
ConvexHull convexHull2;
|
||||
|
||||
private float stuck;
|
||||
public float Stuck
|
||||
{
|
||||
get { return stuck; }
|
||||
set
|
||||
{
|
||||
if (isOpen) return;
|
||||
stuck = MathHelper.Clamp(value, 0.0f, 100.0f);
|
||||
if (stuck == 0.0f) isStuck = false;
|
||||
if (stuck == 100.0f) isStuck = true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool isStuck;
|
||||
|
||||
Gap LinkedGap
|
||||
{
|
||||
get
|
||||
@@ -35,8 +50,9 @@ namespace Subsurface.Items.Components
|
||||
return linkedGap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool isOpen;
|
||||
|
||||
float openState;
|
||||
|
||||
[HasDefaultValue("0.0,0.0,0.0,0.0", false)]
|
||||
@@ -293,6 +309,8 @@ namespace Subsurface.Items.Components
|
||||
|
||||
public override void ReceiveSignal(string signal, Connection connection, Item sender)
|
||||
{
|
||||
if (isStuck) return;
|
||||
|
||||
if (connection.name=="toggle")
|
||||
{
|
||||
isOpen = !isOpen;
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace Subsurface.Items.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Use(Character character = null)
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (!attachable || item.body==null) return false;
|
||||
|
||||
@@ -213,7 +213,7 @@ namespace Subsurface.Items.Components
|
||||
|
||||
public override void OnMapLoaded()
|
||||
{
|
||||
if (attached) Use();
|
||||
if (attached) Use(1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,7 @@ namespace Subsurface
|
||||
switch (subElement.Name.ToString().ToLower())
|
||||
{
|
||||
case "requireditem":
|
||||
case "requireditems":
|
||||
RelatedItem ri = RelatedItem.Load(subElement);
|
||||
if (ri != null) requiredItems.Add(ri);
|
||||
break;
|
||||
@@ -264,13 +265,13 @@ namespace Subsurface
|
||||
|
||||
//called when the item is equipped and left mouse button is pressed
|
||||
//returns true if the item was used succesfully (not out of ammo, reloading, etc)
|
||||
public virtual bool Use(Character character = null)
|
||||
public virtual bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//called when the item is equipped and right mouse button is pressed
|
||||
public virtual void SecondaryUse(Character character = null) { }
|
||||
public virtual void SecondaryUse(float deltaTime, Character character = null) { }
|
||||
|
||||
//called when the item is placed in a "limbslot"
|
||||
public virtual void Equip(Character character) { }
|
||||
@@ -347,12 +348,21 @@ namespace Subsurface
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ApplyStatusEffects(ActionType type, float deltaTime, Character character = null, Limb limb = null)
|
||||
public void ApplyStatusEffects(ActionType type, float deltaTime, Character character = null)
|
||||
{
|
||||
foreach (StatusEffect effect in statusEffects)
|
||||
{
|
||||
if (effect.type != type) continue;
|
||||
item.ApplyStatusEffect(effect, type, deltaTime, character, limb);
|
||||
item.ApplyStatusEffect(effect, type, deltaTime, character);
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyStatusEffects(ActionType type, float deltaTime, Vector2 position, IPropertyObject target)
|
||||
{
|
||||
foreach (StatusEffect effect in statusEffects)
|
||||
{
|
||||
if (effect.type != type) continue;
|
||||
effect.Apply(type, deltaTime, position, target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Subsurface.Items.Components
|
||||
if (!picker.HasSelectedItem(item) && item.body!=null) item.body.Enabled = false;
|
||||
this.picker = picker;
|
||||
|
||||
ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker, null);
|
||||
ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker);
|
||||
|
||||
//foreach (StatusEffect effect in item.Prefab.statusEffects)
|
||||
//{
|
||||
|
||||
@@ -75,11 +75,11 @@ namespace Subsurface.Items.Components
|
||||
|
||||
//}
|
||||
|
||||
public override bool Use(Character character = null)
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character != null && !characterUsable) return false;
|
||||
|
||||
ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
|
||||
//ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
|
||||
|
||||
Debug.WriteLine(item.body.Rotation);
|
||||
|
||||
|
||||
@@ -14,10 +14,11 @@ namespace Subsurface.Items.Components
|
||||
|
||||
private Vector2 barrelPos;
|
||||
|
||||
//[Initable(new Vector2(0.0f, 0.0f))]
|
||||
public Vector2 BarrelPos
|
||||
[HasDefaultValue("0.0,0.0", false)]
|
||||
public string BarrelPos
|
||||
{
|
||||
get { return new Vector2(barrelPos.X * item.body.Dir, barrelPos.Y); }
|
||||
get { return ToolBox.Vector2ToString(ConvertUnits.ToDisplayUnits(barrelPos)); }
|
||||
set { barrelPos = ConvertUnits.ToSimUnits(ToolBox.ParseToVector2(value)); }
|
||||
}
|
||||
|
||||
public Vector2 TransformedBarrelPos
|
||||
@@ -25,7 +26,9 @@ namespace Subsurface.Items.Components
|
||||
get
|
||||
{
|
||||
Matrix bodyTransform = Matrix.CreateRotationZ(item.body.Rotation);
|
||||
return (Vector2.Transform(BarrelPos, bodyTransform) + item.body.Position);
|
||||
Vector2 flippedPos = barrelPos;
|
||||
if (item.body.Dir < 0.0f) flippedPos.X = -flippedPos.X;
|
||||
return (Vector2.Transform(flippedPos, bodyTransform) + item.body.Position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +50,7 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Use(Character character = null)
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == null) return false;
|
||||
if (!character.SecondaryKeyDown.State || reload > 0.0f) return false;
|
||||
@@ -78,7 +81,7 @@ namespace Subsurface.Items.Components
|
||||
projectile.SetTransform(TransformedBarrelPos,
|
||||
(item.body.Dir == 1.0f) ? item.body.Rotation : item.body.Rotation - MathHelper.Pi);
|
||||
|
||||
projectile.Use();
|
||||
projectile.Use(deltaTime);
|
||||
item.RemoveContained(projectile);
|
||||
|
||||
//recoil
|
||||
|
||||
@@ -5,6 +5,7 @@ using FarseerPhysics;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Subsurface.Particles;
|
||||
|
||||
namespace Subsurface.Items.Components
|
||||
{
|
||||
@@ -16,29 +17,49 @@ namespace Subsurface.Items.Components
|
||||
|
||||
Vector2 pickedPosition;
|
||||
|
||||
Vector2 barrelPos;
|
||||
|
||||
float structureFixAmount, limbFixAmount;
|
||||
|
||||
[HasDefaultValue(100.0f, false)]
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
public float Range
|
||||
{
|
||||
get { return ConvertUnits.ToDisplayUnits(range); }
|
||||
set { range = ConvertUnits.ToSimUnits(value); }
|
||||
}
|
||||
|
||||
[HasDefaultValue(1.0f, false)]
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
public float StructureFixAmount
|
||||
{
|
||||
get { return structureFixAmount; }
|
||||
set { structureFixAmount = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(1.0f, false)]
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
public float LimbFixAmount
|
||||
{
|
||||
get { return limbFixAmount; }
|
||||
set { limbFixAmount = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue("0.0,0.0", false)]
|
||||
public string BarrelPos
|
||||
{
|
||||
get { return ToolBox.Vector2ToString(ConvertUnits.ToDisplayUnits(barrelPos)); }
|
||||
set { barrelPos = ConvertUnits.ToSimUnits(ToolBox.ParseToVector2(value)); }
|
||||
}
|
||||
|
||||
public Vector2 TransformedBarrelPos
|
||||
{
|
||||
get
|
||||
{
|
||||
Matrix bodyTransform = Matrix.CreateRotationZ(item.body.Rotation);
|
||||
Vector2 flippedPos = barrelPos;
|
||||
if (item.body.Dir < 0.0f) flippedPos.X = -flippedPos.X;
|
||||
return (Vector2.Transform(flippedPos, bodyTransform) + item.body.Position);
|
||||
}
|
||||
}
|
||||
|
||||
public RepairTool(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
@@ -69,16 +90,18 @@ namespace Subsurface.Items.Components
|
||||
|
||||
//}
|
||||
|
||||
public override bool Use(Character character = null)
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == null) return false;
|
||||
|
||||
isActive = true;
|
||||
|
||||
Vector2 targetPosition = item.body.Position;
|
||||
//targetPosition = targetPosition.X, -targetPosition.Y);
|
||||
|
||||
targetPosition += new Vector2(
|
||||
(float)Math.Cos(item.body.Rotation) * range,
|
||||
(float)Math.Sin(item.body.Rotation) * range) * item.body.Dir;
|
||||
(float)Math.Cos(item.body.Rotation),
|
||||
(float)Math.Sin(item.body.Rotation)) * range * item.body.Dir;
|
||||
|
||||
List<Body> ignoredBodies = new List<Body>();
|
||||
foreach (Limb limb in character.animController.limbs)
|
||||
@@ -86,13 +109,12 @@ namespace Subsurface.Items.Components
|
||||
ignoredBodies.Add(limb.body.FarseerBody);
|
||||
}
|
||||
|
||||
|
||||
Body targetBody = Map.PickBody(item.body.Position, targetPosition, ignoredBodies);
|
||||
Body targetBody = Map.PickBody(TransformedBarrelPos, targetPosition, ignoredBodies);
|
||||
pickedPosition = Map.LastPickedPosition;
|
||||
|
||||
if (targetBody==null || targetBody.UserData==null) return false;
|
||||
if (targetBody==null || targetBody.UserData==null) return true;
|
||||
|
||||
ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
|
||||
//ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
|
||||
|
||||
|
||||
Structure targetStructure;
|
||||
@@ -100,18 +122,14 @@ namespace Subsurface.Items.Components
|
||||
Item targetItem;
|
||||
if ((targetStructure = (targetBody.UserData as Structure)) != null)
|
||||
{
|
||||
if (!fixableEntities.Contains(targetStructure.Name)) return false;
|
||||
if (!fixableEntities.Contains(targetStructure.Name)) return true;
|
||||
|
||||
int sectionIndex = targetStructure.FindSectionIndex(ConvertUnits.ToDisplayUnits(pickedPosition));
|
||||
if (sectionIndex < 0) return false;
|
||||
if (sectionIndex < 0) return true;
|
||||
|
||||
targetStructure.HighLightSection(sectionIndex);
|
||||
|
||||
if (character.SecondaryKeyDown.State)
|
||||
{
|
||||
targetStructure.AddDamage(sectionIndex, -structureFixAmount);
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if ((targetLimb = (targetBody.UserData as Limb)) != null)
|
||||
@@ -119,26 +137,55 @@ namespace Subsurface.Items.Components
|
||||
if (character.SecondaryKeyDown.State)
|
||||
{
|
||||
targetLimb.character.Health += limbFixAmount;
|
||||
isActive = true;
|
||||
//isActive = true;
|
||||
}
|
||||
}
|
||||
else if ((targetItem = (targetBody.UserData as Item)) !=null)
|
||||
else if ((targetItem = (targetBody.UserData as Item)) != null)
|
||||
{
|
||||
targetItem.Condition -= structureFixAmount;
|
||||
//targetItem.Condition -= structureFixAmount;
|
||||
targetItem.IsHighlighted = true;
|
||||
|
||||
foreach (StatusEffect effect in statusEffects)
|
||||
{
|
||||
if (Array.IndexOf(effect.TargetNames, targetItem.Name) == -1) continue;
|
||||
effect.Apply(ActionType.OnUse, deltaTime, targetItem);
|
||||
//targetItem.ApplyStatusEffect(effect, ActionType.OnUse, deltaTime);
|
||||
}
|
||||
//ApplyStatusEffects(ActionType.OnUse, 1.0f, null, targ);
|
||||
}
|
||||
|
||||
//if (character.SecondaryKeyDown.State)
|
||||
//{
|
||||
// IPropertyObject propertyObject = targetBody.UserData as IPropertyObject;
|
||||
// if (propertyObject!=null) ApplyStatusEffects(ActionType.OnUse, 1.0f, item.SimPosition, propertyObject);
|
||||
// //isActive = true;
|
||||
//}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
base.Update(deltaTime, cam);
|
||||
|
||||
//isActive = true;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (!isActive) return;
|
||||
|
||||
Vector2 startPos = ConvertUnits.ToDisplayUnits(item.body.Position);
|
||||
Vector2 endPos = ConvertUnits.ToDisplayUnits(pickedPosition);
|
||||
endPos = new Vector2(endPos.X + Game1.localRandom.Next(-2, 2), endPos.Y + Game1.localRandom.Next(-2, 2));
|
||||
Vector2 particleSpeed = new Vector2(
|
||||
(float)Math.Cos(item.body.Rotation),
|
||||
(float)Math.Sin(item.body.Rotation)) *item.body.Dir * 5.0f;
|
||||
|
||||
GUI.DrawLine(spriteBatch, startPos, endPos, Color.Orange, 0.0f);
|
||||
Game1.particleManager.CreateParticle("weld", TransformedBarrelPos, particleSpeed);
|
||||
|
||||
//Vector2 startPos = ConvertUnits.ToDisplayUnits(item.body.Position);
|
||||
//Vector2 endPos = ConvertUnits.ToDisplayUnits(pickedPosition);
|
||||
//endPos = new Vector2(endPos.X + Game1.localRandom.Next(-2, 2), endPos.Y + Game1.localRandom.Next(-2, 2));
|
||||
|
||||
//GUI.DrawLine(spriteBatch, startPos, endPos, Color.Orange, 0.0f);
|
||||
|
||||
isActive = false;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ namespace Subsurface.Items.Components
|
||||
{
|
||||
Vector2 barrelPos = Vector2.Zero;
|
||||
|
||||
RangedWeapon weapon = item.GetComponent<RangedWeapon>();
|
||||
if (weapon != null) barrelPos = weapon.BarrelPos;
|
||||
//RangedWeapon weapon = item.GetComponent<RangedWeapon>();
|
||||
//if (weapon != null) barrelPos = weapon.barrelPos;
|
||||
|
||||
return barrelPos;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ namespace Subsurface.Items.Components
|
||||
|
||||
}
|
||||
|
||||
public override void SecondaryUse(Character character = null)
|
||||
public override void SecondaryUse(float deltaTime, Character character = null)
|
||||
{
|
||||
if (reload > 0.0f) return;
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace Subsurface.Items.Components
|
||||
//}
|
||||
}
|
||||
|
||||
public override bool Use(Character character = null)
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (newNodePos!= Vector2.Zero && nodes.Count>0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
|
||||
{
|
||||
@@ -155,7 +155,7 @@ namespace Subsurface.Items.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void SecondaryUse(Character character = null)
|
||||
public override void SecondaryUse(float deltaTime, Character character = null)
|
||||
{
|
||||
if (nodes.Count > 1)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Subsurface.Items.Components
|
||||
//throwForce = ToolBox.GetAttributeFloat(element, "throwforce", 1.0f);
|
||||
}
|
||||
|
||||
public override bool Use(Character character = null)
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == null) return false;
|
||||
if (!character.SecondaryKeyDown.State || throwing) return false;
|
||||
@@ -36,7 +36,7 @@ namespace Subsurface.Items.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void SecondaryUse(Character character = null)
|
||||
public override void SecondaryUse(float deltaTime, Character character = null)
|
||||
{
|
||||
if (throwing) return;
|
||||
throwPos = 0.25f;
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Subsurface.Items.Components
|
||||
//cam.OffsetAmount = prefab.OffsetOnSelected;
|
||||
}
|
||||
|
||||
public override void SecondaryUse(Character character = null)
|
||||
public override void SecondaryUse(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == null) return;
|
||||
Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
|
||||
@@ -142,7 +142,7 @@ namespace Subsurface.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Use(Character character = null)
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (reload > 0.0f) return false;
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace Subsurface.Items.Components
|
||||
|
||||
//if (useSounds.Count() > 0) useSounds[Game1.localRandom.Next(useSounds.Count())].Play(1.0f, 800.0f, item.body.FarseerBody);
|
||||
|
||||
projectileComponent.Use();
|
||||
projectileComponent.Use(deltaTime);
|
||||
item.RemoveContained(projectile);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -119,13 +119,13 @@ namespace Subsurface.Items.Components
|
||||
for (int i = 0; i < limb.Length; i++)
|
||||
{
|
||||
if (limb[i] == null) continue;
|
||||
ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker, limb[i]);
|
||||
ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker);
|
||||
|
||||
if (containedItems == null) continue;
|
||||
for (int j = 0; j<containedItems.Length; j++)
|
||||
{
|
||||
if (containedItems[j] == null) continue;
|
||||
containedItems[j].ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker, limb[i]);
|
||||
containedItems[j].ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user