📄 itemmgr.cpp
字号:
// ItemMgr.cpp: implementation of the CItemMgr class.
//
//////////////////////////////////////////////////////////////////////
#include "..\stdafx.h"
#include "CItem.h"
#include "ItemMgr.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CItemMgr ItemMgr;
CItemMgr::CItemMgr()
{
DeleteItem(NULLITEM);
}
CItemMgr::~CItemMgr()
{
}
CItem* CItemMgr::ConvertItemNoToCItem(const int iItemNo)
{
const int iType = iItemNo/1000;
const int iNo = iItemNo%1000;
if( (iType<0) || (iType>10) ) {return NULL;}
if( iNo<=0) {return NULL;}
if( iNo > Item_Ref.nItem[iType]) {return NULL;}
switch( iType )
{
case PLANT : return &CPlant [iNo]; break;
case MINERAL : return &CMineral [iNo]; break;
case HERB : return &CHerb [iNo]; break;
case COOK : return &CCook [iNo]; break;
case POTION : return &CPotion [iNo]; break;
case TOOL : return &CTool [iNo]; break;
case WEAPON : return &CWeapon [iNo]; break;
case DISPOSABLE : return &CDisposable [iNo]; break;
case ARMOR : return &CArmor [iNo]; break;
case ACCESSORY : return &CAccessory [iNo]; break;
case ETC : return &CEtc [iNo]; break;
default : return NULL;
}
return NULL;
}
bool CItemMgr::SwapItem(ITEMATTR &src,ITEMATTR &target)
{
ITEMATTR temp;
// 捞芭绰 唱吝俊 持谰矫促..
if(!CheckFaultItem(src,true)) {return false;}
if(!CheckFaultItem(target,true)){return false;}
temp = src;
src = target;
target = temp;
return true;
}
int CItemMgr::GetItemWeight(const ITEMATTR item )
{
int iDur = 0;
int iType = item.item_no/1000;
CItem *t = ConvertItemNoToCItem( item.item_no );
if( !t ) return 0;
int iWeight = t->GetWeight();
if( iType == DISPOSABLE){iDur = t->GetItemQuantity();}
if( t->GetRbutton() == DIVIDE_ITEM )
{
iDur= t->GetItemDuration();
if(iDur){iWeight *= item.attr[IATTR_MUCH] / iDur;}
else{iWeight *= item.attr[IATTR_MUCH];}
}
return iWeight;
}
int CItemMgr::GetItemValue(const ITEMATTR item)
{
CItem *t = ConvertItemNoToCItem(item.item_no);
if(!t){return 0;}
int iMuch = 0;
int iPrice = 0;
const int iType = item.item_no/1000;
const int iBase = t->GetValue();
if( t->GetRbutton()==DIVIDE_ITEM ) // 荐樊阑 狼固...
{
if( iType == DISPOSABLE )
{
iMuch = t->GetItemQuantity(); // dispoable老 版快
}
else
{
iMuch = t->GetItemDuration(); // 10俺 窜困
}
if( !iMuch ){ iMuch = 1;}
iPrice = (unsigned int)((iBase * .9+.5)*(item.attr[IATTR_MUCH]/(float)iMuch));
return iPrice;
}
unsigned short wNow, wMax;
GetItemDur(item,wNow,wMax);
unsigned int wDBMax = t->GetDuration();
if( wMax < wDBMax ) wMax = wDBMax;
if( wMax )
{
/*
if( (item->attr[IATTR_LIMIT]-g_curr_time) > 0 ) // 蜡烹扁茄捞 巢酒 乐绢具 茄促. 捞 俺充 荤扼咙 唱吝阑 困秦辑 林籍 贸府
{
price = (int)( (float)(base*.9)*d_curr/(float)d_max+.5 );
return price;
}
*/
iPrice = (unsigned int)( (float)(iBase*.9)*wNow/(float)wMax+.5 ); // 烙矫
return iPrice;
}
return 0;
}
int CItemMgr::GetItemDur(const ITEMATTR item, unsigned short &NowDur,unsigned short &MaxDur)
{
NowDur = 0;
MaxDur = 0;
CItem *t = ConvertItemNoToCItem(item.item_no);
if(!t){return 0;}
if( t->GetRbutton()==DIVIDE_ITEM ){return 0;}//唱穿绢瘤绰 酒捞袍 捞骨肺 掂饭捞记捞 酒聪促
NowDur = LOWORD( item.attr[IATTR_DURATION] );
MaxDur = HIWORD( item.attr[IATTR_DURATION] );
return 1;
}
int CItemMgr::GetItemMuch(const ITEMATTR item, int &NowMuch)//唱穿绢 瘤绰 酒捞袍老 版快
{
NowMuch = 0;
CItem *t = ConvertItemNoToCItem(item.item_no);
if(!t){return 0;}
if( t->GetRbutton()!=DIVIDE_ITEM ){return 0;}//唱穿绢瘤绰 酒捞袍捞 酒聪聪鳖 蔼阑 罐瘤 给窃
NowMuch = item.attr[IATTR_MUCH];
return 1;
}
int CItemMgr::ChangeItemAttribute(ITEMATTR &TargetItem, const int iType, const int iAttr)
{
if(!(&TargetItem)){return 0;}//措惑狼 林家啊 壳篮瘤 八荤
switch(iType)
{
case IATTR_ITEMNO: { TargetItem.item_no = iAttr; } break;
case IATTR_MUCH: { TargetItem.attr[IATTR_MUCH] = iAttr; } break;
case IATTR_LIMIT: { TargetItem.attr[IATTR_LIMIT] = iAttr; } break;
case IATTR_ATTR: { TargetItem.attr[IATTR_ATTR] = iAttr; } break;
case IATTR_ID: { TargetItem.attr[IATTR_RARE_MAIN]= iAttr; } break;//0020101 lsw
case IATTR_RESERVED0: { TargetItem.attr[IATTR_RESERVED0]= iAttr; } break;
case IATTR_RESERVED1: { TargetItem.attr[IATTR_RESERVED1]= iAttr; } break;
default : { return 0; } break;
}
return CheckFaultItem(TargetItem,true);//官操绊 唱辑 捞惑茄 仇篮 瘤况 滚赴促 瘤况瘤搁 0 府畔 救瘤况瘤搁 1 府畔
}
int CItemMgr::ChangeItemAttribute(ITEMATTR &TargetItem, const ITEMATTR SourceItem)
{
if(!(&TargetItem)){return 0;}//措惑狼 林家啊 壳篮瘤 八荤
TargetItem = SourceItem;
return 1;
}
int CItemMgr::GetItemTactic(const int iItemNo)//绝栏搁 林冈捞 扁夯 琶平
{
CItem *t = ConvertItemNoToCItem(iItemNo);
if(!t) {return TACTICS_Crapple;}
else {return t->GetSkill_Ability();}
return TACTICS_Crapple;
}
int CItemMgr::GetItemKind(const int iItemNo)
{
CItem *t = ConvertItemNoToCItem(iItemNo);
if(!t) {return IK_NONE;}
else {return t->GetItemKind();}
return IK_NONE;
}
// 031009 CI YGI
int CItemMgr::GenerateItemLimitNumber( int item_no )
{ //< CSD-031229
/*
k_item_limit_number limit_number;
limit_number.who_make = MapNumber+1;
limit_number.number = GetLimitNumber( item_no );
if( limit_number.number == LIMIT_OF_NO_HAVE_LIMIT_ITEM ) // 府固飘 锅龋啊 绝绰芭
{
limit_number.who_make = 255;
limit_number.number = g_curr_time_with_out_year;
}
int limit;
memcpy( &limit, &limit_number, sizeof( int ) );
return limit;
*/
return g_curr_time;
} //> CSD-031229
int CItemMgr::GenerateItemDuration(const int iItemNo)
{
int iDuration = 0;
CItem *t = ConvertItemNoToCItem(iItemNo);
if( t == NULL ) return 0;
if( t->GetRbutton() == DIVIDE_ITEM ) //唱床 瘤绰 芭绰 MAKELONG 救窃
{
switch (iItemNo/1000)
{
case DISPOSABLE :
{
iDuration = t->GetItemQuantity();
}
break;
default :
{
iDuration = t->GetDuration();if(iDuration < 0){iDuration = 1;}
}
break;
}
}
else
{
iDuration = MAKELONG( t->GetDuration(), t->GetDuration() );//促弗 老馆利 酒捞袍篮
}
return iDuration;
}
#include "eventmgr.h" // 040105 YGI 焊拱
ITEMATTR CItemMgr::GenerateItem(const int iItemNo)
{
// 031110 YGI
ITEMATTR item = {0, };
DeleteItem(item);
// 031110 YGI
if( !iItemNo ) return item;
CItem *t = ConvertItemNoToCItem(iItemNo);
if(!t)
{
MyLog( 0, "GenerateItem() : Can't generatie Item [%d]", iItemNo );
return item;
}
if(!t->GetItemImage() || !t->GetObjectNumber())
{
MyLog( 0, "GenerateItem() : Can't generatie Item [%d] because wrong ObjectNumber", iItemNo );
return item;
}//坷宏璃飘 捞固瘤 逞滚 绝栏搁 瘤况咙
item.item_no = iItemNo;
int iDuration = GenerateItemDuration(iItemNo);
if( iDuration ) // dur捞 0老版快 积己矫虐瘤 臼绰促.
{
item.attr[IATTR_DURATION] = iDuration;
item.attr[IATTR_LIMIT] = GenerateItemLimitNumber( item.item_no ); // 031009 CI YGI
}
else
{
DeleteItem(item);//努贰胶 郴何波烙
return item;
}
if( item.item_no == IN_COINS && item.attr[IATTR_MUCH] <= 5 ) item.item_no = IN_COIN;
else if( item.item_no == IN_COIN && item.attr[IATTR_MUCH] > 5 ) item.item_no = IN_COINS;
if( item.item_no == IN_NEW_COINS && item.attr[IATTR_MUCH] <= 5 ) item.item_no = IN_NEW_COIN; // 010210 YGI
else if( item.item_no == IN_NEW_COIN && item.attr[IATTR_MUCH] > 5 ) item.item_no = IN_NEW_COINS;
// 040105 YGI 焊拱
if( IsTreasureMapItem( item.item_no ) )
{
CTreasureMapItem treasure_attr = {0, };
treasure_attr.isChecked = 0;
memcpy( &item.attr[IATTR_TREASURE_MAP], &treasure_attr, sizeof( DWORD ) );
}
CheckFaultItem(item,true);
return item;
}
ITEMATTR CItemMgr::GenerateItem(const int iItemNo, const int iType , const int iCustomValue)
{
int iCustomValueResult = 0;
ITEMATTR item = GenerateItem(iItemNo);
CItem *t = ConvertItemNoToCItem(iItemNo);
if(!t){return item;}
if( iType == IATTR_MUCH)
{//荐樊 何盒篮 目胶乓 窍霸 悸泼 茄促//iCustomValueResult 甫 函拳 矫挪吧肺
if(t->GetRbutton() == DIVIDE_ITEM ) {iCustomValueResult = iCustomValue;}
else {iCustomValueResult = MAKELONG( iCustomValue, iCustomValue);}
}
ChangeItemAttribute(item, iType, iCustomValueResult);
CheckFaultItem(item,true);
return item;
}
int CItemMgr::CheckFaultItem(ITEMATTR &item,bool bDeleteFlag)//020205 lsw
{
int rareresult = 0;
CItem *t = ConvertItemNoToCItem(item.item_no);
WORD ddur=0;
WORD dmax=0;
if(!t) {goto _DELETE_ITEM;}
if(!t->GetItemImage()) {goto _DELETE_ITEM;}//酒捞袍 捞固瘤 逞滚 绝栏搁 瘤况咙
if(!t->GetObjectNumber()) {goto _DELETE_ITEM;}//坷宏璃飘 捞固瘤 逞滚 绝栏搁 瘤况咙
if(!item.item_no) {goto _DELETE_ITEM;}//酒捞袍 锅龋 绝栏搁 瘤况咙
if(!item.attr[IATTR_DURATION]) {goto _DELETE_ITEM;}//酒捞袍 郴备档 绝栏搁 瘤况咙
if(DIVIDE_ITEM == t->GetRbutton())
{ //-蔼阑 啊柳巴篮 瘤快磊
if( 0 > ((int)item.attr[IATTR_MUCH]) ){ goto _DELETE_ITEM; }
if( MAX_DIVIDE_ITEM < (item.attr[IATTR_MUCH]) )//弥措 蔼 焊促 腹栏搁 100 父俺肺 力茄
{
item.attr[IATTR_MUCH] = MAX_DIVIDE_ITEM;
}//100父俺 焊促 腹栏搁
}
else
{
if(!GetItemDur( item, ddur, dmax )) { goto _DELETE_ITEM; }//郴备档甫 罐阑 荐 绝促?
if( ddur > dmax) { goto _DELETE_ITEM; }//钙胶 焊促 泅犁啊 腹酒?
}
if(item.attr[IATTR_RARE_MAIN]) //饭绢牢单
{
RareMain *pRare = (RareMain*)&item.attr[IATTR_RARE_MAIN];
switch(pRare->iHighLevel)
{
case H_LV_NO_HIGH_ITEM:
{//扁瓷酒捞袍档 咯扁俊 甸绢坷聪鳖 炼缴. MAX_STATIC_RARE 甫 逞绰 Item_Fuction 捞 乐促搁 瘤况龙 巴涝聪促.
if(pRare->soksung1)
{
if( MAX_STATIC_RARE < pRare->soksung1)//胶怕平 饭绢 弥措摹 焊促 农促搁
{
rareresult = 7;
}
}
else
{
rareresult = 8;
}
if( !pRare->grade//殿鞭捞 绝芭唱
|| !pRare->soksung1)//加己 皋牢捞 绝匙..
{ rareresult = 5; }//弊烦 瘤况具瘤
}break;
case H_LV_HIGH_ITEM:
{
if(pRare->soksung1)
{
if( START_HIGH_RARE > pRare->soksung1)//窍捞饭绢 矫累痢 焊促 加己捞 撤促搁
{
rareresult = 7;
}
if(pRare->soksung2 || pRare->soksung3)//窍捞酒捞袍牢单 钢萍 加己捞扼搁
{
rareresult = 11;
}
}
else//窍捞牢单 加己捞 绝促搁
{
rareresult = 8;
}
if( !pRare->grade//殿鞭捞 绝芭唱
|| !pRare->soksung1)//加己 皋牢捞 绝匙..
{ rareresult = 5; }//弊烦 瘤况具瘤
}break;
case H_LV_LEGEND_ITEM:
{
if( !pRare->soksung2//饭傈靛 弊缝 逞滚
&& !pRare->soksung3)//饭傈靛 弊缝 牢郸胶 绝促
{ rareresult = 10; }//弊烦 瘤况具瘤
}break;
default:
{
rareresult = 9;
}break;
}//switch(pRare->iHighLevel)
if(rareresult)
{
item.attr[IATTR_RARE_MAIN] = 0;//饭绢 努府绢
}
switch(item.item_no)
{
case IN_COIN:
case IN_COINS:
case IN_NEW_COIN:
case IN_NEW_COINS:
{
item.attr[IATTR_RARE_MAIN] = 0;//饭绢 努府绢
}break;
default:
{
}break;
}
}
return 1;
_DELETE_ITEM:
{
if( bDeleteFlag)
{
DeleteItem(item);
}
return 0;
}
}
int CItemMgr::CheckAddAbleItem(const ITEMATTR SourceItem,const ITEMATTR TargetItem)
{
CItem *tsrc = ConvertItemNoToCItem(SourceItem);
if(!tsrc){return 0;}
if( GetItemKind(SourceItem) == IK_MONEY && GetItemKind(TargetItem) == IK_MONEY){return 1;}
if( GetItemKind(SourceItem) == IK_NEW_MONEY && GetItemKind(TargetItem) == IK_NEW_MONEY){return 1;}
if(SourceItem.item_no != TargetItem.item_no) {return 0;}
if(tsrc->GetRbutton() != DIVIDE_ITEM) {return 0;}
if(SourceItem.attr[IATTR_RARE_MAIN]!=TargetItem.attr[IATTR_RARE_MAIN]) {return 0;}
return 1;
}
int CItemMgr::CombineItem(ITEMATTR &SourceItem,ITEMATTR &TargetItem)//酒捞袍 荐樊 钦摹扁
{
if(!CheckAddAbleItem(SourceItem,TargetItem)){return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -