示例#1
0
        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();
                }
            });
        }
示例#2
0
文件: Form1.cs 项目: SunRiver-NEU/DST
        //***********************************************************************************
        //控制台
        private void TB_input_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up)
            {
                string str = (string)TB_input.Tag;
                TB_input.Text = str;
            }
            else if (e.KeyCode == Keys.Enter)
            {//char[] separator, int count, StringSplitOptions options
                char[]             separator = { ' ', '(', ')', ',', ';', '"', '(', ')', ';', '“', '”' };
                StringSplitOptions options   = StringSplitOptions.RemoveEmptyEntries;
                string[]           str       = TB_input.Text.Split(separator, options);
                if (str.Length <= 0)
                {
                    return;
                }

                if (str.Length > 1) //含有参数的
                {
                    if (str[0] == "c_give" || str[0] == "给我")
                    {
                        if (str[1] == "普通背包" || str[1] == "背包" || str[1] == "猪背包")
                        {
                            traveler.backpack.Resize(str[1] == "猪背包" ? 16 : 12);
                            bakcepackName.Text = str[1];
                        }

                        if (str.Length == 2)
                        {
                            traveler.backpack.AddObject(str[1], 1);
                        }
                        else
                        {
                            uint num;
                            if (uint.TryParse(str[2], out num))
                            {
                                traveler.backpack.AddObject(str[1], num);
                            }
                        }
                        ReflashBackpackList();
                    }
                    else if (str[0] == "printf" || str[0] == "print" || str[0] == "打印")
                    {
                        string output = "";
                        for (int i = 1; i < str.Length; ++i)
                        {
                            output += " " + str[i];
                        }
                        Print(output);
                    }
                    else if (str[0] == "WorldState" || str[0] == "时间")
                    {
                        timer_Time.Enabled = false;
                        Worldtime.SetState(str[1]);
                        timer_Time.Enabled = true;
                    }
                    else if (str[0] == "scane" || str[0] == "场景")
                    {
                        int enterorder;
                        if (str.Length > 2 && int.TryParse(str[2], out enterorder))
                        {
                            if (enterorder <= 0)
                            {
                                enterorder = 0;
                            }
                            else
                            {
                                enterorder = enterorder - 1;
                            }
                        }
                        else
                        {
                            enterorder = 0;
                        }
                        Address address = g_address.GetAddress(str[1]);
                        address.enterorder = enterorder;
                        this.AddAddress(address);
                        this.GotoNextScane();
                    }
                    else if (str[0] == "health" || str[0] == "健康")
                    {
                        int num;
                        if (Int32.TryParse(str[1], out num))
                        {
                            Form1.traveler.currenthealth = num;
                        }
                        ReflashBasedata();
                    }
                    else if (str[0] == "sanity" || str[0] == "精神")
                    {
                        int num;
                        if (Int32.TryParse(str[1], out num))
                        {
                            Form1.traveler.currentsanity = num;
                        }
                        ReflashBasedata();
                    }
                    else if (str[0] == "hunger" || str[0] == "饥饿")
                    {
                        int num;
                        if (Int32.TryParse(str[1], out num))
                        {
                            Form1.traveler.currenthunger = num;
                        }
                        ReflashBasedata();
                    }
                }
                else//不含参数的
                {
                    if (str[0] == "cls" || str[0] == "清屏")
                    {
                        TB_Dialogue.Text = "";
                    }
                    else if (str[0] == "NextWorldState" || str[0] == "下一段")
                    {
                        timer_Time.Enabled = false;
                        Worldtime.AddTime(Worldtime.GetTimeNowToNext());
                        timer_Time.Enabled = true;
                    }
                }

                TB_input.Tag  = TB_input.Text;
                TB_input.Text = "";
                TB_input.Focus();
            }
        }