📄 repair_citywall_processing.php
字号:
<?php
//处理城墙修复进程
$query2 = $db->query("select * from citywall_repair_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' ");
$repairing = $db->fetch_array($query2);
if($repairing['u_id']==$_COOKIE['UserId'] and $repairing['flag']=="1"){//处理当前修复任务
//花费基础表
$query=$db->query("select * from building_attribute where `b_type`='12'");
$task_base_result=$db->fetch_array($query);
$query=$db->query("select b.b_city_wall,b.b_citywall_fy,b.officer_house,b.b_citywall_status,r.rices,r.ores,r.golds,r.woods from building as b,resource as r where b.`u_id`=r.`u_id` and r.`u_id`='".$_COOKIE['UserId']."' and b.`c_id`='".$_COOKIE['CityId']."' ");
$repair_result = $db->fetch_array($query);
//算出当前已修复时间
$current_repair_time = time() - $repairing['start_time'];
//算出修复1%所需时间
$repair_time = 0.01 * ($citywall_build_time * pow(1+$citywall_build_percent,$repair_result['b_city_wall']-1));
// 加上督造斯
if($repair_result['officer_house']>="1"){
$repair_time *= 0.5;
}
if($repair_result['officer_house']>="2"){
$repair_time *= 0.6;
}
if($repair_result['officer_house']>="3"){
$repair_time *= 0.7;
}
if($repair_result['officer_house']>="4"){
for($bi=1;$bi<=$repair_result['officer_house']-3;$bi++){
$repair_time *= 0.8;
}
}
if($repair_time<1) $repair_time = 1;
$repair_time *= 60;
//算出当前修复百分比
if($repair_time)
$current_completed = (int)($current_repair_time / $repair_time);
else $current_completed=0;
$current_completed = ($current_completed < $repairing['repair_percent']) ? $current_completed : $repairing['repair_percent'];
if($current_completed>=1){
//算出1%所需资源
$repair_rices= 0.01 * ($task_base_result['b_rices'] * pow(1+$citywall_resource_percent,$repair_result['b_city_wall']-1));
$repair_irons= 0.01 * ($task_base_result['b_irons'] * pow(1+$citywall_resource_percent,$repair_result['b_city_wall']-1));
$repair_golds= 0.01 * ($task_base_result['b_golds'] * pow(1+$citywall_resource_percent,$repair_result['b_city_wall']-1));
//判断当前资源是否满足1%的修复需求
if($repair_result['rices'] < $repair_rices or $repair_result['ores'] < $repair_irons or $repair_result['golds'] < $repair_golds){
$db->query("INSERT INTO `report` ( `id` , `u_id` , `c_id` , `type` , `r_type1` , `r_type2` , `r_value` , `r_info_type` , `r_date` , `r_beizhu` )
VALUES ('', '".$_COOKIE['UserId']."', '".$_COOKIE['CityId']."', '1', '0', '0', '0', '0', '0', 'a');");
}else{
//开始修复
//算出当前资源可修复百分比
$repair1 = round($repair_result['rices'] / $repair_rices,0);
$repair2 = round($repair_result['ores'] / $repair_irons,0);
$repair3 = round($repair_result['golds'] / $repair_golds,0);
$resource_repair = min($repair1,$repair2,$repair3);
//算出最终完成修复百分比
$last_complate = min($resource_repair,$current_completed);
//算出最终消耗的资源
$repair_rices= $last_complate / 100 * ($task_base_result['b_rices'] * pow(1+$citywall_resource_percent,$repair_result['b_city_wall']-1));
$repair_irons= $last_complate / 100 * ($task_base_result['b_irons'] * pow(1+$citywall_resource_percent,$repair_result['b_city_wall']-1));
$repair_golds= $last_complate / 100 * ($task_base_result['b_golds'] * pow(1+$citywall_resource_percent,$repair_result['b_city_wall']-1));
$total_repair_resource = (int)($repair_rices + $repair_irons + $repair_golds);
//扣除资源
$db->query("update resource set `rices`=(`rices`-'".$repair_rices."'),`ores`=(`ores`-'".$repair_ores."'),`golds`=(`golds`-'".$repair_golds."'),`free_stores`=(`free_stores`-'".$total_repair_resource."') where `u_id`='".$_COOKIE['UserId']."'");
//更新城墙状态及防御值
//当前城墙等级防御初始值
//echo $citywall_fy."|".$citywall_fy_percent;exit;
//$b_citywall_fy = 500 * pow(1+$citywall_fy_percent,$repair_result['b_city_wall']-1);
$b_citywall_fy = 500*$repair_result['b_city_wall'];
$b_citywall_fy *= ($last_complate / 100);
$db->query("update building set `b_citywall_fy`=(`b_citywall_fy`+'".$b_citywall_fy."'),`b_citywall_status`=(`b_citywall_status`+'".$last_complate."') where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."'");
//更新修复任务表
if($last_complate >= $repairing['repair_percent'] or $repair_result['b_citywall_status']>=100){
//删除修复任务表
$db->query("delete from citywall_repair_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' ");
}else{
//更新任务表
$start_time = time();
$db->query("update citywall_repair_task set `repair_percent`=(`repair_percent`-'".$last_complate."'),`start_time`='".$start_time."' where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."'");
}
}
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -