RuneHive-Game
Loading...
Searching...
No Matches
Agility.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.agility;
2
3import com.google.gson.Gson;
4import com.google.gson.GsonBuilder;
5import com.google.gson.JsonIOException;
6import com.google.gson.JsonSyntaxException;
7import com.runehive.Config;
8import com.runehive.content.skill.impl.agility.obstacle.Obstacle;
9import com.runehive.game.world.entity.mob.player.Player;
10import com.runehive.game.world.entity.skill.Skill;
11import com.runehive.game.world.items.Item;
12import com.runehive.game.world.position.Position;
13
14import java.io.*;
15import java.util.HashMap;
16import java.util.function.Consumer;
17
18/**
19 * Created by Daniel on 2017-11-02.
20 */
21public class Agility {
22 public static final int GNOME_FLAGS = 0b0111_1111;
23 public static final int BARBARIAN_FLAGS = 0b0111_1111;
24 public static final int WILDERNESS_FLAGS = 0b0001_1111;
25 public static final int SEERS_FLAGS = 0b0011_1111;
26 public static final int ARDOUGNE_FLAGS = 0b0111_1111;
27 public static final HashMap<Position, Obstacle> obstacles = new HashMap<>();
28
29 public static void declare() {
30 try {
31 Obstacle[] loaded = new Gson().fromJson(new BufferedReader(new FileReader("./data/content/skills/agility.json")), Obstacle[].class);
32 for (Obstacle obstacle : loaded) {
33 if (obstacle.getObjectPosition() == null) {
34 obstacle.setObjectPosition(obstacle.getStart());
35 }
36 if (obstacle.getType() == null) {
37 System.out.println(obstacle + " No object type found. FIX MUST FIX");
38 }
39 obstacles.put(obstacle.getObjectPosition(), obstacle);
40 }
41 } catch (JsonSyntaxException | JsonIOException | FileNotFoundException e) {
42 e.printStackTrace();
43 }
44 }
45
46 private final static double TICKET_EXPERIENCE = 50 * Config.AGILITY_MODIFICATION;
47
48 public static boolean clickButton(Player player, int button) {
49 int amount = -1;
50 Consumer<Player> onClick = null;
51
52 switch (button) {
53 case 8387:
54 amount = 1;
55 onClick = p -> p.skills.addExperience(Skill.AGILITY, TICKET_EXPERIENCE * 1);
56 break;
57 case 8389:
58 amount = 10;
59 onClick = p -> p.skills.addExperience(Skill.AGILITY, TICKET_EXPERIENCE * 10);
60 break;
61 case 8390:
62 amount = 25;
63 onClick = p -> p.skills.addExperience(Skill.AGILITY, TICKET_EXPERIENCE * 25);
64 break;
65 case 8391:
66 amount = 100;
67 onClick = p -> p.skills.addExperience(Skill.AGILITY, TICKET_EXPERIENCE * 100);
68 break;
69 case 8392:
70 amount = 1_000;
71 onClick = p -> p.skills.addExperience(Skill.AGILITY, TICKET_EXPERIENCE * 1000);
72 break;
73 case 8382:
74 amount = 3;
75 onClick = p -> p.inventory.addOrDrop(new Item(3049, 1));
76 break;
77 case 8383:
78 amount = 10;
79 onClick = p -> p.inventory.addOrDrop(new Item(3051, 1));
80 break;
81 case 8381:
82 amount = 800;
83 onClick = p -> p.inventory.addOrDrop(new Item(2997, 1));
84 break;
85 }
86 if (amount > -1) {
87 if (player.inventory.contains(2996, amount)) {
88 player.inventory.remove(2996, amount);
89 onClick.accept(player);
90 player.interfaceManager.close();
91 return true;
92 } else {
93 player.message("You do not have enough agility tickets to purchase that.");
94 return true;
95 }
96 }
97 return false;
98 }
99
100 public static void main(String[] args) {
101 // Write the obstacles so we don't have to deal with a messy wall
102 // of code.
103// obstacles.put(new Location(2551, 3554), new Obstacle.ObstacleBuilder(ObstacleType.ROPE_SWING, new ObeliskData(2551, 3554), new ObeliskData(2551, 3549))
104// .setExperience(22f)
105// .setLevel(35)
106// .setOrdinal(0)
107// .setNext(new Obstacle.ObstacleBuilder(ObstacleType.ROPE_SWING, new Location(2551, 3554), new ObeliskData(2551, 3549)).build())
108// .build());
109
110 try (FileWriter writer = new FileWriter(new File("./data/def/skills/agility1.json"))) {
111 Gson builder = new GsonBuilder().setPrettyPrinting().create();
112
113 writer.write(builder.toJson(obstacles.values()).replaceAll("\\{\n \"x\"", "\\{ \"x\"").replaceAll(",\n \"y\"", ", \"y\"").replaceAll(",\n \"z\"", ", \"z\"").replaceAll("\n \\},", " \\},"));
114 } catch (Exception e) {
115 }
116 }
117
118}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double AGILITY_MODIFICATION
The experience modification for agility.
Definition Config.java:247
Created by Daniel on 2017-11-02.
Definition Agility.java:21
static boolean clickButton(Player player, int button)
Definition Agility.java:48
static final HashMap< Position, Obstacle > obstacles
Definition Agility.java:27
This class represents a character controlled by a player.
Definition Player.java:125
Represents a trainable and usable skill.
Definition Skill.java:18
static final int AGILITY
The agility skill id.
Definition Skill.java:69
The container class that represents an item that can be interacted with.
Definition Item.java:21
boolean remove(Item item)
Attempts to withdraw item from this container.
boolean contains(int id)
Determines if this container contains id.