/** * 赋予玩家一件装备 * @param $intEquipmentId * @param int $plus * @return \App\OwnedEquipment|bool */ public function appendEquipment($intEquipmentId, $plus = 0) { // 取得装备Master情报 $objEquipment = Equipment::find($intEquipmentId); // 装备情报不正确的情况 if (empty($objEquipment)) { return false; } // 初始化玩家装备 $objOwnedEquipment = new OwnedEquipment(); // 玩家装备情报Set $objOwnedEquipment->createOwnedEquipment($intEquipmentId, $this->id, $plus); if ($objOwnedEquipment->save()) { return $objOwnedEquipment; } return false; }
public function equipmentBox() { $playerId = Input::get('player_id'); return Response::json(OwnedEquipment::where('player_id', $playerId)->get()); }
/** * 装备 * *必须在未装备的前提下,才可以装备 * @param $intTargetEquipmentId * @param int $intOwnedEquipmentId */ public function equip($intTargetEquipmentId, $intOwnedEquipmentId = 0) { // 不正目标装备位置ID if ($intTargetEquipmentId <= 0 || $intTargetEquipmentId > self::intMaxEquipmentCount) { return; } // Transaction DB::beginTransaction(); // 装备实装 try { if ($intOwnedEquipmentId != 0) { // 装备目标装备 $objOwnedEquipment = OwnedEquipment::find($intOwnedEquipmentId); // 目标玩家装备是否存在 if (empty($objOwnedEquipment) || !$objOwnedEquipment) { throw new Exception('Wrong Equipment'); } // 目标装备是否装备中 if ($objOwnedEquipment->owned_card_id > 0) { throw new Exception('Already Equipmented'); } // 取得目标装备详细 $objOwnedEquipment->getEquipmentDetail(); $objEquipment = $objOwnedEquipment->_objEquipment; // 目标装备位置是否可以装备此装备 if ($intTargetEquipmentId != $objEquipment->type) { throw new Exception('Wrong Equipment Type'); } // 进行装备 switch ($intTargetEquipmentId) { case 1: // 目标装备位是否有装备 if ($this->owned_equipment_id_1 > 0) { // 原玩家装备对象取得 $objFromOwnedEquipment = OwnedEquipment::find($this->owned_equipment_id_1); // 重置原玩家装备玩家卡片ID $objFromOwnedEquipment->owned_card_id = 0; // 新装备set $objOwnedEquipment->owned_card_id = $this->id; // 重置装备 $this->owned_equipment_id_1 = $objOwnedEquipment->id; // 保存修改 if (!$objFromOwnedEquipment->save() || !$this->save() || !$objOwnedEquipment->save()) { throw new Exception('Save Failed'); } } else { // 新装备set $objOwnedEquipment->owned_card_id = $this->id; // 配置装备 $this->owned_equipment_id_1 = $objOwnedEquipment->id; // 保存修改 if (!$this->save() || !$objOwnedEquipment->save()) { throw new Exception('Save Failed'); } } break; case 2: // 目标装备位是否有装备 if ($this->owned_equipment_id_1 > 0) { // 原玩家装备对象取得 $objFromOwnedEquipment = OwnedEquipment::find($this->owned_equipment_id_1); // 重置原玩家装备玩家卡片ID $objFromOwnedEquipment->owned_card_id = 0; // 新装备set $objOwnedEquipment->owned_card_id = $this->id; // 重置装备 $this->owned_equipment_id_1 = $objOwnedEquipment->id; // 保存修改 if (!$objFromOwnedEquipment->save() || !$this->save() || !$objOwnedEquipment->save()) { throw new Exception('Save Failed'); } } else { // 新装备set $objOwnedEquipment->owned_card_id = $this->id; // 配置装备 $this->owned_equipment_id_1 = $objOwnedEquipment->id; // 保存修改 if (!$this->save() || !$objOwnedEquipment->save()) { throw new Exception('Save Failed'); } } break; case 3: // 目标装备位是否有装备 if ($this->owned_equipment_id_1 > 0) { // 原玩家装备对象取得 $objFromOwnedEquipment = OwnedEquipment::find($this->owned_equipment_id_1); // 重置原玩家装备玩家卡片ID $objFromOwnedEquipment->owned_card_id = 0; // 新装备set $objOwnedEquipment->owned_card_id = $this->id; // 重置装备 $this->owned_equipment_id_1 = $objOwnedEquipment->id; // 保存修改 if (!$objFromOwnedEquipment->save() || !$this->save() || !$objOwnedEquipment->save()) { throw new Exception('Save Failed'); } } else { // 新装备set $objOwnedEquipment->owned_card_id = $this->id; // 配置装备 $this->owned_equipment_id_1 = $objOwnedEquipment->id; // 保存修改 if (!$this->save() || !$objOwnedEquipment->save()) { throw new Exception('Save Failed'); } } break; case 4: // 目标装备位是否有装备 if ($this->owned_equipment_id_1 > 0) { // 原玩家装备对象取得 $objFromOwnedEquipment = OwnedEquipment::find($this->owned_equipment_id_1); // 重置原玩家装备玩家卡片ID $objFromOwnedEquipment->owned_card_id = 0; // 新装备set $objOwnedEquipment->owned_card_id = $this->id; // 重置装备 $this->owned_equipment_id_1 = $objOwnedEquipment->id; // 保存修改 if (!$objFromOwnedEquipment->save() || !$this->save() || !$objOwnedEquipment->save()) { throw new Exception('Save Failed'); } } else { // 新装备set $objOwnedEquipment->owned_card_id = $this->id; // 配置装备 $this->owned_equipment_id_1 = $objOwnedEquipment->id; // 保存修改 if (!$this->save() || !$objOwnedEquipment->save()) { throw new Exception('Save Failed'); } } break; case 5: // 目标装备位是否有装备 if ($this->owned_equipment_id_1 > 0) { // 原玩家装备对象取得 $objFromOwnedEquipment = OwnedEquipment::find($this->owned_equipment_id_1); // 重置原玩家装备玩家卡片ID $objFromOwnedEquipment->owned_card_id = 0; // 新装备set $objOwnedEquipment->owned_card_id = $this->id; // 重置装备 $this->owned_equipment_id_1 = $objOwnedEquipment->id; // 保存修改 if (!$objFromOwnedEquipment->save() || !$this->save() || !$objOwnedEquipment->save()) { throw new Exception('Save Failed'); } } else { // 新装备set $objOwnedEquipment->owned_card_id = $this->id; // 配置装备 $this->owned_equipment_id_1 = $objOwnedEquipment->id; // 保存修改 if (!$this->save() || !$objOwnedEquipment->save()) { throw new Exception('Save Failed'); } } break; } } else { // 卸下装备 switch ($intTargetEquipmentId) { case 1: // 目标装备位是否有装备 if ($this->owned_equipment_id_1 > 0) { // 原玩家装备对象取得 $objFromOwnedEquipment = OwnedEquipment::find($this->owned_equipment_id_1); // 重置玩家卡片ID $objFromOwnedEquipment->owned_card_id = 0; // 重置装备 $this->owned_equipment_id_1 = 0; // 保存修改 if (!$objFromOwnedEquipment->save() || !$this->save()) { throw new Exception('Save Failed'); } } else { throw new Exception('Cant Null To Null'); } break; case 2: // 目标装备位是否有装备 if ($this->owned_equipment_id_2 > 0) { // 原玩家装备对象取得 $objFromOwnedEquipment = OwnedEquipment::find($this->owned_equipment_id_2); // 重置玩家卡片ID $objFromOwnedEquipment->owned_card_id = 0; // 重置装备 $this->owned_equipment_id_2 = 0; // 保存修改 if (!$objFromOwnedEquipment->save() || !$this->save()) { throw new Exception('Save Failed'); } } else { throw new Exception('Cant Null To Null'); } break; case 3: // 目标装备位是否有装备 if ($this->owned_equipment_id_3 > 0) { // 原玩家装备对象取得 $objFromOwnedEquipment = OwnedEquipment::find($this->owned_equipment_id_3); // 重置玩家卡片ID $objFromOwnedEquipment->owned_card_id = 0; // 重置装备 $this->owned_equipment_id_3 = 0; // 保存修改 if (!$objFromOwnedEquipment->save() || !$this->save()) { throw new Exception('Save Failed'); } } else { throw new Exception('Cant Null To Null'); } break; case 4: // 目标装备位是否有装备 if ($this->owned_equipment_id_4 > 0) { // 原玩家装备对象取得 $objFromOwnedEquipment = OwnedEquipment::find($this->owned_equipment_id_4); // 重置玩家卡片ID $objFromOwnedEquipment->owned_card_id = 0; // 重置装备 $this->owned_equipment_id_4 = 0; // 保存修改 if (!$objFromOwnedEquipment->save() || !$this->save()) { throw new Exception('Save Failed'); } } else { throw new Exception('Cant Null To Null'); } break; case 5: // 目标装备位是否有装备 if ($this->owned_equipment_id_5 > 0) { // 原玩家装备对象取得 $objFromOwnedEquipment = OwnedEquipment::find($this->owned_equipment_id_5); // 重置玩家卡片ID $objFromOwnedEquipment->owned_card_id = 0; // 重置装备 $this->owned_equipment_id_5 = 0; // 保存修改 if (!$objFromOwnedEquipment->save() || !$this->save()) { throw new Exception('Save Failed'); } } else { throw new Exception('Cant Null To Null'); } break; case 6: // 目标装备位是否有装备 if ($this->owned_equipment_id_6 > 0) { // 原玩家装备对象取得 $objFromOwnedEquipment = OwnedEquipment::find($this->owned_equipment_id_6); // 重置玩家卡片ID $objFromOwnedEquipment->owned_card_id = 0; // 重置装备 $this->owned_equipment_id_6 = 0; // 保存修改 if (!$objFromOwnedEquipment->save() || !$this->save()) { throw new Exception('Save Failed'); } } else { throw new Exception('Cant Null To Null'); } break; } } // 重新计算卡片数据 $this->setUpStatus(); DB::commit(); } catch (Exception $e) { // TODO Dev Log DB::rollback(); } }
/** * 显示玩家装备库 */ public function equipmentBox() { echo "Player [" . $this->_intPlayerId . "] 装备Box <br />"; // 取得玩家装备列表 $lstEquipments = OwnedEquipment::where('player_id', $this->_intPlayerId)->get(); $intNum = 0; foreach ($lstEquipments as $objOwnedEquipment) { $intNum++; $objEquipmentInfo = Equipment::find($objOwnedEquipment->equipment_id); echo "No.[" . $intNum . "]装备名:" . $objEquipmentInfo->name_cn . " "; echo "主属性[TODO]值:{$objEquipmentInfo->status_1_value}(+{$objOwnedEquipment->status_1_add})"; if ($objOwnedEquipment->owned_card_id != 0) { $objOwnedCard = OwnedCard::find($objOwnedEquipment->owned_card_id); echo "(装备在:<a href='card-detail?player_id={$this->_intPlayerId}&owned_card_id={$objOwnedCard->id}'>{$objOwnedCard->getCardInfo()->name_cn}</a>)"; } echo "<br />"; } }
public function equipment() { // 把装备装备到卡片 $playerId = Input::get('player_id', 0); $ownedCardId = Input::get('owned_card_id', 0); $ownedEquipmentId = Input::get('owned_equipment_id', 0); $ownedCard = OwnedCard::find($ownedCardId); $ownedEquipment = OwnedEquipment::find($ownedEquipmentId); // Ownerc Check if ($ownedCard->player_id != $playerId || $ownedEquipment->player_id != $playerId) { } // 装备限制Check $equipment = Equipment::find($ownedEquipment->equipment_id); if ($equipment->attr != 0) { if ($ownedCard->attr != $equipment->attr) { // Error } } if ($equipment->job != 0) { if ($ownedCard->job != $equipment->job) { // Error } } if ($equipment->race != 0) { if ($ownedCard->race != $equipment->race) { // Error } } if ($equipment->rare != 0) { } // 装备中的卡片 $equipmentCardId = $ownedEquipment->owned_card_id; // 对象卡片原有装备 $cardEquipmentId = $ownedCard->owned_equipment_id; switch ($equipment->type) { case 1: // 武器 // 卸下 if ($equipmentCardId != 0) { $equipmentCard = OwnedCard::find($ownedEquipment->owned_card_id); $equipmentCard->owned_equipment_id_1 = 0; $ownedEquipment->owned_card_id = 0; // 卡片数据更新 $equipmentCard->setUpStatus(); } if ($cardEquipmentId != 0) { $cardEquipment = OwnedEquipment::find($cardEquipmentId); $cardEquipment->owned_card_id = 0; $cardEquipment->save(); } // 装备 $ownedCard->owned_equipment_id_1 = $ownedEquipment->id; $ownedEquipment->owned_card_id = $ownedCard->id; $ownedCard->setUpStatus(); break; case 2: // 头部 // 卸下 if ($equipmentCardId != 0) { $equipmentCard = OwnedCard::find($ownedEquipment->owned_card_id); $equipmentCard->owned_equipment_id_2 = 0; $ownedEquipment->owned_card_id = 0; // 卡片数据更新 $equipmentCard->setUpStatus(); } if ($cardEquipmentId != 0) { $cardEquipment = OwnedEquipment::find($cardEquipmentId); $cardEquipment->owned_card_id = 0; $cardEquipment->save(); } // 装备 $ownedCard->owned_equipment_id_2 = $ownedEquipment->id; $ownedEquipment->owned_card_id = $ownedCard->id; $ownedCard->setUpStatus(); break; case 3: // 胸部 // 卸下 if ($equipmentCardId != 0) { $equipmentCard = OwnedCard::find($ownedEquipment->owned_card_id); $equipmentCard->owned_equipment_id_3 = 0; $ownedEquipment->owned_card_id = 0; // 卡片数据更新 $equipmentCard->setUpStatus(); } if ($cardEquipmentId != 0) { $cardEquipment = OwnedEquipment::find($cardEquipmentId); $cardEquipment->owned_card_id = 0; $cardEquipment->save(); } // 装备 $ownedCard->owned_equipment_id_3 = $ownedEquipment->id; $ownedEquipment->owned_card_id = $ownedCard->id; $ownedCard->setUpStatus(); break; case 4: // 脚部 // 卸下 if ($equipmentCardId != 0) { $equipmentCard = OwnedCard::find($ownedEquipment->owned_card_id); $equipmentCard->owned_equipment_id_4 = 0; $ownedEquipment->owned_card_id = 0; // 卡片数据更新 $equipmentCard->setUpStatus(); } if ($cardEquipmentId != 0) { $cardEquipment = OwnedEquipment::find($cardEquipmentId); $cardEquipment->owned_card_id = 0; $cardEquipment->save(); } // 装备 $ownedCard->owned_equipment_id_4 = $ownedEquipment->id; $ownedEquipment->owned_card_id = $ownedCard->id; $ownedCard->setUpStatus(); break; case 5: // 耳环 // 卸下 if ($equipmentCardId != 0) { $equipmentCard = OwnedCard::find($ownedEquipment->owned_card_id); $equipmentCard->owned_equipment_id_5 = 0; $ownedEquipment->owned_card_id = 0; // 卡片数据更新 $equipmentCard->setUpStatus(); } if ($cardEquipmentId != 0) { $cardEquipment = OwnedEquipment::find($cardEquipmentId); $cardEquipment->owned_card_id = 0; $cardEquipment->save(); } // 装备 $ownedCard->owned_equipment_id_5 = $ownedEquipment->id; $ownedEquipment->owned_card_id = $ownedCard->id; $ownedCard->setUpStatus(); break; case 6: // 项链 // 卸下 if ($equipmentCardId != 0) { $equipmentCard = OwnedCard::find($ownedEquipment->owned_card_id); $equipmentCard->owned_equipment_id_6 = 0; $ownedEquipment->owned_card_id = 0; // 卡片数据更新 $equipmentCard->setUpStatus(); } if ($cardEquipmentId != 0) { $cardEquipment = OwnedEquipment::find($cardEquipmentId); $cardEquipment->owned_card_id = 0; $cardEquipment->save(); } // 装备 $ownedCard->owned_equipment_id_6 = $ownedEquipment->id; $ownedEquipment->owned_card_id = $ownedCard->id; $ownedCard->setUpStatus(); break; default: # code... break; } $ownedEquipment->save(); return Response::json($ownedCard); // 数据更新 // if ($ownedEquipment->atk > 0) { // $ownedCard->updateAtk(); // } }