waypoint selection bug, unequipped captain uniform sprites, repairtool sounds & particle tweaking, wire overlap bug, connectionpanel loading bug, looting dead crew members

This commit is contained in:
Regalis
2015-08-04 20:11:59 +03:00
parent 9149408b36
commit 048eb5713f
24 changed files with 154 additions and 71 deletions

View File

@@ -34,7 +34,7 @@ namespace Subsurface
public readonly bool IsNetworkPlayer;
private Inventory inventory;
private CharacterInventory inventory;
public double LastNetworkUpdate;
@@ -66,6 +66,7 @@ namespace Subsurface
protected float maxHealth;
protected Item closestItem;
private Character closestCharacter, selectedCharacter;
protected bool isDead;
@@ -93,7 +94,6 @@ namespace Subsurface
protected float soundInterval;
private float bleeding;
//private float blood;
private Sound[] sounds;
private float[] soundRange;
@@ -113,7 +113,7 @@ namespace Subsurface
get { return AnimController.Mass; }
}
public Inventory Inventory
public CharacterInventory Inventory
{
get { return inventory; }
}
@@ -301,11 +301,11 @@ namespace Subsurface
public Character(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false)
{
selectKeyHit = new Key(false);
actionKeyDown = new Key(true);
actionKeyHit = new Key(false);
secondaryKeyHit = new Key(false);
secondaryKeyDown = new Key(true);
selectKeyHit = new Key(false);
actionKeyDown = new Key(true);
actionKeyHit = new Key(false);
secondaryKeyHit = new Key(false);
secondaryKeyDown = new Key(true);
selectedItems = new Item[2];
@@ -330,7 +330,7 @@ namespace Subsurface
{
AnimController = new HumanoidAnimController(this, doc.Root.Element("ragdoll"));
AnimController.TargetDir = Direction.Right;
inventory = new CharacterInventory(10, this);
inventory = new CharacterInventory(15, this);
}
else
{
@@ -432,11 +432,15 @@ namespace Subsurface
}
Item item = new Item(itemPrefab, Position);
inventory.TryPutItem(item, item.AllowedSlots, false);
if (info.Job.EquipSpawnItem[i])
{
item.Equip(this);
inventory.TryPutItem(item,
item.AllowedSlots.HasFlag(LimbSlot.Any) ? item.AllowedSlots & ~LimbSlot.Any : item.AllowedSlots, false);
}
else
{
inventory.TryPutItem(item, item.AllowedSlots, false);
}
if (item.Prefab.Name == "ID Card" && spawnPoint != null)
@@ -460,8 +464,7 @@ namespace Subsurface
//find the closest item if selectkey has been hit, or if the character is being
//controlled by the player (in order to highlight it)
//closestItem = null;
if (controlled==this)
if (controlled == this)
{
Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cam.ScreenToWorld(PlayerInput.MousePosition));
closestItem = FindClosestItem(mouseSimPos);
@@ -474,6 +477,13 @@ namespace Subsurface
new NetworkEvent(NetworkEventType.PickItem, ID, true, closestItem.ID);
}
}
closestCharacter = FindClosestCharacter(mouseSimPos);
if (closestCharacter != selectedCharacter) selectedCharacter = null;
if (closestCharacter!=null)
{
if (selectKeyHit.State) selectedCharacter = (selectedCharacter==null) ? closestCharacter : null;
}
}
for (int i = 0; i < selectedItems.Length; i++ )
@@ -509,6 +519,31 @@ namespace Subsurface
return Item.FindPickable(pos, selectedConstruction == null ? mouseSimPos : selectedConstruction.SimPosition, null, selectedItems);
}
private Character FindClosestCharacter(Vector2 mouseSimPos, float maxDist = 150.0f)
{
Character closestCharacter = null;
float closestDist = 0.0f;
maxDist = ConvertUnits.ToSimUnits(maxDist);
foreach (Character c in Character.CharacterList)
{
if (c == this) continue;
if (Vector2.Distance(SimPosition, c.SimPosition) > maxDist) continue;
float dist = Vector2.Distance(mouseSimPos, c.SimPosition);
if (dist < maxDist && closestCharacter==null || dist<closestDist)
{
closestCharacter = c;
closestDist = dist;
continue;
}
}
return closestCharacter;
}
/// <summary>
/// Control the character according to player input
/// </summary>
@@ -743,10 +778,10 @@ namespace Subsurface
private static GUIProgressBar drowningBar, healthBar;
public void DrawHud(SpriteBatch spriteBatch, Camera cam)
{
if (drowningBar==null)
if (drowningBar == null)
{
int width = 100, height = 20;
drowningBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight/2, width, height), Color.Blue, 1.0f);
drowningBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight / 2, width, height), Color.Blue, 1.0f);
healthBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight / 2 + 30, width, height), Color.Red, 1.0f);
}
@@ -757,11 +792,26 @@ namespace Subsurface
healthBar.BarSize = health / maxHealth;
if (healthBar.BarSize < 1.0f) healthBar.Draw(spriteBatch);
if (Controlled.Inventory != null) Controlled.Inventory.Draw(spriteBatch);
if (Controlled.Inventory != null) Controlled.Inventory.DrawOwn(spriteBatch);
if (closestItem != null && selectedConstruction==null)
Color color = Color.Orange;
if (closestCharacter != null && closestCharacter.isDead)
{
Vector2 startPos = Position + (closestCharacter.Position - Position) * 0.7f;
startPos = cam.WorldToScreen(startPos);
Vector2 textPos = startPos;
float stringWidth = GUI.Font.MeasureString(closestCharacter.Info.Name).X;
textPos -= new Vector2(stringWidth / 2, 20);
spriteBatch.DrawString(GUI.Font, closestCharacter.Info.Name, textPos, Color.Black);
spriteBatch.DrawString(GUI.Font, closestCharacter.Info.Name, textPos + new Vector2(1, -1), Color.Orange);
if (selectedCharacter==closestCharacter) closestCharacter.inventory.Draw(spriteBatch);
}
else if (closestItem != null && selectedConstruction==null)
{
Color color = Color.Orange;
Vector2 startPos = Position + (closestItem.Position - Position) * 0.7f;
startPos = cam.WorldToScreen(startPos);
@@ -782,7 +832,7 @@ namespace Subsurface
spriteBatch.DrawString(GUI.Font, coloredText.text, textPos + new Vector2(1, -1), coloredText.color);
textPos.Y += 25;
}
}
}
}

View File

@@ -19,7 +19,8 @@ namespace Subsurface
private static LimbSlot[] limbSlots = new LimbSlot[] {
LimbSlot.Head, LimbSlot.Torso, LimbSlot.Legs, LimbSlot.LeftHand, LimbSlot.RightHand,
LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any };
LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any,
LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any};
private Vector2[] slotPositions;
@@ -52,12 +53,12 @@ namespace Subsurface
case 4:
slotPositions[i] = new Vector2(
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 3),
Game1.GraphicsHeight - (spacing + rectHeight));
Game1.GraphicsHeight - (spacing + rectHeight)*3);
break;
default:
slotPositions[i] = new Vector2(
spacing * (4 + (i - 5)) + rectWidth * (3 + (i - 5)),
Game1.GraphicsHeight - (spacing + rectHeight));
spacing * 2 + rectWidth + (spacing + rectWidth) * ((i - 3)%5),
Game1.GraphicsHeight - (spacing + rectHeight) * ((i>9) ? 2 : 1));
break;
}
}
@@ -212,7 +213,7 @@ namespace Subsurface
}
public override void Draw(SpriteBatch spriteBatch)
public void DrawOwn(SpriteBatch spriteBatch)
{
if (doubleClickedItem!=null && doubleClickedItem.inventory!=this)
{
@@ -251,7 +252,7 @@ namespace Subsurface
slotRect.Y = (int)slotPositions[i].Y;
UpdateSlot(spriteBatch, slotRect, i, items[i], false);
UpdateSlot(spriteBatch, slotRect, i, items[i], i>4);
if (draggingItem!=null && draggingItem == items[i]) draggingItemSlot = slotRect;
}

View File

@@ -58,8 +58,8 @@ namespace Subsurface.Items.Components
[HasDefaultValue(0.0f, false)]
public float ItemRotation
{
get { return itemRotation; }
set { itemRotation = value; }
get { return MathHelper.ToDegrees(itemRotation); }
set { itemRotation = MathHelper.ToRadians(value); }
}
private float itemRotation;

View File

@@ -183,6 +183,17 @@ namespace Subsurface.Items.Components
if (!attachable || item.body==null) return true;
item.Drop();
var containedItems = item.ContainedItems;
if (containedItems!=null)
{
foreach (Item contained in containedItems)
{
if (contained.body == null) continue;
contained.SetTransform(item.SimPosition, contained.body.Rotation);
}
}
item.body.Enabled = false;
item.body = null;

View File

@@ -124,7 +124,7 @@ namespace Subsurface.Items.Components
Body targetBody = Submarine.PickBody(TransformedBarrelPos, targetPosition, ignoredBodies);
pickedPosition = Submarine.LastPickedPosition;
if (targetBody==null || targetBody.UserData==null) return true;
if (targetBody == null || targetBody.UserData == null) return true;
//ApplyStatusEffects(ActionType.OnUse, 1.0f, character);

View File

@@ -550,9 +550,7 @@ namespace Subsurface.Items.Components
public virtual void Load(XElement componentElement)
{
if (componentElement == null) return;
if (componentElement == null) return;
foreach (XAttribute attribute in componentElement.Attributes())
{

View File

@@ -179,6 +179,10 @@ namespace Subsurface.Items.Components
foreach (Item contained in item.ContainedItems)
{
contained.Condition = 0.0f;
if (contained.body!=null)
{
contained.body.SetTransform(item.SimPosition, contained.body.Rotation);
}
}
return true;

View File

@@ -28,7 +28,7 @@ namespace Subsurface.Items.Components
private List<StatusEffect> effects;
int[] wireId;
public readonly int[] wireId;
public List<Connection> Recipients
{
@@ -463,7 +463,7 @@ namespace Subsurface.Items.Components
}
}
wireId = null;
//wireId = null;
}
}

View File

@@ -74,21 +74,26 @@ namespace Subsurface.Items.Components
public override void Load(XElement element)
{
base.Load(element);
connections.Clear();
List<Connection> loadedConnections = new List<Connection>();
foreach (XElement subElement in element.Elements())
{
switch (subElement.Name.ToString())
{
case "input":
connections.Add(new Connection(subElement, item));
loadedConnections.Add(new Connection(subElement, item));
break;
case "output":
connections.Add(new Connection(subElement, item));
loadedConnections.Add(new Connection(subElement, item));
break;
}
}
for (int i = 0; i<loadedConnections.Count && i<connections.Count; i++)
{
loadedConnections[i].wireId.CopyTo(connections[i].wireId, 0);
}
}
public override void Remove()

View File

@@ -274,12 +274,12 @@ namespace Subsurface.Items.Components
for (int i = 1; i < Nodes.Count; i++)
{
DrawSection(spriteBatch, Nodes[i], Nodes[i - 1], i, item.Color);
DrawSection(spriteBatch, Nodes[i], Nodes[i - 1], item.Color);
}
if (isActive && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
{
DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, Nodes.Count, item.Color * 0.5f);
DrawSection(spriteBatch, Nodes[Nodes.Count - 1], newNodePos, item.Color * 0.5f);
//nodes.Add(newNodePos);
}
@@ -333,7 +333,7 @@ selectedNodeIndex = null;
}
private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, int i, Color color)
private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color)
{
start.Y = -start.Y;
end.Y = -end.Y;
@@ -344,7 +344,7 @@ selectedNodeIndex = null;
new Vector2(0.0f, wireSprite.size.Y / 2.0f),
new Vector2((Vector2.Distance(start, end)) / wireSprite.Texture.Width, 0.3f),
SpriteEffects.None,
wireSprite.Depth + 0.1f + i * 0.00001f);
wireSprite.Depth + ((item.ID % 100) * 0.00001f));
}
public override XElement Save(XElement parentElement)

View File

@@ -450,13 +450,21 @@ namespace Subsurface
{
if (ic.Parent != null) ic.IsActive = ic.Parent.IsActive;
if (!ic.WasUsed) ic.StopSounds(ActionType.OnUse);
ic.WasUsed = false;
//if (!ic.WasUsed)
//{
// if (ic.Name == "RepairTool" && ic.IsActive)
// {
// System.Diagnostics.Debug.WriteLine("stop sounds");
// }
// ic.StopSounds(ActionType.OnUse);
//}
//ic.WasUsed = false;
if (!ic.IsActive)
{
ic.StopSounds(ActionType.OnActive);
ic.StopSounds(ActionType.OnUse);
continue;
}
if (condition > 0.0f)

View File

@@ -436,7 +436,7 @@ namespace Subsurface
float dragCoefficient = 0.00001f;
float speedLength = speed.Length();
float speedLength = (speed == Vector2.Zero) ? 0.0f : speed.Length();
float drag = speedLength * speedLength * dragCoefficient * mass;
if (speed != Vector2.Zero)

View File

@@ -73,7 +73,7 @@ namespace Subsurface
public override void DrawEditing(SpriteBatch spriteBatch, Camera cam)
{
if (editingHUD==null)
if (editingHUD == null || editingHUD.UserData != this)
{
editingHUD = CreateEditingHUD();
}

View File

@@ -258,7 +258,6 @@ namespace Subsurface.Networking
{
Character.Controlled = null;
Game1.GameScreen.Cam.TargetPos = Vector2.Zero;
Game1.GameScreen.Cam.Zoom = 1.0f;
}
else
{

View File

@@ -161,9 +161,8 @@ namespace Subsurface.Particles
float drawRotation = Physics.Interpolate(prevRotation, rotation);
drawPosition = ConvertUnits.ToDisplayUnits(drawPosition);
prefab.sprite.Draw(spriteBatch, drawPosition, color*alpha, drawRotation, size.X, SpriteEffects.None, prefab.sprite.Depth);
prefab.sprite.Draw(spriteBatch, drawPosition, color*alpha, prefab.sprite.origin, drawRotation, size, SpriteEffects.None, prefab.sprite.Depth);
//spriteBatch.Draw(
// prefab.sprite.Texture,

View File

@@ -194,6 +194,11 @@ namespace Subsurface
{
spriteBatch.Draw(texture, pos + offset, sourceRect, color, rotation + rotate, origin, scale, spriteEffect, depth == null ? this.depth : (float)depth);
}
public void Draw(SpriteBatch spriteBatch, Vector2 pos, Color color, Vector2 origin, float rotate, Vector2 scale, SpriteEffects spriteEffect = SpriteEffects.None, float? depth = null)
{
spriteBatch.Draw(texture, pos + offset, sourceRect, color, rotation + rotate, origin, scale, spriteEffect, depth == null ? this.depth : (float)depth);
}
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Color color)
{