Exemple #1
0
        public string GetDescription(Token token)
        {
            var canBeIdentified = !UnknownName.IsBlank();
            var isIdentified    = canBeIdentified ? NoxicoGame.Identifications.Contains(ID) : true;

            if (this.ID == "book" && token != null && token.HasToken("id") && NoxicoGame.BookTitles.ContainsKey(token.GetToken("id").Text))
            {
                return(i18n.Format("book_description", NoxicoGame.BookTitles[token.GetToken("id").Text][0], NoxicoGame.BookTitles[token.GetToken("id").Text][1]));
            }
            var a           = string.Empty;
            var description = isIdentified ? "description" : "unknown";

            if (this.HasToken(description))
            {
                var ret   = GetToken(description).Text;
                var color = (token != null && token.HasToken("color")) ? Color.NameColor(token.GetToken("color").Text) : string.Empty;
                var reps  = new Dictionary <string, string>()
                {
                    { "[color]", color },
                    { "[, color]", ", " + color },
                    { "[color ]", color + " " },
                    { "[color, ]", color + ", " },
                };
                if (color.Length == 0)
                {
                    foreach (var key in reps.Keys)
                    {
                        ret = ret.Replace(key, string.Empty);
                    }
                }
                else
                {
                    foreach (var item in reps)
                    {
                        ret = ret.Replace(item.Key, item.Value);
                    }
                }
                return(ret);
            }
            else
            {
                a = Toolkit.StartsWithVowel(this.UnknownName) ? "an " : "a ";
            }
            return(i18n.Format("inventory_thisis_x", this.ToString(token)));            //"This is " + this.ToString(token) + ".";
        }
Exemple #2
0
        public string ToString(Token token, bool the = false, bool a = true)
        {
            if (ID == "book" && token != null && token.HasToken("id") && NoxicoGame.BookTitles.ContainsKey(token.GetToken("id").Text))
            {
                return(string.Format("\"{0}\"", NoxicoGame.BookTitles[token.GetToken("id").Text][0]));
            }

            var canBeIdentified = !UnknownName.IsBlank();
            var isIdentified    = canBeIdentified ? NoxicoGame.Identifications.Contains(ID) : true;

            var name  = isIdentified ? Name : UnknownName;
            var color = (token != null && token.HasToken("color")) ? Color.NameColor(token.GetToken("color").Text) : string.Empty;
            var reps  = new Dictionary <string, string>()
            {
                { "[color]", color },
                { "[, color]", ", " + color },
                { "[color ]", color + " " },
                { "[color, ]", color + ", " },
            };

            if (color.Length == 0)
            {
                foreach (var key in reps.Keys)
                {
                    name = name.Replace(key, string.Empty);
                }
            }
            else
            {
                foreach (var item in reps)
                {
                    name = name.Replace(item.Key, item.Value);
                }
            }

            if (token != null && token.HasToken("bonus"))
            {
                name = string.Format("{0} +{1}", name, token.GetToken("bonus").Value);
            }

            var proper = IsProperNamed && isIdentified;

            if (proper || !a)
            {
                if (the && !string.IsNullOrEmpty(Definite))
                {
                    return(Definite + ' ' + name);
                }
                return(name);
            }
            if (HasToken("charge") && token != null)
            {
                var charge = 0;
                var limit  = "inf";
                if (GetToken("charge").HasToken("limit"))
                {
                    limit = Path("charge/limit").Value.ToString();
                }
                if (token.HasToken("charge") && token.GetToken("charge").Value > 0)
                {
                    charge = (int)token.GetToken("charge").Value;
                    var collective = Path("charge/collectivename");
                    if (collective != null)
                    {
                        name = collective.Text;
                    }
                }
                return(string.Format("{0} {1} ({2}/{3})", the ? Definite : i18n.GetArticle(name), name, charge, limit));
            }
            if (isIdentified)
            {
                return(string.Format("{0} {1}", the ? Definite : Indefinite, name).Trim());
            }
            return(string.Format("{0} {1}", the ? Definite : i18n.GetArticle(UnknownName), name).Trim());
        }