Banning players, networkevent refactoring, wire syncing bugfixes, wrenches can be used as a melee weapon, proper error message for invalid IPs, drawing held items in correct position, fixed client crashing if sending a chatmessage while connection is lost
This commit is contained in:
@@ -161,9 +161,9 @@ namespace Barotrauma
|
||||
{
|
||||
//PutItem(items[i], i, false, false);
|
||||
Inventory otherInventory = items[i].inventory;
|
||||
if (otherInventory!=null)
|
||||
if (otherInventory!=null && createNetworkEvent)
|
||||
{
|
||||
new Networking.NetworkEvent(Networking.NetworkEventType.InventoryUpdate, otherInventory.Owner.ID, true);
|
||||
new Networking.NetworkEvent(Networking.NetworkEventType.InventoryUpdate, otherInventory.Owner.ID, true, true);
|
||||
}
|
||||
|
||||
combined = true;
|
||||
@@ -263,17 +263,77 @@ namespace Barotrauma
|
||||
SpriteEffects.None, 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
slotRect.X = (int)slotPositions[i].X;
|
||||
slotRect.Y = (int)slotPositions[i].Y;
|
||||
|
||||
bool multiSlot = false;
|
||||
//skip if the item is in multiple slots
|
||||
if (items[i]!=null)
|
||||
{
|
||||
for (int n = 0; n < capacity; n++ )
|
||||
{
|
||||
if (i==n || items[n] != items[i]) continue;
|
||||
multiSlot = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateSlot(spriteBatch, slotRect, i, items[i], i>4);
|
||||
if (multiSlot) continue;
|
||||
|
||||
UpdateSlot(spriteBatch, slotRect, i, items[i], i > 4);
|
||||
|
||||
if (draggingItem!=null && draggingItem == items[i]) draggingItemSlot = slotRect;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
|
||||
//Rectangle multiSlotRect = Rectangle.Empty;
|
||||
bool multiSlot = false;
|
||||
|
||||
//check if the item is in multiple slots
|
||||
if (items[i] != null)
|
||||
{
|
||||
slotRect.X = (int)slotPositions[i].X;
|
||||
slotRect.Y = (int)slotPositions[i].Y;
|
||||
slotRect.Width = 40;
|
||||
slotRect.Height = 40;
|
||||
|
||||
for (int n = 0; n < capacity; n++)
|
||||
{
|
||||
if (items[n] != items[i]) continue;
|
||||
|
||||
if (!multiSlot && i > n) break;
|
||||
|
||||
if (i!=n)
|
||||
{
|
||||
multiSlot = true;
|
||||
slotRect = Rectangle.Union(
|
||||
new Rectangle((int)slotPositions[n].X, (int)slotPositions[n].Y, rectWidth, rectHeight), slotRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!multiSlot) continue;
|
||||
|
||||
UpdateSlot(spriteBatch, slotRect, i, items[i], i > 4);
|
||||
|
||||
//if (multiSlot && i == first)
|
||||
//{
|
||||
// multiSlotPos = multiSlotPos / count;
|
||||
// items[i].Sprite.Draw(spriteBatch, new Vector2(multiSlotPos.X + rectWidth / 2, multiSlotPos.Y + rectHeight / 2), items[i].Color);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
slotRect.Width = rectWidth;
|
||||
slotRect.Height = rectHeight;
|
||||
|
||||
|
||||
if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
attached = true;
|
||||
|
||||
item.NewComponentEvent(this, true);
|
||||
item.NewComponentEvent(this, true, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
ac.HoldItem(deltaTime, item, handlePos, new Vector2(hitPos, 0.0f), aimPos, false, 0.0f);
|
||||
ac.HoldItem(deltaTime, item, handlePos, new Vector2(hitPos, 0.0f), aimPos, false, holdAngle);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -93,10 +93,18 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
spriteBatch.DrawString(GUI.Font, "Force: " + (int)(targetForce) + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White);
|
||||
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 30, 40, 40), "+", true)) targetForce += 1.0f;
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 80, 40, 40), "-", true)) targetForce -= 1.0f;
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 30, 40, 40), "+", true))
|
||||
{
|
||||
targetForce += 1.0f;
|
||||
item.NewComponentEvent(this, true, false);
|
||||
}
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 80, 40, 40), "-", true))
|
||||
{
|
||||
targetForce -= 1.0f;
|
||||
item.NewComponentEvent(this, true, false);
|
||||
}
|
||||
|
||||
|
||||
item.NewComponentEvent(this, true);
|
||||
}
|
||||
|
||||
public override void UpdateBroken(float deltaTime, Camera cam)
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace Barotrauma.Items.Components
|
||||
targetLevel = null;
|
||||
IsActive = !IsActive;
|
||||
if (!IsActive) currPowerConsumption = 0.0f;
|
||||
item.NewComponentEvent(this, true);
|
||||
item.NewComponentEvent(this, true, true);
|
||||
}
|
||||
|
||||
spriteBatch.DrawString(GUI.Font, "Pumping speed: " + (int)flowPercentage + " %", new Vector2(x + 20, y + 80), Color.White);
|
||||
@@ -125,12 +125,12 @@ namespace Barotrauma.Items.Components
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "OUT", false))
|
||||
{
|
||||
FlowPercentage -= 10.0f;
|
||||
item.NewComponentEvent(this, true);
|
||||
item.NewComponentEvent(this, true, false);
|
||||
}
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "IN", false))
|
||||
{
|
||||
FlowPercentage += 10.0f;
|
||||
item.NewComponentEvent(this, true);
|
||||
item.NewComponentEvent(this, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Barotrauma.Items.Components
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 20, y + 20, 200, 30), "Activate Radar"))
|
||||
{
|
||||
IsActive = !IsActive;
|
||||
item.NewComponentEvent(this, true);
|
||||
item.NewComponentEvent(this, true, false);
|
||||
}
|
||||
|
||||
int radius = GuiFrame.Rect.Height / 2 - 10;
|
||||
|
||||
@@ -371,7 +371,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (valueChanged)
|
||||
{
|
||||
item.NewComponentEvent(this, true);
|
||||
item.NewComponentEvent(this, true, false);
|
||||
valueChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace Barotrauma.Items.Components
|
||||
networkUpdateTimer -= deltaTime;
|
||||
if (networkUpdateTimer<=0.0f)
|
||||
{
|
||||
item.NewComponentEvent(this, true);
|
||||
item.NewComponentEvent(this, true, false);
|
||||
networkUpdateTimer = 1.0f;
|
||||
valueChanged = false;
|
||||
}
|
||||
@@ -124,7 +124,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
AutoPilot = !AutoPilot;
|
||||
|
||||
item.NewComponentEvent(this, true);
|
||||
item.NewComponentEvent(this, true, true);
|
||||
}
|
||||
|
||||
GUI.DrawLine(spriteBatch,
|
||||
|
||||
@@ -186,13 +186,13 @@ namespace Barotrauma.Items.Components
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 90, 40, 40), "+"))
|
||||
{
|
||||
rechargeSpeed = Math.Min(rechargeSpeed + maxRechargeSpeed*0.1f, maxRechargeSpeed);
|
||||
item.NewComponentEvent(this, true);
|
||||
item.NewComponentEvent(this, true, false);
|
||||
}
|
||||
|
||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 90, 40, 40), "-"))
|
||||
{
|
||||
rechargeSpeed = Math.Max(rechargeSpeed - maxRechargeSpeed * 0.1f, 0.0f);
|
||||
item.NewComponentEvent(this, true);
|
||||
item.NewComponentEvent(this, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -280,7 +280,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (!PlayerInput.LeftButtonDown())
|
||||
{
|
||||
panel.Item.NewComponentEvent(panel, true);
|
||||
panel.Item.NewComponentEvent(panel, true, true);
|
||||
draggingConnected = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,10 +125,9 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
Wire[] wires = Array.FindAll(c.Wires, w => w != null);
|
||||
message.Write((byte)wires.Length);
|
||||
for (int i = 0 ; i < c.Wires.Length; i++)
|
||||
for (int i = 0 ; i < wires.Length; i++)
|
||||
{
|
||||
if (c.Wires[i] == null) continue;
|
||||
message.Write(c.Wires[i].Item.ID);
|
||||
message.Write(wires[i].Item.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,26 +139,22 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
//int wireCount = c.Wires.Length;
|
||||
c.ClearConnections();
|
||||
try
|
||||
|
||||
byte wireCount = message.ReadByte();
|
||||
|
||||
for (int i = 0; i < wireCount; i++)
|
||||
{
|
||||
byte wireCount = message.ReadByte();
|
||||
|
||||
for (int i = 0; i < wireCount; i++)
|
||||
{
|
||||
ushort wireId = message.ReadUInt16();
|
||||
ushort wireId = message.ReadUInt16();
|
||||
|
||||
Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
|
||||
if (wireItem == null) continue;
|
||||
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 { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Barotrauma.Items.Components
|
||||
CleanNodes();
|
||||
}
|
||||
|
||||
if (!loading) Item.NewComponentEvent(this, true);
|
||||
if (!loading) Item.NewComponentEvent(this, true, true);
|
||||
}
|
||||
|
||||
public override void Equip(Character character)
|
||||
@@ -200,7 +200,7 @@ namespace Barotrauma.Items.Components
|
||||
if (Nodes.Count > 1)
|
||||
{
|
||||
Nodes.RemoveAt(Nodes.Count - 1);
|
||||
item.NewComponentEvent(this, true);
|
||||
item.NewComponentEvent(this, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,8 +409,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
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((byte)Math.Min(Nodes.Count, 10));
|
||||
for (int i = 0; i < Math.Min(Nodes.Count,10); i++)
|
||||
{
|
||||
message.Write(Nodes[i].X);
|
||||
message.Write(Nodes[i].Y);
|
||||
@@ -420,8 +420,8 @@ namespace Barotrauma.Items.Components
|
||||
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
|
||||
{
|
||||
Nodes.Clear();
|
||||
int nodeCount = message.ReadInt32();
|
||||
for (int i = 0; i < nodeCount; i++)
|
||||
int nodeCount = message.ReadByte();
|
||||
for (int i = 0; i<nodeCount; i++)
|
||||
{
|
||||
Nodes.Add(new Vector2(message.ReadFloat(), message.ReadFloat()));
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Barotrauma
|
||||
item.body.Enabled = false;
|
||||
}
|
||||
|
||||
if (createNetworkEvent) new NetworkEvent(NetworkEventType.InventoryUpdate, Owner.ID, true);
|
||||
if (createNetworkEvent) new NetworkEvent(NetworkEventType.InventoryUpdate, Owner.ID, true, true);
|
||||
}
|
||||
|
||||
public void RemoveItem(Item item)
|
||||
@@ -203,11 +203,11 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateSlot(SpriteBatch spriteBatch, Rectangle rect, int slotIndex, Item item, bool isSubSlot)
|
||||
protected void UpdateSlot(SpriteBatch spriteBatch, Rectangle rect, int slotIndex, Item item, bool isSubSlot, bool drawItem=true)
|
||||
{
|
||||
bool mouseOn = rect.Contains(PlayerInput.MousePosition);
|
||||
|
||||
DrawSlot(spriteBatch, rect, (draggingItem == item && !mouseOn) ? null : item, mouseOn, isSubSlot);
|
||||
DrawSlot(spriteBatch, rect, (draggingItem == item && !mouseOn) ? null : item, mouseOn, isSubSlot, drawItem);
|
||||
|
||||
if (mouseOn)
|
||||
{
|
||||
@@ -267,12 +267,12 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawSlot(SpriteBatch spriteBatch, Rectangle rect, Item item, bool isHighLighted, bool isSubSlot)
|
||||
protected void DrawSlot(SpriteBatch spriteBatch, Rectangle rect, Item item, bool isHighLighted, bool isSubSlot, bool drawItem=true)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * ((isSubSlot) ? 0.1f : 0.3f), true);
|
||||
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * ((isSubSlot) ? 0.2f : 0.4f), false);
|
||||
|
||||
if (item == null) return;
|
||||
if (item == null || !drawItem) return;
|
||||
|
||||
item.Sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color);
|
||||
|
||||
|
||||
@@ -593,7 +593,25 @@ namespace Barotrauma
|
||||
}
|
||||
else if (body.Enabled)
|
||||
{
|
||||
body.Draw(spriteBatch, prefab.sprite, color);
|
||||
var holdable = GetComponent<Holdable>();
|
||||
if (holdable!=null && holdable.Picker !=null)
|
||||
{
|
||||
float depth = Sprite.Depth;
|
||||
if (holdable.Picker.SelectedItems[0]==this)
|
||||
{
|
||||
depth = holdable.Picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.000001f;
|
||||
}
|
||||
else if (holdable.Picker.SelectedItems[1] == this)
|
||||
{
|
||||
depth = holdable.Picker.AnimController.GetLimb(LimbType.LeftArm).sprite.Depth - 0.000001f;
|
||||
}
|
||||
|
||||
body.Draw(spriteBatch, prefab.sprite, color, depth);
|
||||
}
|
||||
else
|
||||
{
|
||||
body.Draw(spriteBatch, prefab.sprite, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1149,11 +1167,12 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
|
||||
public void NewComponentEvent(ItemComponent ic, bool isClient)
|
||||
public void NewComponentEvent(ItemComponent ic, bool isClient, bool isImportant)
|
||||
{
|
||||
int index = components.IndexOf(ic);
|
||||
|
||||
new NetworkEvent(NetworkEventType.UpdateComponent, ID, isClient, index);
|
||||
new NetworkEvent(isImportant ?
|
||||
NetworkEventType.ImportantComponentUpdate : NetworkEventType.ComponentUpdate, ID, isClient, index);
|
||||
}
|
||||
|
||||
public override bool FillNetworkData(NetworkEventType type, NetOutgoingMessage message, object data)
|
||||
@@ -1173,7 +1192,8 @@ namespace Barotrauma
|
||||
var itemContainer = GetComponent<ItemContainer>();
|
||||
if (itemContainer == null || itemContainer.inventory == null) return false;
|
||||
return itemContainer.inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
||||
case NetworkEventType.UpdateComponent:
|
||||
case NetworkEventType.ComponentUpdate:
|
||||
case NetworkEventType.ImportantComponentUpdate:
|
||||
|
||||
int componentIndex = (int)data;
|
||||
if (componentIndex < 0 || componentIndex >= components.Count) return false;
|
||||
@@ -1230,10 +1250,7 @@ namespace Barotrauma
|
||||
{
|
||||
case NetworkEventType.DropItem:
|
||||
Vector2 newSimPos = Vector2.Zero;
|
||||
if (body != null)
|
||||
{
|
||||
newSimPos = new Vector2(message.ReadFloat(), message.ReadFloat());
|
||||
}
|
||||
newSimPos = new Vector2(message.ReadFloat(), message.ReadFloat());
|
||||
SetTransform(newSimPos, body.Rotation);
|
||||
Drop(null, false);
|
||||
break;
|
||||
@@ -1242,7 +1259,8 @@ namespace Barotrauma
|
||||
if (itemContainer == null || itemContainer.inventory == null) return;
|
||||
itemContainer.inventory.ReadNetworkData(NetworkEventType.DropItem, message);
|
||||
break;
|
||||
case NetworkEventType.UpdateComponent:
|
||||
case NetworkEventType.ComponentUpdate:
|
||||
case NetworkEventType.ImportantComponentUpdate:
|
||||
int componentIndex = message.ReadByte();
|
||||
if (componentIndex < 0 || componentIndex > components.Count - 1) return;
|
||||
components[componentIndex].ReadNetworkData(type, message);
|
||||
|
||||
Reference in New Issue
Block a user