-
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
282 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
function Tile:isTile() | ||
return true | ||
end | ||
|
||
function Tile:isCreature() | ||
return false | ||
end | ||
|
||
function Tile:isLocalPlayer() | ||
return false | ||
end | ||
|
||
function Tile:isNpc() | ||
return false | ||
end | ||
|
||
function Tile:isMonster() | ||
return false | ||
end | ||
|
||
function Tile:isPlayer() | ||
return false | ||
end | ||
|
||
function Tile:isEffect() | ||
return false | ||
end | ||
|
||
function Tile:isMissile() | ||
return false | ||
end | ||
|
||
function Tile:isItem() | ||
return false | ||
end | ||
|
||
function Tile:isContainer() | ||
return false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2010-2022 OTClient <https://github.com/edubart/otclient> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
#include "attachableobject.h" | ||
|
||
#include <framework/core/eventdispatcher.h> | ||
|
||
void AttachableObject::attachEffect(const AttachedEffectPtr& obj) { | ||
if (!obj) | ||
return; | ||
|
||
onStartAttachEffect(obj); | ||
|
||
if (obj->isHidedOwner()) | ||
++m_ownerHidden; | ||
|
||
if (obj->getDuration() > 0) { | ||
g_dispatcher.scheduleEvent([self = std::static_pointer_cast<AttachableObject>(shared_from_this()), effectId = obj->getId()]() { | ||
self->detachEffectById(effectId); | ||
}, obj->getDuration()); | ||
} | ||
|
||
m_attachedEffects.emplace_back(obj); | ||
g_dispatcher.addEvent([effect = obj, self = std::static_pointer_cast<AttachableObject>(shared_from_this())] { | ||
self->onDispatcherAttachEffect(effect); | ||
effect->callLuaField("onAttach", self->attachedObjectToLuaObject()); | ||
}); | ||
} | ||
|
||
bool AttachableObject::detachEffectById(uint16_t id) { | ||
const auto it = std::find_if(m_attachedEffects.begin(), m_attachedEffects.end(), | ||
[id](const AttachedEffectPtr& obj) { return obj->getId() == id; }); | ||
|
||
if (it == m_attachedEffects.end()) | ||
return false; | ||
|
||
onDetachEffect(*it); | ||
m_attachedEffects.erase(it); | ||
|
||
return true; | ||
} | ||
|
||
void AttachableObject::onDetachEffect(const AttachedEffectPtr& effect) { | ||
if (effect->isHidedOwner()) | ||
--m_ownerHidden; | ||
|
||
onStartDetachEffect(effect); | ||
|
||
effect->callLuaField("onDetach", attachedObjectToLuaObject()); | ||
} | ||
|
||
void AttachableObject::clearAttachedEffects() { | ||
for (const auto& e : m_attachedEffects) | ||
onDetachEffect(e); | ||
m_attachedEffects.clear(); | ||
} | ||
|
||
AttachedEffectPtr AttachableObject::getAttachedEffectById(uint16_t id) { | ||
const auto it = std::find_if(m_attachedEffects.begin(), m_attachedEffects.end(), | ||
[id](const AttachedEffectPtr& obj) { return obj->getId() == id; }); | ||
|
||
if (it == m_attachedEffects.end()) | ||
return nullptr; | ||
|
||
return *it; | ||
} | ||
|
||
void AttachableObject::drawAttachedEffect(const Point& dest, LightView* lightView, bool isOnTop) | ||
{ | ||
for (const auto& effect : m_attachedEffects) { | ||
effect->draw(dest, isOnTop, lightView); | ||
if (effect->getLoop() == 0) { | ||
g_dispatcher.addEvent([self = std::static_pointer_cast<AttachableObject>(shared_from_this()), effectId = effect->getId()]() { | ||
self->detachEffectById(effectId); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2010-2022 OTClient <https://github.com/edubart/otclient> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
#pragma once | ||
#include "attachedeffect.h" | ||
#include <framework/luaengine/luaobject.h> | ||
|
||
class AttachableObject : public LuaObject | ||
{ | ||
public: | ||
AttachableObject() = default; | ||
virtual ~AttachableObject() = default; | ||
|
||
void attachEffect(const AttachedEffectPtr& obj); | ||
void clearAttachedEffects(); | ||
bool detachEffectById(uint16_t id); | ||
AttachedEffectPtr getAttachedEffectById(uint16_t id); | ||
|
||
virtual LuaObjectPtr attachedObjectToLuaObject() = 0; | ||
virtual void onStartAttachEffect(const AttachedEffectPtr& effect) { }; | ||
virtual void onDispatcherAttachEffect(const AttachedEffectPtr& effect) { }; | ||
virtual void onStartDetachEffect(const AttachedEffectPtr& effect) { }; | ||
|
||
bool isOwnerHidden() { return m_ownerHidden > 0; } | ||
|
||
const std::vector<AttachedEffectPtr>& getAttachedEffects() { return m_attachedEffects; }; | ||
|
||
protected: | ||
void drawAttachedEffect(const Point& dest, LightView* lightView, bool isOnTop); | ||
void onDetachEffect(const AttachedEffectPtr& effect); | ||
|
||
std::vector<AttachedEffectPtr> m_attachedEffects; | ||
uint8_t m_ownerHidden{ 0 }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.