public void TryPlaySkill(int id,Ilife user,Ilife lockedTarget = null) { SkillConfig config = ConfigManager.Instance.GetSkillConfig(id); if (null == config) { Debuger.Log("can't load skill id: " + id); return; } //check cd SkillCd cd = null; if (m_CdStore.TryGetValue(id, out cd)) { if (cd.cd > 0) { // can't play skill return; } } if (m_BeginCdStore.TryGetValue(id, out cd)) { if (cd.cd > 0) { // can't play skill return; } } if (m_PlayingSkill.ContainsKey(id)) { //can't play return; } //per handle HandleTarget target = HandleTarget.GetHandleTarget(user); if (LimitMethods.HandleLimitExec(target, config.PerLimitId, null)) { FuncMethods.HandleFuncExec(target, config.PerFuncId, null); m_LockedTargetList.Add(id, lockedTarget); if (config.BeginCd <= 0) { TriggerExecSkill(user, config); } else { if (m_BeginCdStore.ContainsKey(config.Id)) { m_BeginCdStore.Add(config.Id, new SkillCd(config.InitCd, config, user)); } else { m_BeginCdStore[config.Id] = new SkillCd(config.InitCd, config, user); } } } }
public override List <Ilife> GetTargetList(Ilife thisUnit, TargetData data, FuncContext context) { List <Ilife> res = new List <Ilife>(); if (thisUnit == null) { return(res); } Vector3 point = ((ITransformBehaviour)(thisUnit)).GetTransformData().GetPosition(); float r = ((ITransformBehaviour)(thisUnit)).GetTransformData().GetScale().x; var lifeList = LifeManager.GetLifeList(); foreach (var elem in lifeList) { if (elem.Key == thisUnit.GetInstanceId()) { continue; } Ilife otherLifes = elem.Value; Vector3 point1 = ((ITransformBehaviour)(otherLifes)).GetTransformData().GetPosition(); if (Vector3.Distance(point, point1) < r) { // add to target list res.Add(otherLifes); } } return(res); }
virtual public void Initialize(Ilife lifeData, string resourcePath, AssetType resourceType) { m_LifeData = lifeData; m_iInstanceId = lifeData.GetInstanceId(); m_ObjectInstance = GameObject.Instantiate(ResourceManager.Instance.LoadBuildInResource <GameObject>(resourcePath, resourceType)); //load material string localpath = resourcePath.Substring(0, resourcePath.LastIndexOf('/')); m_NormalMaterial = ResourceManager.Instance.LoadBuildInResource <Material>(localpath + "/Normal", AssetType.Char); m_HighlightMaterial = ResourceManager.Instance.LoadBuildInResource <Material>(localpath + "/SelectedHighlight", AssetType.Char); m_MeshRender = ComponentTool.FindChildComponent <SkinnedMeshRenderer>("Body", m_ObjectInstance); if (null == m_NormalMaterial || null == m_HighlightMaterial || null == m_MeshRender) { Debuger.LogWarning("can't load mesh render or normal&highlight materials !"); } //mark transform m_CharContainer = m_ObjectInstance.AddComponent <CharTransformContainer>(); m_CharContainer.Initialize(lifeData.GetInstanceId(), lifeData); if (null == m_ObjectInstance) { Debuger.LogError("Can't load resource " + resourcePath); } m_AnimatorAgent = new AnimatorAgent(m_ObjectInstance); }
virtual public void Initialize(Ilife lifeData, string resourcePath, AssetType resourceType) { m_LifeData = lifeData; m_iInstanceId = lifeData.GetInstanceId(); m_ObjectInstance = GameObject.Instantiate(ResourceManager.Instance.LoadBuildInResource<GameObject>(resourcePath, resourceType)); //load material string localpath = resourcePath.Substring(0, resourcePath.LastIndexOf('/')); m_NormalMaterial = ResourceManager.Instance.LoadBuildInResource<Material>(localpath + "/Normal", AssetType.Char); m_HighlightMaterial = ResourceManager.Instance.LoadBuildInResource<Material>(localpath + "/SelectedHighlight", AssetType.Char); m_MeshRender = ComponentTool.FindChildComponent<SkinnedMeshRenderer>("Body", m_ObjectInstance); if (null == m_NormalMaterial || null == m_HighlightMaterial || null == m_MeshRender) { Debuger.LogWarning("can't load mesh render or normal&highlight materials !"); } //mark transform m_CharContainer = m_ObjectInstance.AddComponent<CharTransformContainer>(); m_CharContainer.Initialize(lifeData.GetInstanceId(), lifeData); if (null == m_ObjectInstance) { Debuger.LogError("Can't load resource " + resourcePath); } m_AnimatorAgent = new AnimatorAgent(m_ObjectInstance); }
public StateMachine(int uid, int registerClientMsgId, Ilife lifeInstance) { m_lifeInstance = lifeInstance; m_nCurrentListenId = registerClientMsgId; MessageDispatcher.Instance.RegistMessage(registerClientMsgId, OnTriggerChangeState); //m_CurrentCharStateConflictMap = ConfigManager.Instance.GetStateConflicMap(uid); }
public override List<Ilife> GetTargetList(Ilife thisUnit, TargetData data, FuncContext context) { List<Ilife> res = new List<Ilife>(); if (thisUnit == null) { return res; } Vector3 point = ((ITransformBehaviour) (thisUnit)).GetTransformData().GetPosition(); float r = ((ITransformBehaviour)(thisUnit)).GetTransformData().GetScale().x; var lifeList = LifeManager.GetLifeList(); foreach (var elem in lifeList) { if (elem.Key == thisUnit.GetInstanceId()) { continue; } Ilife otherLifes = elem.Value; Vector3 point1 = ((ITransformBehaviour)(otherLifes)).GetTransformData().GetPosition(); if (Vector3.Distance(point, point1) < r) { // add to target list res.Add(otherLifes); } } return res; }
public override EBTState Tick() { EBTState res; do { Ilife Owner = m_Database.GetData <Ilife>(EDataBaseKey.Owner); if (null == Owner) { res = EBTState.False; break; } HandleTarget handleTarget = HandleTarget.GetHandleTarget(Owner); if (LimitMethods.HandleLimitExec(handleTarget, m_iLimitId, null)) { res = EBTState.True; break; } res = EBTState.False; } while (false); //mark current status CurrentStatus = res; return(res); }
public StateMachine(int uid,int registerClientMsgId,Ilife lifeInstance ) { m_lifeInstance = lifeInstance; m_nCurrentListenId = registerClientMsgId; MessageDispatcher.Instance.RegistMessage(registerClientMsgId, OnTriggerChangeState); //m_CurrentCharStateConflictMap = ConfigManager.Instance.GetStateConflicMap(uid); }
protected override void OnPlay() { GameObject obj = null; switch (m_Config.EntityType) { case EntityType.Camera: obj = GlobalScripts.Instance.mGameCamera.transform.parent.gameObject; break; case EntityType.Npc: Ilife npc = LifeManager.GetLife(m_Config.CharId); if (null == npc || (!(npc is Npc))) { Debuger.LogError("EntityPlayanim : can't load npc by id " + m_Config.CharId); return; } obj = ((CharTransformData)((Npc)(npc)).GetTransformData()).GetGameObject(); break; case EntityType.Player: if (null == PlayerManager.Instance.GetPlayerInstance()) { Debuger.LogError("EntityPlayanim : can't load npc by id " + m_Config.CharId); return; } obj = ((CharTransformData)(PlayerManager.Instance.GetPlayerInstance().GetTransformData())).GetGameObject(); break; } Animation desAnim = obj.GetComponent <Animation>(); if (null == desAnim) { desAnim = obj.AddComponent <Animation>(); } GameObject animsource = ResourceManager.Instance.LoadBuildInResource <GameObject>("AnimationStore", AssetType.Animation); if (null == animsource) { Debuger.LogError("EntityPlayanim : can't load animation source store"); return; } Animation sourceAnim = animsource.GetComponent <Animation>(); if (null == sourceAnim) { Debuger.LogError("EntityPlayanim : can't load animation source store"); return; } AnimationClip clip = sourceAnim.GetClip(m_Config.AnimName); if (null == clip) { Debuger.LogError("EntityPlayanim : can't load target clip on source anim store"); return; } desAnim.clip = clip; desAnim.Play(); }
private void OnTrigger() { //try get target var param = m_ActionPlayer.GetActionParam(); if (null != param && null != param.Object && param.Object is FuncContext) { FuncContext context = param.Object as FuncContext; Ilife userInstance = context.Get(FuncContext.ContextKey.Target) as Ilife; if (null == userInstance) { return; } m_TargetObj = ((CharTransformData)(((ITransformBehaviour)(userInstance)).GetTransformData())).GetGameObject(); m_EffectObj = EffectContainer.GetInstance(uint.Parse(m_FrameConfig.InstanceId)); m_vTargetPos = m_TargetObj.transform.position; m_fLeftTime = (float)(m_FrameConfig.Time); m_fHigh = (float)(m_FrameConfig.High); m_fInitTime = TimeManager.Instance.GetTime(); m_fLastTime = m_fInitTime; m_fLastVx = Vector3.Distance(m_EffectObj.transform.position, m_vTargetPos) / m_fLeftTime; m_fLastVy = (float)(0.5f * 9.8 * m_fLeftTime); m_vInitPos = m_EffectObj.transform.position; m_vDir = m_vTargetPos - m_vInitPos; m_vDeltaSpace.Normalize(); m_bIsRunning = true; } }
public static HandleTarget GetHandleTarget(Ilife userTarget, List<Ilife> targetList) { HandleTarget instance = new HandleTarget(); instance.m_lstUser.Add(userTarget); instance.m_lstTarget = targetList; return instance; }
public static HandleTarget GetHandleTarget(Ilife userTarget, List <Ilife> targetList) { HandleTarget instance = new HandleTarget(); instance.m_lstUser.Add(userTarget); instance.m_lstTarget = targetList; return(instance); }
public static Ilife GetLife(int id) { Ilife elem = null; if (!m_LifeMap.TryGetValue(id, out elem)) { return(null); } return(elem); }
public static void RegisterLife(int id, Ilife life) { if (m_LifeMap.ContainsKey(id)) { m_LifeMap[id] = life; } else { m_LifeMap.Add(id, life); } }
private void OnTrigger() { if (m_FrameConfig.IsAttach) { // try get attach obj GameObject obj = null; switch (m_FrameConfig.EntityType) { case EntityType.Camera: obj = GlobalScripts.Instance.mGameCamera.transform.parent.gameObject; break; case EntityType.Npc: Ilife npc = LifeManager.GetLife(m_FrameConfig.AttachNpcId); if (null == npc || (!(npc is Npc))) { Debuger.LogError("Play audio : can't load npc by id " + m_FrameConfig.AttachNpcId); return; } obj = ((CharTransformData)((Npc)(npc)).GetTransformData()).GetGameObject(); break; case EntityType.Player: if (null == PlayerManager.Instance.GetPlayerInstance()) { Debuger.LogError("Play audio : can't load player"); return; } obj = ((CharTransformData)(PlayerManager.Instance.GetPlayerInstance().GetTransformData())).GetGameObject(); break; } var objInstance = CreateEffect(); if (null == objInstance) { return; } var root = GetAttachPoint(obj); objInstance.transform.parent = root == null ? null: root.transform; objInstance.transform.localPosition = m_FrameConfig.Pos.GetVector3(); objInstance.transform.localEulerAngles = m_FrameConfig.Rot.GetVector3(); } else { var objInstance = CreateEffect(); if (null == objInstance) { return; } objInstance.transform.position = m_FrameConfig.Pos.GetVector3(); objInstance.transform.eulerAngles = m_FrameConfig.Rot.GetVector3(); } }
public static HandleTarget GetHandleTarget(Ilife userTarget, params Ilife[] targetList) { HandleTarget instance = new HandleTarget(); instance.m_lstUser.Add(userTarget); if (null != targetList) { foreach (Ilife Child in targetList) { instance.m_lstTarget.Add(Child); } } return instance; }
public override EFuncRet FuncExecHandler(HandleTarget Target, FuncData funcdata, FuncContext context) { List<Ilife> target = Target.GetTarget((EFuncTarget) (funcdata.Target)); for (int i = 0; i < target.Count; ++i) { Ilife elem = target[i]; if (!(elem is PlayerCharacter)) { continue; } bool newValue = funcdata.ParamIntList[1] != 0; PlayerManager.Instance.GetCharCounterData().SetFlag(funcdata.ParamIntList[0], newValue); } return EFuncRet.Continue; }
protected override EBTState OnEnter() { Debuger.Log("enter move to player"); Ilife owner = m_Database.GetData <Ilife>(EDataBaseKey.Owner); if (null == owner) { return(EBTState.False); } m_TargetNpc = (Npc)(owner); m_TargetNpc.MoveTo(PlayerManager.Instance.GetPlayerInstance().GetFollowPoint(m_iFollowPintId).transform.position); m_fDeltaTime = 0.0f; return(EBTState.Running); }
private static IState CreateStateInstance(ELifeState stateId, Ilife unit) { if (null == m_StateFactory) { StateDefine.RegisterState(); } IState result = null; Type type = null; if (m_StateFactory.TryGetValue(stateId, out type)) { result = Activator.CreateInstance(type, unit, stateId) as IState; } return(result); }
public static HandleTarget GetHandleTarget(Ilife userTarget, params Ilife[] targetList) { HandleTarget instance = new HandleTarget(); instance.m_lstUser.Add(userTarget); if (null != targetList) { foreach (Ilife Child in targetList) { instance.m_lstTarget.Add(Child); } } return(instance); }
public override EFuncRet FuncExecHandler(HandleTarget Target, FuncData funcdata, FuncContext context) { List <Ilife> target = Target.GetTarget((EFuncTarget)(funcdata.Target)); for (int i = 0; i < target.Count; ++i) { Ilife elem = target[i]; if (!(elem is PlayerCharacter)) { continue; } sbyte newValue = 0; OperationFunc.FuncOperatorValue((EFuncOperator)(funcdata.Oper), ref newValue, (sbyte)(funcdata.ParamIntList[1])); PlayerManager.Instance.GetCharCounterData().SetBit8Count(funcdata.ParamIntList[0], newValue); } return(EFuncRet.Continue); }
protected override EBTState OnEnter() { Ilife owner = m_Database.GetData <Ilife>(EDataBaseKey.Owner); if (null == owner) { return(EBTState.False); } IStateMachineBehaviour state = (IStateMachineBehaviour)(owner); if (!state.GetStateController().TryEnterState(ELifeState.Idle, false)) { return(EBTState.False); } return(EBTState.True); }
// public void Active(bool bActive, Ilife Owner) { if (null == m_Root) { return; } if (bActive) { m_Root.Active(new BTDatabase()); m_Root.Database.SetData <Ilife>(EDataBaseKey.Owner, Owner); m_Root.Database.SetData <bool>(EDataBaseKey.IsLock, false); } else { m_Root.active = false; } }
// public void Active( bool bActive, Ilife Owner ) { if( null == m_Root ) { return; } if( bActive ) { m_Root.Active( new BTDatabase() ); m_Root.Database.SetData<Ilife>(EDataBaseKey.Owner, Owner); m_Root.Database.SetData<bool>(EDataBaseKey.IsLock, false); } else { m_Root.active = false; } }
protected override void Execute() { if (m_FrameConfig.IsAttach) { // try get attach obj GameObject obj = null; switch (m_FrameConfig.EntityType) { case EntityType.Camera: obj = GlobalScripts.Instance.mGameCamera.transform.parent.gameObject; break; case EntityType.Npc: Ilife npc = LifeManager.GetLife(m_FrameConfig.AttachNpcId); if (null == npc || (!(npc is Npc))) { Debuger.LogError("Play audio : can't load npc by id " + m_FrameConfig.AttachNpcId); return; } obj = ((CharTransformData)((Npc)(npc)).GetTransformData()).GetGameObject(); break; case EntityType.Player: if (null == PlayerManager.Instance.GetPlayerInstance()) { Debuger.LogError("Play audio : can't load player"); return; } obj = ((CharTransformData)(PlayerManager.Instance.GetPlayerInstance().GetTransformData())).GetGameObject(); break; } AudioPlayer.Instance.PlayAudio(m_FrameConfig.AudioSource, obj.transform, m_FrameConfig.IsLoop); } else { AudioPlayer.Instance.PlayAudio(m_FrameConfig.AudioSource, m_FrameConfig.PlayPosition.GetVector3(), m_FrameConfig.IsLoop); } }
private void TriggerExecSkill(Ilife user, SkillConfig config) { bool isLockedTarget = m_LockedTargetList.ContainsKey(config.Id) && m_LockedTargetList[config.Id] != null; //add to playing list m_PlayingSkill.Add(config.Id, config); // play animation FuncContext context = FuncContext.Create(); if (!isLockedTarget) { context.Put(FuncContext.ContextKey.TargetId, config.TargeteId); } else { context.Put(FuncContext.ContextKey.Target, m_LockedTargetList[config.Id]); } context.Put(FuncContext.ContextKey.User, user); context.Put(FuncContext.ContextKey.LimitId, config.LimitId); context.Put(FuncContext.ContextKey.FunctionId, config.FuncId); ActionParam param = new ActionParam(); param.Id = config.Id; param.Object = context; ActionManager.Instance.PlayAction(config.ActionId, param); if (m_CdStore.ContainsKey(config.Id)) { m_CdStore.Add(config.Id, new SkillCd(config.InitCd)); } else { m_CdStore[config.Id] = new SkillCd(config.InitCd); } }
private void OnTrigger() { //try get target var param = m_ActionPlayer.GetActionParam(); if (null != param && null != param.Object && param.Object is FuncContext) { FuncContext context = param.Object as FuncContext; if (!context.ContainsKey(FuncContext.ContextKey.LimitId) || !context.ContainsKey(FuncContext.ContextKey.FunctionId)) { return; } int limitId = (int)(context.Get(FuncContext.ContextKey.LimitId)); int funcId = (int)(context.Get(FuncContext.ContextKey.LimitId)); HandleTarget target = null; Ilife user = context.Get(FuncContext.ContextKey.User) as Ilife; if (context.ContainsKey(FuncContext.ContextKey.Target)) { //locked skill target = HandleTarget.GetHandleTarget(user, context.Get(FuncContext.ContextKey.Target) as Ilife); } else { //target is null,unlocked skill int targetId = (int)(context.Get(FuncContext.ContextKey.TargetId)); target = TargetMethods.GetTargetList(user, targetId, null); } //exec attack if (LimitMethods.HandleLimitExec(target, limitId, null)) { FuncMethods.HandleFuncExec(target, funcId, null); } } }
public static HandleTarget GetTargetList(Ilife srcLife, int iTargetGroupId, FuncContext context) { HandleTarget handle = HandleTarget.GetHandleTarget(srcLife); if (iTargetGroupId == 0) { return(handle); } TargetGroup targetGroup = ConfigManager.Instance.GetTargetGroup(iTargetGroupId); if (null == targetGroup) { Debug.LogError("target groupId:" + iTargetGroupId + " is not found."); return(handle); } if (null == targetGroup.TargetDataList || 0 == targetGroup.TargetDataList.Count) { Debug.LogError("target groupId:" + iTargetGroupId + " targetDataList is null."); return(handle); } TargetMethodBase handler = null; foreach (TargetData data in targetGroup.TargetDataList) { if (!TargetExec.TryGetValue(data.TargetId, out handler)) { continue; } List <Ilife> targetUnitList = handler.GetTargetList(srcLife, data, context); handle.AddTarget(targetUnitList); } return(handle); }
private void TriggerExecSkill(Ilife user,SkillConfig config) { bool isLockedTarget = m_LockedTargetList.ContainsKey(config.Id) && m_LockedTargetList[config.Id] != null; //add to playing list m_PlayingSkill.Add(config.Id, config); // play animation FuncContext context = FuncContext.Create(); if (!isLockedTarget) { context.Put(FuncContext.ContextKey.TargetId, config.TargeteId); } else { context.Put(FuncContext.ContextKey.Target, m_LockedTargetList[config.Id]); } context.Put(FuncContext.ContextKey.User, user); context.Put(FuncContext.ContextKey.LimitId, config.LimitId); context.Put(FuncContext.ContextKey.FunctionId, config.FuncId); ActionParam param = new ActionParam(); param.Id = config.Id; param.Object = context; ActionManager.Instance.PlayAction(config.ActionId, param); if (m_CdStore.ContainsKey(config.Id)) { m_CdStore.Add(config.Id, new SkillCd(config.InitCd)); } else { m_CdStore[config.Id] = new SkillCd(config.InitCd); } }
public SkillCd(int cd,SkillConfig config,Ilife user) { this.cd = cd; this.config = config; this.user = user; }
public IState(Ilife unit, ELifeState state) { this.unit = unit; this.state = state; }
private static IState CreateStateInstance(ELifeState stateId, Ilife unit) { if (null == m_StateFactory) { StateDefine.RegisterState(); } IState result = null; Type type = null; if (m_StateFactory.TryGetValue(stateId, out type)) { result = Activator.CreateInstance(type, unit,stateId) as IState; } return result; }
public void TryPlaySkill(int id, Ilife user, Ilife lockedTarget = null) { SkillConfig config = ConfigManager.Instance.GetSkillConfig(id); if (null == config) { Debuger.Log("can't load skill id: " + id); return; } //check cd SkillCd cd = null; if (m_CdStore.TryGetValue(id, out cd)) { if (cd.cd > 0) { // can't play skill return; } } if (m_BeginCdStore.TryGetValue(id, out cd)) { if (cd.cd > 0) { // can't play skill return; } } if (m_PlayingSkill.ContainsKey(id)) { //can't play return; } //per handle HandleTarget target = HandleTarget.GetHandleTarget(user); if (LimitMethods.HandleLimitExec(target, config.PerLimitId, null)) { FuncMethods.HandleFuncExec(target, config.PerFuncId, null); m_LockedTargetList.Add(id, lockedTarget); if (config.BeginCd <= 0) { TriggerExecSkill(user, config); } else { if (m_BeginCdStore.ContainsKey(config.Id)) { m_BeginCdStore.Add(config.Id, new SkillCd(config.InitCd, config, user)); } else { m_BeginCdStore[config.Id] = new SkillCd(config.InitCd, config, user); } } } }
public IState(Ilife unit,ELifeState state) { this.unit = unit; this.state = state; }
public StateIdle(Ilife unit, ELifeState state) : base(unit, state) { }
public void Initialize(int id, Ilife data) { m_iId = id; m_Data = data; }
public StateMove(Ilife unit, ELifeState state) : base(unit, state) { }
public StateRun(Ilife unit, ELifeState state) : base(unit, state) { }
public static HandleTarget GetTargetList(Ilife srcLife, int iTargetGroupId, FuncContext context) { HandleTarget handle = HandleTarget.GetHandleTarget(srcLife); if (iTargetGroupId == 0) { return handle; } TargetGroup targetGroup = ConfigManager.Instance.GetTargetGroup(iTargetGroupId); if (null == targetGroup) { Debug.LogError("target groupId:" + iTargetGroupId + " is not found."); return handle; } if (null == targetGroup.TargetDataList || 0 == targetGroup.TargetDataList.Count) { Debug.LogError("target groupId:" + iTargetGroupId + " targetDataList is null."); return handle; } TargetMethodBase handler = null; foreach (TargetData data in targetGroup.TargetDataList) { if (!TargetExec.TryGetValue(data.TargetId,out handler)) { continue; } List<Ilife> targetUnitList = handler.GetTargetList(srcLife, data,context); handle.AddTarget(targetUnitList); } return handle; }
public override List <Ilife> GetTargetList(Ilife thisUnit, TargetData data, FuncContext context) { return(null); }
public abstract List<Ilife> GetTargetList(Ilife thisUnit, TargetData data, FuncContext context);
public override List<Ilife> GetTargetList(Ilife thisUnit, TargetData data, FuncContext context) { return null; }
public SkillCd(int cd, SkillConfig config, Ilife user) { this.cd = cd; this.config = config; this.user = user; }
public abstract List <Ilife> GetTargetList(Ilife thisUnit, TargetData data, FuncContext context);