From 33b096de32c24c8b95b04f3bc76f152fb7ac9be7 Mon Sep 17 00:00:00 2001 From: Lucca Faria Ferri Date: Sun, 22 Jan 2023 09:43:32 -0800 Subject: [PATCH] Added fixed attributes, added Invulnerability command, fixed compilation issue, more translations --- .../CommandManager/GameCommands.cs | 26 +++++++++++++ .../GSSystem/ActorSystem/Actor.cs | 11 +++--- .../GSSystem/ObjectsSystem/FixedMap.cs | 38 +++++++++++++++++++ .../ObjectsSystem/GameAttributeMap.cs | 4 ++ .../PowerSystem/Payloads/DeathPayload.cs | 4 +- 5 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/FixedMap.cs diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/GameCommands.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/GameCommands.cs index 6540f0a..c1237f7 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/GameCommands.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/GameCommands.cs @@ -37,11 +37,37 @@ using System.Linq; using System.Text; //Blizzless Project 2022 using System.Threading.Tasks; +using DiIiS_NA.GameServer.GSSystem.ObjectsSystem; +using DiIiS_NA.LoginServer.AccountsSystem; //Blizzless Project 2022 using static DiIiS_NA.Core.MPQ.FileFormats.GameBalance; namespace DiIiS_NA.GameServer.CommandManager { + [CommandGroup("Invulnerable", "Makes you invulnerable")] + public class InvulnerableCommand : CommandGroup + { + [DefaultCommand] + public string Invulnerable(string[] @params, BattleClient invokerClient) + { + if (invokerClient?.InGameClient?.Player is not { } player) + return "You can not invoke this command from console."; + + if (player.Attributes.FixedMap.Contains(FixedAttribute.Invulnerable)) + { + player.Attributes.FixedMap.Remove(FixedAttribute.Invulnerable); + player.Attributes[GameAttribute.Invulnerable] = false; + player.Attributes.BroadcastChangedIfRevealed(); + return "You are no longer invulnerable."; + } + + player.Attributes.FixedMap.Add(FixedAttribute.Invulnerable, + attributes => { attributes[GameAttribute.Invulnerable] = true; }); + player.Attributes.BroadcastChangedIfRevealed(); + return "You are now invulnerable."; + } + } + [CommandGroup("spawn", "Spawns a mob.\nUsage: spawn [actorSNO] [amount]")] public class SpawnCommand : CommandGroup { diff --git a/src/DiIiS-NA/D3-GameServer/GSSystem/ActorSystem/Actor.cs b/src/DiIiS-NA/D3-GameServer/GSSystem/ActorSystem/Actor.cs index 1525943..5d4ce3d 100644 --- a/src/DiIiS-NA/D3-GameServer/GSSystem/ActorSystem/Actor.cs +++ b/src/DiIiS-NA/D3-GameServer/GSSystem/ActorSystem/Actor.cs @@ -1,4 +1,4 @@ -//Blizzless Project 2022 +//Blizzless Project 2022 using DiIiS_NA.Core.Logging; using DiIiS_NA.D3_GameServer.Core.Types.SNO; //Blizzless Project 2022 @@ -682,18 +682,19 @@ namespace DiIiS_NA.GameServer.GSSystem.ActorSystem UnitAniimStartTime = 0, tAnim = new PlayAnimationMessageSpec[] { - new() + new PlayAnimationMessageSpec { Duration = -2, - AnimationSNO = animationSNO, + AnimationSNO = (int)animationSNO, PermutationIndex = 0x0, AnimationTag = 0, Speed = 1.0f, } } - }, this); + }, + this); + } } - } public void PlayAnimation(int animationType, int animationSNO, float speed = 1.0f, int? ticksToPlay = null, int type2 = 0) { diff --git a/src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/FixedMap.cs b/src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/FixedMap.cs new file mode 100644 index 0000000..2021852 --- /dev/null +++ b/src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/FixedMap.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using DiIiS_NA.Core.Logging; + +namespace DiIiS_NA.GameServer.GSSystem.ObjectsSystem +{ + public enum FixedAttribute + { + Invulnerable, + Speed + } + + public class FixedMap + { + private static readonly Logger _logger = LogManager.CreateLogger(nameof(FixedMap)); + private readonly Dictionary> _attributeMap = new(); + + public void Add(FixedAttribute name, Action action) + { + if (Contains(name)) + { + _attributeMap[name] += action; + _logger.Warn($"Fixed attribute {name} already exists. Action will be added."); + return; + } + _attributeMap.Add(name, action); + } + + public void Remove(FixedAttribute name) => _attributeMap.Remove(name); + public void Clear() => _attributeMap.Clear(); + public bool Contains(FixedAttribute name) => _attributeMap.ContainsKey(name); + public void Apply(GameAttributeMap map) + { + foreach (var action in _attributeMap.Values) + action(map); + } + } +} \ No newline at end of file diff --git a/src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/GameAttributeMap.cs b/src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/GameAttributeMap.cs index cc65f60..a1d3f82 100644 --- a/src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/GameAttributeMap.cs +++ b/src/DiIiS-NA/D3-GameServer/GSSystem/ObjectsSystem/GameAttributeMap.cs @@ -29,9 +29,11 @@ using System.Threading.Tasks; namespace DiIiS_NA.GameServer.GSSystem.ObjectsSystem { + public class GameAttributeMap { private static Logger Logger = LogManager.CreateLogger(); + public FixedMap FixedMap { get; } = new(); public struct KeyId { @@ -233,6 +235,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ObjectsSystem /// public void BroadcastIfRevealed() { + FixedMap.Apply(this); if (_parent.World != null) SendMessage(_parent.World.Players.Values .Where(@player => @player.RevealedObjects.ContainsKey(_parent.GlobalID)) @@ -244,6 +247,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ObjectsSystem /// public void BroadcastChangedIfRevealed() { + FixedMap.Apply(this); if (_parent.World != null) SendChangedMessage(_parent.World.Players.Values .Where(@player => @player.RevealedObjects.ContainsKey(_parent.GlobalID)) diff --git a/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Payloads/DeathPayload.cs b/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Payloads/DeathPayload.cs index 884f2e6..c822ddb 100644 --- a/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Payloads/DeathPayload.cs +++ b/src/DiIiS-NA/D3-GameServer/GSSystem/PowerSystem/Payloads/DeathPayload.cs @@ -266,7 +266,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads //Пчелы case ActorSno._sandwasp_a: case ActorSno._fleshpitflyer_leoric_inferno: - Target.PlayAnimation(11, 8535, 1f); + Target.PlayAnimation(11, AnimationSno.fleshpitflyer_death, 1f); break; //X1_LR_Boss_Angel_Corrupt_A case ActorSno._x1_lr_boss_angel_corrupt_a: Target.PlayAnimation(11, 142005, 1f); break; @@ -277,7 +277,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads Target.PlayAnimation(11, FindBestDeathAnimationSNO(), 1f); else { - Logger.Warn("Анимация смерти не обнаружена: ActorSNOId = {0}", Target.SNO); + Logger.Warn("Death animation not found: ActorSNOId = {0}", Target.SNO); } break; }