zaela-Server/zone/fearpath.cpp

213 lines
5.4 KiB
C++
Raw Permalink Normal View History

2013-05-09 10:44:08 -04:00
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net)
2013-02-16 16:14:39 -08:00
2013-05-09 10:44:08 -04:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
2013-05-06 13:07:41 -04:00
2013-05-09 10:44:08 -04:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
2013-02-16 16:14:39 -08:00
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
2013-05-09 10:44:08 -04:00
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
2013-05-06 13:07:41 -04:00
2013-05-09 10:44:08 -04:00
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2013-02-16 16:14:39 -08:00
*/
#include "../common/debug.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include "../common/rulesys.h"
2014-08-21 19:33:02 -07:00
#include "../common/misc_functions.h"
2013-02-16 16:14:39 -08:00
#include "map.h"
#include "zone.h"
#include "pathing.h"
#ifdef _WINDOWS
#define snprintf _snprintf
#endif
extern Zone* zone;
#define FEAR_PATHING_DEBUG
//this is called whenever we are damaged to process possible fleeing
void Mob::CheckFlee() {
//if were allready fleeing, dont need to check more...
if(flee_mode && curfp)
return;
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
//dont bother if we are immune to fleeing
if(GetSpecialAbility(IMMUNE_FLEEING) || spellbonuses.ImmuneToFlee)
2013-02-16 16:14:39 -08:00
return;
if(!flee_timer.Check())
return; //only do all this stuff every little while, since
//its not essential that we start running RIGHT away
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
//see if were possibly hurt enough
float ratio = GetHPRatio();
float fleeratio = GetSpecialAbility(FLEE_PERCENT);
fleeratio = fleeratio > 0 ? fleeratio : RuleI(Combat, FleeHPRatio);
if(ratio >= fleeratio)
2013-02-16 16:14:39 -08:00
return;
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
//we might be hurt enough, check con now..
Mob *hate_top = GetHateTop();
if(!hate_top) {
//this should never happen...
StartFleeing();
return;
}
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
float other_ratio = hate_top->GetHPRatio();
if(other_ratio < 20) {
//our hate top is almost dead too... stay and fight
return;
}
2013-05-06 13:07:41 -04:00
//base our flee ratio on our con. this is how the
2013-02-16 16:14:39 -08:00
//attacker sees the mob, since this is all we can observe
uint32 con = GetLevelCon(hate_top->GetLevel(), GetLevel());
float run_ratio;
switch(con) {
//these values are not 100% researched
case CON_GREEN:
run_ratio = fleeratio;
2013-02-16 16:14:39 -08:00
break;
case CON_LIGHTBLUE:
run_ratio = fleeratio * 9 / 10;
2013-02-16 16:14:39 -08:00
break;
case CON_BLUE:
run_ratio = fleeratio * 8 / 10;
2013-02-16 16:14:39 -08:00
break;
default:
run_ratio = fleeratio * 7 / 10;
2013-02-16 16:14:39 -08:00
break;
}
if(ratio < run_ratio)
{
2013-05-09 10:44:08 -04:00
if (RuleB(Combat, FleeIfNotAlone) ||
GetSpecialAbility(ALWAYS_FLEE) ||
(!RuleB(Combat, FleeIfNotAlone) && (entity_list.GetHatedCount(hate_top, this) == 0)))
2013-02-16 16:14:39 -08:00
StartFleeing();
}
}
void Mob::ProcessFlee()
{
2013-02-16 16:14:39 -08:00
2013-05-06 13:07:41 -04:00
//Stop fleeing if effect is applied after they start to run.
//When ImmuneToFlee effect fades it will turn fear back on and check if it can still flee.
if (flee_mode && (GetSpecialAbility(IMMUNE_FLEEING) || spellbonuses.ImmuneToFlee) &&
!spellbonuses.IsFeared && !spellbonuses.IsBlind) {
2013-02-16 16:14:39 -08:00
curfp = false;
return;
}
//see if we are still dying, if so, do nothing
float fleeratio = GetSpecialAbility(FLEE_PERCENT);
fleeratio = fleeratio > 0 ? fleeratio : RuleI(Combat, FleeHPRatio);
if (GetHPRatio() < fleeratio)
2013-02-16 16:14:39 -08:00
return;
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
//we are not dying anymore... see what we do next
2013-05-06 13:07:41 -04:00
2013-02-16 16:14:39 -08:00
flee_mode = false;
2013-05-06 13:07:41 -04:00
//see if we are legitimately feared or blind now
if (!spellbonuses.IsFeared && !spellbonuses.IsBlind) {
//not feared or blind... were done...
2013-02-16 16:14:39 -08:00
curfp = false;
return;
}
}
float Mob::GetFearSpeed()
{
if (flee_mode) {
2013-05-09 10:44:08 -04:00
//we know ratio < FLEE_HP_RATIO
float speed = GetBaseRunspeed();
2013-05-09 10:44:08 -04:00
float ratio = GetHPRatio();
float multiplier = RuleR(Combat, FleeMultiplier);
2013-02-16 16:14:39 -08:00
if (GetSnaredAmount() > 40)
multiplier = multiplier / 6.0f;
2013-02-16 16:14:39 -08:00
speed = speed * ratio * multiplier / 100;
2013-05-06 13:07:41 -04:00
//NPC will eventually stop. Snares speeds this up.
if (speed < 0.09)
speed = 0.0001f;
return speed;
2013-05-09 10:44:08 -04:00
}
// fear and blind use their normal run speed
return GetRunspeed();
2013-02-16 16:14:39 -08:00
}
void Mob::CalculateNewFearpoint()
{
if(RuleB(Pathing, Fear) && zone->pathing)
{
int Node = zone->pathing->GetRandomPathNode();
2013-05-06 13:07:41 -04:00
Map::Vertex Loc = zone->pathing->GetPathNodeCoordinates(Node);
2013-02-16 16:14:39 -08:00
++Loc.z;
Map::Vertex CurrentPosition(GetX(), GetY(), GetZ());
2013-02-16 16:14:39 -08:00
std::list<int> Route = zone->pathing->FindRoute(CurrentPosition, Loc);
2013-02-16 16:14:39 -08:00
if(Route.size() > 0)
{
fear_walkto_x = Loc.x;
fear_walkto_y = Loc.y;
fear_walkto_z = Loc.z;
curfp = true;
mlog(PATHING__DEBUG, "Feared to node %i (%8.3f, %8.3f, %8.3f)", Node, Loc.x, Loc.y, Loc.z);
return;
}
mlog(PATHING__DEBUG, "No path found to selected node. Falling through to old fear point selection.");
}
int loop = 0;
float ranx, rany, ranz;
curfp = false;
while (loop < 100) //Max 100 tries
{
int ran = 250 - (loop*2);
loop++;
ranx = GetX()+MakeRandomInt(0, ran-1)-MakeRandomInt(0, ran-1);
rany = GetY()+MakeRandomInt(0, ran-1)-MakeRandomInt(0, ran-1);
ranz = FindGroundZ(ranx,rany);
if (ranz == -999999)
continue;
float fdist = ranz - GetZ();
if (fdist >= -12 && fdist <= 12 && CheckCoordLosNoZLeaps(GetX(),GetY(),GetZ(),ranx,rany,ranz))
{
curfp = true;
break;
}
}
if (curfp)
{
fear_walkto_x = ranx;
fear_walkto_y = rany;
fear_walkto_z = ranz;
}
else //Break fear
{
BuffFadeByEffect(SE_Fear);
}
}