示例#1
0
    //meleeWeapon type is class extending meleeWeapon which holds several meleeWeaponAttackTypess

    /* public void HandleAttack(DamageType damageType, int damageAmount, MeleeAttackDirection attackDirection, MeleeWeapon.MeleeWeaponType meleeWeaponType, MeleeWeaponAttackType meleeWeaponAttackType)
     * {
     *   //if we have a meleeeWeapon selected we can defend ourselves and maybe change the nextAttackTime of us or our enemy(like a counterattack) based on our melleAttack and Defense skill
     *
     *   //after damage we get and ocassionaly the change in the nextAttackType of us our the attacker we will get a calculatet damage value, here we will change it based on armor
     *   float calculatedDamage;
     *
     *   int finalDamage = 0; //=calculatet Damage - armor or smth
     *
     *   GetDamage(damageType,finalDamage);
     *
     *
     *
     * }*/
    #endregion

    #region MissileAttack & Aim
    void MissileAttack()
    {
        //make aiming thingis every x Seconds, we automaticly stop if we are not attacking anymore
        if (Time.time > nextMissileAttackTime)  //for performance optimisation- this gets called once per x frames, but also not at the same time by everone
        {
            PrepareMissileAttack();
            //Debug.Log("prepareMissileAttack");
            nextMissileAttackTime = Time.time + missileAttackIntervall;
        }

        if (inRange)
        {
            //set Weapon rotation
            currentSelectedMissileWeapon.transform.localRotation = Quaternion.RotateTowards(currentSelectedMissileWeapon.transform.localRotation, wishedWeaponRotation, currentSelectedMissileWeapon.aimSpeed);
            //turn to target + predicted offset
            base.TurnToPosition(currentAttackingTargetTransform.position + currentAttackingTarget.agent.velocity.normalized * predictedAttackingPositionOffset);

            // PrepareMissileAttack returns MissileAttackPrepared = true, always
            if (missileAttackPrepared) //we need to send it to false when we are not attacking the target anymore but when?
            {
                //checken ob wir gezielt haben, dann Schuss
                if (HasAimed() && currentSelectedMissileWeapon.weaponReadyToShoot)
                {
                    if (currentSelectedMissileWeapon.AmmoLeft())
                    {
                        RandomRotator(currentSelectedMissileWeapon);
                        currentSelectedMissileWeapon.Shoot();
                        raycastSendForThisAttack = false;
                    }
                    //else Debug.Log("no Ammo left");
                }
                else
                {
                    missileAttackPrepared = false;
                }
            }
        }
    }
    private void MissileAttack()
    {
        MissileWeapon weapon = weapons[selectedWeapon] as MissileWeapon; //cast Notwendig //später das nur einmal machen

        //wenn laudable - dann lade hier falls nicht geladen ist, wir laden schon bevor wir in Range sind

        if (weapon.missileWeaponType == MissileWeapon.MissileWeaponType.Loadable && !weapon.weaponReadyToShoot && !weapon.isPreparingWeapon)
        {
            TurnToPosition(currentAttackingTargetTransform.position);
            StartCoroutine("LoadWeapon");
            //Loading
        }


        if (Vector3.Distance(transform.position, currentAttackingTargetTransform.position) < weapon.missileRange) // wenn wir im Range sind
        {
            //aiming

            /*if (!hasCheckedDirectFire && automaticDirectFire && !moving) //checken wir nur wenn wir stehenbleiben
             * {
             *  directFire = DirectFireCheck(weapon);
             *  hasCheckedDirectFire = true;
             * }*/
            agent.isStopped = true;
            if (weapon.missileWeaponType == MissileWeapon.MissileWeaponType.Loadable) //extraabfrage loadable Weapons können nicht beim laden zielen, bogen schon
            {
                if (weapon.weaponReadyToShoot)
                {
                    aimed = (Aim(weapon));
                    Debug.Log("loaded");
                }
                else
                {
                    TurnToPosition(currentAttackingTargetTransform.position);
                }
            }
            else
            {
                aimed = (Aim(weapon));
            }

            if (Quaternion.Angle(transform.rotation, wishRotation) < 5 && !raycastSendForThisAttack)
            {//if turnedToDestination
                directFire = DirectFireCheck(weapon);
                raycastSendForThisAttack = true;
            }

            if (weapon.missileWeaponType == MissileWeapon.MissileWeaponType.Drawable) //den bogen/Wurfspeer spannen wir erst wenn wir in range sind
            {
                if (!weapon.weaponReadyToShoot && !weapon.isPreparingWeapon)
                {
                    StartCoroutine("WeaponSpannen");
                }
            }

            if (aimed && weapon.weaponReadyToShoot)
            {
                if (weapon.AmmoLeft())
                {
                    RandomRotator(weapon);
                    weapon.Shoot();
                    raycastSendForThisAttack = false;
                }
                //else Debug.Log("no Ammo left");
            }
        }
        else
        {
            SetDestinationAttack(currentAttackingTargetTransform.position);
            //hasCheckedDirectFire = false;
        }
    }