local function _script_dir() local src = debug.getinfo(1, "S").source if type(src) ~= "string" then return "" end if src:sub(1, 1) == "@" then src = src:sub(2) end src = src:gsub("\\", "/") local dir = src:match("^(.*)/") if dir == nil then return "" end return dir .. "/" end local function _dofile_rel(name) return dofile(_script_dir() .. name) end local pet_store = _dofile_rel("pet_role_store.lua") local pet_plot_store = _dofile_rel("pet_plot_store.lua") local function _pet_get(RoleID) if pet_store.schemaReady() then return pet_store.getRole(RoleID) or pet_store.legacyGet(RoleID) end return pet_store.legacyGet(RoleID) end local function _pet_set(RoleID, patch) if pet_store.schemaReady() then return pet_store.setRole(RoleID, patch) end return pet_store.legacySet(RoleID, patch) end local creatur_spawn = 5810201 Petf1_exp = {} Petf1_exp[0] = 0 Petf1_exp[1] = 2264 Petf1_exp[2] = 4144 Petf1_exp[3] = 17000 Petf1_exp[4] = 33333 Petf1_exp[5] = 0 Petf1_level={} Petf1_level[1] = 2 Petf1_level[2] = 4 Petf1_level[3] = 6 Petf1_level[4] = 8 Petf1_level[5] = 10 seed_Petf1_exp = {} seed_Petf1_exp[5810202] = 20 seed_Petf1_exp[5810205] = 40 seed_Petf1_exp[5810208] = 60 seed_Petf1_exp[5810203] = 40 seed_Petf1_exp[5810206] = 60 seed_Petf1_exp[5810209] = 80 seed_Petf1_exp[5810204] = 80 seed_Petf1_exp[5810207] = 100 seed_Petf1_exp[5810210] = 120 seed_Petf1_exp_prem = {} seed_Petf1_exp_prem[5810202] = 30 seed_Petf1_exp_prem[5810205] = 60 seed_Petf1_exp_prem[5810208] = 90 seed_Petf1_exp_prem[5810203] = 60 seed_Petf1_exp_prem[5810206] = 90 seed_Petf1_exp_prem[5810209] = 120 seed_Petf1_exp_prem[5810204] = 120 seed_Petf1_exp_prem[5810207] = 150 seed_Petf1_exp_prem[5810210] = 180 kletka_pets = {} kletka_pets[5810204] = 6602102 kletka_pets[5810207] = 6602103 kletka_pets[5810210] = 6602104 local function _hungry_seconds_by_type(TargetTypeID) -- kura: 1h, feya: 2h, kabanchik: 5h if TargetTypeID == 5810202 or TargetTypeID == 5810203 or TargetTypeID == 5810204 then return 3600 elseif TargetTypeID == 5810205 or TargetTypeID == 5810206 or TargetTypeID == 5810207 then return 7200 elseif TargetTypeID == 5810208 or TargetTypeID == 5810209 or TargetTypeID == 5810210 then return 18000 end return 3600 end function cPetLunka_OnTalk(MapID, InstanceID, TargetID, TargetTypeID, RoleID, TalkIndex) if TalkIndex == -1 then -- Restore pet from SQL if this hole actually has a pet saved (after restart). if pet_plot_store.schemaReady() then local x0, y0, z0 = unit.GetPosition(MapID, InstanceID, TargetID) local row = pet_plot_store.getByCoord(RoleID, x0, y0, z0) if row ~= nil and (tonumber(row.PetTypeID) or 0) ~= 0 then local petType = tonumber(row.PetTypeID) or 0 local last = tonumber(row.LastFeedTime) or 0 map.MapDeleteCreature(MapID, InstanceID, TargetID) local pet = map.MapCreateCreature(MapID, InstanceID, petType, x0, y0, z0) cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 1, RoleID) cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 2, last) cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 3, 1) local hungrySeconds = _hungry_seconds_by_type(petType) local s = (last <= 0) and hungrySeconds or os.difftime(os.time(), last) if s >= hungrySeconds then unit.CancelBuff(MapID, InstanceID, pet, 9857101) unit.AddBuff(MapID, InstanceID, pet, 9857001, pet) else unit.CancelBuff(MapID, InstanceID, pet, 9857001) unit.AddBuff(MapID, InstanceID, pet, 9857101, pet) end return end end local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 20, 951199) --�������� �������� �� ������, ����� ���������� ��� �� ������ �������. ������������ �� ������ ���������� �� 5 �������. ��� ������ ��������� �������� ���������� ������, ���������� ��������� ��������. ��� ������ �������� ��������� 3-�� ������, �� ������ ������� ��� ������ ������� ��� ��������� ����� ������������� �������. msg.AddMsgEvent(MsgID, 24, TargetID) msg.AddMsgEvent(MsgID, 21, 11) msg.AddMsgEvent(MsgID, 1, 951200) --��������� �������� (100 �������) msg.AddMsgEvent(MsgID, 21, 12) msg.AddMsgEvent(MsgID, 1, 951201) --���-������� (300 �������) msg.AddMsgEvent(MsgID, 21, 13) msg.AddMsgEvent(MsgID, 1, 951202) --��������� �������� (500 �������) msg.AddMsgEvent(MsgID, 21, 10) msg.AddMsgEvent(MsgID, 1, 100002) --������ msg.DispatchRoleMsgEvent(RoleID, MsgID) elseif TalkIndex == 11 then local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 20, 951204) ---�� ������������� ������ ���������� ��������� �������� �� 100 �������? msg.AddMsgEvent(MsgID, 24, TargetID) msg.AddMsgEvent(MsgID, 21, 21) msg.AddMsgEvent(MsgID, 1, 100001) --�� msg.AddMsgEvent(MsgID, 21, 10) msg.AddMsgEvent(MsgID, 1, 100002) --������ msg.DispatchRoleMsgEvent(RoleID, MsgID) elseif TalkIndex == 12 then local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 20, 951205) ---�� ������������� ������ ���������� ���-������� �� 300 �������? msg.AddMsgEvent(MsgID, 24, TargetID) msg.AddMsgEvent(MsgID, 21, 22) msg.AddMsgEvent(MsgID, 1, 100001) --�� msg.AddMsgEvent(MsgID, 21, 10) msg.AddMsgEvent(MsgID, 1, 100002) --������ msg.DispatchRoleMsgEvent(RoleID, MsgID) elseif TalkIndex == 13 then local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 20, 951206) ---�� ������������� ������ ���������� ��������� �������� �� 500 �������? msg.AddMsgEvent(MsgID, 24, TargetID) msg.AddMsgEvent(MsgID, 21, 23) msg.AddMsgEvent(MsgID, 1, 100001) --�� msg.AddMsgEvent(MsgID, 21, 10) msg.AddMsgEvent(MsgID, 1, 100002) --������ msg.DispatchRoleMsgEvent(RoleID, MsgID) elseif TalkIndex == 21 then if role.GetRoleSilver(MapID, InstanceID, RoleID) < 1000000 then local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 20, 951207) --������������ ������ msg.AddMsgEvent(MsgID, 24, TargetID) msg.AddMsgEvent(MsgID, 21, 10) msg.AddMsgEvent(MsgID, 1, 100002) --������ msg.DispatchRoleMsgEvent(RoleID, MsgID) else role.DecRoleSilver(MapID, InstanceID, RoleID, 1000000, 452) local x,y,z = unit.GetPosition(MapID, InstanceID, TargetID) local pet = map.MapCreateCreature(MapID, InstanceID, 5810202, x, y, z) cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 1, RoleID) local cTime = os.time() cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 2, cTime) cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 3, 1) unit.CancelBuff(MapID, InstanceID, pet, 9857001) unit.AddBuff(MapID, InstanceID, pet, 9857101, pet) map.MapDeleteCreature(MapID, InstanceID, TargetID) if pet_plot_store.schemaReady() then pet_plot_store.setByCoord(RoleID, x, y, z, { PetTypeID = 5810202, LastFeedTime = cTime }) end end elseif TalkIndex == 22 then if role.GetRoleSilver(MapID, InstanceID, RoleID) < 3000000 then local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 20, 951207) --������������ ������ msg.AddMsgEvent(MsgID, 24, TargetID) msg.AddMsgEvent(MsgID, 21, 10) msg.AddMsgEvent(MsgID, 1, 100002) --������ msg.DispatchRoleMsgEvent(RoleID, MsgID) else role.DecRoleSilver(MapID, InstanceID, RoleID, 3000000, 452) local x,y,z = unit.GetPosition(MapID, InstanceID, TargetID) local pet = map.MapCreateCreature(MapID, InstanceID, 5810205, x, y, z) cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 1, RoleID) local cTime = os.time() cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 2, cTime) cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 3, 1) unit.CancelBuff(MapID, InstanceID, pet, 9857001) unit.AddBuff(MapID, InstanceID, pet, 9857101, pet) map.MapDeleteCreature(MapID, InstanceID, TargetID) if pet_plot_store.schemaReady() then pet_plot_store.setByCoord(RoleID, x, y, z, { PetTypeID = 5810205, LastFeedTime = cTime }) end end elseif TalkIndex == 23 then if role.GetRoleSilver(MapID, InstanceID, RoleID) < 5000000 then local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 20, 951207) --������������ ������ msg.AddMsgEvent(MsgID, 24, TargetID) msg.AddMsgEvent(MsgID, 21, 10) msg.AddMsgEvent(MsgID, 1, 100002) --������ msg.DispatchRoleMsgEvent(RoleID, MsgID) else role.DecRoleSilver(MapID, InstanceID, RoleID, 5000000, 452) local x,y,z = unit.GetPosition(MapID, InstanceID, TargetID) local pet = map.MapCreateCreature(MapID, InstanceID, 5810208, x, y, z) cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 1, RoleID) local cTime = os.time() cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 2, cTime) cre.SetCreatureScriptData(MapID, InstanceID, pet, 1, 3, 1) unit.CancelBuff(MapID, InstanceID, pet, 9857001) unit.AddBuff(MapID, InstanceID, pet, 9857101, pet) map.MapDeleteCreature(MapID, InstanceID, TargetID) if pet_plot_store.schemaReady() then pet_plot_store.setByCoord(RoleID, x, y, z, { PetTypeID = 5810208, LastFeedTime = cTime }) end end end end aux.RegisterCreatureEvent(5810201, 7, "cPetLunka_OnTalk") function cPetNew_OnTalk(MapID, InstanceID, TargetID, TargetTypeID, RoleID, TalkIndex) local cTime = os.time() local target_npc = {5810204, 5810207, 5810210} local lTime = 0 do local x0, y0, z0 = unit.GetPosition(MapID, InstanceID, TargetID) if pet_plot_store.schemaReady() then local row = pet_plot_store.getByCoord(RoleID, x0, y0, z0) if row ~= nil and row.LastFeedTime ~= nil then lTime = tonumber(row.LastFeedTime) or 0 end end if lTime == 0 then local lt = cre.GetCreatureScriptData(MapID, InstanceID, TargetID, 1, 2) lTime = tonumber(lt) or 0 end end local s = os.difftime(cTime, lTime) local hungrySeconds = _hungry_seconds_by_type(TargetTypeID) local rem = hungrySeconds - s if rem < 0 then rem = 0 end local remTotalMin = math.floor((rem + 59) / 60) local remH = math.floor(remTotalMin / 60) local remM = remTotalMin % 60 local seedowner = cre.GetCreatureScriptData(MapID, InstanceID, TargetID, 1, 1) local buff = cre.GetCreatureScriptData(MapID, InstanceID, TargetID, 1, 3) local x, y, z = unit.GetPosition(MapID, InstanceID, TargetID) local pr = _pet_get(RoleID) local zakaz = pr.zakazGi local zero = pr.petf1Level local zero1 = pr.petf2Level local zero2 = pr.petf3Level local farmlevel = zero % 10 local farmexp = pr.petf1Exp local farmexp1 = pr.petf2Exp local farmexp2 = pr.petf3Exp local zakazexp = pr.zakazExp if zero1 == 0 then _pet_set(RoleID, { petf2Level = 1 }) zero1 = 1 end if zakaz == 0 then _pet_set(RoleID, { zakazGi = 1 }) zakaz = 1 end if zero2 == 0 then _pet_set(RoleID, { petf3Level = 1 }) zero2 = 1 end if farmlevel == 0 then farmlevel = 1 _pet_set(RoleID, { petf1Level = 1, petf2Level = 1, petf3Level = 1 }) zero = 1 zero1 = 1 zero2 = 1 end -- Determine the next level experience required local function getNextLevelExp(level) return Petf1_exp[level] or 999999999999 end local needexp = getNextLevelExp(zero) local needexp1 = getNextLevelExp(zero1) local needexp2 = getNextLevelExp(zero2) if TalkIndex == -1 then if s >= hungrySeconds then unit.CancelBuff(MapID, InstanceID, TargetID, 9857101) local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 20, 951213) -- ��� ������� �������. ���������? msg.AddMsgEvent(MsgID, 24, TargetID) msg.AddMsgEvent(MsgID, 9, 0) -- : hours (time until feeding) (already hungry) msg.AddMsgEvent(MsgID, 9, 0) -- : minutes msg.AddMsgEvent(MsgID, 21, 11) msg.AddMsgEvent(MsgID, 1, 951214) -- ��������� if TargetTypeID == target_npc[1] or TargetTypeID == target_npc[2] or TargetTypeID == target_npc[3] then msg.AddMsgEvent(MsgID, 21, 12) msg.AddMsgEvent(MsgID, 1, 951216) -- ������� �������� end msg.AddMsgEvent(MsgID, 21, 10) msg.AddMsgEvent(MsgID, 1, 100002) -- ������ msg.DispatchRoleMsgEvent(RoleID, MsgID) unit.AddBuff(MapID, InstanceID, TargetID, 9857001, TargetID) else if buff == 0 then unit.AddBuff(MapID, InstanceID, TargetID, 9857101, TargetID) cre.SetCreatureScriptData(MapID, InstanceID, TargetID, 1, 3, 1) end unit.CancelBuff(MapID, InstanceID, TargetID, 9857001) local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 20, 951215) -- ��� ������� ��� msg.AddMsgEvent(MsgID, 24, TargetID) msg.AddMsgEvent(MsgID, 9, remH) -- : hours until hungry msg.AddMsgEvent(MsgID, 9, remM) -- : minutes until hungry if TargetTypeID == target_npc[1] or TargetTypeID == target_npc[2] or TargetTypeID == target_npc[3] then msg.AddMsgEvent(MsgID, 21, 12) msg.AddMsgEvent(MsgID, 1, 951216) -- ������� �������� end msg.AddMsgEvent(MsgID, 21, 10) msg.AddMsgEvent(MsgID, 1, 100002) -- ������ msg.DispatchRoleMsgEvent(RoleID, MsgID) end elseif TalkIndex == 12 then local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 20, 951217) -- ��� ������� �������. ���������? msg.AddMsgEvent(MsgID, 24, TargetID) msg.AddMsgEvent(MsgID, 21, 13) msg.AddMsgEvent(MsgID, 1, 951216) -- ������� �������� msg.AddMsgEvent(MsgID, 21, 10) msg.AddMsgEvent(MsgID, 1, 100002) -- ������ msg.DispatchRoleMsgEvent(RoleID, MsgID) elseif TalkIndex == 13 then if role.GetRoleItemNum(RoleID, 6602101) < 1 then local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 20, 951218) -- � ��� ��� ������. msg.AddMsgEvent(MsgID, 24, TargetID) msg.AddMsgEvent(MsgID, 21, 10) msg.AddMsgEvent(MsgID, 1, 100002) -- ������ msg.DispatchRoleMsgEvent(RoleID, MsgID) else map.MapDeleteCreature(MapID, InstanceID, TargetID) local hole = map.MapCreateCreature(MapID, InstanceID, 5810201, x, y, z) role.RemoveFromRole(MapID, InstanceID, RoleID, 6602101, 1, 101) if TargetTypeID == target_npc[1] then _pet_set(RoleID, { petf1Level = 1, petf1Exp = 0 }) elseif TargetTypeID == target_npc[2] then _pet_set(RoleID, { petf2Level = 1, petf2Exp = 0 }) elseif TargetTypeID == target_npc[3] then _pet_set(RoleID, { petf3Level = 1, petf3Exp = 0 }) end role.AddRoleItem(MapID, InstanceID, RoleID, kletka_pets[TargetTypeID], 1, 6, 8, 420) if pet_plot_store.schemaReady() then pet_plot_store.setByCoord(RoleID, x, y, z, { PetTypeID = 0, LastFeedTime = 0 }) end end elseif TalkIndex == 11 then local num = role.GetRoleSilver(MapID, InstanceID, RoleID) local num2 = role.GetRoleSilver(MapID, InstanceID, RoleID) if num > 19999 or num2 > 19999 then if num2 > 19999 then role.DecRoleSilver(MapID, InstanceID, RoleID, 20000, 452) end local x, y, z = unit.GetPosition(MapID, InstanceID, TargetID) local seedowner = cre.GetCreatureScriptData(MapID, InstanceID, TargetID, 1, 1) -- Update experience and level local function updateExperience(currentExp, currentLevel, expGained, nextLevelExp) currentExp = currentExp + expGained while currentExp >= nextLevelExp do currentExp = currentExp - nextLevelExp currentLevel = currentLevel + 1 nextLevelExp = getNextLevelExp(currentLevel) end return currentExp, currentLevel, nextLevelExp end local prem = role.GetRoleAttValue(MapID, InstanceID, RoleID, 91) local expGained = prem < 3 and seed_Petf1_exp[TargetTypeID] or seed_Petf1_exp_prem[TargetTypeID] if TargetTypeID == 5810202 or TargetTypeID == 5810203 or TargetTypeID == 5810204 then farmexp, zero, needexp = updateExperience(farmexp, zero, expGained, needexp) _pet_set(RoleID, { petf1Exp = farmexp, petf1Level = zero }) role.AddRoleItem(MapID, InstanceID, RoleID, 6602105, 1, 6, 8, 420) local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 13, 1) msg.AddMsgEvent(MsgID, 1, 951232) -- ���� ������� �� , �������� �� ���������� ������ ��������� msg.AddMsgEvent(MsgID, 9, expGained) msg.AddMsgEvent(MsgID, 9, needexp - farmexp) msg.DispatchRoleMsgEvent(RoleID, MsgID) -- Transform the pet based on its level local ddddwwww = 5810202 if zero == 2 then ddddwwww = 5810203 elseif zero == 3 then ddddwwww = 5810204 end if TargetTypeID ~= ddddwwww then map.MapDeleteCreature(MapID, InstanceID, TargetID) local newPet = map.MapCreateCreature(MapID, InstanceID, ddddwwww, x, y, z) TargetID = newPet TargetTypeID = ddddwwww end elseif TargetTypeID == 5810205 or TargetTypeID == 5810206 or TargetTypeID == 5810207 then farmexp1, zero1, needexp1 = updateExperience(farmexp1, zero1, expGained, needexp1) _pet_set(RoleID, { petf2Exp = farmexp1, petf2Level = zero1 }) role.AddRoleItem(MapID, InstanceID, RoleID, 6602106, 1, 6, 8, 420) local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 13, 1) msg.AddMsgEvent(MsgID, 1, 951232) -- ���� ������� �� , �������� �� ���������� ������ ��������� msg.AddMsgEvent(MsgID, 9, expGained) msg.AddMsgEvent(MsgID, 9, needexp1 - farmexp1) msg.DispatchRoleMsgEvent(RoleID, MsgID) -- Transform the pet based on its level local ddddwwww = 5810205 if zero1 == 2 then ddddwwww = 5810206 elseif zero1 == 3 then ddddwwww = 5810207 end if TargetTypeID ~= ddddwwww then map.MapDeleteCreature(MapID, InstanceID, TargetID) local newPet = map.MapCreateCreature(MapID, InstanceID, ddddwwww, x, y, z) TargetID = newPet TargetTypeID = ddddwwww end elseif TargetTypeID == 5810208 or TargetTypeID == 5810209 or TargetTypeID == 5810210 then farmexp2, zero2, needexp2 = updateExperience(farmexp2, zero2, expGained, needexp2) _pet_set(RoleID, { petf3Exp = farmexp2, petf3Level = zero2 }) role.AddRoleItem(MapID, InstanceID, RoleID, 6602107, 1, 6, 8, 420) local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 13, 1) msg.AddMsgEvent(MsgID, 1, 951232) -- ���� ������� �� , �������� �� ���������� ������ ��������� msg.AddMsgEvent(MsgID, 9, expGained) msg.AddMsgEvent(MsgID, 9, needexp2 - farmexp2) msg.DispatchRoleMsgEvent(RoleID, MsgID) -- Transform the pet based on its level local ddddwwww = 5810208 if zero2 == 2 then ddddwwww = 5810209 elseif zero2 == 3 then ddddwwww = 5810210 end if TargetTypeID ~= ddddwwww then map.MapDeleteCreature(MapID, InstanceID, TargetID) local newPet = map.MapCreateCreature(MapID, InstanceID, ddddwwww, x, y, z) TargetID = newPet TargetTypeID = ddddwwww end end zakazexp = zakazexp + (prem < 3 and seed_Petf1_exp[TargetTypeID] or seed_Petf1_exp_prem[TargetTypeID]) _pet_set(RoleID, { zakazExp = zakazexp }) unit.CancelBuff(MapID, InstanceID, TargetID, 9857001) unit.AddBuff(MapID, InstanceID, TargetID, 9857101, TargetID) -- start cooldown timer (prevents immediate repeat and prevents spawning a new hole while pet is growing) cre.SetCreatureScriptData(MapID, InstanceID, TargetID, 1, 2, cTime) cre.SetCreatureScriptData(MapID, InstanceID, TargetID, 1, 3, 1) if pet_plot_store.schemaReady() then pet_plot_store.setByCoord(RoleID, x, y, z, { PetTypeID = TargetTypeID, LastFeedTime = cTime }) end else local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 13, 1) msg.AddMsgEvent(MsgID, 1, 951207) -- ������������ ������ msg.DispatchRoleMsgEvent(RoleID, MsgID) end end end aux.RegisterCreatureEvent(5810202, 7, "cPetNew_OnTalk") aux.RegisterCreatureEvent(5810203, 7, "cPetNew_OnTalk") aux.RegisterCreatureEvent(5810204, 7, "cPetNew_OnTalk") aux.RegisterCreatureEvent(5810205, 7, "cPetNew_OnTalk") aux.RegisterCreatureEvent(5810206, 7, "cPetNew_OnTalk") aux.RegisterCreatureEvent(5810207, 7, "cPetNew_OnTalk") aux.RegisterCreatureEvent(5810208, 7, "cPetNew_OnTalk") aux.RegisterCreatureEvent(5810209, 7, "cPetNew_OnTalk") aux.RegisterCreatureEvent(5810210, 7, "cPetNew_OnTalk")