Commit d265e944 authored by wind2009's avatar wind2009

Merge remote-tracking branch 'upstream/master'

parents 81e40af1 ade04cf7
...@@ -3200,69 +3200,32 @@ int32_t scriptlib::card_add_monster_attribute(lua_State *L) { ...@@ -3200,69 +3200,32 @@ int32_t scriptlib::card_add_monster_attribute(lua_State *L) {
card* pcard = *(card**) lua_touserdata(L, 1); card* pcard = *(card**) lua_touserdata(L, 1);
duel* pduel = pcard->pduel; duel* pduel = pcard->pduel;
pcard->set_status(STATUS_NO_LEVEL, FALSE); pcard->set_status(STATUS_NO_LEVEL, FALSE);
// pre-monster effect* peffect;
effect* peffect = pduel->new_effect(); auto add_temp_effect = [&](uint32_t code, int32_t value, uint32_t extra_reset_flag = 0) {
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_PRE_MONSTER;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_CHAIN + RESET_EVENT + 0x47e0000;
peffect->value = type;
pcard->add_effect(peffect);
//attribute
if(attribute) {
peffect = pduel->new_effect(); peffect = pduel->new_effect();
peffect->owner = pcard; peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE; peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_ADD_ATTRIBUTE; peffect->code = code;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE; peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x47e0000; peffect->reset_flag = RESET_EVENT | 0x47e0000 | extra_reset_flag;
peffect->value = attribute; peffect->value = value;
pcard->add_effect(peffect); pcard->add_effect(peffect);
};
add_temp_effect(EFFECT_PRE_MONSTER, type, RESET_CHAIN);
if(attribute) {
add_temp_effect(EFFECT_CHANGE_ATTRIBUTE, attribute);
} }
//race
if(race) { if(race) {
peffect = pduel->new_effect(); add_temp_effect(EFFECT_CHANGE_RACE, race);
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_ADD_RACE;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x47e0000;
peffect->value = race;
pcard->add_effect(peffect);
} }
//level
if(level) { if(level) {
peffect = pduel->new_effect(); add_temp_effect(EFFECT_CHANGE_LEVEL, level);
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_CHANGE_LEVEL;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x47e0000;
peffect->value = level;
pcard->add_effect(peffect);
} }
//atk
if(atk) { if(atk) {
peffect = pduel->new_effect(); add_temp_effect(EFFECT_SET_BASE_ATTACK, atk);
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_SET_BASE_ATTACK;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x47e0000;
peffect->value = atk;
pcard->add_effect(peffect);
} }
//def
if(def) { if(def) {
peffect = pduel->new_effect(); add_temp_effect(EFFECT_SET_BASE_DEFENSE, def);
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_SET_BASE_DEFENSE;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x47e0000;
peffect->value = def;
pcard->add_effect(peffect);
} }
return 0; return 0;
} }
......
...@@ -331,11 +331,11 @@ int32_t scriptlib::group_random_select(lua_State *L) { ...@@ -331,11 +331,11 @@ int32_t scriptlib::group_random_select(lua_State *L) {
check_param(L, PARAM_TYPE_GROUP, 1); check_param(L, PARAM_TYPE_GROUP, 1);
group* pgroup = *(group**) lua_touserdata(L, 1); group* pgroup = *(group**) lua_touserdata(L, 1);
int32_t playerid = (int32_t)lua_tointeger(L, 2); int32_t playerid = (int32_t)lua_tointeger(L, 2);
uint32_t count = (uint32_t)lua_tointeger(L, 3); int32_t count = (int32_t)lua_tointeger(L, 3);
duel* pduel = pgroup->pduel; duel* pduel = pgroup->pduel;
group* newgroup = pduel->new_group(); group* newgroup = pduel->new_group();
if(count > pgroup->container.size()) if (count > (int32_t)pgroup->container.size())
count = (uint32_t)pgroup->container.size(); count = (int32_t)pgroup->container.size();
if(count == 0) { if(count == 0) {
interpreter::group2value(L, newgroup); interpreter::group2value(L, newgroup);
return 1; return 1;
...@@ -343,12 +343,13 @@ int32_t scriptlib::group_random_select(lua_State *L) { ...@@ -343,12 +343,13 @@ int32_t scriptlib::group_random_select(lua_State *L) {
if(count == pgroup->container.size()) if(count == pgroup->container.size())
newgroup->container = pgroup->container; newgroup->container = pgroup->container;
else { else {
while(newgroup->container.size() < count) { card_vector cv(pgroup->container.begin(), pgroup->container.end());
int32_t i = pduel->get_next_integer(0, (int32_t)pgroup->container.size() - 1); int32_t back = (int32_t)cv.size() - 1;
auto cit = pgroup->container.begin(); for (int32_t i = 0; i < count; ++i) {
std::advance(cit, i); int32_t r = pduel->get_next_integer(i, back);
newgroup->container.insert(*cit); std::swap(cv[i], cv[r]);
} }
newgroup->container.insert(cv.begin(), cv.begin() + count);
} }
pduel->write_buffer8(MSG_RANDOM_SELECTED); pduel->write_buffer8(MSG_RANDOM_SELECTED);
pduel->write_buffer8(playerid); pduel->write_buffer8(playerid);
......
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