| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public enum SummonPositionRule
- {
- Summon_PR_NearCaster = 0,
- Summon_PR_NearTarget = 1,
- Summon_PR_SelfTeam = 2,
- Summon_PR_EnemyTeam = 3,
- }
- public class BaseSkill
- {
- protected SkillData mSkillData;
- protected int mSkillLv = 0;
- int mTypeId = 0;
-
- List<BuffData> mBuffList = new List<BuffData>();
- public List<BuffData> BuffList { get { return mBuffList; } }
- #region Properties
- private int mId;
- public int Id { get { return mId; } }
- public int Level
- {
- get { return mSkillLv; }
- }
- public int SkillTypeID { get { return mTypeId; } set { mTypeId = value; } }
- public string SkillName { get { return mSkillData.skillName; } }
- public int SpCost { get { return mSkillData.spCost; } }
- public bool IsNormalAttack { get { return SkillTypeID == SkillType.NormalAttack; } }
- public bool IsAutoSkill { get { return SkillTypeID >= SkillType.Attack1 && SkillTypeID <= SkillType.Attack4; } }
- public bool IsEnabled { get { return IsValid && Level > 0; } }
- public bool IsValid { get { return mSkillData != null && mSkillData.valid; } }
- //是否为被动技能
- public bool IsPassiveSkill { get { return mSkillData.skillTriggerType == SkillTriggerType.Passive_Trigger; } }
- public bool CanBreak { get { return mSkillData.skillTriggerType == SkillTriggerType.Casting_Sing || mSkillData.skillTriggerType == SkillTriggerType.Continuous_Casting_NoSing || mSkillData.skillTriggerType == SkillTriggerType.Continuous_Casting_Sing; } }
- public SkillData SkillDataInfo { get { return mSkillData; } }
- //是否为多段技能
- public bool IsMultiSkill { get { /*return mSkillData.attackNum > 1;*/ return false; } }
- public string SkillAnimName { get; private set; }
- public string SkillSingAnimName { get; private set; }
- public float SingTotalTime
- {
- get;set;
- }
- public bool IsSingSkill { get; private set; }
- public float Duration { get { return SingTotalTime + mSkillData.preCastingTime + mSkillData.castingTime + mSkillData.postCastingTime; } }
- private List<ValType> mSummonNpcs = null;
- public List<ValType> SummonActors {
- get
- {
- return mSummonNpcs;
- }
- }
- private List<ValType> mSummonBosses = null;
- public List<ValType> SummonBosses
- {
- get { return mSummonBosses; }
- }
-
- private List<Fighter> mSummonActorInsts = null;
- public List<Fighter> SummonActorInsts
- {
- get { return mSummonActorInsts; }
- }
- private bool mbDisposed = false;
- private string mEventFileName;
- private bool mIsEnhance = false;
- public bool IsEnhance
- {
- get { return mIsEnhance; }
- set { mIsEnhance = value; }
- }
- private int mTriggerRate = 100;
- public int TriggerRate
- {
- get { return mTriggerRate; }
- set { mTriggerRate = value; }
- }
- #endregion
- private ProfessionType mJobType;
- private int mJobStage;
- private int mJobBranch;
- public BaseSkill(int id,int level, int skillTypeId,int gender, ProfessionType jobType,int jobStage,int jobBranch)
- {
- mTypeId = skillTypeId;
- mId = id;
- mSkillData = new SkillData(id,level);
- mSkillLv = level;
- mIsEnhance = false;
- mJobType = jobType;
- mJobStage = jobStage;
- mJobBranch = jobBranch;
- LoadBuffData(gender,jobType,jobStage,jobBranch);
- }
- public void SetLevel(int level)
- {
- if (mSkillLv == level) return;
- mSkillLv = level;
- mSkillData = new SkillData(mId, level);
- }
- void LoadBuffData(int gender, ProfessionType jobType, int jobStage, int jobBranch)
- {
- mBuffList.Clear();
- if (mSkillData.buffIds!=null)
- {
- for(int idx =0; idx < mSkillData.buffIds.Length;idx++)
- {
- BuffData buffData = new BuffData(mSkillData.buffIds[idx], gender,jobType,jobStage,jobBranch);
- mBuffList.Add(buffData);
- }
- }
- }
- void ParseExtendBuff()
- {
- for (int idx = 0; idx < mBuffList.Count; idx++)
- {
- BuffData buffData = mBuffList[idx];
- if (buffData.extendBuffs != null)
- {
- for (int jdx = 0; jdx < buffData.extendBuffs.Count; jdx++)
- {
- BattlePrepareManager.Instance.PrecacheBuff(buffData.extendBuffs[jdx].id, (int)(Role_Gender.Male), mJobType, mJobStage, mJobBranch);
- }
- }
- if(buffData.markExtendList != null)
- {
- for(int jdx = 0; jdx < buffData.markExtendList.Count;jdx++)
- {
- BattlePrepareManager.Instance.PrecacheBuff(buffData.markExtendList[jdx].val, (int)(Role_Gender.Male), mJobType, mJobStage, mJobBranch);
- }
- }
- }
- if (mSkillData.triggerBuffs != null && mSkillData.triggerBuffs.Count > 0)
- {
- for (int idx = 0; idx < mSkillData.triggerBuffs.Count; idx++)
- {
- SkillTriggerBuffInfo triggerBuffInfo = mSkillData.triggerBuffs[idx];
- if (triggerBuffInfo.buffId > 0)
- {
- BattlePrepareManager.Instance.PrecacheBuff(triggerBuffInfo.buffId, (int)(Role_Gender.Male), mJobType, mJobStage, mJobBranch);
- }
- }
- }
- if(mSkillData.extendBuffIds != null && mSkillData.extendBuffIds.Count > 0)
- {
- for(int idx =0; idx < mSkillData.extendBuffIds.Count;idx++)
- {
- if(mSkillData.extendBuffIds[idx] > 0)
- {
- BattlePrepareManager.Instance.PrecacheBuff(mSkillData.extendBuffIds[idx], (int)(Role_Gender.Male), mJobType, mJobStage, mJobBranch);
- }
- }
- }
- }
- List<int> effects = new List<int>();
- List<int> bulletActors = new List<int>();
- List<int> buffs = new List<int>();
- List<string> sounds = new List<string>();
- List<string> prefabs = new List<string>();
- void ParseSkillData(Fighter owner)
- {
- for (int i = 0; i < mBuffList.Count; i++)
- {
- BuffData buffData = mBuffList[i];
- if (buffData.ActionFrameEvents == null || buffData.ActionFrameEvents.Length == 0) continue;
- for (int idx = 0; idx < buffData.ActionFrameEvents.Length; idx++)
- {
- SkillActionFrameEvent ev = buffData.ActionFrameEvents[idx];
- switch (ev.eventType)
- {
- case SkillActionFrameEventType.FE_PlaySound:
- {
- string sound = ev.GetStr(Constants.s_skillaction_frame_key_sound);
- if (!string.IsNullOrEmpty(sound) && !sounds.Contains(sound))
- {
- sounds.Add(sound);
- }
- break;
- }
- case SkillActionFrameEventType.FE_PlayEffect:
- case SkillActionFrameEventType.FE_PlayUnscaleTimeEffect:
- {
- int v = ev.GetN(Constants.s_skillaction_frame_key_effect);
- if (v > 0 && !effects.Contains(v))
- effects.Add(v);
- break;
- }
- case SkillActionFrameEventType.FE_PlayEffectEx:
- {
- int v = (int)ev.GetN(Constants.s_skillaction_frame_key_effect);
- if (v > 0 && !effects.Contains(v))
- effects.Add(v);
- break;
- }
- case SkillActionFrameEventType.FE_Hit:
- case SkillActionFrameEventType.FE_Skill_Sing:
- case SkillActionFrameEventType.FE_Repeat_Caster:
- case SkillActionFrameEventType.FE_Delay_Hurt:
- case SkillActionFrameEventType.FE_Bullet:
- {
- SkillActionAttackInfo attackInfo = ev.CreateAttackInfo();
- if (attackInfo != null)
- {
- if (attackInfo.bulletID > 0 && !bulletActors.Contains(attackInfo.bulletID))
- {
- bulletActors.Add(attackInfo.bulletID);
- }
- if (attackInfo.hitEffect > 0 && !effects.Contains(attackInfo.hitEffect))
- {
- effects.Add(attackInfo.hitEffect);
- }
- if (attackInfo.effect > 0 && !effects.Contains(attackInfo.effect))
- {
- effects.Add(attackInfo.effect);
- }
- if (!string.IsNullOrEmpty(attackInfo.sound) && !sounds.Contains(attackInfo.sound))
- {
- sounds.Add(attackInfo.sound);
- }
- if (attackInfo.buffID > 0 && !buffs.Contains(attackInfo.buffID))
- {
- buffs.Add(attackInfo.buffID);
- }
- }
- break;
- }
- case SkillActionFrameEventType.FE_Buff:
- {
- int buffId = ev.GetN(Constants.s_skillaction_frame_key_buffid);
- if (buffId > 0 && !buffs.Contains(buffId))
- buffs.Add(buffId);
- break;
- }
- case SkillActionFrameEventType.FE_Summon:
- {
- int npcPos = ev.GetN(Constants.s_skillaction_frame_key_npcPos);
- int npcId = ev.GetN(Constants.s_skillaction_frame_key_npcId);
- if (mSummonNpcs == null)
- mSummonNpcs = new List<ValType>();
-
- if (npcId > 0)
- {
- ValType val = new ValType(npcId, npcPos);
- mSummonNpcs.Add(val);
- }
- break;
- }
- case SkillActionFrameEventType.FE_Clone:
- {
- int npcPos = ev.GetN(Constants.s_skillaction_frame_key_npcPos);
- int npcId = ev.GetN(Constants.s_skillaction_frame_key_npcId);
- int bornEffectId = ev.GetN(Constants.s_skillaction_frame_key_effect);
- if (bornEffectId > 0 && !effects.Contains(bornEffectId))
- {
- effects.Add(bornEffectId);
- }
- if (owner.IsBoss)
- {
- if (mSummonBosses == null)
- mSummonBosses = new List<ValType>();
- if (npcId > 0)
- {
- ValType val = new ValType(npcId, npcPos);
- mSummonBosses.Add(val);
- }
- }
- else
- {
- if (mSummonNpcs == null)
- mSummonNpcs = new List<ValType>();
- if (npcId > 0)
- {
- ValType val = new ValType(npcId, owner.PositionValue);
- mSummonNpcs.Add(val);
- }
- }
- }
- break;
- case SkillActionFrameEventType.FE_PlayPrefab:
- {
- string prefabName = ev.GetStr(Constants.s_skillaction_frame_key_prefabname);
- if (!string.IsNullOrEmpty(prefabName) && !prefabs.Contains(prefabName))
- prefabs.Add(prefabName);
- string sound = ev.GetStr(Constants.s_skillaction_frame_key_sound);
- if (!string.IsNullOrEmpty(sound) && !sounds.Contains(sound))
- {
- sounds.Add(sound);
- }
- }
- break;
- default:
- break;
- }
- }
- for (int idx = 0; idx < buffData.BuffFunList.Count; idx++)
- {
- var data = buffData.BuffFunList[idx];
- if (data.effectId > 0 && !effects.Contains(data.effectId))
- {
- effects.Add(data.effectId);
- }
- if (data.endeffectId > 0 && !effects.Contains(data.endeffectId))
- {
- effects.Add(data.endeffectId);
- }
- }
- }
- }
- public void Prepare(Fighter owner)
- {
- effects.Clear();
- bulletActors.Clear();
- buffs.Clear();
- sounds.Clear();
- prefabs.Clear();
- ParseExtendBuff();
- ParseSkillData(owner);
- BattlePrepareManager.Instance.PrecacheEffects(effects.ToArray());
- BattlePrepareManager.Instance.PrecacheBullets(bulletActors.ToArray());
- BattlePrepareManager.Instance.PrecacheBuffs(buffs.ToArray(),owner.Gender,owner.ProfType,owner.JobStage,owner.JobBranch);
- BattlePrepareManager.Instance.PrecacheUIPrefabs(prefabs.ToArray());
- MusicMgr.Instance.PreloadFightSound(sounds.ToArray());
- }
- public void Load(int gender, ProfessionType jobType, int jobStage, int jobBranch)
- {
- effects.Clear();
- bulletActors.Clear();
- buffs.Clear();
- sounds.Clear();
- prefabs.Clear();
- ParseExtendBuff();
- ParseSkillData(null);
- BattlePrepareManager.Instance.PrecacheEffects(effects.ToArray());
- BattlePrepareManager.Instance.PrecacheBullets(bulletActors.ToArray());
- BattlePrepareManager.Instance.PrecacheBuffs(buffs.ToArray(), gender,jobType,jobStage,jobBranch);
- BattlePrepareManager.Instance.PrecacheUIPrefabs(prefabs.ToArray());
- MusicMgr.Instance.PreloadFightSound(sounds.ToArray());
- }
- public float GetBuffRate(BuffData buffData)
- {
- if (buffData.rate == 0)
- return 1;
- return buffData.rate;
- }
- public void AddSummonActor (Fighter summon)
- {
- if (mSummonActorInsts == null)
- mSummonActorInsts = new List<Fighter>();
- mSummonActorInsts.Add(summon);
- }
- public void Dispose()
- {
- if (mbDisposed)
- return;
- if (mSkillData != null)
- {
- mSkillData.Dispose();
- mSkillData = null;
- }
- for(int idx =0; idx < mBuffList.Count;idx++)
- {
- mBuffList[idx].Dispose();
- }
- mBuffList.Clear();
- if (mSummonActorInsts != null)
- mSummonActorInsts.Clear();
- mSummonActorInsts = null;
- mbDisposed = true;
- }
- public float GetSkillDist(int professionType)
- {
- if (SkillDataInfo == null) return 0;
- float dist;
- SkillDataInfo.skillDistDic.TryGetValue(professionType, out dist);
- return dist;
- }
- public SkillTriggerBuffInfo GetTriggerBuffByType(BuffTriggerType type)
- {
- if (mSkillData == null) return default(SkillTriggerBuffInfo);
- if (mSkillData.triggerBuffs == null || mSkillData.triggerBuffs.Count == 0) return default(SkillTriggerBuffInfo);
- for(int idx =0; idx < mSkillData.triggerBuffs.Count;idx++)
- {
- if (mSkillData.triggerBuffs[idx].type == type) return mSkillData.triggerBuffs[idx];
- }
- return default(SkillTriggerBuffInfo);
- }
- public bool HasBuff(int buffId)
- {
- if (mSkillData == null) return false;
- if (mSkillData.buffIds == null || mSkillData.buffIds.Length == 0) return false;
- for(int idx =0; idx < mSkillData.buffIds.Length;idx++)
- {
- if (mSkillData.buffIds[idx] == buffId) return true;
- }
- return false;
- }
- public Fighter PopSummonActor(int npcId,int npcPos)
- {
- if (mSummonActorInsts == null)
- return null;
- for(int idx =0; idx < mSummonActorInsts.Count;idx++)
- {
- Fighter f = mSummonActorInsts[idx];
- if(f.Actor.BaseId == npcId && f.PositionValue == npcPos)
- {
- return f;
- }
- }
- return null;
- }
- public JSONObject ToJson()
- {
- JSONObject json = new JSONObject();
- json.Add(mId);
- json.Add(mSkillLv);
- json.Add(mTriggerRate);
- return json;
- }
- }
|