2025-05-19 11:49:19 +08:00

68 lines
1.6 KiB
C#

using QFramework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XMLTool;
public class PlayerController : MonoSingleton<PlayerController>
{
private PlayerController() { }
public class HasDeviceData
{
public Device device;
public int count;
}
public Dictionary<string, HasDeviceData> hasDevicesDict = new Dictionary<string, HasDeviceData>();
public int DropDevice(string key, int count = 1)
{
if (hasDevicesDict.ContainsKey(key))
{
var dev = hasDevicesDict[key];
dev.count -= count;
if (dev.count <= 0)
{
hasDevicesDict.Remove(key);
return 0;
}
return dev.count;
}
return -1;
}
public void PickDevice(string key, int count = 1)
{
Device device = null;
if (hasDevicesDict.ContainsKey(key))
{
device = hasDevicesDict[key].device;
hasDevicesDict[key].count += count;
}
else
{
device = DeviceController.Instance.GetDevice(key);
hasDevicesDict.Add(key, new HasDeviceData() { count = count, device = device });
}
TypeEventSystem.Global.Send<OnPickDevice>(new OnPickDevice() { device = device, count = count });
}
public HasDeviceData HasDevice(string key)
{
if (hasDevicesDict.ContainsKey(key))
{
var dev = hasDevicesDict[key];
if (dev.count > 0)
{
return dev;
}
}
return null;
}
}