| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Newtonsoft.Json;
- /* 游戏道具管理者 */
- public class PropMgr {
- static PropMgr _ins = null;
- public static PropMgr ins {
- get {
- if (_ins == null) {
- _ins = new PropMgr();
- }
- return _ins;
- }
- }
- Hashtable propConfigs = new Hashtable();
- List<int> propConfigIds = new List<int>();
- PropMgr()
- {
- for (int i = 1; i <= 5; i++)
- {
- PropScaleAim propScaleAim = new PropScaleAim(10, i);
- CachePropConfig(propScaleAim.id, propScaleAim);
- }
- for (int i = 1; i <= 5; i++)
- {
- PropScaleShoot propScaleShoot = new PropScaleShoot(20, i);
- CachePropConfig(propScaleShoot.id, propScaleShoot);
- }
- }
- void CachePropConfig(int id, PropConfig propConfig)
- {
- propConfigs.Add(id, propConfig);
- propConfigIds.Add(id);
- }
- public PropConfig GetPropConfig(int id)
- {
- return (PropConfig) propConfigs[id];
- }
- public List<PropConfig> ListForShop()
- {
- List<PropConfig> list = new List<PropConfig>();
- foreach (int id in propConfigIds)
- {
- PropConfig propConfig = (PropConfig) propConfigs[id];
- if (propConfig.inShop) {
- list.Add(propConfig);
- }
- }
- return list;
- }
- public List<PropInfo> ListForBag()
- {
- List<PropInfo> list = LoginMgr.myUserInfo.bagList;
- if (CommonConfig.SpecialVersion1) list = GetDebugLocalBagList();
- foreach (var propInfo in list)
- {
- propInfo.config = (PropConfig) propConfigs[propInfo.id];
- }
- return list;
- }
- public List<PropInfo> ListForEquipped()
- {
- List<PropInfo> list = new List<PropInfo>();
- List<PropInfo> myProps = LoginMgr.myUserInfo.bagList;
- if (CommonConfig.SpecialVersion1) myProps = GetDebugLocalBagList();
- foreach (var propInfo in myProps)
- {
- if (propInfo.inuse) {
- propInfo.config = (PropConfig) propConfigs[propInfo.id];
- list.Add(propInfo);
- }
- }
- return list;
- }
- //商店购买接口
- public bool isSoldOut(PropConfig propConfig)
- {
- if (propConfig.type == 1 || propConfig.type == 2)
- {
- List<PropInfo> myProps = LoginMgr.myUserInfo.bagList;
- if (CommonConfig.SpecialVersion1) myProps = GetDebugLocalBagList();
- foreach (var myProp in myProps)
- {
- if (myProp.id == propConfig.id && myProp.count > 0) return true;
- }
- }
- return false;
- }
- public bool buyProp(PropConfig propConfig)
- {
- if (LoginMgr.myUserInfo.diamond >= propConfig.diamond) {
- LoginMgr.myUserInfo.diamond -= propConfig.diamond;
- PropInfo propInfo = new PropInfo();
- propInfo.id = propConfig.id;
- propInfo.count = 1;
- LoginMgr.myUserInfo.bagList.Add(propInfo);
- LoginMgr.myUserInfo.Save();
- return true;
- }
- return false;
- }
- public bool useProp(PropInfo propInfo)
- {
- if (!propInfo.inuse) {
- if (propInfo.config.type == 1 || propInfo.config.type == 2) {
- List<PropInfo> equippeds = ListForEquipped();
- foreach (var equipped in equippeds)
- {
- if (equipped.config.type == propInfo.config.type) {
- equipped.inuse = false;
- }
- }
- }
- }
- propInfo.inuse = !propInfo.inuse;
- if (CommonConfig.SpecialVersion1) {
- SaveDebugLocalBagList();
- return propInfo.inuse;
- }
- LoginMgr.myUserInfo.Save();
- return propInfo.inuse;
- }
- private List<PropInfo> _debugLocalBagList;
- private int _debugLocalBagList_uid = -1;
- private List<PropInfo> GetDebugLocalBagList() {
- if (_debugLocalBagList_uid != LoginMgr.myUserInfo.id) {
- _debugLocalBagList_uid = LoginMgr.myUserInfo.id;
- _debugLocalBagList = null;
- }
- if (_debugLocalBagList == null) {
- try {
- string str = PlayerPrefs.GetString("sv1_baglist," + LoginMgr.myUserInfo.id, null);
- _debugLocalBagList = JsonConvert.DeserializeObject<List<PropInfo>>(str);
- } catch (System.Exception) {}
- if (_debugLocalBagList == null) {
- _debugLocalBagList = new List<PropInfo>();
- for (int i = 2; i <= 5; i++) {
- PropInfo propInfo = new PropInfo();
- propInfo.id = 10 + i;
- propInfo.count = 1;
- _debugLocalBagList.Add(propInfo);
- if (propInfo.id == 12) {
- propInfo.inuse = true;
- }
- }
- for (int i = 2; i <= 5; i++) {
- PropInfo propInfo = new PropInfo();
- propInfo.id = 20 + i;
- propInfo.count = 1;
- _debugLocalBagList.Add(propInfo);
- if (propInfo.id == 25) {
- propInfo.inuse = true;
- }
- }
- }
- }
- return _debugLocalBagList;
- }
- private void SaveDebugLocalBagList() {
- if (_debugLocalBagList != null) {
- string str = JsonConvert.SerializeObject(_debugLocalBagList);
- PlayerPrefs.SetString("sv1_baglist," + LoginMgr.myUserInfo.id, str);
- }
- }
- }
- public class PropInfo {
- public int id = 0;
- public int count = 1;
- [JsonIgnore]
- public PropConfig config = null;
- public bool inuse = false;
- }
- public class PropConfig {
- public int id = 0;
- public int type = 0;
- public int iconID = 0;
- public string[] name = {null};
- public string[] detail = {null};
- public int difficulty = -1;
- public int diamond = 0;
- public bool inShop = true;
- }
- public class PropScaleAim : PropConfig {
- public int scaleValue = 0;
- public PropScaleAim(int baseID, int scaleValue)
- {
- this.scaleValue = scaleValue;
- if (this.scaleValue == 1) {
- this.inShop = false;
- }
- id = baseID + scaleValue;
- type = 1;
- iconID = 1000;
- name = new string[]{"101000", scaleValue.ToString()};
- detail = new string[]{"111000", scaleValue.ToString()};
- diamond = scaleValue * 20;
- }
- }
- public class PropScaleShoot : PropConfig {
- public int scaleValue = 0;
- public PropScaleShoot(int baseID, int scaleValue)
- {
- this.scaleValue = scaleValue;
- if (this.scaleValue == 1) {
- this.inShop = false;
- }
- id = baseID + scaleValue;
- type = 2;
- iconID = 1001;
- name = new string[]{"101001", scaleValue.ToString()};
- detail = new string[]{"111001", scaleValue.ToString()};
- diamond = scaleValue * 20;
- }
- }
|