added font, updated ui, fixed some code
This commit is contained in:
142
Assets/Scripts/Player/PlayerCamera.cs
Normal file
142
Assets/Scripts/Player/PlayerCamera.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts.Player
|
||||
{
|
||||
public class PlayerCamera : MonoBehaviour
|
||||
{
|
||||
UIHandler uihandler;
|
||||
GameObject player;
|
||||
Vector2 rotation = Vector2.zero;
|
||||
public float mouseSpeed = 1; //the sensibility
|
||||
public float controllerSpeed = 0.01f; //the sensibility
|
||||
float xMaxLimit = 50.0f;
|
||||
float xMinLimit = -50.0f;
|
||||
GameObject interact;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
|
||||
player = gameObject.transform.parent.gameObject;
|
||||
interact = GameObject.Find("pnlInteract");
|
||||
interact.transform.localScale = new Vector3(0,0,0);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
transform.position = new Vector3(transform.parent.transform.position.x, transform.position.y, transform.parent.transform.position.z);
|
||||
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
showInformation();
|
||||
}
|
||||
|
||||
public void lookAround(Vector2 view, bool isController){
|
||||
rotation.y += view.x;
|
||||
rotation.x += -view.y;
|
||||
rotation.x = Mathf.Clamp(rotation.x, xMinLimit, xMaxLimit);
|
||||
if(isController){
|
||||
transform.eulerAngles = (Vector2)rotation * controllerSpeed;
|
||||
}
|
||||
else{
|
||||
transform.eulerAngles = (Vector2)rotation * mouseSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject interactWithObject()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(transform.position, transform.forward, out hit, 3))
|
||||
{
|
||||
if (hit.collider.gameObject.tag.ToLower().Contains("object"))
|
||||
{
|
||||
return hit.collider.gameObject;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void showInformation()
|
||||
{
|
||||
RaycastHit hit;
|
||||
interact.transform.localScale = new Vector3(0,0,0);
|
||||
if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity))
|
||||
{
|
||||
if (hit.collider.gameObject.tag.ToLower().Contains("object"))
|
||||
{
|
||||
string obj = hit.collider.gameObject.tag.Split(':')[1];
|
||||
if(hit.distance <= 3 && !obj.ToLower().Equals("house")){
|
||||
interact.transform.localScale = new Vector3(1,1,1);
|
||||
}
|
||||
switch (obj.ToLower())
|
||||
{
|
||||
case "tree":
|
||||
displayInformation(TextHandler.getText("tree"));
|
||||
break;
|
||||
case "stone":
|
||||
displayInformation(TextHandler.getText("rock"));
|
||||
break;
|
||||
case "npc":
|
||||
displayInformation("NPC");
|
||||
break;
|
||||
case "enemy":
|
||||
displayInformation(TextHandler.translate(hit.collider.gameObject.GetComponent<Enemy>().getEnemyName()));
|
||||
break;
|
||||
case "house":
|
||||
displayInformation(TextHandler.getText("house"));
|
||||
break;
|
||||
case "door":
|
||||
displayInformation(TextHandler.getText("door"));
|
||||
break;
|
||||
case "chest":
|
||||
displayInformation(TextHandler.getText("chest"));
|
||||
break;
|
||||
case "ore":
|
||||
if(hit.collider.gameObject.name.ToLower().Contains("iron")){
|
||||
displayInformation(TextHandler.translate("Iron ore"));
|
||||
}
|
||||
else if(hit.collider.gameObject.name.ToLower().Contains("gold")){
|
||||
displayInformation(TextHandler.translate("Gold ore"));
|
||||
}
|
||||
else if(hit.collider.gameObject.name.ToLower().Contains("copper")){
|
||||
displayInformation(TextHandler.translate("Copper ore"));
|
||||
}
|
||||
else if(hit.collider.gameObject.name.ToLower().Contains("tin")){
|
||||
displayInformation(TextHandler.translate("Tin ore"));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
uihandler.hideInformation();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uihandler.hideInformation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uihandler.hideInformation();
|
||||
}
|
||||
}
|
||||
|
||||
private void displayInformation(string information)
|
||||
{
|
||||
if (!uihandler.isPlayerInFight())
|
||||
{
|
||||
uihandler.displayInformation(information);
|
||||
}
|
||||
else
|
||||
{
|
||||
uihandler.hideInformation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Player/PlayerCamera.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerCamera.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccf47fd0e7044a6f08a0f3353ee62cf5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
376
Assets/Scripts/Player/PlayerGameObject.cs
Normal file
376
Assets/Scripts/Player/PlayerGameObject.cs
Normal file
@@ -0,0 +1,376 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scripts.Classes;
|
||||
using Assets.Scripts.Races;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Assets.Scripts.Player
|
||||
{
|
||||
public class PlayerGameObject : MonoBehaviour
|
||||
{
|
||||
UIHandler uihandler;
|
||||
AudioHandler audioHandler;
|
||||
WorldGenerator worldGenerator;
|
||||
Inventory inventory;
|
||||
int difficulty = 0;
|
||||
bool finishedGame = false;
|
||||
PlayerObject player;
|
||||
public float speed = 5f;
|
||||
DateTime jumpTimer;
|
||||
DateTime now;
|
||||
int bobbingDirection = -1;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
SceneHandler.switchGameToMenu();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
|
||||
audioHandler = GameObject.Find("AudioHandler").GetComponent<AudioHandler>();
|
||||
|
||||
if (GameObject.Find("Inventory") != null)
|
||||
{
|
||||
inventory = GameObject.Find("Inventory").GetComponent<Inventory>();
|
||||
}
|
||||
if (GameObject.Find("WorldGenerator") != null)
|
||||
{
|
||||
worldGenerator = GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>();
|
||||
}
|
||||
generatePlayer();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (player.getStat("Killcount").getAmount() != -1)
|
||||
{
|
||||
getRotation();
|
||||
regeneratePlayer();
|
||||
uihandler.adjustInformation(this);
|
||||
if (!finishedGame)
|
||||
{
|
||||
gameFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void regeneratePlayer()
|
||||
{
|
||||
if (uihandler.state != UIState.FIGHT)
|
||||
{
|
||||
if (now == null)
|
||||
{
|
||||
now = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (now.AddSeconds(10).CompareTo(DateTime.Now) <= 0)
|
||||
{
|
||||
now = DateTime.Now;
|
||||
player.regainSecondary(inventory.getEquipmentBonus()["MPR"],inventory.getEquipmentBonus()["MP"]);
|
||||
player.healPlayer(inventory.getEquipmentBonus()["HPR"],inventory.getEquipmentBonus()["HP"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
now = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void generatePlayer()
|
||||
{
|
||||
BasicRace race = new BasicRace();
|
||||
BasicClass role = new BasicClass();
|
||||
switch (PlayerPrefs.GetInt("class"))
|
||||
{
|
||||
case 0:
|
||||
role = new WarriorClass();
|
||||
break;
|
||||
case 1:
|
||||
role = new MageClass();
|
||||
break;
|
||||
case 2:
|
||||
role = new ThiefClass();
|
||||
break;
|
||||
}
|
||||
switch (PlayerPrefs.GetInt("race"))
|
||||
{
|
||||
case 0:
|
||||
race = new HumanRace();
|
||||
break;
|
||||
case 1:
|
||||
race = new ElvenRace();
|
||||
break;
|
||||
case 2:
|
||||
race = new DwarvenRace();
|
||||
break;
|
||||
case 3:
|
||||
race = new GoblinRace();
|
||||
break;
|
||||
case 4:
|
||||
race = new GiantRace();
|
||||
break;
|
||||
}
|
||||
string playername = PlayerPrefs.GetString("playername");
|
||||
difficulty = PlayerPrefs.GetInt("difficulty");
|
||||
player = new PlayerObject(playername, race, role, difficulty);
|
||||
}
|
||||
|
||||
public void generatePlayer(BasicRace playerRace, BasicClass playerClass, string name, int difficulty){
|
||||
player = new PlayerObject(name, playerRace, playerClass, difficulty);
|
||||
}
|
||||
|
||||
public void move(Vector3 input)
|
||||
{
|
||||
GameObject camera = GameObject.Find("Main Camera");
|
||||
|
||||
if (input.y != 0)
|
||||
{
|
||||
if (jumpTimer != null)
|
||||
{
|
||||
if (jumpTimer.AddSeconds(1).CompareTo(DateTime.Now) <= 0)
|
||||
{
|
||||
jumpTimer = DateTime.Now;
|
||||
gameObject.GetComponent<Rigidbody>().velocity = new Vector3(0, 5, 0);
|
||||
audioHandler.playJump();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
jumpTimer = DateTime.Now;
|
||||
gameObject.GetComponent<Rigidbody>().velocity = new Vector3(0, 5, 0);
|
||||
audioHandler.playJump();
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 movement = new Vector3(input.x, 0, input.z);
|
||||
movement = camera.transform.TransformDirection(movement);
|
||||
movement.y = 0;
|
||||
gameObject.transform.Translate(movement * speed * Time.deltaTime);
|
||||
|
||||
if (input.z != 0)
|
||||
{
|
||||
if (camera.transform.localPosition.y >= 0.5)
|
||||
{
|
||||
bobbingDirection = -1;
|
||||
}
|
||||
else if (camera.transform.localPosition.y <= 0.3)
|
||||
{
|
||||
bobbingDirection = 1;
|
||||
}
|
||||
|
||||
camera.transform.Translate(new Vector3(0, bobbingDirection, 0) * Time.deltaTime / 2);
|
||||
}
|
||||
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("explore", gameObject, 1);
|
||||
}
|
||||
|
||||
public void getRotation()
|
||||
{
|
||||
GameObject needle = GameObject.Find("imgNeedle");
|
||||
float rotation = GameObject.Find("Main Camera").transform.rotation.eulerAngles.y;
|
||||
if (rotation < 0)
|
||||
{
|
||||
rotation += 360;
|
||||
}
|
||||
if (rotation >= 360)
|
||||
{
|
||||
rotation -= 360;
|
||||
}
|
||||
needle.transform.eulerAngles = new Vector3(0, 0, rotation);
|
||||
}
|
||||
|
||||
public void gameFinished()
|
||||
{
|
||||
if (worldGenerator.gameWon())
|
||||
{
|
||||
finishedGame = true;
|
||||
uihandler.showMessage("SUCCESS;" + TextHandler.getText("gameWon"));
|
||||
switch (difficulty)
|
||||
{
|
||||
case 0:
|
||||
SteamWorksHandler.getStandardAchievement("EasyAchievement");
|
||||
break;
|
||||
case 1:
|
||||
SteamWorksHandler.getStandardAchievement("NormalAchievement");
|
||||
break;
|
||||
case 2:
|
||||
SteamWorksHandler.getStandardAchievement("HardAchievement");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void OnTriggerEnter(Collider col)
|
||||
{
|
||||
if (col.gameObject.name.Contains("_"))
|
||||
{
|
||||
worldGenerator.changeCurrentTile(col.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerStay(Collider col)
|
||||
{
|
||||
if (col.gameObject.name.Contains("border"))
|
||||
{
|
||||
Vector3 newTile = new Vector3();
|
||||
if (col.gameObject.name.ToLower() == "bordernorth")
|
||||
{
|
||||
newTile = newTile + new Vector3(0, 0, 1);
|
||||
}
|
||||
if (col.gameObject.name.ToLower() == "bordersouth")
|
||||
{
|
||||
newTile = newTile + new Vector3(0, 0, -1);
|
||||
}
|
||||
if (col.gameObject.name.ToLower() == "bordereast")
|
||||
{
|
||||
newTile = newTile + new Vector3(1, 0, 0);
|
||||
}
|
||||
if (col.gameObject.name.ToLower() == "borderwest")
|
||||
{
|
||||
newTile = newTile + new Vector3(-1, 0, 0);
|
||||
}
|
||||
worldGenerator.createTile(newTile);
|
||||
}
|
||||
}
|
||||
|
||||
public void displayAction(int index, GameObject image, GameObject desc)
|
||||
{
|
||||
player.getSkill(index).display(image, desc, player.getStat("Secondary").getAmount());
|
||||
}
|
||||
|
||||
public void enemyKilled()
|
||||
{
|
||||
uihandler.showMessage("SUCCESS;" + TextHandler.getText("enemyKilled"));
|
||||
player.getStat("Killcount").changeAmount(1);
|
||||
SteamWorksHandler.getSlimeAchievement(player.getStat("Killcount").getAmount());
|
||||
gameFinished();
|
||||
}
|
||||
|
||||
public void gainExperience(int amount)
|
||||
{
|
||||
if (player.gainExperience(amount))
|
||||
{
|
||||
uihandler.showMessage("SUCCESS;" + TextHandler.getText("levelUp"));
|
||||
audioHandler.playLevelUp();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateName(Text nameUI)
|
||||
{
|
||||
nameUI.text = player.getPlayerName() + " (" + TextHandler.getText(player.getRace().racename) + "/" + TextHandler.getText(player.getClass().classname) + ", Lvl. " + player.getStat("Level").getAmount() + ")";
|
||||
}
|
||||
|
||||
public void updateNameHUD(Text nameUI)
|
||||
{
|
||||
nameUI.text = player.getPlayerName() + "\n\r" + TextHandler.getText(player.getRace().racename) + "/" + TextHandler.getText(player.getClass().classname) + "\r\n Lvl. " + player.getStat("Level").getAmount();
|
||||
}
|
||||
|
||||
public void upgradeStrength()
|
||||
{
|
||||
if (!player.upgradeStat("Strength", 1))
|
||||
{
|
||||
uihandler.showMessage("ERROR;" + TextHandler.getText("noPoints"));
|
||||
}
|
||||
}
|
||||
|
||||
public void upgradeDexterity()
|
||||
{
|
||||
if (!player.upgradeStat("Dexterity", 1))
|
||||
{
|
||||
uihandler.showMessage("ERROR;" + TextHandler.getText("noPoints"));
|
||||
}
|
||||
}
|
||||
|
||||
public void upgradeIntelligence()
|
||||
{
|
||||
if (!player.upgradeStat("Intelligence", 1))
|
||||
{
|
||||
uihandler.showMessage("ERROR;" + TextHandler.getText("noPoints"));
|
||||
}
|
||||
}
|
||||
|
||||
public void upgradeHealth()
|
||||
{
|
||||
if (!player.upgradeStat("MaxHealth", 5))
|
||||
{
|
||||
uihandler.showMessage("ERROR;" + TextHandler.getText("noPoints"));
|
||||
}
|
||||
}
|
||||
|
||||
public void upgradeSecondary()
|
||||
{
|
||||
if (!player.upgradeStat("MaxSecondary", 5))
|
||||
{
|
||||
uihandler.showMessage("ERROR;" + TextHandler.getText("noPoints"));
|
||||
}
|
||||
}
|
||||
|
||||
public void displaySkills(GameObject pnlSkills)
|
||||
{
|
||||
for (int i = 1; i <= 3; i++)
|
||||
{
|
||||
GameObject skill = pnlSkills.transform.Find("skill" + i).gameObject;
|
||||
player.getSkill(i - 1).displaySkill(skill.transform.Find("imgAction").gameObject, skill.transform.Find("descAction").gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerStat getPlayerStat(string identifier){
|
||||
return player.getStat(identifier);
|
||||
}
|
||||
|
||||
public void loadPlayer(JToken json){
|
||||
player = new PlayerObject();
|
||||
player.loadPlayer(json);
|
||||
}
|
||||
|
||||
public PlayerObject getPlayer(){
|
||||
return player;
|
||||
}
|
||||
|
||||
public string saveGame(){
|
||||
return player.saveGame();
|
||||
}
|
||||
|
||||
public BasicClass getClass(){
|
||||
return player.getClass();
|
||||
}
|
||||
|
||||
public BasicRace getRace(){
|
||||
return player.getRace();
|
||||
}
|
||||
|
||||
public int calculateDamage(){
|
||||
return player.calculateDamage(inventory.getEquipmentBonus()["STR"], inventory.getEquipmentBonus()["DEX"]);
|
||||
}
|
||||
|
||||
public bool takeDamage(int amount){
|
||||
if(player != null){
|
||||
return player.takeDamage(amount,inventory.getEquipmentBonus()["DEX"], inventory.getEquipmentBonus()["INT"]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int castSkill(int skillnumber){
|
||||
return player.castSkill(skillnumber,inventory.getEquipmentBonus()["INT"], inventory.getEquipmentBonus()["STR"], inventory.getEquipmentBonus()["DEX"]);
|
||||
}
|
||||
|
||||
public void reduceCooldown(int skillnumber){
|
||||
player.reduceCooldown(skillnumber);
|
||||
}
|
||||
|
||||
public void regainSecondary(){
|
||||
player.regainSecondary(inventory.getEquipmentBonus()["MPR"], inventory.getEquipmentBonus()["MP"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Player/PlayerGameObject.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerGameObject.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac07c553f4e010e8299fb870481dcc49
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
381
Assets/Scripts/Player/PlayerObject.cs
Normal file
381
Assets/Scripts/Player/PlayerObject.cs
Normal file
@@ -0,0 +1,381 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Assets.Scripts.Classes;
|
||||
using Assets.Scripts.Races;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Assets.Scripts.Player
|
||||
{
|
||||
public class PlayerObject
|
||||
{
|
||||
Random rand = new Random();
|
||||
Dictionary<string, PlayerStat> stats;
|
||||
string playername;
|
||||
BasicRace race;
|
||||
BasicClass role;
|
||||
BasicSkill[] skills = new BasicSkill[3];
|
||||
bool isDodging = false;
|
||||
int difficulty;
|
||||
|
||||
public PlayerObject(string playername, BasicRace race, BasicClass role, int difficulty)
|
||||
{
|
||||
this.playername = playername;
|
||||
this.race = race;
|
||||
this.role = role;
|
||||
this.difficulty = difficulty;
|
||||
generateStats(false);
|
||||
generateSkills();
|
||||
EasterEggHandler.applyEasterEgg(this);
|
||||
}
|
||||
|
||||
public PlayerObject()
|
||||
{
|
||||
generateStats(true);
|
||||
}
|
||||
|
||||
private void generateStats(bool isLoad)
|
||||
{
|
||||
stats = new Dictionary<string, PlayerStat>();
|
||||
stats.Add("Health", new PlayerStat("Health", 100, "The current health of the player"));
|
||||
stats.Add("MaxHealth", new PlayerStat("MaxHealth", 100, "The current max health of the player"));
|
||||
stats.Add("Secondary", new PlayerStat("Secondary", 20, "The current secondary of the player"));
|
||||
stats.Add("MaxSecondary", new PlayerStat("MaxSecondary", 20, "The current max secondary of the player"));
|
||||
stats.Add("Strength", new PlayerStat("Strength", 5, "The current strength of the player"));
|
||||
stats.Add("Dexterity", new PlayerStat("Dexterity", 5, "The current dexterity of the player"));
|
||||
stats.Add("Intelligence", new PlayerStat("Intelligence", 5, "The current intelligence of the player"));
|
||||
stats.Add("Experience", new PlayerStat("Experience", 0, "The current experience of the player"));
|
||||
stats.Add("MaxExperience", new PlayerStat("MaxExperience", 10, "The current max experience of the player"));
|
||||
stats.Add("HealthRegen", new PlayerStat("HealthRegen", 30 / (difficulty + 1), "The current health regen of the player"));
|
||||
stats.Add("SecondaryRegen", new PlayerStat("SecondaryRegen", 5, "The current secondary regen of the player"));
|
||||
stats.Add("Level", new PlayerStat("Level", 0, "The current level of the player"));
|
||||
stats.Add("Luck", new PlayerStat("Luck", 20 - (difficulty * 5), "The current luck of the player"));
|
||||
stats.Add("Killcount", new PlayerStat("Killcount", -1, "The current killcount of the player"));
|
||||
stats.Add("Points", new PlayerStat("Points", 0, "The current skillpoints of the player"));
|
||||
|
||||
if (!isLoad)
|
||||
{
|
||||
race.applyBonus(this);
|
||||
role.applyBonus(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void generateSkills()
|
||||
{
|
||||
switch (role.classname)
|
||||
{
|
||||
case "Warrior":
|
||||
skills[0] = new BasicSkill(20, 10, 2, "Slash", "Skills/Warrior/Slash", null);
|
||||
skills[0].setDescription(TextHandler.getText("slashDesc"));
|
||||
skills[1] = new BasicSkill(0, 5, 1, "Block", "Skills/Warrior/Block", null);
|
||||
skills[1].setDescription(TextHandler.getText("blockDesc"));
|
||||
skills[2] = new BasicSkill(35, 30, 4, "Execution", "Skills/Warrior/Execution", null);
|
||||
skills[2].setDescription(TextHandler.getText("executionDesc"));
|
||||
break;
|
||||
case "Thief":
|
||||
skills[0] = new BasicSkill(20, 10, 2, "Stab", "Skills/Thief/Stab", null);
|
||||
skills[0].setDescription(TextHandler.getText("stabDesc"));
|
||||
skills[1] = new BasicSkill(0, 5, 1, "SmokeScreen", "Skills/Thief/SmokeScreen", null);
|
||||
skills[1].setDescription(TextHandler.getText("smokeScreenDesc"));
|
||||
skills[2] = new BasicSkill(35, 30, 4, "Heartstop", "Skills/Thief/Heartstop", null);
|
||||
skills[2].setDescription(TextHandler.getText("heartStopDesc"));
|
||||
break;
|
||||
case "Mage":
|
||||
skills[0] = new BasicSkill(20, 10, 2, "Icicle", "Skills/Mage/Icicle", null);
|
||||
skills[0].setDescription(TextHandler.getText("icicleDesc"));
|
||||
skills[1] = new BasicSkill(0, 5, 1, "Teleport", "Skills/Mage/Teleport", null);
|
||||
skills[1].setDescription(TextHandler.getText("teleportDesc"));
|
||||
skills[2] = new BasicSkill(35, 30, 4, "Fireball", "Skills/Mage/Fireball", null);
|
||||
skills[2].setDescription(TextHandler.getText("fireballDesc"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void loadPlayer(JToken json)
|
||||
{
|
||||
playername = json["playername"].ToString();
|
||||
|
||||
stats["MaxHealth"].setAmount((int)json["maxHealth"]);
|
||||
stats["MaxSecondary"].setAmount((int)json["maxSecondary"]);
|
||||
stats["Secondary"].setAmount((int)json["secondary"]);
|
||||
stats["Health"].setAmount((int)json["health"]);
|
||||
stats["Strength"].setAmount((int)json["strength"]);
|
||||
stats["Dexterity"].setAmount((int)json["dexterity"]);
|
||||
stats["Intelligence"].setAmount((int)json["intelligence"]);
|
||||
stats["Level"].setAmount((int)json["level"]);
|
||||
stats["Experience"].setAmount((int)json["experience"]);
|
||||
stats["MaxExperience"].setAmount((int)json["maxExperience"]);
|
||||
stats["Points"].setAmount((int)json["points"]);
|
||||
stats["Luck"].setAmount((int)json["luck"]);
|
||||
stats["HealthRegen"].setAmount((int)json["healthRegen"]);
|
||||
stats["SecondaryRegen"].setAmount((int)json["secondaryRegen"]);
|
||||
stats["Killcount"].setAmount((int)json["killcount"]);
|
||||
|
||||
loadRole(json["role"].ToString());
|
||||
loadRace(json["race"].ToString());
|
||||
isDodging = bool.Parse(json["isDodging"].ToString());
|
||||
difficulty = (int)json["difficulty"];
|
||||
generateSkills();
|
||||
}
|
||||
|
||||
private void loadRole(string name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "Warrior":
|
||||
role = new WarriorClass();
|
||||
break;
|
||||
case "Mage":
|
||||
role = new MageClass();
|
||||
break;
|
||||
case "Thief":
|
||||
role = new ThiefClass();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadRace(string name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "Human":
|
||||
race = new HumanRace();
|
||||
break;
|
||||
case "Dwarf":
|
||||
race = new DwarvenRace();
|
||||
break;
|
||||
case "Elf":
|
||||
race = new ElvenRace();
|
||||
break;
|
||||
case "Giant":
|
||||
race = new GiantRace();
|
||||
break;
|
||||
case "Goblin":
|
||||
race = new GoblinRace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void changeStats(int strength, int health, int dexterity, int intelligence, int secondary)
|
||||
{
|
||||
stats["MaxHealth"].changeAmount(health);
|
||||
stats["Health"].changeAmount(stats["MaxHealth"].getAmount());
|
||||
stats["MaxSecondary"].changeAmount(secondary);
|
||||
stats["Secondary"].changeAmount(stats["MaxSecondary"].getAmount());
|
||||
stats["Strength"].changeAmount(strength);
|
||||
stats["Dexterity"].changeAmount(dexterity);
|
||||
stats["Intelligence"].changeAmount(intelligence);
|
||||
}
|
||||
|
||||
public void regainSecondary(int equipRegen, int equipStat)
|
||||
{
|
||||
stats["Secondary"].changeAmount(stats["SecondaryRegen"].getAmount() + equipRegen);
|
||||
if (stats["Secondary"].getAmount() >= stats["MaxSecondary"].getAmount() + equipStat)
|
||||
{
|
||||
stats["Secondary"].setAmount(stats["MaxSecondary"].getAmount() + equipStat);
|
||||
}
|
||||
}
|
||||
|
||||
public void healPlayer(int equipRegen, int equipStat)
|
||||
{
|
||||
stats["Health"].changeAmount(stats["HealthRegen"].getAmount() + equipRegen);
|
||||
if (stats["Health"].getAmount() >= stats["MaxHealth"].getAmount() + equipStat)
|
||||
{
|
||||
stats["Health"].setAmount(stats["MaxHealth"].getAmount() + equipStat);
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, PlayerStat> getStats()
|
||||
{
|
||||
return stats;
|
||||
}
|
||||
|
||||
public void setStats(Dictionary<string, PlayerStat> stats)
|
||||
{
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
public PlayerStat getStat(string identifier)
|
||||
{
|
||||
return stats[identifier];
|
||||
}
|
||||
|
||||
public BasicSkill getSkill(int index)
|
||||
{
|
||||
return skills[index];
|
||||
}
|
||||
|
||||
public int calculateDamage(int equipStatStr, int equipStatDex)
|
||||
{
|
||||
int result;
|
||||
int bonus = 0;
|
||||
if (isCrit(equipStatDex))
|
||||
{
|
||||
bonus = (stats["Strength"].getAmount() + equipStatStr) * 2;
|
||||
}
|
||||
result = stats["Strength"].getAmount() + bonus + 5 + equipStatStr;
|
||||
switch (difficulty)
|
||||
{
|
||||
case 0:
|
||||
result = result * 2;
|
||||
break;
|
||||
case 1:
|
||||
//Default difficulty
|
||||
break;
|
||||
case 2:
|
||||
result = result / 2;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int castSkill(int index, int equipStatInt, int equipStatStr, int equipStatDex)
|
||||
{
|
||||
int damage = 0;
|
||||
if (skills[index].canPlayerCast(stats["Secondary"].getAmount()))
|
||||
{
|
||||
if (index == 1)
|
||||
{
|
||||
isDodging = true;
|
||||
}
|
||||
stats["Secondary"].changeAmount(-skills[index].getSecondaryConsumption());
|
||||
if (role.classname == "Wizard")
|
||||
{
|
||||
damage = skills[index].calculateDamage(stats["Intelligence"].getAmount() + equipStatInt, isCrit(equipStatDex));
|
||||
}
|
||||
else
|
||||
{
|
||||
damage = skills[index].calculateDamage(stats["Strength"].getAmount() + equipStatStr, isCrit(equipStatDex));
|
||||
}
|
||||
|
||||
switch (difficulty)
|
||||
{
|
||||
case 0:
|
||||
damage = damage * 2;
|
||||
break;
|
||||
case 1:
|
||||
//Default difficulty
|
||||
break;
|
||||
case 2:
|
||||
damage = damage / 2;
|
||||
break;
|
||||
}
|
||||
//TODO: Let caller of this method handle audio if damage is higher than 0 // skills[index].playSound(audioHandler);
|
||||
}
|
||||
return damage;
|
||||
}
|
||||
|
||||
public void reduceCooldown(int index)
|
||||
{
|
||||
for (int i = 0; i < skills.Length; i++)
|
||||
{
|
||||
if (i != index)
|
||||
{
|
||||
skills[i].reduceCooldown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool isCrit(int equipStat)
|
||||
{
|
||||
return rand.Next(1, 101) <= stats["Dexterity"].getAmount() + equipStat;
|
||||
}
|
||||
|
||||
public bool takeDamage(int amount, int equipStatDex, int equipStatInt)
|
||||
{
|
||||
|
||||
if (amount <= 0 || EasterEggHandler.isGodMode(this))
|
||||
{
|
||||
return stats["Health"].getAmount() <= 0;
|
||||
}
|
||||
|
||||
if (isDodging)
|
||||
{
|
||||
isDodging = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
int dodgeChance = stats["Dexterity"].getAmount() + equipStatDex + ((stats["Intelligence"].getAmount() + equipStatInt) / 2);
|
||||
if (rand.Next(1, 101) > dodgeChance)
|
||||
{
|
||||
stats["Health"].changeAmount(-amount);
|
||||
//TODO: Let caller of this method handle audio // audioHandler.playDamage();
|
||||
}
|
||||
}
|
||||
return stats["Health"].getAmount() <= 0;
|
||||
}
|
||||
|
||||
public bool gainExperience(int amount)
|
||||
{
|
||||
bool result = false;
|
||||
stats["Experience"].changeAmount(amount);
|
||||
if (stats["Experience"].getAmount() >= stats["MaxExperience"].getAmount())
|
||||
{
|
||||
stats["Experience"].changeAmount(-stats["MaxExperience"].getAmount());
|
||||
stats["MaxExperience"].changeAmount(stats["MaxExperience"].getAmount());
|
||||
stats["Level"].changeAmount(1);
|
||||
stats["Points"].changeAmount(3);
|
||||
stats["Luck"].changeAmount(2);
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool upgradeStat(string identifier, int amount)
|
||||
{
|
||||
bool result = false;
|
||||
if (stats["Points"].getAmount() > 0)
|
||||
{
|
||||
result = true;
|
||||
stats[identifier].changeAmount(amount);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public string getPlayerName()
|
||||
{
|
||||
return playername;
|
||||
}
|
||||
|
||||
public int getDifficulty()
|
||||
{
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public BasicRace getRace()
|
||||
{
|
||||
return race;
|
||||
}
|
||||
|
||||
public BasicClass getClass()
|
||||
{
|
||||
return role;
|
||||
}
|
||||
|
||||
public string saveGame()
|
||||
{
|
||||
string result = "";
|
||||
result = result + FileHandler.generateJSON("playername", "\"" + playername + "\"") + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("maxHealth", stats["MaxHealth"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("maxSecondary", stats["MaxSecondary"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("secondary", stats["Secondary"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("health", stats["Health"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("strength", stats["Strength"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("dexterity", stats["Dexterity"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("intelligence", stats["Intelligence"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("level", stats["Level"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("experience", stats["Experience"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("maxExperience", stats["MaxExperience"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("race", "\"" + race.racename + "\"") + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("role", "\"" + role.classname + "\"") + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("points", stats["Points"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("healthRegen", stats["HealthRegen"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("secondaryRegen", stats["SecondaryRegen"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("isDodging", "\"" + isDodging + "\"") + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("killcount", stats["Killcount"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("luck", stats["Luck"].getAmount()) + ",\r\n";
|
||||
result = result + FileHandler.generateJSON("difficulty", difficulty);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Player/PlayerObject.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerObject.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f3ccf8e929cf8c32b9a9479e8870bbd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
Assets/Scripts/Player/PlayerStat.cs
Normal file
48
Assets/Scripts/Player/PlayerStat.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scripts.Classes;
|
||||
using Assets.Scripts.Races;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Assets.Scripts.Player
|
||||
{
|
||||
public class PlayerStat
|
||||
{
|
||||
string text;
|
||||
int amount;
|
||||
string tooltip;
|
||||
|
||||
public PlayerStat(string text, int amount, string tooltip){
|
||||
this.text = text;
|
||||
this.amount = amount;
|
||||
this.tooltip = tooltip;
|
||||
}
|
||||
|
||||
public string getTooltip(){
|
||||
return this.tooltip;
|
||||
}
|
||||
|
||||
public string getText(){
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public int getAmount(){
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
public void changeAmount(int change){
|
||||
this.amount = this.amount + change;
|
||||
}
|
||||
|
||||
public void setAmount(int amount){
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Player/PlayerStat.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerStat.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3038d55d00ed9d790b3f50d461689251
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user