Exemplo n.º 1
0
 public function cardBox()
 {
     // 取得玩家
     $intPlayerId = Input::get('player_id');
     $lstCards = OwnedCard::where('player_id', $intPlayerId)->get();
     return Response::json($lstCards);
 }
Exemplo n.º 2
0
 /**
  * 构建方法
  */
 public function __construct(array $attributes = array())
 {
     // 继承
     parent::__construct($attributes);
     // Eloquent
     // 玩家卡片详细
     $this->_ownedCardDetail = OwnedCard::find($this->owned_card_id);
 }
Exemplo n.º 3
0
 /**
  * 玩家卡片取得处理
  */
 public function cardBox()
 {
     // 玩家ID获取
     $intPlayerId = Input::get('player_id');
     // 玩家所持卡片全取得
     $lstCard = OwnedCard::where('player_id', $intPlayerId)->get();
     return view('admin.player.card-box')->withCards(Card::all())->withAttrs(Attr::all())->withRaces(Race::all())->withJobs(Job::all())->withSkills(Skill::all())->withOwnedCards($lstCard);
 }
Exemplo n.º 4
0
 /**
  * 我方卡片的战斗单元构造方法
  * @param $intOwnedCardId
  * @param $position
  */
 public function initWithAlien($intOwnedCardId, $position)
 {
     $this->position = $position;
     $objOwnedCard = OwnedCard::find($intOwnedCardId);
     // TODO 战斗各种加成
     // 卡片ID不正的情况
     // 数据整合
     $this->hp = $objOwnedCard->hp;
     $this->atk = $objOwnedCard->atk;
     $this->def = $objOwnedCard->def;
     $this->spd = $objOwnedCard->spd;
     $this->int = $objOwnedCard->int;
     $this->card_id = $objOwnedCard->card_id;
     $this->alive = true;
 }
Exemplo n.º 5
0
 /**
  * 开始一场战斗
  * @return mixed
  */
 public function start()
 {
     // TODO 各种Check
     // 各项参数取得
     $intPlayerId = Input::get('player_id', 0);
     $intDungeonId = Input::get('dungeon_id', 0);
     $strType = Input::get('type', 'normal');
     $now = Carbon::now();
     // 有没有进行中的战斗
     $objBattle = Battle::where('player_id', $intPlayerId)->where('dungeon_id', $intDungeonId)->where('end_datetime', '>', $now)->orderBy('id', 'DESC')->first();
     // 存在进行中的战斗
     if (!empty($objBattle)) {
         return Response::json($objBattle->toArray());
     }
     // 取得地下城信息
     $lstDungeonInfo = Dungeon::getInfo($intDungeonId);
     // 没有找到该当地下城
     if (empty($lstDungeonInfo)) {
         return 'Dungeon not exist';
     }
     // 取得地下城对象
     $objDungeon = $lstDungeonInfo['info'];
     // Team TODO
     $intTeamId = Input::get('team_id');
     $objTeam = Team::find($intTeamId);
     if (!$objTeam) {
         return 'NG TeamId';
     }
     // 队伍的PlayerId不一致的情况
     if ($objTeam->player_id != $intPlayerId) {
         return 'Wrong PlayerId For Team';
     }
     // 冒险做成
     $objBattle = new Battle();
     // 冒险情报的各种设定
     $objBattle->player_id = $intPlayerId;
     $objBattle->dungeon_id = $intDungeonId;
     $objBattle->floor = $objDungeon->floor;
     $objBattle->current_floor = 0;
     $objBattle->type = $strType;
     $objBattle->start_datetime = $now->toDateTimeString();
     $objBattle->end_datetime = $now->addMinutes($objDungeon->floor)->toDateTimeString();
     // 出战队伍信息保存在冒险信息中
     if ($objTeam->position_1_owned_card_id != 0) {
         $ownedCard1 = OwnedCard::find($objTeam->position_1_owned_card_id);
         $objBattle->position_1 = $ownedCard1->id;
     }
     if ($objTeam->position_2_owned_card_id != 0) {
         $ownedCard2 = OwnedCard::find($objTeam->position_2_owned_card_id);
         $objBattle->position_2 = $ownedCard2->id;
     }
     if ($objTeam->position_3_owned_card_id != 0) {
         $ownedCard3 = OwnedCard::find($objTeam->position_3_owned_card_id);
         $objBattle->position_3 = $ownedCard3->id;
     }
     if ($objTeam->position_4_owned_card_id != 0) {
         $ownedCard4 = OwnedCard::find($objTeam->position_4_owned_card_id);
         $objBattle->position_4 = $ownedCard4->id;
     }
     if ($objTeam->position_5_owned_card_id != 0) {
         $ownedCard5 = OwnedCard::find($objTeam->position_5_owned_card_id);
         $objBattle->position_5 = $ownedCard5->id;
     }
     if ($objTeam->position_6_owned_card_id != 0) {
         $ownedCard6 = OwnedCard::find($objTeam->position_6_owned_card_id);
         $objBattle->position_6 = $ownedCard6->id;
     }
     if ($objBattle->save()) {
         return Response::json($objBattle->toArray());
     }
 }
Exemplo n.º 6
0
 public function initTeam()
 {
     $intPlayerId = Input::get('player_id', 0);
     // 目前已经生成Team数量确认
     /* 玩家可用Team数量确认
      * Lv.1 ~ Lv.10   1Team
      * Lv.11 ~ Lv.20  2Team
      * Lv.21 ~ Lv.50  3Team
      * Lv.51 ~ Lv.100 4Team
      * 氪金玩家        +1Team
      */
     $objTeam = new Team();
     $objTeam->player_id = $intPlayerId;
     $objTeam->team_no = 1;
     // 该用户的第一个队伍
     $objTeam->team_name = "Team01";
     $firstCard = OwnedCard::where('player_id', $intPlayerId)->orderBy('id', 'ASC')->first();
     $objTeam->position_1_owned_card_id = $firstCard->id;
     $objTeam->total_cost = $firstCard->getCost();
     $objTeam->save();
     $objTeamBk = Team::find($objTeam->id);
     // 20151012 TeamMember Table 初始化
     for ($intPosition = 1; $intPosition <= 6; $intPosition++) {
         $objTeamMember = new TeamMember();
         $objTeamMember->team_id = $objTeamBk->id;
         $objTeamMember->position = $intPosition;
         $objTeamMember->player_id = $objTeamBk->player_id;
         if ($intPosition == 1) {
             $objTeamMember->card_id = $firstCard->card_id;
             $objTeamMember->owned_card_id = $firstCard->id;
         }
         $objTeamMember->save();
         switch ($intPosition) {
             case 1:
                 $objTeamBk->position_1_member_id = $objTeamMember->id;
                 break;
             case 2:
                 $objTeamBk->position_2_member_id = $objTeamMember->id;
                 break;
             case 3:
                 $objTeamBk->position_3_member_id = $objTeamMember->id;
                 break;
             case 4:
                 $objTeamBk->position_4_member_id = $objTeamMember->id;
                 break;
             case 5:
                 $objTeamBk->position_5_member_id = $objTeamMember->id;
                 break;
             case 6:
                 $objTeamBk->position_6_member_id = $objTeamMember->id;
                 break;
             default:
                 # code...
                 break;
         }
         // 20151103 追加
         $firstCard->team_id = $objTeam->id;
         $firstCard->save();
     }
     $objTeamBk->save();
     return Response::json($objTeamBk->toArray());
 }
Exemplo n.º 7
0
 /**
  * 交换队员处理
  * Case1:该当位置为空
  * Case2:该当位置有队员,换人对象未入队
  * Case3:该当位置有队员,换人对象入队
  * Case4:该当位置有队员,换人对象为空
  * @param $intPosition
  * @param null $objToOwnedCard
  * @return null
  */
 public function changeMember($intPosition, $objToOwnedCard = null)
 {
     // 检查位置信息是否正确
     if ($intPosition <= 0 || $intPosition > self::intTeamMemberCount) {
         // TODO Error
         return null;
     }
     // 取得该位置原队员
     $objTeamMember = $this->getMember($intPosition);
     // Transaction
     DB::beginTransaction();
     // 根据目标队员分析Case
     try {
         if ($objToOwnedCard) {
             /******* 目标队员不为空的情况 *******/
             // 检查目标卡片的用户是否一致
             if ($objToOwnedCard->player_id != $this->player_id) {
                 // 目标卡片用户不同
                 throw new Exception('Wrong Player Id');
             }
             // 检查目标卡片是否已在目标位置
             if ($objToOwnedCard->id == $objTeamMember->owned_card_id) {
                 // 目标卡片已在目标位置
                 throw new Exception('Wrong Player Id');
             }
             // 检查目标卡片的入队情况
             if ($objToOwnedCard->team_id > 0 && $objToOwnedCard->team_id != $this->id) {
                 // 已经在其他队伍中
                 throw new Exception('Wrong Player Id');
             }
             // 开始换人处理
             if ($objTeamMember->owned_card_id > 0) {
                 // 目标位置有玩家卡片的情况
                 // 目标卡片是否已经在当前队伍的其他位置上
                 if ($objToOwnedCard->team_id == $this->id) {
                     // 目标卡片原本已在此队伍中 需要和目标位置原卡片互换情报
                     $objToOwnedCardTeamMember = TeamMember::where("owned_card_id", $objToOwnedCard->id)->first();
                     // 对象卡片原位置的玩家卡片ID更新为目标位置原玩家卡片ID
                     $objToOwnedCardTeamMember->owned_card_id = $objTeamMember->owned_card_id;
                     // 保存
                     if (!$objToOwnedCardTeamMember->save()) {
                         throw new Exception('Save Failed');
                     }
                 } else {
                     // 目标玩家卡片原本未在队伍中 需要重置目标位置原玩家卡片的队伍ID
                     $objFromOwnedCard = OwnedCard::find($objTeamMember->owned_card_id);
                     $objFromOwnedCard->team_id = 0;
                     if (!$objFromOwnedCard->save()) {
                         throw new Exception('Save Failed');
                     }
                 }
                 // 更新目标队员情报
                 $objTeamMember->owned_card_id = $objToOwnedCard->id;
                 // 更新目标用户卡片
                 $objToOwnedCard->team_id = $this->id;
                 // 保存修改
                 if (!$objToOwnedCard->save() || !$objTeamMember->save()) {
                     throw new Exception('Save Failed');
                 }
             } else {
                 // 目标位置无卡片的情况
                 // 目标卡片是否已经在当前队伍的其他位置上
                 if ($objToOwnedCard->team_id == $this->id) {
                     $objToOwnedCardTeamMember = TeamMember::where("owned_card_id", $objToOwnedCard->id)->first();
                     // 对象卡片原位置重置
                     $objToOwnedCardTeamMember->owned_card_id = 0;
                     // 保存
                     if (!$objToOwnedCardTeamMember->save()) {
                         throw new Exception('Save Failed');
                     }
                 }
                 // 更新队员情报
                 $objTeamMember->owned_card_id = $objToOwnedCard->id;
                 // 更新目标用户卡片
                 $objToOwnedCard->team_id = $this->id;
                 // 保存修改
                 if (!$objToOwnedCard->save() || !$objTeamMember->save()) {
                     throw new Exception('Save Failed');
                 }
             }
         } else {
             /******* 目标队员为空的情况下 *******/
             // 检查目前队伍人数,若等于1 则不可换为空
             $intTeamMemberCount = TeamMember::where("team_id", $this->id)->where("owned_card_id", ">", 0)->count();
             if ($intTeamMemberCount <= 1) {
                 throw new Exception('Last Member');
             }
             // 目标位置是否有玩家卡片
             if ($objTeamMember->owned_card_id <= 0) {
                 throw new Exception('Null Member To Null Member');
             }
             // 清空目标位置原卡片数据
             $objFromOwnedCard = OwnedCard::find($objTeamMember->owned_card_id);
             $objFromOwnedCard->team_id = 0;
             $objTeamMember->owned_card_id = 0;
             if (!$objFromOwnedCard->save() || !$objTeamMember->save()) {
                 throw new Exception('Save Failed');
             }
         }
         // 2016/11/10 队伍信息更新
         switch ($intPosition) {
             case 1:
                 if ($objToOwnedCard) {
                     $this->position_1_owned_card_id = $objToOwnedCard->id;
                 } else {
                     $this->position_1_owned_card_id = 0;
                 }
                 break;
             case 2:
                 if ($objToOwnedCard) {
                     $this->position_2_owned_card_id = $objToOwnedCard->id;
                 } else {
                     $this->position_2_owned_card_id = 0;
                 }
                 break;
             case 3:
                 if ($objToOwnedCard) {
                     $this->position_3_owned_card_id = $objToOwnedCard->id;
                 } else {
                     $this->position_3_owned_card_id = 0;
                 }
                 break;
             case 4:
                 if ($objToOwnedCard) {
                     $this->position_4_owned_card_id = $objToOwnedCard->id;
                 } else {
                     $this->position_4_owned_card_id = 0;
                 }
                 break;
             case 5:
                 if ($objToOwnedCard) {
                     $this->position_5_owned_card_id = $objToOwnedCard->id;
                 } else {
                     $this->position_5_owned_card_id = 0;
                 }
                 break;
             case 6:
                 if ($objToOwnedCard) {
                     $this->position_6_owned_card_id = $objToOwnedCard->id;
                 } else {
                     $this->position_6_owned_card_id = 0;
                 }
                 break;
         }
         $this->save();
         DB::commit();
     } catch (Exception $e) {
         // TODO Dev Log
         DB::rollback();
     }
 }
Exemplo n.º 8
0
 /**
  * 显示玩家装备库
  */
 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 />";
     }
 }
Exemplo n.º 9
0
 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();
     // }
 }
Exemplo n.º 10
0
 /**
  * 玩家创建时初始化第一套队伍
  */
 public function firstTeam()
 {
     // Transaction
     DB::beginTransaction();
     try {
         $objTeam = new Team();
         $intPlayerId = $this->id;
         $objTeam->player_id = $intPlayerId;
         $objFirstCard = OwnedCard::where('player_id', $intPlayerId)->orderBy('id', 'ASC')->first();
         $objTeam->position_1_owned_card_id = $objFirstCard->id;
         $objTeam->total_cost = $objFirstCard->getCost();
         $objTeam->save();
         // TODO 是否需要
         $objTeamBk = Team::find($objTeam->id);
         // 20151012 TeamMember Table 初始化
         for ($intPosition = 1; $intPosition <= 6; $intPosition++) {
             $objTeamMember = new TeamMember();
             $objTeamMember->team_id = $objTeamBk->id;
             $objTeamMember->position = $intPosition;
             $objTeamMember->player_id = $objTeamBk->player_id;
             if ($intPosition == 1) {
                 $objTeamMember->card_id = $objFirstCard->card_id;
                 $objTeamMember->owned_card_id = $objFirstCard->id;
             }
             if (!$objTeamMember->save()) {
                 throw new Exception('Save Failed');
             }
             switch ($intPosition) {
                 case 1:
                     $objTeamBk->position_1_member_id = $objTeamMember->id;
                     break;
                 case 2:
                     $objTeamBk->position_2_member_id = $objTeamMember->id;
                     break;
                 case 3:
                     $objTeamBk->position_3_member_id = $objTeamMember->id;
                     break;
                 case 4:
                     $objTeamBk->position_4_member_id = $objTeamMember->id;
                     break;
                 case 5:
                     $objTeamBk->position_5_member_id = $objTeamMember->id;
                     break;
                 case 6:
                     $objTeamBk->position_6_member_id = $objTeamMember->id;
                     break;
             }
             // 更新玩家卡片的队伍信息
             $objFirstCard->team_id = $objTeam->id;
             if (!$objFirstCard->save()) {
                 throw new Exception('Save Failed');
             }
         }
         if (!$objTeamBk->save()) {
             throw new Exception('Save Failed');
         }
         DB::commit();
     } catch (Exception $e) {
         // TODO Dev Log
         DB::rollback();
     }
 }