1
This commit is contained in:
@@ -1,86 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
public class BagManager
|
||||
{
|
||||
PlayerInfo Owner;
|
||||
public BagManager(PlayerInfo owner)
|
||||
{
|
||||
this.Owner = owner;
|
||||
}
|
||||
public void AddItem(int key, int value)
|
||||
{
|
||||
if (Owner == null) return;
|
||||
if (Owner.info.BagInfo.ContainsKey(key))
|
||||
{
|
||||
Owner.info.BagInfo[key] = Owner.info.BagInfo[key] + value;
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.info.BagInfo.Add(key, value);
|
||||
}
|
||||
|
||||
Owner.OnUpdateBagInfo?.Invoke();
|
||||
Owner.OnUpdateMainUI?.Invoke();
|
||||
}
|
||||
public void UserItem(int id, int num)
|
||||
{
|
||||
if (Owner == null) return;
|
||||
if (Owner.info.BagInfo.ContainsKey(id))
|
||||
{
|
||||
foreach (var item in Date.Instance.ItemDate)//测试使用道具
|
||||
{
|
||||
if (item.Id == id && item.type == ItemClass.User)
|
||||
{
|
||||
if(Remove(item,num))
|
||||
{
|
||||
Debug.Log("使用道具");
|
||||
item.UseItem(item);
|
||||
}
|
||||
}
|
||||
if(item.Id == id && item.type == ItemClass.Up)
|
||||
{
|
||||
Remove(item, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("道具缺失");
|
||||
return;
|
||||
}
|
||||
}
|
||||
private bool Remove(Item item,int num)
|
||||
{
|
||||
if (Owner.info.BagInfo[item.Id] < num)
|
||||
{
|
||||
Debug.LogFormat("UserItem [{0}] count Insufficient", item.ItemName);
|
||||
return false;
|
||||
}
|
||||
Owner.info.BagInfo[item.Id] = Owner.info.BagInfo[item.Id] - num;//背包减少
|
||||
|
||||
if (Owner.info.BagInfo[item.Id] <= 0)
|
||||
{
|
||||
Owner.info.BagInfo.Remove(item.Id);
|
||||
}
|
||||
|
||||
Owner.OnUpdateBagInfo?.Invoke();
|
||||
Owner.OnUpdateMainUI?.Invoke();
|
||||
|
||||
Owner.WriteBagInfo();
|
||||
|
||||
//保存数据
|
||||
//Debug.Log(Owner.info.BagValue[item.Id]);
|
||||
|
||||
SaveSystem.SaveDate(Owner.info.DatePath, Owner.info);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20a184ad6c4412540a4cd3c66711e074
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user