Core/CrossFaction: riscrittura crossfaction eliminando collegamenti diretti su player - modulo a se stante, utilizza solo scripts

This commit is contained in:
mik1893
2016-07-21 19:39:49 +01:00
parent 19dd2bef2e
commit 9ab406c175
9 changed files with 72 additions and 84 deletions
@@ -25,66 +25,3 @@ void AzthPlayer::setArena1v1Info(uint8 type, uint32 value) {
float AzthPlayer::GetPlayerQuestRate() {
return playerQuestRate;
}
uint32 AzthPlayer::getOriginalTeam() {
return player->TeamIdForRace(player->getRace());
}
bool AzthPlayer::setFactionForRace(uint8 race) {
bool disable = true;
CrossFaction *cf = sCrossFaction;
// Check disables
if (cf->isMapEnabled(player->GetMapId()) && cf->isZoneEnabled(player->GetZoneId()) && cf->isAreaEnabled(player->GetAreaId()))
disable = false;
else
{
player->Whisper("Quest'area ha il crossfaction disabilitato", LANG_UNIVERSAL, player->GetGUID());
sLog->outError("Crossfaction disabled for player %s", player->GetName().c_str());
return false;
}
if (player->InBattleground()) {
if (Battleground * bg = player->GetBattleground()) {
player->m_team = player->GetBgTeamId();
player->setFaction(player->m_team == TEAM_ALLIANCE ? 1 : 2);
//sLog->outError("Team %d , faction %d, bgteam %d", player->m_team,player->getFaction(), player->m_bgData.bgTeamId);
return true;
}
}
uint64 leaderGuid = player->GetGroup() ? player->GetGroup()->GetLeaderGUID() : player->GetGUID();
if (leaderGuid != player->GetGUID()) {
Player* leader = ObjectAccessor::FindPlayer(leaderGuid);
if (leader) {
player->m_team = leader->GetTeamId();
player->setFaction(leader->getFaction());
} else {
// Query informations from the DB
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_PINFO);
stmt->setUInt32(0, GUID_LOPART(leaderGuid));
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
return false;
Field* fields = result->Fetch();
uint8 raceid = fields[4].GetUInt8();
player->m_team = Player::TeamIdForRace(raceid);
ChrRacesEntry const* rEntry = sChrRacesStore.LookupEntry(raceid);
player->setFaction(rEntry ? rEntry->FactionID : 0);
}
return true;
}
return false;
}
@@ -23,16 +23,6 @@ class AzthPlayer {
*/
float GetPlayerQuestRate();
/**
Get Player team considering CrossFactionGroups: If player is in a group returns group leader's team
@param Unit race (Unused, kept for compatibility)
@returns Group leader team if player is in a group, -1 for default
*/
bool setFactionForRace(uint8 race);
uint32 getOriginalTeam();
uint32 getArena1v1Info(uint8 type);
void setArena1v1Info(uint8 type, uint32 value);
@@ -1,5 +1,5 @@
// Copyright (c) 2016 AzerothCore
// Author: mik1893
// Author: mik1893 - kepler - yehonal
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
@@ -7,15 +7,59 @@
#include "CrossFaction.h"
// Crossfaction class functionalities
void CrossFaction::UpdatePlayerTeam(Group* group, uint64 guid, bool reset /* = false */)
{
Player* player = ObjectAccessor::FindPlayer(guid);
if (player)
{
player->setFactionForRace(player->getRace());
}
bool disable = true;
// Per prima cosa, controllo i disable
if (isMapEnabled(player->GetMapId()) && isZoneEnabled(player->GetZoneId()) && isAreaEnabled(player->GetAreaId()))
disable = false;
else
{
// messaggio al player in caso di crossfaction disabilitato in una specifica area, cosi lo sa prima di lamentarsi e scassarmi la minchia
player->Whisper("Quest'area ha il crossfaction disabilitato", LANG_UNIVERSAL, player->GetGUID());
sLog->outDebug(LOG_FILTER_CROSSFACTION, "Crossfaction: disabled for player %s", player->GetName().c_str());
}
// se non e' un reset forzato oppure na zona disabilitata, eseguo la routine di cambio
if (!reset && !disable)
{
// Se sono in battleground applico la fazione relativa al battleground
if (player->InBattleground())
{
if (Battleground * bg = player->GetBattleground())
{
player->setTeamId(player->GetBgTeamId());
player->setFaction(player->GetTeamId() == TEAM_ALLIANCE ? 1 : 2);
sLog->outDebug(LOG_FILTER_CROSSFACTION, "Crossfaction: Battleground team id set for player %s", player->GetName().c_str());
return;
}
}
// Se sono in un nomrale gruppo, applico la fazione relativa al leader
uint64 leaderGuid = group ? group->GetLeaderGUID() : player->GetGUID();
if (leaderGuid != player->GetGUID())
if (Player* leader = ObjectAccessor::FindPlayer(leaderGuid))
{
player->setTeamId(leader->GetTeamId());
player->setFaction(leader->getFaction());
return;
}
}
// TUTTI GLI ALTRI CASI: RESET DELLA FAZIONE ALL ORIGINALE
// Se reset forzato oppure zona disabilitata, va messa la fazione originale del player, qualunque cosa succeda.
// LA RAZZA NON VIENE MAI MODIFICATA UNA VOLTA LOGGATI - SI PUO USARE PER TORNARE AL PUNTO DI PARTENZA
player->setTeamId(player->GetTeamId(true));
ChrRacesEntry const* rEntry = sChrRacesStore.LookupEntry(player->getRace());
player->setFaction(rEntry ? rEntry->FactionID : 0);
sLog->outDebug(LOG_FILTER_CROSSFACTION, "Crossfaction: reset done for player %s", player->GetName().c_str());
}
void CrossFaction::LoadConfig(bool reload)
@@ -127,6 +171,11 @@ public:
{
sCrossFaction->UpdatePlayerTeam(player->GetGroup(), player->GetGUID());
}
void OnUpdateFaction(Player *player) override
{
sCrossFaction->UpdatePlayerTeam(player->GetGroup(), player->GetGUID());
}
};
class CrossFactionWorld : public WorldScript
+5 -5
View File
@@ -6935,10 +6935,10 @@ void Player::setFactionForRace(uint8 race)
{
m_team = TeamIdForRace(race);
// [AZTH] Kepler: Inject AzthPlayer's team function to get team from group leader in CrossFactionGroups
if (azthPlayer->setFactionForRace(race))
sScriptMgr->OnPlayerUpdateFaction(this);
if (GetTeamId(true) != GetTeamId())
return;
// [/AZTH]
ChrRacesEntry const* rEntry = sChrRacesStore.LookupEntry(race);
setFaction(rEntry ? rEntry->FactionID : 0);
@@ -12228,10 +12228,10 @@ InventoryResult Player::CanUseItem(ItemTemplate const* proto) const
if (proto)
{
if ((proto->Flags2 & ITEM_FLAGS_EXTRA_HORDE_ONLY) && /*[AZTH]*/ azthPlayer->getOriginalTeam() != TEAM_HORDE)
if ((proto->Flags2 & ITEM_FLAGS_EXTRA_HORDE_ONLY) && GetTeamId(true) != TEAM_HORDE)
return EQUIP_ERR_YOU_CAN_NEVER_USE_THAT_ITEM;
if ((proto->Flags2 & ITEM_FLAGS_EXTRA_ALLIANCE_ONLY) && /*[AZTH]*/ azthPlayer->getOriginalTeam() != TEAM_ALLIANCE)
if ((proto->Flags2 & ITEM_FLAGS_EXTRA_ALLIANCE_ONLY) && GetTeamId(true) != TEAM_ALLIANCE)
return EQUIP_ERR_YOU_CAN_NEVER_USE_THAT_ITEM;
if ((proto->AllowableClass & getClassMask()) == 0 || (proto->AllowableRace & getRaceMask()) == 0)
+3 -1
View File
@@ -2126,8 +2126,10 @@ class Player : public Unit, public GridObject<Player>
void CheckAreaExploreAndOutdoor(void);
static TeamId TeamIdForRace(uint8 race);
TeamId GetTeamId() const { return m_team; }
TeamId GetTeamId(bool original = false) const { return original ? m_team : TeamIdForRace(getRace()); };
void setFactionForRace(uint8 race);
void setTeamId(TeamId teamid) { m_team = teamid; };
void InitDisplayIds();
@@ -437,7 +437,7 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPacket &recvData)
//[AZTH]
TeamId teamId = ginfo.teamId;
if (bgTypeId == BATTLEGROUND_RB) {
teamId = _player->azthPlayer->getOriginalTeam() == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE;
teamId = _player->GetTeamId(true) == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE;
}
//[/AZTH]
// remove player from all bg queues
+5
View File
@@ -1183,6 +1183,11 @@ void ScriptMgr::OnPlayerUpdateZone(Player* player, uint32 newZone, uint32 newAre
FOREACH_SCRIPT(PlayerScript)->OnUpdateZone(player, newZone, newArea);
}
void ScriptMgr::OnPlayerUpdateFaction(Player* player)
{
FOREACH_SCRIPT(PlayerScript)->OnUpdateFaction(player);
}
// [AZTH] all custom PlayerScript functions
void ScriptMgr::OnPlayerRemoveFromBattleground(Player* player, Battleground* bg)
{
+4
View File
@@ -710,6 +710,9 @@ class PlayerScript : public ScriptObject
// Called when a player changes to a new map (after moving to new map)
virtual void OnMapChanged(Player* /*player*/) { }
// Called when a player switches to a new zone
virtual void OnUpdateFaction(Player* /*player*/) { }
//[AZTH]
// Called when a player is removed from battleground
virtual void OnPlayerRemoveFromBattleground(Player* /*player*/, Battleground* /*bg*/) { }
@@ -985,6 +988,7 @@ class ScriptMgr
void OnPlayerDelete(uint64 guid);
void OnPlayerBindToInstance(Player* player, Difficulty difficulty, uint32 mapid, bool permanent);
void OnPlayerUpdateZone(Player* player, uint32 newZone, uint32 newArea);
void OnPlayerUpdateFaction(Player* player);
// [AZTH] all custom PlayerScript functions
void OnPlayerRemoveFromBattleground(Player* player, Battleground* bg);
void OnAchievementComplete(Player *player, AchievementEntry const* achievement);
+1
View File
@@ -54,6 +54,7 @@ enum DebugLogFilters
LOG_FILTER_BATTLEFIELD = 0x01000000, // Battlefield related
LOG_FILTER_TRANSMOG = 0x02000000, // Transmog debug
LOG_FILTER_GUILDHOUSE = 0x04000000, // Guildhouse debug
LOG_FILTER_CROSSFACTION = 0x04000000, // CrossFaction
};
enum LogTypes