From 2df51622ba8e2b42940f0b6c514a3ce6882e3da7 Mon Sep 17 00:00:00 2001 From: BenDol Date: Mon, 2 Jun 2014 10:04:56 +1200 Subject: [PATCH] Some improvements to some things. --- modules/corelib/util.lua | 4 ---- modules/gamelib/const.lua | 27 +++++++++++++++++++-------- modules/gamelib/gamelib.otmod | 1 + modules/gamelib/position.lua | 5 +++++ src/client/creature.h | 1 + src/client/game.cpp | 8 +++++--- src/client/luafunctions.cpp | 3 +++ 7 files changed, 34 insertions(+), 15 deletions(-) diff --git a/modules/corelib/util.lua b/modules/corelib/util.lua index 9e8d110f..e72d226a 100644 --- a/modules/corelib/util.lua +++ b/modules/corelib/util.lua @@ -284,10 +284,6 @@ function numbertoboolean(number) end end -function postostring(pos) - return pos.x .. " " .. pos.y .. " " .. pos.z -end - function signalcall(param, ...) if type(param) == 'function' then local status, ret = pcall(param, ...) diff --git a/modules/gamelib/const.lua b/modules/gamelib/const.lua index 3d2e53f6..3588cac0 100644 --- a/modules/gamelib/const.lua +++ b/modules/gamelib/const.lua @@ -34,14 +34,25 @@ EmblemOther = 5 VipIconFirst = 0 VipIconLast = 10 -North = 0 -East = 1 -South = 2 -West = 3 -NorthEast = 4 -SouthEast = 5 -SouthWest = 6 -NorthWest = 7 +Directions = { + North = 0, + East = 1, + South = 2, + West = 3, + NorthEast = 4, + SouthEast = 5, + SouthWest = 6, + NorthWest = 7 +} + +North = Directions.North +East = Directions.East +South = Directions.South +West = Directions.West +NorthEast = Directions.NorthEast +SouthEast = Directions.SouthEast +SouthWest = Directions.SouthWest +NorthWest = Directions.NorthWest FightOffensive = 1 FightBalanced = 2 diff --git a/modules/gamelib/gamelib.otmod b/modules/gamelib/gamelib.otmod index ae1c3dd2..07c4dc3a 100644 --- a/modules/gamelib/gamelib.otmod +++ b/modules/gamelib/gamelib.otmod @@ -9,6 +9,7 @@ Module @onLoad: | dofile 'const' + dofile 'util' dofile 'protocol' dofile 'protocollogin' dofile 'protocolgame' diff --git a/modules/gamelib/position.lua b/modules/gamelib/position.lua index e0b7d8a5..dcc6a2a8 100644 --- a/modules/gamelib/position.lua +++ b/modules/gamelib/position.lua @@ -18,4 +18,9 @@ function Position.lessThan(pos1, pos2, orEqualTo) else return pos1.x < pos2.x or pos1.y < pos2.y or pos1.z < pos2.z end +end + +function Position.isInRange(pos1, pos2, minXRange, maxXRange, minYRange, maxYRange) + return (pos2.x >= pos1.x-minXRange and pos2.x <= pos1.x+maxXRange and pos2.y + >= pos1.y-minYRange and pos2.y <= pos1.y+maxYRange and pos2.z == pos1.z); end \ No newline at end of file diff --git a/src/client/creature.h b/src/client/creature.h index e3ecc796..72d35651 100644 --- a/src/client/creature.h +++ b/src/client/creature.h @@ -116,6 +116,7 @@ public: bool isWalking() { return m_walking; } bool isRemoved() { return m_removed; } bool isInvisible() { return m_outfit.getCategory() == ThingCategoryEffect && m_outfit.getAuxId() == 13; } + bool isDead() { return m_healthPercent <= 0; } bool canBeSeen() { return !isInvisible() || isPlayer(); } bool isCreature() { return true; } diff --git a/src/client/game.cpp b/src/client/game.cpp index 115097da..17a813d7 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1597,10 +1597,12 @@ void Game::setClientVersion(int version) void Game::setAttackingCreature(const CreaturePtr& creature) { - CreaturePtr oldCreature = m_attackingCreature; - m_attackingCreature = creature; + if(creature != m_attackingCreature) { + CreaturePtr oldCreature = m_attackingCreature; + m_attackingCreature = creature; - g_lua.callGlobalField("g_game", "onAttackingCreatureChange", creature, oldCreature); + g_lua.callGlobalField("g_game", "onAttackingCreatureChange", creature, oldCreature); + } } void Game::setFollowingCreature(const CreaturePtr& creature) diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index 63209a12..012ad72d 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -376,6 +376,7 @@ void Client::registerLuaFunctions() g_lua.bindClassMemberFunction("isTranslucent", &Thing::isTranslucent); g_lua.bindClassMemberFunction("isFullGround", &Thing::isFullGround); g_lua.bindClassMemberFunction("isMarketable", &Thing::isMarketable); + g_lua.bindClassMemberFunction("isLyingCorpse", &Thing::isLyingCorpse); g_lua.bindClassMemberFunction("getParentContainer", &Thing::getParentContainer); g_lua.bindClassMemberFunction("getMarketData", &Thing::getMarketData); @@ -457,6 +458,8 @@ void Client::registerLuaFunctions() g_lua.bindClassMemberFunction("hideStaticSquare", &Creature::hideStaticSquare); g_lua.bindClassMemberFunction("isWalking", &Creature::isWalking); g_lua.bindClassMemberFunction("isInvisible", &Creature::isInvisible); + g_lua.bindClassMemberFunction("isDead", &Creature::isDead); + g_lua.bindClassMemberFunction("isRemoved", &Creature::isRemoved); g_lua.bindClassMemberFunction("canBeSeen", &Creature::canBeSeen); g_lua.bindClassMemberFunction("jump", &Creature::jump);