2019-12-05 17:25:46 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using StardewValley;
|
|
|
|
|
|
|
|
namespace StardustCore.Events
|
|
|
|
{
|
|
|
|
public class EventManager
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The list of events that this event manager is holding.
|
|
|
|
/// </summary>
|
|
|
|
public Dictionary<string, EventHelper> events;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Event logic that occurs when the specialized command appears.
|
|
|
|
/// </summary>
|
2019-12-05 17:40:29 +08:00
|
|
|
public Dictionary<string, Action<EventManager,string>> customEventLogic;
|
2019-12-05 17:25:46 +08:00
|
|
|
|
|
|
|
|
2019-12-07 05:31:10 +08:00
|
|
|
public Dictionary<string, ConcurrentEventInformation> concurrentEventActions;
|
2019-12-05 17:40:29 +08:00
|
|
|
|
2019-12-05 17:25:46 +08:00
|
|
|
public EventManager()
|
|
|
|
{
|
|
|
|
this.events = new Dictionary<string, EventHelper>();
|
2019-12-05 17:40:29 +08:00
|
|
|
this.customEventLogic = new Dictionary<string, Action<EventManager,string>>();
|
2019-12-07 05:31:10 +08:00
|
|
|
this.concurrentEventActions = new Dictionary<string, ConcurrentEventInformation>();
|
2019-12-05 17:25:46 +08:00
|
|
|
|
|
|
|
this.customEventLogic.Add("Omegasis.EventFramework.AddObjectToPlayersInventory", ExtraEventActions.addObjectToPlayerInventory);
|
|
|
|
this.customEventLogic.Add("Omegasis.EventFramework.ViewportLerp", ExtraEventActions.ViewportLerp);
|
2019-12-07 04:09:31 +08:00
|
|
|
this.customEventLogic.Add("Omegasis.EventFramework.AddInJunimoActor", ExtraEventActions.AddInJumimoActorForEvent);
|
2019-12-07 11:13:30 +08:00
|
|
|
this.customEventLogic.Add("Omegasis.EventFramework.FlipJunimoActor", ExtraEventActions.FlipJunimoActor);
|
|
|
|
this.customEventLogic.Add("Omegasis.EventFramework.SetUpAdvanceJunimoMovement", ExtraEventActions.SetUpAdvanceJunimoMovement);
|
|
|
|
this.customEventLogic.Add("Omegasis.EventFramework.FinishAdvanceJunimoMovement", ExtraEventActions.FinishAdvanceJunimoMovement);
|
|
|
|
this.customEventLogic.Add("Omegasis.EventFramework.AddInJunimoAdvanceMove", ExtraEventActions.AddInJunimoAdvanceMove);
|
2019-12-07 11:38:13 +08:00
|
|
|
this.customEventLogic.Add("Omegasis.EventFramework.RemoveJunimoAdvanceMove", ExtraEventActions.RemoveAdvanceJunimoMovement);
|
2019-12-05 17:25:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds an event to the dictionary of events.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="Event"></param>
|
|
|
|
public void addEvent(EventHelper Event)
|
|
|
|
{
|
|
|
|
this.events.Add(Event.eventName, Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds in custom code that happens when the game's current event sees the given command name.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="CommandName"></param>
|
|
|
|
/// <param name="Function"></param>
|
2019-12-05 17:40:29 +08:00
|
|
|
public void addCustomEventLogic(string CommandName,Action<EventManager,string> Function)
|
2019-12-05 17:25:46 +08:00
|
|
|
{
|
|
|
|
this.customEventLogic.Add(CommandName, Function);
|
|
|
|
}
|
|
|
|
|
2019-12-07 05:31:10 +08:00
|
|
|
public void addConcurrentEvent(ConcurrentEventInformation EventInfo)
|
2019-12-05 17:40:29 +08:00
|
|
|
{
|
2019-12-07 05:31:10 +08:00
|
|
|
this.concurrentEventActions.Add(EventInfo.id, EventInfo);
|
2019-12-05 17:40:29 +08:00
|
|
|
}
|
|
|
|
|
2019-12-05 17:25:46 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Hooked into the game's update tick.
|
|
|
|
/// </summary>
|
|
|
|
public virtual void update()
|
|
|
|
{
|
2019-12-05 18:09:31 +08:00
|
|
|
if (Game1.CurrentEvent == null)
|
|
|
|
{
|
|
|
|
if (this.concurrentEventActions.Count > 0)
|
|
|
|
{
|
|
|
|
this.concurrentEventActions.Clear();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-12-05 17:25:46 +08:00
|
|
|
string commandName = this.getGameCurrentEventCommandStringName();
|
|
|
|
//HappyBirthday.ModMonitor.Log("Current event command name is: " + commandName, StardewModdingAPI.LogLevel.Info);
|
2019-12-05 17:40:29 +08:00
|
|
|
|
2019-12-07 05:31:10 +08:00
|
|
|
List<string> _eventGC = new List<string>();
|
|
|
|
foreach (KeyValuePair<string,ConcurrentEventInformation> eventInfo in this.concurrentEventActions)
|
2019-12-07 03:34:58 +08:00
|
|
|
{
|
2019-12-07 05:31:10 +08:00
|
|
|
if (eventInfo.Value.finished)
|
|
|
|
{
|
|
|
|
_eventGC.Add(eventInfo.Key);
|
|
|
|
}
|
|
|
|
eventInfo.Value.invokeIfNotFinished();
|
2019-12-07 03:34:58 +08:00
|
|
|
}
|
2019-12-07 05:31:10 +08:00
|
|
|
foreach(string garbage in _eventGC)
|
2019-12-05 17:40:29 +08:00
|
|
|
{
|
2019-12-07 05:31:10 +08:00
|
|
|
this.concurrentEventActions.Remove(garbage);
|
2019-12-05 17:40:29 +08:00
|
|
|
}
|
|
|
|
|
2019-12-05 17:25:46 +08:00
|
|
|
if (string.IsNullOrEmpty(commandName)) return;
|
|
|
|
if (this.customEventLogic.ContainsKey(commandName)){
|
2019-12-05 17:40:29 +08:00
|
|
|
this.customEventLogic[commandName].Invoke(this,this.getGameCurrentEventCommandString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void finishConcurrentEvent(string Key)
|
|
|
|
{
|
|
|
|
if (this.concurrentEventActions.ContainsKey(Key))
|
|
|
|
{
|
2019-12-07 05:31:10 +08:00
|
|
|
this.concurrentEventActions[Key].finish();
|
2019-12-05 17:25:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the event from this list of events.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="Name"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public EventHelper getEvent(string Name)
|
|
|
|
{
|
|
|
|
if (this.events.ContainsKey(Name))
|
|
|
|
{
|
|
|
|
return this.events[Name];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// Starts the event with the given id if possible.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="EventName"></param>
|
|
|
|
public virtual void startEventAtLocationIfPossible(string EventName)
|
|
|
|
{
|
|
|
|
if (this.events.ContainsKey(EventName))
|
|
|
|
{
|
2019-12-07 07:18:23 +08:00
|
|
|
if (Game1.eventUp == true) return;
|
2019-12-05 18:09:31 +08:00
|
|
|
this.concurrentEventActions.Clear(); //Clean all old parallel actions before starting a new event.
|
2019-12-05 17:25:46 +08:00
|
|
|
this.events[EventName].startEventAtLocationifPossible();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Clears the event from the farmer.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="EventName"></param>
|
|
|
|
public void clearEventFromFarmer(string EventName)
|
|
|
|
{
|
|
|
|
|
|
|
|
this.events.TryGetValue(EventName, out EventHelper e);
|
|
|
|
if (e == null) return;
|
|
|
|
Game1.player.eventsSeen.Remove(e.getEventID());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the current command and all of it's data.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public virtual string getGameCurrentEventCommandString()
|
|
|
|
{
|
|
|
|
if (Game1.CurrentEvent != null)
|
|
|
|
{
|
|
|
|
return Game1.CurrentEvent.currentCommandString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the name of the action for the current command in the string of event commands.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public virtual string getGameCurrentEventCommandStringName()
|
|
|
|
{
|
|
|
|
if (Game1.CurrentEvent != null)
|
|
|
|
{
|
|
|
|
return Game1.CurrentEvent.currentCommandStringName();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|