MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / onHitTarget

Method onHitTarget

Source/Platformer/UnitAction.cpp:476–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

474}
475
476bool 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
496Hit::Hit(Unit* unit)
497 : UnitAction(ActionSetting::UnitActionHit, ActionSetting::PriorityHit, true, unit)

Callers

nothing calls this directly

Calls 8

getBulletDefMethod · 0.80
getVelocityXMethod · 0.80
getEntityMethod · 0.80
getMethod · 0.65
setMethod · 0.65
allocFunction · 0.50
getXMethod · 0.45
getUserDataMethod · 0.45

Tested by

no test coverage detected