Untitled
unknown
plain_text
11 days ago
18 kB
4
Indexable
Never
using System.IO; using Core.Steams; using UnityEngine; using UnityEngine.UI; using System.Xml.Linq; #if !STEAM_ENABLED using Scoreboards; #endif public class PlayerStats : MonoBehaviour { public bool isAlive; public float speed; public int speed_stacks; public float atk_speed; public int atk_speed_stacks; public float atk_damage; public int atk_stacks; public float critical_chance; public float critical_multiplier; public float life_steal; public float max_hp; public float hp; public int hp_stacks; public float hp_regen; public float renew_stacks; public float armor; public int armor_stacks; public int revive_count; public int revive_cd; public float i_window; public float jump_force; public int impulse_stacks; public float proj_size; public float proj_fragments; public float body_damage; float burning_cd = 0; public int proj_hits; public int jump_number; public float projectile_acceleration; public int thunder_projs; public int cards_plus; public int shield_lvl; public bool shield_up; public int healing_orb_lvl; public int orb_charge; public int focus_lvl; public float tome_lvl; public int friction_lvl; public int rage_lvl; public float rage_damage; public float rage_body_damage; public int wound_lvl; public int willo_lvl; public GameObject willowisp; public int shrink_lvl; public int soul_orb_level; public int charge_stacks; public int cold_lvl; //Trascendent [Space] public bool thundergod = false; public bool vampire = false; public bool ram_destroyer = false; public bool bloody_mage = false; public bool anti_air = false; public bool flying = false; public bool colossus = false; public bool gnome = false; public bool hoarder = false; public bool protector = false; public bool sadistic = false; public bool marksman = false; public bool dealer = false; public bool blessed = false; public bool white_dwarf = false; public bool burning_man = false; public bool exorcist = false; public bool comet = false; public bool streamer = false; public bool pacman = false; public bool absorbent = false; public bool plague_spreader = false; public bool speculator = false; public bool bunker = false; public bool desperate = false; public bool enchanter = false; public bool avenger = false; public bool nerd = false; public bool tryhard = false; public bool bulldozer = false; public bool freezer = false; [Space] public float i_window_timer; float regen_ticker = 1; public float shield_cooldown; public SpriteRenderer shield_sprite; public float black_hole_cooldown = 1; //Player UI [Space] public Slider hp_bar; public Text hp_count; public SpriteRenderer player_graph; public GameObject EndGame; public GameObject Loading; public GameObject CouldNotLoad; public GameObject Scoreboard; public GameObject Name_Input; //Sound [Space] public AudioSource audio_source; public AudioClip hurt_audio; public AudioClip shield_begin_audio; public AudioClip shield_break_audio; public AudioClip game_over_sound; //Staff [Space] public int staff = 0; public Image staff_ui_graphic; public SpriteRenderer staff_graphic; public Sprite normal_staff; public Sprite homing_staff; public Sprite triple_staff; public Sprite explosive_staff; public Sprite thunder_staff; public GameObject projetctile_normal; public GameObject projetctile_homing; public GameObject projetctile_triple; public GameObject projectile_explosive; public GameObject projectile_pierce; public Text staff_name; public Text staff_description; public ItemGroup staffs; [Space] public int hat = 0; public Image hat_ui_graphic; public SpriteRenderer hat_graphic; public Sprite mage_hat; public Sprite helmet_hat; public Sprite propeller_hat; public Sprite uncommon_hat; public Text hat_name; public Text hat_description; public ItemGroup hats; //Effects [Space] public GameObject overheat; public GameObject burning_effect; public GameObject godofthunder_effect; public GameObject vampire_effect; public GameObject bloody_effect; public SpriteRenderer player_hat; public GameObject streamer_beam; [Space] public Text highscore_text; public GameObject buy_hat_button; public Text buy_hat_text; public GameObject buy_staff_button; public Text buy_staff_text; public WaveManager wave_manager; public ShopManager shop_manager; public ProgresisonManager progression_manager; public void SetMaxHP(int val) { max_hp = val; hp = val; } public void SetFragmentation(int val) => proj_fragments = val; public void SetAtkSpeed(float val) => atk_speed = val; public void SetDamage(float val) => atk_damage = val; #if STEAM_ENABLED private void wdj(Score[] w, Score[] c, bool s) { if (s) { Loading.SetActive(false); Scoreboard.SetActive(true); Scoreboard.GetComponent<SteamLeaderboardViewer>().SetupData(w, c); return; } Loading.SetActive(false); CouldNotLoad.SetActive(true); } #endif // Start is called before the first frame update void Start() { bool completedHat, completedStaff; completedStaff = false; completedHat = false; Debug.Log($"Hat = {completedHat}; Staff {completedStaff}"); hp = max_hp; isAlive = true; progression_manager.soul_orbs = 0; buy_hat_button.SetActive(false); buy_staff_button.SetActive(false); bool fexist = File.Exists($"{Application.persistentDataPath}/Slot_0.sav"); XElement late = fexist ? XElement.Load($"{Application.persistentDataPath}/Slot_0.sav") : null; for (int i = 0; i < staffs.Length; i++) { if (fexist && SaveManager.GetValueOnPrevious($"i{staffs[i].item_id}_Unlocked", false).ToBool()) SaveManager.SetValue($"i{staffs[i].item_id}_Unlocked", true); if (staffs[i].price != 0 && !completedStaff) continue; SaveManager.SetValue($"i{staffs[i].item_id}_Unlocked", true); } for (int i = 0; i < hats.Length; i++) { if (fexist && SaveManager.GetValueOnPrevious($"i{hats[i].item_id}_Unlocked", false).ToBool()) SaveManager.SetValue($"i{hats[i].item_id}_Unlocked", true); if (hats[i].price != 0 && !completedHat) continue; SaveManager.SetValue($"i{hats[i].item_id}_Unlocked", true); } #if STEAM_ENABLED if (AllStaffsUnlocked()) Achievement.Unlock("achiev_06"); if (AllHatsUnlocked()) Achievement.Unlock("achiev_07"); #endif SelectStaffWithIndex(0); SelectHatWithIndex(0); } public void EnableAllStafs() { #if STEAM_ENABLED Achievement.Unlock("achiev_06"); #endif foreach (Item staff in staffs) SaveManager.SetValue($"i{staff.item_id}_Unlocked", true); } public void EnableAllHats() { #if STEAM_ENABLED Achievement.Unlock("achiev_07"); #endif foreach (Item hat in hats) SaveManager.SetValue($"i{hat.item_id}_Unlocked", true); } // Update is called once per frame void Update() { CheckHP(); } private void FixedUpdate() { iWindowCooldown(); HPRegen(); RecoverShield(); RageATK(); if (armor >= 90) { armor = 90; } if (atk_speed < 0.1f) { atk_speed = 0.1f; } if (white_dwarf) { BlackHoleCd(); } if (burning_man) { BurningMan(); } } unsafe void CheckHP() { if (hp > max_hp) { hp = max_hp; } if (!isAlive) return; hp_bar.maxValue = max_hp; hp_bar.value = hp; hp_count.text = Mathf.RoundToInt(hp) + "/" + Mathf.RoundToInt(max_hp); if (hp <= 0 && revive_count <= 0) { Debug.Log("Game Over"); SaveManager.SetValue("soul_prisms", progression_manager.soul_prisms); isAlive = false; EndGame.SetActive(true); WaveManager.Instance.music_source.volume = 0; audio_source.PlayOneShot(game_over_sound, 0.8f); wave_manager.wave_number.GetConfirmation(0); //scoreboard_manager.UpdateBoards((success) => //{ // if (success) // { // //Completed // Loading.SetActive(false); // NameInput.SetActive(true); // } // else // { // //Failed // Loading.SetActive(false); // CouldNotLoad.SetActive(true); // } //}); Loading.SetActive(true); #if STEAM_ENABLED if (Steam.Initialized && hat != 5) { Leaderboards.UploadAll(wave_manager.wave_number); Leaderboards.GetValues((w, c, s) => wdj(w, c, s)); } else { Loading.SetActive(false); CouldNotLoad.SetActive(true); } #else Loading.SetActive(false); CouldNotLoad.SetActive(false); Name_Input.SetActive(true); #endif highscore_text.text = wave_manager.wave_number.ToString(); wave_manager.PauseGame(); wave_manager.pause_screen.SetActive(false); Destroy(this.gameObject); } else if (hp <= 0 && revive_count > 0) { revive_count--; hp = max_hp / 2; GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject e in enemies){ int random_test = Random.Range(0, 2); if (random_test == 1) { e.GetComponent<EnemyStats>().RemoveHP(e.GetComponent<EnemyStats>().hp + 1); } else { } } } } public void TakeDamage(float dmg) { if (i_window_timer >= i_window) { if (gnome == true) { int rand_roll = Random.Range(0, 100); if (rand_roll < 33) { dmg = 0; } } audio_source.PlayOneShot(hurt_audio, 0.2f); player_graph.color = Color.red; hp = Mathf.Clamp(hp - dmg, 0, max_hp); i_window_timer = 0; player_graph.color = new Color(1, 1, 1, 0.5f); } } void iWindowCooldown() { if (i_window_timer > i_window){ player_graph.color = new Color(1, 1, 1, 1f); }else { i_window_timer += Time.deltaTime; } } void HPRegen() { if (regen_ticker >= 1 && hp < max_hp) { hp += (hp_regen/30 * wave_manager.enemies_alive * max_hp/100); regen_ticker = 0; } else { regen_ticker += Time.deltaTime; } } void RecoverShield() { if (shield_lvl > 0) { if (shield_cooldown <= 0 && shield_up == false) { shield_up = true; shield_sprite.color = new Color(0.5f, 0.95f, 1, 0.12f); audio_source.PlayOneShot(shield_begin_audio, 0.5f); } else { shield_cooldown -= Time.fixedDeltaTime; } } } public bool HasSelectedStaff() => staffs[staff].price == 0 || SaveManager.GetValue($"i{staffs[staff].item_id}_Unlocked", false); public bool HasSelectedHat() => hats[hat].price == 0 || SaveManager.GetValue($"i{hats[hat].item_id}_Unlocked", false); public bool AllStaffsUnlocked() { foreach (Item s in staffs) { if (!SaveManager.GetValue($"i{s.item_id}_Unlocked", false)) return false; } return true; } public void UnlockSelectedStaff() { if (progression_manager.soul_prisms < staffs[staff].price || SaveManager.GetValue($"i{staffs[staff].item_id}_Unlocked", false)) return; progression_manager.soul_prisms -= staffs[staff].price; SaveManager.SetValue("soul_prisms", progression_manager.soul_prisms); buy_staff_button.SetActive(false); SaveManager.SetValue($"i{staffs[staff].item_id}_Unlocked", true); SelectStaffWithIndex(staff); #if STEAM_ENABLED if (AllStaffsUnlocked()) Achievement.Unlock("achiev_06"); #endif } public void ReselectStaff() => SelectStaffWithIndex(staff); public void SelectStaffWithIndex(int index) { staff = Mathf.Clamp(index, 0, staffs.Length - 1); Item selectedStaff = staffs[staff]; staff_ui_graphic.sprite = selectedStaff.item_icon; staff_name.text = selectedStaff.LocalizedName.GetLocalizedString(); staff_description.text = ""; if (!HasSelectedStaff()) { buy_staff_text.text = $"{selectedStaff.price}"; buy_staff_button.SetActive(true); return; } buy_staff_button.SetActive(false); staff_graphic.sprite = selectedStaff.item_icon; staff_description.text = selectedStaff.LocalizedDescription.GetLocalizedString(); gameObject.GetComponent<PlayerController>().projectile = selectedStaff.projectile; atk_speed = selectedStaff.attackSpeed; } public void SelectStaff(int add) { int index = Mathf.Clamp(staff + add, 0, staffs.Length - 1); if (staffs[index].mobile_exclude) { if (add > 0) { if (index >= staffs.Length - 1) return; else { SelectStaff(add + 1); return; } } else if (add < 0) { if (index <= 0) index = 1; else { SelectStaff(add - 1); return; } } } SelectStaffWithIndex(index); } public bool AllHatsUnlocked() { foreach (Item h in hats) { if (!SaveManager.GetValue($"i{h.item_id}_Unlocked", false)) return false; } return true; } public void UnlockSelectedHat() { if (progression_manager.soul_prisms < hats[hat].price || SaveManager.GetValue($"i{hats[hat].item_id}_Unlocked", false)) return; progression_manager.soul_prisms -= hats[hat].price; SaveManager.SetValue("soul_prisms", progression_manager.soul_prisms); buy_hat_button.SetActive(false); SaveManager.SetValue($"i{hats[hat].item_id}_Unlocked", true); SelectHatWithIndex(hat); #if STEAM_ENABLED if (AllHatsUnlocked()) Achievement.Unlock("achiev_07"); #endif } public void ReselectHat() => SelectHatWithIndex(hat); public void SelectHatWithIndex(int index) { hat = Mathf.Clamp(index, 0, hats.Length - 1); Item selectedHat = hats[hat]; hat_ui_graphic.sprite = selectedHat.item_icon; hat_name.text = selectedHat.LocalizedName.GetLocalizedString(); hat_description.text = ""; if (!HasSelectedHat()) { buy_hat_text.text = $"{selectedHat.price}"; buy_hat_button.SetActive(true); return; } buy_hat_button.SetActive(false); hat_graphic.sprite = selectedHat.item_icon; hat_description.text = selectedHat.LocalizedDescription.GetLocalizedString(); //Add/Remove jump_number = selectedHat.jumpNumber; armor = selectedHat.armor; speed = selectedHat.speed; } public void SelectHat(int add) { int index = Mathf.Clamp(hat + add, 0, hats.Length - 1); if (hats[index].mobile_exclude) { if (add > 0) { if (index >= hats.Length - 1) return; else { SelectHat(add + 1); return; } } else if (add < 0) { if (index <= 0) index = 1; else { SelectHat(add - 1); return; } } } SelectHatWithIndex(index); } void RageATK() { if (rage_lvl > 0 && hp < max_hp / 2) { rage_damage = ((max_hp / 2 - hp) / (max_hp / 2)) * atk_damage * rage_lvl/2; rage_body_damage = ((max_hp / 2 - hp) / (max_hp / 2)) * body_damage * rage_lvl/2; } else { rage_damage = 0; } } public void KillSelf() { revive_count = 0; hp = 0; } void BlackHoleCd() { if (black_hole_cooldown < 0) { } else { black_hole_cooldown -= Time.fixedDeltaTime; } } void BurningMan() { if (burning_cd <= 0) { Collider2D[] enms = Physics2D.OverlapCircleAll(transform.position, 2.2f, 1); foreach (Collider2D e in enms) { if (e.tag == "Enemy") e.gameObject.GetComponent<EnemyStats>().RemoveHP(body_damage); } burning_effect.GetComponent<ParticleSystem>().Play(); burning_cd = 2; } else { burning_cd -= Time.fixedDeltaTime; } } }
Leave a Comment