You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
196 lines
6.3 KiB
196 lines
6.3 KiB
using System.Collections.Generic; |
|
using System.Globalization; |
|
using System.Xml; |
|
|
|
using UnityEngine; |
|
|
|
namespace Ability |
|
{ |
|
//----------------------------------------------------------- |
|
public enum MainAbilityType |
|
{ |
|
ADD_DAMAGE, |
|
ADD_ATTACK_SPEED, |
|
ADD_HEALTH, |
|
ADD_ARMOR_COLLISION_TRAP, |
|
ADD_ARMOR_SHOT, |
|
ADD_HEAL, |
|
ADD_DROP_GOLD, |
|
ADD_DROP_ITEMS, |
|
ADD_EQUIP, |
|
} |
|
|
|
//----------------------------------------------------------- |
|
public class MainAbilityInfo |
|
{ |
|
public int m_baseParam; |
|
public float m_skillParam; |
|
public int m_lvlUp; |
|
public bool m_isActive; |
|
} |
|
|
|
//----------------------------------------------------------- |
|
public class MainAbility |
|
{ |
|
Dictionary<MainAbilityType, MainAbilityInfo> m_abilities = new Dictionary<MainAbilityType, MainAbilityInfo>(); |
|
|
|
//----------------------------------------------------------- |
|
public void Init() |
|
{ |
|
ParseXml(); |
|
InitAbInfo(); |
|
} |
|
|
|
//----------------------------------------------------------- |
|
void InitAbInfo() |
|
{ |
|
foreach (MainAbilityType type in m_abilities.Keys) |
|
{ |
|
bool isActive = GlobalsVar.gUser.GetMainAbActive(type.ToString()); |
|
m_abilities[type].m_isActive = isActive; |
|
|
|
int lvlUp = GlobalsVar.gUser.GetMainAbLvlUp(type.ToString()); |
|
m_abilities[type].m_lvlUp = lvlUp; |
|
} |
|
} |
|
|
|
//----------------------------------------------------------- |
|
void ParseXml() |
|
{ |
|
TextAsset xml = Resources.Load("data/MainAbilitySettings") as TextAsset; |
|
|
|
XmlDocument file = new XmlDocument(); |
|
file.LoadXml(xml.text); |
|
|
|
XmlNode pRoot = file.DocumentElement; |
|
if (pRoot == null) |
|
{ |
|
CommonFunctions.myassert(false, "Root element not found or xml doesn't load!"); |
|
return; |
|
} |
|
|
|
NumberStyles style = NumberStyles.Number; |
|
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-GB"); |
|
|
|
int baseParam = 0; |
|
foreach (XmlAttribute attr in pRoot.Attributes) |
|
{ |
|
if (attr.Name == "base_param") |
|
int.TryParse(attr.Value, style, culture, out baseParam); |
|
} |
|
|
|
foreach (XmlNode childNode in pRoot.ChildNodes) |
|
{ |
|
MainAbilityInfo info = new MainAbilityInfo(); |
|
info.m_baseParam = baseParam; |
|
|
|
foreach (XmlAttribute attr in childNode.Attributes) |
|
{ |
|
if (attr.Name == "skill_param") |
|
float.TryParse(attr.Value, style, culture, out info.m_skillParam); |
|
} |
|
|
|
info.m_lvlUp = 0; |
|
MainAbilityType type = GetAbilityTypeByName(childNode.Name); |
|
|
|
m_abilities.Add(type, info); |
|
} |
|
} |
|
|
|
//----------------------------------------------------------- |
|
public MainAbilityType GetAbilityTypeByName(string name) |
|
{ |
|
if (name == "ADD_DAMAGE") |
|
return MainAbilityType.ADD_DAMAGE; |
|
else if (name == "ADD_HEALTH") |
|
return MainAbilityType.ADD_HEALTH; |
|
else if (name == "ADD_ATTACK_SPEED") |
|
return MainAbilityType.ADD_ATTACK_SPEED; |
|
else if (name == "ADD_ARMOR_COLLISION_TRAP") |
|
return MainAbilityType.ADD_ARMOR_COLLISION_TRAP; |
|
else if (name == "ADD_ARMOR_SHOT") |
|
return MainAbilityType.ADD_ARMOR_SHOT; |
|
else if (name == "ADD_HEAL") |
|
return MainAbilityType.ADD_HEAL; |
|
else if (name == "ADD_DROP_GOLD") |
|
return MainAbilityType.ADD_DROP_GOLD; |
|
else if (name == "ADD_DROP_ITEMS") |
|
return MainAbilityType.ADD_DROP_ITEMS; |
|
else if (name == "ADD_EQUIP") |
|
return MainAbilityType.ADD_EQUIP; |
|
|
|
CommonFunctions.myassert(false); |
|
return MainAbilityType.ADD_HEAL; |
|
} |
|
|
|
//----------------------------------------------------------- |
|
public int GetAbilityLvlUpByType(MainAbilityType type) |
|
{ |
|
if (m_abilities.ContainsKey(type)) |
|
{ |
|
MainAbilityInfo info = m_abilities[type]; |
|
return info.m_lvlUp; |
|
} |
|
else |
|
CommonFunctions.myassert(false, "WRONG ABILITY!"); |
|
|
|
return 0; |
|
} |
|
|
|
//----------------------------------------------------------- |
|
public float GetAbilityValueByType(MainAbilityType type) |
|
{ |
|
if (m_abilities.ContainsKey(type)) |
|
{ |
|
MainAbilityInfo info = m_abilities[type]; |
|
if (!info.m_isActive) |
|
return 0; |
|
|
|
return info.m_skillParam * info.m_lvlUp; |
|
} |
|
else |
|
CommonFunctions.myassert(false, "WRONG ABILITY!"); |
|
|
|
return 0f; |
|
} |
|
|
|
//----------------------------------------------------------- |
|
public void UpgradeByType(MainAbilityType type) |
|
{ |
|
if (m_abilities.ContainsKey(type)) |
|
{ |
|
m_abilities[type].m_lvlUp++; |
|
GlobalsVar.gUser.SetMainAbLvlUp(type.ToString(), m_abilities[type].m_lvlUp); |
|
} |
|
else |
|
CommonFunctions.myassert(false, "WRONG ABILITY!"); |
|
} |
|
|
|
//----------------------------------------------------------- |
|
public bool GetAbilityActiveByType(MainAbilityType type) |
|
{ |
|
if (m_abilities.ContainsKey(type)) |
|
{ |
|
MainAbilityInfo info = m_abilities[type]; |
|
return info.m_isActive; |
|
} |
|
else |
|
CommonFunctions.myassert(false, "WRONG ABILITY!"); |
|
|
|
return false; |
|
} |
|
|
|
//----------------------------------------------------------- |
|
public void SetAbilityActiveByType(MainAbilityType type) |
|
{ |
|
if (m_abilities.ContainsKey(type)) |
|
{ |
|
m_abilities[type].m_isActive = true; |
|
GlobalsVar.gUser.SetMainAbActive(type.ToString()); |
|
} |
|
else |
|
CommonFunctions.myassert(false, "WRONG ABILITY!"); |
|
} |
|
} |
|
} |
|
|
|
|