Beispiel #1
0
        public List <IntPtr> GatherEffectsForObject(uint objectId)
        {
            _oid = objectId;

            var effects = new List <IntPtr>
            {
                NWScript.EffectSkillIncrease(NWScript.SKILL_MOVE_SILENTLY, 2),
            };


            return(effects);
        }
Beispiel #2
0
        private static IEnumerable <IntPtr> TagEffects(IEnumerable <IntPtr> supernaturalEffects)
        {
            var taggedEffects = new List <IntPtr>();

            foreach (var effect in supernaturalEffects)
            {
                var subracePrefixWithCount = SubracePrefix + taggedEffects.Count;
                taggedEffects.Add(NWScript.TagEffect(effect, subracePrefixWithCount));
            }

            return(taggedEffects);
        }
Beispiel #3
0
        static public int Main()
        {
            if (!initialized)
            {
                Console.WriteLine("Not initialized yet, adding MainLoopTick callback..");
                Events.MainLoopTick += CheckQueryResult;
                Thread query_thread = new Thread(PollQueries);
                query_thread.IsBackground = true;
                query_thread.Start();
                initialized = true;

                // Read database variables from env
                db_name = Environment.GetEnvironmentVariable("NWNX_CSHARP_DB");
                db_user = Environment.GetEnvironmentVariable("NWNX_CSHARP_DB_USER");
                db_pass = Environment.GetEnvironmentVariable("NWNX_CSHARP_DB_PASS");
                Console.WriteLine("db_name: " + db_name);
            }

            QueryThreadParams t_params = new QueryThreadParams();

            t_params.db_object = Object.OBJECT_SELF;
            t_params.query     = NWScript.GetLocalString(t_params.db_object, "sql_query") as string;
            try
            {
                t_params.values = (NWScript.GetLocalString(t_params.db_object, "sql_values") as string);
            }
            catch
            {
                t_params.values = "";
            }
            try
            {
                t_params.callback_script = (NWScript.GetLocalString(t_params.db_object, "sql_callback_script") as string);
                t_params.callback_object = (NWScript.GetLocalObject(t_params.db_object, "sql_callback_object"));
            }
            catch
            {
                t_params.callback_script = "";
                t_params.callback_object = null;
            }
            try
            {
                t_params.metadata = (NWScript.GetLocalString(t_params.db_object, "sql_metadata") as string);
            }
            catch
            {
                t_params.metadata = "";
            }
            query_stack.Push(t_params);

            return(1);
        }
Beispiel #4
0
        /// <summary>
        /// Gets all objects of the given type that are currently in this area of effect.
        /// </summary>
        /// <typeparam name="T">The type of objects to return.</typeparam>
        /// <returns>An enumerable containing all objects currently in the effect area.</returns>
        public IEnumerable <T> GetObjectsInEffectArea <T>() where T : NwGameObject
        {
            int objType = (int)GetObjectType <T>();

            for (uint obj = NWScript.GetFirstInPersistentObject(this, objType); obj != Invalid; obj = NWScript.GetNextInPersistentObject(this, objType))
            {
                T?gameObject = obj.ToNwObjectSafe <T>();
                if (gameObject != null)
                {
                    yield return(gameObject);
                }
            }
        }
        private T Load2DAToCache <T>(string name) where T : ITwoDimArray, new()
        {
            T new2da = new T();

            for (int i = 0; i < UtilPlugin.Get2DARowCount(name); i++)
            {
                int rowIndex = i;
                new2da.DeserializeRow(rowIndex, (column) => NWScript.Get2DAString(name, column, rowIndex));
            }

            cache[name] = new2da;
            return(new2da);
        }
Beispiel #6
0
        private static void MassMessage(string message)
        {
            var objectCreature = NWScript.GetFirstPC();

            while (NWScript.GetIsObjectValid(objectCreature) == NWScript.TRUE)
            {
                NWScript.SendMessageToPC(objectCreature, "-----");
                NWScript.SendMessageToPC(objectCreature, "-----");
                NWScript.SendMessageToPC(objectCreature, message);
                NWScript.SendMessageToPC(objectCreature, "-----");
                NWScript.SendMessageToPC(objectCreature, "-----");
                objectCreature = NWScript.GetNextPC();
            }
        }
Beispiel #7
0
        public List <IntPtr> GatherEffectsForObject(uint objectId)
        {
            _oid             = objectId;
            _hasHeritageFeat = HasHeritageFeat();

            var effects = new List <IntPtr>
            {
                NWScript.EffectSkillIncrease(NWScript.SKILL_TUMBLE, 4),
            };

            AddHeritageEffectsIfObjectHasFeat(effects);

            return(effects);
        }
Beispiel #8
0
        private static void RemoveTaggedEffects()
        {
            IntPtr effect = NWScript.GetFirstEffect(_player);

            while (NWScript.GetIsEffectValid(effect) == NWScript.TRUE)
            {
                if (NWScript.GetEffectTag(effect).Contains(SubracePrefix))
                {
                    NWScript.RemoveEffect(_player, effect);
                }

                effect = NWScript.GetNextEffect(_player);
            }
        }
Beispiel #9
0
 /// <summary>
 /// Locates all objects of the specified type.
 /// </summary>
 /// <typeparam name="T">The type of objects to search.</typeparam>
 /// <returns>An enumeration containing all objects of the specified type.</returns>
 public static IEnumerable <T> FindObjectsOfType <T>() where T : NwObject
 {
     for (uint currentArea = NWScript.GetFirstArea(); currentArea != INVALID; currentArea = NWScript.GetNextArea())
     {
         for (uint currentObj = NWScript.GetFirstObjectInArea(currentArea); currentObj != INVALID; currentObj = NWScript.GetNextObjectInArea(currentArea))
         {
             T obj = currentObj.ToNwObjectSafe <T>();
             if (obj != null)
             {
                 yield return(obj);
             }
         }
     }
 }
Beispiel #10
0
        /// @brief Set the location oPlayer will spawn when logging in to the server.
        /// @note This function is best called in the NWNX_ON_ELC_VALIDATE_CHARACTER_BEFORE event, OnClientEnter will be too late.
        /// @param The player object.
        /// @param locSpawn The location.
        public static void SetSpawnLocation(uint oPlayer, Location locSpawn)
        {
            var vPosition = NWScript.GetPositionFromLocation(locSpawn);

            Internal.NativeFunctions.nwnxSetFunction(PLUGIN_NAME, "SetSpawnLocation");
            Internal.NativeFunctions.nwnxPushFloat(NWScript.GetFacingFromLocation(locSpawn));
            Internal.NativeFunctions.nwnxPushFloat(vPosition.Z);
            Internal.NativeFunctions.nwnxPushFloat(vPosition.Y);
            Internal.NativeFunctions.nwnxPushFloat(vPosition.X);
            Internal.NativeFunctions.nwnxPushObject(NWScript.GetAreaFromLocation(locSpawn));
            Internal.NativeFunctions.nwnxPushObject(oPlayer);

            Internal.NativeFunctions.nwnxCallFunction();
        }
Beispiel #11
0
        public IEnumerable <T> GetNearestObjectsByType <T>() where T : NwGameObject
        {
            int  objType = (int)NwObject.GetObjectType <T>();
            int  i;
            uint next;

            for (i = 1, next = NWScript.GetNearestObjectToLocation(objType, this, i); next != NwObject.Invalid; i++, next = NWScript.GetNearestObjectToLocation(objType, this, i))
            {
                T?obj = next.ToNwObjectSafe <T>();
                if (obj != null)
                {
                    yield return(obj);
                }
            }
        }
        public List <IntPtr> GatherEffectsForObject(uint objectId)
        {
            _oid             = objectId;
            _hasHeritageFeat = HasHeritageFeat();

            var spellResistance = GetSpellResistanceBasedOnFeat();

            var effectsForObject = new List <IntPtr>
            {
                NWScript.EffectSpellResistanceIncrease(spellResistance)
            };

            AddHeritageEffectsIfObjectHasFeat(effectsForObject);
            return(effectsForObject);
        }
Beispiel #13
0
        private void SpawnPlc(uint area, int totalPLC)
        {
            int countPlc = 0;

            while (countPlc < totalPLC)
            {
                IntPtr randomLocation = GenerateRandomLocation(area);
                uint   objectPlc      = CreatePlc(randomLocation);

                if (NWScript.GetIsObjectValid(objectPlc) == NWScript.TRUE)
                {
                    countPlc++;
                }
            }
        }
Beispiel #14
0
        public int RunScript()
        {
            var scriptResult = 1;

            try
            {
                scriptResult = GetManagedScriptFromContext().Run(_currentScript.CallingObject);
            }
            catch (Exception m)
            {
                NWScript.WriteTimestampedLogEntry($"FAILED TO PARSE SCRIPT {_currentScript.ScriptName}. Reason: {m.Message} \n({m.InnerException?.Message}, {m.InnerException?.StackTrace}\n => {m.StackTrace})");
            }

            return(scriptResult);
        }
Beispiel #15
0
        private void SpawnLieutenants(uint area, int totalLieutentants, string lieutentant)
        {
            int countLieutenant = 0;

            while (countLieutenant < totalLieutentants)
            {
                IntPtr randomLocation = GenerateRandomLocation(area);
                uint   objectCreature = NWScript.CreateObject(NWScript.OBJECT_TYPE_CREATURE, lieutentant, randomLocation);

                if (NWScript.GetIsObjectValid(objectCreature) == NWScript.TRUE)
                {
                    countLieutenant++;
                }
            }
        }
        private static void SpawnCreaturesFromResRefs(int maxSpawns, IReadOnlyList <string> resRefs)
        {
            if (!resRefs.Any())
            {
                NWScript.WriteTimestampedLogEntry(
                    $"Attempted to spawn creatures in {NWScript.GetName(NWScript.GetAreaFromLocation(_spawnLocation))}, but there were no creatures to spawn.");
                return;
            }

            for (int i = 0; i < maxSpawns; i++)
            {
                int randomCreature = new Random().Next(0, resRefs.Count);
                SpawnEncounterAtWaypoint(resRefs[randomCreature]);
            }
        }
Beispiel #17
0
        private void SpawnBoss(uint area, string boss)
        {
            int countBoss = 0;

            while (countBoss < 1)
            {
                IntPtr randomLocation = GenerateRandomLocation(area);
                uint   objectCreature = NWScript.CreateObject(NWScript.OBJECT_TYPE_CREATURE, boss, randomLocation);

                if (NWScript.GetIsObjectValid(objectCreature) == NWScript.TRUE)
                {
                    countBoss++;
                }
            }
        }
        static public void CheckScriptQuery(ulong frame)
        {
            ScriptExecutionDescription ex_desc;

            if (execution_stack.TryPop(out ex_desc))
            {
                if (ex_desc.script.Length <= 0)
                {
                    Console.WriteLine("Error: Popped ScriptExecutionDescription without script string set!");
                    return;
                }

                NWScript.SetLocalString(db_object, "script_payload", ex_desc.payload);
                NWScript.ExecuteScript(ex_desc.script, db_object);
            }
        }
Beispiel #19
0
        public void InvasionTrolls(uint area, int size, int random)
        {
            string areaName      = NWScript.GetName(area);
            string creaturetype1 = "mountainguard";
            string creaturetype2 = "mountainguard";
            string creaturetype3 = "mounttroll";
            string creaturetype4 = "mounttroll";
            string creaturetype5 = "mounttroll";
            string lieutentant   = "bigmounttroll";
            string boss          = "invasiontrollbs";
            string message       = "News quickly spreads of an amassing army of Trolls in " + areaName +
                                   ". They must be stopped before it is too late!";

            InvasionGeneric(area, size, random, creaturetype1, creaturetype2, creaturetype3, creaturetype4,
                            creaturetype5, lieutentant, boss, message);
        }
Beispiel #20
0
        public void InvasionOrcs(uint area, int size, int random)
        {
            string areaName      = NWScript.GetName(area);
            string creaturetype1 = "af_ds_ork";
            string creaturetype2 = "arelithorc001";
            string creaturetype3 = "arelithorc";
            string creaturetype4 = "arelithorc";
            string creaturetype5 = "orcbasher";
            string lieutentant   = "orcboss001";
            string boss          = "chosenofkilma002";
            string message       = "News quickly spreads of an amassing army of Orcs in " + areaName +
                                   ". They must be stopped before it is too late!";

            InvasionGeneric(area, size, random, creaturetype1, creaturetype2, creaturetype3, creaturetype4,
                            creaturetype5, lieutentant, boss, message);
        }
Beispiel #21
0
 private static List <IntPtr> ResolveEffectsForObject(uint nwnObjectId)
 {
     return(NWScript.GetSubRace(nwnObjectId).ToLower() switch
     {
         "aasimar" => new AasimarEffects().GatherEffectsForObject(nwnObjectId),
         "tiefling" => new TieflingEffects().GatherEffectsForObject(nwnObjectId),
         "fey'ri" => new FeyriEffects().GatherEffectsForObject(nwnObjectId),
         "feyri" => new FeyriEffects().GatherEffectsForObject(nwnObjectId),
         "feytouched" => new FeytouchedEffects().GatherEffectsForObject(nwnObjectId),
         "centaur" => new CentaurEffects().GatherEffectsForObject(nwnObjectId),
         "avariel" => new AvarielEffects().GatherEffectsForObject(nwnObjectId),
         "half dragon" => new HalfDragonEffects().GatherEffectsForObject(nwnObjectId),
         "half-dragon" => new HalfDragonEffects().GatherEffectsForObject(nwnObjectId),
         "dragon" => new HalfDragonEffects().GatherEffectsForObject(nwnObjectId),
         _ => new List <IntPtr>()
     });
Beispiel #22
0
        public IEnumerable <T> GetObjectsInShapeByType <T>(Shape shape, float size, bool losCheck, Vector3 origin = default) where T : NwGameObject
        {
            int typeFilter = (int)NwObject.GetObjectType <T>();
            int nShape     = (int)shape;

            for (uint obj = NWScript.GetFirstObjectInShape(nShape, size, this, losCheck.ToInt(), typeFilter, origin);
                 obj != NWScript.OBJECT_INVALID;
                 obj = NWScript.GetNextObjectInShape(nShape, size, this, losCheck.ToInt(), typeFilter, origin))
            {
                T?gameObject = obj.ToNwObject <T>();
                if (gameObject != null)
                {
                    yield return(gameObject);
                }
            }
        }
Beispiel #23
0
        public IEnumerable <NwGameObject> GetObjectsInShape(Shape shape, float size, bool losCheck, ObjectTypes objTypes = ObjectTypes.Creature, Vector3 origin = default)
        {
            int typeFilter = (int)objTypes;
            int nShape     = (int)shape;

            for (uint obj = NWScript.GetFirstObjectInShape(nShape, size, this, losCheck.ToInt(), typeFilter, origin);
                 obj != NWScript.OBJECT_INVALID;
                 obj = NWScript.GetNextObjectInShape(nShape, size, this, losCheck.ToInt(), typeFilter, origin))
            {
                NwGameObject?gameObject = obj.ToNwObject <NwGameObject>();
                if (gameObject != null)
                {
                    yield return(gameObject);
                }
            }
        }
Beispiel #24
0
        public void ChangeAreaUnderGroundUpdatesAreaFlags()
        {
            NwArea area = NwModule.Instance.StartingLocation.Area !;

            area.IsUnderGround = true;
            Assert.That(area.IsUnderGround, Is.EqualTo(true));
            Assert.That(area.IsAboveGround, Is.EqualTo(false));
            Assert.That(NWScript.GetIsAreaAboveGround(area).ToBool(), Is.EqualTo(false));
            Assert.That(area.AreaFlags.HasFlag(AreaFlags.UnderGround), Is.EqualTo(true));

            area.IsUnderGround = false;
            Assert.That(area.IsUnderGround, Is.EqualTo(false));
            Assert.That(area.IsAboveGround, Is.EqualTo(true));
            Assert.That(NWScript.GetIsAreaAboveGround(area).ToBool(), Is.EqualTo(true));
            Assert.That(area.AreaFlags.HasFlag(AreaFlags.UnderGround), Is.EqualTo(false));
        }
Beispiel #25
0
        public void ChangeAreaUrbanUpdatesAreaFlags()
        {
            NwArea area = NwModule.Instance.StartingLocation.Area !;

            area.IsUrban = true;
            Assert.That(area.IsUrban, Is.EqualTo(true));
            Assert.That(area.IsNatural, Is.EqualTo(false));
            Assert.That(NWScript.GetIsAreaNatural(area).ToBool(), Is.EqualTo(false));
            Assert.That(area.AreaFlags.HasFlag(AreaFlags.Natural), Is.EqualTo(false));

            area.IsUrban = false;
            Assert.That(area.IsUrban, Is.EqualTo(false));
            Assert.That(area.IsNatural, Is.EqualTo(true));
            Assert.That(NWScript.GetIsAreaNatural(area).ToBool(), Is.EqualTo(true));
            Assert.That(area.AreaFlags.HasFlag(AreaFlags.Natural), Is.EqualTo(true));
        }
Beispiel #26
0
        public void InvasionBeasts(uint area, int size, int random)
        {
            string areaName      = NWScript.GetName(area);
            string creaturetype1 = "beasthero";
            string creaturetype2 = "elitebeastarcher";
            string creaturetype3 = "beastshaman";
            string creaturetype4 = "beastmanchampion";
            string creaturetype5 = "beastmonk";
            string lieutentant   = "beastguard";
            string boss          = "invasionbeastbs";
            string message       = "News quickly spreads of an amassing army of Beastmen in " + areaName +
                                   ". They must be stopped before it is too late!";

            InvasionGeneric(area, size, random, creaturetype1, creaturetype2, creaturetype3, creaturetype4,
                            creaturetype5, lieutentant, boss, message);
        }
Beispiel #27
0
        public List <IntPtr> GatherEffectsForObject(uint objectId)
        {
            List <IntPtr> effects = new()
            {
                NWScript.EffectSkillIncrease(NWScript.SKILL_MOVE_SILENTLY, 4),
                NWScript.EffectSkillIncrease(NWScript.SKILL_LISTEN, 1),
                NWScript.EffectSkillIncrease(NWScript.SKILL_SPOT, 1),
                NWScript.EffectImmunity(NWScript.IMMUNITY_TYPE_PARALYSIS),
                NWScript.EffectImmunity(NWScript.IMMUNITY_TYPE_POISON),
                NWScript.EffectSpellImmunity(NWScript.SPELL_PHANTASMAL_KILLER)
            };


            return(effects);
        }
    }
Beispiel #28
0
        public void InvasionGoblins(uint area, int size, int random)
        {
            string areaName      = NWScript.GetName(area);
            string creaturetype1 = "ds_yellowfang_5";
            string creaturetype2 = "ds_yellowfang_1";
            string creaturetype3 = "ds_yellowfang_2";
            string creaturetype4 = "ds_yellowfang_1";
            string creaturetype5 = "ds_yellowfang_2";
            string lieutentant   = "ds_yellowfang_4";
            string boss          = "ds_yellowfang_6";
            string message       = "News quickly spreads of an amassing army of Goblins in " + areaName +
                                   ". They must be stopped before it is too late!";

            InvasionGeneric(area, size, random, creaturetype1, creaturetype2, creaturetype3, creaturetype4,
                            creaturetype5, lieutentant, boss, message);
        }
        private IEnumerable <uint> GetNumberOfSpawnPointsInTrigger()
        {
            uint        waypoint             = NWScript.GetFirstInPersistentObject(_trigger, NWScript.OBJECT_TYPE_WAYPOINT);
            List <uint> spawnPointsInTrigger = new();

            while (waypoint != NWScript.OBJECT_INVALID)
            {
                if (NWScript.GetTag(waypoint).Equals(DsSpwn))
                {
                    spawnPointsInTrigger.Add(waypoint);
                }
                waypoint = NWScript.GetNextInPersistentObject(_trigger, NWScript.OBJECT_TYPE_WAYPOINT);
            }

            return(spawnPointsInTrigger);
        }
Beispiel #30
0
        public List <IntPtr> GatherEffectsForObject(uint objectId)
        {
            _oid             = objectId;
            _hasHeritageFeat = HasHeritageFeat();

            var orogEffects = new List <IntPtr>
            {
                NWScript.EffectSkillIncrease(NWScript.SKILL_CRAFT_ARMOR, 2),
                NWScript.EffectSkillIncrease(NWScript.SKILL_CRAFT_WEAPON, 2),
                NWScript.EffectDamageResistance(NWScript.DAMAGE_TYPE_FIRE, 5),
                NWScript.EffectDamageResistance(NWScript.DAMAGE_TYPE_COLD, 5)
            };

            AddHeritageEffectsIfObjectHasFeat(orogEffects);

            return(orogEffects);
        }
 public NWLocation Location(UInt32 oArea, NWScript.Vector3 vPosition, float fOrientation)
 {
     return ScriptHost.ExecuteActionService_215_5_Location(oArea, vPosition.z, vPosition.y, vPosition.x, (Single)fOrientation);
 }
 public void SetFacingPoint(NWScript.Vector3 vTarget, Int32 bLockToThisOrientation)
 {
     ScriptHost.ExecuteActionService_143_4_SetFacingPoint(vTarget.z, vTarget.y, vTarget.x, bLockToThisOrientation);
 }
 public float VectorToAngle(NWScript.Vector3 vVector)
 {
     return ScriptHost.ExecuteActionService_145_3_VectorToAngle(vVector.z, vVector.y, vVector.x);
 }
 public NWScript.Vector3 VectorNormalize(NWScript.Vector3 vVector)
 {
     return ScriptHost.ExecuteActionService_137_3_VectorNormalize(vVector.z, vVector.y, vVector.x);
 }
 public void PrintVector(NWScript.Vector3 vVector, Int32 bPrepend)
 {
     ScriptHost.ExecuteActionService_141_4_PrintVector(vVector.z, vVector.y, vVector.x, bPrepend);
 }
 public float VectorMagnitude(NWScript.Vector3 vVector)
 {
     return ScriptHost.ExecuteActionService_104_3_VectorMagnitude(vVector.z, vVector.y, vVector.x);
 }
 public UInt32 GetNextObjectInShape(Int32 nShape, float fSize, NWLocation lTarget, Int32 bLineOfSight, Int32 nObjectFilter, NWScript.Vector3 vOrigin)
 {
     return ScriptHost.ExecuteActionService_129_8_GetNextObjectInShape(nShape, (Single)fSize, lTarget, bLineOfSight, nObjectFilter, vOrigin.z, vOrigin.y, vOrigin.x);
 }
 public void SetLookAtTarget(UInt32 oObject, NWScript.Vector3 vTarget, Int32 nType)
 {
     ScriptHost.ExecuteActionService_908_5_SetLookAtTarget(oObject, vTarget.z, vTarget.y, vTarget.x, nType);
 }
 public UInt32 GetFirstSubArea(UInt32 oArea, NWScript.Vector3 vPosition)
 {
     return ScriptHost.ExecuteActionService_998_4_GetFirstSubArea(oArea, vPosition.z, vPosition.y, vPosition.x);
 }
 public NWEffect EffectNWN2SpecialEffectFile(String sFileName, UInt32 oTarget, NWScript.Vector3 vTargetPosition)
 {
     return ScriptHost.ExecuteActionService_792_5_EffectNWN2SpecialEffectFile(sFileName, oTarget, vTargetPosition.z, vTargetPosition.y, vTargetPosition.x);
 }
 public Int32 LineOfSightVector(NWScript.Vector3 vSource, NWScript.Vector3 vTarget)
 {
     return ScriptHost.ExecuteActionService_753_6_LineOfSightVector(vSource.z, vSource.y, vSource.x, vTarget.z, vTarget.y, vTarget.x);
 }
 public void SetCampaignVector(String sCampaignName, String sVarName, NWScript.Vector3 vVector, UInt32 oPlayer)
 {
     ScriptHost.ExecuteActionService_591_6_SetCampaignVector(sCampaignName, sVarName, vVector.z, vVector.y, vVector.x, oPlayer);
 }
 public void FloatingTextStringOnCreature(String sStringToDisplay, UInt32 oCreatureToFloatAbove, Int32 bBroadcastToFaction, float fDuration, Int32 nStartColor, Int32 nEndColor, float fSpeed, NWScript.Vector3 vDirection)
 {
     ScriptHost.ExecuteActionService_526_10_FloatingTextStringOnCreature(sStringToDisplay, oCreatureToFloatAbove, bBroadcastToFaction, (Single)fDuration, nStartColor, nEndColor, (Single)fSpeed, vDirection.z, vDirection.y, vDirection.x);
 }
 public void SoundObjectSetPosition(UInt32 oSound, NWScript.Vector3 vPosition)
 {
     ScriptHost.ExecuteActionService_416_4_SoundObjectSetPosition(oSound, vPosition.z, vPosition.y, vPosition.x);
 }