Beispiel #1
0
        private ItemStack Load(string name)
        {
            string tname = name.ToLowerFast();
            string fname = "items/" + tname + ".itm";

            if (!TheServer.Files.Exists(fname))
            {
                SysConsole.Output(OutputType.WARNING, "Tried to load non-existent item: " + name);
                return(null);
            }
            try
            {
                string   fdata           = TheServer.Files.ReadText(fname);
                string[] split           = fdata.Replace('\r', '\n').SplitFast('\n');
                string   res_type        = "";
                string   res_icon        = "";
                string   res_display     = "";
                string   res_description = "";
                string   res_color       = "";
                string   res_model       = "";
                string   res_bound       = "";
                string   res_subtype     = null;
                string   res_datum       = "0";
                string   res_weight      = "1";
                string   res_volume      = "1";
                List <KeyValuePair <string, string> > attrs  = new List <KeyValuePair <string, string> >();
                List <KeyValuePair <string, string> > shared = new List <KeyValuePair <string, string> >();
                foreach (string line in split)
                {
                    if (line.Trim().Length < 3)
                    {
                        continue;
                    }
                    string[] dat      = line.SplitFast(':', 1);
                    string   dat_type = dat[0].Trim().ToLowerFast();
                    string   dat_val  = dat[1].Trim();
                    switch (dat_type)
                    {
                    case "type":
                        res_type = dat_val;
                        break;

                    case "subtype":
                        res_subtype = dat_val;
                        break;

                    case "icon":
                        res_icon = dat_val;
                        break;

                    case "display":
                        res_display = dat_val;
                        break;

                    case "description":
                        res_description = dat_val;
                        break;

                    case "color":
                        res_color = dat_val;
                        break;

                    case "model":
                        res_model = dat_val;
                        break;

                    case "bound":
                        res_bound = dat_val;
                        break;

                    case "datum":
                        res_datum = dat_val;
                        break;

                    case "weight":
                        res_weight = dat_val;
                        break;

                    case "volume":
                        res_volume = dat_val;
                        break;

                    default:
                        if (dat_type.StartsWith("shared."))
                        {
                            string opt = dat_type.Substring("shared.".Length).ToLower();
                            shared.Add(new KeyValuePair <string, string>(opt, dat_val));
                        }
                        else if (dat_type.StartsWith("attributes."))
                        {
                            string opt = dat_type.Substring("attributes.".Length).ToLower();
                            attrs.Add(new KeyValuePair <string, string>(opt, dat_val));
                        }
                        break;
                    }
                }
                if (string.IsNullOrEmpty(res_display))
                {
                    res_display = "^[lang=voxalia|items." + tname.Replace("/", ".") + ".display]";
                }
                if (string.IsNullOrEmpty(res_description))
                {
                    res_description = "^[lang=voxalia|items." + tname.Replace("/", ".") + ".description]";
                }
                // TODO: Fix color parsing
                ItemStack it = new ItemStack(res_type, res_subtype, TheServer, 1, res_icon, res_display, res_description,
                                             Color4F.White, res_model, res_bound.ToLower() == "true", ItemStack.IntDatumFor(res_datum))
                {
                    Weight = Utilities.StringToFloat(res_weight),
                    Volume = Utilities.StringToFloat(res_volume)
                };
                foreach (KeyValuePair <string, string> key in shared)
                {
                    string         dat     = UnescapeTagBase.Unescape(key.Value);
                    string         type    = dat.Substring(0, 4);
                    string         content = dat.Substring(5);
                    TemplateObject togive  = ItemStack.TOFor(TheServer, type, content);
                    it.SharedAttributes[key.Key] = togive;
                }
                foreach (KeyValuePair <string, string> key in attrs)
                {
                    string         dat     = UnescapeTagBase.Unescape(key.Value);
                    string         type    = dat.Substring(0, 4);
                    string         content = dat.Substring(5);
                    TemplateObject togive  = ItemStack.TOFor(TheServer, type, content);
                    it.Attributes[key.Key] = togive;
                }
                return(it);
            }
            catch (Exception ex)
            {
                Utilities.CheckException(ex);
                SysConsole.Output("Loading item '" + name + "'", ex);
                return(null);
            }
        }