public void StartGameTimer() { if (_gameTimer == null) { _gameTimer = gameObject.AddComponent <CountDownTimer>(); } _gameTimer.StartTimer(_renderData.GameService.GameTime, UpdateGameTimer, FinishGameTimer); }
/// <summary> /// Ends the attack, turning off the trails and caster and beginning the cooldown timer. /// </summary> void EndAttack () { attackCooldown.StartTimer (cooldownTime); if (!enemy.currentAttack.IsRanged ()) { attackCaster.End (); trailRenderer.enabled = false; } isAttacking = false; // TODO This is bad practice. When we refactor this, let's properly enapsulate // the current attack in one of these classes. enemy.currentAttack = null; }
/// <summary> /// Starts the attack, activating the cast if needed, playing the animation, and starting /// timer for the attack. /// </summary> /// <param name="attackToStart">Attack to start.</param> void StartAttack (AttackData attackToStart) { // TODO This is bad practice. When we refactor this, let's properly enapsulate // the current attack in one of these classes. enemy.currentAttack = attackToStart; attackAnimation.Play (attackToStart.swingAnimation.name); if (!attackToStart.IsRanged ()) { attackCaster.OnHit += OnAttackHit; attackCaster.Begin (); trailRenderer.enabled = true; } attackTime.StartTimer (attackToStart.swingAnimation.length); isAttacking = true; }
public bool HandleEvent(AFEvent afEvent) { switch (afEvent.type) { case AFEventType.KILLED: { HandlePlayerKilledEvent((KilledEventPayload)afEvent.payload); return(true); } case AFEventType.PLAYERS_ALL_CREATED: { var payload = (PlayersAllCreatedPayload)afEvent.payload; HandleGameStart(payload.AllPlayers); return(true); } case AFEventType.COUNT_DOWN_FINISHED: { var payload = (CountDownFinishedPayload)afEvent.payload; if (!payload.TimerName.Equals(RoundTimerName)) { break; } countDownTimerInstance.StopTimer(); if (IsEntireGameOver()) { Debug.Log("Game over, time ran out!"); var winningScore = currentRoundScores.SortedByDescendingScores()[0]; AFEventManager.INSTANCE.PostEvent(AFEvents.GameOver(winningScore.PlayerNumber(), winningScore.Score(), winningScore.PlayerColor())); } else { Debug.Log("Round over, time ran out!"); var winningScore = currentRoundScores.SortedByDescendingScores()[0]; AFEventManager.INSTANCE.PostEvent(AFEvents.RoundOver(winningScore.PlayerNumber(), winningScore.Score(), winningScore.PlayerColor())); } break; } case AFEventType.GAME_START: { countDownTimerInstance.StartTimer(); break; } } return(false); }
public void SendRequest(GameRequests request, GameResponse response, Action <string> onSuccess, Action <ResponseCode> onFail, Message message = null, Servers server = Servers.Game) { if (_ws.isConnected) { _commandCode[0] = (byte)server; _commandCode[1] = (byte)request; _commandCode[2] = (byte)ResponseCode.Ok; if (message != null) { string serializedString = JsonWriter.Serialize(message); byte[] messageBuffer = Encoding.UTF8.GetBytes(serializedString); byte[] sendBuffer = new byte[messageBuffer.Length + 3]; Buffer.BlockCopy(_commandCode, 0, sendBuffer, 0, 3); Buffer.BlockCopy(messageBuffer, 0, sendBuffer, 3, messageBuffer.Length); _ws.Send(sendBuffer); this.Log("Send: server = " + server + ", request = " + request + ", message = " + serializedString); } else { _ws.Send(_commandCode); this.Log("Send: server = " + server + ", request = " + request); } Request newRequest = new Request { RequestType = request, OnSuccess = onSuccess, OnFail = onFail }; _waitingRequests.Add(response, newRequest); CountDownTimer timer = _timerProvider.Get(); timer.StartTimer(_responseTimeOut, null, () => OnTimeOut(response)); _timerRequest.Add(response, timer); } else { this.LogError("Connect before send!"); } }
// Update is called once per frame void Update() { if (Target == null) { FindTarget(); } if (Target != null) { Vector3 directionToTarget = (Target.transform.position - transform.position); float sqrDistanceToTarget = directionToTarget.sqrMagnitude; directionToTarget.Normalize(); // Check if we should start an attack float ATTACK_RANGE_SQUARED = 16.0f; bool isInAttackRange = sqrDistanceToTarget <= ATTACK_RANGE_SQUARED; if (isInAttackRange && attackCooldown.IsTimeUp()) { enemy.WantsToAttack = true; attackCooldown.StartTimer(WAIT_TIME); } if (isInAttackRange && !enemy.isAttacking) { // Stop moving enemy.MoveDirection = Vector3.zero; } else { // Approach target until in range. Also approach during attack enemy.MoveDirection = directionToTarget; } // Always face and move towards the target enemy.FaceDirection = directionToTarget; } }
private void Start() { timer = gameObject.GetComponent <CountDownTimer>(); timer.StartTimer(); }