C_NPCACTION 找到好位子加入
else if (((L1NpcInstance) obj).getNpcTemplate().get_npcId() == NPC編號 && s.equalsIgnoreCase("long_pay")) {
if (!pc.hasSkillEffect(90006)) {
pc.setSkillEffect(90006, 60000);
checkSponsor(pc);
} else {
pc.sendPackets(new S_SystemMessage("目前正在作業中.稍後點擊"));
}
最下方 下入判斷
/**
* 自動贊助
*/
private static synchronized void checkSponsor(L1PcInstance pc) {
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
PreparedStatement pstm2 = null;
try
{
String AccountName = pc.getAccountName();
con = DatabaseFactory.get().getConnection();
pstm = con.prepareStatement("select ordernumber,amount,payname,state from ezpay where state = 1 and payname ='" + AccountName + "'");
rs = pstm.executeQuery();
boolean isfind = false;
while (true)
{
if (!rs.next()|| rs == null)
{
break;
}
int serial = rs.getInt("ordernumber");
if (pc.getAccountName().equalsIgnoreCase(rs.getString("payname"))){
isfind = true;
pstm2 = con.prepareStatement("update ezpay set state = 2 where ordernumber = ?");
pstm2.setInt(1, serial);
pstm2.execute();
int count = rs.getInt("amount");
GiveItem(pc, 44070, count);
writeSponsorlog(pc,count);
}
}
if (!isfind){
pc.sendPackets(new S_ServerMessage("\\aD「系統」尚未偵測到您有贊助"));
http://pc.sendPackets(new S_ServerMessage(79));
}
} catch (SQLException e) {
_log.error(e.getLocalizedMessage());
http://_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
} finally {
SQLUtil.close(rs);
SQLUtil.close(pstm);
SQLUtil.close(pstm2);
SQLUtil.close(con);
}
}
public static void GiveItem(L1PcInstance pc, int itemId, int count)
{
L1ItemInstance item = ItemTable.get().createItem(itemId);
item.setCount(count);
if (pc.getInventory().checkAddItem(item, count) == 0){
pc.getInventory().storeItem(item);
pc.sendPackets(new S_GmMessage("感謝贊助.獲得 " + item.getLogName() + "。", "\\aE"));
}
}
private static BufferedWriter out;
/**
* 領取贊助
* @param player
*/
public static void writeSponsorlog(L1PcInstance player, int count) {
try {
File DeleteLog = new File("自動贊助\\贊助領取資料.log");
if (DeleteLog.createNewFile()) {
out = new BufferedWriter(new FileWriter("自動贊助\\贊助領取資料.log", false));
out.write("※以下是玩家[領取贊助]的所有紀錄※" + "\r
");
out.close();
}
out = new BufferedWriter(new FileWriter("自動贊助\\贊助領取資料.log", true));
out.write("\r
");// 每次填寫資料都控一行
out.write("來自帳號: " + player.getAccountName()
+ "來自ip: " + player.getNetConnection().getIp()
+ ",來自玩家: "+ player.getName()
+ ",領取了: " + count + " 個 "
+ ",<領取時間:" + new Timestamp(System.currentTimeMillis()) + ">"
+ "\r
");
out.close();
} catch (IOException e) {
System.out.println("以下是錯誤訊息: " + e.getMessage());
}
}
請再模擬器新增一個資料夾 自動贊助