public ISkillTriger CreateTriger(Dsl.ISyntaxComponent trigerConfig, SkillInstance instance) { ISkillTriger triger = null; string type = trigerConfig.GetId(); ISkillTrigerFactory factory = GetFactory(type); if (null != factory) { try { triger = factory.Create(); triger.Init(trigerConfig, instance); } catch (Exception ex) { GameFramework.LogSystem.Error("triger:{0} line:{1} failed.", trigerConfig.ToScriptString(), trigerConfig.GetLine()); throw ex; } } else { #if !DEBUG GameFramework.LogSystem.Error("CreateTriger failed, type:{0}", type); #endif } if (null != triger) { GameFramework.LogSystem.Debug("CreateTriger, type:{0} triger:{1}", type, triger.GetType().Name); } else { #if !DEBUG GameFramework.LogSystem.Error("CreateTriger failed, type:{0}", type); #endif } return triger; }
public IStoryCommand CreateCommand(Dsl.ISyntaxComponent commandConfig) { lock (m_Lock) { Dsl.CallData callData = commandConfig as Dsl.CallData; if (null != callData) { if (callData.IsHighOrder) { Dsl.CallData innerCall = callData.Call; if (innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD || innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_BRACKET || innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE || innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET || innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_PARENTHESIS) { if (callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PARENTHESIS) { //obj.member(a,b,...) or obj[member](a,b,...) or obj.(member)(a,b,...) or obj.[member](a,b,...) or obj.{member}(a,b,...) -> execinstance(obj,member,a,b,...) Dsl.CallData newCall = new Dsl.CallData(); newCall.Name = new Dsl.ValueData("dotnetexec", Dsl.ValueData.ID_TOKEN); newCall.SetParamClass((int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PARENTHESIS); if (innerCall.IsHighOrder) { newCall.Params.Add(innerCall.Call); newCall.Params.Add(innerCall.GetParam(0)); for (int i = 0; i < callData.GetParamNum(); ++i) { Dsl.ISyntaxComponent p = callData.Params[i]; newCall.Params.Add(p); } } else { newCall.Params.Add(innerCall.Name); newCall.Params.Add(innerCall.GetParam(0)); for (int i = 0; i < callData.GetParamNum(); ++i) { Dsl.ISyntaxComponent p = callData.Params[i]; newCall.Params.Add(p); } } return CreateCommand(newCall); } } } else if (callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_OPERATOR && callData.GetId() == "=") { Dsl.CallData innerCall = callData.GetParam(0) as Dsl.CallData; if (null != innerCall) { //obj.property = val -> setinstance(obj,property,val) Dsl.CallData newCall = new Dsl.CallData(); newCall.Name = new Dsl.ValueData("dotnetset", Dsl.ValueData.ID_TOKEN); newCall.SetParamClass((int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PARENTHESIS); if (innerCall.IsHighOrder) { newCall.Params.Add(innerCall.Call); newCall.Params.Add(innerCall.GetParam(0)); newCall.Params.Add(callData.GetParam(1)); } else { newCall.Params.Add(innerCall.Name); newCall.Params.Add(innerCall.GetParam(0)); newCall.Params.Add(callData.GetParam(1)); } return CreateCommand(newCall); } } } IStoryCommand command = null; string type = commandConfig.GetId(); IStoryCommandFactory factory = GetFactory(type); if (null != factory) { try { command = factory.Create(); command.Init(commandConfig); } catch (Exception ex) { GameFramework.LogSystem.Error("command:{0} line:{1} failed.", commandConfig.ToScriptString(), commandConfig.GetLine()); throw ex; } } else { #if DEBUG string err = string.Format("CreateCommand failed, line:{0} command:{1}", commandConfig.GetLine(), commandConfig.ToScriptString()); throw new Exception(err); #else GameFramework.LogSystem.Error("CreateCommand failed, type:{0} line:{1}", type, commandConfig.GetLine()); #endif } if (null != command) { GameFramework.LogSystem.Debug("CreateCommand, type:{0} command:{1}", type, command.GetType().Name); } else { #if DEBUG string err = string.Format("CreateCommand failed, line:{0} command:{1}", commandConfig.GetLine(), commandConfig.ToScriptString()); throw new Exception(err); #else GameFramework.LogSystem.Error("CreateCommand failed, type:{0} line:{1}", type, commandConfig.GetLine()); #endif } return command; } }
private bool Init(Dsl.FunctionData skill) { bool ret = false; m_UseImpactsForInit = new List<SkillSectionOrMessageTriggers>(); m_ImpactsForInit = new List<SkillSectionOrMessageTriggers>(); m_DamagesForInit = new List<SkillSectionOrMessageTriggers>(); if (null != skill && (skill.GetId() == "skill" || skill.GetId() == "emitskill" || skill.GetId() == "hitskill")) { ret = true; Dsl.CallData callData = skill.Call; if (null != callData && callData.HaveParam()) { m_OuterDslSkillId = int.Parse(callData.GetParamId(0)); m_DslSkillId = m_OuterDslSkillId; } for (int i = 0; i < skill.Statements.Count; i++) { if (skill.Statements[i].GetId() == "section") { m_UseImpactsForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.Section)); m_ImpactsForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.Section)); m_DamagesForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.Section)); Dsl.FunctionData sectionData = skill.Statements[i] as Dsl.FunctionData; if (null != sectionData) { SkillSection section = new SkillSection(); section.Load(sectionData, this); m_Sections.Add(section); } else { #if DEBUG string err = string.Format("Skill {0} DSL, section must be a function ! line:{1} section:{2}", m_DslSkillId, skill.Statements[i].GetLine(), skill.Statements[i].ToScriptString()); throw new Exception(err); #else LogSystem.Error("Skill {0} DSL, section must be a function !", m_DslSkillId); #endif } } else if (skill.Statements[i].GetId() == "onmessage") { m_UseImpactsForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.Message)); m_ImpactsForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.Message)); m_DamagesForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.Message)); Dsl.FunctionData sectionData = skill.Statements[i] as Dsl.FunctionData; if (null != sectionData) { SkillMessageHandler handler = new SkillMessageHandler(); handler.Load(sectionData, this); m_MessageHandlers.Add(handler); } else { #if DEBUG string err = string.Format("Skill {0} DSL, onmessage must be a function ! line:{1} onmessage:{2}", m_DslSkillId, skill.Statements[i].GetLine(), skill.Statements[i].ToScriptString()); throw new Exception(err); #else LogSystem.Error("Skill {0} DSL, onmessage must be a function !", m_DslSkillId); #endif } } else if (skill.Statements[i].GetId() == "onstop") { m_UseImpactsForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.OnStop)); m_ImpactsForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.OnStop)); m_DamagesForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.OnStop)); Dsl.FunctionData sectionData = skill.Statements[i] as Dsl.FunctionData; if (null != sectionData) { m_StopSection = new SkillMessageHandler(); m_StopSection.Load(sectionData, this); } else { #if DEBUG string err = string.Format("Skill {0} DSL, onstop must be a function ! line:{1} onmessage:{2}", m_DslSkillId, skill.Statements[i].GetLine(), skill.Statements[i].ToScriptString()); throw new Exception(err); #else LogSystem.Error("Skill {0} DSL, onstop must be a function !", m_DslSkillId); #endif } } else if (skill.Statements[i].GetId() == "oninterrupt") { m_UseImpactsForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.OnInterrupt)); m_ImpactsForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.OnInterrupt)); m_DamagesForInit.Add(new SkillSectionOrMessageTriggers(SectionOrMessageType.OnInterrupt)); Dsl.FunctionData sectionData = skill.Statements[i] as Dsl.FunctionData; if (null != sectionData) { m_InterruptSection = new SkillMessageHandler(); m_InterruptSection.Load(sectionData, this); } else { #if DEBUG string err = string.Format("Skill {0} DSL, oninterrupt must be a function ! line:{1} onmessage:{2}", m_DslSkillId, skill.Statements[i].GetLine(), skill.Statements[i].ToScriptString()); throw new Exception(err); #else LogSystem.Error("Skill {0} DSL, oninterrupt must be a function !", m_DslSkillId); #endif } } else if (skill.Statements[i].GetId() == "emitskill") { Dsl.FunctionData sectionData = skill.Statements[i] as Dsl.FunctionData; if (null != sectionData) { PrepareInnerEmitSkillInstances(); SkillInstance inst = new SkillInstance(); inst.Init(sectionData); Dsl.CallData header = sectionData.Call; int innerId = 0; if (header.GetParamNum() > 0) { innerId = int.Parse(header.GetParamId(0)); } inst.m_InnerDslSkillId = GenInnerEmitSkillId(innerId); inst.m_OuterDslSkillId = m_DslSkillId; inst.m_DslSkillId = m_DslSkillId; if (!m_EmitSkillInstances.ContainsKey(inst.InnerDslSkillId)) { m_EmitSkillInstances.Add(inst.InnerDslSkillId, inst); } else { #if DEBUG string err = string.Format("Skill {0} DSL, emitskill id duplicate ! line:{1} onmessage:{2}", m_DslSkillId, skill.Statements[i].GetLine(), skill.Statements[i].ToScriptString()); throw new Exception(err); #else LogSystem.Error("Skill {0} DSL, emitskill id duplicate !", m_DslSkillId); #endif } } else { #if DEBUG string err = string.Format("Skill {0} DSL, emitskill must be a function ! line:{1} onmessage:{2}", m_DslSkillId, skill.Statements[i].GetLine(), skill.Statements[i].ToScriptString()); throw new Exception(err); #else LogSystem.Error("Skill {0} DSL, oninterrupt must be a function !", m_DslSkillId); #endif } } else if (skill.Statements[i].GetId() == "hitskill") { Dsl.FunctionData sectionData = skill.Statements[i] as Dsl.FunctionData; if (null != sectionData) { PrepareInnerHitSkillInstances(); SkillInstance inst = new SkillInstance(); inst.Init(sectionData); Dsl.CallData header = sectionData.Call; int innerId = 0; if (header.GetParamNum() > 0) { innerId = int.Parse(header.GetParamId(0)); } inst.m_InnerDslSkillId = GenInnerHitSkillId(innerId); inst.m_OuterDslSkillId = m_DslSkillId; inst.m_DslSkillId = m_DslSkillId; if (!m_HitSkillInstances.ContainsKey(inst.InnerDslSkillId)) { m_HitSkillInstances.Add(inst.InnerDslSkillId, inst); } else { #if DEBUG string err = string.Format("Skill {0} DSL, hitskill id duplicate ! line:{1} onmessage:{2}", m_DslSkillId, skill.Statements[i].GetLine(), skill.Statements[i].ToScriptString()); throw new Exception(err); #else LogSystem.Error("Skill {0} DSL, hitskill id duplicate !", m_DslSkillId); #endif } } else { #if DEBUG string err = string.Format("Skill {0} DSL, hitskill must be a function ! line:{1} onmessage:{2}", m_DslSkillId, skill.Statements[i].GetLine(), skill.Statements[i].ToScriptString()); throw new Exception(err); #else LogSystem.Error("Skill {0} DSL, oninterrupt must be a function !", m_DslSkillId); #endif } } else { #if DEBUG string err = string.Format("SkillInstance::Init, Skill {0} unknown part {1}, line:{2} section:{3}", m_DslSkillId, skill.Statements[i].GetId(), skill.Statements[i].GetLine(), skill.Statements[i].ToScriptString()); throw new Exception(err); #else LogSystem.Error("SkillInstance::Init, Skill {0} unknown part {1}", m_DslSkillId, skill.Statements[i].GetId()); #endif } } } else { #if DEBUG string err = string.Format("SkillInstance::Init, isn't skill DSL, line:{0} skill:{1}", skill.GetLine(), skill.ToScriptString()); throw new Exception(err); #else LogSystem.Error("SkillInstance::Init, isn't skill DSL"); #endif } BuildImpactAndDamageInfo(); LogSystem.Debug("SkillInstance.Init section num:{0} {1} skill {2}", m_Sections.Count, ret, m_DslSkillId); return ret; }