Exemple #1
0
BOOL CMDToggle::Execute(const std::string &verb, Player* mobile,std::vector<std::string> &args,int subcmd)
{
    World* world  = World::GetPtr();
    OptionManager* omanager = world->GetOptionManager();
    OptionMeta* gopt = nullptr;
    std::vector<Option*> *poptions = nullptr;
    std::vector<OptionMeta*> goptions;
    std::vector<std::string> cols;
    std::vector<std::string> headers;

//if no args were given, print out a list of options:
    if (!args.size())
        {
            headers.push_back("option");
            headers.push_back("value");

            poptions=mobile->GetOptions();
            for (auto pit: *poptions)
                {
                    if (pit->GetMeta()->CanToggle())
                        {
                            cols.push_back(pit->GetMeta()->GetName());
                            cols.push_back(pit->GetValue().GetInt()==0?"off: ":"on ");
                        }
                }

            omanager->ListOptions(&goptions);
            for (OptionMeta* opt: goptions)
                {
                    if (mobile->OptionExists(opt->GetName()))
                        {
                            continue;
                        }
                    if (opt->CanToggle())
                        {
                            cols.push_back(opt->GetName());
                            cols.push_back(opt->GetValue().GetInt()==0?"off: ":"on ");
                        }
                }

            mobile->Message(MSG_LIST, Columnize(&cols, 2, &headers));
            mobile->Message(MSG_INFO, "Note: You can use toggle help <option> to get more help on a specific option.");
            return true;
        }

//see if they want help on a specific option.
    if (args[0] == "help" && args.size() == 2)
        {
            gopt = omanager->GetOption(args[1]);
            if (!gopt)
                {
                    mobile->Message(MSG_ERROR, "That option does not exist.");
                    return false;
                }

            mobile->Message(MSG_INFO, gopt->GetHelp());
            return true;
        }

    mobile->ToggleOption(args[0]);
    return true;
}