2020-06-02 21:41:31 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using MessagePack;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using RethinkDb.Driver.Ast;
|
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
using static Unity.Mathematics.math;
|
|
|
|
|
|
|
|
|
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), Order(-100)]
|
|
|
|
|
|
public class WanderControllerData : ControllerData
|
|
|
|
|
|
{
|
|
|
|
|
|
[InspectableField, JsonProperty("randomDockTime"), Key(6)]
|
|
|
|
|
|
public float RandomDockTime = 5;
|
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
2020-06-02 21:41:31 +01:00
|
|
|
|
{
|
|
|
|
|
|
return new WanderController(context, this, entity, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public class WanderController : ControllerBase<WanderTask>, IBehavior
|
2020-06-02 21:41:31 +01:00
|
|
|
|
{
|
|
|
|
|
|
public WanderTarget WanderTarget;
|
|
|
|
|
|
public BehaviorData Data => _data;
|
|
|
|
|
|
|
|
|
|
|
|
private WanderControllerData _data;
|
2020-12-10 23:20:38 +00:00
|
|
|
|
private EquippedItem Item { get; }
|
2020-06-02 21:41:31 +01:00
|
|
|
|
private Guid _target;
|
|
|
|
|
|
private float _dockTime = -1;
|
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public WanderController(ItemManager itemManager, WanderControllerData data, Entity entity, EquippedItem item) : base(itemManager, data, entity)
|
2020-06-02 21:41:31 +01:00
|
|
|
|
{
|
|
|
|
|
|
_data = data;
|
2020-12-10 23:20:38 +00:00
|
|
|
|
Item = item;
|
2020-06-02 21:41:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public new bool Update(float delta)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Moving && _dockTime < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
NextTarget();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_dockTime -= delta;
|
|
|
|
|
|
return base.Update(delta);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void NextTarget()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (WanderTarget == WanderTarget.Planets)
|
|
|
|
|
|
{
|
2020-11-27 22:47:33 +00:00
|
|
|
|
var planets = Zone.Planets.Values.ToArray();
|
2020-12-10 23:20:38 +00:00
|
|
|
|
var randomPlanet = planets[ItemManager.Random.NextInt(planets.Length)];
|
2020-11-27 22:47:33 +00:00
|
|
|
|
MoveTo(() => Zone.GetOrbitPosition(randomPlanet.Orbit), () => Zone.GetOrbitVelocity(randomPlanet.Orbit));
|
2020-06-02 21:41:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
else if (WanderTarget == WanderTarget.Orbitals)
|
|
|
|
|
|
{
|
2020-12-10 23:20:38 +00:00
|
|
|
|
var entities = Zone.Entities.Where(e=>e is OrbitalEntity).ToArray();
|
|
|
|
|
|
var randomEntity = entities[ItemManager.Random.NextInt(entities.Length)];
|
2020-06-02 21:41:31 +01:00
|
|
|
|
MoveTo(randomEntity, true, () =>
|
|
|
|
|
|
{
|
2020-12-10 23:20:38 +00:00
|
|
|
|
Entity.SetParent(randomEntity);
|
|
|
|
|
|
_dockTime = ItemManager.Random.NextFloat(_data.RandomDockTime);
|
2020-06-02 21:41:31 +01:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public enum WanderTarget
|
|
|
|
|
|
{
|
|
|
|
|
|
Planets,
|
|
|
|
|
|
Orbitals
|
|
|
|
|
|
}
|