Example #1
0
void dgBaseNode::CloneFixUp (const dgBaseNode &clone)
{
	dgBaseNode *obj;
	dgBaseNode *cloneChild;

	_ASSERTE (GetNameID() == clone.GetNameID());

	cloneChild = clone.GetChild();
	for (obj = child; obj; obj = obj->sibling) {
		obj->CloneFixUp (*cloneChild);
		cloneChild = cloneChild->GetSibling();
	}
}
Example #2
0
dBaseHierarchy* dBaseHierarchy::Find (unsigned nameCRC) const 
{
	dBaseHierarchy *ptr;

	if (nameCRC == GetNameID()) {
		return (dBaseHierarchy*)this;
	} else {
		for (ptr = GetFirst(); ptr; ptr = ptr->GetNext()) {
			if (nameCRC == ptr->GetNameID()) {
				break;
			}
		}
	}

	return ptr;
}
Example #3
0
BOOL KStatDataManager::Update(const char cszName[], int64_t nValue)
{
    BOOL    bResult = false;
    int     nNameID = 0;

    nNameID = GetNameID(cszName);
    KGLOG_PROCESS_ERROR(nNameID);

    m_StatValues[nNameID - 1] += nValue;

    if (nNameID > m_nMaxUsedID)
        m_nMaxUsedID = nNameID;

    bResult = true;
Exit0:
    return bResult;
}
Example #4
0
// 直接设置某项统计数据的值,慎用
BOOL KStatDataManager::SetDataValue(const char cszName[], int64_t nValue)
{
    BOOL                                        bResult     = false;
    int                                         nRetCode    = 0;
    int                                         nNameID     = 0;
    uint64_t                                    uNewDataID  = 0;

    nNameID = GetNameID(cszName);
    KGLOG_PROCESS_ERROR(nNameID != 0);

    m_StatValues[nNameID - 1] = nValue;
    
    if (nNameID > m_nMaxUsedID)
        m_nMaxUsedID = nNameID;

    bResult = true;
Exit0:
    return bResult;
}
Example #5
0
void cEffect::Reload()
{
	Deinit();
	Init( GetNameID(), macFile );
}
Example #6
0
void Creature::_LoadGoods()
{
    
    itemcount = 0;

    
    std::stringstream query;
    query << "SELECT * FROM vendors WHERE vendorGuid=" << GetGUIDLow();

    QueryResult *result = sDatabase.Query( query.str().c_str() );

	
	if(!result)
	{
		std::stringstream query7;
		query7 << "SELECT * FROM vendors WHERE vendorGuid=" << GetNameID();

		result = sDatabase.Query( query7.str().c_str() );

		if (result)
			Log::getSingleton( ).outError( "Vendor %u has items.", GetNameID() );
	}

	if(!result)
	{
		std::stringstream query2;
		query2 << "SELECT * FROM vendors WHERE vendorGuid=" << uint64(GetGUIDLow()+1);

		result = sDatabase.Query( query2.str().c_str() );
	}

	if(!result)
	{
		std::stringstream query5;
		query5 << "SELECT * FROM vendors WHERE vendorGuid=" << uint64(GetGUIDLow()-10);

		result = sDatabase.Query( query5.str().c_str() );
	}

	if(!result)
	{
		std::stringstream query3;
		query3 << "SELECT * FROM vendors WHERE vendorGuid=" << uint64(GetGUID());

		result = sDatabase.Query( query3.str().c_str() );
	}

	if(!result)
	{
		std::stringstream query4;
		query4 << "SELECT * FROM vendors WHERE vendorGuid=" << uint64(GetGUID()+1);

		result = sDatabase.Query( query4.str().c_str() );
	}

	if(!result)
	{
		std::stringstream query6;
		query6 << "SELECT * FROM vendors WHERE vendorGuid=" << uint64(GetGUID()-10);

		result = sDatabase.Query( query6.str().c_str() );
	}

    if(result)
    {
        do
        {
            Field *fields = result->Fetch();

            if (getItemCount() >= MAX_CREATURE_ITEMS)
            {
                
                
                Log::getSingleton( ).outError( "Vendor %u has too many items (%u >= %i). Check the DB!", GetNameID(), getItemCount(), MAX_CREATURE_ITEMS );
                break;
            }

            setItemId(getItemCount() , fields[1].GetUInt32());
            setItemAmount(getItemCount() , fields[2].GetUInt32());
            increaseItemCount();

        }
        while( result->NextRow() );

        delete result;
    }
}
Example #7
0
void 
Creature::_RealtimeSetCreatureInfo()
{
    
	
    
    
    

    CreatureInfo *ci = NULL;
    bool need_save = false;
    
    if (GetNameID() >= 0 && GetNameID() < 999999)
		ci = objmgr.GetCreatureName(GetNameID());
    
    if (ci)
    {
	if (this->GetFloatValue(UNIT_FIELD_BOUNDINGRADIUS) != ci->bounding_radius)
	    this->SetFloatValue( UNIT_FIELD_BOUNDINGRADIUS, ci->bounding_radius);
	
	
	
		if (this->GetUInt32Value(UNIT_FIELD_DISPLAYID) != ci->DisplayID)
			this->SetUInt32Value( UNIT_FIELD_DISPLAYID, ci->DisplayID );

		if (this->GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID) != ci->DisplayID)
			this->SetUInt32Value( UNIT_FIELD_NATIVEDISPLAYID, ci->DisplayID );

		if (this->GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID) != ci->mount)
			this->SetUInt32Value( UNIT_FIELD_MOUNTDISPLAYID, ci->mount );
		
		if (this->GetUInt32Value(UNIT_FIELD_LEVEL) != ci->level)
			this->SetUInt32Value( UNIT_FIELD_LEVEL, ci->level );

		if (this->GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE) != ci->faction)
			this->SetUInt32Value( UNIT_FIELD_FACTIONTEMPLATE, ci->faction );
	
		
		if (this->GetUInt32Value(UNIT_FIELD_FLAGS) != ci->Type)
			this->SetUInt32Value( UNIT_FIELD_FLAGS, ci->Type );

		
		{
			if ( objmgr.HasTrainerspells( this->GetNameID() ) )
			{


				if (ci->flag != UNIT_NPC_FLAG_TRAINER)
					ci->flag = UNIT_NPC_FLAG_TRAINER;

				this->SetUInt32Value( UNIT_NPC_FLAGS, ci->flag);
			}
			else if (this->getItemCount() > 0)
			{


				if (ci->flag != UNIT_NPC_FLAG_VENDOR)
					ci->flag = UNIT_NPC_FLAG_VENDOR;

				this->SetUInt32Value( UNIT_NPC_FLAGS, ci->flag);
			}
			else
			{
				this->SetUInt32Value( UNIT_NPC_FLAGS, ci->flag);
			}
		}
		
		if (ci->maxhealth > 0 && (ci->flags1 & UNIT_DYNFLAG_DEAD))
			ci->flags1 &= ~UNIT_DYNFLAG_DEAD;

		if (ci->maxhealth > 0 && (ci->flags1 & UNIT_DYNFLAG_LOOTABLE))
			ci->flags1 &= ~UNIT_DYNFLAG_LOOTABLE;

		if (this->GetUInt32Value(UNIT_DYNAMIC_FLAGS) != ci->flags1)
			this->SetUInt32Value( UNIT_DYNAMIC_FLAGS, ci->flags1);

		if (ci->maxhealth <= 0)
		{
			if (ci->level >= 64)
				ci->maxhealth = urand(ci->level*50, ci->level*80);
			else if (ci->level > 48)
				ci->maxhealth = urand(ci->level*40, ci->level*70);
			else if (ci->level > 32)
				ci->maxhealth = urand(ci->level*30, ci->level*60);
			else if (ci->level > 24)
				ci->maxhealth = urand(ci->level*30, ci->level*60);
			else if (ci->level > 16)
				ci->maxhealth = urand(ci->level*40, ci->level*60);
			else
				ci->maxhealth = urand(ci->level*70, ci->level*150);
			
			need_save = true;
		}

		if (this->GetUInt32Value(UNIT_FIELD_MAXHEALTH) != ci->maxhealth)
			this->SetUInt32Value( UNIT_FIELD_MAXHEALTH, ci->maxhealth );

		if (this->GetUInt32Value(UNIT_FIELD_BASE_HEALTH) != ci->maxhealth)
			this->SetUInt32Value( UNIT_FIELD_BASE_HEALTH, ci->maxhealth );




		if (this->GetUInt32Value(UNIT_FIELD_BASE_MANA) != ci->maxmana)
			this->SetUInt32Value( UNIT_FIELD_BASE_MANA, ci->maxmana);
	
		if (ci->baseattacktime <= 1000) 
		{
			if (ci->level > 48)
				ci->baseattacktime = urand(1000, 1500);
			else if (ci->level > 32)
				ci->baseattacktime = urand(1000, 2000);
			else if (ci->level > 24)
				ci->baseattacktime = urand(1000, 3000);
			else if (ci->level > 16)
				ci->baseattacktime = urand(2000, 3000);
			else if (ci->level > 8)
				ci->baseattacktime = urand(2000, 4000);
			else
				ci->baseattacktime = urand(3000, 4000);

			need_save = true;
		}
	
		if (this->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME) != ci->baseattacktime)
			this->SetUInt32Value( UNIT_FIELD_BASEATTACKTIME, ci->baseattacktime);
	
		if (ci->rangeattacktime <= 1000) 
		{
			if (ci->level > 48)
				ci->rangeattacktime = urand(1000, 1500);
			else if (ci->level > 32)
				ci->rangeattacktime = urand(1000, 2000);
			else if (ci->level > 24)
				ci->rangeattacktime = urand(1000, 3000);
			else if (ci->level > 16)
				ci->rangeattacktime = urand(2000, 3000);
			else if (ci->level > 8)
				ci->rangeattacktime = urand(2000, 4000);
			else
				ci->rangeattacktime = urand(3000, 4000);

			need_save = true;
		}
	
		if (this->GetUInt32Value(UNIT_FIELD_RANGEDATTACKTIME) != ci->rangeattacktime)
			this->SetUInt32Value( UNIT_FIELD_RANGEDATTACKTIME, ci->rangeattacktime);
	
		
		if (((ci->mindmg > 1000 && ci->level < 48) || ci->mindmg <= 0)) 
		{
			if (ci->level > 40)
			{
				ci->mindmg = float(ci->level-urand(0, 5));
			}
			else if (ci->level > 30)
			{
				ci->mindmg = float(ci->level-urand(0, 10));
			}
			else if (ci->level > 20)
			{
				ci->mindmg = float(ci->level-urand(0, 15));
			}
			else if (ci->level > 10)
			{
				ci->mindmg = float(ci->level-urand(0, 9));
			}
			else if (ci->level > 5)
			{
				ci->mindmg = float(ci->level-urand(0, 4));
			}
			else
			{
				ci->mindmg = float(ci->level-1);
			}
	    
			if (ci->mindmg <= 0)
				ci->mindmg = float(1);
		}
	
		if (((ci->maxdmg > 1000 && ci->level < 48) || ci->maxdmg <= 0)) 
		{
			if (ci->level > 40)
			{
				ci->maxdmg = float(ci->level+urand(1, 50));
			}
			else if (ci->level > 20)
			{
				ci->maxdmg = float(ci->level+urand(1, 30));
			}
			else if (ci->level > 10)
			{
			ci->maxdmg = float(ci->level+urand(1, 15));
			}
			else if (ci->level > 5)
			{
			ci->maxdmg = float(ci->level+urand(1, 8));
			}
			else
			{
				ci->maxdmg = float(ci->level+urand(1, 4));
			}
	    
			if (ci->maxdmg <= 1)
				ci->maxdmg = float(2);
		}

		if (ci->mindmg > ci->maxdmg)
		{
			uint32 max = ci->mindmg;

			ci->mindmg = ci->maxdmg;
			ci->maxdmg = max;

			need_save = true;
		}
	
		if (this->GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE) != ci->mindmg)
			this->SetFloatValue( UNIT_FIELD_MINRANGEDDAMAGE, ci->mindmg );

		if (this->GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE) != ci->maxdmg)
			this->SetFloatValue( UNIT_FIELD_MAXRANGEDDAMAGE, ci->maxdmg );
	
		if (this->GetFloatValue(UNIT_FIELD_MINDAMAGE) != ci->mindmg)
			this->SetFloatValue( UNIT_FIELD_MINDAMAGE, ci->mindmg );

		if (this->GetFloatValue(UNIT_FIELD_MAXDAMAGE) != ci->maxdmg)
			this->SetFloatValue( UNIT_FIELD_MAXDAMAGE, ci->maxdmg );
	
		
	

		if (ci->scale <= 0 || ci->scale > 2.0)
			ci->scale = 1.0;

		if (this->GetFloatValue(OBJECT_FIELD_SCALE_X) != ci->scale)
			this->SetFloatValue( OBJECT_FIELD_SCALE_X, ci->scale );

		
	
		if (this->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY) != ci->slot1model)
			this->SetUInt32Value( UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ci->slot1model);

		if (this->GetUInt32Value(UNIT_VIRTUAL_ITEM_INFO) != ci->slot1pos)
			this->SetUInt32Value( UNIT_VIRTUAL_ITEM_INFO, ci->slot1pos);
	
		if (this->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01) != ci->slot2model)
			this->SetUInt32Value( UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ci->slot2model);
	
		if (this->GetUInt32Value(UNIT_VIRTUAL_ITEM_INFO) != ci->slot2pos)
			this->SetUInt32Value( UNIT_VIRTUAL_ITEM_INFO+1, ci->slot2pos);
	
		if (this->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02) != ci->slot3model)
			this->SetUInt32Value( UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ci->slot3model);
	
		if (this->GetUInt32Value(UNIT_VIRTUAL_ITEM_INFO) != ci->slot3pos)
			this->SetUInt32Value( UNIT_VIRTUAL_ITEM_INFO+2, ci->slot3pos);
    }

	if (this->GetUInt32Value( UNIT_FIELD_MAXHEALTH ) <= 0 || this->GetUInt32Value( UNIT_FIELD_BASE_HEALTH ) <= 0)
	{
		uint32 maxhealth;

		if (ci->level >= 64)
			maxhealth = urand(getLevel()*50, getLevel()*80);
		else if (ci->level > 48)
			maxhealth = urand(getLevel()*40, getLevel()*70);
		else if (ci->level > 32)
			maxhealth = urand(getLevel()*30, getLevel()*60);
		else if (ci->level > 24)
			maxhealth = urand(getLevel()*30, getLevel()*60);
		else if (ci->level > 16)
			maxhealth = urand(getLevel()*40, getLevel()*60);
		else
			maxhealth = urand(getLevel()*70, getLevel()*150);

		this->SetUInt32Value( UNIT_FIELD_HEALTH, maxhealth );
		this->SetUInt32Value( UNIT_FIELD_BASE_HEALTH, maxhealth );
	}

	
	if( ci->speed > 0 )
	    m_moveSpeed = ci->speed;
	
	if (need_save)
	{
		
	}

    
    
    
}
Example #8
0
void CBattleground::EventCountdown()
{
	if(m_countdownStage == 1)
	{
		m_countdownStage = 2;

		m_mainLock.Acquire();
		for(int i = 0; i < 2; ++i)
		{
			for(set<Player*>::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr)
				if((*itr) && (*itr)->GetSession())
				{
					(*itr)->GetSession()->SystemMessage((*itr)->GetSession()->LocalizedWorldSrv(WORLDSTRING_MINUTE_LEFT_UNTIL_BATTLE), (*itr)->GetSession()->LocalizedWorldSrv(GetNameID()));
				}
		}
		m_mainLock.Release();

		// SendChatMessage( CHAT_MSG_BG_EVENT_NEUTRAL, 0, "One minute until the battle for %s begins!", GetName() );
	}
	else if(m_countdownStage == 2)
	{
		m_countdownStage = 3;

		m_mainLock.Acquire();
		for(int i = 0; i < 2; ++i)
		{
			for(set<Player*>::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr)
				if((*itr) && (*itr)->GetSession())
				{
					(*itr)->GetSession()->SystemMessage((*itr)->GetSession()->LocalizedWorldSrv(WORLDSTRING_THIRTY_SEC_LEFT_UNTIL_BATTLE), (*itr)->GetSession()->LocalizedWorldSrv(GetNameID()));
				}
		}
		m_mainLock.Release();

		//SendChatMessage( CHAT_MSG_BG_EVENT_NEUTRAL, 0, "Thirty seconds until the battle for %s begins!", GetName() );
	}
	else if(m_countdownStage == 3)
	{
		m_countdownStage = 4;

		m_mainLock.Acquire();
		for(int i = 0; i < 2; ++i)
		{
			for(set<Player*>::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr)
				if((*itr) && (*itr)->GetSession())
				{
					(*itr)->GetSession()->SystemMessage((*itr)->GetSession()->LocalizedWorldSrv(WORLDSTRING_FIFTEEN_SEC_LEFT_UNTIL_BATTLE), (*itr)->GetSession()->LocalizedWorldSrv(GetNameID()));
				}
		}
		m_mainLock.Release();

		//SendChatMessage( CHAT_MSG_BG_EVENT_NEUTRAL, 0, "Fifteen seconds until the battle for %s begins!", GetName() );
		sEventMgr.ModifyEventTime(this, EVENT_BATTLEGROUND_COUNTDOWN, 150);
		sEventMgr.ModifyEventTimeLeft(this, EVENT_BATTLEGROUND_COUNTDOWN, 15000);
	}
	else
	{
		m_mainLock.Acquire();
		for(int i = 0; i < 2; ++i)
		{
			for(set<Player*>::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr)
				if((*itr) && (*itr)->GetSession())
				{
					(*itr)->GetSession()->SystemMessage((*itr)->GetSession()->LocalizedWorldSrv(WORLDSTRING_BATTLE_HAS_BEGUN), (*itr)->GetSession()->LocalizedWorldSrv(GetNameID()));
				}
		}
		m_mainLock.Release();
		//SendChatMessage( CHAT_MSG_BG_EVENT_NEUTRAL, 0, "The battle for %s has begun!", GetName() );
		sEventMgr.RemoveEvents(this, EVENT_BATTLEGROUND_COUNTDOWN);
		Start();
	}
}