示例#1
0
 public void StartGameTimer()
 {
     if (_gameTimer == null)
     {
         _gameTimer = gameObject.AddComponent <CountDownTimer>();
     }
     _gameTimer.StartTimer(_renderData.GameService.GameTime, UpdateGameTimer, FinishGameTimer);
 }
示例#2
0
文件: AILegacy.cs 项目: nasa03/ness
	/// <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;
	}
示例#3
0
文件: AILegacy.cs 项目: nasa03/ness
	/// <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;
	}
示例#4
0
        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);
        }
示例#5
0
    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!");
        }
    }
示例#6
0
文件: AI.cs 项目: nasa03/ness
    // 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;
        }
    }
示例#7
0
 private void Start()
 {
     timer = gameObject.GetComponent <CountDownTimer>();
     timer.StartTimer();
 }