예제 #1
0
 private void OnAttack(GameObject target, GameObject source, Attack attack, AttackResponse attackResponse)
 {
     if (attackResponse.HitType == AttackResponse.HitResult.Heavy)
     {
         PlaySound("light_hit");
     }
 }
        public IRemoteObject Handle(AsyncUserToken token, IRemoteObject request)
        {
            AttackRequest  cardPlayRequest = request as AttackRequest;
            AttackResponse response        = new AttackResponse
            {
                Successfulness = true,
                Message        = null
            };

            try
            {
                GAME_MANAGER.Attack(token, cardPlayRequest.AttackingUnit, cardPlayRequest.TargetPlayer, cardPlayRequest.TargetUnit);
            }
            catch (LogicExecutionException e)
            {
                response.Successfulness = false;
                response.Message        = e.Message;
            }
            return(response);
        }
예제 #3
0
    public override AttackResponse Damage(Attack attack)
    {
        if (!IsAlive)
        {
            return(new AttackResponse(0, AttackResponse.HitResult.None));
        }
        OnAttacked(attack);

        AttackResponse attackResponse = OnReponseToAttack(attack);

        if (attackResponse.HitType == AttackResponse.HitResult.Blocked)
        {
            return(attackResponse);
        }

        if (attackResponse.DamageTaken > 0)
        {
            BuiltInDamage(attackResponse.DamageTaken);
        }
        return(attackResponse);
    }
예제 #4
0
 public void AttackEvent(GameObject target, GameObject source, Attack attack, AttackResponse attackResponse)
 {
     OnAttack?.Invoke(target, source, attack, attackResponse);
 }
 private void HandleAttackResponse(AttackResponse response)
 {
     Debug.Log("Odgovor na zahtev za napad: \n" +
               $"Uspesnost: {response.Successfulness}, poruka: {response.Message}");
 }
예제 #6
0
    /// <summary>
    /// When called triggers attack
    /// </summary>
    public void StartAttack()
    {
        if (combatState != PlayerCombatState.None)
        {
            return;
        }


        hitState = HitState.None;
        //layerMask = LayerMask.GetMask("Enemy");
        RaycastHit hitInfo     = new RaycastHit();
        RaycastHit enemyHitRay = new RaycastHit();
        Vector2    stepSize    = new Vector2(2 * rayProps.checkAngles.x / rayProps.steps, 2 * rayProps.checkAngles.y / rayProps.steps);

        for (float x = -rayProps.checkAngles.x; x <= rayProps.checkAngles.x; x += stepSize.x)
        {
            for (float y = -rayProps.checkAngles.y; y <= rayProps.checkAngles.y; y += stepSize.y)
            {
                Ray ray = new Ray(transform.position + rayProps.offset, transform.rotation * Quaternion.AngleAxis(y, Vector3.forward) * Quaternion.AngleAxis(x, Vector3.up) * Vector3.forward);
                if (Physics.Raycast(ray, out hitInfo, rayProps.checkDistance, layerMask))
                {
                    if (hitInfo.collider.CompareTag("Shield"))
                    {
                        hitState |= HitState.Shield;
                    }
                    if (hitInfo.collider.CompareTag("Enemy"))
                    {
                        hitState   |= HitState.Enemy;
                        enemyHitRay = hitInfo;
                    }
                }
            }
        }
        if ((hitState & HitState.Enemy) == HitState.Enemy)
        {
            //Hit enemy
            if (((transform.position - enemyHitRay.collider.gameObject.transform.position) / 2f).magnitude > 1)
            {
                characterController.Move(-(transform.position - enemyHitRay.collider.gameObject.transform.position) / 2f);
            }

            transform.LookAt(enemyHitRay.collider.gameObject.transform);
            transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
            //enemyHitRay.collider.gameObject.GetComponent<HealthController>().Damage(100000);
            IDamageable    damageable     = (IDamageable)enemyHitRay.collider.gameObject.GetComponent(typeof(IDamageable));
            AttackResponse attackResponse = damageable.Damage(new Attack(15, Attack.AttackType.Heavy));
            GameEvents.current.combat.AttackEvent(enemyHitRay.collider.gameObject, gameObject, new Attack(15, Attack.AttackType.Heavy), attackResponse);
            if (attackResponse.HitType == AttackResponse.HitResult.Blocked)
            {
                StartCoroutine(StagerPlayer(combatProps.stageredProps.shieldHit));
            }
            else
            {
                GameEvents.current.player.DamageEnemy();
                StartCoroutine(AttackDur());
            }
        }
        if (hitState == HitState.Shield)
        {
            //Stager player
            StartCoroutine(StagerPlayer(combatProps.stageredProps.shieldHit));
        }
    }