-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
270 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public static class ConditionalFactory | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
private delegate IConditional ConditionalCreator(Dictionary<string, object> parameters); | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
private static readonly Dictionary<string, ConditionalCreator> conditionCreators = new Dictionary<string, ConditionalCreator> | ||
{ | ||
{ "IsOnSamePlanet", CreateIsOnSamePlanet }, | ||
{ "HasFamilialRelationship", CreateHasFamilialRelationship }, | ||
{ "IsOnOpposingFactions", CreateIsOnOpposingFactions }, | ||
{ "IsOnMission", CreateIsOnMission } | ||
// Add more condition types and their creation functions here | ||
}; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="conditionType"></param> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
/// <exception cref="ArgumentException"></exception> | ||
public static IConditional CreateConditional(string conditionType, Dictionary<string, object> parameters) | ||
{ | ||
if (conditionCreators.TryGetValue(conditionType, out var creator)) | ||
{ | ||
return creator(parameters); | ||
} | ||
else | ||
{ | ||
throw new ArgumentException($"Invalid condition type: {conditionType}"); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
private static IConditional CreateIsOnSamePlanet(Dictionary<string, object> parameters) | ||
{ | ||
return new GenericConditional(IsOnSamePlanet, parameters); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
private static IConditional CreateHasFamilialRelationship(Dictionary<string, object> parameters) | ||
{ | ||
return new GenericConditional(HasFamilialRelationship, parameters); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
private static IConditional CreateIsOnOpposingFactions(Dictionary<string, object> parameters) | ||
{ | ||
return new GenericConditional(IsOnOpposingFactions, parameters); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
private static IConditional CreateIsOnMission(Dictionary<string, object> parameters) | ||
{ | ||
return new GenericConditional(IsOnMission, parameters); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="game"></param> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
private static bool IsOnSamePlanet(Game game, Dictionary<string, object> parameters) | ||
{ | ||
string gameID1 = (string)parameters["GameID1"]; | ||
string gameID2 = (string)parameters["GameID2"]; | ||
// Implement the logic here | ||
return true; // Placeholder | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="game"></param> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
private static bool HasFamilialRelationship(Game game, Dictionary<string, object> parameters) | ||
{ | ||
string gameID1 = (string)parameters["GameID1"]; | ||
string gameID2 = (string)parameters["GameID2"]; | ||
// Implement the logic here | ||
return true; // Placeholder | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="game"></param> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
private static bool IsOnOpposingFactions(Game game, Dictionary<string, object> parameters) | ||
{ | ||
string gameID1 = (string)parameters["GameID1"]; | ||
string gameID2 = (string)parameters["GameID2"]; | ||
// Implement the logic here | ||
return true; // Placeholder | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="game"></param> | ||
/// <param name="parameters"></param> | ||
/// <returns></returns> | ||
private static bool IsOnMission(Game game, Dictionary<string, object> parameters) | ||
{ | ||
string gameID = (string)parameters["GameID"]; | ||
// Implement the logic here | ||
return true; // Placeholder | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class GenericConditional : IConditional | ||
{ | ||
private readonly Func<Game, Dictionary<string, object>, bool> callback; | ||
private Dictionary<string, object> parameters; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="callback"></param> | ||
/// <param name="parameters"></param> | ||
public GenericConditional(Func<Game, Dictionary<string, object>, bool> callback, Dictionary<string, object> parameters) | ||
{ | ||
this.callback = callback; | ||
this.parameters = parameters; | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="game"></param> | ||
/// <returns></returns> | ||
public bool IsMet(Game game) | ||
{ | ||
return callback(game, parameters); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Assets/Scripts/Events/ICondition.cs → Assets/Scripts/Conditionals/IConditional.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
|
||
public class NarrativeEvent : GameEvent | ||
{ | ||
public IConditional Conditionals { get; set; } | ||
public List<SerializableDictionary<string, object>> ConditionalParams { get; set; } | ||
|
||
/// <summary> | ||
/// Default constructor used for serialization. | ||
/// </summary> | ||
public NarrativeEvent() { } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="scheduledTick"></param> | ||
/// <param name="conditionals"></param> | ||
public NarrativeEvent(int scheduledTick, List<IConditional> conditionals) : base(scheduledTick) { } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="game"></param> | ||
protected override void TriggerEvent(Game game) | ||
{ | ||
// @TODO: Implement trigger. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class NarrativeEventManager | ||
{ | ||
private GameEventManager eventManager; | ||
|
||
public NarrativeEventManager(GameEventManager eventManager) | ||
{ | ||
this.eventManager = eventManager; | ||
|
||
initializeNarrativeEvents(); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
private void initializeNarrativeEvents() | ||
{ | ||
List<NarrativeEvent> narrativeEvents = eventManager | ||
.GetEventsByType<NarrativeEvent>() | ||
.OfType<NarrativeEvent>() | ||
.ToList(); | ||
|
||
foreach(NarrativeEvent narrativeEvent in narrativeEvents) | ||
{ | ||
List<IConditional> conditionals = narrativeEvent.ConditionalParams.Aggregate(new List<IConditional>(), (acc, parameters) => { | ||
acc.Add(ConditionalFactory.CreateConditional(narrativeEvent.Conditionals, parameters)); | ||
return acc; | ||
}); | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters