forked from metin2/server
399 lines
11 KiB
Plaintext
399 lines
11 KiB
Plaintext
quest event_easter_2012 begin
|
||
state start begin
|
||
function is_running()
|
||
return (game.get_event_flag("easter_drop") > 0)
|
||
end
|
||
function has_rabbit()
|
||
return (game.get_event_flag("easter_rabbit") > 0)
|
||
end
|
||
function get_settings()
|
||
local spawnPromille = game.get_event_flag("easter_spawn_chance")
|
||
if spawnPromille <= 0 then
|
||
spawnPromille = 5
|
||
end
|
||
local magicEggPercent = game.get_event_flag("easter_magicegg_chance")
|
||
if magicEggPercent <= 0 then
|
||
magicEggPercent = 5
|
||
end
|
||
return {
|
||
["eggvnums"] = {
|
||
["first"] = 50160,
|
||
["last"] = 50179,
|
||
},
|
||
["magicegg"] = {
|
||
["vnum"] = 71150,
|
||
["pct"] = magicEggPercent,
|
||
},
|
||
["metins"] = {
|
||
[8041] = 10,
|
||
[8042] = 20,
|
||
[8043] = 30,
|
||
[8044] = 40,
|
||
[8045] = 50,
|
||
[8046] = 60,
|
||
[8047] = 70,
|
||
[8048] = 80,
|
||
[8049] = 90,
|
||
[8050] = 95
|
||
},
|
||
["max_level_difference"] = 15,
|
||
["rabbit"] = 30129,
|
||
["spawn"] = {
|
||
["kill"] = 100,
|
||
["cooldown"] = 60,
|
||
["promille"] = spawnPromille,
|
||
["maps"] = {
|
||
[1] = {
|
||
[10] = {1, 3, 4, 69},
|
||
[20] = {1, 3, 4, 5, 69},
|
||
[30] = {3, 4, 5, 63, 64, 108},
|
||
[40] = {63, 64, 108, 65},
|
||
[50] = {63, 64, 108, 65, 61, 107, 109},
|
||
[60] = {65, 61, 107, 109, 62, 67, 69, 71, 70},
|
||
[70] = {65, 61, 62, 67, 69, 71, 70, 68, 72, 73},
|
||
[80] = {67, 69, 70, 68, 72},
|
||
[90] = {70, 68, 72, 73},
|
||
[95] = {70, 68, 73},
|
||
},
|
||
[2] = {
|
||
[10] = {21, 23, 24, 69},
|
||
[20] = {21, 23, 24, 25, 69},
|
||
[30] = {23, 24, 25, 63, 64, 108},
|
||
[40] = {63, 64, 108, 65},
|
||
[50] = {63, 64, 108, 65, 61, 107, 109},
|
||
[60] = {65, 61, 107, 109, 62, 67, 69, 71, 70},
|
||
[70] = {65, 61, 62, 67, 69, 71, 70, 68, 72, 73},
|
||
[80] = {67, 69, 70, 68, 72},
|
||
[90] = {70, 68, 72, 73},
|
||
[95] = {70, 68, 73},
|
||
|
||
},
|
||
[3] = {
|
||
[10] = {41, 43, 44, 69},
|
||
[20] = {41, 43, 44, 45, 69},
|
||
[30] = {43, 44, 45, 63, 64, 108},
|
||
[40] = {63, 64, 108, 65},
|
||
[50] = {63, 64, 108, 65, 61, 107, 109},
|
||
[60] = {65, 61, 107, 109, 62, 67, 69, 71, 70},
|
||
[70] = {65, 61, 62, 67, 69, 71, 70, 68, 72, 73},
|
||
[80] = {67, 69, 70, 68, 72},
|
||
[90] = {70, 68, 72, 73},
|
||
[95] = {70, 68, 73},
|
||
},
|
||
},
|
||
},
|
||
}
|
||
end
|
||
function get_reward_table_for_item()
|
||
-- for each level range there is a different reward
|
||
local playerlevel = pc.get_level()
|
||
if playerlevel <= 18 then
|
||
return {
|
||
{27002, 13},
|
||
{27005, 13},
|
||
{27100, 8},
|
||
{27103, 8},
|
||
{50721, 4},
|
||
{30053, 9, 20},
|
||
{30073, 9, 20},
|
||
{30033, 9, 20},
|
||
{30010, 9, 20},
|
||
{30031, 9, 20},
|
||
{30032, 9, 20}
|
||
}
|
||
elseif playerlevel > 18 and playerlevel <= 30 then
|
||
return {
|
||
{27002, 18},
|
||
{27005, 18},
|
||
{27100, 7},
|
||
{27103, 7},
|
||
{27101, 3},
|
||
{27104, 3},
|
||
{50721, 8},
|
||
{50722, 8},
|
||
{50723, 8},
|
||
{50724, 8},
|
||
{50300, 2, 20},
|
||
{30196, 5, 20},
|
||
{30090, 5, 20}
|
||
}
|
||
elseif playerlevel > 30 and playerlevel <= 52 then
|
||
return {
|
||
{27101, 8},
|
||
{27104, 8},
|
||
{27003, 17},
|
||
{27006, 17},
|
||
{27102, 3},
|
||
{27105, 3},
|
||
{50721, 5},
|
||
{50722, 5},
|
||
{50723, 5},
|
||
{50724, 5},
|
||
{50725, 5},
|
||
{50726, 5},
|
||
{50727, 5},
|
||
{50728, 5},
|
||
{50300, 1, 20},
|
||
{30195, 4, 20},
|
||
{30197, 4, 20},
|
||
{30193, 3, 20}
|
||
}
|
||
elseif playerlevel > 52 and playerlevel <= 74 then
|
||
return {
|
||
{27003, 14},
|
||
{27006, 14},
|
||
{27102, 9},
|
||
{27105, 9},
|
||
{50721, 5},
|
||
{50722, 5},
|
||
{50723, 5},
|
||
{50724, 5},
|
||
{50725, 5},
|
||
{50726, 5},
|
||
{50727, 5},
|
||
{50728, 5},
|
||
{50300, 1, 20},
|
||
{30198, 4, 20},
|
||
{30199, 4, 20},
|
||
{08005, 3},
|
||
}
|
||
else
|
||
return {
|
||
{27102, 11},
|
||
{27105, 11},
|
||
{50091, 15},
|
||
{50092, 15},
|
||
{50093, 15},
|
||
{50094, 15},
|
||
{50300, 4, 20},
|
||
{50060, 6, 20},
|
||
{08005, 4},
|
||
{30196, 2, 20},
|
||
{30090, 2, 20},
|
||
{30195, 2, 20},
|
||
{30197, 2, 20},
|
||
{30198, 2, 20},
|
||
{30199, 2, 20}
|
||
}
|
||
end
|
||
end
|
||
function get_reward_amount_for_vnum(reward_table, vnum_to_search)
|
||
local amount_needed = 1
|
||
table.foreachi(reward_table,
|
||
function(index, item)
|
||
local itemVnum = item[1]
|
||
if itemVnum == vnum_to_search then
|
||
if table.getn(item) > 2 then
|
||
amount_needed = item[3]
|
||
else
|
||
amount_needed = 1
|
||
end
|
||
return
|
||
end
|
||
end
|
||
)
|
||
return amount_needed
|
||
end
|
||
function get_number_of_eggs()
|
||
local settings = event_easter_2012.get_settings()
|
||
return count_item_range(settings.eggvnums.first, settings.eggvnums.last)
|
||
end
|
||
function get_random_reward_vnum(reward_table)
|
||
local temp_table = {}
|
||
local easterEggCount = event_easter_2012.get_number_of_eggs()
|
||
table.foreachi(reward_table,
|
||
function(index, item)
|
||
local itemProbability = item[2]
|
||
local itemVnum = item[1]
|
||
local meetsAmountLimit = true
|
||
-- check if we need more than one easter egg
|
||
if table.getn(item) > 2 then
|
||
if easterEggCount < item[3] then
|
||
-- player does not have enough eggs for this item
|
||
meetsAmountLimit = false
|
||
end
|
||
end
|
||
if meetsAmountLimit then
|
||
for amount = 1, itemProbability do
|
||
table.insert(temp_table, itemVnum)
|
||
end
|
||
end
|
||
end
|
||
)
|
||
return temp_table[math.random(table.getn(temp_table))]
|
||
end
|
||
function spawn_metin(level, empire)
|
||
--if pc.is_gm() then
|
||
-- return
|
||
--end
|
||
|
||
local settings = event_easter_2012.get_settings()
|
||
if level >= 10 and level < 95 then
|
||
level = math.floor(level / 10) * 10
|
||
elseif level >= 95 then
|
||
level = 95
|
||
else
|
||
return
|
||
end
|
||
local randomMap = math.random(table.getn(settings.spawn.maps[empire][level]))
|
||
local mapNumber = settings.spawn.maps[empire][level][randomMap]
|
||
regen_in_map(mapNumber, "locale/_master/map/easter/metin_regen_level" .. level .. ".txt")
|
||
|
||
-- We have show a notice when logging is enabled (1)
|
||
local logging = game.get_event_flag("easter_logging")
|
||
if logging == 1 then
|
||
notice(string.format("metin spawn in map %d, level: %d", mapNumber, level))
|
||
end
|
||
end
|
||
function spawn_metin_at_login()
|
||
local settings = event_easter_2012.get_settings()
|
||
|
||
local timestamp = get_global_time()
|
||
local cooldownRemaining = pc.getqf("cooldown") + settings.spawn.cooldown - timestamp
|
||
if cooldownRemaining <= 0 then
|
||
pc.setqf("cooldown", timestamp)
|
||
if cooldownRemaining > -43200 then
|
||
if math.random(1000) <= settings.spawn.promille then
|
||
event_easter_2012.spawn_metin(pc.get_level(), pc.get_empire())
|
||
end
|
||
end
|
||
end
|
||
end
|
||
function metin_killed(vnum)
|
||
local settings = event_easter_2012.get_settings()
|
||
local level = settings.metins[vnum]
|
||
event_easter_2012.spawn_metin_at_login()
|
||
if level < pc.get_level() - settings.max_level_difference then
|
||
-- don't drop an egg when the player who killed the easter egg is more than 15 levels higher
|
||
event_easter_2012.spawn_metin(level, pc.get_empire())
|
||
else
|
||
local eggVnum = math.random(50160, 50179)
|
||
game.drop_item_with_ownership(eggVnum, 1)
|
||
if math.random(1, 100) <= settings.magicegg.pct then
|
||
game.drop_item_with_ownership(settings.magicegg.vnum, 1)
|
||
end
|
||
if math.random(1, 100) <= settings.spawn.kill then
|
||
event_easter_2012.spawn_metin(level, pc.get_empire())
|
||
end
|
||
end
|
||
end
|
||
|
||
when login or enter with event_easter_2012.has_rabbit() begin
|
||
-- spawn rabbit if he is not there
|
||
local settings = event_easter_2012.get_settings()
|
||
local mapIndex = pc.get_map_index()
|
||
if mapIndex == 1 or mapIndex == 21 or mapIndex == 41 then
|
||
if find_npc_by_vnum(settings.rabbit) == 0 then
|
||
if mapIndex == 1 then
|
||
mob.spawn(settings.rabbit, 591, 472, 1, 1, 1)
|
||
elseif mapIndex == 21 then
|
||
mob.spawn(settings.rabbit, 517, 742, 1, 1, 1)
|
||
elseif mapIndex == 41 then
|
||
mob.spawn(settings.rabbit, 306, 828, 1, 1, 1)
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
when login or enter with event_easter_2012.is_running() begin
|
||
|
||
event_easter_2012.spawn_metin_at_login()
|
||
end
|
||
|
||
-- "Was machst du hier?"
|
||
|
||
when 30129.chat.gameforge.main_quest_lv2._10_npcChat with event_easter_2012.get_number_of_eggs() == 0 begin
|
||
event_easter_2012.spawn_metin_at_login()
|
||
say_title(gameforge.event_easter._020_sayTitle) -- "Osterhase: "
|
||
say(gameforge.event_easter._030_say) -- "Ich verstecke Ostereier. Wenn du welche findest und mir zur<75>ck bringst, belohne ich dich toll!"
|
||
say(gameforge.event_easter._035_say)
|
||
if not event_easter_2012.has_rabbit() then
|
||
-- purge the rabbit if the event has finished
|
||
npc.purge()
|
||
end
|
||
end --when
|
||
|
||
when 30129.chat.gameforge.event_easter._040_chat with event_easter_2012.get_number_of_eggs() > 0 begin
|
||
event_easter_2012.spawn_metin_at_login()
|
||
local settings = event_easter_2012.get_settings()
|
||
local reward_table = event_easter_2012.get_reward_table_for_item()
|
||
local amount_to_remove = 0
|
||
local amount_to_give = 0
|
||
local vnum_to_give = 0
|
||
local number_of_eggs = event_easter_2012.get_number_of_eggs()
|
||
local wants_items = 2
|
||
while wants_items == 2 do
|
||
vnum_to_give = event_easter_2012.get_random_reward_vnum(reward_table)
|
||
local amount_needed = event_easter_2012.get_reward_amount_for_vnum(reward_table, vnum_to_give)
|
||
if amount_needed == 20 then
|
||
amount_to_remove = 20
|
||
amount_to_give = 1
|
||
|
||
say_title(gameforge.event_easter._020_sayTitle) -- "Osterhase: "
|
||
say(string.format(gameforge.event_easter._050_say, amount_to_give)) -- "Ich gebe dir %d hiervon:"
|
||
say_item_vnum(vnum_to_give)
|
||
say(string.format(gameforge.event_easter._065_say, amount_to_remove)) -- "Daf<61>r musst du mir %d Eier geben! M<>chtest du das tun?"
|
||
else
|
||
if number_of_eggs > 20 then
|
||
amount_to_remove = 20
|
||
else
|
||
amount_to_remove = number_of_eggs
|
||
end
|
||
if vnum_to_give < 27200 then
|
||
amount_to_give = amount_to_remove * 3
|
||
else
|
||
amount_to_give = amount_to_remove * 5
|
||
end
|
||
say_title(gameforge.event_easter._020_sayTitle) -- "Osterhase: "
|
||
say(string.format(gameforge.event_easter._050_say, amount_to_give)) -- "Ich gebe dir %d hiervon:"a
|
||
say_item_vnum(vnum_to_give)
|
||
say(string.format(gameforge.event_easter._065_say, amount_to_remove)) -- "Daf<61>r musst du mir %d Eier geben! M<>chtest du das tun?"
|
||
end
|
||
wants_items = 1
|
||
end
|
||
|
||
if (remove_item_range(amount_to_remove, settings.eggvnums.first, settings.eggvnums.last)) then
|
||
pc.give_item2(vnum_to_give, amount_to_give)
|
||
end
|
||
wait()
|
||
say_title(gameforge.event_easter._020_sayTitle) -- "Osterhase: "
|
||
say(gameforge.event_easter._080_say) -- "Danke f<>r die Eier, ich hoffe du hast Spa<70> mit dem was du bekommen hast"
|
||
if not event_easter_2012.has_rabbit() then
|
||
-- purge the rabbit if the event has finished
|
||
npc.purge()
|
||
end
|
||
end --when
|
||
when 8041.kill begin
|
||
event_easter_2012.metin_killed(8041)
|
||
end
|
||
when 8042.kill begin
|
||
event_easter_2012.metin_killed(8042)
|
||
end
|
||
when 8043.kill begin
|
||
event_easter_2012.metin_killed(8043)
|
||
end
|
||
when 8044.kill begin
|
||
event_easter_2012.metin_killed(8044)
|
||
end
|
||
when 8045.kill begin
|
||
event_easter_2012.metin_killed(8045)
|
||
end
|
||
when 8046.kill begin
|
||
event_easter_2012.metin_killed(8046)
|
||
end
|
||
when 8047.kill begin
|
||
event_easter_2012.metin_killed(8047)
|
||
end
|
||
when 8048.kill begin
|
||
event_easter_2012.metin_killed(8048)
|
||
end
|
||
when 8049.kill begin
|
||
event_easter_2012.metin_killed(8049)
|
||
end
|
||
when 8050.kill begin
|
||
event_easter_2012.metin_killed(8050)
|
||
end
|
||
|
||
end --state
|
||
end --quest
|