Commit 1c985626 authored by nanahira's avatar nanahira

Merge branch 'master' of https://github.com/Fluorohydride/ygopro-core into mc

parents c22921e4 cf32e53e
......@@ -64,7 +64,6 @@ void card_data::clear() {
std::memset(this, 0, sizeof(card_data));
}
card::card(duel* pd) {
scrtype = 1;
ref_handle = 0;
pduel = pd;
owner = PLAYER_NONE;
......
......@@ -124,7 +124,6 @@ public:
uint8 location;
uint8 sequence;
};
int32 scrtype;
int32 ref_handle;
duel* pduel;
card_data data;
......
......@@ -15,7 +15,6 @@ bool effect_sort_id(const effect* e1, const effect* e2) {
return e1->id < e2->id;
};
effect::effect(duel* pd) {
scrtype = 3;
ref_handle = 0;
pduel = pd;
owner = 0;
......@@ -673,6 +672,9 @@ int32 effect::check_value_condition(uint32 extraargs) {
return (int32)value;
}
}
void* effect::get_label_object() {
return pduel->lua->get_ref_object(label_object);
}
int32 effect::get_speed() {
if(!(type & EFFECT_TYPE_ACTIONS))
return 0;
......
......@@ -27,7 +27,6 @@ enum effect_flag2 : uint32;
class effect {
public:
int32 scrtype;
int32 ref_handle;
duel* pduel;
card* owner;
......@@ -56,7 +55,7 @@ public:
card* active_handler;
uint16 status;
uint32 label;
void* label_object;
int32 label_object;
int32 condition;
int32 cost;
int32 target;
......@@ -91,6 +90,7 @@ public:
void get_value(card* pcard, uint32 extraargs, std::vector<int32>* result);
void get_value(effect* peffect, uint32 extraargs, std::vector<int32>* result);
int32 check_value_condition(uint32 extraargs = 0);
void* get_label_object();
int32 get_speed();
effect* clone();
card* get_owner() const;
......
......@@ -2028,7 +2028,7 @@ int32 field::adjust_grant_effect() {
}
for(auto cit = add_set.begin(); cit != add_set.end(); ++cit) {
card* pcard = *cit;
effect* geffect = (effect*)peffect->label_object;
effect* geffect = (effect*)peffect->get_label_object();
effect* ceffect = geffect->clone();
ceffect->owner = pcard;
pcard->add_effect(ceffect);
......
......@@ -10,20 +10,17 @@
#include "duel.h"
group::group(duel* pd) {
scrtype = 2;
ref_handle = 0;
pduel = pd;
is_readonly = FALSE;
}
group::group(duel* pd, card* pcard) {
container.insert(pcard);
scrtype = 2;
ref_handle = 0;
pduel = pd;
is_readonly = FALSE;
}
group::group(duel* pd, const card_set& cset): container(cset) {
scrtype = 2;
ref_handle = 0;
pduel = pd;
is_readonly = FALSE;
......
......@@ -18,7 +18,6 @@ class duel;
class group {
public:
typedef std::set<card*, card_sort> card_set;
int32 scrtype;
int32 ref_handle;
duel* pduel;
card_set container;
......
......@@ -1176,6 +1176,14 @@ int32 interpreter::clone_function_ref(int32 func_ref) {
int32 ref = luaL_ref(current_state, LUA_REGISTRYINDEX);
return ref;
}
void* interpreter::get_ref_object(int32 ref_handler) {
if(ref_handler == 0)
return nullptr;
lua_rawgeti(current_state, LUA_REGISTRYINDEX, ref_handler);
void* p = *(void**)lua_touserdata(current_state, -1);
lua_pop(current_state, 1);
return p;
}
//Convert a pointer to a lua value, +1 -0
void interpreter::card2value(lua_State* L, card* pcard) {
if (!pcard || pcard->ref_handle == 0)
......
......@@ -69,6 +69,7 @@ public:
int32 get_function_value(int32 f, uint32 param_count, std::vector<int32>* result);
int32 call_coroutine(int32 f, uint32 param_count, uint32* yield_value, uint16 step);
int32 clone_function_ref(int32 func_ref);
void* get_ref_object(int32 ref_handler);
static void card2value(lua_State* L, card* pcard);
static void group2value(lua_State* L, group* pgroup);
......
......@@ -10,6 +10,7 @@
#include "field.h"
#include "card.h"
#include "effect.h"
#include "group.h"
int32 scriptlib::effect_new(lua_State *L) {
check_param_count(L, 1);
......@@ -186,10 +187,17 @@ int32 scriptlib::effect_set_label_object(lua_State *L) {
peffect->label_object = 0;
return 0;
}
if(!lua_isuserdata(L, 2))
if(check_param(L, PARAM_TYPE_CARD, 2, TRUE)) {
card* p = *(card**)lua_touserdata(L, 2);
peffect->label_object = p->ref_handle;
} else if(check_param(L, PARAM_TYPE_EFFECT, 2, TRUE)) {
effect* p = *(effect**)lua_touserdata(L, 2);
peffect->label_object = p->ref_handle;
} else if(check_param(L, PARAM_TYPE_GROUP, 2, TRUE)) {
group* p = *(group**)lua_touserdata(L, 2);
peffect->label_object = p->ref_handle;
} else
luaL_error(L, "Parameter 2 should be \"Card\" or \"Effect\" or \"Group\".");
void* p = *(void**)lua_touserdata(L, 2);
peffect->label_object = p;
return 0;
}
int32 scriptlib::effect_set_category(lua_State *L) {
......@@ -342,15 +350,14 @@ int32 scriptlib::effect_get_label_object(lua_State *L) {
lua_pushnil(L);
return 1;
}
int32 type = *(int32*)peffect->label_object;
if(type == 1)
interpreter::card2value(L, (card*)peffect->label_object);
else if(type == 2)
interpreter::group2value(L, (group*)peffect->label_object);
else if(type == 3)
interpreter::effect2value(L, (effect*)peffect->label_object);
else lua_pushnil(L);
return 1;
lua_rawgeti(L, LUA_REGISTRYINDEX, peffect->label_object);
if(lua_isuserdata(L, -1))
return 1;
else {
lua_pop(L, 1);
lua_pushnil(L);
return 1;
}
}
int32 scriptlib::effect_get_category(lua_State *L) {
check_param_count(L, 1);
......
......@@ -7,54 +7,64 @@
#include "scriptlib.h"
#include "duel.h"
int32 scriptlib::check_data_type(lua_State* L, int32 index, const char* tname) {
int32 result = FALSE;
if(lua_getmetatable(L, index)) {
lua_getglobal(L, tname);
if(lua_rawequal(L, -1, -2))
result = TRUE;
lua_pop(L, 2);
}
return result;
}
int32 scriptlib::check_param(lua_State* L, int32 param_type, int32 index, int32 retfalse) {
int32 result;
switch (param_type) {
case PARAM_TYPE_CARD:
if (lua_isuserdata(L, index)) {
result = **(int32**)lua_touserdata(L, index);
if(result == 1)
return TRUE;
case PARAM_TYPE_CARD: {
int32 result = FALSE;
if(lua_isuserdata(L, index) && lua_getmetatable(L, index)) {
result = check_data_type(L, -1, "Card");
lua_pop(L, 1);
}
if(result)
return TRUE;
if(retfalse)
return FALSE;
luaL_error(L, "Parameter %d should be \"Card\".", index);
break;
case PARAM_TYPE_GROUP:
if (lua_isuserdata(L, index)) {
result = **(int32**)lua_touserdata(L, index);
if(result == 2)
return TRUE;
}
}
case PARAM_TYPE_GROUP: {
if(lua_isuserdata(L, index) && check_data_type(L, index, "Group"))
return TRUE;
if(retfalse)
return FALSE;
luaL_error(L, "Parameter %d should be \"Group\".", index);
break;
case PARAM_TYPE_EFFECT:
if (lua_isuserdata(L, index)) {
result = **(int32**)lua_touserdata(L, index);
if(result == 3)
return TRUE;
}
}
case PARAM_TYPE_EFFECT: {
if(lua_isuserdata(L, index) && check_data_type(L, index, "Effect"))
return TRUE;
if(retfalse)
return FALSE;
luaL_error(L, "Parameter %d should be \"Effect\".", index);
break;
case PARAM_TYPE_FUNCTION:
if (lua_isfunction(L, index))
}
case PARAM_TYPE_FUNCTION: {
if(lua_isfunction(L, index))
return TRUE;
if(retfalse)
return FALSE;
luaL_error(L, "Parameter %d should be \"Function\".", index);
break;
case PARAM_TYPE_STRING:
if (lua_isstring(L, index))
}
case PARAM_TYPE_STRING: {
if(lua_isstring(L, index))
return TRUE;
if(retfalse)
return FALSE;
luaL_error(L, "Parameter %d should be \"String\".", index);
break;
}
}
return FALSE;
}
......
......@@ -13,6 +13,7 @@
class scriptlib {
public:
static int32 check_data_type(lua_State* L, int32 index, const char* tname);
static int32 check_param(lua_State* L, int32 param_type, int32 index, BOOL retfalse = FALSE);
static int32 check_param_count(lua_State* L, int32 count);
static int32 check_action_permission(lua_State* L);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment