Misc Changes
This commit is contained in:
parent
4eb83acb34
commit
c48d3bbc3e
19 changed files with 356 additions and 42 deletions
|
|
@ -93,6 +93,7 @@ public abstract class PersistentBehaviorData
|
|||
Union(26, typeof(MiningToolData)),
|
||||
Union(27, typeof(SurveyControllerData)),
|
||||
Union(28, typeof(ResourceScannerData)),
|
||||
Union(29, typeof(WanderControllerData)),
|
||||
JsonConverter(typeof(JsonKnownTypesConverter<BehaviorData>)), JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class BehaviorData
|
||||
{
|
||||
|
|
|
|||
80
Assets/Scripts/ServerShared/Behaviors/WanderController.cs
Normal file
80
Assets/Scripts/ServerShared/Behaviors/WanderController.cs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
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;
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
{
|
||||
return new WanderController(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class WanderController : ControllerBase, IBehavior
|
||||
{
|
||||
public WanderTarget WanderTarget;
|
||||
public override TaskType TaskType => TaskType.None;
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private WanderControllerData _data;
|
||||
private GameContext _context;
|
||||
private Entity _entity;
|
||||
private Gear _item;
|
||||
private Guid _target;
|
||||
private float _dockTime = -1;
|
||||
|
||||
public WanderController(GameContext context, WanderControllerData data, Entity entity, Gear item) : base(context, data, entity)
|
||||
{
|
||||
_context = context;
|
||||
_data = data;
|
||||
_entity = entity;
|
||||
_item = item;
|
||||
}
|
||||
|
||||
public new bool Update(float delta)
|
||||
{
|
||||
if (!Moving && _dockTime < 0)
|
||||
{
|
||||
NextTarget();
|
||||
}
|
||||
|
||||
_dockTime -= delta;
|
||||
return base.Update(delta);
|
||||
}
|
||||
|
||||
private void NextTarget()
|
||||
{
|
||||
if (WanderTarget == WanderTarget.Planets)
|
||||
{
|
||||
var planets = _context.ZonePlanets[_entity.Zone];
|
||||
var randomPlanet = _context.Cache.Get<PlanetData>(planets[_context.Random.NextInt(planets.Length)]);
|
||||
MoveTo(() => _context.GetOrbitPosition(randomPlanet.Orbit), () => _context.GetOrbitVelocity(randomPlanet.Orbit));
|
||||
}
|
||||
else if (WanderTarget == WanderTarget.Orbitals)
|
||||
{
|
||||
var entities = _context.ZoneEntities[_entity.Zone].Values.ToArray();
|
||||
var randomEntity = entities[_context.Random.NextInt(entities.Length)];
|
||||
MoveTo(randomEntity, true, () =>
|
||||
{
|
||||
_context.SetParent(_entity, randomEntity);
|
||||
_dockTime = _context.Random.NextFloat(_data.RandomDockTime);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum WanderTarget
|
||||
{
|
||||
Planets,
|
||||
Orbitals
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 38e6f1535d5cf5642bd01b1ab7a34492
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue