代码拉取完成,页面将自动刷新
#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));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。