123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- using System;
- using CommonAI.Zone.Helper;
- using CommonAI.Zone.Instance;
- using CommonLang;
- using XmdsCommon.Plugin;
- namespace XmdsCommonServer.Plugin.Scene
- {
- /// <summary>
- /// 由玩家创建的私有位面
- /// </summary>
- public class XmdsPlayerAOI : ObjectAoiStatus
- {
- private readonly InstancePlayer m_owner;
- private readonly InstanceZone m_zone;
- /// <summary>
- /// 玩家自己
- /// </summary>
- public InstancePlayer Owner { get { return m_owner; } }
- bool _canSeeMe = false;
- public override bool CanSeeMe
- {
- get
- {
- return _canSeeMe;
- }
- }
- bool _canSeeOther = false;
- public override bool CanSeeOther
- {
- get
- {
- return _canSeeOther;
- }
- }
- public override bool IsNeedNotifyClient
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// 是否在死亡后退出位面
- /// </summary>
- public bool DeadExit { get; set; }
- /// <summary>
- /// 此次aoi名称
- /// </summary>
- public string AoiName { get; set; }
- /// <summary>
- /// 没有怪物则销毁位面
- /// </summary>
- public bool isDestoryedOnMonsterDead
- {
- get;
- private set;
- }
- /// <summary>
- /// 任务完成则自动退出位面
- /// </summary>
- public string QuestId
- {
- get;
- private set;
- }
- private void onOwnerDead(InstanceUnit unit, InstanceUnit attacker)
- {
- if (DeadExit)
- {
- unit.setAoiStatus(null);
- }
- }
- private void onQuestStatusChanged(InstancePlayer player, string quest, string key, string value)
- {
- if(player == m_owner && quest == QuestId && key == XmdsQuestData.Attribute_SubState && value == "1")
- {
- player.setAoiStatus(null);
- }
- }
- public XmdsPlayerAOI(InstancePlayer player,
- bool can_see_me = false,
- bool can_see_other = false ,
- bool isDestoryedOnMonsterDead = false,
- bool DeadExit = false,
- string QuestId = null)
- {
- this.m_owner = player;
- this.m_zone = player.Parent;
- this._canSeeMe = can_see_me;
- this._canSeeOther = can_see_other;
- this.isDestoryedOnMonsterDead = isDestoryedOnMonsterDead;
- this.DeadExit = DeadExit;
- this.QuestId = QuestId;
- if(!string.IsNullOrEmpty(this.QuestId))
- {
- this.m_zone.OnQuestStatusChanged += onQuestStatusChanged;
- }
- player.OnDead += onOwnerDead;
- }
- protected override void onObjectEnter(InstanceZoneObject o)
- {
- base.onObjectEnter(o);
- }
- protected override void onObjectLeave(InstanceZoneObject o)
- {
- base.onObjectLeave(o);
- if (o == m_owner)
- {
- (o as InstancePlayer).OnDead -= onOwnerDead;
- this.Cleanup();
- }
- if (isDestoryedOnMonsterDead && GetUnitCountByForce(1) == 0)
- {
- m_owner.setAoiStatus(null);
- }
- }
- /// <summary>
- /// 玩家掉线后,干掉所有私有AOI单位
- /// </summary>
- public void Cleanup()
- {
- using(var list = ListObjectPool<InstanceZoneObject>.AllocAutoRelease(base.Objects))
- {
- foreach (var obj in list)
- {
- if (obj != m_owner)
- {
- if(obj is InstancePlayer)
- {
- (obj as InstancePlayer).setAoiStatus(null);
- }
- else
- {
- m_zone.RemoveObjectByID(obj.ID);
- }
- }
- }
- }
- if (!string.IsNullOrEmpty(this.QuestId))
- {
- this.m_zone.OnQuestStatusChanged -= onQuestStatusChanged;
- }
- }
- }
- }
|