Jump to content

Recommended Posts

Posted (edited)

Hello everyone, today I bring you something interesting that was in my head all this time.

I've always thought:'' if a fortress serves a similar function to a castle, why not give you a crown?

''Was a fortress worth much less than a castle?''

 

by consequent I began to write a code in which to conquer a fortress, like a circlet of that fortress and also [if you're a clan leader] a crown as the'' King'', these items are customs, it clarify.

 

Credits belongs to me: CAI

 

it is functional in the rev 1004 of L2JFrozen.

 

Q: CAN IMPROVE? 
A: yes a lot. 
 
Q: I DO NOT LIKE THOSE ID CROWNS, CUSTOM FOR HATE IT, I CAN PUT HATS EXISTING IN THE GAME? 
R: That's right, but you must update iD that will share in the core. 
 
Q: I WANT TO LEAVE IT AS IS TO USE THIS SO THAT I NEED? 
A: You must create crowns in custom_armor or armor [according to you prefer], create their xml to not have mistakes, and enjoy!
 
===================================================================
--- head-src/com/l2jfrozen/gameserver/model/entity/siege/fort.java  (revision 1004)
+++ head-src/com/l2jfrozen/gameserver/model/entity/siege/fort.java  (working copy)
@@ -0,1 +0,1 @@

import com.l2jfrozen.gameserver.datatables.csv.DoorTable;
import com.l2jfrozen.gameserver.datatables.sql.ClanTable;
+import com.l2jfrozen.gameserver.managers.FortCrownManager;
import com.l2jfrozen.gameserver.model.L2Clan;


+/**
+ * @author CAI
+ */

@@ -537,1 +540,1 @@

 // ============================================================================

 // Announce to clan memebers
 if(clan != null)
 {
 clan.setHasFort(getFortId()); // Set has fort flag for new owner
 Announcements.getInstance().announceToAll(clan.getName() + " has taken " + getName() + " fort!");
 clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
 clan.broadcastToOnlineMembers(new PlaySound(1, "Siege_Victory", 0, 0, 0, 0, 0));
 //ThreadPoolManager.getInstance().scheduleGeneral(new FortUpdater(clan, 1), 3600000);   // Schedule owner tasks to start running
+ // give crowns
+ FortCrownManager.getInstance().checkCrowns(clan);

 ThreadPoolManager.getInstance().scheduleGeneral(new CastleUpdater(clan, 1), 3600000); // Schedule owner tasks to start running
 }
=============================================================================================
--- head-src/com/l2jfrozen/gameserver/managers/FortCrownManager.java  (revision 1004)
+++ head-src/com/l2jfrozen/gameserver/managers/FortCrownManager.java  (working copy)
@@ -0,1 +0,1 @@
+/*
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jfrozen.gameserver.managers;

+import java.util.logging.Logger;

+import com.l2jfrozen.gameserver.datatables.CrownTable;
+import com.l2jfrozen.gameserver.model.L2Clan;
+import com.l2jfrozen.gameserver.model.L2ClanMember;
+import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
+import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jfrozen.gameserver.model.entity.siege.Fort;

+/**
+ * @author CAI
+ */
+public class FortCrownManager
+{
+ protected static final Logger _log = Logger.getLogger(FortCrownManager.class.getName());
+ private static FortCrownManager _instance;
+
+ public static final FortCrownManager getInstance()
+ {
+ if(_instance == null)
+ {
+ _instance = new FortCrownManager();
+ }
+ return _instance;
+ }
+
+ public FortCrownManager()
+ {
+ _log.info("FortCrownManager: initialized");
+ }
+
+ public void checkCrowns(L2Clan clan)
+ {
+ if(clan == null)
+ return;
+
+ for(L2ClanMember member : clan.getMembers())
+ {
+ if(member != null && member.isOnline() && member.getPlayerInstance() != null)
+ {
+ checkCrowns(member.getPlayerInstance());
+ }
+ }
+ }
+
+ public void checkCrowns(L2PcInstance activeChar)
+ {
+ if(activeChar == null)
+ return;
+
+ boolean isLeader = false;
+ int crownId = -1;
+
+ L2Clan activeCharClan = activeChar.getClan();
+ L2ClanMember activeCharClanLeader;
+
+ if(activeCharClan != null)
+ {
+ activeCharClanLeader = activeChar.getClan().getLeader();
+ }
+ else
+ {
+ activeCharClanLeader = null;
+ }
+
+ if(activeCharClan != null)
+ {
+ Fort activeCharCastle = FortManager.getInstance().getFortByOwner(activeCharClan);
+
+ if(activeCharCastle != null)
+ {
+ crownId = CrownTable.getCrownId(activeCharCastle.getFortId());
+ }
+
+ activeCharCastle = null;
+
+ if(activeCharClanLeader != null && activeCharClanLeader.getObjectId() == activeChar.getObjectId())
+ {
+ isLeader = true;
+ }
+ }
+
+ activeCharClan = null;
+ activeCharClanLeader = null;
+
+ if(crownId > 0)
+ {
+ if(isLeader && activeChar.getInventory().getItemByItemId(60026) == null)
+ {
+ activeChar.addItem("Crown", 60026, 1, activeChar, true);
+ activeChar.getInventory().updateDatabase();
+ }
+
+ if(activeChar.getInventory().getItemByItemId(crownId) == null)
+ {
+ activeChar.addItem("Crown", crownId, 1, activeChar, true);
+ activeChar.getInventory().updateDatabase();
+ }
+ }
+
+ boolean alreadyFoundCirclet = false;
+ boolean alreadyFoundCrown = false;
+
+ for(L2ItemInstance item : activeChar.getInventory().getItems())
+ {
+ if(CrownTable.getCrownList().contains(item.getItemId()))
+ {
+ if(crownId > 0)
+ {
+ if(item.getItemId() == crownId)
+ {
+ if(!alreadyFoundCirclet)
+ {
+ alreadyFoundCirclet = true;
+ continue;
+ }
+ }
+ else if(item.getItemId() == 60026 && isLeader)
+ {
+ if(!alreadyFoundCrown)
+ {
+ alreadyFoundCrown = true;
+ continue;
+ }
+ }
+ }
+
+ activeChar.destroyItem("Removing Crown", item, activeChar, true);
+ activeChar.getInventory().updateDatabase();
+ }
+ }
+ }
+}
/no new line in the end of document.
===================================================================
--- head-src/com/l2jfrozen/gameserver/Managers/FortManager.java  (revision 1004)
+++ head-src/com/l2jfrozen/gameserver/Managers/FortManager.java  (working copy)
@@ -0,1 +0,1 @@

+import com.l2jfrozen.Config;
import com.l2jfrozen.gameserver.model.L2Clan;
+import com.l2jfrozen.gameserver.model.L2ClanMember;
import com.l2jfrozen.gameserver.model.L2Object;
+import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
+import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.model.entity.siege.Fort;
import com.l2jfrozen.util.CloseUtil;
import com.l2jfrozen.util.database.L2DatabaseFactory;

/**
 * @author CAI
 */

 // Data Field
 private List<Fort> _forts = new FastList<Fort>();

 // =========================================================
 // Constructor
+ //Circlets customs of Fortress
+ private static final int _fortCirclets[] =
+ {
+ 0, 60005, 60006, 60007, 60008, 60009, 60010, 60011, 60012, 60013, 60014, 60015, 60016, 60017, 60018, 60019, 60020, 60021, 60022, 60023, 60024, 60025
+ };
 
public FortManager()
 {

 
@@ -220,1 +222,1 @@ 



public final List<Fort> getForts()
 {
 return _forts;
 }
 
+ int _fortId = 1; // from this fortress
+
+ public int getCirclet()
+ {
+ return getCircletByFortId(_fortId);
+ }
+
+ public int getCircletByFortId(int fortId)
+ {
+ if(fortId > 100 && fortId < 122)
+ return _fortCirclets[fortId];
+
+ return 0;
+ }
+
+ // remove this fort's circlets from the clan
+ public void removeCirclet(L2Clan clan, int fortId)
+ {
+ for(L2ClanMember member : clan.getMembers())
+ {
+ removeCirclet(member, fortId);
+ }
+ }
+
+ //TODO: 
+ //added: remove clan cirlet for clan leaders
+ public void removeCirclet(L2ClanMember member, int fortId)
+ {
+ if(member == null)
+ return;
+
+ L2PcInstance player = member.getPlayerInstance();
+ int circletId = getCircletByFortId(fortId);
+
+ if(circletId != 0)
+ {
+ // online-player circlet removal
+ if(player != null)
+ {
+ try
+ {
+ if(player.isClanLeader())
+ {
+ L2ItemInstance crown = player.getInventory().getItemByItemId(6841);
+
+ if(crown != null)
+ {
+ if(crown.isEquipped())
+ {
+ player.getInventory().unEquipItemInSlotAndRecord(crown.getEquipSlot());
+ }
+ player.destroyItemByItemId("FortCrownRemoval", 60026, 1, player, true);
+ crown = null;
+ }
+ }
+
+ L2ItemInstance circlet = player.getInventory().getItemByItemId(circletId);
+ if(circlet != null)
+ {
+ if(circlet.isEquipped())
+ {
+ player.getInventory().unEquipItemInSlotAndRecord(circlet.getEquipSlot());
+ }
+ player.destroyItemByItemId("FortCircletRemoval", circletId, 1, player, true);
+ circlet = null;
+ }
+ return;
+ }
+ catch(NullPointerException e)
+ {
+ // continue removing offline
+ if(Config.ENABLE_ALL_EXCEPTIONS)
+ e.printStackTrace();
+ }
+ }
+ // else offline-player circlet removal
+ Connection con = null;
+ PreparedStatement statement = null;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection(false);
+ statement = con.prepareStatement("DELETE FROM items WHERE owner_id = ? and item_id = ?");
+ statement.setInt(1, member.getObjectId());
+ statement.setInt(2, 60026);
+ statement.execute();
+ statement.close();
+ statement = null;
+
+ statement = con.prepareStatement("DELETE FROM items WHERE owner_id = ? and item_id = ?");
+ statement.setInt(1, member.getObjectId());
+ statement.setInt(2, circletId);
+ statement.execute();
+ statement.close();
+ statement = null;
+ }
+ catch(Exception e)
+ {
+ _log.info("Failed to remove fortress circlets offline for player " + member.getName());
+ e.printStackTrace();
+ }
+ finally
+ {
+ CloseUtil.close(con);
+ con = null;
+ }
+ }
+ player = null;
+ }
+ 
+
 private static class SingletonHolder
 {
===================================================================
--- head-src/com/l2jfrozen/gameserver/datatables/CrownTable.java  (revision 986)
+++ head-src/com/l2jfrozen/gameserver/datatables/CrownTable.java  (working copy)
@@ -45,1 +48,1 @@
 _crownList.add(8182); // Rune
 _crownList.add(8183); // Schuttgart
+ //==============================================
+ //========== Custom fortress crown =============
+ //============= AUTHOR: CAI ====================
+ //==============================================
+ _crownList.add(60005); // Circlet of Archaic
+ _crownList.add(60006); // Circlet of Bayou
+ _crownList.add(60007); // Circlet of Tanor
+ _crownList.add(60008); // Circlet of Hunter
+ _crownList.add(60009); // Circlet of Cloud
+ _crownList.add(60010); // Circlet of Borderland
+ _crownList.add(60011); // Circlet of Southern
+ _crownList.add(60012); // Circlet of Aaru
+ _crownList.add(60013); // Circlet of Demon
+ _crownList.add(60014); // Circlet of Western
+ _crownList.add(60015); // Circlet of White Sand
+ _crownList.add(60016); // Circlet of Monastery
+ _crownList.add(60017); // Circlet of Dragonspine
+ _crownList.add(60018); // Circlet of Shanty
+ _crownList.add(60019); // Circlet of Valley
+ _crownList.add(60020); // Circlet of Antharas
+ _crownList.add(60021); // Circlet of Narsell
+ _crownList.add(60022); // Circlet of Ivory
+ _crownList.add(60023); // Circlet of Hive
+ _crownList.add(60024); // Circlet of Swamp
+ _crownList.add(60025); // Circlet of Floran
+ _crownList.add(60026); // Crown Fortess
+ //==============================================
+ //========== Fin Coronas Fortalezas Customs=====
+ //============== AUTOR: CAI ====================
+ //==============================================
 }

@@ -115,1 +121,1 @@

 // Schuttgart
 case 9:
 CrownId = 8183;
 break;
- default:
- CrownId = 0;
- break;
- }
+ //==================================
+ //=== Var of crowns and their Ids
+ //==================================
+ // Shanty
+ case 101:
+ CrownId = 60018;
+ break;
+ // Southern
+ case 102:
+ CrownId = 60011;
+ break;
+ // Hive
+ case 103:
+ CrownId = 60023;
+ break;
+ // Valley
+ case 104:
+ CrownId = 60019;
+ break;
+ // Ivory
+ case 105:
+ CrownId = 60022;
+ break;
+ // Narsell
+ case 106:
+ CrownId = 60021;
+ break;
+ // Bayou
+ case 107:
+ CrownId = 60006;
+ break;
+ // White Sand
+ case 108:
+ CrownId = 60015;
+ break;
+ // Borderland
+ case 109:
+ CrownId = 60010;
+ break;
+ // Swampland
+ case 110:
+ CrownId = 60024;
+ break;
+ // Archaic
+ case 111:
+ CrownId = 60005;
+ break;
+ // Floran
+ case 112:
+ CrownId = 60025;
+ break;
+ // CloudMountain
+ case 113:
+ CrownId = 60009;
+ break;
+ // Tanor
+ case 114:
+ CrownId = 60007;
+ break;
+ // Dragonspine
+ case 115:
+ CrownId = 60017;
+ break;
+ // Antharas
+ case 116:
+ CrownId = 60020;
+ break;
+ // Western
+ case 117:
+ CrownId = 60014;
+ break;
+ // Hunters
+ case 118:
+ CrownId = 60008;
+ break;
+ // Aaru
+ case 119:
+ CrownId = 60012;
+ break;
+ // Demon
+ case 120:
+ CrownId = 60013;
+ break;
+ // Monastic
+ case 121:
+ CrownId = 60016;
+ break;
+ default:
+ CrownId = 0;
+ break;
+ }
 return CrownId;
===================================================================
--- head-src/com/l2jfrozen/gameserver/network/clientpackets/EnterWorld.java  (revision 1004)
+++ head-src/com/l2jfrozen/gameserver/network/clientpackets/EnterWorld.java  (working copy)
@@ -0,1 +0,5 @@
import com.l2jfrozen.gameserver.managers.DimensionalRiftManager;
+import com.l2jfrozen.gameserver.managers.FortCrownManager;
+import com.l2jfrozen.gameserver.managers.FortManager;
+import com.l2jfrozen.gameserver.managers.FortSiegeManager;
import com.l2jfrozen.gameserver.managers.PetitionManager;

@@ -858,1 +858,5 @@
private void notifyCastleOwner(L2PcInstance activeChar)
 {
 L2Clan clan = activeChar.getClan();
 if (clan != null)
 {
 if (clan.getHasCastle() > 0)
 {
 Castle castle = CastleManager.getInstance().getCastleById(clan.getHasCastle());
 if ((castle != null) && (activeChar.getObjectId() == clan.getLeaderId()))
 Announcements.getInstance().announceToAll("Lord " + activeChar.getName() + " Ruler Of " + castle.getName() + " Castle is now Online!");
 }
 }
 }
+ //==============================================
+ //========== Custom fortress crowns ============
+ //============= AUTHOR: CAI ====================
+ //==============================================
+
+ private void notifyFortOwner(L2PcInstance activeChar)
+ {
+ L2Clan clan = activeChar.getClan();
+ if (clan != null)
+ {
+ if (clan.getHasFort() > 0)
+ {
+ Fort fort = FortManager.getInstance().getFortById(clan.getHasFort());
+ if ((fort != null) && (activeChar.getObjectId() == clan.getLeaderId()))
+ Announcements.getInstance().announceToAll(activeChar.getName() + ", Emperor Of " + fort.getName() + " Fortress is now Online!");
+ }
+ }
+ }

 @Override
 public String getType()
===================================================================
--- head-src/com/l2jfrozen/Config.java  (revision 1004)
+++ head-src/com/l2jfrozen/Config.java  (working copy)
@@ -576,1 +576,5 @@

 public static int DUAL_AIO_ID;
 
public static boolean ANNOUNCE_CASTLE_LORDS;
-
+ public static boolean ANNOUNCE_FORT_LORDS;
+ 
/** Configuration to allow custom items to be given on character creation */

@@ -683,10 +683,13 @@

                ALLOW_AIO_USE_GK = Boolean.parseBoolean(otherSettings.getProperty("AllowAioUseGk", "False"));
        ALLOW_AIO_USE_CM = Boolean.parseBoolean(otherSettings.getProperty("AllowAioUseClassMaster", "False"));
        DUAL_AIO_ID = Integer.parseInt(otherSettings.getProperty("DualAioItemId", "6580"));
        
        ANNOUNCE_CASTLE_LORDS = Boolean.parseBoolean(otherSettings.getProperty("AnnounceCastleLords", "False"));
-        if(ENABLE_AIO_SYSTEM) //create map if system is enabled
+ //==============================================
+ //========== Custom fortress crown =============
+ //============= AUTHOR: CAI ====================
+ //==============================================
+        ANNOUNCE_FORT_LORDS = Boolean.parseBoolean(otherSettings.getProperty("AnnounceFortLords", "False"));
+        if(ENABLE_AIO_SYSTEM) //create map if system is enabled
        {
     
===================================================================
--- config/head/other.properties  (revision 1004)
+++ config/head/other.properties  (working copy)
@@ -235,1 +235,1 @@

# Announce castle lords on enter game. default = false 
AnnounceCastleLords = False

-# Click task when target an Npc
+ //==============================================
+ //========== Custom fortress crown =============
+ //============== AUTOR: CAI ====================
+ //==============================================
+# Announce fort lords on enter game. default = false

+AnnounceFortLords = False
+
+# Click task when target an Npc 
Edited by CAI
  • 2 weeks later...
Posted

its a nice idea i like it but u should add also some restrict lines so players that dont have any more fortress wont be able to use the crowns etc..

also i think that in frozen the fortress sieges doesnt work but i'm not sure about this..

anyway ;D i rly like it gj

Posted

its a nice idea i like it but u should add also some restrict lines so players that dont have any more fortress wont be able to use the crowns etc..

also i think that in frozen the fortress sieges doesnt work but i'm not sure about this..

anyway ;D i rly like it gj

 

well, in frozen , the fortress sieges works very well, in revision 1004. i should add the restrictions, i know xD but the code is in a ''beta version'', it can be upgraded :D im working on it, thanks for your advice!!

your patch have mistakes but is really nice idea :) weldone

i know u.u the code is still immature xD I'm working on putting restrictions and privileges for owners of fortresses, thanks for your advice too! :D

Posted (edited)

The manager is beyond useless, just static the 2 methods and move them in another class.

 

You do a lot of redundant checks aswell, some methods exist to avoid to code them. For example, your checkCrowns( method content can be divided by 2.

 

And I know you're happy and feel awesome enough to put credits (btw it's "author"), but those comments take a lot of space for nothing and confuse the reading of the patch (You add 5 lines, 1 is a legit line, 4 is a comment).

Edited by Tryskell
Posted

The manager is beyond useless, just static the 2 methods and move them in another class.

 

You do a lot of redundant checks aswell, some methods exist to avoid to code them. For example, your checkCrowns( method content can be divided by 2.

 

And I know you're happy and feel awesome enough to put credits (btw it's "author"), but those comments take a lot of space for nothing and confuse the reading of the patch (You add 5 lines, 1 is a legit line, 4 is a comment).

is for that reason that I said that the code is still in beta mode, can still be improved a lot, I'm working on it. Autor means Author (in spanish xD) its a languaje error :p

I do not think the confucion is provided that has comments, since they are distinct with respect to code, are also beautiful xD

 

thanks so much Tryskell for your opinion, i'll take it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...