private void SendFleet(SilverlightControlPlanet planetFrom, SilverlightControlPlanet planetTo, int ships) { if (planetFrom.ShipNum > 0) { int send_ships = Math.Min(ships, planetFrom.ShipNum); SilverlightControlFleet fleet = new SilverlightControlFleet(); fleet.SetPlanets(planetFrom, planetTo); fleet.ShipNum = send_ships; if (GameDifficulty == Difficulty.Hard && planetFrom.Owner == PlanetOwner.Enemy) { fleet.Speed *= GameParameters.HARD_LEVEL_SPEED_MODIFIER; } fleet.SetValue(Canvas.LeftProperty, planetFrom.GetValue(Canvas.LeftProperty)); fleet.SetValue(Canvas.TopProperty, planetFrom.GetValue(Canvas.TopProperty)); fleets.Add(fleet); CanvasGame.Children.Add(fleet); planetFrom.ShipNum -= send_ships; } }
public override void LoadFromResponse(string apiname, dynamic data) { switch (apiname) { case "api_req_combined_battle/goback_port": foreach (int index in KCDatabase.Instance.Battle.Result.EscapingShipIndex) { Fleets[(index - 1) < 6 ? 1 : 2].Escape((index - 1) % 6); } break; case "api_get_member/ndock": foreach (var fleet in Fleets.Values) { fleet.LoadFromResponse(apiname, data); } break; default: base.LoadFromResponse(apiname, (object)data); //api_port/port, api_get_member/deck foreach (var elem in data) { int id = (int)elem.api_id; if (!Fleets.ContainsKey(id)) { var a = new FleetData(); a.LoadFromResponse(apiname, elem); Fleets.Add(a); } else { Fleets[id].LoadFromResponse(apiname, elem); } } break; } //泊地修理関連 if (apiname == "api_port/port") { if ((DateTime.Now - AnchorageRepairingTimer).TotalMinutes >= 20 || AnchorageRepairingTimer == DateTime.MinValue) { ResetAnchorageRepairing(); } } }
// Issue an order. This function takes num_ships off the source_planet, // puts them into a newly-created fleet, calculates the distance to the // destination_planet, and sets the fleet's total trip time to that // distance. Checks that the given player_id is allowed to give the given // order. If not, the offending player is kicked from the game. If the // order was carried out without any issue, and everything is peachy, then // 0 is returned. Otherwise, -1 is returned. public int IssueOrder(int playerID, int sourcePlanet, int destinationPlanet, int numShips) { Planet source = Planets[sourcePlanet]; bool isIllegalMove = source.Owner != playerID || numShips > source.NumShips || numShips < 0; if (isIllegalMove) { string message = String.Format( "Illegal move player: {0}. From planet {1} owned by {2} with {3} ships, wants to send {4} ships", playerID, sourcePlanet, source.Owner, numShips, source.NumShips); System.Diagnostics.Debug.Assert(false, message); WriteLogMessage(message); DropPlayer(playerID); return(-1); } source.RemoveShips(numShips); string fleetKey = playerID + ";" + sourcePlanet + ";" + destinationPlanet; Fleet duplicate; if (deDupe.TryGetValue(fleetKey, out duplicate)) { //ha there is no add... duplicate.RemoveShips(-numShips); } else { int distance = Distance(sourcePlanet, destinationPlanet); Fleet f = new Fleet(source.Owner, numShips, sourcePlanet, destinationPlanet, distance, distance); deDupe.Add(fleetKey, f); Fleets.Add(f); } return(0); }
public override void LoadFromResponse(string apiname, dynamic data) { switch (apiname) { case "api_req_sortie/goback_port": case "api_req_combined_battle/goback_port": { var battle = KCDatabase.Instance.Battle; foreach (int ii in battle.Result.EscapingShipIndex) { int index = ii - 1; if (index < battle.FirstBattle.Initial.FriendFleet.Members.Count) { battle.FirstBattle.Initial.FriendFleet.Escape(index); } else { battle.FirstBattle.Initial.FriendFleetEscort.Escape(index - 6); } } } break; case "api_get_member/ndock": foreach (var fleet in Fleets.Values) { fleet.LoadFromResponse(apiname, data); } break; case "api_req_hensei/preset_select": { int id = (int)data.api_id; if (!Fleets.ContainsKey(id)) { var a = new FleetData(); a.LoadFromResponse(apiname, data); Fleets.Add(a); } else { Fleets[id].LoadFromResponse(apiname, data); } } break; default: base.LoadFromResponse(apiname, (object)data); //api_port/port, api_get_member/deck foreach (var elem in data) { int id = (int)elem.api_id; if (!Fleets.ContainsKey(id)) { var a = new FleetData(); a.LoadFromResponse(apiname, elem); Fleets.Add(a); } else { Fleets[id].LoadFromResponse(apiname, elem); } } break; } // 泊地修理・コンディションの処理 if (apiname == "api_port/port") { if ((DateTime.Now - AnchorageRepairingTimer).TotalMinutes >= 20) { StartAnchorageRepairingTimer(); } else { CheckAnchorageRepairingHealing(); } UpdateConditionPrediction(); } }
// Parses a game state from a string. On success, returns 1. On failure, // returns 0. private int ParseGameState(String s) { Planets.Clear(); Fleets.Clear(); ClearDupeCache(); //PORT: Make WindowsCompatible String[] lines = s.Replace("\r\n", "\n").Split('\n'); int planetid = 0; for (int i = 0; i < lines.Length; ++i) { String line = lines[i]; int commentBegin = line.IndexOf('#'); if (commentBegin >= 0) { line = line.Substring(0, commentBegin); } if (line.Trim().Length == 0) { continue; } String[] tokens = line.Split(' '); if (tokens.Length == 0) { continue; } if (tokens[0].Equals("P")) { if (tokens.Length != 6) { return(0); } double x = Double.parseDouble(tokens[1]); double y = Double.parseDouble(tokens[2]); int owner = Integer.parseInt(tokens[3]); int numShips = Integer.parseInt(tokens[4]); int growthRate = Integer.parseInt(tokens[5]); Planet p = new Planet(planetid++, owner, numShips, growthRate, x, y); Planets.Add(p); if (gamePlayback.Length > 0) { gamePlayback.Append(":"); } gamePlayback.Append("" + x + "," + y + "," + owner + "," + numShips + "," + growthRate); } else if (tokens[0].Equals("F")) { if (tokens.Length != 7) { return(0); } int owner = Integer.parseInt(tokens[1]); int numShips = Integer.parseInt(tokens[2]); int source = Integer.parseInt(tokens[3]); int destination = Integer.parseInt(tokens[4]); int totalTripLength = Integer.parseInt(tokens[5]); int turnsRemaining = Integer.parseInt(tokens[6]); Fleet f = new Fleet(owner, numShips, source, destination, totalTripLength, turnsRemaining); Fleets.Add(f); } else { return(0); } } gamePlayback.Append("|"); return(1); }
public void AddFleet(Fleet f) { Fleets.Add(f); }
public void AddFleet(Fleet fleet) { Fleets.Add(fleet); }