/***********************************************************************
*Copyright (c)2012 , 天际边工作室
*All rights reserved.
**
文件名称：	ScriptEng.cpp
*摘要：		游戏脚本引擎
**
*修改历史：
*	版本    日期     作者     改动内容和原因
*   ----------------------------------------------------
*	1.0    2012-10-5  wstjb     基本的功能完成
***********************************************************************/
#define DEBUG_CLIENTBLOCK  new( _CLIENT_BLOCK, __FILE__, __LINE__)
#define _CRTDBG_MAP_ALLOC
#define new DEBUG_CLIENTBLOCK
#include "ScriptEng.h"

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

extern  PAINTSTRUCT ps;
extern 	HDC hdc;
extern 	HBITMAP hbmp; 
extern 	BITMAP bmp;
extern 	HBITMAP hbmp2; 
extern 	HDC hdcMem;
extern 	HDC hdcTmp;
extern 	RECT rect;
extern 	HWND hwnd;
extern int flag;
extern int tasknum;

extern int KeyReturn;
extern int KeyEsc;
extern int KeyHome;
extern int KeySpace;
extern int KeyLeft0;
extern int KeyUp0;
extern int KeyRight0;
extern int KeyDown0;
extern int KeyN;//20161221
extern int KeyPageUp;
extern int KeyPageDown;
extern int KeyInsert;
extern int KeyDelete;
extern int KeyHome;
extern int KeyEnd;

extern byte libByte[2097152];
extern byte resByte[2731][16384];//存储lib资源
extern int resByteLen[2731];
extern int resPos[2731][6];//存储lib地址和编号 第六位为长度
extern int resCount;
extern int tmp_order_msg_add;//20160730修正量
//extern SIZE size;
//extern HDC hdcPaint;
extern int g_debugFlag;//20161118
extern int g_dgdelayFlag;//20161217
int g_dgOrderPos;//20161217
extern int version_now;//20170115
extern int specialCallFlag;//特殊调用标志20170129
extern int finishflag;//特殊调用标志20170129
extern int runDebug;//20171003
extern char menu_money[6+1];//"金钱："
extern char menu_num[6+1];//"数量"
extern char menu_price[4+1];//"价"
extern char menu_name[4+1];//"名"
extern char menu_cost[6+1];//"耗真气"
extern char menu_degree[4+1];//"等级"
extern char menu_hp[4+1];//"生命"
extern char menu_mp[4+1];//"真气"
extern char menu_at[6+1];//"攻击力"
extern char menu_df[6+1];//"防御力"
extern char menu_exp[6+1];//"经验值"
extern char menu_speed[4+1];//"身法"
extern char menu_anima[4+1];//"灵力"
extern char menu_luck[4+1];//"幸运"
extern char menu_anti[4+1];//menu_anti
extern int noReadScript;//20170131
extern int allowSave;//20170319

extern int SRPUsed;

void ScriptEng::Init()
{
	keytmp = 0;
	callStackDeep= 0;
	orderChoiceJmpPos = 0;
	orderPos = 0;
	keyflag = 0;
	keyflag2 = 0;
	keyflag21 = 0;
	keyflag31 = 0;
	keyflag32 = 0;
	keyflag33 = 0;
	keyflag34 = 0;
	keyflag431 = 0;
	keyflag432 = 0;
	keyflag433 = 0;
	keyflag5 = 0;
	keyflag51 = 0;
	keyflag52 = 0;
	keyflagfight = 0;
	keyflag332 = 0;

	dgbreakpointmax = 0;
	keyflagret = 0;
	saveEnable = 1;
	fightEnable = 0;//可
	InitCommandParam();
	InitValue();
	//map = new Map();
	memset(&map,0,sizeof(&map));
	map.Init();
	//menu = new Menu();
	memset(&menu,0,sizeof(&menu));
	menu.Init(0,0,0,0,0);
	//secondmenu1 = new Menu();
	memset(&secondmenu1,0,sizeof(&secondmenu1));
	secondmenu1.Init(0,0,0,0,0);
	//secondmenu2 = new Menu();
	memset(&secondmenu2,0,sizeof(&secondmenu2));
	secondmenu2.Init(0,0,0,0,0);
	//secondmenu3 = new Menu();
	memset(&secondmenu3,0,sizeof(&secondmenu3));
	secondmenu3.Init(0,0,0,0,0);
	//secondmenu4 = new Menu();
	memset(&secondmenu4,0,sizeof(&secondmenu4));
	secondmenu4.Init(0,0,0,0,0);
	//thirdmenu1 = new Menu();
	memset(&thirdmenu1,0,sizeof(&thirdmenu1));
	thirdmenu1.Init(0,0,0,0,0);
	memset(&thirdmenu2,0,sizeof(&thirdmenu2));
	thirdmenu2.Init(0,0,0,0,0);
	if(initsaveflag==0)
	{
		//save = new Save();
		memset(&save,0,sizeof(&save));
		save.Init(0);
	}
	initsaveflag = 0;
	memcpy(save.gameName,libByte+3,8);
	del_sp(save.gameName);
	//fight = new Fight();
	memset(&fight,0,sizeof(&fight));
	fight.Init(0,0,0);
	//roleList = new RoleList();
	memset(&roleList,0,sizeof(&roleList));
	roleList.Init();
	memset(magicList,0,sizeof(magicList));
	for(int i = 0 ;i < 255 ; i ++)
	{
		//magicList[i] = new MagicList();
		magicList[i].Init(i+1);

	}
	for(int i = 0 ;i < 25 ; i ++)//20170116修正为25
	{
		//magicList[i] = new MagicList();
		actorMagicList[i].Init(roleList.actor[i].magicListNo);

	}
	memset(degreeList,0,sizeof(degreeList));
	for(int i = 0 ;i < 25 ; i ++)
	{
		//degreeList[i] = new DegreeList();
		degreeList[i].Init(i+1);

	}
	//goodList = new GoodList();
	memset(&goodList,0,sizeof(&goodList));
	goodList.Init();
	//sayBox = new SayBox();
	memset(&sayBox,0,sizeof(&sayBox));
	sayBox.Init(0);
	//gameMenu = new GameMenu();
	memset(&gameMenu,0,sizeof(&gameMenu));
	gameMenu.Init(0,0,0,0,0,"",0);

};

void ScriptEng::InitCommandParam()
{
#if 1
	for(int i = 0;i<78;i++)
	{
		for(int j = 0; j<20;j++)
		{
			command[i][j] = 0;
		}
	}

	command[0][0] = 5;
	command[0][1] = 5;

	command[1][0] = 5;
	command[1][1] = 5;
	command[1][2] = 5;
	command[1][3] = 5;

	command[2][0] = 5;
	command[2][1] = 5;
	command[2][2] = 5;

	command[3][0] = 5;

	command[4][0] = 5;
	command[4][1] = 5;
	command[4][2] = 5;
	command[4][3] = 5;
	command[4][4] = 5;
	command[4][5] = 5;

	command[5][0] = 5;
	command[5][1] = 1;

	command[6][0] = 5;
	command[6][1] = 5;
	command[6][2] = 5;

	command[7][0] = 5;
	command[7][1] = 5;
	command[7][2] = 5;
	command[7][3] = 5;
	command[7][4] = 5;
	command[7][5] = 5;

	command[8][0] = 5;
	command[8][1] = 5;

	command[10][1] = 1;

	command[11][0] = 5;
	command[11][1] = 1;

	command[12][0] = 5;
	command[12][1] = 5;

	command[13][0] = 5;
	command[13][1] = 2;

	command[14][0] = 5;
	command[14][1] = 5;

	command[15][0] = 5;

	command[16][0] = 5;
	command[16][1] = 5;

	command[17][0] = 5;

	command[18][0] = 5;
	command[18][1] = 1;

	command[19][0] = 5;

	command[21][0] = 5;
	command[21][1] = 5;
	command[21][2] = 1;

	command[22][0] = 5;
	command[22][1] = 5;

	command[23][0] = 5;
	command[23][1] = 5;

	command[24][0] = 5;

	command[25][0] = 5;
	command[25][1] = 3;

	command[26][0] = 5;

	command[27][0] = 5;

	command[28][0] = 6;

	command[29][0] = 5;
	command[29][1] = 5;

	command[30][0] = 5;
	command[30][1] = 5;
	command[30][2] = 5;
	command[30][3] = 5;
	command[30][4] = 5;

	command[31][0] = 2;
	command[31][1] = 2;
	command[31][2] = 1;

	command[32][0] = 5;
	command[32][1] = 5;
	command[32][2] = 5;
	command[32][3] = 5;

	command[33][0] = 5;

	command[34][0] = 5;
	command[34][1] = 5;

	command[35][0] = 5;
	command[35][1] = 5;
	command[35][2] = 5;
	command[35][3] = 5;
	command[35][4] = 5;
	command[35][5] = 5;
	command[35][6] = 5;
	command[35][7] = 5;
	command[35][8] = 5;
	command[35][9] = 5;
	command[35][10] = 5;

	command[38][0] = 5;
	command[38][1] = 5;
	command[38][2] = 5;
	command[38][3] = 5;

	command[39][0] = 5;
	command[39][1] = 5;
	command[39][2] = 5;
	command[39][3] = 5;
	command[39][4] = 5;
	command[39][5] = 5;
	command[39][6] = 5;
	command[39][7] = 5;
	command[39][8] = 5;
	command[39][9] = 5;
	command[39][10] = 5;
	command[39][11] = 5;
	command[39][12] = 5;
	command[39][13] = 1;
	command[39][14] = 1;

	command[40][0] = 5;

	command[41][0] = 4;

	command[42][0] = 4;

	command[43][0] = 4;

	command[44][0] = 5;
	command[44][1] = 5;
	command[44][2] = 5;

	command[46][0] = 5;
	command[46][1] = 5;

	command[47][0] = 2;

	command[48][0] = 5;
	command[48][1] = 5;
	command[48][2] = 1;

	command[49][0] = 5;
	command[49][1] = 5;

	command[50][0] = 5;
	command[50][1] = 5;

	command[51][0] = 5;

	command[53][0] = 5;
	command[53][1] = 5;
	command[53][2] = 5;

	command[54][0] = 2;

	command[57][0] = 5;
	command[57][1] = 5;
	command[57][2] = 2;

	command[58][0] = 5;
	command[58][1] = 5;
	command[58][2] = 5;
	command[58][3] = 1;
	command[58][4] = 1;

	command[59][0] = 5;
	command[59][1] = 5;
	command[59][2] = 5;

	command[60][0] = 5;
	command[60][1] = 5;
	command[60][2] = 5;

	command[61][0] = 5;
	command[61][1] = 5;
	command[61][2] = 2;

	command[62][0] = 5;
	command[62][1] = 5;
	command[62][2] = 5;
	command[62][3] = 1;

	command[63][0] = 5;
	command[63][0] = 1;

	command[64][0] = 5;
	command[64][0] = 2;

	command[65][0] = 4;
	command[65][0] = 1;

	command[66][0] = 5;
	command[66][1] = 5;

	command[67][0] = 5;
	command[67][1] = 5;
	command[67][2] = 1;
	command[67][3] = 1;

	command[69][0] = 5;
	command[69][1] = 2;

	command[73][0] = 5;
	command[73][1] = 5;

	command[76][0] = 5;
	command[76][1] = 5;

	command[77][0] = 5;
	command[77][1] = 5;
	command[77][2] = 1;
	command[77][3] = 1;

#endif

}

void ScriptEng::InitValue()
{
	for(int i = 0; i< 2400;i++)
	{
		globalEvent[i] = 0;//存储事件
	}
	for(int i = 0; i< 240;i++)
	{
		globalValue[i] = 0;//存储变量
	}
	money = 0;

	posEnable = 0;
}

void ScriptEng::Show(WPARAM KeyCode)
{

	char tmp[20];
	int act[3];
	int j = 0;
	if(keyflagfight == 1)//战斗界面
	{
		fight.Show(0);
		return;
	}
	else if(keyflag == 1)//20160816新增 saybox
	{
		sayBox.Show(0);
		return;
	}
	else if(keyflag21 == 1)//显示技能使用比较界面
	{
		for(int i = 0;i<25;i++)
		{
			if(roleList.actor[i].inRankFlag == 1)
			{
				int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
				act[k] = i;

				j++;
			}
		}

		int magicType = actorMagicList[act[selectedRoleIdx]].magic[selectedMagic].type;
		int magicIdx =  actorMagicList[act[selectedRoleIdx]].magic[selectedMagic].no;

		ClrScence();

		ShowHeadPic(0,act[act[attFlag2]]+1,10,62);

		//显示法术名称
		char tmp1[4+1];
		memset(tmp1,0,sizeof(tmp1));
		memcpy(tmp1,actorMagicList[act[selectedRoleIdx]].magic[selectedMagic].name,4);
		sprintf_s(tmp,"%s",tmp1);
		ShowText(tmp,6,6);
		memset(tmp1,0,sizeof(tmp1));
		memcpy(tmp1,actorMagicList[act[selectedRoleIdx]].magic[selectedMagic].name+4,4);
		sprintf_s(tmp,"%s",tmp1);
		ShowText(tmp,6,22);
		memset(tmp1,0,sizeof(tmp1));
		memcpy(tmp1,actorMagicList[act[selectedRoleIdx]].magic[selectedMagic].name+8,4);
		sprintf_s(tmp,"%s",tmp1);
		ShowText(tmp,6,38);

		if(j < 3 && attFlag2 > (j - 1))
		{
			attFlag2 = 0;
		}


		MoveToEx(hdcTmp,40,10,NULL);
		LineTo(hdcTmp,40,86);

		if(attFlag == 0)
		{
			ShowText(menu_degree,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].degree);
			if(roleList.actor[act[attFlag2]].degree == degreeList[act[attFlag2]].degreeMax)
			{
				sprintf_s(tmp,"MAX");
			}
			ShowText(tmp,100,5);
			ShowText(menu_hp,45,23);
			sprintf_s(tmp,"%d/%d",roleList.actor[act[attFlag2]].hp,roleList.actor[act[attFlag2]].hpMax);
			ShowText(tmp,100,23);
			ShowText(menu_mp,45,41);
			sprintf_s(tmp,"%d/%d",roleList.actor[act[attFlag2]].mp,roleList.actor[act[attFlag2]].mpMax);
			ShowText(tmp,100,41);
			ShowText(menu_at,45,59);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].att);
			ShowText(tmp,100,59);
			ShowText(menu_df,45,77);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].def);
			ShowText(tmp,100,77);
		}
		else
		{
			ShowText(menu_exp,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].exp);
			int tmplen = strlen(tmp);
			ShowText("/",100+tmplen*5,5);
			ShowText(tmp,100,5,10);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].expMax);
			ShowText(tmp,100+tmplen*5+5,9,10);//20161231修正
			ShowText(menu_speed,45,23);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].speed);
			ShowText(tmp,100,23);
			ShowText(menu_anima,45,41);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].anima);
			ShowText(tmp,100,41);
			ShowText(menu_luck,45,59);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].lucky);
			ShowText(tmp,100,59);
			ShowText(menu_anti,45,77);
			if(roleList.actor[act[attFlag2]].anti == 0)
			{
				ShowText("无",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 8)
			{
				ShowText("毒",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 4)
			{
				ShowText("乱",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 2)
			{
				ShowText("封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 1)
			{
				ShowText("眠",96,77);

			}
			else if(roleList.actor[act[attFlag2]].anti == 12)
			{
				ShowText("毒乱",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 10)
			{
				ShowText("毒封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 9)
			{
				ShowText("毒眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 5)
			{
				ShowText("乱眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 3)
			{
				ShowText("封眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 14)
			{
				ShowText("毒乱封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 13)
			{
				ShowText("毒乱眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 11)
			{
				ShowText("毒封眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 7)
			{
				ShowText("乱封眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 15)
			{
				ShowText("毒乱封眠",96,77);
			}
		}
		return;
	}
	if(keyflag431 == 1 )//显示使用道具比较界面 
	{

		int goodType = goodList.goodInList[selectedGood][0];//20160901
		int goodIdx = goodList.goodInList[selectedGood][1];//20160901
		int goodSum = goodList.goodInList[selectedGood][2];//20160901
		ClrScence();
		for(int i = 0;i<25;i++)
		{
			if(roleList.actor[i].inRankFlag == 1)
			{
				int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
				act[k] = i;

				j++;
			}
		}
		ShowHeadPic(0,act[attFlag2]+1,10,62);

		ShowGoodPic(0,goodType,goodIdx,10,2);
		//ShowGoodPic(0,goodType,goodIdx,10,32);

		sprintf_s(tmp,"%d",goodSum);
		ShowText(tmp,12,32);

		if(j < 3 && attFlag2 > (j - 1))
		{
			attFlag2 = 0;
		}

		/*MoveToEx(hdcTmp,1,10+attFlag2*30,NULL);
		LineTo(hdcTmp,1,25+attFlag2*30);
		MoveToEx(hdcTmp,2,11+attFlag2*30,NULL);
		LineTo(hdcTmp,2,24+attFlag2*30);
		MoveToEx(hdcTmp,3,12+attFlag2*30,NULL);
		LineTo(hdcTmp,3,23+attFlag2*30);
		MoveToEx(hdcTmp,4,13+attFlag2*30,NULL);
		LineTo(hdcTmp,4,22+attFlag2*30);
		MoveToEx(hdcTmp,5,14+attFlag2*30,NULL);
		LineTo(hdcTmp,5,21+attFlag2*30);
		MoveToEx(hdcTmp,6,15+attFlag2*30,NULL);
		LineTo(hdcTmp,6,20+attFlag2*30);
		MoveToEx(hdcTmp,7,16+attFlag2*30,NULL);
		LineTo(hdcTmp,7,19+attFlag2*30);
		MoveToEx(hdcTmp,8,17+attFlag2*30,NULL);
		LineTo(hdcTmp,8,18+attFlag2*30);
		MoveToEx(hdcTmp,40,10,NULL);
		LineTo(hdcTmp,40,86);*/

		if(attFlag == 0)
		{
			ShowText(menu_degree,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].degree);
			if(roleList.actor[act[attFlag2]].degree == degreeList[act[attFlag2]].degreeMax)
			{
				sprintf_s(tmp,"MAX");
			}
			ShowText(tmp,100,5);
			ShowText(menu_hp,45,23);
			sprintf_s(tmp,"%d/%d",roleList.actor[act[attFlag2]].hp,roleList.actor[act[attFlag2]].hpMax);
			ShowText(tmp,100,23);
			ShowText(menu_mp,45,41);
			sprintf_s(tmp,"%d/%d",roleList.actor[act[attFlag2]].mp,roleList.actor[act[attFlag2]].mpMax);
			ShowText(tmp,100,41);
			ShowText(menu_at,45,59);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].att);
			ShowText(tmp,100,59);
			ShowText(menu_df,45,77);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].def);
			ShowText(tmp,100,77);
		}
		else
		{
			ShowText(menu_exp,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].exp);
			int tmplen = strlen(tmp);
			ShowText("/",100+tmplen*5,5);
			ShowText(tmp,100,5,10);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].expMax);
			ShowText(tmp,100+tmplen*5+5,9,10);//20161231修正
			ShowText(menu_speed,45,23);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].speed);
			ShowText(tmp,100,23);
			ShowText(menu_anima,45,41);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].anima);
			ShowText(tmp,100,41);
			ShowText(menu_luck,45,59);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].lucky);
			ShowText(tmp,100,59);
			ShowText(menu_anti,45,77);
			if(roleList.actor[act[attFlag2]].anti == 0)
			{
				ShowText("无",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 8)
			{
				ShowText("毒",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 4)
			{
				ShowText("乱",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 2)
			{
				ShowText("封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 1)
			{
				ShowText("眠",96,77);

			}
			else if(roleList.actor[act[attFlag2]].anti == 12)
			{
				ShowText("毒乱",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 10)
			{
				ShowText("毒封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 9)
			{
				ShowText("毒眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 5)
			{
				ShowText("乱眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 3)
			{
				ShowText("封眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 14)
			{
				ShowText("毒乱封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 13)
			{
				ShowText("毒乱眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 11)
			{
				ShowText("毒封眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 7)
			{
				ShowText("乱封眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 15)
			{
				ShowText("毒乱封眠",96,77);
			}
		}
		return;
	}
	else if(keyflag432 == 1)//显示装备装备比较界面
	{


		int equipType = goodList.equipInList[selectedGood][0];
		int equipIdx = goodList.equipInList[selectedGood][1];

		int equipType1 = goodList.equipInList[selectedGood][0];
		int equipIdx1 = 0;
		int usedecorateflag = 0;

		for(int i = 0;i<25;i++)
		{
			if(roleList.actor[i].inRankFlag == 1)
			{
				int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
				act[k] = i;

				j++;
			}
		}

		if(equipType1 == 1)//head
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].head;
		}
		if(equipType1 == 2)//body
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].body;
		}
		if(equipType1 == 3)//foot
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].foot;
		}
		if(equipType1 == 4)//shoulder
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].shoulder;
		}
		if(equipType1 == 5)//sleeve
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].sleeve;
		}
		if(equipType1 == 6 )//decorate1 20160228
		{
			if( decorateflag == 0 )
			{
				if(roleList.actor[act[selectedRoleIdx]].decorate1!=0&&roleList.actor[act[selectedRoleIdx]].decorate2!=0)
				{
					equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
					usedecorateflag = 1;
				}
				else if(roleList.actor[act[selectedRoleIdx]].decorate1!=0)
				{
					equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate2;
					usedecorateflag = 2;
				}
				else if(roleList.actor[act[selectedRoleIdx]].decorate1==0)
				{
					equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
					usedecorateflag = 1;
				}
			}
			else if( decorateflag == 0 && equipIdx1==0)
			{
				equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
				usedecorateflag = 1;
			}
			else if( decorateflag == 1 )
			{
				equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
				usedecorateflag = 1;
			}
			else if( decorateflag == 2 )
			{
				equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate2;
				usedecorateflag = 2;
			}
		}
		if(equipType1 == 7)//hand
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].hand;//20161231替换selectedRoleIdx
		}

		ClrScence();
		/*for(int i = 0;i<25;i++)
		{
		if(roleList.actor[i].inRankFlag == 1)
		{
		act[j] = i;

		j++;
		}
		}*/
		ShowHeadPic(0,act[selectedRoleIdx]+1,10,62);

		ShowGoodPic(0,equipType,equipIdx,10,2);
		if(equipIdx1!=0)ShowGoodPic(0,equipType1,equipIdx1,10,32);



		MoveToEx(hdcTmp,1,10+attFlag2*30,NULL);
		LineTo(hdcTmp,1,25+attFlag2*30);
		MoveToEx(hdcTmp,2,11+attFlag2*30,NULL);
		LineTo(hdcTmp,2,24+attFlag2*30);
		MoveToEx(hdcTmp,3,12+attFlag2*30,NULL);
		LineTo(hdcTmp,3,23+attFlag2*30);
		MoveToEx(hdcTmp,4,13+attFlag2*30,NULL);
		LineTo(hdcTmp,4,22+attFlag2*30);
		MoveToEx(hdcTmp,5,14+attFlag2*30,NULL);
		LineTo(hdcTmp,5,21+attFlag2*30);
		MoveToEx(hdcTmp,6,15+attFlag2*30,NULL);
		LineTo(hdcTmp,6,20+attFlag2*30);
		MoveToEx(hdcTmp,7,16+attFlag2*30,NULL);
		LineTo(hdcTmp,7,19+attFlag2*30);
		MoveToEx(hdcTmp,8,17+attFlag2*30,NULL);
		LineTo(hdcTmp,8,18+attFlag2*30);
		MoveToEx(hdcTmp,40,10,NULL);
		LineTo(hdcTmp,40,86);

		if(attFlag == 0 && attFlag2 == 1) 
		{
			ShowText(menu_degree,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].degree);
			if(roleList.actor[act[selectedRoleIdx]].degree == degreeList[act[selectedRoleIdx]].degreeMax)//20170806修正
			{
				sprintf_s(tmp,"MAX");
			}
			ShowText(tmp,100,5);
			ShowText(menu_hp,45,23);
			sprintf_s(tmp,"%d/%d",roleList.actor[act[selectedRoleIdx]].hp,roleList.actor[act[selectedRoleIdx]].hpMax);
			ShowText(tmp,100,23);
			ShowText(menu_mp,45,41);
			sprintf_s(tmp,"%d/%d",roleList.actor[act[selectedRoleIdx]].mp,roleList.actor[act[selectedRoleIdx]].mpMax);
			ShowText(tmp,100,41);
			ShowText(menu_at,45,59);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].att);
			ShowText(tmp,100,59);
			ShowText(menu_df,45,77);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].def);
			ShowText(tmp,100,77);
		}
		else if(attFlag == 1 && attFlag2 == 1)
		{
			ShowText(menu_exp,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].exp);
			int tmplen = strlen(tmp);
			ShowText("/",100+tmplen*5,5);
			ShowText(tmp,100,5,10);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].expMax);
			ShowText(tmp,100+tmplen*5+5,9,10);//20161231修正
			ShowText(menu_speed,45,23);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].speed);
			ShowText(tmp,100,23);
			ShowText(menu_anima,45,41);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].anima);
			ShowText(tmp,100,41);
			ShowText(menu_luck,45,59);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].lucky);
			ShowText(tmp,100,59);
			ShowText(menu_anti,45,77);
			if(roleList.actor[act[selectedRoleIdx]].anti == 0)
			{
				ShowText("无",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 8)
			{
				ShowText("毒",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 4)
			{
				ShowText("乱",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 2)
			{
				ShowText("封",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 1)
			{
				ShowText("眠",96,77);

			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 12)
			{
				ShowText("毒乱",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 10)
			{
				ShowText("毒封",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 9)
			{
				ShowText("毒眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 5)
			{
				ShowText("乱眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 3)
			{
				ShowText("封眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 14)
			{
				ShowText("毒乱封",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 13)
			{
				ShowText("毒乱眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 11)
			{
				ShowText("毒封眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 7)
			{
				ShowText("乱封眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 15)
			{
				ShowText("毒乱封眠",96,77);
			}
		}
		else if(attFlag == 0 && attFlag2 == 0)
		{
			ShowText(menu_degree,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].degree);
			if(roleList.actor[act[attFlag2]].degree == degreeList[act[attFlag2]].degreeMax)
			{
				sprintf_s(tmp,"MAX");
			}
			ShowText(tmp,100,5);
			ShowText(menu_hp,45,23);
			int itmp,itmp1;
			itmp = roleList.actor[act[selectedRoleIdx]].hp + goodList.good[equipType-1][equipIdx-1].hp - goodList.good[equipType1-1][equipIdx1-1].hp;
			itmp1 = roleList.actor[act[selectedRoleIdx]].hpMax + goodList.good[equipType-1][equipIdx-1].hpmax - goodList.good[equipType1-1][equipIdx1-1].hpmax;
			sprintf_s(tmp,"%d/%d",itmp,itmp1);
			ShowText(tmp,100,23);
			ShowText(menu_mp,45,41);
			itmp = roleList.actor[act[selectedRoleIdx]].mp + goodList.good[equipType-1][equipIdx-1].mp - goodList.good[equipType1-1][equipIdx1-1].mp;
			itmp1 = roleList.actor[act[selectedRoleIdx]].mpMax + goodList.good[equipType-1][equipIdx-1].mpmax - goodList.good[equipType1-1][equipIdx1-1].mpmax;
			sprintf_s(tmp,"%d/%d",itmp,itmp1);
			ShowText(tmp,100,41);
			ShowText(menu_at,45,59);
			itmp = roleList.actor[act[selectedRoleIdx]].att + goodList.good[equipType-1][equipIdx-1].at - goodList.good[equipType1-1][equipIdx1-1].at;
			sprintf_s(tmp,"%d",itmp);
			ShowText(tmp,100,59);
			ShowText(menu_df,45,77);
			itmp = roleList.actor[act[selectedRoleIdx]].def + goodList.good[equipType-1][equipIdx-1].df - goodList.good[equipType1-1][equipIdx1-1].df;
			sprintf_s(tmp,"%d",itmp);
			ShowText(tmp,100,77);
		}
		else if(attFlag == 1 && attFlag2 == 0)
		{
			ShowText(menu_exp,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].exp);
			int tmplen = strlen(tmp);
			ShowText("/",100+tmplen*5,5);
			ShowText(tmp,100,5,10);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].expMax);
			ShowText(tmp,100+tmplen*5+5,9,10);//20161231修正
			int itmp;
			itmp = roleList.actor[act[selectedRoleIdx]].speed + goodList.good[equipType-1][equipIdx-1].speed - goodList.good[equipType1-1][equipIdx1-1].speed;
			ShowText(menu_speed,45,23);
			sprintf_s(tmp,"%d",itmp);
			ShowText(tmp,100,23);
			ShowText(menu_anima,45,41);
			itmp = roleList.actor[act[selectedRoleIdx]].anima + goodList.good[equipType-1][equipIdx-1].anima - goodList.good[equipType1-1][equipIdx1-1].anima;
			sprintf_s(tmp,"%d",itmp);
			ShowText(tmp,100,41);
			ShowText(menu_luck,45,59);
			itmp = roleList.actor[act[selectedRoleIdx]].lucky + goodList.good[equipType-1][equipIdx-1].lucky - goodList.good[equipType1-1][equipIdx1-1].lucky;
			sprintf_s(tmp,"%d",itmp);
			ShowText(tmp,100,59);
			ShowText(menu_anti,45,77);

			//20170107
			/*int tmp1 = 0;
			if(roleList.actor[act[selectedRoleIdx]].anti > 0)
			{

			if(roleList.actor[act[selectedRoleIdx]].anti  /8 > 0 && goodList.good[equipType-1][equipIdx-1].all_dlfm_Flag /8 > 0)
			{
			tmp1 += 8;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti  %8/4 > 0 && goodList.good[equipType-1][equipIdx-1].all_dlfm_Flag %8/4 > 0)
			{
			tmp1 += 4;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti  %4/2 > 0 && goodList.good[equipType-1][equipIdx-1].all_dlfm_Flag %4/2 > 0)
			{
			tmp1 += 2;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti %2 > 0 && goodList.good[equipType-1][equipIdx-1].all_dlfm_Flag %2 > 0)
			{
			tmp1 += 1;
			}
			}

			//20170319
			if(equipType < 6)//非饰品、武器
			{
			itmp = roleList.actor[act[selectedRoleIdx]].anti + goodList.good[equipType-1][equipIdx-1].all_dlfm_Flag - goodList.good[equipType1-1][equipIdx1-1].all_dlfm_Flag;
			}
			else //武器
			{
			itmp = roleList.actor[act[selectedRoleIdx]].anti ;
			}
			if(itmp > 15) itmp -= tmp1;*/

			//20181007
			int tmp1 = 0;
			//CheckAntiCauseBy检测角色anti是否由该物品引起，0-不是 1-是  1-4毒乱封眠

			//usedecorateflag
			if(roleList.actor[act[selectedRoleIdx]].anti/ 8 > 0 && CheckAntiCauseBy(1,equipType1-1,equipIdx1-1,usedecorateflag)== 1)
			{
				tmp1 += 8;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti%8/4 > 0 && CheckAntiCauseBy(2,equipType1-1,equipIdx1-1,usedecorateflag)== 1)
			{
				tmp1 += 4;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti%4/2 > 0 && CheckAntiCauseBy(3,equipType1-1,equipIdx1-1,usedecorateflag)== 1)
			{
				tmp1 += 2;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti%2 > 0 && CheckAntiCauseBy(4,equipType1-1,equipIdx1-1,usedecorateflag)== 1)
			{
				tmp1 += 1;
			}
			if(equipType < 6)//非饰品、武器20181230
			{
				itmp = roleList.actor[act[selectedRoleIdx]].anti + goodList.good[equipType-1][equipIdx-1].all_dlfm_Flag - tmp1;
			}
			else
			{
				itmp = roleList.actor[act[selectedRoleIdx]].anti ;
			}

			if(itmp <0 || itmp > 15)itmp = 0;


			if(itmp== 0)
			{
				ShowText("无",96,77);
			}
			else if(itmp == 8)
			{
				ShowText("毒",96,77);
			}
			else if(itmp == 4)
			{
				ShowText("乱",96,77);
			}
			else if(itmp == 2)
			{
				ShowText("封",96,77);
			}
			else if(itmp == 1)
			{
				ShowText("眠",96,77);

			}
			else if(itmp == 12)
			{
				ShowText("毒乱",96,77);
			}
			else if(itmp == 10)
			{
				ShowText("毒封",96,77);
			}
			else if(itmp == 9)
			{
				ShowText("毒眠",96,77);
			}
			else if(itmp == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(itmp == 5)
			{
				ShowText("乱眠",96,77);
			}
			else if(itmp == 3)
			{
				ShowText("封眠",96,77);
			}
			else if(itmp == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(itmp == 14)
			{
				ShowText("毒乱封",96,77);
			}
			else if(itmp == 13)
			{
				ShowText("毒乱眠",96,77);
			}
			else if(itmp == 11)
			{
				ShowText("毒封眠",96,77);
			}
			else if(itmp == 7)
			{
				ShowText("乱封眠",96,77);
			}
			else if(itmp == 15)
			{
				ShowText("毒乱封眠",96,77);
			}
		}
		return;
	}
	else if(keyflag433 == 1)//显示装备界面道具信息界面
	{

		//ClrScence();

		Rectangle(hdcTmp,8,10,100,30);
		Rectangle(hdcTmp,8,30,148,68);



		ShowText(goodList.good[selectedEquipType][selectedEquipId].name,10,12);



		char showedText[17][17];
		char text[102];
		int textLen = 0;
		int linestart = 0;
		int lineCount = 0;

		for(int u = 0; u < 102;u++)
		{
			text[u] = ' ';
		}
		for(int u = 0; u < 102;u++)
		{
			if(goodList.good[selectedEquipType][selectedEquipId].description[u]=='\0')
			{
				textLen = u;
				break;
			}
			text[u] = goodList.good[selectedEquipType][selectedEquipId].description[u];
		}

		int v = 0;
		for(v = 0;v<17;v++)
		{

			int p=0;
			for(int k = 0 ;k<16;k++)//20160625
			{
				if((int)text[linestart+k] < 128 && (int)text[linestart+k] >= 0)//单字节字符
				{
					p++;
				}
			}
			if(p%2==0)//双字节
			{
				memcpy(showedText[v],&text[linestart],16);
				showedText[v][16]='\0';
				showedText[v+1][0]='\0';
				linestart+=16;
			}
			else
			{
				memcpy(showedText[v],&text[linestart],15);
				showedText[v][15]='\0';
				showedText[v+1][0]='\0';
				linestart+=15;
			}
			if(linestart>=textLen)
			{
				lineCount = v + 1;
				break;
			}


		}
		if(attFlag2 >= (lineCount -1) )
		{
			attFlag2 = lineCount - 2;
		}
		if(attFlag2 <0 )
		{
			attFlag2 = 0;
		}
		ShowText(showedText[attFlag2],10,32);
		ShowText(showedText[attFlag2+1],10,48);

		return;

	}
	else if(keyflag433 == 2)//显示装备
	{
		char tmp[20];
		ClrScence();
		MoveToEx(hdcTmp,140,21,NULL);
		LineTo(hdcTmp,42,21);
		MoveToEx(hdcTmp,140,0,NULL);
		LineTo(hdcTmp,55,0);
		MoveToEx(hdcTmp,140,20,NULL);
		LineTo(hdcTmp,59,20);

		LineTo(hdcTmp,39,0);
		LineTo(hdcTmp,6,0);
		LineTo(hdcTmp,0,6);
		LineTo(hdcTmp,0,95);
		LineTo(hdcTmp,41,95);
		LineTo(hdcTmp,41,22);
		MoveToEx(hdcTmp,42,95,NULL);
		LineTo(hdcTmp,42,22);
		Rectangle(hdcTmp,43,22,158,58);
		Rectangle(hdcTmp,43,59,158,96);

		MoveToEx(hdcTmp,140,57,NULL);
		LineTo(hdcTmp,42,58);

		ShowText(menu_num,60,3);

		int goodType = selectedEquipType;
		int goodIdx[100];
		int goodSum[100];
		int _j = 0;//20170115
		for(int i = 0 ; i<100;i++)
		{
			goodNo[i] = -1;
		}
		for(int i = 0; i < goodList.equipInListCount ;i++)
		{
			if(goodList.equipInList[i][0] == selectedEquipType + 1)
			{
				goodIdx[_j]= goodList.equipInList[i][1] - 1;
				goodSum[_j]= goodList.equipInList[i][2];
				goodNo[_j]= i;
				_j++;
			}
		}

		if(_j == 0)
		{
			keyflag433 = 0;
			attFlag2 = selectedRoleIdx;
			Show(0);
			return;
		}

		if(attFlag2 >= _j)
		{
			attFlag2 = _j -1 ;
		}

		selectedNewEquipId = goodIdx[attFlag2];

		sprintf_s(tmp,"%d",goodSum[attFlag2]);
		ShowText(tmp,100,3);
		ShowText(menu_name,47,24);
		ShowText(goodList.good[goodType][goodIdx[attFlag2]].name,71,24);

		ShowText(menu_price,47,41);
		sprintf_s(tmp,"%d",goodList.good[goodType][goodIdx[attFlag2]].sell);
		ShowText(tmp,71,41);

		int max = _j>4?3:_j - 1;

		if(flagd==1&&KeyCode==KeyDown0)
		{
			showPos=max;

		}
		else if(flagu==1&&KeyCode==KeyUp0)
		{
			showPos=0;

		}
		else if(flagd==1&&KeyCode==KeyUp0)
		{
			flagd=0;
			showPos--;
		}
		else if(flagu==1&&KeyCode==KeyDown0)
		{
			flagu=0;
			showPos++;
		}
		else if(KeyCode==KeyUp0)
		{
			showPos--;
		}
		else if(KeyCode==KeyDown0)
		{
			showPos++;
		}
		if(showPos==max)flagd=1;
		if(showPos==0)flagu=1;



		if(showPos == 0)
		{
			if(goodNo[attFlag2]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2]][0],goodList.equipInList[goodNo[attFlag2]][1],13,24*0);
			if(goodNo[attFlag2+1]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2+1]][0],goodList.equipInList[goodNo[attFlag2+1]][1],13,24*1);
			if(goodNo[attFlag2+2]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2+2]][0],goodList.equipInList[goodNo[attFlag2+2]][1],13,24*2);
			if(goodNo[attFlag2+3]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2+3]][0],goodList.equipInList[goodNo[attFlag2+3]][1],13,24*3);
		}
		else if(showPos == 1)
		{
			if(goodNo[attFlag2-1]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2-1]][0],goodList.equipInList[goodNo[attFlag2-1]][1],13,24*0);
			if(goodNo[attFlag2+0]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2+0]][0],goodList.equipInList[goodNo[attFlag2+0]][1],13,24*1);
			if(goodNo[attFlag2+1]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2+1]][0],goodList.equipInList[goodNo[attFlag2+1]][1],13,24*2);
			if(goodNo[attFlag2+2]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2+2]][0],goodList.equipInList[goodNo[attFlag2+2]][1],13,24*3);
		}
		else if(showPos == 2)
		{
			if(goodNo[attFlag2-2]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2-2]][0],goodList.equipInList[goodNo[attFlag2-2]][1],13,24*0);
			if(goodNo[attFlag2-1]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2-1]][0],goodList.equipInList[goodNo[attFlag2-1]][1],13,24*1);
			if(goodNo[attFlag2+0]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2+0]][0],goodList.equipInList[goodNo[attFlag2+0]][1],13,24*2);
			if(goodNo[attFlag2+1]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2+1]][0],goodList.equipInList[goodNo[attFlag2+1]][1],13,24*3);
		}
		else if(showPos == 3)
		{
			if(goodNo[attFlag2-3]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2-3]][0],goodList.equipInList[goodNo[attFlag2-3]][1],13,24*0);
			if(goodNo[attFlag2-2]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2-2]][0],goodList.equipInList[goodNo[attFlag2-2]][1],13,24*1);
			if(goodNo[attFlag2-1]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2-1]][0],goodList.equipInList[goodNo[attFlag2-1]][1],13,24*2);
			if(goodNo[attFlag2+0]!=-1)ShowGoodPic(0,goodList.equipInList[goodNo[attFlag2+0]][0],goodList.equipInList[goodNo[attFlag2+0]][1],13,24*3);
		}

		MoveToEx(hdcTmp,4,10+showPos*24,NULL);
		LineTo(hdcTmp,4,25+showPos*24);
		MoveToEx(hdcTmp,5,11+showPos*24,NULL);
		LineTo(hdcTmp,5,24+showPos*24);
		MoveToEx(hdcTmp,6,12+showPos*24,NULL);
		LineTo(hdcTmp,6,23+showPos*24);
		MoveToEx(hdcTmp,7,13+showPos*24,NULL);
		LineTo(hdcTmp,7,22+showPos*24);
		MoveToEx(hdcTmp,8,14+showPos*24,NULL);
		LineTo(hdcTmp,8,21+showPos*24);
		MoveToEx(hdcTmp,9,15+showPos*24,NULL);
		LineTo(hdcTmp,9,20+showPos*24);
		MoveToEx(hdcTmp,10,16+showPos*24,NULL);
		LineTo(hdcTmp,10,19+showPos*24);
		MoveToEx(hdcTmp,11,17+showPos*24,NULL);
		LineTo(hdcTmp,11,18+showPos*24);


		char showedText[15][15];
		char text[102];
		int textLen = 0;
		int linestart = 0;
		int lineCount = 0;

		for(int u = 0; u < 102;u++)
		{
			text[u] = ' ';
		}
		for(int u = 0; u < 102;u++)
		{
			if(goodList.good[goodType][goodIdx[attFlag2]].description[u]=='\0')
			{
				textLen = u;
				break;
			}
			text[u] = goodList.good[goodType][goodIdx[attFlag2]].description[u];
		}

		int v = 0;
		for(v = 0;v<15;v++)
		{

			int p=0;
			for(int k = 0 ;k<14;k++)//20160625
			{
				if((int)text[linestart+k] < 128 && (int)text[linestart+k] >= 0)//单字节字符
				{
					p++;
				}
			}
			if(p%2==0)//双字节
			{
				memcpy(showedText[v],&text[linestart],14);
				showedText[v][14]='\0';
				showedText[v+1][0]='\0';
				linestart+=14;
			}
			else
			{
				memcpy(showedText[v],&text[linestart],13);
				showedText[v][13]='\0';
				showedText[v+1][0]='\0';
				linestart+=13;
			}
			if(linestart>=textLen)
			{
				lineCount = v + 1;
				break;
			}


		}
		if(attFlag >= (lineCount -1) )
		{
			attFlag = lineCount - 2;
		}
		if(attFlag <0 )
		{
			attFlag = 0;
		}
		ShowText(showedText[attFlag],47,61);
		ShowText(showedText[attFlag+1],47,78);
		return;

	}
	else if(keyflag433 == 3)//显示装备装备比较界面
	{
		int equipType = goodList.equipInList[selectedGood][0];
		int equipIdx = goodList.equipInList[selectedGood][1];

		int equipType1 = goodList.equipInList[selectedGood][0];
		int equipIdx1 = 0;
		int usedecorateflag  = 0;
		//20181007修正此处的actor[selectedRoleIdx]为actor[act[selectedRoleIdx]]
		if(equipType1 == 1)//head
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].head;//20170319修正selectedRole-》selectedRoleIdx
		}
		if(equipType1 == 2)//body
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].body;
		}
		if(equipType1 == 3)//foot
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].foot;
		}
		if(equipType1 == 4)//shoulder
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].shoulder;
		}
		if(equipType1 == 5)//sleeve
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].sleeve;
		}
		if(equipType1 == 6 )//decorate1 20160228
		{
			if( decorateflag == 0 )
			{
				if(roleList.actor[act[selectedRoleIdx]].decorate1!=0 && roleList.actor[act[selectedRoleIdx]].decorate2!=0)
				{
					equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
					usedecorateflag = 1;
				}
				else if(roleList.actor[act[selectedRoleIdx]].decorate1!=0)
				{
					equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate2;
					usedecorateflag = 2;
				}
				else if(roleList.actor[act[selectedRoleIdx]].decorate1==0)
				{
					equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
					usedecorateflag = 1;
				}
			}
			else if( decorateflag == 0 && equipIdx1==0)
			{
				equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
				usedecorateflag = 1;
			}
			else if( decorateflag == 1 )
			{
				equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
				usedecorateflag = 1;
			}
			else if( decorateflag == 2 )
			{
				equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate2;
				usedecorateflag = 2;
			}
		}

		if(equipType1 == 7)//hand
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].hand;
		}

		ClrScence();
		for(int i = 0;i<25;i++)
		{
			if(roleList.actor[i].inRankFlag == 1)
			{
				int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
				act[k] = i;

				j++;
			}
		}
		ShowHeadPic(0,act[selectedRoleIdx]+1,10,62);

		ShowGoodPic(0,equipType,equipIdx,10,2);
		if(equipIdx1!=0)ShowGoodPic(0,equipType1,equipIdx1,10,32);



		MoveToEx(hdcTmp,1,10+attFlag2*30,NULL);
		LineTo(hdcTmp,1,25+attFlag2*30);
		MoveToEx(hdcTmp,2,11+attFlag2*30,NULL);
		LineTo(hdcTmp,2,24+attFlag2*30);
		MoveToEx(hdcTmp,3,12+attFlag2*30,NULL);
		LineTo(hdcTmp,3,23+attFlag2*30);
		MoveToEx(hdcTmp,4,13+attFlag2*30,NULL);
		LineTo(hdcTmp,4,22+attFlag2*30);
		MoveToEx(hdcTmp,5,14+attFlag2*30,NULL);
		LineTo(hdcTmp,5,21+attFlag2*30);
		MoveToEx(hdcTmp,6,15+attFlag2*30,NULL);
		LineTo(hdcTmp,6,20+attFlag2*30);
		MoveToEx(hdcTmp,7,16+attFlag2*30,NULL);
		LineTo(hdcTmp,7,19+attFlag2*30);
		MoveToEx(hdcTmp,8,17+attFlag2*30,NULL);
		LineTo(hdcTmp,8,18+attFlag2*30);
		MoveToEx(hdcTmp,40,10,NULL);
		LineTo(hdcTmp,40,86);

		if(attFlag == 0 && attFlag2 == 1)
		{
			ShowText(menu_degree,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].degree);
			if(roleList.actor[act[selectedRoleIdx]].degree == degreeList[act[selectedRoleIdx]].degreeMax)//20170820修正selectedRoleIdx
			{
				sprintf_s(tmp,"MAX");
			}
			ShowText(tmp,100,5);
			ShowText(menu_hp,45,23);
			sprintf_s(tmp,"%d/%d",roleList.actor[act[selectedRoleIdx]].hp,roleList.actor[act[selectedRoleIdx]].hpMax);
			ShowText(tmp,100,23);
			ShowText(menu_mp,45,41);
			sprintf_s(tmp,"%d/%d",roleList.actor[act[selectedRoleIdx]].mp,roleList.actor[act[selectedRoleIdx]].mpMax);
			ShowText(tmp,100,41);
			ShowText(menu_at,45,59);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].att);
			ShowText(tmp,100,59);
			ShowText(menu_df,45,77);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].def);
			ShowText(tmp,100,77);
		}
		else if(attFlag == 1 && attFlag2 == 1)
		{
			ShowText(menu_exp,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].exp);
			int tmplen = strlen(tmp);
			ShowText("/",100+tmplen*5,5);
			ShowText(tmp,100,5,10);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].expMax);
			ShowText(tmp,100+tmplen*5+5,9,10);//20161231修正
			ShowText(menu_speed,45,23);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].speed);
			ShowText(tmp,100,23);
			ShowText(menu_anima,45,41);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].anima);
			ShowText(tmp,100,41);
			ShowText(menu_luck,45,59);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].lucky);
			ShowText(tmp,100,59);
			ShowText(menu_anti,45,77);
			if(roleList.actor[act[selectedRoleIdx]].anti == 0)
			{
				ShowText("无",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 8)
			{
				ShowText("毒",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 4)
			{
				ShowText("乱",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 2)
			{
				ShowText("封",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 1)
			{
				ShowText("眠",96,77);

			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 12)
			{
				ShowText("毒乱",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 10)
			{
				ShowText("毒封",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 9)
			{
				ShowText("毒眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 5)
			{
				ShowText("乱眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 3)
			{
				ShowText("封眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 14)
			{
				ShowText("毒乱封",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 13)
			{
				ShowText("毒乱眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 11)
			{
				ShowText("毒封眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 7)
			{
				ShowText("乱封眠",96,77);
			}
			else if(roleList.actor[act[selectedRoleIdx]].anti == 15)
			{
				ShowText("毒乱封眠",96,77);
			}
		}
		else if(attFlag == 0 && attFlag2 == 0)
		{
			ShowText(menu_degree,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].degree);
			if(roleList.actor[act[attFlag2]].degree == degreeList[act[attFlag2]].degreeMax)
			{
				sprintf_s(tmp,"MAX");
			}
			ShowText(tmp,100,5);
			ShowText(menu_hp,45,23);
			int itmp,itmp1;
			itmp = roleList.actor[act[selectedRoleIdx]].hp + goodList.good[equipType-1][equipIdx-1].hp - goodList.good[equipType1-1][equipIdx1-1].hp;
			itmp1 = roleList.actor[act[selectedRoleIdx]].hpMax + goodList.good[equipType-1][equipIdx-1].hpmax - goodList.good[equipType1-1][equipIdx1-1].hpmax;
			sprintf_s(tmp,"%d/%d",itmp,itmp1);
			ShowText(tmp,100,23);
			ShowText(menu_mp,45,41);
			itmp = roleList.actor[act[selectedRoleIdx]].mp + goodList.good[equipType-1][equipIdx-1].mp - goodList.good[equipType1-1][equipIdx1-1].mp;
			itmp1 = roleList.actor[act[selectedRoleIdx]].mpMax + goodList.good[equipType-1][equipIdx-1].mpmax - goodList.good[equipType1-1][equipIdx1-1].mpmax;
			sprintf_s(tmp,"%d/%d",itmp,itmp1);
			ShowText(tmp,100,41);
			ShowText(menu_at,45,59);
			itmp = roleList.actor[act[selectedRoleIdx]].att + goodList.good[equipType-1][equipIdx-1].at - goodList.good[equipType1-1][equipIdx1-1].at;
			sprintf_s(tmp,"%d",itmp);
			ShowText(tmp,100,59);
			ShowText(menu_df,45,77);
			itmp = roleList.actor[act[selectedRoleIdx]].def + goodList.good[equipType-1][equipIdx-1].df - goodList.good[equipType1-1][equipIdx1-1].df;
			sprintf_s(tmp,"%d",itmp);
			ShowText(tmp,100,77);
		}
		else if(attFlag == 1 && attFlag2 == 0)
		{
			ShowText(menu_exp,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].exp);
			int tmplen = strlen(tmp);
			ShowText("/",100+tmplen*5,5);
			ShowText(tmp,100,5,10);
			sprintf_s(tmp,"%d",roleList.actor[act[selectedRoleIdx]].expMax);
			ShowText(tmp,100+tmplen*5+5,9,10);//20161231修正
			int itmp;
			itmp = roleList.actor[act[selectedRoleIdx]].speed + goodList.good[equipType-1][equipIdx-1].speed - goodList.good[equipType1-1][equipIdx1-1].speed;
			ShowText(menu_speed,45,23);
			sprintf_s(tmp,"%d",itmp);
			ShowText(tmp,100,23);
			ShowText(menu_anima,45,41);
			itmp = roleList.actor[act[selectedRoleIdx]].anima + goodList.good[equipType-1][equipIdx-1].anima - goodList.good[equipType1-1][equipIdx1-1].anima;
			sprintf_s(tmp,"%d",itmp);
			ShowText(tmp,100,41);
			ShowText(menu_luck,45,59);
			itmp = roleList.actor[act[selectedRoleIdx]].lucky + goodList.good[equipType-1][equipIdx-1].lucky - goodList.good[equipType1-1][equipIdx1-1].lucky;
			sprintf_s(tmp,"%d",itmp);
			ShowText(tmp,100,59);
			ShowText(menu_anti,45,77);

			//itmp = roleList.actor[act[selectedRoleIdx]].anti + goodList.good[equipType-1][equipIdx-1].all_dlfm_Flag - goodList.good[equipType1-1][equipIdx1-1].all_dlfm_Flag;

			int tmp1 = 0;
			//CheckAntiCauseBy检测角色anti是否由该物品引起，0-不是 1-是  1-4毒乱封眠

			//usedecorateflag
			if(roleList.actor[act[selectedRoleIdx]].anti/ 8 > 0 && CheckAntiCauseBy(1,equipType1-1,equipIdx1-1,usedecorateflag)== 1)
			{
				tmp1 += 8;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti%8/4 > 0 && CheckAntiCauseBy(2,equipType1-1,equipIdx1-1,usedecorateflag)== 1)
			{
				tmp1 += 4;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti%4/2 > 0 && CheckAntiCauseBy(3,equipType1-1,equipIdx1-1,usedecorateflag)== 1)
			{
				tmp1 += 2;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti%2 > 0 && CheckAntiCauseBy(4,equipType1-1,equipIdx1-1,usedecorateflag)== 1)
			{
				tmp1 += 1;
			}
			itmp = roleList.actor[act[selectedRoleIdx]].anti + goodList.good[equipType-1][equipIdx-1].all_dlfm_Flag - tmp1;

			if(itmp <0 || itmp > 15)itmp = 0;

			if(itmp== 0)
			{
				ShowText("无",96,77);
			}
			else if(itmp == 8)
			{
				ShowText("毒",96,77);
			}
			else if(itmp == 4)
			{
				ShowText("乱",96,77);
			}
			else if(itmp == 2)
			{
				ShowText("封",96,77);
			}
			else if(itmp == 1)
			{
				ShowText("眠",96,77);

			}
			else if(itmp == 12)
			{
				ShowText("毒乱",96,77);
			}
			else if(itmp == 10)
			{
				ShowText("毒封",96,77);
			}
			else if(itmp == 9)
			{
				ShowText("毒眠",96,77);
			}
			else if(itmp == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(itmp == 5)
			{
				ShowText("乱眠",96,77);
			}
			else if(itmp == 3)
			{
				ShowText("封眠",96,77);
			}
			else if(itmp == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(itmp == 14)
			{
				ShowText("毒乱封",96,77);
			}
			else if(itmp == 13)
			{
				ShowText("毒乱眠",96,77);
			}
			else if(itmp == 11)
			{
				ShowText("毒封眠",96,77);
			}
			else if(itmp == 7)
			{
				ShowText("乱封眠",96,77);
			}
			else if(itmp == 15)
			{
				ShowText("毒乱封眠",96,77);
			}
		}
		return;
	}
	else if(keyflag31 == 1)//显示界面
	{
		ClrScence();
		for(int i = 0;i<3;i++)//20170129初始化
		{
			act[i] = 0;
		}
		for(int i = 0;i<25;i++)
		{
			if(roleList.actor[i].inRankFlag == 1)
			{
				int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
				act[k] = i;
				ShowHeadPic(0,i+1,10,k*30+2);
				j++;
			}
		}
		if( attFlag2 > (j - 1))//20160902
		{
			attFlag2 = 0;
		}

		MoveToEx(hdcTmp,1,10+attFlag2*30,NULL);
		LineTo(hdcTmp,1,25+attFlag2*30);
		MoveToEx(hdcTmp,2,11+attFlag2*30,NULL);
		LineTo(hdcTmp,2,24+attFlag2*30);
		MoveToEx(hdcTmp,3,12+attFlag2*30,NULL);
		LineTo(hdcTmp,3,23+attFlag2*30);
		MoveToEx(hdcTmp,4,13+attFlag2*30,NULL);
		LineTo(hdcTmp,4,22+attFlag2*30);
		MoveToEx(hdcTmp,5,14+attFlag2*30,NULL);
		LineTo(hdcTmp,5,21+attFlag2*30);
		MoveToEx(hdcTmp,6,15+attFlag2*30,NULL);
		LineTo(hdcTmp,6,20+attFlag2*30);
		MoveToEx(hdcTmp,7,16+attFlag2*30,NULL);
		LineTo(hdcTmp,7,19+attFlag2*30);
		MoveToEx(hdcTmp,8,17+attFlag2*30,NULL);
		LineTo(hdcTmp,8,18+attFlag2*30);
		MoveToEx(hdcTmp,40,10,NULL);
		LineTo(hdcTmp,40,86);

		if(attFlag == 0)
		{
			ShowText(menu_degree,45,5);

			if(roleList.actor[act[attFlag2]].degree == degreeList[act[attFlag2]].degreeMax)
			{
				sprintf_s(tmp,"MAX");
			}
			else
			{
				sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].degree);
			}
			ShowText(tmp,100,5);
			ShowText(menu_hp,45,23);
			sprintf_s(tmp,"%d/%d",roleList.actor[act[attFlag2]].hp,roleList.actor[act[attFlag2]].hpMax);
			ShowText(tmp,100,23);
			ShowText(menu_mp,45,41);
			sprintf_s(tmp,"%d/%d",roleList.actor[act[attFlag2]].mp,roleList.actor[act[attFlag2]].mpMax);
			ShowText(tmp,100,41);
			ShowText(menu_at,45,59);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].att);
			ShowText(tmp,100,59);
			ShowText(menu_df,45,77);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].def);
			ShowText(tmp,100,77);
		}
		else
		{
			ShowText(menu_exp,45,5);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].exp);
			int tmplen = strlen(tmp);
			ShowText("/",100+tmplen*5,5);
			ShowText(tmp,100,5,10);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].expMax);
			ShowText(tmp,100+tmplen*5+5,9,10);//20161231修正
			ShowText(menu_speed,45,23);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].speed);
			ShowText(tmp,100,23);
			ShowText(menu_anima,45,41);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].anima);
			ShowText(tmp,100,41);
			ShowText(menu_luck,45,59);
			sprintf_s(tmp,"%d",roleList.actor[act[attFlag2]].lucky);
			ShowText(tmp,100,59);
			ShowText(menu_anti,45,77);
			if(roleList.actor[act[attFlag2]].anti == 0)
			{
				ShowText("无",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 8)
			{
				ShowText("毒",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 4)
			{
				ShowText("乱",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 2)
			{
				ShowText("封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 1)
			{
				ShowText("眠",96,77);

			}
			else if(roleList.actor[act[attFlag2]].anti == 12)
			{
				ShowText("毒乱",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 10)
			{
				ShowText("毒封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 9)
			{
				ShowText("毒眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 5)
			{
				ShowText("乱眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 3)
			{
				ShowText("封眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 6)
			{
				ShowText("乱封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 14)
			{
				ShowText("毒乱封",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 13)
			{
				ShowText("毒乱眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 11)
			{
				ShowText("毒封眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 7)
			{
				ShowText("乱封眠",96,77);
			}
			else if(roleList.actor[act[attFlag2]].anti == 15)
			{
				ShowText("毒乱封眠",96,77);
			}
		}
		return;
	}
	else if(keyflag31 == 2)//显示穿戴
	{
		char tmp[20];
		char *word[] = {"装饰","装饰","护腕","脚蹬","手持","身穿","肩披","头戴"};
		int pos[8][2] = {{4,4},{4,33},{24,62},{51,66},{78,62},{105,50},{104,12},{78,3}};
		ClrScence();
		for(int i = 0;i<3;i++)
		{
			act[i] = 0;
		}
		for(int i = 0;i<25;i++)
		{
			if(roleList.actor[i].inRankFlag == 1)
			{
				int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
				act[k] = i;
				j++;
			}
		}
		if(j < 3 && attFlag2 > (j - 1))
		{
			attFlag2 = 0;
			selectedRoleIdx = 0;
		}
		//selectedRole = attFlag2;
		HFONT	h;
		h = CreateFont(20,0,0,0,FW_NORMAL,0,FALSE,FALSE, 
			GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
			DEFAULT_QUALITY,FIXED_PITCH|FF_MODERN,"隶书"); 
		HFONT oldh=(HFONT)SelectObject(hdcTmp,h); 
		TextOut(hdcTmp,136,2,"穿",strlen("穿"));
		TextOut(hdcTmp,136,26,"戴",strlen("戴"));
		InvalidateRect(hwnd,NULL,FALSE);
		SelectObject(hdcTmp,oldh); 
		DeleteObject(h);

		Rectangle(hdcTmp,pos[attFlag][0],pos[attFlag][1],pos[attFlag][0]+26,pos[attFlag][1]+26);
		ShowHeadPic(0,act[selectedRoleIdx]+1,45,15);
		//显示道具图片
		if(roleList.actor[act[selectedRoleIdx]].decorate1!=0)
		{
			ShowGoodPic(0,6,goodList.good[5][roleList.actor[act[selectedRoleIdx]].decorate1-1].no,pos[0][0]+1,pos[0][1]+1);//20170122 picnum->no
		}
		if(roleList.actor[act[selectedRoleIdx]].decorate2!=0)
		{
			ShowGoodPic(0,6,goodList.good[5][roleList.actor[act[selectedRoleIdx]].decorate2-1].no,pos[1][0]+1,pos[1][1]+1);
		}
		if(roleList.actor[act[selectedRoleIdx]].sleeve!=0)
		{
			ShowGoodPic(0,5,goodList.good[4][roleList.actor[act[selectedRoleIdx]].sleeve-1].no,pos[2][0]+1,pos[2][1]+1);
		}
		if(roleList.actor[act[selectedRoleIdx]].foot!=0)
		{
			ShowGoodPic(0,3,goodList.good[2][roleList.actor[act[selectedRoleIdx]].foot-1].no,pos[3][0]+1,pos[3][1]+1);
		}
		if(roleList.actor[act[selectedRoleIdx]].hand!=0)
		{
			ShowGoodPic(0,7,goodList.good[6][roleList.actor[act[selectedRoleIdx]].hand-1].no,pos[4][0]+1,pos[4][1]+1);
		}
		if(roleList.actor[act[selectedRoleIdx]].body!=0)
		{
			ShowGoodPic(0,2,goodList.good[1][roleList.actor[act[selectedRoleIdx]].body-1].no,pos[5][0]+1,pos[5][1]+1);
		}
		if(roleList.actor[act[selectedRoleIdx]].shoulder!=0)
		{
			ShowGoodPic(0,4,goodList.good[3][roleList.actor[act[selectedRoleIdx]].shoulder-1].no,pos[6][0]+1,pos[6][1]+1);
		}
		if(roleList.actor[act[selectedRoleIdx]].head!=0)
		{
			ShowGoodPic(0,1,goodList.good[0][roleList.actor[act[selectedRoleIdx]].head-1].no,pos[7][0]+1,pos[7][1]+1);
		}

		sprintf_s(tmp,"%s",roleList.actor[act[selectedRoleIdx]].name);
		ShowText(tmp,35,43);
		ShowText(word[attFlag],120,80);

		return;
	}
	else if(keyflag32 > 0)//显示技能
	{
		//keytmp = 0;//用于上下选项区分显示位置
		char tmp[20];
		ClrScence();

		int t_j = 0;
		int act[3];
		for(int i = 0;i<25;i++)
		{
			if(roleList.actor[i].inRankFlag == 1)
			{
				int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
				act[k] = i;
				t_j++;
			}
		}

		int magicMax = roleList.actor[act[keyflag32-1]].magicLearn;//degreeList[roleList.actor[keyflag32-1].magicListNo-1].learnedMagic[roleList.actor[keyflag32-1].degree-1];
		if(attFlag >= magicMax)
		{
			attFlag = magicMax - 1;
		}
		if(attFlag < 0)
		{
			attFlag = 0;
		}

		Rectangle(hdcTmp,8,4,150,40);
		Rectangle(hdcTmp,8,42,150,78);
		if(keytmp == 0||magicMax == 1)
		{
			keytmp = 0;
			ShowText(actorMagicList[act[keyflag32-1]].magic[attFlag].name,12,6);
			if((attFlag+1) < magicMax )ShowText(actorMagicList[act[keyflag32-1]].magic[attFlag+1].name,12,22);
		}
		else
		{
			if(attFlag > 0 )ShowText(actorMagicList[act[keyflag32-1]].magic[attFlag-1].name,12,6);
			ShowText(actorMagicList[act[keyflag32-1]].magic[attFlag].name,12,22);
		}

		char showedText[14][17];
		char text[102];
		int textLen = 0;
		int linestart = 0;
		int lineCount = 0;

		for(int i = 0; i < 102;i++)
		{
			text[i] = ' ';
		}
		for(int i = 0; i < 102;i++)
		{
			if(actorMagicList[act[keyflag32-1]].magic[attFlag].description[i]=='\0')
			{
				textLen = i;
				break;
			}
			text[i] = actorMagicList[act[keyflag32-1]].magic[attFlag].description[i];
		}

		int j = 0;
		for(j = 0;j<14;j++)
		{

			int p=0;
			for(int k = 0 ;k<16;k++)//20160625
			{
				if((int)text[linestart+k] < 128 && (int)text[linestart+k] >= 0)//单字节字符
				{
					p++;
				}
			}
			if(p%2==0)//双字节
			{
				memcpy(showedText[j],&text[linestart],16);
				showedText[j][16]='\0';
				showedText[j+1][0]='\0';
				linestart+=16;
			}
			else
			{
				memcpy(showedText[j],&text[linestart],15);
				showedText[j][15]='\0';
				showedText[j+1][0]='\0';
				linestart+=15;
			}
			if(linestart>=textLen)
			{
				lineCount = j + 1;
				break;
			}


		}
		if(attFlag2 >= (lineCount -1) )
		{
			attFlag2 = lineCount - 2;
		}
		if(attFlag2 <0 )
		{
			attFlag2 = 0;
		}
		ShowText(showedText[attFlag2],12,44);
		ShowText(showedText[attFlag2+1],12,61);
		ShowText("耗真气:",8,79);
		sprintf_s(tmp,"%d",actorMagicList[act[keyflag32-1]].magic[attFlag].cost);
		ShowText(tmp,64,79);
		Ellipse(hdcTmp,133,7,138,15);
		Ellipse(hdcTmp,133,15,138,23);
		Ellipse(hdcTmp,133,23,138,31);
		Ellipse(hdcTmp,133,31,138,39);

		//显示黑色标记
		if(attFlag>0)
		{
			Ellipse(hdcTmp,134,8,137,14);
			Ellipse(hdcTmp,135,9,136,13);
		}
		if((attFlag+1) < magicMax)
		{
			Ellipse(hdcTmp,134,32,137,38);
			Ellipse(hdcTmp,135,33,136,37);
		}

		MoveToEx(hdcTmp,135,10,NULL);
		LineTo(hdcTmp,135,12);
		MoveToEx(hdcTmp,135,18,NULL);
		LineTo(hdcTmp,135,20);
		MoveToEx(hdcTmp,135,26,NULL);
		LineTo(hdcTmp,135,28);
		MoveToEx(hdcTmp,135,34,NULL);
		LineTo(hdcTmp,135,36);

		MoveToEx(hdcTmp,100,20+keytmp*16,NULL);
		LineTo(hdcTmp,106,14+keytmp*16);
		MoveToEx(hdcTmp,102,20+keytmp*16,NULL);
		LineTo(hdcTmp,107,15+keytmp*16);

		Rectangle(hdcTmp,106,11+keytmp*16,108,15+keytmp*16);
		Rectangle(hdcTmp,107,15+keytmp*16,111,17+keytmp*16);
		Rectangle(hdcTmp,108,10+keytmp*16,111,11+keytmp*16);
		Rectangle(hdcTmp,111,11+keytmp*16,112,15+keytmp*16);


		return;
	}
	else if(keyflag33 == 1)//显示使用
	{
		char tmp[20];
		ClrScence();
		MoveToEx(hdcTmp,140,21,NULL);
		LineTo(hdcTmp,42,21);
		MoveToEx(hdcTmp,140,0,NULL);
		LineTo(hdcTmp,55,0);
		MoveToEx(hdcTmp,140,20,NULL);
		LineTo(hdcTmp,59,20);

		LineTo(hdcTmp,39,0);
		LineTo(hdcTmp,6,0);
		LineTo(hdcTmp,0,6);
		LineTo(hdcTmp,0,95);
		LineTo(hdcTmp,41,95);
		LineTo(hdcTmp,41,22);
		MoveToEx(hdcTmp,42,95,NULL);
		LineTo(hdcTmp,42,22);
		Rectangle(hdcTmp,43,22,158,58);
		Rectangle(hdcTmp,43,59,158,96);

		MoveToEx(hdcTmp,140,57,NULL);
		LineTo(hdcTmp,42,58);

		ShowText(menu_num,60,3);





		int goodCount = goodList.goodInListCount;
		if(goodList.goodInListCount == 0)//重新显示地图，无效按键
		{
			keyflag33 = 0;
			keyflag2 = 0;
			keyflag = 0;
			Show(0);
			return;
		}




		int goodType = goodList.goodInList[attFlag][0];
		int goodIdx = goodList.goodInList[attFlag][1];
		int goodSum = goodList.goodInList[attFlag][2];


		sprintf_s(tmp,"%d",goodSum);
		ShowText(tmp,100,3);
		ShowText(menu_name,47,24);
		ShowText(goodList.good[goodType-1][goodIdx-1].name,71,24);
		ShowText(menu_price,47,41);
		sprintf_s(tmp,"%d",goodList.good[goodType-1][goodIdx-1].sell);
		ShowText(tmp,71,41);

		int max = goodList.goodInListCount>4?3:goodList.goodInListCount - 1;

		if(flagd==1&&KeyCode==KeyDown0)
		{
			showPos=max;

		}
		else if(flagu==1&&KeyCode==KeyUp0)
		{
			showPos=0;

		}
		else if(flagd==1&&KeyCode==KeyUp0)
		{
			flagd=0;
			showPos--;
		}
		else if(flagu==1&&KeyCode==KeyDown0)
		{
			flagu=0;
			showPos++;
		}
		else if(KeyCode==KeyUp0)
		{
			showPos--;
		}
		else if(KeyCode==KeyDown0)
		{
			showPos++;
		}
		if(showPos==max)flagd=1;
		if(showPos==0)flagu=1;



		if(showPos == 0)
		{
			ShowGoodPic(0,goodList.goodInList[attFlag][0],goodList.goodInList[attFlag][1],13,24*0);
			if((attFlag+1)<goodList.goodInListCount)ShowGoodPic(0,goodList.goodInList[attFlag+1][0],goodList.goodInList[attFlag+1][1],13,24*1);
			if((attFlag+2)<goodList.goodInListCount)ShowGoodPic(0,goodList.goodInList[attFlag+2][0],goodList.goodInList[attFlag+2][1],13,24*2);
			if((attFlag+3)<goodList.goodInListCount)ShowGoodPic(0,goodList.goodInList[attFlag+3][0],goodList.goodInList[attFlag+3][1],13,24*3);
		}
		else if(showPos == 1)
		{
			if((attFlag-1)>=0)ShowGoodPic(0,goodList.goodInList[attFlag-1][0],goodList.goodInList[attFlag-1][1],13,24*0);
			ShowGoodPic(0,goodList.goodInList[attFlag+0][0],goodList.goodInList[attFlag+0][1],13,24*1);
			if((attFlag+1)<goodList.goodInListCount)ShowGoodPic(0,goodList.goodInList[attFlag+1][0],goodList.goodInList[attFlag+1][1],13,24*2);
			if((attFlag+2)<goodList.goodInListCount)ShowGoodPic(0,goodList.goodInList[attFlag+2][0],goodList.goodInList[attFlag+2][1],13,24*3);
		}
		else if(showPos == 2)
		{
			if((attFlag-2)>=0)ShowGoodPic(0,goodList.goodInList[attFlag-2][0],goodList.goodInList[attFlag-2][1],13,24*0);
			if((attFlag-1)>=0)ShowGoodPic(0,goodList.goodInList[attFlag-1][0],goodList.goodInList[attFlag-1][1],13,24*1);
			ShowGoodPic(0,goodList.goodInList[attFlag+0][0],goodList.goodInList[attFlag+0][1],13,24*2);
			if((attFlag+1)<goodList.goodInListCount)ShowGoodPic(0,goodList.goodInList[attFlag+1][0],goodList.goodInList[attFlag+1][1],13,24*3);
		}
		else if(showPos == 3)
		{
			if((attFlag-3)>=0)ShowGoodPic(0,goodList.goodInList[attFlag-3][0],goodList.goodInList[attFlag-3][1],13,24*0);
			if((attFlag-2)>=0)ShowGoodPic(0,goodList.goodInList[attFlag-2][0],goodList.goodInList[attFlag-2][1],13,24*1);
			if((attFlag-1)>=0)ShowGoodPic(0,goodList.goodInList[attFlag-1][0],goodList.goodInList[attFlag-1][1],13,24*2);
			ShowGoodPic(0,goodList.goodInList[attFlag+0][0],goodList.goodInList[attFlag+0][1],13,24*3);
		}



		MoveToEx(hdcTmp,4,10+showPos*24,NULL);
		LineTo(hdcTmp,4,25+showPos*24);
		MoveToEx(hdcTmp,5,11+showPos*24,NULL);
		LineTo(hdcTmp,5,24+showPos*24);
		MoveToEx(hdcTmp,6,12+showPos*24,NULL);
		LineTo(hdcTmp,6,23+showPos*24);
		MoveToEx(hdcTmp,7,13+showPos*24,NULL);
		LineTo(hdcTmp,7,22+showPos*24);
		MoveToEx(hdcTmp,8,14+showPos*24,NULL);
		LineTo(hdcTmp,8,21+showPos*24);
		MoveToEx(hdcTmp,9,15+showPos*24,NULL);
		LineTo(hdcTmp,9,20+showPos*24);
		MoveToEx(hdcTmp,10,16+showPos*24,NULL);
		LineTo(hdcTmp,10,19+showPos*24);
		MoveToEx(hdcTmp,11,17+showPos*24,NULL);
		LineTo(hdcTmp,11,18+showPos*24);


		char showedText[15][15];
		char text[102];
		int textLen = 0;
		int linestart = 0;
		int lineCount = 0;

		for(int u = 0; u < 102;u++)
		{
			text[u] = ' ';
		}
		for(int u = 0; u < 102;u++)
		{
			if(goodList.good[goodType-1][goodIdx-1].description[u]=='\0')
			{
				textLen = u;
				break;
			}
			text[u] = goodList.good[goodType-1][goodIdx-1].description[u];
		}

		int v = 0;
		for(v = 0;v<15;v++)
		{

			int p=0;
			for(int k = 0 ;k<14;k++)//20160625
			{
				if((int)text[linestart+k] < 128 && (int)text[linestart+k] >= 0)//单字节字符
				{
					p++;
				}
			}
			if(p%2==0)//双字节
			{
				memcpy(showedText[v],&text[linestart],14);
				showedText[v][14]='\0';
				showedText[v+1][0]='\0';
				linestart+=14;
			}
			else
			{
				memcpy(showedText[v],&text[linestart],13);
				showedText[v][13]='\0';
				showedText[v+1][0]='\0';
				linestart+=13;
			}
			if(linestart>=textLen)
			{
				lineCount = v + 1;
				break;
			}


		}
		if(attFlag2 >= (lineCount -1) )
		{
			attFlag2 = lineCount - 2;
		}
		if(attFlag2 <0 )
		{
			attFlag2 = 0;
		}
		ShowText(showedText[attFlag2],47,61);
		ShowText(showedText[attFlag2+1],47,78);

		return;

	}
	else if(keyflag33 == 2)//显示装备
	{
		char tmp[20];
		ClrScence();
		MoveToEx(hdcTmp,140,21,NULL);
		LineTo(hdcTmp,42,21);
		MoveToEx(hdcTmp,140,0,NULL);
		LineTo(hdcTmp,55,0);
		MoveToEx(hdcTmp,140,20,NULL);
		LineTo(hdcTmp,59,20);

		LineTo(hdcTmp,39,0);
		LineTo(hdcTmp,6,0);
		LineTo(hdcTmp,0,6);
		LineTo(hdcTmp,0,95);
		LineTo(hdcTmp,41,95);
		LineTo(hdcTmp,41,22);
		MoveToEx(hdcTmp,42,95,NULL);
		LineTo(hdcTmp,42,22);
		Rectangle(hdcTmp,43,22,158,58);
		Rectangle(hdcTmp,43,59,158,96);

		MoveToEx(hdcTmp,140,57,NULL);
		LineTo(hdcTmp,42,58);

		ShowText(menu_num,60,3);


		int equipCount = goodList.equipInListCount;
		if(goodList.equipInListCount == 0)//重新显示地图，无效按键
		{
			keyflag33 = 0;
			keyflag2 = 0;
			keyflag = 0;
			Show(0);
			return;
		}

		int goodType = goodList.equipInList[attFlag][0];
		int goodIdx = goodList.equipInList[attFlag][1];
		int goodSum = goodList.equipInList[attFlag][2];

		sprintf_s(tmp,"%d",goodSum);
		ShowText(tmp,100,3);
		ShowText(menu_name,47,24);
		ShowText(goodList.good[goodType-1][goodIdx-1].name,71,24);
		ShowText(menu_price,47,41);
		sprintf_s(tmp,"%d",goodList.good[goodType-1][goodIdx-1].sell);
		ShowText(tmp,71,41);

		int max = goodList.equipInListCount>4?3:goodList.equipInListCount - 1;

		if(flagd==1&&KeyCode==KeyDown0)
		{
			showPos=max;

		}
		else if(flagu==1&&KeyCode==KeyUp0)
		{
			showPos=0;

		}
		else if(flagd==1&&KeyCode==KeyUp0)
		{
			flagd=0;
			showPos--;
		}
		else if(flagu==1&&KeyCode==KeyDown0)
		{
			flagu=0;
			showPos++;
		}
		else if(KeyCode==KeyUp0)
		{
			showPos--;
		}
		else if(KeyCode==KeyDown0)
		{
			showPos++;
		}
		if(showPos==max)flagd=1;
		if(showPos==0)flagu=1;



		if(showPos == 0)
		{
			ShowGoodPic(0,goodList.equipInList[attFlag][0],goodList.equipInList[attFlag][1],13,24*0);
			if((attFlag+1)<goodList.equipInListCount)ShowGoodPic(0,goodList.equipInList[attFlag+1][0],goodList.equipInList[attFlag+1][1],13,24*1);
			if((attFlag+2)<goodList.equipInListCount)ShowGoodPic(0,goodList.equipInList[attFlag+2][0],goodList.equipInList[attFlag+2][1],13,24*2);
			if((attFlag+3)<goodList.equipInListCount)ShowGoodPic(0,goodList.equipInList[attFlag+3][0],goodList.equipInList[attFlag+3][1],13,24*3);
		}
		else if(showPos == 1)
		{
			if((attFlag-1)>=0)ShowGoodPic(0,goodList.equipInList[attFlag-1][0],goodList.equipInList[attFlag-1][1],13,24*0);
			ShowGoodPic(0,goodList.equipInList[attFlag+0][0],goodList.equipInList[attFlag+0][1],13,24*1);
			if((attFlag+1)<goodList.equipInListCount)ShowGoodPic(0,goodList.equipInList[attFlag+1][0],goodList.equipInList[attFlag+1][1],13,24*2);
			if((attFlag+2)<goodList.equipInListCount)ShowGoodPic(0,goodList.equipInList[attFlag+2][0],goodList.equipInList[attFlag+2][1],13,24*3);
		}
		else if(showPos == 2)
		{
			if((attFlag-2)>=0)ShowGoodPic(0,goodList.equipInList[attFlag-2][0],goodList.equipInList[attFlag-2][1],13,24*0);
			if((attFlag-1)>=0)ShowGoodPic(0,goodList.equipInList[attFlag-1][0],goodList.equipInList[attFlag-1][1],13,24*1);
			ShowGoodPic(0,goodList.equipInList[attFlag+0][0],goodList.equipInList[attFlag+0][1],13,24*2);
			if((attFlag+1)<goodList.equipInListCount)ShowGoodPic(0,goodList.equipInList[attFlag+1][0],goodList.equipInList[attFlag+1][1],13,24*3);
		}
		else if(showPos == 3)
		{
			if((attFlag-3)>=0)ShowGoodPic(0,goodList.equipInList[attFlag-3][0],goodList.equipInList[attFlag-3][1],13,24*0);
			if((attFlag-2)>=0)ShowGoodPic(0,goodList.equipInList[attFlag-2][0],goodList.equipInList[attFlag-2][1],13,24*1);
			if((attFlag-1)>=0)ShowGoodPic(0,goodList.equipInList[attFlag-1][0],goodList.equipInList[attFlag-1][1],13,24*2);
			ShowGoodPic(0,goodList.equipInList[attFlag+0][0],goodList.equipInList[attFlag+0][1],13,24*3);
		}

		MoveToEx(hdcTmp,4,10+showPos*24,NULL);
		LineTo(hdcTmp,4,25+showPos*24);
		MoveToEx(hdcTmp,5,11+showPos*24,NULL);
		LineTo(hdcTmp,5,24+showPos*24);
		MoveToEx(hdcTmp,6,12+showPos*24,NULL);
		LineTo(hdcTmp,6,23+showPos*24);
		MoveToEx(hdcTmp,7,13+showPos*24,NULL);
		LineTo(hdcTmp,7,22+showPos*24);
		MoveToEx(hdcTmp,8,14+showPos*24,NULL);
		LineTo(hdcTmp,8,21+showPos*24);
		MoveToEx(hdcTmp,9,15+showPos*24,NULL);
		LineTo(hdcTmp,9,20+showPos*24);
		MoveToEx(hdcTmp,10,16+showPos*24,NULL);
		LineTo(hdcTmp,10,19+showPos*24);
		MoveToEx(hdcTmp,11,17+showPos*24,NULL);
		LineTo(hdcTmp,11,18+showPos*24);


		char showedText[15][15];
		char text[102];
		int textLen = 0;
		int linestart = 0;
		int lineCount = 0;

		for(int u = 0; u < 102;u++)
		{
			text[u] = ' ';
		}
		for(int u = 0; u < 102;u++)
		{
			if(goodList.good[goodType-1][goodIdx-1].description[u]=='\0')
			{
				textLen = u;
				break;
			}
			text[u] = goodList.good[goodType-1][goodIdx-1].description[u];
		}

		int v = 0;
		for(v = 0;v<15;v++)
		{

			int p=0;
			for(int k = 0 ;k<14;k++)//20160625
			{
				if((int)text[linestart+k] < 128 && (int)text[linestart+k] >= 0)//单字节字符
				{
					p++;
				}
			}
			if(p%2==0)//双字节
			{
				memcpy(showedText[v],&text[linestart],14);
				showedText[v][14]='\0';
				showedText[v+1][0]='\0';
				linestart+=14;
			}
			else
			{
				memcpy(showedText[v],&text[linestart],13);
				showedText[v][13]='\0';
				showedText[v+1][0]='\0';
				linestart+=13;
			}
			if(linestart>=textLen)
			{
				lineCount = v + 1;
				break;
			}


		}
		if(attFlag2 >= (lineCount -1) )
		{
			attFlag2 = lineCount - 2;
		}
		if(attFlag2 <0 )
		{
			attFlag2 = 0;
		}
		ShowText(showedText[attFlag2],47,61);
		ShowText(showedText[attFlag2+1],47,78);
		return;

	}
	else if(keyflag51 == 1)
	{
		char tmp[20];
		//ClrScence();
		int havedSum = goodList.CheckGoodExist(selectedEquipType,selectedEquipId);
		if((havedSum + attFlag)> MAX_GOOD_IN_HAND)//20170102
		{
			attFlag = MAX_GOOD_IN_HAND - havedSum;
		}

		Rectangle(hdcTmp,10,22,150,74);

		if(money-attFlag*goodList.good[selectedEquipType-1][selectedEquipId -1].buy <0)
		{
			attFlag --;
			TimerMessage("金钱不足！",10,37,8,1,1000);
		}

		ShowText("金钱：",12,24);
		sprintf_s(tmp,"%d",money-attFlag*goodList.good[selectedEquipType-1][selectedEquipId -1].buy );
		ShowText(tmp,100,24);

		sprintf_s(tmp,"%5s：",goodList.good[selectedEquipType-1][selectedEquipId-1].name);
		ShowText(tmp,12,40);

		sprintf_s(tmp,"%d",havedSum + attFlag );
		ShowText(tmp,100,40);
		ShowText("买入个数  ：",12,56);
		sprintf_s(tmp,"%d",attFlag);
		ShowText(tmp,100,56);

		//int goodType = g_goodType[attFlag];
		//int goodIdx = g_goodId[attFlag];



		return;
	}
	else if(keyflag52 == 1)
	{
		char tmp[20];
		//ClrScence();

		Rectangle(hdcTmp,10,22,150,74);

		int havedSum = goodList.CheckGoodExist(selectedEquipType,selectedEquipId);
		if((havedSum - attFlag) < 0)
		{
			attFlag --;
			TimerMessage("物品不足！",10,37,8,1,1000);

		}

		ShowText("金钱：",12,24);
		sprintf_s(tmp,"%d",money+attFlag*goodList.good[selectedEquipType-1][selectedEquipId -1].sell );
		ShowText(tmp,100,24);

		sprintf_s(tmp,"%5s：",goodList.good[selectedEquipType-1][selectedEquipId-1].name);
		ShowText(tmp,12,40);

		sprintf_s(tmp,"%d",havedSum - attFlag );
		ShowText(tmp,100,40);
		ShowText("卖出个数  ：",12,56);
		sprintf_s(tmp,"%d",attFlag);
		ShowText(tmp,100,56);

		//int goodType = g_goodType[attFlag];
		//int goodIdx = g_goodId[attFlag];



		return;
	}
	else if(keyflag5 == 1)//1-出售界面
	{
		char tmp[20];
		ClrScence();
		MoveToEx(hdcTmp,140,21,NULL);
		LineTo(hdcTmp,42,21);
		MoveToEx(hdcTmp,140,0,NULL);
		LineTo(hdcTmp,55,0);
		MoveToEx(hdcTmp,140,20,NULL);
		LineTo(hdcTmp,59,20);

		LineTo(hdcTmp,39,0);
		LineTo(hdcTmp,6,0);
		LineTo(hdcTmp,0,6);
		LineTo(hdcTmp,0,95);
		LineTo(hdcTmp,41,95);
		LineTo(hdcTmp,41,22);
		MoveToEx(hdcTmp,42,95,NULL);
		LineTo(hdcTmp,42,22);
		Rectangle(hdcTmp,43,22,158,58);
		Rectangle(hdcTmp,43,59,158,96);

		MoveToEx(hdcTmp,140,57,NULL);
		LineTo(hdcTmp,42,58);

		ShowText("金钱:",60,3);



		int goodType = g_goodType[attFlag];
		int goodIdx = g_goodId[attFlag];

		sprintf_s(tmp,"%d",money);
		ShowText(tmp,100,3);
		ShowText(menu_name,47,24);
		ShowText(goodList.good[goodType-1][goodIdx-1].name,71,24);
		ShowText(menu_price,47,41);
		sprintf_s(tmp,"%d",goodList.good[goodType-1][goodIdx-1].buy);

		ShowText(tmp,71,41);

		//int showPos = attFlag;

		int max = g_goodSum>4?3:g_goodSum - 1;

		if(flagd==1&&KeyCode==KeyDown0)
		{
			showPos=max;

		}
		else if(flagu==1&&KeyCode==KeyUp0)
		{
			showPos=0;

		}
		else if(flagd==1&&KeyCode==KeyUp0)
		{
			flagd=0;
			showPos--;
		}
		else if(flagu==1&&KeyCode==KeyDown0)
		{
			flagu=0;
			showPos++;
		}
		else if(KeyCode==KeyUp0)
		{
			showPos--;
		}
		else if(KeyCode==KeyDown0)
		{
			showPos++;
		}
		if(showPos==max)flagd=1;
		if(showPos==0)flagu=1;



		if(showPos == 0)
		{
			ShowGoodPic(0,g_goodType[attFlag],g_goodId[attFlag],13,24*0);
			if((attFlag+2)<g_goodSum)ShowGoodPic(0,g_goodType[attFlag+1],g_goodId[attFlag+1],13,24*1);
			if((attFlag+1)<g_goodSum)ShowGoodPic(0,g_goodType[attFlag+2],g_goodId[attFlag+2],13,24*2);
			if((attFlag+3)<g_goodSum)ShowGoodPic(0,g_goodType[attFlag+3],g_goodId[attFlag+3],13,24*3);
		}
		else if(showPos == 1)
		{
			if((attFlag-1)>=0)ShowGoodPic(0,g_goodType[attFlag-1],g_goodId[attFlag-1],13,24*0);
			ShowGoodPic(0,g_goodType[attFlag],g_goodId[attFlag],13,24*1);
			if((attFlag+1)<g_goodSum)ShowGoodPic(0,g_goodType[attFlag+1],g_goodId[attFlag+1],13,24*2);
			if((attFlag+2)<g_goodSum)ShowGoodPic(0,g_goodType[attFlag+2],g_goodId[attFlag+2],13,24*3);
		}
		else if(showPos == 2)
		{
			if((attFlag-2)>=0)ShowGoodPic(0,g_goodType[attFlag-2],g_goodId[attFlag-2],13,24*0);
			if((attFlag-1)>=0)ShowGoodPic(0,g_goodType[attFlag-1],g_goodId[attFlag-1],13,24*1);
			ShowGoodPic(0,g_goodType[attFlag],g_goodId[attFlag],13,24*2);
			if((attFlag+1)<g_goodSum)ShowGoodPic(0,g_goodType[attFlag+1],g_goodId[attFlag+1],13,24*3);
		}
		else if(showPos == 3)
		{
			if((attFlag-3)>=0)ShowGoodPic(0,g_goodType[attFlag-3],g_goodId[attFlag-3],13,24*0);
			if((attFlag-2)>=0)ShowGoodPic(0,g_goodType[attFlag-2],g_goodId[attFlag-2],13,24*1);
			if((attFlag-1)>=0)ShowGoodPic(0,g_goodType[attFlag-1],g_goodId[attFlag-1],13,24*2);
			ShowGoodPic(0,g_goodType[attFlag],g_goodId[attFlag],13,24*3);
		}

		MoveToEx(hdcTmp,4,10+showPos*24,NULL);
		LineTo(hdcTmp,4,25+showPos*24);
		MoveToEx(hdcTmp,5,11+showPos*24,NULL);
		LineTo(hdcTmp,5,24+showPos*24);
		MoveToEx(hdcTmp,6,12+showPos*24,NULL);
		LineTo(hdcTmp,6,23+showPos*24);
		MoveToEx(hdcTmp,7,13+showPos*24,NULL);
		LineTo(hdcTmp,7,22+showPos*24);
		MoveToEx(hdcTmp,8,14+showPos*24,NULL);
		LineTo(hdcTmp,8,21+showPos*24);
		MoveToEx(hdcTmp,9,15+showPos*24,NULL);
		LineTo(hdcTmp,9,20+showPos*24);
		MoveToEx(hdcTmp,10,16+showPos*24,NULL);
		LineTo(hdcTmp,10,19+showPos*24);
		MoveToEx(hdcTmp,11,17+showPos*24,NULL);
		LineTo(hdcTmp,11,18+showPos*24);


		char showedText[15][15];
		char text[102];
		int textLen = 0;
		int linestart = 0;
		int lineCount = 0;

		for(int u = 0; u < 102;u++)
		{
			text[u] = ' ';
		}
		for(int u = 0; u < 102;u++)
		{
			if(goodList.good[goodType-1][goodIdx-1].description[u]=='\0')
			{
				textLen = u;
				break;
			}
			text[u] = goodList.good[goodType-1][goodIdx-1].description[u];
		}

		int v = 0;
		for(v = 0;v<15;v++)
		{

			int p=0;
			for(int k = 0 ;k<14;k++)//20160625
			{
				if((int)text[linestart+k] < 128 && (int)text[linestart+k] >= 0)//单字节字符
				{
					p++;
				}
			}
			if(p%2==0)//双字节
			{
				memcpy(showedText[v],&text[linestart],14);
				showedText[v][14]='\0';
				showedText[v+1][0]='\0';
				linestart+=14;
			}
			else
			{
				memcpy(showedText[v],&text[linestart],13);
				showedText[v][13]='\0';
				showedText[v+1][0]='\0';
				linestart+=13;
			}
			if(linestart>=textLen)
			{
				lineCount = v + 1;
				break;
			}


		}
		if(attFlag2 >= (lineCount -1) )
		{
			attFlag2 = lineCount - 2;
		}
		if(attFlag2 <0 )
		{
			attFlag2 = 0;
		}
		ShowText(showedText[attFlag2],47,61);
		ShowText(showedText[attFlag2+1],47,78);

		selectedEquipType = g_goodType[attFlag];
		selectedEquipId =  g_goodId[attFlag];
		return;
	}
	else if(keyflag5 == 2)//回收界面 20160228 增加装备出售
	{
		char tmp[20];
		ClrScence();
		MoveToEx(hdcTmp,140,21,NULL);
		LineTo(hdcTmp,42,21);
		MoveToEx(hdcTmp,140,0,NULL);
		LineTo(hdcTmp,55,0);
		MoveToEx(hdcTmp,140,20,NULL);
		LineTo(hdcTmp,59,20);

		LineTo(hdcTmp,39,0);
		LineTo(hdcTmp,6,0);
		LineTo(hdcTmp,0,6);
		LineTo(hdcTmp,0,95);
		LineTo(hdcTmp,41,95);
		LineTo(hdcTmp,41,22);
		MoveToEx(hdcTmp,42,95,NULL);
		LineTo(hdcTmp,42,22);
		Rectangle(hdcTmp,43,22,158,58);
		Rectangle(hdcTmp,43,59,158,96);

		MoveToEx(hdcTmp,140,57,NULL);
		LineTo(hdcTmp,42,58);

		ShowText(menu_num,60,3);





		int goodCount = goodList.goodInListCount;
		int equipCount = goodList.equipInListCount;
		int allCount = goodCount + equipCount;
		if(allCount == 0)//重新显示地图，无效按键
		{
			keyflag5 = 0;
			keyflag = 0;
			TimerMessage("没有可出售的物品！",10,37,8,1,1000);
			Show(0);
			return;
		}


		int goodType = 0;
		int goodIdx = 0;
		int goodSum = 0;
		int attFlagEq = attFlag-goodCount;
		if(attFlag<goodCount)
		{
			goodType = goodList.goodInList[attFlag][0];
			goodIdx = goodList.goodInList[attFlag][1];
			goodSum = goodList.goodInList[attFlag][2];
		}
		else
		{

			goodType = goodList.equipInList[attFlagEq][0];
			goodIdx = goodList.equipInList[attFlagEq][1];
			goodSum = goodList.equipInList[attFlagEq][2];
		}



		sprintf_s(tmp,"%d",goodSum);
		ShowText(tmp,100,3);
		ShowText(menu_name,47,24);
		ShowText(goodList.good[goodType-1][goodIdx-1].name,71,24);
		ShowText(menu_price,47,41);
		sprintf_s(tmp,"%d",goodList.good[goodType-1][goodIdx-1].sell);
		ShowText(tmp,71,41);

		int max = allCount>4?3:allCount - 1;

		if(flagd==1&&KeyCode==KeyDown0)
		{
			showPos=max;

		}
		else if(flagu==1&&KeyCode==KeyUp0)
		{
			showPos=0;

		}
		else if(flagd==1&&KeyCode==KeyUp0)
		{
			flagd=0;
			showPos--;
		}
		else if(flagu==1&&KeyCode==KeyDown0)
		{
			flagu=0;
			showPos++;
		}
		else if(KeyCode==KeyUp0)
		{
			showPos--;
		}
		else if(KeyCode==KeyDown0)
		{
			showPos++;
		}
		if(showPos==max)flagd=1;
		if(showPos==0)flagu=1;



		if(showPos == 0)
		{
			if(attFlag < goodCount)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag][0],goodList.goodInList[attFlag][1],13,24*0);
			}
			else if(attFlag < allCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq][0],goodList.equipInList[attFlagEq][1],13,24*0);
			}
			if((attFlag+1)<goodCount)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag+1][0],goodList.goodInList[attFlag+1][1],13,24*1);
			}
			else if((attFlag+1) < allCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq+1][0],goodList.equipInList[attFlagEq+1][1],13,24*1);
			}
			if((attFlag+2)<goodCount)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag+2][0],goodList.goodInList[attFlag+2][1],13,24*2);
			}
			else if((attFlag+2) < allCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq+2][0],goodList.equipInList[attFlagEq+2][1],13,24*2);
			}
			if((attFlag+3)<goodCount)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag+3][0],goodList.goodInList[attFlag+3][1],13,24*3);
			}
			else if((attFlag+3) < allCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq+3][0],goodList.equipInList[attFlagEq+3][1],13,24*3);
			}
		}
		else if(showPos == 1)
		{
			if((attFlag-1)>=goodCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq-1][0],goodList.equipInList[attFlagEq-1][1],13,24*0);
			}
			else if((attFlag-1) >=0)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag-1][0],goodList.goodInList[attFlag-1][1],13,24*0);
			}
			if(attFlag < goodCount)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag+0][0],goodList.goodInList[attFlag+0][1],13,24*1);
			}
			else if(attFlag < allCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq][0],goodList.equipInList[attFlagEq][1],13,24*1);
			}
			if((attFlag+1)<goodCount)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag+1][0],goodList.goodInList[attFlag+1][1],13,24*2);
			}
			else if((attFlag+1) < allCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq+1][0],goodList.equipInList[attFlagEq+1][1],13,24*2);
			}
			if((attFlag+2)<goodCount)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag+2][0],goodList.goodInList[attFlag+2][1],13,24*3);
			}
			else if((attFlag+2) < allCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq+2][0],goodList.equipInList[attFlagEq+2][1],13,24*3);
			}
		}
		else if(showPos == 2)
		{
			if((attFlag-2)>=goodCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq-2][0],goodList.equipInList[attFlagEq-2][1],13,24*0);
			}
			else if((attFlag-2) >=0)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag-2][0],goodList.goodInList[attFlag-2][1],13,24*0);
			}
			if((attFlag-1)>=goodCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq-1][0],goodList.equipInList[attFlagEq-1][1],13,24*1);
			}
			else if((attFlag-1) >=0)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag-1][0],goodList.goodInList[attFlag-1][1],13,24*1);
			}
			if(attFlag < goodCount)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag+0][0],goodList.goodInList[attFlag+0][1],13,24*2);
			}
			else if(attFlag < allCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq][0],goodList.equipInList[attFlagEq][1],13,24*2);
			}
			if((attFlag+1)<goodCount)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag+1][0],goodList.goodInList[attFlag+1][1],13,24*3);
			}
			else if((attFlag+1) < allCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq+1][0],goodList.equipInList[attFlagEq+1][1],13,24*3);
			}
		}
		else if(showPos == 3)
		{
			if((attFlag-3)>=goodCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq-3][0],goodList.equipInList[attFlagEq-3][1],13,24*0);
			}
			else if((attFlag-3) >=0)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag-3][0],goodList.goodInList[attFlag-3][1],13,24*0);
			}
			if((attFlag-2)>=goodCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq-2][0],goodList.equipInList[attFlagEq-2][1],13,24*1);
			}
			else if((attFlag-2) >=0)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag-2][0],goodList.goodInList[attFlag-2][1],13,24*1);
			}
			if((attFlag-1)>=goodCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq-1][0],goodList.equipInList[attFlagEq-1][1],13,24*2);
			}
			else if((attFlag-1) >=0)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag-1][0],goodList.goodInList[attFlag-1][1],13,24*2);
			}
			if(attFlag < goodCount)
			{
				ShowGoodPic(0,goodList.goodInList[attFlag+0][0],goodList.goodInList[attFlag+0][1],13,24*3);
			}
			else if(attFlag < allCount)
			{
				ShowGoodPic(0,goodList.equipInList[attFlagEq][0],goodList.equipInList[attFlagEq][1],13,24*3);
			}
		}



		MoveToEx(hdcTmp,4,10+showPos*24,NULL);
		LineTo(hdcTmp,4,25+showPos*24);
		MoveToEx(hdcTmp,5,11+showPos*24,NULL);
		LineTo(hdcTmp,5,24+showPos*24);
		MoveToEx(hdcTmp,6,12+showPos*24,NULL);
		LineTo(hdcTmp,6,23+showPos*24);
		MoveToEx(hdcTmp,7,13+showPos*24,NULL);
		LineTo(hdcTmp,7,22+showPos*24);
		MoveToEx(hdcTmp,8,14+showPos*24,NULL);
		LineTo(hdcTmp,8,21+showPos*24);
		MoveToEx(hdcTmp,9,15+showPos*24,NULL);
		LineTo(hdcTmp,9,20+showPos*24);
		MoveToEx(hdcTmp,10,16+showPos*24,NULL);
		LineTo(hdcTmp,10,19+showPos*24);
		MoveToEx(hdcTmp,11,17+showPos*24,NULL);
		LineTo(hdcTmp,11,18+showPos*24);


		char showedText[15][15];
		char text[102];
		int textLen = 0;
		int linestart = 0;
		int lineCount = 0;

		for(int u = 0; u < 102;u++)
		{
			text[u] = ' ';
		}
		for(int u = 0; u < 102;u++)
		{
			if(goodList.good[goodType-1][goodIdx-1].description[u]=='\0')
			{
				textLen = u;
				break;
			}
			text[u] = goodList.good[goodType-1][goodIdx-1].description[u];
		}

		int v = 0;
		for(v = 0;v<15;v++)
		{

			int p=0;
			for(int k = 0 ;k<14;k++)//20160625
			{
				if((int)text[linestart+k] < 128 && (int)text[linestart+k] >= 0)//单字节字符
				{
					p++;
				}
			}
			if(p%2==0)//双字节
			{
				memcpy(showedText[v],&text[linestart],14);
				showedText[v][14]='\0';
				showedText[v+1][0]='\0';
				linestart+=14;
			}
			else
			{
				memcpy(showedText[v],&text[linestart],13);
				showedText[v][13]='\0';
				showedText[v+1][0]='\0';
				linestart+=13;
			}
			if(linestart>=textLen)
			{
				lineCount = v + 1;
				break;
			}


		}
		if(attFlag2 >= (lineCount -1) )
		{
			attFlag2 = lineCount - 2;
		}
		if(attFlag2 <0 )
		{
			attFlag2 = 0;
		}
		ShowText(showedText[attFlag2],47,61);
		ShowText(showedText[attFlag2+1],47,78);

		if(attFlag<goodCount)
		{
			selectedEquipType = goodList.goodInList[attFlag][0];
			selectedEquipId =  goodList.goodInList[attFlag][1];
		}
		else
		{
			selectedEquipType = goodList.equipInList[attFlagEq][0];
			selectedEquipId =  goodList.equipInList[attFlagEq][1];
		}

		return;

	}

	map.Show(KeyCode);
	if(roleList.actor[actorShowNum].inRankFlag == 1)roleList.actor[actorShowNum].Show(KeyCode);//20160625修正位置 20170129修正
	int sx = 0;
	int sy = 0;

	if(keyflag !=0)return;
	for(int i = 0 ;i<255;i++)
	{
		if(roleList.nPC[i].showFlag == 1)
		{
			sx = roleList.nPC[i].ax - map.x;
			sy = roleList.nPC[i].ay - map.y;
			//roleList.nPC[i].PubInit(roleList.nPC[i].no);
			roleList.nPC[i].Init(-1,sx,sy);
			roleList.nPC[i].Show(0);
		}
		if(roleList.sceneObj[i].showFlag == 1)
		{
			sx = roleList.sceneObj[i].ax - map.x;
			sy = roleList.sceneObj[i].ay - map.y;
			roleList.sceneObj[i].Init(-1,sx,sy);
			roleList.sceneObj[i].Show(0);
		}
	}

	//20210911增加边框显示，用于覆盖右侧sceneObj
	BitBlt(hdcTmp, 0, 0, 7, 96, hdcMem, 0, 0, WHITENESS);
	BitBlt(hdcTmp, 151, 0, 159, 96, hdcMem, 0, 0, WHITENESS);
	MoveToEx(hdcTmp,0,0,NULL);
	LineTo(hdcTmp,0,96);
	MoveToEx(hdcTmp,2,0,NULL);
	LineTo(hdcTmp,2,96);
	MoveToEx(hdcTmp,4,0,NULL);
	LineTo(hdcTmp,4,96);
	MoveToEx(hdcTmp,6,0,NULL);
	LineTo(hdcTmp,6,96);
	MoveToEx(hdcTmp,151,0,NULL);
	LineTo(hdcTmp,151,96);
	MoveToEx(hdcTmp,153,0,NULL);
	LineTo(hdcTmp,153,96);
	MoveToEx(hdcTmp,155,0,NULL);
	LineTo(hdcTmp,155,96);
	MoveToEx(hdcTmp,157,0,NULL);
	LineTo(hdcTmp,157,96);

	//20160726修正显示主角重新更新的条件如下
	//上一行的mapnpc不为0
	//20210630增加条件roleList.actor[actorShowNum].inRankFlag == 1
	if(roleList.actor[actorShowNum].inRankFlag == 1 && map.mapNpc[map.x-1+4][map.y-1+2]!=0)
	{
		roleList.actor[actorShowNum].Show(KeyCode);//20160625修正位置
	}
	//roleList.actor[actorShowNum].Show(KeyCode);

	if(posEnable == 1)//显示坐标框
	{
		BITMAP bwh;
		int type1 = GetType(RES_ACP,2,17);
		if(type1 == 1)
		{
			LoadPic(RES_PIC,2,17,hbmp);
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			BitBlt(hdcTmp, 8, 0, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);
		}
		else
		{
			LoadPicMask(RES_PIC,2,17,hbmp);
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
			BitBlt(hdcTmp, 8, 0, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCPAINT);
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);

			LoadPicTrans(RES_PIC,2,17,hbmp);
			//GetObject(hbmp, sizeof(BITMAP), &bmp);
			oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 8, 0, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCAND);
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);
		}
		ShowNumInPic(16,4,map.x,0);
		ShowNumInPic(32,4,map.y,0);
	}
	if(KeyCode == -1)//20210806
	{
		CopyToHdc();
	}
}

/*keyflag = 0 地图界面
keyflag == 1)//say
keyflag == 2)//菜单界面
keyflag == 3)//messagebox
keyflag == 4)//choice菜单
keyflag == 5)//menu菜单
keyflag2 = 1 属性二级菜单
keyflag2 = 2 技能二级菜单
keyflag2 = 3 物品二级菜单
keyflag2 = 4 系统二级菜单
keyflag31 == 1)//显示主角属性
keyflag31 == 2)//显示穿戴
keyflag32 > 0)//显示技能
keyflag33 = 1)//显示使用
keyflag33 = 2//显示装备
keyflag332 == 1)//装备使用选择角色菜单20160719新增
keyflag34 == 1)//读取进度
keyflag34 == 2)//存储进度
keyflag34 == 3)//系统设置
keyflag431 == 1)//使用道具
keyflag432 == 1)//使用装备
keyflag433 == 1//装备界面显示道具信息
keyflag433 == 2//装备界面显示道具替换
keyflag433 == 3//装备界面显示属性改变
keyflag21 == 1)//显示技能使用确认界面
keyflag5 == 1 //购买
keyflag5 == 2 出售
keyflag51 == 1;//购买数量界面
keyflag52 == 1;//出售数量界面

*/
int ScriptEng::KeyDown(WPARAM KeyCode)
{
	wlogfile(1, __FUNCTION__ ,"KeyCode=",KeyCode);
	//printStack();
	int ret = 0;
	if(KeyCode == -1)
	{
		return -1;
	}
	else if ( keyflagret == 1)
	{
		keyflagret = 0;
		if(RunOrderCycle(orderPos)==GAMEOVER_FLAG)
		{
			return GAMEOVER_FLAG;
		}
		Show(0);
		return 0;
	}


	if(newStartFlag == 1)
	{
		Show(0);
		if(StartChapter(newStartType,newStartIdx)== GAMEOVER_FLAG)
		{
			return GAMEOVER_FLAG;
		}
	}

	if(keyflagfight == 1)//战斗界面
	{
		int ret = fight.KeyDown(KeyCode);
		if(ret == GAMEOVER_FLAG)
		{
			return GAMEOVER_FLAG;
		}
		if(ret == -1)
		{
			keyflagfight = 0;
			//战斗结束 数据处理
			AfterFight();
			Show(0);

		}
		else if(ret == -11)//20170110逃跑
		{
			keyflagfight = 0;
			//战斗结束 数据处理
			AfterFight(1);
			Show(0);

		}
		else if(ret == -2)//剧情战斗 到回合结束
		{
			//orderPos = tmpOrderPos;//20170329 //20180812增加注释
			keyflagfight = 0;
			//战斗结束 数据处理
			AfterFight();
			Show(0);
			if(RunOrderCycle(orderPos)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}

		}
		else if(ret == -3)//剧情战斗 跳转winto
		{
			keyflagfight = 0;
			//战斗结束 数据处理
			AfterFight();
			Show(0);
			//RunOrderCycle(fight.e_winto - 3 - jumpSegmentLen*2);
			if(RunOrderCycle(fight.e_winto - 3 - jumpSegmentLen*2)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}
		}
		else if(ret == -4)//剧情战斗 跳转lossto
		{
			keyflagfight = 0;
			//战斗结束 数据处理
			AfterFight();
			Show(0);
			//RunOrderCycle(fight.e_lossto - 3 - jumpSegmentLen*2);
			if(RunOrderCycle(fight.e_lossto - 3 - jumpSegmentLen*2)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}
		}
		else if(ret < -100)//剧情战斗 跳转事件号 20160118增加
		{
			if(jumpTable[ - (ret + 100) - 1] == 0)return 0;
			keyflagfight = 0;
			keyinfight = 1;
			if(tmpOrderPos == 0 )tmpOrderPos = orderPos;//20170329 20171003增加对第一次=0判断
			//RunOrderCycle(jumpTable[ - (ret + 100) - 1] - 3 - jumpSegmentLen*2);
			if(RunOrderCycle(jumpTable[ - (ret + 100) - 1] - 3 - jumpSegmentLen*2)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}

		}
	}
	else if(keyflag21 == 1)//显示技能使用确认界面
	{
		//selectedMagic = attFlag2;//存储已经选择的技能
		int act[3];
		int j = 0;
		for(int i = 0;i<25;i++)
		{
			if(roleList.actor[i].inRankFlag == 1)
			{
				int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
				act[k] = i;
				j++;
			}
		}

		if(KeyCode == KeyEsc)
		{
			keyflag21 = 0 ;
			attFlag = 0;//20170102
			attFlag2 = 0;//20170102
			keytmp = 0;
			Show(0);
		}
		else if(KeyCode == KeyPageUp || KeyCode == KeyPageDown)
		{
			attFlag ++;
			if(attFlag == 2)attFlag = 0;
			Show(0);
		}
		else if(KeyCode == KeyLeft0 || KeyCode == KeyRight0)
		{
			attFlag2 ++;
			if(attFlag2 == j)attFlag2 = 0;
			Show(0);
		}
		else if(KeyCode == KeyReturn)
		{
			//处理技能使用
			DelMagicUse();
			keyflag21 = 0 ;
			attFlag = 0;//20170102
			attFlag2 = 0;//20170102
			keytmp = 0;
			//keyflag33= 0 ;
			//keyflag2 = 0 ;
			//keyflag = 0 ;
			Show(0);

		}
	}
	else if(keyflag431 == 1)//显示道具属性改变界面
	{

		if(KeyCode == KeyEsc)
		{
			keyflag431 = 0 ;
			attFlag = selectedGood ;//20160901
			Show(0);
		}
		else if(KeyCode == KeyLeft0)
		{
			attFlag2 --;
			if(attFlag2 < 0)attFlag2 = 0;
			Show(0);
		}
		else if(KeyCode == KeyRight0)
		{
			int actmax = 0;
			for(int i = 0;i<25;i++)
			{
				if(roleList.actor[i].inRankFlag == 1)
				{
					actmax++;
				}
			}

			attFlag2 ++;
			if(attFlag2 >= actmax)attFlag2 = (actmax-1);
			Show(0);
		}
		else if(KeyCode == KeyPageUp)//pageup
		{
			attFlag = 0;
			Show(0);
		}
		else if(KeyCode == KeyPageDown)//pagedown
		{
			attFlag = 1;
			Show(0);
		}
		else if(KeyCode == KeyReturn)
		{
			//处理道具使用
			selectedRoleIdx = attFlag2;//20170118
			int ret = DelGoodEffect();//return -1 使用完毕

			//keyflag431 = 0 ;
			//keyflag33= 0 ;
			//keyflag2 = 0 ;
			//keyflag = 0 ;

			if(ret == -1)
			{
				keyflag431 = 0 ;
				attFlag = selectedGood ;//20160902
				//20160719修正道具处理
				if(attFlag>=goodList.goodInListCount&&goodList.goodInListCount<4)
				{
					attFlag--;
					if(attFlag < 0)attFlag = 0;
					showPos--;
				}
				else if(attFlag>=goodList.goodInListCount)
				{
					attFlag--;
					if(attFlag < 0)attFlag = 0;
				}

			}
			Show(0);
		}
	}
	else if(keyflag432 == 1)//显示装备属性改变界面
	{
		int i_j = 0;//20161030
		int i_enable[4];


		int t_goodType = goodList.equipInList[selectedGood][0]-1;
		int t_goodIdx = goodList.equipInList[selectedGood][1]-1;

		for(int i_p = 0 ; i_p < 4;i_p++)i_enable[i_p]=-1;
		if(goodList.good[t_goodType][t_goodIdx].owner %2 == 1&&roleList.actor[0].inRankFlag == 1)//1
		{
			i_enable[i_j]=0;
			i_j++;
		}
		if(goodList.good[t_goodType][t_goodIdx].owner %4/2 ==1&&roleList.actor[1].inRankFlag == 1)//2
		{
			i_enable[i_j]=1;
			i_j++;
		}
		if(goodList.good[t_goodType][t_goodIdx].owner %8/4 == 1 &&roleList.actor[2].inRankFlag == 1)//3
		{
			i_enable[i_j]=2;
			i_j++;
		}
		if(goodList.good[t_goodType][t_goodIdx].owner %16/8 == 1&&roleList.actor[3].inRankFlag == 1)//4
		{
			i_enable[i_j]=3;
			i_j++;
		}
		if(attFlag3 >= i_j) attFlag3 = 0;
		//attFlag3 = i_enable[0];
		if(i_j > 1 && i_enable[attFlag3] >=0)selectedRole = i_enable[attFlag3];//20161030

		int max = 2;
		int equipIdx1 = 0;
		int equipType1 = goodList.equipInList[selectedGood][0];
		if(equipType1 == 1)//head
		{
			equipIdx1 = roleList.actor[selectedRole].head;
		}
		if(equipType1 == 2)//body
		{
			equipIdx1 = roleList.actor[selectedRole].body;
		}
		if(equipType1 == 3)//foot
		{
			equipIdx1 = roleList.actor[selectedRole].foot;
		}
		if(equipType1 == 4)//shoulder
		{
			equipIdx1 = roleList.actor[selectedRole].shoulder;
		}
		if(equipType1 == 5)//sleeve
		{
			equipIdx1 = roleList.actor[selectedRole].sleeve;
		}
		if(equipType1 == 6 )//decorate1 20160228
		{
			if( decorateflag == 0 )
			{
				if(roleList.actor[selectedRole].decorate1!=0&&roleList.actor[selectedRole].decorate2!=0)
				{
					equipIdx1 = roleList.actor[selectedRole].decorate1;
				}
				else if(roleList.actor[selectedRole].decorate1!=0)
				{
					equipIdx1 = roleList.actor[selectedRole].decorate2;
				}
				else if(roleList.actor[selectedRole].decorate1==0)
				{
					equipIdx1 = roleList.actor[selectedRole].decorate1;
				}
			}
			else if( decorateflag == 0 && equipIdx1==0)
			{
				equipIdx1 = roleList.actor[selectedRole].decorate1;
			}
			else if( decorateflag == 1 )
			{
				equipIdx1 = roleList.actor[selectedRole].decorate1;
			}
			else if( decorateflag == 2 )
			{
				equipIdx1 = roleList.actor[selectedRole].decorate2;
			}
		}
		if(equipType1 == 7)//hand
		{
			equipIdx1 = roleList.actor[selectedRole].hand;
		}
		if(equipIdx1==0)max = 1;

		if(KeyCode == KeyEsc)
		{
			keyflag432 = 0 ;
			attFlag = 0;
			attFlag2 = 0;
			attFlag3 = 0;
			flagd = 0;
			flagu = 0;
			showPos = 0;
			Show(0);
		}
		else if(KeyCode == KeyPageUp || KeyCode == KeyPageDown)
		{
			attFlag ++;
			if(attFlag == 2)attFlag = 0;
			Show(0);
		}
		else if(KeyCode == KeyLeft0 || KeyCode == KeyRight0)
		{
			attFlag3 ++;
			attFlag2 = 0;

			int i_j = 0;//20161030
			int i_enable[4];


			int t_goodType = goodList.equipInList[selectedGood][0]-1;
			int t_goodIdx = goodList.equipInList[selectedGood][1]-1;

			for(int i_p = 0 ; i_p < 4;i_p++)i_enable[i_p]=-1;
			if(goodList.good[t_goodType][t_goodIdx].owner %2 == 1&&roleList.actor[0].inRankFlag == 1)//1
			{
				i_enable[i_j]=0;
				i_j++;
			}
			if(goodList.good[t_goodType][t_goodIdx].owner %4/2 ==1&&roleList.actor[1].inRankFlag == 1)//2
			{
				i_enable[i_j]=1;
				i_j++;
			}
			if(goodList.good[t_goodType][t_goodIdx].owner %8/4 == 1 &&roleList.actor[2].inRankFlag == 1)//3
			{
				i_enable[i_j]=2;
				i_j++;
			}
			if(goodList.good[t_goodType][t_goodIdx].owner %16/8 == 1&&roleList.actor[3].inRankFlag == 1)//4
			{
				i_enable[i_j]=3;
				i_j++;
			}
			if(attFlag3 >= i_j) attFlag3 = 0;
			//attFlag3 = i_enable[0];
			if(i_j > 1 && i_enable[attFlag3] >=0)selectedRole = i_enable[attFlag3];//20161030

			int max = 2;
			int equipIdx1 = 0;
			int equipType1 = goodList.equipInList[selectedGood][0];
			if(equipType1 == 1)//head
			{
				equipIdx1 = roleList.actor[selectedRole].head;
			}
			if(equipType1 == 2)//body
			{
				equipIdx1 = roleList.actor[selectedRole].body;
			}
			if(equipType1 == 3)//foot
			{
				equipIdx1 = roleList.actor[selectedRole].foot;
			}
			if(equipType1 == 4)//shoulder
			{
				equipIdx1 = roleList.actor[selectedRole].shoulder;
			}
			if(equipType1 == 5)//sleeve
			{
				equipIdx1 = roleList.actor[selectedRole].sleeve;
			}
			if(equipType1 == 6 )//decorate1 20160228
			{
				if( decorateflag == 0 )
				{
					if(roleList.actor[selectedRole].decorate1!=0&&roleList.actor[selectedRole].decorate2!=0)
					{
						equipIdx1 = roleList.actor[selectedRole].decorate1;
					}
					else if(roleList.actor[selectedRole].decorate1!=0)
					{
						equipIdx1 = roleList.actor[selectedRole].decorate2;
					}
					else if(roleList.actor[selectedRole].decorate1==0)
					{
						equipIdx1 = roleList.actor[selectedRole].decorate1;
					}
				}
				else if( decorateflag == 0 && equipIdx1==0)
				{
					equipIdx1 = roleList.actor[selectedRole].decorate1;
				}
				else if( decorateflag == 1 )
				{
					equipIdx1 = roleList.actor[selectedRole].decorate1;
				}
				else if( decorateflag == 2 )
				{
					equipIdx1 = roleList.actor[selectedRole].decorate2;
				}
			}
			if(equipType1 == 7)//hand
			{
				equipIdx1 = roleList.actor[selectedRole].hand;
			}
			if(equipIdx1==0)max = 1;


			Show(0);
		}
		else if(KeyCode == KeyUp0 || KeyCode == KeyDown0)
		{
			attFlag2 ++;
			if(attFlag2 == max)attFlag2 = 0;
			Show(0);
		}
		else if(KeyCode == KeyReturn)
		{
			//处理装备使用
			//selectedRole = attFlag2;
			if(attFlag2==0)
			{
				decorateflag = 0;//自动选择
				DelEquipUse();
			}
			keyflag432 = 0 ;
			keyflag33= 0 ;
			keyflag2 = 0 ;
			keyflag = 0 ;
			Show(0);

		}
	}
	else if(keyflag433 == 1)//显示装备界面 道具显示
	{
		//selectedGood = attFlag2;//存储已经选择的道具
		if(KeyCode == KeyEsc)
		{
			attFlag = 0;
			attFlag2 = 0;
			attFlag3 = 0;
			keyflag31 = 0;
			keyflag433 = 0;
			Show(0);
		}
		else if(KeyCode == KeyPageUp || KeyCode == KeyPageDown)
		{
			attFlag ++;
			if(attFlag == 2)attFlag = 0;
			Show(0);
		}
		else if(KeyCode == KeyUp0 || KeyCode == KeyDown0)
		{
			attFlag2 ++;
			if(attFlag2 == 3)attFlag2 = 0;
			Show(0);
		}
		else if(KeyCode == KeyReturn)
		{
			//处理道具使用
			keyflag433 = 2 ;
			attFlag = 0;
			attFlag2 = 0;
			showPos = 0;//20170116
			flagd = 0;//20170116
			flagu = 1;//20170116
			//keyflag33= 0 ;
			//keyflag2 = 0 ;
			//keyflag = 0 ;
			Show(KeyCode);


		}
	}
	else if(keyflag433 == 2)//显示装备界面 
	{
		//selectedGood = attFlag2;//存储已经选择的道具
		int max = 0;
		int goodIdx[100];
		int goodSum[100];

		for(int i = 0; i < goodList.equipInListCount ;i++)
		{
			if(goodList.equipInList[i][0] == selectedEquipType + 1)
			{
				goodIdx[max]= goodList.equipInList[i][1] - 1;
				goodSum[max]= goodList.equipInList[i][2];
				goodNo[max]= i;
				max++;
			}
		}

		if(KeyCode == KeyEsc)
		{
			attFlag = 0;
			attFlag2 = selectedRoleIdx;
			attFlag3 = 0;
			keyflag433 = 0;
			Show(0);
		}
		else if(KeyCode == KeyPageDown)//20160317修正
		{
			attFlag +=2;
			Show(KeyCode);
		}
		else if(KeyCode == KeyPageUp)
		{
			attFlag -=2;
			Show(KeyCode);
		}
		else if(KeyCode == KeyUp0 )
		{
			attFlag = 0;
			attFlag2 --;
			if(attFlag2 <= -1)attFlag2 = 0;
			Show(KeyCode);
		}
		else if(KeyCode == KeyDown0)
		{
			attFlag = 0;
			attFlag2 ++;
			if(attFlag2 >= max)attFlag2 = max - 1;
			Show(KeyCode);
		}
		else if(KeyCode == KeyReturn)
		{
			//处理道具使用
			int t_goodType = goodList.equipInList[goodNo[attFlag2]][0]-1;
			int t_goodIdx = goodList.equipInList[goodNo[attFlag2]][1]-1;

			//20161030 act获取
			int act[3];
			int j =0 ;
			for(int i = 0;i<25;i++)
			{
				if(roleList.actor[i].inRankFlag == 1)
				{
					int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
					act[k] = i;
					j++;
				}
			}


			if(goodList.good[t_goodType][t_goodIdx].owner %2 == 1 &&act[selectedRoleIdx]==0)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner >= 8 &&act[selectedRoleIdx]==3)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 2 &&act[selectedRoleIdx]==1)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 3 &&act[selectedRoleIdx]==1)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 4 &&act[selectedRoleIdx]==2)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 5 &&act[selectedRoleIdx]==2)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 6 &&act[selectedRoleIdx]==1)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 6 &&act[selectedRoleIdx]==2)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 7 &&act[selectedRoleIdx]==1)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 7 &&act[selectedRoleIdx]==2)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 10 &&act[selectedRoleIdx]==1)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 11 &&act[selectedRoleIdx]==1)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 12 &&act[selectedRoleIdx]==2)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 13 &&act[selectedRoleIdx]==2)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 14 &&act[selectedRoleIdx]==1)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 14 &&act[selectedRoleIdx]==2)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 15 &&act[selectedRoleIdx]==1)
			{
			}
			else if(goodList.good[t_goodType][t_goodIdx].owner == 15 &&act[selectedRoleIdx]==2)
			{
			}
			else 
			{
				TimerMessage("不能装备！",10,37,8,1,1000);
				Show(0);
				return 0;
			}
			keyflag433 = 3 ;
			selectedGood = goodNo[attFlag2];
			attFlag = 0;
			attFlag2 = 0;
			attFlag3 = 0;
			//keyflag33= 0 ;
			//keyflag2 = 0 ;
			//keyflag = 0 ;
			Show(KeyCode);

		}
	}
	else if(keyflag433 == 3)//显示装备界面 
	{
		//selectedGood = attFlag2;//存储已经选择的道具
		int max = 2;
		int equipIdx1 = 0;
		int equipType1 = goodList.equipInList[selectedGood][0];

		int act[3];//20161030
		int j =0 ;
		for(int i = 0;i<25;i++)
		{
			if(roleList.actor[i].inRankFlag == 1)
			{
				int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
				act[k] = i;
				j++;
			}
		}


		if(equipType1 == 1)//head
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].head;
		}
		if(equipType1 == 2)//body
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].body;
		}
		if(equipType1 == 3)//foot
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].foot;
		}
		if(equipType1 == 4)//shoulder
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].shoulder;
		}
		if(equipType1 == 5)//sleeve
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].sleeve;
		}
		if(equipType1 == 6 )//decorate1 20160228
		{
			if( decorateflag == 0 )
			{
				if(roleList.actor[act[selectedRoleIdx]].decorate1!=0&&roleList.actor[act[selectedRoleIdx]].decorate2!=0)
				{
					equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
				}
				else if(roleList.actor[act[selectedRoleIdx]].decorate1!=0)
				{
					equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate2;
				}
				else if(roleList.actor[act[selectedRoleIdx]].decorate1==0)
				{
					equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
				}
			}
			else if( decorateflag == 0 && equipIdx1==0)
			{
				equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
			}
			else if( decorateflag == 1 )
			{
				equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1;
			}
			else if( decorateflag == 2 )
			{
				equipIdx1 = roleList.actor[act[selectedRoleIdx]].decorate2;
			}
		}
		if(equipType1 == 7)//hand
		{
			equipIdx1 = roleList.actor[act[selectedRoleIdx]].hand;
		}
		if(equipIdx1==0)max = 1;

		if(KeyCode == KeyEsc)
		{
			attFlag = 0;
			attFlag2 = selectedRoleIdx;//act[selectedRoleIdx];20161120
			attFlag3 = 0;
			keyflag433 = 0;
			Show(0);
		}
		else if(KeyCode == KeyPageUp || KeyCode == KeyPageDown)
		{
			attFlag ++;
			if(attFlag == 2)attFlag = 0;
			Show(0);
		}
		else if(KeyCode == KeyUp0 || KeyCode == KeyDown0)
		{
			attFlag2 ++;
			if(attFlag2 == max)attFlag2 = 0;
			Show(0);
		}
		else if(KeyCode == KeyReturn)
		{
			//处理道具使用
			keyflag433 = 0 ;
			for(int i = 0; i < goodList.equipInListCount ; i ++)
			{
				if(goodList.equipInList[i][0] == selectedEquipType + 1 && goodList.equipInList[i][1] == selectedNewEquipId + 1)
				{
					selectedGood = i;
				}

			}
			if(attFlag2 == 0)//20170122修正为attFlag2
			{

				DelEquipUse();
			}
			//keyflag33= 0 ;
			//keyflag2 = 0 ;
			//keyflag = 0 ;
			attFlag2 = selectedRoleIdx;
			Show(0);

		}
	}
	else if(keyflag332 == 1)//20160719
	{
		ret = thirdmenu2.KeyDown(KeyCode);
		if(ret == -1)
		{
			keyflag332 = 0;
			Show(0);
			return 0;
		}
		else if(ret == 1)
		{
			keyflag432 = 1;
			keyflag332 = 0;
			//显示用户状态界面+道具
			selectedRoleIdx = thirdmenu2.stat;
			selectedGood = attFlag;//存储已经选择的道具
			attFlag = 0;
			Show(0);

			return 0;
		}
	}
	else if(keyflag31 == 1)//显示主角属性
	{
		if(KeyCode == KeyEsc)
		{
			attFlag = 0;
			attFlag2 = 0;
			attFlag3 = 0;
			keyflag31 = 0 ;
			keyflag2 = 0;
			Show(0);
			menu.Show(0);
		}
		else if(KeyCode == KeyPageUp || KeyCode == KeyPageDown)
		{
			attFlag ++;
			if(attFlag == 2)attFlag = 0;
			Show(0);
		}
		else if(KeyCode == KeyUp0)//20170319拆分
		{
			attFlag2 --;
			if(attFlag2 == -1)attFlag2 = 2;
			Show(0);
		}
		else if(KeyCode == KeyDown0)//20170319拆分
		{
			attFlag2 ++;
			if(attFlag2 == 3)attFlag2 = 0;
			Show(0);
		}

	}
	else if(keyflag31 == 2)//显示穿戴
	{
		if(KeyCode == KeyEsc)
		{
			attFlag = 0;
			attFlag2 = 0;
			attFlag3 = 0;
			keyflag31 = 0 ;
			keyflag2 = 0;
			Show(0);
			menu.Show(0);
		}
		else if(KeyCode == KeyUp0 )
		{
			attFlag --;
			if(attFlag == -1)attFlag = 0;
			Show(0);
		}
		else if(KeyCode == KeyDown0)
		{
			attFlag ++;
			if(attFlag == 8)attFlag = 7;
			Show(0);
		}
		else if(KeyCode == KeyPageUp || KeyCode == KeyPageDown)
		{
			attFlag2 ++;
			selectedRoleIdx ++;//20161231selectedRoleIdx
			if(attFlag2 == 3)
			{
				attFlag2 = 0;
				selectedRoleIdx = 0;//20170319
			}
			Show(0);
		}
		else if(KeyCode == KeyReturn)
		{
			//换装备


			int act[3];
			int j =0 ;
			for(int i = 0;i<25;i++)
			{
				if(roleList.actor[i].inRankFlag == 1)
				{
					int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
					act[k] = i;
					j++;
				}
			}

			//检测当前是否有装备
			if(roleList.actor[act[attFlag2]].decorate1!=0 && attFlag == 0)
			{
				decorateflag = 1;//20160228
				selectedEquipType = 5;
				selectedEquipId = roleList.actor[act[attFlag2]].decorate1 - 1;
			}
			else if(roleList.actor[act[attFlag2]].decorate2!=0 && attFlag == 1)
			{
				decorateflag = 2;//20160228
				selectedEquipType = 5;
				selectedEquipId = roleList.actor[act[attFlag2]].decorate2 - 1;
			}
			else if(roleList.actor[act[attFlag2]].sleeve!=0 && attFlag == 2)
			{
				selectedEquipType = 4;
				selectedEquipId = roleList.actor[act[attFlag2]].sleeve - 1;
			}
			else if(roleList.actor[act[attFlag2]].foot!=0 && attFlag == 3)
			{
				selectedEquipType = 2;
				selectedEquipId = roleList.actor[act[attFlag2]].foot - 1;
			}
			else if(roleList.actor[act[attFlag2]].hand!=0 && attFlag == 4)
			{
				selectedEquipType = 6;
				selectedEquipId = roleList.actor[act[attFlag2]].hand - 1;
			}
			else if(roleList.actor[act[attFlag2]].body!=0 && attFlag == 5)
			{
				selectedEquipType = 1;
				selectedEquipId = roleList.actor[act[attFlag2]].body - 1;
			}
			else if(roleList.actor[act[attFlag2]].shoulder!=0 && attFlag == 6)
			{
				selectedEquipType = 3;
				selectedEquipId = roleList.actor[act[attFlag2]].shoulder - 1;
			}
			else if(roleList.actor[act[attFlag2]].head!=0 && attFlag == 7)
			{
				selectedEquipType = 0;
				selectedEquipId = roleList.actor[act[attFlag2]].head - 1;
			}
			else//没有已经穿戴道具
			{
				switch (attFlag)
				{
				case 0:
					{
						decorateflag = 1;//20160228
						selectedEquipType = 5;
					}
					break;
				case 1:
					{
						decorateflag = 2;//20160228
						selectedEquipType = 5;
					}
					break;
				case 2:
					selectedEquipType = 4;
					break;
				case 3:
					selectedEquipType = 2;
					break;
				case 4:
					selectedEquipType = 6;
					break;
				case 5:
					selectedEquipType = 1;
					break;
				case 6:
					selectedEquipType = 3;
					break;
				case 7:
					selectedEquipType = 0;
					break;
				default:
					break;
				}
				selectedEquipId = 0;
				selectedRoleIdx = attFlag2;
				keyflag433 = 2;
				attFlag = 0;
				attFlag2 = 0;
				attFlag3 = 0;
				flagd = 0;
				flagu = 0;
				showPos = 0;
				Show(0);
				return 0;
			}
			selectedRoleIdx = attFlag2;
			keyflag433 = 1;
			Show(0);
			//显示当前装备属性
			//显示换装界面
		}

	}
	else if(keyflag32 > 0)//显示技能
	{
		if(KeyCode == KeyEsc)
		{
			keyflag32 = 0;
			keytmp = 0;
			attFlag = 0;
			keyflag2 = 0 ;
			Show(0);
			menu.Show(0);
		}
		else if(KeyCode == KeyUp0 )//技能列表
		{
			if(keytmp == 1)keytmp = 0;
			attFlag --;
			Show(0);
		}
		else if(KeyCode == KeyDown0)
		{
			if(keytmp == 0)keytmp = 1;
			attFlag ++;
			Show(0);
		}
		else if(KeyCode == KeyPageUp)//技能说明
		{
			attFlag2 --;
			Show(0);
		}
		else if(KeyCode == KeyPageDown)
		{
			attFlag2 ++;
			Show(0);
		}
		else if(KeyCode == KeyReturn)//使用魔法
		{
			int j = 0;
			int act[3];
			for(int i = 0;i<25;i++)
			{
				if(roleList.actor[i].inRankFlag == 1)
				{

					int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
					act[k] = i;
					//ShowHeadPic(0,i+1,10,j*30+2);
					j++;
				}
			}

			int magicType = actorMagicList[act[keyflag32-1]].magic[attFlag].type;
			int magicIdx =  actorMagicList[act[keyflag32-1]].magic[attFlag].no;


			if(magicType != 3)//只有恢复型可以使用
			{
				TimerMessage("此处无法使用！",10,37,8,1,1000);

			}
			else
			{
				selectedMagic = attFlag;//20170102修正使用魔法
				attFlag = 0;//20170102
				roleList.actor[act[keyflag32-1]].mp -= actorMagicList[act[keyflag32-1]].magic[attFlag].cost;
				if(roleList.actor[attFlag2].mp < 0 )
				{
					roleList.actor[act[keyflag32-1]].mp += actorMagicList[act[keyflag32-1]].magic[attFlag].cost;
					TimerMessage("真气不足！",10,37,8,1,1000);

				}
				else
				{
					roleList.actor[act[keyflag32-1]].mp += actorMagicList[act[keyflag32-1]].magic[attFlag].cost;
					keyflag21 = 1;
					selectedRoleIdx = keyflag32-1;//20170102
					attFlag2 = keyflag32-1;//20170102
				}

				//DelMagicUse();
			}
			Show(0);
		}

	}
	else if(keyflag33 > 0)//显示使用 装备
	{
		if(KeyCode == KeyEsc)
		{
			keyflag33 = 0 ;
			keyflag2 = 0;
			Show(0);
			menu.Show(0);
		}
		else if(KeyCode == KeyUp0 )
		{
			attFlag --;
			if(attFlag < 0 )
			{
				attFlag = 0;
			}
			attFlag2 = 0;//20160719修正
			Show(KeyCode);
		}
		else if(KeyCode == KeyDown0)
		{
			attFlag ++;
			if(goodList.goodInListCount == attFlag && keyflag33 == 1)
			{
				attFlag = goodList.goodInListCount - 1;
			}
			else if(goodList.equipInListCount == attFlag && keyflag33 == 2)
			{
				attFlag = goodList.equipInListCount - 1;
			}
			attFlag2 = 0;//20160719修正
			Show(KeyCode);
		}
		else if(KeyCode == KeyPageUp )
		{
			attFlag2 --;
			Show(0);
		}
		else if( KeyCode == KeyPageDown)
		{
			attFlag2 ++;
			Show(0);
		}

		else if(KeyCode == KeyReturn)//return 键
		{
			//判断类型后操作
			if(keyflag33 == 1)//使用
			{
				int goodType = goodList.goodInList[attFlag][0] - 1;
				int goodIdx = goodList.goodInList[attFlag][1] - 1;
				//7 12 13直接使用
				if(goodType == 7||/*goodType == 9||*/goodType == 11)//暗器,灵药，兴奋剂
				{
					TimerMessage("战斗中才能使用！",10,37,8,1,1000);
					Show(0);
				}
				else if(goodType == 12)//土遁
				{
					keyflag = 0;
					keyflag33 = 0 ;
					keyflag2 = 0;
					//RunOrderCycle(jumpTable[255 - 1] - 3 - jumpSegmentLen*2);//250事件
					if(RunOrderCycle(jumpTable[255 - 1] - 3 - jumpSegmentLen*2)==GAMEOVER_FLAG)
					{
						return GAMEOVER_FLAG;
					}
					//return -1;
				}
				else if(goodType == 13)//剧情
				{
					if(CheckResExits(RES_GUT, 255,goodIdx + 1)==1)//存在脚本资源
					{
						//处理menu跳出
						keyflag = 0;
						keyflag33 = 0 ;
						keyflag2 = 0;
						Show(0);
						//需进行资源临时保存。
						SetStackForCallChapter();
						orderPos = 0;
						keyflag = 0;
						//saveEnable = 1;
						newStartFlag = 1;//用startchaptrt函数
						newStartType = 255;
						newStartIdx = goodIdx + 1;
						//CallChapter(newStartType,newStartIdx);
						SendMessage(hwnd,WM_KEYDOWN,0,KeyReturn);

						//CallChapter(255,goodIdx + 1);//调用255-x脚本
						//Show(0);
					}
				}
				else
				{
					keyflag431= 1;
					attFlag2 = 0;//20160901
					selectedGood = attFlag;//20160901
					attFlag = 0;//20160901
					Show(0);//20160901
				}
			}
			else if(keyflag33 == 2)//装备
			{

				//20160719增加选择角色
				int act[3];
				int j = 0;
				for(int i = 0;i<25;i++)
				{
					if(roleList.actor[i].inRankFlag == 1)
					{

						int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
						act[k] = i;
						//ShowHeadPic(0,i+1,10,j*30+2);
						j++;
					}
				}

				int i_j = 0;
				int t_goodType = goodList.equipInList[attFlag][0]-1;
				int t_goodIdx = goodList.equipInList[attFlag][1]-1;
				if(goodList.good[t_goodType][t_goodIdx].owner %2 == 1&&roleList.actor[0].inRankFlag == 1)//1
				{
					thirdmenu2.SetName(roleList.actor[act[i_j]].name,i_j);

					i_j++;
				}
				if(goodList.good[t_goodType][t_goodIdx].owner %4/2 ==1&&roleList.actor[1].inRankFlag == 1)//2
				{
					thirdmenu2.SetName(roleList.actor[act[i_j]].name,i_j);

					i_j++;
				}
				if(goodList.good[t_goodType][t_goodIdx].owner %8/4 == 1 &&roleList.actor[2].inRankFlag == 1)//3
				{
					thirdmenu2.SetName(roleList.actor[act[i_j]].name,i_j);

					i_j++;
				}
				if(goodList.good[t_goodType][t_goodIdx].owner %16/8 == 1&&roleList.actor[3].inRankFlag == 1)//4
				{
					thirdmenu2.SetName(roleList.actor[act[i_j]].name,i_j);

					i_j++;
				}



				if(i_j > 1)
				{
					thirdmenu2.Init(5,i_j,50,16,8,0);
					thirdmenu2.Show (0);
					keyflag332 = 1;
				}
				else if(i_j == 0)
				{
					TimerMessage("不能装备！",10,37,8,1,1000);
					Show(0);
					return 0;
				}
				else
				{
					keyflag432 = 1;

					//显示用户状态界面+道具
					//20161030 修正默认选择对象
					selectedRoleIdx = 0;//20161030
					if(goodList.good[t_goodType][t_goodIdx].owner %2 == 1 &&roleList.actor[0].inRankFlag == 1)
					{
						if(act[0] == 0)selectedRoleIdx = 0;//20161030 20161231修正为selectedRoleIdx 20171104修复
						if(act[1] == 0)selectedRoleIdx = 1;//20161030 20161231修正为selectedRoleIdx 20171104修复
						if(act[2] == 0)selectedRoleIdx = 2;//20161030 20161231修正为selectedRoleIdx 20171104修复
					}
					else if(goodList.good[t_goodType][t_goodIdx].owner %4/2 ==1 &&roleList.actor[1].inRankFlag == 1)//2
					{
						if(act[0] == 1)selectedRoleIdx = 0;//20161030 20161231修正为selectedRoleIdx 20171104修复
						if(act[1] == 1)selectedRoleIdx = 1;//20161030 20161231修正为selectedRoleIdx 20171104修复
						if(act[2] == 1)selectedRoleIdx = 2;//20161030 20161231修正为selectedRoleIdx 20171104修复
					}
					else if(goodList.good[t_goodType][t_goodIdx].owner %8/4 == 1&&roleList.actor[2].inRankFlag == 1)//3
					{
						if(act[0] == 2)selectedRoleIdx = 0;//20161030 20161231修正为selectedRoleIdx 20171104修复
						if(act[1] == 2)selectedRoleIdx = 1;//20161030 20161231修正为selectedRoleIdx 20171104修复
						if(act[2] == 2)selectedRoleIdx = 2;//20161030 20161231修正为selectedRoleIdx 20171104修复
					}
					else if(goodList.good[t_goodType][t_goodIdx].owner %16/8 == 1&&roleList.actor[3].inRankFlag == 1)//4
					{
						if(act[0] == 3)selectedRoleIdx = 0;//20161030 20161231修正为selectedRoleIdx 20171104修复
						if(act[1] == 3)selectedRoleIdx = 1;//20161030 20161231修正为selectedRoleIdx 20171104修复
						if(act[2] == 3)selectedRoleIdx = 2;//20161030 20161231修正为selectedRoleIdx 20171104修复
					}

					selectedGood = attFlag;//存储已经选择的道具
					attFlag = 0;
					Show(0);
				}

			}
		}

	}
	else if(keyflag34 == 1)//读取进度
	{

		ret = save.KeyDown(KeyCode);
		if(ret == -1)
		{
			keyflag = 0;
			keyflag2 = 0;
			keyflag34 = 0;
			Show(0);
			return 0;
		}
		else if(ret == 1 )//读取对应的存档
		{
			keyflag = 0;
			keyflag2 = 0;
			keyflag34 = 0;


			initsaveflag = 1;
			Init();
			for(int i = 0 ; i < 255 ;i++)
			{
				//jumpTable[i]=0;
				roleList.nPC[i].showFlag =0;//NPC取消显示
				roleList.sceneObj[i].showFlag =0;//NPC取消显示
			}

			//20160301增加初始化变量
			for(int i = 0 ; i < 2400 ;i++)
			{
				globalEvent[i] =0;
			}
			for(int i = 0 ; i < 256 ;i++)
			{
				globalValue[i] =0;
			}

			//CallChapter(0,5);//20170130
			if(StartChapter(save.scriptType,save.scriptNo,1)== GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}

			ChangeSaveToData();


			map.InitMapNoEvent(map.mapType,map.mapIdx,map.x,map.y );
			map.Show(0);

			Show(0);

			if(CheckResExits(RES_GUT,0,5) == 1 && noReadScript == 0)
			{

				SetStackForCallChapter();
				orderPos = 0;
				keyflag = 0;
				//saveEnable = 1;
				newStartFlag = 1;//用startchaptrt函数
				newStartType = 0;
				newStartIdx = 5;
				//CallChapter(newStartType,newStartIdx);
				SendMessage(hwnd,WM_KEYDOWN,0,KeyReturn);
				specialCallFlag = 1;
				CallChapter(0,5);//20170130
			}


			return 0;

		}


	}
	else if(keyflag34 == 2)//存储进度
	{
		/*if(saveEnable == 0)
		{
		Show(0);
		keyflag = 0;
		keyflag2 = 0;
		keyflag34 = 0;
		TimerMessage("不能存档！",10,37,8,1,1000);
		return 0;
		}*/
		ChangeDataToSave();

		ret = save.KeyDown(KeyCode);
		if(ret == -1)
		{
			keyflag = 0;
			keyflag2 = 0;
			keyflag34 = 0;
			if(inscriptsaveflag == 1)
			{
				inscriptsaveflag = 0;
				orderPos++;
				if(RunOrderCycle(orderPos)==GAMEOVER_FLAG)
				{
					return GAMEOVER_FLAG;
				}
				return 0;
			}
			Show(0);
			return 0;
		}
		else if(ret == 1  )//写入对应的存档
		{
			keyflag = 0;
			keyflag2 = 0;
			keyflag34 = 0;
			if(inscriptsaveflag == 1)
			{
				inscriptsaveflag = 0;
				orderPos++;
				if(RunOrderCycle(orderPos)==GAMEOVER_FLAG)
				{
					return GAMEOVER_FLAG;
				}
				return 0;
			}
			Show(0);
			return 0;

		}

	}
	else if(keyflag34 == 3)//系统设置
	{
		ret = thirdmenu1.KeyDown(KeyCode);
		if(ret == -1)
		{
			keyflag2 = 0;
			keyflag34 = 0;
			Show(0);
			menu.Show(0);
			return 0;
		}
		else if(ret == 1)
		{
			keyflag34 = thirdmenu1.stat + 1;
			switch( thirdmenu1.stat)
			{
			case 0://开音乐
				{
					keyflag2 = 0;
					keyflag34 = 0;
					MusicOnOff(-1,0);

					Show(0);
					menu.Show(0);
					return 0;
				}
			case 1://关音乐
				{
					keyflag2 = 0;
					keyflag34 = 0;
					MusicOnOff(0,0);

					Show(0);
					menu.Show(0);
					return 0;
				}

			}

		}



	}
	else if(keyflag2 == 1)
	{
		ret = secondmenu1.KeyDown(KeyCode);
		if(ret == -1)
		{
			keyflag2 = 0;
			Show(0);
			menu.Show(0);
			return 0;
		}
		else if(ret == 1)
		{
			switch( secondmenu1.stat)
			{
			case 0:
				{
					keyflag31 = 1;//显示属性
					attFlag = 0;
					Show(0);
					break;
				}
			case 1:
				{
					keyflag31 = 2;//显示装备
					attFlag = 0;
					selectedRoleIdx = 0;
					Show(0);
					break;
				}
			}

		}
	}
	else if(keyflag2 == 2)
	{
		ret = secondmenu2.KeyDown(KeyCode);
		if(ret == -1)
		{
			keyflag2 = 0;
			Show(0);
			menu.Show(0);
			return 0;
		}
		else if(ret == 1)
		{
			int act[3];
			int j = 0;
			for(int i = 0;i<25;i++)
			{
				if(roleList.actor[i].inRankFlag == 1)
				{
					int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
					act[k] = i;
					j++;
				}
			}
			if(roleList.actor[act[ secondmenu2.stat]].magicLearn == 0)
			{
				keyflag2 = 0;
				Show(0);
				menu.Show(0);
				return 0;
			}
			else
			{

				keyflag32 = secondmenu2.stat + 1;
				Show(0);
			}

		}
	}
	else if(keyflag2 == 3)
	{
		ret = secondmenu3.KeyDown(KeyCode);
		if(ret == -1)
		{
			keyflag2 = 0;
			Show(0);
			menu.Show(0);
			return 0;
		}
		else if(ret == 1)
		{
			switch( secondmenu3.stat)
			{
			case 0:
				{
					keyflag33 = 1;//显示使用、
					attFlag = 0;
					attFlag2 = 0;
					attFlag3 = 0;
					flagd = 0;
					flagu = 0;
					showPos = 0;
					Show(KeyCode);
					break;
				}
			case 1:
				{
					keyflag33 = 2;//显示装备、
					attFlag = 0;
					attFlag2 = 0;
					attFlag3 = 0;
					flagd = 0;
					flagu = 0;
					showPos = 0;
					Show(KeyCode);
					break;
				}
			}
		}
	}
	else if(keyflag2 == 4)
	{
		ret = secondmenu4.KeyDown(KeyCode);
		if(ret == -1)
		{
			keyflag2 = 0;
			Show(0);
			menu.Show(0);
			return 0;
		}
		else if(ret == 1)
		{
			keyflag34 = secondmenu4.stat + 1;
			switch( secondmenu4.stat)
			{
			case 0://读取进度
				{
					save.Init(0);//0-读
					save.Read(-1);
					save.Show();
					break;
				}
			case 1:
				{
					if(saveEnable == 0 && allowSave == 0)
					{
						Show(0);
						keyflag = 0;
						keyflag2 = 0;
						keyflag34 = 0;
						TimerMessage("目前不能存档！",10,37,8,1,1000);
						return 0;
					}
					save.Init(1);//1-写
					save.Read(-1);
					save.Show();

					break;
				}
			case 2:
				{
					//游戏设置
					keyflag34 = 3;
					Show(0);
					//menu.Init(2,4,10,24,0,money);
					menu.Show(0);
					//secondmenu4.Init(4,-3,40,30,4,money);
					secondmenu4.Show(KeyDown0);
					thirdmenu1.Init(3,2,80,50,5,money);
					thirdmenu1.Show(0);
					break;
				}
			case 3://结束游戏
				{
					return -1;
				}
			}

		}
	}
	else if(keyflag51 == 1)//显示购买数量
	{
		if(KeyCode == KeyEsc)
		{
			keyflag51 = 0 ;
			attFlag = selectedGood;
			Show(0);
		}
		else if(KeyCode == KeyUp0 )
		{
			attFlag ++;
			if(attFlag > MAX_GOOD_IN_HAND) attFlag =MAX_GOOD_IN_HAND;
			Show(0);
		}
		else if(KeyCode ==  KeyDown0)
		{
			attFlag --;
			if(attFlag < 0) attFlag =0;
			Show(0);
		}
		else if(KeyCode == KeyReturn)
		{
			keyflag51 = 0 ;

			//处理商店购买
			DelBuyGood();
			attFlag = selectedGood;
			Show(0);
		}

	}
	else if(keyflag52 == 1)//显示出售数量
	{
		if(KeyCode == KeyEsc)
		{
			keyflag52 = 0 ;
			attFlag = selectedGood;
			Show(0);
		}
		else if(KeyCode == KeyUp0 )
		{
			attFlag ++;
			Show(0);
		}
		else if(KeyCode ==  KeyDown0)
		{
			attFlag --;
			if(attFlag < 0) attFlag =0;
			Show(0);
		}
		else if(KeyCode == KeyReturn)
		{
			keyflag52 = 0 ;

			//处理商店购买
			int tmp  = goodList.goodInListCount+goodList.equipInListCount;
			DelSellGood();
			int tmp1  = goodList.goodInListCount+goodList.equipInListCount;
			if (tmp1 < tmp && selectedGood >= (tmp1-3)&& tmp1>3)
			{
				attFlag = selectedGood-1;
			}
			else if (tmp1 < tmp && tmp1<=3 && selectedGood >= tmp1)
			{
				attFlag = selectedGood-1;
				showPos --;
			}
			else
			{
				attFlag = selectedGood;
			}
			Show(0);
		}

	}
	else if(keyflag5 == 1)//显示商店出售界面
	{
		if(KeyCode == KeyEsc)
		{
			keyflag5 = 0 ;
			attFlag = 0;
			Show(0);
			if(RunOrderCycle(orderPos)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}
		}
		else if(KeyCode == KeyUp0 )
		{
			attFlag --;
			if(attFlag < 0 )
			{
				attFlag = 0;
			}
			attFlag2 = 0;//20160719修正
			Show(KeyCode);
		}
		else if(KeyCode == KeyDown0)
		{
			attFlag ++;
			if(g_goodSum == attFlag)
			{
				attFlag = g_goodSum - 1;
			}
			attFlag2 = 0;//20160719修正
			Show(KeyCode);
		}
		else if(KeyCode == KeyPageUp )//20181230
		{
			attFlag2 --;
			Show(0);
		}
		else if( KeyCode == KeyPageDown )//20181230
		{
			attFlag2 ++;
			Show(0);
		}
		else if(KeyCode == KeyReturn)
		{



			//金钱不足判断
			if(money < goodList.good[g_goodType[attFlag]-1][g_goodId[attFlag]-1].buy)
			{
				TimerMessage("金钱不足！",10,37,8,1,1000);
				Show(0);
				return 0;
			}
			selectedGood = attFlag;
			attFlag = 0;
			keyflag51 = 1 ;
			Show(0);

		}

	}
	else if(keyflag5 == 2)//显示商店收购界面
	{
		if(KeyCode == KeyEsc)
		{
			keyflag5 = 0 ;
			attFlag = 0;
			Show(0);
			if(RunOrderCycle(orderPos)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}

		}
		else if(KeyCode == KeyUp0 )
		{
			attFlag --;
			if(attFlag < 0 )
			{
				attFlag = 0;
			}
			attFlag2 = 0;//20160719修正
			Show(KeyCode);
		}
		else if(KeyCode == KeyDown0)
		{
			attFlag ++;
			if((goodList.goodInListCount+goodList.equipInListCount) == attFlag)
			{
				attFlag = (goodList.goodInListCount+goodList.equipInListCount) - 1;
			}
			attFlag2 = 0;//20160719修正
			Show(KeyCode);
		}
		else if(KeyCode == KeyPageUp )
		{
			attFlag2 --;
			Show(0);
		}
		else if( KeyCode == KeyPageDown)
		{
			attFlag2 ++;
			Show(0);
		}
		else if(KeyCode == KeyReturn)
		{
			selectedGood = attFlag;
			attFlag = 0;
			keyflag52 = 1 ;
			Show(0);

		}

	}
	else if(keyflag == 0)
	{

		if(KeyCode == KeyEsc)
		{
			keyflag = 2;
			menu.Init(2,4,10,24,0,money);
			menu.Show(0);
		}
		else if(KeyCode == KeyInsert)//20160116新增4功能按键 0-6
		{
			//需进行资源临时保存。
			SetStackForCallChapter();
			orderPos = 0;
			keyflag = 0;
			//saveEnable = 1;
			newStartFlag = 1;//用startchaptrt函数
			newStartType = 0;
			newStartIdx = 6;
			//CallChapter(newStartType,newStartIdx);
			SendMessage(hwnd,WM_KEYDOWN,0,KeyReturn);
		}
		else if(KeyCode == KeyDelete)//20160116新增4功能按键 7
		{
			//需进行资源临时保存。
			SetStackForCallChapter();
			orderPos = 0;
			keyflag = 0;
			//saveEnable = 1;
			newStartFlag = 1;//用startchaptrt函数
			newStartType = 0;
			newStartIdx = 7;
			//CallChapter(newStartType,newStartIdx);
			SendMessage(hwnd,WM_KEYDOWN,0,KeyReturn);
		}
		else if(KeyCode == KeyHome)//20160116新增4功能按键 8
		{
			//需进行资源临时保存。
			SetStackForCallChapter();
			orderPos = 0;
			keyflag = 0;
			//saveEnable = 1;
			newStartFlag = 1;//用startchaptrt函数
			newStartType = 0;
			newStartIdx = 8;
			//CallChapter(newStartType,newStartIdx);
			SendMessage(hwnd,WM_KEYDOWN,0,KeyReturn);
		}
		else if(KeyCode == KeyEnd)//20160116新增4功能按键 9
		{
			//需进行资源临时保存。
			SetStackForCallChapter();
			orderPos = 0;
			keyflag = 0;
			//saveEnable = 1;
			newStartFlag = 1;//用startchaptrt函数
			newStartType = 0;
			newStartIdx = 9;
			//CallChapter(newStartType,newStartIdx);
			SendMessage(hwnd,WM_KEYDOWN,0,KeyReturn);
		}
		else if(KeyCode == KeyN)//20161221 自动按键
		{
			autowalkflag = (autowalkflag == 0)?1:0;
		}
		else
		{
			//if(KeyCode != KeyDown0&&KeyCode != KeyUp0&&KeyCode != KeyLeft0&&KeyCode != KeyRight0)return 0;
			ret = map.KeyDown(KeyCode);//返回值判断是否触发事件的事件号

			roleList.actor[actorShowNum].KeyDown(KeyCode);
			Show(0);
			if(ret > 0 && jumpTable[40 + ret - 1] > 0 && map.dirction != 0)//地图事件
			{
				//RunOrderCycle(jumpTable[40 + ret - 1] - 3 - jumpSegmentLen*2);
				if(RunOrderCycle(jumpTable[40 + ret - 1] - 3 - jumpSegmentLen*2)==GAMEOVER_FLAG)
				{
					return GAMEOVER_FLAG;
				}
			}
			else if(ret < 0)//npc事件
			{
				if(ret < -100)//sceneobj事件
				{
					roleList.sceneObj[-ret-100-1].KeyDown(0);

				}
				ret = ret % 100;
				if(jumpTable[- ret  - 1]>0)
				{
					//RunOrderCycle(jumpTable[- ret  - 1] - 3 - jumpSegmentLen*2);
					if(RunOrderCycle(jumpTable[- ret  - 1] - 3 - jumpSegmentLen*2)==GAMEOVER_FLAG)
					{
						return GAMEOVER_FLAG;
					}
				}
			}
			else if(fightEnable == 1 && runDebug == 0 && rand()%100 > 90)//进入随机战斗
			{
				int ret1 = fight.UsedInit();
				if(ret1 != -1)
				{
					//fighthero初始化
					fight.enemySum = 0;
					fight.livedEnemySum = 0;
					fight.randomEnemy();
					SetFightHeroData();
					fight.Show(KeyCode);
					keyflagfight = 1 ;
				}



			}

			//return ret;
		}
	}
	else if(keyflag == 1&&KeyCode!=0)//say
	{
		ret = sayBox.KeyDown(KeyCode);
		if(ret == -1)
		{
			keyflag = 0;
			Show(0);
			//ret = map.KeyDown(KeyCode);
			//ret = roleList.actor[0].KeyDown(KeyCode);
			if(RunOrderCycle(orderPos)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}
		}
	}
	else if(keyflag == 2)//菜单
	{

		ret = menu.KeyDown(KeyCode);
		if(ret == -1)
		{
			keyflag = 0;
			Show(0);
			return 0;
		}
		else if(ret == 1)
		{
			keyflag2 = menu.stat+1;
			switch(keyflag2)
			{
			case 1 :
				secondmenu1.Init(2,2,40,16,1,money);
				secondmenu1.Show (0);
				break;
			case 2 :
				{
					int act[3];
					int j = 0;
					int len = 0;
					int k = 0;
					for(int i = 0;i<3;i++)
					{
						act[i] = 0;
					}
					secondmenu2.nameNum = 0;
					for(int i = 0;i<25;i++)
					{
						if(roleList.actor[i].inRankFlag == 1)
						{
							k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG

							secondmenu2.SetName(roleList.actor[i].name,k);
							if(len < strlen(roleList.actor[i].name)/2)
							{
								len = strlen(roleList.actor[i].name)/2;
							}
							act[k] = i;
							//ShowHeadPic(0,i+1,10,j*30+2);
							j++;
						}
					}
					if(j > 1)
					{

						secondmenu2.Init(len,j,40,16,2,money);
						secondmenu2.Show (0);
					}
					else
					{
						if(roleList.actor[act[0]].magicLearn == 0)
						{
							keyflag2 = 0;
							Show(0);
							menu.Show(0);
							return 0;
						}
						else
						{
							keyflag32 = 1;
							Show (0);
						}
					}
					break;
				}
			case 3 :

				secondmenu3.Init(2,2,40,40,3,money);
				secondmenu3.Show (0);
				break;
			case 4 :
				secondmenu4.Init(4,-3,40,30,4,money);
				secondmenu4.Show (KeyUp0);
				break;
			}
		}
	}
	else if(keyflag == 3&&KeyCode!=0)//messagebox 20160727新增对起始位置为0的情况的不处理
	{
		if(tmp_order_msg_add == 0)
		{
			keyflag = 0;
			if(RunOrderCycle(orderPos)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}
		}
		else
		{
			tmp_order_msg_add = 0;
		}

	}

	else if(keyflag == 4&&KeyCode!=0)//choice菜单
	{
		ret = gameMenu.KeyDown(KeyCode);
		if(ret == 1)
		{
			keyflag = 0;
			//选择第一项 直接下一指令
			if(RunOrderCycle(orderPos)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}
			//Show(0);
		}
		else if(ret == 2)
		{
			keyflag = 0;

			//选择第2项  跳转orderChoiceJmpPos
			int tmpOrderChoiceJmpPos = orderChoiceJmpPos;
			if(RunOrderCycle(orderChoiceJmpPos)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}

			if(tmpOrderChoiceJmpPos == orderChoiceJmpPos)
			{
				orderChoiceJmpPos = 0;
			}
			//Show(0);
		}
		else
		{
			Show(0);
			gameMenu.Show(0);
		}
	}
	else if(keyflag == 5&&KeyCode!=0)//menu菜单
	{
		ret = gameMenu.KeyDown(KeyCode);//返回选择项
		if(ret > 0 )//选择入变量
		{
			keyflag = 0;
			if(gameMenu.vauleNo >0)
			{
				globalValue[gameMenu.vauleNo-1] = ret;
			}
			else if(gameMenu.vauleNo == 0)
			{
				globalValue[255] = ret;
			}
			Show(0);
			if(RunOrderCycle(orderPos)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}

		}
		else if(ret == -1) //退出键
		{
			keyflag = 0;
			if(gameMenu.vauleNo >0)
			{
				globalValue[gameMenu.vauleNo-1] = 0;
			}
			else if(gameMenu.vauleNo == 0)
			{
				globalValue[255] = 0;
			}
			Show(0);
			if(RunOrderCycle(orderPos)==GAMEOVER_FLAG)
			{
				return GAMEOVER_FLAG;
			}


		}
		else //方向键
		{
			Show(0);
			gameMenu.Show(0);
		}
	}
	return 0;
}

void ScriptEng::ChangeDataToSave()
{
	wlogfile(1, __FUNCTION__ ,"---------------------存档-----------------------",0);
	memcpy(save.gameName,libByte+3,8);
	del_sp(save.gameName);
	memcpy(save.sceneName,map.mapName,8);
	save.actorNum = 0;
	for(int i1 = 0 ; i1 < 25 ;i1++)
	{
		if(roleList.actor[i1].inRankFlag == 1)
		{
			int k = roleList.actor[i1].inRankId;
			save.actorNo[k]= roleList.actor[i1].no;
			save.actorNum ++;
			if(save.actorNum >=3)break;
		}
	}
	/*if(roleList.actor[1].inRankFlag == 1)
	{
	save.actorNo[save.actorNum]= roleList.actor[1].no;
	save.actorNum ++;
	}
	if(roleList.actor[2].inRankFlag == 1)
	{
	save.actorNo[save.actorNum]= roleList.actor[2].no;
	save.actorNum ++;
	}
	if(roleList.actor[3].inRankFlag == 1)
	{
	save.actorNo[save.actorNum]= roleList.actor[3].no;
	save.actorNum ++;
	}*/

	save.mapType = map.mapType;
	save.mapNo = map.mapIdx;
	save.mapX = map.x;
	save.mapY = map.y;
	save.scriptType = scriptType;
	save.scriptNo = scriptIndex;
	for(int i = 0 ; i < 25 ; i ++)
	{
		save.actorInfo[i][0] = roleList.actor[i].degree;
		save.actorInfo[i][1] = roleList.actor[i].att;
		save.actorInfo[i][2] = roleList.actor[i].def;
		save.actorInfo[i][3] = roleList.actor[i].speed;
		save.actorInfo[i][4] = roleList.actor[i].hp;
		save.actorInfo[i][5] = roleList.actor[i].mp;
		save.actorInfo[i][6] = roleList.actor[i].exp;
		save.actorInfo[i][7] = roleList.actor[i].expMax;
		save.actorInfo[i][8] = roleList.actor[i].anima;
		save.actorInfo[i][9] = roleList.actor[i].lucky;
		save.actorInfo[i][10] = roleList.actor[i].disround;
		save.actorInfo[i][11] = roleList.actor[i].anti;
		save.actorInfo[i][12] = roleList.actor[i].atcause;
		save.actorInfo[i][13] = roleList.actor[i].togethermagic;
		save.actorInfo[i][14] = roleList.actor[i].hpAdd;
		save.actorInfo[i][15] = roleList.actor[i].mpAdd;
		save.actorInfo[i][16] = roleList.actor[i].head;
		save.actorInfo[i][17] = roleList.actor[i].body;
		save.actorInfo[i][18] = roleList.actor[i].shoulder;
		save.actorInfo[i][19] = roleList.actor[i].sleeve;
		save.actorInfo[i][20] = roleList.actor[i].hand;
		save.actorInfo[i][21] = roleList.actor[i].foot;
		save.actorInfo[i][22] = roleList.actor[i].decorate1;
		save.actorInfo[i][23] = roleList.actor[i].decorate2;
		save.actorInfo[i][24] = roleList.actor[i].hpMax;
		save.actorInfo[i][25] = roleList.actor[i].mpMax;
		save.actorInfo[i][26] = roleList.actor[i].magicMaxInList;
		save.actorInfo[i][27] = roleList.actor[i].magicLearn;
		save.actorInfo[i][28] = roleList.actor[i].magicListNo;//20181007
	}
	save.money = money;
	save.goodListCount = goodList.goodInListCount;
	save.equipListCount = goodList.equipInListCount;
	for(int i = 0 ; i < 2731 ; i ++)
	{
		save.goodList[i][0]= goodList.goodInList[i][0];
		save.goodList[i][1]= goodList.goodInList[i][1];
		save.goodList[i][2]= goodList.goodInList[i][2];
		save.equipList[i][0]= goodList.equipInList[i][0];
		save.equipList[i][1]= goodList.equipInList[i][1];
		save.equipList[i][2]= goodList.equipInList[i][2];
	}
	for(int i = 0 ; i < 2400 ; i ++)
	{
		save.globalEvent[i] = globalEvent[i]; 
	}
	for(int i = 0 ; i < 256 ; i ++)
	{
		save.globalValue[i] = globalValue[i]; 
	}

	save.saveEnable = saveEnable;
	save.fightEnable = fightEnable;
	for(int i = 0 ; i < 8 ; i ++)
	{
		save.fightSave[i] = fight.enemyType[i];
	}
	save.fightSave[8] = fight.scrb;
	save.fightSave[9] = fight.scrl;
	save.fightSave[10] = fight.scrr;

	for(int i = 0 ; i < 255 ; i ++)
	{
		save.npcSaved[i][0] = roleList.nPC[i].showFlag;
		save.npcSaved[i][1] = roleList.nPC[i].ax;
		save.npcSaved[i][2] = roleList.nPC[i].ay;
		save.npcSaved[i][3] = roleList.nPC[i].picno;
		save.npcSaved[i][4] = roleList.nPC[i].action ;
		save.npcSaved[i][5] = roleList.nPC[i].faceTo;//20210627
		save.npcSaved[i][6] = roleList.nPC[i].step;//20210627
		save.npcSaved[i][7] = roleList.nPC[i].no;//20210627
	}
	save.controlId = actorShowNum ;

	for(int i = 0 ; i < 25 ; i ++)
	{
		save.magicMax[i] = actorMagicList[i].magicCount;
		//save.magicMax[i] = magicList[roleList.actor[i].magicListNo-1].magicCount;
		save.magicExLearned[i] = actorMagicList[i].exLearned;
		for(int j = 0 ; j < save.magicMax[i] ; j ++)
		{
			save.magicSaved[i][j][0] = actorMagicList[i].magic[j].type;
			save.magicSaved[i][j][1] = actorMagicList[i].magic[j].no;
		}
	}

	save.missflag = missflag ;
	save.throwflag = throwflag ;

	for(int i = 0 ; i < 255 ; i ++)
	{
		save.sceneObjSaved[i][0] = roleList.sceneObj[i].showFlag;
		save.sceneObjSaved[i][1] = roleList.sceneObj[i].ax;
		save.sceneObjSaved[i][2] = roleList.sceneObj[i].ay;
		save.sceneObjSaved[i][3] = roleList.sceneObj[i].picno;
		save.sceneObjSaved[i][4] = roleList.sceneObj[i].action ;
	}
	save.posEnable = posEnable ;//20160811
	save.timeEventNo = timeEventNo ;//20161221
	save.timeEventSecond = timeEventSecond ;//20161221
	save.timeEventNum = timeEventNum ;//20161221
	save.versionno = version_now ;//20170115
}

void ScriptEng::ChangeSaveToData()
{
	wlogfile(1, __FUNCTION__ ,"---------------------读档-----------------------",0);
	//需增加存档前清理数据工作20170308修正4～25
	for(int i = 0 ; i < 25 ;i ++)
	{
		roleList.actor[i].inRankFlag = 0;
		roleList.actor[i].inRankId = 0;
	}

	memcpy(this->sceneName,save.sceneName,8);
	for(int i = 0 ; i < save.actorNum;i++)
	{
		roleList.actor[save.actorNo[i]-1].inRankFlag = 1;
		roleList.actor[save.actorNo[i]-1].inRankId = i;//20170308
	}

	//20210829清理MAPNPC
	for (int i = 0; i < 256 ;i ++)
	{
		for(int j = 0; j < 256 ;j++)
		{
			map.mapNpc[i][j] = 0;
		}
	}

	map.mapType = save.mapType ;
	map.mapIdx = save.mapNo;
	map.x = save.mapX ;
	map.y = save.mapY ;
	scriptType = save.scriptType ;
	scriptIndex = save.scriptNo ;
	orderPos = 0;//20210829修正白屏问题
	for(int i = 0 ; i < 25 ; i ++)
	{
		//if(roleList.actor[i].inRankFlag != 1)continue;//20170118修正
		roleList.actor[i].degree         = save.actorInfo[i][0];
		roleList.actor[i].att            = save.actorInfo[i][1]; 
		roleList.actor[i].def            = save.actorInfo[i][2]; 
		roleList.actor[i].speed          = save.actorInfo[i][3]; 
		roleList.actor[i].hp             = save.actorInfo[i][4]; 
		roleList.actor[i].mp             = save.actorInfo[i][5]; 
		roleList.actor[i].exp            = save.actorInfo[i][6]; 
		roleList.actor[i].expMax         = save.actorInfo[i][7]; 
		roleList.actor[i].anima          = save.actorInfo[i][8]; 
		roleList.actor[i].lucky          = save.actorInfo[i][9]; 
		roleList.actor[i].disround       = save.actorInfo[i][10];
		roleList.actor[i].anti           = save.actorInfo[i][11];
		roleList.actor[i].atcause        = save.actorInfo[i][12];
		roleList.actor[i].togethermagic  = save.actorInfo[i][13];
		roleList.actor[i].hpAdd          = save.actorInfo[i][14];
		roleList.actor[i].mpAdd          = save.actorInfo[i][15];
		roleList.actor[i].head           = save.actorInfo[i][16];
		roleList.actor[i].body           = save.actorInfo[i][17];
		roleList.actor[i].shoulder       = save.actorInfo[i][18];
		roleList.actor[i].sleeve         = save.actorInfo[i][19];
		roleList.actor[i].hand           = save.actorInfo[i][20];
		roleList.actor[i].foot           = save.actorInfo[i][21];
		roleList.actor[i].decorate1      = save.actorInfo[i][22];
		roleList.actor[i].decorate2      = save.actorInfo[i][23];
		roleList.actor[i].hpMax          = save.actorInfo[i][24];
		roleList.actor[i].mpMax          = save.actorInfo[i][25];
		roleList.actor[i].magicMaxInList = save.actorInfo[i][26];
		roleList.actor[i].magicLearn     = save.actorInfo[i][27];
		roleList.actor[i].magicListNo    = save.actorInfo[i][28];//20170115
	}
	money = save.money;
	goodList.goodInListCount = save.goodListCount;
	goodList.equipInListCount = save.equipListCount;
	for(int i = 0 ; i < 2731 ; i ++)
	{
		goodList.goodInList[i][0]  = save.goodList[i][0] ;
		goodList.goodInList[i][1]  = save.goodList[i][1] ;
		goodList.goodInList[i][2]  = save.goodList[i][2] ;
		goodList.equipInList[i][0] = save.equipList[i][0]; 
		goodList.equipInList[i][1] = save.equipList[i][1]; 
		goodList.equipInList[i][2] = save.equipList[i][2]; 
	}
	for(int i = 0 ; i < 2400 ; i ++)
	{
		globalEvent[i] = save.globalEvent[i]; 
	}
	for(int i = 0 ; i < 256 ; i ++)
	{
		globalValue[i] = save.globalValue[i]; 
	}

	saveEnable = save.saveEnable;

	fightEnable = save.fightEnable;

	//20160302

	for(int i = 0 ; i < 8 ; i ++)
	{
		fight.enemyType[i] = save.fightSave[i];
	}
	fight.scrb = save.fightSave[8];
	fight.scrl = save.fightSave[9];
	fight.scrr = save.fightSave[10];


	for(int i = 0 ; i < 255 ; i ++)
	{
		if(save.npcSaved[i][0] == 1)//showFlag 20210627
		{
			roleList.nPC[i].PubInit(save.npcSaved[i][7]);//no 20210627
		}
		roleList.nPC[i].showFlag = save.npcSaved[i][0];
		roleList.nPC[i].ax = save.npcSaved[i][1];
		roleList.nPC[i].ay = save.npcSaved[i][2];
		roleList.nPC[i].picno = save.npcSaved[i][3];
		roleList.nPC[i].action = save.npcSaved[i][4];
		roleList.nPC[i].faceTo = save.npcSaved[i][5];//20210627
		roleList.nPC[i].step = save.npcSaved[i][6];//20210627
		roleList.nPC[i].no = save.npcSaved[i][7];//20210627
		if(roleList.nPC[i].showFlag == 1)
		{
			map.mapNpc[roleList.nPC[i].ax-1][roleList.nPC[i].ay-1] = i+1;
		}
	}

	actorShowNum = save.controlId;

	for(int i = 0 ; i < 25 ; i ++)
	{
		if(roleList.actor[i].inRankFlag != 1)continue;//20170118修正
		actorMagicList[i].magicCount = save.magicMax[i];
		actorMagicList[i].exLearned = save.magicExLearned[i];
		for(int j = 0 ; j < save.magicMax[i] ; j ++)
		{
			//actorMagicList[roleList.actor[i].magicListNo-1].magic[j].Init(save.magicSaved[i][j][0],save.magicSaved[i][j][1]);
			actorMagicList[i].magic[j].Init(save.magicSaved[i][j][0],save.magicSaved[i][j][1]);
			//magicList[roleList.actor[i].magicListNo-1].magic[j].type = save.magicSaved[i][j][0];
			//magicList[roleList.actor[i].magicListNo-1].magic[j].no = save.magicSaved[i][j][1];
		}
	}
	missflag = save.missflag;
	throwflag = save.throwflag;

	for(int i = 0 ; i < 255 ; i ++)
	{
		roleList.sceneObj[i].showFlag = save.sceneObjSaved[i][0] ;
		roleList.sceneObj[i].ax = save.sceneObjSaved[i][1] ;
		roleList.sceneObj[i].ay = save.sceneObjSaved[i][2]  ;
		roleList.sceneObj[i].picno = save.sceneObjSaved[i][3]  ;
		roleList.sceneObj[i].action = save.sceneObjSaved[i][4]  ;
		if(roleList.sceneObj[i].showFlag == 1)
		{
			SetObjMapNpc(roleList.sceneObj[i].ax-1,roleList.sceneObj[i].ay-1,i+1,0);
		}
		else
		{
			SetObjMapNpc(roleList.sceneObj[i].ax-1,roleList.sceneObj[i].ay-1,0,1);
		}
	}
	posEnable = save.posEnable ;//20160811
	timeEventNo = save.timeEventNo ;//20161221
	timeEventSecond = save.timeEventSecond ;//20161221
	timeEventNum = save.timeEventNum ;//20161221
}

int ScriptEng::CallChapter(int type,int index)
{
	wlogfile(1, __FUNCTION__ ,"开始",0); 
	int resnum = GetResNum( RES_GUT,type,index);
	newStartFlag = 0;
	//effecttype = resByte[resnum][0];
	scriptType = resByte[resnum][0];
	scriptIndex = resByte[resnum][1];
	scriptByteLen = BytesToInt2(&resByte[resnum][24]);
	jumpSegmentLen = resByte[resnum][26];
	orderByteLen = scriptByteLen - jumpSegmentLen*2;
	orderByteStart = jumpSegmentLen*2 + 27;

	wlogfile(1, __FUNCTION__ ,"scriptType = ",scriptType); 
	wlogfile(1, __FUNCTION__ ,"scriptIndex = ",scriptIndex); 

	//跳转段
	for(int i = 0;i < jumpSegmentLen;i++)
	{
		jumpTable[i]=BytesToInt2(&resByte[resnum][27+i*2]);
	}

	//指令段
	for(int i = 0 ;i < orderByteLen;i ++)
	{
		orderByte[i] = resByte[resnum][i + orderByteStart];
	}
	if(RunOrderCycle(0)==GAMEOVER_FLAG)
	{
		return GAMEOVER_FLAG;
	}
	return 0;
}

int ScriptEng::RunOrderCycle(int startOrderPos)
{
	//wlogfile(1, __FUNCTION__ ,"开始",0);
	wlogfile(1, __FUNCTION__ ,"startOrderPos = ",startOrderPos);
	int i = 0;
	if(orderByteLen == 0)return GAMEOVER_FLAG;//20160812修正错误脚本
	for(i = startOrderPos ;i < orderByteLen;i ++)
	{
		orderType = orderByte[i];
		orderParaNum = GetOrderParaNum(orderType);
		startAddress = i;
		parmNum = orderParaNum;

		if(orderType == 66)
		{
			this->orderPos = i+5;
		}
		if(orderType == 0)
		{
			orderType=0;
		}

		//20161108 断点调试中断位置
		if(g_debugFlag==1)
		{
			g_dgOrderPos = i;
			DgCheckSysMsg();
			DgCheckRet(orderType,i);//判断命中或返回 orderType 位置码
		}
		orderParaLen = ExecOrder(orderType);

		//20160727增加gameover处理
		if(orderParaLen == GAMEOVER_FLAG)
		{
			return GAMEOVER_FLAG;
		}
		if(orderType == 9)
		{
			break;
		}

		if(orderType == 68 && orderParaLen != -1 )//return//20170329增加-1判断
		{
			if(finishflag == 0)
			{
				keyflagret = 1;
				SendMessage(hwnd,WM_KEYDOWN,0,KeyReturn);
			}
			return 0;
		}

		if(orderParaLen == 317)//startchapter 直接返回
		{
			return 0;
		}
		//if(orderType == 11)
		{

			//break;
		}
		if(orderParaLen<0)
		{
			orderParaLen = - orderParaLen;//如果返回负数，说明有退出循环
			if(orderParaLen == 1)
			{
				orderParaLen = 0;
			}
			if(orderParaLen == 2001)
			{
				orderParaLen = 1;
			}
			i+= orderParaLen;//需注意。-数返回是break 因此不会i++ 因负数返回值包含指令1个字节，正数则不包含
			break;
		}

		if(orderParaLen>=20000)
		{
			//20160812 -3为前面3个字节长度 -1为 0-1修正 -1为i++修正 如果scriptType为0转为1 （真他妈扯淡,特殊调用脚本直接跳转还少1，这什么程序。。）
			//20160816 修正index<6才出来
			i = orderParaLen - 20000  - 3 - jumpSegmentLen*2 - 1 ;//20161204 恢复修正- ((scriptType==0 && scriptIndex<6)?1:0); //20160117去4 20160118修正 
		}
		else
		{
			i+= orderParaLen;
		}
	}
	if(orderParaLen == 317)//startchapter 直接返回
	{
		return 0;
	}
	if(specialCallFlag == 2)//20210829修正读档后调用0-6等白屏
	{
		specialCallFlag = 0;
	}
	else
	{
		this->orderPos = i;
	}
	return 0;
}
int ScriptEng::StartChapter(int type,int index,int runornot)//,int runornot-是否执行
{
	//wlogfile(1, __FUNCTION__ ,"开始",0);
	wlogfile(1, __FUNCTION__ ,"type = ",type);
	wlogfile(1, __FUNCTION__ ,"index = ",index);
	int resnum = GetResNum( RES_GUT,type,index);
	if(resnum == -1)//20161225
	{
		if(type == 0 && index >= 6)
		{
			getStackForRun();
			return 0;
		}
		else//r3
		{
			//TimerMessage("runerror3",12,37,10,1,1000);
			return GAMEOVER_FLAG;
		}
	}
	//effecttype = resByte[resnum][0];
	newStartFlag = 0;
	scriptType = resByte[resnum][0];
	scriptIndex = resByte[resnum][1];
	scriptByteLen = BytesToInt2(&resByte[resnum][24]);
	jumpSegmentLen = resByte[resnum][26];
	orderByteLen = scriptByteLen - jumpSegmentLen*2;
	orderByteStart = jumpSegmentLen*2 + 27;



	char msgbuf[200];
	sprintf(msgbuf,"start scriptType=%d,scriptIndex=%d\r\n",scriptType,scriptIndex);
	OutputDebugString(msgbuf); 
	//跳转段

	for(int i = 0 ; i < 255 ;i++)
	{
		jumpTable[i]=0;
	}

	for(int i = 0;i < jumpSegmentLen;i++)
	{
		jumpTable[i]=BytesToInt2(&resByte[resnum][27+i*2]);
	}

	//指令段
	for(int i = 0 ;i < orderByteLen;i ++)
	{
		orderByte[i] = resByte[resnum][i + orderByteStart];
	}
	int j = 0;
	//20160301增加标志位
	if(runornot==1)
	{

	}
	else
	{
		if(RunOrderCycle(0)==GAMEOVER_FLAG)
		{
			return GAMEOVER_FLAG;
		}
	}
	/*for(int i = 0 ;i < orderByteLen;i ++)
	{
	orderType = orderByte[i];
	orderParaNum = GetOrderParaNum(orderType);
	startAddress = i;
	parmNum = orderParaNum;
	orderParaLen = ExecOrder(orderType);
	i+= orderParaLen;
	j++;
	if(j == 6)break;
	}*/
	return 0;
}

int ScriptEng::GetOrderParaNum(int orderType)
{
	for(int i = 0 ;i< 20 ; i++)
	{
		if(command[orderType][i] == 0)
		{
			return i;
		}
	}
	return -1;
}

int ScriptEng::ExecOrder(int orderType)
{
	//wlogfile(1, __FUNCTION__ ,"开始",0);
	wlogfile(1, __FUNCTION__ ,"orderType = ",orderType); 
	int ret = 0;
	switch(orderType)
	{
	case MUSIC:             	ret = _Music();          break;
	case LOADMAP:           	ret = _LoadMap();        break;
	case CREATEACTOR:       	ret = _CreateActor();    break;
	case DELETENPC:         	ret = _DeleteNpc();      break;
	case MAPEVENT:          	ret = _MapEvent();       break;
	case ACTOREVENT:        	ret = _ActorEvent();     break;
	case MOVE:          		ret = _Move();           break;
	case ACTORMOVE:         	ret = _ActorMove();      break;
	case ACTORSPEED:        	ret = _ActorSpeed();     break;
	case _CALLBACK:         	ret = _Callback();       break;
	case GOTO:              	ret = _Goto();           break;
	case IF:                	ret = _If();             break;
	case SET:               	ret = _Set();            break;
	case SAY:               	ret = _Say();            break;
	case STARTCHAPTER:      	ret = _StartChapter();   break;
	case SCREENR:           	ret = _ScreenR();        break;
	case SCREENS:           	ret = _ScreenS();        break;
	case SCREENA:           	ret = _ScreenA();        break;
	case EVENT:             	ret = _Event();          break;
	case MONEY:             	ret = _Money();          break;
	case GAMEOVER:          	ret = _Gameover();       break;
	case IFCMP:             	ret = _IfCmp();          break;
	case ADD:               	ret = _Add();            break;
	case SUB:               	ret = _Sub();            break;
	case SETCONTROLID:      	ret = _SetControlId();   break;
	case GUTEVENT:          	ret = _GutEvent();       break;
	case SETEVENT:          	ret = _SetEvent();       break;
	case CLREVENT:          	ret = _ClrEvent();       break;
	case BUY:               	ret = _Buy();            break;
	case FACETOFACE:        	ret = _FaceToFace();     break;
	case MOVIE:             	ret = _Movie();          break;
	case CHOICE:            	ret = _Choice();         break;
	case CREATEBOX:         	ret = _CreateBox();      break;
	case DELETEBOX:         	ret = _DeleteBox();      break;
	case GAINGOODS:         	ret = _GainGoods();      break;
	case INITFIGHT:         	ret = _InitFight();      break;
	case FIGHTENABLE:       	ret = _FightEnable();    break;
	case FIGHTDISENABLE:    	ret = _FightDisenable(); break;
	case CREATENPC:         	ret = _CreateNpc();      break;
	case ENTERFIGHT:        	ret = _EnterFight();     break;
	case DELETEACTOR:       	ret = _DeleteActor();    break;
	case GAINMONEY:         	ret = _GainMoney();      break;
	case USEMONEY:          	ret = _UseMoney();       break;
	case SETMONEY:          	ret = _SetMoney();       break;
	case LEARNMAGIC:        	ret = _LearnMagic();     break;
	case SALE:             		ret = _Sale();           break;
	case NPCMOVEMOD:        	ret = _NpcMoveMod();     break;
	case MESSAGE:           	ret = _Message();        break;
	case DELETEGOODS:       	ret = _DeleteGoods();    break;
	case RESUMEACTORHP:     	ret = _ResumeActorHp();  break;
	case ACTORLAYERUP:      	ret = _ActorLayerUp();   break;
	case BOXOPEN:           	ret = _BoxOpen();        break;
	case DELALLNPC:         	ret = _DelAllNpc();      break;
	case NPCSTEP:           	ret = _NpcStep();        break;
	case SETSCENENAME:      	ret = _SetSceneName();   break;
	case SHOWSCENENAME:     	ret = _ShowSceneName();  break;
	case SHOWSCREEN:        	ret = _ShowScreen();     break;
	case USEGOODS:          	ret = _UseGoods();       break;
	case ATTRIBTEST:        	ret = _AttribTest();     break;
	case ATTRIBSET:         	ret = _AttribSet();      break;
	case ATTRIBADD:         	ret = _AttribAdd();      break;
	case SHOWGUT:           	ret = _ShowGut();        break;
	case USEGOODSNUM:       	ret = _UseGoodsNum();    break;
	case RANDRADE:          	ret = _Randrade();       break;
	case MENU:              	ret = _Menu();           break;
	case TESTMONEY:         	ret = _TestMoney();      break;
	case CALLCHAPTER:       	ret = _CallChapter();    break;
	case DISCMP:            	ret = _DisCmp();         break;
	case RETURN:            	ret = _Return();         break;
	case TIMEMSG:           	ret = _TimeMsg();        break;
	case DISABLESAVE:       	ret = _DisableSave();    break;
	case ENABLESAVE:        	ret = _EnableSave();     break;
	case GAMESAVE:          	ret = _GameSave();       break;
	case SETEVENTTIMER:     	ret = _SetEventTimer();  break;
	case ENABLESHOWPOS:     	ret = _EnableShowPos();  break;
	case DISABLESHOWPOS:    	ret = _DisableShowPos(); break;
	case SETTO:             	ret = _SetTo();          break;
	case TESTGOODSNUM:      	ret = _TestGoodsNum();   break;
	case SETFIGHTMISS:      	ret = _SetFightMiss();   break;
	case SETARMSTOSS:           ret = _SetArmsToss();    break;
	}
	return ret;
}

int ScriptEng::_Music()         
{
	MusicOnOff(orderByte[startAddress + 1],orderByte[startAddress + 3]);
	return 4;
}
int ScriptEng::_LoadMap()       
{
	if(map.mapType == orderByte[startAddress + 1] && map.mapIdx == orderByte[startAddress + 3])
	{

	}
	else
	{
		/*for(int i = 0 ; i < 255 ;i++)
		{
		//jumpTable[i]=0;
		roleList.nPC[i].showFlag =0;//NPC取消显示
		roleList.sceneObj[i].showFlag =0;//NPC取消显示
		roleList.nPC[i].no = 0;
		roleList.nPC[i].ax = 0;
		roleList.nPC[i].ay = 0;
		roleList.sceneObj[i].no = 0;
		roleList.sceneObj[i].ax = 0;
		roleList.sceneObj[i].ay = 0;
		}*/
	}

	map.InitMap(orderByte[startAddress + 1],orderByte[startAddress + 3],orderByte[startAddress + 5],orderByte[startAddress + 7]);
	Show(-1);//20210806
	Delay(100);//20210806

	char msgbuf[200];
	sprintf(msgbuf,"load mapType=%d,mapIndex=%d\r\n",orderByte[startAddress + 1],orderByte[startAddress + 3]);
	OutputDebugString(msgbuf); 

	return 8;
}
int ScriptEng::_CreateActor()   
{
	//roleList.actor[orderByte[startAddress + 1]-1].PubInit(orderByte[startAddress + 1]);
	//int act[3];
	int actMax =0 ;//20161030 默认带队角色设置问题
	for(int i = 0;i<25;i++)//20170308
	{
		if(roleList.actor[i].inRankFlag == 1)
		{
			actMax++;
		}
	}

	roleList.actor[orderByte[startAddress + 1]-1].inRankFlag = 1;
	roleList.actor[orderByte[startAddress + 1]-1].inRankId = actMax;//20170308
	if(keyinfight == 1)//20161126
	{
		roleList.actor[orderByte[startAddress + 1]-1].inRankFlag = 2;
		AddFightHeroData();
	}

	actMax++;//20170312修正
	if(actMax == 1)
	{
		actorShowNum = orderByte[startAddress + 1] - 1;
	}
	map.Show(0);
	roleList.actor[orderByte[startAddress + 1]-1].Init(orderByte[startAddress + 1],orderByte[startAddress + 3],orderByte[startAddress + 5]);
	roleList.actor[orderByte[startAddress + 1]-1].Show(0);
	Show(-1);//20210806
	Delay(100);//20210806
	return 6;
}
int ScriptEng::_DeleteNpc()     
{
	roleList.nPC[orderByte[startAddress + 1]-1].showFlag = 0;
	for (int i = 0; i < 256 ;i ++)
	{
		for(int j = 0; j < 256 ;j++)
		{
			if(map.mapNpc[i][j] == orderByte[startAddress + 1])
			{
				map.mapNpc[i][j] = 0;
			}
		}
	}

	roleList.sceneObj[orderByte[startAddress + 1]-1].showFlag = 0;
	for (int i = 0; i < 256 ;i ++)
	{
		for(int j = 0; j < 256 ;j++)
		{
			if(map.mapNpc[i][j] == (orderByte[startAddress + 1] + 100))
			{
				map.mapNpc[i][j] = 0;
			}
		}
	}

	Show(-1);//20210806
	Delay(100);//20210806
	return 2;
}
int ScriptEng::_MapEvent()      {return 0;}
int ScriptEng::_ActorEvent()    {return 0;}
int ScriptEng::_Move()          
{
	int tx = orderByte[startAddress + 3];
	int ty = orderByte[startAddress + 5];
	int sx = tx - map.x;
	int sy = ty - map.y;

	map.Show(0);
	if(roleList.actor[actorShowNum].inRankFlag == 1)roleList.actor[actorShowNum].Show(0);
	map.mapNpc[roleList.nPC[orderByte[startAddress + 1]-1].ax-1][roleList.nPC[orderByte[startAddress + 1]-1].ay-1] = 0;
	roleList.nPC[orderByte[startAddress + 1]-1].ax = tx;
	roleList.nPC[orderByte[startAddress + 1]-1].ay = ty;
	roleList.nPC[orderByte[startAddress + 1]-1].Init(-1,sx,sy);
	roleList.nPC[orderByte[startAddress + 1]-1].Show(0);
	Show(-1);//20210806
	Delay(100);//20210806
	return 6;
}
int ScriptEng::_ActorMove()     
{
	map.SetPos(orderByte[startAddress+1],orderByte[startAddress+3]);
	Show(-1);//20210806
	Delay(100);//20210806
	return 4;
}
int ScriptEng::_ActorSpeed()    {return 0;}
int ScriptEng::_Callback()      
{
	if(keyinfight == 1)
	{
		keyflagfight = 1;
		keyinfight = 0;
	}
	if (specialCallFlag == 1)//特殊调用 20160812从return加
	{
		specialCallFlag = 2;
		if(scriptType == 0 && scriptIndex == 5)//读档
		{
			getStackForRun();
		}
		SendMessage(hwnd,WM_KEYDOWN,0,KeyEsc);
		finishflag = 1;
	}
	return -1;
}
int ScriptEng::_Goto()          
{
	return 20000 + BytesToInt2(&orderByte[startAddress + 1]);//20000表示绝对地址
}
int ScriptEng::_If()            
{
	if(globalEvent[BytesToInt2(&orderByte[startAddress + 1])-1] == 1)
	{
		return 20000 + BytesToInt2(&orderByte[startAddress + 3]);//20000表示绝对地址
	}
	else
	{
		return 4;
	}
}
int ScriptEng::_Set()         
{
	if(orderByte[startAddress+1]==0)//20160816  
	{
		this->globalValue[255] = orderByte[startAddress+3];
	}
	else
	{
		this->globalValue[orderByte[startAddress + 1]-1] = orderByte[startAddress+3];
	}
	return 4;
}
int ScriptEng::_Say()           
{
	int linestart = 0;
	int chineseflag = 0;
	keyflag = 1;
	sayBox.Init(orderByte[startAddress+1]);
	int textLen = 0;
	char text[16384];
	int storedTextLen = 0;
	for(int i = 0;;i++)
	{
		if(orderByte[startAddress+3+i]==0)
		{
			text[i] = '\0';
			textLen = i;
			break;
		}

		text[i] = orderByte[startAddress+3+i];

	}
	storedTextLen = textLen;

	if(SRPUsed == 1)//20170820
	{

		int retSRP  = SRPGetText(text,scriptType,scriptIndex,startAddress);
		if(retSRP > 0)textLen = retSRP;//20171003

		//记录text到SRPDLL
		SRPSetText(text,scriptType,scriptIndex,startAddress,textLen);

	}

	if(sayBox.person != 0)
	{
		sayBox.text_start = 12;

	}
	else
	{
		sayBox.text_start = 16;
	}
	for(int i = 0 ; i < sayBox.text_start;i++)
	{
		if(text[i] < 128 && text[i] >=0)
		{
			chineseflag ++;
		}
	}
	if(chineseflag %2==1)//双字节
	{
		sayBox.text_start --;
	}
	else
	{

	}

	memcpy(sayBox.showedText[0],&text[0],sayBox.text_start);
	sayBox.showedText[0][sayBox.text_start]='\0';
	sayBox.showedText[1][0]='\0';
	linestart = sayBox.text_start;
	int j = 0;

	for(j = 1;linestart<textLen;j++)
	{
		chineseflag = 0;
		if(sayBox.person != 0 && j % 2 == 0)
		{
			for(int i = linestart ; i < linestart + 12;i++)
			{
				if(text[i] < 128 && text[i] >=0)
				{
					chineseflag ++;
				}
			}
			if(chineseflag % 2 == 0)//双字节
			{
				memcpy(sayBox.showedText[j],&text[linestart],12);
				sayBox.showedText[j][12]='\0';
				sayBox.showedText[j+1][0]='\0';
				linestart+=12;
			}
			else
			{
				memcpy(sayBox.showedText[j],&text[linestart],11);
				sayBox.showedText[j][11]='\0';
				sayBox.showedText[j+1][0]='\0';
				linestart+=11;
			}
		}
		else
		{
			for(int i = linestart ; i < linestart + 16;i++)
			{
				if(text[i] < 128 && text[i] >=0)
				{
					chineseflag ++;
				}
			}
			if(chineseflag % 2 == 0)//双字节
			{
				memcpy(sayBox.showedText[j],&text[linestart],16);
				sayBox.showedText[j][16]='\0';
				sayBox.showedText[j+1][0]='\0';
				linestart+=16;
			}
			else
			{
				memcpy(sayBox.showedText[j],&text[linestart],15);
				sayBox.showedText[j][15]='\0';
				sayBox.showedText[j+1][0]='\0';
				linestart+=15;
			}
		}



	}
	sayBox.showedTextLen = j;

	sayBox.Show(0);

	//if(orderByte[startAddress+1]!=0)ShowPic(0,PIC_OTHER,5,orderByte[startAddress+1],0,0);
	//if(orderByte[startAddress+3]!=0)ShowPic(0,PIC_OTHER,5,orderByte[startAddress+3],0,80);

	//BitBlt(hdc,0,0,800,600,hdcTmp,0,0,SRCCOPY);
	//Delay(10);
	textLen = storedTextLen;
	return -(textLen + 4);
}
int ScriptEng::_StartChapter()  
{
	//需进行资源清理、初始化等等
	orderPos = 0;
	keyflag = 0;
	//saveEnable = 1;
	newStartFlag = 1;
	newStartType = orderByte[startAddress+1];
	newStartIdx = orderByte[startAddress+3];

	for(int i = 200; i< 240;i++)//初始化局部变量
	{
		globalValue[i] = 0;//存储变量
	}

	for(int i = 0 ; i < 255 ;i++)//20170130清除NPC 场景对象
	{
		//jumpTable[i]=0;
		roleList.nPC[i].showFlag =0;//NPC取消显示
		roleList.sceneObj[i].showFlag =0;//NPC取消显示
		if(roleList.nPC[i].ax > 0 && roleList.nPC[i].ay> 0)//20210802
		{
			map.mapNpc[roleList.nPC[i].ax-1][roleList.nPC[i].ay-1] = 0;
		}
		if(roleList.sceneObj[i].ax > 0 && roleList.sceneObj[i].ay> 0)//20210802
		{
			map.mapNpc[roleList.sceneObj[i].ax-1][roleList.sceneObj[i].ay-1] = 0;
		}
		roleList.nPC[i].no = 0;
		roleList.nPC[i].ax = 0;
		roleList.nPC[i].ay = 0;
		roleList.sceneObj[i].no = 0;
		roleList.sceneObj[i].ax = 0;
		roleList.sceneObj[i].ay = 0;
	}

	//StartChapter(int type,int index);
	SendMessage(hwnd,WM_KEYDOWN,0,KeyReturn);
	return 317;
}
int ScriptEng::_ScreenR()       {return 0;}
int ScriptEng::_ScreenS()       
{
	map.SetPos(orderByte[startAddress+1],orderByte[startAddress+3]);//20160816修正
	Show(-1);//20210806
	Delay(100);//20210806
	return 4;
}
int ScriptEng::_ScreenA()       {return 0;}
int ScriptEng::_Event()         {return 0;}
int ScriptEng::_Money()         {return 0;}
int ScriptEng::_Gameover()      
{
	//SendMessage(hwnd,WM_KEYDOWN,0,-1);
	//PostQuitMessage(0);
	//20160727更新为不退出模拟器
	if (specialCallFlag == 1)//特殊调用 20161221增加
	{
		specialCallFlag = 0;
		if(scriptType == 0 && scriptIndex == 5)//读档
		{
			getStackForRun();
		}
		SendMessage(hwnd,WM_KEYDOWN,0,KeyEsc);
		finishflag = 1;
	}
	return GAMEOVER_FLAG;
}
int ScriptEng::_IfCmp()         
{
	int tmp = orderByte[startAddress+1]>0?orderByte[startAddress+1]:256;
	{

	}
	if(globalValue[tmp-1] == orderByte[startAddress + 3])
	{
		return 20000 + BytesToInt2(&orderByte[startAddress + 5]);//20000表示绝对地址
	}
	else
	{
		return 6;
	}
}
int ScriptEng::_Add()           
{
	if(orderByte[startAddress+1]==0)//20160816
	{
		this->globalValue[255] += orderByte[startAddress+3];
	}
	else
	{
		this->globalValue[orderByte[startAddress+1]-1] += orderByte[startAddress+3];
	}
	return 4;
}
int ScriptEng::_Sub()           
{
	if(orderByte[startAddress+1]==0)//20160816
	{
		this->globalValue[255] -= orderByte[startAddress+3];
	}
	else
	{
		this->globalValue[orderByte[startAddress+1]-1] -= orderByte[startAddress+3];
	}
	return 4;
}
int ScriptEng::_SetControlId()  
{
	actorShowNum = orderByte[startAddress+1]-1;
	Show(0);
	return 2;
}
int ScriptEng::_GutEvent()      {return 0;}
int ScriptEng::_SetEvent()      
{
	this->globalEvent[BytesToInt2(&orderByte[startAddress + 1])-1] = 1;
	char msgbuf[200];
	sprintf(msgbuf,"set event=%d\r\n",BytesToInt2(&orderByte[startAddress + 1]) );
	OutputDebugString(msgbuf);
	return 2;
}
int ScriptEng::_ClrEvent()      
{
	this->globalEvent[BytesToInt2(&orderByte[startAddress + 1])-1] = 0;
	char msgbuf[200];
	sprintf(msgbuf,"clr event=%d\r\n",BytesToInt2(&orderByte[startAddress + 1]));
	OutputDebugString(msgbuf);
	return 2;
}
int ScriptEng::_Buy()    
{
	int i = 0;
	int j = 0;

	while(orderByte[startAddress + 1 + i]!= 0)
	{
		g_goodId[j] = orderByte[startAddress + 1 + i];
		g_goodType[j] = orderByte[startAddress + 2 + i];
		i+=2;
		j++;
	}
	g_goodSum = j;
	flagd = 0;
	flagu = 0;
	showPos = 0;
	keyflag5 = 1;
	attFlag = 0;//20170111
	Show(0);
	return -i-2;
}
int ScriptEng::_FaceToFace()    
{
	int p1 = orderByte[startAddress + 1];
	int p2 = orderByte[startAddress + 3];
	int ax = 0;
	int ay = 0;
	int bx = 0;
	int by = 0;
	if(p1 ==0)//有主角
	{
		ax = map.x + 4;
		ay = map.y + 3;
	}
	else
	{
		ax = roleList.nPC[p1-1].ax;//20210628 p1->p1-1
		ay = roleList.nPC[p1-1].ay;//20210628 p1->p1-1
	}
	if(p2 ==0)//有主角
	{
		bx = map.x + 4;
		by = map.y + 2;
	}
	else
	{
		bx = roleList.nPC[p2-1].ax;//20210628 p2->p2-1
		by = roleList.nPC[p2-1].ay;//20210628 p2->p2-1
	}

	//进行判断
	if(ax < bx && ay == by && p1 == 0)
	{
		roleList.actor[actorShowNum].picnum = 4;
		roleList.nPC[p2-1].faceTo = 3;
		roleList.nPC[p2-1].step = 1;
		roleList.nPC[p2-1].picnum = 10;
	}
	else if(ax < bx && ay == by && p2 == 0)
	{
		roleList.actor[actorShowNum].picnum = 10;
		roleList.nPC[p1-1].faceTo = 1;
		roleList.nPC[p1-1].step = 1;
		roleList.nPC[p1-1].picnum = 4;
	}
	else if(ax < bx && ay == by)
	{
		roleList.nPC[p1-1].faceTo = 1;
		roleList.nPC[p1-1].step = 1;
		roleList.nPC[p1-1].picnum = 4;
		roleList.nPC[p2-1].faceTo = 3;
		roleList.nPC[p2-1].step = 1;
		roleList.nPC[p2-1].picnum = 10;
	}
	//2
	if(ax > bx && ay == by && p1 == 0)
	{
		roleList.actor[actorShowNum].picnum = 10;
		roleList.nPC[p2-1].faceTo = 1;
		roleList.nPC[p2-1].step = 1;
		roleList.nPC[p2-1].picnum = 4;
	}
	else if(ax > bx && ay == by && p2 == 0)
	{
		roleList.actor[actorShowNum].picnum = 4;
		roleList.nPC[p1-1].faceTo = 3;
		roleList.nPC[p1-1].step = 1;
		roleList.nPC[p1-1].picnum = 10;
	}
	else if(ax > bx && ay == by)
	{
		roleList.nPC[p1-1].faceTo = 3;
		roleList.nPC[p1-1].step = 1;
		roleList.nPC[p1-1].picnum = 10;
		roleList.nPC[p2-1].faceTo = 1;
		roleList.nPC[p2-1].step = 1;
		roleList.nPC[p2-1].picnum = 4;
	}
	//3
	if(ay < by && ax == bx && p1 == 0)
	{
		roleList.actor[actorShowNum].picnum = 7;
		roleList.nPC[p2-1].faceTo = 0;
		roleList.nPC[p2-1].step = 1;
		roleList.nPC[p2-1].picnum = 1;
	}
	else if(ay < by && ax == bx && p2 == 0)
	{
		roleList.actor[actorShowNum].picnum = 1;
		roleList.nPC[p1-1].faceTo = 2;
		roleList.nPC[p1-1].step = 1;
		roleList.nPC[p1-1].picnum = 7;
	}
	else if(ay < by && ax == bx)
	{
		roleList.nPC[p1-1].faceTo = 2;
		roleList.nPC[p1-1].step = 1;
		roleList.nPC[p1-1].picnum = 7;
		roleList.nPC[p2-1].faceTo = 0;
		roleList.nPC[p2-1].step = 1;
		roleList.nPC[p2-1].picnum = 1;
	}
	//4
	if(ay > by && ax == bx && p1 == 0)
	{
		roleList.actor[actorShowNum].picnum = 1;
		roleList.nPC[p2-1].faceTo = 2;
		roleList.nPC[p2-1].step = 1;
		roleList.nPC[p2-1].picnum = 7;
	}
	else if(ay > by && ax == bx && p2 == 0)
	{
		roleList.actor[actorShowNum].picnum = 7;
		roleList.nPC[p1-1].faceTo = 0;
		roleList.nPC[p1-1].step = 1;
		roleList.nPC[p1-1].picnum = 1;
	}
	else if(ay > by && ax == bx)
	{
		roleList.nPC[p1-1].faceTo = 0;
		roleList.nPC[p1-1].step = 1;
		roleList.nPC[p1-1].picnum = 1;
		roleList.nPC[p1-1].faceTo = 2;
		roleList.nPC[p1-1].step = 1;
		roleList.nPC[p2-1].picnum = 7;
	}

	Show(0);
	return 4;
}
int ScriptEng::_Movie()         
{

	ShowCG(orderByte[startAddress + 1],orderByte[startAddress + 3],orderByte[startAddress + 5],orderByte[startAddress + 7],orderByte[startAddress + 9]);
	return 10;
}
int ScriptEng::_Choice()        
{
	keyflag = 4;
	int text1Len = 0;
	char text1[17];
	int text2Len = 0;
	char text2[17];
	char alltext[40];

	for(int i = 0;;i++)
	{
		if(orderByte[startAddress+1+i]==0)
		{
			if(i> 16)//20170308增加超长判断
			{
				text1[16] = '\0';
			}
			else
			{
				text1[i] = '\0';
			}
			text1Len = i;
			break;
		}
		if(i <= 16)//20170308增加超长判断
		{
			text1[i] = orderByte[startAddress+1+i];
			if(text1[i] == ' ')text1[i] = '_';
		}
	}

	for(int i = 0;;i++)
	{
		if(orderByte[startAddress+1+text1Len+i+1]==0)
		{
			if(i> 16)//20170308增加超长判断
			{
				text2[16] = '\0';
			}
			else
			{
				text2[i] = '\0';
			}
			text2Len = i;
			break;
		}
		if(i <= 16)//20170308增加超长判断
		{
			text2[i] = orderByte[startAddress+1+text1Len+i+1];
			if(text2[i] == ' ')text2[i] = '_';
		}
	}
	gameMenu.maxword = text1Len>16?16:text1Len;//20170308
	if(text2Len>text1Len)gameMenu.maxword = text2Len>16?16:text2Len;//20170308

	sprintf_s(alltext,"%s %s",text1,text2);

	gameMenu.Init(0,0,0,0,0,alltext,0);
	gameMenu.Show(0);
	orderChoiceJmpPos = BytesToInt2(&orderByte[startAddress + 1 + text1Len + 1 + text2Len + 1])- 3 - jumpSegmentLen*2 ;//20000表示绝对地址

	return -(text1Len + text2Len + 5);
}
int ScriptEng::_CreateBox()     
{
	//20160625调整位置
	roleList.sceneObj[orderByte[startAddress + 1]-1].PubInit(orderByte[startAddress + 3]);

	//20160316修正场景下偏bug
	int tx = orderByte[startAddress + 5];
	int tmp = GetPicSize(RES_ACP,4, roleList.sceneObj[orderByte[startAddress + 1]-1].picno,0)%10000-1;
	int ty = orderByte[startAddress + 7]-tmp/16;//20160625
	int sx = tx - map.x;
	int sy = ty - map.y;

	//map.Show(0);
	//roleList.sceneObj[0].Show(0);
	roleList.sceneObj[orderByte[startAddress + 1]-1].ax = tx;//绝对坐标
	roleList.sceneObj[orderByte[startAddress + 1]-1].ay = ty;//绝对坐标

	roleList.sceneObj[orderByte[startAddress + 1]-1].Init(orderByte[startAddress + 3],sx,sy);
	roleList.sceneObj[orderByte[startAddress + 1]-1].showFlag = 1;
	roleList.sceneObj[orderByte[startAddress + 1]-1].Show(0);
	SetObjMapNpc(tx-1,ty-1,orderByte[startAddress + 1],0);//20160316新增用于场景可行走处理 20160829修正纵坐标为下面createbox所在位置
	//map.mapNpc[tx-1][ty-1] = orderByte[startAddress + 1]+ 100;
	return 8;
}
int ScriptEng::_DeleteBox()     
{
	roleList.sceneObj[orderByte[startAddress + 1]-1].showFlag = 0;
	for (int i = 0; i < 256 ;i ++)
	{
		for(int j = 0; j < 256 ;j++)
		{
			if(map.mapNpc[i][j] == (orderByte[startAddress + 1] + 100))
			{
				map.mapNpc[i][j] = 0;
			}
		}
	}
	return 2;
}
int ScriptEng::_GainGoods()     
{
	char tmp[20];
	goodList.Add(orderByte[startAddress + 1],orderByte[startAddress + 3],1);
	if(keyinfight == 1)//20170420修正
	{
		int t_goodtype = orderByte[startAddress + 1];
		int t_goodid = orderByte[startAddress + 3];

		if(t_goodtype > 8 ) 
		{
			fight.goodList.Add(t_goodtype,t_goodid,1);
			fight.goodAll++;
		}
		if(t_goodtype < 8 ) 
		{
			fight.equipList.Add(t_goodtype,t_goodid,1);
			fight.equipAll++;
		}
		if(t_goodtype == 7 || t_goodtype == 8) 
		{
			fight.throwList.Add(t_goodtype,t_goodid,1);
			fight.throwAll++;
		}

	}

	sprintf_s(tmp,"获得：%s",goodList.good[orderByte[startAddress + 1]-1][orderByte[startAddress + 3]-1].name);
	TimerMessage(tmp,12,37,10,1,1000);
	return 4;
}
int ScriptEng::_InitFight()     
{
	fight.Init(orderByte[startAddress + 17],
		orderByte[startAddress + 19],orderByte[startAddress + 21],
		orderByte[startAddress + 1],orderByte[startAddress + 3],
		orderByte[startAddress + 5],orderByte[startAddress + 7],
		orderByte[startAddress + 9],orderByte[startAddress + 11],
		orderByte[startAddress + 13],orderByte[startAddress + 15]);
	fightEnable = 1;
	return 22;
}
int ScriptEng::_FightEnable()   
{
	fightEnable = 1;
	return 0;
}
int ScriptEng::_FightDisenable()
{
	fightEnable = 0;
	return 0;
}
int ScriptEng::_CreateNpc()     
{
	int tx = orderByte[startAddress + 5];
	int ty = orderByte[startAddress + 7];
	int sx = tx - map.x;
	int sy = ty - map.y;

	//map.Show(0);
	//roleList.actor[0].Show(0);

	roleList.nPC[orderByte[startAddress + 1]-1].ax = tx;//绝对坐标
	roleList.nPC[orderByte[startAddress + 1]-1].ay = ty;//绝对坐标
	roleList.nPC[orderByte[startAddress + 1]-1].PubInit(orderByte[startAddress + 3]);
	roleList.nPC[orderByte[startAddress + 1]-1].Init(orderByte[startAddress + 3],sx,sy);
	roleList.nPC[orderByte[startAddress + 1]-1].showFlag = 1;
	roleList.nPC[orderByte[startAddress + 1]-1].Show(0);
	map.mapNpc[tx-1][ty-1] = orderByte[startAddress + 1];

	return 8;
}
int ScriptEng::_EnterFight()    //未完成
{
	fight.EnterInit(BytesToInt2(&orderByte[startAddress + 1]),BytesToInt2(&orderByte[startAddress + 3]),
		BytesToInt2(&orderByte[startAddress + 5]),BytesToInt2(&orderByte[startAddress + 7]),
		BytesToInt2(&orderByte[startAddress + 9]),BytesToInt2(&orderByte[startAddress + 11]),
		BytesToInt2(&orderByte[startAddress + 13]),BytesToInt2(&orderByte[startAddress + 15]),
		BytesToInt2(&orderByte[startAddress + 17]),BytesToInt2(&orderByte[startAddress + 19]),
		BytesToInt2(&orderByte[startAddress + 21]),BytesToInt2(&orderByte[startAddress + 23]),
		BytesToInt2(&orderByte[startAddress + 25]),BytesToInt2(&orderByte[startAddress + 27]),
		BytesToInt2(&orderByte[startAddress + 29]));
	SetFightHeroData();
	fight.Show(0);
	tmpOrderPos = 0;//20171003
	keyflagfight = 1;
	Show(0);
	return -30-1;
}
int ScriptEng::_DeleteActor()   
{
	int t_inRankId = roleList.actor[orderByte[startAddress + 1]-1].inRankFlag;
	int t_inRankFlag = roleList.actor[orderByte[startAddress + 1]-1].inRankFlag;
	if(t_inRankFlag == 0)return 2;//20210806删除了不在队角色
	roleList.actor[orderByte[startAddress + 1]-1].inRankFlag = 0;
	//roleList.actor[orderByte[startAddress + 1]-1].inRankId = 0;
	for(int i = 0 ;i < 25 ;i++)//20170308角色队列中角色顺序异常的BUG改变inRankId
	{
		if(roleList.actor[i].inRankFlag == 1)
		{

			if(roleList.actor[i].inRankId > t_inRankId)//20170319修正编号
			{
				roleList.actor[i].inRankId --;
			}
		}
	}
	if(actorShowNum == (orderByte[startAddress + 1]- 1))//删除主角
	{
		for(int i = 0 ;i < 25 ;i++)
		{
			if(roleList.actor[i].inRankFlag == 1 && roleList.actor[i].inRankId == 0)//首位
			{
				actorShowNum = i;
				roleList.actor[orderByte[startAddress + 1]-1].Show(0);
				break;//20161030 带队角色离队后，新带队角色的选择问题
			}
		}
	}
	return 2;
}
int ScriptEng::_GainMoney()     
{
	this->money += BytesToInt4(&orderByte[startAddress + 1]);
	if(this->money > MONEYMAX ) this->money = MONEYMAX;
	return 4;
}
int ScriptEng::_UseMoney()      
{
	this->money -= BytesToInt4(&orderByte[startAddress + 1]);
	return 4;
}
int ScriptEng::_SetMoney()      
{
	this->money = BytesToInt4(&orderByte[startAddress + 1]);
	return 4;
}
int ScriptEng::_LearnMagic()    
{
	actorMagicList[orderByte[startAddress + 1]-1].Add(orderByte[startAddress + 3],orderByte[startAddress + 5],roleList.actor[orderByte[startAddress + 1]-1].magicLearn);
	roleList.actor[orderByte[startAddress + 1]-1].magicLearn++;
	ShowPic(0,RES_PIC,2,10,-1,-1);
	int showPosAdd = strlen(roleList.actor[orderByte[startAddress + 1]-1].name);//20160816
	ShowText(roleList.actor[orderByte[startAddress + 1]-1].name,80-showPosAdd*4,20);
	showPosAdd = strlen(actorMagicList[orderByte[startAddress + 1]-1].magic[roleList.actor[orderByte[startAddress + 1]-1].magicLearn-1].name);
	ShowText(actorMagicList[orderByte[startAddress + 1]-1].magic[roleList.actor[orderByte[startAddress + 1]-1].magicLearn-1].name,80-showPosAdd*4,32+24);//20160729
	actorMagicList[orderByte[startAddress + 1]-1].exLearned++;//20160729改
	CopyToHdc();
	Delay(2000);
	return 6;
}
int ScriptEng::_Sale()  
{

	keyflag5 = 2;
	attFlag = 0;//20170111
	flagd = 0;
	flagu = 0;
	showPos = 0;
	Show(0);
	return -2000-1;
}
int ScriptEng::_NpcMoveMod()    
{
	roleList.nPC[orderByte[startAddress + 1]-1].picnum = 0;
	roleList.nPC[orderByte[startAddress + 1]-1].action = orderByte[startAddress + 3];//20210629
	roleList.sceneObj[orderByte[startAddress + 1]-1].picnum = 0;
	roleList.sceneObj[orderByte[startAddress + 1]-1].action = orderByte[startAddress + 3];//20210629
	return 4;
}
int ScriptEng::_Message()    //待测试   
{
	int linestart = 0;
	int lineno = 0;
	keyflag = 3;
	int textLen = 0;
	char showedText[5][17];
	char text[16384];

	for(int i = 0;;i++)
	{
		if(orderByte[startAddress+1+i]==0)
		{
			text[i] = '\0';
			textLen = i;
			break;
		}

		text[i] = orderByte[startAddress+1+i];

	}
	linestart = 0;
	int chineseflag = 0;
	int j = 0;
	for(j = 0;j<5;j++)
	{
		chineseflag = 0;
		for(int i = linestart ; i < linestart + 16;i++)
		{
			if(text[i] < 128 && text[i] >=0)
			{
				chineseflag ++;
			}
		}
		if(chineseflag % 2 == 0)//双字节
		{
			memcpy(showedText[j],&text[linestart],16);
			showedText[j][16]='\0';
			linestart+=16;
		}
		else
		{
			memcpy(showedText[j],&text[linestart],15);
			showedText[j][15]='\0';
			linestart+=15;
		}



		lineno = j+1;


		if(linestart>=textLen)break;


	}
	//20160730增加临时偏移量修正message重复esc的BUG


	TimerMessageNoText(showedText[j],12,37-8*(lineno-1),8,lineno,1000);
	for(j = 0;j<lineno;j++)
	{
		ShowTextDirect(showedText[j],12+4,37-8*(lineno-1)+2+j*16,16);	
	}
	//Message(text,12,37,8,1);
	Delay(1000);
	return -(textLen+2);
}
int ScriptEng::_DeleteGoods()   
{
	int ret = goodList.Del(orderByte[startAddress + 1],orderByte[startAddress + 3],1);
	if(ret == -1)
	{
		return 20000 + BytesToInt2(&orderByte[startAddress + 5]);//20000表示绝对地址
	}
	else
	{
		return 6;
	}
}
int ScriptEng::_ResumeActorHp() 
{
	roleList.actor[orderByte[startAddress + 1]-1].hp += roleList.actor[BytesToInt2(&orderByte[startAddress + 1])-1].hpMax * BytesToInt2(&orderByte[startAddress + 3])/100;//20161217
	if(roleList.actor[orderByte[startAddress + 1]-1].hp > roleList.actor[orderByte[startAddress + 1]-1].hpMax)
	{
		roleList.actor[orderByte[startAddress + 1]-1].hp = roleList.actor[orderByte[startAddress + 1]-1].hpMax;
	}
	return 4;
}
int ScriptEng::_ActorLayerUp()  
{
	if(roleList.actor[orderByte[startAddress + 1]-1].degree < orderByte[startAddress + 3])
	{
		int olddegree = roleList.actor[orderByte[startAddress + 1]-1].degree-1;
		int newdegree = orderByte[startAddress + 3]-1;
		int roleId = orderByte[startAddress + 1]-1;
		roleList.actor[roleId].degree = orderByte[startAddress + 3];

		//20210802处理升级属性提升
		//20210903修正负数错误
		roleList.actor[roleId].hpMax = roleList.actor[roleId].hpMax - degreeList[roleId].hpMax[olddegree] + degreeList[roleId].hpMax[newdegree] ;
		if(roleList.actor[roleId].hpMax>HPMAX)roleList.actor[roleId].hpMax = HPMAX;
		if(roleList.actor[roleId].hpMax<0)roleList.actor[roleId].hpMax = 0;
		roleList.actor[roleId].hp = roleList.actor[roleId].hpMax;

		roleList.actor[roleId].mpMax = roleList.actor[roleId].mpMax - degreeList[roleId].mpMax[olddegree] + degreeList[roleId].mpMax[newdegree] ;
		if(roleList.actor[roleId].mpMax>HPMAX)roleList.actor[roleId].mpMax = MPMAX;
		if(roleList.actor[roleId].mpMax<0)roleList.actor[roleId].mpMax = 0;
		roleList.actor[roleId].mp = roleList.actor[roleId].mpMax;

		roleList.actor[roleId].att = roleList.actor[roleId].att - degreeList[roleId].at[olddegree] + degreeList[roleId].at[newdegree] ;
		if(roleList.actor[roleId].att>ATMAX)roleList.actor[roleId].att = ATMAX;
		if(roleList.actor[roleId].att<0)roleList.actor[roleId].att = 0;

		roleList.actor[roleId].def = roleList.actor[roleId].def - degreeList[roleId].df[olddegree] + degreeList[roleId].df[newdegree] ;
		if(roleList.actor[roleId].def>DFMAX)roleList.actor[roleId].def = DFMAX;
		if(roleList.actor[roleId].def<0)roleList.actor[roleId].def = 0;

		roleList.actor[roleId].speed = roleList.actor[roleId].speed - degreeList[roleId].speed[olddegree] + degreeList[roleId].speed[newdegree] ;
		if(roleList.actor[roleId].speed>SPEEDMAX)roleList.actor[roleId].speed = SPEEDMAX;
		if(roleList.actor[roleId].speed<0)roleList.actor[roleId].speed = 0;

		roleList.actor[roleId].lucky = roleList.actor[roleId].lucky - degreeList[roleId].lucky[olddegree] + degreeList[roleId].lucky[newdegree] ;
		if(roleList.actor[roleId].lucky>LUCKMAX)roleList.actor[roleId].lucky = LUCKMAX;
		if(roleList.actor[roleId].lucky<0)roleList.actor[roleId].lucky = 0;

		roleList.actor[roleId].anima = roleList.actor[roleId].anima - degreeList[roleId].anima[olddegree] + degreeList[roleId].anima[newdegree] ;
		if(roleList.actor[roleId].anima>ANIMAMAX)roleList.actor[roleId].anima = ANIMAMAX;
		if(roleList.actor[roleId].anima<0)roleList.actor[roleId].anima = 0;

		roleList.actor[roleId].expMax = degreeList[roleId].exp[newdegree] ;

		if(degreeList[roleId].learnedMagic[newdegree]>= degreeList[roleId].learnedMagic[olddegree])//20170820
		{
			roleList.actor[roleId].magicLearn = roleList.actor[roleId].magicLearn - degreeList[roleId].learnedMagic[olddegree] + degreeList[roleId].learnedMagic[newdegree];
		}

	}
	return 4;
}
int ScriptEng::_BoxOpen()       
{
	roleList.sceneObj[orderByte[startAddress + 1]-1].picnum = 1;
	return 2;
}
int ScriptEng::_DelAllNpc()     
{
	for(int i = 0 ; i<255;i++)
	{
		roleList.nPC[i].showFlag = 0;
	}
	for(int i = 0 ; i<255;i++)//20170130增加
	{
		roleList.sceneObj[i].showFlag = 0;
	}
	for (int i = 0; i < 256 ;i ++)
	{
		for(int j = 0; j < 256 ;j++)
		{
			//if(map.mapNpc[i][j] < 100)//20170130删除条件
			{
				map.mapNpc[i][j] = 0;
			}
		}
	}
	/*for(int i = 0 ; i<255;i++)
	{
	roleList.sceneObj[i].showFlag = 0;
	}
	for (int i = 0; i < 100 ;i ++)
	{
	for(int j = 0; j < 100 ;j++)
	{
	if(map.mapNpc[i][j] >= 100)
	{
	map.mapNpc[i][j] = 0;
	}
	}
	}*/

	return 0;
}
int ScriptEng::_NpcStep()       
{
	if(orderByte[startAddress + 1] == 0)
	{
		roleList.actor[actorShowNum].SetStep(orderByte[startAddress + 3],orderByte[startAddress + 5]);
	}
	else
	{
		roleList.nPC[orderByte[startAddress + 1]-1].SetStep(orderByte[startAddress + 3],orderByte[startAddress + 5]);
		roleList.sceneObj[orderByte[startAddress + 1]-1].SetStep(orderByte[startAddress + 3],orderByte[startAddress + 5]);//20210907
	}
	return 6;
}
int ScriptEng::_SetSceneName()  
{
	int textLen = 0;
	for(int i = 0;;i++)
	{
		if(orderByte[startAddress+1+i]==0)
		{
			sceneName[i] = '\0';
			return i+1;
		}
		sceneName[i] = orderByte[startAddress+1+i];

	}
	return -1;
}
int ScriptEng::_ShowSceneName() 
{
	Show(-1);
	TimerMessage(sceneName,12,37,8,1,1000);
	//Message(sceneName,12,37,8,1);
	return 0;
}
int ScriptEng::_ShowScreen()    
{
	Show(0);
	return 0;
}
int ScriptEng::_UseGoods()      
{
	int ret = goodList.Del(orderByte[startAddress + 1],orderByte[startAddress + 3],1);
	if(ret == -1)
	{
		return 20000 + BytesToInt2(&orderByte[startAddress + 5]);//20000表示绝对地址
	}
	else
	{
		return 6;
	}
}
int ScriptEng::_AttribTest()    
{
	//ATTRIBTEST actor type attrval lowaddr higaddr
	switch(orderByte[startAddress+3])
		//0-级别，1-攻击力，2-防御力，3-身法，4-生命，5-真气当前值，6-当前经验值，7-灵力，8-幸运，9-攻击的异常回合数，10-对特殊状态的免疫，11-普通攻击可能产生异常状态，12-合体法术，13-每回合变化生命，14-每回合变化真气，15-头戴，16-身穿，17-肩披，18-护腕，19-手持，20-脚蹬，21-佩戴1，22-佩戴2，23-生命上限，24-真气上限）属性
	{
	case 0:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].degree < BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].degree > BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 1:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].att <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].att >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 2:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].def <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].def >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 3:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].speed <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].speed >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 4:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].hp <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].hp >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 +  BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 5:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].mp <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].mp > BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 6:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].exp <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].exp >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 7:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].anima <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].anima >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 8:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].lucky <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].lucky >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 9:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].disround < BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].disround >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 10:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].anti <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].anti >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 11:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].atcause < BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].atcause >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 12:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].togethermagic <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].togethermagic >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 13:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].hpAdd < BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].hpAdd >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 14:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].mpAdd <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].mpAdd > BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 15:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].head <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].head >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 16:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].shoulder <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].shoulder >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 17:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].body <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].body >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 18:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].sleeve <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].sleeve >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 19:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].hand <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].hand >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 20:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].foot <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].foot >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 21:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].decorate1 <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].decorate1 >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 22:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].decorate2 <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].decorate2 >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 23:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].hpMax <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].hpMax >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}
	case 24:
		{
			if(roleList.actor[orderByte[startAddress+1]-1].mpMax <  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
			}
			else if(roleList.actor[orderByte[startAddress+1]-1].mpMax >  BytesToInt2(&orderByte[startAddress+5]))
			{
				return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
			}
			return 10;
		}

	}
	return 10;
}
int ScriptEng::_AttribSet()     
{
	//ATTRIBSET actor type attrval			---- 设置号码actor的主角的type（0-级别，1-攻击力，2-防御力，3-身法，4-生命，5-真气当前值，6-当前经验值，7-灵力，8-幸运，9-攻击的异常回合数，10-对特殊状态的免疫，11-普通攻击可能产生异常状态，12-合体法术，13-每回合变化生命，14-每回合变化真气，15-生命上限，16-真气上限）属性，属性值等于attrval。
	switch(orderByte[startAddress+3])
	{
	case 0:
		{
			roleList.actor[orderByte[startAddress+1]-1].degree =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 1:
		{
			roleList.actor[orderByte[startAddress+1]-1].att =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 2:
		{
			roleList.actor[orderByte[startAddress+1]-1].def =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 3:
		{
			roleList.actor[orderByte[startAddress+1]-1].speed =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 4:
		{
			roleList.actor[orderByte[startAddress+1]-1].hp =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 5:
		{
			roleList.actor[orderByte[startAddress+1]-1].mp =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 6:
		{
			roleList.actor[orderByte[startAddress+1]-1].exp = BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 7:
		{
			roleList.actor[orderByte[startAddress+1]-1].anima =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 8:
		{
			roleList.actor[orderByte[startAddress+1]-1].lucky =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 9:
		{
			roleList.actor[orderByte[startAddress+1]-1].disround =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 10:
		{
			roleList.actor[orderByte[startAddress+1]-1].anti =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 11:
		{
			roleList.actor[orderByte[startAddress+1]-1].atcause =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 12:
		{
			roleList.actor[orderByte[startAddress+1]-1].togethermagic =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 13:
		{
			roleList.actor[orderByte[startAddress+1]-1].mpAdd =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 14:
		{
			roleList.actor[orderByte[startAddress+1]-1].hpAdd =  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 15:
		{
			roleList.actor[orderByte[startAddress+1]-1].hpMax =  BytesToInt2(&orderByte[startAddress+5]);//20170110
			break;
		}
	case 16:
		{
			roleList.actor[orderByte[startAddress+1]-1].mpMax =  BytesToInt2(&orderByte[startAddress+5]);//20170110
			break;
		}
	}
	return 6;
}
int ScriptEng::_AttribAdd()     
{
	switch(orderByte[startAddress+3])
	{
	case 0:
		{
			roleList.actor[orderByte[startAddress+1]-1].degree +=  BytesToInt2(&orderByte[startAddress+5]);
			if(roleList.actor[orderByte[startAddress+1]-1].degree >= MYOVERFLOW)roleList.actor[orderByte[startAddress+1]-1].degree-=MYOVERFLOW;//20161220模拟武林新传溢出BUG利用系统
			if(roleList.actor[orderByte[startAddress+1]-1].degree>DEGREEMAX)roleList.actor[orderByte[startAddress+1]-1].degree = DEGREEMAX;
			break;
		}
	case 1:
		{
			roleList.actor[orderByte[startAddress+1]-1].att +=  BytesToInt2(&orderByte[startAddress+5]);
			if(roleList.actor[orderByte[startAddress+1]-1].att>ATMAX)roleList.actor[orderByte[startAddress+1]-1].att = ATMAX;
			break;
		}
	case 2:
		{
			roleList.actor[orderByte[startAddress+1]-1].def +=  BytesToInt2(&orderByte[startAddress+5]);
			if(roleList.actor[orderByte[startAddress+1]-1].def>DFMAX)roleList.actor[orderByte[startAddress+1]-1].def = DFMAX;
			break;
		}
	case 3:
		{
			roleList.actor[orderByte[startAddress+1]-1].speed +=  BytesToInt2(&orderByte[startAddress+5]);
			if(roleList.actor[orderByte[startAddress+1]-1].speed>SPEEDMAX)roleList.actor[orderByte[startAddress+1]-1].speed = SPEEDMAX;
			break;
		}
	case 4:
		{
			roleList.actor[orderByte[startAddress+1]-1].hp +=  BytesToInt2(&orderByte[startAddress+5]);
			if(roleList.actor[orderByte[startAddress+1]-1].hp>HPMAX)roleList.actor[orderByte[startAddress+1]-1].hp = HPMAX;
			break;
		}
	case 5:
		{
			roleList.actor[orderByte[startAddress+1]-1].mp += BytesToInt2(&orderByte[startAddress+5]);
			if(roleList.actor[orderByte[startAddress+1]-1].mp>MPMAX)roleList.actor[orderByte[startAddress+1]-1].mp = MPMAX;
			break;
		}
	case 6:
		{
			roleList.actor[orderByte[startAddress+1]-1].exp +=  BytesToInt2(&orderByte[startAddress+5]);
			if(roleList.actor[orderByte[startAddress+1]-1].exp >= MYOVERFLOW)roleList.actor[orderByte[startAddress+1]-1].exp-=MYOVERFLOW;//20161216 20161220模拟武林新传溢出BUG利用系统
			break;
		}
	case 7:
		{
			roleList.actor[orderByte[startAddress+1]-1].anima += BytesToInt2(&orderByte[startAddress+5]);
			if(roleList.actor[orderByte[startAddress+1]-1].anima >= MYOVERFLOW)roleList.actor[orderByte[startAddress+1]-1].anima-=MYOVERFLOW;//20161220模拟武林新传溢出BUG利用系统
			if(roleList.actor[orderByte[startAddress+1]-1].anima>ANIMAMAX)roleList.actor[orderByte[startAddress+1]-1].anima = ANIMAMAX;
			break;
		}
	case 8:
		{
			roleList.actor[orderByte[startAddress+1]-1].lucky += BytesToInt2(&orderByte[startAddress+5]);
			if(roleList.actor[orderByte[startAddress+1]-1].lucky >= MYOVERFLOW)roleList.actor[orderByte[startAddress+1]-1].lucky-=MYOVERFLOW;//20161220模拟武林新传溢出BUG利用系统
			if(roleList.actor[orderByte[startAddress+1]-1].lucky>LUCKMAX)roleList.actor[orderByte[startAddress+1]-1].lucky = LUCKMAX;
			break;
		}
	case 9:
		{
			roleList.actor[orderByte[startAddress+1]-1].disround +=  BytesToInt2(&orderByte[startAddress+5]);
			break;
		}
	case 10:
		{
			roleList.actor[orderByte[startAddress+1]-1].hpMax +=  BytesToInt2(&orderByte[startAddress+5]);//20161216
			if(roleList.actor[orderByte[startAddress+1]-1].hpMax>HPMAX)roleList.actor[orderByte[startAddress+1]-1].hpMax = HPMAX;
			break;
		}
	case 11:
		{
			roleList.actor[orderByte[startAddress+1]-1].mpMax +=  BytesToInt2(&orderByte[startAddress+5]);//20161216
			if(roleList.actor[orderByte[startAddress+1]-1].mpMax>MPMAX)roleList.actor[orderByte[startAddress+1]-1].mpMax = MPMAX;
			break;
		}
	}
	return 6;
}
int ScriptEng::_ShowGut()       
{
	int textLen = 0;
	char text[16384];
	char showedText[800][20+1];
	for(int i = 0;;i++)
	{
		if(orderByte[startAddress+5+i]==0)
		{
			text[i] = '\0';
			textLen = i;
			break;
		}
		text[i] = orderByte[startAddress+5+i];

	}

	showedText[0][0]='\0';
	showedText[1][0]='\0';
	showedText[2][0]='\0';
	showedText[3][0]='\0';
	for(int j = 4;j<textLen/20+5;j++)
	{
		memcpy(showedText[j],&text[(j-4)*20],20);
		showedText[j][20]='\0';

	}

	//循环显示时间
	for(int t = 0 ;t<textLen/20*16; t ++)
	{
		//i = t/10;
		ClrScence();

		for(int j = 0;j<textLen/20+4+1;j++)//20160901修正
		{
			ShowText(showedText[j],0,16 + j*16 -t,16);

		}
		if(orderByte[startAddress+1]!=0)ShowPic(0,PIC_OTHER,5,orderByte[startAddress+1],0,0);
		if(orderByte[startAddress+3]!=0)ShowPic(0,PIC_OTHER,5,orderByte[startAddress+3],0,80);

		BitBlt(hdc,0,0,800,600,hdcTmp,0,0,SRCCOPY);
		if(Delay(10))break;

	}
	return textLen + 5;
}
int ScriptEng::_UseGoodsNum()   
{
	int ret = goodList.Del(orderByte[startAddress + 1],orderByte[startAddress + 3],orderByte[startAddress + 5]);
	if(ret == -1)
	{
		return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
	}
	else
	{
		return 8;
	}
}
int ScriptEng::_Randrade()      
{
	//20160816优化随机数种子
	//struct timeval tv; 
	//gettimeofday(&tv, NULL);
	//srand(tv.tv_sec + tv.tv_usec);
	//srand((unsigned)time(0)); 


	int R = RAND_MAX-(RAND_MAX+1)%1000; //去除尾数 32767%1000= 767
	int i = rand();
	while( i > R ) 
	{
		i = rand();
	}
	i = i % 1000; // 符合要求的随机数
	Sleep(5);

	if(g_debugFlag == 1 && dgrand >0)
	{
		i = dgrand;
		dgrand = 0;
	}
	if(i <= BytesToInt2(&orderByte[startAddress+1]))//20160812修正
	{
		return 20000 + BytesToInt2(&orderByte[startAddress + 3]);//20000表示绝对地址
	}
	else
	{
		return 4;
	}
}
int ScriptEng::_Menu()          
{
	//globalValue[orderByte[startAddress + 3] = 1;
	keyflag = 5;
	int textLen = 0;
	char text[1000+1];
	int allTextLen = 0;
	int vauleNo = BytesToInt2(&orderByte[startAddress + 1]);

	for(int i = 0;;i++)
	{

		if(orderByte[startAddress+3+i]==0)
		{
			text[i] = '\0';
			textLen = i;

			break;
		}

		text[i] = orderByte[startAddress+3+i];


	}


	gameMenu.Init(0,0,0,0,0,text,vauleNo);
	gameMenu.Show(0);

	return -(textLen + 4);

}
int ScriptEng::_TestMoney()     
{
	if(money < BytesToInt4(&orderByte[startAddress + 1]))//20160118修正
	{
		return 20000 + BytesToInt2(&orderByte[startAddress + 5]);//20000表示绝对地址 20160118修正3->5
	}
	else
	{
		return 6;
	}
}
int ScriptEng::_CallChapter()   //未完成
{
	//需进行资源临时保存。
	SetStackForCallChapter();
	orderPos = 0;
	keyflag = 0;
	//saveEnable = 1;
	newStartFlag = 1;//用startchaptrt函数
	newStartType = orderByte[startAddress+1];
	newStartIdx = orderByte[startAddress+3];
	//CallChapter(newStartType,newStartIdx);
	SendMessage(hwnd,WM_KEYDOWN,0,KeyReturn);
	return 317;//4;
}
int ScriptEng::_DisCmp()        
{
	int tmp = orderByte[startAddress+1]>0?orderByte[startAddress+1]:256;
	if(globalValue[tmp-1] < orderByte[startAddress + 3])
	{
		return 20000 + BytesToInt2(&orderByte[startAddress + 5]);//20000表示绝对地址
	}
	else if(globalValue[tmp-1] > orderByte[startAddress + 3])
	{
		return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
	}
	else 
	{
		return 8;
	}
}
int ScriptEng::_Return()        
{

	for(int ca = 0 ; ca < callStackDeep ; ca ++)//堆栈是从读档调用过来的。
	{
		int t_scriptType = callStack[ca][6];//脚本类型
		int t_scriptIndex = callStack[ca][7];//脚本编号
		if(t_scriptType == 0 && t_scriptIndex == 5 && specialCallFlag == 1)
		{
			getStackForRun();
			return 0;
		}
	}
	if (specialCallFlag == 1)//特殊调用 20170129修正6为5
	{
		specialCallFlag = 0;

		if(scriptType == 0 && scriptIndex == 5)//读档
		{
			getStackForRun();
		}

		SendMessage(hwnd,WM_KEYDOWN,0,KeyEsc);
		finishflag = 1;
	}
	else//恢复现场
	{
		if(callStackDeep==0)//20170329直接返回
		{
			return -1;
		}
		getStackForRun();
	}
	return 0;
}
int ScriptEng::_TimeMsg()  //待测试     
{
	int linestart = 0;
	keyflag = 3;
	char showedText[5][17];
	int textLen = 0;
	char text[16384];

	for(int i = 0;;i++)
	{
		if(orderByte[startAddress+3+i]==0)
		{
			text[i] = '\0';
			textLen = i;
			break;
		}

		text[i] = orderByte[startAddress+3+i];

	}
	linestart = 0;

	int j = 0;
	int chineseflag = 0;
	for(j = 0;j<5;j++)
	{

		chineseflag = 0;
		for(int i = linestart ; i < linestart + 16;i++)
		{
			if(text[i] < 128 && text[i] >=0)
			{
				chineseflag ++;
			}
		}
		if(chineseflag % 2 == 0)//双字节
		{
			memcpy(sayBox.showedText[j],&text[linestart],16);
			showedText[j][16]='\0';
			linestart+=16;
		}
		else
		{
			memcpy(sayBox.showedText[j],&text[linestart],15);
			showedText[j][15]='\0';
			linestart+=15;
		}
		if(linestart>=textLen)break;


	}
	//Message(text,12,37,8,1);
	Show(-1);
	TimerMessage(text,12,37,8,1,orderByte[startAddress+1]*100);
	return -(textLen + 4);
}
int ScriptEng::_DisableSave()   
{
	saveEnable = 0;
	return 0;
}
int ScriptEng::_EnableSave()    
{
	saveEnable = 1;
	return 0;
}
int ScriptEng::_GameSave()      
{
	save.Init(1);
	save.Read(-1);//20161221
	keyflag34 = 2;
	keyflag2 = 4;
	keyflag = 2;
	Show(0);
	inscriptsaveflag = 1;
	return -1;
}
int ScriptEng::_SetEventTimer() //待测试
{
	timeEventNum = 0;
	timeEventNo = orderByte[startAddress+1];
	timeEventSecond = BytesToInt2(&orderByte[startAddress+3]);
	//SetTimer (hwnd, 1, 500, NULL) ;
	//KillTimer (hwnd, 1) ;
	return 4;
}
int ScriptEng::_EnableShowPos() 
{
	posEnable = 1;
	return 0;
}
int ScriptEng::_DisableShowPos()
{
	posEnable = 0;
	return 0;
}
int ScriptEng::_SetTo()         
{
	int tmp1 = (orderByte[startAddress+3]==0)?256:orderByte[startAddress+3];//20160816
	int tmp2 = (orderByte[startAddress+1]==0)?256:orderByte[startAddress+1];//20160816

	this->globalValue[tmp1-1] = this->globalValue[tmp2-1];//20160829修正 
	return 4;
}
int ScriptEng::_TestGoodsNum()  
{
	int ret = goodList.CheckGoodExist(orderByte[startAddress + 1],orderByte[startAddress + 3]);
	if(ret == orderByte[startAddress + 5])
	{
		return 20000 + BytesToInt2(&orderByte[startAddress + 7]);//20000表示绝对地址
	}
	else if(ret > orderByte[startAddress + 5])
	{
		return 20000 + BytesToInt2(&orderByte[startAddress + 9]);//20000表示绝对地址
	}
	else
	{
		return 10;
	}
}

void ScriptEng::DelEquipUse()
{
	int tmp = 0;
	int goodType = goodList.equipInList[selectedGood][0] - 1;
	int goodIdx = goodList.equipInList[selectedGood][1] - 1;

	//判断佩戴标志是否可以
	if(goodList.good[goodType][goodIdx].owner == 0)
	{
		return;
	}

	//20161030 act获取
	int act[3];
	int j =0 ;
	for(int i = 0;i<25;i++)
	{
		if(roleList.actor[i].inRankFlag == 1)
		{
			int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
			act[k] = i;
			j++;
		}
	}

	if(goodList.equipInList[selectedGood][0] == 1)
	{
		if(roleList.actor[act[selectedRoleIdx]].head != 0)
		{
			goodList.Add(1,roleList.actor[act[selectedRoleIdx]].head,1);//20170116
			//goodList.equipInList[goodList.equipInListCount][0] = 1;
			//goodList.equipInList[goodList.equipInListCount][1] = roleList.actor[act[selectedRoleIdx]].head;
			//goodList.equipInList[goodList.equipInListCount][2] = 1;
			//goodList.equipInListCount ++;
		}
		tmp = roleList.actor[act[selectedRoleIdx]].head;
		roleList.actor[act[selectedRoleIdx]].head = goodList.equipInList[selectedGood][1];

	}
	else if(goodList.equipInList[selectedGood][0] == 2)
	{
		if(roleList.actor[act[selectedRoleIdx]].body != 0)
		{
			goodList.Add(2,roleList.actor[act[selectedRoleIdx]].body,1);//20170116
			//goodList.equipInList[goodList.equipInListCount][0] = 2;
			//goodList.equipInList[goodList.equipInListCount][1] = roleList.actor[act[selectedRoleIdx]].body;
			//goodList.equipInList[goodList.equipInListCount][2] = 1;
			//goodList.equipInListCount ++;
		}
		tmp = roleList.actor[act[selectedRoleIdx]].body;
		roleList.actor[act[selectedRoleIdx]].body = goodList.equipInList[selectedGood][1];
	}
	else if(goodList.equipInList[selectedGood][0] == 3)
	{
		if(roleList.actor[act[selectedRoleIdx]].foot != 0)
		{
			goodList.Add(3,roleList.actor[act[selectedRoleIdx]].foot,1);//20170116
			//goodList.equipInList[goodList.equipInListCount][0] = 3;
			//goodList.equipInList[goodList.equipInListCount][1] = roleList.actor[act[selectedRoleIdx]].foot;
			//goodList.equipInList[goodList.equipInListCount][2] = 1;
			//goodList.equipInListCount ++;
		}
		tmp = roleList.actor[act[selectedRoleIdx]].foot;
		roleList.actor[act[selectedRoleIdx]].foot = goodList.equipInList[selectedGood][1];
	}
	else if(goodList.equipInList[selectedGood][0] == 4)
	{
		if(roleList.actor[act[selectedRoleIdx]].shoulder != 0)
		{
			goodList.Add(4,roleList.actor[act[selectedRoleIdx]].shoulder,1);//20170116
			//goodList.equipInList[goodList.equipInListCount][0] = 4;
			//goodList.equipInList[goodList.equipInListCount][1] = roleList.actor[act[selectedRoleIdx]].shoulder;
			//goodList.equipInList[goodList.equipInListCount][2] = 1;
			//goodList.equipInListCount ++;
		}
		tmp = roleList.actor[act[selectedRoleIdx]].shoulder;
		roleList.actor[act[selectedRoleIdx]].shoulder = goodList.equipInList[selectedGood][1];
	}
	else if(goodList.equipInList[selectedGood][0] == 5)
	{
		if(roleList.actor[act[selectedRoleIdx]].sleeve != 0)
		{
			goodList.Add(5,roleList.actor[act[selectedRoleIdx]].sleeve,1);//20170116
			//goodList.equipInList[goodList.equipInListCount][0] = 5;
			//goodList.equipInList[goodList.equipInListCount][1] = roleList.actor[act[selectedRoleIdx]].sleeve;
			//goodList.equipInList[goodList.equipInListCount][2] = 1;
			//goodList.equipInListCount ++;
		}
		tmp = roleList.actor[act[selectedRoleIdx]].sleeve;
		roleList.actor[act[selectedRoleIdx]].sleeve = goodList.equipInList[selectedGood][1];
	}
	else if(goodList.equipInList[selectedGood][0] == 6)//20160228修正饰品使用
	{
		tmp =0;
		if(decorateflag == 0)//自动
		{
			if(roleList.actor[act[selectedRoleIdx]].decorate1 == 0)
			{
				roleList.actor[act[selectedRoleIdx]].decorate1 = goodList.equipInList[selectedGood][1];
			}
			else if(roleList.actor[act[selectedRoleIdx]].decorate2 == 0)
			{
				roleList.actor[act[selectedRoleIdx]].decorate2 = goodList.equipInList[selectedGood][1];
			}
			else
			{
				goodList.Add(6,roleList.actor[act[selectedRoleIdx]].decorate1,1);//20170116
				//goodList.equipInList[goodList.equipInListCount][0] = 6;
				//goodList.equipInList[goodList.equipInListCount][1] = roleList.actor[act[selectedRoleIdx]].decorate1;
				//goodList.equipInList[goodList.equipInListCount][2] = 1;
				//goodList.equipInListCount ++;
				tmp = roleList.actor[act[selectedRoleIdx]].decorate1;
				roleList.actor[act[selectedRoleIdx]].decorate1 = goodList.equipInList[selectedGood][1];
			}
		}
		else if(decorateflag == 1)//1号位
		{
			if(roleList.actor[act[selectedRoleIdx]].decorate1 != 0)
			{
				goodList.Add(6,roleList.actor[act[selectedRoleIdx]].decorate1,1);//20170116
				//goodList.equipInList[goodList.equipInListCount][0] = 6;
				//goodList.equipInList[goodList.equipInListCount][1] = roleList.actor[act[selectedRoleIdx]].decorate1;
				//goodList.equipInList[goodList.equipInListCount][2] = 1;
				//goodList.equipInListCount ++;
			}


			tmp = roleList.actor[act[selectedRoleIdx]].decorate1;
			roleList.actor[act[selectedRoleIdx]].decorate1 = goodList.equipInList[selectedGood][1];
		}
		else if(decorateflag == 2)//2号位
		{
			if(roleList.actor[act[selectedRoleIdx]].decorate2 != 0)
			{
				goodList.Add(6,roleList.actor[act[selectedRoleIdx]].decorate2,1);//20170116
				//goodList.equipInList[goodList.equipInListCount][0] = 6;
				//goodList.equipInList[goodList.equipInListCount][1] = roleList.actor[act[selectedRoleIdx]].decorate2;
				//goodList.equipInList[goodList.equipInListCount][2] = 1;
				//goodList.equipInListCount ++;
			}


			tmp = roleList.actor[act[selectedRoleIdx]].decorate2;
			roleList.actor[act[selectedRoleIdx]].decorate2 = goodList.equipInList[selectedGood][1];
		}
		//20161231新增设置合体法术
		int tmpgoodIdx1 = roleList.actor[act[selectedRoleIdx]].decorate1-1;
		int tmpgoodIdx2 = roleList.actor[act[selectedRoleIdx]].decorate2-1;
		if(goodList.good[goodType][tmpgoodIdx1].allMagic >0 )
		{
			roleList.actor[act[selectedRoleIdx]].togethermagic = goodList.good[goodType][tmpgoodIdx1].allMagic;
		}
		else if(goodList.good[goodType][tmpgoodIdx2].allMagic >0 )
		{
			roleList.actor[act[selectedRoleIdx]].togethermagic = goodList.good[goodType][tmpgoodIdx2].allMagic;
		}
		else
		{
			roleList.actor[act[selectedRoleIdx]].togethermagic = 0;
		}
	}
	else if(goodList.equipInList[selectedGood][0] == 7)
	{
		if(roleList.actor[act[selectedRoleIdx]].hand != 0)
		{
			goodList.Add(7,roleList.actor[act[selectedRoleIdx]].hand,1);//20170116
			//goodList.equipInList[goodList.equipInListCount][0] = 7;
			//goodList.equipInList[goodList.equipInListCount][1] = roleList.actor[act[selectedRoleIdx]].hand;
			//goodList.equipInList[goodList.equipInListCount][2] = 1;
			//goodList.equipInListCount ++;
		}
		tmp = roleList.actor[act[selectedRoleIdx]].hand;
		roleList.actor[act[selectedRoleIdx]].hand = goodList.equipInList[selectedGood][1];

	}
	//人物属性改变
	tmp --;
	int pmt = goodList.equipInList[selectedGood][1]-1;

	//20160317增加装备事件号
	if(goodList.good[goodType][tmp].event >0)
	{
		globalEvent[goodList.good[goodType][tmp].event -1]= 0;
	}

	if(goodList.good[goodType][pmt].event >0)
	{
		globalEvent[goodList.good[goodType][pmt].event -1]= 1;
	}


	if(goodType == 6 )//武器
	{
		if(tmp>=0)
		{
			roleList.actor[act[selectedRoleIdx]].hpMax -= goodList.good[goodType][tmp].hpmax;
			roleList.actor[act[selectedRoleIdx]].hpMax = CheckFit(roleList.actor[act[selectedRoleIdx]].hpMax,HPMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].mpMax -= goodList.good[goodType][tmp].mpmax;
			roleList.actor[act[selectedRoleIdx]].mpMax = CheckFit(roleList.actor[act[selectedRoleIdx]].mpMax,MPMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].att -= goodList.good[goodType][tmp].at;
			roleList.actor[act[selectedRoleIdx]].att = CheckFit(roleList.actor[act[selectedRoleIdx]].att,ATMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].def -= goodList.good[goodType][tmp].df;
			roleList.actor[act[selectedRoleIdx]].def = CheckFit(roleList.actor[act[selectedRoleIdx]].def,DFMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].speed -= goodList.good[goodType][tmp].speed;
			roleList.actor[act[selectedRoleIdx]].speed = CheckFit(roleList.actor[act[selectedRoleIdx]].speed,SPEEDMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].anima -= goodList.good[goodType][tmp].anima;
			roleList.actor[act[selectedRoleIdx]].anima = CheckFit(roleList.actor[act[selectedRoleIdx]].anima,ANIMAMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].lucky -= goodList.good[goodType][tmp].lucky;
			roleList.actor[act[selectedRoleIdx]].lucky = CheckFit(roleList.actor[act[selectedRoleIdx]].lucky,LUCKMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].atcause -= goodList.good[goodType][tmp].all_dlfm_Flag;//免疫
		}


		roleList.actor[act[selectedRoleIdx]].hpMax += goodList.good[goodType][pmt].hpmax;
		roleList.actor[act[selectedRoleIdx]].hpMax = CheckFit(roleList.actor[act[selectedRoleIdx]].hpMax,HPMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].mpMax += goodList.good[goodType][pmt].mpmax;
		roleList.actor[act[selectedRoleIdx]].mpMax = CheckFit(roleList.actor[act[selectedRoleIdx]].mpMax,MPMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].att += goodList.good[goodType][pmt].at;
		roleList.actor[act[selectedRoleIdx]].att = CheckFit(roleList.actor[act[selectedRoleIdx]].att,ATMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].def += goodList.good[goodType][pmt].df;
		roleList.actor[act[selectedRoleIdx]].def = CheckFit(roleList.actor[act[selectedRoleIdx]].def,DFMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].speed += goodList.good[goodType][pmt].speed;
		roleList.actor[act[selectedRoleIdx]].speed = CheckFit(roleList.actor[act[selectedRoleIdx]].speed,SPEEDMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].anima += goodList.good[goodType][pmt].anima;
		roleList.actor[act[selectedRoleIdx]].anima = CheckFit(roleList.actor[act[selectedRoleIdx]].anima,ANIMAMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].lucky += goodList.good[goodType][pmt].lucky;
		roleList.actor[act[selectedRoleIdx]].lucky = CheckFit(roleList.actor[act[selectedRoleIdx]].lucky,LUCKMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].atcause += goodList.good[goodType][pmt].all_dlfm_Flag;//免疫
	}
	else if(goodType == 5 )//饰品
	{
		if(tmp>=0)
		{
			roleList.actor[act[selectedRoleIdx]].hpAdd -= goodList.good[goodType][tmp].hp;
			roleList.actor[act[selectedRoleIdx]].hpAdd = CheckFit(roleList.actor[act[selectedRoleIdx]].hpAdd,HPMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].mpAdd -= goodList.good[goodType][tmp].mp;
			roleList.actor[act[selectedRoleIdx]].mpAdd = CheckFit(roleList.actor[act[selectedRoleIdx]].mpAdd,MPMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].att -= goodList.good[goodType][tmp].at;
			roleList.actor[act[selectedRoleIdx]].att = CheckFit(roleList.actor[act[selectedRoleIdx]].att,ATMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].def -= goodList.good[goodType][tmp].df;
			roleList.actor[act[selectedRoleIdx]].def = CheckFit(roleList.actor[act[selectedRoleIdx]].def,DFMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].speed -= goodList.good[goodType][tmp].speed;
			roleList.actor[act[selectedRoleIdx]].speed = CheckFit(roleList.actor[act[selectedRoleIdx]].speed,SPEEDMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].anima -= goodList.good[goodType][tmp].anima;
			roleList.actor[act[selectedRoleIdx]].anima = CheckFit(roleList.actor[act[selectedRoleIdx]].anima,ANIMAMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].lucky -= goodList.good[goodType][tmp].lucky;
			roleList.actor[act[selectedRoleIdx]].lucky = CheckFit(roleList.actor[act[selectedRoleIdx]].lucky,LUCKMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].togethermagic = goodList.good[goodType][tmp].allMagic;
		}

		roleList.actor[act[selectedRoleIdx]].hpAdd += goodList.good[goodType][pmt].hp;
		roleList.actor[act[selectedRoleIdx]].hpAdd = CheckFit(roleList.actor[act[selectedRoleIdx]].hpAdd,HPMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].mpAdd += goodList.good[goodType][pmt].mp;
		roleList.actor[act[selectedRoleIdx]].mpAdd = CheckFit(roleList.actor[act[selectedRoleIdx]].mpAdd,MPMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].att += goodList.good[goodType][pmt].at;
		roleList.actor[act[selectedRoleIdx]].att = CheckFit(roleList.actor[act[selectedRoleIdx]].att,ATMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].def += goodList.good[goodType][pmt].df;
		roleList.actor[act[selectedRoleIdx]].def = CheckFit(roleList.actor[act[selectedRoleIdx]].def,DFMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].speed += goodList.good[goodType][pmt].speed;
		roleList.actor[act[selectedRoleIdx]].speed = CheckFit(roleList.actor[act[selectedRoleIdx]].speed,SPEEDMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].anima += goodList.good[goodType][pmt].anima;
		roleList.actor[act[selectedRoleIdx]].anima = CheckFit(roleList.actor[act[selectedRoleIdx]].anima,ANIMAMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].lucky += goodList.good[goodType][pmt].lucky;
		roleList.actor[act[selectedRoleIdx]].lucky = CheckFit(roleList.actor[act[selectedRoleIdx]].lucky,LUCKMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].togethermagic = goodList.good[goodType][pmt].allMagic;
	}
	else
	{
		if(tmp>=0)
		{
			roleList.actor[act[selectedRoleIdx]].hpMax -= goodList.good[goodType][tmp].hpmax;
			roleList.actor[act[selectedRoleIdx]].hpMax = CheckFit(roleList.actor[act[selectedRoleIdx]].hpMax,HPMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].mpMax -= goodList.good[goodType][tmp].mpmax;
			roleList.actor[act[selectedRoleIdx]].mpMax = CheckFit(roleList.actor[act[selectedRoleIdx]].mpMax,MPMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].att -= goodList.good[goodType][tmp].at;
			roleList.actor[act[selectedRoleIdx]].att = CheckFit(roleList.actor[act[selectedRoleIdx]].att,ATMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].def -= goodList.good[goodType][tmp].df;
			roleList.actor[act[selectedRoleIdx]].def = CheckFit(roleList.actor[act[selectedRoleIdx]].def,DFMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].speed -= goodList.good[goodType][tmp].speed;
			roleList.actor[act[selectedRoleIdx]].speed = CheckFit(roleList.actor[act[selectedRoleIdx]].speed,SPEEDMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].anima -= goodList.good[goodType][tmp].anima;
			roleList.actor[act[selectedRoleIdx]].anima = CheckFit(roleList.actor[act[selectedRoleIdx]].anima,ANIMAMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].lucky -= goodList.good[goodType][tmp].lucky;
			roleList.actor[act[selectedRoleIdx]].lucky = CheckFit(roleList.actor[act[selectedRoleIdx]].lucky,LUCKMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].anti -= goodList.good[goodType][tmp].all_dlfm_Flag;//免疫
		}

		roleList.actor[act[selectedRoleIdx]].hpMax += goodList.good[goodType][pmt].hpmax;
		roleList.actor[act[selectedRoleIdx]].hpMax = CheckFit(roleList.actor[act[selectedRoleIdx]].hpMax,HPMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].mpMax += goodList.good[goodType][pmt].mpmax;
		roleList.actor[act[selectedRoleIdx]].mpMax = CheckFit(roleList.actor[act[selectedRoleIdx]].mpMax,MPMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].att += goodList.good[goodType][pmt].at;
		roleList.actor[act[selectedRoleIdx]].att = CheckFit(roleList.actor[act[selectedRoleIdx]].att,ATMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].def += goodList.good[goodType][pmt].df;
		roleList.actor[act[selectedRoleIdx]].def = CheckFit(roleList.actor[act[selectedRoleIdx]].def,DFMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].speed += goodList.good[goodType][pmt].speed;
		roleList.actor[act[selectedRoleIdx]].speed = CheckFit(roleList.actor[act[selectedRoleIdx]].speed,SPEEDMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].anima += goodList.good[goodType][pmt].anima;
		roleList.actor[act[selectedRoleIdx]].anima = CheckFit(roleList.actor[act[selectedRoleIdx]].anima,ANIMAMAX);//20170111
		roleList.actor[act[selectedRoleIdx]].lucky += goodList.good[goodType][pmt].lucky;
		roleList.actor[act[selectedRoleIdx]].lucky = CheckFit(roleList.actor[act[selectedRoleIdx]].lucky,LUCKMAX);//20170111
		//20170107
		int tmp1 = 0;
		if(roleList.actor[act[selectedRoleIdx]].anti > 0)
		{

			if(roleList.actor[act[selectedRoleIdx]].anti  /8 > 0 && goodList.good[goodType][pmt].all_dlfm_Flag /8 > 0)
			{
				tmp1 += 8;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti  %8/4 > 0 && goodList.good[goodType][pmt].all_dlfm_Flag %8/4 > 0)
			{
				tmp1 += 4;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti  %4/2 > 0 && goodList.good[goodType][pmt].all_dlfm_Flag %4/2 > 0)
			{
				tmp1 += 2;
			}
			if(roleList.actor[act[selectedRoleIdx]].anti %2 > 0 && goodList.good[goodType][pmt].all_dlfm_Flag %2 > 0)
			{
				tmp1 += 1;
			}
		}
		roleList.actor[act[selectedRoleIdx]].anti += goodList.good[goodType][pmt].all_dlfm_Flag;//免疫
		roleList.actor[act[selectedRoleIdx]].anti -= tmp1;

		if(roleList.actor[act[selectedRoleIdx]].anti > 15)
		{
			roleList.actor[act[selectedRoleIdx]].anti = 0;
		}
	}

	//roleList.actor[act[selectedRoleIdx]].att += goodList.good[1][selectedGood].at;

	if(goodList.equipInList[selectedGood][2] == 1)
	{
		for(int i = selectedGood ; i<goodList.equipInListCount;i++)//删除链中道具
		{
			goodList.equipInList[i][0] = goodList.equipInList[i+1][0];
			goodList.equipInList[i][1] = goodList.equipInList[i+1][1];
			goodList.equipInList[i][2] = goodList.equipInList[i+1][2];
		}
		goodList.equipInListCount --;
		return ;
	}
	else
	{
		goodList.equipInList[selectedGood][2] --;
		return ;
	}



}

int ScriptEng::DelGoodEffect()
{
	int goodType = goodList.goodInList[selectedGood][0] - 1;
	int goodIdx = goodList.goodInList[selectedGood][1] - 1;

	//处理角色属性增加
	//roleList.actor[attFlag2].att += goodList.good[goodType][goodIdx].at;
	//roleList.actor[attFlag2].def += goodList.good[goodType][goodIdx].df;
	//roleList.actor[attFlag2].hp += goodList.good[goodType][goodIdx].hp;
	//roleList.actor[attFlag2].mp += goodList.good[goodType][goodIdx].mp;
	if(goodType == 7 || goodType == 11)//暗器 兴奋剂
	{
		//无法使用
		TimerMessage("战斗中才能使用！",10,37,8,1,1000);
		return -1;
	}
	else if(goodType == 8)//药物 hp mp 战斗才处理异常
	{
		//全体效果20160902
		if(goodList.good[goodType][goodIdx].all_dlfm_Flag > 15)//全体
		{
			int act[3];
			int j =0 ;
			for(int i = 0;i<25;i++)
			{
				if(roleList.actor[i].inRankFlag == 1)
				{
					int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
					act[k] = i;
					j++;
				}
			}

			for(int i = 0 ; i < j ; i ++)
			{
				roleList.actor[act[i]].hp += goodList.good[goodType][goodIdx].hp;
				if(roleList.actor[act[i]].hp > roleList.actor[act[i]].hpMax )
				{
					roleList.actor[act[i]].hp = roleList.actor[act[i]].hpMax;
				}
				roleList.actor[act[i]].mp += goodList.good[goodType][goodIdx].mp;
				if(roleList.actor[act[i]].mp > roleList.actor[act[i]].mpMax )
				{
					roleList.actor[act[i]].mp = roleList.actor[act[i]].mpMax;
				}
			}
		}
		else
		{
			int act[3];//20170118
			int j =0 ;
			for(int i = 0;i<25;i++)
			{
				if(roleList.actor[i].inRankFlag == 1)
				{
					int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
					act[k] = i;
					j++;
				}
			}

			roleList.actor[act[selectedRoleIdx]].hp += goodList.good[goodType][goodIdx].hp;
			if(roleList.actor[act[selectedRoleIdx]].hp > roleList.actor[act[selectedRoleIdx]].hpMax )
			{
				roleList.actor[act[selectedRoleIdx]].hp = roleList.actor[act[selectedRoleIdx]].hpMax;
			}
			roleList.actor[act[selectedRoleIdx]].mp += goodList.good[goodType][goodIdx].mp;
			if(roleList.actor[act[selectedRoleIdx]].mp > roleList.actor[act[selectedRoleIdx]].mpMax )
			{
				roleList.actor[act[selectedRoleIdx]].mp = roleList.actor[act[selectedRoleIdx]].mpMax;
			}
		}
	}
	else if(goodType == 9)//灵药 hp百分比
	{
		//全体效果20160902
		if(goodList.good[goodType][goodIdx].all_dlfm_Flag > 15)//全体
		{
			int act[3];
			int j =0 ;
			for(int i = 0;i<25;i++)
			{
				if(roleList.actor[i].inRankFlag == 1)
				{
					int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
					act[k] = i;
					j++;
				}
			}

			for(int i = 0 ; i < j ; i ++)
			{
				roleList.actor[act[i]].hp += goodList.good[goodType][goodIdx].hp*roleList.actor[i].hpMax/100;
				if(roleList.actor[act[i]].hp > roleList.actor[act[i]].hpMax )
				{
					roleList.actor[act[i]].hp = roleList.actor[act[i]].hpMax;
				}
			}
		}
		else
		{
			int act[3];//20170118
			int j =0 ;
			for(int i = 0;i<25;i++)
			{
				if(roleList.actor[i].inRankFlag == 1)
				{
					int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
					act[k] = i;
					j++;
				}
			}

			roleList.actor[act[selectedRoleIdx]].hp += goodList.good[goodType][goodIdx].hp*roleList.actor[act[selectedRoleIdx]].hpMax/100;
			if(roleList.actor[act[selectedRoleIdx]].hp > roleList.actor[act[selectedRoleIdx]].hpMax )
			{
				roleList.actor[act[selectedRoleIdx]].hp = roleList.actor[act[selectedRoleIdx]].hpMax;
			}
		}
	}
	else if(goodType == 10)//仙药 属性
	{
		if(goodList.good[goodType][goodIdx].all_dlfm_Flag > 15)//全体
		{
			int act[3];
			int j =0 ;
			for(int i = 0;i<25;i++)
			{
				if(roleList.actor[i].inRankFlag == 1)
				{
					int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
					act[k] = i;
					j++;
				}
			}

			for(int i = 0 ; i < j ; i ++)
			{
				roleList.actor[act[i]].hpMax += goodList.good[goodType][goodIdx].hpmax;
				roleList.actor[act[i]].hpMax = CheckFit(roleList.actor[act[i]].hpMax,HPMAX);//20170111
				roleList.actor[act[i]].mpMax += goodList.good[goodType][goodIdx].mpmax;
				roleList.actor[act[i]].mpMax = CheckFit(roleList.actor[act[i]].mpMax,MPMAX);//20170111
				roleList.actor[act[i]].att += goodList.good[goodType][goodIdx].at;
				roleList.actor[act[i]].att = CheckFit(roleList.actor[act[i]].att,ATMAX);//20170111
				roleList.actor[act[i]].def += goodList.good[goodType][goodIdx].df;
				roleList.actor[act[i]].def = CheckFit(roleList.actor[act[i]].def,DFMAX);//20170111
				roleList.actor[act[i]].speed += goodList.good[goodType][goodIdx].speed;
				roleList.actor[act[i]].speed = CheckFit(roleList.actor[act[i]].speed,SPEEDMAX);//20170111
				roleList.actor[act[i]].anima += goodList.good[goodType][goodIdx].anima;
				roleList.actor[act[i]].anima = CheckFit(roleList.actor[act[i]].anima,ANIMAMAX);//20170111
				roleList.actor[act[i]].lucky += goodList.good[goodType][goodIdx].lucky;
				roleList.actor[act[i]].lucky = CheckFit(roleList.actor[act[i]].lucky,LUCKMAX);//20170111
			}
		}
		else
		{
			int act[3];//20170118
			int j =0 ;
			for(int i = 0;i<25;i++)
			{
				if(roleList.actor[i].inRankFlag == 1)
				{
					int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
					act[k] = i;
					j++;
				}
			}

			roleList.actor[act[selectedRoleIdx]].hpMax += goodList.good[goodType][goodIdx].hpmax;
			roleList.actor[act[selectedRoleIdx]].hpMax = CheckFit(roleList.actor[act[selectedRoleIdx]].hpMax,HPMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].mpMax += goodList.good[goodType][goodIdx].mpmax;
			roleList.actor[act[selectedRoleIdx]].mpMax = CheckFit(roleList.actor[act[selectedRoleIdx]].mpMax,MPMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].att += goodList.good[goodType][goodIdx].at;
			roleList.actor[act[selectedRoleIdx]].att = CheckFit(roleList.actor[act[selectedRoleIdx]].att,ATMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].def += goodList.good[goodType][goodIdx].df;
			roleList.actor[act[selectedRoleIdx]].def = CheckFit(roleList.actor[act[selectedRoleIdx]].def,DFMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].speed += goodList.good[goodType][goodIdx].speed;
			roleList.actor[act[selectedRoleIdx]].speed = CheckFit(roleList.actor[act[selectedRoleIdx]].speed,SPEEDMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].anima += goodList.good[goodType][goodIdx].anima;
			roleList.actor[act[selectedRoleIdx]].anima = CheckFit(roleList.actor[act[selectedRoleIdx]].anima,ANIMAMAX);//20170111
			roleList.actor[act[selectedRoleIdx]].lucky += goodList.good[goodType][goodIdx].lucky;
			roleList.actor[act[selectedRoleIdx]].lucky = CheckFit(roleList.actor[act[selectedRoleIdx]].lucky,LUCKMAX);//20170111
		}
	}
	else if(goodType == 12)//土遁
	{
		//RunOrderCycle(jumpTable[250 - 1] - 3 - jumpSegmentLen*2);//250事件
		if(RunOrderCycle(jumpTable[250 - 1] - 3 - jumpSegmentLen*2)==GAMEOVER_FLAG)
		{
			return GAMEOVER_FLAG;
		}
		return -1;
	}
	else if(goodType == 13)//剧情
	{
		//_CallChapter();
		//CallChapter(255,goodIdx + 1);//调用255-x脚本
	}

	if(goodList.goodInList[selectedGood][2] == 1)//20160719修正selectedGood
	{
		for(int i = selectedGood ; i<goodList.goodInListCount;i++)//删除链中道具
		{
			goodList.goodInList[i][0] = goodList.goodInList[i+1][0];
			goodList.goodInList[i][1] = goodList.goodInList[i+1][1];
			goodList.goodInList[i][2] = goodList.goodInList[i+1][2];

		}
		goodList.goodInListCount --;
		return -1;
	}
	else
	{
		goodList.goodInList[selectedGood][2] --;//20160719修正selectedGood
		return 0;
	}
}

void ScriptEng::DelMagicUse()
{
	int act[3];
	int j =0 ;
	for(int i = 0;i<25;i++)
	{
		if(roleList.actor[i].inRankFlag == 1)
		{
			int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
			act[k] = i;
			j++;
		}
	}


	//使用
	roleList.actor[act[selectedRoleIdx]].mp -= actorMagicList[act[selectedRoleIdx]].magic[selectedMagic].cost;
	if(roleList.actor[act[selectedRoleIdx]].mp < 0 )
	{
		roleList.actor[act[selectedRoleIdx]].mp += actorMagicList[act[selectedRoleIdx]].magic[selectedMagic].cost;
		TimerMessage("真气不足！",10,37,8,1,1000);
		return ;
	}
	roleList.actor[act[attFlag2]].hp += actorMagicList[act[selectedRoleIdx]].magic[selectedMagic].hp;
	if(roleList.actor[act[attFlag2]].hp >roleList.actor[act[attFlag2]].hpMax)
	{
		roleList.actor[act[attFlag2]].hp = roleList.actor[act[attFlag2]].hpMax;
	}
}

void ScriptEng::MusicOnOff(int i,int times)//times循环次数
{
	wlogfile(1, __FUNCTION__ ,"开始",0);
	if(i ==0)//关
	{

	}
	else//开 1-11
	{

	}
}

void ScriptEng::DelBuyGood()
{
	wlogfile(1, __FUNCTION__ ,"开始",0); 
	money -= attFlag * goodList.good[selectedEquipType-1][selectedEquipId-1].buy;
	goodList.Add(selectedEquipType,selectedEquipId,attFlag);
}

void ScriptEng::DelSellGood()
{
	wlogfile(1, __FUNCTION__ ,"开始",0); 
	money += attFlag * goodList.good[selectedEquipType-1][selectedEquipId-1].sell;
	goodList.Del(selectedEquipType,selectedEquipId,attFlag);
}

int ScriptEng::DelTimerEvent()
{
	if(keyflag!=0)return 0;
	if(keyflagfight == 1)
	{
		timeEventNum2++;
		if(timeEventNum2 == 5)
		{
			timeEventNum2 = 0;
			fight.Show(-100);
		}
	}
	else
	{
		timeEventNum++;
		if(timeEventNum%3 == 0)
		{
			timeEventNum3++;

			if(timeEventSecond == timeEventNum3 )
			{
				timeEventNum = 0;
				timeEventNum3 = 0;
				if(jumpTable[timeEventNo - 1] != 0)
				{
					//RunOrderCycle(jumpTable[timeEventNo - 1] - 3 - jumpSegmentLen*2);//定时事件
					if(RunOrderCycle(jumpTable[timeEventNo - 1] - 3 - jumpSegmentLen*2)==GAMEOVER_FLAG)
					{
						return GAMEOVER_FLAG;
					}
				}
			}
		}
		//npc移动

		if(timeEventNum % 10 ==0 && keyflag == 0 && keyflag5 == 0 && keyflag51 == 0 && keyflag52 == 0)
		{
			map.Show(0);
			//20170129修正,加入条件
			if(roleList.actor[actorShowNum].inRankFlag == 1)roleList.actor[actorShowNum].Show(0);
			for(int i = 0 ; i < 255 ;i++)
			{
				if(roleList.nPC[i].showFlag == 1)
				{
					map.mapNpc[roleList.nPC[i].ax-1][roleList.nPC[i].ay-1] = 0;
					int rnd = -1;
					rnd = rand()%4;//选择4个面向
					int ret = CheckNPCMoveable(i,rnd);//20160719新增检测NPC可行走
					if (ret)
					{
						roleList.nPC[i].Move(rnd);
					}

					int npcx = roleList.nPC[i].ax;
					int npcy = roleList.nPC[i].ay;

					int sx = npcx - map.x;
					int sy = npcy - map.y;

					//roleList.nPC[i].PubInit(roleList.nPC[i].no);
					roleList.nPC[i].Init(-1,sx,sy);
					map.mapNpc[roleList.nPC[i].ax-1][roleList.nPC[i].ay-1] = i+1;
					roleList.nPC[i].Show(0);
				}
				if(roleList.sceneObj[i].showFlag == 1)
				{
					roleList.sceneObj[i].Move();
					//map.mapNpc[roleList.sceneObj[i].ax-1][roleList.sceneObj[i].ay-1] = i+1+100;
					SetObjMapNpc(roleList.sceneObj[i].ax-1,roleList.sceneObj[i].ay-1,i+1,0);
					roleList.sceneObj[i].Show(0);
				}

			}

			//20210911增加边框显示，用于覆盖右侧sceneObj
			BitBlt(hdcTmp, 0, 0, 7, 96, hdcMem, 0, 0, WHITENESS);
			BitBlt(hdcTmp, 151, 0, 159, 96, hdcMem, 0, 0, WHITENESS);
			MoveToEx(hdcTmp,0,0,NULL);
			LineTo(hdcTmp,0,96);
			MoveToEx(hdcTmp,2,0,NULL);
			LineTo(hdcTmp,2,96);
			MoveToEx(hdcTmp,4,0,NULL);
			LineTo(hdcTmp,4,96);
			MoveToEx(hdcTmp,6,0,NULL);
			LineTo(hdcTmp,6,96);
			MoveToEx(hdcTmp,151,0,NULL);
			LineTo(hdcTmp,151,96);
			MoveToEx(hdcTmp,153,0,NULL);
			LineTo(hdcTmp,153,96);
			MoveToEx(hdcTmp,155,0,NULL);
			LineTo(hdcTmp,155,96);
			MoveToEx(hdcTmp,157,0,NULL);
			LineTo(hdcTmp,157,96);

			//20160726修正显示主角重新更新的条件如下
			//上一行的mapnpc不为0
			if(map.mapNpc[map.x-1+4][map.y-1+2]!=0)
			{
				if(roleList.actor[actorShowNum].inRankFlag == 1)roleList.actor[actorShowNum].Show(0);//20160625修正位置 20170129修正
			}
			if(posEnable == 1)//显示坐标框
			{
				BITMAP bwh;
				int type1 = GetType(RES_ACP,2,17);
				if(type1 == 1)
				{
					LoadPic(RES_PIC,2,17,hbmp);
					HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
					BitBlt(hdcTmp, 8, 0, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);
					DeleteObject(hbmp);
				}
				else
				{
					LoadPicMask(RES_PIC,2,17,hbmp);
					HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					GetObject(hbmp, sizeof (BITMAP), &bwh) ;//获取位图尺寸	
					BitBlt(hdcTmp, 8, 0, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCPAINT);
					SelectObject(hdcMem, oldhbmp);
					DeleteObject(hbmp);

					LoadPicTrans(RES_PIC,2,17,hbmp);
					//GetObject(hbmp, sizeof(BITMAP), &bmp);
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 8, 0, bwh.bmWidth, bwh.bmHeight, hdcMem, 0, 0, SRCAND);
					SelectObject(hdcMem, oldhbmp);
					DeleteObject(hbmp);
				}
				ShowNumInPic(16,4,map.x,0);
				ShowNumInPic(32,4,map.y,0);
			}
		}

		//20161221新增玩家自动行走
		if(timeEventNum%5 == 0 && autowalkflag == 1)
		{
			int t_KeyCode = 0;
			switch(map.dirction)
			{
			case 1:
				t_KeyCode = KeyUp0;
				break;
			case 2:
				t_KeyCode = KeyRight0;
				break;
			case 3:
				t_KeyCode = KeyDown0;
				break;
			case 4:
				t_KeyCode = KeyLeft0;
				break;
			default:
				break;
			}

			int ret = map.KeyDown(t_KeyCode);//返回值判断是否触发事件的事件号

			roleList.actor[actorShowNum].KeyDown(t_KeyCode);
			Show(0);
			if(ret > 0 && jumpTable[40 + ret - 1] > 0 && map.dirction != 0)//地图事件
			{
				//RunOrderCycle(jumpTable[40 + ret - 1] - 3 - jumpSegmentLen*2);
				if(RunOrderCycle(jumpTable[40 + ret - 1] - 3 - jumpSegmentLen*2)==GAMEOVER_FLAG)
				{
					return GAMEOVER_FLAG;
				}
			}
			else if(ret < 0)//npc事件
			{
				if(ret < -100)//sceneobj事件
				{
					roleList.sceneObj[-ret-100-1].KeyDown(0);

				}
				ret = ret % 100;
				if(jumpTable[- ret  - 1]>0)
				{
					//RunOrderCycle(jumpTable[- ret  - 1] - 3 - jumpSegmentLen*2);
					if(RunOrderCycle(jumpTable[- ret  - 1] - 3 - jumpSegmentLen*2)==GAMEOVER_FLAG)
					{
						return GAMEOVER_FLAG;
					}
				}
			}
			else if(fightEnable == 1 && runDebug == 0 && rand()%100 > 90)//进入随机战斗
			{
				int ret1 = fight.UsedInit();
				if(ret1 != -1)
				{
					//fighthero初始化
					fight.enemySum = 0;
					fight.livedEnemySum = 0;
					fight.randomEnemy();
					SetFightHeroData();
					fight.Show(t_KeyCode);
					keyflagfight = 1 ;
				}



			}


		}

		InvalidateRect(hwnd,NULL,FALSE);
	}
	return 0;
}

void ScriptEng::SetStackForCallChapter()
{
	wlogfile(1, __FUNCTION__ ,"开始",0);
	wlogfile(1, __FUNCTION__ ,"callStackDeep = ",callStackDeep);
	if(callStackDeep == 0)memset(callStack,0,sizeof(callStack));//20160816修正
	callStack[callStackDeep][0] = orderPos;//当前执行位置
	callStack[callStackDeep][1] = keyflag;
	callStack[callStackDeep][2] = saveEnable;
	callStack[callStackDeep][3] = newStartFlag;
	callStack[callStackDeep][4] = newStartType ;
	callStack[callStackDeep][5] = newStartIdx ;

	callStack[callStackDeep][6] = scriptType ;//脚本类型
	callStack[callStackDeep][7] = scriptIndex;//脚本编号
	callStack[callStackDeep][8] = scriptByteLen;//脚本总长度
	callStack[callStackDeep][9] = jumpSegmentLen ;//跳转段长度
	callStack[callStackDeep][10] = orderByteLen ;//指令段长度
	callStack[callStackDeep][11] = orderByteStart ;//指令段起始位置


	//保留跳转段
	for(int i = 0;i < jumpSegmentLen;i++)
	{
		callStack[callStackDeep][20+i] = jumpTable[i];
	}

	//保存指令段
	for(int i = 0;i < orderByteLen+orderByteStart;i++)
	{
		callStack[callStackDeep][300+i] = orderByte[i] ;
	}
	callStackDeep ++;
}

void ScriptEng::getStackForRun()
{
	wlogfile(1, __FUNCTION__ ,"开始",0);
	wlogfile(1, __FUNCTION__ ,"callStackDeep = ",callStackDeep);
	if(callStackDeep==0)
	{
		//orderPos = 0;//重定位为起始脚本//20170329取消重定位
		return;
	}
	callStackDeep --;
	orderPos = callStack[callStackDeep][0];//当前执行位置
	keyflag = callStack[callStackDeep][1];
	saveEnable = callStack[callStackDeep][2];
	newStartFlag = callStack[callStackDeep][3];
	newStartType = callStack[callStackDeep][4];
	newStartIdx = callStack[callStackDeep][5];

	scriptType = callStack[callStackDeep][6];//脚本类型
	scriptIndex = callStack[callStackDeep][7];//脚本编号
	scriptByteLen = callStack[callStackDeep][8];//脚本总长度
	jumpSegmentLen = callStack[callStackDeep][9];//跳转段长度
	orderByteLen = callStack[callStackDeep][10];//指令段长度
	orderByteStart = callStack[callStackDeep][11];//指令段起始位置


	//保留跳转段
	for(int i = 0;i < jumpSegmentLen;i++)
	{
		jumpTable[i] = callStack[callStackDeep][20+i];
	}

	//保存指令段
	for(int i = 0;i < orderByteLen+orderByteStart;i++)
	{
		orderByte[i] = callStack[callStackDeep][300+i];
	}
}

void ScriptEng::AfterFight(int isrunaway)
{
	wlogfile(1, __FUNCTION__ ,"开始",0); 
	int act[3];
	int j = 0;
	int k = 0;
	for(int i = 0;i<25;i++)
	{
		if(roleList.actor[i].inRankFlag == 1)
		{
			int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
			act[k] = i;

			j++;
		}

	}

	//恢复roleList
	for(int i = 0;i<j;i++)
	{
		roleList.actor[act[i]].degree = fight.fighthero[i].degree ;
		roleList.actor[act[i]].att = fight.fighthero[i].att;
		roleList.actor[act[i]].def = fight.fighthero[i].def  ;
		roleList.actor[act[i]].speed = fight.fighthero[i].speed  ;
		roleList.actor[act[i]].hp = fight.fighthero[i].hp ;
		if(roleList.actor[act[i]].inRankFlag == 1&&isrunaway ==0)//20170107修正HP MP恢复
		{
			int rnd = rand()%10+1;
			roleList.actor[act[i]].hp += rnd;//20160902
			if(roleList.actor[act[i]].hp  > roleList.actor[act[i]].hpMax)//20170110
			{
				roleList.actor[act[i]].hp  = roleList.actor[act[i]].hpMax;
			}
		}
		roleList.actor[act[i]].mp = fight.fighthero[i].mp  ;
		if(roleList.actor[act[i]].inRankFlag == 1&&isrunaway ==0)//20170107修正HP MP恢复
		{
			int rnd = rand()%10+1;
			roleList.actor[act[i]].mp += rnd;
			if(roleList.actor[act[i]].mp  > roleList.actor[act[i]].mpMax)//20170110
			{
				roleList.actor[act[i]].mp  = roleList.actor[act[i]].mpMax;
			}
		}
		roleList.actor[act[i]].exp = fight.fighthero[i].exp  ;
		roleList.actor[act[i]].expMax = fight.fighthero[i].expMax  ;
		roleList.actor[act[i]].anima = fight.fighthero[i].anima  ;
		roleList.actor[act[i]].lucky = fight.fighthero[i].lucky  ;

		roleList.actor[act[i]].hpAdd = fight.fighthero[i].hpAdd  ;
		roleList.actor[act[i]].mpAdd = fight.fighthero[i].mpAdd  ;
		roleList.actor[act[i]].head = fight.fighthero[i].head  ;
		roleList.actor[act[i]].body = fight.fighthero[i].body  ;
		roleList.actor[act[i]].shoulder = fight.fighthero[i].shoulder  ;
		roleList.actor[act[i]].sleeve = fight.fighthero[i].sleeve  ;
		roleList.actor[act[i]].hand = fight.fighthero[i].hand  ;
		roleList.actor[act[i]].foot = fight.fighthero[i].foot  ;
		roleList.actor[act[i]].decorate1 = fight.fighthero[i].decorate1  ;
		roleList.actor[act[i]].decorate2 = fight.fighthero[i].decorate2  ;
		roleList.actor[act[i]].hpMax = fight.fighthero[i].hpMax  ;
		roleList.actor[act[i]].mpMax = fight.fighthero[i].mpMax  ;

		roleList.actor[act[i]].magicLearn = fight.fighthero[i].magicLearn  ;

	}

	//道具list

	j = 0;
	goodList.Clear();
	for(int i = 0 ; i < fight.goodList.goodInListCount;i++)
	{
		//if(fight.goodList.goodInList[i][0] == 8)continue;20161217
		if(fight.goodList.goodInList[i][0] < 8)continue;//20161218删除道具链非道具物品
		goodList.goodInList[j][0]= fight.goodList.goodInList[i][0];
		goodList.goodInList[j][1]= fight.goodList.goodInList[i][1];
		goodList.goodInList[j][2]= fight.goodList.goodInList[i][2];
		j++;
	}
	goodList.goodInListCount = j;

	for(int i = 0 ; i < fight.equipList.equipInListCount;i++)
	{
		if(fight.goodList.equipInList[i][0] > 7)continue;//20161218删除装备链非装备物品 20161220修正 
		goodList.equipInList[k][0]= fight.equipList.equipInList[i][0];
		goodList.equipInList[k][1]= fight.equipList.equipInList[i][1];
		goodList.equipInList[k][2]= fight.equipList.equipInList[i][2];
		k++;
	}
	goodList.equipInListCount = k;//fight.equipList.equipInListCount;

	//j = 0 ;
	k = 0;
	for(int i = 0 ; i < fight.throwList.goodInListCount;i++)
	{
		if(fight.throwList.goodInList[i][0] == 8)
		{
			goodList.goodInList[j][0] = fight.throwList.goodInList[i][0] ;
			goodList.goodInList[j][1] = fight.throwList.goodInList[i][1] ;
			goodList.goodInList[j][2] = fight.throwList.goodInList[i][2] ;
			j++;
		}
	}
	goodList.goodInListCount = j;

	//20160225 金钱
	money+=fight.allMoney;

}

void ScriptEng::SetFightHeroData()
{
	wlogfile(1, __FUNCTION__ ,"开始",0);
	int act[3];
	int j = 0;
	for(int i = 0;i<25;i++)
	{
		if(roleList.actor[i].inRankFlag == 1)
		{
			int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
			act[k] = i;

			j++;
			if(j==3)break;
		}
	}
	fight.actorSum = j;

	//初始化fighthero,由于数据有变化，所以只能载入 不能读取
	for(int i = 0;i<j;i++)
	{

		fight.fighthero[i].degree = roleList.actor[act[i]].degree;
		fight.fighthero[i].att = roleList.actor[act[i]].att;
		fight.fighthero[i].def = roleList.actor[act[i]].def;
		fight.fighthero[i].speed = roleList.actor[act[i]].speed;
		fight.fighthero[i].hp = roleList.actor[act[i]].hp;
		fight.fighthero[i].mp = roleList.actor[act[i]].mp;
		fight.fighthero[i].exp = roleList.actor[act[i]].exp;
		fight.fighthero[i].expMax = roleList.actor[act[i]].expMax;
		fight.fighthero[i].anima = roleList.actor[act[i]].anima;
		fight.fighthero[i].lucky = roleList.actor[act[i]].lucky;
		fight.fighthero[i].disround = roleList.actor[act[i]].disround;
		fight.fighthero[i].anti = roleList.actor[act[i]].anti;
		fight.fighthero[i].atcause = roleList.actor[act[i]].atcause;
		fight.fighthero[i].togethermagic = roleList.actor[act[i]].togethermagic;
		fight.fighthero[i].hpAdd = roleList.actor[act[i]].hpAdd;
		fight.fighthero[i].mpAdd = roleList.actor[act[i]].mpAdd;
		fight.fighthero[i].head = roleList.actor[act[i]].head;
		fight.fighthero[i].body = roleList.actor[act[i]].body;
		fight.fighthero[i].shoulder = roleList.actor[act[i]].shoulder;
		fight.fighthero[i].sleeve = roleList.actor[act[i]].sleeve;
		fight.fighthero[i].hand = roleList.actor[act[i]].hand;
		fight.fighthero[i].foot = roleList.actor[act[i]].foot;
		fight.fighthero[i].decorate1 = roleList.actor[act[i]].decorate1;
		fight.fighthero[i].decorate2 = roleList.actor[act[i]].decorate2;
		fight.fighthero[i].hpMax = roleList.actor[act[i]].hpMax;
		fight.fighthero[i].mpMax = roleList.actor[act[i]].mpMax;

		fight.fighthero[i].no = roleList.actor[act[i]].no;
		fight.fighthero[i].faceTo = roleList.actor[act[i]].faceTo;
		fight.fighthero[i].step = roleList.actor[act[i]].step;
		fight.fighthero[i].action = roleList.actor[act[i]].action;
		fight.fighthero[i].magicMaxInList = roleList.actor[act[i]].magicMaxInList;
		fight.fighthero[i].magicLearn = roleList.actor[act[i]].magicLearn;
		fight.fighthero[i].magicListNo = roleList.actor[act[i]].magicListNo;
		fight.fighthero[i].picno = roleList.actor[act[i]].picno;

		fight.fighthero[i].du = 0;//20160818
		fight.fighthero[i].ruan = 0;
		fight.fighthero[i].feng = 0;
		fight.fighthero[i].mian = 0;
		fight.fighthero[i].ateffect = 0;
		fight.fighthero[i].dfeffect = 0;
		fight.fighthero[i].speedeffect = 0;

		memcpy(fight.fighthero[i].name, roleList.actor[act[i]].name,11);

	}

	//初始化magiclist 3+3
	for(int i = 0 ;i < j ; i ++)
	{
		//初始化magiclist
		fight.magicList[i] = actorMagicList[act[i]];
		//fight.magicList[i].Init(actorMagicList[act[i]].no - 1);
		fight.magicLen[i] = actorMagicList[act[i]].magicCount;
	}

	for(int i = 3 ;i < 6 ; i ++)
	{
		//初始化magiclist

		if(fight.fightType==1)//剧情战
		{
			if(fight.e_enemyType[i-3]<=0)continue;//20160818
			fight.magicList[i].Init(magicList[roleList.ememy[fight.e_enemyType[i-3]-1].magicLink - 1].no);//20161219修正魔法链异常
			fight.magicLen[i] = magicList[roleList.ememy[fight.e_enemyType[i-3]-1].magicLink - 1].magicCount;
		}
		else//随机战
		{
			if(fight.fightEnemy[i-3].no<=0)continue;//20160818
			fight.magicList[i].Init(magicList[roleList.ememy[fight.fightEnemy[i-3].no-1].magicLink - 1].no);//20161219修正魔法链异常
			fight.magicLen[i] = magicList[roleList.ememy[fight.fightEnemy[i-3].no-1].magicLink - 1].magicCount;
		}

	}


	//初始化degreelist

	for(int i = 0 ;i < 3 ; i ++)
	{
		fight.degreeList[i].Init(act[i]+1);

	}

	//初始化道具list
	fight.goodList.Init();
	j = 0;
	for(int i = 0 ; i < goodList.goodInListCount;i++)
	{
		if(goodList.goodInList[i][0] == 8)continue;
		fight.goodList.goodInList[j][0]= goodList.goodInList[i][0];
		fight.goodList.goodInList[j][1]= goodList.goodInList[i][1];
		fight.goodList.goodInList[j][2]= goodList.goodInList[i][2];
		j++;
	}
	fight.goodAll = j;
	fight.goodList.goodInListCount = j;

	for(int i = 0 ; i < goodList.equipInListCount;i++)
	{

		fight.equipList.equipInList[i][0]= goodList.equipInList[i][0];
		fight.equipList.equipInList[i][1]= goodList.equipInList[i][1];
		fight.equipList.equipInList[i][2]= goodList.equipInList[i][2];
	}
	fight.equipAll = goodList.equipInListCount;
	fight.equipList.equipInListCount = goodList.equipInListCount;

	j = 0 ;
	int k = 0;
	for(int i = 0 ; i < goodList.equipInListCount;i++)
	{
		if(goodList.equipInList[i][0] == 7)
		{
			fight.throwList.goodInList[j][0]= goodList.equipInList[i][0];
			fight.throwList.goodInList[j][1]= goodList.equipInList[i][1];
			fight.throwList.goodInList[j][2]= goodList.equipInList[i][2];
			j++;
		}
	}
	//fight.throwList.equipInListCount = j;


	for(int i = 0 ; i < goodList.goodInListCount;i++)
	{
		if(goodList.goodInList[i][0] == 8)
		{
			fight.throwList.goodInList[j][0]= goodList.goodInList[i][0];
			fight.throwList.goodInList[j][1]= goodList.goodInList[i][1];
			fight.throwList.goodInList[j][2]= goodList.goodInList[i][2];
			j++;
		}
	}
	fight.throwList.goodInListCount = j;//-fight.throwList.equipInListCount;
	fight.throwAll = j;
	if(throwflag == 0)
	{
		fight.throwflag = 1;
	}
	else
	{
		fight.throwflag = 0;
	}
	fight.missflag = missflag;
}


int ScriptEng::_SetArmsToss()
{
	throwflag = BytesToInt2(&orderByte[startAddress + 1]);
	return 2;
}

int ScriptEng::_SetFightMiss()
{
	missflag = BytesToInt2(&orderByte[startAddress + 1]);
	return 2;
}

void ScriptEng::SetObjMapNpc(int x,int y,int num,int type)
{
	//wlogfile(1, __FUNCTION__ ,"开始",0);
	int tmp = 0;
	if(type == 1 && map.mapNpc[x][y]!=0 )	
	{
		tmp = GetPicSize(RES_ACP,4,roleList.sceneObj[(map.mapNpc[x][y]-100)-1].picno,0);
	}
	else
	{
		tmp = GetPicSize(RES_ACP,4,roleList.sceneObj[num-1].picno,0);
	}

	int width = (tmp/10000-1)/16+1;
	int height = (tmp%10000-1)/16+1;

	map.mapNpc[x][y+height-1] = type==0?num+100:0;//20160726修正 20160829修正

	/*for(int i = 0 ;i < width ;i ++)
	{
	for(int j =0;j< height ;j ++)
	{
	map.mapNpc[x+i][y+j] = type==0?num+100:0;
	}
	}*/

}

int ScriptEng::CheckNPCMoveable(int npcid,int faceTo)//返回0-不需要 1-需要 2-定时增加
{
	//wlogfile(1, __FUNCTION__ ,"开始",0); 
	int npcx = roleList.nPC[npcid].ax;
	int npcy = roleList.nPC[npcid].ay;

	int sx = npcx - map.x;
	int sy = npcy - map.y;

	if(roleList.nPC[npcid].action == 4||roleList.nPC[npcid].action == 0)
	{
		return 1;
	}
	else if(roleList.nPC[npcid].action == 3 && roleList.nPC[npcid].delayGot != roleList.nPC[npcid].delay) 
	{
		return 1;
	}
	else//需要移动的情况
	{
		if(roleList.nPC[npcid].faceTo == faceTo)//满足移动条件
		{
			if(faceTo == 0 && map.enableByte[map.width * (npcy-1) + npcx]&&npcx>=4&&npcy>=3&&(sx != 4 && sy != 4))
			{
				if(map.mapNpc[npcx-1][npcy-1-1]!=0)return 0;//npc碰撞
				return 1;
			}
			else if(faceTo == 1 && map.enableByte[map.width * npcy + npcx + 1 ]&&npcx>=4&&npcy>=3&&(sx != 3 && sy != 3))
			{
				if(map.mapNpc[npcx-1+1][npcy-1]!=0)return 0;
				return 1;
			}
			else if(faceTo == 2 && map.enableByte[map.width * (npcy+1) + npcx]&&npcx>=4&&npcy>=3&&(sx != 4 && sy != 2))
			{
				if(map.mapNpc[npcx-1][npcy-1+1]!=0)return 0;
				return 1;
			}
			else if(faceTo == 3 && map.enableByte[map.width * npcy + npcx - 1 ]&&npcx>=4&&npcy>=3&&(sx != 5 && sy != 3))
			{
				if(map.mapNpc[npcx-1-1][npcy-1]!=0)return 0;
				return 1;
			}		
			else
			{
				return 0;
			}
		}
		else
		{
			return 1;
		}
	}			
	return 0;
}

int ScriptEng::DgCheckSysMsg()
{

	MSG msg;
	if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
	{
		if(GetMessage(&msg,NULL,0,0)) 
		{

			if(msg.message == WM_COPYDATA)//20161118
			{
				COPYDATASTRUCT *pCopyData = (COPYDATASTRUCT*)msg.lParam;  
				char szBuffer[300];  

				memset(szBuffer, 0, sizeof(szBuffer));  
				sprintf(szBuffer, "%s", (char*)pCopyData->lpData);  

				//数据分析,进行断点中断处理
				int ret = DgDelMsg((int)pCopyData->cbData,szBuffer);
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				if(ret == 12)
				{
					return 12;
				}
				return 1;
			}
		}

	}
	return 0;
}

//值定义
//事件号（参数号）[返回值]
//0-无效信息 
//1-设置断点（脚本类 脚本序号 orderpos）[0-成功1-失败] 
//2-取消断点（脚本类 脚本序号 orderpos）[0-成功1-失败] 
//3-添加监视（类型 1-事件2变量，序号）[0-成功1-失败] 
//4-取消监视（类型 1-事件2变量，序号）[0-成功1-失败] 
//5-设置事件（事件号 值）[0-成功1-失败] 
//6-设置伤害（0-999999）[0-成功1-失败] 
//7-设置下一事件概率（0-1000）[0-成功1-失败] 
//8-设置变量（变量号 值）[0-成功1-失败] 
//9-设置单步调试临时断点（脚本类 脚本序号 orderpos）[0-成功1-失败] 
//11-命中断点
//12-继续调试
//20210816
//21-获得道具（类 序号）[0-成功1-失败] 
//22-学会法术（类 序号）[0-成功1-失败] 
//23-获得金钱（0-99999）[0-成功1-失败] 
//24-角色升级（角色序号 等级）[0-成功1-失败] 
//25-角色属性设置（角色序号 属性 值）[0-成功1-失败] 
int ScriptEng::DgDelMsg(int type,char *value)
{
	const char *sep = ":"; //可按多个字符来分割
	char *p;
	int u_value[10];
	int i = 0;
	p = strtok(value, sep);
	while(p)
	{
		u_value[i] = atoi(p);
		i++;
		p = strtok(NULL, sep);
	}

	switch (type)
	{
	case 1:
		DgAddBreakPoint(u_value[0],u_value[1],u_value[2]);//脚本类 脚本序号 orderpos
		break;
	case 2:
		DgDelBreakPoint(u_value[0],u_value[1],u_value[2]);//脚本类 脚本序号 orderpos
		break;
	case 3:
		DgAddMonitor(u_value[0],u_value[1]);//类型 1-事件2变量，序号 
		break;
	case 4:
		DgDelMonitor(u_value[0],u_value[1]);//类型 1-事件2变量，序号 
		break;
	case 5:
		DgSetEvent(u_value[0],u_value[1]);//事件号 值
		break;
	case 6:
		DgSetHurt(u_value[0]);//伤害
		break;
	case 7:
		DgSetRand(u_value[0]);//rand
		break;
	case 8:
		DgSetVal(u_value[0],u_value[1]);//变量号 值
		break;
	case 9:
		DgAddBreakPointStep(u_value[0],u_value[1],u_value[2]);//脚本类 脚本序号 orderpos
		break;
	case 11:

		break;
	case 21:
		DgGainGood(u_value[0],u_value[1]);
		break;
	case 22:
		DgLearnMagic(u_value[0],u_value[1],u_value[2]);
		break;
	case 23:
		DgGainMoney(u_value[0]);
		break;
	case 24:
		DgLevelUp(u_value[0],u_value[1]);
		break;
	case 25:
		DgAttSet(u_value[0],u_value[1],u_value[2]);
		break;
	default:
		break;
	}


	int retvalue = 0;
	COPYDATASTRUCT CopyData;  
	char szSendBuf[300];
	memset(szSendBuf,0,sizeof(szSendBuf));
	retvalue = 0;
	if(type == 12)
	{
		retvalue = 12;
		sprintf(szSendBuf,"%d",g_dgOrderPos);
		CopyData.dwData = retvalue;
		CopyData.cbData = strlen(szSendBuf);  
		CopyData.lpData = szSendBuf;

	}
	else 
	{
		//sprintf(szSendBuf,"%d",retvalue);
		CopyData.dwData = retvalue;
		//CopyData.cbData = strlen(szSendBuf);  
		//CopyData.lpData = szSendBuf;  
	}
	HWND hRecvWindow = FindWindow(NULL, "SkyRPGFactory");  
	if (hRecvWindow == NULL)  
		return -1;  

	SendMessage(hRecvWindow, WM_COPYDATA, (WPARAM)hwnd, (LPARAM)&CopyData);  
	return retvalue;//返回需要回复的值
}

//1-返回事件（事件号0-2999）[事件值0/1] 
//2-返回变量（0-255）[变量值] 
int ScriptEng::DgCheckRet(int orderType,int i)
{
	for(int k = 0 ; k < dgbreakpointmax ; k ++)
	{

		if(abs(dgbreakpoint[k].type) == scriptType && dgbreakpoint[k].idx == scriptIndex && dgbreakpoint[k].orderpos == i)
		{
			char msg[100];
			//判断是否有事件需要返回，是否需要中断 //判断是否有变量需要返回，是否需要中断
			for(int j = 0; j < dgmonitormax ; j ++)
			{

				memset(msg,0,sizeof(msg));
				if(dgmonitor[j].type == 1)
				{
					sprintf(msg,"%d:%d\0",dgmonitor[j].idx,globalEvent[dgmonitor[j].idx-1]);
					SendMsg(1,msg);
				}
				if(dgmonitor[j].type == 2)
				{
					sprintf(msg,"%d:%d\0",dgmonitor[j].idx,globalValue[dgmonitor[j].idx-1]);
					SendMsg(2,msg);
				}
			}
			memset(msg,0,sizeof(msg));
			sprintf(msg,"%d\0",g_dgOrderPos);
			SendMsg(11,msg);
			DgDelay(-1);

		}
		if(dgbreakpoint[k].type < 0)
		{
			DgDelBreakPoint(abs(dgbreakpoint[k].type),scriptIndex,i);
		}
	}


	return 0;
}

int ScriptEng::DgDelay(long time)
{
	while( 1 )
	{
		int ret = DgCheckSysMsg();
		if(g_dgdelayFlag == 1)
		{
			g_dgdelayFlag = 0;
			return -1;
		}
		Sleep(1);
	}
	return 0; 
}


int ScriptEng::DgAddBreakPoint(int type,int idx,int orderpos)
{
	dgbreakpoint[dgbreakpointmax].type = type;
	dgbreakpoint[dgbreakpointmax].idx = idx;
	dgbreakpoint[dgbreakpointmax].orderpos = orderpos;
	dgbreakpointmax++;
	return 0;
}

int ScriptEng::DgAddBreakPointStep(int type,int idx,int orderpos)
{
	dgbreakpoint[dgbreakpointmax].type = -type;
	dgbreakpoint[dgbreakpointmax].idx = idx;
	dgbreakpoint[dgbreakpointmax].orderpos = orderpos;
	dgbreakpointmax++;
	return 0;
}


int ScriptEng::DgDelBreakPoint(int type,int idx,int orderpos)
{
	for(int i = 0 ; i < dgbreakpointmax ; i ++)
	{
		if(abs(dgbreakpoint[i].type) == type && dgbreakpoint[i].idx == idx && dgbreakpoint[i].orderpos == orderpos)
		{
			for(int j = i;j<(dgbreakpointmax - 1);j++)
			{
				dgbreakpoint[j].type = dgbreakpoint[j+1].type;
				dgbreakpoint[j].idx = dgbreakpoint[j+1].idx;
				dgbreakpoint[j].orderpos = dgbreakpoint[j+1].orderpos;
			}
			break;
		}
	}

	dgbreakpointmax--;
	if(dgbreakpointmax<0)dgbreakpointmax = 0;
	return 0;
}

int ScriptEng::DgAddMonitor(int type,int idx)
{
	dgmonitor[dgmonitormax].type = type;
	dgmonitor[dgmonitormax].idx = idx;
	dgmonitormax++;
	//DgCheckRet(orderType,g_dgOrderPos);//判断命中或返回 orderType 位置码
	return 0;
}

int ScriptEng::DgDelMonitor(int type,int idx)
{
	for(int i = 0 ; i < dgmonitormax ; i ++)
	{
		if(dgmonitor[i].type == type && dgmonitor[i].idx == idx)
		{
			for(int j = i;j<(dgmonitormax - 1);j++)
			{
				dgmonitor[j].type = dgmonitor[j+1].type;
				dgmonitor[j].idx = dgmonitor[j+1].idx;
			}
			break;
		}
	}

	dgmonitormax--;
	return 0;
}

int ScriptEng::DgSetEvent(int idx,int value)
{
	globalEvent[idx]=value;
	return 0;
}

int ScriptEng::DgSetHurt(int hurt)
{
	fight.dghurt = hurt;
	return 0;
}

int ScriptEng::DgSetRand(int rand)
{
	dgrand = rand;
	return 0;
}

int ScriptEng::DgSetVal(int idx,int value)
{
	globalValue[idx]=value;
	return 0;
}

int ScriptEng::DgGainGood(int type,int idx)//20210816 22
{
	goodList.Add(type,idx,1);
	return 0;
}

int ScriptEng::DgLearnMagic(int actorid,int type,int idx)//20210816 22
{
	actorMagicList[actorid].Add(type,idx,roleList.actor[actorid].magicLearn);
	roleList.actor[actorid].magicLearn++;
	actorMagicList[actorid].exLearned++;
	return 0;
}

int ScriptEng::DgGainMoney(int value)//20210816 23
{
	this->money += value;
	if(this->money > MONEYMAX ) this->money = MONEYMAX;
	return 0;
}

int ScriptEng::DgLevelUp(int actorid,int level)//20210816 24//20210903修正负数及等级为0
{
	int roleId = actorid-1;
	if(roleList.actor[roleId].degree < level)
	{
		int olddegree = roleList.actor[roleId].degree-1;
		int newdegree = level-1;
		roleList.actor[roleId].degree = level;

		//20210802处理升级属性提升
		roleList.actor[roleId].hpMax = roleList.actor[roleId].hpMax - degreeList[roleId].hpMax[olddegree] + degreeList[roleId].hpMax[newdegree] ;
		if(roleList.actor[roleId].hpMax>HPMAX)roleList.actor[roleId].hpMax = HPMAX;
		if(roleList.actor[roleId].hpMax<0)roleList.actor[roleId].hpMax = 0;
		roleList.actor[roleId].hp = roleList.actor[roleId].hpMax;

		roleList.actor[roleId].mpMax = roleList.actor[roleId].mpMax - degreeList[roleId].mpMax[olddegree] + degreeList[roleId].mpMax[newdegree] ;
		if(roleList.actor[roleId].mpMax>MPMAX)roleList.actor[roleId].mpMax = MPMAX;
		if(roleList.actor[roleId].mpMax<0)roleList.actor[roleId].mpMax = 0;
		roleList.actor[roleId].mp = roleList.actor[roleId].mpMax;

		roleList.actor[roleId].att = roleList.actor[roleId].att - degreeList[roleId].at[olddegree] + degreeList[roleId].at[newdegree] ;
		if(roleList.actor[roleId].att>ATMAX)roleList.actor[roleId].att = ATMAX;
		if(roleList.actor[roleId].att<0)roleList.actor[roleId].att = 0;

		roleList.actor[roleId].def = roleList.actor[roleId].def - degreeList[roleId].df[olddegree] + degreeList[roleId].df[newdegree] ;
		if(roleList.actor[roleId].def>DFMAX)roleList.actor[roleId].def = DFMAX;
		if(roleList.actor[roleId].def<0)roleList.actor[roleId].def = 0;

		roleList.actor[roleId].speed = roleList.actor[roleId].speed - degreeList[roleId].speed[olddegree] + degreeList[roleId].speed[newdegree] ;
		if(roleList.actor[roleId].speed>SPEEDMAX)roleList.actor[roleId].speed = SPEEDMAX;
		if(roleList.actor[roleId].speed<0)roleList.actor[roleId].speed = 0;

		roleList.actor[roleId].lucky = roleList.actor[roleId].lucky - degreeList[roleId].lucky[olddegree] + degreeList[roleId].lucky[newdegree] ;
		if(roleList.actor[roleId].lucky>LUCKMAX)roleList.actor[roleId].lucky = LUCKMAX;
		if(roleList.actor[roleId].lucky<0)roleList.actor[roleId].lucky = 0;

		roleList.actor[roleId].anima = roleList.actor[roleId].anima - degreeList[roleId].anima[olddegree] + degreeList[roleId].anima[newdegree] ;
		if(roleList.actor[roleId].anima>ANIMAMAX)roleList.actor[roleId].anima = ANIMAMAX;
		if(roleList.actor[roleId].anima<0)roleList.actor[roleId].anima = 0;

		roleList.actor[roleId].expMax = degreeList[roleId].exp[newdegree] ;

		if(degreeList[roleId].learnedMagic[newdegree]>= degreeList[roleId].learnedMagic[olddegree])//20170820
		{
			roleList.actor[roleId].magicLearn = roleList.actor[roleId].magicLearn - degreeList[roleId].learnedMagic[olddegree] + degreeList[roleId].learnedMagic[newdegree];
		}

	}
	return 0;
}

int ScriptEng::DgAttSet(int actorid,int type,int value)//20210816 25
{
	//ATTRIBSET actor type attrval			---- 设置号码actor的主角的type（0-级别，1-攻击力，2-防御力，3-身法，4-生命，5-真气当前值，6-当前经验值，7-灵力，8-幸运，9-攻击的异常回合数，10-对特殊状态的免疫，11-普通攻击可能产生异常状态，12-合体法术，13-每回合变化生命，14-每回合变化真气，15-生命上限，16-真气上限）属性，属性值等于attrval。
	switch(type)
	{
	case 0:
		{
			roleList.actor[actorid].degree =  value;
			break;
		}
	case 1:
		{
			roleList.actor[actorid].att =  value;
			break;
		}
	case 2:
		{
			roleList.actor[actorid].def =  value;
			break;
		}
	case 3:
		{
			roleList.actor[actorid].speed =  value;
			break;
		}
	case 4:
		{
			roleList.actor[actorid].hp =  value;
			break;
		}
	case 5:
		{
			roleList.actor[actorid].mp =  value;
			break;
		}
	case 6:
		{
			roleList.actor[actorid].exp = value;
			break;
		}
	case 7:
		{
			roleList.actor[actorid].anima =  value;
			break;
		}
	case 8:
		{
			roleList.actor[actorid].lucky =  value;
			break;
		}
	case 9:
		{
			roleList.actor[actorid].disround =  value;
			break;
		}
	case 10:
		{
			roleList.actor[actorid].anti =  value;
			break;
		}
	case 11:
		{
			roleList.actor[actorid].atcause =  value;
			break;
		}
	case 12:
		{
			roleList.actor[actorid].togethermagic =  value;
			break;
		}
	case 13:
		{
			roleList.actor[actorid].mpAdd =  value;
			break;
		}
	case 14:
		{
			roleList.actor[actorid].hpAdd =  value;
			break;
		}
	case 15:
		{
			roleList.actor[actorid].hpMax =  value;
			break;
		}
	case 16:
		{
			roleList.actor[actorid].mpMax = value;
			break;
		}
	}
	return 0;
}

void ScriptEng::AddFightHeroData()
{
	wlogfile(1, __FUNCTION__ ,"开始",0);
	int act[3];
	int j = 0;
	for(int i = 0;i<25;i++)
	{
		if(roleList.actor[i].inRankFlag == 2)
		{
			//int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG//20170806
			act[j] = i;//20170806

			j++;
			roleList.actor[i].inRankFlag = 1;
			if(j==2)break;//最多2人
		}
	}
	int heroStartPos = fight.actorSum;
	fight.actorSum += j;
	if(fight.actorSum > 3) fight.actorSum = 3;

	//初始化fighthero,由于数据有变化，所以只能载入 不能读取
	for(int i = 0;i<j;i++)
	{
		if(i+heroStartPos > 2)break;
		fight.fighthero[i+heroStartPos].degree = roleList.actor[act[i]].degree;
		fight.fighthero[i+heroStartPos].att = roleList.actor[act[i]].att;
		fight.fighthero[i+heroStartPos].def = roleList.actor[act[i]].def;
		fight.fighthero[i+heroStartPos].speed = roleList.actor[act[i]].speed;
		fight.fighthero[i+heroStartPos].hp = roleList.actor[act[i]].hp;
		fight.fighthero[i+heroStartPos].mp = roleList.actor[act[i]].mp;
		fight.fighthero[i+heroStartPos].exp = roleList.actor[act[i]].exp;
		fight.fighthero[i+heroStartPos].expMax = roleList.actor[act[i]].expMax;
		fight.fighthero[i+heroStartPos].anima = roleList.actor[act[i]].anima;
		fight.fighthero[i+heroStartPos].lucky = roleList.actor[act[i]].lucky;
		fight.fighthero[i+heroStartPos].disround = roleList.actor[act[i]].disround;
		fight.fighthero[i+heroStartPos].anti = roleList.actor[act[i]].anti;
		fight.fighthero[i+heroStartPos].atcause = roleList.actor[act[i]].atcause;
		fight.fighthero[i+heroStartPos].togethermagic = roleList.actor[act[i]].togethermagic;
		fight.fighthero[i+heroStartPos].hpAdd = roleList.actor[act[i]].hpAdd;
		fight.fighthero[i+heroStartPos].mpAdd = roleList.actor[act[i]].mpAdd;
		fight.fighthero[i+heroStartPos].head = roleList.actor[act[i]].head;
		fight.fighthero[i+heroStartPos].body = roleList.actor[act[i]].body;
		fight.fighthero[i+heroStartPos].shoulder = roleList.actor[act[i]].shoulder;
		fight.fighthero[i+heroStartPos].sleeve = roleList.actor[act[i]].sleeve;
		fight.fighthero[i+heroStartPos].hand = roleList.actor[act[i]].hand;
		fight.fighthero[i+heroStartPos].foot = roleList.actor[act[i]].foot;
		fight.fighthero[i+heroStartPos].decorate1 = roleList.actor[act[i]].decorate1;
		fight.fighthero[i+heroStartPos].decorate2 = roleList.actor[act[i]].decorate2;
		fight.fighthero[i+heroStartPos].hpMax = roleList.actor[act[i]].hpMax;
		fight.fighthero[i+heroStartPos].mpMax = roleList.actor[act[i]].mpMax;

		fight.fighthero[i+heroStartPos].no = roleList.actor[act[i]].no;
		fight.fighthero[i+heroStartPos].faceTo = roleList.actor[act[i]].faceTo;
		fight.fighthero[i+heroStartPos].step = roleList.actor[act[i]].step;
		fight.fighthero[i+heroStartPos].action = roleList.actor[act[i]].action;
		fight.fighthero[i+heroStartPos].magicMaxInList = roleList.actor[act[i]].magicMaxInList;
		fight.fighthero[i+heroStartPos].magicLearn = roleList.actor[act[i]].magicLearn;
		fight.fighthero[i+heroStartPos].magicListNo = roleList.actor[act[i]].magicListNo;
		fight.fighthero[i+heroStartPos].picno = roleList.actor[act[i]].picno;

		fight.fighthero[i+heroStartPos].du = 0;//20160818
		fight.fighthero[i+heroStartPos].ruan = 0;
		fight.fighthero[i+heroStartPos].feng = 0;
		fight.fighthero[i+heroStartPos].mian = 0;
		fight.fighthero[i+heroStartPos].ateffect = 0;
		fight.fighthero[i+heroStartPos].dfeffect = 0;
		fight.fighthero[i+heroStartPos].speedeffect = 0;

		memcpy(fight.fighthero[i+heroStartPos].name, roleList.actor[act[i]].name,11);
		//strcpy(fight.fighthero[i+heroStartPos].name, roleList.actor[act[i]].name);//20170806

	}

	//初始化magiclist 3+3
	for(int i = 0 ;i < j ; i ++)
	{
		//初始化magiclist
		fight.magicList[i+heroStartPos] = actorMagicList[act[i]];
		//fight.magicList[i].Init(magicList[roleList.actor[act[i]].magicListNo-1].no - 1);
		fight.magicLen[i+heroStartPos] = actorMagicList[act[i]].magicCount;
	}



	//初始化degreelist

	for(int i = 0 ;i < j ; i ++)
	{
		fight.degreeList[i+heroStartPos].Init(act[i]+1);

	}


}

int ScriptEng::CheckAntiCauseBy(int type,int goodType,int goodIdx,int usedecorateflag)
{
	int act[3];
	for(int i = 0;i<25;i++)
	{
		if(roleList.actor[i].inRankFlag == 1)
		{
			int k = roleList.actor[i].inRankId;//20170308角色队列中角色顺序异常的BUG
			act[k] = i;

		}
	}
	int head = roleList.actor[act[selectedRoleIdx]].head;
	int body = roleList.actor[act[selectedRoleIdx]].body;
	int shoulder = roleList.actor[act[selectedRoleIdx]].shoulder;//17-肩披，
	int sleeve = roleList.actor[act[selectedRoleIdx]].sleeve;//18-护腕，
	int hand = roleList.actor[act[selectedRoleIdx]].hand;//19-手持，
	int foot = roleList.actor[act[selectedRoleIdx]].foot;//20-脚蹬，
	int decorate1 = roleList.actor[act[selectedRoleIdx]].decorate1;//21-佩戴1，
	int decorate2 = roleList.actor[act[selectedRoleIdx]].decorate2;//22-佩戴2，

	if(goodType == 0)//head
	{
		if(type == 1)
		{

			if(goodList.good[1][body].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag / 8 >0)return 0; 
		}
		else if(type == 2)
		{

			if(goodList.good[1][body].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 8 /4 >0)return 0; 
		}
		else if(type == 3)
		{

			if(goodList.good[1][body].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag% 4 /2 >0)return 0; 
		}
		else if(type == 4)
		{

			if(goodList.good[1][body].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag  % 2 >0)return 0; 
		}

	}
	if(goodType == 1)//body
	{
		if(type == 1)
		{

			if(goodList.good[0][head].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag / 8 >0)return 0; 
		}
		else if(type == 2)
		{

			if(goodList.good[0][head].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 8 /4>0)return 0; 
		}
		else if(type == 3)
		{

			if(goodList.good[0][head].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 4 /2 >0)return 0; 
		}
		else if(type == 4)
		{

			if(goodList.good[0][head].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag  % 2 >0)return 0; 
		}
	}
	if(goodType == 2)//foot
	{
		if(type == 1)
		{
			if(goodList.good[0][head].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag / 8 >0)return 0; 
		}
		else if(type == 2)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 8 /4 >0)return 0; 
		}
		else if(type == 3)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 4 /2 >0)return 0; 
		}
		else if(type == 4)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 2 >0)return 0; 
		}
	}
	if(goodType == 3)//shoulder
	{
		if(type == 1)
		{
			if(goodList.good[0][head].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag / 8 >0)return 0; 
		}
		else if(type == 2)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 8 /4 >0)return 0; 
		}
		else if(type == 3)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 4 /2 >0)return 0; 
		}
		else if(type == 4)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 2 >0)return 0; 
		}
	}
	if(goodType == 4)//sleeve
	{
		if(type == 1)
		{
			if(goodList.good[0][head].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag / 8 >0)return 0; 
		}
		else if(type == 2)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag% 8 /4 >0)return 0; 
		}
		else if(type == 3)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 4 /2 >0)return 0; 
		}
		else if(type == 4)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag  % 2 >0)return 0; 
		}
	}
	if(goodType == 5 && usedecorateflag == 1)//decorate1 
	{
		if(type == 1)
		{
			if(goodList.good[0][head].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag / 8 >0)return 0;  
			if(goodList.good[5][decorate2].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag / 8 >0)return 0; 
		}
		else if(type == 2)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 8 /4 >0)return 0; 
		}
		else if(type == 3)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 4 /2 >0)return 0; 
		}
		else if(type == 4)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag  % 2 >0)return 0; 
		}
	}
	if(goodType == 5 && usedecorateflag == 2 )//decorate2
	{
		if(type == 1)
		{
			if(goodList.good[0][head].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag / 8 >0)return 0; 
		}
		else if(type == 2)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 8 /4 >0)return 0; 
		}
		else if(type == 3)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag % 4 /2 >0)return 0; 
		}
		else if(type == 4)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[6][hand].all_dlfm_Flag  % 2 >0)return 0; 
		}
	}
	if(goodType == 6)//hand
	{
		if(type == 1)
		{
			if(goodList.good[0][head].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag / 8 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag / 8 >0)return 0; 

		}
		else if(type == 2)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 8 /4 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 8 /4 >0)return 0; 

		}
		else if(type == 3)
		{
			if(goodList.good[0][head].all_dlfm_Flag% 4 /2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 4 /2>0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 4 /2 >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 4 /2 >0)return 0; 

		}
		else if(type == 4)
		{
			if(goodList.good[0][head].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[1][body].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[2][foot].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[3][shoulder].all_dlfm_Flag % 2 >0)return 0; 
			if(goodList.good[4][sleeve].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate1].all_dlfm_Flag % 2  >0)return 0; 
			if(goodList.good[5][decorate2].all_dlfm_Flag % 2  >0)return 0;  
		}

	}
	return 1;

	//roleList.actor[act[selectedRoleIdx]].anti + goodList.good[equipType-1][equipIdx-1].all_dlfm_Flag
}