Control Modules & Job System
Agent behaviors are no longer hard coded but instead created by equippable control modules Game Context has a job system which assigns appropriate tasks to drone control modules
This commit is contained in:
parent
6aeb2ae280
commit
ab8aa5fb9a
27 changed files with 480 additions and 190 deletions
68
Assets/Scripts/ServerShared/Behaviors/PatrolController.cs
Normal file
68
Assets/Scripts/ServerShared/Behaviors/PatrolController.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship)]
|
||||
public class PatrolControllerData : ControllerData
|
||||
{
|
||||
[InspectableField, JsonProperty("targetDistance"), Key(4)]
|
||||
public float TargetDistance = 10;
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
{
|
||||
return new PatrolController(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class PatrolController : IBehavior, IController
|
||||
{
|
||||
public TaskType JobType => TaskType.Tow;
|
||||
public bool Available => false;
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private PatrolControllerData _data;
|
||||
private GameContext _context;
|
||||
private Entity _entity;
|
||||
private Gear _item;
|
||||
private Guid _towingTask;
|
||||
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();
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
{
|
||||
_locomotion.Objective = _context.GetOrbitPosition(_targetOrbit);
|
||||
_locomotion.Update(delta);
|
||||
|
||||
if(length(_entity.Position - _locomotion.Objective) < _data.TargetDistance)
|
||||
RandomTarget();
|
||||
}
|
||||
|
||||
public void AssignTask(Guid task)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void RandomTarget()
|
||||
{
|
||||
var entities = _context.ZonePlanets[_entity.Zone];
|
||||
_targetOrbit = _context.Cache.Get<PlanetData>(entities[_context.Random.NextInt(entities.Length)]).Orbit;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue