protected override void Handle(UserPlayerSelect data, PlayerConnection connection) { var player = gameData.GetPlayer(data.PlayerId); if (player == null) { return; } // the disconnected event is only interesting after a player has // been selected, since the server wont keep track on a logged in user // without a selected player. // if the player is already in a game session // remove it from that session. var activeSession = sessionManager.Get(player); var targetSession = sessionManager.Get(data.SessionKey); if (player.SessionId != null && activeSession != null && activeSession != targetSession) { worldProcessor.RemovePlayer(player); } connection.Disconnected -= ClientDisconnected; connection.Disconnected += ClientDisconnected; connection.PlayerTag = player; connection.SessionKey = data.SessionKey; worldProcessor.LinkToGameSession(data.SessionKey, connection); }
protected override void Handle(PlayerObjectActionRequest data, PlayerConnection connection) { // actionId 0 is examine and is client side if (data.ActionId == 0) { logger.LogDebug("Player sent examine action, ignoring"); return; } logger.LogDebug("Player " + connection.Player.Id + " interacting with object: " + data.ObjectServerId + " action " + data.ActionId + " parameter " + data.ParameterId); var session = sessionManager.Get(connection.Player); var serverObject = session.Objects.Get(data.ObjectServerId); if (serverObject == null) { return; } var action = session.Objects.GetAction(serverObject, data.ActionId); if (action == null) { return; } // if we are already interacting with this object // ignore it. if (session.Objects.HasAcquiredLock(serverObject, connection.Player)) { logger.LogDebug("Player is already interacting with object. Ignore"); return; } worldProcessor.PlayerObjectInteraction(connection.Player, serverObject, action, data.ParameterId); }
public PlayerConnection GetPlayerConnection(Player player) { var session = sessionManager.Get(player); // try and get the player connection, if its null get the session host instead. // as it might be a player without a client (instantiated by Twitch commands) return(GetConnection <PlayerConnection>(x => x != null && x.Player != null && x.Player.Id == player.Id) ?? session.Host); }
public override bool Invoke(Player player, IEntity entity, int parameterId) { if (!(entity is GameObjectInstance obj)) { return(false); } var session = Sessions.Get(player); // if we are already interacting with this object // ignore it. if (session.Objects.HasAcquiredLock(obj, player)) { return(false); } if (!session.Objects.AcquireLock(obj, player)) { return(false); } var gobj = GameData.GetGameObject(obj.ObjectId); if (gobj.InteractItemType > 0) { var inventory = inventoryProvider.GetInventory(player.Id); var requiredItem = inventory.GetItemOfType(gobj.InteractItemType); if (requiredItem == null || requiredItem.Amount < 1) { return(false); } var reqItem = GameData.GetItem(requiredItem.ItemId); if (reqItem.Equippable) { World.SetItemEquipState(player, reqItem, true); } } StartAnimation(player, obj); return(true); }
private bool Invoke( Player player, NpcInstance npc, TimeSpan totalTime, TimeSpan deltaTime) { var attackType = playerState.GetAttackType(player); var session = sessionManager.Get(player); if (!session.Npcs.States.IsEnemy(player, npc)) { return(false); } if (npc.Health <= 0) { return(false); } if (!WithinDistance(player, npc, attackType)) { if (totalTime.TotalMilliseconds < TotalRetryTimeMs) { worldProcessor.SetEntityTimeout(RetryTimeMs, player, npc, Invoke); } return(false); } if (!ReadyForAttack(player, npc, attackType)) { return(false); } PlayerAttack(player, npc, attackType); NpcAttack(player, npc); return(false); }
protected override void Handle(BotPlayerLeave data, PlayerConnection connection) { logger.LogDebug($"Player leave Request from {connection.Player.Id}. User: {data.Username}, Character: {data.CharacterIndex}"); var user = userManager.Get(data.Username); if (user == null) { logger.LogDebug($"Cannot leave game as the user does not exist."); return; } var player = playerProvider.Get(user, data.CharacterIndex); if (player == null) { // this user doesnt have any players yet. // create one for them. logger.LogDebug($"Cannot leave game, character specified does not exist."); return; } var session = sessionManager.Get(data.Session); if (session != null) { if (!sessionManager.InSession(user, session)) { // we cannot join with another player as we are already in // this session. logger.LogDebug($"Cannot leave game, user is not playing on this session."); return; } if (session.Host != null && session.Host.InstanceID == connection.InstanceID) { logger.LogDebug($"The host cannot leave the game."); return; } worldProcessor.RemovePlayer(player); } }
protected override void Handle(NpcTradeSellItem data, PlayerConnection connection) { logger.LogDebug("Player " + connection.Player.Id + " trying to sell item to NPC " + data.NpcServerId + " itemId: " + data.ItemId + " amount " + data.Amount); var session = sessionManager.Get(connection.Player); var npc = session.Npcs.Get(data.NpcServerId); if (npc == null) { return; } var inventory = inventoryProvider.GetInventory(connection.Player.Id); if (!inventory.HasItem(data.ItemId, data.Amount)) { return; } worldProcessor.PlayerSellItem(connection.Player, npc, data.ItemId, data.Amount); }
public override bool Invoke( Player player, IEntity obj, int parameterId) { if (!(obj is NpcInstance npc)) { return(false); } var session = sessionManager.Get(player); var shopInventory = session.Npcs.Inventories.GetInventory(npc.Id); if (shopInventory == null) { return(false); } worldProcessor.OpenTradeWindow(player, npc, "Test shop", shopInventory); return(false); }
protected override void Handle(PlayerMoveRequest data, PlayerConnection connection) { if (connection.Player == null) { #if RELEASE logger.LogError($"Move request from {connection.InstanceID}. But has not selected a player."); #endif return; } logger.LogDebug($"Move Request from {connection.Player.Id} from {data.Position} to {data.Destination}"); var player = connection.Player; var transform = gameData.GetTransform(player.TransformId); transform.SetPosition(data.Position); transform.SetDestination(data.Destination); var session = sessionManager.Get(player); // player moves, release any locked objects the player may have. session.Objects.ReleaseLocks(player); // exit combat if we are in one. This will cancel any ongoing attacks. playerState.ExitCombat(player); foreach (var playerConnection in connectionProvider.GetAllActivePlayerConnections(session)) { playerConnection.Send(new PlayerMoveResponse() { PlayerId = player.Id, Destination = data.Destination, Position = data.Position, Running = data.Running }, Shinobytes.Ravenfall.RavenNet.SendOption.Reliable); } }
protected override void Handle(PlayerNpcActionRequest data, PlayerConnection connection) { // actionId 0 is examine and is client side if (data.ActionId == 0) { logger.LogDebug("Player sent examine action, ignoring"); return; } var session = sessionManager.Get(connection.Player); logger.LogDebug("Player " + connection.Player.Id + " interacting with npc: " + data.NpcServerId + " action " + data.ActionId + " parameter " + data.ParameterId); var npc = session.Npcs.Get(data.NpcServerId); if (npc == null) { return; } var action = session.Npcs.GetAction(npc, data.ActionId); if (action == null) { return; } //// if we are already interacting with this object //// ignore it. //if (npcProvider.HasAcquiredObjectLock(npc, connection.Player)) //{ // logger.Debug("Player is already interacting with object. Ignore"); // return; //} worldProcessor.PlayerNpcInteraction(connection.Player, npc, action, data.ParameterId); }
protected override void Handle(BotPlayerJoin data, PlayerConnection connection) { logger.LogDebug($"Player join Request from {connection.Player.Id}. User: {data.Username}, Character: {data.CharacterIndex}"); var user = userManager.GetByTwitchId(data.TwitchId) ?? userManager.GetByYouTubeId(data.TwitchId) ?? userManager.Get(data.Username); if (user == null) { user = userManager.Create(data.Username, data.TwitchId, data.YouTubeId); } else { userManager.LinkSreamerId(user, data.TwitchId, data.YouTubeId); } var player = playerProvider.Get(user, data.CharacterIndex); if (player == null) { // this user doesnt have any players yet. // create one for them. player = playerProvider.CreateRandom(user, user.Username); } var session = sessionManager.Get(data.Session); if (session != null) { if (sessionManager.InSession(user, session)) { // we cannot join with another player as we are already in // this session. logger.LogDebug($"Cannot add User: {data.Username}, Character: {data.CharacterIndex} to this session as the user already have a player in this session."); return; } // check if this player is in an active session already. // if it is, we cannot join IF that session is hosted by the same user. // otherwise remove it from the existing session var activePlayerSession = sessionManager.Get(player); if (activePlayerSession != null) { if (activePlayerSession.Host != null && activePlayerSession.Host.Player != null && activePlayerSession.Host.Player.Id == player.Id) { logger.LogDebug($"Cannot add User: {data.Username}, Character: {data.CharacterIndex} to this session as the character is being used in a hosted session."); return; } var playerConnection = connectionProvider.GetPlayerConnection(player); if (playerConnection != null && playerConnection.User?.Id == user.Id) { logger.LogDebug($"Cannot add User: {data.Username}, Character: {data.CharacterIndex} to this session as the character is being used in a hosted session."); return; } worldProcessor.RemovePlayer(player); } session.AddPlayer(player); worldProcessor.AddPlayer(player); } }
public void SendChatMessage(Player player, int channelID, string message) { var session = sessions.Get(player); var connections = connectionProvider.GetConnectedActivePlayerConnections(session); // var connections = chatHandler.GetChannelPlayers(channelID); foreach (var connection in connections) { connection.Send(ChatMessage.Create(player, channelID, message), SendOption.Reliable); } }