Dismiss Notice
Wynncraft, the Minecraft MMORPG. Play it now on your Minecraft client at (IP): play.wynncraft.com. No mods required! Click here for more info...
Dismiss Notice
Have some great ideas for Wynncraft? Join the official CT (content team) and help us make quests, builds, cinematics and much more!

World Ocean Currents! Code Included!(+ 60 Supporters)

Discussion in 'General Suggestions' started by Arreme, Feb 19, 2016.

?

Would you like to see this in-game?

  1. Yes. +1 Supporter

    87.5%
  2. No. +0 Supporters

    12.5%
Thread Status:
Not open for further replies.
  1. Arreme

    Arreme Veteran, Learning Game Design VIP+

    Messages:
    378
    Likes Received:
    328
    Trophy Points:
    85
    Minecraft:
    Hello Wynncraftians!
    In my opinion this idea can improve a lot the server
    so read carefully!
    :saltedhappy:

    --)Ocean Currents(--
    General Information:
    What are they?
    An Ocean current is a continuous, directed and superficial movement of sea water.

    What utilities will they have?


    When you have to go to the Mage Island, when you have to travel to the Dead Island, or just you have to go to Selchar adn you don't have any TP scrolls, is always a bit tedious to travel. So, what basically will they do is to make you travel faster! The mechanics will be more complicated of course.

    Explaining The Mechanics:
    Map Distribution:
    MP8raN6.jpg

    Directions:
    Every Current will have a specific direction. For example, if you want to go to Nemract to Selchar, you will have to catch the blue current. Going against the current direction will give you Slowness 4, so you will practically not move. On the other hand, going at the same direction of the current, will give you instead a huge speed bonus.
    Cold and Hot Currents:
    You can see that there are 2 types of Currents: Hot and Cold ones. Cold currents go slower than hot ones, but they are used for traveling, as you can see in the image (50%+ speed). Hot ones, however, are used for returning or exploring (Example: Mage Island-Half Moon Island- Durums Island), but they go FASTER (100%+).

    The Code:
    Yea, the code for doing this is done, so now we can perfectly tell that this is possible! Everything on this code section was written by @Ironraptor3 , he did an awesome job! ^^
    Code:
    public class Main extends JavaPlugin implements Listener {
        //And obviously, anyone with an interest in making plugins can always talk to me if you want help
        public static Plugin plugin;
        World w = null;
        public static final double speed = .3; //again, changeable, or able to be stored in another class and altered
        //Testing speed at 1 was pretty violent when opposing the current
    
        //Add a config file to save current info in between sessions, too lazy to do that for just an example
    
        @Override
        public void onEnable() {
            plugin = this;
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            currentLoop();
        }
        @Override
        public void onDisable() {
            plugin = null;
        }
    
        public static ConcurrentHashMap<Boat, Long> removing = new ConcurrentHashMap<Boat, Long>();
        public static ConcurrentHashMap<Location, Vector> currents = new ConcurrentHashMap<Location, Vector>();
    
        public void currentLoop() {
            new BukkitRunnable() {
                @Override
                public void run() {
                    if (w == null) return;
                    for (Entity e : w.getEntities()) {
                        if (e instanceof Boat) {
                            Boat b = (Boat) e;
                            if (removing.containsKey(b)) {
                                if (b.getPassenger() != null && b.getPassenger() instanceof Player) removing.remove(b);
                                else if (System.currentTimeMillis() - removing.get(b) >= 10*1000) {
                                    removing.remove(b);//boats despawn within 10 seconds of being placed
                                    b.remove();
                                }
                            }
                            else {
                                if (b.getPassenger() == null || !(b.getPassenger() instanceof Player)) {
                                    removing.put(b, System.currentTimeMillis());
                                    continue;
                                }
                                /* You can make a separate stream class, adding equations for their shape,
                                 * dimensions, bounds, etc.  Its simpy an example, however, and if I
                                 * were to mess up, I would not wish to debug that~*/
                                for (Location location : currents.keySet()) {
                                    if (b.getLocation().distanceSquared(location) <= 100) {
                                        b.setVelocity(b.getVelocity().add( currents.get(location).normalize().multiply(speed) ));
                                        break;
                                    //Ew lots of braces
                                    }
                                }
                            }
                        }
                    }
                }
            }.runTaskTimer(plugin, 0, 5);
        }
    
        @EventHandler
        public void onClick(PlayerInteractEvent e) {
            //Just to make it easy, obviously permissions and everything, blah blah blah blah blahyou've read this several times
            //You know its up to you how to make it, its just an example
            if (e.getPlayer().isOp() && e.getPlayer().getInventory().getItemInHand().getType().equals(Material.EYE_OF_ENDER)) {
                Location l = e.getPlayer().getLocation();
                while (l.getBlock().getType() == null) l = l.subtract(0, 1, 0);
                currents.put(l, e.getPlayer().getEyeLocation().getDirection().setY(0));
                e.getPlayer().sendMessage(ChatColor.GREEN + "New current set!"); //debug message
            }
            else if (w == null && e.getPlayer().getInventory().getItemInHand().getType().equals(Material.BOAT)) w = e.getPlayer().getWorld();
        }
    }
    //Wow less than even 100 lines, what a miracle (mwahah take that people who said it couldnt be done effeciently or easily)
    //Written by Ironraptor3
    
    Improved Codes, also made by @Ironraptor3
    Main.java:
    Code:
    public class Main extends JavaPlugin implements Listener {
    
        public static Plugin plugin;
        World w = null;
        public static final double speed = .3;
    
        //sorry I suck with naming while coding <3
    
        @Override
        public void onEnable() {
            plugin = this;
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            //add currents here.  This is the equation for the top half of the volcano island circle (according to the wynn map coords)~
            //(Obviously can be changed from two Semi circles to 2 widened parabolas to improve performance further).
       
            OceanCurrent.currents.put(new OceanCurrent(new Equation("(250^2 + -1 * ((x+950)^2) ) ^ 0.5 - 3700",
                    "(-1* (x + 950)) / ((250^2 + -1 * ((x+950)^2) ) ^ 0.5)"), true, false, -1200, -700), true);
       
            currentLoop();
        }
        @Override
        public void onDisable() {
            plugin = null;
        }
    
        public static ConcurrentHashMap<Boat, Long> removing = new ConcurrentHashMap<Boat, Long>();
    
        public void currentLoop() {
            new BukkitRunnable() {
                @Override
                public void run() {
                    if (w == null) return;
                    for (Entity e : w.getEntities()) {
                        if (e instanceof Boat) {
                            Boat b = (Boat) e;
                            if (removing.containsKey(b)) {
                                if (b.getPassenger() != null && b.getPassenger() instanceof Player) removing.remove(b);
                                else if (System.currentTimeMillis() - removing.get(b) >= 10*1000) {
                                    removing.remove(b);//boats despawn within 10 seconds of being placed
                                    b.remove();
                                }
                            }
                            else {
                                if (b.getPassenger() == null || !(b.getPassenger() instanceof Player)) {
                                    removing.put(b, System.currentTimeMillis());
                                    continue;
                                }
                                for (OceanCurrent oc : OceanCurrent.currents.keySet()) {
                                    if (OceanCurrent.currents.get(oc) == false)continue;
                                    Player p = (Player) b.getPassenger();
                                    if (oc.checkCoords(p)) {
                                        oc.setVelocity(p);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }.runTaskTimer(plugin, 0, 5);
        }
    
        @EventHandler
        public void onClick(PlayerInteractEvent e) {
            if (w == null && e.getPlayer().getInventory().getItemInHand().getType().equals(Material.BOAT)) w = e.getPlayer().getWorld();
        }
    
    }
    //Written by Ironraptor3
    
    OceanCurrent.java:
    Code:
    public class OceanCurrent {
    
        //Define these two with testing
        static double hotMultiplier = .15;
        static double coldMultiplier = .1;
    
        Equation e;
        boolean hot;
        boolean posDirection;
        double bound1;
        double bound2;
    
        public static ConcurrentHashMap<OceanCurrent, Boolean> currents = new ConcurrentHashMap<OceanCurrent, Boolean>();
    
        public OceanCurrent(Equation e, boolean hot, boolean posDirection, double bound1, double bound2) {
            this.e=e;
            this.hot=hot;
            this.posDirection=posDirection;
            this.bound1 = bound1;
            this.bound2 = bound2;
        }
        //add particles if you wish, the only thing is particles lag
    
        public boolean checkCoords(Player p) {
            int x = (int) Math.floor(p.getLocation().getX());
            if (x < bound1 || x > bound2) return false;
            //unsure why something that can only be an integer states it returns a double, thanks java
            double z = p.getLocation().getZ();
            if (Math.abs(this.e.evaluate(x)-z) <= 20) return true;
            else return false;
        }
    
        public void setVelocity(Player p) {
            int x = (int) Math.floor(p.getLocation().getX());
            double slope = this.e.getTangent(x);
            Vector v = new Vector(1, 0, slope).normalize().multiply( (this.posDirection ? 1:-1)* (this.hot ? hotMultiplier:coldMultiplier));
            p.setVelocity(p.getVelocity().add(v));
        }
    }
    
    Equation.java:
    Code:
    public class Equation {
    
        String e;
        String d;
    
        public Equation(String e, String d) {
            this.e=e;
            this.d=d;
        }
    
        public double evaluate(double x) {
            return solve(e,x);
        }
    
        public double getTangent(double x) {
            return solve(d,x);
        }
        public static void main(String[] args) {
            System.out.println(new Equation("((62500 + -1 * ((x+950)^2) ) ^ 0.5)+ -3700", "0").evaluate(-950));
        }
        //warning: not perfect order of operations (P EMD AS) rather than (P E MD AS)
        //Please do not subtract, rather, use *-1 to numbers.  Do not write things such as 3x, write 3 * x
        //If you wish to fix any of this, it is relatively simple, use debug statements to check
        //You can also make a function for finding the derivative of this function, meh
        //But yeah, do with this what you will~
        @SuppressWarnings("unchecked")
        public static double solve(String s, double x) {
            List<Object> terms = new ArrayList<Object>();
            terms.add((double) 0);
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == '(') {
                    for (int p = s.length() - 1; p > i; p--) if (s.charAt(p) == ')'){
                        terms.add(solve(s.substring(i+1, p), x));
                        i=p;
                        break;
                    }
                }
                else {
                    char current = s.charAt(i);
                    if (current == 'x') {
                        terms.add(x);
                    }
                    else if (Character.isDigit(current) || current == '.' || current == '-') {
                        for (int c = i; c <= s.length(); c++) {
                            if (c == s.length() || s.charAt(c) == ' ') {
                                terms.add(Double.parseDouble(s.substring(i, c)) );
                                i = c;
                                break;
                            }
                        }
                    }
                    else if (current == '*' || current == '/' || current == '^') terms.add(current);
                }   
            }
       
            if (terms.isEmpty()) return 0;
            else {
                int index = 0;
                terms.remove(0);
                while (index < terms.size()-1) {
                    if (terms.get(index) instanceof Character) {
                        double num;
                        double old1 = ((double) terms.get(index - 1));
                        double old2 = ((double) terms.get(index + 1));
                        Character c = (Character) terms.get(index);
                        if ( c == '*') num =  old1 * old2;
                        else if ( c == '/') num =  old1 * old2;
                        else {
                            num =  Math.pow(old1, old2);
                        }
                        terms.remove(index);
                        terms.remove(old1);
                        terms.remove(old2);
                        terms.add(0, num);
                        index=0;
                   
                    }
                    index++;
                }
           
                double sum = 0;
                for (double d : (List<Double>) (List<?>) terms) {
                    sum+=d;
                }
                return sum;
            }
        }
    }


    The principal objective if this idea is to make ocean adventures funnier. With this, you will have to plan a bit your route, not only breaking your finger with the W key.
    Each current will have a name, just like "Great Wynn Current" or "Dead Current".

    Edit 1: Currents no longer force you to go to it's direction.

    Edit 2: We have the code for doing this now :P
    Edit 3: Improved Code pages. Last 3
    Edit 4: WATER PUSH YOU AGAIN! No lag involved


    THE GAME
    Can you find the missing island? :D

    :saltedhappy:
    Thanks for reading!
    Hope you have liked my idea and
    remember to leave some feedback below!
     
    Last edited: Feb 27, 2016
  2. flip

    flip Chef HERO

    Messages:
    3,748
    Likes Received:
    8,331
    Trophy Points:
    217
    Minecraft:
    Theres no Island of Flip, it was an easy find,

    Plus I would love to have currents its just that, they act almost like a wall of some sort @Donald Trump 16 .

    It would be a good idea at first but it would get annoying later on
     
    Defunct Fighter and Arreme like this.
  3. Stycore

    Stycore some random golem CHAMPION

    Messages:
    3,635
    Likes Received:
    1,166
    Trophy Points:
    91
    Minecraft:
    Bear zoo is missing
     
    Arreme likes this.
  4. Tantibus

    Tantibus Chairman of the Wynnviet Union, God of Dern CT Manager HERO GM CMD

    Messages:
    8,134
    Likes Received:
    20,393
    Trophy Points:
    217
    Creator Karma:
    Guild:
    Minecraft:
    The problem is, this would be super hard to implement. The game doesn't like tp'ing players who are riding entities. Even if it were to work, the view would be super jittery. Not to mention, just a small lag spike would have you frozen.
     
  5. RamonaFlowers

    RamonaFlowers Subspace Delivery Girl CHAMPION

    Messages:
    4,860
    Likes Received:
    13,174
    Trophy Points:
    217
    Guild:
    Minecraft:
    The missing island is Bear zoo.

    Other than that, it's a well thought out suggestion.
     
    Arreme likes this.
  6. Arreme

    Arreme Veteran, Learning Game Design VIP+

    Messages:
    378
    Likes Received:
    328
    Trophy Points:
    85
    Minecraft:
    Yeaa... I have already thought about that... I was thinking to change the water DataValue and then replace it making the currents in the map. Finally, we will only need to create a command that say if the player stands there will receive "x" speed to "x" direction. There is already a thing that make boats go faster if you are in group.
    @President Trump @Stycore @ItzFlip Added a poll, I forgot to put that before.
     
  7. captainganon

    captainganon God of k | Derpalope VIP+

    Messages:
    11,320
    Likes Received:
    33,307
    Trophy Points:
    229
    Minecraft:
    Hold on. What about the "+20% speed boost per Boat within 20 blocks" on boats? Couldn't you do something like that? Or is that not actually a thing?
     
    Gogeta likes this.
  8. Tantibus

    Tantibus Chairman of the Wynnviet Union, God of Dern CT Manager HERO GM CMD

    Messages:
    8,134
    Likes Received:
    20,393
    Trophy Points:
    217
    Creator Karma:
    Guild:
    Minecraft:
    That's not forcing the player in a direction. That's just a speed boost. I'm not a developer but I think that's just a standard movement speed attribute that just gets changed when it detects another boat in a certain radius.
     
    Kahsol likes this.
  9. captainganon

    captainganon God of k | Derpalope VIP+

    Messages:
    11,320
    Likes Received:
    33,307
    Trophy Points:
    229
    Minecraft:
    I mean, that works too. While you're on the current, you move faster. That's 70% of the suggestion anyways.
     
  10. Tantibus

    Tantibus Chairman of the Wynnviet Union, God of Dern CT Manager HERO GM CMD

    Messages:
    8,134
    Likes Received:
    20,393
    Trophy Points:
    217
    Creator Karma:
    Guild:
    Minecraft:
    It isn't. The current is supposed be pushing the player in a specific direction. If the player just moved faster on a current, they could still move at an equal speed moving against the current, than moving in the direction they're supposed to. Which would require a bunch of complicated techniques to make sure the player's in the right spot and facing the right direction just to assign the movement speed.
     
    Arreme and Kahsol like this.
  11. Arreme

    Arreme Veteran, Learning Game Design VIP+

    Messages:
    378
    Likes Received:
    328
    Trophy Points:
    85
    Minecraft:
    Well, if it's a problem to move a player to a specific direction we can just make it to move "Slower". That would be easier, right?
     
  12. Tantibus

    Tantibus Chairman of the Wynnviet Union, God of Dern CT Manager HERO GM CMD

    Messages:
    8,134
    Likes Received:
    20,393
    Trophy Points:
    217
    Creator Karma:
    Guild:
    Minecraft:
    Yes, that would be a solution but it'd still require a bunch of directional testing to adjust movement speed. And especially because several of these currents aren't straight lines along the cardinal directions, it'd require several, several areas to test for the player's view orientation.
     
    Arreme likes this.
  13. Arreme

    Arreme Veteran, Learning Game Design VIP+

    Messages:
    378
    Likes Received:
    328
    Trophy Points:
    85
    Minecraft:
    Yea, thats right... But I wanted to do the currents more "natural". Welp, Ill change the mechanics then.
     
  14. TrashcanMan

    TrashcanMan Hello I am here

    Messages:
    1,748
    Likes Received:
    864
    Trophy Points:
    117
    Looks like a good idea but as Tantibus said above it would probably be really hard to code.
     
  15. Arreme

    Arreme Veteran, Learning Game Design VIP+

    Messages:
    378
    Likes Received:
    328
    Trophy Points:
    85
    Minecraft:
    Yeaaa we have debated that... I changed to slowness, not to force you to go to certain direction, that will make things easier.
     
  16. Arreme

    Arreme Veteran, Learning Game Design VIP+

    Messages:
    378
    Likes Received:
    328
    Trophy Points:
    85
    Minecraft:
    bump bump :saltedhappy:
     
  17. Ironraptor3

    Ironraptor3 Dragon Slayer, Sabre, CS/Game Dev VIP

    Messages:
    1,103
    Likes Received:
    605
    Trophy Points:
    117
    Guild:
    Minecraft:
    I mean it shouldnt be too hard to code, instead of setting speed and adjusting for the players line of sight, all one would need to do is constantly add the currents' velocity vector to the player/boat's if they are in a certain location (which bounds could be set by implementing some thrown together editor code that saves to some sort of list). I definitely feel like ut could work, ill set up a test server and see how quickly i can pull this off with efficiency)
     
    Arreme likes this.
  18. Devourer

    Devourer Lava Warrior VIP+

    Messages:
    5,035
    Likes Received:
    1,761
    Trophy Points:
    83
    Minecraft:
    This is actually an interesting idea... the only problem is that most people use boats for travel. I think it is possible to make boats go faster (apparently you get +30% speed on boats if you are near other boats) but I'm not sure.
     
  19. Ironraptor3

    Ironraptor3 Dragon Slayer, Sabre, CS/Game Dev VIP

    Messages:
    1,103
    Likes Received:
    605
    Trophy Points:
    117
    Guild:
    Minecraft:
    Pretty sure he meant it affects boats primarily
     
  20. Arreme

    Arreme Veteran, Learning Game Design VIP+

    Messages:
    378
    Likes Received:
    328
    Trophy Points:
    85
    Minecraft:
    Yea, with boats. I think this could be perfectly done. @Ironraptor3 did you succed on the current test? :P
     
Thread Status:
Not open for further replies.