/// <summary> /// Returns true if colonization succesful /// </summary> /// <param name="colonizingShip"></param> /// <param name="xPos">ref in case positions are modified to accomodate placement (e.g. snap to nearest tile)</param> /// <param name="yPos">ref in case positions are modified to accomodate placement (e.g. snap to nearest tile)</param> /// <returns></returns> public bool TryColonizePlanet(Planet planet, IShip colonizingShip, WarpManager wm, LocatorService ls, float xPos, float yPos, out string resultMessage, IDatabaseManager databaseManager) { if (planet.IsColonized) { resultMessage = "Planet is already colonized!"; return(false); } else if (colonizingShip.CurrentEnergy != colonizingShip.ShipStats.Energy)//Is energy full? { resultMessage = "Not enough energy."; return(false); } else if (!planet.GetValidStructurePosition(new CommandCenterStats(), ref xPos, ref yPos))//Check for wall overlap here { resultMessage = "Invalid placement location."; return(false); } else if (colonizingShip.Cargo.GetCargoAmount(StatelessCargoTypes.Biodome) > 0) {//if everything checks out ColonyFactory.CreateColony(xPos, yPos, colonizingShip.GetPlayer(), planet, ls); List <IShip> ShipsToMove = new List <IShip>(1); //Kick all non-allied players into space foreach (var s in planet.GetShips()) { if (s.Value != colonizingShip) { if (s.Value is NPCShip && !_teamLocator.AreAllied(((NPCShip)s.Value), planet.GetOwner())) { ShipsToMove.Add(s.Value); } else if (s.Value is PlayerShip && !_teamLocator.AreAllied(s.Value.GetPlayer(), planet.GetOwner())) { ShipsToMove.Add(s.Value); } } } foreach (var s in ShipsToMove) { wm.ChangeArea((int)planet.ParentAreaID, s, false, true); } resultMessage = "Colonization Successful."; return(true); } else { resultMessage = "No biodome found in ship cargo."; return(false); } }
/// <summary> /// Revives a player and sends him to sendHere /// </summary> public IShip ReviveShip(IShip s, IArea sendHere, float healthMultiplier, float shieldsMultipler) { s.CurrentHealth = s.ShipStats.MaxHealth; s.IsDead = false; _warpManager.ChangeArea(sendHere.Id, s, false, sendHere.AreaType == AreaTypes.System); if (!s.GetPlayer().IsOnline) { return(s); } var health = (int)(s.MaxHealth * healthMultiplier); var shields = (int)(s.MaxShields * shieldsMultipler); _messageManager.SendReviveMessage(s, health, shields); return(s); }