RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Locking.java
1package com.osroyale.game.world.entity.mob;
2
3import com.osroyale.game.world.entity.mob.data.LockType;
4import com.osroyale.game.world.entity.mob.data.PacketType;
5
6import java.util.Arrays;
7import java.util.concurrent.TimeUnit;
8
44
45public class Locking {
46 private final Mob mob;
47 private LockType lock = null;
48 private long lockTime = -1;
49
50 Locking(Mob mob) {
51 this.mob = mob;
52 }
53
55 public void lock() {
56 lock(Integer.MAX_VALUE, LockType.MASTER);
57 }
58
59 public void lock(int time) {
60 lock(time, LockType.MASTER);
61 }
62
63 public void lock(LockType type) {
64 lock(Integer.MAX_VALUE, type);
65 }
66
68 public void lock(int time, LockType type) {
69 lock(time, TimeUnit.SECONDS, type);
70 }
71
73 public void lock(int time, TimeUnit gUnit, LockType type) {
74 long start = System.currentTimeMillis();
75 long timer = TimeUnit.MILLISECONDS.convert(time, gUnit);
76
77 if (Long.MAX_VALUE - start <= timer)
78 timer = (Long.MAX_VALUE - start);
79
80 if (type.execute(mob, time, gUnit)) {
81 mob.movement.reset();
82 lock = type;
83 lockTime = start + timer;
84 }
85 }
86
88 public boolean locked() {
89 if (mob.isDead())
90 return true;
91 boolean state = lock != null && lockTime - System.currentTimeMillis() >= 0;
92 if (!state) unlock();
93 return state;
94 }
95
96 public void status() {
97 System.out.println();
98 System.out.println("Lock Status");
99 System.out.println("Locked: " + locked(LockType.WALKING));
100 System.out.println("Lock Time: " + lockTime);
101 System.out.println("Lock: " + lock);
102 if (lock == null) {
103 System.out.println("Lock Packet: null");
104 } else {
105 System.out.println("Lock Packet: ");
106 Arrays.stream(lock.packets).forEach(System.out::println);
107 }
108
109 System.out.println();
110
111 }
112
114 public boolean locked(LockType type) {
115 return locked() && lock == type;
116 }
117
118 public boolean locked(PacketType packet) {
119 return locked() && lock.isLocked(packet);
120 }
121
122 public boolean locked(PacketType packet, Object object) {
123 return locked() && lock.isLocked(packet, mob, object);
124 }
125
127 public void unlock() {
128 lock = null;
129 lockTime = 0;
130 mob.freezeImmunity.reset();
131 }
132
133 public LockType getLock() {
134 return lock;
135 }
136}
void lock(int time, TimeUnit gUnit, LockType type)
Definition Locking.java:73
void lock(int time, LockType type)
Definition Locking.java:68