/** * Utfør kriminalitet */ public function utfor($id) { $this->options_load(); if (!isset($this->options[$id])) { throw new HSException("Fant ikke ønsket alternativ."); } $krim = $this->options[$id]; $ret = array("success" => false); // treffer vi med sannsynligheten? if (rand(0, 100) <= $krim['prob'] * 100) { // vellykket $ret['success'] = true; // gi penger til spilleren $cash = rand($krim['cash_min'], $krim['cash_max']); \Kofradia\DB::get()->exec("UPDATE users_players SET up_cash = up_cash + {$cash} WHERE up_id = {$this->up->id}"); $ret['cash'] = $cash; // trigger $this->up->update_money($cash, true, false); // gi rank til spilleren $ret['rank_change'] = $this->up->increase_rank($krim['points']); $ret['rank'] = $krim['points']; } // wanted nivå $ret['wanted_change'] = $this->up->fengsel_rank($krim['points'], $ret['success']); // oppdater kriminalitet-status $s = $ret['success'] ? 2 : 1; \Kofradia\DB::get()->exec("\n\t\t\tINSERT INTO kriminalitet_status\n\t\t\tSET krimid = {$id}, ks_up_id = {$this->up->id}, count = 1, success = " . ($ret['success'] ? 1 : 0) . ", last = " . time() . ", ks_strength = ks_strength + {$s}\n\t\t\tON DUPLICATE KEY\n\t\t\tUPDATE count = count + 1, success = success + VALUES(success), last = VALUES(last), ks_strength = VALUES(ks_strength)"); // oppdater kriminalitet \Kofradia\DB::get()->exec("\n\t\t\tUPDATE kriminalitet\n\t\t\tSET k_strength = k_strength + {$s}\n\t\t\tWHERE id = {$id}"); // trigger $this->up->trigger("kriminalitet", array("option" => $krim, "success" => $ret['success'])); // sett ned energien til spilleren $this->up->energy_use(self::ENERGY_KRIM); return $ret; }
/** * Utfør biltyveri */ public function biltyveri_utfor($option_id) { if (!isset($this->options[$option_id])) { throw new HSException("Ugyldig alternativ."); } $option = $this->options[$option_id]; // litt sannsynlighetsberegning $rand = rand(0, 1000); // test sannsynlighet $ret = array("success" => $rand <= $option['percent'] * 10); // traff vi på sannsynligheten? if ($ret['success']) { // hent alle bilene vi kan skaffe $result = \Kofradia\DB::get()->query("SELECT id, probability FROM gta WHERE min_rank <= " . $this->up->rank['number']); $biler = array(); $prob_total = 0; while ($row = $result->fetch()) { $prob_total += $row['probability']; $biler[$row['id']] = $row['probability']; } // finn en bil $rand = rand(1, $prob_total); $prob = 1; $bil = false; foreach ($biler as $id => $p) { $prob = $prob + $p; if ($rand < $prob) { // fant enhet $bil = $id; break; } } // hent bilen $result = \Kofradia\DB::get()->query("SELECT id, brand, model, min_rank, img_mini, probability FROM gta WHERE id = {$bil}"); // finn en tilfeldig bil bassert på sannsynligheten for bilen $bil = $result->fetch(); // beregn skade ut i fra sannsynligheten vi hadde $damage_min = 99 - floor($option['percent']) * (rand(1, 15) / 10); if ($damage_min < 0) { $damage_min = 0; } $damage_max = 99 - floor($option['percent']) * (rand(1, 10) / 10); if ($damage_max > 99) { $damage_max = 99; } if ($damage_min > $damage_max) { $damage = $damage_min; } $damage = rand($damage_min, $damage_max); // gi rankpoeng $ret['rank_change'] = $this->up->increase_rank(self::RANK_BILTYVERI); // gi bil \Kofradia\DB::get()->exec("INSERT INTO users_gta SET ug_up_id = " . $this->up->id . ", gtaid = {$bil['id']}, time = " . time() . ", b_id_org = " . $this->up->data['up_b_id'] . ", b_id = " . $this->up->data['up_b_id'] . ", damage = {$damage}"); $ret['gta'] = $bil; // finn en tekst? $result = \Kofradia\DB::get()->query("SELECT got_text FROM gta_options_text WHERE got_go_id = {$option['id']} ORDER BY RAND() LIMIT 1"); if ($row = $result->fetch()) { $replace_from = array("%bil%", "%skade%"); $replace_to = array("{$bil['brand']} {$bil['model']}", $damage); $ret['message'] = game::bb_to_html(str_replace($replace_from, $replace_to, $row['got_text'])); } else { $ret['message'] = "Du skaffet deg en <b>{$bil['brand']} {$bil['model']}</b> med <b>{$damage} %</b> skade!"; } } // wanted nivå $ret['wanted_change'] = $this->up->fengsel_rank(self::RANK_BILTYVERI, $ret['success']); // oppdater prosenter osv $increase = rand(0, $option['max_pos_change'] * 10) / 10; // for høy prosent? $percent = $option['percent']; if ($percent + $increase > $option['max_percent']) { $percent -= rand(0, $option['max_neg_change'] * 10) / 10; } else { $percent += $increase; } // ordne status if ($option['status_id']) { \Kofradia\DB::get()->exec("UPDATE gta_options_status SET percent = {$percent}, time_last = " . time() . ", count = count + 1" . ($ret['success'] ? ', success = success + 1' : '') . " WHERE id = {$option['status_id']}"); } else { \Kofradia\DB::get()->exec("INSERT INTO gta_options_status SET optionid = {$option['id']}, gos_up_id = " . $this->up->id . ", percent = {$percent}, time_last = " . time() . ", count = 1" . ($ret['success'] ? ', success = 1' : '')); } // energi $this->up->energy_use(self::ENERGY_BILTYVERI); // trigger $this->up->trigger("biltyveri", array("success" => $ret['success'], "option" => $option, "prob" => $option['percent'], "gta" => $ret['success'] ? $bil : null, "damage" => $ret['success'] ? $damage : null)); return $ret; }
/** * Bryte ut fra fengsel */ protected function bryt_ut() { // allerede i fengsel? if ($this->up->fengsel_check()) { ess::$b->page->add_message("Du er allerede i fengsel.", "error"); redirect::handle(); } // har vi ikke nok energi? if (!$this->up->energy_check(self::ENERGY)) { ess::$b->page->add_message("Du har ikke nok energi for å bryte ut andre spillere nå."); redirect::handle(); } $time = intval(postval('time')); // hent informasjon @(list($up_id, $expire, $dusor) = explode("_", $_POST['up_id'] . "_", 3)); $up_id = intval($up_id); $expire = intval($expire); $dusor = game::intval($dusor); $up = player::get($up_id); if (!$up) { ess::$b->page->add_message("Fant ikke brukeren.", "error"); redirect::handle(); } // ikke i fengsel lengre? $wait = $up->fengsel_wait(); if ($wait == 0) { ess::$b->page->add_message('<user id="' . $up->id . '" /> er nok allerede brutt ut!', "error"); redirect::handle(); } // ikke riktig tid? if ($up->data['up_fengsel_time'] != $expire) { ess::$b->page->add_message('<user id="' . $up->id . '" /> har kommet i fengsel på nytt. Prøv igjen.', "error"); redirect::handle(); } // feil dusør? if ($up->data['up_fengsel_dusor'] != $dusor) { ess::$b->page->add_message('Dusøren til <user id="' . $up->id . '" /> har endret seg. Prøv på nytt.', "error"); redirect::handle(); } // sett opp sannsynlighet $prob = self::calc_prob($wait, $up->data['up_wanted_level'] / 10); $points = self::calc_points($prob); // sett opp dusør $dusor_org = $up->data['up_fengsel_dusor']; $dusor = bcmul($up->data['up_fengsel_dusor'], self::DUSOR_PROFIT); // klarte vi det? $success = rand(0, 999) < $prob * 10; if ($success) { // penger man får for utbrytelsen $cash = round(max(0, 100 - $prob) / 100 * self::CASH_MAX); // sett som utbrytet $a = \Kofradia\DB::get()->exec("\n\t\t\t\tUPDATE users_players\n\t\t\t\tSET up_fengsel_time = " . (time() - 1) . ", up_fengsel_dusor_total_out = up_fengsel_dusor_total_out + up_fengsel_dusor, up_fengsel_dusor = 0\n\t\t\t\tWHERE up_id = {$up->id} AND up_fengsel_time = {$up->data['up_fengsel_time']} AND up_fengsel_dusor = {$up->data['up_fengsel_dusor']}"); if ($a == 0) { ess::$b->page->add_message('<user id="' . $up->id . '" /> er nok allerede brutt ut!', "error"); redirect::handle(); } $up->data['up_fengsel_time'] = time() - 1; $up->data['up_fengsel_dusor_total_out'] = bcadd($up->data['up_fengsel_dusor_total_out'], $up->data['up_fengsel_dusor']); $up->data['up_fengsel_dusor'] = 0; // oppdater antall utbrytninger og gi evt. penger \Kofradia\DB::get()->exec("\n\t\t\t\tUPDATE users_players\n\t\t\t\tSET up_fengsel_num_out_tries = up_fengsel_num_out_tries + 1, up_fengsel_num_out_success = up_fengsel_num_out_success + 1, up_cash = up_cash + {$cash} + {$dusor}, up_fengsel_dusor_total_in = up_fengsel_dusor_total_in + {$dusor}\n\t\t\t\tWHERE up_id = " . $this->up->id); $this->up->update_money(bcadd($cash, $dusor), true, false); // hendelse for spilleren som ble brutt ut $up->add_log("fengsel", $dusor_org > 0 ? $dusor_org : null, $this->up->id); $fengsel = $this->up->fengsel_rank($points, true); // penger, dusør og poeng vi mottar $mottok = array(); if ($cash > 0) { $mottok[] = game::format_cash($cash); } if ($dusor > 0) { $mottok[] = "dusøren på " . game::format_cash($dusor); } $mottok[] = game::format_num($points) . ' poeng'; // melding $msg = 'Du brøt ut <user id="' . $up->id . '" /> fra fengselet og mottok ' . sentences_list($mottok) . '.'; if ($fengsel > 0) { $msg .= ' Wanted nivået økte med ' . game::format_number($fengsel / 10, 1) . ' %.'; } ess::$b->page->add_message($msg); // logg putlog("LOG", "FENGSELUTBRYTNING: {$this->up->data['up_name']} brøt ut {$up->data['up_name']} fra fengsel (wait={$wait}, cash={$cash}, dusør={$dusor_org}, prob={$prob}, rank={$points})"); // rank $this->up->increase_rank($points); } else { // mislykket $fengsel = $this->up->fengsel_rank($points, false, true); // oppdater antall utbrytninger (kun forsøk) \Kofradia\DB::get()->exec("UPDATE users_players SET up_fengsel_num_out_tries = up_fengsel_num_out_tries + 1 WHERE up_id = " . $this->up->id); if ($fengsel > 0) { ess::$b->page->add_message('Mislykket! Wanted nivået økte med ' . game::format_number($fengsel / 10, 1) . ' %.'); } } // trigger $this->up->trigger("fengsel", array("success" => $success, "up" => $up, "wait" => $wait, "prob" => $prob, "points" => $points, "cash" => $success ? $cash : null, "dusor" => $dusor, "dusor_org" => $dusor_org)); $up->trigger("fengsel_affected", array("success" => $success, "up" => $this->up, "wait" => $wait, "prob" => $prob, "points" => $points, "cash" => $success ? $cash : null, "dusor" => $dusor, "dusor_org" => $dusor_org)); // energy $this->up->energy_use(self::ENERGY); redirect::handle(); }
/** * Utfør utpressing * * @return \Kofradia\Game\Utpressing\Result */ public function utpress(Utpressing\Option $option) { // bruk energi $this->up->energy_use(self::ENERGY); return $option->attempt(); }