993 lines
19 KiB
C#
993 lines
19 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2021-03-26
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "PetProxy" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using CodeStage.AntiCheat.ObscuredTypes;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public class PetProxy : F.GameProxy
|
|||
|
{
|
|||
|
public class PetInfo
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public readonly ItemPet item;
|
|||
|
|
|||
|
public readonly PetSkillInfo mainSkill;
|
|||
|
public readonly List<PetSkillInfo> skills = new List<PetSkillInfo>();
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
ItemPetLevel currLevelItem => ItemProxy.Instance.GetStaticItem<ItemPetLevel>(grade);
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// id
|
|||
|
/// </summary>
|
|||
|
public int id => item.id;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public string name
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
var saveName = ArchiveProxy.Instance.GetString(this.id);
|
|||
|
if (!string.IsNullOrEmpty(saveName))
|
|||
|
return saveName;
|
|||
|
return item.name;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
ArchiveProxy.Instance.SetString(this.id, value);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public string[] icon
|
|||
|
{
|
|||
|
get { return item.icon; }
|
|||
|
}
|
|||
|
|
|||
|
private ObscuredInt _friend = -1;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int friend
|
|||
|
{
|
|||
|
get => _friend;
|
|||
|
private set { _friend = value; }
|
|||
|
}
|
|||
|
|
|||
|
private ObscuredInt _friendMax = 0;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int friendMax
|
|||
|
{
|
|||
|
get { return _friendMax; }
|
|||
|
private set { _friendMax = value; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int friendId
|
|||
|
{
|
|||
|
get { return item.active[0]; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="value"></param>
|
|||
|
public bool AddFriend(int value)
|
|||
|
{
|
|||
|
if (isUnlock)
|
|||
|
{
|
|||
|
friend += value;
|
|||
|
bool result = isFriend;
|
|||
|
SaveLocal();
|
|||
|
return result;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 已结交
|
|||
|
/// </summary>
|
|||
|
public bool isFriend
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (grade > 0)
|
|||
|
return true;
|
|||
|
if (isUnlock && friend >= friendMax)
|
|||
|
{
|
|||
|
grade = 1;
|
|||
|
MissionProxy.Instance.OnEvent(MissionProxy.解锁宠物数量);
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public bool isUnlock
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (this.friend >= 0)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var mission = MissionProxy.Instance.GetMission(item.unlock);
|
|||
|
if (mission != null && mission.isCompleted)
|
|||
|
{
|
|||
|
this.friend = 0;
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public string unlockText
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
var mission = MissionProxy.Instance.GetMission(item.unlock);
|
|||
|
if (mission != null)
|
|||
|
{
|
|||
|
return mission.description;
|
|||
|
}
|
|||
|
return "";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public ItemAccess access
|
|||
|
{
|
|||
|
get { return ItemProxy.Instance.GetStaticItem<ItemAccess>(item.access); }
|
|||
|
}
|
|||
|
|
|||
|
private ObscuredInt _grade = 0;
|
|||
|
/// <summary>
|
|||
|
/// 等级
|
|||
|
/// </summary>
|
|||
|
public int grade
|
|||
|
{
|
|||
|
get { return _grade; }
|
|||
|
private set
|
|||
|
{
|
|||
|
if (value <= gradeMax && value != grade)
|
|||
|
{
|
|||
|
_grade = value;
|
|||
|
|
|||
|
attributes.Clear();
|
|||
|
var sources = item.attributes;
|
|||
|
if (sources != null)
|
|||
|
for (int i = 0; i < sources.Length; i++)
|
|||
|
{
|
|||
|
attributes.Add(new CombatAttribute
|
|||
|
{
|
|||
|
id = (CombatAttributeId)sources[i][0],
|
|||
|
value = sources[i][1] + value * sources[i][2],
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 等级上限
|
|||
|
/// </summary>
|
|||
|
public int gradeMax
|
|||
|
{
|
|||
|
get;
|
|||
|
private set;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public bool isMaxGrade => grade >= gradeMax;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="value"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool AddGrade(int value)
|
|||
|
{
|
|||
|
bool result = true;
|
|||
|
int tmpGrade = this.grade + value;
|
|||
|
int tmpGradeMax = this.gradeMax;
|
|||
|
|
|||
|
if (tmpGrade > tmpGradeMax)
|
|||
|
{
|
|||
|
tmpGrade = tmpGradeMax;
|
|||
|
}
|
|||
|
this.grade = tmpGrade;
|
|||
|
|
|||
|
SaveLocal();
|
|||
|
MissionProxy.Instance.OnEvent(MissionProxy.宠物升级次数);
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private ObscuredInt _exp = 0;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int exp
|
|||
|
{
|
|||
|
get { return _exp; }
|
|||
|
private set { _exp = value; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int expMax
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
var levelItem = this.currLevelItem;
|
|||
|
return levelItem != null ? levelItem.exp : 1;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="value"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool AddExp(int value)
|
|||
|
{
|
|||
|
bool result = false;
|
|||
|
int tmpExp = this.exp + value;
|
|||
|
int tmpExpMax = this.expMax;
|
|||
|
int tmpLevel = this.grade;
|
|||
|
|
|||
|
if (tmpExp >= tmpExpMax)
|
|||
|
{
|
|||
|
tmpExp -= tmpExpMax;
|
|||
|
tmpLevel += 1;
|
|||
|
result = true;
|
|||
|
}
|
|||
|
this.exp = tmpExp;
|
|||
|
this.grade = tmpLevel;
|
|||
|
|
|||
|
SaveLocal();
|
|||
|
MissionProxy.Instance.OnEvent(MissionProxy.宠物升级次数);
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 伤害
|
|||
|
/// </summary>
|
|||
|
public int damage
|
|||
|
{
|
|||
|
get;
|
|||
|
set;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 速度
|
|||
|
/// </summary>
|
|||
|
public float speed
|
|||
|
{
|
|||
|
get { return item.speed * 0.001f; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int splash => item.splash;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int bullet => item.bullet;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public float bulletDamage
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (grade > 0)
|
|||
|
return currLevelItem.damage * 0.01f;
|
|||
|
return item.damage * 0.01f;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public float bulletSpeed
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (grade > 0)
|
|||
|
return currLevelItem.bulletSpeed * 0.001f;
|
|||
|
return item.bulletSpeed * 0.001f;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int bulletNumber
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (grade > 0)
|
|||
|
return currLevelItem.bulletNumber;
|
|||
|
return item.bulletNumber;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int bulletLayer
|
|||
|
{
|
|||
|
get { return item.bulletLayer; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int combatValue
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
int result = item.combatValue;
|
|||
|
int tmpGrade = this.grade;
|
|||
|
if (tmpGrade > 0)
|
|||
|
{
|
|||
|
var levelItem = this.currLevelItem;
|
|||
|
if (levelItem != null)
|
|||
|
result += levelItem.combatValue;
|
|||
|
|
|||
|
for (int i = 0; i < attributes.Count; i++)
|
|||
|
{
|
|||
|
var attr = attributes[i];
|
|||
|
result += attr.combatValue;
|
|||
|
}
|
|||
|
}
|
|||
|
for (int i = 0; i < skills.Count; i++)
|
|||
|
{
|
|||
|
if (skills[i] != null && tmpGrade >= i * 10)
|
|||
|
result += skills[i].combatValue;
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public readonly List<CombatAttribute> attributes = new List<CombatAttribute>();
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 出战中
|
|||
|
/// </summary>
|
|||
|
public bool isBattling
|
|||
|
{
|
|||
|
get { return this == PetProxy.Instance.battlePet; }
|
|||
|
set
|
|||
|
{
|
|||
|
PetProxy.Instance.battlePet = value ? this : null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public PetInfo(ItemPet petItem)
|
|||
|
{
|
|||
|
this.item = petItem;
|
|||
|
friendMax = petItem.active[1];
|
|||
|
gradeMax = ItemProxy.Instance.GetStaticItems<ItemPetLevel>().Count;
|
|||
|
if (petItem.mainSkills != null)
|
|||
|
mainSkill = new PetSkillInfo(ItemProxy.Instance.GetStaticItem<ItemPetSkill>(petItem.mainSkills[0]));
|
|||
|
|
|||
|
for (int i = 0; i < petItem.skills.Length; i++)
|
|||
|
{
|
|||
|
var petSkillItem = ItemProxy.Instance.GetStaticItem<ItemPetSkill>(petItem.skills[i]);
|
|||
|
skills.Add(new PetSkillInfo(petSkillItem));
|
|||
|
}
|
|||
|
|
|||
|
LoadLocal();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="level"></param>
|
|||
|
/// <param name="exp"></param>
|
|||
|
public void Set(int level, int exp)
|
|||
|
{
|
|||
|
this.grade = level;
|
|||
|
this.exp = exp;
|
|||
|
MissionProxy.Instance.OnEvent(MissionProxy.解锁宠物数量);
|
|||
|
SaveLocal();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void Reset()
|
|||
|
{
|
|||
|
grade = 0;
|
|||
|
exp = 0;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public bool Active()
|
|||
|
{
|
|||
|
return AddFriend(friendMax);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public int Upgrade()
|
|||
|
{
|
|||
|
if (grade > 0 && grade < gradeMax)
|
|||
|
{
|
|||
|
var up = AddExp(100);
|
|||
|
if (up)
|
|||
|
{
|
|||
|
Instance.UpdateAttributes(true);
|
|||
|
}
|
|||
|
return up ? 2 : 1;
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
public IList<PetSkillInfo> CheckSkill()
|
|||
|
{
|
|||
|
var tmpGrade = this.grade;
|
|||
|
for (int i = 0; i < skills.Count; i++)
|
|||
|
{
|
|||
|
skills[i].grade = tmpGrade < i * 10 ? i * 10 : 0;
|
|||
|
}
|
|||
|
return skills;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public bool CheckUpgrade()
|
|||
|
{
|
|||
|
if (this.isFriend)
|
|||
|
{
|
|||
|
var costs = CalcUpgradeCost();
|
|||
|
return MoneyProxy.Instance.CheckMoney(costs);
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
static readonly Item.ItemInfo[] _UpgradeCost = new Item.ItemInfo[0];
|
|||
|
public IList<Item.ItemInfo> CalcUpgradeCost()
|
|||
|
{
|
|||
|
//_UpgradeCost[0].Set(20, grade / 10 + 1);
|
|||
|
//_UpgradeCost[1].Set(1, grade * 100);
|
|||
|
return _UpgradeCost;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public Item.ItemInfo recastCostLow
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
var petConst = ItemProxy.Instance.GetStaticItem<ItemPetConst>(1);
|
|||
|
var cost = petConst.recastCostInfo1;
|
|||
|
cost.count = item.skills.Length;
|
|||
|
return cost;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public Item.ItemInfo recastCostHigh
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
var petConst = ItemProxy.Instance.GetStaticItem<ItemPetConst>(1);
|
|||
|
var cost = petConst.recastCostInfo2;
|
|||
|
cost.count = item.skills.Length;
|
|||
|
return cost;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public bool CheckRecast()
|
|||
|
{
|
|||
|
return grade >= Mathf.Min(30, (skills.Count - 1) * 10);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void ApplyRecast()
|
|||
|
{
|
|||
|
//防止错误
|
|||
|
if (_RecastedPetSkills[0] == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
skills.Clear();
|
|||
|
for (int i = 0; i < 8; i++)
|
|||
|
{
|
|||
|
if (_RecastedPetSkills[i] != null)
|
|||
|
{
|
|||
|
skills.Add(_RecastedPetSkills[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
SaveLocal();
|
|||
|
ResetRecast();
|
|||
|
Instance.UpdateAttributes(true);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void ResetRecast()
|
|||
|
{
|
|||
|
for (int i = 0; i < 8; i++)
|
|||
|
{
|
|||
|
_RecastedPetSkills[i] = null;
|
|||
|
}
|
|||
|
//int skillCount = skills.Count;
|
|||
|
//for (int i = 0; i < skillCount; i++)
|
|||
|
//{
|
|||
|
// _RecastedPetSkills[i] = skills[i];
|
|||
|
//}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public IList<PetSkillInfo> recastSkills
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_RecastedPetSkills[0] == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return _RecastedPetSkills;
|
|||
|
}
|
|||
|
}
|
|||
|
static readonly PetSkillInfo[] _RecastedPetSkills = new PetSkillInfo[8];
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="lockFilter"></param>
|
|||
|
public PetSkillInfo[] RecastSkills(bool high, bool[] lockFilter)
|
|||
|
{
|
|||
|
int skillCount = skills.Count;
|
|||
|
for (int i = 0; i < skillCount; i++)
|
|||
|
{
|
|||
|
if (_RecastedPetSkills[i] == null)
|
|||
|
{
|
|||
|
_RecastedPetSkills[i] = skills[i];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
for (int i = 0; i < 8; i++)
|
|||
|
{
|
|||
|
if (!lockFilter[i])
|
|||
|
_RecastedPetSkills[i] = null;
|
|||
|
}
|
|||
|
|
|||
|
for (int i = 0; i < skillCount; i++)
|
|||
|
{
|
|||
|
if (_RecastedPetSkills[i] == null)
|
|||
|
{
|
|||
|
var rndSkill = GetRandomSkill(high, i);
|
|||
|
_RecastedPetSkills[i] = rndSkill;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
MissionProxy.Instance.OnEvent(MissionProxy.宠物技能洗练);
|
|||
|
return _RecastedPetSkills;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="high"></param>
|
|||
|
/// <param name="max"></param>
|
|||
|
/// <returns></returns>
|
|||
|
PetSkillInfo GetRandomSkill(bool high, int index)
|
|||
|
{
|
|||
|
var petConst = ItemProxy.Instance.GetStaticItem<ItemPetConst>(1);
|
|||
|
var skillPool = high ? petConst.skillPool2 : petConst.skillPool1;
|
|||
|
if (skillPool.Length <= index)
|
|||
|
return null;
|
|||
|
|
|||
|
int resultId = 0;
|
|||
|
int loop = 0;
|
|||
|
do
|
|||
|
{
|
|||
|
loop++;
|
|||
|
resultId = 0;
|
|||
|
int skillId = GlobalUtils.GetRandom(skillPool);
|
|||
|
for (int i = 0; i < 8; i++)
|
|||
|
{
|
|||
|
if (_RecastedPetSkills[i] != null && _RecastedPetSkills[i].id == skillId)
|
|||
|
{
|
|||
|
resultId = -1;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (resultId == 0)
|
|||
|
{
|
|||
|
resultId = skillId;
|
|||
|
}
|
|||
|
} while (resultId < 0 && loop < 1000);
|
|||
|
|
|||
|
var petSkillItem = ItemProxy.Instance.GetStaticItem<ItemPetSkill>(resultId);
|
|||
|
return new PetSkillInfo(petSkillItem);
|
|||
|
}
|
|||
|
|
|||
|
public int GetAttributes(List<CombatAttribute> results)
|
|||
|
{
|
|||
|
if (grade > 0)
|
|||
|
{
|
|||
|
for (int i = 0; i < attributes.Count; i++)
|
|||
|
{
|
|||
|
var attr = attributes[i];
|
|||
|
results.Add(attr);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return this.combatValue;
|
|||
|
}
|
|||
|
|
|||
|
void SaveLocal()
|
|||
|
{
|
|||
|
var dataList = ArchiveProxy.Instance.GetIntList(this.id);
|
|||
|
if (dataList != null)
|
|||
|
{
|
|||
|
dataList.Clear();
|
|||
|
|
|||
|
dataList.Add(friend);
|
|||
|
dataList.Add(grade);
|
|||
|
dataList.Add(exp);
|
|||
|
|
|||
|
dataList.Add(skills.Count);
|
|||
|
for (int i = 0; i < skills.Count; i++)
|
|||
|
{
|
|||
|
dataList.Add(skills[i].id);
|
|||
|
}
|
|||
|
|
|||
|
ArchiveProxy.Instance.SetIntList(this.id, dataList);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void LoadLocal()
|
|||
|
{
|
|||
|
var dataList = ArchiveProxy.Instance.GetIntList(this.id);
|
|||
|
if (dataList != null && dataList.Count > 0)
|
|||
|
{
|
|||
|
int index = 0;
|
|||
|
friend = dataList[index++];
|
|||
|
grade = dataList[index++];
|
|||
|
exp = dataList[index++];
|
|||
|
|
|||
|
skills.Clear();
|
|||
|
int skillCount = dataList.SafeGet(index++);
|
|||
|
for (int i = 0; i < skillCount; i++)
|
|||
|
{
|
|||
|
var skillItem = ItemProxy.Instance.GetStaticItem<ItemPetSkill>(dataList.SafeGet(index++));
|
|||
|
if (skillItem != null)
|
|||
|
skills.Add(new PetSkillInfo(skillItem));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public class PetSkillInfo
|
|||
|
{
|
|||
|
public readonly ItemPetSkill item;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int id => item.id;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int combatValue => item.combatValue;
|
|||
|
|
|||
|
public int grade
|
|||
|
{
|
|||
|
get;
|
|||
|
set;
|
|||
|
}
|
|||
|
|
|||
|
public bool isUnlock => grade == 0;
|
|||
|
|
|||
|
public PetSkillInfo(ItemPetSkill petSkillItem)
|
|||
|
{
|
|||
|
this.item = petSkillItem;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region Field
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 上战宠物
|
|||
|
/// </summary>
|
|||
|
private int _battlePetId;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
readonly Dictionary<int, PetInfo> _pets = new Dictionary<int, PetInfo>(8);
|
|||
|
|
|||
|
int _feedTimestamp;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Property
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public PetInfo battlePet
|
|||
|
{
|
|||
|
get { _pets.TryGetValue(_battlePetId, out var result); return result; }
|
|||
|
set
|
|||
|
{
|
|||
|
_battlePetId = value != null ? value.item.id : 0;
|
|||
|
SaveLocal();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public int petFeedTimestamp => _feedTimestamp;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int combatValue => PlayerProxy.Instance.GetCombatValue(PlayerProxy.ATTRIBUTES_INDEX_PET);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public IReadOnlyCollection<PetInfo> GetAllPets()
|
|||
|
{
|
|||
|
return _pets.Values;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public PetInfo GetPet(int id)
|
|||
|
{
|
|||
|
_pets.TryGetValue(id, out var result);
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public int GetPetCombatValue()
|
|||
|
{
|
|||
|
return PlayerProxy.Instance.GetCombatValue(PlayerProxy.ATTRIBUTES_INDEX_PET);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="ad"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public int UpgradePet(PetInfo pet, bool ad)
|
|||
|
{
|
|||
|
if (pet.isMaxGrade)
|
|||
|
{
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
if (ad)
|
|||
|
{
|
|||
|
int feedCount = TimeProxy.Instance.GetTimes(TimeProxy.宠物升级);
|
|||
|
if (feedCount <= 0)
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
int result = 1;
|
|||
|
if (pet.AddGrade(ad ? 2 : 1))
|
|||
|
{
|
|||
|
result = 2;
|
|||
|
}
|
|||
|
|
|||
|
if (ad)
|
|||
|
{
|
|||
|
TimeProxy.Instance.CostTimes(TimeProxy.宠物升级);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_feedTimestamp = Launch.Timestamp + 60 * 60 * 8;
|
|||
|
}
|
|||
|
SaveLocal();
|
|||
|
UpdateAttributes(true);
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
public int GetRedPoint()
|
|||
|
{
|
|||
|
var remainTime = petFeedTimestamp - Launch.Timestamp;
|
|||
|
if (remainTime <= 0)
|
|||
|
{
|
|||
|
return 1;
|
|||
|
}
|
|||
|
//foreach (var pet in _pets.Values)
|
|||
|
//{
|
|||
|
// if (pet.CheckUpgrade())
|
|||
|
// {
|
|||
|
// return 1;
|
|||
|
// }
|
|||
|
//}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
public void UpdateAttributes(bool sendNotification)
|
|||
|
{
|
|||
|
int combatValue = 0;
|
|||
|
var results = F.ListPool<CombatAttribute>.Get();
|
|||
|
foreach (var pet in _pets.Values)
|
|||
|
{
|
|||
|
if (pet != null && pet.isFriend)
|
|||
|
{
|
|||
|
combatValue += pet.GetAttributes(results);
|
|||
|
}
|
|||
|
}
|
|||
|
PlayerProxy.Instance.UpdatePetCombatValue(results, combatValue, sendNotification);
|
|||
|
F.ListPool<CombatAttribute>.Release(results);
|
|||
|
}
|
|||
|
|
|||
|
const string ARCHIVE_KEY = "pet";
|
|||
|
const string ARCHIVE_KEY_V1 = "pet_v1";
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private void LoadLocal()
|
|||
|
{
|
|||
|
var petItems = ItemProxy.Instance.GetStaticItems<ItemPet>();
|
|||
|
_pets.Clear();
|
|||
|
for (int i = 0; i < petItems.Count; i++)
|
|||
|
{
|
|||
|
var petItem = petItems[i];
|
|||
|
_pets.Add(petItem.id, new PetInfo(petItem));
|
|||
|
}
|
|||
|
|
|||
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|||
|
if (dataList != null && dataList.Count > 0)
|
|||
|
{
|
|||
|
int index = 0;
|
|||
|
_battlePetId = dataList[index++];
|
|||
|
_feedTimestamp = dataList.SafeGet(index++);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY);
|
|||
|
if (dataList != null && dataList.Count > 0)
|
|||
|
{
|
|||
|
int index = 0;
|
|||
|
|
|||
|
dataList.SafeGet(index++);
|
|||
|
int petLevel = dataList.SafeGet(index++);
|
|||
|
int petExp = dataList.SafeGet(index++);
|
|||
|
if (petLevel > 0)
|
|||
|
{
|
|||
|
_pets[12000].Set(petLevel, 0);
|
|||
|
}
|
|||
|
else if (petExp > 0)
|
|||
|
{
|
|||
|
_pets[12000].Set(1, 0);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
ArchiveProxy.Instance.RemoveIntList(ARCHIVE_KEY);
|
|||
|
|
|||
|
UpdateAttributes(false);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private void SaveLocal()
|
|||
|
{
|
|||
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|||
|
if (dataList != null)
|
|||
|
{
|
|||
|
dataList.Clear();
|
|||
|
|
|||
|
dataList.Add(_battlePetId);
|
|||
|
dataList.Add(_feedTimestamp);
|
|||
|
|
|||
|
ArchiveProxy.Instance.SetIntList(ARCHIVE_KEY_V1, dataList);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Unity && Proxy
|
|||
|
|
|||
|
public static PetProxy Instance
|
|||
|
{
|
|||
|
get { return GetInstance<PetProxy>(); }
|
|||
|
}
|
|||
|
|
|||
|
public override void LoadCompleted()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public override void ReadArchive()
|
|||
|
{
|
|||
|
LoadLocal();
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
}
|