Notes about difficulties of DI for scripts
This commit is contained in:
@@ -16,7 +16,7 @@ var commands;
|
|||||||
|
|
||||||
function writeHeavenMSCommands() {
|
function writeHeavenMSCommands() {
|
||||||
const CommandsExecutor = Java.type('client.command.CommandsExecutor');
|
const CommandsExecutor = Java.type('client.command.CommandsExecutor');
|
||||||
commands = CommandsExecutor.getInstance().getGmCommands();
|
commands = CommandsExecutor.getInstance().getGmCommands(); // TODO: fix. CommandsExecutor is now injected rather than being a singleton, so this does not work anymore.
|
||||||
}
|
}
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
|||||||
private String scriptName;
|
private String scriptName;
|
||||||
private String getText;
|
private String getText;
|
||||||
private boolean itemScript;
|
private boolean itemScript;
|
||||||
private List<PartyCharacter> otherParty;
|
|
||||||
|
|
||||||
private final Map<Integer, String> npcDefaultTalks = new HashMap<>();
|
private final Map<Integer, String> npcDefaultTalks = new HashMap<>();
|
||||||
|
|
||||||
@@ -102,11 +101,10 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
|||||||
this(c, npc, -1, scriptName, false);
|
this(c, npc, -1, scriptName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NPCConversationManager(Client c, int npc, List<PartyCharacter> otherParty, boolean test) {
|
public NPCConversationManager(Client c, int npc) {
|
||||||
super(c);
|
super(c);
|
||||||
this.c = c;
|
this.c = c;
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
this.otherParty = otherParty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public NPCConversationManager(Client c, int npc, int oid, String scriptName, boolean itemScript) {
|
public NPCConversationManager(Client c, int npc, int oid, String scriptName, boolean itemScript) {
|
||||||
@@ -377,6 +375,9 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void openShopNPC(int id) {
|
public void openShopNPC(int id) {
|
||||||
|
// TODO: figure out a way to inject ShopFactory.
|
||||||
|
// NPCConversationManager is instantiated by NPCScriptManager, which is a static singleton.
|
||||||
|
// NPCScriptManager is accessed from all over, making it really difficult to structure dependencies properly.
|
||||||
Shop shop = ShopFactory.getInstance().getShop(id);
|
Shop shop = ShopFactory.getInstance().getShop(id);
|
||||||
|
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class NPCScriptManager extends AbstractScriptManager {
|
|||||||
|
|
||||||
public void start(String filename, Client c, int npc, List<PartyCharacter> chrs) {
|
public void start(String filename, Client c, int npc, List<PartyCharacter> chrs) {
|
||||||
try {
|
try {
|
||||||
final NPCConversationManager cm = new NPCConversationManager(c, npc, chrs, true);
|
final NPCConversationManager cm = new NPCConversationManager(c, npc);
|
||||||
cm.dispose();
|
cm.dispose();
|
||||||
if (cms.containsKey(c)) {
|
if (cms.containsKey(c)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import java.util.Set;
|
|||||||
public class Shop {
|
public class Shop {
|
||||||
private static final Logger log = LoggerFactory.getLogger(Shop.class);
|
private static final Logger log = LoggerFactory.getLogger(Shop.class);
|
||||||
private static final Set<Integer> rechargeableItems = new LinkedHashSet<>();
|
private static final Set<Integer> rechargeableItems = new LinkedHashSet<>();
|
||||||
|
private static final short MAX_QUANTITY_PER_PURCHASE = 1000; // Should really use max stack size for the given item
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
private final int npcId;
|
private final int npcId;
|
||||||
@@ -278,11 +279,11 @@ public class Shop {
|
|||||||
recharges.remove(Integer.valueOf(starItem.getItemId()));
|
recharges.remove(Integer.valueOf(starItem.getItemId()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret.addItem(new ShopItem((short) 1000, rs.getInt("itemid"), rs.getInt("price"), rs.getInt("pitch")));
|
ret.addItem(new ShopItem(MAX_QUANTITY_PER_PURCHASE, rs.getInt("itemid"), rs.getInt("price"), rs.getInt("pitch")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Integer recharge : recharges) {
|
for (Integer recharge : recharges) {
|
||||||
ret.addItem(new ShopItem((short) 1000, recharge, 0, 0));
|
ret.addItem(new ShopItem((short) 0, recharge, 0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user