This commit is contained in:
aozhiwei 2020-10-21 17:58:37 +08:00
commit 91aac9611c
12 changed files with 261 additions and 5 deletions

View File

@ -97,6 +97,8 @@ void HandlerMgr::RegisterNetMsgHandlers()
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMAdStart);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMAdCancel);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMAdEnd);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMGetBoxInfo);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMOpenBox);
}
void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,

View File

@ -2540,10 +2540,17 @@ void Human::SendBattleReport()
}
} else {
if (JsonDataMgr::Instance()->channel != 0) {
if (kTouTiaoChannelId == JsonDataMgr::Instance()->channel) {
url = a8::Format("http://game2004api-al.kingsome.cn/%d/webapp/index.php?c=Role&a=battleReport",
{
JsonDataMgr::Instance()->channel
});
} else {
url = a8::Format("http://game2004api.kingsome.cn/%d/webapp/index.php?c=Role&a=battleReport",
{
JsonDataMgr::Instance()->channel
});
}
} else {
url = "http://game2004api.kingsome.cn/webapp/index.php?c=Role&a=battleReport";
}
@ -2632,6 +2639,7 @@ void Human::ProcLootCar(Loot* entity, MetaData::Equip* item_meta)
if (car_.meta->i->buffid()) {
RemoveBuffById(car_.meta->i->buffid());
}
car_weapon = Weapon();
}
car_.car_uniid = entity->GetEntityUniId();
car_.car_id = item_meta->i->id();

View File

@ -110,6 +110,7 @@ namespace MetaData
const metatable::Drop* i = nullptr;
void Init();
//0:item_id 1:item_num 2:weight
void RandItems(std::vector<std::tuple<int, int, int>>& drop_items);
private:

View File

@ -203,6 +203,10 @@ public:
MetaMgr::Instance()->zbmode_player_num) {
abort();
}
{
METAMGR_READ(prebattle_box_id_chiji, 0);
METAMGR_READ(prebattle_box_id_zb, 0);
}
{
METAMGR_READ(newbie_first_robot_ammo, 3);
METAMGR_READ(newbie_first_robot_appeartime, 8);

View File

@ -134,6 +134,9 @@ class MetaMgr : public a8::Singleton<MetaMgr>
MetaData::Player* android_meta = nullptr;
MetaData::Player* terminator_meta = nullptr;
int prebattle_box_id_chiji = 0;
int prebattle_box_id_zb = 0;
private:
MetaDataLoader* loader_ = nullptr;

View File

@ -1301,6 +1301,81 @@ void Player::_CMAdEnd(f8::MsgHdr& hdr, const cs::CMAdEnd& msg)
InternalAdOk();
}
void Player::_CMGetBoxInfo(f8::MsgHdr& hdr, const cs::CMGetBoxInfo& msg)
{
cs::SMGetBoxInfo respmsg;
respmsg.set_box_id(msg.box_id());
std::vector<std::tuple<int, int, int>>* items = GetBox(msg.box_id());
if (items) {
for (auto& tuple : *items) {
auto p = respmsg.add_items();
p->add_values(std::get<0>(tuple));
p->add_values(std::get<1>(tuple));
}
}
SendNotifyMsg(respmsg);
}
void Player::_CMOpenBox(f8::MsgHdr& hdr, const cs::CMOpenBox& msg)
{
cs::SMOpenBox respmsg;
respmsg.set_box_id(msg.box_id());
respmsg.set_errcode(0);
if (msg.box_id() == 1) {
if (receved_box_hash_.find(msg.box_id()) == receved_box_hash_.end()) {
std::vector<std::tuple<int, int, int>>* items = GetBox(msg.box_id());
if (items) {
for (auto& tuple : *items) {
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquip(std::get<0>(tuple));
if (item_meta) {
auto p = respmsg.add_items();
p->add_values(std::get<0>(tuple));
p->add_values(std::get<1>(tuple));
if (item_meta->i->_inventory_slot() >= 0 &&
item_meta->i->_inventory_slot() < IS_END) {
if (GetInventory(item_meta->i->_inventory_slot()) <
GetVolume(item_meta->i->_inventory_slot())) {
int add_num = GetVolume(item_meta->i->_inventory_slot()) -
GetInventory(item_meta->i->_inventory_slot());
add_num = std::min(std::get<1>(tuple), add_num);
AddInventory(item_meta->i->_inventory_slot(), add_num);
}
} else {
switch (item_meta->i->equip_type()) {
case 7:
{
//背包
if (backpack == 0) {
MetaData::Equip* old_item_meta = MetaMgr::Instance()->GetEquip(backpack);
if (old_item_meta) {
if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) {
break;
}
room->DropItem(GetPos(), old_item_meta->i->id(), 1, 1);
}
backpack = item_meta->i->id();
RecalcVolume();
}
}
break;
default:
break;
}
}
}
}
need_sync_active_player = true;
}
receved_box_hash_.insert(msg.box_id());
} else {
respmsg.set_errcode(1);
respmsg.set_errmsg("不能重复领取");
}
}
SendNotifyMsg(respmsg);
}
void Player::InternalAdCancel()
{
if (GetBuffByEffectId(kBET_AdPlaying)) {
@ -1379,3 +1454,32 @@ void Player::ProcPreSettlementInfo(const std::string& pre_settlement_info)
rank = a8::XValue(tmp_strings[3]);
}
}
std::vector<std::tuple<int, int, int>>* Player::GetBox(int box_id)
{
if (box_id != 1) {
return nullptr;
}
{
auto itr = box_hash_.find(box_id);
if (itr != box_hash_.end()) {
return &itr->second;
}
}
int drop_id = 0;
if (room->GetRoomMode() == kZombieMode) {
drop_id = MetaMgr::Instance()->prebattle_box_id_zb;
} else {
drop_id = MetaMgr::Instance()->prebattle_box_id_chiji;
}
MetaData::Drop* drop_meta = MetaMgr::Instance()->GetDrop(drop_id);
if (drop_meta) {
std::vector<std::tuple<int, int, int>> drop_items;
drop_meta->RandItems(drop_items);
box_hash_[box_id] = drop_items;
}
{
auto itr = box_hash_.find(box_id);
return itr != box_hash_.end() ? &itr->second : nullptr;
}
}

View File

@ -101,6 +101,8 @@ class Player : public Human
void _CMAdStart(f8::MsgHdr& hdr, const cs::CMAdStart& msg);
void _CMAdCancel(f8::MsgHdr& hdr, const cs::CMAdCancel& msg);
void _CMAdEnd(f8::MsgHdr& hdr, const cs::CMAdEnd& msg);
void _CMGetBoxInfo(f8::MsgHdr& hdr, const cs::CMGetBoxInfo& msg);
void _CMOpenBox(f8::MsgHdr& hdr, const cs::CMOpenBox& msg);
protected:
Player();
@ -109,6 +111,11 @@ private:
void InternalAdCancel();
void InternalAdOk();
void InternalUpdate(int delta_time);
std::vector<std::tuple<int, int, int>>* GetBox(int box_id);
private:
std::map<int, std::vector<std::tuple<int, int, int>>> box_hash_;
std::set<int> receved_box_hash_;
friend class EntityFactory;
};

View File

@ -175,6 +175,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
msg.account_id()
});
}
OnJoinRoomOk(msg, hum);
}
void RoomMgr::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg)
@ -544,3 +545,93 @@ bool RoomMgr::IsGM(const std::string& account_id)
{
return gm_hash_.find(account_id) != gm_hash_.end();
}
std::string RoomMgr::GenTeamHashData(const std::string& team_uuid, std::map<std::string, long long>* team_hash)
{
std::string data;
data += a8::Format("team_uuid:%s ", {team_uuid});
for (auto pair : *team_hash) {
data += a8::Format("%s->%d ", {pair.first, pair.second});
}
return data;
}
void RoomMgr::OnJoinRoomOk(const cs::CMJoin& msg, Player* hum)
{
if (msg.team_members().size() <= 1) {
return;
}
std::map<std::string, long long>* team_hash = nullptr;
{
auto itr = team_room_hash_.find(msg.team_uuid());
if (itr == team_room_hash_.end()) {
team_room_hash_[msg.team_uuid()] = std::map<std::string, long long>();
itr = team_room_hash_.find(msg.team_uuid());
team_hash = &itr->second;
for (auto& team_member : msg.team_members()) {
team_hash->insert(std::make_pair(team_member.account_id(), 0));
}
a8::Timer::Instance()->AddDeadLineTimer
(1000 * 60,
a8::XParams()
.SetSender(msg.team_uuid()),
[] (const a8::XParams& params)
{
RoomMgr::Instance()->TeamRoomTimeOut(params.sender);
}
);
} else {
team_hash = &itr->second;
}
}
if (!team_hash) {
abort();
}
{
auto itr = team_hash->find(hum->account_id);
if (itr != team_hash->end()) {
itr->second = hum->room->GetRoomUuid();
} else {
a8::UdpLog::Instance()->Warning
("team_data:%s account_id:%s not exists",
{
GenTeamHashData(msg.team_uuid(), team_hash),
hum->account_id
});
}
}
}
void RoomMgr::TeamRoomTimeOut(const std::string& team_uuid)
{
std::map<std::string, long long>* team_hash = nullptr;
{
auto itr = team_room_hash_.find(team_uuid);
if (itr != team_room_hash_.end()) {
team_hash = &itr->second;
}
}
if (team_hash) {
bool ok = true;
for (auto pair : *team_hash) {
if (pair.second == 0) {
ok = false;
break;
}
}
if (!ok) {
a8::UdpLog::Instance()->Warning
("team match failed team_data:%s ",
{
GenTeamHashData(team_uuid, team_hash),
});
}
team_room_hash_.erase(team_uuid);
} else {
a8::UdpLog::Instance()->Warning
("team not found team_uuid:s",
{
team_uuid
});
}
}

View File

@ -53,6 +53,9 @@ class RoomMgr : public a8::Singleton<RoomMgr>
int creator_proto_version,
int creator_channel);
void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle);
std::string GenTeamHashData(const std::string& team_uuid, std::map<std::string, long long>* team_hash);
void OnJoinRoomOk(const cs::CMJoin& msg, Player* hum);
void TeamRoomTimeOut(const std::string& team_uuid);
private:
int current_room_idx_ = 0;
@ -63,4 +66,5 @@ class RoomMgr : public a8::Singleton<RoomMgr>
std::map<long long, Room*> over_room_hash_;
a8::TimerAttacher reportstate_timer_attacher_;
std::map<std::string, int> gm_hash_;
std::map<std::string, std::map<std::string, long long>> team_room_hash_;
};

View File

@ -18,6 +18,8 @@ enum CMMessageId_e
_CMAdStart = 212;
_CMAdCancel = 213;
_CMAdEnd = 214;
_CMGetBoxInfo = 215;
_CMOpenBox = 216;
}
enum SMMessageId_e
@ -28,6 +30,8 @@ enum SMMessageId_e
_SMWatchWar = 208;
_SMLeave = 209;
_SMGetBoxInfo = 216;
_SMOpenBox = 217;
_SMJoinedNotify = 103;
_SMMapInfo = 1002;

View File

@ -857,6 +857,18 @@ message CMAdEnd
optional int32 param = 1; //1: 2
}
//
message CMGetBoxInfo
{
optional int32 box_id = 1; //1
}
//
message CMOpenBox
{
optional int32 box_id = 1; //1:
}
//endcmmsg
//error_code == 0 ,
@ -959,6 +971,22 @@ message SMLeave
{
}
//
message SMGetBoxInfo
{
optional int32 box_id = 1; //1
repeated MFTuple items = 2; //values[0]:id values[1]:
}
//
message SMOpenBox
{
optional int32 box_id = 1; //1:
optional int32 errcode = 2; //
optional string errmsg = 3; //
repeated MFTuple items = 4; //values[0]:id values[1]:
}
//线
message SMDisconnectNotify
{

@ -1 +1 @@
Subproject commit ea69b96451e7004430e99b86db1cfd3ae4d76c6b
Subproject commit 98f1d402cba91a1983dac2eb00de731657e133a5