void ReadAndDoCreateAction(NetIncomingMessage inInputStream, int inNetworkId) { UInt32 classID = inInputStream.ReadByte(); //LogHelper.LogInfo($"replication {(core.GameObjectClassId)classID}"); //we might already have this object- could happen if our ack of the create got dropped so server resends create request //( even though we might have created ) NetGameObject gameObject = NetworkManagerClient.sInstance.GetGameObject(inNetworkId, core.World.DefaultWorldIndex); if (gameObject == null) { //create the object and map it... gameObject = GameObjectRegistry.sInstance.CreateGameObject(classID, false); gameObject.SetNetworkId(inNetworkId); NetworkManagerClient.sInstance.AddToNetworkIdToGameObjectMap(gameObject, core.World.DefaultWorldIndex); gameObject.IsCreate = true; //it had really be the rigth type... //Assert(gameObject.GetClassId() == fourCCName); //Debug.Log($"ReadAndDoCreateAction networkID {inNetworkId}"); } else { gameObject.IsCreate = false; } //and read state gameObject.Read(inInputStream); if (gameObject.IsCreate) { gameObject.CompleteCreate(); } }
void Explode(Vector3 pos /*Tile tile*/) { float current_floor = (float)Math.Round(pos.y); foreach (var game_object in World.Instance(WorldId).GetGameObjects()) { // 같은 층이 아닌 경우는 충돌 검사에서 제외 if (NetGameObject.IsSameFloor(current_floor, game_object) == false) { continue; } if (NetworkId != game_object.NetworkId && MathHelpers.circleRect(pos.x, pos.z, GetCollisionRadius(), game_object.rx, game_object.ry, game_object.rw, game_object.rh) /*game_object.GetLocation().Round().Equals(pos)*/) { game_object.OnExplode(mPlayerId, NetworkId, default_damage); } } //if (tile == null) // return; //foreach(var game_object in tile.gameObjects) //{ // if(NetworkId != game_object.NetworkId) // game_object.OnExplode(mPlayerId, NetworkId, default_damage); //} }
public void SetKingSpell(byte worldId, int playerId) { Entry entry = World.Instance(worldId).GameMode.GetEntry(playerId); if (entry == null) { LogHelper.LogError($"Can't find entry in SetKingSpell playerId : {playerId}"); return; } NetGameObject netGameObject = NetworkManager.Instance.GetGameObject(entry.mNetworkId, worldId); if (netGameObject == null || !(netGameObject is SActor)) { LogHelper.LogError($"netGameObject == null or netGameObject is not SActor playerId : {playerId}, worldId : {worldId}"); return; } SActor actor = netGameObject as SActor; var modeData = ACDC.GameModeData[(int)GetMode()]; for (int i = 0; i < modeData.ModeSpellIDs.Length; ++i) { actor.AddSpell(ACDC.SpellData[modeData.ModeSpellIDs[i]], 0); } if (actor.StateServerSide != ActorState.Ghost) { actor.ResetHealth(actor.GetCharacterHp(), null); } }
void ReadAndDoCreateAction(NetIncomingMessage inInputStream, int inNetworkId) { //need 4 cc uint32_t fourCCName = inInputStream.ReadUInt32(); //we might already have this object- could happen if our ack of the create got dropped so server resends create request //( even though we might have created ) bool is_create = false; NetGameObject gameObject = NetworkManagerClient.sInstance.GetGameObject(inNetworkId); if (gameObject == null) { //create the object and map it... gameObject = GameObjectRegistry.sInstance.CreateGameObject(fourCCName); gameObject.SetNetworkId(inNetworkId); NetworkManagerClient.sInstance.AddToNetworkIdToGameObjectMap(gameObject); is_create = true; //it had really be the rigth type... //Assert(gameObject.GetClassId() == fourCCName); } //and read state gameObject.Read(inInputStream); if (is_create) { gameObject.CompleteCreate(); } }
public void RegisterGameObject(NetGameObject inGameObject, byte worldId) { if (CheckWorldId(inGameObject.WorldId) == false) { Log.Error($"RegisterGameObject error worldId{inGameObject.WorldId}"); return; } //assign network id int newNetworkId = GetNewNetworkId(worldId); inGameObject.SetNetworkId(newNetworkId); inGameObject.WorldId = worldId; //add mapping from network id to game object mNetworkIdToGameObjectMap[worldId][newNetworkId] = inGameObject; //tell all client proxies this is new... foreach (var pair in mAddressToClientMap) { if (pair.Value.IsStartedPlay && pair.Value.GetWorldId() == worldId) { pair.Value.GetReplicationManagerServer().ReplicateCreate(newNetworkId, inGameObject.GetAllStateMask()); } } }
void HandleCreateDeliveryFailure(int inNetworkId) { NetGameObject gameObject = NetworkManagerServer.sInstance.GetGameObject(inNetworkId); if (gameObject != null) { mReplicationManagerServer.ReplicateCreate(inNetworkId, gameObject.GetAllStateMask()); } }
uint32_t WriteCreateAction(NetOutgoingMessage inOutputStream, int inNetworkId, uint32_t inDirtyState) { //need object NetGameObject gameObject = NetworkManagerServer.sInstance.GetGameObject(inNetworkId); //need 4 cc inOutputStream.Write(gameObject.GetClassId()); return(gameObject.Write(inOutputStream, inDirtyState)); }
void ReadAndDoUpdateAction(NetIncomingMessage inInputStream, int inNetworkId) { //need object NetGameObject gameObject = NetworkManagerClient.sInstance.GetGameObject(inNetworkId); //gameObject MUST be found, because create was ack'd if we're getting an update... //and read state gameObject.Read(inInputStream); }
public void UpdateHierarchy(ClientGameObject parent, NetGameObject remote) { this.active = remote.active; this.name = remote.name; bool isSelected = this.selected; this.Selected = false; this.Parent = parent; this.Selected = isSelected; }
public void CancelGameObject(NetGameObject inGameObject) { int networkId = inGameObject.GetNetworkId(); foreach (var pair in mAddressToClientMap) { if (pair.Value.IsStartedPlay && inGameObject.WorldId == pair.Value.GetWorldId()) { pair.Value.GetReplicationManagerServer().RemoveFromReplication(networkId); } } }
public static void Serialize(ServerScene scene, ByteBuffer buffer) { buffer.Append(scene.buildIndex); buffer.AppendUnicodeString(scene.name); buffer.Append(scene.roots.Count); for (int i = 0; i < scene.roots.Count; i++) { NetGameObject.Serialize(scene.roots[i], buffer); } }
void ReadAndDoDestroyAction(NetIncomingMessage inInputStream, int inNetworkId) { //if something was destroyed before the create went through, we'll never get it //but we might get the destroy request, so be tolerant of being asked to destroy something that wasn't created NetGameObject gameObject = NetworkManagerClient.sInstance.GetGameObject(inNetworkId); if (gameObject != null) { gameObject.SetDoesWantToDie(true); NetworkManagerClient.sInstance.RemoveFromNetworkIdToGameObjectMap(gameObject); } }
void HandleBomb() { if (mIsBomb == false) { return; } float time = Timing.sInstance.GetFrameStartTime(); if (Timing.sInstance.GetFrameStartTime() <= mTimeOfNextBomb) { //Log.Information("It's still too early"); return; } foreach (var game_object in World.Instance(WorldId).GetGameObjects()) { if (game_object.GetClassId() != (uint)GameObjectClassId.Bomb) { continue; } // 같은 층이 아닌 경우는 충돌 검사에서 제외 if (NetGameObject.IsSameFloor(floor, game_object) == false) { continue; } if (MathHelpers.circlesColliding(GetLocation().x, GetLocation().z, core.Bomb.DefaultCollisionRadius, game_object.GetLocation().x, game_object.GetLocation().z, game_object.GetCollisionRadius())) { Log.Information("already installed bomb"); return; } } if (BasicAttack.skillType != (int)SkillType.InstallSkill) { Log.Information($"skill type error {BasicAttack.skillType}"); return; } //not exact, but okay mTimeOfNextBomb = time + mTimeBetweenBomb; //install bomb var bomb = (core.Bomb)GameObjectRegistry.sInstance.CreateGameObject((uint)GameObjectClassId.Bomb, true, WorldId); bomb.InitFrom(this, BasicAttack); Log.Information("installed bomb success!"); }
private NetScene(ByteBuffer buffer) { this.buildIndex = buffer.ReadInt32(); this.name = buffer.ReadUnicodeString(); int length = buffer.ReadInt32(); this.roots = new NetGameObject[length]; for (int i = 0; i < length; i++) { this.roots[i] = NetGameObject.Deserialize(buffer); } }
uint32_t WriteUpdateAction(NetOutgoingMessage inOutputStream, int inNetworkId, uint32_t inDirtyState) { //need object NetGameObject gameObject = NetworkManagerServer.sInstance.GetGameObject(inNetworkId); //if we can't find the gameObject on the other side, we won't be able to read the written data ( since we won't know which class wrote it ) //so we need to know how many bytes to skip. //this means we need byte sand each new object needs to be byte aligned uint32_t writtenState = gameObject.Write(inOutputStream, inDirtyState); return(writtenState); }
public static void Serialize(ServerGameObject node, ByteBuffer buffer) { using (SafeWrapByteBuffer.Get(buffer)) { buffer.Append(node.gameObject.activeSelf); buffer.AppendUnicodeString(node.gameObject.name); buffer.Append(node.instanceID); buffer.Append(node.children.Count); for (int i = 0; i < node.children.Count; i++) { NetGameObject.Serialize(node.children[i], buffer); } } }
public ClientGameObject(ClientScene scene, ClientGameObject parent, NetGameObject remote, IUnityData unityData) { this.unityData = unityData; this.scene = scene; this.active = remote.active; this.name = remote.name; this.instanceID = remote.instanceID; this.Parent = parent; int length = remote.children.Length; this.children = new List <ClientGameObject>(remote.children.Length); for (int i = 0; i < length; i++) { new ClientGameObject(scene, this, remote.children[i], this.unityData); } }
void ReadAndDoUpdateAction(NetIncomingMessage inInputStream, int inNetworkId) { //need object NetGameObject gameObject = NetworkManagerClient.sInstance.GetGameObject(inNetworkId, core.World.DefaultWorldIndex); if (gameObject != null) { gameObject.IsCreate = false; //gameObject MUST be found, because create was ack'd if we're getting an update... //and read state gameObject.Read(inInputStream); } else { Debug.LogError($"ReadAndDoUpdateAction cannot find network object {inNetworkId}"); } }
public void UnregisterGameObject(NetGameObject inGameObject) { int networkId = inGameObject.GetNetworkId(); mNetworkIdToGameObjectMap.Remove(networkId); Log.Information(string.Format("remove game object {0}", networkId)); //tell all client proxies to STOP replicating! //tell all client proxies this is new... foreach (var pair in mAddressToClientMap) { if (inGameObject.WorldId == pair.Value.GetWorldId()) { pair.Value.GetReplicationManagerServer().ReplicateDestroy(networkId); } } }
public void RegisterGameObject(NetGameObject inGameObject, byte worldId) { //assign network id int newNetworkId = GetNewNetworkId(); inGameObject.SetNetworkId(newNetworkId); inGameObject.WorldId = worldId; //add mapping from network id to game object mNetworkIdToGameObjectMap[newNetworkId] = inGameObject; //tell all client proxies this is new... foreach (var pair in mAddressToClientMap) { if (pair.Value.GetWorldId() == worldId) { pair.Value.GetReplicationManagerServer().ReplicateCreate(newNetworkId, inGameObject.GetAllStateMask()); } } }
public void UnregisterGameObject(NetGameObject inGameObject) { if (CheckWorldId(inGameObject.WorldId) == false) { Log.Error($"UnregisterGameObject error networID{inGameObject.GetNetworkId()}, worldId{inGameObject.WorldId}"); return; } int networkId = inGameObject.GetNetworkId(); mNetworkIdToGameObjectMap[inGameObject.WorldId].Remove(networkId); //Log.Information($"remove game object {networkId}"); //tell all client proxies to STOP replicating! //tell all client proxies this is new... foreach (var pair in mAddressToClientMap) { if (pair.Value.IsStartedPlay && inGameObject.WorldId == pair.Value.GetWorldId()) { pair.Value.GetReplicationManagerServer().ReplicateDestroy(networkId); } } }
public int Write(NetOutgoingMessage inOutputStream, ReplicationManagerTransmissionData ioTransmissinData, int inRestartedNetworkId, byte inWorldId) { int count = 0; bool skip = (inRestartedNetworkId != 0); //run through each replication command and do something... List <int> removeObject = null; foreach (var pair in mNetworkIdToReplicationCommand) { ReplicationCommand replicationCommand = pair.Value; if (replicationCommand.HasDirtyState()) { // 이전에 중단 되었던 network ID 부터 재개 if (skip) { if (inRestartedNetworkId == pair.Key) { skip = false; } else { continue; } } int networkId = pair.Key; ReplicationAction action = replicationCommand.GetAction(); NetGameObject gameObject = NetworkManagerServer.sInstance.GetGameObject(networkId, inWorldId); if (gameObject == null && action != ReplicationAction.RA_Destroy) { if (removeObject == null) { removeObject = new List <int>(); } removeObject.Add(networkId); continue; } // 최대로 동기화 할수 있는 개수 초과시 중단 ++count; if (count > max_replication_count) { return(pair.Key); } //well, first write the network id... inOutputStream.Write((uint)networkId, NetGameObject.NetworkIdSize); //Log.Information($"write networkId:{networkId}, classId:{gameObject?.GetClassId()}, action:{action}"); //only need 2 bits for action... inOutputStream.Write(action); uint32_t writtenState = 0; uint32_t dirtyState = replicationCommand.GetDirtyState(); //now do what? switch (action) { case ReplicationAction.RA_Create: { inOutputStream.Write(gameObject.GetClassId()); writtenState = gameObject.Write(inOutputStream, dirtyState); } break; case ReplicationAction.RA_Update: { writtenState = gameObject.Write(inOutputStream, dirtyState); } break; case ReplicationAction.RA_Destroy: { //don't need anything other than state! writtenState = dirtyState; } break; } ioTransmissinData.AddTransmission(networkId, action, writtenState, inWorldId); //let's pretend everything was written- don't make this too hard replicationCommand.ClearDirtyState(writtenState); } } if (removeObject != null) { foreach (var key in removeObject) { mNetworkIdToReplicationCommand.Remove(key); } } return(0); }
public NetGameObject RegisterAndReturn(NetGameObject inGameObject, byte worldId) { RegisterGameObject(inGameObject, worldId); return(inGameObject); }