/** * Returns whenever a Character can attack a mob * * @param int $character_id the ID of the character * @param int $area_id the ID of the current location of the character * @return boolean */ function canAttack($areas_mobs_id = null, $character_id = null, $area_id = null) { $someMob = $this->find('first', array('conditions' => array('AreasMob.id' => $areas_mobs_id, 'AreasMob.area_id' => $area_id))); if (empty($someMob)) { return false; } // Check if Quest is needed... // When player_only = 1 we need to check the killing table if the player can kill this mob again if ($someMob['AreasMob']['player_only'] == '1') { App::import('Model', 'Kill'); $Kill = new Kill(); $lastKill = $Kill->find('first', array('conditions' => array('Kill.character_id' => $character_id, 'Kill.target_id' => $someMob['AreasMob']['id'], 'Kill.type' => 'mob', 'Kill.created >= ' => date('Y-m-d H:i:s', strtotime('-' . $someMob['AreasMob']['spawn_time'] . ' seconds'))))); if (empty($lastKill)) { // Controleer de kill limit. Kill_limit is een limit op de areas_mobs.id en niet op de mob_id. if ($someMob['AreasMob']['kill_limit'] > 0) { $amountKills = $Kill->find('count', array('conditions' => array('Kill.character_id' => $character_id, 'Kill.target_id' => $someMob['AreasMob']['id'], 'Kill.type' => 'mob'))); if ($someMob['AreasMob']['kill_limit'] > $amountKills) { return true; } } else { return true; } } } elseif ($someMob['AreasMob']['last_killed'] < date('Y-m-d H:i:s', strtotime('-' . $someMob['AreasMob']['spawn_time'] . ' seconds'))) { if ($someMob['AreasMob']['kill_limit'] > 0) { $amountKills = $Kill->find('count', array('conditions' => array('Kill.target_id' => $someMob['AreasMob']['id'], 'Kill.type' => 'mob'))); if ($someMob['AreasMob']['kill_limit'] < $amountKills) { return true; } } else { return true; } } return false; }
/** * @return string HTML string for the summary overview of the battle. */ public function overview() { global $smarty; $smarty->assignByRef('pilots_a', $this->pilots['a']); $smarty->assignByRef('pilots_e', $this->pilots['e']); $pod = Ship::getByID(670); $smarty->assign('podpic', $pod->getImage(32)); $smarty->assign('friendlycnt', count($this->pilots['a'])); $smarty->assign('hostilecnt', count($this->pilots['e'])); if ($this->kill->isClassified()) { $smarty->assign('system', 'Classified System'); } else { if (!$this->adjacent) { $smarty->assign('system', $this->kill->getSolarSystemName()); } else { $sysnames = array(); foreach ($this->systems as $sys_id) { $system = SolarSystem::getByID($sys_id); $sysnames[] = $system->getName(); } $smarty->assign('system', implode(', ', $sysnames)); } } $smarty->assign('firstts', $this->firstts); $smarty->assign('lastts', $this->lastts); $smarty->assign("battleOverviewTableTemplate", $this->templateDir . "battle_overview_table.tpl"); return $smarty->fetch($this->templateDir . "battle_overview.tpl"); }
/** * @return string HTML string for the summary overview of the battle. */ public function overview() { global $smarty; $smarty->assignByRef('pilots_a', $this->pilots['a']); $smarty->assignByRef('pilots_e', $this->pilots['e']); $pod = Ship::getByID(670); $smarty->assign('podpic', $pod->getImage(32)); $smarty->assign('friendlycnt', count($this->pilots['a'])); $smarty->assign('hostilecnt', count($this->pilots['e'])); if ($classified) { $smarty->assign('system', 'Classified System'); } else { if (!$this->adjacent) { $smarty->assign('system', $this->kill->getSolarSystemName()); } else { $sysnames = array(); foreach ($this->systems as $sys_id) { $system = SolarSystem::getByID($sys_id); $sysnames[] = $system->getName(); } $smarty->assign('system', implode(', ', $sysnames)); } } $smarty->assign('firstts', $this->firstts); $smarty->assign('lastts', $this->lastts); $smarty->assign('killURL', edkURI::page('kill_detail')); return $smarty->fetch(get_tpl('kill_related_battle_overview')); }
/** * @package EDK */ $page = new Page(); $page->setAdmin(); $kll_id = (int) edkURI::getArg('kll_id', 1); $page->setTitle('Administration - Deletion of Kill ID "' . $kll_id . '"'); if (isset($_GET['confirm'])) { $kill = Kill::getByID($kll_id); $kill->remove(true, false); $html .= "Kill ID \"" . $kll_id . "\" deleted!"; $html .= "<br><br><a href=\"javascript:window.close();\">[close]</a>"; } else { if (isset($_GET['permanent'])) { $kill = Kill::getByID($kll_id); $kill->remove(true, true); $html .= "Kill ID \"" . $kll_id . "\" deleted!"; $html .= "<br><br><a href=\"javascript:window.close();\">[close]</a>"; } else { $cargs = array(); $cargs[] = array("a", "admin_kill_delete", true); $cargs[] = array("kll_id", $kll_id, true); $pargs = $cargs; $cargs[] = array("confirm", "yes", false); $pargs[] = array("permanent", "yes", false); $html .= "Delete Kill ID \"" . $kll_id . "\": "; $html .= "<button onClick=\"window.location.href='" . edkURI::build($cargs) . "'\">Yes</button><br />"; $html .= "Delete and prevent reposting: "; $html .= "<button onClick=\"window.location.href='" . edkURI::build($pargs) . "'\">Yes</button><br />"; $html .= "Abort deletion and return: ";
} $html .= "<form><textarea class=killmail id=killmail name=killmail cols=\"55\" rows=\"35\" readonly=readonly>"; // Setup the lists $klist = new KillList(); $klist->setOrdered(true); $klist->addInvolvedPilot($pilot); $klist->rewind(); while ($kll_id = $klist->getKill()) { $kill = new Kill($kll_id->getID()); $html .= "\""; $html .= $kill->getRawMail(); $html .= "\",\n\n"; } // Losses $llist = new KillList(); $llist->setOrdered(true); // $list->setPodsNoobships( true ); // Not working!! $llist->addVictimPilot($pilot); $llist->rewind(); while ($lss_id = $llist->getKill()) { $html .= "\""; $loss = new Kill($lss_id->getID()); $html .= $loss->getRawMail(); $html .= "\",\n\n"; } $html .= "</textarea><br>"; $html .= "<input type=\"button\" value=\"Select All\" onClick=\"this.form.killmail.select();this.form.killmail.focus(); document.execCommand('Copy')\"></form><br>"; $html .= "Copy content of textbox to another location (eg. a textfile)"; $page->setContent($html); $page->addContext($menubox->generate()); $page->generate();
/** * @param SimpleXMLElement $item The element containing an Item. * @param Kill $kill The Kill to add the item to. * @param int $slot Set a default slot if none is specified. * @return boolean false on error */ private function processItem($item, &$kill, $slot = null) { if ((int) $item['singleton'] == 2) { // Blueprint copy - in the cargohold $location = -1; } if ($slot != null) { $location = $slot; } else { if ($this->lookupLocation == true) { if ($item['flag'] > 10 || $item['flag'] == 5) { // item locations in edk only goes up to ~9. // If someone is sending flags > 10 they are probably sending correct ccp flags.. // flag 5 is old+new cargo hold so we can also pass in $location = $item['flag']; } else { $litem = new Item((int) $item['typeID']); $location = $litem->getSlot(); } } else { $location = $item['flag']; } } if ((int) $item['qtyDropped']) { $kill->addDroppedItem(new DestroyedItem(new Item((int) $item['typeID']), (int) $item['qtyDropped'], '', $location, $this->lookupLocation)); } if ((int) $item['qtyDestroyed']) { $kill->addDestroyedItem(new DestroyedItem(new Item((int) $item['typeID']), (int) $item['qtyDestroyed'], '', $location, $this->lookupLocation)); } // Check for containers. if (isset($item->rowset)) { foreach ($item->rowset->row as $subitem) { $this->processItem($subitem, $kill, $location); } } return true; }
} elseif ($typ == 'p') { $klist->addInvolvedPilot(new Pilot($id)); $llist->addVictimPilot(new Pilot($id)); } } $kills = array(); while ($kill = $klist->getKill()) { $kills[$kill->getID()] = $kill->getTimestamp(); } while ($kill = $llist->getKill()) { $kills[$kill->getID()] = $kill->getTimestamp(); } asort($kills); $cnt = 0; foreach ($kills as $id => $timestamp) { $kill = new Kill($id); $cnt++; $file = $_SESSION['admin_kill_export']['dir'] . $cnt . $_SESSION['admin_kill_export']['ext']; $fp = fopen($file, 'w'); fwrite($fp, $kill->getRawMail()); fclose($fp); } $html .= $cnt . ' mails exported<br/>'; $html .= '<a href="' . edkURI::page("admin_kill_export") . '">Ok</a>'; unset($_SESSION['admin_kill_export']); } else { // nothing to export, retry unset($_SESSION['admin_kill_export']['do']); $_SESSION['admin_kill_export']['select'] = 1; header('Location: ' . edkURI::page("admin_kill_export")); }
public static function run() { self::setPath(); Kill::run(); }
public function create_object($data) { if (empty($data['victor'])) { $data['victor'] = 0; } else { $data['victor'] = Agent::mapper()->create_object(array('id' => $data['victor'], 'alias' => $data['victor_agent_alias'])); unset($data['victor_alias']); } $game = Game::create($data, True); $game->attach_mapper('Kill', Kill::mapper()->attach_storage(\Core\Storage::container()->get_storage('Kill'))); $game->attach_mapper('Agent', Agent::mapper()->attach_storage(\Core\Storage::container()->get_storage('Agent'))); foreach (array('start_date', 'end_date') as $f) { $game[$f] = new \DateTime($game[$f]); } $game->invite_only = (int) $data['invite_only']; $now = new \DateTime(); if ($game->start_date > $now) { $game['joinable'] = True; $game['active'] = False; $game['state'] = 0; } else { if ($game->start_date < $now && $now < $game->end_date) { $game['joinable'] = False; $game['active'] = True; $game['state'] = 1; } else { $game['joinable'] = False; $game['active'] = False; $game['state'] = 2; } } return $game; }
public function find_by_game(\Trouble\Game $game, $limit = 20) { $items = \Core\Storage::container()->get_storage('Kill')->fetch(array("joins" => KillContainer::_standard_joins(), "filter" => new \Core\Filter("game", $game['id']))); $kills = Kill::mapper()->get_list($items); return $kills; }
/** * Update the stored value of an item and the total value of this kill. * * Input values are taken from the query string. */ private function updatePrices() { if (config::get('item_values')) { if (isset($_POST['submit']) && $_POST['submit'] == 'UpdateValue') { // Send new value for item to the database $qry = DBFactory::getDBQuery(); $qry->autocommit(false); if (isset($_POST['SID'])) { $SID = intval($_POST['SID']); $Val = preg_replace('/[^0-9]/', '', $_POST[$SID]); $qry->execute("INSERT INTO kb3_item_price (typeID, price) VALUES ('" . $SID . "', '" . $Val . "') ON DUPLICATE KEY UPDATE price = '" . $Val . "'"); Ship::delCache($this->kill->getVictimShip()); } else { $IID = intval($_POST['IID']); $Val = preg_replace('/[^0-9]/', '', $_POST[$IID]); $qry->execute("INSERT INTO kb3_item_price (typeID, price) VALUES ('" . $IID . "', '" . $Val . "') ON DUPLICATE KEY UPDATE price = '" . $Val . "'"); Item::delCache(Item::getByID($IID)); } Kill::delCache($this->kill); $this->kill = Kill::getByID($this->kill->getID()); $this->kill->calculateISKLoss(true); $qry->autocommit(true); } } }
function parse($checkauth = true) { $qry = DBFactory::getDBQuery(); $timestamp = substr($this->killmail_, 0, 16); $timestamp = str_replace('.', '-', $timestamp); //trim out any multiple spaces that may exist - //$this->killmail_ = preg_replace('/ +/', ' ', $this->killmail_); // header section $involvedpos = strpos($this->killmail_, "Involved parties:"); if ($involvedpos == 0) { $this->error("Mail lacks Involved parties header."); return 0; } $header = substr($this->killmail_, 0, $involvedpos); $timestamp = substr($header, 0, 16); $victim = explode("\n", trim(substr($this->killmail_, 0, $involvedpos))); $upper_limit = count($victim); $victimname = "Unknown"; //lovely default values $factionname = "None"; $alliancename = "None"; $corpname = "Unknown"; $shipname = "Unknown"; $systemname = "Unknown"; $systemsec = "0.0"; $dmgtaken = '0'; $this->dmgtaken = '0'; $pos = 0; $moon = ""; for ($counter = 0; $counter <= $upper_limit; $counter++) { if (preg_match("/Victim: (.*)/", $victim[$counter], $matches)) { if ($matches[1]) { $victimname = $matches[1]; } } elseif (preg_match("/Corp: (.*)/", $victim[$counter], $matches)) { if ($matches[1]) { $corpname = $matches[1]; } } elseif (preg_match("/Alliance: (.*)/", $victim[$counter], $matches)) { if ($matches[1]) { $alliancename = $matches[1]; } if ($alliancename == "Unknown") { $alliancename = "None"; } } elseif (preg_match("/Faction: (.*)/", $victim[$counter], $matches)) { if (strlen($matches[1]) > 5 && $matches[1] != "Unknown") { //catches faction mails from -A- $factionname = $matches[1]; } else { $factionname = "None"; } } elseif (preg_match("/Destroyed: (.*)/", $victim[$counter], $matches)) { if ($matches[1]) { $shipname = $matches[1]; } } elseif (preg_match("/System: (.*)/", $victim[$counter], $matches)) { if ($matches[1]) { //bad assumption here - moon has to come before security. $systemname = $matches[1]; if (strcmp($moon, 'Unknown') == 0 && $pos == 1) { $moon = $matches[1]; $victimname = $matches[1]; } } } elseif (preg_match("/Security: (.*)/", $victim[$counter], $matches)) { if ($matches[1]) { $systemsec = (double) $matches[1]; } } elseif (preg_match("/Damage Taken: (.*)/", $victim[$counter], $matches)) { if ($matches[1]) { $dmgtaken = (int) $matches[1]; $this->dmgtaken = $dmgtaken; } } elseif (preg_match("/Moon: (.*)/", $victim[$counter], $matches)) { if ($matches[1]) { $moon = $matches[1]; $victimname = $matches[1]; $pos = 1; } else { //if the system is valid, it will pick this up, provided it features after //the moon is listed - which is unlikely unless the mail format //drastically changes... again :) $moon = 'Unknown'; $victimname = 'Unknown'; $pos = 1; } } } //faction warfare stuff if (strcasecmp($alliancename, 'None') == 0) { $alliancename = $factionname; } //report the errors for the things that make sense. //we need pilot names, corp names, ship types, and the system to be sure //the rest aren't required but for completeness, you'd want them in :) // Customs Offices don't have names. Hack a fix in by accepting mails with // no victim name but that do have a system. if (strcmp($victimname, 'Unknown') == 0) { if (strcmp($systemname, 'Unknown') == 0) { $this->error('Victim has no name.'); unset($victimname); //we unset the variable so that it fails the next check $this->error('Killmail lacks solar system information.'); unset($systemname); } else { $victimname = $systemname; } } if (strcmp($corpname, 'Unknown') == 0) { $this->error('Victim has no corp.'); unset($corpname); } if (strcmp($shipname, 'Unknown') == 0) { $this->error('Victim has no ship type.'); unset($shipname); } if (strcmp($systemname, 'Unknown') == 0) { $this->error('Killmail lacks solar system information.'); unset($systemname); } if ($pos == 1) { $victimname = $moon; } if (!isset($timestamp) || !isset($factionname) || !isset($alliancename) || !isset($corpname) || !isset($victimname) || !isset($shipname) || !isset($systemname) || !isset($systemsec)) { return 0; } if ($checkauth) { $authorized = false; } else { $authorized = true; } // populate/update database $alliance = $this->fetchAlliance($alliancename); $corp = $this->fetchCorp($corpname, $alliance, $timestamp); $victim = $this->fetchPilot($victimname, $corp, $timestamp); $system = SolarSystem::lookup($systemname); if (!$system || !$system->getID()) { $this->error('System not found.', $systemname); $system = new SolarSystem(); } $ship = Ship::lookup($shipname); if (!$ship || !$ship->getID()) { $this->error('Ship not found.', $shipname); $ship = new Ship(); } $kill = new Kill(); if ($this->externalID) { $kill->setExternalID($this->externalID); } $kill->setTimeStamp($timestamp); $kill->setVictim($victim); $kill->setVictimID($victim->getID()); $kill->setVictimCorpID($corp->getID()); $kill->setVictimAllianceID($alliance->getID()); $kill->setVictimShip($ship); $kill->setSolarSystem($system); if ($dmgtaken) { $kill->set('dmgtaken', $dmgtaken); } if (config::get('cfg_allianceid') && in_array($alliance->getID(), config::get('cfg_allianceid'))) { $authorized = true; } elseif (config::get('cfg_corpid') && in_array($corp->getID(), config::get('cfg_corpid'))) { $authorized = true; } elseif (config::get('cfg_pilotid') && in_array($victim->getID(), config::get('cfg_pilotid'))) { $authorized = true; } // involved parties section $end = strpos($this->killmail_, "Destroyed items:"); if ($end == 0) { $end = strpos($this->killmail_, "Dropped items:"); if ($end == 0) { //try to parse to the end of the mail in the event sections are missing $end = strlen($this->killmail_); } } $involved = explode("\n", trim(substr($this->killmail_, strpos($this->killmail_, "Involved parties:") + 17, $end - (strpos($this->killmail_, "Involved parties:") + 17)))); $ipilot_count = 0; //allows us to be a bit more specific when errors strike $i = 0; $topdamage = 0; $order = 0; while ($i < count($involved)) { $iparts = count($involved); $finalblow = 0; while ($i < $iparts) { $ipilot_count++; $ipname = "Unknown"; $ianame = "None"; $ifname = "None"; $icname = "None"; $isname = "Unknown"; $iwname = "Unknown"; $idmgdone = '0'; $secstatus = "0.0"; while ($involved[$i] == '') { //compensates for multiple blank lines between involved parties $i++; if ($i > count($involved)) { $this->error("Involved parties section prematurely ends."); return 0; } } for ($counter = $i; $counter <= $iparts; $counter++) { if (preg_match("/Name: (.*)/", $involved[$counter], $matches)) { if ($matches[1]) { if (stristr($involved[$counter], '/')) { $slash = strpos($involved[$counter], '/'); $name = trim(substr($involved[$counter], 5, $slash - 5)); $corporation = trim(substr($involved[$counter], $slash + 1, strlen($involved[$counter]) - $slash + 1)); //now if the corp bit has final blow info, note it preg_match("/(.*) \\(laid the final blow\\)/", $corporation, $matched); if ($matched[1]) { $finalblow = 1; $iwname = $name; $end = strpos($corporation, '(') - 1; $corporation = substr($corporation, 0, $end); } else { $finalblow = 0; $iwname = $name; } //alliance lookup for warp disruptors - normal NPCs aren't to be bundled in $crp = $this->fetchCorp($corporation); if ($crp && $crp->getExternalID(true) > 0) { if ($crp->fetchCorp()) { $al = $crp->getAlliance(); $alName = $al->getName(); if (trim($alName) != "") { $ianame = $al->getName(); } } // else check db for kills with that corp at the same time? } $ipname = $name; $icname = $corporation; } else { $ipname = $matches[1]; preg_match("/(.*)\\s*\\(laid the final blow\\)/", $ipname, $matches); if (isset($matches[1])) { $ipname = trim($matches[1]); $finalblow = 1; } else { $finalblow = 0; } } } } else { if (preg_match("/Alliance: (.*)/", $involved[$counter], $matches)) { if ($matches[1]) { $ianame = $matches[1]; } if ($ianame == "Unknown") { $ianame = "None"; } } else { if (preg_match("/Faction: (.*)/", $involved[$counter], $matches)) { if (strlen($matches[1]) > 5 && $matches[1] != "Unknown") { //catches faction mails from -A- $ifname = $matches[1]; } else { $ifname = "NONE"; } } else { if (preg_match("/Corp: (.*)/", $involved[$counter], $matches)) { if ($matches[1]) { $icname = $matches[1]; } } else { if (preg_match("/Ship: (.*)/", $involved[$counter], $matches)) { if ($matches[1]) { $isname = $matches[1]; } } else { if (preg_match("/Weapon: (.*)/", $involved[$counter], $matches)) { if ($matches[1]) { $iwname = $matches[1]; } } else { if (preg_match("/Security: (.*)/", $involved[$counter], $matches)) { if ($matches[1]) { $secstatus = (double) $matches[1]; } } else { if (preg_match("/Damage Done: (.*)/", $involved[$counter], $matches)) { if ($matches[1]) { $idmgdone = (int) $matches[1]; } if ($idmgdone > $topdamage) { $topdamage = $idmgdone; } } else { if ($involved[$counter] == '') { //allows us to process the involved party. This is the empty line after the //involved party section $counter++; $i = $counter; break; } else { //skip over this entry, it could read anything, we don't care. Handy if/when //new mail fields get added and we aren't handling them yet. $counter++; $i = $counter; } } } } } } } } } if ($this->needs_final_blow_) { $finalblow = 1; $this->needs_final_blow_ = 0; } } // Faction Warfare stuff if (strcasecmp($ianame, "None") == 0) { $ianame = $ifname; } // end faction warfare stuff $ialliance = $this->fetchAlliance($ianame); if (strcmp($icname, 'None') == 0) { //don't add corp, because pilots have to be in corps. $this->error('Involved party has no corp. (Party No. ' . $ipilot_count . ')'); $icorp = new Corporation(); } else { $icorp = $this->fetchCorp($icname, $ialliance, $kill->getTimeStamp()); } if (preg_match("/^(Mobile \\w+ Warp|\\w+ Control Tower( \\w+)?)/", $iwname)) { //for involved parties parsed that lack a pilot, but are actually POS or mobile warp disruptors $ipname = $icname . ' - ' . $iwname; $ipilot = $this->fetchPilot($ipname, $icorp, $timestamp); } elseif (strcmp($ipname, 'Unknown') == 0 || empty($ipname)) { $ipilot = new Pilot(); $this->error('Involved party has no name. (Party No. ' . $ipilot_count . ')'); } else { //don't add pilot if the pilot's unknown or dud $ipilot = $this->fetchPilot($ipname, $icorp, $timestamp); } $iship = Ship::lookup($isname); if (!$iship || !$iship->getName()) { $this->error('Ship not found.', $isname); } if (strcmp($iwname, 'Unknown') == 0 && $iship && $iship->getID()) { $iwname = $iship->getName(); } $iweapon = Item::lookup($iwname); if (strcmp($iwname, 'Unknown') == 0) { $this->error('No weapon found for pilot "' . $ipname . '"'); $iweapon = new Item(); } else { if (!$iweapon || !$iweapon->getID()) { $this->error('Weapon not found.', $iwname); $iweapon = new Item(); } } if (config::get('cfg_allianceid') && in_array($ialliance->getID(), config::get('cfg_allianceid'))) { $authorized = true; } elseif (config::get('cfg_corpid') && in_array($icorp->getID(), config::get('cfg_corpid'))) { $authorized = true; } elseif (config::get('cfg_pilotid') && in_array($ipilot->getID(), config::get('cfg_pilotid'))) { $authorized = true; } if (!$authorized) { if ($string = config::get('post_permission')) { if ($string == 'all') { $authorized = true; } else { $tmp = explode(',', $string); foreach ($tmp as $item) { if (!$item) { continue; } $typ = substr($item, 0, 1); $id = substr($item, 1); if ($typ == 'a') { if ($ialliance->getID() == $id || $kill->getVictimAllianceID() == $id) { $authorized = true; break; } } elseif ($typ == 'c') { if ($icorp->getID() == $id || $kill->getVictimCorpID() == $id) { $authorized = true; break; } } elseif ($typ == 'p') { if ($ipilot->getID() == $id || $kill->getVictimID() == $id) { $authorized = true; break; } } } } } } $iparty = new InvolvedParty($ipilot->getID(), $icorp->getID(), $ialliance->getID(), $secstatus, $iship->getID(), $iweapon->getID(), $idmgdone); $kill->addInvolvedParty($iparty); if ($finalblow == 1) { $kill->setFBPilotID($ipilot->getID()); $kill->setFBCorpID($icorp->getID()); $kill->setFBAllianceID($ialliance->getID()); } if ($topdamage == $idmgdone) { $kill->setTDPilotID($ipilot->getID()); $kill->setFBCorpID($icorp->getID()); $kill->setFBAllianceID($ialliance->getID()); } } } // Duplicate check does not use items so it's safe to check now if ($id = $kill->getDupe()) { $this->dupeid_ = $id; if ($this->dupeid_ > 0 && $this->externalID) { //if this is a duplicate and we have an external id then update the existing kill $qry->execute("UPDATE kb3_kills SET kll_external_id = " . $this->externalID . " WHERE kll_id = " . $this->dupeid_); $qry->execute("UPDATE kb3_mails SET kll_external_id = " . $this->externalID . ", kll_modified_time = UTC_TIMESTAMP() " . "WHERE kll_id = " . $this->dupeid_ . " AND kll_external_id IS NULL"); } return -1; } // destroyed items section $destroyedpos = strpos($this->killmail_, "Destroyed items:"); if ($destroyedpos) { $endpos = strlen($this->killmail_) - $destroyedpos + 16; $pos = strpos($this->killmail_, "Dropped items:"); if ($pos === false) { $pos = strlen($this->killmail_); } $endpos = $pos - $destroyedpos - 16; $destroyed = explode("\n", trim(substr($this->killmail_, $destroyedpos + 16, $endpos))); $destroyed_items = $this->scanForItems($destroyed); foreach ($destroyed_items as $item) { $ditem = new DestroyedItem($item['item'], $item['quantity'], '', $item['location'], true); $kill->addDestroyedItem($ditem); } } $startpos = strpos($this->killmail_, "Dropped items:"); if ($startpos) { $endpos = strlen($this->killmail_) - $startpos + 14; $dropped = explode("\n", trim(substr($this->killmail_, $startpos + 14, $endpos))); $dropped_items = $this->scanForItems($dropped); foreach ($dropped_items as $item) { $ditem = new DestroyedItem($item['item'], $item['quantity'], '', $item['location'], true); $kill->addDroppedItem($ditem); } } if (!$authorized) { return -2; } if ($this->getError()) { return 0; } if ($this->returnmail) { return $kill; } $id = $kill->add(); if ($id == -2) { $this->error("An error has occurred. Please try again later."); $id = 0; } return $id; }
/** * Attack a Mob. * * This function will auto attack a Mob if possible. After that it may give XP, lose HP, get loot on the current area_id. * * @param $areas_mobs_id the ID of mob/area combination @see `areas_mobs`.`id` * @see /app/models/mob.php battle() */ function game_attack($areas_mobs_id = null) { if (empty($areas_mobs_id) || !is_numeric($areas_mobs_id)) { $this->render('/errors/notfound'); return false; } $this->updateGame(array('Character', 'Stat')); if ($this->AreasMob->canAttack($areas_mobs_id, $this->characterInfo['id'], $this->characterInfo['area_id'])) { $this->AreasMob->contain(array('Mob' => array('Stat'))); $areasMob = $this->AreasMob->find('first', array('conditions' => array('AreasMob.id' => $areas_mobs_id))); $areasMob['Mob']['Stat'] = $this->AreasMob->Mob->makeStats($areasMob['Mob']['Stat']); $areasMob['Mob']['Stat']['hp_org'] = $areasMob['Mob']['Stat']['hp']; $areasMob['Mob']['battle_key'] = 'mob'; $currentCharacter = $this->characterInfo; $currentCharacter['Stat'] = $this->Session->read('Game.Stat'); $currentCharacter['Stat']['hp_org'] = $currentCharacter['Stat']['hp']; $currentCharacter['battle_key'] = 'you'; $battleInfo = $this->AreasMob->Mob->battle($currentCharacter, $areasMob['Mob']); $loot = array(); // List of loot (items) if ($battleInfo['defender']['Stat']['hp'] <= 0) { # debug($battleInfo); // Player wins $areasMob['AreasMob']['last_killed'] = date('Y-m-d H:i:s'); $this->AreasMob->save($areasMob['AreasMob']); App::import('Model', 'Kill'); $Kill = new Kill(); $someKill['character_id'] = $this->characterInfo['id']; $someKill['target_id'] = $areasMob['AreasMob']['id']; $someKill['mob_id'] = $areasMob['Mob']['id']; $someKill['type'] = 'mob'; $Kill->save($someKill); $addXp = $this->AreasMob->Mob->earnedXp($currentCharacter['Stat']['level'], $areasMob['Mob']['level']); $this->Character->addStat('xp', $addXp, $this->characterInfo['id']); // Show the loot $this->loadModel('Loot'); $this->Loot->createLootFromMob($areasMob['Mob']['id'], $this->characterInfo['area_id'], $this->characterInfo['id']); $this->Loot->contain(array('Item')); $loot = $this->Loot->getLoot(array('Loot.character_id' => $this->characterInfo['id'], 'Loot.mob_id' => $areasMob['Mob']['id'])); $this->loadModel('Quest'); $this->Quest->update(null, $this->characterInfo['id']); } elseif ($battleInfo['attacker']['Stat']['hp'] <= 0) { // Player loses // @todo reset it? } // Update the stats $addHp = $battleInfo['attacker']['Stat']['hp'] - $this->Session->read('Game.Stat.hp'); $this->loadModel('Character'); $this->Character->addStat('hp', $addHp, $this->characterInfo['id']); $this->updateGame(array('Character', 'Stat')); $this->set('battleInfo', $battleInfo); $this->set('loot', $loot); } else { $this->render('/errors/notfound'); return false; } }
/** * Update the summary table when a kill value changes. * * @param Kill $kill * @param float $difference */ public static function update($kill, $difference) { $year = date('Y', strtotime($kill->getTimestamp())); $month = date('m', strtotime($kill->getTimestamp())); $shipid = $kill->getVictimShip()->getClass()->getID(); $difference = (double) $difference; $alls = array(); $qry = DBFactory::getDBQuery(); $sql = "UPDATE kb3_sum_alliance SET asm_loss_isk = asm_loss_isk + " . $difference . " WHERE asm_all_id = " . $kill->getVictimAllianceID() . " AND asm_shp_id = " . $shipid; $qry->execute($sql); foreach ($kill->getInvolved() as $inv) { if (isset($alls[$inv->getAllianceID()])) { continue; } $alls[$inv->getAllianceID()] = 1; $qry->execute("SELECT 1 FROM kb3_sum_alliance WHERE asm_all_id = " . $inv->getAllianceID()); if (!$qry->recordCount()) { continue; } $sql = "UPDATE kb3_sum_alliance SET asm_kill_isk = asm_kill_isk + " . $difference . " WHERE asm_all_id = " . $inv->getAllianceID() . " AND asm_shp_id = " . $shipid; $qry->execute($sql); } }
/** * Import zKillboard kills for the selected systems and alliances. */ public function getZkillboard($systems = '') { // If this is the initial call to the function, retrieve the list of systems from the DB. if ($systems == '') { $systems_object = Setting::where('key', 'systems')->firstOrFail(); $systems = $systems_object->value; } // Convert the comma-seperated string into an array. $systems_array = explode(',', $systems); // If there are more systems in the list than we want to pull at once, chop off the first X and call this function again. while (count($systems_array) > $this->api_system_limit) { $this->getZkillboard(implode(',', array_splice($systems_array, 0, $this->api_system_limit))); } // Retrieve the selected alliances from the database. $alliances = Setting::where('key', 'alliances')->firstOrFail(); // Build the API URL. $url = 'https://zkillboard.com/api/xml/losses/no-attackers/' . 'allianceID/' . preg_replace('/\\s+/', '', $alliances->value) . '/' . 'solarSystemID/' . preg_replace('/\\s+/', '', $systems) . '/'; // Send the request. $response = Request::get($url)->addHeader('Accept-Encoding', 'gzip')->addHeader('User-Agent', 'Eve Traders Handbook')->send(); if (isset($response->body) && strlen($response->body) > 0) { $body = simplexml_load_string(gzdecode($response->body)); $insert_count = 0; // Parse the response, inserting the losses into the database. foreach ($body->result->rowset->row as $row) { // First check whether this kill has not already been recorded. $kill = Kill::find($row['killID']); if (!isset($kill->killID)) { // Create and save the new kill record. $kill = new Kill(); $kill->killID = $row['killID']; $kill->solarSystemID = $row['solarSystemID']; $kill->characterID = $row->victim['characterID']; $kill->characterName = $row->victim['characterName']; $kill->allianceID = $row->victim['allianceID']; $kill->corporationID = $row->victim['corporationID']; $kill->shipTypeID = $row->victim['shipTypeID']; $kill->killTime = $row['killTime']; $kill->save(); $insert_count++; // Insert the alliance information into the database unless it already exists. $alliance = Alliance::find($kill->allianceID); if (!isset($alliance->id)) { $alliance = new Alliance(); $alliance->id = $kill->allianceID; $alliance->allianceName = $row->victim['allianceName']; $alliance->save(); } // Insert the corporation information into the database unless it already exists. $corporation = Corporation::find($kill->corporationID); if (!isset($corporation->id)) { $corporation = new Corporation(); $corporation->id = $kill->corporationID; $corporation->corporationName = $row->victim['corporationName']; $corporation->save(); } // Insert the ship type that was lost into the database unless it already exists. $ship = Ship::find($kill->shipTypeID); $type = Type::find($kill->shipTypeID); if (!isset($ship->id)) { $ship = new Ship(); $ship->id = $kill->shipTypeID; $ship->shipName = $type->typeName; $ship->save(); } // Insert the ship loss into the items database as well. if (stristr($ship->shipName, 'Capsule') === FALSE) { $item = new Item(); $item->killID = $row['killID']; $item->typeID = $kill->shipTypeID; $item->typeName = $type->typeName; $item->categoryName = $type->group->category['categoryName']; $item->metaGroupName = isset($type->metaType->metaGroup['metaGroupName']) ? $type->metaType->metaGroup['metaGroupName'] : ''; $item->allowManufacture = 1; $item->qty = 1; $item->save(); } // Add the category to the list of filters available on the site. $filter = Filter::find($type->group->category['categoryID']); if (!isset($filter->categoryID)) { $filter = new Filter(); $filter->categoryID = $type->group->category['categoryID']; $filter->categoryName = $type->group->category['categoryName']; $filter->iconID = $type->group->category['iconID']; $filter->save(); } // Loop through the items lost in the kill. Insert each one into the items table. if (isset($row->rowset->row)) { foreach ($row->rowset->row as $loss) { $typeID = (int) $loss['typeID']; $item = Item::where('typeID', '=', $typeID)->first(); // If this item already exists in the items table, we don't need to re-query all the additional // information, we can just copy it from an existing row. if (isset($item)) { // This type has already been seen. Duplicate the record and save the new instance. $clone = new Item(); $clone = $item->replicate(); // Update the right killID and quantity, and unset the primary key and date columns. $clone->killID = $row['killID']; $clone->qty = $loss['qtyDropped'] + $loss['qtyDestroyed']; unset($clone->id); unset($clone->created_at); unset($clone->updated_at); // Save the cloned row. $clone->save(); } else { // This is a never-before-seen lost item. Create a new row and look up all the related details. $item = new Item(); $type = Type::find($typeID); $item->killID = (int) $row['killID']; $item->typeID = $typeID; $item->typeName = $type->typeName; $item->categoryName = $type->group->category['categoryName']; $metaGroupName = isset($type->metaType->metaGroup['metaGroupName']) ? $type->metaType->metaGroup['metaGroupName'] : ''; if ($metaGroupName == 'Tech I' || $metaGroupName == '') { $metaLevel = DB::table('dgmTypeAttributes')->where('typeID', $typeID)->where('attributeID', 633)->first(); if (isset($metaLevel)) { $metaGroupName = 'Meta '; $metaGroupName .= isset($metaLevel->valueInt) ? $metaLevel->valueInt : $metaLevel->valueFloat; } } $item->metaGroupName = $metaGroupName; $blueprint = Type::where('typeName', $type->typeName . ' Blueprint')->count(); if ($blueprint > 0) { $item->allowManufacture = 1; } $item->qty = $loss['qtyDropped'] + $loss['qtyDestroyed']; $item->save(); // Add the category to the list of filters available on the site. $filter = Filter::find($type->group->category['categoryID']); if (!isset($filter->categoryID)) { $filter = new Filter(); $filter->categoryID = $type->group->category['categoryID']; $filter->categoryName = $type->group->category['categoryName']; $filter->iconID = $type->group->category['iconID']; $filter->save(); } } } } } } echo "Inserted {$insert_count} new kills! "; } else { echo "No response received from zKillboard API."; } }
/** * * @global array $destroyed * @global <type> $pilots * @global array $pods * @param Kill $kill * @param <type> $side * @return <type> */ function handle_destroyed($kill, $side, &$destroyed, &$pilots, $sideAssignmentMap = array(), $completeInformation = FALSE) { // ------------------------------------------------------------------------- // FIX BATTLE REPORT a little by Evoke. Salvoxia // BEGIN // ------------------------------------------------------------------------- // we don't want losses of our own corp/ally as losses on the enemy's side if ($side == 'e') { if (config::get('cfg_corpid')) { $corpId = config::get('cfg_corpid'); $corpId = $corpId[0]; if ($kill->getVictimCorpID() == $corpId) { return; } } elseif (config::get('cfg_allianceid')) { $allianceId = config::get('cfg_allianceid'); $allianceId = $allianceId[0]; if ($kill->getVictimAllianceID() == $allianceId) { return; } } } // ------------------------------------------------------------------------- // FIX BATTLE REPORT a little by Evoke. Salvoxia // END // ------------------------------------------------------------------------- if ($completeInformation && !is_null($destroyed) && is_array($destroyed)) { $destroyed[$kill->getID()] = $kill->getVictimID(); } if (config::get('fleet_battles_mod_sideassign')) { // determine whether the pilot is member of an alliance if ($kill->getVictimAllianceName() == "None") { $entityType = "corp"; $entityId = $kill->getVictimCorpID(); } else { $entityType = "alliance"; $entityId = $kill->getVictimAllianceID(); } if (isset($sideAssignmentMap[$entityType][$entityId])) { $pilotSide = $sideAssignmentMap[$entityType][$entityId]; } else { $pilotSide = $side; } } else { $pilotSide = $side; } $ship = Ship::lookup($kill->getVictimShipName()); $shipc = $ship->getClass(); $ts = strtotime($kill->getTimeStamp()); // mark the pilot as podded if ($shipc->getID() == 18 || $shipc->getID() == 2) { // increase the timestamp of a podkill by 1 so its after the shipkill $ts++; } // search for ships with the same id if (isset($pilots[$pilotSide][$kill->getVictimId()]) && is_array($pilots[$pilotSide][$kill->getVictimId()])) { foreach ($pilots[$pilotSide][$kill->getVictimId()] as $id => $_ship) { if ($ship->getID() == $_ship['sid']) { $pilots[$pilotSide][$kill->getVictimId()][$id]['destroyed'] = true; if (!isset($pilots[$pilotSide][$kill->getVictimId()][$id]['kll_id'])) { $pilots[$pilotSide][$kill->getVictimId()][$id]['kll_id'] = $kill->getID(); $pilots[$pilotSide][$kill->getVictimId()][$id]['kll_url'] = edkURI::page('kill_detail', $kill->getID(), "kll_id"); } //$pilots[$side][$kill->getVictimId()][0]["times"] +=1; return; } } } if ($completeInformation) { $pilots[$pilotSide][$kill->getVictimId()][] = array('name' => $kill->getVictimName(), 'plt_url' => edkURI::page("pilot_detail", $kill->getVictimID(), "plt_id"), 'kll_id' => $kill->getID(), 'kll_url' => edkURI::page('kill_detail', $kill->getID(), "kll_id"), 'spic' => imageURL::getURL('Ship', $ship->getID(), 32), 'scl' => $shipc->getPoints(), 'destroyed' => true, 'corp' => $kill->getVictimCorpName(), 'alliance' => $kill->getVictimAllianceName(), 'aid' => $kill->getVictimAllianceID(), 'alliance_url' => edkURI::page("alliance_detail", $kill->getVictimAllianceID(), "all_id"), 'ship' => $kill->getVictimShipname(), 'shipClass' => $shipc->getName(), 'shipClassObject' => $shipc, 'sid' => $ship->getID(), 'cid' => $kill->getVictimCorpID(), 'crp_url' => edkURI::page("corp_detail", $kill->getVictimCorpID(), "crp_id"), 'ts' => $ts, 'times' => 0, 'color' => getColorClassByClass($shipc)); } else { $pilots[$pilotSide][$kill->getVictimId()] = 1; } }
/** * Update the summary table when a kill value changes. * * @param Kill $kill * @param float $difference */ public static function update($kill, $difference) { $difference = (double) $difference; $alls = array(); $qry = DBFactory::getDBQuery(); $qry->execute("SELECT 1 FROM kb3_sum_pilot WHERE psm_plt_id = " . $kill->getVictimID()); // No summary table to remove kill from so skip. if ($qry->recordCount()) { $sql = "UPDATE kb3_sum_pilot SET psm_loss_isk = psm_loss_isk - " . $difference . " WHERE psm_plt_id = " . $kill->getVictimID() . " AND psm_shp_id = " . $kill->getVictimShip()->getClass()->getID(); $qry->execute($sql); } foreach ($kill->getInvolved() as $inv) { if ($alls[$inv->getPilotID()]) { continue; } $alls[$inv->getPilotID()] = 1; $qry->execute("SELECT 1 FROM kb3_sum_pilot WHERE psm_plt_id = " . $inv->getPilotID()); if (!$qry->recordCount()) { continue; } $sql = "UPDATE kb3_sum_pilot SET psm_kill_isk = psm_kill_isk - " . $difference . " WHERE psm_plt_id = " . $inv->getPilotID() . " AND psm_shp_id = " . $kill->getVictimShip()->getClass()->getID(); $qry->execute($sql); } }
/** * Return the raw killmail for this kill. * * @return string */ function getRawMail() { $kill = Kill::getByID($this->id); return $kill->getRawMail(); }
/** * Updates a Quest for a Character. If the Quest is completed and turned in * the Character may receive some Quest rewards. * * @param int $quest The ID of the quest * @param int $character_id The ID of the Character * @param boolean $turnIn Whenever this quest is turning in */ function update($quest_id = null, $character_id = null, $turnIn = false) { App::import('Model', 'CharactersQuest'); $CharactersQuest = new CharactersQuest(); $conditions = array(); $conditions['CharactersQuest.completed !='] = 'finished'; if (isset($quest_id)) { $conditions['CharactersQuest.quest_id'] = $quest_id; } if (isset($character_id)) { $conditions['CharactersQuest.character_id'] = $character_id; } $quests = $CharactersQuest->find('all', array('conditions' => array($conditions))); if (!empty($quests)) { // Inventory, Kill maybe needed App::import('Model', 'Inventory'); $Inventory = new Inventory(); App::import('Model', 'Kill'); $Kill = new Kill(); $charactersQuestsData = array(); $i = 0; foreach ($quests as $quest) { $charactersQuestsData[$i]['id'] = $quest['CharactersQuest']['id']; // Get the needed things (items, object, whatever) here $itemsNeeded = $this->ItemsQuest->find('list', array('conditions' => array('ItemsQuest.quest_id' => $quest['CharactersQuest']['quest_id'], 'ItemsQuest.type' => 'needed'), 'fields' => array('ItemsQuest.item_id', 'ItemsQuest.amount'))); $mobsNeeded = $this->MobsQuest->find('list', array('conditions' => array('MobsQuest.quest_id' => $quest['CharactersQuest']['quest_id']), 'fields' => array('MobsQuest.mob_id', 'MobsQuest.amount'))); $itemsRewards = $this->ItemsQuest->find('list', array('conditions' => array('ItemsQuest.quest_id' => $quest['CharactersQuest']['quest_id'], 'ItemsQuest.type' => 'reward'), 'fields' => array('ItemsQuest.item_id', 'ItemsQuest.amount'))); $statsRewards = $this->QuestsStat->find('list', array('conditions' => array('QuestsStat.quest_id' => $quest['CharactersQuest']['quest_id']), 'fields' => array('QuestsStat.stat_id', 'QuestsStat.amount'))); $completed = ''; if (empty($itemsNeeded) && empty($mobsNeeded)) { // Geen items nodig.. Omdat er op het moment niks anders is om te controleren updaten we deze quest... if ($turnIn == true && isset($character_id) && isset($quest_id)) { $charactersQuestsData[$i]['completed'] = 'finished'; } else { $charactersQuestsData[$i]['completed'] = 'yes'; } } else { $completed = 'yes'; // Default it's completed. $itemList = array(); $mobList = array(); foreach ($itemsNeeded as $item_id => $amount) { $itemList[] = $item_id; } foreach ($mobsNeeded as $mob_id => $amount) { $mobList[] = $mob_id; } // Er zijn items nodig voor deze quest.. Kijken of deze al gehaald zijn... // ItemsNeeded: item_id => aantal_needed $characterInventories = $Inventory->find('all', array('conditions' => array('Inventory.character_id' => $quest['CharactersQuest']['character_id'], 'Inventory.item_id' => $itemList), 'fields' => array('Inventory.item_id', 'COUNT(Inventory.item_id) as amount'), 'group' => array('Inventory.item_id'))); // Er zijn mobs nodig voor deze quest. Kijken of ze gekilled zijn NADAT de quest is geaccepteerd... $characterKills = $Kill->find('all', array('conditions' => array('Kill.character_id' => $quest['CharactersQuest']['character_id'], 'Kill.mob_id' => $mobList, 'Kill.type' => 'mob', 'Kill.created >=' => $quest['CharactersQuest']['created']), 'fields' => array('Kill.mob_id', 'COUNT(Kill.target_id) as amount'), 'group' => array('Kill.target_id'))); // We hebben een lijst met items wat nodig is.. // En dit wordt een lijst met wat we hebben... $itemsHave = array(); foreach ($characterInventories as $characterInventory) { $itemsHave[$characterInventory['Inventory']['item_id']] = $characterInventory[0]['amount']; } // Opslaan yes/no of de quest compleet is... foreach ($itemsNeeded as $item_id => $amount) { if (!isset($itemsHave[$item_id]) || isset($itemsHave[$item_id]) && $itemsHave[$item_id] < $itemsNeeded[$item_id]) { $completed = 'no'; } } // We hebben nu een lijst met mobs die nodig zijn, en een lijst met kills $mobsHave = array(); foreach ($characterKills as $characterKill) { $mobsHave[$characterKill['Kill']['mob_id']] = $characterKill[0]['amount']; } // Opslaan yes/no of de quest compleet is... foreach ($mobsNeeded as $mob_id => $amount) { if (!isset($mobsHave[$mob_id]) || isset($mobsHave[$mob_id]) && $mobsHave[$mob_id] < $mobsNeeded[$mob_id]) { $completed = 'no'; } } // Maybe the character is turning in the quest... if ($completed == 'yes' && $turnIn == true && isset($character_id) && isset($quest_id)) { $completed = 'finished'; } // Als de quest 'finished' is, dan moeten eventuele items uit de inventory verwijderd worden... // Dat kan hier. if ($completed == 'finished' && !empty($itemsNeeded)) { foreach ($itemsNeeded as $item_id => $amount) { for ($j = 1; $j <= $amount; $j++) { $Inventory->deleteAll(array('Inventory.character_id' => $quest['CharactersQuest']['character_id'], 'Inventory.item_id' => $item_id)); } } } $charactersQuestsData[$i]['completed'] = $completed; } // En voor het mooi, natuurlijk ook even de rewards geven... if ($completed == 'finished' && !empty($itemsRewards)) { App::import('Model', 'Drop'); $Drop = new Drop(); foreach ($itemsRewards as $item_id => $amount) { for ($j = 1; $j <= $amount; $j++) { $data = array(); // Bagid en index opvragen $bagIndex = $Drop->hasFreeSpace($quest['CharactersQuest']['character_id'], $item_id, true); $data['character_id'] = $quest['CharactersQuest']['character_id']; $data['item_id'] = $item_id; $data['index'] = $bagIndex['index']; $data['bag_id'] = $bagIndex['bag_id']; $Inventory->create(); $Inventory->save($data); } } } if ($completed == 'finished' && !empty($statsRewards)) { App::import('Model', 'CharactersStat'); $CharactersStat = new CharactersStat(); foreach ($statsRewards as $stat_id => $amount) { $statData = array(); $statData['character_id'] = $quest['CharactersQuest']['character_id']; // Kijken of deze stat al in de database bestaat $someStat = $CharactersStat->find('first', array('conditions' => array('CharactersStat.stat_id' => $stat_id, 'CharactersStat.character_id' => $quest['CharactersQuest']['character_id']))); if (!empty($someStat)) { $statData['id'] = $someStat['CharactersStat']['id']; $statData['amount'] = $someStat['CharactersStat']['amount'] + $amount; } else { $statData['amount'] = $amount; $statData['stat_id'] = $stat_id; } $CharactersStat->create(); $CharactersStat->save($statData); } } $i++; } $CharactersQuest->saveAll($charactersQuestsData); } }