public double GetRandom() { if (count <= 0) { return(0); } var mh = new long[count]; var ml = new long[count]; long c = 0; for (var i = 0; i < count; ++i) { ml[i] = c; mh[i] = c + (hi[i] - low[i]); c += (hi[i] - low[i]) + 1; } c = QuestRandom.Get("A", (int)c); long f = 0; for (var i = 0; i < count; ++i) { if ((c < ml[i]) || (c > mh[i])) { continue; } f = QuestRandom.Get("B", (int)(hi[i] - low[i] + 1)) + low[i]; } return(f); }
// Changes state of the Location public string FindLocationDescription(int[] playerPars) { var found = false; var text = ""; if (RandomShowLocationDescriptions) { var flag = true; var parse = new QuestCalcParse(); string str = parse.AssignAndPreprocess(LocDescrExprOrder, 1); if (parse.error || parse.default_expression) { flag = false; } if (flag) { parse.Parse(str, playerPars); if (parse.calc_error) { flag = false; } } if (flag) { if ((parse.answer > 10) || (parse.answer < 1)) { flag = false; } } if (flag) { string tmp = LocationDescriptions[parse.answer - 1]; tmp = string.IsNullOrEmpty(tmp) ? "" : tmp.Trim(); if (string.IsNullOrEmpty(tmp)) { flag = false; } } if (flag) { text = LocationDescriptions[parse.answer - 1].Trim(); } if (!flag) { int c = 0; while (!found) { int i = QuestRandom.Get("E", 10);// Random(10) + 1; text = LocationDescriptions[i].Trim(); if (text != "") { found = true; LocationDescription = text; } else { c++; } if (c > MaxLocationDescriptions * 2) { text = ""; found = true; } } } } else { var i = LocDescrOrder; var c = 0; while (!found) { text = LocationDescriptions[i - 1]; if (string.IsNullOrEmpty(text) == false) { found = true; LocationDescription = text.Trim(); LocDescrOrder = i + 1; } else { ++c; } ++i; if (i > MaxLocationDescriptions) { i = 1; } if (c > MaxLocationDescriptions) { text = ""; found = true; LocDescrOrder = i; } } } //!! LocationDescription = Quest.ProcessString(text); return(text); }
private QuestPath GetPathByProbability(List <QuestPath> pathes) { var count = pathes.Count; if (count == 1 && ((!pathes[0].gatesOk && pathes[0].AlwaysShowWhenPlaying) || pathes[0].gatesOk)) { if (pathes[0].Probability < 1) { var k = QuestRandom.Get("C", 1000); var t = (int)Math.Truncate(pathes[0].Probability * 1000); return(k <= t ? pathes[0] : null); } else { return(pathes[0]); } } var always_show_enabled = true; for (var i = 0; i < count; ++i) { if (pathes[i].gatesOk) { always_show_enabled = false; break; } } var ClearedAnswers = new List <QuestPath>(); var custom_maxrnd = new List <int>(); var maxrnd = 0; for (var i = 0; i < count; ++i) { if (pathes[i].gatesOk || (always_show_enabled && pathes[i].AlwaysShowWhenPlaying)) { var max_rand = (int)Math.Round(pathes[i].Probability * 1000); ClearedAnswers.Add(pathes[i]); custom_maxrnd.Add(max_rand); maxrnd = maxrnd + max_rand; } } var cur_rndvalue = QuestRandom.Get("D", maxrnd); var l = 0; for (var i = 0; i < ClearedAnswers.Count; ++i) { if (cur_rndvalue < custom_maxrnd[i] + l) { return(ClearedAnswers[i]); } l += custom_maxrnd[i]; } return(null); }