PetInfo.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.serverpackets;
  20. import com.l2jserver.gameserver.model.actor.L2Summon;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  22. import com.l2jserver.gameserver.model.actor.instance.L2ServitorInstance;
  23. import com.l2jserver.gameserver.model.zone.ZoneId;
  24. public class PetInfo extends L2GameServerPacket
  25. {
  26. private final L2Summon _summon;
  27. private final int _x, _y, _z, _heading;
  28. private final boolean _isSummoned;
  29. private final int _val;
  30. private final int _mAtkSpd, _pAtkSpd;
  31. private final int _runSpd, _walkSpd;
  32. private final int _swimRunSpd, _swimWalkSpd;
  33. private final int _flyRunSpd, _flyWalkSpd;
  34. private final double _moveMultiplier;
  35. private final int _maxHp, _maxMp;
  36. private int _maxFed, _curFed;
  37. public PetInfo(L2Summon summon, int val)
  38. {
  39. _summon = summon;
  40. _isSummoned = summon.isShowSummonAnimation();
  41. _x = summon.getX();
  42. _y = summon.getY();
  43. _z = summon.getZ();
  44. _heading = summon.getHeading();
  45. _mAtkSpd = summon.getMAtkSpd();
  46. _pAtkSpd = summon.getPAtkSpd();
  47. _moveMultiplier = summon.getMovementSpeedMultiplier();
  48. _runSpd = (int) Math.round(summon.getRunSpeed() / _moveMultiplier);
  49. _walkSpd = (int) Math.round(summon.getWalkSpeed() / _moveMultiplier);
  50. _swimRunSpd = (int) Math.round(summon.getSwimRunSpeed() / _moveMultiplier);
  51. _swimWalkSpd = (int) Math.round(summon.getSwimWalkSpeed() / _moveMultiplier);
  52. _flyRunSpd = summon.isFlying() ? _runSpd : 0;
  53. _flyWalkSpd = summon.isFlying() ? _walkSpd : 0;
  54. _maxHp = summon.getMaxHp();
  55. _maxMp = summon.getMaxMp();
  56. _val = val;
  57. if (summon.isPet())
  58. {
  59. final L2PetInstance pet = (L2PetInstance) _summon;
  60. _curFed = pet.getCurrentFed(); // how fed it is
  61. _maxFed = pet.getMaxFed(); // max fed it can be
  62. }
  63. else if (summon.isServitor())
  64. {
  65. final L2ServitorInstance sum = (L2ServitorInstance) _summon;
  66. _curFed = sum.getLifeTimeRemaining();
  67. _maxFed = sum.getLifeTime();
  68. }
  69. }
  70. @Override
  71. protected final void writeImpl()
  72. {
  73. writeC(0xb2);
  74. writeD(_summon.getSummonType());
  75. writeD(_summon.getObjectId());
  76. writeD(_summon.getTemplate().getDisplayId() + 1000000);
  77. writeD(0); // 1=attackable
  78. writeD(_x);
  79. writeD(_y);
  80. writeD(_z);
  81. writeD(_heading);
  82. writeD(0);
  83. writeD(_mAtkSpd);
  84. writeD(_pAtkSpd);
  85. writeD(_runSpd);
  86. writeD(_walkSpd);
  87. writeD(_swimRunSpd);
  88. writeD(_swimWalkSpd);
  89. writeD(_flyRunSpd);
  90. writeD(_flyWalkSpd);
  91. writeD(_flyRunSpd);
  92. writeD(_flyWalkSpd);
  93. writeF(_moveMultiplier);
  94. writeF(_summon.getAttackSpeedMultiplier()); // attack speed multiplier
  95. writeF(_summon.getTemplate().getfCollisionRadius());
  96. writeF(_summon.getTemplate().getfCollisionHeight());
  97. writeD(_summon.getWeapon()); // right hand weapon
  98. writeD(_summon.getArmor()); // body armor
  99. writeD(0x00); // left hand weapon
  100. writeC(_summon.getOwner() != null ? 1 : 0); // when pet is dead and player exit game, pet doesn't show master name
  101. writeC(_summon.isRunning() ? 1 : 0); // running=1 (it is always 1, walking mode is calculated from multiplier)
  102. writeC(_summon.isInCombat() ? 1 : 0); // attacking 1=true
  103. writeC(_summon.isAlikeDead() ? 1 : 0); // dead 1=true
  104. writeC(_isSummoned ? 2 : _val); // 0=teleported 1=default 2=summoned
  105. writeD(-1); // High Five NPCString ID
  106. if (_summon.isPet())
  107. {
  108. writeS(_summon.getName()); // Pet name.
  109. }
  110. else
  111. {
  112. writeS(_summon.getTemplate().isUsingServerSideName() ? _summon.getName() : ""); // Summon name.
  113. }
  114. writeD(-1); // High Five NPCString ID
  115. writeS(_summon.getTitle()); // owner name
  116. writeD(1);
  117. writeD(_summon.getPvpFlag()); // 0 = white,2= purpleblink, if its greater then karma = purple
  118. writeD(_summon.getKarma()); // karma
  119. writeD(_curFed); // how fed it is
  120. writeD(_maxFed); // max fed it can be
  121. writeD((int) _summon.getCurrentHp());// current hp
  122. writeD(_maxHp);// max hp
  123. writeD((int) _summon.getCurrentMp());// current mp
  124. writeD(_maxMp);// max mp
  125. writeD(_summon.getStat().getSp()); // sp
  126. writeD(_summon.getLevel());// lvl
  127. writeQ(_summon.getStat().getExp());
  128. if (_summon.getExpForThisLevel() > _summon.getStat().getExp())
  129. {
  130. writeQ(_summon.getStat().getExp());// 0% absolute value
  131. }
  132. else
  133. {
  134. writeQ(_summon.getExpForThisLevel());// 0% absolute value
  135. }
  136. writeQ(_summon.getExpForNextLevel());// 100% absoulte value
  137. writeD(_summon.isPet() ? _summon.getInventory().getTotalWeight() : 0);// weight
  138. writeD(_summon.getMaxLoad());// max weight it can carry
  139. writeD(_summon.getPAtk(null));// patk
  140. writeD(_summon.getPDef(null));// pdef
  141. writeD(_summon.getMAtk(null, null));// matk
  142. writeD(_summon.getMDef(null, null));// mdef
  143. writeD(_summon.getAccuracy());// accuracy
  144. writeD(_summon.getEvasionRate(null));// evasion
  145. writeD(_summon.getCriticalHit(null, null));// critical
  146. writeD((int) _summon.getMoveSpeed());// speed
  147. writeD(_summon.getPAtkSpd());// atkspeed
  148. writeD(_summon.getMAtkSpd());// casting speed
  149. writeD(_summon.getAbnormalVisualEffects());// c2 abnormal visual effect... bleed=1; poison=2; poison & bleed=3; flame=4;
  150. writeH(_summon.isMountable() ? 1 : 0);// c2 ride button
  151. writeC(_summon.isInsideZone(ZoneId.WATER) ? 1 : _summon.isFlying() ? 2 : 0); // c2
  152. // Following all added in C4.
  153. writeH(0); // ??
  154. writeC(_summon.getTeam().getId());
  155. writeD(_summon.getSoulShotsPerHit()); // How many soulshots this servitor uses per hit
  156. writeD(_summon.getSpiritShotsPerHit()); // How many spiritshots this servitor uses per hit
  157. writeD(_summon.getFormId());// CT1.5 Pet form and skills
  158. writeD(_summon.getAbnormalVisualEffectSpecial());
  159. }
  160. }