Ejemplo n.º 1
0
    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;
    }
Ejemplo n.º 2
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();
 }