⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soldier_educate_create_task.php

📁 Download you own three BR
💻 PHP
字号:
<?php
//士兵训练任务队列
if($_POST['action']=="soldier_educate"){
//  $get_post=Code_unpass($_POST['s_type']);
//  if (!$get_post[0]==$_COOKIE['array_code']) echomsg("非正常提交!","?");
//  setcookie("array_code","",time()-30,"/");
//	$_COOKIE['array_code']="";
//  $_POST['s_type']=$get_post[1];
//  $s_type=$get_post[1]; 
//  if ($s_type<1) echomsg("未获取到士兵列!".$get_post[0],"?");
$s_type=$_POST['s_type'];
if ($s_type<1) echomsg("未获取到士兵列!".$_POST['s_type'],"?");
  $query=$db->query("select * from study where `u_id`='".$_COOKIE['UserId']."'");
$study_result=$db->fetch_array($query);
  $query=$db->query("select b.*,c.*,r.* from building b,city c,resource as r where b.`u_id`=c.`u_id` and c.`u_id`=r.`u_id` and b.`c_id`=c.`c_id` and c.`c_id`=r.`c_id` and r.`u_id`='".$_COOKIE['UserId']."' and b.`c_id`='".$_COOKIE['CityId']."'");
$barracks_result=$db->fetch_array($query);
switch ($s_type){
  	case 1:{
  		if($barracks_result['b_barracks']<1) $flag2=0;
  		else $flag2=1;
  		break;
  	}
  	case 2:{
  		if($barracks_result['b_barracks']<2) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 3:{
  		if($barracks_result['b_barracks']<3) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 4:{
  		if($barracks_result['b_barracks']<4) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 5:{
  		if($barracks_result['b_barracks']<5) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 6:{
  		if($barracks_result['b_barracks']<6) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 7:{
  		if($barracks_result['b_barracks']<7) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 8:{
  		if($barracks_result['b_barracks']<8) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 9:{
  		if($barracks_result['b_barracks']<9) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 10:{
  		if($barracks_result['b_barracks']<10) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 11:{
  		if($barracks_result['b_barracks']<12) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 12:{
  		if($barracks_result['b_barracks']<14) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 13:{
  		if($barracks_result['b_barracks']<16) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 14:{
  		if($barracks_result['b_barracks']<18) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 15:{
  		if($barracks_result['b_barracks']<20) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 16:{
  		if($barracks_result['b_barracks']<20) $flag2=0;
  		else $flag2=1;break;
  	}
  	case 17:{
  		if($barracks_result['b_barracks']<22) $flag2=0;
  		else $flag2=1;break;
  	}
  }
  if($flag2=="0") break;


  switch ($s_type){
    	case 1:{
    		//军营1级
    		if($barracks_result['b_barracks'] >=1 ){$flag=1;}else{$flag=0;}break;
    	}
    	case 2:{
    		//军营2级、“军情刺探”1级
    		if($barracks_result['b_barracks'] >=2 and $study_result['s_army']>=1){$flag=1;}else{$flag=0;}break;
    	}
    	case 3:{
    		//军营3级、“道路地图”2级
    		if($barracks_result['b_barracks'] >=3 and $study_result['s_map']>=2){$flag=1;}else{$flag=0;}break;
    	}
    	case 4:{
    		//军营4级、“铠甲制造”3级
    		if($barracks_result['b_barracks'] >=4 and $study_result['s_loricae']>=3){$flag=1;}else{$flag=0;}break;
    	}
    	case 5:{
    		//军营5级、“武器制造”1级、“铠甲制造”1级
    		if($barracks_result['b_barracks'] >=5 and $study_result['s_arm']>=1 and $study_result['s_loricae']>=1){$flag=1;}else{$flag=0;}break;
    	}
    	case 6:{
    		//军营6级、“武器制造”3级、“铠甲制造”2级
    		if($barracks_result['b_barracks'] >=6 and $study_result['s_arm']>=3 and $study_result['s_loricae']>=2){$flag=1;}else{$flag=0;}break;
    	}
    	case 7:{
    		//军营7级、“武器制造”4级、“马匹圈养”1级
    		if($barracks_result['b_barracks'] >=7 and $study_result['s_arm']>=4  and $study_result['s_gee']>=1){$flag=1;}else{$flag=0;}break;
    	}
    	case 8:{
    		//军营8级、“机械技术”1级
    		if($barracks_result['b_barracks'] >=8 and $study_result['s_engine']>=1){$flag=1;}else{$flag=0;}break;
    	}
    	case 9:{
    		//军营9级、“机械技术”2级、“弹道技术”1级
    		if($barracks_result['b_barracks'] >=9 and $study_result['s_engine']>=2 and $study_result['s_trajectory']>=1){$flag=1;}else{$flag=0;}break;
    	}
    	case 10:{
    		//军营10级、“马匹圈养”3级
    		if($barracks_result['b_barracks'] >=10 and $study_result['s_gee']>=3){$flag=1;}else{$flag=0;}break;
    	}
    	case 11:{
    		//军营12级、“武器制造”6级、“铠甲制造”6级
    		if($barracks_result['b_barracks'] >=12 and $study_result['s_arm']>=6 and $study_result['s_loricae']>=6){$flag=1;}else{$flag=0;}break;
    	}
    	case 12:{
    		//军营14级、“铁矿精炼“2级、“防御加固”5级
    		if($barracks_result['b_barracks'] >=14 and $study_result['s_steel']>=2 and $study_result['s_recovery']>=5){$flag=1;}else{$flag=0;}break;
    	}
    	case 13:{
    		//军营16级、“铁矿精炼“6级、“马匹圈养”8级、“武器制造”8级
    		if($barracks_result['b_barracks'] >=16 and $study_result['s_steel']>=6 and $study_result['s_gee']>=8 and $study_result['s_arm']>=8){$flag=1;}else{$flag=0;}break;
    	}
    	case 14:{
    		//军营18级、“机械技术”6级、“弹道技术”5级、“铠甲制造”8级
    		if($barracks_result['b_barracks'] >=18 and $study_result['s_engine']>=6 and $study_result['s_trajectory']>=5 and $study_result['s_loricae']>=8){$flag=1;}else{$flag=0;}break;
    	}
    	case 15:{
    		//军营20级、“铁矿精炼“10级、“武器制造”10级、“铠甲制造”10级、“马匹圈养”10级
    		if($barracks_result['b_barracks'] >=20 and $study_result['s_steel']>=10 and $study_result['s_arm']>=10 and $study_result['s_loricae']>=10 and $study_result['s_gee']>=10){$flag=1;}else{$flag=0;}break;
    	}
    	case 16:{
    		//军营20级、“机械技术“8级、“弹道技术”8级、“车轮改进”6级
    		if($barracks_result['b_barracks'] >=20 and $study_result['s_engine']>=8 and $study_result['s_trajectory']>=8 and $study_result['s_wheel']>=6){$flag=1;}else{$flag=0;}break;
    	}
    	case 17:{
    		//军营22级、“机械技术“10级、“弹道技术”10级、“车轮改进”8级、“防御加固”8级
    		if($barracks_result['b_barracks'] >=22 and $study_result['s_engine']>=10 and $study_result['s_trajectory']>=10 and $study_result['s_wheel']>=8 and $study_result['s_recovery']>=8){$flag=1;}else{$flag=0;}break;
    	}
    }
    if(!$flag)echomsg("非法操作!","?");
    
  //读取用户提交的表单数据|||||||||||||||||||||||||||||||||||||||||||||||||||
  if(!eregi("^[0-9]+$",(int)trim($_POST['s_num']))) echomsg("请输入训练士兵数!","?");
  $s_num=(int)trim($_POST['s_num']);
  if(($s_num<1 or strlen($s_num)<1)) echomsg("请输入训练士兵数!","?");
  if ($produce_result['true_workers']<1) echomsg("超过人口上限!","?");
  
  //根据提交的士兵类型读取相应的所消耗资源、武器的基础值||||||||||||||||||||||||
  $query=$db->query("select * from soldier_attribute where `s_type`='".$s_type."'");
  $task_base_result=$db->fetch_array($query);

  $query=$db->query("select s_landform from study where `u_id`='".$_COOKIE['UserId']."'");
  $study_grade=$db->fetch_array($query);
  
  //计算所需粮食、时间////||||||||||||||||||||||||||||||||||||||||||||||||
  $s_rices= $s_num * $task_base_result['s_rices'];
  $s_woods= $s_num * $task_base_result['s_woods'];
  $s_irons= $s_num * $task_base_result['s_irons'];
  $s_golds= $s_num * $task_base_result['s_golds'];
    
  $geninfo=explode("|",$_POST['gen_id']);
  
  for($si=1;$si<=$s_num;$si++){  
  	$times1=$task_base_result['s_time']*60;
   if($times1<60) $s_times += 60;
   else $s_times += $times1;
  }  
  
  
  
  $s_times = $s_times * pow(0.8,$study_grade['s_landform']);
 
   
  //判断该武将是否已经在工作
  if((int)$geninfo[0]){
  $query_gen = $db->query("select gen_id from soldier_task where gen_id='".(int)$geninfo[0]."' and  `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."'");
  $gen_work = $db->fetch_array($query_gen);
  if($gen_work['gen_id']==(int)$geninfo[0]) echomsg("该武将已经在工作!","?");
  }
  //echo $s_times;exit;
//$s_times= round($task_base_result['s_time'] - $task_base_result['s_time'] * $hero_spead_time,0) * $s_num; //所需时间:以分钟为单位
  	 
  //根据武将智力算出建造提升的速度
  if($geninfo[0]){
  		
		$query=$db->query("select `g_intellect` from gen where `g_uid`='".$_COOKIE['UserId']."' and `g_cid`='".$_COOKIE['CityId']."' and `g_gid`='".(int)$geninfo[0]."';");
		$gen=$db->fetch_array($query);
		if($gen['g_intellect']){
			$intellect = $gen['g_intellect'];
			//最终时间=原始时间*(100%-智力*0.2%)
			$s_times = (int)($s_times * (1-$intellect*0.002));
		}
   }
   

  if($s_num > $barracks_space) echomsg("军营等级上限不足","?");
  
  if($barracks_result['rices'] < $s_rices) echomsg("粮食不足","?");
  if($barracks_result['golds'] < $s_golds) echomsg("黄金不足","?");
  if($barracks_result['woods'] < $s_woods) echomsg("木材不足","?");
  if($barracks_result['ores'] < $s_irons) echomsg("铁矿不足","?");
  
  //判断已经存在几个队列
  $query=$db->query("select id,s_type from soldier_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."'");
  $rn=$db->num_rows($query);
 
  if($rn>=3) echomsg("军队训练队列上限为3行!","?");
  while($rn_result = $db->fetch_array($query)){
  	if($rn_result['s_type']==$s_type) echomsg("相同兵种不能在同一个训练队列中!","?");
  }

  //扣除资源: ---  士兵训练
  $query=$db->query("update resource set `rices`=(`rices`-'".$s_rices."'),`woods`=(`woods`-'".$s_woods."'),`ores`=(`ores`-'".$s_irons."'),`golds`=(`golds`-'".$s_golds."') where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."'");

  if($query){
   	    //扣除成功,将士兵训练放入士兵训练队列表中
   	    
   	    //[用做内测加速调整]/////////////////////////////////////////////
   	    //$s_times = $s_times * $speed_percent;
   	    ////////////////////////////////////////////////////////////
   	    $s_start_time = time();
   	    
   	    $s_end_time = $s_start_time + $s_times * $speed_percent;
   	    //echo $_COOKIE['CityId'];exit;
   	    $db->query("update gen set `g_status`='5' where `g_uid`='".$_COOKIE['UserId']."' and `g_cid`='".$_COOKIE['CityId']."' and `g_gid`= '".$geninfo[0]."';");
  
   	    $query=$db->query("insert into soldier_task(`id`,`u_id`,`c_id`,`gen_id`,`gen_name`,`s_type`,`s_num`,`s_time`,`s_start_time`,`s_end_time`,`s_sort`) values('','".$_COOKIE['UserId']."','".$_COOKIE['CityId']."','".(int)$geninfo[0]."','".$geninfo[1]."','".$s_type."','".$s_num."','".$s_times."','".$s_start_time."','".$s_end_time."','')");
   	    
   	    //update_resource();
   	    refresh();
   	    if($query) echomsg("","?");
   	 }
}

//获取士兵训练任务队列
$query=$db->query("select * from soldier_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' order by id");
while($row=$db->fetch_array($query)) $current_task_list[]=$row;

//取消士兵训练队列
if($_GET['s_action']=="clear_soldier_task"){
	
    //根据提交生产的武器装备类型读取相应的所消耗资源的基础值||||||||||||||||||||||||
    $query=$db->query("select * from soldier_attribute where `s_type`='".$_GET['s_type']."'");
	$task_base_result=$db->fetch_array($query);
	
	//取得当前要取消的士兵训练任务的信息
	$query=$db->query("select * from soldier_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' and `id`='".$_GET['s_id']."'");
	$chanel_result=$db->fetch_array($query);
	
	//计算所需粮食////||||||||||||||||||||||||||||||||||||||||||||||||
	$s_rices= $chanel_result['s_num'] * $task_base_result['s_rices'];
	$s_woods= $chanel_result['s_num'] * $task_base_result['s_woods'];
	$s_irons= $chanel_result['s_num'] * $task_base_result['s_irons'];
	$s_golds= $chanel_result['s_num'] * $task_base_result['s_golds'];
	
	//取消武将工作状态
	if($chanel_result['gen_id']) $db->query("update gen set `g_status` = '0' where `g_uid`='".$_COOKIE['UserId']."' and `g_cid`='".$_COOKIE['CityId']."' and `g_gid`= '".$chanel_result['gen_id']."';");
	
	 //取消生产任务时,还原资源
   	 $query=$db->query("update resource set `rices`=(`rices`+'".$s_rices."'),`woods`=(`woods`+'".$s_woods."'),`ores`=(`ores`+'".$s_irons."'),`golds`=(`golds`+'".$s_golds."')  where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."';");

   	 
	if($current_task_list['0']['id']==$_GET['s_id']){
	$query=$db->query("select * from soldier_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' order by id limit 1,1");
					$second_result=$db->fetch_array($query);
					$query=$db->query("update soldier_task set `s_start_time`='".time()."',`s_end_time`='".(time()+$second_result['s_time'])."' where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' and `id`= '".$second_result['id']."' ");
	}
	
   	 
	$query=$db->query("delete from soldier_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$CityId."' and `id`='".$_GET['s_id']."'");
	//update_resource();
	
	refresh();
	if($query) echomsg("","?");
}


//获取当前任务的完成时间差
if($current_task_list<>"") foreach($current_task_list as $i=>$cm){
	if($cm['s_end_time']){
		$complate_time=$cm['s_end_time'];
		$remain_hours=(floor(($complate_time-time())/3600)<1) ? 0 : floor(($complate_time-time())/3600);
		$remain_minutes=(floor(($complate_time-time()-($remain_hours*3600))/60)<1) ? 0 : floor(($complate_time-time()-($remain_hours*3600))/60);
	    $remain_seconds=($complate_time-time()) - (($remain_hours*3600)  + ($remain_minutes*60));
        break;
	}
}


?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -