Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ########################################## Attributes file ########################################## //
- public class Attribute : BaseStat {
- public Attribute() {
- // Henter ExpToLevel og LevelModifier from Basic Setters And Getters @ Basestat
- ExpToLevel = 50;
- LevelModifier = 1.05f;
- }
- }
- // List of all the attributes in the game
- public enum AttributeName {
- Might,
- Constitution,
- Nimbleness,
- Speed,
- Consentration,
- Willpower,
- Charisma
- }
- // ########################################## BaseCharacter file ########################################## //
- using UnityEngine;
- using System.Collections;
- using System; //Added to access the enum
- public class BaseCharacter : MonoBehaviour {
- private string _name;
- private int _level;
- private uint _freeExp;
- private Attribute[] _primaryAttribute;
- private Vital[] _vital;
- private Skill[] _skill;
- public void Awake() {
- _name = string.Empty;
- _level = 0;
- _freeExp = 0;
- _primaryAttribute = new Attribute[Enum.GetValues(typeof(AttributeName)).Length];
- _vital = new Vital[Enum.GetValues(typeof(VitalName)).Length];
- _skill = new Skill[Enum.GetValues(typeof(SkillName)).Length];
- SetupPrimaryAttributes();
- SetupVitals();
- SetupSkills();
- }
- public string Name {
- get{ return _name; }
- set{ _name = value;}
- }
- public int Level {
- get{ return _level; }
- set { _level = value; }
- }
- public uint FreeExp {
- get{ return _freeExp; }
- set{ _freeExp = value; }
- }
- public void AddExp(uint exp) {
- _freeExp += exp;
- CalculateLevel();
- }
- //take average of all of the players skills and assign that as the players level
- public void CalculateLevel() {
- }
- private void SetupPrimaryAttributes() {
- for(int cnt = 0; cnt < _primaryAttribute.Length; cnt++)
- _primaryAttribute[cnt] = new Attribute();
- // _primaryAttribute[cnt].Name = ((AttributeName)cnt).ToString();
- }
- private void SetupVitals() {
- for(int cnt = 0; cnt < _vital.Length; cnt++)
- _vital[cnt] = new Vital();
- SetupVitalModifiers ();
- }
- private void SetupSkills() {
- for(int cnt = 0; cnt < _skill.Length; cnt++)
- _skill[cnt] = new Skill();
- SetupSkillModifiers ();
- }
- public Attribute GetPrimaryAttribute(int index) {
- return _primaryAttribute[index];
- }
- public Vital GetVital(int index) {
- return _vital[index];
- }
- public Skill GetSkill(int index) {
- return _skill[index];
- }
- private void SetupVitalModifiers() {
- //Health
- //GetVital((int)VitalName.Health).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), .5f));
- ModifyingAttribute health = new ModifyingAttribute();
- health.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
- health.ratio = .5f;
- //Energy
- //GetVital((int)VitalName.Energy).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), 1));
- ModifyingAttribute energy = new ModifyingAttribute();
- energy.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
- energy.ratio = 1;
- //Mana
- //GetVital((int)VitalName.Mana).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), 1));
- ModifyingAttribute mana = new ModifyingAttribute();
- mana.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
- mana.ratio = 1;
- }
- private void SetupSkillModifiers() {
- //Melee Offence
- //GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Might), .33f));
- //GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nimbleness), .33f));
- ModifyingAttribute MeleeOffenceModifier1 = new ModifyingAttribute();
- ModifyingAttribute MeleeOffenceModifier2 = new ModifyingAttribute();
- MeleeOffenceModifier1.attribute = GetPrimaryAttribute((int)AttributeName.Might);
- MeleeOffenceModifier2.attribute = GetPrimaryAttribute((int)AttributeName.Nimbleness);
- MeleeOffenceModifier1.ratio = .33f;
- MeleeOffenceModifier2.ratio = .33f;
- //Melee Defence
- //GetSkill((int)SkillName.Melee_defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
- //GetSkill((int)SkillName.Melee_defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), .33f));
- ModifyingAttribute MeleeDefence1 = new ModifyingAttribute();
- ModifyingAttribute MeleeDefence2 = new ModifyingAttribute();
- MeleeDefence1.attribute = GetPrimaryAttribute((int)AttributeName.Speed);
- MeleeDefence2.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
- MeleeDefence1.ratio = .33f;
- MeleeDefence2.ratio = .33f;
- //Magic Offence
- //GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Consentration), .33f));
- //GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), .33f));
- ModifyingAttribute MagicOffence1 = new ModifyingAttribute();
- ModifyingAttribute MagicOffence2 = new ModifyingAttribute();
- MagicOffence1.attribute = GetPrimaryAttribute((int)AttributeName.Consentration);
- MagicOffence2.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
- MagicOffence1.ratio = .33f;
- MagicOffence2.ratio = .33f;
- //Magic Defence
- //GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Consentration), .33f));
- //GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), .33f));
- ModifyingAttribute MagicDefence1 = new ModifyingAttribute();
- ModifyingAttribute MagicDefence2 = new ModifyingAttribute();
- MagicDefence1.attribute = GetPrimaryAttribute((int)AttributeName.Consentration);
- MagicDefence2.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
- MagicDefence1.ratio = .33f;
- MagicDefence2.ratio = .33f;
- //Ranged Offence
- //GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Consentration), .33f));
- //GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
- ModifyingAttribute RangedOffence1 = new ModifyingAttribute();
- ModifyingAttribute RangedOffence2 = new ModifyingAttribute();
- RangedOffence1.attribute = GetPrimaryAttribute((int)AttributeName.Consentration);
- RangedOffence2.attribute = GetPrimaryAttribute((int)AttributeName.Speed);
- RangedOffence1.ratio = .33f;
- RangedOffence2.ratio = .33f;
- //Ranged Defence
- //GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
- //GetSkill((int)SkillName.Ranged_Defence ).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nimbleness), .33f));
- ModifyingAttribute RangedDefence1 = new ModifyingAttribute();
- ModifyingAttribute RangedDefence2 = new ModifyingAttribute();
- RangedDefence1.attribute = GetPrimaryAttribute((int)AttributeName.Speed);
- RangedDefence2.attribute = GetPrimaryAttribute((int)AttributeName.Nimbleness);
- RangedDefence1.ratio = .33f;
- RangedDefence2.ratio = .33f;
- }
- public void StatUpdate() {
- for(int cnt = 0; cnt < _vital.Length; cnt++)
- _vital[cnt].Update();
- for(int cnt = 0; cnt < _skill.Length; cnt++)
- _skill[cnt].Update();
- }
- }
- // ########################################## BaseStats file ########################################## //
- public class BaseStat {
- private int _baseValue; // the base value of this stats
- private int _buffValue; // the ammount of the buff to this stats
- private int _expToLevel; // the total amount of XP needed to raise this skill
- private float _levelModifier; // the modifier applied to the exp needed to raise the skills
- public BaseStat() {
- _baseValue = 0;
- _buffValue = 0;
- _levelModifier = 1.1f;
- _expToLevel = 100;
- }
- #region Basic Setters And Getters
- // Basic setters and getters
- public int BaseValue {
- get { return _baseValue; }
- set { _baseValue = value; }
- }
- public int BuffValue {
- get { return _buffValue; }
- set { _buffValue = value; }
- }
- public int ExpToLevel {
- get { return _expToLevel; }
- set { _expToLevel = value; }
- }
- public float LevelModifier {
- get { return _levelModifier; }
- set { _levelModifier = value; }
- }
- #endregion
- // method used to calculate how much xp needed to gain next level
- private int CalculateExpToLevel(){
- return (int)(_expToLevel * _levelModifier);
- }
- // method used to level up and increase the basevalue.
- public void LevelUp(){
- _expToLevel = CalculateExpToLevel();
- _baseValue++;
- }
- // method used to return the basevalue + the buffed value
- public int AdjustedBaseValue {
- get{ return _baseValue + _buffValue; }
- }
- }
- // ########################################## CharacterGenerator file ########################################## //
- using UnityEngine;
- using System.Collections;
- using System; // used for the enum class
- public class CharacterGenerator : MonoBehaviour {
- private PlayerCharacter _toon; // the custom character
- private const int START_POINTS = 350; // the total ammount of start points the user can spend
- private const int MIN_START_ATTRIBUTE_VALUE = 10; // The minimum value of each startpoint.
- private int pointsLeft;
- // Use this for initialization
- void Start () {
- _toon = new PlayerCharacter();
- _toon.Awake();
- pointsLeft = START_POINTS;
- for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++){
- _toon.GetPrimaryAttribute(cnt).BaseValue = MIN_START_ATTRIBUTE_VALUE;
- }
- }
- // Update is called once per frame
- void Update () {
- }
- void OnGUI(){
- DisplayAttributes();
- DisplayPointsLeft();
- DisplayVitals();
- DisplaySkills();
- DisplayName();
- }
- private void DisplayName() {
- GUI.Label(new Rect(Screen.width / 2 + 60,445,45,25), "Name:");
- _toon.Name = GUI.TextArea(new Rect(Screen.width / 2,465,150,25),_toon.Name);
- }
- //private int numberOfAttributes = 0; // variable to count how many attributes and make adjustment in GUI size
- private void DisplayAttributes(){
- for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++){
- GUI.Label(new Rect(10,20 + (cnt * 20 ),100,25),((AttributeName)cnt).ToString() ); // name
- GUI.Label(new Rect(110,20 + (cnt * 20 ),30,25),_toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString()); // value
- if(GUI.Button(new Rect(150,20 + (cnt * 20 ),20,20), "+")){ //if " + " button is clicked // add
- if(pointsLeft > 0){
- _toon.GetPrimaryAttribute(cnt).BaseValue++;
- pointsLeft--;
- _toon.StatUpdate();
- }
- }
- //if(_toon.GetPrimaryAttribute(cnt).BaseValue < MIN_START_ATTRIBUTE_VALUE){
- //}
- if(GUI.Button(new Rect(175,20 + (cnt * 20 ),20,20), "-")){ //if " - " button is clicked // subtract
- if(_toon.GetPrimaryAttribute(cnt).BaseValue > MIN_START_ATTRIBUTE_VALUE){
- _toon.GetPrimaryAttribute(cnt).BaseValue--;
- pointsLeft++;
- _toon.StatUpdate();
- }
- }
- }
- }
- //private int numberOfVitals = 0; // variable to count how many vitals and make adjustment in GUI size
- private void DisplayVitals(){
- for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++){
- GUI.Label(new Rect(10,20 + ((cnt + 7) * 20 ),100,25),((VitalName)cnt).ToString() );
- GUI.Label(new Rect(115,20 + ((cnt + 7) * 20 ),30,25),_toon.GetVital(cnt).AdjustedBaseValue.ToString());
- //numberOfVitals++;
- }
- }
- private void DisplaySkills(){
- for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++){
- GUI.Label(new Rect(Screen.width - 110,20 + (cnt * 20 ),100,25),((SkillName)cnt).ToString() );
- GUI.Label(new Rect(Screen.width - 125,20 + (cnt * 20 ),30,25),_toon.GetSkill(cnt).AdjustedBaseValue.ToString());
- }
- }
- private void DisplayPointsLeft(){
- GUI.Label(new Rect(10,Screen.height / 2,150,20), "Points Left: " + pointsLeft);
- }
- }
- // ########################################## ModifiedStat file ########################################## //
- using System.Collections.Generic;
- public class ModifiedStat : BaseStat {
- private List<ModifyingAttribute> _mods; // a list of attributes that modify this stat
- private int _modValue; // stores the ammount added to the baseValue from the modifyers
- // constructor
- public ModifiedStat(){
- _mods = new List<ModifyingAttribute>();
- _modValue = 0;
- }
- // function to add the mod. attribute to the list
- public void AddModifyer( ModifyingAttribute mod) {
- _mods.Add(mod);
- }
- // calculate the ammout we are going to modify our base value with
- private void CalculateModValue() {
- _modValue = 0;
- if(_mods.Count > 0)
- foreach(ModifyingAttribute att in _mods)
- _modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
- }
- // Using the BaseValue and the BuffValue from Basestat's getters and setters
- public new int AdjustedBaseValue {
- get{ return BaseValue + BuffValue + _modValue; }
- }
- public void Update(){
- CalculateModValue();
- }
- }
- public struct ModifyingAttribute {
- public Attribute attribute;
- public float ratio;
- public ModifyingAttribute(Attribute att, float rat){
- attribute = att;
- ratio = rat;
- }
- }
- // ########################################## PlayerCharacter file ########################################## //
- public class PlayerCharacter : BaseCharacter {
- }
- // ########################################## Skill file ########################################## //
- public class Skill : ModifiedStat {
- private bool _known;
- public Skill(){
- _known = false;
- ExpToLevel = 25;
- LevelModifier = 1.1f;
- }
- public bool Known {
- get{ return _known; }
- set{ _known = value; }
- }
- }
- public enum SkillName {
- Melee_Offence,
- Melee_defence,
- Ranged_Offence,
- Ranged_Defence,
- Magic_Offence,
- Magic_Defence
- }
- // ########################################## Vital file ########################################## //
- public class Vital : ModifiedStat {
- private int _curValue;
- public Vital() {
- _curValue = 0;
- ExpToLevel = 50;
- LevelModifier = 1.1f;
- }
- public int CurValue {
- get{
- if(_curValue > AdjustedBaseValue)
- _curValue = AdjustedBaseValue;
- return _curValue;
- }
- set{ _curValue = value; }
- }
- }
- public enum VitalName {
- Health,
- Energy,
- Mana
- }
Advertisement
Add Comment
Please, Sign In to add comment