int32 scriptlib::effect_reset(lua_State *L) { check_param_count(L, 1); check_param(L, PARAM_TYPE_EFFECT, 1); effect* peffect = *(effect**) lua_touserdata(L, 1); if(peffect->owner == 0) return 0; if(peffect->flag & EFFECT_FLAG_FIELD_ONLY) peffect->pduel->game_field->remove_effect(peffect); else peffect->handler->remove_effect(peffect); return 0; }
int32 scriptlib::effect_set_hint_timing(lua_State *L) { check_param_count(L, 2); check_param(L, PARAM_TYPE_EFFECT, 1); effect* peffect = *(effect**) lua_touserdata(L, 1); int32 vs = lua_tointeger(L, 2); int32 vo = vs; if(lua_gettop(L) >= 3) vo = lua_tointeger(L, 3); peffect->hint_timing[0] = vs; peffect->hint_timing[1] = vo; return 0; }
int32 scriptlib::effect_is_active_type(lua_State *L) { check_param_count(L, 2); check_param(L, PARAM_TYPE_EFFECT, 1); effect* peffect = *(effect**) lua_touserdata(L, 1); uint32 tpe = lua_tointeger(L, 2); uint32 atype; if(peffect->type & 0x7f0) atype = peffect->card_type; else atype = peffect->owner->get_type(); lua_pushboolean(L, atype & tpe); return 1; }
int32 scriptlib::effect_set_count_limit(lua_State *L) { check_param_count(L, 2); check_param(L, PARAM_TYPE_EFFECT, 1); effect* peffect = *(effect**) lua_touserdata(L, 1); if(!(peffect->type & EFFECT_TYPE_ACTIONS)) return 0; int32 v = lua_tointeger(L, 2); if(v == 0) v = 1; peffect->flag |= EFFECT_FLAG_COUNT_LIMIT; peffect->reset_count |= ((v << 12) & 0xf000) | ((v << 8) & 0xf00); return 0; }
int32 scriptlib::effect_set_label_object(lua_State *L) { check_param_count(L, 2); check_param(L, PARAM_TYPE_EFFECT, 1); effect* peffect = *(effect**) lua_touserdata(L, 1); if(lua_isnil(L, 2)) { peffect->label = 0; return 0; } if(!lua_isuserdata(L, 2)) 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_reset(lua_State *L) { check_param_count(L, 2); check_param(L, PARAM_TYPE_EFFECT, 1); effect* peffect = *(effect**) lua_touserdata(L, 1); int32 v = lua_tointeger(L, 2); int32 c = lua_tointeger(L, 3); if(c == 0) c = 1; if(v & (RESET_PHASE) && !(v & (RESET_SELF_TURN | RESET_OPPO_TURN))) v |= (RESET_SELF_TURN | RESET_OPPO_TURN); peffect->reset_flag = v; peffect->reset_count |= c & 0xff; return 0; }
int32 scriptlib::debug_set_player_info(lua_State *L) { check_param_count(L, 4); duel* pduel = interpreter::get_duel_info(L); uint32 playerid = lua_tointeger(L, 1); uint32 lp = lua_tointeger(L, 2); uint32 startcount = lua_tointeger(L, 3); uint32 drawcount = lua_tointeger(L, 4); if(playerid != 0 && playerid != 1) return 0; pduel->game_field->player[playerid].lp = lp; pduel->game_field->player[playerid].start_count = startcount; pduel->game_field->player[playerid].draw_count = drawcount; return 0; }
int32 scriptlib::debug_show_hint(lua_State *L) { check_param_count(L, 1); check_param(L, PARAM_TYPE_STRING, 1); duel* pduel = interpreter::get_duel_info(L); pduel->write_buffer8(MSG_SHOW_HINT); const char* pstr = lua_tostring(L, 1); int len = strlen(pstr); if(len > 1024) len = 1024; pduel->write_buffer16(len); memcpy(pduel->bufferp, pstr, len); pduel->bufferp += len; pduel->bufferlen += len; pduel->write_buffer8(0); return 0; }
int32 scriptlib::effect_set_absolute_range(lua_State *L) { check_param_count(L, 4); check_param(L, PARAM_TYPE_EFFECT, 1); effect* peffect = *(effect**) lua_touserdata(L, 1); int32 playerid = lua_tointeger(L, 2); int32 s = lua_tointeger(L, 3); int32 o = lua_tointeger(L, 4); if(playerid == 0) { peffect->s_range = s; peffect->o_range = o; } else { peffect->s_range = o; peffect->o_range = s; } peffect->flag |= EFFECT_FLAG_ABSOLUTE_TARGET; return 0; }
int32 scriptlib::effect_get_label_object(lua_State *L) { check_param_count(L, 1); check_param(L, PARAM_TYPE_EFFECT, 1); effect* peffect = *(effect**) lua_touserdata(L, 1); if (!peffect->label_object) { 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; }
int32 scriptlib::effect_set_value(lua_State *L) { check_param_count(L, 2); check_param(L, PARAM_TYPE_EFFECT, 1); effect* peffect = *(effect**) lua_touserdata(L, 1); if(peffect->value && (peffect->flag & EFFECT_FLAG_FUNC_VALUE)) luaL_unref(L, LUA_REGISTRYINDEX, peffect->value); if (lua_isfunction(L, 2)) { peffect->value = interpreter::get_function_handle(L, 2); peffect->flag |= EFFECT_FLAG_FUNC_VALUE; } else { peffect->flag &= ~EFFECT_FLAG_FUNC_VALUE; if(lua_isboolean(L, 2)) peffect->value = lua_toboolean(L, 2); else peffect->value = lua_tointeger(L, 2); } return 0; }
int32 scriptlib::effect_set_type(lua_State *L) { check_param_count(L, 2); check_param(L, PARAM_TYPE_EFFECT, 1); effect* peffect = *(effect**) lua_touserdata(L, 1); int32 v = lua_tointeger(L, 2); if (v & 0x0ff0) v |= EFFECT_TYPE_ACTIONS; else v &= ~EFFECT_TYPE_ACTIONS; if(v & 0x550) v |= EFFECT_TYPE_FIELD; if(v & EFFECT_TYPE_ACTIVATE) peffect->range = LOCATION_SZONE + LOCATION_HAND; if(v & EFFECT_TYPE_FLIP) peffect->code = EVENT_FLIP; peffect->type = v; return 0; }
int32 scriptlib::debug_pre_equip(lua_State *L) { check_param_count(L, 2); check_param(L, PARAM_TYPE_CARD, 1); check_param(L, PARAM_TYPE_CARD, 2); card* equip_card = *(card**) lua_touserdata(L, 1); card* target = *(card**) lua_touserdata(L, 2); if((equip_card->current.location != LOCATION_SZONE) || (target->current.location != LOCATION_MZONE) || (target->current.position & POS_FACEDOWN)) lua_pushboolean(L, 0); else { equip_card->equip(target, FALSE); equip_card->effect_target_cards.insert(target); target->effect_target_owner.insert(equip_card); lua_pushboolean(L, 1); } return 1; }
int32 scriptlib::debug_show_system_hint(lua_State *L) { check_param_count(L, 1); uint32 id = lua_tointeger(L, 1); duel* pduel = interpreter::get_duel_info(L); pduel->write_buffer8(MSG_SHOW_HINT); char* pstr = ""; wcstombs(pstr, GetSysString(id),20); int len = strlen(pstr); if(len > 1024) len = 1024; pduel->write_buffer16(len); memcpy(pduel->bufferp, pstr, len); pduel->bufferp += len; pduel->bufferlen += len; pduel->write_buffer8(0); return 0; }
int32 scriptlib::debug_add_card(lua_State *L) { check_param_count(L, 6); duel* pduel = interpreter::get_duel_info(L); int32 code = lua_tointeger(L, 1); int32 owner = lua_tointeger(L, 2); int32 playerid = lua_tointeger(L, 3); int32 location = lua_tointeger(L, 4); int32 sequence = lua_tointeger(L, 5); int32 position = lua_tointeger(L, 6); int32 proc = lua_toboolean(L, 7); if(owner != 0 && owner != 1) return 0; if(playerid != 0 && playerid != 1) return 0; if(pduel->game_field->is_location_useable(playerid, location, sequence)) { card* pcard = pduel->new_card(code); pcard->owner = owner; pcard->operation_param = position << 24; pduel->game_field->add_card(playerid, pcard, location, sequence); pcard->current.position = position; if(!(location & LOCATION_ONFIELD) || (position & POS_FACEUP)) { pcard->enable_field_effect(TRUE); pduel->game_field->adjust_instant(); } if(proc) pcard->set_status(STATUS_PROC_COMPLETE, TRUE); interpreter::card2value(L, pcard); return 1; } else if(location == LOCATION_MZONE) { card* pcard = pduel->new_card(code); pcard->owner = owner; card* fcard = pduel->game_field->get_field_card(playerid, location, sequence); fcard->xyz_materials.push_back(pcard); pcard->overlay_target = fcard; pcard->current.controler = PLAYER_NONE; pcard->current.location = LOCATION_OVERLAY; pcard->current.sequence = fcard->xyz_materials.size() - 1; interpreter::card2value(L, pcard); return 1; } return 0; }
trex_rpc_cmd_rc_e TrexRpcCommand::run(const Json::Value ¶ms, Json::Value &result) { trex_rpc_cmd_rc_e rc; /* the internal run can throw a parser error / other error */ try { check_param_count(params, m_param_count, result); if (m_needs_ownership && !g_test_override_ownership) { verify_ownership(params, result); } /* run the command itself*/ rc = _run(params, result); } catch (TrexRpcCommandException &e) { return e.get_rc(); } return (rc); }