Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/corowne/lorekeeper into …
Browse files Browse the repository at this point in the history
…feature/trades
  • Loading branch information
ScuffedNewt committed Jan 20, 2025
2 parents 92c1c02 + 9255f8f commit f964753
Show file tree
Hide file tree
Showing 122 changed files with 4,753 additions and 529 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
6 changes: 6 additions & 0 deletions app/Console/Commands/AddSiteSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ public function handle() {

$this->addSiteSetting('comment_dislikes_enabled', 0, '0: Dislikes disabled, 1: Dislikes enabled.');

$this->addSiteSetting('shop_type', 0, '0: Default, 1: Collapsible.');

$this->addSiteSetting('coupon_settings', 0, '0: Percentage is taken from total (e.g 20% from 2 items costing a total of 100 = 80), 1: Percentage is taken from item (e.g 20% from 2 items costing a total of 100 = 90)');

$this->addSiteSetting('limited_stock_coupon_settings', 0, '0: Does not allow coupons to be used on limited stock items, 1: Allows coupons to be used on limited stock items');

$this->addSiteSetting('can_transfer_currency_directly', 1, 'Whether or not users can directly transfer currency to other users without trading. 0: Users cannot directly transfer currency. 1: Direct currency transfers are allowed.');

$this->addSiteSetting('can_transfer_items_directly', 1, 'Whether or not users can directly transfer items to other users without trading. 0: Users cannot directly transfer items. 1: Direct item transfers are allowed.');
Expand Down
58 changes: 58 additions & 0 deletions app/Console/Commands/ConvertShopLimits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Console\Commands;

use App\Models\Limit\Limit;
use DB;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Schema;

class ConvertShopLimits extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'convert-shop-limits';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Converts existing shop limits to the new system.';

/**
* Execute the console command.
*/
public function handle() {
if (!Schema::hasTable('shop_limits')) {
$this->info('No shop limits to convert.');

return;
}

$shopLimits = DB::table('shop_limits')->get();
$bar = $this->output->createProgressBar(count($shopLimits));
$bar->start();
foreach ($shopLimits as $shopLimit) {
Limit::create([
'object_model' => 'App\Models\Shop\Shop',
'object_id' => $shopLimit->shop_id,
'limit_type' => 'item',
'limit_id' => $shopLimit->item_id,
'quantity' => 1,
]);

$bar->advance();
}
$bar->finish();

// drop the is_restricted column from the shops table
Schema::table('shops', function ($table) {
$table->dropColumn('is_restricted');
});

Schema::dropIfExists('shop_limits');
}
}
44 changes: 44 additions & 0 deletions app/Console/Commands/FixEqualsCriteriaLoots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Console\Commands;

use App\Models\Loot\Loot;
use Illuminate\Console\Command;

class FixEqualsCriteriaLoots extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fix-equals-criteria-loots';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Fix equals criteria loots to double equals for use in where clause';

/**
* Execute the console command.
*/
public function handle() {
//
$loots = Loot::whereNotNull('data')->get();

foreach ($loots as $loot) {
$data = $loot->data;

if (isset($data['criteria']) && $data['criteria'] == '=') {
$data['criteria'] = '==';

Loot::where([
['loot_table_id', '=', $loot->loot_table_id],
['rewardable_type', '=', $loot->rewardable_type],
['rewardable_id', '=', $loot->rewardable_id],
])->update(['data' => $data]);
}
}
}
}
81 changes: 81 additions & 0 deletions app/Console/Commands/RestockShops.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace App\Console\Commands;

use App\Models\Shop\ShopStock;
use Carbon\Carbon;
use Illuminate\Console\Command;

class RestockShops extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'restock-shops';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Restocks shops.';

/**
* Create a new command instance.
*/
public function __construct() {
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle() {
$stocks = ShopStock::where('is_limited_stock', 1)->where('restock', 1)->get();
foreach ($stocks as $stock) {
if ($stock->restock_interval == 2) {
// check if it's start of week
$now = Carbon::now();
$day = $now->dayOfWeek;
if ($day != 1) {
continue;
}
} elseif ($stock->restock_interval == 3) {
// check if it's start of month
$now = Carbon::now();
$day = $now->day;
if ($day != 1) {
continue;
}
}

// if the stock is random, restock from the stock type
if ($stock->isRandom) {
$type = $stock->stock_type;
$model = getAssetModelString(strtolower($type));
if (method_exists($model, 'visible')) {
$itemId = $stock->categoryId ?
$model::visible()->where(strtolower($type).'_category_id', $stock->categoryId)->inRandomOrder()->first()->id :
$model::visible()->inRandomOrder()->first()->id;
} elseif (method_exists($model, 'released')) {
$itemId = $stock->categoryId ?
$model::released()->where(strtolower($type).'_category_id', $stock->categoryId)->inRandomOrder()->first()->id :
$model::released()->inRandomOrder()->first()->id;
} else {
$itemId = $stock->categoryId ?
$model::where(strtolower($type).'_category_id', $stock->categoryId)->inRandomOrder()->first()->id :
$model::inRandomOrder()->first()->id;
}

$stock->item_id = $itemId;
$stock->save();
}

$stock->quantity = $stock->range ? mt_rand(1, $stock->restock_quantity) : $stock->restock_quantity;
$stock->save();
}
}
}
74 changes: 74 additions & 0 deletions app/Console/Commands/UpdateTimedStock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Console\Commands;

use App\Models\Shop\Shop;
use App\Models\Shop\ShopStock;
use Illuminate\Console\Command;

class UpdateTimedStock extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update-timed-stock';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Hides timed stock or shops when expired, or sets it active if ready.';

/**
* Create a new command instance.
*/
public function __construct() {
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle() {
$hidestock = ShopStock::where('is_timed_stock', 1)->where('is_visible', 1)->get()->filter(function ($stock) {
return !$stock->isActive;
});
$showstock = ShopStock::where('is_timed_stock', 1)->where('is_visible', 0)->get()->filter(function ($stock) {
return $stock->isActive;
});

// set stock that should be active to active
foreach ($showstock as $showstock) {
$showstock->is_visible = 1;
$showstock->save();
}
// hide stock that should be hidden now
foreach ($hidestock as $hidestock) {
$hidestock->is_visible = 0;
$hidestock->save();
}

// also activate or deactivate the shops
$hideshop = Shop::where('is_timed_shop', 1)->where('is_active', 1)->get()->filter(function ($shop) {
return !$shop->isActive;
});
$showshop = Shop::where('is_timed_shop', 1)->where('is_active', 0)->get()->filter(function ($shop) {
return $shop->isActive;
});

// set shop that should be active to active
foreach ($showshop as $showshop) {
$showshop->is_active = 1;
$showshop->save();
}
// hide shop that should be hidden now
foreach ($hideshop as $hideshop) {
$hideshop->is_active = 0;
$hideshop->save();
}
}
}
4 changes: 4 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ protected function schedule(Schedule $schedule) {
->daily();
$schedule->command('update-staff-reward-actions')
->daily();
$schedule->command('restock-shops')
->daily();
$schedule->command('update-timed-stock')
->everyMinute();
}

/**
Expand Down
Loading

0 comments on commit f964753

Please sign in to comment.