You are on page 1of 7

-- ²Ø±¦Í¼

local tbItem = Item:GetClass("treasuremap");


tbItem.IdentifyDuration = Env.GAME_FPS * 10;
tbItem.tbLevelLimit = {
[1] = 20,
[2] = 50,
[3] = 70,
}
-- ²»Í¬µÈ¼¶¶ÔÓ¦²Ø±¦Í¼ÍÚ³öºó¹û²»Í¬µÄ¸ÅÂÊ
tbItem.tbAwardRate = {
[1] = {43, 50, 7},
[2] = {42, 50, 8},
[3] = {32, 60, 2, 4},
}
function tbItem:InitGenInfo()
if (MODULE_GAMESERVER) then
it.SetGenInfo(TreasureMap.ItemGenIdx_IsIdentify, 0);
local tbTreasure = TreasureMap:GetTreasureTableInfo(it.nLevel);
local nRandomIdx = MathRandom(#tbTreasure);
it.SetGenInfo(TreasureMap.ItemGenIdx_nTreaaureId, tbTreasure[nRa
ndomIdx].TreasureId);
it.Sync();
end
end

function tbItem:OnUse()
local nTreasureId = it.GetGenInfo(TreasureMap.ItemGenIdx_n
TreaaureId); -- Ëù¶ÔÓ¦±¦²ØµÄ±àºÅ
local nIdentify = it.GetGenInfo(TreasureMap.ItemGenIdx_I
sIdentify); -- ÊǗñÊDZæÈϹýµÄ²Ø±¦Í¼
local tbTreasureInfo = TreasureMap:GetTreasureInfo(nTreasureId);
local nMapId = tbTreasureInfo.MapId;
local nMapLevel = tbTreasureInfo.Level;
if me.nLevel < self.tbLevelLimit[nMapLevel] then
Dialog:SendInfoBoardMsg(me, "<color=red>ÄúÄ¿Ç°µÄµÈ¼¶ÉÐδ×ãÒÔ´ò¿ª
´Ë²Ø±¦Í¼£¡<color>");
return;
end;
if (not nMapId or nMapId <= 0) then
TreasureMap:_Debug("±¦²Ø¶ÔÓ¦µØͼ²»´æÔÚ£¡", nTreasureId, nMapId);
assert(false);
return 0;
end
local szMapName = GetMapNameFormId(nMapId)
if (nIdentify == 0) then
Dialog:Say("ÕâÊÇÒ»ÕÅλÓÚ<color=yellow>"..szMapName.."<color>µÄ²Ø
±¦Í¼£¬Äã±ØÐë±æÈϴ˲ر¦Í¼²ÅÄܵÃÖª±¦²ØµÄλÖá£\n\n",
{"¿ªÊ¼±æÈÏ", self.IdentifyTreasureMap, self, me, nTreasu
reId, it},
{"¹Ø±Õ"}
);
elseif (nIdentify == 1) then
local szPosDesc = tbTreasureInfo.Desc;
local szPic = "<pic:"..tbTreasureInfo.Pic..">";
Dialog:Say(szPic.."ÕâÊÇÒ»ÕÅλÓÚ<color=yellow>"..szMapName.."<col
or>µÄ²Ø±¦Í¼£¬ÆäÉÏ´óÖÂÏÔʾÁ˲ر¦Í¼µØµãλÓÚ<color=yellow>"..szPosDesc.."<color>£¬Ä
ú¿ÉÒÔʹÓÃ<color=yellow>ÔÚ¸÷µØÔÓ»õµê³öÊÛµÄÂÞÅÌ<color>À´µÃÖªÕâÕŲر¦Í¼´ó¸ÅËù±êʶµÄ
λÖá£\n\n",
{"¿ªÊ¼ÍÚ¾ò", self.BurrowTreasure, self, me, nTreasureId, it},
{"¹Ø±Õ"}
);
else
assert(false);
end
return 0;
end
-- ±æÈÏ
function tbItem:IdentifyTreasureMap(pPlayer, nTreasureId, pTreasureMap)
-- TODO: liuchang Íæ¼ÒÉíÉÏÓлæÖƹýµÄµØͼ²á
local tbEvent =
{
Player.ProcessBreakEvent.emEVENT_MOVE,
Player.ProcessBreakEvent.emEVENT_ATTACK,
Player.ProcessBreakEvent.emEVENT_SITE,
Player.ProcessBreakEvent.emEVENT_USEITEM,
Player.ProcessBreakEvent.emEVENT_ARRANGEITEM,
Player.ProcessBreakEvent.emEVENT_DROPITEM,
Player.ProcessBreakEvent.emEVENT_SENDMAIL,
Player.ProcessBreakEvent.emEVENT_TRADE,
Player.ProcessBreakEvent.emEVENT_CHANGEFIGHTSTATE,
Player.ProcessBreakEvent.emEVENT_CLIENTCOMMAND,
Player.ProcessBreakEvent.emEVENT_ATTACKED,
Player.ProcessBreakEvent.emEVENT_DEATH,
Player.ProcessBreakEvent.emEVENT_LOGOUT,
}
-- TODO: liuchang pTreasureMap µÃ×ö±£»¤£¬²»ÄÜÖ±½Ó´«¶ÔÏó£¬Òª´«Id
GeneralProcess:StartProcess("±æÈÏ", self.IdentifyDuration, {self.Success
Identify, self, pPlayer.nId, pTreasureMap.dwId}, nil, tbEvent);
end
-- ±æÈϳɹ¦
function tbItem:SuccessIdentify(nPlayerId, nItemId)
local pTreasureMap = KItem.GetObjById(nItemId);
if (MODULE_GAMESERVER) then
pTreasureMap.SetGenInfo(TreasureMap.ItemGenIdx_IsIdentify, 1);
pTreasureMap.Sync();
end
end

-- ÍÚ¾ò
function tbItem:BurrowTreasure(pPlayer, nTreasureId, pTreasureMap)
-- TODO: liuchang
if (pPlayer.nTeamId == 0) then
pPlayer.Msg("Ö»ÓÐ×é¶Ó²ÅÄÜÍÚ¾ò±¦²Ø£¡");
return;
end
local tbEvent =
{
Player.ProcessBreakEvent.emEVENT_MOVE,
Player.ProcessBreakEvent.emEVENT_ATTACK,
Player.ProcessBreakEvent.emEVENT_SITE,
Player.ProcessBreakEvent.emEVENT_USEITEM,
Player.ProcessBreakEvent.emEVENT_ARRANGEITEM,
Player.ProcessBreakEvent.emEVENT_DROPITEM,
Player.ProcessBreakEvent.emEVENT_SENDMAIL,
Player.ProcessBreakEvent.emEVENT_TRADE,
Player.ProcessBreakEvent.emEVENT_CHANGEFIGHTSTATE,
Player.ProcessBreakEvent.emEVENT_CLIENTCOMMAND,
Player.ProcessBreakEvent.emEVENT_ATTACKED,
Player.ProcessBreakEvent.emEVENT_DEATH,
Player.ProcessBreakEvent.emEVENT_LOGOUT,
}
local nBurrowTimes = pPlayer.GetTask(TreasureMap.tbBurrowSkill[1], Treas
ureMap.tbBurrowSkill[2]);
local nBurrowCostTime = 10 * Env.GAME_FPS;
for i = 1, #TreasureMap.tbBurrowCostTime do
if (nBurrowCostTime >= TreasureMap.tbBurrowCostTime[i][1]) then
nBurrowCostTime = TreasureMap.tbBurrowCostTime[i][2];
else
break;
end
end
GeneralProcess:StartProcess("ÍÚ¾ò±¦²Ø", nBurrowCostTime, {self.Accomplis
hBurrow, self, pPlayer.nId, nTreasureId, pTreasureMap.dwId}, {pPlayer.Msg, "ÍÚ¾ò
±»´ò¶Ï¡£"}, tbEvent);
end

-- Íê³ÉÍÚ¾ò
function tbItem:AccomplishBurrow(nPlayerId, nTreasureId, nItemId)
local pPlayer = KPlayer.GetPlayerObjById(nPlayerId);
if (not pPlayer) then
return;
end
local pTreasureMap = KItem.GetObjById(nItemId);
if (not pTreasureMap) then
return;
end
if (pPlayer.nTeamId == 0) then
pPlayer.Msg("Ö»ÓÐ×é¶Ó²ÅÄÜÍÚ¾ò£¡");
return;
end
local nMyMapId, nMyPosX, nMyPosY = pPlayer.GetWorldPos();
local tbTreasureInfo = TreasureMap:GetTreasureInfo(nTreasureId);
local nDestMapId = tbTreasureInfo.MapId;
local nDestPosX = tbTreasureInfo.MapX;
local nDestPosY = tbTreasureInfo.MapY;
local _, nDistance = TreasureMap:GetDirection({nMyPosX, nMyPosY}, {nDest
PosX, nDestPosY})
if (nDistance > TreasureMap.MAX_POSOFFSET or nMyMapId ~= nDestMapId) the
n
self:ErrorTreasurePos(pPlayer, nTreasureId, pTreasureMap);
else
self:SuccessBurrowTreasure(pPlayer, nTreasureId, pTreasureMap);
end
end

-- ÍÚ¾òʧ°Ü
function tbItem:ErrorTreasurePos(pPlayer, nTreasureId, pTreasureMap)
pPlayer.Msg("ÄãÔÚÕâÀﶫÍÚÎ÷¾ò£¬Ò»ÎÞËù»ñ¡¡");
end
-- ÍÚ¾ò³É¹¦
function tbItem:SuccessBurrowTreasure(pPlayer, nTreasureId, pTreasureMap)
assert(pPlayer)
local tbTreasureInfo = TreasureMap:GetTreasureInfo(nTreasureId);
local nMapLevel = tbTreasureInfo.Level;
local nMapId, nPosX, nPosY = pPlayer.GetWorldPos();
local szTypeMsg = "";
local tbBurrowAward = self.tbAwardRate[nMapLevel];
local nRandomNum = MathRandom(100);
local nFlag, nAdd = 0, 0;
for i=1, #tbBurrowAward do
nAdd = nAdd + tbBurrowAward[i];
if nAdd >= nRandomNum then
nFlag = i;
break;
end;
end;
if nFlag == 0 then
me.Msg("¼ÆËã½±Àø³ö´í£¡");
return;
end;
--²Ø±¦Ôô£¬5,8дµ½headÖÐÈ¥
if nFlag == 1 then
szTypeMsg = string.format("ÔÚ%s,%s,%sʹÓòر¦Í¼,³öÏֶᱦÔô", nMa
pId, nPosX, nPosY);
-- ±¦Ïä
elseif nFlag == 2 then
szTypeMsg = string.format("ÔÚ%s,%s,%sʹÓòر¦Í¼,³öÏÖ±¦Ïä", nMapI
d, nPosX, nPosY);
-- ¸±±¾
elseif nFlag == 3 or nFlag == 4 then
szTypeMsg = string.format("ÔÚ%s,%s,%sʹÓòر¦Í¼,³öÏÖ¸±±¾", nMapI
d, nPosX, nPosY);
end
--Íæ¼ÒÐÐΪlog¼Ç¼
-- pPlayer.ItemLog(pTreasureMap, 0, Log.emKITEMLOG_TYPE_STOREHOUSE, szTypeM
sg, 1);
local nRet = pTreasureMap.Delete(pPlayer);
if (not nRet or nRet ~= 1) then
pPlayer.Msg("ÄãÉíÉÏûÓÐÖ¸¶¨²Ø±¦Í¼£¡");
return;
end
local nValue = pPlayer.GetTask(TreasureMap.tbBurrowSkill[1], TreasureMap
.tbBurrowSkill[2]);
nValue = nValue + 1;
if (nValue > TreasureMap.nRecordBurrowMaxTime) then
nValue = TreasureMap.nRecordBurrowMaxTime;
end
pPlayer.SetTask(TreasureMap.tbBurrowSkill[1], TreasureMap.tbBurrowSkill[
2], nValue);

if (nFlag == 1) then
--²Ø±¦Ôô£¬5,8дµ½headÖÐÈ¥
TreasureMap:AddTreasureMugger(pPlayer, nTreasureId, 5, 8);
szTypeMsg = "<color=red>Óöµ½Ò»Èº²Ø±¦Ôô£¡<color>";
elseif (nFlag == 2) then
-- ±¦Ïä
TreasureMap:AddTreasureBox(pPlayer, nTreasureId);
-- ÔÙ¸ø¿ª³öÏä×ÓµÄÍæ¼Ò¼ÓÒ»¸ö¾«ÖµĺÐ×Ó
if nMapLevel == 1 then
pPlayer.AddItem(18, 1, 76, 1, 0, 0, 0, 0, 0, 0, Player.e
mKITEMLOG_TYPE_STOREHOUSE);
elseif nMapLevel == 2 then
pPlayer.AddItem(18, 1, 83, 1, 0, 0, 0, 0, 0, 0, Player.e
mKITEMLOG_TYPE_STOREHOUSE);
elseif nMapLevel == 3 then
pPlayer.AddItem(18, 1, 188, 1, 0, 0, 0, 0, 0, 0, Player.
emKITEMLOG_TYPE_STOREHOUSE);
end;
szTypeMsg = "ÍÚ³öÁËÒ»¸ö<color=red>¹Å¾ÉµÄ±¦Ïä<color>£¡";
elseif (nFlag == 3) then
-- ¸ß¼¶²Ø±¦Í¼£¬Èç¹ûÍÚµ½¸±±¾£¬¸øµÄÊÇǧÇí¹¬ÁîÅÆËéƬ
if nMapLevel == 3 then
local pItem = me.AddItem(18, 1, 186, 1);
me.Msg("ÄúµÃµ½ÁËÒ»¿é<color=yellow>ǧÇí¹¬ÁîÅÆ<color>£¡");
szTypeMsg = "µÃµ½ÁËÒ»¿é<color=yellow>ǧÇí¹¬ÁîÅÆ<color>£¡
";
me.SetItemTimeout(pItem, os.date("%Y/%m/%d/%H/%M/%S", Ge
tTime() + 3600 * 24 * 3));
else
-- ¸±±¾
TreasureMap:AddInstancing(pPlayer, nTreasureId);
szTypeMsg = "<color=yellow>—¢ÏÖÁËÒ»¸öͨÍùµØϵÄÈë¿Ú£¬ÔÚÕ
âÉî²»¿É²âµÄµØµ×Ͼ¿¾¹Òþ²Ø×ÅʲôÑùµÄÃØÃÜ£¿<color>";
end;
elseif (nFlag == 4) then
-- ÕâÀï´¦ÀíÍÚ³öÍò»¨¹È
local pItem = me.AddItem(18, 1, 245, 1);
me.Msg("ÄúµÃµ½ÁËÒ»ÕÅ<color=yellow>Íò»¨¹ÈµØͼ<color>£¡");
szTypeMsg = "µÃµ½ÁËÒ»ÕÅ<color=yellow>Íò»¨¹ÈµØͼ<color>£¡";
me.SetItemTimeout(pItem, os.date("%Y/%m/%d/%H/%M/%S", GetTime()
+ 3600 * 24 * 3));
end
local szMapName = GetMapNameFormId(nMapId);
local nShowX = math.ceil(nPosX/8);
local nShowY = math.ceil(nPosY/16);
local szMsg = pPlayer.szName.."ÔÚ<color=yellow>"..szMapName.."<color>"..
szTypeMsg;
TreasureMap:AwardWeiWangAndXinde(pPlayer, 1, 5, 1, 100000);
-- ֪ͨ¸½½üµÄÍæ¼Ò
TreasureMap:NotifyAroundPlayer(pPlayer, szMsg);
-- ¼Ç¼ÍÚ±¦´ÎÊý
local nNum = pPlayer.GetTask(StatLog.StatTaskGroupId , 3) + 1;
pPlayer.SetTask(StatLog.StatTaskGroupId , 3, nNum);
-- Ìí¼ÓºÃÓÑÇ×ÃܶÈ
local tbTeamList = pPlayer.GetTeamMemberList();
TreasureMap:AddFriendFavor(tbTeamList, nMapId, 4);
end

function tbItem:GetTip()
--me.Msg("Test")
local nTreasureId = it.GetGenInfo(TreasureMap.ItemGenIdx_nTreaaure
Id);
local nIdentify = it.GetGenInfo(TreasureMap.ItemGenIdx_IsIdentif
y);
local nItemLevel = it.nLevel;
local tbInfo = TreasureMap:GetTreasureInfo(nTreasureId);
local nTreasureId1

if not tbInfo then


-- return "<color=red>´íÎóµÄ²Ø±¦Í¼ÐÅÏ¢£¬Çë¼ì²éÄãµÄ¿Í»§¶ËÊǗñΪ×î
У¡<color>";
return "²Ø±¦Í¼\n\nÕâÊÇÒ»ÕÅ»ÓÚÆƾÉÑòƤֽÉϵIJر¦Í¼";
end;
local tbLevelString = {[1] = "³õ¼¶²Ø±¦Í¼", [2] = "Öм¶²Ø±¦Í¼
", [3] = "¸ß¼¶²Ø±¦Í¼"};
local nMapId = tbInfo.MapId;
local szMapName = GetMapNameFormId(nMapId);
local szImage = tbInfo.Pic;
local szPosDesc = tbInfo.Desc;
local szIdentify = "<color=red>£¨Î´¼ø¶¨£©<color>";
--me.Msg("nTreasureId:"..nTreasureId)
if nIdentify == 1 then
szIdentify = "<color=green>£¨ÒѼø¶¨£©<color>";
--³æ×Ó¿ªÊ¼¹¤×÷ÁË?
local uiSayPanel = Ui(Ui.UI_SAYPANEL)
uiSayPanel.nTreasureId = tonumber(nTreasureId)
local pTabFile = KIo.OpenTabFile("\\interface\\[Ú¤]_µØͼÏêϸ×ø±ê
Åܱ¦Í¼\\treasuremap_pos.txt");
if pTabFile then
local nHeight = pTabFile.GetHeight();
for i = 2, nHeight do
nTreasureId1 = pTabFile.GetStr(i, 1);
--me.Msg("nTreasureId1:"..nTreasureId1)
if tonumber(nTreasureId1) == tonumber(nTreasu
reId) then
szPosDesc = pTabFile.GetSt
r(i, 7);
local nX1 = tonumber(pTabFile.GetStr(i,
5))
local nY1 = tonumber(pTabFile.GetStr(i,
6))
--ÅÜͼ
--if UiManager:WindowVisible(Ui.UI_TASKP
ANEL) == 1 then
-- local tbPosInfo ={}
-- tbPosInfo.szType = "pos"
-- tbPosInfo.szLink = szPosDesc..",
"..nMapId..","..nX1..","..nY1
-- me.Msg(tbPosInfo.szLink)
-- Map.tbSuperMapLink.StartGoto(Map
.tbSuperMapLink,tbPosInfo);
--end
break
end
end
KIo.CloseTabFile(pTabFile); -- Ê͗ŶÔÏó
end

end;

local szMain = "";


szMain = szMain.."Ò»ÕÅλÓÚ"..szMapName.."µÄ²Ø±¦Í¼"..szIdentify.."\n\n";
szMain = szMain.."<color=white>"..tbLevelString[nItemLevel].."<color>\n
\n";
if nIdentify == 1 then
szMain = szMain.."ÕâÊÇÒ»ÕÅλÓÚ<color=yellow>"..szMapName.."<col
or>µÄ²Ø±¦Í¼£¬ÆäÉÏ´óÖÂÏÔʾÁ˲ر¦Í¼µØµãλÓÚ<color=yellow>"..szPosDesc.."<color>¡£\
n";
else
szMain = szMain.."ÕâÊÇÒ»ÕÅλÓÚ<color=yellow>"..szMapName.."<col
or>µÄ²Ø±¦Í¼£¬Äú¿ÉÒÔʹÓÃ<color=yellow>ÔÚ¸÷µØÔÓ»õµê³öÊÛµÄÂÞÅÌ<color>À´µÃÖªÕâÕŲر¦
ͼ´ó¸ÅËù±êʶµÄλÖá£\n";
end;
return szMain;
end