/** * 检查地块上物品是否成熟(比如鸡蛋、牛奶等) * @param $uid * @param $data Map record */ private function checkHarvestItem($data) { if (!$data || !$data->raw_materials) { return; } $store = new StoreModel($this->lang); $item = $store->getStoreById($data->id); if (!$item || !isset($item->collect_in) || !$item->collect_in) { return; } $collect_in = $item->collect_in / ($data->animals ? $data->animals : 1); $num = min(self::MAX_PRODUCTS - $data->products, min($data->raw_materials, floor(($this->timestamp - $data->start_time) / $collect_in))); $this->debugMsg('New Products: ' . $num); if ($num <= 0) { return; } // 没有饲料了 或者 存储位已满 开始时间为 0 if ($data->raw_materials == $num || $num + $data->products >= self::MAX_PRODUCTS) { $updata = array('products' => $num, 'raw_materials' => 0 - $num, 'start_time' => 0 - $data->start_time); } else { $updata = array('products' => $num, 'raw_materials' => 0 - $num, 'start_time' => $num * $collect_in); } // 更新地图 $map = new MapModel(); $ret = $map->increaseMapItem($this->uid, $data->x, $data->y, $updata); $this->debugMsg($map->getLastQuery()); return $ret; }