| 474 | } |
| 475 | |
| 476 | bool RangeAttack::onHitTarget(Bullet* bullet, Unit* target, Vec2 hitPoint, Vec2 normal) { |
| 477 | /* Get hit point */ |
| 478 | bool attackFromRight = false; |
| 479 | if (bullet->getBulletDef()->damageRadius > 0.0f) { |
| 480 | attackFromRight = bullet->getX() < hitPoint.x; |
| 481 | } else { |
| 482 | attackFromRight = bullet->getVelocityX() < 0.0f; |
| 483 | } |
| 484 | Entity* entity = target->getEntity(); |
| 485 | auto attackPower = _owner->getEntity()->get(ActionSetting::AttackPower, Vec2::zero); |
| 486 | auto data = target->getUserData(); |
| 487 | data->set(ActionSetting::HitPoint, Value::alloc(hitPoint)); |
| 488 | data->set(ActionSetting::HitPower, Value::alloc(attackPower)); |
| 489 | data->set(ActionSetting::HitFromRight, Value::alloc(attackFromRight)); |
| 490 | /* Make damage */ |
| 491 | float damage = Attack::getDamage(target); |
| 492 | entity->set(ActionSetting::HP, entity->get<double>(ActionSetting::HP) - damage); |
| 493 | return true; |
| 494 | } |
| 495 | |
| 496 | Hit::Hit(Unit* unit) |
| 497 | : UnitAction(ActionSetting::UnitActionHit, ActionSetting::PriorityHit, true, unit) |
nothing calls this directly
no test coverage detected