Item.Container bugfix (affected at least railguns in MP), merged the "your crew has died" message box with shiftsummary, reliable reactor syncing, prevent artifacts dropping out of the level

This commit is contained in:
Regalis
2016-01-12 01:02:05 +02:00
parent 64e62545a5
commit 5513637fe5
21 changed files with 132 additions and 89 deletions

View File

@@ -52,7 +52,7 @@ namespace Barotrauma
return;
}
if (container.Item.inventory == character.Inventory)
if (container.Item.Inventory == character.Inventory)
{
var containedItems = container.Inventory.Items;
//if there's already something in the mask (empty oxygen tank?), drop it

View File

@@ -102,8 +102,8 @@ namespace Barotrauma
currSearchIndex++;
if (!Item.ItemList[currSearchIndex].HasTag(itemName) && Item.ItemList[currSearchIndex].Name != itemName) continue;
if (IgnoreContainedItems && Item.ItemList[currSearchIndex].container != null) continue;
if (Item.ItemList[currSearchIndex].inventory is CharacterInventory) continue;
if (IgnoreContainedItems && Item.ItemList[currSearchIndex].Container != null) continue;
if (Item.ItemList[currSearchIndex].Inventory is CharacterInventory) continue;
targetItem = Item.ItemList[currSearchIndex];
@@ -119,9 +119,9 @@ namespace Barotrauma
private void AddGoToObjective(Item item)
{
Item moveToTarget = item;
while (moveToTarget.container != null)
while (moveToTarget.Container != null)
{
moveToTarget = moveToTarget.container;
moveToTarget = moveToTarget.Container;
}
AddSubObjective(new AIObjectiveGoTo(moveToTarget, character));

View File

@@ -968,7 +968,7 @@ namespace Barotrauma
{
if (!Enabled) return;
Vector2 pos = AnimController.Limbs[0].WorldPosition;
Vector2 pos = DrawPosition;
pos.Y = -pos.Y;
if (this == controlled) return;
@@ -992,7 +992,7 @@ namespace Barotrauma
if (isDead) return;
Vector2 healthBarPos = new Vector2(DrawPosition.X - 50, -DrawPosition.Y - 100.0f);
Vector2 healthBarPos = new Vector2(pos.X - 50, pos.Y - 100.0f);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X - 2, (int)healthBarPos.Y - 2, 100 + 4, 15 + 4), Color.Black, false);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)healthBarPos.X, (int)healthBarPos.Y, (int)(100.0f * (health / maxHealth)), 15), Color.Red, true);
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using System.Xml.Linq;
namespace Barotrauma
@@ -29,6 +30,7 @@ namespace Barotrauma
Vector2 position = level.PositionsOfInterest[Rand.Int(level.PositionsOfInterest.Count, false)];
monster = Character.Create(monsterFile, position);
monster.Enabled = false;
radarPosition = monster.Position;
}
@@ -37,7 +39,14 @@ namespace Barotrauma
switch (state)
{
case 0:
if (monster.Enabled) radarPosition = monster.Position;
if (monster.Enabled)
{
radarPosition = monster.Position;
}
else
{ Vector2 diff = monster.WorldPosition-Submarine.Loaded.WorldPosition;
monster.Enabled = FarseerPhysics.ConvertUnits.ToSimUnits(diff.Length()) < NetConfig.CharacterIgnoreDistance;
}
if (!monster.IsDead) return;
ShowMessage(state);

View File

@@ -51,7 +51,7 @@ namespace Barotrauma
ConvertUnits.ToSimUnits(tryPos - Vector2.UnitY*level.Size.Y),
null, Physics.CollisionLevel) != null)
{
position = tryPos;
position = ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition);
break;
}
@@ -67,7 +67,7 @@ namespace Barotrauma
item = new Item(itemPrefab, position, null);
item.MoveWithLevel = true;
item.body.FarseerBody.GravityScale = 0.5f;
item.body.FarseerBody.IsKinematic = true;
//item.MoveWithLevel = true;
}
@@ -76,7 +76,10 @@ namespace Barotrauma
switch (state)
{
case 0:
//item.body.LinearVelocity = Vector2.Zero;
if (item.Inventory!=null) item.body.FarseerBody.IsKinematic = false;
if (item.CurrentHull == null) return;
ShowMessage(state);
state = 1;
break;

View File

@@ -204,15 +204,39 @@ namespace Barotrauma
}
else
{
var msgBox = new GUIMessageBox("Game over", "Your entire crew has died!", new string[] { "Load game", "Quit" });
msgBox.Buttons[0].OnClicked += GameMain.GameSession.LoadPrevious;
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked = GameMain.LobbyScreen.QuitToMainMenu;
msgBox.Buttons[1].OnClicked += msgBox.Close;
// var okButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Ok", Alignment.BottomRight, GUI.Style, summaryFrame.children[0]);
//okButton.OnClicked = (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Dequeue(); return true; };
// var msgBox = new GUIMessageBox("Game over", "Your entire crew has died!", new string[] { "Load game", "Quit" });
// msgBox.Buttons[0].OnClicked += GameMain.GameSession.LoadPrevious;
// msgBox.Buttons[0].OnClicked += msgBox.Close;
// msgBox.Buttons[1].OnClicked = GameMain.LobbyScreen.QuitToMainMenu;
// msgBox.Buttons[1].OnClicked += msgBox.Close;
}
GameMain.GameSession.EndShift("");
if (!success)
{
var summaryScreen = GUIMessageBox.MessageBoxes.Peek();
if (summaryScreen != null)
{
summaryScreen = summaryScreen.children[0];
summaryScreen.RemoveChild(summaryScreen.children.Find(c => c is GUIButton));
var okButton = new GUIButton(new Rectangle(-120, 0, 100, 30), "Load game", Alignment.BottomRight, GUI.Style, summaryScreen);
okButton.OnClicked += GameMain.GameSession.LoadPrevious;
okButton.OnClicked += (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Dequeue(); return true; };
var quitButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Quit", Alignment.BottomRight, GUI.Style, summaryScreen);
quitButton.OnClicked += GameMain.LobbyScreen.QuitToMainMenu;
quitButton.OnClicked += (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Dequeue(); return true; };
}
}
CrewManager.EndShift();
for (int i = Character.CharacterList.Count - 1; i >= 0; i--)
{

View File

@@ -95,7 +95,7 @@ namespace Barotrauma
int x = 0;
foreach (Character character in gameSession.CrewManager.characters)
{
var characterFrame = new GUIFrame(new Rectangle(x, y, 170, 70), character.IsDead ? Color.DarkRed * 0.7f : Color.Transparent, GUI.Style, listBox);
var characterFrame = new GUIFrame(new Rectangle(x, y, 170, 70), Color.Transparent, GUI.Style, listBox);
characterFrame.OutlineColor = Color.Transparent;
characterFrame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
characterFrame.CanBeFocused = false;

View File

@@ -162,7 +162,7 @@ namespace Barotrauma
System.Diagnostics.Debug.Assert(false);
return false;
}
Inventory otherInventory = Items[index].inventory;
Inventory otherInventory = Items[index].Inventory;
if (otherInventory != null && createNetworkEvent)
{
new Networking.NetworkEvent(Networking.NetworkEventType.InventoryUpdate, otherInventory.Owner.ID, true, true);
@@ -213,7 +213,7 @@ namespace Barotrauma
string toolTip = "";
Rectangle highlightedSlot = Rectangle.Empty;
if (doubleClickedItem!=null && doubleClickedItem.inventory!=this)
if (doubleClickedItem!=null && doubleClickedItem.Inventory!=this)
{
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots, true);
}

View File

@@ -222,7 +222,7 @@ namespace Barotrauma.Items.Components
IsActive = true;
if (hideItems || (item.body!=null && !item.body.Enabled)) item.body.Enabled = false;
item.container = this.item;
//item.Container = this.item;
return true;
}

View File

@@ -10,6 +10,8 @@ namespace Barotrauma.Items.Components
{
class Reactor : Powered
{
const float NetworkUpdateInterval = 3.0f;
//the rate at which the reactor is being run un
//higher rates generate more power (and heat)
private float fissionRate;
@@ -50,6 +52,9 @@ namespace Barotrauma.Items.Components
private PropertyTask powerUpTask;
private bool unsentChanges;
private float sendUpdateTimer;
[Editable, HasDefaultValue(9500.0f, true)]
public float MeltDownTemp
{
@@ -248,6 +253,15 @@ namespace Barotrauma.Items.Components
AvailableFuel = 0.0f;
item.SendSignal(((int)temperature).ToString(), "temperature_out");
sendUpdateTimer = Math.Max(sendUpdateTimer - deltaTime, 0.0f);
if (unsentChanges && sendUpdateTimer<= 0.0f)
{
item.NewComponentEvent(this, true, true);
sendUpdateTimer = NetworkUpdateInterval;
unsentChanges = false;
}
}
public override void UpdateBroken(float deltaTime, Camera cam)
@@ -353,9 +367,7 @@ namespace Barotrauma.Items.Components
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
IsActive = true;
bool valueChanged = false;
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
int x = GuiFrame.Rect.X;
int y = GuiFrame.Rect.Y;
@@ -380,12 +392,12 @@ namespace Barotrauma.Items.Components
spriteBatch.DrawString(GUI.Font, "Shutdown Temperature: " + shutDownTemp, new Vector2(x + 450, y + 80), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 450, y + 110, 40, 40), "+", true))
{
valueChanged = true;
unsentChanges = true;
ShutDownTemp += 100.0f;
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 500, y + 110, 40, 40), "-", true))
{
valueChanged = true;
unsentChanges = true;
ShutDownTemp -= 100.0f;
}
@@ -393,7 +405,7 @@ namespace Barotrauma.Items.Components
spriteBatch.DrawString(GUI.Font, "Automatic Temperature Control: " + ((autoTemp) ? "ON" : "OFF"), new Vector2(x + 450, y + 180), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 450, y + 210, 100, 40), ((autoTemp) ? "TURN OFF" : "TURN ON")))
{
valueChanged = true;
unsentChanges = true;
autoTemp = !autoTemp;
}
@@ -407,12 +419,12 @@ namespace Barotrauma.Items.Components
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 30, 40, 40), "+", true))
{
valueChanged = true;
unsentChanges = true;
FissionRate += 1.0f;
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 80, 40, 40), "-", true))
{
valueChanged = true;
unsentChanges = true;
FissionRate -= 1.0f;
}
@@ -422,21 +434,17 @@ namespace Barotrauma.Items.Components
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 540, y + 30, 40, 40), "+", true))
{
valueChanged = true;
unsentChanges = true;
CoolingRate += 1.0f;
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 540, y + 80, 40, 40), "-", true))
{
valueChanged = true;
unsentChanges = true;
CoolingRate -= 1.0f;
}
//y = y - 260;
if (valueChanged)
{
item.NewComponentEvent(this, true, false);
}
}
static void UpdateGraph<T>(IList<T> graph, T newValue)

View File

@@ -122,7 +122,7 @@ namespace Barotrauma.Items.Components
}
currPowerConsumption = MathHelper.Lerp(currPowerConsumption, rechargeSpeed, 0.05f);
charge += currPowerConsumption*voltage / 3600.0f;
Charge += currPowerConsumption*voltage / 3600.0f;
}
//provide power to the grid
else if (gridLoad > 0.0f)

View File

@@ -100,7 +100,7 @@ namespace Barotrauma.Items.Components
light.Submarine = item.CurrentHull.Submarine;
}
if (item.container != null)
if (item.Container != null)
{
light.Color = Color.Transparent;
return;

View File

@@ -133,7 +133,7 @@ namespace Barotrauma.Items.Components
if (ic == this) continue;
ic.Drop(null);
}
if (item.container != null) item.container.RemoveContained(this.item);
if (item.Container != null) item.Container.RemoveContained(this.item);
item.body.Enabled = false;

View File

@@ -156,7 +156,7 @@ namespace Barotrauma.Items.Components
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y)), -rotation);
projectiles[0].Use(deltaTime);
if (projectile.container != null) projectile.container.RemoveContained(projectile);
if (projectile.Container != null) projectile.Container.RemoveContained(projectile);
return true;
}

View File

@@ -125,11 +125,11 @@ namespace Barotrauma
if (removeItem)
{
item.Drop(null, false);
if (item.inventory != null) item.inventory.RemoveItem(item);
if (item.Inventory != null) item.Inventory.RemoveItem(item);
}
Items[i] = item;
item.inventory = this;
item.Inventory = this;
if (item.body != null)
{
item.body.Enabled = false;
@@ -152,7 +152,7 @@ namespace Barotrauma
{
if (Items[n] != item) continue;
Items[n] = null;
item.inventory = null;
item.Inventory = null;
}
}
@@ -201,7 +201,7 @@ namespace Barotrauma
}
}
if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition) && draggingItem.container == this.Owner)
if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition) && draggingItem.Container == this.Owner)
{
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
{

View File

@@ -61,11 +61,29 @@ namespace Barotrauma
private bool inWater;
//the inventory in which the item is contained in
public Inventory inventory;
private Inventory inventory;
//the inventory in which the item is contained in
public Inventory Inventory
{
get
{
return inventory;
}
set
{
inventory = value;
if (inventory != null) Container = inventory.Owner as Item;
}
}
public Item Container
{
get;
private set;
}
public Item container;
public List<FixRequirement> FixRequirements;
public override string Name
@@ -354,7 +372,7 @@ namespace Barotrauma
if (c == null) return;
c.RemoveContained(contained);
contained.container = null;
contained.Container = null;
}
@@ -517,7 +535,7 @@ namespace Barotrauma
//effect.Apply(type, deltaTime, null, Character);
//ApplyStatusEffect(effect, type, deltaTime, null, Character, limb);
if (container != null && effect.Targets.HasFlag(StatusEffect.TargetType.Parent)) targets.Add(container);
if (Container != null && effect.Targets.HasFlag(StatusEffect.TargetType.Parent)) targets.Add(Container);
//{
// effect.Apply(type, deltaTime, container);
// //container.ApplyStatusEffect(effect, type, deltaTime, container);
@@ -558,7 +576,7 @@ namespace Barotrauma
}
ic.WasUsed = false;
if (container != null) ic.ApplyStatusEffects(ActionType.OnContained, deltaTime);
if (Container != null) ic.ApplyStatusEffects(ActionType.OnContained, deltaTime);
if (!ic.IsActive) continue;
@@ -1005,7 +1023,7 @@ namespace Barotrauma
}
}
if (container!=null) container.RemoveContained(this);
if (Container!=null) Container.RemoveContained(this);
return true;
}
@@ -1079,7 +1097,7 @@ namespace Barotrauma
foreach (ItemComponent ic in components) ic.Drop(dropper);
if (container != null) container.RemoveContained(this);
if (Container != null) Container.RemoveContained(this);
}
public void Equip(Character character)

View File

@@ -57,7 +57,7 @@ namespace Barotrauma
item.Unequip(c);
break;
}
item.container = container.Item;
//item.Container = container.Item;
container.IsActive = true;
}
return wasPut;

View File

@@ -233,7 +233,7 @@ namespace Barotrauma
foreach (Item item in Item.ItemList)
{
if (item.CurrentHull != hull || item.FireProof || item.Condition <= 0.0f) continue;
if (item.inventory != null) return;
if (item.Inventory != null) return;
float range = (float)Math.Sqrt(size.X) * 10.0f;
if (item.Position.X < position.X - range || item.Position.X > position.X + size.X + range) continue;

View File

@@ -609,49 +609,29 @@ namespace Barotrauma.Networking
float endPreviewLength = 10.0f;
var cinematic = new TransitionCinematic(Submarine.Loaded, GameMain.GameScreen.Cam, endPreviewLength);
float secondsLeft = endPreviewLength;
do
if (Screen.Selected == GameMain.GameScreen)
{
secondsLeft -= CoroutineManager.DeltaTime;
var cinematic = new TransitionCinematic(Submarine.Loaded, GameMain.GameScreen.Cam, endPreviewLength);
//float camAngle = (float)((DateTime.Now - endTime).TotalSeconds / endPreviewLength) * MathHelper.TwoPi;
//Vector2 offset = (new Vector2(
// (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f),
// (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f)));
float secondsLeft = endPreviewLength;
//GameMain.GameScreen.Cam.TargetPos = Submarine.Loaded.Position + offset * 0.8f;
//Game1.GameScreen.Cam.MoveCamera((float)deltaTime);
do
{
secondsLeft -= CoroutineManager.DeltaTime;
//messageBox.Text = endMessage + "\nReturning to lobby in " + (int)secondsLeft + " s";
//float camAngle = (float)((DateTime.Now - endTime).TotalSeconds / endPreviewLength) * MathHelper.TwoPi;
//Vector2 offset = (new Vector2(
// (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f),
// (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f)));
yield return CoroutineStatus.Running;
} while (secondsLeft > 0.0f);
//GameMain.GameScreen.Cam.TargetPos = Submarine.Loaded.Position + offset * 0.8f;
//Game1.GameScreen.Cam.MoveCamera((float)deltaTime);
//float endPreviewLength = 10.0f;
//messageBox.Text = endMessage + "\nReturning to lobby in " + (int)secondsLeft + " s";
//DateTime endTime = DateTime.Now + new TimeSpan(0,0,0,0,(int)(1000.0f*endPreviewLength));
//float secondsLeft = endPreviewLength;
//do
//{
// secondsLeft = (float)(endTime - DateTime.Now).TotalSeconds;
// float camAngle = (float)((DateTime.Now - endTime).TotalSeconds / endPreviewLength) * MathHelper.TwoPi;
// Vector2 offset = (new Vector2(
// (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f),
// (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f)));
// GameMain.GameScreen.Cam.TargetPos = Submarine.Loaded.DrawPosition + offset * 0.8f;
// //Game1.GameScreen.Cam.MoveCamera((float)deltaTime);
// messageBox.Text = endMessage + "\nReturning to lobby in " + (int)secondsLeft + " s";
// yield return CoroutineStatus.Running;
//} while (secondsLeft > 0.0f);
//messageBox.Close(null,null);
yield return CoroutineStatus.Running;
} while (secondsLeft > 0.0f);
}
Submarine.Unload();

View File

@@ -90,6 +90,7 @@ namespace Barotrauma.Networking
GUIFrame innerFrame = new GUIFrame(new Rectangle(0,0,400,400), null, Alignment.Center, GUI.Style, settingsFrame);
var randomizeLevelBox = new GUITickBox(new Rectangle(0, 0, 20, 20), "Randomize level seed", Alignment.Left, innerFrame);
randomizeLevelBox.Selected = randomizeSeed;
randomizeLevelBox.OnSelected = ToggleRandomizeSeed;
new GUITextBlock(new Rectangle(0, 35, 100, 20), "Submarine selection:", GUI.Style, innerFrame);

Binary file not shown.