Quests, new sounds, explosives, bugfixes, asdfasdf
This commit is contained in:
@@ -1,106 +0,0 @@
|
||||
//using Microsoft.Xna.Framework;
|
||||
//using Microsoft.Xna.Framework.Graphics;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
|
||||
//namespace Subsurface
|
||||
//{
|
||||
// static class EventManager
|
||||
// {
|
||||
// static Event activeEvent;
|
||||
|
||||
// static GUIFrame infoPanel;
|
||||
|
||||
// const int MaxPreviousEvents = 6;
|
||||
// const float PreviouslyUsedWeight = 10.0f;
|
||||
|
||||
// static List<Event> previousEvents = new List<Event>();
|
||||
|
||||
// public static Event ActiveEvent
|
||||
// {
|
||||
// get { return activeEvent; }
|
||||
// }
|
||||
|
||||
// public static void StartShift()
|
||||
// {
|
||||
// int eventCount = Event.list.Count();
|
||||
|
||||
// //create an array where the probability of an event being selected will be calculated
|
||||
// float[] eventProbability = new float[eventCount];
|
||||
|
||||
// float probabilitySum = 0.0f;
|
||||
|
||||
// for (int i = 0; i < eventCount; i++)
|
||||
// {
|
||||
// eventProbability[i] = Event.list[i].Commonness;
|
||||
|
||||
// //if the event has been previously selected, it's less likely to be selected now
|
||||
// int previousEventIndex = previousEvents.FindIndex(x => x == Event.list[i]);
|
||||
// if (previousEventIndex>=0)
|
||||
// {
|
||||
// //how many shifts ago was the event last selected
|
||||
// int eventDist = eventCount - previousEventIndex;
|
||||
|
||||
// float weighting = (1.0f / eventDist) * PreviouslyUsedWeight;
|
||||
|
||||
// eventProbability[i] *= weighting;
|
||||
// }
|
||||
|
||||
// probabilitySum += eventProbability[i];
|
||||
// }
|
||||
|
||||
// float randomNumber = (float)Game1.random.NextDouble()*probabilitySum;
|
||||
|
||||
// for (int i = 0; i < eventCount; i++)
|
||||
// {
|
||||
// if (randomNumber <= eventProbability[i])
|
||||
// {
|
||||
// SelectEvent(Event.list[i]);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// randomNumber -= eventProbability[i];
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static void SelectEvent(Event selectedEvent)
|
||||
// {
|
||||
// if (selectedEvent == null) return;
|
||||
|
||||
// activeEvent = selectedEvent;
|
||||
// previousEvents.Add(activeEvent);
|
||||
|
||||
// activeEvent.Init();
|
||||
// }
|
||||
|
||||
// public static void Update(GameTime gameTime)
|
||||
// {
|
||||
// if (activeEvent==null) return;
|
||||
// activeEvent.Update(gameTime);
|
||||
// }
|
||||
|
||||
// public static void DrawInfo(SpriteBatch spriteBatch)
|
||||
// {
|
||||
// if (activeEvent==null || !activeEvent.IsStarted) return;
|
||||
|
||||
// if (infoPanel == null)
|
||||
// {
|
||||
// infoPanel = new GUIFrame(new Rectangle(Game1.GraphicsWidth - 320, 20, 300, 100), Color.White * 0.8f);
|
||||
// infoPanel.Padding = GUI.style.smallPadding;
|
||||
// infoPanel.AddChild(new GUITextBlock(new Rectangle(0, 0, 200, 20), activeEvent.Name, Color.Transparent, Color.Black));
|
||||
// infoPanel.AddChild(new GUITextBlock(new Rectangle(0, 0, 200, 50), activeEvent.Description, Color.Transparent, Color.Black));
|
||||
// }
|
||||
|
||||
|
||||
// //infoPanel.Draw(spriteBatch);
|
||||
// }
|
||||
|
||||
// public static void EventFinished(Event e)
|
||||
// {
|
||||
// if (e != activeEvent) return;
|
||||
// infoPanel.AddChild(new GUITextBlock(new Rectangle(0, 0, 200, 80), "Finished!", Color.Transparent, Color.Black));
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,155 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class Quest
|
||||
{
|
||||
private static List<Quest> list = new List<Quest>();
|
||||
|
||||
private static string configFile = "Content/Quests.xml";
|
||||
|
||||
private string name;
|
||||
|
||||
private string description;
|
||||
|
||||
protected bool completed;
|
||||
|
||||
private string successMessage;
|
||||
private string failureMessage;
|
||||
|
||||
private int reward;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get { return description; }
|
||||
}
|
||||
|
||||
public int Reward
|
||||
{
|
||||
get { return reward; }
|
||||
}
|
||||
|
||||
public bool Completed
|
||||
{
|
||||
get { return completed; }
|
||||
}
|
||||
|
||||
public virtual string RadarLabel
|
||||
{
|
||||
get { return ""; }
|
||||
}
|
||||
|
||||
public virtual Vector2 RadarPosition
|
||||
{
|
||||
get { return Vector2.Zero; }
|
||||
}
|
||||
|
||||
public Quest(XElement element)
|
||||
{
|
||||
name = ToolBox.GetAttributeString(element, "name", "");
|
||||
|
||||
description = ToolBox.GetAttributeString(element, "description", "");
|
||||
|
||||
reward = ToolBox.GetAttributeInt(element, "reward", 1);
|
||||
|
||||
successMessage = ToolBox.GetAttributeString(element, "successmessage", "");
|
||||
failureMessage = ToolBox.GetAttributeString(element, "failuremessage", "");
|
||||
}
|
||||
|
||||
public static Quest LoadRandom(Random rand)
|
||||
{
|
||||
XDocument doc = ToolBox.TryLoadXml(configFile);
|
||||
if (doc == null) return null;
|
||||
|
||||
int eventCount = doc.Root.Elements().Count();
|
||||
//int[] commonness = new int[eventCount];
|
||||
float[] eventProbability = new float[eventCount];
|
||||
|
||||
float probabilitySum = 0.0f;
|
||||
|
||||
int i = 0;
|
||||
foreach (XElement element in doc.Root.Elements())
|
||||
{
|
||||
eventProbability[i] = ToolBox.GetAttributeInt(element, "commonness", 1);
|
||||
|
||||
probabilitySum += eventProbability[i];
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
float randomNumber = (float)rand.NextDouble() * probabilitySum;
|
||||
|
||||
i = 0;
|
||||
foreach (XElement element in doc.Root.Elements())
|
||||
{
|
||||
if (randomNumber <= eventProbability[i])
|
||||
{
|
||||
Type t;
|
||||
string type = element.Name.ToString();
|
||||
|
||||
try
|
||||
{
|
||||
t = Type.GetType("Subsurface." + type + ", Subsurface", true, true);
|
||||
if (t == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + configFile + "! Could not find a quest class of the type ''" + type + "''.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + configFile + "! Could not find a an event class of the type ''" + type + "''.");
|
||||
continue;
|
||||
}
|
||||
|
||||
ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement) });
|
||||
object instance = constructor.Invoke(new object[] { element });
|
||||
|
||||
return (Quest)instance;
|
||||
}
|
||||
|
||||
randomNumber -= eventProbability[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual void Start(Level level)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// End the quest and give a reward if it was completed successfully
|
||||
/// </summary>
|
||||
/// <returns>whether the quest was completed or not</returns>
|
||||
public virtual void End()
|
||||
{
|
||||
completed = true;
|
||||
|
||||
GiveReward();
|
||||
}
|
||||
|
||||
public void GiveReward()
|
||||
{
|
||||
var mode = Game1.GameSession.gameMode as SinglePlayerMode;
|
||||
mode.Money += reward;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(successMessage))
|
||||
{
|
||||
new GUIMessageBox("Quest completed", successMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class SalvageQuest : Quest
|
||||
{
|
||||
ItemPrefab itemPrefab;
|
||||
|
||||
Item item;
|
||||
|
||||
public override string RadarLabel
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Infrasonic signal";
|
||||
}
|
||||
}
|
||||
|
||||
public override Vector2 RadarPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return item.Position;
|
||||
}
|
||||
}
|
||||
|
||||
public SalvageQuest(XElement element)
|
||||
: base(element)
|
||||
{
|
||||
string itemName = ToolBox.GetAttributeString(element, "itemname", "");
|
||||
|
||||
itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab;
|
||||
|
||||
if (itemPrefab == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in salvagequest: couldn't find an item prefab with the name "+itemName);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Start(Level level)
|
||||
{
|
||||
Vector2 position = level.PositionsOfInterest[Rand.Int(level.PositionsOfInterest.Count)];
|
||||
|
||||
item = new Item(itemPrefab, position+level.Position);
|
||||
//item.MoveWithLevel = true;
|
||||
}
|
||||
|
||||
public override void End()
|
||||
{
|
||||
if (item.CurrentHull == null) return;
|
||||
|
||||
item.Remove();
|
||||
|
||||
GiveReward();
|
||||
|
||||
completed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,13 +140,13 @@ namespace Subsurface
|
||||
t = Type.GetType("Subsurface." + type + ", Subsurface", true, true);
|
||||
if (t == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + configFile + "! Could not find a an event class of the type ''" + type + "''.");
|
||||
DebugConsole.ThrowError("Error in " + configFile + "! Could not find an event class of the type ''" + type + "''.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + configFile + "! Could not find a an event class of the type ''" + type + "''.");
|
||||
DebugConsole.ThrowError("Error in " + configFile + "! Could not find an event class of the type ''" + type + "''.");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user