mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-08-02 14:41:23 +00:00
chore: format Minecraft.World
This commit is contained in:
@@ -9,89 +9,86 @@
|
||||
#include "MeleeAttackGoal.h"
|
||||
#include "../Navigation/Path.h"
|
||||
|
||||
void MeleeAttackGoal::_init(Mob *mob, float speed, bool trackTarget)
|
||||
{
|
||||
this->attackType = eTYPE_NOTSET;
|
||||
this->mob = mob;
|
||||
this->level = mob->level;
|
||||
this->speed = speed;
|
||||
this->trackTarget = trackTarget;
|
||||
setRequiredControlFlags(Control::MoveControlFlag | Control::LookControlFlag);
|
||||
void MeleeAttackGoal::_init(Mob* mob, float speed, bool trackTarget) {
|
||||
this->attackType = eTYPE_NOTSET;
|
||||
this->mob = mob;
|
||||
this->level = mob->level;
|
||||
this->speed = speed;
|
||||
this->trackTarget = trackTarget;
|
||||
setRequiredControlFlags(Control::MoveControlFlag |
|
||||
Control::LookControlFlag);
|
||||
|
||||
|
||||
attackTime = 0;
|
||||
path = NULL;
|
||||
timeToRecalcPath = 0;
|
||||
attackTime = 0;
|
||||
path = NULL;
|
||||
timeToRecalcPath = 0;
|
||||
}
|
||||
|
||||
MeleeAttackGoal::MeleeAttackGoal(Mob *mob, eINSTANCEOF attackType, float speed, bool trackTarget)
|
||||
{
|
||||
_init(mob, speed, trackTarget);
|
||||
this->attackType = attackType;
|
||||
MeleeAttackGoal::MeleeAttackGoal(Mob* mob, eINSTANCEOF attackType, float speed,
|
||||
bool trackTarget) {
|
||||
_init(mob, speed, trackTarget);
|
||||
this->attackType = attackType;
|
||||
}
|
||||
|
||||
MeleeAttackGoal::MeleeAttackGoal(Mob *mob, float speed, bool trackTarget)
|
||||
{
|
||||
_init(mob,speed,trackTarget);
|
||||
MeleeAttackGoal::MeleeAttackGoal(Mob* mob, float speed, bool trackTarget) {
|
||||
_init(mob, speed, trackTarget);
|
||||
}
|
||||
|
||||
MeleeAttackGoal::~MeleeAttackGoal()
|
||||
{
|
||||
if(path != NULL) delete path;
|
||||
MeleeAttackGoal::~MeleeAttackGoal() {
|
||||
if (path != NULL) delete path;
|
||||
}
|
||||
|
||||
bool MeleeAttackGoal::canUse()
|
||||
{
|
||||
std::shared_ptr<Mob> bestTarget = mob->getTarget();
|
||||
if (bestTarget == NULL) return false;
|
||||
if(!bestTarget->isAlive()) return false;
|
||||
if (attackType != eTYPE_NOTSET && (attackType & bestTarget->GetType()) != attackType) return false;
|
||||
target = std::weak_ptr<Mob>(bestTarget);
|
||||
delete path;
|
||||
path = mob->getNavigation()->createPath(target.lock());
|
||||
return path != NULL;
|
||||
bool MeleeAttackGoal::canUse() {
|
||||
std::shared_ptr<Mob> bestTarget = mob->getTarget();
|
||||
if (bestTarget == NULL) return false;
|
||||
if (!bestTarget->isAlive()) return false;
|
||||
if (attackType != eTYPE_NOTSET &&
|
||||
(attackType & bestTarget->GetType()) != attackType)
|
||||
return false;
|
||||
target = std::weak_ptr<Mob>(bestTarget);
|
||||
delete path;
|
||||
path = mob->getNavigation()->createPath(target.lock());
|
||||
return path != NULL;
|
||||
}
|
||||
|
||||
bool MeleeAttackGoal::canContinueToUse()
|
||||
{
|
||||
std::shared_ptr<Mob> bestTarget = mob->getTarget();
|
||||
if (bestTarget == NULL) return false;
|
||||
if (target.lock() == NULL || !target.lock()->isAlive()) return false;
|
||||
if (!trackTarget) return !mob->getNavigation()->isDone();
|
||||
if (!mob->isWithinRestriction(Mth::floor(target.lock()->x), Mth::floor(target.lock()->y), Mth::floor(target.lock()->z))) return false;
|
||||
return true;
|
||||
bool MeleeAttackGoal::canContinueToUse() {
|
||||
std::shared_ptr<Mob> bestTarget = mob->getTarget();
|
||||
if (bestTarget == NULL) return false;
|
||||
if (target.lock() == NULL || !target.lock()->isAlive()) return false;
|
||||
if (!trackTarget) return !mob->getNavigation()->isDone();
|
||||
if (!mob->isWithinRestriction(Mth::floor(target.lock()->x),
|
||||
Mth::floor(target.lock()->y),
|
||||
Mth::floor(target.lock()->z)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MeleeAttackGoal::start()
|
||||
{
|
||||
mob->getNavigation()->moveTo(path, speed);
|
||||
path = NULL;
|
||||
timeToRecalcPath = 0;
|
||||
void MeleeAttackGoal::start() {
|
||||
mob->getNavigation()->moveTo(path, speed);
|
||||
path = NULL;
|
||||
timeToRecalcPath = 0;
|
||||
}
|
||||
|
||||
void MeleeAttackGoal::stop()
|
||||
{
|
||||
target = std::weak_ptr<Mob>();
|
||||
mob->getNavigation()->stop();
|
||||
void MeleeAttackGoal::stop() {
|
||||
target = std::weak_ptr<Mob>();
|
||||
mob->getNavigation()->stop();
|
||||
}
|
||||
|
||||
void MeleeAttackGoal::tick()
|
||||
{
|
||||
mob->getLookControl()->setLookAt(target.lock(), 30, 30);
|
||||
if (trackTarget || mob->getSensing()->canSee(target.lock()))
|
||||
{
|
||||
if (--timeToRecalcPath <= 0)
|
||||
{
|
||||
timeToRecalcPath = 4 + mob->getRandom()->nextInt(7);
|
||||
mob->getNavigation()->moveTo(target.lock(), speed);
|
||||
}
|
||||
}
|
||||
void MeleeAttackGoal::tick() {
|
||||
mob->getLookControl()->setLookAt(target.lock(), 30, 30);
|
||||
if (trackTarget || mob->getSensing()->canSee(target.lock())) {
|
||||
if (--timeToRecalcPath <= 0) {
|
||||
timeToRecalcPath = 4 + mob->getRandom()->nextInt(7);
|
||||
mob->getNavigation()->moveTo(target.lock(), speed);
|
||||
}
|
||||
}
|
||||
|
||||
attackTime = std::max(attackTime - 1, 0);
|
||||
attackTime = std::max(attackTime - 1, 0);
|
||||
|
||||
double meleeRadiusSqr = (mob->bbWidth * 2) * (mob->bbWidth * 2);
|
||||
if (mob->distanceToSqr(target.lock()->x, target.lock()->bb->y0, target.lock()->z) > meleeRadiusSqr) return;
|
||||
if (attackTime > 0) return;
|
||||
attackTime = 20;
|
||||
mob->doHurtTarget(target.lock());
|
||||
double meleeRadiusSqr = (mob->bbWidth * 2) * (mob->bbWidth * 2);
|
||||
if (mob->distanceToSqr(target.lock()->x, target.lock()->bb->y0,
|
||||
target.lock()->z) > meleeRadiusSqr)
|
||||
return;
|
||||
if (attackTime > 0) return;
|
||||
attackTime = 20;
|
||||
mob->doHurtTarget(target.lock());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user