Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1914,24 +1914,6 @@ parameters:
count: 4
path: src/Controller/Item/Pinata/BoosterPackController.php

-
message: '#^Cannot call method setSpice\(\) on mixed\.$#'
identifier: method.nonObject
count: 1
path: src/Controller/Item/Pinata/BoxController.php

-
message: '#^Parameter \#2 \$itemGroup of static method App\\Service\\InventoryService\:\:getRandomItemFromItemGroup\(\) expects App\\Entity\\ItemGroup, App\\Entity\\ItemGroup\|null given\.$#'
identifier: argument.type
count: 1
path: src/Controller/Item/Pinata/BoxController.php

-
message: '#^Parameter \#5 \$newInventory of static method App\\Controller\\Item\\Pinata\\BoxHelpers\:\:countRemoveFlushAndRespond\(\) expects array\<App\\Entity\\Inventory\>, array\<int, mixed\> given\.$#'
identifier: argument.type
count: 1
path: src/Controller/Item/Pinata/BoxController.php

-
message: '#^Binary operation "\." between non\-falsy\-string and mixed results in an error\.$#'
identifier: binaryOp.invalid
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Poppy Seed Pets API.
*
* The Poppy Seed Pets API is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* The Poppy Seed Pets API is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with The Poppy Seed Pets API. If not, see <https://www.gnu.org/licenses/>.
*/

namespace App\Controller\Item\Pinata\Box;

use App\Controller\Item\ItemControllerHelpers;
use App\Entity\Inventory;
use App\Service\InventoryService;
use App\Service\IRandom;
use App\Service\ResponseService;
use App\Service\UserAccessor;
use App\Service\UserStatsService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

class DisassemblePepperboxController
{
#[Route("/item/box/pepperbox/{inventory}/disassemble", methods: ["POST"])]
#[IsGranted("IS_AUTHENTICATED_FULLY")]
public function disassemblePepperbox(
Inventory $inventory, ResponseService $responseService, InventoryService $inventoryService,
UserStatsService $userStatsRepository, EntityManagerInterface $em, IRandom $rng,
UserAccessor $userAccessor
): JsonResponse
{
$user = $userAccessor->getUserOrThrow();

ItemControllerHelpers::validateInventory($user, $inventory, 'box/pepperbox/#/disassemble');
ItemControllerHelpers::validateLocationSpace($inventory, $em);

$peppers = $rng->rngNextInt(4, $rng->rngNextInt(6, 10));

$description = $user->getName() . ' got this by taking apart ' . $inventory->getItem()->getNameWithArticle() . '.';
$location = $inventory->getLocation();

for($i = 0; $i < $peppers; $i++)
{
$inventoryService->receiveItem('Spicy Peps', $user, $user, $description, $location, $inventory->getLockedToOwner())
->setSpice($inventory->getSpice())
;
}

$userStatsRepository->incrementStat($user, 'Disassembled ' . $inventory->getItem()->getNameWithArticle());

$em->remove($inventory);

$em->flush();

return $responseService->itemActionSuccess('You take apart the Pepperbox into its constituent pieces...', [ 'itemDeleted' => true ]);
}
}
86 changes: 86 additions & 0 deletions src/Controller/Item/Pinata/Box/ListenToJukeboxController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Poppy Seed Pets API.
*
* The Poppy Seed Pets API is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* The Poppy Seed Pets API is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with The Poppy Seed Pets API. If not, see <https://www.gnu.org/licenses/>.
*/

namespace App\Controller\Item\Pinata\Box;

use App\Controller\Item\ItemControllerHelpers;
use App\Entity\Inventory;
use App\Entity\Pet;
use App\Enum\LocationEnum;
use App\Enum\PetLocationEnum;
use App\Enum\PetSkillEnum;
use App\Functions\ArrayFunctions;
use App\Functions\PetActivityLogFactory;
use App\Functions\UserQuestRepository;
use App\Model\PetChanges;
use App\Service\PetExperienceService;
use App\Service\ResponseService;
use App\Service\UserAccessor;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

class ListenToJukeboxController
{
#[Route("/item/box/jukebox/{inventory}/listen", methods: ["POST"])]
#[IsGranted("IS_AUTHENTICATED_FULLY")]
public function listenToJukebox(
Inventory $inventory, ResponseService $responseService, PetExperienceService $petExperienceService,
EntityManagerInterface $em, UserAccessor $userAccessor
): JsonResponse
{
$user = $userAccessor->getUserOrThrow();

ItemControllerHelpers::validateInventory($user, $inventory, 'box/jukebox/#/listen');

$today = (new \DateTimeImmutable())->format('Y-m-d');
$listenedToJukebox = UserQuestRepository::findOrCreate($em, $user, 'Listened to Jukebox', (new \DateTimeImmutable())->modify('-1 day')->format('Y-m-d'));

if($today === $listenedToJukebox->getValue())
return $responseService->itemActionSuccess('You already listened to the Jukebox today. (Everyone knows that Jukeboxes can only be listened to once per day! Everyone!)');

if($inventory->getLocation() !== LocationEnum::Home && $inventory->getLocation() !== LocationEnum::Mantle)
return $responseService->itemActionSuccess('For maximum effect, the Jukebox should be played somewhere your pets can hear it!');

$listenedToJukebox->setValue($today);

$pets = $em->getRepository(Pet::class)->findBy([
'owner' => $user->getId(),
'location' => PetLocationEnum::HOME
]);

if(count($pets) === 0)
return $responseService->itemActionSuccess('For maximum effect, the Jukebox should be played with pets around to hear it!');

$petNames = [];

foreach($pets as $pet)
{
$petNames[] = $pet->getName();
$changes = new PetChanges($pet);

$pet->increaseSafety(2);

$activityLog = PetActivityLogFactory::createUnreadLog($em, $pet, $pet->getName() . ' listened to the Jukebox.');

$petExperienceService->gainExp($pet, 1, [ PetSkillEnum::Music ], $activityLog);

$activityLog->setChanges($changes->compare($pet));
}

$em->flush();

return $responseService->itemActionSuccess(ArrayFunctions::list_nice($petNames) . ' enjoyed listening to the Jukebox!');
}
}
59 changes: 59 additions & 0 deletions src/Controller/Item/Pinata/Box/Open4thOfJulyBoxController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Poppy Seed Pets API.
*
* The Poppy Seed Pets API is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* The Poppy Seed Pets API is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with The Poppy Seed Pets API. If not, see <https://www.gnu.org/licenses/>.
*/

namespace App\Controller\Item\Pinata\Box;

use App\Controller\Item\ItemControllerHelpers;
use App\Controller\Item\Pinata\BoxHelpers;
use App\Entity\Inventory;
use App\Service\InventoryService;
use App\Service\ResponseService;
use App\Service\UserAccessor;
use App\Service\UserStatsService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

class Open4thOfJulyBoxController
{
#[Route("/item/box/july4/{inventory}/open", methods: ["POST"])]
#[IsGranted("IS_AUTHENTICATED_FULLY")]
public function open4thOfJulyBox(
Inventory $inventory, ResponseService $responseService, InventoryService $inventoryService,
UserStatsService $userStatsRepository, EntityManagerInterface $em,
UserAccessor $userAccessor
): JsonResponse
{
$user = $userAccessor->getUserOrThrow();

ItemControllerHelpers::validateInventory($user, $inventory, 'box/july4/#/open');
ItemControllerHelpers::validateLocationSpace($inventory, $em);

$comment = $user->getName() . ' got this from ' . $inventory->getItem()->getNameWithArticle() . '.';

$location = $inventory->getLocation();
$lockedToOwner = $inventory->getLockedToOwner();

$newInventory = [
$inventoryService->receiveItem('Hot Dog', $user, $user, $comment, $location, $lockedToOwner),
$inventoryService->receiveItem('Hot Dog', $user, $user, $comment, $location, $lockedToOwner),
$inventoryService->receiveItem('Sunscreen', $user, $user, $comment, $location, $lockedToOwner),
$inventoryService->receiveItem('Red Firework', $user, $user, $comment, $location, $lockedToOwner),
$inventoryService->receiveItem('White Firework', $user, $user, $comment, $location, $lockedToOwner),
$inventoryService->receiveItem('Blue Firework', $user, $user, $comment, $location, $lockedToOwner),
];

return BoxHelpers::countRemoveFlushAndRespond('Opening the box revealed', $userStatsRepository, $user, $inventory, $newInventory, $responseService, $em);
}
}
60 changes: 60 additions & 0 deletions src/Controller/Item/Pinata/Box/OpenBagOfBeansController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Poppy Seed Pets API.
*
* The Poppy Seed Pets API is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* The Poppy Seed Pets API is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with The Poppy Seed Pets API. If not, see <https://www.gnu.org/licenses/>.
*/

namespace App\Controller\Item\Pinata\Box;

use App\Controller\Item\ItemControllerHelpers;
use App\Controller\Item\Pinata\BoxHelpers;
use App\Entity\Inventory;
use App\Service\InventoryService;
use App\Service\IRandom;
use App\Service\ResponseService;
use App\Service\UserAccessor;
use App\Service\UserStatsService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

class OpenBagOfBeansController
{
#[Route("/item/box/bagOfBeans/{inventory}/open", methods: ["POST"])]
#[IsGranted("IS_AUTHENTICATED_FULLY")]
public function openBagOfBeans(
Inventory $inventory, ResponseService $responseService, InventoryService $inventoryService, IRandom $rng,
UserStatsService $userStatsRepository, EntityManagerInterface $em,
UserAccessor $userAccessor
): JsonResponse
{
$user = $userAccessor->getUserOrThrow();

ItemControllerHelpers::validateInventory($user, $inventory, 'box/bagOfBeans/#/open');
ItemControllerHelpers::validateLocationSpace($inventory, $em);

$newInventory = [];

$beans = $rng->rngNextInt(6, $rng->rngNextInt(7, 12));

$description = $user->getName() . ' got this from ' . $inventory->getItem()->getNameWithArticle() . '.';
$location = $inventory->getLocation();

for($i = 0; $i < $beans; $i++)
{
$newInventory[] = $inventoryService->receiveItem($rng->rngNextFromArray(['Coffee Beans', 'Cocoa Beans', 'Beans']), $user, $user, $description, $location, $inventory->getLockedToOwner())
->setSpice($inventory->getSpice())
;
}

return BoxHelpers::countRemoveFlushAndRespond('You upturn the bag, finding', $userStatsRepository, $user, $inventory, $newInventory, $responseService, $em);
}
}
86 changes: 86 additions & 0 deletions src/Controller/Item/Pinata/Box/OpenBakersBoxController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Poppy Seed Pets API.
*
* The Poppy Seed Pets API is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* The Poppy Seed Pets API is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with The Poppy Seed Pets API. If not, see <https://www.gnu.org/licenses/>.
*/

namespace App\Controller\Item\Pinata\Box;

use App\Controller\Item\ItemControllerHelpers;
use App\Controller\Item\Pinata\BoxHelpers;
use App\Entity\Inventory;
use App\Functions\DateFunctions;
use App\Functions\UserQuestRepository;
use App\Service\Clock;
use App\Service\InventoryService;
use App\Service\IRandom;
use App\Service\ResponseService;
use App\Service\UserAccessor;
use App\Service\UserStatsService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

class OpenBakersBoxController
{
#[Route("/item/box/bakers/{inventory}/open", methods: ["POST"])]
#[IsGranted("IS_AUTHENTICATED_FULLY")]
public function openBakers(
Inventory $inventory, ResponseService $responseService, InventoryService $inventoryService, IRandom $rng,
UserStatsService $userStatsRepository, EntityManagerInterface $em, Clock $clock,
UserAccessor $userAccessor
): JsonResponse
{
$user = $userAccessor->getUserOrThrow();

ItemControllerHelpers::validateInventory($user, $inventory, 'box/bakers/#/open');
ItemControllerHelpers::validateLocationSpace($inventory, $em);

$wheatOrCorn = DateFunctions::isCornMoon($clock->now) ? 'Corn' : 'Wheat';
$wheatFlourOrCorn = DateFunctions::isCornMoon($clock->now) ? 'Corn' : 'Wheat Flour';

/**
* @var Inventory[] $newInventory
*/
$newInventory = [];

$location = $inventory->getLocation();
$spice = $inventory->getSpice();

$freeBasicRecipes = UserQuestRepository::findOrCreate($em, $user, 'Got free Basic Recipes', false);
if(!$freeBasicRecipes->getValue())
{
$newInventory[] = $inventoryService->receiveItem('Cooking 101', $user, $user, $user->getName() . ' got this from ' . $inventory->getItem()->getNameWithArticle() . '.', $location, $inventory->getLockedToOwner());
$freeBasicRecipes->setValue(true);
}

$newInventory[] = $inventoryService->receiveItem($wheatOrCorn, $user, $user, $user->getName() . ' got this from a weekly Care Package.', $location, $inventory->getLockedToOwner());

for($i = 0; $i < 4; $i++)
$newInventory[] = $inventoryService->receiveItem($rng->rngNextFromArray([ 'Egg', $wheatFlourOrCorn, 'Sugar', 'Creamy Milk' ]), $user, $user, $user->getName() . ' got this from a weekly Care Package.', $location, $inventory->getLockedToOwner());

for($i = 0; $i < 4; $i++)
$newInventory[] = $inventoryService->receiveItem($rng->rngNextFromArray([ 'Corn Syrup', 'Yeast', 'Cocoa Beans', 'Baking Soda', 'Cream of Tartar' ]), $user, $user, $user->getName() . ' got this from a weekly Care Package.', $location, $inventory->getLockedToOwner());

if($rng->rngNextInt(1, 4) === 1)
$newInventory[] = $inventoryService->receiveItem('Cobbler Recipe', $user, $user, $user->getName() . ' got this from a weekly Care Package.', $location, $inventory->getLockedToOwner());

if($spice)
{
$inventoryToSpice = $rng->rngNextSubsetFromArray($newInventory, 3);

foreach($inventoryToSpice as $inventoryItem)
$inventoryItem->setSpice($spice);
}

return BoxHelpers::countRemoveFlushAndRespond('Opening the box revealed', $userStatsRepository, $user, $inventory, $newInventory, $responseService, $em);
}
}
Loading
Loading