📄 kein_item.cpp
字号:
#include "..\stdafx.h"
#include "DefaultHeader.h"
#include "CItem.h"
#include "OP_Magic.h"
extern int GetBoxItemId_SQL( );
extern struct CItem_List Item_Ref ;
extern void getItemIndex(int, int &, int &) ;
////////////////////////////////////////////////////////////////////////////////
//
// 酒捞袍 锅龋客 鸥涝捞 倾侩等 蔼阑 逞菌绰瘤甫 魄窜窍绰 窃荐
//
// 颇扼皋磐绰 鸥涝苞 锅龋甫 涝仿 罐绊
// 器牢磐肺 府畔茄促. 肋 给 灯阑 版快 NULL府畔
//
////////////////////////////////////////////////////////////////////////////////
CItem *ItemUnit( ItemAttr item )
{
int type, num;
getItemIndex( item.item_no, type, num );
return ItemUnit( type, num );
}
//011030 lsw >
CItem *ItemUnit( int item_no )
{
return ItemUnit( item_no/1000, item_no%1000);
}
//011030 lsw <
CItem *ItemUnit( int type, int item_no )
{
if( (type<0) || (type>10) ) return NULL;
if( (item_no<=0) || (item_no > Item_Ref.nItem[type]) ) return NULL;
switch( type )
{
case PLANT : return &CPlant [item_no]; break;
case MINERAL : return &CMineral [item_no]; break;
case HERB : return &CHerb [item_no]; break;
case COOK : return &CCook [item_no]; break;
case POTION : return &CPotion [item_no]; break;
case TOOL : return &CTool [item_no]; break;
case WEAPON : return &CWeapon [item_no]; break;
case DISPOSABLE : return &CDisposable [item_no]; break;
case ARMOR : return &CArmor [item_no]; break;
case ACCESSORY : return &CAccessory [item_no]; break;
case ETC : return &CEtc [item_no]; break;
}
return NULL;
// return Item_Ref.Item_Info[type][item_no];
}
DWORD CreateItemDuration( int type, int itemno ) // 0620 YGI
{
static int bonus = 0;
CItem *t;
t = ItemUnit( type, itemno );
if( t == NULL ) return 0;
DWORD basic_dur;
if( type == DISPOSABLE )
basic_dur = t->GetItemQuantity();
else if( t->GetRbutton() == DIVIDE_ITEM )
{
basic_dur = t->GetDuration();
if( basic_dur == -1 ) basic_dur = 1;
}
else basic_dur = MAKELONG( t->GetDuration(), t->GetDuration() );
return basic_dur;
}
ItemAttr GenerateItem( const int iItemFullNo, const int iCustomType, const DWORD dwValue )
{
return ItemMgr.GenerateItem(iItemFullNo,iCustomType,dwValue);
}
ItemAttr GenerateItem( const int iItemFullNo )
{
return ItemMgr.GenerateItem(iItemFullNo);
}
// 010109 YGI
int DeleteItem( ItemAttr *item )
{
int type, num;
if( !item ) return 0; // NULL老 版快
getItemIndex( item->item_no, type, num );
CItem *t = ItemUnit( type, num );
if( !t )
{
memset( item, 0, sizeof( ItemAttr ) );
return 0;
}
if( t->GetItemKind() == IK_BOX )
SendDeleteBox( item->attr[IATTR_ID] );
t->ThisMapValue--;
memset( item, 0, sizeof( ItemAttr ) );
return 1;
}
int GetWeight( ItemAttr item )
{
int type, num;
getItemIndex( item.item_no, type, num );
CItem *t = ItemUnit( type, num );
if( !t ) return 1;
int weight = t->GetWeight();
if( type == DISPOSABLE)
{
int dur = t->GetItemQuantity();
}
if( t->GetRbutton() == DIVIDE_ITEM )
{
int dur = t->GetItemDuration();
if( dur > 0 )
weight *= item.attr[IATTR_MUCH] / dur;
else weight *= item.attr[IATTR_MUCH];
}
return weight;
}
int GetTotalItemWeight( CHARLIST *ch )
{
int weight = 0;
int a, b, c;
for(a=0;a<3;a++)
for(b=0;b<3;b++)
for(c=0;c<8;c++)
if(ch->inv[a][b][c].item_no)
weight += GetWeight( ch->inv[a][b][c] );
for(a=0;a<6;a++)
if(ch->quick[a].item_no) weight += GetWeight(ch->quick[a]);
for(a=0;a<8;a++)
if(ch->equip[a].item_no) weight += GetWeight(ch->equip[a]);
if( ch->handheld.item_no ) weight += GetWeight( ch->handheld );
return weight;
}
/////////////////////////////////////////////////
// 厘馒 捞固瘤甫 啊廉柯促
/////////////////////////////////////////////////
int GetItemView( int item_no, int is_man )
{
CItem *t;
int type, num;
getItemIndex( item_no, type, num );
t = ItemUnit( type, num );
if( !t ) return 0;
else return t->GetItemShow( is_man );
}
/////////////////////////////////// //0101 //////////////////////////////////////
//////////////////////////// Item POS Set /////////////////////////////////
void SetItemPos(int type, POS* IP_set)
{
IP_set->type = (char)type;
IP_set->p1 = 0;
IP_set->p2 = 0;
IP_set->p3 = 0;
}
void SetItemPos(int type, int p, POS* IP_set)
{
IP_set->type = (char)type;
IP_set->p1 = 0;
IP_set->p2 = 0;
IP_set->p3 = (short int)p;
}
void SetItemPos(int type, int p1, int p2, int p3, POS* IP_set)
{
IP_set->type = ( char )type;
IP_set->p1 = (short int)p1;
IP_set->p2 = (short int)p2;
IP_set->p3 = (short int)p3;
}
DWORD GetMoneyByItem( CHARLIST *ch )
{
return (LocalMgr.IsChangeMoney())?GetNewMoneyByItem(ch):GetMoneyByOldItem(ch);
}
DWORD GetNewMoneyByItem( CHARLIST *ch ) // 牢亥俊 乐绰 捣父
{
DWORD money=0;
int type, num;
CItem *t;
int weight = 0;
for( int i=0; i<3; i++ )
for( int j=0; j<3; j++ )
for( int k=0; k<8; k++ )
{
ItemAttr &item = ch->inv[i][j][k];
if( item.item_no )
{
weight += GetWeight( item );
getItemIndex( item.item_no, type, num );
t = ItemUnit( type, num );
if( t->GetItemKind() == IK_NEW_MONEY )
{
if( item.item_no == IN_NEW_COIN && item.attr[IATTR_MUCH] > 5) // 悼傈
{
item.item_no = IN_NEW_COINS; // 捣 歹固肺 官厕
}
else if( item.item_no == IN_NEW_COINS && item.attr[IATTR_MUCH] <= 5 ) // 悼傈 歹固
{
item.item_no = IN_NEW_COIN;
}
money += item.attr[IATTR_MUCH];
}
}
}
ch->itemweight = weight;
return money;
}
DWORD GetMoneyByOldItem( CHARLIST *ch )
{
DWORD money=0;
int type, num;
CItem *t;
int weight = 0;
for( int i=0; i<3; i++ )
for( int j=0; j<3; j++ )
for( int k=0; k<8; k++ )
{
ItemAttr &item = ch->inv[i][j][k];
if( item.item_no )
{
weight += GetWeight( item );
getItemIndex( item.item_no, type, num );
t = ItemUnit( type, num );
if( t->GetItemKind() == IK_MONEY )
{
if( item.item_no == IN_COIN && item.attr[IATTR_MUCH] > 5) // 悼傈
{
item.item_no = IN_COINS; // 捣 歹固肺 官厕
}
else if( item.item_no == IN_COINS && item.attr[IATTR_MUCH] <= 5 ) // 悼傈 歹固
{
item.item_no = IN_COIN;
}
money += item.attr[IATTR_MUCH];
}
}
}
ch->itemweight = weight;
return money;
}
/////////////////////////////////////////////////////////////////////////
// 某腐磐啊 啊瘤绊 乐绰 酒捞袍 搞俊 冻备扁
///////////////////////////////////////////////////////////////////////
int DropItem( int x, int y, ItemAttr *item )
{
return AddItemList( item->item_no, item->attr, 0, x, y, 0, 0 );
}
/////////////////////////////////////////////////////////////////////
//
// 捣 酒捞袍俊 包访茄 皋家靛甸 ( 捣 哗绊 歹窍扁 窃荐 )
//
////////////////////////////////////////////////////////////////////
// 010210 YGI
int SubtractOldMoney( DWORD money, CHARLIST *ch )
{
CHARLIST *check_ch = CheckServerId( ch->GetServerID());
if( check_ch != ch ) return -1;
if( !money ) return 1;
int a, b, c;
ItemAttr *item = SearchItemOfInvByKind( IK_MONEY, ch, a, b, c );
if( !item ) return -1; // 捣 酒捞袍捞 窍唱档 绝澜. -->SCharacterData.nMoney = 0; ==> 巩力 乐澜...
POS pos;
SetItemPos( INV, a, b, c, &pos);
if( item->attr[IATTR_MUCH] <= money )
{
money -= item->attr[IATTR_MUCH];
// 020428 YGI acer
SendDeleteItem( item, &pos, ch );
SubtractOldMoney( money, ch );
}
else
{
item->attr[IATTR_MUCH] -= money;
SendChangeDurationByKein( &pos, item->attr[IATTR_MUCH], ch->GetServerID());
return 1;
}
return 1;
}
// 010109 YGI
int SubtractMoney( DWORD money, CHARLIST *ch, int type )
{
CHARLIST *check_ch = CheckServerId( ch->GetServerID());
if( check_ch != ch ) return -1;
if(ch->Money < money ) return -1; // 捣捞 何练窃
if( !money ) return 1;
int a = 0, b = 0, c = 0;
ItemAttr *item = NULL;
if(LocalMgr.IsChangeMoney())//030102 lsw
{
item = SearchItemOfInvByKind( IK_NEW_MONEY, ch, a, b, c );
}
else
{
item = SearchItemOfInvByKind( IK_MONEY, ch, a, b, c );
}
if( !item ) return -1; // 捣 酒捞袍捞 窍唱档 绝澜. -->SCharacterData.nMoney = 0; ==> 巩力 乐澜...
POS pos;
SetItemPos( INV, a, b, c, &pos);
if( item->attr[IATTR_MUCH] <= money )
{
money -= item->attr[IATTR_MUCH];
// 020428 YGI acer
SendDeleteItem( item, &pos, ch );
return SubtractMoney( money, ch );
}
else
{
item->attr[IATTR_MUCH] -= money;
SendChangeDurationByKein( &pos, item->attr[IATTR_MUCH], ch->GetServerID());
return 1;
}
return 1;
}
int SubtractMoney( DWORD money, CHARLIST *ch )
{
int ret = SubtractMoney( money, ch, 1 ); // 犁蓖 龋免阑 葛滴 场郴绊
ch->Money = GetMoneyByItem( ch ); // 捣 拌魂篮 茄锅父 茄促.
return ret;
}
int SearchItemPosByNumber(ItemAttr *item, int &a, int &b, int &c, CHARLIST *ch)
{
for(a=0;a<3;a++)
for(b=0;b<3;b++)
for(c=0;c<8;c++)
if(ch->inv[a][b][c].item_no == item->item_no &&
ch->inv[a][b][c].attr[IATTR_RARE_MAIN] == item->attr[IATTR_RARE_MAIN] )
return 1;
return 0;
}
int SearchCoinItem( int &a, int &b, int &c, CHARLIST *ch ) // 010210 YGI
{
for(a=0;a<3;a++)
for(b=0;b<3;b++)
for(c=0;c<8;c++)
{
int iItemNo1 = IN_NEW_COIN, iItemNo2 = IN_NEW_COINS;
if(LocalMgr.IsChangeMoney())//030102 lsw
{
iItemNo1 = IN_NEW_COIN;
iItemNo2 =IN_NEW_COINS;
}
else
{
iItemNo1 = IN_COIN;
iItemNo2 =IN_COINS;
}
if( ch->inv[a][b][c].item_no == iItemNo1 || ch->inv[a][b][c].item_no == iItemNo2 )
{
if( ch->inv[a][b][c].attr[IATTR_MUCH] == MAX_MONEY ) continue;
return 1;
}
}
return 0;
}
ItemAttr *SearchItemOfInvByKind( int kind, CHARLIST *ch, int &i, int &j, int &k )
{
int type, num;
CItem * t;
for( i=0; i<3; i++ )
for( j=0; j<3; j++ )
for( k=0; k<8; k++ )
{
ItemAttr &item = ch->inv[i][j][k];
if( item.item_no )
{
getItemIndex( item.item_no, type, num );
t = ItemUnit( type, num );
if( t && t->GetItemKind() == kind )
{
return &item;
}
}
}
return NULL;
}
ItemAttr *SearchItemOfInvByKind( int kind, CHARLIST *ch )
{
int a, b, c;
return SearchItemOfInvByKind( kind, ch, a, b, c );
}
ItemAttr *SearchInv( CHARLIST *ch )
{
for( int a=0; a<3; a++ )
for( int b=0; b<3; b++ )
for( int c=0; c<8; c++ )
{
if( !ch->inv[a][b][c].item_no ) return &ch->inv[a][b][c];
}
return NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -