using System; using System.Collections.Generic; using UnityEngine; namespace GFGGame { public class FightDataManager : SingletonBase { public byte[] FightRoleRes { get; set; } public Texture2D RoleTextuex { get; set; } //角色基础分+部件基础分 // private int _score; // public int score // { // get // { // return _score; // } // set // { // _score = value; // EventAgent.DispatchEvent(ConstMessage.DRESS_UP_SCORE_CHANGED, _score); // } // } public int GetScore(FightData roleData) { float score = 0; for (int i = 0; i < roleData.itemList.Count; i++) { score += ItemDataManager.GetItemAdditionScore(roleData.itemList[i], roleData.scoreType, roleData.tags); } if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena) { int tagCount = ArenaDataManager.Instance.GetTagsCount(roleData.itemList, roleData.tags); ; tagCount = Math.Min(ArenaTagCfgArray.Instance.dataArray.Length, tagCount); float addition = 0; if (tagCount > 0) { int additionCfg = ArenaTagCfgArray.Instance.GetCfg(tagCount).addition; addition = additionCfg / 10000f; } score = score * (1 + addition); } return (int)Math.Ceiling(score); } //最终得分 private int _totalScore; public int totalScore { get { return _totalScore; } set { _totalScore = value; } } //战斗对象最终得分 private int _targetTotalScore; public int npcTotalScore { get { return _targetTotalScore; } set { _targetTotalScore = value; } } private bool _autoPlay = false; public bool autoPlay { get { return _autoPlay; } set { _autoPlay = value; if (!_autoPlay) fightSpeed = 1; StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_AUTO_PLAY, _autoPlay == true ? 1 : 0).Coroutine(); } } public int maxFightSpeed = 3; private int _fightSpeed = 1; public int fightSpeed { get { return _fightSpeed; } set { _fightSpeed = value; StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_FIGHT_AUTO_PLAY_SPEED, _fightSpeed).Coroutine(); } } private int _storyDialogSpeed = 1; public int dialogSpeed { get { return _storyDialogSpeed; } set { _storyDialogSpeed = value; StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_DIALOG_AUTO_PLAY_SPEED, _storyDialogSpeed).Coroutine(); } } //根据位置原点和随机范围获取评分位置 public void GetCirclePos(Vector2 pos, int range, out float x, out float y) { int numX = UnityEngine.Random.Range(0, 2); int signX = numX % 2 == 0 ? 1 : -1; float rangeX = UnityEngine.Random.Range(0, range); x = pos.x + signX * (rangeX); int numY = UnityEngine.Random.Range(0, 2); int signY = numY % 2 == 0 ? 1 : -1; float rangeY = UnityEngine.Random.Range(0, range); y = pos.y + signY * (rangeY); } public Texture2D GetPrintscreenNTexture(Camera camera) { RenderTexture rt = new RenderTexture(UnityEngine.Screen.width, UnityEngine.Screen.height, 0);//渲染一张1920*1080的图 camera.targetTexture = rt;//传到主摄像机上 camera.Render();//渲染 RenderTexture.active = rt; Texture2D screenShot = new Texture2D(UnityEngine.Screen.width, UnityEngine.Screen.height, TextureFormat.ARGB32, false); screenShot.ReadPixels(new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height), 0, 0);//读像素 screenShot.Apply(); camera.targetTexture = null; RenderTexture.active = null; UnityEngine.Object.Destroy(rt); return screenShot; } /// /// 获取标签总分数 /// /// 服装列表 /// 标签 /// public int GetTagsScore(List itemList, string[] tags) { int score = 0; for (int i = 0; i < itemList.Count; i++) { score += ItemDataManager.GetItemTagScore(itemList[i], tags); } return score; } public void SetItemScoreList(FightData _roleData) { _roleData.itemScoreList.Clear(); _roleData.itemScoreDic.Clear(); for (int i = 0; i < _roleData.itemList.Count; i++) { int score = ItemDataManager.GetItemAdditionScore(_roleData.itemList[i], _roleData.scoreType); _roleData.itemScoreList.Add(score); _roleData.itemScoreDic[_roleData.itemList[i]] = score; } } public float GetDressListAllScore(List itemList, int scoreType) { float itemSum = 0; for (int i = 0; i < itemList.Count; i++) { itemSum += ItemDataManager.GetItemAdditionScore(itemList[i], scoreType); } return itemSum; } /// /// 0失败1优秀2完美 /// /// /// public int GetClickType(float scale) { // float scaleX = _ui.m_comClick.m_comResult.m_imgCircle.scale.x; int clickType = ClickType.MISS_CLICK; if (FightDataManager.Instance.autoPlay == true) { return ClickType.PREFACT_CLICK; } if (scale <= 0.33f && scale > 0.23f) { clickType = ClickType.PREFACT_CLICK; } else if (scale <= 0.05f) { clickType = ClickType.MISS_CLICK; } else { clickType = ClickType.GREAT_CLICK; } return clickType; } /// /// 卡牌列表按竞技战力排序 /// /// /// public List SortCardList(List cardList, double itemSum, int scoreType) { int baseScore = RoleLevelCfgArray.Instance.GetCfg(RoleDataManager.lvl).baseScore; int leagueSkillScore = LeagueDataManager.Instance.GetAllSkillScore(scoreType); cardList.Sort((CardData a, CardData b) => { List skillLvsA = SkillDataManager.Instance.GetCardSkillLvs(a.id); List skillLvsB = SkillDataManager.Instance.GetCardSkillLvs(b.id); double addA = a.scores[scoreType] * ConstScoreSystem.PERFECT_SCORE * ConstScoreSystem.CLICK_SCORE / ConstScoreSystem.PART_SCORE * 6d; double addB = b.scores[scoreType] * ConstScoreSystem.PERFECT_SCORE * ConstScoreSystem.CLICK_SCORE / ConstScoreSystem.PART_SCORE * 6d; double scoreA = GetSkillFightScore(itemSum, baseScore, leagueSkillScore, a.id, a.scores[scoreType], skillLvsA) + addA; double scoreB = GetSkillFightScore(itemSum, baseScore, leagueSkillScore, b.id, b.scores[scoreType], skillLvsB) + addB; if (scoreA < scoreB) { return 1; } else if (scoreA > scoreB) { return -1; } return string.Compare(a.itemCfg.res, b.itemCfg.res); }); return cardList; } /// /// 获取技能战力 /// /// /// /// /// /// /// public long GetSkillFightScore(double itemScoreSum, int baseScore, long leagueSkillScore, int cardId, int cardScore, List skillLvs) { float skillScore = 0; if (skillLvs.Count == 0) return (long)skillScore; float skillBaseScore = (long)itemScoreSum + cardScore + baseScore + leagueSkillScore; List skillCfgs = PassivitySkillCfgArray.Instance.GetCfgsBycardId(cardId); //容错处理,防止两个长度不一致 var count = Mathf.Min(skillLvs.Count, skillCfgs.Count); for (int j = 0; j < count; j++) { PassivitySkillLvlCfg skillLvlCfg = PassivitySkillLvlCfgArray.Instance.GetCfgByskilllvlAndskillId(skillLvs[j], skillCfgs[j].skillId); if (skillLvlCfg == null) continue; skillScore += skillBaseScore * ((float)skillLvlCfg.fightPowerParam / 10000f); } // ET.Log.Debug("cardId:" + cardId); // ET.Log.Debug("skillScore:" + skillScore); return (long)Math.Ceiling(skillScore); ; } /// /// 获取快速挑战结果 /// /// /// /// /// /// /// public void GetQuickFightResult(int roundIndex, FightData myRoleData, FightData targetRoleData, out long _score, out long _targetScore) { double score = 0; double targetScore = 0; int cardId = myRoleData.cardId; double mainScore = ScoreSystemData.Instance.GetMainScore(myRoleData); List skillLvs = myRoleData.skillLvs; int targetCardId; double targetMainScore; List targetSkillLvs; List targetRoundTime; List roundTime = ScoreSystemData.Instance.GetRoundTime(myRoleData.cardId, myRoleData.skillLvs); targetCardId = targetRoleData.cardId; targetSkillLvs = targetRoleData.skillLvs; targetRoundTime = ScoreSystemData.Instance.GetRoundTime(targetRoleData.cardId, targetRoleData.skillLvs); if (targetRoleData.type == FightTargetType.PLAYER) { targetMainScore = ScoreSystemData.Instance.GetMainScore(targetRoleData); } else { targetMainScore = ScoreSystemData.Instance.GetRobotMainScore(targetRoleData); } if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena) { ArenaDataManager.Instance.roundTime = roundTime; ArenaDataManager.Instance.targetRoundTime = targetRoundTime; if (!ArenaDataManager.Instance.vaildSkills.ContainsKey(roundIndex)) ArenaDataManager.Instance.vaildSkills[roundIndex] = new Dictionary>>(); if (!ArenaDataManager.Instance.targetVaildSkills.ContainsKey(roundIndex)) ArenaDataManager.Instance.targetVaildSkills[roundIndex] = new Dictionary>>(); } int partId = 0; int currentTime = BeginTime.PART_ALL_FIGHT_BEGIN; GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore); GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score); for (int i = 0; i < FightScoreCfgArray.Instance.dataArray.Length; i++) { partId++; currentTime = BeginTime.PART_FIGHT_BEGIN; GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore); GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score); score += ScoreSystemData.Instance.GetPartScore(myRoleData, partId, ClickType.PREFACT_CLICK, 0); if (targetRoleData.type == FightTargetType.PLAYER) { targetScore += ScoreSystemData.Instance.GetPartScore(targetRoleData, partId, ClickType.PREFACT_CLICK, 0); } else { targetScore += ScoreSystemData.Instance.GetRobotPartScore(targetRoleData, partId, ClickType.PREFACT_CLICK, 0); } currentTime = BeginTime.PART_PREFACT_CLICK; GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore); GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score); currentTime = BeginTime.PART_FIGHT_END; GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore); GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score); // Debug.Log(" targetScore444:" + targetScore); } partId++; currentTime = BeginTime.ALL_PERFECT_START; GetSkillScore(FightRoleType.MINE, roundIndex, currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore); GetSkillScore(FightRoleType.TAEGET, roundIndex, currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score); score += ScoreSystemData.Instance.GetAllCircleAddScore(mainScore); targetScore += ScoreSystemData.Instance.GetAllCircleAddScore(targetMainScore); Debug.Log(" targetScore666:" + targetScore); _score = Mathf.CeilToInt((float)score); _targetScore = Mathf.CeilToInt((float)targetScore); } private void GetSkillScore(int roleType, int roundIndex, int currentTime, int partId, double mainScore, int cardId, List skillLvs, List roundTime, ref double score, double targetMainScore, int targetCardId, List targetSkillLvs, List targetRoundTime, ref double targetScore) { List vaildSkills = ScoreSystemData.Instance.GetValidSkills(currentTime, partId, cardId, skillLvs, targetCardId, targetSkillLvs, roundTime, targetRoundTime); ScoreSystemData.Instance.GetPartItemSkillScore(vaildSkills, mainScore, targetMainScore, out int skillScore, out int targetSkillScore, out Dictionary skillScoreDic); score += skillScore; targetScore += targetSkillScore; if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena) { ArenaDataManager dataManager = ArenaDataManager.Instance; if (roleType == FightRoleType.MINE) { if (!dataManager.vaildSkills[roundIndex].ContainsKey(partId)) dataManager.vaildSkills[roundIndex][partId] = new Dictionary>(); dataManager.vaildSkills[roundIndex][partId][currentTime] = vaildSkills; } else { if (!dataManager.targetVaildSkills[roundIndex].ContainsKey(partId)) dataManager.targetVaildSkills[roundIndex][partId] = new Dictionary>(); dataManager.targetVaildSkills[roundIndex][partId][currentTime] = vaildSkills; } } } } }