public virtual IBehaviorContext Clone() { return(new DefaultBehaviorContext <T>( Behaviors.ToList(), Handler, CustomValues, NextBehaviorIndex - 1 )); }
public virtual void Update(GameTime gameTime, Level level) { _savedPositions.Enqueue(new EntitySavedPosition { Position = CenterPosition, Level = level.Id, TotalGameTime = gameTime.TotalGameTime }); if (_savedPositions.Count > 5) { _savedPositions.Dequeue(); } if (Behaviors != null) { var activeBehaviors = new List <EntityUpdateBehavior>(); foreach (var behaviorGroup in Behaviors.ToList()) { if (behaviorGroup.Key == string.Empty) { foreach (var behavior in behaviorGroup.Value.Where(b => b.IsActive(gameTime, level))) { activeBehaviors.Add(behavior); } } else { var bh = behaviorGroup.Value.Where(b => b.IsActive(gameTime, level)).FirstOrDefault(); if (bh != null) { activeBehaviors.Add(bh); } } } foreach (var bh in Behaviors.SelectMany(b => b.Value).ToList()) { if (activeBehaviors.Contains(bh)) { bh.Update(gameTime, level); } else { bh.Deactivated(gameTime, level); } } } var curAnimation = SelectAnimation(); if (curAnimation != _lastAnimation) { _lastFrameStartTime = gameTime.TotalGameTime; _lastAnimation = curAnimation; _currentFrameIndex = 0; } else if (gameTime.TotalGameTime > _lastFrameStartTime + curAnimation.FrameDuration) { _currentFrameIndex++; if (_currentFrameIndex >= curAnimation.FrameIndexes.Length) { if (AnimationEnded != null) { AnimationEnded(this, EventArgs.Empty); } _currentFrameIndex = curAnimation.ResetToFrame; } _lastFrameStartTime = gameTime.TotalGameTime; } if (Magic != null) { if (_timeSinceLastMpRegen > 1000) { if (!Magic.IsFull) { Magic.Quantity++; } _timeSinceLastMpRegen = 0; } else { _timeSinceLastMpRegen += gameTime.ElapsedGameTime.Milliseconds; } } }
private void RegisterBehaviors(Behaviors behaviors) => behaviors .ToList() .ForEach(RegisterBehavior);
private List <IAnimatedBehavior> InternalBehaviors() { return(Behaviors.ToList()); }