Jump to content

The RuneLocus forum has been archived and does not accept new registrations.
Click here for more information, and click here to join the community on Discord.

667/718 Random Events Base


bitmask
 Share

Recommended Posts

package com.enso.game.player.content.randomevent;

import com.enso.Configuration;
import com.enso.game.player.Player;
import com.enso.utils.Utils;
import java.io.Serializable;

/**
 * @author FUZENSETH
 */
public class RandomEventDelegate implements Serializable {
    
    private transient Player player;
    private transient RandomEvent randomEvent;
    private transient boolean loaded;
    private Object[] lastArguments;
    
    private String lastRandomEvent;
    
    public void startRandomEvent(String key, Object... parameters) {
		if (randomEvent != null)
			stop();
		randomEvent = RandomEventHandler.getRandomEvent(key);
		if (randomEvent == null)
			return;
		randomEvent.setPlayer(player);
		lastArguments = parameters;
		lastRandomEvent = key;
		randomEvent.start();
		loaded = true;
	}
    
        public void stop() {
		if (randomEvent != null) {
			randomEvent.stop();
			randomEvent = null;
		}
		lastArguments = null;
		lastRandomEvent = null;
		loaded = false;
	}
        
        public void process(int experience) {
            int random = Utils.random(0, RandomEventHandler.getRegisteredEvents().size());
           player.setExperienceTreshold(player.getExperienceTreshold() + experience);
          if (player.getExperienceTreshold() > getMaxExperienceTreshold()) {
              
          }
        }
        
       public Object[] getLastArguments() {
		return lastArguments;
	}
       
        public int getMaxExperienceTreshold() {
            return Configuration.RANDOM_EVENT_XP_TRESHOLD;
        }

     public void setLastArguments(Object[] objects) {
         objects = lastArguments;
    }
}
package com.enso.game.player.content.randomevent;

import com.enso.game.player.Player;


/**
 * @author FUZENSETH
 */
public abstract class RandomEvent {
   
    protected Player player;
    
    public void setPlayer(Player player) {
        this.player = player;
    }
    
    public abstract void start();
    
    public abstract void stop();
 
    
    public final Object[] getArguments() {
		return player.getRandomEventDelegate().getLastArguments();
	}
    
    public final void setArguments(Object[] objects) {
		player.getRandomEventDelegate().setLastArguments(objects);
    }
    
}
package com.enso.game.player.content.randomevent;

import com.enso.game.player.content.randomevent.impl.FrogEvent;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author FUZENSETH
 */
public class RandomEventHandler {
    
    private static final HashMap<Object, Class<RandomEvent>> registeredEvents = new HashMap<>();
    
    public static void loadRegisteredEvents() {
        try {
            registeredEvents.put("frog_event", (Class<RandomEvent>) Class.forName(FrogEvent.class.getCanonicalName()));
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(RandomEventHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static RandomEvent getRandomEvent(Object key) {
     if (key instanceof RandomEvent)
			return (RandomEvent) key;
		Class<RandomEvent> subClass = registeredEvents.get(key);
		if (subClass == null)
			return null;
		try {
			return subClass.newInstance();
		} catch (InstantiationException | IllegalAccessException e) {
                   
                }
		return null;
    }
    
    public static void reloadAll() {
        registeredEvents.clear();
        loadRegisteredEvents();
    }
    
}

 

Edited by FUZENSETH
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...