/** * * @param <GameProgress> $gameProgress * @return <GameResponse> */ public function grantShareProgress($gameProgress) { $gameResponse = new GameProgressResponse(); 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']; $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; } $gameUtil = new GameUtil(); //checking weather the person have sufficient money to buy or not if (!$gameUtil->validShare($currentUserGameProfile, $gameProgress)) { return null; } $gameDao = new GameDAO(); $progress = $gameDao->getShareProgress($currentUserGameProfile, $gameProgress); $progress = (int) $progress; $gameProgress->csp->progress += $progress; if ($progress == 0) { //dont update } else { //update and it will always happen as progress will b greater than zero $currentSearchPartyUtil = new CurrentSearchPartyUtil(); $updatedSearchParty = $currentSearchPartyUtil->updateCurrentSearchPartyProgress($gameProgress->csp); if ($updatedSearchParty == null) { //some body already get the artifact $gameResponse->isSomebodyGetArtifact = true; return $gameResponse; } else { $gameResponse->isSomebodyGetArtifact = false; } } $gameResponse->percentObjtained = $progress; 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; }
/** * * @param <CurrentSearchParty> $currentSearchParty * @param <GameProfile> $gameProfile * @return <Array> */ public function obtainArtifact($currentSearchParty, $gameProfile) { //add to inventory //give experience i.e update game profile //chk for lvl up //make item inactive /* * Adding to inventory */ $inventoryUtil = new InventoryUtil(); $inventory = new Inventory(); $inventory->artifact = $currentSearchParty->artifact; $inventory->artifactLvl = $currentSearchParty->artifactLvl; $inventory->user = $currentSearchParty->user; $inventory = $inventoryUtil->addToInventory($inventory); /* * Calulate exp */ $exp = $currentSearchParty->artifactLvl * 100; $exp = $gameProfile->exp + $exp; /* * Update game profile and checking for levelup and updateing level */ $userProfileDAO = new UserProfileDAO(); $updatedProfile = $userProfileDAO->giveExperience($gameProfile, $exp); //exp is the updated exp /* * Making the artifact inactive */ $artifactUtil = new ArtifactUtil(); $artifactUtil->makeArtifactInactive($currentSearchParty->artifact); $returnArray = array(); array_push($returnArray, $inventory); //on position 0 inventory will b thr array_push($returnArray, $updatedProfile); //on 1st position updated profile return $returnArray; }