示例#1
0
 //当Obj进入场景前,(Obj还没有进入场景,他的Scene是空)这里只可以写场景逻辑(例如改个坐标),不可以同步数据
 public override void OnObjBeforeEnterScene(ObjBase obj)
 {
     if (obj.GetObjType() == ObjType.PLAYER)
     {
         (obj as ObjPlayer).SetPosition(RelivePos.Range());
     }
 }
示例#2
0
        //public override void Init(ulong characterId, int dataId)
        //{
        //    base.Init(characterId, dataId);

        //}

        //输出成一个objdata用于客户端创建
        public ObjData DumpObjData(ObjDropItem _this, ReasonType reason)
        {
            var data = ObjBase.GetImpl().DumpObjData(_this, reason);

            data.Pos = Utility.MakePositionDataByPosAndDir(_this.OrginPos, _this.GetDirection());
            var span = DateTime.Now - _this.mDropTime;

            data.Owner = new Uint64Array();
            data.Owner.Items.AddRange(_this.OwnerList);
            data.ExtData.Add(60 - span.Seconds); //temp
            data.TargetPos.Add(new Vector2Int32
            {
                x = Utility.MultiplyPrecision(_this.GetPosition().X),
                y = Utility.MultiplyPrecision(_this.GetPosition().Y)
            });
            if (DateTime.Now.GetDiffSeconds(_this.mDropTime) > ObjDropItem.DROP_TIME)
            {
                data.ExtData.Add(0);
            }
            else
            {
                data.ExtData.Add(1);
            }
            return(data);
        }
示例#3
0
 public override void OnNpcDamage(ObjNPC npc, int damage, ObjBase enemy)
 {
     base.OnNpcDamage(npc, damage, enemy);
     if (npc.GetObjType() == ObjType.NPC)
     {
         DamageAddChicken(npc);
     }
 }
示例#4
0
        public override bool IsColliderObj(ObjBase obj)
        {
            var newx = mDir.Y * (obj.GetPosition().X - mCenter.X) - mDir.X * (obj.GetPosition().Y - mCenter.Y);
            var newy = mDir.X * (obj.GetPosition().X - mCenter.X) + mDir.Y * (obj.GetPosition().Y - mCenter.Y);

            return((newy > -mHalfLength) && (newy < mHalfLength) &&
                   (newx > -mHalfWidth) && (newx < mHalfWidth));
        }
示例#5
0
 //当Obj进入场景前,(Obj还没有进入场景,他的Scene是空)这里只可以写场景逻辑(例如改个坐标),不可以同步数据
 public override void OnObjBeforeEnterScene(ObjBase obj)
 {
     //变身
     if (obj.GetObjType() == ObjType.PLAYER)
     {
         var player = obj as ObjPlayer;
         player.AddBuff(1206 + player.TypeId, 1, player);
     }
 }
示例#6
0
 //设置坐标
 public void SetPosition(ObjBase _this, Vector2 p)
 {
     //if (float.IsNaN(p.X))
     //{
     //    Logger.Error("SetPosition ");
     //    throw new Exception("SetPosition ");
     //}
     _this.mPosition = p;
 }
示例#7
0
        public bool IsColliderObj(OrientedBox _this, ObjBase obj)
        {
            var newx = _this.mDir.Y * (obj.GetPosition().X - _this.mCenter.X) -
                       _this.mDir.X * (obj.GetPosition().Y - _this.mCenter.Y);
            var newy = _this.mDir.X * (obj.GetPosition().X - _this.mCenter.X) +
                       _this.mDir.Y * (obj.GetPosition().Y - _this.mCenter.Y);

            return((newy > -_this.mHalfLength) && (newy < _this.mHalfLength) &&
                   (newx > -_this.mHalfWidth) && (newx < _this.mHalfWidth));
        }
示例#8
0
        public bool IsColliderObj(CircleShape _this, ObjBase obj)
        {
            var dif = _this.Pos - obj.GetPosition();

            if (dif.LengthSquared() > _this.mRadius * _this.mRadius)
            {
                return(false);
            }
            return(true);
        }
示例#9
0
        public virtual bool LeaveScene(Scene _this, ObjBase obj, ReasonType reason = ReasonType.VisibilityChanged)
        {
            if (_this.mTicking)
            {
                _this.mNeedToRemoveObjDict.Add(obj.ObjId, obj);
                obj.Active = false;
                return(true);
            }

            var zone = obj.Zone;

            if (null != zone)
            {
                obj.BroadcastDestroyMe(reason);
                zone.RemoveObj(obj);
                //Uint64Array array = new Uint64Array();
                //array.Items.Add(obj.ObjId);
                //SceneServer.Instance.ServerControl.DeleteObj(zone.EnumAllVisiblePlayerIdExclude(obj.ObjId), array, (uint)reason);
            }
            obj.SetZone(null);
            if (obj.IsCharacter())
            {
                var character = obj as ObjCharacter;
                character.ClearRetinue();
                foreach (var pair in _this.mAreaDict)
                {
                    if (pair.Value.Cantains(character))
                    {
                        pair.Value.Remove(character);
                    }
                }

                if (obj.GetObjType() == ObjType.PLAYER)
                {
                    _this.OnPlayerLeave(obj as ObjPlayer);
                }
                else if (obj.GetObjType() == ObjType.NPC)
                {
                    if (_this.SpeMonsterToWorldBossId.ContainsKey(obj))
                    {
                        Log(_this, Logger, "Special monster killed!Type = {0}", obj.TypeId);
                        var worldBossId = _this.SpeMonsterToWorldBossId[obj];
                        --_this.SpeMonsterAlwaysRecords[worldBossId];
                        _this.SpeMonsterToWorldBossId.Remove(obj);
                    }
                }
            }


            obj.LeavelScene();
            _this.RemoveObj(obj);

            return(true);
        }
示例#10
0
        public override void OnObjBeforeEnterScene(ObjBase obj)
        {
            if (ObjType.PLAYER != obj.GetObjType())
            {
                return;
            }

            var player = obj as ObjPlayer;

            FixPostion(player);
        }
示例#11
0
 public void RemoveObj(Zone _this, ObjBase obj)
 {
     if (_this.mObjDict.ContainsKey(obj.ObjId))
     {
         _this.mObjDict.Remove(obj.ObjId);
         if (obj.GetObjType() == ObjType.PLAYER)
         {
             MarkDirty(_this);
         }
     }
 }
示例#12
0
        public ObjData DumpObjData(ObjBase _this, ReasonType reason)
        {
            var data = new ObjData
            {
                ObjId  = _this.ObjId,
                Type   = (int)_this.GetObjType(),
                DataId = _this.TypeId,
                Pos    = Utility.MakePositionDataByPosAndDir(_this.GetPosition(), _this.GetDirection()),
                Reason = (uint)reason
            };

            return(data);
        }
示例#13
0
        public override void OnObjBeforeEnterScene(ObjBase obj)
        {
            var player = obj as ObjPlayer;

            if (null == player)
            {
                return;
            }

            if (!PlayerReliveTime.ContainsKey(player.ObjId))
            {
                PlayerReliveTime.Add(player.ObjId, StaticVariable.ReliveTimeInit);
            }
        }
示例#14
0
        public IEnumerable <ulong> EnumAllVisiblePlayerIdExclude(ObjBase _this,
                                                                 ulong excludeId = TypeDefine.INVALID_ULONG)
        {
            if (_this.Zone == null)
            {
                Logger.Warn("EnumAllVisiblePlayerIdExclude has null zone.");
                return(ObjBase.sEmtpyIdList);
            }

            if (TypeDefine.INVALID_ULONG == excludeId)
            {
                return(_this.Zone.EnumAllVisiblePlayerId());
            }
            return(_this.Zone.EnumAllVisiblePlayerIdExclude(excludeId));
        }
示例#15
0
 public void AddObj(Zone _this, ObjBase obj)
 {
     if (!_this.mObjDict.ContainsKey(obj.ObjId))
     {
         _this.mObjDict.Add(obj.ObjId, obj);
         if (obj.GetObjType() == ObjType.PLAYER)
         {
             MarkDirty(_this);
         }
     }
     else
     {
         Logger.Fatal("mObjDict has same key[0]", obj.ObjId);
     }
 }
示例#16
0
 public void NotifyCharactersToSyncMe(ObjBase _this, IEnumerable <ulong> players)
 {
     //             if (Scene == null)
     //             {
     //                 return;
     //             }
     //             foreach (var id in players)
     //             {
     //                 var player = Scene.FindPlayer(id);
     //                 if (player != null)
     //                 {
     //                     player.RegisterCharacterSyncData(this);
     //                 }
     //             }
 }
示例#17
0
        public override bool LeaveScene(ObjBase obj, ReasonType reason = ReasonType.VisibilityChanged)
        {
            if (mPhaseRequirementDic.ContainsKey(EnterPhaseRequireType.AllMonsterDie) && obj.GetObjType() == ObjType.NPC &&
                mPlayerDict.Count > 0)
            {
                var p      = mPlayerDict.First().Value;
                var camp   = p.GetCamp();
                var tbCamp = Table.GetCamp(camp);
                var count  = mObjDict.Values.Count(o =>
                {
                    var npc = o as ObjNPC;
                    return(npc != null && tbCamp.Camp[npc.GetCamp()] == 1);
                });
                if (count == 1)
                {
                    AccomplishPhaseRequire(EnterPhaseRequireType.AllMonsterDie, 0);
                }
            }

            return(base.LeaveScene(obj, reason));
        }
示例#18
0
        //角色增加广播
        public virtual void BroadcastCreateMe(ObjBase _this, ReasonType reason = ReasonType.VisibilityChanged)
        {
            if (null == _this.Zone)
            {
                return;
            }
            var data = _this.DumpObjData(reason);

            if (ObjBase.BroadcastCreateObjType == 1)
            {
                _this.Zone.PushCreateObj(data);
                return;
            }
            var msg2Other = new CreateObjMsg();

            msg2Other.Data.Add(data);
            var list = _this.EnumAllVisiblePlayerIdExclude(_this.ObjId).ToArray();

            SceneServer.Instance.ServerControl.CreateObj(list, msg2Other);
            _this.NotifyCharactersToSyncMe(list);
        }
示例#19
0
        //角色删除广播
        public virtual void BroadcastDestroyMe(ObjBase _this, ReasonType reason = ReasonType.VisibilityChanged)
        {
            if (null == _this.Zone)
            {
                return;
            }
            if (ObjBase.BroadcastDeleteObjType == 1)
            {
                _this.Zone.PushDeleteObj(new DeleteObjMsg
                {
                    ObjId  = _this.ObjId,
                    reason = (int)reason
                });
                return;
            }
            var array = new Uint64Array();

            array.Items.Add(_this.ObjId);
            var list = _this.EnumAllVisiblePlayerIdExclude(_this.ObjId).ToArray();

            _this.NotifyCharactersToStopSyncMe(list);
            SceneServer.Instance.ServerControl.DeleteObj(list, array, (uint)reason);
        }
示例#20
0
        public bool IsColliderObj(FanShape _this, ObjBase obj)
        {
            var dif = obj.GetPosition() - _this.Pos;

            var l = dif.LengthSquared();

            if (l > _this.mRadius * _this.mRadius)
            {
                return(false);
            }

            // 如果两个点基本重合,也算命中了
            if (l < 4.0f)
            {
                return(true);
            }

            dif.Normalize();
            if (Vector2.Dot(_this.mDir, dif) < Math.Cos((float)Math.PI * _this.mRegree / 2 / 180))
            {
                return(false);
            }
            return(true);
        }
示例#21
0
 public bool EnterScene(LeaverScene _this, ObjBase obj)
 {
     _this.AddObj(obj);
     obj.EnterScene(_this);
     return(true);
 }
示例#22
0
 public void RemoveObj(ObjBase obj)
 {
     mImpl.RemoveObj(this, obj);
 }
示例#23
0
 public void AddObj(ObjBase obj)
 {
     mImpl.AddObj(this, obj);
 }
示例#24
0
        public override void OnObjBeforeEnterScene(ObjBase obj)
        {
            var player = obj as ObjPlayer;

            if (player == null)
            {
                return;
            }

            if (mIsInit == false)
            {
                Init();
                mIsInit = true;
            }

            var teamId = player.mDbData.P1vP1CharacterId;
            var flag   = -1;

            for (var i = 0; i < 2; i++)
            {
                var team = mTeams[i];
                if (team == ulong.MaxValue)
                {
                    flag      = i;
                    mTeams[i] = teamId;
                    break;
                }
                if (team == teamId)
                {
                    flag = i;
                    break;
                }
            }

            if (flag == -1)
            {
                Logger.Error("OnPlayerEnter Error CharacterId = {0},TeamId = {1}", player.ObjId, teamId);
                return;
            }

            var teamPlayers = mPlayers[flag];

            if (teamPlayers.Keys.Contains(player.ObjId))
            {
                teamPlayers[player.ObjId] = player;
            }
            else
            {
                teamPlayers.Add(player.ObjId, player);
                FixPostion(player);

                if (player.IsDead())
                {
                    player.Relive();
                }
                else
                {
                    player.Attr.SetDataValue(eAttributeType.HpNow, player.Attr.GetDataValue(eAttributeType.HpMax));
                    player.Attr.SetDataValue(eAttributeType.MpNow, player.Attr.GetDataValue(eAttributeType.MpMax));
                }
            }
            var newCamp = 4 + flag;

            player.SetCamp(newCamp);
            var pos = Utility.MakeVectorMultiplyPrecision(player.GetPosition().X, player.GetPosition().Y);

            player.Proxy.NotifyCampChange(newCamp, pos);
        }
示例#25
0
        public override void OnObjBeforeEnterScene(ObjBase obj)
        {
            var type = obj.GetObjType();

            if (type != ObjType.PLAYER)
            {
                return;
            }

            var player = obj as ObjPlayer;

            if (null == player)
            {
                return;
            }

            //设置camp
            var allianceId = player.GetAllianceId();
            var idx        = AllianceIds.IndexOf(allianceId);
            var campId     = DefenderCampId + idx;

            if (!Camps.ContainsKey(campId))
            {
                //潜规则camp = -1,表示要把他踢掉,人已满
                player.SetCamp(-1);
                Logger.Fatal("OnObjBeforeEnterScene  Name[{0}] CampId=[{1}]", player.GetName(), campId);
                return;
            }

            var camp = Camps[campId];

            if (camp.Players.Count >= Constants.AllianceMaxPlayer)
            {
                //潜规则camp = -1,表示要把他踢掉,人已满
                player.SetCamp(-1);
                return;
            }


            player.SetCamp(campId);
            player.SetPosition(camp.AppearPos);
            camp.Players.Add(player);

            var position = player.GetPosition();
            var pos      = Utility.MakeVectorMultiplyPrecision(position.X, position.Y);

            player.Proxy.NotifyCampChange(campId, pos);

            //恢复满血满蓝
            if (player.IsDead())
            {
                player.Relive();
            }
            else
            {
                player.Attr.SetDataValue(eAttributeType.HpNow, player.Attr.GetDataValue(eAttributeType.HpMax));
                player.Attr.SetDataValue(eAttributeType.MpNow, player.Attr.GetDataValue(eAttributeType.MpMax));
            }

            if (!PlayerReliveTime.ContainsKey(player.ObjId))
            {
                PlayerReliveTime.Add(player.ObjId, StaticVariable.ReliveTimeInit);
            }
        }
示例#26
0
 public override bool LeaveScene(ObjBase obj, ReasonType reason = ReasonType.VisibilityChanged)
 {
     return(mImpl.LeaveScene(this, obj, reason));
 }
示例#27
0
 public override bool EnterScene(ObjBase obj)
 {
     return(mImpl.EnterScene(this, obj));
 }
示例#28
0
 public virtual bool EnterScene(ObjBase obj)
 {
     return(mImpl.EnterScene(this, obj));
 }
示例#29
0
        public override void OnObjBeforeEnterScene(ObjBase obj)
        {
            var player = obj as ObjPlayer;

            if (player == null)
            {
                return;
            }

            var campId = player.mDbData.P1vP1CharacterId;
            var flag   = -1;

            for (var i = 0; i < CampCount; i++)
            {
                var c = Camps[i];
                if (c.UUID == ulong.MaxValue)
                {
                    flag   = i;
                    c.UUID = campId;
                    break;
                }
                if (c.UUID == campId)
                {
                    flag = i;
                    break;
                }
            }

            if (flag == -1)
            {
                Logger.Error("OnPlayerEnter Error CharacterId = {0}, CampId = {1}", player.ObjId, campId);
                return;
            }

            //设置阵营
            var newCamp = CampBegin + flag;

            player.SetCamp(newCamp);

            var camp        = Camps[flag];
            var teamPlayers = camp.Players;

            if (teamPlayers.Keys.Contains(player.ObjId))
            {
                teamPlayers[player.ObjId] = player;
            }
            else
            {
                teamPlayers.Add(player.ObjId, player);
                FixPostion(player);

                if (player.IsDead())
                {
                    player.Relive();
                }
                else
                {
                    player.Attr.SetDataValue(eAttributeType.HpNow, player.Attr.GetDataValue(eAttributeType.HpMax));
                    player.Attr.SetDataValue(eAttributeType.MpNow, player.Attr.GetDataValue(eAttributeType.MpMax));
                }
            }

            var position = player.GetPosition();
            var pos      = Utility.MakeVectorMultiplyPrecision(position.X, position.Y);

            player.Proxy.NotifyCampChange(newCamp, pos);
        }
示例#30
0
 public bool LeaveScene(LeaverScene _this, ObjBase obj, ReasonType reason = ReasonType.VisibilityChanged)
 {
     obj.LeavelScene();
     _this.RemoveObj(obj);
     return(true);
 }