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

Commit

Permalink
Progress #1407 -- Moving pieces of code to where they should be (#1439)
Browse files Browse the repository at this point in the history
For `GameObject`s, the `LateUpdate`, `Sync`, `OnAfterSync` and `OnReconnect` functions have been introduced.
The next step is to move the some of the function calls from `PacketNotifier` to `OnEnter/LeaveVision`, `OnSync` and `OnSpawn`.
  • Loading branch information
Killfrra authored May 1, 2022
1 parent 85a966e commit 6630850
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 121 deletions.
30 changes: 29 additions & 1 deletion GameServerCore/Domain/GameObjects/IGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public interface IGameObject : IUpdate
/// Radius of the circle which is used for vision; detecting if objects are visible given terrain, and if so, networked to the player (or team) that owns this game object.
/// </summary>
float VisionRadius { get; }
/// <summary>
/// Whether the object should be hidden by the fog of war.
/// </summary>
bool IsAffectedByFoW { get; }
/// <summary>
/// If an object is to be hidden by the fog of war,
/// should the object's spawn notification be sent only when the object comes into view,
/// not as soon as possible.
/// </summary>
bool SpawnShouldBeHidden { get; }

/// <summary>
/// Called by ObjectManager after AddObject (usually right after instatiation of GameObject).
Expand Down Expand Up @@ -104,6 +114,24 @@ public interface IGameObject : IUpdate
/// </summary>
void OnCollision(IGameObject collider, bool isTerrain = false);

/// <summary>
/// Called by ObjectManager after the Update function has been called on all objects.
/// Designed to be used by AI to determine the target.
/// </summary>
void LateUpdate(float diff);
/// <summary>
/// Called by the ObjectManager after vision has been computed for this object and a particular player.
/// </summary>
void Sync(int userId, TeamId team, bool visible, bool forceSpawn = false);
/// <summary>
/// Called by ObjectManager after the Sync function has been called on all objects.
/// </summary>
void OnAfterSync();
/// <summary>
/// Called by HandleSpawn class after the player has reconnected.
/// </summary>
void OnReconnect(int userId, TeamId team);

/// <summary>
/// Sets the object's team.
/// </summary>
Expand All @@ -128,7 +156,7 @@ public interface IGameObject : IUpdate
/// <param name="team">A team which could have vision of this object.</param>
/// <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>
Expand Down
2 changes: 2 additions & 0 deletions GameServerLib/GameObjects/AttackableUnits/AI/BaseTurret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class BaseTurret : ObjAiBase, IBaseTurret
/// </summary>
public IRegion BubbleRegion { get; private set; }

public override bool IsAffectedByFoW => false;

public BaseTurret(
Game game,
string name,
Expand Down
2 changes: 2 additions & 0 deletions GameServerLib/GameObjects/AttackableUnits/AI/LaneMinion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class LaneMinion : Minion, ILaneMinion
public string BarracksName { get; }
public MinionSpawnType MinionSpawnType { get; }

public override bool SpawnShouldBeHidden => false;

public LaneMinion(
Game game,
MinionSpawnType spawnType,
Expand Down
12 changes: 12 additions & 0 deletions GameServerLib/GameObjects/AttackableUnits/AI/LaneTurret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,17 @@ public override void AutoAttackHit(IAttackableUnit target)
base.AutoAttackHit(target);
}
}

protected override void OnSpawn(int userId, TeamId team, bool doVision)
{
base.OnSpawn(userId, team, doVision);
foreach (var item in Inventory)
{
if (item != null)
{
_game.PacketNotifier.NotifyBuyItem(userId, this, item as IItem);
}
}
}
}
}
31 changes: 30 additions & 1 deletion GameServerLib/GameObjects/AttackableUnits/AI/ObjAIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,9 @@ public void SetPet(IPet pet)
public override void Update(float diff)
{
base.Update(diff);

UpdateBuffs(diff);

CharScript.OnUpdate(diff);
if (!_aiPaused)
{
Expand Down Expand Up @@ -1093,7 +1096,33 @@ public override void Update(float diff)
SetPet(null);
}
}

void UpdateBuffs(float diff)
{
var tempBuffs = new List<IBuff>(GetBuffs());
for (int i = tempBuffs.Count - 1; i >= 0; i--)
{
if (tempBuffs[i].Elapsed())
{
RemoveBuff(tempBuffs[i]);
}
else
{
tempBuffs[i].Update(diff);
}
}
}
public override void LateUpdate(float diff)
{
// Stop targeting an untargetable unit.
if (TargetUnit != null && !TargetUnit.Status.HasFlag(StatusFlags.Targetable))
{
if(TargetUnit is IObjAiBase aiTar && aiTar.CharData.IsUseable)
{
return;
}
Untarget(TargetUnit);
}
}
public override void TakeDamage(IAttackableUnit attacker, float damage, DamageType type, DamageSource source, DamageResultType damageText)
{
base.TakeDamage(attacker, damage, type, source, damageText);
Expand Down
21 changes: 21 additions & 0 deletions GameServerLib/GameObjects/AttackableUnits/AttackableUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public class AttackableUnit : GameObject, IAttackableUnit
/// </summary>
public IForceMovementParameters MovementParameters { get; protected set; }

public override bool IsAffectedByFoW => true;
public override bool SpawnShouldBeHidden => true;

public AttackableUnit(
Game game,
string model,
Expand Down Expand Up @@ -273,6 +276,24 @@ public override void OnCollision(IGameObject collider, bool isTerrain = false)
}
}

protected override void OnSync(int userId, TeamId team)
{
if (Replication.Changed)
{
_game.PacketNotifier.HoldReplicationDataUntilOnReplicationNotification(this, userId, true);
}
if (IsMovementUpdated())
{
_game.PacketNotifier.HoldMovementDataUntilWaypointGroupNotification(this, userId, false);
}
}

public override void OnAfterSync()
{
Replication.MarkAsUnchanged();
ClearMovementUpdated();
}

/// <summary>
/// Returns whether or not this unit is targetable to the specified team.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace LeagueSandbox.GameServer.GameObjects.AttackableUnits.Buildings
{
public class ObjBuilding : AttackableUnit, IObjBuilding
{
public override bool IsAffectedByFoW => false;

public ObjBuilding(Game game, string model, IStats stats, int collisionRadius = 40,
Vector2 position = new Vector2(), int visionRadius = 0, uint netId = 0, TeamId team = TeamId.TEAM_BLUE) :
base(game, model, stats, collisionRadius, position, visionRadius, netId, team)
Expand Down
73 changes: 71 additions & 2 deletions GameServerLib/GameObjects/GameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public IEnumerable<int> VisibleForPlayers
/// </summary>
public float VisionRadius { get; protected set; }

public virtual bool IsAffectedByFoW => false;
public virtual bool SpawnShouldBeHidden => false;

/// <summary>
/// Instantiation of an object which represents the base class for all objects in League of Legends.
/// </summary>
Expand Down Expand Up @@ -132,6 +135,10 @@ public virtual void Update(float diff)
{
}

public virtual void LateUpdate(float diff)
{
}

/// <summary>
/// Whether or not the object should be removed from the game (usually both server and client-side). Refer to ObjectManager.
/// </summary>
Expand Down Expand Up @@ -242,6 +249,68 @@ public virtual void OnCollision(IGameObject collider, bool isTerrain = false)
}
}

protected virtual void OnSpawn(int userId, TeamId team, bool doVision)
{
_game.PacketNotifier.NotifySpawn(this, team, userId, _game.GameTime, doVision);
}

protected virtual void OnEnterVision(int userId, TeamId team)
{
_game.PacketNotifier.NotifyVisibilityChange(this, team, true, userId);
}

protected virtual void OnSync(int userId, TeamId team)
{
}

protected virtual void OnLeaveVision(int userId, TeamId team)
{
_game.PacketNotifier.NotifyVisibilityChange(this, team, false, userId);
}

public virtual void Sync(int userId, TeamId team, bool visible, bool forceSpawn = false)
{
visible = visible || !IsAffectedByFoW;

if (!forceSpawn && IsSpawnedForPlayer(userId))
{
if (IsAffectedByFoW && (IsVisibleForPlayer(userId) != visible))
{
if(visible)
{
OnEnterVision(userId, team);
}
else
{
OnLeaveVision(userId, team);
}
SetVisibleForPlayer(userId, visible);
}
else if(visible)
{
OnSync(userId, team);
}
}
else if (visible || !SpawnShouldBeHidden)
{
OnSpawn(userId, team, visible);
SetVisibleForPlayer(userId, visible);
SetSpawnedForPlayer(userId);
}
}

public virtual void OnAfterSync()
{
}

public virtual void OnReconnect(int userId, TeamId team)
{
if(IsSpawnedForPlayer(userId))
{
OnSpawn(userId, team, IsVisibleForPlayer(userId));
}
}

/// <summary>
/// Sets the object's team.
/// </summary>
Expand All @@ -263,7 +332,7 @@ public virtual void SetTeam(TeamId team)
/// <param name="team">A team which could have vision of this object.</param>
public bool IsVisibleByTeam(TeamId team)
{
return _visibleByTeam[team];
return !IsAffectedByFoW || _visibleByTeam[team];
}

/// <summary>
Expand All @@ -283,7 +352,7 @@ public void SetVisibleByTeam(TeamId team, bool visible = true)
/// <param name="userId">The player in relation to which the value is obtained</param>
public bool IsVisibleForPlayer(int userId)
{
return _visibleForPlayers.GetValueOrDefault(userId, false);
return !IsAffectedByFoW || _visibleForPlayers.GetValueOrDefault(userId, false);
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions GameServerLib/GameObjects/Particle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public class Particle : GameObject, IParticle
/// </summary>
public FXFlags Flags { get; }

public override bool IsAffectedByFoW => true;
public override bool SpawnShouldBeHidden => true;

/// <summary>
/// Prepares the Particle, setting up the information required for networking it to clients.
/// This particle will spawn and stay on the specified GameObject target.
Expand Down
3 changes: 3 additions & 0 deletions GameServerLib/GameObjects/Spell/Missile/SpellMissile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class SpellMissile : GameObject, ISpellMissile
/// </summary>
public bool IsServerOnly { get; }

public override bool IsAffectedByFoW => true;
public override bool SpawnShouldBeHidden => true;

public SpellMissile(
Game game,
int collisionRadius,
Expand Down
Loading

0 comments on commit 6630850

Please sign in to comment.