RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.content.mysterybox.MysteryBoxEvent Class Reference
Inheritance diagram for com.runehive.content.mysterybox.MysteryBoxEvent:
Collaboration diagram for com.runehive.content.mysterybox.MysteryBoxEvent:

Protected Member Functions

boolean canSchedule ()
 A function executed on registration.
void onCancel (boolean logout)
 A function executed on cancellation.
void onSchedule ()
 A function executed on registration.
void tick ()
Protected Member Functions inherited from com.runehive.game.task.Task
void baseExecute ()

Package Functions

 MysteryBoxEvent (Player player)
Package Functions inherited from com.runehive.game.task.Task
void onException (Exception e)
 A function executed on thrown exceptions.
void onLoop ()
 A function executed when iterated over.
final synchronized void process ()
synchronized void setRunning (boolean running)

Private Member Functions

double getItemProbability (MysteryItem item)
MysteryItem getNextItem ()
void move ()
void reward ()

Private Attributes

List< MysteryItemallItems
List< MysteryItemitems
final MysteryBoxManager mysteryBox
final Player player
int speed

Additional Inherited Members

Public Member Functions inherited from com.runehive.game.task.TickableTask
void execute ()
 A function representing the unit of work that will be carried out.
 TickableTask (boolean instant, int delay)
Public Member Functions inherited from com.runehive.game.task.Task
Task attach (Object newKey)
 Attaches a new key.
synchronized final void cancel ()
 Cancels all subsequent executions.
synchronized final void cancel (boolean logout)
 Cancels all subsequent executions.
boolean canRun ()
 Determines if the task can be ran.
Optional< Object > getAttachment ()
String getCreationStackTraceStr ()
int getDelay ()
Long getElapsedTimeFromRunStartTime ()
Optional< Long > getRunStartTime ()
long getTaskCreationTime ()
String getTaskId ()
boolean isInstant ()
boolean isRunning ()
void setDelay (int delay)
 Sets the cyclic delay.
void setExecutionTime ()
 Task (boolean instant, int delay)
 Creates a new Task.
 Task (int delay)
 Creates a new Task that doesn't execute instantly.

Detailed Description

Definition at line 13 of file MysteryBoxEvent.java.

Constructor & Destructor Documentation

◆ MysteryBoxEvent()

com.runehive.content.mysterybox.MysteryBoxEvent.MysteryBoxEvent ( Player player)
package

Definition at line 21 of file MysteryBoxEvent.java.

21 {
22 super(false, 1);
23 this.player = player;
24 this.items = new ArrayList<>();
25 this.allItems = new ArrayList<>();
26 this.speed = Utility.random(30, 40);
27 this.mysteryBox = player.mysteryBox;
28 }

References player, and com.runehive.util.Utility.random().

Here is the call graph for this function:

Member Function Documentation

◆ canSchedule()

boolean com.runehive.content.mysterybox.MysteryBoxEvent.canSchedule ( )
protected

A function executed on registration.

Reimplemented from com.runehive.game.task.Task.

Definition at line 95 of file MysteryBoxEvent.java.

95 {
96 return player.mysteryBox.box != null;
97 }

◆ getItemProbability()

double com.runehive.content.mysterybox.MysteryBoxEvent.getItemProbability ( MysteryItem item)
private

Definition at line 49 of file MysteryBoxEvent.java.

49 {
50 switch (item.rarity) {
51 case COMMON:
52 return 0.40;
53 case UNCOMMON:
54 return 0.35;
55 case RARE:
56 return 0.15;
57 case EXOTIC:
58 return 0.10;
59 default:
60 return 0;
61 }
62 }

References com.runehive.content.mysterybox.MysteryItem.rarity.

Referenced by reward().

Here is the caller graph for this function:

◆ getNextItem()

MysteryItem com.runehive.content.mysterybox.MysteryBoxEvent.getNextItem ( )
private

Definition at line 38 of file MysteryBoxEvent.java.

38 {
39 MysteryItem next = null;
40 for (MysteryItem item : allItems) {
41 if (!items.contains(item)) {
42 next = item;
43 break;
44 }
45 }
46 return next;
47 }

References allItems, and items.

Referenced by move().

Here is the caller graph for this function:

◆ move()

void com.runehive.content.mysterybox.MysteryBoxEvent.move ( )
private

Definition at line 30 of file MysteryBoxEvent.java.

30 {
31 allItems.add(items.get(0));
32 items.remove(0);
33 MysteryItem next = getNextItem();
34 allItems.remove(next);
35 items.add(next);
36 }

References allItems, getNextItem(), and items.

Here is the call graph for this function:

◆ onCancel()

void com.runehive.content.mysterybox.MysteryBoxEvent.onCancel ( boolean logout)
protected

A function executed on cancellation.

Reimplemented from com.runehive.game.task.Task.

Definition at line 124 of file MysteryBoxEvent.java.

124 {
125 if (logout) {
126 player.inventory.add(mysteryBox.box.item(), 1);
127 } else {
128 reward();
129 }
130 }

References mysteryBox, player, and reward().

Here is the call graph for this function:

◆ onSchedule()

void com.runehive.content.mysterybox.MysteryBoxEvent.onSchedule ( )
protected

A function executed on registration.

Reimplemented from com.runehive.game.task.Task.

Definition at line 99 of file MysteryBoxEvent.java.

99 {
100 player.dialogueFactory.clear();
101 player.locking.lock();
102 allItems.addAll(Arrays.asList(mysteryBox.box.rewards()));
103 player.inventory.remove(mysteryBox.box.item(), 1);
104 mysteryBox.count = player.inventory.computeAmountForId(mysteryBox.box.item());
105 Collections.shuffle(allItems);
106 for (int index = 0; index < 11; index++) {
107 if (index >= allItems.size())
108 continue;
109 MysteryItem item = allItems.get(index);
110 items.add(item);
111 allItems.remove(index);
112 }
113
114 player.send(new SendColor(59508, 0xF01616));
115 player.send(new SendString("You have " + mysteryBox.count + " mystery box available!", 59507));
116 }
val index

References allItems, items, mysteryBox, and player.

◆ reward()

void com.runehive.content.mysterybox.MysteryBoxEvent.reward ( )
private

Definition at line 66 of file MysteryBoxEvent.java.

66 {
67 double randomValue = Math.random();
68 double cumulativeProbability = 0.0;
69 MysteryItem reward = null;
70
71 Collections.sort(items, Comparator.comparingDouble(this::getItemProbability).reversed());
72
73 for (MysteryItem item : items) {
74 double itemProbability = getItemProbability(item);
75 cumulativeProbability += itemProbability;
76 if (randomValue <= cumulativeProbability) {
77 reward = item;
78 break;
79 }
80 }
81
82 if(reward == null) {
83 reward = items.get(0);
84 }
85 if (reward.rarity == MysteryRarity.EXOTIC) {
86 World.sendMessage("<icon=17><col=5739B3> osroyale: <col=" + player.right.getColor() + ">" + player.getName() + " </col>has won " + Utility.getAOrAn(reward.getName()) + " <col=5739B3>" + reward.getName() + " </col>from the <col=5739B3>" + mysteryBox.box.name() + "</col>.");
87 }
88
89 player.locking.unlock();
90 player.inventory.add(reward.getId(), reward.getAmount());
91 player.message("Congratulations! You have won @red@" + Utility.getAOrAn(reward.getName()) + " " + reward.getName() + "!\nThis item falls in the rarity of " + reward.rarity.name().toLowerCase() + ".");
92 System.out.println("Rarity: " + reward.rarity.name().toLowerCase());
93 }

References com.runehive.content.mysterybox.MysteryRarity.EXOTIC, com.runehive.util.Utility.getAOrAn(), getItemProbability(), items, mysteryBox, player, reward(), and com.runehive.game.world.World.sendMessage().

Referenced by onCancel(), and reward().

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

◆ tick()

void com.runehive.content.mysterybox.MysteryBoxEvent.tick ( )
protected

Reimplemented from com.runehive.game.task.TickableTask.

Definition at line 119 of file MysteryBoxEvent.java.

119 {
120 cancel();
121 }

References com.runehive.game.task.Task.cancel().

Here is the call graph for this function:

Member Data Documentation

◆ allItems

List<MysteryItem> com.runehive.content.mysterybox.MysteryBoxEvent.allItems
private

Definition at line 16 of file MysteryBoxEvent.java.

Referenced by getNextItem(), move(), and onSchedule().

◆ items

List<MysteryItem> com.runehive.content.mysterybox.MysteryBoxEvent.items
private

Definition at line 15 of file MysteryBoxEvent.java.

Referenced by getNextItem(), move(), onSchedule(), and reward().

◆ mysteryBox

final MysteryBoxManager com.runehive.content.mysterybox.MysteryBoxEvent.mysteryBox
private

Definition at line 18 of file MysteryBoxEvent.java.

Referenced by onCancel(), onSchedule(), and reward().

◆ player

final Player com.runehive.content.mysterybox.MysteryBoxEvent.player
private

Definition at line 14 of file MysteryBoxEvent.java.

Referenced by MysteryBoxEvent(), onCancel(), onSchedule(), and reward().

◆ speed

int com.runehive.content.mysterybox.MysteryBoxEvent.speed
private

Definition at line 17 of file MysteryBoxEvent.java.


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