Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Task
  5. {
  6. public readonly string taskName;
  7. public readonly float taskDuration;
  8. public readonly float repeatDuration;
  9. public readonly int minWorkers = 1;
  10. public readonly int maxWorkers = 1;
  11. public readonly bool reserveOwner = true;
  12. public readonly Action<AiEntity> taskAction = e => { };
  13. public readonly Action<AiEntity> arrivalAction = e => { };
  14. public readonly Func<AiEntity, bool> entityCondition = e => true;
  15. public readonly Func<GameEntity, bool> workerCondition = e => true;
  16. public readonly Func<GameEntity, bool> ownerCondition = e => true;
  17. public readonly Func<AiEntity, bool> repeatCondition = e => false;
  18. public readonly Action<AiEntity> completionAction = e => { };
  19.  
  20. public Task
  21. (
  22. string taskName,
  23. float taskDuration = 0,
  24. float repeatDuration = 0,
  25. int minWorkers = 1,
  26. int maxWorkers = 1,
  27. bool reserveOwner = true,
  28. Action<AiEntity> taskAction = null,
  29. Action<AiEntity> arrivalAction = null,
  30. Func<GameEntity, bool> workerCondition = null,
  31. Func<GameEntity, bool> ownerCondition = null,
  32. Func<AiEntity, bool> repeatCondition = null,
  33. Action<AiEntity> completionAction = null
  34. )
  35. {
  36. this.taskName = taskName;
  37. this.taskDuration = taskDuration;
  38. this.repeatDuration = repeatDuration;
  39. this.minWorkers = minWorkers;
  40. this.maxWorkers = maxWorkers;
  41. this.reserveOwner = reserveOwner;
  42. if (taskAction != null) this.taskAction = taskAction;
  43. if (arrivalAction != null) this.arrivalAction = arrivalAction;
  44. if (workerCondition != null) this.workerCondition = workerCondition;
  45. if (ownerCondition != null) this.ownerCondition = ownerCondition;
  46. if (repeatCondition != null) this.repeatCondition = repeatCondition;
  47. if (completionAction != null) this.completionAction = completionAction;
  48.  
  49. if (_taskLookup.ContainsKey(taskName))
  50. {
  51. throw new Exception("Task <" + taskName + "> has already been used.");
  52. }
  53.  
  54. _taskLookup.Add(taskName, this);
  55. }
  56.  
  57. private static readonly Dictionary<string, Task> _taskLookup = new Dictionary<string, Task>();
  58.  
  59. public static Task GetTask(string name)
  60. {
  61. if (_taskLookup.ContainsKey(name))
  62. {
  63. return _taskLookup[name];
  64. }
  65.  
  66. throw new Exception("Unrecognised task name <" + name + ">");
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement