⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 item.cpp

📁 国内著名网络游戏dragon的客户端登陆用完整源码 配套一起上传的服务端部分可开服 无说明文档
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************\
* Copyright (c), Future Entertainment World / Seoul, Republic of Korea        *
* All Rights Reserved.                                                        *
*                                                                             *
* This document contains proprietary and confidential information.  No        *
* parts of this document or the computer program it embodies may be in        *
* any way copied, duplicated, reproduced, translated into a different         *
* programming language, or distributed to any person, company, or             *
* corporation without the prior written consent of Future Entertainment World *
\*****************************************************************************/
#include "StdAfx.h"
#include <Ddraw.h>
#include <Stdio.h>
#include <io.h>
#include "Dragon.h"
#include "Hong_Sprite.h"
#include "Hong_Light.h"
#include "Hong_Sub.h"
#include "map.h"
#include "GameProc.h"
#include "Convert565to555.h"
#include "Tool.h"
#include "Skill.h"
#include "CharDataTable.h"
#include "Char.h"
#include "ItemTable.h"
#include "DirectSound.h"
#include "Effect.h"
#include "Path.h"
#include "Object.h"
#include "hangul.h"
#include "item.h"

extern MAP		g_Map;		
extern int		g_MouseItemType;	// menu.cpp
extern int		g_MouseItemNumber;
extern int		g_StartMenuOn;

LPITEMGROUND g_Item, CursorCheckedItem;
LPITEMSPRITE  g_ItemSprite;

extern void changemapobjectname( char *oldname, char *newname );

int LoadItemSprite( Spr *s, int no, int type, int order, int return_null = 0 )
{	
	char temp[ FILENAME_MAX];
	char tempitemname[ FILENAME_MAX];
	FILE *fp = NULL;

	changemapobjectname( MapName, tempitemname );
	
	if( type < 13 )		// 0811 YGI
	{	
		sprintf( temp, "./item/%07d.CSP", no ); // item
		fp = Fopen( temp, "rb" );
		if( fp == NULL )
		{
				sprintf( temp, "./item/0000000.CSP" ); // item
				fp = Fopen( temp, "rb" );
		}
	}	
	else
#ifdef _MAPOBJECT_DIRECTORY_CHANGE_
	{	
		
		int lev;

		if( order == 0 )
		{	no -= 13000;
		
			lev = no / 1000;
			if( lev == 1 ) lev = 0;

			sprintf( temp, "./object/%d/%04d.csp", lev, no );
			fp = Fopen( temp, "rb" );
			if( fp == NULL ) 
			{
				if( !return_null )
				{
					sprintf( temp, "./item/0000000.CSP" ); // item
					fp = Fopen( temp, "rb" );
				}
			}
		}	
		else 
		{
			no -= 1300000;

			lev = no / 100000;
			if( lev == 1 ) lev = 0;

			sprintf( temp, "./object/%d/%06d.csp", lev, no );
			fp = Fopen( temp, "rb" );
			if( fp == NULL ) 
			{

				if( !return_null )
				{
					sprintf( temp, "./item/0000000.CSP" ); // item
					fp = Fopen( temp, "rb" );
				}
			}
		}
	}
#else
	{
		if( order == 0 )
		{	
			sprintf( temp, "./object/%s/%04d.csp", tempitemname, no - 13000);
			fp = Fopen( temp, "rb" );
			if( fp == NULL ) 
			{
				if( !return_null )
				{
					sprintf( temp, "./item/0000000.CSP" ); // item
					fp = Fopen( temp, "rb" );
				}
			}
		}	
		else 
		{
			sprintf( temp, "./object/%s/%06d.csp", tempitemname, no - 1300000 );
			fp = Fopen( temp, "rb" );
			if( fp == NULL ) 
			{
				if( !return_null )
				{
					sprintf( temp, "./item/0000000.CSP" ); // item
					fp = Fopen( temp, "rb" );
				}
			}
		}
	}
#endif

	
	if( fp )
	{	
		fread( &s->xl, sizeof( short ), 1, fp);
		fread( &s->yl, sizeof( short ), 1, fp);
		fread( &s->ox, sizeof( short ), 1, fp);
		fread( &s->oy, sizeof( short ), 1, fp);
//		s->oy = s->yl * 80/ 100; //sizeof( short ), 1, fp);
		fread( &s->size, sizeof( unsigned int ), 1, fp);
		s->img = NULL;
		MemAlloc( s->img, s->size );
		fread( s->img, s->size, 1, fp );
		convert565to555( s );
		fclose(fp);
		return 1;
	}
	return 0;
}		
		
		
		
void FreeItemSprite( LPITEMSPRITE i)
{
	MemFree( i->sp.img );
}


LPITEMSPRITE FindItemSprite( int no )
{
	LPITEMSPRITE is = g_ItemSprite;

	while( is != NULL )
	{
		if( is->no == no ) return is;
		is = is->next;
	}

	return NULL;
}


void DeleteItemSprite( int no )
{		
	LPITEMSPRITE  t = g_ItemSprite;
			
	while( t != NULL )
	{		
		if( t->no == no )
		{	
			t->count --;
					
			if( t->count == 0 )
			{		
				if( t == g_ItemSprite )
				{	
					t = g_ItemSprite->next;
					FreeItemSprite( g_ItemSprite );
					MemFree( g_ItemSprite );
					g_ItemSprite = t;
					if( t != NULL )	g_ItemSprite->prev = NULL;
					return;
				}
				else 
				{
					if ( t->prev != NULL )
					{
						t->prev->next = t->next;
					}
					if( t->next != NULL )
					{
						t->next->prev = t->prev;
					}
					FreeItemSprite( t );
					MemFree( t );
					return;
				}
			}
		}	
		t = t->next;
	}		
}		

// 020620 YGI
LPITEMSPRITE AddItemSprite( int no, int type, int order, int return_flag = 0  )
{			
	LPITEMSPRITE temp, s = FindItemSprite( no );
			
	if( s == NULL )
	{		
		if( g_ItemSprite == NULL )
		{	
			MemAlloc( g_ItemSprite, sizeof( ITEMSPRITE ) );
			g_ItemSprite->no = no;
			g_ItemSprite->count = 1;
			
			LoadItemSprite( &g_ItemSprite->sp, no, type, order );
			g_ItemSprite->next = NULL;
			g_ItemSprite->prev = NULL;
			
			s = g_ItemSprite;
		}	
		else
		{
			MemAlloc(s,  sizeof( ITEMSPRITE ) );
			s->no = no;
			s->count = 1;
			if( LoadItemSprite( &s->sp, no, type, order, return_flag ) )
			{
				s->next = NULL;
					
				temp = g_ItemSprite;
				temp->prev = s;
				s->next = temp;
				s->prev = NULL;
				g_ItemSprite = s;
			}
			else
			{
				MemFree( s );
				s = 0;
			}
		}	
	}		
	else	
	{		
		s->count ++;
	}		
			
	return s;
}													
	
extern void changemapobjectname( char *oldname, char *newname );

#include "menuset.h"//021030 YGI							
// 020620 YGI											
void LoadItem( LPITEMGROUND i )
{										
	char temp[ FILENAME_MAX];
	char tempitemname[ FILENAME_MAX];
	FILE *fp;									
	int  j, m;
	DWORD k;									
	LPITEMSPRITE t;							
	int itemno;		
	fpos_t  pos;
	int obcount;
														
	int type = i->no / 1000;
	int no = i->no % 1000;
	int getable, anitype,itemtype, dir,where,sorting,shadow,dx1, dy1,	dx2, dy2, dx3, dy3,	dx4, dy4,framecount;
	int light, lightx, lighty;

	int dsx, dsy, ddx, ddy;
	changemapobjectname( MapName, tempitemname );
	
	if( i->no > 25000 )
	{
		i->getable	  = 1;
		i->Anitype 	  = 0;
		i->type		  = 0; 
		i->dirno	  = 0;
		i->Where	  = 0;	
		i->Sorttype   = 0;
		i->shadow	  = 0;	
		i->dx[0]	  = 0;
		i->dx[1]	  = 0;
		i->dx[2]	  = 0;
		i->dx[3]	  = 0;
		i->framecount = 1;
		i->dsx[0] = 0; i->dsy[1] = 0; i->ddx[0] = 0; i->ddy[1] = 0;

		int spr_no = i->no-25000+13000;
		type = spr_no/1000;

		// 劝己拳 老版快 // 020701 YGI
		if( ( i->attr[IATTR_ATTR] & IA2_SCENARIO_POTAL ) && ( i->attr[IATTR_ATTR] & IA2_OPENED ) )
		{
			// 付摹 甘 坷宏璃飘狼 OBJECTANI_1_LOOP 贸烦 免仿窍扁 困秦
			//temp_item = i;
			DWORD attr = OBJECTSPRITE_ALPHA;
			if( i->attr[IATTR_ATTR] & IA2_POISONED ) 
			{
				attr = OBJECTSPRITE_TRANS;
			}
			i->Anitype 	  = ITEMANIMATION_ACTIVE;
			int al = 15;
			al <<= 3;
			i->attr[IATTR_SPRITE_TYPE] = al;
			i->attr[IATTR_SPRITE_TYPE] = (i->attr[IATTR_SPRITE_TYPE] & 0xf8) + attr;
			for( j = 0 ; j < 99 ; j ++)
			{		
				if( j == 0 )	t = AddItemSprite( spr_no , type, 0 );
				else 			t = AddItemSprite( spr_no * 100 + j, type, j, 1 );
				if( !t ) break;
				i->spr[j] = &t->sp;
			}
			i->framecount = j;
		}
		else		// 厚劝己拳 老 版快
		{
			t = AddItemSprite( spr_no , type, 0 );
			i->spr[0] = &t->sp;
		}
		return;
	}

	if( type < 13 )
	{										
		/*# AnimationType : 0:NO Animation  1:馆汗  2:空汗   3:巩凯覆   4:巩凯覆惑怕   5:巩摧塞   6:巩摧腮惑怕		
		# Type - 0:焊烹 Item  1: 狼磊   2: Table   3: 档绢  4:Box
		# 笼阑荐乐促 AnimationType Type   Dir  嘛绰规过  嘛绰鉴辑 弊覆磊             DontBox         醚弊覆荐		*/
		i->getable	  = 1;
		
		if (i->no/1000 == 6)
		{	//< CSD-031101
			CItem_Weapon* pWeapon = static_cast<CItem_Weapon*>(ItemUnit(i->no));

			if (pWeapon != NULL)
			{
				const int nEffect = pWeapon->effect;

				i->Anitype = (nEffect > 0) ? 1:0;
			}
			else
			{
				i->Anitype = 0;
			}
		}	
		else
		{
			i->Anitype = 0;
		}	//> CSD-031101
		
		i->type		  = 0; 
		i->dirno	  = 0;
		i->Where	  = 0;	
		i->Sorttype   = 0;
		i->shadow	  = 0;	
		i->dx[0]	  = 0;
		i->dx[1]	  = 0;
		i->dx[2]	  = 0;
		i->dx[3]	  = 0;
		i->framecount = 1;
		i->dsx[0] = 0; i->dsy[1] = 0; i->ddx[0] = 0; i->ddy[1] = 0;

		CItem *ii = ItemUnit( type, no );		//	0527 YGI
		if( !ii ) return;
		int spr_no = ii->GetObjectNumber()/100;
		
		for( m = 0 ; m < 99; m++ )			// 010509 YGI
		{	
			sprintf( temp, "./item/%05d%02d.CSP",  spr_no, m );
			fp = Fopen( temp, "rb" );
			if( fp == NULL )  break;
			fclose(fp);
		}		
		i->framecount = m;
				
		for( j = 0 ; j < m ; j ++)
		{		
			t = AddItemSprite( spr_no * 100 + j,   type, 0 );
			i->spr[j] = &t->sp;
		}		
	}								
	else								
	{			
		//021030 YGI
		fp = 0;
		if( g_Menu_Variable.m_pEventObjcet )
		{
			sprintf( temp, "./object/%s/%s", tempitemname, g_Menu_Variable.m_pEventObjcet->object_b );
			fp = Fopen( temp,"rb" );
		}
		if( !fp )
		{
			sprintf( temp, "./object/%s/%s_toi2.b", tempitemname, MapName );
			fp = Fopen( temp,"rb" );
		}
		// ---------------------------
		
		if( fp != NULL )
		{									
			static int check;
			check++;
			if( (check % 5)  == 2 ) // 眉农级阑 备窍咯 厚背秦夯促. 
			{		
				DWORD fl = filelength( fileno( fp ) );
				char  *tbuf, *buf = NULL;
				char crc = 0, crc1;
				MemAlloc( buf, fl );
				fread( buf, fl-1, 1, fp );
				tbuf = buf;
				for( k = 0 ; k < fl-1 ; k ++ )
				{	
					crc += *tbuf ++;
				}	
				fread( &crc1, 1,1, fp );
				if( CheckSumError == 0 ) 
				{
					CheckSumError = abs( crc - crc1 );
					if( CheckSumError )  JustMsg( " LoadItem CheckSumError " );
				}
				fclose(fp);
				MemFree( buf );
				fp = Fopen(  temp,"rb" );
			}	
				
				
			fread( &obcount, sizeof( int), 1, fp );
					
			for( j = 0 ; j < obcount ; j ++)
			{		
				fseek(fp, j * (sizeof( int ) * 20 + sizeof( short int ) * 4 * ITEM_FRAME_MAX_ ) + sizeof( int ), SEEK_SET );
				fread( &no, sizeof( int ), 1, fp );
				if( no == i->no )
				{	
					fread( &getable,	sizeof( int ), 1, fp );
					fread( &anitype,	sizeof( int ), 1, fp );
					fread( &itemtype,	sizeof( int ), 1, fp );
					fread( &dir,		sizeof( int ), 1, fp );
					fread( &where,		sizeof( int ), 1, fp );
					fread( &sorting,	sizeof( int ), 1, fp );
					fread( &shadow,		sizeof( int ), 1, fp );
					fread( &light,		sizeof( int ), 1, fp );
					fread( &lightx,		sizeof( int ), 1, fp );
					fread( &lighty,		sizeof( int ), 1, fp );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -