diff --git a/Assets/Prefabs/Player Attacks/Slash.prefab b/Assets/Prefabs/Player Attacks/Slash.prefab index 086c111..f1674f9 100644 --- a/Assets/Prefabs/Player Attacks/Slash.prefab +++ b/Assets/Prefabs/Player Attacks/Slash.prefab @@ -122,6 +122,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: baseDamage: 10 + isDealtByPlayer: 1 --- !u!1 &8608725923624236417 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Deal_damage.cs b/Assets/Scripts/Deal_damage.cs index 0041381..594781e 100644 --- a/Assets/Scripts/Deal_damage.cs +++ b/Assets/Scripts/Deal_damage.cs @@ -6,6 +6,7 @@ public class Deal_damage : MonoBehaviour { // Fixed base damage (treat as const, its only not const to allow unity to serialize it) public float baseDamage = 15.0f; + public bool isDealtByPlayer = false; // How much damage is actually dealt by the attack private float damage = 0; @@ -15,13 +16,27 @@ private void OnTriggerEnter(Collider c) if (c.gameObject.GetComponent() != null) { damage = baseDamage + Level_manager.instance.precisionUpgradeModifier; // Recalculate damage on every hit, based on upgrade/pattern modifiers + + // Check if this damage is dealt by a player + if (isDealtByPlayer && !c.CompareTag("Player")) + { + // Spice of life upgrade - multiply damage depending on unique patterns found + int uniquePatterns = Level_manager.instance.uniquePatterns.Count; + + float originalDamage = damage; + damage = damage * uniquePatterns * Level_manager.instance.spiceLifeUpgradeModifier; + + Debug.Log("Damage collided, unique pattern multiplier: x" + uniquePatterns + ", original damage: " + originalDamage); + } + Health health = c.gameObject.GetComponent(); health.TakeDamage(damage); } } // Getters, Setters - public float Damage { + public float Damage + { get { return damage; } set { damage = value; } } diff --git a/Assets/Scripts/Level_manager.cs b/Assets/Scripts/Level_manager.cs index f9dd689..3330d86 100644 --- a/Assets/Scripts/Level_manager.cs +++ b/Assets/Scripts/Level_manager.cs @@ -10,7 +10,7 @@ public class Level_manager : MonoBehaviour { public static Level_manager instance; public bool isPaused = false; - + // Most upgrades the player can have at once public const int MAX_PLAYER_UPGRADES = 5; @@ -47,7 +47,7 @@ public class Level_manager : MonoBehaviour [System.NonSerialized] public List types = new List() { "Earth", "Fire", "Ice", "Wind" }; [System.NonSerialized] - public List typeColors = new List() { Color.green, Color.red, Color.blue, Color.cyan}; + public List typeColors = new List() { Color.green, Color.red, Color.blue, Color.cyan }; static Pattern_UI_manager pat_man; [Header("Patterns")] [SerializeField] @@ -62,7 +62,7 @@ public class Level_manager : MonoBehaviour //FIXME: Add this to a game_constants file [System.NonSerialized] public List> Patterns = new List>(); - + public HashSet<(int, int)> uniquePatterns = new HashSet<(int, int)>(); //FIXME: Add to game_constants [System.NonSerialized] @@ -164,7 +164,7 @@ private void Awake() //Makes levelmanager callable in any script: Level_manager. // Start is called before the first frame update void Start() - { + { // Give self 0 coins to set HUD currency GainCoin(0); MusicManager = Instantiate(musicManagerPrefab); @@ -270,26 +270,31 @@ void Dummy() Debug.Log("Dummy key pressed"); } - public void GainCoin(int val) { + public void GainCoin(int val) + { Currency += val; T_Currency.text = Currency.ToString() + " CHIPS"; } - public void SetMaxHealth(float val){ + public void SetMaxHealth(float val) + { PlayerMaxHealth = val; } - public void SetHealth(float val){ + public void SetHealth(float val) + { PlayerHealth = val; - healthBar.SetProgress(PlayerHealth/PlayerMaxHealth); + healthBar.SetProgress(PlayerHealth / PlayerMaxHealth); } //---------------------------------Functions for Patterns---------------------------- - public static void AddPatternUI(GameObject new_pat_man){ + public static void AddPatternUI(GameObject new_pat_man) + { pat_man = new_pat_man.GetComponent(); } - public void UpdatePattern(int type) { + public void UpdatePattern(int type) + { // Adds a type to the pattern record. Should be called whenever an enemy is killed. // This then checks the Pattern Record to see if any Patterns have occurred. AddToPattern(type); @@ -303,7 +308,12 @@ public void UpdatePattern(int type) { } currentPattern = success; - if (pat_man != null){ + + // add this pattern to the hashset to find the # of unique patterns so far + uniquePatterns.Add(success); + + if (pat_man != null) + { pat_man.UpdatePatternName(pat); pat_man.UpdateQueueColors(type, subpat.Item1, subpat.Item2); } @@ -314,12 +324,14 @@ void AddToPattern(int type) Debug.Log($"Add to Pattern {type}"); //Add the passed type to the pattern_record Pattern_record.Add(type); - if (Pattern_record.Count > MAX_PATTERN_LEN) { + if (Pattern_record.Count > MAX_PATTERN_LEN) + { Pattern_record.Remove(Pattern_record[0]); } } - int TypeToChar(){ + int TypeToChar() + { return TypeToChar(Pattern_record.Count, 0); } int TypeToChar(int start, int end) @@ -338,26 +350,29 @@ int TypeToChar(int start, int end) Translations.Add(t, counter); counter++; } - ret += (int)(Mathf.Pow(10, start-i) * Translations[t]); + ret += (int)(Mathf.Pow(10, start - i) * Translations[t]); } return ret; } - ((int, int), (int, int)) CheckPatterns(){ - return CheckPatterns(-1, Pattern_record.Count-1, 0); + ((int, int), (int, int)) CheckPatterns() + { + return CheckPatterns(-1, Pattern_record.Count - 1, 0); } ((int, int), (int, int)) CheckPatterns(int Seq_in, int start, int end) { - if(Seq_in == 0){return ((-1, -1), (-1, -1)); } + if (Seq_in == 0) { return ((-1, -1), (-1, -1)); } int Seq = Seq_in; - if(Seq_in == -1){ - if (start < end){ + if (Seq_in == -1) + { + if (start < end) + { return ((-1, -1), (-1, -1)); } Seq = TypeToChar(start, end); } - int l = start-end; + int l = start - end; int s = Pattern_record.Count - 1; //Loop through all patterns of size and smaller for (int i = 0; i < Patterns[l].Count; i++) @@ -370,23 +385,26 @@ int TypeToChar(int start, int end) } //Go to smaller pattern if no pattern found in that list. //Left - ((int, int), (int, int)) left = CheckPatterns(-1, start, end+1); + ((int, int), (int, int)) left = CheckPatterns(-1, start, end + 1); (int, int) sub_left = left.Item1; //Right - ((int, int), (int, int)) right = CheckPatterns(-1, start-1, end); + ((int, int), (int, int)) right = CheckPatterns(-1, start - 1, end); (int, int) sub_right = right.Item1; - Debug.Log($"Comparing {left} to {right} :: {sub_left.Item1} > {sub_right.Item1}? {sub_left.Item1>sub_right.Item1}-{sub_left.Item2} > {sub_right.Item2}? {sub_left.Item2>sub_right.Item2}"); + Debug.Log($"Comparing {left} to {right} :: {sub_left.Item1} > {sub_right.Item1}? {sub_left.Item1 > sub_right.Item1}-{sub_left.Item2} > {sub_right.Item2}? {sub_left.Item2 > sub_right.Item2}"); - if (sub_left.Item1 == sub_right.Item1){ + if (sub_left.Item1 == sub_right.Item1) + { return sub_left.Item2 > sub_right.Item2 ? left : right; } return sub_left.Item1 > sub_right.Item1 ? left : right; } - public void UsePattern(){ + public void UsePattern() + { //Use the current Pattern's ability string patternName = ""; - if(currentPattern.Item1 != -1){ + if (currentPattern.Item1 != -1) + { //Update the name for debugging and use ability patternName = Patterns[currentPattern.Item1][currentPattern.Item2].Item2; int l = currentPattern.Item1; //length @@ -400,16 +418,19 @@ public void UsePattern(){ pat_man.ClearQueue(); } - void ClearPatternQueue(){ + void ClearPatternQueue() + { Pattern_record.RemoveAll(c => true); } //Sets the leftmost and rightmost points of the room - used for pattern func sweeps - public void SetLeftPoint(Transform t){ + public void SetLeftPoint(Transform t) + { Left_point = t; } - public void SetRightPoint(Transform t){ - Right_point = t; + public void SetRightPoint(Transform t) + { + Right_point = t; } // Pause menu @@ -530,7 +551,8 @@ public bool AddPlayerUpgrade(Upgrade upgrade, GameObject shop) GainCoin(-1 * upgrade.Cost); return true; } - else { + else + { // U ARE TOO BROKE TO AFFORD UPGRADE return false; } @@ -566,7 +588,7 @@ public void SwapOutUpgrade(Upgrade newUpgrade, GameObject shop, Vector2 original Destroy(PlayerHeldUpgradeIcons[CurrentlySelectedUpgradeIndex].GetComponent().upgradeUIIcon); Destroy(PlayerHeldUpgradeIcons[CurrentlySelectedUpgradeIndex]); - + Debug.Log("Replacing upgrade: " + PlayerHeldUpgradeIcons[CurrentlySelectedUpgradeIndex].GetComponent().upgrade.Name + " (Upgrade slot index " + CurrentlySelectedUpgradeIndex + ")"); PlayerHeldUpgradeIcons[CurrentlySelectedUpgradeIndex] = upgradeUIIcon; @@ -577,8 +599,10 @@ public void SwapOutUpgrade(Upgrade newUpgrade, GameObject shop, Vector2 original // Called when upgrades are added to the player held upgrades list, essentially applies the effects of upgrades. // POST-MVP: implement more effects - void ApplyUpgradeModifiers(Upgrade upgrade) { - switch (upgrade.Name) { + void ApplyUpgradeModifiers(Upgrade upgrade) + { + switch (upgrade.Name) + { case "Precision": precisionUpgradeModifier += precisionUpgradeModifierValue; upgrade.N = precisionUpgradeModifier; @@ -624,7 +648,7 @@ void ApplyUpgradeModifiers(Upgrade upgrade) { break; } upgrade.UpdateDesc(); - if (Shop_room_setup.instance != null) + if (Shop_room_setup.instance != null) { Shop_room_setup.instance.UpdateShopItemLabel(upgrade); } @@ -632,7 +656,8 @@ void ApplyUpgradeModifiers(Upgrade upgrade) { // Called when upgrades are removed from the player held upgrades list, essentially removes the effects of upgrades. // POST-MVP: implement more effects - void RemoveUpgradeModifiers(Upgrade upgrade) { + void RemoveUpgradeModifiers(Upgrade upgrade) + { switch (upgrade.Name) { case "Precision": @@ -656,7 +681,7 @@ void RemoveUpgradeModifiers(Upgrade upgrade) { upgrade.N = bootUpUpgradeModifier; break; case "Spice of Life": - spiceLifeUpgradeModifier= 0; + spiceLifeUpgradeModifier = 0; upgrade.N = spiceLifeUpgradeModifier; break; case "Git Restore": diff --git a/Assets/Scripts/Player_input_manager.cs b/Assets/Scripts/Player_input_manager.cs index 0ed3dec..00d6c09 100644 --- a/Assets/Scripts/Player_input_manager.cs +++ b/Assets/Scripts/Player_input_manager.cs @@ -73,7 +73,7 @@ void Start() RotatePlayerToMousePoint(); } - + void Update() { // If the player is dashing, continue with fixed velocity, reject new player inputs @@ -89,7 +89,7 @@ void Update() AimToMousePoint(); RotatePlayerToMousePoint(); } - + // If dash input pressed and the dash is not on cooldown, execute the dash if (dashInput && !Cooldown_manager.instance.IsDashOnCooldown) { @@ -97,22 +97,24 @@ void Update() } // If interact input pressed and an interactable object has been set, execute interaction behavior with it. - if (interactInput && interactable) + if (interactInput && interactable) { Interact(interactable); } - else if(interactInput){ + else if (interactInput) + { // Use e for pattern activation if there's no interactable Level_manager.instance.UsePattern(); } // If fireProjectile input pressed and the projectile is not on cooldown, fire the projectile - if (fireProjectileInput && !Cooldown_manager.instance.IsFireProjectileOnCooldown) + if (fireProjectileInput && !Cooldown_manager.instance.IsFireProjectileOnCooldown) { FireProjectile(); } - if (attackInput && !Cooldown_manager.instance.IsSlashOnCooldown && !Level_manager.instance.IsCurrentlySelectingUpgrade){ + if (attackInput && !Cooldown_manager.instance.IsSlashOnCooldown && !Level_manager.instance.IsCurrentlySelectingUpgrade) + { BasicAttack(); } } @@ -140,7 +142,7 @@ void MovePlayer() moveDirection = up * verticalInput + right * horizontalInput; // Store the last non-zero moveDirection as the orientation - if (!moveDirection.Equals(new Vector3(0, 0, 0))) + if (!moveDirection.Equals(new Vector3(0, 0, 0))) { orientation = moveDirection.normalized; } @@ -148,7 +150,7 @@ void MovePlayer() // Add the forces in direction specified by moveDirection and speed specified by moveSpeed float speed = moveSpeed * (Level_manager.instance.PF.isBoosted ? boostedMult : 1f); rb.AddForce(moveDirection.normalized * speed, ForceMode.Force); - + } void StartDash(Vector3 vect) @@ -162,7 +164,7 @@ void StartDash(Vector3 vect) void Interact(GameObject interactable) { // If the other GameObject is a ShopItem and the shop is active, buy the item. - if (interactable.CompareTag("ShopItem") && interactable.GetComponent().IsShopActive) + if (interactable.CompareTag("ShopItem") && interactable.GetComponent().IsShopActive) { interactable.GetComponent().buy(); return; @@ -176,9 +178,13 @@ void Interact(GameObject interactable) // Instantiates a projectile that moves toward the position defined by aimPoint at the time of firing void FireProjectile() - { + { // Projectile starts at the position of the "nose" of the player GameObject projectile = Instantiate(projectilePrefab, new Vector3(transform.Find("Forward").position.x, ProjectilePlaneY, transform.Find("Forward").position.z), transform.rotation); + + // mark as being from the player + projectile.GetComponent().isDealtByPlayer = true; + projectile.transform.LookAt(aimPoint); projectile.layer = 7; // Set to PlayerProjectiles layer, this makes it so it can only hit enemies and obstacles, but not the player. Cooldown_manager.instance.UpdateFireProjectileCooldown(); @@ -187,6 +193,7 @@ void FireProjectile() void BasicAttack() { GameObject Slash = Instantiate(slashPrefab, new Vector3(transform.Find("Forward").position.x, transform.position.y, transform.Find("Forward").position.z), transform.rotation); + Slash.transform.parent = transform; Cooldown_manager.instance.UpdateSlashCooldown(); } @@ -257,10 +264,10 @@ public GameObject Interactable } public Vector3 AimPoint - { - get { return aimPoint; } - set { aimPoint = value; } + { + get { return aimPoint; } + set { aimPoint = value; } } - + } diff --git a/Assets/Scripts/Projectile.cs b/Assets/Scripts/Projectile.cs index 0d9619d..751f9bb 100644 --- a/Assets/Scripts/Projectile.cs +++ b/Assets/Scripts/Projectile.cs @@ -28,18 +28,21 @@ private void OnTriggerEnter(Collider other) health.TakeDamage(damage); } - if(!Indestructable){ Destroy(gameObject); } + if (!Indestructable) { Destroy(gameObject); } } - - public void SetLifetime(float new_lifetime){ + + public void SetLifetime(float new_lifetime) + { lifetime = new_lifetime; } - public float GetSpeed(){ + public float GetSpeed() + { return speed; } - public void SetAsIndestructable(bool indestructable){ + public void SetAsIndestructable(bool indestructable) + { Indestructable = indestructable; } }