public string ValidateArguments(NWPlayer user, params string[] args) { bool isEnabled = user.GetLocalInt("DISPLAY_DISCORD") == TRUE; if (!isEnabled) { return("You have disabled the Discord chat channel. You can't send messages to it while disabled."); } if (args.Length <= 0 || args[0].Length <= 0) { return("Please enter in a message to send to Discord."); } return(string.Empty); }
public void OnModuleItemEquipped() { using (new Profiler("SkillService::OnModuleItemEquipped()")) { NWPlayer oPC = _.GetPCItemLastEquippedBy(); if (!oPC.IsInitializedAsPlayer) { return; // Players who log in for the first time don't have an ID yet. } if (oPC.GetLocalInt("LOGGED_IN_ONCE") <= 0) { return; // Don't fire heavy calculations if this is the player's first log in after a restart. } NWItem oItem = _.GetPCItemLastEquipped(); _playerStat.ApplyStatChanges(oPC, null); ApplyWeaponPenalties(oPC, oItem); ApplyEquipmentPenalties(oPC, oItem); } }
public void OnHitCastSpell(NWPlayer oPC) { NWObject oTarget = NWObject.Wrap(_.GetSpellTargetObject()); int activeWeaponSkillID = oPC.GetLocalInt("ACTIVE_WEAPON_SKILL"); if (activeWeaponSkillID <= 0) { return; } Data.Entities.Perk entity = _db.Perks.Single(x => x.PerkID == activeWeaponSkillID); IPerk perk = App.ResolveByInterface <IPerk>("Perk." + entity.JavaScriptName); perk?.OnImpact(oPC, oTarget); oPC.DeleteLocalString("ACTIVE_WEAPON_SKILL_UUID"); oPC.DeleteLocalInt("ACTIVE_WEAPON_SKILL"); }
public void OnModuleChat() { NWPlayer sender = (_.GetPCChatSpeaker()); if (sender.GetLocalInt("LISTENING_FOR_DESCRIPTION") != 1) { return; } if (!sender.IsPlayer) { return; } string text = _.GetPCChatMessage().Trim(); sender.SetLocalString("NEW_DESCRIPTION_TO_SET", text); _.SetPCChatMessage(string.Empty); // Skip the message _.SendMessageToPC(sender.Object, "New description received. Please press the 'Next' button in the conversation window."); }
private static void OnModuleUnequipItem() { NWPlayer oPC = (_.GetPCItemLastUnequippedBy()); if (oPC.GetLocalInt("IS_CUSTOMIZING_ITEM") == _.TRUE) { return; // Don't run heavy code when customizing equipment. } NWItem oItem = (_.GetPCItemLastUnequipped()); if (!oPC.IsPlayer) { return; } var executionPerks = GetPCPerksByExecutionType(oPC, PerkExecutionType.EquipmentBased); foreach (PCPerk pcPerk in executionPerks) { var handler = GetPerkHandler(pcPerk.PerkID); handler.OnItemUnequipped(oPC, oItem); } }
private static void OnModuleClientEnter() { NWPlayer oPC = (_.GetEnteringObject()); if (!oPC.IsPlayer) { return; } if (oPC.GetLocalInt("MAP_PINS_LOADED") == 1) { return; } List <PCMapPin> pins = DataService.Where <PCMapPin>(x => x.PlayerID == oPC.GlobalID).ToList(); foreach (PCMapPin pin in pins) { NWArea area = (_.GetObjectByTag(pin.AreaTag)); SetMapPin(oPC, pin.NoteText, (float)pin.PositionX, (float)pin.PositionY, area); } oPC.SetLocalInt("MAP_PINS_LOADED", 1); }
public void DoAction(NWPlayer user, NWObject target, NWLocation targetLocation, params string[] args) { if (!user.IsPlayer) { return; } //Checks if the player has Plasma Cell if (!_.GetHasFeat(Feat.PlasmaCell, user)) { user.SendMessage(ColorTokenService.Red("You do not have the perk: Plasma Cell.")); return; } //Checks if the player has toggled plasma cell off if (user.GetLocalBool("PLASMA_CELL_TOGGLE_OFF") == false) { user.SetLocalInt("PLASMA_CELL_TOGGLE_OFF", 1); user.SendMessage(ColorTokenService.Red("Plasma Cell is now toggled off.")); return; } //Checks if plasma cell has been toggled off else if (user.GetLocalInt("PLASMA_CELL_TOGGLE_OFF") > 0) { user.DeleteLocalInt("PLASMA_CELL_TOGGLE_OFF"); user.SendMessage(ColorTokenService.Green("Plasma Cell is now toggled on!")); return; } //If the above aren't working, this should appear and debugging required else { user.SendMessage(ColorTokenService.Red("Something's wrong, contact a code contributor!")); return; } }
private static void OnModuleUnequipItem() { NWPlayer player = (_.GetPCItemLastUnequippedBy()); if (player.GetLocalInt("IS_CUSTOMIZING_ITEM") == _.TRUE) { return; // Don't run heavy code when customizing equipment. } if (!player.IsPlayer) { return; } NWItem item = (_.GetPCItemLastUnequipped()); if (item.BaseItemType != _.BASE_ITEM_HELMET) { return; } Player pc = DataService.Player.GetByID(player.GlobalID); _.SetHiddenWhenEquipped(item.Object, !pc.DisplayHelmet == false ? 0 : 1); }
private static void OnModuleEquipItem() { NWPlayer oPC = (_.GetPCItemLastEquippedBy()); // Don't run heavy code when customizing equipment. if (oPC.GetLocalInt("IS_CUSTOMIZING_ITEM") == _.TRUE) { return; } NWItem oItem = (_.GetPCItemLastEquipped()); float durability = GetDurability(oItem); if (durability <= 0 && durability != -1 && oItem.IsValid) { oPC.AssignCommand(() => { _.ClearAllActions(); _.ActionUnequipItem(oItem.Object); }); oPC.FloatingText(ColorTokenService.Red("That item is broken and must be repaired before you can use it.")); } }
public void OnHitCastSpell(NWPlayer oPC) { NWObject oTarget = _.GetSpellTargetObject(); HandleGrenadeProficiency(oPC, oTarget); HandlePlasmaCellPerk(oPC, oTarget); int activeWeaponSkillID = oPC.GetLocalInt("ACTIVE_WEAPON_SKILL"); if (activeWeaponSkillID <= 0) { return; } PCPerk entity = _data.GetAll <PCPerk>().Single(x => x.PlayerID == oPC.GlobalID && x.PerkID == activeWeaponSkillID); var perk = _data.Get <Data.Entity.Perk>(entity.PerkID); App.ResolveByInterface <IPerk>("Perk." + perk.ScriptName, (script) => { if (script.CanCastSpell(oPC, oTarget)) { script.OnImpact(oPC, oTarget, entity.PerkLevel); if (oTarget.IsNPC) { ApplyEnmity(oPC, oTarget.Object, perk); } } else { oPC.SendMessage(script.CannotCastSpellMessage(oPC, oTarget) ?? "That ability cannot be used at this time."); } oPC.DeleteLocalString("ACTIVE_WEAPON_SKILL_UUID"); oPC.DeleteLocalInt("ACTIVE_WEAPON_SKILL"); }); }
private static void OnModuleUseFeat() { NWPlayer pc = Object.OBJECT_SELF; NWCreature target = NWNXEvents.OnFeatUsed_GetTarget().Object; int featID = NWNXEvents.OnFeatUsed_GetFeatID(); var perkFeat = DataService.SingleOrDefault <PerkFeat>(x => x.FeatID == featID); if (perkFeat == null) { return; } Data.Entity.Perk perk = DataService.GetAll <Data.Entity.Perk>().SingleOrDefault(x => x.ID == perkFeat.PerkID); if (perk == null) { return; } // Check to see if we are a spaceship. Spaceships can't use abilities... if (pc.GetLocalInt("IS_SHIP") > 0 || pc.GetLocalInt("IS_GUNNER") > 0) { pc.SendMessage("You cannot use that ability while piloting a ship."); return; } var perkAction = PerkService.GetPerkHandler(perkFeat.PerkID); Player playerEntity = DataService.Get <Player>(pc.GlobalID); int pcPerkLevel = PerkService.GetPCPerkLevel(pc, perk.ID); // If player is disabling an existing stance, remove that effect. if (perk.ExecutionTypeID == (int)PerkExecutionType.Stance) { PCCustomEffect stanceEffect = DataService.SingleOrDefault <PCCustomEffect>(x => x.StancePerkID == perk.ID && x.PlayerID == pc.GlobalID); if (stanceEffect != null) { if (CustomEffectService.RemoveStance(pc)) { return; } } } if (pcPerkLevel <= 0) { pc.SendMessage("You do not meet the prerequisites to use this ability."); return; } if (perkAction.IsHostile() && target.IsPlayer) { if (!PVPSanctuaryService.IsPVPAttackAllowed(pc, target.Object)) { return; } } if (pc.Area.Resref != target.Area.Resref || _.LineOfSightObject(pc.Object, target.Object) == 0) { pc.SendMessage("You cannot see your target."); return; } if (!perkAction.CanCastSpell(pc, target)) { pc.SendMessage(perkAction.CannotCastSpellMessage(pc, target) ?? "That ability cannot be used at this time."); return; } int fpCost = perkAction.FPCost(pc, perkAction.FPCost(pc, perk.BaseFPCost, featID), featID); if (playerEntity.CurrentFP < fpCost) { pc.SendMessage("You do not have enough FP. (Required: " + fpCost + ". You have: " + playerEntity.CurrentFP + ")"); return; } if (pc.IsBusy || pc.CurrentHP <= 0) { pc.SendMessage("You are too busy to activate that ability."); return; } // Check cooldown int? cooldownCategoryID = perkAction.CooldownCategoryID(pc, perk.CooldownCategoryID, featID); PCCooldown pcCooldown = DataService.GetAll <PCCooldown>().SingleOrDefault(x => x.PlayerID == pc.GlobalID && x.CooldownCategoryID == cooldownCategoryID); if (pcCooldown == null) { pcCooldown = new PCCooldown { CooldownCategoryID = Convert.ToInt32(cooldownCategoryID), DateUnlocked = DateTime.UtcNow.AddSeconds(-1), PlayerID = pc.GlobalID }; DataService.SubmitDataChange(pcCooldown, DatabaseActionType.Insert); } DateTime unlockDateTime = pcCooldown.DateUnlocked; DateTime now = DateTime.UtcNow; if (unlockDateTime > now) { string timeToWait = TimeService.GetTimeToWaitLongIntervals(now, unlockDateTime, false); pc.SendMessage("That ability can be used in " + timeToWait + "."); return; } // Force Abilities (aka Spells) if (perk.ExecutionTypeID == (int)PerkExecutionType.ForceAbility) { target.SetLocalInt(LAST_ATTACK + pc.GlobalID, ATTACK_FORCE); ActivateAbility(pc, target, perk, perkAction, pcPerkLevel, PerkExecutionType.ForceAbility, featID); } // Combat Abilities else if (perk.ExecutionTypeID == (int)PerkExecutionType.CombatAbility) { target.SetLocalInt(LAST_ATTACK + pc.GlobalID, ATTACK_PHYSICAL); ActivateAbility(pc, target, perk, perkAction, pcPerkLevel, PerkExecutionType.CombatAbility, featID); } // Queued Weapon Skills else if (perk.ExecutionTypeID == (int)PerkExecutionType.QueuedWeaponSkill) { target.SetLocalInt(LAST_ATTACK + pc.GlobalID, ATTACK_PHYSICAL); HandleQueueWeaponSkill(pc, perk, perkAction, featID); } // Stances else if (perk.ExecutionTypeID == (int)PerkExecutionType.Stance) { target.SetLocalInt(LAST_ATTACK + pc.GlobalID, ATTACK_COMBATABILITY); ActivateAbility(pc, target, perk, perkAction, pcPerkLevel, PerkExecutionType.Stance, featID); } }
public bool Run(params object[] args) { int nodeType = (int)args[0]; int nodeID = (int)args[1]; NWPlayer player = NWPlayer.Wrap(_.GetPCSpeaker()); PlayerDialog dialog = _dialog.LoadPlayerDialog(player.GlobalID); DialogPage page = dialog.CurrentPage; int currentSelectionNumber = nodeID + 1; bool displayNode = false; string newNodeText = string.Empty; int dialogOffset = (_dialog.NumberOfResponsesPerPage + 1) * (dialog.DialogNumber - 1); if (currentSelectionNumber == _dialog.NumberOfResponsesPerPage + 1) // Next page { int displayCount = page.NumberOfResponses - (_dialog.NumberOfResponsesPerPage * dialog.PageOffset); if (displayCount > _dialog.NumberOfResponsesPerPage) { displayNode = true; } } else if (currentSelectionNumber == _dialog.NumberOfResponsesPerPage + 2) // Previous Page { if (dialog.PageOffset > 0) { displayNode = true; } } else if (nodeType == 2) { int responseID = (dialog.PageOffset * _dialog.NumberOfResponsesPerPage) + nodeID; if (responseID + 1 <= page.NumberOfResponses) { DialogResponse response = page.Responses[responseID]; if (response != null) { newNodeText = response.Text; displayNode = response.IsActive; } } } else if (nodeType == 1) { IConversation convo = App.ResolveByInterface <IConversation>("Conversation." + dialog.ActiveDialogName); if (player.GetLocalInt("DIALOG_SYSTEM_INITIALIZE_RAN") != 1) { convo.Initialize(); player.SetLocalInt("DIALOG_SYSTEM_INITIALIZE_RAN", 1); } if (dialog.IsEnding) { convo.EndDialog(); _dialog.RemovePlayerDialog(player.GlobalID); player.DeleteLocalInt("DIALOG_SYSTEM_INITIALIZE_RAN"); return(false); } page = dialog.CurrentPage; newNodeText = page.Header; _.SetCustomToken(90000 + dialogOffset, newNodeText); return(true); } _.SetCustomToken(90001 + nodeID + dialogOffset, newNodeText); return(displayNode); }
public static string TranslateSnippetForListener(NWObject speaker, NWObject listener, SkillType language, string snippet) { Dictionary <SkillType, Type> map = new Dictionary <SkillType, Type> { { SkillType.Bothese, typeof(TranslatorBothese) }, { SkillType.Catharese, typeof(TranslatorCatharese) }, { SkillType.Cheunh, typeof(TranslatorCheunh) }, { SkillType.Dosh, typeof(TranslatorDosh) }, { SkillType.Droidspeak, typeof(TranslatorDroidspeak) }, { SkillType.Huttese, typeof(TranslatorHuttese) }, { SkillType.Mandoa, typeof(TranslatorMandoa) }, { SkillType.Shyriiwook, typeof(TranslatorShyriiwook) }, { SkillType.Twileki, typeof(TranslatorTwileki) }, { SkillType.Zabraki, typeof(TranslatorZabraki) }, { SkillType.Mirialan, typeof(TranslatorMirialan) }, { SkillType.MonCalamarian, typeof(TranslatorMonCalamarian) }, { SkillType.Ugnaught, typeof(TranslatorUgnaught) } }; Type type = typeof(TranslatorGeneric); map.TryGetValue(language, out type); ITranslator translator = (ITranslator)Activator.CreateInstance(type); if (speaker.IsPC && !speaker.IsDM) { // Get the rank and max rank for the speaker, and garble their English text based on it. NWPlayer speakerAsPlayer = speaker.Object; int speakerSkillRank = SkillService.GetPCSkillRank(speakerAsPlayer, language); int speakerSkillMaxRank = SkillService.GetSkill(language).MaxRank; if (speakerSkillRank != speakerSkillMaxRank) { int garbledChance = 100 - (int)(((float)speakerSkillRank / (float)speakerSkillMaxRank) * 100); string[] split = snippet.Split(' '); for (int i = 0; i < split.Length; ++i) { if (RandomService.Random(100) <= garbledChance) { split[i] = new string(split[i].ToCharArray().OrderBy(s => (RandomService.Random(2) % 2) == 0).ToArray()); } } snippet = split.Aggregate((a, b) => a + " " + b); } } if (!listener.IsPC || listener.IsDM) { // Short circuit for a DM or NPC - they will always understand the text. return(snippet); } // Let's grab the max rank for the listener skill, and then we roll for a successful translate based on that. NWPlayer listenerAsPlayer = listener.Object; int rank = SkillService.GetPCSkillRank(listenerAsPlayer, language); int maxRank = SkillService.GetSkill(language).MaxRank; // Check for the Comprehend Speech concentration ability. Player dbPlayer = DataService.Player.GetByID(listenerAsPlayer.GlobalID); bool grantSenseXP = false; if (dbPlayer.ActiveConcentrationPerkID == (int)PerkType.ComprehendSpeech) { int bonus = 5 * dbPlayer.ActiveConcentrationTier; rank += bonus; grantSenseXP = true; } // Ensure we don't go over the maximum. if (rank > maxRank) { rank = maxRank; } if (rank == maxRank || speaker == listener) { // Guaranteed success - return original. return(snippet); } string textAsForeignLanguage = translator.Translate(snippet); if (rank != 0) { int englishChance = (int)(((float)rank / (float)maxRank) * 100); string[] originalSplit = snippet.Split(' '); string[] foreignSplit = textAsForeignLanguage.Split(' '); StringBuilder endResult = new StringBuilder(); // WARNING: We're making the assumption that originalSplit.Length == foreignSplit.Length. // If this assumption changes, the below logic needs to change too. for (int i = 0; i < originalSplit.Length; ++i) { if (RandomService.Random(100) <= englishChance) { endResult.Append(originalSplit[i]); } else { endResult.Append(foreignSplit[i]); } endResult.Append(" "); } textAsForeignLanguage = endResult.ToString(); } long now = DateTime.Now.Ticks; int lastSkillUpLow = listenerAsPlayer.GetLocalInt("LAST_LANGUAGE_SKILL_INCREASE_LOW"); int lastSkillUpHigh = listenerAsPlayer.GetLocalInt("LAST_LANGUAGE_SKILL_INCREASE_HIGH"); long lastSkillUp = lastSkillUpHigh; lastSkillUp = (lastSkillUp << 32) | (uint)lastSkillUpLow; long differenceInSeconds = (now - lastSkillUp) / 10000000; if (differenceInSeconds / 60 >= 2) { int amount = Math.Max(10, Math.Min(150, snippet.Length) / 3); // Reward exp towards the language - we scale this with character count, maxing at 50 exp for 150 characters. SkillService.GiveSkillXP(listenerAsPlayer, language, amount); // Grant Sense XP if player is concentrating Comprehend Speech. if (grantSenseXP) { SkillService.GiveSkillXP(listenerAsPlayer, SkillType.ForceSense, amount * 10); } listenerAsPlayer.SetLocalInt("LAST_LANGUAGE_SKILL_INCREASE_LOW", (int)(now & 0xFFFFFFFF)); listenerAsPlayer.SetLocalInt("LAST_LANGUAGE_SKILL_INCREASE_HIGH", (int)((now >> 32) & 0xFFFFFFFF)); } return(textAsForeignLanguage); }
public static void HandlePlasmaCellPerk(NWPlayer player, NWObject target) { if (!player.IsPlayer) { return; } if (_.GetHasFeat((int)CustomFeatType.PlasmaCell, player) == FALSE) { return; // Check if player has the perk } if (player.RightHand.CustomItemType != CustomItemType.BlasterPistol && player.RightHand.CustomItemType != CustomItemType.BlasterRifle) { return; // Check if player has the right weapons } if (target.GetLocalInt("TRANQUILIZER_EFFECT_FIRST_RUN") == _.TRUE) { return; // Check if Tranquilizer is on to avoid conflict } if (player.GetLocalInt("PLASMA_CELL_TOGGLE_OFF") == _.TRUE) { return; // Check if Plasma Cell toggle is on or off } if (target.GetLocalInt("TRANQUILIZER_EFFECT_FIRST_RUN") == _.TRUE) { return; } int perkLevel = PerkService.GetCreaturePerkLevel(player, PerkType.PlasmaCell); int chance; CustomEffectType[] damageTypes; switch (perkLevel) { case 1: chance = 10; damageTypes = new[] { CustomEffectType.FireCell }; break; case 2: chance = 10; damageTypes = new[] { CustomEffectType.FireCell, CustomEffectType.ElectricCell }; break; case 3: chance = 20; damageTypes = new[] { CustomEffectType.FireCell, CustomEffectType.ElectricCell }; break; case 4: chance = 20; damageTypes = new[] { CustomEffectType.FireCell, CustomEffectType.ElectricCell, CustomEffectType.SonicCell }; break; case 5: chance = 30; damageTypes = new[] { CustomEffectType.FireCell, CustomEffectType.ElectricCell, CustomEffectType.SonicCell }; break; case 6: chance = 30; damageTypes = new[] { CustomEffectType.FireCell, CustomEffectType.ElectricCell, CustomEffectType.SonicCell, CustomEffectType.AcidCell }; break; case 7: chance = 40; damageTypes = new[] { CustomEffectType.FireCell, CustomEffectType.ElectricCell, CustomEffectType.SonicCell, CustomEffectType.AcidCell }; break; case 8: chance = 40; damageTypes = new[] { CustomEffectType.FireCell, CustomEffectType.ElectricCell, CustomEffectType.SonicCell, CustomEffectType.AcidCell, CustomEffectType.IceCell }; break; case 9: chance = 50; damageTypes = new[] { CustomEffectType.FireCell, CustomEffectType.ElectricCell, CustomEffectType.SonicCell, CustomEffectType.AcidCell, CustomEffectType.IceCell }; break; case 10: chance = 50; damageTypes = new[] { CustomEffectType.FireCell, CustomEffectType.ElectricCell, CustomEffectType.SonicCell, CustomEffectType.AcidCell, CustomEffectType.IceCell, CustomEffectType.DivineCell }; break; default: return; } foreach (var effect in damageTypes) { if (RandomService.D100(1) <= chance) { CustomEffectService.ApplyCustomEffect(player, target.Object, effect, RandomService.D6(1), perkLevel, null); } } }
public bool Run(params object[] args) { NWPlaceable resource = NWPlaceable.Wrap(Object.OBJECT_SELF); NWPlayer oPC = NWPlayer.Wrap(_.GetLastDamager(resource.Object)); if (oPC.GetLocalInt("NOT_USING_CORRECT_WEAPON") == 1) { oPC.DeleteLocalInt("NOT_USING_CORRECT_WEAPON"); return(true); } PlayerCharacter pcEntity = _db.PlayerCharacters.Single(x => x.PlayerID == oPC.GlobalID); NWItem oWeapon = NWItem.Wrap(_.GetLastWeaponUsed(oPC.Object)); Location location = oPC.Location; string resourceItemResref = resource.GetLocalString("RESOURCE_RESREF"); int activityID = resource.GetLocalInt("RESOURCE_ACTIVITY"); string resourceName = resource.GetLocalString("RESOURCE_NAME"); int resourceCount = resource.GetLocalInt("RESOURCE_COUNT"); int difficultyRating = resource.GetLocalInt("RESOURCE_DIFFICULTY_RATING"); int weaponChanceBonus; SkillType skillType; int perkChanceBonus; int secondResourceChance; int durabilityChanceReduction = 0; int hasteChance; int lucky = _perk.GetPCPerkLevel(oPC, PerkType.Lucky) + oPC.EffectiveLuckBonus; bool hasBaggerPerk; if (activityID == 1) // 1 = Logging { weaponChanceBonus = oWeapon.LoggingBonus; if (weaponChanceBonus > 0) { weaponChanceBonus += _perk.GetPCPerkLevel(oPC, PerkType.LoggingAxeExpert) * 5; durabilityChanceReduction = _perk.GetPCPerkLevel(oPC, PerkType.LoggingAxeExpert) * 10 + lucky; } skillType = SkillType.Logging; perkChanceBonus = _perk.GetPCPerkLevel(oPC, PerkType.Lumberjack) * 5 + lucky; secondResourceChance = _perk.GetPCPerkLevel(oPC, PerkType.PrecisionLogging) * 10; hasteChance = _perk.GetPCPerkLevel(oPC, PerkType.SpeedyLogger) * 10 + lucky; if (pcEntity.BackgroundID == (int)BackgroundType.Lumberjack) { hasteChance += 10; } hasBaggerPerk = _perk.GetPCPerkLevel(oPC, PerkType.WoodBagger) > 0; } else if (activityID == 2) // Mining { weaponChanceBonus = oWeapon.MiningBonus; if (weaponChanceBonus > 0) { weaponChanceBonus += _perk.GetPCPerkLevel(oPC, PerkType.PickaxeExpert) * 5; durabilityChanceReduction = _perk.GetPCPerkLevel(oPC, PerkType.PickaxeExpert) * 10 + lucky; } skillType = SkillType.Mining; perkChanceBonus = _perk.GetPCPerkLevel(oPC, PerkType.Miner) * 5 + lucky; secondResourceChance = _perk.GetPCPerkLevel(oPC, PerkType.PrecisionMining) * 10; hasteChance = _perk.GetPCPerkLevel(oPC, PerkType.SpeedyMiner) * 10 + lucky; if (pcEntity.BackgroundID == (int)BackgroundType.Miner) { hasteChance += 10; } hasBaggerPerk = _perk.GetPCPerkLevel(oPC, PerkType.OreBagger) > 0; } else { return(false); } PCSkill skill = _skill.GetPCSkillByID(oPC.GlobalID, (int)skillType); int durabilityLossChance = 100 - durabilityChanceReduction; if (_random.Random(100) <= durabilityLossChance) { _durability.RunItemDecay(oPC, oWeapon); } int baseChance = 10; int chance = baseChance + weaponChanceBonus; chance += CalculateSuccessChanceDeltaModifier(difficultyRating, skill.Rank); chance += perkChanceBonus; bool givePityItem = false; if (chance > 0) { if (_random.Random(100) + 1 <= hasteChance) { _.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, _.EffectHaste(), oPC.Object, 8.0f); } // Give an item if the player hasn't gotten anything after 6-8 attempts. int attemptFailureCount = oPC.GetLocalInt("RESOURCE_ATTEMPT_FAILURE_COUNT") + 1; NWObject failureResource = NWObject.Wrap(oPC.GetLocalObject("RESOURCE_ATTEMPT_FAILURE_OBJECT")); if (!failureResource.IsValid || !Equals(failureResource, resource)) { failureResource = resource; attemptFailureCount = 1; } int pityItemChance = 0; if (attemptFailureCount == 6) { pityItemChance = 60; } else if (attemptFailureCount == 7) { pityItemChance = 80; } else if (attemptFailureCount >= 8) { pityItemChance = 100; } if (_random.Random(100) + 1 <= pityItemChance) { givePityItem = true; attemptFailureCount = 0; } oPC.SetLocalInt("RESOURCE_ATTEMPT_FAILURE_COUNT", attemptFailureCount); oPC.SetLocalObject("RESOURCE_ATTEMPT_FAILURE_OBJECT", failureResource.Object); } if (chance <= 0) { oPC.FloatingText("You do not have enough skill to harvest this resource..."); } else if (_random.Random(100) <= chance || givePityItem) { if (hasBaggerPerk) { _.CreateItemOnObject(resourceItemResref, oPC.Object); } else { _.CreateObject(OBJECT_TYPE_ITEM, resourceItemResref, location); } oPC.FloatingText("You break off some " + resourceName + "."); resource.SetLocalInt("RESOURCE_COUNT", --resourceCount); _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(10000), resource.Object); if (_random.Random(100) + 1 <= secondResourceChance) { oPC.FloatingText("You break off a second piece."); if (hasBaggerPerk) { _.CreateItemOnObject(resourceItemResref, oPC.Object); } else { _.CreateObject(OBJECT_TYPE_ITEM, resourceItemResref, location); } } float deltaModifier = CalculateXPDeltaModifier(difficultyRating, skill.Rank); float baseXP = (100 + _random.Random(20)) * deltaModifier; int xp = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(baseXP, oWeapon.RecommendedLevel, skill.Rank); _skill.GiveSkillXP(oPC, skillType, xp); oPC.DeleteLocalInt("RESOURCE_ATTEMPT_FAILURE_COUNT"); oPC.DeleteLocalObject("RESOURCE_ATTEMPT_FAILURE_OBJECT"); } if (resourceCount <= 0) { SpawnSeed(resource, oPC); NWObject prop = NWObject.Wrap(resource.GetLocalObject("RESOURCE_PROP_OBJ")); if (prop.IsValid) { prop.Destroy(); } resource.Destroy(); } return(true); }
private void CastSpell(NWPlayer pc, NWObject target, Data.Entities.Perk entity, IPerk perk, CooldownCategory cooldown) { string spellUUID = Guid.NewGuid().ToString(); int itemBonus = pc.CastingSpeed; float baseCastingTime = perk.CastingTime(pc, (float)entity.BaseCastingTime); float castingTime = baseCastingTime; // Casting Bonus % - Shorten casting time. if (itemBonus < 0) { float castingPercentageBonus = Math.Abs(itemBonus) * 0.01f; castingTime = castingTime - (castingTime * castingPercentageBonus); } // Casting Penalty % - Increase casting time. else if (itemBonus > 0) { float castingPercentageBonus = Math.Abs(itemBonus) * 0.01f; castingTime = castingTime + (castingTime * castingPercentageBonus); } if (castingTime < 0.5f) { castingTime = 0.5f; } // Heavy armor increases casting time by 2x the base casting time if (pc.Chest.CustomItemType == CustomItemType.HeavyArmor) { castingTime = baseCastingTime * 2; } if (_.GetActionMode(pc.Object, ACTION_MODE_STEALTH) == 1) { _.SetActionMode(pc.Object, ACTION_MODE_STEALTH, 0); } _.ClearAllActions(); _biowarePosition.TurnToFaceObject(target, pc); _.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, _.EffectVisualEffect(VFX_DUR_ELEMENTAL_SHIELD), pc.Object, castingTime + 0.2f); float animationTime = castingTime; pc.AssignCommand(() => _.ActionPlayAnimation(ANIMATION_LOOPING_CONJURE1, 1.0f, animationTime - 0.1f)); pc.IsBusy = true; CheckForSpellInterruption(pc, spellUUID, pc.Position); pc.SetLocalInt(spellUUID, SPELL_STATUS_STARTED); _nwnxPlayer.StartGuiTimingBar(pc, (int)castingTime, ""); pc.DelayCommand(() => { if (pc.GetLocalInt(spellUUID) == SPELL_STATUS_INTERRUPTED || // Moved during casting pc.CurrentHP < 0 || pc.IsDead) // Or is dead/dying { pc.DeleteLocalInt(spellUUID); pc.SendMessage("Your spell has been interrupted."); return; } pc.DeleteLocalInt(spellUUID); if ((PerkExecutionType)entity.ExecutionTypeID == PerkExecutionType.Spell || (PerkExecutionType)entity.ExecutionTypeID == PerkExecutionType.CombatAbility) { perk.OnImpact(pc, target); } else { HandleQueueWeaponSkill(pc, entity, perk); } // Adjust mana only if spell cost > 0 PlayerCharacter pcEntity = _db.PlayerCharacters.Single(x => x.PlayerID == pc.GlobalID); if (perk.ManaCost(pc, entity.BaseManaCost) > 0) { pcEntity.CurrentMana = pcEntity.CurrentMana - perk.ManaCost(pc, entity.BaseManaCost); _db.SaveChanges(); pc.SendMessage(_color.Custom("Mana: " + pcEntity.CurrentMana + " / " + pcEntity.MaxMana, 32, 223, 219)); } if (_random.Random(100) + 1 <= 3) { _food.DecreaseHungerLevel(pc, 1); } // Mark cooldown on category ApplyCooldown(pc, cooldown, perk); pc.IsBusy = false; }, castingTime + 0.5f); }
private static void OnModuleEquipItem() { int[] validItemTypes = { BASE_ITEM_ARMOR, BASE_ITEM_ARROW, BASE_ITEM_BASTARDSWORD, BASE_ITEM_BATTLEAXE, BASE_ITEM_BELT, BASE_ITEM_BOLT, BASE_ITEM_BOOTS, BASE_ITEM_BRACER, BASE_ITEM_BULLET, BASE_ITEM_CLOAK, BASE_ITEM_CLUB, BASE_ITEM_DAGGER, BASE_ITEM_DART, BASE_ITEM_DIREMACE, BASE_ITEM_DOUBLEAXE, BASE_ITEM_DWARVENWARAXE, BASE_ITEM_GLOVES, BASE_ITEM_GREATAXE, BASE_ITEM_GREATSWORD, BASE_ITEM_GRENADE, BASE_ITEM_HALBERD, BASE_ITEM_HANDAXE, BASE_ITEM_HEAVYCROSSBOW, BASE_ITEM_HEAVYFLAIL, BASE_ITEM_HELMET, BASE_ITEM_KAMA, BASE_ITEM_KATANA, BASE_ITEM_KUKRI, BASE_ITEM_LARGESHIELD, BASE_ITEM_LIGHTCROSSBOW, BASE_ITEM_LIGHTFLAIL, BASE_ITEM_LIGHTHAMMER, BASE_ITEM_LIGHTMACE, BASE_ITEM_LONGBOW, BASE_ITEM_LONGSWORD, BASE_ITEM_MORNINGSTAR, BASE_ITEM_QUARTERSTAFF, BASE_ITEM_RAPIER, BASE_ITEM_SCIMITAR, BASE_ITEM_SCYTHE, BASE_ITEM_SHORTBOW, BASE_ITEM_SHORTSPEAR, BASE_ITEM_SHORTSWORD, BASE_ITEM_SHURIKEN, BASE_ITEM_SICKLE, BASE_ITEM_SLING, BASE_ITEM_SMALLSHIELD, BASE_ITEM_THROWINGAXE, BASE_ITEM_TOWERSHIELD, BASE_ITEM_TRIDENT, BASE_ITEM_TWOBLADEDSWORD, BASE_ITEM_WARHAMMER, BASE_ITEM_WHIP, CustomBaseItemType.Saberstaff, CustomBaseItemType.Lightsaber }; NWPlayer player = _.GetPCItemLastEquippedBy(); if (player.GetLocalInt("IS_CUSTOMIZING_ITEM") == _.TRUE) { return; // Don't run heavy code when customizing equipment. } NWItem oItem = (_.GetPCItemLastEquipped()); int baseItemType = oItem.BaseItemType; Effect eEffect = _.EffectVisualEffect(579); eEffect = _.TagEffect(eEffect, "LIGHTSABER_HUM"); // Handle lightsaber sounds if (oItem.CustomItemType == CustomItemType.Lightsaber || oItem.CustomItemType == CustomItemType.Saberstaff) { _.ApplyEffectToObject(DURATION_TYPE_PERMANENT, eEffect, player); player.AssignCommand(() => { _.PlaySound("saberon"); }); } if (!validItemTypes.Contains(baseItemType)) { HandleEquipmentSwappingDelay(); return; } AddOnHitProperty(oItem); // Check ammo every time if (player.Arrows.IsValid) { AddOnHitProperty(player.Arrows); player.Arrows.RecommendedLevel = oItem.RecommendedLevel; } if (player.Bolts.IsValid) { AddOnHitProperty(player.Bolts); player.Bolts.RecommendedLevel = oItem.RecommendedLevel; } if (player.Bullets.IsValid) { AddOnHitProperty(player.Bullets); player.Bullets.RecommendedLevel = oItem.RecommendedLevel; } if (baseItemType == BASE_ITEM_TORCH) { int charges = oItem.ReduceCharges(); if (charges <= 0) { oItem.Destroy(); } } HandleEquipmentSwappingDelay(); }
public static bool OnAppearsWhen(int nodeType, int nodeID) { NWPlayer player = (_.GetPCSpeaker()); bool hasDialog = HasPlayerDialog(player.GlobalID); if (!hasDialog) { return(false); } PlayerDialog dialog = LoadPlayerDialog(player.GlobalID); using (new Profiler(nameof(DialogService) + "." + nameof(OnAppearsWhen) + "." + dialog.ActiveDialogName)) { DialogPage page = dialog.CurrentPage; var convo = GetConversation(dialog.ActiveDialogName); int currentSelectionNumber = nodeID + 1; bool displayNode = false; string newNodeText = string.Empty; int dialogOffset = (NumberOfResponsesPerPage + 1) * (dialog.DialogNumber - 1); if (currentSelectionNumber == NumberOfResponsesPerPage + 1) // Next page { int displayCount = page.NumberOfResponses - (NumberOfResponsesPerPage * dialog.PageOffset); if (displayCount > NumberOfResponsesPerPage) { displayNode = true; } } else if (currentSelectionNumber == NumberOfResponsesPerPage + 2) // Previous Page { if (dialog.PageOffset > 0) { displayNode = true; } } else if (currentSelectionNumber == NumberOfResponsesPerPage + 3) // Back { if (dialog.NavigationStack.Count > 0 && dialog.EnableBackButton) { displayNode = true; } } else if (nodeType == 2) { int responseID = (dialog.PageOffset * NumberOfResponsesPerPage) + nodeID; if (responseID + 1 <= page.NumberOfResponses) { DialogResponse response = page.Responses[responseID]; if (response != null) { newNodeText = response.Text; displayNode = response.IsActive; } } } else if (nodeType == 1) { if (player.GetLocalInt("DIALOG_SYSTEM_INITIALIZE_RAN") != 1) { convo.Initialize(); player.SetLocalInt("DIALOG_SYSTEM_INITIALIZE_RAN", 1); } if (dialog.IsEnding) { convo.EndDialog(); RemovePlayerDialog(player.GlobalID); player.DeleteLocalInt("DIALOG_SYSTEM_INITIALIZE_RAN"); return(false); } page = dialog.CurrentPage; newNodeText = page.Header; _.SetCustomToken(90000 + dialogOffset, newNodeText); return(true); } _.SetCustomToken(90001 + nodeID + dialogOffset, newNodeText); return(displayNode); } }
private static void OnHitCastSpell() { NWPlayer oPC = _.OBJECT_SELF; if (!oPC.IsValid) { return; } NWObject oTarget = _.GetSpellTargetObject(); NWItem oItem = _.GetSpellCastItem(); // If this method was triggered by our own armor (from getting hit), return. if (oItem.BaseItemType == BaseItem.Armor) { return; } // Flag this attack as physical so that the damage scripts treat it properly. LoggingService.Trace(TraceComponent.LastAttack, "Setting attack type from " + oPC.GlobalID + " against " + _.GetName(oTarget) + " to physical (" + ATTACK_PHYSICAL.ToString() + ")"); oTarget.SetLocalInt(LAST_ATTACK + oPC.GlobalID, ATTACK_PHYSICAL); HandleGrenadeProficiency(oPC, oTarget); HandlePlasmaCellPerk(oPC, oTarget); int activeWeaponSkillID = oPC.GetLocalInt("ACTIVE_WEAPON_SKILL"); if (activeWeaponSkillID <= 0) { return; } int activeWeaponSkillFeatID = oPC.GetLocalInt("ACTIVE_WEAPON_SKILL_FEAT_ID"); if (activeWeaponSkillFeatID < 0) { activeWeaponSkillFeatID = -1; } PCPerk entity = DataService.PCPerk.GetByPlayerAndPerkID(oPC.GlobalID, activeWeaponSkillID); var perk = DataService.Perk.GetByID(entity.PerkID); var perkFeat = DataService.PerkFeat.GetByFeatID(activeWeaponSkillFeatID); var handler = PerkService.GetPerkHandler(activeWeaponSkillID); string canCast = handler.CanCastSpell(oPC, oTarget, perkFeat.PerkLevelUnlocked); if (string.IsNullOrWhiteSpace(canCast)) { handler.OnImpact(oPC, oTarget, entity.PerkLevel, perkFeat.PerkLevelUnlocked); if (oTarget.IsNPC) { ApplyEnmity(oPC, oTarget.Object, perk); } } else { oPC.SendMessage(canCast); } oPC.DeleteLocalString("ACTIVE_WEAPON_SKILL_UUID"); oPC.DeleteLocalInt("ACTIVE_WEAPON_SKILL"); oPC.DeleteLocalInt("ACTIVE_WEAPON_SKILL_FEAT_ID"); }
public bool Run(params object[] args) { using (new Profiler(nameof(FinishAbilityUse))) { NWPlayer pc = (NWPlayer)args[0]; string spellUUID = Convert.ToString(args[1]); int perkID = (int)args[2]; NWObject target = (NWObject)args[3]; int pcPerkLevel = (int)args[4]; int featID = (int)args[5]; Data.Entity.Perk entity = DataService.Single <Data.Entity.Perk>(x => x.ID == perkID); PerkExecutionType executionType = (PerkExecutionType)entity.ExecutionTypeID; IPerkHandler perk = PerkService.GetPerkHandler(perkID); int?cooldownID = perk.CooldownCategoryID(pc, entity.CooldownCategoryID, featID); CooldownCategory cooldown = cooldownID == null ? null : DataService.SingleOrDefault <CooldownCategory>(x => x.ID == cooldownID); if (pc.GetLocalInt(spellUUID) == (int)SpellStatusType.Interrupted || // Moved during casting pc.CurrentHP < 0 || pc.IsDead) // Or is dead/dying { pc.DeleteLocalInt(spellUUID); return(false); } pc.DeleteLocalInt(spellUUID); if (executionType == PerkExecutionType.ForceAbility || executionType == PerkExecutionType.CombatAbility || executionType == PerkExecutionType.Stance) { perk.OnImpact(pc, target, pcPerkLevel, featID); if (entity.CastAnimationID != null && entity.CastAnimationID > 0) { pc.AssignCommand(() => { _.ActionPlayAnimation((int)entity.CastAnimationID, 1f, 1f); }); } if (target.IsNPC) { AbilityService.ApplyEnmity(pc, (target.Object), entity); } } else if (executionType == PerkExecutionType.QueuedWeaponSkill) { AbilityService.HandleQueueWeaponSkill(pc, entity, perk, featID); } // Adjust FP only if spell cost > 0 Data.Entity.Player pcEntity = DataService.Single <Data.Entity.Player>(x => x.ID == pc.GlobalID); int fpCost = perk.FPCost(pc, entity.BaseFPCost, featID); if (fpCost > 0) { pcEntity.CurrentFP = pcEntity.CurrentFP - fpCost; DataService.SubmitDataChange(pcEntity, DatabaseActionType.Update); pc.SendMessage(ColorTokenService.Custom("FP: " + pcEntity.CurrentFP + " / " + pcEntity.MaxFP, 32, 223, 219)); } bool hasChainspell = CustomEffectService.DoesPCHaveCustomEffect(pc, CustomEffectType.Chainspell) && executionType == PerkExecutionType.ForceAbility; if (!hasChainspell && cooldown != null) { // Mark cooldown on category AbilityService.ApplyCooldown(pc, cooldown, perk, featID); } pc.IsBusy = false; pc.SetLocalInt(spellUUID, (int)SpellStatusType.Completed); return(true); } }
public static void ApplyStatChanges(NWPlayer player, NWItem ignoreItem, bool isInitialization = false) { if (!player.IsPlayer) { return; } if (!player.IsInitializedAsPlayer) { return; } if (player.GetLocalInt("IS_SHIP") == 1) { return; } // Don't fire for ammo as it reapplies bonuses **just** removed from blasters. if (ignoreItem != null && (ignoreItem.BaseItemType == BASE_ITEM_BOLT || ignoreItem.BaseItemType == BASE_ITEM_ARROW || ignoreItem.BaseItemType == BASE_ITEM_BULLET)) { return; } Player pcEntity = DataService.Get <Player>(player.GlobalID); List <PCSkill> skills = DataService.Where <PCSkill>(x => x.PlayerID == player.GlobalID && x.Rank > 0).ToList(); EffectiveItemStats itemBonuses = GetPlayerItemEffectiveStats(player, ignoreItem); float strBonus = 0.0f; float dexBonus = 0.0f; float conBonus = 0.0f; float intBonus = 0.0f; float wisBonus = 0.0f; float chaBonus = 0.0f; using (new Profiler("PlayerStatService::ApplyStatChanges::AttributeApplication")) { foreach (PCSkill pcSkill in skills) { Skill skill = DataService.Get <Skill>(pcSkill.SkillID); CustomAttribute primary = (CustomAttribute)skill.Primary; CustomAttribute secondary = (CustomAttribute)skill.Secondary; CustomAttribute tertiary = (CustomAttribute)skill.Tertiary; // Primary Bonuses if (primary == CustomAttribute.STR) { strBonus += PrimaryIncrease * pcSkill.Rank; } else if (primary == CustomAttribute.DEX) { dexBonus += PrimaryIncrease * pcSkill.Rank; } else if (primary == CustomAttribute.CON) { conBonus += PrimaryIncrease * pcSkill.Rank; } else if (primary == CustomAttribute.INT) { intBonus += PrimaryIncrease * pcSkill.Rank; } else if (primary == CustomAttribute.WIS) { wisBonus += PrimaryIncrease * pcSkill.Rank; } else if (primary == CustomAttribute.CHA) { chaBonus += PrimaryIncrease * pcSkill.Rank; } // Secondary Bonuses if (secondary == CustomAttribute.STR) { strBonus += SecondaryIncrease * pcSkill.Rank; } else if (secondary == CustomAttribute.DEX) { dexBonus += SecondaryIncrease * pcSkill.Rank; } else if (secondary == CustomAttribute.CON) { conBonus += SecondaryIncrease * pcSkill.Rank; } else if (secondary == CustomAttribute.INT) { intBonus += SecondaryIncrease * pcSkill.Rank; } else if (secondary == CustomAttribute.WIS) { wisBonus += SecondaryIncrease * pcSkill.Rank; } else if (secondary == CustomAttribute.CHA) { chaBonus += SecondaryIncrease * pcSkill.Rank; } // Tertiary Bonuses if (tertiary == CustomAttribute.STR) { strBonus += TertiaryIncrease * pcSkill.Rank; } else if (tertiary == CustomAttribute.DEX) { dexBonus += TertiaryIncrease * pcSkill.Rank; } else if (tertiary == CustomAttribute.CON) { conBonus += TertiaryIncrease * pcSkill.Rank; } else if (tertiary == CustomAttribute.INT) { intBonus += TertiaryIncrease * pcSkill.Rank; } else if (tertiary == CustomAttribute.WIS) { wisBonus += TertiaryIncrease * pcSkill.Rank; } else if (tertiary == CustomAttribute.CHA) { chaBonus += TertiaryIncrease * pcSkill.Rank; } } } // Check caps. if (strBonus > MaxAttributeBonus) { strBonus = MaxAttributeBonus; } if (dexBonus > MaxAttributeBonus) { dexBonus = MaxAttributeBonus; } if (conBonus > MaxAttributeBonus) { conBonus = MaxAttributeBonus; } if (intBonus > MaxAttributeBonus) { intBonus = MaxAttributeBonus; } if (wisBonus > MaxAttributeBonus) { wisBonus = MaxAttributeBonus; } if (chaBonus > MaxAttributeBonus) { chaBonus = MaxAttributeBonus; } // Apply item bonuses strBonus += itemBonuses.Strength; dexBonus += itemBonuses.Dexterity; conBonus += itemBonuses.Constitution; wisBonus += itemBonuses.Wisdom; intBonus += itemBonuses.Intelligence; chaBonus += itemBonuses.Charisma; // Check final caps if (strBonus > 100) { strBonus = 100; } if (dexBonus > 100) { dexBonus = 100; } if (conBonus > 100) { conBonus = 100; } if (intBonus > 100) { intBonus = 100; } if (wisBonus > 100) { wisBonus = 100; } if (chaBonus > 100) { chaBonus = 100; } // Apply attributes NWNXCreature.SetRawAbilityScore(player, ABILITY_STRENGTH, (int)strBonus + pcEntity.STRBase); NWNXCreature.SetRawAbilityScore(player, ABILITY_DEXTERITY, (int)dexBonus + pcEntity.DEXBase); NWNXCreature.SetRawAbilityScore(player, ABILITY_CONSTITUTION, (int)conBonus + pcEntity.CONBase); NWNXCreature.SetRawAbilityScore(player, ABILITY_INTELLIGENCE, (int)intBonus + pcEntity.INTBase); NWNXCreature.SetRawAbilityScore(player, ABILITY_WISDOM, (int)wisBonus + pcEntity.WISBase); NWNXCreature.SetRawAbilityScore(player, ABILITY_CHARISMA, (int)chaBonus + pcEntity.CHABase); // Apply AC using (new Profiler("PlayerStatService::ApplyStatChanges::CalcAC")) { int ac = EffectiveArmorClass(itemBonuses, player); NWNXCreature.SetBaseAC(player, ac); } // Apply BAB using (new Profiler("PlayerStatService::ApplyStatChanges::CalcBAB")) { int bab = CalculateBAB(player, ignoreItem, itemBonuses); NWNXCreature.SetBaseAttackBonus(player, bab); } // Apply HP using (new Profiler("PlayerStatService::ApplyStatChanges::CalcHP")) { int hp = EffectiveMaxHitPoints(player, itemBonuses); for (int level = 1; level <= 5; level++) { hp--; NWNXCreature.SetMaxHitPointsByLevel(player, level, 1); } for (int level = 1; level <= 5; level++) { if (hp > 255) // Levels can only contain a max of 255 HP { NWNXCreature.SetMaxHitPointsByLevel(player, level, 255); hp = hp - 254; } else // Remaining value gets set to the level. (<255 hp) { NWNXCreature.SetMaxHitPointsByLevel(player, level, hp + 1); break; } } } if (player.CurrentHP > player.MaxHP) { int amount = player.CurrentHP - player.MaxHP; Effect damage = _.EffectDamage(amount); _.ApplyEffectToObject(DURATION_TYPE_INSTANT, damage, player.Object); } // Apply FP using (new Profiler("PlayerStatService::ApplyStatChanges::CalcFP")) { pcEntity.MaxFP = EffectiveMaxFP(player, itemBonuses); if (isInitialization) { pcEntity.CurrentFP = pcEntity.MaxFP; } DataService.SubmitDataChange(pcEntity, DatabaseActionType.Update); } }
public static int GetCallAttempt(NWPlayer player) { return(player.GetLocalInt("HOLOCOM_CALL_ATTEMPT")); }
public static void SaveLocation(NWPlayer player) { if (!player.IsPlayer) { return; } if (player.GetLocalInt("IS_SHIP") == 1) { return; } if (player.GetLocalInt("IS_GUNNER") == 1) { return; } NWArea area = player.Area; if (area.IsValid && area.Tag != "ooc_area" && area.Tag != "tutorial" && !area.IsInstance) { LoggingService.Trace(TraceComponent.Space, "Saving location in area " + GetName(area)); Player entity = GetPlayerEntity(player.GlobalID); entity.LocationAreaResref = area.Resref; entity.LocationX = player.Position.X; entity.LocationY = player.Position.Y; entity.LocationZ = player.Position.Z; entity.LocationOrientation = (player.Facing); entity.LocationInstanceID = null; if (string.IsNullOrWhiteSpace(entity.RespawnAreaResref)) { NWObject waypoint = GetWaypointByTag("DTH_DEFAULT_RESPAWN_POINT"); entity.RespawnAreaResref = waypoint.Area.Resref; entity.RespawnLocationOrientation = waypoint.Facing; entity.RespawnLocationX = waypoint.Position.X; entity.RespawnLocationY = waypoint.Position.Y; entity.RespawnLocationZ = waypoint.Position.Z; } DataService.SubmitDataChange(entity, DatabaseActionType.Update); } else if (area.IsInstance) { LoggingService.Trace(TraceComponent.Space, "Saving location in instance area " + GetName(area)); string instanceID = area.GetLocalString("PC_BASE_STRUCTURE_ID"); if (string.IsNullOrWhiteSpace(instanceID)) { instanceID = area.GetLocalString("PC_BASE_ID"); } LoggingService.Trace(TraceComponent.Space, "Saving character in instance ID: " + instanceID); if (!string.IsNullOrWhiteSpace(instanceID)) { Player entity = GetPlayerEntity(player.GlobalID); entity.LocationAreaResref = area.Resref; entity.LocationX = player.Position.X; entity.LocationY = player.Position.Y; entity.LocationZ = player.Position.Z; entity.LocationOrientation = (player.Facing); entity.LocationInstanceID = new Guid(instanceID); DataService.SubmitDataChange(entity, DatabaseActionType.Update); } } }
public bool Run(params object[] args) { NWPlayer pc = (NWPlayer)args[0]; string spellUUID = Convert.ToString(args[1]); int perkID = (int)args[2]; NWObject target = (NWObject)args[3]; int pcPerkLevel = (int)args[4]; Data.Entity.Perk entity = _data.Single <Data.Entity.Perk>(x => x.ID == perkID); CooldownCategory cooldown = _data.SingleOrDefault <CooldownCategory>(x => x.ID == entity.CooldownCategoryID); PerkExecutionType executionType = (PerkExecutionType)entity.ExecutionTypeID; return(App.ResolveByInterface <IPerk, bool>("Perk." + entity.ScriptName, perk => { if (pc.GetLocalInt(spellUUID) == (int)SpellStatusType.Interrupted || // Moved during casting pc.CurrentHP < 0 || pc.IsDead) // Or is dead/dying { pc.DeleteLocalInt(spellUUID); return false; } pc.DeleteLocalInt(spellUUID); if (executionType == PerkExecutionType.ForceAbility || executionType == PerkExecutionType.CombatAbility || executionType == PerkExecutionType.Stance) { perk.OnImpact(pc, target, pcPerkLevel); if (entity.CastAnimationID != null && entity.CastAnimationID > 0) { pc.AssignCommand(() => { _.ActionPlayAnimation((int)entity.CastAnimationID, 1f, 1f); }); } if (target.IsNPC) { _ability.ApplyEnmity(pc, (target.Object), entity); } } else if (executionType == PerkExecutionType.QueuedWeaponSkill) { _ability.HandleQueueWeaponSkill(pc, entity, perk); } // Adjust FP only if spell cost > 0 Data.Entity.Player pcEntity = _data.Single <Data.Entity.Player>(x => x.ID == pc.GlobalID); if (perk.FPCost(pc, entity.BaseFPCost) > 0) { pcEntity.CurrentFP = pcEntity.CurrentFP - perk.FPCost(pc, entity.BaseFPCost); _data.SubmitDataChange(pcEntity, DatabaseActionType.Update); pc.SendMessage(_color.Custom("FP: " + pcEntity.CurrentFP + " / " + pcEntity.MaxFP, 32, 223, 219)); } bool hasChainspell = _customEffect.DoesPCHaveCustomEffect(pc, CustomEffectType.Chainspell) && executionType == PerkExecutionType.ForceAbility; if (!hasChainspell) { // Mark cooldown on category _ability.ApplyCooldown(pc, cooldown, perk); } pc.IsBusy = false; pc.SetLocalInt(spellUUID, (int)SpellStatusType.Completed); return true; })); }
public static int GetNumberOfMapPins(NWPlayer oPC) { return(oPC.GetLocalInt("NW_TOTAL_MAP_PINS")); }
public static void ApplyStatChanges(NWPlayer player, NWItem ignoreItem, bool isInitialization = false) { if (!player.IsPlayer) { return; } if (!player.IsInitializedAsPlayer) { return; } if (player.GetLocalInt("IS_SHIP") == 1) { return; } // Don't fire for ammo as it reapplies bonuses we **just** removed from blasters. if (ignoreItem != null && (ignoreItem.BaseItemType == BaseItem.Bolt || ignoreItem.BaseItemType == BaseItem.Arrow || ignoreItem.BaseItemType == BaseItem.Bullet)) { return; } Player pcEntity = DataService.Player.GetByID(player.GlobalID); List <PCSkill> skills = DataService.PCSkill .GetAllByPlayerID(player.GlobalID) .Where(x => x.Rank > 0).ToList(); EffectiveItemStats itemBonuses = GetPlayerItemEffectiveStats(player, ignoreItem); float strBonus = 0.0f; float dexBonus = 0.0f; float conBonus = 0.0f; float intBonus = 0.0f; float wisBonus = 0.0f; float chaBonus = 0.0f; foreach (PCSkill pcSkill in skills) { Skill skill = DataService.Skill.GetByID(pcSkill.SkillID); CustomAttribute primary = (CustomAttribute)skill.Primary; CustomAttribute secondary = (CustomAttribute)skill.Secondary; CustomAttribute tertiary = (CustomAttribute)skill.Tertiary; // Primary Bonuses if (primary == CustomAttribute.STR) { strBonus += PrimaryIncrease * pcSkill.Rank; } else if (primary == CustomAttribute.DEX) { dexBonus += PrimaryIncrease * pcSkill.Rank; } else if (primary == CustomAttribute.CON) { conBonus += PrimaryIncrease * pcSkill.Rank; } else if (primary == CustomAttribute.INT) { intBonus += PrimaryIncrease * pcSkill.Rank; } else if (primary == CustomAttribute.WIS) { wisBonus += PrimaryIncrease * pcSkill.Rank; } else if (primary == CustomAttribute.CHA) { chaBonus += PrimaryIncrease * pcSkill.Rank; } // Secondary Bonuses if (secondary == CustomAttribute.STR) { strBonus += SecondaryIncrease * pcSkill.Rank; } else if (secondary == CustomAttribute.DEX) { dexBonus += SecondaryIncrease * pcSkill.Rank; } else if (secondary == CustomAttribute.CON) { conBonus += SecondaryIncrease * pcSkill.Rank; } else if (secondary == CustomAttribute.INT) { intBonus += SecondaryIncrease * pcSkill.Rank; } else if (secondary == CustomAttribute.WIS) { wisBonus += SecondaryIncrease * pcSkill.Rank; } else if (secondary == CustomAttribute.CHA) { chaBonus += SecondaryIncrease * pcSkill.Rank; } // Tertiary Bonuses if (tertiary == CustomAttribute.STR) { strBonus += TertiaryIncrease * pcSkill.Rank; } else if (tertiary == CustomAttribute.DEX) { dexBonus += TertiaryIncrease * pcSkill.Rank; } else if (tertiary == CustomAttribute.CON) { conBonus += TertiaryIncrease * pcSkill.Rank; } else if (tertiary == CustomAttribute.INT) { intBonus += TertiaryIncrease * pcSkill.Rank; } else if (tertiary == CustomAttribute.WIS) { wisBonus += TertiaryIncrease * pcSkill.Rank; } else if (tertiary == CustomAttribute.CHA) { chaBonus += TertiaryIncrease * pcSkill.Rank; } } // Check caps. if (strBonus > MaxAttributeBonus) { strBonus = MaxAttributeBonus; } if (dexBonus > MaxAttributeBonus) { dexBonus = MaxAttributeBonus; } if (conBonus > MaxAttributeBonus) { conBonus = MaxAttributeBonus; } if (intBonus > MaxAttributeBonus) { intBonus = MaxAttributeBonus; } if (wisBonus > MaxAttributeBonus) { wisBonus = MaxAttributeBonus; } if (chaBonus > MaxAttributeBonus) { chaBonus = MaxAttributeBonus; } // Apply item bonuses strBonus += itemBonuses.Strength; dexBonus += itemBonuses.Dexterity; conBonus += itemBonuses.Constitution; wisBonus += itemBonuses.Wisdom; intBonus += itemBonuses.Intelligence; chaBonus += itemBonuses.Charisma; // Check final caps if (strBonus > 55) { strBonus = 55; } if (dexBonus > 55) { dexBonus = 55; } if (conBonus > 55) { conBonus = 55; } if (intBonus > 55) { intBonus = 55; } if (wisBonus > 55) { wisBonus = 55; } if (chaBonus > 55) { chaBonus = 55; } // Apply attributes NWNXCreature.SetRawAbilityScore(player, AbilityType.Strength, (int)strBonus + pcEntity.STRBase); NWNXCreature.SetRawAbilityScore(player, AbilityType.Dexterity, (int)dexBonus + pcEntity.DEXBase); NWNXCreature.SetRawAbilityScore(player, AbilityType.Constitution, (int)conBonus + pcEntity.CONBase); NWNXCreature.SetRawAbilityScore(player, AbilityType.Intelligence, (int)intBonus + pcEntity.INTBase); NWNXCreature.SetRawAbilityScore(player, AbilityType.Wisdom, (int)wisBonus + pcEntity.WISBase); NWNXCreature.SetRawAbilityScore(player, AbilityType.Charisma, (int)chaBonus + pcEntity.CHABase); // Apply AC int ac = EffectiveArmorClass(player, ignoreItem, itemBonuses); NWNXCreature.SetBaseAC(player, ac); // Apply BAB int bab = CalculateBAB(player, ignoreItem, itemBonuses); NWNXCreature.SetBaseAttackBonus(player, bab); // Apply HP int hp = EffectiveMaxHitPoints(player, itemBonuses); for (int level = 1; level <= 5; level++) { hp--; NWNXCreature.SetMaxHitPointsByLevel(player, level, 1); } for (int level = 1; level <= 5; level++) { if (hp >= 255) // Levels can only contain a max of 255 HP { NWNXCreature.SetMaxHitPointsByLevel(player, level, 255); hp = hp - 254; } else // Remaining value gets set to the level. (<255 hp) { NWNXCreature.SetMaxHitPointsByLevel(player, level, hp + 1); break; } } if (player.CurrentHP > player.MaxHP) { int amount = player.CurrentHP - player.MaxHP; var damage = _.EffectDamage(amount); _.ApplyEffectToObject(DurationType.Instant, damage, player.Object); } // Apply FP pcEntity.MaxFP = EffectiveMaxFP(player, itemBonuses); if (isInitialization) { pcEntity.CurrentFP = pcEntity.MaxFP; } DataService.SubmitDataChange(pcEntity, DatabaseActionType.Update); // Attempt a refresh of the character sheet UI in a second. _.DelayCommand(1.0f, () => { NWNXPlayer.UpdateCharacterSheet(player); }); }