Skip to content

Achievement Chain #30

Open
Open
@gabs-simon

Description

@gabs-simon

Sometimes, there are multiple achievements that track the exact same thing, but with different points to obtain.

For example, an user can obtain a "Newcomer" achievement when creating their first comment on the site, a "Regular Commenter" achievement when they reached 10 comments and a "Regular Commenter" achievement when they reached 100 comments.

Currently, these achievements need to be tracked separately, something like this:

<?php
use App\Achievements\Newcomer;
use App\Achievements\RegularCommenter;
use App\Achievements\VeteranCommenter;

public function createComment($user, $comment){
     // Some logic to be processed when the user creates a comment...
    $user->addProgress(Newcomer, 1);
    $user->addProgress(RegularCommenter, 1);
    $user->addProgress(VeteranCommenter, 1);
}

And this would quickly grow out of hand when there are many achievements tracking the same thing. In order to solve this problem, I propose a feature called "Achievement Chain". It would work in the following way:

  1. A new abstract class, AchievementChain will be created. This class will be defined only by a list of achievements.
  2. All methods that can be used to add, remove, set reset progress to Achievements can also receive instances of AchievementChain. When one of this methods receive an instance of AchievementChain, it will call the same method for every Achievement described in the definition of the AchievementChain instance.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions