Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 + ">");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement