public void EnterForce(NecClient client, MapPosition mapPosition = null) { Enter(client, mapPosition); _server.Router.Send(new RecvMapChangeForce(this, mapPosition, _server.Setting), client); // currently required to prevent disconnect by force changing _server.Router.Send(new RecvMapChangeSyncOk(), client); }
/// <summary> /// Adds a Client. /// </summary> public void Add(NecClient client) { if (client == null) { return; } lock (_lock) { _clients.Add(client); } }
/// <summary> /// Returns a Character by CharacterName if it exists or null. /// </summary> public Character GetCharacterByCharacterId(int characterId) { NecClient client = GetByCharacterId(characterId); if (client == null) { return(null); } Character character = client.character; return(character); }
MonsterOrient(NecServer server, NecClient client) // Need to change this to a recv_ with a time attribute, monsters shouldn't turn instantly { IBuffer res = BufferProvider.Provide(); res.WriteUInt32(instanceId); res.WriteFloat(x); res.WriteFloat(y); res.WriteFloat(z); res.WriteByte(heading); res.WriteByte(1); server.router.Send(client, (ushort)AreaPacketId.recv_0x6B6A, res, ServerType.Area); }
public void MonsterStop(NecServer server, NecClient client, byte pose, byte animation, float travelTime) { IBuffer res = BufferProvider.Provide(); res.WriteUInt32(instanceId); //Monster ID res.WriteFloat(x); res.WriteFloat(y); res.WriteFloat(z); res.WriteFloat(0.0F); //X per tick res.WriteFloat(0.0F); //Y Per tick res.WriteFloat(0.0F); //verticalMovementSpeedMultiplier res.WriteFloat(1 / travelTime); //movementMultiplier res.WriteFloat(travelTime); //Seconds to move res.WriteByte(pose); //MOVEMENT ANIM res.WriteByte(animation); //JUMP & FALLING ANIM server.router.Send(client, (ushort)AreaPacketId.recv_0x8D92, res, ServerType.Area); }
public void Leave(NecClient client) { Logger.Info(client, $"Leaving Map: {Id}:{FullName}"); ClientLookup.Remove(client); if (!_server.Database.UpdateCharacter(client.Character)) { Logger.Error("Could not update the database with last known player position"); } client.Map = null; RecvObjectDisappearNotify objectDisappearData = new RecvObjectDisappearNotify(client.Character.InstanceId); _server.Router.Send(this, objectDisappearData, client); if (ClientLookup.GetAll().Count == 0) { foreach (MonsterSpawn monsterSpawn in this.MonsterSpawns.Values) { monsterSpawn.SpawnActive = false; } } Logger.Debug($"Client Lookup count is now : {ClientLookup.GetAll().Count} for map {this.Id} "); }
public void Move(NecServer server, NecClient client) { InventoryItem fromInvItem = client.Character.GetInventoryItem(fromStoreType, fromBagId, fromSlot); InventoryItem toInvItem = client.Character.GetInventoryItem(toStoreType, toBagId, toSlot); if (toInvItem != null && (fromInvItem.StorageCount + toInvItem.StorageCount > 255)) { RecvNormalSystemMessage unlikeItems = new RecvNormalSystemMessage("The move would place too many items in destination slot!"); server.Router.Send(unlikeItems, client); return; } if (fromInvItem.StorageCount == itemCount) { if (toInvItem != null) { toInvItem.StorageCount = (byte)(fromInvItem.StorageCount + toInvItem.StorageCount); // huh??? byte - byte is cast as int???? RecvItemUpdateNum itemNum = new RecvItemUpdateNum(toInvItem.InstanceId, toInvItem.StorageCount); server.Router.Send(itemNum, client); RecvItemRemove removeItem = new RecvItemRemove(fromInvItem.InstanceId); server.Router.Send(removeItem, client); client.Character.RemoveInventoryItem(fromInvItem); client.Character.UpdateInventoryItem(toInvItem); } else { fromInvItem.StorageType = toStoreType; fromInvItem.StorageId = toBagId; fromInvItem.StorageSlot = toSlot; RecvItemUpdatePlace itemPlace = new RecvItemUpdatePlace(fromInvItem.InstanceId, fromInvItem.StorageType, fromInvItem.StorageId, fromInvItem.StorageSlot); server.Router.Send(itemPlace, client); client.Character.UpdateInventoryItem(fromInvItem); } } else { byte remainCount = (byte)(fromInvItem.StorageCount - itemCount); // huh??? byte - byte is cast as int???? if (toInvItem != null) { toInvItem.StorageCount = (byte)(itemCount + toInvItem.StorageCount); // huh??? byte - byte is cast as int???? fromInvItem.StorageCount = remainCount; RecvItemUpdateNum toItemNum = new RecvItemUpdateNum(toInvItem.InstanceId, toInvItem.StorageCount); server.Router.Send(toItemNum, client); RecvItemUpdateNum fromItemNum = new RecvItemUpdateNum(fromInvItem.InstanceId, fromInvItem.StorageCount); server.Router.Send(fromItemNum, client); client.Character.RemoveInventoryItem(fromInvItem); client.Character.UpdateInventoryItem(toInvItem); } else { RecvItemUpdateNum updateNum = new RecvItemUpdateNum(fromInvItem.InstanceId, remainCount); server.Router.Send(updateNum, client); InventoryItem newInvItem = client.Character.GetNextInventoryItem(server); newInvItem.StorageCount = (byte)itemCount; newInvItem.StorageType = toStoreType; newInvItem.StorageId = toBagId; newInvItem.StorageSlot = toSlot; newInvItem.StorageItem = item; RecvItemInstanceUnidentified itemUnidentified = new RecvItemInstanceUnidentified(newInvItem); server.Router.Send(itemUnidentified, client); fromInvItem.StorageCount = remainCount; client.Character.UpdateInventoryItem(fromInvItem); } } }
public void Update(NecServer server, NecClient client) { }
public void Leave(NecClient client) { partyMembers.Remove(client); //to-do try/catch }
public void Join(NecClient client) { partyMembers.Add(client); }
public void Enter(NecClient client, MapPosition mapPosition = null) { if (client.map != null) { client.map.Leave(client); } client.map = this; _Logger.Info(client, $"Entering Map: {id}:{fullName}"); // If position is passed in use it and set character position, if null then use map default coords // If this isn't set here, the wrong coords are in character until send_movement_info updates it. if (mapPosition != null) { client.character.x = mapPosition.x; client.character.y = mapPosition.y; client.character.z = mapPosition.z; client.character.heading = mapPosition.heading; } //set character coords to default map entry coords If arriving form another map. else if (client.character.mapId != id) { client.character.x = x; client.character.y = y; client.character.z = z; client.character.heading = orientation; } client.character.mapId = id; client.character.mapChange = false; clientLookup.Add(client); _Logger.Debug($"Client Lookup count is now : {clientLookup.GetAll().Count} for map {id} "); _Logger.Debug($"Character State for character {client.character.name} is {client.character.state}"); //Send your character data to the other living or dead players on the map. //on successful map entry, update the client database position if (!_server.database.UpdateCharacter(client.character)) { _Logger.Error("Could not update the database with current known player position"); } if (!_server.database.UpdateSoul(client.soul)) { _Logger.Error("Could not update the database with soul details "); } //ToDo move all this rendering logic to Send_Map_Entry. We dont need a copy of this logic on every map instance. RecvDataNotifyCharaData myCharacterData = new RecvDataNotifyCharaData(client.character, client.soul.name); //dead //you are dead here. only getting soul form characters. sorry bro. if (client.character.state.HasFlag(CharacterState.SoulForm)) { foreach (NecClient otherClient in clientLookup.GetAll()) { if (otherClient == client) { continue; } if (otherClient.character.state.HasFlag(CharacterState.SoulForm)) { _server.router.Send(myCharacterData, otherClient); } } } else //Bro, you alive! You gon see living characters! { foreach (NecClient otherClient in clientLookup.GetAll()) { if (otherClient == client) { continue; } if (otherClient.character.state.HasFlag(CharacterState.SoulForm)) { continue; } _server.router.Send(myCharacterData, otherClient); } } if (client.union != null) { RecvDataNotifyUnionData myUnionData = new RecvDataNotifyUnionData(client.character, client.union.name); _server.router.Send(this, myUnionData, client); } Task.Delay(TimeSpan.FromSeconds(10)).ContinueWith (t1 => { foreach (MonsterSpawn monsterSpawn in monsterSpawns.Values) { if (monsterSpawn.active) { monsterSpawn.spawnActive = true; if (!monsterSpawn.taskActive) { MonsterTask monsterTask = new MonsterTask(_server, monsterSpawn); if (monsterSpawn.defaultCoords) { monsterTask.monsterHome = monsterSpawn.monsterCoords[0]; } else { monsterTask.monsterHome = monsterSpawn.monsterCoords.Find(x => x.coordIdx == 64); } monsterTask.Start(); } else { if (monsterSpawn.monsterVisible) { _Logger.Debug($"MonsterTask already running for [{monsterSpawn.name}]"); RecvDataNotifyMonsterData monsterData = new RecvDataNotifyMonsterData(monsterSpawn); _server.router.Send(monsterData, client); if (!monsterSpawn.GetAgro()) { monsterSpawn.MonsterMove(_server, client, monsterSpawn.monsterWalkVelocity, 2, 0); } } } } } } ); }
public void Leave(NecClient client) { _logger.Info($"Leaving Map: {Id}", client); ClientLookup.Remove(client); client.Map = null; }
public void Enter(NecClient client) { _logger.Info($"Entering Map: {Id}", client); ClientLookup.Add(client); client.Map = this; }
public void Enter(NecClient client, MapPosition mapPosition = null) { if (client.Map != null) { client.Map.Leave(client); } Logger.Info(client, $"Entering Map: {Id}:{FullName}"); // If position is passed in use it and set character position, if null then use map default coords // If this isn't set here, the wrong coords are in character until send_movement_info updates it. if (mapPosition != null) { client.Character.X = mapPosition.X; client.Character.Y = mapPosition.Y; client.Character.Z = mapPosition.Z; client.Character.Heading = mapPosition.Heading; } else { client.Character.X = this.X; client.Character.Y = this.Y; client.Character.Z = this.Z; client.Character.Heading = this.Orientation; } client.Map = this; client.Character.MapId = Id; client.Character.mapChange = false; ClientLookup.Add(client); Logger.Debug($"Client Lookup count is now : {ClientLookup.GetAll().Count} for map {this.Id} "); RecvDataNotifyCharaData myCharacterData = new RecvDataNotifyCharaData(client.Character, client.Soul.Name); _server.Router.Send(this, myCharacterData, client); if (client.Union != null) { RecvDataNotifyUnionData myUnionData = new RecvDataNotifyUnionData(client.Character, client.Union.Name); _server.Router.Send(this, myUnionData, client); } foreach (MonsterSpawn monsterSpawn in this.MonsterSpawns.Values) { if (monsterSpawn.Active == true) { monsterSpawn.SpawnActive = true; if (!monsterSpawn.TaskActive) { MonsterTask monsterTask = new MonsterTask(_server, monsterSpawn); if (monsterSpawn.defaultCoords) { monsterTask.monsterHome = monsterSpawn.monsterCoords[0]; } else { monsterTask.monsterHome = monsterSpawn.monsterCoords.Find(x => x.CoordIdx == 64); } monsterTask.Start(); } else { if (monsterSpawn.MonsterVisible) { Logger.Debug($"MonsterTask already running for [{monsterSpawn.Name}]"); RecvDataNotifyMonsterData monsterData = new RecvDataNotifyMonsterData(monsterSpawn); _server.Router.Send(monsterData, client); if (!monsterSpawn.GetAgro()) { monsterSpawn.MonsterMove(_server, client, monsterSpawn.MonsterWalkVelocity, (byte)2, (byte)0); } } } } } //on successful map entry, update the client database position if (!_server.Database.UpdateCharacter(client.Character)) { Logger.Error("Could not update the database with current known player position"); } }