Last active
July 25, 2021 20:52
-
-
Save dbjorkholm/3d9aa986756e2ac8337668c24d04239d to your computer and use it in GitHub Desktop.
Player.addAura/addWing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int LuaScriptInterface::luaPlayerAddWing(lua_State* L) | |
{ | |
// player:addWing(wingId or wingName) | |
Player* player = getUserdata<Player>(L, 1); | |
if (!player) { | |
lua_pushnil(L); | |
return 1; | |
} | |
Wing* wing = nullptr; | |
if (isNumber(L, 2)) { | |
wing = g_game.wings.getWingByID(getNumber<uint8_t>(L, 2)); | |
} else { | |
wing = g_game.wings.getWingByName(getString(L, 2)); | |
} | |
if (!wing) { | |
lua_pushnil(L); | |
return 1; | |
} | |
pushBoolean(L, player->addWing(wing->id)); | |
return 1; | |
} | |
int LuaScriptInterface::luaPlayerRemoveWing(lua_State* L) | |
{ | |
// player:removeWing(wingId or wingName) | |
Player* player = getUserdata<Player>(L, 1); | |
if (!player) { | |
lua_pushnil(L); | |
return 1; | |
} | |
uint8_t wingId; | |
if (isNumber(L, 2)) { | |
wingId = getNumber<uint8_t>(L, 2); | |
} else { | |
Wing* wing = g_game.wings.getWingByName(getString(L, 2)); | |
if (!wing) { | |
lua_pushnil(L); | |
return 1; | |
} | |
wingId = wing->id; | |
} | |
pushBoolean(L, player->removeWing(wingId)); | |
return 1; | |
} | |
int LuaScriptInterface::luaPlayerAddAura(lua_State* L) | |
{ | |
// player:addAura(id or name) | |
Player* player = getUserdata<Player>(L, 1); | |
if (!player) { | |
lua_pushnil(L); | |
return 1; | |
} | |
Aura* aura = nullptr; | |
if (isNumber(L, 2)) { | |
aura = g_game.auras.getAuraByID(getNumber<uint8_t>(L, 2)); | |
} else { | |
aura = g_game.auras.getAuraByName(getString(L, 2)); | |
} | |
if (!aura) { | |
lua_pushnil(L); | |
return 1; | |
} | |
pushBoolean(L, player->addAura(aura->id)); | |
return 1; | |
} | |
int LuaScriptInterface::luaPlayerRemoveAura(lua_State* L) | |
{ | |
// player:removeAura(id or name) | |
Player* player = getUserdata<Player>(L, 1); | |
if (!player) { | |
lua_pushnil(L); | |
return 1; | |
} | |
uint8_t auraId; | |
if (isNumber(L, 2)) { | |
auraId = getNumber<uint8_t>(L, 2); | |
} else { | |
Aura* aura = g_game.auras.getAuraByName(getString(L, 2)); | |
if (!aura) { | |
lua_pushnil(L); | |
return 1; | |
} | |
auraId = aura->id; | |
} | |
pushBoolean(L, player->removeAura(auraId)); | |
return 1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool Player::addWing(uint8_t wingId) | |
{ | |
if (!g_game.wings.getWingByID(wingId)) { | |
return false; | |
} | |
const uint8_t tmpWingId = wingId - 1; | |
const uint32_t key = PSTRG_WINGS_RANGE_START + (tmpWingId / 31); | |
int32_t value; | |
if (getStorageValue(key, value)) { | |
value |= (1 << (tmpWingId % 31)); | |
} else { | |
value = (1 << (tmpWingId % 31)); | |
} | |
addStorageValue(key, value); | |
return true; | |
} | |
bool Player::removeWing(uint8_t wingId) | |
{ | |
if (!g_game.wings.getWingByID(wingId)) { | |
return false; | |
} | |
const uint8_t tmpWingId = wingId - 1; | |
const uint32_t key = PSTRG_WINGS_RANGE_START + (tmpWingId / 31); | |
int32_t value; | |
if (!getStorageValue(key, value)) { | |
return true; | |
} | |
value &= ~(1 << (tmpWingId % 31)); | |
addStorageValue(key, value); | |
return true; | |
} | |
bool Player::addAura(uint8_t auraId) | |
{ | |
if (!g_game.auras.getAuraByID(auraId)) { | |
return false; | |
} | |
const uint8_t tmpAuraId = auraId - 1; | |
const uint32_t key = PSTRG_AURAS_RANGE_START + (tmpAuraId / 31); | |
int32_t value; | |
if (getStorageValue(key, value)) { | |
value |= (1 << (tmpAuraId % 31)); | |
} else { | |
value = (1 << (tmpAuraId % 31)); | |
} | |
addStorageValue(key, value); | |
return true; | |
} | |
bool Player::removeAura(uint8_t auraId) | |
{ | |
if (!g_game.auras.getAuraByID(auraId)) { | |
return false; | |
} | |
const uint8_t tmpAuraId = auraId - 1; | |
const uint32_t key = PSTRG_AURAS_RANGE_START + (tmpAuraId / 31); | |
int32_t value; | |
if (!getStorageValue(key, value)) { | |
return true; | |
} | |
value &= ~(1 << (tmpAuraId % 31)); | |
addStorageValue(key, value); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment