Disable aiming with holdable items when using a (railgun) controller, syncing ViewTargetID properly between clients, dropping connected wires when a button is picked up, placing large InterestingPositions on the main path through the level

This commit is contained in:
Regalis
2016-02-13 23:26:50 +02:00
parent 9b6dd5da00
commit ea6824a60d
7 changed files with 88 additions and 43 deletions
@@ -301,7 +301,7 @@ namespace Barotrauma
{ {
Structure structure = f2.Body.UserData as Structure; Structure structure = f2.Body.UserData as Structure;
if (f2.Body.UserData as SubmarineBody != null) return true; if (f2.Body.UserData as Submarine != null && character.Submarine == f2.Body.UserData as Submarine) return false;
//always collides with bodies other than structures //always collides with bodies other than structures
if (structure == null) if (structure == null)
+14 -5
View File
@@ -107,6 +107,8 @@ namespace Barotrauma
//which AIstate each sound is for //which AIstate each sound is for
private AIController.AiState[] soundStates; private AIController.AiState[] soundStates;
private Entity viewTarget;
private CharacterInfo info; private CharacterInfo info;
@@ -1380,15 +1382,21 @@ namespace Barotrauma
if (secondaryHeld) if (secondaryHeld)
{ {
if (Character.controlled==this)
{
viewTarget = Lights.LightManager.ViewTarget == null ? this : Lights.LightManager.ViewTarget;
}
if (viewTarget == null) viewTarget = this;
Vector2 relativeCursorPosition = cursorPosition; Vector2 relativeCursorPosition = cursorPosition;
relativeCursorPosition -= Lights.LightManager.ViewTarget == null ? Position : Lights.LightManager.ViewTarget.Position; relativeCursorPosition -= viewTarget.Position;
if (relativeCursorPosition.Length()>500.0f) if (relativeCursorPosition.Length()>500.0f)
{ {
relativeCursorPosition = Vector2.Normalize(relativeCursorPosition) * 495.0f; relativeCursorPosition = Vector2.Normalize(relativeCursorPosition) * 495.0f;
} }
message.Write(Lights.LightManager.ViewTarget == null ? (ushort)0 : Lights.LightManager.ViewTarget.ID); message.Write(viewTarget.ID);
message.WriteRangedSingle(relativeCursorPosition.X, -500.0f, 500.0f, 8); message.WriteRangedSingle(relativeCursorPosition.X, -500.0f, 500.0f, 8);
message.WriteRangedSingle(relativeCursorPosition.Y, -500.0f, 500.0f, 8); message.WriteRangedSingle(relativeCursorPosition.Y, -500.0f, 500.0f, 8);
@@ -1556,13 +1564,14 @@ namespace Barotrauma
float dir = 1.0f; float dir = 1.0f;
Vector2 pos = Vector2.Zero; Vector2 pos = Vector2.Zero;
ushort viewTargetId = 0; ushort viewTargetID = 0;
viewTarget = null;
try try
{ {
if (secondaryKeyState) if (secondaryKeyState)
{ {
viewTargetId = message.ReadUInt16(); viewTargetID = message.ReadUInt16();
relativeCursorPos = new Vector2( relativeCursorPos = new Vector2(
message.ReadRangedSingle(-500.0f, 500.0f, 8), message.ReadRangedSingle(-500.0f, 500.0f, 8),
@@ -1600,7 +1609,7 @@ namespace Barotrauma
{ {
cursorPosition = MathUtils.IsValid(relativeCursorPos) ? relativeCursorPos : Vector2.Zero; cursorPosition = MathUtils.IsValid(relativeCursorPos) ? relativeCursorPos : Vector2.Zero;
Entity viewTarget = viewTargetId == 0 ? this : Entity.FindEntityByID(viewTargetId); viewTarget = viewTargetID == 0 ? this : Entity.FindEntityByID(viewTargetID);
if (viewTarget == null) viewTarget = this; if (viewTarget == null) viewTarget = this;
cursorPosition += viewTarget.Position; cursorPosition += viewTarget.Position;
@@ -110,6 +110,7 @@ namespace Barotrauma.Items.Components
public override void Drop(Character dropper) public override void Drop(Character dropper)
{ {
DropConnectedWires(dropper);
if (body != null) item.body = body; if (body != null) item.body = body;
@@ -246,6 +247,8 @@ namespace Barotrauma.Items.Components
item.Submarine = picker.Submarine; item.Submarine = picker.Submarine;
if (picker.SelectedConstruction != null && picker.SelectedConstruction.GetComponent<Controller>() != null) return;
//item.sprite.Depth = picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.01f; //item.sprite.Depth = picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.01f;
ac.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle); ac.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle);
@@ -97,20 +97,7 @@ namespace Barotrauma.Items.Components
} }
item.linkedTo.Clear(); item.linkedTo.Clear();
var connectionPanel = item.GetComponent<ConnectionPanel>(); DropConnectedWires(picker);
if (connectionPanel != null)
{
foreach (Connection c in connectionPanel.Connections)
{
foreach (Wire w in c.Wires)
{
if (w == null) continue;
w.Item.Drop(picker);
w.Item.SetTransform(picker.SimPosition, 0.0f);
}
}
}
ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker); ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker);
@@ -134,7 +121,9 @@ namespace Barotrauma.Items.Components
pickTimer = 0.0f; pickTimer = 0.0f;
while (pickTimer < requiredTime) while (pickTimer < requiredTime)
{ {
if (picker.IsKeyHit(InputType.Aim) || !item.IsInPickRange(picker.WorldPosition)) if (picker.IsKeyDown(InputType.Aim) ||
!item.IsInPickRange(picker.WorldPosition) ||
picker.Stun > 0.0f || picker.IsDead)
{ {
StopPicking(picker); StopPicking(picker);
yield return CoroutineStatus.Success; yield return CoroutineStatus.Success;
@@ -159,7 +148,7 @@ namespace Barotrauma.Items.Components
StopPicking(picker); StopPicking(picker);
OnPicked(picker); if (!picker.IsNetworkPlayer) OnPicked(picker);
yield return CoroutineStatus.Success; yield return CoroutineStatus.Success;
} }
@@ -170,6 +159,25 @@ namespace Barotrauma.Items.Components
pickTimer = 0.0f; pickTimer = 0.0f;
} }
protected void DropConnectedWires(Character character)
{
if (character == null) return;
var connectionPanel = item.GetComponent<ConnectionPanel>();
if (connectionPanel == null) return;
foreach (Connection c in connectionPanel.Connections)
{
foreach (Wire w in c.Wires)
{
if (w == null) continue;
w.Item.Drop(character);
w.Item.SetTransform(character.SimPosition, 0.0f);
}
}
}
public override void Draw(SpriteBatch spriteBatch, bool editing = false) public override void Draw(SpriteBatch spriteBatch, bool editing = false)
{ {
@@ -198,7 +206,9 @@ namespace Barotrauma.Items.Components
//} //}
} }
if (picker==null || picker.Inventory == null) return; if (picker == null || picker.Inventory == null) return;
DropConnectedWires(picker);
item.Submarine = picker.Submarine; item.Submarine = picker.Submarine;
@@ -68,13 +68,14 @@ namespace Barotrauma.Items.Components
this.cam = cam; this.cam = cam;
if (character == null if (character == null
|| character.IsDead
|| character.Stun > 0.0f
|| character.SelectedConstruction != item || character.SelectedConstruction != item
|| Vector2.Distance(character.Position, item.Position) > item.PickDistance * 1.5f) || Vector2.Distance(character.Position, item.Position) > item.PickDistance * 2.0f)
{ {
if (character != null) if (character != null)
{ {
character.SelectedConstruction = null; CancelUsing(character);
character.AnimController.Anim = AnimController.Animation.None;
character = null; character = null;
} }
IsActive = false; IsActive = false;
@@ -119,15 +120,13 @@ namespace Barotrauma.Items.Components
limb.Disabled = true; limb.Disabled = true;
FixedMouseJoint fmj = limb.pullJoint; if (limb.pullJoint == null) continue;
if (fmj == null) continue;
Vector2 position = ConvertUnits.ToSimUnits(lb.position + new Vector2(item.Rect.X, item.Rect.Y)); Vector2 position = ConvertUnits.ToSimUnits(lb.position + new Vector2(item.Rect.X, item.Rect.Y));
fmj.Enabled = true; limb.pullJoint.Enabled = true;
fmj.WorldAnchorB = position; limb.pullJoint.WorldAnchorB = position;
} }
item.SendSignal(ToolBox.Vector2ToString(character.CursorWorldPosition), "position_out");
} }
public override bool Use(float deltaTime, Character activator = null) public override bool Use(float deltaTime, Character activator = null)
@@ -153,6 +152,8 @@ namespace Barotrauma.Items.Components
return; return;
} }
if (character!=null) item.SendSignal(ToolBox.Vector2ToString(character.CursorWorldPosition), "position_out");
foreach (Connection c in item.Connections) foreach (Connection c in item.Connections)
{ {
if (c.Name != "position_out") continue; if (c.Name != "position_out") continue;
@@ -183,20 +184,42 @@ namespace Barotrauma.Items.Components
return true; return true;
} }
private void CancelUsing(Character character)
{
foreach (LimbPos lb in limbPositions)
{
Limb limb = character.AnimController.GetLimb(lb.limbType);
if (limb == null) continue;
limb.Disabled = false;
limb.pullJoint.Enabled = false;
}
character.AnimController.Anim = AnimController.Animation.None;
}
public override bool Select(Character activator = null) public override bool Select(Character activator = null)
{ {
if (character!=null && character.SelectedConstruction == item) if (activator == null) return false;
{
character = null;
IsActive = false;
if (activator != null) activator.AnimController.Anim = AnimController.Animation.None;
return true; //someone already using the item
if (character != null)
{
if (character == activator)
{
IsActive = false;
CancelUsing(character);
character = null;
}
else
{
return false;
}
} }
else else
{ {
character = activator; character = activator;
if (activator == null) return false;
IsActive = true; IsActive = true;
} }
+5 -5
View File
@@ -166,11 +166,11 @@ namespace Barotrauma
for (float x = startPosition.X; x < endPosition.X; x += Rand.Range(5000.0f, 10000.0f, false)) for (float x = startPosition.X; x < endPosition.X; x += Rand.Range(5000.0f, 10000.0f, false))
{ {
pathNodes.Add(new Vector2(x, Rand.Range(pathBorders.Y, pathBorders.Bottom, false))); pathNodes.Add(new Vector2(x, Rand.Range(pathBorders.Y, pathBorders.Bottom, false)));
}
//if (x > borders.Center.X) for (int i = 2; i < pathNodes.Count; i+=3 )
//{ {
// positionsOfInterest.Add(pathNodes.Last()); positionsOfInterest.Add(new InterestingPosition(pathNodes[i], true));
//}
} }
pathNodes.Add(endPosition); pathNodes.Add(endPosition);
@@ -1021,7 +1021,7 @@ namespace Barotrauma
var positionsWithSpace = positionsOfInterest.FindAll(p => (bool)preferLarge == p.IsLarge); var positionsWithSpace = positionsOfInterest.FindAll(p => (bool)preferLarge == p.IsLarge);
if (!positionsWithSpace.Any()) return Size * 0.5f; if (!positionsWithSpace.Any()) return Size * 0.5f;
return positionsWithSpace[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position; return positionsWithSpace[Rand.Int(positionsWithSpace.Count, !useSyncedRand)].Position;
} }
} }
Binary file not shown.