Move loot bodies and pickup contacts into Ymir
This commit is contained in:
parent
def4a5b906
commit
3a38f050de
7 changed files with 142 additions and 43 deletions
|
|
@ -803,23 +803,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return false;
|
||||
|
||||
var pickup = pickups[pickupIndex];
|
||||
var quantity = Math.Max(1, pickup.Item?.Quantity ?? command.LootPickup.Quantity);
|
||||
if (pickup.AgeSeconds >= pickup.LifetimeSeconds ||
|
||||
Math.Pow(pickup.PositionX - entity.PositionX, 2) + Math.Pow(pickup.PositionZ - entity.PositionZ, 2) > 25 * 25 ||
|
||||
quantity > AetheriaRuntimeCargoCapacityQueries.UnitsThatFit(entity, catalog, pickup.Item?.ItemKey ?? command.LootPickup.ItemKey))
|
||||
return false;
|
||||
pickups.RemoveAt(pickupIndex);
|
||||
zone.DroppedPickups = pickups.ToArray();
|
||||
|
||||
AddCargoItem(entity, 0, new AetheriaRuntimeLoadoutItemSlotCommit
|
||||
{
|
||||
Item = pickup.Item ?? new AetheriaRuntimeLoadoutItemCommit
|
||||
{
|
||||
ItemKey = command.LootPickup.ItemKey ?? "",
|
||||
Quantity = command.LootPickup.Quantity
|
||||
}
|
||||
});
|
||||
return true;
|
||||
return AetheriaRuntimePickupTransactions.TryCollect(zone, entity, pickup.PickupIndex, catalog);
|
||||
}
|
||||
|
||||
private static bool ApplyToggleHullConductivity(
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ namespace GameCult.Aetheria.State.Verse
|
|||
StepTractorPower(entities, deltaSeconds);
|
||||
StepRaiderAi(entities);
|
||||
StepTargetPursuit(entities, settings);
|
||||
StepWorldPhysics(zone, entities, deltaSeconds, worldPhysics);
|
||||
var worldStep = StepWorldPhysics(zone, entities, deltaSeconds, worldPhysics);
|
||||
ResolvePickupContacts(zone, entities, worldStep, catalog);
|
||||
StepCombat(run, zone, entities, intents, deltaSeconds, settings, projectilePhysics);
|
||||
AetheriaRuntimeMiningSimulation.Step(run, zone, entities, intents, catalog, frameId, simulationTimeSeconds, deltaSeconds);
|
||||
AetheriaRuntimeSurveySimulation.Step(run, zone, entities, intents, catalog, frameId, simulationTimeSeconds, deltaSeconds);
|
||||
|
|
@ -158,7 +159,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
}
|
||||
}
|
||||
|
||||
private static void StepWorldPhysics(
|
||||
private static AetheriaRuntimeWorldStep StepWorldPhysics(
|
||||
AetheriaRuntimeZoneSnapshotCommit zone,
|
||||
IReadOnlyList<AetheriaRuntimeEntitySnapshotCommit> entities,
|
||||
double deltaSeconds,
|
||||
|
|
@ -173,6 +174,14 @@ namespace GameCult.Aetheria.State.Verse
|
|||
entity.VelocityX = body.VelocityX; entity.VelocityY = body.VelocityY;
|
||||
entity.DirectionX = body.DirectionX; entity.DirectionY = body.DirectionY;
|
||||
}
|
||||
var pickups = (zone.DroppedPickups ?? Array.Empty<AetheriaRuntimeDroppedPickupCommit>())
|
||||
.Where(pickup => pickup != null).ToDictionary(pickup => pickup.PickupIndex);
|
||||
foreach (var body in result.Pickups)
|
||||
{
|
||||
if (!pickups.TryGetValue(body.PickupIndex, out var pickup)) continue;
|
||||
pickup.PositionX = body.PositionX; pickup.PositionZ = body.PositionZ;
|
||||
pickup.VelocityX = body.VelocityX; pickup.VelocityZ = body.VelocityZ;
|
||||
}
|
||||
foreach (var parent in entities)
|
||||
foreach (var childIndex in parent.ChildEntityIndices ?? Array.Empty<int>())
|
||||
{
|
||||
|
|
@ -181,6 +190,30 @@ namespace GameCult.Aetheria.State.Verse
|
|||
child.PositionX = parent.PositionX; child.PositionZ = parent.PositionZ;
|
||||
child.VelocityX = parent.VelocityX; child.VelocityY = parent.VelocityY;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void ResolvePickupContacts(
|
||||
AetheriaRuntimeZoneSnapshotCommit zone,
|
||||
IReadOnlyList<AetheriaRuntimeEntitySnapshotCommit> entities,
|
||||
AetheriaRuntimeWorldStep worldStep,
|
||||
AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
{
|
||||
foreach (var contact in worldStep.Contacts.Where(contact => contact.PickupIndex >= 0))
|
||||
{
|
||||
var entityIndex = Math.Max(contact.EntityAIndex, contact.EntityBIndex);
|
||||
var entity = entities.FirstOrDefault(value => value.EntityIndex == entityIndex && value.IsActive);
|
||||
var pickup = (zone.DroppedPickups ?? Array.Empty<AetheriaRuntimeDroppedPickupCommit>())
|
||||
.FirstOrDefault(value => value != null && value.PickupIndex == contact.PickupIndex);
|
||||
if (entity == null || pickup == null) continue;
|
||||
if (AetheriaRuntimePickupTransactions.TryCollect(zone, entity, pickup.PickupIndex, catalog, requireRange: false))
|
||||
continue;
|
||||
var dx = pickup.PositionX - entity.PositionX; var dz = pickup.PositionZ - entity.PositionZ;
|
||||
var length = Math.Sqrt(dx * dx + dz * dz);
|
||||
if (length < 0.001) { dx = 1; dz = 0; length = 1; }
|
||||
pickup.VelocityX += dx / length * 25;
|
||||
pickup.VelocityZ += dz / length * 25;
|
||||
}
|
||||
}
|
||||
|
||||
private static void StepCombat(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Verse
|
||||
{
|
||||
public static class AetheriaRuntimePickupTransactions
|
||||
{
|
||||
public static bool TryCollect(AetheriaRuntimeZoneSnapshotCommit zone, AetheriaRuntimeEntitySnapshotCommit entity,
|
||||
int pickupIndex, AetheriaRuntimeCatalogSnapshot? catalog, bool requireRange = true)
|
||||
{
|
||||
var pickups = (zone.DroppedPickups ?? Array.Empty<AetheriaRuntimeDroppedPickupCommit>()).ToList();
|
||||
var index = pickups.FindIndex(pickup => pickup != null && pickup.PickupIndex == pickupIndex);
|
||||
if (index < 0) return false;
|
||||
var pickup = pickups[index];
|
||||
var quantity = Math.Max(1, pickup.Item?.Quantity ?? 1);
|
||||
if (pickup.AgeSeconds >= pickup.LifetimeSeconds ||
|
||||
(requireRange && Math.Pow(pickup.PositionX - entity.PositionX, 2) + Math.Pow(pickup.PositionZ - entity.PositionZ, 2) > 25 * 25) ||
|
||||
quantity > AetheriaRuntimeCargoCapacityQueries.UnitsThatFit(entity, catalog, pickup.Item?.ItemKey ?? ""))
|
||||
return false;
|
||||
var bays = (entity.CargoContents ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>()).ToList();
|
||||
if (bays.Count == 0) bays.Add(new AetheriaRuntimeCargoBayLoadoutCommit());
|
||||
var slots = (bays[0].Items ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>()).ToList();
|
||||
var existing = slots.FirstOrDefault(slot => string.Equals(slot?.Item?.ItemKey, pickup.Item.ItemKey, StringComparison.Ordinal));
|
||||
if (existing != null) existing.Item.Quantity += quantity;
|
||||
else slots.Add(new AetheriaRuntimeLoadoutItemSlotCommit { Item = pickup.Item });
|
||||
bays[0].Items = slots; entity.CargoContents = bays;
|
||||
pickups.RemoveAt(index); zone.DroppedPickups = pickups;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,12 +13,22 @@ namespace GameCult.Aetheria.State.Verse
|
|||
|
||||
public sealed class AetheriaRuntimeWorldStep
|
||||
{
|
||||
public AetheriaRuntimeWorldStep(IReadOnlyList<AetheriaRuntimeWorldBodyStep> bodies, IReadOnlyList<AetheriaRuntimeWorldContact> contacts)
|
||||
{ Bodies = bodies ?? Array.Empty<AetheriaRuntimeWorldBodyStep>(); Contacts = contacts ?? Array.Empty<AetheriaRuntimeWorldContact>(); }
|
||||
public AetheriaRuntimeWorldStep(IReadOnlyList<AetheriaRuntimeWorldBodyStep> bodies, IReadOnlyList<AetheriaRuntimeWorldPickupStep> pickups, IReadOnlyList<AetheriaRuntimeWorldContact> contacts)
|
||||
{ Bodies = bodies ?? Array.Empty<AetheriaRuntimeWorldBodyStep>(); Pickups = pickups ?? Array.Empty<AetheriaRuntimeWorldPickupStep>(); Contacts = contacts ?? Array.Empty<AetheriaRuntimeWorldContact>(); }
|
||||
public IReadOnlyList<AetheriaRuntimeWorldBodyStep> Bodies { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeWorldPickupStep> Pickups { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeWorldContact> Contacts { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeWorldPickupStep
|
||||
{
|
||||
public int PickupIndex { get; set; } = -1;
|
||||
public double PositionX { get; set; }
|
||||
public double PositionZ { get; set; }
|
||||
public double VelocityX { get; set; }
|
||||
public double VelocityZ { get; set; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeWorldBodyStep
|
||||
{
|
||||
public int EntityIndex { get; set; } = -1;
|
||||
|
|
@ -34,6 +44,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
{
|
||||
public int EntityAIndex { get; set; } = -1;
|
||||
public int EntityBIndex { get; set; } = -1;
|
||||
public int PickupIndex { get; set; } = -1;
|
||||
public double PointX { get; set; }
|
||||
public double PointZ { get; set; }
|
||||
public double NormalX { get; set; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue