Ejemplo n.º 1
0
        public static void InitPrefabs()
        {
            foreach (string name in material)
            {
                Prefab prefab = new Prefab(name);
                prefab.AddTag("material");
                prefab.AddTag("stackable");//可堆叠
                prefabs.Add(name, prefab);
            }
            foreach (string v in tool)
            {
                string[] str    = v.Split();
                string   name   = str[0];
                int      num    = Convert.ToInt32(str[1]);
                Tool     prefab = new Tool(name, num);
                SetToolUSe(prefab);
                tools.Add(name, prefab);
            }
            foreach (string v in weapon)
            {
                var      traveler = Form1.traveler;
                string[] str      = v.Split();
                string   name     = str[0];
                double   damage   = Convert.ToDouble(str[1]);
                int      usetime  = Convert.ToInt32(str[2]);
                Weapon   prefab   = new Weapon(name, damage, usetime);
                SetWeaponSkills(prefab);

                prefab.usefn1 = (Prefab who) => {
                    var weapon = (Weapon)who;
                    traveler.SetWeapon(weapon);
                    weapon.curusetime--;
                    MainForm.TB_weapon.Text = weapon.name;
                    if (weapon.IsBroken())
                    {
                        MainForm.TB_weapon.Text = "";
                        traveler.backpack.Remove(weapon.name, 1);
                    }
                    MainForm.ReflashBackpackList();
                };

                weapons.Add(name, prefab);
            }
            foreach (string v in armor)
            {
                var      traveler      = Form1.traveler;
                string[] str           = v.Split();
                string   name          = str[0];
                double   defense       = Convert.ToDouble(str[1]);
                double   maxdurability = Convert.ToDouble(str[2]);
                Armor    prefab        = new Armor(name, defense, maxdurability);

                prefab.usefn1 = (Prefab who) => {
                    var armor = (Armor)who;
                    traveler.SetArmor(armor);
                    traveler.backpack.Remove(armor.name, 1);
                    MainForm.TB_armor.Text = armor.name;
                    MainForm.ReflashBackpackList();
                };

                armors.Add(name, prefab);
            }
            foreach (string v in hat)
            {
                var      traveler    = Form1.traveler;
                string[] str         = v.Split();
                string   name        = str[0];
                double   sanitybonus = Convert.ToDouble(str[1]);
                int      usetime     = Convert.ToInt32(str[2]);
                Hat      prefab      = new Hat(name, sanitybonus, usetime);
                prefab.usefn1 = (Prefab who) => {
                    var hat = (Hat)who;
                    traveler.SetHat(hat);
                    traveler.backpack.Remove(who.name, 1);
                    MainForm.TB_hat.Text = who.name;
                    MainForm.timer_baseupdata.Enabled = true;
                };
                hats.Add(name, prefab);
            }
            foreach (string v in food) //简单的烤
            {
                var      traveler = Form1.traveler;
                string[] str      = v.Split();
                string   name     = str[0];
                if (name == "end")
                {
                    continue;
                }
                double hungerdelta = Convert.ToDouble(str[1]);
                double healthdelta = Convert.ToDouble(str[2]);
                double sanitydelta = Convert.ToDouble(str[3]);
                Food   prefab      = new Food(name, hungerdelta, healthdelta, sanitydelta);
                foods.Add(prefab.name, prefab);
                prefab.usefn1 = (Prefab who) => {
                    traveler.Eat((Food)who);
                    traveler.backpack.Remove(who.name, 1);
                    MainForm.ReflashBasedata();
                };

                if (str.Length > 4)
                {
                    double cookhungerdelta = Convert.ToDouble(str[4]);
                    double cookhealthdelta = Convert.ToDouble(str[5]);
                    double cooksanitydelta = Convert.ToDouble(str[6]);

                    Food cookprefab = new Food("烤" + name, cookhungerdelta, cookhealthdelta, cooksanitydelta);
                    cookprefab.recipe.Add(prefab.name, 1);
                    prefab.SetCookfood(cookprefab);

                    foods.Add(cookprefab.name, cookprefab);
                    MainForm.AddCookButton(cookprefab, str[7]);  //强迫加入图片
                    cookprefab.usefn1 = (Prefab who) => {
                        traveler.Eat((Food)who);
                        traveler.backpack.Remove(who.name, 1);
                        MainForm.ReflashBasedata();
                    };
                }
            }

            foreach (string name in goods)
            {
                if (prefabs.ContainsKey(name))
                {
                    prefabs[name].AddTag("tradeable");
                }
                else if (tools.ContainsKey(name))
                {
                    tools[name].AddTag("tradeable");
                }
                else if (weapons.ContainsKey(name))
                {
                    weapons[name].AddTag("tradeable");
                }
                else if (armors.ContainsKey(name))
                {
                    armors[name].AddTag("tradeable");
                }
                else if (foods.ContainsKey(name))
                {
                    foods[name].AddTag("tradeable");
                }
                else
                {
                    Prefab newprefab = new Prefab(name);
                    newprefab.AddTag("tradeable");
                    prefabs.Add(name, newprefab);
                }
            }
        }
Ejemplo n.º 2
0
 public void RemoveArmor()
 {
     this.armor   = null;
     this.defense = 0;
 }
Ejemplo n.º 3
0
 public static void RemovePrefab(Armor prefab)
 {
     armors.Remove(prefab.name);
 }
Ejemplo n.º 4
0
 public void SetArmor(Armor armor)
 {
     this.armor   = armor;
     this.defense = armor.defense;
 }