Quests, new sounds, explosives, bugfixes, asdfasdf

This commit is contained in:
Regalis
2015-07-29 23:40:26 +03:00
parent 7155f1cef0
commit 5d0a453e23
81 changed files with 1374 additions and 819 deletions
+2
View File
@@ -125,6 +125,8 @@ namespace Subsurface
}
}
if (allowedSlots.HasFlag(LimbSlot.BothHands)) TryPutItem(item, 3, createNetworkEvent);
return false;
}
+2 -2
View File
@@ -132,8 +132,8 @@ namespace Subsurface.Items.Components
foreach (StatusEffect effect in ri.statusEffects)
{
if (effect.Targets.HasFlag(StatusEffect.TargetType.This)) effect.Apply(ActionType.OnContaining, deltaTime, item.SimPosition, item.AllPropertyObjects);
if (effect.Targets.HasFlag(StatusEffect.TargetType.Contained)) effect.Apply(ActionType.OnContaining, deltaTime, item.SimPosition, contained.AllPropertyObjects);
if (effect.Targets.HasFlag(StatusEffect.TargetType.This)) effect.Apply(ActionType.OnContaining, deltaTime, item, item.AllPropertyObjects);
if (effect.Targets.HasFlag(StatusEffect.TargetType.Contained)) effect.Apply(ActionType.OnContaining, deltaTime, item, contained.AllPropertyObjects);
}
contained.ApplyStatusEffects(ActionType.OnContained, deltaTime);
@@ -4,12 +4,12 @@ using Microsoft.Xna.Framework;
namespace Subsurface.Items.Components
{
class Holdable : ItemComponent
class Holdable : Pickable
{
//the position(s) in the item that the character grabs
protected Vector2[] handlePos;
protected Character picker;
//protected Character picker;
//the distance from the holding characters elbow to center of the physics body of the item
protected Vector2 holdPos;
@@ -154,6 +154,8 @@ namespace Subsurface.Items.Components
public override bool Pick(Character picker)
{
if (!base.Pick(picker)) return false;
if (!attachable) return false;
//if (item.body==null)
@@ -37,10 +37,6 @@ namespace Subsurface.Items.Components
if (picker == null) return false;
if (picker.Inventory == null) return false;
//this.picker = picker;
if (picker.Inventory.TryPutItem(item, allowedSlots))
{
if (!picker.HasSelectedItem(item) && item.body!=null) item.body.Enabled = false;
@@ -151,7 +151,7 @@ namespace Subsurface.Items.Components
foreach (StatusEffect effect in statusEffects)
{
//if (Array.IndexOf(effect.TargetNames, targetItem.Name) == -1) continue;
effect.Apply(ActionType.OnUse, deltaTime, item.SimPosition, targetItem.AllPropertyObjects);
effect.Apply(ActionType.OnUse, deltaTime, item, targetItem.AllPropertyObjects);
//targetItem.ApplyStatusEffect(effect, ActionType.OnUse, deltaTime);
}
//ApplyStatusEffects(ActionType.OnUse, 1.0f, null, targ);
@@ -182,7 +182,7 @@ namespace Subsurface.Items.Components
(float)Math.Cos(item.body.Rotation),
(float)Math.Sin(item.body.Rotation)) *item.body.Dir * 5.0f;
Game1.particleManager.CreateParticle("weld", TransformedBarrelPos, particleSpeed);
Game1.ParticleManager.CreateParticle("weld", TransformedBarrelPos, particleSpeed);
//Vector2 startPos = ConvertUnits.ToDisplayUnits(item.body.Position);
//Vector2 endPos = ConvertUnits.ToDisplayUnits(pickedPosition);
+43 -24
View File
@@ -7,11 +7,10 @@ using Lidgren.Network;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Subsurface.Networking;
using Subsurface.Items.Components;
using System.IO;
using System.Globalization;
namespace Subsurface
namespace Subsurface.Items.Components
{
class ItemSound
{
@@ -20,6 +19,8 @@ namespace Subsurface
public string VolumeProperty;
public float VolumeMultiplier;
public readonly float Range;
public ItemSound(Sound sound, ActionType type, float range)
@@ -207,10 +208,10 @@ namespace Subsurface
guiFrame = new GUIFrame(
new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Z, (int)rect.W),
new Color(color.X, color.Y, color.Z, color.W), alignment);
new Color(color.X, color.Y, color.Z, color.W), alignment, GUI.style);
//guiFrame.Alpha = color.W;
break;
break;
case "sound":
string filePath = ToolBox.GetAttributeString(subElement, "file", "");
if (filePath=="") continue;
@@ -236,6 +237,7 @@ namespace Subsurface
float range = ToolBox.GetAttributeFloat(subElement, "range", 800.0f);
ItemSound itemSound = new ItemSound(sound, type, range);
itemSound.VolumeProperty = ToolBox.GetAttributeString(subElement, "volume", "");
itemSound.VolumeMultiplier = ToolBox.GetAttributeFloat(subElement, "volumemultiplier", 1.0f);
sounds.Add(itemSound);
break;
}
@@ -245,7 +247,7 @@ namespace Subsurface
private ItemSound loopingSound;
private int loopingSoundIndex;
public void PlaySound(ActionType type, float volume, Vector2 position, bool loop=false)
public void PlaySound(ActionType type, Vector2 position, bool loop=false)
{
ItemSound itemSound = null;
if (!loop || !Sounds.SoundManager.IsPlaying(loopingSoundIndex))
@@ -254,19 +256,9 @@ namespace Subsurface
if (matchingSounds.Count == 0) return;
int index = Rand.Int(matchingSounds.Count);
itemSound = sounds[index];
itemSound = matchingSounds[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;
}
@@ -274,16 +266,33 @@ namespace Subsurface
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, GetSoundVolume(loopingSound), position, loopingSound.Range);
}
else
{
itemSound.Sound.Play(volume, itemSound.Range, position);
itemSound.Sound.Play(GetSoundVolume(itemSound), itemSound.Range, position);
}
}
private float GetSoundVolume(ItemSound sound)
{
if (sound.VolumeProperty == "") return 1.0f;
ObjectProperty op = null;
if (properties.TryGetValue(sound.VolumeProperty.ToLower(), out op))
{
float newVolume = 0.0f;
float.TryParse(op.GetValue().ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out newVolume);
newVolume *= sound.VolumeMultiplier;
return MathHelper.Clamp(newVolume, 0.0f, 1.0f);
}
return 0.0f;
}
public virtual void Move(Vector2 amount) { }
/// <summary>a character has picked the item</summary>
@@ -347,7 +356,17 @@ namespace Subsurface
return false;
}
public virtual void ReceiveSignal(string signal, Connection connection, Item sender, float power = 0.0f) { }
public virtual void ReceiveSignal(string signal, Connection connection, Item sender, float power = 0.0f)
{
switch (connection.Name)
{
case "activate":
case "use":
item.Use(1.0f);
break;
}
}
public virtual bool Combine(Item item)
{
@@ -459,12 +478,12 @@ namespace Subsurface
}
}
public void ApplyStatusEffects(ActionType type, float deltaTime, Vector2 position, IPropertyObject target)
public void ApplyStatusEffects(ActionType type, float deltaTime, IPropertyObject target)
{
foreach (StatusEffect effect in statusEffects)
{
if (effect.type != type) continue;
effect.Apply(type, deltaTime, position, target);
effect.Apply(type, deltaTime, item, target);
}
}
@@ -569,7 +588,7 @@ namespace Subsurface
ConstructorInfo constructor;
try
{
if (!t.IsSubclassOf(typeof(ItemComponent))) return null;
if (t!=typeof(ItemComponent) && !t.IsSubclassOf(typeof(ItemComponent))) return null;
constructor = t.GetConstructor(new Type[] { typeof(Item), typeof(XElement) });
if (constructor == null)
{
@@ -50,7 +50,11 @@ namespace Subsurface.Items.Components
: base(item, element)
{
isActive = true;
}
public float CurrentVolume
{
get { return Math.Abs((force / 100.0f) * (voltage / minVoltage)); }
}
public override void Update(float deltaTime, Camera cam)
@@ -68,7 +72,7 @@ namespace Subsurface.Items.Components
for (int i = 0; i < 5; i++)
{
Game1.particleManager.CreateParticle("bubbles", item.SimPosition,
Game1.ParticleManager.CreateParticle("bubbles", item.SimPosition,
-currForce/500.0f + new Vector2(Rand.Range(-1.0f, 1.0f), Rand.Range(-0.5f, 0.5f)));
}
}
+45 -71
View File
@@ -1,4 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Specialized;
using System.Globalization;
using System.Xml.Linq;
@@ -16,6 +18,16 @@ namespace Subsurface.Items.Components
Hull hull1, hull2;
private float FlowPercentage
{
get { return flowPercentage; }
set
{
if (float.IsNaN(flowPercentage)) return;
flowPercentage = MathHelper.Clamp(value,-100.0f,100.0f);
}
}
[HasDefaultValue(100.0f, false)]
public float MaxFlow
{
@@ -26,7 +38,7 @@ namespace Subsurface.Items.Components
public Pump(Item item, XElement element)
: base(item, element)
{
//maxFlow = ToolBox.GetAttributeFloat(element, "maxflow", 100.0f);
flowPercentage = 100.0f;
item.linkedTo.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e)
{ GetHulls(); };
@@ -34,7 +46,7 @@ namespace Subsurface.Items.Components
public override void Update(float deltaTime, Camera cam)
{
currPowerConsumption = powerConsumption;
currPowerConsumption = powerConsumption * Math.Abs(flowPercentage / 100.0f);
if (voltage < minVoltage) return;
@@ -56,52 +68,17 @@ namespace Subsurface.Items.Components
}
hull1.Volume += deltaVolume;
if (hull2 != null) hull2.Volume -= deltaVolume;
if (hull1.Volume > hull1.FullVolume) hull1.Pressure += 0.5f;
if (hull2 != null)
{
hull2.Volume -= deltaVolume;
if (hull2.Volume > hull1.FullVolume) hull2.Pressure += 0.5f;
}
voltage = 0.0f;
}
//public override void DrawHUD(SpriteBatch spriteBatch, Character character)
//{
// int width = 300, height = 200;
// int x = Game1.GraphicsWidth / 2 - width / 2;
// int y = Game1.GraphicsHeight / 2 - height / 2;
// GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
// spriteBatch.DrawString(GUI.font, "Pumping direction: " + ((flowIn) ? "in" : "out"), new Vector2(x + 30, y + 30), Color.White);
// if (GUI.DrawButton(spriteBatch, new Rectangle(x + 30, y + 50, 80, 40), "TOGGLE")) flowIn = !flowIn;
// if (GUI.DrawButton(spriteBatch, new Rectangle(x + 30, y + 150, 100, 40), (isActive) ? "TURN OFF" : "TURN ON")) IsActive = !isActive;
//}
//public override bool Pick(Character activator = null)
//{
// //isActive = !isActive;
// hull1 = null;
// hull2 = null;
// foreach (MapEntity e in item.linkedTo)
// {
// Hull hull = e as Hull;
// if (hull == null) continue;
// if (hull1 == null)
// {
// hull1 = hull;
// }
// else if (hull2 == null && hull != hull1)
// {
// hull2 = hull;
// break;
// }
// }
// return true;
//}
private void GetHulls()
{
hull1 = null;
@@ -124,34 +101,33 @@ namespace Subsurface.Items.Components
}
}
//public override void OnMapLoaded()
//{
// hull1 = null;
// hull2 = null;
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
int x = GuiFrame.Rect.X;
int y = GuiFrame.Rect.Y;
// foreach (MapEntity e in item.linkedTo)
// {
// Hull hull = e as Hull;
// if (hull == null) continue;
GuiFrame.Draw(spriteBatch);
// if (hull1 == null)
// {
// hull1 = hull;
// }
// else if (hull2 == null && hull != hull1)
// {
// hull2 = hull;
// break;
// }
// }
//}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 20, y + 20, 100, 40), ((isActive) ? "TURN OFF" : "TURN ON")))
{
targetLevel = null;
isActive = !isActive;
}
spriteBatch.DrawString(GUI.Font, "Flow percentage: " + (int)flowPercentage + " %", new Vector2(x + 20, y + 80), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "+", true)) FlowPercentage += 1.0f;
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "-", true)) FlowPercentage -= 1.0f;
item.NewComponentEvent(this, true);
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{
base.ReceiveSignal(signal, connection, sender, power);
isActive = true;
if (connection.Name == "toggle")
{
isActive = !isActive;
@@ -176,8 +152,6 @@ namespace Subsurface.Items.Components
targetLevel = MathHelper.Clamp(tempTarget, 0.0f, 100.0f);
}
}
}
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message)
@@ -193,13 +167,13 @@ namespace Subsurface.Items.Components
try
{
newFlow = MathHelper.Clamp(message.ReadFloat(), -100.0f, 100.0f);
newFlow = message.ReadFloat();
newActive = message.ReadBoolean();
}
catch { return; }
flowPercentage = newFlow;
FlowPercentage = newFlow;
isActive = newActive;
}
}
+72 -4
View File
@@ -96,6 +96,7 @@ namespace Subsurface.Items.Components
float scale = 0.015f;
float displayScale = ConvertUnits.ToDisplayUnits(scale);
if (Level.Loaded != null)
{
@@ -109,12 +110,11 @@ namespace Subsurface.Items.Components
center + (edges[i][1] - offset) * scale, Color.White);
}
scale = ConvertUnits.ToDisplayUnits(scale);
for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++)
{
Vector2 start = Submarine.Loaded.HullVertices[i] * scale;
Vector2 start = Submarine.Loaded.HullVertices[i] * displayScale;
start.Y = -start.Y;
Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * scale;
Vector2 end = Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] * displayScale;
end.Y = -end.Y;
GUI.DrawLine(spriteBatch, center + start, center + end, Color.White);
@@ -127,7 +127,7 @@ namespace Subsurface.Items.Components
if (c.SimPosition != Vector2.Zero && c.SimPosition.Length() < 7 * Level.GridCellWidth)
{
int width = (int)Math.Min(c.Mass / 5, 30);
int width = (int)MathHelper.Clamp(c.Mass / 20, 1, 10);
Vector2 pos = c.Position * scale;
pos.Y = -pos.Y;
@@ -141,6 +141,74 @@ namespace Subsurface.Items.Components
{
screenOverlay.Draw(spriteBatch, center, 0.0f, rect.Width/screenOverlay.size.X);
}
//if (Level.Loaded != null)
//{
// for (int i = 0; i < 2; i++)
// {
// Vector2 targetPos = (i == 0) ? Level.Loaded.StartPosition : Level.Loaded.EndPosition;
// targetPos += Level.Loaded.Position;
// float dist = targetPos.Length();
// targetPos.Y = -targetPos.Y;
// Vector2 markerPos = Vector2.Normalize(targetPos) * (rect.Width * 0.55f);
// markerPos += center;
// GUI.DrawRectangle(spriteBatch, new Rectangle((int)markerPos.X, (int)markerPos.Y, 5, 5), Color.LightGreen);
// string label;
// if (Game1.GameSession.Map!=null)
// {
// label = (i == 0) ? Game1.GameSession.Map.CurrentLocation.Name : Game1.GameSession.Map.SelectedLocation.Name;
// }
// else
// {
// label = (i == 0) ? "Start" : "End";
// }
// spriteBatch.DrawString(GUI.SmallFont, label, new Vector2(markerPos.X + 10, markerPos.Y), Color.LightGreen);
// spriteBatch.DrawString(GUI.SmallFont, (int)(dist / 80.0f) + " m", new Vector2(markerPos.X + 10, markerPos.Y + 15), Color.LightGreen);
// }
DrawMarker(spriteBatch,
(Game1.GameSession.Map == null) ? "Start" : Game1.GameSession.Map.CurrentLocation.Name,
Level.Loaded.StartPosition + Level.Loaded.Position, center, (rect.Width * 0.55f));
DrawMarker(spriteBatch,
(Game1.GameSession.Map == null) ? "End" : Game1.GameSession.Map.SelectedLocation.Name,
Level.Loaded.EndPosition + Level.Loaded.Position, center, (rect.Width * 0.55f));
if (Game1.GameSession.Map != null && Game1.GameSession.Map.SelectedConnection.Quest!=null)
{
var quest = Game1.GameSession.Map.SelectedConnection.Quest;
if (!string.IsNullOrWhiteSpace(quest.RadarLabel))
{
DrawMarker(spriteBatch,
quest.RadarLabel,
quest.RadarPosition, center, (rect.Width * 0.55f));
}
}
}
private void DrawMarker(SpriteBatch spriteBatch, string label, Vector2 position, Vector2 center, float radius)
{
//position += Level.Loaded.Position;
float dist = position.Length();
position.Y = -position.Y;
Vector2 markerPos = center + Vector2.Normalize(position) * radius;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)markerPos.X, (int)markerPos.Y, 5, 5), Color.LightGreen);
spriteBatch.DrawString(GUI.SmallFont, label, new Vector2(markerPos.X + 10, markerPos.Y), Color.LightGreen);
spriteBatch.DrawString(GUI.SmallFont, (int)(dist / 80.0f) + " m", new Vector2(markerPos.X + 10, markerPos.Y + 15), Color.LightGreen);
}
private void UpdateRendertarget()
+12 -39
View File
@@ -101,6 +101,8 @@ namespace Subsurface.Items.Components
meltDownTemp = 9000.0f;
shutDownTemp = 500.0f;
powerPerTemp = 1.0f;
isActive = true;
@@ -227,39 +229,14 @@ namespace Subsurface.Items.Components
new RepairTask(item, 60.0f, "Reactor meltdown!");
item.Condition = 0.0f;
fissionRate = 0.0f;
coolingRate = 0.0f;
//fissionRate = 0.0f;
//coolingRate = 0.0f;
new Explosion(item.SimPosition, 6.0f, 500.0f, 600.0f, 10.0f, 2.0f).Explode();
//List<Structure> structureList = new List<Structure>();
//float dist = 600.0f;
//foreach (MapEntity entity in MapEntity.mapEntityList)
//{
// Structure structure = entity as Structure;
// if (structure == null) continue;
// if (structure.HasBody && Vector2.Distance(structure.Position, item.Position)<dist*3.0f)
// {
// structureList.Add(structure);
// }
//}
//foreach (Structure structure in structureList)
//{
// for (int i = 0; i < structure.SectionCount; i++)
// {
// float damage = dist - Vector2.Distance(structure.SectionPosition(i), item.Position);
// if (damage > 0.0f) structure.AddDamage(i, damage);
// }
//}
//if (item.currentHull!=null)
//{
// item.currentHull.WaveVel[item.currentHull.GetWaveIndex(item.SimPosition)] = 100.0f;
//}
//PlaySound(ActionType.OnFailure, item.Position);
//item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, null);
//new Explosion(item.SimPosition, 6.0f, 500.0f, 600.0f, 10.0f, 2.0f).Explode();
if (item.ContainedItems!=null)
{
foreach (Item containedItem in item.ContainedItems)
@@ -274,11 +251,7 @@ namespace Subsurface.Items.Components
public override bool Pick(Character picker)
{
if (picker == null) return false;
//picker.SelectedConstruction = (picker.SelectedConstruction==item) ? null : item;
return true;
return (picker != null);
}
public override void Draw(SpriteBatch spriteBatch, bool editing)
@@ -331,10 +304,10 @@ namespace Subsurface.Items.Components
y = y - 260;
spriteBatch.DrawString(GUI.Font, "Autotemp: " + ((autoTemp) ? "ON" : "OFF"), new Vector2(x + 400, y + 30), Color.White);
spriteBatch.DrawString(GUI.Font, "Automatic Temperature Control: " + ((autoTemp) ? "ON" : "OFF"), new Vector2(x + 400, y + 30), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 60, 100, 40), ((autoTemp) ? "TURN OFF" : "TURN ON"))) autoTemp = !autoTemp;
spriteBatch.DrawString(GUI.Font, "Max temperature: " + shutDownTemp, new Vector2(x + 400, y + 150), Color.White);
spriteBatch.DrawString(GUI.Font, "Shutdown Temperature: " + shutDownTemp, new Vector2(x + 400, y + 150), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 180, 40, 40), "+", true)) shutDownTemp += 100.0f;
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 450, y + 180, 40, 40), "-", true)) shutDownTemp -= 100.0f;
@@ -378,7 +351,7 @@ namespace Subsurface.Items.Components
Vector2 lastPoint = new Vector2(x,
y + height - (graph[graph.Count - 1] + (graph[graph.Count - 2] - graph[graph.Count - 1]) * xOffset) * yScale);
GUI.DrawLine(spriteBatch, prevPoint, lastPoint, Color.Red);
GUI.DrawLine(spriteBatch, prevPoint, lastPoint, Color.White);
}
public override void FillNetworkData(NetworkEventType type, NetOutgoingMessage message)
@@ -12,12 +12,33 @@ namespace Subsurface.Items.Components
{
class Steering : ItemComponent
{
Vector2 currVelocity;
Vector2 targetVelocity;
private Vector2 currVelocity;
private Vector2 targetVelocity;
bool autoPilot;
private bool autoPilot;
SteeringPath steeringPath;
private SteeringPath steeringPath;
private static PathFinder pathFinder;
bool AutoPilot
{
get { return autoPilot; }
set
{
if (value == autoPilot) return;
autoPilot = value;
if (autoPilot)
{
if (pathFinder==null) pathFinder = new PathFinder(WayPoint.WayPointList, false);
steeringPath = pathFinder.FindPath(
ConvertUnits.ToSimUnits(Level.Loaded.Position),
ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
}
}
}
private Vector2 TargetVelocity
{
@@ -43,18 +64,16 @@ namespace Subsurface.Items.Components
public override void Update(float deltaTime, Camera cam)
{
base.Update(deltaTime, cam);
if (autoPilot)
{
if (steeringPath==null)
{
PathFinder pathFinder = new PathFinder(WayPoint.WayPointList, false);
steeringPath = pathFinder.FindPath(
ConvertUnits.ToSimUnits(Level.Loaded.StartPosition),
ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
}
//if (steeringPath==null)
//{
// PathFinder pathFinder = new PathFinder(WayPoint.WayPointList, false);
// steeringPath = pathFinder.FindPath(
// ConvertUnits.ToSimUnits(Level.Loaded.StartPosition),
// ConvertUnits.ToSimUnits(Level.Loaded.EndPosition));
//}
steeringPath.GetNode(Vector2.Zero, 20.0f);
@@ -90,7 +109,7 @@ namespace Subsurface.Items.Components
if (GUI.DrawButton(spriteBatch, new Rectangle(x + width - 150, y + height - 30, 150, 30), "Autopilot"))
{
autoPilot = !autoPilot;
AutoPilot = !AutoPilot;
item.NewComponentEvent(this, true);
}
@@ -156,7 +175,7 @@ namespace Subsurface.Items.Components
}
TargetVelocity = newTargetVelocity;
autoPilot = newAutoPilot;
AutoPilot = newAutoPilot;
}
}
}
@@ -7,9 +7,9 @@ namespace Subsurface.Items.Components
{
class PowerContainer : Powered
{
//[power/min]
float capacity;
//[power/min]
float charge;
//how fast the battery can be recharged
@@ -21,12 +21,6 @@ namespace Subsurface.Items.Components
float maxOutput;
//public override float Charge
//{
// get { return charge; }
// set { Math.Max(Math.Min(charge = value, capacity), 0.0f); }
//}
[Editable, HasDefaultValue(10.0f, true)]
public float MaxOutPut
{
@@ -46,13 +40,14 @@ namespace Subsurface.Items.Components
}
[HasDefaultValue(10.0f, false)]
[HasDefaultValue(10.0f, false), Editable]
public float Capacity
{
get { return capacity; }
set { capacity = Math.Max(value,1.0f); }
}
[HasDefaultValue(10.0f, false), Editable]
public float RechargeSpeed
{
get { return rechargeSpeed; }
@@ -63,7 +58,7 @@ namespace Subsurface.Items.Components
}
}
[HasDefaultValue(10.0f, false)]
[HasDefaultValue(10.0f, false), Editable]
public float MaxRechargeSpeed
{
get { return maxRechargeSpeed; }
@@ -26,6 +26,8 @@ namespace Subsurface.Items.Components
private static Item draggingConnected;
private List<StatusEffect> effects;
int[] wireId;
public List<Connection> Recipients
@@ -67,21 +69,31 @@ namespace Subsurface.Items.Components
IsOutput = (element.Name.ToString() == "output");
Name = ToolBox.GetAttributeString(element, "name", (IsOutput) ? "output" : "input");
effects = new List<StatusEffect>();
wireId = new int[MaxLinked];
foreach (XElement subElement in element.Elements())
{
int index = -1;
for (int i = 0; i < MaxLinked; i++)
switch (subElement.Name.ToString().ToLower())
{
if (wireId[i]<1) index = i;
case "link":
int index = -1;
for (int i = 0; i < MaxLinked; i++)
{
if (wireId[i]<1) index = i;
}
if (index == -1) break;
wireId[index] = ToolBox.GetAttributeInt(subElement, "w", -1);
break;
case "statuseffect":
effects.Add(StatusEffect.Load(subElement));
break;
}
if (index == -1) break;
wireId[index] = ToolBox.GetAttributeInt(subElement, "w", -1);
}
}
public int FindEmptyIndex()
@@ -149,6 +161,13 @@ namespace Subsurface.Items.Components
{
ic.ReceiveSignal(signal, recipient, sender, power);
}
foreach (StatusEffect effect in recipient.effects)
{
//effect.Apply(ActionType.OnUse, 1.0f, recipient.item, recipient.item);
recipient.item.ApplyStatusEffect(effect, ActionType.OnUse, 1.0f);
}
}
}
@@ -28,7 +28,7 @@ namespace Subsurface.Items.Components
{
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power = 0.0f)
{
switch (connection.Name)
{
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Subsurface.Items.Components
{
class SignalCheckComponent : ItemComponent
{
private string output;
private string targetSignal;
[InGameEditable, HasDefaultValue("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, HasDefaultValue("", true)]
public string TargetSignal
{
get { return targetSignal; }
set { targetSignal = value; }
}
public SignalCheckComponent(Item item, XElement element)
: base(item, element)
{
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{
switch (connection.Name)
{
case "signal_in":
item.SendSignal((signal == targetSignal) ? output : "0", "signal_out");
break;
case "set_output":
output = signal;
break;
case "set_targetsignal":
targetSignal = signal;
break;
}
}
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ namespace Subsurface.Items.Components
set { reloadTime = value; }
}
[HasDefaultValue("0.0,0.0", true)]
[HasDefaultValue("0.0,0.0", true), Editable]
public string RotationLimits
{
get
+94 -10
View File
@@ -17,7 +17,7 @@ namespace Subsurface
public enum ActionType
{
OnPicked, OnWearing, OnContaining, OnContained, OnActive, OnUse, OnFailure
OnPicked, OnWearing, OnContaining, OnContained, OnActive, OnUse, OnFailure, OnBroken
}
class Item : MapEntity, IDamageable, IPropertyObject
@@ -69,8 +69,9 @@ namespace Subsurface
float prev = condition;
condition = MathHelper.Clamp(value, 0.0f, 100.0f);
if (condition==0.0f && prev>0.0f)
if (condition == 0.0f && prev>0.0f)
{
ApplyStatusEffects(ActionType.OnBroken, 1.0f, null);
foreach (FixRequirement req in FixRequirements)
{
req.Fixed = false;
@@ -369,7 +370,7 @@ namespace Subsurface
public void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaTime, Character character = null)
{
if (condition == 0.0f) return;
if (condition == 0.0f && effect.type != ActionType.OnBroken) return;
bool hasTargets = (effect.TargetNames == null);
@@ -424,7 +425,7 @@ namespace Subsurface
// //container.ApplyStatusEffect(effect, type, deltaTime, container);
//}
effect.Apply(type, deltaTime, SimPosition, targets);
effect.Apply(type, deltaTime, this, targets);
}
}
@@ -446,7 +447,7 @@ namespace Subsurface
{
ic.Update(deltaTime, cam);
ic.PlaySound(ActionType.OnActive, 1.0f, Position, true);
ic.PlaySound(ActionType.OnActive, Position, true);
ic.ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
}
else
@@ -596,8 +597,8 @@ namespace Subsurface
requiredItemCount += ic.requiredItems.Count;
}
}
editingHUD = new GUIFrame(new Rectangle(x, y, width, 110 + (editableProperties.Count()+requiredItemCount) * 30), Color.Black * 0.5f);
editingHUD = new GUIFrame(new Rectangle(x, y, width, 110 + (editableProperties.Count() + requiredItemCount) * 30), Color.Black * 0.5f);
editingHUD.Padding = new Vector4(10, 10, 0, 0);
editingHUD.UserData = this;
@@ -662,6 +663,7 @@ namespace Subsurface
editingHUD = CreateEditingHUD(true);
}
editingHUD.Update((float)Physics.step);
editingHUD.Draw(spriteBatch);
foreach (ItemComponent ic in components)
@@ -764,7 +766,7 @@ namespace Subsurface
if (tempRequiredSkill != null) requiredSkill = tempRequiredSkill;
if (!ic.HasRequiredItems(picker, picker == Character.Controlled) && !forcePick) continue;
if (!forcePick && !ic.HasRequiredItems(picker, picker == Character.Controlled)) continue;
if ((ic.CanBePicked && ic.Pick(picker)) || (ic.CanBeSelected && ic.Select(picker)))
{
picked = true;
@@ -805,7 +807,7 @@ namespace Subsurface
if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue;
if (ic.Use(deltaTime, character))
{
ic.PlaySound(ActionType.OnUse, 1.0f, Position);
ic.PlaySound(ActionType.OnUse, Position);
ic.ApplyStatusEffects(ActionType.OnUse, deltaTime, character);
@@ -902,14 +904,19 @@ namespace Subsurface
object prevValue = objectProperty.GetValue();
textBox.Selected = false;
if (objectProperty.TrySetValue(text))
{
textBox.Text = text;
new NetworkEvent(NetworkEventType.UpdateProperty, ID, true, objectProperty.Name);
return true;
}
else
{
if (prevValue!=null)
if (prevValue != null)
{
textBox.Text = prevValue.ToString();
}
@@ -1075,6 +1082,42 @@ namespace Subsurface
case NetworkEventType.UpdateComponent:
message.Write((int)data);
components[(int)data].FillNetworkData(type, message);
break;
case NetworkEventType.UpdateProperty:
var allProperties = GetProperties<InGameEditable>();
ObjectProperty objectProperty = allProperties.Find(op => op.Name == (string)data);
if (objectProperty != null)
{
message.Write((string)data);
object value = objectProperty.GetValue();
if (value is string)
{
message.Write((byte)0);
message.Write((string)value);
}
else if (value is float)
{
message.Write((byte)1);
message.Write((float)value);
}
else if (value is int)
{
message.Write((byte)2);
message.Write((int)value);
}
else if (value is bool)
{
message.Write((byte)3);
message.Write((bool)value);
}
else
{
message.Write((byte)200);
}
}
break;
}
}
@@ -1093,6 +1136,47 @@ namespace Subsurface
int componentIndex = message.ReadInt32();
if (componentIndex < 0 || componentIndex > components.Count - 1) return;
components[componentIndex].ReadNetworkData(type, message);
break;
case NetworkEventType.UpdateProperty:
string propertyName = "";
try
{
propertyName = message.ReadString();
}
catch
{
return;
}
var allProperties = GetProperties<InGameEditable>();
ObjectProperty property = allProperties.Find(op => op.Name == propertyName);
if (property == null) return;
try
{
switch (message.ReadByte())
{
case 0:
property.TrySetValue(message.ReadString());
break;
case 1:
property.TrySetValue(message.ReadFloat());
break;
case 2:
property.TrySetValue(message.ReadInt32());
break;
case 3:
property.TrySetValue(message.ReadBoolean());
break;
}
}
catch
{
return;
}
break;
}
}