Пример #1
0
 /**
  * Generate object
  *
  * @param int points
  * @param int pos
  * @param int access level (0 = dead)
  */
 public function __construct($points, $pos = 0, $access_level = 0)
 {
     // set correct points-rank
     $this->pointsRank = \Kofradia\Game\Rank\Points::getRank($points);
     // set correct pos-rank
     $this->posRank = \Kofradia\Game\Rank\Pos::getRank($pos);
     // dead?
     if ($access_level == 0) {
         $this->isDead = true;
     }
     // access?
     if (isset(\ess::$g['ranks_access_levels'][$access_level])) {
         $this->accessTitle = \ess::$g['ranks_access_levels'][$access_level];
     }
 }
Пример #2
0
 /**
  * Try to attack a specific player
  *
  * @param array Data about the player
  * @param int Cash to get
  * @return bool|null True on success
  */
 protected function handleSuccessPlayer($player, $cash)
 {
     $rank = \Kofradia\Game\Rank\Points::getRank($player['up_points']);
     $affect = $this->ut->getAffectedTable($rank);
     // can not have too little energy
     if ($player['up_energy'] < $affect['energy'] * 2) {
         return;
     }
     // now take money
     $a = \Kofradia\DB::get()->prepare("\n\t\t\tUPDATE users_players\n\t\t\tSET up_bank = IF(up_cash < ?, up_bank - ?, up_bank),\n\t\t\t\tup_cash = IF(up_cash >= ?, up_cash - ?, up_cash)\n\t\t\tWHERE up_id = ? AND (up_cash >= ? OR up_bank >= ?)");
     if (!$a->execute(array($cash, $cash, $cash, $cash, $player['up_id'], $cash, $cash))) {
         // did not succeed
         return;
     }
     $this->result->up = \player::get($player['up_id']);
     $this->result->cashLost = $cash;
     $this->result->fromBank = $this->result->up->data['up_cash'] < $cash;
     // TODO: this cannot be checked this way?
     // notify victim
     $this->result->up->add_log("utpressing", $this->ut->up->id, $cash);
     // log
     putlog("SPAMLOG", "%c11%bUTPRESSING:%b%c %u{$this->ut->up->data['up_name']}%u presset %u{$this->result->up->data['up_name']}%u for %u" . \game::format_cash($cash) . "%u" . ($this->result->fromBank ? ' (fra bankkonto)' : ''));
     \Kofradia\DB::get()->prepare("\n\t\t\tINSERT INTO utpressinger\n\t\t\tSET\n\t\t\t\tut_action_up_id = ?,\n\t\t\t\tut_affected_up_id = ?,\n\t\t\t\tut_b_id = ?,\n\t\t\t\tut_time = ?")->execute(array($this->ut->up->id, $this->result->up->id, $this->ut->up->data['up_b_id'], time()));
     // the victim always looses energy
     // but only health if the money comes from the hand
     // (don't really know why we made it this way)
     $this->result->up->energy_use($affect['energy']);
     if (!$this->result->fromBank) {
         $this->result->attack = $this->result->up->health_decrease($affect['health'], $this->ut->up, \player::ATTACK_TYPE_UTPRESSING);
     }
     return true;
 }