添加新maps.json读表规则

This commit is contained in:
aozhiwei 2019-04-29 16:57:02 +08:00
parent 5efdcf722c
commit 9b33e85aed
10 changed files with 142 additions and 25 deletions

View File

@ -49,7 +49,7 @@ void Building::FillMFObjectFull(cs::MFObjectFull* full_data)
p->set_obj_uniid(entity_uniid);
pos.ToPB(p->mutable_pos());
p->set_building_id(meta->i->_building_id());
p->set_building_id(meta->i->mapid());
}
ColliderComponent* Building::GetBoxBound()

View File

@ -12,7 +12,10 @@
#include "collision.h"
#include "building.h"
#include "hero.h"
#include "app.h"
#include "roommgr.h"
#include "framework/cpp/utils.h"
#include "framework/cpp/httpclientpool.h"
Human::Human():Entity()
@ -454,9 +457,11 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id)
Entity* hum = room->GetEntityByUniId(killer_id);
if (hum && hum->entity_type == ET_Player) {
((Human*)hum)->stats.kills++;
((Human*)hum)->kill_humans.insert(this);
}
stats.killer_id = killer_id;
stats.killer_name = killer_name;
stats.weapon_id = weapon_id;
dead = true;
health = 0.0f;
dead_frameno = room->frame_no;
@ -1192,9 +1197,63 @@ void Human::SendUpdateMsg()
void Human::UpdateGameOver()
{
#if 0
a8::MutableXObject* params = a8::MutableXObject::NewObject();
GenBattleReportData(params);
auto on_ok = [] (a8::XParams& param, a8::XObject& data)
{
long long room_uuid = param.sender;
int hum_uniid = param.param1;
Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
if (room) {
Entity* entity = room->GetEntityByUniId(hum_uniid);
if (entity && entity->entity_type == ET_Player) {
Human* hum = (Human*)entity;
}
}
};
auto on_error = [] (a8::XParams& param, const std::string& response)
{
long long room_uuid = param.sender;
int hum_uniid = param.param1;
Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
if (room) {
Entity* entity = room->GetEntityByUniId(hum_uniid);
if (entity && entity->entity_type == ET_Player) {
Human* hum = (Human*)entity;
++hum->send_gameover_trycount;
if (hum->send_gameover_trycount < 10){
hum->send_gameover = true;
}
}
}
};
std::string url;
if (!f8::IsOnlineEnv()) {
if (App::Instance()->flags.find(3) != App::Instance()->flags.end()) {
url = "http://http://192.168.100.41/webapp/index.php?c=Role&a=battleReport";
} else {
url = "https://game2001api-test.kingsome.cn/webapp/index.php?c=Role&a=battleReport";
}
} else {
url = "https://game2001api.kingsome.cn/webapp/index.php?c=Role&a=battleReport";
}
f8::HttpClientPool::Instance()->HttpGet(
a8::XParams()
.SetSender(room->room_uuid)
.SetParam1(entity_uniid),
on_ok,
on_error,
url.c_str(),
*params,
rand()
);
delete params;
#else
cs::SMGameOver msg;
FillSMGameOver(msg);
SendNotifyMsg(msg);
#endif
send_gameover = false;
}
@ -1223,7 +1282,7 @@ void Human::ClearFrameData()
}
}
void Human::BattleReport()
void Human::GenBattleReportData(a8::MutableXObject* params)
{
int rank = 0;
{
@ -1252,7 +1311,6 @@ void Human::BattleReport()
}
}
}
a8::MutableXObject* params = a8::MutableXObject::NewObject();
params->SetVal("account_id", account_id);
params->SetVal("map_name", room->map_meta->i->map_name());
params->SetVal("game_time", time(nullptr));
@ -1267,29 +1325,51 @@ void Human::BattleReport()
params->SetVal("alive_time", dead_frameno * 1000.0f / SERVER_FRAME_RATE);
}
params->SetVal("team_status", team_id != 0);
params->SetVal("snipe_kill", 0);
params->SetVal("rifle_kill", 0);
params->SetVal("pistol_kill", 0);
params->SetVal("submachine_kill", 0);
{
#if 0
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(lethal_weapon);
int snipe_kill = 0;
int rifle_kill = 0;
int pistol_kill = 0;
int submachine_kill = 0;
for (Human* hum : kill_humans) {
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(hum->lethal_weapon);
if (equip_meta) {
switch (equip_meta->i->equip_subtype()) {
case 7:
{
params->SetVal("snipe_kill", 0);
//狙击枪
++snipe_kill;
}
break;
case 5:
{
//步枪
++rifle_kill;
}
break;
case 2:
{
//手枪
++pistol_kill;
}
break;
case 3:
{
//冲锋枪
++submachine_kill;
}
break;
}
}
#endif
}
params->SetVal("snipe_kill", snipe_kill);
params->SetVal("rifle_kill", rifle_kill);
params->SetVal("pistol_kill", pistol_kill);
params->SetVal("submachine_kill", submachine_kill);
params->SetVal("rescue_member", stats.rescue_member);
{
int coin_num = (rank * MetaMgr::Instance()->rank_param) + (stats.kills * MetaMgr::Instance()->kill_param);
params->SetVal("coin_num", coin_num);
}
params->SetVal("score", 0);
delete params;
}

View File

@ -88,6 +88,7 @@ class Human : public Entity
PlayerStats stats;
bool send_gameover = false;
int send_gameover_trycount = 0;
int pain_killer_frameno = 0;
int pain_killer_lastingtime = 0;
@ -168,7 +169,7 @@ class Human : public Entity
private:
void ClearFrameData();
void BattleReport();
void GenBattleReportData(a8::MutableXObject* params);
protected:
long long last_shot_frameno_ = 0;

View File

@ -226,6 +226,25 @@ namespace MetaData
#endif
}
}
metatable::BuildingJson* building_meta = (metatable::BuildingJson*)i;
for (auto& loot : *building_meta->mutable_lootobj()) {
loot.set__rand_space(0);
std::vector<std::string> strings;
a8::Split(loot.things(), strings, '\n');
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
assert(strings2.size() == 2);
loot.set__rand_space(
loot._rand_space() +
a8::XValue(strings2[1]).GetInt()
);
auto p = loot.add__things();
p->set_key(a8::XValue(strings2[0]));
p->set_value(loot._rand_space());
}
}
}
void MapTplThing::Init()

View File

@ -208,9 +208,8 @@ private:
for (auto& meta : building_meta_list) {
MetaData::Building& item = a8::FastAppend(building_list);
item.i = &meta;
meta.set__building_id(building_id++);
item.Init();
building_hash[item.i->_building_id()] = &item;
building_hash[item.i->mapid()] = &item;
}
}

View File

@ -96,7 +96,7 @@ void Obstacle::FillMFObjectFull(cs::MFObjectFull* full_data)
p->set_door_old_state((int)door_state);
p->set_door_new_state((int)door_state);
p->set_door_house_uniid(door_house_uniid);
p->set_door_house_id(building->meta->i->_building_id());
p->set_door_house_id(building->meta->i->mapid());
if (door_state == DoorStateClose) {
p->set_door_width(door_state0->width());
p->set_door_height(door_state0->height());

View File

@ -392,11 +392,19 @@ void Room::CreateBuilding(int thing_id, float building_x, float building_y)
for (auto& obj : building_meta->i->lootobj()) {
float x = building->pos.x + obj.x() - building->meta->i->tilewidth() / 2.0;
float y = building->pos.y + obj.y() - building->meta->i->tileheight() / 2.0;
InternalCreateObstacle(obj.id(), x, y,
[building] (Obstacle* entity)
{
entity->building = building;
});
if (obj._rand_space() > 0) {
int rnd = rand () % obj._rand_space();
for (auto& pair : obj._things()) {
if (rnd <= pair.value()) {
InternalCreateObstacle(pair.key(), x, y,
[building] (Obstacle* entity)
{
entity->building = building;
});
break;
}
}
}
}
for (auto& obj : building_meta->i->dropobj()) {
CreateLoot(obj.id(),

View File

@ -23,10 +23,10 @@ class RoomMgr : public a8::Singleton<RoomMgr>
void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg);
void RemoveFromInactiveRoomHash(long long room_uuid);
int RoomNum();
Room* GetRoomByUuid(long long uuid);
private:
Room* GetJoinableRoom(const std::string& account_id);
Room* GetRoomByUuid(long long uuid);
private:
std::map<long long, Room*> inactive_room_hash_;

View File

@ -60,6 +60,7 @@ struct PlayerStats
int killer_id = 0;
std::string killer_name;
int weapon_id = 0;
};

View File

@ -1,5 +1,11 @@
package metatable;
message MFPair
{
optional int32 key = 1; //key
optional int32 value = 2; //val
}
message Parameter
{
optional string param_name = 1;
@ -165,7 +171,10 @@ message LootObjJson
{
optional float x = 1;
optional float y = 2;
optional int32 id = 3;
optional int32 weight = 3;
optional string things = 4;
repeated MFPair _things = 5;
optional int32 _rand_space = 6;
}
message BuildingJson
@ -178,7 +187,7 @@ message BuildingJson
repeated StaticObjJson staticObj = 6;
repeated LootObjJson lootObj = 7;
optional int32 _building_id = 20;
optional int32 mapId = 20;
}
message MapTplThingJson