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.
315 lines
7.0 KiB
315 lines
7.0 KiB
using System.Collections.Generic; |
|
using System.Linq; |
|
using UnityEngine; |
|
|
|
namespace Equip |
|
{ |
|
public enum WeaponType |
|
{ |
|
Gun, |
|
Auto, |
|
Shotgun, |
|
Rocket |
|
} |
|
|
|
public class EquipItem |
|
{ |
|
public string Name; |
|
public string Icon; |
|
public string Rarity; |
|
public float AddHp; |
|
public float AddDamage; |
|
public float AddSpeed; |
|
public float DamageMult; |
|
public float AddCrit; |
|
public WeaponType WeaponType; |
|
} |
|
|
|
public enum EquipType |
|
{ |
|
Weapon, |
|
Armor, |
|
Implant |
|
} |
|
|
|
public class EquipSettings { |
|
|
|
private static readonly List<EquipItem> Weapons = new List<EquipItem> |
|
{ |
|
new EquipItem |
|
{ |
|
Name = "Gun", |
|
DamageMult = 1, |
|
AddDamage = 5, |
|
AddSpeed = 1f, |
|
Icon = "ICN_Pistol_01", |
|
Rarity = "green", |
|
WeaponType = WeaponType.Gun |
|
}, |
|
new EquipItem |
|
{ |
|
Name = "Auto", |
|
DamageMult = 1f, |
|
AddDamage = 10, |
|
AddSpeed = 1f, |
|
Icon = "ICN_AssaultRifle_01", |
|
Rarity = "blue", |
|
WeaponType = WeaponType.Auto |
|
}, |
|
new EquipItem |
|
{ |
|
Name = "Shotgun", |
|
DamageMult = 1f, |
|
AddDamage = 40, |
|
AddSpeed = 1.5f, |
|
Icon = "ICN_Shotgun_01", |
|
Rarity = "blue", |
|
WeaponType = WeaponType.Shotgun |
|
}, |
|
new EquipItem |
|
{ |
|
Name = "Bazooka", |
|
DamageMult = 1, |
|
AddDamage = 100, |
|
AddSpeed = 2.2f, |
|
Icon = "ICN_Bazooka_01", |
|
Rarity = "violet", |
|
WeaponType = WeaponType.Rocket |
|
} |
|
}; |
|
|
|
private static readonly List<EquipItem> Armor = new List<EquipItem> |
|
{ |
|
new EquipItem |
|
{ |
|
Name = "Leather", |
|
AddHp = 10f, |
|
Icon = "ICN_Armor_01", |
|
Rarity = "green" |
|
}, |
|
new EquipItem |
|
{ |
|
Name = "Bulletproof", |
|
AddHp = 30f, |
|
Icon = "ICN_Armor_02", |
|
Rarity = "blue" |
|
}, |
|
new EquipItem |
|
{ |
|
Name = "Exo", |
|
AddHp = 50f, |
|
Icon = "ICN_Armor_03", |
|
Rarity = "blue" |
|
}, |
|
new EquipItem |
|
{ |
|
Name = "Tactical", |
|
AddHp = 100f, |
|
Icon = "ICN_Armor_04", |
|
Rarity = "violet" |
|
} |
|
}; |
|
|
|
private static readonly List<EquipItem> Implant = new List<EquipItem> |
|
{ |
|
new EquipItem |
|
{ |
|
Name = "Bull Heart", |
|
AddCrit = 0.05f, |
|
Icon = "ICN_Implant_01", |
|
Rarity = "green" |
|
}, |
|
new EquipItem |
|
{ |
|
Name = "Hawk Eye", |
|
AddCrit = 0.1f, |
|
Icon = "ICN_Implant_02", |
|
Rarity = "blue" |
|
}, |
|
new EquipItem |
|
{ |
|
Name = "Inner Fire", |
|
AddCrit = 0.2f, |
|
Icon = "ICN_Implant_03", |
|
Rarity = "blue" |
|
}, |
|
new EquipItem |
|
{ |
|
Name = "Berserk", |
|
AddCrit = 0.4f, |
|
Icon = "ICN_Implant_04", |
|
Rarity = "violet" |
|
} |
|
}; |
|
|
|
public static List<int> EquipedItems = new List<int> |
|
{ |
|
0, |
|
0, |
|
0 |
|
}; |
|
|
|
private static Dictionary<EquipType, List<int>> UnlockedItems = new Dictionary<EquipType, List<int>> |
|
{ |
|
{ |
|
EquipType.Weapon, |
|
new List<int> |
|
{ |
|
0 |
|
} |
|
}, |
|
{ |
|
EquipType.Armor, |
|
new List<int> |
|
{ |
|
0 |
|
} |
|
}, |
|
{ |
|
EquipType.Implant, |
|
new List<int> |
|
{ |
|
0 |
|
} |
|
} |
|
}; |
|
|
|
public static void Init() |
|
{ |
|
InitEquipedItems(); |
|
InitUnlockedItems(); |
|
} |
|
|
|
private static void InitEquipedItems() |
|
{ |
|
string equipedStr = GlobalsVar.gUser.GetFlagByName("equiped_items"); |
|
if (equipedStr != "") |
|
{ |
|
string[] arr = equipedStr.Split('_'); |
|
if (arr.Length != 3) |
|
{ |
|
CommonFunctions.myassert(false); |
|
return; |
|
} |
|
|
|
for (int i = 0; i < arr.Length; ++i) |
|
EquipedItems[i] = System.Convert.ToInt32(arr[i]); |
|
} |
|
} |
|
|
|
private static void InitUnlockedItems() |
|
{ |
|
string weaponStr = GlobalsVar.gUser.GetFlagByName("unlocked_weapons"); |
|
if (weaponStr != "") |
|
{ |
|
string[] weaponArr = weaponStr.Split('_'); |
|
List<int> weapons = new List<int>(); |
|
for (int i = 0; i < weaponArr.Length; ++i) |
|
weapons.Add(System.Convert.ToInt32(weaponArr[i])); |
|
|
|
UnlockedItems[EquipType.Weapon] = weapons; |
|
} |
|
|
|
string armorStr = GlobalsVar.gUser.GetFlagByName("unlocked_armor"); |
|
if (armorStr != "") |
|
{ |
|
string[] armorArr = armorStr.Split('_'); |
|
List<int> armors = new List<int>(); |
|
for (int i = 0; i < armorArr.Length; ++i) |
|
armors.Add(System.Convert.ToInt32(armorArr[i])); |
|
|
|
UnlockedItems[EquipType.Armor] = armors; |
|
} |
|
|
|
string implantStr = GlobalsVar.gUser.GetFlagByName("unlocked_implant"); |
|
if (implantStr != "") |
|
{ |
|
string[] implantArr = implantStr.Split('_'); |
|
List<int> implants = new List<int>(); |
|
for (int i = 0; i < implantArr.Length; ++i) |
|
implants.Add(System.Convert.ToInt32(implantArr[i])); |
|
|
|
UnlockedItems[EquipType.Implant] = implants; |
|
} |
|
} |
|
|
|
public static string GetEquipedItemsSerializedStr() |
|
{ |
|
string serStr = ""; |
|
for (int i = 0; i < EquipedItems.Count; ++i) |
|
{ |
|
serStr += EquipedItems[i]; |
|
if (i < EquipedItems.Count - 1) |
|
serStr += "_"; |
|
} |
|
|
|
return serStr; |
|
} |
|
|
|
public static string GetUnlockedItemsSerializedStr(EquipType type) |
|
{ |
|
if (UnlockedItems.ContainsKey(type)) |
|
{ |
|
string serStr = ""; |
|
for (int i = 0; i < UnlockedItems[type].Count; ++i) |
|
{ |
|
serStr += UnlockedItems[type][i]; |
|
if (i < UnlockedItems[type].Count - 1) |
|
serStr += "_"; |
|
} |
|
|
|
return serStr; |
|
} |
|
else |
|
CommonFunctions.myassert(false); |
|
|
|
return ""; |
|
} |
|
|
|
public static EquipItem UnlockRandomItem() |
|
{ |
|
var randomTypeRange = new List<int> {0, 1, 2}; |
|
for (int i = 0; i < 3; i++) |
|
{ |
|
var randomType = randomTypeRange[Random.Range(0, randomTypeRange.Count)]; |
|
var type = (EquipType) randomType; |
|
var collection = randomType == 0 ? Weapons : randomType == 1 ? Armor : Implant; |
|
if (collection.Count == UnlockedItems[type].Count) |
|
continue; |
|
|
|
var items = new List<int>(); |
|
for (var a = 0; a < collection.Count; a++) |
|
items.Add(a); |
|
|
|
items = items.Except(UnlockedItems[type]).ToList(); |
|
var index = items[Random.Range(0, items.Count)]; |
|
UnlockedItems[type].Add(index); |
|
|
|
GlobalsVar.gUser.SaveUnlockedItems(); |
|
return collection[index]; |
|
} |
|
|
|
return null; |
|
} |
|
|
|
public static bool ItemUnlocked(int index, EquipType type) |
|
{ |
|
return UnlockedItems[type].Contains(index); |
|
} |
|
|
|
public static List<EquipItem> GetItemsByType(EquipType type) |
|
{ |
|
return type == EquipType.Weapon ? Weapons : type == EquipType.Armor ? Armor : Implant; |
|
} |
|
|
|
public static List<EquipItem> GetItems() |
|
{ |
|
return new List<EquipItem> |
|
{ |
|
Weapons[EquipedItems[0]], |
|
Armor[EquipedItems[1]], |
|
Implant[EquipedItems[2]] |
|
}; |
|
} |
|
} |
|
}
|
|
|