Advertisement
Cool_boy21

Polytopia unit battle

May 29th, 2018
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function getBattleResult(attacker:WorldObject, defender:WorldObject) : Object
  2.       {
  3.          var _magic_:* = 4.5;
  4.          var _attk_:Number = attacker.attack * (attacker.health / attacker.maxHealth);
  5.          var _deff_:Number = defender.defence * (defender.health / defender.maxHealth);
  6.          var _sum_:Number = _attk_ + _deff_;
  7.          var _attack_:Number = Math.round(_attk_ / _sum_ * attacker.attack * _magic_);
  8.          var _defence_:* = -1;
  9.          if(defender.tile.getAttackRange(defender.owner).indexOf(attacker.tile) > -1)
  10.          {
  11.             _defence_ = Number(Math.round(_deff_ / defender.defenceBonus / _sum_ * defender.defence * _magic_));
  12.          }
  13.          var _proceed_:Boolean = false;
  14.          if(attacker is Unit && defender.health <= _attack_ && attacker.range == 1 && Boolean(defender.tile.moveOk(attacker as Unit)))
  15.          {
  16.             _proceed_ = true;
  17.          }
  18.          return {
  19.             "attack":_attack_,
  20.             "defence":_defence_,
  21.             "proceed":_proceed_
  22.          };
  23.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement