private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Mouse0) || Input.GetKeyDown(KeyCode.Space))
     {
         combatController.Attack();
     }
 }
    private void CombatInput()
    {
        if (GetPointerState())
        {
            return;
        }

        if (Input.GetButtonDown("Attack"))
        {
            combatController.Attack();
        }

        if (Input.GetButtonDown("DrawSword"))
        {
            combatController.ToggleCombatMode();
            enemyInfo.TogglePanel(false);
        }

        if (Input.GetButtonDown("Block"))
        {
            combatController.Block(true);
        }
        else if (Input.GetButtonUp("Block"))
        {
            combatController.Block(false);
        }

        if (Input.GetButtonDown("Cast"))
        {
            animator.SetTrigger("castSpell");
        }
    }
Example #3
0
 private void OnTriggerEnter(Collider spell)
 {
     if (spell.CompareTag("Spell"))
     {
         attacker = spell.GetComponent <Projectile>().caster;
         //Debug.Log(attacker);
         if (attacker != null && attacker.name != gameObject.name)
         {
             attacker.Attack(myStats, spell.GetComponent <Projectile>().projectileDamage);
         }
     }
 }
 void HandleAttack()
 {
     foreach (Collider hitObject in combatController.GetHitObjects())
     {
         if (hitObject.TryGetComponent <CombatController>(out CombatController targetCC) &&
             targetCC.faction != combatController.faction)
         {
             combatController.Attack();
             return;
         }
     }
 }
Example #5
0
    void AttackIfInRange()
    {
        float distanceFromTarget = Mathf.Abs(target.position.x - transform.position.x);

        if (distanceFromTarget < attackRange)
        {
            if (canAttack)
            {
                canAttack = false;
                combatController.Attack();
                StartCoroutine(WaitAttackSpeed());
            }
        }
    }
Example #6
0
    void Update()
    {
        if (Input.GetKeyDown(attackKey))
        {
            combatController.Attack();
        }

        if (Input.GetKeyDown(blockKey))
        {
            combatController.SetBlocking(true);
        }
        else if (Input.GetKeyUp(blockKey))
        {
            combatController.SetBlocking(false);
        }
    }
        public void AttackPlayerInCombat()
        {
            // Arrange
            Mock <User>        userMock    = new Mock <User>();
            Mock <GameManager> managerMock = new Mock <GameManager>(userMock.Object);

            managerMock.Expect(m => m.CurrentPlayer.Ship.InProgressCombat)
            .Returns(new Combat()).Verifiable();
            CombatController controller = new CombatController(managerMock.Object);

            // Act
            ActionResult result = controller.Attack();

            // Assert
            Assert.That(result, Is.TypeOf(typeof(RedirectToRouteResult)), "Should return a redirect");
            Assert.That(controller.ModelState.IsValid, "No errors should be returned");
            managerMock.Verify();
        }
        public void AttackInvalidShip()
        {
            // Arrange
            Mock <User>        userMock    = new Mock <User>();
            Mock <GameManager> managerMock = new Mock <GameManager>(userMock.Object);
            Ship targetShip = new Ship();

            managerMock.Expect(m => m.GetShip(2))
            .Returns <Ship>(null).Verifiable();
            CombatController controller = new CombatController(managerMock.Object);

            // Act
            ActionResult result = controller.Attack(2);

            // Assert
            Assert.That(result, Is.TypeOf(typeof(ViewResult)), "Should return a view");
            Assert.That(controller.ModelState.IsValid, Is.False, "Errors should be returned");
            managerMock.Verify();
        }
Example #9
0
    void Update()
    {
        if (!controllable)
        {
            return;
        }

        CheckMovement();

        crouch = Input.GetButton(AxisConst.crouch);

        if (Input.GetButtonDown(AxisConst.jump))
        {
            Jump();
        }

        if (Input.GetButtonDown(AxisConst.attack))
        {
            combatController.Attack();
        }
    }
Example #10
0
    // Update is called once per frame
    void Update()
    {
        lookDirection = new Vector3(Input.GetAxis("LookHorizontal" + playerControlString), Input.GetAxis("LookVertical" + playerControlString), 0);

        if (Input.GetButtonDown("Boost" + playerControlString))
        {
            movement.boosting = true;
        }
        if (Input.GetButtonUp("Boost" + playerControlString))
        {
            movement.boosting = false;
        }

        if (Input.GetButtonDown("Drift" + playerControlString))
        {
            movement.drifting = true;
        }
        if (Input.GetButtonUp("Drift" + playerControlString))
        {
            movement.drifting = false;
        }
        //Keyboard Fire mechanism
        if (Input.GetButtonDown("Fire" + playerControlString))
        {
            if (controlType == ControlType.Keyboard)
            {
                combat.Charge();
            }
            else
            {
                RaycastHit hit;
                target = Vector3.zero;
                Vector3 direction = new Vector3(lookDirection.x, 0, lookDirection.y) * 10.0f;
                Physics.Raycast(transform.position + direction + Vector3.up * 50, Vector3.down, out hit, 1000, obstacleMask);
                target    = hit.point;
                target.y += 1;
                combat.Attack(target);
                charging = false;
            }
        }
        if (Input.GetButtonUp("Fire" + playerControlString))
        {
            if (controlType == ControlType.Keyboard)
            {
                RaycastHit hit;
                target = Vector3.zero;
                Physics.Raycast(myCamera.ScreenPointToRay(Input.mousePosition), out hit, 1000, obstacleMask);
                Debug.Log(hit.point);
                target    = hit.point;
                target.y += 1;
                //target.y = transform.position.y;
                combat.Attack(target);
            }
        }

        if (lookDirection.magnitude > 0 && !charging)
        {
            combat.Charge();
            charging = true;
        }
        else if (lookDirection.magnitude < 0.1f)
        {
            charging = false;
        }

        if (Input.GetButtonDown("Drop" + playerControlString))
        {
            combat.Drop();
        }

        movement.turn   = Input.GetAxis("Horizontal" + playerControlString);
        movement.thrust = Input.GetAxis("Vertical" + playerControlString);

        if (lookDirection.magnitude > 0.5f)
        {
            Vector3 targetDir = Vector3.RotateTowards(aimReticle.forward, new Vector3(-lookDirection.x, 0, -lookDirection.y), 1.0f, 0.0f);
            aimReticle.rotation = Quaternion.LookRotation(targetDir);
            reticleRend.enabled = true;
        }
        else
        {
            reticleRend.enabled = false;
        }

        lastLookDirection = lookDirection;
    }
Example #11
0
    private IEnumerator StartTrueAttack(Action <OperationStateType> setOperationState, Action <float> setDelay, AttackType attackType = AttackType.Attack, ElementType elementType = ElementType.None)
    {
        /// 攻擊前搖
        opc.isPreAttacking = true;

        _attack.AttackOperationLock();

        // 重置每段攻擊時間間隔
        AttackAnimNumber++;
        ResetAttackDelayDuration();
        setDelay(attackDelayDuration);

        // 若是最後一段的攻擊動作,就無法預存下一個攻擊動作。
        if (CheckIsFinalAttack())
        {
            setOperationState(OperationStateType.Interrupt);
        }
        else
        {
            setOperationState(OperationStateType.Trigger);
        }
        yield return(new WaitForSeconds(GetFrameTimeOffset(1)));   // 等待一幀,使動畫開始撥放,否則會取到上一個動畫的狀態。

        // 攻速過快,動畫時間縮短
        preAttackAnimDuration = AnimationBase.Instance.GetCurrentAnimationLength(anim);
        if (maxAttackAnimDuration < preAttackAnimDuration)
        {
            preAttackAnimDuration = maxAttackAnimDuration;
        }
        yield return(new WaitForSeconds(preAttackAnimDuration));    // 等待動畫播放結束

        /// 攻擊中
        opc.isPreAttacking = false;
        opc.isAttacking    = true;

        // 鎖定跳躍與閃避、方向
        jump.Lock(LockType.Operation);
        evade.Lock(LockType.Operation);
        freeDirection.Lock(LockType.Operation);

        if (!CheckIsFinalAttack())
        {
            setOperationState(OperationStateType.Continuous);
        }
        else
        {
            setOperationState(OperationStateType.None);
        }
        yield return(new WaitForSeconds(GetFrameTimeOffset(2)));

        // 累積攻擊次數+1
        attackComboCount++;

        // 攻擊觸發
        opsc.PlaySound(opsc.attackSound);
        if (combatController.Attack(attackType, elementType))
        {
            opsc.PlaySound(opsc.hitSound);
        }

        // 攻速過快,動畫時間縮短
        attackAnimDuration = AnimationBase.Instance.GetCurrentAnimationLength(anim);
        if (maxAttackAnimDuration < attackAnimDuration)
        {
            attackAnimDuration = maxAttackAnimDuration;
        }

        // 儲存下次攻擊重置時間
        attackFinishedTime  = Time.time + attackAnimDuration;
        nextAttackResetTime = attackFinishedTime + attackResetDuration;

        float comboDuration = GetFrameTimeOffset(8);

        yield return(new WaitForSeconds(attackAnimDuration - comboDuration));

        // 攻擊收尾,可連段
        setOperationState(OperationStateType.Link);

        yield return(new WaitForSeconds(comboDuration));

        opc.isAttacking = false;
    }