Exemple #1
0
    /**
     * Spiller blir drept
     * @param bool $instant døde spilleren momentant?
     * @param player $by_up hvem som forårsaket dødsfallet
     */
    public function dies($instant, player $by_up = NULL)
    {
        // er ikke aktivert?
        if (!$this->active) {
            return false;
        }
        $ret = array();
        if ($instant) {
            $ret['penger_bank'] = 0;
        }
        $prev_level = $this->data['up_access_level'];
        $this->active = false;
        $this->data['up_access_level'] = 0;
        $this->data['up_deactivated_time'] = time();
        $this->data['up_deactivated_up_id'] = $by_up ? $by_up->id : NULL;
        $this->data['up_deactivated_dead'] = $instant ? 1 : 2;
        $this->data['up_deactivated_reason'] = NULL;
        $this->data['up_deactivated_note'] = NULL;
        $this->data['up_deactivated_points'] = $this->data['up_points'];
        $this->data['up_deactivated_rank_pos'] = $this->data['upr_rank_pos'];
        // deaktiver spilleren
        $by_up_id = $by_up ? $by_up->id : 'NULL';
        $a = \Kofradia\DB::get()->exec("\n\t\t\tUPDATE users_players LEFT JOIN users_players_rank ON upr_up_id = up_id\n\t\t\tSET\n\t\t\t\tup_access_level = 0, up_deactivated_time = {$this->data['up_deactivated_time']}, up_deactivated_up_id = {$by_up_id}, up_deactivated_dead = {$this->data['up_deactivated_dead']},\n\t\t\t\tup_deactivated_reason = NULL, up_deactivated_note = NULL,\n\t\t\t\tup_deactivated_points = up_points, up_deactivated_rank_pos = upr_rank_pos\n\t\t\tWHERE up_id = {$this->id} AND up_access_level != 0");
        if ($a == 0) {
            return false;
        }
        // har vi noen som skal få penger vi har i banken?
        if ($this->data['up_bank'] > 0) {
            // hent liste over FF-id vi er med i
            $ff_list = $this->get_ff_id_list();
            $num_ff = count($ff_list);
            if ($num_ff > 0) {
                $ff_ids = implode(",", $ff_list);
                // familier som skal få penger
                $result = \Kofradia\DB::get()->query("\n\t\t\t\t\tSELECT ff_id\n\t\t\t\t\tFROM ff\n\t\t\t\t\tWHERE ff_id IN ({$ff_ids}) AND ff_type = 1 AND ff_is_crew = 0");
                $num_ff = $result->rowCount();
            }
            // har vi noen familier eller ble drept instant
            if ($num_ff > 0 || $instant) {
                // hent ut beløpet i banken og sett bankkontoen til 10 %
                \Kofradia\DB::get()->exec("\n\t\t\t\t\tUPDATE users_players, (SELECT up_id ref_up_id, @bank := up_bank FROM users_players WHERE up_id = {$this->id}) ref\n\t\t\t\t\tSET up_bank = up_bank * 0.1\n\t\t\t\t\tWHERE ref_up_id = up_id");
                $bank = \Kofradia\DB::get()->query("SELECT @bank")->fetchColumn(0);
                if ($num_ff > 0 && $instant) {
                    $f_ff = 0.3;
                    $f_up = 0.6;
                } elseif ($num_ff > 0) {
                    $f_ff = 0.9;
                    $f_up = 0;
                } else {
                    $f_ff = 0;
                    $f_up = 0.9;
                }
                // noe til familie?
                if ($f_ff > 0) {
                    // hvor mye hver familie skal få
                    $ff_bank_each = bcdiv(bcmul($bank, $f_ff), $num_ff);
                    // del ut pengene til familiene
                    while ($row = $result->fetch()) {
                        ff::bank_static(ff::BANK_DONASJON, $ff_bank_each, $row['ff_id'], "Testamentert", $this->id);
                    }
                }
                // noe til angriper?
                if ($f_up > 0) {
                    $ret['penger_bank'] = bcmul($bank, $f_up);
                    $by_up->data['up_cash'] = bcadd($by_up->data['up_cash'], $ret['penger_bank']);
                    \Kofradia\DB::get()->exec("UPDATE users_players SET up_cash = up_cash + {$ret['penger_bank']} WHERE up_id = {$by_up->id}");
                }
            }
        }
        $info = $instant ? 'ble drept av ' . $by_up->data['up_name'] : ($by_up ? 'døde av skadene påført av ' . $by_up->data['up_name'] : 'døde pga. lav helse og energi');
        putlog("INFO", "%bDrept%b: Spilleren {$this->data['up_name']} " . ($instant ? 'ble drept ' : 'døde av skader ') . $this->generate_profile_url());
        putlog("DF", "%bDrept%b: Spilleren {$this->data['up_name']} {$info} " . $this->generate_minside_url());
        // hent familier
        $familier = array();
        $list = $this->get_ff_list();
        foreach ($list as $row) {
            if ($row['ff_type'] != 1 || $row['ff_is_crew'] != 0) {
                continue;
            }
            $familier[] = '<a href="' . ess::$s['relative_path'] . '/ff/?ff_id=' . $row['ff_id'] . '">' . htmlspecialchars($row['ff_name']) . '</a>';
        }
        // live-feed
        livefeed::add_row('<user id="' . $this->id . '" />' . (count($familier) > 0 ? ' (medlem av ' . implode(", ", $familier) . ')' : '') . ' ' . ($instant ? 'ble drept' : ($by_up ? 'døde av et tidligere angrep' : 'døde pga. lav helse og energi')) . '.');
        $ret = array_merge($ret, $this->release_relations($prev_level, $by_up, $instant));
        // behandle hitlist
        $ret = array_merge($ret, etterlyst::player_dies($this, $by_up, $instant));
        // informer spilleren på e-post
        $email = new email();
        $email->text = 'Hei,

Din spiller ' . $this->data['up_name'] . ' ' . ($instant ? 'har blitt drept av en annen spiller' : 'døde på grunn av lav energi og lav helse') . '.

Du kan se informasjon om din spiller og opprette en ny spiller ved å logge inn på din bruker.

--
www.kofradia.no';
        $email->send($this->user->data['u_email'], "Din spiller {$this->data['up_name']} " . ($instant ? 'har blitt drept' : 'er død'));
        // legg til hendelse hos spilleren
        $this->add_log("dead", $instant ? 1 : 0);
        return $ret;
    }