Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EnterWolrd.java
- if(!activeChar.isEvil() && !activeChar.isGood())
- {
- activeChar.startParalyze();
- activeChar.setIsParalyzed(true);
- activeChar.ShowDestination();
- }
- //
- Faction.java class
- /*
- * 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 net.sf.l2j.gameserver.model.entity.events;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.List;
- import javolution.util.FastList;
- import net.sf.l2j.gameserver.model.L2Object;
- import net.sf.l2j.gameserver.model.L2World;
- import net.sf.l2j.gameserver.model.actor.L2Character;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
- /**
- * @author Mr.Anonymous
- */
- public class Faction
- {
- private static final FastList<L2PcInstance> players = new FastList<L2PcInstance>();
- private final List<Integer> _pointsE = new ArrayList<Integer>();
- private final List<Integer> _pointsG = new ArrayList<Integer>();
- public static boolean isTeam = false;
- final int[] points = {0};
- private static int yes =0;
- private static int no =0;
- public void setTeamsColors(L2PcInstance a)
- {
- final String Evil = "0033CC";
- final String Good = "FF6600";
- final String Normal = "FFFFFFFF";
- if(a.isEvil())
- a.getAppearance().setNameColor(Integer.decode("0x"+Evil));
- else if(a.isGood())
- a.getAppearance().setNameColor(Integer.decode("0x"+Good));
- else
- a.getAppearance().setNameColor(Integer.decode("0x"+Normal));
- a.broadcastUserInfo();
- }
- public final boolean checkHit(L2Character attacker, L2Character target)
- {
- if (target == null)
- return false;
- final L2PcInstance aPlayer = attacker.getActingPlayer();
- final L2PcInstance tPlayer = target.getActingPlayer();
- if (aPlayer != null && tPlayer != null && aPlayer.isEvil() && tPlayer.isEvil() || aPlayer.isGood() && tPlayer.isGood())
- {
- isTeam = true;
- aPlayer.sendPacket(ActionFailed.STATIC_PACKET);
- aPlayer.sendMessage("You can't attack your team!");
- return false;
- }
- return true;
- }
- public static boolean checkActions(L2Character attacker, L2Character target)
- {
- if (target == null)
- return false;
- final L2PcInstance aPlayer = attacker.getActingPlayer();
- final L2PcInstance tPlayer = target.getActingPlayer();
- if (aPlayer != null && tPlayer != null && aPlayer.isEvil() && tPlayer.isEvil() || aPlayer.isGood() && tPlayer.isGood())
- {
- isTeam = true;
- aPlayer.sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- return true;
- }
- public static boolean checkActions(L2Object t,L2Character p)
- {
- L2Character target = (L2Character) t;
- if(target instanceof L2PcInstance && p.isEvil() && target.isEvil() || p.isGood() && target.isGood())
- {
- isTeam = true;
- p.sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- return true;
- }
- public void checkPointsAndReward()
- {
- final int evilpoints = getEvilPoints();
- final int goodpoints = getEvilPoints();
- final Collection<L2PcInstance> allevils = L2World.getInstance().getAllEvils().values();
- final Collection<L2PcInstance> allgoods = L2World.getInstance().getAllGoods().values();
- if(evilpoints > goodpoints)
- {
- for(L2PcInstance evils: allevils)
- {
- if(evils != null)
- evils.addItem("Reward", 57, 4, evils, false);
- evils.sendMessage("You have rewarded with 4 adena");
- }
- }
- else if(evilpoints < goodpoints)
- {
- for(L2PcInstance goods: allgoods)
- {
- if(goods != null)
- goods.addItem("Reward", 57, 4, goods, false);
- goods.sendMessage("You have rewarded with 4 adena");
- }
- }
- }
- public void AddPointToEvils()
- {
- for (int i = 0; i < points.length; i++)
- {
- if(!isTeam)
- _pointsE.add(points[i]);
- }
- }
- public void AddPointToGoods()
- {
- for (int i = 0; i < points.length; i++)
- {
- if(!isTeam)
- _pointsG.add(points[i]);
- }
- }
- public int getEvilPoints()
- {
- return _pointsE.size();
- }
- public int getGoodPoints()
- {
- return _pointsG.size();
- }
- public void RemovePointFromEvils()
- {
- _pointsE.remove(String.valueOf(points[1]));
- }
- public void RemovePointFromGoods()
- {
- _pointsG.remove(String.valueOf(points[1]));
- }
- public void clearEvilPoints()
- {
- _pointsE.clear();
- }
- public void clearGoodPoints()
- {
- _pointsG.clear();
- }
- public void clearBothTeamsPoints()
- {
- _pointsE.clear();
- _pointsG.clear();
- }
- public void TeleAllEvils(final int x,final int y,final int z)
- {
- for(L2PcInstance ph: players)
- if(ph.isEvil())
- ph.teleToLocation(x, y, z);
- }
- public void TeleAllGoods(final int x,final int y,final int z)
- {
- for(L2PcInstance ph: players)
- if(ph.isGood())
- ph.teleToLocation(x, y, z);
- }
- public void setHeroAllEvils()
- {
- for(L2PcInstance ph: players)
- {
- if(ph.isEvil())
- ph.setHero(true);
- ph.broadcastUserInfo();
- }
- }
- public void setHeroAllGoods()
- {
- for(L2PcInstance ph: players)
- {
- if(ph.isGood())
- ph.setHero(true);
- ph.broadcastUserInfo();
- }
- }
- public void removeHeroFromAllEvils()
- {
- for(L2PcInstance ph: players)
- {
- if(ph.isEvil() && ph.isHero())
- ph.setHero(false);
- ph.broadcastUserInfo();
- }
- }
- public void removeHeroFromAllGoods()
- {
- for(L2PcInstance ph: players)
- {
- if(ph.isGood() && ph.isHero())
- ph.setHero(false);
- ph.broadcastUserInfo();
- }
- }
- public static void Vote(int yess,int noo)
- {
- yes = yes + yess;
- no = no + noo;
- }
- public static int getVotes()
- {
- if(yes > 0 && yes > no)
- return yes;
- return no;
- }
- }
- L2Character.java
- boolean _isEvil = false;
- boolean _isGood = false;
- public boolean isEvil()
- {
- return _isEvil;
- }
- public boolean isGood()
- {
- return _isGood;
- }
- public void setIsEvil(boolean j)
- {
- _isEvil = j;
- }
- public void setIsGood(boolean j)
- {
- _isGood = j;
- }
- L2PcInstance.java
- boolean _isEvil = false;
- boolean _isGood = false;
- @Override
- public boolean isEvil()
- {
- return _isEvil;
- }
- @Override
- public boolean isGood()
- {
- return _isGood;
- }
- @Override
- public void setIsEvil(boolean j)
- {
- _isEvil = j;
- }
- @Override
- public void setIsGood(boolean j)
- {
- _isGood = j;
- }
- public void ShowDestination()
- {
- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- TextBuilder sb = new TextBuilder();
- sb.append("<html><title>Good Vs Evils</title><body>");
- sb.append("<center>");
- sb.append("<img src=\"l2ui_ch3.herotower_deco\" width=256 height=32><br>");
- sb.append("<br>");
- sb.append("Welcome " + getName() + "<br>");
- sb.append("<font color=\"999999\">Choose your destination </font><br>");
- sb.append("<font color=\"999999\">by pressing</font><br>");
- sb.append("<font color=\"999999\">.evil or .good and then you will be unparalysed</font><br>");
- sb.append("<br>");
- sb.append("<img src=\"l2ui_ch3.herotower_deco\" width=256 height=32><br>");
- sb.append("</center>");
- sb.append("</body></html>");
- html.setHtml(sb.toString());
- sendPacket(html);
- return;
- }
- public void AddTheEvil()
- {
- Connection connection = null;
- if(this.isGood())
- return;
- try
- {
- connection = L2DatabaseFactory.getInstance().getConnection();
- final PreparedStatement statement = connection.prepareStatement("UPDATE characters SET evil=1 WHERE obj_id=?");
- statement.setInt(1, this.getObjectId());
- statement.execute();
- statement.close();
- this.setIsEvil(true);
- final long getExp = this.getStat().getExp();
- this.getStat().addExp(getExp + 6299994999L);
- this.stopParalyze(true);
- this.setIsParalyzed(false);
- this.updateNameTitleColor();
- this.sendPacket(new StatusUpdate(this));
- this.broadcastUserInfo();
- this.teleToLocation(getRandomSpawn()[0], getRandomSpawn()[1], getRandomSpawn()[2]);
- this.sendMessage("You are fighting with evils,you can't chance faction now this will be your final destination!");
- }
- catch (Exception e)
- {
- if(Config.DEBUG)
- e.printStackTrace();
- _log.log(Level.WARNING,"could not set evil stats to char:", e);
- }
- finally
- {
- L2DatabaseFactory.close(connection);
- }
- }
- public void AddTheGood()
- {
- Connection connection = null;
- if(this.isEvil())
- return;
- try
- {
- connection = L2DatabaseFactory.getInstance().getConnection();
- final PreparedStatement statement = connection.prepareStatement("UPDATE characters SET good=1 WHERE obj_id=?");
- statement.setInt(1, this.getObjectId());
- statement.execute();
- statement.close();
- this.setIsGood(true);
- final long getExp = this.getStat().getExp();
- this.getStat().addExp(getExp + 6299994999L);
- this.stopParalyze(true);
- this.setIsParalyzed(false);
- this.updateNameTitleColor();
- this.sendPacket(new UserInfo(this));
- this.sendPacket(new StatusUpdate(this));
- this.broadcastUserInfo();
- this.teleToLocation(getRandomSpawn()[0], getRandomSpawn()[1], getRandomSpawn()[2]);
- this.sendMessage("You are fighting with goods,you can't chance faction now this will be your final destination!");
- }
- catch (Exception e)
- {
- if(Config.DEBUG)
- e.printStackTrace();
- _log.log(Level.WARNING,"could not set good stats to char:", e);
- }
- finally
- {
- L2DatabaseFactory.close(connection);
- }
- }
- private final int[][] RandomSpawnE =
- {
- {-44678, -112589, -240},
- {-44538, -112587, -240},
- {-44632, -112630, -240},
- {-44674, -112559, -240},
- {-44548, -112567, -240},
- {-44632, -112630, -240},
- };
- private final int[][] RandomSpawnG =
- {
- {111930, 220021, -3671},
- {111898, 219969, -3671},
- {111582, 219961, -3677},
- {111936, 220052, -3671},
- {111896, 219968, -3671},
- {111584, 219966, -3677},
- };
- public final int[] getRandomSpawn()
- {
- final int[] getPosE = RandomSpawnE[Rnd.get(RandomSpawnE.length)];
- final int[] getPosG = RandomSpawnG[Rnd.get(RandomSpawnG.length)];
- if(this.isEvil())
- return getPosE;
- else if(this.isGood())
- return getPosG;
- else
- return null;
- }
- Faction.java (Voiced commands)
- /*
- * 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 net.sf.l2j.gameserver.handler.voicedcommandhandlers;
- import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- public class Faction implements IVoicedCommandHandler
- {
- private static String[] _voicedCommands =
- {
- "evil",
- "good"
- };
- @Override
- public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
- {
- if(command.equalsIgnoreCase("evil"))
- {
- if(activeChar.isEvil())
- {
- activeChar.sendMessage("You are already evil");
- return false;
- }
- else if(activeChar.isGood())
- {
- activeChar.sendMessage("You can't change team");
- return false;
- }
- activeChar.AddTheEvil();
- }
- else if(command.equalsIgnoreCase("good"))
- {
- if(activeChar.isGood())
- {
- activeChar.sendMessage("You are already good");
- return false;
- }
- else if(activeChar.isEvil())
- {
- activeChar.sendMessage("You can't change team");
- return false;
- }
- activeChar.AddTheGood();
- }
- return true;
- }
- @Override
- public String[] getVoicedCommandList()
- {
- return _voicedCommands;
- }
- }
- CharacterCreat.java (now the random spawns when we create a character)
- private static final int[][] RandomSpawn =
- {
- {44521, 108628, -2038},
- {44512, 108671, -2038},
- {44538, 108589, -2038},
- {44464, 108608, -2038},
- {44609, 108632, -2038},
- {44585, 108636, -2038}
- };
- public static int[] getRandom()
- {
- return RandomSpawn[Rnd.get(RandomSpawn.length)];
- }
- find this: private void initNewChar(L2GameClient client, L2PcInstance newChar)
- and add
- final int X = getRandom()[0];
- final int Y = getRandom()[1];
- final int Z = getRandom()[2];
- newChar.setXYZInvisible(X,Y,Z);
- and now the sql:
- go to characters.sql
- and add `evil` decimal(1,0) NOT NULL DEFAULT 0,
- `good` decimal(1,0) NOT NULL DEFAULT 0,
- now the L2PcInstance.java sqls
- // Character SQL String Definitions:
- private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,obj_Id,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,karma,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,accesslevel,online,isin7sdungeon,clan_privs,wantspeace,base_class,nobless,power_grade,last_recom_date,evil,good) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=?,evil=?,good=? WHERE obj_id=?";
- private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level,evil,good FROM characters WHERE obj_id=?";
- private boolean createDb()
- +statement.setInt(35, isEvil() ? 1 :0);
- +statement.setInt(36, isGood() ? 1 :0);
- voide StoreCharBase
- +statement.setInt(50, isEvil() ? 1 :0);
- +statement.setInt(51, isGood() ? 1 :0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement