<commit_before><?php
/**
 * Created by PhpStorm.
 * User: maksim.d
 * Date: 12/7/15
 * Time: 01:46
 */

namespace frontend\models\game\characters\base;


use frontend\models\game\characters\base\interfaces\CharacterInterface;
use frontend\models\game\GameInterface;

abstract class Character implements CharacterInterface
{
    /** @var  GameInterface */
    private $game;
    private $lifespan;

    final public function __construct(GameInterface $game)
    {
        $this->game = $game;
        $this->lifespan = $this->getLifespanMax();
        $this->init();
    }
    public function init() {}

    public function getHitAmount($criticalPercent)
    {
        $amount = $this->game->getConfig()['hitAmounts'][$this->getType()];
        return  $amount + $amount/100*$criticalPercent;
    }

    public function getLifespanMax()
    {
        return $this->game->getConfig()['maxLifespans'][$this->getType()];
    }

    public function getLifespan()
    {
        return $this->lifespan;
    }

    /**
     * @param $value
     * @return int lifespan
     */
    public function setLifespan($value)
    {
        if($value < $this->getLifespanMax())
            return $this->lifespan = $value;
        return $this->lifespan = $this->getLifespanMax();
    }


    public function toDie()
    {
        $this->beforeDead();
        $this->game->finish();
    }

    public function beforeDead()
    {
        // TODO: Implement beforeDead() method.
    }

    abstract public function getType();

    public function beforeTakeHit()
    {
        return true;
    }

    public function takeHit($criticalPercent)
    {
        $this->setLifespan($this->getLifespan() - $this->getHitAmount($criticalPercent));
    }
    public function afterTakeHit()
    {
        if($this->getLifespan() <=0 )
            $this->toDie();
    }

    public function getGame()
    {
        return $this->game;
    }

}<commit_msg>Make getGame function protected and rearange code in Character<commit_after><?php
/**
 * Created by PhpStorm.
 * User: maksim.d
 * Date: 12/7/15
 * Time: 01:46
 */

namespace frontend\models\game\characters\base;


use frontend\models\game\characters\base\interfaces\CharacterInterface;
use frontend\models\game\GameInterface;

abstract class Character implements CharacterInterface
{
    /** @var  GameInterface */
    private $game;
    private $lifespan;

    final public function __construct(GameInterface $game)
    {
        $this->game = $game;
        $this->lifespan = $this->getLifespanMax();
        $this->init();
    }
    public function init() {}

    protected function getGame()
    {
        return $this->game;
    }

    public function getHitAmount($criticalPercent)
    {
        $amount = $this->game->getConfig()['hitAmounts'][$this->getType()];
        return  $amount + $amount/100*$criticalPercent;
    }

    public function getLifespanMax()
    {
        return $this->game->getConfig()['maxLifespans'][$this->getType()];
    }

    public function getLifespan()
    {
        return $this->lifespan;
    }

    /**
     * @param $value
     * @return int lifespan
     */
    public function setLifespan($value)
    {
        if($value < $this->getLifespanMax())
            return $this->lifespan = $value;
        return $this->lifespan = $this->getLifespanMax();
    }

    abstract public function getType();

    public function beforeTakeHit()
    {
        return true;
    }

    public function takeHit($criticalPercent)
    {
        $this->setLifespan($this->getLifespan() - $this->getHitAmount($criticalPercent));
    }

    public function afterTakeHit()
    {
        if($this->getLifespan() <=0 )
            $this->toDie();
    }

    public function beforeDead()
    {
        // TODO: Implement beforeDead() method.
    }

    public function toDie()
    {
        $this->beforeDead();
        $this->game->finish();
    }

}
{'fraction_non_alphanumeric': 0.1391170431211499, 'fraction_numerical': 0.006673511293634497, 'mean_word_length': 2.4763603925066904, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4933455', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1173, 'n_words': 230}