diff --git a/Subsurface/Characters/StatusEffect.cs b/Subsurface/Characters/StatusEffect.cs index e7c504e4c..c1744171f 100644 --- a/Subsurface/Characters/StatusEffect.cs +++ b/Subsurface/Characters/StatusEffect.cs @@ -150,7 +150,7 @@ namespace Subsurface public virtual void Apply(ActionType type, float deltaTime, Vector2 position, IPropertyObject target) { - if (!targetNames.Contains(target.Name)) return; + if (targetNames == null && !targetNames.Contains(target.Name)) return; List targets = new List(); targets.Add(target); diff --git a/Subsurface/Content/Items/Reactor/reactor.xml b/Subsurface/Content/Items/Reactor/reactor.xml index 15ad3cfef..bd432f5cb 100644 --- a/Subsurface/Content/Items/Reactor/reactor.xml +++ b/Subsurface/Content/Items/Reactor/reactor.xml @@ -3,8 +3,20 @@ name="Nuclear Reactor" type ="Reactor" linkable="true"> + + + + + + + + + + + + diff --git a/Subsurface/Content/Items/Tools/tools.xml b/Subsurface/Content/Items/Tools/tools.xml index 6bcfc97f2..a94b1d709 100644 --- a/Subsurface/Content/Items/Tools/tools.xml +++ b/Subsurface/Content/Items/Tools/tools.xml @@ -17,6 +17,12 @@ + + + + + + @@ -44,6 +50,12 @@ + + + + + + diff --git a/Subsurface/Content/Items/Weapons/weapons.xml b/Subsurface/Content/Items/Weapons/weapons.xml index 654824ded..0af72d864 100644 --- a/Subsurface/Content/Items/Weapons/weapons.xml +++ b/Subsurface/Content/Items/Weapons/weapons.xml @@ -30,7 +30,7 @@ - + diff --git a/Subsurface/GUI/GUITextBlock.cs b/Subsurface/GUI/GUITextBlock.cs index 96004c4d6..935f645eb 100644 --- a/Subsurface/GUI/GUITextBlock.cs +++ b/Subsurface/GUI/GUITextBlock.cs @@ -54,6 +54,7 @@ namespace Subsurface public Color TextColor { get { return textColor; } + set { textColor = value; } } public Vector2 CaretPos @@ -64,16 +65,12 @@ namespace Subsurface public GUITextBlock(Rectangle rect, string text, GUIStyle style, GUIComponent parent = null, bool wrap = false) : this(rect, text, style, Alignment.TopLeft, Alignment.TopLeft, parent, wrap) { - //hoverColor = style.hoverColor; - //selectedColor = style.selectedColor; } public GUITextBlock(Rectangle rect, string text, GUIStyle style, Alignment alignment = Alignment.TopLeft, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null, bool wrap = false) : this (rect, text, null, null, alignment, textAlignment, style, parent, wrap) { - //hoverColor = style.hoverColor; - //selectedColor = style.selectedColor; } public GUITextBlock(Rectangle rect, string text, Color? color, Color? textColor, Alignment textAlignment = Alignment.Left, GUIStyle style = null, GUIComponent parent = null, bool wrap = false) diff --git a/Subsurface/GUI/GUITickBox.cs b/Subsurface/GUI/GUITickBox.cs index 6e0a9fe8c..ffa74fb80 100644 --- a/Subsurface/GUI/GUITickBox.cs +++ b/Subsurface/GUI/GUITickBox.cs @@ -12,7 +12,18 @@ namespace Subsurface public delegate bool OnSelectedHandler(object obj); public OnSelectedHandler OnSelected; - bool selected; + private bool selected; + + public bool Selected + { + get { return selected; } + set + { + if (value == selected) return; + selected = value; + state = (selected) ? ComponentState.Selected : ComponentState.None; + } + } public GUITickBox(Rectangle rect, string label, Alignment alignment, GUIComponent parent) : base(null) @@ -20,8 +31,11 @@ namespace Subsurface if (parent != null) parent.AddChild(this); - box = new GUIFrame(new Rectangle(rect.X, rect.Y, 30, 30), Color.LightGray, null, this); - text = new GUITextBlock(new Rectangle(rect.X + 40, rect.Y, 200, 30), label, Color.Transparent, Color.White, Alignment.Left | Alignment.CenterY, null, this); + box = new GUIFrame(rect, Color.DarkGray, null, this); + box.HoverColor = Color.Gray; + box.SelectedColor = Color.DarkGray; + + text = new GUITextBlock(new Rectangle(rect.X + 40, rect.Y, 200, 30), label, Color.Transparent, Color.White, Alignment.TopLeft, null, this); } public override void Update(float deltaTime) @@ -33,28 +47,31 @@ namespace Subsurface box.State = ComponentState.Hover; if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) - box.State = ComponentState.Selected; + { + box.State = ComponentState.Selected; + } + if (PlayerInput.LeftButtonClicked()) { - selected = !selected; + Selected = !Selected; if (OnSelected != null) OnSelected(this); } - } else { box.State = ComponentState.None; } + } public override void Draw(SpriteBatch spriteBatch) { DrawChildren(spriteBatch); - if (selected) + if (Selected) { - GUI.DrawRectangle(spriteBatch, new Rectangle(box.Rect.X + 5, box.Rect.Y + 5, box.Rect.Width - 10, box.Rect.Height - 10), Color.Green * (color.A / 255.0f), true); + GUI.DrawRectangle(spriteBatch, new Rectangle(box.Rect.X + 2, box.Rect.Y + 2, box.Rect.Width - 4, box.Rect.Height - 4), Color.Green * 0.8f, true); } } } diff --git a/Subsurface/Items/Components/Holdable/RangedWeapon.cs b/Subsurface/Items/Components/Holdable/RangedWeapon.cs index 98622a207..05cbb0559 100644 --- a/Subsurface/Items/Components/Holdable/RangedWeapon.cs +++ b/Subsurface/Items/Components/Holdable/RangedWeapon.cs @@ -57,7 +57,7 @@ namespace Subsurface.Items.Components isActive = true; reload = 1.0f; - bool failed = UseFailed(character); + bool failed = DoesUseFail(character); List limbBodies = new List(); foreach (Limb l in character.AnimController.limbs) diff --git a/Subsurface/Items/Components/Holdable/RepairTool.cs b/Subsurface/Items/Components/Holdable/RepairTool.cs index 7cd21e7e8..98bb5e813 100644 --- a/Subsurface/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Items/Components/Holdable/RepairTool.cs @@ -93,6 +93,9 @@ namespace Subsurface.Items.Components public override bool Use(float deltaTime, Character character = null) { if (character == null) return false; + if (!character.SecondaryKeyDown.State) return false; + + if (DoesUseFail(character)) return false; isActive = true; diff --git a/Subsurface/Items/Components/ItemComponent.cs b/Subsurface/Items/Components/ItemComponent.cs index 048e61dba..cf2d7d63b 100644 --- a/Subsurface/Items/Components/ItemComponent.cs +++ b/Subsurface/Items/Components/ItemComponent.cs @@ -356,24 +356,39 @@ namespace Subsurface } public bool HasRequiredSkills(Character character) + { + Skill temp; + return HasRequiredSkills(character, out temp); + } + + public bool HasRequiredSkills(Character character, out Skill insufficientSkill) { foreach (Skill skill in requiredSkills) { int characterLevel = character.GetSkillLevel(skill.Name); - if (characterLevel < skill.Level) return false; + if (characterLevel < skill.Level) + { + insufficientSkill = skill; + return false; + } } - + insufficientSkill = null; return true; } - protected bool UseFailed(Character character) + protected bool DoesUseFail(Character character) { foreach (Skill skill in requiredSkills) { int characterLevel = character.GetSkillLevel(skill.Name); if (characterLevel > skill.Level) continue; - if (Rand.Int(characterLevel) - skill.Level < 0) return true; + if (Rand.Int(characterLevel) - skill.Level < 0) + { + item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, character); + //Item.ApplyStatusEffects(); + return true; + } } return false; diff --git a/Subsurface/Items/Components/Machines/Reactor.cs b/Subsurface/Items/Components/Machines/Reactor.cs index 5df26a393..bd2260e39 100644 --- a/Subsurface/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Items/Components/Machines/Reactor.cs @@ -308,7 +308,7 @@ namespace Subsurface.Items.Components float xOffset = (graphTimer / (float)updateGraphInterval); - GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); + //GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); spriteBatch.DrawString(GUI.Font, "Temperature: " + (int)temperature + " C", new Vector2(x + 30, y + 30), Color.White); DrawGraph(tempGraph, spriteBatch, x + 30, y + 50, 10000.0f, xOffset); diff --git a/Subsurface/Items/FixRequirement.cs b/Subsurface/Items/FixRequirement.cs new file mode 100644 index 000000000..f117b1b73 --- /dev/null +++ b/Subsurface/Items/FixRequirement.cs @@ -0,0 +1,186 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.Linq; + +namespace Subsurface +{ + class FixRequirement + { + string name; + + private static GUIFrame frame; + + List requiredSkills; + List requiredItems; + + public bool Fixed; + + public FixRequirement(XElement element) + { + name = ToolBox.GetAttributeString(element, "name", ""); + + requiredSkills = new List(); + requiredItems = new List(); + + foreach (XElement subElement in element.Elements()) + { + switch (subElement.Name.ToString().ToLower()) + { + case "skill": + string skillName = ToolBox.GetAttributeString(subElement, "name", ""); + int level = ToolBox.GetAttributeInt(subElement, "level", 1); + + requiredSkills.Add(new Skill(skillName, level)); + break; + case "item": + string itemName = ToolBox.GetAttributeString(subElement, "name", ""); + + requiredItems.Add(itemName); + break; + } + } + } + + public bool Fix(Character character, GUIComponent reqFrame) + { + bool success = true; + foreach (string itemName in requiredItems) + { + GUIComponent component = reqFrame.children.Find(c => c.UserData as string == itemName); + + GUITextBlock text = component as GUITextBlock; + bool itemFound = (character.Inventory.items.FirstOrDefault(i => i !=null && i.Name == itemName) != null); + + if (!itemFound) success = false; + + if (text != null) text.TextColor = itemFound ? Color.LightGreen : Color.Red; + } + + foreach (Skill skill in requiredSkills) + { + GUIComponent component = reqFrame.children.Find(c => c.UserData as Skill == skill); + GUITextBlock text = component as GUITextBlock; + + float characterSkill = character.GetSkillLevel(skill.Name); + bool sufficientSkill = characterSkill >= skill.Level; + + if (!sufficientSkill) success = false; + + if (text != null) text.TextColor = sufficientSkill ? Color.LightGreen : Color.Red; + } + + return success; + } + + private static void CreateGUIFrame(Item item) + { + int width = 400, height = 500; + int x = 0, y = 0; + + frame = new GUIFrame(new Rectangle(0, 0, width, height), Color.White * 0.8f, Alignment.Center, GUI.style); + frame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f); + frame.UserData = item; + + new GUITextBlock(new Rectangle(0,0,200,20), "Attempting to fix " + item.Name, GUI.style, frame); + + y = y + 40; + foreach (FixRequirement requirement in item.FixRequirements) + { + GUIFrame reqFrame = new GUIFrame( + new Rectangle(0, y, 0, 20 + Math.Max(requirement.requiredItems.Count, requirement.requiredSkills.Count) * 15), + Color.Transparent, null, frame); + reqFrame.UserData = requirement; + + + var fixButton = new GUIButton(new Rectangle(0, 0, 50, 20), "Fix", GUI.style, reqFrame); + fixButton.OnClicked = FixButtonPressed; + fixButton.UserData = requirement; + + new GUITickBox(new Rectangle(70, 0, 20,20), requirement.name, Alignment.Left, reqFrame); + + int y2 = 20; + foreach (string itemName in requirement.requiredItems) + { + var itemBlock = new GUITextBlock(new Rectangle(30, y2, 200, 15), itemName, GUI.style, reqFrame); + itemBlock.Font = GUI.SmallFont; + itemBlock.UserData = itemName; + + y2 += 15; + } + + y2 = 20; + foreach (Skill skill in requirement.requiredSkills) + { + var skillBlock = new GUITextBlock(new Rectangle(150, y2, 200, 15), skill.Name + " - " + skill.Level, GUI.style, Alignment.Right, Alignment.TopLeft, reqFrame); + skillBlock.Font = GUI.SmallFont; + skillBlock.UserData = skill; + + + y2 += 15; + } + + y += reqFrame.Rect.Height; + } + } + + private static bool FixButtonPressed(GUIButton button, object obj) + { + FixRequirement requirement = obj as FixRequirement; + if (requirement == null) return false; + + requirement.Fixed = true; + return true; + } + + private static void UpdateGUIFrame(Item item, Character character) + { + bool unfixedFound = false; + foreach (GUIComponent child in frame.children) + { + FixRequirement requirement = child.UserData as FixRequirement; + if (requirement == null) continue; + + if (requirement.Fixed) + { + child.Color = Color.LightGreen * 0.3f; + child.GetChild().Selected = true; + } + else + { + bool canBeFixed = requirement.Fix(character, child); + unfixedFound = true; + //child.GetChild().Selected = canBeFixed; + GUITickBox tickBox = child.GetChild(); + if (tickBox.Selected) + { + tickBox.Selected = canBeFixed; + requirement.Fixed = canBeFixed; + + } + child.Color = Color.Red * 0.2f; + //tickBox.State = GUIComponent.ComponentState.None; + } + } + if (!unfixedFound) + { + item.Condition = 100.0f; + } + } + + public static void DrawHud(SpriteBatch spriteBatch, Item item, Character character) + { + if (frame == null || frame.UserData != item) + { + CreateGUIFrame(item); + + } +UpdateGUIFrame(item, character); + frame.Update((float)Physics.step); + frame.Draw(spriteBatch); + } + } +} diff --git a/Subsurface/Items/Item.cs b/Subsurface/Items/Item.cs index 6c7c91fff..d9972f511 100644 --- a/Subsurface/Items/Item.cs +++ b/Subsurface/Items/Item.cs @@ -17,7 +17,7 @@ namespace Subsurface public enum ActionType { - OnPicked, OnWearing, OnContaining, OnContained, OnActive, OnUse + OnPicked, OnWearing, OnContaining, OnContained, OnActive, OnUse, OnFailure } class Item : MapEntity, IDamageable, IPropertyObject @@ -27,6 +27,7 @@ namespace Subsurface private List tags; + public Hull CurrentHull; //components that determine the functionality of the item @@ -47,6 +48,8 @@ namespace Subsurface public Item container; + public List FixRequirements; + public override string Name { get { return prefab.Name; } @@ -57,7 +60,6 @@ namespace Subsurface get { return prefab.sprite; } } - public float Condition { get { return condition; } @@ -69,6 +71,7 @@ namespace Subsurface get { return condition; } } + [Editable, HasDefaultValue("", true)] public string Tags { @@ -181,17 +184,13 @@ namespace Subsurface { prefab = itemPrefab; - linkedTo = new ObservableCollection(); - components = new List(); - - tags = new List(); + linkedTo = new ObservableCollection(); + components = new List(); + FixRequirements = new List(); + tags = new List(); rect = newRect; - //rect.X -= rect.Width / 2; - //rect.Y += rect.Height / 2; - - //dir = 1.0f; - + FindHull(); condition = 100.0f; @@ -210,21 +209,8 @@ namespace Subsurface } } - properties = ObjectProperty.InitProperties(this, element); - //foreach (XAttribute attribute in element.Attributes()) - //{ - // ObjectProperty property = null; - // if (!properties.TryGetValue(attribute.Name.ToString().ToLower(), out property)) continue; - // if (property.Attributes.OfType().Count() == 0) continue; - // property.TrySetValue(attribute.Value); - //} - - - - //highlightText = new List(); - foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLower()) @@ -240,6 +226,9 @@ namespace Subsurface aiTarget.SightRange = ToolBox.GetAttributeFloat(subElement, "sightrange", 1000.0f); aiTarget.SoundRange = ToolBox.GetAttributeFloat(subElement, "soundrange", 0.0f); break; + case "fixrequirement": + FixRequirements.Add(new FixRequirement(subElement)); + break; default: ItemComponent ic = ItemComponent.Load(subElement, this, prefab.ConfigFile); if (ic == null) break; @@ -638,16 +627,23 @@ namespace Subsurface public virtual void DrawHUD(SpriteBatch spriteBatch, Character character) { - if (editingHUD==null || editingHUD.UserData as Item != this) + if (condition>0.0f) { - editingHUD = CreateEditingHUD(true); + if (editingHUD==null || editingHUD.UserData as Item != this) + { + editingHUD = CreateEditingHUD(true); + } + + editingHUD.Draw(spriteBatch); + + foreach (ItemComponent ic in components) + { + ic.DrawHUD(spriteBatch, character); + } } - - editingHUD.Draw(spriteBatch); - - foreach (ItemComponent ic in components) + else { - ic.DrawHUD(spriteBatch, character); + FixRequirement.DrawHud(spriteBatch, this, character); } } @@ -730,9 +726,16 @@ namespace Subsurface bool hasRequiredSkills = true; bool picked = false, selected = false; + + Skill requiredSkill = null; + foreach (ItemComponent ic in components) { - if (!ic.HasRequiredSkills(picker)) hasRequiredSkills = false; + Skill tempRequiredSkill; + if (!ic.HasRequiredSkills(picker, out tempRequiredSkill)) hasRequiredSkills = false; + + if (tempRequiredSkill != null) requiredSkill = tempRequiredSkill; + if (!ic.HasRequiredItems(picker, picker == Character.Controlled) && !forcePick) continue; if ((ic.CanBePicked && ic.Pick(picker)) || (ic.CanBeSelected && ic.Select(picker))) { @@ -751,6 +754,10 @@ namespace Subsurface if (!hasRequiredSkills && Character.Controlled==picker) { GUI.AddMessage("Your skills may be insufficient to use the item!", Color.Red, 5.0f); + if (requiredSkill != null) + { + GUI.AddMessage("("+requiredSkill.Name+" level "+requiredSkill.Level+" required)", Color.Red, 5.0f); + } } if (container!=null) container.RemoveContained(this); diff --git a/Subsurface/Items/ItemPrefab.cs b/Subsurface/Items/ItemPrefab.cs index 8ed6b2518..b1a768580 100644 --- a/Subsurface/Items/ItemPrefab.cs +++ b/Subsurface/Items/ItemPrefab.cs @@ -25,9 +25,6 @@ namespace Subsurface //how close the character has to be to the item to pick it up private float pickDistance; - - //public List sounds; - //an area next to the construction //the construction can be Activated() by a character inside the area public List Triggers; @@ -144,40 +141,19 @@ namespace Subsurface name = ToolBox.GetAttributeString(element, "name", ""); if (name == "") DebugConsole.ThrowError("Unnamed item in "+filePath+"!"); - //if (element.Attribute("sprite") != null) - //{ - // sprite = new Sprite(Path.GetDirectoryName(filePath) + "/" + element.Attribute("sprite").Value, new Vector2(0.5f, 0.5f)); - // sprite.Depth = 0.5f; - //} - - //var initableProperties = GetProperties(); - //foreach (ObjectProperty initableProperty in initableProperties) - //{ - // object value = ToolBox.GetAttributeObject(element, initableProperty.Name.ToLower()); - // if (value == null) - // { - // foreach (var ini in initableProperty.Attributes.OfType()) - // { - // value = ini.defaultValue; - // break; - // } - // } - - // initableProperty.TrySetValue(value); - //} - pickDistance = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "pickdistance", 0.0f)); - isLinkable = ToolBox.GetAttributeBool(element, "linkable", false); + isLinkable = ToolBox.GetAttributeBool(element, "linkable", false); - resizeHorizontal = ToolBox.GetAttributeBool(element, "resizehorizontal", false); - resizeVertical = ToolBox.GetAttributeBool(element, "resizevertical", false); + resizeHorizontal = ToolBox.GetAttributeBool(element, "resizehorizontal", false); + resizeVertical = ToolBox.GetAttributeBool(element, "resizevertical", false); - focusOnSelected = ToolBox.GetAttributeBool(element, "focusonselected", false); + focusOnSelected = ToolBox.GetAttributeBool(element, "focusonselected", false); - offsetOnSelected = ToolBox.GetAttributeFloat(element, "offsetonselected", 0.0f); + offsetOnSelected = ToolBox.GetAttributeFloat(element, "offsetonselected", 0.0f); - Triggers = new List(); + Triggers = new List(); + foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLower()) @@ -201,18 +177,6 @@ namespace Subsurface } } - //sounds = new List(); - //var soundElements = element.Descendants(); - //foreach (XElement soundElement in soundElements) - //{ - // if (soundElement.Name.ToString().ToLower() != "sound") continue; - // string soundPath = ToolBox.GetAttributeString(soundElement, "path", ""); - // if (soundPath == "") continue; - - // Sound sound = Sound.Load(soundPath); - // if (sound != null) sounds.Add(sound); - //} - list.Add(this); } } diff --git a/Subsurface/Map/Explosion.cs b/Subsurface/Map/Explosion.cs index 64b20cf53..d0344c4f0 100644 --- a/Subsurface/Map/Explosion.cs +++ b/Subsurface/Map/Explosion.cs @@ -94,7 +94,7 @@ namespace Subsurface { distFactor = 1.0f - Vector2.Distance(limb.SimPosition, position)/range; - c.AddDamage(limb.SimPosition, DamageType.None, damage * distFactor, 0.0f, stun * distFactor); + c.AddDamage(limb.SimPosition, DamageType.None, damage / c.AnimController.limbs.Length * distFactor, 0.0f, stun * distFactor); if (force>0.0f) { diff --git a/Subsurface/Networking/GameClient.cs b/Subsurface/Networking/GameClient.cs index 3528a3bb2..d14e1c8ff 100644 --- a/Subsurface/Networking/GameClient.cs +++ b/Subsurface/Networking/GameClient.cs @@ -6,22 +6,20 @@ using System.Collections.Generic; namespace Subsurface.Networking { - - class GameClient : NetworkMember { - NetClient Client; + private NetClient client; private Character myCharacter; private CharacterInfo characterInfo; - GUIMessageBox reconnectBox; + private GUIMessageBox reconnectBox; private bool connected; private int myID; - List otherClients; + private List otherClients; private string serverIP; @@ -48,11 +46,28 @@ namespace Subsurface.Networking characterInfo = new CharacterInfo("Content/Characters/Human/human.xml", name); otherClients = new List(); + } public void ConnectToServer(string hostIP) { - serverIP = hostIP; + + string[] address = hostIP.Split(':'); + if (address.Length==1) + { + serverIP = hostIP; + Port = DefaultPort; + } + else + { + serverIP = address[0]; + + if (!int.TryParse(address[1], out Port)) + { + DebugConsole.ThrowError("Invalid port: address[1]!"); + Port = DefaultPort; + } + } myCharacter = Character.Controlled; @@ -63,10 +78,10 @@ namespace Subsurface.Networking //Config.SimulatedMinimumLatency = 0.25f; // Create new client, with previously created configs - Client = new NetClient(Config); + client = new NetClient(Config); - NetOutgoingMessage outmsg = Client.CreateMessage(); - Client.Start(); + NetOutgoingMessage outmsg = client.CreateMessage(); + client.Start(); outmsg.Write((byte)PacketTypes.Login); outmsg.Write(Game1.Version.ToString()); @@ -75,7 +90,7 @@ namespace Subsurface.Networking // Connect client, to ip previously requested from user try { - Client.Connect(hostIP, 14242, outmsg); + client.Connect(serverIP, Port, outmsg); } catch (ArgumentNullException e) { @@ -133,7 +148,7 @@ namespace Subsurface.Networking NetIncomingMessage inc; // If new messages arrived - if ((inc = Client.ReadMessage()) == null) continue; + if ((inc = client.ReadMessage()) == null) continue; // Switch based on the message types switch (inc.MessageType) @@ -192,7 +207,7 @@ namespace Subsurface.Networking reconnectBox = null; } - if (Client.ConnectionStatus != NetConnectionStatus.Connected) + if (client.ConnectionStatus != NetConnectionStatus.Connected) { var reconnect = new GUIMessageBox("CONNECTION FAILED", "Failed to connect to server.", new string[] { "Retry", "Cancel" }); reconnect.Buttons[0].OnClicked += RetryConnection; @@ -226,7 +241,7 @@ namespace Subsurface.Networking if (!connected || updateTimer > DateTime.Now) return; - if (Client.ConnectionStatus == NetConnectionStatus.Disconnected && reconnectBox==null) + if (client.ConnectionStatus == NetConnectionStatus.Disconnected && reconnectBox==null) { reconnectBox = new GUIMessageBox("CONNECTION LOST", "You have been disconnected from the server. Reconnecting...", new string[0]); connected = false; @@ -255,13 +270,13 @@ namespace Subsurface.Networking foreach (NetworkEvent networkEvent in NetworkEvent.events) { - NetOutgoingMessage message = Client.CreateMessage(); + NetOutgoingMessage message = client.CreateMessage(); message.Write((byte)PacketTypes.NetworkEvent); if (networkEvent.FillData(message)) { - Client.SendMessage(message, + client.SendMessage(message, (networkEvent.IsImportant) ? NetDeliveryMethod.ReliableUnordered : NetDeliveryMethod.Unreliable); } } @@ -284,7 +299,7 @@ namespace Subsurface.Networking // Create new incoming message holder NetIncomingMessage inc; - while ((inc = Client.ReadMessage()) != null) + while ((inc = client.ReadMessage()) != null) { if (inc.MessageType != NetIncomingMessageType.Data) continue; @@ -406,18 +421,18 @@ namespace Subsurface.Networking public override void Disconnect() { - NetOutgoingMessage msg = Client.CreateMessage(); + NetOutgoingMessage msg = client.CreateMessage(); msg.Write((byte)PacketTypes.PlayerLeft); - Client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); - Client.Shutdown(""); + client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); + client.Shutdown(""); } public void SendCharacterData() { if (characterInfo == null) return; - NetOutgoingMessage msg = Client.CreateMessage(); + NetOutgoingMessage msg = client.CreateMessage(); msg.Write((byte)PacketTypes.CharacterInfo); msg.Write(characterInfo.Name); msg.Write(characterInfo.Gender == Gender.Male); @@ -431,7 +446,7 @@ namespace Subsurface.Networking msg.Write(jobPreferences[i].Name); } - Client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); + client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); } private Character ReadCharacterData(NetIncomingMessage inc) @@ -486,12 +501,12 @@ namespace Subsurface.Networking type = (gameStarted && myCharacter != null && myCharacter.IsDead) ? ChatMessageType.Dead : ChatMessageType.Default; - NetOutgoingMessage msg = Client.CreateMessage(); + NetOutgoingMessage msg = client.CreateMessage(); msg.Write((byte)PacketTypes.Chatmessage); msg.Write((byte)type); msg.Write(message); - Client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); + client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); } /// @@ -500,7 +515,7 @@ namespace Subsurface.Networking /// public void SendRandomData() { - NetOutgoingMessage msg = Client.CreateMessage(); + NetOutgoingMessage msg = client.CreateMessage(); switch (Rand.Int(5)) { case 0: @@ -531,7 +546,7 @@ namespace Subsurface.Networking } - Client.SendMessage(msg, (Rand.Int(2)==0) ? NetDeliveryMethod.ReliableOrdered : NetDeliveryMethod.Unreliable); + client.SendMessage(msg, (Rand.Int(2)==0) ? NetDeliveryMethod.ReliableOrdered : NetDeliveryMethod.Unreliable); } } diff --git a/Subsurface/Networking/NetworkMember.cs b/Subsurface/Networking/NetworkMember.cs index 6d3641cf6..1d5cea09a 100644 --- a/Subsurface/Networking/NetworkMember.cs +++ b/Subsurface/Networking/NetworkMember.cs @@ -29,8 +29,10 @@ namespace Subsurface.Networking class NetworkMember { - protected static Color[] messageColor = { Color.White, Color.Red, Color.LightBlue, Color.LightGreen }; + public const int DefaultPort = 14242; + protected static Color[] messageColor = { Color.White, Color.Red, Color.LightBlue, Color.LightGreen }; + protected string name; protected TimeSpan updateInterval; @@ -39,6 +41,8 @@ namespace Subsurface.Networking protected GUIFrame inGameHUD; protected GUIListBox chatBox; + public int Port; + protected bool gameStarted; public string Name diff --git a/Subsurface/Screens/MainMenu.cs b/Subsurface/Screens/MainMenu.cs index 70714c967..d78b9bf53 100644 --- a/Subsurface/Screens/MainMenu.cs +++ b/Subsurface/Screens/MainMenu.cs @@ -141,7 +141,7 @@ namespace Subsurface new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server IP:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]); ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.JoinServer]); - + GUIButton joinButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Join", Alignment.BottomCenter, GUI.style, menuTabs[(int)Tabs.JoinServer]); joinButton.OnClicked = JoinServer; @@ -162,7 +162,7 @@ namespace Subsurface selectedTab = (int)obj; return true; } - + private bool HostServerClicked(GUIButton button, object obj) { Game1.NetLobbyScreen.IsServer = true; diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index a45191f9c..004ff703e 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -66,6 +66,7 @@ + diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 92cc73001..64afddea1 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ