19 Star 45 Fork 32

留天下/CM-Server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
logicfight.cpp 2.87 KB
一键复制 编辑 原始数据 按行查看 历史
留天下 提交于 2019-02-22 13:22 . net redo done!
#include "logicfight.h"
#include"networkmanager.h"
#include"messageconst.h"
#include<iostream>
using namespace std;
DEFINE_SINGLE_ATTRIBUTES(LogicFight);
LogicFight::LogicFight()
{
NET_INSTANCE()->add(MESSAGE_PLAYER_ATTACK,handler(this,SEL_EVENTFUNC(LogicFight::c2sPlayerAtk)));
NET_INSTANCE()->add(MESSAGE_MONSTER_ATTACK,handler(this,SEL_EVENTFUNC(LogicFight::c2sMonsterAtk)));
NET_INSTANCE()->add(MESSAGE_PLAYER_RUN,handler(this,SEL_EVENTFUNC(LogicFight::c2sPlayerRun)));
NET_INSTANCE()->add(MESSAGE_USE_MEDICATION,handler(this,SEL_EVENTFUNC(LogicFight::c2sUseMedication)));
NET_INSTANCE()->add(MESSAGE_PLAYER_DIE,handler(this,SEL_EVENTFUNC(LogicFight::c2sPlayerDie)));
}
void LogicFight::c2sPlayerAtk(Json::Value& msg)
{
cout<<"ogicFight::c2sPlayerAtk"<<msg.toStyledString()<<endl;
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
msg["fd"]=fd;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
cout<<playermaps[fd].rolename<<" attack monster"<<endl;
NET_INSTANCE()->send(dest,MESSAGE_PLAYER_ATTACK,msg);
//SendMsg(msg->dest,(char*)msg,sizeof(PlayerAtk_Msg));
}
}
void LogicFight::c2sMonsterAtk(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
msg["fd"]=fd;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
cout<<"monster attack "<<playermaps[dest].rolename<<endl;
NET_INSTANCE()->send(dest,MESSAGE_MONSTER_ATTACK,msg);
//SendMsg(msg->dest,(char*)msg,sizeof(MonsterAtk_Msg));
}
}
void LogicFight::c2sPlayerRun(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
msg["fd"]=fd;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
cout<<playermaps[fd].rolename<<" run away"<<endl;
NET_INSTANCE()->send(dest,MESSAGE_PLAYER_RUN,msg);
//SendMsg(msg->dest,(char*)msg,sizeof(PlayerRun_Msg));
}
}
void LogicFight::c2sUseMedication(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
msg["fd"]=fd;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
cout<<playermaps[fd].rolename<<" use medication"<<endl;
NET_INSTANCE()->send(dest,MESSAGE_PLAYER_RUN,msg);
//SendMsg(msg->dest,(char*)msg,sizeof(PlayerRun_Msg));
}
}
void LogicFight::c2sPlayerDie(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
msg["fd"]=fd;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
cout<<playermaps[fd].rolename<<" die!"<<endl;
NET_INSTANCE()->send(dest,MESSAGE_PLAYER_RUN,msg);
//SendMsg(msg->dest,(char*)msg,sizeof(PlayerRun_Msg));
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/lsylovews/CM-Server.git
git@gitee.com:lsylovews/CM-Server.git
lsylovews
CM-Server
CM-Server
master

搜索帮助