/**
  * Clean states for a ReportModel
  *
  * @param ReportModel $model
  */
 protected function cleanStates($model)
 {
     $key = $model->getWorkflowIdentifier();
     $result = $this->em->getRepository('Lexik\\Bundle\\WorkflowBundle\\Entity\\ModelState')->findBy(array('workflowIdentifier' => $key));
     foreach ($result as $entity) {
         $this->em->remove($entity);
     }
     $this->em->flush();
 }
예제 #2
0
 public function generatereportAction()
 {
     $reportModel = new ReportModel();
     $cdreport = $_POST["cdreport"];
     $reportNameData = $reportModel->fetchRow($reportModel->getReport($cdreport));
     $query = $this->createQuery($_POST);
     $url = "http://localhost:8080/gslabreport/ReportsGslab?report=" . $reportNameData->idreport . "&query=" . $query;
     $this->_redirect($url);
 }
예제 #3
0
 public function specific($cabinet = null)
 {
     $this->load->model('LendingModel');
     $lending = new LendingModel();
     $this->load->model('ReportModel');
     $report = new ReportModel();
     $lend = $lending->inuse($cabinet);
     if ($report->specific($lend['id'])) {
         return true;
     }
 }
예제 #4
0
파일: spy.php 프로젝트: vcelis/tatar-wars
    function handleWarSpy($taskRow, $toVillageRow, $fromVillageRow, $procInfo)
    {
        if (intval($toVillageRow['player_id']) == 0) {
            $paramsArray = explode('|', $taskRow['proc_params']);
            $paramsArray[sizeof($paramsArray) - 1] = 1;
            $newParams = implode('|', $paramsArray);
            $this->provider->executeQuery('UPDATE p_queue q
				SET
					q.player_id=%s,
					q.village_id=%s,
					q.to_player_id=%s,
					q.to_village_id=%s,
					q.proc_type=%s,
					q.proc_params=\'%s\',
					q.end_date=(q.end_date + INTERVAL q.execution_time SECOND)
				WHERE q.id=%s', array(intval($taskRow['to_player_id']), intval($taskRow['to_village_id']), intval($taskRow['player_id']), intval($taskRow['village_id']), QS_WAR_REINFORCE, $newParams, intval($taskRow['id'])));
            return TRUE;
        }
        $attackTroops = $this->_getAttackTroopsForVillage('', $procInfo['troopsArray']['troops'], 0, 0, 0, TRUE);
        $defenseTroops = array();
        $totalDefensePower = 0;
        $troops_num = trim($toVillageRow['troops_num']);
        if ($troops_num != '') {
            $vtroopsArr = explode('|', $troops_num);
            foreach ($vtroopsArr as $vtroopsStr) {
                list($tvid, $tvtroopsStr) = explode(':', $vtroopsStr);
                $incFactor = $toVillageRow['is_oasis'] && intval($toVillageRow['player_id']) == 0 && $tvid == 0 - 1 ? floor($toVillageRow['oasisElapsedTimeInSeconds'] / 86400) : 0;
                $_hasHero = FALSE;
                $vtroops = array();
                $_arr = explode(',', $tvtroopsStr);
                foreach ($_arr as $_arrStr) {
                    list($_tid, $_tnum) = explode(' ', $_arrStr);
                    if ($_tnum == 0 - 1) {
                        $_hasHero = TRUE;
                        continue;
                    }
                    $vtroops[$_tid] = $_tnum + $incFactor;
                }
                if ($tvid == 0 - 1) {
                    $hero_in_village_id = intval($this->provider->fetchScalar('SELECT p.hero_in_village_id FROM p_players p WHERE p.id=%s', array(intval($toVillageRow['player_id']))));
                    if (0 < $hero_in_village_id && $hero_in_village_id == $toVillageRow['id']) {
                        $_hasHero = TRUE;
                    }
                }
                $defenseTroops[$tvid] = $this->_getDefenseTroopsForVillage($tvid == 0 - 1 ? $toVillageRow['id'] : $tvid, $vtroops, $_hasHero, 0, 0, TRUE);
                $totalDefensePower += $defenseTroops[$tvid]['total_power'];
            }
        }
        $warResult = $this->_getSpyResult($attackTroops, $defenseTroops, $totalDefensePower);
        $reduceConsumption = $warResult['attackTroops']['total_dead_consumption'];
        if (0 < $reduceConsumption) {
            $this->_updateVillage($fromVillageRow, $reduceConsumption, FALSE);
        }
        $defenseTroopsStr = '';
        $defenseReduceConsumption = 0;
        $reportTroopTable = array();
        $tribeId = 0;
        foreach ($warResult['defenseTroops'] as $vid => $troopsTable) {
            $defenseReduceConsumption += $troopsTable['total_dead_consumption'];
            $newTroops = '';
            $thisInforcementDied = TRUE;
            foreach ($troopsTable['troops'] as $tid => $tprop) {
                if ($newTroops != '') {
                    $newTroops .= ',';
                }
                $newTroops .= $tid . ' ' . $tprop['live_number'];
                if (0 < $tprop['live_number']) {
                    $thisInforcementDied = FALSE;
                }
                $tribeId = $GLOBALS['GameMetadata']['troops'][$tid]['for_tribe_id'];
                if (!isset($reportTroopTable[$tribeId])) {
                    $reportTroopTable[$tribeId] = array('troops' => array(), 'hero' => array('number' => 0, 'dead_number' => 0));
                }
                if ($tid != 99) {
                    if (!isset($reportTroopTable[$tribeId]['troops'][$tid])) {
                        $reportTroopTable[$tribeId]['troops'][$tid] = array('number' => $tprop['number'], 'dead_number' => $tprop['number'] - $tprop['live_number']);
                        continue;
                    }
                    $reportTroopTable[$tribeId]['troops'][$tid]['number'] += $tprop['number'];
                    $reportTroopTable[$tribeId]['troops'][$tid]['dead_number'] += $tprop['number'] - $tprop['live_number'];
                    continue;
                }
            }
            if ($troopsTable['hasHero']) {
                ++$reportTroopTable[$tribeId]['hero']['number'];
                if ($vid != 0 - 1) {
                    if ($newTroops != '') {
                        $newTroops .= ',';
                    }
                    $newTroops .= $troopsTable['heroTroopId'] . ' -1';
                }
                $thisInforcementDied = FALSE;
            }
            $this->_updateVillageOutTroops($vid, $toVillageRow['id'], $newTroops, $troopsTable['hasHero'] && $troopsTable['total_live_number'] <= 0, $thisInforcementDied, intval($toVillageRow['player_id']));
            if ($vid == 0 - 1 && $toVillageRow['is_oasis']) {
                $this->provider->executeQuery('UPDATE p_villages v SET v.creation_date=NOW() WHERE v.id=%s', array(intval($toVillageRow['id'])));
            }
            if (!$thisInforcementDied || $vid == 0 - 1) {
                if ($defenseTroopsStr != '') {
                    $defenseTroopsStr .= '|';
                }
                $defenseTroopsStr .= $vid . ':' . $newTroops;
                continue;
            }
        }
        if ($toVillageRow['is_oasis'] && 0 < intval($toVillageRow['player_id']) && isset($reportTroopTable[4])) {
            unset($reportTroopTable[4]);
        }
        $this->provider->executeQuery('UPDATE p_villages v SET v.troops_num=\'%s\' WHERE v.id=%s', array($defenseTroopsStr, intval($toVillageRow['id'])));
        if (!($toVillageRow['is_oasis'] && intval($toVillageRow['player_id']) == 0)) {
            $_tovid = $toVillageRow['is_oasis'] ? intval($toVillageRow['parent_id']) : $toVillageRow['id'];
            $this->provider->executeQuery('UPDATE p_villages v SET v.crop_consumption=v.crop_consumption-%s WHERE v.id=%s', array($defenseReduceConsumption, intval($_tovid)));
        }
        $newTroops = '';
        foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
            if ($newTroops != '') {
                $newTroops .= ',';
            }
            $newTroops .= $tid . ' ' . $tprop['number'] . ' ' . ($tprop['number'] - $tprop['live_number']);
        }
        if ($procInfo['troopsArray']['hasHero']) {
            if ($newTroops != '') {
                $newTroops .= ',';
            }
            $newTroops .= 0 - 1 . ' ' . 1 . ' ' . ($warResult['all_attack_killed'] ? 1 : 0);
        }
        $attackReportTroops = $newTroops;
        $defenseReportTroops = '';
        foreach ($reportTroopTable as $tribeId => $defTroops) {
            $defenseReportTroops1 = '';
            foreach ($defTroops['troops'] as $tid => $tArr) {
                if ($defenseReportTroops1 != '') {
                    $defenseReportTroops1 .= ',';
                }
                $defenseReportTroops1 .= $tid . ' ' . $tArr['number'] . ' ' . $tArr['dead_number'];
            }
            if (0 < $defTroops['hero']['number']) {
                if ($defenseReportTroops1 != '') {
                    $defenseReportTroops1 .= ',';
                }
                $defenseReportTroops1 .= 0 - 1 . ' ' . $defTroops['hero']['number'] . ' ' . $defTroops['hero']['dead_number'];
            }
            if ($defenseReportTroops1 != '') {
                if ($defenseReportTroops != '') {
                    $defenseReportTroops .= '#';
                }
                $defenseReportTroops .= $defenseReportTroops1;
                continue;
            }
        }
        $harvestInfo = '';
        $harvestResources = '';
        $spyType = $procInfo['spyAction'];
        if (!$warResult['all_spy_killed']) {
            if ($spyType == 1) {
                $harvestResources = '0 0 0 0';
                if (!$toVillageRow['is_oasis']) {
                    $resources_info = array();
                    $r_arr = explode(',', $toVillageRow['resources']);
                    foreach ($r_arr as $r_str) {
                        $r2 = explode(' ', $r_str);
                        $prate = floor($r2[4] * (1 + $r2[5] / 100)) - ($r2[0] == 4 ? $toVillageRow['crop_consumption'] : 0);
                        $current_value = floor($r2[1] + $toVillageRow['elapsedTimeInSeconds'] * ($prate / 3600));
                        if ($r2[2] < $current_value) {
                            $current_value = $r2[2];
                        }
                        $resources_info[] = $current_value;
                    }
                    $harvestResources = implode(' ', $resources_info);
                }
            }
            if ($spyType == 2) {
                if (!$toVillageRow['is_oasis']) {
                    $buildingsInfo = array();
                    $bStr = trim($toVillageRow['buildings']);
                    if ($bStr != '') {
                        $bStrArr = explode(',', $bStr);
                        $_i = 0;
                        foreach ($bStrArr as $b2Str) {
                            ++$_i;
                            if ($_i < 19) {
                                continue;
                            }
                            list($item_id, $level, $update_state) = explode(' ', $b2Str);
                            if (0 < $level) {
                                $buildingsInfo[] = $item_id . ' ' . $level;
                                continue;
                            }
                        }
                    }
                    if (0 < sizeof($buildingsInfo)) {
                        $_randIndex = mt_rand(0, sizeof($buildingsInfo) - 1);
                        $harvestInfo = $buildingsInfo[$_randIndex];
                    }
                }
            }
        } else {
            $spyType = 3;
        }
        $timeInSeconds = $taskRow['remainingTimeInSeconds'];
        if (!$warResult['defense_has_spytroops']) {
            $reportResult = 100;
        } else {
            $reportResult = $warResult['all_spy_killed'] ? 9 : 10;
        }
        $reportCategory = 4;
        $reportBody = $attackReportTroops . '|' . $defenseReportTroops . '|' . $harvestResources . '|' . $harvestInfo . '|' . $spyType;
        $r = new ReportModel();
        $reportId = $r->createReport(intval($fromVillageRow['player_id']), intval($toVillageRow['player_id']), intval($fromVillageRow['id']), intval($toVillageRow['id']), $reportCategory, $reportResult, $reportBody, $timeInSeconds);
        if (!$warResult['defense_has_spytroops'] && $toVillageRow['player_id'] != $fromVillageRow['player_id']) {
            $r->deleteReport(intval($taskRow['to_player_id']), $reportId);
        }
        if (!$warResult['all_attack_killed']) {
            $paramsArray = explode('|', $taskRow['proc_params']);
            $paramsArray[sizeof($paramsArray) - 1] = 1;
            $newTroops = '';
            foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
                if ($newTroops != '') {
                    $newTroops .= ',';
                }
                $newTroops .= $tid . ' ' . $tprop['live_number'];
            }
            if (!$warResult['all_attack_killed'] && $procInfo['troopsArray']['hasHero']) {
                if ($newTroops != '') {
                    $newTroops .= ',';
                }
                $newTroops .= $procInfo['troopsArray']['heroTroopId'] . ' -1';
            }
            $paramsArray[0] = $newTroops;
            $newParams = implode('|', $paramsArray);
            $this->provider->executeQuery('UPDATE p_queue q
				SET
					q.player_id=%s,
					q.village_id=%s,
					q.to_player_id=%s,
					q.to_village_id=%s,
					q.proc_type=%s,
					q.proc_params=\'%s\',
					q.end_date=(q.end_date + INTERVAL q.execution_time SECOND)
				WHERE q.id=%s', array(intval($taskRow['to_player_id']), intval($taskRow['to_village_id']), intval($taskRow['player_id']), intval($taskRow['village_id']), QS_WAR_REINFORCE, $newParams, intval($taskRow['id'])));
            return TRUE;
        }
        return FALSE;
    }
<?php

require '../modelo/ReportModel.php';
ReportModel::usersReport();
?>

예제 #6
0
    function handleReInforcement($taskRow, $toVillageRow, $fromVillageRow, $procInfo, $troopsArrStr)
    {
        if ($procInfo['troopBack']) {
            if (0 < intval($toVillageRow['player_id']) && $taskRow['to_player_id'] == intval($toVillageRow['player_id'])) {
                $paramsArray = explode('|', $taskRow['proc_params']);
                $res = array(0, 0, 0, 0);
                if (trim($paramsArray[4]) != '') {
                    $res = explode(' ', $paramsArray[4]);
                }
                $k = 0;
                $r_arr = explode(',', $toVillageRow['resources']);
                foreach ($r_arr as $r_str) {
                    $r2 = explode(' ', $r_str);
                    $resources[$r2[0]] = array('current_value' => $r2[2] < $r2[1] + $res[$k] ? $r2[2] : $r2[1] + $res[$k], 'store_max_limit' => $r2[2], 'store_init_limit' => $r2[3], 'prod_rate' => $r2[4], 'prod_rate_percentage' => $r2[5]);
                    ++$k;
                }
                $resourcesStr = '';
                foreach ($resources as $k => $v) {
                    if ($resourcesStr != '') {
                        $resourcesStr .= ',';
                    }
                    $resourcesStr .= sprintf('%s %s %s %s %s %s', $k, $v['current_value'], $v['store_max_limit'], $v['store_init_limit'], $v['prod_rate'], $v['prod_rate_percentage']);
                }
                $this->provider->executeQuery('UPDATE p_villages v  SET v.troops_num=\'%s\', v.resources=\'%s\' WHERE v.id=%s', array($this->_getNewTroops($toVillageRow['troops_num'], $procInfo['troopsArray'], 0 - 1, $toVillageRow['player_id'] == $fromVillageRow['player_id'] && !$toVillageRow['is_oasis']), $resourcesStr, intval($toVillageRow['id'])));
                if ($procInfo['troopsArray']['hasHero']) {
                    $this->provider->executeQuery('UPDATE p_players p SET p.hero_in_village_id=%s WHERE p.id=%s', array(intval($toVillageRow['id']), intval($toVillageRow['player_id'])));
                }
            } else {
                if ($procInfo['troopsArray']['hasHero']) {
                    $this->provider->executeQuery('UPDATE p_players p SET p.hero_in_village_id=NULL, hero_troop_id=NULL WHERE p.id=%s', array(intval($toVillageRow['player_id'])));
                }
            }
        } else {
            if (0 < intval($toVillageRow['player_id'])) {
                $allegiance_percent = intval($toVillageRow['allegiance_percent']);
                if ($toVillageRow['is_oasis'] && $allegiance_percent < 100) {
                    $allegiance_percent += 15;
                    if (100 < $allegiance_percent) {
                        $allegiance_percent = 100;
                    }
                    $this->provider->executeQuery('UPDATE p_villages v SET v.allegiance_percent=%s WHERE v.id=%s', array($allegiance_percent, intval($toVillageRow['id'])));
                }
                $affectCropConsumption = TRUE;
                if ($toVillageRow['is_oasis'] && trim($fromVillageRow['village_oases_id']) != '') {
                    $oArr = explode(',', trim($fromVillageRow['village_oases_id']));
                    foreach ($oArr as $oid) {
                        if ($oid == $taskRow['to_village_id']) {
                            $affectCropConsumption = FALSE;
                            break;
                        }
                    }
                }
                $this->_addTroopsToVillage($toVillageRow, $fromVillageRow, $procInfo['troopsArray'], $affectCropConsumption);
                if ($procInfo['troopsArray']['hasHero'] && $toVillageRow['player_id'] == $fromVillageRow['player_id'] && !$toVillageRow['is_oasis']) {
                    $this->provider->executeQuery('UPDATE p_players p SET p.hero_in_village_id=%s WHERE p.id=%s', array(intval($toVillageRow['id']), intval($toVillageRow['player_id'])));
                }
                $timeInSeconds = $taskRow['remainingTimeInSeconds'];
                $reportResult = 8;
                $reportCategory = 2;
                $troopsCropConsumption = $procInfo['troopsArray']['cropConsumption'];
                $reportBody = $troopsArrStr . '|' . $troopsCropConsumption;
                $r = new ReportModel();
                $r->createReport(intval($taskRow['player_id']), intval($taskRow['to_player_id']), intval($taskRow['village_id']), intval($taskRow['to_village_id']), $reportCategory, $reportResult, $reportBody, $timeInSeconds);
                return FALSE;
            }
            $paramsArray = explode('|', $taskRow['proc_params']);
            $paramsArray[sizeof($paramsArray) - 1] = 1;
            $newParams = implode('|', $paramsArray);
            $this->provider->executeQuery('UPDATE p_queue q
					SET
						q.player_id=%s,
						q.village_id=%s,
						q.to_player_id=%s,
						q.to_village_id=%s,
						q.proc_type=%s,
						q.proc_params=\'%s\',
						q.end_date=(q.end_date + INTERVAL q.execution_time SECOND)
					WHERE q.id=%s', array(intval($taskRow['to_player_id']), intval($taskRow['to_village_id']), intval($taskRow['player_id']), intval($taskRow['village_id']), QS_WAR_REINFORCE, $newParams, intval($taskRow['id'])));
            return TRUE;
        }
        return FALSE;
    }
<?php

require '../modelo/ReportModel.php';
ReportModel::reservesReport();
?>

<?php

require '../modelo/ReportModel.php';
ReportModel::reservesNoConfirmReport();
?>

예제 #9
0
 public function executeMerchantTask($taskRow)
 {
     $villageRow = $this->provider->fetchRow("SELECT\r\n\t\t\t\tv.player_id,\r\n\t\t\t\tv.resources,\r\n\t\t\t\tv.cp,\r\n\t\t\t\tv.crop_consumption,\r\n\t\t\t\tTIME_TO_SEC(TIMEDIFF(NOW(), v.last_update_date)) elapsedTimeInSeconds \r\n\t\t\tFROM p_villages v\r\n\t\t\tWHERE v.id=%s", array(intval($taskRow['to_village_id'])));
     if (0 < intval($villageRow['player_id'])) {
         $resultArr = $this->_getResourcesArray($villageRow['resources'], $villageRow['elapsedTimeInSeconds'], $villageRow['crop_consumption'], $villageRow['cp']);
         $resourcesStr = explode("|", $taskRow['proc_params']);
         $merchantNum = explode("|", $taskRow['proc_params']);
         list($merchantNum, $resourcesStr) = $merchantNum;
         $resources = explode(" ", $resourcesStr);
         $i = 0;
         foreach ($resources as $v) {
             $resultArr['resources'][++$i]['current_value'] += $v;
             if ($resultArr['resources'][$i]['store_max_limit'] < $resultArr['resources'][$i]['current_value']) {
                 $resultArr['resources'][$i]['current_value'] = $resultArr['resources'][$i]['store_max_limit'];
             }
         }
         $this->provider->executeQuery("UPDATE p_villages v \r\n\t\t\t\tSET\r\n\t\t\t\t\tv.resources='%s',\r\n\t\t\t\t\tv.cp='%s',\r\n\t\t\t\t\tv.last_update_date=NOW()\r\n\t\t\t\tWHERE v.id=%s", array($this->_getResourcesString($resultArr['resources']), $resultArr['cp']['cpValue'] . " " . $resultArr['cp']['cpRate'], intval($taskRow['to_village_id'])));
     }
     if (intval($this->provider->fetchScalar("SELECT v.player_id FROM p_villages v WHERE v.id=%s", array(intval($taskRow['village_id'])))) == 0) {
         return FALSE;
     }
     $this->provider->executeQuery("UPDATE p_queue q \r\n\t\t\tSET \r\n\t\t\t\tq.proc_type=%s,\r\n\t\t\t\tq.end_date=(q.end_date + INTERVAL q.execution_time SECOND)\r\n\t\t\tWHERE q.id=%s", array(QS_MERCHANT_BACK, intval($taskRow['id'])));
     $timeInSeconds = $taskRow['remainingTimeInSeconds'];
     $body = explode("|", $taskRow['proc_params']);
     $merchantsNum = explode("|", $taskRow['proc_params']);
     list($merchantsNum, $body) = $merchantsNum;
     $res = explode(" ", $body);
     $maxValue = 0;
     $maxIndex = 0 - 1;
     $n = 0;
     foreach ($res as $v) {
         ++$n;
         if ($maxValue < $v) {
             $maxValue = $v;
             $maxIndex = $n;
         }
     }
     $reportResult = 10 + $maxIndex;
     $r = new ReportModel();
     $r->createReport($taskRow['player_id'], $taskRow['to_player_id'], $taskRow['village_id'], $taskRow['to_village_id'], 1, $reportResult, $body, $timeInSeconds);
     return TRUE;
 }
예제 #10
0
 public static function patientDiagnosis()
 {
     return ReportModel::patientDiagnosis(ReportController::getGender());
 }
예제 #11
0
 public function load()
 {
     parent::load();
     $this->showList = !(isset($_GET['id']) && 0 < intval($_GET['id']));
     $this->selectedTabIndex = $this->showList && isset($_GET['t']) && is_numeric($_GET['t']) && 1 <= intval($_GET['t']) && intval($_GET['t']) <= 4 ? intval($_GET['t']) : 0;
     $m = new ReportModel();
     if (!$this->isPost()) {
         if (!$this->showList) {
             $this->selectedTabIndex = 0;
             $reportId = intval($_GET['id']);
             $result = $m->getReport($reportId);
             if ($result->next()) {
                 $readStatus = $result->row['read_status'];
                 $deleteStatus = $result->row['delete_status'];
                 $this->reportData = array();
                 $this->reportData['messageDate'] = $result->row['mdate'];
                 $this->reportData['messageTime'] = $result->row['mtime'];
                 $this->reportData['from_player_id'] = $from_player_id = intval($result->row['from_player_id']);
                 $this->reportData['to_player_id'] = $to_player_id = intval($result->row['to_player_id']);
                 $this->reportData['from_village_id'] = intval($result->row['from_village_id']);
                 $this->reportData['to_village_id'] = intval($result->row['to_village_id']);
                 $this->reportData['from_player_name'] = $result->row['from_player_name'];
                 $this->reportData['to_player_name'] = $result->row['to_player_name'];
                 $this->reportData['to_village_name'] = $result->row['to_village_name'];
                 $this->reportData['from_village_name'] = $result->row['from_village_name'];
                 $this->reportData['rpt_body'] = $result->row['rpt_body'];
                 $this->reportData['rpt_cat'] = $result->row['rpt_cat'];
                 $this->reportData['mdate'] = $result->row['mdate'];
                 $this->reportData['mtime'] = $result->row['mtime'];
                 $this->reportData['to_player_alliance_id'] = $m->getPlayerAllianceId($to_player_id);
                 switch ($this->reportData['rpt_cat']) {
                     case 1:
                         $this->reportData['resources'] = explode(" ", $this->reportData['rpt_body']);
                         break;
                     case 2:
                         $troopsStr = explode("|", $this->reportData['rpt_body']);
                         list($troopsStr) = $troopsStr;
                         $this->reportData['troopsTable'] = array("troops" => array(), "hasHero" => FALSE);
                         $troopsStrArr = explode(",", $troopsStr);
                         foreach ($troopsStrArr as $t) {
                             $tnum = explode(" ", $t);
                             $tid = explode(" ", $t);
                             list($tid, $tnum) = $tid;
                             if ($tnum == 0 - 1) {
                                 $this->reportData['troopsTable']['hasHero'] = TRUE;
                             } else {
                                 $this->reportData['troopsTable']['troops'][$tid] = $tnum;
                             }
                         }
                         break;
                     case 3:
                         $bodyArr = explode("|", $this->reportData['rpt_body']);
                         $harvestResources = $bodyArr;
                         $total_carry_load = $bodyArr;
                         $defenseTableTroopsStr = $bodyArr;
                         $attackTroopsStr = $bodyArr;
                         list($attackTroopsStr, $defenseTableTroopsStr, $total_carry_load, $harvestResources) = $attackTroopsStr;
                         $wallDestructionResult = isset($bodyArr[4]) ? $bodyArr[4] : "";
                         $catapultResult = isset($bodyArr[5]) ? $bodyArr[5] : "";
                         $oasisResult = isset($bodyArr[6]) ? $bodyArr[6] : "";
                         $captureResult = isset($bodyArr[7]) ? $bodyArr[7] : "";
                         $this->reportData['total_carry_load'] = $total_carry_load;
                         $this->reportData['total_harvest_carry_load'] = 0;
                         $this->reportData['harvest_resources'] = array();
                         $res = explode(" ", $harvestResources);
                         foreach ($res as $r) {
                             $this->reportData['total_harvest_carry_load'] += $r;
                             $this->reportData['harvest_resources'][] = $r;
                         }
                         $attackTroopsStrArr = explode(",", $attackTroopsStr);
                         $this->reportData['attackTroopsTable'] = array("troops" => array(), "heros" => array("number" => 0, "dead_number" => 0));
                         $totalAttackTroops_live = 0;
                         $totalAttackTroops_dead = 0;
                         $attackWallDestrTroopId = 0;
                         $attackCatapultTroopId = 0;
                         $kingTroopId = 0;
                         foreach ($attackTroopsStrArr as $s) {
                             $deadNum = explode(" ", $s);
                             $num = explode(" ", $s);
                             $tid = explode(" ", $s);
                             list($tid, $num, $deadNum) = $tid;
                             $totalAttackTroops_live += $num;
                             $totalAttackTroops_dead += $deadNum;
                             if ($tid == 7 || $tid == 17 || $tid == 27 || $tid == 106 || $tid == 57) {
                                 $attackWallDestrTroopId = $tid;
                             } else {
                                 if ($tid == 8 || $tid == 18 || $tid == 28 || $tid == 107 || $tid == 58) {
                                     $attackCatapultTroopId = $tid;
                                 } else {
                                     if ($tid == 9 || $tid == 19 || $tid == 29 || $tid == 108 || $tid == 59) {
                                         $kingTroopId = $tid;
                                     }
                                 }
                             }
                             if ($tid == 0 - 1) {
                                 $this->reportData['attackTroopsTable']['heros']['number'] = $num;
                                 $this->reportData['attackTroopsTable']['heros']['dead_number'] = $deadNum;
                             } else {
                                 $this->reportData['attackTroopsTable']['troops'][$tid] = array("number" => $num, "dead_number" => $deadNum);
                             }
                         }
                         $this->reportData['all_attackTroops_dead'] = $totalAttackTroops_live <= $totalAttackTroops_dead;
                         $this->reportData['defenseTroopsTable'] = array();
                         $troopsTableStrArr = trim($defenseTableTroopsStr) == "" ? array() : explode("#", $defenseTableTroopsStr);
                         $j = 0 - 1;
                         foreach ($troopsTableStrArr as $defenseTableTroopsStr2) {
                             ++$j;
                             $defenseTroopsStrArr = explode(",", $defenseTableTroopsStr2);
                             $this->reportData['defenseTroopsTable'][$j] = array("troops" => array(), "heros" => array("number" => 0, "dead_number" => 0));
                             foreach ($defenseTroopsStrArr as $s) {
                                 $deadNum = explode(" ", $s);
                                 $num = explode(" ", $s);
                                 $tid = explode(" ", $s);
                                 list($tid, $num, $deadNum) = $tid;
                                 if ($tid == 0 - 1) {
                                     $this->reportData['defenseTroopsTable'][$j]['heros']['number'] = $num;
                                     $this->reportData['defenseTroopsTable'][$j]['heros']['dead_number'] = $deadNum;
                                 } else {
                                     $this->reportData['defenseTroopsTable'][$j]['troops'][$tid] = array("number" => $num, "dead_number" => $deadNum);
                                 }
                             }
                         }
                         if ($captureResult != "") {
                             $wstr = "";
                             if ($captureResult == "+") {
                                 $wstr = report_p_villagecaptured;
                             } else {
                                 $warr = explode("-", $captureResult);
                                 $wstr = report_p_allegiancelowered . " " . $warr[0] . " " . report_p_to . " " . $warr[1];
                             }
                             if ($wstr != "") {
                                 $wstr = "<img src=\"assets/x.gif\" class=\"unit u" . $kingTroopId . "\" align=\"center\" /> " . $wstr;
                             }
                             $this->reportData['captureResult'] = $wstr;
                         }
                         if ($oasisResult != "") {
                             $wstr = "";
                             if ($oasisResult == "+") {
                                 $wstr = report_p_oasiscaptured;
                             } else {
                                 $warr = explode("-", $oasisResult);
                                 $wstr = report_p_allegiancelowered . " " . $warr[0] . " " . report_p_to . " " . $warr[1];
                             }
                             if ($wstr != "") {
                                 $wstr = "<img src=\"assets/x.gif\" class=\"unit uhero\" align=\"center\" /> " . $wstr;
                             }
                             $this->reportData['oasisResult'] = $wstr;
                         }
                         if ($wallDestructionResult != "") {
                             $wstr = "";
                             if ($wallDestructionResult == "-") {
                                 $wstr = report_p_wallnotdestr;
                             } else {
                                 if ($wallDestructionResult == "+") {
                                     $wstr = report_p_nowall;
                                 } else {
                                     $warr = explode("-", $wallDestructionResult);
                                     if (intval($warr[1]) == 0) {
                                         $wstr = report_p_walldestr;
                                     }
                                     $wstr = report_p_walllowered . " " . $warr[0] . " " . report_p_to . " " . $warr[1];
                                 }
                             }
                             if ($wstr != "") {
                                 $wstr = "<img src=\"assets/x.gif\" class=\"unit u" . $attackWallDestrTroopId . "\" align=\"center\" /> " . $wstr;
                             }
                             $this->reportData['wallDestructionResult'] = $wstr;
                         }
                         if ($catapultResult != "") {
                             $bdestArr = array();
                             if ($catapultResult == "+") {
                                 $bdestArr[] = "<img src=\"assets/x.gif\" class=\"unit u" . $attackCatapultTroopId . "\" align=\"center\" /> " . report_p_totallydestr;
                             } else {
                                 $catapultResultArr = explode("#", $catapultResult);
                                 foreach ($catapultResultArr as $catapultResultInfo) {
                                     $toLevel = explode(" ", $catapultResultInfo);
                                     $fromLevel = explode(" ", $catapultResultInfo);
                                     $itemId = explode(" ", $catapultResultInfo);
                                     list($itemId, $fromLevel, $toLevel) = $itemId;
                                     if ($toLevel == 0 - 1) {
                                         $bdestArr[] = "<img src=\"assets/x.gif\" class=\"unit u" . $attackCatapultTroopId . "\" align=\"center\" /> " . report_p_notdestr . " " . constant("item_" . $itemId);
                                     } else {
                                         if ($toLevel == 0) {
                                             $bdestArr[] = "<img src=\"assets/x.gif\" class=\"unit u" . $attackCatapultTroopId . "\" align=\"center\" /> " . report_p_wasdestr . " " . constant("item_" . $itemId);
                                         } else {
                                             $bdestArr[] = "<img src=\"assets/x.gif\" class=\"unit u" . $attackCatapultTroopId . "\" align=\"center\" /> " . report_p_waslowered . " " . constant("item_" . $itemId) . " " . report_p_fromlevel . " " . $fromLevel . " " . report_p_to . " " . $toLevel;
                                         }
                                     }
                                 }
                             }
                             $this->reportData['buildingDestructionResult'] = $bdestArr;
                         }
                         break;
                     case 4:
                         $spyType = explode("|", $this->reportData['rpt_body']);
                         $harvestInfo = explode("|", $this->reportData['rpt_body']);
                         $harvestResources = explode("|", $this->reportData['rpt_body']);
                         $defenseTableTroopsStr = explode("|", $this->reportData['rpt_body']);
                         $attackTroopsStr = explode("|", $this->reportData['rpt_body']);
                         list($attackTroopsStr, $defenseTableTroopsStr, $harvestResources, $harvestInfo, $spyType) = $attackTroopsStr;
                         if (trim($harvestResources) != "" && $spyType == 1) {
                             $this->reportData['harvest_resources'] = explode(" ", trim($harvestResources));
                         }
                         if (trim($harvestInfo) != "" && $spyType == 2) {
                             $level = explode(" ", $harvestInfo);
                             $itemId = explode(" ", $harvestInfo);
                             list($itemId, $level) = $itemId;
                             $this->reportData['harvest_info'] = constant("item_" . $itemId) . " " . level_lang . " " . $level;
                         }
                         $this->reportData['all_spy_dead'] = FALSE;
                         if ($spyType == 3) {
                             $this->reportData['all_spy_dead'] = TRUE;
                             $this->reportData['harvest_info'] = report_p_allkilled;
                         }
                         $attackTroopsStrArr = explode(",", $attackTroopsStr);
                         $this->reportData['attackTroopsTable'] = array("troops" => array(), "heros" => array("number" => 0, "dead_number" => 0));
                         foreach ($attackTroopsStrArr as $s) {
                             $deadNum = explode(" ", $s);
                             $num = explode(" ", $s);
                             $tid = explode(" ", $s);
                             list($tid, $num, $deadNum) = $tid;
                             if ($tid == 0 - 1) {
                                 $this->reportData['attackTroopsTable']['heros']['number'] = $num;
                                 $this->reportData['attackTroopsTable']['heros']['dead_number'] = $deadNum;
                             } else {
                                 $this->reportData['attackTroopsTable']['troops'][$tid] = array("number" => $num, "dead_number" => $deadNum);
                             }
                         }
                         $this->reportData['defenseTroopsTable'] = array();
                         $troopsTableStrArr = trim($defenseTableTroopsStr) == "" ? array() : explode("#", $defenseTableTroopsStr);
                         $j = 0 - 1;
                         foreach ($troopsTableStrArr as $defenseTableTroopsStr2) {
                             ++$j;
                             $defenseTroopsStrArr = explode(",", $defenseTableTroopsStr2);
                             $this->reportData['defenseTroopsTable'][$j] = array("troops" => array(), "heros" => array("number" => 0, "dead_number" => 0));
                             foreach ($defenseTroopsStrArr as $s) {
                                 $deadNum = explode(" ", $s);
                                 $num = explode(" ", $s);
                                 $tid = explode(" ", $s);
                                 list($tid, $num, $deadNum) = $tid;
                                 if ($tid == 0 - 1) {
                                     $this->reportData['defenseTroopsTable'][$j]['heros']['number'] = $num;
                                     $this->reportData['defenseTroopsTable'][$j]['heros']['dead_number'] = $deadNum;
                                 } else {
                                     $this->reportData['defenseTroopsTable'][$j]['troops'][$tid] = array("number" => $num, "dead_number" => $deadNum);
                                 }
                             }
                         }
                 }
                 $isDeleted = FALSE;
                 if (!$isDeleted) {
                     $canOpenReport = TRUE;
                     if ($this->player->playerId != $from_player_id && $this->player->playerId != $to_player_id) {
                         $canOpenReport = 0 < intval($this->data['alliance_id']) && ($this->data['alliance_id'] == $m->getPlayerAllianceId($to_player_id) || $this->data['alliance_id'] == $m->getPlayerAllianceId($from_player_id));
                     }
                     if ($canOpenReport) {
                         if (!$this->player->isSpy) {
                             if ($to_player_id == $this->player->playerId) {
                                 if ($readStatus == 0 || $readStatus == 2) {
                                     $m->markReportAsReaded($this->player->playerId, $to_player_id, $reportId, $readStatus);
                                     --$this->data['new_report_count'];
                                 }
                             } else {
                                 if ($from_player_id == $this->player->playerId && ($readStatus == 0 || $readStatus == 1)) {
                                     $m->markReportAsReaded($this->player->playerId, $to_player_id, $reportId, $readStatus);
                                     --$this->data['new_report_count'];
                                 }
                             }
                         }
                     } else {
                         $this->showList = TRUE;
                     }
                 } else {
                     $this->showList = TRUE;
                 }
             } else {
                 $this->showList = TRUE;
             }
             $result->free();
         }
     } else {
         if (isset($_POST['dr']) && isset($_POST['dr'])) {
             foreach ($_POST['dr'] as $reportId) {
                 if ($m->deleteReport($this->player->playerId, $reportId)) {
                     --$this->data['new_report_count'];
                 }
             }
         }
     }
     if ($this->showList) {
         $rowsCount = $m->getReportListCount($this->player->playerId, $this->selectedTabIndex);
         $this->pageCount = 0 < $rowsCount ? ceil($rowsCount / $this->pageSize) : 1;
         $this->pageIndex = isset($_GET['p']) && is_numeric($_GET['p']) && intval($_GET['p']) < $this->pageCount ? intval($_GET['p']) : 0;
         $this->dataList = $m->getReportList($this->player->playerId, $this->selectedTabIndex, $this->pageIndex, $this->pageSize);
         if (0 < $this->data['new_report_count']) {
             $this->data['new_report_count'] = $m->syncReports($this->player->playerId);
         }
     }
     $m->dispose();
 }
예제 #12
0
파일: war.php 프로젝트: vcelis/tatar-wars
    function handleWarAttack($taskRow, $toVillageRow, $fromVillageRow, $procInfo)
    {
        global $GameMetadata, $SetupMetadata;
        if (!$toVillageRow['is_oasis'] && intval($toVillageRow['player_id']) == 0) {
            $paramsArray = explode('|', $taskRow['proc_params']);
            $paramsArray[sizeof($paramsArray) - 1] = 1;
            $newParams = implode('|', $paramsArray);
            $this->provider->executeQuery('UPDATE p_queue q 
				SET 
					q.player_id=%s,
					q.village_id=%s,
					q.to_player_id=%s,
					q.to_village_id=%s,
					q.proc_type=%s,
					q.proc_params=\'%s\',
					q.end_date=(q.end_date + INTERVAL q.execution_time SECOND)
				WHERE q.id=%s', array(intval($taskRow['to_player_id']), intval($taskRow['to_village_id']), intval($taskRow['player_id']), intval($taskRow['village_id']), QS_WAR_REINFORCE, $newParams, intval($taskRow['id'])));
            return TRUE;
        }
        $heroLevel = array('att' => 0, 'deff' => 0, 'heroTroopId' => -1);
        if ($procInfo['troopsArray']['hasHero']) {
            $_row = $this->provider->fetchRow('SELECT p.hero_att, p.hero_deff, p.hero_troop_id FROM p_players p WHERE p.id=%s', array(intval($fromVillageRow['player_id'])));
            if ($_row != NULL) {
                $heroLevel['att'] = intval($_row['hero_att']);
                $heroLevel['deff'] = intval($_row['hero_deff']);
                $heroLevel['heroTroopId'] = intval($_row['hero_troop_id']);
            }
        }
        $heroBuildingLevel = 0;
        $wringerLevel = 0;
        $buildings = array();
        $bStr = trim($fromVillageRow['buildings']);
        if ($bStr != '') {
            $bStrArr = explode(',', $bStr);
            foreach ($bStrArr as $b2Str) {
                list($item_id, $level, $update_state) = explode(' ', $b2Str);
                if ($item_id == 35) {
                    $wringerLevel = $level;
                } else {
                    if ($item_id == 37) {
                        $heroBuildingLevel = $level;
                    } else {
                        if ($item_id == 27) {
                            $TreasuryLevel = $level;
                        }
                    }
                }
            }
        }
        $attackTroops = $this->_getAttackTroopsForVillage($fromVillageRow['troops_training'], $procInfo['troopsArray']['troops'], $heroLevel, $wringerLevel, FALSE);
        $buildinStabilityFactor = 1;
        $crannyTotalSize = 0;
        $palLevel = 0;
        $wallPower = 0;
        $wallLevel = 0;
        $wallBid = 0;
        $wallItemId = 0;
        $buildings = array();
        $bStr = trim($toVillageRow['buildings']);
        if ($bStr != '') {
            $bStrArr = explode(',', $bStr);
            $fcc = 0;
            foreach ($bStrArr as $b2Str) {
                ++$fcc;
                list($item_id, $level, $update_state) = explode(' ', $b2Str);
                if ($item_id == 31 || $item_id == 32 || $item_id == 33) {
                    $wallBid = $fcc;
                    $wallItemId = $item_id;
                    $wallLevel = $level;
                    $wallPower = $level > 0 ? $GameMetadata['items'][$item_id]['levels'][$level - 1]['value'] : 0;
                } else {
                    if ($item_id == 23 && $level > 0) {
                        $crannyTotalSize += $GameMetadata['items'][$item_id]['levels'][$level - 1]['value'] * $GameMetadata['items'][$item_id]['for_tribe_id'][$toVillageRow['tribe_id']];
                    } else {
                        if ($item_id == 34 && $level > 0) {
                            $buildinStabilityFactor = $GameMetadata['items'][$item_id]['levels'][$level - 1]['value'] / 100;
                        } else {
                            if ($item_id == 26 && $level > 0) {
                                $palLevel = $level;
                            }
                        }
                    }
                }
            }
        }
        $crannyTotalSize = floor($crannyTotalSize * $GameMetadata['tribes'][$fromVillageRow['tribe_id']]['crannyFactor']);
        $buildinStability = 1;
        $crannySize = 0;
        $crannyTotalSize = floor($crannyTotalSize * $GameMetadata['tribes'][$fromVillageRow['tribe_id']]['crannyFactor']);
        $defenseTroops = array();
        $totalDefensePower['infantry_power'] = $totalDefensePower['cavalry_power'] = 0;
        $troops_num = trim($toVillageRow['troops_num']);
        if ($troops_num != '') {
            $vtroopsArr = explode('|', $troops_num);
            foreach ($vtroopsArr as $vtroopsStr) {
                list($tvid, $tvtroopsStr) = explode(':', $vtroopsStr);
                $incFactor = $toVillageRow['is_oasis'] && intval($toVillageRow['player_id']) == 0 && $tvid == -1 ? floor($toVillageRow['oasisElapsedTimeInSeconds'] / 86400) : 0;
                $_hasHero = FALSE;
                $vtroops = array();
                $_arr = explode(',', $tvtroopsStr);
                foreach ($_arr as $_arrStr) {
                    list($_tid, $_tnum) = explode(' ', $_arrStr);
                    if ($_tnum == -1) {
                        $_hasHero = TRUE;
                    } else {
                        $vtroops[$_tid] = $_tnum + $incFactor;
                    }
                }
                if ($tvid == -1) {
                    $hero_in_village_id = intval($this->provider->fetchScalar('SELECT p.hero_in_village_id FROM p_players p WHERE p.id=%s', array(intval($toVillageRow['player_id']))));
                    if ($hero_in_village_id > 0 && $hero_in_village_id == $toVillageRow['id']) {
                        $_hasHero = TRUE;
                    }
                }
                $defenseTroops[$tvid] = $this->_getDefenseTroopsForVillage($tvid == -1 ? $toVillageRow['id'] : $tvid, $vtroops, $_hasHero, $toVillageRow['people_count'], $wallPower, FALSE);
                $totalDefensePower['infantry_power'] += $defenseTroops[$tvid]['infantry_power'];
                $totalDefensePower['cavalry_power'] += $defenseTroops[$tvid]['cavalry_power'];
            }
        }
        $warResult = $this->getWarResult($attackTroops, $defenseTroops, $totalDefensePower, $wallLevel, $palLevel, $taskRow['proc_type'] == QS_WAR_ATTACK_PLUNDER, $procInfo['troopsArray']['onlyHero'] ? TRUE : FALSE);
        $harvestResources = '0 0 0 0';
        $harvestInfoStruct = array('string' => $harvestResources, 'sum' => 0);
        if (!$warResult['all_attack_killed']) {
            $harvestInfoStruct = $this->_harvestTroopsFrom($toVillageRow, $warResult['attackTroops']['total_carry_load'], $crannyTotalSize);
            $harvestResources = $harvestInfoStruct['string'];
        }
        $reduceConsumption = $warResult['attackTroops']['total_dead_consumption'];
        if ($warResult['all_attack_killed'] && $procInfo['troopsArray']['hasHero']) {
            $reduceConsumption += $GameMetadata['troops'][$procInfo['troopsArray']['heroTroopId']]['crop_consumption'];
        }
        if ($reduceConsumption > 0) {
            $this->_updateVillage($fromVillageRow, $reduceConsumption, $warResult['all_attack_killed'] && $procInfo['troopsArray']['hasHero']);
        }
        if ($procInfo['troopsArray']['hasHero'] && $warResult['defense_total_dead_number'] >= 1) {
            $heroStatisticPoint = ceil(5 * $warResult['defense_total_dead_number'] / 100);
            $this->provider->executeQuery('UPDATE p_players p SET p.hero_points=p.hero_points+%s WHERE p.id=%s', array($heroStatisticPoint, intval($fromVillageRow['player_id'])));
        }
        $defenseTroopsStr = '';
        $defenseReduceConsumption = 0;
        $reportTroopTable = array();
        $villages = array();
        $tribeId = 0;
        foreach ($warResult['defenseTroops'] as $vid => $troopsTable) {
            $defenseReduceConsumption += $troopsTable['total_dead_consumption'];
            $newTroops = '';
            $thisInforcementDied = TRUE;
            foreach ($troopsTable['troops'] as $tid => $tprop) {
                if ($newTroops != '') {
                    $newTroops .= ',';
                }
                $newTroops .= $tid . ' ' . $tprop['live_number'];
                if ($tprop['live_number'] > 0) {
                    $thisInforcementDied = FALSE;
                }
                if ($tid != 99) {
                    if ($vid != -1) {
                        if (!isset($villages[$vid])) {
                            $villages[$vid] = array('troops' => array(), 'hero' => array('number' => 0, 'dead_number' => 0));
                        }
                        if (!isset($villages[$vid]['troops'][$tid])) {
                            $villages[$vid]['troops'][$tid] = array('number' => $tprop['number'], 'dead_number' => $tprop['number'] - $tprop['live_number']);
                        } else {
                            $villages[$vid]['troops'][$tid]['number'] += $tprop['number'];
                            $villages[$vid]['troops'][$tid]['dead_number'] += $tprop['number'] - $tprop['live_number'];
                        }
                    }
                    $tribeId = $GameMetadata['troops'][$tid]['for_tribe_id'];
                    if (!isset($reportTroopTable[$tribeId])) {
                        $reportTroopTable[$tribeId] = array('troops' => array(), 'hero' => array('number' => 0, 'dead_number' => 0));
                    }
                    if (!isset($reportTroopTable[$tribeId]['troops'][$tid])) {
                        $reportTroopTable[$tribeId]['troops'][$tid] = array('number' => $tprop['number'], 'dead_number' => $tprop['number'] - $tprop['live_number']);
                    } else {
                        $reportTroopTable[$tribeId]['troops'][$tid]['number'] += $tprop['number'];
                        $reportTroopTable[$tribeId]['troops'][$tid]['dead_number'] += $tprop['number'] - $tprop['live_number'];
                    }
                }
            }
            if ($troopsTable['hasHero']) {
                $reportTroopTable[$tribeId]['hero']['number']++;
                if ($vid != -1) {
                    $villages[$vid]['hero']['number']++;
                }
            }
            if ($troopsTable['total_live_number'] > 0 && $troopsTable['hasHero']) {
                if ($vid != -1) {
                    if ($newTroops != '') {
                        $newTroops .= ',';
                    }
                    $newTroops .= $troopsTable['heroTroopId'] . ' -1';
                }
                if ($vid == -1 && !$toVillageRow['is_oasis'] && $warResult['attackTroops']['total_dead_number'] > 0) {
                    $heroStatisticPoint = ceil(5 * $warResult['attackTroops']['total_dead_number'] / 100);
                    $this->provider->executeQuery('UPDATE p_players p SET p.hero_points=p.hero_points+%s WHERE p.id=%s', array($heroStatisticPoint, intval($toVillageRow['player_id'])));
                }
                $thisInforcementDied = FALSE;
            }
            if ($troopsTable['hasHero'] && $troopsTable['total_live_number'] <= 0) {
                $reportTroopTable[$tribeId]['hero']['dead_number']++;
                if ($vid != -1) {
                    $villages[$vid]['hero']['dead_number']++;
                }
                $defenseReduceConsumption += $GameMetadata['troops'][$troopsTable['heroTroopId']]['crop_consumption'];
            }
            $this->_updateVillageOutTroops($vid, $toVillageRow['id'], $newTroops, $troopsTable['hasHero'] && $troopsTable['total_live_number'] <= 0, $thisInforcementDied, intval($toVillageRow['player_id']));
            if ($vid == -1 && $toVillageRow['is_oasis']) {
                $this->provider->executeQuery('UPDATE p_villages v SET v.creation_date=NOW() WHERE v.id=%s', array(intval($toVillageRow['id'])));
            }
            if (!$thisInforcementDied || $vid == -1) {
                if ($defenseTroopsStr != '') {
                    $defenseTroopsStr .= '|';
                }
                $defenseTroopsStr .= $vid . ':' . $newTroops;
            }
        }
        if ($toVillageRow['is_oasis'] && intval($toVillageRow['player_id']) > 0 && isset($reportTroopTable[4])) {
            unset($reportTroopTable[4]);
        }
        $this->provider->executeQuery('UPDATE p_villages v SET v.troops_num=\'%s\' WHERE v.id=%s', array($defenseTroopsStr, $toVillageRow['id']));
        if (!($toVillageRow['is_oasis'] && intval($toVillageRow['player_id']) == 0)) {
            $_tovid = $toVillageRow['is_oasis'] ? intval($toVillageRow['parent_id']) : $toVillageRow['id'];
            $this->provider->executeQuery('UPDATE p_villages v SET v.crop_consumption=v.crop_consumption-%s WHERE v.id=%s', array($defenseReduceConsumption, intval($_tovid)));
        }
        $villageTotallyDestructed = FALSE;
        $wallDestructionResult = '';
        $catapultResult = '';
        if (!$toVillageRow['is_oasis'] && !$warResult['all_attack_killed'] && $taskRow['proc_type'] != QS_WAR_ATTACK_PLUNDER) {
            $wallDestrTroopsCount = 0;
            $buildDestrTroopsCount = 0;
            foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
                if ($tid == 7 || $tid == 17 || $tid == 27 || $tid == 57) {
                    $wallDestrTroopsCount = $tprop['number'];
                } else {
                    if ($tid == 8 || $tid == 18 || $tid == 28 || $tid == 58) {
                        $buildDestrTroopsCount = $tprop['number'];
                    }
                }
            }
            if ($procInfo['troopsArray']['hasWallDest']) {
                if ($wallLevel > 0) {
                    $dropLevels = 0;
                    if (2 * $wallPower < $wallDestrTroopsCount) {
                        $dropLevels = floor($wallDestrTroopsCount / (2 * $wallPower));
                        if ($wallLevel - $dropLevels < 0) {
                            $dropLevels = $wallLevel;
                        }
                    }
                    if ($dropLevels > 0) {
                        $wallDestructionResult = $wallLevel . '-' . ($wallLevel - $dropLevels);
                        $wallLevel -= $dropLevels;
                        $mq = new QueueJobModel();
                        while (0 < $dropLevels--) {
                            $mq->upgradeBuilding($toVillageRow['id'], $wallBid, $wallItemId, TRUE);
                        }
                    } else {
                        $wallDestructionResult = '-';
                    }
                } else {
                    $wallDestructionResult = '+';
                }
            }
            if (trim($procInfo['catapultTarget']) != '') {
                $catapultTargetArr = explode(':', $procInfo['catapultTarget']);
                $catapultTargetArr = explode(' ', $catapultTargetArr[1]);
                $buildingsInfo = array();
                $bStr = trim($toVillageRow['buildings']);
                if ($bStr != '') {
                    $bStrArr = explode(',', $bStr);
                    $_i = 0;
                    foreach ($bStrArr as $b2Str) {
                        ++$_i;
                        list($item_id, $level, $update_state) = explode(' ', $b2Str);
                        if ($item_id == 31 || $item_id == 32 || $item_id == 33) {
                            continue;
                        }
                        if ($level > 0) {
                            $buildingsInfo[] = array('id' => $_i, 'item_id' => $item_id, 'level' => $level);
                        }
                    }
                }
                $catapultTargetInfoArr = array();
                if (sizeof($buildingsInfo) > 0) {
                    foreach ($catapultTargetArr as $catapultTargetItemId) {
                        $targetExists = FALSE;
                        foreach ($buildingsInfo as $bInfo) {
                            if ($catapultTargetItemId == $bInfo['item_id']) {
                                $catapultTargetInfoArr[] = $bInfo;
                                $targetExists = TRUE;
                                break;
                                break;
                            }
                        }
                        if (!$targetExists) {
                            $_randIndex = mt_rand(0, sizeof($buildingsInfo) - 1);
                            $catapultTargetInfoArr[] = $buildingsInfo[$_randIndex];
                        }
                    }
                }
                if (sizeof($catapultTargetInfoArr) > 0) {
                    if (sizeof($catapultTargetInfoArr) > 1 && $catapultTargetInfoArr[0]['id'] == $catapultTargetInfoArr[1]['id']) {
                        $tmp = $catapultTargetInfoArr[0];
                        $catapultTargetInfoArr = array();
                        $catapultTargetInfoArr[] = $tmp;
                    }
                    $buildDestrTroopsCount = floor($buildDestrTroopsCount / sizeof($catapultTargetInfoArr));
                    foreach ($catapultTargetInfoArr as $catapultTargetInfoItem) {
                        if ($catapultResult != '') {
                            $catapultResult .= '#';
                        }
                        $canDestructBuilding = $catapultTargetInfoItem['level'] * $buildinStabilityFactor * 4 <= $buildDestrTroopsCount;
                        if ($canDestructBuilding) {
                            $dropBuildingLevels = floor($buildDestrTroopsCount / ($catapultTargetInfoItem['level'] * $buildinStabilityFactor * 4));
                            if ($catapultTargetInfoItem['level'] - $dropBuildingLevels < 0) {
                                $dropBuildingLevels = $catapultTargetInfoItem['level'];
                            }
                            $catapultResult .= $catapultTargetInfoItem['item_id'] . ' ' . $catapultTargetInfoItem['level'] . ' ' . ($catapultTargetInfoItem['level'] - $dropBuildingLevels);
                            $mq = new QueueJobModel();
                            while (0 < $dropBuildingLevels--) {
                                $mq->upgradeBuilding($toVillageRow['id'], $catapultTargetInfoItem['id'], $catapultTargetInfoItem['item_id'], TRUE);
                            }
                        } else {
                            $catapultResult .= $catapultTargetInfoItem['item_id'] . ' ' . $catapultTargetInfoItem['level'] . ' -1';
                        }
                    }
                }
                if (!$toVillageRow['is_capital'] && !$toVillageRow['is_special_village']) {
                    $checkToVillageRow = $this->_getVillageInfo($taskRow['to_village_id']);
                    $villageTotallyDestructed = TRUE;
                    $bStr = trim($checkToVillageRow['buildings']);
                    if ($bStr != '') {
                        $bStrArr = explode(',', $bStr);
                        $_i = 0;
                        foreach ($bStrArr as $b2Str) {
                            ++$_i;
                            list($item_id, $level, $update_state) = explode(' ', $b2Str);
                            if ($level > 0) {
                                $villageTotallyDestructed = FALSE;
                                break;
                            }
                        }
                    }
                    if ($villageTotallyDestructed) {
                        $catapultResult = '+';
                        $this->leaveVillage($toVillageRow['id'], $toVillageRow['player_id'], 0, $toVillageRow['parent_id']);
                    }
                }
            }
        }
        $doTroopsBack = TRUE;
        $villageCaptured = FALSE;
        $captureResult = '';
        if ($procInfo['troopsArray']['hasKing'] && !$toVillageRow['is_oasis'] && !$warResult['all_attack_killed'] && $taskRow['proc_type'] != QS_WAR_ATTACK_PLUNDER && !$toVillageRow['is_capital'] && !$villageTotallyDestructed && $warResult['all_defense_killed'] && $toVillageRow['player_id'] != $fromVillageRow['player_id'] && !$toVillageRow['is_artefacts']) {
            $checkToVillageRow = $this->_getVillageInfo($taskRow['to_village_id']);
            $b25_26_exists = FALSE;
            $bStr = trim($checkToVillageRow['buildings']);
            if ($bStr != '') {
                $bStrArr = explode(',', $bStr);
                foreach ($bStrArr as $b2Str) {
                    list($item_id, $level, $update_state) = explode(' ', $b2Str);
                    if ($level > 0 && ($item_id == 25 || $item_id == 26)) {
                        $b25_26_exists = TRUE;
                        break;
                    }
                }
            }
            $kingIsLive = FALSE;
            foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
                if ($tid == 9 || $tid == 19 || $tid == 29) {
                    $kingIsLive = $tprop['live_number'] > 0;
                    break;
                }
            }
            if ($kingIsLive && $b25_26_exists) {
                $captureResult = '#';
            }
            if ($kingIsLive && !$b25_26_exists) {
                $elapsedTimeInSeconds = $toVillageRow['elapsedTimeInSeconds'];
                $addValue = $elapsedTimeInSeconds * 10 / 3600;
                $total = round($toVillageRow['allegiance_percent'] + $addValue);
                $allegiancepercent = $total < 100 ? $total : 100;
                $minusAllgeriance = $fromVillageRow['tribe_id'] == 1 ? mt_rand(25, 30) : mt_rand(20, 25);
                $allegiance_percent = $allegiancepercent - round($minusAllgeriance * (1 - $wringerLevel / 100));
                if ($allegiance_percent > 0) {
                    $this->provider->executeQuery('UPDATE p_villages v SET v.allegiance_percent=%s, v.last_update_date=NOW() WHERE v.id=%s', array($allegiance_percent, intval($toVillageRow['id'])));
                    $captureResult = $allegiancepercent . '-' . $allegiance_percent;
                } else {
                    $allegiance_percent = 0;
                    $captureResult = '+';
                }
                if ($allegiance_percent == 0) {
                    $villageCaptured = TRUE;
                    $kingCropConumption = 0;
                    $doTroopsBack = FALSE;
                    foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
                        if ($tid == 9 || $tid == 19 || $tid == 29) {
                            $kingCropConumption = $GameMetadata['troops'][$tid]['crop_consumption'];
                            break;
                        }
                        if ($tprop['live_number'] > 0) {
                            $doTroopsBack = TRUE;
                        }
                    }
                    $toCheckPeople = $this->provider->fetchScalar('SELECT v.people_count FROM p_villages v WHERE v.id=%s', array($toVillageRow['id']));
                    $this->leaveVillage($toVillageRow['id'], $toVillageRow['player_id'], $toCheckPeople, $toVillageRow['parent_id'], FALSE);
                    $this->captureVillage($toVillageRow, $fromVillageRow, $kingCropConumption);
                }
            }
        }
        $oasisResult = '';
        if ($procInfo['troopsArray']['hasHero'] && $toVillageRow['is_oasis'] && !$warResult['all_attack_killed'] && $warResult['all_defense_killed'] && $toVillageRow['player_id'] != $fromVillageRow['player_id'] && 10 <= $heroBuildingLevel) {
            $canCaptureOasis = FALSE;
            $numberOfOwnedOases = trim($fromVillageRow['village_oases_id']) == '' ? 0 : sizeof(explode(',', $fromVillageRow['village_oases_id']));
            if ($heroBuildingLevel == 20) {
                $canCaptureOasis = $numberOfOwnedOases < 3;
            } else {
                if (15 <= $heroBuildingLevel) {
                    $canCaptureOasis = $numberOfOwnedOases < 2;
                } else {
                    if (10 <= $heroBuildingLevel) {
                        $canCaptureOasis = $numberOfOwnedOases < 1;
                    }
                }
            }
            $oasisInRang = FALSE;
            $rang = 3;
            $map_size = $SetupMetadata['map_size'];
            $x = $fromVillageRow['rel_x'];
            $y = $fromVillageRow['rel_y'];
            $mi = -$rang;
            while ($mi <= $rang) {
                if ($oasisInRang) {
                    break;
                }
                $mj = -$rang;
                while ($mj <= $rang) {
                    if ($toVillageRow['id'] == $this->__getVillageId($map_size, $this->__getCoordInRange($map_size, $x + $mi), $this->__getCoordInRange($map_size, $y + $mj))) {
                        $oasisInRang = TRUE;
                        break;
                    }
                    ++$mj;
                }
                ++$mi;
            }
            if ($canCaptureOasis && $oasisInRang) {
                $qm = new QueueJobModel();
                if (intval($toVillageRow['player_id']) == 0) {
                    $oasisResult = '+';
                    $qm->captureOasis($toVillageRow['id'], $fromVillageRow['player_id'], $fromVillageRow['id'], TRUE);
                } else {
                    $allegiance_percent = $toVillageRow['allegiance_percent'];
                    $allegiance_percent -= 25;
                    if ($allegiance_percent > 0) {
                        $oasisResult = $toVillageRow['allegiance_percent'] . '-' . $allegiance_percent;
                        $this->provider->executeQuery('UPDATE p_villages v SET v.allegiance_percent=%s WHERE v.id=%s', array($allegiance_percent, intval($toVillageRow['id'])));
                    } else {
                        $allegiance_percent = 0;
                        $oasisResult = '+';
                    }
                    if ($allegiance_percent == 0) {
                        $qm->captureOasis($toVillageRow['id'], $toVillageRow['player_id'], $toVillageRow['parent_id'], FALSE);
                        $qm->captureOasis($toVillageRow['id'], $fromVillageRow['player_id'], $fromVillageRow['id'], TRUE);
                    }
                }
            }
        }
        $artefactResult = '';
        if ($procInfo['troopsArray']['hasHero'] && $toVillageRow['artefacts'] != '' && !$warResult['all_attack_killed'] && $warResult['all_defense_killed'] && $toVillageRow['player_id'] != $fromVillageRow['player_id'] && 10 <= $TreasuryLevel) {
            $checkToVillageRow = $this->_getVillageInfo($taskRow['to_village_id']);
            $b27_exists = FALSE;
            $bStr = trim($checkToVillageRow['buildings']);
            if ($bStr != '') {
                $bStrArr = explode(',', $bStr);
                foreach ($bStrArr as $b2Str) {
                    list($item_id, $level, $update_state) = explode(' ', $b2Str);
                    if ($level > 0 && $item_id == 27) {
                        $b27_exists = TRUE;
                        break;
                    }
                }
            }
            if ($b27_exists) {
                $artefactResult = 'X';
            }
            if (!$b27_exists) {
                list($type, $effect) = explode(' ', $toVillageRow['artefacts']);
                if ($TreasuryLevel >= 10 && $effect == 2) {
                    if ($fromVillageRow['artefacts'] != '') {
                        $artefactResult = '#';
                    } else {
                        $this->captureArtefact($toVillageRow, $fromVillageRow);
                        $artefactResult = '+';
                    }
                } else {
                    if ($TreasuryLevel == 20 && $effect == 1) {
                        if ($fromVillageRow['artefacts'] != '') {
                            $artefactResult = '#';
                        } else {
                            $this->captureArtefact($toVillageRow, $fromVillageRow);
                            $artefactResult = '+';
                        }
                    } else {
                        $artefactResult = '-';
                    }
                }
            }
        }
        $newTroops = '';
        foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
            if ($newTroops != '') {
                $newTroops .= ',';
            }
            $newTroops .= $tid . ' ' . $tprop['number'] . ' ' . ($tprop['number'] - $tprop['live_number']);
        }
        if ($procInfo['troopsArray']['hasHero']) {
            if ($newTroops != '') {
                $newTroops .= ',';
            }
            $newTroops .= -1 . ' ' . 1 . ' ' . ($warResult['all_attack_killed'] ? 1 : 0);
        }
        $attackReportTroops = $newTroops;
        $defenseReportTroops = '';
        foreach ($reportTroopTable as $tribeId => $defTroops) {
            $defenseReportTroops1 = '';
            if ($tribeId == 4) {
                $monsterTroops = array();
                foreach ($GameMetadata['troops'] as $t4k => $t4v) {
                    if ($t4v['for_tribe_id'] == 4) {
                        $monsterTroops[$t4k] = array('number' => isset($defTroops['troops'][$t4k]) ? $defTroops['troops'][$t4k]['number'] : 0, 'dead_number' => isset($defTroops['troops'][$t4k]) ? $defTroops['troops'][$t4k]['dead_number'] : 0);
                    }
                }
                $defTroops['troops'] = $monsterTroops;
            }
            foreach ($defTroops['troops'] as $tid => $tArr) {
                if ($defenseReportTroops1 != '') {
                    $defenseReportTroops1 .= ',';
                }
                $defenseReportTroops1 .= $tid . ' ' . $tArr['number'] . ' ' . $tArr['dead_number'];
            }
            if ($defTroops['hero']['number'] > 0) {
                if ($defenseReportTroops1 != '') {
                    $defenseReportTroops1 .= ',';
                }
                $defenseReportTroops1 .= -1 . ' ' . $defTroops['hero']['number'] . ' ' . $defTroops['hero']['dead_number'];
            }
            if ($defenseReportTroops1 != '') {
                if ($defenseReportTroops != '') {
                    $defenseReportTroops .= '#';
                }
                $defenseReportTroops .= $defenseReportTroops1;
            }
        }
        $timeInSeconds = $taskRow['remainingTimeInSeconds'];
        $attackDigit = 0;
        $defenseDigit = 0;
        if ($warResult['all_attack_killed']) {
            $attackDigit = 3;
            $defenseDigit = $warResult['defense_total_dead_number'] > 0 ? 5 : 4;
        } else {
            $attackDigit = $warResult['attackTroops']['total_dead_number'] > 0 ? 2 : 1;
            $defenseDigit = $warResult['defense_total_dead_number'] > 0 ? 6 : 7;
        }
        $reportResult = $defenseDigit * 10 + $attackDigit;
        $reportCategory = 3;
        $reportBody = $attackReportTroops . '|' . $defenseReportTroops . '|' . $warResult['attackTroops']['total_carry_load'] . '|' . $harvestResources . '|' . $wallDestructionResult . '|' . $catapultResult . '|' . $oasisResult . '|' . $captureResult . '|' . $artefactResult;
        $r = new ReportModel();
        $r->createReport(intval($fromVillageRow['player_id']), intval($toVillageRow['player_id']), intval($fromVillageRow['id']), intval($toVillageRow['id']), $reportCategory, $reportResult, $reportBody, $timeInSeconds);
        foreach ($villages as $vID => $vTroops) {
            $defenseReportTroops2 = '';
            $playerID = $this->provider->fetchScalar('SELECT v.player_id FROM p_villages v WHERE v.id=%s', array(intval($vID)));
            if ($playerID != NULL) {
                foreach ($vTroops['troops'] as $tid => $tArr) {
                    if ($defenseReportTroops2 != '') {
                        $defenseReportTroops2 .= ',';
                    }
                    $defenseReportTroops2 .= $tid . ' ' . $tArr['number'] . ' ' . $tArr['dead_number'];
                }
                if ($vTroops['hero']['number'] > 0) {
                    if ($defenseReportTroops2 != '') {
                        $defenseReportTroops2 .= ',';
                    }
                    $defenseReportTroops2 .= -1 . ' ' . $vTroops['hero']['number'] . ' ' . $vTroops['hero']['dead_number'];
                }
                $r->createReport('', intval($playerID), '', intval($toVillageRow['id']), 5, 62, $defenseReportTroops2, $taskRow['remainingTimeInSeconds']);
            }
        }
        if (intval($toVillageRow['player_id']) != intval($fromVillageRow['player_id'])) {
            $statisticPoint = 0;
            $harvestPoint = $harvestInfoStruct['sum'];
            if (intval($toVillageRow['player_id']) > 0 && intval($toVillageRow['tribe_id']) != 5) {
                $statisticPoint = $warResult['attackTroops']['total_dead_number'];
                $this->provider->executeQuery('UPDATE p_players p SET p.defense_points=p.defense_points+%s, p.week_defense_points=p.week_defense_points+%s WHERE p.id=%s', array($statisticPoint, $statisticPoint, intval($toVillageRow['player_id'])));
            }
            if (intval($fromVillageRow['player_id']) > 0 && intval($toVillageRow['tribe_id']) != 5) {
                $statisticPoint = $warResult['defense_total_dead_number'];
                $this->provider->executeQuery('UPDATE p_players p SET p.attack_points=p.attack_points+%s, p.week_attack_points=p.week_attack_points+%s, p.week_thief_points=p.week_thief_points+%s WHERE p.id=%s', array($statisticPoint, $statisticPoint, $harvestPoint, intval($fromVillageRow['player_id'])));
            }
            if (intval($toVillageRow['alliance_id']) > 0) {
                $statisticPoint = $warResult['attackTroops']['total_dead_number'];
                $this->provider->executeQuery('UPDATE p_alliances p SET p.rating=p.rating+%s, p.defense_points=p.defense_points+%s, p.week_defense_points=p.week_defense_points+%s WHERE p.id=%s', array($statisticPoint, $statisticPoint, $statisticPoint, intval($toVillageRow['alliance_id'])));
            }
            if (intval($fromVillageRow['alliance_id']) > 0) {
                $statisticPoint = $warResult['defense_total_dead_number'];
                $this->provider->executeQuery('UPDATE p_alliances p SET p.rating=p.rating+%s, p.attack_points=p.attack_points+%s, p.week_attack_points=p.week_attack_points+%s, p.week_thief_points=p.week_thief_points+%s WHERE p.id=%s', array($statisticPoint, $statisticPoint, $statisticPoint, $harvestPoint, intval($fromVillageRow['alliance_id'])));
            }
        }
        if (!$warResult['all_attack_killed'] && $doTroopsBack) {
            $paramsArray = explode('|', $taskRow['proc_params']);
            $paramsArray[sizeof($paramsArray) - 1] = 1;
            $newTroops = '';
            foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
                if ($newTroops != '') {
                    $newTroops .= ',';
                }
                if ($villageCaptured && ($tid == 9 || $tid == 19 || $tid == 29)) {
                    $tprop['live_number'] = 0;
                }
                $newTroops .= $tid . ' ' . $tprop['live_number'];
            }
            if (!$warResult['all_attack_killed'] && $procInfo['troopsArray']['hasHero']) {
                if ($newTroops != '') {
                    $newTroops .= ',';
                }
                $newTroops .= $procInfo['troopsArray']['heroTroopId'] . ' -1';
            }
            $paramsArray[0] = $newTroops;
            $paramsArray[4] = $harvestResources;
            $newParams = implode('|', $paramsArray);
            $this->provider->executeQuery('UPDATE p_queue q 
				SET 
					q.player_id=%s,
					q.village_id=%s,
					q.to_player_id=%s,
					q.to_village_id=%s,
					q.proc_type=%s,
					q.proc_params=\'%s\',
					q.end_date=(q.end_date + INTERVAL q.execution_time SECOND)
				WHERE q.id=%s', array(intval($taskRow['to_player_id']), intval($taskRow['to_village_id']), intval($taskRow['player_id']), intval($taskRow['village_id']), QS_WAR_REINFORCE, $newParams, intval($taskRow['id'])));
            return TRUE;
        }
        return FALSE;
    }
예제 #13
0
 public function handleWarAttack($taskRow, $toVillageRow, $fromVillageRow, $procInfo)
 {
     $GameMetadata = $GLOBALS['GameMetadata'];
     $SetupMetadata = $GLOBALS['SetupMetadata'];
     if (!$toVillageRow['is_oasis'] && intval($toVillageRow['player_id']) == 0) {
         $paramsArray = explode("|", $taskRow['proc_params']);
         $paramsArray[sizeof($paramsArray) - 1] = 1;
         $newParams = implode("|", $paramsArray);
         $this->provider->executeQuery("UPDATE p_queue q \r\n\t\t\t\tSET \r\n\t\t\t\t\tq.player_id=%s,\r\n\t\t\t\t\tq.village_id=%s,\r\n\t\t\t\t\tq.to_player_id=%s,\r\n\t\t\t\t\tq.to_village_id=%s,\r\n\t\t\t\t\tq.proc_type=%s,\r\n\t\t\t\t\tq.proc_params='%s',\r\n\t\t\t\t\tq.end_date=(q.end_date + INTERVAL q.execution_time SECOND)\r\n\t\t\t\tWHERE q.id=%s", array(intval($taskRow['to_player_id']), intval($taskRow['to_village_id']), intval($taskRow['player_id']), intval($taskRow['village_id']), QS_WAR_REINFORCE, $newParams, intval($taskRow['id'])));
         return TRUE;
     }
     $heroLevel = 0;
     if ($procInfo['troopsArray']['hasHero']) {
         $heroLevel = intval($this->provider->fetchScalar("SELECT p.hero_level FROM p_players p WHERE p.id=%s", array(intval($fromVillageRow['player_id']))));
     }
     $heroBuildingLevel = 0;
     $wringerLevel = 0;
     $buildings = array();
     $bStr = trim($fromVillageRow['buildings']);
     if ($bStr != "") {
         $bStrArr = explode(",", $bStr);
         foreach ($bStrArr as $b2Str) {
             $update_state = explode(" ", $b2Str);
             $level = explode(" ", $b2Str);
             $item_id = explode(" ", $b2Str);
             list($item_id, $level, $update_state) = $item_id;
             if ($item_id == 35) {
                 $wringerLevel = $level;
             } else {
                 if ($item_id == 37) {
                     $heroBuildingLevel = $level;
                 }
             }
         }
     }
     $attackTroops = $this->_getAttackTroopsForVillage($fromVillageRow['troops_training'], $procInfo['troopsArray']['troops'], $heroLevel, $fromVillageRow['people_count'], $wringerLevel, FALSE);
     $buildinStabilityFactor = 1;
     $crannyTotalSize = 0;
     $wallPower = 0;
     $wallLevel = 0;
     $wallBid = 0;
     $wallItemId = 0;
     $buildings = array();
     $bStr = trim($toVillageRow['buildings']);
     if ($bStr != "") {
         $bStrArr = explode(",", $bStr);
         $fcc = 0;
         foreach ($bStrArr as $b2Str) {
             ++$fcc;
             $update_state = explode(" ", $b2Str);
             $level = explode(" ", $b2Str);
             $item_id = explode(" ", $b2Str);
             list($item_id, $level, $update_state) = $item_id;
             if ($item_id == 31 || $item_id == 32 || $item_id == 33) {
                 $wallBid = $fcc;
                 $wallItemId = $item_id;
                 $wallLevel = $level;
                 $wallPower = 0 < $level ? $GameMetadata['items'][$item_id]['levels'][$level - 1]['value'] : 0;
             } else {
                 if ($item_id == 23 && 0 < $level) {
                     $crannyTotalSize += $GameMetadata['items'][$item_id]['levels'][$level - 1]['value'] * $GameMetadata['items'][$item_id]['for_tribe_id'][$toVillageRow['tribe_id']];
                 } else {
                     if ($item_id == 34 && 0 < $level) {
                         $buildinStabilityFactor = $GameMetadata['items'][$item_id]['levels'][$level - 1]['value'] / 100;
                     }
                 }
             }
         }
     }
     $crannyTotalSize = floor($crannyTotalSize * $GameMetadata['tribes'][$fromVillageRow['tribe_id']]['crannyFactor']);
     $defenseTroops = array();
     $totalDefensePower = 0;
     $troops_num = trim($toVillageRow['troops_num']);
     if ($troops_num != "") {
         $vtroopsArr = explode("|", $troops_num);
         foreach ($vtroopsArr as $vtroopsStr) {
             $tvtroopsStr = explode(":", $vtroopsStr);
             $tvid = explode(":", $vtroopsStr);
             list($tvid, $tvtroopsStr) = $tvid;
             $incFactor = $toVillageRow['is_oasis'] && intval($toVillageRow['player_id']) == 0 && $tvid == 0 - 1 ? floor($toVillageRow['oasisElapsedTimeInSeconds'] / 86400) : 0;
             $_hasHero = FALSE;
             $vtroops = array();
             $_arr = explode(",", $tvtroopsStr);
             foreach ($_arr as $_arrStr) {
                 $_tnum = explode(" ", $_arrStr);
                 $_tid = explode(" ", $_arrStr);
                 list($_tid, $_tnum) = $_tid;
                 if ($_tnum == 0 - 1) {
                     $_hasHero = TRUE;
                 } else {
                     $vtroops[$_tid] = $_tnum + $incFactor;
                 }
             }
             if ($tvid == 0 - 1) {
                 $hero_in_village_id = intval($this->provider->fetchScalar("SELECT p.hero_in_village_id FROM p_players p WHERE p.id=%s", array(intval($toVillageRow['player_id']))));
                 if (0 < $hero_in_village_id && $hero_in_village_id == $toVillageRow['id']) {
                     $_hasHero = TRUE;
                 }
             }
             $defenseTroops[$tvid] = $this->_getDefenseTroopsForVillage($tvid == 0 - 1 ? $toVillageRow['id'] : $tvid, $vtroops, $_hasHero, $toVillageRow['people_count'], $wallPower, FALSE);
             $totalDefensePower += $defenseTroops[$tvid]['total_power'];
         }
     }
     $warResult = $this->getWarResult($attackTroops, $defenseTroops, $totalDefensePower, $taskRow['proc_type'] == QS_WAR_ATTACK_PLUNDER);
     $harvestResources = "0 0 0 0";
     $harvestInfoStruct = array("string" => $harvestResources, "sum" => 0);
     if (!$warResult['all_attack_killed']) {
         $harvestInfoStruct = $this->_harvestTroopsFrom($toVillageRow, $warResult['attackTroops']['total_carry_load'], $crannyTotalSize);
         $harvestResources = $harvestInfoStruct['string'];
     }
     $reduceConsumption = $warResult['attackTroops']['total_dead_consumption'];
     if ($warResult['all_attack_killed'] && $procInfo['troopsArray']['hasHero']) {
         $reduceConsumption += $GameMetadata['troops'][$procInfo['troopsArray']['heroTroopId']]['crop_consumption'];
     }
     if (0 < $reduceConsumption) {
         $this->_updateVillage($fromVillageRow, $reduceConsumption, $warResult['all_attack_killed'] && $procInfo['troopsArray']['hasHero']);
     }
     if ($procInfo['troopsArray']['hasHero'] && !$warResult['all_attack_killed'] && 1 <= $warResult['defense_total_dead_number']) {
         $heroStatisticPoint = 1;
         $this->provider->executeQuery("UPDATE p_players p SET p.hero_points=p.hero_points+%s, p.hero_level=p.hero_level+floor(p.hero_points/(100*(p.hero_level+1))) WHERE p.id=%s", array($heroStatisticPoint, intval($fromVillageRow['player_id'])));
     }
     $defenseTroopsStr = "";
     $defenseReduceConsumption = 0;
     $reportTroopTable = array();
     $tribeId = 0;
     foreach ($warResult['defenseTroops'] as $vid => $troopsTable) {
         $defenseReduceConsumption += $troopsTable['total_dead_consumption'];
         $newTroops = "";
         $thisInforcementDied = TRUE;
         foreach ($troopsTable['troops'] as $tid => $tprop) {
             if ($newTroops != "") {
                 $newTroops .= ",";
             }
             $newTroops .= $tid . " " . $tprop['live_number'];
             if (0 < $tprop['live_number']) {
                 $thisInforcementDied = FALSE;
             }
             $tribeId = $GameMetadata['troops'][$tid]['for_tribe_id'];
             if (!isset($reportTroopTable[$tribeId])) {
                 $reportTroopTable[$tribeId] = array("troops" => array(), "hero" => array("number" => 0, "dead_number" => 0));
             }
             if ($tid != 99) {
                 if (!isset($reportTroopTable[$tribeId]['troops'][$tid])) {
                     $reportTroopTable[$tribeId]['troops'][$tid] = array("number" => $tprop['number'], "dead_number" => $tprop['number'] - $tprop['live_number']);
                 } else {
                     $reportTroopTable[$tribeId]['troops'][$tid]['number'] += $tprop['number'];
                     $reportTroopTable[$tribeId]['troops'][$tid]['dead_number'] += $tprop['number'] - $tprop['live_number'];
                 }
             }
         }
         if ($troopsTable['hasHero']) {
             ++$reportTroopTable[$tribeId]['hero']['number'];
         }
         if (0 < $troopsTable['total_live_number'] && $troopsTable['hasHero']) {
             if ($vid != 0 - 1) {
                 if ($newTroops != "") {
                     $newTroops .= ",";
                 }
                 $newTroops .= $troopsTable['heroTroopId'] . " -1";
             }
             if ($vid == 0 - 1 && !$toVillageRow['is_oasis'] && $warResult['all_attack_killed']) {
                 $heroStatisticPoint = 1;
                 $this->provider->executeQuery("UPDATE p_players p SET p.hero_points=p.hero_points+%s, p.hero_level=p.hero_level+floor(p.hero_points/(100*(p.hero_level+1))) WHERE p.id=%s", array($heroStatisticPoint, intval($toVillageRow['player_id'])));
             }
             $thisInforcementDied = FALSE;
         }
         if ($troopsTable['hasHero'] && $troopsTable['total_live_number'] <= 0) {
             ++$reportTroopTable[$tribeId]['hero']['dead_number'];
             $defenseReduceConsumption += $GameMetadata['troops'][$troopsTable['heroTroopId']]['crop_consumption'];
         }
         $this->_updateVillageOutTroops($vid, $toVillageRow['id'], $newTroops, $troopsTable['hasHero'] && $troopsTable['total_live_number'] <= 0, $thisInforcementDied, intval($toVillageRow['player_id']));
         if ($vid == 0 - 1 && $toVillageRow['is_oasis']) {
             $this->provider->executeQuery("UPDATE p_villages v SET v.creation_date=NOW() WHERE v.id=%s", array(intval($toVillageRow['id'])));
         }
         if (!$thisInforcementDied || $vid == 0 - 1) {
             if ($defenseTroopsStr != "") {
                 $defenseTroopsStr .= "|";
             }
             $defenseTroopsStr .= $vid . ":" . $newTroops;
         }
     }
     if ($toVillageRow['is_oasis'] && 0 < intval($toVillageRow['player_id']) && isset($reportTroopTable[4])) {
         unset($reportTroopTable[4]);
     }
     $this->provider->executeQuery("UPDATE p_villages v SET v.troops_num='%s' WHERE v.id=%s", array($defenseTroopsStr, $toVillageRow['id']));
     if (!($toVillageRow['is_oasis'] && intval($toVillageRow['player_id']) == 0)) {
         $_tovid = $toVillageRow['is_oasis'] ? intval($toVillageRow['parent_id']) : $toVillageRow['id'];
         $this->provider->executeQuery("UPDATE p_villages v SET v.crop_consumption=v.crop_consumption-%s WHERE v.id=%s", array($defenseReduceConsumption, intval($_tovid)));
     }
     $villageTotallyDestructed = FALSE;
     $wallDestructionResult = "";
     $catapultResult = "";
     if (!$toVillageRow['is_oasis'] && !$warResult['all_attack_killed'] && $taskRow['proc_type'] != QS_WAR_ATTACK_PLUNDER) {
         $wallDestrTroopsCount = 0;
         $buildDestrTroopsCount = 0;
         foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
             if ($tid == 7 || $tid == 17 || $tid == 27 || $tid == 106 || $tid == 57) {
                 $wallDestrTroopsCount = $tprop['live_number'];
             } else {
                 if ($tid == 8 || $tid == 18 || $tid == 28 || $tid == 107 || $tid == 58) {
                     $buildDestrTroopsCount = $tprop['live_number'];
                 }
             }
         }
         if ($procInfo['troopsArray']['hasWallDest']) {
             if (0 < $wallLevel) {
                 $dropLevels = 0;
                 if (2 * $wallPower < $wallDestrTroopsCount) {
                     $dropLevels = floor($wallDestrTroopsCount / (2 * $wallPower));
                     if ($wallLevel - $dropLevels < 0) {
                         $dropLevels = $wallLevel;
                     }
                 }
                 if (0 < $dropLevels) {
                     $wallDestructionResult = $wallLevel . "-" . ($wallLevel - $dropLevels);
                     $wallLevel -= $dropLevels;
                     $mq = new QueueJobModel();
                     while (0 < $dropLevels--) {
                         $mq->upgradeBuilding($toVillageRow['id'], $wallBid, $wallItemId, TRUE);
                     }
                 } else {
                     $wallDestructionResult = "-";
                 }
             } else {
                 $wallDestructionResult = "+";
             }
         }
         if (trim($procInfo['catapultTarget']) != "") {
             $catapultTargetArr = explode(":", $procInfo['catapultTarget']);
             $catapultTargetArr = explode(" ", $catapultTargetArr[1]);
             $buildingsInfo = array();
             $bStr = trim($toVillageRow['buildings']);
             if ($bStr != "") {
                 $bStrArr = explode(",", $bStr);
                 $_i = 0;
                 foreach ($bStrArr as $b2Str) {
                     ++$_i;
                     $update_state = explode(" ", $b2Str);
                     $level = explode(" ", $b2Str);
                     $item_id = explode(" ", $b2Str);
                     list($item_id, $level, $update_state) = $item_id;
                     if ($item_id == 31 || $item_id == 32 || $item_id == 33) {
                         continue;
                     }
                     if (0 < $level) {
                         $buildingsInfo[] = array("id" => $_i, "item_id" => $item_id, "level" => $level);
                     }
                 }
             }
             $catapultTargetInfoArr = array();
             if (0 < sizeof($buildingsInfo)) {
                 foreach ($catapultTargetArr as $catapultTargetItemId) {
                     $targetExists = FALSE;
                     foreach ($buildingsInfo as $bInfo) {
                         if (!($catapultTargetItemId == $bInfo['item_id'])) {
                             continue;
                         }
                         $catapultTargetInfoArr[] = $bInfo;
                         $targetExists = TRUE;
                         break;
                         break;
                     }
                     if (!$targetExists) {
                         $_randIndex = mt_rand(0, sizeof($buildingsInfo) - 1);
                         $catapultTargetInfoArr[] = $buildingsInfo[$_randIndex];
                     }
                 }
             }
             if (0 < sizeof($catapultTargetInfoArr)) {
                 if (1 < sizeof($catapultTargetInfoArr) && $catapultTargetInfoArr[0]['id'] == $catapultTargetInfoArr[1]['id']) {
                     $tmp = $catapultTargetInfoArr[0];
                     $catapultTargetInfoArr = array();
                     $catapultTargetInfoArr[] = $tmp;
                 }
                 $buildDestrTroopsCount = floor($buildDestrTroopsCount / sizeof($catapultTargetInfoArr));
                 foreach ($catapultTargetInfoArr as $catapultTargetInfoItem) {
                     if ($catapultResult != "") {
                         $catapultResult .= "#";
                     }
                     $canDestructBuilding = $catapultTargetInfoItem['level'] * $buildinStabilityFactor * 4 <= $buildDestrTroopsCount;
                     if ($canDestructBuilding) {
                         $dropBuildingLevels = floor($buildDestrTroopsCount / ($catapultTargetInfoItem['level'] * $buildinStabilityFactor * 4));
                         if ($catapultTargetInfoItem['level'] - $dropBuildingLevels < 0) {
                             $dropBuildingLevels = $catapultTargetInfoItem['level'];
                         }
                         $catapultResult .= $catapultTargetInfoItem['item_id'] . " " . $catapultTargetInfoItem['level'] . " " . ($catapultTargetInfoItem['level'] - $dropBuildingLevels);
                         $mq = new QueueJobModel();
                         do {
                             if (0 < $dropBuildingLevels--) {
                                 $mq->upgradeBuilding($toVillageRow['id'], $catapultTargetInfoItem['id'], $catapultTargetInfoItem['item_id'], TRUE);
                             }
                         } while (1);
                     } else {
                         $catapultResult .= $catapultTargetInfoItem['item_id'] . " " . $catapultTargetInfoItem['level'] . " -1";
                     }
                 }
             }
             if (!$toVillageRow['is_capital'] && !$toVillageRow['is_special_village']) {
                 $checkToVillageRow = $this->_getVillageInfo($taskRow['to_village_id']);
                 $villageTotallyDestructed = TRUE;
                 $bStr = trim($checkToVillageRow['buildings']);
                 if ($bStr != "") {
                     $bStrArr = explode(",", $bStr);
                     $_i = 0;
                     foreach ($bStrArr as $b2Str) {
                         ++$_i;
                         $update_state = explode(" ", $b2Str);
                         $level = explode(" ", $b2Str);
                         $item_id = explode(" ", $b2Str);
                         list($item_id, $level, $update_state) = $item_id;
                         if (!(0 < $level)) {
                             continue;
                         }
                         $villageTotallyDestructed = FALSE;
                         break;
                         break;
                     }
                 }
                 if ($villageTotallyDestructed) {
                     $catapultResult = "+";
                     $this->leaveVillage($toVillageRow['id'], $toVillageRow['player_id'], $toVillageRow['people_count'], $toVillageRow['parent_id']);
                 }
             }
         }
     }
     $doTroopsBack = TRUE;
     $villageCaptured = FALSE;
     $captureResult = "";
     if ($procInfo['troopsArray']['hasKing'] && !$toVillageRow['is_oasis'] && !$warResult['all_attack_killed'] && $taskRow['proc_type'] != QS_WAR_ATTACK_PLUNDER && !$toVillageRow['is_capital'] && !$villageTotallyDestructed && $warResult['all_defense_killed'] && $toVillageRow['player_id'] != $fromVillageRow['player_id']) {
         $checkToVillageRow = $this->_getVillageInfo($taskRow['to_village_id']);
         $b25_26_exists = FALSE;
         $bStr = trim($checkToVillageRow['buildings']);
         if ($bStr != "") {
             $bStrArr = explode(",", $bStr);
             foreach ($bStrArr as $b2Str) {
                 $update_state = explode(" ", $b2Str);
                 $level = explode(" ", $b2Str);
                 $item_id = explode(" ", $b2Str);
                 list($item_id, $level, $update_state) = $item_id;
                 if (0 < $level && ($item_id == 25 || $item_id == 26)) {
                     $b25_26_exists = TRUE;
                     break;
                 }
             }
         }
         $kingIsLive = FALSE;
         foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
             if (!($tid == 9 || $tid == 19 || $tid == 29 || $tid == 108 || $tid == 59)) {
                 continue;
             }
             $kingIsLive = 0 < $tprop['live_number'];
             break;
             break;
         }
         if ($kingIsLive && !$b25_26_exists) {
             $allegiance_percent = $toVillageRow['allegiance_percent'];
             $allegiance_percent -= 25;
             if (0 < $allegiance_percent) {
                 $this->provider->executeQuery("UPDATE p_villages v SET v.allegiance_percent=%s WHERE v.id=%s", array($allegiance_percent, intval($toVillageRow['id'])));
                 $captureResult = $toVillageRow['allegiance_percent'] . "-" . $allegiance_percent;
             } else {
                 $allegiance_percent = 0;
                 $captureResult = "+";
             }
             if ($allegiance_percent == 0) {
                 $villageCaptured = TRUE;
                 $kingCropConumption = 0;
                 $doTroopsBack = FALSE;
                 foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
                     if ($tid == 9 || $tid == 19 || $tid == 29 || $tid == 108 || $tid == 59) {
                         $kingCropConumption = $GLOBALS['GameMetadata']['troops'][$tid]['crop_consumption'];
                         break;
                     }
                     if (0 < $tprop['live_number']) {
                         $doTroopsBack = TRUE;
                     }
                 }
                 $this->leaveVillage($toVillageRow['id'], $toVillageRow['player_id'], $toVillageRow['people_count'], $toVillageRow['parent_id'], FALSE);
                 $this->captureVillage($toVillageRow, $fromVillageRow, $kingCropConumption);
             }
         }
     }
     $oasisResult = "";
     if ($procInfo['troopsArray']['hasHero'] && $toVillageRow['is_oasis'] && !$warResult['all_attack_killed'] && $warResult['all_defense_killed'] && $toVillageRow['player_id'] != $fromVillageRow['player_id'] && 10 <= $heroBuildingLevel) {
         $canCaptureOasis = FALSE;
         $numberOfOwnedOases = trim($fromVillageRow['village_oases_id']) == "" ? 0 : sizeof(explode(",", $fromVillageRow['village_oases_id']));
         if ($heroBuildingLevel == 20) {
             $canCaptureOasis = $numberOfOwnedOases < 3;
         } else {
             if (15 <= $heroBuildingLevel) {
                 $canCaptureOasis = $numberOfOwnedOases < 2;
             } else {
                 if (10 <= $heroBuildingLevel) {
                     $canCaptureOasis = $numberOfOwnedOases < 1;
                 }
             }
         }
         $oasisInRang = FALSE;
         $rang = 3;
         $map_size = $SetupMetadata['map_size'];
         $x = $fromVillageRow['rel_x'];
         $y = $fromVillageRow['rel_y'];
         $mi = 0 - $rang;
         while ($mi <= $rang) {
             if ($oasisInRang) {
                 break;
             }
             $mj = 0 - $rang;
             while ($mj <= $rang) {
                 if ($toVillageRow['id'] == $this->__getVillageId($map_size, $this->__getCoordInRange($map_size, $x + $mi), $this->__getCoordInRange($map_size, $y + $mj))) {
                     $oasisInRang = TRUE;
                     break;
                 }
                 ++$mj;
             }
             ++$mi;
         }
         if ($canCaptureOasis && $oasisInRang) {
             $qm = new QueueJobModel();
             if (intval($toVillageRow['player_id']) == 0) {
                 $oasisResult = "+";
                 $qm->captureOasis($toVillageRow['id'], $fromVillageRow['player_id'], $fromVillageRow['id'], TRUE);
             } else {
                 $allegiance_percent = $toVillageRow['allegiance_percent'];
                 $allegiance_percent -= 25;
                 if (0 < $allegiance_percent) {
                     $oasisResult = $toVillageRow['allegiance_percent'] . "-" . $allegiance_percent;
                     $this->provider->executeQuery("UPDATE p_villages v SET v.allegiance_percent=%s WHERE v.id=%s", array($allegiance_percent, intval($toVillageRow['id'])));
                 } else {
                     $allegiance_percent = 0;
                     $oasisResult = "+";
                 }
                 if ($allegiance_percent == 0) {
                     $qm->captureOasis($toVillageRow['id'], $toVillageRow['player_id'], $toVillageRow['parent_id'], FALSE);
                     $qm->captureOasis($toVillageRow['id'], $fromVillageRow['player_id'], $fromVillageRow['id'], TRUE);
                 }
             }
         }
     }
     $newTroops = "";
     foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
         if ($newTroops != "") {
             $newTroops .= ",";
         }
         $newTroops .= $tid . " " . $tprop['number'] . " " . ($tprop['number'] - $tprop['live_number']);
     }
     if ($procInfo['troopsArray']['hasHero']) {
         if ($newTroops != "") {
             $newTroops .= ",";
         }
         $newTroops .= 0 - 1 . " " . 1 . " " . ($warResult['all_attack_killed'] ? 1 : 0);
     }
     $attackReportTroops = $newTroops;
     $defenseReportTroops = "";
     foreach ($reportTroopTable as $tribeId => $defTroops) {
         $defenseReportTroops1 = "";
         if ($tribeId == 4) {
             $monsterTroops = array();
             foreach ($GLOBALS['GameMetadata']['troops'] as $t4k => $t4v) {
                 if ($t4v['for_tribe_id'] == 4) {
                     $monsterTroops[$t4k] = array("number" => isset($defTroops['troops'][$t4k]) ? $defTroops['troops'][$t4k]['number'] : 0, "dead_number" => isset($defTroops['troops'][$t4k]) ? $defTroops['troops'][$t4k]['dead_number'] : 0);
                 }
             }
             $defTroops['troops'] = $monsterTroops;
         }
         foreach ($defTroops['troops'] as $tid => $tArr) {
             if ($defenseReportTroops1 != "") {
                 $defenseReportTroops1 .= ",";
             }
             $defenseReportTroops1 .= $tid . " " . $tArr['number'] . " " . $tArr['dead_number'];
         }
         if (0 < $defTroops['hero']['number']) {
             if ($defenseReportTroops1 != "") {
                 $defenseReportTroops1 .= ",";
             }
             $defenseReportTroops1 .= 0 - 1 . " " . $defTroops['hero']['number'] . " " . $defTroops['hero']['dead_number'];
         }
         if ($defenseReportTroops1 != "") {
             if ($defenseReportTroops != "") {
                 $defenseReportTroops .= "#";
             }
             $defenseReportTroops .= $defenseReportTroops1;
         }
     }
     $timeInSeconds = $taskRow['remainingTimeInSeconds'];
     $attackDigit = 0;
     $defenseDigit = 0;
     if ($warResult['all_attack_killed']) {
         $attackDigit = 3;
         $defenseDigit = 0 < $warResult['defense_total_dead_number'] ? 5 : 4;
     } else {
         $attackDigit = 0 < $warResult['attackTroops']['total_dead_number'] ? 2 : 1;
         $defenseDigit = 0 < $warResult['defense_total_dead_number'] ? 6 : 7;
     }
     $reportResult = $defenseDigit * 10 + $attackDigit;
     $reportCategory = 3;
     $reportBody = $attackReportTroops . "|" . $defenseReportTroops . "|" . $warResult['attackTroops']['total_carry_load'] . "|" . $harvestResources . "|" . $wallDestructionResult . "|" . $catapultResult . "|" . $oasisResult . "|" . $captureResult;
     $r = new ReportModel();
     $r->createReport(intval($fromVillageRow['player_id']), intval($toVillageRow['player_id']), intval($fromVillageRow['id']), intval($toVillageRow['id']), $reportCategory, $reportResult, $reportBody, $timeInSeconds);
     if (intval($toVillageRow['player_id']) != intval($fromVillageRow['player_id'])) {
         $statisticPoint = 0;
         $harvestPoint = $harvestInfoStruct['sum'];
         if (0 < intval($toVillageRow['player_id']) && intval($toVillageRow['tribe_id']) != 5) {
             $statisticPoint = $warResult['attackTroops']['total_dead_number'];
             $this->provider->executeQuery("UPDATE p_players p SET p.defense_points=p.defense_points+%s, p.week_defense_points=p.week_defense_points+%s WHERE p.id=%s", array($statisticPoint, $statisticPoint, intval($toVillageRow['player_id'])));
         }
         if (0 < intval($fromVillageRow['player_id']) && intval($fromVillageRow['tribe_id']) != 5) {
             $statisticPoint = $warResult['defense_total_dead_number'];
             $this->provider->executeQuery("UPDATE p_players p SET p.attack_points=p.attack_points+%s, p.week_attack_points=p.week_attack_points+%s, p.week_thief_points=p.week_thief_points+%s WHERE p.id=%s", array($statisticPoint, $statisticPoint, $harvestPoint, intval($fromVillageRow['player_id'])));
         }
         if (0 < intval($toVillageRow['alliance_id'])) {
             $statisticPoint = $warResult['attackTroops']['total_dead_number'];
             $allianceRate = $warResult['all_attack_killed'] ? 1 : 0;
             $this->provider->executeQuery("UPDATE p_alliances p SET p.rating=p.rating+%s, p.defense_points=p.defense_points+%s, p.week_defense_points=p.week_defense_points+%s WHERE p.id=%s", array($allianceRate, $statisticPoint, $statisticPoint, intval($toVillageRow['alliance_id'])));
         }
         if (0 < intval($fromVillageRow['alliance_id'])) {
             $statisticPoint = $warResult['defense_total_dead_number'];
             $allianceRate = !$warResult['all_attack_killed'] && 0 < $statisticPoint ? 1 : 0;
             $this->provider->executeQuery("UPDATE p_alliances p SET p.rating=p.rating+%s, p.attack_points=p.attack_points+%s, p.week_attack_points=p.week_attack_points+%s, p.week_thief_points=p.week_thief_points+%s WHERE p.id=%s", array($allianceRate, $statisticPoint, $statisticPoint, $harvestPoint, intval($fromVillageRow['alliance_id'])));
         }
     }
     if (!$warResult['all_attack_killed'] && $doTroopsBack) {
         $paramsArray = explode("|", $taskRow['proc_params']);
         $paramsArray[sizeof($paramsArray) - 1] = 1;
         $newTroops = "";
         foreach ($warResult['attackTroops']['troops'] as $tid => $tprop) {
             if ($newTroops != "") {
                 $newTroops .= ",";
             }
             if ($villageCaptured && ($tid == 9 || $tid == 19 || $tid == 29 || $tid == 108 || $tid == 59)) {
                 $tprop['live_number'] = 0;
             }
             $newTroops .= $tid . " " . $tprop['live_number'];
         }
         if (!$warResult['all_attack_killed'] && $procInfo['troopsArray']['hasHero']) {
             if ($newTroops != "") {
                 $newTroops .= ",";
             }
             $newTroops .= $procInfo['troopsArray']['heroTroopId'] . " -1";
         }
         $paramsArray[0] = $newTroops;
         $paramsArray[4] = $harvestResources;
         $newParams = implode("|", $paramsArray);
         $this->provider->executeQuery("UPDATE p_queue q \r\n\t\t\t\tSET \r\n\t\t\t\t\tq.player_id=%s,\r\n\t\t\t\t\tq.village_id=%s,\r\n\t\t\t\t\tq.to_player_id=%s,\r\n\t\t\t\t\tq.to_village_id=%s,\r\n\t\t\t\t\tq.proc_type=%s,\r\n\t\t\t\t\tq.proc_params='%s',\r\n\t\t\t\t\tq.end_date=(q.end_date + INTERVAL q.execution_time SECOND)\r\n\t\t\t\tWHERE q.id=%s", array(intval($taskRow['to_player_id']), intval($taskRow['to_village_id']), intval($taskRow['player_id']), intval($taskRow['village_id']), QS_WAR_REINFORCE, $newParams, intval($taskRow['id'])));
         return TRUE;
     }
     return FALSE;
 }