コード例 #1
0
ファイル: Storylet.cs プロジェクト: Cidolfas/Aster
        public bool ShouldShow(Inventory inv)
        {
            for (int i = 0; i < Requirements.Count; i++)
            {
                if (!Requirements[i].IsMet(inv) && Requirements[i].NoShow)
                    return false;
            }

            return true;
        }
コード例 #2
0
ファイル: Storylet.cs プロジェクト: Cidolfas/Aster
        public bool HasMet(Inventory inv)
        {
            for (int i = 0; i < Requirements.Count; i++)
            {
                Data.Log("HasMet: {0} {1} {2}", Name, Requirements[i].QualityName, Requirements[i].IsMet(inv));
                if (!Requirements[i].IsMet(inv))
                    return false;
            }

            return true;
        }
コード例 #3
0
ファイル: Storylet.cs プロジェクト: Cidolfas/Aster
        public int GetOdds(Inventory inv)
        {
            if (Tests.Count == 0)
                return 0;

            float odds = 1f;

            for (int i = 0; i < Tests.Count; i++)
            {
                odds *= (float)Tests[i].GetOdds(inv) / 100;
            }

            return (int)Math.Round(odds * 100);
        }
コード例 #4
0
ファイル: AzaleaBasicView.cs プロジェクト: Cidolfas/Aster
        public static string GetReqString(Storylet.Requirement req, Inventory inv)
        {
            if (req == null || inv == null)
                return "";

            if (req.NoShow) // This controls storylet visibility, not IsMet
                return "";

            bool met = req.IsMet(inv);

            string classname = met ? "met" : "notmet";

            string countword = "";
            switch(req.Req)
            {
                case Storylet.Requirement.ReqType.AtLeast:
                    countword = "you have at least " + req.Value;
                    break;

                case Storylet.Requirement.ReqType.Equals:
                    countword = "you have exactly " + req.Value;
                    break;

                case Storylet.Requirement.ReqType.Has:
                    countword = "you have";
                    break;

                case Storylet.Requirement.ReqType.HasNo:
                    countword = "you have no";
                    break;

                case Storylet.Requirement.ReqType.LessThan:
                    countword = "you have less than " + req.Value;
                    break;

                case Storylet.Requirement.ReqType.Range:
                    countword = "you have between " + req.Value + " and " + req.ValueTwo;
                    break;
            }

            Quality q = Data.GetQuality(req.QualityName);
            string qName = (q != null) ? q.Name : req.QualityName;

            int count = inv.GetCount(req.QualityName);
            string currentCount = (q != null) ? q.GetLevel(count).ToString() : count.ToString();

            return string.Format("<span class='{0}'>Requires {1} {2} (You have {3})</span>", classname, countword, qName, currentCount);
        }
コード例 #5
0
ファイル: AzaleaBasicView.cs プロジェクト: Cidolfas/Aster
        public static string GetInvOpString(Inventory.Result res)
        {
            if (res == null)
                return "NoOpResult";

            string title = (res.Qual != null) ? res.Qual.Title : res.QualName;

            if (res.HasSet)
            {
                if (res.ModifiedDelta == 0)
                {
                    return string.Format("{0} reamins at {1}", title, res.ModifiedEnd);
                }

                return string.Format("{0} is now {1}", title, res.ModifiedEnd);
            }
            if (res.HasGained)
            {
                return string.Format("You now have {0} {1}", res.ModifiedEnd, title);
            }
            if (res.HasLost)
            {
                return string.Format("You have lost all {0}", title);
            }
            if (res.HasIncreased)
            {
                if (res.ModifiedDelta > 0)
                {
                    return string.Format("{0} has increased from {1} to {2}", title, res.ModifiedStart, res.ModifiedEnd);
                }

                return string.Format("{0} is increasing", title);
            }
            if (res.HasDecreased)
            {
                if (res.ModifiedDelta < 0)
                {
                    return string.Format("{0} has decreased from {1} to {2}", title, res.ModifiedStart, res.ModifiedEnd);
                }

                return string.Format("{0} is decreasing", title);
            }

            return string.Format("{0} is unchanged", title);
        }
コード例 #6
0
ファイル: Inventory.cs プロジェクト: Cidolfas/Aster
            public Result ApplyOp(Inventory Items)
            {
                Result res = new Result();
                int before = Items.GetCount(QualityName);
                switch(Op)
                {
                    case OpType.Gain:
                        Items.AddItem(QualityName, Value);
                        break;

                    case OpType.Lose:
                        Items.RemoveItem(QualityName, Value);
                        break;

                    case OpType.Set:
                        Items.SetItem(QualityName, Value);
                        break;

                    case OpType.GainRange:
                        int v = Data.GenericRandom.Next(Value, ValueTwo);
                        Items.AddItem(QualityName, v);
                        break;

                    case OpType.LoseRange:
                        v = Data.GenericRandom.Next(Value, ValueTwo);
                        Items.RemoveItem(QualityName, v);
                        break;
                }
                int after = Items.GetCount(QualityName);
                Data.Log("ApplyOp: {0} {1} from {2} to {3}", QualityName, Op, before, after);

                res.Qual = Data.GetQuality(QualityName);
                res.QualName = QualityName;
                res.Start = before;
                res.End = after;
                res.Op = Op;
                return res;
            }
コード例 #7
0
ファイル: Storylet.cs プロジェクト: Cidolfas/Aster
            public int GetOdds(Inventory inv)
            {
                Quality qual = Data.GetQuality(QualityName);
                int level = inv.GetCount(QualityName);
                if (qual != null)
                    level = qual.GetLevel(level);

                if (TestName != null && Data.TestCurves.ContainsKey(TestName))
                {
                    return Data.TestCurves[TestName](Value, ValueTwo, level);
                }

                int odds = Data.DefaultTestCurve(Value, ValueTwo, level);

                if (Invert)
                    odds = 100-odds;

                return odds;
            }
コード例 #8
0
ファイル: Storylet.cs プロジェクト: Cidolfas/Aster
            public bool IsMet(Inventory inv)
            {
                Quality qual = Data.GetQuality(QualityName);
                int quantity = inv.GetCount(QualityName);
                if (qual != null)
                    quantity = qual.GetLevel(quantity);

                switch (Req)
                {
                    case ReqType.None:
                        return false;

                    case ReqType.Equals:
                        return quantity == Value;

                    case ReqType.LessThan:
                        return quantity < Value;

                    case ReqType.AtLeast:
                        return quantity >= Value;

                    case ReqType.Has:
                        return quantity > 0;

                    case ReqType.HasNo:
                        return quantity == 0;

                    case ReqType.Range:
                        return (quantity >= Value) && (quantity <= ValueTwo);

                    default:
                        return false;
                }
            }
コード例 #9
0
ファイル: AzaleaBasicView.cs プロジェクト: Cidolfas/Aster
        public static string RenderLink(Storylet.Link l, string id, Inventory inv)
        {
            var s = Data.GetStorylet(l.StoryletName);
            if (s == null)
                return "";

            string title = s.LinkTitle;
            string description = s.LinkText;
            if (l.Special == "Onwards")
            {
                title = "Onwards";
                description = null;
            }

            if (l.Special == "Return")
            {
                title = "Return";
                description = null;
            }

            bool valid = !string.IsNullOrEmpty(id);

            string result = string.Format("<div class='{0}'>", valid ? "link" : "link inactive");
            if (valid)
            {
                result += string.Format("<a href=\"#\" onclick=\"doAction('{0}'); return false;\">{1}</a>\n", id, title);
            }
            else
            {
                result += string.Format("<span class='nonoption'>{0}</span>\n", title);
            }

            if (!string.IsNullOrEmpty(description))
                result += string.Format("<p>{0}</p>\n", description);

            if (string.IsNullOrEmpty(l.Special))
            {
                if (s.Type == Storylet.NodeType.Test && s.Tests.Count > 0)
                {
                    result += "<p class='tests'>\n";
                    foreach(var test in s.Tests)
                    {
                        result += string.Format("{0}<br />\n", GetTestString(test, inv));
                    }
                    result += "</p>\n";
                }

                if (s.Requirements.Count > 0)
                {
                    result += "<p class='reqs'>\n";
                    foreach(var req in s.Requirements)
                    {
                        result += string.Format("{0}<br />\n", GetReqString(req, inv));
                    }
                    result += "</p>\n";
                }
            }

            result += "</div>";

            return result;
        }
コード例 #10
0
ファイル: AzaleaBasicView.cs プロジェクト: Cidolfas/Aster
        public static string RenderInventoryOp(Inventory.Result inv)
        {
            string result = "<div class='invOp'>";
            result += string.Format("<p>{0}</p>\n", GetInvOpString(inv));
            result += "</div>";

            return result;
        }
コード例 #11
0
ファイル: AzaleaBasicView.cs プロジェクト: Cidolfas/Aster
        public static string GetTestString(Storylet.Test test, Inventory inv)
        {
            if (test == null || inv == null)
                return "";

            Quality q = Data.GetQuality(test.QualityName);
            string qName = (q != null) ? q.Name : test.QualityName;

            int odds = test.GetOdds(inv);

            return string.Format("Test on {0} {1}%", qName, odds);
        }