@Override public void attackTarget(Creature target) { Npc npc = getOwner(); /** Check all prerequisites */ if (npc == null || npc.getLifeStats().isAlreadyDead() || !npc.isSpawned()) return; if (!npc.canAttack()) return; AI<?> ai = npc.getAi(); NpcGameStats gameStats = npc.getGameStats(); if (target == null || target.getLifeStats().isAlreadyDead()) { ai.handleEvent(Event.MOST_HATED_CHANGED); return; } /** notify attack observers */ super.attackTarget(target); /** Calculate and apply damage */ List<AttackResult> attackList = AttackUtil.calculateAttackResult(npc, target); int damage = 0; for (AttackResult result : attackList) { damage += result.getDamage(); } int attackType = 0; // TODO investigate attack types (0 or 1) PacketSendUtility.broadcastPacket( npc, new SM_ATTACK(npc, target, gameStats.getAttackCounter(), 274, attackType, attackList)); target.getController().onAttack(npc, damage, true); gameStats.increaseAttackCounter(); }
/** {@inheritDoc} */ @Override protected void writeImpl(AionConnection con, ByteBuffer buf) { writeF(buf, npc.getX()); // x writeF(buf, npc.getY()); // y writeF(buf, npc.getZ()); // z writeD(buf, npc.getObjectId()); writeD(buf, npcId); writeD(buf, npcId); writeC(buf, npcTypeId); writeH( buf, npc .getState()); // unk 65=normal,0x47 (71)= [dead npc ?]no drop,0x21(33)=fight // state,0x07=[dead monster?] // no drop // 3,19 - wings spread (NPCs) // 5,6,11,21 - sitting (NPC) // 7,23 - dead (no drop) // 8,24 - [dead][NPC only] - looks like some orb of light (no normal mesh) // 32,33 - fight mode writeC(buf, npc.getHeading()); writeD(buf, npcTemplate.getNameId()); writeD(buf, npcTemplate.getTitleId()); // titleID writeH(buf, 0x00); // unk writeC(buf, 0x00); // unk writeD(buf, 0x00); // unk /* * Master Info (Summon, Kisk, Etc) */ writeD(buf, masterObjId); // masterObjectId writeS(buf, masterName); // masterName int maxHp = npc.getLifeStats().getMaxHp(); int currHp = npc.getLifeStats().getCurrentHp(); writeC(buf, 100 * currHp / maxHp); // %hp writeD(buf, npc.getGameStats().getCurrentStat(StatEnum.MAXHP)); writeC(buf, npc.getLevel()); // lvl NpcEquippedGear gear = npcTemplate.getEquipment(); if (gear == null) writeH(buf, 0x00); else { writeH(buf, gear.getItemsMask()); for (Entry<ItemSlot, ItemTemplate> item : gear) // getting it from template ( later if we make sure that npcs actually use items, // we'll make Item from it ) { writeD(buf, item.getValue().getTemplateId()); writeD(buf, 0x00); writeD(buf, 0x00); writeH(buf, 0x00); } } writeF(buf, 1.5f); // unk writeF(buf, npcTemplate.getHeight()); writeF(buf, npc.getMoveController().getSpeed()); // speed writeH(buf, 2000); // 0x834 (depends on speed ? ) writeH(buf, 2000); // 0x834 if (npc instanceof Servant) writeC(buf, 0x01); // unk else writeC(buf, 0x00); /** Movement */ writeF(buf, npc.getX()); // x writeF(buf, npc.getY()); // y writeF(buf, npc.getZ()); // z writeC(buf, 0x00); // move type SpawnTemplate spawn = npc.getSpawn(); if (spawn == null) { writeH(buf, 0); } else { int mask = (Math.round(spawn.getStaticid() / 0xFF) < 0 ? 0 : Math.round(spawn.getStaticid() / 0xFF)); byte[] statics = new byte[] {(byte) spawn.getStaticid(), (byte) mask}; writeB(buf, statics); } writeC(buf, 0); writeC(buf, 0); // all unknown writeC(buf, 0); writeC(buf, 0); writeC(buf, 0); writeC(buf, 0); writeC(buf, 0); writeC(buf, 0); writeC(buf, npc.getVisualState()); // visualState /** 1 : normal (kisk too) 2 : summon 32 : trap 1024 : holy servant, noble energy */ writeH(buf, npc.getNpcObjectType().getId()); writeC(buf, 0x00); // unk if (npc instanceof Artifact) { writeD(buf, 0); } else { writeD(buf, npc.getTarget() == null ? 0 : npc.getTarget().getObjectId()); } }