Exemplo n.º 1
0
Creature* Factory::GenerateCreature(int iMaxLevel)
{
    vector<Creature*> vProperCreatures;

    for( auto it = vCreatures.begin();
        it != vCreatures.end();
        it++)
    {
        if((*it)->getLevel() <= iMaxLevel)
        {
            vProperCreatures.push_back(*it);
        }
    }

    if(vProperCreatures.size() != 0)
    {
        int iIndex = (mtRandom() % vProperCreatures.size());
        Creature* c_Creature = vProperCreatures[iIndex];

        //use copy constructor to return a copy that is a seperate object
        Creature* pReturnValue = new Creature(*c_Creature);

		//arming creature
		pReturnValue->AddItem(GenerateWeapon());
		
        return pReturnValue;
    }

    return NULL;
}
Exemplo n.º 2
0
bool ChatHandler::HandleAddVendorItemCommand(const char* args)
{
    if (!*args)
        return false;

    Creature* vendor = getSelectedCreature();
    if (!vendor || !vendor->isVendor())
    {
        SendSysMessage("You must select vendor");
        return true;
    }

    char* pitem = strtok((char*)args, " ");
    uint32 itemId = atol(pitem);
    if (!pitem)
    {
        SendSysMessage("You must send id for item");
        return true;
    }

    char* fmaxcount = strtok(NULL, " ");                    //add maxcount, default: 0
    uint32 maxcount = 0;
    if (fmaxcount)
        maxcount = atol(fmaxcount);

    char* fincrtime = strtok(NULL, " ");                    //add incrtime, default: 0
    uint32 incrtime = 0;
    if (fincrtime)
        incrtime = atol(fincrtime);

    ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
    if(!pProto)
    {
        PSendSysMessage(LANG_ITEM_NOT_FOUND, itemId);
        return true;
    }

    if(vendor->FindItem(itemId))
    {
        PSendSysMessage(LANG_ITEM_ALREADY_IN_LIST,itemId);
        return true;
    }

    if (vendor->GetItemCount() >= MAX_CREATURE_ITEMS)
    {
        SendSysMessage("Vendor has too many items (max 128)");
        return true;
    }

    // add to DB and to current ingame vendor
    sDatabase.PExecuteLog("INSERT INTO `npc_vendor` (`entry`,`item`,`maxcount`,`incrtime`) VALUES('%u','%u','%u','%u')",vendor->GetEntry(), itemId, maxcount,incrtime);
    vendor->AddItem(itemId,maxcount,incrtime);
    PSendSysMessage(LANG_ITEM_ADDED_TO_LIST,itemId,pProto->Name1,maxcount,incrtime);
    return false;
}