-
Notifications
You must be signed in to change notification settings - Fork 0
/
Item.cpp
99 lines (72 loc) · 1.58 KB
/
Item.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "Item.h"
#include "FileStream.h"
CItem::CItem()
{
}
CItem::CItem(const CItem & item) : CObj(item)
{
m_tInfo = item.m_tInfo;
}
CItem::~CItem()
{
}
void CItem::SetItemInfo(ITEM_TYPE eType, int iPrice, int iSell, const std::string& SDesc)
{
m_tInfo.eType = eType;
switch (eType)
{
case IT_WEAPON:
m_tInfo.strTypeName = "¹«±â";
break;
case IT_ARMOR:
m_tInfo.strTypeName = "¹æ¾î±¸";
break;
}
m_tInfo.iPrice = iPrice;
m_tInfo.iSell = iSell;
m_tInfo.strDesc = SDesc;
}
bool CItem::Init()
{
return false;
}
void CItem::Render()
{
}
void CItem::Save(CFileStream * pFile)
{
CObj::Save(pFile);
//pFile->Write(&m_tInfo, sizeof(m_tInfo));
pFile->Write(&m_eType, 4);
int iLength = m_tInfo.strTypeName.length();
pFile->Write(&iLength, 4);
pFile->Write((void*)m_tInfo.strTypeName.c_str(), iLength);
pFile->Write(&m_tInfo.iPrice, 4);
pFile->Write(&m_tInfo.iSell, 4);
iLength = m_tInfo.strDesc.length();
pFile->Write(&iLength, 4);
pFile->Write((void*)m_tInfo.strDesc.c_str(), iLength);
}
void CItem::Load(CFileStream * pFile)
{
CObj::Load(pFile);
pFile->Read(&m_tInfo.eType, 4);
int iLength = 0;
pFile->Read(&iLength, 4);
char* pName = new char[iLength + 1];
memset(pName, 0, iLength);
pFile->Read(pName, iLength);
pName[iLength] = 0;
m_tInfo.strTypeName = pName;
SAFE_DELETE_ARRAY(pName);
pFile->Read(&m_tInfo.iPrice, 4);
pFile->Read(&m_tInfo.iSell, 4);
iLength = 0;
pFile->Read(&iLength, 4);
pName = new char[iLength + 1];
memset(pName, 0, iLength);
pFile->Read(pName, iLength);
pName[iLength] = 0;
m_tInfo.strDesc = pName;
SAFE_DELETE_ARRAY(pName);
}