<commit_before>'use strict';

Darwinator.MeleeWeapon = function (game, coolDown, damage, owner) {
    Darwinator.Weapon.call(this, game, coolDown, damage, owner);

    // nothing permanent here, just some values to get started with implementation
    this.coolDown           = 250;
    this.damage             = this.owner.damage;
    this.knockBackDistance  = 2 * this.owner.attributes.strength;
};

Darwinator.MeleeWeapon.prototype = Object.create(Darwinator.Weapon.prototype);

Darwinator.MeleeWeapon.strike = function(target){
  if (!this.onCooldown()){
    var crit  = Math.random() - this.criticalStrike;
    var dmg   = this.damage;

    if (crit < 0){
      dmg *= 2;
    }
    target.takeDamage(dmg);
    this.lastAttack = Date.now();
    return dmg;
  }
};

Darwinator.MeleeWeapon.knockBack = function(target){
    var angle           = this.game.physics.arcade.angleBetween(this.owner, target);
    var targetFuturePos = Darwinator.Helpers.calculatePosition(target.x, target.y, this.knockBackDistance, angle);
    target.knockedBack  = true;
    target.knockBackPos = targetFuturePos;
};<commit_msg>add knockback to melee attacks<commit_after>'use strict';

Darwinator.MeleeWeapon = function (game, coolDown, damage, owner) {
    Darwinator.Weapon.call(this, game, coolDown, damage, owner);

    // nothing permanent here, just some values to get started with implementation
    this.coolDown           = 250;
    this.damage             = this.owner.damage;
    this.knockBackDistance  = 2 * this.owner.attributes.strength;
};

Darwinator.MeleeWeapon.prototype = Object.create(Darwinator.Weapon.prototype);

Darwinator.MeleeWeapon.strike = function(target){
  if (!this.onCooldown()){
    var crit  = Math.random() - this.criticalStrike;
    var dmg   = this.damage;

    if (crit < 0){
      dmg *= 2;
    }
    target.takeDamage(dmg);
    this.lastAttack = Date.now();
    this.knockBack(target);
    return dmg;
  }
};

Darwinator.MeleeWeapon.knockBack = function(target){
    var angle           = this.game.physics.arcade.angleBetween(this.owner, target);
    var targetFuturePos = Darwinator.Helpers.calculatePosition(target.x, target.y, this.knockBackDistance, angle);
    target.knockedBack  = true;
    target.knockBackPos = targetFuturePos;
};
{'fraction_non_alphanumeric': 0.11920529801324503, 'fraction_numerical': 0.005298013245033113, 'mean_word_length': 3.382978723404255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1757677', 'n_tokens_mistral': 773, 'n_tokens_neox': 725, 'n_words': 145}