사이트 로그인
2016.06.29 10:34
에바팩 판도라팩 3.63버젼을 기준으로하였으며
테스트다해봤고 공성돌아가는거까지 확인했습니다 ㅎ
기존소스와달라진점은 캐슬테이블에 성만 추가하면 공성타이머부분은 알아서돌아줍니다.
이전처럼 소스+디비 다수정할필요는없어졌어요 제작 : 킹덤
WarTimeController.java
아래꺼 다 복사해서 고대로 컨트롤 A 컨트롤 V
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/
package l1j.server.server.TimeController;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import l1j.server.Config;
import l1j.server.server.datatables.CastleTable;
import l1j.server.server.datatables.CharacterTable;
import l1j.server.server.datatables.DoorSpawnTable;
import l1j.server.server.model.L1CastleLocation;
import l1j.server.server.model.L1Clan;
import l1j.server.server.model.L1Object;
import l1j.server.server.model.L1Teleport;
import l1j.server.server.model.L1War;
import l1j.server.server.model.L1WarSpawn;
import l1j.server.server.model.L1World;
import l1j.server.server.model.L1CastleData;
import l1j.server.server.model.Instance.L1CrownInstance;
import l1j.server.server.model.Instance.L1DoorInstance;
import l1j.server.server.model.Instance.L1FieldObjectInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.model.Instance.L1TowerInstance;
import l1j.server.server.model.gametime.RealTimeClock;
import l1j.server.server.serverpackets.S_PacketBox;
import l1j.server.server.templates.L1Castle;
public class WarTimeController implements Runnable {
private static WarTimeController _instance;
private L1Castle _l1castle = null;
private int ALT_WAR_TIME_UNIT = Config.ALT_WAR_TIME_UNIT;
private int ALT_WAR_TIME = Config.ALT_WAR_TIME;
private int ALT_WAR_INTERVAL_UNIT = Config.ALT_WAR_INTERVAL_UNIT;
private int ALT_WAR_INTERVAL = Config.ALT_WAR_INTERVAL;
private ArrayList<L1Castle> castlelist = new ArrayList<L1Castle>();
private ArrayList<L1Castle> Waringcastlelist = new ArrayList<L1Castle>();
private WarTimeController() {
L1CastleData CD = new L1CastleData();
castlelist = CD.CatleDate(); //성리스트를 넣는다.
}
/**
* Run()
*/
public void run() {
try {
while (true) {
try {
checkWarTime(); // 전쟁 시간을 체크
Thread.sleep(1000);
} catch (Exception e) {
}
}
} catch (Exception e1) {
}
}
/**
* 싱글톤 패턴
* @return _instance
*/
public static WarTimeController getInstance() {
if (_instance == null) {
_instance = new WarTimeController();
}
return _instance;
}
/**
* 테이블및 castle정보 reLoad
*/
public void reload() {
L1CastleData CD = new L1CastleData();
castlelist = CD.CatleDate(); //성리스트를 넣는다.
}
/**
* 해당성의 공성시간을 변경하고 공지한다.
* @param name 성이름
* @param cal 시간
*/
public void setWarStartTime(String name, Calendar cal) {
Calendar endtime;
if (name == null) {
return;
}
if (name.length() == 0) {
return;
}
int index =0;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
for (L1Castle castle : castlelist) {
if (castle.getName().startsWith(name)) {
index = castlelist.indexOf(castle);
castle.setWarTime(cal);
endtime = (Calendar) castle.getWarTime().clone();
endtime.add(ALT_WAR_TIME_UNIT,ALT_WAR_TIME);
castlelist.set(index,castle);
// 모든 유저에게 공성시간 알리기
L1World.getInstance().broadcastServerMessage(String.format("%s공성시간: %s ~ %s", castle.getName(), formatter.format(castle.getWarTime()), formatter.format(endtime)));
}
}
}
/**
* void 공성시간체크
*/
private void checkWarTime() {
Calendar Rtime = RealTimeClock.getInstance().getRealTimeCalendar();
Calendar endtime;
int index = 0;
for(L1Castle _castle : castlelist){
index = castlelist.indexOf(_castle);
endtime = (Calendar) _castle.getWarTime().clone();
endtime.add(ALT_WAR_TIME_UNIT,ALT_WAR_TIME);
if(_castle.getWarTime().before(Rtime) && endtime.after(Rtime)){
if (!_castle.isNowwar()){
_castle.setNowwar(true);
castlelist.set(index,_castle);
StartWar(_castle);
System.out.println(_castle.getName()+"시작");
}
}else if (endtime.before(Rtime)){
if (_castle.isNowwar()){
EndWar(_castle);
System.out.println(_castle.getName()+"종료");
}
}
}
}
/**
* 공성시간이맞다면 공성시작
* @param _castle2 castlelist의 index
*/
private void StartWar(L1Castle _castle){
L1WarSpawn warspawn = null;
warspawn = new L1WarSpawn();
warspawn.SpawnFlag(_castle.getId()); // 깃발을 소환한다.
// 성문을 수리해 닫는다
for (L1DoorInstance door : DoorSpawnTable.getInstance()
.getDoorList()) {
if (L1CastleLocation.checkInWarArea(_castle.getId(), door)) {
door.setAutoStatus(0);// 자동수리를 해제
door.repairGate();
}
}
if (_castle.getCastleSecurity() == 1){
securityStart(_castle);// 치안관리
}
for (L1War war : L1World.getInstance().getWarList()) {
if (war == null) {
continue;
}
for (String attackClan : war.GetAttackClanList()) {
war.CeaseWar(attackClan, war.GetDefenceClanName());
}
}
L1World.getInstance().broadcastPacketToAll(new S_PacketBox(S_PacketBox.MSG_WAR_BEGIN, _castle.getId())); // %s의
// 공성전이
// 시작되었습니다.
L1World.getInstance().broadcastPacketToAll(new S_PacketBox(S_PacketBox.GREEN_MESSAGE,"공성전이 시작되었습니다~~!!! "));
int[] loc = new int[3];
L1Clan clan = null;
for (L1PcInstance pc : L1World.getInstance()
.getAllPlayers()) {
int castleId = _castle.getId();
if (L1CastleLocation.checkInWarArea(castleId, pc)
&& !pc.isGm()) {
clan = L1World.getInstance().getClan(
pc.getClanname());
if (clan != null) {
if (clan.getCastleId() == castleId) {
continue;
}
}
loc = L1CastleLocation.getGetBackLoc(castleId);
L1Teleport.teleport(pc, loc[0], loc[1],
(short) loc[2], 5, true);
}
}
}
/**
* 공성시간이 지났다면 공성종료
* @param _castle2 castlelist의 index
*/
private void EndWar(L1Castle _castle){
_castle.setNowwar(false);
L1World.getInstance().broadcastPacketToAll(
new S_PacketBox(S_PacketBox.MSG_WAR_END, _castle.getId())); // %s의
// 공성전이
// 종료했습니다.
_castle.getWarTime().add(ALT_WAR_INTERVAL_UNIT, ALT_WAR_INTERVAL);
_castle.setTaxRate(10); // 세율10프로
CastleTable.getInstance().updateCastle(_castle);
castlelist.set(_castle.getId(), _castle); // 저장
WarParkClear(_castle.getId());
}
/**
* 공성존 정리 (깃발,왕관,수호탑수리등등)
* @param castleNum castleID
*/
private void WarParkClear(int castleNum){
L1WarSpawn warspawn = null;
int castle_id = castleNum;
L1FieldObjectInstance flag = null;
L1CrownInstance crown = null;
L1TowerInstance tower = null;
for (L1Object l1object : L1World.getInstance().getObject()) {
// 전쟁 에리어내의 기를 지운다
if (l1object instanceof L1FieldObjectInstance) {
flag = (L1FieldObjectInstance) l1object;
if (L1CastleLocation
.checkInWarArea(castle_id, flag)) {
flag.deleteMe();
}
}
// 크라운이 있는 경우는, 크라운을 지워 타워를 spawn 한다
if (l1object instanceof L1CrownInstance) {
crown = (L1CrownInstance) l1object;
if (L1CastleLocation.checkInWarArea(castle_id,
crown)) {
crown.deleteMe();
}
}
if (l1object instanceof L1TowerInstance) {
tower = (L1TowerInstance) l1object;
if (L1CastleLocation.checkInWarArea(castle_id,
tower)) {
tower.deleteMe();
}
}
}
warspawn = new L1WarSpawn();
warspawn.SpawnTower(castle_id);
for (L1DoorInstance door : DoorSpawnTable.getInstance()
.getDoorList()) {
if (L1CastleLocation.checkInWarArea(castle_id, door)) {
door.repairGate();
}
}
}
// 공성종료
public void stopWar(String name) {
if (name == null) {
return;
}
if (name.length() == 0) {
return;
}
int index = 0;
for(L1Castle _castle : castlelist){
if (_castle.getName().startsWith(name)) {
_castle.setNowwar(false);
index = castlelist.indexOf(_castle);
L1World.getInstance().broadcastPacketToAll(
new S_PacketBox(S_PacketBox.MSG_WAR_END, _castle.getId())); // %s의
// 공성전이
// 종료했습니다.
_castle.getWarTime().add(ALT_WAR_INTERVAL_UNIT, ALT_WAR_INTERVAL);
_castle.setTaxRate(10); // 세율10프로
CastleTable.getInstance().updateCastle(_castle);
castlelist.set(index, _castle); // 저장
WarParkClear(_castle.getId());
}
}
}
/**
* 현재 공성중인성인지
* @param castlenum Castle ID
* @return == ID ? True : false
*/
public boolean isNowWar(int castlenum) {
for(L1Castle _castle : castlelist){
if(_castle.getId() ==castlenum){
if(_castle.isNowwar()){
return true;
}
}
}
return false;
}
/**
* 해당유저에게 공성중인 성을 알려주는 메세지
* @param player 넘어오는 player
*/
public void checkCastleWar(L1PcInstance player) {
for(L1Castle _castle : castlelist){
if (_castle.isNowwar()) {
player.sendPackets(new S_PacketBox(S_PacketBox.MSG_WAR_GOING,_castle.getId())); // %s의 공성전이 진행중입니다.
// L1World.getInstance().broadcastPacketToAll(new S_PacketBox(S_PacketBox.GREEN_MESSAGE,"공성전이 진행중입니다. "));
}
}
}
//공성종료
private void securityStart(L1Castle castle) {
int castleId = castle.getId();
int a = 0, b = 0, c = 0, d = 0, e = 0;
int[] loc = new int[3];
L1Clan clan = null;
switch (castleId) {
case 1:
case 2:
case 3:
case 4:
a = 52;
b = 248;
c = 249;
d = 250;
e = 251;
break;
case 5:
case 6:
case 7:
default:
break;
}
for (L1PcInstance pc : L1World.getInstance().getAllPlayers()) {
if ((pc.getMapId() == a || pc.getMapId() == b || pc.getMapId() == c
|| pc.getMapId() == d || pc.getMapId() == e)
&& !pc.isGm()) {
clan = L1World.getInstance().getClan(pc.getClanname());
if (clan != null) {
if (clan.getCastleId() == castleId) {
continue;
}
}
loc = L1CastleLocation.getGetBackLoc(castleId);
L1Teleport
.teleport(pc, loc[0], loc[1], (short) loc[2], 5, true);
}
}
castle.setCastleSecurity(0);
CastleTable.getInstance().updateCastle(castle);
CharacterTable.getInstance().updateLoc(castleId, a, b, c, d, e);
}
}
이건 l1j.server.server.model 폴더에 위치해주시면되고
새로만드셔야되는 java파일입니다. 파일명 대소문자 꼭 똑같이하세요
L1CastleDate.java
package l1j.server.server.model;
import java.util.ArrayList;
import java.util.Calendar;
import l1j.server.server.datatables.CastleTable;
import l1j.server.server.templates.L1Castle;
public class L1CastleData {
private ArrayList<L1Castle> castlelist = new ArrayList<L1Castle>();
public L1CastleData(){
Calendar endtime;
castlelist = CastleTable.getInstance().CastleLoad();
}
public ArrayList<L1Castle> CatleDate(){
return castlelist;
}
}
CastleTable.java 아래꼐 없다면 추가해주세요
/**
* Castle Table ArrayList형식으로 넘겨준다
* @return ArrayList<L1Castle>
*/
public ArrayList<L1Castle> CastleLoad(){
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
ArrayList<L1Castle> castlelist = new ArrayList<L1Castle>();
L1Castle _castle = null;
try{
con = L1DatabaseFactory.getInstance().getConnection();
pstm = con
.prepareStatement("Select * from castle");
rs = pstm.executeQuery();
while(rs.next()){
_castle = new L1Castle(rs.getInt(1),rs.getString(2));
_castle.setWarTime(timestampToCalendar((Timestamp) rs
.getObject(3)));
_castle.setTaxRate(rs.getInt(4));
_castle.setPublicMoney(rs.getInt(5));
_castle.setPublicReadyMoney(rs.getInt(6));
_castle.setShowMoney(rs.getInt(7));
_castle.setWarBaseTime(rs.getInt(8));
_castle.setCastleSecurity(rs.getInt(9));
castlelist.add(_castle);
}
}catch(Exception e){
e.printStackTrace();
}finally{
SQLUtil.close(pstm);
SQLUtil.close(con);
SQLUtil.close(rs);
}
return castlelist;
}
[출처] 공성소스 최종수정판 테스트완료 (비공개 카페) |