From d9b96438deab9a80fe78bb0a9a9c48ba3667ef8a Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 14 Jul 2025 23:44:00 -0400 Subject: [PATCH] implemented bolas + status effect mechanic --- Assets/Prefabs/Sticks/bolasStick.prefab | 44 ++-- Assets/Prefabs/bolasProjectile.prefab | 231 ++++++++++++++++++ Assets/Prefabs/bolasProjectile.prefab.meta | 7 + Assets/Scripts/Ally/Ally.cs | 1 - Assets/Scripts/Ally/Bolas.cs | 32 +++ Assets/Scripts/Ally/Bolas.cs.meta | 11 + Assets/Scripts/Entity.cs | 14 +- Assets/Scripts/Enum.cs | 5 + Assets/Scripts/Projectile.cs | 37 +-- Assets/Scripts/Projectile.meta | 8 + Assets/Scripts/Projectile/BolasProjectile.cs | 18 ++ .../Projectile/BolasProjectile.cs.meta | 11 + Assets/Scripts/Root.cs | 3 +- Assets/Scripts/Status.meta | 8 + Assets/Scripts/Status/Slow.cs | 29 +++ Assets/Scripts/Status/Slow.cs.meta | 11 + Assets/Scripts/Status/Status.cs | 26 ++ Assets/Scripts/Status/Status.cs.meta | 11 + Assets/Scripts/StatusHandler.cs | 40 +++ Assets/Scripts/StatusHandler.cs.meta | 11 + 20 files changed, 515 insertions(+), 43 deletions(-) create mode 100644 Assets/Prefabs/bolasProjectile.prefab create mode 100644 Assets/Prefabs/bolasProjectile.prefab.meta create mode 100644 Assets/Scripts/Ally/Bolas.cs create mode 100644 Assets/Scripts/Ally/Bolas.cs.meta create mode 100644 Assets/Scripts/Projectile.meta create mode 100644 Assets/Scripts/Projectile/BolasProjectile.cs create mode 100644 Assets/Scripts/Projectile/BolasProjectile.cs.meta create mode 100644 Assets/Scripts/Status.meta create mode 100644 Assets/Scripts/Status/Slow.cs create mode 100644 Assets/Scripts/Status/Slow.cs.meta create mode 100644 Assets/Scripts/Status/Status.cs create mode 100644 Assets/Scripts/Status/Status.cs.meta create mode 100644 Assets/Scripts/StatusHandler.cs create mode 100644 Assets/Scripts/StatusHandler.cs.meta diff --git a/Assets/Prefabs/Sticks/bolasStick.prefab b/Assets/Prefabs/Sticks/bolasStick.prefab index 3796679..7a0c327 100644 --- a/Assets/Prefabs/Sticks/bolasStick.prefab +++ b/Assets/Prefabs/Sticks/bolasStick.prefab @@ -152,7 +152,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 531d7966d86bd0c4d83baf58bcb56cd5, type: 3} m_Name: m_EditorClassIdentifier: - _entityLinked: {fileID: 6069600615579642376} + _entityLinked: {fileID: 5530763025372097863} --- !u!1 &1167891119861249516 GameObject: m_ObjectHideFlags: 0 @@ -499,10 +499,10 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 7468362030574254172} + - component: {fileID: 5530763025372097863} - component: {fileID: 7802907299062813180} - component: {fileID: 1182150014477180862} - component: {fileID: 5931428661698025033} - - component: {fileID: 6069600615579642376} - component: {fileID: 577648786767256172} m_Layer: 0 m_Name: bolasStick @@ -530,6 +530,24 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &5530763025372097863 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7468362030574254173} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 20821ed53f7f53e4cbdc7b3157c35b97, type: 3} + m_Name: + m_EditorClassIdentifier: + _lifeBar: {fileID: 9115548409632460044} + _hp: 4 + _speed: 0 + _attack_damage: 1 + _attack_interval: 4 + _enemy: {fileID: 0} --- !u!50 &7802907299062813180 Rigidbody2D: serializedVersion: 4 @@ -592,24 +610,6 @@ MonoBehaviour: playableSounds: - {fileID: 11400000, guid: 24352f713d54a924c98784212780e0da, type: 2} - {fileID: 11400000, guid: 155d3b4d90b751748a35f21d3074b910, type: 2} ---- !u!114 &6069600615579642376 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7468362030574254173} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 4efc1afdf7c559a4cac25dad0d8917cb, type: 3} - m_Name: - m_EditorClassIdentifier: - _lifeBar: {fileID: 9115548409632460044} - _hp: 4 - _speed: 0 - _attack_damage: 1 - _attack_interval: 4 - _enemy: {fileID: 0} --- !u!82 &577648786767256172 AudioSource: m_ObjectHideFlags: 0 @@ -1963,8 +1963,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c0fbd934c179894458914437255781c4, type: 3} m_Name: m_EditorClassIdentifier: - _entity: {fileID: 6069600615579642376} - _projectile: {fileID: 6962989255644195630, guid: 869a03bba705e8d4485aa73daad773dc, type: 3} + _entity: {fileID: 5530763025372097863} + _projectile: {fileID: 6962989255644195630, guid: 3df5eaab2a4c1d64bba590ed4e1ac0f7, type: 3} _projectileSpawn: {fileID: 7322466304790414952} --- !u!1 &9107841294774877216 GameObject: diff --git a/Assets/Prefabs/bolasProjectile.prefab b/Assets/Prefabs/bolasProjectile.prefab new file mode 100644 index 0000000..306ab67 --- /dev/null +++ b/Assets/Prefabs/bolasProjectile.prefab @@ -0,0 +1,231 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &6962989255644195630 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6962989255644195631} + - component: {fileID: -1491803373025033585} + - component: {fileID: 2924140018079318964} + m_Layer: 0 + m_Name: bolasProjectile + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6962989255644195631 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6962989255644195630} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -6.61, y: -0.638, z: 1.8112363} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 6962989256011107500} + - {fileID: 6802302589573039538} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!50 &-1491803373025033585 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6962989255644195630} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDrag: 0 + m_AngularDrag: 0.05 + m_GravityScale: 0 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 4 +--- !u!114 &2924140018079318964 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6962989255644195630} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: af32629f84318134799756134098abf9, type: 3} + m_Name: + m_EditorClassIdentifier: + _detectionLinked: {fileID: 4130391605812397686} + straightProjectile: 1 + _angle: 0 + _speed: 2 + _slowIntensity: 0.25 +--- !u!1 &6962989256011107503 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6962989256011107500} + - component: {fileID: 6962989256011107501} + m_Layer: 0 + m_Name: sprite + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6962989256011107500 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6962989256011107503} + m_LocalRotation: {x: 0, y: -0, z: 0.7071068, w: -0.7071068} + m_LocalPosition: {x: 0.0259, y: 0.01, z: 0} + m_LocalScale: {x: 0.5394133, y: 0.56488746, z: 0.9686} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 6962989255644195631} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 270} +--- !u!212 &6962989256011107501 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6962989256011107503} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 364159097 + m_SortingLayer: 1 + m_SortingOrder: 4 + m_Sprite: {fileID: 21300000, guid: b28a7c5aeb45b224983f69339965c55d, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 1.06, y: 1.69} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!1 &8726647054546243319 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6802302589573039538} + - component: {fileID: 7006189111012443782} + - component: {fileID: 4130391605812397686} + m_Layer: 0 + m_Name: detection + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6802302589573039538 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8726647054546243319} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 6962989255644195631} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!61 &7006189111012443782 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8726647054546243319} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0.16277367, y: 0.016521543} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 0, y: 0} + newSize: {x: 0, y: 0} + adaptiveTilingThreshold: 0 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 0.3744527, y: 0.17825907} + m_EdgeRadius: 0 +--- !u!114 &4130391605812397686 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8726647054546243319} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 531d7966d86bd0c4d83baf58bcb56cd5, type: 3} + m_Name: + m_EditorClassIdentifier: + _entityLinked: {fileID: 0} diff --git a/Assets/Prefabs/bolasProjectile.prefab.meta b/Assets/Prefabs/bolasProjectile.prefab.meta new file mode 100644 index 0000000..f90d30b --- /dev/null +++ b/Assets/Prefabs/bolasProjectile.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3df5eaab2a4c1d64bba590ed4e1ac0f7 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Ally/Ally.cs b/Assets/Scripts/Ally/Ally.cs index 0fcb14b..a29a110 100644 --- a/Assets/Scripts/Ally/Ally.cs +++ b/Assets/Scripts/Ally/Ally.cs @@ -11,7 +11,6 @@ public class Ally : Entity public override float SpeedMultiplier => GlobalConfig.Instance.Current.allySpeedMultiplier; public float PopulationCost => GlobalConfig.Instance.Current.populationCostPerUnit; - public override void Update() { base.Update(); diff --git a/Assets/Scripts/Ally/Bolas.cs b/Assets/Scripts/Ally/Bolas.cs new file mode 100644 index 0000000..c39cfc9 --- /dev/null +++ b/Assets/Scripts/Ally/Bolas.cs @@ -0,0 +1,32 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Bolas : Ally +{ + public override void Start() + { + base.Start(); + } + + public override void Update() + { + base.Update(); + if (IsEnemyDetected) + { + AttackEnemy(); + } + } + + void AttackEnemy() + { + //Attack Cooldown + if (AttackInterval < AttackSpeedWait) + { + Animation.PlayAttackAnim(); + AttackSpeedWait = 0f; + } + AttackSpeedWait += Time.deltaTime; + } + +} diff --git a/Assets/Scripts/Ally/Bolas.cs.meta b/Assets/Scripts/Ally/Bolas.cs.meta new file mode 100644 index 0000000..656d676 --- /dev/null +++ b/Assets/Scripts/Ally/Bolas.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 20821ed53f7f53e4cbdc7b3157c35b97 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index 943edda..29b3f01 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -23,6 +23,10 @@ public abstract class Entity : LevelObject private Shader _shaderSpritesDefault; private SpriteRenderer[] _spriteRenderers; private AudioPlayerComponent _audioPlayerComponent; + private StatusHandler _statusHandler; + + // status modifiers + private float _speedStatusModifier = 1; //Enemy Spotted private bool _isEnemyDetected = false; @@ -36,11 +40,12 @@ public abstract class Entity : LevelObject _spriteRenderers = GetComponentsInChildren(true); _audioPlayerComponent = GetComponent(); Animation = gameObject.AddComponent(); + _statusHandler = gameObject.AddComponent(); } public virtual void Update() { Animation.AttackSpeedMultiplier = AttackSpeedMultiplier; - Animation.SpeedMultiplier = SpeedMultiplier; + Animation.SpeedMultiplier = SpeedMultiplier * SpeedStatusModifier; _lifeBar.gameObject.SetActive(_lifeBar.value <= 0.99f); } @@ -121,7 +126,7 @@ public abstract class Entity : LevelObject public int Hp => (int)(_hp * HpMultiplier); - public float Speed => _speed * SpeedMultiplier; + public float Speed => _speed * SpeedMultiplier * SpeedStatusModifier; public int AttackDamage { @@ -157,6 +162,11 @@ public abstract class Entity : LevelObject public SpriteRenderer[] SpriteRenderers { get { return _spriteRenderers; } } + public StatusHandler StatusHandler { + get => _statusHandler; + } + public float SpeedStatusModifier { get => _speedStatusModifier; set => _speedStatusModifier = value; } + #region [LevelManager code] public override bool Equals(ILevelObject other) { diff --git a/Assets/Scripts/Enum.cs b/Assets/Scripts/Enum.cs index 08bcd5c..e4cd7ed 100644 --- a/Assets/Scripts/Enum.cs +++ b/Assets/Scripts/Enum.cs @@ -13,4 +13,9 @@ public class Enum Farm = 2, BerryBush = 3 } + public enum StatusType + { + Slow = 0, + SpeedBoost = 1, + } } diff --git a/Assets/Scripts/Projectile.cs b/Assets/Scripts/Projectile.cs index f513ef9..1338c7b 100644 --- a/Assets/Scripts/Projectile.cs +++ b/Assets/Scripts/Projectile.cs @@ -22,7 +22,7 @@ public class Projectile : MonoBehaviour private Vector2 _vectorStart; private Vector2 _vectorEnd; - + private int _damage; private float _enemySpeed; private Entity _target; @@ -38,14 +38,14 @@ public class Projectile : MonoBehaviour private float _initialXDistance; private float _initialYDistance; - private void Start() + private void Start() { _rigidbodyProjectile = GetComponent(); _initialX = transform.position.x; _initialY = transform.position.y; _destinationX = _vectorEnd.x - _initialX - _enemySpeed; _destinationY = _vectorEnd.y - _initialY; - + _detectionLinked.gameObject.GetComponent().EntityLinked = _target; _detectionLinked.gameObject.GetComponent().ProjectileDamage = _damage; @@ -53,13 +53,13 @@ public class Projectile : MonoBehaviour _initialYDistance = Mathf.Abs(_initialY - _destinationY); } - private void Update() + protected virtual void Update() { if (straightProjectile) { - transform.position = Vector2.Lerp(new Vector2(_initialX, _initialY), - new Vector2(_vectorEnd.x, _vectorEnd.y), _time/_duration); + transform.position = Vector2.Lerp(new Vector2(_initialX, _initialY), + new Vector2(_vectorEnd.x, _vectorEnd.y), _time / _duration); DetStraigthArrowAngle(); @@ -70,15 +70,16 @@ public class Projectile : MonoBehaviour if (transform.position.x >= _vectorEnd.x) { + ApplyEffects(); Destroy(this.gameObject); } return; } float x = _speedTime; - float y = (_angle*-Mathf.Pow(x, 2) + _destinationX * x); + float y = (_angle * -Mathf.Pow(x, 2) + _destinationX * x); - transform.position = new Vector2(_initialX + x*_angle, _initialY + y); + transform.position = new Vector2(_initialX + x * _angle, _initialY + y); // Move projectile angle according to distance with target float lerpStep = (_destinationX - transform.position.x) / _initialXDistance; @@ -87,19 +88,20 @@ public class Projectile : MonoBehaviour _speedTime += _speed * Time.deltaTime; - if(y < 0) { + if (y < 0) + { Destroy(this.gameObject); } } - private void DetStraigthArrowAngle() + protected virtual void DetStraigthArrowAngle() { - if(_target != null) _enemyPosY = _target.Position.y; + if (_target != null) _enemyPosY = _target.Position.y; float angleX = (_destinationX) / _initialXDistance; float angleY = (_destinationY) / _initialYDistance; - + //Obtenir la difference entre la position Y du chateau et de l'ennemie. float diffY = transform.position.y - _enemyPosY; @@ -114,23 +116,26 @@ public class Projectile : MonoBehaviour //Si cette distance est plus petite qu'un certain nombre, on utilise un calcul differents //pour determine l'angle que la fleche doit prendre. if (angleX > 0.23) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY); - + //Si la position est negative, on utilise un calcul different pour determiner l'angle. //(Il faudra tester si ca marche lorsque le chateau pourrait tirer en arriere). else if (angleX >= 0) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleY / angleX); //Calcul utilise pour tenter de mieux faire fonctionner l'angle de la fleche lorsque l'ennemi est //proche de l'unite. - else { + else + { lerpStepS = -Mathf.Rad2Deg * Mathf.Atan(angleY / angleX); - } - + } + float angleS = Mathf.Lerp(lerpStepS, 0, 0); transform.eulerAngles = new Vector3(0, 0, angleS); } } + protected virtual void ApplyEffects() { } + //Getter and Setter public float EnemySpeed { diff --git a/Assets/Scripts/Projectile.meta b/Assets/Scripts/Projectile.meta new file mode 100644 index 0000000..579c88f --- /dev/null +++ b/Assets/Scripts/Projectile.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 796c5970b01ebd249b04e1a0598abc7c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Projectile/BolasProjectile.cs b/Assets/Scripts/Projectile/BolasProjectile.cs new file mode 100644 index 0000000..4107b6a --- /dev/null +++ b/Assets/Scripts/Projectile/BolasProjectile.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BolasProjectile : Projectile +{ + [SerializeField] + private float _slowIntensity = 0.25f; + private float _slowDuration = 5f; + + protected override void ApplyEffects() + { + if (Target.StatusHandler) + { + Target.StatusHandler.ApplySlow(_slowIntensity, _slowDuration); + } + } +} diff --git a/Assets/Scripts/Projectile/BolasProjectile.cs.meta b/Assets/Scripts/Projectile/BolasProjectile.cs.meta new file mode 100644 index 0000000..fd0561e --- /dev/null +++ b/Assets/Scripts/Projectile/BolasProjectile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: af32629f84318134799756134098abf9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Root.cs b/Assets/Scripts/Root.cs index 338cc8f..b5a6d3e 100644 --- a/Assets/Scripts/Root.cs +++ b/Assets/Scripts/Root.cs @@ -41,8 +41,7 @@ public class Root : MonoBehaviour _newArrow.GetComponent().EnemySpeed = _entity.Enemy.Speed; _newArrow.GetComponent().VectorStart = _rigidbodyAlly.position; _newArrow.GetComponent().VectorEnd = _rigidbodyOpponent.position; - _newArrow.GetComponent().Target = _entity.Enemy; - + _newArrow.GetComponent().Target = _entity.Enemy; } public void PlaySound(string soundName) diff --git a/Assets/Scripts/Status.meta b/Assets/Scripts/Status.meta new file mode 100644 index 0000000..d472446 --- /dev/null +++ b/Assets/Scripts/Status.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 53425a7650ca89b438da0796d0bd79ed +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Status/Slow.cs b/Assets/Scripts/Status/Slow.cs new file mode 100644 index 0000000..e282926 --- /dev/null +++ b/Assets/Scripts/Status/Slow.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Slow : Status +{ + private float _speedModifier; + + public override void Apply(float duration) + { + _duration += duration; + EntityLinked.SpeedStatusModifier *= _speedModifier; + } + + public override void Unapply() + { + EntityLinked.SpeedStatusModifier /= _speedModifier; + Destroy(this); + } + + /// + /// A higher intensity results in a stronger slow. + /// Example: An intensity of 0.99 multiplies the entity's speed by 0.01 (which would result in a really low speed) + /// + public float Intensity { + get => 1 - _speedModifier; + set => _speedModifier = _speedModifier == 0 ? 1 - value : _speedModifier + (1 - _speedModifier) * value; + } +} diff --git a/Assets/Scripts/Status/Slow.cs.meta b/Assets/Scripts/Status/Slow.cs.meta new file mode 100644 index 0000000..6904878 --- /dev/null +++ b/Assets/Scripts/Status/Slow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b89154fc4d657474e988151a13f82fc5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Status/Status.cs b/Assets/Scripts/Status/Status.cs new file mode 100644 index 0000000..7cf9095 --- /dev/null +++ b/Assets/Scripts/Status/Status.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public abstract class Status : MonoBehaviour +{ + private Entity entityLinked; + protected float _duration; + + protected virtual void Start() + { + EntityLinked = GetComponent(); + } + + protected virtual void Update() + { + _duration -= Time.deltaTime; + if ( _duration < 0 ) Unapply(); + } + + public abstract void Apply(float duration); + public abstract void Unapply(); + + public Entity EntityLinked { get => entityLinked; set => entityLinked = value; } + +} diff --git a/Assets/Scripts/Status/Status.cs.meta b/Assets/Scripts/Status/Status.cs.meta new file mode 100644 index 0000000..c0841ee --- /dev/null +++ b/Assets/Scripts/Status/Status.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8cd371169b5f23347994997e816d1d0f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/StatusHandler.cs b/Assets/Scripts/StatusHandler.cs new file mode 100644 index 0000000..3298566 --- /dev/null +++ b/Assets/Scripts/StatusHandler.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class StatusHandler : MonoBehaviour +{ + private Entity _entityLinked; + private Dictionary activeStatuses = new(); + + public void ApplySlow(float intensity, float duration) + { + Slow slow = (Slow)GetStatus(Enum.StatusType.Slow); + slow.Intensity = intensity; + slow.Apply(duration); + } + + // please add status to switch case everytime you design one! + private Status GetStatus(Enum.StatusType type) + { + Status status; + activeStatuses.TryGetValue(Enum.StatusType.Slow, out status); + if (!status) + { + switch (type) + { + case Enum.StatusType.Slow: + status = gameObject.AddComponent(); + break; + default: break; + } + } + status.EntityLinked = _entityLinked; + return status; + } + + private void Start() + { + _entityLinked = gameObject.GetComponent(); ; + } +} diff --git a/Assets/Scripts/StatusHandler.cs.meta b/Assets/Scripts/StatusHandler.cs.meta new file mode 100644 index 0000000..375babf --- /dev/null +++ b/Assets/Scripts/StatusHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e1a590a40aadfa24ab3c0d725467255f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: