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); } } //最终得分 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 = 2; 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 int GetTagsCount(List itemList, string[] tags) { int count = 0; for (int i = 0; i < itemList.Count; i++) { if (ItemDataManager.CheckItemTagsRight(itemList[i], tags)) count++; } return count; } //获取玩家战斗数据 public FightRoleData GetMyFightRoleData() { FightRoleData roleData = new FightRoleData(); roleData.name = RoleDataManager.roleName; roleData.headId = RoleDataManager.headId; roleData.headBorderId = RoleDataManager.headBorderId; roleData.scoreType = InstanceZonesDataManager.currentScoreType; //本次战斗的主题 roleData.baseScore = RoleLevelCfgArray.Instance.GetCfg(RoleDataManager.lvl).baseScore;//角色等级分数 roleData.cardId = InstanceZonesDataManager.currentCardId; ;//卡牌id roleData.cardScore = CardDataManager.GetCardDataById(roleData.cardId).scores[roleData.scoreType];//卡牌对应主题的属性分数 if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena) { // roleData.fightScene = ConstInstanceZonesType.Arena; roleData.tags = new string[1] { ArenaDataManager.Instance.Tag }; } else { StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId); // roleData.fightScene = levelCfg.type; if (!string.IsNullOrEmpty(levelCfg.fightID)) { StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID); roleData.tags = fightCfg.needTagsArr;////本次战斗要求的标签 } } if (roleData.cardId > 0) { roleData.skillLvs = SkillDataManager.Instance.GetSkillLvs(roleData.cardId); } roleData.itemList = MyDressUpHelper.dressUpObj.itemList; for (int i = 0; i < roleData.itemList.Count; i++) { int score = ItemDataManager.GetItemAdditionScore(roleData.itemList[i], roleData.scoreType); roleData.itemScoreList.Add(score); } return roleData; } //获取副本机器人战斗数据 public FightRobotData GetFightRobotData() { FightRobotData robotData = new FightRobotData(); StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId); StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID); robotData.res = fightCfg.targetRes; robotData.name = fightCfg.targetName; robotData.scoreType = InstanceZonesDataManager.currentScoreType; //本次战斗的主题 robotData.baseScore = fightCfg.targetBaseScore; robotData.cardId = fightCfg.targetCardId; robotData.cardScore = fightCfg.targetCardScore; robotData.skillLvs = new List(fightCfg.targetSkillLvsArr); robotData.itemScoreList = new List(fightCfg.targetPartsScoreArr); return robotData; } //获取竞技场对手角色战斗数据 public FightRoleData GetArenaRoleData(int index, ArenaTargetData arenaTarget) { return arenaTarget.RoleDressupList[index]; } //获取竞技场机器人战斗数据 public FightRobotData GetArenaRobotData(int index, ArenaTargetData arenaTarget) { return arenaTarget.RobotDressupList[index]; } /// /// 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.866f && scale > 0.65f) { clickType = ClickType.PREFACT_CLICK; } else if (scale <= 0.216f) { clickType = ClickType.MISS_CLICK; } else { clickType = ClickType.GREAT_CLICK; } return clickType; } /// /// 获取快速挑战结果 /// /// /// /// /// /// /// public void GetQuickFightResult(FightRoleData myRoleData, int targetType, FightRoleData targetRoleData, FightRobotData targetRobotData, out int _score, out int _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); if (targetType == ArenaFightTargetType.PLAYER) { targetCardId = targetRoleData.cardId; targetSkillLvs = targetRoleData.skillLvs; targetMainScore = ScoreSystemData.Instance.GetMainScore(targetRoleData); targetRoundTime = ScoreSystemData.Instance.GetRoundTime(targetRoleData.cardId, targetRoleData.skillLvs); } else { targetCardId = targetRobotData.cardId; targetSkillLvs = targetRobotData.skillLvs; targetMainScore = ScoreSystemData.Instance.GetRobotMainScore(targetRobotData); targetRoundTime = ScoreSystemData.Instance.GetRoundTime(targetRobotData.cardId, targetRobotData.skillLvs); } int partId = 0; int currentTime = BeginTime.PART_ALL_FIGHT_BEGIN; GetSkillScore(currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore); GetSkillScore(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(currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore); GetSkillScore(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 (targetType == ArenaFightTargetType.PLAYER) { targetScore += ScoreSystemData.Instance.GetPartScore(targetRoleData, partId, ClickType.PREFACT_CLICK, 0); } else { targetScore += ScoreSystemData.Instance.GetRobotPartScore(targetRobotData, partId, ClickType.PREFACT_CLICK, 0); } currentTime = BeginTime.PART_PREFACT_CLICK; GetSkillScore(currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore); GetSkillScore(currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score); currentTime = BeginTime.PART_FIGHT_END; GetSkillScore(currentTime, partId, mainScore, cardId, skillLvs, roundTime, ref score, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore); GetSkillScore(currentTime, partId, targetMainScore, targetCardId, targetSkillLvs, targetRoundTime, ref targetScore, mainScore, cardId, skillLvs, roundTime, ref score); } score += ScoreSystemData.Instance.GetAllCircleAddScore(mainScore); targetScore += ScoreSystemData.Instance.GetAllCircleAddScore(targetMainScore); _score = Mathf.CeilToInt((float)score); _targetScore = Mathf.CeilToInt((float)targetScore); } private void GetSkillScore(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; targetMainScore += targetSkillScore; } /// /// 获取竞技场玩家战力 /// /// public int GetArenaRoleFightScore(FightRoleData roleDatas) { //竞技场战力=搭配战力+卓越点击战力+卡牌战力 //搭配战力=第1套搭配所有部件主属性和+第2套搭配所有部件主属性和+第3套搭配所有部件主属性和 //卓越点击战力=卓越点击评分和/2.33 //技能战力=(第1套搭配所有部件主属性和+卡牌主属性+人物基础分)*技能1当前等级对应的战力系数+(第1套搭配所有部件主属性和+卡牌主属性+人物基础分)*技能2当前等级对应的战力系数+(第1套搭配所有部件主属性和+卡牌主属性+人物基础分)*技能3当前等级对应的战力系数+(第2套搭配所有部件主属性和+卡牌主属性+人物基础分)*技能1当前等级对应的战力系数+(第2套搭配所有部件主属性和+卡牌主属性+人物基础分)*技能2当前等级对应的战力系数+(第2套搭配所有部件主属性和+卡牌主属性+人物基础分)*技能3当前等级对应的战力系数+(第3套搭配所有部件主属性和+卡牌主属性+人物基础分)*技能1当前等级对应的战力系数+(第3套搭配所有部件主属性和+卡牌主属性+人物基础分)*技能2当前等级对应的战力系数+(第3套搭配所有部件主属性和+卡牌主属性+人物基础分)*技能3当前等级对应的战力系数 double fightScore = 0; double itemSum = GetItemScoreSum(roleDatas.itemScoreList); double clickScore = GetPerfectClickScore(roleDatas) / ConstScoreSystem.PART_SCORE; double skillScore = 0; double skillBaseScore = itemSum + roleDatas.cardScore + roleDatas.baseScore; List skillCfgs = PassivitySkillCfgArray.Instance.GetCfgsBycardId(roleDatas.cardId); for (int j = 0; j < skillCfgs.Count; j++) { PassivitySkillLvlCfg skillLvlCfg = PassivitySkillLvlCfgArray.Instance.GetCfgByskilllvlAndskillId(roleDatas.skillLvs[j], skillCfgs[j].skillId); if (skillLvlCfg == null) continue; skillScore += skillBaseScore * skillLvlCfg.fightPowerParam / 10000; } fightScore = itemSum + clickScore + skillScore; return (int)Math.Ceiling(fightScore); } /// /// 获取竞技场机器人战力 /// /// public int GetArenaRobotFightScore(List robotDatas) { double fightScore = 0; for (int i = 0; i < robotDatas.Count; i++) { double itemSum = GetItemScoreSum(robotDatas[i].itemScoreList); double clickScore = GetRobotPerfectClickScore(robotDatas[i]) / ConstScoreSystem.PART_SCORE; double skillScore = 0; double skillBaseScore = itemSum + robotDatas[i].cardScore + robotDatas[i].baseScore; List skillCfgs = PassivitySkillCfgArray.Instance.GetCfgsBycardId(robotDatas[i].cardId); for (int j = 0; j < skillCfgs.Count; j++) { PassivitySkillLvlCfg skillLvlCfg = PassivitySkillLvlCfgArray.Instance.GetCfgByskilllvlAndskillId(robotDatas[i].skillLvs[j], skillCfgs[i].skillId); if (skillLvlCfg == null) continue; skillScore += skillBaseScore * skillLvlCfg.fightPowerParam / 10000; } fightScore = itemSum + clickScore + skillScore; } return (int)Math.Ceiling(fightScore); } /// /// 所有部件主属性和 /// /// private double GetItemScoreSum(List itemScoreList) { double scoreSum = 0; for (int i = 0; i < itemScoreList.Count; i++) { scoreSum += itemScoreList[i]; } return scoreSum; } private double GetPerfectClickScore(FightRoleData roleData) { double clickScore = 0; foreach (int key in roleData.pardScoreListDic.Keys) { clickScore += ScoreSystemData.Instance.GetPartScore(roleData, key, ClickType.PREFACT_CLICK, 0); } return clickScore; } private double GetRobotPerfectClickScore(FightRobotData robotData) { double clickScore = 0; FightScoreCfg[] scoreCfg = FightScoreCfgArray.Instance.dataArray; for (int i = 0; i < scoreCfg.Length; i++) { clickScore += ScoreSystemData.Instance.GetRobotPartScore(robotData, i + 1, ClickType.PREFACT_CLICK, 0); } return clickScore; } } }