Inject ShopFactory
This commit is contained in:
@@ -65,6 +65,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import server.CashShop.CashItemFactory;
|
||||
import server.ShopFactory;
|
||||
import server.SkillbookInformationProvider;
|
||||
import server.ThreadManager;
|
||||
import server.TimerManager;
|
||||
@@ -977,10 +978,11 @@ public class Server {
|
||||
MakerProcessor makerProcessor = new MakerProcessor(new MakerInfoProvider(new MakerDao(connection)));
|
||||
FredrickProcessor fredrickProcessor = new FredrickProcessor(noteService);
|
||||
DropProvider dropProvider = new DropProvider(new DropDao(connection));
|
||||
CommandContext commandContext = new CommandContext(dropProvider);
|
||||
ShopFactory shopFactory = new ShopFactory();
|
||||
CommandContext commandContext = new CommandContext(dropProvider, shopFactory);
|
||||
CommandsExecutor commandsExecutor = new CommandsExecutor(commandContext);
|
||||
ChannelDependencies channelDependencies = new ChannelDependencies(noteService, fredrickProcessor,
|
||||
makerProcessor, dropProvider, commandsExecutor);
|
||||
makerProcessor, dropProvider, commandsExecutor, shopFactory);
|
||||
|
||||
PacketProcessor.registerGameHandlerDependencies(channelDependencies);
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ import net.packet.InPacket;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import scripting.npc.NPCScriptManager;
|
||||
import server.Shop;
|
||||
import server.ShopFactory;
|
||||
import server.life.NPC;
|
||||
import server.life.PlayerNPC;
|
||||
import server.maps.MapObject;
|
||||
@@ -37,6 +39,11 @@ import tools.PacketCreator;
|
||||
|
||||
public final class NPCTalkHandler extends AbstractPacketHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(NPCTalkHandler.class);
|
||||
private final ShopFactory shopFactory;
|
||||
|
||||
public NPCTalkHandler(ShopFactory shopFactory) {
|
||||
this.shopFactory = shopFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacket(InPacket p, Client c) {
|
||||
@@ -75,7 +82,7 @@ public final class NPCTalkHandler extends AbstractPacketHandler {
|
||||
} else {
|
||||
boolean hasNpcScript = NPCScriptManager.getInstance().start(c, npc.getId(), oid, null);
|
||||
if (!hasNpcScript) {
|
||||
if (!npc.hasShop()) {
|
||||
if (!hasShop(npc)) {
|
||||
log.warn("NPC {} ({}) is not coded", npc.getName(), npc.getId());
|
||||
return;
|
||||
} else if (c.getPlayer().getShop() != null) {
|
||||
@@ -83,7 +90,7 @@ public final class NPCTalkHandler extends AbstractPacketHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
npc.sendShop(c);
|
||||
sendShop(npc, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,4 +104,16 @@ public final class NPCTalkHandler extends AbstractPacketHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasShop(NPC npc) {
|
||||
return shopFactory.getShopForNPC(npc.getId()) != null;
|
||||
}
|
||||
|
||||
private void sendShop(NPC npc, Client c) {
|
||||
Shop shop = shopFactory.getShopForNPC(npc.getId());
|
||||
if (shop == null) {
|
||||
return;
|
||||
}
|
||||
shop.sendShop(c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,11 +60,14 @@ import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
public final class UseCashItemHandler extends AbstractPacketHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(UseCashItemHandler.class);
|
||||
private static final int MIU_MIU_SHOP_ID = 1338;
|
||||
|
||||
private final NoteService noteService;
|
||||
private final ShopFactory shopFactory;
|
||||
|
||||
public UseCashItemHandler(NoteService noteService) {
|
||||
public UseCashItemHandler(NoteService noteService, ShopFactory shopFactory) {
|
||||
this.noteService = noteService;
|
||||
this.shopFactory = shopFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -508,7 +511,7 @@ public final class UseCashItemHandler extends AbstractPacketHandler {
|
||||
}
|
||||
} else if (itemType == 545) { // MiuMiu's travel store
|
||||
if (player.getShop() == null) {
|
||||
Shop shop = ShopFactory.getInstance().getShop(1338);
|
||||
Shop shop = shopFactory.getShop(MIU_MIU_SHOP_ID);
|
||||
if (shop != null) {
|
||||
shop.sendShop(c);
|
||||
remove(c, position, itemId);
|
||||
|
||||
Reference in New Issue
Block a user