RuneHive-Game
Loading...
Searching...
No Matches
GroundItemEvent.java
Go to the documentation of this file.
1package com.runehive.game.world.items.ground;
2
3import com.runehive.game.task.Task;
4import com.runehive.game.world.World;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.game.world.region.Region;
7import com.runehive.net.packet.out.SendGroundItem;
8
9/**
10 * @author <a href="http://www.rune-server.org/members/stand+up/">Stand Up</a>
11 * @since 27-12-2016.
12 */
13public final class GroundItemEvent extends Task {
14
15 /** A variable which indicates how many ticks a minute is. */
16 private static final int MINUTE = 100;
17
18 /** The ground item this randomevent is running for. */
19 private final GroundItem groundItem;
20
21 /** The counter of this task. */
22 private int minutes;
23
24 /** Creates a new {@link Task} that doesn't execute instantly. */
26 super(MINUTE);
27 this.groundItem = groundItem;
28 }
29
30 @Override
31 public void execute() {
32 switch (groundItem.policy) {
33 case GLOBAL:
34 if (++minutes < 5) {
35 return;
36 }
37
38 if (groundItem.item.getId() == 12791) {
39 groundItem.player.runePouch.runes.clear();
40 }
41
42 cancel();
43 break;
44 case ONLY_OWNER:
45 if (++minutes < 2) {
46 return;
47 }
48
49 groundItem.policy = GroundItemPolicy.GLOBAL;
50 if (!groundItem.item.isTradeable()) {
51 return;
52 }
53 //If a player drops an item, only they will be able to view it
54 if(groundItem.player.playTime < 6000) {
55 return;
56 }
57
58 Region[] regions = World.getRegions().getSurroundingRegions(groundItem.getPosition());
59 for (Region region : regions) {
60 for (Player player : region.getPlayers(groundItem.getHeight())) {
61 if (!groundItem.isRegistered())
62 continue;
63
64 if (!groundItem.canSee(player))
65 continue;
66
67 if (groundItem.player.usernameLong != player.usernameLong)
68 player.send(new SendGroundItem(groundItem));
69 }
70 }
71 break;
72 }
73 }
74
75 @Override
76 protected void onCancel(boolean logout) {
77 groundItem.unregister();
78 }
79
80}
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
Task(boolean instant, int delay)
Creates a new Task.
Definition Task.java:41
Represents the game world.
Definition World.java:46
static RegionManager getRegions()
Definition World.java:552
This class represents a character controlled by a player.
Definition Player.java:125
static final int MINUTE
A variable which indicates how many ticks a minute is.
void execute()
A function representing the unit of work that will be carried out.
final GroundItem groundItem
The ground item this randomevent is running for.
GroundItemEvent(GroundItem groundItem)
Creates a new Task that doesn't execute instantly.
void onCancel(boolean logout)
A function executed on cancellation.
Represents a single Ground item on the world map.
Represents a single region.
Definition Region.java:21
Region[] getSurroundingRegions(Position position)
Gets the regions surrounding a position.