private void OnRoleAttrInfo(GameEvent ge, EventParameter parameter) { MsgData_sRoleAttrInfoNotify data = parameter.msgParameter as MsgData_sRoleAttrInfoNotify; ActorObj obj = CoreEntry.gActorMgr.GetActorByServerID(data.RoleID); if (obj != null) { if (ArenaMgr.Instance.IsArena)//如果是竞技场 更新血量 { CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_ARENA_HP_REFRESH, null); } obj.UpdateAttr(data.AttrList); }else //查看缓存中的数据 { SceneObj so = mSceneCache.Find(o => { return o.ObjGuid == data.RoleID; }); if(so != null && so.ObjType == EnEntType.EnEntType_Monster) { var msg = so.ObjData as MsgData_sSceneObjectEnterMonster; foreach(var attr in data.AttrList) { var type = BaseAttr.GetBasicAttrTypeFromStatType(attr.AttrType); switch(type) { case BasicAttrEnum.CurHP: msg.CurHp = attr.AttrValue; break; case BasicAttrEnum.MaxHP: msg.MaxHp = attr.AttrValue; break; } } } } }
private SceneObj CacheSceneObj(EnEntType type, long guid, object data) { SceneObj sceneObj = new SceneObj(); sceneObj.ObjType = type; sceneObj.ObjGuid = guid; sceneObj.ObjData = data; mSceneCache.Add(sceneObj); mSceneDataList.Add(sceneObj); return sceneObj; }
void Update() { if (!bSceneLoaded) { return; } float time = 0.0f; float lastTime = Time.realtimeSinceStartup; while (mSceneCache.Count > 0) { if (time > mMaxPrcessingTime) { return; } SceneObj sceneObj = mSceneCache[0]; switch (sceneObj.ObjType) { case EnEntType.EnEntType_Player: MsgData_sSceneObjectEnterHuman humanStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterHuman; CoreEntry.gSceneLoader.LoadOtherPlayer(humanStruct); if (sceneObj.PlayerData != null) { sceneObj.PlayerData = null; } break; case EnEntType.EnEntType_Monster: MsgData_sSceneObjectEnterMonster monsterStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterMonster; //Debug.LogError("创建怪物:" + monsterStruct.Guid); if (!mObjRecord.ContainsKey(monsterStruct.Guid)) { CoreEntry.gSceneLoader.LoadMonster(monsterStruct); mObjRecord.Add(monsterStruct.Guid, CoreEntry.gActorMgr.GetActorByServerID(monsterStruct.Guid)); } else { //Debug.LogError("重复怪物:" + monsterStruct.Guid); } break; case EnEntType.EnEntType_NPC: MsgData_sSceneObjectEnterNPC npcStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterNPC; CoreEntry.gSceneLoader.LoadNPC(npcStruct); break; case EnEntType.EnEntType_StaticObj: MsgData_sSceneObjectEnterStaticObj sstaticStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterStaticObj; CoreEntry.gSceneLoader.LoadStaticObj(sstaticStruct); break; case EnEntType.EnEntType_Item: MsgData_sSceneObjectEnterItem itemStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterItem; EventParameter param = EventParameter.Get(); param.objParameter = itemStruct; CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_OBJ_ITEM_ENTER, param); break; case EnEntType.EnEntType_GatherObj: MsgData_sSceneObjectEnterCollection collectionStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterCollection; CoreEntry.gSceneLoader.LoadCollection(collectionStruct); break; case EnEntType.EnEntType_Pet: MsgData_sSceneObjectEnterPet petStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterPet; CoreEntry.gSceneLoader.LoadPet(petStruct); break; case EnEntType.EnEntType_BiaoChe: MsgData_sSceneObjectEnterBiaoChe cheStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterBiaoChe; CoreEntry.gSceneLoader.LoadBiaoChe(cheStruct); break; case EnEntType.EnEntType_Trap: MsgData_sSceneObjectEnterTrap trapStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterTrap; CoreEntry.gSceneLoader.LoadTrap(trapStruct); break; case EnEntType.EntType_VirtualPlayer: MsgData_sSceneObjectEnterVirtualPlayer vpStruct = sceneObj.ObjData as MsgData_sSceneObjectEnterVirtualPlayer; CoreEntry.gSceneLoader.LoadVirtualPlayer(vpStruct); break; default: break; } mSceneCache.RemoveAt(0); time += Time.realtimeSinceStartup - lastTime; } for (int i = 0; i < mDeathCache.Count; i++) { MsgData_sObjDeadInfo msg = mDeathCache[i]; ActorObj behitActor = CoreEntry.gActorMgr.GetActorByServerID(msg.ID); if (null == behitActor) { continue; } ActorObj attackActor = CoreEntry.gActorMgr.GetActorByServerID(msg.KillerID); BehitParam behitParam = new BehitParam(); DamageParam damageParam = new DamageParam(); damageParam.attackActor = attackActor; damageParam.behitActor = behitActor; damageParam.skillID = msg.KillerSkillID; behitParam.damgageInfo = damageParam; behitActor.OnDead(msg.KillerSkillID, attackActor, behitParam, EventParameter.Get()); mDeathCache.RemoveAt(i); i--; } for (int i = 0; i < mLeaveCache.Count; i++) { ActorObj actor = mLeaveCache[i]; if (null != actor) { if (actor.mActorState.IsDeathEnd()) { CoreEntry.gActorMgr.RemoveActorByServerID(actor.ServerID); actor.RecycleObj(); EventParameter param = EventParameter.Get(); param.longParameter = actor.ServerID; CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_ACTOR_REMOVE, param); if (actor is OtherPlayer) { param = EventParameter.Get(); param.longParameter = actor.ServerID; CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_OTHERPLAYER_LEAVE, param); } } else { continue; } } mLeaveCache.RemoveAt(i); i--; } }
private void OnLeaveScene(GameEvent ge, EventParameter parameter) { MsgData_sSceneObjectLeaveNotify data = parameter.msgParameter as MsgData_sSceneObjectLeaveNotify; long serverID = (long)data.ObjectID; if (mObjRecord.ContainsKey(serverID)) { mObjRecord.Remove(serverID); //Debug.LogError("怪物消失" + serverID); } if (mBackgroundPlayer.ContainsKey(serverID)) { mBackgroundPlayer.Remove(serverID); return; } for (int i = 0; i < mSceneDataList.Count; i++) { if (mSceneDataList[i].ObjGuid == serverID) { mSceneDataList.RemoveAt(i); break; } } for(int i = 0;i < mDeathCache.Count;i++) { if(serverID == mDeathCache[i].ID) { mDeathCache.RemoveAt(i); break; } } for (int i = 0; i < mSceneCache.Count; i++) { if (mSceneCache[i].ObjGuid == serverID) { mSceneCache.RemoveAt(i); return; } } if (!bSceneLoaded) { return; } if (data.ObjectType == (sbyte)EnEntType.EnEntType_Item) { EventParameter param = EventParameter.Get(); param.longParameter = serverID; CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_OBJ_ITEM_LEAVE, param); return; } else if (data.ObjectType == (sbyte)EnEntType.EnEntType_GatherObj) { CollectionObj collection = CoreEntry.gEntityMgr.GetCollectionByServerID(serverID) as CollectionObj; if (null != collection) { CoreEntry.gEntityMgr.RemoveCollectionByServerID(serverID); collection.RecycleObj(); } return; } else if (data.ObjectType == (sbyte)EnEntType.EnEntType_StaticObj) { PortalObj portal = CoreEntry.gEntityMgr.GetPortalByServerID(serverID) as PortalObj; if (null != portal) { CoreEntry.gEntityMgr.RemovePortalByServerID(serverID); portal.RecycleObj(); } return; } else if (data.ObjectType == (sbyte)EnEntType.EnEntType_Trap) { Trap trap = CoreEntry.gEntityMgr.GetTrapByServerID(serverID) as Trap; if (null != trap) { CoreEntry.gEntityMgr.RemoveTrapByServerID(serverID); trap.RecycleObj(); } return; } ActorObj actor = CoreEntry.gActorMgr.GetActorByServerID(serverID); if (null != actor) { if (!actor.mActorState.IsDeathEnd()) { if (!mLeaveCache.Contains(actor)) { mLeaveCache.Add(actor); } return; } CoreEntry.gActorMgr.RemoveActorByServerID(serverID); actor.RecycleObj(); EventParameter param = EventParameter.Get(); param.longParameter = serverID; CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_ACTOR_REMOVE, param); if (actor is OtherPlayer) { param = EventParameter.Get(); param.longParameter = serverID; CoreEntry.gEventMgr.TriggerEvent(GameEvent.GE_OTHERPLAYER_LEAVE, param); } //有后台玩家则切换进来 if (mBackgroundPlayer.Count > 0) { int num = CoreEntry.gActorMgr.GetAllPlayerActors().Count - 1 + GetCacheNumber(EnEntType.EnEntType_Player); if (num < CreateMaxPlayer) { var e = mBackgroundPlayer.GetEnumerator(); if (e.MoveNext()) { ScenePlayerData value = e.Current.Value; SceneObj sceneobj = CacheSceneObj(EnEntType.EnEntType_Player, value.Guid, value.EnterData); sceneobj.PlayerData = value; mBackgroundPlayer.Remove(value.Guid); } e.Dispose(); } } } }