fixed railgun, fixed repairtools radar ping & improved rendering, waypoint bugfixes, inventory bugfixes, syncing wires between clients

This commit is contained in:
Regalis
2015-07-15 23:34:13 +03:00
parent 44b9a63c94
commit 237df18765
39 changed files with 461 additions and 405 deletions
@@ -129,7 +129,7 @@ namespace Subsurface.Items.Components
targetStructure.HighLightSection(sectionIndex);
targetStructure.AddDamage(sectionIndex, -structureFixAmount);
}
else if ((targetLimb = (targetBody.UserData as Limb)) != null)
+16 -20
View File
@@ -284,6 +284,11 @@ namespace Subsurface
{
return false;
}
public virtual bool Select(Character character)
{
return CanBeSelected;
}
/// <summary>a character has dropped the item</summary>
public virtual void Drop(Character dropper) { }
@@ -395,40 +400,31 @@ namespace Subsurface
return true;
}
public bool HasRequiredEquippedItems(Character character, bool addMessage)
public bool HasRequiredItems(Character character, bool addMessage)
{
if (!requiredItems.Any()) return true;
foreach (RelatedItem ri in requiredItems)
{
if (!ri.Type.HasFlag(RelatedItem.RelationType.Equipped) && !ri.Type.HasFlag(RelatedItem.RelationType.Picked)) continue;
bool hasItem = false;
if (ri.Type.HasFlag(RelatedItem.RelationType.Equipped))
{
for (int i = 0; i < character.SelectedItems.Length; i++ )
{
Item selectedItem = character.SelectedItems[i];
if (selectedItem !=null && selectedItem.Condition>0.0f && ri.MatchesItem(selectedItem ))
{
return true;
}
}
//if (addMessage && !String.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
return false;
if (character.SelectedItems.FirstOrDefault(it => it != null && it.Condition > 0.0f && ri.MatchesItem(it)) != null) hasItem = true;
}
else if (ri.Type.HasFlag(RelatedItem.RelationType.Picked))
if (!hasItem && ri.Type.HasFlag(RelatedItem.RelationType.Picked))
{
Item pickedItem = character.Inventory.items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x));
if (pickedItem == null)
{
//if (addMessage && !String.IsNullOrEmpty(ri.Msg)) GUI.AddMessage(ri.Msg, Color.Red);
return false;
}
if (character.Inventory.items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x))!=null) hasItem = true;
}
if (!hasItem) return false;
}
return true;
}
public void ApplyStatusEffects(ActionType type, float deltaTime, Character character = null)
{
foreach (StatusEffect effect in statusEffects)
+3 -3
View File
@@ -10,11 +10,11 @@ namespace Subsurface.Items.Components
{
}
public override bool Pick(Character picker = null)
public override bool Select(Character character = null)
{
if (picker == null) return false;
if (character == null) return false;
picker.AnimController.Anim = AnimController.Animation.Climbing;
character.AnimController.Anim = AnimController.Animation.Climbing;
//picker.SelectedConstruction = item;
return true;
@@ -23,6 +23,8 @@ namespace Subsurface.Items.Components
//the x-position where the user walks to when using the controller
float userPos;
Camera cam;
Character character;
[HasDefaultValue(1.0f,false)]
@@ -38,19 +40,6 @@ namespace Subsurface.Items.Components
dir = (Direction)Enum.Parse(typeof(Direction), ToolBox.GetAttributeString(element, "direction", "None"), true);
//userPos = ToolBox.GetAttributeInt(element, "userpos", 1);
//string allowedIdString = ToolBox.GetAttributeString(element, "allowedids", "");
//if (allowedIdString!="")
//{
// string[] splitIds = allowedIdString.Split(',');
// allowedIDs = new string[splitIds.Length];
// for (int i = 0; i<splitIds.Length; i++)
// {
// allowedIDs[i] = allowedIDs[i].Trim();
// }
//}
foreach (XElement el in element.Elements())
{
if (el.Name != "limbposition") continue;
@@ -75,6 +64,8 @@ namespace Subsurface.Items.Components
public override void Update(float deltaTime, Camera cam)
{
this.cam = cam;
if (character == null || character.SelectedConstruction != item)
{
if (character != null)
@@ -126,25 +117,29 @@ namespace Subsurface.Items.Components
fmj.WorldAnchorB = position;
}
foreach (MapEntity e in item.linkedTo)
{
Item linkedItem = e as Item;
if (linkedItem == null) continue;
linkedItem.Update(cam, deltaTime);
}
//foreach (MapEntity e in item.linkedTo)
//{
// Item linkedItem = e as Item;
// if (linkedItem == null) continue;
// linkedItem.Update(cam, deltaTime);
//}
item.SendSignal(ToolBox.Vector2ToString(character.CursorPosition), "position_out");
}
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(deltaTime, activator);
}
//character = activator;
//foreach (MapEntity e in item.linkedTo)
//{
// Item linkedItem = e as Item;
// if (linkedItem == null) continue;
// linkedItem.Use(deltaTime, activator);
//}
ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
item.SendSignal("1", "trigger_out");
ApplyStatusEffects(ActionType.OnUse, 1.0f, activator);
return true;
}
@@ -153,15 +148,43 @@ namespace Subsurface.Items.Components
{
if (character == null) return;
foreach (MapEntity e in item.linkedTo)
foreach (Connection c in item.Connections)
{
Item linkedItem = e as Item;
if (linkedItem == null) continue;
linkedItem.SecondaryUse(deltaTime, character);
if (c.Name != "position_out") continue;
foreach (Connection c2 in c.Recipients)
{
if (c2 == null || c2.Item==null || !c2.Item.Prefab.FocusOnSelected) continue;
Vector2 centerPos = c2.Item.Position;
if (character == Character.Controlled && cam != null)
{
Lights.LightManager.ViewPos = centerPos;
cam.TargetPos = c2.Item.Position;
}
break;
}
}
//foreach (MapEntity e in item.linkedTo)
//{
// Item linkedItem = e as Item;
// if (linkedItem == null) continue;
// linkedItem.SecondaryUse(deltaTime, character);
//}
}
public override bool Pick(Character activator = null)
public override bool Pick(Character picker)
{
item.SendSignal("1", "signal_out");
return true;
}
public override bool Select(Character activator = null)
{
if (character!=null && character.SelectedConstruction == item)
{
+12 -3
View File
@@ -51,10 +51,19 @@ namespace Subsurface.Items.Components
{
base.Update(deltaTime, cam);
pingState = (pingState + deltaTime * 0.5f) % 1.0f;
pingState = (pingState + deltaTime * 0.5f);
if (pingState>1.0f)
{
item.Use(deltaTime,null);
pingState = 0.0f;
}
angle = (angle + deltaTime) % MathHelper.TwoPi;
//angle = (angle + deltaTime) % MathHelper.TwoPi;
}
public override bool Use(float deltaTime, Character character = null)
{
return true;
}
public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Character character)
@@ -34,45 +34,37 @@ namespace Subsurface.Items.Components
{
isActive = true;
}
public override void OnMapLoaded()
{
PathFinder pathFinder = new PathFinder(WayPoint.WayPointList, false);
steeringPath = pathFinder.FindPath(
ConvertUnits.ToSimUnits(Level.Loaded.StartPosition),
ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
}
public override void Update(float deltaTime, Camera cam)
{
base.Update(deltaTime, cam);
if (autoPilot || true)
if (autoPilot)
{
steeringPath.GetNode(Vector2.Zero, 5.0f);
if (steeringPath==null)
{
PathFinder pathFinder = new PathFinder(WayPoint.WayPointList, false);
steeringPath = pathFinder.FindPath(
ConvertUnits.ToSimUnits(Level.Loaded.StartPosition),
ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
}
steeringPath.GetNode(Vector2.Zero, 20.0f);
if (steeringPath.CurrentNode!=null)
{
Vector2 targetSpeed = steeringPath.CurrentNode.Position;
float prediction = 10.0f;
float dist = targetSpeed.Length();
Vector2 futurePosition = Submarine.Loaded.Speed * prediction;
Vector2 targetSpeed = (steeringPath.CurrentNode.Position - futurePosition);
//float dist = targetSpeed.Length();
targetSpeed = Vector2.Normalize(targetSpeed);
if (dist<2000.0f)
{
targetSpeed = targetSpeed * Math.Max(dist / 2000.0f, 0.5f);
}
Vector2 currSpeed = (Submarine.Loaded.Speed == Vector2.Zero) ? Vector2.Zero : Vector2.Normalize(Submarine.Loaded.Speed);
//targetSpeed.X = (targetSpeed.X - currSpeed.X);
//targetSpeed.Y = (targetSpeed.Y - currSpeed.Y);
//TargetVelocity += targetSpeed;
TargetVelocity += (targetSpeed-currSpeed);
TargetVelocity = targetSpeed*100.0f;
}
}
@@ -91,6 +83,13 @@ namespace Subsurface.Items.Components
Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40);
GUI.DrawRectangle(spriteBatch, velRect, Color.White, false);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + width - 150, y + height - 30, 150, 30), "Autopilot"))
{
autoPilot = !autoPilot;
item.NewComponentEvent(this, true);
}
GUI.DrawLine(spriteBatch,
new Vector2(velRect.Center.X,velRect.Center.Y),
new Vector2(velRect.Center.X + currVelocity.X, velRect.Center.Y - currVelocity.Y),
@@ -113,10 +112,10 @@ namespace Subsurface.Items.Components
{
targetVelocity = PlayerInput.MousePosition - new Vector2(velRect.Center.X, velRect.Center.Y);
targetVelocity.Y = -targetVelocity.Y;
item.NewComponentEvent(this, true);
}
}
item.NewComponentEvent(this, true);
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
@@ -131,14 +130,19 @@ namespace Subsurface.Items.Components
{
message.Write(targetVelocity.X);
message.Write(targetVelocity.Y);
message.Write(autoPilot);
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
{
Vector2 newTargetVelocity = Vector2.Zero;
Vector2 newTargetVelocity = Vector2.Zero;
bool newAutoPilot = false;
try
{
newTargetVelocity = new Vector2(message.ReadFloat(), message.ReadFloat());
newAutoPilot = message.ReadBoolean();
}
catch
@@ -147,6 +151,7 @@ namespace Subsurface.Items.Components
}
TargetVelocity = newTargetVelocity;
autoPilot = newAutoPilot;
}
}
}
@@ -1,5 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
@@ -28,26 +29,13 @@ namespace Subsurface.Items.Components
break;
}
}
isActive = true;
}
//public override void Move(Vector2 amount)
//{
// base.Move(amount);
// foreach (Connection c in connections)
// {
// foreach (Wire w in c.wires)
// {
// if (w == null) continue;
// w.Move
// }
// }
//}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
if (user!=character) return;
if (character != Character.Controlled || character != user) return;
Connection.DrawConnections(spriteBatch, this, character);
}
@@ -76,7 +64,7 @@ namespace Subsurface.Items.Components
if (user != null && user.SelectedConstruction != item) user = null;
}
public override bool Pick(Character picker)
public override bool Select(Character picker)
{
user = picker;
isActive = true;
@@ -107,10 +95,12 @@ namespace Subsurface.Items.Components
{
foreach (Connection c in connections)
{
int wireCount = c.Wires.Length;
for (int i = 0 ; i < wireCount; i++)
Wire[] wires = Array.FindAll(c.Wires, w => w != null);
message.Write((byte)wires.Length);
for (int i = 0 ; i < c.Wires.Length; i++)
{
message.Write(c.Wires[i]==null ? -1 : c.Wires[i].Item.ID);
if (c.Wires[i] == null) continue;
message.Write(c.Wires[i].Item.ID);
}
}
}
@@ -120,23 +110,28 @@ namespace Subsurface.Items.Components
System.Diagnostics.Debug.WriteLine("connectionpanel update");
foreach (Connection c in connections)
{
int wireCount = c.Wires.Length;
//int wireCount = c.Wires.Length;
c.ClearConnections();
for (int i = 0; i < wireCount; i++)
try
{
int wireId = message.ReadInt32();
if (wireId == -1) continue;
byte wireCount = message.ReadByte();
Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
if (wireItem == null) continue;
for (int i = 0; i < wireCount; i++)
{
int wireId = message.ReadInt32();
Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
if (wireItem == null) continue;
Wire wireComponent = wireItem.GetComponent<Wire>();
if (wireComponent == null) continue;
Wire wireComponent = wireItem.GetComponent<Wire>();
if (wireComponent == null) continue;
c.Wires[i] = wireComponent;
wireComponent.Connect(c, false);
c.Wires[i] = wireComponent;
wireComponent.Connect(c, false);
}
}
catch { }
}
}
}
+40 -41
View File
@@ -15,12 +15,12 @@ namespace Subsurface.Items.Components
static Sprite wireSprite;
List<Vector2> nodes;
public List<Vector2> Nodes;
Connection[] connections;
private Vector2 newNodePos;
public Wire(Item item, XElement element)
: base(item, element)
{
@@ -30,7 +30,7 @@ namespace Subsurface.Items.Components
wireSprite.Depth = 0.85f;
}
nodes = new List<Vector2>();
Nodes = new List<Vector2>();
connections = new Connection[2];
}
@@ -38,9 +38,9 @@ namespace Subsurface.Items.Components
public override void Move(Vector2 amount)
{
amount = FarseerPhysics.ConvertUnits.ToDisplayUnits(amount);
for (int i = 0; i<nodes.Count; i++)
for (int i = 0; i<Nodes.Count; i++)
{
nodes[i] += amount;
Nodes[i] += amount;
}
}
@@ -76,11 +76,11 @@ namespace Subsurface.Items.Components
if (i == 0)
{
nodes.Insert(0, newConnection.Item.Position);
Nodes.Insert(0, newConnection.Item.Position);
}
else
{
nodes.Add(newConnection.Item.Position);
Nodes.Add(newConnection.Item.Position);
}
@@ -97,8 +97,7 @@ namespace Subsurface.Items.Components
CleanNodes();
}
//new Networking.NetworkEvent(item.ID, true);
Item.NewComponentEvent(this, true);
}
public override void Equip(Character character)
@@ -117,7 +116,7 @@ namespace Subsurface.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (nodes.Count == 0) return;
if (Nodes.Count == 0) return;
item.FindHull();
@@ -153,9 +152,9 @@ namespace Subsurface.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
if (newNodePos!= Vector2.Zero && nodes.Count>0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
if (newNodePos!= Vector2.Zero && Nodes.Count>0 && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
{
nodes.Add(newNodePos);
Nodes.Add(newNodePos);
newNodePos = Vector2.Zero;
}
@@ -166,9 +165,9 @@ namespace Subsurface.Items.Components
public override void SecondaryUse(float deltaTime, Character character = null)
{
if (nodes.Count > 1)
if (Nodes.Count > 1)
{
nodes.RemoveAt(nodes.Count - 1);
Nodes.RemoveAt(Nodes.Count - 1);
item.NewComponentEvent(this, true);
}
}
@@ -182,7 +181,7 @@ namespace Subsurface.Items.Components
private void ClearConnections()
{
nodes.Clear();
Nodes.Clear();
for (int i = 0; i < 2; i++)
{
@@ -198,14 +197,14 @@ namespace Subsurface.Items.Components
private void CleanNodes()
{
for (int i = nodes.Count - 2; i > 0; i--)
for (int i = Nodes.Count - 2; i > 0; i--)
{
if ((nodes[i - 1].X == nodes[i].X || nodes[i - 1].Y == nodes[i].Y) &&
(nodes[i + 1].X == nodes[i].X || nodes[i + 1].Y == nodes[i].Y))
if ((Nodes[i - 1].X == Nodes[i].X || Nodes[i - 1].Y == Nodes[i].Y) &&
(Nodes[i + 1].X == Nodes[i].X || Nodes[i + 1].Y == Nodes[i].Y))
{
if (Vector2.Distance(nodes[i - 1], nodes[i]) == Vector2.Distance(nodes[i + 1], nodes[i]))
if (Vector2.Distance(Nodes[i - 1], Nodes[i]) == Vector2.Distance(Nodes[i + 1], Nodes[i]))
{
nodes.RemoveAt(i);
Nodes.RemoveAt(i);
}
}
}
@@ -214,12 +213,12 @@ namespace Subsurface.Items.Components
do
{
removed = false;
for (int i = nodes.Count - 2; i > 0; i--)
for (int i = Nodes.Count - 2; i > 0; i--)
{
if ((nodes[i - 1].X == nodes[i].X && nodes[i + 1].X == nodes[i].X)
|| (nodes[i - 1].Y == nodes[i].Y && nodes[i + 1].Y == nodes[i].Y))
if ((Nodes[i - 1].X == Nodes[i].X && Nodes[i + 1].X == Nodes[i].X)
|| (Nodes[i - 1].Y == Nodes[i].Y && Nodes[i + 1].Y == Nodes[i].Y))
{
nodes.RemoveAt(i);
Nodes.RemoveAt(i);
removed = true;
}
}
@@ -231,21 +230,21 @@ namespace Subsurface.Items.Components
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
{
if (nodes.Count == 0) return;
if (Nodes.Count == 0) return;
//for (int i = 0; i < nodes.Count; i++)
//{
// GUI.DrawRectangle(spriteBatch, new Rectangle((int)nodes[i].X, (int)-nodes[i].Y, 5, 5), Color.DarkGray, true, wireSprite.Depth - 0.01f);
//}
for (int i = 1; i < nodes.Count; i++)
for (int i = 1; i < Nodes.Count; i++)
{
DrawSection(spriteBatch, nodes[i], nodes[i - 1], i, Color.White);
DrawSection(spriteBatch, Nodes[i], Nodes[i - 1], i, Color.White);
}
if (isActive && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
if (isActive && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
{
DrawSection(spriteBatch, nodes[nodes.Count - 1], newNodePos, nodes.Count, Color.White * 0.5f);
DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, Nodes.Count, Color.White * 0.5f);
//nodes.Add(newNodePos);
}
@@ -269,13 +268,13 @@ namespace Subsurface.Items.Components
{
XElement componentElement = base.Save(parentElement);
if (nodes == null || nodes.Count == 0) return componentElement;
if (Nodes == null || Nodes.Count == 0) return componentElement;
string[] nodeCoords = new string[nodes.Count() * 2];
for (int i = 0; i < nodes.Count(); i++)
string[] nodeCoords = new string[Nodes.Count() * 2];
for (int i = 0; i < Nodes.Count(); i++)
{
nodeCoords[i * 2] = nodes[i].X.ToString(CultureInfo.InvariantCulture);
nodeCoords[i * 2 + 1] = nodes[i].Y.ToString(CultureInfo.InvariantCulture);
nodeCoords[i * 2] = Nodes[i].X.ToString(CultureInfo.InvariantCulture);
nodeCoords[i * 2 + 1] = Nodes[i].Y.ToString(CultureInfo.InvariantCulture);
}
componentElement.Add(new XAttribute("nodes", string.Join(";", nodeCoords)));
@@ -307,28 +306,28 @@ namespace Subsurface.Items.Components
}
catch { y = 0.0f; }
nodes.Add(new Vector2(x, y));
Nodes.Add(new Vector2(x, y));
}
}
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message)
{
message.Write(nodes.Count);
for (int i = 0; i < nodes.Count; i++)
message.Write(Nodes.Count);
for (int i = 0; i < Nodes.Count; i++)
{
message.Write(nodes[i].X);
message.Write(nodes[i].Y);
message.Write(Nodes[i].X);
message.Write(Nodes[i].Y);
}
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
{
nodes.Clear();
Nodes.Clear();
int nodeCount = message.ReadInt32();
for (int i = 0; i < nodeCount; i++)
{
nodes.Add(new Vector2(message.ReadFloat(), message.ReadFloat()));
Nodes.Add(new Vector2(message.ReadFloat(), message.ReadFloat()));
}
}
}
+58 -59
View File
@@ -4,6 +4,7 @@ using System.IO;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using FarseerPhysics;
namespace Subsurface.Items.Components
{
@@ -13,14 +14,11 @@ namespace Subsurface.Items.Components
Vector2 barrelPos;
float targetRotation;
float rotation;
float rotation, targetRotation;
float reload;
float reloadTime;
float reload, reloadTime;
float minRotation;
float maxRotation;
float minRotation, maxRotation;
float launchImpulse;
@@ -53,12 +51,16 @@ namespace Subsurface.Items.Components
set { reloadTime = value; }
}
[HasDefaultValue("0.0,0.0", false)]
[HasDefaultValue("0.0,0.0", true)]
public string RotationLimits
{
get
{
return ToolBox.Vector2ToString(barrelPos);
Vector2 limits = new Vector2(minRotation, maxRotation);
limits.X = MathHelper.ToDegrees(limits.X);
limits.Y = MathHelper.ToDegrees(limits.Y);
return ToolBox.Vector2ToString(limits);
}
set
{
@@ -75,35 +77,15 @@ namespace Subsurface.Items.Components
barrelSprite = new Sprite(Path.GetDirectoryName(item.Prefab.ConfigFile) + "\\" +element.Attribute("barrelsprite").Value,
ToolBox.GetAttributeVector2(element, "origin", Vector2.Zero));
//barrelPos = ToolBox.GetAttributeVector2(element, "BarrelPos", Vector2.Zero);
//launchImpulse = ToolBox.GetAttributeFloat(element, "launchimpulse", 0.0f);
//minRotation = ToolBox.GetAttributeFloat(element, "MinimumRotation", 0.0f);
//maxRotation = ToolBox.GetAttributeFloat(element, "MaximumRotation", MathHelper.TwoPi);
//reloadTime = ToolBox.GetAttributeFloat(element, "reload", 5.0f);
}
public override void Draw(SpriteBatch spriteBatch)
{
barrelSprite.Draw(spriteBatch, new Vector2(item.Rect.X, -item.Rect.Y) + barrelPos, rotation + MathHelper.PiOver2, 1.0f);
//GUI.DrawRectangle(spriteBatch,
// new Rectangle((int)(rect.X + barrelPos.X), (int)(-rect.Y + barrelPos.Y), 10, 10),
// Color.White, true);
}
public override void Update(float deltaTime, Camera cam)
{
//if (character == null || character.SelectedConstruction != item)
//{
// character = null;
// isActive = false;
// return;
//}
this.cam = cam;
if (reload>0.0f) reload -= deltaTime;
@@ -117,30 +99,22 @@ namespace Subsurface.Items.Components
}
rotation = MathUtils.CurveAngle(rotation, targetRotation, 0.05f);
//if (!prefab.FocusOnSelected) return;
//cam.OffsetAmount = prefab.OffsetOnSelected;
}
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);
//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);
Vector2 offset = character.CursorPosition - centerPos;
offset.Y = -offset.Y;
targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
isActive = true;
if (character == Character.Controlled && cam!=null)
{
Lights.LightManager.ViewPos = centerPos;
cam.TargetPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
}
}
// if (character == Character.Controlled && cam!=null)
// {
// Lights.LightManager.ViewPos = centerPos;
// cam.TargetPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
// }
//}
public override bool Use(float deltaTime, Character character = null)
{
@@ -148,23 +122,25 @@ namespace Subsurface.Items.Components
Projectile projectileComponent = null;
currPowerConsumption = powerConsumption;
//currPowerConsumption = powerConsumption;
float availablePower = 0.0f;
//List<PowerContainer> batteries = new List<PowerContainer>();
foreach (MapEntity e in item.linkedTo)
foreach (Connection c in item.Connections)
{
Item battery = e as Item;
if (battery == null) continue;
foreach (Connection c2 in c.Recipients)
{
if (c2 == null || c2.Item == null) continue;
PowerContainer batteryComponent = battery.GetComponent<PowerContainer>();
if (batteryComponent == null) continue;
PowerContainer batteryComponent = c2.Item.GetComponent<PowerContainer>();
if (batteryComponent == null) continue;
float batteryPower = Math.Min(batteryComponent.Charge, batteryComponent.MaxOutPut);
float takePower = Math.Min(currPowerConsumption - availablePower, batteryPower);
float batteryPower = Math.Min(batteryComponent.Charge, batteryComponent.MaxOutPut);
float takePower = Math.Min(currPowerConsumption - availablePower, batteryPower);
batteryComponent.Charge -= takePower;
availablePower += takePower;
batteryComponent.Charge -= takePower;
availablePower += takePower;
}
}
reload = reloadTime;
@@ -198,7 +174,7 @@ namespace Subsurface.Items.Components
projectile.body.ResetDynamics();
projectile.body.Enabled = true;
projectile.SetTransform(item.SimPosition, rotation);
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation);
//if (useSounds.Count() > 0) useSounds[Game1.localRandom.Next(useSounds.Count())].Play(1.0f, 800.0f, item.body.FarseerBody);
@@ -207,6 +183,29 @@ namespace Subsurface.Items.Components
return true;
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power)
{
switch (connection.Name)
{
case "position_in":
Vector2 receivedPos = ToolBox.ParseToVector2(signal, false);
Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
Vector2 offset = receivedPos - centerPos;
offset.Y = -offset.Y;
targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
isActive = true;
break;
case "trigger_in":
item.Use((float)Physics.step, null);
break;
}
}
}
}