RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.util.GameSaver Class Reference

Created by Daniel on 2017-11-05. More...

Static Public Member Functions

static void load ()
static void save ()
static JsonObject toJson ()

Static Public Attributes

static long ITEMS_SOLD = 0
static int MAX_PLAYERS
static long PERSONAL_ITEM_WORTH = 0

Detailed Description

Created by Daniel on 2017-11-05.

Definition at line 20 of file GameSaver.java.

Member Function Documentation

◆ load()

void com.runehive.util.GameSaver.load ( )
static

Definition at line 64 of file GameSaver.java.

64 {
65 new GsonParser("content/game/world") {
66 @Override
67 protected void parse(JsonObject object) {
68 MAX_PLAYERS = object.get("max-players").getAsInt();
69
70 /* Well of Goodwill */
71 WellOfGoodwill.activeTime = object.get("wog-active-time").getAsInt();
72 WellOfGoodwill.CONTRIBUTION = object.get("wog-contribution").getAsInt();
73
74 if (object.has("wog-last-contributor")) {
75 WellOfGoodwill.lastContributor = object.get("wog-last-contributor").getAsString();
76 }
77
78 final JsonArray contributors = object.get("contributors").getAsJsonArray();
79 for (JsonElement element : contributors) {
80 final JsonObject contributorObj = (JsonObject) element;
81 final String name = contributorObj.get("name").getAsString();
82 final Optional<PlayerRight> rank = PlayerRight.lookup(contributorObj.get("rank").getAsInt());
83 final int amount = contributorObj.get("amount").getAsInt();
84 WellOfGoodwill.add(name, rank.orElse(PlayerRight.PLAYER), amount);
85 }
86
87 /* Personal Store */
88 PERSONAL_ITEM_WORTH = object.get("personal-store-worth").getAsLong();
89 ITEMS_SOLD = object.get("personal-store-items-sold").getAsLong();
90 BotUtility.BOOT_LOOT = GsonUtils.JSON_PRETTY_ALLOW_NULL.get().fromJson(object.get("pk-bot-loot"), new TypeToken<HashMap<Integer, MutableNumber>>() { }.getType());
91 }
92 }.run();
93 }

References com.runehive.content.WellOfGoodwill.activeTime, com.runehive.content.WellOfGoodwill.add(), com.runehive.content.bot.BotUtility.BOOT_LOOT, com.runehive.content.WellOfGoodwill.CONTRIBUTION, ITEMS_SOLD, com.runehive.util.GsonUtils.JSON_PRETTY_ALLOW_NULL, com.runehive.content.WellOfGoodwill.lastContributor, com.runehive.game.world.entity.mob.player.PlayerRight.lookup(), MAX_PLAYERS, PERSONAL_ITEM_WORTH, and com.runehive.game.world.entity.mob.player.PlayerRight.PLAYER.

Referenced by com.runehive.RuneHive.processParallelStartupTasks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save()

void com.runehive.util.GameSaver.save ( )
static

Definition at line 26 of file GameSaver.java.

26 {
27 Thread.startVirtualThread(() -> {
28 try (FileWriter fw = new FileWriter("./data/content/game/world.json")) {
29 fw.write(GsonUtils.JSON_PRETTY_NO_NULLS.get().toJson(toJson()));
30 } catch (final Exception e) {
31 e.printStackTrace();
32 }
33 });
34 }

References com.runehive.util.GsonUtils.JSON_PRETTY_NO_NULLS, and toJson().

Referenced by com.runehive.game.world.World.save().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toJson()

JsonObject com.runehive.util.GameSaver.toJson ( )
static

Definition at line 36 of file GameSaver.java.

36 {
37 JsonObject object = new JsonObject();
38
39 object.addProperty("max-players", MAX_PLAYERS);
40
41 /* Well of Goodwill */
42 object.addProperty("wog-active-time", WellOfGoodwill.activeTime);
43 object.addProperty("wog-contribution", WellOfGoodwill.CONTRIBUTION);
44 object.addProperty("wog-last-contributor", WellOfGoodwill.lastContributor);
45
46 JsonArray wogArray = new JsonArray();
47 for (Contributor contributor : WellOfGoodwill.contributors) {
48 JsonObject contributorObj = new JsonObject();
49 contributorObj.addProperty("name", contributor.name);
50 contributorObj.addProperty("rank", contributor.rank.getCrown());
51 contributorObj.addProperty("amount", contributor.contribution);
52 wogArray.add(contributorObj);
53 }
54
55 object.add("contributors", wogArray);
56
57 /* Personal Store */
58 object.addProperty("personal-store-worth", PERSONAL_ITEM_WORTH);
59 object.addProperty("personal-store-items-sold", ITEMS_SOLD);
60 object.add("pk-bot-loot", GsonUtils.JSON_PRETTY_ALLOW_NULL.get().toJsonTree(BotUtility.BOOT_LOOT));
61 return object;
62 }

References com.runehive.content.WellOfGoodwill.activeTime, com.runehive.content.bot.BotUtility.BOOT_LOOT, com.runehive.content.WellOfGoodwill.CONTRIBUTION, com.runehive.content.WellOfGoodwill.Contributor.contribution, com.runehive.content.WellOfGoodwill.contributors, com.runehive.game.world.entity.mob.player.PlayerRight.getCrown(), ITEMS_SOLD, com.runehive.util.GsonUtils.JSON_PRETTY_ALLOW_NULL, com.runehive.content.WellOfGoodwill.lastContributor, MAX_PLAYERS, com.runehive.content.WellOfGoodwill.Contributor.name, PERSONAL_ITEM_WORTH, and com.runehive.content.WellOfGoodwill.Contributor.rank.

Referenced by save().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ ITEMS_SOLD

long com.runehive.util.GameSaver.ITEMS_SOLD = 0
static

◆ MAX_PLAYERS

int com.runehive.util.GameSaver.MAX_PLAYERS
static

◆ PERSONAL_ITEM_WORTH

long com.runehive.util.GameSaver.PERSONAL_ITEM_WORTH = 0
static

The documentation for this class was generated from the following file: