v0.1
This commit is contained in:
@@ -0,0 +1,234 @@
|
||||
using System.Xml.Linq;
|
||||
using FarseerPhysics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Subsurface.Items.Components
|
||||
{
|
||||
class Holdable : Pickable
|
||||
{
|
||||
//the position(s) in the item that the character grabs
|
||||
protected Vector2[] handlePos;
|
||||
|
||||
private List<RelatedItem> prevRequiredItems;
|
||||
|
||||
string prevMsg;
|
||||
|
||||
//protected Character picker;
|
||||
|
||||
//the distance from the holding characters elbow to center of the physics body of the item
|
||||
protected Vector2 holdPos;
|
||||
|
||||
protected Vector2 aimPos;
|
||||
|
||||
protected bool aimable;
|
||||
|
||||
private bool attachable;
|
||||
private bool attached;
|
||||
private PhysicsBody body;
|
||||
|
||||
//the angle in which the character holds the item
|
||||
protected float holdAngle;
|
||||
|
||||
[HasDefaultValue(false, true)]
|
||||
public bool Attached
|
||||
{
|
||||
get { return attached; }
|
||||
set { attached = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
public bool Aimable
|
||||
{
|
||||
get { return aimable; }
|
||||
set { aimable = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
public bool Attachable
|
||||
{
|
||||
get { return attachable; }
|
||||
set { attachable = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue("0.0,0.0", false)]
|
||||
public string HoldPos
|
||||
{
|
||||
get { return ToolBox.Vector2ToString(ConvertUnits.ToDisplayUnits(holdPos)); }
|
||||
set { holdPos = ConvertUnits.ToSimUnits(ToolBox.ParseToVector2(value)); }
|
||||
}
|
||||
|
||||
[HasDefaultValue("0.0,0.0", false)]
|
||||
public string AimPos
|
||||
{
|
||||
get { return ToolBox.Vector2ToString(ConvertUnits.ToDisplayUnits(aimPos)); }
|
||||
set { aimPos = ConvertUnits.ToSimUnits(ToolBox.ParseToVector2(value)); }
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
public float HoldAngle
|
||||
{
|
||||
get { return MathHelper.ToDegrees(holdAngle); }
|
||||
set { holdAngle = MathHelper.ToRadians(value); }
|
||||
}
|
||||
|
||||
public Holdable(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
body = item.body;
|
||||
|
||||
handlePos = new Vector2[2];
|
||||
|
||||
for (int i = 1; i < 3; i++)
|
||||
{
|
||||
handlePos[i - 1] = ToolBox.GetAttributeVector2(element, "handle" + i, Vector2.Zero);
|
||||
|
||||
handlePos[i - 1] = ConvertUnits.ToSimUnits(handlePos[i - 1]);
|
||||
}
|
||||
|
||||
canBePicked = true;
|
||||
|
||||
if (attachable)
|
||||
{
|
||||
prevRequiredItems = new List<RelatedItem>(requiredItems);
|
||||
prevMsg = Msg;
|
||||
|
||||
requiredItems.Clear();
|
||||
Msg = "";
|
||||
}
|
||||
|
||||
|
||||
//holdAngle = ToolBox.GetAttributeFloat(element, "holdangle", 0.0f);
|
||||
//holdAngle = MathHelper.ToRadians(holdAngle);
|
||||
}
|
||||
|
||||
public override void Drop(Character dropper)
|
||||
{
|
||||
if (picker == null)
|
||||
{
|
||||
if (dropper==null) return;
|
||||
picker = dropper;
|
||||
}
|
||||
if (picker.Inventory == null) return;
|
||||
|
||||
item.body.Enabled = true;
|
||||
isActive = false;
|
||||
|
||||
//item.Unequip();
|
||||
|
||||
picker.DeselectItem(item);
|
||||
picker.Inventory.RemoveItem(item);
|
||||
picker = null;
|
||||
}
|
||||
|
||||
public override void Equip(Character character)
|
||||
{
|
||||
picker = character;
|
||||
|
||||
if (!item.body.Enabled)
|
||||
{
|
||||
Limb rightHand = picker.AnimController.GetLimb(LimbType.RightHand);
|
||||
item.SetTransform(rightHand.SimPosition, 0.0f);
|
||||
}
|
||||
|
||||
if (picker.TrySelectItem(item))
|
||||
{
|
||||
item.body.Enabled = true;
|
||||
isActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Unequip(Character character)
|
||||
{
|
||||
if (picker == null) return;
|
||||
|
||||
picker.DeselectItem(item);
|
||||
|
||||
item.body.Enabled = false;
|
||||
isActive = false;
|
||||
}
|
||||
|
||||
public override bool Pick(Character picker)
|
||||
{
|
||||
if (!attachable)
|
||||
{
|
||||
return base.Pick(picker);
|
||||
}
|
||||
|
||||
if (!base.Pick(picker))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
requiredItems.Clear();
|
||||
Msg = "";
|
||||
}
|
||||
|
||||
attached = false;
|
||||
if (body!=null) item.body = body;
|
||||
//item.body.Enabled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (!attachable || item.body==null) return true;
|
||||
|
||||
item.Drop();
|
||||
item.body.Enabled = false;
|
||||
item.body = null;
|
||||
|
||||
requiredItems = new List<RelatedItem>(prevRequiredItems);
|
||||
Msg = prevMsg;
|
||||
|
||||
attached = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void UpdateBroken(float deltaTime, Camera cam)
|
||||
{
|
||||
Update(deltaTime, cam);
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
if (!item.body.Enabled) return;
|
||||
if (!picker.HasSelectedItem(item)) isActive = false;
|
||||
|
||||
ApplyStatusEffects(ActionType.OnActive, deltaTime, picker);
|
||||
|
||||
if (item.body.Dir != picker.AnimController.Dir) Flip(item);
|
||||
|
||||
AnimController ac = picker.AnimController;
|
||||
|
||||
//item.sprite.Depth = picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.01f;
|
||||
|
||||
ac.HoldItem(deltaTime, cam, item, handlePos, holdPos, aimPos, holdAngle);
|
||||
}
|
||||
|
||||
protected void Flip(Item item)
|
||||
{
|
||||
handlePos[0].X = -handlePos[0].X;
|
||||
handlePos[1].X = -handlePos[1].X;
|
||||
item.body.Dir = -item.body.Dir;
|
||||
}
|
||||
|
||||
public override void OnMapLoaded()
|
||||
{
|
||||
//prevRequiredItems = new List<RelatedItem>(requiredItems);
|
||||
|
||||
if (attached)
|
||||
{
|
||||
Use(1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
requiredItems.Clear();
|
||||
Msg = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface.Items.Components
|
||||
{
|
||||
class Pickable : ItemComponent
|
||||
{
|
||||
protected Character picker;
|
||||
|
||||
protected LimbSlot allowedSlots;
|
||||
|
||||
public LimbSlot AllowedSlots
|
||||
{
|
||||
get { return allowedSlots; }
|
||||
}
|
||||
|
||||
public Character Picker
|
||||
{
|
||||
get { return picker; }
|
||||
}
|
||||
|
||||
public Pickable(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
string slotString = ToolBox.GetAttributeString(element, "slots", "Any");
|
||||
string[] slots = slotString.Split(',');
|
||||
foreach (string slot in slots)
|
||||
{
|
||||
allowedSlots = allowedSlots | (LimbSlot)Enum.Parse(typeof(LimbSlot), slot.Trim());
|
||||
}
|
||||
|
||||
canBePicked = true;
|
||||
}
|
||||
|
||||
public override bool Pick(Character picker)
|
||||
{
|
||||
if (picker == null) return false;
|
||||
if (picker.Inventory == null) return false;
|
||||
|
||||
if (picker.Inventory.TryPutItem(item, allowedSlots))
|
||||
{
|
||||
if (!picker.HasSelectedItem(item) && item.body!=null) item.body.Enabled = false;
|
||||
this.picker = picker;
|
||||
|
||||
for (int i = item.linkedTo.Count - 1; i >= 0; i--)
|
||||
item.linkedTo[i].RemoveLinked(item);
|
||||
item.linkedTo.Clear();
|
||||
|
||||
ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker);
|
||||
|
||||
//foreach (StatusEffect effect in item.Prefab.statusEffects)
|
||||
//{
|
||||
// effect.OnPicked(picker, null);
|
||||
//}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Drop(Character dropper)
|
||||
{
|
||||
if (picker == null)
|
||||
{
|
||||
picker = dropper;
|
||||
|
||||
//foreach (Character c in Character.characterList)
|
||||
//{
|
||||
// if (c.Inventory == null) continue;
|
||||
// if (c.Inventory.FindIndex(item) == -1) continue;
|
||||
|
||||
// picker = c;
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
|
||||
if (picker==null || picker.Inventory == null) return;
|
||||
|
||||
if (item.body!= null && !item.body.Enabled)
|
||||
{
|
||||
Limb rightHand = picker.AnimController.GetLimb(LimbType.RightHand);
|
||||
item.SetTransform(rightHand.SimPosition, 0.0f);
|
||||
item.body.Enabled = true;
|
||||
}
|
||||
picker.Inventory.RemoveItem(item);
|
||||
picker = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using FarseerPhysics;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Subsurface.Items.Components
|
||||
{
|
||||
class RangedWeapon : ItemComponent
|
||||
{
|
||||
private float reload;
|
||||
|
||||
private Vector2 barrelPos;
|
||||
|
||||
[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 RangedWeapon(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
//barrelPos = ToolBox.GetAttributeVector2(element, "barrelpos", Vector2.Zero);
|
||||
//barrelPos = ConvertUnits.ToSimUnits(barrelPos);
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
reload -= deltaTime;
|
||||
|
||||
if (reload < 0.0f)
|
||||
{
|
||||
reload = 0.0f;
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == null) return false;
|
||||
if (!character.SecondaryKeyDown.State || 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)
|
||||
{
|
||||
limbBodies.Add(l.body.FarseerBody);
|
||||
}
|
||||
|
||||
Item[] containedItems = item.ContainedItems;
|
||||
if (containedItems == null || !containedItems.Any()) return false;
|
||||
|
||||
foreach (Item projectile in containedItems)
|
||||
{
|
||||
if (projectile == null) continue;
|
||||
//find the projectile-itemcomponent of the projectile,
|
||||
//and add the limbs of the shooter to the list of bodies to be ignored
|
||||
//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);
|
||||
|
||||
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));
|
||||
|
||||
//recoil
|
||||
//item.body.ApplyLinearImpulse(
|
||||
// new Vector2((float)Math.Cos(projectile.body.Rotation), (float)Math.Sin(projectile.body.Rotation)) * item.body.Mass * -10.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);
|
||||
|
||||
|
||||
|
||||
Rope rope = item.GetComponent<Rope>();
|
||||
if (rope != null) rope.Attach(projectile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using FarseerPhysics;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Subsurface.Particles;
|
||||
|
||||
namespace Subsurface.Items.Components
|
||||
{
|
||||
class RepairTool : ItemComponent
|
||||
{
|
||||
List<string> fixableEntities;
|
||||
|
||||
float range;
|
||||
|
||||
Vector2 pickedPosition;
|
||||
|
||||
Vector2 barrelPos;
|
||||
|
||||
float structureFixAmount, limbFixAmount;
|
||||
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
public float Range
|
||||
{
|
||||
get { return ConvertUnits.ToDisplayUnits(range); }
|
||||
set { range = ConvertUnits.ToSimUnits(value); }
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
public float StructureFixAmount
|
||||
{
|
||||
get { return structureFixAmount; }
|
||||
set { structureFixAmount = value; }
|
||||
}
|
||||
|
||||
[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)
|
||||
{
|
||||
this.item = item;
|
||||
|
||||
//range = ToolBox.GetAttributeFloat(element, "range", 100.0f);
|
||||
//range = ConvertUnits.ToSimUnits(range);
|
||||
|
||||
//structureFixAmount = ToolBox.GetAttributeFloat(element, "structurefixamount", 1.0f);
|
||||
//limbFixAmount = ToolBox.GetAttributeFloat(element, "limbfixamount", -0.5f);
|
||||
|
||||
|
||||
fixableEntities = new List<string>();
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLower())
|
||||
{
|
||||
case "fixable":
|
||||
fixableEntities.Add(subElement.Attribute("name").Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//public override void Update(float deltaTime, Camera cam)
|
||||
//{
|
||||
// base.Update(deltaTime, cam);
|
||||
|
||||
//}
|
||||
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == null) return false;
|
||||
if (!character.SecondaryKeyDown.State) return false;
|
||||
|
||||
if (DoesUseFail(character)) return false;
|
||||
|
||||
isActive = true;
|
||||
|
||||
Vector2 targetPosition = item.body.Position;
|
||||
//targetPosition = targetPosition.X, -targetPosition.Y);
|
||||
|
||||
targetPosition += new Vector2(
|
||||
(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)
|
||||
{
|
||||
ignoredBodies.Add(limb.body.FarseerBody);
|
||||
}
|
||||
|
||||
Body targetBody = Submarine.PickBody(TransformedBarrelPos, targetPosition, ignoredBodies);
|
||||
pickedPosition = Submarine.LastPickedPosition;
|
||||
|
||||
if (targetBody==null || targetBody.UserData==null) return true;
|
||||
|
||||
//ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
|
||||
|
||||
|
||||
Structure targetStructure;
|
||||
Limb targetLimb;
|
||||
Item targetItem;
|
||||
if ((targetStructure = (targetBody.UserData as Structure)) != null)
|
||||
{
|
||||
if (!fixableEntities.Contains(targetStructure.Name)) return true;
|
||||
|
||||
int sectionIndex = targetStructure.FindSectionIndex(ConvertUnits.ToDisplayUnits(pickedPosition));
|
||||
if (sectionIndex < 0) return true;
|
||||
|
||||
targetStructure.HighLightSection(sectionIndex);
|
||||
|
||||
targetStructure.AddDamage(sectionIndex, -structureFixAmount);
|
||||
|
||||
}
|
||||
else if ((targetLimb = (targetBody.UserData as Limb)) != null)
|
||||
{
|
||||
if (character.SecondaryKeyDown.State)
|
||||
{
|
||||
targetLimb.character.Health += limbFixAmount;
|
||||
//isActive = true;
|
||||
}
|
||||
}
|
||||
else if ((targetItem = (targetBody.UserData as Item)) != null)
|
||||
{
|
||||
//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, item, targetItem.AllPropertyObjects);
|
||||
//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, bool editing)
|
||||
{
|
||||
if (!isActive) return;
|
||||
|
||||
Vector2 particleSpeed = new Vector2(
|
||||
(float)Math.Cos(item.body.Rotation),
|
||||
(float)Math.Sin(item.body.Rotation)) *item.body.Dir * 5.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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using FarseerPhysics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface.Items.Components
|
||||
{
|
||||
class Throwable : Holdable
|
||||
{
|
||||
float throwForce;
|
||||
|
||||
float throwPos;
|
||||
|
||||
bool throwing;
|
||||
|
||||
[HasDefaultValue(1.0f, false)]
|
||||
public float ThrowForce
|
||||
{
|
||||
get { return throwForce; }
|
||||
set { throwForce = value; }
|
||||
}
|
||||
|
||||
public Throwable(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
//throwForce = ToolBox.GetAttributeFloat(element, "throwforce", 1.0f);
|
||||
}
|
||||
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == null) return false;
|
||||
if (!character.SecondaryKeyDown.State || throwing) return false;
|
||||
|
||||
throwing = true;
|
||||
|
||||
isActive = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void SecondaryUse(float deltaTime, Character character = null)
|
||||
{
|
||||
if (throwing) return;
|
||||
throwPos = 0.25f;
|
||||
}
|
||||
|
||||
public override void Drop(Character dropper)
|
||||
{
|
||||
base.Drop(dropper);
|
||||
|
||||
throwing = false;
|
||||
throwPos = 0.0f;
|
||||
}
|
||||
|
||||
public override void UpdateBroken(float deltaTime, Camera cam)
|
||||
{
|
||||
Update(deltaTime, cam);
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
if (!item.body.Enabled) return;
|
||||
if (!picker.HasSelectedItem(item)) isActive = false;
|
||||
|
||||
if (!picker.SecondaryKeyDown.State && !throwing) throwPos = 0.0f;
|
||||
|
||||
ApplyStatusEffects(ActionType.OnActive, deltaTime, picker);
|
||||
|
||||
if (item.body.Dir != picker.AnimController.Dir) Flip(item);
|
||||
|
||||
AnimController ac = picker.AnimController;
|
||||
|
||||
ac.HoldItem(deltaTime, cam, item, handlePos, new Vector2(throwPos, 0.0f), aimPos, holdAngle);
|
||||
|
||||
if (!throwing) return;
|
||||
|
||||
throwPos += deltaTime*5.0f;
|
||||
|
||||
Vector2 throwVector = ConvertUnits.ToSimUnits(picker.CursorPosition) - item.body.Position;
|
||||
throwVector = Vector2.Normalize(throwVector);
|
||||
|
||||
if (handlePos[0]!=Vector2.Zero)
|
||||
{
|
||||
Limb leftHand = ac.GetLimb(LimbType.LeftHand);
|
||||
leftHand.body.ApplyForce(throwVector*10.0f);
|
||||
}
|
||||
|
||||
if (handlePos[1] != Vector2.Zero)
|
||||
{
|
||||
Limb rightHand = ac.GetLimb(LimbType.RightHand);
|
||||
rightHand.body.ApplyForce(throwVector * 10.0f);
|
||||
}
|
||||
|
||||
if (throwPos>1.0f)
|
||||
{
|
||||
item.Drop();
|
||||
item.body.ApplyLinearImpulse(throwVector * throwForce * item.body.Mass * 3.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user