/// <summary> /// Leaf was hit by tool. /// </summary> /// <param name="toolTransform">Transform of the tool.</param> /// <param name="toolType">Type of tool equipped.</param> /// <param name="toolMode">Mode of current tool.</param> public override void HitByTool(PlayerServer player, Transform toolTransform, ToolType toolType, ToolMode toolMode) { // Call the base hit by tool. base.HitByTool(player, toolTransform, toolType, toolMode); // If this is a leaf blower. if (toolType == ToolType.BLOWER) { // Get the forward of the tool. Vector3 toolForward = toolTransform.Forward; // Get the vector from the tool to the lefa. Vector3 toolToObj = Transform.Position - toolTransform.Position; // Get the angle between the two vectors. float angleBetween = Utility.AngleBetweenVectors(toolForward, toolToObj); // If the angle is negative, rotate the leaf left. if (angleBetween < 0.0f) { RandomRotateLeft(); } // If the angle is postiive, rotate the leaf right. else { RandomRotateRight(); } } }
/// <summary> /// Function that determines what happens when the player is hit by another player's tool. /// </summary> /// <param name="toolTransform">Position of the other player.</param> /// <param name="toolType">Type of tool hit by.</param> /// <param name="toolMode">Tool mode hit by.</param> public override void HitByTool(PlayerServer player, Transform toolTransform, ToolType toolType, ToolMode toolMode) { if (!Dead) { base.HitByTool(player, toolTransform, toolType, toolMode); } }
public PlayerServer CreateNewPlayer() { //Assign id based on the next spot in the gameObjectDict. int id = gameObjectDict.Count(); //Create two players, one to send as an active player to client. Other to keep track of on server. PlayerServer newPlayer = matchHandler.AddPlayer(); newPlayer.Register(); playerServerList.Add(newPlayer); //Create the active player with the same id as the newPlayer. PlayerServer newActivePlayer = new PlayerServer(newPlayer.Team) { ObjectType = ObjectType.ACTIVE_PLAYER, Id = newPlayer.Id }; newActivePlayer.Transform.Position = newPlayer.Transform.Position; CreatePlayerPacket objPacket = (CreatePlayerPacket)ServerPacketFactory.NewCreatePacket(newPlayer); // Sending this new packet before the new client joins. networkServer.SendAll(PacketUtil.Serialize(objPacket)); return(newActivePlayer); }
/// <summary> /// Function called when this object is hit by a player's tool. /// </summary> /// <param name="toolTransform">Position of the player that hit this object.</param> /// <param name="toolType">Type of tool equipped.</param> /// <param name="toolMode">Mode (primary or secondary) of tool equipped.</param> public override void HitByTool(PlayerServer player, Transform toolTransform, ToolType toolType, ToolMode toolMode) { // Call the base's HitByTool function (burns the object) base.HitByTool(player, toolTransform, toolType, toolMode); // Get information about the tool that was used on this object. ToolInfo toolInfo = Tool.GetToolInfo(toolType); // If this is a leafblower. if (toolType == ToolType.BLOWER) { // If this is the leafblower's primary tool. if (toolMode == ToolMode.PRIMARY) { // Get the force of this tool. float toolForce = toolInfo.Force; // Get the vector from the player to the object. Vector3 playerToObj = Transform.Position - toolTransform.Position; playerToObj.Y = 0.0f; float distance = playerToObj.Length(); // Divide the vector by the range of the tool to normalize it. playerToObj /= toolInfo.Range; // Multiply tool force by distance so that it's stronger on objects that are closer. // Also make sure denominator can't be zero. toolForce /= Math.Max(0.001f, distance * Constants.BLOWER_DISTANCE_SCALER); // Apply a force in the direction of the player -> object. Vector3 force = playerToObj * toolForce; ApplyForce(force); // Console.WriteLine("Blowing object {0} {1} with force {2}", this.GetType().ToString(), Id, force); } else if (toolMode == ToolMode.SECONDARY) { // Get the force of this tool. float toolForce = toolInfo.Force * 0.25f; float toolRange = toolInfo.Range * 0.5f; // Get the vector from the player to the object. Vector3 objToPlayer = toolTransform.Position - Transform.Position; objToPlayer.Y = 0.0f; float distance = objToPlayer.Length(); // Divide the vector by the range of the tool to normalize it. objToPlayer /= toolRange; // Multiply tool force by distance so that it's stronger on objects that are closer. // Also make sure denominator can't be zero. toolForce /= Math.Max(0.001f, distance * Constants.BLOWER_DISTANCE_SCALER); // Apply a force in the direction of the player -> object. Vector3 force = objToPlayer * toolForce; ApplyForce(force); } } }
/// <summary> /// Extinguish this object. /// </summary> public void Extinguish() { // Extinguish the object by setting burn and blow frames to 0. burnFrames = 0; blowFrames = 0; ExtinguishTimer.Stop(); PlayerThatSetThisOnFire = null; }
internal PlayerServer AddPlayer() { Team minPlayerTeam = match.teams.Aggregate( (curMin, x) => (curMin == null || (x.numPlayers) < curMin.numPlayers ? x : curMin) ); PlayerServer newPlayer = new PlayerServer(minPlayerTeam); minPlayerTeam.numPlayers++; return(newPlayer); }
/// <summary> /// Function called when this object is hit by the player's active tool (in range) /// </summary> /// <param name="toolTransform">Position of the player. </param> /// <param name="toolType">Type of the tool hit by.</param> /// <param name="toolMode">Mode (primary or secondary) the tool was in.</param> public virtual void HitByTool(PlayerServer player, Transform toolTransform, ToolType toolType, ToolMode toolMode) { // Get information about the tool that was used on this object. ToolInfo toolInfo = Tool.GetToolInfo(toolType); LastPlayerInteracted = player; if (toolType == ToolType.THROWER) { // If it's the primary flamethrower function if (toolMode == ToolMode.PRIMARY) { CatchFire(); PlayerThatSetThisOnFire = player; if (burnFrames == 0) { if (this is LeafServer) { player.playerStats.numLeavesSetOnFire++; } else if (this is PlayerServer me) { if (me.Team == player.Team) { player.playerStats.numTeammateSetOnFire++; } else { player.playerStats.numEnemiesSetOnFire++; } } } } } if (toolType == ToolType.BLOWER) { // If this is the primary function of the blower. if (toolMode == ToolMode.PRIMARY && Burning) { blowFrames++; } else { blowFrames = 0; } } else { blowFrames = 0; } }
private void HandleIncomingPackets() { for (int i = 0; i < networkServer.PlayerPackets.Count(); i++) { RequestPacket packet = networkServer.PlayerPackets[i]; int playerId = packet.GetId(); gameObjectDict.TryGetValue(playerId, out GameObjectServer playerGameObject); if (packet != null && playerGameObject != null) { PlayerServer player = (PlayerServer)playerGameObject; player.UpdateFromPacket(networkServer.PlayerPackets[i]); } } }
/// <summary> /// Add the tool effects of all the players. /// </summary> public void AddPlayerToolEffects() { // Iterate through all players. for (int i = 0; i < playerServerList.Count; i++) { // Get this player. PlayerServer player = playerServerList[i]; //Only check if tools are active. if (player.ActiveToolMode != ToolMode.NONE) { // Affect all objects within range of the player. player.AffectObjectsInToolRange(GetInteractableObjects()); } } }
/// <summary> /// Creates a new player in the game, sends it out to all the clients, /// and then sends that active player to the clientSocket that is /// specified /// </summary> /// <param name="clientSocket"> /// The socket that needs an active player /// </param> private void ProcessNewPlayer(Socket clientSocket) { PlayerServer player = GameServer.instance.CreateNewPlayer(); //Associate player's id with with the socket. playerDictionary.Add(clientSocket, player.Id); BasePacket createPlayPack = ServerPacketFactory.NewCreatePacket(player); // Create createObjectPacket, send to client byte[] data = PacketUtil.Serialize(createPlayPack); Send(clientSocket, data); MatchStartPacket informStart = new MatchStartPacket(MatchHandler.instance.GetMatch().GetTimeElapsed().Milliseconds); Send(clientSocket, PacketUtil.Serialize(informStart)); }
internal void DisconnectPlayer(PlayerServer player) { player.Team.numPlayers--; Destroy(player); }