Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: methods to set factions into player #693

Merged
merged 9 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ ReturnValue Combat::canDoCombat(Creature* attacker, Creature* target)
} else if (attackerPlayer->getTile()->hasFlag(TILESTATE_NOPVPZONE) && !targetPlayerTile->hasFlag(TILESTATE_NOPVPZONE | TILESTATE_PROTECTIONZONE)) {
return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE;
}

if (attackerPlayer->getFaction() != FACTION_DEFAULT && attackerPlayer->getFaction() != FACTION_PLAYER && attackerPlayer->getFaction() == targetPlayer->getFaction()) {
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
}
}

if (attackerMaster) {
Expand Down
6 changes: 5 additions & 1 deletion src/creatures/players/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,12 @@ class Player final : public Creature, public Cylinder
}

Faction_t getFaction() const override {
return FACTION_PLAYER;
return faction;
}

void setFaction(Faction_t factionId) {
faction = factionId;
}
//combat functions
bool setAttackedCreature(Creature* creature) override;
bool isImmune(CombatType_t type) const override;
Expand Down Expand Up @@ -2434,6 +2437,7 @@ class Player final : public Creature, public Cylinder
BlockType_t lastAttackBlockType = BLOCK_NONE;
TradeState_t tradeState = TRADE_NONE;
FightMode_t fightMode = FIGHTMODE_ATTACK;
Faction_t faction = FACTION_PLAYER;
account::AccountType accountType = account::AccountType::ACCOUNT_TYPE_NORMAL;
QuickLootFilter_t quickLootFilter;
VipStatus_t statusVipList = VIPSTATUS_ONLINE;
Expand Down
26 changes: 26 additions & 0 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3199,3 +3199,29 @@ int PlayerFunctions::luaPlayerGetForgeCores(lua_State *L) {
lua_pushnumber(L, static_cast<lua_Number>(core));
return 1;
}

int PlayerFunctions::luaPlayerSetFaction(lua_State* L) {
// player:setFaction(factionId)
Player* player = getUserdata<Player>(L, 1);
if (!player) {
lua_pushnil(L);
return 1;
}
Faction_t factionId = getNumber<Faction_t>(L, 2);
player->setFaction(factionId);
pushBoolean(L, true);
return 1;
}

int PlayerFunctions::luaPlayerGetFaction(lua_State* L) {
// player:getFaction()
Player* player = getUserdata<Player>(L, 1);

if (player) {
lua_pushnumber(L, player->getFaction());
}
else {
lua_pushnil(L);
}
return 1;
}
6 changes: 6 additions & 0 deletions src/lua/functions/creatures/player/player_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ class PlayerFunctions final : LuaScriptInterface {
registerMethod(L, "Player", "getForgeSlivers", PlayerFunctions::luaPlayerGetForgeSlivers);
registerMethod(L, "Player", "getForgeCores", PlayerFunctions::luaPlayerGetForgeCores);

registerMethod(L, "Player", "setFaction", PlayerFunctions::luaPlayerSetFaction);
registerMethod(L, "Player", "getFaction", PlayerFunctions::luaPlayerGetFaction);

GroupFunctions::init(L);
GuildFunctions::init(L);
MountFunctions::init(L);
Expand Down Expand Up @@ -568,6 +571,9 @@ class PlayerFunctions final : LuaScriptInterface {
static int luaPlayerGetForgeSlivers(lua_State* L);
static int luaPlayerGetForgeCores(lua_State* L);

static int luaPlayerSetFaction(lua_State* L);
static int luaPlayerGetFaction(lua_State* L);

friend class CreatureFunctions;
};

Expand Down