| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using IwbZero.Expr;
- using IwbZero.IwbBase;
- using IwbZero.ToolCommon.StringModel;
- using WeEngine.CommonDto;
- using WeEngine.Enum;
- using WeEngine.Message;
- using WeEngine.Strategy.Eval;
- using WeEngine.Strategy.Runner;
- namespace WeEngine.Packages
- {
- /// <summary>
- /// 方案包
- /// </summary>
- public class PackageNode : NodeBase
- {
- public PackageNode()
- {
- EventSwitch = true;
- NodeType = NodeType.ScenePackage;
- WaitForRunNode= new Dictionary<string, List<string>>();
- Variables = DefaultVariable.Variables;
- }
- public bool EventSwitch { get; set; }
- /// <summary>
- /// 目标客户端
- /// </summary>
- public string TargetClientId { get; set; }
- /// <summary>
- /// 模型类型
- /// </summary>
- public string EngineType { get; set; }
- /// <summary>
- /// 评估模块
- /// </summary>
- public IEvalManager EvalManager { get; set; }
-
- /// <summary>
- /// 运行模块
- /// </summary>
- public IRunnerManager RunnerManager { get; set; }
- /// <summary>
- /// 消息发送模块
- /// </summary>
- public IMessageSender MessageSender { get; set; }
-
- /// <summary>
- /// 运行ID
- /// </summary>
- public string RunningId { get; set; }
-
- /// <summary>
- /// 考核角色
- /// </summary>
- public List<string> AssessRoles { get; set; }
- /// <summary>
- /// 未考核分数自动运行(满分)
- /// </summary>
- public bool AssessAuto { get; set; }
- /// <summary>
- /// 自动下一轮
- /// </summary>
- public bool AutoNextRound { get; set; }
- /// <summary>
- /// 每轮总分
- /// </summary>
- public decimal RoundScore { get; set; }
- /// <summary>
- /// 等待运行的节点
- /// </summary>
- public Dictionary<string,List<string>> WaitForRunNode { get; set; }
- /// <summary>
- /// 模块已加载
- /// </summary>
- public bool ModuleHasLoad => EvalManager != null && RunnerManager != null && MessageSender != null;
- /// <summary>
- /// 从运行数据恢复到运行态
- /// </summary>
- /// <param name="running"></param>
- public void ConvertFromRun(RunningInfo running)
- {
- EventSwitch = false;
- RunningId = running.Id;
- NodeState = GetNodeState(running);
- AssessAuto = running.AssessAuto;
- AssessRoles = running.AssessRoles;
- RoundScore = running.RoundScore;
- AutoNextRound = running.AutoNextRound;
- Variables = running.VariableTable;
- WaitPath = running.WaitPath;
- if (HasChild)
- {
- foreach (var nodeBase in Children)
- {
- var child = (SceneRoundNode)nodeBase;
- var runChild = running.RoundInfo.FirstOrDefault(a => a.Path == child.NodePath);
- if (runChild != null)
- {
- child.ConvertFromRun(runChild);
- }
- }
- }
- EventSwitch = true;
- }
- #region CurrentInfo
- public RunningInfo RunningInfo => GetRunningInfo();
- /// <summary>
- /// 当前轮次
- /// </summary>
- public int CurrentRound => CurRoundInfo?.RoundIndex ?? 0;
- /// <summary>
- /// 当前轮次信息
- /// </summary>
- public SceneRoundNode CurRoundInfo => GetCurrentRoundInfo();
- /// <summary>
- /// 当前情景流块
- /// </summary>
- public List<SceneFlowBlockNode> CurSceneFlowBlocks => GetCurrentFlowBlocks();
- /// <summary>
- /// 当前情景流
- /// </summary>
- public List<SceneFlowNode> CurSceneFlows => GetCurrentFlows();
- /// <summary>
- /// 当前流节点
- /// </summary>
- public List<FlowNode> CurFlowNodes => GetCurrentFlowNodes();
- /// <summary>
- /// 当前情景
- /// </summary>
- public List<SceneNode> CurSceneInfos => GetCurrentSceneInfos();
- /// <summary>
- /// 当前行为
- /// </summary>
- public List<BehaviorNode> CurBehaviorInfos => GetCurrentBehaviors();
- /// <summary>
- /// 已运行的行为
- /// </summary>
- public List<BehaviorNode> AllRunnedBehaviorInfos => GetAllRunnedBehaviors();
- /// <summary>
- /// 当前轮次各标签总得分
- /// </summary>
- public Dictionary<string, decimal> BehaviorTagScoreDic => GetBehaviorTagScoreDic();
- /// <summary>
- /// 当前轮次所运行的行为各标签总分
- /// </summary>
- public Dictionary<string, decimal> BehaviorTagFullScoreDic => GetBehaviorTagScoreDic(true);
- /// <summary>
- /// 当前关键字
- /// </summary>
- public List<KeyWord> CurKeyWords => GetCurrentKeyWords();
- /// <summary>
- /// 未匹配的关键字
- /// </summary>
- public List<KeyWord> NotMatchKeyWords => GetNotMatchKeyWords();
- /// <summary>
- /// 获取当前轮次
- /// </summary>
- /// <returns></returns>
- private SceneRoundNode GetCurrentRoundInfo()
- {
- var round = (SceneRoundNode) Children.FirstOrDefault(a => a.NodeState == NodeState.Running) ?? Children
- .Select(a => (SceneRoundNode) a).OrderByDescending(a => a.RoundIndex)
- .FirstOrDefault(a => a.NodeState == NodeState.Complete || a.NodeState == NodeState.RunEnd);
- return round;
- }
- /// <summary>
- /// 获取当前情景流块
- /// </summary>
- /// <returns></returns>
- private List<SceneFlowBlockNode> GetCurrentFlowBlocks()
- {
- var list = new List<SceneFlowBlockNode>();
- var children = CurRoundInfo?.HasChild == true ? CurRoundInfo.Children.Where(a => a.NodeState == NodeState.Running).Select(a => (SceneFlowBlockNode)a).ToList() : new List<SceneFlowBlockNode>();
- list.AddRange(children);
- return list;
- }
- /// <summary>
- /// 获取当前情景流
- /// </summary>
- /// <returns></returns>
- private List<SceneFlowNode> GetCurrentFlows()
- {
- var list = new List<SceneFlowNode>();
- foreach (var cur in CurSceneFlowBlocks)
- {
- var children = cur?.HasChild == true ? cur.Children.Where(a => a.NodeState == NodeState.Running).Select(a => (SceneFlowNode)a).ToList() : new List<SceneFlowNode>();
- list.AddRange(children);
- }
- return list;
- }
- /// <summary>
- /// 获取当前流节点
- /// </summary>
- /// <returns></returns>
- private List<FlowNode> GetCurrentFlowNodes()
- {
- var list = new List<FlowNode>();
- foreach (var cur in CurSceneFlows)
- {
- var flowNode = cur.RunningNode?.NodeState == NodeState.Running ? cur.RunningNode : null;
- if (flowNode != null)
- {
- list.Add(flowNode);
- }
- }
- return list;
- }
-
- /// <summary>
- /// 获取当前情景信息
- /// </summary>
- /// <returns></returns>
- private List<SceneNode> GetCurrentSceneInfos()
- {
- var list = new List<SceneNode>();
- foreach (var cur in CurFlowNodes)
- {
- var children = cur?.SceneInfos.Count >0
- ? cur.SceneInfos.Where(a => a.NodeState == NodeState.Running).Select(a => a)
- .ToList()
- : new List<SceneNode>();
- list.AddRange(children);
- }
- return list;
- }
- /// <summary>
- /// 获取当前行为信息
- /// </summary>
- /// <returns></returns>
- private List<BehaviorNode> GetCurrentBehaviors()
- {
- var list = new List<BehaviorNode>();
- foreach (var cur in CurSceneInfos)
- {
- var children = cur?.HasChild == true ? cur.Children.Select(a => (BehaviorNode)a).ToList() : new List<BehaviorNode>();
- list.AddRange(children);
- }
- return list;
- }
- /// <summary>
- /// 获取已运行的行为信息
- /// </summary>
- /// <returns></returns>
- private List<BehaviorNode> GetAllRunnedBehaviors()
- {
- var list = new List<BehaviorNode>();
- var rounds = HasChild ? Children.Where(a => a.NodeState != NodeState.New).ToList() : null;
- if (rounds==null || !rounds.Any())
- {
- return list;
- }
- List<NodeBase> blocks = new List<NodeBase>();
- foreach (var node in rounds)
- {
- blocks.AddRange(node.HasChild ? node.Children.Where(a => a.NodeState != NodeState.New).ToList() : new List<NodeBase>());
- }
- if (!blocks.Any())
- {
- return list;
- }
- List<NodeBase> flows = new List<NodeBase>();
- foreach (var node in blocks)
- {
- flows.AddRange(node.HasChild ? node.Children.Where(a => a.NodeState != NodeState.New).ToList() : new List<NodeBase>());
- }
- if (!flows.Any())
- {
- return list;
- }
- List<NodeBase> flowNodes = new List<NodeBase>();
- foreach (var node in flows)
- {
- flowNodes.AddRange(node.HasChild ? GetAllRunFlowNodes(node.Children.FirstOrDefault(a => a.NodeState != NodeState.New)) : new List<NodeBase>());
- }
- if (!flowNodes.Any())
- {
- return list;
- }
- List<SceneNode> scenes = new List<SceneNode>();
- foreach (var nodeBase in flowNodes)
- {
- var node = (FlowNode) nodeBase;
- scenes.AddRange(node.HasChild ? node.SceneInfos.Where(a => a.NodeState != NodeState.New).ToList() : new List<SceneNode>());
- }
- if (!scenes.Any())
- {
- return list;
- }
- foreach (var node in scenes)
- {
- list.AddRange(node.HasChild ? node.Children.Where(a => a.NodeState != NodeState.New).Select(a=>(BehaviorNode)a).ToList() : new List<BehaviorNode>());
- }
- return list;
- }
- /// <summary>
- /// 递归获取已运行的流节点
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- private List<NodeBase> GetAllRunFlowNodes(NodeBase node)
- {
- List<NodeBase> flowNodes = new List<NodeBase>();
- if (node == null)
- {
- return flowNodes;
- }
- if (node.NodeType == NodeType.FlowNode)
- {
- flowNodes.Add(node);
- }
- if (node.HasChild)
- {
- flowNodes.AddRange(GetAllRunFlowNodes(node.Children.FirstOrDefault(a => a.NodeState != NodeState.New)));
- }
- return flowNodes;
- }
- /// <summary>
- /// 计算标签的总分
- /// </summary>
- /// <param name="isAll"></param>
- /// <returns></returns>
- private Dictionary<string, decimal> GetBehaviorTagScoreDic(bool isAll = false)
- {
- var dic= new Dictionary<string, decimal>();
- var behaviorInfos = AllRunnedBehaviorInfos?.Where(a => a.BehaviorScoreType != BehaviorScoreType.ImportantNegative).ToList();
- if (behaviorInfos != null&& behaviorInfos.Any())
- {
- foreach(var be in behaviorInfos)
- {
- if(be.BehaviorTagArray!=null&& be.BehaviorTagArray.Any())
- {
- foreach (var tag in be.BehaviorTagArray)
- {
- var score = isAll
- ? be.BehaviorScoreType == BehaviorScoreType.Normal ? be.NodeFullScore : 0
- : be.ActualScore;
- if (dic.ContainsKey(tag))
- {
- var temp = dic[tag];
- dic[tag] = temp + score;
- }
- else
- {
- dic.Add(tag, score);
- }
- }
- }
- }
- }
- return dic;
- }
- /// <summary>
- /// 获取当前关键字
- /// </summary>
- /// <returns></returns>
- private List<KeyWord> GetCurrentKeyWords()
- {
- var list = new List<KeyWord>();
- foreach (var cur in CurBehaviorInfos)
- {
- var children = cur.HasChild
- ? cur.Children.Select(a => (KeyWord)a).ToList()
- : new List<KeyWord>();
- list.AddRange(children);
- }
- return list;
- }
- /// <summary>
- /// 获取未匹配的当前关键字
- /// </summary>
- /// <returns></returns>
- private List<KeyWord> GetNotMatchKeyWords()
- {
- var list = new List<KeyWord>();
- foreach (var cur in CurBehaviorInfos)
- {
- var children = cur.HasChild
- ? cur.Children.Select(a => (KeyWord)a).Where(a => !a.HasMatched).ToList()
- : new List<KeyWord>();
- list.AddRange(children);
- }
- return list;
- }
- #endregion
- #region RUNNING
-
- public RunningInfo GetRunningInfo()
- {
- var running = new RunningInfo(this)
- {
- Id = RunningId,
- CurrentRoundIndex = CurrentRound,
- PackageNo = Id,
- AssessAuto = AssessAuto,
- AssessRoles = AssessRoles,
- RoundScore = RoundScore,
- AutoNextRound= AutoNextRound,
- RoundInfo = new List<RoundRunningInfo>()
- };
- if (Children != null && Children.Any())
- {
- foreach (var child in Children)
- {
- GetRoundRunningInfo((SceneRoundNode)child, running);
- }
- }
- return running;
- }
- public RoundRunningInfo GetRoundRunningInfo(SceneRoundNode node, RunningInfo parent)
- {
- var running = new RoundRunningInfo(node)
- {
- RoundIndex = node.RoundIndex,
- BlockInfo = new List<BlockRunningInfo>()
- };
- if (running.IsStart)
- {
- parent.CurrentRoundIndex = running.RoundIndex;
- }
- if (node.Children != null && node.Children.Any())
- {
- foreach (var child in node.Children)
- {
- GetBlockRunningInfo((SceneFlowBlockNode)child, running);
- }
- }
- parent.RoundInfo.Add(running);
- return running;
- }
- public BlockRunningInfo GetBlockRunningInfo(SceneFlowBlockNode node, RoundRunningInfo parent)
- {
- var running = new BlockRunningInfo(node)
- {
- FlowInfo = new List<FlowRunningInfo>()
- };
- if (node.Children != null && node.Children.Any())
- {
- foreach (var child in node.Children)
- {
- GetFlowRunningInfo((SceneFlowNode)child, running);
- }
- }
- parent.BlockInfo.Add(running);
- return running;
- }
- public FlowRunningInfo GetFlowRunningInfo(SceneFlowNode node, BlockRunningInfo parent)
- {
- var running = new FlowRunningInfo(node)
- {
- NodeInfo = new List<FlowNodeRunningInfo>()
- };
- if (node.Children != null && node.Children.Any())
- {
- foreach (var child in node.Children)
- {
- GetFlowNodeRunningInfo((FlowNode)child, running);
- }
- }
- parent.FlowInfo.Add(running);
- return running;
- }
- public FlowNodeRunningInfo GetFlowNodeRunningInfo(FlowNode node, FlowRunningInfo parent)
- {
- var running = new FlowNodeRunningInfo(node)
- {
- NodeInfo = new List<FlowNodeRunningInfo>(),
- SceneInfo = new List<SceneRunningInfo>()
- };
- if (node.Children != null && node.Children.Any())
- {
- foreach (var child in node.Children)
- {
- GetFlowNodeRunningInfo((FlowNode)child, running);
- }
- }
- if (node.SceneInfos != null && node.SceneInfos.Any())
- {
- foreach (var sceneInfo in node.SceneInfos)
- {
- GetSceneRunningInfo(sceneInfo, running);
- }
- }
- parent.NodeInfo.Add(running);
- return running;
- }
- public FlowNodeRunningInfo GetFlowNodeRunningInfo(FlowNode node, FlowNodeRunningInfo parent)
- {
- var running = new FlowNodeRunningInfo(node)
- {
- NodeInfo = new List<FlowNodeRunningInfo>(),
- SceneInfo = new List<SceneRunningInfo>()
- };
- if (node.Children != null && node.Children.Any())
- {
- foreach (var child in node.Children)
- {
- GetFlowNodeRunningInfo((FlowNode)child, running);
- }
- }
- if (node.SceneInfos != null && node.SceneInfos.Any())
- {
- foreach (var sceneInfo in node.SceneInfos)
- {
- GetSceneRunningInfo(sceneInfo, running);
- }
- }
- parent.NodeInfo.Add(running);
- return running;
- }
- public SceneRunningInfo GetSceneRunningInfo(SceneNode node, FlowNodeRunningInfo parent)
- {
- var running = new SceneRunningInfo(node)
- {
- BehaviorInfo = new List<BehaviorRunningInfo>()
- };
- if (node.Children != null && node.Children.Any())
- {
- foreach (var child in node.Children)
- {
- GetBehaviorRunningInfo((BehaviorNode)child, running);
- }
- }
- parent.SceneInfo.Add(running);
- return running;
- }
- public BehaviorRunningInfo GetBehaviorRunningInfo(BehaviorNode node, SceneRunningInfo parent)
- {
- var running = new BehaviorRunningInfo(node) {KeyWords = node.GetKeyWords()};
- parent.BehaviorInfo.Add(running);
- return running;
- }
- #endregion
- #region override
- public override void SetPreVariables()
- {
- SetVariable(DefaultVariable.RunningId, RunningId);
- base.SetPreVariables();
- }
- protected override void CreateSelfNode(IwbXmlNode xmlNode)
- {
- EventSwitch = true;
- if (xmlNode != null)
- {
- RunningId = xmlNode.GetChildValue("RunningId");
- EngineType = xmlNode.GetChildValue("EngineType");
- AutoNextRound = xmlNode.GetChildValue("AutoNextRound").ValB();
- AssessRoles = xmlNode.GetChildValue("AssessRoles")?.StrToArray()?.ToList() ?? new List<string>();
- AssessAuto = xmlNode.GetChildValue("AssessAuto").ValB();
- RoundScore = xmlNode.GetChildValue("RoundScore").ValD();
- var childNodes = xmlNode.GetChildNode("RoundInfos")?.Nodes;
- if (childNodes != null && childNodes.Count > 0)
- {
- foreach (IwbXmlNode childNode in childNodes)
- {
- var node = (SceneRoundNode)new SceneRoundNode() { Parent = this }.CreateNodeByXmlNode(childNode);
- Children.Add(node);
- }
- }
- }
- }
- public override string ToXmlString()
- {
- return ToXmlStringSelf();
- }
- public string ToXmlStringSelf(bool withHeader = true)
- {
- string str = withHeader ? "<?xml version=\"1.0\" encoding=\"utf-8\"?>" : "";
- str += $"<PackageInfo id=\"{Id}\">\r\n";
- str += RunningId.IsEmpty() ? "" : $"<RunningId>{RunningId}</RunningId>";
- str += base.ToXmlString();
- str += $"<CurrentRound>{CurrentRound}</CurrentRound>\r\n";
- str += $"<AutoNextRound>{AutoNextRound}</AutoNextRound>\r\n";
- str += EngineType.IsEmpty() ? "" : $"<EngineType>{EngineType}</EngineType>\r\n";
- str += AssessRoles == null ? "" : $"<AssessRoles>{AssessRoles?.ToArray().ArrayToStr()}</AssessRoles>\r\n";
- str += $"<AssessAuto>{AssessAuto.ToString().UAndT()}</AssessAuto>\r\n";
- if (Children?.Count > 0)
- {
- str += "<RoundInfos>\r\n";
- foreach (var sceneRound in Children)
- {
- str += sceneRound.ToXmlString();
- }
- str += "</RoundInfos>\r\n";
- }
- str += "</PackageInfo>\r\n";
- return str;
- }
-
- #endregion override
- }
- /// <summary>
- /// 演练轮次
- /// </summary>
- public class SceneRoundNode : NodeBase
- {
- public SceneRoundNode()
- {
- NodeType = NodeType.SceneRound;
-
- }
- /// <summary>
- /// 轮次
- /// </summary>
- public int RoundIndex { get; set; }
- private decimal _roundFullScore;
- /// <summary>
- /// 轮次总分
- /// </summary>
- public decimal RoundFullScore
- {
- get => (HasParent && ((PackageNode) Parent).RoundScore > 0)
- ? ((PackageNode) Parent).RoundScore
- : _roundFullScore;
- set => _roundFullScore = value;
- }
- /// <summary>
- /// 最大情景流数量
- /// </summary>
- public int SceneCount { get; set; }
- private int _controlRate;
- /// <summary>
- /// 随机几率
- /// </summary>
- public int ControlRate
- {
- get => _controlRate;
- set => _controlRate = value > 100 ? 100 : value < 0 ? 0 : value;
- }
- /// <summary>
- /// 获取当前所在的轮次
- /// </summary>
- /// <returns></returns>
- public SceneRoundNode GetSelfRound()
- {
- return this;
- }
- /// <summary>
- /// 是否已选中演化情景流块(一个轮次只能选一个演化情景流块)
- /// </summary>
- public bool EvolutionBlockHasSelected { get; set; }
- /// <summary>
- /// 从运行数据恢复到运行态
- /// </summary>
- /// <param name="running"></param>
- public void ConvertFromRun(RoundRunningInfo running)
- {
- Variables = running.VariableTable;
- WaitPath = running.WaitPath;
- NodeState = GetNodeState(running);
- if (HasChild)
- {
- foreach (var nodeBase in Children)
- {
- var child = (SceneFlowBlockNode)nodeBase;
- var runChild = running.BlockInfo.FirstOrDefault(a => a.Path == child.NodePath);
- if (runChild != null)
- {
- child.ConvertFromRun(runChild);
- }
- }
- }
- }
- #region override
- public override void SetPreVariables()
- {
- SetVariable(DefaultVariable.FullRoundScore, RoundFullScore);
- var score = RoundIndex == 1
- ? new Random(0).Next(0, Convert.ToInt32(NodeFullScore))
- : Parent.Children.Select(a => (SceneRoundNode) a).FirstOrDefault(a => a.RoundIndex == RoundIndex - 1)?
- .ActualScore ?? 0;
- SetVariable(DefaultVariable.PrevNodeScore, score);
- SetVariable(DefaultVariable.RoundScore, score);
- base.SetPreVariables();
- }
- public override void SetRunnedVariables()
- {
- SetVariable(DefaultVariable.RoundScore,ActualScore);
- base.SetRunnedVariables();
- }
- protected override void CreateSelfNode(IwbXmlNode xmlNode)
- {
- if (xmlNode != null)
- {
- RoundIndex = xmlNode.GetChildValue("RoundIndex").ValI();
- SceneCount = xmlNode.GetChildValue("SceneCount").ValI();
- RoundFullScore = xmlNode.GetChildValue("RoundFullScore").ValD();
- ControlRate = xmlNode.GetChildValue("ControlRate").ValI();
- var childNodes = xmlNode.GetChildNode("BlockInfos")?.Nodes;
- if (childNodes != null && childNodes.Count > 0)
- {
- foreach (IwbXmlNode childNode in childNodes)
- {
- var node = (SceneFlowBlockNode)new SceneFlowBlockNode() { Parent = this }.CreateNodeByXmlNode(childNode);
- Children.Add(node);
- }
- }
- }
- }
- public override string ToXmlString()
- {
- string str = "";
- str += $"<RoundInfo id=\"{Id}\">\r\n";
- str += base.ToXmlString();
- str += $"<RoundIndex>{RoundIndex}</RoundIndex>\r\n";
- str += $"<RoundFullScore>{RoundFullScore}</RoundFullScore>\r\n";
- str += $"<SceneCount>{SceneCount}</SceneCount>\r\n";
- str += $"<ControlRate>{ControlRate}</ControlRate>\r\n";
- if (Children?.Count > 0)
- {
- str += "<BlockInfos>\r\n";
- foreach (var flowBlock in Children)
- {
- str += flowBlock.ToXmlString();
- }
- str += "</BlockInfos>\r\n";
- }
- str += "</RoundInfo>\r\n";
- return str;
- }
- #endregion override
- }
- /// <summary>
- /// 情景流块
- /// </summary>
- public class SceneFlowBlockNode : NodeBase
- {
- public SceneFlowBlockNode()
- {
- NodeType = NodeType.SceneFlowBlock;
-
- }
- /// <summary>
- /// 情景流块类型(客观|演化)
- /// </summary>
- public SceneFlowBlockType BlockType { get; set; }
- /// <summary>
- /// 当前轮次
- /// </summary>
- public SceneRoundNode SelfRound => GetSelfRound();
- /// <summary>
- /// 获取当前所在的轮次
- /// </summary>
- /// <returns></returns>
- public SceneRoundNode GetSelfRound()
- {
- return HasParent ? ((SceneRoundNode)Parent).GetSelfRound() : null;
- }
- /// <summary>
- /// 从运行数据恢复到运行态
- /// </summary>
- /// <param name="running"></param>
- public void ConvertFromRun(BlockRunningInfo running)
- {
- Variables = running.VariableTable;
- WaitPath = running.WaitPath;
- NodeState = GetNodeState(running);
- if (HasChild)
- {
- foreach (var nodeBase in Children)
- {
- var child = (SceneFlowNode)nodeBase;
- var runChild = running.FlowInfo.FirstOrDefault(a => a.Path == child.NodePath);
- if (runChild != null)
- {
- child.ConvertFromRun(runChild);
- }
- }
- }
- }
- #region override
- protected override void CreateSelfNode(IwbXmlNode xmlNode)
- {
- if (xmlNode != null)
- {
- BlockType = xmlNode.GetChildValue("FlowBlockType").GetEnumByName<SceneFlowBlockType>();
- var flowNos = xmlNode.GetChildValue("SceneFlowNos")?.StrToArray();
- if (flowNos != null && flowNos.Length > 0)
- {
- foreach (var no in flowNos)
- {
- var id = no;
- var child = new SceneFlowNode() { Parent = this }.CreateFlowById(id);
- child.InternalNo = no;
- Children.Add(child);
- }
- }
- }
- }
- public override string ToXmlString()
- {
- string str = "";
- str += $"<SceneFlowBlock id=\"{Id}\">\r\n";
- str += base.ToXmlString();
- str += $"<FlowBlockType>{BlockType}</FlowBlockType>\r\n";
- if (Children?.Count > 0)
- {
- //str += "<SceneFlows>\r\n";
- //foreach (var sceneFlow in Children)
- //{
- // str += sceneFlow.ToXmlString();
- //}
- //str += "</SceneFlows>\r\n";
- str += $"<SceneFlowNos>{Children.Select(a => $"{a.Id}|{a.InternalNo}").ToArray().ArrayToStr()}</SceneFlowNos>";
- }
- str += "</SceneFlowBlock>\r\n";
- return str;
- }
- #endregion override
- }
- /// <summary>
- /// 情景流
- /// </summary>
- public class SceneFlowNode : NodeBase
- {
- public SceneFlowNode()
- {
- NodeType = NodeType.SceneFlow;
- }
- public FlowNode RunningNode { get; set; }
- /// <summary>
- /// 当前轮次
- /// </summary>
- public SceneRoundNode SelfRound => GetSelfRound();
- /// <summary>
- /// 获取当前所在的轮次
- /// </summary>
- /// <returns></returns>
- public SceneRoundNode GetSelfRound()
- {
- return HasParent ? ((SceneFlowBlockNode)Parent).GetSelfRound() : null;
- }
- /// <summary>
- /// 根据flowId创建情景流
- /// </summary>
- /// <param name="flowId"></param>
- /// <returns></returns>
- public SceneFlowNode CreateFlowById(string flowId)
- {
- var xmlNode= PackageHelper.GetSceneFlowXmlFromFile(CurPackageInfo?.Id ?? "", flowId);
- if (xmlNode != null)
- {
- return (SceneFlowNode)CreateNodeByXmlNode(xmlNode);
- }
- return null;
- }
- /// <summary>
- /// 从运行数据恢复到运行态
- /// </summary>
- /// <param name="running"></param>
- public void ConvertFromRun(FlowRunningInfo running)
- {
- Variables = running.VariableTable;
- NodeState = GetNodeState(running);
- WaitPath = running.WaitPath;
- if (HasChild)
- {
- foreach (var nodeBase in Children)
- {
- var child = (FlowNode)nodeBase;
- var runChild = running.NodeInfo.FirstOrDefault(a => a.Path == child.NodePath);
- if (runChild != null)
- {
- child.ConvertFromRun(runChild);
- }
- }
- }
- }
- #region override
- public override void SetPreVariables()
- {
- SetVariable(DefaultVariable.FullFlowScore, NodeFullScore);
- SetVariable(DefaultVariable.FlowScore, ActualScore);
- base.SetPreVariables();
- }
- protected override void CreateSelfNode(IwbXmlNode xmlNode)
- {
- var childNodes = xmlNode?.GetChildNode("FlowNodes")?.Nodes;
- if (childNodes != null && childNodes.Count > 0)
- {
- foreach (IwbXmlNode childNode in childNodes)
- {
- var node = (FlowNode)new FlowNode() { Parent = this }.CreateNodeByXmlNode(childNode);
- Children.Add(node);
- }
- }
- }
- public override string ToXmlString()
- {
- string str = "";
- str += $"<SceneFlow id=\"{Id}\">\r\n";
- str += base.ToXmlString();
- if (Children?.Count > 0)
- {
- str += "<FlowNodes>\r\n";
- foreach (var node in Children)
- {
- str += node.ToXmlString();
- }
- str += "</FlowNodes>\r\n";
- }
- str += "</SceneFlow>\r\n";
- return str;
- }
- #endregion override
- }
-
- /// <summary>
- /// 情景流节点
- /// </summary>
- public class FlowNode:NodeBase
- {
- public FlowNode()
- {
- NodeType = NodeType.FlowNode;
- SceneInfos= new List<SceneNode>();
- }
- /// <summary>
- /// 节点深度
- /// </summary>
- public int FlowDepth { get; set; }
- /// <summary>
- /// 是否是留根节点
- /// </summary>
- public bool IsFlowRoot { get; set; }
- public string SceneNos { get; set; }
- public string SceneNames { get; set; }
- /// <summary>
- /// 当前轮次
- /// </summary>
- public SceneRoundNode SelfRound => SelfFlow?.SelfRound;
- /// <summary>
- /// 当前情景流
- /// </summary>
- public SceneFlowNode SelfFlow => GetSelfFlow();
- /// <summary>
- /// 情景集合
- /// </summary>
- public List<SceneNode> SceneInfos { get; set; }
- /// <summary>
- /// 情景总权重
- /// </summary>
- public decimal SceneFullWeights => SceneInfos?.Where(a=>a.ChildFullWeights>0).Sum(a => a.Weights) ?? 0;
- /// <summary>
- /// 获取当前所在的情景流
- /// </summary>
- /// <returns></returns>
- public SceneFlowNode GetSelfFlow()
- {
- return Parent.NodeType != NodeType.SceneFlow ? ((FlowNode) Parent).GetSelfFlow() : (SceneFlowNode) Parent;
- }
- /// <summary>
- /// 从运行数据恢复到运行态
- /// </summary>
- /// <param name="running"></param>
- public void ConvertFromRun(FlowNodeRunningInfo running)
- {
- Variables = running.VariableTable;
- NodeState = GetNodeState(running);
- WaitPath = running.WaitPath;
- if (SceneInfos != null && SceneInfos.Any())
- {
- foreach (var sceneInfo in SceneInfos)
- {
- var runChild = running.SceneInfo.FirstOrDefault(a => a.Path == sceneInfo.NodePath);
- if (runChild != null)
- {
- sceneInfo.ConvertFromRun(runChild);
- }
- }
- }
- if (NodeState == NodeState.Running)
- {
- SelfFlow.RunningNode = this;
- }
- else if (HasChild)
- {
- foreach (var nodeBase in Children)
- {
- var child = (FlowNode)nodeBase;
- var runChild = running.NodeInfo.FirstOrDefault(a => a.Path == child.NodePath);
- if (runChild != null)
- {
- child.ConvertFromRun(runChild);
- }
- }
- }
-
- }
- #region override
- public override void SetPreVariables()
- {
- SetVariable(DefaultVariable.FlowNodeScore, ActualScore);
- SetVariable(DefaultVariable.FullFlowScore, SelfFlow.NodeFullScore);
- SetVariable(DefaultVariable.PrevNodeScore, SelfFlow.ActualScore);
- base.SetPreVariables();
- }
- public override void SetRunnedVariables()
- {
- SetVariable(DefaultVariable.FlowNodeScore, ActualScore);
- Parent.SetVariable(DefaultVariable.FlowScore, SelfFlow.ActualScore);
- Parent.SetVariable($"{DefaultVariable.FlowScore}{FlowDepth}", SelfFlow.ActualScore);
- }
- protected override void CreateSelfNode(IwbXmlNode xmlNode)
- {
- IsFlowRoot = Parent.NodeType == NodeType.FlowNode;
- if (xmlNode != null)
- {
- FlowDepth = xmlNode.GetChildValue("").ValI();
- SceneNos = xmlNode.GetChildValue("SceneInfoNos");
- var sceneNos = SceneNos?.StrToArray();
- if (sceneNos != null && sceneNos.Length > 0)
- {
- foreach (var no in sceneNos)
- {
- var nos = no.StrToArray("|");
- var id = nos[0];
- var child = new SceneNode() { Parent = this }.CreateSceneById(id);
- if (nos.Length >1)
- {
- child.InternalNo = nos[1];
- }
- SceneNames = (SceneNames.IsEmpty() ? "" : ",") + child.Name;
- SceneInfos.Add(child);
- }
- }
- var childNodes = xmlNode.GetChildNode("ChildNodes")?.Nodes;
- if (childNodes != null && childNodes.Count > 0)
- {
- foreach (IwbXmlNode childNode in childNodes)
- {
- var node = (FlowNode)new FlowNode() { Parent = this }.CreateNodeByXmlNode(childNode);
- Children.Add(node);
- }
- }
-
- }
- }
- public override string ToXmlString()
- {
- string str = "";
- str += $"<FlowNode id=\"{Id}\">\r\n";
- str += base.ToXmlString();
- str += $"<FlowDepth>{FlowDepth}</FlowDepth>\r\n";
- if (Children?.Count > 0)
- {
- str += "<ChildNodes>";
- foreach (var node in Children)
- {
- str += node.ToXmlString();
- }
- str += "</ChildNodes>\r\n";
- }
- if (SceneInfos?.Count > 0)
- {
- str += $"<SceneInfoNos>{SceneInfos.Select(a => $"{a.Id}|{a.InternalNo}").ToArray().ArrayToStr()}</SceneInfoNos>";
- str += $"<SceneInfoNames>{SceneInfos.Select(a => $"{a.Name}").ToArray().ArrayToStr()}</SceneInfoNames>";
- }
- else
- {
- str += $"<SceneInfoNos>{SceneNos}</SceneInfoNos>";
- str += $"<SceneInfoNames>{SceneNames}</SceneInfoNames>";
- }
- str += "</FlowNode>\r\n";
- return str;
- }
- #endregion override
- }
-
- /// <summary>
- /// 情景信息
- /// </summary>
- public class SceneNode : NodeBase
- {
- public SceneNode()
- {
- NodeType = NodeType.SceneInfo;
- }
- public SceneType SceneType { get; set; }
- /// <summary>
- /// 当前轮次
- /// </summary>
- public SceneRoundNode SelfRound => SelfFlow?.SelfRound;
- /// <summary>
- /// 情景标签
- /// </summary>
- public string SceneTag { get; set; }
- private string _desc;
-
- /// <summary>
- /// 情景信息
- /// </summary>
- public string Description
- {
- get => _desc?.IndexOf(IwbVariableType.Local, StringComparison.Ordinal) >= 0 ? EvalExpr.TransVariable(_desc, GetVariables()) : _desc;
- set => _desc = value;
- }
- /// <summary>
- /// 当前情景流
- /// </summary>
- public SceneFlowNode SelfFlow => GetSelfFlow();
- /// <summary>
- /// 环境渲染码
- /// </summary>
- public List<EnvironmentRender> EnvironResources { get; set; }
- /// <summary>
- /// 触发关键负向行为(true 为0分)
- /// </summary>
- public bool ImportantNegative => CheckImportantNegative();
- /// <summary>
- /// 获取当前所在的情景流
- /// </summary>
- /// <returns></returns>
- public SceneFlowNode GetSelfFlow()
- {
- return HasParent ? ((FlowNode)Parent).GetSelfFlow() : null;
- }
- /// <summary>
- /// 检查是否触发关键性负向行为
- /// </summary>
- /// <returns></returns>
- private bool CheckImportantNegative()
- {
- return HasChild && Children.Select(a=>(BehaviorNode)a).Any(a=>a.ImportantNegative);
- }
- /// <summary>
- /// 从运行数据恢复到运行态
- /// </summary>
- /// <param name="running"></param>
- public void ConvertFromRun(SceneRunningInfo running)
- {
- Variables = running.VariableTable;
- NodeState = GetNodeState(running);
- WaitPath = running.WaitPath;
- if (HasChild)
- {
- foreach (var nodeBase in Children)
- {
- var child = (BehaviorNode)nodeBase;
- var runChild = running.BehaviorInfo.FirstOrDefault(a => a.Path == child.NodePath);
- if (runChild != null)
- {
- child.ConvertFromRun(runChild);
- }
- }
- }
- }
- #region override
- public override void SetRunnedVariables()
- {
- SetVariable(DefaultVariable.SceneScore, ActualScore);
- base.SetRunnedVariables();
- }
- protected override bool CheckChildIsRunning()
- {
- return NodeState == NodeState.Running;
- }
- protected override void CreateSelfNode(IwbXmlNode xmlNode)
- {
- if (xmlNode != null)
- {
- SceneType = xmlNode.GetChildValue("SceneType").GetEnumByName<SceneType>();
- SceneTag = xmlNode.GetChildValue("SceneTag");
- Description = xmlNode.GetChildValue("Description");
- var behaviorNos = xmlNode.GetChildValue("BehaviorNos")?.StrToArray();
- if (behaviorNos != null && behaviorNos.Length > 0)
- {
- foreach (var no in behaviorNos)
- {
- var nos = no.StrToArray("|");
- var id = nos[0];
- var child = new BehaviorNode() { Parent = this }.CreateBehaviorById(id);
- if (nos.Length >= 2)
- {
- child.InternalNo = nos[1];
- }
- Children.Add(child);
- }
- }
- var resourceNos = xmlNode.GetChildValue("EnvironResourceNos")?.StrToArray();
- if (resourceNos != null && resourceNos.Length > 0)
- {
- foreach (var no in resourceNos)
- {
- var nos = no.StrToArray("|");
- var id = nos[0];
- var child = new EnvironmentRender().CreateEnvironmentById(CurPackageInfo?.Id ?? "", id);
- EnvironResources = EnvironResources ?? new List<EnvironmentRender>();
- EnvironResources.Add(child);
- }
- }
- }
- }
- public SceneNode CreateSceneById( string id)
- {
- var xmlNode = PackageHelper.GetSceneXmlFromFile(CurPackageInfo?.Id ?? "", id);
- return (SceneNode) CreateNodeByXmlNode(xmlNode);
- }
- public override string ToXmlString()
- {
- string str = "";
- str += $"<SceneInfo id=\"{Id}\">\r\n";
- str += base.ToXmlString();
- str += $"<SceneType>{SceneType}</SceneType>\r\n";
- str += SceneTag.IsEmpty() ? "" : $"<SceneTag>{SceneTag}</SceneTag>\r\n";
- str += $"<ImportantNegative>{ImportantNegative}</ImportantNegative>\r\n";
- str += $"<Description>{Description}</Description>\r\n";
- if (EnvironResources?.Count > 0)
- {
- str += "<EnvironResourceNos>";
- str += string.Join(",", EnvironResources.Select(a => Id).ToArray());
- //foreach (var render in EnvironResources)
- //{
- // str += render.ToXmlString();
- //}
- str += "</EnvironResourceNos>\r\n";
- }
- if (Children?.Count > 0)
- {
- //str += "<Behaviors>";
- //foreach (var behaviorNode in Children)
- //{
- // str += behaviorNode.ToXmlString();
- //}
- //str += "</Behaviors>\r\n";
- str += $"<BehaviorNos>{Children.Select(a => $"{a.Id}|{a.InternalNo}").ToArray().ArrayToStr()}</BehaviorNos>";
- }
- str += "</SceneInfo>\r\n";
- return str;
- }
- #endregion override
- }
- /// <summary>
- /// 行为节点
- /// </summary>
- public class BehaviorNode : NodeBase
- {
- public BehaviorNode()
- {
- NodeType = NodeType.Behavior;
- }
- public BehaviorNode(string word):this()
- {
- KeyWords = word;
- CreateKeyWord();
- }
- ///// <summary>
- ///// 行为类型
- ///// </summary>
- //public BehaviorType BehaviorType { get; set; }
- /// <summary>
- /// 行为得分类型
- /// </summary>
- public BehaviorScoreType BehaviorScoreType { get; set; }
- /// <summary>
- /// 关键字字符串
- /// </summary>
- public string KeyWords { get; set; }
- /// <summary>
- /// 行为规则
- /// </summary>
- public string Description { get; set; }
- /// <summary>
- /// 行为标签
- /// </summary>
- public string BehaviorTag { get; set; }
- /// <summary>
- /// 行为标签
- /// </summary>
- public string[] BehaviorTagArray => BehaviorTag.StrToArray();
- /// <summary>
- /// 行为角色
- /// </summary>
- public string[] BehaviorRole { get; set; }
- /// <summary>
- /// 行为角色关系
- /// </summary>
- public BehaviorRoleLogicType BehaviorRoleLogic { get; set; }
- /// <summary>
- /// 触发关键负向行为(true 情景为0分)
- /// </summary>
- public bool ImportantNegative => CheckImportantNegative();
- /// <summary>
- /// 环境渲染码
- /// </summary>
- public List<EnvironmentRender> EnvironResources { get; set; }
- /// <summary>
- /// 检查是否触发关键性负向行为
- /// </summary>
- /// <returns></returns>
- private bool CheckImportantNegative()
- {
- return HasChild && BehaviorScoreType==BehaviorScoreType.ImportantNegative && Children.Select(a=>(KeyWord)a).Any(a=>a.HasMatched);
- }
- /// <summary>
- /// 从运行数据恢复到运行态
- /// </summary>
- /// <param name="running"></param>
- public void ConvertFromRun(BehaviorRunningInfo running)
- {
- NodeState = GetNodeState(running);
- WaitPath = running.WaitPath;
- KeyWords = running.KeyWords;
- CreateKeyWord();
- }
- #region override
- protected override bool CheckChildIsRunning()
- {
- return false;
- }
- protected override void CreateSelfNode(IwbXmlNode xmlNode)
- {
- if (xmlNode != null)
- {
- BehaviorScoreType = xmlNode.GetChildValue("ScoreType").GetEnumByName<BehaviorScoreType>();
- BehaviorRoleLogic = xmlNode.GetChildValue("RoleLogic").GetEnumByName<BehaviorRoleLogicType>();
- BehaviorTag = xmlNode.GetChildValue("BehaviorTag");
- Description = xmlNode.GetChildValue("Description");
- KeyWords = xmlNode.GetChildValue("KeyWord");
- CreateKeyWord();
- BehaviorRole = xmlNode.GetChildValue("Role")?.StrToArray() ?? new string[0];
- var resourceNos = xmlNode.GetChildValue("EnvironResourceNos")?.StrToArray();
- if (resourceNos != null && resourceNos.Length > 0)
- {
- foreach (var no in resourceNos)
- {
- var nos = no.StrToArray("|");
- var id = nos[0];
- var child = new EnvironmentRender().CreateEnvironmentById(CurPackageInfo?.Id ?? "", id);
- EnvironResources = EnvironResources ?? new List<EnvironmentRender>();
- EnvironResources.Add(child);
- }
- }
- }
- }
- public BehaviorNode CreateBehaviorById(string id)
- {
- var xmlNode = PackageHelper.GetBehaviorXmlFromFile(CurPackageInfo?.Id ?? "", id);
- return (BehaviorNode)CreateNodeByXmlNode(xmlNode);
- }
- private void CreateKeyWord()
- {
- string wordStr = KeyWords;
- if (KeyWords.StartsWith("[") && KeyWords.EndsWith("]"))
- {
- wordStr = KeyWords.StrToArray()[0];
- }
- var wordArray = wordStr?.StrToArray();
- if (wordArray != null && wordArray.Length > 0)
- {
- Children= new List<NodeBase>();
- foreach (string word in wordArray)
- {
- var kc = new KeyWord(word, this);
- Children.Add(kc);
- }
- }
- }
- public string GetKeyWords()
- {
- var str = "";
- if (HasChild)
- {
- foreach (var keyWord in Children)
- {
- str += (str == "" ? "" : ",") + keyWord.ToXmlString();
- }
- }
- return str;
- }
- public override string ToXmlString()
- {
- string str = "";
- str += $"<Behavior id=\"{Id}\">\r\n";
- str += base.ToXmlString();
- //str += $"<BehaviorType>{BehaviorType}</BehaviorType>\r\n";
- str += $"<ScoreType>{BehaviorScoreType}</ScoreType>\r\n";
- str += BehaviorRole?.Length > 0 ? $"<Role>{BehaviorRole.ArrayToStr()}</Role>\r\n" : "";
- str += $"<RoleLogic>{BehaviorRoleLogic}</RoleLogic>\r\n";
- str += $"<BehaviorTag>{BehaviorTag}</BehaviorTag>\r\n";
- str += $"<Description>{Description}</Description>\r\n";
- if (Children?.Count > 0)
- {
- string str1 = "",str2="";
- foreach (var keyWord in Children)
- {
- str1 += (str1 == "" ? "" : ",") + keyWord.ToXmlString();
- str2 += ((KeyWord)keyWord).MatchWordXmlString();
- }
- str += $"<KeyWord>[{str1}]</KeyWord>\r\n";
- if (str2.IsNotEmpty())
- {
- str += "<MatchWords>";
- str += str2;
- str += "</MatchWords>";
- }
- }
- else
- {
- str += $"<KeyWord>{KeyWords}</KeyWord>\r\n";
- }
- str += "</Behavior>\r\n";
- return str;
- }
- #endregion override
- }
- /// <summary>
- /// 关键字分组
- /// </summary>
- public sealed class KeyWord : NodeBase
- {
- public KeyWord()
- {
- NodeType = NodeType.KeyWord;
- }
- /// <summary>
- /// [aa,bb,ccc]:8:0【关键字:比重:是否匹配】
- /// </summary>
- /// <param name="words"></param>
- public KeyWord(string words) : this()
- {
- Word = words;
- string w = words;
- if (words.StartsWith("[") && words.EndsWith("]"))
- {
- w = words.StrToArray()[0];
- }
- var arr = w.StrToArray(":");
- if (arr.Length == 2)
- {
- Words = arr[0].StrToArray();
- Weights = arr[1].ValD();
- HasMatched = false;
- }
- else if (arr.Length == 3)
- {
- Words = arr[0].StrToArray();
- Weights = arr[1].ValD();
- HasMatched = arr[2].ValB();
- }
- }
- public KeyWord(string words, BehaviorNode parent) : this(words)
- {
- Parent = parent;
- }
- /// <summary>
- /// 行为角色
- /// </summary>
- public string[] Roles => HasParent ? ((BehaviorNode) Parent).BehaviorRole : "".StrToArray();
- /// <summary>
- /// 匹配此关键字的内容
- /// </summary>
- public string MatchWord { get; set; }
- /// <summary>
- /// 是否匹配
- /// </summary>
- public bool HasMatched { get; set; }
- /// <summary>
- /// 关键字信息
- /// </summary>
- public string Word { get; set; }
- /// <summary>
- /// 关键字数组
- /// </summary>
- public string[] Words { get; set; }
- #region override
-
- protected override bool CheckChildIsRunning()
- {
- return false;
- }
-
- public override string ToString()
- {
- return $"[{GetType().Name}]【{Word}】";
- }
- public override string ToXmlString()
- {
- string str = Words?.Length > 0 ? $"[{Words.ArrayToStr()}]:{Weights}:{(HasMatched ? "1" : "0")}" : "";
- return str;
- }
- public string MatchWordXmlString()
- {
- string str = MatchWord.IsEmpty()? "":$"<MatchWord>{ToXmlString()}|{MatchWord}</MatchWord>\r\n";
- return str;
- }
- #endregion override
- }
- /// <summary>
- /// 环境渲染
- /// </summary>
- public class EnvironmentRender
- {
- public string Id { get; set; }
- public string NodePath { get; set; }
- public string ResourceName { get; set; }
- public int ResourceType { get; set; }
- public string ResourcePath { get; set; }
- public string Description { get; set; }
- public string MessageCode { get; set; }
- public EnvironmentRender CreateEnvironmentById(string packageId,string id)
- {
- var xmlNode = PackageHelper.GetEnvironResourceXmlFromFile(packageId, id);
- return CreateNodeByXmlNode(xmlNode);
- }
- public EnvironmentRender CreateNodeByXmlNode(IwbXmlNode xmlNode)
- {
- if (xmlNode != null )
- {
- Id = xmlNode.GetChildValue("Id");
- ResourceName = xmlNode.GetChildValue("ResourceName");
- ResourceType = xmlNode.GetChildValue("ResourceType").ValI();
- ResourcePath = xmlNode.GetChildValue("ResourcePath");
- MessageCode = xmlNode.GetChildValue("MessageCode");
- Description = xmlNode.GetChildValue("Description");
- }
- return this;
- }
- public string ToXmlString()
- {
- string str = "";
- str += $"<Environment id=\"{Id}\">\r\n";
- str += $"<ResourceName>{ResourceName}</ResourceName>\r\n";
- str += $"<ResourceType>{ResourceType}</ResourceType>\r\n";
- str += ResourcePath.IsEmpty() ? "" : $"<ResourcePath>{ResourcePath}</ResourcePath>\r\n";
- str += MessageCode.IsEmpty() ? "" : $"<MessageCode>{MessageCode}</MessageCode>\r\n";
- str += Description.IsEmpty() ? "" : $"<Description>{Description}</Description>\r\n";
- str += $"</Environment>\r\n";
- return str;
- }
- }
- /// <summary>
- /// 引导信息
- /// </summary>
- public class GuideNode
- {
- public string Id { get; set; }
- public string Name { get; set; }
- public string Description { get; set; }
- public bool IsPush { get; set; }
- public int GuideType { get; set; }
- public GuideNode CreateNodeByXmlNode(IwbXmlNode xmlNode)
- {
- if (xmlNode != null)
- {
- Id = xmlNode.GetChildValue("Id");
- Name = xmlNode.GetChildValue("Name");
- Description = xmlNode.GetChildValue("Description");
- GuideType = xmlNode.GetChildValue("GuideType").ValI();
- IsPush = xmlNode.GetChildValue("IsPush").ValB();
- }
- return this;
- }
- public string ToXmlString()
- {
- string str = "";
- str += $"<GuideInfo id=\"{Id}\">\r\n";
- str += $"<Name>{Name}</Name>\r\n";
- str += $"<Desc>{Description}</Desc>\r\n";
- str += $"<IsPush>{IsPush}</IsPush>\r\n";
- str += "</GuideInfo>\r\n";
- return str;
- }
- }
- }
|