private void OnStandAttempt(EntityUid uid, MobStateComponent component, StandAttemptEvent args) { if (component.IsIncapacitated()) { args.Cancel(); } }
private void OnStartPullAttempt(EntityUid uid, MobStateComponent component, StartPullAttemptEvent args) { if (IsIncapacitated(uid, component)) { args.Cancel(); } }
/// <summary> /// when sleeping component is added or removed, we do some stuff with other components. /// </summary> private void OnSleepStateChanged(EntityUid uid, MobStateComponent component, SleepStateChangedEvent args) { _prototypeManager.TryIndex <InstantActionPrototype>("Wake", out var wakeAction); if (args.FellAsleep) { EnsureComp <StunnedComponent>(uid); EnsureComp <KnockedDownComponent>(uid); var emitSound = EnsureComp <SpamEmitSoundComponent>(uid); emitSound.Sound = new SoundCollectionSpecifier("Snores"); emitSound.PlayChance = 0.33f; emitSound.RollInterval = 5f; emitSound.PopUp = "sleep-onomatopoeia"; emitSound.PitchVariation = 0.2f; if (wakeAction != null) { var wakeInstance = new InstantAction(wakeAction); wakeInstance.Cooldown = (_gameTiming.CurTime, _gameTiming.CurTime + TimeSpan.FromSeconds(15)); _actionsSystem.AddAction(uid, wakeInstance, null); } return; } if (wakeAction != null) { _actionsSystem.RemoveAction(uid, wakeAction); } RemComp <StunnedComponent>(uid); RemComp <KnockedDownComponent>(uid); RemComp <SpamEmitSoundComponent>(uid); }
private void OnUnequipAttempt(EntityUid uid, MobStateComponent component, IsUnequippingAttemptEvent args) { // is this a self-equip, or are they being stripped? if (args.Unequipee == uid) { CheckAct(uid, component, args); } }
public virtual void RemoveState(MobStateComponent component) { var old = component.CurrentState; component.CurrentState = null; component.CurrentThreshold = null; SetMobState(component, old, null); }
public MobStateChangedEvent( MobStateComponent component, DamageState?oldMobState, DamageState currentMobState) { Component = component; OldMobState = oldMobState; CurrentMobState = currentMobState; }
/// <summary> /// Updates the mob state.. /// </summary> public void UpdateState(MobStateComponent component, FixedPoint2 damage) { if (!TryGetState(component, damage, out var newState, out var threshold)) { return; } SetMobState(component, component.CurrentState, (newState.Value, threshold)); }
private void SetLevel(MobStateComponent stateComponent, FixedPoint2 threshold) { var uid = stateComponent.Owner; if (_playerManager.LocalPlayer?.ControlledEntity != uid) { return; } ClearOverlay(); if (!TryComp <DamageableComponent>(uid, out var damageable)) { return; } switch (stateComponent.CurrentState) { case DamageState.Dead: _overlay.State = DamageState.Dead; return; } var bruteLevel = 0f; var oxyLevel = 0f; var critLevel = 0f; if (TryGetEarliestIncapacitatedState(stateComponent, threshold, out _, out var earliestThreshold) && damageable.TotalDamage != 0) { if (damageable.DamagePerGroup.TryGetValue("Brute", out var bruteDamage)) { bruteLevel = MathF.Min(1f, (bruteDamage / earliestThreshold).Float()); } if (damageable.Damage.DamageDict.TryGetValue("Asphyxiation", out var oxyDamage)) { oxyLevel = MathF.Min(1f, (oxyDamage / earliestThreshold).Float()); } if (threshold >= earliestThreshold && TryGetEarliestDeadState(stateComponent, threshold, out _, out var earliestDeadHold)) { critLevel = (float)Math.Clamp((damageable.TotalDamage - earliestThreshold).Double() / (earliestDeadHold - earliestThreshold).Double(), 0.1, 1); } } // Don't show damage overlay if they're near enough to max. if (bruteLevel < 0.05f) { bruteLevel = 0f; } _overlay.State = critLevel > 0f ? DamageState.Critical : DamageState.Alive; _overlay.BruteLevel = bruteLevel; _overlay.OxygenLevel = oxyLevel; _overlay.CritLevel = critLevel; }
private void CheckAct(EntityUid uid, MobStateComponent component, CancellableEntityEventArgs args) { switch (component.CurrentState) { case DamageState.Dead: case DamageState.Critical: args.Cancel(); break; } }
private void OnChangeDirectionAttempt(EntityUid uid, MobStateComponent component, ChangeDirectionAttemptEvent args) { switch (component.CurrentState) { case SharedDeadMobState: case SharedCriticalMobState: args.Cancel(); break; } }
private void CheckAct(EntityUid uid, MobStateComponent component, CancellableEntityEventArgs args) { switch (component.CurrentState) { case SharedDeadMobState: case SharedCriticalMobState: args.Cancel(); break; } }
private void OnMoveAttempt(EntityUid uid, MobStateComponent component, MovementAttemptEvent args) { switch (component.CurrentState) { case SharedCriticalMobState: case SharedDeadMobState: args.Cancel(); return; default: return; } }
private void OnMobStartup(EntityUid uid, MobStateComponent component, ComponentStartup args) { if (component.CurrentState != null && component.CurrentThreshold != null) { // Initialize with given states SetMobState(component, null, (component.CurrentState.Value, component.CurrentThreshold.Value)); } else { // Initialize with some amount of damage, defaulting to 0. UpdateState(component, CompOrNull <DamageableComponent>(uid)?.TotalDamage ?? FixedPoint2.Zero); } }
private void OnMoveAttempt(EntityUid uid, MobStateComponent component, UpdateCanMoveEvent args) { switch (component.CurrentState) { case DamageState.Critical: case DamageState.Dead: args.Cancel(); return; default: return; } }
private void OnMobHandleState(EntityUid uid, MobStateComponent component, ref ComponentHandleState args) { if (args.Current is not MobStateComponentState state) { return; } if (component.CurrentThreshold == state.CurrentThreshold) { return; } if (state.CurrentThreshold == null) { RemoveState(component); } else { UpdateState(component, state.CurrentThreshold.Value); } }
protected virtual void ExitState(MobStateComponent component, DamageState?state) { switch (state) { case DamageState.Alive: ExitNormState(component.Owner); break; case DamageState.Critical: ExitCritState(component.Owner); break; case DamageState.Dead: ExitDeadState(component.Owner); break; case null: break; default: throw new NotImplementedException(); } }
protected virtual void UpdateState(MobStateComponent component, DamageState?state, FixedPoint2 threshold) { switch (state) { case DamageState.Alive: UpdateNormState(component.Owner, threshold); break; case DamageState.Critical: UpdateCritState(component.Owner, threshold); break; case DamageState.Dead: UpdateDeadState(component.Owner, threshold); break; case null: break; default: throw new NotImplementedException(); } }
protected override void UpdateState(MobStateComponent component, DamageState?state, FixedPoint2 threshold) { base.UpdateState(component, state, threshold); SetLevel(component, threshold); }
private void OnDropAttempt(EntityUid uid, MobStateComponent component, DropAttemptEvent args) { CheckAct(uid, component, args); }
private void OnInteractAttempt(EntityUid uid, MobStateComponent component, InteractionAttemptEvent args) { CheckAct(uid, component, args); }
private void OnChangeDirectionAttempt(EntityUid uid, MobStateComponent component, ChangeDirectionAttemptEvent args) { CheckAct(uid, component, args); }
/// <summary> /// Sets the mob state and marks the component as dirty. /// </summary> private void SetMobState(MobStateComponent component, DamageState?old, (DamageState state, FixedPoint2 threshold)?current)
private void OnSleepAction(EntityUid uid, MobStateComponent component, SleepActionEvent args) { TrySleeping(uid); }
public void UpdateState(EntityUid _, MobStateComponent component, DamageChangedEvent args) { component.UpdateState(args.Damageable.TotalDamage); }
private void OnMobGetState(EntityUid uid, MobStateComponent component, ref ComponentGetState args) { args.State = new MobStateComponentState(component.CurrentThreshold); }
private void OnMobShutdown(EntityUid uid, MobStateComponent component, ComponentShutdown args) { Alerts.ClearAlert(uid, AlertType.HumanHealth); }
private void OnWakeAction(EntityUid uid, MobStateComponent component, WakeActionEvent args) { TryWaking(uid); }