Esempio n. 1
0
        public bool Run(params object[] args)
        {
            NWPlayer    oPC         = NWPlayer.Wrap(_.GetLastDisturbed());
            NWItem      oItem       = NWItem.Wrap(_.GetInventoryDisturbItem());
            NWPlaceable point       = NWPlaceable.Wrap(NWN.Object.OBJECT_SELF);
            int         disturbType = _.GetInventoryDisturbType();

            if (disturbType == INVENTORY_DISTURB_TYPE_ADDED)
            {
                _item.ReturnItem(oPC, oItem);
            }
            else
            {
                if (point.InventoryItems.Count <= 0 && point.GetLocalInt("FORAGE_POINT_FULLY_HARVESTED") == 1)
                {
                    string seed = point.GetLocalString("FORAGE_POINT_SEED");
                    if (!string.IsNullOrWhiteSpace(seed))
                    {
                        _.CreateObject(OBJECT_TYPE_ITEM, seed, point.Location);

                        int perkLevel = _perk.GetPCPerkLevel(oPC, PerkType.SeedPicker);
                        if (_random.Random(100) + 1 <= perkLevel * 10)
                        {
                            _.CreateObject(OBJECT_TYPE_ITEM, seed, point.Location);
                        }
                    }

                    point.Destroy();
                    _farming.RemoveGrowingPlant(point);
                }
            }
            return(true);
        }
Esempio n. 2
0
        public bool Run(params object[] args)
        {
            NWPlaceable objSelf        = (Object.OBJECT_SELF);
            bool        hasSpawnedProp = objSelf.GetLocalInt("RESOURCE_PROP_SPAWNED") == 1;

            if (hasSpawnedProp)
            {
                return(false);
            }

            string propResref = objSelf.GetLocalString("RESOURCE_PROP");

            if (string.IsNullOrWhiteSpace(propResref))
            {
                return(false);
            }

            Location    location = objSelf.Location;
            NWPlaceable prop     = (_.CreateObject(NWScript.OBJECT_TYPE_PLACEABLE, propResref, location));

            objSelf.SetLocalObject("RESOURCE_PROP_OBJ", prop.Object);
            objSelf.SetLocalInt("RESOURCE_PROP_SPAWNED", 1);

            _.SetEventScript(objSelf, NWScript.EVENT_SCRIPT_PLACEABLE_ON_HEARTBEAT, string.Empty);
            return(true);
        }
Esempio n. 3
0
        public void OnModuleLoad()
        {
            List <GrowingPlant> plants = _data.Where <GrowingPlant>(x => x.IsActive).ToList();

            foreach (GrowingPlant growingPlant in plants)
            {
                var    plant  = _data.Get <Plant>(growingPlant.PlantID);
                string resref = "growing_plant";
                if (growingPlant.RemainingTicks <= 0)
                {
                    resref = plant.Resref;
                }

                NWArea      area     = (_.GetObjectByTag(growingPlant.LocationAreaTag));
                Vector      position = _.Vector((float)growingPlant.LocationX, (float)growingPlant.LocationY, (float)growingPlant.LocationZ);
                Location    location = _.Location(area.Object, position, (float)growingPlant.LocationOrientation);
                NWPlaceable plantPlc = (_.CreateObject(NWScript.OBJECT_TYPE_PLACEABLE, resref, location));
                plantPlc.SetLocalString("GROWING_PLANT_ID", growingPlant.ID.ToString());

                if (growingPlant.RemainingTicks > 0)
                {
                    plantPlc.Name = "Growing Plant (" + plant.Name + ")";
                }
            }
        }
Esempio n. 4
0
        public NWPlaceable SpawnStructure(NWArea area, Guid pcBaseStructureID)
        {
            PCBaseStructure pcStructure   = _data.Get <PCBaseStructure>(pcBaseStructureID);
            PCBase          pcBase        = _data.Get <PCBase>(pcStructure.PCBaseID);
            BaseStructure   baseStructure = _data.Get <BaseStructure>(pcStructure.BaseStructureID);
            var             exteriorStyle = _data.Get <BuildingStyle>(pcStructure.ExteriorStyleID);

            NWLocation location = _.Location(area.Object,
                                             _.Vector((float)pcStructure.LocationX, (float)pcStructure.LocationY, (float)pcStructure.LocationZ),
                                             (float)pcStructure.LocationOrientation);

            BaseStructureType structureType = (BaseStructureType)baseStructure.BaseStructureTypeID;
            string            resref        = baseStructure.PlaceableResref;

            List <AreaStructure> areaStructures = area.Data["BASE_SERVICE_STRUCTURES"];

            if (string.IsNullOrWhiteSpace(resref) &&
                structureType == BaseStructureType.Building)
            {
                resref = exteriorStyle.Resref;
            }

            NWPlaceable plc = (_.CreateObject(OBJECT_TYPE_PLACEABLE, resref, location));

            plc.SetLocalString("PC_BASE_STRUCTURE_ID", pcStructure.ID.ToString());
            plc.SetLocalInt("REQUIRES_BASE_POWER", baseStructure.RequiresBasePower ? 1 : 0);
            plc.SetLocalString("ORIGINAL_SCRIPT_CLOSED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_CLOSED));
            plc.SetLocalString("ORIGINAL_SCRIPT_DAMAGED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_DAMAGED));
            plc.SetLocalString("ORIGINAL_SCRIPT_DEATH", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_DEATH));
            plc.SetLocalString("ORIGINAL_SCRIPT_HEARTBEAT", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_HEARTBEAT));
            plc.SetLocalString("ORIGINAL_SCRIPT_INVENTORYDISTURBED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_INVENTORYDISTURBED));
            plc.SetLocalString("ORIGINAL_SCRIPT_LOCK", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_LOCK));
            plc.SetLocalString("ORIGINAL_SCRIPT_MELEEATTACKED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_MELEEATTACKED));
            plc.SetLocalString("ORIGINAL_SCRIPT_OPEN", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_OPEN));
            plc.SetLocalString("ORIGINAL_SCRIPT_SPELLCASTAT", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_SPELLCASTAT));
            plc.SetLocalString("ORIGINAL_SCRIPT_UNLOCK", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_UNLOCK));
            plc.SetLocalString("ORIGINAL_SCRIPT_USED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_USED));
            plc.SetLocalString("ORIGINAL_SCRIPT_USER_DEFINED_EVENT", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_USER_DEFINED_EVENT));
            plc.SetLocalString("ORIGINAL_SCRIPT_LEFT_CLICK", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_LEFT_CLICK));
            plc.SetLocalString("ORIGINAL_JAVA_SCRIPT_1", _.GetLocalString(plc.Object, "JAVA_SCRIPT_1"));

            NWPlaceable door = null;

            if (structureType == BaseStructureType.Building)
            {
                door = SpawnBuildingDoor(exteriorStyle.DoorRule, plc);
                areaStructures.Add(new AreaStructure(pcStructure.PCBaseID, pcStructure.ID, door, false, null));
            }
            areaStructures.Add(new AreaStructure(pcStructure.PCBaseID, pcStructure.ID, plc, true, door));

            if (area.IsInstance && area.GetLocalInt("PC_BASE_STRUCTURE_ID") > 0)
            {
                if (DateTime.UtcNow > pcBase.DateFuelEnds && pcBase.Fuel <= 0)
                {
                    ToggleInstanceObjectPower(area, false);
                }
            }

            return(plc);
        }
Esempio n. 5
0
        public void Tick(NWCreature oCaster, NWObject oTarget, int currentTick, int effectiveLevel, string data)
        {
            if (currentTick % 2 == 0)
            {
                return;
            }

            Location    location = oTarget.Location;
            NWPlaceable oBlood   = (_.CreateObject(NWScript.OBJECT_TYPE_PLACEABLE, "plc_bloodstain", location));

            oBlood.Destroy(48.0f);

            int amount = 1;

            if (!string.IsNullOrWhiteSpace(data))
            {
                amount = Convert.ToInt32(data);
            }

            oCaster.AssignCommand(() =>
            {
                Effect damage = _.EffectDamage(amount);
                _.ApplyEffectToObject(NWScript.DURATION_TYPE_INSTANT, damage, oTarget.Object);
            });
        }
Esempio n. 6
0
        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(NWScript.OBJECT_TYPE_ITEM, seed, point.Location);
                }

                point.Destroy();
                _farming.RemoveGrowingPlant(point);
            }
            return(false);
        }
Esempio n. 7
0
        public void OnModuleLoad()
        {
            List <PCCorpse> entities = _db.PCCorpses.ToList();

            foreach (PCCorpse entity in entities)
            {
                NWArea      area     = NWArea.Wrap(_.GetObjectByTag(entity.AreaTag));
                Vector      position = new Vector((float)entity.PositionX, (float)entity.PositionY, (float)entity.PositionZ);
                Location    location = _.Location(area.Object, position, (float)entity.Orientation);
                NWPlaceable corpse   = NWPlaceable.Wrap(_.CreateObject(OBJECT_TYPE_PLACEABLE, CorpsePlaceableResref, location));
                corpse.Name = entity.Name;
                corpse.IdentifiedDescription = entity.Name;
                corpse.SetLocalInt("CORPSE_ID", (int)entity.PCCorpseID);

                foreach (PCCorpseItem item in entity.PCCorpseItems)
                {
                    _serialization.DeserializeItem(item.NWItemObject, corpse);
                }
            }
        }
Esempio n. 8
0
        public void Tick(NWCreature oCaster, NWObject oTarget)
        {
            Location    location = oTarget.Location;
            NWPlaceable oBlood   = NWPlaceable.Wrap(_.CreateObject(OBJECT_TYPE_PLACEABLE, "plc_bloodstain", location));

            oBlood.Destroy(48.0f);

            oCaster.AssignCommand(() =>
            {
                Effect damage = _.EffectDamage(1);
                _.ApplyEffectToObject(DURATION_TYPE_INSTANT, damage, oTarget.Object);
            });
        }
Esempio n. 9
0
        public void RequestItemsFromPC(NWPlayer oPC, NWObject questOwner, int questID)
        {
            if (!oPC.IsPlayer)
            {
                return;
            }

            PCQuestStatus pcStatus = _data.SingleOrDefault <PCQuestStatus>(x => x.PlayerID == oPC.GlobalID && x.QuestID == questID);

            if (pcStatus == null)
            {
                oPC.SendMessage("You have not accepted this quest yet.");
                return;
            }

            QuestState questState       = _data.Get <QuestState>(pcStatus.CurrentQuestStateID);
            var        requiredKeyItems = _data.Where <QuestRequiredKeyItem>(x => x.QuestStateID == pcStatus.CurrentQuestStateID);

            foreach (QuestRequiredKeyItem ki in requiredKeyItems)
            {
                if (!_keyItem.PlayerHasKeyItem(oPC, ki.KeyItemID))
                {
                    oPC.SendMessage("You are missing a required key item.");
                    return;
                }
            }

            if (questState.QuestTypeID != (int)QuestType.CollectItems)
            {
                oPC.SendMessage("The quest state you are currently on is not configured to collect items. Please inform an admin of this issue. (QuestID: " + questID + ")");
                return;
            }

            Location    location  = oPC.Location;
            NWPlaceable collector = (_.CreateObject(OBJECT_TYPE_PLACEABLE, "qst_item_collect", location));

            collector.SetLocalObject("QUEST_OWNER", questOwner);

            collector.AssignCommand(() =>
            {
                _.SetFacingPoint(oPC.Position);
            });
            collector.SetLocalInt("QUEST_ID", questID);

            oPC.AssignCommand(() =>
            {
                _.ActionInteractObject(collector.Object);
            });
        }
Esempio n. 10
0
        private bool CheckItemCounts(NWPlayer oPC, NWPlaceable device, ICollection <CraftBlueprintComponent> componentList)
        {
            bool allComponentsFound             = false;
            Dictionary <string, int> components = new Dictionary <string, int>();

            foreach (CraftBlueprintComponent component in componentList)
            {
                components.Add(component.ItemResref, component.Quantity);
            }

            NWPlaceable tempStorage = NWPlaceable.Wrap(_.CreateObject(OBJECT_TYPE_PLACEABLE, "craft_temp_store", device.Location));

            device.SetLocalObject("CRAFT_TEMP_STORAGE", tempStorage.Object);

            foreach (NWItem item in device.InventoryItems)
            {
                if (components.ContainsKey(item.Resref) && components[item.Resref] > 0)
                {
                    components[item.Resref] = components[item.Resref] - 1;

                    _.CopyItem(item.Object, tempStorage.Object, TRUE);
                    item.Destroy();
                }

                int remainingQuantities = 0;
                foreach (int quantity in components.Values)
                {
                    remainingQuantities += quantity;
                }

                if (remainingQuantities <= 0)
                {
                    allComponentsFound = true;
                    break;
                }
            }

            if (!allComponentsFound)
            {
                foreach (NWItem item in tempStorage.InventoryItems)
                {
                    _.CopyItem(item.Object, device.Object, TRUE);
                    item.Destroy();
                }
                oPC.IsBusy = false;
            }

            return(allComponentsFound);
        }
Esempio n. 11
0
        public bool Run(params object[] args)
        {
            NWPlaceable objSelf = NWPlaceable.Wrap(Object.OBJECT_SELF);
            bool hasSpawnedProp = objSelf.GetLocalInt("RESOURCE_PROP_SPAWNED") == 1;
            if (hasSpawnedProp) return false;

            string propResref = objSelf.GetLocalString("RESOURCE_PROP");
            if (string.IsNullOrWhiteSpace(propResref)) return false;

            Location location = objSelf.Location;
            NWPlaceable prop = NWPlaceable.Wrap(_.CreateObject(OBJECT_TYPE_PLACEABLE, propResref, location));
            objSelf.SetLocalObject("RESOURCE_PROP_OBJ", prop.Object);
            objSelf.SetLocalInt("RESOURCE_PROP_SPAWNED", 1);
            return true;
        }
Esempio n. 12
0
        public void RequestItemsFromPC(NWPlayer oPC, NWObject questOwner, int questID, int sequenceID)
        {
            if (!oPC.IsPlayer)
            {
                return;
            }

            PCQuestStatus pcStatus = _db.PCQuestStatus.Single(x => x.PlayerID == oPC.GlobalID && x.QuestID == questID);

            if (pcStatus == null)
            {
                oPC.SendMessage("You have not accepted this quest yet.");
                return;
            }

            QuestState questState = pcStatus.CurrentQuestState;

            if (questState.Sequence != sequenceID)
            {
                oPC.SendMessage("SequenceID mismatch. Please inform an admin there is a bug with this quest. (QuestID = " + questID + ")");
                return;
            }

            foreach (QuestRequiredKeyItemList ki in questState.QuestRequiredKeyItemLists)
            {
                if (!_keyItem.PlayerHasKeyItem(oPC, ki.KeyItemID))
                {
                    oPC.SendMessage("You are missing a required key item.");
                    return;
                }
            }

            Location    location  = oPC.Location;
            NWPlaceable collector = NWPlaceable.Wrap(_.CreateObject(OBJECT_TYPE_PLACEABLE, "qst_item_collect", location));

            collector.AssignCommand(() =>
            {
                _.SetFacingPoint(oPC.Position);
            });
            collector.SetLocalInt("QUEST_ID", questID);
            _.CreateItemOnObject(SubmitQuestItemResref, collector.Object);

            oPC.AssignCommand(() =>
            {
                _.ActionInteractObject(collector.Object);
            });
        }
Esempio n. 13
0
        private void StartSmelt(NWPlaceable forge, NWPlayer pc, NWItem item)
        {
            int charges = forge.GetLocalInt("FORGE_CHARGES");

            if (item.Resref == "power_core")
            {
                item.Destroy();
                charges += 10 + CalculatePerkCoalBonusCharges(pc) + GetPowerCoreDurability(item) * 2;
                forge.SetLocalInt("FORGE_CHARGES", charges);

                NWPlaceable flames = (forge.GetLocalObject("FORGE_FLAMES"));
                if (!flames.IsValid)
                {
                    Vector   flamePosition = _biowarePosition.GetChangedPosition(forge.Position, 0.36f, forge.Facing);
                    Location flameLocation = _.Location(forge.Area.Object, flamePosition, 0.0f);
                    flames = (_.CreateObject(NWScript.OBJECT_TYPE_PLACEABLE, "forge_flame", flameLocation));
                    forge.SetLocalObject("FORGE_FLAMES", flames.Object);
                }

                return;
            }
            else if (charges <= 0)
            {
                ReturnItemToPC(pc, item, "You must power the refinery with a power unit before refining.");
                return;
            }

            // Ready to smelt
            float baseCraftDelay = 18.0f - (18.0f * _perk.GetPCPerkLevel(pc, PerkType.SpeedyRefining) * 0.1f);

            pc.IsBusy = true;
            _nwnxPlayer.StartGuiTimingBar(pc, baseCraftDelay, string.Empty);

            // Any component bonuses on the ore get applied to the end product.
            var itemProperties = item.ItemProperties.Where(x =>
                                                           _.GetItemPropertyType(x) == (int)CustomItemPropertyType.ComponentBonus ||
                                                           _.GetItemPropertyType(x) == (int)CustomItemPropertyType.RecommendedLevel).ToList();

            string itemResref = item.Resref;

            pc.DelayEvent <CompleteSmelt>(baseCraftDelay, pc, itemResref, itemProperties);

            _.ApplyEffectToObject(NWScript.DURATION_TYPE_TEMPORARY, _.EffectCutsceneImmobilize(), pc.Object, baseCraftDelay);
            pc.AssignCommand(() => _.ActionPlayAnimation(NWScript.ANIMATION_LOOPING_GET_MID, 1.0f, baseCraftDelay));
            item.Destroy();
        }
Esempio n. 14
0
        public bool Run(params object[] args)
        {
            NWPlaceable point = NWPlaceable.Wrap(Object.OBJECT_SELF);

            bool isFullyHarvested = point.GetLocalInt("FORAGE_POINT_FULLY_HARVESTED") == 1;

            if (point.InventoryItems.Count <= 0 && isFullyHarvested)
            {
                string seed = point.GetLocalString("FORAGE_POINT_SEED");
                if (!string.IsNullOrWhiteSpace(seed))
                {
                    _.CreateObject(NWScript.OBJECT_TYPE_ITEM, seed, point.Location);
                }

                point.Destroy();
                _farming.RemoveGrowingPlant(point);
            }
            return(false);
        }
Esempio n. 15
0
        private void startSmelt(NWPlaceable forge, NWPlayer pc, NWItem item)
        {
            int charges = forge.GetLocalInt("FORGE_CHARGES");

            if (item.Resref == "coal")
            {
                item.Destroy();
                charges += 10 + CalculatePerkCoalBonusCharges(pc);
                forge.SetLocalInt("FORGE_CHARGES", charges);

                NWPlaceable flames = NWPlaceable.Wrap(forge.GetLocalObject("FORGE_FLAMES"));
                if (!flames.IsValid)
                {
                    Vector   flamePosition = _biowarePosition.GetChangedPosition(forge.Position, 0.36f, forge.Facing);
                    Location flameLocation = _.Location(forge.Area.Object, flamePosition, 0.0f);
                    flames = NWPlaceable.Wrap(_.CreateObject(OBJECT_TYPE_PLACEABLE, "forge_flame", flameLocation));
                    forge.SetLocalObject("FORGE_FLAMES", flames.Object);
                }

                return;
            }
            else if (charges <= 0)
            {
                ReturnItemToPC(pc, item, "You must light the forge with coal before smelting.");
                return;
            }
            item.Destroy();

            // Ready to smelt
            float baseCraftDelay = 18.0f - (_perk.GetPCPerkLevel(pc, PerkType.SpeedySmelter) * 0.1f);

            pc.IsBusy = true;
            forge.SetLocalObject("FORGE_USER", pc.Object);
            pc.SetLocalObject("FORGE", forge.Object);
            forge.SetLocalString("FORGE_ORE", item.Resref);

            _nwnxPlayer.StartGuiTimingBar(pc, baseCraftDelay, "cft_finish_smelt");

            _.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, _.EffectCutsceneImmobilize(), pc.Object, baseCraftDelay);
            pc.AssignCommand(() => _.ActionPlayAnimation(ANIMATION_LOOPING_GET_MID, 1.0f, baseCraftDelay));
        }
Esempio n. 16
0
        public NWPlaceable Run(NWArea area, Location location, float orientationOverride = 0f, float sqrtValue = 0f)
        {
            Vector doorPosition = _.GetPositionFromLocation(location);
            float  fOrient      = _.GetFacingFromLocation(location);

            fOrient = fOrient + 126.31f;
            if (fOrient > 360.0)
            {
                fOrient = fOrient - 360.0f;
            }

            float fMod = _.sqrt(13.0f) * _.sin(fOrient);

            doorPosition.m_X = doorPosition.m_X + fMod;

            fMod             = _.sqrt(13.0f) * _.cos(fOrient);
            doorPosition.m_Y = doorPosition.m_Y - fMod;
            Location doorLocation = _.Location(area.Object, doorPosition, _.GetFacingFromLocation(location));

            return(_.CreateObject(NWScript.OBJECT_TYPE_PLACEABLE, "building_door", doorLocation));
        }
Esempio n. 17
0
        public bool Run(params object[] args)
        {
            NWPlaceable plc            = (Object.OBJECT_SELF);
            int         growingPlantID = plc.GetLocalInt("GROWING_PLANT_ID");

            if (growingPlantID <= 0)
            {
                return(false);
            }

            var growingPlant = _data.Get <Data.Entity.GrowingPlant>(growingPlantID);
            var plant        = _data.Get <Plant>(growingPlant.PlantID);

            growingPlant.RemainingTicks--;
            growingPlant.TotalTicks++;

            int waterTicks = plant.WaterTicks;

            if (waterTicks > 0 && growingPlant.TotalTicks % waterTicks == 0)
            {
                int maxWaterStatus = plant.BaseTicks / plant.WaterTicks;

                if (growingPlant.WaterStatus < maxWaterStatus)
                {
                    growingPlant.WaterStatus++;
                    growingPlant.RemainingTicks = growingPlant.RemainingTicks * growingPlant.WaterStatus;
                }
            }

            if (growingPlant.RemainingTicks <= 0)
            {
                plc.Destroy();
                plc = (_.CreateObject(NWScript.OBJECT_TYPE_PLACEABLE, plant.Resref, plc.Location));
                plc.SetLocalInt("GROWING_PLANT_ID", growingPlantID);
            }

            _data.SubmitDataChange(growingPlant, DatabaseActionType.Update);
            return(true);
        }
Esempio n. 18
0
        public void OnChestUsed(NWPlaceable oChest)
        {
            NWPlayer oPC = (_.GetLastUsedBy());

            if (!oPC.IsPlayer)
            {
                return;
            }


            NWPlaceable oCopy = (_.CreateObject(NWScript.OBJECT_TYPE_PLACEABLE, SearchSiteCopyResref, oChest.Location));

            oCopy.Name = oChest.Name;
            _.SetFacingPoint(oPC.Position);

            _localVariable.CopyVariables(oChest, oCopy);

            oPC.AssignCommand(() =>
            {
                _.ActionInteractObject(oCopy.Object);
            });
        }
Esempio n. 19
0
        public bool Run(params object[] args)
        {
            NWPlaceable plant          = NWPlaceable.Wrap(Object.OBJECT_SELF);
            int         growingPlantID = plant.GetLocalInt("GROWING_PLANT_ID");

            if (growingPlantID <= 0)
            {
                return(false);
            }

            Data.Entities.GrowingPlant growingPlant = _db.GrowingPlants.Single(x => x.GrowingPlantID == growingPlantID);
            growingPlant.RemainingTicks--;
            growingPlant.TotalTicks++;

            int waterTicks = growingPlant.Plant.WaterTicks;

            if (waterTicks > 0 && growingPlant.TotalTicks % waterTicks == 0)
            {
                int maxWaterStatus = growingPlant.Plant.BaseTicks / growingPlant.Plant.WaterTicks;

                if (growingPlant.WaterStatus < maxWaterStatus)
                {
                    growingPlant.WaterStatus++;
                    growingPlant.RemainingTicks = growingPlant.RemainingTicks * growingPlant.WaterStatus;
                }
            }

            if (growingPlant.RemainingTicks <= 0)
            {
                plant.Destroy();
                plant = NWPlaceable.Wrap(_.CreateObject(OBJECT_TYPE_PLACEABLE, growingPlant.Plant.Resref, plant.Location));
                plant.SetLocalInt("GROWING_PLANT_ID", growingPlantID);
            }

            _db.SaveChanges();
            return(true);
        }
Esempio n. 20
0
        public void OnModuleLoad()
        {
            List <GrowingPlant> plants = _db.GrowingPlants.Where(x => x.IsActive).ToList();

            foreach (GrowingPlant plant in plants)
            {
                string resref = "growing_plant";
                if (plant.RemainingTicks <= 0)
                {
                    resref = plant.Plant.Resref;
                }

                NWArea      area     = NWArea.Wrap(_.GetObjectByTag(plant.LocationAreaTag));
                Vector      position = _.Vector(plant.LocationX, plant.LocationY, plant.LocationZ);
                Location    location = _.Location(area.Object, position, plant.LocationOrientation);
                NWPlaceable plantPlc = NWPlaceable.Wrap(_.CreateObject(OBJECT_TYPE_PLACEABLE, resref, location));
                plantPlc.SetLocalInt("GROWING_PLANT_ID", plant.GrowingPlantID);

                if (plant.RemainingTicks > 0)
                {
                    plantPlc.Name = "Growing Plant (" + plant.Plant.Name + ")";
                }
            }
        }
Esempio n. 21
0
        public NWPlaceable Run(NWArea area, Location location, float orientationOverride = 0f, float sqrtValue = 0f)
        {
            float orientationAdjustment = orientationOverride != 0f ? orientationOverride : 200.31f;
            float sqrtAdjustment        = sqrtValue != 0f ? sqrtValue : 18.0f;

            Vector position    = _.GetPositionFromLocation(location);
            float  orientation = _.GetFacingFromLocation(location);

            orientation = orientation + orientationAdjustment;
            if (orientation > 360.0)
            {
                orientation = orientation - 360.0f;
            }

            float mod = _.sqrt(sqrtAdjustment) * _.sin(orientation);

            position.m_X = position.m_X + mod;

            mod          = _.sqrt(sqrtAdjustment) * _.cos(orientation);
            position.m_Y = position.m_Y - mod;
            Location doorLocation = _.Location(area.Object, position, _.GetFacingFromLocation(location));

            return(_.CreateObject(NWScript.OBJECT_TYPE_PLACEABLE, "building_ent1", doorLocation));
        }
Esempio n. 22
0
        public bool Run(params object[] args)
        {
            NWPlaceable container      = (Object.OBJECT_SELF);
            NWPlayer    oPC            = (_.GetLastDisturbed());
            int         type           = _.GetInventoryDisturbType();
            NWItem      item           = (_.GetInventoryDisturbItem());
            var         effectiveStats = _playerStat.GetPlayerItemEffectiveStats(oPC);

            if (type != NWScript.INVENTORY_DISTURB_TYPE_ADDED)
            {
                return(false);
            }

            int plantID = item.GetLocalInt("PLANT_ID");

            if (plantID <= 0)
            {
                _item.ReturnItem(oPC, item);
                oPC.SendMessage("You cannot plant that item.");
                return(true);
            }

            Plant plant = _farming.GetPlantByID(plantID);

            if (plant == null)
            {
                _item.ReturnItem(oPC, item);
                oPC.SendMessage("You cannot plant that item.");
                return(true);
            }

            int rank = _skill.GetPCSkillRank(oPC, SkillType.Farming);

            if (rank + 2 < plant.Level)
            {
                _item.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     = _perk.GetPCPerkLevel(oPC, PerkType.FarmingEfficiency) * 2;
            int      ticks         = (int)(plant.BaseTicks - ((_perk.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
            };

            _data.SubmitDataChange(growingPlant, DatabaseActionType.Insert);

            NWPlaceable hole     = (container.GetLocalObject("FARM_SMALL_HOLE"));
            NWPlaceable plantPlc = (_.CreateObject(NWScript.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)_skill.CalculateRegisteredSkillLevelAdjustedXP(200, plant.Level, rank);

            if (_random.Random(100) + 1 <= _perk.GetPCPerkLevel(oPC, PerkType.Lucky) + effectiveStats.Luck)
            {
                xp *= 2;
            }

            _skill.GiveSkillXP(oPC, SkillType.Farming, xp);
            return(true);
        }
Esempio n. 23
0
        public void OnCreatureDeath()
        {
            _.SetIsDestroyable(FALSE);

            NWObject self          = Object.OBJECT_SELF;
            Vector   lootPosition  = _.Vector(self.Position.m_X, self.Position.m_Y, self.Position.m_Z - 0.11f);
            Location spawnLocation = _.Location(self.Area, lootPosition, self.Facing);

            NWPlaceable container = _.CreateObject(OBJECT_TYPE_PLACEABLE, "corpse", spawnLocation);

            container.SetLocalObject("CORPSE_BODY", self);
            container.Name = self.Name + "'s Corpse";

            container.AssignCommand(() =>
            {
                _.TakeGoldFromCreature(self.Gold, self);
            });

            // Dump equipped items in container
            for (int slot = 0; slot < NUM_INVENTORY_SLOTS; slot++)
            {
                if (slot == INVENTORY_SLOT_CARMOUR ||
                    slot == INVENTORY_SLOT_CWEAPON_B ||
                    slot == INVENTORY_SLOT_CWEAPON_L ||
                    slot == INVENTORY_SLOT_CWEAPON_R)
                {
                    continue;
                }

                NWItem item = _.GetItemInSlot(slot, self);
                if (item.IsValid && !item.IsCursed && item.IsDroppable)
                {
                    NWItem copy = _.CopyItem(item, container, TRUE);

                    if (slot == INVENTORY_SLOT_HEAD ||
                        slot == INVENTORY_SLOT_CHEST)
                    {
                        copy.SetLocalObject("CORPSE_ITEM_COPY", item);
                    }
                    else
                    {
                        item.Destroy();
                    }
                }
            }

            foreach (var item in self.InventoryItems)
            {
                _.CopyItem(item, container, TRUE);
                item.Destroy();
            }

            _.DelayCommand(360.0f, () =>
            {
                if (!container.IsValid)
                {
                    return;
                }

                NWObject body = container.GetLocalObject("CORPSE_BODY");
                body.AssignCommand(() => _.SetIsDestroyable(TRUE));
                body.DestroyAllInventoryItems();
                body.Destroy();

                container.DestroyAllInventoryItems();
                container.Destroy();
            });
        }
Esempio n. 24
0
        private void BlowUpBase(PCBase pcBase)
        {
            NWArea area = (_.GetArea(Object.OBJECT_SELF));
            List <AreaStructure> cache = area.Data["BASE_SERVICE_STRUCTURES"];

            cache = cache.Where(x => x.PCBaseID == pcBase.ID).ToList();

            foreach (var structure in cache)
            {
                // Child structures will be picked up later on in the process.
                // Just destroy the structure and continue on.
                if (structure.ChildStructure != null)
                {
                    structure.Structure.Destroy();
                    continue;
                }

                var dbStructure   = _data.Get <PCBaseStructure>(structure.PCBaseStructureID);
                var baseStructure = _data.Get <BaseStructure>(dbStructure.BaseStructureID);
                var items         = _data.Where <PCBaseStructureItem>(x => x.PCBaseStructureID == structure.PCBaseStructureID).ToList();
                var children      = _data.Where <PCBaseStructure>(x => x.ParentPCBaseStructureID == dbStructure.ParentPCBaseStructureID).ToList();

                // Explosion effect
                Location location = structure.Structure.Location;
                _.ApplyEffectAtLocation(DURATION_TYPE_INSTANT, _.EffectVisualEffect(VFX_FNF_FIREBALL), location);

                // Boot from instance, if any
                _base.BootPlayersOutOfInstance(structure.PCBaseStructureID);

                // Spawn container for items
                NWPlaceable container = (_.CreateObject(OBJECT_TYPE_PLACEABLE, "structure_rubble", structure.Structure.Location));
                container.Name = baseStructure.Name + " Rubble";

                // Drop item storage into container
                for (int i = items.Count - 1; i >= 0; i--)
                {
                    var dbItem = items.ElementAt(i);
                    _serialization.DeserializeItem(dbItem.ItemObject, container);
                    _data.SubmitDataChange(dbItem, DatabaseActionType.Delete);
                }

                // Convert child placeables to items and drop into container
                for (int f = children.Count - 1; f >= 0; f--)
                {
                    var child      = children.ElementAt(f);
                    var childItems = _data.Where <PCBaseStructureItem>(x => x.PCBaseStructureID == child.ID).ToList();

                    // Move child items to container
                    for (int i = childItems.Count - 1; i >= 0; i++)
                    {
                        var dbItem = childItems.ElementAt(i);
                        _serialization.DeserializeItem(dbItem.ItemObject, container);
                        _data.SubmitDataChange(dbItem, DatabaseActionType.Delete);
                    }

                    // Convert child structure to item
                    _base.ConvertStructureToItem(child, container);
                    _data.SubmitDataChange(child, DatabaseActionType.Delete);
                }


                // Clear structure permissions
                var structurePermissions = _data.Where <PCBaseStructurePermission>(x => x.PCBaseStructureID == dbStructure.ID).ToList();
                for (int p = structurePermissions.Count - 1; p >= 0; p--)
                {
                    var permission = structurePermissions.ElementAt(p);
                    _data.SubmitDataChange(permission, DatabaseActionType.Delete);
                }

                // Destroy structure placeable
                _data.SubmitDataChange(dbStructure, DatabaseActionType.Delete);
                structure.Structure.Destroy();
            }

            // Remove from cache
            foreach (var record in cache)
            {
                ((List <AreaStructure>)area.Data["BASE_SERVICE_STRUCTURES"]).Remove(record);
            }
            var basePermissions = _data.Where <PCBasePermission>(x => x.PCBaseID == pcBase.ID).ToList();

            // Clear base permissions
            for (int p = basePermissions.Count - 1; p >= 0; p--)
            {
                var permission = basePermissions.ElementAt(p);
                _data.SubmitDataChange(permission, DatabaseActionType.Delete);
            }

            _data.SubmitDataChange(pcBase, DatabaseActionType.Delete);

            Area dbArea = _data.Single <Area>(x => x.Resref == pcBase.AreaResref);

            if (pcBase.Sector == AreaSector.Northeast)
            {
                dbArea.NortheastOwner = null;
            }
            else if (pcBase.Sector == AreaSector.Northwest)
            {
                dbArea.NorthwestOwner = null;
            }
            else if (pcBase.Sector == AreaSector.Southeast)
            {
                dbArea.SoutheastOwner = null;
            }
            else if (pcBase.Sector == AreaSector.Southwest)
            {
                dbArea.SouthwestOwner = null;
            }
        }
Esempio n. 25
0
        public bool Run(params object[] args)
        {
            NWPlaceable container = NWPlaceable.Wrap(Object.OBJECT_SELF);
            NWPlayer    oPC       = NWPlayer.Wrap(_.GetLastDisturbed());
            int         type      = _.GetInventoryDisturbType();
            NWItem      item      = NWItem.Wrap(_.GetInventoryDisturbItem());

            if (type != INVENTORY_DISTURB_TYPE_ADDED)
            {
                return(false);
            }

            int plantID = item.GetLocalInt("PLANT_ID");

            if (plantID <= 0)
            {
                _item.ReturnItem(oPC, item);
                oPC.SendMessage("You cannot plant that item.");
                return(true);
            }

            Plant plant = _farming.GetPlantByID(plantID);

            if (plant == null)
            {
                _item.ReturnItem(oPC, item);
                oPC.SendMessage("You cannot plant that item.");
                return(true);
            }

            PCSkill pcSkill = _skill.GetPCSkill(oPC, SkillType.Farming);
            int     rank    = 0;

            if (pcSkill != null)
            {
                rank = pcSkill.Rank;
            }

            if (rank + 2 < plant.Level)
            {
                _item.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     = _perk.GetPCPerkLevel(oPC, PerkType.FarmingEfficiency) * 2;
            int      ticks         = (int)(plant.BaseTicks - ((_perk.GetPCPerkLevel(oPC, PerkType.ExpertFarmer) * 0.05f)) * plant.BaseTicks);

            Data.Entities.GrowingPlant growingPlant = new Data.Entities.GrowingPlant();
            growingPlant.PlantID             = plant.PlantID;
            growingPlant.RemainingTicks      = ticks;
            growingPlant.LocationAreaTag     = areaTag;
            growingPlant.LocationOrientation = _.GetFacingFromLocation(plantLocation);
            growingPlant.LocationX           = _.GetPositionFromLocation(plantLocation).m_X;
            growingPlant.LocationY           = _.GetPositionFromLocation(plantLocation).m_Y;
            growingPlant.LocationZ           = _.GetPositionFromLocation(plantLocation).m_Z;
            growingPlant.IsActive            = true;
            growingPlant.DateCreated         = DateTime.UtcNow;
            growingPlant.LongevityBonus      = perkBonus;

            _db.GrowingPlants.Add(growingPlant);
            _db.SaveChanges();

            NWPlaceable hole     = NWPlaceable.Wrap(container.GetLocalObject("FARM_SMALL_HOLE"));
            NWPlaceable plantPlc = NWPlaceable.Wrap(_.CreateObject(OBJECT_TYPE_PLACEABLE, "growing_plant", hole.Location));

            plantPlc.SetLocalInt("GROWING_PLANT_ID", growingPlant.GrowingPlantID);
            plantPlc.Name = "Growing Plant (" + plant.Name + ")";

            container.Destroy();
            hole.Destroy();

            int xp = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(200, plant.Level, rank);

            if (_random.Random(100) + 1 <= _perk.GetPCPerkLevel(oPC, PerkType.Lucky) + oPC.EffectiveLuckBonus)
            {
                xp *= 2;
            }

            _skill.GiveSkillXP(oPC, SkillType.Farming, xp);
            return(true);
        }
Esempio n. 26
0
        private void ProcessSpawn(ObjectSpawn spawn, int objectType, NWArea area, bool forceSpawn)
        {
            // Don't process anything that's valid.
            if (spawn.Spawn.IsValid)
            {
                return;
            }

            spawn.Timer += _processor.ProcessingTickInterval;

            // Time to respawn!
            if (spawn.Timer >= spawn.RespawnTime || forceSpawn)
            {
                string     resref   = spawn.Resref;
                NWLocation location = spawn.IsStaticSpawnPoint ? spawn.SpawnLocation : null;

                spawn.HasSpawnedOnce = true;

                if (string.IsNullOrWhiteSpace(resref))
                {
                    var dbSpawn = _data.Where <SpawnObject>(x => x.SpawnID == spawn.SpawnTableID)
                                  .OrderBy(o => Guid.NewGuid()).First();

                    resref = dbSpawn.Resref;

                    if (!string.IsNullOrWhiteSpace(dbSpawn.SpawnRule))
                    {
                        spawn.SpawnRule = dbSpawn.SpawnRule;
                    }
                }

                if (location == null)
                {
                    location = _spawn.GetRandomSpawnPoint(area);
                }

                spawn.Spawn = _.CreateObject(objectType, resref, location);

                if (!spawn.Spawn.IsValid)
                {
                    Console.WriteLine("ERROR: Cannot locate object with resref " + resref + ". Error occurred in area " + area.Name + " (" + area.Resref + ")");
                    return;
                }

                if (spawn.NPCGroupID > 0)
                {
                    spawn.Spawn.SetLocalInt("NPC_GROUP", spawn.NPCGroupID);
                }

                if (spawn.DeathVFXID > 0)
                {
                    spawn.Spawn.SetLocalInt("DEATH_VFX", spawn.DeathVFXID);
                }

                if (!string.IsNullOrWhiteSpace(spawn.BehaviourScript) &&
                    string.IsNullOrWhiteSpace(spawn.Spawn.GetLocalString("BEHAVIOUR")))
                {
                    spawn.Spawn.SetLocalString("BEHAVIOUR", spawn.BehaviourScript);
                }

                if (objectType == OBJECT_TYPE_CREATURE)
                {
                    _spawn.AssignScriptEvents(spawn.Spawn.Object);
                }

                if (!string.IsNullOrWhiteSpace(spawn.SpawnRule))
                {
                    App.ResolveByInterface <ISpawnRule>("SpawnRule." + spawn.SpawnRule, rule =>
                    {
                        rule.Run(spawn.Spawn);
                    });
                }

                App.Resolve <IObjectVisibilityService>(ovs =>
                {
                    ovs.ApplyVisibilityForObject(spawn.Spawn);
                });

                spawn.Timer = 0.0f;
            }
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        private void SpawnResources(NWArea area, AreaSpawn areaSpawn)
        {
            var dbArea = _data.GetAll <Area>().Single(x => x.Resref == area.Resref);

            if (dbArea.ResourceSpawnTableID <= 0 ||
                !dbArea.AutoSpawnResources)
            {
                return;
            }
            var possibleSpawns = _data.Where <SpawnObject>(x => x.SpawnID == dbArea.ResourceSpawnTableID).ToList();

            // 1024 size = 32x32
            // 256  size = 16x16
            // 64   size = 8x8
            int size = area.Width * area.Height;

            int maxSpawns = 0;

            if (size <= 12)
            {
                maxSpawns = 2;
            }
            else if (size <= 32)
            {
                maxSpawns = 6;
            }
            else if (size <= 64)
            {
                maxSpawns = 10;
            }
            else if (size <= 256)
            {
                maxSpawns = 25;
            }
            else if (size <= 512)
            {
                maxSpawns = 40;
            }
            else if (size <= 1024)
            {
                maxSpawns = 50;
            }

            int[] weights = new int[possibleSpawns.Count()];
            for (int x = 0; x < possibleSpawns.Count(); x++)
            {
                weights[x] = possibleSpawns.ElementAt(x).Weight;
            }

            for (int x = 1; x <= maxSpawns; x++)
            {
                int         index    = _random.GetRandomWeightedIndex(weights);
                var         dbSpawn  = possibleSpawns.ElementAt(index);
                Location    location = GetRandomSpawnPoint(area);
                NWPlaceable plc      = (_.CreateObject(OBJECT_TYPE_PLACEABLE, dbSpawn.Resref, location));
                ObjectSpawn spawn    = new ObjectSpawn(location, false, dbArea.ResourceSpawnTableID, 600.0f);
                spawn.Spawn = plc;

                App.Resolve <IObjectVisibilityService>(ovs =>
                {
                    ovs.ApplyVisibilityForObject(plc);
                });

                if (dbSpawn.NPCGroupID != null && dbSpawn.NPCGroupID > 0)
                {
                    plc.SetLocalInt("NPC_GROUP", Convert.ToInt32(dbSpawn.NPCGroupID));
                    spawn.NPCGroupID = Convert.ToInt32(dbSpawn.NPCGroupID);
                }

                if (!string.IsNullOrWhiteSpace(dbSpawn.BehaviourScript) &&
                    string.IsNullOrWhiteSpace(plc.GetLocalString("BEHAVIOUR")))
                {
                    plc.SetLocalString("BEHAVIOUR", dbSpawn.BehaviourScript);
                    spawn.BehaviourScript = dbSpawn.BehaviourScript;
                }

                if (!string.IsNullOrWhiteSpace(dbSpawn.SpawnRule))
                {
                    App.ResolveByInterface <ISpawnRule>("SpawnRule." + dbSpawn.SpawnRule, rule =>
                    {
                        rule.Run(plc);
                    });
                }

                areaSpawn.Placeables.Add(spawn);
            }
        }