コード例 #1
0
 public static function updateCoin(GameUsers $user, GameUsers $opponent, $roomGroupId, $action, $gameId = null, $double = 0, $normal = true, $type = null, $time = null)
 {
     //Add Log
     $result = new FunctionResult();
     $result->success = false;
     if (!empty($user) && !empty($action)) {
         $roomGroup = GameRoomGroups::getRoomGroupByGroupId($roomGroupId);
         if (!empty($roomGroup)) {
             $coin = $user->getCoins();
             $maxCoin = $roomGroup->getMatchCoin() * 128;
             $matchCoins = $roomGroup->getMatchCoin();
             if (!$normal) {
                 $matchCoins = $matchCoins * 2;
             }
             if ($double > 1) {
                 $matchCoins = $matchCoins * pow(2, $double);
             }
             $calCcoin = $matchCoins;
             $error = false;
             if ($action == GameUtils::$GAME_RESULT_ACTION_WIN) {
                 if ($matchCoins > $maxCoin) {
                     $matchCoins = $maxCoin;
                 }
             } else {
                 if ($action == GameUtils::$GAME_RESULT_ACTION_LOST) {
                     $matchCoins = -1 * $matchCoins;
                     if ($coin + $matchCoins < 0) {
                         $matchCoins = -1 * $coin;
                     }
                 } else {
                     $error = true;
                 }
             }
             if (!$error) {
                 $gameResult = $action . "_" . $normal . "_" . $double . "_" . $type;
                 $oppId = null;
                 if (!empty($opponent)) {
                     $oppId = $opponent->getUserId();
                 }
                 if (empty($time)) {
                     $time = time();
                 }
                 $add = 1;
                 if ($action == GameUtils::$GAME_RESULT_ACTION_LOST) {
                     $add = 0;
                 }
                 Queue::addUserCoinLog($user->userId, $calCcoin, $matchCoins, $time, GameUserXpLog::$CONSTANT_LOG_TYPE_GAME, $add, $gameId, $gameResult, $oppId);
                 Queue::addUserLeaderBoard($user->userId, $matchCoins, $time);
                 $user->setCoins($coin + $matchCoins);
                 $result->success = true;
             } else {
                 $result->success = false;
                 $result->result = "Action unknown";
             }
         } else {
             $result->success = false;
             $result->result = "Room Group is unknown";
         }
     }
     return $result;
 }