예제 #1
0
            void Config(Player p, string modelName, List <string> args)
            {
                StoredCustomModel storedCustomModel = new StoredCustomModel(modelName, true);

                if (!storedCustomModel.Exists())
                {
                    p.Message("%WCustom Model %S{0} %Wnot found!", modelName);
                    return;
                }

                storedCustomModel.LoadFromFile();

                if (args.Count == 0)
                {
                    // /CustomModel [name] config
                    foreach (var entry in ModifiableFields)
                    {
                        var fieldName  = entry.Key;
                        var modelField = entry.Value;
                        if (!modelField.CanEdit(p, modelName))
                        {
                            continue;
                        }

                        p.Message(
                            "{0} = %T{1}",
                            fieldName,
                            modelField.get.Invoke(storedCustomModel)
                            );
                    }
                    return;
                }

                if (args.Count >= 1)
                {
                    // /CustomModel [name] config [field]
                    // or
                    // /CustomModel [name] config [field] [value]
                    var fieldName = args.PopFront();
                    if (!ModifiableFields.ContainsKey(fieldName))
                    {
                        p.Message(
                            "%WNo such field %S{0}!",
                            fieldName
                            );
                        return;
                    }

                    var modelField = ModifiableFields[fieldName];
                    if (args.Count == 0)
                    {
                        // /CustomModel [name] config [field]
                        p.Message(
                            "{0} = %T{1}",
                            fieldName,
                            modelField.get.Invoke(storedCustomModel)
                            );
                        return;
                    }
                    else
                    {
                        // /CustomModel config [field] [value]...
                        var values = args.ToArray();
                        if (values.Length != modelField.types.Length)
                        {
                            p.Message(
                                "%WNot enough values for setting field %S{0}",
                                fieldName
                                );
                        }
                        else
                        {
                            if (!modelField.CanEdit(p, modelName))
                            {
                                p.Message("%WYou can't edit this field on a primary personal model!");
                                return;
                            }

                            if (modelField.set.Invoke(storedCustomModel, p, values))
                            {
                                // field was set, update file!
                                p.Message("%TField %S{0} %Tset!", fieldName);

                                storedCustomModel.WriteToFile();
                                CheckUpdateAll(storedCustomModel);
                            }
                        }
                    }
                }
            }