Instance Spawn Raid

byEvanthe

Интересующийся
Участник
Сообщения
119
Розыгрыши
0
Решения
1
Репутация
0
Реакции
9
Баллы
380
Хроники
  1. Chaotic Throne: High Five
Исходники
Присутствуют
Сборка
L2jSunrise
Hello, can anyone check this instance file to check why sometimes, monument are spawned twice and raid no?
Smetimes, monument are spawned once and raid too, but sometimes monument twice, and raid no.

+ i don't get drops sometimes.
JavaScript:
package instances.MoiraiInstance;

import l2r.gameserver.ThreadPoolManager;
import l2r.gameserver.cache.HtmCache;
import l2r.gameserver.data.xml.impl.ItemData;
import l2r.gameserver.enums.CtrlEvent;
import l2r.gameserver.enums.CtrlIntention;
import l2r.gameserver.instancemanager.InstanceManager;
import l2r.gameserver.model.L2Object;
import l2r.gameserver.model.L2World;
import l2r.gameserver.model.actor.L2Attackable;
import l2r.gameserver.model.actor.L2Npc;
import l2r.gameserver.model.actor.L2Summon;
import l2r.gameserver.model.actor.instance.L2PcInstance;
import l2r.gameserver.model.effects.L2EffectType;
import l2r.gameserver.model.entity.Instance;
import l2r.gameserver.model.instancezone.InstanceWorld;
import l2r.gameserver.model.quest.Quest;
import l2r.gameserver.model.skills.L2Skill;
import l2r.gameserver.network.SystemMessageId;
import l2r.gameserver.network.serverpackets.ExSendUIEvent;
import l2r.gameserver.network.serverpackets.SystemMessage;
import l2r.gameserver.util.Util;
import l2r.util.StringUtil;

import java.util.HashMap;
import java.util.Map;

public class MoiraiInstance extends Quest
{
    private class DHSWorld extends InstanceWorld
    {
        public Map<L2Npc, Boolean> npcList = new HashMap<>();
        public L2Npc ZAKEN = null;
        
        public long[] storeTime =
        {
            0,
            0
        };
        
        public DHSWorld()
        {
            
        }
    }

    private static final int ENTRANCE_NPC = 4313; // Enter Npc
    private static final int NORMAL_STONE = 17704; // Penalty Stones
    private static final int PREMIUM_STONE = 17720; // Penalty Stones
    
    private static final int[][] PREMIUM_DROPS =
            {
                    {57, 400}, // Adena
                    {68003, 3}, // L2-Prolog Coin
                    {67463, 2}, // Head of Zaken { Moirai }
                    {NORMAL_STONE, 1} /* Penalty Stone */
            };

    private static final int[][] COMMON_DROPS =
            {
                    // itemId, itemCount
                    {57, 200}, // Adena
                    {68003, 1}, // L2-Prolog Coin
                    {67463, 1}, // Head of Zaken { Moirai }
                    {PREMIUM_STONE, 1} /* Penalty Stone */
            };
    
    // mobs
    private static final int[] ZAKEN_MOBIDS =
    {
        80004
    };
    
    //@formatter:off
    private static final int[][] ROOM_1_MOBS =
            {
                {80004,83983,-17645,-1833}, {80004,84056,-17272,-1855}, {80004,84671,-17102,-1840},
                {80004,84214,-16852,-1848}, {80004,84383,-16311,-1834}, {80004,83981,-16022,-1834},
                {80004,83665,-15509,-1834}, {80004,83231,-15198,-1841}, {80004,82802,-15650,-1898},
                {80004,82266,-15698,-1888}, {80004,81799,-15189,-1839}, {80004,81484,-15807,-1850},
                {80004,81199,-16456,-1837}, {80004,81649,-16542,-1857}, {80004,81894,-17002,-1830},
                {80004,82530,-17265,-1824}, {80004,83199,-17547,-1828}, {80004,83680,-17273,-1834},
                {80004,83536,-16772,-1869}, {80004,83484,-16354,-1887}, {80004,82975,-16486,-1893},
                {80004,82709,-16910,-1880}, {80004,83491,-16783,-1870}, {80004,82179,-15588,-1878},
                {80004,81387,-15969,-1856}, {80004,81642,-16958,-1827}, {80004,82207,-17312,-1826},
                {80004,82870,-17059,-1853}, {80004,83656,-16482,-1864}, {80004,83433,-15646,-1853},
                {80004,82223,-16111,-1897}, {80004,81123,-15785,-1834}, {80004,81097,-15028,-1835},
                {80004,81967,-14654,-1819}, {80004,82484,-16545,-1888}, {80004,85307,-16420,-1834},
                {80004,85065,-16952,-1824}, {80004,84495,-17306,-1860}, {80004,84519,-16822,-1832},
                {80004,84213,-16617,-1833}, {80004,83728,-17001,-1846}, {80004,83260,-17210,-1824},
                {80004,83085,-16792,-1886}, {80004,82758,-16210,-1891}, {80004,82300,-16299,-1894},
                {80004,81363,-16081,-1857}, {80004,81511,-15471,-1836}, {80004,82077,-15051,-1837},
                {80004,82753,-15427,-1871}, {80004,83194,-15980,-1895}, {80004,83866,-15793,-1833},
                {80004,84348,-15795,-1832}, {80004,84879,-16523,-1824}, {80004,84589,-16717,-1829},
                {80004,83536,-16772,-1869}, {80004,83484,-16354,-1887}, {80004,82975,-16486,-1893},
                {80004,82709,-16910,-1880}, {80004,83491,-16783,-1870}, {80004,82179,-15588,-1878},
                {80004,81387,-15969,-1856}, {80004,81642,-16958,-1827}, {80004,82207,-17312,-1826},
                {80004,82870,-17059,-1853}, {80004,83656,-16482,-1864}, {80004,83433,-15646,-1853},
                {80004,82223,-16111,-1897}, {80004,81123,-15785,-1834}, {80004,81097,-15028,-1835},
                {80004,81967,-14654,-1819}, {80004,82484,-16545,-1888}, {80004,85307,-16420,-1834},
                {80004,82447,-16303,-1898}
            };

    private static final int ZAKEN_BOSS = 77858; // Boss Id
    private static final int MONUMENT = 18506; // Monument
    
    private static final int[][] ZAKEN_MONUMENT_SPAWNS ={{81000,-15440,-1810}};
    
    private static final int[][] ZAKEN_SPAWNS ={{77858, 81561,-15432, -1837}};


    //@formatter:on
    public class teleCoord
    {
        int instanceId;
        int x;
        int y;
        int z;
    }
    
    public MoiraiInstance()
    {
        super(-1, MoiraiInstance.class.getSimpleName(), "custom");
        addStartNpc(ENTRANCE_NPC);
        addTalkId(ENTRANCE_NPC);
        addKillId(MONUMENT);
        addKillId(ZAKEN_BOSS);
        addAttackId(ZAKEN_BOSS);
        addSkillSeeId(ZAKEN_MOBIDS);
        addKillId(ZAKEN_MOBIDS);
    }
    
    private boolean checkConditions(L2PcInstance player)
    {
        if (hasQuestItems(player, PREMIUM_STONE))
        {
            SystemMessage sm = SystemMessage.getSystemMessage(2100);
            sm.addPcName(player);
            player.broadcastPacket(sm);
            return false;
        }
        if (hasQuestItems(player, NORMAL_STONE))
        {
            SystemMessage sm = SystemMessage.getSystemMessage(2100);
            sm.addPcName(player);
            player.broadcastPacket(sm);
            return false;
        }
        return true;
    }
    
    private void teleportplayer(L2PcInstance player, teleCoord teleto)
    {
        player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
        player.setInstanceId(teleto.instanceId);
        player.teleToLocation(teleto.x, teleto.y, teleto.z);
    }
    
    protected void enterInstance(L2PcInstance player, String template, teleCoord teleto, L2Npc npc)
    {
        if (hasQuestItems(player, PREMIUM_STONE))
        {
            SystemMessage sm = SystemMessage.getSystemMessage(2100);
            sm.addPcName(player);
            player.broadcastPacket(sm);
            return;
        }
        if (hasQuestItems(player, NORMAL_STONE))
        {
            SystemMessage sm = SystemMessage.getSystemMessage(2100);
            sm.addPcName(player);
            player.broadcastPacket(sm);
            return;
        }
        // check for existing instances for this player
        InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
        // existing instance
        if (world != null)
        {
            if (!(world instanceof DHSWorld))
            {
                player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_ENTERED_ANOTHER_INSTANT_ZONE_THEREFORE_YOU_CANNOT_ENTER_CORRESPONDING_DUNGEON));
                return;
            }
        }
        else
        {
            if (!checkConditions(player))
            {
                return;
            }
            world = new DHSWorld();
            world.setInstanceId(InstanceManager.getInstance().createDynamicInstance(template));
            world.setStatus(0);
            world.addAllowed(player.getObjectId());
            ((DHSWorld) world).storeTime[0] = System.currentTimeMillis();
            InstanceManager.getInstance().addWorld(world);
            _log.info("Epic Mission as been started " + template + " Instance: " + world.getInstanceId() + " created by player: " + player.getName());
            spawnMobs((MoiraiInstance.DHSWorld) world);
        }
        // teleport players
        teleto.instanceId = world.getInstanceId();
        teleportplayer(player, teleto);
    }
    
    protected void exitInstance(L2PcInstance player, teleCoord tele)
    {
        player.setInstanceId(0);
        player.teleToLocation(tele.x, tele.y, tele.z);
        L2Summon pet = player.getSummon();
        if (pet != null)
        {
            pet.setInstanceId(0);
            pet.teleToLocation(tele.x, tele.y, tele.z);
        }
    }
    
    protected boolean checkKillProgress(L2Npc mob, DHSWorld world)
    {
        if (world.npcList.containsKey(mob))
        {
            world.npcList.put(mob, true);
        }
        for (boolean isDead : world.npcList.values())
        {
            if (!isDead)
            {
                return false;
            }
        }
        return true;
    }
    
    protected int[][] getRoomSpawns(int room)
    {
        if (room == 0)
        {
            return ROOM_1_MOBS;
        }
        return new int[][] {};
    }
    
    protected void spawnMobs(MoiraiInstance.DHSWorld world)
    {
        for (int[] mob : getRoomSpawns(world.getStatus()))
        {
            L2Npc npc = addSpawn(mob[0], mob[1], mob[2], mob[3], 0, false, 0, false, world.getInstanceId());
            npc.disableCoreAI(true);
            npc.setIsImmobilized(true);
            world.npcList.put(npc, false);
        }
    }
    
    protected void spawnGuard(DHSWorld world)
    {
        L2Npc mob = addSpawn(MONUMENT, ZAKEN_MONUMENT_SPAWNS[world.getStatus()][0], ZAKEN_MONUMENT_SPAWNS[world.getStatus()][1], ZAKEN_MONUMENT_SPAWNS[world.getStatus()][2], 0, false, 0, false, world.getInstanceId());
        mob.disableCoreAI(true);
        mob.setIsImmobilized(true);
        mob.setCurrentHp(mob.getMaxHp() * 1.0);
        world.npcList.put(mob, false);
        world.setStatus(world.getStatus() + 1); // setting status to 1
    }
    
    protected void spawnRaid(DHSWorld world)
    {
        world.ZAKEN = addSpawn(ZAKEN_SPAWNS[0][0], ZAKEN_SPAWNS[0][1], ZAKEN_SPAWNS[0][2], ZAKEN_SPAWNS[0][3], 0, false, 0, false, world.getInstanceId());
        world.ZAKEN.setIsMortal(true);
        world.setStatus(world.getStatus() + 1); // sets status to 2
    }
    
    protected void bossSimpleDie(L2Npc boss)
    {
        // killing is only possible one time
        synchronized (this)
        {
            if (boss.isDead())
            {
                return;
            }
            // now reset currentHp to zero
            boss.setCurrentHp(0);
            boss.setIsDead(true);
        }
        
        // Set target to null and cancel Attack or Cast
        boss.setTarget(null);
        
        // Stop movement
        boss.stopMove(null);
        
        // Stop HP/MP/CP Regeneration task
        boss.getStatus().stopHpMpRegeneration();
        
        boss.stopAllEffectsExceptThoseThatLastThroughDeath();
        
        // Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
        boss.broadcastStatusUpdate();
        
        // Notify L2Character AI
        boss.getAI().notifyEvent(CtrlEvent.EVT_DEAD);
        
        if (boss.getWorldRegion() != null)
        {
            boss.getWorldRegion().onDeath(boss);
        }
    }
    
    @Override
    public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
    {
        if (skill.hasEffectType(L2EffectType.REBALANCE_HP, L2EffectType.HEAL, L2EffectType.HEAL_PERCENT))
        {
            int hate = 2 * skill.getAggroPoints();
            if (hate < 2)
            {
                hate = 1000;
            }
            ((L2Attackable) npc).addDamageHate(caster, 0, hate);
        }
        return super.onSkillSee(npc, caster, skill, targets, isPet);
    }
    
    @Override
    public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
    {
        InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
        if (tmpworld instanceof DHSWorld)
        {
            DHSWorld world = (DHSWorld) tmpworld;
            if (world.getStatus() == 0)
            {
                if (checkKillProgress(npc, world))
                {
                    spawnGuard(world);
                }
            }
            else if (world.getStatus() == 1)
            {
                if (checkKillProgress(npc, world))
                {
                    spawnRaid(world);
                }
            }
            else if ((world.getStatus() == 2) && ((npc.getId() == ZAKEN_BOSS)))
            {
                world.setStatus(world.getStatus() + 1); // sets status to 3
                // instance end
                world.storeTime[1] = System.currentTimeMillis();
                world.ZAKEN = null;
                if (player.isPremium())
                {
                    for (int[] drop : PREMIUM_DROPS)
                    {
                        player.addItem("PREMIUM_DROP", drop[0], drop[1], player, false);
                    }
                }
                else
                {
                    for (int[] drop : COMMON_DROPS)
                    {
                        player.addItem("COMMON_DROP", drop[0], drop[1], player, false);
                    }
                }
                world.removeAllowed(player.getObjectId());
                
                player.sendMessage("You will be teleported back in 10 seconds.");
                
                ThreadPoolManager.getInstance().scheduleGeneral(() ->
                {
                    teleCoord tele = new teleCoord();
                    tele.instanceId = 0;
                    tele.x = 82497;
                    tele.y = 148597;
                    tele.z = -3469;
                    exitInstance(player, tele);
                }, 10_000);
                
                for (Integer pc : world.getAllowed())
                {
                    L2PcInstance killer = L2World.getInstance().getPlayer(pc);
                    if (killer != null)
                    {
                        killer.sendPacket(new ExSendUIEvent(killer, true, true, 0, 0, ""));
                    }
                }
                
                Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
                inst.setDuration(1 * 10000);
                inst.setEmptyDestroyTime(0);


                String html = HtmCache.getInstance().getHtm(player, player.getHtmlPrefix(), "data/html/mods/InstanceRewards/Moirai.htm");
                StringBuilder sb = new StringBuilder();

                if (player.isPremium())
                {
                    for (int[] drop : PREMIUM_DROPS)
                    {
                        //player.addItem("PREMIUM_DROP", drop[0], drop[1], player, true);
                        sb.append("<br><br><table><tr><td width=240 align=center><table width=550 border=0 cellspacing=3 cellpadding=3 bgcolor=2e2e1f><tr><td height =36 align=left valign=top><img src=\"" + ItemData.getInstance().getTemplate(drop[0]).getIcon() + "\" width=32 height=32></td><td width=255 align=left valign=center> <font name=hs9 color=B59A75>" + ItemData.getInstance().getTemplate(drop[0]).getName( ) + "</font>" + " x<font name=hs9 color=66ff66> " + StringUtil.getFormatValue(drop[1]) + "</font></td></tr></table></td></tr></table><br1>");
                    }
                }
                else
                {
                    for (int[] drop : COMMON_DROPS)
                    {
                        //player.addItem("COMMON_DROP", drop[0], drop[1], player, true);
                        sb.append("<br><br><table><tr><td width=240 align=center><table width=550 border=0 cellspacing=3 cellpadding=3 bgcolor=2e2e1f><tr><td height =36 align=left valign=top><img src=\"" + ItemData.getInstance().getTemplate(drop[0]).getIcon() + "\" width=32 height=32></td><td width=255 align=left valign=center> <font name=hs9 color=B59A75>" + ItemData.getInstance().getTemplate(drop[0]).getName( ) + "</font>" + " x<font name=hs9 color=66ff66> " + StringUtil.getFormatValue(drop[1]) + "</font></td></tr></table></td></tr></table><br1>");
                    }
                }
                html = html.replace("%player%", player.getName());
                html = html.replace("%drops%", player.isPremium() ? "<font name=hs9 color=LEVEL>Premium Account</font>" : "<font name=hs9>Normal Account</font>" );
                html = html.replace("%data%", sb.toString());
                Util.sendCBHtml(player, html);
            }
        }
        return "";
    }
    
    @Override
    public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
    {
        if (event.equalsIgnoreCase("start"))
        {
            teleCoord tele = new teleCoord();
            tele.x = 85133;
            tele.y = -17938;
            tele.z = -1863;
            enterInstance(player, "MoiraiInstance.xml", tele, npc);
        }
        return event;
    }
}
 
I don't remember if onKill can be accessed concurrently, if yes, I would try to use concurrent hashmaps or synchronized spawnguard method. Didn't check your code carefully so I might have just missed an actual bug :)
 
Can you help me to fix the instance please?
 
как вариант что моб не успевает спавнится, попробовать можно статус мира менять до того как заспавнили моба

Java:
protected void spawnGuard(DHSWorld world)
    {
        world.setStatus(world.getStatus() + 1); // setting status to 1
        L2Npc mob = addSpawn(MONUMENT, ZAKEN_MONUMENT_SPAWNS[world.getStatus()][0], ZAKEN_MONUMENT_SPAWNS[world.getStatus()][1], ZAKEN_MONUMENT_SPAWNS[world.getStatus()][2], 0, false, 0, false, world.getInstanceId());
        mob.disableCoreAI(true);
        mob.setIsImmobilized(true);
        mob.setCurrentHp(mob.getMaxHp() * 1.0);
        world.npcList.put(mob, false);
    }
    
    protected void spawnRaid(DHSWorld world)
    {
        world.setStatus(world.getStatus() + 1); // sets status to 2
        world.ZAKEN = addSpawn(ZAKEN_SPAWNS[0][0], ZAKEN_SPAWNS[0][1], ZAKEN_SPAWNS[0][2], ZAKEN_SPAWNS[0][3], 0, false, 0, false, world.getInstanceId());
        world.ZAKEN.setIsMortal(true);
    }
 
Infact, i want to someone to check the instance. Because the drops are bugged too, sometimes drop items, sometimes no. But I hope this change the drops and drop will work properly!
as an option that the mob does not have time to spawn, you can try to change the world status before the mob is spawned

Java:
protected void spawnGuard(DHSWorld world)
    {
        world.setStatus(world.getStatus() + 1); // setting status to 1
        L2Npc mob = addSpawn(MONUMENT, ZAKEN_MONUMENT_SPAWNS[world.getStatus()][0], ZAKEN_MONUMENT_SPAWNS[world.getStatus()][1], ZAKEN_MONUMENT_SPAWNS[world.getStatus()][2], 0, false, 0, false , world.getInstanceId());
        mob.disableCoreAI(true);
        mob.setIsImmobilized(true);
        mob.setCurrentHp(mob.getMaxHp() * 1.0);
        world.npcList.put(mob, false);
    }
   
    protected void spawnRaid(DHSWorld world)
    {
        world.setStatus(world.getStatus() + 1); // sets status to 2
        world.ZAKEN = addSpawn(ZAKEN_SPAWNS[0][0], ZAKEN_SPAWNS[0][1], ZAKEN_SPAWNS[0][2], ZAKEN_SPAWNS[0][3], 0, false, 0, false, world.getInstanceId( ));
        world.ZAKEN.setIsMortal(true);
    }
 
Назад
Сверху