From 31a04c7bc1f137cc4169474471d66c6373fdb3da Mon Sep 17 00:00:00 2001 From: Regalis Date: Sat, 16 Apr 2016 15:36:01 +0300 Subject: [PATCH] Cargo missions, a menu that shows the mission description mid-round --- Subsurface/Barotrauma.csproj | 7 +- Subsurface/Content/Missions.xml | 91 +++++++++++++++ .../AI/Objectives/AIObjectiveFindSafety.cs | 20 ++-- .../Source/Events/Missions/CargoMission.cs | 100 +++++++++++++++++ .../{Quests/Quest.cs => Missions/Mission.cs} | 0 .../MonsterMission.cs} | 0 .../SalvageMission.cs} | 0 Subsurface/Source/GUI/GUITextBlock.cs | 1 + Subsurface/Source/GameSession/CrewManager.cs | 33 +++--- Subsurface/Source/GameSession/GameSession.cs | 104 ++++++++++++++++-- Subsurface/Source/Map/Levels/Level.cs | 7 +- Subsurface/Source/Networking/GameClient.cs | 4 +- Subsurface/Source/Networking/GameServer.cs | 2 +- 13 files changed, 327 insertions(+), 42 deletions(-) create mode 100644 Subsurface/Source/Events/Missions/CargoMission.cs rename Subsurface/Source/Events/{Quests/Quest.cs => Missions/Mission.cs} (100%) rename Subsurface/Source/Events/{Quests/MonsterQuest.cs => Missions/MonsterMission.cs} (100%) rename Subsurface/Source/Events/{Quests/SalvageQuest.cs => Missions/SalvageMission.cs} (100%) diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 02c92edaf..48e46d9d5 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -97,9 +97,10 @@ - - - + + + + diff --git a/Subsurface/Content/Missions.xml b/Subsurface/Content/Missions.xml index eb09fca5a..6b3bcdb72 100644 --- a/Subsurface/Content/Missions.xml +++ b/Subsurface/Content/Missions.xml @@ -66,4 +66,95 @@ successmessage="It turns out the signal was emitted by a Moloch. The researchers of [location1] have agreed to pay you the reward nevertheless for getting rid of the Moloch." monsterfile="Content/Characters/Moloch/moloch.xml"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs index 5cee70842..2770496ec 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs @@ -33,7 +33,7 @@ namespace Barotrauma var currentHull = character.AnimController.CurrentHull; currenthullSafety = OverrideCurrentHullSafety == null ? - GetHullSafety(currentHull) : (float)OverrideCurrentHullSafety; + GetHullSafety(currentHull, character) : (float)OverrideCurrentHullSafety; if (currentHull != null) { @@ -112,7 +112,7 @@ namespace Barotrauma { if (hull == character.AnimController.CurrentHull || unreachable.Contains(hull)) continue; - float hullValue = GetHullSafety(hull); + float hullValue = GetHullSafety(hull, character); hullValue -= (float)Math.Sqrt(Math.Abs(character.Position.X - hull.Position.X)); hullValue -= (float)Math.Sqrt(Math.Abs(character.Position.Y - hull.Position.Y) * 2.0f); @@ -139,7 +139,7 @@ namespace Barotrauma } if (character.AnimController.CurrentHull == null) return 5.0f; - currenthullSafety = GetHullSafety(character.AnimController.CurrentHull); + currenthullSafety = GetHullSafety(character.AnimController.CurrentHull, character); priority = 100.0f - currenthullSafety; if (divingGearObjective != null && !divingGearObjective.IsCompleted()) priority += 20.0f; @@ -147,22 +147,22 @@ namespace Barotrauma return priority; } - private float GetHullSafety(Hull hull) + public static float GetHullSafety(Hull hull, Character character) { if (hull == null) return 0.0f; - float waterPercentage = (hull.Volume / hull.FullVolume)*100.0f; + float waterPercentage = (hull.Volume / hull.FullVolume) * 100.0f; float fireAmount = 0.0f; foreach (FireSource fireSource in hull.FireSources) { - fireAmount += Math.Max(fireSource.Size.X,50.0f); + fireAmount += Math.Max(fireSource.Size.X, 50.0f); } - + float safety = 100.0f - fireAmount; - - if (waterPercentage > 30.0f && character.OxygenAvailable<=0.0f) safety -= waterPercentage; - if (hull.OxygenPercentage < 30.0f) safety -= (30.0f-hull.OxygenPercentage)*5.0f; + + if (waterPercentage > 30.0f && character.OxygenAvailable <= 0.0f) safety -= waterPercentage; + if (hull.OxygenPercentage < 30.0f) safety -= (30.0f - hull.OxygenPercentage) * 5.0f; return safety; } diff --git a/Subsurface/Source/Events/Missions/CargoMission.cs b/Subsurface/Source/Events/Missions/CargoMission.cs new file mode 100644 index 000000000..a21a60350 --- /dev/null +++ b/Subsurface/Source/Events/Missions/CargoMission.cs @@ -0,0 +1,100 @@ +using Barotrauma.Items.Components; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.Linq; + +namespace Barotrauma +{ + class CargoMission : Mission + { + + private XElement itemConfig; + + private List items; + + private int requiredDeliveryAmount; + + public CargoMission(XElement element) + : base(element) + { + itemConfig = element.Element("Items"); + + requiredDeliveryAmount = ToolBox.GetAttributeInt(element, "requireddeliveryamount", 0); + } + + private void InitItems() + { + items = new List(); + + if (itemConfig==null) + { + DebugConsole.ThrowError("Failed to initialize items for cargo mission (itemConfig == null)"); + return; + } + + foreach (XElement subElement in itemConfig.Elements()) + { + LoadItemAsChild(subElement, null); + } + + if (requiredDeliveryAmount == 0) requiredDeliveryAmount = items.Count(); + } + + private void LoadItemAsChild(XElement element, Item parent) + { + string itemName = ToolBox.GetAttributeString(element, "name", ""); + + ItemPrefab itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab; + if (itemPrefab==null) + { + DebugConsole.ThrowError("Couldn't spawn item for cargo mission: item prefab ''"+element.Name.ToString()+"'' not found"); + return; + } + + WayPoint cargoSpawnPos = WayPoint.GetRandom(SpawnType.Cargo); + if (cargoSpawnPos==null) + { + DebugConsole.ThrowError("Couldn't spawn items for cargo mission, cargo spawnpoint not found"); + return; + } + + var item = new Item(itemPrefab, cargoSpawnPos.Position, Submarine.Loaded); + items.Add(item); + + if (parent != null) parent.Combine(item); + + foreach (XElement subElement in element.Elements()) + { + int amount = ToolBox.GetAttributeInt(subElement, "amount", 1); + for (int i = 0; i < amount; i++) + { + LoadItemAsChild(subElement, item); + } + } + } + + public override void Start(Level level) + { + InitItems(); + } + + public override void End() + { + if (Submarine.Loaded != null && Submarine.Loaded.AtEndPosition) + { + int deliveredItemCount = items.Count(i => i.CurrentHull != null && i.Condition > 0.0f); + + if (deliveredItemCount >= requiredDeliveryAmount) + { + GiveReward(); + + completed = true; + } + } + + items.ForEach(i => i.Remove()); + } + } +} diff --git a/Subsurface/Source/Events/Quests/Quest.cs b/Subsurface/Source/Events/Missions/Mission.cs similarity index 100% rename from Subsurface/Source/Events/Quests/Quest.cs rename to Subsurface/Source/Events/Missions/Mission.cs diff --git a/Subsurface/Source/Events/Quests/MonsterQuest.cs b/Subsurface/Source/Events/Missions/MonsterMission.cs similarity index 100% rename from Subsurface/Source/Events/Quests/MonsterQuest.cs rename to Subsurface/Source/Events/Missions/MonsterMission.cs diff --git a/Subsurface/Source/Events/Quests/SalvageQuest.cs b/Subsurface/Source/Events/Missions/SalvageMission.cs similarity index 100% rename from Subsurface/Source/Events/Quests/SalvageQuest.cs rename to Subsurface/Source/Events/Missions/SalvageMission.cs diff --git a/Subsurface/Source/GUI/GUITextBlock.cs b/Subsurface/Source/GUI/GUITextBlock.cs index 4b4dda5dc..088c87ca8 100644 --- a/Subsurface/Source/GUI/GUITextBlock.cs +++ b/Subsurface/Source/GUI/GUITextBlock.cs @@ -52,6 +52,7 @@ namespace Barotrauma } set { + if (base.Rect == value) return; base.Rect = value; SetTextPos(); } diff --git a/Subsurface/Source/GameSession/CrewManager.cs b/Subsurface/Source/GameSession/CrewManager.cs index c465fd207..67c2422b4 100644 --- a/Subsurface/Source/GameSession/CrewManager.cs +++ b/Subsurface/Source/GameSession/CrewManager.cs @@ -19,7 +19,7 @@ namespace Barotrauma private GUIListBox listBox, orderListBox; private bool crewFrameOpen; - private GUIButton crewButton; + //private GUIButton crewButton; protected GUIFrame crewFrame; private CrewCommander commander; @@ -45,9 +45,6 @@ namespace Barotrauma orderListBox.ScrollBarEnabled = false; orderListBox.OnSelected = SelectCharacterOrder; - crewButton = new GUIButton(new Rectangle(5, 0, 100, 20), "Crew", GUI.Style, guiFrame); - crewButton.OnClicked = ToggleCrewFrame; - commander = new CrewCommander(this); money = 10000; @@ -207,12 +204,12 @@ namespace Barotrauma //} } - public void CreateCrewFrame(List crew) + public void CreateCrewFrame(List crew, GUIFrame crewFrame) { int width = 600, height = 400; - crewFrame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style); - crewFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); + //crewFrame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style); + //crewFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); GUIListBox crewList = new GUIListBox(new Rectangle(0, 0, 280, 300), Color.White * 0.7f, GUI.Style, crewFrame); crewList.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); @@ -238,8 +235,8 @@ namespace Barotrauma new GUIImage(new Rectangle(-10, 0, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame); } - var closeButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Close", Alignment.BottomCenter, GUI.Style, crewFrame); - closeButton.OnClicked = ToggleCrewFrame; + //var closeButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Close", Alignment.BottomCenter, GUI.Style, crewFrame); + //closeButton.OnClicked = ToggleCrewFrame; } protected virtual bool SelectCrewCharacter(GUIComponent component, object obj) @@ -247,6 +244,12 @@ namespace Barotrauma Character character = obj as Character; if (character == null) return false; + var crewFrame = component.Parent; + while (crewFrame.Parent!=null) + { + crewFrame = crewFrame.Parent; + } + GUIComponent existingFrame = crewFrame.FindChild("selectedcharacter"); if (existingFrame != null) crewFrame.RemoveChild(existingFrame); @@ -263,13 +266,13 @@ namespace Barotrauma return true; } - private bool ToggleCrewFrame(GUIButton button, object obj) - { - if (crewFrame == null) CreateCrewFrame(characters); + //private bool ToggleCrewFrame(GUIButton button, object obj) + //{ + // if (crewFrame == null) CreateCrewFrame(characters); - crewFrameOpen = !crewFrameOpen; - return true; - } + // crewFrameOpen = !crewFrameOpen; + // return true; + //} public void StartShift() { diff --git a/Subsurface/Source/GameSession/GameSession.cs b/Subsurface/Source/GameSession/GameSession.cs index 6ee8a7c95..a9b92112d 100644 --- a/Subsurface/Source/GameSession/GameSession.cs +++ b/Subsurface/Source/GameSession/GameSession.cs @@ -7,11 +7,15 @@ namespace Barotrauma { class GameSession { + public enum InfoFrameTab { Crew, Mission }; + public readonly TaskManager TaskManager; public readonly GameMode gameMode; - - private GUIFrame guiRoot; + + private InfoFrameTab selectedTab; + private GUIButton infoButton; + private GUIFrame infoFrame; private string saveFile; @@ -72,7 +76,10 @@ namespace Barotrauma this.saveFile = saveFile; - guiRoot = new GUIFrame(new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsWidth), Color.Transparent); + //guiRoot = new GUIFrame(new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsWidth), Color.Transparent); + + infoButton = new GUIButton(new Rectangle(10, 10, 100, 20), "Info", GUI.Style, null); + infoButton.OnClicked = ToggleInfoFrame; if (gameModePreset!=null) gameMode = gameModePreset.Instantiate(); this.submarine = submarine; @@ -125,16 +132,17 @@ namespace Barotrauma GameMain.GameScreen.BackgroundCreatureManager.SpawnSprites(80); } - if (gameMode.Mission!=null) + if (gameMode.Mission != null) { currentMission = gameMode.Mission; - Mission.Start(Level.Loaded); } shiftSummary = new ShiftSummary(this); if (gameMode!=null) gameMode.Start(); - + + if (gameMode.Mission != null) Mission.Start(Level.Loaded); + TaskManager.StartShift(level); GameMain.GameScreen.ColorFade(Color.Black, Color.TransparentBlack, 5.0f); @@ -187,22 +195,98 @@ namespace Barotrauma return true; } + private bool ToggleInfoFrame(GUIButton button, object obj) + { + if (infoFrame == null) + { + CreateInfoFrame(); + SelectInfoFrameTab(null, selectedTab); + } + else + { + infoFrame = null; + } + + return true; + } + + public void CreateInfoFrame() + { + int width = 600, height = 400; + + infoFrame = new GUIFrame( + new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style); + + infoFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f); + + var crewButton = new GUIButton(new Rectangle(0, -30, 100, 20), "Crew", GUI.Style, infoFrame); + crewButton.UserData = InfoFrameTab.Crew; + crewButton.OnClicked = SelectInfoFrameTab; + + var missionButton = new GUIButton(new Rectangle(100, -30, 100, 20), "Mission", GUI.Style, infoFrame); + missionButton.UserData = InfoFrameTab.Mission; + missionButton.OnClicked = SelectInfoFrameTab; + + var closeButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Close", Alignment.BottomCenter, GUI.Style, infoFrame); + closeButton.OnClicked = ToggleInfoFrame; + + } + + private bool SelectInfoFrameTab(GUIButton button, object userData) + { + selectedTab = (InfoFrameTab)userData; + + CreateInfoFrame(); + + switch (selectedTab) + { + case InfoFrameTab.Crew: + CrewManager.CreateCrewFrame(CrewManager.characters, infoFrame); + break; + case InfoFrameTab.Mission: + CreateMissionInfo(infoFrame); + break; + } + + return true; + } + + private void CreateMissionInfo(GUIFrame infoFrame) + { + if (Mission == null) + { + new GUITextBlock(new Rectangle(0,0,0,400), "No mission", GUI.Style, infoFrame, true); + return; + } + + new GUITextBlock(new Rectangle(0, 0, 0, 40), Mission.Name, GUI.Style, infoFrame, GUI.LargeFont); + + new GUITextBlock(new Rectangle(0, 50, 0, 20), "Reward: "+Mission.Reward, GUI.Style, infoFrame, true); + new GUITextBlock(new Rectangle(0, 70, 0, 50), Mission.Description, GUI.Style, infoFrame, true); + + + } + public void Update(float deltaTime) { TaskManager.Update(deltaTime); //guiRoot.Update(deltaTime); - if (gameMode != null) gameMode.Update(deltaTime); - if (Mission != null) Mission.Update(deltaTime); + infoButton.Update(deltaTime); + + if (gameMode != null) gameMode.Update(deltaTime); + if (Mission != null) Mission.Update(deltaTime); + if (infoFrame != null) infoFrame.Update(deltaTime); } public void Draw(SpriteBatch spriteBatch) { //guiRoot.Draw(spriteBatch); - + infoButton.Draw(spriteBatch); - if (gameMode != null) gameMode.Draw(spriteBatch); + if (gameMode != null) gameMode.Draw(spriteBatch); + if (infoFrame != null) infoFrame.Draw(spriteBatch); } public void Save(string filePath) diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index 6273ba528..e50a59192 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -373,7 +373,12 @@ namespace Barotrauma foreach (VoronoiCell cell in cells) { - cellGrid[(int)Math.Floor(cell.Center.X / GridCellSize), (int)Math.Floor(cell.Center.Y / GridCellSize)].Add(cell); + int x = (int)Math.Floor(cell.Center.X / GridCellSize); + int y = (int)Math.Floor(cell.Center.Y / GridCellSize); + + if (x < 0 || y < 0 || x >= cellGrid.GetLength(0) || y >= cellGrid.GetLength(1)) continue; + + cellGrid[x,y].Add(cell); } diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index 29bf04126..42a608e12 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -541,7 +541,7 @@ namespace Barotrauma.Networking crew.Add(c); } - GameMain.GameSession.CrewManager.CreateCrewFrame(crew); + //GameMain.GameSession.CrewManager.CreateCrewFrame(crew); break; @@ -660,7 +660,7 @@ namespace Barotrauma.Networking AddChatMessage("Press TAB to chat", ChatMessageType.Server); - GameMain.GameSession.CrewManager.CreateCrewFrame(crew); + //GameMain.GameSession.CrewManager.CreateCrewFrame(crew); yield return CoroutineStatus.Success; } diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 226304c23..cc142820e 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -1128,7 +1128,7 @@ namespace Barotrauma.Networking if (myCharacter != null) crew.Add(myCharacter); - if (GameMain.GameSession!=null) GameMain.GameSession.CrewManager.CreateCrewFrame(crew); + //if (GameMain.GameSession!=null) GameMain.GameSession.CrewManager.CreateCrewFrame(crew); } public void KickPlayer(string playerName, bool ban = false)