_rspData(array( 'list' => $metaList )); } public function avatarList(){ $avatarList = array(); Avatar::getAvatarList(function ($row) use (&$avatarList){ array_push($avatarList,Avatar::toDto($row)); }); $this->_rspData(array( 'list' => $avatarList )); } public function equip(){ $heroUniid = trim(getReqVal('hero_uniid', 0)); $avatarUniid = trim(getReqVal('avatar_uniid', 0)); $heroDb = Hero::find($heroUniid); if (!$heroDb){ $this->_rspErr(1, 'hero_uniid error'); return; } $avatarDb = Avatar::find($avatarUniid); if (!$avatarDb){ $this->_rspErr(1, 'avatar_uniid error'); return; } if ($heroDb['idx'] == $avatarDb['hero_idx']){ $this->_rspErr(1, 'avatar_uniid error'); return; } $randAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array()); $itemMeta = \mt\Item::get($avatarDb['item_id']); $quality = 1; foreach ($randAttr as $value){ $quality = max($quality,$value['quality']); } switch ($itemMeta['quality']){ case 2 : { if ($quality < 3){ $this->_rspErr(1, 'Can not meet the wearing condition'); return; } } break; case 3 :{ if ($quality < 4){ $this->_rspErr(1, 'Can not meet the wearing condition'); return; } } break; case 4 :{ if ($quality < 5){ $this->_rspErr(1, 'Can not meet the wearing condition'); return; } } } Avatar::equipUpdate($avatarDb,$heroUniid); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function remove(){ $avatarUniid = trim(getReqVal('avatar_uniid', 0)); $avatarDb = Avatar::find($avatarUniid); if (!$avatarDb){ $this->_rspErr(1, 'avatar_uniid error'); return; } Avatar::update($avatarUniid,array( 'hero_idx' => null, 'status' => 0, 'modifytime' => myself()->_getNowTime(), )); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function clearAvatar(){ $heroUniid = trim(getReqVal('hero_uniid', 0)); $heroDb = Hero::find($heroUniid); if (!$heroDb){ $this->_rspErr(1, 'hero_uniid error'); return; } $avatarDbs = Avatar::getAvatarByHeroIdx($heroUniid); if (!$avatarDbs){ $this->_rspErr(1, 'Meaningless operation'); return; } foreach ($avatarDbs as $avatarDb){ Avatar::update($avatarDb['idx'],array( 'hero_idx' => null, 'status' => 0, 'modifytime' => myself()->_getNowTime(), )); } $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function buyAvatarS(){ $itemId = trim(getReqVal('item_id', 0)); $itemMeta = \mt\Item::get($itemId); if (!$itemMeta || $itemMeta['type'] != \mt\Item::AVATAR_TYPE){ $this->_rspErr(1, 'item id error'); return; } //检验钻石是否足够 并消耗钻石 $costItems = array( array( 'item_id' => V_ITEM_DIAMOND, 'item_num' => $itemMeta['diamond'] ), ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); Avatar::addAvatar($itemMeta); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } }