stoneage8.5/石器时代8.5客户端最新源代码/石器源码/system/shop.cpp
2020-06-23 15:53:23 +08:00

787 lines
30 KiB
C++

/************************/
#include "../systeminc/version.h"
#include "../systeminc/system.h"
#include "../systeminc/pc.h"
#include "../systeminc/shop.h"
#include "../systeminc/tool.h"
#include "../systeminc/menu.h"
#include "../systeminc/t_music.h"
#include "../systeminc/netmain.h"
#include "../systeminc/map.h"
#include "../NewProto/protocol.h"
#include "../systeminc/login.h"
#include "../other/caryIme.h"
#include "../systeminc/field.h"
#include "../wgs/tea.h"
#include "../systeminc/VMProtectSDK.h"
int getfilesize(FILE* fp)
{
if( fp == NULL) return 0;
int size;
fseek(fp,0,SEEK_END);
size = ftell(fp);
fseek(fp,0,SEEK_SET);
return size;
}
#ifdef _NEWSHOP_
void (short x,short y,UCHAR );
void ();
void (short );
extern void getStrSplit( char *, char *, int, int, int );
void StockFontBufferSplit(int x, int y, char unk1, int color, char* data, int unk2,int strLen){
char token[310]={0};
getStrSplit(token,(char *)data,0x64,3,strLen);
char * b = token;
int c = 20;
int d = 0;
do{
if(strlen(b)!=1) StockFontBuffer(x,y+c*d,unk1,color,b,unk2);
++d;
b+=100;
}while(d < 3);
}
typedef int BOOL;
extern int indexWN;
extern int idWN;
extern int cloasewindows;
typedef struct {
char [32];
unsigned int ;
unsigned int ;
unsigned int ;
char [500];
short ;
};
_ [5];
typedef struct {
short ;
short ;
} ;
typedef struct {
BOOL 使;
unsigned int ;
* ;
};
typedef struct {
[15];
short ;
short ;
short ;
short ;
unsigned int ;
} ;
typedef struct {
;
;
short ;
short ID;
short ;
short ;
BOOL ;
unsigned int ;
ACTION * ;
ACTION * ;
short ;
short ;
short X;
short Y;
short ;
BOOL ;
} ;
[200];
;
short [][2] = {
{90,100},
{245,100},
{90,193},
{245,193},
{90,282},
{242,282},
{90,369},
{242,369}
};
short [][2]={
{0,5},
{1,9},
{2,11},
{3,14},
{4,17},
{5,19}
};
unsigned short [][4] ={
{40041,40046,40066,35},
{40042,40047,40067,106},
{40043,40048,40068,176},
{40044,40049,40069,246},
{40045,40050,40070,316},
};
void 线()
{
memset(&,0,sizeof()*200);
memset(&,0,sizeof());
}
int ( char *arr[], char *str, const char *del)//字符分割函数的简单定义搜索和实现
{
int num = 0;
char *s =NULL;
char *p =NULL;
s=strtok_s(str,del,&p);
while(s != NULL) {
arr[num] = s;
s = strtok_s(NULL,del,&p);
num++;
}
num--;
return num;
}
void 线(char * )
{
if(.) DeathAction(.);
.=0;
if(.) DeathAction(.);
.=0;
.=-1;
线();
. = getIntegerToken(,'|',1);
. = getIntegerToken(,'|',2);
.ID = getIntegerToken(,'|',3);
..=1;
if([.ID-1].!=NULL){
int strlena=strlen([.ID-1].);
char * = new char [strlena+1];
memset(,0,strlena+1);
memcpy(,[.ID-1].,strlena);
char *[200] ={0};
char *[5]={0};
. = (,,"#");
int i=0;
for(;i<=.;i++){
(,[i],"|");
sprintf_s([i].,"%s",[0]);
[i]. = atoi( [1]);
[i]. = atoi( [2]);
[i]. = atoi( [3]);
sprintf_s([i].,"%s",[4]);
[i].[strlen([i].)]=0;
[i].[strlen([i].)]=0;
[i].=i;
}
.++;
if(. > 8)
..= .%8 ? ./8+1 : ./8;
else ..= 1;
.=-1;
.=FALSE;
delete ;
}
.=628;
.=386;
.X=(800-.)/2;
.Y=(600-.)/2-40;
}
ACTION* ()
{
if(.) DeathAction(.);
. = MakeWindowDisp(.X,.Y,0,0,[.ID-1][0],0,FALSE);
play_se(202,320,240);
return .;
}
ACTION* ()
{
if(.ID!=5){
if(.){
DeathAction(.);
.=0;
.=-1;
}
}
int ID;
StockDispBuffer(.X,.Y+28,104,[.ID-1][0],1);
//类型按钮
int i=0;
for(;i<5;i++){
if(i!=(.ID-1)){
if(MakeHitBox(.X+1,.Y+[i][3],.X+29,.Y+[i][3]+69,-1)==1){
if(!.){
StockDispBuffer(.X+1,.Y+[i][3],106,[i][2],1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
char [10]={0};
sprintf_s(,"%d",i+1);
lssproto_WN_send(sockfd,nowGx,nowGy,indexWN,idWN,0,);
windowTypeWN = -1;
wnCloseFlag = 1;
}else StockDispBuffer(.X+1,.Y+[i][3],106,[i][1],1);
}
}else StockDispBuffer(.X+1,.Y+[i][3],106,[i][1],1);
}
}
//关闭按钮
if(MakeHitBox(.X+595,.Y+27,.X+626,.Y+53,-1)==1){
StockDispBuffer(.X+594,.Y+27,105,40054,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
cloasewindows = 1;
}
}else StockDispBuffer(.X+595,.Y+27,105,40061,1);
if(.) (.X+130,.Y+140,110);
//结算按钮
if(MakeHitBox(.X+534,.Y+372,.X+591,.Y+391,-1)==1){
if(!.){
StockDispBuffer(.X+534,.Y+372,105,40072,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
if(..){
.=1;
.=TRUE;
}else{
.=2;
.=TRUE;
}
}
}else StockDispBuffer(.X+534,.Y+372,105,40058,1);
}else StockDispBuffer(.X+534,.Y+372,105,40058,1);
//清空功能
if(MakeHitBox(.X+435,.Y+372,.X+435+58,.Y+372+19,-1)==1){
if(!.){
StockDispBuffer(.X+435,.Y+372,105,40059,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
..=0;
..=0;
..=0;
..=0;
..=0;
..=0;
memset(..,0,sizeof()*15);
}
}else StockDispBuffer(.X+435,.Y+372,105,40073,1);
}else StockDispBuffer(.X+435,.Y+372,105,40073,1);
//商品上页
if(MakeHitBox(.X+379,.Y+39,.X+405,.Y+66,-1)==1){
if(!.){
StockDispBuffer(.X+379,.Y+39,105,40055,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
if(..>1) ..-=1;
}
}else StockDispBuffer(.X+379,.Y+39,105,40062,1);
}else StockDispBuffer(.X+379,.Y+39,105,40062,1);
//商品下页
if(MakeHitBox(.X+379,.Y+370,.X+405,.Y+397,-1)==1){
if(!.){
StockDispBuffer(.X+379,.Y+370,105,40056,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
if(..<..) ..+=1;
}
}else StockDispBuffer(.X+379,.Y+370,105,40063,1);
}else StockDispBuffer(.X+379,.Y+370,105,40063,1);
//printf("当前=%d 结束=%d\n",商城数据.滚动条.当前,商城数据.滚动条.终点);
short =0;
if(..==1 || ..==0) =75;
else if(..==..) =361;
else =(361-75)/(..-1)*(..-1)+75;
StockDispBuffer(.X+391,.Y+,105,26447,1);
//商城数据显示
if(.>0){
short ,;
= (..-1)*8+1;
= +7;
if( >.) = .;
short =0;
BOOL =FALSE;
i=;
for(;i<=;i++){
++;
ID = StockDispBuffer(.X+[-1][0],.Y+[-1][1],106,[i-1].,1);
if(HitDispNo==ID){
if(!.){
if(.){
if(.!=ID){
DeathAction(.);
.=0;
.=-1;
}
}
(.X+[-1][0],.Y+[-1][1],109,[i-1].,[i-1].,[i-1].);
=TRUE;
if(.) .=ID;
}else{
if(.){
DeathAction(.);
.=0;
.=-1;
}
}
}
//购买按钮
if(MakeHitBox(.X+[-1][0]+40,.Y+[-1][1],.X+[-1][0]+40+59,.Y+[-1][1]+22,-1)==1){
if(!.){
StockDispBuffer(.X+[-1][0]+40,.Y+[-1][1],105,40071,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
if(. < .. + [i-1].){
StockChatBufferLine("系统:身上的金币不足。",6);
break;
}
if(. < ..+1){
StockChatBufferLine("系统:身上的道具位不足。",6);
break;
}
if(!..){
memset(&..,0,sizeof()*15);
..[0].使=TRUE;
..[0].=1;
..=1;
..[0].=&[i-1];
..++;
..++;
..+=..[0].->;
}else{
BOOL =FALSE;
int k=0;
for(;k<15;k++){
if(..[k].使){
//printf("地址1=%x 地址2=%x\n",商城数据.购物车.购物栏[0].商品,&商品数据[i-1]);
if(..[k]. == &[i-1]){
=TRUE;
..[k].++;
..++;
..+=..[k].->;
break;
}
}
}
if(!){
if(..[0].使){
1;
2;
1. = ..[0].;
1. = ..[0].;
k=1;
for(;k<15;k++){
if(..[k].使){
2. = ..[k].;
2. = ..[k].;
..[k].=1.;
..[k].=1.;
1.=2.;
1.=2.;
}else{
..[k].使 = TRUE;
..[k].=1.;
..[k].=1.;
break;
}
}
}
..[0]. = &[i-1];
..[0]. = 1;
..[0].使 = TRUE;
..++;
..++;
..+=..[0].->;
}
}
// printf("商城数据.购物车.商品类型个数%3 = %d\n",商城数据.购物车.商品类型个数%3);
.. = ..%3 ? ../3+1 : ../3;
if(..*3-2>..) ..--;
if(!..) ..=1;
}
}else StockDispBuffer(.X+[-1][0]+40,.Y+[-1][1],105,40057,1);
}else StockDispBuffer(.X+[-1][0]+40,.Y+[-1][1],105,40057,1);
char [128]={0};
sprintf_s(,"%-5d金币",[i-1].);
StockFontBuffer(.X+[-1][0]+15,.Y+[-1][1]-45,1,0,[i-1].,0);
StockFontBuffer(.X+[-1][0]+38,.Y+[-1][1]-20,1,4,,0);
}
if(!. && !){
if(.){
DeathAction(.);
.=0;
.=-1;
}
}
}
//购物车处理
if(..>0){
short ,;
= (..-1)*3+1;
= ..*3;
if(>..) = ..;
short =0;
BOOL = FALSE;
int i=;
for(;i<=;i++){
++;
StockDispBuffer(.X+412,.Y+67+((-1)*80),105,40053,1);
//购物车左页
if(MakeHitBox(.X+505,.Y+121+((-1)*80),.X+505+31,.Y+121+((-1)*80)+16,-1)==1){
if(!.){
StockDispBuffer(.X+505,.Y+121+((-1)*80),106,40064,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
..-= ..[i-1].->;
..-=1;
if(..[i-1].==1){
(i-1);
..--;
.. = ..%3 ? ../3+1 : ../3;
if(..*3>..) ..--;
if(!..&&..) ..=1;
if(..>..) .. = ..;
if(!..)
{
..=0;
..=0;
}
break;
}else ..[i-1].-=1;
}
}else StockDispBuffer(.X+505,.Y+121+((-1)*80),106,40051,1);
}else StockDispBuffer(.X+505,.Y+121+((-1)*80),106,40051,1);
if(MakeHitBox(.X+571,.Y+121+((-1)*80),.X+571+31,.Y+121+((-1)*80)+16,-1)==1){
if(!.){
StockDispBuffer(.X+571,.Y+121+((-1)*80),106,40065,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
if(. < .. + ..[i-1].->){
StockChatBufferLine("系统:身上的金币不足。",6);
break;
}
if(. < ..+1){
StockChatBufferLine("系统:身上的道具位不足。",6);
break;
}
..++;
..+=..[i-1].->;
..[i-1].++;
}
}else StockDispBuffer(.X+571,.Y+121+((-1)*80),106,40052,1);
}else StockDispBuffer(.X+571,.Y+121+((-1)*80),106,40052,1);
ID = StockDispBuffer(.X+455,.Y+105+((-1)*80),106,..[i-1].->,1);
if(HitDispNo==ID){
if(!.){
if(.){
if(.!=ID){
DeathAction(.);
.=0;
.=-1;
}
}
(.X+455,.Y+105+((-1)*80),109,..[i-1].->,..[i-1].->,..[i-1].->);
=TRUE;
if(.) .=ID;
}else if(.){
DeathAction(.);
.=0;
.=-1;
}
}
char [128]={0};
sprintf_s(,"%-5d金币",..[i-1].->);
StockFontBuffer(.X+500,.Y+80+((-1)*80),1,0,..[i-1].->,0);
StockFontBuffer(.X+535,.Y+100+((-1)*80),1,4,,0);
sprintf_s(,"%d",..[i-1].);
[strlen()]=0;
StockFontBuffer(.X+549,.Y+121+((-1)*80),1,4,,0);
}
if() .=TRUE;
else . = FALSE;
//购物车按钮左页
if(MakeHitBox(.X+420,.Y+312,.X+420+31,.Y+312+16,-1)==1){
if(!.){
StockDispBuffer(.X+420,.Y+312,105,40064,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
if(..!=1) ..-=1;
}
}else StockDispBuffer(.X+420,.Y+312,105,40051,1);
}else StockDispBuffer(.X+420,.Y+312,105,40051,1);
//购物车按钮右页
if(MakeHitBox(.X+575,.Y+312,.X+575+31,.Y+312+16,-1)==1){
if(!.){
StockDispBuffer(.X+575,.Y+312,105,40065,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
if(..!=..) ..+=1;
}
}else StockDispBuffer(.X+575,.Y+312,105,40052,1);
}else StockDispBuffer(.X+575,.Y+312,105,40052,1);
}
char [20]={0};
sprintf_s(,"%-3d/ %-3d",..,..);
StockFontBuffer(.X+490,.Y+314,1,0,,0);
memset(,0,20);
sprintf_s(,"%d",.);
StockFontBuffer(.X+462,.Y+342,1,0,,0);
memset(,0,20);
sprintf_s(,"%d",..);
StockFontBuffer(.X+573,.Y+342,1,0,,0);
if( CheckMenuFlag()
|| ((joy_trg[ 0 ] & JOY_ESC) && GetImeString() == NULL)
|| actBtn == 1
|| menuBtn == 1
|| disconnectServerFlag == TRUE
|| wnCloseFlag == 1
|| cloasewindows == 1)
{
wnCloseFlag = 0;
cloasewindows = 0;
();
}
return .;
}
void ()
{
if(.) DeathAction(.);
.=0;
if(.) DeathAction(.);
.=0;
.=-1;
wnCloseFlag=0;
windowTypeWN = -1;
wnCloseFlag = 1;
}
void (short x,short y,UCHAR )
{
if(.==1){
StockDispBuffer(x,y,,40088,1);
StockFontBuffer(x+110,y+50,2,0,"您确定需要购买这些商品吗?",0);
if(MakeHitBox(x+60,y+100,x+60+105,y+100+18,-1)==1){
StockDispBuffer(x+60,y+100,+1,40084,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)){
char [256]={0};
int i=0;
for(;i<15;i++){
if(..[i].使){
char [15]={0};
sprintf_s(,"%d|%d#",..[i].->+1,..[i].);
strcat_s(,);
}
}
lssproto_WN_send(sockfd,nowGx,nowGy,indexWN,idWN,.ID,);
windowTypeWN = -1;
wnCloseFlag = 1;
}
}else StockDispBuffer(x+60,y+100,+1,40086,1);
if(MakeHitBox(x+220,y+100,x+220+105,y+100+18,-1)==1){
StockDispBuffer(x+220,y+100,+1,40085,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)) .=FALSE;
}else StockDispBuffer(x+220,y+100,+1,40087,1);
}else{
StockDispBuffer(x,y,,40088,1);
StockFontBuffer(x+130,y+50,2,0,"您的购物车没有商品!",0);
if(MakeHitBox(x+140,y+100,x+140+105,y+100+18,-1)==1){
StockDispBuffer(x+140,y+100,+1,40090,1);
if( (mouse.onceState & MOUSE_LEFT_CRICK)) .=FALSE;
}else StockDispBuffer(x+140,y+100,+1,40089,1);
}
}
void (short x,short y,UCHAR ,char* ,unsigned int ,char* )
{
char [500]={0};
sprintf_s(,"%s",);
char *[30]={0};
int = 0;
if(.ID!=5){
= (,,"\n");
if([-1][0]==0) --;
}
int 1=;
int ,x,y,i=0;
if(.ID!=5){
for(;i<6;i++){
if(i==5) {
= [i][0];
break;
}
if([i][1]>=){
= [i][0];
break;
}
}
= *48+144;
if((x-190) >(628+.X-x-65)) x=x-190;
else x=x+35;
y=y-(/2);
BOOL =FALSE;
while(true){
if(.Y > y-20){
y +=10;
=TRUE;
}
if((.Y+386+30) < (y+)){
y -=10;
=TRUE;
}
if() =FALSE;
else break;
}
StockDispBuffer(x+80,y+50,,40171,1);
int =48;
if( >=1){
for(i=1;i<=;i++) StockDispBuffer(x+80,y+50+*(i-1)+83,,40172,1);
}
StockDispBuffer(x+80,y+50+*+83,,40173,1);
int x,y;
x=x+6-10;
y=y-25+50;
for(i=1;i<=1+1;i++) StockFontBufferSplit(x+15,y+((i-1)*20),FONT_PRIO_AFRONT,0,[i-1],0,20);
}else{
= 1*48+144;
if((x-190) >(628+.X-x-65)) x=x-190;
else x=x+35;
y=y-(/2);
BOOL =FALSE;
while(true){
if(.Y > y-20){
y +=10;
=TRUE;
}
if((.Y+386+30) < (y+)){
y -=10;
=TRUE;
}
if() =FALSE;
else break;
}
StockDispBuffer(x+80,y+50,,40171,1);
int =48;
StockDispBuffer(x+80,y+50+83,,40173,1);
if(!.) . = MakeAnimDisp(x+76,y+80,,0);
StockFontBufferSplit(x+15,y+100,2,0,,0,20);
}
}
void (short )
{
..[].=0;
..[].=0;
..[].使=FALSE;
int i = +1;
if(i>14) return;
for(i;i<15;i++){
if(!..[i].使) break;
..[]. = ..[i].;
..[]. = ..[i].;
..[].使=TRUE;
..[i].=0;
..[i].=0;
..[i].使=FALSE;
= i;
}
}
void (char * ,_ *)
{
FILE *fp;
fopen_s(&fp,,"rb");
if( fp == NULL )
{
->MD5码[0]=NULL;
->=NULL;
return;
}
int size = getfilesize(fp);
char * = (char*)malloc(size);
fread(,1,size,fp);
fclose(fp);
-> = (char*)malloc(size-34+1);
memset(->,0,size-34+1);
memset(->MD5码,0,64);
memcpy_s(->MD5码,34,,34);
memcpy_s(->,size-34,+34,size-34);
TEA解密((long*)->,((size-34)/4),(long*)_KEY_);
free();
}
void (char * ,_ *)
{
FILE *fp;
fopen_s(&fp,,"wb");
int length=strlen(->);
int length1 = length%4?length+(4-length%4):length;
char * = (char*)malloc(34+length1);
memset(,0,34+length1);
memcpy_s(,34,->MD5码,34);
memcpy_s((+34),length,->,length);
#ifdef _VMP_
TEA加密((long *)(+34),(long)(length1/4),(long*)VMProtectDecryptStringA(_KEY_));
#else
TEA加密((long *)(+34),(long)(length1/4),(long*)_KEY_);
#endif
fwrite(, length1+34, 1, fp);
free();
fclose(fp);
}
void ()
{
("./data/shop1.bin",&[0]);
("./data/shop2.bin",&[1]);
("./data/shop3.bin",&[2]);
("./data/shop4.bin",&[3]);
("./data/shop5.bin",&[4]);
}
#endif