public void InitializePlayer(NWPlayer player) { if (player == null) { throw new ArgumentNullException(nameof(player)); } if (player.Object == null) { throw new ArgumentNullException(nameof(player.Object)); } if (!player.IsPlayer) { return; } if (!player.IsInitializedAsPlayer) { player.DestroyAllInventoryItems(); player.InitializePlayer(); _.CreateItemOnObject("open_rest_menu", player.Object); _.AssignCommand(player.Object, () => _.TakeGoldFromCreature(_.GetGold(player.Object), player.Object, 1)); NWItem knife = NWItem.Wrap(_.CreateItemOnObject("survival_knife", player.Object)); knife.Name = player.Name + "'s Survival Knife"; knife.IsCursed = true; knife.MaxDurability = 5; knife.Durability = 5; NWItem hammer = NWItem.Wrap(_.CreateItemOnObject("basic_hammer", player.Object)); hammer.Name = player.Name + "'s Hammer"; hammer.IsCursed = true; hammer.MaxDurability = 5; hammer.Durability = 5; NWItem darts = NWItem.Wrap(_.CreateItemOnObject("nw_wthdt001", player.Object, 50)); // 50x Dart darts.Name = "Starting Darts"; darts.IsCursed = true; NWItem book = NWItem.Wrap(_.CreateItemOnObject("player_guide", player.Object)); book.Name = player.Name + "'s Player Guide"; book.IsCursed = true; NWItem dyeKit = NWItem.Wrap(_.CreateItemOnObject("tk_omnidye", player.Object)); dyeKit.IsCursed = true; NWItem shovel = NWItem.Wrap(_.CreateItemOnObject("basic_shovel", player.Object)); shovel.Name = player.Name + "'s Shovel"; shovel.IsCursed = true; int numberOfFeats = _nwnxCreature.GetFeatCount(player); for (int currentFeat = numberOfFeats; currentFeat >= 0; currentFeat--) { _nwnxCreature.RemoveFeat(player, _nwnxCreature.GetFeatByIndex(player, currentFeat - 1)); } _nwnxCreature.SetClassByPosition(player, 0, CLASS_TYPE_FIGHTER); _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_LIGHT, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_MEDIUM, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_HEAVY, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_SHIELD_PROFICIENCY, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_EXOTIC, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_MARTIAL, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_SIMPLE, 1); for (int iCurSkill = 1; iCurSkill <= 27; iCurSkill++) { _nwnxCreature.SetSkillRank(player, iCurSkill - 1, 0); } _.SetFortitudeSavingThrow(player.Object, 0); _.SetReflexSavingThrow(player.Object, 0); _.SetWillSavingThrow(player.Object, 0); int classID = _.GetClassByPosition(1, player.Object); for (int index = 0; index <= 255; index++) { _nwnxCreature.RemoveKnownSpell(player, classID, 0, index); } using (DataContext context = new DataContext()) { PlayerCharacter entity = player.ToEntity(); context.PlayerCharacters.Add(entity); context.SaveChanges(); } _skill.ApplyStatChanges(player, null); _.DelayCommand(1000, () => _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(999), player.Object)); InitializeHotBar(player); } }
public void InitializePlayer(NWPlayer player) { if (player == null) { throw new ArgumentNullException(nameof(player)); } if (player.Object == null) { throw new ArgumentNullException(nameof(player.Object)); } if (!player.IsPlayer) { return; } if (!player.IsInitializedAsPlayer) { player.DestroyAllInventoryItems(); player.InitializePlayer(); _.AssignCommand(player.Object, () => _.TakeGoldFromCreature(_.GetGold(player.Object), player.Object, 1)); player.DelayCommand(() => { _.GiveGoldToCreature(player.Object, 100); }, 0.5f); NWItem knife = NWItem.Wrap(_.CreateItemOnObject("survival_knife", player.Object)); knife.Name = player.Name + "'s Survival Knife"; knife.IsCursed = true; knife.MaxDurability = 5; knife.Durability = 5; NWItem darts = NWItem.Wrap(_.CreateItemOnObject("nw_wthdt001", player.Object, 50)); // 50x Dart darts.Name = "Starting Darts"; darts.IsCursed = true; NWItem book = NWItem.Wrap(_.CreateItemOnObject("player_guide", player.Object)); book.Name = player.Name + "'s Player Guide"; book.IsCursed = true; NWItem dyeKit = NWItem.Wrap(_.CreateItemOnObject("tk_omnidye", player.Object)); dyeKit.IsCursed = true; int numberOfFeats = _nwnxCreature.GetFeatCount(player); for (int currentFeat = numberOfFeats; currentFeat >= 0; currentFeat--) { _nwnxCreature.RemoveFeat(player, _nwnxCreature.GetFeatByIndex(player, currentFeat - 1)); } _nwnxCreature.SetClassByPosition(player, 0, CLASS_TYPE_FIGHTER); _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_LIGHT, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_MEDIUM, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_HEAVY, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_SHIELD_PROFICIENCY, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_EXOTIC, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_MARTIAL, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_SIMPLE, 1); _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.StructureTool, 1); _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.OpenRestMenu, 1); for (int iCurSkill = 1; iCurSkill <= 27; iCurSkill++) { _nwnxCreature.SetSkillRank(player, iCurSkill - 1, 0); } _.SetFortitudeSavingThrow(player.Object, 0); _.SetReflexSavingThrow(player.Object, 0); _.SetWillSavingThrow(player.Object, 0); int classID = _.GetClassByPosition(1, player.Object); for (int index = 0; index <= 255; index++) { _nwnxCreature.RemoveKnownSpell(player, classID, 0, index); } PlayerCharacter entity = player.ToEntity(); _db.PlayerCharacters.Add(entity); _db.SaveChanges(); _db.StoredProcedure("InsertAllPCSkillsByID", new SqlParameter("PlayerID", player.GlobalID)); _skill.ApplyStatChanges(player, null, true); _.DelayCommand(1.0f, () => _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(999), player.Object)); InitializeHotBar(player); } }
public void InitializePlayer(NWPlayer player) { if (player == null) { throw new ArgumentNullException(nameof(player)); } if (player.Object == null) { throw new ArgumentNullException(nameof(player.Object)); } if (!player.IsPlayer) { return; } // Player is initialized but not in the DB. Wipe the tag and rerun them through initialization - something went wrong before. if (player.IsInitializedAsPlayer) { if (_data.GetAll <Player>().SingleOrDefault(x => x.ID == player.GlobalID) == null) { _.SetTag(player, string.Empty); } } if (!player.IsInitializedAsPlayer) { player.DestroyAllInventoryItems(); player.InitializePlayer(); _.AssignCommand(player, () => _.TakeGoldFromCreature(_.GetGold(player), player, 1)); _.DelayCommand(0.5f, () => { _.GiveGoldToCreature(player, 100); }); // Capture original stats before we level up the player. int str = _nwnxCreature.GetRawAbilityScore(player, ABILITY_STRENGTH); int con = _nwnxCreature.GetRawAbilityScore(player, ABILITY_CONSTITUTION); int dex = _nwnxCreature.GetRawAbilityScore(player, ABILITY_DEXTERITY); int @int = _nwnxCreature.GetRawAbilityScore(player, ABILITY_INTELLIGENCE); int wis = _nwnxCreature.GetRawAbilityScore(player, ABILITY_WISDOM); int cha = _nwnxCreature.GetRawAbilityScore(player, ABILITY_CHARISMA); // Take player to level 5 in NWN levels so that we have access to more HP slots _.GiveXPToCreature(player, 10000); for (int level = 1; level <= 5; level++) { _.LevelUpHenchman(player, player.Class1); } // Set stats back to how they were on entry. _nwnxCreature.SetRawAbilityScore(player, ABILITY_STRENGTH, str); _nwnxCreature.SetRawAbilityScore(player, ABILITY_CONSTITUTION, con); _nwnxCreature.SetRawAbilityScore(player, ABILITY_DEXTERITY, dex); _nwnxCreature.SetRawAbilityScore(player, ABILITY_INTELLIGENCE, @int); _nwnxCreature.SetRawAbilityScore(player, ABILITY_WISDOM, wis); _nwnxCreature.SetRawAbilityScore(player, ABILITY_CHARISMA, cha); NWItem knife = (_.CreateItemOnObject("survival_knife", player)); knife.Name = player.Name + "'s Survival Knife"; knife.IsCursed = true; _durability.SetMaxDurability(knife, 5); _durability.SetDurability(knife, 5); NWItem book = (_.CreateItemOnObject("player_guide", player)); book.Name = player.Name + "'s Player Guide"; book.IsCursed = true; NWItem dyeKit = (_.CreateItemOnObject("tk_omnidye", player)); dyeKit.IsCursed = true; int numberOfFeats = _nwnxCreature.GetFeatCount(player); for (int currentFeat = numberOfFeats; currentFeat >= 0; currentFeat--) { _nwnxCreature.RemoveFeat(player, _nwnxCreature.GetFeatByIndex(player, currentFeat - 1)); } _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_LIGHT, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_MEDIUM, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_HEAVY, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_SHIELD_PROFICIENCY, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_EXOTIC, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_MARTIAL, 1); _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_SIMPLE, 1); _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.StructureManagementTool, 1); _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.OpenRestMenu, 1); _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.RenameCraftedItem, 1); _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.ChatCommandTargeter, 1); for (int iCurSkill = 1; iCurSkill <= 27; iCurSkill++) { _nwnxCreature.SetSkillRank(player, iCurSkill - 1, 0); } _.SetFortitudeSavingThrow(player, 0); _.SetReflexSavingThrow(player, 0); _.SetWillSavingThrow(player, 0); int classID = _.GetClassByPosition(1, player); for (int index = 0; index <= 255; index++) { _nwnxCreature.RemoveKnownSpell(player, classID, 0, index); } Player entity = CreateDBPCEntity(player); _data.SubmitDataChange(entity, DatabaseActionType.Insert); var skills = _data.GetAll <Skill>(); foreach (var skill in skills) { var pcSkill = new PCSkill { IsLocked = false, SkillID = skill.ID, PlayerID = entity.ID, Rank = 0, XP = 0 }; _data.SubmitDataChange(pcSkill, DatabaseActionType.Insert); } _race.ApplyDefaultAppearance(player); _nwnxCreature.SetAlignmentLawChaos(player, 50); _nwnxCreature.SetAlignmentGoodEvil(player, 50); _background.ApplyBackgroundBonuses(player); _stat.ApplyStatChanges(player, null, true); _language.InitializePlayerLanguages(player); _.DelayCommand(1.0f, () => _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(999), player)); InitializeHotBar(player); } }
public void DoPerkUpgrade(NWPlayer oPC, int perkID, bool freeUpgrade = false) { var perk = _data.Single <Data.Entity.Perk>(x => x.ID == perkID); var perkLevels = _data.Where <PerkLevel>(x => x.PerkID == perkID); var pcPerk = _data.SingleOrDefault <PCPerk>(x => x.PlayerID == oPC.GlobalID && x.PerkID == perkID); var player = _data.Single <Player>(x => x.ID == oPC.GlobalID); if (freeUpgrade || CanPerkBeUpgraded(oPC, perkID)) { DatabaseActionType action = DatabaseActionType.Update; if (pcPerk == null) { pcPerk = new PCPerk(); DateTime dt = DateTime.UtcNow; pcPerk.AcquiredDate = dt; pcPerk.PerkID = perk.ID; pcPerk.PlayerID = oPC.GlobalID; pcPerk.PerkLevel = 0; action = DatabaseActionType.Insert; } PerkLevel nextPerkLevel = FindPerkLevel(perkLevels, pcPerk.PerkLevel + 1); if (nextPerkLevel == null) { return; } pcPerk.PerkLevel++; _data.SubmitDataChange(pcPerk, action); if (!freeUpgrade) { player.UnallocatedSP -= nextPerkLevel.Price; _data.SubmitDataChange(player, DatabaseActionType.Update); } // If a perk is activatable, create the item on the PC. // Remove any existing cast spell unique power properties and add the correct one based on the DB flag. if (!string.IsNullOrWhiteSpace(perk.ItemResref)) { if (_.GetIsObjectValid(_.GetItemPossessedBy(oPC.Object, perk.ItemResref)) == FALSE) { NWItem spellItem = (_.CreateItemOnObject(perk.ItemResref, oPC.Object)); spellItem.IsCursed = true; spellItem.SetLocalInt("ACTIVATION_PERK_ID", perk.ID); foreach (ItemProperty ipCur in spellItem.ItemProperties) { int ipType = _.GetItemPropertyType(ipCur); int ipSubType = _.GetItemPropertySubType(ipCur); if (ipType == ITEM_PROPERTY_CAST_SPELL && (ipSubType == IP_CONST_CASTSPELL_UNIQUE_POWER || ipSubType == IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY || ipSubType == IP_CONST_CASTSPELL_ACTIVATE_ITEM)) { _.RemoveItemProperty(spellItem.Object, ipCur); } } ItemProperty ip; if (perk.IsTargetSelfOnly) { ip = _.ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY, IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE); } else { ip = _.ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER, IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE); } _biowareXP2.IPSafeAddItemProperty(spellItem, ip, 0.0f, AddItemPropertyPolicy.ReplaceExisting, false, false); } _.SetName(_.GetItemPossessedBy(oPC.Object, perk.ItemResref), perk.Name + " (Lvl. " + pcPerk.PerkLevel + ")"); } // If a feat ID is assigned, add the feat to the player if it doesn't exist yet. else if (perk.FeatID != null && perk.FeatID > 0 && _.GetHasFeat((int)perk.FeatID, oPC.Object) == FALSE) { _nwnxCreature.AddFeatByLevel(oPC, (int)perk.FeatID, 1); var qbs = _nwnxQBS.UseFeat((int)perk.FeatID); // Try to add the new feat to the player's hotbar. if (_nwnxPlayer.GetQuickBarSlot(oPC, 0).ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(oPC, 0, qbs); } else if (_nwnxPlayer.GetQuickBarSlot(oPC, 1).ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(oPC, 1, qbs); } else if (_nwnxPlayer.GetQuickBarSlot(oPC, 2).ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(oPC, 2, qbs); } else if (_nwnxPlayer.GetQuickBarSlot(oPC, 3).ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(oPC, 3, qbs); } else if (_nwnxPlayer.GetQuickBarSlot(oPC, 4).ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(oPC, 4, qbs); } else if (_nwnxPlayer.GetQuickBarSlot(oPC, 5).ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(oPC, 5, qbs); } else if (_nwnxPlayer.GetQuickBarSlot(oPC, 6).ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(oPC, 6, qbs); } else if (_nwnxPlayer.GetQuickBarSlot(oPC, 7).ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(oPC, 7, qbs); } else if (_nwnxPlayer.GetQuickBarSlot(oPC, 8).ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(oPC, 8, qbs); } else if (_nwnxPlayer.GetQuickBarSlot(oPC, 9).ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(oPC, 9, qbs); } else if (_nwnxPlayer.GetQuickBarSlot(oPC, 10).ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(oPC, 10, qbs); } } oPC.SendMessage(_color.Green("Perk Purchased: " + perk.Name + " (Lvl. " + pcPerk.PerkLevel + ")")); App.ResolveByInterface <IPerk>("Perk." + perk.ScriptName, (perkScript) => { if (perkScript == null) { return; } perkScript.OnPurchased(oPC, pcPerk.PerkLevel); }); } else { oPC.FloatingText(_color.Red("You cannot purchase the perk at this time.")); } }
public void OnModuleNWNXChat(NWPlayer sender) { string originalMessage = _nwnxChat.GetMessage().Trim(); if (!CanHandleChat(sender, originalMessage)) { return; } var split = originalMessage.Split(' ').ToList(); // Commands with no arguments won't be split, so if we didn't split anything then add the command to the split list manually. if (split.Count <= 0) { split.Add(originalMessage); } split[0] = split[0].ToLower(); string command = split[0].Substring(1, split[0].Length - 1); split.RemoveAt(0); _nwnxChat.SkipMessage(); if (!App.IsKeyRegistered <IChatCommand>("ChatCommand." + command)) { sender.SendMessage(_color.Red("Invalid chat command. Use '/help' to get a list of available commands.")); return; } App.ResolveByInterface <IChatCommand>("ChatCommand." + command, chatCommand => { string args = string.Join(" ", split); if (!chatCommand.RequiresTarget) { ProcessChatCommand(chatCommand, sender, null, null, args); } else { string error = chatCommand.ValidateArguments(sender, split.ToArray()); if (!string.IsNullOrWhiteSpace(error)) { sender.SendMessage(error); return; } sender.SetLocalString("CHAT_COMMAND", command); sender.SetLocalString("CHAT_COMMAND_ARGS", args); sender.SendMessage("Please use your 'Chat Command Targeter' feat to select the target of this chat command."); if (_.GetHasFeat((int)CustomFeatType.ChatCommandTargeter, sender) == FALSE || sender.IsDM) { _nwnxCreature.AddFeatByLevel(sender, (int)CustomFeatType.ChatCommandTargeter, 1); if (sender.IsDM) { var qbs = _nwnxPlayer.GetQuickBarSlot(sender, 11); if (qbs.ObjectType == QuickBarSlotType.Empty) { _nwnxPlayer.SetQuickBarSlot(sender, 11, _nwnxQBS.UseFeat((int)CustomFeatType.ChatCommandTargeter)); } } } } }); }