Page 1 of 1

[Help] Thread management + DM Event

Posted: Thu Jul 15, 2010 10:06 am
by rychoo84
L2J Revision n/a
L2JDP Revision n/a

Hi,
First of all I'd like to aplogize if this topic doesn't fit the section (don't want to spam useless posts in order to become able to write in Custom section. If it's possible please move this topic into the right section, thank you

I'm writing my own DM (Last man standing type) event based on already existing TvT files. The main part is working fine, except when one participant is left, the event is running until the time is over (and it should end after there's only one player left).

after every call of OnKill method killed participant is being removed (that part works fine) from the event.
Ofc REWARDING state is set only when there's one guy left (that works fine too)

Code: Select all

 if(_players[0].getParticipatedPlayerCount() == 1){	setState(EventState.REWARDING);	rewardDmWinner(_players[0]);} 
I also have made a method, which checks if there's only on guy left:

Code: Select all

 public static boolean CheckDmPlayerCountEqualToOne(){	if(_players[0].getParticipatedPlayers().size() == 1)		return true; 	return false;} 
Now I'm checking for these conditions inside the DmManager class (equivalent of TvTManager)

Code: Select all

 public void run(){	int delay = (int) Math.round((_startTime - System.currentTimeMillis()) / 1000.0); 	if (delay > 0)	{	      this.announce(delay);	} 	int nextMsg = 0;	if (delay > 3600)	{		nextMsg = delay - 3600;	}	else if (delay > 1800)	//..... 	else	{	   // start	   if (DmEvent.isInactive())	   {		DmManager.this.startReg();	   }	   else if (DmEvent.isParticipating())	   {		DmManager.this.startEvent();	   }	  else	   {		DmManager.this.endEvent();	    }       } 	if (delay > 0)	{	       //here it is		[color=#00BF40]if(DmEvent.isStarted() && DmEvent.CheckDmPlayerCountEqualToOne())		{			DmManager.this.endEvent();		}[/color] 		nextRun = ThreadPoolManager.getInstance().scheduleGeneral(this, nextMsg * 1000);	}} 
I must have forgot something, probably need to stop the thread somehow. Could you give me some hints how make it work?
Thx in advance
Tom

Re: [Help] Thread management + DM Event

Posted: Thu Jul 15, 2010 11:42 am
by jurchiks
where's the endEvent method itself?

Re: [Help] Thread management + DM Event

Posted: Thu Jul 15, 2010 12:15 pm
by rychoo84
it's totally unchanged (if speaking about TvT eqiuvalent it's in TvT Manager class)

Code: Select all

 public void endEvent()	{		Announcements.getInstance().announceToAll(DmEvent.calculateRewards()); 		DmEvent.sysMsgToAllParticipants("DM Event: Teleporting back to the registration npc in "				+ Config.DM_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");		DmEvent.stopFight(); 		this.scheduleEventStart();	} 

Stop Fight (also unchanged, equivalent in TvTEvent class)

Code: Select all

 public static void stopFight()	{			// Set state INACTIVATING		setState(EventState.INACTIVATING); 		//Unspawn event npc		unSpawnNpc(); 		// Opens all doors specified in configs for dm		openDoors(Config.DM_DOORS_IDS_TO_CLOSE); 		// Closes all doors specified in Configs for dm		closeDoors(Config.DM_DOORS_IDS_TO_OPEN); 		// Iterate over all teams		for (DmEventTeam team : _players)		{			for (L2PcInstance playerInstance : team.getParticipatedPlayers().values())			{				// Check for nullpointer				if (playerInstance != null)				{					new DmEventTeleporter(playerInstance, Config.DM_EVENT_PARTICIPATION_NPC_COORDINATES, false, false);				}			}		} 		// Cleanup of teams		_players[0].cleanMe(); 		// Set state INACTIVE		setState(EventState.INACTIVE);	} 

Re: [Help] Thread management + DM Event

Posted: Thu Jul 15, 2010 12:21 pm
by jurchiks
and stopFight()?
i'm not searching this in epilogue code since i'm not working with it atm.

Re: [Help] Thread management + DM Event

Posted: Thu Jul 15, 2010 12:29 pm
by Raikkon35
Under my limited knowledge of Java, I think you should add the check in onkill.
And then, start the endEvent.

Re: [Help] Thread management + DM Event

Posted: Thu Jul 15, 2010 12:54 pm
by rychoo84
Raikkon35 wrote:Under my limited knowledge of Java, I think you should add the check in onkill.
And then, start the endEvent.
your modesty is unlimited...
Exactly this is what I was looking for :)
put this into onKill method:

Code: Select all

 if(CheckDmPlayerCountEqualToOne())      DmManager.getInstance().endEvent(); 
Thx for your tip Raikkon35