Esempio n. 1
0
 /**
  * adds loot to a group of buyers
  *
  * @param int $raid_id
  * @param array $item_buyers
  * @param float $item_value
  * @param string $item_name
  * @param int $loottime optional
  * @param int $wowhead_id
  * @return boolean
  */
 public function addloot($raid_id, $item_buyers, $item_value, $item_name, $loottime = 0, $wowhead_id = 0)
 {
     global $user, $config;
     $this->loot = new \bbdkp\controller\loot\Loot();
     $this->loot->raid_id = $raid_id;
     $this->loot->item_value = $item_value;
     $this->loot->item_name = $item_name;
     $this->loot->wowhead_id = $wowhead_id;
     $raid = new \bbdkp\controller\raids\Raids($raid_id);
     $this->loot->dkpid = $raid->event_dkpid;
     $this->loot->item_date = $loottime;
     if ($loottime == 0) {
         $this->loot->item_date = $raid->raid_start;
     }
     $this->loot->item_group_key = $this->gen_group_key($this->loot->item_name, $this->loot->item_date, $raid_id + rand(10, 100));
     $this->loot->item_added_by = (string) $user->data['username'];
     $PointsController = new \bbdkp\controller\points\PointsController($raid->event_dkpid);
     $decayarray = array(0.0, 0);
     if ($config['bbdkp_decay'] == '1') {
         //diff between now and the raidtime
         $now = getdate();
         $timediff = mktime($now['hours'], $now['minutes'], $now['seconds'], $now['mon'], $now['mday'], $now['year']) - $this->loot->item_date;
         $decayarray = $PointsController->decay($this->loot->item_value, $timediff, 2);
     }
     $this->loot->item_decay = $decayarray[0];
     $this->loot->decay_time = $decayarray[1];
     // Add purchase(s) to items table
     $buyernames = '';
     foreach ($item_buyers as $key => $this_member_id) {
         $buyer = new \bbdkp\controller\members\Members($this_member_id);
         $this->loot->member_id = $this_member_id;
         $this->loot->member_name = $buyer->member_name;
         $this->loot->game_id = $buyer->game_id;
         if ($config['bbdkp_zerosum'] == 1) {
             $this->loot->item_zs = 1;
         }
         $this->loot->insert();
         $PointsController->addloot_update_dkprecord($this->loot->item_value, $this_member_id);
         if ($buyernames != '') {
             $buyernames .= ', ';
         }
         $buyernames .= $buyer->member_name;
         unset($buyer);
     }
     //if zerosum flag is set and  then distribute item value over raiders
     // item decay is not redistributed to zerosum earnings, because that is depreciated using raid decay
     if ($config['bbdkp_zerosum'] == 1) {
         foreach ($item_buyers as $key => $this_member_id) {
             $PointsController->zero_balance($this_member_id, $raid_id, $this->loot->item_value);
         }
     }
     unset($raid);
     // Logging
     $log_action = array('header' => 'L_ACTION_ITEM_ADDED', 'L_NAME' => $item_name, 'L_BUYERS' => $buyernames, 'L_RAID_ID' => $raid_id, 'L_VALUE' => $item_value, 'L_ADDED_BY' => $user->data['username']);
     $this->log_insert(array('log_type' => $log_action['header'], 'log_action' => $log_action));
     return true;
 }