📄 citem.cpp
字号:
//#include <winerror.h>
#include "StdAfx.h"
#include "main.h"
#include "CItem.h"
#include "Mylog.h"
const int MAX_DIVIDE_ITEM = 1000000;
extern CItem *ItemUnit( int type, int item_no );
extern DWORD CreateItemDuration( int type, int itemno );
extern int GetBoxItemId_SQL( );
extern HENV hEnv ;
extern HDBC hDBC ;
struct CItem_List Item_Ref ;
CItem_Plant CPlant [MAX_ITEM_NUM];
CItem_Mineral CMineral [MAX_ITEM_NUM];
CItem_Herb CHerb [MAX_ITEM_NUM];
CItem_Cook CCook [MAX_ITEM_NUM];
CItem_Potion CPotion [MAX_ITEM_NUM];
CItem_Tool CTool [MAX_ITEM_NUM];
CItem_Weapon CWeapon [MAX_ITEM_NUM];
CItem_Disposable CDisposable [MAX_ITEM_NUM];
CItem_Armor CArmor [MAX_ITEM_NUM];
CItem_Accessory CAccessory [MAX_ITEM_NUM];
CItem_Etc CEtc [MAX_ITEM_NUM];
ItemAttr TItem; // 烙矫肺 荤侩窍绰..
// 酒捞袍 曼炼 抛捞喉阑 DB俊辑 佬绢客 积己窍绰 窃荐.
int initItem(void)
{
int i, c ;
int check[20] = {0,};
if(hEnv == NULL || hDBC == NULL) return -1 ;
// set the number of items
/*
Item_Ref.nItem[0]= Num_Of_CItem_Plant ;
Item_Ref.nItem[1]= Num_Of_CItem_Mineral ;
Item_Ref.nItem[2]= Num_Of_CItem_Herb ;
Item_Ref.nItem[3]= Num_Of_CItem_Cook ;
Item_Ref.nItem[4]= Num_Of_CItem_Potion ;
Item_Ref.nItem[5]= Num_Of_CItem_Tool ;
Item_Ref.nItem[6]= Num_Of_CItem_Weapon ;
Item_Ref.nItem[7]= Num_Of_CItem_Disposable ;
Item_Ref.nItem[8]= Num_Of_CItem_Armor ;
Item_Ref.nItem[9]= Num_Of_CItem_Accessory ;
Item_Ref.nItem[10]= Num_Of_CItem_Etc ;*/
c= CPlant[0].getAllData() - 1 ;
if( c <= 0 ){ JustMsg( " Fail to Read Plant Item "); return -1; }
Item_Ref.nItem[0]= c;
MyLog( LOG_NORMAL, " .Plant Item %4d data Loaded", c) ;
c= CMineral[0].getAllData() - 1 ;
if( c <= 0 ){ JustMsg(" Fail to Read Mineral Item "); return -1; }
Item_Ref.nItem[1]= c;
MyLog( LOG_NORMAL, " .Mineral Item %4d data Loaded", c) ;
c= CHerb[0].getAllData() - 1 ;
if( c <= 0 ){ JustMsg(" Fail to Read Herb Item "); return -1; }
Item_Ref.nItem[2]= c;
MyLog( LOG_NORMAL, " .Herb Item %4d data Loaded", c) ;
c= CCook[0].getAllData() - 1 ;
if( c <= 0 ){ JustMsg(" Fail to Read Cook Item "); return -1; }
Item_Ref.nItem[3]= c;
MyLog( LOG_NORMAL, " .Cook Item %4d data Loaded", c) ;
c= CPotion[0].getAllData() - 1 ;
if( c <= 0 ){ JustMsg(" Fail to Read Potion Item "); return -1; }
Item_Ref.nItem[4]= c;
MyLog( LOG_NORMAL, " .Potion Item %4d data Loaded", c) ;
c= CTool[0].getAllData() - 1 ;
if( c <= 0 ){ JustMsg(" Fail to Read Tool Item "); return -1; }
Item_Ref.nItem[5]= c;
MyLog( LOG_NORMAL, " .Tool Item %4d data Loaded", c) ;
c= CWeapon[0].getAllData() - 1 ;
if( c <= 0 ){ JustMsg(" Fail to Read Weapon Item "); return -1; }
Item_Ref.nItem[6]= c;
MyLog( LOG_NORMAL, " .Weapon Item %4d data Loaded", c) ;
c= CDisposable[0].getAllData() - 1 ;
if( c <= 0 ){ JustMsg(" Fail to Read Disposable Item "); return -1; }
Item_Ref.nItem[7]= c;
MyLog( LOG_NORMAL, " .Disposable Item %4d data Loaded", c) ;
c= CArmor[0].getAllData() - 1 ;
if( c <= 0 ){ JustMsg(" Fail to Read Armor Item "); return -1; }
Item_Ref.nItem[8]= c;
MyLog( LOG_NORMAL, " .Armor Item %4d data Loaded", c) ;
c= CAccessory[0].getAllData() - 1 ;
if( c <= 0 ){ JustMsg(" Fail to Read Accessory Item "); return -1; }
Item_Ref.nItem[9]= c;
MyLog( LOG_NORMAL, " .Accessory Item %4d data Loaded", c) ;
c= CEtc[0].getAllData() - 1 ;
if( c <= 0 ){ JustMsg(" Fail to Read Etc Item "); return -1; }
Item_Ref.nItem[10]= c;
MyLog( LOG_NORMAL, " .Etc Item %4d data Loaded", c) ;
// 0锅 牢郸胶绰 荤侩窍瘤 臼澜.
// item锅龋啊 1锅何磐 矫累(0锅篮 NULL酒捞袍, 溜 酒捞袍 绝澜狼 惑怕甫 唱鸥辰促)
for(i= 1 ; i <= Item_Ref.nItem[0] ; i++) Item_Ref.Item_Info[0][i]= &CPlant[i] ;
for(i= 1 ; i <= Item_Ref.nItem[1] ; i++) Item_Ref.Item_Info[1][i]= &CMineral[i] ;
for(i= 1 ; i <= Item_Ref.nItem[2] ; i++) Item_Ref.Item_Info[2][i]= &CHerb[i] ;
for(i= 1 ; i <= Item_Ref.nItem[3] ; i++) Item_Ref.Item_Info[3][i]= &CCook[i] ;
for(i= 1 ; i <= Item_Ref.nItem[4] ; i++) Item_Ref.Item_Info[4][i]= &CPotion[i] ;
for(i= 1 ; i <= Item_Ref.nItem[5] ; i++) Item_Ref.Item_Info[5][i]= &CTool[i] ;
for(i= 1 ; i <= Item_Ref.nItem[6] ; i++) Item_Ref.Item_Info[6][i]= &CWeapon[i] ;
for(i= 1 ; i <= Item_Ref.nItem[7] ; i++) Item_Ref.Item_Info[7][i]= &CDisposable[i] ;
for(i= 1 ; i <= Item_Ref.nItem[8] ; i++) Item_Ref.Item_Info[8][i]= &CArmor[i] ;
for(i= 1 ; i <= Item_Ref.nItem[9] ; i++) Item_Ref.Item_Info[9][i]= &CAccessory[i] ;
for(i= 1 ; i <= Item_Ref.nItem[10] ; i++) Item_Ref.Item_Info[10][i]= &CEtc[i] ;
InitSkillTable( ) ;
return 1 ;
}
/////////////////////////////////////////////////////////////////////////////
//
// 窃荐汲疙: DB俊辑 秦寸 酒捞袍狼 荐摹甫 佬绢坷绰 窃荐.
// virtual 窃荐捞促.
// 秦寸 酒捞袍 硅凯狼 1锅何磐 佬绢坷扁 矫累茄促.
// Num_Of_CItem_XXXXX肺 define等 俺荐父怒 佬绢柯促.
// DB俊 乐绰 酒捞袍狼 俺荐啊 Num_Of_CItem_XXXXX焊促 累促搁
// DB俊 乐绰 酒捞袍 犁荐父 佬绢柯促.
//
// 府畔蔼: DB俊辑 角力肺 佬绢柯 酒捞袍 俺荐
//
/////////////////////////////////////////////////////////////////////////////
int CItem_Plant::getAllData(void)
{
if(Num_Of_CItem_Plant <= 0) {
//fprintf(stdout, "\n No item's available ") ;
return -4 ; // No item's available
}
HSTMT hStmt= NULL ;
RETCODE ret ;
SWORD nCols ;
char query_stmt[80]= {0, } ;
char col_name[60]= {0, } ;
//UWORD i ;
SDWORD cbValue ;
int *tmp= NULL ;
int c= 1 ;
int i= 4 ;
SQLAllocStmt(hDBC, &hStmt);
/////////////////////////////////////////////////////////////////////////////
//strcpy(query_stmt, "select * from Item_Plant order by item_id") ;
strcpy(query_stmt, "EXEC up_get_item_plant");
/////////////////////////////////////////////////////////////////////////////
ret= SQLExecDirect(hStmt, (UCHAR *)query_stmt, SQL_NTS) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nItem PLAnt: ExecDirect Error ") ;
return -1 ;
}
SQLNumResultCols(hStmt, &nCols) ;
ret= SQLFetch(hStmt) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf, 0, NULL );// Process any inserts in lpMsgBuf.
// ...// Display the string.
printf("\nLast Error: %s", (LPCTSTR)lpMsgBuf) ;
// Free the buffer.
LocalFree( lpMsgBuf );
printf("\nItem7: Fetch Error ") ;
return -1 ;
}
while(ret == SQL_SUCCESS)
{
ret= SQLGetData(hStmt, 1, SQL_C_SLONG, &c, sizeof(int), &cbValue) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nError!!! (%d)", ret) ;
return -1 ;
}
CPlant[c].Item_id = c;
ret= SQLGetData(hStmt, 2, SQL_C_CHAR, &CPlant[c].Name, sizeof(Name), &cbValue) ;
ret= SQLGetData(hStmt, 3, SQL_C_CHAR, &CPlant[c].Han_Name, sizeof(Han_Name), &cbValue) ;
EatRearWhiteChar( CPlant[c].Han_Name );
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nString GET Error!!! (%d)", ret) ;
return -1 ;
}
tmp = &CPlant[c].lv;
for(i=4; i <= nCols; i++) {
ret= SQLGetData(hStmt, i, SQL_C_SLONG, tmp, sizeof(int), &cbValue) ;
tmp++ ;
}
c++ ;
ret= SQLFetch(hStmt) ;
m_Much = 0;
}
SQLFreeStmt(hStmt, SQL_DROP) ;
return c ;
}
int CItem_Mineral::getAllData(void)
{
if(Num_Of_CItem_Mineral <= 0) {
return -4 ; // No item's available
}
HSTMT hStmt= NULL ;
RETCODE ret ;
SWORD nCols ;
char query_stmt[80]= {0, } ;
SDWORD cbValue ;
int *tmp ;
int c= 1, i ;
SQLAllocStmt(hDBC, &hStmt);
/////////////////////////////////////////////////////////////////////////////
//strcpy(query_stmt, "select * from Item_Mineral order by item_id") ;
strcpy(query_stmt, "EXEC up_get_item_mineral");
/////////////////////////////////////////////////////////////////////////////
ret= SQLExecDirect(hStmt, (UCHAR *)query_stmt, SQL_NTS) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nItem Mineral: ExecDirect Error ") ;
return -1 ;
}
SQLNumResultCols(hStmt, &nCols) ;
ret= SQLFetch(hStmt) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf, 0, NULL );// Process any inserts in lpMsgBuf.
// ...// Display the string.
printf("\nLast Error: %s", (LPCTSTR)lpMsgBuf) ;
// Free the buffer.
LocalFree( lpMsgBuf );
printf("\nItem7: Fetch Error ") ;
return -1 ;
}
//tmp= &Nead2_Level ;
//tmp= &lv ;
while( ret == SQL_SUCCESS)
{
// Accquire the DATA
ret= SQLGetData(hStmt, 1, SQL_C_SLONG, &c, sizeof(int), &cbValue) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nError!!! (%d)", ret) ;
return -1 ;
}
CMineral[c].Item_id = c;
ret= SQLGetData(hStmt, 2, SQL_C_CHAR, &CMineral[c].Name, sizeof(Name), &cbValue) ;
ret= SQLGetData(hStmt, 3, SQL_C_CHAR, &CMineral[c].Han_Name, sizeof(Han_Name), &cbValue) ;
EatRearWhiteChar( CMineral[c].Han_Name );
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nString GET Error!!! (%d)", ret) ;
return -1 ;
}
tmp = &CMineral[c].lv;
for(i=4; i <= nCols; i++) {
ret= SQLGetData(hStmt, i, SQL_C_SLONG, tmp, sizeof(int), &cbValue) ;
tmp++ ;
}
c++ ;
ret= SQLFetch(hStmt) ;
m_Much = 0;
}
SQLFreeStmt(hStmt, SQL_DROP) ;
return c ;
}
int CItem_Herb::getAllData(void)
{
if(Num_Of_CItem_Herb <= 0) {
return -4 ; // No item's available
}
HSTMT hStmt= NULL ;
RETCODE ret ;
SWORD nCols ;
char query_stmt[80]= {0, } ;
SDWORD cbValue ;
int *tmp ;
int c= 1, i ;
SQLAllocStmt(hDBC, &hStmt);
/////////////////////////////////////////////////////////////////////////////
//strcpy(query_stmt, "select * from Item_Herb order by item_id") ;
strcpy(query_stmt, "EXEC up_get_item_herb");
/////////////////////////////////////////////////////////////////////////////
ret= SQLExecDirect(hStmt, (UCHAR *)query_stmt, SQL_NTS) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nItem Herb: ExecDirect Error ") ;
return -1 ;
}
SQLNumResultCols(hStmt, &nCols) ;
ret= SQLFetch(hStmt) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf, 0, NULL );// Process any inserts in lpMsgBuf.
// ...// Display the string.
printf("\nLast Error: %s", (LPCTSTR)lpMsgBuf) ;
// Free the buffer.
LocalFree( lpMsgBuf );
printf("\nItem7: Fetch Error ") ;
return -1 ;
}
while( ret == SQL_SUCCESS)
{
// Accquire the DATA
ret= SQLGetData(hStmt, 1, SQL_C_SLONG, &c, sizeof(int), &cbValue) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nError!!! (%d)", ret) ;
return -1 ;
}
CHerb[c].Item_id = c;
ret= SQLGetData(hStmt, 2, SQL_C_CHAR, &CHerb[c].Name, sizeof(Name), &cbValue) ;
ret= SQLGetData(hStmt, 3, SQL_C_CHAR, &CHerb[c].Han_Name, sizeof(Han_Name), &cbValue) ;
EatRearWhiteChar( CHerb[c].Han_Name );
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nString GET Error!!! (%d)", ret) ;
return -1 ;
}
tmp = &CHerb[c].lv;
for(i=4; i <= nCols; i++) {
ret= SQLGetData(hStmt, i, SQL_C_SLONG, tmp, sizeof(int), &cbValue) ;
tmp++ ;
}
c++ ;
ret= SQLFetch(hStmt) ;
m_Much = 0;
}
SQLFreeStmt(hStmt, SQL_DROP) ;
return c ;
}
int CItem_Cook::getAllData(void)
{
if(Num_Of_CItem_Cook <= 0) {
return -4 ; // No item's available
}
HSTMT hStmt= NULL ;
RETCODE ret ;
SWORD nCols ;
char query_stmt[80]= {0, } ;
SDWORD cbValue ;
int *tmp ;
int c= 1, i ;
SQLAllocStmt(hDBC, &hStmt);
/////////////////////////////////////////////////////////////////////////////
//strcpy(query_stmt, "select * from Item_Cook order by item_id") ;
strcpy(query_stmt, "EXEC up_get_item_cook");
/////////////////////////////////////////////////////////////////////////////
ret= SQLExecDirect(hStmt, (UCHAR *)query_stmt, SQL_NTS) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nItem Cook: ExecDirect Error ") ;
return -1 ;
}
SQLNumResultCols(hStmt, &nCols) ;
ret= SQLFetch(hStmt) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf, 0, NULL );// Process any inserts in lpMsgBuf.
// ...// Display the string.
printf("\nLast Error: %s", (LPCTSTR)lpMsgBuf) ;
// Free the buffer.
LocalFree( lpMsgBuf );
printf("\nItem7: Fetch Error ") ;
return -1 ;
}
while(ret == SQL_SUCCESS)
{
// Accquire the DATA
ret= SQLGetData(hStmt, 1, SQL_C_SLONG, &c, sizeof(int), &cbValue) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nError!!! (%d)", ret) ;
return -1 ;
}
CCook[c].Item_id = c;
ret= SQLGetData(hStmt, 2, SQL_C_CHAR, &CCook[c].Name, sizeof(Name), &cbValue) ;
ret= SQLGetData(hStmt, 3, SQL_C_CHAR, &CCook[c].Han_Name, sizeof(Han_Name), &cbValue) ;
EatRearWhiteChar( CCook[c].Han_Name );
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nString GET Error!!! (%d)", ret) ;
return -1 ;
}
tmp = &CCook[c].lv;
for(i=4; i <= nCols; i++) {
ret= SQLGetData(hStmt, i, SQL_C_SLONG, tmp, sizeof(int), &cbValue) ;
tmp++ ;
}
c++ ;
ret= SQLFetch(hStmt) ;
m_Much = 0; //1215
}
SQLFreeStmt(hStmt, SQL_DROP) ;
return c ;
}
int CItem_Potion::getAllData(void)
{
if(Num_Of_CItem_Potion <= 0) {
return -4 ; // No item's available
}
HSTMT hStmt= NULL ;
RETCODE ret ;
SWORD nCols ;
char query_stmt[80]= {0, } ;
SDWORD cbValue ;
int *tmp ;
int c= 1, i ;
SQLAllocStmt(hDBC, &hStmt);
/////////////////////////////////////////////////////////////////////////////
//strcpy(query_stmt, "select * from Item_Potion order by item_id") ;
strcpy(query_stmt, "EXEC up_get_item_potion");
/////////////////////////////////////////////////////////////////////////////
ret= SQLExecDirect(hStmt, (UCHAR *)query_stmt, SQL_NTS) ;
if(ret != SQL_SUCCESS_WITH_INFO && ret != SQL_SUCCESS) {
printf("\nItem Potion: ExecDirect Error ") ;
return -1 ;
}
SQLNumResultCols(hStmt, &nCols) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -