<?php

require_once __DIR__ . '/../../src/Events/MonthEndEvent.php';
require_once __DIR__ . '/../../src/Classes/Kobold.php';

class IllnessEvent extends MonthEndEvent
{
    public function getMinAge()
    {
        return 5;
    }

    public function getMinParticipants()
    {
        return 1;
    }

    public function getMaxParticipants()
    {
        return 1;
    }

    public function getCost()
    {
        return 60;
    }

    public function isAvailable()
    {
        return true;
    }

    public function execute()
    {
        $this->story = '';

        $eligible = $this->tribe->getAliveKobolds();
        if (empty($eligible)) {
            return;
        }

        $kobold = $eligible[array_rand($eligible)];

        // Disease types that can be randomly acquired
        $diseases = [
            ['type' => 'smallCut', 'name' => 'small cut'],
            ['type' => 'sunburn', 'name' => 'sunburn'],
        ];

        $disease = $diseases[array_rand($diseases)];

        $kobold->addInjury($disease['type']);

        $nameA = $kobold->getName();

        $illnessVariations = [
            "{$nameA} developed a {$disease['name']} this month and is feeling poorly.",
            "Misfortune struck {$nameA}, who came down with a {$disease['name']}.",
            "{$nameA} is suffering from a {$disease['name']} and needs rest.",
            "A {$disease['name']} has plagued {$nameA} throughout the month.",
            "{$nameA} was afflicted with a {$disease['name']} and is quite uncomfortable.",
            "The elements were unkind to {$nameA}, leaving {$kobold->him()} with a {$disease['name']}.",
            "{$nameA} has been dealing with a {$disease['name']} that emerged this month.",
        ];

        $this->story = $illnessVariations[array_rand($illnessVariations)];

        $kobold->save();
    }
}
