Hi everyone, I am thinking about joining this community to enhance my college experience as a side project. I downloaded the source code and was able to successful launch and play with prebuilt binary. Then I altered AdminCommand and added methods in the hopes that it will allow me to alter potentials at will. There are two commands that I added and extended CommandExecute:
Code:
/**
* Lists all slots of a given type for a given person.
* If player is unspecified, list all slots for the current player.
* @author Jun
*
*/
public static class ListSlot extends CommandExecute {
private MapleInventoryType transType(String type){
if(type.equalsIgnoreCase("equip")){
return MapleInventoryType.EQUIP;
} else if(type.equalsIgnoreCase("equiped")){
return MapleInventoryType.EQUIPPED;
} else if(type.equalsIgnoreCase("cash")){
return MapleInventoryType.CASH;
} else if(type.equalsIgnoreCase("etc")){
return MapleInventoryType.ETC;
} else if(type.equalsIgnoreCase("use")){
return MapleInventoryType.USE;
} else {
return MapleInventoryType.UNDEFINED;
}
}
private MapleCharacter playerByName(MapleClient c, String name){
List<MapleMap> maps = c.getChannelServer().getMapFactory().getAllLoadedMaps();
for(MapleMap map : maps){
MapleCharacter chrFound = map.getCharacterByName(name);
if(chrFound!=null) return chrFound;
}
return null;
}
private void printHeader(MapleCharacter p, String formatString){
String headerString = String.format(formatString, "Unique ID", "Item ID", "Position");
p.dropMessage(6,headerString);
}
public int execute(MapleClient c, String[] args){
MapleCharacter self = c.getPlayer();
//ListSlot <type>
String formatString = "%10s\t%10s\t%10s";
printHeader(self,formatString);
if(args.length<1){
self.dropMessage(6,"!ListSlot <Item Type> [Player]");
return 1;
}
String typeString = args[0];
String playerString = args.length == 2?args[1]:null;
MapleCharacter foundPlayer = playerString==null?self:playerByName(c, playerString);
if(foundPlayer==null){
self.dropMessage(6,"Player not found.");
return 1;
}
MapleInventoryType itemType = transType(typeString);
if(itemType == MapleInventoryType.UNDEFINED){
self.dropMessage(6, "Item type undefined.");
return 1;
}
MapleInventory inventory = foundPlayer.getInventory(itemType);
Collection<Item> items = inventory.list();
for(Item item:items){
//possible enhancement, change display of item type id to item type name.
String itemString = String.format(formatString, item.getUniqueId(), item.getItemId(), item.getPosition());
self.dropMessage(6, itemString);
}
return 0;
}
}
public static class AlterPotential extends CommandExecute {
private Equip findEquip(MapleCharacter owner, short position) throws ClassCastException{
return (Equip)owner.getInventory(MapleInventoryType.EQUIP).getItem(position);
}
private short findFirstAvailablePotentialLine(Equip equip, short requestLine){
int p1=equip.getPotential1(),p2=equip.getPotential2(),
p3=equip.getPotential3(),p4=equip.getPotential4(),
p5=equip.getPotential5();
//simply replace if potential is already set.
switch(requestLine){
case 1: if(p1>=0) return requestLine;
case 2: if(p2>=0) return requestLine;
case 3: if(p3>=0) return requestLine;
case 4: if(p4>=0) return requestLine;
case 5: if(p5>=0) return requestLine;
}
//otherwise, add to the first empty line
if(p1<=0) return 1;
else if(p2<=0) return 2;
else if(p3<=0) return 3;
else if(p4<=0) return 4;
else return 5;
}
@Override
public int execute(MapleClient c, String[] args){
String helpString = "!AlterPotential <item position> <potential id> <req level> <potential line> [item owner]";
MapleCharacter self = c.getPlayer();
//see InventoryHandler.UseMagnify
final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
try{
String posStr = args[0];
String potIdStr = args[1];
String reqLevelStr = args[2];
String potLineStr = args[3];
String itemOwnerStr = args.length>=5?args[4]:null;
MapleCharacter itemOwner = self;
if(itemOwnerStr!=null){
itemOwner = self.getMap().getCharacterByName(itemOwnerStr);
}
if(itemOwner == null){
self.dropMessage(6, "Player not found.");
return 1;
}
List<StructItemOption> potGrades = ii.getPotentialInfo(Integer.parseInt(potIdStr));
int reqLevel = Integer.parseInt(reqLevelStr)/10;
StructItemOption pot = potGrades.get(reqLevel);
//find item
Equip equip = findEquip(itemOwner,Short.parseShort(posStr));
short potLine = Short.parseShort(potLineStr);
potLine = findFirstAvailablePotentialLine(equip, potLine);
switch(potLine){
case 1: equip.setPotential1(pot.opID); break;
case 2: equip.setPotential2(pot.opID); break;
case 3: equip.setPotential3(pot.opID); break;
case 4: equip.setPotential4(pot.opID); break;
case 5: equip.setPotential5(pot.opID); break;
}
//TODO: Send update info to player and save to database.
//See CWvsContext.scrolledItem and SendOP for information.
c.getPlayer().getMap().broadcastMessage(CField.showPotentialReset(false, c.getPlayer().getId(), true, equip.getItemId()));
// c.getSession().write(InventoryPacket.scrolledItem(toUse, item, false, true));
c.getPlayer().forceReAddItem_NoUpdate(equip, MapleInventoryType.EQUIP);
c.getPlayer().reloadC();
MapleInventoryManipulator.addById(c, 2430481, (short) 1, "Cube" + " on " + FileoutputUtil.CurrentReadable_Date());
return 0;
} catch (ArrayIndexOutOfBoundsException e){
self.dropMessage(6, helpString);
return 1;
} catch (ClassCastException e){
self.dropMessage(6, "Required Level must be a number.");
return 1;
} catch (NumberFormatException e){
self.dropMessage(6, "Entered NaN into a number argument.");
return 1;
}
}
}
And to facilitate quick recompilation, I have created the following simple batch script (I am messing around in Win 7):
Code:
@echo off
@title Jouyang3's quick recompiler (make sure you have java installed)
if not exist class mkdir class
dir /s /B src\*.java > srcp
javac -Xlint:none -cp dist/* -d class @srcp
set curr_dir=%cd%
chdir /D .\class
jar cf ../v116.jar .
chdir /D %curr_dir%
rmdir class /s /q
del srcp
if exist dist\v116.jar move dist\v116.jar dist\v116.jar.old
move v116.jar dist\v116.jar
chdir /D %curr_dir%
pause
It compiles and all classes are in place. I was able to launch ms client. However, the animation did not follow the black screen, but rather, it d/ced me. I have checked the cmd output, no logging for me to debug.
So I went on. I was skeptical about the code that I have modified. So I have diff within the src folder against the untouch src folder. The only thing that I had changed was the AdminCommand thus I commented out the changes I made and recompiled with my tool. But the same error followed.
As a last resort, I went on and recompiled the original src and see if there were something wrong with it (or with me), again with my own batch compile script. However, same "black screen then d/c" error occurred to me. Now I am really confused.:junglejane:
Can I compile src folder with simple java commands? Or was there something wrong with the original source? And where is the log or error file. Can you guys shed me some light on such matters?
Thanks you,
Sincerely,
Jun D. Ouyang
[Edited]
It turns out that you really have to change MAPLE_PATCH constant for the login server to function.
I wonder why...
[/Edited]