public static void Sleep(object sender, EventArgs e) { ((Button)sender).Enabled = false; MainForm.Print("休息中……"); Worldtime.GotoNextState(0.3); MainForm.ReflashBasedata(); ((Button)sender).Enabled = true; }
private static void GeneralToolfn(Tool tool, string tag, Dictionary <string, uint> input) { tool.SetUsefn((Prefab who) => { Random rand = new Random(); var traveler = Form1.traveler; char[] separator = { ' ' }; StringSplitOptions options = StringSplitOptions.RemoveEmptyEntries; if (traveler.HasTag(tag)) { if (Worldtime.GetState() == "晚上" && !traveler.HasTag("light")) { // MainForm.Print(traveler.name + "迷失在了黑暗当中"); g_baseresult.LostInDark(); return; } MainForm.SleepTime(); TimeSpan passtime = Worldtime.GetTimeNowToNext(); string hour = Convert.ToString((int)(passtime.TotalHours * 10) / 10.0); //保留一位小数 //-------------------------- var my = (Tool)who; my.curusetime--; if (my.IsBroken()) { traveler.backpack.Remove(my.name, 1); } //---------------------------- Queue <string> output = new Queue <string>(); foreach (var v in input) { int num = (int)(passtime.TotalMinutes * 0.01 * v.Value); // (12-6)*60*0.01 = 3.6 num = rand.Next(num - 1) + 1; string[] str = v.Key.Split(separator, options); if (str.Length != 3) { return; } string spoil = str[0], action = str[1], unit = str[2]; if (traveler.backpack.IsFull() && !traveler.backpack.IsExistObject(spoil)) { output.Enqueue(traveler.name + "花费了" + hour + "小时来" + action + ",掉落了" + num + unit + spoil + ",却因背包满而带不回来。"); } else { traveler.backpack.AddObject(spoil, (uint)num); output.Enqueue(traveler.name + "花费" + hour + "小时来" + action + ",得到了" + (uint)num + unit + spoil + "。"); } } //------------------- MainForm.Print(output); // MainForm.Awake(passtime); MainForm.ReflashBackpackList(); Worldtime.GotoNextState(); MainForm.Awake(); } }); }
public Button(string name, EventHandler fn, int usetime = 1, string prefabname = null, bool GotoNextState = false, double rate = 0.5) { this.name = name; this.maxusetime = this.usetime = usetime; this.prefabname = prefabname; this.fn = (object sender, EventArgs e) => { if (GotoNextState) { Worldtime.GotoNextState(rate); } fn(sender, e); }; }
public Button(string name, ElFN fn, int usetime = 1, bool CanLostInDark = true, bool CanLostCook = true, string prefabname = null, bool GotoNextState = false, double rate = 0.5) { this.name = name; this.maxusetime = this.usetime = usetime; this.prefabname = prefabname; this.fn = (object sender, EventArgs e) => { if (CanLostInDark && Worldtime.GetState() == "晚上" && !Form1.traveler.HasTag("light")) { g_baseresult.LostInDark(); } else { if (this.usetime > 0) //注意不能直接用 usetime-- !!!,因为它是指传入的参数 { --this.usetime; if (fn != null) { fn(this.scane); } if (this.usetime <= 0) { if (linkbutton != null) { linkbutton.Enabled = false; } } } if (CanLostCook) { MainForm.DeCookMenu(); } } if (GotoNextState) { Worldtime.GotoNextState(rate); } }; }