571 lines
18 KiB
C++
571 lines
18 KiB
C++
#include "StdAfx.h"
|
|
|
|
//_NA_005026_20120527_CHAOS_ZONE_BATTLE_GROUND
|
|
#include <World/ChaosZoneSystem/BattleGroundTeam.h>
|
|
#include <../ProgramCommon/ChaosZoneSystem/PacketStruct_ChaosZoneSystem.h>
|
|
#include <World/ChaosZoneSystem/BattleGround.h>
|
|
#include "MapInfoParser.h"
|
|
#include "GameInstanceDungeon.h"
|
|
#include <ServerOptionParserEx.h>
|
|
#include <../ProgramCommon/BattleGroundInfoParser.h>
|
|
#include <StatusManager.h>
|
|
#include "MissionManager.h"
|
|
#include "MissionRewardManager.h"
|
|
#include "TriggerManagerEx.h"
|
|
|
|
#ifdef _NA_008679_20160202_REWORK_BATTLEGROUND
|
|
#include "SunRanking/SunRankingManager.h"
|
|
#endif //_NA_008679_20160202_REWORK_BATTLEGROUND
|
|
|
|
void BattleGroundTeam::Update()
|
|
{
|
|
//_NA_007065_20140217_BATTLEGROUND_REFACTORYING
|
|
if (team_state_ != eCHAOSTEAM_STATE_MATCHED) {
|
|
return;
|
|
}
|
|
|
|
PLAYER_HASH_ITR itr = player_hash_map_.begin();
|
|
for (; itr != player_hash_map_.end(); ++itr)
|
|
{
|
|
Player* const player = itr->second;
|
|
if (player == NULL || player->IsDeleted())
|
|
continue;
|
|
|
|
if (player->IsDead() &&
|
|
(player->GetBattleGroundPlayerInfo().GetPlayerState() == kPlayerStateMatch ||
|
|
player->GetBattleGroundPlayerInfo().GetPlayerState() == kPlayerStateDeath)
|
|
)
|
|
{
|
|
if (player->GetBattleGroundPlayerInfo().IsExpiredMoveToSafeZone() == false)
|
|
{
|
|
continue;
|
|
}
|
|
player->GetBattleGroundPlayerInfo().SetPlayerState(kPlayerStateStandbyResurection);
|
|
OnMoveToSafezone(player);
|
|
player->OnResurrection( 0, 1.f, 1.f );
|
|
|
|
MSG_CG_BATTLE_GROUND_STATE_RESURECTION_CMD send_msg;
|
|
send_msg.player_object_key = player->GetObjectKey();
|
|
send_msg.player_state = kPlayerStateStandbyResurection;
|
|
send_msg.resurection_time = battle_ground_->GetRemainTicks();
|
|
player->SendPacketAround(&send_msg, sizeof(send_msg));
|
|
}
|
|
|
|
else if(player->IsAlive() &&
|
|
player->GetBattleGroundPlayerInfo().GetPlayerState() == kPlayerStateDeath)
|
|
{
|
|
player->GetBattleGroundPlayerInfo().SetPlayerState(kPlayerStateMatch);
|
|
}
|
|
}
|
|
|
|
#ifdef _NA_006800_20130703_BATTLE_GROUND_VOTE_SYSTEM
|
|
if (voting_timer_.IsExpiredManual(false) == true)
|
|
{
|
|
OnVoteResult(true);
|
|
}
|
|
#endif // _NA_006800_20130703_BATTLE_GROUND_VOTE_SYSTEM
|
|
if (_IsExpired())
|
|
{
|
|
//_NA_007065_20140217_BATTLEGROUND_REFACTORYING
|
|
team_state_ = eCHAOSTEAM_STATE_END;
|
|
}
|
|
}
|
|
|
|
void BattleGroundTeam::Start()
|
|
{
|
|
//_NA_007065_20140217_BATTLEGROUND_REFACTORYING
|
|
team_state_ = eCHAOSTEAM_STATE_MATCHED;
|
|
|
|
PLAYER_HASH_ITR itr = player_hash_map_.begin();
|
|
for (; itr != player_hash_map_.end(); ++itr)
|
|
{
|
|
Player* const player = itr->second;
|
|
if (player == NULL || player->IsDeleted())
|
|
continue;
|
|
|
|
player->GetBattleGroundPlayerInfo().SetPlayerState(kPlayerStateMatch);
|
|
|
|
MSG_CG_BATTLE_GROUND_STATE_RESURECTION_CMD cmd_msg;
|
|
cmd_msg.player_state = kPlayerStateMatch;
|
|
player->SendPacket(&cmd_msg, sizeof(cmd_msg));
|
|
}
|
|
}
|
|
|
|
void BattleGroundTeam::AddMember(Player* const player)
|
|
{
|
|
if (player_hash_map_.size() > battle_ground_Info_->team_max)
|
|
{
|
|
return;
|
|
}
|
|
|
|
const DWORD char_guid = player->GetCharGuid();
|
|
;{
|
|
Player* const member = FindMember(char_guid);
|
|
if (member != NULL) {
|
|
player_hash_map_.erase(char_guid);
|
|
}
|
|
};
|
|
|
|
player_hash_map_.insert(PLAYER_HASH::value_type(char_guid, player));
|
|
|
|
int offset = 1;
|
|
int index = (battle_ground_Info_->index) - offset;
|
|
|
|
BattleGroundRecord* const record = \
|
|
player->GetExtraInfoManager().GetBattleGroundRecord(index);
|
|
record->map_code = battle_ground_->GetInstanceDungeon()->GetMapCode();
|
|
|
|
player->GetBattleGroundPlayerInfo().Init(record);
|
|
player->GetBattleGroundPlayerInfo().SetTeamKey(team_key_);
|
|
|
|
OnMoveToSafezone(player);
|
|
|
|
//CMD..
|
|
MSG_CG_BATTLE_GROUND_TEAM_INFO_CMD cmd_msg;
|
|
cmd_msg.team_key = team_key_;
|
|
player->SendPacket(&cmd_msg, sizeof(cmd_msg));
|
|
|
|
ready_user_keys_.erase(player->GetUserKey());
|
|
}
|
|
|
|
void BattleGroundTeam::AllDeathMemberResurrectionAtSafezone()
|
|
{
|
|
PLAYER_HASH::const_iterator const_itr = player_hash_map_.begin();
|
|
for (; const_itr != player_hash_map_.end(); ++const_itr)
|
|
{
|
|
Player* const player = const_itr->second;
|
|
if (player == NULL || player->IsDeleted()) {
|
|
continue;
|
|
}
|
|
|
|
BattleGroundPlayerState player_battle_ground_state = \
|
|
player->GetBattleGroundPlayerInfo().GetPlayerState();
|
|
|
|
if (player_battle_ground_state == kPlayerStateDeath ||
|
|
player_battle_ground_state == kPlayerStateMatch)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
MSG_CG_BATTLE_GROUND_STATE_RESURECTION_CMD cmd_msg;
|
|
cmd_msg.player_object_key = player->GetObjectKey();
|
|
if (player_battle_ground_state == kPlayerStateStandbyResurection)
|
|
{
|
|
ALLOC_STATUS_PAIR steel = \
|
|
player->GetStatusManager()->AllocStatus(eCHAR_STATE_IMMUNITY_DAMAGE,
|
|
battle_ground_Info_->iron_mode * 1000);
|
|
if (steel.second)
|
|
{
|
|
steel.second->SendStatusAddBRD();
|
|
}
|
|
|
|
cmd_msg.player_state = kPlayerStateMatch;
|
|
}
|
|
else if (player_battle_ground_state == kPlayerStateStandbyResurectionRefuse)
|
|
{
|
|
cmd_msg.player_state = kPlayerStateStandbyResurection;
|
|
cmd_msg.resurection_time = battle_ground_->GetRemainTicks();
|
|
}
|
|
else
|
|
{
|
|
continue;
|
|
}
|
|
|
|
player->GetBattleGroundPlayerInfo().SetPlayerState(cmd_msg.player_state);
|
|
player->SendPacketAround(&cmd_msg, sizeof(cmd_msg));
|
|
}
|
|
}
|
|
|
|
RC::eSTATUS_RESULT BattleGroundTeam::OnMoveToSafezone(Player* const player)
|
|
{
|
|
GameField* const field = player->GetField();
|
|
if (field == NULL)
|
|
{
|
|
return RC::RC_STATUS_FIELD_IS_NULL;
|
|
}
|
|
|
|
const sMAPINFO* const map_info = \
|
|
MapInfoParser::Instance()->FindMapInfo(battle_ground_->GetInstanceDungeon()->GetMapCode());
|
|
if (map_info == NULL)
|
|
{
|
|
return RC::RC_STATUS_MAPINFO_IS_NULL;
|
|
}
|
|
|
|
DWORD area_id = 0;
|
|
if (team_key_ == kRed)
|
|
{
|
|
area_id = map_info->wStartAreaID;
|
|
}
|
|
else
|
|
{
|
|
area_id = map_info->wStartAreaID2;
|
|
}
|
|
|
|
WzVector dest_pos;
|
|
if (field->GetAreaRandomStartingVector(area_id, dest_pos) == false)
|
|
{
|
|
return RC::RC_STATUS_IS_NOT_SAFEZONE;
|
|
}
|
|
|
|
if(field->TeleportObject( player, &dest_pos, TRUE ) == false)
|
|
{
|
|
return RC::RC_STATUS_TELEPORT_FAIL;
|
|
}
|
|
|
|
return RC::RC_STATUS_SUCCESS;
|
|
}
|
|
|
|
void BattleGroundTeam::IncreasePlayerKillPoint(Player* const player, Player* const target_player)
|
|
{
|
|
if (player)
|
|
player->GetBattleGroundPlayerInfo().IncreaseKill();
|
|
}
|
|
|
|
void BattleGroundTeam::IncreaseVictroyPoint(const int increase_victory_point)
|
|
{
|
|
victory_point_ += increase_victory_point;
|
|
}
|
|
|
|
void BattleGroundTeam::OnResult(const eBATTLEGROUND_RESULT result_type)
|
|
{
|
|
PLAYER_HASH::const_iterator const_itr = player_hash_map_.begin();
|
|
for (; const_itr != player_hash_map_.end(); ++const_itr)
|
|
{
|
|
eBATTLEGROUND_RESULT current_result_type = result_type;
|
|
Player* const player = const_itr->second;
|
|
if (player == NULL || player->IsDeleted())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
BattleGroundBattleResult* const battle_ground_result = \
|
|
battle_ground_->GetBattleGroundBattleResult();
|
|
if (battle_ground_result == NULL)
|
|
{
|
|
continue;
|
|
}
|
|
const BattleRecorder::Record* record = \
|
|
battle_ground_result->GetPlayerBattleResult(player);
|
|
if (record == NULL)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
const DWORD total_abusing_point = record->total_damage_to_enemy +
|
|
record->total_damage_by_enemy +
|
|
record->total_heal_to_party +
|
|
(record->player_kill_count * 1000) +
|
|
(record->assist_count * 100) +
|
|
(record->strongpoint_attack * 10000) +
|
|
(record->strongpoint_defense * 10000);
|
|
|
|
|
|
// abuse_point check..
|
|
if ((player->GetTeamKey() == kRed || player->GetTeamKey() == kBlue) &&
|
|
(total_abusing_point <= battle_ground_Info_->abusing_point))
|
|
{
|
|
current_result_type = eBG_RESULT_ABUSE;
|
|
battle_ground_->BattleGroundPenalty(player);
|
|
SUNBATTLEGROUNDLOG(
|
|
eCRITICAL_LOG,
|
|
TEXT("| [ZONE_KEY(%d)] | BattleGround Penalty Reason | Guid = %d , CharName = %s | total_abusing_point = %d, total_damage_to_enemy = %d, total_damage_by_enemy = %d, total_heal = %d, kill_count = %d, assist_count = %d, strongpoint_attack = %d, strongpoint_defense = %d |"),
|
|
battle_ground_->GetInstanceDungeon()->GetKey(),
|
|
player->GetUserGuid(),
|
|
player->GetCharName(),
|
|
total_abusing_point,
|
|
record->total_damage_to_enemy,
|
|
record->total_damage_by_enemy,
|
|
record->total_heal_to_party,
|
|
(record->player_kill_count * 1000),
|
|
(record->assist_count * 100),
|
|
(record->strongpoint_attack * 10000),
|
|
(record->strongpoint_defense * 10000));
|
|
}
|
|
|
|
battle_ground_result->SendBattleResult(player);
|
|
|
|
if (player->GetTeamKey() == kRed || player->GetTeamKey() == kBlue) {
|
|
_OnReward(player, current_result_type);
|
|
}
|
|
|
|
_OnFinishResult(player, current_result_type);
|
|
|
|
if (player->GetTeamKey() == kObserve) {
|
|
return;
|
|
}
|
|
|
|
switch (current_result_type)
|
|
{
|
|
case eBG_RESULT_WIN:
|
|
player->GetBattleGroundPlayerInfo().IncreaseWinTimes();
|
|
GAMELOG->LogChaosZone(ACT_BATTLE_GROUND_WIN, player);
|
|
break;
|
|
case eBG_RESULT_DRAW:
|
|
player->GetBattleGroundPlayerInfo().IncreaseDrawTimes();
|
|
GAMELOG->LogChaosZone(ACT_BATTLE_GROUND_DRAW, player);
|
|
break;
|
|
case eBG_RESULT_LOSE:
|
|
player->GetBattleGroundPlayerInfo().IncreaseLoseTimes();
|
|
GAMELOG->LogChaosZone(ACT_BATTLE_GROUND_LOSE, player);
|
|
break;
|
|
case eBG_RESULT_ABUSE:
|
|
player->GetBattleGroundPlayerInfo().IncreaseDisTimes();
|
|
GAMELOG->LogChaosZone(ACT_BATTLE_GROUND_DIS, player);
|
|
break;
|
|
}
|
|
|
|
if (current_result_type != eBG_RESULT_ABUSE)
|
|
player->GetBattleGroundPlayerInfo().IncreasePlayTimes();
|
|
|
|
#ifdef _NA_008679_20160202_REWORK_BATTLEGROUND
|
|
SunRankingManager::Instance()->ProcessBattleGround(*record, current_result_type, player);
|
|
#endif //_NA_008679_20160202_REWORK_BATTLEGROUND
|
|
}
|
|
}
|
|
|
|
#ifdef _NA_006800_20130703_BATTLE_GROUND_VOTE_SYSTEM
|
|
bool BattleGroundTeam::IsInitialteTime()
|
|
{
|
|
// time check..
|
|
if (initialte_vote_timer_.IsExpiredManual(false) == false) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool BattleGroundTeam::OnInitiateVote(Player* initiate_player, Player* van_player)
|
|
{
|
|
if (is_initialte_vote_ == true)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
voting_timer_.SetTimer(30 * 1000);
|
|
|
|
#ifdef _NA_008679_20160202_REWORK_BATTLEGROUND
|
|
TCHAR * _van_player_name = van_player->GetBattleGroundPlayerInfo().GetFalseName();
|
|
#else
|
|
TCHAR * _van_player_name = van_player->GetCharName();
|
|
#endif //_NA_008679_20160202_REWORK_BATTLEGROUND
|
|
|
|
;{
|
|
MSG_CG_BATTLE_GROUND_VOTE_STATUS_BRD brd_msg;
|
|
_tcsncpy(brd_msg.van_payer_name, _van_player_name, MAX_CHARNAME_LENGTH);
|
|
brd_msg.yes_count = 1;
|
|
brd_msg.no_count = 0;
|
|
brd_msg.remain_vote_time = voting_timer_.GetRemainedTime();
|
|
|
|
initiate_player->SendPacket(&brd_msg, sizeof(brd_msg));
|
|
van_player->SendPacket(&brd_msg, sizeof(brd_msg));
|
|
|
|
_tcsncpy(van_player_name_, _van_player_name, MAX_CHARNAME_LENGTH);
|
|
vote_player_hash_map_.insert(PLAYER_HASH::value_type(initiate_player->GetCharGuid(), initiate_player));
|
|
vote_player_hash_map_.insert(PLAYER_HASH::value_type(van_player->GetCharGuid(), van_player));
|
|
};
|
|
|
|
;{
|
|
MSG_CG_BATTLE_GROUND_INITIATE_VOTE_BRD brd_msg;
|
|
_tcsncpy(brd_msg.van_payer_name, _van_player_name, MAX_CHARNAME_LENGTH);
|
|
PLAYER_HASH::const_iterator const_itr = player_hash_map_.begin();
|
|
for (; const_itr != player_hash_map_.end(); ++const_itr)
|
|
{
|
|
Player* const player = const_itr->second;
|
|
if (player == NULL || player->IsDeleted())
|
|
continue;
|
|
if (player->GetCharGuid() == initiate_player->GetCharGuid() ||
|
|
player->GetCharGuid() == van_player->GetCharGuid())
|
|
continue;
|
|
player->SendPacket(&brd_msg, sizeof(brd_msg));
|
|
}
|
|
};
|
|
|
|
is_initialte_vote_ = true;
|
|
|
|
return true;
|
|
}
|
|
|
|
void BattleGroundTeam::OnVote(CHARGUID char_guid, bool vote_result)
|
|
{
|
|
Player* player = FindMember(char_guid);
|
|
if (player == NULL || player->IsDeleted()) {
|
|
return;
|
|
}
|
|
|
|
if (is_initialte_vote_ == false) {
|
|
return;
|
|
}
|
|
|
|
if (voting_timer_.IsExpired(false) == true) {
|
|
return;
|
|
}
|
|
|
|
if (vote_result == true)
|
|
{
|
|
vote_player_hash_map_.insert(PLAYER_HASH::value_type(char_guid, player));
|
|
|
|
if (CheckVoteResult() == true)
|
|
{
|
|
OnVoteResult(true);
|
|
}
|
|
|
|
else
|
|
{
|
|
MSG_CG_BATTLE_GROUND_VOTE_STATUS_BRD brd_msg;
|
|
_tcsncpy(brd_msg.van_payer_name, van_player_name_, MAX_CHARNAME_LENGTH);
|
|
brd_msg.yes_count = static_cast<BYTE>(vote_player_hash_map_.size() - 1);
|
|
brd_msg.no_count = 0;
|
|
brd_msg.remain_vote_time = voting_timer_.GetRemainedTime();
|
|
|
|
PLAYER_HASH::const_iterator const_itr = vote_player_hash_map_.begin();
|
|
for (; const_itr != vote_player_hash_map_.end(); ++const_itr)
|
|
{
|
|
Player* const player = const_itr->second;
|
|
if (player == NULL || player->IsDeleted()) {
|
|
continue;
|
|
}
|
|
player->SendPacket(&brd_msg, sizeof(brd_msg));
|
|
}
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
OnVoteResult(false);
|
|
}
|
|
}
|
|
|
|
bool BattleGroundTeam::CheckVoteResult()
|
|
{
|
|
const int current_memeber_count = player_hash_map_.size();
|
|
const int vote_member_count = vote_player_hash_map_.size();
|
|
|
|
if (current_memeber_count == vote_member_count)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void BattleGroundTeam::OnVoteResult(bool van_result)
|
|
{
|
|
if (is_initialte_vote_ == false)
|
|
return;
|
|
|
|
MSG_CG_BATTLE_GROUND_VOTE_RESULT_BRD brd_msg;
|
|
brd_msg.vote_result = van_result;
|
|
_tcsncpy(brd_msg.van_payer_name, van_player_name_, MAX_CHARNAME_LENGTH);
|
|
|
|
if (van_result)
|
|
{
|
|
OnVanPlayer();
|
|
|
|
battle_ground_->SendPacketToAll(&brd_msg, sizeof(brd_msg));
|
|
|
|
}
|
|
else
|
|
{
|
|
SendPacketToAll(&brd_msg, sizeof(brd_msg));
|
|
}
|
|
|
|
initialte_vote_timer_.SetTimer(60 * 1000);
|
|
is_initialte_vote_ = false;
|
|
vote_player_hash_map_.clear();
|
|
|
|
}
|
|
|
|
void BattleGroundTeam::OnVanPlayer()
|
|
{
|
|
#ifdef _NA_008679_20160202_REWORK_BATTLEGROUND
|
|
Player* van_player = battle_ground_->FindBattleGroundMemberByFalseName(van_player_name_);
|
|
#else
|
|
Player* const van_player = PlayerManager::Instance()->FindPlayerByName(van_player_name_);
|
|
#endif
|
|
if (van_player == NULL) {
|
|
return;
|
|
}
|
|
|
|
OnMoveToSafezone(van_player);
|
|
battle_ground_->BattleGroundPenalty(van_player);
|
|
|
|
MSG_CG_BATTLE_GROUND_VANP_PLAYER_CMD cmd_msg;
|
|
van_player->SendPacket(&cmd_msg, sizeof(cmd_msg));
|
|
}
|
|
#endif // _NA_006800_20130703_BATTLE_GROUND_VOTE_SYSTEM
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool BattleGroundTeam::_IsExpired()
|
|
{
|
|
if (victory_point_ >= battle_ground_Info_->goal_score) //script..
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void BattleGroundTeam::_OnReward(Player* const player, const eBATTLEGROUND_RESULT result_type)
|
|
{
|
|
ZONEKEY zone_key = battle_ground_->GetInstanceDungeon()->GetKey();
|
|
|
|
BOOL reward_result = MissionRewardManager::Instance()->RewardBattlegroundMember(player, zone_key,
|
|
battle_ground_Info_->map_code, result_type);
|
|
if (reward_result == TRUE)
|
|
{
|
|
SUNLOG(eFULL_LOG,
|
|
"[BattleGroundTeam::_OnReward] [ID:%s]:����������������.",player->GetUserID());
|
|
|
|
TCHAR* result_type_string[] =
|
|
{
|
|
"Error!",
|
|
"WIN",
|
|
"LOSE",
|
|
"DRAW",
|
|
"ABUSE"
|
|
};
|
|
|
|
SUNBATTLEGROUNDLOG(
|
|
eCRITICAL_LOG,
|
|
TEXT("| [ZONE_KEY(%d)] | Reward | Guid = %d, Match Result = %s, TEAM = %d, CharName = %s |"),
|
|
zone_key,
|
|
player->GetUserGuid(),
|
|
result_type_string[result_type],
|
|
player->GetTeamKey(),
|
|
player->GetCharName());
|
|
}
|
|
}
|
|
|
|
void BattleGroundTeam::_OnFinishResult(Player* const player, const eBATTLEGROUND_RESULT result_type)
|
|
{
|
|
MSG_CG_BATTLE_GROUND_FINISH_RESULT_BRD brd_msg;
|
|
brd_msg.result_type = result_type;
|
|
player->SendPacket(&brd_msg, sizeof(brd_msg));
|
|
}
|
|
|
|
#ifdef _NA_008679_20160202_REWORK_BATTLEGROUND
|
|
VOID BattleGroundTeam::SetPlayerFalseName( Player* _player )
|
|
{
|
|
STLX_MAP<DWORD, BYTE>::const_iterator con_itr = ready_user_keys_.find(_player->GetUserKey());
|
|
|
|
BYTE team_index = 0;
|
|
if (con_itr != ready_user_keys_.end()) {
|
|
team_index = con_itr->second;
|
|
}
|
|
|
|
_player->GetBattleGroundPlayerInfo().SetFalseName(GetTeamKey(), team_index);
|
|
}
|
|
|
|
BattleGroundTeam::BattleGroundTeam( BattleGround* const battle_ground ) :
|
|
battle_ground_(battle_ground),
|
|
battle_ground_Info_(NULL),
|
|
victory_point_(0),
|
|
strongpoint_count_(0),
|
|
is_initialte_vote_(false)
|
|
#ifdef _NA_008679_20160202_REWORK_BATTLEGROUND
|
|
, false_costume_code_(0)
|
|
#endif //_NA_008679_20160202_REWORK_BATTLEGROUND
|
|
{
|
|
initialte_vote_timer_.SetTimer(60 * 1000);
|
|
}
|
|
|
|
#endif //_NA_008679_20160202_REWORK_BATTLEGROUND
|