Behavior Canceling & Grouping
Behaviors are now grouped, behaviors within a group can cancel execution of the rest of the group
This commit is contained in:
parent
c24c155673
commit
fc94531566
35 changed files with 613 additions and 190 deletions
|
|
@ -24,26 +24,32 @@ public class ProjectileWeaponData : WeaponData
|
|||
|
||||
public class ProjectileWeapon : IActivatedBehavior
|
||||
{
|
||||
private ProjectileWeaponData _data;
|
||||
private Entity Entity { get; }
|
||||
private Gear Item { get; }
|
||||
private GameContext Context { get; }
|
||||
private float _firingVisibility;
|
||||
private bool _firing;
|
||||
private float _cooldown; // normalized
|
||||
private ProjectileWeaponData _projectileWeapon;
|
||||
public Entity Entity { get; }
|
||||
public Gear Item { get; }
|
||||
public GameContext Context { get; }
|
||||
private float _firingVisibility;
|
||||
private float _burstCooldown;
|
||||
private float _burstCooldownTime;
|
||||
private int _burstRemaining;
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public ProjectileWeapon(GameContext context, ProjectileWeaponData c, Entity entity, Gear item)
|
||||
{
|
||||
Context = context;
|
||||
_projectileWeapon = c;
|
||||
_data = c;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
public bool Activate()
|
||||
{
|
||||
_firing = true;
|
||||
return true;
|
||||
// Debug.Log("Activating ProjectileWeapon");
|
||||
// _firing = true;
|
||||
// Observable.EveryUpdate().TakeWhile(_ => _firing).Subscribe(_ =>
|
||||
// {
|
||||
// // Debug.Log($"Updating Observable {_cooldown}");
|
||||
|
|
@ -58,9 +64,11 @@ public class ProjectileWeapon : IActivatedBehavior
|
|||
// });
|
||||
}
|
||||
|
||||
private void Fire(long b)
|
||||
private void Fire()
|
||||
{
|
||||
// _firingVisibility += _projectileWeapon.Visibility.Evaluate(Hardpoint);
|
||||
_burstRemaining--;
|
||||
_firingVisibility += Context.Evaluate(_data.Visibility, Item, Entity);
|
||||
Entity.AddHeat(Context.Evaluate(_data.Heat, Item, Entity));
|
||||
// Hardpoint.Temperature += _projectileWeapon.Heat.Evaluate(Hardpoint) / Hardpoint.HeatCapacity;
|
||||
// var inst = GameObject.Instantiate(_projectileWeapon.BulletPrefab).transform;
|
||||
// Physics.IgnoreCollision(Hardpoint.Ship.Ship.GetComponent<Collider>(), inst.GetComponent<Collider>());
|
||||
|
|
@ -85,17 +93,38 @@ public class ProjectileWeapon : IActivatedBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
_cooldown -= delta / Context.Evaluate(_projectileWeapon.Cooldown, Item, Entity);
|
||||
_cooldown -= delta / Context.Evaluate(_data.Cooldown, Item, Entity);
|
||||
if (_cooldown < 0)
|
||||
{
|
||||
_cooldown = 1;
|
||||
_burstRemaining = _data.BurstCount;
|
||||
_burstCooldownTime = Context.Evaluate(_data.BurstTime, Item, Entity) / _data.BurstCount;
|
||||
_burstCooldown = -1;
|
||||
Fire();
|
||||
}
|
||||
|
||||
if (_burstRemaining > 0)
|
||||
{
|
||||
_burstCooldown -= delta / _burstCooldownTime;
|
||||
if (_burstCooldown < 0)
|
||||
{
|
||||
_burstCooldown = 1;
|
||||
Fire();
|
||||
}
|
||||
}
|
||||
|
||||
_firingVisibility *= Context.Evaluate(_projectileWeapon.VisibilityDecay, Item, Entity);
|
||||
_firingVisibility *= Context.Evaluate(_data.VisibilityDecay, Item, Entity);
|
||||
|
||||
if (_firingVisibility < 0.01f)
|
||||
{
|
||||
Entity.VisibilitySources.Remove(this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
|
||||
public BehaviorData Data => _projectileWeapon;
|
||||
}
|
||||
Loading…
Reference in a new issue