Closes #343. Allows multiple players to steal from a stall at the same tick. (#344)

This commit is contained in:
MitchvanWijngaarden
2020-01-01 18:51:12 +01:00
committed by Daniel Ginovker
parent d1c2150c60
commit 33ef596bd3
2 changed files with 84 additions and 68 deletions
@@ -10,7 +10,6 @@ import com.rebotted.game.content.skills.SkillHandler;
import com.rebotted.game.items.ItemAssistant; import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.items.ItemList; import com.rebotted.game.items.ItemList;
import com.rebotted.game.npcs.NpcHandler; import com.rebotted.game.npcs.NpcHandler;
import com.rebotted.game.objects.Object;
import com.rebotted.game.players.Player; import com.rebotted.game.players.Player;
import com.rebotted.util.Misc; import com.rebotted.util.Misc;
@@ -23,17 +22,17 @@ public class Stalls {
TEA_STALL(635, 5, 16, 0, new int[] {712, 1 }), TEA_STALL(635, 5, 16, 0, new int[] {712, 1 }),
SILK_STALL(2560, 20, 24, 2, new int[] { 950, 1 }), SILK_STALL(2560, 20, 24, 2, new int[] { 950, 1 }),
WINE_STALL(14011, 22, 27, 0, new int[] { 1935, 1 }, new int[] {i("jug of water"), 1 }, new int[] { i("jug of wine"), 1 }, WINE_STALL(14011, 22, 27, 0, new int[] { 1935, 1 }, new int[] {i("jug of water"), 1 }, new int[] { i("jug of wine"), 1 },
new int[] { i("grapes"), 1 }), SEED_STALL(7053, 27, 10, 0, new int[] { i("potato seed"), 1 }, new int[] {i("onion seed"), 1 }, new int[] { i("grapes"), 1 }), SEED_STALL(7053, 27, 10, 0, new int[] { i("potato seed"), 1 }, new int[] {i("onion seed"), 1 },
new int[] { i("cabbage seed"), 1 }, new int[] {i("tomato seed"), 1 }, new int[] { i("sweetcorn seed"), 1 }, new int[] { i("strawberry seed"), 1 }, new int[] { i("cabbage seed"), 1 }, new int[] {i("tomato seed"), 1 }, new int[] { i("sweetcorn seed"), 1 }, new int[] { i("strawberry seed"), 1 },
new int[] {i("watermelon seed"), 1 }, new int[] {i("barley seed"), 1 }, new int[] { i("jute seed"), 1 }, new int[] { i("marigold seed"), 1 }, new int[] {i("watermelon seed"), 1 }, new int[] {i("barley seed"), 1 }, new int[] { i("jute seed"), 1 }, new int[] { i("marigold seed"), 1 },
new int[] {i("rosemary seed"), 1 }, new int[] {i("hammerstone seed"), 1 }, new int[] {i("asgarnain seed"), 1 }, new int[] {i("yanillian seed"), 1 }, new int[] {i("rosemary seed"), 1 }, new int[] {i("hammerstone seed"), 1 }, new int[] {i("asgarnain seed"), 1 }, new int[] {i("yanillian seed"), 1 },
new int[] {i("krandorian seed"), 1 }, new int[] {i("wildblood seed"), 1 }), FUR_STALL(2563, 35, 36, 0, new int[] { 6814, 1 }, new int[] { 958, 1 }), new int[] {i("krandorian seed"), 1 }, new int[] {i("wildblood seed"), 1 }), FUR_STALL(2563, 35, 36, 0, new int[] { 6814, 1 }, new int[] { 958, 1 }),
FUR_STALL2(4278, 35, 36, 0, new int[] { 6814, 1 }, new int[] { 958, 1 }), FUR_STALL2(4278, 35, 36, 0, new int[] { 6814, 1 }, new int[] { 958, 1 }),
FISH_STALL(4705, 42, 42, 0, new int[] { 359, 1 }), FISH_STALL(4705, 42, 42, 0, new int[] { 359, 1 }),
FISH_STALL2(4277, 42, 42, 0, new int[] { 359, 1 }), FISH_STALL2(4277, 42, 42, 0, new int[] { 359, 1 }),
SILVER_STALL(2565, 50, 54, 2, new int[] { 442, 1 }, new int[] { 2355, 1 }), SILVER_STALL(2565, 50, 54, 2, new int[] { 442, 1 }, new int[] { 2355, 1 }),
SPICE_STALL(2564, 65, 81.3, 0, new int[] { 2007, 1 }, new int[] { 946, 1 }, new int[] { 1550, 1 }), GEM_STALL(2562, 75, 160, 3, SPICE_STALL(2564, 65, 81.3, 0, new int[] { 2007, 1 }, new int[] { 946, 1 }, new int[] { 1550, 1 }), GEM_STALL(2562, 75, 160, 3,
new int[] { 1617, 1 }, new int[] { 1619, 1 }, new int[] { 1621, 1 }, new int[] { 1623, 1 }), new int[] { 1617, 1 }, new int[] { 1619, 1 }, new int[] { 1621, 1 }, new int[] { 1623, 1 }),
MAGIC_STALL(4877, 65, 100, 0, new int[] {i("air rune"), 1}, new int[] {i("water rune"), 1}, new int[] {i("fire rune"), 1}, new int[] {i("law rune"), 1}), MAGIC_STALL(4877, 65, 100, 0, new int[] {i("air rune"), 1}, new int[] {i("water rune"), 1}, new int[] {i("fire rune"), 1}, new int[] {i("law rune"), 1}),
SCIMITAR_STALL(4878, 65, 100, 0, new int[] {i("iron scimitar"), 1}, new int[] {i("steel scimitar"), 1}); SCIMITAR_STALL(4878, 65, 100, 0, new int[] {i("iron scimitar"), 1}, new int[] {i("steel scimitar"), 1});
@@ -121,8 +120,13 @@ public class Stalls {
if(objectId == s.getObject()) { if(objectId == s.getObject()) {
// Wait for respawn // Wait for respawn
if (System.currentTimeMillis() < s.respawnTime) { if (System.currentTimeMillis() < s.respawnTime) {
p.getPacketSender().sendMessage("You need to wait longer before you can thieve this stall!"); long timeFirstStealFromStall = s.respawnTime - (GameConstants.CYCLE_TIME * getRespawnTime(s.objectId));
return;
// If stealing from stall at the same tick as another player
if(p.hasThievedStall() || System.currentTimeMillis() - timeFirstStealFromStall >= GameConstants.CYCLE_TIME) {
p.getPacketSender().sendMessage("You need to wait longer before you can thieve this stall!");
return;
}
} }
// Thieving level too low // Thieving level too low
if (p.playerLevel[p.playerThieving] < s.getLevel()) { if (p.playerLevel[p.playerThieving] < s.getLevel()) {
@@ -144,11 +148,13 @@ public class Stalls {
s.respawnTime = System.currentTimeMillis() + (respawnTime * GameConstants.CYCLE_TIME); s.respawnTime = System.currentTimeMillis() + (respawnTime * GameConstants.CYCLE_TIME);
p.getPacketSender().sendMessage("You steal a " + ItemAssistant.getItemName(random[0]) + " from the stall."); p.getPacketSender().sendMessage("You steal a " + ItemAssistant.getItemName(random[0]) + " from the stall.");
p.getItemAssistant().addItem(random[0], random[1]); p.getItemAssistant().addItem(random[0], random[1]);
p.setHasThievedStall(true);
CycleEventHandler.getSingleton().addEvent(p, new CycleEvent() { CycleEventHandler.getSingleton().addEvent(p, new CycleEvent() {
@Override @Override
public void execute(CycleEventContainer container) { public void execute(CycleEventContainer container) {
GameEngine.objectHandler.createAnObject(p, s.getObject(), x, y, s.getFace()); GameEngine.objectHandler.createAnObject(p, s.getObject(), x, y, s.getFace());
//new Object(objectId, x, y, 0, s.getFace(), 10, j, getRespawnTime(objectId)); //new Object(objectId, x, y, 0, s.getFace(), 10, j, getRespawnTime(objectId));
p.setHasThievedStall(false);
container.stop(); container.stop();
} }
@Override @Override
@@ -194,7 +200,7 @@ public class Stalls {
if (NpcHandler.npcs[i] != null) { if (NpcHandler.npcs[i] != null) {
if (NpcHandler.npcs[i].npcType == 32 || NpcHandler.npcs[i].npcType == 1317 || NpcHandler.npcs[i].npcType == 2236 || NpcHandler.npcs[i].npcType == 2571) { if (NpcHandler.npcs[i].npcType == 32 || NpcHandler.npcs[i].npcType == 1317 || NpcHandler.npcs[i].npcType == 2236 || NpcHandler.npcs[i].npcType == 2571) {
if (p.goodDistance(p.absX, p.absY, NpcHandler.npcs[i].absX, NpcHandler.npcs[i].absY, 7) if (p.goodDistance(p.absX, p.absY, NpcHandler.npcs[i].absX, NpcHandler.npcs[i].absY, 7)
&& p.heightLevel == NpcHandler.npcs[i].heightLevel) { && p.heightLevel == NpcHandler.npcs[i].heightLevel) {
if (!NpcHandler.npcs[i].underAttack) { if (!NpcHandler.npcs[i].underAttack) {
NpcHandler.npcs[i].forceChat("What do you think you're doing?!?"); NpcHandler.npcs[i].forceChat("What do you think you're doing?!?");
NpcHandler.npcs[i].underAttack = true; NpcHandler.npcs[i].underAttack = true;
@@ -1582,6 +1582,16 @@ public abstract class Player {
public int XremoveSlot, XinterfaceID, XremoveID, Xamount; public int XremoveSlot, XinterfaceID, XremoveID, Xamount;
public boolean isMining; public boolean isMining;
public boolean hasThievedStall;
public boolean hasThievedStall() {
return hasThievedStall;
}
public void setHasThievedStall(boolean hasThievedStall) {
this.hasThievedStall = hasThievedStall;
}
public boolean antiFirePot = false; public boolean antiFirePot = false;
public boolean underWater = false; public boolean underWater = false;