public bool Check(float deltaTime) { if (IsHappened) { if (ChainedEvent != null) { return(ChainedEvent.Check(deltaTime)); } return(false); } if (_coundownTimer < _realSecondsBetweenChecks) { if (Math.Abs(_updateRate) < 0.000001) { _coundownTimer += deltaTime; } else { _coundownTimer += _updateRate; } } else { if (_coundownTimer >= _realSecondsBetweenChecks) { _coundownTimer = 0; } //(_name); // Check for event chance var willHappen = _chanceOfHappening.WillHappen(); if (willHappen) { IsHappened = true; if (_eventHappenedAction != null) { _eventHappenedAction.Invoke(this); } if (AutoReset) { Reset(); } } } return(!IsHappened); }
public void Reset() { if (!IsHappened) { return; } IsHappened = false; _coundownTimer = _realSecondsBetweenChecks; if (ChainedEvent != null) { ChainedEvent.Reset(); } if (RootEvent != null) { RootEvent.Reset(); } }
public void Reset() { if (!IsHappened) { return; } IsHappened = false; //(_name + " reset"); if (ChainedEvent != null) { ChainedEvent.Reset(); } if (RootEvent != null) { RootEvent.Reset(); } }
public void Reset() { if (!IsHappened && !IsEnded) { return; } IsHappened = false; IsEnded = false; _previousWorldTime = default(DateTime); _gameSecondsSinceEventStarted = 0f; _coundownTimer = _realSecondsBetweenChecks; if (ChainedEvent != null) { ChainedEvent.Reset(); } if (RootEvent != null) { RootEvent.Reset(); } }
public void ChainsTransformsToFindAWayToApply() { var existing = new ExampleProjection(); var @event = new ExampleEvent { Id = Guid.NewGuid(), AppendValue = "AppendingValue" }; var secondEvent = new ChainedEvent() { Id = @event.Id, OldValue = "MoreValuesToAdd" }; var buildUp = BuildUp.Initialize(_ => { _.RegisterApply(_apply); _.RegisterEventTransform(_transform); _.RegisterEventTransform(_chainedTransform); }); var projectedValue = buildUp.Project(existing, @event, secondEvent); Assert.Equal(projectedValue.Id, @event.Id); Assert.Equal(projectedValue.SomeValue, $"{@event.AppendValue}{secondEvent.OldValue}"); }
public void TestSetup() { eventUnderTest = new ChainedEvent <TestEventArgs>(); }
public void TestSetup() { eventUnderTest = new ChainedEvent<TestEventArgs>(); }
public bool Check(float deltaTime) { if (_gc == null) { return(false); } if (!_gc.WorldTime.HasValue) { return(false); } if (IsHappened && IsEnded) { if (ChainedEvent != null) { return(ChainedEvent.Check(deltaTime)); } } if (_coundownTimer < _realSecondsBetweenChecks) { if (Math.Abs(_updateRate) < 0.00001) { _coundownTimer += deltaTime; } else { _coundownTimer += _updateRate; } } else { if (_coundownTimer >= _realSecondsBetweenChecks) { _coundownTimer = 0; } if (!IsHappened) { // Check for event chance var willHappen = _chanceOfHappening.WillHappen(); if (willHappen) { IsHappened = true; if (DurationPercentRandomizer != null) { var durationPart = Helpers.RollDice(DurationPercentRandomizer.First, DurationPercentRandomizer.Second) / 100f; RealDuration = TimeSpan.FromSeconds(Duration.TotalSeconds * durationPart); //(_name + " happened and will last for game's " + RealDuration.Hours + "h:" + RealDuration.Minutes + "m:" + RealDuration.Seconds + "s (until " + (_gc.WorldTime.Value + RealDuration).ToString("HH:mm") + ")"); } _gameSecondsSinceEventStarted = 0; if (_eventStartHappenningAction != null) { _eventStartHappenningAction.Invoke(this); } } } if (IsHappened && !IsEnded) { if (_gameSecondsSinceEventStarted >= RealDuration.TotalSeconds) { IsEnded = true; if (_eventEndHappenningAction != null) { _eventEndHappenningAction.Invoke(this); } //(_name + " ended"); if (AutoReset) { Reset(); } else { // Smooth transitions between chain nodes if (ChainedEvent != null) { return(ChainedEvent.Check(deltaTime)); } } } else { if (_previousWorldTime == default(DateTime)) { _previousWorldTime = _gc.WorldTime.Value; } _gameSecondsSinceEventStarted += (float)(_gc.WorldTime.Value - _previousWorldTime).TotalSeconds; _previousWorldTime = _gc.WorldTime.Value; } } } return(IsHappened && !IsEnded); }