Guest User

Untitled

a guest
Jan 26th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.47 KB | None | 0 0
  1. /*
  2.  * This program is free software: you can redistribute it and/or modify it under
  3.  * the terms of the GNU General Public License as published by the Free Software
  4.  * Foundation, either version 3 of the License, or (at your option) any later
  5.  * version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful, but WITHOUT
  8.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10.  * details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License along with
  13.  * this program. If not, see <http://www.gnu.org/licenses/>.
  14.  */
  15. package net.sf.l2j.gameserver.network.clientpackets;
  16.  
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.datatables.CharNameTable;
  19. import net.sf.l2j.gameserver.datatables.CharTemplateTable;
  20. import net.sf.l2j.gameserver.datatables.SkillTable;
  21. import net.sf.l2j.gameserver.datatables.SkillTreeTable;
  22. import net.sf.l2j.gameserver.idfactory.IdFactory;
  23. import net.sf.l2j.gameserver.instancemanager.QuestManager;
  24. import net.sf.l2j.gameserver.model.L2ItemInstance;
  25. import net.sf.l2j.gameserver.model.L2ShortCut;
  26. import net.sf.l2j.gameserver.model.L2SkillLearn;
  27. import net.sf.l2j.gameserver.model.L2World;
  28. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  29. import net.sf.l2j.gameserver.model.quest.Quest;
  30. import net.sf.l2j.gameserver.network.serverpackets.CharCreateFail;
  31. import net.sf.l2j.gameserver.network.serverpackets.CharCreateOk;
  32. import net.sf.l2j.gameserver.network.serverpackets.CharSelectInfo;
  33. import net.sf.l2j.gameserver.templates.chars.L2PcTemplate;
  34. import net.sf.l2j.gameserver.templates.item.L2Item;
  35. import net.sf.l2j.gameserver.util.Util;
  36.  
  37. @SuppressWarnings("unused")
  38. public final class CharacterCreate extends L2GameClientPacket
  39. {
  40.     // cSdddddddddddd
  41.     private String _name;
  42.     private int _race;
  43.     private byte _sex;
  44.     private int _classId;
  45.     private int _int;
  46.     private int _str;
  47.     private int _con;
  48.     private int _men;
  49.     private int _dex;
  50.     private int _wit;
  51.     private byte _hairStyle;
  52.     private byte _hairColor;
  53.     private byte _face;
  54.    
  55.     @Override
  56.     protected void readImpl()
  57.     {
  58.         _name = readS();
  59.         _race = readD();
  60.         _sex = (byte) readD();
  61.         _classId = readD();
  62.         _int = readD();
  63.         _str = readD();
  64.         _con = readD();
  65.         _men = readD();
  66.         _dex = readD();
  67.         _wit = readD();
  68.         _hairStyle = (byte) readD();
  69.         _hairColor = (byte) readD();
  70.         _face = (byte) readD();
  71.     }
  72.    
  73.     @Override
  74.     protected void runImpl()
  75.     {
  76.         if (_name.length() > 16)
  77.         {
  78.             sendPacket(new CharCreateFail(CharCreateFail.REASON_16_ENG_CHARS));
  79.             return;
  80.         }
  81.        
  82.         if (!Util.isValidPlayerName(_name))
  83.         {
  84.             sendPacket(new CharCreateFail(CharCreateFail.REASON_INCORRECT_NAME));
  85.             return;
  86.         }
  87.        
  88.         if (_face > 2 || _face < 0)
  89.         {
  90.             sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
  91.             return;
  92.         }
  93.        
  94.         if (_hairStyle < 0 || (_sex == 0 && _hairStyle > 4) || (_sex != 0 && _hairStyle > 6))
  95.         {
  96.             sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
  97.             return;
  98.         }
  99.        
  100.         if (_hairColor > 3 || _hairColor < 0)
  101.         {
  102.             sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
  103.             return;
  104.         }
  105.        
  106.         L2PcInstance newChar = null;
  107.         L2PcTemplate template = null;
  108.        
  109.         /*
  110.          * DrHouse: Since checks for duplicate names are done using SQL, lock must be held until data is written to DB as well.
  111.          */
  112.         synchronized (CharNameTable.getInstance())
  113.         {
  114.             if (CharNameTable.accountCharNumber(getClient().getAccountName()) >= 7)
  115.             {
  116.                 sendPacket(new CharCreateFail(CharCreateFail.REASON_TOO_MANY_CHARACTERS));
  117.                 return;
  118.             }
  119.            
  120.             if (CharNameTable.doesCharNameExist(_name))
  121.             {
  122.                 sendPacket(new CharCreateFail(CharCreateFail.REASON_NAME_ALREADY_EXISTS));
  123.                 return;
  124.             }
  125.            
  126.             template = CharTemplateTable.getInstance().getTemplate(_classId);
  127.             if (template == null || template.classBaseLevel > 1)
  128.             {
  129.                 sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
  130.                 return;
  131.             }
  132.            
  133.             int objectId = IdFactory.getInstance().getNextId();
  134.             newChar = L2PcInstance.create(objectId, template, getClient().getAccountName(), _name, _hairStyle, _hairColor, _face, _sex != 0);
  135.         }
  136.  
  137.    
  138.         newChar.setCurrentCp(0);
  139.         newChar.setCurrentHp(newChar.getMaxHp());
  140.         newChar.setCurrentMp(newChar.getMaxMp());
  141.        
  142.         // send acknowledgement
  143.         sendPacket(CharCreateOk.STATIC_PACKET);
  144.        
  145.         L2World.getInstance().storeObject(newChar);
  146.        
  147.         newChar.addAdena("Init", Config.STARTING_ADENA, null, false);
  148.        
  149.         if(Config.SPAWN_POINT)
  150.         newChar.setXYZInvisible(Config.SPAWN_X, Config.SPAWN_Y,Config.SPAWN_Z);
  151.             else
  152.         newChar.setXYZInvisible(template.spawnX, template.spawnY, template.spawnZ);
  153.        
  154.         newChar.setTitle("");
  155.        
  156.         newChar.registerShortCut(new L2ShortCut(0, 0, 3, 2, -1, 1)); // attack shortcut
  157.         newChar.registerShortCut(new L2ShortCut(3, 0, 3, 5, -1, 1)); // take shortcut
  158.         newChar.registerShortCut(new L2ShortCut(10, 0, 3, 0, -1, 1)); // sit shortcut
  159.        
  160.         for (L2Item ia : template.getItems())
  161.         {
  162.             L2ItemInstance item = newChar.getInventory().addItem("Init", ia.getItemId(), 1, newChar, null);
  163.             if (item.getItemId() == 5588) // tutorial book shortcut
  164.                 newChar.registerShortCut(new L2ShortCut(11, 0, 1, item.getObjectId(), -1, 1));
  165.            
  166.             if (item.isEquipable())
  167.             {
  168.                 if (newChar.getActiveWeaponItem() == null || !(item.getItem().getType2() != L2Item.TYPE2_WEAPON))
  169.                     newChar.getInventory().equipItemAndRecord(item);
  170.             }
  171.         }
  172.        
  173.         for (L2SkillLearn skill : SkillTreeTable.getInstance().getAvailableSkills(newChar, newChar.getClassId()))
  174.         {
  175.             newChar.addSkill(SkillTable.getInstance().getInfo(skill.getId(), skill.getLevel()), true);
  176.             if (skill.getId() == 1001 || skill.getId() == 1177)
  177.                 newChar.registerShortCut(new L2ShortCut(1, 0, 2, skill.getId(), 1, 1));
  178.            
  179.             if (skill.getId() == 1216)
  180.                 newChar.registerShortCut(new L2ShortCut(9, 0, 2, skill.getId(), 1, 1));
  181.         }
  182.        
  183.         if (!Config.DISABLE_TUTORIAL)
  184.         {
  185.             if (newChar.getQuestState("Tutorial") == null)
  186.             {
  187.                 Quest q = QuestManager.getInstance().getQuest("Tutorial");
  188.                 if (q != null)
  189.                     q.newQuestState(newChar).setState(Quest.STATE_STARTED);
  190.             }
  191.         }
  192.        
  193.        
  194.         newChar.setOnlineStatus(true, false);
  195.         newChar.deleteMe();
  196.        
  197.         final CharSelectInfo cl = new CharSelectInfo(getClient().getAccountName(), getClient().getSessionId().playOkID1);
  198.         getClient().getConnection().sendPacket(cl);
  199.         getClient().setCharSelection(cl.getCharInfo());
  200.     }
  201.    
  202.  
  203.        
  204.     }
Advertisement
Add Comment
Please, Sign In to add comment