Conflicts:
	Subsurface/Subsurface.csproj
	Subsurface_Solution.v12.suo
This commit is contained in:
Regalis11
2015-06-14 18:18:24 +03:00
86 changed files with 1503 additions and 631 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ namespace Subsurface
damage = ToolBox.GetAttributeFloat(element, "damage", 0.0f); damage = ToolBox.GetAttributeFloat(element, "damage", 0.0f);
structureDamage = ToolBox.GetAttributeFloat(element, "damage", 0.0f); structureDamage = ToolBox.GetAttributeFloat(element, "structuredamage", 0.0f);
bleedingDamage = ToolBox.GetAttributeFloat(element, "bleedingdamage", 0.0f); bleedingDamage = ToolBox.GetAttributeFloat(element, "bleedingdamage", 0.0f);
stun = ToolBox.GetAttributeFloat(element, "stun", 0.0f); stun = ToolBox.GetAttributeFloat(element, "stun", 0.0f);
+73 -38
View File
@@ -14,7 +14,7 @@ using Subsurface.Particles;
namespace Subsurface namespace Subsurface
{ {
class Character : Entity, IDamageable class Character : Entity, IDamageable, IPropertyObject
{ {
public static List<Character> characterList = new List<Character>(); public static List<Character> characterList = new List<Character>();
@@ -40,12 +40,14 @@ namespace Subsurface
public byte largeUpdateTimer; public byte largeUpdateTimer;
public readonly Dictionary<string, ObjectProperty> properties; public readonly Dictionary<string, ObjectProperty> properties;
public Dictionary<string, ObjectProperty> ObjectProperties
{
get { return properties; }
}
protected Key selectKeyHit; protected Key selectKeyHit;
protected Key actionKeyHit; protected Key actionKeyHit, actionKeyDown;
protected Key actionKeyDown; protected Key secondaryKeyHit, secondaryKeyDown;
protected Key secondaryKeyHit;
protected Key secondaryKeyDown;
private Item selectedConstruction; private Item selectedConstruction;
private Item[] selectedItems; private Item[] selectedItems;
@@ -59,6 +61,9 @@ namespace Subsurface
protected float oxygen; protected float oxygen;
protected float drowningTime; protected float drowningTime;
protected float health;
protected float maxHealth;
protected Item closestItem; protected Item closestItem;
protected bool isDead; protected bool isDead;
@@ -73,12 +78,21 @@ namespace Subsurface
protected float soundTimer; protected float soundTimer;
protected float soundInterval; protected float soundInterval;
private float bleeding;
private float blood; private float blood;
private Sound[] sounds; private Sound[] sounds;
//which AIstate each sound is for //which AIstate each sound is for
private AIController.AiState[] soundStates; private AIController.AiState[] soundStates;
public string Name
{
get
{
return speciesName;
}
}
public Inventory Inventory public Inventory Inventory
{ {
get { return inventory; } get { return inventory; }
@@ -122,13 +136,19 @@ namespace Subsurface
{ {
get get
{ {
float totalHealth = 0.0f; return health;
foreach (Limb l in animController.limbs) //float totalHealth = 0.0f;
{ //foreach (Limb l in animController.limbs)
totalHealth += (l.MaxHealth - l.Damage); //{
// totalHealth += (l.MaxHealth - l.Damage);
} //}
return totalHealth/animController.limbs.Count(); //return totalHealth/animController.limbs.Count();
}
set
{
health = MathHelper.Clamp(value, 0.0f, maxHealth);
if (health==0.0f) Kill();
} }
} }
@@ -301,6 +321,9 @@ namespace Subsurface
//limb.prevPosition = ConvertUnits.ToDisplayUnits(position); //limb.prevPosition = ConvertUnits.ToDisplayUnits(position);
} }
maxHealth = ToolBox.GetAttributeFloat(doc.Root, "health", 100.0f);
health = maxHealth;
needsAir = ToolBox.GetAttributeBool(doc.Root, "needsair", false); needsAir = ToolBox.GetAttributeBool(doc.Root, "needsair", false);
drowningTime = ToolBox.GetAttributeFloat(doc.Root, "drowningtime", 10.0f); drowningTime = ToolBox.GetAttributeFloat(doc.Root, "drowningtime", 10.0f);
@@ -331,10 +354,10 @@ namespace Subsurface
animController.FindHull(); animController.FindHull();
if (info.ID >= 0) //if (info.ID >= 0)
{ //{
ID = info.ID; // ID = info.ID;
} //}
characterList.Add(this); characterList.Add(this);
} }
@@ -343,7 +366,7 @@ namespace Subsurface
/// <summary> /// <summary>
/// Control the characte /// Control the characte
/// </summary> /// </summary>
public void Control(Camera cam, bool forcePick=false) public void Control(float deltaTime, Camera cam, bool forcePick=false)
{ {
if (isDead) return; if (isDead) return;
@@ -370,15 +393,15 @@ namespace Subsurface
if (selectedItems[i] == null) continue; if (selectedItems[i] == null) continue;
if (i == 1 && selectedItems[0] == selectedItems[1]) continue; if (i == 1 && selectedItems[0] == selectedItems[1]) continue;
if (actionKeyDown.State) selectedItems[i].Use(this); if (actionKeyDown.State) selectedItems[i].Use(deltaTime, this);
if (secondaryKeyDown.State && selectedItems[i] != null) selectedItems[i].SecondaryUse(this); if (secondaryKeyDown.State && selectedItems[i] != null) selectedItems[i].SecondaryUse(deltaTime, this);
} }
if (selectedConstruction != null) if (selectedConstruction != null)
{ {
if (actionKeyDown.State) selectedConstruction.Use(this); if (actionKeyDown.State) selectedConstruction.Use(deltaTime, this);
if (secondaryKeyDown.State) selectedConstruction.SecondaryUse(this); if (secondaryKeyDown.State) selectedConstruction.SecondaryUse(deltaTime, this);
} }
if (IsNetworkPlayer) if (IsNetworkPlayer)
@@ -509,8 +532,8 @@ namespace Subsurface
} }
if (controlled == this) ControlLocalPlayer(cam); if (controlled == this) ControlLocalPlayer(cam);
Control(cam); Control(deltaTime, cam);
UpdateSightRange(); UpdateSightRange();
aiTarget.SoundRange = 0.0f; aiTarget.SoundRange = 0.0f;
@@ -543,10 +566,10 @@ namespace Subsurface
soundTimer = soundInterval; soundTimer = soundInterval;
} }
foreach (Limb limb in animController.limbs) //foreach (Limb limb in animController.limbs)
{ //{
Blood = blood - limb.Bleeding * deltaTime * 0.1f; Blood = blood - bleeding * deltaTime;
} //}
if (aiController != null) aiController.Update(deltaTime); if (aiController != null) aiController.Update(deltaTime);
} }
@@ -587,19 +610,25 @@ namespace Subsurface
} }
private static GUIProgressBar drowningBar; private static GUIProgressBar drowningBar, bloodBar;
public void DrawHud(SpriteBatch spriteBatch, Camera cam) public void DrawHud(SpriteBatch spriteBatch, Camera cam)
{ {
if (drowningBar==null) if (drowningBar==null)
{ {
int width = 200, height = 20; int width = 100, height = 20;
drowningBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth / 2 - width / 2, 20, width, height), Color.Blue, 1.0f); drowningBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight/2, width, height), Color.Blue, 1.0f);
bloodBar = new GUIProgressBar(new Rectangle(20, Game1.GraphicsHeight / 2 + 30, width, height), Color.Red, 1.0f);
} }
drowningBar.BarSize = Controlled.Oxygen / 100.0f; drowningBar.BarSize = Controlled.Oxygen / 100.0f;
if (drowningBar.BarSize < 1.0f) if (drowningBar.BarSize < 1.0f)
drowningBar.Draw(spriteBatch); drowningBar.Draw(spriteBatch);
bloodBar.BarSize = Blood / 100.0f;
if (bloodBar.BarSize < 1.0f)
bloodBar.Draw(spriteBatch);
if (Controlled.Inventory != null) if (Controlled.Inventory != null)
Controlled.Inventory.Draw(spriteBatch); Controlled.Inventory.Draw(spriteBatch);
@@ -674,7 +703,11 @@ namespace Subsurface
closestLimb.body.ApplyForce(pull*Math.Min(amount*100.0f, 100.0f)); closestLimb.body.ApplyForce(pull*Math.Min(amount*100.0f, 100.0f));
return closestLimb.AddDamage(position, damageType, amount, bleedingAmount, playSound); AttackResult attackResult = closestLimb.AddDamage(position, damageType, amount, bleedingAmount, playSound);
health -= attackResult.damage;
bleeding += attackResult.bleeding;
return attackResult;
} }
@@ -705,12 +738,14 @@ namespace Subsurface
centerOfMass /= totalMass; centerOfMass /= totalMass;
health = 0.0f;
foreach (Limb limb in animController.limbs) foreach (Limb limb in animController.limbs)
{ {
Vector2 diff = centerOfMass - limb.SimPosition; Vector2 diff = centerOfMass - limb.SimPosition;
if (diff == Vector2.Zero) continue; if (diff == Vector2.Zero) continue;
limb.body.ApplyLinearImpulse(diff * 10.0f); limb.body.ApplyLinearImpulse(diff * 10.0f);
limb.Damage = 100.0f; // limb.Damage = 100.0f;
} }
AmbientSoundManager.PlayDamageSound(DamageSoundType.Implode, 50.0f, torso.body.FarseerBody); AmbientSoundManager.PlayDamageSound(DamageSoundType.Implode, 50.0f, torso.body.FarseerBody);
@@ -739,7 +774,7 @@ namespace Subsurface
if (isDead) return; if (isDead) return;
//if the game is run by a client, characters are only killed when the server says so //if the game is run by a client, characters are only killed when the server says so
if (Game1.client != null) if (Game1.Client != null)
{ {
if (networkMessage) if (networkMessage)
{ {
@@ -751,14 +786,14 @@ namespace Subsurface
} }
} }
if (Game1.server != null) if (Game1.Server != null)
{ {
new NetworkEvent(NetworkEventType.KillCharacter, ID, false); new NetworkEvent(NetworkEventType.KillCharacter, ID, false);
} }
if (Game1.gameSession.crewManager!=null) if (Game1.GameSession!=null && Game1.GameSession.crewManager != null)
{ {
Game1.gameSession.crewManager.KillCharacter(this); Game1.GameSession.crewManager.KillCharacter(this);
} }
isDead = true; isDead = true;
@@ -876,9 +911,9 @@ namespace Subsurface
else if (type == NetworkEventType.KillCharacter) else if (type == NetworkEventType.KillCharacter)
{ {
Kill(true); Kill(true);
if (Game1.client != null && controlled == this) if (Game1.Client != null && controlled == this)
{ {
Game1.client.AddChatMessage("YOU HAVE DIED. Your chat messages will only be visible to other dead players.", ChatMessageType.Dead); Game1.Client.AddChatMessage("YOU HAVE DIED. Your chat messages will only be visible to other dead players.", ChatMessageType.Dead);
} }
return; return;
} }
@@ -970,7 +1005,7 @@ namespace Subsurface
if (controlled == this) controlled = null; if (controlled == this) controlled = null;
if (Game1.client!=null && Game1.client.Character == this) Game1.client.Character = null; if (Game1.Client!=null && Game1.Client.Character == this) Game1.Client.Character = null;
if (aiTarget != null) if (aiTarget != null)
aiTarget.Remove(); aiTarget.Remove();
+49 -11
View File
@@ -1,4 +1,5 @@
using System.Xml.Linq; using Microsoft.Xna.Framework;
using System.Xml.Linq;
namespace Subsurface namespace Subsurface
{ {
@@ -6,27 +7,28 @@ namespace Subsurface
class CharacterInfo class CharacterInfo
{ {
//the name of the character (e.q. Urist McEngineer)
public string name; public string name;
public readonly string file; public readonly string file;
public int ID; public readonly int headSpriteId;
//public int ID;
public Gender gender; public Gender gender;
public int salary; public int salary;
public string GenderString() //public string GenderString()
{ //{
return gender.ToString(); // return gender.ToString();
} //}
public CharacterInfo(string file, string name = "", Gender gender = Gender.None) public CharacterInfo(string file, string name = "", Gender gender = Gender.None)
{ {
this.file = file; this.file = file;
ID = -1; //ID = -1;
XDocument doc = ToolBox.TryLoadXml(file); XDocument doc = ToolBox.TryLoadXml(file);
if (doc == null) return; if (doc == null) return;
@@ -35,7 +37,7 @@ namespace Subsurface
if (ToolBox.GetAttributeBool(doc.Root, "genders", false)) if (ToolBox.GetAttributeBool(doc.Root, "genders", false))
{ {
if (gender==Gender.None) if (gender == Gender.None)
{ {
float femaleRatio = ToolBox.GetAttributeFloat(doc.Root, "femaleratio", 0.5f); float femaleRatio = ToolBox.GetAttributeFloat(doc.Root, "femaleratio", 0.5f);
this.gender = (Game1.random.NextDouble() < femaleRatio) ? Gender.Female : Gender.Male; this.gender = (Game1.random.NextDouble() < femaleRatio) ? Gender.Female : Gender.Male;
@@ -45,7 +47,21 @@ namespace Subsurface
this.gender = gender; this.gender = gender;
} }
} }
Vector2 headSpriteRange = ToolBox.GetAttributeVector2(doc.Root, "headid", Vector2.Zero);
if (headSpriteRange == Vector2.Zero)
{
headSpriteRange = ToolBox.GetAttributeVector2(
doc.Root,
this.gender == Gender.Female ? "femaleheadid" : "maleheadid",
Vector2.Zero);
}
if (headSpriteRange != Vector2.Zero)
{
headSpriteId = Game1.localRandom.Next((int)headSpriteRange.X, (int)headSpriteRange.Y + 1);
}
if (!string.IsNullOrEmpty(name)) if (!string.IsNullOrEmpty(name))
{ {
this.name = name; this.name = name;
@@ -69,8 +85,30 @@ namespace Subsurface
this.name += ToolBox.GetRandomLine(lastNamePath); this.name += ToolBox.GetRandomLine(lastNamePath);
} }
} }
}
public CharacterInfo(XElement element)
{
name = element.Name.ToString();
string genderStr = ToolBox.GetAttributeString(element, "gender", "male").ToLower();
gender = (genderStr == "male") ? Gender.Male : Gender.Female;
salary = ToolBox.GetAttributeInt(element, "salary", 1000);
}
public virtual XElement Save(XElement parentElement)
{
XElement componentElement = new XElement("character");
componentElement.Add(
new XAttribute("name", name),
new XAttribute("gender", gender == Gender.Male ? "male" : "female"),
new XAttribute("salary", salary),
new XAttribute("headspriteid", headSpriteId));
parentElement.Add(componentElement);
return componentElement;
} }
} }
} }
+11 -13
View File
@@ -1,4 +1,5 @@
using System.Collections.Generic; using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.Xml.Linq; using System.Xml.Linq;
namespace Subsurface namespace Subsurface
@@ -11,12 +12,10 @@ namespace Subsurface
float timer; float timer;
private Item item; Vector2 position;
private Character character;
private Limb limb;
List<IPropertyObject> targets;
public float Timer public float Timer
{ {
get { return timer; } get { return timer; }
@@ -28,15 +27,14 @@ namespace Subsurface
delay = ToolBox.GetAttributeFloat(element, "delay", 1.0f); delay = ToolBox.GetAttributeFloat(element, "delay", 1.0f);
} }
public override void Apply(ActionType type, float deltaTime, Item item, Character character = null, Limb limb = null) public override void Apply(ActionType type, float deltaTime, Vector2 position, List<IPropertyObject> targets)
{ {
if (this.type != type) return; if (this.type != type) return;
this.item = item;
this.character = character;
this.limb = limb;
timer = delay; timer = delay;
this.position = position;
this.targets = targets;
list.Add(this); list.Add(this);
} }
@@ -47,7 +45,7 @@ namespace Subsurface
if (timer > 0.0f) return; if (timer > 0.0f) return;
base.Apply(1.0f, character, item, limb); base.Apply(1.0f, position, targets);
list.Remove(this); list.Remove(this);
} }
+36 -32
View File
@@ -41,9 +41,9 @@ namespace Subsurface
public readonly bool ignoreCollisions; public readonly bool ignoreCollisions;
private readonly float maxHealth; //private readonly float maxHealth;
private float damage; //private float damage;
private float bleeding; //private float bleeding;
public readonly float impactTolerance; public readonly float impactTolerance;
@@ -122,26 +122,26 @@ namespace Subsurface
get { return refJointIndex; } get { return refJointIndex; }
} }
public float Damage //public float Damage
{ //{
get { return damage; } // get { return damage; }
set // set
{ // {
damage = Math.Max(value, 0.0f); // damage = Math.Max(value, 0.0f);
if (damage >=maxHealth) character.Kill(); // if (damage >=maxHealth) character.Kill();
} // }
} //}
public float MaxHealth //public float MaxHealth
{ //{
get { return maxHealth; } // get { return maxHealth; }
} //}
public float Bleeding //public float Bleeding
{ //{
get { return bleeding; } // get { return bleeding; }
set { bleeding = MathHelper.Clamp(value, 0.0f, 100.0f); } // set { bleeding = MathHelper.Clamp(value, 0.0f, 100.0f); }
} //}
public Item WearingItem public Item WearingItem
{ {
@@ -208,7 +208,7 @@ namespace Subsurface
steerForce = ToolBox.GetAttributeFloat(element, "steerforce", 0.0f); steerForce = ToolBox.GetAttributeFloat(element, "steerforce", 0.0f);
maxHealth = Math.Max(ToolBox.GetAttributeFloat(element, "health", 100.0f),1.0f); //maxHealth = Math.Max(ToolBox.GetAttributeFloat(element, "health", 100.0f),1.0f);
armorSector = ToolBox.GetAttributeVector2(element, "armorsector", Vector2.Zero); armorSector = ToolBox.GetAttributeVector2(element, "armorsector", Vector2.Zero);
armorSector.X = MathHelper.ToRadians(armorSector.X); armorSector.X = MathHelper.ToRadians(armorSector.X);
@@ -227,7 +227,11 @@ namespace Subsurface
string spritePath = subElement.Attribute("texture").Value; string spritePath = subElement.Attribute("texture").Value;
if (character.info!=null) if (character.info!=null)
{
spritePath = spritePath.Replace("[GENDER]", (character.info.gender == Gender.Female) ? "f" : ""); spritePath = spritePath.Replace("[GENDER]", (character.info.gender == Gender.Female) ? "f" : "");
spritePath = spritePath.Replace("[HEADID]", character.info.headSpriteId.ToString());
}
sprite = new Sprite(subElement, "", spritePath); sprite = new Sprite(subElement, "", spritePath);
break; break;
@@ -277,7 +281,7 @@ namespace Subsurface
{ {
hitArmor = true; hitArmor = true;
damageSoundType = DamageSoundType.LimbArmor; damageSoundType = DamageSoundType.LimbArmor;
damage /= armorValue; amount /= armorValue;
bleedingAmount /= armorValue; bleedingAmount /= armorValue;
} }
} }
@@ -287,8 +291,8 @@ namespace Subsurface
AmbientSoundManager.PlayDamageSound(damageSoundType, amount, position); AmbientSoundManager.PlayDamageSound(damageSoundType, amount, position);
} }
Bleeding += bleedingAmount; //Bleeding += bleedingAmount;
Damage += amount; //Damage += amount;
float bloodAmount = hitArmor ? 0 : (int)Math.Min((int)(amount * 2.0f), 20); float bloodAmount = hitArmor ? 0 : (int)Math.Min((int)(amount * 2.0f), 20);
//if (closestLimb.Damage>=100.0f) //if (closestLimb.Damage>=100.0f)
@@ -366,18 +370,18 @@ namespace Subsurface
soundTimer -= deltaTime; soundTimer -= deltaTime;
if (ToolBox.RandomFloat(0.0f, 1000.0f) < Bleeding) //if (ToolBox.RandomFloat(0.0f, 1000.0f) < Bleeding)
{ //{
Game1.particleManager.CreateParticle( // Game1.particleManager.CreateParticle(
!inWater ? "blood" : "waterblood", // !inWater ? "blood" : "waterblood",
SimPosition, Vector2.Zero); // SimPosition, Vector2.Zero);
} //}
} }
public void Draw(SpriteBatch spriteBatch, bool debugDraw) public void Draw(SpriteBatch spriteBatch, bool debugDraw)
{ {
Color color = new Color(1.0f, 1.0f - damage / maxHealth, 1.0f - damage / maxHealth); Color color = Color.White;// new Color(1.0f, 1.0f - damage / maxHealth, 1.0f - damage / maxHealth);
body.Dir = Dir; body.Dir = Dir;
body.Draw(spriteBatch, sprite, color); body.Draw(spriteBatch, sprite, color);
+1 -1
View File
@@ -298,7 +298,7 @@ namespace Subsurface
if (impact > l.impactTolerance) if (impact > l.impactTolerance)
{ {
l.Damage += (impact-l.impactTolerance*0.1f); character.Health -= (impact-l.impactTolerance*0.1f);
strongestImpact = Math.Max(strongestImpact, impact - l.impactTolerance); strongestImpact = Math.Max(strongestImpact, impact - l.impactTolerance);
} }
} }
+64 -31
View File
@@ -1,4 +1,5 @@
using System; using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
@@ -8,12 +9,12 @@ namespace Subsurface
class StatusEffect class StatusEffect
{ {
[Flags] [Flags]
public enum Target public enum TargetType
{ {
This = 1, Parent = 2, Character = 4, Contained = 8, Nearby = 16 This = 1, Parent = 2, Character = 4, Contained = 8, Nearby = 16, UseTarget=32
} }
private Target targets; private TargetType targetTypes;
private string[] targetNames; private string[] targetNames;
public string[] propertyNames; public string[] propertyNames;
@@ -29,9 +30,9 @@ namespace Subsurface
private Sound sound; private Sound sound;
public Target Targets public TargetType Targets
{ {
get { return targets; } get { return targetTypes; }
} }
public string[] TargetNames public string[] TargetNames
@@ -91,7 +92,7 @@ namespace Subsurface
string[] Flags = attribute.Value.Split(','); string[] Flags = attribute.Value.Split(',');
foreach (string s in Flags) foreach (string s in Flags)
{ {
targets |= (Target)Enum.Parse(typeof(Target), s, true); targetTypes |= (TargetType)Enum.Parse(typeof(TargetType), s, true);
} }
break; break;
@@ -142,43 +143,75 @@ namespace Subsurface
} }
public virtual void Apply(ActionType type, float deltaTime, Item item, Character character = null, Limb limb = null) //public virtual void Apply(ActionType type, float deltaTime, Item item, Character character = null)
{ //{
if (this.type == type) Apply(deltaTime, character, item); // if (this.type == type) Apply(deltaTime, character, item);
//}
public virtual void Apply(ActionType type, float deltaTime, Vector2 position, IPropertyObject target)
{
if (!targetNames.Contains(target.Name)) return;
List<IPropertyObject> targets = new List<IPropertyObject>();
targets.Add(target);
if (this.type == type) Apply(deltaTime, position, targets);
} }
public virtual void Apply(ActionType type, float deltaTime, Vector2 position, List<IPropertyObject> targets)
protected virtual void Apply(float deltaTime, Character character, Item item, Limb limb = null)
{ {
if (explosion != null) explosion.Explode(item.SimPosition); if (this.type == type) Apply(deltaTime, position, targets);
}
protected virtual void Apply(float deltaTime, Vector2 position, List<IPropertyObject> targets)
{
if (explosion != null) explosion.Explode(position);
if (sound != null) sound.Play(1.0f, 1000.0f, position);
if (sound != null) sound.Play(1.0f, 1000.0f, item.body.FarseerBody);
for (int i = 0; i < propertyNames.Count(); i++) for (int i = 0; i < propertyNames.Count(); i++)
{ {
ObjectProperty property; ObjectProperty property;
foreach (IPropertyObject target in targets)
if (character!=null && character.properties.TryGetValue(propertyNames[i], out property))
{ {
ApplyToProperty(property, propertyEffects[i], deltaTime); if (targetNames!=null && !targetNames.Contains(target.Name)) continue;
} if (!target.ObjectProperties.TryGetValue(propertyNames[i], out property)) continue;
if (item == null) continue; ApplyToProperty(property, propertyEffects[i], deltaTime);
if (item.properties.TryGetValue(propertyNames[i], out property))
{
ApplyToProperty(property, propertyEffects[i], deltaTime);
}
foreach (ItemComponent ic in item.components)
{
if (!ic.properties.TryGetValue(propertyNames[i], out property)) continue;
ApplyToProperty(property, propertyEffects[i], deltaTime);
} }
} }
} }
//protected virtual void Apply(float deltaTime, Character character, Item item)
//{
// if (explosion != null) explosion.Explode(item.SimPosition);
// if (sound != null) sound.Play(1.0f, 1000.0f, item.body.FarseerBody);
// for (int i = 0; i < propertyNames.Count(); i++)
// {
// ObjectProperty property;
// if (character!=null && character.properties.TryGetValue(propertyNames[i], out property))
// {
// ApplyToProperty(property, propertyEffects[i], deltaTime);
// }
// if (item == null) continue;
// if (item.properties.TryGetValue(propertyNames[i], out property))
// {
// ApplyToProperty(property, propertyEffects[i], deltaTime);
// }
// foreach (ItemComponent ic in item.components)
// {
// if (!ic.properties.TryGetValue(propertyNames[i], out property)) continue;
// ApplyToProperty(property, propertyEffects[i], deltaTime);
// }
// }
//}
protected void ApplyToProperty(ObjectProperty property, object value, float deltaTime) protected void ApplyToProperty(ObjectProperty property, object value, float deltaTime)
{ {
if (disableDeltaTime) deltaTime = 1.0f; if (disableDeltaTime) deltaTime = 1.0f;
@@ -26,7 +26,7 @@
<limb id = "3" width="13" height="45" mass = "6" ignorecollisions="true" flip="true"> <limb id = "3" width="13" height="45" mass = "6" ignorecollisions="true" flip="true">
<sprite texture="Content/Characters/Crawler/crawler.png" sourcerect="65,131,36,50" depth="0.15" origin="0.4,0.5"/> <sprite texture="Content/Characters/Crawler/crawler.png" sourcerect="65,131,36,50" depth="0.15" origin="0.4,0.5"/>
<attack type="PinchCW" range="120" duration="0.5" damage="30" stun="0.1" bleedingdamage="20" structuredamage="350" damagetype="slash"/> <attack type="PinchCW" range="120" duration="0.5" damage="30" stun="0.1" bleedingdamage="20" structuredamage="50" damagetype="slash"/>
</limb> </limb>
<limb id = "4" width="11" height="34" mass = "4" type="RightLeg" flip="true"> <limb id = "4" width="11" height="34" mass = "4" type="RightLeg" flip="true">

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<character name ="human" humanoid="true" needsair="true" genders="true" drowningtime="30"> <character name ="human" humanoid="true" needsair="true" genders="true" maleheadid="1,4" femaleheadid="1,2" drowningtime="30">
<name firstname="Content/Characters/Human/[GENDER]firstnames.txt" lastname="Content/Characters/Human/lastnames.txt" /> <name firstname="Content/Characters/Human/[GENDER]firstnames.txt" lastname="Content/Characters/Human/lastnames.txt" />
@@ -8,7 +8,7 @@
<!-- head --> <!-- head -->
<limb id = "0" radius="13" mass = "6" type="Head" attackpriority="2" impacttolerance="3.0"> <limb id = "0" radius="13" mass = "6" type="Head" attackpriority="2" impacttolerance="3.0">
<sprite texture="Content/Characters/Human/[GENDER]head.png" sourcerect="1,1,37,38" depth="0.12" origin="0.5,0.5"/> <sprite texture="Content/Characters/Human/[GENDER]head[HEADID].png" sourcerect="1,1,37,38" depth="0.12" origin="0.5,0.5"/>
</limb> </limb>
<!-- body --> <!-- body -->
<limb id = "1" width="26" height="30" mass = "20" type="Torso" attackpriority="3" impacttolerance="5.0"> <limb id = "1" width="26" height="30" mass = "20" type="Torso" attackpriority="3" impacttolerance="5.0">
Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

@@ -0,0 +1,16 @@
<Items>
<Item
name="Captain's Cap"
pickdistance="150">
<Sprite texture ="captainhat.png" depth="0.4"/>
<Body radius="8" density="5"/>
<Wearable limbtype="Head" slots="Any,Head">
<sprite texture="captainhat.png" limb="Head" origin="0.4,0.94"/>
</Wearable>
</Item>
</Items>
@@ -11,11 +11,13 @@
<Wearable limbtype="Head" slots="Any,Head"> <Wearable limbtype="Head" slots="Any,Head">
<sprite texture="DivingMask.png" limb="Head" sourcerect="1,1,37,38"/> <sprite texture="DivingMask.png" limb="Head" sourcerect="1,1,37,38"/>
<StatusEffect type="OnWearing" target="Contained,Character" targetnames="Oxygen Tank" Condition="-0.7" Oxygen="20.0"/> <StatusEffect type="OnWearing" target="Contained,Character" targetnames="Oxygen Tank,human" Condition="-0.7" Oxygen="20.0"/>
<StatusEffect type="OnWearing" target="Contained,Character" targetnames="Welding Fuel Tank,human" Condition="-0.7" Oxygen="-20.0"/>
</Wearable> </Wearable>
<ItemContainer capacity="1" hideitems="true"> <ItemContainer capacity="1" hideitems="true">
<Containable name="Oxygen Tank"/> <Containable name="Oxygen Tank"/>
<Containable name="Welding Fuel Tank"/>
</ItemContainer> </ItemContainer>
</Item> </Item>

Before

Width:  |  Height:  |  Size: 464 B

After

Width:  |  Height:  |  Size: 464 B

+1 -1
View File
@@ -11,7 +11,7 @@
<Reactor canbeselected = "true"> <Reactor canbeselected = "true">
<requireditem name="Fuel Rod" type="Contained"/> <requireditem name="Fuel Rod" type="Contained"/>
<StatusEffect type="OnActive" target="Contained" targetnames="Fuel Rod, Heat Absorber, Temperature Control Circuit" Condition="-0.1" /> <StatusEffect type="OnActive" target="Contained" targetnames="Fuel Rod, Heat Absorber, Temperature Control Circuit" Condition="-0.1" />
<sound file="reactor.ogg" type="OnActive" range="1000.0"/> <sound file="reactor.ogg" type="OnActive" range="1000.0" volume="FissionRate"/>
</Reactor> </Reactor>
<ConnectionPanel canbeselected = "true"> <ConnectionPanel canbeselected = "true">
Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

+52 -4
View File
@@ -7,16 +7,64 @@
<Sprite texture ="weldingtool.png" depth="0.04"/> <Sprite texture ="weldingtool.png" depth="0.04"/>
<Body width="50" height="44" density="5"/> <Body width="39" height="18" density="5"/>
<Holdable holdpos="-9,-20" holdangle="-30"/> <Holdable aimpos="50,0" handle1="-17,0" handle2="8,0"/>
<RepairTool range="80"> <RepairTool structurefixamount="50.0" range="80" barrelpos="19,8">
<RequiredItems name="Welding Fuel Tank" type="Contained"/>
<StatusEffect type="OnUse" target="Contained" targetnames="Welding Fuel Tank" Condition="-0.7"/>
<StatusEffect type="OnUse" target="UseTarget" targetnames="Door,Windowed Door" Stuck="10.0"/>
<Fixable name="structure"/> <Fixable name="structure"/>
</RepairTool> </RepairTool>
<Pickable slots="Any,RightHand"/> <Pickable slots="Any,BothHands"/>
<ItemContainer capacity="1" hideitems="false" itempos="-17,-21">
<Containable name="Welding Fuel Tank"/>
<Containable name="Oxygen Tank"/>
</ItemContainer>
</Item>
<Item
name="Plasma Cutter"
Tags="smallitem"
pickdistance="200">
<Sprite texture ="plasmacutter.png" depth="0.04"/>
<Body width="39" height="18" density="5"/>
<Holdable aimpos="50,0" handle1="-12,4"/>
<RepairTool structurefixamount="-10.0" range="50" barrelpos="19,8">
<RequiredItems name="Oxygen Tank" type="Contained"/>
<StatusEffect type="OnUse" target="Contained" targetnames="Oxygen Tank" Condition="-0.7"/>
<StatusEffect type="OnUse" target="UseTarget" targetnames="Door,Windowed Door" Stuck="-10.0"/>
<Fixable name="structure"/>
</RepairTool>
<Pickable slots="Any,RightHand,LeftHand"/>
<ItemContainer capacity="1" hideitems="false" itempos="9,-15">
<Containable name="Welding Fuel Tank"/>
<Containable name="Oxygen Tank"/>
</ItemContainer>
</Item>
<Item
name="Welding Fuel Tank"
Tags="smallitem"
pickdistance="150">
<Sprite texture ="fueltank.png" depth="0.05"/>
<Body radius="6" height="22" density="5"/>
<Holdable holdpos="30,-15" handle1="0,5" handle2="0,-5"/>
<Pickable slots="RightHand,Any"/>
</Item> </Item>
<Item <Item
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 307 B

+3 -3
View File
@@ -10,8 +10,8 @@
<Body width="64" height="5" density="20"/> <Body width="64" height="5" density="20"/>
<Pickable slots="Any"/> <Pickable slots="Any"/>
<Projectile launchimpulse="20.0" damage="20.0" bleedingdamage="20.0" doesstick="true"> <Projectile launchimpulse="20.0" doesstick="true">
<Attack damage="20" bleeding="30" structuredamage="50" damagetype="Blunt"/> <Attack damage="20" bleedingdamage="30" structuredamage="50" damagetype="Blunt"/>
</Projectile> </Projectile>
</Item> </Item>
@@ -46,7 +46,7 @@
<Body width="11" height="24" density="15" friction="0.8f"/> <Body width="11" height="24" density="15" friction="0.8f"/>
<Throwable holdpos="0,0" handle1="0,0" throwforce="5.0"> <Throwable holdpos="0,0" handle1="0,0" throwforce="5.0" aimpos="35,-10">
<StatusEffect type="OnUse" target="This" Condition="-100.0" delay="3.0" sound="Content/Items/Weapons/stunGrenade.ogg"> <StatusEffect type="OnUse" target="This" Condition="-100.0" delay="3.0" sound="Content/Items/Weapons/stunGrenade.ogg">
<Explosion range="5" damage="5" stun="10" force="0.1"/> <Explosion range="5" damage="5" stun="10" force="0.1"/>
</StatusEffect> </StatusEffect>
+11
View File
@@ -70,4 +70,15 @@
inwater="false" inwater="false"
deleteonhit="true" deleteonhit="true"
velocitychange="0.0, 0.5"/> velocitychange="0.0, 0.5"/>
<weld sprite="Content/Particles/explosion.png"
startsizemin="0.1,0.1" startsizemax="0.2,0.2"
sizechangemin="0.5,0.5" sizechangemax="0.7,0.7"
startrotationmin ="0.0" startrotationmax="6.28"
startcolor="1.0, 1.0, 1.0" startalpha="1.0"
colorchange="0.0, 0.0, -1.0, -5.0"
lifetime="1.0"
inwater="false"
deleteonhit="true"
velocitychange="0.0, 0.0"/>
</prefabs> </prefabs>
Binary file not shown.
Binary file not shown.
+4
View File
@@ -25,4 +25,8 @@
<damagesound file="Content/Sounds/Damage/HitArmor3.ogg" damagerange="40.0,100.0" damagesoundtype="LimbArmor"/> <damagesound file="Content/Sounds/Damage/HitArmor3.ogg" damagerange="40.0,100.0" damagesoundtype="LimbArmor"/>
<damagesound file="Content/Sounds/Damage/implode.ogg" damagerange="0.0,100.0" damagesoundtype="Implode"/> <damagesound file="Content/Sounds/Damage/implode.ogg" damagerange="0.0,100.0" damagesoundtype="Implode"/>
<music file="Content\Sounds\Music\Simplex.ogg" type="default"/>
<music file="Content\Sounds\Music\Enter The Maze.ogg" type="repair" priorityrange="40,100"/>
<music file="Content\Sounds\Music\Unseen Horrors.ogg" type="monster" priorityrange="40,100"/>
</sounds> </sounds>
+7 -5
View File
@@ -3,13 +3,15 @@
<MonsterEvent name="Under attack" description="" <MonsterEvent name="Under attack" description=""
characterfile="Content/Characters/Crawler/Crawler.xml" characterfile="Content/Characters/Crawler/Crawler.xml"
commonness="10" commonness="10"
difficulty="10" difficulty="30"
minamount="2" maxamount="4" minamount="2" maxamount="3"
starttimemin="5" starttimemax="10"/> starttimemin="5" starttimemax="10"
musictype="monster"/>
<MonsterEvent name="Under attack" description="" <MonsterEvent name="Under attack" description=""
characterfile="Content/Characters/TigerThresher/tigerthresher.xml" characterfile="Content/Characters/TigerThresher/tigerthresher.xml"
commonness="10" commonness="10"
difficulty="10" difficulty="50"
starttimemin="5" starttimemax="10"/> starttimemin="5" starttimemax="10"
musictype="monster"/>
</Randomevents> </Randomevents>
+29 -17
View File
@@ -148,8 +148,8 @@ namespace Subsurface
{ {
WayPoint spawnPoint = WayPoint.GetRandom(WayPoint.SpawnType.Human); WayPoint spawnPoint = WayPoint.GetRandom(WayPoint.SpawnType.Human);
Character.Controlled = new Character("Content/Characters/Human/human.xml", (spawnPoint == null) ? Vector2.Zero : spawnPoint.SimPosition); Character.Controlled = new Character("Content/Characters/Human/human.xml", (spawnPoint == null) ? Vector2.Zero : spawnPoint.SimPosition);
if (Game1.gameSession != null) Game1.gameSession.crewManager.AddCharacter(Character.Controlled); if (Game1.GameSession != null) Game1.GameSession.crewManager.AddCharacter(Character.Controlled);
if (Game1.gameSession != null) Game1.gameSession.crewManager.SelectCharacter(Character.Controlled); if (Game1.GameSession != null) Game1.GameSession.crewManager.SelectCharacter(Character.Controlled);
} }
else else
{ {
@@ -159,42 +159,42 @@ namespace Subsurface
break; break;
case "startserver": case "startserver":
if (Game1.server==null) if (Game1.Server==null)
Game1.server = new GameServer(); Game1.Server = new GameServer();
break; break;
case "kick": case "kick":
if (Game1.server == null) break; if (Game1.Server == null) break;
Game1.server.KickPlayer(commands[1]); Game1.Server.KickPlayer(commands[1]);
break; break;
case "startclient": case "startclient":
if (commands.Length == 1) return; if (commands.Length == 1) return;
if (Game1.client == null) if (Game1.Client == null)
{ {
Game1.client = new GameClient("Name"); Game1.Client = new GameClient("Name");
Game1.client.ConnectToServer(commands[1]); Game1.Client.ConnectToServer(commands[1]);
} }
break; break;
case "mainmenuscreen": case "mainmenuscreen":
case "mainmenu": case "mainmenu":
case "menu": case "menu":
Game1.mainMenuScreen.Select(); Game1.MainMenuScreen.Select();
break; break;
case "gamescreen": case "gamescreen":
case "game": case "game":
Game1.gameScreen.Select(); Game1.GameScreen.Select();
break; break;
case "editmapscreen": case "editmapscreen":
case "editmap": case "editmap":
case "edit": case "edit":
Game1.editMapScreen.Select(); Game1.EditMapScreen.Select();
break; break;
case "editcharacter": case "editcharacter":
case "editchar": case "editchar":
Game1.editCharacterScreen.Select(); Game1.EditCharacterScreen.Select();
break; break;
case "editwater": case "editwater":
case "water": case "water":
if (Game1.client== null) if (Game1.Client== null)
{ {
Hull.EditWater = !Hull.EditWater; Hull.EditWater = !Hull.EditWater;
} }
@@ -206,15 +206,27 @@ namespace Subsurface
break; break;
case "lobbyscreen": case "lobbyscreen":
case "lobby": case "lobby":
Game1.lobbyScreen.Select(); Game1.LobbyScreen.Select();
break; break;
case "savemap": case "savemap":
Map.Loaded.SaveAs("Content/SavedMaps/" + commands[1]); if (commands.Length < 2) break;
Map.SaveCurrent("Content/SavedMaps/" + commands[1]);
NewMessage("map saved", Color.Green); NewMessage("map saved", Color.Green);
break; break;
case "loadmap": case "loadmap":
if (commands.Length < 2) break;
Map.Load("Content/SavedMaps/" + commands[1]); Map.Load("Content/SavedMaps/" + commands[1]);
break; break;
case "savegame":
SaveUtil.SaveGame(SaveUtil.SaveFolder+"save");
break;
case "loadgame":
SaveUtil.LoadGame(SaveUtil.SaveFolder + "save");
break;
case "messagebox":
if (commands.Length < 3) break;
new GUIMessageBox(commands[1], commands[2]);
break;
case "debugdraw": case "debugdraw":
Hull.DebugDraw = !Hull.DebugDraw; Hull.DebugDraw = !Hull.DebugDraw;
Ragdoll.DebugDraw = !Ragdoll.DebugDraw; Ragdoll.DebugDraw = !Ragdoll.DebugDraw;
+4 -2
View File
@@ -8,9 +8,11 @@
public delegate bool IsFinishedHandler(); public delegate bool IsFinishedHandler();
private IsFinishedHandler IsFinishedChecker; private IsFinishedHandler IsFinishedChecker;
public PropertyTask(TaskManager taskManager, Item item, IsFinishedHandler isFinished, float priority, string name) public PropertyTask(Item item, IsFinishedHandler isFinished, float priority, string name)
: base(taskManager, priority, name) : base(priority, name)
{ {
if (taskManager == null) return;
this.item = item; this.item = item;
IsFinishedChecker = isFinished; IsFinishedChecker = isFinished;
+4 -2
View File
@@ -4,9 +4,11 @@
{ {
Item item; Item item;
public RepairTask(TaskManager taskManager, Item item, float priority, string name) public RepairTask(Item item, float priority, string name)
: base(taskManager, priority, name) : base(priority, name)
{ {
if (taskManager == null) return;
this.item = item; this.item = item;
taskManager.TaskStarted(this); taskManager.TaskStarted(this);
+11 -1
View File
@@ -30,7 +30,7 @@ namespace Subsurface
protected bool isStarted; protected bool isStarted;
protected bool isFinished; protected bool isFinished;
public string Name public string Name
{ {
get { return name; } get { return name; }
@@ -46,6 +46,12 @@ namespace Subsurface
get { return commonness; } get { return commonness; }
} }
public string MusicType
{
get;
set;
}
public bool IsStarted public bool IsStarted
{ {
get { return isStarted; } get { return isStarted; }
@@ -69,6 +75,10 @@ namespace Subsurface
difficulty = ToolBox.GetAttributeInt(element, "difficulty", 1); difficulty = ToolBox.GetAttributeInt(element, "difficulty", 1);
commonness = ToolBox.GetAttributeInt(element, "commonness", 1); commonness = ToolBox.GetAttributeInt(element, "commonness", 1);
MusicType = ToolBox.GetAttributeString(element, "musictype", "default");
if (element.Attribute("starttime") != null) if (element.Attribute("starttime") != null)
{ {
startTimeMax = ToolBox.GetAttributeInt(element, "starttime", 1); startTimeMax = ToolBox.GetAttributeInt(element, "starttime", 1);
+6 -2
View File
@@ -6,9 +6,13 @@
private bool prevStarted; private bool prevStarted;
public ScriptedTask(TaskManager taskManager, ScriptedEvent scriptedEvent) public ScriptedTask(ScriptedEvent scriptedEvent)
: base(taskManager, scriptedEvent.Difficulty, scriptedEvent.Name) : base(scriptedEvent.Difficulty, scriptedEvent.Name)
{ {
if (taskManager == null) return;
this.musicType = scriptedEvent.MusicType;
this.scriptedEvent = scriptedEvent; this.scriptedEvent = scriptedEvent;
scriptedEvent.Init(); scriptedEvent.Init();
} }
+12 -2
View File
@@ -8,6 +8,8 @@ namespace Subsurface
private float priority; private float priority;
protected string musicType;
protected TaskManager taskManager; protected TaskManager taskManager;
protected bool isFinished; protected bool isFinished;
@@ -22,14 +24,22 @@ namespace Subsurface
get { return priority; } get { return priority; }
} }
public string MusicType
{
get { return musicType; }
}
public bool IsFinished public bool IsFinished
{ {
get { return isFinished; } get { return isFinished; }
} }
public Task(TaskManager taskManager, float priority, string name) public Task(float priority, string name)
{ {
this.taskManager = taskManager; if (Game1.GameSession==null || Game1.GameSession.taskManager == null) return;
taskManager = Game1.GameSession.taskManager;
musicType = "repair";
this.priority = priority; this.priority = priority;
this.name = name; this.name = name;
+20 -1
View File
@@ -6,10 +6,29 @@ namespace Subsurface
{ {
class TaskManager class TaskManager
{ {
const float CriticalPriority = 50.0f;
private List<Task> tasks; private List<Task> tasks;
private GUIListBox taskListBox; private GUIListBox taskListBox;
public List<Task> Tasks
{
get { return tasks; }
}
public bool CriticalTasks
{
get
{
foreach (Task task in tasks)
{
if (task.Priority >= CriticalPriority) return true;
}
return false;
}
}
public TaskManager(GameSession session) public TaskManager(GameSession session)
{ {
tasks = new List<Task>(); tasks = new List<Task>();
@@ -45,7 +64,7 @@ namespace Subsurface
for (int i = 0; i < scriptedEventCount; i++) for (int i = 0; i < scriptedEventCount; i++)
{ {
ScriptedEvent scriptedEvent = ScriptedEvent.LoadRandom(); ScriptedEvent scriptedEvent = ScriptedEvent.LoadRandom();
AddTask(new ScriptedTask(this, scriptedEvent)); AddTask(new ScriptedTask(scriptedEvent));
} }
} }
+17 -1
View File
@@ -269,13 +269,29 @@ namespace Subsurface
// new Vector2(10, 30), Color.White); // new Vector2(10, 30), Color.White);
if (Character.Controlled != null) Character.Controlled.DrawHud(spriteBatch, cam); if (Character.Controlled != null && cam!=null) Character.Controlled.DrawHud(spriteBatch, cam);
DrawMessages(spriteBatch, (float)deltaTime); DrawMessages(spriteBatch, (float)deltaTime);
if (GUIMessageBox.messageBoxes.Count>0)
{
var messageBox = GUIMessageBox.messageBoxes.Peek();
if (messageBox != null) messageBox.Draw(spriteBatch);
}
DebugConsole.Draw(spriteBatch); DebugConsole.Draw(spriteBatch);
} }
public static void Update(float deltaTime)
{
if (GUIMessageBox.messageBoxes.Count > 0)
{
var messageBox = GUIMessageBox.messageBoxes.Peek();
if (messageBox != null) messageBox.Update(deltaTime);
}
}
public static void AddMessage(string message, Color color, float lifeTime = 3.0f) public static void AddMessage(string message, Color color, float lifeTime = 3.0f)
{ {
Vector2 currPos = new Vector2(Game1.GraphicsWidth / 2.0f, Game1.GraphicsHeight * 0.7f); Vector2 currPos = new Vector2(Game1.GraphicsWidth / 2.0f, Game1.GraphicsHeight * 0.7f);
+3 -4
View File
@@ -51,7 +51,7 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
if (rect.Contains(PlayerInput.GetMouseState.Position) && Enabled) if (rect.Contains(PlayerInput.GetMouseState.Position) && Enabled && (MouseOn == this || IsParentOf(MouseOn)))
{ {
state = ComponentState.Hover; state = ComponentState.Hover;
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed) if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
@@ -66,8 +66,7 @@ namespace Subsurface
if (OnClicked != null) if (OnClicked != null)
{ {
if (OnClicked(this, UserData)) state = ComponentState.Selected; if (OnClicked(this, UserData)) state = ComponentState.Selected;
} }
} }
} }
else else
@@ -87,7 +86,7 @@ namespace Subsurface
DrawChildren(spriteBatch); DrawChildren(spriteBatch);
if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f*alpha, true); if (!Enabled) GUI.DrawRectangle(spriteBatch, rect, Color.Gray*0.5f, true);
} }
} }
} }
+18 -5
View File
@@ -142,14 +142,27 @@ namespace Subsurface
return null; return null;
} }
public bool IsParentOf(GUIComponent component)
{
foreach (GUIComponent child in children)
{
if (child == component) return true;
if (child.IsParentOf(component)) return true;
}
return false;
}
public virtual void Draw(SpriteBatch spriteBatch) public virtual void Draw(SpriteBatch spriteBatch)
{ {
Color newColor = color;
if (state == ComponentState.Selected) newColor = selectedColor;
if (state == ComponentState.Hover) newColor = hoverColor;
GUI.DrawRectangle(spriteBatch, rect, newColor*alpha, true);
DrawChildren(spriteBatch); //Color newColor = color;
//if (state == ComponentState.Selected) newColor = selectedColor;
//if (state == ComponentState.Hover) newColor = hoverColor;
//GUI.DrawRectangle(spriteBatch, rect, newColor*alpha, true);
//DrawChildren(spriteBatch);
} }
public virtual void Update(float deltaTime) public virtual void Update(float deltaTime)
+12
View File
@@ -27,5 +27,17 @@ namespace Subsurface
parent.AddChild(this); parent.AddChild(this);
} }
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
{
base.Draw(spriteBatch);
Color newColor = color;
if (state == ComponentState.Selected) newColor = selectedColor;
if (state == ComponentState.Hover) newColor = hoverColor;
GUI.DrawRectangle(spriteBatch, rect, newColor * alpha, true);
DrawChildren(spriteBatch);
}
} }
} }
+3 -4
View File
@@ -117,7 +117,7 @@ namespace Subsurface
public override void Update(float deltaTime) public override void Update(float deltaTime)
{ {
base.Update(deltaTime); base.Update(deltaTime);
scrollBar.Update(deltaTime); scrollBar.Update(deltaTime);
} }
@@ -188,7 +188,7 @@ namespace Subsurface
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
base.Draw(spriteBatch);
GUI.DrawRectangle(spriteBatch, rect, color*alpha, true); GUI.DrawRectangle(spriteBatch, rect, color*alpha, true);
int x = rect.X, y = rect.Y; int x = rect.X, y = rect.Y;
@@ -206,7 +206,6 @@ namespace Subsurface
} }
} }
for (int i = 0; i < children.Count; i++ ) for (int i = 0; i < children.Count; i++ )
{ {
GUIComponent child = children[i]; GUIComponent child = children[i];
@@ -232,7 +231,7 @@ namespace Subsurface
if (CheckSelected() != selected.UserData) selected = null; if (CheckSelected() != selected.UserData) selected = null;
} }
} }
else if (child.Rect.Contains(PlayerInput.GetMouseState.Position) && enabled) else if (enabled && (MouseOn==this || ( MouseOn!=null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.GetMouseState.Position))
{ {
child.State = ComponentState.Hover; child.State = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked()) if (PlayerInput.LeftButtonClicked())
+22 -19
View File
@@ -3,27 +3,29 @@ using System.Collections.Generic;
namespace Subsurface namespace Subsurface
{ {
class GUIMessageBox class GUIMessageBox : GUIFrame
{ {
public static Queue<GUIMessageBox> messageBoxes = new Queue<GUIMessageBox>(); public static Queue<GUIMessageBox> messageBoxes = new Queue<GUIMessageBox>();
const int DefaultWidth=400, DefaultHeight=200; const int DefaultWidth=400, DefaultHeight=200;
public delegate bool OnClickedHandler(GUIButton button, object obj); //public delegate bool OnClickedHandler(GUIButton button, object obj);
public OnClickedHandler OnClicked; //public OnClickedHandler OnClicked;
GUIFrame frame; //GUIFrame frame;
GUIButton[] buttons; GUIButton[] buttons;
public GUIMessageBox(string header, string text) public GUIMessageBox(string header, string text)
: this(header, text, new string[] {"OK"}) : this(header, text, new string[] {"OK"})
{ }
public GUIMessageBox(string header, string text, string[] buttons, Alignment textAlignment = (Alignment.Left |Alignment.Top))
{ {
frame = new GUIFrame(new Rectangle(Game1.GraphicsWidth/2-DefaultWidth/2, Game1.GraphicsHeight/2-DefaultHeight/2, DefaultWidth, DefaultHeight), this.buttons[0].OnClicked = OkClicked;
GUI.style.backGroundColor, Alignment.CenterX, GUI.style); }
frame.Padding = GUI.style.smallPadding;
public GUIMessageBox(string header, string text, string[] buttons, Alignment textAlignment = (Alignment.Left | Alignment.Top))
: base(new Rectangle(Game1.GraphicsWidth / 2 - DefaultWidth / 2, Game1.GraphicsHeight / 2 - DefaultHeight / 2, DefaultWidth, DefaultHeight),
GUI.style.backGroundColor, Alignment.CenterX, GUI.style)
{
Padding = GUI.style.smallPadding;
if (buttons == null || buttons.Length == 0) if (buttons == null || buttons.Length == 0)
{ {
@@ -31,24 +33,25 @@ namespace Subsurface
return; return;
} }
new GUITextBlock(new Rectangle(0, 5, 0, 30), header, Color.Transparent, Color.White, textAlignment, frame, true); new GUITextBlock(new Rectangle(0, 0, 0, 30), header, Color.Transparent, Color.White, textAlignment, this, true);
new GUITextBlock(new Rectangle(0,50,0,DefaultHeight-70),text, Color.Transparent, Color.White, textAlignment, frame, true); new GUITextBlock(new Rectangle(0, 30, 0, DefaultHeight - 70), text, Color.Transparent, Color.White, textAlignment, this, true);
int x = 0; int x = 0;
this.buttons = new GUIButton[buttons.Length]; this.buttons = new GUIButton[buttons.Length];
for (int i=0; i<buttons.Length; i++) for (int i = 0; i < buttons.Length; i++)
{ {
this.buttons[i] = new GUIButton(new Rectangle(x,0,150,30), buttons[i], GUI.style, Alignment.Left, frame); this.buttons[i] = new GUIButton(new Rectangle(x, 0, 150, 30), buttons[i], GUI.style, Alignment.Left | Alignment.Bottom, this);
this.buttons[i].OnClicked = ButtonClicked;
x += this.buttons[i].Rect.Width + 20; x += this.buttons[i].Rect.Width + 20;
} }
messageBoxes.Enqueue(this);
} }
private bool ButtonClicked(GUIButton button, object obj) private bool OkClicked(GUIButton button, object obj)
{ {
if (OnClicked==null) return true; messageBoxes.Dequeue();
return true;
return OnClicked(button, obj);
} }
} }
+26 -24
View File
@@ -23,17 +23,17 @@ namespace Subsurface
public static readonly Version version = Assembly.GetEntryAssembly().GetName().Version; public static readonly Version version = Assembly.GetEntryAssembly().GetName().Version;
public static GameScreen gameScreen; public static GameScreen GameScreen;
public static MainMenuScreen mainMenuScreen; public static MainMenuScreen MainMenuScreen;
public static LobbyScreen lobbyScreen; public static LobbyScreen LobbyScreen;
public static NetLobbyScreen netLobbyScreen; public static NetLobbyScreen NetLobbyScreen;
public static EditMapScreen editMapScreen; public static EditMapScreen EditMapScreen;
public static EditCharacterScreen editCharacterScreen; public static EditCharacterScreen EditCharacterScreen;
public static GameSession gameSession; public static GameSession GameSession;
public static GameClient client; public static GameClient Client;
public static GameServer server; public static GameServer Server;
public static ParticleManager particleManager; public static ParticleManager particleManager;
@@ -50,7 +50,7 @@ namespace Subsurface
public Camera Cam public Camera Cam
{ {
get { return gameScreen.Cam; } get { return GameScreen.Cam; }
} }
public static int GraphicsWidth public static int GraphicsWidth
@@ -103,7 +103,6 @@ namespace Subsurface
/// </summary> /// </summary>
protected override void Initialize() protected override void Initialize()
{ {
// TODO: Add your initialization logic here
base.Initialize(); base.Initialize();
particleManager = new ParticleManager("Content/Particles/prefabs.xml", Cam); particleManager = new ParticleManager("Content/Particles/prefabs.xml", Cam);
@@ -145,15 +144,15 @@ namespace Subsurface
AmbientSoundManager.Init("Content/Sounds/Sounds.xml"); AmbientSoundManager.Init("Content/Sounds/Sounds.xml");
Map.PreloadMaps("Content/SavedMaps"); Map.PreloadMaps("Content/SavedMaps");
gameScreen = new GameScreen(graphics.GraphicsDevice); GameScreen = new GameScreen(graphics.GraphicsDevice);
mainMenuScreen = new MainMenuScreen(this); MainMenuScreen = new MainMenuScreen(this);
lobbyScreen = new LobbyScreen(); LobbyScreen = new LobbyScreen();
netLobbyScreen = new NetLobbyScreen(); NetLobbyScreen = new NetLobbyScreen();
editMapScreen = new EditMapScreen(); EditMapScreen = new EditMapScreen();
editCharacterScreen = new EditCharacterScreen(); EditCharacterScreen = new EditCharacterScreen();
mainMenuScreen.Select(); MainMenuScreen.Select();
} }
/// <summary> /// <summary>
@@ -179,19 +178,22 @@ namespace Subsurface
PlayerInput.Update(deltaTime); PlayerInput.Update(deltaTime);
//if (PlayerInput.KeyDown(Keys.Escape)) Quit(); //if (PlayerInput.KeyDown(Keys.Escape)) Quit();
DebugConsole.Update(this, (float)deltaTime); DebugConsole.Update(this, (float)deltaTime);
if (!DebugConsole.IsOpen || server != null || client != null) Screen.Selected.Update(deltaTime); if (!DebugConsole.IsOpen || Server != null || Client != null) Screen.Selected.Update(deltaTime);
if (server != null) GUI.Update((float)deltaTime);
if (Server != null)
{ {
server.Update(); Server.Update();
} }
else if (client != null) else if (Client != null)
{ {
client.Update(); Client.Update();
} }
else else
{ {
@@ -219,7 +221,7 @@ namespace Subsurface
protected override void OnExiting(object sender, EventArgs args) protected override void OnExiting(object sender, EventArgs args)
{ {
if (client != null) client.Disconnect(); if (Client != null) Client.Disconnect();
base.OnExiting(sender, args); base.OnExiting(sender, args);
} }
+29 -11
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System.Xml.Linq;
namespace Subsurface namespace Subsurface
{ {
@@ -25,7 +26,7 @@ namespace Subsurface
set { money = (int)Math.Max(value, 0.0f); } set { money = (int)Math.Max(value, 0.0f); }
} }
public CrewManager(GameSession session) public CrewManager()
{ {
characters = new List<Character>(); characters = new List<Character>();
characterInfos = new List<CharacterInfo>(); characterInfos = new List<CharacterInfo>();
@@ -39,19 +40,17 @@ namespace Subsurface
money = 10000; money = 10000;
} }
private string CreateSaveFile(string mapName) public CrewManager(XElement element)
: this()
{ {
string path = "Content/Data/Saves/"; money = ToolBox.GetAttributeInt(element, "money", 0);
string name = Path.GetFileNameWithoutExtension(mapName); foreach (XElement subElement in element.Elements())
int i = 0;
while (File.Exists(path+name + i))
{ {
i++; if (subElement.Name.ToString().ToLower()!="character") continue;
}
return path + name + i; characterInfos.Add(new CharacterInfo(subElement));
}
} }
public bool SelectCharacter(object selection) public bool SelectCharacter(object selection)
@@ -89,7 +88,7 @@ namespace Subsurface
GUITextBlock textBlock = new GUITextBlock( GUITextBlock textBlock = new GUITextBlock(
new Rectangle(40,0,0,25), new Rectangle(40,0,0,25),
name, name,
Color.Transparent, Color.Black, Color.Transparent, Color.White,
Alignment.Left, Alignment.Left,
Alignment.Left, Alignment.Left,
frame); frame);
@@ -98,6 +97,11 @@ namespace Subsurface
new GUIImage(new Rectangle(-10,-10,0,0), character.animController.limbs[0].sprite, Alignment.Left, frame); new GUIImage(new Rectangle(-10,-10,0,0), character.animController.limbs[0].sprite, Alignment.Left, frame);
} }
public void Update(float deltaTime)
{
guiFrame.Update(deltaTime);
}
public void KillCharacter(Character killedCharacter) public void KillCharacter(Character killedCharacter)
{ {
GUIComponent characterBlock = listBox.GetChild(killedCharacter) as GUIComponent; GUIComponent characterBlock = listBox.GetChild(killedCharacter) as GUIComponent;
@@ -138,5 +142,19 @@ namespace Subsurface
{ {
guiFrame.Draw(spriteBatch); guiFrame.Draw(spriteBatch);
} }
public void Save(XElement parentElement)
{
XElement element = new XElement("crew");
element.Add(new XAttribute("money", money));
foreach (CharacterInfo ci in characterInfos)
{
ci.Save(element);
}
parentElement.Add(element);
}
} }
} }
+1 -1
View File
@@ -75,7 +75,7 @@ namespace Subsurface
if (endMessage != "" || this.endMessage == null) this.endMessage = endMessage; if (endMessage != "" || this.endMessage == null) this.endMessage = endMessage;
Game1.gameSession.EndShift(null, null); Game1.GameSession.EndShift(null, null);
} }
public static void Init() public static void Init()
+146 -63
View File
@@ -4,6 +4,9 @@ using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using System.Text;
using System.Collections.Generic;
using System.Xml.Linq;
namespace Subsurface namespace Subsurface
{ {
@@ -18,6 +21,8 @@ namespace Subsurface
public readonly GameMode gameMode; public readonly GameMode gameMode;
private GUIFrame guiRoot;
private GUIListBox chatBox; private GUIListBox chatBox;
private GUITextBox textBox; private GUITextBox textBox;
@@ -25,57 +30,85 @@ namespace Subsurface
private GUIButton endShiftButton; private GUIButton endShiftButton;
string saveFile; private string savePath;
private Map selectedMap;
private int day; private int day;
public string SaveFile
{
get { return saveFile; }
}
public int Day public int Day
{ {
get { return day; } get { return day; }
} }
public GameSession(string selectedMapFile, bool save, TimeSpan gameDuration, GameMode gameMode = null) public GameSession(Map selectedMap, TimeSpan gameDuration, GameMode gameMode = null)
{ {
taskManager = new TaskManager(this); taskManager = new TaskManager(this);
crewManager = new CrewManager(this); crewManager = new CrewManager();
hireManager = new HireManager(); hireManager = new HireManager();
savePath = SaveUtil.CreateSavePath(SaveUtil.SaveFolder);
hireManager.GenerateCharacters("Content/Characters/Human/human.xml", 10); hireManager.GenerateCharacters("Content/Characters/Human/human.xml", 10);
guiRoot = new GUIFrame(new Rectangle(0,0,Game1.GraphicsWidth,Game1.GraphicsWidth), Color.Transparent);
int width = 350, height = 100; int width = 350, height = 100;
chatBox = new GUIListBox(new Rectangle( if (Game1.Client!=null || Game1.Server!=null)
Game1.GraphicsWidth - (int)GUI.style.smallPadding.X - width, {
Game1.GraphicsHeight - (int)GUI.style.smallPadding.W*2 - 25 - height, chatBox = new GUIListBox(new Rectangle(
width, height), Game1.GraphicsWidth - (int)GUI.style.smallPadding.X - width,
Color.White * 0.5f); Game1.GraphicsHeight - (int)GUI.style.smallPadding.W*2 - 25 - height,
width, height),
Color.White * 0.5f, guiRoot);
endShiftButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 240, 20, 100, 25), "End shift", Color.White, Alignment.CenterX, null); textBox = new GUITextBox(
endShiftButton.OnClicked = EndShift; new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + (int)GUI.style.smallPadding.W, chatBox.Rect.Width, 25),
Color.White * 0.5f, Color.Black, Alignment.Bottom, Alignment.Left, guiRoot);
textBox.OnEnter = EnterChatMessage;
}
timerBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth - 120, 20, 100, 25), Color.Gold, 0.0f, null); if (Game1.Client==null)
{
endShiftButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 240, 20, 100, 25), "End shift", Color.White, Alignment.Left | Alignment.Top, guiRoot);
endShiftButton.OnClicked = EndShift;
}
timerBar = new GUIProgressBar(new Rectangle(Game1.GraphicsWidth - 120, 20, 100, 25), Color.Gold, 0.0f, guiRoot);
textBox = new GUITextBox(
new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + (int)GUI.style.smallPadding.W, chatBox.Rect.Width, 25),
Color.White * 0.5f, Color.Black, Alignment.Bottom, Alignment.Left);
textBox.OnEnter = EnterChatMessage;
this.gameMode = gameMode; this.gameMode = gameMode;
if (this.gameMode != null) this.gameMode.Start(Game1.netLobbyScreen.GameDuration); if (this.gameMode != null) this.gameMode.Start(Game1.NetLobbyScreen.GameDuration);
startTime = DateTime.Now; startTime = DateTime.Now;
endTime = startTime + gameDuration; endTime = startTime + gameDuration;
if (!save) return; this.selectedMap = selectedMap;
CreateSaveFile(selectedMapFile);
day = 1;
//if (!save) return;
//CreateSaveFile(selectedMapFile);
day = 1;
}
public GameSession(string filePath)
: this(null, new TimeSpan(0,0,0,0))
{
XDocument doc = ToolBox.TryLoadXml(filePath);
if (doc == null) return;
day = ToolBox.GetAttributeInt(doc.Root,"day",1);
foreach (XElement subElement in doc.Root.Elements())
{
if (subElement.Name.ToString().ToLower()=="crew")
{
crewManager = new CrewManager(subElement);
}
}
savePath = filePath;
} }
public bool TryHireCharacter(CharacterInfo characterInfo) public bool TryHireCharacter(CharacterInfo characterInfo)
@@ -99,32 +132,58 @@ namespace Subsurface
{ {
if (crewManager.characterInfos.Count == 0) return; if (crewManager.characterInfos.Count == 0) return;
if (Map.Loaded!=selectedMap) selectedMap.Load();
crewManager.StartShift(); crewManager.StartShift();
taskManager.StartShift(scriptedEventCount); taskManager.StartShift(scriptedEventCount);
} }
public bool EndShift(GUIButton button, object obj) public bool EndShift(GUIButton button, object obj)
{ {
if (Game1.server!=null) if (Game1.Server!=null)
{ {
string endMessage = gameMode.EndMessage; string endMessage = gameMode.EndMessage;
Game1.server.EndGame(endMessage); Game1.Server.EndGame(endMessage);
} }
else if (Game1.client==null) else if (Game1.Client==null)
{ {
if (saveFile == null) return false; StringBuilder sb = new StringBuilder();
List<Character> casualties = crewManager.characters.FindAll(c => c.IsDead);
Map.Loaded.SaveAs(Path.GetDirectoryName(saveFile) + "/"+ Path.GetFileName(saveFile)); if (casualties.Any())
{
sb.Append("Casualties: \n");
foreach (Character c in casualties)
{
sb.Append(" - " + c.info.name + "\n");
}
}
else
{
sb.Append("No casualties!");
}
new GUIMessageBox("Day #" + day + " is over!\n", sb.ToString());
//if (saveFile == null) return false;
//Map.Loaded.SaveAs(saveFile);
crewManager.EndShift(); crewManager.EndShift();
Game1.lobbyScreen.Select(); Game1.LobbyScreen.Select();
day++; day++;
} }
for (int i = Character.characterList.Count - 1; i >= 0; i--)
{
Character.characterList.RemoveAt(i);
}
taskManager.EndShift(); taskManager.EndShift();
return true; return true;
@@ -132,46 +191,46 @@ namespace Subsurface
private void CreateSaveFile(string mapName) private void CreateSaveFile(string mapName)
{ {
string path = "Content/Data/Saves/"; //string path = "Content/Data/Saves/";
if (!Directory.Exists(path)) //if (!Directory.Exists(path))
{ //{
Directory.CreateDirectory(path); // Directory.CreateDirectory(path);
} //}
string name = Path.GetFileNameWithoutExtension(mapName); //string name = Path.GetFileNameWithoutExtension(mapName);
string extension = Path.GetExtension(mapName); //string extension = Path.GetExtension(mapName);
int i = 0; //int i = 0;
while (File.Exists(path + name + i + extension)) //while (File.Exists(path + name + i + extension))
{ //{
i++; // i++;
} //}
saveFile = path + name + i+extension; //saveFile = path + name + i+extension;
try //try
{ //{
File.Copy(mapName, saveFile); // File.Copy(mapName, saveFile);
} //}
catch (Exception e) //catch (Exception e)
{ //{
DebugConsole.ThrowError("Copying map file ''" + mapName + "'' to ''" + saveFile + "'' failed", e); // DebugConsole.ThrowError("Copying map file ''" + mapName + "'' to ''" + saveFile + "'' failed", e);
} //}
} }
public bool EnterChatMessage(GUITextBox textBox, string message) public bool EnterChatMessage(GUITextBox textBox, string message)
{ {
if (string.IsNullOrWhiteSpace(message)) return false; if (string.IsNullOrWhiteSpace(message)) return false;
if (Game1.server!=null) if (Game1.Server!=null)
{ {
Game1.server.SendChatMessage(message); Game1.Server.SendChatMessage(message);
} }
else if (Game1.client!=null) else if (Game1.Client!=null)
{ {
Game1.client.SendChatMessage(Game1.client.Name + ": " + message); Game1.Client.SendChatMessage(Game1.Client.Name + ": " + message);
} }
textBox.Deselect(); textBox.Deselect();
@@ -197,8 +256,14 @@ namespace Subsurface
public void Update(float deltaTime) public void Update(float deltaTime)
{ {
taskManager.Update(deltaTime); taskManager.Update(deltaTime);
if (endShiftButton!=null) endShiftButton.Enabled = !taskManager.CriticalTasks;
textBox.Update(deltaTime);
guiRoot.Update(deltaTime);
crewManager.Update(deltaTime);
//endShiftButton.Update(deltaTime);
//textBox.Update(deltaTime);
if (gameMode != null) gameMode.Update(); if (gameMode != null) gameMode.Update();
@@ -222,15 +287,33 @@ namespace Subsurface
public void Draw(SpriteBatch spriteBatch) public void Draw(SpriteBatch spriteBatch)
{ {
guiRoot.Draw(spriteBatch);
crewManager.Draw(spriteBatch); crewManager.Draw(spriteBatch);
taskManager.Draw(spriteBatch); taskManager.Draw(spriteBatch);
chatBox.Draw(spriteBatch); //chatBox.Draw(spriteBatch);
textBox.Draw(spriteBatch); //textBox.Draw(spriteBatch);
timerBar.Draw(spriteBatch); //timerBar.Draw(spriteBatch);
if (Game1.client == null) endShiftButton.Draw(spriteBatch); //if (Game1.Client == null) endShiftButton.Draw(spriteBatch);
}
public void Save(string filePath)
{
XDocument doc = new XDocument(
new XElement((XName)"Gamesession"));
doc.Root.Add(new XAttribute("day", day));
try
{
doc.Save(filePath);
}
catch
{
DebugConsole.ThrowError("Saving gamesession to ''" + filePath + "'' failed!");
}
} }
} }
} }
+4 -4
View File
@@ -40,21 +40,21 @@ namespace Subsurface
if (traitor==null || target ==null) if (traitor==null || target ==null)
{ {
int clientCount = Game1.server.connectedClients.Count(); int clientCount = Game1.Server.connectedClients.Count();
if (clientCount < 2) return; if (clientCount < 2) return;
int traitorIndex = Game1.localRandom.Next(clientCount); int traitorIndex = Game1.localRandom.Next(clientCount);
traitor = Game1.server.connectedClients[traitorIndex]; traitor = Game1.Server.connectedClients[traitorIndex];
int targetIndex = 0; int targetIndex = 0;
while (targetIndex==traitorIndex) while (targetIndex==traitorIndex)
{ {
targetIndex = Game1.localRandom.Next(clientCount); targetIndex = Game1.localRandom.Next(clientCount);
} }
target = Game1.server.connectedClients[targetIndex]; target = Game1.Server.connectedClients[targetIndex];
Game1.server.NewTraitor(traitor, target); Game1.Server.NewTraitor(traitor, target);
} }
else else
{ {
+5
View File
@@ -4,6 +4,11 @@ namespace Subsurface
{ {
interface IPropertyObject interface IPropertyObject
{ {
string Name
{
get;
}
Dictionary<string, ObjectProperty> ObjectProperties Dictionary<string, ObjectProperty> ObjectProperties
{ {
get; get;
+7 -41
View File
@@ -115,54 +115,20 @@ namespace Subsurface.Items.Components
foreach (StatusEffect effect in ri.statusEffects) foreach (StatusEffect effect in ri.statusEffects)
{ {
if (effect.Targets.HasFlag(StatusEffect.Target.This)) effect.Apply(ActionType.OnContaining, deltaTime, item); if (effect.Targets.HasFlag(StatusEffect.TargetType.This)) effect.Apply(ActionType.OnContaining, deltaTime, item.SimPosition, item.AllPropertyObjects);
if (effect.Targets.HasFlag(StatusEffect.Target.Contained)) effect.Apply(ActionType.OnContaining, deltaTime, contained); if (effect.Targets.HasFlag(StatusEffect.TargetType.Contained)) effect.Apply(ActionType.OnContaining, deltaTime, item.SimPosition, contained.AllPropertyObjects);
} }
contained.ApplyStatusEffects(ActionType.OnContained, deltaTime); contained.ApplyStatusEffects(ActionType.OnContained, deltaTime);
} }
//if (hideItems) return;
//Vector2 transformedItemPos;
//Vector2 transformedItemInterval = itemInterval;
////float transformedItemRotation = itemRotation;
//if (item.body==null)
//{
// transformedItemPos = new Vector2(item.Rect.X, item.Rect.Y);
// transformedItemPos = ConvertUnits.ToSimUnits(transformedItemPos) + itemPos;
//}
//else
//{
// Matrix transform = Matrix.CreateRotationZ(item.body.Rotation);
// transformedItemPos = item.body.Position + Vector2.Transform(itemPos, transform);
// transformedItemInterval = Vector2.Transform(transformedItemInterval, transform);
// //transformedItemRotation += item.body.Rotation;
//}
//foreach (Item containedItem in inventory.items)
//{
// if (containedItem == null) continue;
// Vector2 itemDist = (transformedItemPos - containedItem.body.Position);
// Vector2 force = (itemDist - containedItem.body.LinearVelocity * 0.1f) * containedItem.body.Mass * 60.0f;
// containedItem.body.ApplyForce(force);
// containedItem.body.SmoothRotate(itemRotation);
// transformedItemPos += transformedItemInterval;
//}
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
base.Draw(spriteBatch); base.Draw(spriteBatch);
if (hideItems) return; if (hideItems || (item.body!=null && !item.body.Enabled)) return;
Vector2 transformedItemPos = itemPos; Vector2 transformedItemPos = itemPos;
Vector2 transformedItemInterval = itemInterval; Vector2 transformedItemInterval = itemInterval;
@@ -175,6 +141,8 @@ namespace Subsurface.Items.Components
} }
else else
{ {
//item.body.Enabled = true;
Matrix transform = Matrix.CreateRotationZ(item.body.Rotation); Matrix transform = Matrix.CreateRotationZ(item.body.Rotation);
if (item.body.Dir==-1.0f) if (item.body.Dir==-1.0f)
@@ -184,9 +152,7 @@ namespace Subsurface.Items.Components
} }
transformedItemPos = Vector2.Transform(transformedItemPos, transform); transformedItemPos = Vector2.Transform(transformedItemPos, transform);
transformedItemInterval = Vector2.Transform(transformedItemInterval, transform); transformedItemInterval = Vector2.Transform(transformedItemInterval, transform);
transformedItemPos += ConvertUnits.ToDisplayUnits(item.body.Position); transformedItemPos += ConvertUnits.ToDisplayUnits(item.body.Position);
currentRotation += item.body.Rotation; currentRotation += item.body.Rotation;
@@ -230,7 +196,7 @@ namespace Subsurface.Items.Components
if (inventory.TryPutItem(item)) if (inventory.TryPutItem(item))
{ {
isActive = true; isActive = true;
if (hideItems) item.body.Enabled = false; if (hideItems || (item.body!=null && !item.body.Enabled)) item.body.Enabled = false;
item.container = this.item; item.container = this.item;
+4 -4
View File
@@ -134,14 +134,14 @@ namespace Subsurface.Items.Components
} }
} }
public override bool Use(Character activator = null) public override bool Use(float deltaTime, Character activator = null)
{ {
character = activator; character = activator;
foreach (MapEntity e in item.linkedTo) foreach (MapEntity e in item.linkedTo)
{ {
Item linkedItem = e as Item; Item linkedItem = e as Item;
if (linkedItem == null) continue; if (linkedItem == null) continue;
linkedItem.Use(activator); linkedItem.Use(deltaTime, activator);
} }
ApplyStatusEffects(ActionType.OnUse, 1.0f, character); ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
@@ -149,7 +149,7 @@ namespace Subsurface.Items.Components
return true; return true;
} }
public override void SecondaryUse(Character character = null) public override void SecondaryUse(float deltaTime, Character character = null)
{ {
if (character == null) return; if (character == null) return;
@@ -157,7 +157,7 @@ namespace Subsurface.Items.Components
{ {
Item linkedItem = e as Item; Item linkedItem = e as Item;
if (linkedItem == null) continue; if (linkedItem == null) continue;
linkedItem.SecondaryUse(character); linkedItem.SecondaryUse(deltaTime, character);
} }
} }
+23 -4
View File
@@ -19,6 +19,21 @@ namespace Subsurface.Items.Components
ConvexHull convexHull; ConvexHull convexHull;
ConvexHull convexHull2; ConvexHull convexHull2;
private float stuck;
public float Stuck
{
get { return stuck; }
set
{
if (isOpen) return;
stuck = MathHelper.Clamp(value, 0.0f, 100.0f);
if (stuck == 0.0f) isStuck = false;
if (stuck == 100.0f) isStuck = true;
}
}
private bool isStuck;
Gap LinkedGap Gap LinkedGap
{ {
get get
@@ -35,8 +50,9 @@ namespace Subsurface.Items.Components
return linkedGap; return linkedGap;
} }
} }
bool isOpen; bool isOpen;
float openState; float openState;
[HasDefaultValue("0.0,0.0,0.0,0.0", false)] [HasDefaultValue("0.0,0.0,0.0,0.0", false)]
@@ -199,7 +215,7 @@ namespace Subsurface.Items.Components
{ {
base.Move(amount); base.Move(amount);
linkedGap.Move(amount); LinkedGap.Move(amount);
body.SetTransform(body.Position + ConvertUnits.ToSimUnits(amount), 0.0f); body.SetTransform(body.Position + ConvertUnits.ToSimUnits(amount), 0.0f);
@@ -217,9 +233,12 @@ namespace Subsurface.Items.Components
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
OpenState += deltaTime * ((isOpen) ? 3.0f : -3.0f); if (!isStuck)
{
OpenState += deltaTime * ((isOpen) ? 3.0f : -3.0f);
LinkedGap.Open = openState;
}
LinkedGap.Open = openState;
item.SendSignal((isOpen) ? "1" : "0", "state_out"); item.SendSignal((isOpen) ? "1" : "0", "state_out");
} }
+2 -2
View File
@@ -166,7 +166,7 @@ namespace Subsurface.Items.Components
return true; return true;
} }
public override bool Use(Character character = null) public override bool Use(float deltaTime, Character character = null)
{ {
if (!attachable || item.body==null) return false; if (!attachable || item.body==null) return false;
@@ -213,7 +213,7 @@ namespace Subsurface.Items.Components
public override void OnMapLoaded() public override void OnMapLoaded()
{ {
if (attached) Use(); if (attached) Use(1.0f);
} }
} }
} }
+42 -8
View File
@@ -9,6 +9,7 @@ using Microsoft.Xna.Framework.Graphics;
using Subsurface.Networking; using Subsurface.Networking;
using Subsurface.Items.Components; using Subsurface.Items.Components;
using System.IO; using System.IO;
using System.Globalization;
namespace Subsurface namespace Subsurface
{ {
@@ -17,6 +18,8 @@ namespace Subsurface
public readonly Sound sound; public readonly Sound sound;
public readonly ActionType type; public readonly ActionType type;
public string volumeProperty;
public readonly float range; public readonly float range;
public ItemSound(Sound sound, ActionType type, float range) public ItemSound(Sound sound, ActionType type, float range)
@@ -143,6 +146,7 @@ namespace Subsurface
switch (subElement.Name.ToString().ToLower()) switch (subElement.Name.ToString().ToLower())
{ {
case "requireditem": case "requireditem":
case "requireditems":
RelatedItem ri = RelatedItem.Load(subElement); RelatedItem ri = RelatedItem.Load(subElement);
if (ri != null) requiredItems.Add(ri); if (ri != null) requiredItems.Add(ri);
break; break;
@@ -172,8 +176,9 @@ namespace Subsurface
Sound sound = Sound.Load(filePath); Sound sound = Sound.Load(filePath);
float range = ToolBox.GetAttributeFloat(subElement, "range", 800.0f); float range = ToolBox.GetAttributeFloat(subElement, "range", 800.0f);
ItemSound itemSound = new ItemSound(sound, type, range);
sounds.Add(new ItemSound(sound, type, range)); itemSound.volumeProperty = ToolBox.GetAttributeString(subElement, "volume", "");
sounds.Add(itemSound);
break; break;
} }
@@ -193,16 +198,30 @@ namespace Subsurface
int index = Game1.localRandom.Next(matchingSounds.Count); int index = Game1.localRandom.Next(matchingSounds.Count);
itemSound = sounds[index]; itemSound = sounds[index];
if (itemSound.volumeProperty != "")
{
ObjectProperty op = null;
if (properties.TryGetValue(itemSound.volumeProperty.ToLower(), out op))
{
float newVolume = 0.0f;
float.TryParse(op.GetValue().ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out newVolume);
volume = MathHelper.Clamp(newVolume, 0.0f, 1.0f);
}
}
if (loop) loopingSound = itemSound; if (loop) loopingSound = itemSound;
} }
if (loop) if (loop)
{ {
//if (loopingSound != null && loopingSound.volumeProperty != "") volume = float.Parse(properties[loopingSound.volumeProperty].GetValue().ToString());
loopingSoundIndex = loopingSound.sound.Loop(loopingSoundIndex, volume, position, loopingSound.range); loopingSoundIndex = loopingSound.sound.Loop(loopingSoundIndex, volume, position, loopingSound.range);
} }
else else
{ {
itemSound.sound.Play(volume, itemSound.range, position); itemSound.sound.Play(volume, itemSound.range, position);
} }
} }
@@ -246,13 +265,13 @@ namespace Subsurface
//called when the item is equipped and left mouse button is pressed //called when the item is equipped and left mouse button is pressed
//returns true if the item was used succesfully (not out of ammo, reloading, etc) //returns true if the item was used succesfully (not out of ammo, reloading, etc)
public virtual bool Use(Character character = null) public virtual bool Use(float deltaTime, Character character = null)
{ {
return false; return false;
} }
//called when the item is equipped and right mouse button is pressed //called when the item is equipped and right mouse button is pressed
public virtual void SecondaryUse(Character character = null) { } public virtual void SecondaryUse(float deltaTime, Character character = null) { }
//called when the item is placed in a "limbslot" //called when the item is placed in a "limbslot"
public virtual void Equip(Character character) { } public virtual void Equip(Character character) { }
@@ -272,7 +291,13 @@ namespace Subsurface
return false; return false;
} }
public virtual void Remove() { } public virtual void Remove()
{
if (loopingSound!=null)
{
Sounds.SoundManager.Stop(loopingSoundIndex);
}
}
public bool HasRequiredContainedItems(bool addMessage) public bool HasRequiredContainedItems(bool addMessage)
{ {
@@ -329,12 +354,21 @@ namespace Subsurface
return true; return true;
} }
public void ApplyStatusEffects(ActionType type, float deltaTime, Character character = null, Limb limb = null) public void ApplyStatusEffects(ActionType type, float deltaTime, Character character = null)
{ {
foreach (StatusEffect effect in statusEffects) foreach (StatusEffect effect in statusEffects)
{ {
if (effect.type != type) continue; if (effect.type != type) continue;
item.ApplyStatusEffect(effect, type, deltaTime, character, limb); item.ApplyStatusEffect(effect, type, deltaTime, character);
}
}
public void ApplyStatusEffects(ActionType type, float deltaTime, Vector2 position, IPropertyObject target)
{
foreach (StatusEffect effect in statusEffects)
{
if (effect.type != type) continue;
effect.Apply(type, deltaTime, position, target);
} }
} }
+16 -3
View File
@@ -8,13 +8,15 @@ namespace Subsurface.Items.Components
{ {
PropertyTask powerUpTask; PropertyTask powerUpTask;
float powerDownTimer;
bool running; bool running;
List<Vent> ventList; List<Vent> ventList;
public bool IsRunning() public bool IsRunning()
{ {
return running && item.Condition>0.0f; return (running && item.Condition>0.0f);
} }
public OxygenGenerator(Item item, XElement element) public OxygenGenerator(Item item, XElement element)
@@ -38,13 +40,18 @@ namespace Subsurface.Items.Components
if (voltage < minVoltage) if (voltage < minVoltage)
{ {
powerDownTimer += deltaTime;
running = false; running = false;
if (powerUpTask==null || powerUpTask.IsFinished) if ((powerUpTask==null || powerUpTask.IsFinished) && powerDownTimer>5.0f)
{ {
powerUpTask = new PropertyTask(Game1.gameSession.taskManager, item, IsRunning, 30.0f, "Turn on the oxygen generator"); powerUpTask = new PropertyTask(item, IsRunning, 50.0f, "Turn on the oxygen generator");
} }
return; return;
} }
else
{
powerDownTimer = 0.0f;
}
running = true; running = true;
@@ -53,9 +60,15 @@ namespace Subsurface.Items.Components
UpdateVents(deltaOxygen); UpdateVents(deltaOxygen);
voltage = 0.0f; voltage = 0.0f;
} }
public override void UpdateBroken(float deltaTime, Camera cam)
{
powerDownTimer += deltaTime;
}
private void GetVents() private void GetVents()
{ {
foreach (MapEntity entity in item.linkedTo) foreach (MapEntity entity in item.linkedTo)
+1 -1
View File
@@ -48,7 +48,7 @@ namespace Subsurface.Items.Components
if (!picker.HasSelectedItem(item) && item.body!=null) item.body.Enabled = false; if (!picker.HasSelectedItem(item) && item.body!=null) item.body.Enabled = false;
this.picker = picker; this.picker = picker;
ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker, null); ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker);
//foreach (StatusEffect effect in item.Prefab.statusEffects) //foreach (StatusEffect effect in item.Prefab.statusEffects)
//{ //{
+2 -1
View File
@@ -1,4 +1,5 @@
using System; using System;
using System.Globalization;
using System.Xml.Linq; using System.Xml.Linq;
namespace Subsurface.Items.Components namespace Subsurface.Items.Components
@@ -62,7 +63,7 @@ namespace Subsurface.Items.Components
{ {
if (connection.name=="power_in") if (connection.name=="power_in")
{ {
if (!float.TryParse(signal, out voltage)) if (!float.TryParse(signal, NumberStyles.Any, CultureInfo.InvariantCulture, out voltage))
{ {
voltage = 0.0f; voltage = 0.0f;
} }
+2 -2
View File
@@ -75,11 +75,11 @@ namespace Subsurface.Items.Components
//} //}
public override bool Use(Character character = null) public override bool Use(float deltaTime, Character character = null)
{ {
if (character != null && !characterUsable) return false; if (character != null && !characterUsable) return false;
ApplyStatusEffects(ActionType.OnUse, 1.0f, character); //ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
Debug.WriteLine(item.body.Rotation); Debug.WriteLine(item.body.Rotation);
+9 -6
View File
@@ -14,10 +14,11 @@ namespace Subsurface.Items.Components
private Vector2 barrelPos; private Vector2 barrelPos;
//[Initable(new Vector2(0.0f, 0.0f))] [HasDefaultValue("0.0,0.0", false)]
public Vector2 BarrelPos public string BarrelPos
{ {
get { return new Vector2(barrelPos.X * item.body.Dir, barrelPos.Y); } get { return ToolBox.Vector2ToString(ConvertUnits.ToDisplayUnits(barrelPos)); }
set { barrelPos = ConvertUnits.ToSimUnits(ToolBox.ParseToVector2(value)); }
} }
public Vector2 TransformedBarrelPos public Vector2 TransformedBarrelPos
@@ -25,7 +26,9 @@ namespace Subsurface.Items.Components
get get
{ {
Matrix bodyTransform = Matrix.CreateRotationZ(item.body.Rotation); Matrix bodyTransform = Matrix.CreateRotationZ(item.body.Rotation);
return (Vector2.Transform(BarrelPos, bodyTransform) + item.body.Position); Vector2 flippedPos = barrelPos;
if (item.body.Dir < 0.0f) flippedPos.X = -flippedPos.X;
return (Vector2.Transform(flippedPos, bodyTransform) + item.body.Position);
} }
} }
@@ -47,7 +50,7 @@ namespace Subsurface.Items.Components
} }
} }
public override bool Use(Character character = null) public override bool Use(float deltaTime, Character character = null)
{ {
if (character == null) return false; if (character == null) return false;
if (!character.SecondaryKeyDown.State || reload > 0.0f) return false; if (!character.SecondaryKeyDown.State || reload > 0.0f) return false;
@@ -78,7 +81,7 @@ namespace Subsurface.Items.Components
projectile.SetTransform(TransformedBarrelPos, projectile.SetTransform(TransformedBarrelPos,
(item.body.Dir == 1.0f) ? item.body.Rotation : item.body.Rotation - MathHelper.Pi); (item.body.Dir == 1.0f) ? item.body.Rotation : item.body.Rotation - MathHelper.Pi);
projectile.Use(); projectile.Use(deltaTime);
item.RemoveContained(projectile); item.RemoveContained(projectile);
//recoil //recoil
+4 -5
View File
@@ -108,9 +108,8 @@ namespace Subsurface.Items.Components
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
ApplyStatusEffects(ActionType.OnActive, deltaTime, null); //ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
fissionRate = Math.Min(fissionRate, AvailableFuel); fissionRate = Math.Min(fissionRate, AvailableFuel);
float heat = 100 * fissionRate; float heat = 100 * fissionRate;
@@ -128,7 +127,7 @@ namespace Subsurface.Items.Components
{ {
if (powerUpTask==null || powerUpTask.IsFinished) if (powerUpTask==null || powerUpTask.IsFinished)
{ {
powerUpTask = new PropertyTask(Game1.gameSession.taskManager, item, IsRunning, 20.0f, "Power up the reactor"); powerUpTask = new PropertyTask(item, IsRunning, 50.0f, "Power up the reactor");
} }
} }
@@ -208,7 +207,7 @@ namespace Subsurface.Items.Components
{ {
if (item.Condition <= 0.0f) return; if (item.Condition <= 0.0f) return;
new RepairTask(Game1.gameSession.taskManager, item, 50.0f, "Reactor meltdown!"); new RepairTask(item, 60.0f, "Reactor meltdown!");
item.Condition = 0.0f; item.Condition = 0.0f;
fissionRate = 0.0f; fissionRate = 0.0f;
coolingRate = 0.0f; coolingRate = 0.0f;
+72 -25
View File
@@ -5,6 +5,7 @@ using FarseerPhysics;
using FarseerPhysics.Dynamics; using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Subsurface.Particles;
namespace Subsurface.Items.Components namespace Subsurface.Items.Components
{ {
@@ -16,29 +17,49 @@ namespace Subsurface.Items.Components
Vector2 pickedPosition; Vector2 pickedPosition;
Vector2 barrelPos;
float structureFixAmount, limbFixAmount; float structureFixAmount, limbFixAmount;
[HasDefaultValue(100.0f, false)] [HasDefaultValue(0.0f, false)]
public float Range public float Range
{ {
get { return ConvertUnits.ToDisplayUnits(range); } get { return ConvertUnits.ToDisplayUnits(range); }
set { range = ConvertUnits.ToSimUnits(value); } set { range = ConvertUnits.ToSimUnits(value); }
} }
[HasDefaultValue(1.0f, false)] [HasDefaultValue(0.0f, false)]
public float StructureFixAmount public float StructureFixAmount
{ {
get { return structureFixAmount; } get { return structureFixAmount; }
set { structureFixAmount = value; } set { structureFixAmount = value; }
} }
[HasDefaultValue(1.0f, false)] [HasDefaultValue(0.0f, false)]
public float LimbFixAmount public float LimbFixAmount
{ {
get { return limbFixAmount; } get { return limbFixAmount; }
set { limbFixAmount = value; } set { limbFixAmount = value; }
} }
[HasDefaultValue("0.0,0.0", false)]
public string BarrelPos
{
get { return ToolBox.Vector2ToString(ConvertUnits.ToDisplayUnits(barrelPos)); }
set { barrelPos = ConvertUnits.ToSimUnits(ToolBox.ParseToVector2(value)); }
}
public Vector2 TransformedBarrelPos
{
get
{
Matrix bodyTransform = Matrix.CreateRotationZ(item.body.Rotation);
Vector2 flippedPos = barrelPos;
if (item.body.Dir < 0.0f) flippedPos.X = -flippedPos.X;
return (Vector2.Transform(flippedPos, bodyTransform) + item.body.Position);
}
}
public RepairTool(Item item, XElement element) public RepairTool(Item item, XElement element)
: base(item, element) : base(item, element)
{ {
@@ -69,16 +90,18 @@ namespace Subsurface.Items.Components
//} //}
public override bool Use(Character character = null) public override bool Use(float deltaTime, Character character = null)
{ {
if (character == null) return false; if (character == null) return false;
isActive = true;
Vector2 targetPosition = item.body.Position; Vector2 targetPosition = item.body.Position;
//targetPosition = targetPosition.X, -targetPosition.Y); //targetPosition = targetPosition.X, -targetPosition.Y);
targetPosition += new Vector2( targetPosition += new Vector2(
(float)Math.Cos(item.body.Rotation) * range, (float)Math.Cos(item.body.Rotation),
(float)Math.Sin(item.body.Rotation) * range) * item.body.Dir; (float)Math.Sin(item.body.Rotation)) * range * item.body.Dir;
List<Body> ignoredBodies = new List<Body>(); List<Body> ignoredBodies = new List<Body>();
foreach (Limb limb in character.animController.limbs) foreach (Limb limb in character.animController.limbs)
@@ -86,13 +109,12 @@ namespace Subsurface.Items.Components
ignoredBodies.Add(limb.body.FarseerBody); ignoredBodies.Add(limb.body.FarseerBody);
} }
Body targetBody = Map.PickBody(TransformedBarrelPos, targetPosition, ignoredBodies);
Body targetBody = Map.PickBody(item.body.Position, targetPosition, ignoredBodies);
pickedPosition = Map.LastPickedPosition; pickedPosition = Map.LastPickedPosition;
if (targetBody==null || targetBody.UserData==null) return false; if (targetBody==null || targetBody.UserData==null) return true;
ApplyStatusEffects(ActionType.OnUse, 1.0f, character); //ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
Structure targetStructure; Structure targetStructure;
@@ -100,45 +122,70 @@ namespace Subsurface.Items.Components
Item targetItem; Item targetItem;
if ((targetStructure = (targetBody.UserData as Structure)) != null) if ((targetStructure = (targetBody.UserData as Structure)) != null)
{ {
if (!fixableEntities.Contains(targetStructure.Name)) return false; if (!fixableEntities.Contains(targetStructure.Name)) return true;
int sectionIndex = targetStructure.FindSectionIndex(ConvertUnits.ToDisplayUnits(pickedPosition)); int sectionIndex = targetStructure.FindSectionIndex(ConvertUnits.ToDisplayUnits(pickedPosition));
if (sectionIndex < 0) return false; if (sectionIndex < 0) return true;
targetStructure.HighLightSection(sectionIndex); targetStructure.HighLightSection(sectionIndex);
if (character.SecondaryKeyDown.State)
{
targetStructure.AddDamage(sectionIndex, -structureFixAmount);
isActive = true;
}
} }
else if ((targetLimb = (targetBody.UserData as Limb)) != null) else if ((targetLimb = (targetBody.UserData as Limb)) != null)
{ {
if (character.SecondaryKeyDown.State) if (character.SecondaryKeyDown.State)
{ {
targetLimb.Damage -= limbFixAmount; targetLimb.character.Health += limbFixAmount;
isActive = true; //isActive = true;
} }
} }
else if ((targetItem = (targetBody.UserData as Item)) !=null) else if ((targetItem = (targetBody.UserData as Item)) != null)
{ {
targetItem.Condition -= structureFixAmount; //targetItem.Condition -= structureFixAmount;
targetItem.IsHighlighted = true;
foreach (StatusEffect effect in statusEffects)
{
//if (Array.IndexOf(effect.TargetNames, targetItem.Name) == -1) continue;
effect.Apply(ActionType.OnUse, deltaTime, item.SimPosition, targetItem.AllPropertyObjects);
//targetItem.ApplyStatusEffect(effect, ActionType.OnUse, deltaTime);
}
//ApplyStatusEffects(ActionType.OnUse, 1.0f, null, targ);
} }
//if (character.SecondaryKeyDown.State)
//{
// IPropertyObject propertyObject = targetBody.UserData as IPropertyObject;
// if (propertyObject!=null) ApplyStatusEffects(ActionType.OnUse, 1.0f, item.SimPosition, propertyObject);
// //isActive = true;
//}
return true; return true;
} }
public override void Update(float deltaTime, Camera cam)
{
base.Update(deltaTime, cam);
//isActive = true;
}
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
if (!isActive) return; if (!isActive) return;
Vector2 startPos = ConvertUnits.ToDisplayUnits(item.body.Position); Vector2 particleSpeed = new Vector2(
Vector2 endPos = ConvertUnits.ToDisplayUnits(pickedPosition); (float)Math.Cos(item.body.Rotation),
endPos = new Vector2(endPos.X + Game1.localRandom.Next(-2, 2), endPos.Y + Game1.localRandom.Next(-2, 2)); (float)Math.Sin(item.body.Rotation)) *item.body.Dir * 5.0f;
GUI.DrawLine(spriteBatch, startPos, endPos, Color.Orange, 0.0f); Game1.particleManager.CreateParticle("weld", TransformedBarrelPos, particleSpeed);
//Vector2 startPos = ConvertUnits.ToDisplayUnits(item.body.Position);
//Vector2 endPos = ConvertUnits.ToDisplayUnits(pickedPosition);
//endPos = new Vector2(endPos.X + Game1.localRandom.Next(-2, 2), endPos.Y + Game1.localRandom.Next(-2, 2));
//GUI.DrawLine(spriteBatch, startPos, endPos, Color.Orange, 0.0f);
isActive = false; isActive = false;
} }
+3 -3
View File
@@ -40,8 +40,8 @@ namespace Subsurface.Items.Components
{ {
Vector2 barrelPos = Vector2.Zero; Vector2 barrelPos = Vector2.Zero;
RangedWeapon weapon = item.GetComponent<RangedWeapon>(); //RangedWeapon weapon = item.GetComponent<RangedWeapon>();
if (weapon != null) barrelPos = weapon.BarrelPos; //if (weapon != null) barrelPos = weapon.barrelPos;
return barrelPos; return barrelPos;
} }
@@ -120,7 +120,7 @@ namespace Subsurface.Items.Components
} }
public override void SecondaryUse(Character character = null) public override void SecondaryUse(float deltaTime, Character character = null)
{ {
if (reload > 0.0f) return; if (reload > 0.0f) return;
+2 -2
View File
@@ -142,7 +142,7 @@ namespace Subsurface.Items.Components
//} //}
} }
public override bool Use(Character character = null) public override bool Use(float deltaTime, Character character = null)
{ {
if (newNodePos!= Vector2.Zero && nodes.Count>0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance) if (newNodePos!= Vector2.Zero && nodes.Count>0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
{ {
@@ -155,7 +155,7 @@ namespace Subsurface.Items.Components
return true; return true;
} }
public override void SecondaryUse(Character character = null) public override void SecondaryUse(float deltaTime, Character character = null)
{ {
if (nodes.Count > 1) if (nodes.Count > 1)
{ {
+5 -5
View File
@@ -25,7 +25,7 @@ namespace Subsurface.Items.Components
//throwForce = ToolBox.GetAttributeFloat(element, "throwforce", 1.0f); //throwForce = ToolBox.GetAttributeFloat(element, "throwforce", 1.0f);
} }
public override bool Use(Character character = null) public override bool Use(float deltaTime, Character character = null)
{ {
if (character == null) return false; if (character == null) return false;
if (!character.SecondaryKeyDown.State || throwing) return false; if (!character.SecondaryKeyDown.State || throwing) return false;
@@ -36,7 +36,7 @@ namespace Subsurface.Items.Components
return true; return true;
} }
public override void SecondaryUse(Character character = null) public override void SecondaryUse(float deltaTime, Character character = null)
{ {
if (throwing) return; if (throwing) return;
throwPos = 0.25f; throwPos = 0.25f;
@@ -54,7 +54,7 @@ namespace Subsurface.Items.Components
{ {
Update(deltaTime, cam); Update(deltaTime, cam);
} }
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
if (!item.body.Enabled) return; if (!item.body.Enabled) return;
@@ -68,11 +68,11 @@ namespace Subsurface.Items.Components
AnimController ac = picker.animController; AnimController ac = picker.animController;
ac.HoldItem(deltaTime, cam, item, handlePos, new Vector2(throwPos, 0.0f), Vector2.Zero, holdAngle); ac.HoldItem(deltaTime, cam, item, handlePos, new Vector2(throwPos, 0.0f), aimPos, holdAngle);
if (!throwing) return; if (!throwing) return;
throwPos +=0.1f; throwPos += deltaTime*5.0f;
Vector2 throwVector = ConvertUnits.ToSimUnits(picker.CursorPosition) - item.body.Position; Vector2 throwVector = ConvertUnits.ToSimUnits(picker.CursorPosition) - item.body.Position;
throwVector = Vector2.Normalize(throwVector); throwVector = Vector2.Normalize(throwVector);
+3 -3
View File
@@ -123,7 +123,7 @@ namespace Subsurface.Items.Components
//cam.OffsetAmount = prefab.OffsetOnSelected; //cam.OffsetAmount = prefab.OffsetOnSelected;
} }
public override void SecondaryUse(Character character = null) public override void SecondaryUse(float deltaTime, Character character = null)
{ {
if (character == null) return; if (character == null) return;
Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y); Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
@@ -142,7 +142,7 @@ namespace Subsurface.Items.Components
} }
} }
public override bool Use(Character character = null) public override bool Use(float deltaTime, Character character = null)
{ {
if (reload > 0.0f) return false; if (reload > 0.0f) return false;
@@ -202,7 +202,7 @@ namespace Subsurface.Items.Components
//if (useSounds.Count() > 0) useSounds[Game1.localRandom.Next(useSounds.Count())].Play(1.0f, 800.0f, item.body.FarseerBody); //if (useSounds.Count() > 0) useSounds[Game1.localRandom.Next(useSounds.Count())].Play(1.0f, 800.0f, item.body.FarseerBody);
projectileComponent.Use(); projectileComponent.Use(deltaTime);
item.RemoveContained(projectile); item.RemoveContained(projectile);
return true; return true;
+6 -14
View File
@@ -115,22 +115,14 @@ namespace Subsurface.Items.Components
Item[] containedItems = item.ContainedItems; Item[] containedItems = item.ContainedItems;
ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker);
for (int i = 0; i < limb.Length; i++) if (containedItems == null) return;
for (int j = 0; j<containedItems.Length; j++)
{ {
if (limb[i] == null) continue; if (containedItems[j] == null) continue;
ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker, limb[i]); containedItems[j].ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker);
}
if (containedItems == null) continue;
for (int j = 0; j<containedItems.Length; j++)
{
if (containedItems[j] == null) continue;
containedItems[j].ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker, limb[i]);
}
}
} }
} }
+45 -20
View File
@@ -144,6 +144,20 @@ namespace Subsurface
get { return prefab.IsLinkable; } get { return prefab.IsLinkable; }
} }
public List<IPropertyObject> AllPropertyObjects
{
get
{
List<IPropertyObject> pobjects = new List<IPropertyObject>();
pobjects.Add(this);
foreach (ItemComponent ic in components)
{
pobjects.Add(ic);
}
return pobjects;
}
}
List<string> highlightText; List<string> highlightText;
public List<string> HighlightText public List<string> HighlightText
@@ -308,18 +322,18 @@ namespace Subsurface
} }
public void ApplyStatusEffects(ActionType type, float deltaTime, Character character = null, Limb limb = null) public void ApplyStatusEffects(ActionType type, float deltaTime, Character character = null)
{ {
foreach (ItemComponent ic in components) foreach (ItemComponent ic in components)
{ {
foreach (StatusEffect effect in ic.statusEffects) foreach (StatusEffect effect in ic.statusEffects)
{ {
ApplyStatusEffect(effect, type, deltaTime, character, limb); ApplyStatusEffect(effect, type, deltaTime, character);
} }
} }
} }
public void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaTime, Character character = null, Limb limb = null) public void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaTime, Character character = null)
{ {
if (condition == 0.0f) return; if (condition == 0.0f) return;
@@ -334,9 +348,11 @@ namespace Subsurface
} }
} }
List<IPropertyObject> targets = new List<IPropertyObject>();
if (containedItems!=null) if (containedItems!=null)
{ {
if (effect.Targets.HasFlag(StatusEffect.Target.Contained)) if (effect.Targets.HasFlag(StatusEffect.TargetType.Contained))
{ {
foreach (Item containedItem in containedItems) foreach (Item containedItem in containedItems)
{ {
@@ -344,7 +360,8 @@ namespace Subsurface
if (effect.TargetNames != null && !effect.TargetNames.Contains(containedItem.Name)) continue; if (effect.TargetNames != null && !effect.TargetNames.Contains(containedItem.Name)) continue;
hasTargets = true; hasTargets = true;
effect.Apply(type, deltaTime, containedItem); targets.Add(containedItem);
//effect.Apply(type, deltaTime, containedItem);
//containedItem.ApplyStatusEffect(effect, type, deltaTime, containedItem); //containedItem.ApplyStatusEffect(effect, type, deltaTime, containedItem);
} }
} }
@@ -353,19 +370,27 @@ namespace Subsurface
if (hasTargets) if (hasTargets)
{ {
if (effect.Targets.HasFlag(StatusEffect.Target.This)) if (effect.Targets.HasFlag(StatusEffect.TargetType.This))
effect.Apply(type, deltaTime, this); {
foreach (var pobject in AllPropertyObjects)
{
targets.Add(pobject);
}
}
//effect.Apply(type, deltaTime, this);
//ApplyStatusEffect(effect, type, deltaTime, this); //ApplyStatusEffect(effect, type, deltaTime, this);
if (effect.Targets.HasFlag(StatusEffect.Target.Character)) if (effect.Targets.HasFlag(StatusEffect.TargetType.Character)) targets.Add(character);
effect.Apply(type, deltaTime, null, character, limb); //effect.Apply(type, deltaTime, null, character);
//ApplyStatusEffect(effect, type, deltaTime, null, character, limb); //ApplyStatusEffect(effect, type, deltaTime, null, character, limb);
if (container != null && effect.Targets.HasFlag(StatusEffect.Target.Parent)) if (container != null && effect.Targets.HasFlag(StatusEffect.TargetType.Parent)) targets.Add(container);
{ //{
effect.Apply(type, deltaTime, container); // effect.Apply(type, deltaTime, container);
//container.ApplyStatusEffect(effect, type, deltaTime, container); // //container.ApplyStatusEffect(effect, type, deltaTime, container);
} //}
effect.Apply(type, deltaTime, SimPosition, targets);
} }
} }
@@ -388,7 +413,7 @@ namespace Subsurface
ic.Update(deltaTime, cam); ic.Update(deltaTime, cam);
ic.PlaySound(ActionType.OnActive, 1.0f, Position, true); ic.PlaySound(ActionType.OnActive, 1.0f, Position, true);
ic.ApplyStatusEffects(ActionType.OnActive, 1.0f, null); ic.ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
} }
else else
{ {
@@ -712,28 +737,28 @@ namespace Subsurface
} }
public void Use(Character character = null) public void Use(float deltaTime, Character character = null)
{ {
if (condition == 0.0f) return; if (condition == 0.0f) return;
foreach (ItemComponent ic in components) foreach (ItemComponent ic in components)
{ {
if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue; if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue;
if (ic.Use(character)) if (ic.Use(deltaTime, character))
{ {
ic.PlaySound(ActionType.OnUse, 1.0f, Position); ic.PlaySound(ActionType.OnUse, 1.0f, Position);
ic.ApplyStatusEffects(ActionType.OnUse, 1.0f, character); ic.ApplyStatusEffects(ActionType.OnUse, deltaTime, character);
} }
} }
} }
public void SecondaryUse(Character character = null) public void SecondaryUse(float deltaTime, Character character = null)
{ {
foreach (ItemComponent ic in components) foreach (ItemComponent ic in components)
{ {
if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue; if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue;
ic.SecondaryUse(character); ic.SecondaryUse(deltaTime, character);
} }
} }
+35 -15
View File
@@ -1,14 +1,14 @@
using System; using FarseerPhysics;
using FarseerPhysics.Collision;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Xml.Linq; using System.Xml.Linq;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using FarseerPhysics.Collision;
namespace Subsurface namespace Subsurface
{ {
@@ -62,6 +62,8 @@ namespace Subsurface
{ {
get get
{ {
if (mapHash != null) return mapHash;
XDocument doc = OpenDoc(filePath); XDocument doc = OpenDoc(filePath);
mapHash = new MapHash(doc); mapHash = new MapHash(doc);
@@ -286,8 +288,7 @@ namespace Subsurface
try try
{ {
//string docString = doc.ToString(); SaveUtil.CompressStringToFile(filePath, doc.ToString());
ToolBox.CompressStringToFile(filePath+".gz", doc.ToString());
} }
catch catch
{ {
@@ -295,7 +296,18 @@ namespace Subsurface
} }
doc.Save(filePath); //doc.Save(filePath);
}
public static void SaveCurrent(string savePath)
{
if (loaded==null)
{
loaded = new Map(savePath);
return;
}
loaded.SaveAs(savePath);
} }
public static void PreloadMaps(string mapFolder) public static void PreloadMaps(string mapFolder)
@@ -342,7 +354,15 @@ namespace Subsurface
public Map(string filePath, string mapHash="") public Map(string filePath, string mapHash="")
{ {
this.filePath = filePath; this.filePath = filePath;
name = Path.GetFileNameWithoutExtension(filePath); try
{
name = Path.GetFileNameWithoutExtension(filePath);
}
catch (Exception e)
{
DebugConsole.ThrowError("Error loading map " + filePath + "!", e);
}
if (mapHash != "") if (mapHash != "")
{ {
@@ -380,7 +400,7 @@ namespace Subsurface
if (extension == ".gz") if (extension == ".gz")
{ {
Stream stream = ToolBox.DecompressFiletoStream(file); Stream stream = SaveUtil.DecompressFiletoStream(file);
if (stream == null) if (stream == null)
{ {
DebugConsole.ThrowError("Loading map ''" + file + "'' failed!"); DebugConsole.ThrowError("Loading map ''" + file + "'' failed!");
@@ -496,7 +516,7 @@ namespace Subsurface
public static void Unload() public static void Unload()
{ {
if (loaded==null)return; if (loaded == null) return;
loaded.Clear(); loaded.Clear();
loaded = null; loaded = null;
} }
@@ -505,12 +525,12 @@ namespace Subsurface
{ {
filePath = ""; filePath = "";
if (Game1.gameScreen.Cam != null) Game1.gameScreen.Cam.TargetPos = Vector2.Zero; if (Game1.GameScreen.Cam != null) Game1.GameScreen.Cam.TargetPos = Vector2.Zero;
Entity.RemoveAll(); Entity.RemoveAll();
if (Game1.gameSession!=null) if (Game1.GameSession!=null)
Game1.gameSession.crewManager.EndShift(); Game1.GameSession.crewManager.EndShift();
PhysicsBody.list.Clear(); PhysicsBody.list.Clear();
+1 -1
View File
@@ -345,7 +345,7 @@ namespace Subsurface
{ {
if (!prefab.HasBody || prefab.IsPlatform) return; if (!prefab.HasBody || prefab.IsPlatform) return;
if (Game1.client==null) if (Game1.Client==null)
SetDamage(sectionIndex, sections[sectionIndex].damage + damage); SetDamage(sectionIndex, sections[sectionIndex].damage + damage);
+17 -17
View File
@@ -134,11 +134,11 @@ namespace Subsurface.Networking
int existingClients = inc.ReadInt32(); int existingClients = inc.ReadInt32();
for (int i = 1; i <= existingClients; i++) for (int i = 1; i <= existingClients; i++)
{ {
Game1.netLobbyScreen.AddPlayer(inc.ReadString()); Game1.NetLobbyScreen.AddPlayer(inc.ReadString());
} }
//add the name of own client to the lobby screen //add the name of own client to the lobby screen
Game1.netLobbyScreen.AddPlayer(name); Game1.NetLobbyScreen.AddPlayer(name);
CanStart = true; CanStart = true;
} }
@@ -147,7 +147,7 @@ namespace Subsurface.Networking
string msg = inc.ReadString(); string msg = inc.ReadString();
DebugConsole.ThrowError(msg); DebugConsole.ThrowError(msg);
Game1.mainMenuScreen.Select(); Game1.MainMenuScreen.Select();
} }
break; break;
case NetIncomingMessageType.StatusChanged: case NetIncomingMessageType.StatusChanged:
@@ -172,8 +172,8 @@ namespace Subsurface.Networking
if (myCharacter.IsDead) if (myCharacter.IsDead)
{ {
Character.Controlled = null; Character.Controlled = null;
Game1.gameScreen.Cam.TargetPos = Vector2.Zero; Game1.GameScreen.Cam.TargetPos = Vector2.Zero;
Game1.gameScreen.Cam.Zoom = 1.0f; Game1.GameScreen.Cam.Zoom = 1.0f;
} }
else else
{ {
@@ -228,7 +228,7 @@ namespace Subsurface.Networking
string mapName = inc.ReadString(); string mapName = inc.ReadString();
string mapHash = inc.ReadString(); string mapHash = inc.ReadString();
Game1.netLobbyScreen.TrySelectMap(mapName, mapHash); Game1.NetLobbyScreen.TrySelectMap(mapName, mapHash);
//Map.Load(mapFile); //Map.Load(mapFile);
@@ -240,8 +240,8 @@ namespace Subsurface.Networking
TimeSpan duration = new TimeSpan(0,(int)durationMinutes,0); TimeSpan duration = new TimeSpan(0,(int)durationMinutes,0);
//int gameModeIndex = inc.ReadInt32(); //int gameModeIndex = inc.ReadInt32();
Game1.gameSession = new GameSession("", false, duration); Game1.GameSession = new GameSession(Map.Loaded, duration);
Game1.gameSession.StartShift(1); Game1.GameSession.StartShift(1);
myCharacter = ReadCharacterData(inc); myCharacter = ReadCharacterData(inc);
Character.Controlled = myCharacter; Character.Controlled = myCharacter;
@@ -254,7 +254,7 @@ namespace Subsurface.Networking
gameStarted = true; gameStarted = true;
Game1.gameScreen.Select(); Game1.GameScreen.Select();
AddChatMessage("Press TAB to chat", ChatMessageType.Server); AddChatMessage("Press TAB to chat", ChatMessageType.Server);
@@ -268,7 +268,7 @@ namespace Subsurface.Networking
Client otherClient = new Client(); Client otherClient = new Client();
otherClient.name = inc.ReadString(); otherClient.name = inc.ReadString();
Game1.netLobbyScreen.AddPlayer(otherClient.name); Game1.NetLobbyScreen.AddPlayer(otherClient.name);
//string newPlayerName = inc.ReadString(); //string newPlayerName = inc.ReadString();
//int newPlayerID = inc.ReadInt32(); //int newPlayerID = inc.ReadInt32();
@@ -285,7 +285,7 @@ namespace Subsurface.Networking
string leavingName = inc.ReadString(); string leavingName = inc.ReadString();
AddChatMessage(inc.ReadString(), ChatMessageType.Server); AddChatMessage(inc.ReadString(), ChatMessageType.Server);
Game1.netLobbyScreen.RemovePlayer(leavingName); Game1.NetLobbyScreen.RemovePlayer(leavingName);
break; break;
case (byte)PacketTypes.KickedOut: case (byte)PacketTypes.KickedOut:
@@ -293,7 +293,7 @@ namespace Subsurface.Networking
DebugConsole.ThrowError(msg); DebugConsole.ThrowError(msg);
Game1.mainMenuScreen.Select(); Game1.MainMenuScreen.Select();
break; break;
case (byte)PacketTypes.Chatmessage: case (byte)PacketTypes.Chatmessage:
@@ -307,13 +307,13 @@ namespace Subsurface.Networking
break; break;
case (byte)PacketTypes.UpdateNetLobby: case (byte)PacketTypes.UpdateNetLobby:
if (gameStarted) continue; if (gameStarted) continue;
Game1.netLobbyScreen.ReadData(inc); Game1.NetLobbyScreen.ReadData(inc);
break; break;
case (byte)PacketTypes.Traitor: case (byte)PacketTypes.Traitor:
string targetName = inc.ReadString(); string targetName = inc.ReadString();
Game1.gameSession.NewChatMessage("You are an agent of Ordo Europae", messageColor[(int)ChatMessageType.Server]); Game1.GameSession.NewChatMessage("You are an agent of Ordo Europae", messageColor[(int)ChatMessageType.Server]);
Game1.gameSession.NewChatMessage("Your secret task is to assassinate " + targetName + "!", messageColor[(int)ChatMessageType.Server]); Game1.GameSession.NewChatMessage("Your secret task is to assassinate " + targetName + "!", messageColor[(int)ChatMessageType.Server]);
break; break;
} }
@@ -325,9 +325,9 @@ namespace Subsurface.Networking
{ {
Map.Unload(); Map.Unload();
Game1.netLobbyScreen.Select(); Game1.NetLobbyScreen.Select();
if (Game1.gameSession!=null) Game1.gameSession.EndShift(null, null); if (Game1.GameSession!=null) Game1.GameSession.EndShift(null, null);
DebugConsole.ThrowError(endMessage); DebugConsole.ThrowError(endMessage);
+13 -13
View File
@@ -119,7 +119,7 @@ namespace Subsurface.Networking
else else
{ {
Game1.netLobbyScreen.AddPlayer(sender.name); Game1.NetLobbyScreen.AddPlayer(sender.name);
// Notify the client that they have logged in // Notify the client that they have logged in
outmsg = Server.CreateMessage(); outmsg = Server.CreateMessage();
@@ -271,12 +271,12 @@ namespace Subsurface.Networking
int seed = DateTime.Now.Millisecond; int seed = DateTime.Now.Millisecond;
Game1.random = new Random(seed); Game1.random = new Random(seed);
Map selectedMap = Game1.netLobbyScreen.SelectedMap as Map; Map selectedMap = Game1.NetLobbyScreen.SelectedMap as Map;
selectedMap.Load(); //selectedMap.Load();
Game1.gameSession = new GameSession("", false, Game1.netLobbyScreen.GameDuration, Game1.netLobbyScreen.SelectedMode); Game1.GameSession = new GameSession(selectedMap, Game1.NetLobbyScreen.GameDuration, Game1.NetLobbyScreen.SelectedMode);
Game1.gameSession.StartShift(1); Game1.GameSession.StartShift(1);
//EventManager.SelectEvent(Game1.netLobbyScreen.SelectedEvent); //EventManager.SelectEvent(Game1.netLobbyScreen.SelectedEvent);
foreach (Client client in connectedClients) foreach (Client client in connectedClients)
@@ -307,10 +307,10 @@ namespace Subsurface.Networking
msg.Write(seed); msg.Write(seed);
msg.Write(Game1.netLobbyScreen.SelectedMap.Name); msg.Write(Game1.NetLobbyScreen.SelectedMap.Name);
msg.Write(Game1.netLobbyScreen.SelectedMap.MapHash.MD5Hash); msg.Write(Game1.NetLobbyScreen.SelectedMap.MapHash.MD5Hash);
msg.Write(Game1.netLobbyScreen.GameDuration.TotalMinutes); msg.Write(Game1.NetLobbyScreen.GameDuration.TotalMinutes);
WriteCharacterData(msg, client.name, client.character); WriteCharacterData(msg, client.name, client.character);
@@ -331,9 +331,9 @@ namespace Subsurface.Networking
gameStarted = true; gameStarted = true;
Game1.gameScreen.Cam.TargetPos = Vector2.Zero; Game1.GameScreen.Cam.TargetPos = Vector2.Zero;
Game1.gameScreen.Select(); Game1.GameScreen.Select();
return true; return true;
} }
@@ -362,7 +362,7 @@ namespace Subsurface.Networking
} }
} }
Game1.netLobbyScreen.Select(); Game1.NetLobbyScreen.Select();
DebugConsole.ThrowError(endMessage); DebugConsole.ThrowError(endMessage);
} }
@@ -394,7 +394,7 @@ namespace Subsurface.Networking
outmsg.Write(client.name); outmsg.Write(client.name);
outmsg.Write(msg); outmsg.Write(msg);
Game1.netLobbyScreen.RemovePlayer(client.name); Game1.NetLobbyScreen.RemovePlayer(client.name);
if (Server.Connections.Count > 0) if (Server.Connections.Count > 0)
{ {
@@ -435,7 +435,7 @@ namespace Subsurface.Networking
{ {
NetOutgoingMessage msg = Server.CreateMessage(); NetOutgoingMessage msg = Server.CreateMessage();
msg.Write((byte)PacketTypes.UpdateNetLobby); msg.Write((byte)PacketTypes.UpdateNetLobby);
Game1.netLobbyScreen.WriteData(msg); Game1.NetLobbyScreen.WriteData(msg);
if (Server.Connections.Count > 0) if (Server.Connections.Count > 0)
{ {
+2 -2
View File
@@ -53,11 +53,11 @@ namespace Subsurface.Networking
{ {
if (isClient) if (isClient)
{ {
if (Game1.server != null) return; if (Game1.Server != null) return;
} }
else else
{ {
if (Game1.server == null) return; if (Game1.Server == null) return;
} }
eventType = type; eventType = type;
+2 -2
View File
@@ -37,8 +37,8 @@ namespace Subsurface.Networking
public void AddChatMessage(string message, ChatMessageType messageType) public void AddChatMessage(string message, ChatMessageType messageType)
{ {
Game1.netLobbyScreen.NewChatMessage(message, messageColor[(int)messageType]); Game1.NetLobbyScreen.NewChatMessage(message, messageColor[(int)messageType]);
if (Game1.gameSession != null) Game1.gameSession.NewChatMessage(message, messageColor[(int)messageType]); if (Game1.GameSession != null) Game1.GameSession.NewChatMessage(message, messageColor[(int)messageType]);
GUI.PlayMessageSound(); GUI.PlayMessageSound();
} }
+185
View File
@@ -0,0 +1,185 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
namespace Subsurface
{
class SaveUtil
{
public const string SaveFolder = "Content/SavedMaps/";
public delegate void ProgressDelegate(string sMessage);
public static void SaveGame(string directory)
{
if (Directory.Exists(directory))
{
Directory.Delete(directory, true);
}
Directory.CreateDirectory(directory);
Map.Loaded.SaveAs(directory+"\\map.gz");
Game1.GameSession.Save(directory+"\\gamesession.xml");
//Game1.GameSession.crewManager.Save(directory+"\\crew.xml");
CompressDirectory(directory, directory+".save", null);
Directory.Delete(directory, true);
}
public static void LoadGame(string filePath)
{
DecompressToDirectory(filePath+".save", Path.GetDirectoryName(filePath)+"\\temp", null);
Map.Load(Path.GetDirectoryName(filePath) + "\\temp\\map.gz");
Game1.GameSession = new GameSession(Path.GetDirectoryName(filePath) + "\\temp\\gamesession.gz");
}
public static string CreateSavePath(string saveFolder, string fileName="save")
{
if (!Directory.Exists(saveFolder))
{
DebugConsole.ThrowError("Save folder ''"+saveFolder+"'' not found. Created new folder");
Directory.CreateDirectory(saveFolder);
}
string extension = ".save";
int i = 0;
while (File.Exists(saveFolder + fileName + i + extension))
{
i++;
}
return saveFolder + fileName + i + extension;
}
public static void CompressStringToFile(string fileName, string value)
{
// A.
// Write string to temporary file.
string temp = Path.GetTempFileName();
File.WriteAllText(temp, value);
// B.
// Read file into byte array buffer.
byte[] b;
using (FileStream f = new FileStream(temp, FileMode.Open))
{
b = new byte[f.Length];
f.Read(b, 0, (int)f.Length);
}
// C.
// Use GZipStream to write compressed bytes to target file.
using (FileStream f2 = new FileStream(fileName, FileMode.Create))
using (GZipStream gz = new GZipStream(f2, CompressionMode.Compress, false))
{
gz.Write(b, 0, b.Length);
}
}
public static Stream DecompressFiletoStream(string fileName)
{
if (!File.Exists(fileName))
{
DebugConsole.ThrowError("File ''"+fileName+" doesn't exist!");
return null;
}
using (FileStream originalFileStream = new FileStream(fileName, FileMode.Open))
{
MemoryStream decompressedFileStream = new MemoryStream();
using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
{
decompressionStream.CopyTo(decompressedFileStream);
return decompressedFileStream;
}
}
}
public static void CompressFile(string sDir, string sRelativePath, GZipStream zipStream)
{
//Compress file name
char[] chars = sRelativePath.ToCharArray();
zipStream.Write(BitConverter.GetBytes(chars.Length), 0, sizeof(int));
foreach (char c in chars)
zipStream.Write(BitConverter.GetBytes(c), 0, sizeof(char));
//Compress file content
byte[] bytes = File.ReadAllBytes(Path.Combine(sDir, sRelativePath));
zipStream.Write(BitConverter.GetBytes(bytes.Length), 0, sizeof(int));
zipStream.Write(bytes, 0, bytes.Length);
}
public static bool DecompressFile(string sDir, GZipStream zipStream, ProgressDelegate progress)
{
//Decompress file name
byte[] bytes = new byte[sizeof(int)];
int Readed = zipStream.Read(bytes, 0, sizeof(int));
if (Readed < sizeof(int))
return false;
int iNameLen = BitConverter.ToInt32(bytes, 0);
bytes = new byte[sizeof(char)];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < iNameLen; i++)
{
zipStream.Read(bytes, 0, sizeof(char));
char c = BitConverter.ToChar(bytes, 0);
sb.Append(c);
}
string sFileName = sb.ToString();
if (progress != null)
progress(sFileName);
//Decompress file content
bytes = new byte[sizeof(int)];
zipStream.Read(bytes, 0, sizeof(int));
int iFileLen = BitConverter.ToInt32(bytes, 0);
bytes = new byte[iFileLen];
zipStream.Read(bytes, 0, bytes.Length);
string sFilePath = Path.Combine(sDir, sFileName);
string sFinalDir = Path.GetDirectoryName(sFilePath);
if (!Directory.Exists(sFinalDir))
Directory.CreateDirectory(sFinalDir);
using (FileStream outFile = new FileStream(sFilePath, FileMode.Create, FileAccess.Write, FileShare.None))
outFile.Write(bytes, 0, iFileLen);
return true;
}
public static void CompressDirectory(string sInDir, string sOutFile, ProgressDelegate progress)
{
string[] sFiles = Directory.GetFiles(sInDir, "*.*", SearchOption.AllDirectories);
int iDirLen = sInDir[sInDir.Length - 1] == Path.DirectorySeparatorChar ? sInDir.Length : sInDir.Length + 1;
using (FileStream outFile = new FileStream(sOutFile, FileMode.Create, FileAccess.Write, FileShare.None))
using (GZipStream str = new GZipStream(outFile, CompressionMode.Compress))
foreach (string sFilePath in sFiles)
{
string sRelativePath = sFilePath.Substring(iDirLen);
if (progress != null)
progress(sRelativePath);
CompressFile(sInDir, sRelativePath, str);
}
}
public static void DecompressToDirectory(string sCompressedFile, string sDir, ProgressDelegate progress)
{
using (FileStream inFile = new FileStream(sCompressedFile, FileMode.Open, FileAccess.Read, FileShare.None))
using (GZipStream zipStream = new GZipStream(inFile, CompressionMode.Decompress, true))
while (DecompressFile(sDir, zipStream, progress)) ;
}
}
}
+1 -1
View File
@@ -74,7 +74,7 @@ namespace Subsurface
if (physicsEnabled) if (physicsEnabled)
{ {
editingCharacter.Control(cam); editingCharacter.Control(1.0f, cam);
} }
else else
{ {
+2 -2
View File
@@ -94,7 +94,7 @@ namespace Subsurface
public override void Select() public override void Select()
{ {
base.Select(); base.Select();
GUIComponent.MouseOn = null; GUIComponent.MouseOn = null;
characterMode = false; characterMode = false;
//CreateDummyCharacter(); //CreateDummyCharacter();
@@ -197,7 +197,7 @@ namespace Subsurface
} }
dummyCharacter.ControlLocalPlayer(cam, false); dummyCharacter.ControlLocalPlayer(cam, false);
dummyCharacter.Control(cam); dummyCharacter.Control((float)deltaTime, cam);
} }
else else
{ {
+14 -3
View File
@@ -38,7 +38,7 @@ namespace Subsurface
{ {
base.Select(); base.Select();
if (Game1.gameSession == null) Game1.gameSession = new GameSession("",false, TimeSpan.Zero); //if (Game1.gameSession == null) Game1.gameSession = new GameSession("",false, TimeSpan.Zero);
foreach (MapEntity entity in MapEntity.mapEntityList) foreach (MapEntity entity in MapEntity.mapEntityList)
entity.IsHighlighted = false; entity.IsHighlighted = false;
@@ -57,7 +57,18 @@ namespace Subsurface
AmbientSoundManager.Update(); AmbientSoundManager.Update();
Game1.gameSession.Update((float)deltaTime); //Vector2 targetMovement = Vector2.Zero;
//if (PlayerInput.KeyDown(Keys.I)) targetMovement.Y += 1.0f;
//if (PlayerInput.KeyDown(Keys.K)) targetMovement.Y -= 1.0f;
//if (PlayerInput.KeyDown(Keys.J)) targetMovement.X -= 1.0f;
//if (PlayerInput.KeyDown(Keys.L)) targetMovement.X += 1.0f;
//foreach (MapEntity e in Structure.mapEntityList)
//{
// e.Move(targetMovement);
//}
if (Game1.GameSession!=null) Game1.GameSession.Update((float)deltaTime);
//EventManager.Update(gameTime); //EventManager.Update(gameTime);
Character.UpdateAll(cam, (float)deltaTime); Character.UpdateAll(cam, (float)deltaTime);
@@ -107,7 +118,7 @@ namespace Subsurface
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
spriteBatch.Begin(); spriteBatch.Begin();
if (Game1.gameSession != null) Game1.gameSession.Draw(spriteBatch); if (Game1.GameSession != null) Game1.GameSession.Draw(spriteBatch);
//EventManager.DrawInfo(spriteBatch); //EventManager.DrawInfo(spriteBatch);
+24 -14
View File
@@ -96,7 +96,7 @@ namespace Subsurface
{ {
base.Select(); base.Select();
Map.Unload(); //Map.Unload();
UpdateCharacterLists(); UpdateCharacterLists();
@@ -105,7 +105,7 @@ namespace Subsurface
private void UpdateCharacterLists() private void UpdateCharacterLists()
{ {
characterList.ClearChildren(); characterList.ClearChildren();
foreach (CharacterInfo c in Game1.gameSession.crewManager.characterInfos) foreach (CharacterInfo c in Game1.GameSession.crewManager.characterInfos)
{ {
GUITextBlock textBlock = new GUITextBlock( GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25), new Rectangle(0, 0, 0, 25),
@@ -117,7 +117,7 @@ namespace Subsurface
} }
hireList.ClearChildren(); hireList.ClearChildren();
foreach (CharacterInfo c in Game1.gameSession.hireManager.availableCharacters) foreach (CharacterInfo c in Game1.GameSession.hireManager.availableCharacters)
{ {
GUIFrame frame = new GUIFrame( GUIFrame frame = new GUIFrame(
new Rectangle(0, 0, 0, 25), new Rectangle(0, 0, 0, 25),
@@ -144,18 +144,27 @@ namespace Subsurface
} }
} }
public override void Update(double deltaTime)
{
base.Update(deltaTime);
leftPanel.Update((float)deltaTime);
rightPanel[selectedRightPanel].Update((float)deltaTime);
shiftPanel.Update((float)deltaTime);
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{ {
if (characterList.CountChildren != Game1.gameSession.crewManager.characterInfos.Count if (characterList.CountChildren != Game1.GameSession.crewManager.characterInfos.Count
|| hireList.CountChildren != Game1.gameSession.hireManager.availableCharacters.Count) || hireList.CountChildren != Game1.GameSession.hireManager.availableCharacters.Count)
{ {
UpdateCharacterLists(); UpdateCharacterLists();
} }
graphics.Clear(Color.CornflowerBlue); graphics.Clear(Color.CornflowerBlue);
Game1.gameScreen.DrawMap(graphics, spriteBatch); Game1.GameScreen.DrawMap(graphics, spriteBatch);
spriteBatch.Begin(); spriteBatch.Begin();
@@ -182,20 +191,20 @@ namespace Subsurface
private string GetMoney() private string GetMoney()
{ {
return "Money: " + ((Game1.gameSession == null) ? "" : Game1.gameSession.crewManager.Money.ToString()); return "Money: " + ((Game1.GameSession == null) ? "" : Game1.GameSession.crewManager.Money.ToString());
} }
private string GetDay() private string GetDay()
{ {
return "Day #" + ((Game1.gameSession == null) ? "" : Game1.gameSession.Day.ToString()); return "Day #" + ((Game1.GameSession == null) ? "" : Game1.GameSession.Day.ToString());
} }
private float GetWeekProgress() private float GetWeekProgress()
{ {
if (Game1.gameSession == null) return 0.0f; if (Game1.GameSession == null) return 0.0f;
return (float)((Game1.gameSession.Day - 1) % 7) / 7.0f; return (float)((Game1.GameSession.Day - 1) % 7) / 7.0f;
} }
private bool HireCharacter(object selection) private bool HireCharacter(object selection)
@@ -206,20 +215,21 @@ namespace Subsurface
if (characterInfo == null) return false; if (characterInfo == null) return false;
Game1.gameSession.TryHireCharacter(characterInfo); Game1.GameSession.TryHireCharacter(characterInfo);
return false; return false;
} }
private bool StartShift(GUIButton button, object selection) private bool StartShift(GUIButton button, object selection)
{ {
Map.Load(Game1.gameSession.SaveFile);
//Map.Load(Game1.GameSession.SaveFile);
Game1.gameSession.StartShift(); Game1.GameSession.StartShift();
//EventManager.StartShift(); //EventManager.StartShift();
Game1.gameScreen.Select(); Game1.GameScreen.Select();
return true; return true;
} }
+23 -26
View File
@@ -55,23 +55,20 @@ namespace Subsurface
new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected map:", Color.Transparent, Color.Black, Alignment.Left, menuTabs[(int)Tabs.NewGame]); new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected map:", Color.Transparent, Color.Black, Alignment.Left, menuTabs[(int)Tabs.NewGame]);
mapList = new GUIListBox(new Rectangle(0, 60, 200, 400), Color.White, menuTabs[1]); mapList = new GUIListBox(new Rectangle(0, 60, 200, 400), Color.White, menuTabs[1]);
//string[] mapFilePaths = Map.GetMapFilePaths(); foreach (Map map in Map.SavedMaps)
//if (mapFilePaths!=null) {
//{ GUITextBlock textBlock = new GUITextBlock(
foreach (Map map in Map.SavedMaps) new Rectangle(0, 0, 0, 25),
{ map.Name,
GUITextBlock textBlock = new GUITextBlock( GUI.style,
new Rectangle(0, 0, 0, 25), Alignment.Left,
map.Name, Alignment.Left,
GUI.style, mapList);
Alignment.Left, textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
Alignment.Left, textBlock.UserData = map;
mapList); }
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f); if (Map.SavedMaps.Count > 0) mapList.Select(Map.SavedMaps[0]);
textBlock.UserData = map;
}
if (Map.SavedMaps.Count > 0) mapList.Select(Map.SavedMaps[0]);
//}
button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", GUI.style, Alignment.Right | Alignment.Bottom, menuTabs[(int)Tabs.NewGame]); button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", GUI.style, Alignment.Right | Alignment.Bottom, menuTabs[(int)Tabs.NewGame]);
button.OnClicked = StartGame; button.OnClicked = StartGame;
@@ -112,8 +109,8 @@ namespace Subsurface
private bool HostServerClicked(GUIButton button, object obj) private bool HostServerClicked(GUIButton button, object obj)
{ {
Game1.netLobbyScreen.isServer = true; Game1.NetLobbyScreen.isServer = true;
Game1.netLobbyScreen.Select(); Game1.NetLobbyScreen.Select();
return true; return true;
} }
@@ -132,7 +129,7 @@ namespace Subsurface
{ {
graphics.Clear(Color.CornflowerBlue); graphics.Clear(Color.CornflowerBlue);
Game1.gameScreen.DrawMap(graphics, spriteBatch); Game1.GameScreen.DrawMap(graphics, spriteBatch);
spriteBatch.Begin(); spriteBatch.Begin();
@@ -150,9 +147,9 @@ namespace Subsurface
if (selectedMap == null) return false; if (selectedMap == null) return false;
Game1.gameSession = new GameSession(selectedMap.FilePath, true, TimeSpan.Zero); Game1.GameSession = new GameSession(selectedMap, TimeSpan.Zero);
Game1.lobbyScreen.Select(); Game1.LobbyScreen.Select();
return true; return true;
} }
@@ -162,15 +159,15 @@ namespace Subsurface
if (string.IsNullOrEmpty(nameBox.Text)) return false; if (string.IsNullOrEmpty(nameBox.Text)) return false;
if (string.IsNullOrEmpty(ipBox.Text)) return false; if (string.IsNullOrEmpty(ipBox.Text)) return false;
Game1.client = new GameClient(nameBox.Text); Game1.Client = new GameClient(nameBox.Text);
if (Game1.client.ConnectToServer(ipBox.Text)) if (Game1.Client.ConnectToServer(ipBox.Text))
{ {
Game1.netLobbyScreen.Select(); Game1.NetLobbyScreen.Select();
return true; return true;
} }
else else
{ {
Game1.client = null; Game1.Client = null;
return false; return false;
} }
} }
+31 -30
View File
@@ -6,6 +6,7 @@ using Subsurface.Networking;
using FarseerPhysics; using FarseerPhysics;
using FarseerPhysics.Factories; using FarseerPhysics.Factories;
using FarseerPhysics.Dynamics; using FarseerPhysics.Dynamics;
using System.IO;
namespace Subsurface namespace Subsurface
{ {
@@ -122,7 +123,7 @@ namespace Subsurface
{ {
infoFrame.ClearChildren(); infoFrame.ClearChildren();
if (isServer && Game1.server == null) Game1.server = new GameServer(); if (isServer && Game1.Server == null) Game1.Server = new GameServer();
textBox.Select(); textBox.Select();
@@ -132,7 +133,7 @@ namespace Subsurface
new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected map:", Color.Transparent, Color.Black, Alignment.Left, infoFrame); new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected map:", Color.Transparent, Color.Black, Alignment.Left, infoFrame);
mapList = new GUIListBox(new Rectangle(0, 60, 200, 200), Color.White, infoFrame); mapList = new GUIListBox(new Rectangle(0, 60, 200, 200), Color.White, infoFrame);
mapList.OnSelected = SelectMap; mapList.OnSelected = SelectMap;
mapList.Enabled = (Game1.server!=null); mapList.Enabled = (Game1.Server!=null);
if (Map.SavedMaps.Count>0) if (Map.SavedMaps.Count>0)
{ {
@@ -157,7 +158,7 @@ namespace Subsurface
new GUITextBlock(new Rectangle(220, 30, 0, 30), "Selected game mode: ", Color.Transparent, Color.Black, Alignment.Left, infoFrame); new GUITextBlock(new Rectangle(220, 30, 0, 30), "Selected game mode: ", Color.Transparent, Color.Black, Alignment.Left, infoFrame);
modeList = new GUIListBox(new Rectangle(220, 60, 200, 200), Color.White, infoFrame); modeList = new GUIListBox(new Rectangle(220, 60, 200, 200), Color.White, infoFrame);
modeList.Enabled = (Game1.server != null); modeList.Enabled = (Game1.Server != null);
//modeList.OnSelected = new GUIListBox.OnSelectedHandler(SelectEvent); //modeList.OnSelected = new GUIListBox.OnSelectedHandler(SelectEvent);
foreach (GameMode mode in GameMode.list) foreach (GameMode mode in GameMode.list)
@@ -180,16 +181,16 @@ namespace Subsurface
durationBar = new GUIScrollBar(new Rectangle((int)(modeList.Rect.X + modeList.Rect.Width + GUI.style.smallPadding.X), modeList.Rect.Y + 30, 100, 20), durationBar = new GUIScrollBar(new Rectangle((int)(modeList.Rect.X + modeList.Rect.Width + GUI.style.smallPadding.X), modeList.Rect.Y + 30, 100, 20),
Color.Gold, 0.1f, Alignment.Left, infoFrame); Color.Gold, 0.1f, Alignment.Left, infoFrame);
durationBar.BarSize = 0.1f; durationBar.BarSize = 0.1f;
durationBar.Enabled = (Game1.server != null); durationBar.Enabled = (Game1.Server != null);
if (isServer && Game1.server!=null) if (isServer && Game1.Server!=null)
{ {
GUIButton startButton = new GUIButton(new Rectangle(0,0,200,30), "Start", Color.White, Alignment.Right | Alignment.Bottom, infoFrame); GUIButton startButton = new GUIButton(new Rectangle(0,0,200,30), "Start", Color.White, Alignment.Right | Alignment.Bottom, infoFrame);
startButton.OnClicked = Game1.server.StartGame; startButton.OnClicked = Game1.Server.StartGame;
//mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby); //mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby);
modeList.OnSelected = Game1.server.UpdateNetLobby; modeList.OnSelected = Game1.Server.UpdateNetLobby;
durationBar.OnMoved = Game1.server.UpdateNetLobby; durationBar.OnMoved = Game1.Server.UpdateNetLobby;
if (mapList.CountChildren > 0) mapList.Select(Map.SavedMaps[0]); if (mapList.CountChildren > 0) mapList.Select(Map.SavedMaps[0]);
if (GameMode.list.Count > 0) modeList.Select(GameMode.list[0]); if (GameMode.list.Count > 0) modeList.Select(GameMode.list[0]);
@@ -199,7 +200,7 @@ namespace Subsurface
int x = playerFrame.Rect.Width / 2; int x = playerFrame.Rect.Width / 2;
GUITextBox playerName = new GUITextBox(new Rectangle(x, 0, 0, 20), Color.White, Color.Black, GUITextBox playerName = new GUITextBox(new Rectangle(x, 0, 0, 20), Color.White, Color.Black,
Alignment.Left | Alignment.Top, Alignment.Left, playerFrame); Alignment.Left | Alignment.Top, Alignment.Left, playerFrame);
playerName.Text = Game1.client.CharacterInfo.name; playerName.Text = Game1.Client.CharacterInfo.name;
playerName.OnEnter += ChangeCharacterName; playerName.OnEnter += ChangeCharacterName;
new GUITextBlock(new Rectangle(x,40,200, 30), "Gender: ", Color.Transparent, Color.Black, new GUITextBlock(new Rectangle(x,40,200, 30), "Gender: ", Color.Transparent, Color.Black,
@@ -240,7 +241,7 @@ namespace Subsurface
private bool SelectMap(object obj) private bool SelectMap(object obj)
{ {
if (Game1.server != null) Game1.server.UpdateNetLobby(obj); if (Game1.Server != null) Game1.Server.UpdateNetLobby(obj);
Map map = (Map)obj; Map map = (Map)obj;
@@ -275,7 +276,7 @@ namespace Subsurface
{ {
base.Update(deltaTime); base.Update(deltaTime);
Game1.gameScreen.Cam.MoveCamera((float)deltaTime); Game1.GameScreen.Cam.MoveCamera((float)deltaTime);
Vector2 pos = new Vector2( Vector2 pos = new Vector2(
Map.Borders.X + Map.Borders.Width / 2, Map.Borders.X + Map.Borders.Width / 2,
@@ -288,7 +289,7 @@ namespace Subsurface
pos += offset * 0.8f; pos += offset * 0.8f;
Game1.gameScreen.Cam.TargetPos = pos; Game1.GameScreen.Cam.TargetPos = pos;
menu.Update((float)deltaTime); menu.Update((float)deltaTime);
@@ -299,7 +300,7 @@ namespace Subsurface
{ {
graphics.Clear(Color.CornflowerBlue); graphics.Clear(Color.CornflowerBlue);
Game1.gameScreen.DrawMap(graphics, spriteBatch); Game1.GameScreen.DrawMap(graphics, spriteBatch);
spriteBatch.Begin(); spriteBatch.Begin();
@@ -310,18 +311,18 @@ namespace Subsurface
spriteBatch.End(); spriteBatch.End();
if (Game1.client != null) if (Game1.Client != null)
{ {
if (Game1.client.Character != null) if (Game1.Client.Character != null)
{ {
Vector2 position = new Vector2(playerFrame.Rect.X + playerFrame.Rect.Width * 0.25f, playerFrame.Rect.Y + 25.0f); Vector2 position = new Vector2(playerFrame.Rect.X + playerFrame.Rect.Width * 0.25f, playerFrame.Rect.Y + 25.0f);
Vector2 pos = Game1.client.Character.Position; Vector2 pos = Game1.Client.Character.Position;
pos.Y = -pos.Y; pos.Y = -pos.Y;
Matrix transform = Matrix.CreateTranslation(new Vector3(-pos+position, 0.0f)); Matrix transform = Matrix.CreateTranslation(new Vector3(-pos+position, 0.0f));
spriteBatch.Begin(SpriteSortMode.BackToFront, null,null,null,null,null,transform); spriteBatch.Begin(SpriteSortMode.BackToFront, null,null,null,null,null,transform);
Game1.client.Character.Draw(spriteBatch); Game1.Client.Character.Draw(spriteBatch);
spriteBatch.End(); spriteBatch.End();
} }
else else
@@ -346,7 +347,7 @@ namespace Subsurface
public bool StartGame(object obj) public bool StartGame(object obj)
{ {
Game1.server.StartGame(null, obj); Game1.Server.StartGame(null, obj);
return true; return true;
} }
@@ -356,11 +357,11 @@ namespace Subsurface
if (isServer) if (isServer)
{ {
Game1.server.SendChatMessage("Server: " + message); Game1.Server.SendChatMessage("Server: " + message);
} }
else else
{ {
Game1.client.SendChatMessage(Game1.client.Name + ": " + message); Game1.Client.SendChatMessage(Game1.Client.Name + ": " + message);
} }
return true; return true;
@@ -368,13 +369,13 @@ namespace Subsurface
private void CreatePreviewCharacter() private void CreatePreviewCharacter()
{ {
if (Game1.client.Character != null) Game1.client.Character.Remove(); if (Game1.Client.Character != null) Game1.Client.Character.Remove();
Vector2 pos = new Vector2(1000.0f, 1000.0f); Vector2 pos = new Vector2(1000.0f, 1000.0f);
Character character = new Character(Game1.client.CharacterInfo, pos); Character character = new Character(Game1.Client.CharacterInfo, pos);
Game1.client.Character = character; Game1.Client.Character = character;
character.animController.isStanding = true; character.animController.isStanding = true;
@@ -406,8 +407,8 @@ namespace Subsurface
try try
{ {
Gender gender = (Gender)obj; Gender gender = (Gender)obj;
Game1.client.CharacterInfo.gender = gender; Game1.Client.CharacterInfo.gender = gender;
Game1.client.SendCharacterData(); Game1.Client.SendCharacterData();
CreatePreviewCharacter(); CreatePreviewCharacter();
} }
catch catch
@@ -421,9 +422,9 @@ namespace Subsurface
{ {
if (string.IsNullOrEmpty(newName)) return false; if (string.IsNullOrEmpty(newName)) return false;
Game1.client.CharacterInfo.name = newName; Game1.Client.CharacterInfo.name = newName;
Game1.client.Name = newName; Game1.Client.Name = newName;
Game1.client.SendCharacterData(); Game1.Client.SendCharacterData();
textBox.Text = newName; textBox.Text = newName;
@@ -472,7 +473,7 @@ namespace Subsurface
} }
else else
{ {
msg.Write(selectedMap.Name); msg.Write(Path.GetFileName(selectedMap.FilePath));
msg.Write(selectedMap.MapHash.MD5Hash); msg.Write(selectedMap.MapHash.MD5Hash);
} }
@@ -502,7 +503,7 @@ namespace Subsurface
else else
{ {
mapList.Select(map); mapList.Select(map);
map.Load(); //map.Load();
return true; return true;
} }
} }
+102 -1
View File
@@ -6,6 +6,7 @@ using FarseerPhysics;
using FarseerPhysics.Dynamics; using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Subsurface.Sounds; using Subsurface.Sounds;
using System.Collections.Generic;
namespace Subsurface namespace Subsurface
{ {
@@ -33,14 +34,36 @@ namespace Subsurface
} }
} }
public class BackgroundMusic
{
public readonly string file;
public readonly string type;
public readonly Vector2 priorityRange;
public BackgroundMusic(string file, string type, Vector2 priorityRange)
{
this.file = file;
this.type = type;
this.priorityRange = priorityRange;
}
}
static class AmbientSoundManager static class AmbientSoundManager
{ {
public static Sound[] flowSounds = new Sound[3]; public static Sound[] flowSounds = new Sound[3];
private const float MusicLerpSpeed = 0.01f;
private static Sound waterAmbience; private static Sound waterAmbience;
private static int waterAmbienceIndex; private static int waterAmbienceIndex;
private static DamageSound[] damageSounds; private static DamageSound[] damageSounds;
private static BackgroundMusic currentMusic;
private static BackgroundMusic targetMusic;
private static BackgroundMusic[] musicClips;
private static float musicVolume;
public static void Init(string filePath) public static void Init(string filePath)
{ {
@@ -57,7 +80,7 @@ namespace Subsurface
var xDamageSounds = doc.Root.Elements("damagesound").ToList(); var xDamageSounds = doc.Root.Elements("damagesound").ToList();
if (!xDamageSounds.Any()) if (xDamageSounds.Any())
{ {
damageSounds = new DamageSound[xDamageSounds.Count()]; damageSounds = new DamageSound[xDamageSounds.Count()];
int i = 0; int i = 0;
@@ -85,6 +108,24 @@ namespace Subsurface
} }
} }
var xMusic = doc.Root.Elements("music").ToList();
if (xMusic.Any())
{
musicClips = new BackgroundMusic[xMusic.Count];
int i = 0;
foreach (XElement element in xMusic)
{
string file = ToolBox.GetAttributeString(element, "file", "").ToLower();
string type = ToolBox.GetAttributeString(element, "type", "").ToLower();
Vector2 priority = ToolBox.GetAttributeVector2(element, "priorityrange", new Vector2(0.0f,100.0f));
musicClips[i] = new BackgroundMusic(file, type, priority);
i++;
}
}
//Sound.StartStream("Content/Sounds/Music/Simplex.ogg", 0.3f); //Sound.StartStream("Content/Sounds/Music/Simplex.ogg", 0.3f);
} }
@@ -92,6 +133,8 @@ namespace Subsurface
public static void Update() public static void Update()
{ {
UpdateMusic();
float ambienceVolume = 0.5f; float ambienceVolume = 0.5f;
float lowpassHFGain = 1.0f; float lowpassHFGain = 1.0f;
if (Character.Controlled != null) if (Character.Controlled != null)
@@ -110,6 +153,64 @@ namespace Subsurface
waterAmbienceIndex = waterAmbience.Loop(waterAmbienceIndex, ambienceVolume); waterAmbienceIndex = waterAmbience.Loop(waterAmbienceIndex, ambienceVolume);
} }
private static void UpdateMusic()
{
Task criticalTask = null;
if (Game1.GameSession!=null)
{
foreach (Task task in Game1.GameSession.taskManager.Tasks)
{
if (criticalTask == null || task.Priority > criticalTask.Priority)
{
criticalTask = task;
}
}
}
List<BackgroundMusic> suitableMusic = null;
if (criticalTask == null)
{
suitableMusic = musicClips.Where(x => x.type == "default").ToList();
}
else
{
suitableMusic = musicClips.Where(x =>
x.type == criticalTask.MusicType &&
x.priorityRange.X < criticalTask.Priority &&
x.priorityRange.Y > criticalTask.Priority).ToList();
}
if (suitableMusic.Count > 0 && !suitableMusic.Contains(currentMusic))
{
int index = Game1.localRandom.Next(suitableMusic.Count());
if (currentMusic == null || suitableMusic[index].file != currentMusic.file)
{
targetMusic = suitableMusic[index];
}
}
if (targetMusic == null || currentMusic == null || targetMusic.file != currentMusic.file)
{
musicVolume = MathHelper.Lerp(musicVolume, 0.0f, MusicLerpSpeed);
if (currentMusic != null) Sound.StreamVolume(musicVolume);
if (musicVolume < 0.01f)
{
Sound.StopStream();
if (targetMusic != null) Sound.StartStream(targetMusic.file, musicVolume);
currentMusic = targetMusic;
}
}
else
{
musicVolume = MathHelper.Lerp(musicVolume, 0.3f, MusicLerpSpeed);
Sound.StreamVolume(musicVolume);
}
}
public static void PlayDamageSound(DamageSoundType damageType, float damage, Body body) public static void PlayDamageSound(DamageSoundType damageType, float damage, Body body)
{ {
Vector2 bodyPosition = ConvertUnits.ToDisplayUnits(body.Position); Vector2 bodyPosition = ConvertUnits.ToDisplayUnits(body.Position);
+10 -3
View File
@@ -13,6 +13,8 @@ namespace Subsurface
private static List<Sound> loadedSounds = new List<Sound>(); private static List<Sound> loadedSounds = new List<Sound>();
private static OggStream stream;
private OggSound oggSound; private OggSound oggSound;
string filePath; string filePath;
@@ -218,12 +220,17 @@ namespace Subsurface
public static void StartStream(string file, float volume = 1.0f) public static void StartStream(string file, float volume = 1.0f)
{ {
SoundManager.StartStream(file, volume); stream = SoundManager.StartStream(file, volume);
} }
public static void Stoptream() public static void StreamVolume(float volume = 1.0f)
{ {
SoundManager.StopStream(); stream.Volume = volume;
}
public static void StopStream()
{
if (stream!=null) SoundManager.StopStream();
} }
public static void Dispose() public static void Dispose()
+46 -5
View File
@@ -133,6 +133,7 @@
<Compile Include="Particles\ParticlePrefab.cs" /> <Compile Include="Particles\ParticlePrefab.cs" />
<Compile Include="Physics\Physics.cs" /> <Compile Include="Physics\Physics.cs" />
<Compile Include="Properties.cs" /> <Compile Include="Properties.cs" />
<Compile Include="SaveUtil.cs" />
<Compile Include="Screens\EditCharacterScreen.cs" /> <Compile Include="Screens\EditCharacterScreen.cs" />
<Compile Include="EventInput\EventInput.cs" /> <Compile Include="EventInput\EventInput.cs" />
<Compile Include="EventInput\KeyboardDispatcher.cs" /> <Compile Include="EventInput\KeyboardDispatcher.cs" />
@@ -218,16 +219,28 @@
<Content Include="Content\Characters\Human\ffirstnames.txt"> <Content Include="Content\Characters\Human\ffirstnames.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Characters\Human\fhead.png"> <Content Include="Content\Characters\Human\fhead1.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\fhead2.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Characters\Human\firstnames.txt"> <Content Include="Content\Characters\Human\firstnames.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Characters\Human\head.png"> <Content Include="Content\Characters\Human\flegs.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Characters\Human\flegs.png"> <Content Include="Content\Characters\Human\head1.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\head2.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\head3.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\head4.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Characters\Human\lastnames.txt"> <Content Include="Content\Characters\Human\lastnames.txt">
@@ -271,6 +284,12 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Content> </Content>
<Content Include="Content\Items\Clothes\captainhat.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Items\Clothes\clothes.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Items\connector.png"> <Content Include="Content\Items\connector.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@@ -357,6 +376,12 @@
<Content Include="Content\Items\idcard.xml"> <Content Include="Content\Items\idcard.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Items\Tools\fueltank.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Items\Tools\plasmacutter.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Items\Weapons\harpoon.png"> <Content Include="Content\Items\Weapons\harpoon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@@ -400,10 +425,10 @@
<Content Include="Content\Items\OxygenGenerator\item.xml"> <Content Include="Content\Items\OxygenGenerator\item.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Items\OxygenTank\item.xml"> <Content Include="Content\Items\Diving\item.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Items\OxygenTank\oxygentank.png"> <Content Include="Content\Items\Diving\oxygentank.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Items\poweritems.xml"> <Content Include="Content\Items\poweritems.xml">
@@ -565,6 +590,15 @@
<None Include="Content\Items\Weapons\stunGrenade.ogg"> <None Include="Content\Items\Weapons\stunGrenade.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Content\Sounds\Damage\HitArmor1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Damage\HitArmor2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Damage\HitArmor3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Damage\implode.ogg"> <None Include="Content\Sounds\Damage\implode.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
@@ -577,6 +611,12 @@
<None Include="Content\Sounds\Damage\LimbSlash2.ogg"> <None Include="Content\Sounds\Damage\LimbSlash2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Content\Sounds\Music\Enter the Maze.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Music\Unseen Horrors.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\stepMetal.ogg"> <None Include="Content\Sounds\stepMetal.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
@@ -642,6 +682,7 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Content\Items\OxygenTank\" />
<Folder Include="Content\SavedMaps\" /> <Folder Include="Content\SavedMaps\" />
<Folder Include="Data\Saves\" /> <Folder Include="Data\Saves\" />
</ItemGroup> </ItemGroup>
+1 -1
View File
@@ -9,6 +9,6 @@
<ErrorReportUrlHistory /> <ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture> <FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles> <VerifyUploadedFiles>false</VerifyUploadedFiles>
<ProjectView>ShowAllFiles</ProjectView> <ProjectView>ProjectFiles</ProjectView>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
+39 -39
View File
@@ -128,50 +128,50 @@ namespace Subsurface
} }
public static void CompressStringToFile(string fileName, string value) //public static void CompressStringToFile(string fileName, string value)
{ //{
// A. // // A.
// Write string to temporary file. // // Write string to temporary file.
string temp = Path.GetTempFileName(); // string temp = Path.GetTempFileName();
File.WriteAllText(temp, value); // File.WriteAllText(temp, value);
// B. // // B.
// Read file into byte array buffer. // // Read file into byte array buffer.
byte[] b; // byte[] b;
using (FileStream f = new FileStream(temp, FileMode.Open)) // using (FileStream f = new FileStream(temp, FileMode.Open))
{ // {
b = new byte[f.Length]; // b = new byte[f.Length];
f.Read(b, 0, (int)f.Length); // f.Read(b, 0, (int)f.Length);
} // }
// C. // // C.
// Use GZipStream to write compressed bytes to target file. // // Use GZipStream to write compressed bytes to target file.
using (FileStream f2 = new FileStream(fileName, FileMode.Create)) // using (FileStream f2 = new FileStream(fileName, FileMode.Create))
using (GZipStream gz = new GZipStream(f2, CompressionMode.Compress, false)) // using (GZipStream gz = new GZipStream(f2, CompressionMode.Compress, false))
{ // {
gz.Write(b, 0, b.Length); // gz.Write(b, 0, b.Length);
} // }
} //}
public static Stream DecompressFiletoStream(string fileName) //public static Stream DecompressFiletoStream(string fileName)
{ //{
if (!File.Exists(fileName)) // if (!File.Exists(fileName))
{ // {
DebugConsole.ThrowError("File ''"+fileName+" doesn't exist!"); // DebugConsole.ThrowError("File ''"+fileName+" doesn't exist!");
return null; // return null;
} // }
using (FileStream originalFileStream = new FileStream(fileName, FileMode.Open)) // using (FileStream originalFileStream = new FileStream(fileName, FileMode.Open))
{ // {
MemoryStream decompressedFileStream = new MemoryStream(); // MemoryStream decompressedFileStream = new MemoryStream();
using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress)) // using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
{ // {
decompressionStream.CopyTo(decompressedFileStream); // decompressionStream.CopyTo(decompressedFileStream);
return decompressedFileStream; // return decompressedFileStream;
} // }
} // }
} //}
public static XDocument TryLoadXml(string filePath) public static XDocument TryLoadXml(string filePath)
{ {
Binary file not shown.