Fabricator, deconstructor, itemspawner & itemremover syncing, fixed placing hulls in editor, misc cleanup
This commit is contained in:
@@ -192,7 +192,7 @@ namespace Barotrauma
|
||||
//vel.Y = message.ReadFloat();
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -413,11 +413,6 @@ namespace Barotrauma
|
||||
|
||||
Item item = FindEntityByID(Info.PickedItemIDs[i]) as Item;
|
||||
|
||||
if (item==null)
|
||||
{
|
||||
int a = 1;
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(item != null);
|
||||
if (item == null) continue;
|
||||
|
||||
|
||||
@@ -128,33 +128,6 @@ namespace Barotrauma
|
||||
{
|
||||
if (!isOpen) return;
|
||||
|
||||
int margin = 5;
|
||||
|
||||
//GUI.DrawRectangle(spriteBatch,
|
||||
// new Vector2(x, y),
|
||||
// new Vector2(width, height),
|
||||
// new Color(0.4f, 0.4f, 0.4f, 0.6f), true);
|
||||
|
||||
//GUI.DrawRectangle(spriteBatch,
|
||||
// new Vector2(x + margin, y + margin),
|
||||
// new Vector2(width - margin * 2, height - margin * 2),
|
||||
// new Color(0.0f, 0.0f, 0.0f, 0.6f), true);
|
||||
|
||||
//remove messages that won't fit on the screen
|
||||
//while (messages.Count() * 20 > height - 70)
|
||||
//{
|
||||
// messages.RemoveAt(0);
|
||||
//}
|
||||
|
||||
//Vector2 messagePos = new Vector2(x + margin * 2, y + height - 70 - messages.Count()*20);
|
||||
//foreach (ColoredText message in messages)
|
||||
//{
|
||||
// spriteBatch.DrawString(GUI.Font, message.Text, messagePos, message.Color);
|
||||
// messagePos.Y += 20;
|
||||
//}
|
||||
|
||||
//textBox.Draw(spriteBatch);
|
||||
|
||||
frame.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Barotrauma
|
||||
public bool IsHorizontal
|
||||
{
|
||||
get { return isHorizontal; }
|
||||
set { isHorizontal = value; }
|
||||
}
|
||||
|
||||
public float BarSize
|
||||
|
||||
@@ -17,13 +17,15 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
ItemContainer container;
|
||||
|
||||
private float lastNetworkUpdate;
|
||||
|
||||
public Deconstructor(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
progressBar = new GUIProgressBar(new Rectangle(0,0,200,20), Color.Green, 0.0f, Alignment.BottomCenter, GuiFrame);
|
||||
|
||||
activateButton = new GUIButton(new Rectangle(0, 0, 200, 20), "Deconstruct", Alignment.TopCenter, GUI.Style, GuiFrame);
|
||||
activateButton.OnClicked = Activate;
|
||||
activateButton.OnClicked = ToggleActive;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
@@ -73,19 +75,31 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||
{
|
||||
GuiFrame.Update((float)Physics.step);
|
||||
GuiFrame.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
private bool Activate(GUIButton button, object obj)
|
||||
private bool ToggleActive(GUIButton button, object obj)
|
||||
{
|
||||
SetActive(!IsActive);
|
||||
|
||||
item.NewComponentEvent(this, true, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void SetActive(bool active)
|
||||
{
|
||||
container = item.GetComponent<ItemContainer>();
|
||||
if (container==null)
|
||||
if (container == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in Deconstructor.Activate: Deconstructors must have two ItemContainer components");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsActive)
|
||||
IsActive = active;
|
||||
|
||||
if (!IsActive)
|
||||
{
|
||||
progressBar.BarSize = 0.0f;
|
||||
progressTimer = 0.0f;
|
||||
@@ -94,16 +108,38 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!container.Inventory.Items.Any(i => i != null)) return false;
|
||||
if (!container.Inventory.Items.Any(i => i != null)) return;
|
||||
|
||||
activateButton.Text = "Cancel";
|
||||
}
|
||||
|
||||
IsActive = !IsActive;
|
||||
|
||||
container.Inventory.Locked = IsActive;
|
||||
|
||||
}
|
||||
|
||||
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
|
||||
{
|
||||
|
||||
var containers = item.GetComponents<ItemContainer>();
|
||||
containers[0].Inventory.FillNetworkData(type, message, null);
|
||||
containers[1].Inventory.FillNetworkData(type, message, null);
|
||||
|
||||
message.Write(IsActive);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message, float sendingTime)
|
||||
{
|
||||
if (sendingTime < lastNetworkUpdate) return;
|
||||
|
||||
var containers = item.GetComponents<ItemContainer>();
|
||||
containers[0].Inventory.ReadNetworkData(type, message, sendingTime);
|
||||
containers[1].Inventory.ReadNetworkData(type, message, sendingTime);
|
||||
|
||||
SetActive(message.ReadBoolean());
|
||||
|
||||
lastNetworkUpdate = sendingTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,11 @@ namespace Barotrauma.Items.Components
|
||||
class Engine : Powered
|
||||
{
|
||||
|
||||
float force;
|
||||
private float force;
|
||||
|
||||
float targetForce;
|
||||
private float targetForce;
|
||||
|
||||
float maxForce;
|
||||
|
||||
float powerPerForce;
|
||||
private float maxForce;
|
||||
|
||||
//[Editable, HasDefaultValue(1.0f, true)]
|
||||
//public float PowerPerForce
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Barotrauma.Items.Components
|
||||
public readonly List<ItemPrefab> RequiredItems;
|
||||
|
||||
public readonly float RequiredTime;
|
||||
|
||||
|
||||
//ListOrSomething requiredLevels
|
||||
|
||||
public FabricableItem(XElement element)
|
||||
@@ -45,14 +45,19 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
class Fabricator : ItemComponent
|
||||
{
|
||||
List<FabricableItem> fabricableItems;
|
||||
private List<FabricableItem> fabricableItems;
|
||||
|
||||
GUIListBox itemList;
|
||||
private GUIListBox itemList;
|
||||
|
||||
GUIFrame selectedItemFrame;
|
||||
private GUIFrame selectedItemFrame;
|
||||
|
||||
FabricableItem fabricatedItem;
|
||||
float timeUntilReady;
|
||||
GUIProgressBar progressBar;
|
||||
GUIButton activateButton;
|
||||
|
||||
private FabricableItem fabricatedItem;
|
||||
private float timeUntilReady;
|
||||
|
||||
private float lastNetworkUpdate;
|
||||
|
||||
public Fabricator(Item item, XElement element)
|
||||
: base(item, element)
|
||||
@@ -96,10 +101,13 @@ namespace Barotrauma.Items.Components
|
||||
if (selectedItemFrame != null) GuiFrame.RemoveChild(selectedItemFrame);
|
||||
|
||||
//int width = 200, height = 150;
|
||||
selectedItemFrame = new GUIFrame(new Rectangle(0,0,(int)(GuiFrame.Rect.Width*0.4f),200), Color.Black*0.8f, Alignment.CenterY | Alignment.Right, null, GuiFrame);
|
||||
selectedItemFrame = new GUIFrame(new Rectangle(0,0,(int)(GuiFrame.Rect.Width*0.4f),250), Color.Black*0.8f, Alignment.CenterY | Alignment.Right, null, GuiFrame);
|
||||
|
||||
selectedItemFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
|
||||
progressBar = new GUIProgressBar(new Rectangle(0, 0, 0, 20), Color.Green, GUI.Style, 0.0f, Alignment.BottomCenter, selectedItemFrame);
|
||||
progressBar.IsHorizontal = true;
|
||||
|
||||
if (targetItem.TargetItem.sprite != null)
|
||||
{
|
||||
GUIImage img = new GUIImage(new Rectangle(10, 0, 40, 40), targetItem.TargetItem.sprite, Alignment.TopLeft, selectedItemFrame);
|
||||
@@ -119,7 +127,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
text += " - " + ip.Name + "\n";
|
||||
}
|
||||
text += "Required time: "+targetItem.RequiredTime+" s";
|
||||
text += "Required time: " + targetItem.RequiredTime + " s";
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 50, 0, 25),
|
||||
@@ -129,11 +137,10 @@ namespace Barotrauma.Items.Components
|
||||
Alignment.TopLeft, null,
|
||||
selectedItemFrame);
|
||||
|
||||
GUIButton button = new GUIButton(new Rectangle(0,0,100,20), "Create", Color.White, Alignment.CenterX | Alignment.Bottom, GUI.Style, selectedItemFrame);
|
||||
button.OnClicked = StartFabricating;
|
||||
button.UserData = targetItem;
|
||||
|
||||
|
||||
activateButton = new GUIButton(new Rectangle(0, -30, 100, 20), "Create", Color.White, Alignment.CenterX | Alignment.Bottom, GUI.Style, selectedItemFrame);
|
||||
activateButton.OnClicked = StartButtonClicked;
|
||||
activateButton.UserData = targetItem;
|
||||
activateButton.Enabled = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -144,25 +151,80 @@ namespace Barotrauma.Items.Components
|
||||
return (picker != null);
|
||||
}
|
||||
|
||||
private bool StartFabricating(GUIButton button, object obj)
|
||||
private bool StartButtonClicked(GUIButton button, object obj)
|
||||
{
|
||||
GUIComponent listElement = itemList.GetChild(obj);
|
||||
if (fabricatedItem == null)
|
||||
{
|
||||
StartFabricating(obj as FabricableItem);
|
||||
|
||||
item.NewComponentEvent(this, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
CancelFabricating();
|
||||
|
||||
item.NewComponentEvent(this, true, true);
|
||||
}
|
||||
|
||||
listElement.Color = Color.Green;
|
||||
//listElement.Color = Color.Green;
|
||||
//itemList.Enabled = false;
|
||||
|
||||
//activateButton.Text = "Cancel";
|
||||
|
||||
//fabricatedItem = obj as FabricableItem;
|
||||
//IsActive = true;
|
||||
|
||||
//timeUntilReady = fabricatedItem.RequiredTime;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void StartFabricating(FabricableItem selectedItem)
|
||||
{
|
||||
if (selectedItem == null) return;
|
||||
|
||||
itemList.Enabled = false;
|
||||
|
||||
fabricatedItem = obj as FabricableItem;
|
||||
activateButton.Text = "Cancel";
|
||||
|
||||
fabricatedItem = selectedItem;
|
||||
IsActive = true;
|
||||
|
||||
timeUntilReady = fabricatedItem.RequiredTime;
|
||||
|
||||
return true;
|
||||
var containers = item.GetComponents<ItemContainer>();
|
||||
containers[0].Inventory.Locked = true;
|
||||
containers[1].Inventory.Locked = true;
|
||||
}
|
||||
|
||||
private void CancelFabricating()
|
||||
{
|
||||
itemList.Enabled = true;
|
||||
IsActive = false;
|
||||
fabricatedItem = null;
|
||||
|
||||
if (activateButton != null)
|
||||
{
|
||||
activateButton.Text = "Create";
|
||||
}
|
||||
if (progressBar != null) progressBar.BarSize = 0.0f;
|
||||
|
||||
timeUntilReady = 0.0f;
|
||||
|
||||
var containers = item.GetComponents<ItemContainer>();
|
||||
containers[0].Inventory.Locked = false;
|
||||
containers[1].Inventory.Locked = false;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
timeUntilReady -= deltaTime;
|
||||
|
||||
if (progressBar!=null)
|
||||
{
|
||||
progressBar.BarSize = fabricatedItem == null ? 0.0f : (fabricatedItem.RequiredTime - timeUntilReady) / fabricatedItem.RequiredTime;
|
||||
}
|
||||
|
||||
if (timeUntilReady > 0.0f) return;
|
||||
|
||||
var containers = item.GetComponents<ItemContainer>();
|
||||
@@ -180,9 +242,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
Item.Spawner.QueueItem(fabricatedItem.TargetItem, containers[1].Inventory);
|
||||
|
||||
itemList.Enabled = true;
|
||||
IsActive = false;
|
||||
fabricatedItem = null;
|
||||
CancelFabricating();
|
||||
}
|
||||
|
||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||
@@ -190,13 +250,13 @@ namespace Barotrauma.Items.Components
|
||||
FabricableItem targetItem = itemList.SelectedData as FabricableItem;
|
||||
if (targetItem != null)
|
||||
{
|
||||
selectedItemFrame.GetChild<GUIButton>().Enabled = true;
|
||||
activateButton.Enabled = true;
|
||||
|
||||
ItemContainer container = item.GetComponent<ItemContainer>();
|
||||
foreach (ItemPrefab ip in targetItem.RequiredItems)
|
||||
{
|
||||
if (Array.Find(container.Inventory.Items, it => it != null && it.Prefab == ip) != null) continue;
|
||||
selectedItemFrame.GetChild<GUIButton>().Enabled = false;
|
||||
activateButton.Enabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -213,5 +273,39 @@ namespace Barotrauma.Items.Components
|
||||
// selectedItemFrame.Draw(spriteBatch);
|
||||
//}
|
||||
}
|
||||
|
||||
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
|
||||
{
|
||||
int itemIndex = fabricatedItem == null ? -1 : fabricableItems.IndexOf(fabricatedItem);
|
||||
|
||||
message.WriteRangedInteger(-1, fabricableItems.Count-1, itemIndex);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message, float sendingTime)
|
||||
{
|
||||
if (sendingTime < lastNetworkUpdate) return;
|
||||
|
||||
int itemIndex = message.ReadRangedInteger(-1, fabricableItems.Count-1);
|
||||
|
||||
if (itemIndex == -1)
|
||||
{
|
||||
CancelFabricating();
|
||||
}
|
||||
else
|
||||
{
|
||||
//if already fabricating the selected item, return
|
||||
if (fabricatedItem != null && fabricableItems.IndexOf(fabricatedItem) != itemIndex) return;
|
||||
|
||||
if (itemIndex < 0 || itemIndex >= fabricableItems.Count) return;
|
||||
|
||||
SelectItem(null, fabricableItems[itemIndex]);
|
||||
StartFabricating(fabricableItems[itemIndex]);
|
||||
timeUntilReady -= sendingTime - (float)Lidgren.Network.NetTime.Now;
|
||||
}
|
||||
|
||||
lastNetworkUpdate = sendingTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
float lastUpdate;
|
||||
|
||||
Hull hull1, hull2;
|
||||
Hull hull1;
|
||||
|
||||
[HasDefaultValue(0.0f, true)]
|
||||
public float FlowPercentage
|
||||
@@ -82,7 +82,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
|
||||
|
||||
if (hull2 == null && hull1 == null) return;
|
||||
if (hull1 == null) return;
|
||||
|
||||
float powerFactor = (currPowerConsumption==0.0f) ? 1.0f : voltage;
|
||||
//flowPercentage = maxFlow * powerFactor;
|
||||
@@ -92,11 +92,11 @@ namespace Barotrauma.Items.Components
|
||||
hull1.Volume += currFlow;
|
||||
if (hull1.Volume > hull1.FullVolume) hull1.Pressure += 0.5f;
|
||||
|
||||
if (hull2 != null)
|
||||
{
|
||||
hull2.Volume -= currFlow;
|
||||
if (hull2.Volume > hull1.FullVolume) hull2.Pressure += 0.5f;
|
||||
}
|
||||
//if (hull2 != null)
|
||||
//{
|
||||
// hull2.Volume -= currFlow;
|
||||
// if (hull2.Volume > hull1.FullVolume) hull2.Pressure += 0.5f;
|
||||
//}
|
||||
|
||||
voltage = 0.0f;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Barotrauma
|
||||
private static void CreateGUIFrame(Item item)
|
||||
{
|
||||
int width = 400, height = 500;
|
||||
int x = 0, y = 0;
|
||||
int y = 0;
|
||||
|
||||
frame = new GUIFrame(new Rectangle(0, 0, width, height), null, Alignment.Center, GUI.Style);
|
||||
frame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
|
||||
|
||||
@@ -228,7 +228,7 @@ namespace Barotrauma
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (GameMain.DebugDraw) ? Name +"(ID: "+ID+")" : Name;
|
||||
return (GameMain.DebugDraw) ? Name + "(ID: " + ID + ")" : Name;
|
||||
}
|
||||
|
||||
public List<IPropertyObject> AllPropertyObjects
|
||||
|
||||
@@ -15,8 +15,14 @@ namespace Barotrauma
|
||||
spawnQueue = new Queue<Pair<ItemPrefab, object>>();
|
||||
}
|
||||
|
||||
public void QueueItem(ItemPrefab itemPrefab, Vector2 position)
|
||||
public void QueueItem(ItemPrefab itemPrefab, Vector2 position, bool isNetworkMessage = false)
|
||||
{
|
||||
if (!isNetworkMessage && GameMain.Client!=null)
|
||||
{
|
||||
//clients aren't allowed to spawn new items unless the server says so
|
||||
return;
|
||||
}
|
||||
|
||||
var itemInfo = new Pair<ItemPrefab, object>();
|
||||
itemInfo.First = itemPrefab;
|
||||
itemInfo.Second = position;
|
||||
@@ -24,8 +30,14 @@ namespace Barotrauma
|
||||
spawnQueue.Enqueue(itemInfo);
|
||||
}
|
||||
|
||||
public void QueueItem(ItemPrefab itemPrefab, Inventory inventory)
|
||||
public void QueueItem(ItemPrefab itemPrefab, Inventory inventory, bool isNetworkMessage = false)
|
||||
{
|
||||
if (!isNetworkMessage && GameMain.Client != null)
|
||||
{
|
||||
//clients aren't allowed to spawn new items unless the server says so
|
||||
return;
|
||||
}
|
||||
|
||||
var itemInfo = new Pair<ItemPrefab, object>();
|
||||
itemInfo.First = itemPrefab;
|
||||
itemInfo.Second = inventory;
|
||||
@@ -35,24 +47,91 @@ namespace Barotrauma
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!spawnQueue.Any()) return;
|
||||
|
||||
List<Item> items = new List<Item>();
|
||||
List<Inventory> inventories = new List<Inventory>();
|
||||
|
||||
while (spawnQueue.Count>0)
|
||||
{
|
||||
var itemInfo = spawnQueue.Dequeue();
|
||||
|
||||
if (itemInfo.Second is Vector2)
|
||||
{
|
||||
new Item(itemInfo.First, (Vector2)itemInfo.Second - Submarine.HiddenSubPosition, null);
|
||||
Vector2 position = (Vector2)itemInfo.Second - Submarine.HiddenSubPosition;
|
||||
|
||||
items.Add(new Item(itemInfo.First, position, null));
|
||||
inventories.Add(null);
|
||||
|
||||
}
|
||||
else if (itemInfo.Second is Inventory)
|
||||
{
|
||||
|
||||
var item = new Item(itemInfo.First, Vector2.Zero, null);
|
||||
|
||||
var inventory = itemInfo.Second as Inventory;
|
||||
inventory.TryPutItem(item, null, false);
|
||||
|
||||
items.Add(item);
|
||||
inventories.Add(inventory);
|
||||
}
|
||||
//!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
}
|
||||
|
||||
if (GameMain.Server != null) GameMain.Server.SendItemSpawnMessage(items, inventories);
|
||||
}
|
||||
|
||||
public void FillNetworkData(Lidgren.Network.NetBuffer message, List<Item> items, List<Inventory> inventories)
|
||||
{
|
||||
message.Write((byte)items.Count);
|
||||
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
message.Write(items[i].Prefab.Name);
|
||||
message.Write(items[i].ID);
|
||||
|
||||
message.Write(inventories[i].Owner == null ? 0 : inventories[i].Owner.ID);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadNetworkData(Lidgren.Network.NetBuffer message)
|
||||
{
|
||||
var itemCount = message.ReadByte();
|
||||
for (int i = 0; i < itemCount; i++)
|
||||
{
|
||||
string itemName = message.ReadString();
|
||||
ushort itemId = message.ReadUInt16();
|
||||
|
||||
ushort inventoryId = message.ReadUInt16();
|
||||
|
||||
|
||||
var prefab = MapEntityPrefab.list.Find(me => me.Name == itemName);
|
||||
if (prefab == null) continue;
|
||||
|
||||
var itemPrefab = prefab as ItemPrefab;
|
||||
if (itemPrefab == null) continue;
|
||||
|
||||
Inventory inventory = null;
|
||||
|
||||
var inventoryOwner = Entity.FindEntityByID(inventoryId);
|
||||
if (inventoryOwner != null)
|
||||
{
|
||||
if (inventoryOwner is Character)
|
||||
{
|
||||
inventory = (inventoryOwner as Character).Inventory;
|
||||
}
|
||||
else if (inventoryOwner is Item)
|
||||
{
|
||||
var containers = (inventoryOwner as Item).GetComponents<Items.Components.ItemContainer>();
|
||||
if (containers!=null && containers.Any())
|
||||
{
|
||||
inventory = containers.Last().Inventory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var item = new Item(itemPrefab, Vector2.Zero, null);
|
||||
item.ID = itemId;
|
||||
if (inventory != null) inventory.TryPutItem(item, null, false);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,18 +145,55 @@ namespace Barotrauma
|
||||
removeQueue = new Queue<Item>();
|
||||
}
|
||||
|
||||
public void QueueItem(Item item)
|
||||
public void QueueItem(Item item, bool isNetworkMessage = false)
|
||||
{
|
||||
if (!isNetworkMessage && GameMain.Client != null)
|
||||
{
|
||||
//clients aren't allowed to remove items unless the server says so
|
||||
return;
|
||||
}
|
||||
|
||||
removeQueue.Enqueue(item);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!removeQueue.Any()) return;
|
||||
|
||||
List<Item> items = new List<Item>();
|
||||
|
||||
while (removeQueue.Count > 0)
|
||||
{
|
||||
var item = removeQueue.Dequeue();
|
||||
|
||||
item.Remove();
|
||||
|
||||
items.Add(item);
|
||||
}
|
||||
|
||||
if (GameMain.Server != null) GameMain.Server.SendItemRemoveMessage(items);
|
||||
}
|
||||
|
||||
public void FillNetworkData(Lidgren.Network.NetBuffer message, List<Item> items)
|
||||
{
|
||||
message.Write((byte)items.Count);
|
||||
foreach (Item item in items)
|
||||
{
|
||||
message.Write(item.ID);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadNetworkData(Lidgren.Network.NetBuffer message)
|
||||
{
|
||||
var itemCount = message.ReadByte();
|
||||
for (int i = 0; i<itemCount; i++)
|
||||
{
|
||||
ushort itemId = message.ReadUInt16();
|
||||
|
||||
var item = MapEntity.FindEntityByID(itemId);
|
||||
if (item == null || item as Item != null) continue;
|
||||
|
||||
item.Remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,12 @@ namespace Barotrauma
|
||||
get { return fireSources; }
|
||||
}
|
||||
|
||||
public Hull(Rectangle rectangle)
|
||||
: this (rectangle, Submarine.Loaded)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Hull(Rectangle rectangle, Submarine submarine)
|
||||
: base (submarine)
|
||||
{
|
||||
|
||||
@@ -691,6 +691,9 @@ namespace Barotrauma
|
||||
if (triangles[i][0].Y == triangles[i][1].Y && triangles[i][0].Y == triangles[i][2].Y) continue;
|
||||
if (triangles[i][0].X == triangles[i][1].X && triangles[i][0].X == triangles[i][2].X) continue;
|
||||
|
||||
if (Vector2.DistanceSquared(triangles[i][0], triangles[i][1]) < 0.1f) continue;
|
||||
if (Vector2.DistanceSquared(triangles[i][1], triangles[i][2]) < 0.1f) continue;
|
||||
|
||||
Vertices bodyVertices = new Vertices(triangles[i]);
|
||||
FixtureFactory.AttachPolygon(bodyVertices, 5.0f, edgeBody);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
IPEndPoint = new System.Net.IPEndPoint(NetUtility.Resolve(serverIP), Port);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch
|
||||
{
|
||||
new GUIMessageBox("Could not connect to server", "Failed to resolve address ''"+serverIP+":"+Port+"''. Please make sure you have entered a valid IP address.");
|
||||
return;
|
||||
@@ -519,6 +519,12 @@ namespace Barotrauma.Networking
|
||||
case (byte)PacketTypes.VoteStatus:
|
||||
Voting.ReadData(inc);
|
||||
break;
|
||||
case (byte)PacketTypes.NewItem:
|
||||
Item.Spawner.ReadNetworkData(inc);
|
||||
break;
|
||||
case (byte)PacketTypes.RemoveItem:
|
||||
Item.Remover.ReadNetworkData(inc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1264,6 +1264,29 @@ namespace Barotrauma.Networking
|
||||
message.Write(character.Info.Job.Name);
|
||||
}
|
||||
|
||||
public void SendItemSpawnMessage(List<Item> items, List<Inventory> inventories = null)
|
||||
{
|
||||
if (items == null || !items.Any()) return;
|
||||
|
||||
NetOutgoingMessage message = server.CreateMessage();
|
||||
message.Write((byte)PacketTypes.NewItem);
|
||||
|
||||
Item.Spawner.FillNetworkData(message, items, inventories);
|
||||
|
||||
SendMessage(message, NetDeliveryMethod.ReliableUnordered);
|
||||
}
|
||||
|
||||
public void SendItemRemoveMessage(List<Item> items)
|
||||
{
|
||||
if (items == null || !items.Any()) return;
|
||||
|
||||
NetOutgoingMessage message = server.CreateMessage();
|
||||
|
||||
Item.Remover.FillNetworkData(message, items);
|
||||
|
||||
SendMessage(message, NetDeliveryMethod.ReliableUnordered);
|
||||
}
|
||||
|
||||
private void AssignJobs()
|
||||
{
|
||||
List<Client> unassigned = new List<Client>(ConnectedClients);
|
||||
@@ -1305,16 +1328,7 @@ namespace Barotrauma.Networking
|
||||
if (assignedClientCount[i] < JobPrefab.List[i].MinNumber) unassignedJobsFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
//share the rest of the jobs according to the ''commonness'' of the job
|
||||
//float totalCommonness = 0.0f;
|
||||
//for (int i = 0; i < JobPrefab.List.Count; i++)
|
||||
//{
|
||||
// if (JobPrefab.List[i].AllowAlways || JobPrefab.List[i].MaxNumber == 0) continue;
|
||||
|
||||
// totalCommonness += JobPrefab.List[i].Commonness;
|
||||
//}
|
||||
|
||||
|
||||
//find a suitable job for the rest of the players
|
||||
for (int i = unassigned.Count - 1; i >= 0; i--)
|
||||
{
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
catch
|
||||
{
|
||||
int afghj = 1;
|
||||
|
||||
}
|
||||
//+1 because msgLength is one additional byte
|
||||
currPos += msgLength + 1;
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
StartGame, EndGame,
|
||||
|
||||
NewItem, RemoveItem,
|
||||
|
||||
CharacterInfo,
|
||||
|
||||
Chatmessage, UpdateNetLobby,
|
||||
|
||||
Reference in New Issue
Block a user