- Joined
- Feb 16, 2007
- Messages
- 71
- Reaction score
- 0
BETA TESTING
Well i have modified the detection very stronghly the formula for stealth detection in unit.cpp
here are the fallowing fixes :
-Range detection, centers on mob no more 3 feet extremeties so it is now possible to implement correctly sap and other stealth attacjs
-Collision detection, if touching a mob stealth is automaticly lost
-Stealth depending on level, the higher the difference in level the higher the probability of detection ( using old values minus the level of mob values as it should change anything towards detection, only difference in level between mo.
-Different probability per difference of level. If the difference is 0 very low possibility of being detected if it is 4 very higher and more than 5 you are detected automaticly.
-If mobs are more than 5 levels they will turn to face the player and will fallow them from their position, if they come closer they will get attack if they go farther away they will be ignored. (Higher the difference in level the farther away they will be detected)
-Detection is based on level difference, distance, rank of mobs. It is know that stealth stats of mobs and player do not work, when they do the code will be easy implemented in the body of the function.
Here is the code, at the bottom is the release files.
added changes in mangosconf.ini :
modified function in object.cpp
Added the fallowing variable in world.cpp in under void World::SetInitialWorldSettings() (under the raterate section)
Added the fallowing under world.h under enum Rates
Main function unit.cpp:
New includes :
Here is the main function unit.cpp
And now for the compile 3322 for 1.12.1 and source files:
Download:
Let me know what you guys think, i would want this to be as blizlike as possible. Take in mind that this function is repeated very fast in the code, so probsbilities need to be low.
VERY IMPORTANT, TO ENABLE DETECTION YOU MUST SELECT 1 IN THE INI UNDER STEAL_RATE 0 will make you go in super stealth mode, only collision will mob will bring you out of stealth
All comments are welcomed, this is so this function can be bettered and we can all get some better rogues play in wow
lates
Well i have modified the detection very stronghly the formula for stealth detection in unit.cpp
here are the fallowing fixes :
-Range detection, centers on mob no more 3 feet extremeties so it is now possible to implement correctly sap and other stealth attacjs
-Collision detection, if touching a mob stealth is automaticly lost
-Stealth depending on level, the higher the difference in level the higher the probability of detection ( using old values minus the level of mob values as it should change anything towards detection, only difference in level between mo.
-Different probability per difference of level. If the difference is 0 very low possibility of being detected if it is 4 very higher and more than 5 you are detected automaticly.
-If mobs are more than 5 levels they will turn to face the player and will fallow them from their position, if they come closer they will get attack if they go farther away they will be ignored. (Higher the difference in level the farther away they will be detected)
-Detection is based on level difference, distance, rank of mobs. It is know that stealth stats of mobs and player do not work, when they do the code will be easy implemented in the body of the function.
Here is the code, at the bottom is the release files.
added changes in mangosconf.ini :
Code:
#************************* NEW*****************
#Stealth probability rate
# default = 1, 0 = probability 0 of being seen by mob
RATE_STEALTH=0
#***********************************************
Code:
float WorldObject::GetDistanceSq(const WorldObject* obj) const
{
float dx = GetPositionX() - obj->GetPositionX();
float dy = GetPositionY() - obj->GetPositionY();
float dz = GetPositionZ() - obj->GetPositionZ();
float sizefactor = GetObjectSize() + obj->GetObjectSize() - 2.28; //size factor is too big student1
if (sizefactor <= 0) sizefactor = 1; //makes sures values are not negative for too little objects student1
float dist = sqrt((dx*dx) + (dy*dy) + (dz*dz)) - sizefactor;
return ( dist > 0 ? dist * dist : 0);
}
Code:
//Added mangos.ini rate_stealth, this variable controls probability of stealth detection
rate_values[RATE_STEALTH] = sConfig.GetFloatDefault("RATE_STEALTH", 1);
Code:
//Stealth prob initialisation
RATE_STEALTH,
New includes :
Code:
#include <iostream> // enables input and output //student1
#include "RedZoneDistrict.h" // addon student1
#include "CellImpl.h" // addon student1
#include "GridNotifiersImpl.h" // addon student1
#include "MapManager.h" // addon student1
using namespace std; //student 1
Code:
bool Unit::isVisibleFor(Unit* u, bool detect)
{
// Visible units, always are visible for all pjs
if (m_Visibility == VISIBILITY_ON)
return true;
// GMs are visible for higher gms (or players are visible for gms)
if (u->GetTypeId() == TYPEID_PLAYER && ((Player *)u)->isGameMaster())
return (GetTypeId() == TYPEID_PLAYER && ((Player *)this)->GetSession()->GetSecurity() <= ((Player *)u)->GetSession()->GetSecurity());
// non faction visibility non-breakable for non-GMs
if (m_Visibility == VISIBILITY_OFF)
return false;
// Units far than MAX_DIST_INVISIBLE, that are not gms and are stealth, are not visibles too
if (!this->IsWithinDist(u,MAX_DIST_INVISIBLE_UNIT))
return false;
// Stealth not hostile units, not visibles (except Player-with-Player case)
if (!u->IsHostileTo(this))
{
// player autodetect other player with stealth only if he in same group or raid or same team (raid/team case dependent from conf setting)
if(GetTypeId()==TYPEID_PLAYER && u->GetTypeId()==TYPEID_PLAYER)
{
if(((Player*)this)->IsGroupVisibleFor(((Player*)u)))
return true;
// else apply same rules as for hostile case (detecting check)
}
else
return true;
}
// if in non-detect mode then invisible for unit
if(!detect)
return false;
bool IsVisible = true;
bool isNotFront;
isNotFront = u->isInFront(this, MAX_DIST_INVISIBLE_UNIT * MAX_DIST_INVISIBLE_UNIT)? 0 : 1;;
float Distance = sqrt(GetDistanceSq(u));
float prob = 0;
float modifier = 1;
//Assigns the current level of the mobs and players to 2 variables
int mobLevel = u->getLevel();
int playerLevel = ((Player*)this)->getLevel();
int LevelDif = mobLevel - playerLevel;
int32 x = (u->m_detectStealth / 5) - (m_stealthvalue / 5) + 59; //int32 x = u->getLevel() + (u->m_detectStealth / 5) - (m_stealthvalue / 5) + 59;
//rank initialisation
int rank =0;
//Gets the difference in level between player and mob
float DistanceFormula = ((((sWorld.getRate(RATE_CREATURE_AGGRO) * 16))/5)*LevelDif);
//Original probability values
//removed level of mob in calculation as it should not affect the detection, it is mainly dependant on level difference
float AverageDist = 1 - 0.11016949*x + 0.00301637*x*x; //at this distance, the detector has to be a 15% prob of detect
if (x<0) x = 0;
if (AverageDist < 1) AverageDist = 1;
if (Distance > AverageDist)
//prob between 10% and 0%
prob = (AverageDist-200+9*Distance)/(AverageDist-20);
else
prob = 75 - (60/AverageDist)*Distance; //prob between 15% and 75% (75% max prob)
if (isNotFront)
prob = prob/100;
if (prob < 0.1)
prob = 0.1;
//applies a probability modifier depending if mobs are normal, elite, rare, rare elite or world bosses
switch (rank)
{
//normal no modifier
case 0 : modifier =1; break;
case 1 : modifier =1.2; break; // elite
case 2 : modifier =1.4; break; // rareelite
case 3 : modifier =1.6; break; //worldboss
case 4 : modifier =1.8; break; //rare elite
default : modifier=1; break; //abnormal case, should never enter this line, only for safety.
}
//Sets 'owner' variable
Creature* pCreature = ((Creature *)u);
Creature& owner = *pCreature;
//Show in console distance between player and mob
cout << "LevelDifference: " << LevelDif << "\n";
// Detection variable = 0 then no stealth detection (simple collision detection used independant of level)
cout << "Distance from mob: " << Distance << "\n";
cout << "Agro selected in ini: " << sWorld.getRate(RATE_CREATURE_AGGRO) << "\n";
cout << "DistanceDetect: " << DistanceFormula << "\n";
cout << "BufferZone: " << DistanceFormula*2 << "\n";
cout << "Mob detect stealth value: " << u->m_detectStealth << "\n";
cout << "Player stealth value: " << ((Player*)this)->m_stealthvalue << "\n";
//****************************************************************
//New system, takes level in consideration when applying detection
//****************************************************************
//All level will not be detected unless collison (if it is enabled in ini) 0 means there is no detection
if ((sWorld.getRate(RATE_STEALTH)==0) && (Distance > 1))
{
IsVisible = false; // remains visible student1
return IsVisible && ( Distance <= MAX_DIST_INVISIBLE_UNIT * MAX_DIST_INVISIBLE_UNIT);
}
//If the mob is one level less or more there is no detection unless there is collision
if ((LevelDif<0) && (Distance> 1))
{
//Makes sure it removes Threat once mob it too far
IsVisible = false;
return IsVisible && ( Distance <= MAX_DIST_INVISIBLE_UNIT * MAX_DIST_INVISIBLE_UNIT);
}
//Distance of approch player stays stealth 100% is dependant of level. No probabiliy or detection is rolled
//This establishes a buffer zone in between mob start to see you and mob start to roll probabilities or detect you
if ((Distance < 100) && (Distance > (DistanceFormula * 2) * modifier))
{
IsVisible = false;
return IsVisible && ( Distance <= MAX_DIST_INVISIBLE_UNIT * MAX_DIST_INVISIBLE_UNIT);
}
//******************************************************************************************************************************************
//Mobs will face players if they are 5 levels higher or more at a certain distance the higher the difference in level the higher the distance
//*******************************************************************************************************************************************
//If mob is a higher level but is approached from behind, mob will turn toweard player and attack if closer than 7 fet
if ( (LevelDif>=5) && (Distance > 1) )
{
//Mob turns to look at player
((Creature *)u)->SetInFront((Player*)this);
CellPair p = MaNGOS::ComputeCellPair(owner.GetPositionX(), owner.GetPositionY());
Cell cell = RedZone::GetZone(p);
cell.data.Part.reserved = ALL_DISTRICT;
MaNGOS::CreatureVisibleMovementNotifier notifier(owner);
TypeContainerVisitor<MaNGOS::CreatureVisibleMovementNotifier, WorldTypeMapContainer > player_notifier(notifier);
CellLock<GridReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, player_notifier, *MapManager::Instance().GetMap(owner.GetMapId()));
((Creature *)u)->StopMoving();
//If player comes close to mob he gets detected ( Formula is based on agro and level difference between mob and player
//Formula used is (((aggro * 16)/5) * level difference between mob and player) Will give you the level of detection
//At agro 0.4 and at a difference of 5 levels you can approach until 6.4 feet. At a level diff of 6 you are detected at 7.68 feet or closer etc
if (Distance <= (DistanceFormula * modifier))
{
//Puts mob back to threat to normal value
IsVisible = true;
return IsVisible && ( Distance <= MAX_DIST_INVISIBLE_UNIT * MAX_DIST_INVISIBLE_UNIT);
}
IsVisible = false;
return IsVisible && ( Distance <= MAX_DIST_INVISIBLE_UNIT * MAX_DIST_INVISIBLE_UNIT);
}
//This establishes level detection based on level, the higher the mob level the higher the chance of detection.
switch (LevelDif)
{
//If same level with mob
case 0:
//min prob of detect is 0.1
if ((rand_chance() > ((prob*modifier)/15)) && (Distance> 1))
{
IsVisible = false;
cout << "Probability: " << prob << "\n";
}
else
IsVisible = true;
break;
//If mob has one level more
case 1:
if ((rand_chance() > ((prob*modifier)/10)) && (Distance> 1))
{
IsVisible = false;
cout << "Probability: " << prob << "\n";
}
else
IsVisible = true;
break;
//If mob has 2 levels more
case 2:
if ((rand_chance() > ((prob*modifier)/5)) && (Distance > 1))
{
IsVisible = false;
cout << "Probability: " << prob << "\n";
}
else
IsVisible = true;
break;
//If mob has 3 level more
case 3:
//min prob of detect is 0.1
if ((rand_chance() > ((prob*modifier)/1.5)) && (Distance > 1))
IsVisible = false;
else
IsVisible = true;
break;
//If mob has 4 levels more
case 4:
//min prob of detect is 0.1
if ((rand_chance() > (prob*modifier)) && (Distance > 1))
IsVisible = false;
else
IsVisible = true;
break;
default : //abnormal case, should never enter this line, only for safety.
if ((rand_chance() > ((prob*modifier)/1.5)) && (Distance > 1))
IsVisible = false;
else
IsVisible = true;
break;
}
return IsVisible && ( Distance <= MAX_DIST_INVISIBLE_UNIT * MAX_DIST_INVISIBLE_UNIT);
}
Download:
To view the content, you need to sign in or register
Let me know what you guys think, i would want this to be as blizlike as possible. Take in mind that this function is repeated very fast in the code, so probsbilities need to be low.
VERY IMPORTANT, TO ENABLE DETECTION YOU MUST SELECT 1 IN THE INI UNDER STEAL_RATE 0 will make you go in super stealth mode, only collision will mob will bring you out of stealth
All comments are welcomed, this is so this function can be bettered and we can all get some better rogues play in wow

lates