public static SystemLocationDto ToDto(this SystemLocation systemLocation) { return(new SystemLocationDto { SystemLocationId = systemLocation.SystemLocationId, Name = systemLocation.Name, Location = systemLocation.Location }); }
public override void SetDestSystemLocation(SystemLocation dest) { base.SetDestSystemLocation(dest); if (Player != null) { Player.Persist(); } else { this.Persist(); } }
public override bool Update() { if (Target != null && !this.InSpace) //Follow Target { SystemLocation dLocation = null; SystemBody body = this.Target as SystemBody; if (body != null) { dLocation = SystemLocation.GetUpdatedLocation(body); } else { dLocation = this.Target.SystemLocation; } if (dLocation.GetInSystemDistance(this.SystemLocation) > (1000)) { SetDestSystemLocation(dLocation); } } this.IsDirty |= base.Update(); if (this.IsDirty) { if (Player != null) { Player.Location = new GameLocation(this.Coords); Player.Location.UpdateSystemBody(this.SystemLocation, this.InSpace); Player.Persist(); } return(true); } else { return(false); } }
private BattleCommand GetBattleCommand(SpaceShip ship, SpaceShip target, string command) { int rangePoints = 0, hitPointsE = 0, hitPointsM = 0, multiplier = 0, defencePointsE = 0, defencePointsM = 0; var range = ship.SystemLocation.GetInSystemDistance(target.SystemLocation); bool commandOk = false; switch (command.ToUpper().Trim()) { case "M": if (ship.MissileLaunchers != null) { foreach (var missileLauncher in ship.MissileLaunchers) { if (missileLauncher.Activate()) { rangePoints += GetRangePoints(missileLauncher, range); hitPointsM += missileLauncher.HitPoints; multiplier++; commandOk = true; } } } if (commandOk) { if (ship.Player != null) { ship.Player.SendPlayerMessage(new PlayerMessage( "SHIP", PlayerMessageType.Battle, string.Format("{0} missiles fired at target {1}", multiplier, target.Code))); } if (target.Player != null) { target.Player.SendPlayerMessage(new PlayerMessage( ship.Code, PlayerMessageType.Battle, string.Format("missile incomming! range: {0}", SystemLocation.GetDistanceDesc(range)))); } } else { ship.Player.SendPlayerMessage(new PlayerMessage( "SHIP", PlayerMessageType.BattleWarning, "Not enougf enery to fire missiles")); } break; case "F": if (ship.Lasers != null) { foreach (var laser in ship.Lasers) { if (laser.Activate()) { rangePoints += GetRangePoints(laser, range); hitPointsE += laser.HitPoints; multiplier++; commandOk = true; } } } if (commandOk) { if (ship.Player != null) { ship.Player.SendPlayerMessage(new PlayerMessage( "SHIP", PlayerMessageType.Battle, string.Format("{0} lasers fired at target {1}", multiplier, target.Code))); } if (target.Player != null) { target.Player.SendPlayerMessage(new PlayerMessage( ship.Code, PlayerMessageType.Battle, string.Format("laser fire! range: {0}", SystemLocation.GetDistanceDesc(range)))); } } else { ship.Player.SendPlayerMessage(new PlayerMessage( "SHIP", PlayerMessageType.BattleWarning, "Not enougf enery to fire lasers")); } break; case "E": defencePointsE += 2; //Todo calculate this based on spaceship and experience; defencePointsM += 2; //Todo calculate this based on spaceship and experience; multiplier = 1; commandOk = true; ship.Player.SendPlayerMessage(new PlayerMessage( "SHIP", PlayerMessageType.Battle, "Performing evasive manouvers")); target.Player.SendPlayerMessage(new PlayerMessage( ship.Code, PlayerMessageType.Battle, "target is performing evasive manouvers")); break; case "X": break; case "S": break; } return(new BattleCommand(command, hitPointsE, hitPointsM, rangePoints, multiplier, defencePointsE, defencePointsM)); }
public void FlyTo(SystemLocation dest) { SetDestSystemLocation(dest); }
public string GetHud() { List <SectorObject> secObjects = new List <SectorObject>(); List <ObjInfo> objects = new List <ObjInfo>(); GameManager manager = GameManager.Instance; //int smallHudWidth = 30, smallHudHeight = 15; int smallHudWidth = 20, smallHudHeight = 12; TextCanvas closeDistHUDCanvas = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); closeDistHUDCanvas.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); closeDistHUDCanvas.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas nearbyShipsHUDCanvas = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); nearbyShipsHUDCanvas.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); nearbyShipsHUDCanvas.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas closeDistHUDCanvas_Target = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); closeDistHUDCanvas_Target.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); closeDistHUDCanvas_Target.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas nearbyEShipsHUDCanvas = new TextCanvas(smallHudWidth, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); nearbyEShipsHUDCanvas.DrawGrid(0, 0, smallHudWidth, smallHudHeight, (byte)234); nearbyEShipsHUDCanvas.DrawRectangle(0, 0, smallHudWidth, smallHudHeight, (byte)ANSI.ANSIColor_8.Cyan); TextCanvas canvas = new TextCanvas(Width - 5, smallHudHeight, TextCanvas.NumOfColorsEnum.XTERM256); //canvas.DrawRectangle(0, 0, Width -5, Height -5, (byte)ANSI.ANSIColor_8.Cyan); //canvas.DrawString(Width / 2, Height / 2, "▲", (byte)ANSI.ANSIColor_16.Green, (byte)ANSI.ANSIColor_16.Black); StarSystem system = this.Player.Player.Location.StarSystem; SpaceShip ship = this.Player.Player.SpaceShip; if (system == null) { return(string.Empty); } var sysM = manager.StarSystemManager.GetStarSystemArea(system.Coords); secObjects.AddRange(system.SystemBodies); secObjects.AddRange(sysM.GetShipsInSystem().Cast <SectorObject>()); secObjects.Add(system); if (ship.Target != null) { secObjects.Add(ship.Target); } secObjects.Add(ship); double minDist = Double.MaxValue; double minDistShips = Double.MaxValue; double minDist_Target = Double.MaxValue; double minDistEShips = Double.MaxValue; foreach (SectorObject secObject in secObjects) { double dist = secObject.SystemLocation.GetInSystemDistance(ship.SystemLocation); double dist_Target = (ship.Target != null) ? secObject.SystemLocation.GetInSystemDistance(ship.Target.SystemLocation) : 0; if (dist < minDist && dist > 0) { minDist = dist; } if (dist_Target < minDist_Target && dist_Target > 0) { minDist_Target = dist_Target; } SpaceShip shipObj = secObject as SpaceShip; SystemBody bodyObj = secObject as SystemBody; StarSystem sysObj = secObject as StarSystem; ObjInfo info = new ObjInfo(); info.X = secObject.SystemLocation.X; info.Y = secObject.SystemLocation.Y; info.Distance = dist; if (secObject == ship) { info.IsPlayer = true; } if (secObject == ship.Target) { info.IsTarget = true; } if (shipObj != null) { info.Display = "▪"; if (dist < minDistShips && dist > 0) { minDistShips = dist; } if (info.IsEnemy) { if (dist < minDistEShips && dist > 0) { minDistEShips = dist; } } } else if (bodyObj != null) { info.Display = "●"; } else if (sysObj != null) { info.Display = "☼"; } objects.Add(info); } if (minDist_Target == Double.MaxValue) { minDist_Target = 0; } if (minDistShips == Double.MaxValue) { minDistShips = 0; } if (minDistEShips == Double.MaxValue) { minDistEShips = 0; } //write close distance HUD double hudRange = minDist * (smallHudHeight / 2); // 149598000 / 2; double zX = ship.SystemLocation.X; double zY = ship.SystemLocation.Y; #region Close Distance HUD foreach (var obj in objects) { if (obj.Distance < (hudRange)) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } closeDistHUDCanvas.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } closeDistHUDCanvas.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion #region Nearby Ships HUD hudRange = minDistShips * (smallHudHeight / 2); foreach (var obj in objects) { if (obj.Distance < (hudRange)) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } nearbyShipsHUDCanvas.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } nearbyShipsHUDCanvas.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion #region Nearby Enemy Ships HUD hudRange = minDistEShips * (smallHudHeight / 2); foreach (var obj in objects) { if (obj.Distance < (hudRange) && obj.IsEnemy) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } nearbyEShipsHUDCanvas.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } nearbyEShipsHUDCanvas.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion #region Target Close Distance HUD hudRange = minDist_Target * (smallHudHeight / 2); // 149598000 / 2; if (ship.Target != null) { zX = ship.Target.SystemLocation.X; zY = ship.Target.SystemLocation.Y; } foreach (var obj in objects) { if (obj.Distance < (hudRange)) { double x = obj.X - zX, y = obj.Y - zY; int cX = (int)(x * smallHudWidth / hudRange + (smallHudWidth / 2)); int cY = (int)(y * smallHudHeight / hudRange + (smallHudHeight / 2)); byte foreColor = (byte)ANSI.ANSIColor_16.Cyan; if (obj.IsPlayer) { foreColor = (byte)ANSI.ANSIColor_16.Green; } if (obj.IsEnemy) { foreColor = (byte)ANSI.ANSIColor_16.Red; } if (obj.IsTarget) { foreColor = (byte)ANSI.ANSIColor_16.DarkYellow; } closeDistHUDCanvas_Target.DrawString(cX, cY, obj.Display, foreColor, (byte)ANSI.ANSIColor_16.Black); } } closeDistHUDCanvas_Target.DrawString(1, 1, string.Format("{0}", SystemLocation.GetDistanceDesc(hudRange)), 6, 0); #endregion canvas.DrawRawData(0, 0, closeDistHUDCanvas.GetRawData()); canvas.DrawRawData(smallHudWidth, 0, nearbyShipsHUDCanvas.GetRawData()); canvas.DrawRawData(smallHudWidth * 2, 0, closeDistHUDCanvas_Target.GetRawData()); canvas.DrawRawData(smallHudWidth * 3, 0, nearbyEShipsHUDCanvas.GetRawData()); long baseX, baseY; baseX = (long)(ship.SystemLocation.X / minDist); baseY = (long)(ship.SystemLocation.Y / minDist); return(canvas.ToString()); }