1 Star 0 Fork 32

nh41435/CM-Server

forked from 留天下/CM-Server 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
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/nh41435/CM-Server.git
git@gitee.com:nh41435/CM-Server.git
nh41435
CM-Server
CM-Server
master

搜索帮助