|
|
|
@ -16,6 +16,7 @@ use App\Repository\EmojiRepository;
|
|
|
|
|
use App\Entity\UserEmojis;
|
|
|
|
|
use App\Repository\UserRepository;
|
|
|
|
|
use App\Repository\UserEmojisRepository;
|
|
|
|
|
use App\Entity\StockEmoji;
|
|
|
|
|
|
|
|
|
|
#[Route('/emojis', name: 'app_emoji_')]
|
|
|
|
|
class EmojiController extends AbstractController
|
|
|
|
@ -25,72 +26,27 @@ class EmojiController extends AbstractController
|
|
|
|
|
private EmojiService $emojiService;
|
|
|
|
|
private UserRepository $userRepository;
|
|
|
|
|
private UserEmojisRepository $userEmojisRepository;
|
|
|
|
|
private EntityManagerInterface $em;
|
|
|
|
|
|
|
|
|
|
public function __construct(RarityRepository $rarityRepository, HttpClientInterface $httpClient, EmojiService $emojiService,
|
|
|
|
|
UserRepository $userRepository, UserEmojisRepository $userEmojisRepository)
|
|
|
|
|
UserRepository $userRepository, UserEmojisRepository $userEmojisRepository, EntityManagerInterface $em)
|
|
|
|
|
{
|
|
|
|
|
$this->rarityRepository = $rarityRepository;
|
|
|
|
|
$this->httpClient = $httpClient;
|
|
|
|
|
$this->emojiService = $emojiService;
|
|
|
|
|
$this->userRepository = $userRepository;
|
|
|
|
|
$this->userEmojisRepository = $userEmojisRepository;
|
|
|
|
|
$this->em = $em;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/', name: 'emojis')]
|
|
|
|
|
public function index(): Response
|
|
|
|
|
{
|
|
|
|
|
$this->testToMove();
|
|
|
|
|
return $this->render('emoji/index.html.twig', [
|
|
|
|
|
'controller_name' => 'EmojiController',
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/count', name: 'count')]
|
|
|
|
|
public function count(EmojiRepository $emojiRepository): Response
|
|
|
|
|
{
|
|
|
|
|
$count = count($emojiRepository->findAll());
|
|
|
|
|
return new Response(['count' => $count]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/addRarity', name: 'add_rarity')]
|
|
|
|
|
public function addRarityDebug(EntityManagerInterface $entityManager) {
|
|
|
|
|
$rarity = new Rarity();
|
|
|
|
|
$rarity->setName('Bip');
|
|
|
|
|
$rarity->setDropRate(42);
|
|
|
|
|
$entityManager->persist($rarity);
|
|
|
|
|
$entityManager->flush();
|
|
|
|
|
|
|
|
|
|
return new Response();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/add/{code}', name: 'add_code')]
|
|
|
|
|
public function addEmojiDebug(string $code, EntityManagerInterface $entityManager) {
|
|
|
|
|
$emoji = new Emoji();
|
|
|
|
|
$emoji->setCode($code);
|
|
|
|
|
$emoji->setName('Default Name');
|
|
|
|
|
$emoji->setStrength(1.0);
|
|
|
|
|
$emoji->setToughness(1.0);
|
|
|
|
|
$emoji->setIntelligence(1.0);
|
|
|
|
|
$emoji->setSpeed(1.0);
|
|
|
|
|
$emoji->setFightsWon(0);
|
|
|
|
|
|
|
|
|
|
// On récupère une instance de Rarity existante (par exemple, la première)
|
|
|
|
|
$rarity = $this->emojiService->generateRarity();
|
|
|
|
|
if (!$rarity) {
|
|
|
|
|
throw new \RuntimeException('Aucun objet Rarity trouvé en base.');
|
|
|
|
|
}
|
|
|
|
|
$emoji->setRarity($rarity);
|
|
|
|
|
|
|
|
|
|
// Optionnel : définir parent1 et parent2 si tu veux tester avec des relations
|
|
|
|
|
// $emoji->setParent1(null);
|
|
|
|
|
// $emoji->setParent2(null);
|
|
|
|
|
|
|
|
|
|
$entityManager->persist($emoji);
|
|
|
|
|
$entityManager->flush();
|
|
|
|
|
|
|
|
|
|
return new Response();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Renvoi l'url de l'image issue de la fusion de deux emojis. Fonctionne avec un code et un emoji directement
|
|
|
|
|
private function getFusionUrl(string $emoji1, string $emoji2): string
|
|
|
|
|
{
|
|
|
|
@ -122,11 +78,24 @@ class EmojiController extends AbstractController
|
|
|
|
|
|
|
|
|
|
$child = new Emoji();
|
|
|
|
|
|
|
|
|
|
$child->setName("Testenfant");
|
|
|
|
|
$names = [
|
|
|
|
|
'Zabbo', 'Snorky', 'Wiblo', 'Kipzi', 'Gribz', 'Flimbo', 'Plinko', 'Raffu', 'Mibzo', 'Dazzo',
|
|
|
|
|
'Flinko', 'Groopi', 'Zimba', 'Wocky', 'Trizzi', 'Lumpo', 'Yabbo', 'Glinky', 'Zuffo', 'Brimbo',
|
|
|
|
|
'Chompa', 'Snizzle', 'Wibzi', 'Paffy', 'Tizzle', 'Nokko', 'Lazzo', 'Flumzi', 'Wozzy', 'Blimpo',
|
|
|
|
|
'Zuppi', 'Glinty', 'Fobzi', 'Muggo', 'Twibzy', 'Crungo', 'Jibbi', 'Snoffy', 'Glimzo', 'Daffo',
|
|
|
|
|
'Nibzi', 'Kranko', 'Yibba', 'Bloopo', 'Taffli', 'Zagga', 'Whizzo', 'Plobbi', 'Ruffli', 'Snibbo',
|
|
|
|
|
'Fuzzu', 'Gozzi', 'Trabbo', 'Flonzi', 'Whimpy', 'Klipzo', 'Zombzi', 'Hiffa', 'Fruggo', 'Luzzli',
|
|
|
|
|
'Zilpo', 'Baffi', 'Ramboo', 'Dibzo', 'Muffli', 'Kaffo', 'Gobzi', 'Tobbu', 'Xibzi', 'Pufflo',
|
|
|
|
|
'Jabbo', 'Zinky', 'Baffro', 'Tizzi', 'Wombo', 'Snuxi', 'Lompa', 'Criffy', 'Mebzi', 'Zoffo',
|
|
|
|
|
'Quimbo', 'Trubzi', 'Hozzy', 'Kabbo', 'Snooki', 'Laffo', 'Glumpi', 'Vibzo', 'Druffo', 'Whirli',
|
|
|
|
|
'Torko', 'Gropzi', 'Plibzo', 'Shaffi', 'Zabboz', 'Wubzi', 'Cloppo', 'Nibzo', 'Flunzi', 'Krabbo'
|
|
|
|
|
];
|
|
|
|
|
$randomName = $names[array_rand($names)];
|
|
|
|
|
$child->setName($randomName);
|
|
|
|
|
|
|
|
|
|
// Chance de fusion
|
|
|
|
|
$fusionRand = mt_rand() / mt_getrandmax();
|
|
|
|
|
if($fusionRand > 0.8) {
|
|
|
|
|
if($fusionRand > 0.5) {
|
|
|
|
|
// Si les emoji parents sont des fusions on remonte l'arbre généalogique jusqu'à trouver un smiley normal
|
|
|
|
|
// On ne peut pas fusionner un smiley déjà fusionné
|
|
|
|
|
$temp1 = $emoji1;
|
|
|
|
@ -141,12 +110,11 @@ class EmojiController extends AbstractController
|
|
|
|
|
|
|
|
|
|
$child->setCode($this->getFusionUrl($temp1->getCode(), $temp2->getCode()));
|
|
|
|
|
} else {
|
|
|
|
|
$rand = mt_rand() / mt_getrandmax();
|
|
|
|
|
if($rand > 0.5) {
|
|
|
|
|
$child->setCode($emoji1->getCode());
|
|
|
|
|
} else {
|
|
|
|
|
$child->setCode($emoji2->getCode());
|
|
|
|
|
}
|
|
|
|
|
$repository = $this->em->getRepository(StockEmoji::class);
|
|
|
|
|
$allEmojis = $repository->findAll();
|
|
|
|
|
$randomKey = array_rand($allEmojis);
|
|
|
|
|
$randomEmoji = $allEmojis[$randomKey]->getCode();
|
|
|
|
|
$child->setCode($randomEmoji);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lors d'une fusion un emoji récupère chaque stat d'un de ces deux parents de manière aléatoire
|
|
|
|
@ -244,23 +212,6 @@ class EmojiController extends AbstractController
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testToMove(){
|
|
|
|
|
$e = new Emoji();
|
|
|
|
|
$e->setName("ROBERT");
|
|
|
|
|
$e->setStrength(5);
|
|
|
|
|
$e->setIntelligence(2);
|
|
|
|
|
$e->setToughness(3);
|
|
|
|
|
$e->setSpeed(4);
|
|
|
|
|
$e2 = new Emoji();
|
|
|
|
|
$e2->setName("BIBOP");
|
|
|
|
|
$e2->setStrength(42);
|
|
|
|
|
$e2->setIntelligence(1);
|
|
|
|
|
$e2->setToughness(1);
|
|
|
|
|
$e2->setSpeed(1);
|
|
|
|
|
$vic = $this->fightEmoji($e,$e2);
|
|
|
|
|
echo $vic->getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/{emojiID}/getParents/', name: 'get_parents_emoji', methods: ['GET'])]
|
|
|
|
|
public function getParentsEmoji(int $emojiID, EmojiRepository $emojiRepository): JsonResponse {
|
|
|
|
|
$emoji = $emojiRepository->find($emojiID);
|
|
|
|
|