void RemoveAllPassengers() { int i; for (i = 0; i < GameStruct_Bus.DEF_BUS_MAX_PASSENGER_COUNT; i++) { if (m_anPassengerIDs[i] != MacroDefine.INVALID_ID) { if (m_abPassengerAttacheds[i] && GetRenderInterface() != null) { CObject pObj = CObjectManager.Instance.FindServerObject((int)m_anPassengerIDs[i]); if (pObj != null && pObj.GetRenderInterface() != null) { CObject_Character player = pObj as CObject_Character; if (player != null) { player.GetCharacterData().Set_BusObjID(0); } GetRenderInterface().Detach_Object(pObj.GetRenderInterface()); pObj.SetMapPosition(pObj.GetPosition().x, pObj.GetPosition().z); //角色离开飞行坐骑后刷新自己的位置 [8/22/2011 zzy] } } m_anPassengerIDs[i] = 0; m_abPassengerAttacheds[i] = false; } } m_nPassengerCount = 0; }
public void DetachCharacterInterface(uint nObjID) { if (nObjID == 0) { return; } int nCount = GetPassengerCount(); if (nCount > 0) { int i; for (i = 0; i < nCount; i++) { if (m_anPassengerIDs[i] == nObjID) { if (m_abPassengerAttacheds[i] && GetRenderInterface() != null) { CObject pObj = CObjectManager.Instance.FindServerObject((int)m_anPassengerIDs[i]); if (pObj != null && pObj.GetRenderInterface() != null) { GetRenderInterface().Detach_Object(pObj.GetRenderInterface()); pObj.SetMapPosition(pObj.GetPosition().x, pObj.GetPosition().z); //角色离开飞行坐骑后刷新自己的位置 [8/22/2011 zzy] } } m_anPassengerIDs[i] = m_anPassengerIDs[nCount - 1]; m_abPassengerAttacheds[i] = m_abPassengerAttacheds[nCount - 1]; m_anPassengerIDs[nCount - 1] = 0; m_abPassengerAttacheds[nCount - 1] = false; return; } } } }
//检查被UI关心的逻辑对象 private void TickCareLogic() { Dictionary <string, OBJECT_BECARED> .Enumerator enumerator = mapCaredObjects.GetEnumerator(); while (enumerator.MoveNext()) { OBJECT_BECARED careItem = enumerator.Current.Value; CObject npc = FindObject(careItem.id); if (npc == null) { LogManager.LogError("Cannot found CareObject"); continue; } float newDistance = Utility.TDU_GetDist(getPlayerMySelf().GetPosition(), npc.GetPosition()); float fStep = Mathf.Abs(newDistance - careItem.fLastDistance); if (fStep > 0.01) { List <string> sParams = new List <string>(); sParams.Add(npc.ID.ToString()); sParams.Add(newDistance.ToString()); CEventSystem.Instance.PushEvent(GAME_EVENT_ID.GE_OBJECT_CARED_EVENT, sParams); } careItem.fLastDistance = newDistance; } }
bool RemovePassenger(uint nPassengerID) { if (nPassengerID == 0) { return(false); } int nCount = GetPassengerCount(); if (nCount > 0) { int i; for (i = 0; i < nCount; i++) { if (m_anPassengerIDs[i] == nPassengerID) { if (m_abPassengerAttacheds[i] && GetRenderInterface() != null) { CObject pObj = CObjectManager.Instance.FindServerObject((int)m_anPassengerIDs[i]); if (pObj != null && pObj.GetRenderInterface() != null) { CObject_Character player = pObj as CObject_Character; if (player != null) { player.GetCharacterData().Set_BusObjID(0); } GetRenderInterface().Detach_Object(pObj.GetRenderInterface()); pObj.SetMapPosition(pObj.GetPosition().x, pObj.GetPosition().z); //角色离开飞行坐骑后刷新自己的位置 [8/22/2011 zzy] } } m_anPassengerIDs[i] = m_anPassengerIDs[nCount - 1]; m_abPassengerAttacheds[i] = m_abPassengerAttacheds[nCount - 1]; m_anPassengerIDs[nCount - 1] = 0; m_abPassengerAttacheds[nCount - 1] = false; // 减少乘客 [8/26/2011 ivan edit] --m_nPassengerCount; return(true); } } } return(false); }
public override NET_RESULT_DEFINE.PACKET_EXE Execute(PacketBase pPacket, ref Peer pPlayer) { if (GameProcedure.GetActiveProcedure() == (GameProcedure)GameProcedure.s_ProcMain) { //LogManager.Log("Receive GCCharMove Packet"); GCCharMove charMovePacket = (GCCharMove)pPacket; CObjectManager pObjectManager = CObjectManager.Instance; CObject pObj = (CObject)(pObjectManager.FindServerObject((int)charMovePacket.ObjID)); if (pObj == null || !(pObj is CObject_Character)) { return(NET_RESULT_DEFINE.PACKET_EXE.PACKET_EXE_CONTINUE); } SCommand_Object cmdTemp = new SCommand_Object(); if (charMovePacket.IsHaveStopInfo()) { cmdTemp.m_wID = (int)OBJECTCOMMANDDEF.OC_STOP_MOVE; cmdTemp.SetValue(0, charMovePacket.StopLogicCount); cmdTemp.SetValue(1, 0); cmdTemp.SetValue(2, pObj.GetPosition().x); cmdTemp.SetValue(3, pObj.GetPosition().z); pObj.PushCommand(cmdTemp); } WORLD_POS[] posTarget = new WORLD_POS[1]; posTarget[0].m_fX = charMovePacket.PosTarget.m_fX; posTarget[0].m_fZ = charMovePacket.PosTarget.m_fZ; cmdTemp.m_wID = (int)OBJECTCOMMANDDEF.OC_MOVE; cmdTemp.SetValue(0, charMovePacket.StartTime); cmdTemp.SetValue(1, charMovePacket.HandleID); cmdTemp.SetValue(2, 1); cmdTemp.SetValue(3, posTarget); pObj.PushCommand(cmdTemp); pObj.SetMsgTime(GameProcedure.s_pTimeSystem.GetTimeNow()); } return(NET_RESULT_DEFINE.PACKET_EXE.PACKET_EXE_CONTINUE); }
//// 没用到 public void RemoveLogicEvent(int nLogicCount) ////{ //// _LOGIC_EVENT pLogicEvent; //// for (int i = 0; i < m_listLogicEvent.Count; i++) //// { //// pLogicEvent = m_listLogicEvent[i]; //// if (pLogicEvent.m_nSenderLogicCount == nLogicCount) //// { //// m_listLogicEvent.RemoveAt(i); //// break; //// } //// } ////} private void DoLogicEvent_Bullet(_LOGIC_EVENT pLogicEvent) { if (pLogicEvent != null) { _LOGIC_EVENT_BULLET pBulletInfo = pLogicEvent.m_bullet; CObject pSender = CObjectManager.Instance.FindServerObject((int)pLogicEvent.m_nSenderID); if (pSender != null) { UnityEngine.Vector3 fvSenderPos = new UnityEngine.Vector3(); UnityEngine.Vector3 fvSenderRot = UnityEngine.Vector3.zero; CObject_Character pCharacterSender = (CObject_Character)pSender; fvSenderPos = pSender.GetPosition(); fvSenderPos.y += 1.0f; //temp code fvSenderRot.y = pSender.GetFaceDir(); if (pCharacterSender != null) { if (pBulletInfo.m_pszSenderLocator.Length > 0 && pCharacterSender.GetRenderInterface() != null) { pCharacterSender.GetRenderInterface().GetLocator(pBulletInfo.m_pszSenderLocator, ref fvSenderPos); } } SObject_BulletInit initBullet = new SObject_BulletInit(); initBullet.m_fvPos = fvSenderPos; initBullet.m_fvRot = fvSenderRot; initBullet.m_idSend = pLogicEvent.m_nSenderID; initBullet.m_nSendLogicCount = pLogicEvent.m_nSenderLogicCount; initBullet.m_nBulletID = pBulletInfo.m_nBulletID; initBullet.m_bSingleTarget = pBulletInfo.m_bHitTargetObj; if (pBulletInfo.m_bHitTargetObj) { initBullet.m_fvTargetPos = new Vector3(-1.0f, -1.0f, -1.0f); initBullet.m_idTarget = (int)pBulletInfo.m_nTargetID; } else { initBullet.m_fvTargetPos.x = pBulletInfo.m_fTargetX; initBullet.m_fvTargetPos.z = pBulletInfo.m_fTargetZ; initBullet.m_fvTargetPos.y = GFX.GfxUtility.getSceneHeight(pBulletInfo.m_fTargetX, pBulletInfo.m_fTargetZ); } CObject_Bullet pBullet = CObjectManager.Instance.NewBullet(-1); pBullet.Initial(initBullet); } } }
int s_nLastHitObj = -1; //上次选中的对象ID public CObject GetMouseOverObject(Vector3 pt, out Vector3 fvMouseHitPlan) //pt: screen Position in pixel { fvMouseHitPlan = Vector3.zero; CObject hitObj = null; Ray ray = Camera.main.ScreenPointToRay(pt); RaycastHit hitInfo; bool hit = Physics.Raycast(ray, out hitInfo); if (hit) { GameObject hitGo = hitInfo.collider.gameObject; //根据layer判断是否相交于动态对象还是静态的物体 if (hitGo.layer == LayerManager.ActorLayer && hitGo != null && mPhyObjectsMap.ContainsKey(hitGo)) { hitObj = mPhyObjectsMap[hitGo]; fvMouseHitPlan = hitObj.GetPosition(); } else { fvMouseHitPlan = hitInfo.point; } } int nHitObjID = hitObj != null ? hitObj.ID : -1; if (s_nLastHitObj != nHitObjID) { if (hitObj != null && hitObj.GetRenderInterface() != null) { hitObj.GetRenderInterface().SetMouseHover(true); } CObject pLastHitObj = FindObject(s_nLastHitObj); if (pLastHitObj != null && pLastHitObj.GetRenderInterface() != null) { pLastHitObj.GetRenderInterface().SetMouseHover(false); } s_nLastHitObj = nHitObjID; } return(hitObj); }
//将一个需要Ask的obj放入 public bool TryAddLoadTask(int idObj) { //玩家自己不放入队列 CObject pObj = CObjectManager.Instance.FindObject(idObj); if (pObj == null || pObj == CObjectManager.Instance.getPlayerMySelf()) { return(false); } if (m_LoadDirect) { //立即请求 CGCharAskBaseAttrib msgAskBaseAttrib = new CGCharAskBaseAttrib(); msgAskBaseAttrib.setTargetID((uint)pObj.ServerID); GameProcedure.s_NetManager.SendPacket(msgAskBaseAttrib); //LogManager.LogWarning("Ask Char BaseAttrib id=" + pObj.ServerID); } else { //自己位置 Vector3 fvPosMySelf = CObjectManager.Instance.getPlayerMySelf().GetPosition(); float fDistanceSq = Utility.TDU_GetDistSq(pObj.GetPosition(), fvPosMySelf); if (m_mapLoadTask.ContainsValue(idObj)) { LogManager.LogWarning("该角色ID<" + idObj + ">已经在加载队列中"); } else { m_mapLoadTask.Add(fDistanceSq, idObj); //LogManager.Log("Ask Char BaseAttrib in queue id" + idObj); } } return(true); }
public override NET_RESULT_DEFINE.PACKET_EXE Execute(PacketBase pPacket, ref Peer pPlayer) { if (GameProcedure.GetActiveProcedure() == (GameProcedure)GameProcedure.s_ProcMain) { //检查位置是否合法 //if(!CWorldManager::GetMe()->GetActiveScene()->IsValidPosition(fVector2(pPacket->GetCurPos()->m_fX, pPacket->GetCurPos()->m_fZ))) //{ // TDThrow("ERROR POSITION @ GCNewBusHandler"); //} GCNewBus busPacket = pPacket as GCNewBus; if (busPacket == null) { LogManager.LogError("GCNewBus 收包错误。"); return(NET_RESULT_DEFINE.PACKET_EXE.PACKET_EXE_ERROR); } //创建玩家 CObject pBus = CObjectManager.Instance.FindServerObject((int)busPacket.ObjID); Vector3 fvGame = new Vector3(busPacket.PosWorld.m_fX, 0, busPacket.PosWorld.m_fZ); if (pBus == null) { pBus = CObjectManager.Instance.NewBus((int)busPacket.ObjID); SObject_BusInit tBusInit = new SObject_BusInit(); tBusInit.m_fvPos = fvGame; tBusInit.m_fvRot = new Vector3(0.0f, busPacket.Dir, 0.0f); tBusInit.m_nDataID = busPacket.DataID; pBus.Initial(tBusInit); pBus.SetMapPosition(busPacket.PosWorld.m_fX, busPacket.PosWorld.m_fZ); } else { if (pBus.isVisible()) { if (Math.Abs(pBus.GetPosition().x - fvGame.x) + Math.Abs(pBus.GetPosition().z - fvGame.z) > ObjectDef.DEF_CHARACTER_POS_ADJUST_DIST) { pBus.SetMapPosition(fvGame.x, fvGame.z); } } else { pBus.SetMapPosition(fvGame.x, fvGame.z); pBus.SetFaceDir(busPacket.Dir); //pBus->setVisible(true); } } SCommand_Object cmdTemp = new SCommand_Object(); cmdTemp.m_wID = (int)OBJECTCOMMANDDEF.OC_BUS_ADD_PASSENGER; int i; for (i = 0; i < busPacket.PassengerCount; i++) { cmdTemp.SetValue(0, i); cmdTemp.SetValue(1, busPacket.PassengerIDs[i]); pBus.PushCommand(cmdTemp); } //放入Ask队列 GameProcedure.s_pObjectManager.LoadQueue.TryAddLoadTask(pBus.ID); } return(NET_RESULT_DEFINE.PACKET_EXE.PACKET_EXE_CONTINUE); }
//pObject中心对象, excludePlayerOther是否排除玩家 public CObject GetNearestTargetByOrigin(CObject pObject, float fMaxDistance, bool excludePlayerOther) { float fNearestDist = fMaxDistance; CObject pNearestTarget = null; CObject pOriginObject = (CObject)pObject; Vector2 fvOrigin = new Vector2(pOriginObject.GetPosition().x, pOriginObject.GetPosition().z); foreach (int k in mServerObjects.Keys) { CObject pObj = mServerObjects[k]; //不再查找自身 if (pObj == pOriginObject) { continue; } if (CObjectManager.Instance.getPlayerMySelf().IsMyPet(pObj.ServerID)) { continue; } //非角色 if (!(pObj is CObject_Character)) { continue; } if (excludePlayerOther) { if (pObj is CObject_PlayerOther) { continue; } } //友好阵营 CObject_Character pChar = (CObject_Character)pObj; if (ENUM_RELATION.RELATION_ENEMY != GameProcedure.s_pGameInterface.GetCampType( getPlayerMySelf(), pChar)) { continue; } //死亡 if (ENUM_CHARACTER_LOGIC.CHARACTER_LOGIC_DEAD == pChar.CharacterLogic_Get()) { continue; } //距离太远 Vector2 vec = fvOrigin - new Vector2(pObj.GetPosition().x, pObj.GetPosition().z); float fDistance = vec.magnitude; if (fDistance >= fNearestDist) { continue; } pNearestTarget = pObj; fNearestDist = fDistance; } return(pNearestTarget); }
public void CareObject(int objId, bool isCare, string sign) { CObject obj = FindObject(objId); if (obj == null) { return; } mapCaredObjects.Remove(sign); if (isCare) { OBJECT_BECARED careObj = new OBJECT_BECARED(); careObj.id = objId; careObj.fLastDistance = Utility.TDU_GetDist(getPlayerMySelf().GetPosition(), obj.GetPosition()); mapCaredObjects.Add(sign, careObj); } }
//private void AddFriend( CObject_PlayerOther* pObj ); //创建轨迹特效 //private void CreateMoveTrackProjTex(); //private void Tick_MoveTrack(); //CObject_ProjTex_MoveTrack* GetFreeProjTex(); //void FreeMoveTrackProjTex(CObject_ProjTex_MoveTrack* pMoveTrack); //private void FreeAllMoveTrackProjTex(); //private void ClearAllFreeProjTex(); // 刷新地图信息 [3/19/2012 Ivan] public void UpdateMinimapData() { ClearMapData(); // 更新队友列表 //if(CUIDataPool::GetMe()->GetTeamOrGroup()) //{ // for( int i = 0; i < CUIDataPool::GetMe()->GetTeamOrGroup()->GetTeamMemberCount(); i ++ ) // { // const TeamMemberInfo* pInfo = CUIDataPool::GetMe()->GetTeamOrGroup()->GetMemberByIndex( i ); // if( pInfo ) // { // /*if( pInfo->m_SceneID != m_pActiveScene->GetSceneDefine()->nID ) // continue;*/ // if( pInfo->m_OjbID == CObjectManager::GetMe()->GetMySelf()->GetServerID() ) // continue; // data.pos.x = pInfo->m_WorldPos.m_fX; // data.pos.z = pInfo->m_WorldPos.m_fZ; // _snprintf( data.name, 128, "%s", pInfo->m_szNick ); // data.nServerID = pInfo->m_OjbID; // data.dwSceneID = pInfo->m_SceneID; // m_FriendlistObj.push_back( data ); // } // } //} MAP_POS_DEFINE data; CObject_PlayerMySelf mySelf = CObjectManager.Instance.getPlayerMySelf(); // 遍历所有的对象 [3/19/2012 Ivan] foreach (KeyValuePair <int, CObject> obj in CObjectManager.Instance.ServerObjects) { data = new MAP_POS_DEFINE(); // 如果是角色 [3/19/2012 Ivan] if (obj.Value is CObject_Character) { CObject curObj = obj.Value; if (curObj == mySelf) { continue; } ENUM_RELATION sCamp = GameInterface.Instance.GetCampType(curObj, mySelf); // 如果已经死了,就不加如列表了。 if (((CObject_Character)curObj).CharacterLogic_Get() == ENUM_CHARACTER_LOGIC.CHARACTER_LOGIC_DEAD) { continue; } if (((CObject_Character)curObj).GetFakeObjectFlag() == true) { continue; } // 判断是不是宠物 // 此处还有判断m_FlashlistObj和m_ActivelistObj的逻辑,没有使用,屏蔽 [3/19/2012 Ivan] data.pos.x = curObj.GetPosition().x; data.pos.y = curObj.GetPosition().z; data.name = ((CObject_Character)curObj).GetCharacterData().Get_Name(); data.nServerID = ((CObject_PlayerNPC)curObj).ServerID; if (curObj is CObject_PlayerOther) // 如果是玩家 { if (sCamp == ENUM_RELATION.RELATION_FRIEND) // 如果是同一阵营的 { // 如果是队友,就替掉本来已经存在的位置 // if( CheckIsFriend( pCurObj->GetServerID() ) ) // { // AddFriend( (CObject_PlayerOther*)pCurObj ); // continue; // } m_PlayerlistObj.Add(data); } else if (sCamp == ENUM_RELATION.RELATION_ENEMY) // 敌人 { m_AnimylistObj.Add(data); } } else if (curObj is CObject_PlayerNPC) // 如果是npc { //data.nServerID = ((CObject_PlayerNPC)curObj).GetCharacterData().Get_RaceID(); if (((CObject_PlayerNPC)curObj).IsDisplayBoard() == false) { continue; } // 如果是宠物 if (((CObject_PlayerNPC)curObj).GetNpcType() == ENUM_NPC_TYPE.NPC_TYPE_PET) { if (((CObject_PlayerNPC)curObj).GetOwnerId() == -1) // 还没有主人 { m_PetlistObj.Add(data); } } else if (sCamp == ENUM_RELATION.RELATION_FRIEND) // 如果是同阵营的,是npc,否则是敌人 { // TODO 以后要判断该npc身上是否带了任务,有的话需要放到任务列表里面去 [3/19/2012 Ivan] m_ExpNPClistObj.Add(data); } else if (sCamp == ENUM_RELATION.RELATION_ENEMY) { m_AnimylistObj.Add(data); } } } else if (obj.Value is CTripperObject_Resource) { CTripperObject_Resource resource = obj.Value as CTripperObject_Resource; data.pos.x = resource.GetPosition().x; data.pos.y = resource.GetPosition().z; data.name = resource.GetLifeAbility().szName; data.nServerID = resource.ServerID; m_ExpObjlistObj.Add(data); } // else if( obj.Value is CTripperObject_Transport ) // { // data.pos.x = (( CObject*)pCurObj)->GetPosition().x; // data.pos.z = (( CObject*)pCurObj)->GetPosition().z; // _snprintf( data.name, 128, "传送点" ); // } } }
public override void Tick() { if (m_bAlreadyHit) { base.Tick(); } else { if (m_pBulletData == null) { m_bAlreadyHit = true; return; } switch ((ENUM_BULLET_CONTRAIL_TYPE)m_pBulletData.m_nContrailType) { case ENUM_BULLET_CONTRAIL_TYPE.BULLET_CONTRAIL_TYPE_BEELINE: case ENUM_BULLET_CONTRAIL_TYPE.BULLET_CONTRAIL_TYPE_PARABOLA: { Vector3 fvTargetPos; if (m_bSingleTarget) { CObject pObj = CObjectManager.Instance.FindServerObject(m_idTarget); if (pObj != null) { fvTargetPos = pObj.GetPosition(); if (pObj.GetRenderInterface() != null && (m_pBulletData.m_szHitEffectLocator.Length != 0)) { pObj.GetRenderInterface().GetLocator(m_pBulletData.m_szHitEffectLocator, ref fvTargetPos); } else { fvTargetPos = pObj.GetPosition(); } } else { fvTargetPos = new Vector3(-1.0f, -1.0f, -1.0f); CObjectManager.Instance.DestroyObject(this); return; } } else { fvTargetPos = m_fvTargetPos; } float fCurTickFlyDist = m_pBulletData.m_fSpeed * GameProcedure.s_pTimeSystem.GetDeltaTime() / 1000.0f; float fDistSq = (fvTargetPos - GetPosition()).sqrMagnitude; if (GFX.GfxUtility.IsLessEqual(fDistSq, fCurTickFlyDist * fCurTickFlyDist)) { if (m_pBulletData.m_nContrailType == (int)ENUM_BULLET_CONTRAIL_TYPE.BULLET_CONTRAIL_TYPE_PARABOLA) { float fStartToEndDist = m_fStartToEndDist; float fTargetToStartDist = (fvTargetPos - m_fvStartPos).magnitude; float fCenterToTargetDist = Mathf.Abs(fTargetToStartDist - fStartToEndDist / 2.0f); float fTemp = (fCenterToTargetDist * 2.0f) / fStartToEndDist; float fAddY = (1.0f - (fTemp * fTemp)) * m_pBulletData.m_fContrailParam; fvTargetPos.y += fAddY; } Vector2 curPos = new Vector2(GetPosition().x, GetPosition().z); Vector2 targetPos = new Vector2(fvTargetPos.x, fvTargetPos.z); float fDir = GFX.GfxUtility.GetYAngle(curPos, targetPos); SetPosition(fvTargetPos); SetFaceDir(fDir); AlreadyHit(); } else { Vector3 vDir = fvTargetPos - GetPosition(); vDir.Normalize(); Vector3 vFlyLength; vFlyLength.x = vDir.x * fCurTickFlyDist; vFlyLength.y = vDir.y * fCurTickFlyDist; vFlyLength.z = vDir.z * fCurTickFlyDist; fvTargetPos = vFlyLength + GetPosition(); if (m_pBulletData.m_nContrailType == (int)ENUM_BULLET_CONTRAIL_TYPE.BULLET_CONTRAIL_TYPE_PARABOLA) { float fStartToEndDist = m_fStartToEndDist; float fTargetToStartDist = (fvTargetPos - m_fvStartPos).magnitude; float fCenterToTargetDist = Mathf.Abs(fTargetToStartDist - fStartToEndDist / 2.0f); float fTemp = (fCenterToTargetDist * 2.0f) / fStartToEndDist; float fAddY = (1.0f - (fTemp * fTemp)) * m_pBulletData.m_fContrailParam; fvTargetPos.y += fAddY; } Vector2 curPos = new Vector2(GetPosition().x, GetPosition().z); Vector2 targetPos = new Vector2(fvTargetPos.x, fvTargetPos.z); float fDir = GFX.GfxUtility.GetYAngle(curPos, targetPos); SetPosition(fvTargetPos); SetFaceDir(fDir); } } break; case ENUM_BULLET_CONTRAIL_TYPE.BULLET_CONTRAIL_TYPE_NONE: default: { AlreadyHit(); } break; } } }