Пример #1
0
    public bool isEnabled()
    {
        Ink.Runtime.Story story = StoryManager.GetSingleton().GetStory();

        var storyValue = story.variablesState[savedName];

        if (!multiple && storyValue != null && (int)storyValue > 0)
        {
            return(false);
        }

        if (parsedCondition == null && condition != null && condition != "")
        {
            parsedCondition = ConditionParser.parseCondition(condition);
        }

        if (cost > (int)story.variablesState["player_money"])
        {
            return(false);
        }

        if (parsedCondition == null)
        {
            return(true);
        }
        else
        {
            return(parsedCondition.evaluate(new GameState(story)));
        }
    }
Пример #2
0
    public void Buy()
    {
        Ink.Runtime.Story story = StoryManager.GetSingleton().GetStory();

        story.variablesState["player_money"] = (int)story.variablesState["player_money"] - cost;
        story.variablesState[savedName]      = (int)story.variablesState[savedName] + (multiple ? quantity : 1);
    }
    public Boolean LoadStory()
    {
        this.reset();

        if (!this.isJSONFileValid())
        {
            return(false);
        }

        this.story = new Ink.Runtime.Story(this.InkFile.GetMeta("content") as String);
        return(true);
    }
Пример #4
0
    public bool LoadStory()
    {
        Reset();

        if (!IsJSONFileValid())
        {
            GD.PrintErr("The story you're trying to load is not valid.");
            return(false);
        }

        story = new Ink.Runtime.Story(InkFile.GetMeta("content") as string);
        return(true);
    }
Пример #5
0
    public Boolean LoadStory()
    {
        this.reset();

        if (!this.isJSONFileValid())
        {
            GD.PrintErr("The story you're trying to load is not valid.");
            return(false);
        }

        this.story = new Ink.Runtime.Story(this.InkFile.GetMeta("content") as String);
        return(true);
    }
    private void reset()
    {
        this.story = null;

        foreach (String varName in this.observedVariables)
        {
            // TODO Unregister Signal
        }
        this.observedVariables.Clear();

        this.CurrentText    = "";
        this.CurrentTags    = new String[0];
        this.CurrentChoices = new String[0];
    }
Пример #7
0
    /// <summary>
    /// Actually load the story content from <see cref="InkFile"/>.
    /// This method is automatically called in <see cref="_Ready"/> if <see cref="AutoLoadStory"/> is true.
    /// </summary>
    /// <returns>False if there was an error while loading, true otherwise.</returns>
    public Boolean LoadStory()
    {
        reset();

        if (!isJSONFileValid())
        {
            GD.PrintErr("The story you're trying to load is not valid.");
            return(false);
        }

        story          = new Ink.Runtime.Story(InkFile.GetMeta("content") as String);
        story.onError += OnStoryError;
        return(true);
    }
Пример #8
0
    private void reset()
    {
        if (story == null)
        {
            return;
        }

        foreach (String varName in observedVariables)
        {
            RemoveVariableObserver(varName, false);
        }
        observedVariables.Clear();

        story = null;
    }
Пример #9
0
    void JsonRoundtrip()
    {
        var jsonStr = story.ToJson();

        Console.WriteLine(jsonStr);

        Console.WriteLine("---------------------------------------------------");

        var reloadedStory = new Ink.Runtime.Story(jsonStr);
        var newJsonStr    = reloadedStory.ToJson();

        Console.WriteLine(newJsonStr);

        story = reloadedStory;
    }
Пример #10
0
    private void reset()
    {
        if (this.story == null)
        {
            return;
        }

        foreach (String varName in this.observedVariables)
        {
            this.RemoveVariableObserver(varName, false);
        }
        this.observedVariables.Clear();

        this.story = null;
    }
Пример #11
0
    public Ink.Runtime.InkList MakeSharpInkList(Godot.Object list, Ink.Runtime.Story story)
    {
        if (!IsInkObjectOfType(list, "InkList"))
        {
            throw new ArgumentException("Expected a 'Godot.Object' of class 'InkList'");
        }

        var underlyingDictionary =
            (Godot.Collections.Dictionary <Godot.Object, int>)list.Get("_dictionary");
        var originNames = (Godot.Collections.Array <string>)list.Get("origin_names");

        var inkList = new Ink.Runtime.InkList();

        inkList.SetInitialOriginNames(originNames.ToList());

        foreach (string originName in originNames)
        {
            if (story.listDefinitions.TryListGetDefinition(originName, out Ink.Runtime.ListDefinition definition))
            {
                if (!inkList.origins.Contains(definition))
                {
                    inkList.origins.Add(definition);
                }
            }
            else
            {
                throw new Exception(
                          $"InkList origin could not be found in story when reconstructing list: {originName}"
                          );
            }
        }

        foreach (KeyValuePair <Godot.Object, int> kv in underlyingDictionary)
        {
            inkList[MakeSharpInkListItem(kv.Key)] = kv.Value;
        }

        return(inkList);
    }
Пример #12
0
        public void PostExport(Ink.Parsed.Story parsedStory, Ink.Runtime.Story runtimeStory)
        {
            var choiceJsonArray = new JArray();

            var allChoices = parsedStory.FindAll <Choice>();

            foreach (Ink.Parsed.Choice choice in allChoices)
            {
                var sb = new StringBuilder();

                if (choice.startContent != null)
                {
                    sb.Append(choice.startContent.ToString());
                }

                if (choice.choiceOnlyContent)
                {
                    sb.Append(choice.choiceOnlyContent.ToString());
                }

                // Note that this choice text is an approximation since
                // it can be dynamically generated at runtime. We are therefore
                // making the assumption that the startContent and choiceOnlyContent
                // lists contain only string value content.
                var choiceTextApproximation = sb.ToString();
                var filename = choice.debugMetadata.fileName;

                var jsonObj = new JObject();
                jsonObj ["filename"]   = filename;
                jsonObj ["choiceText"] = choiceTextApproximation.ToString();

                choiceJsonArray.Add(jsonObj);
            }

            var jsonString = choiceJsonArray.ToString();

            File.WriteAllText("choiceList.json", jsonString, System.Text.Encoding.UTF8);
        }
Пример #13
0
    public void ProcessQuest(Story story, FileInfo inkFile)
    {
        var fileName = Path.GetFileNameWithoutExtension(inkFile.FullName);
        var quest    = new GalaxyQuest();

        quest.Story = story;
        foreach (var knot in _storyKnotPaths[story])
        {
            var tags = story.TagsForContentAtPath(knot);
            if (tags == null)
            {
                continue;
            }
            var contentTags = GetContentTags(tags);
            if (contentTags.ContainsKey("location"))
            {
                var locationName  = contentTags["location"].First();
                var locationStory = ResolveLocation(locationName);
                if (tags.Contains("required") && locationStory == null)
                {
                    Log($"Quest \"{fileName}\" unable to find required location \"{locationName}\" for knot \"{knot}\"");
                    return;
                }
                quest.KnotLocations[knot] = locationStory;
            }
        }

        foreach (var x in quest.KnotLocations)
        {
            if (!x.Value.KnotQuests.ContainsKey(x.Key))
            {
                x.Value.KnotQuests[x.Key] = new List <GalaxyQuest>();
            }
            x.Value.KnotQuests[x.Key].Add(quest);
        }
    }
Пример #14
0
    public void ProcessLocation(Story story, FileInfo inkFile)
    {
        if (_placedStories.ContainsKey(story))
        {
            return;                   // Don't place already placed stories, idiot!
        }
        _placedStories[story] = null; // Avoids potential for infinite loops when evaluating constraints
        var fileName = Path.GetFileNameWithoutExtension(inkFile.FullName);

        var contentTags = GetContentTags(story.globalTags);

        var constraints = new List <ZoneConstraint>();

        if (contentTags.ContainsKey("constraint"))
        {
            foreach (var constraintString in contentTags["constraint"])
            {
                var args = constraintString.Split(' ');
                var flip = args[0] == "not";
                if (flip)
                {
                    args = args.Skip(1).ToArray();
                }
                var constraintName = args[0];
                args = args.Skip(1).ToArray();
                ZoneConstraint constraint = constraintName switch
                {
                    "DistanceFrom" => new DistanceConstraint(args, this)
                    {
                        Flip = flip
                    },
                    "FactionPresent" => new FactionPresenceConstraint(args, this)
                    {
                        Flip = flip
                    },
                    "FactionOwner" => new FactionOwnerConstraint(args, this)
                    {
                        Flip = flip
                    },
                    _ => null
                };
                if (constraint != null)
                {
                    constraints.Add(constraint);
                }
            }
        }

        ZoneSelector selector;

        if (contentTags.ContainsKey("select"))
        {
            var selectorString = contentTags["select"].First();
            var args           = selectorString.Split(' ');
            var flip           = args[0] == "not";
            if (flip)
            {
                args = args.Skip(1).ToArray();
            }
            var selectorName = args[0];
            args     = args.Skip(1).ToArray();
            selector = selectorName switch
            {
                "DistanceFrom" => new DistanceSelector(args, this)
                {
                    Flip = flip
                },
                _ => new RandomSelector(ref _random)
            };
        }
        else
        {
            selector = new RandomSelector(ref _random);
        }

        var zoneCandidates = new List <GalaxyZone>();

        zoneCandidates.AddRange(Galaxy.Zones.Where(z => !z.NamedZone && constraints.All(c => c.Test(z))));

        var zone = selector.SelectZone(zoneCandidates);

        var location = new LocationStory
        {
            Zone     = zone,
            FileName = fileName,
            Name     = contentTags.ContainsKey("name") ? contentTags["name"].First() : fileName,
            Faction  = contentTags.ContainsKey("faction") ? ResolveFaction(contentTags["faction"].First()) : zone.Owner,
            Security = contentTags.ContainsKey("security")
                ? (SecurityLevel)Enum.Parse(typeof(SecurityLevel), contentTags["security"].First(), true)
                : SecurityLevel.Open,
            Story = story,
            Type  = contentTags.ContainsKey("type")
                ? (LocationType)Enum.Parse(typeof(LocationType), contentTags["type"].First(), true)
                : LocationType.Station,
            Turrets = contentTags.ContainsKey("turrets") ? int.Parse(contentTags["turrets"].First()) : 0
        };

        zone.Locations.Add(location);

        if (contentTags.ContainsKey("namezone"))
        {
            zone.Name = contentTags["namezone"].First();
        }

        _placedStories[story] = location;
    }
Пример #15
0
 public void destroy()
 {
     story = null;
 }
Пример #16
0
 private void CreateStory(string json_story)
 {
     story = new Ink.Runtime.Story(json_story);
 }
Пример #17
0
 public static void BindExternalFunctions(Ink.Runtime.Story story)
 {
     story.BindExternalFunction(GET_VAR_VALUE_FUNC_NAME, (Func <string, object>)GetVarValue);
 }