mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-14 03:32:27 +00:00
Trap converted to use xyz_location as m_Position instead of x, y, z
This commit is contained in:
parent
54bc1b06e4
commit
2546c6c226
@ -11699,29 +11699,29 @@ void Client::Handle_OP_SenseTraps(const EQApplicationPacket *app)
|
|||||||
int uskill = GetSkill(SkillSenseTraps);
|
int uskill = GetSkill(SkillSenseTraps);
|
||||||
if ((MakeRandomInt(0, 99) + uskill) >= (MakeRandomInt(0, 99) + trap->skill*0.75))
|
if ((MakeRandomInt(0, 99) + uskill) >= (MakeRandomInt(0, 99) + trap->skill*0.75))
|
||||||
{
|
{
|
||||||
float xdif = trap->x - GetX();
|
auto diff = trap->m_Position - GetPosition();
|
||||||
float ydif = trap->y - GetY();
|
|
||||||
if (xdif == 0 && ydif == 0)
|
if (diff.m_X == 0 && diff.m_Y == 0)
|
||||||
Message(MT_Skills, "You sense a trap right under your feet!");
|
Message(MT_Skills, "You sense a trap right under your feet!");
|
||||||
else if (xdif > 10 && ydif > 10)
|
else if (diff.m_X > 10 && diff.m_Y > 10)
|
||||||
Message(MT_Skills, "You sense a trap to the NorthWest.");
|
Message(MT_Skills, "You sense a trap to the NorthWest.");
|
||||||
else if (xdif < -10 && ydif > 10)
|
else if (diff.m_X < -10 && diff.m_Y > 10)
|
||||||
Message(MT_Skills, "You sense a trap to the NorthEast.");
|
Message(MT_Skills, "You sense a trap to the NorthEast.");
|
||||||
else if (ydif > 10)
|
else if (diff.m_Y > 10)
|
||||||
Message(MT_Skills, "You sense a trap to the North.");
|
Message(MT_Skills, "You sense a trap to the North.");
|
||||||
else if (xdif > 10 && ydif < -10)
|
else if (diff.m_X > 10 && diff.m_Y < -10)
|
||||||
Message(MT_Skills, "You sense a trap to the SouthWest.");
|
Message(MT_Skills, "You sense a trap to the SouthWest.");
|
||||||
else if (xdif < -10 && ydif < -10)
|
else if (diff.m_X < -10 && diff.m_Y < -10)
|
||||||
Message(MT_Skills, "You sense a trap to the SouthEast.");
|
Message(MT_Skills, "You sense a trap to the SouthEast.");
|
||||||
else if (ydif < -10)
|
else if (diff.m_Y < -10)
|
||||||
Message(MT_Skills, "You sense a trap to the South.");
|
Message(MT_Skills, "You sense a trap to the South.");
|
||||||
else if (xdif > 10)
|
else if (diff.m_X > 10)
|
||||||
Message(MT_Skills, "You sense a trap to the West.");
|
Message(MT_Skills, "You sense a trap to the West.");
|
||||||
else
|
else
|
||||||
Message(MT_Skills, "You sense a trap to the East.");
|
Message(MT_Skills, "You sense a trap to the East.");
|
||||||
trap->detected = true;
|
trap->detected = true;
|
||||||
|
|
||||||
float angle = CalculateHeadingToTarget(trap->x, trap->y);
|
float angle = CalculateHeadingToTarget(trap->m_Position.m_X, trap->m_Position.m_Y);
|
||||||
|
|
||||||
if (angle < 0)
|
if (angle < 0)
|
||||||
angle = (256 + angle);
|
angle = (256 + angle);
|
||||||
|
|||||||
@ -68,7 +68,7 @@ Entity::Entity()
|
|||||||
|
|
||||||
Entity::~Entity()
|
Entity::~Entity()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Client *Entity::CastToClient()
|
Client *Entity::CastToClient()
|
||||||
@ -493,14 +493,14 @@ void EntityList::MobProcess()
|
|||||||
while (it != mob_list.end()) {
|
while (it != mob_list.end()) {
|
||||||
uint16 id = it->first;
|
uint16 id = it->first;
|
||||||
Mob *mob = it->second;
|
Mob *mob = it->second;
|
||||||
|
|
||||||
size_t sz = mob_list.size();
|
size_t sz = mob_list.size();
|
||||||
bool p_val = mob->Process();
|
bool p_val = mob->Process();
|
||||||
size_t a_sz = mob_list.size();
|
size_t a_sz = mob_list.size();
|
||||||
|
|
||||||
if(a_sz > sz) {
|
if(a_sz > sz) {
|
||||||
//increased size can potentially screw with iterators so reset it to current value
|
//increased size can potentially screw with iterators so reset it to current value
|
||||||
//if buckets are re-orderered we may skip a process here and there but since
|
//if buckets are re-orderered we may skip a process here and there but since
|
||||||
//process happens so often it shouldn't matter much
|
//process happens so often it shouldn't matter much
|
||||||
it = mob_list.find(id);
|
it = mob_list.find(id);
|
||||||
++it;
|
++it;
|
||||||
@ -3106,33 +3106,25 @@ void EntityList::OpenDoorsNear(NPC *who)
|
|||||||
|
|
||||||
void EntityList::SendAlarm(Trap *trap, Mob *currenttarget, uint8 kos)
|
void EntityList::SendAlarm(Trap *trap, Mob *currenttarget, uint8 kos)
|
||||||
{
|
{
|
||||||
float val2 = trap->effectvalue * trap->effectvalue;
|
float preSquareDistance = trap->effectvalue * trap->effectvalue;
|
||||||
|
|
||||||
auto it = npc_list.begin();
|
for (auto it = npc_list.begin();it != npc_list.end(); ++it) {
|
||||||
while (it != npc_list.end()) {
|
|
||||||
NPC *cur = it->second;
|
NPC *cur = it->second;
|
||||||
float curdist = 0;
|
|
||||||
float tmp = cur->GetX() - trap->x;
|
auto diff = cur->GetPosition() - trap->m_Position;
|
||||||
curdist += tmp*tmp;
|
float curdist = diff.m_X * diff.m_X + diff.m_Y * diff.m_Y + diff.m_Z * diff.m_Z;
|
||||||
tmp = cur->GetY() - trap->y;
|
|
||||||
curdist += tmp*tmp;
|
if (cur->GetOwner() || cur->IsEngaged() || curdist > preSquareDistance )
|
||||||
tmp = cur->GetZ() - trap->z;
|
continue;
|
||||||
curdist += tmp*tmp;
|
|
||||||
if (!cur->GetOwner() &&
|
if (kos) {
|
||||||
/*!cur->CastToMob()->dead && */
|
uint8 factioncon = currenttarget->GetReverseFactionCon(cur);
|
||||||
!cur->IsEngaged() &&
|
if (factioncon == FACTION_THREATENLY || factioncon == FACTION_SCOWLS) {
|
||||||
curdist <= val2 )
|
|
||||||
{
|
|
||||||
if (kos) {
|
|
||||||
uint8 factioncon = currenttarget->GetReverseFactionCon(cur);
|
|
||||||
if (factioncon == FACTION_THREATENLY || factioncon == FACTION_SCOWLS) {
|
|
||||||
cur->AddToHateList(currenttarget,1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cur->AddToHateList(currenttarget,1);
|
cur->AddToHateList(currenttarget,1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++it;
|
else
|
||||||
|
cur->AddToHateList(currenttarget,1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3636,7 +3628,7 @@ int16 EntityList::CountTempPets(Mob *owner)
|
|||||||
}
|
}
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
owner->SetTempPetCount(count);
|
owner->SetTempPetCount(count);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
|
|||||||
@ -67,6 +67,16 @@ const xyz_heading xyz_heading::operator -(const xyz_location& rhs) const{
|
|||||||
return xyz_heading(m_X - rhs.m_X, m_Y - rhs.m_Y, m_Z - rhs.m_Z, m_Heading);
|
return xyz_heading(m_X - rhs.m_X, m_Y - rhs.m_Y, m_Z - rhs.m_Z, m_Heading);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void xyz_heading::ABS_XYZ(void) {
|
||||||
|
if (m_X < 0)
|
||||||
|
m_X = -m_X;
|
||||||
|
|
||||||
|
if (m_Y < 0)
|
||||||
|
m_Y = -m_Y;
|
||||||
|
|
||||||
|
if (m_Z < 0)
|
||||||
|
m_Z = -m_Z;
|
||||||
|
}
|
||||||
|
|
||||||
xyz_location::xyz_location(float x, float y, float z) :
|
xyz_location::xyz_location(float x, float y, float z) :
|
||||||
m_X(x),
|
m_X(x),
|
||||||
|
|||||||
@ -74,6 +74,7 @@ public:
|
|||||||
|
|
||||||
const xyz_heading operator -(const xyz_location& rhs) const;
|
const xyz_heading operator -(const xyz_location& rhs) const;
|
||||||
|
|
||||||
|
void ABS_XYZ();
|
||||||
bool isOrigin() const { return m_X == 0.0f && m_Y == 0.0f && m_Z == 0.0f;}
|
bool isOrigin() const { return m_X == 0.0f && m_Y == 0.0f && m_Z == 0.0f;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -50,12 +50,10 @@ CREATE TABLE traps (
|
|||||||
Trap::Trap() :
|
Trap::Trap() :
|
||||||
Entity(),
|
Entity(),
|
||||||
respawn_timer(600000),
|
respawn_timer(600000),
|
||||||
chkarea_timer(500)
|
chkarea_timer(500),
|
||||||
|
m_Position(xyz_location::Origin())
|
||||||
{
|
{
|
||||||
trap_id = 0;
|
trap_id = 0;
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
z = 0;
|
|
||||||
maxzdiff = 0;
|
maxzdiff = 0;
|
||||||
radius = 0;
|
radius = 0;
|
||||||
effect = 0;
|
effect = 0;
|
||||||
@ -145,8 +143,8 @@ void Trap::Trigger(Mob* trigger)
|
|||||||
if ((tmp = database.GetNPCType(effectvalue)))
|
if ((tmp = database.GetNPCType(effectvalue)))
|
||||||
{
|
{
|
||||||
auto randomOffset = xyz_heading(-5 + MakeRandomInt(0, 10),-5 + MakeRandomInt(0, 10),-5 + MakeRandomInt(0, 10), MakeRandomInt(0, 249));
|
auto randomOffset = xyz_heading(-5 + MakeRandomInt(0, 10),-5 + MakeRandomInt(0, 10),-5 + MakeRandomInt(0, 10), MakeRandomInt(0, 249));
|
||||||
auto position = randomOffset + xyz_location(x, y, z);
|
auto spawnPosition = randomOffset + m_Position;
|
||||||
NPC* new_npc = new NPC(tmp, nullptr, position, FlyMode3);
|
NPC* new_npc = new NPC(tmp, nullptr, spawnPosition, FlyMode3);
|
||||||
new_npc->AddLootTable();
|
new_npc->AddLootTable();
|
||||||
entity_list.AddNPC(new_npc);
|
entity_list.AddNPC(new_npc);
|
||||||
new_npc->AddToHateList(trigger,1);
|
new_npc->AddToHateList(trigger,1);
|
||||||
@ -168,8 +166,8 @@ void Trap::Trigger(Mob* trigger)
|
|||||||
if ((tmp = database.GetNPCType(effectvalue)))
|
if ((tmp = database.GetNPCType(effectvalue)))
|
||||||
{
|
{
|
||||||
auto randomOffset = xyz_heading(-2 + MakeRandomInt(0, 5), -2 + MakeRandomInt(0, 5), -2 + MakeRandomInt(0, 5), MakeRandomInt(0, 249));
|
auto randomOffset = xyz_heading(-2 + MakeRandomInt(0, 5), -2 + MakeRandomInt(0, 5), -2 + MakeRandomInt(0, 5), MakeRandomInt(0, 249));
|
||||||
auto position = randomOffset + xyz_location(x, y, z);
|
auto spawnPosition = randomOffset + m_Position;
|
||||||
NPC* new_npc = new NPC(tmp, nullptr, position, FlyMode3);
|
NPC* new_npc = new NPC(tmp, nullptr, spawnPosition, FlyMode3);
|
||||||
new_npc->AddLootTable();
|
new_npc->AddLootTable();
|
||||||
entity_list.AddNPC(new_npc);
|
entity_list.AddNPC(new_npc);
|
||||||
new_npc->AddToHateList(trigger,1);
|
new_npc->AddToHateList(trigger,1);
|
||||||
@ -212,55 +210,47 @@ Trap* EntityList::FindNearbyTrap(Mob* searcher, float max_dist) {
|
|||||||
|
|
||||||
float max_dist2 = max_dist*max_dist;
|
float max_dist2 = max_dist*max_dist;
|
||||||
Trap *cur;
|
Trap *cur;
|
||||||
auto it = trap_list.begin();
|
|
||||||
while (it != trap_list.end()) {
|
|
||||||
cur = it->second;
|
|
||||||
if(!cur->disarmed) {
|
|
||||||
float curdist = 0;
|
|
||||||
float tmp = searcher->GetX() - cur->x;
|
|
||||||
curdist += tmp*tmp;
|
|
||||||
tmp = searcher->GetY() - cur->y;
|
|
||||||
curdist += tmp*tmp;
|
|
||||||
tmp = searcher->GetZ() - cur->z;
|
|
||||||
curdist += tmp*tmp;
|
|
||||||
|
|
||||||
if (curdist < max_dist2 && curdist < dist)
|
for (auto it = trap_list.begin(); it != trap_list.end(); ++it) {
|
||||||
{
|
cur = it->second;
|
||||||
dist = curdist;
|
if(cur->disarmed)
|
||||||
current_trap = cur;
|
continue;
|
||||||
}
|
|
||||||
}
|
auto diff = searcher->GetPosition() - cur->m_Position;
|
||||||
++it;
|
float curdist = diff.m_X * diff.m_X + diff.m_Y * diff.m_Y + diff.m_Z * diff.m_Z;
|
||||||
|
|
||||||
|
if (curdist < max_dist2 && curdist < dist)
|
||||||
|
{
|
||||||
|
dist = curdist;
|
||||||
|
current_trap = cur;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return current_trap;
|
return current_trap;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mob* EntityList::GetTrapTrigger(Trap* trap) {
|
Mob* EntityList::GetTrapTrigger(Trap* trap) {
|
||||||
Mob* savemob = 0;
|
Mob* savemob = 0;
|
||||||
|
|
||||||
float xdiff, ydiff, zdiff;
|
|
||||||
|
|
||||||
float maxdist = trap->radius * trap->radius;
|
float maxdist = trap->radius * trap->radius;
|
||||||
|
|
||||||
auto it = client_list.begin();
|
for (auto it = client_list.begin(); it != client_list.end(); ++it) {
|
||||||
while (it != client_list.end()) {
|
|
||||||
Client* cur = it->second;
|
Client* cur = it->second;
|
||||||
zdiff = cur->GetZ() - trap->z;
|
|
||||||
if(zdiff < 0)
|
|
||||||
zdiff = 0 - zdiff;
|
|
||||||
|
|
||||||
xdiff = cur->GetX() - trap->x;
|
auto diff = cur->GetPosition() - trap->m_Position;
|
||||||
ydiff = cur->GetY() - trap->y;
|
diff.ABS_XYZ();
|
||||||
if ((xdiff*xdiff + ydiff*ydiff) <= maxdist
|
|
||||||
&& zdiff < trap->maxzdiff)
|
if ((diff.m_X*diff.m_X + diff.m_Y*diff.m_Y) <= maxdist
|
||||||
|
&& diff.m_Z < trap->maxzdiff)
|
||||||
{
|
{
|
||||||
if (MakeRandomInt(0,100) < trap->chance)
|
if (MakeRandomInt(0,100) < trap->chance)
|
||||||
return(cur);
|
return cur;
|
||||||
else
|
else
|
||||||
savemob = cur;
|
savemob = cur;
|
||||||
}
|
}
|
||||||
++it;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return savemob;
|
return savemob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,9 +269,7 @@ bool ZoneDatabase::LoadTraps(const char* zonename, int16 version) {
|
|||||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
Trap* trap = new Trap();
|
Trap* trap = new Trap();
|
||||||
trap->trap_id = atoi(row[0]);
|
trap->trap_id = atoi(row[0]);
|
||||||
trap->x = atof(row[1]);
|
trap->m_Position = xyz_location(atof(row[1]), atof(row[2]), atof(row[3]));
|
||||||
trap->y = atof(row[2]);
|
|
||||||
trap->z = atof(row[3]);
|
|
||||||
trap->effect = atoi(row[4]);
|
trap->effect = atoi(row[4]);
|
||||||
trap->effectvalue = atoi(row[5]);
|
trap->effectvalue = atoi(row[5]);
|
||||||
trap->effectvalue2 = atoi(row[6]);
|
trap->effectvalue2 = atoi(row[6]);
|
||||||
@ -322,7 +310,7 @@ void Trap::CreateHiddenTrigger()
|
|||||||
make_npc->trackable = 0;
|
make_npc->trackable = 0;
|
||||||
make_npc->level = level;
|
make_npc->level = level;
|
||||||
strcpy(make_npc->special_abilities, "19,1^20,1^24,1^25,1");
|
strcpy(make_npc->special_abilities, "19,1^20,1^24,1^25,1");
|
||||||
NPC* npca = new NPC(make_npc, nullptr, xyz_heading(x, y, z, 0.0f), FlyMode3);
|
NPC* npca = new NPC(make_npc, nullptr, xyz_heading(m_Position, 0.0f), FlyMode3);
|
||||||
npca->GiveNPCTypeData(make_npc);
|
npca->GiveNPCTypeData(make_npc);
|
||||||
entity_list.AddNPC(npca);
|
entity_list.AddNPC(npca);
|
||||||
|
|
||||||
|
|||||||
@ -53,9 +53,7 @@ public:
|
|||||||
Timer respawn_timer; //Respawn Time when Trap's been disarmed
|
Timer respawn_timer; //Respawn Time when Trap's been disarmed
|
||||||
Timer chkarea_timer;
|
Timer chkarea_timer;
|
||||||
uint32 trap_id; //Database ID of trap
|
uint32 trap_id; //Database ID of trap
|
||||||
float x; //X position
|
xyz_location m_Position;
|
||||||
float y; //Y position
|
|
||||||
float z; //Z position
|
|
||||||
float maxzdiff; //maximum z diff to be triggerable
|
float maxzdiff; //maximum z diff to be triggerable
|
||||||
float radius; //radius around trap to be triggerable
|
float radius; //radius around trap to be triggerable
|
||||||
uint8 chance; //%chance that the trap is triggered each 'tick'
|
uint8 chance; //%chance that the trap is triggered each 'tick'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user