Commit f150c9ae authored by Chen Bill's avatar Chen Bill Committed by GitHub

no longer load script for temp card (#682)

parent 9b4a241e
......@@ -51,7 +51,7 @@ void duel::clear() {
card* duel::new_card(uint32 code) {
card* pcard = new card(this);
cards.insert(pcard);
if(code)
if (code != TEMP_CARD_ID)
::read_card(code, &(pcard->data));
pcard->data.code = code;
lua->register_card(pcard);
......
......@@ -63,7 +63,7 @@ void interpreter::register_card(card *pcard) {
lua_setmetatable(current_state, -2); //-1
lua_pop(current_state, 1); //-1
//Initial
if(pcard->data.code && is_load_script(pcard->data)) {
if(is_load_script(pcard->data)) {
pcard->set_status(STATUS_INITIALIZING, TRUE);
add_param(pcard, PARAM_TYPE_CARD);
call_card_function(pcard, "initial_effect", 1, 0);
......@@ -669,11 +669,13 @@ int32 interpreter::get_function_handle(lua_State* L, int32 index) {
int32 ref = luaL_ref(L, LUA_REGISTRYINDEX);
return ref;
}
duel* interpreter::get_duel_info(lua_State * L) {
duel* interpreter::get_duel_info(lua_State* L) {
duel* pduel;
std::memcpy(&pduel, lua_getextraspace(L), LUA_EXTRASPACE);
return pduel;
}
bool interpreter::is_load_script(card_data data) {
bool interpreter::is_load_script(const card_data& data) {
if(data.code == TEMP_CARD_ID)
return false;
return !(data.type & TYPE_NORMAL) || (data.type & TYPE_PENDULUM);
}
......@@ -85,7 +85,7 @@ public:
static void function2value(lua_State* L, int32 func_ref);
static int32 get_function_handle(lua_State* L, int32 index);
static duel* get_duel_info(lua_State* L);
static bool is_load_script(card_data data);
static bool is_load_script(const card_data& data);
template <size_t N, typename... TR>
static int sprintf(char (&buffer)[N], const char* format, TR... args) {
......
......@@ -6,6 +6,7 @@
*/
#include <cstdio>
#include <cstring>
#include <set>
#include "ocgapi.h"
#include "duel.h"
#include "card.h"
......@@ -14,7 +15,6 @@
#include "field.h"
#include "interpreter.h"
#include "buffer.h"
#include <set>
static script_reader sreader = default_script_reader;
static card_reader creader = default_card_reader;
......@@ -35,6 +35,10 @@ byte* read_script(const char* script_name, int* len) {
return sreader(script_name, len);
}
uint32 read_card(uint32 code, card_data* data) {
if (code == TEMP_CARD_ID) {
data->clear();
return 0;
}
return creader(code, data);
}
uint32 handle_message(void* pduel, uint32 msg_type) {
......
......@@ -19,6 +19,7 @@
#define LEN_FAIL 0
#define LEN_EMPTY 4
#define LEN_HEADER 8
#define TEMP_CARD_ID 0
class card;
struct card_data;
......
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