(99feac023) Unstable 0.9.704.0

This commit is contained in:
Joonas Rikkonen
2020-02-07 20:47:03 +02:00
parent 590619459b
commit 6754b9d5a2
104 changed files with 2224 additions and 1091 deletions
@@ -5,11 +5,11 @@ using System.Xml.Linq;
namespace Barotrauma
{
class CargoMission : Mission
partial class CargoMission : Mission
{
private XElement itemConfig;
private readonly XElement itemConfig;
private List<Item> items;
private readonly List<Item> items = new List<Item>();
private int requiredDeliveryAmount;
@@ -22,7 +22,7 @@ namespace Barotrauma
private void InitItems()
{
items = new List<Item>();
items.Clear();
if (itemConfig == null)
{
@@ -35,7 +35,7 @@ namespace Barotrauma
LoadItemAsChild(subElement, null);
}
if (requiredDeliveryAmount == 0) requiredDeliveryAmount = items.Count;
if (requiredDeliveryAmount == 0) { requiredDeliveryAmount = items.Count; }
}
private void LoadItemAsChild(XElement element, Item parent)
@@ -90,8 +90,6 @@ namespace Barotrauma
var item = new Item(itemPrefab, position, cargoRoom.Submarine);
item.FindHull();
items.Add(item);
if (parent != null) parent.Combine(item, user: null);
@@ -108,7 +106,10 @@ namespace Barotrauma
public override void Start(Level level)
{
InitItems();
if (!IsClient)
{
InitItems();
}
}
public override void End()
@@ -127,8 +128,9 @@ namespace Barotrauma
foreach (Item item in items)
{
if (!item.Removed) item.Remove();
if (!item.Removed) { item.Remove(); }
}
items.Clear();
}
}
}
@@ -1,11 +1,12 @@
using Microsoft.Xna.Framework;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Barotrauma
{
partial class Mission
abstract partial class Mission
{
public readonly MissionPrefab Prefab;
protected bool completed;
@@ -192,9 +193,7 @@ namespace Barotrauma
public void GiveReward()
{
var mode = GameMain.GameSession.GameMode as CampaignMode;
if (mode == null) return;
if (!(GameMain.GameSession.GameMode is CampaignMode mode)) { return; }
mode.Money += Reward;
}
}
@@ -3,14 +3,18 @@ using System.Collections.Generic;
using System.Linq;
using System;
using System.Xml.Linq;
using Barotrauma.Extensions;
using Barotrauma.Networking;
namespace Barotrauma
{
class MonsterMission : Mission
partial class MonsterMission : Mission
{
private readonly string monsterFile;
private readonly int monsterCount;
private readonly HashSet<Tuple<string, int>> monsterFiles = new HashSet<Tuple<string, int>>();
//string = filename, point = min,max
private readonly HashSet<Tuple<string, Point>> monsterFiles = new HashSet<Tuple<string, Point>>();
private readonly List<Character> monsters = new List<Character>();
private readonly List<Vector2> sonarPositions = new List<Vector2>();
@@ -50,7 +54,7 @@ namespace Barotrauma
maxSonarMarkerDistance = prefab.ConfigElement.GetAttributeFloat("maxsonarmarkerdistance", 10000.0f);
monsterCount = prefab.ConfigElement.GetAttributeInt("monstercount", 1);
monsterCount = Math.Min(prefab.ConfigElement.GetAttributeInt("monstercount", 1), 255);
string monsterFileName = monsterFile;
foreach (var monsterElement in prefab.ConfigElement.GetChildElements("monster"))
{
@@ -64,9 +68,9 @@ namespace Barotrauma
{
defaultCount = monsterElement.GetAttributeInt("amount", 1);
}
int min = monsterElement.GetAttributeInt("min", defaultCount);
int max = Math.Max(min, monsterElement.GetAttributeInt("max", defaultCount));
monsterFiles.Add(new Tuple<string, int>(monster, Rand.Range(min, max + 1, Rand.RandSync.Server)));
int min = Math.Min(monsterElement.GetAttributeInt("min", defaultCount), 255);
int max = Math.Min(Math.Max(min, monsterElement.GetAttributeInt("max", defaultCount)), 255);
monsterFiles.Add(new Tuple<string, Point>(monster, new Point(min, max)));
}
description = description.Replace("[monster]",
TextManager.Get("character." + System.IO.Path.GetFileNameWithoutExtension(monsterFileName)));
@@ -74,45 +78,50 @@ namespace Barotrauma
public override void Start(Level level)
{
Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, Level.Loaded.Size.X * 0.3f, out Vector2 spawnPos);
bool isClient = IsClient;
if (monsters.Count > 0)
{
throw new Exception($"monsters.Count > 0 ({monsters.Count})");
}
if (!string.IsNullOrEmpty(monsterFile))
{
for (int i = 0; i < monsterCount; i++)
{
monsters.Add(Character.Create(monsterFile, spawnPos, ToolBox.RandomSeed(8), null, isClient, true, false));
}
}
foreach (var monster in monsterFiles)
{
for (int i = 0; i < monster.Item2; i++)
{
monsters.Add(Character.Create(monster.Item1, spawnPos, ToolBox.RandomSeed(8), null, isClient, true, false));
}
}
if (tempSonarPositions.Count > 0)
{
throw new Exception($"tempSonarPositions.Count > 0 ({tempSonarPositions.Count})");
}
if (!IsClient)
{
Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, Level.Loaded.Size.X * 0.3f, out Vector2 spawnPos);
if (!string.IsNullOrEmpty(monsterFile))
{
for (int i = 0; i < monsterCount; i++)
{
monsters.Add(Character.Create(monsterFile, spawnPos, ToolBox.RandomSeed(8), createNetworkEvent: false));
}
}
foreach (var monster in monsterFiles)
{
int amount = Rand.Range(monster.Item2.X, monster.Item2.Y + 1);
for (int i = 0; i < amount; i++)
{
monsters.Add(Character.Create(monster.Item1, spawnPos, ToolBox.RandomSeed(8), createNetworkEvent: false));
}
}
InitializeMonsters(monsters);
}
}
private void InitializeMonsters(IEnumerable<Character> monsters)
{
monsters.ForEach(m => m.Enabled = false);
SwarmBehavior.CreateSwarm(monsters.Cast<AICharacter>());
for (int i = 0; i < monsters.Count; i++)
foreach (Character monster in monsters)
{
tempSonarPositions.Add(spawnPos + Rand.Vector(maxSonarMarkerDistance));
tempSonarPositions.Add(monster.WorldPosition + Rand.Vector(maxSonarMarkerDistance));
}
if (monsters.Count != tempSonarPositions.Count)
if (monsters.Count() != tempSonarPositions.Count)
{
throw new Exception($"monsters.Count != tempSonarPositions.Count ({monsters.Count} != {tempSonarPositions.Count})");
throw new Exception($"monsters.Count != tempSonarPositions.Count ({monsters.Count()} != {tempSonarPositions.Count})");
}
}
@@ -183,5 +192,6 @@ namespace Barotrauma
}
public bool IsEliminated(Character enemy) => enemy.Removed || enemy.IsDead || enemy.AIController is EnemyAIController ai && ai.State == AIState.Flee;
}
}
@@ -6,13 +6,13 @@ using System.Linq;
namespace Barotrauma
{
class SalvageMission : Mission
partial class SalvageMission : Mission
{
private readonly ItemPrefab itemPrefab;
private Item item;
private Level.PositionType spawnPositionType;
private readonly Level.PositionType spawnPositionType;
public override IEnumerable<Vector2> SonarPositions
{
@@ -62,23 +62,26 @@ namespace Barotrauma
public override void Start(Level level)
{
//ruin items are allowed to spawn close to the sub
float minDistance = spawnPositionType == Level.PositionType.Ruin ? 0.0f : Level.Loaded.Size.X * 0.3f;
Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, minDistance, 30.0f);
item = new Item(itemPrefab, position, null);
item.body.FarseerBody.BodyType = BodyType.Kinematic;
if (item.HasTag("alien"))
if (!IsClient)
{
//try to find an artifact holder and place the artifact inside it
foreach (Item it in Item.ItemList)
{
if (it.Submarine != null || !it.HasTag("artifactholder")) continue;
//ruin items are allowed to spawn close to the sub
float minDistance = spawnPositionType == Level.PositionType.Ruin ? 0.0f : Level.Loaded.Size.X * 0.3f;
Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, minDistance, 30.0f);
item = new Item(itemPrefab, position, null);
item.body.FarseerBody.BodyType = BodyType.Kinematic;
var itemContainer = it.GetComponent<Items.Components.ItemContainer>();
if (itemContainer == null) continue;
if (itemContainer.Combine(item, user: null)) break; // Placement successful
if (item.HasTag("alien"))
{
//try to find an artifact holder and place the artifact inside it
foreach (Item it in Item.ItemList)
{
if (it.Submarine != null || !it.HasTag("artifactholder")) continue;
var itemContainer = it.GetComponent<Items.Components.ItemContainer>();
if (itemContainer == null) { continue; }
if (itemContainer.Combine(item, user: null)) { break; } // Placement successful
}
}
}
}
@@ -108,7 +111,8 @@ namespace Barotrauma
{
if (item.CurrentHull?.Submarine == null || !item.CurrentHull.Submarine.AtEndPosition || item.Removed) { return; }
item.Remove();
item?.Remove();
item = null;
GiveReward();
completed = true;
}