123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- namespace GFGGame
- {
- public class FightDataManager : SingletonBase<FightDataManager>
- {
- 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 FightRoleData _roleData = new FightRoleData();
- public FightRoleData roleData
- {
- get
- {
- return GetMyFightRoleData();
- }
- }
- public int GetScore(List<int> itemScoreList)
- {
- int score = 0;
- for (int i = 0; i < itemScoreList.Count; i++)
- {
- score += itemScoreList[i];
- }
- return 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;
- }
- /// <summary>
- /// 获取标签总分数
- /// </summary>
- /// <param name="itemList">服装列表</param>
- /// <param name="tags">标签</param>
- /// <returns></returns>
- public int GetTagsScore(List<int> itemList, string[] tags)
- {
- int score = 0;
- for (int i = 0; i < itemList.Count; i++)
- {
- score += ItemDataManager.GetItemTagScore(itemList[i], tags);
- }
- return score;
- }
- //获取玩家战斗数据
- private FightRoleData GetMyFightRoleData()
- {
- _roleData.name = RoleDataManager.roleName;
- _roleData.headId = RoleDataManager.headId;
- // _roleData.headBorderId = RoleDataManager.headBorderId;
- _roleData.baseScore = RoleLevelCfgArray.Instance.GetCfg(RoleDataManager.lvl).baseScore;//角色等级分数
- if (InstanceZonesDataManager.FightScene == ConstInstanceZonesType.Arena)
- {
- if (ArenaDataManager.Instance.CurFightIndex == 0)
- {
- _roleData.tags = new string[1] { ArenaDataManager.Instance.Tag };
- }
- _roleData.scoreType = ArenaDataManager.Instance.DressupList[ArenaDataManager.Instance.CurFightIndex].scoreType;
- _roleData.cardId = ArenaDataManager.Instance.DressupList[ArenaDataManager.Instance.CurFightIndex].cardId;
- _roleData.cardScore = ItemDataManager.GetItemAdditionScore(_roleData.cardId, _roleData.scoreType, _roleData.tags);
- _roleData.itemList = ArenaDataManager.Instance.DressupList[ArenaDataManager.Instance.CurFightIndex].itemList;
- }
- 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;////本次战斗要求的标签
- }
- _roleData.scoreType = InstanceZonesDataManager.currentScoreType; //本次战斗的主题
- _roleData.cardId = InstanceZonesDataManager.currentCardId; ;//卡牌id
- _roleData.cardScore = _roleData.cardId == 0 ? 0 : CardDataManager.GetCardDataById(_roleData.cardId).scores[_roleData.scoreType];//卡牌对应主题的属性分数
- _roleData.itemList = MyDressUpHelper.dressUpObj.itemList;
- }
- if (_roleData.cardId > 0)
- {
- _roleData.skillLvs = SkillDataManager.Instance.GetSkillLvs(_roleData.cardId);
- }
- SetItemScoreList(_roleData);
- ScoreSystemData.Instance.SetEquipScoresWithPartId(_roleData);
- return _roleData;
- }
- public void SetItemScoreList(FightRoleData _roleData)
- {
- _roleData.itemScoreList.Clear();
- for (int i = 0; i < _roleData.itemList.Count; i++)
- {
- int score = ItemDataManager.GetItemAdditionScore(_roleData.itemList[i], _roleData.scoreType);
- _roleData.itemScoreList.Add(score);
- }
- }
- //获取副本机器人战斗数据
- 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<int>(fightCfg.targetSkillLvsArr);
- robotData.itemScoreList = new List<int>(fightCfg.targetPartsScoreArr);
- return robotData;
- }
- /// <summary>
- /// 0失败1优秀2完美
- /// </summary>
- /// <param name="scale"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 卡牌列表按竞技战力排序
- /// </summary>
- /// <param name="arrayList"></param>
- /// <returns></returns>
- public List<CardData> SortCardList(List<CardData> cardList, List<int> itemList, int scoreType)
- {
- double itemSum = 0;
- for (int i = 0; i < itemList.Count; i++)
- {
- itemSum += ItemDataManager.GetItemAdditionScore(itemList[i], scoreType);
- }
- List<CardData> arrayList = new List<CardData>(cardList);
- for (int i = arrayList.Count - 1; i >= 0; i--)
- {
- List<int> skillLvs = SkillDataManager.Instance.GetSkillLvs(arrayList[i].id);
- if (skillLvs.Count == 0)
- {
- ET.Log.Error("卡牌:" + arrayList[i].id + " 未配置技能");
- arrayList.RemoveAt(i);
- }
- }
- int baseScore = RoleLevelCfgArray.Instance.GetCfg(RoleDataManager.lvl).baseScore;
- arrayList.Sort((CardData a, CardData b) =>
- {
- double scoreA = GetSkillFightScore(itemSum, baseScore, a.id, a.scores[scoreType], SkillDataManager.Instance.GetSkillLvs(a.id));
- double scoreB = GetSkillFightScore(itemSum, baseScore, b.id, b.scores[scoreType], SkillDataManager.Instance.GetSkillLvs(b.id));
- if (scoreA < scoreB)
- {
- return 1;
- }
- else if (scoreA > scoreB)
- {
- return -1;
- }
- return string.Compare(a.itemCfg.res, b.itemCfg.res);
- });
- return arrayList;
- }
- /// <summary>
- /// 获取技能战力
- /// </summary>
- /// <param name="itemScoreSum"></param>
- /// <param name="baseScore"></param>
- /// <param name="cardId"></param>
- /// <param name="cardScore"></param>
- /// <param name="skillLvs"></param>
- /// <returns></returns>
- public long GetSkillFightScore(double itemScoreSum, int baseScore, int cardId, int cardScore, List<int> skillLvs)
- {
- // double itemSum = itemScoreSum;
- long skillScore = 0;
- long skillBaseScore = (long)itemScoreSum + cardScore + baseScore;
- List<PassivitySkillCfg> skillCfgs = PassivitySkillCfgArray.Instance.GetCfgsBycardId(cardId);
- for (int j = 0; j < skillCfgs.Count; j++)
- {
- // ET.Log.Debug("cardId:" + cardId + " skillLvs:" + skillLvs.Count + " skillCfgs:" + skillCfgs.Count + " index:" + j);
- PassivitySkillLvlCfg skillLvlCfg = PassivitySkillLvlCfgArray.Instance.GetCfgByskilllvlAndskillId(skillLvs[j], skillCfgs[j].skillId);
- if (skillLvlCfg == null) continue;
- skillScore += skillBaseScore * skillLvlCfg.fightPowerParam / 10000;
- }
- return skillScore;
- }
- /// <summary>
- /// 获取快速挑战结果
- /// </summary>
- /// <param name="myRoleData"></param>
- /// <param name="targetType"></param>
- /// <param name="targetRoleData"></param>
- /// <param name="targetRobotData"></param>
- /// <param name="_score"></param>
- /// <param name="_targetScore"></param>
- 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<int> skillLvs = myRoleData.skillLvs;
- int targetCardId;
- double targetMainScore;
- List<int> targetSkillLvs;
- List<int> targetRoundTime;
- List<int> 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<int> skillLvs, List<int> roundTime, ref double score, double targetMainScore, int targetCardId, List<int> targetSkillLvs, List<int> targetRoundTime, ref double targetScore)
- {
- List<PassivitySkillLvlCfg> 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<int, int> skillScoreDic);
- score += skillScore;
- targetMainScore += targetSkillScore;
- }
- }
- }
|