2022-03-24 18:37:17 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2022-10-01 15:39:24 +02:00
|
|
|
using System.Linq;
|
2022-03-24 18:37:17 +01:00
|
|
|
|
2022-10-23 15:56:31 +02:00
|
|
|
public class Player : MonoBehaviour
|
2022-03-24 18:37:17 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
Rigidbody2D rb;
|
2022-04-07 23:46:09 +02:00
|
|
|
private Animator myAnimator;
|
2022-06-09 21:51:48 +02:00
|
|
|
public float walkSpeed = 4f;
|
2022-03-24 18:37:17 +01:00
|
|
|
float speedLimiter = 0.7f;
|
|
|
|
float inputHorizontal;
|
|
|
|
float inputVertical;
|
2022-06-04 13:59:18 +02:00
|
|
|
public GameObject Panel;
|
|
|
|
private bool inRange = false;
|
|
|
|
public ParticleSystem dmgParticleSystem;
|
|
|
|
|
2022-06-12 20:14:11 +02:00
|
|
|
public HealthBar healthBar;
|
2022-10-23 00:21:54 +02:00
|
|
|
|
2022-06-21 03:57:04 +02:00
|
|
|
private static bool attackSword;
|
2022-06-14 21:20:02 +02:00
|
|
|
private bool attackFist;
|
2022-06-21 03:57:04 +02:00
|
|
|
private static bool pickaxeInUse;
|
|
|
|
private static bool playerInCollider;
|
|
|
|
|
2022-10-23 13:29:22 +02:00
|
|
|
public bool lvlUp = false;
|
|
|
|
public float test;
|
|
|
|
|
2022-06-13 17:38:09 +02:00
|
|
|
private float timerRegen = 0f;
|
|
|
|
private float timerTick = 0f;
|
|
|
|
private float waitRegen = 8.0f;
|
|
|
|
private float waitTick = 1.0f;
|
2022-06-12 20:14:11 +02:00
|
|
|
|
2022-06-13 17:38:09 +02:00
|
|
|
private bool startRegen = false;
|
2022-06-12 20:14:11 +02:00
|
|
|
|
2022-06-06 16:21:26 +02:00
|
|
|
private bool canWalk = true;
|
2022-10-16 21:35:56 +02:00
|
|
|
|
2022-12-29 00:58:03 +01:00
|
|
|
[Header("Player Starts values")]
|
|
|
|
public const int BaseHealth = 10;
|
|
|
|
public const float BaseSpeed = 4f;
|
2022-11-14 22:22:08 +01:00
|
|
|
|
2022-12-29 00:58:03 +01:00
|
|
|
|
|
|
|
[Header("Player Skills Points")]
|
2022-11-14 22:22:08 +01:00
|
|
|
public int healthPoints;
|
|
|
|
public int defensePoints;
|
|
|
|
public int strengthPoints;
|
|
|
|
public int intelligencePoints;
|
2022-10-23 15:56:31 +02:00
|
|
|
|
2022-12-29 00:58:03 +01:00
|
|
|
[Header("Player current values")]
|
|
|
|
public float attackValue;
|
|
|
|
public float defenseValue;
|
|
|
|
public float currentSpeed; // as WalkSpeed
|
|
|
|
|
|
|
|
public float currentHealth;
|
|
|
|
public float maxHealth;
|
|
|
|
|
2022-10-23 13:29:22 +02:00
|
|
|
public float exp;
|
2022-10-16 21:35:56 +02:00
|
|
|
public int lvl;
|
2022-10-23 13:29:22 +02:00
|
|
|
public float maxExp;
|
2022-10-23 00:21:54 +02:00
|
|
|
public LevelBar levelBar;
|
|
|
|
public FloatValue minPlayerExp;
|
2022-10-23 15:56:31 +02:00
|
|
|
|
2022-12-29 00:58:03 +01:00
|
|
|
|
2022-11-15 12:32:28 +01:00
|
|
|
|
2022-06-21 03:57:04 +02:00
|
|
|
public static void putPlayerInCollider()
|
|
|
|
{
|
|
|
|
playerInCollider = true;
|
|
|
|
}
|
2022-10-23 15:56:31 +02:00
|
|
|
|
2022-06-21 03:57:04 +02:00
|
|
|
public static void takePlayerFromCollider()
|
|
|
|
{
|
|
|
|
playerInCollider = false;
|
|
|
|
}
|
2022-10-23 15:56:31 +02:00
|
|
|
|
2022-03-24 18:37:17 +01:00
|
|
|
void Start()
|
|
|
|
{
|
2022-10-01 15:39:24 +02:00
|
|
|
Panel = GameObject.FindObjectsOfType<GameObject>(true).Where(sr => sr.gameObject.name == "YouDied").ToArray()[0];
|
|
|
|
healthBar = (HealthBar)FindObjectOfType<HealthBar>();
|
2022-10-23 00:21:54 +02:00
|
|
|
levelBar = (LevelBar)FindObjectOfType<LevelBar>();
|
2022-12-06 01:20:01 +01:00
|
|
|
if (OnMapAppearanceMethod.IsNewGame())
|
2022-06-15 19:54:44 +02:00
|
|
|
{
|
2022-10-16 21:35:56 +02:00
|
|
|
currentHealth = PlayerPrefs.GetFloat("health");
|
2022-10-23 00:21:54 +02:00
|
|
|
exp = PlayerPrefs.GetFloat("exp");
|
2022-10-23 13:29:22 +02:00
|
|
|
lvl = PlayerPrefs.GetInt("lvl");
|
2022-06-15 19:54:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-01 19:28:26 +02:00
|
|
|
currentHealth = PlayerPrefs.GetFloat("health-S");
|
2022-10-23 00:21:54 +02:00
|
|
|
exp = PlayerPrefs.GetFloat("exp-S");
|
2022-10-23 13:29:22 +02:00
|
|
|
lvl = PlayerPrefs.GetInt("lvl-S");
|
2022-06-15 19:54:44 +02:00
|
|
|
}
|
2022-03-24 18:37:17 +01:00
|
|
|
rb = gameObject.GetComponent<Rigidbody2D>();
|
2022-04-07 23:46:09 +02:00
|
|
|
myAnimator = GetComponent<Animator>();
|
2022-11-14 22:22:08 +01:00
|
|
|
//healthBar.SetMaxHealth(maxHealth.initialValue);
|
|
|
|
//healthBar.SetHealth(currentHealth);
|
2022-10-23 13:29:22 +02:00
|
|
|
//levelBar.SetStartExp(minPlayerExp.initialValue);
|
|
|
|
//levelBar.SetExp(exp);
|
2022-12-29 00:58:03 +01:00
|
|
|
|
|
|
|
ManageSpeed();
|
|
|
|
walkSpeed = PlayerPrefs.GetFloat("speed");
|
|
|
|
|
|
|
|
|
2022-10-23 13:29:22 +02:00
|
|
|
ManageLevels(exp);
|
2023-01-10 04:21:36 +01:00
|
|
|
|
|
|
|
//DEFAULT CONTROLS
|
|
|
|
if (!PlayerPrefs.HasKey("Interaction"))
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetString("Interaction","E");
|
|
|
|
}
|
|
|
|
if (!PlayerPrefs.HasKey("Attack"))
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetString("Attack","Space");
|
|
|
|
}
|
|
|
|
if (!PlayerPrefs.HasKey("Skills"))
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetString("Skills","U");
|
|
|
|
}
|
|
|
|
if (!PlayerPrefs.HasKey("Inventory"))
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetString("Inventory","I");
|
|
|
|
}
|
|
|
|
if (!PlayerPrefs.HasKey("Settings"))
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetString("Settings","Escape");
|
|
|
|
}
|
|
|
|
if (!PlayerPrefs.HasKey("Quests"))
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetString("Quests","Q");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PlayerPrefs.HasKey("Quests"))
|
|
|
|
{
|
|
|
|
TaskUIManager.Instance.keyToOpen = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("Quests"));
|
|
|
|
}
|
|
|
|
if (!PlayerPrefs.HasKey("ExpHlth"))
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetString("ExpHlth","Tab");
|
|
|
|
}
|
|
|
|
if (!PlayerPrefs.HasKey("EXP HEALTH"))
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetString("EXP HEALTH","Tab");
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2022-03-24 18:37:17 +01:00
|
|
|
}
|
|
|
|
|
2022-10-23 00:21:54 +02:00
|
|
|
public void GetExp(float expValue)
|
2022-10-16 21:35:56 +02:00
|
|
|
{
|
|
|
|
exp = exp + expValue;
|
2022-10-23 13:29:22 +02:00
|
|
|
ManageLevels(exp);
|
2022-10-16 21:35:56 +02:00
|
|
|
}
|
|
|
|
|
2022-10-23 00:21:54 +02:00
|
|
|
public void ManageLevels(float exp)
|
2022-10-16 21:35:56 +02:00
|
|
|
{
|
2022-10-23 13:29:22 +02:00
|
|
|
if (lvl == 1)
|
|
|
|
{
|
2022-12-19 22:11:22 +01:00
|
|
|
maxExp = 25;
|
2022-10-23 13:29:22 +02:00
|
|
|
if (exp >= maxExp)
|
|
|
|
{
|
|
|
|
lvl = 2;
|
|
|
|
lvlUp = true;
|
|
|
|
maxExp = 50;
|
2022-12-25 03:39:31 +01:00
|
|
|
|
|
|
|
// Add points and refresh view (if opened)
|
|
|
|
SkillsPointsManger.Instance.AddFreePoints(2);
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
2022-10-23 13:29:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lvl == 2)
|
2022-10-16 21:35:56 +02:00
|
|
|
{
|
2022-10-23 13:29:22 +02:00
|
|
|
maxExp = 50;
|
|
|
|
if (exp >= maxExp)
|
|
|
|
{
|
|
|
|
lvl = 3;
|
|
|
|
lvlUp = true;
|
|
|
|
maxExp = 100;
|
2022-12-25 03:39:31 +01:00
|
|
|
|
|
|
|
// Add points and refresh view (if opened)
|
|
|
|
SkillsPointsManger.Instance.AddFreePoints(2);
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
2022-10-23 13:29:22 +02:00
|
|
|
}
|
2022-10-16 21:35:56 +02:00
|
|
|
}
|
2022-10-23 15:56:31 +02:00
|
|
|
else if (lvl == 3)
|
2022-10-16 21:35:56 +02:00
|
|
|
{
|
2022-10-23 13:29:22 +02:00
|
|
|
maxExp = 100;
|
|
|
|
if (exp >= maxExp)
|
|
|
|
{
|
|
|
|
lvl = 4;
|
|
|
|
lvlUp = true;
|
|
|
|
maxExp = 200;
|
2022-12-25 03:39:31 +01:00
|
|
|
|
2023-01-07 21:02:30 +01:00
|
|
|
// Add points and refresh view (if opened)
|
|
|
|
SkillsPointsManger.Instance.AddFreePoints(2);
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lvl == 4)
|
|
|
|
{
|
|
|
|
maxExp = 200;
|
|
|
|
if (exp >= maxExp)
|
|
|
|
{
|
|
|
|
lvl = 5;
|
|
|
|
lvlUp = true;
|
|
|
|
maxExp = 300;
|
|
|
|
|
|
|
|
// Add points and refresh view (if opened)
|
|
|
|
SkillsPointsManger.Instance.AddFreePoints(2);
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lvl == 5)
|
|
|
|
{
|
|
|
|
maxExp = 300;
|
|
|
|
if (exp >= maxExp)
|
|
|
|
{
|
|
|
|
lvl = 6;
|
|
|
|
lvlUp = true;
|
|
|
|
maxExp = 450;
|
|
|
|
|
|
|
|
// Add points and refresh view (if opened)
|
|
|
|
SkillsPointsManger.Instance.AddFreePoints(2);
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lvl == 6)
|
|
|
|
{
|
|
|
|
maxExp = 450;
|
|
|
|
if (exp >= maxExp)
|
|
|
|
{
|
|
|
|
lvl = 7;
|
|
|
|
lvlUp = true;
|
|
|
|
maxExp = 550;
|
|
|
|
|
|
|
|
// Add points and refresh view (if opened)
|
|
|
|
SkillsPointsManger.Instance.AddFreePoints(2);
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lvl == 7)
|
|
|
|
{
|
|
|
|
maxExp = 550;
|
|
|
|
if (exp >= maxExp)
|
|
|
|
{
|
|
|
|
lvl = 8;
|
|
|
|
lvlUp = true;
|
|
|
|
maxExp = 700;
|
|
|
|
|
2023-01-15 21:57:49 +01:00
|
|
|
// Add points and refresh view (if opened)
|
|
|
|
SkillsPointsManger.Instance.AddFreePoints(2);
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lvl == 8)
|
|
|
|
{
|
|
|
|
maxExp = 700;
|
|
|
|
if (exp >= maxExp)
|
|
|
|
{
|
|
|
|
lvl = 9;
|
|
|
|
lvlUp = true;
|
|
|
|
maxExp = 850;
|
|
|
|
|
|
|
|
// Add points and refresh view (if opened)
|
|
|
|
SkillsPointsManger.Instance.AddFreePoints(2);
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lvl == 9)
|
|
|
|
{
|
|
|
|
maxExp = 850;
|
|
|
|
if (exp >= maxExp)
|
|
|
|
{
|
|
|
|
lvl = 10;
|
|
|
|
lvlUp = true;
|
|
|
|
maxExp = 1000;
|
|
|
|
|
2022-12-25 03:39:31 +01:00
|
|
|
// Add points and refresh view (if opened)
|
|
|
|
SkillsPointsManger.Instance.AddFreePoints(2);
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
2022-10-23 13:29:22 +02:00
|
|
|
}
|
2022-10-16 21:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-02 18:45:58 +02:00
|
|
|
public void TakeDamage(float damage, bool isPanelEnabled = true)
|
2022-06-04 13:59:18 +02:00
|
|
|
{
|
2022-11-14 23:04:29 +01:00
|
|
|
|
2022-12-25 03:39:31 +01:00
|
|
|
defensePoints = PlayerPrefs.GetInt(SkillsPointsManger.PLAYER_SKILS_DEFENSE_POINTS);
|
2022-12-29 00:58:03 +01:00
|
|
|
|
2023-01-04 21:23:02 +01:00
|
|
|
Debug.Log($"Minion Damage: {damage}; \n\tDefense: {PlayerPrefs.GetFloat("defenseValue")}");
|
2022-12-29 00:58:03 +01:00
|
|
|
|
|
|
|
damage = damage - PlayerPrefs.GetFloat("defenseValue");
|
2022-12-29 20:02:32 +01:00
|
|
|
damage = damage < 0 ? 0 : damage;
|
2022-12-29 00:58:03 +01:00
|
|
|
|
2023-01-04 21:23:02 +01:00
|
|
|
Debug.Log($"\tRealDamage: {damage}");
|
2022-11-14 23:04:29 +01:00
|
|
|
|
2022-11-14 22:22:08 +01:00
|
|
|
currentHealth = PlayerPrefs.GetFloat("health");
|
2022-06-12 20:14:11 +02:00
|
|
|
currentHealth = currentHealth - damage;
|
2022-11-14 22:22:08 +01:00
|
|
|
PlayerPrefs.SetFloat("health", currentHealth);
|
2022-10-01 15:39:24 +02:00
|
|
|
|
2022-06-04 13:59:18 +02:00
|
|
|
var em = dmgParticleSystem.emission;
|
|
|
|
em.enabled = true;
|
|
|
|
StartCoroutine(Timer());
|
2022-06-13 17:38:09 +02:00
|
|
|
timerRegen = 0.0f;
|
|
|
|
startRegen = false;
|
2022-06-12 20:14:11 +02:00
|
|
|
if (currentHealth <= 0)
|
2022-06-04 13:59:18 +02:00
|
|
|
{
|
2022-10-23 15:56:31 +02:00
|
|
|
if (isPanelEnabled)
|
2022-10-02 18:45:58 +02:00
|
|
|
{
|
2022-10-23 15:56:31 +02:00
|
|
|
Panel.SetActive(true);
|
2022-10-02 18:45:58 +02:00
|
|
|
}
|
2022-06-06 16:21:26 +02:00
|
|
|
walkSpeed = 0f;
|
2022-10-16 21:35:56 +02:00
|
|
|
canWalk = false;
|
2022-06-04 13:59:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator Timer()
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(0.2f);
|
|
|
|
var em = dmgParticleSystem.emission;
|
|
|
|
em.enabled = false;
|
|
|
|
}
|
|
|
|
|
2022-05-31 23:53:48 +02:00
|
|
|
private void HandleAttacks()
|
|
|
|
{
|
2022-11-27 21:28:55 +01:00
|
|
|
|
2022-10-16 21:35:56 +02:00
|
|
|
if (canWalk == true)
|
2022-05-31 23:53:48 +02:00
|
|
|
{
|
2022-12-29 00:58:03 +01:00
|
|
|
/* if (EquipmentUIManager.Instance.GetList().Count() == 0 || EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.WeaponSlot && el.Value != null).Count() == 0)
|
|
|
|
return;*/
|
2022-10-23 15:56:31 +02:00
|
|
|
|
2022-12-29 00:58:03 +01:00
|
|
|
if (attackFist)
|
|
|
|
{
|
|
|
|
myAnimator.SetTrigger("attackFist");
|
|
|
|
} else if (attackSword &&
|
|
|
|
EquipmentUIManager.Instance.GetList().Count() != 0 &&
|
|
|
|
EquipmentUIManager.Instance.GetList()
|
|
|
|
.Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.WeaponSlot && el.Value != null).Count() > 0 &&
|
|
|
|
EquipmentUIManager.Instance.GetList()
|
|
|
|
.Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.WeaponSlot && el.Value != null).First().Value.Name.Equals("Pickaxe"))
|
2022-10-16 21:35:56 +02:00
|
|
|
{
|
|
|
|
myAnimator.SetTrigger("pickaxe");
|
|
|
|
}
|
2022-12-29 00:58:03 +01:00
|
|
|
else if (attackSword &&
|
|
|
|
EquipmentUIManager.Instance.GetList().Count() != 0 &&
|
|
|
|
EquipmentUIManager.Instance.GetList()
|
|
|
|
.Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.WeaponSlot && el.Value != null).Count() > 0 &&
|
|
|
|
EquipmentUIManager.Instance.GetList()
|
|
|
|
.Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.WeaponSlot && el.Value != null).First().Value.EquipmentType == EquipmentTypeEnum.Weapon)
|
2022-10-16 21:35:56 +02:00
|
|
|
{
|
|
|
|
myAnimator.SetTrigger("attack");
|
|
|
|
}
|
2022-05-31 23:53:48 +02:00
|
|
|
}
|
2022-10-10 20:44:52 +02:00
|
|
|
|
2022-05-31 23:53:48 +02:00
|
|
|
}
|
|
|
|
|
2022-06-21 03:57:04 +02:00
|
|
|
private void HandleInput()
|
2022-03-24 18:37:17 +01:00
|
|
|
{
|
2023-01-07 02:56:38 +01:00
|
|
|
KeyCode keyToAttack = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("Attack"));
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(keyToAttack))
|
2022-10-01 15:39:24 +02:00
|
|
|
{
|
|
|
|
attackSword = true;
|
|
|
|
}
|
2023-01-10 04:23:56 +01:00
|
|
|
/*if (Input.GetKeyDown(KeyCode.LeftShift))
|
2022-10-01 15:39:24 +02:00
|
|
|
{
|
|
|
|
attackFist = true;
|
2023-01-10 04:23:56 +01:00
|
|
|
}*/
|
2022-10-23 15:56:31 +02:00
|
|
|
if (Input.GetKeyDown(KeyCode.X))
|
2022-10-01 15:39:24 +02:00
|
|
|
{
|
|
|
|
pickaxeInUse = true;
|
|
|
|
}
|
2022-06-21 03:57:04 +02:00
|
|
|
}
|
2022-10-01 15:39:24 +02:00
|
|
|
|
|
|
|
private void ResetValues()
|
2022-06-21 03:57:04 +02:00
|
|
|
{
|
2022-10-01 15:39:24 +02:00
|
|
|
attackSword = false;
|
|
|
|
attackFist = false;
|
|
|
|
pickaxeInUse = false;
|
2022-03-24 18:37:17 +01:00
|
|
|
}
|
|
|
|
|
2022-10-01 15:39:24 +02:00
|
|
|
void Update()
|
2022-03-24 18:37:17 +01:00
|
|
|
{
|
2022-11-15 12:32:28 +01:00
|
|
|
|
2022-10-23 13:29:22 +02:00
|
|
|
if (lvlUp == true)
|
|
|
|
{
|
2022-10-23 15:56:31 +02:00
|
|
|
PlayerPrefs.SetInt("LvlUpPopUp", 1);
|
2022-10-23 13:29:22 +02:00
|
|
|
exp = 0;
|
|
|
|
lvlUp = false;
|
|
|
|
}
|
|
|
|
|
2022-11-14 22:22:08 +01:00
|
|
|
ManageHealth();
|
|
|
|
ManageDefense();
|
|
|
|
ManageIntelligence();
|
|
|
|
ManageStrength();
|
2022-12-29 00:58:03 +01:00
|
|
|
ManageSpeed();
|
2022-11-14 22:22:08 +01:00
|
|
|
|
2022-10-16 21:35:56 +02:00
|
|
|
if (canWalk == true)
|
|
|
|
{
|
2022-10-01 15:39:24 +02:00
|
|
|
|
2022-10-23 15:56:31 +02:00
|
|
|
inputHorizontal = Input.GetAxisRaw("Horizontal");
|
|
|
|
inputVertical = Input.GetAxisRaw("Vertical");
|
2022-10-01 15:39:24 +02:00
|
|
|
|
2022-12-29 00:58:03 +01:00
|
|
|
// speed calculated in ManageSpeed function
|
|
|
|
walkSpeed = PlayerPrefs.GetFloat("speed");
|
|
|
|
|
2022-10-23 15:56:31 +02:00
|
|
|
myAnimator.SetFloat("moveX", inputHorizontal * walkSpeed);
|
|
|
|
myAnimator.SetFloat("moveY", inputVertical * walkSpeed);
|
2022-12-29 00:58:03 +01:00
|
|
|
|
2022-10-23 15:56:31 +02:00
|
|
|
if (inputHorizontal != 0)
|
|
|
|
{
|
|
|
|
myAnimator.SetFloat("speed", walkSpeed);
|
|
|
|
}
|
|
|
|
else if (inputVertical != 0)
|
|
|
|
{
|
|
|
|
myAnimator.SetFloat("speed", walkSpeed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
myAnimator.SetFloat("speed", 0);
|
|
|
|
}
|
2022-10-01 15:39:24 +02:00
|
|
|
|
2022-10-23 15:56:31 +02:00
|
|
|
if (inputHorizontal == 1 || inputHorizontal == -1 || inputVertical == 1 || inputVertical == -1)
|
|
|
|
{
|
|
|
|
myAnimator.SetFloat("lastMoveX", inputHorizontal);
|
|
|
|
myAnimator.SetFloat("lastMoveY", inputVertical);
|
|
|
|
}
|
2022-06-21 03:57:04 +02:00
|
|
|
|
2022-10-23 15:56:31 +02:00
|
|
|
timerRegen += Time.deltaTime;
|
|
|
|
if (timerRegen >= waitRegen)
|
|
|
|
{
|
|
|
|
startRegen = true;
|
|
|
|
}
|
|
|
|
|
2022-11-14 22:22:08 +01:00
|
|
|
currentHealth = PlayerPrefs.GetFloat("health");
|
|
|
|
maxHealth = PlayerPrefs.GetFloat("maxHealth");
|
2022-10-23 15:56:31 +02:00
|
|
|
if (startRegen == true)
|
2022-06-06 16:21:26 +02:00
|
|
|
{
|
2022-10-23 15:56:31 +02:00
|
|
|
timerTick += Time.deltaTime;
|
|
|
|
if (timerTick >= waitTick)
|
2022-10-01 15:39:24 +02:00
|
|
|
{
|
2022-11-14 22:22:08 +01:00
|
|
|
if (currentHealth < maxHealth)
|
2022-10-23 15:56:31 +02:00
|
|
|
{
|
|
|
|
currentHealth = currentHealth + 1;
|
2022-11-14 23:04:29 +01:00
|
|
|
if (currentHealth > maxHealth)
|
|
|
|
{
|
|
|
|
currentHealth = maxHealth;
|
|
|
|
}
|
2022-11-14 22:22:08 +01:00
|
|
|
PlayerPrefs.SetFloat("health", currentHealth);
|
2022-10-23 15:56:31 +02:00
|
|
|
timerTick = 0f;
|
|
|
|
}
|
2022-10-01 15:39:24 +02:00
|
|
|
}
|
2022-03-24 18:37:17 +01:00
|
|
|
}
|
2022-10-23 15:56:31 +02:00
|
|
|
PlayerPrefs.SetFloat("health", currentHealth);
|
|
|
|
PlayerPrefs.SetFloat("exp", exp);
|
|
|
|
PlayerPrefs.SetInt("lvl", lvl);
|
|
|
|
PlayerPrefs.SetFloat("maxExp", maxExp);
|
2022-11-14 22:22:08 +01:00
|
|
|
PlayerPrefs.SetFloat("maxHealth", maxHealth);
|
2022-10-16 21:35:56 +02:00
|
|
|
}
|
2022-06-21 03:57:04 +02:00
|
|
|
|
2022-10-01 15:39:24 +02:00
|
|
|
HandleInput();
|
|
|
|
}
|
2022-06-21 03:57:04 +02:00
|
|
|
|
2022-10-01 15:39:24 +02:00
|
|
|
void FixedUpdate()
|
2022-06-15 19:54:44 +02:00
|
|
|
{
|
2022-10-23 15:56:31 +02:00
|
|
|
if (canWalk == true)
|
2022-06-21 03:57:04 +02:00
|
|
|
{
|
2022-10-01 15:39:24 +02:00
|
|
|
if (inputHorizontal != 0 || inputVertical != 0)
|
|
|
|
{
|
|
|
|
if (inputHorizontal != 0 && inputVertical != 0)
|
|
|
|
{
|
|
|
|
inputHorizontal *= speedLimiter;
|
|
|
|
inputVertical *= speedLimiter;
|
|
|
|
}
|
|
|
|
rb.velocity = new Vector2(inputHorizontal * walkSpeed, inputVertical * walkSpeed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb.velocity = new Vector2(0f, 0f);
|
|
|
|
}
|
2022-06-21 03:57:04 +02:00
|
|
|
}
|
2022-10-01 15:39:24 +02:00
|
|
|
|
|
|
|
HandleAttacks();
|
|
|
|
ResetValues();
|
2022-06-15 19:54:44 +02:00
|
|
|
}
|
2022-10-01 15:39:24 +02:00
|
|
|
|
|
|
|
public void SaveCheckpoint()
|
2022-06-21 03:57:04 +02:00
|
|
|
{
|
2022-11-14 22:22:08 +01:00
|
|
|
currentHealth = PlayerPrefs.GetFloat("health");
|
2022-10-01 15:39:24 +02:00
|
|
|
PlayerPrefs.SetFloat("health-S", currentHealth);
|
2022-10-23 00:21:54 +02:00
|
|
|
PlayerPrefs.SetFloat("exp-S", exp);
|
2022-10-23 13:29:22 +02:00
|
|
|
PlayerPrefs.SetInt("lvl-S", lvl);
|
2022-06-21 03:57:04 +02:00
|
|
|
}
|
2022-10-23 15:56:31 +02:00
|
|
|
|
|
|
|
public void ManageHealth()
|
|
|
|
{
|
2022-12-29 00:58:03 +01:00
|
|
|
//nie wiem czy to potrzebne ale zostawiam tak
|
2022-12-25 03:39:31 +01:00
|
|
|
healthPoints = PlayerPrefs.GetInt(SkillsPointsManger.PLAYER_SKILS_HEALTH_POINTS);
|
2022-12-29 00:58:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
// nowe - analogicznie jak w ataku
|
|
|
|
var healthCalculltor = new HealthCalcullator();
|
|
|
|
|
|
|
|
var health = BaseHealth + healthCalculltor.CalculateWithoutItem();
|
|
|
|
|
|
|
|
PlayerPrefs.SetFloat("maxHealth", health);
|
|
|
|
|
2023-01-06 21:54:50 +01:00
|
|
|
//Debug.Log("Health: " + PlayerPrefs.GetFloat("maxHealth"));
|
2022-11-14 22:22:08 +01:00
|
|
|
}
|
2022-10-23 15:56:31 +02:00
|
|
|
|
2022-11-14 22:22:08 +01:00
|
|
|
public void AddHealthPoint()
|
|
|
|
{
|
2022-12-25 03:39:31 +01:00
|
|
|
healthPoints = PlayerPrefs.GetInt(SkillsPointsManger.PLAYER_SKILS_HEALTH_POINTS);
|
2022-11-14 22:22:08 +01:00
|
|
|
healthPoints = healthPoints + 1;
|
2022-12-25 03:39:31 +01:00
|
|
|
PlayerPrefs.SetInt(SkillsPointsManger.PLAYER_SKILS_HEALTH_POINTS, healthPoints);
|
|
|
|
|
|
|
|
// Fetch change in scene manager responsible for this data
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
2022-10-23 15:56:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ManageStrength()
|
|
|
|
{
|
2022-11-27 21:28:55 +01:00
|
|
|
if (EquipmentUIManager.Instance.GetList().Count() == 0 || EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.WeaponSlot && el.Value != null).Count() == 0)
|
2022-11-15 12:32:28 +01:00
|
|
|
{
|
2022-12-29 00:58:03 +01:00
|
|
|
var attackCalculator = new AttackCalcullator();
|
|
|
|
|
|
|
|
attackValue = attackCalculator.CalculateWithoutItem();
|
|
|
|
|
2022-11-15 12:32:28 +01:00
|
|
|
PlayerPrefs.SetFloat("attackValue", attackValue);
|
|
|
|
}
|
2022-11-27 21:28:55 +01:00
|
|
|
else if (EquipmentUIManager.Instance.GetList().Count() != 0 &&
|
|
|
|
EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.WeaponSlot && el.Value != null).Count() > 0 &&
|
2022-12-29 00:58:03 +01:00
|
|
|
EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.WeaponSlot && el.Value != null).First().Value.EquipmentType == EquipmentTypeEnum.Weapon)
|
2022-11-15 12:32:28 +01:00
|
|
|
{
|
2022-12-29 00:58:03 +01:00
|
|
|
var equippedItem = EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.WeaponSlot && el.Value != null).First().Value;
|
2022-11-15 12:32:28 +01:00
|
|
|
|
2022-12-29 00:58:03 +01:00
|
|
|
var attackCalculator = new AttackCalcullator();
|
|
|
|
|
|
|
|
attackValue = attackCalculator.Calculate(equippedItem.Value);
|
|
|
|
|
2022-11-15 12:32:28 +01:00
|
|
|
PlayerPrefs.SetFloat("attackValue", attackValue);
|
2022-12-29 00:58:03 +01:00
|
|
|
} else
|
2022-11-15 12:32:28 +01:00
|
|
|
{
|
2022-12-29 00:58:03 +01:00
|
|
|
throw new System.Exception("Attack Calculation Error");
|
2022-11-15 12:32:28 +01:00
|
|
|
}
|
2022-12-29 00:58:03 +01:00
|
|
|
|
2023-01-06 21:54:50 +01:00
|
|
|
//Debug.Log("Attack: " + PlayerPrefs.GetFloat("attackValue"));
|
2022-11-14 22:22:08 +01:00
|
|
|
}
|
2022-10-23 15:56:31 +02:00
|
|
|
|
2022-11-14 22:22:08 +01:00
|
|
|
public void AddStrengthPoint()
|
|
|
|
{
|
2022-12-25 03:39:31 +01:00
|
|
|
strengthPoints = PlayerPrefs.GetInt(SkillsPointsManger.PLAYER_SKILS_STRENGHT_POINTS);
|
2022-11-14 22:22:08 +01:00
|
|
|
strengthPoints = strengthPoints + 1;
|
2022-12-25 03:39:31 +01:00
|
|
|
PlayerPrefs.SetInt(SkillsPointsManger.PLAYER_SKILS_STRENGHT_POINTS, strengthPoints);
|
|
|
|
|
|
|
|
// Fetch change in scene manager responsible for this data
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
2022-10-23 15:56:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ManageDefense()
|
|
|
|
{
|
2022-12-29 00:58:03 +01:00
|
|
|
//nie wiem czy to potrzebne ale zostawiam tak
|
2022-12-25 03:39:31 +01:00
|
|
|
defensePoints = PlayerPrefs.GetInt(SkillsPointsManger.PLAYER_SKILS_DEFENSE_POINTS);
|
2022-12-29 00:58:03 +01:00
|
|
|
|
|
|
|
// nowe - analogicznie jak w ataku
|
|
|
|
var defenseCalculator = new DefenseCalculattor();
|
|
|
|
|
|
|
|
if (EquipmentUIManager.Instance.GetList().Count() == 0 ||
|
|
|
|
EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.HelmetSlot && el.Value != null).Count() == 0 &&
|
|
|
|
EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.ArmorSlot && el.Value != null).Count() == 0
|
|
|
|
){
|
|
|
|
|
|
|
|
defenseValue = defenseCalculator.CalculateWithoutItem();
|
|
|
|
|
|
|
|
PlayerPrefs.SetFloat("defenseValue", defenseValue);
|
|
|
|
}
|
|
|
|
else if (EquipmentUIManager.Instance.GetList().Count() != 0 &&
|
|
|
|
|
|
|
|
(EquipmentUIManager.Instance.GetList()
|
|
|
|
.Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.HelmetSlot && el.Value != null).Count() > 0 &&
|
|
|
|
EquipmentUIManager.Instance.GetList()
|
|
|
|
.Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.HelmetSlot && el.Value != null).First().Value.EquipmentType == EquipmentTypeEnum.Helmet) ||
|
|
|
|
|
|
|
|
(EquipmentUIManager.Instance.GetList()
|
|
|
|
.Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.ArmorSlot && el.Value != null).Count() > 0 &&
|
|
|
|
EquipmentUIManager.Instance.GetList()
|
|
|
|
.Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.ArmorSlot && el.Value != null).First().Value.EquipmentType == EquipmentTypeEnum.Chest)
|
|
|
|
) {
|
|
|
|
var helmetSlot = EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.HelmetSlot && el.Value != null);
|
|
|
|
var helmet = (helmetSlot.Count() != 0) ? helmetSlot.First().Value.Value : 0;
|
|
|
|
|
|
|
|
|
|
|
|
var chestplateSlot = EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.ArmorSlot && el.Value != null);
|
|
|
|
var chestplate = (chestplateSlot.Count() != 0) ? chestplateSlot.First().Value.Value : 0;
|
|
|
|
|
|
|
|
|
|
|
|
defenseValue = defenseCalculator.Calculate(helmet + chestplate);
|
|
|
|
|
|
|
|
PlayerPrefs.SetFloat("defenseValue", defenseValue);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new System.Exception("Defense Calculation Error");
|
|
|
|
}
|
|
|
|
|
2023-01-06 21:54:50 +01:00
|
|
|
//Debug.Log("Defense: " + PlayerPrefs.GetFloat("defenseValue"));
|
2022-11-14 22:22:08 +01:00
|
|
|
}
|
2022-10-23 15:56:31 +02:00
|
|
|
|
2022-11-14 22:22:08 +01:00
|
|
|
public void AddDefensePoint()
|
|
|
|
{
|
2022-12-25 03:39:31 +01:00
|
|
|
defensePoints = PlayerPrefs.GetInt(SkillsPointsManger.PLAYER_SKILS_DEFENSE_POINTS);
|
2022-11-14 22:22:08 +01:00
|
|
|
defensePoints = defensePoints + 1;
|
2022-12-25 03:39:31 +01:00
|
|
|
PlayerPrefs.SetInt(SkillsPointsManger.PLAYER_SKILS_DEFENSE_POINTS, defensePoints);
|
|
|
|
|
|
|
|
// Fetch change in scene manager responsible for this data
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
2022-10-23 15:56:31 +02:00
|
|
|
}
|
|
|
|
|
2022-11-14 22:22:08 +01:00
|
|
|
public void ManageIntelligence()
|
|
|
|
{
|
2022-12-25 03:39:31 +01:00
|
|
|
intelligencePoints = PlayerPrefs.GetInt(SkillsPointsManger.PLAYER_SKILS_INTELIGENCE_POINTS);
|
2022-11-14 22:22:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void AddIntelligencePoint()
|
2022-10-23 15:56:31 +02:00
|
|
|
{
|
2022-12-25 03:39:31 +01:00
|
|
|
intelligencePoints = PlayerPrefs.GetInt(SkillsPointsManger.PLAYER_SKILS_INTELIGENCE_POINTS);
|
2022-11-14 22:22:08 +01:00
|
|
|
intelligencePoints = intelligencePoints + 1;
|
2022-12-25 03:39:31 +01:00
|
|
|
PlayerPrefs.SetInt(SkillsPointsManger.PLAYER_SKILS_INTELIGENCE_POINTS, intelligencePoints);
|
2022-11-14 22:22:08 +01:00
|
|
|
|
2022-12-25 03:39:31 +01:00
|
|
|
// Fetch change in scene manager responsible for this data
|
|
|
|
SkillsPointsManger.Instance.UpdatePanelView();
|
2022-11-14 22:22:08 +01:00
|
|
|
}
|
2022-10-23 15:56:31 +02:00
|
|
|
|
2022-11-14 22:22:08 +01:00
|
|
|
public void LevelUpPopUp()
|
|
|
|
{
|
2022-12-25 03:39:31 +01:00
|
|
|
healthPoints = PlayerPrefs.GetInt(SkillsPointsManger.PLAYER_SKILS_HEALTH_POINTS);
|
2022-10-23 15:56:31 +02:00
|
|
|
}
|
|
|
|
|
2022-12-29 00:58:03 +01:00
|
|
|
public void ManageSpeed()
|
|
|
|
{
|
|
|
|
var speed = 0f;
|
|
|
|
var speedCalculator = new SpeedCalcullator();
|
|
|
|
|
|
|
|
if (EquipmentUIManager.Instance.GetList().Count() == 0 || EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.BootsSlot && el.Value != null).Count() == 0)
|
|
|
|
{
|
|
|
|
speed = BaseSpeed + speedCalculator.CalculateWithoutItem();
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (EquipmentUIManager.Instance.GetList().Count() != 0 &&
|
|
|
|
EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.BootsSlot && el.Value != null).Count() > 0 &&
|
|
|
|
EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.BootsSlot && el.Value != null).First().Value.EquipmentType == EquipmentTypeEnum.Boots)
|
|
|
|
{
|
|
|
|
var boots = EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.BootsSlot && el.Value != null).First().Value;
|
|
|
|
|
|
|
|
speed = BaseSpeed + speedCalculator.Calculate(boots.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PlayerPrefs.SetFloat("speed", speed);
|
|
|
|
|
2023-01-06 21:54:50 +01:00
|
|
|
//Debug.Log("Speed: " + PlayerPrefs.GetFloat("speed"));
|
2022-12-29 00:58:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// nowe - analogicznie jak w ataku
|
2022-10-23 15:56:31 +02:00
|
|
|
|
2022-03-24 18:37:17 +01:00
|
|
|
}
|