2016-02-29 09:26:36 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2016-02-29 11:16:32 +08:00
|
|
|
|
using System.Reflection;
|
2016-03-03 22:44:10 +08:00
|
|
|
|
using System.Xml.Serialization;
|
2016-02-29 09:26:36 +08:00
|
|
|
|
using Microsoft.Xna.Framework;
|
2016-03-01 14:35:52 +08:00
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2016-02-29 09:26:36 +08:00
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
|
|
|
|
using StardewValley;
|
2016-03-03 22:44:10 +08:00
|
|
|
|
using StardewValley.Characters;
|
2016-03-01 02:22:24 +08:00
|
|
|
|
using StardewValley.Menus;
|
2016-03-03 22:44:10 +08:00
|
|
|
|
using StardewValley.Monsters;
|
|
|
|
|
using StardewValley.Quests;
|
|
|
|
|
using StardewValley.TerrainFeatures;
|
2016-02-29 09:26:36 +08:00
|
|
|
|
|
2016-02-29 11:16:32 +08:00
|
|
|
|
namespace StardewModdingAPI.Inheritance
|
2016-02-29 09:26:36 +08:00
|
|
|
|
{
|
|
|
|
|
public class SGame : Game1
|
|
|
|
|
{
|
2016-03-01 14:35:52 +08:00
|
|
|
|
public static List<SGameLocation> ModLocations = new List<SGameLocation>();
|
|
|
|
|
public static SGameLocation CurrentLocation { get; internal set; }
|
|
|
|
|
public static Dictionary<Int32, SObject> ModItems { get; private set; }
|
|
|
|
|
public const Int32 LowestModItemID = 1000;
|
2016-02-29 11:16:32 +08:00
|
|
|
|
|
2016-03-01 14:35:52 +08:00
|
|
|
|
public static FieldInfo[] StaticFields { get { return GetStaticFields(); } }
|
|
|
|
|
|
|
|
|
|
public static FieldInfo[] GetStaticFields()
|
2016-02-29 11:16:32 +08:00
|
|
|
|
{
|
|
|
|
|
return typeof(Game1).GetFields();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-29 09:26:36 +08:00
|
|
|
|
public KeyboardState KStateNow { get; private set; }
|
|
|
|
|
public KeyboardState KStatePrior { get; private set; }
|
|
|
|
|
|
2016-03-02 06:22:19 +08:00
|
|
|
|
public MouseState MStateNow { get; private set; }
|
|
|
|
|
public MouseState MStatePrior { get; private set; }
|
|
|
|
|
|
2016-02-29 09:26:36 +08:00
|
|
|
|
public Keys[] CurrentlyPressedKeys { get; private set; }
|
|
|
|
|
public Keys[] PreviouslyPressedKeys { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Keys[] FramePressedKeys
|
|
|
|
|
{
|
|
|
|
|
get { return CurrentlyPressedKeys.Where(x => !PreviouslyPressedKeys.Contains(x)).ToArray(); }
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 14:35:52 +08:00
|
|
|
|
public int PreviousGameLocations { get; private set; }
|
|
|
|
|
public GameLocation PreviousGameLocation { get; private set; }
|
|
|
|
|
public IClickableMenu PreviousActiveMenu { get; private set; }
|
|
|
|
|
|
2016-03-03 11:54:37 +08:00
|
|
|
|
public Int32 PreviousTimeOfDay { get; private set; }
|
|
|
|
|
public Int32 PreviousDayOfMonth { get; private set; }
|
|
|
|
|
public String PreviousSeasonOfYear { get; private set; }
|
|
|
|
|
public Int32 PreviousYearOfGame { get; private set; }
|
|
|
|
|
|
2016-03-03 01:24:15 +08:00
|
|
|
|
public Farmer PreviousFarmer { get; private set; }
|
|
|
|
|
|
2016-03-03 12:38:51 +08:00
|
|
|
|
public SGame()
|
|
|
|
|
{
|
|
|
|
|
if (Program.debug)
|
|
|
|
|
{
|
2016-03-03 22:44:10 +08:00
|
|
|
|
SaveGame.serializer = new XmlSerializer(typeof (SaveGame), new Type[28]
|
|
|
|
|
{
|
|
|
|
|
typeof (Tool),
|
|
|
|
|
typeof (GameLocation),
|
|
|
|
|
typeof (Crow),
|
|
|
|
|
typeof (Duggy),
|
|
|
|
|
typeof (Bug),
|
|
|
|
|
typeof (BigSlime),
|
|
|
|
|
typeof (Fireball),
|
|
|
|
|
typeof (Ghost),
|
|
|
|
|
typeof (Child),
|
|
|
|
|
typeof (Pet),
|
|
|
|
|
typeof (Dog),
|
|
|
|
|
typeof (StardewValley.Characters.Cat),
|
|
|
|
|
typeof (Horse),
|
|
|
|
|
typeof (GreenSlime),
|
|
|
|
|
typeof (LavaCrab),
|
|
|
|
|
typeof (RockCrab),
|
|
|
|
|
typeof (ShadowGuy),
|
|
|
|
|
typeof (SkeletonMage),
|
|
|
|
|
typeof (SquidKid),
|
|
|
|
|
typeof (Grub),
|
|
|
|
|
typeof (Fly),
|
|
|
|
|
typeof (DustSpirit),
|
|
|
|
|
typeof (Quest),
|
|
|
|
|
typeof (MetalHead),
|
|
|
|
|
typeof (ShadowGirl),
|
|
|
|
|
typeof (Monster),
|
|
|
|
|
typeof (TerrainFeature),
|
|
|
|
|
typeof (SObject)
|
|
|
|
|
});
|
2016-03-03 12:38:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-29 09:26:36 +08:00
|
|
|
|
protected override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
Program.Log("XNA Initialize");
|
2016-03-01 14:35:52 +08:00
|
|
|
|
ModItems = new Dictionary<Int32, SObject>();
|
|
|
|
|
PreviouslyPressedKeys = new Keys[0];
|
2016-02-29 09:26:36 +08:00
|
|
|
|
base.Initialize();
|
2016-03-01 14:37:56 +08:00
|
|
|
|
Events.InvokeInitialize();
|
2016-02-29 09:26:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadContent()
|
|
|
|
|
{
|
|
|
|
|
Program.Log("XNA LoadContent");
|
|
|
|
|
base.LoadContent();
|
2016-03-01 14:37:56 +08:00
|
|
|
|
Events.InvokeLoadContent();
|
2016-02-29 09:26:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update(GameTime gameTime)
|
|
|
|
|
{
|
2016-03-03 11:54:37 +08:00
|
|
|
|
UpdateEventCalls();
|
2016-02-29 09:26:36 +08:00
|
|
|
|
|
2016-03-03 11:54:37 +08:00
|
|
|
|
try
|
2016-03-01 14:35:52 +08:00
|
|
|
|
{
|
2016-03-03 11:54:37 +08:00
|
|
|
|
base.Update(gameTime);
|
2016-03-01 14:35:52 +08:00
|
|
|
|
}
|
2016-03-03 11:54:37 +08:00
|
|
|
|
catch (Exception ex)
|
2016-03-03 01:24:15 +08:00
|
|
|
|
{
|
2016-03-03 11:54:37 +08:00
|
|
|
|
Program.LogError("An error occured in the base update loop: " + ex);
|
|
|
|
|
Console.ReadKey();
|
2016-03-03 01:24:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 14:37:56 +08:00
|
|
|
|
Events.InvokeUpdateTick();
|
2016-02-29 09:26:36 +08:00
|
|
|
|
|
|
|
|
|
PreviouslyPressedKeys = CurrentlyPressedKeys;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Draw(GameTime gameTime)
|
|
|
|
|
{
|
|
|
|
|
base.Draw(gameTime);
|
2016-03-01 14:37:56 +08:00
|
|
|
|
Events.InvokeDrawTick();
|
2016-03-02 07:44:41 +08:00
|
|
|
|
|
2016-03-03 11:54:37 +08:00
|
|
|
|
if (false)
|
2016-03-02 08:36:12 +08:00
|
|
|
|
{
|
|
|
|
|
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
2016-03-01 15:16:35 +08:00
|
|
|
|
|
2016-03-02 08:36:12 +08:00
|
|
|
|
if (CurrentLocation != null)
|
2016-03-03 11:54:37 +08:00
|
|
|
|
CurrentLocation.draw(spriteBatch);
|
2016-03-02 08:36:12 +08:00
|
|
|
|
|
|
|
|
|
if (player != null && player.position != null)
|
2016-03-03 11:54:37 +08:00
|
|
|
|
spriteBatch.DrawString(dialogueFont, player.position.ToString(), new Vector2(0, 180), Color.Orange);
|
2016-03-02 08:36:12 +08:00
|
|
|
|
|
|
|
|
|
spriteBatch.End();
|
|
|
|
|
}
|
2016-03-01 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Int32 RegisterModItem(SObject modItem)
|
|
|
|
|
{
|
|
|
|
|
if (modItem.HasBeenRegistered)
|
|
|
|
|
{
|
|
|
|
|
Program.LogError("The item {0} has already been registered with ID {1}", modItem.Name, modItem.RegisteredId);
|
|
|
|
|
return modItem.RegisteredId;
|
|
|
|
|
}
|
|
|
|
|
Int32 newId = LowestModItemID;
|
|
|
|
|
if (ModItems.Count > 0)
|
|
|
|
|
newId = Math.Max(LowestModItemID, ModItems.OrderBy(x => x.Key).First().Key + 1);
|
|
|
|
|
ModItems.Add(newId, modItem);
|
|
|
|
|
modItem.HasBeenRegistered = true;
|
|
|
|
|
modItem.RegisteredId = newId;
|
|
|
|
|
return newId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static SObject PullModItemFromDict(Int32 id, bool isIndex)
|
|
|
|
|
{
|
|
|
|
|
if (isIndex)
|
|
|
|
|
{
|
|
|
|
|
if (ModItems.ElementAtOrDefault(id).Value != null)
|
|
|
|
|
{
|
|
|
|
|
return ModItems.ElementAt(id).Value.Clone();
|
|
|
|
|
}
|
2016-03-04 02:50:22 +08:00
|
|
|
|
Program.LogError("ModItem Dictionary does not contain index: " + id.ToString());
|
2016-03-03 11:54:37 +08:00
|
|
|
|
return null;
|
2016-03-01 14:35:52 +08:00
|
|
|
|
}
|
2016-03-03 11:54:37 +08:00
|
|
|
|
if (ModItems.ContainsKey(id))
|
2016-03-01 14:35:52 +08:00
|
|
|
|
{
|
2016-03-03 11:54:37 +08:00
|
|
|
|
return ModItems[id].Clone();
|
2016-03-01 14:35:52 +08:00
|
|
|
|
}
|
2016-03-04 02:50:22 +08:00
|
|
|
|
Program.LogError("ModItem Dictionary does not contain ID: " + id.ToString());
|
2016-03-03 11:54:37 +08:00
|
|
|
|
return null;
|
2016-03-01 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static SGameLocation GetLocationFromName(String name)
|
|
|
|
|
{
|
|
|
|
|
if (ModLocations.Any(x => x.name == name))
|
|
|
|
|
{
|
|
|
|
|
return ModLocations[ModLocations.IndexOf(ModLocations.First(x => x.name == name))];
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2016-02-29 09:26:36 +08:00
|
|
|
|
}
|
2016-03-03 01:24:15 +08:00
|
|
|
|
|
|
|
|
|
public static SGameLocation LoadOrCreateSGameLocationFromName(String name)
|
|
|
|
|
{
|
|
|
|
|
if (GetLocationFromName(name) != null)
|
|
|
|
|
return GetLocationFromName(name);
|
2016-03-03 11:54:37 +08:00
|
|
|
|
GameLocation gl = locations.FirstOrDefault(x => x.name == name);
|
|
|
|
|
if (gl != null)
|
2016-03-03 01:24:15 +08:00
|
|
|
|
{
|
2016-03-03 11:54:37 +08:00
|
|
|
|
Program.LogDebug("A custom location was created for the new name: " + name);
|
|
|
|
|
SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
|
|
|
|
|
ModLocations.Add(s);
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
if (currentLocation != null && currentLocation.name == name)
|
|
|
|
|
{
|
|
|
|
|
gl = currentLocation;
|
|
|
|
|
Program.LogDebug("A custom location was created from the current location for the new name: " + name);
|
|
|
|
|
SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
|
|
|
|
|
ModLocations.Add(s);
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Program.LogDebug("A custom location could not be created for: " + name);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateEventCalls()
|
|
|
|
|
{
|
|
|
|
|
KStateNow = Keyboard.GetState();
|
|
|
|
|
CurrentlyPressedKeys = KStateNow.GetPressedKeys();
|
|
|
|
|
MStateNow = Mouse.GetState();
|
|
|
|
|
|
|
|
|
|
foreach (Keys k in FramePressedKeys)
|
|
|
|
|
Events.InvokeKeyPressed(k);
|
|
|
|
|
|
|
|
|
|
if (KStateNow != KStatePrior)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
Events.InvokeKeyboardChanged(KStatePrior, KStateNow);
|
2016-03-03 11:54:37 +08:00
|
|
|
|
KStatePrior = KStateNow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MStateNow != MStatePrior)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
Events.InvokeMouseChanged(MStatePrior, MStateNow);
|
2016-03-03 11:54:37 +08:00
|
|
|
|
MStatePrior = MStateNow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (activeClickableMenu != null && activeClickableMenu != PreviousActiveMenu)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
Events.InvokeMenuChanged(PreviousActiveMenu, activeClickableMenu);
|
2016-03-03 11:54:37 +08:00
|
|
|
|
PreviousActiveMenu = activeClickableMenu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (locations.GetHash() != PreviousGameLocations)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
2016-03-03 11:54:37 +08:00
|
|
|
|
Events.InvokeLocationsChanged(locations);
|
|
|
|
|
PreviousGameLocations = locations.GetHash();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentLocation != PreviousGameLocation)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
Events.InvokeCurrentLocationChanged(PreviousGameLocation, currentLocation);
|
2016-03-03 11:54:37 +08:00
|
|
|
|
PreviousGameLocation = currentLocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (player != null && player != PreviousFarmer)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
Events.InvokeFarmerChanged(PreviousFarmer, player);
|
2016-03-03 11:54:37 +08:00
|
|
|
|
PreviousFarmer = player;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (timeOfDay != PreviousTimeOfDay)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
Events.InvokeTimeOfDayChanged(PreviousTimeOfDay, timeOfDay);
|
2016-03-03 11:54:37 +08:00
|
|
|
|
PreviousTimeOfDay = timeOfDay;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dayOfMonth != PreviousDayOfMonth)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
Events.InvokeDayOfMonthChanged(PreviousDayOfMonth, dayOfMonth);
|
2016-03-03 11:54:37 +08:00
|
|
|
|
PreviousDayOfMonth = dayOfMonth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentSeason != PreviousSeasonOfYear)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
Events.InvokeSeasonOfYearChanged(PreviousSeasonOfYear, currentSeason);
|
2016-03-03 11:54:37 +08:00
|
|
|
|
PreviousSeasonOfYear = currentSeason;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (year != PreviousYearOfGame)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
Events.InvokeYearOfGameChanged(PreviousYearOfGame, year);
|
2016-03-03 11:54:37 +08:00
|
|
|
|
PreviousYearOfGame = year;
|
2016-03-03 01:24:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-29 09:26:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|