-
Notifications
You must be signed in to change notification settings - Fork 164
add "reward maker" ext #1194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
CH3RVB
wants to merge
19
commits into
lk-arpg:develop
Choose a base branch
from
CH3RVB:pr/rewardmaker-core
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
add "reward maker" ext #1194
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c576b44
reward maker
CH3RVB ca20b8a
fixes
CH3RVB 5a2fd33
add character reward granting
CH3RVB 7bb59c5
e
CH3RVB 49d9626
i forgor
CH3RVB 5c520da
aa
CH3RVB 2c7f7e2
editing...
CH3RVB 8ca39e8
no message
CH3RVB 48ae819
Merge branch 'reward-maker-development' into pr/rewardmaker-core
CH3RVB e7fe487
Merge branch 'develop' of https://github.com/corowne/lorekeeper into …
CH3RVB 099dacb
no message
CH3RVB c86a922
refactor: fix PHP styling
CH3RVB 52a4a91
refactor: fix blade formatting
CH3RVB f44bbe2
no message
CH3RVB 5403e56
Merge commit '52a4a913edd924c115a03e2e94c11ff7ada2be65' into pr/rewar…
CH3RVB ba6b949
refactor: fix PHP styling
CH3RVB 5378165
no message
CH3RVB 22fa315
Merge branch 'pr/rewardmaker-core' of https://github.com/CH3RVB/lorek…
CH3RVB bd7f4b4
refactor: fix PHP styling
CH3RVB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| <?php | ||
|
|
||
| namespace App\Console\Commands; | ||
|
|
||
| use App\Models\ObjectReward; | ||
| use DB; | ||
| use Illuminate\Console\Command; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| class UpdateRewardMaker extends Command { | ||
| /** | ||
| * The name and signature of the console command. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $signature = 'update-reward-maker'; | ||
|
|
||
| /** | ||
| * The console command description. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $description = 'Update reward maker for develop'; | ||
|
|
||
| /** | ||
| * Execute the console command. | ||
| */ | ||
| public function handle() { | ||
| if (!Schema::hasTable('prompt_rewards')) { | ||
| $this->info('Already ran conversions.'); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if ($this->confirm('Have you migrated after installation?')) { | ||
| $this->info('If you have edited the reward maker to include custom reward types and other object support, ensure that they have been added to the UpdateRewardMaker command file or errors and data loss may occur.'); | ||
| if ($this->confirm('Have you either edited the UpdateRewardMaker file to include your edits, or not edited the reward maker at all?')) { | ||
| $this->info('Converting rewards.'); | ||
| $rewards = DB::table('prompt_rewards')->get(); | ||
|
|
||
| foreach ($rewards as $promptreward) { | ||
| $rewardmodel = getAssetModelString(strtolower($promptreward->rewardable_type)); | ||
|
|
||
| $newreward = ObjectReward::create([ | ||
| 'object_id' => $promptreward->prompt_id, | ||
| 'object_type' => 'App\Models\Prompt\Prompt', | ||
| 'rewardable_type' => $rewardmodel, | ||
| 'rewardable_id' => $promptreward->rewardable_id, | ||
| 'quantity' => $promptreward->quantity, | ||
| 'recipient_type' => 'User', | ||
| 'reward_key' => 'objectRewards', | ||
| ]); | ||
|
|
||
| if (!$newreward) { | ||
| $this->error('Error. Skipping prompt reward for prompt: '.$promptreward->prompt->name); | ||
| } | ||
| } | ||
| $this->info('Dropping prompt rewards'); | ||
| Schema::dropIfExists('prompt_rewards'); | ||
|
|
||
| $this->info('Converting any existing rewards...'); | ||
|
|
||
| $objrewards = ObjectReward::all(); | ||
|
|
||
| foreach ($objrewards as $reward) { | ||
| switch ($reward->object_type) { | ||
| case 'Questline': | ||
| $objmodel = 'App\Models\Questline\Questline'; | ||
| break; | ||
| case 'Prompt': | ||
| $objmodel = 'App\Models\Prompt\Prompt'; | ||
| break; | ||
| } | ||
|
|
||
| switch ($reward->recipient_type) { | ||
| case 'User': | ||
| $key = 'objectRewards'; | ||
| break; | ||
| case 'Character': | ||
| $key = 'objectCharacterRewards'; | ||
| break; | ||
| } | ||
|
|
||
| $reward->update([ | ||
| 'rewardable_type' => getAssetModelString(strtolower($reward->rewardable_type)), | ||
| 'object_type' => $objmodel, | ||
| 'reward_key' => $key, | ||
| ]); | ||
| } | ||
|
|
||
| $this->info('Converted rewards successfully. Happy Lorekeeping! :)'); | ||
| } else { | ||
| $this->error('Please edit the file to ensure the conversion goes smoothly.'); | ||
|
|
||
| return; | ||
| } | ||
| } else { | ||
| $this->info('Migrating DB. After this is complete, run this command again and confirm that you have to continue.'); | ||
| $this->call('migrate'); | ||
| $this->info('Migrations complete. Please run the command again to continue.'); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Controllers\Admin\Data; | ||
|
|
||
| use App\Http\Controllers\Controller; | ||
| use App\Services\RewardManager; | ||
| use Illuminate\Http\Request; | ||
|
|
||
| class RewardController extends Controller { | ||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Admin / Reward Maker Controller | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | Handles creation/editing of rewards | ||
| | | ||
| */ | ||
|
|
||
| /** | ||
| * Edit reward. | ||
| * | ||
| * @param int|null $id | ||
| * @param mixed $model | ||
| * | ||
| * @return \Illuminate\Http\RedirectResponse | ||
| */ | ||
| public function editReward(Request $request, RewardManager $service, $model, $id) { | ||
| $decodedmodel = urldecode(base64_decode($model)); | ||
| // check model + id combo exists | ||
| $object = $decodedmodel::find($id); | ||
| if (!$object) { | ||
| throw new \Exception('Invalid object.'); | ||
| } | ||
|
|
||
| $data = $request->only([ | ||
| 'rewardable_type', 'rewardable_id', 'reward_quantity', 'recipient_type', 'reward_key', | ||
| ]); | ||
|
|
||
| if ($id && $service->editRewards($object, $data)) { | ||
| flash('Rewards updated successfully.')->success(); | ||
| } else { | ||
| foreach ($service->errors()->getMessages()['error'] as $error) { | ||
| flash($error)->error(); | ||
| } | ||
| } | ||
|
|
||
| return redirect()->back(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| class ObjectReward extends Model { | ||
| /** | ||
| * The attributes that are mass assignable. | ||
| * | ||
| * @var array | ||
| */ | ||
| protected $fillable = [ | ||
| 'object_id', 'object_type', 'rewardable_id', 'rewardable_type', 'quantity', 'recipient_type', 'reward_key', | ||
| ]; | ||
|
|
||
| /** | ||
| * The table associated with the model. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $table = 'object_rewards'; | ||
|
|
||
| /********************************************************************************************** | ||
| RELATIONS | ||
| **********************************************************************************************/ | ||
|
|
||
| /** | ||
| * Get the object. | ||
| */ | ||
| public function object() { | ||
| return $this->morphTo(__FUNCTION__, 'object_type', 'object_id'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whats the purpose of the |
||
| } | ||
|
|
||
| /** | ||
| * Get the reward attached to the prompt reward. | ||
| */ | ||
| public function reward() { | ||
| return $this->morphTo(__FUNCTION__, 'rewardable_type', 'rewardable_id'); | ||
| } | ||
|
|
||
| /** | ||
| * Get the reward type so we don't have to do the no-no of model names in forms. | ||
| */ | ||
| public function rewardType() { | ||
| return class_basename($this->rewardable_type); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of having an object reward model why not just have the stored assets array?