Thread: Bot Commands
View Single Post
  #26  
Old 01-21-2016, 03:37 PM
Uleat's Avatar
Uleat
Developer
 
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
Default

Ok..I think that I've got the basics encapsulated to the point of not needing to replicate checks across every command:

Code:
void bot_command_bind_affinity(Client *c, const Seperator *sep)
{
    // [spell list and dispatch verification]
    bcst_list* local_list = &bot_command_spells[BCEnum::ST_BindAffinity];
    if (spell_list_fail(c, local_list, BCEnum::ST_BindAffinity) || command_alias_fail(c, "bot_command_bind_affinity", sep->arg[0], "bindaffinity"))
        return;

    // ['help'/'usage' argument check] 
    if (is_help_or_usage(sep->arg[1])) {
        c->Message(0, "usage: (<target>) %s", sep->arg[0]);
        send_usage_required_bots(c, BCEnum::ST_BindAffinity);
        return;
    }

    // [selected bot pointer and selectable bot list declarations; populate sbl] 
    Bot* b = nullptr;
    std::list<Bot*> sbl;
    MyBots::PopulateSBL_BySpawnedBots(c, sbl);

    // [client target pointers declaration - self-populating target array based on target type] 
    MyTarget::Pointers mtp;

    // [spell list iterator for given command spell type]
    for (bcst_list::iterator iter_list = local_list->begin(); iter_list != local_list->end(); ++iter_list) {
        STBaseEntry* local_entry = *iter_list;
        if (!local_entry)
            continue;
 
        // [pre-target/-bot spell filtering]
        if (spells[local_entry->spell_id].zonetype && zone->GetZoneType() && !(spells[local_entry->spell_id].zonetype & zone->GetZoneType()))
            continue;

        // [target assignment based on target type and FRIENDLY/ENEMY spell behavior] 
        Mob* t = mtp.Target(c, local_entry->target_type, FRIENDLY);
        if (!t)
            continue;

        // [actionable bot selection based on spell criteria and target type] 
        b = ActionableBots::Select_ByMinLevelAndClass(c, local_entry->target_type, sbl, local_entry->spell_level, local_entry->caster_class, t);
        if (!b)
            continue;

        // bot spell casting
        b->InterruptSpell();
        Bot::BotGroupSay(b, "Attempting to cast '%s' on %s", spells[local_entry->spell_id].name, t->GetCleanName());
        b->CastSpell(local_entry->spell_id, t->GetID(), 1, -1, -1);
 
        break;
    }
    if (!b) {
        c->Message(15, "No bots are capable of performing this action");
        return;
    }
}

Still needs to be fully tested/tweaked..but, it should make adding new commands easier in the long run.
__________________
Uleat of Bertoxxulous

Compilin' Dirty
Reply With Quote