public virtual int SpawnPlayableShip(string requester, string requestedType, string requestedName) { string typeToUse = requestedType; // something wants a new player ship to be spawned if (typeToUse == string.Empty) { typeToUse = GetPlayerShipTemplate(); } ShipTemplate template = TemplateDatabase.GetTemplate(typeToUse) as ShipTemplate; if (!GetPlayableShips().Contains(template) && GetPlayableShips().Count > 0) { template = GetPlayableShips()[0]; } Zone spawnZone = ZoneManager.FindZone(GetDefaultZoneName()); if (spawnZone == null) { var zones = ZoneManager.GetZones(); if (zones.Length == 0) { return(-1); // no zones to spawn a ship in } spawnZone = zones[0]; } var ship = new Ship(template); ship.Name = FilterShipName(requestedName, requestedType); spawnZone.Add(ship); return(ship.GUID); }
private void HandleShipRequest(object sender, ShipMessage msg) { ShipPeer peer = sender as ShipPeer; ShipRequest request = msg as ShipRequest; JoinShipResponce responce = new JoinShipResponce(); PlayerShip shipToLink = null; if (peer.LinkedShip != null) { shipToLink = peer.LinkedShip; } else { if (request.Join) { shipToLink = PlayerShips.Find((x) => x.LinkedShip.GUID == request.RequestedShipID); if (shipToLink == null || shipToLink.Locked && shipToLink.Password != request.Password) { responce.Error = true; responce.Message = "NoShipToJoin"; peer.Send(responce); return; // nope! } else { if (!shipToLink.ControlingPeers.Contains(peer)) { shipToLink.ControlingPeers.Add(peer); } peer.LinkedShip = shipToLink; } } } if (shipToLink == null) { var template = TemplateDatabase.GetTemplate(request.RequestedShipID); int shipID = ActiveScenario.SpawnPlayableShip(peer.Connection.RemoteUniqueIdentifier.ToString(), template == null ? string.Empty : template.Name, request.Name); var ship = ZoneManager.GetFirstMatch(new PlayableShipFinder(shipID)) as Ship; shipToLink = new PlayerShip(); shipToLink.LinkedShip = ship; shipToLink.ControlingPeers.Add(peer); shipToLink.Locked = request.Password != string.Empty; shipToLink.Password = request.Password; peer.LinkedShip = shipToLink; PlayerShips.Add(shipToLink); } // send back the responce with the ship they are on responce.Error = false; responce.Message = shipToLink.LinkedShip.Name; responce.ShipID = shipToLink.LinkedShip.GUID; peer.Send(responce); // send an info and status update }