Skip to content

Commit

Permalink
PvP Helpers and Hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
kaytotes committed Jan 8, 2025
1 parent c724d95 commit 08574fe
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tswow-core/Private/TSEventsLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void TSLua::load_events(sol::state& state)
LUA_HANDLE(player_events, PlayerEvents, OnRewardHonorEarly);
LUA_HANDLE(player_events, PlayerEvents, OnSummonIfPossible);
LUA_HANDLE(player_events, PlayerEvents, OnBeforeUpdateLocalChannels);
LUA_HANDLE(player_events, PlayerEvents, OnBeforeTogglePvP);
LUA_HANDLE(player_events, PlayerEvents, OnCheckPvPTarget);
//LUA_HANDLE(player_events, PlayerEvents, OnTradeComplete);
LUA_HANDLE(player_events, PlayerEvents, OnUpdateDodgePercentage);
LUA_HANDLE(player_events, PlayerEvents, OnUpdateBlockPercentage);
Expand Down
25 changes: 25 additions & 0 deletions tswow-core/Private/TSPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4217,4 +4217,29 @@ bool TSPlayer::CanSeeTransmog()
void TSPlayer::SetCanSeeTransmog(bool on)
{
player->SetCanSeeTransmog(on);
}

void TSPlayer::TogglePvP(bool enable)
{
if (enable)
{
player->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP, enable);
player->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER, !enable);
}
else
{
player->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP);
player->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER);
}

if (player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP))
{
if (!player->IsPvP() || player->pvpInfo.EndTimer)
player->UpdatePvP(true, true);
}
else
{
if (!player->pvpInfo.IsHostile && player->IsPvP())
player->pvpInfo.EndTimer = GameTime::GetGameTime(); // start toggle-off
}
}
4 changes: 4 additions & 0 deletions tswow-core/Public/TSEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ struct TSEvents

EVENT(OnBeforeUpdateLocalChannels, TSPlayer, TSMutable<bool, bool>)

EVENT(OnBeforeTogglePvP, TSPlayer, TSMutable<bool, bool>)

EVENT(OnCheckPvPTarget, TSPlayer, TSPlayer, TSMutable<bool, bool>)

EVENT(
OnTradeCompleted
, TSPlayer me
Expand Down
1 change: 1 addition & 0 deletions tswow-core/Public/TSPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ class TC_GAME_API TSPlayer : public TSUnit, public TSDBJsonProvider {

bool CanSeeTransmog();
void SetCanSeeTransmog(bool on);
void TogglePvP(bool enable);
private:
TSLua::Dictionary<TSNumber<uint32>, TSPlayerSpell> LGetSpellMap();
TSItem LGetItemByGUID0(TSGUID guid);
Expand Down
6 changes: 6 additions & 0 deletions tswow-core/Public/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,8 @@ declare interface TSPlayer extends TSUnit, TSDBJsonProvider {
CanSeeTransmog(): bool;

SetCanSeeTransmog(on: bool): void;

TogglePvP(enable: bool): void;
}

declare interface TSCorpse extends TSWorldObject {
Expand Down Expand Up @@ -8337,6 +8339,10 @@ declare namespace _hidden {
OnSummonIfPossible(callback: (player: TSPlayer, cancel: TSMutable<boolean,boolean>)=>void);

OnBeforeUpdateLocalChannels(callback: (player: TSPlayer, cancel: TSMutable<boolean,boolean>)=>void);

OnBeforeTogglePvP(callback: (player: TSPlayer, cancel: TSMutable<boolean, boolean>) => void);

OnCheckPvPTarget(callback: (attacker: TSPlayer, target: TSPlayer, valid: TSMutable<boolean, boolean>) => void);
}

export class Account<T> {
Expand Down

0 comments on commit 08574fe

Please sign in to comment.