#include "stdafx.h"
#include "Gameserver.h"
#include "DoubleGoer.h"
#include "Utilidades.h"
#include "Extra.h"
DoubleGoer DGEvent;
int NCItemType = GetPrivateProfileIntA("DoubleGoer","ENCNormalChest DropGroup",12,ENCDPS);
int NCItemNr = GetPrivateProfileIntA("DoubleGoer","ENCNormalChest DropID",15,ENCDPS);
int NCItemLevel = GetPrivateProfileIntA("DoubleGoer","ENCNormalChest DropLevel",0,ENCDPS);
int NCItemSkill = GetPrivateProfileIntA("DoubleGoer","ENCNormalChest DropWithSkill",0,ENCDPS);
int NCItemLuck = GetPrivateProfileIntA("DoubleGoer","ENCNormalChest DropWithLuck",0,ENCDPS);
int NCItemOpt = GetPrivateProfileIntA("DoubleGoer","ENCNormalChest DropLifeAdd",0,ENCDPS);
int NCItemExc = GetPrivateProfileIntA("DoubleGoer","ENCNormalChest DropExcOpt",0,ENCDPS);
int NCItemAncient = GetPrivateProfileIntA("DoubleGoer","ENCNormalChest DropAncOpt",0,ENCDPS);
int GCItemType = GetPrivateProfileIntA("DoubleGoer","ENCGoldenChest DropGroup",14,ENCDPS);
int GCItemNr = GetPrivateProfileIntA("DoubleGoer","ENCGoldenChest DropID",13,ENCDPS);
int GCItemLevel = GetPrivateProfileIntA("DoubleGoer","ENCGoldenChest DropLevel",0,ENCDPS);
int GCItemSkill = GetPrivateProfileIntA("DoubleGoer","ENCGoldenChest DropWithSkill",0,ENCDPS);
int GCItemLuck = GetPrivateProfileIntA("DoubleGoer","ENCGoldenChest DropWithLuck",0,ENCDPS);
int GCItemOpt = GetPrivateProfileIntA("DoubleGoer","ENCGoldenChest DropLifeAdd",0,ENCDPS);
int GCItemExc = GetPrivateProfileIntA("DoubleGoer","ENCGoldenChest DropExcOpt",0,ENCDPS);
int GCItemAncient = GetPrivateProfileIntA("DoubleGoer","ENCGoldenChest DropAncOpt",0,ENCDPS);
<!--more-->void OnCurse__InsideTrigger(void *lParam)
{
int ctime = 600-2;
DGEvent.TimeStoped = 0;
while(true)
{
if(ctime == 540 || ctime == 480 || ctime == 420 || ctime == 360 || ctime == 300 || ctime == 240 || ctime == 180 || ctime == 120 || ctime == 60)DGEvent.LackTime--;
ctime--;
if(DGEvent.TimeStoped == 0)
{
int TIME1,TIME2;
TIME2=(int)floor((float)ctime/255);
TIME1=ctime-(TIME2*255);
DataSend(DGEvent.Players[0],Packet3,Packet3[1]);
if(DGEvent.BossID[2] != 0)
{
DataSend(DGEvent.Players[0],BossPacket,BossPacket[1]);
}
}
if(ctime == 0)
{
if(DGEvent.Players[0] != 0)
{
DataSend(DGEvent.Players[0],FailurePacket,FailurePacket[1]);
}
DGEvent.EndEvent();
DGEvent.InCurse = 0;
_endthread();
}
Sleep(1000);
}
_endthread();
}
void TakeToStart__InsideTrigger(void *lParam)
{
Sleep(5000);
if(DGEvent.Players[0] != 0)DGEvent.StartEvent();
else
{
DGEvent.InCurse = 0;
}
_endthread();
}
void DoubleGoer::RemoveIntruser()
{
for(int x=MIN_PLAYERID;x < MAX_PLAYERID;x++)
{
if(gObjIsConnected(x) == 1)
{
if(gObj_GetMap(x) == EventMap)gObjMoveGate(x,267);
}
}
}
void DoubleGoer::EnterMap(DWORD PlayerID,int Invitation)
{
if(InCurse == 0)
{
InCurse = 1;
LackTime = 10;
Players[0] = PlayerID;
int GoToGate = 329;
if(EventMap == 68)EventMap = 65;
else
{
EventMap++;
}
if(EventMap == 66)GoToGate = 330;
if(EventMap == 67)GoToGate = 331;
if(EventMap == 68)GoToGate = 332;
gObjMoveGate(PlayerID,GoToGate);
gObjInventoryDeleteItem(PlayerID,Invitation);
GCInventoryItemDeleteSend(PlayerID,Invitation,1);
RemoveIntruser();
_beginthread( TakeToStart__InsideTrigger, 0, NULL );
}
else
{
GCServerMsgStringSend("Double Goer Event is full!!", PlayerID,1);
}
}
void DoubleGoer::EndEvent()
{
if(MobCount > 0)
{
ClearMobs();
}
for(int y=0;y<3;y++)
{
if(BossID[y] != 0)
{
gObjDel(BossID[y]);
}
BossID[y] = 0;
}
BossCount = 0;
for(int x=0;x<5;x++)
{
Players[x] = 0;
}
for(int x=0;x<6;x++)
{
if(ChestID[x] != 0)
{
gObjDel(ChestID[x]);
}
ChestID[x] = 0;
}
if(GChestID != 0)
{
gObjDel(GChestID);
GChestID = 0;
}
}
void DoubleGoer::StartEvent()
{
SetMobs("..\\data\\DGMonsterSetBase.txt");
SetBoss();
DataSend(DGEvent.Players[0],Packet2,Packet2[1]);
_beginthread( OnCurse__InsideTrigger, 0, NULL );
}
void DoubleGoer::SetBoss()
{
if(EventMap == 65)
{
BossID[0] = MonsterAddAndSpawn(529,EventMap,198,51);
BossID[1] = MonsterAddAndSpawn(530,EventMap,219,75);
BossID[2] = MonsterAddAndSpawn(531,EventMap,220,84);
}
if(EventMap == 66)
{
BossID[0] = MonsterAddAndSpawn(529,EventMap,137,96);
BossID[1] = MonsterAddAndSpawn(530,EventMap,116,139);
BossID[2] = MonsterAddAndSpawn(531,EventMap,113,158);
}
if(EventMap == 67)
{
BossID[0] = MonsterAddAndSpawn(529,EventMap,****92);
BossID[1] = MonsterAddAndSpawn(530,EventMap,****112);
BossID[2] = MonsterAddAndSpawn(531,EventMap,****128);
}
if(EventMap == 68)
{
BossID[0] = MonsterAddAndSpawn(529,EventMap,93,50);
BossID[1] = MonsterAddAndSpawn(530,EventMap,62,55);
BossID[2] = MonsterAddAndSpawn(531,EventMap,49,80);
}
}
void DoubleGoer::ClearMobs()
{
for(int i=0;i<MobCount;i++)
{
gObjDel(MobID);
MobID = 0;
}
for(int x=0;x<15;x++)
{
if(WormID[x] != 0)
{
gObjDel(WormID[x]);
}
WormID[x] = 0;
}
MobCount = 0;
}
void DoubleGoer::SetMobs(char *FileName)
{
FILE *fp;
char sLineTxt[255] = {0};
int Stage = -1;
MobCount = 0;
fp = fopen(FileName,"r");
if(!fp)
{
MessageBoxA(NULL, "DGMonsterSetBase.txt not found!!", "Error!", MB_OK);
return;
}
rewind(fp);
while(fgets(sLineTxt, 255, fp) != NULL)
{
if(sLineTxt[0] == '/')continue;
if(sLineTxt[0] == ';')continue;
if(strlen(sLineTxt) < 3)
{
sscanf(sLineTxt, "%d", Stage);
}
if(strlen(sLineTxt) > 3)
{
if ((sLineTxt[0] == 'e')&(sLineTxt[1] == 'n')&&(sLineTxt[2] == 'd'))
{
Stage = -1;
continue;
}else
{
if(Stage == 1)
{
int Mob,Map,X,Y;
sscanf(sLineTxt, " %d %d %d %d",Mob,&Map,&X,&Y);
if(Map == EventMap)
{
MobID[MobCount] = MonsterAddAndSpawn(Mob,Map,X,Y);
MobCount++;
}
}
}
}
}
rewind(fp);
fclose(fp);
}
void DoubleGoer::Init()
{
InCurse = 0;
BossCount = 0;
EventMap = 64;
TimeStoped = 0;
for(int x=0;x<5;x++)
{
Players[x] = 0;
}
for(int x=0;x<3;x++)
{
BossID[x] = 0;
}
}
void DoubleGoer::NPCTalk_GateKeeper(DWORD PlayerID)
{
if(InCurse == 0)
{
DataSend (PlayerID,buff , buff[1]);
}
else
{
DataSend (PlayerID,buff , buff[1]);
}
}
void DoubleGoer::CreateGChest()
{
if(EventMap == 65)
{
GChestID = MonsterAddAndSpawn(542,EventMap,224,102);
}
if(EventMap == 66)
{
GChestID = MonsterAddAndSpawn(542,EventMap,****180);
}
if(EventMap == 67)
{
GChestID = MonsterAddAndSpawn(542,EventMap,****150);
}
}
void DoubleGoer::CreateChest(int Map,int X,int Y)
{
BYTE Packet2[6]={0xC1,0x06,0xBF,0x14,0x03,BossCount};
DataSend(Players[0],Packet2,Packet2[1]);
for(int x=0;x<6;x++)
{
if(ChestID[x] == 0)
{
ChestID[x] = MonsterAddAndSpawn(541,Map,X,Y);
ChestID[x+1] = MonsterAddAndSpawn(541,Map,X+2,Y+2);
return;
}
}
}
void DoubleGoer::OpenGChest(DWORD PlayerID,int Map,int X,int Y,int NPC)
{
char Character[11];
gObj_GetNick(PlayerID,Character);
char Message[57];
sprintf(Message,"%s has completed DoubleGoer Event successfully!!",Character);
StringSendAll(Message,0);
}
void DoubleGoer::OpenChest(DWORD PlayerID,int Map,int X,int Y,int NPC)
{
for(int x=0;x<6;x++)
{
if(ChestID[x] == NPC)
{
if(x == 0 || x == 2 || x == 4)
{
gObjDel(ChestID[x]);
gObjDel(ChestID[x+1]);
ChestID[x] = 0;
ChestID[x+1] = 0;
}
}
}
int RamdomPercent = rand() % 100 + 1;
if(RamdomPercent <= 50)
{
DWORD Item=NCItemType*512+NCItemNr;
ItemSerialCreateSend(PlayerID,Map,X,Y,Item,NCItemL evel,0,NCItemSkill,NCItemLuck,NCItemOpt,PlayerID,N CItemExc,NCItemAncient);
}
else
{
for(int w=0;w<15;w++)
{
if(WormID[w] == 0)
{
WormID[w] = MonsterAddAndSpawn(5***Map,X,Y);
WormID[w+1] = MonsterAddAndSpawn(5***Map,X,Y);
WormID[w+2] = MonsterAddAndSpawn(5***Map,X,Y);
WormID[w+3] = MonsterAddAndSpawn(5***Map,X,Y);
WormID[w+4] = MonsterAddAndSpawn(5***Map,X,Y);
return;
}
}
}
}
int DoubleGoer::IsInEvent(DWORD PlayerID)
{
for(int x=0;x<5;x++)
{
if(Players[x] == PlayerID)return 1;
}
return 0;
}
int DoubleGoer::GetPosition(DWORD PlayerID)
{
int result,temp;
int Y = (int)gObj_GetPosY(PlayerID);
if(Y < 0)Y = Y + 256;
if(EventMap == 65)temp = (Y-34)/2.7;
if(EventMap == 66)temp = (Y-80)/4.2;
if(EventMap == 67)temp = (Y-70)/3.2;
if(EventMap == 68)temp = (Y-25)/3.4;
if(temp <= 0)result = 22;
if(temp >= 22)result = 0;
else
{
result = 22-temp;
}
return result;
}