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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
#include "stdafx.h"
#include "HappyHour.h"
#include "GameMain.h"
#include "user.h"
#include "protocol.h"
#include "logproc.h"
#include "..\pugixml\pugixml.hpp"
#ifdef MyProtection
#include "License.h"
#endif
// -------------------------------------------------------------------------
using namespace pugi;
cHappyHour g_HappyHour;
// -------------------------------------------------------------------------
cHappyHour::cHappyHour()
{
this->Init();
}
// -------------------------------------------------------------------------
cHappyHour::~cHappyHour()
{
}
// -------------------------------------------------------------------------
void cHappyHour::Init()
{
#ifdef MyProtection
if (MacLicense == false)
{
return;
}
#endif
this->Enable = 0;
this->ExpIncrease = 0;
this->DropIncrease = 0;
this->ExcDropIncrease = 0;
this->lpTime.clear();
if (this->lpTime.capacity() > 0)
{
std::vector<HAPPY_HOUR_TIME>().swap(this->lpTime);
}
}
// -------------------------------------------------------------------------
void cHappyHour::Load()
{
this->Init();
this->Read(gDirPath.GetNewPath(HAPPY_HOUR_DIR));
}
// -------------------------------------------------------------------------
void cHappyHour::Read(char * file)
{
xml_document Document;
xml_parse_result Result = Document.load_file(file);
// ----
if (Result.status != status_ok)
{
MsgBox("[HappyHour] File %s not found! %d", file, Result.status);
return;
}
// ----
xml_node HappyHour = Document.child("HappyHour");
xml_node TimeSettings = HappyHour.child("TimeSettings");
xml_node Node;
this->Enable = HappyHour.child("Enabled").text().as_int(0);
this->ExpIncrease = HappyHour.child("Common").attribute("AddExp").as_int();
this->DropIncrease = HappyHour.child("Common").attribute("AddDrop").as_int();
this->ExcDropIncrease = HappyHour.child("Common").attribute("AddExcDrop").as_int();
for ( Node = TimeSettings.child("Time"); Node; Node = Node.next_sibling() )
{
HAPPY_HOUR_TIME m_Data;
m_Data.sHour = Node.attribute("sHour").as_int();
m_Data.sMin = Node.attribute("sMin").as_int();
m_Data.cHour = Node.attribute("cHour").as_int();
m_Data.cMin = Node.attribute("cMin").as_int();
this->lpTime.push_back(m_Data);
}
}
// -------------------------------------------------------------------------
void cHappyHour::EndEvent()
{
gAddExperience -= this->ExpIncrease;
gItemDropPer -= this->DropIncrease;
gExcItemDropRate -= this->ExcDropIncrease;
// ----
#ifdef DEBUG_HAPPY_HOUR
int NewExp;
NewExp = gAddExperience;
// ----
int NewDrop;
NewDrop = gItemDropPer;
// ----
int NewExc;
NewExc = gExcItemDropRate;
#endif
// ----
char Text[256];
ZeroMemory(Text, sizeof(Text));
sprintf(Text, "[HappyHour] Event has been finished.");
AllSendServerMsg(Text);
// ----
LogAddTD("[HappyHour] Event End");
#ifdef DEBUG_HAPPY_HOUR
LogAddTD("Return Exp: %d, Drop: %d, ExcDrop: %d", NewExp, NewDrop, NewExc);
#endif
}
// -------------------------------------------------------------------------
void cHappyHour::RunEvent()
{
gAddExperience += this->ExpIncrease;
gItemDropPer += this->DropIncrease;
gExcItemDropRate += this->ExcDropIncrease;
// ----
#ifdef DEBUG_HAPPY_HOUR
int NewExp;
NewExp = gAddExperience;
// ----
int NewDrop;
NewDrop = gItemDropPer;
// ----
int NewExc;
NewExc = gExcItemDropRate;
#endif
// ----
char Text[256];
ZeroMemory(Text, sizeof(Text));
sprintf(Text, "[HappyHour] Event has been started.");
AllSendServerMsg(Text);
// ----
LogAddTD("[HappyHour] Event Start");
#ifdef DEBUG_HAPPY_HOUR
LogAddTD("New Exp: %d, Drop: %d, ExcDrop: %d", NewExp, NewDrop, NewExc);
#endif
}
// -------------------------------------------------------------------------
void cHappyHour::TickTime()
{
SYSTEMTIME t;
GetLocalTime(&t);
if (t.wSecond == 00)
{
for (int i = 0; i < this->lpTime.size(); i++)
{
if (t.wHour == this->lpTime[i].sHour && t.wMinute == this->lpTime[i].sMin)
{
this->RunEvent();
}
if (t.wHour == this->lpTime[i].cHour && t.wMinute == this->lpTime[i].cMin)
{
this->EndEvent();
}
for (int a = 0; a < 3; a++)
{
int RemainTime[3] = { 1, 3, 5 };
if (t.wHour == this->lpTime[i].sHour && t.wMinute == this->lpTime[i].sMin - RemainTime[a])
{
if (RemainTime[a] != 0)
{
char Text[256];
ZeroMemory(Text, sizeof(Text));
sprintf(Text, "[HappyHour] Will start in %d min", RemainTime[a]);
AllSendServerMsg(Text);
}
}
if (t.wHour == this->lpTime[i].cHour && t.wMinute == this->lpTime[i].cMin - RemainTime[a])
{
if (RemainTime[a] != 0)
{
char Text[256];
ZeroMemory(Text, sizeof(Text));
sprintf(Text, "[HappyHour] Will close in %d min", RemainTime[a]);
AllSendServerMsg(Text);
}
}
}
}
}
}
// -------------------------------------------------------------------------
| |