示例#1
0
int csr_start(int argc, char *argv[])
{

  int error;
  struct Parameter para;
  
  int N, NNZ;
  double *bvec, *xvec, *val;
  int *col, *ptr;
  double *Tval;
  int *Tcol, *Tptr;

  double *test;
  malloc_cuda_1d(10, test);
  free_cuda_1d(test);

  init_ver(&para);

  error = get_opt(argc, argv, &para);
  if(error_handle(error, (char*)"error in get_cmd")!=0)
    return -1;

  error = check_opt(&para);
  if(error_handle(error, (char*)"error in check_cmd")!=0)
    return -1;

  error = find_mat(&para);
  if(error_handle(error, (char*)"error in find_mat")!=0)
    return -1;

  show_opt(&para);

  error = set_openmp_thread(para.i_thread);
  if(error_handle(error, (char*)"error in set_openmp_thread")!=0)
    return -1;

  error = get_mat_head(&para, &N, &NNZ);
  if(error_handle(error, (char*)"error in get_mat_head")!=0)
    return -1;

  if( para.f_cuda == false )
  {
    bvec = malloc_1d(N);
    xvec = malloc_1d(N);

    val = malloc_1d(NNZ);
    col = malloc_1i(NNZ);
    ptr = malloc_1i(N+1);

    Tval=malloc_1d(NNZ);
    Tcol=malloc_1i(NNZ);
    Tptr=malloc_1i(N+1);
  }else{
    error_log((char*)"Cuda not done now");
    return -1;
  }


  error = get_mat_data(&para, col, ptr, val, bvec, xvec, N, NNZ);
  if(error_handle(error, (char*)"error in get_mat_data")!=0)
    return -1;

  //A^T
  Transpose_d(val, col, ptr, Tval, Tcol, Tptr, N, NNZ);

  error = outer_selecter(&para, bvec, xvec, val, col, ptr, Tval, Tcol, Tptr, N, NNZ);
  if(error_handle(error, (char*)"error in outer_selecter")!=0)
    return -1;

  show_opt(&para);

  if( para.f_cuda == false )
  {
    free_1d(bvec);
    free_1d(xvec);

    free_1d(val);
    free_1i(col);
    free_1i(ptr);

    free_1d(Tval);
    free_1i(Tcol);
    free_1i(Tptr);
  }else{
    error_log((char*)"Cuda not done now");
    return -1;
  }
  return 0;
}
// Initializes memory allocation framework once per process.
static void malloc_init_impl(libc_globals* globals) {
  const char* so_name = NULL;
  MallocDebugInit malloc_debug_initialize = NULL;
  unsigned int qemu_running = 0;
  unsigned int memcheck_enabled = 0;
  char env[PROP_VALUE_MAX];
  char memcheck_tracing[PROP_VALUE_MAX];
  char debug_program[PROP_VALUE_MAX];

  // Get custom malloc debug level. Note that emulator started with
  // memory checking option will have priority over debug level set in
  // libc.debug.malloc system property.
  if (__system_property_get("ro.kernel.qemu", env) && atoi(env)) {
    qemu_running = 1;
    if (__system_property_get("ro.kernel.memcheck", memcheck_tracing)) {
      if (memcheck_tracing[0] != '0') {
        // Emulator has started with memory tracing enabled. Enforce it.
        g_malloc_debug_level = 20;
        memcheck_enabled = 1;
      }
    }
  }

  // If debug level has not been set by memcheck option in the emulator,
  // lets grab it from libc.debug.malloc system property.
  if (g_malloc_debug_level == 0 && __system_property_get("libc.debug.malloc", env)) {
    g_malloc_debug_level = atoi(env);
  }

  // Debug level 0 means that we should use default allocation routines.
  if (g_malloc_debug_level == 0) {
    return;
  }

  // If libc.debug.malloc.program is set and is not a substring of progname,
  // then exit.
  if (__system_property_get("libc.debug.malloc.program", debug_program)) {
    if (!strstr(getprogname(), debug_program)) {
      return;
    }
  }

  // mksh is way too leaky. http://b/7291287.
  if (g_malloc_debug_level >= 10) {
    if (strcmp(getprogname(), "sh") == 0 || strcmp(getprogname(), "/system/bin/sh") == 0) {
      return;
    }
  }

  // Choose the appropriate .so for the requested debug level.
  switch (g_malloc_debug_level) {
    case 1:
    case 5:
    case 10:
      so_name = "libc_malloc_debug_leak.so";
      break;
    case 20:
      // Quick check: debug level 20 can only be handled in emulator.
      if (!qemu_running) {
        error_log("%s: Debug level %d can only be set in emulator\n",
                  getprogname(), g_malloc_debug_level);
        return;
      }
      // Make sure that memory checking has been enabled in emulator.
      if (!memcheck_enabled) {
        error_log("%s: Memory checking is not enabled in the emulator\n", getprogname());
        return;
      }
      so_name = "libc_malloc_debug_qemu.so";
      break;
    default:
      error_log("%s: Debug level %d is unknown\n", getprogname(), g_malloc_debug_level);
      return;
  }

  // Load .so that implements the required malloc debugging functionality.
  void* malloc_impl_handle = dlopen(so_name, RTLD_NOW);
  if (malloc_impl_handle == NULL) {
    error_log("%s: Missing module %s required for malloc debug level %d: %s",
              getprogname(), so_name, g_malloc_debug_level, dlerror());
    return;
  }

  // Initialize malloc debugging in the loaded module.
  malloc_debug_initialize = reinterpret_cast<MallocDebugInit>(dlsym(malloc_impl_handle,
                                                                    "malloc_debug_initialize"));
  if (malloc_debug_initialize == NULL) {
    error_log("%s: Initialization routine is not found in %s\n", getprogname(), so_name);
    dlclose(malloc_impl_handle);
    return;
  }
  if (!malloc_debug_initialize(&g_hash_table, &__libc_malloc_default_dispatch)) {
    dlclose(malloc_impl_handle);
    return;
  }

  if (g_malloc_debug_level == 20) {
    // For memory checker we need to do extra initialization.
    typedef int (*MemCheckInit)(int, const char*);
    MemCheckInit memcheck_initialize =
      reinterpret_cast<MemCheckInit>(dlsym(malloc_impl_handle, "memcheck_initialize"));
    if (memcheck_initialize == NULL) {
      error_log("%s: memcheck_initialize routine is not found in %s\n",
                getprogname(), so_name);
      dlclose(malloc_impl_handle);
      return;
    }

    if (memcheck_initialize(MALLOC_ALIGNMENT, memcheck_tracing)) {
      dlclose(malloc_impl_handle);
      return;
    }
  }

  // No need to init the dispatch table because we can only get
  // here if debug level is 1, 5, 10, or 20.
  MallocDebug malloc_dispatch_table;
  switch (g_malloc_debug_level) {
    case 1:
      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "leak");
      break;
    case 5:
      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "fill");
      break;
    case 10:
      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "chk");
      break;
    case 20:
      InitMalloc(malloc_impl_handle, &malloc_dispatch_table, "qemu_instrumented");
      break;
    default:
      break;
  }

  // Make sure dispatch table is initialized
  if ((malloc_dispatch_table.calloc == NULL) ||
      (malloc_dispatch_table.free == NULL) ||
      (malloc_dispatch_table.mallinfo == NULL) ||
      (malloc_dispatch_table.malloc == NULL) ||
      (malloc_dispatch_table.malloc_usable_size == NULL) ||
      (malloc_dispatch_table.memalign == NULL) ||
      (malloc_dispatch_table.posix_memalign == NULL) ||
#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
      (malloc_dispatch_table.pvalloc == NULL) ||
#endif
      (malloc_dispatch_table.realloc == NULL)
#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
      || (malloc_dispatch_table.valloc == NULL)
#endif
      ) {
    error_log("%s: some symbols for libc.debug.malloc level %d were not found (see above)",
              getprogname(), g_malloc_debug_level);
    dlclose(malloc_impl_handle);
  } else {
    globals->malloc_dispatch = malloc_dispatch_table;
    libc_malloc_impl_handle = malloc_impl_handle;
  }
}
示例#3
0
    void UpdateAI(const uint32 diff)
    {
        if (!UpdateVictim() || Phase < PHASE_NORMAL)
            return;

        if (IsWaiting)
        {
            if (WaitTimer <= diff)
            {
                IsWaiting = false;
                ChangeTimers(false, 0);
            } else WaitTimer -= diff;
        }

        for (uint8 t = 0; t < ActiveTimers; ++t)
        {
            if (Timer[t] <= diff && !TimerIsDeactivated[t])
            {
                switch(t)
                {
                    case TIMER_SPEECH:
                        if (SpeechBegins)
                        {
                            SpeechBegins=false;
                            switch(Phase)
                            {
                                case PHASE_NORMAL:
                                    speechPhaseEnd=1;
                                    break;
                                case PHASE_DARKNESS:
                                    speechPhaseEnd=4;
                                    break;
                                case PHASE_ARMAGEDDON:
                                    speechPhaseEnd=7;
                                    break;
                                case PHASE_SACRIFICE:
                                    speechPhaseEnd=12;
                                    break;
                            }
                        }
                        if (Speeches[speechCount].timer < SpeechTimer)
                        {
                            SpeechTimer = 0;
                            if (pInstance)
                                if (Creature* pSpeechCreature = Unit::GetCreature(*me, pInstance->GetData64(Speeches[speechCount].pCreature)))
                                    DoScriptText(Speeches[speechCount].textid, pSpeechCreature);
                            if (speechCount == 12)
                                if (Creature* pAnveena =  Unit::GetCreature(*me, pInstance->GetData64(DATA_ANVEENA)))
                                    pAnveena->CastSpell(me, SPELL_SACRIFICE_OF_ANVEENA, false);
                                    //   ChangeTimers(true, 10000); // Kil should do an emote while screaming without attacking for 10 seconds
                            if (speechCount == speechPhaseEnd)
                                TimerIsDeactivated[TIMER_SPEECH]=true;
                            speechCount++;
                        }
                        SpeechTimer += diff;
                        break;
                    case TIMER_SOUL_FLAY:
                        if (!me->IsNonMeleeSpellCasted(false))
                        {
                            DoCast(me->getVictim(), SPELL_SOUL_FLAY_SLOW, false);
                            DoCast(me->getVictim(), SPELL_SOUL_FLAY, false);
                            Timer[TIMER_SOUL_FLAY] = 3500;
                        }
                        break;
                    case TIMER_LEGION_LIGHTNING:
                        if (!me->IsNonMeleeSpellCasted(false))
                        {
                            Unit* pRandomPlayer = NULL;

                            me->RemoveAurasDueToSpell(SPELL_SOUL_FLAY);
                            for (uint8 z = 0; z < 6; ++z)
                            {
                                pRandomPlayer = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true);
                                if (!pRandomPlayer || !pRandomPlayer->HasAura(SPELL_VENGEANCE_OF_THE_BLUE_FLIGHT,0))
                                    break;
                            }

                            if (pRandomPlayer)
                                DoCast(pRandomPlayer, SPELL_LEGION_LIGHTNING, false);
                            else
                                error_log("try to cast SPELL_LEGION_LIGHTNING on invalid target");

                            Timer[TIMER_LEGION_LIGHTNING] = (Phase == PHASE_SACRIFICE) ? 18000 : 30000; // 18 seconds in PHASE_SACRIFICE
                            Timer[TIMER_SOUL_FLAY] = 2500;
                        }
                        break;
                    case TIMER_FIRE_BLOOM:
                        if (!me->IsNonMeleeSpellCasted(false))
                        {
                            me->RemoveAurasDueToSpell(SPELL_SOUL_FLAY);
                            DoCastAOE(SPELL_FIRE_BLOOM, false);
                            Timer[TIMER_FIRE_BLOOM] = (Phase == PHASE_SACRIFICE) ? 25000 : 40000; // 25 seconds in PHASE_SACRIFICE
                            Timer[TIMER_SOUL_FLAY] = 1000;
                        }
                        break;
                    case TIMER_SUMMON_SHILEDORB:
                        for (uint8 i = 1; i < Phase; ++i)
                        {
                            float sx, sy;
                            sx = ShieldOrbLocations[0][0] + sin(ShieldOrbLocations[i][0]);
                            sy = ShieldOrbLocations[0][1] + sin(ShieldOrbLocations[i][1]);
                            me->SummonCreature(CREATURE_SHIELD_ORB, sx, sy, SHIELD_ORB_Z, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 45000);
                        }
                        Timer[TIMER_SUMMON_SHILEDORB] = urand(30000,60000); // 30-60seconds cooldown
                        Timer[TIMER_SOUL_FLAY] = 2000;
                        break;
                    case TIMER_SHADOW_SPIKE: //Phase 3
                        if (!me->IsNonMeleeSpellCasted(false))
                        {
                            CastSinisterReflection();
                            DoCastAOE(SPELL_SHADOW_SPIKE, false);
                            ChangeTimers(true, 30000);
                            Timer[TIMER_SHADOW_SPIKE] = 0;
                            TimerIsDeactivated[TIMER_SPEECH] = false;
                        }
                        break;
                    case TIMER_FLAME_DART: //Phase 3
                        DoCastAOE(SPELL_FLAME_DART, false);
                        Timer[TIMER_FLAME_DART] = 3000; //TODO Timer
                        break;
                    case TIMER_DARKNESS: //Phase 3
                        if (!me->IsNonMeleeSpellCasted(false))
                        {
                            // Begins to channel for 8 seconds, then deals 50'000 damage to all raid members.
                            if (!IsInDarkness)
                            {
                                DoScriptText(EMOTE_KJ_DARKNESS, me);
                                DoCastAOE(SPELL_DARKNESS_OF_A_THOUSAND_SOULS, false);
                                ChangeTimers(true, 9000);
                                Timer[TIMER_DARKNESS] = 8750;
                                TimerIsDeactivated[TIMER_DARKNESS] = false;
                                if (Phase == PHASE_SACRIFICE)
                                    TimerIsDeactivated[TIMER_ARMAGEDDON] = false;
                                IsInDarkness = true;
                            }
                            else
                            {
                                Timer[TIMER_DARKNESS] = (Phase == PHASE_SACRIFICE) ? 15000 : urand(40000,70000);
                                IsInDarkness = false;
                                DoCastAOE(SPELL_DARKNESS_OF_A_THOUSAND_SOULS_DAMAGE);
                                DoScriptText(RAND(SAY_KJ_DARKNESS1,SAY_KJ_DARKNESS2,SAY_KJ_DARKNESS3), me);
                            }
                            Timer[TIMER_SOUL_FLAY] = 9000;
                        }
                        break;
                    case TIMER_ORBS_EMPOWER: //Phase 3
                        if (pInstance)
                            if (Creature* pKalec = Unit::GetCreature(*me, pInstance->GetData64(DATA_KALECGOS_KJ)))
                            {
                                switch (Phase)
                                {
                                   case PHASE_SACRIFICE:
                                        CAST_AI(boss_kalecgos_kjAI, pKalec->AI())->EmpowerOrb(true);
                                        break;
                                    default:
                                        CAST_AI(boss_kalecgos_kjAI, pKalec->AI())->EmpowerOrb(false);
                                        break;
                                }
                            }
                        OrbActivated = true;
                        TimerIsDeactivated[TIMER_ORBS_EMPOWER] = true;
                        break;
                    case TIMER_ARMAGEDDON: //Phase 4
                        Unit *pTarget = NULL;
                        for (uint8 z = 0; z < 6; ++z)
                        {
                            pTarget = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true);
                            if (!pTarget || !pTarget->HasAura(SPELL_VENGEANCE_OF_THE_BLUE_FLIGHT,0)) break;
                        }
                        if (pTarget)
                        {
                            float x, y, z;
                            pTarget->GetPosition(x, y, z);
                            me->SummonCreature(CREATURE_ARMAGEDDON_TARGET, x,y,z,0, TEMPSUMMON_TIMED_DESPAWN,15000);
                        }
                        Timer[TIMER_ARMAGEDDON] = 2000; // No, I'm not kidding
                        break;
                 }
            }
        }
        DoMeleeAttackIfReady();
        //Time runs over!
        for (uint8 i = 0; i < ActiveTimers; ++i)
            if (!TimerIsDeactivated[i])
            {
                Timer[i] -= diff;
                if (((int32)Timer[i]) < 0) Timer[i] = 0;
            }

        //Phase 3
        if (Phase <= PHASE_NORMAL && !IsInDarkness)
        {
            if (Phase == PHASE_NORMAL && HealthBelowPct(85))
            {
                Phase = PHASE_DARKNESS;
                ActiveTimers = 9;
                EnterNextPhase();
            }
            else return;
        }

        //Phase 4
        if (Phase <= PHASE_DARKNESS && !IsInDarkness)
        {
            if (Phase == PHASE_DARKNESS && HealthBelowPct(55))
            {
                Phase = PHASE_ARMAGEDDON;
                ActiveTimers = 10;
                EnterNextPhase();
            }
            else return;
        }

        //Phase 5 specific spells all we can
        if (Phase <= PHASE_ARMAGEDDON && !IsInDarkness)
        {
            if (Phase == PHASE_ARMAGEDDON && HealthBelowPct(25))
            {
                Phase = PHASE_SACRIFICE;
                EnterNextPhase();
            }
            else return;
        }
    }
示例#4
0
void ProcessMenu_TeleportMaster(Player *player, Creature *Creature, uint32 action, uint32 MoreLess, uint32 GroupID){
	if(DEBUG_TELE) error_log("TeleportMaster: Running ProcessMenu - Action: \"%i\" MoreLess: \"%i\" GroupID: \"%i\"",action,MoreLess,GroupID);
	
	//Initialize
	int32 ItemCount = 0;
	int32 locations = 0;
	int32 throttle  = 0;
	QueryResult* pResult;
	if(action==100000) action=0;
	if(action<=1000) throttle = 1000;
	if(action<=100)  throttle = 100;
	if(GroupID>0)    throttle = 1000;

	// Query the DB 
	if( action<=1000 ){
		pResult = SD2Database.PQuery("SELECT CategoryID,CategoryName,SubCatGroupID,SubCatName FROM teleportmaster_categories WHERE CategoryID >= \"%i\" AND CategoryID <= \"%i\" ORDER BY CategoryID", action, throttle);	
		//Not a SubCat, list out locations
		if( pResult->Fetch()[2].GetInt32()==0 && (action>100 || (action<=100 && action>0 && MoreLess==0)) ){
			pResult = SD2Database.PQuery("SELECT ID,CategoryID,Name,faction,ReqLevel,GuildID,Cost FROM teleportmaster_locations WHERE CategoryID = \"%i\" ORDER BY ID", action);
			locations = 1;
		}
		else if(action<=1000 && action>1){
			if(MoreLess>0 || action<=100){
				if(action<=100){
					pResult = SD2Database.PQuery("SELECT CategoryID,CategoryName,SubCatGroupID,SubCatName FROM teleportmaster_categories WHERE CategoryID >= \"%i\" AND CategoryID <= \"%i\" ORDER BY CategoryID", action, throttle);	
				}
				else{
					QueryResult* pResultGroup = SD2Database.PQuery("SELECT CategoryID,CategoryName,SubCatGroupID,SubCatName FROM teleportmaster_categories WHERE CategoryID = \"%i\"", action);	
					if(pResultGroup){
						GroupID = pResultGroup->Fetch()[2].GetInt32();
						pResult = SD2Database.PQuery("SELECT CategoryID,CategoryName,SubCatGroupID,SubCatName FROM teleportmaster_categories WHERE CategoryID >= \"%i\" AND SubCatGroupID = \"%i\" ORDER BY CategoryID", action, GroupID);	
					}
				}
			}
			else{
				//List what is INSIDE this sub-group
				pResult = SD2Database.PQuery("SELECT ID,CategoryID,Name,faction,ReqLevel,GuildID,Cost FROM teleportmaster_locations WHERE CategoryID = \"%i\" ORDER BY ID", action);
				locations = 1;
			}
		}
	}
	if(action>1000){
		if(MoreLess>0){
			QueryResult* pResultGroup = SD2Database.PQuery("SELECT ID,CategoryID FROM teleportmaster_locations WHERE ID = \"%i\"", action);
			if(pResultGroup){
				GroupID = pResultGroup->Fetch()[1].GetInt32();
				pResult = SD2Database.PQuery("SELECT ID,CategoryID,Name,faction,ReqLevel,GuildID,Cost FROM teleportmaster_locations WHERE CategoryID = \"%i\" AND ID>= \"%i\" ORDER BY ID", GroupID, action);
				locations = 1;
			}
		}
		else{
			ProcessTeleport_TeleportMaster( player, Creature, action);
			return;
		}
	}
	
	// Make sure the result is valid, add menu items
	if(pResult){
		if(DEBUG_TELE) error_log("TeleportMaster: ProcessMenu queried the DB and got results, processing results...");
		do{
			Field* pFields = pResult->Fetch();
			if(ItemCount==10){
				//Count is 10! We need a 'more' button!
				if(DEBUG_TELE) error_log("TeleportMaster: 10 Items on menu, adding 'more' button: \"%i\"", pFields[0].GetInt32() + 200000);
				player->ADD_GOSSIP_ITEM( 4, "More ->", GOSSIP_SENDER_MAIN,  pFields[0].GetInt32() + 200000);
				ItemCount++;
			}
			else{
				std::stringstream CatName;
				//MainCat Items
				if(action<101 && !locations && GroupID==0){
						CatName<<pFields[1].GetCppString()<<" ->";
						player->ADD_GOSSIP_ITEM( 5, CatName.str().c_str(), GOSSIP_SENDER_MAIN, pFields[0].GetInt32());
						ItemCount++;
				}
				//SubCat Items
				if(action<1001 && GroupID>0 && pFields[0].GetInt32()>100 && pFields[2].GetInt32()==GroupID && !locations){
						CatName<<pFields[3].GetCppString()<<" ->";
						player->ADD_GOSSIP_ITEM( 5, CatName.str().c_str(), GOSSIP_SENDER_MAIN, pFields[0].GetInt32());
						ItemCount++;
				}
				//Locations or Root SubCats
				if(locations){
					if(GroupID==0 || action>1000 || (action<=1000 && MoreLess==0) ){
						if( (pFields[3].GetInt32()==2 && player->GetTeam()==ALLIANCE) || (pFields[3].GetInt32()==1 && player->GetTeam()==HORDE) || (player->getLevel()<pFields[4].GetUInt32()) || (pFields[5].GetInt32()>0 && player->GetGuildId() != pFields[5].GetInt32()) ){
								//FAIL!!  Do nothing...
						}
						else{
							std::stringstream menuItem;
							menuItem << pFields[2].GetCppString() << " - " << CopperToGold(pFields[6].GetInt32());
							player->ADD_GOSSIP_ITEM( 2, menuItem.str().c_str(), GOSSIP_SENDER_MAIN, pFields[0].GetInt32());
							ItemCount++;
						}
					}
					else{
						CatName<<pFields[1].GetCppString()<<" ->";
						player->ADD_GOSSIP_ITEM( 5, CatName.str().c_str(), GOSSIP_SENDER_MAIN, pFields[0].GetInt32());
						ItemCount++;
					}
				}
			}
		}while(pResult->NextRow() && ItemCount<11);
	}
	
	//scan teleportmaster_locations for locations matching this groupID and add them if ItemCount<10
	if( GroupID>0 && !locations && ItemCount<10 ){
		pResult = SD2Database.PQuery("SELECT ID,CategoryID,faction,ReqLevel,GuildID,Name,cost FROM teleportmaster_locations WHERE CategoryID = \"%i\" ORDER BY ID",action); 
		if(pResult){
			if(DEBUG_TELE) error_log("TeleportMaster: Adding additional locations to a SubCat");
			do{
				Field* pFields = pResult->Fetch();
				if(ItemCount==10){
					//Count is 10! We need a 'more' button!
					if(DEBUG_TELE) error_log("TeleportMaster: 10 Items on menu, adding 'more' button: \"%i\"", pFields[0].GetInt32() + 200000);
					player->ADD_GOSSIP_ITEM( 4, "More ->", GOSSIP_SENDER_MAIN,  pFields[0].GetInt32() + 200000);
					ItemCount++;
				}
				if( (pFields[2].GetInt32()==2 && player->GetTeam()==ALLIANCE) || (pFields[2].GetInt32()==1 && player->GetTeam()==HORDE) || (player->getLevel()<pFields[3].GetUInt32()) || (pFields[4].GetInt32()>0 && player->GetGuildId() != pFields[4].GetInt32()) ){
					//FAIL!!  Do nothing...
				}
				else{
					std::stringstream menuItem;
					menuItem << pFields[5].GetCppString() << " - " << CopperToGold(pFields[6].GetInt32());
					player->ADD_GOSSIP_ITEM( 2, menuItem.str().c_str(), GOSSIP_SENDER_MAIN, pFields[0].GetInt32());
					ItemCount++;
				}
			}while(pResult->NextRow() && ItemCount<11);
		}
	}
		
	//Add 'Prev' and 'Main Menu' buttons as needed
	if(DEBUG_TELE) error_log("TeleportMaster: Adding 'Prev' and 'Main Menu' buttons for action: \"%i\" GroupId:\"%i\"",action,GroupID);
	if(MoreLess>0 || locations){
		if(action<2){
			if(MoreLess==0)
				player->ADD_GOSSIP_ITEM( 4, "<- Main Menu", GOSSIP_SENDER_MAIN,  100000 );
		}
		else{
			int32 prevAction=0;
			QueryResult* pResultPrev;
			if(action>=1000)
				pResultPrev = SD2Database.PQuery("SELECT ID,CategoryID,faction,ReqLevel,GuildID FROM teleportmaster_locations WHERE CategoryID = \"%i\" AND ID <= \"%i\" ORDER BY ID DESC",GroupID,action);	
			if(action>=100 && action<1000)
				pResultPrev = SD2Database.PQuery("SELECT CategoryID,SubCatGroupID FROM teleportmaster_categories WHERE SubCatGroupID = \"%i\" AND CategoryID <= \"%i\" ORDER BY CategoryID DESC",GroupID,action);
			if(action>1 && action<100)
				pResultPrev = SD2Database.PQuery("SELECT CategoryID,SubCatGroupID FROM teleportmaster_categories WHERE CategoryID <= \"%i\" ORDER BY CategoryID DESC",action);
			
			// Make sure the result is valid
			if(pResultPrev){
				int32 count=0;
				//Count backwards starting at our last item and only count valid locations
				do{
					Field* pFields = pResultPrev->Fetch();
					if(action>1000){
						if( (pFields[2].GetInt32()==2 && player->GetTeam()==ALLIANCE) || (pFields[2].GetInt32()==1 && player->GetTeam()==HORDE) || (player->getLevel()<pFields[3].GetUInt32()) || (pFields[4].GetInt32()>0 && player->GetGuildId() != pFields[4].GetInt32()) ){
							//FAIL!!  Do nothing...
						}
						else{
							count++;
						}
					}
					else{
						count++;
					}
					if(count==11)
						prevAction = pFields[0].GetInt32();
				}while(pResultPrev->NextRow());
				
			}
			if(prevAction>0){
				player->ADD_GOSSIP_ITEM( 4, "<- Prev", GOSSIP_SENDER_MAIN, prevAction + 400000 );
				if(DEBUG_TELE) error_log("TeleportMaster: Prev1: \"%i\"", prevAction + 400000);
			}
			player->ADD_GOSSIP_ITEM( 4, "<- Main Menu", GOSSIP_SENDER_MAIN,  100000 );
		}
	}
	else if(action<=1000 && action>0 && MoreLess==0){
		if( GroupID==0 || (action<100 && GroupID>0) )
			player->ADD_GOSSIP_ITEM( 4, "<- Main Menu", GOSSIP_SENDER_MAIN,  100000 );
	}
	player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE,Creature->GetGUID());
	return;
}
示例#5
0
    void UpdateAI(const uint32 diff)
    {
        //Phase 1
        switch (Phase)
        {
        case 1:
            {
                Unit* pTarget = NULL;
                Creature* Advisor = NULL;

                //Subphase switch
                switch (PhaseSubphase)
                {
                //Subphase 1 - Start
                case 0:
                    if (Phase_Timer <= diff)
                    {
                        DoScriptText(SAY_INTRO_THALADRED, me);

                        //start advisor within 7 seconds
                        Phase_Timer = 7000;

                        PhaseSubphase++;
                    }
                    else Phase_Timer -= diff;
                    break;

                //Subphase 1 - Unlock advisor
                case 1:
                    if (Phase_Timer <= diff)
                    {
                        Advisor = (Creature*)(Unit::GetUnit((*me), m_auiAdvisorGuid[0]));

                        if (Advisor)
                        {
                            Advisor->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
                            Advisor->setFaction(me->getFaction());

                            pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0);
                            if (pTarget)
                                Advisor->AI()->AttackStart(pTarget);
                        }

                        PhaseSubphase++;
                    }
                    else Phase_Timer -= diff;
                    break;

                //Subphase 2 - Start
                case 2:
                    Advisor = (Creature*)(Unit::GetUnit((*me), m_auiAdvisorGuid[0]));

                    if (Advisor && (Advisor->getStandState() == UNIT_STAND_STATE_DEAD))
                    {
                        DoScriptText(SAY_INTRO_SANGUINAR, me);

                        //start advisor within 12.5 seconds
                        Phase_Timer = 12500;

                        PhaseSubphase++;
                    }
                    break;

                //Subphase 2 - Unlock advisor
                case 3:
                    if (Phase_Timer <= diff)
                    {
                        Advisor = (Creature*)(Unit::GetUnit((*me), m_auiAdvisorGuid[1]));

                        if (Advisor)
                        {
                            Advisor->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
                            Advisor->setFaction(me->getFaction());

                            pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0);
                            if (pTarget)
                                Advisor->AI()->AttackStart(pTarget);
                        }

                        PhaseSubphase++;
                    }
                    else Phase_Timer -= diff;
                    break;

                //Subphase 3 - Start
                case 4:
                    Advisor = (Creature*)(Unit::GetUnit((*me), m_auiAdvisorGuid[1]));

                    if (Advisor && (Advisor->getStandState() == UNIT_STAND_STATE_DEAD))
                    {
                        DoScriptText(SAY_INTRO_CAPERNIAN, me);

                        //start advisor within 7 seconds
                        Phase_Timer = 7000;

                        PhaseSubphase++;
                    }
                    break;

                //Subphase 3 - Unlock advisor
                case 5:
                    if (Phase_Timer <= diff)
                    {
                        Advisor = (Creature*)(Unit::GetUnit((*me), m_auiAdvisorGuid[2]));

                        if (Advisor)
                        {
                            Advisor->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
                            Advisor->setFaction(me->getFaction());

                            pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0);
                            if (pTarget)
                                Advisor->AI()->AttackStart(pTarget);
                        }

                        PhaseSubphase++;
                    }
                    else Phase_Timer -= diff;
                    break;

                //Subphase 4 - Start
                case 6:
                    Advisor = (Creature*)(Unit::GetUnit((*me), m_auiAdvisorGuid[2]));

                    if (Advisor && (Advisor->getStandState() == UNIT_STAND_STATE_DEAD))
                    {
                        DoScriptText(SAY_INTRO_TELONICUS, me);

                        //start advisor within 8.4 seconds
                        Phase_Timer = 8400;

                        PhaseSubphase++;
                    }
                    break;

                //Subphase 4 - Unlock advisor
                case 7:
                    if (Phase_Timer <= diff)
                    {
                        Advisor = (Creature*)(Unit::GetUnit((*me), m_auiAdvisorGuid[3]));

                        if (Advisor)
                        {
                            Advisor->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
                            Advisor->setFaction(me->getFaction());

                            pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0);
                            if (pTarget)
                                Advisor->AI()->AttackStart(pTarget);
                        }

                        Phase_Timer = 3000;

                        PhaseSubphase++;
                    }
                    else Phase_Timer -= diff;
                    break;

                //End of phase 1
                case 8:
                    Advisor = (Creature*)(Unit::GetUnit((*me), m_auiAdvisorGuid[3]));

                    if (Advisor && (Advisor->getStandState() == UNIT_STAND_STATE_DEAD))
                    {
                        Phase = 2;
                        m_pInstance->SetData(DATA_KAELTHASEVENT, 2);

                        DoScriptText(SAY_PHASE2_WEAPON, me);
                        PhaseSubphase = 0;
                        Phase_Timer = 3500;
                        DoCast(me, SPELL_SUMMON_WEAPONS);
                    }
                    break;
                }
            }
            break;

        case 2:
            {
                if (PhaseSubphase == 0)
                {
                    if (Phase_Timer <= diff)
                        PhaseSubphase = 1;
                    else Phase_Timer -= diff;
                }

                //Spawn weapons
                if (PhaseSubphase == 1)
                {
                    me->CastSpell(me, SPELL_SUMMON_WEAPONS, false);

                    uint8 uiMaxWeapon = sizeof(m_auiSpellSummonWeapon) / sizeof(uint32);

                    for (uint32 i = 0; i < uiMaxWeapon; ++i)
                        me->CastSpell(me, m_auiSpellSummonWeapon[i], true);

                    PhaseSubphase = 2;
                    Phase_Timer = TIME_PHASE_2_3;
                }

                if (PhaseSubphase == 2)
                {
                    if (Phase_Timer < diff)
                    {
                        DoScriptText(SAY_PHASE3_ADVANCE, me);
                        m_pInstance->SetData(DATA_KAELTHASEVENT, 3);
                        Phase = 3;
                        PhaseSubphase = 0;
                    }
                    else Phase_Timer -= diff;
                }
            }
            break;

        case 3:
            {
                if (PhaseSubphase == 0)
                {
                    //Respawn advisors
                    Unit* pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0);

                    Creature* Advisor;
                    for (uint32 i = 0; i < MAX_ADVISORS; i++)
                    {
                        Advisor = (Creature*)(Unit::GetUnit((*me), m_auiAdvisorGuid[i]));
                        if (!Advisor)
                            error_log("OSCR: Kael'Thas Advisor %u does not exist. Possibly despawned? Incorrectly Killed?", i);
                        else if (pTarget)
                            ((advisorbase_ai*)Advisor->AI())->Revive(pTarget);
                    }

                    PhaseSubphase = 1;
                    Phase_Timer = TIME_PHASE_3_4;
                }

                if (Phase_Timer <= diff)
                {
                    DoScriptText(SAY_PHASE4_INTRO2, me);
                    Phase = 4;

                    m_pInstance->SetData(DATA_KAELTHASEVENT, 4);

                    // Sometimes people can collect Aggro in Phase 1-3. Reset threat before releasing Kael.
                    DoResetThreat();

                    me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
                    me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);

                    if (Unit* pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0))
                        AttackStart(pTarget);

                    Phase_Timer = 30000;
                }
                else Phase_Timer -= diff;
            }
            break;

        case 4:
        case 5:
        case 6:
            {
                //Return since we have no target
                if (!UpdateVictim())
                    return;

                //Fireball_Timer
                if (!InGravityLapse && !ChainPyros && Phase != 5)
                {
                    if (Fireball_Timer <= diff)
                    {
                        if (!IsCastingFireball)
                        {
                            if (!me->IsNonMeleeSpellCast(false))
                            {
                                //interruptable
                                me->ApplySpellImmune(0, IMMUNITY_EFFECT, SPELL_EFFECT_INTERRUPT_CAST, false);
                                int32 dmg = 20000 + rand() % 5000;
                                me->CastCustomSpell(me->getVictim(), SPELL_FIREBALL, &dmg, 0, 0, false);
                                IsCastingFireball = true;
                                Fireball_Timer = 2500;
                            }
                        }
                        else
                        {
                            //apply resistance
                            me->ApplySpellImmune(0, IMMUNITY_EFFECT, SPELL_EFFECT_INTERRUPT_CAST, true);
                            IsCastingFireball = false;
                            Fireball_Timer = 5000 + rand() % 10000;
                        }
                    }
                    else Fireball_Timer -= diff;

                    //ArcaneDisruption_Timer
                    if (ArcaneDisruption_Timer <= diff)
                    {
                        DoCastVictim( SPELL_ARCANE_DISRUPTION, true);

                        ArcaneDisruption_Timer = 60000;
                    }
                    else ArcaneDisruption_Timer -= diff;

                    if (FlameStrike_Timer <= diff)
                    {
                        if (Unit* pUnit = SelectUnit(SELECT_TARGET_RANDOM, 0))
                            DoCast(pUnit, SPELL_FLAME_STRIKE);

                        FlameStrike_Timer = 30000;
                    }
                    FlameStrike_Timer -= diff;

                    if (MindControl_Timer <= diff)
                    {
                        if (me->getThreatManager().getThreatList().size() >= 2)
                            for (uint32 i = 0; i < 3; i++)
                            {
                                debug_log("OSCR: Kael'Thas mind control not supported.");
                                //DoCast(pTarget, SPELL_MIND_CONTROL);
                            }

                        MindControl_Timer = 60000;
                    }
                    MindControl_Timer -= diff;
                }

                //Phoenix_Timer
                if (Phoenix_Timer <= diff)
                {
                    DoCast(me, SPELL_PHOENIX_ANIMATION);

                    if (Creature* pPhoenix = me->SummonCreature(NPC_PHOENIX, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 45000))
                    {
                        if (Unit* pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0))
                            pPhoenix->AI()->AttackStart(pTarget);
                    }
                    else
                        error_log("OSCR: Kael'Thas Phoenix could not be spawned");

                    switch (rand() % 2)
                    {
                    case 0:
                        DoScriptText(SAY_SUMMON_PHOENIX1, me);
                        break;
                    case 1:
                        DoScriptText(SAY_SUMMON_PHOENIX2, me);
                        break;
                    }

                    Phoenix_Timer = 60000;
                }
                else Phoenix_Timer -= diff;

                //Phase 4 specific spells
                if (Phase == 4)
                {
                    if (me->GetHealth() * 100 / me->GetMaxHealth() < 50)
                    {
                        m_pInstance->SetData(DATA_KAELTHASEVENT, 4);
                        Phase = 5;
                        Phase_Timer = 10000;

                        DoScriptText(SAY_PHASE5_NUTS, me);

                        me->StopMoving();
                        me->GetMotionMaster()->Clear();
                        me->GetMotionMaster()->MoveIdle();
                        me->Relocate(afGravityPos[0], afGravityPos[1], afGravityPos[2], 0);
                        Movement::MoveSplineInit init(*me);
                        init.MoveTo(afGravityPos[0], afGravityPos[1], afGravityPos[2], true);
                        init.Launch();

                        me->InterruptNonMeleeSpells(false);
                        DoCast(me, SPELL_FULLPOWER);
                        me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
                    }

                    //ShockBarrier_Timer
                    if (ShockBarrier_Timer <= diff)
                    {
                        DoCast(me, SPELL_SHOCK_BARRIER);
                        ChainPyros = true;
                        PyrosCasted = 0;

                        ShockBarrier_Timer = 60000;
                    }
                    else ShockBarrier_Timer -= diff;

                    //Chain Pyros (3 of them max)
                    if (ChainPyros && !me->IsNonMeleeSpellCast(false))
                    {
                        if (PyrosCasted < 3)
                        {
                            DoCastVictim( SPELL_PYROBLAST);
                            PyrosCasted++;
                        }
                        else
                        {
                            ChainPyros = false;
                            Fireball_Timer = 2500;
                            ArcaneDisruption_Timer = 60000;
                        }
                    }
                }

                if (Phase == 5)
                {
                    if (Phase_Timer <= diff)
                    {
                        me->InterruptNonMeleeSpells(false);
                        me->RemoveAurasDueToSpell(SPELL_FULLPOWER);
                        DoCast(me, SPELL_EXPLODE);
                        me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
                        Phase = 6;
                        AttackStart(me->getVictim());
                    }
                    else Phase_Timer -= diff;
                }

                //Phase 5
                if (Phase == 6)
                {

                    //GravityLapse_Timer
                    if (GravityLapse_Timer <= diff)
                    {
                        ThreatContainer::StorageType threatlist = me->getThreatManager().getThreatList();
                        ThreatContainer::StorageType::const_iterator i = threatlist.begin();

                        Movement::MoveSplineInit init(*me);
                        switch (GravityLapse_Phase)
                        {
                        case 0:
                            me->StopMoving();
                            me->GetMotionMaster()->Clear();
                            me->GetMotionMaster()->MoveIdle();
                            me->Relocate(afGravityPos[0], afGravityPos[1], afGravityPos[2], 0);
                            init.MoveTo(afGravityPos[0], afGravityPos[1], afGravityPos[2], true);
                            init.Launch();

                            // 1) Kael'thas will portal the whole raid right into his body
                            for (i = threatlist.begin(); i != threatlist.end(); ++i)
                            {
                                Unit* pUnit = Unit::GetUnit((*me), (*i)->getUnitGuid());
                                if (pUnit && (pUnit->GetTypeId() == TYPEID_PLAYER))
                                {
                                    //Use work around packet to prevent player from being dropped from combat
                                    DoTeleportPlayer(pUnit, afGravityPos[0], afGravityPos[1], afGravityPos[2], pUnit->GetOrientation());
                                }
                            }
                            GravityLapse_Timer = 500;
                            ++GravityLapse_Phase;
                            InGravityLapse = true;
                            ShockBarrier_Timer = 1000;
                            NetherBeam_Timer = 5000;
                            break;

                        case 1:
                            switch (rand() % 2)
                            {
                            case 0:
                                DoScriptText(SAY_GRAVITYLAPSE1, me);
                                break;
                            case 1:
                                DoScriptText(SAY_GRAVITYLAPSE2, me);
                                break;
                            }

                            // 2) At that point he will put a Gravity Lapse debuff on everyone
                            for (i = threatlist.begin(); i != threatlist.end(); ++i)
                            {
                                if (Unit* pUnit = Unit::GetUnit((*me), (*i)->getUnitGuid()))
                                {
                                    me->CastSpell(pUnit, SPELL_KNOCKBACK, true);
                                    //Gravity lapse - needs an exception in Spell system to work

                                    pUnit->CastSpell(pUnit, SPELL_GRAVITY_LAPSE, true, 0, 0, me->GetGUID());
                                    pUnit->CastSpell(pUnit, SPELL_GRAVITY_LAPSE_AURA, true, 0, 0, me->GetGUID());

                                    //Using packet workaround
                                    WorldPacket data(12);
                                    data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
                                    data << pUnit->GetPackGUID();
                                    data << uint32(0);
                                    pUnit->SendMessageToSet(&data, true);
                                }
                            }
                            GravityLapse_Timer = 10000;
                            GravityLapse_Phase++;
                            break;

                        case 2:
                            //Cast nether vapor aura on self
                            me->InterruptNonMeleeSpells(false);
                            DoCast(me, SPELL_NETHER_VAPOR);

                            GravityLapse_Timer = 20000;
                            GravityLapse_Phase++;
                            break;

                        case 3:
                            //Remove flight
                            for (i = threatlist.begin(); i != threatlist.end(); ++i)
                            {
                                if (Unit* pUnit = Unit::GetUnit((*me), (*i)->getUnitGuid()))
                                {
                                    //Using packet workaround
                                    WorldPacket data(12);
                                    data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
                                    data << pUnit->GetPackGUID();
                                    data << uint32(0);
                                    pUnit->SendMessageToSet(&data, true);
                                }
                            }
                            me->RemoveAurasDueToSpell(SPELL_NETHER_VAPOR);
                            InGravityLapse = false;
                            GravityLapse_Timer = 60000;
                            GravityLapse_Phase = 0;
                            AttackStart(me->getVictim());
                            break;
                        }
                    }
                    else GravityLapse_Timer -= diff;

                    if (InGravityLapse)
                    {
                        //ShockBarrier_Timer
                        if (ShockBarrier_Timer <= diff)
                        {
                            DoCast(me, SPELL_SHOCK_BARRIER);
                            ShockBarrier_Timer = 20000;
                        }
                        else ShockBarrier_Timer -= diff;

                        //NetherBeam_Timer
                        if (NetherBeam_Timer <= diff)
                        {
                            if (Unit* pUnit = SelectUnit(SELECT_TARGET_RANDOM, 0))
                                DoCast(pUnit, SPELL_NETHER_BEAM);

                            NetherBeam_Timer = 4000;
                        }
                        else NetherBeam_Timer -= diff;
                    }
                }

                if (!InGravityLapse)
                    DoMeleeAttackIfReady();
            }
        }
    }
示例#6
0
/* ==================== start_listen() ==================== */ 
int start_listen(int listen_port, const char *data_dir)
{
    int r;

    /* -------- server_addr -------- */
    struct sockaddr_in server_addr;
    r = uv_ip4_addr("0.0.0.0", listen_port, &server_addr);
    if ( r ) {
        error_log("uv_ip4_addr() failed.");
        return -1;
    }

    /* -------- server-------- */
    server_t *server = server_new();

    if ( server_init(server) != 0 ){
        error_log("server_init() failed.");
        return -1;
    }

    /* -------- loop -------- */
    uv_loop_t *loop = &server->connection.loop;

    /* -------- tcp_handle -------- */
    uv_tcp_t *tcp_handle = &server->connection.handle.tcp;

    /* -------- uv_tcp_init -------- */
    r = uv_tcp_init(loop, tcp_handle);
    if ( r ) {
        error_log("uv_tcp_init() failed.");
        server_free(server);
        return -1;
    }
    tcp_handle->data = server;

    /* -------- uv_tcp_bind -------- */
    r = uv_tcp_bind(tcp_handle, (const struct sockaddr*)&server_addr, 0);
    if ( r ) {
        error_log("uv_tcp_bind() failed.");
        server_free(server);
        return -1;
    }

    /* -------- uv_listen -------- */
    r = uv_listen((uv_stream_t*)tcp_handle, SOMAXCONN, on_connection);
    if ( r ) {
        error_log("uv_listen() failed.");
        server_free(server);
        return -1;
    }

    info_log("Listen on port %d.", listen_port);

    /* -------- uv_run -------- */
    r = uv_run(loop, UV_RUN_DEFAULT);
    if ( r ) {
        error_log("uv_run() failed.");
        server_free(server);
        return -1;
    }

    /* FIXME */
    /*MAKE_VALGRIND_HAPPY(loop);*/

    /*close_loop(loop);      */
    /*uv_loop_delete(loop);  */

    server_free(server);

    notice_log("Server exit.");

    return 0;
}
示例#7
0
void npc_unworthy_initiateAI::UpdateAI(const uint32 diff)
{
    switch(phase)
    {
    case PHASE_CHAINED:
        if (!anchorGUID)
        {
            if (Creature *anchor = me->FindNearestCreature(29521, 30))
            {
                anchor->AI()->SetGUID(me->GetGUID());
                anchor->CastSpell(me, SPELL_SOUL_PRISON_CHAIN, true);
                anchorGUID = anchor->GetGUID();
            }
            else
                error_log("npc_unworthy_initiateAI: unable to find anchor!");

            float dist = 99.0f;
            GameObject *prison = NULL;

            for (uint8 i = 0; i < 12; ++i)
            {
                if (GameObject* temp_prison = me->FindNearestGameObject(acherus_soul_prison[i],30))
                {
                    if (me->IsWithinDist(temp_prison, dist, false))
                    {
                        dist = me->GetDistance2d(temp_prison);
                        prison = temp_prison;
                    }
                }
            }

            if (prison)
                prison->ResetDoorOrButton();
            else
                error_log("npc_unworthy_initiateAI: unable to find prison!");
        }
        return;
    case PHASE_TO_EQUIP:
        if (wait_timer)
        {
            if (wait_timer > diff)
                wait_timer -= diff;
            else
            {
                me->GetMotionMaster()->MovePoint(1, anchorX, anchorY, me->GetPositionZ());
                //debug_log("npc_unworthy_initiateAI: move to %f %f %f", anchorX, anchorY, me->GetPositionZ());
                phase = PHASE_EQUIPING;
                wait_timer = 0;
            }
        }
        return;
    case PHASE_TO_ATTACK:
        if (wait_timer)
        {
            if (wait_timer > diff)
                wait_timer -= diff;
            else
            {
                me->setFaction(14);
                me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE);
                phase = PHASE_ATTACKING;

                if (Player *pTarget = Unit::GetPlayer(playerGUID))
                    me->AI()->AttackStart(pTarget);
                wait_timer = 0;
            }
        }
        return;
    case PHASE_ATTACKING:
        if (!UpdateVictim())
            return;

        events.Update(diff);

        while (uint32 eventId = events.ExecuteEvent())
        {
            switch(eventId)
            {
            case EVENT_ICY_TOUCH:
                DoCast(me->getVictim(), SPELL_ICY_TOUCH);
                events.DelayEvents(1000, GCD_CAST);
                events.ScheduleEvent(EVENT_ICY_TOUCH, 5000, GCD_CAST);
                break;
            case EVENT_PLAGUE_STRIKE:
                DoCast(me->getVictim(), SPELL_PLAGUE_STRIKE);
                events.DelayEvents(1000, GCD_CAST);
                events.ScheduleEvent(SPELL_PLAGUE_STRIKE, 5000, GCD_CAST);
                break;
            case EVENT_BLOOD_STRIKE:
                DoCast(me->getVictim(), SPELL_BLOOD_STRIKE);
                events.DelayEvents(1000, GCD_CAST);
                events.ScheduleEvent(EVENT_BLOOD_STRIKE, 5000, GCD_CAST);
                break;
            case EVENT_DEATH_COIL:
                DoCast(me->getVictim(), SPELL_DEATH_COIL);
                events.DelayEvents(1000, GCD_CAST);
                events.ScheduleEvent(EVENT_DEATH_COIL, 5000, GCD_CAST);
                break;
            }
        }

        DoMeleeAttackIfReady();
    }
}
示例#8
0
/**
 * Prints the usage statement to screen.
 */
static void print_usage(void)
{
  error_log("Usage: %s <configserver endpoint>", PROCESS_NAME);
  error_log("This is a Pronghorn test harness");
}
示例#9
0
/**
 * Starts the harness.
 *
 * \param argc Num of args
 * \param argv The args
 * \returns 0 on success, -1 on error
 */
int main(int argc, char *argv[])
{
  SHORT_PROCESS_NAME = basename_safe(argv[0]);
  PROCESS_NAME = argv[0];

  // We accept only one argument, namely the transport address of the
  // global configuration server
  if (argc != 2)
  {
    print_usage();
    return -1;
  }

  if (config_init(argv[1]) != 0)
  {
    error_log("Unable to setup test harness. Is there a problem with the endpoint syntax? %s", argv[1]);
    return -1;
  }

  int ret = 0;

  ret = logger_config_init();

  if (ret != 0)
  {
    error_log("Failed to create log transport");
    cleanup(NULL);
    return -1;
  }

  char *test_harness_listen_endpoint = g_strdup_printf("%s-%d", TEST_SOCKET, getpid());

  debug_log("Test harness is listening on %s", test_harness_listen_endpoint);
  transport_t transport = transport_init(TRANSPORT_TYPE_PUSHPULL, test_harness_listen_endpoint);

  if (transport == NULL)
  {
    error_log("Unable to create transport");
    g_free(test_harness_listen_endpoint);
    cleanup(NULL);
    return -1;
  }

  if (spawn_subcontractor(argv[1], test_harness_listen_endpoint) != 0)
  {
    error_log("Unable to spawn subcontractor");
    g_free(test_harness_listen_endpoint);
    cleanup(transport);
    return -1;
  }
  g_free(test_harness_listen_endpoint);
  test_harness_listen_endpoint = NULL;

  char *input_file;

  if ((config_get(NULL, CONFIG_INPUT_FILE_OPTION_NAME, &input_file) != 0) || (input_file == NULL))
  {
    error_log("Could not get input file name");
    cleanup(transport);
    return -1;
  }

  char *subcontractor;

  if ((config_get(NULL, CONFIG_TEST_HARNESS_SUBCONTRACTOR_TO_TEST_OPTION_NAME, &subcontractor) != 0) || (subcontractor == NULL))
  {
    error_log("Unable to get the name of the subcontractor which means I couldn't calculate the timeout!");
    return -1;
  }

  const char *sub_name = basename_safe(subcontractor);

  long timeout = CONFIG_CONTRACTOR_SUBCONTRACTOR_TRANSPORT_TIMEOUT_DEFAULT;

  if (config_get_long_group_or_general_with_default_macro(sub_name, CONFIG_CONTRACTOR_SUBCONTRACTOR_TRANSPORT_TIMEOUT, &timeout) != 0)
  {
    info_log("Couldn't find out what timeout option to use, using default");
  }

  transport_set_recv_timeout(transport, timeout);
  debug_log("Using %li for timeout to subcontractor", timeout);

  unsigned int contract_string_size;
  contract_t c = contract_init(NULL, 0);

  contract_set_path(c, input_file);
  contract_set_contiguous(c, 1);
  contract_set_absolute_offset(c, 0);
  char *contract_string = contract_serialise(c, &contract_string_size);

  contract_close(c);
  g_free(input_file);
  if (contract_string == NULL)
  {
    perror("Failed to create contract_string");
    g_free(contract_string);
    g_free(subcontractor);
    cleanup(transport);
    return -1;
  }

  info_log("Sending message");

  unsigned int subcontractor_result_msg_size;
  const char *subcontractor_result_msg = transport_sendrecv(transport, contract_string, contract_string_size, &child_pid, &subcontractor_result_msg_size);

  if (subcontractor_result_msg == NULL)
  {

    if (errno == EAGAIN)
    {
      // Timeout.
      error_log
        ("Timeout in receiving message from subcontractor! Either your subcontractor hung (it will be killed when running in pronghorn) or it didn't compelete in time. You need to make sure that the timeout is long enough, by setting subcontractor_timeout (specifcally for your sub contractor or the general case). In pronghorn, this would be via the config file. Using the test harness, you can specificy this using \"-o %s.subcontractor_timeout=<timeout in milliseconds>\" or \"-o general.subcontractor_timeout=<timeout in milliseconds>\" at the end of the command line",
         sub_name);

    } else if (errno == EINTR)
    {
      // Interupted.
      error_log("Something when wrong waiting for your subcontractor to return. Did it crash?! You might like to try adding \"-o %s.valgrind_opts=<path to valgrind>\" when testing.", sub_name);
    }

    cleanup(transport);
    g_free(contract_string);
    g_free(subcontractor);
    return -1;
  }

  g_free(subcontractor);

  contract_completion_report_t report = contract_completion_report_init(subcontractor_result_msg, subcontractor_result_msg_size);

  if (report == NULL)
  {
    perror("Recreating contract_completion_report");
    g_free(contract_string);
    cleanup(transport);
    return -1;
  } else
  {
    info_log("Reconstructed message");
  }

  info_log("=====================");
  info_log("Results: ");
  unsigned int results_count;
  const result_t *results = contract_completion_report_get_results(report, &results_count);

  c = contract_completion_report_get_original_contract(report);;

  for (int i = 0; i < results_count; i++)
  {
    const result_t r = results[i];

    info_log("Path=%s. Type=(%s) %s. Confidence=%d", contract_get_path(c), result_get_brief_data_description(r), result_get_data_description(r), result_get_confidence(r));

#if PRINT_BLOCK_ARRAY
    unsigned int block_range_size;
    const block_range_t *ranges = result_get_block_ranges(r, &block_range_size);

    if (block_range_size > 0)
    {
      int j;

      info_log("Blocks:");

      // This is inefficient. But it works and this function is rarely used
      char *big_s = g_strdup("");

      for (j = 0; j < block_range_size; j++)
      {
        unsigned long long pos;
        unsigned long long len;

        block_range_get_range(ranges[j], &pos, &len);
        char *new_s = g_strdup_printf("%s %llu-%llu", big_s, pos, pos + len - 1);

        g_free(big_s);
        big_s = new_s;
      }
      info_log("%s", big_s);
      g_free(big_s);
    }
#endif // PRINT_BLOCK_ARRAY

    unsigned int new_contracts_count;

#if SIMPLE_CONTRACT_ENUMERATION
    result_get_new_contracts(r, &new_contracts_count);

    info_log("\t- With %d new contracts!", new_contracts_count);
#else // SIMPLE_CONTRACT_ENUMERATION
    // Yes, this looks dodgy, but it's fine until r gets destroyed (which is after we destroy our copy)
    const contract_t *new_contracts_const = result_get_new_contracts(r, &new_contracts_count);
    contract_t *new_contracts = (contract_t *) g_malloc(sizeof(contract_t) * new_contracts_count);

    memcpy(new_contracts, new_contracts_const, sizeof(contract_t) * new_contracts_count);

    if (new_contracts_count > 0)
    {
      // Sorting the array
#if SORT_CONTRACT_ARRAY
      {
        int j;

        for (j = 0; j < new_contracts_count - 1; j++)
        {
          int k;

          for (k = 0; k < new_contracts_count - j - 1; k++)
          {
            int a = atoi(contract_get_path(new_contracts[k]));
            int b = atoi(contract_get_path(new_contracts[k + 1]));

            if (a > b)
            {
              contract_t temp = new_contracts[k];

              new_contracts[k] = new_contracts[k + 1];
              new_contracts[k + 1] = temp;
            } else if (a == b)
            {
              warning_log("Duplicate entry found! %s", contract_get_path(new_contracts[k]));
            }
          }
        }
      }
#endif // SORT_CONTRACT_ARRAY
#if PRINT_CONTRACT_ARRAY
      {
        info_log("New contracts: ");
        int j;

        for (j = new_contracts_count - 1; j >= 0; j--)
        {
          const char *path = contract_get_path(new_contracts[j]);

          if (access(path, R_OK) == 0)
          {
            info_log("OK %s", path);
            print_md5(path);
          } else
          {
            info_log("Couldn't access advertised new path %s", path);
          }
        }
      }
#endif // PRINT_CONTRACT_ARRAY
    }
    g_free(new_contracts);
#endif // SIMPLE_CONTRACT_ENUMERATION
  }
  contract_completion_report_close(report);


  if (NUM_EXERCISE_LOOPS != 0)
  {
    info_log("=====================");
    info_log("Exercising the plugin");
    for (int i = 0; i < NUM_EXERCISE_LOOPS; i++)
    {
      subcontractor_result_msg = transport_sendrecv(transport, (char *) contract_string, contract_string_size, &child_pid, &subcontractor_result_msg_size);
    }

    info_log("Finished exercising the plugin");
  }

  info_log("=====================");

  info_log("Telling subcontractor to close nicely");

  g_free(contract_string);

  // Send empty contract to tell child to close
  c = contract_init(NULL, 0);
  contract_set_path(c, "");
  contract_string = contract_serialise(c, &contract_string_size);
  contract_close(c);
  subcontractor_result_msg = transport_sendrecv(transport, (char *) contract_string, contract_string_size, &child_pid, &subcontractor_result_msg_size);
  g_free(contract_string);

  if (child_pid != -1)
  {
    sleep(100);
  }

  volatile int local_child_pid = child_pid;

  if (local_child_pid != -1)
  {
    warning_log("Process hasn't died automatically. Sending SIGTERM");
    kill(local_child_pid, SIGTERM);
    sleep(10);
    local_child_pid = child_pid;
    if (local_child_pid != -1)
    {
      warning_log("Process STILL hasn't died... Killing it");
      kill(local_child_pid, SIGKILL);
    }
  }

  cleanup(transport);

  return 0;
}
示例#10
0
 cthunAI(Creature *c) : Scripted_NoMovementAI(c)
 {
     pInstance = (ScriptedInstance*)c->GetInstanceData();
     if (!pInstance)
         error_log("TSCR: No Instance eye_of_cthunAI");
 }
    void UpdateAI(const uint32 diff)
    {
        if (!UpdateVictim())
            return;

        //Only do this if we haven't spawned nef yet
        if (SpawnedAdds < 42)
        {
            //ShadowBoltTimer
            if (ShadowBoltTimer <= diff)
            {
                Unit *pTarget = NULL;
                pTarget = SelectUnit(SELECT_TARGET_RANDOM,0);
                if (pTarget)
                    DoCast(pTarget,SPELL_SHADOWBOLT);

                ShadowBoltTimer = 3000 + (rand()%7000);
            } else ShadowBoltTimer -= diff;

            //FearTimer
            if (FearTimer <= diff)
            {
                Unit *pTarget = NULL;
                pTarget = SelectUnit(SELECT_TARGET_RANDOM,0);
                if (pTarget)
                    DoCast(pTarget,SPELL_FEAR);

                FearTimer = 10000 + (rand()%10000);
            } else FearTimer -= diff;

            //Add spawning mechanism
            if (AddSpawnTimer <= diff)
            {
                //Spawn 2 random types of creatures at the 2 locations
                uint32 CreatureID;
                Creature* Spawned = NULL;
                Unit *pTarget = NULL;

                //1 in 3 chance it will be a chromatic
                if (rand()%3 == 0)
                    CreatureID = CREATURE_CHROMATIC_DRAKANOID;
                else CreatureID = DrakType1;

                SpawnedAdds++;

                //Spawn creature and force it to start attacking a random target
                Spawned = me->SummonCreature(CreatureID,ADD_X1,ADD_Y1,ADD_Z1,5.000f,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,5000);
                pTarget = SelectUnit(SELECT_TARGET_RANDOM,0);
                if (pTarget && Spawned)
                {
                    Spawned->AI()->AttackStart(pTarget);
                    Spawned->setFaction(103);
                }

                //1 in 3 chance it will be a chromatic
                if (rand()%3 == 0)
                    CreatureID = CREATURE_CHROMATIC_DRAKANOID;
                else CreatureID = DrakType2;

                SpawnedAdds++;

                pTarget = NULL;
                Spawned = NULL;
                Spawned = me->SummonCreature(CreatureID,ADD_X2,ADD_Y2,ADD_Z2,5.000f,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,5000);
                pTarget = SelectUnit(SELECT_TARGET_RANDOM,0);
                if (pTarget && Spawned)
                {
                    Spawned->AI()->AttackStart(pTarget);
                    Spawned->setFaction(103);
                }

                //Begin phase 2 by spawning Nefarian and what not
                if (SpawnedAdds >= 42)
                {
                    //Teleport Victor Nefarius way out of the map
                    //MapManager::Instance().GetMap(me->GetMapId(), me)->CreatureRelocation(me,0,0,-5000,0);

                    //Inturrupt any spell casting
                    me->InterruptNonMeleeSpells(false);

                    //Root self
                    DoCast(me,33356);

                    //Make super invis
                    DoCast(me,8149);

                    //Teleport self to a hiding spot (this causes errors in the Oregon log but no real issues)
                    DoTeleportTo(HIDE_X,HIDE_Y,HIDE_Z);
                    me->addUnitState(UNIT_STAT_FLEEING);

                    //Spawn nef and have him attack a random target
                    Creature* Nefarian = NULL;
                    Nefarian = me->SummonCreature(CREATURE_NEFARIAN,NEF_X,NEF_Y,NEF_Z,0,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,120000);
                    pTarget = NULL;
                    pTarget = SelectUnit(SELECT_TARGET_RANDOM,0);
                    if (pTarget && Nefarian)
                    {
                        Nefarian->AI()->AttackStart(pTarget);
                        Nefarian->setFaction(103);
                        NefarianGUID = Nefarian->GetGUID();
                    }
                    else error_log("OSCR: Blackwing Lair: Unable to spawn nefarian properly.");
                }

                AddSpawnTimer = 4000;
            } else AddSpawnTimer -= diff;
        }
        else if (NefarianGUID)
        {
            if (NefCheckTime <= diff)
            {
                Unit* Nefarian = NULL;
                Nefarian = Unit::GetUnit((*me),NefarianGUID);

                //If nef is dead then we die to so the players get out of combat
                //and cannot repeat the event
                if (!Nefarian || !Nefarian->isAlive())
                {
                    NefarianGUID = 0;
                    me->DealDamage(me, me->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
                }

                NefCheckTime = 2000;
            } else NefCheckTime -= diff;
        }
    }
示例#12
0
void downloader_init(upstreams *upstr_ptr, mqd_t msgq_id) {

	/* Initialise MySQL connection */
	MYSQL_RES *result;
	MYSQL_ROW row;
	int num_fields;

	if ((conn = init_mysql(conn)) == NULL) {
		mysql_close(conn);
		error_log(ERROR, "MySQL initialisation failed");
		exit(EXIT_FAILURE);
	}

	if (!connect_mysql(conn)) {
		mysql_close(conn);
		error_log(ERROR, "MySQL connection failed");
		exit(EXIT_FAILURE);
	}

	int n;
	const config_setting_t *upstr_setting;
	static int upstream_count;

	upstr_setting = config_lookup(&cfg, "upstreams");
	upstream_count = config_setting_length(upstr_setting);

	error_log(ERROR, "Connected to MySQL.");
	struct mq_attr msgq_attr;
	int fe_id = cfg_get_int("fe_id");
	static char query[QUERY_MAX];
	unsigned int msgprio = 1;

	while (running) {
		/* Schedule upstreams */
		for (n = 0; n < upstream_count; n++) {
			if (!upstr_ptr[n].alive
					&& (time(NULL) - upstr_ptr[n].deadtime)
							> cfg_get_int("upstream_dead_timeout")) {
				error_log(DEBUG,
						"Making %s live again, time of dead: %d, now: %d",
						upstr_ptr[n].upstream, upstr_ptr[n].deadtime,
						time(NULL));
				upstr_ptr[n].alive = 1;
			}
			error_log(DEBUG, "Upstream: %s, active: %d", upstr_ptr[n].upstream,
					upstr_ptr[n].alive);
		}
		/* Get latest data */
		mq_getattr(msgq_id, &msgq_attr);
		if (!msgq_attr.mq_curmsgs) {
			if (cfg_get_int("dmode") == 2) {
				/* Query for robin mode*/
				sprintf(query,
						"SELECT filename, size from scoreboard WHERE id NOT "
								"IN(SELECT id from cached where fe_id=%d) AND count >=%d "
								"order by count DESC, last_modified DESC, size limit %d",
						fe_id, cfg_get_int("cache_req_count"),
						cfg_get_int("workers"));
			} else {
				/* Query for shard mode*/
				sprintf(query,
						"SELECT filename, size from scoreboard WHERE id NOT "
								"IN(SELECT id from cached where fe_id=%d) AND count >=%d "
								"AND fe_id=%d "
								"order by count DESC, last_modified DESC, size limit %d",
						fe_id, cfg_get_int("cache_req_count"), fe_id,
						cfg_get_int("workers"));
			}

			query_mysql(conn, query);
			result = mysql_store_result(conn);
			num_fields = mysql_num_fields(result);

			while ((row = mysql_fetch_row(result))) {
				if (row[0] && row[1]) {
					if (check_file_exists(row[0], atoi(row[1])) != 0) {
						continue;
					}
					mq_send(msgq_id, row[0], strlen(row[0]) + 1, msgprio);
				}
			}
			mysql_free_result(result);
		}
		sleep(5);
	}
	error_log(ERROR, "Exiting");
}
示例#13
0
    void UpdateAI(const uint32 uiDiff)
    {
        if (!UpdateVictim())
            return;

        if (!m_bIsPhaseTwo)
        {
            if (m_uiShadowWordPain_Timer <= uiDiff)
            {
                DoCast(m_creature->getVictim(), SPELL_SHADOWWORDPAIN);
                m_uiShadowWordPain_Timer = 15000;
            }
            else
                m_uiShadowWordPain_Timer -= uiDiff;

            if (m_uiMark_Timer <= uiDiff)
            {
                m_pMarkedTarget = SelectUnit(SELECT_TARGET_RANDOM,0);

                if (m_pMarkedTarget)
                    DoCast(m_pMarkedTarget, SPELL_MARK);
                else
                    error_log("TSCR: boss_arlokk could not accuire m_pMarkedTarget.");

                m_uiMark_Timer = 15000;
            }
            else
                m_uiMark_Timer -= uiDiff;
        }
        else
        {
            //Cleave_Timer
            if (m_uiCleave_Timer <= uiDiff)
            {
                DoCast(m_creature->getVictim(), SPELL_CLEAVE);
                m_uiCleave_Timer = 16000;
            }
            else
                m_uiCleave_Timer -= uiDiff;

            //Gouge_Timer
            if (m_uiGouge_Timer <= uiDiff)
            {
                DoCast(m_creature->getVictim(), SPELL_GOUGE);

                DoModifyThreatPercent(m_creature->getVictim(),-80);

                m_uiGouge_Timer = 17000+rand()%10000;
            }
            else
                m_uiGouge_Timer -= uiDiff;
        }

        if (m_uiSummonCount <= 30)
        {
            if (m_uiSummon_Timer <= uiDiff)
            {
                DoSummonPhanters();
                m_uiSummon_Timer = 5000;
            }
            else
                m_uiSummon_Timer -= uiDiff;
        }

        if (m_uiVanish_Timer <= uiDiff)
        {
            //Invisble Model
            m_creature->SetDisplayId(MODEL_ID_BLANK);
            m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);

            m_creature->AttackStop();
            DoResetThreat();

            m_bIsVanished = true;

            m_uiVanish_Timer = 45000;
            m_uiVisible_Timer = 6000;
        }
        else
            m_uiVanish_Timer -= uiDiff;

        if (m_bIsVanished)
        {
            if (m_uiVisible_Timer <= uiDiff)
            {
                //The Panther Model
                m_creature->SetDisplayId(MODEL_ID_PANTHER);
                m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);

                const CreatureInfo *cinfo = m_creature->GetCreatureInfo();
                m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (cinfo->mindmg +((cinfo->mindmg/100) * 35)));
                m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (cinfo->maxdmg +((cinfo->maxdmg/100) * 35)));
                m_creature->UpdateDamagePhysical(BASE_ATTACK);

                if (Unit* pTarget = SelectUnit(SELECT_TARGET_RANDOM,0))
                    AttackStart(pTarget);

                m_bIsPhaseTwo = true;
                m_bIsVanished = false;
            }
            else
                m_uiVisible_Timer -= uiDiff;
        }
        else
            DoMeleeAttackIfReady();
    }
void instance_trial_of_the_crusader::SetData(uint32 uiType, uint32 uiData)
{
    switch(uiType)
    {
        case TYPE_WIPE_COUNT:
            if (IsHeroicDifficulty())
                DoUpdateWorldState(WORLD_STATE_WIPES_COUNT, MAX_WIPES_ALLOWED - m_auiEncounter[TYPE_WIPE_COUNT] >= 0 ? MAX_WIPES_ALLOWED - m_auiEncounter[TYPE_WIPE_COUNT] : 0);
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_NORTHREND_BEASTS:
            if (uiData == SPECIAL)
            {
                if (Creature* pTirion = GetSingleCreatureFromStorage(NPC_TIRION_A))
                    DoScriptText(m_auiEncounter[uiType] != FAIL ? SAY_TIRION_RAID_INTRO_LONG : SAY_RAID_TRIALS_INTRO, pTirion);
                StartNextDialogueText(TYPE_NORTHREND_BEASTS);
            }
            else if (uiData == FAIL)
            {
                SetData(TYPE_WIPE_COUNT, m_auiEncounter[TYPE_WIPE_COUNT] + 1);
                StartNextDialogueText(SAY_TIRION_BEAST_WIPE);
            }
            else if (uiData == DONE)
                StartNextDialogueText(SAY_TIRION_BEAST_SLAY);
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_JARAXXUS:
            if (uiData == SPECIAL)
                // TODO - What happen in wipe case?
                StartNextDialogueText(TYPE_JARAXXUS);
            else if (uiData == FAIL)
            {
                SetData(TYPE_WIPE_COUNT, m_auiEncounter[TYPE_WIPE_COUNT] + 1);
                StartNextDialogueText(NPC_RAMSEY_2);
            }
            else if (uiData == DONE)
                StartNextDialogueText(SAY_JARAXXUS_DEATH);
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_FACTION_CHAMPIONS:
            if (uiData == SPECIAL)
                StartNextDialogueText(m_auiEncounter[uiType] != FAIL ? SAY_TIRION_PVP_INTRO_1 : TYPE_FACTION_CHAMPIONS);
            else if (uiData == FAIL)
            {
                SetData(TYPE_WIPE_COUNT, m_auiEncounter[TYPE_WIPE_COUNT] + 1);
                StartNextDialogueText(NPC_RAMSEY_3);
            }
            else if (uiData == DONE)
            {
                DoRespawnGameObject(GO_CRUSADERS_CACHE, 60*MINUTE);
                StartNextDialogueText(SAY_VARIAN_PVP_A_WIN);
            }
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_TWIN_VALKYR:
            if (uiData == SPECIAL)
            {
                if (Creature* pTirion = GetSingleCreatureFromStorage(NPC_TIRION_A))
                    DoScriptText(m_auiEncounter[uiType] != FAIL ? SAY_TIRION_TWINS_INTRO : SAY_RAID_INTRO_SHORT, pTirion);
            }
            else if (uiData == FAIL)
            {
                SetData(TYPE_WIPE_COUNT, m_auiEncounter[TYPE_WIPE_COUNT] + 1);
                StartNextDialogueText(NPC_RAMSEY_4);
            }
            else if (uiData == DONE)
                StartNextDialogueText(EVENT_TWINS_KILLED);
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_ANUBARAK:
            if (uiData == SPECIAL)
                StartNextDialogueText(TYPE_ANUBARAK);
            else if (uiData == FAIL)
                SetData(TYPE_WIPE_COUNT, m_auiEncounter[TYPE_WIPE_COUNT] + 1);
            else if (uiData == DONE)
                DoHandleEventEpilogue();
            // Handle combat door
            if (uiData != SPECIAL)
                DoUseDoorOrButton(GO_WEB_DOOR);
            m_auiEncounter[uiType] = uiData;
            break;
        default:
            error_log("SD2: Instance Trial of The Crusader: ERROR SetData = %u for type %u does not exist/not implemented.", uiType, uiData);
            return;
    }

    if (uiData == DONE || uiType == TYPE_WIPE_COUNT)
    {
        OUT_SAVE_INST_DATA;

        std::ostringstream saveStream;
        saveStream << m_auiEncounter[0] << " " << m_auiEncounter[1] << " " << m_auiEncounter[2] << " "
            << m_auiEncounter[3] << " " << m_auiEncounter[4] << " " << m_auiEncounter[5];

        m_strInstData = saveStream.str();

        SaveToDB();
        OUT_SAVE_INST_DATA_COMPLETE;
    }
}
示例#15
0
 void HandleFlightSequence()
 {
     switch(FlightCount)
     {
     case 0:
         //m_creature->AttackStop();
         error_log("prevent fly phase");
         m_creature->GetMotionMaster()->Clear(false);
         m_creature->HandleEmoteCommand(EMOTE_ONESHOT_LIFTOFF);
         m_creature->SetUnitMovementFlags(MOVEMENTFLAG_LEVITATING);
         m_creature->StopMoving();
         DoScriptText(YELL_TAKEOFF, m_creature);
         Timer[EVENT_FLIGHT_SEQUENCE] = 2000;
         break;
     case 1:
         error_log("Move to Fly point");
         m_creature->GetMotionMaster()->MovePoint(0, m_creature->GetPositionX()+1, m_creature->GetPositionY(), m_creature->GetPositionZ()+10);
         Timer[EVENT_FLIGHT_SEQUENCE] = 0;
         break;
     case 2:{
         error_log("Summon Vapor case 2");
         Unit* target;
         target = SelectUnit(SELECT_TARGET_RANDOM, 0, 150, true);
         if(!target) target = Unit::GetUnit((*m_creature), pInstance->GetData64(DATA_PLAYER_GUID));
         if(target)
         {
             Creature* Vapor = m_creature->SummonCreature(MOB_VAPOR, target->GetPositionX()-5+rand()%10, target->GetPositionY()-5+rand()%10, target->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 9000);
             if(Vapor)
             {
                 Vapor->AI()->AttackStart(target);
                 m_creature->InterruptNonMeleeSpells(false);
                 m_creature->CastSpell(Vapor, SPELL_VAPOR_CHANNEL, false); // core bug
                 Vapor->CastSpell(Vapor, SPELL_VAPOR_TRIGGER, true);
             }
         }
         else
         {
             EnterEvadeMode();
             return;
         }
         Timer[EVENT_FLIGHT_SEQUENCE] = 10000;
         break;}
     case 3: {
         DespawnSummons(MOB_VAPOR_TRAIL);
         error_log("Summon Vapor case3");
         //m_creature->CastSpell(m_creature, SPELL_VAPOR_SELECT); need core support
         Unit* target;
         target = SelectUnit(SELECT_TARGET_RANDOM, 0, 150, true);
         if(!target) target = Unit::GetUnit((*m_creature), pInstance->GetData64(DATA_PLAYER_GUID));
         if(target)
         {
             //target->CastSpell(target, SPELL_VAPOR_SUMMON, true); need core support
             Creature* Vapor = m_creature->SummonCreature(MOB_VAPOR, target->GetPositionX()-5+rand()%10, target->GetPositionY()-5+rand()%10, target->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 9000);
             if(Vapor)
             {
                 Vapor->AI()->AttackStart(target);
                 m_creature->InterruptNonMeleeSpells(false);
                 m_creature->CastSpell(Vapor, SPELL_VAPOR_CHANNEL, false); // core bug
                 Vapor->CastSpell(Vapor, SPELL_VAPOR_TRIGGER, true);
             }
         }
         else
         {
             EnterEvadeMode();
             return;
         }
         Timer[EVENT_FLIGHT_SEQUENCE] = 10000;
         break;}
     case 4:
         DespawnSummons(MOB_VAPOR_TRAIL);
         Timer[EVENT_FLIGHT_SEQUENCE] = 1;
         break;
     case 5:{
         Unit* target;
         target = SelectUnit(SELECT_TARGET_RANDOM, 0, 150, true);
         if(!target) target = Unit::GetUnit((*m_creature), pInstance->GetData64(DATA_PLAYER_GUID));
         if(target)
         {
             BreathX = target->GetPositionX();
             BreathY = target->GetPositionY();
             float x, y, z;
             target->GetContactPoint(m_creature, x, y, z, 70);
             m_creature->GetMotionMaster()->MovePoint(0, x, y, z+10);
         }else
         {
             EnterEvadeMode();
             return;
         }
         Timer[EVENT_FLIGHT_SEQUENCE] = 0;
         break;}
     case 6:
         m_creature->SetOrientation(m_creature->GetAngle(BreathX, BreathY));
         m_creature->StopMoving();
         //DoTextEmote("takes a deep breath.", NULL);
         Timer[EVENT_FLIGHT_SEQUENCE] = 10000;
         break;
     case 7:
         m_creature->CastSpell(m_creature, SPELL_FOG_BREATH, true);
         {
             float x, y, z;
             m_creature->GetPosition(x, y, z);
             x = 2 * BreathX - x;
             y = 2 * BreathY - y;
             m_creature->GetMotionMaster()->MovePoint(0, x, y, z);
         }
         Timer[EVENT_SUMMON_FOG] = 1;
         Timer[EVENT_FLIGHT_SEQUENCE] = 0;
         break;
     case 8:
         m_creature->RemoveAurasDueToSpell(SPELL_FOG_BREATH);
         BreathCount++;
         Timer[EVENT_SUMMON_FOG] = 0;
         Timer[EVENT_FLIGHT_SEQUENCE] = 1;
         if(BreathCount < 3) FlightCount = 4;
         break;
     case 9:
         if(Unit* target = SelectUnit(SELECT_TARGET_TOPAGGRO, 0))
         {
             float x, y, z;
             target->GetContactPoint(m_creature, x, y, z);
             m_creature->GetMotionMaster()->MovePoint(0, x, y, z);
         }
         else
         {
             EnterEvadeMode();
             return;
         }
         Timer[EVENT_FLIGHT_SEQUENCE] = 0;
         break;
     case 10:
         m_creature->RemoveUnitMovementFlag(MOVEMENTFLAG_LEVITATING);
         m_creature->StopMoving();
         m_creature->HandleEmoteCommand(EMOTE_ONESHOT_LAND);
         EnterPhase(PHASE_GROUND);
         m_creature->AI()->AttackStart(SelectUnit(SELECT_TARGET_TOPAGGRO, 0));
         break;
     default:
         break;
     }
     FlightCount++;
 }
示例#16
0
int listen_thread(struct server_conf *srv){
	struct sockaddr_in server;
	struct sockaddr_in client;
	//struct con_stack *connections=NULL;
	int client_len;
	int newsock=-1;
	int sock;
	char logstr[1024];
	server.sin_family=AF_INET;    ///init server addr
	//struct con_stack *connections;
	sprintf(logstr,"listen thread create %u",pthread_self());
	debug_log(logstr);
	connections=(struct con_stack*)malloc(sizeof(struct con_stack));
	if(!connections){
		error_log("malloc for connection stack error");
		exit(-1);
	}
	debug_log("malloc for connection stack OK");
	stack_init(connections);
	if(!srv->ip)
    		server.sin_addr.s_addr=htonl(INADDR_ANY);
	else
		inet_pton(AF_INET,srv->ip,&server.sin_addr.s_addr);
   	if(!srv->port)
		server.sin_port=htons(80);
	else
		server.sin_port=htons(srv->port);
   	memset(server.sin_zero,0,8);

	if((sock=socket(AF_INET,SOCK_STREAM,0))<0){
		error_log("create sock failed");
		exit(-1);
	}
	debug_log("create sock sucessful");
	//listen_sock=sock;
	if(bind(sock,(struct sockaddr*)&server,sizeof(server))<0){
		error_log("bind sock error");
		exit(-1);
	}
	debug_log("bind sock sucessful");
	if(!srv->maxfds){
		listen(sock,10);
		error_log("read server config maxfds error,listen 10");
	}
	else{
		listen(sock,srv->maxfds);
		debug_log("listen sucessful");
	}
	while(1){
		if((int)(connections->top)>128){
			//printf("top is %d\n",connections->top);
			warn_log("listen stack > 128,sleep 1s");
			sleep(1);
			continue;
		}
		if((newsock=accept(sock,(struct sockaddr*)&client,&client_len))<0){
			sprintf(logstr,"accept error,accept sock %d",newsock);
			warn_log(logstr);
			continue;
		}
		sprintf(logstr,"accept OK,accept sock %d",newsock);
		warn_log(logstr);
		con_push(connections,newsock);

	}
}
示例#17
0
 void Debug (uint32 Point)
 {
     error_log("Debug: Wailing Caverns escort event point %u, initialized by %w", Point, EventStarter->GetName());
 }
void instance_blood_furnace::SetData(uint32 uiType, uint32 uiData)
{
    switch(uiType)
    {
        case TYPE_THE_MAKER_EVENT:
            if (uiData == IN_PROGRESS)
                DoUseDoorOrButton(GO_DOOR_MAKER_FRONT);
            if (uiData == FAIL)
                DoUseDoorOrButton(GO_DOOR_MAKER_FRONT);
            if (uiData == DONE)
            {
                DoUseDoorOrButton(GO_DOOR_MAKER_FRONT);
                DoUseDoorOrButton(GO_DOOR_MAKER_REAR);
		// Init Brogook event
		BroggokOrcsInit();
            }
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_BROGGOK_EVENT:
            if (m_auiEncounter[uiType] == uiData)
                return;

            // Combat door; the exit door is opened in event
            DoUseDoorOrButton(GO_DOOR_BROGGOK_FRONT);
            if (uiData == IN_PROGRESS)
            {
                if (m_uiBroggokEventPhase <= MAX_ORC_WAVES)
                {
                    m_uiBroggokEventPhase = 0;
                    DoSortBroggokOrcs();
                    // open first cage
                    DoNextBroggokEventPhase();
                }
            }
            else if (uiData == FAIL)
            {
                // On wipe we reset only the orcs; if the party wipes at the boss itself then the orcs don't reset
                if (m_uiBroggokEventPhase <= MAX_ORC_WAVES)
                {
                    for (uint8 i = 0; i < MAX_ORC_WAVES; ++i)
                    {
                        // Reset Orcs
                        if (!m_aBroggokEvent[i].m_bIsCellOpened)
                            continue;

                        m_aBroggokEvent[i].m_uiKilledOrcCount = 0;
                        for (GuidSet::const_iterator itr = m_aBroggokEvent[i].m_sSortedOrcGuids.begin(); itr != m_aBroggokEvent[i].m_sSortedOrcGuids.end(); ++itr)
                        {
                            if (Creature* pOrc = instance->GetCreature(*itr))
                            {
                                if (!pOrc->isAlive())
                                    pOrc->Respawn();
                            }
                        }

                        // Close Door
                        DoUseDoorOrButton(m_aBroggokEvent[i].m_cellGuid);
                        m_aBroggokEvent[i].m_bIsCellOpened = false;
                    }
                }
            }
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_KELIDAN_EVENT:
            if (uiData == DONE)
            {
                DoUseDoorOrButton(GO_DOOR_KELIDAN_EXIT);
                DoUseDoorOrButton(GO_DOOR_FINAL_EXIT);
            }
            m_auiEncounter[uiType] = uiData;
            break;
        default:
            error_log("SD2: Instance Blood Furnace SetData with Type %u Data %u, but this is not implemented.", uiType, uiData);
            return;
    }

    if (uiData == DONE)
    {
        OUT_SAVE_INST_DATA;

        std::ostringstream saveStream;
        saveStream << m_auiEncounter[0] << " " << m_auiEncounter[1] << " " << m_auiEncounter[2];

        m_strInstData = saveStream.str();

        SaveToDB();
        OUT_SAVE_INST_DATA_COMPLETE;
    }
}
示例#19
0
void instance_gundrak::SetData(uint32 uiType, uint32 uiData)
{
    debug_log("SD2: Instance Gundrak: SetData received for type %u with data %u",uiType,uiData);

    switch(uiType)
    {
        case TYPE_SLADRAN:
            m_auiEncounter[0] = uiData;
            if (uiData == DONE)
                if (GameObject* pGo = instance->GetGameObject(m_uiAltarOfSladranGUID))
                    pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_UNK1);
            if (uiData == SPECIAL)
			{
                DoUseDoorOrButton(m_uiSnakeKeyGUID);
				DoSwitchBridgeIfCan();
			}
            break;
        case TYPE_MOORABI:
            m_auiEncounter[1] = uiData;
            if (uiData == DONE)
            {
                if (!instance->IsRegularDifficulty())
                    DoUseDoorOrButton(m_uiEckDoorGUID);
                if (GameObject* pGo = instance->GetGameObject(m_uiAltarOfMoorabiGUID))
                    pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_UNK1);
            }
            if (uiData == SPECIAL)
			{
                DoUseDoorOrButton(m_uiMammothKeyGUID);
				DoSwitchBridgeIfCan();
			}
            break;
        case TYPE_COLOSSUS:
            m_auiEncounter[2] = uiData;
            if (uiData == DONE)
                if (GameObject* pGo = instance->GetGameObject(m_uiAltarOfColossusGUID))
                    pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_UNK1);
            if (uiData == SPECIAL)
			{
                DoUseDoorOrButton(m_uiTrollKeyGUID);
				DoSwitchBridgeIfCan();
			}
            break;
        case TYPE_GALDARAH:
            m_auiEncounter[3] = uiData;
            DoUseDoorOrButton(m_uiGaldarahDoorGUID);
            if (uiData == DONE)
            {
                DoUseDoorOrButton(m_uiExitDoorLeftGUID);
                DoUseDoorOrButton(m_uiExitDoorRightGUID);
            }
            break;
        case TYPE_ECK:
            m_auiEncounter[4] = uiData;
            if (uiData == DONE)
                DoUseDoorOrButton(m_uiEckUnderwaterDoorGUID);
            break;
        default:
            error_log("SD2: Instance Gundrak: ERROR SetData = %u for type %u does not exist/not implemented.",uiType,uiData);
            break;
    }

    if (uiData == DONE)
    {
        OUT_SAVE_INST_DATA;

        std::ostringstream saveStream;
        saveStream << m_auiEncounter[0] << " " << m_auiEncounter[1] << " " << m_auiEncounter[2] << " " << m_auiEncounter[3] << " "
            << m_auiEncounter[4];

        strInstData = saveStream.str();

        SaveToDB();
        OUT_SAVE_INST_DATA_COMPLETE;
    }
}
示例#20
0
//TODO: get rid of this many variables passed in function.
void npc_escortAI::Start(bool bIsActiveAttacker, bool bRun, uint64 uiPlayerGUID, const Quest* pQuest, bool bInstantRespawn, bool bCanLoopPath)
{
    if (m_creature->getVictim())
    {
        error_log("ISCR ERROR: EscortAI attempt to Start while in combat.");
        return;
    }

    if (HasEscortState(STATE_ESCORT_ESCORTING))
    {
        error_log("ISCR: EscortAI attempt to Start while already escorting.");
        return;
    }

    if (!ScriptWP) // sd2 never adds wp in script, but tc does
    {

    if (!WaypointList.empty())
        WaypointList.clear();

    FillPointMovementListForCreature();

    }

    if (WaypointList.empty())
    {
        if (pQuest != NULL)
        {
            error_db_log("TSCR: EscortAI Start with 0 waypoints (possible missing entry in script_waypoint. Quest: %u).", m_pQuestForEscort->GetQuestId());
            return;
        }
        else
            return;
    }

    //set variables
    m_bIsActiveAttacker = bIsActiveAttacker;
    m_bIsRunning = bRun;

    m_uiPlayerGUID = uiPlayerGUID;
    m_pQuestForEscort = pQuest;

    m_bCanInstantRespawn = bInstantRespawn;
    m_bCanReturnToStart = bCanLoopPath;

    if (m_bCanReturnToStart && m_bCanInstantRespawn)
        debug_log("ISCR: EscortAI is set to return home after waypoint end and instant respawn at waypoint end. Creature will never despawn.");

    if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE)
    {
        m_creature->GetMotionMaster()->MovementExpired();
        m_creature->GetMotionMaster()->MoveIdle();
        debug_log("ISCR: EscortAI start with WAYPOINT_MOTION_TYPE, changed to MoveIdle.");
    }

    //disable npcflags
    m_creature->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);

    debug_log("ISCR: EscortAI started with %u waypoints. ActiveAttacker = %d, Run = %d, PlayerGUID = %u", WaypointList.size(), m_bIsActiveAttacker, m_bIsRunning, m_uiPlayerGUID);

    CurrentWP = WaypointList.begin();

    //Set initial speed
    if (m_bIsRunning)
        m_creature->RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
    else
        m_creature->AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);

    AddEscortState(STATE_ESCORT_ESCORTING);

    JustStartedEscort();
}
    void SetData(uint32 uiType, uint32 uiData)
    {
        debug_log("DS: Instance Black Temple: SetData received for type %u with data %u",uiType,uiData);

        switch(uiType)
        {
            case TYPE_NAJENTUS:
                m_auiEncounter[0] = uiData;
                if (uiData == DONE)
                    DoUseDoorOrButton(m_uiNajentusGateGUID);
                break;
            case TYPE_SUPREMUS:
                m_auiEncounter[1] = uiData;
                if (uiData == DONE)
                    DoUseDoorOrButton(m_uiMainTempleDoorsGUID);
                break;
            case TYPE_SHADE:
                m_auiEncounter[2] = uiData;
                if (uiData == DONE && CanPreMotherDoorOpen())
                    DoUseDoorOrButton(m_uiShahrazPreDoorGUID);
                break;
            case TYPE_GOREFIEND:
                m_auiEncounter[3] = uiData;
                if (uiData == DONE && CanPreMotherDoorOpen())
                    DoUseDoorOrButton(m_uiShahrazPreDoorGUID);
                break;
            case TYPE_BLOODBOIL:
                m_auiEncounter[4] = uiData;
                if (uiData == DONE && CanPreMotherDoorOpen())
                    DoUseDoorOrButton(m_uiShahrazPreDoorGUID);
                break;
            case TYPE_RELIQUIARY:
                m_auiEncounter[5] = uiData;
                if (uiData == DONE && CanPreMotherDoorOpen())
                    DoUseDoorOrButton(m_uiShahrazPreDoorGUID);
                break;
            case TYPE_SHAHRAZ:
                if (uiData == DONE)
                {
                    DoUseDoorOrButton(m_uiCouncilDoorGUID);
                    DoUseDoorOrButton(m_uiShahrazPostDoorGUID);
                }
                m_auiEncounter[6] = uiData;
                break;
            case TYPE_COUNCIL:    m_auiEncounter[7] = uiData; break;
            case TYPE_ILLIDAN:    m_auiEncounter[8] = uiData; break;
            default:
                error_log("DS: Instance Black Temple: ERROR SetData = %u for type %u does not exist/not implemented.",uiType,uiData);
                break;
        }

        if (uiData == DONE)
        {
            OUT_SAVE_INST_DATA;

            std::ostringstream saveStream;
            saveStream << m_auiEncounter[0] << " " << m_auiEncounter[1] << " " << m_auiEncounter[2] << " "
                << m_auiEncounter[3] << " " << m_auiEncounter[4] << " " << m_auiEncounter[5] << " "
                << m_auiEncounter[6] << " " << m_auiEncounter[7] << " " << m_auiEncounter[8];

            strInstData = saveStream.str();

            SaveToDB();
            OUT_SAVE_INST_DATA_COMPLETE;
        }
    }
示例#22
0
文件: vnode.c 项目: uukuguy/legolas
vnode_t *vnode_new(const char *root_dir, uint32_t id, enum eVnodeStorageType storage_type, vnode_write_queue_handle_write_cb vnode_write_queue_handle_write)
{
    vnode_t *vnode = (vnode_t*)zmalloc(sizeof(vnode_t));

    memset(vnode, 0, sizeof(vnode_t));
    vnode->id = id;
    vnode->storage_type = storage_type;
    /*vnode->max_dbsize = 1024L * 1024L * 1024L * 4L;*/
    vnode->max_dbsize = 1024L * 1024L * 500L;

    /* Create vnode root dir */
    sprintf(vnode->root_dir, "%s/%04d", root_dir, id);
    if ( mkdir_if_not_exist(vnode->root_dir) != 0 ){
        error_log("Cann't create vnode(%d) dir:%s", id, vnode->root_dir);
        zfree(vnode);
        return NULL;
    }

    /* datazones */
    int i;
    for ( i = 0 ; i < MAX_DATAZONES ; i++ ){
        vnode->datazones[i] = (datazone_t*)zmalloc(sizeof(datazone_t));
        if ( datazone_init(vnode->datazones[i], vnode, i) != 0 ){
            zfree(vnode);
            return NULL;
        }
    }

    /* Slices DB */
    if ( vnode->storage_type >= STORAGE_KVDB ){

        // Create Metadata DB.
        const char *metadata_dbname = "metadata";
        kvdb_t *kvdb_metadata = vnode_open_kvdb(vnode, metadata_dbname);
        if ( kvdb_metadata == NULL ){
            error_log("MetadataDB create failed. dbname:%s", metadata_dbname);
            zfree(vnode);
            return NULL;
        }
        vnode->kvdb_metadata = kvdb_metadata;

        uint32_t active_slicedb_id = 0;
        if ( kvdb_get_uint32(kvdb_metadata, "active_slicedb_id", &active_slicedb_id) != 0 ){
            active_slicedb_id = 0;
        }
        notice_log("vnode active_slicedb_id:%d", active_slicedb_id);

        // Create Slice DB.
        for ( int db_id = 0 ; db_id <= active_slicedb_id ; db_id++ ){
            slicedb_t *slicedb = vnode_open_slicedb(vnode, db_id);
            if ( slicedb != NULL ){
            } else {
            /*char dbname[NAME_MAX];*/
            /*sprintf(dbname, "slice-%03d", db_id);*/
            /*kvdb_t *kvdb = vnode_open_kvdb(vnode, dbname);*/
            /*if ( kvdb != NULL ){*/
                /*vnode->slicedbs[db_id] = slicedb_new(db_id, kvdb, vnode->max_dbsize);*/
            /*} else {*/
                /*error_log("SliceDB create failed. dbname:%s", dbname);*/
                for ( int n = 0 ; n < db_id ; n++ ){
                    slicedb_free(vnode->slicedbs[n]);
                    vnode->slicedbs[n] = NULL;
                }
                zfree(vnode);
                return NULL;
            }
        }
        vnode->active_slicedb = vnode->slicedbs[active_slicedb_id];
        /*vnode->kvdb = vnode->active_slicedb->kvdb;*/

    }

    vnode->caching_objects = object_queue_new(object_compare_md5_func);

    vnode->received_objects = listCreate();
    vnode->received_object_size = 0;
    vnode->standby_objects = listCreate();
    vnode->standby_object_size = 0;

    vnode->write_queue = init_work_queue(vnode_write_queue_handle_write, VNODE_WRITE_QUEUE_INTERVAL);

    return vnode;
}
示例#23
0
    void UpdateAI(const uint32 diff)
    {
        if (!m_creature->SelectHostilTarget() || !m_creature->getVictim())
            return;

        //Only do this if we haven't spawned nef yet
        if (SpawnedAdds < 42)
        {
            //ShadowBoltTimer
            if (ShadowBoltTimer < diff)
            {
                Unit* target = NULL;
                target = SelectUnit(SELECT_TARGET_RANDOM,0);
                if (target)
                    DoCast(target,SPELL_SHADOWBOLT);

                ShadowBoltTimer = 3000 + (rand()%7000);
            }else ShadowBoltTimer -= diff;

            //FearTimer
            if (FearTimer < diff)
            {
                Unit* target = NULL;
                target = SelectUnit(SELECT_TARGET_RANDOM,0);
                if (target)
                    DoCast(target,SPELL_FEAR);

                FearTimer = 10000 + (rand()%10000);
            }else FearTimer -= diff;

            //Add spawning mechanism
            if (AddSpawnTimer < diff)
            {
                //Spawn 2 random types of creatures at the 2 locations
                uint32 CreatureID;
                Creature* Spawned = NULL;
                Unit* target = NULL;

                //1 in 3 chance it will be a chromatic
                if (rand()%3 == 0)
                    CreatureID = CREATURE_CHROMATIC_DRAKANOID;
                else CreatureID = DrakType1;

                ++SpawnedAdds;

                //Spawn creature and force it to start attacking a random target
                Spawned = m_creature->SummonCreature(CreatureID,ADD_X1,ADD_Y1,ADD_Z1,5.000,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,5000);
                target = SelectUnit(SELECT_TARGET_RANDOM,0);
                if (target && Spawned)
                {
                    Spawned->AI()->AttackStart(target);
                    Spawned->setFaction(103);
                }

                //1 in 3 chance it will be a chromatic
                if (rand()%3 == 0)
                    CreatureID = CREATURE_CHROMATIC_DRAKANOID;
                else CreatureID = DrakType2;

                ++SpawnedAdds;

                target = NULL;
                Spawned = NULL;
                Spawned = m_creature->SummonCreature(CreatureID,ADD_X2,ADD_Y2,ADD_Z2,5.000,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,5000);
                target = SelectUnit(SELECT_TARGET_RANDOM,0);
                if (target && Spawned)
                {
                    Spawned->AI()->AttackStart(target);
                    Spawned->setFaction(103);
                }

                //Begin phase 2 by spawning Nefarian and what not
                if (SpawnedAdds >= 42)
                {
                    //Teleport Victor Nefarius way out of the map
                    //MapManager::Instance().GetMap(m_creature->GetMapId(), m_creature)->CreatureRelocation(m_creature,0,0,-5000,0);

                    //Inturrupt any spell casting
                    m_creature->InterruptNonMeleeSpells(false);

                    //Root self
                    DoCast(m_creature,33356);

                    //Make super invis
                    DoCast(m_creature,8149);

                    //Teleport self to a hiding spot (this causes errors in the mangos log but no real issues)
                    m_creature->GetMap()->CreatureRelocation(m_creature, HIDE_X, HIDE_Y, HIDE_Z, 0.0f);
                    m_creature->SendMonsterMove(HIDE_X, HIDE_Y, HIDE_Z, 0, MONSTER_MOVE_NONE, 0);

                    //Spawn nef and have him attack a random target
                    Creature* Nefarian = m_creature->SummonCreature(CREATURE_NEFARIAN,NEF_X,NEF_Y,NEF_Z,0,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,120000);
                    target = SelectUnit(SELECT_TARGET_RANDOM,0);

                    if (target && Nefarian)
                    {
                        Nefarian->AI()->AttackStart(target);
                        Nefarian->setFaction(103);
                        NefarianGUID = Nefarian->GetGUID();
                    }
                    else error_log("SD2: Blackwing Lair: Unable to spawn nefarian properly.");
                }

                AddSpawnTimer = 4000;
            }else AddSpawnTimer -= diff;
        }
        else if (NefarianGUID)
        {
            if (NefCheckTime < diff)
            {
                Creature* pNefarian = (Creature*)Unit::GetUnit((*m_creature),NefarianGUID);

                //If nef is dead then we die to so the players get out of combat
                //and cannot repeat the event
                if (!pNefarian || !pNefarian->isAlive())
                {
                    NefarianGUID = 0;
                    m_creature->ForcedDespawn();
                }

                NefCheckTime = 2000;
            }else NefCheckTime -= diff;
        }
    }
    void UpdateAI(const uint32 diff)
    {
        if (!UpdateVictim())
            return;

            if (phase == 1)
            {
                if (FrostAura_Timer <= diff)
                {
                    DoCast(me->getVictim(),SPELL_FROST_AURA);
                    FrostAura_Timer = 5000;
                } else FrostAura_Timer -= diff;

                if (LifeDrain_Timer <= diff)
                {
                    if (Unit *pTarget = SelectUnit(SELECT_TARGET_RANDOM,0))
                        DoCast(pTarget,SPELL_LIFE_DRAIN);
                    LifeDrain_Timer = 24000;
                } else LifeDrain_Timer -= diff;

                if (Blizzard_Timer <= diff)
                {
                    if (Unit *pTarget = SelectUnit(SELECT_TARGET_RANDOM,0))
                        DoCast(pTarget,SPELL_BLIZZARD);
                    Blizzard_Timer = 20000;
                } else Blizzard_Timer -= diff;

                if (me->GetHealth()*100 / me->GetMaxHealth() > 10)
                {
                    if (Fly_Timer <= diff)
                    {
                        phase = 2;
                        me->HandleEmoteCommand(EMOTE_ONESHOT_LIFTOFF);
                        me->AddUnitMovementFlag(MOVEFLAG_LEVITATING | MOVEFLAG_ONTRANSPORT);
                        me->GetMotionMaster()->Clear(false);
                        me->GetMotionMaster()->MoveIdle();
                        me->SetHover(true);
                        Icebolt_Timer = 4000;
                        Icebolt_Count = 0;
                        IsInFly = true;
                    } else Fly_Timer -= diff;
                }
            }

                if (phase == 2)
                {
                    if (Icebolt_Timer <= diff && Icebolt_Count < 5)
                    {
                        if (Unit *pTarget = SelectUnit(SELECT_TARGET_RANDOM,0))
                        {
                            DoCast(pTarget,SPELL_ICEBOLT);
                            ++Icebolt_Count;
                            error_log("Count incremented");
                        }
                        FrostBreath_Timer = 6000;
                        Icebolt_Timer = 4000;
                    } else Icebolt_Timer -= diff;

                    if (Icebolt_Count == 5 && IsInFly && FrostBreath_Timer <= diff)
                    {
                        DoScriptText(EMOTE_BREATH, me);
                        DoCast(me->getVictim(),SPELL_FROST_BREATH);
                        land_Timer = 2000;
                        IsInFly = false;
                        FrostBreath_Timer = 6000;
                    } else FrostBreath_Timer -= diff;

                    if (!IsInFly && land_Timer <= diff)
                    {
                        phase = 1;
                        me->HandleEmoteCommand(EMOTE_ONESHOT_LAND);
                        me->RemoveUnitMovementFlag(MOVEFLAG_LEVITATING | MOVEFLAG_ONTRANSPORT);
                        me->GetMotionMaster()->Clear(false);
                        me->GetMotionMaster()->MoveChase(me->getVictim());
                        me->SetHover(true);
                        land_Timer = 0;
                        Fly_Timer = 67000;
                    } else land_Timer -= diff;
                }

                if ((me->GetHealth()*100) / me->GetMaxHealth() <= 10)
                {
                    if (Beserk_Timer <= diff)
                    {
                        DoScriptText(EMOTE_ENRAGE, me);
                        DoCast(me,SPELL_BESERK);
                        Beserk_Timer = 300000;
                    } else Beserk_Timer -= diff;
                }

                 if (phase != 2)
                     DoMeleeAttackIfReady();
    }
示例#25
0
void instance_zulaman::SetData(uint32 uiType, uint32 uiData)
{
    debug_log("SD2: Instance Zulaman: SetData received for type %u with data %u",uiType,uiData);

    switch (uiType)
    {
        case TYPE_EVENT_RUN:
            if (uiData == SPECIAL)
            {
                ++m_uiGongCount;
                if (m_uiGongCount == 5)
                    m_auiEncounter[TYPE_EVENT_RUN] = uiData;
                return;
            }
            if (uiData == IN_PROGRESS)
            {
                DoTimeRunSay(RUN_START);
                DoUseDoorOrButton(GO_MASSIVE_GATE);
                if (m_auiEncounter[TYPE_RUN_EVENT_TIME])
                    SetData(TYPE_RUN_EVENT_TIME, m_auiEncounter[TYPE_RUN_EVENT_TIME]);
                else
                    SetData(TYPE_RUN_EVENT_TIME, 60);   // 20 Minutes as default time
                DoUpdateWorldState(WORLD_STATE_ID, 1);
            }
            if (uiData == FAIL)
            {
                DoTimeRunSay(RUN_FAIL);
                DoUpdateWorldState(WORLD_STATE_ID, 0);
                // Kill remaining Event NPCs
                for (uint8 i = 0; i < MAX_CHESTS; ++i)
                {
                    // Not yet rescued, so too late
                    if (!m_aEventNpcInfo[i].uiSavePosition)
                    {
                        if (Creature* pCreature = instance->GetCreature(m_aEventNpcInfo[i].npGuid))
                            pCreature->ForcedDespawn();
                    }
                }
            }
            if (uiData == DONE)
            {
                DoTimeRunSay(RUN_DONE);
                DoUpdateWorldState(WORLD_STATE_ID, 0);
            }
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_AKILZON:
            DoUseDoorOrButton(GO_WIND_DOOR);
            if (uiData == DONE)
            {
                if (m_auiEncounter[TYPE_EVENT_RUN] == IN_PROGRESS)
                {
                    m_auiEncounter[TYPE_RUN_EVENT_TIME] += 10; // Add 10 minutes
                    SetData(TYPE_RUN_EVENT_TIME, m_auiEncounter[TYPE_RUN_EVENT_TIME]);
                    DoChestEvent(INDEX_AKILZON);
                }
            }
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_NALORAKK:
            if (uiData == DONE)
            {
                if (m_auiEncounter[TYPE_EVENT_RUN] == IN_PROGRESS)
                {
                    m_auiEncounter[TYPE_RUN_EVENT_TIME] += 15; // Add 15 minutes
                    SetData(TYPE_RUN_EVENT_TIME, m_auiEncounter[TYPE_RUN_EVENT_TIME]);
                    DoChestEvent(INDEX_NALORAKK);
                }
            }
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_JANALAI:
            if (uiData == DONE)
            {
                if (m_auiEncounter[TYPE_EVENT_RUN] == IN_PROGRESS)
                    DoChestEvent(INDEX_JANALAI);
            }
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_HALAZZI:
            DoUseDoorOrButton(GO_LYNX_TEMPLE_ENTRANCE);
            if (uiData == DONE)
            {
                DoUseDoorOrButton(GO_LYNX_TEMPLE_EXIT);
                if (m_auiEncounter[TYPE_EVENT_RUN] == IN_PROGRESS)
                    DoChestEvent(INDEX_HALAZZI);
            }
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_MALACRASS:
            DoUseDoorOrButton(GO_HEXLORD_ENTRANCE);
            if (uiData == DONE)
                DoUseDoorOrButton(GO_WOODEN_DOOR);
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_ZULJIN:
            DoUseDoorOrButton(GO_FIRE_DOOR);
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_RUN_EVENT_TIME:
            m_auiEncounter[uiType] = uiData;
            DoUpdateWorldState(WORLD_STATE_COUNTER, m_auiEncounter[uiType]);
            break;

        case TYPE_RAND_VENDOR_1:
            m_auiRandVendor[0] = uiData;
            break;
        case TYPE_RAND_VENDOR_2:
            m_auiRandVendor[1] = uiData;
            break;

        default:
            error_log("SD2: Instance Zulaman: ERROR SetData = %u for type %u does not exist/not implemented.", uiType, uiData);
            return;
    }

    if (uiData == DONE && GetKilledPreBosses() == 4 && (uiType == TYPE_AKILZON || uiType == TYPE_NALORAKK || uiType == TYPE_JANALAI || uiType == TYPE_HALAZZI))
    {
        DoUseDoorOrButton(GO_HEXLORD_ENTRANCE);
        if (m_auiEncounter[TYPE_EVENT_RUN] == IN_PROGRESS)
            SetData(TYPE_EVENT_RUN, DONE);
    }

    if (uiData == DONE || uiType == TYPE_RUN_EVENT_TIME || uiType == TYPE_EVENT_RUN)
    {
        OUT_SAVE_INST_DATA;

        std::ostringstream saveStream;
        saveStream << m_auiEncounter[0] << " " << m_auiEncounter[1] << " " << m_auiEncounter[2] << " "
            << m_auiEncounter[3] << " " << m_auiEncounter[4] << " " << m_auiEncounter[5] << " "
            << m_auiEncounter[6] << " " << m_auiEncounter[7];

        m_strInstData = saveStream.str();

        SaveToDB();
        OUT_SAVE_INST_DATA_COMPLETE;
    }
}
    void SetData(uint32 type, uint32 uiData)
    {
        switch(type)
        {
        case TYPE_HELLMAW:
            m_auiEncounter[0] = uiData;
            break;

        case TYPE_OVERSEER:
            if (uiData != DONE)
            {
                error_log("TSCR: Shadow Labyrinth: TYPE_OVERSEER did not expect other data than DONE");
                return;
            }
            if (m_uiFelOverseerCount)
            {
                --m_uiFelOverseerCount;

                if (m_uiFelOverseerCount)
                    debug_log("TSCR: Shadow Labyrinth: %u Fel Overseers left to kill.",m_uiFelOverseerCount);
                else
                {
                    m_auiEncounter[1] = DONE;
                    debug_log("TSCR: Shadow Labyrinth: TYPE_OVERSEER == DONE");
                }
            }
            break;

        case DATA_BLACKHEARTTHEINCITEREVENT:
            if (uiData == DONE)
                DoUseDoorOrButton(m_uiRefectoryDoorGUID);
            m_auiEncounter[2] = uiData;
            break;

        case DATA_GRANDMASTERVORPILEVENT:
            if (uiData == DONE)
                DoUseDoorOrButton(m_uiScreamingHallDoorGUID);
            m_auiEncounter[3] = uiData;
            break;

        case DATA_MURMUREVENT:
            m_auiEncounter[4] = uiData;
            break;
        }

        if (uiData == DONE)
        {
            if (type == TYPE_OVERSEER && m_uiFelOverseerCount != 0)
                return;

            OUT_SAVE_INST_DATA;

            std::ostringstream saveStream;
            saveStream << m_auiEncounter[0] << " " << m_auiEncounter[1] << " "
                       << m_auiEncounter[2] << " " << m_auiEncounter[3] << " " << m_auiEncounter[4];

            str_data = saveStream.str();

            SaveToDB();
            OUT_SAVE_INST_DATA_COMPLETE;
        }
    }
示例#27
0
void DoScriptText(int32 iTextEntry, WorldObject* pSource, Unit* pTarget)
{
    if (!pSource)
    {
        error_log("SD2: DoScriptText entry %i, invalid Source pointer.", iTextEntry);
        return;
    }

    if (iTextEntry >= 0)
    {
        error_log("SD2: DoScriptText with source entry %u (TypeId=%u, guid=%u) attempts to process text entry %i, but text entry must be negative.",
            pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), iTextEntry);

        return;
    }

    const StringTextData* pData = pSystemMgr.GetTextData(iTextEntry);

    if (!pData)
    {
        error_log("SD2: DoScriptText with source entry %u (TypeId=%u, guid=%u) could not find text entry %i.",
            pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), iTextEntry);

        return;
    }

    debug_log("SD2: DoScriptText: text entry=%i, Sound=%u, Type=%u, Language=%u, Emote=%u",
        iTextEntry, pData->uiSoundId, pData->uiType, pData->uiLanguage, pData->uiEmote);

    if (pData->uiSoundId)
    {
        if (GetSoundEntriesStore()->LookupEntry(pData->uiSoundId))
            pSource->PlayDirectSound(pData->uiSoundId);
        else
            error_log("SD2: DoScriptText entry %i tried to process invalid sound id %u.", iTextEntry, pData->uiSoundId);
    }

    if (pData->uiEmote)
    {
        if (pSource->GetTypeId() == TYPEID_UNIT || pSource->GetTypeId() == TYPEID_PLAYER)
            ((Unit*)pSource)->HandleEmote(pData->uiEmote);
        else
            error_log("SD2: DoScriptText entry %i tried to process emote for invalid TypeId (%u).", iTextEntry, pSource->GetTypeId());
    }

    switch(pData->uiType)
    {
        case CHAT_TYPE_SAY:
            pSource->MonsterSay(iTextEntry, pData->uiLanguage, pTarget);
            break;
        case CHAT_TYPE_YELL:
            pSource->MonsterYell(iTextEntry, pData->uiLanguage, pTarget);
            break;
        case CHAT_TYPE_TEXT_EMOTE:
            pSource->MonsterTextEmote(iTextEntry, pTarget);
            break;
        case CHAT_TYPE_BOSS_EMOTE:
            pSource->MonsterTextEmote(iTextEntry, pTarget, true);
            break;
        case CHAT_TYPE_WHISPER:
        {
            if (pTarget && pTarget->GetTypeId() == TYPEID_PLAYER)
                pSource->MonsterWhisper(iTextEntry, pTarget);
            else
                error_log("SD2: DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", iTextEntry);

            break;
        }
        case CHAT_TYPE_BOSS_WHISPER:
        {
            if (pTarget && pTarget->GetTypeId() == TYPEID_PLAYER)
                pSource->MonsterWhisper(iTextEntry, pTarget, true);
            else
                error_log("SD2: DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", iTextEntry);

            break;
        }
        case CHAT_TYPE_ZONE_YELL:
            pSource->MonsterYellToZone(iTextEntry, pData->uiLanguage, pTarget);
            break;
    }
}
示例#28
0
void instance_gundrak::SetData(uint32 uiType, uint32 uiData)
{
    debug_log("SD2: Instance Gundrak: SetData received for type %u with data %u", uiType, uiData);

    switch (uiType)
    {
        case TYPE_SLADRAN:
            m_auiEncounter[TYPE_SLADRAN] = uiData;
            if (uiData == DONE)
                if (GameObject* pGo = GetSingleGameObjectFromStorage(GO_ALTAR_OF_SLADRAN))
                    pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NO_INTERACT);
            if (uiData == FAIL)
                m_uisWhySnakesAchievPlayers.clear();
            if (uiData == SPECIAL)
                m_mAltarInProgress.insert(TypeTimerPair(TYPE_SLADRAN, TIMER_VISUAL_ALTAR));
            break;
        case TYPE_MOORABI:
            m_auiEncounter[TYPE_MOORABI] = uiData;
            if (uiData == DONE)
            {
                if (!instance->IsRegularDifficulty())
                    DoUseDoorOrButton(GO_ECK_DOOR);
                if (GameObject* pGo = GetSingleGameObjectFromStorage(GO_ALTAR_OF_MOORABI))
                    pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NO_INTERACT);
            }
            if (uiData == IN_PROGRESS)
                SetLessRabiAchievementCriteria(true);
            if (uiData == SPECIAL)
                m_mAltarInProgress.insert(TypeTimerPair(TYPE_MOORABI, TIMER_VISUAL_ALTAR));
            break;
        case TYPE_COLOSSUS:
            m_auiEncounter[TYPE_COLOSSUS] = uiData;
            if (uiData == DONE)
                if (GameObject* pGo = GetSingleGameObjectFromStorage(GO_ALTAR_OF_COLOSSUS))
                    pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NO_INTERACT);
            if (uiData == FAIL)
            {
                for (GuidSet::const_iterator itr = m_sColossusMojosGuids.begin(); itr != m_sColossusMojosGuids.end(); ++itr)
                {
                    if (Creature* pMojo = instance->GetCreature(*itr))
                    {
                        pMojo->Respawn();
                        pMojo->GetMotionMaster()->MoveTargetedHome();
                    }
                }
            }
            if (uiData == SPECIAL)
                m_mAltarInProgress.insert(TypeTimerPair(TYPE_COLOSSUS, TIMER_VISUAL_ALTAR));
            break;
        case TYPE_GALDARAH:
            m_auiEncounter[TYPE_GALDARAH] = uiData;
            DoUseDoorOrButton(GO_GALDARAH_DOOR);
            if (uiData == DONE)
            {
                DoUseDoorOrButton(GO_EXIT_DOOR_L);
                DoUseDoorOrButton(GO_EXIT_DOOR_R);
            }
            if (uiData == FAIL)
                m_uisShareLoveAchievPlayers.clear();
            break;
        case TYPE_ECK:
            m_auiEncounter[TYPE_ECK] = uiData;
            if (uiData == DONE)
                DoUseDoorOrButton(GO_ECK_UNDERWATER_DOOR);
            break;
        case TYPE_ACHIEV_WHY_SNAKES:
            // insert the players who failed the achiev and haven't been already inserted in the set
            if (m_uisWhySnakesAchievPlayers.find(uiData) == m_uisWhySnakesAchievPlayers.end())
                m_uisWhySnakesAchievPlayers.insert(uiData);
            break;
        case TYPE_ACHIEV_SHARE_LOVE:
            // insert players who got stampeled and haven't been already inserted in the set
            if (m_uisShareLoveAchievPlayers.find(uiData) == m_uisShareLoveAchievPlayers.end())
                m_uisShareLoveAchievPlayers.insert(uiData);
            break;
        default:
            error_log("SD2: Instance Gundrak: ERROR SetData = %u for type %u does not exist/not implemented.", uiType, uiData);
            return;
    }

    if (uiData == DONE || uiData == SPECIAL)                // Save activated altars, too
    {
        OUT_SAVE_INST_DATA;

        std::ostringstream saveStream;
        saveStream << m_auiEncounter[TYPE_SLADRAN] << " " << m_auiEncounter[TYPE_MOORABI] << " " << m_auiEncounter[TYPE_COLOSSUS] << " " << m_auiEncounter[TYPE_GALDARAH] << " "
                   << m_auiEncounter[TYPE_ECK];

        m_strInstData = saveStream.str();

        SaveToDB();
        OUT_SAVE_INST_DATA_COMPLETE;
    }
}
示例#29
0
    void SetData(uint32 uiType, uint32 uiData)
    {
        debug_log("SD2: Instance Nexus: SetData received for type %u with data %u", uiType, uiData);

        switch (uiType)
        {
            case TYPE_TELESTRA:
                m_auiEncounter[0] = uiData;
                if (uiData == DONE)
                {
                    if (GameObject* pGo = instance->GetGameObject(m_uiTelestrasContainmentSphereGUID))
                        pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_UNK1);
                }
                break;
            case TYPE_ANOMALUS:
                m_auiEncounter[1] = uiData;
                if (uiData == DONE)
                {
                    if (GameObject* pGo = instance->GetGameObject(m_uiAnomalusContainmentSphereGUID))
                        pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_UNK1);
                }
                break;
            case TYPE_ORMOROK:
                m_auiEncounter[2] = uiData;
                if (uiData == DONE)
                {
                    if (GameObject* pGo = instance->GetGameObject(m_uiOrmoroksContainmentSphereGUID))
                        pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_UNK1);
                }
                break;
            case TYPE_KERISTRASZA:
                m_auiEncounter[3] = uiData;
                break;
            default:
                error_log("SD2: Instance Nexus: ERROR SetData = %u for type %u does not exist/not implemented.", uiType, uiData);
                break;
        }

        if (m_auiEncounter[0] == SPECIAL && m_auiEncounter[1] == SPECIAL && m_auiEncounter[2] == SPECIAL)
        {
            // release Keristrasza from her prison here
            m_auiEncounter[3] = SPECIAL;

            if (Creature* pCreature = instance->GetCreature(m_uiKeristrazaGUID))
            {
                if (pCreature->isAlive())
                    pCreature->RemoveAurasDueToSpell(SPELL_FROZEN_PRISON);
            }
        }

        if (uiData == DONE)
        {
            OUT_SAVE_INST_DATA;

            std::ostringstream saveStream;
            saveStream << m_auiEncounter[0] << " " << m_auiEncounter[1] << " " << m_auiEncounter[2] << " " << m_auiEncounter[3];

            strInstData = saveStream.str();

            SaveToDB();
            OUT_SAVE_INST_DATA_COMPLETE;
        }
    }
void instance_black_temple::SetData(uint32 uiType, uint32 uiData)
{
    switch (uiType)
    {
        case TYPE_NAJENTUS:
            m_auiEncounter[uiType] = uiData;
            if (uiData == DONE)
                DoUseDoorOrButton(GO_NAJENTUS_GATE);
            break;
        case TYPE_SUPREMUS:
            m_auiEncounter[uiType] = uiData;
            if (uiData == DONE)
                DoUseDoorOrButton(GO_SUPREMUS_DOORS);
            break;
        case TYPE_SHADE:
            m_auiEncounter[uiType] = uiData;
            // combat door
            DoUseDoorOrButton(GO_SHADE_OF_AKAMA);
            if (uiData == FAIL)
            {
                // Reset channelers on fail
                for (GuidList::const_iterator itr = m_lChannelersGuidList.begin(); itr != m_lChannelersGuidList.end(); ++itr)
                {
                    if (Creature* pChanneler = instance->GetCreature(*itr))
                    {
                        if (!pChanneler->isAlive())
                            pChanneler->Respawn();
                        else
                            pChanneler->AI()->EnterEvadeMode();
                    }
                }
            }
            if (uiData == DONE)
                DoOpenPreMotherDoor();
            break;
        case TYPE_GOREFIEND:
            m_auiEncounter[uiType] = uiData;
            DoUseDoorOrButton(GO_GOREFIEND_DOOR);
            if (uiData == DONE)
                DoOpenPreMotherDoor();
            break;
        case TYPE_BLOODBOIL:
            m_auiEncounter[uiType] = uiData;
            if (uiData == DONE)
            {
                DoOpenPreMotherDoor();
                DoUseDoorOrButton(GO_GURTOGG_DOOR);
            }
            break;
        case TYPE_RELIQUIARY:
            m_auiEncounter[uiType] = uiData;
            if (uiData == DONE)
                DoOpenPreMotherDoor();
            break;
        case TYPE_SHAHRAZ:
            if (uiData == DONE)
                DoUseDoorOrButton(GO_POST_SHAHRAZ_DOOR);
            m_auiEncounter[uiType] = uiData;
            break;
        case TYPE_COUNCIL:
            // Don't set the same data twice
            if (m_auiEncounter[uiType] == uiData)
                return;
            DoUseDoorOrButton(GO_COUNCIL_DOOR);
            m_auiEncounter[uiType] = uiData;
            if (uiData == DONE)
                DoSpawnAkamaIfCan();
            break;
        case TYPE_ILLIDAN:
            DoUseDoorOrButton(GO_ILLIDAN_DOOR_R);
            DoUseDoorOrButton(GO_ILLIDAN_DOOR_L);
            if (uiData == FAIL)
            {
                // Cleanup encounter
                DoSpawnAkamaIfCan();
                DoUseDoorOrButton(GO_ILLIDAN_GATE);
            }
            m_auiEncounter[uiType] = uiData;
            break;
        default:
            error_log("SD2: Instance Black Temple: ERROR SetData = %u for type %u does not exist/not implemented.", uiType, uiData);
            return;
    }

    if (uiData == DONE)
    {
        OUT_SAVE_INST_DATA;

        std::ostringstream saveStream;
        saveStream << m_auiEncounter[0] << " " << m_auiEncounter[1] << " " << m_auiEncounter[2] << " "
                   << m_auiEncounter[3] << " " << m_auiEncounter[4] << " " << m_auiEncounter[5] << " "
                   << m_auiEncounter[6] << " " << m_auiEncounter[7] << " " << m_auiEncounter[8];

        m_strInstData = saveStream.str();

        SaveToDB();
        OUT_SAVE_INST_DATA_COMPLETE;
    }
}