public function updateAchievementCriterias($owner, string $type, $data = null): int
    {
        $criterias = $this->storage->getOwnerCriteriasByType($owner, $type, $data);

        if (!count($criterias)) {
            return 0;
        }

        $this->achievementsToCheck = [];

        $achievements = $this->storage->getAchievementsByCriterias($criterias);
        $updatedCriteriasCount = 0;

        foreach ($criterias as $criteria) {
            /** @var AchievementCriteria $criteria*/

            if ($criteria->completed()) {
                continue;
            }

            $achievement = $this->storage->getAchievementForCriteria($criteria, $achievements);

            if (is_null($achievement)) {
                continue;
            }

            $change = $this->getCriteriaChange($owner, $criteria, $achievement, $data);

            if (is_null($change)) {
                continue;
            }

            $this->setCriteriaProgress($owner, $criteria, $achievement, $change);
            $updatedCriteriasCount++;
        }

        if (count($this->achievementsToCheck) > 0) {
            $this->checkCompletedAchievements($owner);
        }

        return $updatedCriteriasCount;
    }
public function updateAchievementCriterias($owner, string $type, $data = null): int
    {
        $criterias = $this->storage->getOwnerCriteriasByType($owner, $type, $data);

        if (!count($criterias)) {
            return 0;
        }

        $this->achievementsToCheck = [];

        $achievements = $this->storage->getAchievementsByCriterias($criterias);
        $updatedCriteriasCount = 0;

        foreach ($criterias as $criteria) {
            /** @var AchievementCriteria $criteria*/

            if ($criteria->completed()) {
                continue;
            }

            $achievement = $this->storage->getAchievementForCriteria($criteria, $achievements);

            if (is_null($achievement)) {
                continue;
            }

            $change = $this->getCriteriaChange($owner, $criteria, $achievement, $data);

            if (is_null($change)) {
                continue;
            }

            $this->setCriteriaProgress($owner, $criteria, $achievement, $change);
            $updatedCriteriasCount++;
        }

        if (count($this->achievementsToCheck) > 0) {
            $this->checkCompletedAchievements($owner);
        }

        return $updatedCriteriasCount;
    }
public function updateAchievementCriterias ( $ owner , string $ type , $ data = null ) : int { $ criterias = $ this -> storage -> getOwnerCriteriasByType ( $ owner , $ type , $ data ) ; if ( ! count ( $ criterias ) ) { return 0 ; } $ this -> achievementsToCheck = [ ] ; $ achievements = $ this -> storage -> getAchievementsByCriterias ( $ criterias ) ; $ updatedCriteriasCount = 0 ; foreach ( $ criterias as $ criteria ) { /** @var AchievementCriteria $criteria*/ if ( $ criteria -> completed ( ) ) { continue ; } $ achievement = $ this -> storage -> getAchievementForCriteria ( $ criteria , $ achievements ) ; if ( is_null ( $ achievement ) ) { continue ; } $ change = $ this -> getCriteriaChange ( $ owner , $ criteria , $ achievement , $ data ) ; if ( is_null ( $ change ) ) { continue ; } $ this -> setCriteriaProgress ( $ owner , $ criteria , $ achievement , $ change ) ; $ updatedCriteriasCount ++ ; } if ( count ( $ this -> achievementsToCheck ) > 0 ) { $ this -> checkCompletedAchievements ( $ owner ) ; } return $ updatedCriteriasCount ; }
Updates criterias progress by given type & checks
referred achievements for completeness state.

Returns number of updated criterias.

@param mixed  $owner
@param string $type
@param mixed  $data  = null

@return int
Updates criterias progress by given type & checks referred achievements for completeness state .