| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Newtonsoft.Json;
- /* 设备管理者(弓和箭的种类) */
- public class DeviceMgr
- {
- static DeviceMgr _ins = null;
- public static DeviceMgr ins {
- get {
- if (_ins == null) {
- _ins = new DeviceMgr();
- }
- return _ins;
- }
- }
- Hashtable deviceConfigs = new Hashtable();
- DeviceMgr()
- {
- CacheDeviceConfig<DeviceBow1000>();
- CacheDeviceConfig<DeviceBow1001>();
- CacheDeviceConfig<DeviceArrow2000>();
- //用户数据初始化
- List<DeviceInfo> deviceInfos = LoginMgr.myUserInfo.deviceList;
- if (deviceInfos.Count == 0) {
- // 加入初始设备
- // int[] ids = {1000, 1001, 2000};
- int[] ids = {1000, 2000};
- foreach (var id in ids) {
- DeviceInfo deviceInfo = new DeviceInfo();
- deviceInfo.id = id;
- if (id == 1000 || id == 2000) deviceInfo.inuse = true;
- deviceInfos.Add(deviceInfo);
- }
- LoginMgr.myUserInfo.Save();
- }
- }
- void CacheDeviceConfig<T>() where T : DeviceConfig
- {
- DeviceConfig deviceConfig = System.Activator.CreateInstance<T>();
- deviceConfigs.Add(deviceConfig.id, deviceConfig);
- }
- void CacheDeviceConfig(int id, DeviceConfig deviceConfig)
- {
- deviceConfigs.Add(id, deviceConfig);
- }
- public PropConfig GetDeviceConfig(int id)
- {
- return (PropConfig) deviceConfigs[id];
- }
- public List<DeviceInfo> GetMyDeviceList()
- {
- List<DeviceInfo> list = LoginMgr.myUserInfo.deviceList;
- foreach (var deviceInfo in list)
- {
- deviceInfo.config = (DeviceConfig) deviceConfigs[deviceInfo.id];
- }
- return list;
- }
- public void UseDevice(DeviceInfo deviceInfo)
- {
- List<DeviceInfo> myDevices = GetMyDeviceList();
- if (deviceInfo.config.type == 1 || deviceInfo.config.type == 2)
- {
- foreach (var myDevice in myDevices)
- {
- if (myDevice.config.type == deviceInfo.config.type)
- {
- myDevice.inuse = false;
- }
- }
- deviceInfo.inuse = true;
- LoginMgr.myUserInfo.Save();
- }
- }
- public (DeviceInfo, DeviceInfo) GetCurrentBowArrowInfo()
- {
- List<DeviceInfo> myDevices = GetMyDeviceList();
- DeviceInfo bow = null;
- DeviceInfo arrow = null;
- foreach (var myDevice in myDevices)
- {
- if (myDevice.config.type == 1 && myDevice.inuse)
- {
- bow = myDevice;
- } else if (myDevice.config.type == 2 && myDevice.inuse) {
- arrow = myDevice;
- }
- }
- return (bow, arrow);
- }
- public int GetCurrentBowPound()
- {
- List<DeviceInfo> myDevices = GetMyDeviceList();
- foreach (var myDevice in myDevices)
- {
- if (myDevice.config.type == 1 && myDevice.inuse)
- {
- return ((DeviceBowConfig) myDevice.config).pound;
- }
- }
- return 0;
- }
- }
- public class DeviceInfo
- {
- public int id = 0;
- public bool inuse = false;
- [JsonIgnore]
- public DeviceConfig config = null;
- }
- public class DeviceConfig
- {
- public int id = 0;
- public int name = 0;
- public int detail = 0;
- public int difficulty = 0;
- public int model = 0;
- public int type = 0;
- }
- public class DeviceBowConfig : DeviceConfig {
- public int pound = 0;
- }
- public class DeviceBow1000 : DeviceBowConfig {
- public DeviceBow1000()
- {
- id = 1000;
- name = 201000;
- detail = 211000;
- difficulty = 3;
- model = 1;
- type = 1;
- pound = 18;
- }
- }
- public class DeviceBow1001 : DeviceBowConfig {
- public DeviceBow1001()
- {
- id = 1001;
- name = 201001;
- detail = 211001;
- difficulty = 5;
- model = 1;
- type = 1;
- pound = 25;
- }
- }
- public class DeviceArrow2000 : DeviceConfig {
- public DeviceArrow2000()
- {
- id = 2000;
- name = 201002;
- detail = 211002;
- difficulty = 3;
- model = 2;
- type = 2;
- }
- }
|