diff --git a/l2-unity/Assets/Scripts/Game/Character/CharacterBuilder.cs b/l2-unity/Assets/Scripts/Game/Character/CharacterBuilder.cs index 4b62509c6..498424512 100644 --- a/l2-unity/Assets/Scripts/Game/Character/CharacterBuilder.cs +++ b/l2-unity/Assets/Scripts/Game/Character/CharacterBuilder.cs @@ -18,7 +18,7 @@ void Awake() { // Load player animations, face and hair public GameObject BuildCharacterBase(CharacterRaceAnimation raceId, PlayerAppearance appearance, EntityType entityType) { - Debug.Log($"Building character: Race:{raceId} Sex:{appearance.Sex} Face:{appearance.Face} Hair:{appearance.HairStyle} HairC:{appearance.HairColor}"); + //Debug.Log($"Building character: Race:{raceId} Sex:{appearance.Sex} Face:{appearance.Face} Hair:{appearance.HairStyle} HairC:{appearance.HairColor}"); GameObject entity = Instantiate(ModelTable.Instance.GetContainer(raceId, entityType)); GameObject face = Instantiate(ModelTable.Instance.GetFace(raceId, appearance.Face)); diff --git a/l2-unity/Assets/Scripts/Game/Entity/Entity.cs b/l2-unity/Assets/Scripts/Game/Entity/Entity.cs index 0975b37f0..85fcdfb8c 100644 --- a/l2-unity/Assets/Scripts/Game/Entity/Entity.cs +++ b/l2-unity/Assets/Scripts/Game/Entity/Entity.cs @@ -62,13 +62,13 @@ public virtual void Initialize() { } // Called when ApplyDamage packet is received - public void ApplyDamage(int damage, int newHp, bool criticalHit) { + public void ApplyDamage(int damage, bool criticalHit) { if(_status.Hp <= 0) { Debug.LogWarning("Trying to apply damage to a dead entity"); return; } - _status.Hp = Mathf.Max(newHp, 0); + _status.Hp = Mathf.Max(_status.Hp - damage, 0); OnHit(criticalHit); diff --git a/l2-unity/Assets/Scripts/Game/Manager/World.cs b/l2-unity/Assets/Scripts/Game/Manager/World.cs index 766fe601a..364a59dfa 100644 --- a/l2-unity/Assets/Scripts/Game/Manager/World.cs +++ b/l2-unity/Assets/Scripts/Game/Manager/World.cs @@ -218,6 +218,8 @@ public void SpawnNpc(NetworkIdentity identity, NpcStatus status, Stats stats) { npc.Status = status; + npc.Stats = stats; + npc.Identity = identity; npc.Identity.NpcClass = npcgrp.ClassName; npc.Identity.Name = npcName.Name; @@ -229,7 +231,6 @@ public void SpawnNpc(NetworkIdentity identity, NpcStatus status, Stats stats) { } npc.Identity.TitleColor = npcName.TitleColor; - npc.Stats = stats; npc.Appearance = appearance; npcGo.transform.eulerAngles = new Vector3(npcGo.transform.eulerAngles.x, identity.Heading, npcGo.transform.eulerAngles.z); @@ -285,12 +286,12 @@ public Task UpdateObjectAnimation(int id, int animId, float value) { }); } - public Task InflictDamageTo(int sender, int target, int damage, int newHp, bool criticalHit) { + public Task InflictDamageTo(int sender, int target, int damage, bool criticalHit) { return ExecuteWithEntitiesAsync(sender, target, (senderEntity, targetEntity) => { if (senderEntity != null) { - WorldCombat.Instance.InflictAttack(senderEntity.transform, targetEntity.transform, damage, newHp, criticalHit); + WorldCombat.Instance.InflictAttack(senderEntity.transform, targetEntity.transform, damage, criticalHit); } else { - WorldCombat.Instance.InflictAttack(targetEntity.transform, damage, newHp, criticalHit); + WorldCombat.Instance.InflictAttack(targetEntity.transform, damage, criticalHit); } }); } @@ -327,7 +328,9 @@ public Task EntityStopAutoAttacking(int id) { public Task StatusUpdate(int id, List attributes) { return ExecuteWithEntityAsync(id, e => { WorldCombat.Instance.StatusUpdate(e, attributes); - CharacterInfoWindow.Instance.UpdateValues(); + if(e == PlayerEntity.Instance) { + CharacterInfoWindow.Instance.UpdateValues(); + } }); } diff --git a/l2-unity/Assets/Scripts/Game/Manager/WorldCombat.cs b/l2-unity/Assets/Scripts/Game/Manager/WorldCombat.cs index 9db957b07..bf20baf60 100644 --- a/l2-unity/Assets/Scripts/Game/Manager/WorldCombat.cs +++ b/l2-unity/Assets/Scripts/Game/Manager/WorldCombat.cs @@ -22,22 +22,22 @@ void OnDestroy() { } - public void InflictAttack(Transform target, int damage, int newHp, bool criticalHit) { - ApplyDamage(target, damage, newHp, criticalHit); + public void InflictAttack(Transform target, int damage, bool criticalHit) { + ApplyDamage(target, damage, criticalHit); } - public void InflictAttack(Transform attacker, Transform target, int damage, int newHp, bool criticalHit) { - ApplyDamage(target, damage, newHp, criticalHit); + public void InflictAttack(Transform attacker, Transform target, int damage, bool criticalHit) { + ApplyDamage(target, damage, criticalHit); // Instantiate hit particle ParticleImpact(attacker, target); } - private void ApplyDamage(Transform target, int damage, int newHp, bool criticalHit) { + private void ApplyDamage(Transform target, int damage, bool criticalHit) { Entity entity = target.GetComponent(); if (entity != null) { // Apply damage to target - entity.ApplyDamage(damage, newHp, criticalHit); + entity.ApplyDamage(damage, criticalHit); } } @@ -73,6 +73,9 @@ public void StatusUpdate(Entity entity, List attributes) { Stats stats = entity.Stats; foreach (Attribute attribute in attributes) { + if (entity != PlayerEntity.Instance) { + Debug.LogWarning($"{entity.Identity.Name} - {(AttributeType)attribute.id}"); + } switch((AttributeType) attribute.id) { case AttributeType.LEVEL: stats.Level = attribute.value; diff --git a/l2-unity/Assets/Scripts/Networking/ClientLibrary/Model/Hit.cs b/l2-unity/Assets/Scripts/Networking/ClientLibrary/Model/Hit.cs new file mode 100644 index 000000000..a1bd2e897 --- /dev/null +++ b/l2-unity/Assets/Scripts/Networking/ClientLibrary/Model/Hit.cs @@ -0,0 +1,44 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Hit +{ + private static int HITFLAG_USESS = 0x10; + private static int HITFLAG_CRIT = 0x20; + private static int HITFLAG_SHLD = 0x40; + private static int HITFLAG_MISS = 0x80; + + private int _targetId; + private int _damage; + private int _flags = 0; + + public int TargetId { get { return _targetId; } } + public int Damage { get { return _damage; } } + + public Hit(int targetId, int damage, int flags) { + this._targetId = targetId; + this._damage = damage; + this._flags = flags; + } + + public bool isCrit() { + return (_flags & HITFLAG_CRIT) != 0; + } + + public bool isMiss() { + return (_flags & HITFLAG_MISS) != 0; + } + + public bool hasSoulshot() { + return (_flags & HITFLAG_USESS) != 0; + } + + public bool isShielded() { + return (_flags & HITFLAG_SHLD) != 0; + } + + public int getSsGrade() { + return _flags & 0x0F; + } +} diff --git a/l2-unity/Assets/Scripts/Networking/ClientLibrary/Model/Hit.cs.meta b/l2-unity/Assets/Scripts/Networking/ClientLibrary/Model/Hit.cs.meta new file mode 100644 index 000000000..d243eed34 --- /dev/null +++ b/l2-unity/Assets/Scripts/Networking/ClientLibrary/Model/Hit.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0b19397bfb98a1a47b5d1a339e6e6bf8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/l2-unity/Assets/Scripts/Networking/ClientLibrary/Packet/Gameserver/ServerPackets/InflictDamagePacket.cs b/l2-unity/Assets/Scripts/Networking/ClientLibrary/Packet/Gameserver/ServerPackets/InflictDamagePacket.cs index c99141ad0..e3d355bf4 100644 --- a/l2-unity/Assets/Scripts/Networking/ClientLibrary/Packet/Gameserver/ServerPackets/InflictDamagePacket.cs +++ b/l2-unity/Assets/Scripts/Networking/ClientLibrary/Packet/Gameserver/ServerPackets/InflictDamagePacket.cs @@ -1,11 +1,9 @@ using UnityEngine; using System; public class InflictDamagePacket : ServerPacket { + private Hit[] _hits; public int SenderId { get; private set; } - public int TargetId { get; private set; } - public int Value { get; private set; } - public int NewHp { get; private set; } - public bool CriticalHit { get; private set; } + public Hit[] Hits { get { return _hits; }} public InflictDamagePacket(byte[] d) : base(d) { Parse(); @@ -14,10 +12,19 @@ public InflictDamagePacket(byte[] d) : base(d) { public override void Parse() { try { SenderId = ReadI(); - TargetId = ReadI(); - Value = ReadI(); - NewHp = ReadI(); - CriticalHit = ReadB() == 0 ? false : true; + + byte hitCount = ReadB(); + _hits = new Hit[hitCount]; + + for (int i = 0; i < hitCount; i++) { + int targetId = ReadI(); + int damage = ReadI(); + int hitFlags = ReadI(); + + Hit hit = new Hit(targetId, damage, hitFlags); + _hits[i] = hit; + } + } catch(Exception e) { Debug.LogError(e); } diff --git a/l2-unity/Assets/Scripts/Networking/ClientLibrary/PacketHandler/Gameserver/GameServerPacketHandler.cs b/l2-unity/Assets/Scripts/Networking/ClientLibrary/PacketHandler/Gameserver/GameServerPacketHandler.cs index 6ab5d5863..6c37ae99b 100644 --- a/l2-unity/Assets/Scripts/Networking/ClientLibrary/PacketHandler/Gameserver/GameServerPacketHandler.cs +++ b/l2-unity/Assets/Scripts/Networking/ClientLibrary/PacketHandler/Gameserver/GameServerPacketHandler.cs @@ -229,7 +229,11 @@ private void OnUpdateAnimation(byte[] data) { private void OnInflictDamage(byte[] data) { InflictDamagePacket packet = new InflictDamagePacket(data); - World.Instance.InflictDamageTo(packet.SenderId, packet.TargetId, packet.Value, packet.NewHp, packet.CriticalHit); + Hit[] hits = packet.Hits; + + for (int i = 0; i < hits.Length; i++) { + World.Instance.InflictDamageTo(packet.SenderId, hits[i].TargetId, hits[i].Damage, hits[i].isCrit()); + } } private void OnNpcInfoReceive(byte[] data) { diff --git a/l2-unity/Assets/Scripts/UI/Login/ServerSelectWindow.cs b/l2-unity/Assets/Scripts/UI/Login/ServerSelectWindow.cs index 5b28a6493..965acbf48 100644 --- a/l2-unity/Assets/Scripts/UI/Login/ServerSelectWindow.cs +++ b/l2-unity/Assets/Scripts/UI/Login/ServerSelectWindow.cs @@ -62,6 +62,8 @@ protected override IEnumerator BuildWindow(VisualElement root) { } public void UpdateServerList(int lastServer, List serverData, Dictionary charsOnServers) { + ResetWindow(); + _serverData = serverData; for (int i = 0; i < serverData.Count; i++) {