Skip to content

Commit

Permalink
Area effect changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
agm-114 committed Dec 1, 2024
1 parent bedda42 commit 855fba4
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 59 deletions.
56 changes: 39 additions & 17 deletions AGMLIB/Dynamic Systems/Area/Core/AreaEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,33 @@ public class AreaEffect : ActiveSettings
private Color? _oldcolor;
private float _updateAccum = 0f;

public Material Material => _followingInstance.GetComponentInChildren<MeshRenderer>().material;
public Material Material
{
get
{
//if (_followingInstance == null)
// Common.Hint("Following Instance Null");
MeshRenderer renderer = _followingInstance.GetComponentInChildren<MeshRenderer>();
//if (renderer == null)
// Common.Hint("Following mesh Null");
//if(_followingInstance.GetComponentInChildren<MeshRenderer>(includeInactive:true).material == null)
// Common.Hint("Following mat Null");

return _followingInstance.GetComponentInChildren<MeshRenderer>(includeInactive: true).material;
}
}

//public List<BasicEffect<Ship>> ShipEffects = new();
//public List<BasicEffect<ModularMissile>> ModularMissileEffects = new();
//public List<BasicEffect<ModularMissile>> ModularMissileEffects = new();


public List<BasicEffect> Effects;

public void Fire()
{
StopFire();//_EmissionColor
if (_followingInstance != null)
return;
//StopFire();//_EmissionColor
//Debug.LogError("Creating Sphere");
string PrefabName = "Stock/E70 'Interruption' Jammer";
HullComponent goodewar = BundleManager.Instance.AllComponents.FirstOrDefault(x => x.SaveKey == PrefabName);
Expand All @@ -55,7 +71,7 @@ public void Fire()
if(prefab == null)
Debug.LogError("Did not get following prefab");
else
_followingInstance = NetworkObjectPooler.Instance?.GetNextOrNew(prefab, transform.position, transform.rotation );
_followingInstance = NetworkObjectPooler.Instance.GetNextOrNew(prefab, transform.position, transform.rotation);
if (_followingInstance is ISettableEWarParameters settableEWarParameters)
{
settableEWarParameters.SetParams(SignatureType.Radar, omni: true, 360f, Radius, 1, 0, 0, 0f, true);
Expand All @@ -69,14 +85,17 @@ public void Fire()

public void StopFire()
{
if (_followingInstance != null)
{
if(_oldcolor != null)
Material.SetColor(matproperty, _oldcolor.Value);
_followingInstance.RepoolSelf();
_followingInstance = null;
_oldcolor = null;
}

if (_followingInstance == null)
return;
//Debug.LogError("Stopping Sphere");

if (_oldcolor != null)
Material.SetColor(matproperty, _oldcolor.Value);
//DestroyImmediate(_followingInstance);
_followingInstance.RepoolSelf();
_followingInstance = null;
_oldcolor = null;
}

// Start is called before the first frame update
Expand All @@ -86,7 +105,7 @@ void Start()
{
effect.AreaEffect = this;
effect.Setup();
}
}
if (Trigger == null)
{
SphereCollider sphereCollider = gameObject.GetOrAddComponent<SphereCollider>();
Expand All @@ -95,7 +114,7 @@ void Start()
}
else if(Trigger is SphereCollider sphere)
{
//Radius = sphere.radius;
Radius = sphere.radius;
}

Trigger.isTrigger = true;
Expand All @@ -108,6 +127,7 @@ void Start()
protected override void FixedUpdate()
{
base.FixedUpdate();
//Debug.LogError($"{Buttonstate} current buttonstate | targetbuttonstate {activateButtonState}");
if (InEditor)
return;
//Debug.LogError("Core Fixed Update");
Expand All @@ -130,18 +150,20 @@ protected override void FixedUpdate()
}

}


_laststate = active;

_updateAccum += Time.fixedDeltaTime;
if(CustomVFX)
{

if (active && _followingInstance == null)
if (active)
Fire();
else if (!active)
else
StopFire();
if ((_updateEveryFrame || _updateAccum >= _updateInterval) && _followingInstance != null)

if (_followingInstance != null && (_updateEveryFrame || _updateAccum >= _updateInterval))
{
_updateAccum = 0f;
_followingInstance.transform.position = base.transform.position;
Expand Down
16 changes: 8 additions & 8 deletions AGMLIB/Dynamic Systems/Area/RepairEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ public class RepairEffect : FalloffEffect<Ship>
protected float _accum = 0;
public override void FixedUpdate()
{
//Debug.LogError("Generic Fixed Update");
//
_accum += Time.fixedDeltaTime;
if(_accum < 1)
return;
_accum -= 1;
if (Active)
{
//Debug.LogError("Generic repair Fixed Update");
IEnumerable<IEnumerable<HullPart>> ships = new List<IEnumerable<HullPart>>();
IEnumerable<RestoreStatus> lockers = new List<RestoreStatus>();
foreach (Ship target in Targets.Where(target => target != null))
Expand All @@ -66,21 +67,20 @@ public override void FixedUpdate()
parts = parts.OrderByDescending(h => h.DCPriority);
parts = parts.Take(MaxRepairsPerHull);
}
if(parts.Count() > 0)
ships.Append(parts);
if(parts.Any())
ships = ships.Append(parts);
else
{
IEnumerable<RestoreStatus> shiplockers = root.GetComponentsInChildren<DCLockerComponent>().ToList().OrderByDescending(h => h.DCPriority).ConvertAll(locker => RestoreStatus.GetRestoreStatus(locker)).Where(status => status.NeedsRestores).Take(1);
if(shiplockers.Count() > 0)
{
lockers.First();
}
IEnumerable<RestoreStatus> hulllockers = root.GetComponentsInChildren<DCLockerComponent>().ToList().OrderByDescending(h => h.DCPriority).ConvertAll(locker => RestoreStatus.GetRestoreStatus(locker)).Where(status => status.NeedsRestores).Take(1);
if (hulllockers.Any())
lockers = lockers.Append(hulllockers.First());
}

}
float repairsperhull = RepairPerSecond / (ships.Count() + lockers.Count());
foreach(IEnumerable<HullPart> repairparts in ships)
{
//continue;
float repairsperpart = repairsperhull / repairparts.Count();

foreach(HullPart hullPart in repairparts)
Expand Down
81 changes: 47 additions & 34 deletions AGMLIB/Dynamic Systems/Area/ResupplyEffect.cs
Original file line number Diff line number Diff line change
@@ -1,67 +1,80 @@
using static Ships.BulkMagazineComponent;
using static UnityEngine.UI.CanvasScaler;

namespace AGMLIB.Dynamic_Systems.Area
{
public class ResupplyEffect : FalloffEffect<Ship>
{
public float PointsPerSecond = 1;

private float ReloadPoints = 0;

public bool BulkMagazines = true;
public bool CellLaunchers = true;

[SerializeField] protected ISimpleFilter _simplefilter;


public override void TargetFixedUpdate(Ship target)
{
ReloadPoints += PointsPerSecond * Time.fixedDeltaTime;
if (target == AreaEffect.Ship)
return;

if (AreaEffect.ShipController?.GetIFF(target?.Controller?.OwnedBy) == IFF.Enemy)
return;

Transform targettransform = target.gameObject.transform.root;
//Debug.LogError("Resupply Ship");

bool dirtymissiles = false;

List<IEnumerable<KeyValuePair<IMagazine, HullComponent>>> test1 = new();
if(BulkMagazines)
test1.AddRange(targettransform.GetComponentsInChildren<BulkMagazineComponent>().ConvertAll(comp => comp.Magazines.Select(mag => new KeyValuePair<IMagazine, HullComponent>(mag, comp))));
if(CellLaunchers)
test1.AddRange(targettransform.GetComponentsInChildren<CellLauncherComponent>().ConvertAll(comp => comp.Missiles .Select(mag => new KeyValuePair<IMagazine, HullComponent>(mag, comp))));
IEnumerable<KeyValuePair<IMagazine, HullComponent>> test2 = test1.SelectMany(list => list).Where(pair => pair.Key.QuantityAvailable < pair.Key.PeakQuantity);
if (_simplefilter != null)
test2 = test2.Where(pair => _simplefilter.IsAmmoCompatible(pair.Key.AmmoType));
IOrderedEnumerable<KeyValuePair<IMagazine, HullComponent>> test3 = test2.OrderBy(kvp => kvp.Key.PercentageAvailable);

foreach (BulkMagazineComponent hullComponent in target.gameObject.transform.root.GetComponentsInChildren<BulkMagazineComponent>())
{

BulkMagazineData magdata = hullComponent.gameObject.GetComponent<StartState>().saveData as BulkMagazineData;
List<IMagazine> mags = hullComponent.Magazines.ToList();

foreach (IMagazine mag in hullComponent.Magazines)
{
if(mag.QuantityAvailable < mag.PeakQuantity)
{
Debug.LogError($"{AreaEffect.Ship.gameObject.name} Resupply Ship {target.gameObject.name} {mag.AmmoType.MunitionName} {mag.QuantityAvailable}/{mag.PeakQuantity}");
hullComponent.AddToMagazine(mag.AmmoType, 1u);

AreaEffect.Hull.MyShip.AmmoFeed.GetAmmoSource(mag.AmmoType).Withdraw(1u);

}
}

foreach (Magazine.MagSaveData targetdata in magdata.Load)
{
IMunition munition = AreaEffect.Hull.MyShip.Fleet.AvailableMunitions.GetMunition(targetdata.MunitionKey);
foreach (var kvp in test3)
{
IMagazine sink = kvp.Key;
IMagazine source = AreaEffect.Hull.MyShip.AmmoFeed.GetAmmoSource(sink.AmmoType);
HullComponent hullComponent = kvp.Value;

IMagazine mag = mags.Find(x => x.AmmoType == munition);
if (sink.AmmoType.PointCost > ReloadPoints)
return;

//if(mag.)
//hullComponent.AddToMagazine(mags, 1);
}
}
foreach (CellLauncherComponent hullComponent in target.gameObject.transform.root.GetComponentsInChildren<CellLauncherComponent>())
{
IMagazineProvider magazineProvider = hullComponent as IMagazineProvider;
uint reloadamount = (uint)Math.Min((uint)Math.Min(source.QuantityAvailable, sink.PeakQuantity - sink.QuantityAvailable), ReloadPoints / (float)sink.AmmoType.PointCost);
ReloadPoints -= reloadamount * sink.AmmoType.PointCost;
//BulkMagazineData magdata = hullComponent.gameObject.GetComponent<StartState>().saveData as BulkMagazineData;
//List<IMagazine> mags = hullComponent.Magazines.ToList();

foreach (IMagazine mag in hullComponent.Missiles)

//Debug.LogError($"{AreaEffect.Ship.gameObject.name} Resupply Ship {target.gameObject.name} {sink.AmmoType.MunitionName} {sink.QuantityAvailable}/{sink.PeakQuantity}");
if(hullComponent is BulkMagazineComponent magcomp)
magcomp.AddToMagazine(sink.AmmoType, reloadamount);
else if( hullComponent is CellLauncherComponent cellcomp)
{
if (mag.QuantityAvailable < mag.PeakQuantity)
{
dirtymissiles = true;
IMagazineProvider magazineProvider = cellcomp as IMagazineProvider;
//Debug.LogError("movin missiles");
dirtymissiles = true;

magazineProvider.AddToMagazine(mag.AmmoType, 1);
AreaEffect.Hull.MyShip.AmmoFeed.GetAmmoSource(mag.AmmoType).Withdraw(1);
}
magazineProvider.AddToMagazine(sink.AmmoType, reloadamount);
}


}
source.Withdraw(reloadamount);

}


//target.BuildMissileGroups();
if(dirtymissiles)
target?.BuildMissileMagazineTracker();
Expand Down

0 comments on commit 855fba4

Please sign in to comment.