diff --git a/Content/LeagueSandbox-Default b/Content/LeagueSandbox-Default index b4f623e8a..16efd61d7 160000 --- a/Content/LeagueSandbox-Default +++ b/Content/LeagueSandbox-Default @@ -1 +1 @@ -Subproject commit b4f623e8ac68e0f06e943e9da4270a262bf48fb4 +Subproject commit 16efd61d707d304726a4fd1e124247277f7ca119 diff --git a/GameServerCore/Content/INavGrid.cs b/GameServerCore/Content/INavGrid.cs index 240ccb9ca..93830d6e5 100644 --- a/GameServerCore/Content/INavGrid.cs +++ b/GameServerCore/Content/INavGrid.cs @@ -1,4 +1,5 @@ using System.Numerics; +using GameServerCore.Domain.GameObjects; namespace GameServerCore.Content { @@ -28,5 +29,7 @@ public interface INavGrid bool IsWalkable(Vector2 coords); bool IsWalkable(float x, float y); Vector2 GetSize(); + bool IsAnythingBetween(IGameObject a, IGameObject b); + Vector2 GetClosestTerrainExit(Vector2 location); } } diff --git a/GameServerCore/Domain/GameObjects/IAttackableUnit.cs b/GameServerCore/Domain/GameObjects/IAttackableUnit.cs index 92a1b5662..27315f6d8 100644 --- a/GameServerCore/Domain/GameObjects/IAttackableUnit.cs +++ b/GameServerCore/Domain/GameObjects/IAttackableUnit.cs @@ -4,17 +4,20 @@ namespace GameServerCore.Domain.GameObjects { public interface IAttackableUnit : IGameObject { - bool IsModelUpdated { get; set; } bool IsDead { get; } - string Model { get; set; } - int KillDeathCounter { get; } + bool IsModelUpdated { get; set; } + int KillDeathCounter { get; set; } int MinionCounter { get; } + string Model { get; } + IInventoryManager Inventory { get; } IReplication Replication { get; } IStats Stats { get; } - IInventoryManager Inventory { get; } + void Die(IAttackableUnit killer); void TakeDamage(IAttackableUnit attacker, float damage, DamageType type, DamageSource source, bool isCrit); void TakeDamage(IAttackableUnit attacker, float damage, DamageType type, DamageSource source, DamageText damageText); - void Die(IAttackableUnit killer); + + bool IsInDistress(); + bool ChangeModel(string model); } } diff --git a/GameServerCore/Domain/GameObjects/IBaseTurret.cs b/GameServerCore/Domain/GameObjects/IBaseTurret.cs index 343b59e2c..420a5636b 100644 --- a/GameServerCore/Domain/GameObjects/IBaseTurret.cs +++ b/GameServerCore/Domain/GameObjects/IBaseTurret.cs @@ -2,7 +2,9 @@ { public interface IBaseTurret : IObjAiBase { - string Name { get; } uint ParentNetId { get; } + string Name { get; } + + void CheckForTargets(); } } diff --git a/GameServerCore/Domain/GameObjects/IChampion.cs b/GameServerCore/Domain/GameObjects/IChampion.cs index 7775ea2e9..ff461a45e 100644 --- a/GameServerCore/Domain/GameObjects/IChampion.cs +++ b/GameServerCore/Domain/GameObjects/IChampion.cs @@ -5,8 +5,9 @@ namespace GameServerCore.Domain.GameObjects { public interface IChampion : IObjAiBase { + IShop Shop { get; } float RespawnTimer { get; } - float ChampionGoldFromMinions { get; } + float ChampionGoldFromMinions { get; set; } IRuneCollection RuneList { get; } Dictionary Spells { get; } int Skin { get; } @@ -14,13 +15,14 @@ public interface IChampion : IObjAiBase byte SkillPoints { get; set; } // basic - void TeleportTo(float x, float y); void UpdateSkin(int skinNo); int GetChampionHash(); void StopChampionMovement(); bool CanMove(); void UpdateMoveOrder(MoveOrder order); bool CanCast(); + void Recall(); + void Respawn(); // spells void SetSpell(string name, byte slot, bool enabled = false); @@ -29,6 +31,6 @@ public interface IChampion : IObjAiBase ISpell GetSpell(byte slot); ISpell LevelUpSpell(byte slot); - + void OnKill(IAttackableUnit killed); } } diff --git a/GameServerCore/Domain/GameObjects/IChampionStats.cs b/GameServerCore/Domain/GameObjects/IChampionStats.cs index a6891e3ce..92088b575 100644 --- a/GameServerCore/Domain/GameObjects/IChampionStats.cs +++ b/GameServerCore/Domain/GameObjects/IChampionStats.cs @@ -2,46 +2,47 @@ { public interface IChampionStats { - int Assists { get; } - int Kills { get; } - int DoubleKills { get; } - int UnrealKills { get; } - float GoldEarned { get; } - float GoldSpent { get; } - int CurrentKillingSpree { get; } - float LargestCriticalStrike { get; } - int LargestKillingSpree { get; } - int LargestMultiKill { get; } - float LongestTimeSpentLiving { get; } - float MagicDamageDealt { get; } - float MagicDamageDealtToChampions { get; } - float MagicDamageTaken { get; } - int MinionsKilled { get; } - int NeutralMinionsKilled { get; } - int NeutralMinionsKilledInEnemyJungle { get; } - int NeutralMinionsKilledInTeamJungle { get; } - int Deaths { get; } - int PentaKills { get; } - float PhysicalDamageDealt { get; } - float PhysicalDamageDealtToChampions { get; } - float PhysicalDamageTaken { get; } - int QuadraKills { get; } - int TeamId { get; } - float TotalDamageDealt { get; } - float TotalDamageDealtToChampions { get; } - float TotalDamageTaken { get; } - int TotalHeal { get; } - float TotalTimeCrowdControlDealt { get; } - float TotalTimeSpentDead { get; } - int TotalUnitsHealed { get; } - int TripleKills { get; } - float TrueDamageDealt { get; } - float TrueDamageDealtToChampions { get; } - float TrueDamageTaken { get; } - int TurretsKilled { get; } - int BarracksKilled { get; } - int WardsKilled { get; } - int WardsPlaced { get; } + int Kills { get; set; } + int DoubleKills { get; set; } + int TripleKills { get; set; } + int QuadraKills { get; set; } + int PentaKills { get; set; } + int UnrealKills { get; set; } + int Deaths { get; set; } + int Assists { get; set; } + int CurrentKillingSpree { get; set; } + int LargestKillingSpree { get; set; } + int LargestMultiKill { get; set; } + int MinionsKilled { get; set; } + int NeutralMinionsKilled { get; set; } + int NeutralMinionsKilledInEnemyJungle { get; set; } + int NeutralMinionsKilledInTeamJungle { get; set; } + int TurretsKilled { get; set; } + int BarracksKilled { get; set; } + int WardsKilled { get; set; } + int WardsPlaced { get; set; } + int TeamId { get; set; } + int TotalHeal { get; set; } + int TotalUnitsHealed { get; set; } + + float GoldEarned { get; set; } + float GoldSpent { get; set; } + float LargestCriticalStrike { get; set; } + float LongestTimeSpentLiving { get; set; } + float MagicDamageDealt { get; set; } + float MagicDamageDealtToChampions { get; set; } + float MagicDamageTaken { get; set; } + float PhysicalDamageDealt { get; set; } + float PhysicalDamageDealtToChampions { get; set; } + float PhysicalDamageTaken { get; set; } + float TotalDamageDealt { get; set; } + float TotalDamageDealtToChampions { get; set; } + float TotalDamageTaken { get; set; } + float TotalTimeCrowdControlDealt { get; set; } + float TotalTimeSpentDead { get; set; } + float TrueDamageDealt { get; set; } + float TrueDamageDealtToChampions { get; set; } + float TrueDamageTaken { get; set; } byte[] GetBytes(); } diff --git a/GameServerCore/Domain/GameObjects/IGameObject.cs b/GameServerCore/Domain/GameObjects/IGameObject.cs index 61ba0f8bc..29e73567c 100644 --- a/GameServerCore/Domain/GameObjects/IGameObject.cs +++ b/GameServerCore/Domain/GameObjects/IGameObject.cs @@ -4,24 +4,35 @@ namespace GameServerCore.Domain.GameObjects { - public interface IGameObject : ITarget + public interface IGameObject : ITarget, IUpdate { uint NetId { get; } - ITarget Target { get; } - List Waypoints { get; } int CurWaypoint { get; } + List Waypoints { get; } + ITarget Target { get; } TeamId Team { get; } - int AttackerCount { get; } float CollisionRadius { get; } float VisionRadius { get; } - bool IsDashing { get; } float GetZ(); float GetMoveSpeed(); - void SetPosition(float x, float y); - void SetWaypoints(List newWaypoints); - void SetTeam(TeamId team); + + void ClearMovementUpdated(); + void OnAdded(); + void OnCollision(IGameObject collider); void OnRemoved(); + + void SetPosition(float x, float y); + void SetPosition(Vector2 vec); + void SetTeam(TeamId team); + void SetToRemove(); + void SetVisibleByTeam(TeamId team, bool visible); + void SetWaypoints(List newWaypoints); + + bool IsCollidingWith(IGameObject o); + bool IsMovementUpdated(); + bool IsToRemove(); + bool IsVisibleByTeam(TeamId team); } } diff --git a/GameServerCore/Domain/GameObjects/IInhibitor.cs b/GameServerCore/Domain/GameObjects/IInhibitor.cs index 7797ba827..acaa5e0ee 100644 --- a/GameServerCore/Domain/GameObjects/IInhibitor.cs +++ b/GameServerCore/Domain/GameObjects/IInhibitor.cs @@ -4,6 +4,9 @@ namespace GameServerCore.Domain.GameObjects { public interface IInhibitor : IObjAnimatedBuilding { + bool RespawnAnnounced { get; } InhibitorState InhibitorState { get; } + void SetState(InhibitorState state, IGameObject killer); + double GetRespawnTimer(); } } diff --git a/GameServerCore/Domain/GameObjects/IObjAiBase.cs b/GameServerCore/Domain/GameObjects/IObjAiBase.cs index 04cb3871c..1cbd15f8d 100644 --- a/GameServerCore/Domain/GameObjects/IObjAiBase.cs +++ b/GameServerCore/Domain/GameObjects/IObjAiBase.cs @@ -1,22 +1,40 @@ -using GameServerCore.Enums; +using System.Collections.Generic; +using GameServerCore.Enums; namespace GameServerCore.Domain.GameObjects { public interface IObjAiBase : IAttackableUnit { - IAttackableUnit TargetUnit { get; } - IAttackableUnit AutoAttackTarget { get; } + IAttackableUnit TargetUnit { get; set; } + IAttackableUnit AutoAttackTarget { get; set; } + bool IsAttacking { get; set; } + bool IsDashing { get; } + bool HasMadeInitialAttack { get; set; } - float AutoAttackDelay { get; } - float AutoAttackProjectileSpeed { get; } + float AutoAttackDelay { get; set; } + float AutoAttackProjectileSpeed { get; set; } MoveOrder MoveOrder { get; } - bool IsCastingSpell { get; } - bool IsMelee { get; } + bool IsCastingSpell { get; set; } + bool IsMelee { get; set; } void UpdateTargetUnit(IAttackableUnit unit); void StopMovement(); + void TeleportTo(float x, float y); + void AddStatModifier(IStatsModifier statModifier); + void RemoveStatModifier(IStatsModifier statModifier); + void SetTargetUnit(IAttackableUnit target); + void AutoAttackHit(IAttackableUnit target); // buffs bool HasBuffGameScriptActive(string buffNamespace, string buffClass); void AddBuffGameScript(string buffNamespace, string buffClass, ISpell ownerSpell, float removeAfter = -1f, bool isUnique = false); + void RemoveBuffSlot(IBuff b); + byte GetNewBuffSlot(IBuff b); + void AddBuff(IBuff b); + void ApplyCrowdControl(ICrowdControl cc); + void RemoveCrowdControl(ICrowdControl cc); + void SetDashingState(bool state); + void DashToTarget(ITarget t, float dashSpeed, float followTargetMaxDistance, float backDistance, float travelTime); + Dictionary GetBuffs(); + void RemoveBuff(IBuff b); } } diff --git a/GameServerCore/Domain/GameObjects/IStat.cs b/GameServerCore/Domain/GameObjects/IStat.cs index 3a0f39c66..5d8de4a0c 100644 --- a/GameServerCore/Domain/GameObjects/IStat.cs +++ b/GameServerCore/Domain/GameObjects/IStat.cs @@ -6,8 +6,10 @@ public interface IStat float BaseBonus { get; } float FlatBonus { get; set; } float BaseValue { get; set; } - float PercentBonus { get; } + float PercentBonus { get; set; } float PercentBaseBonus { get; } float Total { get; } + bool ApplyStatModificator(IStatModifier statModifcator); + bool RemoveStatModificator(IStatModifier statModifcator); } } diff --git a/GameServerCore/Domain/GameObjects/IStats.cs b/GameServerCore/Domain/GameObjects/IStats.cs index b304e3c94..810616192 100644 --- a/GameServerCore/Domain/GameObjects/IStats.cs +++ b/GameServerCore/Domain/GameObjects/IStats.cs @@ -2,7 +2,7 @@ namespace GameServerCore.Domain.GameObjects { - public interface IStats + public interface IStats: IUpdate { ulong SpellsEnabled { get; } ulong SummonerSpellsEnabled { get; } @@ -13,8 +13,8 @@ public interface IStats bool IsPhysicalImmune { get; } bool IsLifestealImmune { get; } bool IsTargetable { get; } - IsTargetableToTeamFlags IsTargetableToTeam { get; } - float AttackSpeedFlat { get; } + IsTargetableToTeamFlags IsTargetableToTeam { get; set; } + float AttackSpeedFlat { get; set; } float HealthPerLevel { get; } float ManaPerLevel { get; } float AdPerLevel { get; } @@ -22,7 +22,7 @@ public interface IStats float MagicResistPerLevel { get; } float HealthRegenerationPerLevel { get; } float ManaRegenerationPerLevel { get; } - float GrowthAttackSpeed { get; } + float GrowthAttackSpeed { get; set; } float[] ManaCost { get; } IStat AbilityPower { get; } IStat Armor { get; } @@ -50,14 +50,20 @@ public interface IStats float Experience { get; set; } float CurrentHealth { get; set; } float CurrentMana { get; set; } - bool IsGeneratingGold { get; } + bool IsGeneratingGold { get; set; } float SpellCostReduction { get; } - + + void AddModifier(IStatsModifier modifier); + void RemoveModifier(IStatsModifier modifier); + void LevelUp(); + + float GetTotalAttackSpeed(); + bool GetActionState(ActionState state); bool GetSpellEnabled(byte id); - void SetSpellEnabled(byte id, bool enabled); bool GetSummonerSpellEnabled(byte id); + + void SetActionState(ActionState state, bool enabled); + void SetSpellEnabled(byte id, bool enabled); void SetSummonerSpellEnabled(byte id, bool enabled); - void AddModifier(IStatsModifier modifier); - void RemoveModifier(IStatsModifier modifier); } } diff --git a/GameServerCore/Domain/GameObjects/ITarget.cs b/GameServerCore/Domain/GameObjects/ITarget.cs index c6c6d2be8..4fe40af9c 100644 --- a/GameServerCore/Domain/GameObjects/ITarget.cs +++ b/GameServerCore/Domain/GameObjects/ITarget.cs @@ -1,4 +1,6 @@ -namespace GameServerCore.Domain.GameObjects +using System.Numerics; + +namespace GameServerCore.Domain.GameObjects { public interface ITarget { @@ -7,6 +9,6 @@ public interface ITarget bool IsSimpleTarget { get; } float GetDistanceTo(ITarget target); - + Vector2 GetPosition(); } } diff --git a/GameServerCore/Domain/IAnnounce.cs b/GameServerCore/Domain/IAnnounce.cs new file mode 100644 index 000000000..5739be733 --- /dev/null +++ b/GameServerCore/Domain/IAnnounce.cs @@ -0,0 +1,9 @@ +namespace GameServerCore.Domain +{ + public interface IAnnounce + { + bool IsAnnounced { get; } + long EventTime { get; } + void Execute(); + } +} \ No newline at end of file diff --git a/GameServerCore/Domain/IBuff.cs b/GameServerCore/Domain/IBuff.cs index 2fca0d256..29de471c9 100644 --- a/GameServerCore/Domain/IBuff.cs +++ b/GameServerCore/Domain/IBuff.cs @@ -3,7 +3,7 @@ namespace GameServerCore.Domain { - public interface IBuff + public interface IBuff: IStackable, IUpdate { float Duration { get; } float TimeElapsed { get; } @@ -11,8 +11,8 @@ public interface IBuff IObjAiBase SourceUnit { get; } BuffType BuffType { get; } string Name { get; } - int Stacks { get; } byte Slot { get; } - + void ResetDuration(); + bool Elapsed(); } } diff --git a/GameServerCore/Domain/ICrowdControl.cs b/GameServerCore/Domain/ICrowdControl.cs new file mode 100644 index 000000000..bbb353a6f --- /dev/null +++ b/GameServerCore/Domain/ICrowdControl.cs @@ -0,0 +1,13 @@ +using GameServerCore.Enums; + +namespace GameServerCore.Domain +{ + public interface ICrowdControl: IUpdate + { + CrowdControlType Type { get; } + float Duration { get; } + float CurrentTime { get; } + bool IsRemoved { get; } + bool IsTypeOf(CrowdControlType type); + } +} \ No newline at end of file diff --git a/GameServerCore/Domain/IInventoryManager.cs b/GameServerCore/Domain/IInventoryManager.cs index 2f16eeb5e..00fed9556 100644 --- a/GameServerCore/Domain/IInventoryManager.cs +++ b/GameServerCore/Domain/IInventoryManager.cs @@ -1,11 +1,18 @@ -namespace GameServerCore.Domain +using System.Collections; +using System.Collections.Generic; + +namespace GameServerCore.Domain { public interface IInventoryManager { IItem GetItem(byte slot); - void RemoveItem(byte slot); byte GetItemSlot(IItem item); - IItem SetExtraItem(byte slot, IItemType item); + void RemoveItem(byte slot); + void RemoveItem(IItem item); + IItem AddItem(IItemData item); + IItem SetExtraItem(byte slot, IItemData item); void SwapItems(byte slot1, byte slot2); + List GetAvailableItems(IEnumerable items); + IEnumerator GetEnumerator(); } } diff --git a/GameServerCore/Domain/IItem.cs b/GameServerCore/Domain/IItem.cs index 63d76311c..3965c8df5 100644 --- a/GameServerCore/Domain/IItem.cs +++ b/GameServerCore/Domain/IItem.cs @@ -1,9 +1,8 @@ namespace GameServerCore.Domain { - public interface IItem + public interface IItem: IStackable { - byte StackSize { get; } int TotalPrice { get; } - IItemType ItemType { get; } + IItemData ItemData { get; } } } diff --git a/GameServerCore/Domain/IItemData.cs b/GameServerCore/Domain/IItemData.cs new file mode 100644 index 000000000..d216f35b0 --- /dev/null +++ b/GameServerCore/Domain/IItemData.cs @@ -0,0 +1,19 @@ +using System.Dynamic; +using GameServerCore.Domain.GameObjects; + +namespace GameServerCore.Domain +{ + public interface IItemData: IStatsModifier + { + int ItemId { get; } + string Name { get; } + int MaxStack { get; } + int Price { get; } + string ItemGroup { get; } + string SpellName { get; } + float SellBackModifier { get; } + int[] RecipeItem { get; } + IItemRecipe Recipe { get; } + int TotalPrice { get; } + } +} diff --git a/GameServerCore/Domain/IItemRecipe.cs b/GameServerCore/Domain/IItemRecipe.cs new file mode 100644 index 000000000..2853ffce6 --- /dev/null +++ b/GameServerCore/Domain/IItemRecipe.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace GameServerCore.Domain +{ + public interface IItemRecipe + { + int TotalPrice { get; } + IEnumerable GetItems(); + } +} \ No newline at end of file diff --git a/GameServerCore/Domain/IItemType.cs b/GameServerCore/Domain/IItemType.cs deleted file mode 100644 index b76162681..000000000 --- a/GameServerCore/Domain/IItemType.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace GameServerCore.Domain -{ - public interface IItemType - { - int ItemId { get; } - string Name { get; } - int MaxStack { get; } - int Price { get; } - string ItemGroup { get; } - float SellBackModifier { get; } - int RecipeItem1 { get; } - int RecipeItem2 { get; } - int RecipeItem3 { get; } - int RecipeItem4 { get; } - int TotalPrice { get; } - - } -} diff --git a/GameServerLib/Scripting/CSharp/MapGameScript.cs b/GameServerCore/Domain/IMapProperties.cs similarity index 58% rename from GameServerLib/Scripting/CSharp/MapGameScript.cs rename to GameServerCore/Domain/IMapProperties.cs index a5edfd679..b075bf11a 100644 --- a/GameServerLib/Scripting/CSharp/MapGameScript.cs +++ b/GameServerCore/Domain/IMapProperties.cs @@ -1,14 +1,12 @@ -using System; +using System; using System.Collections.Generic; using System.Numerics; +using GameServerCore.Domain.GameObjects; using GameServerCore.Enums; -using LeagueSandbox.GameServer.GameObjects.AttackableUnits; -using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; -using LeagueSandbox.GameServer.GameObjects.Other; -namespace LeagueSandbox.GameServer.Scripting.CSharp +namespace GameServerCore.Domain { - public interface IMapGameScript + public interface IMapProperties: IUpdate { List ExpToLevelUp { get; set; } float GoldPerSecond { get; set; } @@ -20,20 +18,19 @@ public interface IMapGameScript bool SpawnEnabled { get; set; } void Init(); - void Update(float diff); Tuple GetMinionSpawnPosition(MinionSpawnPosition spawnPosition); - void SetMinionStats(Minion m); + void SetMinionStats(IMinion m); - Target GetRespawnLocation(TeamId team); + ITarget GetRespawnLocation(TeamId team); string GetMinionModel(TeamId team, MinionSpawnType type); - float GetGoldFor(AttackableUnit u); + float GetGoldFor(IAttackableUnit u); - float GetExperienceFor(AttackableUnit u); + float GetExperienceFor(IAttackableUnit u); Vector3 GetEndGameCameraPosition(TeamId team); } -} +} \ No newline at end of file diff --git a/GameServerCore/Domain/IReplication.cs b/GameServerCore/Domain/IReplication.cs index 43ba04440..898d6363a 100644 --- a/GameServerCore/Domain/IReplication.cs +++ b/GameServerCore/Domain/IReplication.cs @@ -7,5 +7,6 @@ public interface IReplication IReplicate[,] Values { get; } bool Changed { get; } void MarkAsUnchanged(); + void Update(); } } diff --git a/GameServerCore/Domain/IRuneCollection.cs b/GameServerCore/Domain/IRuneCollection.cs index 5ef111100..06aaa5eb9 100644 --- a/GameServerCore/Domain/IRuneCollection.cs +++ b/GameServerCore/Domain/IRuneCollection.cs @@ -5,5 +5,6 @@ namespace GameServerCore.Domain public interface IRuneCollection { Dictionary Runes { get; } + void Add(int runeSlotId, int runeId); } } diff --git a/GameServerCore/Domain/IShop.cs b/GameServerCore/Domain/IShop.cs new file mode 100644 index 000000000..09493b4a7 --- /dev/null +++ b/GameServerCore/Domain/IShop.cs @@ -0,0 +1,8 @@ +namespace GameServerCore.Domain +{ + public interface IShop + { + bool HandleItemSellRequest(byte slotId); + bool HandleItemBuyRequest(int itemId); + } +} \ No newline at end of file diff --git a/GameServerCore/Domain/ISpell.cs b/GameServerCore/Domain/ISpell.cs index 1c8f707d1..6100b7235 100644 --- a/GameServerCore/Domain/ISpell.cs +++ b/GameServerCore/Domain/ISpell.cs @@ -3,7 +3,7 @@ namespace GameServerCore.Domain { - public interface ISpell + public interface ISpell: IUpdate { IChampion Owner { get; } byte Level { get; } @@ -23,8 +23,17 @@ public interface ISpell float Y2 { get; } ISpellData SpellData { get; } + bool Cast(float x, float y, float x2, float y2, IAttackableUnit u); int GetId(); float GetCooldown(); + void LowerCooldown(float lowerValue); void Deactivate(); + void ApplyEffects(IAttackableUnit u, IProjectile p); + void LevelUp(); + void AddProjectile(string nameMissile, float toX, float toY, bool isServerOnly = false); + void AddProjectileTarget(string nameMissile, ITarget target, bool isServerOnly = false); + void AddLaser(string effectName, float toX, float toY, bool affectAsCastIsOver = true); + void AddCone(string effectName, float toX, float toY, float angleDeg, bool affectAsCastIsOver = true); + void SpellAnimation(string animName, IAttackableUnit target); } } diff --git a/GameServerCore/Domain/ISpellData.cs b/GameServerCore/Domain/ISpellData.cs index c8cf0e298..74cceeff0 100644 --- a/GameServerCore/Domain/ISpellData.cs +++ b/GameServerCore/Domain/ISpellData.cs @@ -110,5 +110,6 @@ public interface ISpellData bool UseMinimapTargeting { get; } float GetCastTime(); + void Load(string name); } } diff --git a/GameServerCore/Domain/IStackable.cs b/GameServerCore/Domain/IStackable.cs new file mode 100644 index 000000000..508fb0359 --- /dev/null +++ b/GameServerCore/Domain/IStackable.cs @@ -0,0 +1,10 @@ +namespace GameServerCore.Domain +{ + public interface IStackable + { + byte StackCount { get; } + bool IncrementStackCount(); + bool DecrementStackCount(); + void SetStacks(byte newStacks); + } +} \ No newline at end of file diff --git a/GameServerCore/Domain/IUpdate.cs b/GameServerCore/Domain/IUpdate.cs new file mode 100644 index 000000000..e2370bd37 --- /dev/null +++ b/GameServerCore/Domain/IUpdate.cs @@ -0,0 +1,7 @@ +namespace GameServerCore.Domain +{ + public interface IUpdate + { + void Update(float diff); + } +} \ No newline at end of file diff --git a/GameServerCore/Enums/CrowdControlType.cs b/GameServerCore/Enums/CrowdControlType.cs new file mode 100644 index 000000000..72c10b001 --- /dev/null +++ b/GameServerCore/Enums/CrowdControlType.cs @@ -0,0 +1,7 @@ +namespace GameServerCore.Enums +{ + public enum CrowdControlType + { + AIRBORNE, BLIND, DISARM, GROUND, INVULNERABLE, NEARSIGHT, ROOT, SILENCE, STASIS, STUN, SUPPRESSION, SNARE + } +} \ No newline at end of file diff --git a/GameServerCore/GameServerCore.csproj b/GameServerCore/GameServerCore.csproj index 95f353d43..26584903c 100644 --- a/GameServerCore/GameServerCore.csproj +++ b/GameServerCore/GameServerCore.csproj @@ -42,6 +42,14 @@ + + + + + + + + @@ -74,7 +82,7 @@ - + @@ -98,6 +106,7 @@ + diff --git a/GameServerCore/ICollisionHandler.cs b/GameServerCore/ICollisionHandler.cs new file mode 100644 index 000000000..d7031e7a8 --- /dev/null +++ b/GameServerCore/ICollisionHandler.cs @@ -0,0 +1,13 @@ +using System.Runtime.Versioning; +using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; + +namespace GameServerCore +{ + public interface ICollisionHandler + { + void Update(); + void AddObject(IGameObject obj); + void RemoveObject(IGameObject obj); + } +} \ No newline at end of file diff --git a/GameServerCore/IGame.cs b/GameServerCore/IGame.cs index 313ee55e6..1f942dd7b 100644 --- a/GameServerCore/IGame.cs +++ b/GameServerCore/IGame.cs @@ -3,10 +3,11 @@ using GameServerCore.Packets.Handlers; using System.Collections.Generic; using System.Reflection; +using GameServerCore.Domain; namespace GameServerCore { - public interface IGame + public interface IGame: IUpdate { IMap Map { get; } IObjectManager ObjectManager { get; } diff --git a/GameServerCore/IObjectManager.cs b/GameServerCore/IObjectManager.cs index f24a4c640..b5ff5f1fb 100644 --- a/GameServerCore/IObjectManager.cs +++ b/GameServerCore/IObjectManager.cs @@ -1,10 +1,11 @@ using System.Collections.Generic; +using GameServerCore.Domain; using GameServerCore.Domain.GameObjects; using GameServerCore.Enums; namespace GameServerCore { - public interface IObjectManager + public interface IObjectManager: IUpdate { List Teams { get; } diff --git a/GameServerCore/Maps/IMap.cs b/GameServerCore/Maps/IMap.cs index 885eb4635..b64364655 100644 --- a/GameServerCore/Maps/IMap.cs +++ b/GameServerCore/Maps/IMap.cs @@ -1,9 +1,17 @@ -using GameServerCore.Content; +using System.Collections.Generic; +using GameServerCore.Content; +using GameServerCore.Domain; namespace GameServerCore.Maps { - public interface IMap + public interface IMap: IUpdate { + List AnnouncerEvents { get; } INavGrid NavGrid { get; } + int Id { get; } + ICollisionHandler CollisionHandler { get; } + void Init(); + IMapProperties MapProperties { get; } + IMapProperties GetMapProperties(int mapId); } } diff --git a/GameServerLib/API/ApiEventManager.cs b/GameServerLib/API/ApiEventManager.cs index f780d0c61..af87f8ade 100644 --- a/GameServerLib/API/ApiEventManager.cs +++ b/GameServerLib/API/ApiEventManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using GameServerCore.Domain.GameObjects; using LeagueSandbox.GameServer.GameObjects.AttackableUnits; using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; using LeagueSandbox.GameServer.Logging; @@ -96,14 +97,14 @@ public void Publish(float diff) public class EventOnUnitDamageTaken { - private List> _listeners = new List>(); - public void AddListener(object owner, AttackableUnit unit, Action callback) + private readonly List> _listeners = new List>(); + public void AddListener(object owner, IAttackableUnit unit, Action callback) { - var listenerTuple = new Tuple(owner, unit, callback); + var listenerTuple = new Tuple(owner, unit, callback); _listeners.Add(listenerTuple); } - public void RemoveListener(object owner, AttackableUnit unit) + public void RemoveListener(object owner, IAttackableUnit unit) { _listeners.RemoveAll(listener => listener.Item1 == owner && listener.Item2 == unit); } @@ -113,26 +114,24 @@ public void RemoveListener(object owner) _listeners.RemoveAll(listener => listener.Item1 == owner); } - public void Publish(AttackableUnit unit) + public void Publish(IAttackableUnit unit) { _listeners.ForEach(listener => listener.Item3()); - if (unit is Champion champion) - { + if (unit is IChampion champion) ApiEventManager.OnChampionDamageTaken.Publish(champion); - } } } public class EventOnChampionDamageTaken { - private List> _listeners = new List>(); - public void AddListener(object owner, Champion champion, Action callback) + private readonly List> _listeners = new List>(); + public void AddListener(object owner, IChampion champion, Action callback) { - var listenerTuple = new Tuple(owner, champion, callback); + var listenerTuple = new Tuple(owner, champion, callback); _listeners.Add(listenerTuple); } - public void RemoveListener(object owner, Champion champion) + public void RemoveListener(object owner, IChampion champion) { _listeners.RemoveAll(listener => listener.Item1 == owner && listener.Item2 == champion); } @@ -142,7 +141,7 @@ public void RemoveListener(object owner) _listeners.RemoveAll(listener => listener.Item1 == owner); } - public void Publish(Champion champion) + public void Publish(IChampion champion) { _listeners.ForEach(listener => { diff --git a/GameServerLib/API/ApiFunctionManager.cs b/GameServerLib/API/ApiFunctionManager.cs index ff8e936e8..dcc59ea28 100644 --- a/GameServerLib/API/ApiFunctionManager.cs +++ b/GameServerLib/API/ApiFunctionManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; +using GameServerCore.Domain; using GameServerCore.Domain.GameObjects; using GameServerCore.Enums; using GameServerCore.Packets.Enums; @@ -64,12 +65,12 @@ public static GameScriptTimer CreateTimer(float duration, Action callback) return newTimer; } - public static Buff AddBuffHudVisual(string buffName, float duration, int stacks, BuffType buffType, ObjAiBase onto, float removeAfter = -1.0f) + public static Buff AddBuffHudVisual(string buffName, float duration, byte stacks, BuffType buffType, IObjAiBase onto, float removeAfter = -1.0f) { return AddBuffHudVisual(buffName, duration, stacks, buffType, onto, onto, removeAfter); } - public static Buff AddBuffHudVisual(string buffName, float duration, int stacks, BuffType buffType, ObjAiBase onto, ObjAiBase from, float removeAfter = -1.0f) + public static Buff AddBuffHudVisual(string buffName, float duration, byte stacks, BuffType buffType, IObjAiBase onto, IObjAiBase from, float removeAfter = -1.0f) { var b = new Buff(_game, buffName, duration, stacks, buffType, onto, from); _game.PacketNotifier.NotifyAddBuff(b); @@ -81,7 +82,7 @@ public static Buff AddBuffHudVisual(string buffName, float duration, int stacks, return b; } - public static void RemoveBuffHudVisual(Buff b) + public static void RemoveBuffHudVisual(IBuff b) { _game.PacketNotifier.NotifyRemoveBuff(b.TargetUnit, b.Name, b.Slot); b.TargetUnit.RemoveBuffSlot(b); @@ -101,7 +102,7 @@ public static List GetTeams() return _game.ObjectManager.Teams; } - public static void TeleportTo(ObjAiBase unit, float x, float y) + public static void TeleportTo(IObjAiBase unit, float x, float y) { var coords = new Vector2(x, y); var truePos = _game.Map.NavGrid.GetClosestTerrainExit(coords); @@ -115,20 +116,20 @@ public static bool IsWalkable(float x, float y) return _game.Map.NavGrid.IsWalkable(x, y); } - public static void AddBuff(string buffName, float duration, int stacks, BuffType buffType, ObjAiBase onto, ObjAiBase from) + public static void AddBuff(string buffName, float duration, byte stacks, BuffType buffType, IObjAiBase onto, IObjAiBase from) { var buff = new Buff(_game, buffName, duration, stacks, buffType, onto, from); onto.AddBuff(buff); _game.PacketNotifier.NotifyAddBuff(buff); } - public static void EditBuff(Buff b, int newStacks) + public static void EditBuff(IBuff b, byte newStacks) { b.SetStacks(newStacks); _game.PacketNotifier.NotifyEditBuff(b, newStacks); } - public static Particle AddParticle(Champion champion, string particle, float toX, float toY, float size = 1.0f, string bone = "") + public static Particle AddParticle(IChampion champion, string particle, float toX, float toY, float size = 1.0f, string bone = "") { var t = new Target(toX, toY); var p = new Particle(_game, champion, t, particle, size, bone); @@ -153,23 +154,23 @@ public static void PrintChat(string msg) _game.PacketNotifier.NotifyDebugMessage(msg); } - public static void FaceDirection(AttackableUnit unit, Vector2 direction, bool instant = true, float turnTime = 0.0833f) + public static void FaceDirection(IAttackableUnit unit, Vector2 direction, bool instant = true, float turnTime = 0.0833f) { _game.PacketNotifier.NotifyFaceDirection(unit, direction, instant, turnTime); // todo change units direction } - public static List GetUnitsInRange(Target target, float range, bool isAlive) + public static List GetUnitsInRange(ITarget target, float range, bool isAlive) { return _game.ObjectManager.GetUnitsInRange(target, range, isAlive); } - public static List GetChampionsInRange(Target target, float range, bool isAlive) + public static List GetChampionsInRange(ITarget target, float range, bool isAlive) { return _game.ObjectManager.GetChampionsInRange(target, range, isAlive); } - public static void CancelDash(ObjAiBase unit) + public static void CancelDash(IObjAiBase unit) { // Allow the user to move the champion unit.SetDashingState(false); @@ -179,8 +180,8 @@ public static void CancelDash(ObjAiBase unit) _game.PacketNotifier.NotifySetAnimation(unit, animList); } - public static void DashToUnit(ObjAiBase unit, - Target target, + public static void DashToUnit(IObjAiBase unit, + ITarget target, float dashSpeed, bool keepFacingLastDirection, string animation = null, @@ -229,7 +230,7 @@ public static void DashToUnit(ObjAiBase unit, unit.TargetUnit = null; } - public static void DashToLocation(ObjAiBase unit, + public static void DashToLocation(IObjAiBase unit, float x, float y, float dashSpeed, diff --git a/GameServerLib/API/UnitCrowdControl.cs b/GameServerLib/API/UnitCrowdControl.cs index 22cec5c70..d7ed6dced 100644 --- a/GameServerLib/API/UnitCrowdControl.cs +++ b/GameServerLib/API/UnitCrowdControl.cs @@ -1,14 +1,12 @@ -namespace LeagueSandbox.GameServer.API -{ - public enum CrowdControlType - { - AIRBORNE, BLIND, DISARM, GROUND, INVULNERABLE, NEARSIGHT, ROOT, SILENCE, STASIS, STUN, SUPPRESSION, SNARE - } +using GameServerCore.Domain; +using GameServerCore.Enums; - public class UnitCrowdControl +namespace LeagueSandbox.GameServer.API +{ + public class UnitCrowdControl: ICrowdControl { - public CrowdControlType Type { get; private set; } - public float Duration { get; private set; } + public CrowdControlType Type { get; } + public float Duration { get; } public float CurrentTime { get; private set; } public bool IsRemoved { get; private set; } diff --git a/GameServerLib/Chatbox/Commands/ChCommand.cs b/GameServerLib/Chatbox/Commands/ChCommand.cs index 7e12ddeea..8266d1af2 100644 --- a/GameServerLib/Chatbox/Commands/ChCommand.cs +++ b/GameServerLib/Chatbox/Commands/ChCommand.cs @@ -1,4 +1,5 @@ using GameServerCore; +using GameServerCore.Domain.GameObjects; using LeagueSandbox.GameServer.Content; using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; @@ -33,8 +34,8 @@ public override void Execute(int userId, bool hasReceivedArguments, string argum split[1], (uint)_playerManager.GetPeerInfo(userId).UserId, 0, // Doesnt matter at this point - (RuneCollection)currentChampion.RuneList, - _playerManager.GetClientInfoByChampion((Champion)currentChampion), + currentChampion.RuneList, + _playerManager.GetClientInfoByChampion(currentChampion), currentChampion.NetId ); c.SetPosition( @@ -42,9 +43,9 @@ public override void Execute(int userId, bool hasReceivedArguments, string argum _playerManager.GetPeerInfo(userId).Champion.Y ); - c.Model = split[1]; // trigger the "modelUpdate" proc + c.ChangeModel(split[1]); // trigger the "modelUpdate" proc c.SetTeam(_playerManager.GetPeerInfo(userId).Champion.Team); - Game.ObjectManager.RemoveObject((Champion)_playerManager.GetPeerInfo(userId).Champion); + Game.ObjectManager.RemoveObject(_playerManager.GetPeerInfo(userId).Champion); Game.ObjectManager.AddObject(c); _playerManager.GetPeerInfo(userId).Champion = c; } diff --git a/GameServerLib/Chatbox/Commands/KillCommand.cs b/GameServerLib/Chatbox/Commands/KillCommand.cs index 336e4889d..8c1fb9f16 100644 --- a/GameServerLib/Chatbox/Commands/KillCommand.cs +++ b/GameServerLib/Chatbox/Commands/KillCommand.cs @@ -32,7 +32,7 @@ public override void Execute(int userId, bool hasReceivedArguments, string argum { if (o.Value is Minion minion) { - minion.Die((Champion)_playerManager.GetPeerInfo(userId).Champion); // :( + minion.Die(_playerManager.GetPeerInfo(userId).Champion); // :( } } } diff --git a/GameServerLib/Chatbox/Commands/LevelCommand.cs b/GameServerLib/Chatbox/Commands/LevelCommand.cs index 7bb7105e9..283c054ce 100644 --- a/GameServerLib/Chatbox/Commands/LevelCommand.cs +++ b/GameServerLib/Chatbox/Commands/LevelCommand.cs @@ -30,7 +30,7 @@ public override void Execute(int userId, bool hasReceivedArguments, string argum return; } - var experienceToLevelUp = Game.Map.MapGameScript.ExpToLevelUp[lvl - 1]; + var experienceToLevelUp = Game.Map.MapProperties.ExpToLevelUp[lvl - 1]; _playerManager.GetPeerInfo(userId).Champion.Stats.Experience = experienceToLevelUp; } } diff --git a/GameServerLib/Chatbox/Commands/ModelCommand.cs b/GameServerLib/Chatbox/Commands/ModelCommand.cs index 0822e2313..5d1d29050 100644 --- a/GameServerLib/Chatbox/Commands/ModelCommand.cs +++ b/GameServerLib/Chatbox/Commands/ModelCommand.cs @@ -20,7 +20,7 @@ public override void Execute(int userId, bool hasReceivedArguments, string argum var split = arguments.Split(' '); if (split.Length >= 2) { - _playerManager.GetPeerInfo(userId).Champion.Model = split[1]; + _playerManager.GetPeerInfo(userId).Champion.ChangeModel(split[1]); } else { diff --git a/GameServerLib/Chatbox/Commands/ReviveCommand.cs b/GameServerLib/Chatbox/Commands/ReviveCommand.cs index 964078a07..37a8aa176 100644 --- a/GameServerLib/Chatbox/Commands/ReviveCommand.cs +++ b/GameServerLib/Chatbox/Commands/ReviveCommand.cs @@ -18,7 +18,7 @@ public ReviveCommand(ChatCommandManager chatCommandManager, Game game) public override void Execute(int userId, bool hasReceivedArguments, string arguments = "") { - var champ = (Champion)_playerManager.GetPeerInfo(userId).Champion; + var champ = _playerManager.GetPeerInfo(userId).Champion; if (!champ.IsDead) { ChatCommandManager.SendDebugMsgFormatted(DebugMsgType.INFO, "Your champion is already alive."); diff --git a/GameServerLib/Chatbox/Commands/SpawnStateCommand.cs b/GameServerLib/Chatbox/Commands/SpawnStateCommand.cs index e4e4d83a5..858e137d2 100644 --- a/GameServerLib/Chatbox/Commands/SpawnStateCommand.cs +++ b/GameServerLib/Chatbox/Commands/SpawnStateCommand.cs @@ -22,7 +22,7 @@ public override void Execute(int userId, bool hasReceivedArguments, string argum } else { - Game.Map.MapGameScript.SpawnEnabled = input != 0; + Game.Map.MapProperties.SpawnEnabled = input != 0; } } } diff --git a/GameServerLib/Config.cs b/GameServerLib/Config.cs index d23edef20..dad262aea 100644 --- a/GameServerLib/Config.cs +++ b/GameServerLib/Config.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Numerics; +using GameServerCore.Domain; using LeagueSandbox.GameServer.Content; using Newtonsoft.Json.Linq; @@ -161,10 +162,9 @@ public class PlayerConfig public string Summoner2 => (string)_playerData.SelectToken("summoner2"); public short Ribbon => (short)_playerData.SelectToken("ribbon"); public int Icon => (int)_playerData.SelectToken("icon"); - public RuneCollection Runes => _runeList; + public IRuneCollection Runes { get; } private JToken _playerData; - private RuneCollection _runeList; public PlayerConfig(JToken playerData) { @@ -172,11 +172,11 @@ public PlayerConfig(JToken playerData) try { var runes = _playerData.SelectToken("runes"); - _runeList = new RuneCollection(); + Runes = new RuneCollection(); foreach (JProperty runeCategory in runes) { - _runeList.Add(Convert.ToInt32(runeCategory.Name), Convert.ToInt32(runeCategory.Value)); + Runes.Add(Convert.ToInt32(runeCategory.Name), Convert.ToInt32(runeCategory.Value)); } } catch (Exception) diff --git a/GameServerLib/Content/ContentManager.cs b/GameServerLib/Content/ContentManager.cs index 33affc1e8..96e6362aa 100644 --- a/GameServerLib/Content/ContentManager.cs +++ b/GameServerLib/Content/ContentManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using GameServerCore.Domain; using LeagueSandbox.GameServer.Logging; using log4net; using Newtonsoft.Json.Linq; @@ -13,7 +14,7 @@ public class ContentManager private readonly ILog _logger; private Game _game; - private Dictionary _spellData = new Dictionary(); + private readonly Dictionary _spellData = new Dictionary(); private Dictionary _charData = new Dictionary(); private string _contentPath; @@ -199,7 +200,7 @@ public string GetSpellDataPath(string spellName) return GetContentPath(contentPackages, contentType, fileName); } - public SpellData GetSpellData(string spellName) + public ISpellData GetSpellData(string spellName) { if (_spellData.ContainsKey(spellName)) { diff --git a/GameServerLib/Content/NavGrid.cs b/GameServerLib/Content/NavGrid.cs index 9a0bd800b..eb28fc448 100644 --- a/GameServerLib/Content/NavGrid.cs +++ b/GameServerLib/Content/NavGrid.cs @@ -3,6 +3,7 @@ using System.IO; using GameServerCore; using GameServerCore.Content; +using GameServerCore.Domain.GameObjects; using LeagueSandbox.GameServer.GameObjects; using RoyT.AStar; using Vector2 = System.Numerics.Vector2; @@ -445,7 +446,7 @@ public bool IsAnythingBetween(Vector2 a, Vector2 b) return CastRaySqr(a, b) <= (b - a).SqrLength(); } - public bool IsAnythingBetween(GameObject a, GameObject b) + public bool IsAnythingBetween(IGameObject a, IGameObject b) { return CastRaySqr(a.GetPosition(), b.GetPosition()) <= (b.GetPosition() - a.GetPosition()).SqrLength(); } diff --git a/GameServerLib/Content/RuneCollection.cs b/GameServerLib/Content/RuneCollection.cs index bc279cb7a..8a2784e92 100644 --- a/GameServerLib/Content/RuneCollection.cs +++ b/GameServerLib/Content/RuneCollection.cs @@ -5,7 +5,7 @@ namespace LeagueSandbox.GameServer.Content { public class RuneCollection : IRuneCollection { - public Dictionary Runes { get; set; } + public Dictionary Runes { get; } public RuneCollection() { diff --git a/GameServerLib/Game.cs b/GameServerLib/Game.cs index 7bcaa2a01..1f32d7386 100644 --- a/GameServerLib/Game.cs +++ b/GameServerLib/Game.cs @@ -46,7 +46,7 @@ public class Game : IGame public IPacketReader PacketReader { get; private set; } public IPacketNotifier PacketNotifier { get; private set; } public IObjectManager ObjectManager { get; private set; } - public Map Map { get; private set; } + public IMap Map { get; private set; } public Config Config { get; protected set; } protected const double REFRESH_RATE = 1000.0 / 30.0; // 30 fps @@ -60,8 +60,6 @@ public class Game : IGame //Script Engine internal CSharpScriptEngine ScriptEngine { get; private set; } - IMap IGame.Map => Map; - private Stopwatch _lastMapDurationWatch; private List _gameScriptTimers; @@ -159,10 +157,11 @@ public void GameLoop() } } + public void Update(float diff) { GameTime += diff; - ((ObjectManager)ObjectManager).Update(diff); + ObjectManager.Update(diff); Map.Update(diff); _gameScriptTimers.ForEach(gsTimer => gsTimer.Update(diff)); _gameScriptTimers.RemoveAll(gsTimer => gsTimer.IsDead()); @@ -250,10 +249,10 @@ public Dictionary> GetAllPacketHa } private static List GetInstances(IGame g) { - return (Assembly.GetCallingAssembly() + return Assembly.GetCallingAssembly() .GetTypes() - .Where(t => t.BaseType == (typeof(T))) - .Select(t => (T)Activator.CreateInstance(t, g))).ToList(); + .Where(t => t.BaseType == typeof(T)) + .Select(t => (T)Activator.CreateInstance(t, g)).ToList(); } public void SetGameToExit() diff --git a/GameServerLib/GameObjects/AttackableUnits/AI/AzirTurret.cs b/GameServerLib/GameObjects/AttackableUnits/AI/AzirTurret.cs index 55a8c06bb..0463aa724 100644 --- a/GameServerLib/GameObjects/AttackableUnits/AI/AzirTurret.cs +++ b/GameServerLib/GameObjects/AttackableUnits/AI/AzirTurret.cs @@ -5,13 +5,11 @@ namespace LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI { public class AzirTurret : BaseTurret, IAzirTurret { - public AttackableUnit Owner { get; private set; } - - IAttackableUnit IAzirTurret.Owner => Owner; + public IAttackableUnit Owner { get; private set; } public AzirTurret( Game game, - AttackableUnit owner, + IAttackableUnit owner, string name, string model, float x = 0, diff --git a/GameServerLib/GameObjects/AttackableUnits/AI/BaseTurret.cs b/GameServerLib/GameObjects/AttackableUnits/AI/BaseTurret.cs index 870ed1c76..8d95f1a4c 100644 --- a/GameServerLib/GameObjects/AttackableUnits/AI/BaseTurret.cs +++ b/GameServerLib/GameObjects/AttackableUnits/AI/BaseTurret.cs @@ -35,17 +35,16 @@ public BaseTurret( public void CheckForTargets() { var objects = _game.ObjectManager.GetObjects(); - AttackableUnit nextTarget = null; + IAttackableUnit nextTarget = null; var nextTargetPriority = 14; foreach (var it in objects) { - var u = it.Value as AttackableUnit; - - if (u == null || u.IsDead || u.Team == Team || GetDistanceTo(u) > Stats.Range.Total) - { + if (!(it.Value is IAttackableUnit u) || + u.IsDead || + u.Team == Team || + GetDistanceTo(u) > Stats.Range.Total) continue; - } // Note: this method means that if there are two champions within turret range, // The player to have been added to the game first will always be targeted before the others @@ -60,33 +59,25 @@ public void CheckForTargets() } else { - var targetIsChampion = TargetUnit as Champion; - // Is the current target a champion? If it is, don't do anything - if (targetIsChampion != null) - { - // Find the next champion in range targeting an enemy champion who is also in range - var enemyChamp = u as Champion; - if (enemyChamp != null && enemyChamp.TargetUnit != null) - { - var enemyChampTarget = enemyChamp.TargetUnit as Champion; - if (enemyChampTarget != null && // Enemy Champion is targeting an ally - enemyChamp.GetDistanceTo(enemyChampTarget) <= enemyChamp.Stats.Range.Total && // Enemy within range of ally - GetDistanceTo(enemyChampTarget) <= Stats.Range.Total) // Enemy within range of this turret - { - nextTarget = enemyChamp; // No priority required - break; - } - } - } + if (!(TargetUnit is IChampion)) + continue; + // Find the next champion in range targeting an enemy champion who is also in range + if (!(u is IChampion enemyChamp) || enemyChamp.TargetUnit == null) + continue; + if (!(enemyChamp.TargetUnit is IChampion enemyChampTarget) || + enemyChamp.GetDistanceTo(enemyChampTarget) > enemyChamp.Stats.Range.Total || + GetDistanceTo(enemyChampTarget) > Stats.Range.Total) + continue; + nextTarget = enemyChamp; // No priority required + break; } } - if (nextTarget != null) - { - TargetUnit = nextTarget; - _game.PacketNotifier.NotifySetTarget(this, nextTarget); - } + if (nextTarget == null) + return; + TargetUnit = nextTarget; + _game.PacketNotifier.NotifySetTarget(this, nextTarget); } public override void Update(float diff) diff --git a/GameServerLib/GameObjects/AttackableUnits/AI/Champion.cs b/GameServerLib/GameObjects/AttackableUnits/AI/Champion.cs index 6cf488d1f..a0a9e192b 100644 --- a/GameServerLib/GameObjects/AttackableUnits/AI/Champion.cs +++ b/GameServerLib/GameObjects/AttackableUnits/AI/Champion.cs @@ -16,20 +16,16 @@ namespace LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI { public class Champion : ObjAiBase, IChampion { - public Shop Shop { get; protected set; } + public IShop Shop { get; protected set; } public float RespawnTimer { get; private set; } public float ChampionGoldFromMinions { get; set; } - public RuneCollection RuneList { get; set; } - private Dictionary Spells { get; set; } - public ChampionStats ChampStats { get; private set; } = new ChampionStats(); + public IRuneCollection RuneList { get; } + public Dictionary Spells { get; } + public IChampionStats ChampStats { get; private set; } = new ChampionStats(); public byte SkillPoints { get; set; } public int Skin { get; set; } - IRuneCollection IChampion.RuneList => RuneList; - Dictionary IChampion.Spells => Spells.ToDictionary(x => x.Key, x => (ISpell)x.Value); - IChampionStats IChampion.ChampStats => ChampStats; - private float _championHitFlagTimer; /// /// Player number ordered by the config file. @@ -46,7 +42,7 @@ public Champion(Game game, string model, uint playerId, uint playerTeamSpecialId, - RuneCollection runeList, + IRuneCollection runeList, ClientInfo clientInfo, uint netId = 0) : base(game, model, new Stats.Stats(), 30, 0, 0, 1200, netId) @@ -55,13 +51,13 @@ public Champion(Game game, _playerTeamSpecialId = playerTeamSpecialId; RuneList = runeList; - Spells = new Dictionary(); + Spells = new Dictionary(); Inventory = InventoryManager.CreateInventory(); - Shop = Shop.CreateShop(this, game); + Shop = Items.Shop.CreateShop(this, game); - Stats.Gold = _game.Map.MapGameScript.StartingGold; - Stats.GoldPerSecond.BaseValue = _game.Map.MapGameScript.GoldPerSecond; + Stats.Gold = _game.Map.MapProperties.StartingGold; + Stats.GoldPerSecond.BaseValue = _game.Map.MapProperties.GoldPerSecond; Stats.IsGeneratingGold = false; //TODO: automaticaly rise spell levels with CharData.SpellLevelsUp @@ -217,8 +213,8 @@ public Vector2 GetRespawnPosition() var coords = new Vector2 { - X = _game.Map.MapGameScript.GetRespawnLocation(Team).X, - Y = _game.Map.MapGameScript.GetRespawnLocation(Team).Y + X = _game.Map.MapProperties.GetRespawnLocation(Team).X, + Y = _game.Map.MapProperties.GetRespawnLocation(Team).Y }; return new Vector2(coords.X, coords.Y); @@ -232,12 +228,12 @@ public void StopChampionMovement() _game.PacketNotifier.NotifyMovement(this); } - public Spell GetSpellBySlot(byte slot) + public ISpell GetSpellBySlot(byte slot) { return Spells[slot]; } - public Spell GetSpellByName(string name) + public ISpell GetSpellByName(string name) { foreach (var s in Spells.Values) { @@ -255,7 +251,7 @@ public Spell GetSpellByName(string name) return null; } - public Spell LevelUpSpell(byte slot) + public ISpell LevelUpSpell(byte slot) { if (SkillPoints == 0) { @@ -275,7 +271,7 @@ public Spell LevelUpSpell(byte slot) return s; } - public bool CanSpellBeLeveledUp(Spell s) + public bool CanSpellBeLeveledUp(ISpell s) { return CharData.SpellsUpLevels[s.Slot][s.Level] <= Stats.Level; } @@ -288,21 +284,21 @@ public override void Update(float diff) { var objects = _game.ObjectManager.GetObjects(); var distanceToTarget = 25000f; - AttackableUnit nextTarget = null; + IAttackableUnit nextTarget = null; var range = Math.Max(Stats.Range.Total, DETECT_RANGE); foreach (var it in objects) { - if (!(it.Value is AttackableUnit u) || u.IsDead || u.Team == Team || GetDistanceTo(u) > range) - { + if (!(it.Value is IAttackableUnit u) || + u.IsDead || + u.Team == Team || + GetDistanceTo(u) > range) continue; - } - if (GetDistanceTo(u) < distanceToTarget) - { - distanceToTarget = GetDistanceTo(u); - nextTarget = u; - } + if (!(GetDistanceTo(u) < distanceToTarget)) + continue; + distanceToTarget = GetDistanceTo(u); + nextTarget = u; } if (nextTarget != null) @@ -312,7 +308,7 @@ public override void Update(float diff) } } - if (!Stats.IsGeneratingGold && _game.GameTime >= _game.Map.MapGameScript.FirstGoldTime) + if (!Stats.IsGeneratingGold && _game.GameTime >= _game.Map.MapProperties.FirstGoldTime) { Stats.IsGeneratingGold = true; Logger.Debug("Generating Gold!"); @@ -362,10 +358,10 @@ public void Respawn() RespawnTimer = -1; } - public void Recall(ObjAiBase owner) + public void Recall() { var spawnPos = GetRespawnPosition(); - owner.TeleportTo(spawnPos.X, spawnPos.Y); + TeleportTo(spawnPos.X, spawnPos.Y); } public int GetChampionHash() @@ -405,7 +401,7 @@ public int GetChampionHash() public bool LevelUp() { var stats = Stats; - var expMap = _game.Map.MapGameScript.ExpToLevelUp; + var expMap = _game.Map.MapProperties.ExpToLevelUp; if (stats.Level >= expMap.Count) { return false; @@ -426,9 +422,9 @@ public bool LevelUp() return true; } - public void OnKill(AttackableUnit killed) + public void OnKill(IAttackableUnit killed) { - if (killed is Minion) + if (killed is IMinion) { ChampStats.MinionsKilled += 1; if (killed.Team == TeamId.TEAM_NEUTRAL) @@ -436,7 +432,7 @@ public void OnKill(AttackableUnit killed) ChampStats.NeutralMinionsKilled += 1; } - var gold = _game.Map.MapGameScript.GetGoldFor(killed); + var gold = _game.Map.MapProperties.GetGoldFor(killed); if (gold <= 0) { return; @@ -467,11 +463,11 @@ public override void Die(IAttackableUnit killer) _game.PacketNotifier.NotifyUnitAnnounceEvent(UnitAnnounces.DEATH, this, killer); - var cKiller = killer as Champion; + var cKiller = killer as IChampion; if (cKiller == null && _championHitFlagTimer > 0) { - cKiller = _game.ObjectManager.GetObjectById(_playerHitId) as Champion; + cKiller = _game.ObjectManager.GetObjectById(_playerHitId) as IChampion; Logger.Debug("Killed by turret, minion or monster, but still give gold to the enemy."); } @@ -485,7 +481,7 @@ public override void Die(IAttackableUnit killer) cKiller.ChampStats.Kills += 1; // TODO: add assists - var gold = _game.Map.MapGameScript.GetGoldFor(this); + var gold = _game.Map.MapProperties.GetGoldFor(this); Logger.Debug($"Before: getGoldFromChamp: {gold} Killer: {cKiller.KillDeathCounter} Victim {KillDeathCounter}"); if (cKiller.KillDeathCounter < 0) @@ -506,17 +502,17 @@ public override void Die(IAttackableUnit killer) return; } - if (_game.Map.MapGameScript.IsKillGoldRewardReductionActive - && _game.Map.MapGameScript.HasFirstBloodHappened) + if (_game.Map.MapProperties.IsKillGoldRewardReductionActive + && _game.Map.MapProperties.HasFirstBloodHappened) { gold -= gold * 0.25f; //CORE_INFO("Still some minutes for full gold reward on champion kills"); } - if (!_game.Map.MapGameScript.HasFirstBloodHappened) + if (!_game.Map.MapProperties.HasFirstBloodHappened) { gold += 100; - _game.Map.MapGameScript.HasFirstBloodHappened = true; + _game.Map.MapProperties.HasFirstBloodHappened = true; } _game.PacketNotifier.NotifyChampionDie(this, cKiller, (int)gold); @@ -528,7 +524,7 @@ public override void Die(IAttackableUnit killer) _game.ObjectManager.StopTargeting(this); } - public override void OnCollision(GameObject collider) + public override void OnCollision(IGameObject collider) { base.OnCollision(collider); if (collider == null) @@ -553,8 +549,8 @@ public void UpdateSkin(int skinNo) public void SetSpell(string name, byte slot, bool enabled) { - Spells[slot] = new Spell(_game, this, name, (byte)slot); - Stats.SetSpellEnabled((byte)slot, enabled); + Spells[slot] = new Spell(_game, this, name, slot); + Stats.SetSpellEnabled(slot, enabled); } public void SwapSpells(byte slot1, byte slot2) @@ -569,7 +565,7 @@ public void SwapSpells(byte slot1, byte slot2) public void RemoveSpell(byte slot) { - ((ISpell)Spells[slot]).Deactivate(); + Spells[slot].Deactivate(); Spells[slot] = new Spell(_game, this, "BaseSpell", slot); // Replace previous spell with empty spell. Stats.SetSpellEnabled(slot, false); } diff --git a/GameServerLib/GameObjects/AttackableUnits/AI/LaneTurret.cs b/GameServerLib/GameObjects/AttackableUnits/AI/LaneTurret.cs index c80064563..4b6fa2dbf 100644 --- a/GameServerLib/GameObjects/AttackableUnits/AI/LaneTurret.cs +++ b/GameServerLib/GameObjects/AttackableUnits/AI/LaneTurret.cs @@ -6,7 +6,7 @@ namespace LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI { public class LaneTurret : BaseTurret, ILaneTurret { - public TurretType Type { get; private set; } + public TurretType Type { get; } private bool _turretHpUpdated; public LaneTurret( @@ -284,7 +284,7 @@ public override float GetMoveSpeed() return 0; } - public override void AutoAttackHit(AttackableUnit target) + public override void AutoAttackHit(IAttackableUnit target) { if (Type == TurretType.FOUNTAIN_TURRET) { diff --git a/GameServerLib/GameObjects/AttackableUnits/AI/Minion.cs b/GameServerLib/GameObjects/AttackableUnits/AI/Minion.cs index a6461ad63..b906be88c 100644 --- a/GameServerLib/GameObjects/AttackableUnits/AI/Minion.cs +++ b/GameServerLib/GameObjects/AttackableUnits/AI/Minion.cs @@ -14,12 +14,10 @@ public class Minion : ObjAiBase, IMinion /// protected List _mainWaypoints; protected int _curMainWaypoint; - public MinionSpawnPosition SpawnPosition { get; private set; } - public MinionSpawnType MinionSpawnType { get; protected set; } + public MinionSpawnPosition SpawnPosition { get; } + public MinionSpawnType MinionSpawnType { get; } protected bool _aiPaused; - private int HitBox => 60; - public Minion( Game game, MinionSpawnType spawnType, @@ -34,14 +32,14 @@ public Minion( _curMainWaypoint = 0; _aiPaused = false; - var spawnSpecifics = _game.Map.MapGameScript.GetMinionSpawnPosition(SpawnPosition); + var spawnSpecifics = _game.Map.MapProperties.GetMinionSpawnPosition(SpawnPosition); SetTeam(spawnSpecifics.Item1); SetPosition(spawnSpecifics.Item2.X, spawnSpecifics.Item2.Y); - _game.Map.MapGameScript.SetMinionStats(this); // Let the map decide how strong this minion has to be. + _game.Map.MapProperties.SetMinionStats(this); // Let the map decide how strong this minion has to be. // Set model - Model = _game.Map.MapGameScript.GetMinionModel(spawnSpecifics.Item1, spawnType); + Model = _game.Map.MapProperties.GetMinionModel(spawnSpecifics.Item1, spawnType); // Fix issues induced by having an empty model string CollisionRadius = _game.Config.ContentManager.GetCharData(Model).PathfindingCollisionRadius; @@ -115,21 +113,18 @@ protected bool ScanForTargets() { return true; } - AttackableUnit nextTarget = null; + IAttackableUnit nextTarget = null; var nextTargetPriority = 14; var objects = _game.ObjectManager.GetObjects(); foreach (var it in objects.OrderBy(x => GetDistanceTo(x.Value) - Stats.Range.Total))//Find target closest to max attack range. { - var u = it.Value as AttackableUnit; - - // Targets have to be: - if (u == null || // a unit - u.IsDead || // alive - u.Team == Team || // not on our team - GetDistanceTo(u) > DETECT_RANGE || // in range - !_game.ObjectManager.TeamHasVisionOn(Team, u)) // visible to this minion - continue; // If not, look for something else + if (!(it.Value is IAttackableUnit u) || + u.IsDead || + u.Team == Team || + GetDistanceTo(u) > DETECT_RANGE || + !_game.ObjectManager.TeamHasVisionOn(Team, u)) + continue; var priority = (int)ClassifyTarget(u); // get the priority. if (priority < nextTargetPriority) // if the priority is lower than the target we checked previously diff --git a/GameServerLib/GameObjects/AttackableUnits/AI/ObjAIBase.cs b/GameServerLib/GameObjects/AttackableUnits/AI/ObjAIBase.cs index 07dc7a1fc..7368aeeb2 100644 --- a/GameServerLib/GameObjects/AttackableUnits/AI/ObjAIBase.cs +++ b/GameServerLib/GameObjects/AttackableUnits/AI/ObjAIBase.cs @@ -21,37 +21,35 @@ namespace LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI { public class ObjAiBase : AttackableUnit, IObjAiBase { - private Buff[] AppliedBuffs { get; } + private IBuff[] AppliedBuffs { get; } private List BuffGameScriptControllers { get; } private object BuffsLock { get; } - private Dictionary Buffs { get; } + private Dictionary Buffs { get; } - private List _crowdControlList = new List(); + private List _crowdControlList = new List(); protected ItemManager _itemManager; protected CSharpScriptEngine _scriptEngine; /// /// Unit we want to attack as soon as in range /// - public AttackableUnit TargetUnit { get; set; } - public AttackableUnit AutoAttackTarget { get; set; } - public CharData CharData { get; protected set; } - public SpellData AaSpellData { get; protected set; } + public IAttackableUnit TargetUnit { get; set; } + public IAttackableUnit AutoAttackTarget { get; set; } + public CharData CharData { get; } + public ISpellData AaSpellData { get; } private bool _isNextAutoCrit; public float AutoAttackDelay { get; set; } public float AutoAttackProjectileSpeed { get; set; } private float _autoAttackCurrentCooldown; private float _autoAttackCurrentDelay; - public bool IsAttacking { protected get; set; } - protected internal bool HasMadeInitialAttack; + public bool IsAttacking { get; set; } + public bool HasMadeInitialAttack { get; set; } private bool _nextAttackFlag; private uint _autoAttackProjId; public MoveOrder MoveOrder { get; set; } public bool IsCastingSpell { get; set; } public bool IsMelee { get; set; } - - IAttackableUnit IObjAiBase.TargetUnit => TargetUnit; - IAttackableUnit IObjAiBase.AutoAttackTarget => AutoAttackTarget; + public bool IsDashing { get; protected set; } private Random _random = new Random(); @@ -62,7 +60,7 @@ public ObjAiBase(Game game, string model, Stats.Stats stats, int collisionRadius _itemManager = game.ItemManager; _scriptEngine = game.ScriptEngine; CharData = _game.Config.ContentManager.GetCharData(Model); - Stats.LoadStats(CharData); + stats.LoadStats(CharData); if (CharData.PathfindingCollisionRadius > 0) { @@ -93,10 +91,11 @@ public ObjAiBase(Game game, string model, Stats.Stats stats, int collisionRadius IsMelee = true; } - AppliedBuffs = new Buff[256]; + AppliedBuffs = new IBuff[256]; BuffGameScriptControllers = new List(); BuffsLock = new object(); - Buffs = new Dictionary(); + Buffs = new Dictionary(); + IsDashing = false; } public void AddBuffGameScript(string buffNamespace, string buffClass, ISpell ownerSpell, float removeAfter = -1f, bool isUnique = false) @@ -107,7 +106,7 @@ public void AddBuffGameScript(string buffNamespace, string buffClass, ISpell own } var buffController = - new BuffGameScriptController(_game, this, buffNamespace, buffClass, (Spell)ownerSpell, removeAfter); + new BuffGameScriptController(_game, this, buffNamespace, buffClass, ownerSpell, removeAfter); BuffGameScriptControllers.Add(buffController); buffController.ActivateBuff(); @@ -143,9 +142,9 @@ public List GetBuffGameScriptController() return BuffGameScriptControllers; } - public Dictionary GetBuffs() + public Dictionary GetBuffs() { - var toReturn = new Dictionary(); + var toReturn = new Dictionary(); lock (BuffsLock) { foreach (var buff in Buffs) @@ -163,7 +162,7 @@ public int GetBuffsCount() } //todo: use statmods - public Buff GetBuff(string name) + public IBuff GetBuff(string name) { lock (BuffsLock) { @@ -175,17 +174,17 @@ public Buff GetBuff(string name) } } - public void AddStatModifier(StatsModifier statModifier) + public void AddStatModifier(IStatsModifier statModifier) { Stats.AddModifier(statModifier); } - public void RemoveStatModifier(StatsModifier statModifier) + public void RemoveStatModifier(IStatsModifier statModifier) { Stats.RemoveModifier(statModifier); } - public void AddBuff(Buff b) + public void AddBuff(IBuff b) { lock (BuffsLock) { @@ -195,12 +194,12 @@ public void AddBuff(Buff b) } else { - Buffs[b.Name].TimeElapsed = 0; // if buff already exists, just restart its timer + Buffs[b.Name].ResetDuration(); // if buff already exists, just restart its timer } } } - public void RemoveBuff(Buff b) + public void RemoveBuff(IBuff b) { //TODO add every stat RemoveBuff(b.Name); @@ -215,20 +214,20 @@ public void RemoveBuff(string b) } } - public byte GetNewBuffSlot(Buff b) + public byte GetNewBuffSlot(IBuff b) { var slot = GetBuffSlot(); AppliedBuffs[slot] = b; return slot; } - public void RemoveBuffSlot(Buff b) + public void RemoveBuffSlot(IBuff b) { var slot = GetBuffSlot(b); AppliedBuffs[slot] = null; } - public void ApplyCrowdControl(UnitCrowdControl cc) + public void ApplyCrowdControl(ICrowdControl cc) { if (cc.IsTypeOf(CrowdControlType.STUN) || cc.IsTypeOf(CrowdControlType.ROOT)) { @@ -238,7 +237,7 @@ public void ApplyCrowdControl(UnitCrowdControl cc) _crowdControlList.Add(cc); } - public void RemoveCrowdControl(UnitCrowdControl cc) + public void RemoveCrowdControl(ICrowdControl cc) { _crowdControlList.Remove(cc); } @@ -284,89 +283,67 @@ public virtual void RefreshWaypoints() } } - public ClassifyUnit ClassifyTarget(AttackableUnit target) + public ClassifyUnit ClassifyTarget(IAttackableUnit target) { - if (target is ObjAiBase ai) + if (target is IObjAiBase ai && ai.TargetUnit != null && ai.TargetUnit.IsInDistress()) // If an ally is in distress, target this unit. (Priority 1~5) { - if (ai.TargetUnit != null && ai.TargetUnit.IsInDistress()) // If an ally is in distress, target this unit. (Priority 1~5) + switch (target) { - if (target is Champion && ai.TargetUnit is Champion) // If it's a champion attacking an allied champion - { + // If it's a champion attacking an allied champion + case IChampion _ when ai.TargetUnit is IChampion: return ClassifyUnit.CHAMPION_ATTACKING_CHAMPION; - } - - if (target is Minion && ai.TargetUnit is Champion) // If it's a minion attacking an allied champion. - { + // If it's a minion attacking an allied champion. + case IMinion _ when ai.TargetUnit is IChampion: return ClassifyUnit.MINION_ATTACKING_CHAMPION; - } - - if (target is Minion && ai.TargetUnit is Minion) // Minion attacking minion - { + // Minion attacking minion + case IMinion _ when ai.TargetUnit is IMinion: return ClassifyUnit.MINION_ATTACKING_MINION; - } - - if (target is BaseTurret && ai.TargetUnit is Minion) // Turret attacking minion - { + // Turret attacking minion + case IBaseTurret _ when ai.TargetUnit is IMinion: return ClassifyUnit.TURRET_ATTACKING_MINION; - } - - if (target is Champion && ai.TargetUnit is Minion) // Champion attacking minion - { + // Champion attacking minion + case IChampion _ when ai.TargetUnit is IMinion: return ClassifyUnit.CHAMPION_ATTACKING_MINION; - } - } - } - - if (target is Placeable) - { - return ClassifyUnit.PLACEABLE; - } - - if (target is Minion m) - { - switch (m.MinionSpawnType) - { - case MinionSpawnType.MINION_TYPE_MELEE: - return ClassifyUnit.MELEE_MINION; - case MinionSpawnType.MINION_TYPE_CASTER: - return ClassifyUnit.CASTER_MINION; - case MinionSpawnType.MINION_TYPE_CANNON: - case MinionSpawnType.MINION_TYPE_SUPER: - return ClassifyUnit.SUPER_OR_CANNON_MINION; } } - - if (target is BaseTurret) - { - return ClassifyUnit.TURRET; - } - - if (target is Champion) + + switch (target) { - return ClassifyUnit.CHAMPION; - } - - if (target is Inhibitor && !target.IsDead) - { - return ClassifyUnit.INHIBITOR; - } + case IPlaceable _: + return ClassifyUnit.PLACEABLE; + case IMinion m: + switch (m.MinionSpawnType) + { + case MinionSpawnType.MINION_TYPE_MELEE: + return ClassifyUnit.MELEE_MINION; + case MinionSpawnType.MINION_TYPE_CASTER: + return ClassifyUnit.CASTER_MINION; + case MinionSpawnType.MINION_TYPE_CANNON: + case MinionSpawnType.MINION_TYPE_SUPER: + return ClassifyUnit.SUPER_OR_CANNON_MINION; + } - if (target is Nexus) - { - return ClassifyUnit.NEXUS; + break; + case IBaseTurret _: + return ClassifyUnit.TURRET; + case IChampion _: + return ClassifyUnit.CHAMPION; + case IInhibitor _ when !target.IsDead: + return ClassifyUnit.INHIBITOR; + case INexus _: + return ClassifyUnit.NEXUS; } return ClassifyUnit.DEFAULT; } - - public void SetTargetUnit(AttackableUnit target) + public void SetTargetUnit(IAttackableUnit target) { TargetUnit = target; RefreshWaypoints(); } - private byte GetBuffSlot(Buff buffToLookFor = null) + private byte GetBuffSlot(IBuff buffToLookFor = null) { for (byte i = 1; i < AppliedBuffs.Length; i++) // Find the first open slot or the slot corresponding to buff { @@ -382,7 +359,7 @@ private byte GetBuffSlot(Buff buffToLookFor = null) /// /// This is called by the AA projectile when it hits its target /// - public virtual void AutoAttackHit(AttackableUnit target) + public virtual void AutoAttackHit(IAttackableUnit target) { if (HasCrowdControl(CrowdControlType.BLIND)) { @@ -398,7 +375,7 @@ public virtual void AutoAttackHit(AttackableUnit target) damage *= Stats.CriticalDamage.Total; } - var onAutoAttack = _scriptEngine.GetStaticMethod>(Model, "Passive", "OnAutoAttack"); + var onAutoAttack = _scriptEngine.GetStaticMethod>(Model, "Passive", "OnAutoAttack"); onAutoAttack?.Invoke(this, target); target.TakeDamage(this, damage, DamageType.DAMAGE_TYPE_PHYSICAL, @@ -540,7 +517,7 @@ public override void Update(float diff) _crowdControlList.RemoveAll(cc => cc.IsRemoved); - var onUpdate = _scriptEngine.GetStaticMethod>(Model, "Passive", "OnUpdate"); + var onUpdate = _scriptEngine.GetStaticMethod>(Model, "Passive", "OnUpdate"); onUpdate?.Invoke(this, diff); BuffGameScriptControllers.RemoveAll(b => b.NeedsRemoved()); base.Update(diff); @@ -549,23 +526,23 @@ public override void Update(float diff) public override void Die(IAttackableUnit killer) { - var onDie = _scriptEngine.GetStaticMethod>(Model, "Passive", "OnDie"); + var onDie = _scriptEngine.GetStaticMethod>(Model, "Passive", "OnDie"); onDie?.Invoke(this, killer); base.Die(killer); } - public override void OnCollision(GameObject collider) + public override void OnCollision(IGameObject collider) { base.OnCollision(collider); if (collider == null) { - var onCollideWithTerrain = _scriptEngine.GetStaticMethod>(Model, "Passive", "onCollideWithTerrain"); + var onCollideWithTerrain = _scriptEngine.GetStaticMethod>(Model, "Passive", "onCollideWithTerrain"); onCollideWithTerrain?.Invoke(this); } else { - var onCollide = _scriptEngine.GetStaticMethod>(Model, "Passive", "onCollide"); - onCollide?.Invoke(this, collider as AttackableUnit); + var onCollide = _scriptEngine.GetStaticMethod>(Model, "Passive", "onCollide"); + onCollide?.Invoke(this, collider as IAttackableUnit); } } @@ -576,14 +553,14 @@ public bool RecalculateAttackPosition() return false; } var objects = _game.ObjectManager.GetObjects(); - List UsedPositions = new List(); + List usedPositions = new List(); var isCurrentlyOverlapping = false; - var thisCollisionCircle = new CirclePoly(((Target)Target)?.GetPosition() ?? GetPosition(), CollisionRadius + 10); + var thisCollisionCircle = new CirclePoly(Target?.GetPosition() ?? GetPosition(), CollisionRadius + 10); foreach (var gameObject in objects) { - var unit = gameObject.Value as AttackableUnit; + var unit = gameObject.Value as IAttackableUnit; if (unit == null || unit.NetId == NetId || unit.IsDead || @@ -593,35 +570,34 @@ public bool RecalculateAttackPosition() { continue; } - var targetCollisionCircle = new CirclePoly(((Target)unit.Target)?.GetPosition() ?? unit.GetPosition(), unit.CollisionRadius + 10); + var targetCollisionCircle = new CirclePoly(unit.Target?.GetPosition() ?? unit.GetPosition(), unit.CollisionRadius + 10); if (targetCollisionCircle.CheckForOverLaps(thisCollisionCircle)) { isCurrentlyOverlapping = true; } - UsedPositions.Add(targetCollisionCircle); + usedPositions.Add(targetCollisionCircle); } if (isCurrentlyOverlapping) { - var targetCircle = new CirclePoly(((Target)TargetUnit.Target)?.GetPosition() ?? TargetUnit.GetPosition(), Stats.Range.Total, 72); + var targetCircle = new CirclePoly(TargetUnit.Target?.GetPosition() ?? TargetUnit.GetPosition(), Stats.Range.Total, 72); //Find optimal position... foreach (var point in targetCircle.Points.OrderBy(x => GetDistanceTo(X, Y))) { - if (_game.Map.NavGrid.IsWalkable(point)) + if (!_game.Map.NavGrid.IsWalkable(point)) + continue; + var positionUsed = false; + foreach (var circlePoly in usedPositions) { - var positionUsed = false; - foreach (var circlePoly in UsedPositions) - { - if (circlePoly.CheckForOverLaps(new CirclePoly(point, CollisionRadius + 10, 20))) - { - positionUsed = true; - } - } - if (!positionUsed) + if (circlePoly.CheckForOverLaps(new CirclePoly(point, CollisionRadius + 10, 20))) { - SetWaypoints(new List { GetPosition(), point }); - return true; + positionUsed = true; } } + + if (positionUsed) + continue; + SetWaypoints(new List { GetPosition(), point }); + return true; } } return false; @@ -651,7 +627,20 @@ public void TeleportTo(float x, float y) public void UpdateTargetUnit(IAttackableUnit unit) { - TargetUnit = (AttackableUnit)unit; + TargetUnit = unit; + } + + public void DashToTarget(ITarget t, float dashSpeed, float followTargetMaxDistance, float backDistance, float travelTime) + { + // TODO: Take into account the rest of the arguments + IsDashing = true; + Target = t; + Waypoints.Clear(); + } + + public void SetDashingState(bool state) + { + IsDashing = state; } } } diff --git a/GameServerLib/GameObjects/AttackableUnits/AttackableUnit.cs b/GameServerLib/GameObjects/AttackableUnits/AttackableUnit.cs index e740cebc9..ed5250802 100644 --- a/GameServerLib/GameObjects/AttackableUnits/AttackableUnit.cs +++ b/GameServerLib/GameObjects/AttackableUnits/AttackableUnit.cs @@ -16,36 +16,23 @@ public class AttackableUnit : GameObject, IAttackableUnit internal const float DETECT_RANGE = 475.0f; internal const int EXP_RANGE = 1400; - public Stats.Stats Stats { get; protected set; } + public IStats Stats { get; protected set; } private float _statUpdateTimer; public bool IsModelUpdated { get; set; } public bool IsDead { get; protected set; } - private string _model; - public string Model - { - get => _model; - set - { - _model = value; - IsModelUpdated = true; - } - } + public string Model { get; protected set; } protected readonly ILog Logger; - public InventoryManager Inventory { get; protected set; } - public int KillDeathCounter { get; protected set; } + public IInventoryManager Inventory { get; protected set; } + public int KillDeathCounter { get; set; } public int MinionCounter { get; protected set; } - public Replication Replication { get; protected set; } - - IReplication IAttackableUnit.Replication => Replication; - IStats IAttackableUnit.Stats => Stats; - IInventoryManager IAttackableUnit.Inventory => Inventory; + public IReplication Replication { get; protected set; } public AttackableUnit( Game game, string model, - Stats.Stats stats, + IStats stats, int collisionRadius = 40, float x = 0, float y = 0, @@ -98,7 +85,7 @@ public virtual void Die(IAttackableUnit killer) _game.PacketNotifier.NotifyNpcDie(this, killer); - var exp = _game.Map.MapGameScript.GetExperienceFor(this); + var exp = _game.Map.MapProperties.GetExperienceFor(this); var champs = _game.ObjectManager.GetChampionsInRange(this, EXP_RANGE, true); //Cull allied champions champs.RemoveAll(l => l.Team == Team); @@ -113,11 +100,8 @@ public virtual void Die(IAttackableUnit killer) } } - if ((killer != null) && (killer is Champion)) - { - ((Champion)killer).OnKill(this); - } - IsDashing = false; + if (killer != null && killer is IChampion champion) + champion.OnKill(this); } public virtual bool IsInDistress() @@ -125,6 +109,15 @@ public virtual bool IsInDistress() return false; //return DistressCause; } + public bool ChangeModel(string model) + { + if (Model.Equals(model)) + return false; + IsModelUpdated = true; + Model = model; + return true; + } + public virtual void TakeDamage(IAttackableUnit attacker, float damage, DamageType type, DamageSource source, DamageText damageText) { diff --git a/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/Inhibitor.cs b/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/Inhibitor.cs index f7d6d307f..f76073f5f 100644 --- a/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/Inhibitor.cs +++ b/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/Inhibitor.cs @@ -45,7 +45,7 @@ public override void Die(IAttackableUnit killer) var objects = _game.ObjectManager.GetObjects().Values; foreach (var obj in objects) { - var u = obj as ObjAiBase; + var u = obj as IObjAiBase; if (u != null && u.TargetUnit == this) { u.SetTargetUnit(null); @@ -68,7 +68,7 @@ public override void Die(IAttackableUnit killer) _respawnTimer.Start(); _timerStartTime = DateTime.Now; - if (killer is Champion c) + if (killer is IChampion c) { c.Stats.Gold += GOLD_WORTH; _game.PacketNotifier.NotifyAddGold(c, this, GOLD_WORTH); diff --git a/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/Nexus.cs b/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/Nexus.cs index 64a7ad272..60e52a83c 100644 --- a/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/Nexus.cs +++ b/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/Nexus.cs @@ -24,7 +24,7 @@ public Nexus( public override void Die(IAttackableUnit killer) { - var cameraPosition = _game.Map.MapGameScript.GetEndGameCameraPosition(Team); + var cameraPosition = _game.Map.MapProperties.GetEndGameCameraPosition(Team); _game.Stop(); _game.PacketNotifier.NotifyGameEnd(cameraPosition, this, _game.PlayerManager.GetPlayers()); _game.SetGameToExit(); diff --git a/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/ObjAnimatedBuilding.cs b/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/ObjAnimatedBuilding.cs index 1ba54385a..216a85d7d 100644 --- a/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/ObjAnimatedBuilding.cs +++ b/GameServerLib/GameObjects/AttackableUnits/Buildings/AnimatedBuildings/ObjAnimatedBuilding.cs @@ -5,7 +5,7 @@ namespace LeagueSandbox.GameServer.GameObjects.AttackableUnits.Buildings.Animate { public class ObjAnimatedBuilding : ObjBuilding, IObjAnimatedBuilding { - public ObjAnimatedBuilding(Game game, string model, Stats.Stats stats, int collisionRadius = 40, + public ObjAnimatedBuilding(Game game, string model, IStats stats, int collisionRadius = 40, float x = 0, float y = 0, int visionRadius = 0, uint netId = 0) : base(game, model, stats, collisionRadius, x, y, visionRadius, netId) { diff --git a/GameServerLib/GameObjects/AttackableUnits/Buildings/ObjBuilding.cs b/GameServerLib/GameObjects/AttackableUnits/Buildings/ObjBuilding.cs index 5ab3bc922..c7c931cef 100644 --- a/GameServerLib/GameObjects/AttackableUnits/Buildings/ObjBuilding.cs +++ b/GameServerLib/GameObjects/AttackableUnits/Buildings/ObjBuilding.cs @@ -4,7 +4,7 @@ namespace LeagueSandbox.GameServer.GameObjects.AttackableUnits.Buildings { public class ObjBuilding : AttackableUnit, IObjBuilding { - public ObjBuilding(Game game, string model, Stats.Stats stats, int collisionRadius = 40, + public ObjBuilding(Game game, string model, IStats stats, int collisionRadius = 40, float x = 0, float y = 0, int visionRadius = 0, uint netId = 0) : base(game, model, stats, collisionRadius, x, y, visionRadius, netId) { diff --git a/GameServerLib/GameObjects/GameObject.cs b/GameServerLib/GameObjects/GameObject.cs index 0b3913801..3f737c0bb 100644 --- a/GameServerLib/GameObjects/GameObject.cs +++ b/GameServerLib/GameObjects/GameObject.cs @@ -13,18 +13,14 @@ namespace LeagueSandbox.GameServer.GameObjects { public class GameObject : Target, IGameObject { - public uint NetId { get; private set; } - protected float _xvector, _yvector; - - /// - /// Current target the object running to (can be coordinates or an object) - /// - public ITarget Target { get; set; } + protected bool _movementUpdated; + protected bool _toRemove; + public uint NetId { get; } public List Waypoints { get; private set; } public int CurWaypoint { get; private set; } + public TeamId Team { get; protected set; } - public void SetTeam(TeamId team) { _visibleByTeam[Team] = false; @@ -32,24 +28,22 @@ public void SetTeam(TeamId team) _visibleByTeam[Team] = true; if (_game.IsRunning) { - _game.PacketNotifier.NotifySetTeam(this as AttackableUnit, team); + _game.PacketNotifier.NotifySetTeam(this as IAttackableUnit, team); } } - protected bool _movementUpdated; - protected bool _toRemove; - public int AttackerCount { get; private set; } public float CollisionRadius { get; set; } - protected Vector2 _direction; public float VisionRadius { get; protected set; } - public bool IsDashing { get; protected set; } public override bool IsSimpleTarget => false; - protected float _dashSpeed; + protected Vector2 _direction; private Dictionary _visibleByTeam; protected Game _game; protected NetworkIdManager _networkIdManager; - ITarget IGameObject.Target => Target; + /// + /// Current target the object running to (can be coordinates or an object) + /// + public ITarget Target { get; set; } public GameObject(Game game, float x, float y, int collisionRadius, int visionRadius = 0, uint netId = 0) : base(x, y) { @@ -78,8 +72,6 @@ public GameObject(Game game, float x, float y, int collisionRadius, int visionRa Team = TeamId.TEAM_NEUTRAL; _movementUpdated = false; _toRemove = false; - AttackerCount = 0; - IsDashing = false; } public virtual void OnAdded() @@ -92,7 +84,7 @@ public virtual void OnRemoved() _game.Map.CollisionHandler.RemoveObject(this); } - public virtual void OnCollision(GameObject collider) + public virtual void OnCollision(IGameObject collider) { } @@ -129,10 +121,6 @@ public void Move(float diff, Vector2 to) } var moveSpeed = GetMoveSpeed(); - if (IsDashing) - { - moveSpeed = _dashSpeed; - } var deltaMovement = moveSpeed * 0.001f * diff; @@ -146,24 +134,12 @@ public void Move(float diff, Vector2 to) if (GetDistanceTo(Target) < deltaMovement * 2) { - if (this is Projectile && !Target.IsSimpleTarget) + if (this is IProjectile && !Target.IsSimpleTarget) { return; } - - if (IsDashing) - { - if (this is AttackableUnit) - { - var u = this as AttackableUnit; - - var animList = new List(); - _game.PacketNotifier.NotifySetAnimation(u, animList); - } - - Target = null; - } - else if (++CurWaypoint >= Waypoints.Count) + + if (++CurWaypoint >= Waypoints.Count) { Target = null; } @@ -171,27 +147,7 @@ public void Move(float diff, Vector2 to) { Target = new Target(Waypoints[CurWaypoint]); } - - if (IsDashing) - { - IsDashing = false; - } - } - } - - public void CalculateVector(float xtarget, float ytarget) - { - _xvector = xtarget - X; - _yvector = ytarget - Y; - - if (_xvector == 0 && _yvector == 0) - { - return; } - - var toDivide = Math.Abs(_xvector) + Math.Abs(_yvector); - _xvector /= toDivide; - _yvector /= toDivide; } public virtual void Update(float diff) @@ -260,20 +216,11 @@ public virtual float GetZ() return _game.Map.NavGrid.GetHeightAtLocation(X, Y); } - public bool IsCollidingWith(GameObject o) + public bool IsCollidingWith(IGameObject o) { return GetDistanceToSqr(o) < (CollisionRadius + o.CollisionRadius) * (CollisionRadius + o.CollisionRadius); } - public void IncrementAttackerCount() - { - ++AttackerCount; - } - public void DecrementAttackerCount() - { - --AttackerCount; - } - public bool IsVisibleByTeam(TeamId team) { return team == Team || _visibleByTeam[team]; @@ -283,25 +230,11 @@ public void SetVisibleByTeam(TeamId team, bool visible) { _visibleByTeam[team] = visible; - if (this is AttackableUnit) + if (this is IAttackableUnit) { // TODO: send this in one place only - _game.PacketNotifier.NotifyUpdatedStats(this as AttackableUnit, false); + _game.PacketNotifier.NotifyUpdatedStats(this as IAttackableUnit, false); } } - - public void DashToTarget(Target t, float dashSpeed, float followTargetMaxDistance, float backDistance, float travelTime) - { - // TODO: Take into account the rest of the arguments - IsDashing = true; - _dashSpeed = dashSpeed; - Target = t; - Waypoints.Clear(); - } - - public void SetDashingState(bool state) - { - IsDashing = state; - } } } diff --git a/GameServerLib/GameObjects/LevelProp.cs b/GameServerLib/GameObjects/LevelProp.cs index e8fb0330a..7c8229538 100644 --- a/GameServerLib/GameObjects/LevelProp.cs +++ b/GameServerLib/GameObjects/LevelProp.cs @@ -5,15 +5,15 @@ namespace LeagueSandbox.GameServer.GameObjects { public class LevelProp : GameObject, ILevelProp { - public string Name { get; private set; } - public string Model { get; private set; } - public float Z { get; private set; } - public float DirX { get; private set; } - public float DirY { get; private set; } - public float DirZ { get; private set; } - public float Unk1 { get; private set; } - public float Unk2 { get; private set; } - public byte SkinId { get; private set; } + public string Name { get; } + public string Model { get; } + public float Z { get; } + public float DirX { get; } + public float DirY { get; } + public float DirZ { get; } + public float Unk1 { get; } + public float Unk2 { get; } + public byte SkinId { get; } public LevelProp( Game game, diff --git a/GameServerLib/GameObjects/Missiles/Cone.cs b/GameServerLib/GameObjects/Missiles/Cone.cs index 893d49de5..e230b6d2a 100644 --- a/GameServerLib/GameObjects/Missiles/Cone.cs +++ b/GameServerLib/GameObjects/Missiles/Cone.cs @@ -1,5 +1,7 @@ using System; using System.Numerics; +using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; using GameServerCore.Enums; using LeagueSandbox.GameServer.Content; using LeagueSandbox.GameServer.GameObjects.AttackableUnits; @@ -25,9 +27,9 @@ public Cone( float x, float y, int collisionRadius, - AttackableUnit owner, - Target target, - Spell originSpell, + IAttackableUnit owner, + ITarget target, + ISpell originSpell, string effectName, int flags, bool affectAsCastIsOver, @@ -53,7 +55,7 @@ public override void Update(float diff) var objects = _game.ObjectManager.GetObjects().Values; foreach (var obj in objects) { - var u = obj as AttackableUnit; + var u = obj as IAttackableUnit; if (u != null && CheckIfValidTarget(u)) { if (TargetIsInCone(u)) @@ -67,89 +69,7 @@ public override void Update(float diff) } } - public override void SetToRemove() - { - if (Target != null && !Target.IsSimpleTarget) - { - (Target as GameObject).DecrementAttackerCount(); - } - - Owner.DecrementAttackerCount(); - base.SetToRemove(); - _game.PacketNotifier.NotifyProjectileDestroy(this); - } - - private bool CheckIfValidTarget(AttackableUnit unit) - { - if (!Target.IsSimpleTarget) - { - return false; - } - - if (unit == null || ObjectsHit.Contains(unit)) - { - return false; - } - - if (unit.Team == Owner.Team - && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_FRIENDS) > 0)) - { - return false; - } - - if (unit.Team == TeamId.TEAM_NEUTRAL - && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_NEUTRAL) > 0)) - { - return false; - } - - if (unit.Team != Owner.Team - && unit.Team != TeamId.TEAM_NEUTRAL - && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_ENEMIES) > 0)) - { - return false; - } - - if (unit.IsDead && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_DEAD) > 0)) - { - return false; - } - - var m = unit as Minion; - if (m != null && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_MINIONS) > 0)) - { - return false; - } - - var p = unit as Placeable; - if (p != null && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_USEABLE) > 0)) - { - return false; - } - - var t = unit as BaseTurret; - if (t != null && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_TURRETS) > 0)) - { - return false; - } - - var i = unit as Inhibitor; - var n = unit as Nexus; - if ((i != null || n != null) && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_BUILDINGS) > 0)) - { - return false; - } - - var c = unit as Champion; - if (c != null && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_HEROES) > 0)) - { - return false; - } - - return true; - } - - private void ApplyEffects(AttackableUnit unit) + private void ApplyEffects(IAttackableUnit unit) { ObjectsHit.Add(unit); var attackableUnit = unit; @@ -159,7 +79,7 @@ private void ApplyEffects(AttackableUnit unit) } } - private void CreateCone(Target beginPoint, Target endPoint) + private void CreateCone(ITarget beginPoint, ITarget endPoint) { var beginCoords = new Vector2(beginPoint.X, beginPoint.Y); var trueEndCoords = new Vector2(endPoint.X, endPoint.Y); @@ -174,14 +94,14 @@ private void CreateCone(Target beginPoint, Target endPoint) _radius = distance; } - private bool TargetIsInCone(AttackableUnit target) + private bool TargetIsInCone(IAttackableUnit target) { var unitCoords = new Vector2(target.X, target.Y); var targetDistance = Vector2.Distance(_ownerCoords, unitCoords); float targetAngle = (float)Math.Acos((target.X - _ownerCoords.X) / targetDistance); - return (targetDistance <= _radius) && (targetAngle >= _beginAngle) && (targetAngle <= _endAngle); + return targetDistance <= _radius && targetAngle >= _beginAngle && targetAngle <= _endAngle; } } diff --git a/GameServerLib/GameObjects/Missiles/Laser.cs b/GameServerLib/GameObjects/Missiles/Laser.cs index f5672e87c..7b0c8b368 100644 --- a/GameServerLib/GameObjects/Missiles/Laser.cs +++ b/GameServerLib/GameObjects/Missiles/Laser.cs @@ -1,6 +1,8 @@ using System; using System.Numerics; using GameServerCore; +using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; using GameServerCore.Enums; using LeagueSandbox.GameServer.Content; using LeagueSandbox.GameServer.GameObjects.AttackableUnits; @@ -24,9 +26,9 @@ public Laser( float x, float y, int collisionRadius, - AttackableUnit owner, - Target target, - Spell originSpell, + IAttackableUnit owner, + ITarget target, + ISpell originSpell, string effectName, int flags, bool affectAsCastIsOver) : base(game, x, y, collisionRadius, owner, target, originSpell, 0, effectName, flags) @@ -48,7 +50,7 @@ public override void Update(float diff) var objects = _game.ObjectManager.GetObjects().Values; foreach (var obj in objects) { - var u = obj as AttackableUnit; + var u = obj as IAttackableUnit; if (u != null && CheckIfValidTarget(u)) { if (TargetIsInRectangle(u)) @@ -62,95 +64,18 @@ public override void Update(float diff) } } - public override void SetToRemove() + /*public override void SetToRemove() { - if (Target != null && !Target.IsSimpleTarget) - { - (Target as GameObject).DecrementAttackerCount(); - } - - Owner.DecrementAttackerCount(); base.SetToRemove(); _game.PacketNotifier.NotifyProjectileDestroy(this); - } - - private bool CheckIfValidTarget(AttackableUnit unit) - { - if (!Target.IsSimpleTarget) - { - return false; - } - - if (unit == null || ObjectsHit.Contains(unit)) - { - return false; - } - - if (unit.Team == Owner.Team - && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_FRIENDS) > 0)) - { - return false; - } - - if (unit.Team == TeamId.TEAM_NEUTRAL - && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_NEUTRAL) > 0)) - { - return false; - } - - if (unit.Team != Owner.Team - && unit.Team != TeamId.TEAM_NEUTRAL - && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_ENEMIES) > 0)) - { - return false; - } - - if (unit.IsDead && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_DEAD) > 0)) - { - return false; - } - - var m = unit as Minion; - if (m != null && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_MINIONS) > 0)) - { - return false; - } - - var p = unit as Placeable; - if (p != null && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_USEABLE) > 0)) - { - return false; - } - - var t = unit as BaseTurret; - if (t != null && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_TURRETS) > 0)) - { - return false; - } - - var i = unit as Inhibitor; - var n = unit as Nexus; - if ((i != null || n != null) && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_BUILDINGS) > 0)) - { - return false; - } - - var c = unit as Champion; - if (c != null && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_HEROES) > 0)) - { - return false; - } - - return true; - } + }*/ - private void ApplyEffects(AttackableUnit unit) + private void ApplyEffects(IAttackableUnit unit) { ObjectsHit.Add(unit); - var attackableUnit = unit; - if (attackableUnit != null) + if (unit != null) { - _originSpell.ApplyEffects(attackableUnit, this); + _originSpell.ApplyEffects(unit, this); } } @@ -162,7 +87,7 @@ private void ApplyEffects(AttackableUnit unit) /// /// Assigns this 's corners to form a rectangle. /// - private void CreateRectangle(Target beginPoint, Target endPoint) + private void CreateRectangle(ITarget beginPoint, ITarget endPoint) { var beginCoords = new Vector2(beginPoint.X, beginPoint.Y); var trueEndCoords = new Vector2(endPoint.X, endPoint.Y); @@ -186,7 +111,7 @@ private void CreateRectangle(Target beginPoint, Target endPoint) /// /// Target to be checked /// true if target is in rectangle, otherwise false. - private bool TargetIsInRectangle(AttackableUnit target) + private bool TargetIsInRectangle(IAttackableUnit target) { var unitCoords = new Vector2(target.X, target.Y); diff --git a/GameServerLib/GameObjects/Missiles/Projectile.cs b/GameServerLib/GameObjects/Missiles/Projectile.cs index d009cf9b1..e875f9125 100644 --- a/GameServerLib/GameObjects/Missiles/Projectile.cs +++ b/GameServerLib/GameObjects/Missiles/Projectile.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -using System.Linq; using GameServerCore.Content; +using GameServerCore.Domain; using GameServerCore.Domain.GameObjects; using GameServerCore.Enums; using LeagueSandbox.GameServer.Content; @@ -8,31 +8,27 @@ using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; using LeagueSandbox.GameServer.GameObjects.AttackableUnits.Buildings.AnimatedBuildings; using LeagueSandbox.GameServer.GameObjects.Other; -using LeagueSandbox.GameServer.GameObjects.Spells; namespace LeagueSandbox.GameServer.GameObjects.Missiles { public class Projectile : ObjMissile, IProjectile { - public List ObjectsHit { get; private set; } - public AttackableUnit Owner { get; private set; } - public int ProjectileId { get; private set; } - public SpellData SpellData { get; protected set; } - - List IProjectile.ObjectsHit => ObjectsHit.Cast().ToList(); - IAttackableUnit IProjectile.Owner => Owner; + public List ObjectsHit { get; } + public IAttackableUnit Owner { get; } + public int ProjectileId { get; } + public ISpellData SpellData { get; protected set; } protected float _moveSpeed; - protected Spell _originSpell; + protected ISpell _originSpell; public Projectile( Game game, float x, float y, int collisionRadius, - AttackableUnit owner, - Target target, - Spell originSpell, + IAttackableUnit owner, + ITarget target, + ISpell originSpell, float moveSpeed, string projectileName, int flags = 0, @@ -49,16 +45,9 @@ public Projectile( { VisionRadius = SpellData.MissilePerceptionBubbleRadius; } - ObjectsHit = new List(); + ObjectsHit = new List(); Target = target; - - if (!target.IsSimpleTarget) - { - ((GameObject)target).IncrementAttackerCount(); - } - - owner.IncrementAttackerCount(); } public override void Update(float diff) @@ -72,18 +61,18 @@ public override void Update(float diff) base.Update(diff); } - public override void OnCollision(GameObject collider) + public override void OnCollision(IGameObject collider) { base.OnCollision(collider); if (Target != null && Target.IsSimpleTarget && !IsToRemove()) { - CheckFlagsForUnit(collider as AttackableUnit); + CheckFlagsForUnit(collider as IAttackableUnit); } else { if (Target == collider) { - CheckFlagsForUnit(collider as AttackableUnit); + CheckFlagsForUnit(collider as IAttackableUnit); } } } @@ -93,7 +82,8 @@ public override float GetMoveSpeed() return _moveSpeed; } - protected virtual void CheckFlagsForUnit(AttackableUnit unit) + // todo refactor this + protected virtual void CheckFlagsForUnit(IAttackableUnit unit) { if (Target == null) { @@ -102,60 +92,8 @@ protected virtual void CheckFlagsForUnit(AttackableUnit unit) if (Target.IsSimpleTarget) { // Skillshot - if (unit == null || ObjectsHit.Contains(unit)) - { - return; - } - - if (unit.Team == Owner.Team - && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_FRIENDS) > 0)) - { - return; - } - - if (unit.Team == TeamId.TEAM_NEUTRAL - && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_NEUTRAL) > 0)) - { - return; - } - - if (unit.Team != Owner.Team - && unit.Team != TeamId.TEAM_NEUTRAL - && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_ENEMIES) > 0)) - { - return; - } - - - if (unit.IsDead && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_DEAD) > 0)) - { - return; - } - - if (unit is Minion m && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_MINIONS) > 0)) - { - return; - } - - if (unit is Placeable p && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_USEABLE) > 0)) - { - return; - } - - if (unit is BaseTurret t && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_TURRETS) > 0)) - { + if (!CheckIfValidTarget(unit)) return; - } - - if ((unit is Inhibitor i || unit is Nexus n) && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_BUILDINGS) > 0)) - { - return; - } - - if (unit is Champion c && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_HEROES) > 0)) - { - return; - } ObjectsHit.Add(unit); var attackableUnit = unit; @@ -166,7 +104,7 @@ protected virtual void CheckFlagsForUnit(AttackableUnit unit) } else { - if (Target is AttackableUnit u) + if (Target is IAttackableUnit u) { // Autoguided spell if (_originSpell != null) { @@ -174,7 +112,7 @@ protected virtual void CheckFlagsForUnit(AttackableUnit unit) } else { // auto attack - if (Owner is ObjAiBase ai) + if (Owner is IObjAiBase ai) { ai.AutoAttackHit(u); } @@ -186,14 +124,55 @@ protected virtual void CheckFlagsForUnit(AttackableUnit unit) public override void SetToRemove() { - if (Target != null && !Target.IsSimpleTarget) + base.SetToRemove(); + _game.PacketNotifier.NotifyProjectileDestroy(this); + } + + protected bool CheckIfValidTarget(IAttackableUnit unit) + { + if (!Target.IsSimpleTarget || unit == null || ObjectsHit.Contains(unit)) { - (Target as GameObject)?.DecrementAttackerCount(); + return false; } - Owner.DecrementAttackerCount(); - base.SetToRemove(); - _game.PacketNotifier.NotifyProjectileDestroy(this); + if (unit.Team == Owner.Team + && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_FRIENDS) > 0)) + { + return false; + } + + if (unit.Team == TeamId.TEAM_NEUTRAL + && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_NEUTRAL) > 0)) + { + return false; + } + + if (unit.Team != Owner.Team + && unit.Team != TeamId.TEAM_NEUTRAL + && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_ENEMIES) > 0)) + { + return false; + } + + if (unit.IsDead && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_DEAD) > 0)) + { + return false; + } + + switch (unit) + { + case IMinion _ when !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_MINIONS) > 0): + case IPlaceable _ when !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_USEABLE) > 0): + case IBaseTurret _ when !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_TURRETS) > 0): + return false; + } + + if ((unit is IInhibitor || unit is INexus) && !((SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_BUILDINGS) > 0)) + { + return false; + } + + return unit is IChampion || (SpellData.Flags & (int)SpellFlag.SPELL_FLAG_AFFECT_HEROES) > 0; } } } diff --git a/GameServerLib/GameObjects/Other/Announce.cs b/GameServerLib/GameObjects/Other/Announce.cs index e62318b70..4d89f0e8a 100644 --- a/GameServerLib/GameObjects/Other/Announce.cs +++ b/GameServerLib/GameObjects/Other/Announce.cs @@ -1,11 +1,12 @@ -using GameServerCore.Enums; +using GameServerCore.Domain; +using GameServerCore.Enums; namespace LeagueSandbox.GameServer.GameObjects.Other { - public class Announce + public class Announce: IAnnounce { public bool IsAnnounced { get; private set; } - public long EventTime { get; private set; } + public long EventTime { get; } private Announces _messageId; private bool _isMapSpecific; private Game _game; diff --git a/GameServerLib/GameObjects/Other/CollisionHandler.cs b/GameServerLib/GameObjects/Other/CollisionHandler.cs index 73d79f5a6..1fb8ce351 100644 --- a/GameServerLib/GameObjects/Other/CollisionHandler.cs +++ b/GameServerLib/GameObjects/Other/CollisionHandler.cs @@ -1,29 +1,32 @@ using System.Collections.Generic; +using GameServerCore; +using GameServerCore.Domain.GameObjects; +using GameServerCore.Maps; using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; using LeagueSandbox.GameServer.GameObjects.AttackableUnits.Buildings.AnimatedBuildings; using LeagueSandbox.GameServer.Maps; namespace LeagueSandbox.GameServer.GameObjects.Other { - public class CollisionHandler + public class CollisionHandler: ICollisionHandler { private Game _game; - private List _objects = new List(); + private readonly List _objects = new List(); - public CollisionHandler(Game game, Map map) + public CollisionHandler(Game game, IMap map) { _game = game; //Pathfinder.setMap(map); // Initialise the pathfinder. } - public void AddObject(GameObject obj) + public void AddObject(IGameObject obj) { _objects.Add(obj); } - public void RemoveObject(GameObject obj) + public void RemoveObject(IGameObject obj) { _objects.Remove(obj); } @@ -32,7 +35,7 @@ public void Update() { foreach (var obj in _objects) { - if (obj is BaseTurret || obj is Inhibitor || obj is Nexus) + if (obj is IBaseTurret || obj is IInhibitor || obj is INexus) { continue; } diff --git a/GameServerLib/GameObjects/Other/Placeable.cs b/GameServerLib/GameObjects/Other/Placeable.cs index 552be44ed..d424756e3 100644 --- a/GameServerLib/GameObjects/Other/Placeable.cs +++ b/GameServerLib/GameObjects/Other/Placeable.cs @@ -6,14 +6,12 @@ namespace LeagueSandbox.GameServer.GameObjects.Other { public class Placeable : ObjAiBase, IPlaceable { - public string Name { get; private set; } - public ObjAiBase Owner { get; private set; } // We'll probably want to change this in the future - - IObjAiBase IPlaceable.Owner => Owner; + public string Name { get; } + public IObjAiBase Owner { get; } // We'll probably want to change this in the future public Placeable( Game game, - ObjAiBase owner, + IObjAiBase owner, float x, float y, string model, diff --git a/GameServerLib/GameObjects/Other/Target.cs b/GameServerLib/GameObjects/Other/Target.cs index 6a4beef22..5559b2c85 100644 --- a/GameServerLib/GameObjects/Other/Target.cs +++ b/GameServerLib/GameObjects/Other/Target.cs @@ -27,13 +27,13 @@ public float GetDistanceTo(ITarget target) { return GetDistanceTo(target.X, target.Y); } - + public float GetDistanceTo(float xtarget, float ytarget) { return (float)Math.Sqrt(GetDistanceToSqr(xtarget, ytarget)); } - public float GetDistanceToSqr(Target target) + public float GetDistanceToSqr(ITarget target) { return GetDistanceToSqr(target.X, target.Y); } diff --git a/GameServerLib/GameObjects/Particle.cs b/GameServerLib/GameObjects/Particle.cs index 4676b9ea5..4c551953b 100644 --- a/GameServerLib/GameObjects/Particle.cs +++ b/GameServerLib/GameObjects/Particle.cs @@ -6,12 +6,10 @@ namespace LeagueSandbox.GameServer.GameObjects { public class Particle : GameObject, IParticle { - public IChampion Owner { get; private set; } - public string Name { get; private set; } - public string BoneName { get; private set; } - public float Size { get; private set; } - - IChampion IParticle.Owner => Owner; + public IChampion Owner { get; } + public string Name { get; } + public string BoneName { get; } + public float Size { get; } public Particle(Game game, IChampion owner, ITarget t, string particleName, float size = 1.0f, string boneName = "", uint netId = 0) : base(game, t.X, t.Y, 0, 0, netId) diff --git a/GameServerLib/GameObjects/Spells/Buff.cs b/GameServerLib/GameObjects/Spells/Buff.cs index 0c06bcb4f..3d9253c73 100644 --- a/GameServerLib/GameObjects/Spells/Buff.cs +++ b/GameServerLib/GameObjects/Spells/Buff.cs @@ -10,32 +10,29 @@ public class Buff : IBuff { public float Duration { get; private set; } protected float _movementSpeedPercentModifier; - public float TimeElapsed { get; set; } + public float TimeElapsed { get; private set; } protected bool _remove; - public ObjAiBase TargetUnit { get; private set; } - public ObjAiBase SourceUnit { get; private set; } // who added this buff to the unit it's attached to + public IObjAiBase TargetUnit { get; private set; } + public IObjAiBase SourceUnit { get; private set; } // who added this buff to the unit it's attached to public BuffType BuffType { get; private set; } protected CSharpScriptEngine _scriptEngine; public string Name { get; private set; } - public int Stacks { get; private set; } + public byte StackCount { get; private set; } public byte Slot { get; private set; } - IObjAiBase IBuff.TargetUnit => TargetUnit; - IObjAiBase IBuff.SourceUnit => SourceUnit; - protected Game _game; - public bool NeedsToRemove() + public bool Elapsed() { return _remove; } - public Buff(Game game, string buffName, float dur, int stacks, BuffType buffType, ObjAiBase onto, ObjAiBase from) + public Buff(Game game, string buffName, float dur, byte stacks, BuffType buffType, IObjAiBase onto, IObjAiBase from) { _game = game; _scriptEngine = game.ScriptEngine; Duration = dur; - Stacks = stacks; + StackCount = stacks; Name = buffName; TimeElapsed = 0; _remove = false; @@ -45,10 +42,11 @@ public Buff(Game game, string buffName, float dur, int stacks, BuffType buffType Slot = onto.GetNewBuffSlot(this); } - public Buff(Game game, string buffName, float dur, int stacks, BuffType buffType, ObjAiBase onto) + public Buff(Game game, string buffName, float dur, byte stacks, BuffType buffType, IObjAiBase onto) : this(game, buffName, dur, stacks, buffType, onto, onto) //no attacker specified = selfbuff, attacker aka source is same as attachedto { } + public void Update(float diff) { TimeElapsed += diff / 1000.0f; @@ -61,9 +59,30 @@ public void Update(float diff) } } - public void SetStacks(int newStacks) + public void ResetDuration() + { + Duration = 0; + } + + public bool IncrementStackCount() + { + if (StackCount == byte.MaxValue) + return false; + StackCount++; + return true; + } + + public bool DecrementStackCount() + { + if (StackCount <= 0) + return false; + StackCount--; + return true; + } + + public void SetStacks(byte newStacks) { - Stacks = newStacks; + StackCount = newStacks; } } } diff --git a/GameServerLib/GameObjects/Spells/Spell.cs b/GameServerLib/GameObjects/Spells/Spell.cs index 85f039d3d..d12450afd 100644 --- a/GameServerLib/GameObjects/Spells/Spell.cs +++ b/GameServerLib/GameObjects/Spells/Spell.cs @@ -16,7 +16,7 @@ namespace LeagueSandbox.GameServer.GameObjects.Spells public class Spell : ISpell { - public Champion Owner { get; private set; } + public IChampion Owner { get; private set; } public byte Level { get; private set; } public byte Slot { get; set; } public float CastTime { get; private set; } = 0; @@ -31,7 +31,7 @@ public class Spell : ISpell public uint FutureProjNetId { get; protected set; } public uint SpellNetId { get; protected set; } - public AttackableUnit Target { get; private set; } + public IAttackableUnit Target { get; private set; } public float X { get; private set; } public float Y { get; private set; } public float X2 { get; private set; } @@ -43,13 +43,9 @@ public class Spell : ISpell private IGameScript _spellGameScript; - public SpellData SpellData { get; private set; } + public ISpellData SpellData { get; private set; } - IChampion ISpell.Owner => Owner; - IAttackableUnit ISpell.Target => Target; - ISpellData ISpell.SpellData => SpellData; - - public Spell(Game game, Champion owner, string spellName, byte slot) + public Spell(Game game, IChampion owner, string spellName, byte slot) { Owner = owner; SpellName = spellName; @@ -73,7 +69,7 @@ void ISpell.Deactivate() /// /// Called when the character casts the spell /// - public virtual bool Cast(float x, float y, float x2, float y2, AttackableUnit u = null) + public virtual bool Cast(float x, float y, float x2, float y2, IAttackableUnit u = null) { if (HasEmptyScript) { @@ -210,7 +206,7 @@ public virtual void Update(float diff) /// /// Called by projectiles when they land / hit, this is where we apply damage/slows etc. /// - public void ApplyEffects(AttackableUnit u, Projectile p = null) + public void ApplyEffects(IAttackableUnit u, IProjectile p = null) { if (SpellData.HaveHitEffect && !string.IsNullOrEmpty(SpellData.HitEffectName)) { @@ -241,7 +237,7 @@ public void AddProjectile(string nameMissile, float toX, float toY, bool isServe } } - public void AddProjectileTarget(string nameMissile, Target target, bool isServerOnly = false) + public void AddProjectileTarget(string nameMissile, ITarget target, bool isServerOnly = false) { var p = new Projectile( _game, @@ -297,7 +293,7 @@ public void AddCone(string effectName, float toX, float toY, float angleDeg, boo _game.ObjectManager.AddObject(c); } - public void SpellAnimation(string animName, AttackableUnit target) + public void SpellAnimation(string animName, IAttackableUnit target) { _game.PacketNotifier.NotifySpellAnimation(target, animName); } @@ -332,7 +328,7 @@ public float GetCooldown() return _game.Config.CooldownsEnabled ? SpellData.Cooldown[Level] * (1 - Owner.Stats.CooldownReduction.Total) : 0; } - public virtual void LevelUp() + public void LevelUp() { if (Level <= 5) { @@ -345,27 +341,25 @@ public virtual void LevelUp() } } - public void SetCooldown(byte slot, float newCd) + public void SetCooldown(float newCd) { - var targetSpell = Owner.GetSpellBySlot(slot); - if (newCd <= 0) { - _game.PacketNotifier.NotifySetCooldown(Owner, slot, 0, 0); - targetSpell.State = SpellState.STATE_READY; - targetSpell.CurrentCooldown = 0; + _game.PacketNotifier.NotifySetCooldown(Owner, Slot, 0, 0); + State = SpellState.STATE_READY; + CurrentCooldown = 0; } else { - _game.PacketNotifier.NotifySetCooldown(Owner, slot, newCd, targetSpell.GetCooldown()); - targetSpell.State = SpellState.STATE_COOLDOWN; - targetSpell.CurrentCooldown = newCd; + _game.PacketNotifier.NotifySetCooldown(Owner, Slot, newCd, GetCooldown()); + State = SpellState.STATE_COOLDOWN; + CurrentCooldown = newCd; } } - public void LowerCooldown(byte slot, float lowerValue) + public void LowerCooldown(float lowerValue) { - SetCooldown(slot, Owner.GetSpellBySlot(slot).CurrentCooldown - lowerValue); + SetCooldown(CurrentCooldown - lowerValue); } } } diff --git a/GameServerLib/GameObjects/Stats/ChampionStats.cs b/GameServerLib/GameObjects/Stats/ChampionStats.cs index 1f6ae07dd..1e19c1d7c 100644 --- a/GameServerLib/GameObjects/Stats/ChampionStats.cs +++ b/GameServerLib/GameObjects/Stats/ChampionStats.cs @@ -10,134 +10,214 @@ namespace LeagueSandbox.GameServer.GameObjects.Stats public class ChampionStats : IChampionStats { [FieldOffset(0)] - public int Assists; + public int _Assists; [FieldOffset(8)] - public int Kills; + public int _Kills; [FieldOffset(16)] - public int DoubleKills; + public int _DoubleKills; [FieldOffset(32)] - public int UnrealKills; + public int _UnrealKills; [FieldOffset(36)] - public float GoldEarned; + public float _GoldEarned; [FieldOffset(40)] - public float GoldSpent; + public float _GoldSpent; [FieldOffset(84)] - public int CurrentKillingSpree; + public int _CurrentKillingSpree; [FieldOffset(88)] - public float LargestCriticalStrike; + public float _LargestCriticalStrike; [FieldOffset(92)] - public int LargestKillingSpree; + public int _LargestKillingSpree; [FieldOffset(96)] - public int LargestMultiKill; + public int _LargestMultiKill; [FieldOffset(104)] - public float LongestTimeSpentLiving; + public float _LongestTimeSpentLiving; [FieldOffset(108)] - public float MagicDamageDealt; + public float _MagicDamageDealt; [FieldOffset(112)] - public float MagicDamageDealtToChampions; + public float _MagicDamageDealtToChampions; [FieldOffset(116)] - public float MagicDamageTaken; + public float _MagicDamageTaken; [FieldOffset(120)] - public int MinionsKilled; + public int _MinionsKilled; [FieldOffset(126)] - public int NeutralMinionsKilled; + public int _NeutralMinionsKilled; [FieldOffset(130)] - public int NeutralMinionsKilledInEnemyJungle; + public int _NeutralMinionsKilledInEnemyJungle; [FieldOffset(134)] - public int NeutralMinionsKilledInTeamJungle; + public int _NeutralMinionsKilledInTeamJungle; [FieldOffset(142)] - public int Deaths; + public int _Deaths; [FieldOffset(146)] - public int PentaKills; + public int _PentaKills; [FieldOffset(150)] - public float PhysicalDamageDealt; + public float _PhysicalDamageDealt; [FieldOffset(154)] - public float PhysicalDamageDealtToChampions; + public float _PhysicalDamageDealtToChampions; [FieldOffset(158)] - public float PhysicalDamageTaken; + public float _PhysicalDamageTaken; [FieldOffset(166)] - public int QuadraKills; + public int _QuadraKills; [FieldOffset(206)] - public int TeamId; + public int _TeamId; [FieldOffset(226)] - public float TotalDamageDealt; + public float _TotalDamageDealt; [FieldOffset(230)] - public float TotalDamageDealtToChampions; + public float _TotalDamageDealtToChampions; [FieldOffset(234)] - public float TotalDamageTaken; + public float _TotalDamageTaken; [FieldOffset(238)] - public int TotalHeal; + public int _TotalHeal; [FieldOffset(242)] - public float TotalTimeCrowdControlDealt; + public float _TotalTimeCrowdControlDealt; [FieldOffset(246)] - public float TotalTimeSpentDead; + public float _TotalTimeSpentDead; [FieldOffset(250)] - public int TotalUnitsHealed; + public int _TotalUnitsHealed; [FieldOffset(254)] - public int TripleKills; + public int _TripleKills; [FieldOffset(258)] - public float TrueDamageDealt; + public float _TrueDamageDealt; [FieldOffset(262)] - public float TrueDamageDealtToChampions; + public float _TrueDamageDealtToChampions; [FieldOffset(266)] - public float TrueDamageTaken; + public float _TrueDamageTaken; [FieldOffset(270)] - public int TurretsKilled; + public int _TurretsKilled; [FieldOffset(274)] - public int BarracksKilled; + public int _BarracksKilled; [FieldOffset(282)] - public int WardsKilled; + public int _WardsKilled; [FieldOffset(286)] - public int WardsPlaced; + public int _WardsPlaced; [FieldOffset(298)] // sort of length (when above 0 sends malformed buffer error) public short Padding; - int IChampionStats.Assists => Assists; - int IChampionStats.Kills => Kills; - int IChampionStats.DoubleKills => DoubleKills; - int IChampionStats.UnrealKills => UnrealKills; - float IChampionStats.GoldEarned => GoldEarned; - float IChampionStats.GoldSpent => GoldSpent; - int IChampionStats.CurrentKillingSpree => CurrentKillingSpree; - float IChampionStats.LargestCriticalStrike => LargestCriticalStrike; - int IChampionStats.LargestKillingSpree => LargestKillingSpree; - int IChampionStats.LargestMultiKill => LargestMultiKill; - float IChampionStats.LongestTimeSpentLiving => LongestTimeSpentLiving; - float IChampionStats.MagicDamageDealt => MagicDamageDealt; - float IChampionStats.MagicDamageDealtToChampions => MagicDamageDealtToChampions; - float IChampionStats.MagicDamageTaken => MagicDamageTaken; - int IChampionStats.MinionsKilled => MinionsKilled; - int IChampionStats.NeutralMinionsKilled => NeutralMinionsKilled; - int IChampionStats.NeutralMinionsKilledInEnemyJungle => NeutralMinionsKilledInEnemyJungle; - int IChampionStats.NeutralMinionsKilledInTeamJungle => NeutralMinionsKilledInTeamJungle; - int IChampionStats.Deaths => Deaths; - int IChampionStats.PentaKills => PentaKills; - float IChampionStats.PhysicalDamageDealt => PhysicalDamageDealt; - float IChampionStats.PhysicalDamageDealtToChampions => PhysicalDamageDealtToChampions; - float IChampionStats.PhysicalDamageTaken => PhysicalDamageTaken; - int IChampionStats.QuadraKills => QuadraKills; - int IChampionStats.TeamId => TeamId; - float IChampionStats.TotalDamageDealt => TotalDamageDealt; - float IChampionStats.TotalDamageDealtToChampions => TotalDamageDealtToChampions; - float IChampionStats.TotalDamageTaken => TotalDamageTaken; - int IChampionStats.TotalHeal => TotalHeal; - float IChampionStats.TotalTimeCrowdControlDealt => TotalTimeCrowdControlDealt; - float IChampionStats.TotalTimeSpentDead => TotalTimeSpentDead; - int IChampionStats.TotalUnitsHealed => TotalUnitsHealed; - int IChampionStats.TripleKills => TripleKills; - float IChampionStats.TrueDamageDealt => TrueDamageDealt; - float IChampionStats.TrueDamageDealtToChampions => TrueDamageDealtToChampions; - float IChampionStats.TrueDamageTaken => TrueDamageTaken; - int IChampionStats.TurretsKilled => TurretsKilled; - int IChampionStats.BarracksKilled => BarracksKilled; - int IChampionStats.WardsKilled => WardsKilled; - int IChampionStats.WardsPlaced => WardsPlaced; + public int Assists { get => _Assists; + set => _Assists = value; + } + public int Kills { get => _Kills; + set => _Kills = value; + } + public int DoubleKills { get => _DoubleKills; + set => _DoubleKills = value; + } + public int UnrealKills { get => _UnrealKills; + set => _UnrealKills = value; + } + public float GoldEarned { get => _GoldEarned; + set => _GoldEarned = value; + } + public float GoldSpent { get => _GoldSpent; + set => _GoldSpent = value; + } + public int CurrentKillingSpree { get => _CurrentKillingSpree; + set => _CurrentKillingSpree = value; + } + public float LargestCriticalStrike { get => _LargestCriticalStrike; + set => _LargestCriticalStrike = value; + } + public int LargestKillingSpree { get => _LargestKillingSpree; + set => _LargestKillingSpree = value; + } + public int LargestMultiKill { get => _LargestMultiKill; + set => _LargestMultiKill = value; + } + public float LongestTimeSpentLiving { get => _LongestTimeSpentLiving; + set => _LongestTimeSpentLiving = value; + } + public float MagicDamageDealt { get => _MagicDamageDealt; + set => _MagicDamageDealt = value; + } + public float MagicDamageDealtToChampions { get => _MagicDamageDealtToChampions; + set => _MagicDamageDealtToChampions = value; + } + public float MagicDamageTaken { get => _MagicDamageTaken; + set => _MagicDamageTaken = value; + } + public int MinionsKilled { get => _MinionsKilled; + set => _MinionsKilled = value; + } + public int NeutralMinionsKilled { get => _NeutralMinionsKilled; + set => _NeutralMinionsKilled = value; + } + public int NeutralMinionsKilledInEnemyJungle { get => _NeutralMinionsKilledInEnemyJungle; + set => _NeutralMinionsKilledInEnemyJungle = value; + } + public int NeutralMinionsKilledInTeamJungle { get => _NeutralMinionsKilledInTeamJungle; + set => _NeutralMinionsKilledInTeamJungle = value; + } + public int Deaths { get => _Deaths; + set => _Deaths = value; + } + public int PentaKills { get => _PentaKills; + set => _PentaKills = value; + } + public float PhysicalDamageDealt { get => _PhysicalDamageDealt; + set => _PhysicalDamageDealt = value; + } + public float PhysicalDamageDealtToChampions { get => _PhysicalDamageDealtToChampions; + set => _PhysicalDamageDealtToChampions = value; + } + public float PhysicalDamageTaken { get => _PhysicalDamageTaken; + set => _PhysicalDamageTaken = value; + } + public int QuadraKills { get => _QuadraKills; + set => _QuadraKills = value; + } + public int TeamId { get => _TeamId; + set => _TeamId = value; + } + public float TotalDamageDealt { get => _TotalDamageDealt; + set => _TotalDamageDealt = value; + } + public float TotalDamageDealtToChampions { get => _TotalDamageDealtToChampions; + set => _TotalDamageDealtToChampions = value; + } + public float TotalDamageTaken { get => _TotalDamageTaken; + set => _TotalDamageTaken = value; + } + public int TotalHeal { get => _TotalHeal; + set => _TotalHeal = value; + } + public float TotalTimeCrowdControlDealt { get => _TotalTimeCrowdControlDealt; + set => _TotalTimeCrowdControlDealt = value; + } + public float TotalTimeSpentDead { get => _TotalTimeSpentDead; + set => _TotalTimeSpentDead = value; + } + public int TotalUnitsHealed { get => _TotalUnitsHealed; + set => _TotalUnitsHealed = value; + } + public int TripleKills { get => _TripleKills; + set => _TripleKills = value; + } + public float TrueDamageDealt { get => _TrueDamageDealt; + set => _TrueDamageDealt = value; + } + public float TrueDamageDealtToChampions { get => _TrueDamageDealtToChampions; + set => _TrueDamageDealtToChampions = value; + } + public float TrueDamageTaken { get => _TrueDamageTaken; + set => _TrueDamageTaken = value; + } + public int TurretsKilled { get => _TurretsKilled; + set => _TurretsKilled = value; + } + public int BarracksKilled { get => _BarracksKilled; + set => _BarracksKilled = value; + } + public int WardsKilled { get => _WardsKilled; + set => _WardsKilled = value; + } + public int WardsPlaced { get => _WardsPlaced; + set => _WardsPlaced = value; + } // TODO: move to universal serializer // also code here is unsafe, but thats prefered than just // write a function that simply dumps all the variables - public static byte[] GetBytes(ChampionStats stats) + public static byte[] GetBytes(IChampionStats stats) { int size = Marshal.SizeOf(stats); byte[] arr = new byte[size]; diff --git a/GameServerLib/GameObjects/Stats/Replication.cs b/GameServerLib/GameObjects/Stats/Replication.cs index aac8200f4..fac3d978a 100644 --- a/GameServerLib/GameObjects/Stats/Replication.cs +++ b/GameServerLib/GameObjects/Stats/Replication.cs @@ -1,5 +1,6 @@ using System; using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; using LeagueSandbox.GameServer.GameObjects.AttackableUnits; namespace LeagueSandbox.GameServer.GameObjects.Stats @@ -11,21 +12,16 @@ public class Replicate : IReplicate public uint Value { get; set; } public bool IsFloat { get; set; } public bool Changed { get; set; } - - public void MarkAsUnchanged() - { - Changed = false; - } } - protected Replication(AttackableUnit owner) + protected Replication(IAttackableUnit owner) { Owner = owner; Update(); } - protected readonly AttackableUnit Owner; - protected Stats Stats => Owner.Stats; + protected readonly IAttackableUnit Owner; + protected IStats Stats => Owner.Stats; public uint NetId => Owner.NetId; public Replicate[,] Values { get; private set; } = new Replicate[6, 32]; @@ -78,7 +74,8 @@ public void MarkAsUnchanged() { foreach (var x in Values) { - x?.MarkAsUnchanged(); + if (x != null) + x.Changed = false; } Changed = false; diff --git a/GameServerLib/GameObjects/Stats/ReplicationAiTurret.cs b/GameServerLib/GameObjects/Stats/ReplicationAiTurret.cs index 0baf3aaa5..79a3e22eb 100644 --- a/GameServerLib/GameObjects/Stats/ReplicationAiTurret.cs +++ b/GameServerLib/GameObjects/Stats/ReplicationAiTurret.cs @@ -1,10 +1,11 @@ -using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; +using GameServerCore.Domain.GameObjects; +using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; namespace LeagueSandbox.GameServer.GameObjects.Stats { public class ReplicationAiTurret : Replication { - public ReplicationAiTurret(BaseTurret owner) : base(owner) + public ReplicationAiTurret(IBaseTurret owner) : base(owner) { } diff --git a/GameServerLib/GameObjects/Stats/Stats.cs b/GameServerLib/GameObjects/Stats/Stats.cs index 34279960c..d7ad7771d 100644 --- a/GameServerLib/GameObjects/Stats/Stats.cs +++ b/GameServerLib/GameObjects/Stats/Stats.cs @@ -18,7 +18,7 @@ public class Stats : IStats public bool IsInvulnerable { get; set; } public bool IsPhysicalImmune { get; set; } public bool IsLifestealImmune { get; set; } - public bool IsTargetable { get; set; } + public bool IsTargetable { get; } public IsTargetableToTeamFlags IsTargetableToTeam { get; set; } public float AttackSpeedFlat { get; set; } @@ -30,29 +30,29 @@ public class Stats : IStats public float HealthRegenerationPerLevel { get; set; } public float ManaRegenerationPerLevel { get; set; } public float GrowthAttackSpeed { get; set; } - public float[] ManaCost { get; set; } + public float[] ManaCost { get; } - public Stat AbilityPower { get; } - public Stat Armor { get; } - public Stat ArmorPenetration { get; } - public Stat AttackDamage { get; } - public Stat AttackSpeedMultiplier { get; } - public Stat CooldownReduction { get; } - public Stat CriticalChance { get; } - public Stat CriticalDamage { get; } - public Stat GoldPerSecond { get; } - public Stat HealthPoints { get; } - public Stat HealthRegeneration { get; } - public Stat LifeSteal { get; } - public Stat MagicResist { get; } - public Stat MagicPenetration { get; } - public Stat ManaPoints { get; } - public Stat ManaRegeneration { get; } - public Stat MoveSpeed { get; } - public Stat Range { get; } - public Stat Size { get; } - public Stat SpellVamp { get; } - public Stat Tenacity { get; } + public IStat AbilityPower { get; } + public IStat Armor { get; } + public IStat ArmorPenetration { get; } + public IStat AttackDamage { get; } + public IStat AttackSpeedMultiplier { get; } + public IStat CooldownReduction { get; } + public IStat CriticalChance { get; } + public IStat CriticalDamage { get; } + public IStat GoldPerSecond { get; } + public IStat HealthPoints { get; } + public IStat HealthRegeneration { get; } + public IStat LifeSteal { get; } + public IStat MagicResist { get; } + public IStat MagicPenetration { get; } + public IStat ManaPoints { get; } + public IStat ManaRegeneration { get; } + public IStat MoveSpeed { get; } + public IStat Range { get; } + public IStat Size { get; } + public IStat SpellVamp { get; } + public IStat Tenacity { get; } public float Gold { get; set; } public byte Level { get; set; } @@ -75,28 +75,6 @@ public float CurrentMana public bool IsGeneratingGold { get; set; } // Used to determine if the Stats update should include generating gold. Changed in Champion.h public float SpellCostReduction { get; set; } //URF Buff/Lissandra's passive - IStat IStats.AbilityPower => AbilityPower; - IStat IStats.Armor => Armor; - IStat IStats.ArmorPenetration => ArmorPenetration; - IStat IStats.AttackDamage => AttackDamage; - IStat IStats.AttackSpeedMultiplier => AttackSpeedMultiplier; - IStat IStats.CooldownReduction => CooldownReduction; - IStat IStats.CriticalChance => CriticalChance; - IStat IStats.CriticalDamage => CriticalDamage; - IStat IStats.GoldPerSecond => GoldPerSecond; - IStat IStats.HealthPoints => HealthPoints; - IStat IStats.HealthRegeneration => HealthRegeneration; - IStat IStats.LifeSteal => LifeSteal; - IStat IStats.MagicResist => MagicResist; - IStat IStats.MagicPenetration => MagicPenetration; - IStat IStats.ManaPoints => ManaPoints; - IStat IStats.ManaRegeneration => ManaRegeneration; - IStat IStats.MoveSpeed => MoveSpeed; - IStat IStats.Range => Range; - IStat IStats.Size => Size; - IStat IStats.SpellVamp => SpellVamp; - IStat IStats.Tenacity => Tenacity; - public Stats() { SpellCostReduction = 0; diff --git a/GameServerLib/GameObjects/Stats/StatsModifier.cs b/GameServerLib/GameObjects/Stats/StatsModifier.cs index f956811c3..ea0978ef7 100644 --- a/GameServerLib/GameObjects/Stats/StatsModifier.cs +++ b/GameServerLib/GameObjects/Stats/StatsModifier.cs @@ -5,25 +5,25 @@ namespace LeagueSandbox.GameServer.GameObjects.Stats public class StatsModifier : IStatsModifier { // Stats - public IStatModifier HealthPoints { get; set; } = new StatModifier(); - public IStatModifier HealthRegeneration { get; set; } = new StatModifier(); - public IStatModifier AttackDamage { get; set; } = new StatModifier(); - public IStatModifier AbilityPower { get; set; } = new StatModifier(); - public IStatModifier CriticalChance { get; set; } = new StatModifier(); - public IStatModifier CriticalDamage { get; set; } = new StatModifier(); - public IStatModifier Armor { get; set; } = new StatModifier(); - public IStatModifier MagicResist { get; set; } = new StatModifier(); - public IStatModifier AttackSpeed { get; set; } = new StatModifier(); - public IStatModifier ArmorPenetration { get; set; } = new StatModifier(); - public IStatModifier MagicPenetration { get; set; } = new StatModifier(); - public IStatModifier ManaPoints { get; set; } = new StatModifier(); - public IStatModifier ManaRegeneration { get; set; } = new StatModifier(); - public IStatModifier LifeSteal { get; set; } = new StatModifier(); - public IStatModifier SpellVamp { get; set; } = new StatModifier(); - public IStatModifier Tenacity { get; set; } = new StatModifier(); - public IStatModifier Size { get; set; } = new StatModifier(); - public IStatModifier Range { get; set; } = new StatModifier(); - public IStatModifier MoveSpeed { get; set; } = new StatModifier(); - public IStatModifier GoldPerSecond { get; set; } = new StatModifier(); + public IStatModifier HealthPoints { get; } = new StatModifier(); + public IStatModifier HealthRegeneration { get; } = new StatModifier(); + public IStatModifier AttackDamage { get; } = new StatModifier(); + public IStatModifier AbilityPower { get; } = new StatModifier(); + public IStatModifier CriticalChance { get; } = new StatModifier(); + public IStatModifier CriticalDamage { get; } = new StatModifier(); + public IStatModifier Armor { get; } = new StatModifier(); + public IStatModifier MagicResist { get; } = new StatModifier(); + public IStatModifier AttackSpeed { get; } = new StatModifier(); + public IStatModifier ArmorPenetration { get; } = new StatModifier(); + public IStatModifier MagicPenetration { get; } = new StatModifier(); + public IStatModifier ManaPoints { get; } = new StatModifier(); + public IStatModifier ManaRegeneration { get; } = new StatModifier(); + public IStatModifier LifeSteal { get; } = new StatModifier(); + public IStatModifier SpellVamp { get; } = new StatModifier(); + public IStatModifier Tenacity { get; } = new StatModifier(); + public IStatModifier Size { get; } = new StatModifier(); + public IStatModifier Range { get; } = new StatModifier(); + public IStatModifier MoveSpeed { get; } = new StatModifier(); + public IStatModifier GoldPerSecond { get; } = new StatModifier(); } } diff --git a/GameServerLib/GameServerLib.csproj b/GameServerLib/GameServerLib.csproj index a0d902a2c..b2605e682 100644 --- a/GameServerLib/GameServerLib.csproj +++ b/GameServerLib/GameServerLib.csproj @@ -266,7 +266,7 @@ - + @@ -313,7 +313,6 @@ - diff --git a/GameServerLib/Items/Inventory.cs b/GameServerLib/Items/Inventory.cs index a677f7656..1d8221585 100644 --- a/GameServerLib/Items/Inventory.cs +++ b/GameServerLib/Items/Inventory.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using GameServerCore.Domain; namespace LeagueSandbox.GameServer.Items { @@ -9,24 +10,23 @@ public class Inventory private const byte BASE_INVENTORY_SIZE = 7; // Includes trinket private const byte EXTRA_INVENTORY_SIZE = 7; private const byte RUNE_INVENTORY_SIZE = 30; - private Item[] _items; private InventoryManager _owner; - public Item[] Items => _items; + public IItem[] Items { get; } public Inventory(InventoryManager owner) { _owner = owner; - _items = new Item[BASE_INVENTORY_SIZE + EXTRA_INVENTORY_SIZE + RUNE_INVENTORY_SIZE]; + Items = new IItem[BASE_INVENTORY_SIZE + EXTRA_INVENTORY_SIZE + RUNE_INVENTORY_SIZE]; } - public Item[] GetBaseItems() + public IItem[] GetBaseItems() { - return _items.Take(BASE_INVENTORY_SIZE).ToArray(); + return Items.Take(BASE_INVENTORY_SIZE).ToArray(); } - public Item AddItem(ItemType item) + public IItem AddItem(IItemData item) { - if (item.IsTrinket()) + if (item.ItemGroup.ToLower().Equals("relicbase")) { return AddTrinketItem(item); } @@ -39,7 +39,7 @@ public Item AddItem(ItemType item) return AddNewItem(item); } - public Item SetExtraItem(byte slot, ItemType item) + public IItem SetExtraItem(byte slot, IItemData item) { if (slot < BASE_INVENTORY_SIZE) { @@ -49,32 +49,32 @@ public Item SetExtraItem(byte slot, ItemType item) return SetItem(slot, item); } - private Item SetItem(byte slot, ItemType item) + private IItem SetItem(byte slot, IItemData item) { - _items[slot] = Item.CreateFromType(this, item); - return _items[slot]; + Items[slot] = Item.CreateFromType(item); + return Items[slot]; } - public Item GetItem(byte slot) + public IItem GetItem(byte slot) { - return _items[slot]; + return Items[slot]; } public void RemoveItem(byte slot) { - _items[slot] = null; + Items[slot] = null; } - public void RemoveItem(Item item) + public void RemoveItem(IItem item) { RemoveItem(GetItemSlot(item)); } - public byte GetItemSlot(Item item) + public byte GetItemSlot(IItem item) { - for (byte i = 0; i < _items.Length; i++) + for (byte i = 0; i < Items.Length; i++) { - if (_items[i] != item) + if (Items[i] != item) { continue; } @@ -92,14 +92,14 @@ public void SwapItems(byte slot1, byte slot2) throw new Exception("Can't swap to or from the trinket slot"); } - var buffer = _items[slot1]; - _items[slot1] = _items[slot2]; - _items[slot2] = buffer; + var buffer = Items[slot1]; + Items[slot1] = Items[slot2]; + Items[slot2] = buffer; } - private Item AddTrinketItem(ItemType item) + private IItem AddTrinketItem(IItemData item) { - if (_items[TRINKET_SLOT] != null) + if (Items[TRINKET_SLOT] != null) { return null; } @@ -107,23 +107,23 @@ private Item AddTrinketItem(ItemType item) return SetItem(TRINKET_SLOT, item); } - private Item AddStackingItem(ItemType item) + private IItem AddStackingItem(IItemData item) { for (var i = 0; i < BASE_INVENTORY_SIZE; i++) { - if (_items[i] == null) + if (Items[i] == null) { continue; } - if (item.ItemId != _items[i].ItemType.ItemId) + if (item.ItemId != Items[i].ItemData.ItemId) { continue; } - if (_items[i].IncrementStackSize()) + if (Items[i].IncrementStackCount()) { - return _items[i]; + return Items[i]; } return null; @@ -131,7 +131,7 @@ private Item AddStackingItem(ItemType item) return AddNewItem(item); } - private Item AddNewItem(ItemType item) + private IItem AddNewItem(IItemData item) { for (var i = 0; i < BASE_INVENTORY_SIZE; i++) { @@ -140,7 +140,7 @@ private Item AddNewItem(ItemType item) continue; } - if (_items[i] != null) + if (Items[i] != null) { continue; } diff --git a/GameServerLib/Items/InventoryManager.cs b/GameServerLib/Items/InventoryManager.cs index 297b99fff..12fd6d683 100644 --- a/GameServerLib/Items/InventoryManager.cs +++ b/GameServerLib/Items/InventoryManager.cs @@ -14,17 +14,17 @@ private InventoryManager() _inventory = new Inventory(this); } - public Item AddItem(ItemType item) + public IItem AddItem(IItemData item) { return _inventory.AddItem(item); } - public Item SetExtraItem(byte slot, ItemType item) + public IItem SetExtraItem(byte slot, IItemData item) { return _inventory.SetExtraItem(slot, item); } - public Item GetItem(byte slot) + public IItem GetItem(byte slot) { return _inventory.GetItem(slot); } @@ -34,12 +34,12 @@ public void RemoveItem(byte slot) _inventory.RemoveItem(slot); } - public void RemoveItem(Item item) + public void RemoveItem(IItem item) { _inventory.RemoveItem(item); } - public byte GetItemSlot(Item item) + public byte GetItemSlot(IItem item) { return _inventory.GetItemSlot(item); } @@ -49,26 +49,25 @@ public void SwapItems(byte slot1, byte slot2) _inventory.SwapItems(slot1, slot2); } - public List GetAvailableItems(ItemRecipe recipe) + public List GetAvailableItems(IEnumerable items) { - var tempInv = new List(_inventory.GetBaseItems()); - return GetAvailableItemsRecursive(ref tempInv, recipe); + var tempInv = new List(_inventory.GetBaseItems()); + return GetAvailableItemsRecursive(ref tempInv, items); } - private static List GetAvailableItemsRecursive(ref List inventoryState, ItemRecipe recipe) + private static List GetAvailableItemsRecursive(ref List inventoryState, IEnumerable items) { - var result = new List(); - var tmpRecipe = recipe.GetItems(); - foreach (var component in tmpRecipe) + var result = new List(); + foreach (var component in items) { if (component == null) { continue; } - var idx = inventoryState.FindIndex(i => i != null && i.ItemType == component); + var idx = inventoryState.FindIndex(i => i != null && i.ItemData == component); if (idx == -1) { - result = result.Concat(GetAvailableItemsRecursive(ref inventoryState, component.Recipe)).ToList(); + result = result.Concat(GetAvailableItemsRecursive(ref inventoryState, component.Recipe.GetItems())).ToList(); } else { @@ -89,20 +88,5 @@ public IEnumerator GetEnumerator() { return _inventory.Items.GetEnumerator(); } - - byte IInventoryManager.GetItemSlot(IItem item) - { - return GetItemSlot((Item)item); - } - - IItem IInventoryManager.SetExtraItem(byte slot, IItemType item) - { - return SetExtraItem(slot, (ItemType)item); - } - - IItem IInventoryManager.GetItem(byte slot) - { - return GetItem(slot); - } } } diff --git a/GameServerLib/Items/Item.cs b/GameServerLib/Items/Item.cs index 200be6ab6..bed326d09 100644 --- a/GameServerLib/Items/Item.cs +++ b/GameServerLib/Items/Item.cs @@ -4,46 +4,47 @@ namespace LeagueSandbox.GameServer.Items { public class Item : IItem { - public byte StackSize { get; private set; } - public int TotalPrice => ItemType.TotalPrice; - public ItemType ItemType { get; private set; } + public int TotalPrice => ItemData.TotalPrice; + public IItemData ItemData { get; } + public byte StackCount { get; private set; } - IItemType IItem.ItemType => ItemType; - private Inventory _owner; - - private Item(Inventory owner, ItemType type) + private Item(IItemData data) { - _owner = owner; - ItemType = type; - StackSize = 1; + ItemData = data; + StackCount = 1; } - - public bool IncrementStackSize() + + public bool IncrementStackCount() { - if (StackSize >= ItemType.MaxStack) + if (StackCount >= ItemData.MaxStack) { return false; } - StackSize++; + StackCount++; return true; } - public bool DecrementStackSize() + public bool DecrementStackCount() { - if (StackSize < 1) + if (StackCount < 1) { return false; } - StackSize--; + StackCount--; return true; } - public static Item CreateFromType(Inventory inventory, ItemType item) + public void SetStacks(byte newStacks) + { + throw new System.NotImplementedException(); + } + + public static Item CreateFromType(IItemData item) { - return new Item(inventory, item); + return new Item(item); } } } \ No newline at end of file diff --git a/GameServerLib/Items/ItemType.cs b/GameServerLib/Items/ItemData.cs similarity index 86% rename from GameServerLib/Items/ItemType.cs rename to GameServerLib/Items/ItemData.cs index 93444f991..c3a4a67e4 100644 --- a/GameServerLib/Items/ItemType.cs +++ b/GameServerLib/Items/ItemData.cs @@ -4,11 +4,8 @@ namespace LeagueSandbox.GameServer.Items { - public class ItemType : StatsModifier, IItemType + public class ItemData : StatsModifier, IItemData { - //private ItemManager _owner; - private ItemContentCollectionEntry _itemInfo; - // Meta public int ItemId { get; private set; } public string Name { get; private set; } @@ -21,18 +18,32 @@ public class ItemType : StatsModifier, IItemType public float SellBackModifier { get; private set; } // Recipes - public int RecipeItem1 { get; private set; } - public int RecipeItem2 { get; private set; } - public int RecipeItem3 { get; private set; } - public int RecipeItem4 { get; private set; } + private int RecipeItem1 { get; set; } + private int RecipeItem2 { get; set; } + private int RecipeItem3 { get; set; } + private int RecipeItem4 { get; set; } + + public int[] RecipeItem + { + get + { + return new int[4] + { + RecipeItem1, + RecipeItem2, + RecipeItem3, + RecipeItem4, + }; + } + } // Not from data - public ItemRecipe Recipe { get; private set; } + public IItemRecipe Recipe { get; private set; } public int TotalPrice => Recipe.TotalPrice; - private ItemType(ItemContentCollectionEntry itemInfo) + private ItemData() { - _itemInfo = itemInfo; + } private void CreateRecipe(ItemManager manager) @@ -40,10 +51,10 @@ private void CreateRecipe(ItemManager manager) Recipe = ItemRecipe.FromItemType(this, manager); } - public static ItemType Load(ItemManager owner, ItemContentCollectionEntry itemInfo) + public static ItemData Load(ItemManager owner, ItemContentCollectionEntry itemInfo) { // Because IntelliSense is nice to have - var result = new ItemType(itemInfo) + var result = new ItemData() { ItemId = itemInfo.ItemId, Name = itemInfo.Name, @@ -128,11 +139,6 @@ public static ItemType Load(ItemManager owner, ItemContentCollectionEntry itemIn result.CreateRecipe(owner); return result; } - - public bool IsTrinket() - { - return ItemGroup.ToLower().Equals("relicbase"); - } } } \ No newline at end of file diff --git a/GameServerLib/Items/ItemManager.cs b/GameServerLib/Items/ItemManager.cs index 7dfa8b273..fc19197e9 100644 --- a/GameServerLib/Items/ItemManager.cs +++ b/GameServerLib/Items/ItemManager.cs @@ -1,23 +1,24 @@ using System.Collections.Generic; +using GameServerCore.Domain; using LeagueSandbox.GameServer.Content; namespace LeagueSandbox.GameServer.Items { public class ItemManager { - private Dictionary _itemTypes; + private readonly Dictionary _itemTypes; public ItemManager() { - _itemTypes = new Dictionary(); + _itemTypes = new Dictionary(); } - public ItemType GetItemType(int itemId) + public IItemData GetItemType(int itemId) { return _itemTypes[itemId]; } - public ItemType SafeGetItemType(int itemId, ItemType defaultValue) + public IItemData SafeGetItemType(int itemId, IItemData defaultValue) { if (!_itemTypes.ContainsKey(itemId)) { @@ -27,7 +28,7 @@ public ItemType SafeGetItemType(int itemId, ItemType defaultValue) return _itemTypes[itemId]; } - public ItemType SafeGetItemType(int itemId) + public IItemData SafeGetItemType(int itemId) { return SafeGetItemType(itemId, null); } @@ -41,7 +42,7 @@ public void AddItems(ItemContentCollection contentCollection) { foreach (var entry in contentCollection) { - var itemType = ItemType.Load(this, entry.Value); + var itemType = ItemData.Load(this, entry.Value); _itemTypes.Add(entry.Key, itemType); } } diff --git a/GameServerLib/Items/ItemRecipe.cs b/GameServerLib/Items/ItemRecipe.cs index 20e83ff28..bc4980174 100644 --- a/GameServerLib/Items/ItemRecipe.cs +++ b/GameServerLib/Items/ItemRecipe.cs @@ -1,14 +1,15 @@ using System.Collections.Generic; using System.Linq; +using GameServerCore.Domain; namespace LeagueSandbox.GameServer.Items { - public class ItemRecipe + public class ItemRecipe: IItemRecipe { - private readonly ItemType _itemType; - private ItemType[] _items; + private readonly IItemData _itemData; + private IItemData[] _items; private int _totalPrice; - private ItemManager _itemManager; + private readonly ItemManager _itemManager; public int TotalPrice { @@ -23,33 +24,28 @@ public int TotalPrice } } - private ItemRecipe(ItemType itemType, ItemManager manager) + private ItemRecipe(IItemData itemData, ItemManager manager) { - _itemType = itemType; + _itemData = itemData; _totalPrice = -1; _itemManager = manager; } - public List GetItems() + public IEnumerable GetItems() { if (_items == null) { FindRecipeItems(_itemManager); } - return _items.ToList(); + return _items; } private void FindRecipeItems(ItemManager itemManager) { - // TODO: Figure out how to refactor this. - _items = new[] - { - itemManager.SafeGetItemType(_itemType.RecipeItem1), - itemManager.SafeGetItemType(_itemType.RecipeItem2), - itemManager.SafeGetItemType(_itemType.RecipeItem3), - itemManager.SafeGetItemType(_itemType.RecipeItem4) - }.Where(i => i != null).ToArray(); + _items = _itemData.RecipeItem.AsEnumerable() + .Select(itemManager.SafeGetItemType) + .Where(i => i != null).ToArray(); } private void FindPrice() @@ -60,12 +56,12 @@ private void FindPrice() _totalPrice += item.TotalPrice; } - _totalPrice += _itemType.Price; + _totalPrice += _itemData.Price; } - public static ItemRecipe FromItemType(ItemType type, ItemManager manager) + public static ItemRecipe FromItemType(IItemData data, ItemManager manager) { - return new ItemRecipe(type, manager); + return new ItemRecipe(data, manager); } } } \ No newline at end of file diff --git a/GameServerLib/Items/Shop.cs b/GameServerLib/Items/Shop.cs index 4c949eadc..28d415342 100644 --- a/GameServerLib/Items/Shop.cs +++ b/GameServerLib/Items/Shop.cs @@ -1,16 +1,17 @@ using System.Linq; -using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; +using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; namespace LeagueSandbox.GameServer.Items { - public class Shop + public class Shop: IShop { - private readonly Champion _owner; + private readonly IChampion _owner; private readonly Game _game; public const byte ITEM_ACTIVE_OFFSET = 6; - private Shop(Champion owner, Game game) + private Shop(IChampion owner, Game game) { _owner = owner; _game = game; @@ -25,14 +26,14 @@ public bool HandleItemSellRequest(byte slotId) return false; } - var sellPrice = i.TotalPrice * i.ItemType.SellBackModifier; + var sellPrice = i.TotalPrice * i.ItemData.SellBackModifier; _owner.Stats.Gold += sellPrice; - if (i.ItemType.MaxStack > 1) + if (i.ItemData.MaxStack > 1) { - i.DecrementStackSize(); + i.DecrementStackCount(); } - RemoveItem(i, slotId, i.StackSize); + RemoveItem(i, slotId, i.StackCount); return true; } @@ -47,11 +48,11 @@ public bool HandleItemBuyRequest(int itemId) var stats = _owner.Stats; var inventory = _owner.Inventory; var price = itemTemplate.TotalPrice; - var ownedItems = inventory.GetAvailableItems(itemTemplate.Recipe); + var ownedItems = inventory.GetAvailableItems(itemTemplate.Recipe.GetItems()); if (ownedItems.Count != 0) { - price -= ownedItems.Sum(item => item.ItemType.TotalPrice); + price -= ownedItems.Sum(item => item.ItemData.TotalPrice); if (stats.Gold < price) { return false; @@ -73,32 +74,32 @@ public bool HandleItemBuyRequest(int itemId) return true; } - private void RemoveItem(Item item, byte slotId, byte stackSize = 0) + private void RemoveItem(IItem item, byte slotId, byte stackSize = 0) { var inventory = _owner.Inventory; - _owner.Stats.RemoveModifier(item.ItemType); + _owner.Stats.RemoveModifier(item.ItemData); _game.PacketNotifier.NotifyRemoveItem(_owner, slotId, stackSize); _owner.RemoveSpell((byte)(slotId + ITEM_ACTIVE_OFFSET)); inventory.RemoveItem(item); } - private bool AddItem(ItemType itemType) + private bool AddItem(IItemData itemData) { - var i = _owner.Inventory.AddItem(itemType); + var i = _owner.Inventory.AddItem(itemData); if (i == null) { return false; } - _owner.Stats.AddModifier(itemType); + _owner.Stats.AddModifier(itemData); _game.PacketNotifier.NotifyItemBought(_owner, i); - if (!string.IsNullOrEmpty(i.ItemType.SpellName)) + if (!string.IsNullOrEmpty(i.ItemData.SpellName)) { - _owner.SetSpell(i.ItemType.SpellName, (byte)(_owner.Inventory.GetItemSlot(i) + ITEM_ACTIVE_OFFSET), true); + _owner.SetSpell(i.ItemData.SpellName, (byte)(_owner.Inventory.GetItemSlot(i) + ITEM_ACTIVE_OFFSET), true); } return true; } - public static Shop CreateShop(Champion owner, Game game) + public static Shop CreateShop(IChampion owner, Game game) { return new Shop(owner, game); } diff --git a/GameServerLib/Maps/Map.cs b/GameServerLib/Maps/Map.cs index d7f55eafc..db5cc3f0a 100644 --- a/GameServerLib/Maps/Map.cs +++ b/GameServerLib/Maps/Map.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.IO; +using GameServerCore; using GameServerCore.Content; +using GameServerCore.Domain; using GameServerCore.Maps; using LeagueSandbox.GameServer.Content; using LeagueSandbox.GameServer.GameObjects.Other; @@ -11,18 +13,16 @@ namespace LeagueSandbox.GameServer.Maps { - public class Map : IMap + public class Map: IMap { protected Game _game; private readonly ILog _logger; - public List AnnouncerEvents { get; private set; } - public NavGrid NavGrid { get; private set; } - public CollisionHandler CollisionHandler { get; private set; } + public List AnnouncerEvents { get; private set; } + public INavGrid NavGrid { get; private set; } + public ICollisionHandler CollisionHandler { get; private set; } public int Id { get; private set; } - public IMapGameScript MapGameScript { get; private set; } - - INavGrid IMap.NavGrid => NavGrid; + public IMapProperties MapProperties { get; private set; } public Map(Game game) { @@ -47,12 +47,12 @@ public Map(Game game) return; } - AnnouncerEvents = new List(); + AnnouncerEvents = new List(); CollisionHandler = new CollisionHandler(_game, this); - MapGameScript = GetMapScript(Id); + MapProperties = GetMapProperties(Id); } - public IMapGameScript GetMapScript(int mapId) + public IMapProperties GetMapProperties(int mapId) { var dict = new Dictionary { @@ -74,12 +74,12 @@ public IMapGameScript GetMapScript(int mapId) return new SummonersRift(_game); } - return (IMapGameScript)Activator.CreateInstance(dict[mapId], _game); + return (IMapProperties)Activator.CreateInstance(dict[mapId], _game); } public void Init() { - MapGameScript.Init(); + MapProperties.Init(); } public void Update(float diff) @@ -93,7 +93,7 @@ public void Update(float diff) } } - MapGameScript.Update(diff); + MapProperties.Update(diff); } } } diff --git a/GameServerLib/Maps/SummonersRift.cs b/GameServerLib/Maps/SummonersRift.cs index 0f65abb81..9e569e435 100644 --- a/GameServerLib/Maps/SummonersRift.cs +++ b/GameServerLib/Maps/SummonersRift.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Numerics; +using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; using GameServerCore.Enums; using LeagueSandbox.GameServer.GameObjects; using LeagueSandbox.GameServer.GameObjects.AttackableUnits; @@ -11,7 +13,7 @@ namespace LeagueSandbox.GameServer.Maps { - internal class SummonersRift : IMapGameScript + internal class SummonersRift : IMapProperties { private static readonly List BlueTopWaypoints = new List { @@ -131,7 +133,7 @@ internal class SummonersRift : IMapGameScript { TeamId.TEAM_PURPLE, new Vector3(12800, 13100, 110) } }; - private static readonly Dictionary SpawnsByTeam = new Dictionary + private static readonly Dictionary SpawnsByTeam = new Dictionary { {TeamId.TEAM_BLUE, new Target(25.90f, 280)}, {TeamId.TEAM_PURPLE, new Target(13948, 14202)} @@ -319,7 +321,7 @@ public void Update(float diff) } } - public Target GetRespawnLocation(TeamId team) + public ITarget GetRespawnLocation(TeamId team) { if (!SpawnsByTeam.ContainsKey(team)) { @@ -353,11 +355,11 @@ public string GetMinionModel(TeamId team, MinionSpawnType type) return $"{teamDictionary[team]}_Minion_{typeDictionary[type]}"; } - public float GetGoldFor(AttackableUnit u) + public float GetGoldFor(IAttackableUnit u) { - if (!(u is Minion m)) + if (!(u is IMinion m)) { - if (!(u is Champion c)) + if (!(u is IChampion c)) { return 0.0f; } @@ -383,29 +385,27 @@ public float GetGoldFor(AttackableUnit u) return 500.0f; } - if (c.KillDeathCounter < 0) - { - var firstDeathGold = gold - gold * 0.085f; - - if (c.KillDeathCounter == -1) - { - return firstDeathGold; - } + if (c.KillDeathCounter >= 0) + return 0.0f; + + var firstDeathGold = gold - gold * 0.085f; - for (var i = c.KillDeathCounter; i < -1; ++i) - { - firstDeathGold -= firstDeathGold * 0.2f; - } + if (c.KillDeathCounter == -1) + { + return firstDeathGold; + } - if (firstDeathGold < 50) - { - firstDeathGold = 50; - } + for (var i = c.KillDeathCounter; i < -1; ++i) + { + firstDeathGold -= firstDeathGold * 0.2f; + } - return firstDeathGold; + if (firstDeathGold < 50) + { + firstDeathGold = 50; } - return 0.0f; + return firstDeathGold; } var dic = new Dictionary @@ -424,9 +424,9 @@ public float GetGoldFor(AttackableUnit u) return dic[m.MinionSpawnType]; } - public float GetExperienceFor(AttackableUnit u) + public float GetExperienceFor(IAttackableUnit u) { - if (!(u is Minion m)) + if (!(u is IMinion m)) { return 0.0f; } @@ -467,7 +467,7 @@ public Tuple GetMinionSpawnPosition(MinionSpawnPosition spawnPo return new Tuple(0, new Vector2()); } - public void SetMinionStats(Minion m) + public void SetMinionStats(IMinion m) { // Same for all minions m.Stats.MoveSpeed.BaseValue = 325.0f; @@ -569,7 +569,7 @@ public bool Spawn() var waypoints = spawnToWaypoints[pos].Item1; var inhibitorId = spawnToWaypoints[pos].Item2; var inhibitor = _game.ObjectManager.GetInhibitorById(inhibitorId); - var isInhibitorDead = inhibitor.InhibitorState == InhibitorState.DEAD && !((Inhibitor)inhibitor).RespawnAnnounced; + var isInhibitorDead = inhibitor.InhibitorState == InhibitorState.DEAD && !inhibitor.RespawnAnnounced; var oppositeTeam = TeamId.TEAM_BLUE; if (inhibitor.Team == TeamId.TEAM_PURPLE) @@ -577,7 +577,7 @@ public bool Spawn() oppositeTeam = TeamId.TEAM_PURPLE; } - var areAllInhibitorsDead = _game.ObjectManager.AllInhibitorsDestroyedFromTeam(oppositeTeam) && !((Inhibitor)inhibitor).RespawnAnnounced; + var areAllInhibitorsDead = _game.ObjectManager.AllInhibitorsDestroyedFromTeam(oppositeTeam) && !inhibitor.RespawnAnnounced; var list = RegularMinionWave; if (_cannonMinionCount >= cannonMinionCap) diff --git a/GameServerLib/ObjectManager.cs b/GameServerLib/ObjectManager.cs index fd1bce2c8..aae80016c 100644 --- a/GameServerLib/ObjectManager.cs +++ b/GameServerLib/ObjectManager.cs @@ -9,6 +9,7 @@ using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; using LeagueSandbox.GameServer.GameObjects.AttackableUnits.Buildings.AnimatedBuildings; using LeagueSandbox.GameServer.GameObjects.Other; +using LeagueSandbox.GameServer.Logging; namespace LeagueSandbox.GameServer { @@ -50,19 +51,18 @@ public void Update(float diff) var temp = GetObjects(); foreach (var obj in temp.Values) { - if (((GameObject)obj).IsToRemove()) + if (obj.IsToRemove()) { - if (obj.AttackerCount == 0) - RemoveObject(obj); + RemoveObject(obj); continue; } - ((GameObject)obj).Update(diff); + obj.Update(diff); - if (!(obj is AttackableUnit)) + if (!(obj is IAttackableUnit)) continue; - var u = obj as AttackableUnit; + var u = obj as IAttackableUnit; foreach (var team in Teams) { if (u.Team == team || team == TeamId.TEAM_NEUTRAL) @@ -96,21 +96,23 @@ public void Update(float diff) } } - var ai = u as ObjAiBase; + var ai = u as IObjAiBase; if (ai != null) { var tempBuffs = ai.GetBuffs(); foreach (var buff in tempBuffs.Values) { - if (buff.NeedsToRemove()) + if (buff.Elapsed()) { if (buff.Name != "") { _game.PacketNotifier.NotifyRemoveBuff(buff.TargetUnit, buff.Name, buff.Slot); } + ai.RemoveBuff(buff); continue; } + buff.Update(diff); } } @@ -124,10 +126,10 @@ public void Update(float diff) u.IsModelUpdated = false; } - if (((GameObject)obj).IsMovementUpdated()) + if (obj.IsMovementUpdated()) { _game.PacketNotifier.NotifyMovement(obj); - ((GameObject)obj).ClearMovementUpdated(); + obj.ClearMovementUpdated(); } } } @@ -161,6 +163,7 @@ public bool AllInhibitorsDestroyedFromTeam(TeamId team) return false; } } + return true; } @@ -174,6 +177,7 @@ public void AddObject(IGameObject o) { _objects.Add(o.NetId, o); } + o.OnAdded(); } @@ -199,6 +203,7 @@ public void RemoveObject(IGameObject o) { _objects.Remove(o.NetId); } + o.OnRemoved(); } @@ -274,12 +279,13 @@ public void StopTargeting(IAttackableUnit target) { foreach (var kv in _objects) { - var u = kv.Value as AttackableUnit; + var u = kv.Value as IAttackableUnit; if (u == null) { continue; } - var ai = u as ObjAiBase; + + var ai = u as IObjAiBase; if (ai != null) { if (ai.TargetUnit == target) @@ -304,6 +310,7 @@ public List GetAllChampionsFromTeam(TeamId team) champs.Add(c); } } + return champs; } @@ -320,11 +327,12 @@ public List GetChampionsInRange(ITarget t, float range, bool onlyAliv foreach (var kv in _champions) { var c = kv.Value; - if (((Target)t).GetDistanceTo(((Target)c)) <= range) + if (t.GetDistanceTo(c) <= range) if (onlyAlive && !c.IsDead || !onlyAlive) champs.Add(c); } } + return champs; } @@ -340,8 +348,7 @@ public List GetUnitsInRange(ITarget t, float range, bool onlyAl { foreach (var kv in _objects) { - var u = kv.Value as IAttackableUnit; - if (u != null && ((Target) t).GetDistanceTo(((Target)u)) <= range && (onlyAlive && !u.IsDead || !onlyAlive)) + if (kv.Value is IAttackableUnit u && t.GetDistanceTo(u) <= range && (onlyAlive && !u.IsDead || !onlyAlive)) { units.Add(u); } @@ -367,10 +374,10 @@ public bool TeamHasVisionOn(TeamId team, IGameObject o) { foreach (var kv in _objects) { - if (kv.Value.Team == team && ((Target)kv.Value).GetDistanceTo((GameObject)o) < kv.Value.VisionRadius && - !_game.Map.NavGrid.IsAnythingBetween((GameObject)kv.Value, (GameObject)o)) + if (kv.Value.Team == team && kv.Value.GetDistanceTo(o) < kv.Value.VisionRadius && + !_game.Map.NavGrid.IsAnythingBetween(kv.Value, o)) { - var unit = kv.Value as AttackableUnit; + var unit = kv.Value as IAttackableUnit; if (unit != null && unit.IsDead) { continue; @@ -387,7 +394,7 @@ public bool TeamHasVisionOn(TeamId team, IGameObject o) public int CountUnitsAttackingUnit(IAttackableUnit target) { return GetObjects().Count(x => - x.Value is ObjAiBase aiBase && + x.Value is IObjAiBase aiBase && aiBase.Team == target.Team.GetEnemyTeam() && !aiBase.IsDead && aiBase.TargetUnit != null && diff --git a/GameServerLib/Packets/PacketHandlers/HandleBuyItem.cs b/GameServerLib/Packets/PacketHandlers/HandleBuyItem.cs index 202c4c930..8a12a1cdf 100644 --- a/GameServerLib/Packets/PacketHandlers/HandleBuyItem.cs +++ b/GameServerLib/Packets/PacketHandlers/HandleBuyItem.cs @@ -1,4 +1,5 @@ using GameServerCore; +using GameServerCore.Domain.GameObjects; using GameServerCore.Packets.Enums; using GameServerCore.Packets.Handlers; using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; @@ -25,7 +26,7 @@ public HandleBuyItem(Game game) public override bool HandlePacket(int userId, byte[] data) { var request = _game.PacketReader.ReadBuyItemRequest(data); - var champion = (Champion)_playerManager.GetPeerInfo(userId).Champion; + var champion = _playerManager.GetPeerInfo(userId).Champion; return champion.Shop.HandleItemBuyRequest(request.ItemId); } } diff --git a/GameServerLib/Packets/PacketHandlers/HandleCastSpell.cs b/GameServerLib/Packets/PacketHandlers/HandleCastSpell.cs index 5170a5e31..0f04c7072 100644 --- a/GameServerLib/Packets/PacketHandlers/HandleCastSpell.cs +++ b/GameServerLib/Packets/PacketHandlers/HandleCastSpell.cs @@ -1,4 +1,6 @@ using GameServerCore; +using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; using GameServerCore.Packets.Enums; using GameServerCore.Packets.Handlers; using LeagueSandbox.GameServer.GameObjects.AttackableUnits; @@ -26,14 +28,14 @@ public override bool HandlePacket(int userId, byte[] data) { var request = _game.PacketReader.ReadCastSpellRequest(data); var targetObj = _game.ObjectManager.GetObjectById(request.TargetNetId); - var targetUnit = targetObj as AttackableUnit; + var targetUnit = targetObj as IAttackableUnit; var owner = _playerManager.GetPeerInfo(userId).Champion; if (owner == null || !owner.CanCast()) { return false; } - var s = owner.GetSpell(request.SpellSlot) as Spell; + var s = owner.GetSpell(request.SpellSlot); if (s == null) { return false; diff --git a/GameServerLib/Packets/PacketHandlers/HandleMove.cs b/GameServerLib/Packets/PacketHandlers/HandleMove.cs index 748a795a6..374ec92a2 100644 --- a/GameServerLib/Packets/PacketHandlers/HandleMove.cs +++ b/GameServerLib/Packets/PacketHandlers/HandleMove.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.IO; using System.Numerics; +using GameServerCore.Maps; namespace LeagueSandbox.GameServer.Packets.PacketHandlers { @@ -63,7 +64,7 @@ public override bool HandlePacket(int userId, byte[] data) return true; } - private List ReadWaypoints(byte[] buffer, int coordCount, Map map) + private List ReadWaypoints(byte[] buffer, int coordCount, IMap map) { if (coordCount % 2 > 0) { diff --git a/GameServerLib/Packets/PacketHandlers/HandleSellItem.cs b/GameServerLib/Packets/PacketHandlers/HandleSellItem.cs index 5ca0472dc..9da511510 100644 --- a/GameServerLib/Packets/PacketHandlers/HandleSellItem.cs +++ b/GameServerLib/Packets/PacketHandlers/HandleSellItem.cs @@ -23,7 +23,7 @@ public HandleSellItem(Game game) public override bool HandlePacket(int userId, byte[] data) { var request = _game.PacketReader.ReadSellItemRequest(data); - var champion = (Champion)_playerManager.GetPeerInfo(userId).Champion; + var champion = _playerManager.GetPeerInfo(userId).Champion; return champion.Shop.HandleItemSellRequest(request.SlotId); } } diff --git a/GameServerLib/Packets/PacketHandlers/HandleSkillUp.cs b/GameServerLib/Packets/PacketHandlers/HandleSkillUp.cs index 411d1bde8..cbdb26f6a 100644 --- a/GameServerLib/Packets/PacketHandlers/HandleSkillUp.cs +++ b/GameServerLib/Packets/PacketHandlers/HandleSkillUp.cs @@ -30,7 +30,7 @@ public override bool HandlePacket(int userId, byte[] data) return false; } - _game.PacketNotifier.NotifySkillUp(userId, champion.NetId, request.Skill, s.Level, (byte)s.Owner.SkillPoints); + _game.PacketNotifier.NotifySkillUp(userId, champion.NetId, request.Skill, s.Level, s.Owner.SkillPoints); champion.Stats.SetSpellEnabled(request.Skill, true); return true; diff --git a/GameServerLib/Packets/PacketHandlers/HandleSpawn.cs b/GameServerLib/Packets/PacketHandlers/HandleSpawn.cs index e1d785f0c..2689ea38f 100644 --- a/GameServerLib/Packets/PacketHandlers/HandleSpawn.cs +++ b/GameServerLib/Packets/PacketHandlers/HandleSpawn.cs @@ -1,4 +1,6 @@ using GameServerCore; +using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; using GameServerCore.Enums; using GameServerCore.Packets.Enums; using GameServerCore.Packets.Handlers; @@ -46,7 +48,7 @@ public override bool HandlePacket(int userId, byte[] data) } var peerInfo = _playerManager.GetPeerInfo(userId); - var bluePill = _itemManager.GetItemType(_game.Map.MapGameScript.BluePillId); + var bluePill = _itemManager.GetItemType(_game.Map.MapProperties.BluePillId); var itemInstance = peerInfo.Champion.Inventory.SetExtraItem(7, bluePill); _game.PacketNotifier.NotifyBuyItem(userId, peerInfo.Champion, itemInstance); @@ -73,7 +75,7 @@ public override bool HandlePacket(int userId, byte[] data) var objects = _game.ObjectManager.GetObjects(); foreach (var kv in objects) { - if (kv.Value is LaneTurret turret) + if (kv.Value is ILaneTurret turret) { _game.PacketNotifier.NotifyTurretSpawn(userId, turret); @@ -86,27 +88,27 @@ public override bool HandlePacket(int userId, byte[] data) foreach (var item in turret.Inventory) { if (item == null) continue; - _game.PacketNotifier.NotifyItemBought(turret, item as Item); + _game.PacketNotifier.NotifyItemBought(turret, item as IItem); } } - else if (kv.Value is LevelProp levelProp) + else if (kv.Value is ILevelProp levelProp) { _game.PacketNotifier.NotifyLevelPropSpawn(userId, levelProp); } - else if (kv.Value is Champion champion) + else if (kv.Value is IChampion champion) { if (champion.IsVisibleByTeam(peerInfo.Champion.Team)) { _game.PacketNotifier.NotifyEnterVision(userId, champion); } } - else if (kv.Value is Inhibitor || kv.Value is Nexus) + else if (kv.Value is IInhibitor || kv.Value is INexus) { - var inhibtor = (AttackableUnit)kv.Value; + var inhibtor = (IAttackableUnit)kv.Value; _game.PacketNotifier.NotifyStaticObjectSpawn(userId, inhibtor.NetId); _game.PacketNotifier.NotifySetHealth(userId, inhibtor.NetId); } - else if (kv.Value is Projectile projectile) + else if (kv.Value is IProjectile projectile) { if (projectile.IsVisibleByTeam(peerInfo.Champion.Team)) { diff --git a/GameServerLib/Packets/PacketHandlers/HandleStartGame.cs b/GameServerLib/Packets/PacketHandlers/HandleStartGame.cs index 0a2e5ac62..00e3f02c7 100644 --- a/GameServerLib/Packets/PacketHandlers/HandleStartGame.cs +++ b/GameServerLib/Packets/PacketHandlers/HandleStartGame.cs @@ -91,7 +91,7 @@ public override bool HandlePacket(int userId, byte[] data) foreach (var p in _playerManager.GetPlayers()) { - _game.ObjectManager.AddObject((GameObject)p.Item2.Champion); + _game.ObjectManager.AddObject(p.Item2.Champion); // Send the initial game time sync packets, then let the map send another var gameTime = _game.GameTime; diff --git a/GameServerLib/Scripting/CSharp/BuffGameScript.cs b/GameServerLib/Scripting/CSharp/BuffGameScript.cs index 81b440cd5..3fd342269 100644 --- a/GameServerLib/Scripting/CSharp/BuffGameScript.cs +++ b/GameServerLib/Scripting/CSharp/BuffGameScript.cs @@ -1,4 +1,6 @@ -using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; +using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; +using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; using LeagueSandbox.GameServer.GameObjects.Spells; namespace LeagueSandbox.GameServer.Scripting.CSharp @@ -7,8 +9,8 @@ public interface IBuffGameScript { void OnUpdate(double diff); - void OnActivate(ObjAiBase unit, Spell ownerSpell); + void OnActivate(IObjAiBase unit, ISpell ownerSpell); - void OnDeactivate(ObjAiBase unit); + void OnDeactivate(IObjAiBase unit); } } diff --git a/GameServerLib/Scripting/CSharp/BuffGameScriptController.cs b/GameServerLib/Scripting/CSharp/BuffGameScriptController.cs index c50dadd67..1ca34f806 100644 --- a/GameServerLib/Scripting/CSharp/BuffGameScriptController.cs +++ b/GameServerLib/Scripting/CSharp/BuffGameScriptController.cs @@ -1,4 +1,6 @@ -using LeagueSandbox.GameServer.API; +using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; +using LeagueSandbox.GameServer.API; using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; using LeagueSandbox.GameServer.GameObjects.Spells; @@ -6,16 +8,16 @@ namespace LeagueSandbox.GameServer.Scripting.CSharp { public class BuffGameScriptController { - public ObjAiBase Unit { get; private set; } + public IObjAiBase Unit { get; private set; } public IBuffGameScript GameScript { get; private set; } public string BuffNamespace { get; private set; } public string BuffClass { get; private set; } - public Spell OwnerSpell { get; private set; } + public ISpell OwnerSpell { get; private set; } private bool _remove; private float _duration = -1f; protected CSharpScriptEngine _scriptEngine; - public BuffGameScriptController(Game game, ObjAiBase unit, string buffNamespace, string buffClass, Spell ownerSpell, float duration = -1f) + public BuffGameScriptController(Game game, IObjAiBase unit, string buffNamespace, string buffClass, ISpell ownerSpell, float duration = -1f) { _scriptEngine = game.ScriptEngine; BuffNamespace = buffNamespace; diff --git a/GameServerLib/Scripting/CSharp/GameScript.cs b/GameServerLib/Scripting/CSharp/GameScript.cs index ea545c599..f4e5dea1c 100644 --- a/GameServerLib/Scripting/CSharp/GameScript.cs +++ b/GameServerLib/Scripting/CSharp/GameScript.cs @@ -1,20 +1,18 @@ -using LeagueSandbox.GameServer.GameObjects.AttackableUnits; -using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; -using LeagueSandbox.GameServer.GameObjects.Missiles; -using LeagueSandbox.GameServer.GameObjects.Spells; +using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; namespace LeagueSandbox.GameServer.Scripting.CSharp { public interface IGameScript { - void OnActivate(Champion owner); + void OnActivate(IChampion owner); - void OnDeactivate(Champion owner); + void OnDeactivate(IChampion owner); - void OnStartCasting(Champion owner, Spell spell, AttackableUnit target); + void OnStartCasting(IChampion owner, ISpell spell, IAttackableUnit target); - void OnFinishCasting(Champion owner, Spell spell, AttackableUnit target); + void OnFinishCasting(IChampion owner, ISpell spell, IAttackableUnit target); - void ApplyEffects(Champion owner, AttackableUnit target, Spell spell, Projectile projectile); + void ApplyEffects(IChampion owner, IAttackableUnit target, ISpell spell, IProjectile projectile); } } diff --git a/GameServerLib/Scripting/CSharp/GameScriptEmpty.cs b/GameServerLib/Scripting/CSharp/GameScriptEmpty.cs index 40174e1bc..591779f59 100644 --- a/GameServerLib/Scripting/CSharp/GameScriptEmpty.cs +++ b/GameServerLib/Scripting/CSharp/GameScriptEmpty.cs @@ -1,29 +1,27 @@ -using LeagueSandbox.GameServer.GameObjects.AttackableUnits; -using LeagueSandbox.GameServer.GameObjects.AttackableUnits.AI; -using LeagueSandbox.GameServer.GameObjects.Missiles; -using LeagueSandbox.GameServer.GameObjects.Spells; +using GameServerCore.Domain; +using GameServerCore.Domain.GameObjects; namespace LeagueSandbox.GameServer.Scripting.CSharp { public class GameScriptEmpty : IGameScript { - public void OnActivate(Champion owner) + public void OnActivate(IChampion owner) { } - public void OnDeactivate(Champion owner) + public void OnDeactivate(IChampion owner) { } - public void OnStartCasting(Champion owner, Spell spell, AttackableUnit target) + public void OnStartCasting(IChampion owner, ISpell spell, IAttackableUnit target) { } - public void OnFinishCasting(Champion owner, Spell spell, AttackableUnit target) + public void OnFinishCasting(IChampion owner, ISpell spell, IAttackableUnit target) { } - public void ApplyEffects(Champion owner, AttackableUnit target, Spell spell, Projectile projectile) + public void ApplyEffects(IChampion owner, IAttackableUnit target, ISpell spell, IProjectile projectile) { } } diff --git a/GameServerLibTests/GameServerLibTests.csproj b/GameServerLibTests/GameServerLibTests.csproj index 69c4c8642..5051a2e41 100644 --- a/GameServerLibTests/GameServerLibTests.csproj +++ b/GameServerLibTests/GameServerLibTests.csproj @@ -66,6 +66,10 @@ + + {da3de633-d75b-40b0-8833-099abfbf43a2} + GameServerCore + {cb004023-b938-4ec6-b036-29ee2f55cfa4} GameServerLib diff --git a/GameServerLibTests/Tests/Items/TestInventoryManager.cs b/GameServerLibTests/Tests/Items/TestInventoryManager.cs index 8b6172af5..36d0a2af4 100644 --- a/GameServerLibTests/Tests/Items/TestInventoryManager.cs +++ b/GameServerLibTests/Tests/Items/TestInventoryManager.cs @@ -67,19 +67,19 @@ public void TestItemStacking() Assert.AreEqual(item2, manager.GetItem(1)); // Check stack sizes - Assert.AreEqual(1, item1.StackSize); - Assert.AreEqual(1, item2.StackSize); + Assert.AreEqual(1, item1.StackCount); + Assert.AreEqual(1, item2.StackCount); // Stack the second item, and make sure the second gets stacked for(var i = 0; i < itemType2.MaxStack - 1; i++) { var item2Reference = manager.AddItem(itemType2); Assert.AreEqual(item2, item2Reference); - Assert.AreEqual(1 + i + 1, item2.StackSize); + Assert.AreEqual(1 + i + 1, item2.StackCount); } // Make sure the first item's stack is unchanged - Assert.AreEqual(1, item1.StackSize); + Assert.AreEqual(1, item1.StackCount); // Make sure we can't add any more of the second item to the stack var shouldBeNull = manager.AddItem(itemType2); @@ -232,25 +232,25 @@ public void TestGetAvailableItems() // Get zephyr and make sure we have no items available to it's recipe var zephyr = itemManager.GetItemType(zephyrId); - var availableItems = manager.GetAvailableItems(zephyr.Recipe); + var availableItems = manager.GetAvailableItems(zephyr.Recipe.GetItems()); Assert.AreEqual(0, availableItems.Count); // Add a component and make sure we get it from the available items function var component1 = manager.AddItem(itemManager.GetItemType(componentId1)); - var available = manager.GetAvailableItems(zephyr.Recipe); + var available = manager.GetAvailableItems(zephyr.Recipe.GetItems()); Assert.AreEqual(1, available.Count); Assert.AreEqual(component1, available[0]); // Add another component and make sure we get that as well var component2 = manager.AddItem(itemManager.GetItemType(componentId2)); - available = manager.GetAvailableItems(zephyr.Recipe); + available = manager.GetAvailableItems(zephyr.Recipe.GetItems()); Assert.AreEqual(2, available.Count); Assert.AreEqual(component1, available[0]); Assert.AreEqual(component2, available[1]); // Remove the first component and make sure we still have everything correctly manager.RemoveItem(manager.GetItemSlot(component1)); - available = manager.GetAvailableItems(zephyr.Recipe); + available = manager.GetAvailableItems(zephyr.Recipe.GetItems()); Assert.AreEqual(1, available.Count); Assert.AreEqual(component2, available[0]); @@ -262,7 +262,7 @@ public void TestGetAvailableItems() Assert.IsNotNull(manager.GetItem(manager.GetItemSlot(unrelated))); // Make sure we have no available items, even though there are some in the inventory - available = manager.GetAvailableItems(zephyr.Recipe); + available = manager.GetAvailableItems(zephyr.Recipe.GetItems()); Assert.AreEqual(0, available.Count); } } diff --git a/PacketDefinitions420/PacketDefinitions/S2C/BuyItemResponse.cs b/PacketDefinitions420/PacketDefinitions/S2C/BuyItemResponse.cs index 0eb41fefc..2b9bfa056 100644 --- a/PacketDefinitions420/PacketDefinitions/S2C/BuyItemResponse.cs +++ b/PacketDefinitions420/PacketDefinitions/S2C/BuyItemResponse.cs @@ -9,9 +9,9 @@ public class BuyItemResponse : BasePacket public BuyItemResponse(IAttackableUnit actor, IItem item, byte unk = 0x29) : base(PacketCmd.PKT_S2C_BUY_ITEM_ANS, actor.NetId) { - Write((int)item.ItemType.ItemId); + Write((int)item.ItemData.ItemId); Write((byte)actor.Inventory.GetItemSlot(item)); - Write((byte)item.StackSize); + Write((byte)item.StackCount); Write((byte)0); //unk or stacks => short Write((byte)unk); //unk (turret 0x01 and champions 0x29) } diff --git a/PacketDefinitions420/PacketNotifier.cs b/PacketDefinitions420/PacketNotifier.cs index b83c77688..0fa5dab88 100644 --- a/PacketDefinitions420/PacketNotifier.cs +++ b/PacketDefinitions420/PacketNotifier.cs @@ -360,7 +360,7 @@ public void NotifyInhibitorSpawningSoon(IInhibitor inhibitor) public void NotifyAddBuff(IBuff b) { - var add = new AddBuff(b.TargetUnit, b.SourceUnit, b.Stacks, b.Duration, b.BuffType, b.Name, b.Slot); + var add = new AddBuff(b.TargetUnit, b.SourceUnit, b.StackCount, b.Duration, b.BuffType, b.Name, b.Slot); _packetHandlerManager.BroadcastPacket(add, Channel.CHL_S2C); } @@ -378,7 +378,7 @@ public void NotifyDebugMessage(TeamId team, string message) public void NotifyEditBuff(IBuff b, int stacks) { - var edit = new EditBuff(b.TargetUnit, b.Slot, (byte)b.Stacks); + var edit = new EditBuff(b.TargetUnit, b.Slot, b.StackCount); _packetHandlerManager.BroadcastPacket(edit, Channel.CHL_S2C); }