Created
July 24, 2017 16:13
-
-
Save FNGgames/a95ac015494532e536ccf7bec279b012 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Collections.Generic; | |
public class Task | |
{ | |
public readonly string taskName; | |
public readonly float taskDuration; | |
public readonly float repeatDuration; | |
public readonly int minWorkers = 1; | |
public readonly int maxWorkers = 1; | |
public readonly bool reserveOwner = true; | |
public readonly Action<AiEntity> taskAction = e => { }; | |
public readonly Action<AiEntity> arrivalAction = e => { }; | |
public readonly Func<AiEntity, bool> entityCondition = e => true; | |
public readonly Func<GameEntity, bool> workerCondition = e => true; | |
public readonly Func<GameEntity, bool> ownerCondition = e => true; | |
public readonly Func<AiEntity, bool> repeatCondition = e => false; | |
public readonly Action<AiEntity> completionAction = e => { }; | |
public Task | |
( | |
string taskName, | |
float taskDuration = 0, | |
float repeatDuration = 0, | |
int minWorkers = 1, | |
int maxWorkers = 1, | |
bool reserveOwner = true, | |
Action<AiEntity> taskAction = null, | |
Action<AiEntity> arrivalAction = null, | |
Func<GameEntity, bool> workerCondition = null, | |
Func<GameEntity, bool> ownerCondition = null, | |
Func<AiEntity, bool> repeatCondition = null, | |
Action<AiEntity> completionAction = null | |
) | |
{ | |
this.taskName = taskName; | |
this.taskDuration = taskDuration; | |
this.repeatDuration = repeatDuration; | |
this.minWorkers = minWorkers; | |
this.maxWorkers = maxWorkers; | |
this.reserveOwner = reserveOwner; | |
if (taskAction != null) this.taskAction = taskAction; | |
if (arrivalAction != null) this.arrivalAction = arrivalAction; | |
if (workerCondition != null) this.workerCondition = workerCondition; | |
if (ownerCondition != null) this.ownerCondition = ownerCondition; | |
if (repeatCondition != null) this.repeatCondition = repeatCondition; | |
if (completionAction != null) this.completionAction = completionAction; | |
if (_taskLookup.ContainsKey(taskName)) | |
{ | |
throw new Exception("Task <" + taskName + "> has already been used."); | |
} | |
_taskLookup.Add(taskName, this); | |
} | |
private static readonly Dictionary<string, Task> _taskLookup = new Dictionary<string, Task>(); | |
public static Task GetTask(string name) | |
{ | |
if (_taskLookup.ContainsKey(name)) | |
{ | |
return _taskLookup[name]; | |
} | |
throw new Exception("Unrecognised task name <" + name + ">"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment