New Inventory System + Overhaul
Removed universal GameContext references Refactored GameContext: It's now only responsible for item management. As such it's now called ItemManager GlobalData is gone, relevant settings are distributed amongst specialized settings classes Entities are no longer database entries, references to them are now direct - Zone is reponsible for storing them in ZonePacks Controller subtypes are now generic classes, class argument is task type Inventory is now a 2D grid instead of a list Entity temperature is now a 2D grid instead of a number Item sizes are now arbitrary shapes instead of a number Hardpoints are now arbitrary shapes instead Equipped items have their own temperatures Map view now displays sunlight colors Integrated Allegorithmic Substance Plugin Imported Djinni ship and assigned Substance materials Removed Node Editor framework (might come back later but needs work to integrate with behavior system)
This commit is contained in:
parent
53a91351b7
commit
f643f6cc8a
330 changed files with 24242 additions and 2830 deletions
|
|
@ -11,109 +11,102 @@ using static Unity.Mathematics.math;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), Order(-100)]
|
||||
public class SurveyControllerData : ControllerData
|
||||
{
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new SurveyController(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class SurveyController : ControllerBase, IBehavior, IPersistentBehavior, IInitializableBehavior
|
||||
public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBehavior, IInitializableBehavior
|
||||
{
|
||||
public override TaskType TaskType => TaskType.Explore;
|
||||
private EquippedItem Item { get; }
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private SurveyControllerData _data;
|
||||
private GameContext _context;
|
||||
private Entity _entity;
|
||||
private Gear _item;
|
||||
private bool _taskStarted;
|
||||
private ResourceScanner _scanningTool;
|
||||
private Switch _toolSwitch;
|
||||
private Guid _targetPlanet;
|
||||
private int _asteroid = -1;
|
||||
|
||||
public SurveyController(GameContext context, SurveyControllerData data, Entity entity, Gear item) : base(context, data, entity)
|
||||
public SurveyController(ItemManager itemManager, SurveyControllerData data, Entity entity, EquippedItem item) : base(itemManager, data, entity)
|
||||
{
|
||||
_context = context;
|
||||
_data = data;
|
||||
_entity = entity;
|
||||
_item = item;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public new void Initialize()
|
||||
{
|
||||
_scanningTool = _entity.GetBehavior<ResourceScanner>();
|
||||
_toolSwitch = _entity.GetSwitch<ResourceScanner>();
|
||||
_scanningTool = Entity.GetBehavior<ResourceScanner>();
|
||||
_toolSwitch = Entity.GetSwitch<ResourceScanner>();
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
public new bool Update(float delta)
|
||||
{
|
||||
var surveyTask = _context.Cache.Get<Survey>(Task);
|
||||
var corporation = _context.Cache.Get<Corporation>(_entity.Corporation);
|
||||
if (surveyTask != null)
|
||||
{
|
||||
if (!_taskStarted)
|
||||
{
|
||||
if (surveyTask.Planets.Any())
|
||||
{
|
||||
_entity.SetMessage("Moving to survey target.");
|
||||
NextPlanet();
|
||||
_scanningTool.ScanTarget = _targetPlanet;
|
||||
_scanningTool.Asteroid = _asteroid;
|
||||
if (!corporation.PlanetSurveyFloor.ContainsKey(_targetPlanet) ||
|
||||
corporation.PlanetSurveyFloor[_targetPlanet] + .5f < _scanningTool.MinimumDensity)
|
||||
{
|
||||
var planetData = _context.Cache.Get<BodyData>(_targetPlanet);
|
||||
MoveTo(() =>
|
||||
{
|
||||
var target = GetPosition(planetData, _asteroid);
|
||||
var targetToUs = _entity.Position - target;
|
||||
return target + normalize(targetToUs) * _scanningTool.Range / 2;
|
||||
},
|
||||
() => GetVelocity(planetData, _asteroid),
|
||||
() => _entity.SetMessage("Arrived at target. Scanning for resources."));
|
||||
_taskStarted = true;
|
||||
}
|
||||
else
|
||||
surveyTask.Planets.Remove(_targetPlanet);
|
||||
}
|
||||
else
|
||||
{
|
||||
_entity.SetMessage("Survey complete. Returning Home.");
|
||||
FinishTask();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Moving)
|
||||
{
|
||||
var planetData = _context.Cache.Get<BodyData>(_targetPlanet);
|
||||
if ((!corporation.PlanetSurveyFloor.ContainsKey(_targetPlanet) ||
|
||||
corporation.PlanetSurveyFloor[_targetPlanet] + .5f < _scanningTool.MinimumDensity) &&
|
||||
length(_entity.Position - GetPosition(planetData, _asteroid)) < _scanningTool.Range)
|
||||
{
|
||||
_toolSwitch.Activated = true;
|
||||
Aim.Objective = GetPosition(planetData, _asteroid);
|
||||
Aim.Update(delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
_toolSwitch.Activated = false;
|
||||
_taskStarted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// var corporation = _context.ItemData.Get<Corporation>(_entity.Corporation);
|
||||
// if (surveyTask != null)
|
||||
// {
|
||||
// if (!_taskStarted)
|
||||
// {
|
||||
// if (surveyTask.Planets.Any())
|
||||
// {
|
||||
// _entity.SetMessage("Moving to survey target.");
|
||||
// NextPlanet();
|
||||
// _scanningTool.ScanTarget = _targetPlanet;
|
||||
// _scanningTool.Asteroid = _asteroid;
|
||||
// if (!corporation.PlanetSurveyFloor.ContainsKey(_targetPlanet) ||
|
||||
// corporation.PlanetSurveyFloor[_targetPlanet] + .5f < _scanningTool.MinimumDensity)
|
||||
// {
|
||||
// var planetData = _context.ItemData.Get<BodyData>(_targetPlanet);
|
||||
// MoveTo(() =>
|
||||
// {
|
||||
// var target = GetPosition(planetData, _asteroid);
|
||||
// var targetToUs = _entity.Position - target;
|
||||
// return target + normalize(targetToUs) * _scanningTool.Range / 2;
|
||||
// },
|
||||
// () => GetVelocity(planetData, _asteroid),
|
||||
// () => _entity.SetMessage("Arrived at target. Scanning for resources."));
|
||||
// _taskStarted = true;
|
||||
// }
|
||||
// else
|
||||
// surveyTask.Planets.Remove(_targetPlanet);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _entity.SetMessage("Survey complete. Returning Home.");
|
||||
// FinishTask();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (!Moving)
|
||||
// {
|
||||
// var planetData = _context.ItemData.Get<BodyData>(_targetPlanet);
|
||||
// if ((!corporation.PlanetSurveyFloor.ContainsKey(_targetPlanet) ||
|
||||
// corporation.PlanetSurveyFloor[_targetPlanet] + .5f < _scanningTool.MinimumDensity) &&
|
||||
// length(_entity.Position - GetPosition(planetData, _asteroid)) < _scanningTool.Range)
|
||||
// {
|
||||
// _toolSwitch.Activated = true;
|
||||
// Aim.Objective = GetPosition(planetData, _asteroid);
|
||||
// Aim.Update(delta);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _toolSwitch.Activated = false;
|
||||
// _taskStarted = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return base.Update(delta);
|
||||
}
|
||||
|
||||
private void NextPlanet()
|
||||
{
|
||||
var surveyTask = _context.Cache.Get<Survey>(Task);
|
||||
var planets = surveyTask.Planets.Select(id => Zone.Planets[id]);
|
||||
var nearestPlanet = planets.MinBy(p => lengthsq(_entity.Position - GetPosition(p)));
|
||||
_asteroid = nearestPlanet is AsteroidBeltData ? Zone.NearestAsteroid(nearestPlanet.ID, _entity.Position) : -1;
|
||||
var planets = Task.Planets.Select(id => Zone.Planets[id]);
|
||||
var nearestPlanet = planets.MinBy(p => lengthsq(Entity.Position - GetPosition(p)));
|
||||
_asteroid = nearestPlanet is AsteroidBeltData ? Zone.NearestAsteroid(nearestPlanet.ID, Entity.Position) : -1;
|
||||
_targetPlanet = nearestPlanet.ID;
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +114,7 @@ public class SurveyController : ControllerBase, IBehavior, IPersistentBehavior,
|
|||
{
|
||||
if (planet is AsteroidBeltData)
|
||||
{
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, _entity.Position);
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position);
|
||||
return Zone.GetAsteroidTransform(planet.ID, asteroid).xy;
|
||||
}
|
||||
return Zone.GetOrbitPosition(planet.Orbit);
|
||||
|
|
@ -131,7 +124,7 @@ public class SurveyController : ControllerBase, IBehavior, IPersistentBehavior,
|
|||
{
|
||||
if (planet is AsteroidBeltData)
|
||||
{
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, _entity.Position);
|
||||
if(asteroid == -1) asteroid = Zone.NearestAsteroid(planet.ID, Entity.Position);
|
||||
return Zone.GetAsteroidVelocity(planet.ID, asteroid);
|
||||
}
|
||||
return Zone.GetOrbitVelocity(planet.Orbit);
|
||||
|
|
@ -155,5 +148,5 @@ public class SurveyController : ControllerBase, IBehavior, IPersistentBehavior,
|
|||
public class SurveyControllerPersistence : PersistentBehaviorData
|
||||
{
|
||||
[JsonProperty("task"), Key(0)]
|
||||
public Guid Task;
|
||||
public Survey Task;
|
||||
}
|
||||
Loading…
Reference in a new issue