// *********************************************************************** // Assembly : Unity // Author : Kimch // Created : 2019-06-05 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using System.Collections; using System.Collections.Generic; using CodeStage.AntiCheat.ObscuredTypes; using F; using UnityEngine; namespace G { /// /// /// public partial class PlayerProxy : GameProxy { #region Proxy private static PlayerProxy _Instance; public static PlayerProxy Instance { get { return _Instance; } } private void Awake() { _Instance = this; } public override int priority => 900; public override void ReadArchive() { this.InitCombatAttributes(); this.InitEquipmentSlots(); this.InitEquipmentSlotSuits(); LoadCha(); LoadEquipmentSlots(); LoadEquipmentSuits(); this.UpdateAttributes(false); SyncMission(); } private void SyncMission() { //MissionProxy.Instance.OnEvent2(MissionProxy.角色达到X, this.grade); int totalGrade = 0; for (int i = 0; i < _equipmentSlots.Length; i++) { totalGrade += _equipmentSlots[i].grade; } MissionProxy.Instance.OnEvent2(MissionProxy.累计强化次数, totalGrade); } #endregion #region Method /// /// /// /// public ItemCha GetCurrentCha() { return ItemProxy.Instance.GetStaticItem(1); } /// /// /// /// public string GetCurrentChaModel() { var skin = ChaSkinProxy.Instance.GetCurrentSkin(0).item; if (skin.asset3d == "cha_01_skin_1" && KPlatform.Instance.IsAbConfig("expt_cha", "1")) return "cha_01_skin_t"; return skin.asset3d; } public string GetWeaponModel(int weaponKind) { var chaSkinInfo = ChaSkinProxy.Instance.GetCurrentSkin(weaponKind); if (chaSkinInfo != null && !chaSkinInfo.isDefault) { return chaSkinInfo.item.weapon3d[weaponKind - 1]; } else { return null; } } public ItemChaSkin GetCurrentChaSkin() { var weapon = GetCurWeapon(); if (weapon != null) { return ChaSkinProxy.Instance.GetCurrentSkin(weapon.weaponKind).item; } return ItemProxy.Instance.GetStaticItem(2000); } //public ItemChaSkin GetChaSkinByWeapon(int weaponKind) //{ // int skinId = ArchiveProxy.Instance.GetInt("cha_skin_" + weaponKind, 2000); // return ItemProxy.Instance.GetStaticItem(skinId); //} //public void SetChaSkinByWeapon(int weaponKind, int skin) //{ // ArchiveProxy.Instance.SetInt("cha_skin_" + weaponKind, skin); //} private void LoadCha() { var isNew = ArchiveProxy.Instance.GetInt(GlobalDefine.KEY_NEW, 0); if (isNew == 0) { GlobalVar.IsNewPlayer = true; //设置初始装备 var item = GetCurrentCha(); if (item != null) { MoneyProxy.Instance.AddCoin(item.money); MoneyProxy.Instance.AddChip(item.gem); //this.energyMax = item.energy; if (item.weapon > 0) { SetDefaultEquipment(item.weapon); } } ArchiveProxy.Instance.SetInt(GlobalDefine.KEY_NEW, 1); var saveVer = ArchiveProxy.Instance.GetString("app_ver"); if (string.IsNullOrEmpty(saveVer)) { ArchiveProxy.Instance.SetString("app_ver", Application.version); } } this.gradeMax = ItemProxy.Instance.GetStaticItems().Count; UpdateGrowthCombatValue(false); } #endregion #region 角色属性 /// /// 角色Id /// public int id { get; private set; } /// /// 配置表Id /// public int itemId { get { return 1; } } /// /// 等级 /// public int grade { get { return Mathf.Min(ArchiveProxy.Instance.GetInt(Item.Id.kGrade, 1), gradeMax); } set { value = Mathf.Clamp(value, 1, gradeMax); var tmpGrade = ArchiveProxy.Instance.GetInt(Item.Id.kGrade, 1); if (value > tmpGrade) { ArchiveProxy.Instance.SetInt(Item.Id.kGrade, value); //UpdateGrowthCombatValue(true); MissionProxy.Instance.OnEvent2(MissionProxy.角色达到X, value); PostNotification(GlobalDefine.EVENT_GRADE_CHANGED); } } } /// /// 等级上限 /// public int gradeMax { get; private set; } /// /// 经验 /// public int exp { get { return ArchiveProxy.Instance.GetInt(Item.Id.kExp); } set { int tmpGrade = this.grade; int oldGrade = tmpGrade; int tmpExp = value; Label: var chaLevelItem = ItemProxy.Instance.GetStaticItem(tmpGrade); if (chaLevelItem != null && tmpGrade < gradeMax) { if (tmpExp >= chaLevelItem.exp) { tmpExp -= chaLevelItem.exp; tmpGrade += 1; if (tmpExp > chaLevelItem.exp) goto Label; } } ArchiveProxy.Instance.SetInt(Item.Id.kExp, tmpExp); if (oldGrade < tmpGrade) { this.grade = tmpGrade; KStatistics.Instance.ReportEventLevelUp(1, oldGrade, tmpGrade, "battle", 0); } } } /// /// /// /// public void AddExp(int value) { if (value > 0) { this.exp += value; } } /// /// 当前等级所需经验 /// public int expMax { get { var gi = this.GetGradeInfo(this.grade); return gi != null ? gi.exp : 1; } } /// /// 经验比例 /// public float expRatio { get { return UnityEngine.Mathf.Clamp01(exp / (float)expMax); } } /// /// /// public int combatValue { get { return _combatValues[0]; } } /// /// 昵称 /// public string nickName { get { return ArchiveProxy.Instance.GetString("name", "少侠李太白"); } set { if (!string.IsNullOrEmpty(value)) ArchiveProxy.Instance.SetString("name", value); } } /// /// 自我介绍 /// public string selfIntro { get; set; } /// /// 头像 /// public string headURL { get { return ArchiveProxy.Instance.GetString("avatar", ""); } set { if (!string.IsNullOrEmpty(value)) { ArchiveProxy.Instance.SetString("avatar", value); } else { ArchiveProxy.Instance.SetString("avatar", ""); } } } public string socialAvatarUrl { get; set; } public string socialNickName { get; set; } #endregion #region Energy private int _energyTime => energy; private const int ENERGY_RECOVER_SECOND = 900; private const int ENERGY_LIMIT = 600; private const int ENERGY_INIT_AMOUNT = 20; /// /// /// public int energy { get { var result = ArchiveProxy.Instance.GetInt(Item.Id.kEnergy); int maxEnergy = this.energyMax; if (result >= maxEnergy && result <= ENERGY_LIMIT) { return result; } else { float secondEnergy = (result - Launch.Timestamp) / (float)ENERGY_RECOVER_SECOND; //int second = Mathf.Max(0, result - Launch.Timestamp);// (float)ENERGY_RECOVER_SECOND); return Mathf.Clamp((int)(maxEnergy - secondEnergy), 0, maxEnergy); } } set { int maxEnergy = this.energyMax; if (value >= maxEnergy) { ArchiveProxy.Instance.SetInt(Item.Id.kEnergy, Mathf.Min(ENERGY_LIMIT, value)); } else if (value >= 0) { var tmpEnergy = ArchiveProxy.Instance.GetInt(Item.Id.kEnergy); int second = 0; if (tmpEnergy > ENERGY_LIMIT) { second = Mathf.Max(0, tmpEnergy - Launch.Timestamp); second %= ENERGY_RECOVER_SECOND; if (second != 0) second = ENERGY_RECOVER_SECOND - second; } tmpEnergy = Launch.Timestamp + Mathf.Max(0, (maxEnergy - value) * ENERGY_RECOVER_SECOND - second); ArchiveProxy.Instance.SetInt(Item.Id.kEnergy, tmpEnergy); } //if (_energy >= energyMax) //{ // int diff = _energy - value; // _energy = value; // if (_energy < energyMax) // _energyTime = Launch.Timestamp + (ENERGY_RECOVER_SECOND * diff); // else // _energyTime = 0; //} //else //{ // int diff = _energy - value; // _energy = value; // if (_energy < energyMax) // _energyTime += (ENERGY_RECOVER_SECOND * diff); // else // _energyTime = 0; //} //ArchiveProxy.Instance.SetInt((int)Item.ItemId.kEnergy, _energy); //ArchiveProxy.Instance.SetInt("energy_time", _energyTime); } } /// /// /// public float energyOverflow { get { var result = ArchiveProxy.Instance.GetInt(Item.Id.kEnergy); int maxEnergy = this.energyMax; if (result >= maxEnergy && result <= ENERGY_LIMIT) { return 0f; } else { return (Launch.Timestamp - result) / (float)ENERGY_RECOVER_SECOND; } } } ObscuredInt _energyMax; /// /// /// public int energyMax { get { return Mathf.Max(ENERGY_INIT_AMOUNT, _energyMax); } set { if (value > 0) _energyMax = Mathf.Max(ENERGY_INIT_AMOUNT, value); else _energyMax = ENERGY_INIT_AMOUNT; //ArchiveProxy.Instance.SetInt(GlobalDefine.KEY_ENERGY_MAX, value); } } /// /// /// public int energyTime { get { var result = ArchiveProxy.Instance.GetInt(Item.Id.kEnergy); if (result >= energyMax && result <= ENERGY_LIMIT) { return 0; } return result; } } /// /// /// public string energyRecoverTime { get { int second = (energyTime - Launch.Timestamp); if (second > 0) { int temp = second % ENERGY_RECOVER_SECOND; return $"{temp / 60}:{(temp % 60).ToString("00")}"; } return ""; } } // private static ObscuredByte _LevelEnergyCost = 5; /// /// /// /// public bool UseEnergyForLevel() { int energyCost = _LevelEnergyCost; if (energy >= energyCost) { energy -= energyCost; return true; } return false; } /// /// 检查 /// /// public bool CheckEnergyForLevel() { int energyCost = _LevelEnergyCost; return energy >= energyCost; } #endregion #region Motility private const int MOTILITY_RECOVER_SECOND = 3600; private const int MOTILITY_LIMIT = 100; private const int MOTILITY_INIT_AMOUNT = 3; /// /// /// public int motility { get { var result = ArchiveProxy.Instance.GetInt(Item.Id.kMotility); if (result >= motilityMax && result <= MOTILITY_LIMIT) { return result; } else { int second = Mathf.Max(0, result - Launch.Timestamp); return Mathf.Max(0, (int)(motilityMax - second / (float)MOTILITY_RECOVER_SECOND)); } } set { if (value >= motilityMax) { ArchiveProxy.Instance.SetInt(Item.Id.kMotility, Mathf.Min(MOTILITY_LIMIT, value)); } else if (value >= 0) { var tmpMotility = ArchiveProxy.Instance.GetInt(Item.Id.kMotility); int second = 0; if (tmpMotility > MOTILITY_LIMIT) { second = Mathf.Max(0, tmpMotility - Launch.Timestamp); second %= MOTILITY_RECOVER_SECOND; if (second != 0) second = MOTILITY_RECOVER_SECOND - second; } tmpMotility = Launch.Timestamp + Mathf.Max(0, (motilityMax - value) * MOTILITY_RECOVER_SECOND - second); ArchiveProxy.Instance.SetInt(Item.Id.kMotility, tmpMotility); } } } ObscuredInt _motilityMax; /// /// (0)重置 /// public int motilityMax { get { return Mathf.Max(MOTILITY_INIT_AMOUNT, _motilityMax); } set { if (value > 0) _motilityMax = Mathf.Max(MOTILITY_INIT_AMOUNT, value); else _motilityMax = MOTILITY_INIT_AMOUNT; //ArchiveProxy.Instance.SetInt(GlobalDefine.KEY_MOTILITY_MAX, value); } } /// /// /// public int motilityTime { get { var result = ArchiveProxy.Instance.GetInt(Item.Id.kMotility); if (result >= motilityMax && result <= MOTILITY_LIMIT) { return 0; } return result; } } /// /// /// public string motilityRecoverTime { get { int second = (motilityTime - Launch.Timestamp); if (second > 0) { int temp = second % MOTILITY_RECOVER_SECOND; return $"{temp / 60}:{(temp % 60).ToString("00")}"; } return ""; } } /// /// /// /// /// public bool UseMotilityForTravel(bool check = false) { if (motility >= 1) { if (!check) motility -= 1; return true; } return false; } #endregion #region 角色信息表 /// /// 头像信息表 /// public class HeadInfo { public enum Type { PlayerHead = 1, } public int id { get; private set; } public int type { get; private set; } public string icon { get; private set; } public bool unlocked { get; private set; } public void Load(IDictionary table) { this.id = table.GetInt("Id"); this.type = table.GetInt("Type"); this.icon = table.GetString("Icon"); } } public class NameInfo { public int id; public int type; public void Load(IDictionary table) { id = table.GetInt("Id"); type = table.GetInt("Type"); } } public class HeadFrameInfo { public int id; public int nameId; public string iconName; public string iconAtlas; public bool islock = false; public void Load(IDictionary table) { //id = table.GetInt("Id"); //nameId = table.GetInt("NameId"); //iconName = table.GetString("Icon"); //iconAtlas = table.GetString("IconAtlas"); } } private static Dictionary _HeadInfos; public ItemChaLevel GetGradeInfo(int grade) { return ItemProxy.Instance.GetStaticItem(grade); } public List GetAllHeads() { return new List(_HeadInfos.Values); } public HeadInfo GetHeadInfo(int id) { HeadInfo ret = null; if (_HeadInfos != null) { _HeadInfos.TryGetValue(id, out ret); } return ret; } /// /// 1为男性2为女性 /// /// /// public static string GetRandomName(int type) { var firstString = string.Empty; var familyString = string.Empty; return firstString + familyString; } #endregion } }