📄 message.cpp
字号:
map.CenterMap( role[0].State.X, role[0].State.Y );
break;
case MSG_SETPLAYERSHOW: //设置主角显示与否
role[0].State.bShow=m_stMsg[Id].Param1;
break;
case MSG_LOADPLAYER: //从ini文件读入主角
role[m_stMsg[Id].Param1].LoadRoleIni(m_stMsg[Id].String1, m_stMsg[Id].String2);
break;
case MSG_SWITCHPLAYER: //交换主角
{
int r1=m_stMsg[Id].Param1;
int r2=m_stMsg[Id].Param2;
//先保存
role[r1].SaveRole("save\\temp1.rol");
role[r2].SaveRole("save\\temp2.rol");
//交换加载
role[r1].LoadRole("save\\temp2.rol");
role[r2].LoadRole("save\\temp1.rol");
if( r2==0 )
goto _Next;
else
if( r1==0 )
{
r1=r2;
r2=0;
}
else
break;
_Next:
//继承过来
role[r2].Propertiy.Money=role[r1].Propertiy.Money; //金钱
role[r2].Propertiy.CurGoodsNum=role[r1].Propertiy.CurGoodsNum; //物品总数
//物品(最多可带64种)
memcpy(role[r2].Propertiy.Goods, role[r1].Propertiy.Goods, MAXGOODS*2);
//每种物品的数量
memcpy(role[r2].Propertiy.GoodsNum, role[r1].Propertiy.GoodsNum, MAXGOODS*2);
role[r2].Propertiy.CurArmNum=role[r1].Propertiy.CurArmNum; //装备总数
//装备(最多可带32种)
memcpy(role[r2].Propertiy.Arm, role[r2].Propertiy.Arm, MAXARM*2);
//每种装备的数量
memcpy(role[r2].Propertiy.ArmNum, role[r2].Propertiy.ArmNum, MAXARM*2);
}
break;
case MSG_SETPLAYERNUM: //设置主角个数
RoleNum=m_stMsg[Id].Param1;
break;
case MSG_ADDMONEY: //改变金钱
role[0].Propertiy.Money+=m_stMsg[Id].Param1;
break;
case MSG_ADDOBJECT: //添加物体
if( m_stMsg[Id].Param1==ERROR_DATA ) //数目
m_stMsg[Id].Param1=1;
role[0].AddObject( m_stMsg[Id].String1, m_stMsg[Id].Param1 );
break;
case MSG_DELOBJECT: //删除物体
if( m_stMsg[Id].Param1==ERROR_DATA ) //数目
m_stMsg[Id].Param1=1;
role[0].DelObject( m_stMsg[Id].String1, m_stMsg[Id].Param1 );
break;
case MSG_ADDMAGIC: //添加魔法
if(m_stMsg[Id].Param1 == ERROR_DATA)
m_stMsg[Id].Param1 = 0; //缺省是第一个角色
role[m_stMsg[Id].Param1].AddMagic(m_stMsg[Id].String1);
break;
case MSG_DELMAGIC: //添加魔法
if(m_stMsg[Id].Param1 == ERROR_DATA)
m_stMsg[Id].Param1 = 0; //缺省是第一个角色
role[m_stMsg[Id].Param1].DelMagic(m_stMsg[Id].String1);
break;
//------------------------NPC------------------------------------
case MSG_MOVENPCTO: //NPC移动
{
int num=map.GetNpcId(m_stMsg[Id].String1); //得到NPC的编号
if( num != -1 )
{
map.m_vNpc[num]->MoveTo(m_stMsg[Id].Param1*CellWidth,
m_stMsg[Id].Param2*CellHeight);
m_stMsg[Id].Param1=num; //保存,到BackMessage时使用
bControl=false; //不能控制
m_bMessageRunning=true; //等到NPC移动到位
}
}
break;
case MSG_MOVENPC: //NPC移动
{
int num=map.GetNpcId(m_stMsg[Id].String1);
if( num != -1 )
map.m_vNpc[num]->MoveTo(m_stMsg[Id].Param1*CellWidth,
m_stMsg[Id].Param2*CellHeight);
}
break;
case MSG_SETNPCPOS: //设置npc位置
{
int num=map.GetNpcId(m_stMsg[Id].String1);
if( num != -1 )
{
if( m_stMsg[Id].Param3 != ERROR_DATA )
map.Block[map.Width*map.m_vNpc[num]->State.Y+
map.m_vNpc[num]->State.X]=0;
map.m_vNpc[num]->State.x=map.m_vNpc[num]->State.oldx=
m_stMsg[Id].Param1*CellWidth+CellWidth/2;
map.m_vNpc[num]->State.y=map.m_vNpc[num]->State.oldy=
m_stMsg[Id].Param2*CellHeight+CellHeight/2;
//取格子坐标
map.m_vNpc[num]->State.X=map.m_vNpc[num]->State.oldX=
_grid_x(map.m_vNpc[num]->State.x);
map.m_vNpc[num]->State.Y=map.m_vNpc[num]->State.oldY=
_grid_y(map.m_vNpc[num]->State.y);
//阻挡
map.Block[map.Width*map.m_vNpc[num]->State.Y
+map.m_vNpc[num]->State.X]=1;
}
}
break;
case MSG_SETNPCDIR: //设置npc方向
{
int num=map.GetNpcId(m_stMsg[Id].String1);
if( num != -1 )
map.m_vNpc[num]->State.CurrentDir=m_stMsg[Id].Param1;
}
break;
case MSG_SETNPCSTEP: //设置npc步伐
{
int num=map.GetNpcId(m_stMsg[Id].String1);
if( num != -1 )
map.m_vNpc[num]->State.CurrentStep=m_stMsg[Id].Param1;
}
break;
case MSG_ADDNPC: //加入NPC
{
bool *BackCell=NULL;
int x=m_stMsg[Id].Param1;
int y=m_stMsg[Id].Param2;
//备份数据,地图阻挡关系
if( x != ERROR_DATA && y != ERROR_DATA )
{
BackCell=new bool[map.Width*map.Height];
for(int i=0; i<map.Width*map.Height; i++)
{
BackCell[i]=map.Block[i];
}
}
//添加
int num=map.AddNpc(m_stMsg[Id].String1, m_stMsg[Id].String2);
if( num != ERROR_DATA ) //位置
if( x != ERROR_DATA && y != ERROR_DATA )
{
//计算TILE坐标
int n=map.m_vNpc[num]->State.X+map.m_vNpc[num]->State.Y*map.Width;
//恢复阻挡
map.Block[n]=BackCell[n];
//脚底中心坐标
map.m_vNpc[num]->State.x=StartX+x*CellWidth+CellWidth/2;
map.m_vNpc[num]->State.y=StartY+y*CellHeight+CellHeight/2;
//现在位置的阻挡
map.Block[map.Width*y+x]=1;
//地图位置
map.m_vNpc[num]->State.X = map.m_vNpc[num]->State.oldX = x;
map.m_vNpc[num]->State.Y = map.m_vNpc[num]->State.oldY = y;
}
_DELETE( BackCell ); //释放
}
break;
case MSG_DELNPC: //删除NPC
{
int num=map.GetNpcId(m_stMsg[Id].String1);
if( num != -1 )
map.DelNpc(num);
}
break;
case MSG_SETNPCACTIVE: //设置NPC活动与否
if( m_stMsg[Id].Param3 == 1 ) //Param2是编号
{
map.m_vNpc[m_stMsg[Id].Param2]->State.bActive=m_stMsg[Id].Param1;
}
else //通过名字获取
{
int num=map.GetNpcId(m_stMsg[Id].String1);
if( num != -1 )
{
map.m_vNpc[num]->State.bActive=m_stMsg[Id].Param1;
}
}
break;
case MSG_SETNPCSHOW: //设置NPC活动与否
{
int num=map.GetNpcId(m_stMsg[Id].String1);
if( num != -1 )
map.m_vNpc[num]->State.bShow=m_stMsg[Id].Param1;
}
break;
case MSG_SETNPCSCRIPT: //设置NPC脚本文件
{
int num=map.GetNpcId(m_stMsg[Id].String1);
if( num != -1 )
strcpy(map.m_vNpc[num]->ScriptFile, m_stMsg[Id].String2);;
}
break;
//------------------------TOOLS-----------------------------------
case MSG_DELAY: //延时
bControl=false; //不能控制
m_bMessageRunning=true; //等待结束
m_stMsg[Id].Param2=timeGetTime(); //保存当前时间,等到BackMessage时使用
break;
case MSG_FADEIN: //淡入
{
int time=1;
WORD color;
//颜色
if( m_stMsg[Id].Param2 == ERROR_DATA )
color=0;
else
color=RGB16(m_stMsg[Id].Param2);
//延时
if( m_stMsg[Id].Param3 == ERROR_DATA )
{
if( m_stMsg[Id].Param1 == 1 )
time=20;
else
if( m_stMsg[Id].Param1 == 2 )
time=50;
}
else
time=m_stMsg[Id].Param3;
map.FadeIn(m_stMsg[Id].Param1, time, color);
}
break;
case MSG_FADEOUT: //淡出
{
int time=1;
//延时
if( m_stMsg[Id].Param2 == ERROR_DATA )
{
if( m_stMsg[Id].Param1 == 1 )
time=20;
else
if( m_stMsg[Id].Param1 == 2 )
time=50;
}
else
time=m_stMsg[Id].Param2;
map.FadeOut(m_stMsg[Id].Param1, time);
}
break;
case MSG_PLAYMUSIC: //播放背景音乐
{
Music.Stop();
WCHAR* str = WChar(m_stMsg[Id].String1);
Music.LoadMusic(str);
_DELETE( str );
Music.Play();
}
break;
case MSG_STOPMUSIC: //停止播放背景音乐
Music.Stop();
break;
case MSG_PAUSEMUSIC: //暂停音乐
Music.Pause();
break;
case MSG_RESUMEMUSIC: //恢复音乐
Music.Resume();
break;
case MSG_PLAYSOUND: //播放音效
Sound.LoadSoundFX( hWnd, m_stMsg[Id].String1 );
Sound.Play();
break;
case MSG_STOPSOUND: //停止播放
Sound.Stop();
break;
case MSG_GAMEMESSAGE: //显示一条游戏消息
GameMessage.DoMenu(lpDDSBack, m_stMsg[Id].String1);
break;
case MSG_SHOWMESSAGE: //显示一条消息
ShowMessage(m_stMsg[Id].String1, m_stMsg[Id].Param1,
m_stMsg[Id].Param2, m_stMsg[Id].Param3,
m_stMsg[Id].String2, m_stMsg[Id].String3);
break;
case MSG_SETCPTYPE:
map.SetCPType(m_stMsg[Id].Param1,m_stMsg[Id].Param2,m_stMsg[Id].Param3);
break;
}
return true;
}
//消息结束处理
bool CMessage::BackMessage()
{
switch( m_stMsg[m_nStartId].msg )
{
case MSG_SCROLLMAPTO: //卷动地图
if( g_ePlayState==PS_MAIN ) //卷动完成了会设置成PS_MAIN,参看Map.ScrollLoop()
{
bControl=true; //玩家可以控制
m_bMessageRunning=false; //可以执行下条消息
DeleteMessage(); //删除本消息
}
break;
case MSG_MOVE: //行走消息
case MSG_MOVEDIRECTTO:
if( role[0].bMoving==false ) //移动到位
{
bControl=true;
m_bMessageRunning=false;
DeleteMessage();
if(role[0].bCancelTalk)
{
if(m_stMsg[m_nStartId].msg == MSG_TALKDIR)
DeleteMessage();
}
}
break;
case MSG_MOVENPCTO: //NPC行走消息
//移动到位了
//m_stMsg[m_nStartId].Param1保存了NPC的ID,参看RunMessage的处理
if( map.m_vNpc[m_stMsg[m_nStartId].Param1]->bMoving==false )
{
bControl=true;
m_bMessageRunning=false;
DeleteMessage();
}
break;
case MSG_DELAY: //延时
//m_stMsg[m_nStartId].Param2保存了DELAY开始时的时间,参看RunMessage的处理
if( timeGetTime() - m_stMsg[m_nStartId].Param2 >=
(unsigned int)m_stMsg[m_nStartId].Param1 )
{
bControl=true;
m_bMessageRunning=false;
DeleteMessage();
}
break;
default: //缺省删除本条消息
DeleteMessage();
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -