aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/MeleeAttackGoal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Minecraft.World/MeleeAttackGoal.cpp')
-rw-r--r--Minecraft.World/MeleeAttackGoal.cpp50
1 files changed, 25 insertions, 25 deletions
diff --git a/Minecraft.World/MeleeAttackGoal.cpp b/Minecraft.World/MeleeAttackGoal.cpp
index f3aa6455..7003609e 100644
--- a/Minecraft.World/MeleeAttackGoal.cpp
+++ b/Minecraft.World/MeleeAttackGoal.cpp
@@ -8,12 +8,12 @@
#include "net.minecraft.world.phys.h"
#include "MeleeAttackGoal.h"
-void MeleeAttackGoal::_init(Mob *mob, float speed, bool trackTarget)
+void MeleeAttackGoal::_init(PathfinderMob *mob, double speedModifier, bool trackTarget)
{
this->attackType = eTYPE_NOTSET;
this->mob = mob;
- this->level = mob->level;
- this->speed = speed;
+ level = mob->level;
+ this->speedModifier = speedModifier;
this->trackTarget = trackTarget;
setRequiredControlFlags(Control::MoveControlFlag | Control::LookControlFlag);
@@ -23,15 +23,15 @@ void MeleeAttackGoal::_init(Mob *mob, float speed, bool trackTarget)
timeToRecalcPath = 0;
}
-MeleeAttackGoal::MeleeAttackGoal(Mob *mob, eINSTANCEOF attackType, float speed, bool trackTarget)
+MeleeAttackGoal::MeleeAttackGoal(PathfinderMob *mob, eINSTANCEOF attackType, double speedModifier, bool trackTarget)
{
- _init(mob, speed, trackTarget);
+ _init(mob, speedModifier, trackTarget);
this->attackType = attackType;
}
-MeleeAttackGoal::MeleeAttackGoal(Mob *mob, float speed, bool trackTarget)
+MeleeAttackGoal::MeleeAttackGoal(PathfinderMob *mob, double speedModifier, bool trackTarget)
{
- _init(mob,speed,trackTarget);
+ _init(mob,speedModifier,trackTarget);
}
MeleeAttackGoal::~MeleeAttackGoal()
@@ -41,56 +41,56 @@ MeleeAttackGoal::~MeleeAttackGoal()
bool MeleeAttackGoal::canUse()
{
- 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 = weak_ptr<Mob>(bestTarget);
+ shared_ptr<LivingEntity> target = mob->getTarget();
+ if (target == NULL) return false;
+ if (!target->isAlive()) return false;
+ if (attackType != NULL && !target->instanceof(attackType)) return false;
delete path;
- path = mob->getNavigation()->createPath(target.lock());
+ path = mob->getNavigation()->createPath(target);
return path != NULL;
}
bool MeleeAttackGoal::canContinueToUse()
{
- shared_ptr<Mob> bestTarget = mob->getTarget();
- if (bestTarget == NULL) return false;
- if (target.lock() == NULL || !target.lock()->isAlive()) return false;
+ shared_ptr<LivingEntity> target = mob->getTarget();
+ if (target == NULL) return false;
+ if (!target->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;
+ if (!mob->isWithinRestriction(Mth::floor(target->x), Mth::floor(target->y), Mth::floor(target->z))) return false;
return true;
}
void MeleeAttackGoal::start()
{
- mob->getNavigation()->moveTo(path, speed);
+ mob->getNavigation()->moveTo(path, speedModifier);
path = NULL;
timeToRecalcPath = 0;
}
void MeleeAttackGoal::stop()
{
- target = weak_ptr<Mob>();
mob->getNavigation()->stop();
}
void MeleeAttackGoal::tick()
{
- mob->getLookControl()->setLookAt(target.lock(), 30, 30);
- if (trackTarget || mob->getSensing()->canSee(target.lock()))
+ shared_ptr<LivingEntity> target = mob->getTarget();
+ mob->getLookControl()->setLookAt(target, 30, 30);
+ if (trackTarget || mob->getSensing()->canSee(target))
{
if (--timeToRecalcPath <= 0)
{
timeToRecalcPath = 4 + mob->getRandom()->nextInt(7);
- mob->getNavigation()->moveTo(target.lock(), speed);
+ mob->getNavigation()->moveTo(target, speedModifier);
}
}
attackTime = 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;
+ double meleeRadiusSqr = (mob->bbWidth * 2) * (mob->bbWidth * 2) + target->bbWidth;
+ if (mob->distanceToSqr(target->x, target->bb->y0, target->z) > meleeRadiusSqr) return;
if (attackTime > 0) return;
attackTime = 20;
- mob->doHurtTarget(target.lock());
+ if (mob->getCarriedItem() != NULL) mob->swing();
+ mob->doHurtTarget(target);
}