最新公告
★ 欢迎来到天堂私服123 | 天天更新最新私服信息
天堂私服123|每日開服情報
首页 › 文章看板 › 🖥️ 私服架设 › 天堂私服编写计时地图教学~
🖥️ 私服架设

天堂私服编写计时地图教学~

🧙
匿名

1.
MapsTable.java DB化最大停留时间

寻找 MapData

增加

/**
* 计时地图时间
*/
public int maptime;

寻找 loadMapsFromDatabase

增加

data.maptime = rs.getInt("maptime");

找个地方增加

/**
* 取回计时地图时间
*
* @param mapId
* @return
*/
public int getMapTime(final int mapId) {
final MapData map = this._maps.get(mapId);
if (map == null) {
return 0;
}
return this._maps.get(mapId).maptime;
}

mapids.sql 增加一个 maptime字段(单位是分钟)
2.
L1PcIntance.java 制作字段来存储秒数
找个地方增加

/**
* 奇岩地监可停留时间(秒).
*/
private int _rocksPrisonTime;
/**
* 取回奇岩地监可停留时间(秒).
*
* @return
*/
public int getRocksPrisonTime() {
return this._rocksPrisonTime;
}
/**
* 设置奇岩地监使用时间.
*
* @param time
* 时间
*/
public void setRocksPrisonTime(final int time) {
this._rocksPrisonTime = time;
}
/**
* 拉斯塔巴德地监可停留时间(秒).
*/
private int _lastabardTime;
/**
* 取回拉斯塔巴德地监可停留时间(秒).
*
* @return
*/
public int getLastabardTime() {
return this._lastabardTime;
}
/**
* 设置拉斯塔巴德监狱使用时间.
*
* @param time
* 时间
*/
public void setLastabardTime(final int time) {
this._lastabardTime = time;
}

/**
* 象牙塔可停留时间(秒).
*/
private int _ivorytowerTime;
/**
* 取回象牙塔可停留时间(秒).
*
* @return
*/
public int getIvoryTowerTime() {
return this._ivorytowerTime;
}
/**
* 设置象牙塔使用时间.
*
* @param time
* 时间
*/
public void setIvoryTowerTime(final int time) {
this._ivorytowerTime = time;
}

/**
* 取回计时地图使用时间
*
* @param mapid
* 玩家所在的地图
* @return
*/
public int getMapUseTime(final int mapid) {
int result = 0;
switch (mapid) {
case 53: // 奇岩地监1F
case 54: // 奇岩地监2F
case 55: // 奇岩地监3F
case 56: // 奇岩地监4F
result = this._rocksPrisonTime;
break;
case 75: // 象牙塔1F
case 76: // 象牙塔2F
case 77: // 象牙塔3F
case 78: // 象牙塔4F
case 79: // 象牙塔5F
case 80: // 象牙塔6F
case 81: // 象牙塔7F
case 82: // 象牙塔8F
result = this._ivorytowerTime;
break;
case 450: // 拉斯塔巴德正门
case 451: // 1楼 集会场
case 452: // 1楼 突击队训练场
case 453: // 1楼 魔兽君王之室
case 454: // 1楼 魔兽调教场
case 455: // 1楼 魔兽训练场
case 456: // 1楼 魔兽召唤室
case 460: // 2楼 黑魔法修练场
case 462: // 2楼 法令军王之室
case 463: // 2楼 法令军王的书房
case 464: // 2楼 暗黑精灵召唤室
case 465: // 2楼 暗黑精灵栖息地
case 466: // 2楼 暗黑精灵研究室
case 470: // 3楼 恶灵祭坛
case 471: // 3楼 恶灵之主祭坛
case 472: // 3楼 佣兵训练场
case 473: // 3楼 冥法军训练场
case 474: // 3楼 欧姆实验室
case 475: // 3楼 冥法军王之室
case 476: // 3楼 中央控制室
case 477: // 3楼 恶灵之主佣兵室
case 478: // 3楼 控制室走廊
case 490: // 地下训练场
case 491: // 地下信道
case 492: // 暗杀军王之室
case 493: // 地下控制室
case 494: // 地下处刑场
case 495: // 地下竞技场
case 496: // 地下监狱
case 530: // 4楼 格兰肯神殿、长老.琪娜之室
case 531: // 4楼 长老.巴塔斯之室、长老.安迪斯之室
case 532: // 4楼 庭园广场、长老.泰玛斯之室
case 533: // 4楼 长老.泰玛斯之室、长老.拉曼斯之室、长老.巴陆德之室
case 534: // 4楼 长老会议厅、副神官.卡山德拉之室、真.冥皇丹特斯之室
result = this._lastabardTime;
break;
}
return result;
}
/**
* 设置地图已使用时间.
*
* @param time
* 时间
*/
public void setMapUseTime(final int mapid, final int time) {
switch (mapid) {
case 53:// 奇岩地监1F
case 54:// 奇岩地监2F
case 55:// 奇岩地监3F
case 56:// 奇岩地监4F
this.setRocksPrisonTime(time);
break;
case 75:// 象牙塔1F
case 76:// 象牙塔2F
case 77:// 象牙塔3F
case 78:// 象牙塔4F
case 79:// 象牙塔5F
case 80:// 象牙塔6F
case 81:// 象牙塔7F
case 82:// 象牙塔8F
this.setIvoryTowerTime(time);
break;
case 450: // 拉斯塔巴德正门
case 451: // 1楼 集会场
case 452: // 1楼 突击队训练场
case 453: // 1楼 魔兽君王之室
case 454: // 1楼 魔兽调教场
case 455: // 1楼 魔兽训练场
case 456: // 1楼 魔兽召唤室
case 460: // 2楼 黑魔法修练场
case 462: // 2楼 法令军王之室
case 463: // 2楼 法令军王的书房
case 464: // 2楼 暗黑精灵召唤室
case 465: // 2楼 暗黑精灵栖息地
case 466: // 2楼 暗黑精灵研究室
case 470: // 3楼 恶灵祭坛
case 471: // 3楼 恶灵之主祭坛
case 472: // 3楼 佣兵训练场
case 473: // 3楼 冥法军训练场
case 474: // 3楼 欧姆实验室
case 475: // 3楼 冥法军王之室
case 476: // 3楼 中央控制室
case 477: // 3楼 恶灵之主佣兵室
case 478: // 3楼 控制室走廊
case 490: // 地下训练场
case 491: // 地下信道
case 492: // 暗杀军王之室
case 493: // 地下控制室
case 494: // 地下处刑场
case 495: // 地下竞技场
case 496: // 地下监狱
case 530: // 4楼 格兰肯神殿、长老.琪娜之室
case 531: // 4楼 长老.巴塔斯之室、长老.安迪斯之室
case 532: // 4楼 庭园广场、长老.泰玛斯之室
case 533: // 4楼 长老.泰玛斯之室、长老.拉曼斯之室、长老.巴陆德之室
case 534: // 4楼 长老会议厅、副神官.卡山德拉之室、真.冥皇丹特斯之室
this.setLastabardTime(time);
break;
}
}
/**
* 是否在计时地图 <br>
*
* @return true:玩家位于限时的地图内
*/
public boolean isInTimeMap() {
final int map = this.getMapId();
final int maxMapUsetime = MapsTable.getInstance().getMapTime(map);
return maxMapUsetime > 0;
}

3.
MySqlCharacterStorage.java 关系到人物数据存储
寻找loadCharacter

增加

pc.setRocksPrisonTime(rs.getInt("RocksPrisonTime"));
pc.setIvoryTowerTime(rs.getInt("IvorytowerTime"));
pc.setLastabardTime(rs.getInt("LastabardTime"));

寻找

storeCharacter

SQL脚本内增加

,RocksPrisonTime=?,IvorytowerTime=?,LastabardTime=?

运行动作增加
pstm.setInt(++i, pc.getRocksPrisonTime());
pstm.setInt(++i, pc.getIvoryTowerTime());
pstm.setInt(++i, pc.getLastabardTime());

characters.sql 增加RocksPrisonTime,IvorytowerTime,LastabardTime三个字段

此文只分享于浪漫物语网络社区,转载请著名作者,出处

4.
写一个线程来增加或更新时间

import java.util.Calendar;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
import l1j.server.config.Config_Server;
import l1j.server.server.datatables.MapsTable;
import l1j.server.server.model.L1Teleport;
import l1j.server.server.model.L1World;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.model.identity.L1SystemMessageId;
import l1j.server.server.serverpackets.S_MapTimer;
import l1j.server.server.serverpackets.S_ServerMessage;

/**
* 计时地图线程
*
* @author Psnnwe
*
*/
public final class MapTimerThread extends Thread {

/**
* 实例
*/
private static MapTimerThread _instance;

/**
* 提示信息.
*/
private static final Logger LOG = Logger.getLogger(MapTimerThread.class
.getName());

/**
* 取回实例
*
* @return
*/
public static MapTimerThread getInstance() {
if (_instance == null) {
_instance = new MapTimerThread();
_instance.start();
}
return _instance;
}

/**
* 日历
*
* @return
*/
private Calendar getRealTime() {
final TimeZone tz = TimeZone.getTimeZone(Config_Server.TIME_ZONE);
final Calendar cal = Calendar.getInstance(tz);
return cal;
}

/**
* 地图时间检查
*
* @param pc
*/
private void MapTimeCheck(final L1PcInstance pc) {
// 玩家所在的地图
final int map = pc.getMapId();
// 地图限制时间(秒数)
final int maxMapUsetime = MapsTable.getInstance().getMapTime(map) * 60;
final Calendar time = this.getRealTime();
// 取回今年的第几天
int dayofyear = time.get(Calendar.DAY_OF_YEAR);
if (dayofyear == 365) {
dayofyear += 1;
}
// 使用秒数(取余数)
final int entertime = pc.getMapUseTime(map) % 100000;
// 使用日期(取整数)
final int enterday = pc.getMapUseTime(map) / 100000;
if (entertime > (maxMapUsetime)) {
this.teleport(pc);
} else if (enterday < dayofyear) {
// 不同天-更新日期
pc.setMapUseTime(map, time.get(Calendar.DAY_OF_YEAR) * 100000);
} else {
this.message(pc);
pc.setMapUseTime(map, pc.getMapUseTime(map) + 1);
// 已使用时间(秒)
final int usetime = pc.getMapUseTime(map) % 100000;
// 剩余时间(秒)
final int can_useTime = (maxMapUsetime - usetime);
if ((entertime % 60) == 0) {// 计时器显示(1分钟来一次就好了= = )
pc.sendPackets(new S_MapTimer(can_useTime));
}
}
}

/**
* 时间提示消息
*
* @param pc
*/
private void message(final L1PcInstance pc) {
// 玩家所在的地图
final int map = pc.getMapId();
// 地图限制时间(秒数)
final int maxMapUsetime = MapsTable.getInstance().getMapTime(map) * 60;
// 取回地图使用时间(秒) --- (取余数(不取日期))
final int time = pc.getMapUseTime(map) % 100000;
final int usetime = maxMapUsetime - time; // 秒数
S_ServerMessage msg = null;
switch (usetime) {
case 10800:
msg = new S_ServerMessage(L1SystemMessageId.$1526,
String.valueOf(3));
break;
case 7200:
msg = new S_ServerMessage(L1SystemMessageId.$1526,
String.valueOf(2));
break;
case 3600:
msg = new S_ServerMessage(L1SystemMessageId.$1526,
String.valueOf(1));
break;
case 1800:
msg = new S_ServerMessage(L1SystemMessageId.$1527,
String.valueOf(30));
break;
case 900:
msg = new S_ServerMessage(L1SystemMessageId.$1527,
String.valueOf(15));
break;
case 600:
msg = new S_ServerMessage(L1SystemMessageId.$1527,
String.valueOf(10));
break;
case 300:
msg = new S_ServerMessage(L1SystemMessageId.$1527,
String.valueOf(5));
break;
case 120:
msg = new S_ServerMessage(L1SystemMessageId.$1527,
String.valueOf(2));
break;
case 60:
msg = new S_ServerMessage(L1SystemMessageId.$1527,
String.valueOf(1));
break;
case 10:
msg = new S_ServerMessage(L1SystemMessageId.$1528,
String.valueOf(10));
break;
case 9:
msg = new S_ServerMessage(L1SystemMessageId.$1528,
String.valueOf(9));
break;
case 8:
msg = new S_ServerMessage(L1SystemMessageId.$1528,
String.valueOf(8));
break;
case 7:
msg = new S_ServerMessage(L1SystemMessageId.$1528,
String.valueOf(7));
break;
case 6:
msg = new S_ServerMessage(L1SystemMessageId.$1528,
String.valueOf(6));
break;
case 5:
msg = new S_ServerMessage(L1SystemMessageId.$1528,
String.valueOf(5));
break;
case 4:
msg = new S_ServerMessage(L1SystemMessageId.$1528,
String.valueOf(4));
break;
case 3:
msg = new S_ServerMessage(L1SystemMessageId.$1528,
String.valueOf(3));
break;
case 2:
msg = new S_ServerMessage(L1SystemMessageId.$1528,
String.valueOf(2));
break;
case 1:
msg = new S_ServerMessage(L1SystemMessageId.$1528,
String.valueOf(1));
break;
default:
break;
}
pc.sendPackets(msg);
}

@Override
public void run() {
System.out.println("╠》加载 - 计时地图线程。");
while (true) {
try {
for (final L1PcInstance pc : L1World.getInstance()
.getAllPlayers()) {
if ((pc == null) || (pc.getNetConnection() == null)) {
continue;
} else {
if (pc.isDead()) {// 死亡不计时
continue;
} else {
if (pc.isInTimeMap()) {// 离开地图不计时
this.MapTimeCheck(pc);
}
}
}
}
final int time = 1 * 1000;
Thread.sleep(time);// 1秒一次
} catch (final Throwable e) {
LOG.log(Level.WARNING, e.getLocalizedMessage(), e);
}
}
}

/**
* 发送处理.(这边只举例奇岩地监)
*
* @param pc
*/
private void teleport(final L1PcInstance pc) {
final int map = pc.getMapId();
if ((map == 53) || (map == 54) || (map == 55) || (map == 56)) {
final int locx = 33427;
final int locy = 32822;
final int mapid = 4;
final int heading = 5;
L1Teleport.teleport(pc, locx, locy, mapid, heading, true);
}
}
}

5.
GameServer.java 让MapTimerThread伴随服务器启动
寻找initialize

方法内找地方增加

MapTimerThread.getInstance();

6.
封包的处理(ctrl+q)

import l1j.server.server.model.Instance.L1PcInstance;
/**
* 地图剩余时间(ctrl+q)
*
* @author Psnnwe
*
*/
public class S_MapTimerOutextends ServerBasePacket {
private byte[] _byte = null;
private static final String S_MAP_TIMER_OUT = "[S] S_MapTimerOut";
/**
* ctrl+Q中地图剩余时间
*/
public static final int DISPLAY_MAP_TIME = 159;
/**
* ctrl+Q显示剩余时间
*
* @param pc
*/
public S_MapTimerOut(final L1PcInstance pc) {
this.writeC(Opcodes_Server.S_OPCODE_PACKETBOX);
this.writeC(DISPLAY_MAP_TIME);
this.writeD(3);// 组数
this.writeD(1);// 排序
this.writeS("$12125"); // 奇岩监狱
final int g_time = pc.getRocksPrisonTime() % 100000;
final int g_maxTime = 10800; // 3小时(秒)
final int g_newTime = g_maxTime - g_time;
this.writeD(g_newTime);
this.writeD(2);
this.writeS("$6081"); // 象牙塔
final int i_time = pc.getIvoryTowerTime() % 100000;
final int i_maxTime = 3600; // 1小时(秒)
final int i_newTime = i_maxTime - i_time;
this.writeD(i_newTime);
this.writeD(3);
this.writeS("$12126"); // 拉斯塔巴德地监
final int l_time = pc.getLastabardTime() % 100000;
final int l_maxTime = 43200; // 12小时(秒)
final int l_newTime = l_maxTime - l_time;
this.writeD(l_newTime);
}
@Override
public byte[] getContent() {
if (this._byte == null) {
this._byte = this.getBytes();
}
return this._byte;
}
@Override
public String getType() {
return S_MAP_TIMER_OUT;
}
}

7.
画面左上角计时器

/**
* 计时地图左上角计时器
*
* @author Psnnwe
*
*/
public final class S_MapTimer extends ServerBasePacket {
private static final String S_MAP_TIMER = "[S] S_MapTimer";
/**
* 字节
*/
private byte[] _byte;
/**
* 显示定时器地图的剩余时间
**/
public static final int MAP_TIMER = 153;
/**
* 地图计时器
*
* @param value
* 剩余的时间(秒)
*/
public S_MapTimer(final int value) {
this.writeC(Opcodes_Server.S_OPCODE_PACKETBOX);
this.writeC(MAP_TIMER);
this.writeH(value);
}
@Override
public byte[] getContent() {
if (this._byte == null) {
this._byte = this.getBytes();
}
return this._byte;
}
@Override
public String getType() {
return S_MAP_TIMER;
}
}

8.
C_NPCAction.java NPC发送
写法不同请自行变通,在此只举例奇岩 (注意是否再 if (obj instanceof L1NpcInstance) 判断内)

case 自行输入:
if (s.equalsIgnoreCase("teleportURL")) {
pc.sendPackets(new S_NPCTalkReturn(npc.getId(),"merlin2"));
}
if (s.equalsIgnoreCase("teleport giranD")) { // 发送至奇岩地监
final Calendar time = this.getRealTime();
final int entertime = pc.getRocksPrisonTime() % 100000;
final int enterday = pc.getRocksPrisonTime() / 100000;
final int dayofyear = time.get(Calendar.DAY_OF_YEAR);
final int maxtime = 3 * 60 * 60;// 最多可停留的时间10800(秒)
final int onehour = 1 * 60 * 60;// 1小时(3600秒)
if ((entertime >= maxtime) && (enterday == dayofyear)) {
pc.sendPackets(new S_ServerMessage(
L1SystemMessageId.$1522, "3"));
htmlid = "";
return;
} else {
if (enterday < dayofyear) {
pc.setRocksPrisonTime(dayofyear * 100000);
}
if (pc.getInventory().consumeItem(L1ItemId.ADENA,
1000)) { // 检查身上金币是否足够
final int a = entertime % 60;
if (a == 0) {
final int b = (maxtime - entertime)
/ onehour; // 取回小时
pc.sendPackets(new S_ServerMessage(
L1SystemMessageId.$1526, "" + b
+ ""));
} else if ((maxtime - entertime) < onehour) { // 不到一小时
final int c = maxtime - entertime;
pc.sendPackets(new S_ServerMessage(
L1SystemMessageId.$1527, "" + c
+ ""));
}
L1Teleport.teleport(pc, 32806, 32735,
(short) 53, 5, true);
} else {
PacketCreate.getInstance().sendSinglePackets(
pc, L1SystemMessageId.$189);
return;
}
}
}
break;


9.
C_Rank.java 查找的部分
增加


case 8: // 查找指令(/入场时间)
// 取余数(时间)
final int g_entertime = pc.getRocksPrisonTime() % 100000;
final int g_maxTime = 10800; // 3小时
int g_newTime = (g_maxTime - g_entertime) / 60;
if (g_newTime <= 0) {
g_newTime = 0;
}
final S_ServerMessage rocksPrison = new S_ServerMessage(
L1SystemMessageId.$2535, "$12125",
String.valueOf(g_newTime)); // [奇岩监狱]
pc.sendPackets(rocksPrison); // %0 : %0 : 剩余时间 %1 分
// 取余数(时间)
final int i_entertime = pc.getIvoryTowerTime() % 100000;
final int i_maxTime = 3600; // 1小时
int i_newTime = (i_maxTime - i_entertime) / 60;
if (i_newTime <= 0) {
i_newTime = 0;
}
final S_ServerMessage ivorytower = new S_ServerMessage(
L1SystemMessageId.$2535, "$6081", String.valueOf(i_newTime)); // [象牙塔]
pc.sendPackets(ivorytower); // %0 : %0 : 剩余时间 %1 分
// 取余数(时间)
final int l_entertime = pc.getLastabardTime() % 100000;
final int l_maxTime = 43200; // 12小时
int l_newTime = (l_maxTime - l_entertime) / 60;
if (l_newTime <= 0) {
l_newTime = 0;
}
final S_ServerMessage lastabard = new S_ServerMessage(
L1SystemMessageId.$2535, "$12126",
String.valueOf(l_newTime)); // [拉斯塔巴德地监]
pc.sendPackets(lastabard); // %0 : %0 : 剩余时间 %1 分
break;
case 9: // 地图剩余使用时间
pc.sendPackets(new S_MapTimerOut(pc));
break;
end


10.
C_SendLocation.java 发送座标位置(更新ctrl+q的显示)
增加


case 9: // 更新Ctrl+Q的显示时间
pc.sendPackets(new S_MapTimerOut(pc));
break;

❤️ 0 💬 0 🔄 0 🔖 0
分享 f L 𝕏 已拷贝

💬 留言

还没有留言,来抢头香吧!

LINE 咨询
比较:
开始比较
PlaySF

ui.pwa_install

ui.install_prompt