楓之谷私服v120 每日簽到系統
夢夢谷端口扒來的。
時間有點久遠,如果有哪裡漏掉了import還是什麼的...請自行補上吧。
簽到成功
簽到過或者時長不足
簽到後會在資料表中自動寫入今天日期以及簽到的帳號id。
在線時長領獎勵這種東西應該不需要分享了吧...
❗️新建資料表
- 首先,在資料庫新增一個資料表
prizelog_n
:
- id/int/10/勾選主索引鍵/自動遞增
- accid/int/10
- bossid/varchar/20/字元集:utf8 整理:utf8_general_ci
- 再新增第二個資料表
accounts_event
:
直接用sql語法新增,或者參考語法手動新增。
CREATE TABLE `accounts_event` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`accId` int(11) NOT NULL DEFAULT '0',
`eventId` varchar(20) NOT NULL DEFAULT '',
`count` int(11) NOT NULL DEFAULT '0',
`type` int(11) NOT NULL DEFAULT '0',
`updateTime` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `accid` (`accId`),
KEY `eventid` (`eventId`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=big5;
❗️改SRC
▶️1. 打開client\MapleCharacter.java
,在最後一個}前貼上:
public int getPrizeLog_n(String bossid) {
Connection con1 = DatabaseConnection.getConnection();
try {
int ret_count = 0;
PreparedStatement ps;
ps = con1.prepareStatement("select count(*) from prizelog_n where accid = ? and bossid = ?");
ps.setInt(1, getClient().getAccID());
ps.setString(2, bossid);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
ret_count = rs.getInt(1);
} else {
ret_count = -1;
}
rs.close();
ps.close();
return ret_count;
} catch (Exception Wx) {
return -1;
}
}
public void setPrizeLog_n(String bossid) {
Connection con1 = DatabaseConnection.getConnection();
try {
PreparedStatement ps;
ps = con1.prepareStatement("insert into prizelog_n (accid, bossid) values (?,?)");
ps.setInt(1, getClient().getAccID());
ps.setString(2, bossid);
ps.executeUpdate();
ps.close();
} catch (Exception Wx) {
}
}
📣PS.如果你的端口已經有prizelog函數,此步驟可以跳過。
▶️2. 同樣是MapleCharacter.java
在最上方一堆變數宣告加上以下變數宣告
private long logintime;//登入時間
private long onlineTime;//上線時間
//角色一些特殊變量數據
private Timestamp todayonlinetimestamp;
在最後一個} 前加上
/*
* OnlineTime 系統
*/
public void initOnlineTime() {
onlineTime = getEventCount("OnlineTime", 0);
}
//獲得在線時間
public int getOnlineTime() {
long l2;
long l3 = getDaybyDay(1).getTimeInMillis() - getLogintime();
if (onlineTime < 0) {
resetEventCount("OnlineTime", 0);
initOnlineTime();
}
if (l3 >= 86400000) {//86400000 = 一天毫秒
l2 = getDaybyDay(1).getTimeInMillis() - 86400000;
setLogintime(getDaybyDay(0).getTimeInMillis());
} else {
l2 = getLogintime() - onlineTime;
}
return (int) (System.currentTimeMillis() - l2);
}
public void setOnlineTime() {
if (getLogintime() > 0) {
long l2 = getDaybyDay(1).getTimeInMillis() - getLogintime();
if (onlineTime < 0) {
resetEventCount("OnlineTime", 0);
}
setEventCount("OnlineTime", 0, (int) (System.currentTimeMillis() - (l2 >= 86400000 ? getDaybyDay(1).getTimeInMillis() - 86400000 : getLogintime())));
setLogintime(System.currentTimeMillis());
}
}
public void setOnlineTime(long onlineTime) {
this.onlineTime = onlineTime;
}
/*
* Logintime 系統
*/
public long getLogintime() {
return logintime;
}
public void setLogintime(long logintime) {
this.logintime = logintime;
}
public Calendar getDaybyDay(int n2) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + n2);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.AM_PM, 0);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar;
}
/*
* 新增函數
* 帳號下的角色統計計算每日活動次數
*/
public int getEventCount(String eventId) {
return getEventCount(eventId, 0);
}
public int getEventCount(String eventId, int type) {
try (Connection con = DatabaseConnection.getConnection()) {
int count = 0;
PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts_event WHERE accId = ? AND eventId = ?");
ps.setInt(1, getClient().getAccID()); //1
ps.setString(2, eventId); //2
ResultSet rs = ps.executeQuery();
if (rs.next()) {
/*
* 年:calendar.get(Calendar.YEAR)
* 月:calendar.get(Calendar.MONTH)+1
* 日:calendar.get(Calendar.DAY_OF_MONTH)
* 星期:calendar.get(Calendar.DAY_OF_WEEK)-1
*/
count = rs.getInt("count");
Timestamp updateTime = rs.getTimestamp("updateTime");
if (type == 0) {
Calendar sqlcal = Calendar.getInstance();
if (updateTime != null) {
sqlcal.setTimeInMillis(updateTime.getTime());
}
if (sqlcal.get(Calendar.DAY_OF_MONTH) + 1 <= Calendar.getInstance().get(Calendar.DAY_OF_MONTH) || sqlcal.get(Calendar.MONTH) + 1 <= Calendar.getInstance().get(Calendar.MONTH) || sqlcal.get(Calendar.YEAR) + 1 <= Calendar.getInstance().get(Calendar.YEAR)) {
count = 0;
PreparedStatement psu = con.prepareStatement("UPDATE accounts_event SET count = 0, updateTime = CURRENT_TIMESTAMP() WHERE accId = ? AND eventId = ?");
psu.setInt(1, id); //1
psu.setString(2, eventId); //2
psu.executeUpdate();
psu.close();
}
}
} else {
PreparedStatement psu = con.prepareStatement("INSERT INTO accounts_event (accId, eventId, count, type) VALUES (?, ?, ?, ?)");
psu.setInt(1, getClient().getAccID()); //1 - 4
psu.setString(2, eventId);
psu.setInt(3, 0);
psu.setInt(4, type);
psu.executeUpdate();
psu.close();
}
rs.close();
ps.close();
return count;
} catch (Exception Ex) {
System.err.println("獲取 EventCount 次數." + Ex);
return -1;
}
}
/*
* 增加帳號下的角色統計計算每日活動次數
*/
public void setEventCount(String eventId) {
setEventCount(eventId, 0);
}
public void setEventCount(String eventId, int type) {
setEventCount(eventId, type, 1);
}
public void setEventCount(String eventId, int type, int count) {
int eventCount = getEventCount(eventId, type);
try (Connection con = DatabaseConnection.getConnection()) {
PreparedStatement ps = con.prepareStatement("UPDATE accounts_event SET count = ?, type = ?, updateTime = CURRENT_TIMESTAMP() WHERE accId = ? AND eventId = ?");
ps.setInt(1, eventCount + count);
ps.setInt(2, type); //2
ps.setInt(3, getClient().getAccID()); //3
ps.setString(4, eventId); //4
ps.executeUpdate();
ps.close();
} catch (Exception Ex) {
System.err.println("增加 EventCount 次數失敗." + Ex);
}
}
/*
* 重置帳號下的角色統計計算每日活動次數
*/
public void resetEventCount(String eventId) {
resetEventCount(eventId, 0);
}
public void resetEventCount(String eventId, int type) {
try (Connection con = DatabaseConnection.getConnection()) {
PreparedStatement ps = con.prepareStatement("UPDATE accounts_event SET count = 0, type = ?, updateTime = CURRENT_TIMESTAMP() WHERE accId = ? AND eventId = ?");
ps.setInt(1, type); //1
ps.setInt(2, getClient().getAccID()); //2
ps.setString(3, eventId); //3
ps.executeUpdate();
ps.close();
} catch (Exception Ex) {
System.err.println("重置 EventCount 次數失敗" + Ex);
}
}
▶️3. 還是MapleCharacter.java
沒變,搜索函數MapleCharacter底下的if (ChannelServer) {
在下方加上
todayonlinetimestamp = new Timestamp(System.currentTimeMillis());//今天在線時間
▶️4. 打開handling.channel.handler.InterServerHandler.java
搜索 player.sendMacros();
,在上面加上
//更新在線時間
c.getPlayer().initOnlineTime();
player.setLogintime(System.currentTimeMillis());
❗️簽到NPC腳本
最後一步就是找個NPC把腳本貼上,當成每日簽到的NPC來用。
腳本直接放上..自行研究吧。
可以調整每日贈送不一樣的物品或者點數,當然也可以都給..看你開心。
var status = 0;
var objDate=new Date();
var day=objDate.getDay();
var Month= objDate.getMonth();
var MonthS =["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"];
var weekday = ["日", "一", "二", "三", "四", "五", "六"];
var MonthB=objDate.getMonth()-1;
var tzc =objDate.getDate();
var Year =objDate.getFullYear();
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
} else {
if (mode == 0 && status == 0) {
cm.dispose();
return;
}
if (mode == 1) status++;
else status--;
if (status == 0) {
var tt=31;
if (Month == 0 || Month == 2 || Month == 4 || Month == 6|| Month == 7 || Month == 9 || Month == 11) { // 1月 3月 5月 78 月 10月 12月
tt=32;
}
if (Month == 1) { // 2月的話
tt=29;
}
var text3 = 0;
for(var i=1; i<tt; i++) {
text3+= cm.getPlayer().getPrizeLog_n(""+Year+"年"+MonthS[Month]+i+"日");}
var ta="#b";
var text = "";
for(var i=1,ytz=1; i<tt; i++,ytz++) {
if (cm.getPlayer().getPrizeLog_n(""+Year+"年"+MonthS[Month]+i+"日") == 0) {
ta="#b";
}
if (cm.getPlayer().getPrizeLog_n(""+Year+"年"+MonthS[Month]+i+"日") != 0) {
ta="#r";
}
text+=ta+ytz+"#i"+itemList[i][0]+"#"+((i + 0) % 7 == 0 ? "\r\n": "");
}
var text2 = 0;
cm.sendSimple("#e現在時間:#b"+Year+"年"+MonthS[Month]+tzc+"日星期"+weekday[day]+"\r\n#k本月累積簽到【 #r"+ text3 +"#k 】天"+"\r\n#k本日在線時間【 #r"+ cm.getOnlineTime() +"#k 】分"+"\r\n#b上線時間需滿60分鐘才可進行每日簽到"+"\r\n#k"+"\r\n#L0# #r每日簽到獲得100點#l\r\n\r\n#k");
} else if (status == 1) {
if (selection == 0) {
if(!cm.canHold(itemList[tzc][0], itemList[tzc][1])){
cm.sendOk("您的背包空間不足");
cm.dispose();
return;
}
if (cm.getPlayer().getPrizeLog_n(""+Year+"年"+MonthS[Month]+tzc+"日") < 1 && cm.getOnlineTime() >= 60) { // 在線時數
cm.getPlayer().setPrizeLog_n(""+Year+"年"+MonthS[Month]+tzc+"日");
cm.getPlayer().modifyCSPoints(1, 100, true);
cm.sendOk("恭喜您成功進行簽到並獲取100點!!");
cm.worldMessage(5,"『xx谷』" + " : " + "玩家 " + cm.getChar().getName() + " 已進行每日簽到!!!");
cm.dispose();
} else{
cm.sendOk("已進行每日簽到或上線時間未達60分鐘!。");
cm.dispose();
}
}
}
}
}