Core/BattleGrounds: store data about BGs victories

Enable in worldserver.conf

Closes #12944

Signed-off-by: DDuarte <dnpd.dd@gmail.com>
This commit is contained in:
ShinDarth
2014-08-28 15:32:38 +01:00
committed by DDuarte
parent cbeaa6703c
commit b65172910c
15 changed files with 201 additions and 1 deletions

View File

@@ -2378,6 +2378,66 @@ LOCK TABLES `pool_quest_save` WRITE;
/*!40000 ALTER TABLE `pool_quest_save` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `pvpstats_battlegrounds`
--
DROP TABLE IF EXISTS `pvpstats_battlegrounds`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `pvpstats_battlegrounds` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`winner_faction` tinyint(4) NOT NULL,
`bracket_id` tinyint(3) unsigned NOT NULL,
`type` tinyint(3) unsigned NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `pvpstats_battlegrounds`
--
LOCK TABLES `pvpstats_battlegrounds` WRITE;
/*!40000 ALTER TABLE `pvpstats_battlegrounds` DISABLE KEYS */;
/*!40000 ALTER TABLE `pvpstats_battlegrounds` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `pvpstats_players`
--
DROP TABLE IF EXISTS `pvpstats_players`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `pvpstats_players` (
`battleground_id` bigint(20) unsigned NOT NULL,
`character_guid` int(10) unsigned NOT NULL,
`score_killing_blows` mediumint(8) unsigned NOT NULL,
`score_deaths` mediumint(8) unsigned NOT NULL,
`score_honorable_kills` mediumint(8) unsigned NOT NULL,
`score_bonus_honor` mediumint(8) unsigned NOT NULL,
`score_damage_done` mediumint(8) unsigned NOT NULL,
`score_healing_done` mediumint(8) unsigned NOT NULL,
`attr_1` mediumint(8) unsigned NOT NULL DEFAULT '0',
`attr_2` mediumint(8) unsigned NOT NULL DEFAULT '0',
`attr_3` mediumint(8) unsigned NOT NULL DEFAULT '0',
`attr_4` mediumint(8) unsigned NOT NULL DEFAULT '0',
`attr_5` mediumint(8) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`battleground_id`,`character_guid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `pvpstats_players`
--
LOCK TABLES `pvpstats_players` WRITE;
/*!40000 ALTER TABLE `pvpstats_players` DISABLE KEYS */;
/*!40000 ALTER TABLE `pvpstats_players` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `reserved_name`
--
@@ -2457,4 +2517,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2014-01-26 14:39:20
-- Dump completed on 2014-08-28 15:30:47

View File

@@ -0,0 +1,28 @@
DROP TABLE IF EXISTS `pvpstats_battlegrounds`;
CREATE TABLE `pvpstats_battlegrounds` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`winner_faction` TINYINT NOT NULL,
`bracket_id` TINYINT UNSIGNED NOT NULL,
`type` TINYINT UNSIGNED NOT NULL,
`date` DATETIME NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
DROP TABLE IF EXISTS `pvpstats_players`;
CREATE TABLE `pvpstats_players` (
`battleground_id` BIGINT UNSIGNED NOT NULL,
`character_guid` INT UNSIGNED NOT NULL,
`score_killing_blows` MEDIUMINT UNSIGNED NOT NULL,
`score_deaths` MEDIUMINT UNSIGNED NOT NULL,
`score_honorable_kills` MEDIUMINT UNSIGNED NOT NULL,
`score_bonus_honor` MEDIUMINT UNSIGNED NOT NULL,
`score_damage_done` MEDIUMINT UNSIGNED NOT NULL,
`score_healing_done` MEDIUMINT UNSIGNED NOT NULL,
`attr_1` MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,
`attr_2` MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,
`attr_3` MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,
`attr_4` MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,
`attr_5` MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`battleground_id`, `character_guid`)
) ENGINE=InnoDB;

View File

@@ -712,6 +712,24 @@ void Battleground::EndBattleground(uint32 winner)
int32 winmsg_id = 0;
PreparedStatement* stmt;
PreparedQueryResult result;
uint64 battleground_id = 1;
if (isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_STORE_STATISTICS_ENABLE))
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PVPSTATS_MAXID);
result = CharacterDatabase.Query(stmt);
if (result)
{
Field* fields = result->Fetch();
battleground_id = fields[0].GetInt64() + 1;
}
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PVPSTATS_BATTLEGROUND);
}
if (winner == ALLIANCE)
{
winmsg_id = isBattleground() ? LANG_BG_A_WINS : LANG_ARENA_GOLD_WINS;
@@ -719,6 +737,9 @@ void Battleground::EndBattleground(uint32 winner)
PlaySoundToAll(SOUND_ALLIANCE_WINS); // alliance wins sound
SetWinner(BG_TEAM_ALLIANCE);
if (isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_STORE_STATISTICS_ENABLE))
stmt->setUInt8(1, BG_TEAM_ALLIANCE);
}
else if (winner == HORDE)
{
@@ -727,10 +748,24 @@ void Battleground::EndBattleground(uint32 winner)
PlaySoundToAll(SOUND_HORDE_WINS); // horde wins sound
SetWinner(BG_TEAM_HORDE);
if (isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_STORE_STATISTICS_ENABLE))
stmt->setUInt8(1, BG_TEAM_HORDE);
}
else
{
SetWinner(BG_TEAM_NEUTRAL);
if (isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_STORE_STATISTICS_ENABLE))
stmt->setUInt8(1, BG_TEAM_NEUTRAL);
}
if (isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_STORE_STATISTICS_ENABLE))
{
stmt->setUInt64(0, battleground_id);
stmt->setUInt8(2, m_BracketId + 1);
stmt->setUInt8(3, GetTypeID());
CharacterDatabase.Execute(stmt);
}
SetStatus(STATUS_WAIT_LEAVE);
@@ -770,6 +805,30 @@ void Battleground::EndBattleground(uint32 winner)
uint32 loser_kills = player->GetRandomWinner() ? sWorld->getIntConfig(CONFIG_BG_REWARD_LOSER_HONOR_LAST) : sWorld->getIntConfig(CONFIG_BG_REWARD_LOSER_HONOR_FIRST);
uint32 winner_arena = player->GetRandomWinner() ? sWorld->getIntConfig(CONFIG_BG_REWARD_WINNER_ARENA_LAST) : sWorld->getIntConfig(CONFIG_BG_REWARD_WINNER_ARENA_FIRST);
if (isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_STORE_STATISTICS_ENABLE))
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PVPSTATS_PLAYER);
BattlegroundScoreMap::const_iterator score = PlayerScores.find(player->GetGUIDLow());
// battleground_id, character_guid, score_killing_blows, score_deaths, score_honorable_kills, score_bonus_honor, score_damage_done, score_healing_done
stmt->setUInt32(0, battleground_id);
stmt->setUInt32(1, player->GetGUIDLow());
stmt->setUInt32(2, score->second->GetKillingBlows());
stmt->setUInt32(3, score->second->GetDeaths());
stmt->setUInt32(4, score->second->GetHonorableKills());
stmt->setUInt32(5, score->second->GetBonusHonor());
stmt->setUInt32(6, score->second->GetDamageDone());
stmt->setUInt32(7, score->second->GetHealingDone());
stmt->setUInt32(8, score->second->GetAttr1());
stmt->setUInt32(9, score->second->GetAttr2());
stmt->setUInt32(10, score->second->GetAttr3());
stmt->setUInt32(11, score->second->GetAttr4());
stmt->setUInt32(12, score->second->GetAttr5());
CharacterDatabase.Execute(stmt);
}
// Reward winner team
if (team == winner)
{

View File

@@ -107,6 +107,19 @@ struct BattlegroundScore
// For Logging purpose
virtual std::string ToString() const { return ""; }
uint32 GetKillingBlows() const { return KillingBlows; }
uint32 GetDeaths() const { return Deaths; }
uint32 GetHonorableKills() const { return HonorableKills; }
uint32 GetBonusHonor() const { return BonusHonor; }
uint32 GetDamageDone() const { return DamageDone; }
uint32 GetHealingDone() const { return HealingDone; }
virtual uint32 GetAttr1() const { return 0; }
virtual uint32 GetAttr2() const { return 0; }
virtual uint32 GetAttr3() const { return 0; }
virtual uint32 GetAttr4() const { return 0; }
virtual uint32 GetAttr5() const { return 0; }
uint64 PlayerGuid;
// Default score, present in every type

View File

@@ -267,6 +267,9 @@ struct BattlegroundABScore final : public BattlegroundScore
data << uint32(BasesDefended);
}
uint32 GetAttr1() const { return BasesAssaulted; }
uint32 GetAttr2() const { return BasesDefended; }
uint32 BasesAssaulted;
uint32 BasesDefended;
};

View File

@@ -1568,6 +1568,12 @@ struct BattlegroundAVScore final : public BattlegroundScore
data << uint32(MinesCaptured);
}
uint32 GetAttr1() const { return GraveyardsAssaulted; }
uint32 GetAttr2() const { return GraveyardsDefended; }
uint32 GetAttr3() const { return TowersAssaulted; }
uint32 GetAttr4() const { return TowersDefended; }
uint32 GetAttr5() const { return MinesCaptured; }
uint32 GraveyardsAssaulted;
uint32 GraveyardsDefended;
uint32 TowersAssaulted;

View File

@@ -349,6 +349,8 @@ struct BattlegroundEYScore final : public BattlegroundScore
data << uint32(FlagCaptures);
}
uint32 GetAttr1() const { return FlagCaptures; }
uint32 FlagCaptures;
};

View File

@@ -878,6 +878,9 @@ struct BattlegroundICScore final : public BattlegroundScore
data << uint32(BasesDefended);
}
uint32 GetAttr1() const { return BasesAssaulted; }
uint32 GetAttr2() const { return BasesDefended; }
uint32 BasesAssaulted;
uint32 BasesDefended;
};

View File

@@ -538,6 +538,9 @@ struct BattlegroundSAScore final : public BattlegroundScore
data << uint32(GatesDestroyed);
}
uint32 GetAttr1() const { return DemolishersDestroyed; }
uint32 GetAttr2() const { return GatesDestroyed; }
uint32 DemolishersDestroyed;
uint32 GatesDestroyed;
};

View File

@@ -177,6 +177,9 @@ struct BattlegroundWGScore final : public BattlegroundScore
data << uint32(FlagReturns);
}
uint32 GetAttr1() const { return FlagCaptures; }
uint32 GetAttr2() const { return FlagReturns; }
uint32 FlagCaptures;
uint32 FlagReturns;
};

View File

@@ -1021,6 +1021,7 @@ void World::LoadConfigSettings(bool reload)
m_bool_configs[CONFIG_BATTLEGROUND_CAST_DESERTER] = sConfigMgr->GetBoolDefault("Battleground.CastDeserter", true);
m_bool_configs[CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE] = sConfigMgr->GetBoolDefault("Battleground.QueueAnnouncer.Enable", false);
m_bool_configs[CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_PLAYERONLY] = sConfigMgr->GetBoolDefault("Battleground.QueueAnnouncer.PlayerOnly", false);
m_bool_configs[CONFIG_BATTLEGROUND_STORE_STATISTICS_ENABLE] = sConfigMgr->GetBoolDefault("Battleground.StoreStatistics.Enable", false);
m_int_configs[CONFIG_BATTLEGROUND_INVITATION_TYPE] = sConfigMgr->GetIntDefault ("Battleground.InvitationType", 0);
m_int_configs[CONFIG_BATTLEGROUND_PREMATURE_FINISH_TIMER] = sConfigMgr->GetIntDefault ("Battleground.PrematureFinishTimer", 5 * MINUTE * IN_MILLISECONDS);
m_int_configs[CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH] = sConfigMgr->GetIntDefault ("Battleground.PremadeGroupWaitForMatch", 30 * MINUTE * IN_MILLISECONDS);

View File

@@ -121,6 +121,7 @@ enum WorldBoolConfigs
CONFIG_BATTLEGROUND_CAST_DESERTER,
CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE,
CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_PLAYERONLY,
CONFIG_BATTLEGROUND_STORE_STATISTICS_ENABLE,
CONFIG_BG_XP_FOR_KILL,
CONFIG_ARENA_AUTO_DISTRIBUTE_POINTS,
CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE,

View File

@@ -600,4 +600,10 @@ void CharacterDatabaseConnection::DoPrepareStatements()
PrepareStatement(CHAR_UPD_CHAR_PET_SLOT_BY_ID, "UPDATE character_pet SET slot = ? WHERE owner = ? AND id = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_CHAR_PET_BY_ID, "DELETE FROM character_pet WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_CHAR_PET_BY_SLOT, "DELETE FROM character_pet WHERE owner = ? AND (slot = ? OR slot > ?)", CONNECTION_ASYNC);
// PvPstats
PrepareStatement(CHAR_SEL_PVPSTATS_MAXID, "SELECT MAX(id) FROM pvpstats_battlegrounds", CONNECTION_SYNCH);
PrepareStatement(CHAR_INS_PVPSTATS_BATTLEGROUND, "INSERT INTO pvpstats_battlegrounds (id, winner_faction, bracket_id, type, date) VALUES (?, ?, ?, ?, NOW())", CONNECTION_ASYNC);
PrepareStatement(CHAR_INS_PVPSTATS_PLAYER, "INSERT INTO pvpstats_players (battleground_id, character_guid, score_killing_blows, score_deaths, score_honorable_kills, score_bonus_honor, score_damage_done, score_healing_done, attr_1, attr_2, attr_3, attr_4, attr_5) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC);
}

View File

@@ -534,6 +534,10 @@ enum CharacterDatabaseStatements
CHAR_DEL_ITEMCONTAINER_MONEY,
CHAR_INS_ITEMCONTAINER_MONEY,
CHAR_SEL_PVPSTATS_MAXID,
CHAR_INS_PVPSTATS_BATTLEGROUND,
CHAR_INS_PVPSTATS_PLAYER,
MAX_CHARACTERDATABASE_STATEMENTS
};

View File

@@ -2059,6 +2059,14 @@ Battleground.QueueAnnouncer.Enable = 0
Battleground.QueueAnnouncer.PlayerOnly = 0
#
# Battleground.StoreStatistics.Enable
# Description: Store Battleground scores in the database.
# Default: 0 - (Disabled)
# 1 - (Enabled)
Battleground.StoreStatistics.Enable = 0
#
# Battleground.InvitationType
# Description: Set Battleground invitation type.