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

📄 itemdb.c

📁 仙镜游戏源码,仅供学习!请勿用于非法应用!
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "mmo.h"#include "grfio.h"#include "itemdb.h"#define ITEMDB_HASH_SIZE 64static int itemdb_hash[ITEMDB_HASH_SIZE];static int itemdb_size,itemdb_num;static struct {  // for hash  int nameid;  int next;  // data  int value;  int type;  int class;  int equip;  int weight;  int atk;  int def;  int slot;  int look;} *itemdb;static int search_itemdb_index(int nameid){  int i;  for(i=itemdb_hash[nameid%ITEMDB_HASH_SIZE];i>=0;i=itemdb[i].next)    if(itemdb[i].nameid==nameid)      return i;  if(itemdb_size<=itemdb_num){    itemdb_size+=ITEMDB_HASH_SIZE;    itemdb=realloc(itemdb,sizeof(itemdb[0])*itemdb_size);  }  i=itemdb_num;  itemdb_num++;  itemdb[i].nameid=nameid;  itemdb[i].next=itemdb_hash[nameid%ITEMDB_HASH_SIZE];  itemdb_hash[nameid%ITEMDB_HASH_SIZE]=i;  itemdb[i].value=10;  itemdb[i].type=0;  itemdb[i].class=0;  itemdb[i].equip=0;  itemdb[i].weight=10;  itemdb[i].atk=0;  itemdb[i].def=0;  itemdb[i].slot=0;  itemdb[i].look=0;  return i;}int itemdb_type(int nameid){  if(nameid>500 && nameid<600)    return 0;	//heal item  if(nameid>600 && nameid<700)    return 2;	//use item  if((nameid>700 && nameid<1100) ||     (nameid>7000 && nameid<8000))    return 3;	//correction  if(nameid>=1750 && nameid<1760)    return 10;	//arrow  if(nameid>1100 && nameid<2000)    return 4;	//weapon  if((nameid>2100 && nameid<3000) ||     (nameid>5000 && nameid<6000))    return 5;	//armor  if(nameid>4000 && nameid<5000)    return 6;	//card  return 0;}int itemdb_sellvalue(int nameid){  return itemdb[search_itemdb_index(nameid)].value;}int itemdb_weight(int nameid){  return itemdb[search_itemdb_index(nameid)].weight;}int itemdb_isequip(int nameid){  return itemdb[search_itemdb_index(nameid)].equip!=0;}int itemdb_equip_point(int nameid,struct map_session_data *sd){  return itemdb[search_itemdb_index(nameid)].equip;}static int itemdb_read_itemslottable(void){  char *buf,*p;  int s;  buf=grfio_read("data\\itemslottable.txt");  if(buf==NULL)    return -1;  s=grfio_size("data\\itemslottable.txt");  buf[s]=0;  for(p=buf;p-buf<s;){    int nameid,equip;    sscanf(p,"%d#%d#",&nameid,&equip);    itemdb[search_itemdb_index(nameid)].equip=equip;    p=strchr(p,10);    if(!p) break;    p++;    p=strchr(p,10);    if(!p) break;    p++;  }  return 0;}int itemdb_init(void){  int i;  for(i=0;i<ITEMDB_HASH_SIZE;i++)    itemdb_hash[i]=-1;  itemdb_size=ITEMDB_HASH_SIZE;  itemdb_num=0;  itemdb=malloc(sizeof(itemdb[0])*itemdb_size);    itemdb_read_itemslottable();#if 0  for(i=0;i<ITEMDB_HASH_SIZE;i++){    int j,c;    for(j=itemdb_hash[i],c=0;j>=0;j=itemdb[j].next,c++);    printf("%4d",c);    if(i%16==15) printf("\n");  }  exit(1);#endif  return 0;}

⌨️ 快捷键说明

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