1
0
forked from metin2/server
server/src/game/src/questlua_monarch.cpp
2024-04-05 23:34:45 +02:00

978 lines
29 KiB
C++

#include "stdafx.h"
#include "questlua.h"
#include "questmanager.h"
#include "monarch.h"
#include "desc_client.h"
#include "start_position.h"
#include "config.h"
#include "mob_manager.h"
#include "castle.h"
#include "char.h"
#include "char_manager.h"
#include "utils.h"
#include "p2p.h"
#include "guild.h"
#include "sectree_manager.h"
ACMD(do_monarch_mob);
namespace quest
{
EVENTINFO(monarch_powerup_event_info)
{
int EmpireIndex;
monarch_powerup_event_info()
: EmpireIndex( 0 )
{
}
};
// NOTE: Copied from SPacketGGMonarchTransfer for event data
EVENTINFO(monarch_transfer2_event_info)
{
BYTE bHeader;
DWORD dwTargetPID;
int x;
int y;
monarch_transfer2_event_info()
: bHeader( 0 )
, dwTargetPID( 0 )
, x( 0 )
, y( 0 )
{
}
};
EVENTFUNC(monarch_powerup_event)
{
monarch_powerup_event_info * info = dynamic_cast<monarch_powerup_event_info*>(event->info);
if ( info == NULL )
{
quest_err( "monarch_powerup_event> <Factor> Null pointer" );
return 0;
}
CMonarch::instance().PowerUp(info->EmpireIndex, false);
return 0;
}
EVENTINFO(monarch_defenseup_event_info)
{
int EmpireIndex;
monarch_defenseup_event_info()
: EmpireIndex( 0 )
{
}
};
EVENTFUNC(monarch_defenseup_event)
{
monarch_powerup_event_info * info = dynamic_cast<monarch_powerup_event_info*>(event->info);
if ( info == NULL )
{
quest_err( "monarch_defenseup_event> <Factor> Null pointer" );
return 0;
}
CMonarch::instance().DefenseUp(info->EmpireIndex, false);
return 0;
}
//
// "monarch_" lua functions
//
int takemonarchmoney(lua_State * L)
{
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
int nMoney = (int)lua_tonumber(L,1);
int nPID = ch->GetPlayerID();
int nEmpire = ch->GetEmpire();
nMoney = nMoney * 10000;
SPDLOG_DEBUG("[MONARCH] Take Money Empire({}) pid({}) Money({})", ch->GetEmpire(), ch->GetPlayerID(), nMoney);
db_clientdesc->DBPacketHeader(HEADER_GD_TAKE_MONARCH_MONEY, ch->GetDesc()->GetHandle(), sizeof(int) * 3);
db_clientdesc->Packet(&nEmpire, sizeof(int));
db_clientdesc->Packet(&nPID, sizeof(int));
db_clientdesc->Packet(&nMoney, sizeof(int));
return 1;
}
int is_guild_master(lua_State * L)
{
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (ch->GetGuild() )
{
TGuildMember * pMember = ch->GetGuild()->GetMember(ch->GetPlayerID());
if (pMember)
{
if (pMember->grade <= 4)
{
lua_pushnumber(L ,1);
return 1;
}
}
}
lua_pushnumber(L ,0);
return 1;
}
int monarch_bless(lua_State * L)
{
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (false==ch->IsMonarch())
{
if (!ch->IsGM())
{
ch->ChatPacket(CHAT_TYPE_INFO ,LC_TEXT("\xB1\xBA\xC1\xD6\xC0\xC7 \xC0\xDA\xB0\xDD\xC0\xBB \xB0\xA1\xC1\xF6\xB0\xED \xC0\xD6\xC1\xF6 \xBE\xCA\xBD\xC0\xB4\xCF\xB4\xD9"));
quest_err("No Monarch pid %d ", ch->GetPlayerID());
return 0;
}
}
int HealPrice = quest::CQuestManager::instance().GetEventFlag("MonarchHealGold");
if (HealPrice == 0)
HealPrice = 2000000; // 200만
if (CMonarch::instance().HealMyEmpire(ch, HealPrice))
{
char szNotice[256];
snprintf(szNotice, sizeof(szNotice),
LC_TEXT("\xB1\xBA\xC1\xD6\xC0\xC7 \xC3\xE0\xBA\xB9\xC0\xB8\xB7\xCE \xC0\xCC\xC1\xF6\xBF\xAA %s \xC0\xAF\xC0\xFA\xB4\xC2 HP,SP\xB0\xA1 \xB8\xF0\xB5\xCE \xC3\xA4\xBF\xF6\xC1\xFD\xB4\xCF\xB4\xD9."), EMPIRE_NAME(ch->GetEmpire()));
SendNoticeMap(szNotice, ch->GetMapIndex(), false);
ch->ChatPacket(CHAT_TYPE_INFO ,LC_TEXT("\xB1\xBA\xC1\xD6\xC0\xC7 \xC3\xE0\xBA\xB9\xC0\xBB \xBB\xE7\xBF\xEB\xC7\xCF\xBF\xB4\xBD\xC0\xB4\xCF\xB4\xD9."));
}
return 1;
}
// 군주의 사자후 퀘스트 함수
int monarch_powerup(lua_State * L)
{
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (!ch)
return 0;
//군주 체크
if (false==ch->IsMonarch())
{
if (!ch->IsGM())
{
ch->ChatPacket(CHAT_TYPE_INFO ,LC_TEXT("\xB1\xBA\xC1\xD6\xC0\xC7 \xC0\xDA\xB0\xDD\xC0\xBB \xB0\xA1\xC1\xF6\xB0\xED \xC0\xD6\xC1\xF6 \xBE\xCA\xBD\xC0\xB4\xCF\xB4\xD9"));
quest_err("No Monarch pid %d ", ch->GetPlayerID());
return 0;
}
}
//군주 국고 검사
int money_need = 5000000; // 500만
if (!CMonarch::instance().IsMoneyOk(money_need, ch->GetEmpire()))
{
int NationMoney = CMonarch::instance().GetMoney(ch->GetEmpire());
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB1\xB9\xB0\xED\xBF\xA1 \xB5\xB7\xC0\xCC \xBA\xCE\xC1\xB7\xC7\xD5\xB4\xCF\xB4\xD9. \xC7\xF6\xC0\xE7 : %u \xC7\xCA\xBF\xE4\xB1\xDD\xBE\xD7 : %u"), NationMoney, money_need);
return 0;
}
if (!CMonarch::instance().CheckPowerUpCT(ch->GetEmpire()))
{
int next_sec = CMonarch::instance().GetPowerUpCT(ch->GetEmpire()) / passes_per_sec;
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xC4\xF0\xC5\xB8\xC0\xD3 \xC0\xFB\xBF\xEB\xC1\xDF %d \xC8\xC4 \xBB\xE7\xBF\xEB\xB0\xA1\xB4\xC9"), next_sec);
return 0;
}
//군주의 사자후 적용
CMonarch::instance().PowerUp(ch->GetEmpire(), true);
//군주의 사자후 적용시간
int g_nMonarchPowerUpCT = 60 * 3;
monarch_powerup_event_info* info = AllocEventInfo<monarch_powerup_event_info>();
info->EmpireIndex = ch->GetEmpire();
event_create(quest::monarch_powerup_event, info, PASSES_PER_SEC(g_nMonarchPowerUpCT));
CMonarch::instance().SendtoDBDecMoney(5000000, ch->GetEmpire(), ch);
char szNotice[256];
snprintf(szNotice, sizeof(szNotice), LC_TEXT("\xB1\xBA\xC1\xD6\xC0\xC7 \xBB\xE7\xC0\xDA\xC8\xC4 \xBF\xB5\xC7\xE2\xC0\xB8\xB7\xCE \xC0\xCC\xC1\xF6\xBF\xAA %s \xC0\xAF\xC0\xFA\xB4\xC2 3\xBA\xD0\xB0\xA3 10 %% \xC0\xC7 \xB0\xF8\xB0\xDD\xB7\xC2\xC0\xCC \xC1\xF5\xB0\xA1\xB5\xCB\xB4\xCF\xB4\xD9"), EMPIRE_NAME(ch->GetEmpire()));
SendNoticeMap(szNotice, ch->GetMapIndex(), false);
return 1;
}
// 군주의 금강권 퀘스트 함수
int monarch_defenseup(lua_State * L)
{
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (!ch)
return 0;
//군주 체크
if (false==ch->IsMonarch())
{
if (!ch->IsGM())
{
ch->ChatPacket(CHAT_TYPE_INFO ,LC_TEXT("\xB1\xBA\xC1\xD6\xC0\xC7 \xC0\xDA\xB0\xDD\xC0\xBB \xB0\xA1\xC1\xF6\xB0\xED \xC0\xD6\xC1\xF6 \xBE\xCA\xBD\xC0\xB4\xCF\xB4\xD9"));
quest_err("No Monarch pid %d ", ch->GetPlayerID());
return 0;
}
}
int money_need = 5000000; // 500만
if (!CMonarch::instance().IsMoneyOk(money_need, ch->GetEmpire()))
{
int NationMoney = CMonarch::instance().GetMoney(ch->GetEmpire());
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB1\xB9\xB0\xED\xBF\xA1 \xB5\xB7\xC0\xCC \xBA\xCE\xC1\xB7\xC7\xD5\xB4\xCF\xB4\xD9. \xC7\xF6\xC0\xE7 : %u \xC7\xCA\xBF\xE4\xB1\xDD\xBE\xD7 : %u"), NationMoney, money_need);
return 0;
}
if (!CMonarch::instance().CheckDefenseUpCT(ch->GetEmpire()))
{
int next_sec = CMonarch::instance().GetDefenseUpCT(ch->GetEmpire()) / passes_per_sec;
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xC4\xF0\xC5\xB8\xC0\xD3 \xC0\xFB\xBF\xEB\xC1\xDF %d \xC8\xC4 \xBB\xE7\xBF\xEB\xB0\xA1\xB4\xC9"), next_sec);
return 0;
}
//군주의 금강권 적용
CMonarch::instance().DefenseUp(ch->GetEmpire(), true);
//군주의 금강권 적용 시간
int g_nMonarchDefenseUpCT = 60 * 3;
monarch_defenseup_event_info* info = AllocEventInfo<monarch_defenseup_event_info>();
info->EmpireIndex = ch->GetEmpire();
event_create(quest::monarch_defenseup_event, info, PASSES_PER_SEC(g_nMonarchDefenseUpCT));
CMonarch::instance().SendtoDBDecMoney(5000000, ch->GetEmpire(), ch);
char szNotice[256];
snprintf(szNotice, sizeof(szNotice), LC_TEXT("\xB1\xBA\xC1\xD6\xC0\xC7 \xB1\xDD\xB0\xAD\xB1\xC7 \xBF\xB5\xC7\xE2\xC0\xB8\xB7\xCE \xC0\xCC\xC1\xF6\xBF\xAA %s \xC0\xAF\xC0\xFA\xB4\xC2 3\xBA\xD0\xB0\xA3 10 %% \xC0\xC7 \xB9\xE6\xBE\xEE\xB7\xC2\xC0\xCC \xC1\xF5\xB0\xA1\xB5\xCB\xB4\xCF\xB4\xD9"), EMPIRE_NAME(ch->GetEmpire()));
SendNoticeMap(szNotice, ch->GetMapIndex(), false);
return 1;
}
int is_monarch(lua_State * L)
{
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (!ch)
return 0;
lua_pushnumber(L, ch->IsMonarch());
return 1;
}
int spawn_mob(lua_State * L)
{
if (!lua_isnumber(L, 1))
{
quest_err("invalid argument");
return 0;
}
DWORD mob_vnum = (DWORD)lua_tonumber(L, 1);
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (!ch)
return 0;
const CMob * pkMob = NULL;
if (!(pkMob = CMobManager::Instance().Get(mob_vnum)))
if (pkMob == NULL)
{
ch->ChatPacket(CHAT_TYPE_INFO, "No such mob by that vnum");
return 0;
}
if (false == ch->IsMonarch())
{
if (!ch->IsGM())
{
ch->ChatPacket(CHAT_TYPE_INFO ,LC_TEXT("\xB1\xBA\xC1\xD6\xC0\xC7 \xC0\xDA\xB0\xDD\xC0\xBB \xB0\xA1\xC1\xF6\xB0\xED \xC0\xD6\xC1\xF6 \xBE\xCA\xBD\xC0\xB4\xCF\xB4\xD9"));
quest_err("No Monarch pid %d ", ch->GetPlayerID());
return 0;
}
}
DWORD dwQuestIdx = CQuestManager::instance().GetCurrentPC()->GetCurrentQuestIndex();
bool ret = false;
LPCHARACTER mob = NULL;
{
int x = ch->GetX();
int y = ch->GetY();
#if 0
if (11505 == mob_vnum) // 황금두꺼비
{
//군주 국고 검사
if (!CMonarch::instance().IsMoneyOk(CASTLE_FROG_PRICE, ch->GetEmpire()))
{
int NationMoney = CMonarch::instance().GetMoney(ch->GetEmpire());
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB1\xB9\xB0\xED\xBF\xA1 \xB5\xB7\xC0\xCC \xBA\xCE\xC1\xB7\xC7\xD5\xB4\xCF\xB4\xD9. \xC7\xF6\xC0\xE7 : %u \xC7\xCA\xBF\xE4\xB1\xDD\xBE\xD7 : %u"), NationMoney, CASTLE_FROG_PRICE);
return 0;
}
mob = castle_spawn_frog(ch->GetEmpire());
if (mob)
{
// 국고감소
CMonarch::instance().SendtoDBDecMoney(CASTLE_FROG_PRICE, ch->GetEmpire(), ch);
castle_save();
}
}
else
#endif
{
mob = CHARACTER_MANAGER::instance().SpawnMob(mob_vnum, ch->GetMapIndex(), x, y, 0, pkMob->m_table.bType == CHAR_TYPE_STONE, -1);
}
if (mob)
{
//if (bAggressive)
// mob->SetAggressive();
mob->SetQuestBy(dwQuestIdx);
if (!ret)
{
ret = true;
lua_pushnumber(L, (DWORD) mob->GetVID());
}
}
}
return 1;
}
int spawn_guard(lua_State * L)
{
// mob_level(0-2), region(0~3)
if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2))
{
quest_err("invalid argument");
return 0;
}
DWORD group_vnum = (DWORD)lua_tonumber(L,1);
int region_index = (int)lua_tonumber(L, 2);
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (!ch)
return 0;
/*-----
const CMob * pkMob = NULL;
if (!(pkMob = CMobManager::Instance().Get(mob_vnum)))
if (pkMob == NULL)
{
ch->ChatPacket(CHAT_TYPE_INFO, "No such mob by that vnum");
return 0;
}
-----*/
if (false==ch->IsMonarch())
{
if (!ch->IsGM())
{
ch->ChatPacket(CHAT_TYPE_INFO ,LC_TEXT("\xB1\xBA\xC1\xD6\xC0\xC7 \xC0\xDA\xB0\xDD\xC0\xBB \xB0\xA1\xC1\xF6\xB0\xED \xC0\xD6\xC1\xF6 \xBE\xCA\xBD\xC0\xB4\xCF\xB4\xD9"));
quest_err("No Monarch pid %d ", ch->GetPlayerID());
return 0;
}
}
if (false==castle_is_my_castle(ch->GetEmpire(), ch->GetMapIndex()))
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xBC\xBA\xBF\xA1\xBC\xAD\xB8\xB8 \xBB\xE7\xBF\xEB\xC7\xD2 \xBC\xF6 \xC0\xD6\xB4\xC2 \xB1\xE2\xB4\xC9\xC0\xD4\xB4\xCF\xB4\xD9."));
return 0;
}
//DWORD dwQuestIdx = CQuestManager::instance().GetCurrentPC()->GetCurrentQuestIndex();
LPCHARACTER guard_leader = NULL;
{
int money_need = castle_cost_of_hiring_guard(group_vnum);
//군주 국고 검사
if (!CMonarch::instance().IsMoneyOk(money_need, ch->GetEmpire()))
{
int NationMoney = CMonarch::instance().GetMoney(ch->GetEmpire());
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB1\xB9\xB0\xED\xBF\xA1 \xB5\xB7\xC0\xCC \xBA\xCE\xC1\xB7\xC7\xD5\xB4\xCF\xB4\xD9. \xC7\xF6\xC0\xE7 : %u \xC7\xCA\xBF\xE4\xB1\xDD\xBE\xD7 : %u"), NationMoney, money_need);
return 0;
}
guard_leader = castle_spawn_guard(ch->GetEmpire(), group_vnum, region_index);
if (guard_leader)
{
// 국고감소
CMonarch::instance().SendtoDBDecMoney(money_need, ch->GetEmpire(), ch);
castle_save();
}
}
return 1;
}
int frog_to_empire_money(lua_State * L)
{
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (NULL==ch)
return false;
if (!ch->IsMonarch())
{
if (!ch->IsGM())
{
ch->ChatPacket(CHAT_TYPE_INFO ,LC_TEXT("\xB1\xBA\xC1\xD6\xC0\xC7 \xC0\xDA\xB0\xDD\xC0\xBB \xB0\xA1\xC1\xF6\xB0\xED \xC0\xD6\xC1\xF6 \xBE\xCA\xBD\xC0\xB4\xCF\xB4\xD9"));
quest_err("No Monarch pid %d ", ch->GetPlayerID());
return 0;
}
}
if (castle_frog_to_empire_money(ch))
{
int empire_money = CMonarch::instance().GetMoney(ch->GetEmpire());
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("TEST : \xC8\xB2\xB1\xDD\xB5\xCE\xB2\xA8\xBA\xF1\xB0\xA1 \xB1\xB9\xB0\xED\xB7\xCE \xC8\xAF\xBF\xF8\xB5\xC7\xBE\xFA\xBD\xC0\xB4\xCF\xB4\xD9."));
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("TEST : \xC7\xF6\xC0\xE7 \xB1\xB9\xB0\xED : %d"), empire_money);
castle_save();
return 1;
}
else
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("TEST : \xC8\xB2\xB1\xDD\xB5\xCE\xB2\xA8\xBA\xF1\xB8\xA6 \xB1\xB9\xB0\xED\xB7\xCE \xC8\xAF\xBF\xF8\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
}
int monarch_warp(lua_State * L)
{
if (!lua_isstring(L, 1))
{
quest_err("invalid argument");
return 0;
}
std::string name = lua_tostring(L, 1);
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (!ch)
return 0;
if (!CMonarch::instance().IsMonarch(ch->GetPlayerID(), ch->GetEmpire()))
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB1\xBA\xC1\xD6\xB8\xB8\xC0\xCC \xBB\xE7\xBF\xEB \xB0\xA1\xB4\xC9\xC7\xD1 \xB1\xE2\xB4\xC9\xC0\xD4\xB4\xCF\xB4\xD9"));
return 0;
}
//군주 쿨타임 검사
if (!ch->IsMCOK(CHARACTER::MI_WARP))
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%d \xC3\xCA\xB0\xA3 \xC4\xF0\xC5\xB8\xC0\xD3\xC0\xCC \xC0\xFB\xBF\xEB\xC1\xDF\xC0\xD4\xB4\xCF\xB4\xD9."), ch->GetMCLTime(CHARACTER::MI_WARP));
return 0;
}
//군주 몹 소환 비용
const int WarpPrice = 10000;
//군주 국고 검사
if (!CMonarch::instance().IsMoneyOk(WarpPrice, ch->GetEmpire()))
{
int NationMoney = CMonarch::instance().GetMoney(ch->GetEmpire());
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB1\xB9\xB0\xED\xBF\xA1 \xB5\xB7\xC0\xCC \xBA\xCE\xC1\xB7\xC7\xD5\xB4\xCF\xB4\xD9. \xC7\xF6\xC0\xE7 : %u \xC7\xCA\xBF\xE4\xB1\xDD\xBE\xD7 : %u"), NationMoney, WarpPrice);
return 0;
}
int x, y;
LPCHARACTER tch = CHARACTER_MANAGER::instance().FindPC(name.c_str());
if (!tch)
{
CCI * pkCCI = P2P_MANAGER::instance().Find(name.c_str());
if (pkCCI)
{
if (pkCCI->bEmpire != ch->GetEmpire())
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xC5\xB8\xC1\xA6\xB1\xB9 \xC0\xAF\xC0\xFA\xBF\xA1\xB0\xD4\xB4\xC2 \xC0\xCC\xB5\xBF\xC7\xD2\xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9"));
return 0;
}
if (pkCCI->bChannel != g_bChannel)
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xC7\xD8\xB4\xE7 \xC0\xAF\xC0\xFA\xB4\xC2 %d \xC3\xA4\xB3\xCE\xBF\xA1 \xC0\xD6\xBD\xC0\xB4\xCF\xB4\xD9. (\xC7\xF6\xC0\xE7 \xC3\xA4\xB3\xCE %d)"), pkCCI->bChannel, g_bChannel);
return 0;
}
if (!IsMonarchWarpZone(pkCCI->lMapIndex))
{
ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT("\xC7\xD8\xB4\xE7 \xC1\xF6\xBF\xAA\xC0\xB8\xB7\xCE \xC0\xCC\xB5\xBF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
PIXEL_POSITION pos;
if (!SECTREE_MANAGER::instance().GetCenterPositionOfMap(pkCCI->lMapIndex, pos))
ch->ChatPacket(CHAT_TYPE_INFO, "Cannot find map (index %d)", pkCCI->lMapIndex);
else
{
//ch->ChatPacket(CHAT_TYPE_INFO, "You warp to (%d, %d)", pos.x, pos.y);
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s \xBF\xA1\xB0\xD4\xB7\xCE \xC0\xCC\xB5\xBF\xC7\xD5\xB4\xCF\xB4\xD9"), name.c_str());
ch->WarpSet(pos.x, pos.y);
//군주 돈 삭감
CMonarch::instance().SendtoDBDecMoney(WarpPrice, ch->GetEmpire(), ch);
//쿨타임 초기화
ch->SetMC(CHARACTER::MI_WARP);
}
}
else if (NULL == CHARACTER_MANAGER::instance().FindPC(name.c_str()))
{
ch->ChatPacket(CHAT_TYPE_INFO, "There is no one by that name");
}
return 0;
}
else
{
if (tch->GetEmpire() != ch->GetEmpire())
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xC5\xB8\xC1\xA6\xB1\xB9 \xC0\xAF\xC0\xFA\xBF\xA1\xB0\xD4\xB4\xC2 \xC0\xCC\xB5\xBF\xC7\xD2\xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9"));
return 0;
}
if (!IsMonarchWarpZone(tch->GetMapIndex()))
{
ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT("\xC7\xD8\xB4\xE7 \xC1\xF6\xBF\xAA\xC0\xB8\xB7\xCE \xC0\xCC\xB5\xBF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
x = tch->GetX();
y = tch->GetY();
}
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s \xBF\xA1\xB0\xD4\xB7\xCE \xC0\xCC\xB5\xBF\xC7\xD5\xB4\xCF\xB4\xD9"), name.c_str());
ch->WarpSet(x,y);
ch->Stop();
//군주 돈 삭감
CMonarch::instance().SendtoDBDecMoney(WarpPrice, ch->GetEmpire(), ch);
//쿨타임 초기화
ch->SetMC(CHARACTER::MI_WARP);
return 0;
}
int empire_info(lua_State * L)
{
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (NULL == ch)
return false;
TMonarchInfo * p = CMonarch::instance().GetMonarch();
if (CMonarch::instance().IsMonarch(ch->GetPlayerID(), ch->GetEmpire()))
{
ch->ChatPacket(CHAT_TYPE_INFO,LC_TEXT("\xB3\xAA\xC0\xC7 \xB1\xBA\xC1\xD6 \xC1\xA4\xBA\xB8"));
for (int n = 1; n < 4; ++n)
{
if (n == ch->GetEmpire())
ch->ChatPacket(CHAT_TYPE_INFO,LC_TEXT("[%s\xB1\xBA\xC1\xD6] : %s \xBA\xB8\xC0\xAF\xB1\xDD\xBE\xD7 %lld "), EMPIRE_NAME(n), p->name[n], p->money[n]);
else
ch->ChatPacket(CHAT_TYPE_INFO,LC_TEXT("[%s\xB1\xBA\xC1\xD6] : %s "), EMPIRE_NAME(n), p->name[n]);
}
}
else
{
ch->ChatPacket(CHAT_TYPE_INFO,LC_TEXT("\xB1\xBA\xC1\xD6 \xC1\xA4\xBA\xB8"));
for (int n = 1; n < 4; ++n)
ch->ChatPacket(CHAT_TYPE_INFO,LC_TEXT("[%s\xB1\xBA\xC1\xD6] : %s "), EMPIRE_NAME(n), p->name[n]);
}
return 0;
}
int monarch_transfer(lua_State * L)
{
if (!lua_isstring(L, 1))
{
quest_err("invalid argument");
return 0;
}
std::string name = lua_tostring(L, 1);
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (!ch)
return 0;
if (!CMonarch::instance().IsMonarch(ch->GetPlayerID(), ch->GetEmpire()))
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB1\xBA\xC1\xD6\xB8\xB8\xC0\xCC \xBB\xE7\xBF\xEB \xB0\xA1\xB4\xC9\xC7\xD1 \xB1\xE2\xB4\xC9\xC0\xD4\xB4\xCF\xB4\xD9"));
return 0;
}
// 군주 쿨타임 검사
if (!ch->IsMCOK(CHARACTER::MI_TRANSFER))
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%d \xC3\xCA\xB0\xA3 \xC4\xF0\xC5\xB8\xC0\xD3\xC0\xCC \xC0\xFB\xBF\xEB\xC1\xDF\xC0\xD4\xB4\xCF\xB4\xD9."), ch->GetMCLTime(CHARACTER::MI_TRANSFER));
return 0;
}
// 군주 워프 비용
const int WarpPrice = 10000;
// 군주 국고 검사
if (!CMonarch::instance().IsMoneyOk(WarpPrice, ch->GetEmpire()))
{
int NationMoney = CMonarch::instance().GetMoney(ch->GetEmpire());
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB1\xB9\xB0\xED\xBF\xA1 \xB5\xB7\xC0\xCC \xBA\xCE\xC1\xB7\xC7\xD5\xB4\xCF\xB4\xD9. \xC7\xF6\xC0\xE7 : %u \xC7\xCA\xBF\xE4\xB1\xDD\xBE\xD7 : %u"), NationMoney, WarpPrice);
return 0;
}
LPCHARACTER tch = CHARACTER_MANAGER::instance().FindPC(name.c_str());
if (!tch)
{
CCI * pkCCI = P2P_MANAGER::instance().Find(name.c_str());
if (pkCCI)
{
if (pkCCI->bEmpire != ch->GetEmpire())
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB4\xD9\xB8\xA5 \xC1\xA6\xB1\xB9 \xC0\xAF\xC0\xFA\xB4\xC2 \xBC\xD2\xC8\xAF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
if (pkCCI->bChannel != g_bChannel)
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s \xB4\xD4\xC0\xBA %d \xC3\xA4\xB3\xCE\xBF\xA1 \xC1\xA2\xBC\xD3 \xC1\xDF \xC0\xD4\xB4\xCF\xB4\xD9. (\xC7\xF6\xC0\xE7 \xC3\xA4\xB3\xCE: %d)"), name.c_str(), pkCCI->bChannel, g_bChannel);
return 0;
}
if (!IsMonarchWarpZone(pkCCI->lMapIndex))
{
ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT("\xC7\xD8\xB4\xE7 \xC1\xF6\xBF\xAA\xC0\xB8\xB7\xCE \xC0\xCC\xB5\xBF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
if (!IsMonarchWarpZone(ch->GetMapIndex()))
{
ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT("\xC7\xD8\xB4\xE7 \xC1\xF6\xBF\xAA\xC0\xB8\xB7\xCE \xBC\xD2\xC8\xAF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
TPacketGGTransfer pgg;
pgg.bHeader = HEADER_GG_TRANSFER;
strlcpy(pgg.szName, name.c_str(), sizeof(pgg.szName));
pgg.lX = ch->GetX();
pgg.lY = ch->GetY();
P2P_MANAGER::instance().Send(&pgg, sizeof(TPacketGGTransfer));
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s \xB4\xD4\xC0\xBB \xBC\xD2\xC8\xAF\xC7\xCF\xBF\xB4\xBD\xC0\xB4\xCF\xB4\xD9."), name.c_str());
// 군주 돈 삭감
CMonarch::instance().SendtoDBDecMoney(WarpPrice, ch->GetEmpire(), ch);
// 쿨타임 초기화
ch->SetMC(CHARACTER::MI_TRANSFER);
}
else
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xC0\xD4\xB7\xC2\xC7\xCF\xBD\xC5 \xC0\xCC\xB8\xA7\xC0\xBB \xB0\xA1\xC1\xF8 \xBB\xE7\xBF\xEB\xC0\xDA\xB0\xA1 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
}
return 0;
}
if (ch == tch)
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xC0\xDA\xBD\xC5\xC0\xBB \xBC\xD2\xC8\xAF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
if (tch->GetEmpire() != ch->GetEmpire())
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB4\xD9\xB8\xA5 \xC1\xA6\xB1\xB9 \xC0\xAF\xC0\xFA\xB4\xC2 \xBC\xD2\xC8\xAF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
if (!IsMonarchWarpZone(tch->GetMapIndex()))
{
ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT("\xC7\xD8\xB4\xE7 \xC1\xF6\xBF\xAA\xC0\xB8\xB7\xCE \xC0\xCC\xB5\xBF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
if (!IsMonarchWarpZone(ch->GetMapIndex()))
{
ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT("\xC7\xD8\xB4\xE7 \xC1\xF6\xBF\xAA\xC0\xB8\xB7\xCE \xBC\xD2\xC8\xAF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
tch->WarpSet(ch->GetX(), ch->GetY(), ch->GetMapIndex());
// 군주 돈 삭감
CMonarch::instance().SendtoDBDecMoney(WarpPrice, ch->GetEmpire(), ch);
// 쿨타임 초기화
ch->SetMC(CHARACTER::MI_TRANSFER);
return 0;
}
int monarch_notice(lua_State * L)
{
if (!lua_isstring(L, 1))
return 0;
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (ch == NULL)
return 0;
if (ch->IsMonarch() == false)
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB1\xBA\xC1\xD6\xB8\xB8\xC0\xCC \xBB\xE7\xBF\xEB \xB0\xA1\xB4\xC9\xC7\xD1 \xB1\xE2\xB4\xC9\xC0\xD4\xB4\xCF\xB4\xD9"));
return 0;
}
std::string strNotice = lua_tostring(L, 1);
if (strNotice.length() > 0)
SendMonarchNotice(ch->GetEmpire(), strNotice.c_str());
return 0;
}
int monarch_mob(lua_State * L)
{
if (!lua_isstring(L, 1))
return 0;
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (ch == NULL)
return 0;
char vnum[256];
strlcpy(vnum, lua_tostring(L, 1), sizeof(vnum));
do_monarch_mob(ch, vnum, 0, 0);
return 0;
}
EVENTFUNC(monarch_transfer2_event)
{
monarch_transfer2_event_info* info = dynamic_cast<monarch_transfer2_event_info*>(event->info);
if ( info == NULL )
{
quest_err( "monarch_transfer2_event> <Factor> Null pointer" );
return 0;
}
LPCHARACTER pTargetChar = CHARACTER_MANAGER::instance().FindByPID(info->dwTargetPID);
if (pTargetChar != NULL)
{
unsigned int qIndex = quest::CQuestManager::instance().GetQuestIndexByName("monarch_transfer");
if (qIndex != 0)
{
pTargetChar->SetQuestFlag("monarch_transfer.x", info->x);
pTargetChar->SetQuestFlag("monarch_transfer.y", info->y);
quest::CQuestManager::instance().Letter(pTargetChar->GetPlayerID(), qIndex, 0);
}
}
return 0;
}
int monarch_transfer2(lua_State* L)
{
if (lua_isstring(L, 1) == false) return 0;
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
if (ch == NULL) return false;
if (CMonarch::instance().IsMonarch(ch->GetPlayerID(), ch->GetEmpire()) == false)
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB1\xBA\xC1\xD6\xB8\xB8\xC0\xCC \xBB\xE7\xBF\xEB \xB0\xA1\xB4\xC9\xC7\xD1 \xB1\xE2\xB4\xC9\xC0\xD4\xB4\xCF\xB4\xD9"));
return 0;
}
if (ch->IsMCOK(CHARACTER::MI_TRANSFER) == false)
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%d \xC3\xCA\xB0\xA3 \xC4\xF0\xC5\xB8\xC0\xD3\xC0\xCC \xC0\xFB\xBF\xEB\xC1\xDF\xC0\xD4\xB4\xCF\xB4\xD9."), ch->GetMCLTime(CHARACTER::MI_TRANSFER));
return 0;
}
const int ciTransferCost = 10000;
if (CMonarch::instance().IsMoneyOk(ciTransferCost, ch->GetEmpire()) == false)
{
int NationMoney = CMonarch::instance().GetMoney(ch->GetEmpire());
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB1\xB9\xB0\xED\xBF\xA1 \xB5\xB7\xC0\xCC \xBA\xCE\xC1\xB7\xC7\xD5\xB4\xCF\xB4\xD9. \xC7\xF6\xC0\xE7 : %u \xC7\xCA\xBF\xE4\xB1\xDD\xBE\xD7 : %u"), NationMoney, ciTransferCost);
return 0;
}
std::string strTargetName = lua_tostring(L, 1);
LPCHARACTER pTargetChar = CHARACTER_MANAGER::instance().FindPC(strTargetName.c_str());
if (pTargetChar == NULL)
{
CCI* pCCI = P2P_MANAGER::instance().Find(strTargetName.c_str());
if (pCCI != NULL)
{
if (pCCI->bEmpire != ch->GetEmpire())
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB4\xD9\xB8\xA5 \xC1\xA6\xB1\xB9 \xC0\xAF\xC0\xFA\xB4\xC2 \xBC\xD2\xC8\xAF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
if (pCCI->bChannel != g_bChannel)
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s \xB4\xD4\xC0\xBA %d \xC3\xA4\xB3\xCE\xBF\xA1 \xC1\xA2\xBC\xD3\xC1\xDF\xC0\xD4\xB4\xCF\xB4\xD9. (\xC7\xF6\xC0\xE7 \xC3\xA4\xB3\xCE: %d)"),
strTargetName.c_str(), pCCI->bChannel, g_bChannel);
return 0;
}
if (!IsMonarchWarpZone(pCCI->lMapIndex))
{
ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT("\xC7\xD8\xB4\xE7 \xC1\xF6\xBF\xAA\xC0\xB8\xB7\xCE \xC0\xCC\xB5\xBF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
if (!IsMonarchWarpZone(ch->GetMapIndex()))
{
ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT("\xC7\xD8\xB4\xE7 \xC1\xF6\xBF\xAA\xC0\xB8\xB7\xCE \xBC\xD2\xC8\xAF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
TPacketMonarchGGTransfer packet;
packet.bHeader = HEADER_GG_MONARCH_TRANSFER;
packet.dwTargetPID = pCCI->dwPID;
packet.x = ch->GetX();
packet.y = ch->GetY();
P2P_MANAGER::instance().Send(&packet, sizeof(TPacketMonarchGGTransfer));
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xBC\xD2\xC8\xAF \xBF\xE4\xC3\xBB\xC0\xBB \xBA\xB8\xB3\xC2\xBD\xC0\xB4\xCF\xB4\xD9"));
CMonarch::instance().SendtoDBDecMoney(ciTransferCost, ch->GetEmpire(), ch);
ch->SetMC(CHARACTER::MI_TRANSFER);
}
else
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xC0\xD4\xB7\xC2\xC7\xCF\xBD\xC5 \xC0\xCC\xB8\xA7\xC0\xBB \xB0\xA1\xC1\xF8 \xBB\xE7\xBF\xEB\xC0\xDA\xB0\xA1 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
}
else
{
if (pTargetChar == ch)
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xC0\xDA\xBD\xC5\xC0\xBB \xBC\xD2\xC8\xAF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
if (pTargetChar->GetEmpire() != ch->GetEmpire())
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xB4\xD9\xB8\xA5 \xC1\xA6\xB1\xB9 \xC0\xAF\xC0\xFA\xB4\xC2 \xBC\xD2\xC8\xAF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
if (DISTANCE_APPROX(pTargetChar->GetX() - ch->GetX(), pTargetChar->GetY() - ch->GetY()) <= 5000)
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s \xB4\xD4\xC0\xBA \xB1\xD9\xC3\xB3\xBF\xA1 \xC0\xD6\xBD\xC0\xB4\xCF\xB4\xD9"), pTargetChar->GetName());
return 0;
}
if (!IsMonarchWarpZone(pTargetChar->GetMapIndex()))
{
ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT("\xC7\xD8\xB4\xE7 \xC1\xF6\xBF\xAA\xC0\xB8\xB7\xCE \xC0\xCC\xB5\xBF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
if (!IsMonarchWarpZone(ch->GetMapIndex()))
{
ch->ChatPacket (CHAT_TYPE_INFO, LC_TEXT("\xC7\xD8\xB4\xE7 \xC1\xF6\xBF\xAA\xC0\xB8\xB7\xCE \xBC\xD2\xC8\xAF\xC7\xD2 \xBC\xF6 \xBE\xF8\xBD\xC0\xB4\xCF\xB4\xD9."));
return 0;
}
monarch_transfer2_event_info* info = AllocEventInfo<monarch_transfer2_event_info>();
info->bHeader = HEADER_GG_MONARCH_TRANSFER;
info->dwTargetPID = pTargetChar->GetPlayerID();
info->x = ch->GetX();
info->y = ch->GetY();
event_create(monarch_transfer2_event, info, 1);
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("\xBC\xD2\xC8\xAF \xBF\xE4\xC3\xBB\xC0\xBB \xBA\xB8\xB3\xC2\xBD\xC0\xB4\xCF\xB4\xD9"));
CMonarch::instance().SendtoDBDecMoney(ciTransferCost, ch->GetEmpire(), ch);
ch->SetMC(CHARACTER::MI_TRANSFER);
return 0;
}
return 0;
}
void RegisterMonarchFunctionTable()
{
luaL_reg Monarch_functions[] =
{
{ "takemonarchmoney", takemonarchmoney },
{ "isguildmaster", is_guild_master },
{ "ismonarch", is_monarch },
{ "monarchbless", monarch_bless },
{ "monarchpowerup", monarch_powerup },
{ "monarchdefenseup", monarch_defenseup },
{ "spawnmob", spawn_mob },
{ "spawnguard", spawn_guard },
// { "frog_to_empire_money", frog_to_empire_money },
{ "warp", monarch_warp },
{ "transfer", monarch_transfer },
{ "transfer2", monarch_transfer2 },
{ "info", empire_info },
{ "notice", monarch_notice },
{ "monarch_mob", monarch_mob },
{ NULL, NULL }
};
CQuestManager::instance().AddLuaFunctionTable("oh", Monarch_functions);
}
}