| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- public enum OutputType
- {
- BeginFighting = 1, //开始战斗
- EndFighting = 2, //结束战斗
- Dead = 3, //角色死亡
- Damage = 4, //技能伤害
- Heal = 5, //治疗
- Shield = 6, //护盾
- Disperse = 7, //驱散
- Clean = 8, //净化
- Break = 9, //打断
- Vertigo = 10, //眩晕
- }
- public struct OutputInfo
- {
- public OutputType type;
- public string timeStr;
- public string casterName;
- public string targetName;
- public string skillName;
- public object val;
- public OutputInfo(OutputType type)
- {
- this.type = type;
- timeStr = DateTime.Now.ToLongTimeString();
- casterName = null;
- targetName = null;
- skillName = null;
- val = null;
- }
- }
- /// <summary>
- /// 超链接信息类
- /// </summary>
- public class HrefInfo
- {
- public string color;
- public string text;
- public HrefInfo(string clr,string content)
- {
- color = clr;
- text = content;
- }
- }
- public class BattleOutput
- {
- const int MaxNum = 200;
- private List<string> mOutputList = new List<string>();
- public List<string> OutputList
- {
- get { return mOutputList; }
- }
- public void Begin()
- {
- ConvertLogToStr(OutputType.BeginFighting);
- }
- public void End()
- {
- ConvertLogToStr(OutputType.EndFighting);
- }
- public void Output(OutputType type, Fighter caster, Fighter target = null, string skillName = null, object val = null)
- {
- ConvertLogToStr(type, caster, target, skillName, val);
- }
- private void ConvertLogToStr(OutputType type, Fighter caster = null, Fighter target = null, string skillName = null, object val = null)
- {
- string timeStr = DateTime.Now.ToLongTimeString();
- string str = "";
- string casterName = caster != null ? I18N.T(caster.Name) : "";
- string targetName = target != null ? I18N.T(target.Name) : "";
- string sName = skillName != null ? I18N.SetLanguageValue("BattleOutput_SkillName", skillName) : "";
- string valStr = val != null ? val.ToString() : "";
- bool team = caster != null ? caster.TeamSide == 0 : false;
- switch (type)
- {
- case OutputType.BeginFighting:
- str = I18N.SetLanguageValue("BattleOutput_001", timeStr);
- break;
- case OutputType.EndFighting:
- str = I18N.SetLanguageValue("BattleOutput_002", timeStr);
- break;
- case OutputType.Dead:
- if(team)
- str = I18N.SetLanguageValue("BattleOutput_003", timeStr, casterName, sName, targetName, valStr);
- else
- str = I18N.SetLanguageValue("BattleOutput_011", timeStr, casterName, sName, targetName, valStr);
- break;
- case OutputType.Damage:
- if(team)
- str = I18N.SetLanguageValue("BattleOutput_004", timeStr, casterName, sName, targetName, valStr);
- else
- str = I18N.SetLanguageValue("BattleOutput_012", timeStr, casterName, sName, targetName, valStr);
- break;
- case OutputType.Heal:
- if(team)
- str = I18N.SetLanguageValue("BattleOutput_005", timeStr, casterName, sName, targetName, valStr);
- else
- str = I18N.SetLanguageValue("BattleOutput_013", timeStr, casterName, sName, targetName, valStr);
- break;
- case OutputType.Shield:
- if(team)
- str = I18N.SetLanguageValue("BattleOutput_006", timeStr, casterName, sName, targetName, valStr);
- else
- str = I18N.SetLanguageValue("BattleOutput_014", timeStr, casterName, sName, targetName, valStr);
- break;
- case OutputType.Disperse:
- if(team)
- str = I18N.SetLanguageValue("BattleOutput_007", timeStr, casterName, sName, targetName, valStr);
- else
- str = I18N.SetLanguageValue("BattleOutput_015", timeStr, casterName, sName, targetName, valStr);
- break;
- case OutputType.Clean:
- if(team)
- str = I18N.SetLanguageValue("BattleOutput_008", timeStr, casterName, sName, targetName, valStr);
- else
- str = I18N.SetLanguageValue("BattleOutput_016", timeStr, casterName, sName, targetName, valStr);
- break;
- case OutputType.Break:
- if(team)
- str = I18N.SetLanguageValue("BattleOutput_009", timeStr, casterName, sName, targetName, valStr);
- else
- str = I18N.SetLanguageValue("BattleOutput_017", timeStr, casterName, sName, targetName, valStr);
- break;
- case OutputType.Vertigo:
- if(team)
- str = I18N.SetLanguageValue("BattleOutput_010", timeStr, casterName, sName, targetName, valStr);
- else
- str = I18N.SetLanguageValue("BattleOutput_018", timeStr, casterName, sName, targetName, valStr);
- break;
- }
- GetOutputText(str);
- string tempStr = "";
- int lastCnt = 0;
- int deltaCnt = 0;
- int cursor = 0;
- for(int idx = 0; idx < mTextInfos.Count;idx++)
- {
- tempStr += mTextInfos[idx].text;
- int cnt = StringUtil.GetStringByteLength(tempStr);
- if(cnt >= 50)
- {
- cursor = idx;
- deltaCnt = 50 - lastCnt;
- break;
- }else
- {
- lastCnt = cnt;
- }
- }
- if(deltaCnt > 0)
- {
- var info = mTextInfos[cursor];
- string temp = StringUtil.CutOutString(info.text, deltaCnt);
- string temp2 = info.text.Replace(temp, "");
- mTextInfos.Insert(cursor,new HrefInfo(info.color, temp));
- cursor++;
- info.text = temp2;
- }
- string str1 = "";
- string str2 = "";
- for(int idx =0; idx < cursor;idx++)
- {
- var info = mTextInfos[idx];
- if (!string.IsNullOrEmpty(info.text))
- {
- if (string.IsNullOrEmpty(info.color))
- {
- str1 += info.text;
- }
- else
- {
- str1 = str1 + string.Format("<color=#{0}>{1}</color>", info.color, info.text);
- }
- }
- }
- for(int idx = cursor; idx < mTextInfos.Count;idx++)
- {
- var info = mTextInfos[idx];
- if(!string.IsNullOrEmpty(info.text))
- {
- if (string.IsNullOrEmpty(info.color))
- {
- str2 += info.text;
- }
- else
- {
- str2 = str2 + string.Format("<color=#{0}>{1}</color>", info.color, info.text);
- }
- }
- }
- if (!string.IsNullOrEmpty(str1))
- {
- if (mOutputList.Count >= MaxNum)
- {
- mOutputList.RemoveAt(0);
- }
- mOutputList.Add(str1);
- }
- if (!string.IsNullOrEmpty(str2))
- {
- if (mOutputList.Count >= MaxNum)
- {
- mOutputList.RemoveAt(0);
- }
- mOutputList.Add(str2);
- }
- NotifyOutput();
- }
- List<HrefInfo> mTextInfos = new List<HrefInfo>();
- Regex s_HrefRegex = new Regex(@"<color=#(.+?)>(.*?)(</color>)", RegexOptions.Singleline);
- protected void GetOutputText(string text)
- {
- mTextInfos.Clear();
- var indexText = 0;
- foreach (Match match in s_HrefRegex.Matches(text))
- {
- var hrefInfo = new HrefInfo(null, text.Substring(indexText, match.Index - indexText));
- mTextInfos.Add(hrefInfo);
- var hrefInfo2 = new HrefInfo(match.Groups[1].Value, match.Groups[2].Value);
- mTextInfos.Add(hrefInfo2);
- indexText = match.Index + match.Length;
- }
- string lastText = text.Substring(indexText, text.Length - indexText);
- if (!string.IsNullOrEmpty(lastText))
- {
- var lastInfo = new HrefInfo(null, lastText);
- mTextInfos.Add(lastInfo);
- }
- }
- private void NotifyOutput()
- {
- BattleMgr.Instance.OnRefreshBattleOutput();
- }
- public void Clean()
- {
- mOutputList.Clear();
- }
- public void Dispose()
- {
- Clean();
- }
- }
|