1
This commit is contained in:
154
unity/Assets/Script/GameObject/Player/PlayerInfo.cs
Normal file
154
unity/Assets/Script/GameObject/Player/PlayerInfo.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using Managers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerInfo : Singleton<PlayerInfo>
|
||||
{
|
||||
public CharInfo info;
|
||||
|
||||
public Action OnUpdateBagInfo;
|
||||
public Action OnUpdateMainUI;
|
||||
public Action OnUpdateLevel;
|
||||
|
||||
public Action<LotteryType, float> OnUpdateAttrbute;
|
||||
|
||||
public Managers.BagManager BagMgr;
|
||||
|
||||
public void Init(CharInfo date)
|
||||
{
|
||||
|
||||
info = date;
|
||||
info.playerName = date.playerName;
|
||||
info.Level = date.Level;
|
||||
info.exp = date.exp;
|
||||
|
||||
info.maxHp = date.maxHp;
|
||||
info.attack = date.attack;
|
||||
|
||||
info.testAttack = date.testAttack;
|
||||
info.currentHp = date.currentHp;
|
||||
info.currentMap = date.currentMap;
|
||||
|
||||
info.BagInfo = new Dictionary<int, int>();
|
||||
info.UpInfo = new Dictionary<int, bool>();
|
||||
|
||||
for (int i = 0; i < date.BagKey.Count; i++)
|
||||
{
|
||||
info.BagInfo.Add(date.BagKey[i], date.BagValue[i]);
|
||||
}
|
||||
for (int i = 0; i < date.UpKey.Count; i++)
|
||||
{
|
||||
info.UpInfo.Add(date.UpKey[i], date.UpValue[i]);
|
||||
}
|
||||
|
||||
//初始化管理器
|
||||
BagMgr = new Managers.BagManager(this);
|
||||
|
||||
Debug.Log("数据读取完毕");
|
||||
}
|
||||
public void Resrt()
|
||||
{
|
||||
info.currentHp = info.maxHp; ;
|
||||
info.testAttack = info.attack;
|
||||
if(!info.BagInfo.ContainsKey(1))
|
||||
{
|
||||
info.BagInfo.Add(1,4);
|
||||
}
|
||||
else
|
||||
{
|
||||
info.BagInfo[1] = 4;
|
||||
}
|
||||
|
||||
WriteBagInfo();
|
||||
}
|
||||
|
||||
public void KeepData(float max, float current, float attack)
|
||||
{
|
||||
info.maxHp = max;
|
||||
info.currentHp = current;
|
||||
info.testAttack = attack;
|
||||
}
|
||||
public Sprite GetSprite(string path)
|
||||
{
|
||||
return Resloader.Load<Sprite>(path);
|
||||
}
|
||||
|
||||
#region 属性更改
|
||||
public void AddHp(int num)
|
||||
{
|
||||
OnUpdateAttrbute?.Invoke(LotteryType.Hp, num);
|
||||
}
|
||||
public void AddMp(int num)
|
||||
{
|
||||
OnUpdateAttrbute?.Invoke(LotteryType.Mp, num);
|
||||
}
|
||||
public void AddAttack(int num)
|
||||
{
|
||||
OnUpdateAttrbute?.Invoke(LotteryType.Attack, num);
|
||||
}
|
||||
public void AddUpHp(int num)
|
||||
{
|
||||
OnUpdateAttrbute?.Invoke(LotteryType.UpHp, num);
|
||||
}
|
||||
public void AddUpMaxHp(int num)
|
||||
{
|
||||
OnUpdateAttrbute?.Invoke(LotteryType.UpMaxHp, num);
|
||||
}
|
||||
public void AddUpAttack(int num)
|
||||
{
|
||||
OnUpdateAttrbute?.Invoke(LotteryType.UpAttack, num);
|
||||
}
|
||||
#endregion
|
||||
#region 升级
|
||||
public void LevelUp()
|
||||
{
|
||||
int need = NeedExp();
|
||||
if (need < info.exp)
|
||||
{
|
||||
info.exp -= need;
|
||||
|
||||
info.Level++;
|
||||
LevelUp();
|
||||
|
||||
SaveSystem.SaveDate(info.DatePath, info);
|
||||
}
|
||||
}
|
||||
public int NeedExp()
|
||||
{
|
||||
int needExp;
|
||||
return needExp = info.Level * (1000);
|
||||
}
|
||||
public void ItemLevel(LevelUpDefine item)
|
||||
{
|
||||
switch (item.type)
|
||||
{
|
||||
case LotteryType.UpMaxHp:
|
||||
AddUpMaxHp(item.value);
|
||||
break;
|
||||
case LotteryType.UpAttack:
|
||||
AddUpAttack(item.value);
|
||||
break;
|
||||
case LotteryType.UpHp:
|
||||
AddUpHp(item.value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
//重写数据
|
||||
public void WriteBagInfo()
|
||||
{
|
||||
info.BagKey.Clear();
|
||||
info.BagValue.Clear();
|
||||
foreach (var data in info.BagInfo)
|
||||
{
|
||||
info.BagKey.Add(data.Key);
|
||||
info.BagValue.Add(data.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user