2016-03-05 03:10:39 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
|
|
|
|
using StardewValley;
|
|
|
|
|
using StardewValley.Characters;
|
|
|
|
|
using StardewValley.Menus;
|
|
|
|
|
using StardewValley.Monsters;
|
|
|
|
|
using StardewValley.Quests;
|
|
|
|
|
using StardewValley.TerrainFeatures;
|
2016-03-05 04:40:46 +08:00
|
|
|
|
using StardewModdingAPI.Events;
|
2016-03-05 03:10:39 +08:00
|
|
|
|
|
|
|
|
|
namespace StardewModdingAPI.Inheritance
|
|
|
|
|
{
|
|
|
|
|
public class SGame : Game1
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
public static FieldInfo[] StaticFields { get { return GetStaticFields(); } }
|
|
|
|
|
|
|
|
|
|
public static FieldInfo[] GetStaticFields()
|
|
|
|
|
{
|
|
|
|
|
return typeof(Game1).GetFields();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public KeyboardState KStateNow { get; private set; }
|
|
|
|
|
public KeyboardState KStatePrior { get; private set; }
|
|
|
|
|
|
|
|
|
|
public MouseState MStateNow { get; private set; }
|
|
|
|
|
public MouseState MStatePrior { get; private set; }
|
|
|
|
|
|
|
|
|
|
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-07 03:46:47 +08:00
|
|
|
|
public Keys[] FrameReleasedKeys
|
|
|
|
|
{
|
|
|
|
|
get { return PreviouslyPressedKeys.Where(x => !CurrentlyPressedKeys.Contains(x)).ToArray(); }
|
|
|
|
|
}
|
2016-03-08 01:25:51 +08:00
|
|
|
|
|
2016-03-07 21:49:45 +08:00
|
|
|
|
public Buttons[][] PreviouslyPressedButtons;
|
|
|
|
|
|
|
|
|
|
private bool WasButtonJustPressed(Buttons button, ButtonState buttonState, PlayerIndex stateIndex)
|
|
|
|
|
{
|
|
|
|
|
return buttonState == ButtonState.Pressed && !PreviouslyPressedButtons[(int)stateIndex].Contains(button);
|
|
|
|
|
}
|
2016-03-08 01:25:51 +08:00
|
|
|
|
|
|
|
|
|
private bool WasButtonJustReleased(Buttons button, ButtonState buttonState, PlayerIndex stateIndex)
|
|
|
|
|
{
|
|
|
|
|
return buttonState == ButtonState.Released && PreviouslyPressedButtons[(int)stateIndex].Contains(button);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool WasButtonJustPressed(Buttons button, float value, PlayerIndex stateIndex)
|
|
|
|
|
{
|
|
|
|
|
return WasButtonJustPressed(button, value > 0.2f ? ButtonState.Pressed : ButtonState.Released, stateIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool WasButtonJustReleased(Buttons button, float value, PlayerIndex stateIndex)
|
|
|
|
|
{
|
|
|
|
|
return WasButtonJustReleased(button, value > 0.2f ? ButtonState.Pressed : ButtonState.Released, stateIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Buttons[] GetButtonsDown(PlayerIndex index)
|
|
|
|
|
{
|
|
|
|
|
GamePadState state = GamePad.GetState((PlayerIndex)index);
|
|
|
|
|
List<Buttons> buttons = new List<Buttons>();
|
|
|
|
|
if (state.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
if (state.Buttons.A == ButtonState.Pressed) buttons.Add(Buttons.A);
|
|
|
|
|
if (state.Buttons.B == ButtonState.Pressed) buttons.Add(Buttons.B);
|
|
|
|
|
if (state.Buttons.Back == ButtonState.Pressed) buttons.Add(Buttons.Back);
|
|
|
|
|
if (state.Buttons.BigButton == ButtonState.Pressed) buttons.Add(Buttons.BigButton);
|
|
|
|
|
if (state.Buttons.LeftShoulder == ButtonState.Pressed) buttons.Add(Buttons.LeftShoulder);
|
|
|
|
|
if (state.Buttons.LeftStick == ButtonState.Pressed) buttons.Add(Buttons.LeftStick);
|
|
|
|
|
if (state.Buttons.RightShoulder == ButtonState.Pressed) buttons.Add(Buttons.RightShoulder);
|
|
|
|
|
if (state.Buttons.RightStick == ButtonState.Pressed) buttons.Add(Buttons.RightStick);
|
|
|
|
|
if (state.Buttons.Start == ButtonState.Pressed) buttons.Add(Buttons.Start);
|
|
|
|
|
if (state.Buttons.X == ButtonState.Pressed) buttons.Add(Buttons.X);
|
|
|
|
|
if (state.Buttons.Y == ButtonState.Pressed) buttons.Add(Buttons.Y);
|
|
|
|
|
if (state.DPad.Up == ButtonState.Pressed) buttons.Add(Buttons.DPadUp);
|
|
|
|
|
if (state.DPad.Down == ButtonState.Pressed) buttons.Add(Buttons.DPadDown);
|
|
|
|
|
if (state.DPad.Left == ButtonState.Pressed) buttons.Add(Buttons.DPadLeft);
|
|
|
|
|
if (state.DPad.Right == ButtonState.Pressed) buttons.Add(Buttons.DPadRight);
|
|
|
|
|
if (state.Triggers.Left > 0.2f) buttons.Add(Buttons.LeftTrigger);
|
|
|
|
|
if (state.Triggers.Right > 0.2f) buttons.Add(Buttons.RightTrigger);
|
|
|
|
|
}
|
|
|
|
|
return buttons.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 21:49:45 +08:00
|
|
|
|
public Buttons[] GetFramePressedButtons(PlayerIndex index)
|
|
|
|
|
{
|
|
|
|
|
GamePadState state = GamePad.GetState((PlayerIndex)index);
|
|
|
|
|
List<Buttons> buttons = new List<Buttons>();
|
|
|
|
|
if (state.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
if (WasButtonJustPressed(Buttons.A, state.Buttons.A, index)) buttons.Add(Buttons.A);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.B, state.Buttons.B, index)) buttons.Add(Buttons.B);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.Back, state.Buttons.Back, index)) buttons.Add(Buttons.Back);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.BigButton, state.Buttons.BigButton, index)) buttons.Add(Buttons.BigButton);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.LeftShoulder, state.Buttons.LeftShoulder, index)) buttons.Add(Buttons.LeftShoulder);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.LeftStick, state.Buttons.LeftStick, index)) buttons.Add(Buttons.LeftStick);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.RightShoulder, state.Buttons.RightShoulder, index)) buttons.Add(Buttons.RightShoulder);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.RightStick, state.Buttons.RightStick, index)) buttons.Add(Buttons.RightStick);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.Start, state.Buttons.Start, index)) buttons.Add(Buttons.Start);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.X, state.Buttons.X, index)) buttons.Add(Buttons.X);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.Y, state.Buttons.Y, index)) buttons.Add(Buttons.Y);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.DPadUp, state.DPad.Up, index)) buttons.Add(Buttons.DPadUp);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.DPadDown, state.DPad.Down, index)) buttons.Add(Buttons.DPadDown);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.DPadLeft, state.DPad.Left, index)) buttons.Add(Buttons.DPadLeft);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.DPadRight, state.DPad.Right, index)) buttons.Add(Buttons.DPadRight);
|
2016-03-08 01:25:51 +08:00
|
|
|
|
if (WasButtonJustPressed(Buttons.LeftTrigger, state.Triggers.Left, index)) buttons.Add(Buttons.LeftTrigger);
|
|
|
|
|
if (WasButtonJustPressed(Buttons.RightTrigger, state.Triggers.Right, index)) buttons.Add(Buttons.RightTrigger);
|
2016-03-07 21:49:45 +08:00
|
|
|
|
}
|
|
|
|
|
return buttons.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 01:25:51 +08:00
|
|
|
|
public Buttons[] GetFrameReleasedButtons(PlayerIndex index)
|
|
|
|
|
{
|
|
|
|
|
GamePadState state = GamePad.GetState((PlayerIndex)index);
|
|
|
|
|
List<Buttons> buttons = new List<Buttons>();
|
|
|
|
|
if (state.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
if (WasButtonJustReleased(Buttons.A, state.Buttons.A, index)) buttons.Add(Buttons.A);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.B, state.Buttons.B, index)) buttons.Add(Buttons.B);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.Back, state.Buttons.Back, index)) buttons.Add(Buttons.Back);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.BigButton, state.Buttons.BigButton, index)) buttons.Add(Buttons.BigButton);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.LeftShoulder, state.Buttons.LeftShoulder, index)) buttons.Add(Buttons.LeftShoulder);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.LeftStick, state.Buttons.LeftStick, index)) buttons.Add(Buttons.LeftStick);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.RightShoulder, state.Buttons.RightShoulder, index)) buttons.Add(Buttons.RightShoulder);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.RightStick, state.Buttons.RightStick, index)) buttons.Add(Buttons.RightStick);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.Start, state.Buttons.Start, index)) buttons.Add(Buttons.Start);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.X, state.Buttons.X, index)) buttons.Add(Buttons.X);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.Y, state.Buttons.Y, index)) buttons.Add(Buttons.Y);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.DPadUp, state.DPad.Up, index)) buttons.Add(Buttons.DPadUp);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.DPadDown, state.DPad.Down, index)) buttons.Add(Buttons.DPadDown);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.DPadLeft, state.DPad.Left, index)) buttons.Add(Buttons.DPadLeft);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.DPadRight, state.DPad.Right, index)) buttons.Add(Buttons.DPadRight);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.LeftTrigger, state.Triggers.Left, index)) buttons.Add(Buttons.LeftTrigger);
|
|
|
|
|
if (WasButtonJustReleased(Buttons.RightTrigger, state.Triggers.Right, index)) buttons.Add(Buttons.RightTrigger);
|
|
|
|
|
}
|
|
|
|
|
return buttons.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-05 03:10:39 +08:00
|
|
|
|
public int PreviousGameLocations { get; private set; }
|
|
|
|
|
public int PreviousLocationObjects { get; private set; }
|
2016-03-05 04:20:58 +08:00
|
|
|
|
public int PreviousItems_ { get; private set; }
|
|
|
|
|
public Dictionary<Item, int> PreviousItems { get; private set; }
|
2016-03-05 03:10:39 +08:00
|
|
|
|
|
2016-03-05 04:40:46 +08:00
|
|
|
|
public int PreviousCombatLevel { get; private set; }
|
|
|
|
|
public int PreviousFarmingLevel { get; private set; }
|
|
|
|
|
public int PreviousFishingLevel { get; private set; }
|
|
|
|
|
public int PreviousForagingLevel { get; private set; }
|
|
|
|
|
public int PreviousMiningLevel { get; private set; }
|
|
|
|
|
public int PreviousLuckLevel { get; private set; }
|
|
|
|
|
|
2016-03-05 03:10:39 +08:00
|
|
|
|
public GameLocation PreviousGameLocation { get; private set; }
|
|
|
|
|
public IClickableMenu PreviousActiveMenu { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Int32 PreviousTimeOfDay { get; private set; }
|
|
|
|
|
public Int32 PreviousDayOfMonth { get; private set; }
|
|
|
|
|
public String PreviousSeasonOfYear { get; private set; }
|
|
|
|
|
public Int32 PreviousYearOfGame { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Farmer PreviousFarmer { get; private set; }
|
|
|
|
|
|
2016-03-05 06:21:16 +08:00
|
|
|
|
private static SGame instance;
|
|
|
|
|
public static SGame Instance { get { return instance; } }
|
|
|
|
|
|
|
|
|
|
public Farmer CurrentFarmer { get { return player; } }
|
|
|
|
|
|
2016-03-05 03:10:39 +08:00
|
|
|
|
public SGame()
|
|
|
|
|
{
|
2016-03-05 06:21:16 +08:00
|
|
|
|
instance = this;
|
|
|
|
|
|
2016-03-05 14:32:04 +08:00
|
|
|
|
#if DEBUG
|
|
|
|
|
SaveGame.serializer = new XmlSerializer(typeof (SaveGame), new Type[28]
|
2016-03-05 03:10:39 +08:00
|
|
|
|
{
|
|
|
|
|
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-05 14:32:04 +08:00
|
|
|
|
#endif
|
2016-03-05 03:10:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Initialize()
|
|
|
|
|
{
|
2016-03-05 14:32:04 +08:00
|
|
|
|
Log.Verbose("XNA Initialize");
|
2016-03-05 03:10:39 +08:00
|
|
|
|
ModItems = new Dictionary<Int32, SObject>();
|
|
|
|
|
PreviouslyPressedKeys = new Keys[0];
|
2016-03-08 01:25:51 +08:00
|
|
|
|
PreviouslyPressedButtons = new Buttons[4][];
|
|
|
|
|
for (int i = 0; i < 4; ++i) PreviouslyPressedButtons[i] = new Buttons[0];
|
|
|
|
|
|
2016-03-05 03:10:39 +08:00
|
|
|
|
base.Initialize();
|
|
|
|
|
Events.GameEvents.InvokeInitialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadContent()
|
|
|
|
|
{
|
2016-03-05 14:32:04 +08:00
|
|
|
|
Log.Verbose("XNA LoadContent");
|
2016-03-05 03:10:39 +08:00
|
|
|
|
base.LoadContent();
|
|
|
|
|
Events.GameEvents.InvokeLoadContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update(GameTime gameTime)
|
|
|
|
|
{
|
|
|
|
|
UpdateEventCalls();
|
|
|
|
|
|
|
|
|
|
try
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
2016-03-05 03:10:39 +08:00
|
|
|
|
base.Update(gameTime);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
2016-03-05 14:32:04 +08:00
|
|
|
|
Log.Error("An error occured in the base update loop: " + ex);
|
2016-03-05 03:10:39 +08:00
|
|
|
|
Console.ReadKey();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Events.GameEvents.InvokeUpdateTick();
|
|
|
|
|
|
|
|
|
|
PreviouslyPressedKeys = CurrentlyPressedKeys;
|
2016-03-08 01:25:51 +08:00
|
|
|
|
for(PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
|
|
|
|
|
{
|
|
|
|
|
PreviouslyPressedButtons[(int)i] = GetButtonsDown(i);
|
|
|
|
|
}
|
2016-03-05 03:10:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Draw(GameTime gameTime)
|
|
|
|
|
{
|
|
|
|
|
base.Draw(gameTime);
|
|
|
|
|
Events.GraphicsEvents.InvokeDrawTick();
|
|
|
|
|
|
|
|
|
|
if (false)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
2016-03-05 03:10:39 +08:00
|
|
|
|
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
|
|
|
|
|
|
|
|
|
if (CurrentLocation != null)
|
|
|
|
|
CurrentLocation.draw(spriteBatch);
|
|
|
|
|
|
|
|
|
|
if (player != null && player.position != null)
|
|
|
|
|
spriteBatch.DrawString(dialogueFont, player.position.ToString(), new Vector2(0, 180), Color.Orange);
|
|
|
|
|
|
|
|
|
|
spriteBatch.End();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Int32 RegisterModItem(SObject modItem)
|
|
|
|
|
{
|
|
|
|
|
if (modItem.HasBeenRegistered)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
2016-03-05 14:32:04 +08:00
|
|
|
|
Log.Error("The item {0} has already been registered with ID {1}", modItem.Name, modItem.RegisteredId);
|
2016-03-05 03:10:39 +08:00
|
|
|
|
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)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
2016-03-05 03:10:39 +08:00
|
|
|
|
if (ModItems.ElementAtOrDefault(id).Value != null)
|
|
|
|
|
{
|
|
|
|
|
return ModItems.ElementAt(id).Value.Clone();
|
|
|
|
|
}
|
2016-03-05 14:32:04 +08:00
|
|
|
|
Log.Error("ModItem Dictionary does not contain index: " + id.ToString());
|
2016-03-05 03:10:39 +08:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (ModItems.ContainsKey(id))
|
|
|
|
|
{
|
|
|
|
|
return ModItems[id].Clone();
|
|
|
|
|
}
|
2016-03-05 14:32:04 +08:00
|
|
|
|
Log.Error("ModItem Dictionary does not contain ID: " + id.ToString());
|
2016-03-05 03:10:39 +08:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static SGameLocation GetLocationFromName(String name)
|
|
|
|
|
{
|
2016-03-05 06:21:16 +08:00
|
|
|
|
return ModLocations.FirstOrDefault(n => n.name == name);
|
2016-03-05 03:10:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static SGameLocation LoadOrCreateSGameLocationFromName(String name)
|
|
|
|
|
{
|
|
|
|
|
if (GetLocationFromName(name) != null)
|
|
|
|
|
return GetLocationFromName(name);
|
|
|
|
|
GameLocation gl = locations.FirstOrDefault(x => x.name == name);
|
|
|
|
|
if (gl != null)
|
|
|
|
|
{
|
2016-03-05 14:32:04 +08:00
|
|
|
|
Log.Debug("A custom location was created for the new name: " + name);
|
2016-03-05 03:10:39 +08:00
|
|
|
|
SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
|
|
|
|
|
ModLocations.Add(s);
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
if (currentLocation != null && currentLocation.name == name)
|
|
|
|
|
{
|
|
|
|
|
gl = currentLocation;
|
2016-03-05 14:32:04 +08:00
|
|
|
|
Log.Debug("A custom location was created from the current location for the new name: " + name);
|
2016-03-05 03:10:39 +08:00
|
|
|
|
SGameLocation s = SGameLocation.ConstructFromBaseClass(gl);
|
|
|
|
|
ModLocations.Add(s);
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-05 14:32:04 +08:00
|
|
|
|
Log.Debug("A custom location could not be created for: " + name);
|
2016-03-05 03:10:39 +08:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2016-03-05 04:20:58 +08:00
|
|
|
|
|
2016-03-05 03:10:39 +08:00
|
|
|
|
public void UpdateEventCalls()
|
|
|
|
|
{
|
|
|
|
|
KStateNow = Keyboard.GetState();
|
|
|
|
|
CurrentlyPressedKeys = KStateNow.GetPressedKeys();
|
2016-03-07 03:46:47 +08:00
|
|
|
|
|
2016-03-05 03:10:39 +08:00
|
|
|
|
MStateNow = Mouse.GetState();
|
|
|
|
|
|
|
|
|
|
foreach (Keys k in FramePressedKeys)
|
|
|
|
|
Events.ControlEvents.InvokeKeyPressed(k);
|
2016-03-07 03:46:47 +08:00
|
|
|
|
|
|
|
|
|
foreach (Keys k in FrameReleasedKeys)
|
|
|
|
|
Events.ControlEvents.InvokeKeyReleased(k);
|
|
|
|
|
|
2016-03-07 21:49:45 +08:00
|
|
|
|
for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
|
|
|
|
|
{
|
2016-03-08 01:25:51 +08:00
|
|
|
|
Buttons[] buttons = GetFramePressedButtons(i);
|
|
|
|
|
foreach (Buttons b in buttons)
|
2016-03-07 21:49:45 +08:00
|
|
|
|
{
|
2016-03-08 01:25:51 +08:00
|
|
|
|
if(b == Buttons.LeftTrigger || b == Buttons.RightTrigger)
|
|
|
|
|
{
|
|
|
|
|
Events.ControlEvents.InvokeTriggerPressed(i, b, b == Buttons.LeftTrigger ? GamePad.GetState(i).Triggers.Left : GamePad.GetState(i).Triggers.Right);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Events.ControlEvents.InvokeButtonPressed(i, b);
|
|
|
|
|
}
|
2016-03-07 21:49:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
|
|
|
|
|
{
|
2016-03-08 01:25:51 +08:00
|
|
|
|
foreach (Buttons b in GetFrameReleasedButtons(i))
|
2016-03-07 21:49:45 +08:00
|
|
|
|
{
|
2016-03-08 01:25:51 +08:00
|
|
|
|
if (b == Buttons.LeftTrigger || b == Buttons.RightTrigger)
|
|
|
|
|
{
|
|
|
|
|
Events.ControlEvents.InvokeTriggerReleased(i, b, b == Buttons.LeftTrigger ? GamePad.GetState(i).Triggers.Left : GamePad.GetState(i).Triggers.Right);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Events.ControlEvents.InvokeButtonReleased(i, b);
|
|
|
|
|
}
|
2016-03-07 21:49:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-03-05 03:10:39 +08:00
|
|
|
|
if (KStateNow != KStatePrior)
|
|
|
|
|
{
|
|
|
|
|
Events.ControlEvents.InvokeKeyboardChanged(KStatePrior, KStateNow);
|
|
|
|
|
KStatePrior = KStateNow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MStateNow != MStatePrior)
|
|
|
|
|
{
|
|
|
|
|
Events.ControlEvents.InvokeMouseChanged(MStatePrior, MStateNow);
|
|
|
|
|
MStatePrior = MStateNow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (activeClickableMenu != null && activeClickableMenu != PreviousActiveMenu)
|
|
|
|
|
{
|
|
|
|
|
Events.MenuEvents.InvokeMenuChanged(PreviousActiveMenu, activeClickableMenu);
|
|
|
|
|
PreviousActiveMenu = activeClickableMenu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (locations.GetHash() != PreviousGameLocations)
|
|
|
|
|
{
|
|
|
|
|
Events.LocationEvents.InvokeLocationsChanged(locations);
|
|
|
|
|
PreviousGameLocations = locations.GetHash();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentLocation != PreviousGameLocation)
|
|
|
|
|
{
|
|
|
|
|
Events.LocationEvents.InvokeCurrentLocationChanged(PreviousGameLocation, currentLocation);
|
|
|
|
|
PreviousGameLocation = currentLocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (player != null && player != PreviousFarmer)
|
|
|
|
|
{
|
|
|
|
|
Events.PlayerEvents.InvokeFarmerChanged(PreviousFarmer, player);
|
|
|
|
|
PreviousFarmer = player;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-05 04:40:46 +08:00
|
|
|
|
if (player != null && player.combatLevel != PreviousCombatLevel)
|
|
|
|
|
{
|
|
|
|
|
Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Combat, player.combatLevel);
|
|
|
|
|
PreviousCombatLevel = player.combatLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (player != null && player.farmingLevel != PreviousFarmingLevel)
|
|
|
|
|
{
|
|
|
|
|
Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Farming, player.farmingLevel);
|
|
|
|
|
PreviousFarmingLevel = player.farmingLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (player != null && player.fishingLevel != PreviousFishingLevel)
|
|
|
|
|
{
|
|
|
|
|
Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Fishing, player.fishingLevel);
|
|
|
|
|
PreviousFishingLevel = player.fishingLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (player != null && player.foragingLevel != PreviousForagingLevel)
|
|
|
|
|
{
|
|
|
|
|
Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Foraging, player.foragingLevel);
|
|
|
|
|
PreviousForagingLevel = player.foragingLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (player != null && player.miningLevel != PreviousMiningLevel)
|
|
|
|
|
{
|
|
|
|
|
Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Mining, player.miningLevel);
|
|
|
|
|
PreviousMiningLevel = player.miningLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (player != null && player.luckLevel != PreviousLuckLevel)
|
|
|
|
|
{
|
|
|
|
|
Events.PlayerEvents.InvokeLeveledUp(EventArgsLevelUp.LevelType.Luck, player.luckLevel);
|
|
|
|
|
PreviousLuckLevel = player.luckLevel;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-05 04:20:58 +08:00
|
|
|
|
List<ItemStackChange> changedItems;
|
|
|
|
|
if (player != null && HasInventoryChanged(player.items, out changedItems))
|
2016-03-05 03:10:39 +08:00
|
|
|
|
{
|
2016-03-05 04:20:58 +08:00
|
|
|
|
Events.PlayerEvents.InvokeInventoryChanged(player.items, changedItems);
|
|
|
|
|
PreviousItems = player.items.Where(n => n != null).ToDictionary(n => n, n => n.Stack);
|
2016-03-08 13:47:52 +08:00
|
|
|
|
}
|
2016-03-05 03:10:39 +08:00
|
|
|
|
|
2016-03-08 13:47:52 +08:00
|
|
|
|
var objectHash = currentLocation?.objects?.GetHash();
|
|
|
|
|
if(objectHash != null && PreviousLocationObjects != objectHash)
|
2016-03-04 04:36:53 +08:00
|
|
|
|
{
|
2016-03-04 22:05:36 +08:00
|
|
|
|
Events.LocationEvents.InvokeOnNewLocationObject(currentLocation.objects);
|
2016-03-08 13:47:52 +08:00
|
|
|
|
PreviousLocationObjects = objectHash ?? -1;
|
2016-03-05 03:10:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (timeOfDay != PreviousTimeOfDay)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
2016-03-05 03:10:39 +08:00
|
|
|
|
Events.TimeEvents.InvokeTimeOfDayChanged(PreviousTimeOfDay, timeOfDay);
|
|
|
|
|
PreviousTimeOfDay = timeOfDay;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dayOfMonth != PreviousDayOfMonth)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
2016-03-05 03:10:39 +08:00
|
|
|
|
Events.TimeEvents.InvokeDayOfMonthChanged(PreviousDayOfMonth, dayOfMonth);
|
|
|
|
|
PreviousDayOfMonth = dayOfMonth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentSeason != PreviousSeasonOfYear)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
2016-03-05 03:10:39 +08:00
|
|
|
|
Events.TimeEvents.InvokeSeasonOfYearChanged(PreviousSeasonOfYear, currentSeason);
|
|
|
|
|
PreviousSeasonOfYear = currentSeason;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (year != PreviousYearOfGame)
|
2016-03-04 02:50:22 +08:00
|
|
|
|
{
|
2016-03-05 03:10:39 +08:00
|
|
|
|
Events.TimeEvents.InvokeYearOfGameChanged(PreviousYearOfGame, year);
|
|
|
|
|
PreviousYearOfGame = year;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-05 04:20:58 +08:00
|
|
|
|
|
|
|
|
|
private bool HasInventoryChanged(List<Item> items, out List<ItemStackChange> changedItems)
|
|
|
|
|
{
|
|
|
|
|
changedItems = new List<ItemStackChange>();
|
|
|
|
|
IEnumerable<Item> actualItems = items.Where(n => n != null);
|
|
|
|
|
foreach (var item in actualItems)
|
|
|
|
|
{
|
|
|
|
|
if (PreviousItems != null && PreviousItems.ContainsKey(item))
|
|
|
|
|
{
|
|
|
|
|
if(PreviousItems[item] != item.Stack)
|
|
|
|
|
{
|
|
|
|
|
changedItems.Add(new ItemStackChange() { Item = item, StackChange = item.Stack - PreviousItems[item], ChangeType = ChangeType.StackChange });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
changedItems.Add(new ItemStackChange() { Item = item, StackChange = item.Stack, ChangeType = ChangeType.Added });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PreviousItems != null)
|
|
|
|
|
{
|
|
|
|
|
changedItems.AddRange(PreviousItems.Where(n => !actualItems.Any(i => i == n.Key)).Select(n =>
|
|
|
|
|
new ItemStackChange() { Item = n.Key, StackChange = -n.Key.Stack, ChangeType = ChangeType.Removed }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (changedItems.Any());
|
|
|
|
|
}
|
2016-03-05 03:10:39 +08:00
|
|
|
|
}
|
2016-02-29 09:26:36 +08:00
|
|
|
|
}
|