public override void Update(GameTime gameTime) { base.Update(gameTime); var anim = _walkingAnimation.GetAnimationForOrientation(Orientation); var sheet = anim.AnimatedSpriteSheets.FirstOrDefault(); if (!IsMoving) { sheet.Reset(); } else { sheet.Update(gameTime); } if (ActiveActions.Any()) { foreach (var act in ActiveActions) { act.Action(gameTime, act); } return; } _currentAnimationSheet = anim.AnimatedSpriteSheets.FirstOrDefault(); }
public Error Cancel(uint id) { ActiveAction activeAction; if (ActiveActions.TryGetValue(id, out activeAction) && !activeAction.IsDone) { var actionRequirements = Ioc.Kernel.Get <ActionRequirementFactory>().GetActionRequirementRecord(activeAction.WorkerType); var actionRequirement = actionRequirements.List.FirstOrDefault(x => x.Index == activeAction.WorkerIndex); if (actionRequirement == null || (actionRequirement.Option & ActionOption.Uncancelable) == ActionOption.Uncancelable) { return(Error.ActionUncancelable); } ThreadPool.QueueUserWorkItem(ActiveCancelCallback, activeAction); return(Error.Ok); } PassiveAction passiveAction; if (PassiveActions.TryGetValue(id, out passiveAction) && !passiveAction.IsDone) { if (!passiveAction.IsCancellable) { return(Error.ActionUncancelable); } ThreadPool.QueueUserWorkItem(PassiveCancelCallback, passiveAction); return(Error.Ok); } return(Error.ActionNotFound); }
private bool ActivateActions(int startIndex) { for (int i = startIndex; i < Actions.Length; i++) { activeActionIndex = i; FsmStateAction fsmStateAction = Actions[i]; if (!fsmStateAction.Enabled) { fsmStateAction.Finished = true; continue; } ActiveActions.Add(fsmStateAction); activeAction = fsmStateAction; fsmStateAction.Active = true; fsmStateAction.Finished = false; fsmStateAction.Init(this); fsmStateAction.Entered = true; fsmStateAction.OnEnter(); if (Fsm.IsSwitchingState) { return(false); } if (!fsmStateAction.Finished && isSequence) { return(false); } } return(true); }
private void RemoveFinishedActions() { for (int i = 0; i < finishedActions.Count; i++) { ActiveActions.Remove(finishedActions[i]); } finishedActions.Clear(); }
public void PerformAction(string name, bool force = false) { if (SupportedActions.TryGetValue(name, out var action)) { ActiveActions.Add(action); action.IsRunning = true; } }
protected void callInvestFinished(bool Success, string Message) { if (ActiveActions.Contains(SiteAction.Invest)) { ActiveActions.Remove(SiteAction.Invest); } OnWithdrawalFinished?.Invoke(this, new GenericEventArgs { Success = Success, Message = Message }); }
protected void callResetSeedFinished(bool Success, string Message) { if (ActiveActions.Contains(SiteAction.ResetSeed)) { ActiveActions.Remove(SiteAction.ResetSeed); } OnResetSeedFinished?.Invoke(this, new GenericEventArgs { Success = Success, Message = Message }); }
protected void callInvestFinished(bool Success, string Message) { if (ActiveActions.Contains(SiteAction.Invest)) { ActiveActions.Remove(SiteAction.Invest); } ForceUpdateStats = true; OnInvestFinished?.Invoke(this, new GenericEventArgs { Success = Success, Message = Message }); }
public void SendTip(string Username, decimal Amount) { if (CanTip) { ActiveActions.Add(SiteAction.Tip); callNotify($"Tipping {Amount} {CurrentCurrency} to {Username}"); _SendTip(Username, Amount); } else { callError("Tipping not allowed!", false, ErrorType.NotImplemented); } }
public bool Contains(GameAction action) { if (action is ActiveAction) { return(ActiveActions.ContainsKey(action.ActionId)); } if (action is PassiveAction) { return(PassiveActions.ContainsKey(action.ActionId)); } return(false); }
public void Withdraw(string Address, decimal Amount) { if (AutoWithdraw) { ActiveActions.Add(SiteAction.Withdraw); callNotify($"Withdrawing {Amount} {CurrentCurrency} to {Address}"); _Withdraw(Address, Amount); UpdateStats(); } else { callError("Withdrawing not allowed!", false, ErrorType.NotImplemented); } }
public void Invest(decimal Amount) { if (AutoInvest) { ActiveActions.Add(SiteAction.Invest); callNotify($"Investing {Amount} {CurrentCurrency}"); _Invest(Amount); UpdateStats(); } else { callError("Investing not allowed!", false, ErrorType.NotImplemented); } }
public void ResetSeed(string ClientSeed) { if (CanChangeSeed) { ActiveActions.Add(SiteAction.ResetSeed); callNotify("Resetting seed."); _ResetSeed(); if (CanSetClientSeed) { SetClientSeed(ClientSeed); } } else { callError("Reset Seed not allowed!", false, ErrorType.NotImplemented); } }
public void OnEnter() { loopCount++; if (loopCount > maxLoopCount) { maxLoopCount = loopCount; } active = true; finished = false; finishedActions.Clear(); RealStartTime = FsmTime.RealtimeSinceStartup; StateTime = 0f; ActiveActions.Clear(); if (ActivateActions(0)) { CheckAllActionsFinished(); } }
public override void Update(GameTime gameTime) { ActiveActions.RemoveAll(z => !z.IsRunning); if (_walkingToList == null || !_walkingToList.Any()) { return; } if (Vector2.Distance(Position, _targetPoint) < 5f) { _walkingToList.Remove(_targetPoint); _targetPoint = _walkingToList.FirstOrDefault(); if (_targetPoint == default(Vector2)) { _walkingToList.Clear(); IsMoving = false; return; } } var currentTargetPoint = _targetPoint; var elapsed = (float)gameTime.ElapsedGameTime.TotalMilliseconds; var distance = Vector2.Distance(Position, currentTargetPoint); var interpolatedVector = Vector2.Lerp(Position, currentTargetPoint, MoveSpeedModifier / distance * elapsed); float xDif = interpolatedVector.X - Position.X; float yDif = interpolatedVector.Y - Position.Y; if (Math.Abs(xDif) > Math.Abs(yDif)) { Orientation = xDif < 0 ? Orientation.Left : Orientation.Right; } else { Orientation = yDif < 0 ? Orientation.Top : Orientation.Bottom; } IsMoving = true; Position = interpolatedVector; }
public override void Update(GameTime gameTime) { //Update Keyboard and Mouse States PreviousKeyboardState = CurrentKeyboardState; CurrentKeyboardState = Keyboard.GetState(); PreviousMouseState = CurrentMouseState; CurrentMouseState = Mouse.GetState(); //Clear Data Structures ActiveActions.Clear(); ActiveStates.Clear(); ActiveRanges.Clear(); MappedKeyboardKeys.Clear(); MappedMouseButtons.Clear(); MappedMouseRanges.Clear(); RangeValues.Clear(); MouseScreenLocation = new Point(CurrentMouseState.X, CurrentMouseState.Y); //Sort EntityList by InputMap Priority EntityList.Sort((Entity x, Entity y) => { if (x.GetComponent <CInputMap>().Priority < y.GetComponent <CInputMap>().Priority) { return(-1); } else if (x.GetComponent <CInputMap>().Priority > y.GetComponent <CInputMap>().Priority) { return(1); } else { return(0); } }); //Map Raw Inputs to Actions, States and Ranges foreach (Entity e in EntityList) { var inputMap = e.GetComponent <CInputMap>(); //KEYBOARD KEY TO ACTION foreach (KeyValuePair <Keys, int> pair in inputMap.KeyboardKeyToAction) { if (!MappedKeyboardKeys.Contains(pair.Key)) { if (PreviousKeyboardState.IsKeyUp(pair.Key) && CurrentKeyboardState.IsKeyDown(pair.Key)) { ActiveActions.Add(pair.Value); MappedKeyboardKeys.Add(pair.Key); } } } //KEYBOARD KEY TO STATE foreach (KeyValuePair <Keys, int> pair in inputMap.KeyboardKeyToState) { if (!MappedKeyboardKeys.Contains(pair.Key)) { if (CurrentKeyboardState.IsKeyDown(pair.Key)) { ActiveStates.Add(pair.Value); MappedKeyboardKeys.Add(pair.Key); } } } //MOUSE BUTTON TO ACTION foreach (KeyValuePair <MouseButtons, int> pair in inputMap.MouseButtonToAction) { if (!MappedMouseButtons.Contains(pair.Key)) { if (pair.Key == MouseButtons.LeftButton) { if (PreviousMouseState.LeftButton == ButtonState.Released && CurrentMouseState.LeftButton == ButtonState.Pressed) { ActiveActions.Add(pair.Value); MappedMouseButtons.Add(pair.Key); } } if (pair.Key == MouseButtons.RightButton) { if (PreviousMouseState.RightButton == ButtonState.Released && CurrentMouseState.RightButton == ButtonState.Pressed) { ActiveActions.Add(pair.Value); MappedMouseButtons.Add(pair.Key); } } if (pair.Key == MouseButtons.MiddleButton) { if (PreviousMouseState.MiddleButton == ButtonState.Released && CurrentMouseState.MiddleButton == ButtonState.Pressed) { ActiveActions.Add(pair.Value); MappedMouseButtons.Add(pair.Key); } } if (pair.Key == MouseButtons.XButton1) { if (PreviousMouseState.XButton1 == ButtonState.Released && CurrentMouseState.XButton1 == ButtonState.Pressed) { ActiveActions.Add(pair.Value); MappedMouseButtons.Add(pair.Key); } } if (pair.Key == MouseButtons.XButton2) { if (PreviousMouseState.XButton2 == ButtonState.Released && CurrentMouseState.XButton2 == ButtonState.Pressed) { ActiveActions.Add(pair.Value); MappedMouseButtons.Add(pair.Key); } } } } //MOUSE BUTTON TO STATE foreach (KeyValuePair <MouseButtons, int> pair in inputMap.MouseButtonToState) { if (!MappedMouseButtons.Contains(pair.Key)) { if (pair.Key == MouseButtons.LeftButton) { if (CurrentMouseState.LeftButton == ButtonState.Pressed) { ActiveStates.Add(pair.Value); MappedMouseButtons.Add(pair.Key); } } if (pair.Key == MouseButtons.RightButton) { if (CurrentMouseState.RightButton == ButtonState.Pressed) { ActiveStates.Add(pair.Value); MappedMouseButtons.Add(pair.Key); } } if (pair.Key == MouseButtons.MiddleButton) { if (CurrentMouseState.MiddleButton == ButtonState.Pressed) { ActiveStates.Add(pair.Value); MappedMouseButtons.Add(pair.Key); } } if (pair.Key == MouseButtons.XButton1) { if (CurrentMouseState.XButton1 == ButtonState.Pressed) { ActiveStates.Add(pair.Value); MappedMouseButtons.Add(pair.Key); } } if (pair.Key == MouseButtons.XButton2) { if (CurrentMouseState.XButton2 == ButtonState.Pressed) { ActiveStates.Add(pair.Value); MappedMouseButtons.Add(pair.Key); } } } } //MOUSE RANGE TO RANGE foreach (KeyValuePair <MouseRanges, int> pair in inputMap.MouseRangeToRange) { if (!MappedMouseRanges.Contains(pair.Key)) { if (pair.Key == MouseRanges.ScrollDelta) { ActiveRanges.Add(pair.Value); RangeValues.Add(pair.Value, CurrentMouseState.ScrollWheelValue - PreviousMouseState.ScrollWheelValue); MappedMouseRanges.Add(pair.Key); } if (pair.Key == MouseRanges.MouseHorizontalDelta) { float hCenter = ViewPort.Width / 2; ActiveRanges.Add(pair.Value); RangeValues.Add(pair.Value, CurrentMouseState.X - hCenter); MappedMouseRanges.Add(pair.Key); } if (pair.Key == MouseRanges.MouseVerticalDelta) { float vCenter = ViewPort.Height / 2; ActiveRanges.Add(pair.Value); RangeValues.Add(pair.Value, CurrentMouseState.Y - vCenter); MappedMouseRanges.Add(pair.Key); } } } } //Given the Mapped Inputs, Call all Callbacks and see if they can use the Mapped Input foreach (Entity e in EntityList) { var inputHandlers = e.GetComponent <CInputHandlers>(); foreach (int callbackID in inputHandlers.InputHandlerIDs) { GameRegistry.FetchInputCallback(callbackID)(e, gameTime, ActiveActions, ActiveStates, ActiveRanges, RangeValues); } } }