/
Mr.Stalin
/
FOnline-Engine
Обзор
Документация
Войти
/
Mr.Stalin
/
FOnline-Engine
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Source/Scripting/ClientItemScriptMethods.cpp
237 строк
6 KB
cvet
Ref count leak fix
11 авг 2026, 22:54
11 авг 2026, 22:54
1e93cc3
Код
Авторство
О чём код?
// __________ ___ ______ _ // / ____/ __ \____ / (_)___ ___ / ____/___ ____ _(_)___ ___ // / /_ / / / / __ \/ / / __ \/ _ \ / __/ / __ \/ __ `/ / __ \/ _ ` // / __/ / /_/ / / / / / / / / / __/ / /___/ / / / /_/ / / / / / __/ // /_/ \____/_/ /_/_/_/_/ /_/\___/ /_____/_/ /_/\__, /_/_/ /_/\___/ // /____/ // FOnline Engine // https://fonline.ru // https://github.com/cvet/fonline // // MIT License // // Copyright (c) 2006 - 2026, Anton Tsvetinskiy aka cvet <cvet@tut.by> // // 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 "Common.h" #include "Client.h" #include "Geometry.h" #include "ScriptSystem.h" FO_BEGIN_NAMESPACE ///@ ExportMethod FO_SCRIPT_API bool Client_Item_IsVisible(ptr<ItemView> self) { auto hex_item = self.dyn_cast<ItemHexView>(); if (!hex_item) { throw ScriptException("Item is not on map"); } return hex_item->IsMapSpriteVisible(); } ///@ ExportMethod FO_SCRIPT_API ipos32 Client_Item_GetSpriteOffset(ptr<ItemView> self) { auto hex_item = self.dyn_cast<ItemHexView>(); if (!hex_item) { throw ScriptException("Item is not on map"); } return hex_item->GetSpriteOffset(); } ///@ ExportMethod PassOwnership FO_SCRIPT_API ptr<ItemView> Client_Item_Clone(ptr<ItemView> self) { auto cloned_item = self->CreateRefClone(); cloned_item->AddRef(); return cloned_item; } ///@ ExportMethod PassOwnership FO_SCRIPT_API ptr<ItemView> Client_Item_Clone(ptr<ItemView> self, int32_t count) { auto cloned_item = self->CreateRefClone(); cloned_item->SetCount(count); cloned_item->AddRef(); return cloned_item; } static void ItemGetMapPos(ptr<ItemView> item, mpos& hex) { FO_STACK_TRACE_ENTRY(); auto map = item->GetEngine()->GetCurMap(); if (!map) { throw ScriptException("Map is not loaded"); } switch (item->GetOwnership()) { case ItemOwnership::CritterInventory: { auto cr = map->GetCritter(item->GetCritterId()); if (!cr) { throw ScriptException("Invalid critter ownership, critter not found"); } hex = cr->GetHex(); } break; case ItemOwnership::MapHex: { hex = item->GetHex(); } break; case ItemOwnership::ItemContainer: { if (item->GetId() == item->GetContainerId()) { throw ScriptException("Invalid container ownership, crosslinks"); } auto cont = map->GetItem(item->GetContainerId()); if (!cont) { throw ScriptException("Invalid container ownership, container not found"); } // Look recursively ItemGetMapPos(cont, hex); } break; default: throw ScriptException("Invalid item ownership"); } } ///@ ExportMethod FO_SCRIPT_API void Client_Item_GetMapPos(ptr<ItemView> self, mpos& hex) { if (!self->GetEngine()->GetCurMap()) { throw ScriptException("Map is not loaded"); } ItemGetMapPos(self, hex); } ///@ ExportMethod FO_SCRIPT_API bool Client_Item_IsAnimPlaying(ptr<ItemView> self) { if (auto hex_item = self.dyn_cast<const ItemHexView>()) { return hex_item->GetAnim()->IsPlaying(); } return false; } ///@ ExportMethod FO_SCRIPT_API void Client_Item_PlayAnim(ptr<ItemView> self, hstring animName, bool looped, bool reversed) { if (auto hex_item = self.dyn_cast<ItemHexView>()) { hex_item->PlayAnim(animName, looped, reversed); } } ///@ ExportMethod FO_SCRIPT_API void Client_Item_StopAnim(ptr<ItemView> self) { if (auto hex_item = self.dyn_cast<ItemHexView>()) { hex_item->StopAnim(); } } ///@ ExportMethod FO_SCRIPT_API void Client_Item_SetAnimTime(ptr<ItemView> self, float32_t normalizedTime) { if (auto hex_item = self.dyn_cast<ItemHexView>()) { hex_item->SetAnimTime(normalizedTime); } } ///@ ExportMethod FO_SCRIPT_API void Client_Item_SetAnimDir(ptr<ItemView> self, mdir dir) { if (auto hex_item = self.dyn_cast<ItemHexView>()) { hex_item->SetAnimDir(dir); } } ///@ ExportMethod FO_SCRIPT_API bool Client_Item_IsMoving(ptr<ItemView> self) { if (auto hex_item = self.dyn_cast<const ItemHexView>()) { return hex_item->IsMoving(); } return false; } ///@ ExportMethod FO_SCRIPT_API void Client_Item_MoveToHex(ptr<ItemView> self, mpos hex, float32_t speed) { if (auto hex_item = self.dyn_cast<ItemHexView>()) { hex_item->MoveToHex(hex, speed); } } ///@ ExportMethod FO_SCRIPT_API vector<ptr<ItemView>> Client_Item_GetInnerItems(ptr<ItemView> self) { span<refcount_ptr<ItemView>> inner_items = self->GetInnerItems(); vector<ptr<ItemView>> items; items.reserve(inner_items.size()); for (size_t i = 0; i < inner_items.size(); i++) { items.emplace_back(inner_items[i]); } return items; } ///@ ExportMethod FO_SCRIPT_API uint8_t Client_Item_GetAlpha(ptr<ItemView> self) { auto hex_item = self.dyn_cast<ItemHexView>(); if (!hex_item) { return 0xFF; } return hex_item->GetCurAlpha(); } ///@ ExportMethod FO_SCRIPT_API void Client_Item_SetAlpha(ptr<ItemView> self, uint8_t alpha) { if (auto hex_item = self.dyn_cast<ItemHexView>()) { hex_item->SetTargetAlpha(alpha); } } ///@ ExportMethod FO_SCRIPT_API void Client_Item_Finish(ptr<ItemView> self) { if (auto hex_item = self.dyn_cast<ItemHexView>()) { if (!hex_item->IsFinishing()) { hex_item->Finish(); } } } FO_END_NAMESPACE