Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 53 additions & 31 deletions GameMaths/MathExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

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".

{
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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
Expand All @@ -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);
Expand All @@ -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
}
}
1 change: 1 addition & 0 deletions GameServerCore/Domain/GameObjects/IChampion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface IChampion : IObjAiBase
int Skin { get; }
IChampionStats ChampStats { get; }
byte SkillPoints { get; set; }
int PlayerId { get; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for adding it?


// basic
void UpdateSkin(int skinNo);
Expand Down
17 changes: 17 additions & 0 deletions GameServerCore/Packets/Interfaces/IPacketNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should pass userId here I think.


/// <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);
}
}
12 changes: 12 additions & 0 deletions GameServerLib/API/ApiFunctionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,18 @@ float travelTime
unit.DashToTarget(target, dashSpeed, animation, leapGravity, keepFacingLastDirection, followTargetMaxDistance, backDistance, travelTime);
}


/// <summary>
/// Broadcasts request to play sound client-side
/// </summary>
/// <param name="owner">Sound source (champion, minion, etc).
/// Client depends on it to adjust sound direction according to the Camera position</param>
/// <param name="soundName">Sound name as in game files (can be found by "Play" or "SFX" keywords, or "Play_sfx" prefix)</param>
public static void PlaySFX(IObjAiBase owner, string soundName)
{
_game.PacketNotifier.NotifySfxCreated(soundName, owner.NetId);
}

/// <summary>
/// Forces the specified unit to perform a dash which ends at the given position.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions GameServerLib/GameObjects/AttackableUnits/AI/Champion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class Champion : ObjAiBase, IChampion
private uint _playerTeamSpecialId;
private uint _playerHitId;

public int PlayerId => (int)_playerId;
Copy link
Contributor

Choose a reason for hiding this comment

The 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,
Expand Down Expand Up @@ -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;
}

Expand Down
20 changes: 17 additions & 3 deletions GameServerLib/GameObjects/Spells/Spell.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using GameServerCore;
using GameMaths;

using GameServerCore;
using GameServerCore.Content;
using GameServerCore.Domain;
using GameServerCore.Domain.GameObjects;
using GameServerCore.Enums;

using LeagueSandbox.GameServer.API;
using LeagueSandbox.GameServer.Content;
using LeagueSandbox.GameServer.GameObjects.AttackableUnits;
Expand All @@ -11,6 +14,7 @@
using LeagueSandbox.GameServer.GameObjects.Other;
using LeagueSandbox.GameServer.Packets;
using LeagueSandbox.GameServer.Scripting.CSharp;

using System.Collections.Generic;
using System.Numerics;

Expand Down Expand Up @@ -121,12 +125,12 @@ public virtual bool Cast(float x, float y, float x2, float y2, IAttackableUnit u
}

// TODO: Check SpellData for if the spell should stop movement (and when).
if (!Owner.IsDashing)
if (!Owner.IsDashing && !SpellData.CanMoveWhileChanneling)
{
Owner.StopMovement();
}

_game.PacketNotifier.NotifyNPC_CastSpellAns(_game.Map.NavigationGrid, this, new Vector2(x, y) , new Vector2(x2, y2), _futureProjNetId);
_game.PacketNotifier.NotifyNPC_CastSpellAns(_game.Map.NavigationGrid, this, new Vector2(x, y), new Vector2(x2, y2), _futureProjNetId);

return true;
}
Expand Down Expand Up @@ -216,6 +220,16 @@ public virtual void Update(float diff)
}
}

//Preparations for the charging
private int CalculateGrowthFromCurrentChannelDuration()
{
var actuallyPassed = SpellData.ChannelDuration[Level] - CurrentChannelDuration;
var percentageGrowth = actuallyPassed / SpellData.CastRangeGrowthDuration[Level];
var newRange = MathExtension.Lerp(SpellData.CastRange[Level], SpellData.CastRadius[Level], percentageGrowth);

return (int)System.Math.Min(newRange, SpellData.CastRadius[Level]);
}

/// <summary>
/// Called by projectiles when they land / hit, this is where we apply damage/slows etc.
/// </summary>
Expand Down
43 changes: 42 additions & 1 deletion PacketDefinitions420/PacketNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

player.PlayerId shouldn't be here. There is a way to go from Champion to userId with PlayerManager. The champion class shouldn't know about that.

}

/// <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);
}
}
}
15 changes: 14 additions & 1 deletion PacketDefinitions420/PacketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Expand Down