Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Resolve #1306, Progress #1326 -- Vision and spawn system rework #1329

Merged
merged 12 commits into from
Mar 11, 2022
41 changes: 37 additions & 4 deletions GameServerCore/Domain/GameObjects/IGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,50 @@ public interface IGameObject : IUpdate
void FaceDirection(Vector3 newDirection, bool isInstant = true, float turnTime = 0.08333f);

/// <summary>
/// Whether or not the object is networked to a specified team.
/// Whether or not the object is within the vision of the specified team.
/// </summary>
/// <param name="team">A team which could have vision of this object.</param>
bool IsVisibleByTeam(TeamId team);

/// <summary>
/// Sets the object to be networked or not to a specified team.
/// Sets the object as visible to a specified team.
/// Should be called in the ObjectManager. By itself, it only affects the return value of IsVisibleByTeam.
/// </summary>
/// <param name="team">A team which could have vision of this object.</param>
/// <param name="visible">true/false; networked or not</param>
void SetVisibleByTeam(TeamId team, bool visible);
/// <param name="visible">New value.</param>
void SetVisibleByTeam(TeamId team, bool visible = true);

/// <summary>
/// Whether or not the object is visible for the specified player.
/// <summary>
/// <param name="userId">The player in relation to which the value is obtained</param>
bool IsVisibleForPlayer(int userId);

/// <summary>
/// Sets the object as visible and or not to a specified player.
/// Should be called in the ObjectManager. By itself, it only affects the return value of IsVisibleForPlayer.
/// <summary>
/// <param name="userId">The player for which the value is set.</param>
/// <param name="visible">New value.</param>
void SetVisibleForPlayer(int userId, bool visible = true);

/// <summary>
/// Whether or not the object is spawned on the player's client side.
/// <summary>
/// <param name="userId">The player in relation to which the value is obtained</param>
bool IsSpawnedForPlayer(int userId);

/// <summary>
/// Sets the object as spawned on the player's client side.
/// Should be called in the ObjectManager. By itself, it only affects the return value of IsSpawnedForPlayer.
/// <summary>
/// <param name="userId">The player for which the value is set.</param>
void SetSpawnedForPlayer(int userId);

/// <summary>
/// Allows to iterate all players who see the object
/// </summary>
IEnumerable<int> VisibleForPlayers { get; }

/// <summary>
/// Sets the position of this GameObject to the specified position.
Expand Down
8 changes: 7 additions & 1 deletion GameServerCore/IObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public interface IObjectManager: IUpdate
/// <param name="o">GameObject to add.</param>
void AddObject(IGameObject o);

/// <summary>
/// Normally, objects will spawn at the end of the frame, but calling this function will force the teams' and players' vision of that object to update and send out a spawn notification.
/// </summary>
/// <param name="obj">Object to spawn.</param>
void SpawnObject(IGameObject o);

/// <summary>
/// Gets a new Dictionary of all NetID,GameObject pairs present in the dictionary of objects in ObjectManager.
/// </summary>
Expand Down Expand Up @@ -165,4 +171,4 @@ public interface IObjectManager: IUpdate
/// <param name="champion">Champion to remove.</param>
void RemoveChampion(IChampion champion);
}
}
}
38 changes: 25 additions & 13 deletions GameServerCore/Packets/Interfaces/IPacketNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public interface IPacketNotifier
/// TODO: Implement a Region class so we can easily grab these parameters instead of listing them all in the function.
void NotifyAddRegion(uint unitNetId, uint bubbleNetId, TeamId team, Vector2 position, float time, float radius = 0, int regionType = 0, ClientInfo clientInfo = null, IGameObject obj = null, float collisionRadius = 0, float grassRadius = 0, float sizemult = 1.0f, float addsize = 0, bool grantVis = true, bool stealthVis = false);
/// <summary>
/// Sends a packet to the specified team that a part of the map has changed. Known to be used in League for initializing turret vision and collision.
/// </summary>
/// <param name="region">Region to add.</param>
void NotifyAddRegion(IRegion region);
/// <summary>
/// Sends a packet to all players with vision of the specified attacker detailing that they have targeted the specified target.
/// </summary>
/// <param name="attacker">AI that is targeting an AttackableUnit.</param>
Expand Down Expand Up @@ -133,7 +138,8 @@ public interface IPacketNotifier
/// <param name="slotId">Slot of the spell.</param>
/// <param name="currentCd">Amount of time the spell has already been on cooldown (if applicable).</param>
/// <param name="totalCd">Amount of time that the spell should have be in cooldown before going off cooldown.</param>
void NotifyCHAR_SetCooldown(IObjAiBase c, byte slotId, float currentCd, float totalCd);
/// <param name="userId">UserId to send the packet to. If not specified or zero, the packet is broadcasted to all players that have vision of the specified unit.</param>
void NotifyCHAR_SetCooldown(IObjAiBase c, byte slotId, float currentCd, float totalCd, int userId = 0);
/// <summary>
/// Sends a packet to the specified user that highlights the specified GameObject.
/// </summary>
Expand Down Expand Up @@ -180,8 +186,8 @@ public interface IPacketNotifier
/// Sends a packet to either all players with vision of the specified GameObject or a specified user. The packet contains details of the GameObject's health (given it is of the type AttackableUnit) and is meant for after the GameObject is first initialized into vision.
/// </summary>
/// <param name="o">GameObject coming into vision.</param>
/// <param name="userId">User to send the packet to.</param>
/// <param name="ignoreVision">Optionally ignore vision checks when sending this packet.</param>
/// <param name="userId">UserId to send the packet to. If not specified or zero, the packet is broadcasted to all players that have vision of the specified unit.</param>
/// <param name="ignoreVision">Optionally ignore vision checks when sending this packet and broadcast it to all players instead.</param>
void NotifyEnterLocalVisibilityClient(IGameObject o, int userId = 0, bool ignoreVision = false);
/// <summary>
/// Sends a packet to either all players with vision of the specified object or the specified user. The packet details the data surrounding the specified GameObject that is required by players when a GameObject enters vision such as items, shields, skin, and movements.
Expand Down Expand Up @@ -234,7 +240,8 @@ public interface IPacketNotifier
/// <summary>
/// Sends a packet to all players detailing that the game has started. Sent when all players have finished loading.
/// </summary>
void NotifyGameStart();
/// <param name="userId">UserId to send the packet to. If not specified or zero, the packet is broadcasted to all players.</param>
void NotifyGameStart(int userId = 0);
/// <summary>
/// Sends a packet to all players which announces that the team which owns the specified inhibitor has an inhibitor which is respawning soon.
/// </summary>
Expand Down Expand Up @@ -291,10 +298,8 @@ public interface IPacketNotifier
/// <summary>
/// Optionally sends a packet to all players who have vision of the specified Minion detailing that it has spawned.
/// </summary>
/// <returns>A new and fully setup SpawnMinionS2C packet.</returns>
/// <param name="minion">Minion that is spawning.</param>
/// <param name="send">Whether or not to send the created packet.</param>
SpawnMinionS2C NotifyMinionSpawned(IMinion minion, bool send = true);
void NotifyMinionSpawned(IMinion minion);
/// <summary>
/// Sends a packet to either all players with vision (given the projectile is networked to the client) of the projectile, or all players. The packet contains all details regarding the specified projectile's creation.
/// </summary>
Expand All @@ -304,11 +309,12 @@ public interface IPacketNotifier
/// Sends a packet to all players that updates the specified unit's model.
/// </summary>
/// <param name="obj">AttackableUnit to update.</param>
/// <param name="userId">UserId to send the packet to. If not specified or zero, the packet is broadcasted to all players that have vision of the specified unit.</param>
/// <param name="skinID">Unit's skin ID after changing model.</param>
/// <param name="modelOnly">Wether or not it's only the model that it's being changed(?). I don't really know what's this for</param>
/// <param name="overrideSpells">Wether or not the user's spells should be overriden, i assume it would be used for things like Nidalee or Elise.</param>
/// <param name="replaceCharacterPackage">Unknown.</param>
void NotifyS2C_ChangeCharacterData(IAttackableUnit obj, uint skinID = 0, bool modelOnly = true, bool overrideSpells = false, bool replaceCharacterPackage = false);
void NotifyS2C_ChangeCharacterData(IAttackableUnit obj, int userId = 0, uint skinID = 0, bool modelOnly = true, bool overrideSpells = false, bool replaceCharacterPackage = false);
/// <summary>
/// Sends a packet to the specified player detailing that the specified debug object's radius has changed.
/// </summary>
Expand Down Expand Up @@ -435,7 +441,8 @@ public interface IPacketNotifier
/// Sends a packet to all players detailing that the specified Champion has leveled up.
/// </summary>
/// <param name="c">Champion which leveled up.</param>
void NotifyNPC_LevelUp(IChampion c);
/// <param name="userId">UserId to send the packet to. If not specified or zero, the packet is broadcasted to all players that have vision of the specified unit.</param>
void NotifyNPC_LevelUp(IChampion c, int userId = 0);
/// <summary>
/// Sends a packet to the specified user that the spell in the specified slot has been upgraded (skill point added).
/// </summary>
Expand Down Expand Up @@ -788,9 +795,11 @@ public interface IPacketNotifier
/// Calls for the appropriate spawn packet to be sent given the specified GameObject's type and calls for a vision packet to be sent for the specified GameObject.
/// </summary>
/// <param name="o">GameObject that has spawned.</param>
/// <param name="team">The team the user belongs to.</param>
/// <param name="userId">UserId to send the packet to.</param>
/// <param name="gameTime">Time elapsed since the start of the game</param>
/// <param name="doVision">Whether or not to package the packets into a vision packet.</param>
void NotifySpawn(IGameObject o, int userId = 0, bool doVision = true, float gameTime = 0);
void NotifySpawn(IGameObject obj, TeamId team, int userId, float gameTime, bool doVision = true);
/// <summary>
/// Sends a packet to the specified player detailing that the spawning (of champions & buildings) that occurs at the start of the game has ended.
/// </summary>
Expand Down Expand Up @@ -908,9 +917,10 @@ public interface IPacketNotifier
/// Sends a packet to all players with vision of the specified unit detailing that the specified unit's stats have been updated.
/// </summary>
/// <param name="u">Unit who's stats have been updated.</param>
/// <param name="userId">UserId to send the packet to. If not specified or zero, the packet is broadcasted to all players that have vision of the specified unit.</param>
/// <param name="partial">Whether or not the packet should be counted as a partial update (whether the stats have actually changed or not). *NOTE*: Use case for this parameter is unknown.</param>
/// TODO: Replace with LeaguePackets and preferably move all uses of this function to a central EventHandler class (if one is fully implemented).
void NotifyUpdatedStats(IAttackableUnit u, bool partial = true);
void NotifyUpdatedStats(IAttackableUnit u, int userId = 0, bool partial = true);
/// <summary>
/// Sends a packet to the player attempting to use an item that the item was used successfully.
/// </summary>
Expand All @@ -925,13 +935,15 @@ public interface IPacketNotifier
/// <param name="obj">GameObject which had their visibility changed.</param>
/// <param name="team">Team which is affected by this visibility change.</param>
/// <param name="becameVisible">Whether or not the change was an entry into vision.</param>
void NotifyVisibilityChange(IGameObject obj, TeamId team, bool becameVisible);
/// <param name="userId">UserId to send the packet to. If not specified or zero, the packet is broadcasted to the team.</param>
void NotifyVisibilityChange(IGameObject obj, TeamId team, bool becameVisible, int userId = 0);
/// <summary>
/// Sends a packet to all players that have vision of the specified unit that it has made a movement.
/// </summary>
/// <param name="u">AttackableUnit that is moving.</param>
/// <param name="userId">UserId to send the packet to. If not specified or zero, the packet is broadcasted to all players that have vision of the specified unit.</param>
/// <param name="useTeleportID">Whether or not to teleport the unit to its current position in its path.</param>
void NotifyWaypointGroup(IAttackableUnit u, bool useTeleportID = true);
void NotifyWaypointGroup(IAttackableUnit u, int userId = 0, bool useTeleportID = true);
/// <summary>
/// Sends a packet to all players that have vision of the specified unit.
/// The packet details a group of waypoints with speed parameters which determine what kind of movement will be done to reach the waypoints, or optionally a GameObject.
Expand Down
2 changes: 1 addition & 1 deletion GameServerLib/API/APIMapFunctionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public static void AddTurretItems(IBaseTurret turret, int[] items)

public static void NotifySpawn(IGameObject obj)
{
_game.PacketNotifier.NotifySpawn(obj);
_game.ObjectManager.SpawnObject(obj);
}
}
}
3 changes: 3 additions & 0 deletions GameServerLib/API/ApiEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public static void RemoveAllListenersForOwner(object owner)
public static EventOnKill OnKill = new EventOnKill();
public static EventOnKillUnit OnKillUnit = new EventOnKillUnit();
public static EventOnLaunchAttack OnLaunchAttack = new EventOnLaunchAttack();
/// <summary>
/// Called immediately after the rocket is added to the scene. *NOTE*: At the time of the call, the rocket has not yet been spawned for players.
/// <summary>
public static EventOnLaunchMissile OnLaunchMissile = new EventOnLaunchMissile();
public static EventOnLevelUp OnLevelUp = new EventOnLevelUp();
public static EventOnLevelUpSpell OnLevelUpSpell = new EventOnLevelUpSpell();
Expand Down
Loading