GetImpactPoint() public method

public GetImpactPoint ( ) : Vector3
return Vector3
    /// <summary>
    /// NPC hits another NPC
    /// </summary>
    /// <param name="targetNPC">Target NP.</param>
    /// <param name="originNPC">Origin NP.</param>
    public static void NPC_Hits_NPC(NPC targetNPC, NPC originNPC)
    {
        int Defence    = targetNPC.GetDefence();
        int Attack     = originNPC.GetAttack();
        int toHit      = Mathf.Max(Defence - Attack, 1);
        int roll       = Random.Range(-1, 31);
        int BaseDamage = Random.Range(1, originNPC.GetDamage() + 1);

        if (((roll >= toHit) || (roll >= 30)) && (roll > -1))
        {
            targetNPC.ApplyAttack((short)BaseDamage, originNPC.gameObject);
            Impact.SpawnHitImpact(Impact.ImpactBlood(), targetNPC.GetImpactPoint(), targetNPC.objInt().GetHitFrameStart(), targetNPC.objInt().GetHitFrameEnd());
            if (ObjectInteraction.PlaySoundEffects)
            {
                originNPC.objInt().aud.clip = GameWorldController.instance.getMus().SoundEffects[MusicController.SOUND_EFFECT_MELEE_HIT_1];
                originNPC.objInt().aud.Play();
            }
        }
    }
    /// <summary>
    /// Combat calculations for PC hitting an NPC
    /// </summary>
    /// <param name="playerUW">Player Character</param>
    /// <param name="npc">Npc.</param>
    /// <param name="hit">Hit.</param>
    public static void PC_Hits_NPC(UWCharacter playerUW, WeaponMelee currentWeapon, string StrikeName, float StrikeCharge, NPC npc, RaycastHit hit)
    {
        int attackScore = 0;

        int   flankingbonus = 0; //need to calcu but depending on relative headings between attacker and defender.
        int   magicbonus    = 0; //currently unknown what provides this but is calculated by casting/5 + 0xA when set.
        short MinCharge;
        short MaxCharge;

        if (npc != null)
        {
            //recalc position to get the correct heading for the flanking bonus
            npc.objInt().UpdatePosition();
            flankingbonus = CalcFlankingBonus(playerUW.currentHeading, npc.objInt().heading);
        }


        if (currentWeapon != null)
        {
            attackScore = (playerUW.PlayerSkills.GetSkill(Skills.SkillAttack) >> 1) + playerUW.PlayerSkills.GetSkill(currentWeapon.GetSkill()) + (playerUW.PlayerSkills.DEX / 7) + magicbonus + flankingbonus;
            if (GameWorldController.instance.difficulty == 0)
            {//bonus of 7 for easy difficulty
                attackScore += 7;
            }
            attackScore += currentWeapon.AccuracyBonus();//Given by the accuracy enchantments. Note in vanilla UW2 accuracy actually increases damage and not attack score. This is fixed here.

            MinCharge = currentWeapon.GetMinCharge();
            MaxCharge = currentWeapon.GetMaxCharge();
        }
        else
        {
            //use the unarmed calculations
            attackScore = (playerUW.PlayerSkills.GetSkill(Skills.SkillAttack) >> 1) + playerUW.PlayerSkills.GetSkill(Skills.SkillUnarmed) + (playerUW.PlayerSkills.DEX / 7) + magicbonus + flankingbonus;
            if (GameWorldController.instance.difficulty == 0)
            {//bonus of 7 for easy difficulty
                attackScore += 7;
            }
            MinCharge = WeaponMelee.GetMeleeMinCharge();
            MaxCharge = WeaponMelee.GetMeleeMaxCharge();
        }


        //Get base damage
        int BaseSwingDamage   = GetPlayerBaseDamage(currentWeapon, StrikeName);
        int basePower         = (short)(GameWorldController.instance.objDat.critterStats[63].Strength / 9); //the player is actually a critter so power in this case is their STR.
        int WeaponBonusDamage = 0;

        if (currentWeapon != null)
        {
            WeaponBonusDamage = currentWeapon.DamageBonus();
        }
        else
        {                                                                                            //unarmed
            basePower  = (short)(GameWorldController.instance.objDat.critterStats[63].Strength / 6); //the player is actually a critter so power in this case is their STR.
            basePower += (playerUW.PlayerSkills.GetSkill(Skills.SkillUnarmed) / 5);
        }


        //scale base damage by charge. Min damage is always 2.
        short Damage = (short)(basePower + BaseSwingDamage + WeaponBonusDamage);

        // damage % 6 no of 1D6s to calculate the actual damage and then add the remainder as a final roll 1-remainder
        Damage = (short)(DamageRoll((short)(Damage / 6), 6) + DamageRoll(1, (short)(Damage % 6)));

        //Damage is scaled by the amount of weapon charge built up.
        Damage = CalcAttackChargeDamage((short)StrikeCharge, MinCharge, MaxCharge, Damage);

        //And a flat flanking bonus
        Damage += (short)flankingbonus;

        //Min damage will be 2.
        Damage = (short)(Mathf.Max(Damage, 2));

        Skills.SkillRollResult rollresult = Skills.SkillRoll(attackScore, npc.Defence());

        bool CriticalHit = RollForCritDamage(ref Damage, rollresult);

        switch (rollresult)
        {
        case Skills.SkillRollResult.CriticalSuccess:
        case Skills.SkillRollResult.Success:
        {
            Debug.Log("Base Damage = " + ((short)(basePower + BaseSwingDamage + WeaponBonusDamage)) + " Final Damage = " + Damage);
            if (CriticalHit)
            {
                Impact.SpawnHitImpact(Impact.ImpactBlood(), npc.GetImpactPoint() + Vector3.up * 0.1f, npc.objInt().GetHitFrameStart(), npc.objInt().GetHitFrameEnd());
            }
            npc.ApplyAttack(Damage, playerUW.gameObject);
            Impact.SpawnHitImpact(Impact.ImpactBlood(), npc.GetImpactPoint(), npc.objInt().GetHitFrameStart(), npc.objInt().GetHitFrameEnd());
            if (currentWeapon != null)
            {        ///Performs the onHit action of the melee weapon.
                currentWeapon.onHit(hit.transform.gameObject);
            }
            break;
        }

        case Skills.SkillRollResult.Failure:
            npc.ApplyAttack(0, playerUW.gameObject);
            npc.npc_aud.PlayCombatMissed();
            break;

        case Skills.SkillRollResult.CriticalFailure:
        {
            npc.ApplyAttack(0, playerUW.gameObject);
            npc.npc_aud.PlayCombatMissed();
            //Damage weapon
            short durability = currentWeapon.getDurability();
            if (durability <= 30)
            {
                currentWeapon.SelfDamage((short)Mathf.Max(0, Random.Range(0, npc.EquipDamage + 1) - durability));
            }
            break;
        }
        }
    }
示例#3
0
    //Combat calcs


    /// <summary>
    /// Combat calculations for PC hitting an NPC
    /// </summary>
    /// <param name="playerUW">Player Character</param>
    /// <param name="npc">Npc.</param>
    /// <param name="hit">Hit.</param>
    public static void PC_Hits_NPC(UWCharacter playerUW, WeaponMelee currentWeapon, string StrikeName, float StrikeCharge, NPC npc, RaycastHit hit)
    {
        int attackScore = 0;
        int BaseDamage  = GetPlayerBaseDamage(currentWeapon, StrikeName);

        if (currentWeapon != null)
        {
            attackScore  = playerUW.PlayerSkills.GetSkill(Skills.SkillAttack) / 2 + playerUW.PlayerSkills.GetSkill(currentWeapon.GetSkill() + 1);
            attackScore += currentWeapon.AccuracyBonus();
        }
        else
        {
            attackScore = playerUW.PlayerSkills.GetSkill(Skills.SkillAttack) / 2 + playerUW.PlayerSkills.GetSkill(Skills.SkillUnarmed);
        }


        int toHit = Mathf.Max(npc.GetDefence() - attackScore, 0);
        //Difficulty is either 1 for standard or 0 for easy.
        //int roll = Mathf.Max(30,Random.Range(-1,31) + ( 5 * (1- GameWorldController.instance.difficulty) )  );//-1 is critical miss. 30 is always hit

        int roll = Mathf.Min(30, Skills.DiceRoll(-1, 31) + (5 * (1 - GameWorldController.instance.difficulty)));

        int HitRollResult = 0;

        if (((roll >= toHit) || (roll >= 30)) && (roll > -1))
        {
            short Damage = (short)(Mathf.Max(((float)(BaseDamage)) * (StrikeCharge / 100f), 1));
            npc.ApplyAttack(Damage, playerUW.gameObject);
            HitRollResult = 1;
            if (roll == 30)
            {
                HitRollResult = 2;                      //crit. apply double damage
                npc.ApplyAttack(Damage, playerUW.gameObject);
            }
            if (roll >= 27)
            {
                HitRollResult = 2;                      //critical
            }
        }
        else
        {
            HitRollResult = 0;
            npc.ApplyAttack(0, playerUW.gameObject);                   //A zero damage attack to update ai if needed
            if (currentWeapon != null)
            {
                //Apply equipment damage to weapon if NPC Defence is 1.5 times attackscore
                if ((float)npc.GetDefence() > (float)attackScore * 1.5f)
                {
                    short durability = currentWeapon.getDurability();
                    //currentWeapon.WeaponSelfDamage();
                    if (durability <= 30)
                    {
                        currentWeapon.SelfDamage((short)Mathf.Max(0, Random.Range(0, npc.GetArmourDamage() + 1) - durability));
                    }
                }
            }
        }


        ///Creates a blood splatter at the point of impact
        switch (HitRollResult)
        {
        case 0:                 //Miss
                                //Impact.SpawnHitImpact(hit.transform.name + "_impact", npc.objInt().GetImpactPoint(),46,50);
            if (ObjectInteraction.PlaySoundEffects)
            {
                npc.objInt().aud.clip = GameWorldController.instance.getMus().SoundEffects[MusicController.SOUND_EFFECT_MELEE_MISS_2];
                npc.objInt().aud.Play();
            }
            break;

        case 1:                //Hit
            Impact.SpawnHitImpact(Impact.ImpactBlood(), npc.GetImpactPoint(), npc.objInt().GetHitFrameStart(), npc.objInt().GetHitFrameEnd());
            if (ObjectInteraction.PlaySoundEffects)
            {
                npc.objInt().aud.clip = GameWorldController.instance.getMus().SoundEffects[MusicController.SOUND_EFFECT_MELEE_HIT_1];
                npc.objInt().aud.Play();
            }
            break;

        case 2:                //Crit
            Impact.SpawnHitImpact(Impact.ImpactBlood(), npc.GetImpactPoint(), npc.objInt().GetHitFrameStart(), npc.objInt().GetHitFrameEnd());
            Impact.SpawnHitImpact(Impact.ImpactBlood(), npc.GetImpactPoint() + Vector3.up * 0.1f, npc.objInt().GetHitFrameStart(), npc.objInt().GetHitFrameEnd());
            if (ObjectInteraction.PlaySoundEffects)
            {
                npc.objInt().aud.clip = GameWorldController.instance.getMus().SoundEffects[MusicController.SOUND_EFFECT_MELEE_HIT_2];
                npc.objInt().aud.Play();
            }
            break;
        }

        if (currentWeapon != null)
        {                ///Performs the onHit action of the melee weapon.
            currentWeapon.onHit(hit.transform.gameObject);
        }
    }