Jump to content

Recommended Posts

Posted (edited)

Well i had 30 minute free so i coded a faction for aCis, in which you can set unlimited factions no just 2.

The code contain the Npc Instance, exceptions and stuff like that.  I will update the code more soon.. 

 

Ps. i havent tested or idk if it works in some part so if you want apply the patch and write me.. 

 

Code here

 

Update 2.0 Code

Update 3.0 Code (Optimized code, fixed some things, added reward with no config yet) 18/1/2016

 

Sql files: 

/*
MySQL Data Transfer
Source Host: localhost
Source Database: acis
Target Host: localhost
Target Database: acis
Date: 17/1/2017 6:47:13 μμ
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for faction
-- ----------------------------
DROP TABLE IF EXISTS `faction`;
CREATE TABLE `faction` (
  `factionId` int(5) DEFAULT NULL,
  `factionName` text,
  `factionPos` text,
  `factionColor` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records 
-- ----------------------------
INSERT INTO `faction` VALUES ('1', 'Angels', '555;555;5555', 00FF00);
INSERT INTO `faction` VALUES ('2', 'Demons', '5125;51251;512', FF0000);

/*
MySQL Data Transfer
Source Host: localhost
Source Database: acis
Target Host: localhost
Target Database: acis
Date: 17/1/2017 6:48:01 μμ
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for characters
-- ----------------------------
DROP TABLE IF EXISTS `characters`;
CREATE TABLE `characters` (
  `account_name` varchar(45) DEFAULT NULL,
  `obj_Id` int(10) unsigned NOT NULL DEFAULT '0',
  `char_name` varchar(35) NOT NULL,
  `level` tinyint(3) unsigned DEFAULT NULL,
  `maxHp` mediumint(8) unsigned DEFAULT NULL,
  `curHp` mediumint(8) unsigned DEFAULT NULL,
  `maxCp` mediumint(8) unsigned DEFAULT NULL,
  `curCp` mediumint(8) unsigned DEFAULT NULL,
  `maxMp` mediumint(8) unsigned DEFAULT NULL,
  `curMp` mediumint(8) unsigned DEFAULT NULL,
  `face` tinyint(3) unsigned DEFAULT NULL,
  `hairStyle` tinyint(3) unsigned DEFAULT NULL,
  `hairColor` tinyint(3) unsigned DEFAULT NULL,
  `sex` tinyint(3) unsigned DEFAULT NULL,
  `heading` mediumint(9) DEFAULT NULL,
  `x` mediumint(9) DEFAULT NULL,
  `y` mediumint(9) DEFAULT NULL,
  `z` mediumint(9) DEFAULT NULL,
  `exp` bigint(20) unsigned DEFAULT '0',
  `expBeforeDeath` bigint(20) unsigned DEFAULT '0',
  `sp` int(10) unsigned NOT NULL DEFAULT '0',
  `karma` int(10) unsigned DEFAULT NULL,
  `pvpkills` smallint(5) unsigned DEFAULT NULL,
  `pkkills` smallint(5) unsigned DEFAULT NULL,
  `clanid` int(10) unsigned DEFAULT NULL,
  `race` tinyint(3) unsigned DEFAULT NULL,
  `classid` tinyint(3) unsigned DEFAULT NULL,
  `base_class` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `deletetime` bigint(20) DEFAULT NULL,
  `cancraft` tinyint(3) unsigned DEFAULT NULL,
  `title` varchar(16) DEFAULT NULL,
  `rec_have` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `rec_left` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `accesslevel` mediumint(9) DEFAULT '0',
  `online` tinyint(3) unsigned DEFAULT NULL,
  `onlinetime` int(11) DEFAULT NULL,
  `char_slot` tinyint(3) unsigned DEFAULT NULL,
  `lastAccess` bigint(20) unsigned DEFAULT NULL,
  `clan_privs` mediumint(8) unsigned DEFAULT '0',
  `wantspeace` tinyint(3) unsigned DEFAULT '0',
  `isin7sdungeon` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `punish_level` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `punish_timer` int(10) unsigned NOT NULL DEFAULT '0',
  `power_grade` tinyint(3) unsigned DEFAULT NULL,
  `nobless` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `hero` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `subpledge` smallint(6) NOT NULL DEFAULT '0',
  `last_recom_date` bigint(20) unsigned NOT NULL DEFAULT '0',
  `lvl_joined_academy` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `apprentice` int(10) unsigned NOT NULL DEFAULT '0',
  `sponsor` int(10) unsigned NOT NULL DEFAULT '0',
  `varka_ketra_ally` tinyint(4) NOT NULL DEFAULT '0',
  `clan_join_expiry_time` bigint(20) unsigned NOT NULL DEFAULT '0',
  `clan_create_expiry_time` bigint(20) unsigned NOT NULL DEFAULT '0',
  `death_penalty_level` smallint(5) unsigned NOT NULL DEFAULT '0',
  `factionid` int(5) DEFAULT '0',
  PRIMARY KEY (`obj_Id`),
  KEY `clanid` (`clanid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Npc Html (for test):

<html><head><body><center>
<font color=AAAAAA>Faction Manager</font><br>
<br>
Welcome, which path are you gonna follow?
<button value="Angels" action="bypass -h npc_%objectId%_1" back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df" width=125 height=21>
<button value="Demons" action="bypass -h npc_%objectId%_2" back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df" width=125 height=21>
<font color="cc9900"><img src="L2UI_CH3.herotower_deco" width=256 height=32></font><br1>
</center>
</body>
</head>
</html>

Edited by AccessDenied
Posted (edited)

Factions on enum.

+   public Collection<L2PcInstance> getFactionPlayers(int id)
+   {
+       Map<Integer, L2PcInstance> players = new ConcurrentHashMap<>();

NONONONONONONONO

Edited by Tryskell
Posted

Factions on enum.

+   public Collection<L2PcInstance> getFactionPlayers(int id)
+   {
+       Map<Integer, L2PcInstance> players = new ConcurrentHashMap<>();

NONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONONONONONONONONONONONONONONONONONJONO

How u suggest it?

Posted (edited)

How u suggest it?

 

Use .stream().filter( or at least a basic List<L2PcInstance>.

 

About Faction enum, I did similar thing for SevenSigns (and I do whenever I can now)

	public enum CabalType
	{
		NORMAL("No Cabal", "No Cabal"),
		DUSK("dusk", "Revolutionaries of Dusk"),
		DAWN("dawn", "Lords of Dawn");
		
		private final String _shortName;
		private final String _fullName;
		
		private CabalType(String shortName, String fullName)
		{
			_shortName = shortName;
			_fullName = fullName;
		}
		
		public String getShortName()
		{
			return _shortName;
		}
		
		public String getFullName()
		{
			return _fullName;
		}
		
		public static final CabalType VALUES[] = values();
	}

which avoid a lot of idiot methods like (or getFactionName, or whatever generic)

+   public Location getFactionLocation(L2PcInstance player)
+   {
+       int factionId = player.getFactionId();
+       Location loc = null;
+      
+       for (FactionHolder faction : factions.values())
+       {
+           if (faction.getFactionId() == factionId)
+           {
+               loc = faction.getFactionLoc();
+           }
+       }
+      
+       return loc;
+   }
Edited by Tryskell
Posted (edited)

I work in java 7 since i use l2jfreya from 2009 maybe you're right but ill update it anyway. In which part you refer to ?

 

First thing I noticed, you can avoid all this:

 

private static class TeleToBase implements Runnable
{


L2PcInstance _player = null;


public TeleToBase(L2PcInstance player)
{
_player = player;
}


@Override
public void run()
{
if (_player !=null)
{
Faction.getInstance().teleToBase(_player);
_player.sendMessage("Have a nice gameplay!");
}
}


}

using a lambda expression:

 

ThreadPoolManager.getInstance().scheduleGeneral(() -> player.teleToLocation(x, y, z), 5000);

 

 

Since you use a singleton on Faction, you should load the factions in a constructor, that's the whole point.

Plus, in loadFaction() method, if (result.next()) should be while (result.next()). But you should use xml for the factions' data.

+	public void teleToBase(L2PcInstance player)
+	{
+		int factionId = player.getFactionId();
+		
+		for (FactionHolder faction : factions.values())
+		{
+			if (faction.getFactionId() == factionId)
+			{
+				Location loc = faction.getFactionLoc();
+				player.teleToLocation(loc, 0);
+			}
+		}
+	} 

Can be done:

+	public void teleToBase(L2PcInstance player)
+	{
+		if (factions.containsKey(player.getFactionId())
+			player.teleToLocation(factions.get(player.getFactionId()).getFactionLoc(), 0);
+	} 

Same thing for onPlayerEnter() and getFactionLocation() (here again you can avoid 2 methods to get the faction's location by making a getFaction() method that can be used in many instances) method.

 

 

On L2FactionInstance, after calling player.setFactionId(), you should store the player in database because in some cases (critical error, dc) the faction he chose isn't going to be saved and he will have to choose again. Use player.store().

Edited by An4rchy
Posted

First thing I noticed, you can avoid all this:

 

private static class TeleToBase implements Runnable
{


L2PcInstance _player = null;


public TeleToBase(L2PcInstance player)
{
_player = player;
}


@Override
public void run()
{
if (_player !=null)
{
Faction.getInstance().teleToBase(_player);
_player.sendMessage("Have a nice gameplay!");
}
}


}

using a lambda expression:

 

ThreadPoolManager.getInstance().scheduleGeneral(() -> player.teleToLocation(x, y, z), 5000);

 

 

Since you use a singleton on Faction, you should load the factions in a constructor, that's the whole point.

Plus, in loadFaction() method, if (result.next()) should be while (result.next()). But you should use xml for the factions' data.

+	public void teleToBase(L2PcInstance player)
+	{
+		int factionId = player.getFactionId();
+		
+		for (FactionHolder faction : factions.values())
+		{
+			if (faction.getFactionId() == factionId)
+			{
+				Location loc = faction.getFactionLoc();
+				player.teleToLocation(loc, 0);
+			}
+		}
+	} 

Can be done:

+	public void teleToBase(L2PcInstance player)
+	{
+		if (factions.containsKey(player.getFactionId())
+			player.teleToLocation(factions.get(player.getFactionId()).getFactionLoc(), 0);
+	} 

Same thing for onPlayerEnter() and getFactionLocation() (here again you can avoid 2 methods to get the faction's location by making a getFaction() method that can be used in many instances) method.

 

 

On L2FactionInstance, after calling player.setFactionId(), you should store the player in database because in some cases (critical error, dc) the faction he chose isn't going to be saved and he will have to choose again. Use player.store().

 

I know i'll change it in V3.0 but im used in Java 7 since i work as i mentionted in old freya revision since 2010

 

make with config for 3.0 update :)

 

Configurations such as? Cause the configs are pretty much those in navicat. Color, name, location e.t.c the only config ill add will be for reward

Posted (edited)

Is this code tested?

Loading Factions from db it will load just the first result from ResultSet.

 

Change if(rs.next()) to while(rs.next())

Edited by `Son
Posted

I know i'll change it in V3.0 but im used in Java 7 since i work as i mentionted in old freya revision since 2010

 

It's not just about the Java 8 I mentioned, you can improve your code in numerous ways, not only those I mentioned.

 

Gl.

Posted (edited)

Is this code tested?

Loading Factions from db it will load just the first result from ResultSet.

 

Change if(rs.next()) to while(rs.next())

 

You just proved that you skipped the 3 lines i wrote. I said the code is not tested so please write me problems e.t.c to update it..

Also yes i saw that it load only 1 faction cause i added if instead of while. ill update it tomorrow along with reward.

 

It's not just about the Java 8 I mentioned, you can improve your code in numerous ways, not only those I mentioned.

 

Gl.

 

I know i could even make it Runnable and no make new class but the lamba expression is exclusively in j8 which i dont use. Habbit

But ill change it tomorrow along with 1-2 mistakes i did

Edited by AccessDenied
Guest
This topic is now closed to further replies.



  • Posts

    • Luniage - a custom Interlude client on Unity, with its own server Hi everyone. I've been quietly working on this for a long time and I think it's finally at the point where it's worth showing. Short version: it's Interlude, but the client and the server are both mine. The client is a custom one, built in Unity — not a patched or reskinned original. The server is written from scratch in C#. The only thing that comes from the old game is the content: the world, the models, the animations, the sounds, the icons, the interface art. The game looks and feels like the game you know. Everything underneath it is new. Why do this at all   Because the old client is a 2004 executable and anyone who has ever tried to add something to it knows exactly how that conversation ends. You can't add a window. You can't change how a skill looks. You can't fix a bug that's staring you in the face. Every server that wanted a feature of its own had to fake it through HTML dialogs and system messages, because the client simply won't bend. At some point it stops being worth fighting. I'd rather keep the game and rebuild everything around it. Where it is right now   You can sit down and play it. Not a tech demo, not a walk-around-and-look-at-the-trees build - an actual character. Most of the game is in: movement, combat, the skill system with its real formulas and timings, items and equipment, enchanting, shops and player trade, quests, parties, clans, and the whole interface that ties it together. Progression works from level 1 all the way through A grade - you can level, gear up, join a clan and run content today. What's missing isn't the foundation. It's the top end - and that's exactly where the work is pointed next.   Videos     What I'm working on now   Castle sieges and the Olympiad. The two biggest systems the game has, the ones that turn a working world into a server people actually stay on. And visual effects. They already run, but "runs" and "looks the way you remember it" are two very different things, and closing that gap turned out to be a much longer road than I expected. I'm going through them one by one. Does it run outside Windows   Yes. It's a Unity project, so Windows, Mac and Linux are just build targets. I actually develop on a Mac, which has kept the whole thing honest about staying portable. Will it work with my existing server   No, and it never will. The client talks to my server and nothing else - that's the trade I made, and it's the reason everything above is possible in the first place. If you're looking for a drop-in replacement client for a setup you already have, this isn't it. What's the goal   First and foremost, to launch my own project on it. That's what the client and the server are being built for, and that's what sets the priorities. Longer term, I'd like to open-source it. This community has spent twenty years working around a client nobody can touch, and I think the honest ending to this story is handing over something people can actually build on. I'm not putting a date on that - first it has to be good enough to be worth someone else's time. Can I try it   Not yet. When there's a build worth handing out, it gets posted here first. In the meantime I'll be posting progress regularly, and I read every reply. If you've run a server, built a client, or just spent a decade staring at this game and know exactly which detail everyone gets wrong — please say so. A good share of what's right in this project is right because somebody pointed at a screenshot and said "that's not how it looked." Thanks for reading.  
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..