Got the set up for events! Now to make them!.

This commit is contained in:
JoshuaNavarro 2019-12-04 18:14:45 -08:00
parent 267ed77092
commit f5db7501f4
9 changed files with 125 additions and 48 deletions

View File

@ -1,26 +0,0 @@
using StardewValley;
namespace Omegasis.HappyBirthday
{
// TODO: Make all the events
// Resources:https://stardewvalleywiki.com/Modding:Event_data
public class BirthdayEvents
{
public Event communityCenterJunimoEvent;
public Event marriedNoKidsEvent;
public Event surpriseBirthdayPartyEvent;
public Event marriedWithOneKidEvent;
public Event marriedWithTwoKidsEvent;
public BirthdayEvents()
{
this.initializeEvents();
}
public void initializeEvents()
{
Event e = new Event("", -1, Game1.player);
Game1.player.currentLocation.currentEvent = new Event();
}
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Omegasis.HappyBirthday.Framework.Events;
using Omegasis.HappyBirthday.Framework.Events.Preconditions;
using Omegasis.HappyBirthday.Framework.Events.Preconditions.TimeSpecific;
using Omegasis.HappyBirthday.Framework.Events.SpecialPreconditions;
using StardewValley;
namespace Omegasis.HappyBirthday.Framework
{
public class BirthdayEvents
{
public static EventHelper CommunityCenterBirthday()
{
List<EventPrecondition> conditions = new List<EventPrecondition>();
conditions.Add(new FarmerBirthdayPrecondition());
conditions.Add(new LocationPrecondition(Game1.getLocationFromName("CommunityCenter")));
conditions.Add(new TimePrecondition(600, 2600));
EventHelper e = new EventHelper("CommunityCenterBirthday",19950, conditions, new EventStartData(EventStartData.MusicToPlayType.Continue, 10, 10, new EventStartData.FarmerData(10, 10, EventHelper.FacingDirection.Up),new List<EventStartData.NPCData>()));
e.showMessage("Community center birthday here.");
e.end();
return e;
}
}
}

View File

@ -45,7 +45,7 @@ namespace Omegasis.HappyBirthday.Framework
public BirthdayMenu(string season, int day, Action<string, int> onChanged) public BirthdayMenu(string season, int day, Action<string, int> onChanged)
: base(Game1.viewport.Width / 2 - (632 + IClickableMenu.borderWidth * 2) / 2, Game1.viewport.Height / 2 - (600 + IClickableMenu.borderWidth * 2) / 2 - Game1.tileSize, 632 + IClickableMenu.borderWidth * 2, 600 + IClickableMenu.borderWidth * 2 + Game1.tileSize) : base(Game1.viewport.Width / 2 - (632 + IClickableMenu.borderWidth * 2) / 2, Game1.viewport.Height / 2 - (600 + IClickableMenu.borderWidth * 2) / 2 - Game1.tileSize, 632 + IClickableMenu.borderWidth * 2, 600 + IClickableMenu.borderWidth * 2 + Game1.tileSize)
{ {
this.BirthdaySeason = season; this.BirthdaySeason = HappyBirthday.Config.translationInfo.getTranslatedString(season);
this.BirthdayDay = day; this.BirthdayDay = day;
this.OnChanged = onChanged; this.OnChanged = onChanged;
this.SetUpPositions(); this.SetUpPositions();

View File

@ -63,6 +63,8 @@ namespace Omegasis.HappyBirthday.Framework.Events
protected List<EventPrecondition> eventPreconditions; protected List<EventPrecondition> eventPreconditions;
protected int eventID; protected int eventID;
public string eventName;
public EventHelper() public EventHelper()
{ {
this.eventData = new StringBuilder(); this.eventData = new StringBuilder();
@ -70,8 +72,9 @@ namespace Omegasis.HappyBirthday.Framework.Events
this.eventPreconditions = new List<EventPrecondition>(); this.eventPreconditions = new List<EventPrecondition>();
} }
public EventHelper(int ID, LocationPrecondition Location, TimePrecondition Time, EventDayExclusionPrecondition NotTheseDays, EventStartData StartData) public EventHelper(string EventName,int ID, LocationPrecondition Location, TimePrecondition Time, EventDayExclusionPrecondition NotTheseDays, EventStartData StartData)
{ {
this.eventName = EventName;
this.eventData = new StringBuilder(); this.eventData = new StringBuilder();
this.eventPreconditionData = new StringBuilder(); this.eventPreconditionData = new StringBuilder();
this.eventPreconditions = new List<EventPrecondition>(); this.eventPreconditions = new List<EventPrecondition>();
@ -82,8 +85,10 @@ namespace Omegasis.HappyBirthday.Framework.Events
this.add(StartData.ToString()); this.add(StartData.ToString());
} }
public EventHelper(List<EventPrecondition> Conditions, EventStartData StartData) public EventHelper(string EventName,int ID,List<EventPrecondition> Conditions, EventStartData StartData)
{ {
this.eventName = EventName;
this.eventID = ID;
this.eventData = new StringBuilder(); this.eventData = new StringBuilder();
this.eventPreconditions = new List<EventPrecondition>(); this.eventPreconditions = new List<EventPrecondition>();
this.eventPreconditionData = new StringBuilder(); this.eventPreconditionData = new StringBuilder();
@ -176,9 +181,9 @@ namespace Omegasis.HappyBirthday.Framework.Events
return s.Substring(0, 4); return s.Substring(0, 4);
} }
protected virtual string getEventID() public virtual int getEventID()
{ {
return this.getUniqueEventStartID() + this.eventID.ToString(); return Convert.ToInt32(this.getUniqueEventStartID() + this.eventID.ToString());
} }
/// <summary> /// <summary>
@ -203,7 +208,7 @@ namespace Omegasis.HappyBirthday.Framework.Events
else return true; else return true;
} }
protected virtual string getEventString() public virtual string getEventString()
{ {
return this.eventData.ToString(); return this.eventData.ToString();
} }
@ -216,7 +221,7 @@ namespace Omegasis.HappyBirthday.Framework.Events
/// <summary> /// <summary>
/// Checks to see if all of the event preconditions have been met and starts the event if so. /// Checks to see if all of the event preconditions have been met and starts the event if so.
/// </summary> /// </summary>
protected virtual void startEventAtLocationifPossible() public virtual void startEventAtLocationifPossible()
{ {
if (this.canEventOccur()) if (this.canEventOccur())
{ {
@ -224,6 +229,7 @@ namespace Omegasis.HappyBirthday.Framework.Events
Game1.player.currentLocation.startEvent(this.getEvent()); Game1.player.currentLocation.startEvent(this.getEvent());
} }
} }
//~~~~~~~~~~~~~~~~// //~~~~~~~~~~~~~~~~//
// Validation // // Validation //
@ -233,7 +239,7 @@ namespace Omegasis.HappyBirthday.Framework.Events
/// Checks to see if the event can occur. /// Checks to see if the event can occur.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
protected virtual bool canEventOccur() public virtual bool canEventOccur()
{ {
foreach (EventPrecondition eve in this.eventPreconditions) foreach (EventPrecondition eve in this.eventPreconditions)
{ {
@ -1139,9 +1145,9 @@ namespace Omegasis.HappyBirthday.Framework.Events
{ {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
b.Append("message "); b.Append("message ");
b.Append('"'); b.Append("\\\"");
b.Append(Message); b.Append(Message);
b.Append('"'); b.Append("\"");
this.add(b); this.add(b);
} }

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StardewValley;
namespace Omegasis.HappyBirthday.Framework.Events
{
public class EventManager
{
public Dictionary<string, EventHelper> events;
public EventManager()
{
this.events = new Dictionary<string, EventHelper>();
}
public void addEvent(EventHelper Event)
{
this.events.Add(Event.eventName, Event);
}
public EventHelper getEvent(string Name)
{
if (this.events.ContainsKey(Name))
{
return this.events[Name];
}
else
{
return null;
}
}
public void clearEventFromFarmer(string EventName)
{
this.events.TryGetValue(EventName, out EventHelper e);
if (e == null) return;
Game1.player.eventsSeen.Remove(e.getEventID());
}
}
}

View File

@ -118,7 +118,8 @@ namespace Omegasis.HappyBirthday.Framework.Events
} }
this.add(CameraTileX.ToString()); this.add(CameraTileX.ToString());
this.add(CameraTileY.ToString()); this.builder.Append(" ");
this.builder.Append(CameraTileY.ToString());
StringBuilder npcData = new StringBuilder(); StringBuilder npcData = new StringBuilder();

View File

@ -113,7 +113,7 @@ namespace Omegasis.HappyBirthday.Framework
{ {
return this.getFileExtensionForFileType(File); return this.getFileExtensionForFileType(File);
} }
return this.TranslationFileExtensions[language] + this.getFileExtensionForFileType(File); return "."+this.TranslationFileExtensions[language] + this.getFileExtensionForFileType(File);
} }
catch (Exception err) catch (Exception err)
{ {

View File

@ -5,6 +5,7 @@ using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Omegasis.HappyBirthday.Framework; using Omegasis.HappyBirthday.Framework;
using Omegasis.HappyBirthday.Framework.Events;
using StardewModdingAPI; using StardewModdingAPI;
using StardewModdingAPI.Events; using StardewModdingAPI.Events;
using StardewValley; using StardewValley;
@ -69,6 +70,8 @@ namespace Omegasis.HappyBirthday
private NPC lastSpeaker; private NPC lastSpeaker;
private EventManager eventManager;
/********* /*********
** Public methods ** Public methods
*********/ *********/
@ -91,11 +94,28 @@ namespace Omegasis.HappyBirthday
helper.Events.Multiplayer.ModMessageReceived += this.Multiplayer_ModMessageReceived; helper.Events.Multiplayer.ModMessageReceived += this.Multiplayer_ModMessageReceived;
helper.Events.Multiplayer.PeerDisconnected += this.Multiplayer_PeerDisconnected; helper.Events.Multiplayer.PeerDisconnected += this.Multiplayer_PeerDisconnected;
helper.Events.GameLoop.GameLaunched += this.GameLoop_GameLaunched; helper.Events.GameLoop.GameLaunched += this.GameLoop_GameLaunched;
helper.Events.Player.Warped += this.Player_Warped;
ModHelper = this.Helper; ModHelper = this.Helper;
ModMonitor = this.Monitor; ModMonitor = this.Monitor;
this.othersBirthdays = new Dictionary<long, PlayerData>(); this.othersBirthdays = new Dictionary<long, PlayerData>();
this.eventManager = new EventManager();
}
private void Player_Warped(object sender, WarpedEventArgs e)
{
if (e.NewLocation == Game1.getLocationFromName("CommunityCenter"))
{
EventHelper eve=this.eventManager.getEvent("CommunityCenterBirthday");
this.Monitor.Log("Birthday event can occur: " + eve.canEventOccur(), LogLevel.Info);
this.Monitor.Log("Birthday event info: " + eve.getEventString(), LogLevel.Info);
eve.startEventAtLocationifPossible();
}
} }
private void GameLoop_GameLaunched(object sender, GameLaunchedEventArgs e) private void GameLoop_GameLaunched(object sender, GameLaunchedEventArgs e)
@ -103,6 +123,7 @@ namespace Omegasis.HappyBirthday
this.messages = new BirthdayMessages(); this.messages = new BirthdayMessages();
this.giftManager = new GiftManager(); this.giftManager = new GiftManager();
this.isDailyQuestBoard = false; this.isDailyQuestBoard = false;
} }
/// <summary>Get whether this instance can edit the given asset.</summary> /// <summary>Get whether this instance can edit the given asset.</summary>
@ -528,20 +549,15 @@ namespace Omegasis.HappyBirthday
this.MigrateLegacyData(); this.MigrateLegacyData();
this.PlayerData = this.Helper.Data.ReadJsonFile<PlayerData>(this.DataFilePath) ?? new PlayerData(); this.PlayerData = this.Helper.Data.ReadJsonFile<PlayerData>(this.DataFilePath) ?? new PlayerData();
;
if (PlayerBirthdayData != null) if (PlayerBirthdayData != null)
{ {
ModMonitor.Log("Send all birthday information from " + Game1.player.Name); ModMonitor.Log("Send all birthday information from " + Game1.player.Name);
MultiplayerSupport.SendBirthdayInfoToOtherPlayers(); MultiplayerSupport.SendBirthdayInfoToOtherPlayers();
} }
//this.SeenEvent = false;
//this.Dialogue = new Dictionary<string, Dialogue>();
this.eventManager.addEvent(BirthdayEvents.CommunityCenterBirthday());
//Game1.player.addItemToInventoryBool(new StardewValley.Object(388, 999));
//Game1.player.addItemToInventoryBool(new StardewValley.Object(390, 999));
//Game1.player.Money = 999999;
} }
/// <summary>Raised before the game begins writes data to the save file (except the initial save creation).</summary> /// <summary>Raised before the game begins writes data to the save file (except the initial save creation).</summary>
@ -702,7 +718,7 @@ namespace Omegasis.HappyBirthday
{ {
return return
this.PlayerData.BirthdayDay == Game1.dayOfMonth this.PlayerData.BirthdayDay == Game1.dayOfMonth
&& this.PlayerData.BirthdaySeason .Equals(HappyBirthday.Config.translationInfo.getTranslatedString(Game1.currentSeason)); && this.PlayerData.BirthdaySeason.Equals(Game1.currentSeason);
} }
/// <summary>Migrate the legacy settings for the current player.</summary> /// <summary>Migrate the legacy settings for the current player.</summary>

View File

@ -80,9 +80,10 @@
<Compile Include="..\GlobalAssemblyInfo.cs"> <Compile Include="..\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link> <Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="BirthdayEvents.cs" />
<Compile Include="BirthdayMessages.cs" /> <Compile Include="BirthdayMessages.cs" />
<Compile Include="Framework\BirthdayEvents.cs" />
<Compile Include="Framework\BirthdayMenu.cs" /> <Compile Include="Framework\BirthdayMenu.cs" />
<Compile Include="Framework\Events\EventManager.cs" />
<Compile Include="Framework\Events\EventStartData.cs" /> <Compile Include="Framework\Events\EventStartData.cs" />
<Compile Include="Framework\Events\Preconditions\LocationPrecondition.cs" /> <Compile Include="Framework\Events\Preconditions\LocationPrecondition.cs" />
<Compile Include="Framework\Events\Preconditions\MISC\ChanceToOccur.cs" /> <Compile Include="Framework\Events\Preconditions\MISC\ChanceToOccur.cs" />