Loading...   


sub EVENT_SPAWN{
	quest::gmsay("Expedition controller alive in $zonesn instver: $instanceversion instid: $instanceid", 15, 1);
	$npc->ModifyNPCStat("special_attacks", "35^19^20^24");
} 

sub EVENT_DEATH{
	quest::gmsay("Expedition controller killed in $zonesn instver: $instanceversion instid: $instanceid (This isn't supposed to happen)", 15, 1);
}

sub EVENT_SIGNAL{ 
	# quest::gmsay($npc->GetCleanName() . " recieved signal " . $signal . " in " . $zonesn . " ent var is " . plugin::REV($npc, "test_var"), 15, 1);
	use Time::HiRes qw(time);
	
	#::: Recieved Request to Sync Tasks for clients...
	if(plugin::REV($npc, "sync_expedition_task") == 1){ 
		quest::gmsay("[$zonesn exp_controller] Recieved request to task sync for expedition " . $signal, 15, 1);
		my @task_progress = split('_', plugin::REV($npc, "expedition_progress_" . $signal));
		if(plugin::REV($npc, "sync_complete_" . $signal . "_" . $task_progress[0] . "_" . $task_progress[1] . "_" . $task_progress[2]) != 1){
			# quest::gmsay("[$zonesn exp_controller] Current Expedition Task Progress is Task: $task_progress[0] Act: $task_progress[1] DC: $task_progress[2]", 15, 1);
			
			#::: Record Task progress
			$query = "REPLACE INTO `cust_ext_expedition_task_progress` (expedition_id, task_id, activity_id, done_count) VALUES (?, ?, ?, ?);";
			plugin::LoadMysql()->prepare($query)->execute($signal, $task_progress[0], $task_progress[1], $task_progress[2]); 
			
			#::: Load Expedition members if not loaded 
			if(!defined($expedition_members_loaded[$signal])){
				if(!defined($expedition_info[$signal])){
					LoadExpeditionInfo($signal);
				}
				LoadExpeditionMembers($signal);  
			} 
			
			my $n = 0;
			while($expedition_members_loaded[$signal][$n]){
				quest::gmsay("[$zonesn controller] " . $expedition_members_loaded[$signal][$n], 15, 1); 
				#::: Make sure we don't update the person who originated the propogation...
				if($expedition_members_loaded[$signal][$n] != $task_progress[3]){ 
					my $c = $entity_list->GetClientByCharID($expedition_members_loaded[$signal][$n]);  
					if($c){ 
						my $c_t_prog = $c->GetTaskActivityDoneCount($task_progress[0], $task_progress[1]);
						# quest::gmsay("task prog " . $c_t_prog, 15, 1);
						quest::gmsay("[$zonesn controller] Updating " . $c->GetCleanName() . " " . ($task_progress[2] - $c_t_prog) . " donecount via $task_progress[2] - $c_t_prog", 15, 1); 
						if($c_t_prog < $task_progress[2]){
							$c->SetEntityVariable("task_sync_time", time());
							$c->UpdateTaskActivity($task_progress[0], $task_progress[1], ($task_progress[2] - $c_t_prog)); 
						}
					}
				}
				$n++; 
			}
			plugin::SEV($npc, "sync_complete_" . $signal . "_" . $task_progress[0] . "_" . $task_progress[1] . "_" . $task_progress[2], 1);
		}
		else{ 
			quest::gmsay("[$zonesn controller] Already recieved task_sync request for sync_complete_" . $signal . "_" . $task_progress[0] . "_" . $task_progress[1] . "_" . $task_progress[2] . " ... dropping", 15, 1); 
		}
	}	
}

sub LoadExpeditionInfo{
	my $exp_id = $_[0];
	$query = "SELECT
		ID,
		inst_id,
		identifier,
		type,
		`limit`,
		task_assoc,
		inst_name,
		zonesn,
		x,
		y,
		z,
		return_zone,
		return_version,
		return_instanceid,
		return_x,
		return_y,
		return_z,
		heading,
		avglevelreq,
		req_players,
		shared_task,
		duration,
		expdate,
		lockout,
		boot_on_completion
		FROM
		cust_ext_instances
		WHERE `ID` = ?
		LIMIT 1";
	$ex = plugin::LoadMysql()->prepare($query); $ex->execute($exp_id);
	while (@row = $ex->fetchrow_array()){ 
		$n = 0;
		while($row[$n]){ push(@e_data, $row[$n]); $n++; }
		# quest::gmsay("[$zonesn controller] Loading expedition data into memory", 15, 1); 
		$expedition_info[$row[0]] = [@e_data]; 
	}
}

sub LoadExpeditionMembers{
	my $exp_id = $_[0];
	$inst_id = $expedition_info[$exp_id][1];
	my @e_data;
	# quest::gmsay("INST ID " . $expedition_info[$exp_id][1], 15, 1);
	$query = "SELECT `char_id` FROM `cust_inst_players` WHERE `inst_id` = ?";
	$ex = plugin::LoadMysql()->prepare($query); $ex->execute($inst_id);
	while (@row = $ex->fetchrow_array()){ push(@e_data, $row[0]); }
	$expedition_members_loaded[$exp_id] = [@e_data];
}

Raw Paste Data