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); }
//当Obj进入场景前,(Obj还没有进入场景,他的Scene是空)这里只可以写场景逻辑(例如改个坐标),不可以同步数据 public override void OnObjBeforeEnterScene(ObjBase obj) { if (obj.GetObjType() == ObjType.PLAYER) { (obj as ObjPlayer).SetPosition(RelivePos.Range()); } }
//当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); } }
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); } } }
public override void OnObjBeforeEnterScene(ObjBase obj) { if (ObjType.PLAYER != obj.GetObjType()) { return; } var player = obj as ObjPlayer; FixPostion(player); }
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); }
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); } }
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)); }
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); } }
public virtual bool EnterScene(Scene _this, ObjBase obj) { if (_this.mTicking) { _this.mNeedToAddObjDict.Add(obj.ObjId, obj); return(true); } _this.OnObjBeforeEnterScene(obj); var zoneId = _this.Pos2ZoneId(obj.GetPosition().X, obj.GetPosition().Y); if (zoneId < 0 || zoneId >= _this.mZoneList.Count) { //这里保证一下Character进入的位置必须得是个有效的位置 if (obj.IsCharacter()) { var character = obj as ObjCharacter; var validPos = _this.FindNearestValidPosition(character.GetPosition()); if (null != validPos) { character.SetPosition(validPos.Value); Logger.Warn("[{0}] set valid pos[{1},{2}]", character.GetName(), character.GetPosition().X, character.GetPosition().Y); } else { character.SetPosition((float)_this.TableSceneData.Entry_x, (float)_this.TableSceneData.Entry_z); Logger.Warn("[{0}] set entry pos[{1},{2}]", character.GetName(), character.GetPosition().X, character.GetPosition().Y); } } zoneId = _this.Pos2ZoneId(obj.GetPosition().X, obj.GetPosition().Y); if (zoneId < 0 || zoneId >= _this.mZoneList.Count) { Logger.Fatal("zone = null[x={0},y={1}]", obj.GetPosition().X, obj.GetPosition().Y); return(false); } } if (_this.mObjDict.ContainsKey(obj.ObjId)) { if (_this.mObjDict[obj.ObjId].Equals(obj)) { Logger.Fatal("!ObjDic.ContainsKey({0}) mObjDict[obj.ObjId].Equals(obj)", obj.ObjId); return(false); } _this.RemoveObj(obj); Logger.Fatal("!ObjDic.ContainsKey({0})", obj.ObjId); } _this.AddObj(obj); obj.EnterScene(_this); var zone = _this.mZoneList[zoneId]; zone.AddObj(obj); obj.SetZone(zone); //player 一上来时不时Active状态,不会走这里,只有player掉了EnterSceneOver之后才是active状态, //EnterSceneOver里自己会处理可见和飞可见的玩家 if (obj.Active) { var canSee = true; if (obj.IsCharacter()) { var character = obj as ObjCharacter; if (character.IsDead()) { canSee = false; } } if (canSee) { var bornType = _this.GetBornVisibleType(); obj.BroadcastCreateMe(bornType); } } if (obj.GetObjType() == ObjType.PLAYER) { var player = obj as ObjPlayer; foreach (var pair in _this.mAreaDict) { pair.Value.AdjustPlayer(player); } } return(true); }