Exemple #1
0
            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;
            }
Exemple #2
0
            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;
            }
Exemple #3
0
            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;
                }
            }
Exemple #4
0
        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);
        }