Exemplo n.º 1
0
 /**
  *
  * @param <Array> $answers
  * @param <GameProgress> $gameProgress
  * @return <GameResponse>
  */
 public function grantSpyProgress($answers, $gameProgress)
 {
     //$answers=array();
     $gameResponse = new GameProgressResponse();
     settype($answers, "array");
     settype($gameProgress, "object");
     settype($gameProgress, "object");
     settype($gameProgress->friend, "object");
     settype($gameProgress->csp, "object");
     settype($gameProgress->csp->user, "object");
     settype($gameProgress->csp->artifact, "object");
     settype($gameProgress->progressType, "object");
     settype($gameProgress->friend->user, "object");
     $currentUserGameProfile = $_SESSION['game_profile'];
     for ($count = 0; $count < count($answers); $count++) {
         settype($answers[$count], "object");
     }
     $gameResponse->currentSearchParty = $gameProgress->csp;
     $artifactUtil = new ArtifactUtil();
     $artifact = $gameProgress->csp->artifact;
     if ($artifactUtil->isArtifactActive($artifact) == 0) {
         //artifact is in active
         $gameResponse->isSomebodyGetArtifact = true;
         return $gameResponse;
     }
     $gameDao = new GameDAO();
     $correntAnswers = $gameDao->checkAnswers($answers, $gameProgress);
     //cannot spy two persons at time same time
     if ($correntAnswers == -1) {
         return null;
     }
     if ($correntAnswers == 0) {
         //no need of update if corrent answers is zero
         $gameResponse->isSomebodyGetArtifact = false;
     } else {
         $progressObtained = $correntAnswers * 5 * $currentUserGameProfile->spyLvl;
         $gameProgress->csp->progress += $progressObtained;
         $currentSearchPartyUtil = new CurrentSearchPartyUtil();
         $updatedSearchParty = $currentSearchPartyUtil->updateCurrentSearchPartyProgress($gameProgress->csp);
         if ($updatedSearchParty == null) {
             $gameResponse->isSomebodyGetArtifact = true;
             return $gameResponse;
         }
     }
     $gameResponse->percentObjtained = $progressObtained;
     if ($gameProgress->csp->progress >= 100) {
         $gameUtil = new GameUtil();
         $gameUtilRes = $gameUtil->obtainArtifact($gameProgress->csp, $currentUserGameProfile);
         $updatedGameProfile = $gameUtilRes[1];
         $gameResponse->updatedGameProfile = $updatedGameProfile;
         $gameResponse->artifact = $gameUtilRes[0];
         $gameResponse->isActifactObtained = true;
     }
     return $gameResponse;
 }