2015-09-25 21:07:16 +08:00
|
|
|
/*
|
2024-01-03 01:21:08 +01:00
|
|
|
* Copyright (c) 2010-2015, Argon Sun (Fluorohydride)
|
2025-05-09 22:15:14 +02:00
|
|
|
* Copyright (c) 2018-2025, Edoardo Lolletti (edo9300) <edoardo762@gmail.com>
|
2015-09-25 21:07:16 +08:00
|
|
|
*
|
2024-01-03 01:21:08 +01:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2015-09-25 21:07:16 +08:00
|
|
|
*/
|
|
|
|
|
#include "duel.h"
|
2021-04-19 12:04:28 +02:00
|
|
|
#include "field.h"
|
2024-01-05 12:17:47 +01:00
|
|
|
#include "lua_obj.h"
|
|
|
|
|
#include "scriptlib.h"
|
2015-09-25 21:07:16 +08:00
|
|
|
|
2021-10-13 17:29:29 +02:00
|
|
|
namespace scriptlib {
|
|
|
|
|
|
2024-03-01 17:53:08 +01:00
|
|
|
const char* get_lua_type_name(lua_State* L, int32_t index) {
|
2024-03-02 19:58:42 +01:00
|
|
|
switch(auto type = lua_type(L, index); type) {
|
|
|
|
|
case LUA_TFUNCTION:
|
2024-03-01 17:53:08 +01:00
|
|
|
return "Function";
|
2024-03-02 19:58:42 +01:00
|
|
|
case LUA_TSTRING:
|
2024-03-01 17:53:08 +01:00
|
|
|
return "String";
|
2024-03-02 19:58:42 +01:00
|
|
|
case LUA_TNUMBER:
|
2024-03-01 17:53:08 +01:00
|
|
|
return "Int";
|
2024-03-02 19:58:42 +01:00
|
|
|
case LUA_TBOOLEAN:
|
2024-03-01 17:53:08 +01:00
|
|
|
return "boolean";
|
2024-03-02 19:58:42 +01:00
|
|
|
case LUA_TTABLE:
|
|
|
|
|
return "table";
|
|
|
|
|
case LUA_TNIL:
|
|
|
|
|
case LUA_TNONE:
|
2024-03-01 17:53:08 +01:00
|
|
|
return "nil";
|
2024-03-02 19:58:42 +01:00
|
|
|
case LUA_TUSERDATA:
|
|
|
|
|
if(auto* obj = lua_get<lua_obj*>(L, index); obj != nullptr) {
|
|
|
|
|
switch(obj->lua_type) {
|
|
|
|
|
case LuaParam::CARD:
|
|
|
|
|
return "Card";
|
|
|
|
|
case LuaParam::GROUP:
|
|
|
|
|
return "Group";
|
|
|
|
|
case LuaParam::EFFECT:
|
|
|
|
|
return "Effect";
|
|
|
|
|
case LuaParam::DELETED:
|
|
|
|
|
return "Deleted";
|
|
|
|
|
default:
|
|
|
|
|
unreachable();
|
|
|
|
|
}
|
2020-07-21 15:03:03 +02:00
|
|
|
}
|
2024-03-02 19:58:42 +01:00
|
|
|
[[fallthrough]];
|
|
|
|
|
default:
|
|
|
|
|
return "unknown";
|
2020-03-14 18:40:09 +01:00
|
|
|
}
|
2015-09-25 21:07:16 +08:00
|
|
|
}
|
2024-03-01 17:53:08 +01:00
|
|
|
|
2021-10-13 17:29:29 +02:00
|
|
|
void check_action_permission(lua_State* L) {
|
2022-06-23 11:47:00 +02:00
|
|
|
if(lua_get<duel*>(L)->lua->no_action)
|
|
|
|
|
lua_error(L, "Action is not allowed here.");
|
2021-04-19 12:04:28 +02:00
|
|
|
}
|
2021-10-13 17:29:29 +02:00
|
|
|
int32_t push_return_cards(lua_State* L, int32_t/* status*/, lua_KContext ctx) {
|
2021-04-19 12:04:28 +02:00
|
|
|
const auto pduel = lua_get<duel*>(L);
|
|
|
|
|
bool cancelable = (bool)ctx;
|
|
|
|
|
if(pduel->game_field->return_cards.canceled) {
|
|
|
|
|
if(cancelable) {
|
|
|
|
|
lua_pushnil(L);
|
|
|
|
|
} else {
|
2025-05-03 12:54:01 +02:00
|
|
|
auto pgroup = pduel->new_group();
|
2021-04-19 12:04:28 +02:00
|
|
|
interpreter::pushobject(L, pgroup);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-05-03 12:54:01 +02:00
|
|
|
auto pgroup = pduel->new_group(pduel->game_field->return_cards.list);
|
2021-04-19 12:04:28 +02:00
|
|
|
interpreter::pushobject(L, pgroup);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
2021-10-13 17:29:29 +02:00
|
|
|
}
|
2021-10-13 18:18:02 +02:00
|
|
|
int32_t is_deleted_object(lua_State* L) {
|
|
|
|
|
if(auto obj = lua_touserdata(L, 1)) {
|
2022-11-02 13:01:42 +01:00
|
|
|
auto* ret = *static_cast<lua_obj**>(obj);
|
2023-12-08 19:53:35 +01:00
|
|
|
lua_pushboolean(L, ret->lua_type == LuaParam::DELETED);
|
2021-10-13 18:18:02 +02:00
|
|
|
} else {
|
|
|
|
|
lua_pushboolean(L, false);
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2023-11-25 11:15:21 +01:00
|
|
|
}
|