Thread: [Shard] Using public event instead of Process

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 [Shard] Using public event instead of Process 
    Уважение и любовь Market Banned Market Banned

    R0cky 0wnz's Avatar
    Join Date
    Mar 2008
    Age
    28
    Posts
    2,569
    Thanks given
    642
    Thanks received
    511
    Rep Power
    1716
    Alright, am I doing it right?

    --

    Added class (using it for all processing stuff used on public event)

    (Thanks to ultimate)
    Code:
    package server.model.player;
    import server.events.Event;
    import server.events.EventContainer;
    import server.model.player.Client;
    import server.world.PlayerManager;
    
    public class RestoreEvent implements Event {
    
    	@Override
    	public void execute(EventContainer container) {
    for(Player p : PlayerManager.getSingleton().getPlayers()){
    	if(p == null) continue;
    		if (p.playerEnergy < 100) {
    		((Client) p).getActionAssistant().sendFrame126("@[email protected]"+p.playerEnergy + "%", 149);
    		if(System.currentTimeMillis() - p.lastIncrease >= 6000){
    			p.playerEnergy += 1;
    			p.lastIncrease = System.currentTimeMillis();
    		}
    		}
    
    		if(System.currentTimeMillis() - p.restoreStatsDelay >  40000) {
    			p.restoreStatsDelay = System.currentTimeMillis();
    			for (int level = 0; level < p.playerLevel.length; level++)  {
    				if (p.playerLevel[level] < ((Client) p).getActionAssistant().getLevelForXP(p.playerXP[level])) {
    					if(level != 5) { // prayer doesn't restore
    						p.playerLevel[level] += 1;
    						((Client) p).getActionAssistant().setSkillLevel(level, p.playerLevel[level], p.playerXP[level]);
    						((Client) p).getActionAssistant().refreshSkill(level);
    					}
    				} else if (p.playerLevel[level] > ((Client) p).getActionAssistant().getLevelForXP(p.playerXP[level])) {
    					p.playerLevel[level] -= 1;
    					((Client) p).getActionAssistant().setSkillLevel(level, p.playerLevel[level], p.playerXP[level]);
    					((Client) p).getActionAssistant().refreshSkill(level);
    				}
    			}	
    		}
    
    		if(System.currentTimeMillis() - p.skullDelay >= 1200000 && p.isSkulled){
    			p.isSkulled = false;
    			if(p.isSkulled) {
    				p.headIcon = 1;
    			} else {
    				p.headIcon = 0;
    			}
            		p.updateRequired = true;
            		p.appearanceUpdateRequired = true;
    		}
    
    		((Client) p).getCombatManager().process();
    		if (p.playerLevel[3] <= 0) {
    			p.isDead = true;
    		}
    		if (p.isDead) {
    			if (!p.isDeadWaiting) {
    					((Client) p).getActionAssistant().applyDead();
    			} else {
    				if (p.isDeadTimer == 0) {
    					((Client) p).getActionAssistant().giveLife();
    				}
    				p.isDeadTimer--;
    			}
    		}
    
    }
    }
    	
    	public void stop() {
    	}
    }
    and added it into Eventmanager intialize
    Code:
    	public static EventManager getSingleton() {
    		if (singleton == null) {
    			singleton = new EventManager();
    			singleton.thread = new Thread(singleton, "eventManager");
    			singleton.thread.start();
    			singleton.addEvent(null, new RestoreEvent(), 500);
    		}
    		return singleton;
    	}

    So now my Process() method is fully clean..

    Is this the right way? since using process method is so bad..


    Thanks.
    SELLING CREATIVESCAPE 2012 SOURCE

    [Only registered and activated users can see links. ]

    Snippets
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Уважение и любовь Market Banned Market Banned

    R0cky 0wnz's Avatar
    Join Date
    Mar 2008
    Age
    28
    Posts
    2,569
    Thanks given
    642
    Thanks received
    511
    Rep Power
    1716
    any1??
    SELLING CREATIVESCAPE 2012 SOURCE

    [Only registered and activated users can see links. ]

    Snippets
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Oct 2007
    Posts
    1,017
    Thanks given
    1
    Thanks received
    3
    Rep Power
    562
    You're still using a timer which runs every 500 milleseconds. Some things should be in proccess, like combat. But some things you can change. Let's say you have an eatDelay. Then you would do something like this:

    Code:
    eatDelay = 4;
    And in your process, you would have:

    Code:
    if (eatDelay > 0)
    eatDelay--;
    This basically means it has to count 4 four times before actually executing the event, this can be done much easier. You should execute an event after 2000 MS (5x400) MS.

    Code:
    EventManager.getSingleton().addEvent(player, new Event() {
    				public void execute(EventContainer c) {
    					//EAT STUFF HERE 
    					c.stop();
    				}
    
    				@Override
    				public void stop() {
    					
    				}
    			}, 2000);
    <William.D | Perfectworld> before
    Reply With Quote  
     

  4. #4  
    Уважение и любовь Market Banned Market Banned

    R0cky 0wnz's Avatar
    Join Date
    Mar 2008
    Age
    28
    Posts
    2,569
    Thanks given
    642
    Thanks received
    511
    Rep Power
    1716
    no these are restore stat events. Im using eat stuff right way
    SELLING CREATIVESCAPE 2012 SOURCE

    [Only registered and activated users can see links. ]

    Snippets
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. #5  
    Apocalyptism
    Harry's Avatar
    Join Date
    Apr 2007
    Posts
    3,783
    Thanks given
    594
    Thanks received
    1,833
    Rep Power
    2934
    shards process already uses an event i think
    ~ Harry
    Please bear this in mind when hearing the word 'soon' from a software programmer.

    As coding software generally takes thousands of years, software programmers have developed a natural adaptation to this in the form of an altered perception of the flow of time.

    Due to this, the word 'soon' when uttered by a programmer should be taken to mean 'a very, very long time from now' in the terminology used by common human specimens who have not developed such an adaptation.
    knowledge can be taught, but passion cannot.
    It's better to create something that others criticise than to create nothing and criticise others.
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Jan 2009
    Posts
    778
    Thanks given
    74
    Thanks received
    61
    Rep Power
    0
    Wouldn't this be near enough the same as having process?
    Reply With Quote  
     

  7. #7  
    Уважение и любовь Market Banned Market Banned

    R0cky 0wnz's Avatar
    Join Date
    Mar 2008
    Age
    28
    Posts
    2,569
    Thanks given
    642
    Thanks received
    511
    Rep Power
    1716
    using process is wrong, idk
    SELLING CREATIVESCAPE 2012 SOURCE

    [Only registered and activated users can see links. ]

    Snippets
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #8  
    Registered Member

    Join Date
    Oct 2007
    Posts
    1,017
    Thanks given
    1
    Thanks received
    3
    Rep Power
    562
    But you're still doing your restore every 500 MS, execute it in 30.000 ms or something.
    <William.D | Perfectworld> before
    Reply With Quote  
     

  9. #9  
    Уважение и любовь Market Banned Market Banned

    R0cky 0wnz's Avatar
    Join Date
    Mar 2008
    Age
    28
    Posts
    2,569
    Thanks given
    642
    Thanks received
    511
    Rep Power
    1716
    ok thx
    SELLING CREATIVESCAPE 2012 SOURCE

    [Only registered and activated users can see links. ]

    Snippets
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  10. #10  
    fb slider
    Guest
    execute it in 20.000 or what ever you want, don't have it that low.
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •