public bool Run(params object[] args) { NWCreature attacker = (_.GetLastDamager(Object.OBJECT_SELF)); NWPlaceable tower = (Object.OBJECT_SELF); NWItem weapon = (_.GetLastWeaponUsed(attacker.Object)); int damage = _.GetTotalDamageDealt(); var structureID = tower.GetLocalString("PC_BASE_STRUCTURE_ID"); PCBaseStructure structure = _data.Single <PCBaseStructure>(x => x.ID == new Guid(structureID)); int maxShieldHP = _base.CalculateMaxShieldHP(structure); PCBase pcBase = _data.Get <PCBase>(structure.PCBaseID); pcBase.ShieldHP -= damage; if (pcBase.ShieldHP <= 0) { pcBase.ShieldHP = 0; } float hpPercentage = (float)pcBase.ShieldHP / (float)maxShieldHP * 100.0f; if (hpPercentage <= 25.0f && pcBase.ReinforcedFuel > 0) { pcBase.IsInReinforcedMode = true; pcBase.ShieldHP = (int)(maxShieldHP * 0.25f); } attacker.SendMessage("Tower Shields: " + hpPercentage.ToString("0.00") + "%"); if (pcBase.IsInReinforcedMode) { attacker.SendMessage("Control tower is in reinforced mode and cannot be damaged. Reinforced mode will be disabled when the tower runs out of fuel."); } _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(9999), tower.Object); var durability = _durability.GetDurability(weapon) - _random.RandomFloat(0.01f, 0.03f); _durability.SetDurability(weapon, durability); if (pcBase.ShieldHP <= 0) { pcBase.ShieldHP = 0; structure.Durability -= _random.RandomFloat(0.5f, 2.0f); if (structure.Durability < 0.0f) { structure.Durability = 0.0f; } attacker.SendMessage("Structure Durability: " + structure.Durability.ToString("0.00")); if (structure.Durability <= 0.0f) { structure.Durability = 0.0f; BlowUpBase(pcBase); return(true); } } _data.SubmitDataChange(pcBase, DatabaseActionType.Update); _data.SubmitDataChange(structure, DatabaseActionType.Update); return(true); }
public void Apply(NWPlayer player, NWItem target, params string[] args) { var maxDurability = _durability.GetMaxDurability(target); var curDurability = _durability.GetDurability(target); int value = Convert.ToInt32(args[0]); float newValue = maxDurability + value; if (newValue > 100) { newValue = 100; } maxDurability = newValue; curDurability += value; _durability.SetMaxDurability(target, maxDurability); _durability.SetDurability(target, curDurability); }
public NWItem ConvertStructureToItem(PCBaseStructure pcBaseStructure, NWObject target) { var baseStructure = _data.Get <BaseStructure>(pcBaseStructure.BaseStructureID); NWItem item = (_.CreateItemOnObject(baseStructure.ItemResref, target.Object)); item.SetLocalInt("BASE_STRUCTURE_ID", pcBaseStructure.BaseStructureID); item.Name = baseStructure.Name; _durability.SetMaxDurability(item, (float)pcBaseStructure.Durability); _durability.SetDurability(item, (float)pcBaseStructure.Durability); item.StructureBonus = pcBaseStructure.StructureBonus; if (pcBaseStructure.InteriorStyleID != null && pcBaseStructure.ExteriorStyleID != null) { item.SetLocalInt("STRUCTURE_BUILDING_INTERIOR_ID", (int)pcBaseStructure.InteriorStyleID); item.SetLocalInt("STRUCTURE_BUILDING_EXTERIOR_ID", (int)pcBaseStructure.ExteriorStyleID); item.SetLocalInt("STRUCTURE_BUILDING_INITIALIZED", TRUE); } return(item); }
private void RunSearchCycle(NWPlayer oPC, NWPlaceable oChest, int iDC) { int lootTable = oChest.GetLocalInt(SearchSiteLootTableVariableName); int skill = _.GetSkillRank(NWScript.SKILL_SEARCH, oPC.Object); if (skill > 10) { skill = 10; } else if (skill < 0) { skill = 0; } int roll = _random.Random(20) + 1; int combinedRoll = roll + skill; if (roll + skill >= iDC) { oPC.FloatingText(_color.SkillCheck("Search: *success*: (" + roll + " + " + skill + " = " + combinedRoll + " vs. DC: " + iDC + ")")); ItemVO spawnItem = PickResultItem(lootTable); if (!string.IsNullOrWhiteSpace(spawnItem.Resref) && spawnItem.Quantity > 0) { NWItem foundItem = (_.CreateItemOnObject(spawnItem.Resref, oChest.Object, spawnItem.Quantity, "")); float maxDurability = _durability.GetMaxDurability(foundItem); if (maxDurability > -1) { _durability.SetDurability(foundItem, _random.RandomFloat() * maxDurability + 1); } } } else { oPC.FloatingText(_color.SkillCheck("Search: *failure*: (" + roll + " + " + skill + " = " + combinedRoll + " vs. DC: " + iDC + ")")); } }
private void RunCreateItem(NWPlayer player) { var model = _craft.GetPlayerCraftingData(player); CraftBlueprint blueprint = _data.Single <CraftBlueprint>(x => x.ID == model.BlueprintID); BaseStructure baseStructure = blueprint.BaseStructureID == null ? null : _data.Get <BaseStructure>(blueprint.BaseStructureID); PCSkill pcSkill = _skill.GetPCSkill(player, blueprint.SkillID); int pcEffectiveLevel = _craft.CalculatePCEffectiveLevel(player, pcSkill.Rank, (SkillType)blueprint.SkillID); int itemLevel = model.AdjustedLevel; float chance = CalculateBaseChanceToAddProperty(pcEffectiveLevel, itemLevel); float equipmentBonus = CalculateEquipmentBonus(player, (SkillType)blueprint.SkillID); if (chance <= 1.0f) { player.FloatingText(_color.Red("Critical failure! You don't have enough skill to create that item. All components were lost.")); _craft.ClearPlayerCraftingData(player, true); return; } int luckyBonus = _perk.GetPCPerkLevel(player, PerkType.Lucky); var craftedItems = new List <NWItem>(); NWItem craftedItem = (_.CreateItemOnObject(blueprint.ItemResref, player.Object, blueprint.Quantity)); craftedItem.IsIdentified = true; craftedItems.Add(craftedItem); // If item isn't stackable, loop through and create as many as necessary. if (craftedItem.StackSize < blueprint.Quantity) { for (int x = 2; x <= blueprint.Quantity; x++) { craftedItem = (_.CreateItemOnObject(blueprint.ItemResref, player.Object)); craftedItem.IsIdentified = true; craftedItems.Add(craftedItem); } } // Recommended level gets set regardless if all item properties make it on the final product. // Also mark who crafted the item. This is later used for display on the item's examination event. foreach (var item in craftedItems) { item.RecommendedLevel = itemLevel < 0 ? 0 : itemLevel; item.SetLocalString("CRAFTER_PLAYER_ID", player.GlobalID.ToString()); _base.ApplyCraftedItemLocalVariables(item, baseStructure); } if (_random.Random(1, 100) <= luckyBonus) { chance += _random.Random(1, luckyBonus); } int successAmount = 0; foreach (var component in model.MainComponents) { var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems); successAmount += result.Item1; chance = result.Item2; } foreach (var component in model.SecondaryComponents) { var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems); successAmount += result.Item1; chance = result.Item2; } foreach (var component in model.TertiaryComponents) { var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems); successAmount += result.Item1; chance = result.Item2; } foreach (var component in model.EnhancementComponents) { var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems); successAmount += result.Item1; chance = result.Item2; } // Structures gain increased durability based on the blueprint if (baseStructure != null) { foreach (var item in craftedItems) { var maxDur = _durability.GetMaxDurability(item); maxDur += (float)baseStructure.Durability; _durability.SetMaxDurability(item, maxDur); _durability.SetDurability(item, maxDur); } } player.SendMessage("You created " + blueprint.Quantity + "x " + blueprint.ItemName + "!"); int baseXP = 250 + successAmount * _random.Random(1, 50); float xp = _skill.CalculateRegisteredSkillLevelAdjustedXP(baseXP, model.AdjustedLevel, pcSkill.Rank); var pcCraftedBlueprint = _data.SingleOrDefault <PCCraftedBlueprint>(x => x.PlayerID == player.GlobalID && x.CraftBlueprintID == blueprint.ID); if (pcCraftedBlueprint == null) { xp = xp * 1.25f; player.SendMessage("You receive an XP bonus for crafting this item for the first time."); pcCraftedBlueprint = new PCCraftedBlueprint { CraftBlueprintID = blueprint.ID, DateFirstCrafted = DateTime.UtcNow, PlayerID = player.GlobalID }; _data.SubmitDataChange(pcCraftedBlueprint, DatabaseActionType.Insert); } _skill.GiveSkillXP(player, blueprint.SkillID, (int)xp); _craft.ClearPlayerCraftingData(player, true); }
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 bool Run(params object[] args) { NWCreature attacker = (_.GetLastDamager(Object.OBJECT_SELF)); NWPlaceable tower = (Object.OBJECT_SELF); NWItem weapon = (_.GetLastWeaponUsed(attacker.Object)); int damage = _.GetTotalDamageDealt(); var structureID = tower.GetLocalString("PC_BASE_STRUCTURE_ID"); PCBaseStructure structure = _data.Single <PCBaseStructure>(x => x.ID == new Guid(structureID)); int maxShieldHP = _base.CalculateMaxShieldHP(structure); PCBase pcBase = _data.Get <PCBase>(structure.PCBaseID); var playerIDs = _data.Where <PCBasePermission>(x => x.PCBaseID == structure.PCBaseID && !x.IsPublicPermission) .Select(s => s.PlayerID); var toNotify = NWModule.Get().Players.Where(x => playerIDs.Contains(x.GlobalID)); DateTime timer = DateTime.UtcNow.AddSeconds(30); string clock = timer.ToString(CultureInfo.InvariantCulture); string sector = _base.GetSectorOfLocation(attacker.Location); if (DateTime.UtcNow <= DateTime.Parse(clock)) { foreach (NWPlayer player in toNotify) { player.SendMessage("Your base in " + attacker.Area.Name + " " + sector + " is under attack!"); } } pcBase.ShieldHP -= damage; if (pcBase.ShieldHP <= 0) { pcBase.ShieldHP = 0; } float hpPercentage = (float)pcBase.ShieldHP / (float)maxShieldHP * 100.0f; if (hpPercentage <= 25.0f && pcBase.ReinforcedFuel > 0) { pcBase.IsInReinforcedMode = true; pcBase.ShieldHP = (int)(maxShieldHP * 0.25f); } attacker.SendMessage("Tower Shields: " + hpPercentage.ToString("0.00") + "%"); if (pcBase.IsInReinforcedMode) { attacker.SendMessage("Control tower is in reinforced mode and cannot be damaged. Reinforced mode will be disabled when the tower runs out of fuel."); } _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(9999), tower.Object); var durability = _durability.GetDurability(weapon) - _random.RandomFloat(0.01f, 0.03f); _durability.SetDurability(weapon, durability); if (pcBase.ShieldHP <= 0) { pcBase.ShieldHP = 0; structure.Durability -= _random.RandomFloat(0.5f, 2.0f); if (structure.Durability < 0.0f) { structure.Durability = 0.0f; } attacker.SendMessage("Structure Durability: " + structure.Durability.ToString("0.00")); if (structure.Durability <= 0.0f) { structure.Durability = 0.0f; BlowUpBase(pcBase); return(true); } } _data.SubmitDataChange(pcBase, DatabaseActionType.Update); _data.SubmitDataChange(structure, DatabaseActionType.Update); return(true); }
public void ApplyComponentBonus(NWItem product, ItemProperty sourceIP) { ComponentBonusType bonusType = (ComponentBonusType)_.GetItemPropertySubType(sourceIP); int amount = _.GetItemPropertyCostTableValue(sourceIP); ItemProperty prop = null; string sourceTag = string.Empty; // A note about the sourceTags: // It's not currently possible to create custom item properties on items. To get around this, // we look in an inaccessible container which holds the custom item properties. Then, we get the // item that has the item property we want. From there we take that item property and copy it to // the crafted item. // This is a really roundabout way to do it, but it's the only option for now. Hopefully a feature to // directly add the item properties comes in to NWNX in the future. for (int x = 1; x <= amount; x++) { switch (bonusType) { case ComponentBonusType.ModSocketRed: sourceTag = "rslot_red"; break; case ComponentBonusType.ModSocketBlue: sourceTag = "rslot_blue"; break; case ComponentBonusType.ModSocketGreen: sourceTag = "rslot_green"; break; case ComponentBonusType.ModSocketYellow: sourceTag = "rslot_yellow"; break; case ComponentBonusType.ModSocketPrismatic: sourceTag = "rslot_prismatic"; break; case ComponentBonusType.DurabilityUp: var maxDur = _durability.GetMaxDurability(product) + amount; _durability.SetMaxDurability(product, maxDur); _durability.SetDurability(product, maxDur); break; case ComponentBonusType.ChargesUp: product.Charges += amount; break; case ComponentBonusType.ACUp: product.CustomAC += amount; break; case ComponentBonusType.HarvestingUp: product.HarvestingBonus += amount; break; case ComponentBonusType.CastingSpeedUp: product.CastingSpeed += amount; break; case ComponentBonusType.ArmorsmithUp: product.CraftBonusArmorsmith += amount; break; case ComponentBonusType.WeaponsmithUp: product.CraftBonusWeaponsmith += amount; break; case ComponentBonusType.CookingUp: product.CraftBonusCooking += amount; break; case ComponentBonusType.EngineeringUp: product.CraftBonusEngineering += amount; break; case ComponentBonusType.FabricationUp: product.CraftBonusFabrication += amount; break; case ComponentBonusType.HPUp: product.HPBonus += amount; break; case ComponentBonusType.FPUp: product.FPBonus += amount; break; case ComponentBonusType.EnmityUp: product.EnmityRate += amount; break; case ComponentBonusType.EnmityDown: product.EnmityRate -= amount; break; case ComponentBonusType.DarkAbilityUp: product.DarkAbilityBonus += amount; break; case ComponentBonusType.LightAbilityUp: product.LightAbilityBonus += amount; break; case ComponentBonusType.LuckUp: product.LuckBonus += amount; break; case ComponentBonusType.MeditateUp: product.MeditateBonus += amount; break; case ComponentBonusType.RestUp: product.RestBonus += amount; break; case ComponentBonusType.MedicineUp: product.MedicineBonus += amount; break; case ComponentBonusType.HPRegenUp: product.HPRegenBonus += amount; break; case ComponentBonusType.FPRegenUp: product.FPRegenBonus += amount; break; case ComponentBonusType.BaseAttackBonusUp: product.BaseAttackBonus += amount; break; case ComponentBonusType.SneakAttackUp: product.SneakAttackBonus += amount; break; case ComponentBonusType.DamageUp: product.DamageBonus += amount; break; case ComponentBonusType.DarkAbilityDown: product.DarkAbilityBonus -= amount; break; case ComponentBonusType.LightAbilityDown: product.LightAbilityBonus -= amount; break; case ComponentBonusType.StructureBonusUp: product.StructureBonus += amount; break; case ComponentBonusType.StrengthUp: product.StrengthBonus += amount; break; case ComponentBonusType.DexterityUp: product.DexterityBonus += amount; break; case ComponentBonusType.ConstitutionUp: product.ConstitutionBonus += amount; break; case ComponentBonusType.WisdomUp: product.WisdomBonus += amount; break; case ComponentBonusType.IntelligenceUp: product.IntelligenceBonus += amount; break; case ComponentBonusType.CharismaUp: product.CharismaBonus += amount; break; case ComponentBonusType.AttackBonusUp: prop = _.ItemPropertyAttackBonus(amount); break; case ComponentBonusType.DurationUp: product.DurationBonus += amount; break; case ComponentBonusType.ScanningUp: product.ScanningBonus += amount; break; default: throw new ArgumentOutOfRangeException(); } if (!string.IsNullOrWhiteSpace(sourceTag)) { prop = _item.GetCustomItemPropertyByItemTag(sourceTag); } if (prop == null) { return; } _biowareXP2.IPSafeAddItemProperty(product, prop, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true); } }