本文整理汇总了C++中Pet::CreateBaseAtCreature方法的典型用法代码示例。如果您正苦于以下问题:C++ Pet::CreateBaseAtCreature方法的具体用法?C++ Pet::CreateBaseAtCreature怎么用?C++ Pet::CreateBaseAtCreature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pet
的用法示例。
在下文中一共展示了Pet::CreateBaseAtCreature方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleCreatePetCommand
bool ChatHandler::HandleCreatePetCommand(const char* /*args*/)
{
Player* player = m_session->GetPlayer();
Creature* creatureTarget = getSelectedCreature();
if (!creatureTarget || creatureTarget->isPet() || creatureTarget->GetTypeId() == TYPEID_PLAYER)
{
PSendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(creatureTarget->GetEntry());
// Creatures with family 0 crashes the server
if (cInfo->family == 0)
{
PSendSysMessage("This creature cannot be tamed. (family id: 0).");
SetSentErrorMessage(true);
return false;
}
if (player->GetPetGUID())
{
PSendSysMessage("You already have a pet");
SetSentErrorMessage(true);
return false;
}
// Everything looks OK, create new pet
Pet* pet = new Pet(player, HUNTER_PET);
if (!pet->CreateBaseAtCreature(creatureTarget))
{
delete pet;
PSendSysMessage("Error 1");
return false;
}
creatureTarget->setDeathState(JUST_DIED);
creatureTarget->RemoveCorpse();
creatureTarget->SetHealth(0); // just for nice GM-mode view
pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, player->GetGUID());
pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, player->getFaction());
if (!pet->InitStatsForLevel(creatureTarget->getLevel()))
{
sLog->outError("InitStatsForLevel() in EffectTameCreature failed! Pet deleted.");
PSendSysMessage("Error 2");
delete pet;
return false;
}
// prepare visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel()-1);
pet->GetCharmInfo()->SetPetNumber(sObjectMgr->GeneratePetNumber(), true);
// this enables pet details window (Shift+P)
pet->InitPetCreateSpells();
pet->SetFullHealth();
pet->GetMap()->AddToMap(pet->ToCreature());
// visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel());
player->SetMinion(pet, true);
pet->SavePetToDB(PET_SAVE_AS_CURRENT);
player->PetSpellInitialize();
return true;
}
示例2: CreatePet
void CPlayer::CreatePet(uint32 entry, bool classcheck)
{
if (classcheck && getClass() != CLASS_HUNTER)
return;
CreatureInfo const *cinfo = sObjectMgr.GetCreatureTemplate(entry);
if (!cinfo)
{
BoxChat << MSG_COLOR_WHITE << " This pet doesn't exist in our database. Please report that creature " << entry << " is missing." << std::endl;
return;
}
CreatureCreatePos pos(GetSession()->GetPlayer(), GetOrientation());
Creature* pCreature = new Creature;
// used guids from specially reserved range (can be 0 if no free values)
uint32 lowguid = sObjectMgr.GenerateStaticCreatureLowGuid();
if (!lowguid)
return;
if (!pCreature->Create(lowguid, pos, cinfo))
{
delete pCreature;
return;
}
//--------------------------------------------------
if (GetPetGuid())
UnsummonPetTemporaryIfAny();
Pet* pet = new Pet(HUNTER_PET);
if (!pet->CreateBaseAtCreature(pCreature))
{
delete pet;
return;
}
pet->SetOwnerGuid(GetObjectGuid());
pet->SetCreatorGuid(GetObjectGuid());
pet->setFaction(getFaction());
pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, 13481);
if (IsPvP())
pet->SetPvP(true);
if (!pet->InitStatsForLevel(pCreature->getLevel()))
{
sLog.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!", pCreature->GetEntry());
delete pet;
return;
}
pet->GetCharmInfo()->SetPetNumber(sObjectMgr.GeneratePetNumber(), true);
// this enables pet details window (Shift+P)
pet->AIM_Initialize();
pet->InitPetCreateSpells();
pet->SetHealth(pet->GetMaxHealth());
// add to world
pet->GetMap()->Add((Creature*)pet);
// visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL, 70);
for (auto x = 0; x < 6; x++)
{
pet->SetPower(POWER_HAPPINESS, 66600000);
pet->ModifyLoyalty(150000);
pet->TickLoyaltyChange();
pet->SetTP(350);
}
// caster have pet now
SetPet(pet);
pet->SavePetToDB(PET_SAVE_AS_CURRENT);
PetSpellInitialize();
pet->learnSpell(27052);
pet->learnSpell(35698);
pet->learnSpell(25076);
pet->learnSpell(27048);
pet->learnSpell(27053);
pet->learnSpell(27054);
pet->learnSpell(27062);
pet->learnSpell(27047);
pet->learnSpell(24551);
delete pCreature;
}