- 
                Notifications
    You must be signed in to change notification settings 
- Fork 454
Quality of life improvements #1038
base: indev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -5,29 +5,78 @@ namespace GameMaths | |
| { | ||
| public static class MathExtension | ||
| { | ||
|  | ||
| public static bool IsZero(this float a) | ||
| { | ||
| return Math.Abs(a) < 1e-6f; | ||
| } | ||
|  | ||
| public static float Lerp(float firstFloat, float secondFloat, float by) | ||
| { | ||
| return firstFloat * (1 - by) + secondFloat * by; | ||
| } | ||
|  | ||
| #region Vector operations extensions | ||
|  | ||
| public static Vector2 ToVector2(this Vector3 vector) | ||
| { | ||
| return new Vector2(vector.X, vector.Z); | ||
| } | ||
|  | ||
| public static void Normalize(this Vector2 vector2) | ||
| { | ||
| float length = vector2.Length(); | ||
| if (!length.IsZero()) | ||
| { | ||
| float inv = 1.0f / length; | ||
| vector2.X *= inv; | ||
| vector2.Y *= inv; | ||
| } | ||
| } | ||
|  | ||
| public static float Distance(this Vector2 value1, Vector2 value2) | ||
| { | ||
| float x = value1.X - value2.X; | ||
| float y = value1.Y - value2.Y; | ||
| return (float)Math.Sqrt((x * x) + (y * y)); | ||
| } | ||
|  | ||
| public static float DistanceSquared(this Vector2 value1, Vector2 value2) | ||
| { | ||
| float x = value1.X - value2.X; | ||
| float y = value1.Y - value2.Y; | ||
| return (x * x) + (y * y); | ||
| } | ||
|  | ||
| public static Vector2 Rotated(this Vector2 vector2, float angle) | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a comment if this is clockwise or anti-clockwise (I think this is anti-clockwise???). [I know that you didn't write this function, but it may be useful to know what is the direction of the rotation] | ||
| { | ||
| var cos = Math.Cos(angle); | ||
| var sin = Math.Sin(angle); | ||
|  | ||
| return new Vector2( | ||
| (float)((vector2.X * cos) - (vector2.Y * sin)), | ||
| (float)((vector2.Y * cos) + (vector2.X * sin))); | ||
| } | ||
|  | ||
| public static Vector2 Normalized(this Vector2 vector2) | ||
| { | ||
| vector2.Normalize(); | ||
| return vector2; | ||
| } | ||
|  | ||
| public static Vector2 Perpendicular(this Vector2 vector2, int offset = 0) | ||
| { | ||
| return (offset == 0) ? new Vector2(-vector2.Y, vector2.X) : new Vector2(vector2.Y, -vector2.X); | ||
| } | ||
|  | ||
| public static float Distance(this Vector3 value1, Vector3 value2) | ||
| { | ||
| float x = value1.X - value2.X; | ||
| float y = value1.Y - value2.Y; | ||
| float z = value1.Z - value2.Z; | ||
| return (float)Math.Sqrt((x * x) + (y * y) + (z * z)); | ||
| } | ||
|  | ||
| public static float DistanceSquared(this Vector3 value1, Vector3 value2) | ||
| { | ||
| float x = value1.X - value2.X; | ||
|  | @@ -36,10 +85,12 @@ public static float DistanceSquared(this Vector3 value1, Vector3 value2) | |
|  | ||
| return (x * x) + (y * y) + (z * z); | ||
| } | ||
|  | ||
| public static float Dot(this Vector3 left, Vector3 right) | ||
| { | ||
| return (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z); | ||
| } | ||
|  | ||
| public static Vector3 Rotated(this Vector3 vector3, float angle) | ||
| { | ||
| var cos = Math.Cos(angle); | ||
|  | @@ -50,41 +101,12 @@ public static Vector3 Rotated(this Vector3 vector3, float angle) | |
| (float)((vector3.Y * cos) + (vector3.X * sin)), | ||
| vector3.Z); | ||
| } | ||
| public static Vector2 Rotated(this Vector2 vector2, float angle) | ||
| { | ||
| var cos = Math.Cos(angle); | ||
| var sin = Math.Sin(angle); | ||
|  | ||
| return new Vector2( | ||
| (float)((vector2.X * cos) - (vector2.Y * sin)), | ||
| (float)((vector2.Y * cos) + (vector2.X * sin))); | ||
| } | ||
| public static bool IsZero(this float a) | ||
| { | ||
| return Math.Abs(a) < 1e-6f; | ||
| } | ||
| public static void Normalize(this Vector2 vector2) | ||
| { | ||
| float length = vector2.Length(); | ||
| if (!length.IsZero()) | ||
| { | ||
| float inv = 1.0f / length; | ||
| vector2.X *= inv; | ||
| vector2.Y *= inv; | ||
| } | ||
| } | ||
| public static Vector2 Normalized(this Vector2 vector2) | ||
| { | ||
| vector2.Normalize(); | ||
| return vector2; | ||
| } | ||
| public static Vector2 Perpendicular(this Vector2 vector2, int offset = 0) | ||
| { | ||
| return (offset == 0) ? new Vector2(-vector2.Y, vector2.X) : new Vector2(vector2.Y, -vector2.X); | ||
| } | ||
| public static Vector3 Perpendicular(this Vector3 vector3, int offset = 0) | ||
| { | ||
| return (offset == 0) ? new Vector3(-vector3.Y, vector3.X, vector3.Z) : new Vector3(vector3.Y, -vector3.X, vector3.Z); | ||
| } | ||
|  | ||
| #endregion | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -13,6 +13,7 @@ public interface IChampion : IObjAiBase | |
| int Skin { get; } | ||
| IChampionStats ChampStats { get; } | ||
| byte SkillPoints { get; set; } | ||
| int PlayerId { get; } | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for adding it? | ||
|  | ||
| // basic | ||
| void UpdateSkin(int skinNo); | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -760,5 +760,22 @@ public interface IPacketNotifier | |
| /// <param name="request">ViewRequest housing information about the camera's view.</param> | ||
| /// TODO: Verify if this is the correct implementation. | ||
| void NotifyViewResponse(int userId, ViewRequest request); | ||
|  | ||
| /// <summary> | ||
| /// Notifies client that spell in <paramref name="slot"/> must be replaced with a <paramref name="newSpell"/> | ||
| /// </summary> | ||
| /// <param name="playerId">User to send the packet to.</param> | ||
| /// <param name="player">User to send the packe</param> | ||
| /// <param name="newSpell"></param> | ||
| /// <param name="slot"></param> | ||
| void NotifySpellChangeResponse(IChampion player, string newSpell, byte slot); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should pass  | ||
|  | ||
| /// <summary> | ||
| /// Broadcasts request to play sound client-side | ||
| /// </summary> | ||
| /// <param name="sfxName">Sound name (can be found by "Play" or "SFX" keywords, or "Play_sfx" prefix)</param> | ||
| /// <param name="ownerNetId">NetId of the sound source (champion, minion, etc). | ||
| /// Client depends on it to adjust sound direction according to the Camera position</param> | ||
| void NotifySfxCreated(string sfxName, uint ownerNetId); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -40,6 +40,8 @@ public class Champion : ObjAiBase, IChampion | |
| private uint _playerTeamSpecialId; | ||
| private uint _playerHitId; | ||
|  | ||
| public int PlayerId => (int)_playerId; | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this PlayerId. It shouldn't be here. | ||
|  | ||
| public Champion(Game game, | ||
| string model, | ||
| uint playerId, | ||
|  | @@ -522,6 +524,8 @@ public ISpell SetSpell(string name, byte slot, bool enabled) | |
| Spells[slot] = newSpell; | ||
| Stats.SetSpellEnabled(slot, enabled); | ||
|  | ||
| _game.PacketNotifier.NotifySpellChangeResponse(this, name, slot); | ||
|  | ||
| return newSpell; | ||
| } | ||
|  | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -1651,7 +1651,7 @@ public void NotifyNPC_CastSpellAns(INavigationGrid navGrid, ISpell s, Vector2 st | |
| // TODO: Implement castInfo.Targets | ||
|  | ||
| DesignerCastTime = s.SpellData.GetCastTime(), // TODO: Verify | ||
| ExtraCastTime = 0.0f, // TODO: Unhardcode | ||
| ExtraCastTime = s.SpellData.ChannelDuration[s.Level] + s.SpellData.DelayCastOffsetPercent, | ||
| DesignerTotalTime = s.SpellData.GetCastTimeTotal(), // TODO: Verify | ||
| Cooldown = s.GetCooldown(), | ||
| StartCastTime = 0.0f, // TODO: Unhardcode | ||
|  | @@ -2329,5 +2329,46 @@ public void NotifyViewResponse(int userId, ViewRequest request) | |
|  | ||
| _packetHandlerManager.SendPacket(userId, answer, Channel.CHL_S2C, PacketFlags.None); | ||
| } | ||
|  | ||
| /// <summary> | ||
| /// Notifies client that spell in <paramref name="slot"/> must be replaced with a <paramref name="newSpell"/> | ||
| /// </summary> | ||
| /// <param name="playerId">User to send the packet to.</param> | ||
| /// <param name="player">User to send the packe</param> | ||
| /// <param name="newSpell"></param> | ||
| /// <param name="slot"></param> | ||
| public void NotifySpellChangeResponse(IChampion player, string newSpell, byte slot) | ||
| { | ||
| var packet = new ChangeSlotSpellData_OwnerOnly | ||
| { | ||
| SenderNetID = player.NetId, | ||
| ChangeSpellData = new ChangeSpellDataSpellName | ||
| { | ||
| IsSummonerSpell = slot == 4 || slot == 5, | ||
| SpellName = newSpell, | ||
| SpellSlot = slot, | ||
| } | ||
| }; | ||
|  | ||
| _packetHandlerManager.SendPacket(player.PlayerId, packet.GetBytes(), Channel.CHL_S2C, PacketFlags.Reliable); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 | ||
| } | ||
|  | ||
| /// <summary> | ||
| /// Broadcasts request to play sound client-side | ||
| /// </summary> | ||
| /// <param name="sfxName">Sound name (can be found by "Play" or "SFX" keywords, or "Play_sfx" prefix)</param> | ||
| /// <param name="ownerNetId">NetId of the sound source (champion, minion, etc). | ||
| /// Client depends on it to adjust sound direction according to the Camera position</param> | ||
| public void NotifySfxCreated(string sfxName, uint ownerNetId) | ||
| { | ||
| var packet = new S2C_PlaySound | ||
| { | ||
| OwnerNetID = ownerNetId, | ||
| SenderNetID = ownerNetId, | ||
| SoundName = sfxName, | ||
| }; | ||
|  | ||
| _packetHandlerManager.BroadcastPacket(packet.GetBytes(), Channel.CHL_S2C); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -41,7 +41,20 @@ public void InitServer(ushort port, Dictionary<ulong, string> blowfishKeys, IGam | |
| { | ||
| _game = game; | ||
| _server = new Host(); | ||
| _server.Create(new Address(_serverHost,port), 32, 32, 0, 0); | ||
| try | ||
| { | ||
| _server.Create(new Address(_serverHost, port), 32, 32, 0, 0); | ||
| } | ||
| catch (Exception) | ||
| { | ||
| foreach (var process in System.Diagnostics.Process.GetProcessesByName("League of Legends")) | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is VERY risky. You can kill the wrong process very easily. Please remove this. | ||
| { | ||
| process.Kill(); | ||
| } | ||
|  | ||
| System.Threading.Thread.Sleep(200); | ||
| _server.Create(new Address(_serverHost, port), 32, 32, 0, 0); | ||
| } | ||
|  | ||
| Dictionary<ulong, BlowFish> blowfishes = new Dictionary<ulong, BlowFish>(); | ||
| foreach(var rawKey in blowfishKeys) | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand this function, but it isn't clear generally. Please add a comment like "Calculation the point between firstFloat and secondFloat with by marking the affinity".