Aetheria/Assets/Scripts/ServerShared/Behaviors/PatrolController.cs
Reinier Vens fddd485262 Hellfire
Targeting
Target locking
Crosshairs
Improved HUD schematic feedback
Equipment Heat Damage
Equipment Disabling
2021-01-10 03:59:47 +00:00

63 lines
1.9 KiB
C#

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), Order(-100)]
public class PatrolControllerData : ControllerData
{
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
{
return new PatrolController(context, this, entity, item);
}
}
public class PatrolController : IBehavior, IInitializableBehavior
{
public BehaviorData Data => _data;
private PatrolControllerData _data;
private ItemManager Context { get; }
private Entity Entity { get; }
private EquippedItem Item { get; }
private Locomotion _locomotion;
private Guid _targetOrbit;
public PatrolController(ItemManager context, PatrolControllerData data, Entity entity, EquippedItem item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public void Initialize()
{
_locomotion = new Locomotion(Context, Entity, _data);
RandomTarget();
}
public bool Execute(float delta)
{
_locomotion.Objective = Entity.Zone.GetOrbitPosition(_targetOrbit);
_locomotion.Update(delta);
if(length(Entity.Position.xz - _locomotion.Objective) < _data.TargetDistance)
RandomTarget();
return true;
}
private void RandomTarget()
{
_targetOrbit = Entity.Zone.Planets.Keys.ToArray()[Context.Random.NextInt(Entity.Zone.Planets.Count)];
}
}