public void ExecuteAttack() { float weaponRange = 1.0f; Ray ray = new Ray(this.transform.position, player.transform.position - this.transform.position); RaycastHit hit = new RaycastHit(); if (Physics.Raycast(ray, out hit, weaponRange)) { if (hit.transform.Equals(this.transform)) { Debug.Log("you've hit yourself ? " + hit.transform.name); } else { if (hit.transform.name == "Gronk") { MusicController.LastAttackCounter = 30.0f; //Thirty more seconds of combat music UWCharacter playerUW = hit.transform.GetComponent <UWCharacter>(); playerUW.ApplyDamage(5); } } } //else //{ // Debug.Log ("MISS"); //} }
/// <summary> /// NPC hits player /// </summary> /// <param name="playerUW">Player U.</param> /// <param name="npc">Npc.</param> public static void NPC_Hits_PC(UWCharacter playerUW, NPC npc) { int PlayerDefence = 0; if (playerUW.PlayerCombat.currWeapon != null) { PlayerDefence = playerUW.PlayerSkills.GetSkill(Skills.SkillDefense) + (playerUW.PlayerSkills.GetSkill(playerUW.PlayerCombat.currWeapon.GetSkill() + 1) / 2); } else { PlayerDefence = playerUW.PlayerSkills.GetSkill(Skills.SkillDefense) + (playerUW.PlayerSkills.GetSkill(Skills.SkillUnarmed) / 2); } int toHit = Mathf.Max(PlayerDefence - npc.GetAttack(), 0); int roll = Random.Range(-1, 31); if ((_RES == GAME_UW1) && (npc.objInt().item_id == 124)) { roll = 30; //Slasher will always hit. } int BaseDamage = npc.GetDamage(); //get the damage of the current attack if (((roll >= toHit) || (roll >= 30)) && (roll > -1)) { int PlayerArmourScore = playerUW.playerInventory.getArmourScore(); int ReducedDamage = Mathf.Max(1, BaseDamage - PlayerArmourScore); //Hit playerUW.ApplyDamage(Random.Range(1, ReducedDamage + 1), npc.gameObject); //reduce damage by protection if (BaseDamage > PlayerArmourScore) { //apply equipment damage to a random piece of armour playerUW.playerInventory.ApplyArmourDamage((short)Random.Range(0, npc.GetArmourDamage() + 1)); } if (npc.PoisonLevel() > 0) { //roll for poisoning. if (!UWCharacter.Instance.isPoisonResistant()) { //Player has resistence against poisoning int PoisonRoll = Random.Range(1, 30); if (PoisonRoll < npc.PoisonLevel()) { int PoisonToAdd = Random.Range(1, npc.PoisonLevel() + 1); int newPlayPoison = (short)Mathf.Min(playerUW.play_poison + PoisonToAdd, 15); UWCharacter.Instance.play_poison = (short)newPlayPoison; if (UWCharacter.Instance.poison_timer == 0) { UWCharacter.Instance.poison_timer = 30f; } } } } MusicController.LastAttackCounter = 10.0f; //Ten more seconds of combat music if (ObjectInteraction.PlaySoundEffects) { UWCharacter.Instance.aud.clip = GameWorldController.instance.getMus().SoundEffects[MusicController.SOUND_EFFECT_MELEE_HIT_1]; UWCharacter.Instance.aud.Play(); } } }
/// <summary> /// NPC hits player /// </summary> /// <param name="playerUW">Player U.</param> /// <param name="npc">Npc.</param> public static void NPC_Hits_PC(UWCharacter playerUW, NPC npc) { int flankingbonus = 0; flankingbonus = CalcFlankingBonus(npc.objInt().heading, playerUW.currentHeading); int attackScore = npc.CurrentAttackScore + (npc.EquipDamage >> 1) + Random.Range(0, 5) + 7 + flankingbonus; //+Maybe Npc Level //Player defence //defence skill + sum of all armour+(skill with current weapon >>1) + unknownbonus(stored in critterdata) int DefenderScore = playerUW.PlayerSkills.GetSkill(Skills.SkillDefense) + playerUW.playerInventory.ArmourProtection; if (playerUW.PlayerCombat.currWeapon != null) { DefenderScore += (playerUW.PlayerSkills.GetSkill(playerUW.PlayerCombat.currWeapon.GetSkill()) >> 1); } else { DefenderScore += (playerUW.PlayerSkills.GetSkill(Skills.SkillUnarmed) >> 1); } Skills.SkillRollResult rollresult = Skills.SkillRoll(attackScore, DefenderScore); if ((_RES == GAME_UW1) && (npc.item_id == 124) && (rollresult == Skills.SkillRollResult.CriticalFailure || rollresult == Skills.SkillRollResult.Failure)) { rollresult = Skills.SkillRollResult.Success;//Slasher of veils will always hit. } short Damage = 0; Damage = (short)(npc.CurrentAttackDamage + (npc.Strength / 5)); Damage = (short)Mathf.Max(Damage, 2); int baseDamage = Damage; bool CriticalHit = RollForCritDamage(ref Damage, rollresult); // 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))); //TODO: damage for NPCS is scaled based on a lookup table and a property in their mobile data. This is similar to the player attack charge. (values stored in segment_60 in UW2 exe) //Lookup appears to be based on the value in the object at 0xF ( bits 12 to 15) //For now just scale it randomly Damage = (short)Random.Range(2, Damage + 1); switch (rollresult) { case Skills.SkillRollResult.CriticalSuccess: case Skills.SkillRollResult.Success: { Debug.Log("Base Damage = " + (short)(baseDamage) + " Final Damage = " + Damage); playerUW.ApplyDamage(Damage, npc.gameObject); //TODO: restore equipment damage and poisoning. //Ten more seconds of combat music MusicController.LastAttackCounter = 10.0f; if (ObjectInteraction.PlaySoundEffects) { UWCharacter.Instance.aud.clip = MusicController.instance.SoundEffects[MusicController.SOUND_EFFECT_MELEE_HIT_1]; UWCharacter.Instance.aud.Play(); } break; } case Skills.SkillRollResult.Failure: case Skills.SkillRollResult.CriticalFailure: //a miss. break; } //////// int PlayerDefence = 0; //////// if (playerUW.PlayerCombat.currWeapon != null) //////// { //////// PlayerDefence = playerUW.PlayerSkills.GetSkill(Skills.SkillDefense) + (playerUW.PlayerSkills.GetSkill(playerUW.PlayerCombat.currWeapon.GetSkill() + 1) / 2); //////// } //////// else //////// { //////// PlayerDefence = playerUW.PlayerSkills.GetSkill(Skills.SkillDefense) + (playerUW.PlayerSkills.GetSkill(Skills.SkillUnarmed) / 2); //////// } //////// int toHit = Mathf.Max(PlayerDefence - npc.Dexterity, 0); //////// int roll = Random.Range(-1, 31); //////// if ((_RES == GAME_UW1) && (npc.item_id == 124)) //////// { //////// roll = 30;//Slasher will always hit. //////// } //////// int BaseDamage = npc.CurrentAttackDamage;//get the damage of the current attack //////// if (((roll >= toHit) || (roll >= 30)) && (roll > -1)) //////// { //////// int PlayerArmourScore = playerUW.playerInventory.getArmourScore(); //////// int ReducedDamage = Mathf.Max(1, BaseDamage - PlayerArmourScore); //////// //Hit //////// playerUW.ApplyDamage(Random.Range(1, ReducedDamage + 1), npc.gameObject); //////// //reduce damage by protection //////// if (BaseDamage > PlayerArmourScore) //////// { //////// //apply equipment damage to a random piece of armour //////// playerUW.playerInventory.ApplyArmourDamage((short)Random.Range(0, npc.ArmourDamage + 1)); //////// } //////// if (npc.PoisonLevel() > 0) //////// {//roll for poisoning. //////// if (!UWCharacter.Instance.isPoisonResistant()) //////// {//Player has resistence against poisoning //////// int PoisonRoll = Random.Range(1, 30); //////// if (PoisonRoll < npc.PoisonLevel()) //////// { //////// int PoisonToAdd = Random.Range(1, npc.PoisonLevel() + 1); //////// int newPlayPoison = (short)Mathf.Min(playerUW.play_poison + PoisonToAdd, 15); //////// UWCharacter.Instance.play_poison = (short)newPlayPoison; //////// if (UWCharacter.Instance.poison_timer == 0) //////// { //////// UWCharacter.Instance.poison_timer = 30f; //////// } //////// } //////// } //////// } //////// MusicController.LastAttackCounter = 10.0f; //Ten more seconds of combat music //////// if (ObjectInteraction.PlaySoundEffects) //////// { //////// UWCharacter.Instance.aud.clip = MusicController.instance.SoundEffects[MusicController.SOUND_EFFECT_MELEE_HIT_1]; //////// UWCharacter.Instance.aud.Play(); //////// } //////// } }