Código:
#include "StdAfx.h"
TREASURE_CUSTOM Treasure;
char treasureMapName[][15] = {"Lorencia", "Devias", "Noria"};
BYTE treasureMapNumber[] = {0, 2, 3};
BYTE Index = (BYTE)(rand() % sizeof(treasureMapNumber));
bool TREASURE_CUSTOM::Load()
{
ZeroMemory(this->_winner,sizeof(this->_winner));
this->_enabled = GetPrivateProfileInt("Pirata Jack","Ativar",1,CFG_PIRATA) > 0 ? true : false;
this->_timeOpen = GetPrivateProfileInt("Pirata Jack","TimeOpen",1,CFG_PIRATA) * 60;
this->_timeBuy = GetPrivateProfileInt("Pirata Jack","TimeBuy",1,CFG_PIRATA);
this->_timeClose = GetPrivateProfileInt("Pirata Jack","TimeClose",1,CFG_PIRATA) * 60;
this->_state = treasureOff;
this->_timeCount = this->_timeOpen;
this->_index = -1;
this->_shopNumber = 11;
return true;
}
void TREASURE_CUSTOM::Check()
{
if(!this->_enabled)
{
return;
}
if(this->_timeCount > 0)
{
this->_timeCount--;
return;
}
if(this->_state == treasureOff)
{
ZeroMemory(this->_winner,sizeof(this->_winner));
this->_state = treasureOn;
this->_timeCount = this->_timeClose;
short X, Y;
BYTE Map = treasureMapNumber[Index];
while(func.GetBoxPosition(Map,10,10,240,240,X,Y) == 0) {}
this->_index = gObjAddMonsters();
if(this->_index >= 0 && this->_index < OBJECT_MIN)
{
OBJECTSTRUCT* lpNpc = &gObj[this->_index];
lpNpc->Class = 201;
lpNpc->MapNumber = Map;
lpNpc->X = X;
lpNpc->Y = Y;
lpNpc->Dir = (rand() % 7);
lpNpc->m_RecallMon = this->_index;
lpNpc->TargetNumber = -1;
lpNpc->TX = lpNpc->X;
lpNpc->TY = lpNpc->Y;
lpNpc->MTX = lpNpc->X;
lpNpc->MTY = lpNpc->Y;
lpNpc->m_OldX = lpNpc->X;
lpNpc->m_OldY = lpNpc->Y;
lpNpc->StartX = (BYTE)(lpNpc->X);
lpNpc->StartY = (BYTE)(lpNpc->Y);
lpNpc->m_ActState.Emotion = 0;
lpNpc->m_ActState.Attack = 0;
lpNpc->m_ActState.EmotionCount = 0;
lpNpc->PathCount = 0;
lpNpc->m_MoveRange = 0;
lpNpc->m_PosNum = -1;
Functions::gObjSetMonster(this->_index, 201);
gObjViewportListProtocolCreate(&gObj[this->_index]);
lpNpc->ShopNumber = this->_shopNumber;
char Buffer[60];
sprintf_s(Buffer,"O pirata Jack escondeu seu tesouro em %s",treasureMapName[Index]);
for(int i = OBJECT_MIN; i != OBJECT_MAX; i++)
{
if(gObj[i].Connected == 3)
{
GCServerMsgStringSend(Buffer,i,0);
GCServerMsgStringSend("Procure-o e ganhe recompensas!",i,0);
}
}
}
else
{
this->_timeCount = this->_timeOpen;
this->_index = -1;
this->_state = treasureOff;
}
}
else if(this->_state == treasureOn)
{
this->_state = treasureOff;
this->_timeCount = this->_timeOpen;
if(this->_index != -1)
{
gObjDel(this->_index);
}
if(this->_winner[0] == 0)
{
for(int i = OBJECT_MIN; i != OBJECT_MAX; i++)
{
if(gObj[i].Connected == 3)
{
GCServerMsgStringSend("O tesouro do pirata Jack foi destruído por monstros",i,0);
GCServerMsgStringSend("Tente ajudá-lo novamente na próxima vez",i,0);
}
}
}
else
{
ZeroMemory(this->_winner,sizeof(this->_winner));
}
this->_index = -1;
}
}
void TREASURE_CUSTOM::Talk(OBJECTSTRUCT* Npc, OBJECTSTRUCT* Player)
{
if(!this->_enabled)
{
ChatTargetSend(Npc,"Como eu parei aqui? Vixi! Acho que estou perdido",Player->m_Index);
return;
}
if(this->_state == treasureOn)
{
if(this->_winner[0] == 0)
{
this->_timeCount = this->_timeBuy;
strcpy_s(this->_winner,Player->Name);
ChatTargetSend(Npc,"Obrigado por vir! O tesouro é todo seu!",Player->m_Index);
char Buffer[2][60];
sprintf_s(Buffer[0],"O tesouro foi encontrado por %s",Player->Name);
sprintf_s(Buffer[1],"Localização: %s %02d/%02d",treasureMapName[Index],Npc->X,Npc->Y);
for(int i = OBJECT_MIN; i != OBJECT_MAX; i++)
{
if(gObj[i].Connected == 3)
{
GCServerMsgStringSend(Buffer[0], i, 0);
GCServerMsgStringSend(Buffer[1], i, 0);
}
}
}
else
{
if(_stricmp(this->_winner,Player->Name))
{
ChatTargetSend(Npc,"Parece que você chegou meio tarde, não é?!",Player->m_Index);
}
}
}
else
{
ChatTargetSend(Npc,"Não tem doce no meu baú para você",Player->m_Index);
}
}
BYTE TREASURE_CUSTOM::ShopNumber() const
{
return this->_shopNumber;
}
const char* TREASURE_CUSTOM::Winner() const
{
return this->_winner;
}