Пример #1
0
        private void RegisterFunctions()
        {
            runner.RegisterFunction("getProgressString", 1, delegate(Yarn.Value[] p)
            {
                return(StoryProgress.Instance.GetString(p[0].AsString));
            });

            runner.RegisterFunction("getProgressInt", 1, delegate(Yarn.Value[] p)
            {
                return(StoryProgress.Instance.GetInt(p[0].AsString));
            });

            runner.RegisterFunction("getProgressBool", 1, delegate(Yarn.Value[] p)
            {
                return(StoryProgress.Instance.GetBool(p[0].AsString));
            });

            runner.RegisterFunction("canGive", 2, delegate(Yarn.Value[] p)
            {
                return(Player.Instance.bag.CanAdd(p[0].AsString, (int)p[1].AsNumber));
            });

            runner.RegisterFunction("has", 2, delegate(Yarn.Value[] p)
            {
                Item i = Player.Instance.bag.Get(p[0].AsString);
                return(i != null && i.Quantity >= (int)p[1].AsNumber);
            });

            runner.RegisterFunction("hasAny", 1, delegate(Yarn.Value[] p)
            {
                Item i = Player.Instance.bag.Get(p[0].AsString);
                return(i != null);
            });

            runner.RegisterFunction("getItemCount", 0, delegate(Yarn.Value[] p)
            {
                Item i = Player.Instance.bag.Get(p[0].AsString);

                if (i != null)
                {
                    return(i.Quantity);
                }
                return(0);
            });

            runner.RegisterFunction("getItemName", 0, delegate(Yarn.Value[] p)
            {
                ItemInfo info = ItemInfo.Get(p[0].AsString);

                if (info != null)
                {
                    return(info.displayName);
                }
                return($"[UNKNOWN ITEM: {p[0].AsString}]");
            });

            runner.RegisterFunction("getMoney", 0, delegate(Yarn.Value[] p) {
                return(ScoreManager.Instance.Money);
            });

            runner.RegisterFunction("getWood", 0, delegate(Yarn.Value[] p) {
                return(ScoreManager.Instance.wood);
            });

            runner.RegisterFunction("getStones", 0, delegate(Yarn.Value[] p) {
                return(ScoreManager.Instance.stones);
            });

            runner.RegisterFunction("getTenderTodayNode", 0, delegate(Yarn.Value[] p) {
                return(FindObjectOfType <Till>().todayNode);
            });

            runner.RegisterFunction("getTenderNode", 1, delegate(Yarn.Value[] p)
            {
                int index = (int)p[0].AsNumber;
                Till till = FindObjectOfType <Till>();
                if (index > -1 && index < till.chatNodes.Length)
                {
                    return(till.chatNodes[index]);
                }
                return("null");
            });
        }