123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- using CommonAI.Data;
- using CommonAI.Zone.Instance;
- using System.Collections.Generic;
- using XmdsCommon.Message;
- using XmdsCommon.Plugin;
- using XmdsCommonServer.Message;
- using XmdsCommonServer.Plugin.Units;
- using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
- namespace XmdsCommonServer.Plugin
- {
- public class XmdsVirtual_Pet : XmdsVirtual
- {
- /// <summary>
- /// 药剂HP恢复.
- /// </summary>
- private XmdsVirtual_Player.ItemRecoveryTask mHPRecoveryTask = new XmdsVirtual_Player.ItemRecoveryTask();
- /// <summary>
- /// 药剂MP恢复.
- /// </summary>
- private XmdsVirtual_Player.ItemRecoveryTask mMPRecoveryTask = new XmdsVirtual_Player.ItemRecoveryTask();
- /// <summary>
- /// 药剂HPMP同时恢复.
- /// </summary>
- private XmdsVirtual_Player.ItemRecoveryTask mHPMPRecoveryTask = new XmdsVirtual_Player.ItemRecoveryTask();
- private XmdsVirtual mMaster = null;
- public XmdsVirtual_Pet(XmdsInstancePet unit) : base(unit)
- {
- }
- public void InitVisibleData(PetBaseInfo info)
- {
- PetVisibleDataB2C data = new PetVisibleDataB2C();
- data.BaseInfo = info;
- mUnit.Level = info.level;
- mUnit.SetVisibleInfo(data);
- }
- public void SetMaster(XmdsVirtual master)
- {
- mMaster = master;
- if (this.mUnit != null)
- {
- (this.mUnit as XmdsInstancePet).SummonerUnit = mMaster.mUnit;
- }
- master.OnHandleCombatChangeEvent += Master_OnHandleCombatChangeEvent;
- //首次需要同步战斗状态.
- Master_OnHandleCombatChangeEvent(master.CombatState);
- }
- private void Master_OnHandleCombatChangeEvent(BattleStatus status)
- {
- (this.mUnit as XmdsInstancePet).OnMasterChangeCombatStatus(status);
- }
- public override string GetPlayerUUID()
- {
- InstanceUnit u = (mUnit as InstancePet).Master;
- if (u != null)
- {
- return ((u.Virtual) as XmdsVirtual).GetPlayerUUID();
- }
- return base.GetPlayerUUID();
- }
- public override int GetForceID()
- {
- InstanceUnit u = (mUnit as InstancePet).Master;
- if (u != null)
- {
- return ((u.Virtual) as XmdsVirtual).GetForceID();
- }
- return base.GetForceID();
- }
- public override string GetGuildID()
- {
- InstanceUnit u = (mUnit as InstancePet).Master;
- if (u != null)
- {
- return ((u.Virtual) as XmdsVirtual).GetGuildID();
- }
- return base.GetGuildID();
- }
- public override int GetServerID()
- {
- InstanceUnit u = (mUnit as InstancePet).Master;
- if (u != null)
- {
- return ((u.Virtual) as XmdsVirtual).GetServerID();
- }
- return base.GetServerID();
- }
- public override PKLevel GetCurPKLevel()
- {
- InstanceUnit u = (mUnit as InstancePet).Master;
- if (u != null)
- {
- return ((u.Virtual) as XmdsVirtual).GetCurPKLevel();
- }
- return base.GetCurPKLevel();
- }
- public override PKMode GetCurPKMode()
- {
- InstanceUnit u = (mUnit as InstancePet).Master;
- if (u != null)
- {
- return ((u.Virtual) as XmdsVirtual).GetCurPKMode();
- }
- return base.GetCurPKMode();
- }
- public override bool IsMember(XmdsVirtual target, PKMode mode, bool includeSelf, bool onlyForTeam)
- {
- if (includeSelf == true && this.mUnit == target.mUnit)
- {
- return true;
- }
- InstanceUnit u = (this.mUnit as InstancePet).SummonerUnit;
- if (u != null)
- {
- XmdsVirtual zv = u.Virtual as XmdsVirtual;
- return zv.IsMember(target, mode, includeSelf, onlyForTeam);
- }
- return base.IsMember(target, mode, includeSelf, onlyForTeam);
- }
- public bool IsMaster(XmdsVirtual target)
- {
- bool ret = false;
- if ((this.mUnit as InstancePet).Master == target.mUnit)
- {
- ret = true;
- }
- return ret;
- }
- public XmdsVirtual GetMaster()
- {
- return mMaster;
- }
- public override uint GetMasterID()
- {
- if(this.mMaster != null)
- {
- return this.mMaster.mUnit.ID;
- }
- return 0;
- }
- public override InstanceUnit GetMasterUnit()
- {
- if (this.mMaster != null)
- {
- return this.mMaster.mUnit;
- }
- return null;
- }
- public override void OnKillUnit(XmdsVirtual dead)
- {
- if (CalPKValue(dead) == true)
- {
- if (dead.IsPlayerUnit() &&
- dead.GetCurPKLevel() == PKLevel.White)
- {
- XmdsInstancePlayer zip = (mUnit as InstancePet).Master as XmdsInstancePlayer;
- if (zip != null)
- {
- (zip.Virtual as XmdsVirtual).OnKillUnit(dead);
- }
- }
- }
- }
- public override void OnHitOthter(XmdsVirtual target)
- {
- if (mHateSystem.ContainsID(target.mUnit.ID) == false)
- {
- mHateSystem.AddTarget(target);
- }
- var zv = GetMaster();
- if (zv != null)
- {
- zv.OnHitOthter(target);
- }
- }
- public override bool IsPlayerUnit()
- {
- bool ret = false;
- InstanceUnit u = (mUnit as InstancePet).Master;
- if (u is XmdsInstancePlayer)
- {
- ret = true;
- }
- return ret;
- }
- public override XmdsVirtual_Player GetPlayerUnit()
- {
- XmdsVirtual_Player ret = null;
- InstanceUnit u = (mUnit as InstancePet).Master;
- if (u != null && u is XmdsInstancePlayer)
- {
- ret = u.Virtual as XmdsVirtual_Player;
- }
- return ret;
- }
- public void UpdateBaseInfo(PetBaseInfo info)
- {
- mUnit.Level = info.level;
- mProp.ServerData.BaseInfo.UnitLv = info.level;
- var p = GetMaster();
- if (p != null)
- {
- //宿主ID.
- info.MasterID = p.mUnit.ID;
- }
- if (this.mUnit.VisibleInfo is PetVisibleDataB2C)
- {
- //服务端数据保存更新.
- PetVisibleDataB2C pvd = this.mUnit.VisibleInfo as PetVisibleDataB2C;
- pvd.BaseInfo = info;
- //推送变更协议.
- PetBaseInfoChangeEventB2C evt = new PetBaseInfoChangeEventB2C();
- evt.BaseInfo = info;
- this.mUnit.queueEvent(evt);
- }
- }
-
- public void UpdatePetProps(XmdsUnitProp prop)
- {
- XmdsUnitPropEventB2C evt = new XmdsUnitPropEventB2C();
- evt.Props = prop;
- OnPlayerPropertiesChanged(evt);
- }
- public void OnReceivePetSkillChangeEventR2B(PetSkillChangeEventR2B evt)
- {
- if (evt != null)
- {
- switch (evt.OperateID)
- {
- case PlayerSkillChangeEventR2B.SkillOperate.Replace:
- this.mSkillHelper.ReplaceSkill(evt.SkillList);
- break;
- case PlayerSkillChangeEventR2B.SkillOperate.Add:
- this.mSkillHelper.AddSkill(evt.SkillList);
- break;
- case PlayerSkillChangeEventR2B.SkillOperate.Remove:
- this.mSkillHelper.RemoveSkill(evt.SkillList);
- break;
- case PlayerSkillChangeEventR2B.SkillOperate.Reset:
- //this.mSkillHelper.ResetSkill(evt.SkillList);
- this.ResetSkill(evt.SkillList);
- break;
- default: break;
- }
- }
- }
- public override void OnUpdateTriggerSkill(int intervalMS, bool slowRefresh)
- {
- UpdateItemRecoveryTask(intervalMS);
- base.OnUpdateTriggerSkill(intervalMS, slowRefresh);
- }
- private void UpdateItemRecoveryTask(int intervalMS)
- {
- mHPRecoveryTask.Update(intervalMS);
- mMPRecoveryTask.Update(intervalMS);
- mHPMPRecoveryTask.Update(intervalMS);
- }
- public void OnRceivePropertyChangeEventR2B(PropertyChangeEventR2B evt)
- {
- FormatLog("OnRceivePropertyChangeOrder", null);
- bool success = false;
- switch (evt.ChangeType)
- {
- case PropertyChangeEventR2B.PropertyChangeType.HP:
- if (evt.Duration > 0)
- {
- mHPMPRecoveryTask.Init(this, evt, true);
- }
- else
- {
- success = AddHP(evt.ChangeValueType, evt.ChangeValue, false);
- }
- break;
- case PropertyChangeEventR2B.PropertyChangeType.NPC:
- if (this.mUnit.CurrentHP != this.mUnit.MaxHP ||
- this.mUnit.CurrentMP != this.mUnit.MaxMP)
- {
- this.AddHP(this.mUnit.MaxHP, null, false);
- this.AddMP(this.mUnit.MaxMP, null, false, true);
- }
- break;
- default: break;
- }
- }
- public void OnReceivePetFollowModeChangeEventR2B(PetFollowModeChangeEventR2B evt)
- {
- SetFollowMode(evt.mode);
- }
- public void SetFollowMode(XmdsCommon.Plugin.XmdsPetConifg.XmdsPetFollowMode mode)
- {
- (this.mUnit as XmdsInstancePet).SetFollowMode(mode);
- }
- //protected override void CombatStateConnect(CombatStateChangeEvent.BattleStatus status, byte reason)
- //{
- // var v = GetMaster();
- // if (v != null)
- // {
- // v.SetCombatState(status, reason);
- // }
- //}
- protected override void Dispose()
- {
- if (mMaster != null)
- {
- mMaster.OnHandleCombatChangeEvent -= Master_OnHandleCombatChangeEvent;
- mMaster = null;
- }
- base.Dispose();
- }
- public override bool IsAttackable(XmdsVirtual attacker)
- {
- var v = GetMaster();
- if (v != null)
- {
- return v.IsAttackable(attacker);
- }
- return base.IsAttackable(attacker);
- }
- public override bool TeamMemberVisible
- {
- get
- {
- if (mMaster != null)
- {
- return (!mMaster.mUnit.IsDead());
- }
- return base.TeamMemberVisible;
- }
- set
- {
- base.TeamMemberVisible = value;
- }
- }
- }
- }
|