public Status Add(QueuedAction action) { try { lock (m_queue) { m_queue.Enqueue(action); } // Start or restart the processing thread. if (m_thread == null || m_thread.ThreadState == ThreadState.Stopped || m_thread.ThreadState == ThreadState.Aborted) { m_thread = new Thread(ProcessActions); m_thread.Name = "ActionQueue Thread"; m_thread.Start(); } // Notify the processing thread that there's an action to process. m_gate.Set(); return Status.Success; } catch (Exception e) { s_log.ErrorFormat("Exception queueing action: {0}", e.Message); return Status.Failure; } }
public BattleFight(BattleField field, FightingEntity fighter, QueuedAction action, BattleUI ui) { this._field = field; this.fighter = fighter; this.queuedAction = action; this._ui = ui; }
private void Update() { lock (actionQueue) { while (actionQueue.Count > 0) { QueuedAction queuedAction = actionQueue.Dequeue(); switch (queuedAction.actionType) { case QueuedActionType.HandEnter: OnHandEnter(queuedAction.id, queuedAction.position); break; case QueuedActionType.HandExit: OnHandExit(queuedAction.id, queuedAction.position); break; case QueuedActionType.HandMoved: OnHandMoved(queuedAction.id, queuedAction.position, queuedAction.timestamp); break; case QueuedActionType.TapPressed: OnHandTapPressed(queuedAction.id, queuedAction.position); break; case QueuedActionType.TapReleased: OnHandTapReleased(queuedAction.id, queuedAction.position); break; } } } }
void Update() { Time += UnityEngine.Time.deltaTime * TimeFactor + UnityEngine.Time.deltaTime * TimeFactor * Input.GetAxis("Time") * 100.0f; if (ChosenJoystickTriggerAxis != null) { Time += UnityEngine.Time.deltaTime * TimeFactor * Input.GetAxis(ChosenJoystickTriggerAxis) * 100.0f; } if (Time < 0f) { Time += SecondsPerDay; } // Time contribution values blatantly stolen from FEZ const float onesixth = 1f / 6f; const float onethird = 1f / 3f; DawnContribution = EaseTime(TimeRelative, 0.08333334f, onesixth); DuskContribution = EaseTime(TimeRelative, 0.75f, onesixth); NightContribution = EaseTime(TimeRelative, 0.8333333f, onethird); NightContribution = Mathf.Max(NightContribution, EaseTime(TimeRelative, 0.8333333f - 1f, onethird)); RenderSettings.skybox.SetFloat("_SkyGradientX", TimeRelative); while (0 < MainQueue.Count) { QueuedAction qa = MainQueue[0]; MainQueue.RemoveAt(0); qa.Invoke(); } }
private void QueueActionWithCharacter( AbilityData i_dataAbility, DefaultModel i_model ) { // create the queued action and add it to our queue QueuedAction action = new QueuedAction( i_model, i_dataAbility ); m_queueActions.Enqueue( action ); // Debug.Log( i_dataCharacter.Name + " is queuing " + i_dataAbility.Name ); }
/// <summary> /// Queues an action from another thread to happen on the MainPluginThread. /// </summary> /// <param name="action">The action to take.</param> public static void QueueAction(QueuedAction action) { lock (mQueuedActions) { mQueuedActions.Enqueue(action); //mActionQueueTimer.Start(); } }
/// <summary> /// Queues the specified action to be run. /// </summary> public Task RunAsync(Action action) { var qt = new QueuedAction(action); queue.Enqueue(qt); newTaskEvent.Set(); return(qt.Task); }
public void StackAction(UnityAction act, float duration, bool blocking = true) { var QA = new QueuedAction(act, duration, blocking); var queueList = actions.ToList(); queueList.Insert(0, QA); actions = new Queue <QueuedAction>(queueList); }
private void QueueActionWithCharacter(AbilityData i_dataAbility, DefaultModel i_model) { // create the queued action and add it to our queue QueuedAction action = new QueuedAction(i_model, i_dataAbility); m_queueActions.Enqueue(action); // Debug.Log( i_dataCharacter.Name + " is queuing " + i_dataAbility.Name ); }
public void AdjustPiston(Point3 position, int length) { if (!m_actions.TryGetValue(position, out QueuedAction value)) { value = new QueuedAction(); m_actions[position] = value; } value.Move = length; }
////////////////////////////////////////// /// ProcessAction() /// Processes the incoming action, doing /// whatever it's supposed to do. ////////////////////////////////////////// private void ProcessAction(QueuedAction i_action) { // get the target the action affects CharacterModel modelTarget = GetTargetModel(i_action.GetData().Target, i_action); CharacterModel modelAggressor = ModelManager.Instance.GetModel(i_action.GetOwnerID()); //Debug.Log( "Processing " + i_action.GetData().Name + " on " + modelTarget.Name ); // check to see if any effects on the aggressor contribute to increased power int nPowerBonus = modelAggressor.GetTotalModification("AllDamage"); int nDamage = i_action.GetData().Power + nPowerBonus; // check for valid bonus damage nDamage = CheckForBonuses(i_action.GetData(), nDamage, modelTarget, modelAggressor); // now do defenses -- for now, just handle one if (i_action.GetData().DamageTypes.Count > 0) { DamageTypes eDamageType = i_action.GetData().DamageTypes[0]; int nDefense = modelTarget.GetTotalModification(eDamageType.ToString() + "Defense"); if (nDamage > 0) { // something is reducing the defense nDamage = Mathf.Max(nDamage - nDefense, 0); } else { // something is augmenting the heal nDamage = nDamage + nDefense; } } // for now, we're just altering the hp of the target modelTarget.AlterHP(nDamage); // handle applied effects, if any foreach (AppliedEffectData effect in i_action.GetData().AppliedEffects) { // get the model the effect should apply to CharacterModel modelEffectTarget = GetTargetModel(effect.Target, i_action); // apply the effect! modelEffectTarget.ApplyEffect(effect); } // handle remove effects, if any foreach (RemovedEffectData removal in i_action.GetData().RemovedEffects) { // get the model the removal should apply to CharacterModel modelEffectRemoval = GetTargetModel(removal.Target, i_action); // remove the effect! modelEffectRemoval.RemoveEffect(removal); } }
/// <summary> /// Adds an Action to the queue. Queue is FIFO. /// </summary> public void AddQueuedAction(Action action, double updateInterval) { if (updateInterval <= 0) { updateInterval = 0.001; // avoids divide by zero } QueuedAction scheduledAction = new QueuedAction(action, updateInterval); _queuedActions.Enqueue(scheduledAction); }
public void ProcessQueuedActions() { m_tmpActions.Clear(); m_tmpActions.AddRange(m_actions); foreach (KeyValuePair <Point3, QueuedAction> tmpAction in m_tmpActions) { Point3 key = tmpAction.Key; QueuedAction value = tmpAction.Value; if (Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z)) != 237) { StopPiston(key); value.Move = null; value.Stop = false; } else if (value.Stop) { StopPiston(key); value.Stop = false; value.StoppedFrame = Time.FrameIndex; } } foreach (KeyValuePair <Point3, QueuedAction> tmpAction2 in m_tmpActions) { Point3 key2 = tmpAction2.Key; QueuedAction value2 = tmpAction2.Value; if (value2.Move.HasValue && !value2.Stop && Time.FrameIndex != value2.StoppedFrame && m_subsystemMovingBlocks.FindMovingBlocks("Piston", key2) == null) { bool flag = true; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(key2.X + i * 16, key2.Z + j * 16); if (chunkAtCell == null || chunkAtCell.State <= TerrainChunkState.InvalidContents4) { flag = false; } } } if (flag && MovePiston(key2, value2.Move.Value)) { value2.Move = null; } } } foreach (KeyValuePair <Point3, QueuedAction> tmpAction3 in m_tmpActions) { Point3 key3 = tmpAction3.Key; QueuedAction value3 = tmpAction3.Value; if (!value3.Move.HasValue && !value3.Stop) { m_actions.Remove(key3); } } }
private void PostInternal(QueuedAction queuedAction) { lock (_mutex) { if (_shouldQuit) { return; } _queuedActions.Enqueue(queuedAction); } }
public void Initialize(int index, Fighter persistentFighter) { this.targetId = persistentFighter.index; this.Name = persistentFighter.Name; this.persistentFighter = persistentFighter; this.stats = persistentFighter.stats; this._queuedAction = new QueuedAction(this); _ai = new FightingEntityAI(this); this.targetName = GameManager.Instance.battleComponents.field.GetTargetNameFromIndex(index); }
public bool EnqueueAction(QueuedAction action) { if (CanPerformeAction(action)) { currentActionPoints -= action.GetCost(); actionQueue.AddAction(action); return(true); } return(false); }
public static string CreateChatCommand(string text, QueuedAction action) { if (mChatActions.Count >= MaxChatActions) { mChatActions.RemoveAt(0); } int id = mNextChatActionId++; mChatActions[id] = action; return("<Tell:IIDString:" + id + ":" + ChatActionCommand + ">" + text + @"<\Tell>"); }
public IEnumerator DoFight() { // if (this.fighter.isEnemy()) { // this.getEnemyAction(); // } Messenger.Broadcast <FightResult>(Messages.OnFightStart, new FightResult(this.fighter, queuedAction.GetAction())); QueuedAction attackerAction = queuedAction; string attackerName = this.fighter.Name; if (attackerAction == null) { Debug.LogError("Cannot find queued action: " + attackerName); yield break; } ActionBase action = attackerAction.GetAction(); string attackName = action.name; List <FightingEntity> targets = action.GetTargets(this.fighter, attackerAction.GetTargetIds()); if (targets.Count == 1) { Debug.Log(this.fighter.Name + " Execute Action: " + attackName + targets[0].targetId); } List <FightingEntity> focusedFighters = new List <FightingEntity>(); focusedFighters.Add(fighter); List <FightingEntity> focusedTargets = action.GetFocusedTargets(this.fighter, attackerAction.GetTargetIds()); foreach (FightingEntity target in focusedTargets) { focusedFighters.Add(target); } List <FightingEntity> unfocusedFighters = this._field.GetAllFightingEntities().Filter(fighter => !focusedFighters.Contains(fighter)); foreach (FightingEntity focusedFighter in focusedFighters) { this._ui.focusOverlay.AddToFocusLayer(focusedFighter.gameObject, true); } foreach (FightingEntity unfocusedFighter in unfocusedFighters) { this._ui.focusOverlay.AddToFocusLayer(unfocusedFighter.gameObject, false); } yield return(GameManager.Instance.time.GetController().StartCoroutine(action.ExecuteAction(fighter, targets, this))); }
public override void SetAction() { if (ActionFeed.Count == 0) { if (Dead) { CurrentAction = MirAction.Dead; } else { CurrentAction = MirAction.Standing; } } else { QueuedAction action = ActionFeed[0]; ActionFeed.RemoveAt(0); CurrentAction = action.Action; Direction = action.Direction; Model.transform.rotation = ClientFunctions.GetRotation(Direction); switch (CurrentAction) { case MirAction.Walking: case MirAction.Running: int steps = 1; if (CurrentAction == MirAction.Running) { steps = 2; } Vector3 targetpos = GameManager.CurrentScene.Cells[(int)action.Location.x, (int)action.Location.y].position; TargetPosition = targetpos; Vector2 back = ClientFunctions.Back(action.Location, Direction, steps); gameObject.transform.position = GameManager.CurrentScene.Cells[(int)back.x, (int)back.y].position; GameManager.CurrentScene.Cells[CurrentLocation.x, CurrentLocation.y].RemoveObject(this); GameManager.CurrentScene.Cells[action.Location.x, action.Location.y].AddObject(this); StartPosition = gameObject.transform.position; TargetDistance = Vector3.Distance(transform.position, targetpos); IsMoving = true; break; } CurrentLocation = action.Location; } GetComponentInChildren <Animator>().SetInteger("CurrentAction", (int)CurrentAction); }
////////////////////////////////////////// /// ExecuteActions() /// Empties the action queue and executes /// each action. ////////////////////////////////////////// private void ExecuteActions() { //Debug.Log( "Executing actions!" ); //StartCoroutine( ExecuteActions_() ); while (m_queueActions.Count > 0) { QueuedAction action = m_queueActions.Dequeue(); // process the action -- first get the character who it will affect ProcessAction(action); } }
protected override IEnumerator Run() { this._ui.battleOrderUI.SetTurnOrder(fighters); yield return(GameManager.Instance.time.GetController().StartCoroutine(this._ui.battleStartUI.PlayAnimation())); this._ui.targetIconsUI.ClearTargetArrows(); for (int i = 0; i < fighters.Count; i++) { if (fighters[i] == null) { // This can happen if the fighter dies mid-battle this._ui.battleOrderUI.PopFighter(); yield return(GameManager.Instance.time.GetController().WaitForSeconds(1.0f)); continue; } // Apply Status Ailment fighters[i].ailmentController.TickAilmentEffects(this._phase); if (queuedActions[i] == null) { Debug.LogError("ERROR: Queued action was null!"); } QueuedAction attackerAction = queuedActions[i]; // This can happen if target dies mid-battle if (attackerAction._action.TargetsDead(fighters[i], attackerAction.GetTargetIds())) { Debug.Log("Skip attacker's turn: " + fighters[i].Name); this._ui.battleOrderUI.PopFighter(); yield return(GameManager.Instance.time.GetController().WaitForSeconds(1.0f)); continue; } BattleFight fight = new BattleFight(_field, fighters[i], attackerAction, this._ui); this.currentFight = fight; yield return(GameManager.Instance.time.GetController().StartCoroutine(this._ui.focusOverlay.EnableOverlay())); yield return(GameManager.Instance.time.GetController().StartCoroutine(fight.DoFight())); yield return(GameManager.Instance.time.GetController().StartCoroutine(this._ui.focusOverlay.DisableOverlay())); this._ui.battleOrderUI.PopFighter(); } }
public QueuedAction Queue(System.Action action, List <QueuedAction> queue = null, bool skipQueue = false) { Debug.Log("QUEUE: " + action.Method.Name + ", " + (queue == null ? "null" : queue.Count.ToString()) + ", " + skipQueue); if (skipQueue) { action(); return(null); } QueuedAction qa = new QueuedAction(action, queue); MainQueue.Add(qa); return(qa); }
public QueuedAction GetQueuedAction(ActionTarget actionTarget) { var output = new QueuedAction { Action = action, ActionController = controller, ActionTarget = actionTarget, Display = preview.GetPreviewDisplay() }; preview.DetachPreview(); return(output); }
public void Play(bool blocking = false) { playing = true; if (blocker == null && blocking) { blocker = (GameObject)GameObject.Instantiate(Resources.Load("Blocker")); blocker.GetComponentInChildren <Blocker>().queue = this; } if (blocking) { blocker.SetActive(true); } currentAction = actions.Dequeue(); currentAction.Play(); }
/// <summary>Queues an action from another thread to happen on the MainPluginThread.</summary> /// <param name="action">The action to take.</param> public static void QueueAction(QueuedAction action) { lock (mQueuedActions) { mQueuedActions.Enqueue(action); if (mActionQueueTimer == null) { mActionQueueTimer = new WindowsTimer(); mActionQueueTimer.Tick += new EventHandler(ActionQueueTimer_Tick); mActionQueueTimer.Interval = 100; } mActionQueueTimer.Start(); } }
IEnumerator ProcessQueue() { while (true) { if (queue.Count > 0) { QueuedAction action = queue.Dequeue(); yield return(StartCoroutine(action.PerformAction(this))); yield return(StartCoroutine(QueueElementBuffer())); } yield return(null); } }
protected override void OnPhaseStart() { this._playerActionCounter = 0; this._heroMenuActions.Clear(); // Reset Player Commands PlayerObject heroPlayer = this._field.GetHeroPlayer(); int mookCount = 0; int autoQueuedMookCount = 0; foreach (FightingEntity player in this._field.GetAllFightingEntities()) { if (player.HasModifier(ModifierAilment.MODIFIER_CANNOT_USE_ACTION)) { ActionBase action = GameManager.Instance.models.GetCommonAction("Nothing"); player.SetQueuedAction(action, new List <int>(player.targetId)); continue; } if (player == heroPlayer || player.isEnemy()) { player.ResetCommand(); } else { mookCount++; // Experimental: Mooks keep their actions QueuedAction lastAction = player.GetQueuedAction(); if (lastAction != null && lastAction._action != null && lastAction.CanQueueAction(lastAction._action)) { player.SetQueuedAction(lastAction._action, lastAction._targetIds, true); autoQueuedMookCount++; } else { player.ResetCommand(); } } } if (autoQueuedMookCount == mookCount) { this._playerActionCounter = maxTimeBeforeAction / 2f; // Advance faster if mooks are autoqueued! } Messenger.Broadcast(Messages.OnUpdateStatusBarsUI); }
private Task SendInternalAsync(QueuedAction queuedAction) { var completionSource = new TaskCompletionSource <object>(); lock (_mutex) { if (_shouldQuit) { completionSource.SetException(new GameLoopExitException()); } queuedAction.SetCompletionSource(completionSource); _queuedActions.Enqueue(queuedAction); } return(completionSource.Task); }
private void OtherThreadFingerReleased(InteractionSourceState state) { Vector3 handPosition; if (state.source.kind == InteractionSourceKind.Hand && state.properties.location.TryGetPosition(out handPosition)) { QueuedAction newAction = new QueuedAction { actionType = QueuedActionType.TapReleased, id = state.source.id, position = handPosition, timestamp = Time.time }; lock (actionQueue) { actionQueue.Enqueue(newAction); } } }
private void ProcessHandInput(AbilityIndex index, InputActionPhase phase) { if (downAction.isNew && index < downAction.index) { return; } if (phase == InputActionPhase.Started) { downAction = new QueuedAction(index); } else if (phase == InputActionPhase.Canceled) { fighter.UseAbility(index, false, out _); } }
private void SetSlotUIForAction(QueuedAction action) { if (!GameManager.Instance.battleComponents.turnManager.GetPhase().CanInputActions()) { return; } FightingEntity user = action.user; List <FightingEntity> targets = action.GetTargets(); foreach (FightingEntity target in targets) { target.fighterSlot.AddTargetArrowUI(user.GetOrderColor()); } }
private void OtherThread_InteractionSourceReleased(InteractionSourceReleasedEventArgs args) { Vector3 handPosition; if (args.state.source.kind == InteractionSourceKind.Hand && args.state.sourcePose.TryGetPosition(out handPosition)) { QueuedAction newAction = new QueuedAction { actionType = QueuedActionType.TapReleased, id = args.state.source.id, position = handPosition, timestamp = Time.time }; lock (actionQueue) { actionQueue.Enqueue(newAction); } } }
////////////////////////////////////////// /// GetTargetModel() /// Returns the character model that the /// incoming action targets. ////////////////////////////////////////// private CharacterModel GetTargetModel( CombatTargets i_eTarget, QueuedAction i_action ) { // let's just brute force this for now string strTargetID; if ( i_eTarget == CombatTargets.Self ) { // if the action target is self, use whoever owns the ID strTargetID = i_action.GetOwnerID(); } else { // if the target is oppened, use the proper target...TODO fix this! strTargetID = i_action.GetOwnerID() == "Finthis" ? "Goblin" : "Finthis"; } return ModelManager.Instance.GetModel( strTargetID ); }
////////////////////////////////////////// /// ProcessAction() /// Processes the incoming action, doing /// whatever it's supposed to do. ////////////////////////////////////////// private void ProcessAction( QueuedAction i_action ) { // get the target the action affects CharacterModel modelTarget = GetTargetModel( i_action.GetData().Target, i_action ); CharacterModel modelAggressor = ModelManager.Instance.GetModel( i_action.GetOwnerID() ); //Debug.Log( "Processing " + i_action.GetData().Name + " on " + modelTarget.Name ); // check to see if any effects on the aggressor contribute to increased power int nPowerBonus = modelAggressor.GetTotalModification( "AllDamage" ); int nDamage = i_action.GetData().Power + nPowerBonus; // check for valid bonus damage nDamage = CheckForBonuses( i_action.GetData(), nDamage, modelTarget, modelAggressor ); // now do defenses -- for now, just handle one if ( i_action.GetData().DamageTypes.Count > 0 ) { DamageTypes eDamageType = i_action.GetData().DamageTypes[0]; int nDefense = modelTarget.GetTotalModification( eDamageType.ToString() + "Defense" ); if ( nDamage > 0 ) { // something is reducing the defense nDamage = Mathf.Max( nDamage - nDefense, 0 ); } else { // something is augmenting the heal nDamage = nDamage + nDefense; } } // for now, we're just altering the hp of the target modelTarget.AlterHP( nDamage ); // handle applied effects, if any foreach ( AppliedEffectData effect in i_action.GetData().AppliedEffects ) { // get the model the effect should apply to CharacterModel modelEffectTarget = GetTargetModel( effect.Target, i_action ); // apply the effect! modelEffectTarget.ApplyEffect( effect ); } // handle remove effects, if any foreach ( RemovedEffectData removal in i_action.GetData().RemovedEffects ) { // get the model the removal should apply to CharacterModel modelEffectRemoval = GetTargetModel( removal.Target, i_action ); // remove the effect! modelEffectRemoval.RemoveEffect( removal ); } }
public GroupBadgeHandler() { this.currentUsers = new Dictionary<GroupData, uint>(); this.exitRequests = new QueuedAction<GroupMember>(UserLeaving); this.listRequests = new QueuedAction<GroupMember>(ReceiveBadgeList); }
private void DatabaseReminderDelay_Tick(object sender, EventArgs e) { try { mDatabaseReminderDelay.Stop(); TimeSpan timeSinceUpdate = DateTime.Now - mLocDb.LastUpdate; if (!(chkUpdateRemind.Checked && timeSinceUpdate.TotalDays > 30)) return; QueuedAction openUpdateTabAction = new QueuedAction(delegate() { nbkMain.ActiveTab = MainTab.Atlas; nbkAtlas.ActiveTab = AtlasTab.Update; DefaultView.Activate(); }); QueuedAction updateAction = new QueuedAction(delegate() { openUpdateTabAction(); btnLocationsUpdate_Click(null, null); }); QueuedAction disableReminderAction = new QueuedAction(delegate() { if (chkUpdateRemind.Checked) { chkUpdateRemind.Checked = false; Util.Message("Database update reminders have been disabled. " + "You can re-enable the reminders on the " + Util.CreateChatCommand("Atlas > Update Tab", openUpdateTabAction)); } else { Util.Warning("Database update reminders are already disabled."); } }); string updateCommand = Util.CreateChatCommand("Update Now", updateAction); string disableReminderCommand = Util.CreateChatCommand("Don't remind me again", disableReminderAction); if (mLocDb.LastUpdate == DateTime.MinValue) { Util.Message(Util.PluginName + "'s location database may be out of date." + "Would you like to update? " + updateCommand + " | " + disableReminderCommand); } else { Util.Message(Util.PluginName + "'s location database was last updated " + ((int)timeSinceUpdate.TotalDays) + " days ago, it may be out of date. " + "Would you like to update? " + updateCommand + " | " + disableReminderCommand); } } catch (Exception ex) { Util.HandleException(ex); } }
private void PostInternal(QueuedAction queuedAction) { lock (_mutex) { if (_shouldQuit) return; _queuedActions.Enqueue(queuedAction); } }
private void SendInternal(QueuedAction queuedAction) { ManualResetEventSlim completedEvent = null; try { lock (_mutex) { if (_shouldQuit) throw new GameLoopExitException(); if (Thread.CurrentThread != _loopThread) { /* If we come from a different thread, create an event so that we can be notified. */ completedEvent = new ManualResetEventSlim(); queuedAction.SetCompletedEvent(completedEvent); } _queuedActions.Enqueue(queuedAction); } if (completedEvent != null) { /* We come from a different thread. Wait for the event to be processed. */ completedEvent.Wait(); } else { /* We are in the main thread. Process queued actions until our action is finished. */ while (ProcessSingleQueuedAction() && !queuedAction.IsCompleted) { } } /* Exceptions should bubble up to the caller. */ queuedAction.ThrowIfNotSuccessful(); } finally { if (completedEvent != null) completedEvent.Dispose(); } }
private Task SendInternalAsync(QueuedAction queuedAction) { var completionSource = new TaskCompletionSource<object>(); lock (_mutex) { if (_shouldQuit) completionSource.SetException(new GameLoopExitException()); queuedAction.SetCompletionSource(completionSource); _queuedActions.Enqueue(queuedAction); } return completionSource.Task; }