Exemplo n.º 1
0
        private static void ApplyMessageQuestConditionProxyData(MessageQuestCondition messageQuestCondition, string s)
        {
            if (messageQuestCondition == null || s == null)
            {
                return;
            }
            var fields = s.Split(';');

            if (fields.Length < 7)
            {
                return;
            }
            messageQuestCondition.senderSpecifier = (QuestMessageParticipant)SafeConvert.ToInt(fields[0]);
            messageQuestCondition.senderID        = new StringField(fields[1]);
            messageQuestCondition.targetSpecifier = (QuestMessageParticipant)SafeConvert.ToInt(fields[2]);
            messageQuestCondition.targetID        = new StringField(fields[3]);
            messageQuestCondition.message         = new StringField(fields[4]);
            messageQuestCondition.parameter       = new StringField(fields[5]);
            var valueType = (MessageValueType)SafeConvert.ToInt(fields[6]);

            switch (valueType)
            {
            case MessageValueType.Int:
                messageQuestCondition.value = new MessageValue(SafeConvert.ToInt(fields[7]));
                break;

            case MessageValueType.String:
                messageQuestCondition.value = new MessageValue(fields[7]);
                break;

            default:
                messageQuestCondition.value = new MessageValue();
                break;
            }
        }
Exemplo n.º 2
0
        private static void ApplyCounterQuestConditionProxyData(CounterQuestCondition counterQuestCondition, string s)
        {
            if (counterQuestCondition == null || s == null)
            {
                return;
            }
            var fields = s.Split(';');

            if (fields.Length < 5)
            {
                return;
            }
            counterQuestCondition.counterValueMode = (CounterValueConditionMode)SafeConvert.ToInt(fields[0]);
            var valueType = (QuestNumber.ValueType)SafeConvert.ToInt(fields[1]);

            switch (valueType)
            {
            case QuestNumber.ValueType.Literal:
                counterQuestCondition.requiredCounterValue = new QuestNumber(SafeConvert.ToInt(fields[2]));
                break;

            case QuestNumber.ValueType.CounterValue:
            case QuestNumber.ValueType.CounterMinValue:
            case QuestNumber.ValueType.CounterMaxValue:
                counterQuestCondition.requiredCounterValue              = new QuestNumber();
                counterQuestCondition.requiredCounterValue.valueType    = valueType;
                counterQuestCondition.requiredCounterValue.counterIndex = SafeConvert.ToInt(fields[3]);
                break;

            default:
                counterQuestCondition.requiredCounterValue = new QuestNumber();
                break;
            }
            counterQuestCondition.counterIndex = SafeConvert.ToInt(fields[4]);
        }
Exemplo n.º 3
0
 private static void ApplyTimerQuestConditionProxyData(TimerQuestCondition timerQuestCondition, string s)
 {
     if (timerQuestCondition == null || s == null)
     {
         return;
     }
     timerQuestCondition.counterIndex = SafeConvert.ToInt(s);
 }
Exemplo n.º 4
0
        private static void ApplyHeadingTextQuestContentProxyData(HeadingTextQuestContent headingTextQuestContent, string s)
        {
            if (headingTextQuestContent == null || s == null)
            {
                return;
            }
            var fields = s.Split(';');

            if (fields.Length < 2)
            {
                return;
            }
            headingTextQuestContent.headingLevel = SafeConvert.ToInt(fields[0]);
            headingTextQuestContent.originalText = new StringField(fields[1]);
        }
Exemplo n.º 5
0
        private static void ApplyIconQuestContentProxyData(IconQuestContent iconQuestContent, string s)
        {
            if (iconQuestContent == null || s == null)
            {
                return;
            }
            var fields = s.Split(';');

            if (fields.Length < 3)
            {
                return;
            }
            iconQuestContent.count        = SafeConvert.ToInt(fields[0]);
            iconQuestContent.image        = string.IsNullOrEmpty(fields[1]) ? null : QuestMachine.GetImage(fields[1]);
            iconQuestContent.originalText = new StringField(fields[2]);
        }
Exemplo n.º 6
0
        private static void ApplyButtonQuestContentProxyData(ButtonQuestContent buttonQuestContent, string s)
        {
            if (buttonQuestContent == null || s == null)
            {
                return;
            }
            var fields = s.Split(';');

            if (fields.Length < 4)
            {
                return;
            }
            buttonQuestContent.count          = SafeConvert.ToInt(fields[0]);
            buttonQuestContent.image          = string.IsNullOrEmpty(fields[1]) ? null : QuestMachine.GetImage(fields[1]);
            buttonQuestContent.originalText   = new StringField(fields[2]);
            buttonQuestContent.m_actionsProxy = JsonUtility.FromJson <QuestActionProxyContainer>(fields[3]);
        }
Exemplo n.º 7
0
        public virtual void ConvertStoryToConversation(DialogueDatabase database, Template template, TwineStory story, int actorID, int conversantID)
        {
            this.database = database;
            this.template = template;

            // Get/create conversation:
            var conversation = database.GetConversation(story.name);

            if (conversation == null)
            {
                conversation = template.CreateConversation(template.GetNextConversationID(database), story.name);
                database.conversations.Add(conversation);
            }
            conversation.ActorID      = actorID;
            conversation.ConversantID = conversantID;

            // Reset to just <START> node:
            conversation.dialogueEntries.Clear();
            var startEntry = template.CreateDialogueEntry(0, conversation.id, "START");

            conversation.dialogueEntries.Add(startEntry);

            // Find the highest pid:
            int highestPid = 0;

            foreach (var passage in story.passages)
            {
                highestPid = Mathf.Max(highestPid, SafeConvert.ToInt(passage.pid));
            }

            // Add passages as nodes:
            var allHooks = new Dictionary <TwinePassage, List <TwineHook> >();

            foreach (var passage in story.passages)
            {
                var entryID = SafeConvert.ToInt(passage.pid);
                if (entryID == 0)
                {
                    entryID = ++highestPid;
                }
                var              entry = template.CreateDialogueEntry(entryID, conversation.id, passage.name);
                int              entryActorID, entryConversantID;
                string           dialogueText, sequence, conditions, script;
                List <TwineHook> hooks;
                ExtractParticipants(passage.text, actorID, conversantID, false, out dialogueText, out entryActorID, out entryConversantID);
                ExtractSequenceConditionsScript(ref dialogueText, out sequence, out conditions, out script);
                ExtractHooks(ref dialogueText, out hooks);
                allHooks.Add(passage, hooks);
                dialogueText = RemoveAllLinksFromText(dialogueText);
                ExtractMacros(ref dialogueText, ref entry);
                dialogueText           = ReplaceFormatting(dialogueText);
                entry.DialogueText     = dialogueText.Trim();
                entry.ActorID          = entryActorID;
                entry.ConversantID     = conversantID;
                entry.Sequence         = AppendCode(entry.Sequence, sequence);
                entry.conditionsString = AppendCode(entry.conditionsString, conditions);
                entry.userScript       = AppendCode(entry.userScript, script);
                conversation.dialogueEntries.Add(entry);
            }

            // Link startnode:
            var startnodeID = SafeConvert.ToInt(story.startnode);

            startEntry.outgoingLinks.Add(new Link(conversation.id, startEntry.id, conversation.id, startnodeID));

            // Link nodes:
            foreach (var passage in story.passages)
            {
                if (passage.links == null)
                {
                    continue;
                }
                var originID    = SafeConvert.ToInt(passage.pid);
                var originEntry = conversation.GetDialogueEntry(originID);
                foreach (var link in passage.links)
                {
                    if (link == null)
                    {
                        continue;
                    }
                    var willLinkInHook  = IsLinkInHooks(link.link, allHooks[passage]);
                    var linkedPassageID = SafeConvert.ToInt(link.pid);
                    //-- Save for potential future use: var destinationPassageEntry = conversation.GetDialogueEntry(link.link) ?? conversation.GetDialogueEntry(RemoveFormatting(link.link));
                    if (IsLinkImplicit(link))
                    {
                        // Link passages directly with implicit links (with parens around name):
                        if (!willLinkInHook)
                        {
                            originEntry.outgoingLinks.Add(new Link(conversation.id, originID, conversation.id, linkedPassageID));
                        }
                    }
                    else
                    {
                        // Otherwise add a link entry between passages:
                        var linkEntryTitle = link.name + " Link";
                        var linkEntry      = conversation.GetDialogueEntry(linkEntryTitle);
                        if (linkEntry == null)
                        {
                            linkEntry = template.CreateDialogueEntry(++highestPid, conversation.id, linkEntryTitle);
                            int    linkActorID, linkConversantID;
                            string linkDialogueText, sequence, conditions, script;
                            ExtractParticipants(link.name, actorID, conversantID, true, out linkDialogueText, out linkActorID, out linkConversantID);
                            ExtractSequenceConditionsScript(ref linkDialogueText, out sequence, out conditions, out script);
                            linkEntry.DialogueText     = ReplaceFormatting(linkDialogueText);
                            linkEntry.ActorID          = linkActorID;
                            linkEntry.ConversantID     = linkConversantID;
                            linkEntry.Sequence         = sequence;
                            linkEntry.conditionsString = AppendCode(linkEntry.conditionsString, conditions);
                            linkEntry.userScript       = AppendCode(linkEntry.userScript, script);
                            conversation.dialogueEntries.Add(linkEntry);
                        }
                        conversation.dialogueEntries.Add(linkEntry);
                        if (!willLinkInHook)
                        {
                            originEntry.outgoingLinks.Add(new Link(conversation.id, originID, conversation.id, linkEntry.id));
                        }
                        linkEntry.outgoingLinks.Add(new Link(conversation.id, linkEntry.id, conversation.id, linkedPassageID));
                    }
                }
            }

            // Link hooks:
            foreach (var passage in story.passages)
            {
                var passageID    = SafeConvert.ToInt(passage.pid);
                var passageEntry = conversation.GetDialogueEntry(passageID);
                foreach (var hook in allHooks[passage])
                {
                    int hookActorID, hookConversantID;
                    ExtractParticipants(hook.text, passageEntry.ActorID, passageEntry.ConversantID, true, out hook.text, out hookActorID, out hookConversantID);
                    var conditions = hook.prefix.StartsWith("(if:") ? ConvertIfMacro(hook.prefix) : string.Empty;
                    foreach (var link in hook.links)
                    {
                        var linkEntry = conversation.GetDialogueEntry(link + " Link");
                        if (!string.IsNullOrEmpty(hook.text))
                        {
                            // Hook still has text, so make the text an intermediate entry:
                            var midEntry = template.CreateDialogueEntry(++highestPid, conversation.id, hook.text);
                            midEntry.DialogueText     = hook.text;
                            midEntry.ActorID          = hookActorID;
                            midEntry.ConversantID     = hookConversantID;
                            midEntry.conditionsString = AppendCode(midEntry.conditionsString, conditions);
                            conversation.dialogueEntries.Add(midEntry);
                            passageEntry.outgoingLinks.Add(new Link(conversation.id, passageEntry.id, conversation.id, midEntry.id));
                        }
                        else
                        {
                            // Otherwise link directly from passage to link entry:
                            linkEntry.conditionsString = conditions;
                            passageEntry.outgoingLinks.Add(new Link(conversation.id, passageEntry.id, conversation.id, linkEntry.id));
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Converts a string to an int.
 /// </summary>
 /// <returns>
 /// The int, or <c>0</c> if the string can't be parsed to an int.
 /// </returns>
 /// <param name='s'>
 /// The string.
 /// </param>
 public static int StringToInt(string s)
 {
     return(SafeConvert.ToInt(s));
 }
Exemplo n.º 9
0
        public void DeserializeFromString(string s)
        {
            if (string.IsNullOrEmpty(s) || factionDatabase == null)
            {
                return;
            }

            var traitCount = factionDatabase.relationshipTraitDefinitions.Length;
            var data       = new Queue <string>(s.Split(','));

            if (data.Count < 1)
            {
                return;
            }

            // Get faction count:
            var factionCount = SafeConvert.ToInt(data.Dequeue());

            for (int f = 0; f < Mathf.Min(factionCount, factionDatabase.factions.Length); f++)
            {
                var faction = factionDatabase.factions[f];

                // Get faction ID and name:
                faction.id   = SafeConvert.ToInt(data.Dequeue());
                faction.name = SafeConvert.FromSerializedElement(data.Dequeue());

                // Get faction personality trait values:
                for (int p = 0; p < faction.traits.Length; p++)
                {
                    faction.traits[p] = SafeConvert.ToFloat(data.Dequeue());
                }

                // Get faction parents:
                var parents     = new List <int>();
                var parentCount = SafeConvert.ToInt(data.Dequeue());
                for (int p = 0; p < parentCount; p++)
                {
                    parents.Add(SafeConvert.ToInt(data.Dequeue()));
                }
                faction.parents = parents.ToArray();

                // Release faction's old relationships:
                for (int r = 0; r < faction.relationships.Count; r++)
                {
                    var relationship = faction.relationships[r];
                    Relationship.Release(relationship);
                }
                faction.relationships.Clear();

                // Get faction's relationships:
                var relationshipCount = SafeConvert.ToInt(data.Dequeue());
                for (int r = 0; r < relationshipCount; r++)
                {
                    var id          = SafeConvert.ToInt(data.Dequeue());
                    var inheritable = (SafeConvert.ToInt(data.Dequeue()) == 1);
                    var traits      = new float[traitCount];
                    for (int i = 0; i < traitCount; i++)
                    {
                        traits[i] = SafeConvert.ToFloat(data.Dequeue());
                    }
                    var relationship = Relationship.GetNew(id, inheritable, traits);
                    faction.relationships.Add(relationship);
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Deserializes the faction member's data from a string. This string must
        /// have been generated by SerializeToString. This method replaces the
        /// faction member's current data with the serialized data in the strnig.
        /// </summary>
        /// <param name="s">Seralized data.</param>
        public void DeserializeFromString(string s)
        {
            if (factionManager == null || factionManager.factionDatabase == null)
            {
                return;
            }
            var traitCount = factionManager.factionDatabase.personalityTraitDefinitions.Length;

            var data = new Queue <string>(s.Split(','));

            if (data.Count < 5)
            {
                return;
            }

            // Get faction ID:
            var newFactionID = SafeConvert.ToInt(data.Dequeue());

            if (newFactionID != factionID)
            {
                SwitchFaction(newFactionID);
            }

            // Get PAD:
            pad.happiness = SafeConvert.ToFloat(data.Dequeue());
            pad.pleasure  = SafeConvert.ToFloat(data.Dequeue());
            pad.arousal   = SafeConvert.ToFloat(data.Dequeue());
            pad.dominance = SafeConvert.ToFloat(data.Dequeue());

            try
            {
                StopMemoryCleanup();

                // Release old memories:
                shortTermMemory.Clear();
                for (int m = 0; m < longTermMemory.Count; m++)
                {
                    var mem = longTermMemory[m];
                    Rumor.Release(mem);
                }
                longTermMemory.Clear();
                shortTermMemory.Clear();

                // Get memories:
                var memCount = SafeConvert.ToInt(data.Dequeue());
                for (int m = 0; m < memCount; m++)
                {
                    var mem = Rumor.GetNew();
                    mem.deedGuid        = new System.Guid(data.Dequeue());
                    mem.tag             = data.Dequeue();
                    mem.actorFactionID  = SafeConvert.ToInt(data.Dequeue());
                    mem.targetFactionID = SafeConvert.ToInt(data.Dequeue());
                    mem.impact          = SafeConvert.ToFloat(data.Dequeue());
                    mem.traits          = new float[traitCount];
                    for (int t = 0; t < traitCount; t++)
                    {
                        mem.traits[t] = SafeConvert.ToFloat(data.Dequeue());
                    }
                    mem.count      = SafeConvert.ToInt(data.Dequeue());
                    mem.confidence = SafeConvert.ToFloat(data.Dequeue());
                    mem.pleasure   = SafeConvert.ToFloat(data.Dequeue());
                    mem.arousal    = SafeConvert.ToFloat(data.Dequeue());
                    mem.dominance  = SafeConvert.ToFloat(data.Dequeue());
                    mem.memorable  = true;
                    var shortTermLeft = SafeConvert.ToFloat(data.Dequeue());
                    var longTermLeft  = SafeConvert.ToFloat(data.Dequeue());
                    mem.shortTermExpiration = (shortTermLeft <= 0) ? 0 : GameTime.time + shortTermLeft;
                    mem.longTermExpiration  = GameTime.time + longTermLeft;
                    longTermMemory.Add(mem);
                    if (shortTermLeft > 0)
                    {
                        shortTermMemory.Add(mem);
                    }
                }
            }
            finally
            {
                StartMemoryCleanup();
            }
        }
        private void Import()
        {
            try
            {
                // PersonalityTraits.csv:
                EditorUtility.DisplayProgressBar("Importing Faction Database From CSV", "Importing personality trait definitions...", 0);
                var csv = ReadCSVMinusBlankLastLine(prefs.folder + "/PersonalityTraits.csv");
                if (csv.Count > 1)
                {
                    csv.RemoveAt(0); // Remove heading.
                    db.personalityTraitDefinitions = new TraitDefinition[csv.Count];
                    for (int i = 0; i < csv.Count; i++)
                    {
                        var row = csv[i];
                        db.personalityTraitDefinitions[i] = new TraitDefinition(row[0], row[1]);
                    }
                }

                // RelationshipTraits.csv:
                EditorUtility.DisplayProgressBar("Importing Faction Database From CSV", "Importing relationship trait definitions...", 40);
                csv = ReadCSVMinusBlankLastLine(prefs.folder + "/RelationshipTraits.csv");
                if (csv.Count > 1)
                {
                    csv.RemoveAt(0); // Remove heading.
                    db.relationshipTraitDefinitions = new TraitDefinition[csv.Count];
                    for (int i = 0; i < csv.Count; i++)
                    {
                        var row = csv[i];
                        db.relationshipTraitDefinitions[i] = new TraitDefinition(row[0], row[1]);
                    }
                }

                // Factions.csv:
                EditorUtility.DisplayProgressBar("Importing Faction Database From CSV", "Importing factions...", 60);
                csv = ReadCSVMinusBlankLastLine(prefs.folder + "/Factions.csv");
                if (csv.Count > 1)
                {
                    csv.RemoveAt(0); // Remove heading row.
                    var presetList  = new List <Preset>();
                    var factionList = new List <Faction>();
                    // Get all except parents:
                    for (int i = 0; i < csv.Count; i++)
                    {
                        var row = csv[i];
                        if (row[0].StartsWith("GDE_"))
                        {
                            continue;                            // Skip special Game Data Editor (GDE) rows.
                        }
                        if (prefs.hasPresets && GetColumn(row, prefs.presetColumn) == "1")
                        {
                            var preset = new Preset();
                            preset.name        = GetColumn(row, prefs.nameColumn);
                            preset.description = GetColumn(row, prefs.descriptionColumn);
                            preset.traits      = GetPersonalityTraits(row);
                            presetList.Add(preset);
                        }
                        else
                        {
                            var faction = new Faction();
                            faction.id                  = prefs.autoID ? factionList.Count : SafeConvert.ToInt(GetColumn(row, prefs.idColumn));
                            faction.name                = GetColumn(row, prefs.nameColumn);
                            faction.description         = GetColumn(row, prefs.descriptionColumn);
                            faction.color               = SafeConvert.ToInt(GetColumn(row, prefs.colorColumn));
                            faction.percentJudgeParents = SafeConvert.ToFloat(GetColumn(row, prefs.percentJudgeParentsColumn));
                            faction.traits              = GetPersonalityTraits(row);
                            factionList.Add(faction);
                        }
                    }
                    // Then do parents:
                    int factionIndex = 0;
                    for (int i = 0; i < csv.Count; i++)
                    {
                        var row = csv[i];
                        if (row[0].StartsWith("GDE_"))
                        {
                            continue;                            // Skip special Game Data Editor (GDE) rows.
                        }
                        if (!(prefs.hasPresets && GetColumn(row, prefs.presetColumn) == "1"))
                        {
                            var faction = factionList[factionIndex++];
                            faction.parents = GetParents(row, factionList);
                        }
                    }
                    db.presets  = presetList.ToArray();
                    db.factions = factionList.ToArray();
                }

                // Relationships.csv:
                EditorUtility.DisplayProgressBar("Importing Faction Database From CSV", "Importing relationships...", 60);
                for (int i = 0; i < db.relationshipTraitDefinitions.Length; i++)
                {
                    csv = ReadCSVMinusBlankLastLine(prefs.folder + "/Relationships_" + GetValidFilespec(db.relationshipTraitDefinitions[i].name) + ".csv");
                    if (csv.Count > 1)
                    {
                        for (int j = 1; j < csv.Count; j++) // Skip heading row.
                        {
                            var row = csv[j];
                            if (row.Count == 0)
                            {
                                continue;
                            }
                            var judgeName = row[0];// db.GetFactionID(row[0]);
                            for (int k = 1; k < Mathf.Min(db.factions.Length, row.Count); k++)
                            {
                                var   subjectName = db.factions[k - 1].name;
                                float value;
                                if (float.TryParse(row[k], out value))
                                {
                                    db.SetPersonalRelationshipTrait(judgeName, subjectName, i, value);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
                EditorUtility.SetDirty(db);
            }
            Debug.Log("Exported " + db.name + " to CSV files in " + prefs.folder + ".", db);
        }