public void Update(double dt) { if (SlowTime < 0.5) { SlowTime += dt / 2; } else { SlowTime = 1; } dt = SlowTime * dt; TimerContainer.Update(dt); Time += dt; Copies[Player1].Refresh(); Copies[Player2].Refresh(); UpdateForPlayer(dt, Player1); UpdateForPlayer(dt, Player2); foreach (var l in Copies) { foreach (var p in l.Value) { UpdateCopy(dt, p); } } Level.Update(dt); EffectsTop.Update(dt); EffectsTop.Refresh(); EffectsMid.Update(dt); EffectsMid.Refresh(); EffectsBot.Update(dt); EffectsBot.Refresh(); EffectsScreen.Update(dt); EffectsScreen.Refresh(); }
internal static void Tick() { var now = DateTime.Now; while (_timer != null && _timer.to <= now) { TimerContainer cur = _timer; try { cur.func.Call(cur.func.Context.ThisBind, new JSC.Arguments()); } catch (Exception ex) { Log.Warning("JsTimer.Tick - {0}", ex.Message); } _timer = cur.next; if (cur.interval > 0) { cur.to = now.AddMilliseconds(cur.interval); AddTimer(cur); } else if (cur.interval == int.MinValue) { cur.to = cur.to.AddDays(1); AddTimer(cur); } } }
private void InsertToTimerList(TimerContainer container) { TimerContainerComparer TCC = new TimerContainerComparer(); timers.Add(container); timers.Sort(TCC); }
public static void ClearTimeout(JSC.JSValue oi) { if (oi == null || !oi.IsNumber) { return; } var idx = (int)oi; TimerContainer t = _timer, tp = null; while (t != null) { if ((long)t.idx == (long)idx) { if (tp == null) { _timer = t.next; } else { tp.next = t.next; } } else { tp = t; } t = t.next; } }
void Update() { RaycastHit lookingAt; if (Physics.Raycast(cam.transform.position, transform.forward, out lookingAt, 3)) { Interactable interactable = lookingAt.collider.GetComponent <Interactable>(); if (interactable != null && !isPaused.activeInHierarchy) { if (TimerContainer.countdown(3, 5f, true, true)) { print("Interactable object detected"); } interactIndicator.SetActive(true); interactText.text = "Touch " + interactable.gameObject.name + "?"; } } else { print("No interactable object detected."); interactIndicator.SetActive(false); } if (Input.GetMouseButtonDown(0)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, activateDist)) { Interactable interactable = hit.collider.GetComponent <Interactable>(); if (interactable != null) { print("We found an interactable object"); if (Vector3.Distance(this.transform.position, hit.collider.transform.position) <= activateDist) { print("Object is within range."); setFocus(interactable); affect(); } } else { print("Not an interactable object. Is this an error?"); } } } focused = focus != null; if (focused) { if (TimerContainer.countdown(0, 0.2f, focused, focused)) { affect(); removeFocus(); } } }
public override void Finish(Player player) { bool first = Program.WhichPlayer(player) == 0; TimerContainer.Clear(); new TournamentShowdown(World.Level.Name.Trim() + "_S", first); Close(); }
private static void UpdateTimers(Delegate action, TimerContainer newTimer) { if (_timers.IsNotNullAndTryGetValue(action, out var oldTimer)) { oldTimer.Kill(); } _timers?.Update(action, newTimer); }
public override void KeyDown(Key key) { World.KeyDown(key); if (key == Key.Escape) { Close(); TimerContainer.Clear(); } }
// Start is called before the first frame update protected void Start() { TimerContainer.CreateTimer(out _timer, true, OnFinishTime, timeType); if (atStart) { InitDestroy(); } }
protected override void Finish() { Player p = (World.Player1.Lives < 1 ? World.Player2 : World.Player1); bool first = Program.WhichPlayer(p) == 0; Program.Tournament.Current.Done(first ? Tournament.Result.P1 : Tournament.Result.P2); Close(); TimerContainer.Clear(); }
protected virtual void Finish() { TimerContainer.Clear(); Player p = (World.Player1.Lives < 1 ? World.Player2 : World.Player1); Texture tex = new Texture(RenderState.Width, RenderState.Height); RenderState.BeginTexture(tex); Render(); RenderState.EndTexture(); Program.Manager.NextState = new GameOver(p); }
void searching() { if (TimerContainer.wait(8, 3f, 8f)) { print("Player not found, searching for a wander position"); chooseDest(); } else if (behaviors.name != "Searching") { navMesh.Stop(); movementHandler(targetSighted); } }
void Update() { if (increasedAggressionTesting) { aggressionLevel += TimerContainer.wait(4, 5f, -2, 10, 7); //wait for 5 to 10 seoconds, and increase the } else { aggressionLevel += TimerContainer.wait(4, 30, -2, 45, 7); } for (int i = 0; i <= behaviorObjects.Length - 1; i++) { if (behaviorObjects[i].activeInHierarchy) //loops through and finds an active object for the current behavior { currentBehavior = behaviorObjects[i].name; //Assings the current behavrior to a string so we can use it later break; //We've already found the current behavior, so exit the loop. } } if (Input.GetKeyDown(KeyCode.Q)) { aggressionLevel = 100; } targetSighted = EnemyController.targetSighted; if (targetSighted == false && currentBehavior != "Searching") { print("Searching behavior chosen."); setBehavior(0); } else if (targetSighted == true /*&& currentBehavior == "Searching"*/) { targetFound(EnemyController.targetSighted, targetSightedRecently); } else { /*print("There's been an error with deciding behaviors... no paramaters were met."); * print("Current time: " + Time.time); * print(EnemyController.targetSighted); * print(targetSighted); * print(currentBehavior);*/ } targetSightedRecently = false; }
private static void AddTimer(TimerContainer tc) { TimerContainer cur = _timer, prev = null; while (cur != null && cur.to < tc.to) { prev = cur; cur = prev.next; } tc.next = cur; if (prev == null) { _timer = tc; } else { prev.next = tc; } }
public void addComponent(Player shot) { int updateTimeHere = -1; int i = 0; foreach (TimerContainer element in myList) { if (element.player == shot) { updateTimeHere = i; break; } i++; } if (updateTimeHere != -1) { myList.RemoveAt(updateTimeHere); } TimerContainer added = new TimerContainer(); added.player = shot; added.time = Time.time; myList.Add(added); }
void targetFound(bool yesNo, bool recently) //Target sighted and recently { if (yesNo == true) { if (TimerContainer.wait(5, 10f, 30f)) { print("Time to wait until next check: " + TimerContainer.timer[5]); chooseBehavior(); } else if (recently == true) { print("Update required before timer struck."); chooseBehavior(); } } else { print("There was an error... player was not really found?"); print("Current time: " + Time.time); print(EnemyController.targetSighted); print(targetSighted); print(currentBehavior); } }
public static void ClearTimeout(JSC.Context ctx) { TimerContainer t = _timer, tp = null; while (t != null) { if (t.ctx == ctx) { if (tp == null) { _timer = t.next; } else { tp.next = t.next; } } else { tp = t; } t = t.next; } }
public void movementHandler(bool playerFound) { playerFound = EnemyController.targetSighted; if (playerFound == false) { //Makes sure we can run the check if the ghost is stuck if (TimerContainer.wait(6, 0.5f)) { checks[lastCheck] = rb.position; lastCheck += 1; ghostReportedStuck = false; checkPositions(); if (lastCheck >= 6) //Resets the points recorded to check if the ghost is stuck. { lastCheck = 0; resetChecks(); } if (!ghostReportedStuck) { print("There are no one positions that are the same. Continue as normal!"); } else { print("The ghost has reported being stuck. Searching for a new position!"); chooseDest(); } } if (behaviors.name == "Searching") { if (TimerContainer.wait(7, 2f)) { print("Searching behavior chosen."); searching(); } } else { print("There was an erorr. Searching behavior is not active, but player is not found!"); } } else { if (behaviors.name == "Aggressive") { if (TimerContainer.wait(7, 2f)) { print("Aggressive behavior chosen"); } aggressive(); } else if (behaviors.name == "Stalking") { if (TimerContainer.wait(7, 2f)) { print("Stalk behavior chosen"); stalk(); } } } }
void runDetection(float distance, bool targetAlreadyFound = false) { //check if we can detect player bool tryToFind = true; if (distance >= 40 && distance < 150) { minChance = (-Mathf.RoundToInt(distance) + Mathf.RoundToInt(detectionDistPlayer)); //lowest min chance is -15. maxChance = 100 + (Mathf.RoundToInt(distance) - Mathf.RoundToInt(maxViewDist)); //lowest max chance is 120. } else if (distance >= 150) //makes it a 0% chance for the ghost to find the player after 150 feet distance. { print("There is no chance to find the player... must wander...."); tryToFind = false; } else if (!targetAlreadyFound) { if (distance < 40 && distance > 20) { minChance = 100; //makes it a 17.3% chance for the ghost to fail to find the player if they are less then 40 units away. } else if (distance <= 20) { minChance = 115; //makes it a 4.2% chance the ghost will fail to find the player if they are less then 20 feet away. } } else if (targetAlreadyFound) { //this needs to change how calculations are done so that the player has a chance to escape and the ghost goes back to searching like before. if (distance <= 20) { minChance = 119; } else if (distance >= 70 && distance < 150) { if (targetInfront) { if (TimerContainer.wait(2, 10f)) //Timer to make sure the ghost is given time before decreasing the chance { minChance = 100; } else { minChance = 110; } } else { if (TimerContainer.wait(3, 10f)) //Second timer to make sure the ghost is given time before decreasing the chance { minChance = 90; } else { minChance = 100; } } } } if (tryToFind) //this tells us if we CAN check for the player. { detectionRoll = Random.Range(minChance, maxChance); //the ROLL if ((maxChance + minChance) > maxChance) //this is meant to make sure the required min role does not exceed possible roles. { if (distance < 40 && distance > 20) { int aditionalChances = (maxChance - minChance) / 4; detectionChance = minChance + aditionalChances; } else if (distance <= 20) { int aditionalChances = (maxChance - minChance) / 10; detectionChance = minChance + aditionalChances; } } else { detectionChance = maxChance + minChance; //Min required roll to detect player } bool agroDetectIncrease = false; if (targetAlreadyFound == true) { print("Target is found. Decreasing chance of losing target. (-40)"); detectionChance -= 40; if (agroDetectIncrease == false) { if (Behavior.aggressionLevel >= 100 || chosenBehavior.name == "Aggressive") { print("Ghost is aggressive. Decreasing chance further. (-60)"); detectionChance -= 60; agroDetectIncrease = true; } } agroDetectIncrease = false; } if (targetInfront) //Pretty straight forward... if target is infront... increase the odds of finding the player. { print("Target is in front of ghost. Decreasing chance of losing target. (-30)"); detectionChance -= 30; if (agroDetectIncrease == false) { if (Behavior.aggressionLevel >= 100 || chosenBehavior.name == "Aggressive") { print("Ghost is aggressive. Decreasing chance further. (-60)"); detectionChance -= 60; agroDetectIncrease = true; } } agroDetectIncrease = false; } else { if (distance > 70) { print("Ghost is not close to target. Increasing chance of losing target. (+15)"); detectionChance += 15; } } print("Final result of the ghost detecting the player: " + detectionChance); if (detectionRoll >= detectionChance) //Should run when the ghost finds the player. { targetSighted = true; Behavior.recentlySighted(); } else { if (targetSighted) { targetSighted = false; print("Target was lost."); print(detectionChance); print(detectionRoll); } } } else //this should run if the ghost fails to find the player { targetSighted = false; } }
void Update() { float distance = Vector3.Distance(target.position, transform.position); distanceFromPlayer = distance; time = Time.time; chosenBehavior = GameObject.FindGameObjectWithTag("Behaviors"); if (Behavior.aggressionLevel >= 100) { scream.SetActive(true); } else if (Behavior.aggressionLevel <= 75) { scream.SetActive(false); } if (targetSighted && distance >= 150) { targetSighted = false; } detectionDistPlayer = PlayerControllerMovements.detectionDist; //pulls the info from the player movement script to see what the weight of detection is from them. //check if we are facing player float dot = Vector3.Dot(transform.forward, (target.position - transform.position).normalized); if (dot > 0.7f) { targetInfront = true; } else { targetInfront = false; } //facing player check end. if (TimerContainer.wait(1, 4f, 8f)) //handles the timer to check and see if the target can be found. { detectionRoll = 0; runDetection(distance, targetSighted); print("Detection check ran. Next check at: " + TimerContainer.timer[1]); } else if (Input.GetKeyDown(KeyCode.I)) { detectionRoll = 0; print("Forcing detection check"); runDetection(distance, targetSighted); } if (Input.GetKeyDown(KeyCode.P)) //enter debugging mode { if (debugging) { debugging = false; } else { debugging = true; } } if (debugging) { Vector3 right = (transform.TransformDirection(Vector3.forward) + transform.TransformDirection(Vector3.right)) * 100; Vector3 left = (transform.TransformDirection(Vector3.forward) - transform.TransformDirection(Vector3.right)) * 100; Debug.DrawRay(transform.position, right, Color.green); Debug.DrawRay(transform.position, left, Color.green); Debug.DrawRay(transform.position, transform.forward, Color.yellow); Debug.DrawRay(transform.position, (target.position - transform.position).normalized, Color.yellow); } }
private void OnFinish(TimerContainer container, float left, float right) { text = "FINISH TIMER WITH " + right + " DELAY"; }
// Start is called before the first frame update protected void Start() { TimerContainer.CreateTimer(out timer, timerValue, true, false, OnFinish, TimeType.Scaled); }
private void OnFinishTime(TimerContainer container, float left, float right) { GameObjectExtend.DestroyGameObject(gameObject); }
void Awake() { instance = this; }
public virtual void Finish(Player player) { TimerContainer.Clear(); new Showdown(World.Level.Name.Trim() + "_S", World.Player1 == player ? true : false); Close(); }