本文整理汇总了C++中TO_UNIT函数的典型用法代码示例。如果您正苦于以下问题:C++ TO_UNIT函数的具体用法?C++ TO_UNIT怎么用?C++ TO_UNIT使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TO_UNIT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddTarget
void Spell::AddRaidTargets(uint32 i, uint32 TargetType, float r, uint32 maxtargets, bool partylimit)
{
Object* u = m_caster->GetMapMgr()->_GetObject(m_targets.m_unitTarget);
if(u == NULL)
u = m_caster;
Player* p = TO< Player* >(u->GetPlayerOwner());
if(p == NULL || u_caster == NULL)
return;
AddTarget(i, TargetType, p);
ObjectSet::iterator itr;
for(itr = u->GetInRangeSetBegin(); itr != u->GetInRangeSetEnd(); itr++)
{
if(!(*itr)->IsUnit() || !TO_UNIT(*itr)->isAlive())
continue;
//only affect players and pets
if(!(*itr)->IsPlayer() && !(*itr)->IsPet())
continue;
if(!p->InRaid(TO_UNIT(*itr)))
continue;
if(u->CalcDistance(*itr) > r)
continue;
AddTarget(i, TargetType, (*itr));
}
}
示例2: TO_UNIT
Unit* AscentScriptCreatureAI::GetBestUnitTarget( TargetFilter pTargetFilter, float pMinRange, float pMaxRange )
{
//Build potential target list
UnitArray TargetArray;
if ( pTargetFilter & TargetFilter_Friendly )
{
for ( unordered_set< Object* >::iterator ObjectIter = _unit->GetInRangeSetBegin(); ObjectIter != _unit->GetInRangeSetEnd(); ++ObjectIter )
{
if ( IsValidUnitTarget( *ObjectIter, pTargetFilter, pMinRange, pMaxRange ) )
TargetArray.push_back( TO_UNIT( *ObjectIter ) );
};
if ( IsValidUnitTarget( _unit, pTargetFilter ) )
TargetArray.push_back( _unit ); //Also add self as possible friendly target
}
else
{
for ( unordered_set< Object* >::iterator ObjectIter = _unit->GetInRangeOppFactsSetBegin(); ObjectIter != _unit->GetInRangeOppFactsSetEnd(); ++ObjectIter )
{
if ( IsValidUnitTarget( *ObjectIter, pTargetFilter, pMinRange, pMaxRange ) )
TargetArray.push_back( TO_UNIT( *ObjectIter ) );
};
};
return ChooseBestTargetInArray( TargetArray, pTargetFilter );
};
示例3: switch
void DynamicObject::Create(Object* caster, Spell* pSpell, float x, float y, float z, uint32 duration, float radius)
{
Object::_Create(caster->GetMapId(),x, y, z, 0);
if(pSpell->g_caster)
m_parentSpell = pSpell;
m_caster = caster;
switch(caster->GetTypeId())
{
case TYPEID_GAMEOBJECT:
{
p_caster = pSpell->p_caster;
u_caster = pSpell->u_caster;
if(!u_caster && p_caster)
u_caster = TO_UNIT(p_caster);
g_caster = TO_GAMEOBJECT(caster);
}break;
case TYPEID_UNIT:
{
u_caster = TO_UNIT(caster);
}break;
case TYPEID_PLAYER:
{
p_caster = TO_PLAYER(caster);
u_caster = TO_UNIT(caster);
}break;
}
m_spellProto = pSpell->m_spellInfo;
SetUInt64Value(DYNAMICOBJECT_CASTER, caster->GetGUID());
m_uint32Values[OBJECT_FIELD_ENTRY] = m_spellProto->Id;
m_uint32Values[DYNAMICOBJECT_BYTES] = 0x01eeeeee;
m_uint32Values[DYNAMICOBJECT_SPELLID] = m_spellProto->Id;
m_floatValues[DYNAMICOBJECT_RADIUS] = radius;
m_position.x = x;
m_position.y = y;
m_position.z = z;
m_uint32Values[DYNAMICOBJECT_CASTTIME] = (uint32)UNIXTIME;
m_aliveDuration = duration;
m_faction = caster->m_faction;
m_factionDBC = caster->m_factionDBC;
if(caster->dynObj != 0)
{
// expire next update
caster->dynObj->m_aliveDuration = 1;
caster->dynObj->UpdateTargets();
}
caster->dynObj = TO_DYNAMICOBJECT(this);
PushToWorld(caster->GetMapMgr());
sEventMgr.AddEvent(TO_DYNAMICOBJECT(this), &DynamicObject::UpdateTargets, EVENT_DYNAMICOBJECT_UPDATE, 200, 0,EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
}
示例4: TO_UNIT
void DynamicObject::OnRemoveInRangeObject( Object* pObj )
{
if( pObj->IsUnit() )
{
m_inRangeOppFactions.erase( TO_UNIT( pObj ) );
targets.erase( TO_UNIT(pObj) );
}
Object::OnRemoveInRangeObject( pObj );
}
示例5: OUT_DEBUG
/////////////////
// Summoned Go's
//guardians are temporary spawn that will inherit master faction and will follow them. Apart from that they have their own mind
Unit* GameObject::CreateTemporaryGuardian(uint32 guardian_entry,uint32 duration,float angle, Unit* u_caster, uint8 Slot)
{
CreatureProto * proto = CreatureProtoStorage.LookupEntry(guardian_entry);
CreatureInfo * info = CreatureNameStorage.LookupEntry(guardian_entry);
if(!proto || !info)
{
OUT_DEBUG("Warning : Missing summon creature template %u !",guardian_entry);
return NULL;
}
uint32 lvl = u_caster->getLevel();
LocationVector v = GetPositionNC();
float m_followAngle = angle + v.o;
float x = v.x +(3*(cosf(m_followAngle)));
float y = v.y +(3*(sinf(m_followAngle)));
Creature* p = NULL;
p = GetMapMgr()->CreateCreature(guardian_entry);
if(p == NULL)
return NULL;
p->SetInstanceID(GetMapMgr()->GetInstanceID());
p->Load(proto, x, y, v.z, angle);
if (lvl != 0)
{
/* power */
p->SetPowerType(POWER_TYPE_MANA);
p->SetUInt32Value(UNIT_FIELD_MAXPOWER1,p->GetUInt32Value(UNIT_FIELD_MAXPOWER1)+28+10*lvl);
p->SetUInt32Value(UNIT_FIELD_POWER1,p->GetUInt32Value(UNIT_FIELD_POWER1)+28+10*lvl);
/* health */
p->SetUInt32Value(UNIT_FIELD_MAXHEALTH,p->GetUInt32Value(UNIT_FIELD_MAXHEALTH)+28+30*lvl);
p->SetUInt32Value(UNIT_FIELD_HEALTH,p->GetUInt32Value(UNIT_FIELD_HEALTH)+28+30*lvl);
/* level */
p->SetUInt32Value(UNIT_FIELD_LEVEL, lvl);
}
p->SetSummonedByGUID(GetGUID());
p->SetCreatedByGUID(GetGUID());
p->SetZoneId(GetZoneId());
p->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,u_caster->GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE));
p->_setFaction();
p->GetAIInterface()->Init(p,AITYPE_PET,MOVEMENTTYPE_NONE,u_caster);
p->GetAIInterface()->SetUnitToFollow(TO_UNIT(this));
p->GetAIInterface()->SetUnitToFollowAngle(angle);
p->GetAIInterface()->SetFollowDistance(3.0f);
p->PushToWorld(GetMapMgr());
if(duration)
sEventMgr.AddEvent(TO_UNIT(this), &Unit::SummonExpireSlot,Slot, EVENT_SUMMON_EXPIRE, duration, 1,EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT );
return p;
}
示例6: LuaAura_GetCaster
int LuaAura_GetCaster(lua_State * L, Aura * aura)
{
TEST_AURA_RET_NULL();
Object* caster = aura->GetCaster();
if(caster == NULL)
RET_NIL(true);
if (caster->IsUnit()) //unit caster
{
Lunar<Unit>::push(L, TO_UNIT(caster));
return 1;
}
else if (caster->IsGameObject()) //gameobject
{
Lunar<GameObject>::push(L, TO_GAMEOBJECT(caster));
return 1;
}
else if (caster->IsItem()) //item
{
Lunar<Item>::push(L, TO_ITEM(caster));
return 1;
}
RET_NIL(true);
}
示例7: OnQuestComplete
void OnQuestComplete( PlayerPointer mTarget, QuestLogEntry * qLogEntry)
{
if( mTarget == NULL || mTarget->GetMapMgr() == NULL || mTarget->GetMapMgr()->GetInterface() == NULL )
return;
float SSX = mTarget->GetPositionX();
float SSY = mTarget->GetPositionY();
float SSZ = mTarget->GetPositionZ();
GameObjectPointer skull1 = mTarget->GetMapMgr()->GetInterface()->GetGameObjectNearestCoords(SSX, SSY, SSZ, 2551);
if(skull1)
return;
CreaturePointer Kin_weelay = mTarget->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(SSX, SSY, SSZ, 2519);
if(Kin_weelay == NULL)
return;
string msg1 = "Ah. Good ";
msg1 += mTarget->GetName();
msg1 += ". Now let us see what tale these heads tell...";
Kin_weelay->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, msg1.c_str());
Kin_weelay->CastSpell(Kin_weelay, dbcSpell.LookupEntry(3644), false);
skull1->Despawn(5000);
GameObjectPointer skull2 = mTarget->GetMapMgr()->GetInterface()->GetGameObjectNearestCoords(SSX, SSY, SSZ, 2551);
if(skull2)
skull2->Despawn(5000);
if(Kin_weelay == NULL)
return;
string msg = "There, ";
msg += mTarget->GetName();
msg += ". You may now speak to the Bloodscalp chief and his witchdoctor.";
sEventMgr.AddEvent(TO_UNIT(Kin_weelay), &Creature::SendChatMessage, (uint8)CHAT_MSG_MONSTER_SAY, (uint32)LANG_UNIVERSAL, msg.c_str(), EVENT_UNIT_CHAT_MSG, 500, 1, 1);
}
示例8: TO_UNIT
void Player::UpdateInrangeSetsBasedOnReputation()
{
// This function assumes that the opp faction set for player = the opp faction set for the unit.
InRangeSet::iterator itr;
Unit* pUnit;
bool rep_value;
bool enemy_current;
for( itr = m_objectsInRange.begin(); itr != m_objectsInRange.end(); ++itr )
{
if( (*itr)->GetTypeId() != TYPEID_UNIT )
continue;
pUnit = TO_UNIT( *itr );
if(pUnit->m_factionDBC == NULL || pUnit->m_factionDBC->RepListId < 0)
continue;
rep_value = IsHostileBasedOnReputation( pUnit->m_factionDBC );
enemy_current = IsInRangeOppFactSet( pUnit );
if( rep_value && !enemy_current ) // We are now enemies.
m_oppFactsInRange.insert( pUnit );
else if( !rep_value && enemy_current )
m_oppFactsInRange.erase( pUnit );
}
}
示例9: getSelectedChar
bool ChatHandler::HandleDismountCommand(const char* args, WorldSession *m_session)
{
Unit* m_target = NULL;
Player* p_target = getSelectedChar(m_session, false);
if(p_target)
m_target = TO_UNIT(p_target);
else
{
Creature* m_crt = getSelectedCreature(m_session, false);
if(m_crt)
m_target = m_crt;
}
if(!m_target)
RedSystemMessage(m_session, "No target found.");
else if( !m_target->GetUInt32Value( UNIT_FIELD_MOUNTDISPLAYID) )
RedSystemMessage(m_session, "Target is not mounted.");
else
{
m_target->Dismount();
BlueSystemMessage(m_session, "Unit has been dismounted.");
}
return true;
}
示例10: OnQuestStart
void OnQuestStart(Player* mTarget, QuestLogEntry * qLogEntry)
{
if( mTarget == NULL || mTarget->GetMapMgr() == NULL || mTarget->GetMapMgr()->GetInterface() == NULL )
return;
Creature* pMogor = mTarget->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(mTarget->GetPositionX(), mTarget->GetPositionY(), 0, 18069);
if( pMogor != NULL )
{
pMogor->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Prepare yourselves!");
Unit* Qgiver = mTarget->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(mTarget->GetPositionX(), mTarget->GetPositionY(), 0, 18471);
if( Qgiver != NULL )
{
char msg[256];
snprintf((char*)msg, 256, "Mogor has challenged you. You have to accept! Get in the right of blood if you are ready to fight.", mTarget->GetName());
Qgiver->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, msg);
string msg2 = "For the first time in the Ring of Bloods history. Mogor has chosen to exercise his right of the battle! On this wartorn ground, ";
msg2 += mTarget->GetName();
msg2 += " will face Mogor, hero of the Warmaul!";
sEventMgr.AddEvent(TO_UNIT(Qgiver), &Unit::SendChatMessage, (uint8)CHAT_MSG_MONSTER_YELL, (uint32)LANG_UNIVERSAL, msg2.c_str(), EVENT_UNIT_CHAT_MSG, 32000, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
}
pMogor->SetUInt64Value(UNIT_FIELD_FLAGS, 0);
pMogor->GetAIInterface()->SetAllowedToEnterCombat(true);
pMogor->GetAIInterface()->MoveTo(-704.669f, 7871.08f, 45.0387f, 1.59531f);
pMogor->SetFacing(1.908516);
pMogor->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, 14);
}
}
示例11: AIUpdate
void AIUpdate()
{
if (!IsCasting())
{
if (IsTimerFinished(mGrowthTimer))
{
if (mGrowthStacks == 30)
{
RemoveAura(GRUUL_THE_DRAGONKILLER_GROWTH);
mGrowthStacks = 0;
}
if (mGrowthStacks != 29)
{
ResetTimer(mGrowthTimer, 30000);
}
else if (mGrowthStacks == 29)
{
ResetTimer(mGrowthTimer, 300000);
}
ApplyAura(GRUUL_THE_DRAGONKILLER_GROWTH);
++mGrowthStacks;
}
else if (IsTimerFinished(mHurtfulTimer))
{
Unit* pCurrentTarget = _unit->GetAIInterface()->GetNextTarget();
if (pCurrentTarget != NULL)
{
Unit* pTarget = pCurrentTarget;
for (unordered_set<Player*>::iterator itr = _unit->GetInRangePlayerSetBegin(); itr != _unit->GetInRangePlayerSetEnd(); itr++)
{
Player* pPlayer = TO_PLAYER(*itr);
if (!pPlayer->isAlive())
continue;
// if (pPlayer->m_auracount[SPELL_AURA_MOD_INVISIBILITY])
// continue;
if (pPlayer->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FEIGN_DEATH))
continue;
if (GetRangeToUnit(pPlayer) > 8.0f)
continue;
if (_unit->GetAIInterface()->getThreatByPtr(pPlayer) >= _unit->GetAIInterface()->getThreatByPtr(pCurrentTarget))
continue;
pTarget = TO_UNIT(pPlayer);
}
if (pTarget == pCurrentTarget)
CastSpellNowNoScheduling(mHurtfulStrike);
else
_unit->CastSpell(pTarget, GRUUL_THE_DRAGONKILLER_HURTFUL_STRIKE, true);
}
ResetTimer(mHurtfulTimer, 8000);
}
}
ParentClass::AIUpdate();
}
示例12: CastSpellOnRandomTarget
void CastSpellOnRandomTarget(uint32 i, float mindist2cast, float maxdist2cast, int minhp2cast, int maxhp2cast)
{
if(!maxdist2cast) maxdist2cast = 100.0f;
if(!maxhp2cast) maxhp2cast = 100;
if(_unit->GetCurrentSpell() == NULL && _unit->GetAIInterface()->getNextTarget())
{
std::vector<Unit*> TargetTable; /* From M4ksiu - Big THX to Capt who helped me with std stuff to make it simple and fully working <3 */
/* If anyone wants to use this function, then leave this note! */
for(set<Object*>::iterator itr = _unit->GetInRangeSetBegin(); itr != _unit->GetInRangeSetEnd(); ++itr)
{
if(((spells[i].targettype == TARGET_RANDOM_FRIEND && isFriendly(_unit, (*itr))) || (spells[i].targettype != TARGET_RANDOM_FRIEND && isHostile(_unit, (*itr)) && (*itr) != _unit)) && (*itr)->IsUnit()) // isAttackable(_unit, (*itr)) &&
{
Unit* RandomTarget = NULL;
RandomTarget = TO_UNIT(*itr);
if(RandomTarget->isAlive() && _unit->GetDistance2dSq(RandomTarget) >= mindist2cast * mindist2cast && _unit->GetDistance2dSq(RandomTarget) <= maxdist2cast * maxdist2cast && ((RandomTarget->GetHealthPct() >= minhp2cast && RandomTarget->GetHealthPct() <= maxhp2cast && spells[i].targettype == TARGET_RANDOM_FRIEND) || (_unit->GetAIInterface()->getThreatByPtr(RandomTarget) > 0 && isHostile(_unit, RandomTarget))))
{
TargetTable.push_back(RandomTarget);
}
}
}
if(_unit->GetHealthPct() >= minhp2cast && _unit->GetHealthPct() <= maxhp2cast && spells[i].targettype == TARGET_RANDOM_FRIEND)
TargetTable.push_back(_unit);
if(!TargetTable.size())
return;
size_t RandTarget = rand() % TargetTable.size();
Unit* RTarget = TargetTable[RandTarget];
if(!RTarget)
return;
switch(spells[i].targettype)
{
case TARGET_RANDOM_FRIEND:
case TARGET_RANDOM_SINGLE:
_unit->CastSpell(RTarget, spells[i].info, spells[i].instant);
break;
case TARGET_RANDOM_DESTINATION:
_unit->CastSpellAoF(RTarget->GetPositionX(), RTarget->GetPositionY(), RTarget->GetPositionZ(), spells[i].info, spells[i].instant);
break;
}
if(i == 0)
{
_unit->GetAIInterface()->StopMovement(9000);
_unit->setAttackTimer(9000, false);
}
TargetTable.clear();
}
}
示例13: ShatariTorch
bool ShatariTorch(uint32 i, Spell* pSpell)
{
if(pSpell->u_caster->IsPlayer() == false)
return true;
Player* plr = TO_PLAYER(pSpell->u_caster);
Unit* unit_target = TO_UNIT(plr->GetMapMgr()->GetCreature(GET_LOWGUID_PART(plr->GetSelection())));
if(unit_target == NULL)
return true;
if ( plr->CalcDistance( unit_target->GetPositionX(), unit_target->GetPositionY(), unit_target->GetPositionZ(), plr->GetPositionX(), plr->GetPositionY(), plr->GetPositionZ() ) > 5 )
return true;
if(!unit_target->IsCreature())
return true;
Creature* target = TO_CREATURE(unit_target);
QuestLogEntry *qle = plr->GetQuestLogForEntry(10913);
if(qle == NULL)
return true;
GameObject* obj = NULL;
if(target->GetEntry() == 21859)
{
if(qle->GetMobCount(0) == qle->GetQuest()->required_mobcount[0])
return true;
qle->SetMobCount(0, qle->GetMobCount(0)+1);
qle->SendUpdateAddKill(0);
obj = sEAS.SpawnGameobject(plr, 183816, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation(), 1, 0, 0, 0, 0);
sEAS.GameobjectDelete(obj, 1*60*1000);
}
else if(target->GetEntry() == 21846)
{
if(qle->GetMobCount(1) == qle->GetQuest()->required_mobcount[1])
return true;
qle->SetMobCount(1, qle->GetMobCount(1)+1);
qle->SendUpdateAddKill(1);
obj = sEAS.SpawnGameobject(plr, 183816, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation(), 1, 0, 0, 0, 0);
sEAS.GameobjectDelete(obj, 1*60*1000);
}
else
return true;
target->Despawn(0, 1*60*1000);
qle->UpdatePlayerFields();
plr->UpdateNearbyGameObjects();
return true;
}
示例14: TO_UNIT
/******************************************************************************
PUSH METHODS
******************************************************************************/
void LuaEngine::PushUnit(Object * unit, lua_State * LuaS)
{
Unit * pUnit = NULL;
if(unit != NULL && unit->IsUnit())
pUnit = TO_UNIT(unit);
if(LuaS == NULL)
Lunar<Unit>::push(L, pUnit);
else
Lunar<Unit>::push(LuaS, pUnit);
}
示例15: _AddTarget
/// Spell Target Handling for type 54: Targets in Front of the Caster
void Spell::SpellTargetInFrontOfCaster2(uint32 i, uint32 j)
{
unordered_set<Object*>::iterator itr;
for( itr = m_caster->GetInRangeSetBegin(); itr != m_caster->GetInRangeSetEnd(); ++itr )
{
if(!((*itr)->IsUnit()) || !TO_UNIT(*itr)->isAlive())
continue;
//is Creature in range
if(m_caster->isInRange(TO_UNIT(*itr),GetDBCCastTime(i)))
{
if(m_caster->isInFront(TO_UNIT(*itr)))
{
if(isAttackable(u_caster, TO_UNIT(*itr)))
_AddTarget(TO_UNIT(*itr), i);
}
}
}
}