From ddf2466cd89bc8e48f78baafc8b9be591af3ddd9 Mon Sep 17 00:00:00 2001 From: kong Date: Tue, 6 Feb 2024 12:54:21 +0700 Subject: [PATCH] Game Prototype V0.20.1 Bullet System - fix Bullet System --- Assets/Resources/CheesePlayerMulti.prefab | 6 +++--- .../Scripts/Systems/Bullet/BulletIgnition.cs | 20 +++++++++++-------- .../Systems/Bullet/Enemy/EnemySpawnBullet.cs | 4 ++-- .../Bullet/Player/PlayerSpawnBullet.cs | 4 ++-- .../Character/CharacterStateMachine.cs | 2 +- .../Enemies/StateMachine/EnemyAttackState.cs | 2 +- .../Enemies/StateMachine/EnemyState.cs | 4 ++-- .../StrategyPattern/BulletFireManeuver.cs | 4 ++-- .../Enemies/StrategyPattern/EnemyManeuver.cs | 5 ++++- .../ProjectileReflectionBulletFireManeuver.cs | 5 +++-- .../RandomBulletFireManeuver.cs | 1 + .../SingleBulletFireManeuver.cs | 1 + .../SurroundBulletFireManeuver.cs | 1 + .../TriBulletFireManeuver.cs | 1 + Assets/Scripts/Systems/Weapon/WeaponSystem.cs | 4 ++++ .../Strategy Pattern/IManeuverBehaviour.cs | 6 ++++-- .../Util/Strategy Pattern/StrategyPattern.cs | 2 +- 17 files changed, 45 insertions(+), 27 deletions(-) diff --git a/Assets/Resources/CheesePlayerMulti.prefab b/Assets/Resources/CheesePlayerMulti.prefab index a617a6b4..a8a16d59 100644 --- a/Assets/Resources/CheesePlayerMulti.prefab +++ b/Assets/Resources/CheesePlayerMulti.prefab @@ -238,7 +238,7 @@ MonoBehaviour: m_triggerEnterEvent: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 0} + - m_Target: {fileID: 6300914170578224804} m_TargetAssemblyTypeName: GDD.PlayerSystem, Assembly-CSharp m_MethodName: OnEnterSpinWheel m_Mode: 0 @@ -253,7 +253,7 @@ MonoBehaviour: m_triggerStayEvent: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 0} + - m_Target: {fileID: 6300914170578224804} m_TargetAssemblyTypeName: GDD.PlayerSystem, Assembly-CSharp m_MethodName: OnDoorEnter m_Mode: 0 @@ -268,7 +268,7 @@ MonoBehaviour: m_triggerExitEvent: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 0} + - m_Target: {fileID: 6300914170578224804} m_TargetAssemblyTypeName: GDD.PlayerSystem, Assembly-CSharp m_MethodName: OnDoorExit m_Mode: 0 diff --git a/Assets/Scripts/Systems/Bullet/BulletIgnition.cs b/Assets/Scripts/Systems/Bullet/BulletIgnition.cs index 5ac28149..94f766bd 100644 --- a/Assets/Scripts/Systems/Bullet/BulletIgnition.cs +++ b/Assets/Scripts/Systems/Bullet/BulletIgnition.cs @@ -45,11 +45,12 @@ public virtual void Update() } - public virtual List OnSpawnBullet(float distance, float power, int shot, float damge, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null) + public virtual List OnSpawnBullet(float distance, float power, int shot, float damge, Transform target, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null) { if (shotMode == BulletShotMode.SurroundMode) return OnIgnitionBulletSurround(builder, m_spawnPoint, + target, type, distance, power, @@ -57,7 +58,7 @@ public virtual List OnSpawnBullet(float distance, float power, int s damge, surroundMode); else - return OnIgnitionBulletRandom(builder, m_spawnPoint, distance, power, shot, damge); + return OnIgnitionBulletRandom(builder, m_spawnPoint, target, distance, power, shot, damge); } public virtual void OnSpawnGrenade(int shot, float damge, int[] posIndex = default, ObjectPoolBuilder builder = null) @@ -67,14 +68,14 @@ public virtual void OnSpawnGrenade(int shot, float damge, int[] posIndex = defau OnProjectileLaunch(builder, m_spawnPoint, shot, damge, posIndex); } - public List OnIgnitionBulletSurround(ObjectPoolBuilder builder, Transform spawnPoint, BulletType _type, float distance, float power, int shot, float damage, BulletShotSurroundMode surroundMode) + public List OnIgnitionBulletSurround(ObjectPoolBuilder builder, Transform spawnPoint, Transform target, BulletType _type, float distance, float power, int shot, float damage, BulletShotSurroundMode surroundMode) { - int current_axis = 0; - int surrounded_axis; + float current_axis = 0; + float surrounded_axis; int helf_axis = 0; if (surroundMode == BulletShotSurroundMode.Surround) { - surrounded_axis = 360 / shot; + surrounded_axis = 360.0f / shot; } else { @@ -84,6 +85,10 @@ public List OnIgnitionBulletSurround(ObjectPoolBuilder builder, Tran bullets = new List(); + //Aim to target + Quaternion lookAt = Quaternion.LookRotation(target.position - spawnPoint.position); + current_axis += lookAt.eulerAngles.y - transform.eulerAngles.y; + if(bullet_rot_spawn == null) bullet_rot_spawn = new GameObject("bullet rot spawn"); @@ -103,7 +108,6 @@ public List OnIgnitionBulletSurround(ObjectPoolBuilder builder, Tran else if (surroundMode == BulletShotSurroundMode.Back) spawnPoint.rotation = transform.rotation * Quaternion.Euler(new Vector3(0, (helf_axis / 2) + 90, 0)); - spawnPoint.rotation *= rot; //Rot @@ -123,7 +127,7 @@ public List OnIgnitionBulletSurround(ObjectPoolBuilder builder, Tran return bullets; } - public List OnIgnitionBulletRandom(ObjectPoolBuilder builder, Transform spawnPoint, float distance, float power, int shot, float damage) + public List OnIgnitionBulletRandom(ObjectPoolBuilder builder, Transform spawnPoint, Transform target, float distance, float power, int shot, float damage) { int current_axis = 0; int surrounded_axis; diff --git a/Assets/Scripts/Systems/Bullet/Enemy/EnemySpawnBullet.cs b/Assets/Scripts/Systems/Bullet/Enemy/EnemySpawnBullet.cs index c8ea4f94..6028b711 100644 --- a/Assets/Scripts/Systems/Bullet/Enemy/EnemySpawnBullet.cs +++ b/Assets/Scripts/Systems/Bullet/Enemy/EnemySpawnBullet.cs @@ -22,9 +22,9 @@ public override void Start() } - public override List OnSpawnBullet(float distance, float power, int shot, float damage, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null) + public override List OnSpawnBullet(float distance, float power, int shot, float damage, Transform target, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null) { - return base.OnSpawnBullet(distance, power, shot, damage, type, surroundMode, shotMode, _bulletObjectPool); + return base.OnSpawnBullet(distance, power, shot, damage, target, type, surroundMode, shotMode, _bulletObjectPool); } public override void OnSpawnGrenade(int shot, float damge, int[] posIndex = default, ObjectPoolBuilder builder = null) diff --git a/Assets/Scripts/Systems/Bullet/Player/PlayerSpawnBullet.cs b/Assets/Scripts/Systems/Bullet/Player/PlayerSpawnBullet.cs index d5e622ca..ef649ec2 100644 --- a/Assets/Scripts/Systems/Bullet/Player/PlayerSpawnBullet.cs +++ b/Assets/Scripts/Systems/Bullet/Player/PlayerSpawnBullet.cs @@ -21,9 +21,9 @@ public override void Start() _bulletObjectPool = gameObject.AddComponent(); } - public override List OnSpawnBullet(float distance, float power, int shot, float damage, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null) + public override List OnSpawnBullet(float distance, float power, int shot, float damage,Transform target, BulletType type, BulletShotSurroundMode surroundMode, BulletShotMode shotMode, ObjectPoolBuilder builder = null) { - return base.OnSpawnBullet(distance, power, shot, damage, type, surroundMode, shotMode, _bulletObjectPool); + return base.OnSpawnBullet(distance, power, shot, damage, target, type, surroundMode, shotMode, _bulletObjectPool); } public override void OnSpawnGrenade(int shot, float damge, int[] posIndex = default, ObjectPoolBuilder builder = null) diff --git a/Assets/Scripts/Systems/Character/CharacterStateMachine.cs b/Assets/Scripts/Systems/Character/CharacterStateMachine.cs index 3bded018..317d94c6 100644 --- a/Assets/Scripts/Systems/Character/CharacterStateMachine.cs +++ b/Assets/Scripts/Systems/Character/CharacterStateMachine.cs @@ -14,7 +14,7 @@ public class CharacterStateMachine : StateMachine protected PlayerSpawnBullet PlayerSpawnBullet; protected bool _is_Start_Fire = false; protected List _coroutines = new List(); - + protected virtual void OnEnable() { diff --git a/Assets/Scripts/Systems/Character/Enemies/StateMachine/EnemyAttackState.cs b/Assets/Scripts/Systems/Character/Enemies/StateMachine/EnemyAttackState.cs index ca864724..2d2fe395 100644 --- a/Assets/Scripts/Systems/Character/Enemies/StateMachine/EnemyAttackState.cs +++ b/Assets/Scripts/Systems/Character/Enemies/StateMachine/EnemyAttackState.cs @@ -29,7 +29,7 @@ public override void OnStart(EnemySystem contrller) //Get New Target GetNewTarget(contrller.SetTargetRandom()); - ApplyEnemyStrategy(); + ApplyEnemyStrategy(target); } protected void GetNewTarget(int targetID) diff --git a/Assets/Scripts/Systems/Character/Enemies/StateMachine/EnemyState.cs b/Assets/Scripts/Systems/Character/Enemies/StateMachine/EnemyState.cs index 9189e69a..c12a1101 100644 --- a/Assets/Scripts/Systems/Character/Enemies/StateMachine/EnemyState.cs +++ b/Assets/Scripts/Systems/Character/Enemies/StateMachine/EnemyState.cs @@ -39,11 +39,11 @@ public override void OnExit() base.OnExit(); } - public void ApplyEnemyStrategy() + public void ApplyEnemyStrategy(Transform target) { strategy = GetComponent(); //print("Apply Enemy Strategy"); - strategy.Maneuver(this); + strategy.Maneuver(this, this.target); } public void WithdrawEnemyStrategy() diff --git a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/BulletFireManeuver.cs b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/BulletFireManeuver.cs index 35806751..1eddfe59 100644 --- a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/BulletFireManeuver.cs +++ b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/BulletFireManeuver.cs @@ -57,9 +57,9 @@ public override void Start() base.Start(); } - public override void Maneuver(EnemyState pawn) + public override void Maneuver(EnemyState pawn, Transform target) { - base.Maneuver(pawn); + base.Maneuver(pawn, target); if (_player == null) { diff --git a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/EnemyManeuver.cs b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/EnemyManeuver.cs index 728d03e2..2d30de3d 100644 --- a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/EnemyManeuver.cs +++ b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/EnemyManeuver.cs @@ -15,6 +15,7 @@ public class EnemyManeuver : StrategyPattern protected PlayerSystem _player; protected EnemySystem _enemySystem; protected EnemyAttackState _enemyAttackState; + protected Transform _target; protected virtual void Awake() { @@ -28,8 +29,10 @@ public virtual void Start() _enemySystem = GetComponent(); } - public override void Maneuver(EnemyState pawn) + public override void Maneuver(EnemyState pawn, Transform target) { + _target = target; + if(GM.players.Count <= 0) return; diff --git a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/ProjectileReflectionBullet/ProjectileReflectionBulletFireManeuver.cs b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/ProjectileReflectionBullet/ProjectileReflectionBulletFireManeuver.cs index 13d76d4d..0dd561a1 100644 --- a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/ProjectileReflectionBullet/ProjectileReflectionBulletFireManeuver.cs +++ b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/ProjectileReflectionBullet/ProjectileReflectionBulletFireManeuver.cs @@ -29,12 +29,12 @@ public override void Start() _punECC.OnProjectileReflectionLinesEnable(true); } - public override void Maneuver(EnemyState pawn) + public override void Maneuver(EnemyState pawn, Transform target) { _punECC.OnProjectileReflectionLinesEnable(true); OnShowProjectileReflectionLines(); - base.Maneuver(pawn); + base.Maneuver(pawn, target); } public override void Truce() @@ -64,6 +64,7 @@ public override void ToggleFire(EnemySpawnBullet enemySpawnBullet, int[] posInde _enemyBulletConfig.bullet_power, _enemyBulletConfig.shot, _enemyBulletConfig.damage, + _target, _enemyBulletConfig.bulletType, BulletShotSurroundMode.Front, BulletShotMode.SurroundMode diff --git a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/RandomBulletFireManeuver.cs b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/RandomBulletFireManeuver.cs index f71b974e..97818597 100644 --- a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/RandomBulletFireManeuver.cs +++ b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/RandomBulletFireManeuver.cs @@ -71,6 +71,7 @@ public override void ToggleFire(EnemySpawnBullet enemySpawnBullet, int[] posInde _enemyBulletConfig.bullet_power, _enemyBulletConfig.shot, _enemyBulletConfig.damage, + _target, _enemyBulletConfig.bulletType, BulletShotSurroundMode.Back, BulletShotMode.RandomMode diff --git a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/SingleBulletFireManeuver.cs b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/SingleBulletFireManeuver.cs index eb79f515..0fb8c9e6 100644 --- a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/SingleBulletFireManeuver.cs +++ b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/SingleBulletFireManeuver.cs @@ -19,6 +19,7 @@ public override void ToggleFire(EnemySpawnBullet enemySpawnBullet, int[] posInde _enemyBulletConfig.bullet_power, _enemyBulletConfig.shot, _enemyBulletConfig.damage, + _target, _enemyBulletConfig.bulletType, BulletShotSurroundMode.Surround, BulletShotMode.SurroundMode diff --git a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/SurroundBulletFireManeuver.cs b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/SurroundBulletFireManeuver.cs index e2148b22..8a59d532 100644 --- a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/SurroundBulletFireManeuver.cs +++ b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/SurroundBulletFireManeuver.cs @@ -19,6 +19,7 @@ public override void ToggleFire(EnemySpawnBullet enemySpawnBullet, int[] posInde _enemyBulletConfig.bullet_power, _enemyBulletConfig.shot, _enemyBulletConfig.damage, + _target, _enemyBulletConfig.bulletType, BulletShotSurroundMode.Surround, BulletShotMode.SurroundMode diff --git a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/TriBulletFireManeuver.cs b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/TriBulletFireManeuver.cs index 42ebe29f..8e9757c2 100644 --- a/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/TriBulletFireManeuver.cs +++ b/Assets/Scripts/Systems/Character/Enemies/StrategyPattern/RectilinearBullet/TriBulletFireManeuver.cs @@ -19,6 +19,7 @@ public override void ToggleFire(EnemySpawnBullet enemySpawnBullet, int[] posInde _enemyBulletConfig.bullet_power, _enemyBulletConfig.shot, _enemyBulletConfig.damage, + _target, _enemyBulletConfig.bulletType, BulletShotSurroundMode.Front, BulletShotMode.SurroundMode diff --git a/Assets/Scripts/Systems/Weapon/WeaponSystem.cs b/Assets/Scripts/Systems/Weapon/WeaponSystem.cs index 4a81bed3..76be9422 100644 --- a/Assets/Scripts/Systems/Weapon/WeaponSystem.cs +++ b/Assets/Scripts/Systems/Weapon/WeaponSystem.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using GDD.Spatial_Partition; using UnityEngine; using UnityEngine.Serialization; @@ -183,6 +184,8 @@ public void ToggleFire(PlayerSpawnBullet playerSpawnBullet) if(_weapon == null) return; + IPawn closestEnemy = GM.grid.FindClosestEnemy(_characterSystem); + playerSpawnBullet.bulletObjectPool.weapon = _weapon; playerSpawnBullet.bulletObjectPool.Set_GameObject = _weapon.bulletObject; playerSpawnBullet.OnSpawnBullet( @@ -190,6 +193,7 @@ public void ToggleFire(PlayerSpawnBullet playerSpawnBullet) _weapon.power, _weapon.shot, _weapon.damage, + closestEnemy.GetPawnTransform(), BulletType.Rectilinear, _weapon.surroundMode, _weapon.bulletShotMode diff --git a/Assets/Scripts/Util/Strategy Pattern/IManeuverBehaviour.cs b/Assets/Scripts/Util/Strategy Pattern/IManeuverBehaviour.cs index e6a0b4c1..decd2721 100644 --- a/Assets/Scripts/Util/Strategy Pattern/IManeuverBehaviour.cs +++ b/Assets/Scripts/Util/Strategy Pattern/IManeuverBehaviour.cs @@ -1,8 +1,10 @@ -namespace GDD.StrategyPattern +using UnityEngine; + +namespace GDD.StrategyPattern { public interface IManeuverBehaviour { - public abstract void Maneuver(T pawn); + public abstract void Maneuver(T pawn, Transform target); public abstract void Truce(); } diff --git a/Assets/Scripts/Util/Strategy Pattern/StrategyPattern.cs b/Assets/Scripts/Util/Strategy Pattern/StrategyPattern.cs index 6d42fbd9..bada817c 100644 --- a/Assets/Scripts/Util/Strategy Pattern/StrategyPattern.cs +++ b/Assets/Scripts/Util/Strategy Pattern/StrategyPattern.cs @@ -12,7 +12,7 @@ public virtual void Start() GM = GameManager.Instance; } - public abstract void Maneuver(T pawn); + public abstract void Maneuver(T pawn, Transform target); public abstract void Truce(); }