mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 04:24:54 +02:00
Reimplement battle using new events, no more scheduleEvents
This commit is contained in:
@@ -286,6 +286,11 @@ void Creature::stopWalk()
|
||||
terminateWalk();
|
||||
}
|
||||
|
||||
void Creature::onPositionChange(const Position& newPos, const Position& oldPos)
|
||||
{
|
||||
callLuaField("onPositionChange", newPos, oldPos);
|
||||
}
|
||||
|
||||
void Creature::onAppear()
|
||||
{
|
||||
// cancel any disappear event
|
||||
@@ -328,7 +333,8 @@ void Creature::onDisappear()
|
||||
self->callLuaField("onDisappear");
|
||||
|
||||
// invalidate this creature position
|
||||
self->m_position = Position();
|
||||
if(!self->isLocalPlayer())
|
||||
self->setPosition(Position());
|
||||
self->m_oldPosition = Position();
|
||||
self->m_disappearEvent = nullptr;
|
||||
});
|
||||
|
@@ -100,6 +100,7 @@ public:
|
||||
const ThingTypePtr& getThingType();
|
||||
ThingType *rawGetThingType();
|
||||
|
||||
virtual void onPositionChange(const Position& newPos, const Position& oldPos);
|
||||
virtual void onAppear();
|
||||
virtual void onDisappear();
|
||||
|
||||
|
@@ -383,3 +383,8 @@ double LocalPlayer::getWalkPing()
|
||||
sum += p;
|
||||
return sum / (double)m_lastWalkPings.size();
|
||||
}
|
||||
|
||||
bool LocalPlayer::hasSight(const Position& pos)
|
||||
{
|
||||
return m_position.isInRange(pos, (Otc::VISIBLE_X_TILES - 1)/2, (Otc::VISIBLE_Y_TILES - 1)/2);
|
||||
}
|
||||
|
@@ -73,6 +73,7 @@ public:
|
||||
double getStamina() { return m_stamina; }
|
||||
ItemPtr getInventoryItem(Otc::InventorySlot inventory) { return m_inventoryItems[inventory]; }
|
||||
|
||||
bool hasSight(const Position& pos);
|
||||
bool isKnown() { return m_known; }
|
||||
bool isPreWalking() { return m_preWalking; }
|
||||
bool isAutoWalking() { return m_autoWalking; }
|
||||
|
@@ -393,6 +393,7 @@ void OTClient::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<LocalPlayer>("isPremium", &LocalPlayer::isPremium);
|
||||
g_lua.bindClassMemberFunction<LocalPlayer>("isKnown", &LocalPlayer::isKnown);
|
||||
g_lua.bindClassMemberFunction<LocalPlayer>("isPreWalking", &LocalPlayer::isPreWalking);
|
||||
g_lua.bindClassMemberFunction<LocalPlayer>("hasSight", &LocalPlayer::hasSight);
|
||||
|
||||
g_lua.registerClass<Tile>();
|
||||
g_lua.bindClassMemberFunction<Tile>("clean", &Tile::clean);
|
||||
|
@@ -301,7 +301,8 @@ void Map::setCentralPosition(const Position& centralPosition)
|
||||
Position oldPos = localPlayer->getPosition();
|
||||
Position pos = m_centralPosition;
|
||||
if(oldPos != pos) {
|
||||
localPlayer->onDisappear();
|
||||
if(!localPlayer->isRemoved())
|
||||
localPlayer->onDisappear();
|
||||
localPlayer->setPosition(pos);
|
||||
localPlayer->onAppear();
|
||||
}
|
||||
|
@@ -216,6 +216,7 @@ public:
|
||||
private:
|
||||
stdext::boolean<false> m_enableSendExtendedOpcode;
|
||||
stdext::boolean<false> m_gameInitialized;
|
||||
stdext::boolean<false> m_mapKnown;
|
||||
stdext::boolean<true> m_firstRecv;
|
||||
std::string m_accountName;
|
||||
std::string m_accountPassword;
|
||||
|
@@ -399,8 +399,19 @@ void ProtocolGame::parseDeath(const InputMessagePtr& msg)
|
||||
void ProtocolGame::parseMapDescription(const InputMessagePtr& msg)
|
||||
{
|
||||
Position pos = getPosition(msg);
|
||||
|
||||
if(!m_mapKnown)
|
||||
m_localPlayer->setPosition(pos);
|
||||
|
||||
g_map.setCentralPosition(pos);
|
||||
setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES);
|
||||
|
||||
if(!m_mapKnown) {
|
||||
g_dispatcher.addEvent([] { g_lua.callGlobalField("g_game", "onMapKnown"); });
|
||||
m_mapKnown = true;
|
||||
}
|
||||
|
||||
g_dispatcher.addEvent([] { g_lua.callGlobalField("g_game", "onMapDescription"); });
|
||||
}
|
||||
|
||||
void ProtocolGame::parseMapMoveNorth(const InputMessagePtr& msg)
|
||||
|
Reference in New Issue
Block a user