Index: scripts/zones/The_Shrine_of_RuAvitau/mobs/Kirin.lua =================================================================== --- scripts/zones/The_Shrine_of_RuAvitau/mobs/Kirin.lua (revision 3307) +++ scripts/zones/The_Shrine_of_RuAvitau/mobs/Kirin.lua (working copy) @@ -2,79 +2,96 @@ -- Area: The Shrine of Ru'Avitau -- NPC: Kirin ----------------------------------- -package.loaded["scripts/zones/The_Shrine_of_RuAvitau/TextIDs"] = nil; +package.loaded[ "scripts/zones/The_Shrine_of_RuAvitau/TextIDs" ] = nil; ----------------------------------- -require("scripts/zones/The_Shrine_of_RuAvitau/TextIDs"); -require("scripts/globals/titles"); -require("scripts/globals/status"); +require( "scripts/zones/The_Shrine_of_RuAvitau/TextIDs" ); +require( "scripts/globals/titles" ); +require( "scripts/globals/status" ); ----------------------------------- -- onMobInitialize Action ----------------------------------- +function onMobInitialize( mob ) + -- Add regen and gain effects.. + mob:addStatusEffect( EFFECT_REGEN, 50, 3, 0 ); + mob:addStatusEffect( EFFECT_REGAIN, 15, 3, 0 ); +end -function onMobInitialize(mob) - mob:addStatusEffect(EFFECT_REGEN,50,3,0); - mob:addStatusEffect(EFFECT_REGAIN,15,3,0); -end; - ----------------------------------- -- onMobFight Action ----------------------------------- +function onMobFight( mob, target ) + if (mob:getBattleTime() ~= 0 and mob:getBattleTime() % 180 == 0) then + -- Ensure we have not spawned all pets yet.. + local genbu, seiryu, byakko, suzaku = mob:getExtraVar( 4 ); + if (genbu == 1 and seiryu == 1 and byakko == 1 and suzaku == 1) then + return; + end + + -- Pick a pet to spawn at random.. + local ChosenPet = nil; + repeat + + local rand = math.random( 0, 3 ); + ChosenPet = 17506671 + rand; + + switch (ChosenPet): caseof { + [17506671] = function (x) if ( genbu == 1) then ChosenPet = 0; else genbu = 1; end end, -- Genbu + [17506672] = function (x) if (seiryu == 1) then ChosenPet = 0; else seiryu = 1; end end, -- Seiryu + [17506673] = function (x) if (byakko == 1) then ChosenPet = 0; else byakko = 1; end end, -- Byakko + [17506674] = function (x) if (suzaku == 1) then ChosenPet = 0; else suzaku = 1; end end, -- Suzaku + } + + until (ChosenPet ~= 0 and ChosenPet ~= nil) + + -- Spawn the pet.. + local pet = SpawnMob( ChosenPet ); + pet:updateEnmity( target ); + pet:setPos( mob:getXPos(), mob:getYPos(), mob:getZPos() ); -function onMobFight(mob,target) - local ChosenPet; - local RandomMod; - local pets; + -- Update Kirins extra vars.. + mob:setExtraVar( genbu, seiryu, byakko, suzaku ); + end - if(mob:getBattleTime() % 180 == 0) then -- Every 3 minutes ... - if (Kirin_PetsCalled < 15) then -- ... if you haven't called all four pets already ... - repeat - RandomMod = math.random(0,3); - ChosenPet = 17506671 + RandomMod; -- ... pick a random pet... + -- Ensure all spawned pets are doing stuff.. + for pets = 17506671, 17506674 do + if (GetMobAction( pets ) == 16) then + -- Send pet after current target.. + GetMobByID( pets ):updateEnmity( target ); + end + end +end - -- ... unless you've already called that pet ... - if (target:getMaskBit(Kirin_PetsCalled,RandomMod) == true) then - ChosenPet = 0; - end - until(ChosenPet ~= 0 and ChosenPet ~= nil) - - -- ... then pop it and send it after the tank ... - SpawnMob(ChosenPet):updateEnmity(target); - GetMobByID(ChosenPet):setPos(mob:getXPos(), mob:getYPos(), mob:getZPos()); - - -- ... and set a bit so you can't resummon that pet. - switch (ChosenPet): caseof { - [17506671] = function (x) Kirin_PetsCalled = Kirin_PetsCalled + 1; end, -- Genbu - [17506672] = function (x) Kirin_PetsCalled = Kirin_PetsCalled + 2; end, -- Seiryu - [17506673] = function (x) Kirin_PetsCalled = Kirin_PetsCalled + 4; end, -- Byakko - [17506674] = function (x) Kirin_PetsCalled = Kirin_PetsCalled + 8; end, -- Suzaku - } - end - end - - - -- If any pets are idle ... - for pets = 17506671,17506674 do - if (GetMobAction(pets) == 16) then - GetMobByID(pets):updateEnmity(target); -- ... get back in the fight. - end - end - -end; - ----------------------------------- -- onMobDeath ----------------------------------- +function onMobDeath( mob, killer ) + -- Award title and cleanup.. + killer:addTitle( KIRIN_CAPTIVATOR ); + killer:showText( mob, KIRIN_OFFSET + 1 ); + GetNPCByID( 17506693 ):hideNPC( 900 ); + + -- Despawn pets.. + DespawnMob( 17506671 ); + DespawnMob( 17506672 ); + DespawnMob( 17506673 ); + DespawnMob( 17506674 ); + + -- Reset popped pet var.. + mob:setExtraVar( 0 ); +end -function onMobDeath(mob, killer) - killer:addTitle(KIRIN_CAPTIVATOR); - killer:showText(mob,KIRIN_OFFSET + 1); - GetNPCByID(17506693):hideNPC(900); - - -- Depop Pets - DespawnMob(17506671); - DespawnMob(17506672); - DespawnMob(17506673); - DespawnMob(17506674); -end; \ No newline at end of file +----------------------------------- +-- OnMobDespawn +----------------------------------- +function onMobDespawn( mob ) + -- Despawn pets.. + DespawnMob( 17506671 ); + DespawnMob( 17506672 ); + DespawnMob( 17506673 ); + DespawnMob( 17506674 ); + + -- Reset popped pet var.. + mob:setExtraVar( 0 ); +end Index: scripts/zones/The_Shrine_of_RuAvitau/npcs/qm2.lua =================================================================== --- scripts/zones/The_Shrine_of_RuAvitau/npcs/qm2.lua (revision 3307) +++ scripts/zones/The_Shrine_of_RuAvitau/npcs/qm2.lua (working copy) @@ -13,16 +13,20 @@ ----------------------------------- function onTrade(player,npc,trade) - - -- Trade seal of genbu, seal of seiryu, seal of byakko, seal of suzaku - if(GetMobAction(17506670) == 0 and trade:hasItemQty(1404,1) and trade:hasItemQty(1405,1) and - trade:hasItemQty(1406,1) and trade:hasItemQty(1407,1) and trade:getItemCount() == 4) then - player:tradeComplete(); - SpawnMob(17506670,180):updateEnmity(player); - player:showText(npc,KIRIN_OFFSET); - Kirin_PetsCalled = 0; - end - + -- Ensure Kirin is not alive.. + if (GetMobAction( 17506670 ) == 0) then + -- Validate traded items are all needed seals.. + if (trade:hasItemQty( 1404, 1 ) and trade:hasItemQty( 1405, 1 ) and trade:hasItemQty( 1406, 1 ) and trade:hasItemQty( 1407, 1 ) and trade:getItemCount() == 4) then + -- Complete the trade.. + player:tradeComplete(); + + -- Spawn Kirin.. + local mob = SpawnMob( 17506670, 180 ); + mob:setExtraVar( 0 ); + player:showText( npc, KIRIN_OFFSET ); + mob:updateEnmity( player ); + end + end end; ----------------------------------- Index: src/map/ai/ai_mob_dummy.cpp =================================================================== --- src/map/ai/ai_mob_dummy.cpp (revision 3307) +++ src/map/ai/ai_mob_dummy.cpp (working copy) @@ -557,6 +557,7 @@ } m_PMob->loc.zone->PushPacket(m_PMob, CHAR_INRANGE, new CEntityUpdatePacket(m_PMob, ENTITY_SPAWN)); + luautils::OnMobSpawn( m_PMob ); } } Index: src/map/lua/lua_baseentity.cpp =================================================================== --- src/map/lua/lua_baseentity.cpp (revision 3307) +++ src/map/lua/lua_baseentity.cpp (working copy) @@ -6524,16 +6524,14 @@ lua_pushinteger(L, var3); } else { uint32 var = ((CMobEntity*)m_PBaseEntity)->m_extraVar; - uint8 var1 = var & 0x000000FF; - uint8 var2 = var & 0x0000FF00; - var2 >>= 8; - uint8 var3 = var & 0x00FF0000; - var3 >>= 16; - uint8 var4 = var >>= 24; + uint8 var1 = (var & 0x000000FF); + uint8 var2 = (var & 0x0000FF00) >> 8; + uint8 var3 = (var & 0x00FF0000) >> 16; + uint8 var4 = (var & 0xFF000000) >> 24; + lua_pushinteger(L, var4); + lua_pushinteger(L, var3); + lua_pushinteger(L, var2); lua_pushinteger(L, var1); - lua_pushinteger(L, var2); - lua_pushinteger(L, var3); - lua_pushinteger(L, var4); } return n; Index: src/map/lua/luautils.cpp =================================================================== --- src/map/lua/luautils.cpp (revision 3307) +++ src/map/lua/luautils.cpp (working copy) @@ -1939,7 +1939,7 @@ Lunar::push(LuaHandle,&LuaMobEntity); - if( lua_pcall(LuaHandle,2,LUA_MULTRET,0) ) + if( lua_pcall(LuaHandle,1,LUA_MULTRET,0) ) { ShowError("luautils::OnMobSpawn: %s\n",lua_tostring(LuaHandle,-1)); lua_pop(LuaHandle, 1);