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"); //} }
public void Begin() { if (_RES == GAME_SHOCK) { return; } GRLoader bodies = new GRLoader(GRLoader.BODIES_GR); Blank = Resources.Load <Texture2D>(_RES + "/Sprites/Texture_Blank"); //atTopLevel=true; playerUW = this.GetComponent <UWCharacter>(); playerContainer = this.GetComponent <Container>(); for (int i = 0; i < 8; i++) { //bBackPack[i] = true; setBackPack(i, null); } UWHUD.instance.Encumberance.text = getEncumberance().ToString(); if (playerUW.isFemale) { //UWHUD.instance.playerBody.texture =(Texture2D)Resources.Load(_RES +"/Hud/Bodies/bodies_" + (5+playerUW.Body).ToString("0000")); UWHUD.instance.playerBody.texture = bodies.LoadImageAt(5 + playerUW.Body); } else { //UWHUD.instance.playerBody.texture =(Texture2D)Resources.Load(_RES +"/Hud/Bodies/bodies_" + (playerUW.Body).ToString("0000")); UWHUD.instance.playerBody.texture = bodies.LoadImageAt(playerUW.Body); } Ready = true; Refresh(); }
public virtual void start() { if (playerUW == null) { playerUW = GameObject.Find("Gronk").GetComponent <UWCharacter>(); } }
/// <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(); } } }
/* * 0181 a_teleport trap * teleports the player to another level and tile; destination level is * given by "zpos" (0 means current level), tile x/y coordinates * are given in "quality" and "owner" fields. */ public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State) { if (_RES == GAME_UWDEMO) { if (zpos != 0) { ExecuteForUWDemo(); return; } //Special case for the UW Demo. } if (EditorMode) { return; } if ((_RES == GAME_UW2) && (UWCharacter.Instance.JustTeleported)) { //To stop infinite level transitions in UW2 //UWCharacter.Instance.JustTeleported=false; return; } float targetX = (float)quality * 1.2f + 0.6f; float targetY = (float)owner * 1.2f + 0.6f; //Heading //0=north //1=northeast //2=east and so on UWCharacter.Instance.transform.eulerAngles = new Vector3(0f, ((float)heading * 45f), 0f); UWCharacter.Instance.playerCam.transform.localRotation = Quaternion.identity; UWCharacter.Instance.JustTeleported = true; UWCharacter.Instance.teleportedTimer = 0f; if (zpos == 0) { //Stay on this level. float Height = ((float)(CurrentTileMap().GetFloorHeight(quality, owner))) * 0.15f; UWCharacter.Instance.transform.position = new Vector3(targetX, Height + 0.5f, targetY); UWCharacter.Instance.TeleportPosition = UWCharacter.Instance.transform.position; } else { UWCharacter.Instance.teleportedTimer = -1f; //Longer wait period when travelling between levels. //Goto to another level if (_RES == GAME_UW1) { //Special case for the magic drain effect in UW1 UWCharacter.ResetTrueMana(); } UWCharacter.Instance.playerMotor.movement.velocity = Vector3.zero; if ((xpos & 0x1) == 1) {//Teleport above ground and drop down into level GameWorldController.instance.SwitchLevel((short)(zpos - 1), quality, owner, 24); } else { GameWorldController.instance.SwitchLevel((short)(zpos - 1), quality, owner); } } }
void PostAnimPlay() { //Code to call at the end of some animations. switch (SetAnimation.ToLower()) { case "death_with_sapling": //Player will resurrect, case "cs402.n01": { SetAnimation = "Anim_Base"; //Clears out the animation. PrevAnimation = "x"; UWCharacter.ResurrectPlayer(); break; } case "death": //PLayer is dying and will not resurrect. case "cs403.n01": SetAnimation = "cs403.n02"; break; case "death_final": //Player has finally died. case "cs403.n02": SetAnimation = "Anim_Base"; GameWorldController.instance.AtMainMenu = true; //Clear out game objects foreach (Transform child in GameWorldController.instance.LevelModel.transform) { GameObject.Destroy(child.gameObject); } foreach (Transform child in GameWorldController.instance.DynamicObjectMarker()) { GameObject.Destroy(child.gameObject); } foreach (Transform child in GameWorldController.instance.SceneryModel.transform) { GameObject.Destroy(child.gameObject); } for (int x = 0; x <= GameWorldController.instance.Tilemaps.GetUpperBound(0); x++) { GameWorldController.instance.Tilemaps[x] = null; } for (int x = 0; x <= GameWorldController.instance.objectList.GetUpperBound(0); x++) { GameWorldController.instance.objectList[x] = null; } MainMenuHud.instance.gameObject.SetActive(true); MainMenuHud.instance.MenuMode = 0; MainMenuHud.instance.OpScr.SetActive(true); MainMenuHud.instance.CharGen.SetActive(false); MainMenuHud.instance.ButtonClickMainMenu(4); //reset menu GameWorldController.instance.LevelNo = -1; WindowDetectUW.SwitchFromMouseLook(); break; default: UWCharacter.Instance.playerCam.cullingMask = HudAnimation.NormalCullingMask; SetAnimation = "Anim_Base"; break; } }
public int ContainerOffset = 0; //For scrolling the inventory. // Use this for initialization void Start() { Blank = Resources.Load <Texture2D> ("Sprites/Texture_Blank"); atTopLevel = true; playerUW = this.GetComponent <UWCharacter>(); playerContainer = this.GetComponent <Container>(); for (int i = 0; i < 8; i++) { bBackPack[i] = true; } playerUW.playerHud.Encumberance.text = Mathf.Round(getEncumberance()).ToString(); }
static void RestoreHealthMana(UWCharacter sunshine) { sunshine.CurVIT += Random.Range(1, 40); if (sunshine.CurVIT > sunshine.MaxVIT) { sunshine.CurVIT = sunshine.MaxVIT; } sunshine.PlayerMagic.CurMana += Random.Range(1, 40); if (sunshine.PlayerMagic.CurMana > sunshine.PlayerMagic.MaxMana) { sunshine.PlayerMagic.CurMana = sunshine.PlayerMagic.MaxMana; } }
protected virtual void Start() { if (playerUW == null) { playerUW = GameObject.Find("Gronk").GetComponent <UWCharacter>(); } if (ml == null) { ml = playerUW.playerHud.MessageScroll; } //if (mi==null) //{ // mi = playerUW.playerHud.InputControl; //} CheckReferences(); }
/* * 0181 a_teleport trap * teleports the player to another level and tile; destination level is * given by "zpos" (0 means current level), tile x/y coordinates * are given in "quality" and "owner" fields. */ //public int levelNo; //public float targetX; //public float targetY; //public float targetZ; public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State) { if (_RES == GAME_UWDEMO) { if (objInt().zpos != 0) { ExecuteForUWDemo(); return; } //Special case for the UW Demo. } //Debug.Log (this.name); if (EditorMode) { return; } if ((_RES == GAME_UW2) && (UWCharacter.Instance.JustTeleported)) { //To stop infinite level transitions in UW2 //UWCharacter.Instance.JustTeleported=false; return; } float targetX = (float)objInt().quality *1.2f + 0.6f; float targetY = (float)objInt().owner *1.2f + 0.6f; UWCharacter.Instance.JustTeleported = true; UWCharacter.Instance.teleportedTimer = 0f; if (objInt().zpos == 0) { //Stay on this level. float Height = ((float)(GameWorldController.instance.currentTileMap().GetFloorHeight(objInt().quality, objInt().owner))) * 0.15f; UWCharacter.Instance.transform.position = new Vector3(targetX, Height + 0.3f, targetY); UWCharacter.Instance.TeleportPosition = UWCharacter.Instance.transform.position; } else { UWCharacter.Instance.teleportedTimer = -1f; //Longer wait period when travelling between levels. //Goto to another level if (_RES == GAME_UW1) { //Special case for the magic drain effect in UW1 UWCharacter.ResetTrueMana(); } UWCharacter.Instance.playerMotor.movement.velocity = Vector3.zero; GameWorldController.instance.SwitchLevel((short)(objInt().zpos - 1), objInt().quality, objInt().owner); } }
void Update() { if (playerUW == null) { playerUW = GameObject.Find("Gronk").GetComponent <UWCharacter>(); } if (uiText == null) { uiText = this.gameObject.GetComponent <UITexture>(); } if ((PreviousCharge != playerUW.PlayerCombat.Charge) || (playerUW.PlayerCombat.AttackCharging == true)) { PreviousCharge = playerUW.PlayerCombat.Charge; int index = (int)playerUW.PlayerCombat.Charge / 10; if (index == 10) { if (!IsInvoking("UpdateMaxCharge")) { InvokeRepeating("UpdateMaxCharge", 0.0f, 0.1f); } } else { if (index != PreviousIndex) { RepeatCounter = 0; uiText.mainTexture = Resources.Load <Texture2D> ("HUD/Power/Power_" + index.ToString("0000")); CurrentPower = "HUD/Power/Power_" + index.ToString("0000"); } } } else { if (IsInvoking("UpdateMaxCharge")) { CancelInvoke("UpdateMaxCharge"); uiText.mainTexture = Resources.Load <Texture2D> ("HUD/Power/Power_" + 0.ToString("0000")); } RepeatCounter = 0; } }
/// <summary> /// Checks if the player can cast the spell. /// </summary> /// <returns><c>true</c>, if spell cast was tested, <c>false</c> otherwise.</returns> /// <param name="casterUW">The player character casting the spell</param> /// <param name="Rune1">Rune1.</param> /// <param name="Rune2">Rune2.</param> /// <param name="Rune3">Rune3.</param> /// Tests their spell casting level /// Tests their mana level /// Tests their casting level (for failurs and backfires) public bool TestSpellCast(UWCharacter casterUW, int Rune1, int Rune2, int Rune3) { int TestSpellLevel=0; string MagicWords=TranslateSpellRune(Rune1,Rune2,Rune3); switch (MagicWords) { case "An An An": TestSpellLevel=1; break; //1st Circle case "In Mani Ylem"://Create Food case "In Lor": //Light case "Ort Jux"://Magic Arrow case "Bet In Sanct"://Resist Blows case "Sanct Hur"://Stealth TestSpellLevel=1; break; //2nd Circle case "Quas Corp"://Cause Fear case "Wis Mani"://Detect Monster case "Uus Por"://Jump case "In Bet Mani"://Lesser Heal case "Rel Des Por"://Slow Fall case "In Sanct"://Thick Skin case "In Jux"://Rune of Warding TestSpellLevel=2; break; //3rd Circle case "Bet Sanct Lor"://Conceal case "Ort Grav"://Lightning case "Quas Lor"://Night Vision case "Rel Tym Por"://Speed case "Ylem Por"://Water Walk case "Sanct Jux"://Strengten Door TestSpellLevel=3; break; //4th Circle case "An Sanct"://Curse case "Sanct Flam":// Flameproof case "In Mani"://Heal case "Hur Por"://Levitate case "Nox Ylem"://Poison case "An Jux"://Remove Trap TestSpellLevel=4; break; //5th Circle case "Por Flam"://Fireball case "Grav Sanct Por"://Missile Protection case "Ort Wis Ylem"://Name Enchantment case "Ex Ylem"://Open case "An Nox"://Cure Poison case "An Corp Mani"://Smite Undead TestSpellLevel=5; break; //6th Circle case "Vas In Lor"://Daylight case "Vas Rel Por"://Gate Travel case "Vas In Mani"://Greater Heal case "An Ex Por"://Paralyze case "Vas Ort Grav"://Sheet Lightning case "Ort Por Ylem"://Telekinesis TestSpellLevel=6; break; //7th Circle case "In Mani Rel"://Ally case "Vas An Wis"://Confusion case "Vas Sanct Lor"://Invisibility case "Vas Hur Por"://Fly case "Kal Mani"://Monster Summoning case "Ort An Quas"://Reveal TestSpellLevel=7; break; //8th Circle case "Vas Kal Corp"://Armageddon case "Flam Hur"://Flame Wind case "An Tym":// Freeze Time case "In Vas Sanct"://Iron Flesh case "Ort Por Wis"://Roaming sight case "Vas Por Ylem"://Tremor TestSpellLevel=8; break; default: { UWHUD.instance.MessageScroll.Add ("Not a spell."); return false; } }//magicwords if (Mathf.Round(casterUW.CharLevel/2)<TestSpellLevel) {//Not experienced enough UWHUD.instance.MessageScroll.Add (StringController.instance.GetString (1,210)); return false; } else if (CurMana< TestSpellLevel*3) {//Mana test UWHUD.instance.MessageScroll.Add (StringController.instance.GetString (1,211)); return false; } else if( ! casterUW.PlayerSkills.TrySkill(Skills.SkillCasting, TestSpellLevel)) {//Skill test. Random chance to backfire if (Random.Range(1,10)<8) {//TODO:decide on the chances //000~001~213~Casting was not successful. UWHUD.instance.MessageScroll.Add (StringController.instance.GetString (1,213)); } else {//000~001~214~The spell backfires. UWHUD.instance.MessageScroll.Add (StringController.instance.GetString (1,214)); casterUW.CurVIT = casterUW.CurVIT-3; } return false; } else {//Casting sucessful. UWHUD.instance.MessageScroll.Add ("Casting " + MagicWords); return true; } }
// Use this for initialization void Start() { Blank = Resources.Load <Texture2D> (_RES +"/Sprites/Texture_Blank"); atTopLevel=true; playerUW=this.GetComponent<UWCharacter>(); playerContainer =this.GetComponent<Container>(); for (int i =0;i<8;i++) { bBackPack[i]=true; } UWHUD.instance.Encumberance.text=Mathf.Round(getEncumberance()).ToString(); if (playerUW.isFemale) { UWHUD.instance.playerBody.texture =(Texture2D)Resources.Load(_RES +"/Hud/Bodies/bodies_" + (5+playerUW.Body).ToString("0000")); } else { UWHUD.instance.playerBody.texture =(Texture2D)Resources.Load(_RES +"/Hud/Bodies/bodies_" + (playerUW.Body).ToString("0000")); } Refresh(); }
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 } }
public void Awake() { Instance=this; //DontDestroyOnLoad(this); }
public static void WakeUp(UWCharacter sunshine) { //Todo: Test the quality of the sleep and check for monster interuption. RestoreHealthMana(sunshine); UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1, 18)); }
/// <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(); //////// } //////// } }
public void Awake() { Instance = this; //DontDestroyOnLoad(this); }
public static void WakeUp(UWCharacter sunshine) { //Todo: Test the quality of the sleep and check for monster interuption. RestoreHealthMana(sunshine); UWHUD.instance.MessageScroll.Add(StringController.instance.GetString (1,18)); }
static void RestoreHealthMana(UWCharacter sunshine) { sunshine.CurVIT += Random.Range(1,40); if (sunshine.CurVIT>sunshine.MaxVIT) { sunshine.CurVIT=sunshine.MaxVIT; } sunshine.PlayerMagic.CurMana += Random.Range(1,40); if (sunshine.PlayerMagic.CurMana>sunshine.PlayerMagic.MaxMana) { sunshine.PlayerMagic.CurMana=sunshine.PlayerMagic.MaxMana; } }
public override void Start() { base.Start(); playerUW = GameObject.Find("Gronk").GetComponent <UWCharacter>(); }
/// <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; } } }
//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); } }