forked from GamesDeadLol/GDL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKey.cpp
66 lines (57 loc) · 1.5 KB
/
Key.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
#include "StdAfx.h"
#include "Key.h"
#include "UseManager.h"
#include "Player.h"
CKeyWeenie::CKeyWeenie()
{
}
CKeyWeenie::~CKeyWeenie()
{
}
int CKeyWeenie::UseWith(CPlayerWeenie *player, CWeenieObject *with)
{
CGenericUseEvent *useEvent = new CGenericUseEvent;
useEvent->_target_id = with->GetID();
useEvent->_tool_id = GetID();
useEvent->_max_use_distance = 1.0;
player->ExecuteUseEvent(useEvent);
return WERROR_NONE;
}
int CKeyWeenie::DoUseWithResponse(CWeenieObject *player, CWeenieObject *with)
{
if (CPlayerWeenie *player_weenie = player->AsPlayer())
{
if (!with->IsLocked())
{
if (with->IsContainer())
{
return WERROR_CHEST_ALREADY_UNLOCKED;
}
}
else
{
std::string lockCode;
if (with->m_Qualities.InqString(LOCK_CODE_STRING, lockCode) && !_stricmp(lockCode.c_str(), InqStringQuality(KEY_CODE_STRING, "").c_str()))
{
DecrementStackOrStructureNum();
with->SetLocked(FALSE);
with->EmitSound(Sound_LockSuccess, 1.0f);
int structureNum = 0;
if (m_Qualities.InqInt(STRUCTURE_INT, structureNum, TRUE) && structureNum > 0)
{
player->SendText(csprintf("The %s has been unlocked.\nYour key has %d %s left.", with->GetName().c_str(), structureNum, structureNum != 1 ? "uses" : "use"), LTT_DEFAULT);
}
else
{
player->SendText(csprintf("The %s has been unlocked.\nYour key is used up.", with->GetName().c_str()), LTT_DEFAULT);
}
return WERROR_NONE;
}
else
{
return WERROR_CHEST_WRONG_KEY;
}
}
}
return WERROR_NONE;
}