Melee Weapons.
Inheritance: Weapon
Exemplo n.º 1
0
    public void OnActivation(EntityController entity)
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            if (this.weapon is WeaponMelee)
            {
                WeaponMelee weaponMeleeToEquip = this.weapon as WeaponMelee;

                if (entity.entityProperties.weaponMelee != null)
                {
                    Debug.Log("Drop a " + entity.entityProperties.weaponMelee.weaponName + " and get a " + this.weapon.weaponName);

                    weaponPrefab.GetComponent <WeaponDisplay>().weapon = entity.entityProperties.weaponMelee;
                    Instantiate(weaponPrefab, this.transform);
                }
                entity.entityProperties.weaponMelee = weaponMeleeToEquip;
            }
            else if (this.weapon is WeaponRange)
            {
                WeaponRange weaponRangeToEquip = this.weapon as WeaponRange;
                if (entity.entityProperties.weaponRange != null)
                {
                    Debug.Log("Drop a " + entity.entityProperties.weaponRange.weaponName + " and get a " + this.weapon.weaponName);
                    weaponPrefab.GetComponent <WeaponDisplay>().weapon = entity.entityProperties.weaponRange;

                    Instantiate(weaponPrefab, this.transform);
                }

                entity.entityProperties.weaponRange = weaponRangeToEquip;
            }
            Destroy(this.gameObject);
        }
    }
Exemplo n.º 2
0
        public static WeaponBase Read(this NetworkReader reader)
        {
            WeaponType weaponType = (WeaponType)reader.ReadByte();

            switch (weaponType)
            {
            case WeaponType.Default:
                return(WeaponDefault.OnDeserialize(reader));

            case WeaponType.Melee:
                return(WeaponMelee.OnDeserialize(reader));

            case WeaponType.Projectile:
                return(WeaponProjectile.OnDeserialize(reader));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 3
0
    public static int GetPlayerBaseDamage(WeaponMelee currentWeapon, string StrikeName)
    {
        int BaseDamage = 1;

        if (currentWeapon != null)
        {
            switch (StrikeName)
            {
            case "SLASH":
                BaseDamage = currentWeapon.GetSlash(); break;

            case "BASH":
                BaseDamage = currentWeapon.GetBash(); break;

            case "STAB":
            default:
                BaseDamage = currentWeapon.GetStab(); break;
            }
        }
        else
        {
            switch (StrikeName)
            {
            case "SLASH":
                BaseDamage = WeaponMelee.getMeleeSlash(); break;

            case "BASH":
                BaseDamage = WeaponMelee.getMeleeBash(); break;

            case "STAB":
            default:
                BaseDamage = WeaponMelee.getMeleeStab(); break;
            }
        }
        return(BaseDamage);
    }
Exemplo n.º 4
0
    static int RollForAHitMelee(UWCharacter Origin, ObjectInteraction Target, WeaponMelee weap)
    {
        //0 =Miss
                //1 = hit
                //2 = Crit eventually.
                int HitScore;
                int DefenseScore;
                int WeaponSkill;

                if (weap!=null)
                {
                        WeaponSkill= Origin.PlayerSkills.GetSkill(weap.GetSkill());
                }
                else
                {
                        WeaponSkill= Origin.PlayerSkills.GetSkill(Skills.SkillUnarmed);
                }
                HitScore=Origin.PlayerSkills.Attack/2+WeaponSkill+ Random.Range(1,5);
                if (Target.GetComponent<NPC>()!=null)
                {//Target is an NPC
                        //Need to calculate this based on npc level

                        DefenseScore=-1;	//Until I figure out what values drive this, always hit.
                }
                else
                {
                        DefenseScore=-1;//Will always hit an non-npc;
                }

                if (DefenseScore<=HitScore)
                {
                        return 1;
                }
                else
                {
                        return 0;//A Miss
                }
    }
Exemplo n.º 5
0
        public void UnitTestTestTest()
        {
            var p = new WeaponMelee();

            Assert.AreEqual(1, p.UnitTestTest());
        }
Exemplo n.º 6
0
    /// <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;
        }
        }
    }
Exemplo n.º 7
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 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.objInt().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.objInt().GetImpactPoint(), npc.objInt().GetHitFrameStart(), npc.objInt().GetHitFrameEnd());
            Impact.SpawnHitImpact(Impact.ImpactBlood(), npc.objInt().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);
        }
    }