当前位置: 首页>>代码示例>>C++>>正文


C++ CMonster::DoAi方法代码示例

本文整理汇总了C++中CMonster::DoAi方法的典型用法代码示例。如果您正苦于以下问题:C++ CMonster::DoAi方法的具体用法?C++ CMonster::DoAi怎么用?C++ CMonster::DoAi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CMonster的用法示例。


在下文中一共展示了CMonster::DoAi方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DoAttack


//.........这里部分代码省略.........
                return;                    
            }                
        }
    }
    CMap* map = GServer->MapList.Index[Position->Map];
    //Log(MSG_INFO,"DoAttack Battle Attack type = %i",Battle->atktype);
    switch(Battle->atktype)
    {
        case NORMAL_ATTACK://normal attack
        {
            //if(!Status->CanAttack)
            //    return; //can't attack right now.
            CCharacter* Enemy = GetCharTarget( );
            if(Enemy == NULL)
            {
                ClearBattle( Battle );
                return;
            }
            if(Enemy == this)
            {
                //Log(MSG_INFO,"WTF?? I AM trying to attack myself");
                ClearBattle( Battle );
            }
            if(IsTargetReached( Enemy ))
            {
                //if(IsMonster())
                //    Log(MSG_INFO,"Monster is trying to hit the player");
                NormalAttack( Enemy );
                if (Enemy->IsMonster()) // do monster AI script when monster is attacked.
                {
                    CMonster* monster = GServer->GetMonsterByID(Enemy->clientid, Enemy->Position->Map);
                    if(monster == NULL)return;
                    //monster->DoAi(monster->thisnpc->AI, 3);
                    monster->DoAi(monster->monAI, 3);
                }
            }
        }
        break;
        case SKILL_ATTACK://skill attack
        {
            CCharacter* Enemy = GetCharTarget( );
            if(Enemy == NULL)
            {
                ClearBattle( Battle );
                return;
            }
            CSkills* skill = GServer->GetSkillByID( Battle->skillid );
            if(skill == NULL)
            {
                //ClearBattle( Battle );
                return;
            }
            if(IsTargetReached( Enemy, skill )) 
            {
                SkillAttack( Enemy, skill );
                if (Enemy->IsMonster())
                {
                    CMonster* monster = GServer->GetMonsterByID(Enemy->clientid, Enemy->Position->Map);
                    if(monster == NULL)return;
                    monster->DoAi(monster->monAI, 3);
                }
            }
        }
        break;
        case SKILL_BUFF://buffs
        {
开发者ID:osROSE,项目名称:osprose,代码行数:67,代码来源:battle.cpp

示例2: MapProcess


//.........这里部分代码省略.........
                         //Log(MSG_DEBUG,"Spawning TD mob of type %i at position %i in the list for map %i",nextmon, map->TDNextSpawn, map->id);
                         map->AddMonster(nextmon, GServer->WPList[map->id][1].pos, 0, 0, 0, 1, 0, 999 ); //spawn a TD mob with no AI
                         //Log(MSG_DEBUG,"Spawned mob in addmonster");
                         map->TDMobList[map->TDNextSpawn] = 0; //clear the spawn
                         //Log(MSG_DEBUG,"cleared the spawn");
                         map->TDNextSpawn++; //move the pointer
                         //Log(MSG_DEBUG,"moved the pointer");
                         if(map->TDNextSpawn > 100)map->TDNextSpawn = 0;
                         map->lastTDSpawnTime = clock();
                    }
                }
                //TD spawn end

                for(UINT j=0;j<map->MonsterList.size();j++)
                {
                    CMonster* monster = map->MonsterList.at(j);
                    //UINT thistimer = monster->AItimer;
                    clock_t etime = clock() - monster->lastAiUpdate;

                    //LMA: only summon ?
                    if (only_summon&&!monster->IsSummon())
                    {
                        continue;
                    }
                    else if(only_summon)
                    {
                        nb_summons_map++;
                    }

					if(monster->hitcount == 0xFF)//this is a delay for new monster spawns this might olso fix invisible monsters(if they attack directly on spawning the client dosn't get the attack packet(its not in it's visible list yet))
                    {
                        monster->hitcount = 0;
                        //monster->DoAi(monster->thisnpc->AI, 0);
                        monster->DoAi(monster->MonAI, 0);		//AI on spawn
                        monster->lastAiUpdate=clock();
                    }

                    //PY handling day only or night only monsters. 
                    
					if(!map->IsNight( ) && monster->Status->nightonly)// if day, delete all night time monsters
                    {
                        //Log( MSG_INFO, "Night Only monster deleted. Type %i", monster->montype);
                        map->DeleteMonster( monster, true, j );
                        continue;
                    }
                    if(map->IsNight() && monster->Status->dayonly)
                    {
                        //Log( MSG_INFO, "Day Only monster deleted. Type %i", monster->montype);
                        map->DeleteMonster( monster, true, j );
                        continue;
                    }

                    //Do TD stuff
                    if(monster->MonAI == 999 && etime >= monster->AITimer) //It's a TD mob
                    {
                        monster->UpdatePosition(monster->stay_still );
                        float distance = GServer->distance( monster->Position->current, monster->Position->destiny );
                        //Log( MSG_INFO, "Found a TD monster %f from target. Waypoint type = %i stance %i speed %i", distance,GServer->WPList[map->id][monster->NextWayPoint].WPType,monster->Stats->stance, monster->Stats->Move_Speed);
                        //Log( MSG_INFO, "monster location X: %f Y: %f",monster->Position->current.x, monster->Position->current.y);
                        //Log( MSG_INFO, "WP location X: %f Y: %f ", GServer->WPList[map->id][monster->NextWayPoint].pos.x,GServer->WPList[map->id][monster->NextWayPoint].pos.y);
                        if(distance < 1) //monster has reached it's destination
                        {
                            switch(GServer->WPList[map->id][monster->NextWayPoint].WPType)
                            {
                                case 1: //Start waypoint
                                case 2: //regular waypoint. Increment waypoint counter. Set detiny to next waypoint
开发者ID:PurpleYouko,项目名称:KTRose_Server,代码行数:67,代码来源:MainProcess.cpp

示例3: MapProcess

// Map Process
PVOID MapProcess( PVOID TS )
{
    bool only_npc = false;
    while(GServer->ServerOnline)
    {
        pthread_mutex_lock( &GServer->PlayerMutex );
        pthread_mutex_lock( &GServer->MapMutex );
        for(UINT i=0;i<GServer->MapList.Map.size();i++)
        {
            CMap* map = GServer->MapList.Map.at(i);
            if( map->PlayerList.size()<1 )
                only_npc = true;
            else
                only_npc = false;
                //continue;
            if(!only_npc)
            {
                // Player update //------------------------
                for(UINT j=0;j<map->PlayerList.size();j++)
                {
                    CPlayer* player = map->PlayerList.at(j);
                    if(!player->Session->inGame) continue;
                    if(player->IsDead( )) continue;
                    //if(player->UpdateValues( ))
                        player->UpdatePosition( );
                    if(player->IsOnBattle( ))
                        player->DoAttack( );
                    player->RefreshBuff( );
                    player->PlayerHeal( );
                    player->Regeneration( );
                    player->CheckPlayerLevelUP( );
                    if( GServer->Config.AUTOSAVE == 1 )
                    {
                        clock_t etime = clock() - player->lastSaveTime;
                        if( etime >= GServer->Config.SAVETIME*1000 )
                        {
                            player->savedata( );
                            player->lastSaveTime = clock();
                        }
                    }
                }
                // Monster update //------------------------
                pthread_mutex_lock( &map->MonsterMutex );
                for(UINT j=0;j<map->MonsterList.size();j++)
                {
                    CMonster* monster = map->MonsterList.at(j);
                    
                    UINT thistimer = monster->AItimer; 
    				if(monster->hitcount == 0xFF)//this is a delay for new monster spawns this might olso fix invisible monsters(if they attack directly on spawning the client dosn't get the attack packet(its not in it's visible list yet))
                    {
                        if(thistimer < (UINT)GServer->round((clock( ) - monster->lastAiUpdate)))
                        {
                            monster->hitcount = 0;
                            //monster->DoAi(monster->thisnpc->AI, 0);
                            monster->DoAi(monster->monAI, 0);
                            monster->lastAiUpdate=clock();
                        }
                    }
                    //still need this for special spawns
                    if(!map->IsNight( ) && monster->Status->nightonly)// if day, delete all night time monsters
                    {
                        //Log( MSG_INFO, "Night Only monster deleted. Type %i", monster->montype);
                        map->DeleteMonster( monster, true, j );
                        continue;
                    }
                    if(map->IsNight() && monster->Status->dayonly)
                    {
                        //Log( MSG_INFO, "Day Only monster deleted. Type %i", monster->montype);
                        map->DeleteMonster( monster, true, j );
                        continue;
                    }
    
                    if(!monster->PlayerInRange( )) continue;
                    if(!monster->UpdateValues( )) continue;
                        monster->UpdatePosition( );
                    if(monster->IsOnBattle( ))
                    {
                        //monster->DoAttack( );
                        if(thistimer<(UINT)GServer->round((clock( ) - monster->lastAiUpdate)))
                        {
                             //monster->DoAi(monster->thisnpc->AI, 2);
                             monster->DoAi(monster->monAI, 2);
                             monster->lastAiUpdate = clock();
                             //Log(MSG_INFO,"Monster type: %i current HP: %i",monster->montype, monster->Stats->HP);
                        }
                        else
                        {
                             //Log(MSG_INFO,"Monster doing attack");
                             monster->DoAttack( );
                        }
                    }
                    else if(!monster->IsOnBattle() && !monster->IsDead( ))
                    {
                        if(thistimer<(UINT)GServer->round((clock( ) - monster->lastAiUpdate)))
                        {
                            //monster->DoAi(monster->thisnpc->AI, 1);
                            monster->DoAi(monster->monAI, 1);
                            monster->lastAiUpdate = clock();
                        }
//.........这里部分代码省略.........
开发者ID:osROSE,项目名称:osprose,代码行数:101,代码来源:MainProcess.cpp


注:本文中的CMonster::DoAi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。