2020-05-07 03:53:54 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-11-27 22:47:33 +00:00
|
|
|
|
using System.Linq;
|
2020-05-07 03:53:54 +01:00
|
|
|
|
using MessagePack;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
using static Unity.Mathematics.math;
|
|
|
|
|
|
|
2020-05-13 22:35:56 +01:00
|
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), Order(-100)]
|
2020-05-07 03:53:54 +01:00
|
|
|
|
public class PatrolControllerData : ControllerData
|
|
|
|
|
|
{
|
|
|
|
|
|
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new PatrolController(context, this, entity, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
|
public class PatrolController : IBehavior, IController, IInitializableBehavior
|
2020-05-07 03:53:54 +01:00
|
|
|
|
{
|
2020-05-28 04:50:40 +01:00
|
|
|
|
public TaskType TaskType => TaskType.None;
|
2020-05-07 03:53:54 +01:00
|
|
|
|
public bool Available => false;
|
2020-11-27 22:47:33 +00:00
|
|
|
|
public Zone Zone => _entity.Zone;
|
2020-05-07 03:53:54 +01:00
|
|
|
|
public BehaviorData Data => _data;
|
|
|
|
|
|
|
|
|
|
|
|
private PatrolControllerData _data;
|
|
|
|
|
|
private GameContext _context;
|
|
|
|
|
|
private Entity _entity;
|
|
|
|
|
|
private Gear _item;
|
|
|
|
|
|
private Locomotion _locomotion;
|
|
|
|
|
|
private Guid _targetOrbit;
|
|
|
|
|
|
|
|
|
|
|
|
public PatrolController(GameContext context, PatrolControllerData data, Entity entity, Gear item)
|
|
|
|
|
|
{
|
|
|
|
|
|
_context = context;
|
|
|
|
|
|
_data = data;
|
|
|
|
|
|
_entity = entity;
|
|
|
|
|
|
_item = item;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
_locomotion = new Locomotion(_context, _entity, _data);
|
|
|
|
|
|
RandomTarget();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-11 01:17:10 +01:00
|
|
|
|
public bool Update(float delta)
|
2020-05-07 03:53:54 +01:00
|
|
|
|
{
|
2020-11-27 22:47:33 +00:00
|
|
|
|
_locomotion.Objective = Zone.GetOrbitPosition(_targetOrbit);
|
2020-05-07 03:53:54 +01:00
|
|
|
|
_locomotion.Update(delta);
|
|
|
|
|
|
|
|
|
|
|
|
if(length(_entity.Position - _locomotion.Objective) < _data.TargetDistance)
|
|
|
|
|
|
RandomTarget();
|
2020-05-11 01:17:10 +01:00
|
|
|
|
|
|
|
|
|
|
return true;
|
2020-05-07 03:53:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-27 02:23:25 +01:00
|
|
|
|
public void AssignTask(Guid task)
|
2020-05-07 03:53:54 +01:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void RandomTarget()
|
|
|
|
|
|
{
|
2020-11-27 22:47:33 +00:00
|
|
|
|
_targetOrbit = Zone.Planets.Keys.ToArray()[_context.Random.NextInt(Zone.Planets.Count)];
|
2020-05-07 03:53:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|