public bool Run(params object[] args) { NWPlayer player = NWPlayer.Wrap(_.GetLastUsedBy()); NWPlaceable warp = NWPlaceable.Wrap(Object.OBJECT_SELF); bool isExit = warp.GetLocalInt("IS_EXIT") == NWScript.TRUE; if (isExit) { PlayerCharacter entity = _player.GetPlayerEntity(player.GlobalID); NWArea area = NWArea.Wrap(_.GetObjectByTag(entity.LocationAreaTag)); Vector position = _.Vector((float)entity.LocationX, (float)entity.LocationY, (float)entity.LocationZ); Location location = _.Location(area.Object, position, (float)entity.LocationOrientation); player.AssignCommand(() => _.ActionJumpToLocation(location)); } else { _player.SaveLocation(player); NWObject waypoint = NWObject.Wrap(_.GetWaypointByTag("TUTORIAL_WP")); player.AssignCommand(() => _.ActionJumpToLocation(waypoint.Location)); } return(true); }
private void TeleportPlayerToBindPoint(NWObject pc, PlayerCharacter entity) { if (entity.CurrentHunger < 50) { entity.CurrentHunger = 50; } if (string.IsNullOrWhiteSpace(entity.RespawnAreaTag)) { NWObject defaultRespawn = NWObject.Wrap(_.GetWaypointByTag("DEFAULT_RESPAWN_POINT")); Location location = defaultRespawn.Location; pc.AssignCommand(() => { _.ActionJumpToLocation(location); }); } else { pc.AssignCommand(() => { NWArea area = NWArea.Wrap(_.GetObjectByTag(entity.RespawnAreaTag)); Vector position = _.Vector((float)entity.RespawnLocationX, (float)entity.RespawnLocationY, (float)entity.RespawnLocationZ); Location location = _.Location(area.Object, position, (float)entity.RespawnLocationOrientation); _.ActionJumpToLocation(location); }); } }
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); if (perk.CanCastSpell(oPC, oTarget)) { perk.OnImpact(oPC, oTarget); if (oTarget.IsNPC) { ApplyEnmity(oPC, NWCreature.Wrap(oTarget.Object), entity); } } else { oPC.SendMessage(perk.CannotCastSpellMessage(oPC, oTarget) ?? "That ability cannot be used at this time."); } oPC.DeleteLocalString("ACTIVE_WEAPON_SKILL_UUID"); oPC.DeleteLocalInt("ACTIVE_WEAPON_SKILL"); }
public bool Run(params object[] args) { NWObject oPC = NWObject.Wrap(_.GetLastUsedBy()); oPC.AssignCommand(() => _.ActionAttack(Object.OBJECT_SELF)); return(true); }
// Gets the player's quickbar slot info public QuickBarSlot NWNX_Player_GetQuickBarSlot(NWPlayer player, int slot) { string sFunc = "GetQuickBarSlot"; QuickBarSlot qbs = new QuickBarSlot(); NWNX_PushArgumentInt(NWNX_Player, sFunc, slot); NWNX_PushArgumentObject(NWNX_Player, sFunc, player.Object); NWNX_CallFunction(NWNX_Player, sFunc); qbs.Associate = NWObject.Wrap(NWNX_GetReturnValueObject(NWNX_Player, sFunc)); qbs.AssociateType = NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.DomainLevel = NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.MetaType = NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.INTParam1 = NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.ToolTip = NWNX_GetReturnValueString(NWNX_Player, sFunc); qbs.CommandLine = NWNX_GetReturnValueString(NWNX_Player, sFunc); qbs.CommandLabel = NWNX_GetReturnValueString(NWNX_Player, sFunc); qbs.Resref = NWNX_GetReturnValueString(NWNX_Player, sFunc); qbs.MultiClass = NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.ObjectType = NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.SecondaryItem = NWItem.Wrap(NWNX_GetReturnValueObject(NWNX_Player, sFunc)); qbs.Item = NWItem.Wrap(NWNX_GetReturnValueObject(NWNX_Player, sFunc)); return(qbs); }
private bool CanHarvest() { NWObject target = NWObject.Wrap(GetPC().GetLocalObject("SHOVEL_TARGET_OBJECT")); return(target.IsValid && target.GetLocalInt("GROWING_PLANT_ID") > 0 && _.GetDistanceBetween(GetPC().Object, target.Object) <= 2.0f); }
// Returns an NWObject from the provided NWObject ID. // This is the counterpart to ObjectToString. public NWObject StringToObject(string id) { string sFunc = "StringToObject"; NWNX_PushArgumentString(NWNX_Object, sFunc, id); NWNX_CallFunction(NWNX_Object, sFunc); return(NWObject.Wrap(NWNX_GetReturnValueObject(NWNX_Object, sFunc))); }
public bool Run(params object[] args) { NWObject user = NWObject.Wrap(_.GetLastUsedBy()); user.AssignCommand(() => { _.ActionSit(Object.OBJECT_SELF); }); return(true); }
public bool Run(params object[] args) { NWPlaceable self = NWPlaceable.Wrap(Object.OBJECT_SELF); NWObject oPC = NWObject.Wrap(_.GetLastUsedBy()); string storeTag = self.GetLocalString("STORE_TAG"); Object store = _.GetObjectByTag(storeTag); _.OpenStore(store, oPC.Object); return(true); }
private void HarvestSeed() { if (!CanHarvest()) { _.SendMessageToPC(GetPC().Object, "You cannot harvest that plant from here. Move closer and try again."); return; } NWItem shovel = NWItem.Wrap(GetPC().GetLocalObject("SHOVEL_ITEM")); NWObject plant = NWObject.Wrap(GetPC().GetLocalObject("SHOVEL_TARGET_OBJECT")); _farming.HarvestPlant(GetPC(), shovel, (NWPlaceable)plant); EndConversation(); }
public override void OnBlocked() { base.OnBlocked(); NWObject door = NWObject.Wrap(_.GetBlockingDoor()); if (!door.IsValid) { return; } if (_.GetIsDoorActionPossible(door.Object, DOOR_ACTION_OPEN) == TRUE) { _.DoDoorAction(door.Object, DOOR_ACTION_OPEN); } }
public bool Run(params object[] args) { NWPlaceable objSelf = NWPlaceable.Wrap(Object.OBJECT_SELF); foreach (NWItem item in objSelf.InventoryItems) { item.Destroy(); } NWObject parent = NWObject.Wrap(objSelf.GetLocalObject("STRUCTURE_TEMP_PARENT")); parent.DeleteLocalObject("STRUCTURE_TEMP_INVENTORY_OPENED"); objSelf.Destroy(); return(true); }
public bool Run(params object[] args) { NWObject self = NWObject.Wrap(Object.OBJECT_SELF); string script = self.GetLocalString((string)args[0]); Type type = Type.GetType(Assembly.GetExecutingAssembly().GetName().Name + "." + script); if (type == null) { Console.WriteLine("Unable to locate type for LegacyJVMEvent: " + script); return(false); } App.RunEvent(type); return(true); }
private void HandleItemSpecificCastSpell() { NWObject oSpellOrigin = NWObject.Wrap(_.GetSpellCastItem()); // Item specific string script = oSpellOrigin.GetLocalString("JAVA_SCRIPT"); if (!string.IsNullOrWhiteSpace(script)) { // Remove "Item." prefix if it exists. if (script.StartsWith("Item.")) { script = script.Substring(5); } App.RunEvent <LegacyJVMEvent>("Item." + script); } }
public void RegisterPCToAllCombatTargetsForSkill(NWPlayer player, SkillType skillType) { int skillID = (int)skillType; if (!player.IsPlayer) { return; } if (skillID <= 0) { return; } List <NWPlayer> members = new List <NWPlayer>(); NWPlayer member = NWPlayer.Wrap(_.GetFirstFactionMember(player.Object)); while (member.IsValid) { members.Add(member); member = NWPlayer.Wrap(_.GetNextFactionMember(player.Object)); } int nth = 1; NWCreature creature = NWCreature.Wrap(_.GetNearestCreature(CREATURE_TYPE_IS_ALIVE, 1, player.Object, nth, CREATURE_TYPE_PLAYER_CHAR, 0)); while (creature.IsValid) { if (_.GetDistanceBetween(player.Object, creature.Object) > 20.0f) { break; } NWObject target = NWObject.Wrap(_.GetAttackTarget(creature.Object)); if (target.IsValid && members.Contains(target)) { if (target.IsValid && target.Area.Equals(player.Area)) { RegisterPCToNPCForSkill(player, creature, skillID); } } nth++; creature = NWCreature.Wrap(_.GetNearestCreature(CREATURE_TYPE_IS_ALIVE, 1, player.Object, nth, CREATURE_TYPE_PLAYER_CHAR, 0)); } }
public bool Run(params object[] args) { NWPlaceable device = NWPlaceable.Wrap(Object.OBJECT_SELF); NWObject oPC = NWObject.Wrap(_.GetLastClosedBy()); foreach (NWItem item in device.InventoryItems) { string resref = item.Resref; if (resref != "cft_choose_bp" && resref != "cft_craft_item") { _.CopyItem(item.Object, oPC.Object, TRUE); } item.Destroy(); } return(true); }
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 OnModuleLoad() { NWArea area = NWArea.Wrap(_.GetFirstArea()); while (area.IsValid) { NWObject @object = NWObject.Wrap(_.GetFirstObjectInArea(area.Object)); while (@object.IsValid) { HandleSpawnWaypointRename(@object); @object = NWObject.Wrap(_.GetNextObjectInArea(area.Object)); } area = NWArea.Wrap(_.GetNextArea()); } RunProcessor(); }
public bool Run(params object[] args) { NWObject oPC = NWObject.Wrap(_.GetLastUsedBy()); NWPlaceable self = NWPlaceable.Wrap(Object.OBJECT_SELF); string destination = self.GetLocalString("DESTINATION"); int visualEffectID = self.GetLocalInt("VISUAL_EFFECT"); if (visualEffectID > 0) { _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectVisualEffect(visualEffectID), oPC.Object); } oPC.AssignCommand(() => { Location location = _.GetLocation(_.GetWaypointByTag(destination)); _.ActionJumpToLocation(location); }); return(true); }
// Create an empty QBS of given type public QuickBarSlot Empty(QuickBarSlotType type) { QuickBarSlot qbs = new QuickBarSlot { ObjectType = type, Item = NWItem.Wrap(new Object()), SecondaryItem = NWItem.Wrap(new Object()), MultiClass = 0, Resref = "", CommandLabel = "", CommandLine = "", ToolTip = "", INTParam1 = 0, MetaType = 0, DomainLevel = 0, AssociateType = 0, Associate = NWObject.Wrap(new Object()) }; return(qbs); }
public void OnModuleClientEnter() { NWPlayer oPC = NWPlayer.Wrap(_.GetEnteringObject()); if (!oPC.IsPlayer || oPC.IsDM) { return; } NWObject token = NWObject.Wrap(_.GetItemPossessedBy(oPC.Object, "bkg_token")); PlayerCharacter entity = _db.PlayerCharacters.Single(x => x.PlayerID == oPC.GlobalID); if (entity.BackgroundID > 0) { return; } if (!token.IsValid) { _.CreateItemOnObject("bkg_token", oPC.Object); } }
public DamageData GetDamageEventData() { string sFunc = "GetEventData"; DamageData data = new DamageData(); NWNX_CallFunction(NWNX_Damage, sFunc); data.Damager = NWObject.Wrap(NWNX_GetReturnValueObject(NWNX_Damage, sFunc)); data.Bludgeoning = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Pierce = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Slash = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Magical = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Acid = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Cold = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Divine = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Electrical = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Fire = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Negative = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Positive = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Sonic = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); data.Base = NWNX_GetReturnValueInt(NWNX_Damage, sFunc); return(data); }
private void HandleBattlemagePerk(DamageData data) { NWObject target = NWObject.Wrap(Object.OBJECT_SELF); if (!data.Damager.IsPlayer || !target.IsNPC) { return; } if (_.GetHasFeat((int)CustomFeatType.Battlemage, data.Damager.Object) == FALSE) { return; } NWPlayer player = NWPlayer.Wrap(data.Damager.Object); NWItem weapon = NWItem.Wrap(_.GetLastWeaponUsed(player.Object)); if (weapon.CustomItemType != CustomItemType.HeavyBlunt) { return; } if (player.Chest.CustomItemType != CustomItemType.MysticArmor) { return; } int perkRank = _perk.GetPCPerkLevel(player, PerkType.Battlemage); int restoreAmount = 0; bool metRoll = _random.Random(100) + 1 <= 50; switch (perkRank) { case 1 when metRoll: restoreAmount = 1; break; case 2: restoreAmount = 1; break; case 3: restoreAmount = 1; if (metRoll) { restoreAmount++; } break; case 4: restoreAmount = 2; break; case 5: restoreAmount = 2; if (metRoll) { restoreAmount++; } break; case 6: restoreAmount = 3; break; } if (restoreAmount > 0) { RestoreMana(player, restoreAmount); } }
public void OnPlayerDeath() { NWPlayer oPC = NWPlayer.Wrap(_.GetLastPlayerDied()); string corpseName = oPC.Name + "'s Corpse"; NWObject oHostileActor = NWObject.Wrap(_.GetLastHostileActor(oPC.Object)); Location location = oPC.Location; bool hasItems = false; var factionMember = _.GetFirstFactionMember(oHostileActor.Object, FALSE); while (_.GetIsObjectValid(factionMember) == TRUE) { _.ClearPersonalReputation(oPC.Object, factionMember); factionMember = _.GetNextFactionMember(oHostileActor.Object, FALSE); } _.PopUpDeathGUIPanel(oPC.Object, TRUE, TRUE, 0, RespawnMessage); NWPlaceable corpse = NWPlaceable.Wrap(_.CreateObject(OBJECT_TYPE_PLACEABLE, CorpsePlaceableResref, location)); PCCorpse entity = new PCCorpse { AreaTag = _.GetTag(_.GetAreaFromLocation(location)), Name = corpseName, Orientation = _.GetFacingFromLocation(location), PositionX = _.GetPositionFromLocation(location).m_X, PositionY = _.GetPositionFromLocation(location).m_Y, PositionZ = _.GetPositionFromLocation(location).m_Z }; if (oPC.Gold > 0) { corpse.AssignCommand(() => { _.TakeGoldFromCreature(oPC.Gold, oPC.Object); }); hasItems = true; } foreach (NWItem item in oPC.InventoryItems) { if (!item.IsCursed) { _.CopyItem(item.Object, corpse.Object, TRUE); item.Destroy(); hasItems = true; } } if (!hasItems) { corpse.Destroy(); return; } corpse.Name = corpseName; corpse.IdentifiedDescription = corpseName; foreach (NWItem corpseItem in corpse.InventoryItems) { PCCorpseItem corpseItemEntity = new PCCorpseItem { GlobalID = corpseItem.GlobalID, NWItemObject = _serialization.Serialize(corpseItem), PCCorpseItemID = entity.PCCorpseID, ItemName = corpseItem.Name, ItemTag = corpseItem.Tag, ItemResref = corpseItem.Resref }; entity.PCCorpseItems.Add(corpseItemEntity); } _db.PCCorpses.Add(entity); _db.SaveChanges(); corpse.SetLocalInt("CORPSE_ID", (int)entity.PCCorpseID); }
// Gets the target. May be OBJECT_INVALID if no target. // Must be called from an chat or system script handler. public NWObject GetTarget() { NWNX_CallFunction("NWNX_Chat", "GET_TARGET"); return(NWObject.Wrap(NWNX_GetReturnValueObject("NWNX_Chat", "GET_TARGET"))); }
public void AddWaypointMapPin(NWPlayer oPC, string waypointTag, string text, string mapPinTag) { NWObject waypoint = NWObject.Wrap(_.GetWaypointByTag(waypointTag)); SetMapPin(oPC, text, waypoint.Position.m_X, waypoint.Position.m_Y, waypoint.Area, mapPinTag); }
public override void DoAction(NWPlayer player, string pageName, int responseID) { switch (pageName) { case "MainPage": switch (responseID) { // Open Overflow Inventory case 1: NWObject storage = NWObject.Wrap(_.CreateObject(NWScript.OBJECT_TYPE_PLACEABLE, "overflow_storage", player.Location)); player.AssignCommand(() => _.ActionInteractObject(storage.Object)); break; // View Skills case 2: SwitchConversation("ViewSkills"); break; // View Perks case 3: SwitchConversation("ViewPerks"); break; // View Blueprints case 4: SwitchConversation("ViewBlueprints"); break; // Dice Bag case 5: player.SetLocalObject("dmfi_univ_target", player.Object); player.SetLocalLocation("dmfi_univ_location", player.Location); player.SetLocalString("dmfi_univ_conv", "pc_dicebag"); player.AssignCommand(() => { _.ClearAllActions(); _.ActionStartConversation(player.Object, "dmfi_universal", 1, 0); }); break; // Emote Menu case 6: player.SetLocalObject("dmfi_univ_target", player.Object); player.SetLocalLocation("dmfi_univ_location", player.Location); player.SetLocalString("dmfi_univ_conv", "pc_emote"); player.AssignCommand(() => { _.ClearAllActions(); _.ActionStartConversation(player.Object, "dmfi_universal", 1, 0); }); break; // Key Item Categories Page case 7: SwitchConversation("KeyItems"); break; // Modify Clothes case 8: player.AssignCommand(() => _.ActionStartConversation(player.Object, "x0_skill_ctrap", 1, 0)); break; // Character Management case 9: SwitchConversation("CharacterManagement"); break; // Open Trash Can (Destroy Items) case 10: EndConversation(); NWPlaceable trashCan = NWPlaceable.Wrap(_.CreateObject(NWScript.OBJECT_TYPE_PLACEABLE, "reo_trash_can", player.Location)); player.AssignCommand(() => _.ActionInteractObject(trashCan.Object)); _.DelayCommand(0.2f, () => trashCan.IsUseable = false); break; } break; } }
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); }
public void OnModuleActivatedItem() { NWPlayer oPC = NWPlayer.Wrap(_.GetItemActivator()); NWItem oItem = NWItem.Wrap(_.GetItemActivated()); NWObject oTarget = NWObject.Wrap(_.GetItemActivatedTarget()); Location targetLocation = _.GetItemActivatedTargetLocation(); string className = oItem.GetLocalString("JAVA_SCRIPT"); if (className == string.Empty) { className = oItem.GetLocalString("ACTIVATE_JAVA_SCRIPT"); } if (className == string.Empty) { className = oItem.GetLocalString("JAVA_ACTION_SCRIPT"); } if (className == string.Empty) { className = oItem.GetLocalString("SCRIPT"); } if (className == string.Empty) { return; } oPC.ClearAllActions(); // Remove "Item." prefix if it exists. if (className.StartsWith("Item.")) { className = className.Substring(5); } IActionItem item = App.ResolveByInterface <IActionItem>("Item." + className); if (oPC.IsBusy) { oPC.SendMessage("You are busy."); return; } string invalidTargetMessage = item.IsValidTarget(oPC, oItem, oTarget, targetLocation); if (!string.IsNullOrWhiteSpace(invalidTargetMessage)) { oPC.SendMessage(invalidTargetMessage); return; } if (item.MaxDistance() > 0.0f) { if (_.GetDistanceBetween(oPC.Object, oTarget.Object) > item.MaxDistance() || oPC.Area.Resref != oTarget.Area.Resref) { oPC.SendMessage("Your target is too far away."); return; } } CustomData customData = item.StartUseItem(oPC, oItem, oTarget, targetLocation); float delay = item.Seconds(oPC, oItem, oTarget, targetLocation, customData); int animationID = item.AnimationID(); bool faceTarget = item.FaceTarget(); Vector userPosition = oPC.Position; oPC.AssignCommand(() => { oPC.IsBusy = true; if (faceTarget) { _.SetFacingPoint(oTarget.Position); } if (animationID > 0) { _.ActionPlayAnimation(animationID, 1.0f, delay); } }); _nwnxPlayer.StartGuiTimingBar(oPC, delay, string.Empty); oPC.DelayCommand(() => { FinishActionItem(item, oPC, oItem, oTarget, targetLocation, userPosition, customData); }, delay); }
public void OnCreatureDeath(NWCreature creature) { int npcGroupID = creature.GetLocalInt("NPC_GROUP"); if (npcGroupID <= 0) { return; } NWObject oKiller = NWObject.Wrap(_.GetLastKiller()); if (_.GetIsPC(oKiller.Object) == FALSE || _.GetIsDM(oKiller.Object) == TRUE) { return; } string areaResref = creature.Area.Resref; NWPlayer oPC = NWPlayer.Wrap(_.GetFirstFactionMember(oKiller.Object)); while (oPC.IsValid) { if (areaResref != oPC.Area.Resref) { continue; } if (_.GetDistanceBetween(creature.Object, oPC.Object) == 0.0f || _.GetDistanceBetween(creature.Object, oPC.Object) > 20.0f) { continue; } List <PCQuestKillTargetProgress> killTargets = _db.PCQuestKillTargetProgresses.Where(x => x.PlayerID == oPC.GlobalID && x.NPCGroupID == npcGroupID).ToList(); foreach (PCQuestKillTargetProgress kt in killTargets) { kt.RemainingToKill--; string targetGroupName = kt.NPCGroup.Name; string questName = kt.PcQuestStatus.Quest.Name; string updateMessage = "[" + questName + "] " + targetGroupName + " remaining: " + kt.RemainingToKill; if (kt.RemainingToKill <= 0) { _db.PCQuestKillTargetProgresses.Remove(kt); updateMessage += " " + _color.Green(" {COMPLETE}"); if (kt.PcQuestStatus.PCQuestKillTargetProgresses.Count - 1 <= 0) { AdvanceQuestState(oPC, kt.PcQuestStatus.QuestID); } } _db.SaveChanges(); string finalMessage = updateMessage; var pc = oPC; oPC.DelayCommand(() => { pc.SendMessage(finalMessage); }, 1.0f); } oPC = NWPlayer.Wrap(_.GetNextFactionMember(oKiller.Object)); } }