Пример #1
0
        public void InitTriggerArea(TriggerArea _this, int id, Scene scene)
        {
            _this.Id    = id;
            _this.Scene = scene;

            _this.TableTriggerArea = Table.GetTriggerArea(_this.Id);
            if (null != _this.TableTriggerArea)
            {
                if (0 == _this.TableTriggerArea.AreaType)
                {
//0是陷阱那种(会重复发生),1是开门那种(只发生一次,触发条件在这个区域里描述不了)
                    _this.mBuffId    = _this.TableTriggerArea.Param[0];                          //buff id
                    _this.mBuffLevel = _this.TableTriggerArea.Param[1];                          //buff 等级
                    _this.mBuffIntervalMilliseconds = Math.Max(_this.mBuffIntervalMilliseconds,
                                                               _this.TableTriggerArea.Param[2]); //最小时间间隔
                    var tableId = _this.TableTriggerArea.Param[3];
                    if (tableId != -1)
                    {
                        var skillUpgrade = Table.GetSkillUpgrading(tableId);
                        if (null != skillUpgrade)
                        {
                            _this.mCamps = new List <int>(skillUpgrade.Values);
                        }
                    }
                }
                _this.TirggerRadiusSqrt = _this.TableTriggerArea.Radius * _this.TableTriggerArea.Radius;
            }
        }
Пример #2
0
        public bool IsInArea(TriggerArea _this, Vector2 pos)
        {
            var distance =
                new Vector2(pos.X - _this.TableTriggerArea.PosX, pos.Y - _this.TableTriggerArea.PosZ).LengthSquared();

            return(distance <= _this.TirggerRadiusSqrt);
        }
Пример #3
0
        private void Add(TriggerArea _this, ObjCharacter character)
        {
            if (null == character)
            {
                return;
            }

            if (!_this.mCharacterList.Contains(character))
            {
                _this.mCharacterList.Add(character);

                try
                {
                    _this.Scene.OnCharacterEnterArea(_this.Id, character);
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Scene.OnCharacterEnterArea");
                }
            }
            else
            {
                Logger.Warn("TriggerArea mObjDict has this");
            }

            if (character.GetObjType() == ObjType.PLAYER)
            {
                if (!_this.mPlayer.Contains(character))
                {
                    _this.mPlayer.Add(character as ObjPlayer);
                }
            }
        }
Пример #4
0
 public void AdjustPlayer(TriggerArea _this, ObjCharacter player)
 {
     if (IsInArea(_this, player.GetPosition()))
     {
         if (!_this.mCharacterList.Contains(player))
         {
             Add(_this, player);
         }
     }
     else
     {
         if (_this.mCharacterList.Contains(player))
         {
             Remove(_this, player);
         }
     }
 }
Пример #5
0
        private void OnTriggerAreaPlayersChanged(TriggerArea area)
        {
            if (State != eDungeonState.Start && State != eDungeonState.ExtraTime)
            {
                return;
            }

            var tbTriggerArea = area.TableTriggerArea;

            if (tbTriggerArea.AreaType != (int)eTriggerAreaType.Strongpoint)
            {
                return;
            }

            var camps      = new Dictionary <int, int>();
            var characters = area.mCharacterList;
            var tip        = Utils.WrapDictionaryId(300940);

            foreach (var character in characters)
            {
                var player = character as ObjPlayer;
                if (player != null && !player.IsDead())
                {
                    var campId = player.GetCamp();
                    if (Camps[campId].Step != 1)
                    {
                        //打掉防御塔后获得据点争夺权
                        player.Proxy.NotifyBattleReminder(14, tip, 1);
                        continue;
                    }
                    if (campId >= DefenderCampId && campId <= Offensiver2CampId)
                    {
                        camps[campId] = 1;
                    }
                    else
                    {
                        Logger.Error("side = {0}, error! player id = {1}, name = {2}", campId, player.ObjId,
                                     player.GetName());
                    }
                }
            }
        }
Пример #6
0
        public void Tick(TriggerArea _this, float delta)
        {
            try
            {
                _this.Scene.OnAreaTick(_this.Id, _this.mCharacterList.GetEnumerator());
            }
            catch (Exception e)
            {
                Logger.Error(e, "Scene.OnAreaTick");
            }

            if (_this.mPlayer.Count > 0 && _this.mTriggerTime < DateTime.Now)
            {
                if (-1 != _this.mBuffId && _this.mBuffLevel >= 0)
                {
                    _this.mTriggerTime = DateTime.Now.AddMilliseconds(_this.mBuffIntervalMilliseconds);
                    foreach (var player in _this.mPlayer)
                    {
                        if (null != _this.mCamps)
                        {
                            if (!_this.mCamps.Contains(player.GetCamp()))
                            {
                                continue;
                            }
                        }
                        player.AddBuff(_this.mBuffId, _this.mBuffLevel, player);
                    }

                    if (null != _this.TableTriggerArea && null != _this.Scene &&
                        -1 != _this.TableTriggerArea.ClientAnimation)
                    {
                        SceneServer.Instance.ServerControl.NotifySceneAction(_this.Scene.EnumAllPlayerId(),
                                                                             _this.TableTriggerArea.ClientAnimation);
                    }
                }
            }
        }
Пример #7
0
        public void Remove(TriggerArea _this, ObjCharacter character)
        {
            if (character.GetObjType() == ObjType.PLAYER)
            {
                _this.mPlayer.Remove(character as ObjPlayer);
            }

            if (_this.mCharacterList.Contains(character))
            {
                _this.mCharacterList.Remove(character);
                try
                {
                    _this.Scene.OnCharacterLeaveArea(_this.Id, character);
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Scene.OnCharacterLeaveArea");
                }
            }
            else
            {
                Logger.Warn("TriggerArea mObjDict doesn't has this");
            }
        }
Пример #8
0
        private void OnTriggerAreaPlayersChanged(TriggerArea area)
        {
            var tbTriggerArea = area.TableTriggerArea;

            if (tbTriggerArea.AreaType != (int)eTriggerAreaType.Strongpoint)
            {
                return;
            }

            int[] sides      = { 0, 0 };
            var   characters = area.mCharacterList;

            foreach (var character in characters)
            {
                var player = character as ObjPlayer;
                if (player != null && !player.IsDead())
                {
                    var s = GetPlayerSide(player);
                    if (s >= 0 && s <= 1)
                    {
                        sides[s] = 1;
                    }
                    else
                    {
                        Logger.Error("side = {0}, error! player id = {1}, name = {2}", s, player.ObjId, player.GetName());
                    }
                }
            }

            var idx         = tbTriggerArea.Param[0];
            var strongpoint = Strongpoints[idx];
            var count       = sides.Count(i => i == 1);

            if (count != 1)
            {
                switch (strongpoint.State)
                {
                case eStrongpointState.Idle:
                case eStrongpointState.Occupied:
                    break;

                case eStrongpointState.Occupying:
                    if (count == 0)
                    {
                        strongpoint.FightingSide = -1;
                        strongpoint.OccupyTimer  = 0;
                        SetStrongpointState(idx, eStrongpointState.Idle);
                    }
                    else
                    {
                        SetStrongpointState(idx, eStrongpointState.OccupyWait);
                    }
                    break;

                case eStrongpointState.OccupyWait:
                    if (count == 0)
                    {
                        strongpoint.FightingSide = -1;
                        strongpoint.OccupyTimer  = 0;
                        SetStrongpointState(idx, eStrongpointState.Idle);
                    }
                    break;
                }
                return;
            }

            //如果只有一波人在据点内,则继续检查
            var side = sides[0] == 1 ? 0 : 1;

            if (strongpoint.OwnerSide == side)
            {
                if (strongpoint.FightingSide != -1)
                {
                    strongpoint.FightingSide = -1;
                    strongpoint.OccupyTimer  = 0;
                    SetStrongpointState(idx, eStrongpointState.Idle);
                }
                return;
            }
            if (strongpoint.FightingSide == side && strongpoint.State == eStrongpointState.Occupying)
            {
                return;
            }

            if (strongpoint.FightingSide != side)
            {
                strongpoint.FightingSide = side;
                strongpoint.OccupyTimer  = 0;
            }
            SetStrongpointState(idx, eStrongpointState.Occupying);
        }
Пример #9
0
        private void OnTriggerAreaPlayersChanged(TriggerArea area)
        {
            if (State != eDungeonState.Start && State != eDungeonState.ExtraTime)
            {
                return;
            }

            var tbTriggerArea = area.TableTriggerArea;

            if (tbTriggerArea.AreaType != (int)eTriggerAreaType.Strongpoint)
            {
                return;
            }

            var camps      = new Dictionary <int, int>();
            var characters = area.mCharacterList;
            var tip        = Utils.WrapDictionaryId(300940);

            foreach (var character in characters)
            {
                var player = character as ObjPlayer;
                if (player != null && !player.IsDead())
                {
                    var campId = player.GetCamp();
                    if (Camps[campId].Step != 1)
                    {
                        //打掉防御塔后获得据点争夺权
                        player.Proxy.NotifyBattleReminder(14, tip, 1);
                        continue;
                    }
                    if (campId >= DefenderCampId && campId <= Offensiver2CampId)
                    {
                        camps[campId] = 1;
                    }
                    else
                    {
                        Logger.Error("side = {0}, error! player id = {1}, name = {2}", campId, player.ObjId,
                                     player.GetName());
                    }
                }
            }

            var now   = DateTime.Now;
            var idx   = tbTriggerArea.Param[0];
            var sp    = StrongPoints[idx];
            var count = camps.Count;

            switch (sp.State)
            {
            case eStrongpointState.Idle:
                if (count == 1)
                {
                    var camp = camps.First(c => c.Value == 1).Key;
                    if (sp.OccupiedCamp == camp)
                    {
                        return;
                    }
                    sp.OccupyingCamp = camp;
                    StartTimer(sp, now.AddSeconds(OccupyTime), () =>
                    {
                        SetStrongpointState(sp, eStrongpointState.Occupied, camp);
                        SetStrongpointCamp(sp, sp.OccupyingCamp);
                        sp.OccupyingCamp = -1;
                    });
                    SetStrongpointState(sp, eStrongpointState.Occupying, camp);
                }
                break;

            case eStrongpointState.Occupied:
                if (count == 1)
                {
                    var camp = camps.First(c => c.Value == 1).Key;
                    if (sp.OccupiedCamp == camp)
                    {
                        return;
                    }
                    sp.OccupyingCamp = camp;
                    StartTimer(sp, now.AddSeconds(OccupyTime), () =>
                    {
                        SetStrongpointState(sp, eStrongpointState.Occupied, camp);
                        SetStrongpointCamp(sp, sp.OccupyingCamp);
                        sp.OccupyingCamp = -1;
                    });
                    SetStrongpointState(sp, eStrongpointState.Occupying, camp);
                }
                else if (count == 2)
                {
                    if (sp.OccupiedCamp != -1 && camps.ContainsKey(sp.OccupiedCamp))
                    {
                        return;
                    }
                    StartTimer(sp, now.AddSeconds(OccupyTime), () =>
                    {
                        SetStrongpointState(sp, eStrongpointState.Idle, sp.OccupiedCamp);
                        SetStrongpointCamp(sp, -1);
                    });
                    SetStrongpointState(sp, eStrongpointState.Contending, sp.OccupiedCamp);
                }
                break;

            case eStrongpointState.Occupying:
                if (count == 0 || count == 3)
                {
                    sp.OccupyingCamp = -1;
                    CloseTimer(sp);
                    SetStrongpointState(sp,
                                        sp.OccupiedCamp == -1 ? eStrongpointState.Idle : eStrongpointState.Occupied, sp.OccupiedCamp);
                }
                else if (count == 2)
                {
                    if (sp.OccupiedCamp != -1)
                    {
                        if (camps.ContainsKey(sp.OccupiedCamp))
                        {
                            sp.OccupyingCamp = -1;
                            CloseTimer(sp);
                            SetStrongpointState(sp, eStrongpointState.Occupied, sp.OccupiedCamp);
                        }
                        else
                        {
                            sp.OccupyingCamp = -1;
                            StartTimer(sp, now.AddSeconds(OccupyTime), () =>
                            {
                                SetStrongpointState(sp, eStrongpointState.Idle, -1);
                                SetStrongpointCamp(sp, -1);
                            });
                            SetStrongpointState(sp, eStrongpointState.Contending, sp.OccupiedCamp);
                        }
                    }
                    else
                    {
                        CloseTimer(sp);
                        SetStrongpointState(sp, eStrongpointState.Idle, sp.OccupiedCamp);
                    }
                }
                break;

            case eStrongpointState.Contending:
                if (count == 0 || count == 3)
                {
                    CloseTimer(sp);
                    SetStrongpointState(sp,
                                        sp.OccupiedCamp == -1 ? eStrongpointState.Idle : eStrongpointState.Occupied, sp.OccupiedCamp);
                }
                else if (count == 1)
                {
                    var camp = camps.First(c => c.Value == 1).Key;
                    if (camp == sp.OccupiedCamp)
                    {
                        CloseTimer(sp);
                        SetStrongpointState(sp, eStrongpointState.Occupied, camp);
                    }
                    else
                    {
                        sp.OccupyingCamp = camp;
                        StartTimer(sp, now.AddSeconds(OccupyTime), () =>
                        {
                            SetStrongpointState(sp, eStrongpointState.Occupied, camp);
                            SetStrongpointCamp(sp, sp.OccupyingCamp);
                            sp.OccupyingCamp = -1;
                        });
                        SetStrongpointState(sp, eStrongpointState.Occupying, camp);
                    }
                }
                else if (count == 2)
                {
                }
                break;
            }
        }
Пример #10
0
 public void Destroy(TriggerArea _this)
 {
 }
Пример #11
0
 public bool Cantains(TriggerArea _this, ObjCharacter character)
 {
     return(_this.mCharacterList.Contains(character));
 }