public bool Run(params object[] args) { NWPlaceable point = (Object.OBJECT_SELF); NWPlayer player = _.GetLastClosedBy(); if (!player.IsPlayer) { return(false); } bool isFullyHarvested = point.GetLocalInt("SCAVENGE_POINT_FULLY_HARVESTED") == 1; if (!point.InventoryItems.Any() && isFullyHarvested) { string seed = point.GetLocalString("SCAVENGE_POINT_SEED"); if (!string.IsNullOrWhiteSpace(seed)) { _.CreateObject(_.OBJECT_TYPE_ITEM, seed, point.Location); } point.Destroy(); FarmingService.RemoveGrowingPlant(point); } return(false); }
private void HarvestSeed() { if (!CanHarvest()) { _.SendMessageToPC(GetPC().Object, "You cannot harvest that plant from here. Move closer and try again."); return; } NWItem shovel = (GetPC().GetLocalObject("SHOVEL_ITEM")); NWObject plant = (GetPC().GetLocalObject("SHOVEL_TARGET_OBJECT")); FarmingService.HarvestPlant(GetPC(), shovel, (NWPlaceable)plant); EndConversation(); }
public bool Run(params object[] args) { NWPlayer oPC = (_.GetLastDisturbed()); if (!oPC.IsPlayer) { return(false); } NWItem oItem = (_.GetInventoryDisturbItem()); NWPlaceable point = (Object.OBJECT_SELF); int disturbType = _.GetInventoryDisturbType(); if (disturbType == _.INVENTORY_DISTURB_TYPE_ADDED) { ItemService.ReturnItem(oPC, oItem); } else { if (!point.InventoryItems.Any() && point.GetLocalInt("SCAVENGE_POINT_FULLY_HARVESTED") == 1) { string seed = point.GetLocalString("SCAVENGE_POINT_SEED"); if (!string.IsNullOrWhiteSpace(seed)) { _.CreateObject(_.OBJECT_TYPE_ITEM, seed, point.Location); int perkLevel = PerkService.GetCreaturePerkLevel(oPC, PerkType.SeedPicker); if (RandomService.Random(100) + 1 <= perkLevel * 10) { _.CreateObject(_.OBJECT_TYPE_ITEM, seed, point.Location); } } point.Destroy(); FarmingService.RemoveGrowingPlant(point); } } return(true); }
public bool Run(params object[] args) { NWPlaceable plant = (Object.OBJECT_SELF); string growingPlantID = plant.GetLocalString("GROWING_PLANT_ID"); if (string.IsNullOrWhiteSpace(growingPlantID)) { return(false); } NWPlayer oPC = (_.GetLastUsedBy()); Data.Entity.GrowingPlant growingPlant = FarmingService.GetGrowingPlantByID(new Guid(growingPlantID)); if (growingPlant.WaterStatus <= 0) { oPC.SendMessage("This plant doesn't seem to need anything right now."); return(true); } oPC.SendMessage("This plant needs to be watered. Use a Water Jug on it to water it. These can be crafted with the Metalworking skill."); return(true); }
// ReSharper disable once UnusedMember.Local private static void Main() { // Breaking the rules for the examine event because the result of the services is used in the following // service call. We still signal an event for this, but in general all of the logic should go into this method. using (new Profiler(nameof(mod_on_examine))) { NWPlayer examiner = (Object.OBJECT_SELF); NWObject examinedObject = NWNXEvents.OnExamineObject_GetTarget(); if (ExaminationService.OnModuleExamine(examiner, examinedObject)) { MessageHub.Instance.Publish(new OnModuleExamine()); return; } string description = _.GetDescription(examinedObject.Object, _.TRUE) + "\n\n"; if (examinedObject.IsCreature) { int racialID = Convert.ToInt32(_.Get2DAString("racialtypes", "Name", _.GetRacialType(examinedObject))); string racialtype = _.GetStringByStrRef(racialID); description += ColorTokenService.Green("Racial Type: ") + racialtype; } description = ModService.OnModuleExamine(description, examiner, examinedObject); description = ItemService.OnModuleExamine(description, examiner, examinedObject); description = DurabilityService.OnModuleExamine(description, examinedObject); description = FarmingService.OnModuleExamine(description, examinedObject); if (!string.IsNullOrWhiteSpace(description)) { _.SetDescription(examinedObject.Object, description, _.FALSE); _.SetDescription(examinedObject.Object, description); } } MessageHub.Instance.Publish(new OnModuleExamine()); }
public bool Run(params object[] args) { NWPlaceable point = (Object.OBJECT_SELF); NWPlayer oPC = (_.GetLastOpenedBy()); if (!oPC.IsPlayer) { return(false); } var effectiveStats = PlayerStatService.GetPlayerItemEffectiveStats(oPC); const int baseChanceToFullyHarvest = 50; bool alwaysDestroys = point.GetLocalInt("SCAVENGE_POINT_ALWAYS_DESTROYS") == 1; bool hasBeenSearched = point.GetLocalInt("SCAVENGE_POINT_FULLY_HARVESTED") == 1; if (hasBeenSearched) { oPC.SendMessage("There's nothing left to harvest here..."); return(true); } // Not fully harvested but the timer hasn't counted down yet. int refillTick = point.GetLocalInt("SCAVENGE_POINT_REFILL_TICKS"); if (refillTick > 0) { oPC.SendMessage("You couldn't find anything new here. Check back later..."); return(true); } if (!oPC.IsPlayer && !oPC.IsDM) { return(false); } int rank = SkillService.GetPCSkillRank(oPC, SkillType.Scavenging); int lootTableID = point.GetLocalInt("SCAVENGE_POINT_LOOT_TABLE_ID"); int level = point.GetLocalInt("SCAVENGE_POINT_LEVEL"); int delta = level - rank; if (delta > 8) { oPC.SendMessage("You aren't skilled enough to scavenge through this. (Required Level: " + (level - 8) + ")"); oPC.AssignCommand(() => _.ActionInteractObject(point.Object)); return(true); } int dc = 6 + delta; if (dc <= 4) { dc = 4; } int searchAttempts = 1 + CalculateSearchAttempts(oPC); int luck = PerkService.GetPCPerkLevel(oPC, PerkType.Lucky) + effectiveStats.Luck; if (RandomService.Random(100) + 1 <= luck / 2) { dc--; } oPC.AssignCommand(() => _.ActionPlayAnimation(_.ANIMATION_LOOPING_GET_LOW, 1.0f, 2.0f)); for (int attempt = 1; attempt <= searchAttempts; attempt++) { int roll = RandomService.Random(20) + 1; if (roll >= dc) { oPC.FloatingText(ColorTokenService.SkillCheck("Search: *success*: (" + roll + " vs. DC: " + dc + ")")); ItemVO spawnItem = LootService.PickRandomItemFromLootTable(lootTableID); if (spawnItem == null) { return(false); } if (!string.IsNullOrWhiteSpace(spawnItem.Resref) && spawnItem.Quantity > 0) { NWItem resource = _.CreateItemOnObject(spawnItem.Resref, point.Object, spawnItem.Quantity); var componentIP = resource.ItemProperties.FirstOrDefault(x => _.GetItemPropertyType(x) == (int)CustomItemPropertyType.ComponentType); if (componentIP != null) { // Add properties to the item based on Scavenging skill. Similar logic to the resource harvester. var chance = RandomService.Random(1, 100) + PerkService.GetPCPerkLevel(oPC, PerkType.Lucky) + effectiveStats.Luck; ResourceQuality quality; if (chance < 50) { quality = ResourceQuality.Low; } else if (chance < 75) { quality = ResourceQuality.Normal; } else if (chance < 95) { quality = ResourceQuality.High; } else { quality = ResourceQuality.VeryHigh; } int ipBonusChance = ResourceService.CalculateChanceForComponentBonus(oPC, (level / 10 + 1), quality, true); if (RandomService.Random(1, 100) <= ipBonusChance) { var ip = ResourceService.GetRandomComponentBonusIP(ResourceQuality.Normal); BiowareXP2.IPSafeAddItemProperty(resource, ip.Item1, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true); switch (ip.Item2) { case 0: resource.Name = ColorTokenService.Green(resource.Name); break; case 1: resource.Name = ColorTokenService.Blue(resource.Name); break; case 2: resource.Name = ColorTokenService.Purple(resource.Name); break; case 3: resource.Name = ColorTokenService.Orange(resource.Name); break; } } } } float xp = SkillService.CalculateRegisteredSkillLevelAdjustedXP(200, level, rank); SkillService.GiveSkillXP(oPC, SkillType.Scavenging, (int)xp); } else { oPC.FloatingText(ColorTokenService.SkillCheck("Search: *failure*: (" + roll + " vs. DC: " + dc + ")")); float xp = SkillService.CalculateRegisteredSkillLevelAdjustedXP(50, level, rank); SkillService.GiveSkillXP(oPC, SkillType.Scavenging, (int)xp); } dc += RandomService.Random(3) + 1; } // Chance to destroy the scavenge point. int chanceToFullyHarvest = baseChanceToFullyHarvest - (PerkService.GetPCPerkLevel(oPC, PerkType.CarefulScavenger) * 5); string growingPlantID = point.GetLocalString("GROWING_PLANT_ID"); if (!string.IsNullOrWhiteSpace(growingPlantID)) { Data.Entity.GrowingPlant growingPlant = FarmingService.GetGrowingPlantByID(new Guid(growingPlantID)); chanceToFullyHarvest = chanceToFullyHarvest - (growingPlant.LongevityBonus); } if (chanceToFullyHarvest <= 5) { chanceToFullyHarvest = 5; } if (alwaysDestroys || RandomService.Random(100) + 1 <= chanceToFullyHarvest) { point.SetLocalInt("SCAVENGE_POINT_FULLY_HARVESTED", 1); oPC.SendMessage("This resource has been fully harvested..."); } // Otherwise the scavenge point will be refilled in 10-20 minutes. else { point.SetLocalInt("SCAVENGE_POINT_REFILL_TICKS", 100 + RandomService.Random(100)); } point.SetLocalInt("SCAVENGE_POINT_DESPAWN_TICKS", 30); return(true); }
public bool Run(params object[] args) { NWPlaceable point = (Object.OBJECT_SELF); NWPlayer oPC = (_.GetLastOpenedBy()); if (!oPC.IsPlayer) { return(false); } var effectiveStats = PlayerStatService.GetPlayerItemEffectiveStats(oPC); const int baseChanceToFullyHarvest = 50; bool alwaysDestroys = point.GetLocalInt("SCAVENGE_POINT_ALWAYS_DESTROYS") == 1; bool hasBeenSearched = point.GetLocalInt("SCAVENGE_POINT_FULLY_HARVESTED") == 1; if (hasBeenSearched) { oPC.SendMessage("There's nothing left to harvest here..."); return(true); } // Not fully harvested but the timer hasn't counted down yet. int refillTick = point.GetLocalInt("SCAVENGE_POINT_REFILL_TICKS"); if (refillTick > 0) { oPC.SendMessage("You couldn't find anything new here. Check back later..."); return(true); } if (!oPC.IsPlayer && !oPC.IsDM) { return(false); } int rank = SkillService.GetPCSkillRank(oPC, SkillType.Scavenging); int lootTableID = point.GetLocalInt("SCAVENGE_POINT_LOOT_TABLE_ID"); int level = point.GetLocalInt("SCAVENGE_POINT_LEVEL"); int delta = level - rank; if (delta > 8) { oPC.SendMessage("You aren't skilled enough to scavenge through this. (Required Level: " + (level - 8) + ")"); oPC.AssignCommand(() => _.ActionInteractObject(point.Object)); return(true); } int dc = 6 + delta; if (dc <= 4) { dc = 4; } int searchAttempts = 1 + CalculateSearchAttempts(oPC); int luck = PerkService.GetCreaturePerkLevel(oPC, PerkType.Lucky) + effectiveStats.Luck; if (RandomService.Random(100) + 1 <= luck / 2) { dc--; } oPC.AssignCommand(() => _.ActionPlayAnimation(_.ANIMATION_LOOPING_GET_LOW, 1.0f, 2.0f)); for (int attempt = 1; attempt <= searchAttempts; attempt++) { int roll = RandomService.Random(20) + 1; if (roll >= dc) { oPC.FloatingText(ColorTokenService.SkillCheck("Search: *success*: (" + roll + " vs. DC: " + dc + ")")); ItemVO spawnItem = LootService.PickRandomItemFromLootTable(lootTableID); if (spawnItem == null) { return(false); } if (!string.IsNullOrWhiteSpace(spawnItem.Resref) && spawnItem.Quantity > 0) { _.CreateItemOnObject(spawnItem.Resref, point.Object, spawnItem.Quantity); } float xp = SkillService.CalculateRegisteredSkillLevelAdjustedXP(200, level, rank); SkillService.GiveSkillXP(oPC, SkillType.Scavenging, (int)xp); } else { oPC.FloatingText(ColorTokenService.SkillCheck("Search: *failure*: (" + roll + " vs. DC: " + dc + ")")); float xp = SkillService.CalculateRegisteredSkillLevelAdjustedXP(50, level, rank); SkillService.GiveSkillXP(oPC, SkillType.Scavenging, (int)xp); } dc += RandomService.Random(3) + 1; } // Chance to destroy the scavenge point. int chanceToFullyHarvest = baseChanceToFullyHarvest - (PerkService.GetCreaturePerkLevel(oPC, PerkType.CarefulScavenger) * 5); string growingPlantID = point.GetLocalString("GROWING_PLANT_ID"); if (!string.IsNullOrWhiteSpace(growingPlantID)) { Data.Entity.GrowingPlant growingPlant = FarmingService.GetGrowingPlantByID(new Guid(growingPlantID)); chanceToFullyHarvest = chanceToFullyHarvest - (growingPlant.LongevityBonus); } if (chanceToFullyHarvest <= 5) { chanceToFullyHarvest = 5; } if (alwaysDestroys || RandomService.Random(100) + 1 <= chanceToFullyHarvest) { point.SetLocalInt("SCAVENGE_POINT_FULLY_HARVESTED", 1); oPC.SendMessage("This resource has been fully harvested..."); } // Otherwise the scavenge point will be refilled in 10-20 minutes. else { point.SetLocalInt("SCAVENGE_POINT_REFILL_TICKS", 100 + RandomService.Random(100)); } point.SetLocalInt("SCAVENGE_POINT_DESPAWN_TICKS", 30); return(true); }
public bool Run(params object[] args) { NWPlaceable container = (Object.OBJECT_SELF); NWPlayer oPC = (_.GetLastDisturbed()); int type = _.GetInventoryDisturbType(); NWItem item = (_.GetInventoryDisturbItem()); var effectiveStats = PlayerStatService.GetPlayerItemEffectiveStats(oPC); if (type != _.INVENTORY_DISTURB_TYPE_ADDED) { return(false); } int plantID = item.GetLocalInt("PLANT_ID"); if (plantID <= 0) { ItemService.ReturnItem(oPC, item); oPC.SendMessage("You cannot plant that item."); return(true); } Plant plant = FarmingService.GetPlantByID(plantID); if (plant == null) { ItemService.ReturnItem(oPC, item); oPC.SendMessage("You cannot plant that item."); return(true); } int rank = SkillService.GetPCSkillRank(oPC, SkillType.Farming); if (rank + 2 < plant.Level) { ItemService.ReturnItem(oPC, item); oPC.SendMessage("You do not have enough Farming skill to plant that seed. (Required: " + (plant.Level - 2) + ")"); return(true); } item.Destroy(); string areaTag = container.Area.Tag; Location plantLocation = container.Location; int perkBonus = PerkService.GetPCPerkLevel(oPC, PerkType.FarmingEfficiency) * 2; int ticks = (int)(plant.BaseTicks - ((PerkService.GetPCPerkLevel(oPC, PerkType.ExpertFarmer) * 0.05f)) * plant.BaseTicks); Data.Entity.GrowingPlant growingPlant = new Data.Entity.GrowingPlant { PlantID = plant.ID, RemainingTicks = ticks, LocationAreaTag = areaTag, LocationOrientation = _.GetFacingFromLocation(plantLocation), LocationX = _.GetPositionFromLocation(plantLocation).m_X, LocationY = _.GetPositionFromLocation(plantLocation).m_Y, LocationZ = _.GetPositionFromLocation(plantLocation).m_Z, IsActive = true, DateCreated = DateTime.UtcNow, LongevityBonus = perkBonus }; DataService.SubmitDataChange(growingPlant, DatabaseActionType.Insert); NWPlaceable hole = (container.GetLocalObject("FARM_SMALL_HOLE")); NWPlaceable plantPlc = (_.CreateObject(_.OBJECT_TYPE_PLACEABLE, "growing_plant", hole.Location)); plantPlc.SetLocalString("GROWING_PLANT_ID", growingPlant.ID.ToString()); plantPlc.Name = "Growing Plant (" + plant.Name + ")"; container.Destroy(); hole.Destroy(); int xp = (int)SkillService.CalculateRegisteredSkillLevelAdjustedXP(200, plant.Level, rank); if (RandomService.Random(100) + 1 <= PerkService.GetPCPerkLevel(oPC, PerkType.Lucky) + effectiveStats.Luck) { xp *= 2; } SkillService.GiveSkillXP(oPC, SkillType.Farming, xp); return(true); }