本文整理汇总了C#中Task.ActivateBehavior方法的典型用法代码示例。如果您正苦于以下问题:C# Task.ActivateBehavior方法的具体用法?C# Task.ActivateBehavior怎么用?C# Task.ActivateBehavior使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Task
的用法示例。
在下文中一共展示了Task.ActivateBehavior方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Attack
public void Attack(Minion d)
{
Building b = WorldMap.Instance.GetBuildings(Buildings.BuildingType.Depot)[0];
_currentTask = new MoveToFortressTask(b);
_currentBehavior = _currentTask.ActivateBehavior(d);
}
示例2: MoveRandom
private void MoveRandom(Dwarf d)
{
Vector2 moveTo = Vector2.Zero;
int ran = DwarfRandom.GetRandomInt(1, 4);
if (ran == 1 && WorldMap.Instance.GetMapElement((int)d.Position.X + 1, (int)d.Position.Y, 5) == null)
{
moveTo = new Vector2(d.Position.X + 1, d.Position.Y);
}
if (ran == 2 && WorldMap.Instance.GetMapElement((int)d.Position.X - 1, (int)d.Position.Y, 5) == null)
{
moveTo = new Vector2(d.Position.X - 1, d.Position.Y);
}
if (ran == 3 && WorldMap.Instance.GetMapElement((int)d.Position.X, (int)d.Position.Y + 1, 5) == null)
{
moveTo = new Vector2(d.Position.X, d.Position.Y+1);
}
if (ran == 4 && WorldMap.Instance.GetMapElement((int)d.Position.X, (int)d.Position.Y - 1, 5) == null)
{
moveTo = new Vector2(d.Position.X, d.Position.Y-1);
}
if (moveTo == Vector2.Zero)
return;
else
{
_currentTask = new MoveToPositionTask(moveTo);
_currentBehavior = _currentTask.ActivateBehavior(d);
}
}
示例3: Update
public override void Update(Dwarf d, float dt, double dtd)
{
List<Dwarf> dwarfs = WorldMap.Instance.GetAllDwarfs();
if (_currentTask == null)
{
_prevTask = _currentTask;
_currentTask = TaskManager.GetTask(d, _failedTasks, _failedBuildings);
if (_currentTask == null)
{
_failedTasks.Clear();
return;
}
#if DEBUG_WINDOW
DebugWindow.Instance.ChangeDwarfTask(d, _currentTask);
#endif
_currentBehavior = _currentTask.ActivateBehavior(d);
}
TaskState result = _currentBehavior.Execute(d, dt, dtd);
#if DEBUG_WINDOW
//Console.WriteLine(_currentBehavior.ToString());
//DebugWindow.Instance.ChangeDwarfTaskStatus(d, _currentTask)
#endif
if (_currentBehavior.State == TaskState.Success)
{
DwarfConsole.WriteLine("Task: " + _currentTask.ToString() + " is success " + _currentTask.Id, ConsoleColor.Gray);
//TaskManager.PrintOutTasks();
TaskManager.FinishTask(_currentTask);
Stop();
Update(d, dt, dtd);
d.PersonalSkiped();
}
else if (_currentBehavior.State == TaskState.Fail)
{
//DwarfConsole.WriteLine("Task failed: " + _currentTask.TaskType, ConsoleColor.Red);
TaskManager.TaskFailed(_currentTask);
_failedTasks.Add(_currentTask);
Stop();
Update(d, dt, dtd);
}
else if (_currentBehavior.State == TaskState.SmallFail)
{
DwarfConsole.WriteLine("Task small failed: " + _currentTask.TaskType + " - ", ConsoleColor.Magenta);
TaskManager.TaskSmallFail(_currentTask);
_failedTasks.Add(_currentTask);
Stop();
Update(d, dt, dtd);
}
else if (_currentBehavior.State == TaskState.Absolete)
{
DwarfConsole.WriteLine("Task ABSOLETE: " + _currentTask.TaskType + " - ", ConsoleColor.Magenta);
TaskManager.TaskAbsolete(_currentTask);
Stop();
Update(d, dt, dtd);
}
else if (_currentBehavior.State == TaskState.PersonalSuccess)
{
DwarfConsole.WriteLine("Task: " + _currentTask.ToString() + " is success", ConsoleColor.DarkCyan);
Stop();
Update(d, dt, dtd);
}
else if (_currentBehavior.State == TaskState.PersonalFail)
{
_failedTasks.Add(_currentTask);
d.SkipPersonal();
Stop();
}
else if (_currentBehavior.State == TaskState.PersonalFailTryTaskAgain)
{
_currentBehavior = _currentTask.ActivateBehavior(d);
}
else if (_currentBehavior.State == TaskState.PersonalFailTryBehaviorAgain)
{
}
_failedTasks.Clear();
_failedBuildings.Clear();
}
示例4: MoveRandomInPasture
private void MoveRandomInPasture(Dwarf d)
{
_currentTask = new MoveToPositionTask(_pasture.GetRandomFreeSpace());
_currentBehavior = _currentTask.ActivateBehavior(d);
}