Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Assets/Prefabs/Player Attacks/Slash.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
baseDamage: 10
isDealtByPlayer: 1
--- !u!1 &8608725923624236417
GameObject:
m_ObjectHideFlags: 0
Expand Down
17 changes: 16 additions & 1 deletion Assets/Scripts/Deal_damage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,13 +16,27 @@ private void OnTriggerEnter(Collider c)
if (c.gameObject.GetComponent<Health>() != 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>();
health.TakeDamage(damage);
}
}

// Getters, Setters
public float Damage {
public float Damage
{
get { return damage; }
set { damage = value; }
}
Expand Down
99 changes: 62 additions & 37 deletions Assets/Scripts/Level_manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class Level_manager : MonoBehaviour
[System.NonSerialized]
public List<string> types = new List<string>() { "Earth", "Fire", "Ice", "Wind" };
[System.NonSerialized]
public List<Color> typeColors = new List<Color>() { Color.green, Color.red, Color.blue, Color.cyan};
public List<Color> typeColors = new List<Color>() { Color.green, Color.red, Color.blue, Color.cyan };
static Pattern_UI_manager pat_man;
[Header("Patterns")]
[SerializeField]
Expand All @@ -62,7 +62,7 @@ public class Level_manager : MonoBehaviour
//FIXME: Add this to a game_constants file
[System.NonSerialized]
public List<List<(int, string, Action)>> Patterns = new List<List<(int, string, Action)>>();

public HashSet<(int, int)> uniquePatterns = new HashSet<(int, int)>();

//FIXME: Add to game_constants
[System.NonSerialized]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Pattern_UI_manager>();
}

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);
Expand All @@ -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);
}
Expand All @@ -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)
Expand All @@ -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++)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -566,7 +588,7 @@ public void SwapOutUpgrade(Upgrade newUpgrade, GameObject shop, Vector2 original

Destroy(PlayerHeldUpgradeIcons[CurrentlySelectedUpgradeIndex].GetComponent<Upgrade_manager>().upgradeUIIcon);
Destroy(PlayerHeldUpgradeIcons[CurrentlySelectedUpgradeIndex]);


Debug.Log("Replacing upgrade: " + PlayerHeldUpgradeIcons[CurrentlySelectedUpgradeIndex].GetComponent<Upgrade_manager>().upgrade.Name + " (Upgrade slot index " + CurrentlySelectedUpgradeIndex + ")");
PlayerHeldUpgradeIcons[CurrentlySelectedUpgradeIndex] = upgradeUIIcon;
Expand All @@ -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;
Expand Down Expand Up @@ -624,15 +648,16 @@ 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);
}
}

// 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":
Expand All @@ -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":
Expand Down
Loading