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); }
protected void CreateNew(string line) { CloseCurrent(); string[] chunks = line.Split(' '); if (chunks.Length < 2) { Data.Log("ERROR: Trying to create storylet without a name!"); return; } currentStorylet = new Storylet(); currentStorylet.Name = chunks[1]; }
protected void CloseCurrent() { inTextBlock = false; inLink = false; if (currentStorylet == null) return; currentStorylet.Body.Trim(); if (!library.ContainsKey(currentStorylet.Name)) { #if DEBUG_LOAD Data.Log("Added Storylet " + currentStorylet.Name + " " + currentStorylet.Title); #endif library.Add(currentStorylet.Name, currentStorylet); } currentStorylet = null; }
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; }
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); }
public void GoToStorylet(Storylet s, ActionResult r) { if (s == null) return; Data.Log("GoTo Storylet {0}", s.Name); foreach (var op in s.Operations) { var opRes = op.ApplyOp(Items); r.InventoryOps.Add(opRes); } if (s.IsLocation) { CurrentLocation = s; r.CountsAsLocation = true; } if (s.MoveLoc != null) { var storylet = Data.GetStorylet(s.MoveLoc); if (storylet != null && storylet.IsLocation) { CurrentLocation = storylet; } } if (s.Type == Storylet.NodeType.PassThrough) { foreach(var link in s.Links) { var storylet = Data.GetStorylet(link.StoryletName); if (storylet != null && storylet.HasMet(Items)) { GoToStorylet(storylet, r); return; } } return; } if (s.Type == Storylet.NodeType.Chance) { Data.Log("Chance!"); int total = 0; var metStorylets = new List<Storylet>(); var metLinks = new List<Storylet.Link>(); foreach(var link in s.Links) { var storylet = Data.GetStorylet(link.StoryletName); if (storylet != null && storylet.HasMet(Items)) { Data.Log("Add chance for {0} {1}", storylet.Name, link.Weight); total += link.Weight; metStorylets.Add(storylet); metLinks.Add(link); } } int roll = Data.GenericRandom.Next(total); Data.Log("Rolled {0} on total {1}", roll, total); for (int i = 0; i < metStorylets.Count; i++) { roll -= metLinks[i].Weight; if (roll < 0) { GoToStorylet(metStorylets[i], r); return; } } return; } if (s.Type == Storylet.NodeType.Test) { int roll; foreach(var test in s.Tests) { bool success = true; int odds = 100 - test.GetOdds(Items); roll = Data.GenericRandom.Next(100); if (roll < odds) success = false; TestResult tr = new TestResult(); tr.Test = test; tr.Success = success; r.Tests.Add(tr); } int total = 0; var metStorylets = new List<Storylet>(); var metLinks = new List<Storylet.Link>(); foreach(var link in s.Links) { if (r.TestSuccess && link.Test != Storylet.Link.TestResult.Success) continue; if (!r.TestSuccess && link.Test != Storylet.Link.TestResult.Failure) continue; var storylet = Data.GetStorylet(link.StoryletName); if (storylet != null && storylet.HasMet(Items)) { total += link.Weight; metStorylets.Add(storylet); metLinks.Add(link); } } roll = Data.GenericRandom.Next(total); for (int i = 0; i < metStorylets.Count; i++) { roll -= metLinks[i].Weight; if (roll < 0) { GoToStorylet(metStorylets[i], r); return; } } return; } r.Storylet = s; }
public bool JumpToStorylet(Storylet s) { if (s == null) { Data.Log("Cannot jump to null storylet"); return false; } Data.Log("Jumping to storylet {0}", s.Name); ActionResult r = new ActionResult(); GoToStorylet(s, r); CurrentAR = r; SetupAR(); return true; }