mirror of
https://github.com/OTCv8/otclientv8.git
synced 2025-10-21 23:15:54 +02:00
Version 2.5.3 - http://otclient.net/showthread.php?tid=275
This commit is contained in:
@@ -169,6 +169,8 @@ void Client::registerLuaFunctions()
|
||||
g_lua.bindSingletonFunction("g_map", "getMinimapColor", &Map::getMinimapColor, &g_map);
|
||||
g_lua.bindSingletonFunction("g_map", "isPatchable", &Map::isPatchable, &g_map);
|
||||
g_lua.bindSingletonFunction("g_map", "isWalkable", &Map::isWalkable, &g_map);
|
||||
g_lua.bindSingletonFunction("g_map", "checkSightLine", &Map::checkSightLine, &g_map);
|
||||
g_lua.bindSingletonFunction("g_map", "isSightClear", &Map::isSightClear, &g_map);
|
||||
|
||||
g_lua.registerSingletonClass("g_minimap");
|
||||
g_lua.bindSingletonFunction("g_minimap", "clean", &Minimap::clean, &g_minimap);
|
||||
@@ -523,6 +525,7 @@ void Client::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<Creature>("isDead", &Creature::isDead);
|
||||
g_lua.bindClassMemberFunction<Creature>("isRemoved", &Creature::isRemoved);
|
||||
g_lua.bindClassMemberFunction<Creature>("canBeSeen", &Creature::canBeSeen);
|
||||
g_lua.bindClassMemberFunction<Creature>("canShoot", &Creature::canShoot);
|
||||
g_lua.bindClassMemberFunction<Creature>("jump", &Creature::jump);
|
||||
g_lua.bindClassMemberFunction<Creature>("getPrewalkingPosition", &Creature::getPrewalkingPosition);
|
||||
g_lua.bindClassMemberFunction<Creature>("setInformationColor", &Creature::setInformationColor);
|
||||
@@ -772,6 +775,7 @@ void Client::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<Tile>("isFullGround", &Tile::isFullGround);
|
||||
g_lua.bindClassMemberFunction<Tile>("isFullyOpaque", &Tile::isFullyOpaque);
|
||||
g_lua.bindClassMemberFunction<Tile>("isLookPossible", &Tile::isLookPossible);
|
||||
g_lua.bindClassMemberFunction<Tile>("isBlockingProjectile", &Tile::isBlockingProjectile);
|
||||
g_lua.bindClassMemberFunction<Tile>("hasCreature", &Tile::hasCreature);
|
||||
g_lua.bindClassMemberFunction<Tile>("hasBlockingCreature", &Tile::hasBlockingCreature);
|
||||
g_lua.bindClassMemberFunction<Tile>("isEmpty", &Tile::isEmpty);
|
||||
@@ -789,6 +793,7 @@ void Client::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<Tile>("getElevation", &Tile::getElevation);
|
||||
g_lua.bindClassMemberFunction<Tile>("hasElevation", &Tile::hasElevation);
|
||||
g_lua.bindClassMemberFunction<Tile>("isBlocking", &Tile::isBlocking);
|
||||
g_lua.bindClassMemberFunction<Tile>("canShoot", &Tile::canShoot);
|
||||
// for bot
|
||||
g_lua.bindClassMemberFunction<Tile>("setText", &Tile::setText);
|
||||
g_lua.bindClassMemberFunction<Tile>("getText", &Tile::getText);
|
||||
|
@@ -967,3 +967,118 @@ bool Map::isWalkable(const Position& pos, bool ignoreCreatures)
|
||||
const MinimapTile& mtile = g_minimap.getTile(pos);
|
||||
return !mtile.hasFlag(MinimapTileNotPathable);
|
||||
}
|
||||
|
||||
std::vector<CreaturePtr> Map::getSpectatorsByPattern(const Position& centerPos, const std::string& pattern, Otc::Direction direction)
|
||||
{
|
||||
std::vector<bool> finalPattern(pattern.size(), false);
|
||||
std::vector<CreaturePtr> creatures;
|
||||
int width = 0, height = 0, lineLength = 0, p = 0;
|
||||
for (auto& c : pattern) {
|
||||
lineLength += 1;
|
||||
if (c == '0' || c == '-') {
|
||||
p += 1;
|
||||
} else if (c == '1' || c == '+') {
|
||||
finalPattern[p++] = true;
|
||||
} else if (c == 'N' || c == 'n') {
|
||||
finalPattern[p++] = direction == Otc::North;
|
||||
} else if (c == 'E' || c == 'e') {
|
||||
finalPattern[p++] = direction == Otc::East;
|
||||
} else if (c == 'W' || c == 'w') {
|
||||
finalPattern[p++] = direction == Otc::West;
|
||||
} else if (c == 'S' || c == 's') {
|
||||
finalPattern[p++] = direction == Otc::South;
|
||||
} else {
|
||||
lineLength -= 1;
|
||||
if (lineLength > 1) {
|
||||
if (width == 0)
|
||||
width = lineLength;
|
||||
if (width != lineLength) {
|
||||
g_logger.error(stdext::format("Invalid pattern for getSpectatorsByPattern: %s", pattern));
|
||||
return creatures;
|
||||
}
|
||||
height += 1;
|
||||
lineLength = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lineLength > 0) {
|
||||
if (width == 0)
|
||||
width = lineLength;
|
||||
if (width != lineLength) {
|
||||
g_logger.error(stdext::format("Invalid pattern for getSpectatorsByPattern: %s", pattern));
|
||||
return creatures;
|
||||
}
|
||||
height += 1;
|
||||
}
|
||||
if (width % 2 != 1 || height % 2 != 1) {
|
||||
g_logger.error(stdext::format("Invalid pattern for getSpectatorsByPattern, width and height should be odd (height: %i width: %i)", height, width));
|
||||
return creatures;
|
||||
}
|
||||
|
||||
p = 0;
|
||||
for (int y = centerPos.y - height / 2, endy = centerPos.y + height / 2; y <= endy; ++y) {
|
||||
for (int x = centerPos.x - width / 2, endx = centerPos.x + width / 2; x <= endx; ++x) {
|
||||
if (!finalPattern[p++])
|
||||
continue;
|
||||
TilePtr tile = getTile(Position(x, y, centerPos.z));
|
||||
if (!tile)
|
||||
continue;
|
||||
auto tileCreatures = tile->getCreatures();
|
||||
creatures.insert(creatures.end(), tileCreatures.rbegin(), tileCreatures.rend());
|
||||
}
|
||||
}
|
||||
return creatures;
|
||||
}
|
||||
|
||||
bool Map::isSightClear(const Position& fromPos, const Position& toPos)
|
||||
{
|
||||
if (fromPos == toPos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Position start(fromPos.z > toPos.z ? toPos : fromPos);
|
||||
Position destination(fromPos.z > toPos.z ? fromPos : toPos);
|
||||
|
||||
const int8_t mx = start.x < destination.x ? 1 : start.x == destination.x ? 0 : -1;
|
||||
const int8_t my = start.y < destination.y ? 1 : start.y == destination.y ? 0 : -1;
|
||||
|
||||
int32_t A = destination.y - start.y;
|
||||
int32_t B = start.x - destination.x;
|
||||
int32_t C = -(A * destination.x + B * destination.y);
|
||||
|
||||
while (start.x != destination.x || start.y != destination.y) {
|
||||
int32_t move_hor = std::abs(A * (start.x + mx) + B * (start.y) + C);
|
||||
int32_t move_ver = std::abs(A * (start.x) + B * (start.y + my) + C);
|
||||
int32_t move_cross = std::abs(A * (start.x + mx) + B * (start.y + my) + C);
|
||||
|
||||
if (start.y != destination.y && (start.x == destination.x || move_hor > move_ver || move_hor > move_cross)) {
|
||||
start.y += my;
|
||||
}
|
||||
|
||||
if (start.x != destination.x && (start.y == destination.y || move_ver > move_hor || move_ver > move_cross)) {
|
||||
start.x += mx;
|
||||
}
|
||||
|
||||
auto tile = getTile(Position(start.x, start.y, start.z));
|
||||
if (tile && tile->isBlockingProjectile()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
while (start.z != destination.z) {
|
||||
auto tile = getTile(Position(start.x, start.y, start.z));
|
||||
if (tile && tile->getThingCount() > 0) {
|
||||
return false;
|
||||
}
|
||||
start.z++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Map::checkSightLine(const Position& fromPos, const Position& toPos)
|
||||
{
|
||||
if (fromPos.z != toPos.z)
|
||||
return false;
|
||||
return checkSightLine(fromPos, toPos) || checkSightLine(toPos, fromPos);
|
||||
}
|
@@ -109,13 +109,15 @@ void Application::registerLuaFunctions()
|
||||
|
||||
// Platform
|
||||
g_lua.registerSingletonClass("g_platform");
|
||||
#ifdef UNSAFE_LUA_FUNCTIONS
|
||||
g_lua.bindSingletonFunction("g_platform", "spawnProcess", &Platform::spawnProcess, &g_platform);
|
||||
g_lua.bindSingletonFunction("g_platform", "getProcessId", &Platform::getProcessId, &g_platform);
|
||||
g_lua.bindSingletonFunction("g_platform", "isProcessRunning", &Platform::isProcessRunning, &g_platform);
|
||||
g_lua.bindSingletonFunction("g_platform", "copyFile", &Platform::copyFile, &g_platform);
|
||||
g_lua.bindSingletonFunction("g_platform", "fileExists", &Platform::fileExists, &g_platform);
|
||||
g_lua.bindSingletonFunction("g_platform", "removeFile", &Platform::removeFile, &g_platform);
|
||||
g_lua.bindSingletonFunction("g_platform", "killProcess", &Platform::killProcess, &g_platform);
|
||||
#endif
|
||||
g_lua.bindSingletonFunction("g_platform", "getProcessId", &Platform::getProcessId, &g_platform);
|
||||
g_lua.bindSingletonFunction("g_platform", "isProcessRunning", &Platform::isProcessRunning, &g_platform);
|
||||
g_lua.bindSingletonFunction("g_platform", "getTempPath", &Platform::getTempPath, &g_platform);
|
||||
g_lua.bindSingletonFunction("g_platform", "openUrl", &Platform::openUrl, &g_platform);
|
||||
g_lua.bindSingletonFunction("g_platform", "openDir", &Platform::openDir, &g_platform);
|
||||
@@ -226,6 +228,7 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindSingletonFunction("g_http", "wsSend", &Http::wsSend, &g_http);
|
||||
g_lua.bindSingletonFunction("g_http", "wsClose", &Http::wsClose, &g_http);
|
||||
g_lua.bindSingletonFunction("g_http", "cancel", &Http::cancel, &g_http);
|
||||
g_lua.bindSingletonFunction("g_http", "setUserAgent", &Http::setUserAgent, &g_http);
|
||||
|
||||
g_lua.registerSingletonClass("g_atlas");
|
||||
g_lua.bindSingletonFunction("g_atlas", "getStats", &Atlas::getStats, &g_atlas);
|
||||
@@ -273,6 +276,8 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindSingletonFunction("g_resources", "selfChecksum", &ResourceManager::selfChecksum, &g_resources);
|
||||
g_lua.bindSingletonFunction("g_resources", "updateData", &ResourceManager::updateData, &g_resources);
|
||||
g_lua.bindSingletonFunction("g_resources", "updateExecutable", &ResourceManager::updateExecutable, &g_resources);
|
||||
g_lua.bindSingletonFunction("g_resources", "createArchive", &ResourceManager::createArchive, &g_resources);
|
||||
g_lua.bindSingletonFunction("g_resources", "decompressArchive", &ResourceManager::decompressArchive, &g_resources);
|
||||
g_lua.bindSingletonFunction("g_resources", "setLayout", &ResourceManager::setLayout, &g_resources);
|
||||
g_lua.bindSingletonFunction("g_resources", "getLayout", &ResourceManager::getLayout, &g_resources);
|
||||
|
||||
|
Reference in New Issue
Block a user