//
        // Float
        //

        #region Float
        public static float GetFloat(NWN2ScriptVarTable variables, string name)
        {
            try
            {
                return variables.GetVariable(name).ValueFloat;
            }
            catch
            {
                return 0.0f;
            }
        }
        //
        // Integer
        //

        #region Integer
        public static int GetInteger(NWN2ScriptVarTable variables, string name)
        {
            try
            {
                return variables.GetVariable(name).ValueInt;
            }
            catch
            {
                return 0;
            }
        }
 public static void SetInteger(NWN2ScriptVarTable variables, string name, int value)
 {
     try
     {
         variables.GetVariable(name).ValueInt = value;
         variables.GetVariable(name).VariableType = NWN2ScriptVariableType.Int;
     }
     catch
     {
         NWN2ScriptVariable var = new NWN2ScriptVariable(name, value);
         var.VariableType = NWN2ScriptVariableType.Int;
         variables.Add(var);
     }
 }
 public static void SetFloat(NWN2ScriptVarTable variables, string name, float value)
 {
     try
     {
         variables.GetVariable(name).ValueFloat = value;
         variables.GetVariable(name).VariableType = NWN2ScriptVariableType.Float;
     }
     catch
     {
         NWN2ScriptVariable var = new NWN2ScriptVariable(name, value);
         var.VariableType = NWN2ScriptVariableType.Float;
         variables.Add(var);
     }
 }
Пример #5
0
 private static NWN2ScriptVarTable removeDuplicates(NWN2ScriptVarTable varTable, LinkedList<String> toRemove)
 {
     // I remove any old duplicates
     LinkedList<NWN2ScriptVariable> varList = new LinkedList<NWN2ScriptVariable>();
     foreach (NWN2ScriptVariable var in varTable.ToArray())
         {
         if (toRemove.Contains(var.Name))
             {
             varList.AddLast(var);
             }
         }
     foreach (NWN2ScriptVariable var in varList)
         {
         varTable.Remove(var);
         }
     return varTable;
 }
Пример #6
0
 private static NWN2ScriptVarTable getAdvanceJournalVar(NWN2ScriptVarTable varTable, string questName, int questId, int xp, LinkedList<string> toRemove)
 {
     toRemove.AddLast("XP");
     toRemove.AddLast("JournalUpdate");
     toRemove.AddLast("nextState");
     removeDuplicates(varTable, toRemove);
     var XP = new NWN2ScriptVariable("XP", xp);
     var journalCategory = new NWN2ScriptVariable("JournalUpdate", "Q_" + questName);
     int state = (questId == 0) ? 1 : questId;
     var journalEntry = new NWN2ScriptVariable("nextState", state);
     varTable.Add(XP);
     varTable.Add(journalCategory);
     varTable.Add(journalEntry);
     return varTable;
 }
Пример #7
0
 private static NWN2ScriptVarTable getAdvanceJournalVar(NWN2ScriptVarTable varTable, string questName, int questId, int xp)
 {
     LinkedList<string> toRemove = new LinkedList<string>();
     return getAdvanceJournalVar(varTable, questName, questId, xp, toRemove);
 }
Пример #8
0
 /// <summary>
 /// Sets all the triggers values so that it has the correct triggers
 /// </summary>
 /// <param name="questName">The name of the quset</param>
 /// <param name="gender">The gender which will be used in the quest</param>
 /// <param name="lang">The spoken (real world) language</param>
 /// <returns>The conversation</returns>
 private NWN2GameConversation triggerFixer(string questName, BWLanguages.Gender gender, BWLanguages.BWLanguage lang)
 {
     NWN2GameConversation cConversation = null;
     if (triggerHappens == convType.Explore)
         {
         NWN2ScriptVarTable varTable = trigger.Var;
         if (varTable == null)
             {
             varTable = new NWN2ScriptVarTable();
             }
         condAdvance(trigger, varTable, questName, questId, xp, "ga_advance_journal", "XP granted for exploration");
         }
     else if (triggerHappens == convType.Escort)
         {
         cConversation = conversationFixer(questName, gender, lang);
         makeEscort(actor.Tag, trigger, cConversation.Name, questName, questId);
         }
     return cConversation;
 }
Пример #9
0
        /// <summary>
        /// The utility method which takes care of settig the trigger correctly
        /// </summary>
        /// <param name="actor">The actor who might be used in the script</param>
        /// <param name="trigger">The trigger we are going to work on</param>
        /// <param name="cConversation">The conversation which will be referenced by the trigger</param>
        /// <param name="triggerHappens">The type of trigger</param>
        private void makeEscort(string actorName, Actor trigger, string convName, string questName, int questId)
        {
            var varTable = trigger.Var;
            if (varTable == null)
                {
                varTable = new NWN2ScriptVarTable();
                }
            LinkedList<String> toRemove = new LinkedList<string>();
            toRemove.AddLast("Conversation");
            toRemove.AddLast("Node");
            toRemove.AddLast("Run");
            toRemove.AddLast("TalkNow");
            toRemove.AddLast("CutsceneBars");
            toRemove.AddLast("OnceOnly");
            toRemove.AddLast("MultiUse");
            toRemove.AddLast("CombatCutsceneSetup");
            toRemove.AddLast("NPC_Tag");

            var Conversation = new NWN2ScriptVariable("Conversation", convName);
            var Node = new NWN2ScriptVariable("Node", 1);
            var Run = new NWN2ScriptVariable("Run", 1);
            var TalkNow = new NWN2ScriptVariable("TalkNow", 1);
            var CutsceneBars = new NWN2ScriptVariable("CutsceneBars", 0);
            var OnceOnly = new NWN2ScriptVariable("OnceOnly", 0);
            var MutilUse = new NWN2ScriptVariable("MultiUse", 1);
            var CombatCutsceneSetup = new NWN2ScriptVariable("CombatCutsceneSetup", 0);
            var NPCTag = new NWN2ScriptVariable("NPC_Tag", actorName);

            // I add the variables to the tables
            varTable = removeDuplicates(varTable, toRemove);

            varTable.Add(Conversation);
            varTable.Add(Node);
            varTable.Add(Run);
            varTable.Add(TalkNow);
            varTable.Add(CutsceneBars);
            varTable.Add(OnceOnly);
            varTable.Add(MutilUse);
            varTable.Add(CombatCutsceneSetup);
            varTable.Add(NPCTag);

            condAdvance(trigger, varTable, questName, questId, 0, "gtr_speak_node", "");
        }
Пример #10
0
        /// <summary>
        /// Currently not correctly implemented - this should make sure that once you open a door/gets an item then the quest is updated
        /// I have yet to find a way to do this without writing a new script - but perhaps you have an idea - if so you are more than welcome 
        /// to contact me
        /// </summary>
        /// <param name="questName">The name of the quset</param>
        /// <param name="gender">The gender which will be used in the quest</param>
        /// <param name="lang">The spoken (real world) language</param>
        /// <returns>The conversation</returns>
        private void doorFixer(string questName, BWLanguages.Gender gender, BWLanguages.BWLanguage lang)
        {
            addInv();
            NWN2GameScript advanceScript = getAdvanceJournal();

            var varTable = new NWN2ScriptVarTable();
            varTable = getAdvanceJournalVar(varTable, questName, questId, xp);
            var resource = advanceScript.Resource;
            if (actor.type == EnumTypes.actorType.Door)
                {
                if (actor.boolInstance)
                    {
                    var instDoor = (NWN2DoorInstance)actor.instance;
                    instDoor.Variables = varTable;
                    instDoor.OnDeath = advanceScript.Resource;
                    instDoor.OnOpen = resource;
                    }
                else
                    {
                    var blueDoor = (NWN2DoorBlueprint)actor.blueprint;
                    blueDoor.Variables = varTable;
                    blueDoor.OnDeath = resource;
                    blueDoor.OnOpen = resource;
                    }
                }
            else if (actor.type == EnumTypes.actorType.Placeable)
                {
                if (actor.boolInstance)
                    {
                    var instPlaceable = (NWN2PlaceableInstance)actor.instance;
                    instPlaceable.Variables = varTable;
                    instPlaceable.OnDeath = resource;
                    if (containerContains && villianItem != null)
                        {
                        NWN2InstanceInventoryItem instanceItem = null;
                        if (villianItem.boolInstance)
                            {
                            instanceItem = createInstanceItemInfo((NWN2ItemInstance)villianItem.instance, false, false);
                            }
                        else
                            {
                            instanceItem = createInstanceItemInfo((NWN2ItemBlueprint)villianItem.blueprint, false, false);
                            }
                        instPlaceable.Inventory.Add(instanceItem);
                        instPlaceable.OnInvDisturbed = resource;
                        }
                    else
                        {
                        instPlaceable.OnOpen = resource;
                        }
                    }
                else
                    {
                    var bluePlaceable = (NWN2PlaceableBlueprint)actor.blueprint;
                    bluePlaceable.Variables = varTable;
                    bluePlaceable.OnDeath = resource;
                    if (containerContains && villianItem != null)
                        {
                        NWN2BlueprintInventoryItem blueItemItem = null;
                        if (villianItem.boolInstance)
                            {
                            blueItemItem = createBlueprintItemInfo((NWN2ItemInstance)villianItem.instance, false, false);
                            }
                        else
                            {
                            blueItemItem = createBlueprintItemInfo((NWN2ItemBlueprint)villianItem.blueprint, false, false);
                            }
                        bluePlaceable.Inventory.Add(blueItemItem);
                        bluePlaceable.OnInvDisturbed = resource;
                        }
                    else
                        {
                        bluePlaceable.OnOpen = resource;
                        }
                    }
                }
        }
        //
        // String
        //

        #region String
        public static string GetString(NWN2ScriptVarTable variables, string name)
        {
            try
            {
                return variables.GetVariable(name).ValueString;
            }
            catch
            {
                return "";
            }
        }
        //
        // String Array - Nonstandard NWN2 type. '*' is replaced with a variable index.
        // Note: Index starts at 1!
        //

        #region String Array
        public static string[] GetStringArray(NWN2ScriptVarTable variables, string name)
        {
            try
            {
                List<string> ret = new List<string>();
                for (uint i = 1; i < uint.MaxValue; i++)
                {
                    string val = GetString(variables, name.Replace("*", i.ToString()));
                    if (val == "")
                        break;
                    ret.Add(val);
                }
                return ret.ToArray();
            }
            catch
            {
                return new string[] {};
            }
        }
Пример #13
0
        private void condAdvance(Actor trigger, NWN2ScriptVarTable varTable, string questName, int questId, int xp, string script, string message)
        {
            LinkedList<String> toRemove = new LinkedList<string>();
            toRemove.AddLast("negate");
            toRemove.AddLast("condition");
            toRemove.AddLast("script");
            toRemove.AddLast("message");
            varTable = getAdvanceJournalVar(varTable, questName, questId, xp, toRemove);
            string value = "";
            if (preReq == EnumTypes.prereq.SimplePrereq || preReq == EnumTypes.prereq.CastSpecificPrereq)
                {
                int questValue = preReqNode.questId;
                if (questValue == 0) questValue = 1;
                value = questValue.ToString();
                }

            NWN2GameScript sayString = module.Scripts["gtr_conditional_run_script"];
            if (sayString == null)
                {
                sayString = new NWN2GameScript("gtr_conditional_run_script", module.Repository.DirectoryName, module.Repository);
                sayString.Data = Properties.Resources.gtr_conditional_run_script;
                sayString.OEISerialize();
                module.Scripts.Add(sayString);
                }

            if (preReq == EnumTypes.prereq.SimplePrereq)
                {
                value = "<" + value;
                NWN2ScriptVariable negate = new NWN2ScriptVariable("negate", 1);
                varTable.Add(negate);
                }

            NWN2ScriptVariable compare1 = new NWN2ScriptVariable("condition", value);
            NWN2ScriptVariable scriptVar = new NWN2ScriptVariable("script", script);
            if (message != "")
                {
                NWN2ScriptVariable messageVar = new NWN2ScriptVariable("message", message);
                varTable.Add(messageVar);
                }

            varTable.Add(compare1);
            varTable.Add(scriptVar);

            trigger.Var = varTable;
            if (trigger.boolInstance)
                {
                ((NWN2TriggerInstance)trigger.instance).OnEnter = sayString.Resource;
                }
            else
                {
                ((NWN2TriggerBlueprint)trigger.blueprint).OnEnter = sayString.Resource;
                }
        }
        //
        // Boolean - Nonstandard NWN2 type. A non-zero integer is true.
        //

        #region Boolean
        public static bool GetBoolean(NWN2ScriptVarTable variables, string name)
        {
            return GetInteger(variables, name) != 0;
        }
 public static void SetBoolean(NWN2ScriptVarTable variables, string name, bool value)
 {
     SetInteger(variables, name, Convert.ToInt32(value));
 }
        public static void DeleteStringArray(NWN2ScriptVarTable variables, string name)
        {
            try
            {
                for (uint i = 1; i < uint.MaxValue; i++)
                {
                    NWN2ScriptVariable var = variables.GetVariable(name.Replace("*", i.ToString()));
                    if (var.VariableType == NWN2ScriptVariableType.None)
                        break;
                    variables.Remove(var);
                }
            }
            catch
            {

            }
        }
        public static void SetStringArray(NWN2ScriptVarTable variables, string name, string[] value)
        {
            try
            {
                DeleteStringArray(variables, name);
                for (uint i = 1; i <= value.Length; i++)
                {
                    SetString(variables, name.Replace("*", i.ToString()), value[i-1]);
                }
            }
            catch
            {

            }
        }
Пример #18
0
        /// <summary>
        /// Creates a conversation that contains a conflict (i.e. the actor will turn hostile)
        /// </summary>
        /// <param name="questName">The name of the quset</param>
        /// <param name="gender">The gender which will be used in the quest</param>
        /// <param name="lang">The spoken (real world) language</param>
        /// <returns>The conversation</returns>
        private NWN2GameConversation conflictFixer(string questName, BWLanguages.Gender gender, BWLanguages.BWLanguage lang)
        {
            // I set the villian to drop the needed loot
            addInv();

            NWN2GameConversation cConversation = null;

            /* If the villian does not talk to the player, but just attacks,
            then we don't need to any of the following */

            if (!villianTalk)
                {
                ushort hostile = 0;
                foreach (NWN2Faction fact in module.FactionData.Factions)
                    {
                    if (fact.Name == "Hostile")
                        {
                        hostile = (ushort)fact.ID;
                        debug("Value for hostile: " + hostile.ToString());
                        break;
                        }
                    }
                if (actor.boolInstance)
                    {
                    NWN2CreatureInstance insActor = (NWN2CreatureInstance)actor.instance;
                    insActor.FactionID = hostile;
                    }
                else
                    {
                    NWN2CreatureBlueprint bluActor = (NWN2CreatureBlueprint)actor.blueprint;
                    bluActor.FactionID = hostile;
                    }
                }
            else
                {
                NWN2GameScript killActor = getAdvanceJournal();

                questName = questNamePrep(questName);
                NWN2ScriptVarTable varTable;
                NWN2CreatureBlueprint creatureBlue = null;
                NWN2CreatureInstance creatureInst = null;

                if (actor.boolInstance)
                    {
                    creatureInst = (NWN2CreatureInstance)actor.instance;
                    varTable = creatureInst.Variables;
                    }
                else
                    {
                    creatureBlue = (NWN2CreatureBlueprint)actor.blueprint;
                    varTable = creatureBlue.Variables;
                    }
                if (varTable == null)
                    {
                    varTable = new NWN2ScriptVarTable();
                    }

                // I remove any old duplicates
                LinkedList<string> toRemove = new LinkedList<string>();
                toRemove.AddLast("DeathScript");
                varTable = getAdvanceJournalVar(varTable, questName, questId, xp, toRemove);
                var deathScript = new NWN2ScriptVariable("DeathScript", "ga_advance_journal");
                varTable.Add(deathScript);

                if (creatureInst != null)
                    {
                    creatureInst.Variables = varTable;
                    }
                else if (creatureBlue != null)
                    {
                    creatureBlue.Variables = varTable;
                    }

                cConversation = conversationFixer(questName, gender, lang);
                }
            return cConversation;
        }
 public static void SetString(NWN2ScriptVarTable variables, string name, string value)
 {
     try
     {
         variables.GetVariable(name).ValueString = value;
         variables.GetVariable(name).VariableType = NWN2ScriptVariableType.String;
     }
     catch
     {
         NWN2ScriptVariable var = new NWN2ScriptVariable(name, value);
         var.VariableType = NWN2ScriptVariableType.String;
         variables.Add(var);
     }
 }