/// <summary> /// attacks region - manage ammo type. /// </summary> /// <param name="ob"></param> protected void AttackRegion(BoardObject ob) { Position s = ob.Position; Ammo a = new Ammo(new ObjectID(this.ObjectID.PlayerID, _simulation.Players[this.ObjectID.PlayerID].GenerateObjectID()), this.Position, ob.Position, this.AmmoType, this._ammoSpeed, this._firePower, this.ammoDamageRange, _simulation); InfoLog.WriteInfo(a.ObjectID.ToString() + " for ammunition ", EPrefix.GObj); this._simulation.AddAmmo(a); this._simulation.OnShoot(a); /* * * List<BoardObject> objectsInRange = GetObjectsInRange(s); * * foreach (BoardObject boardObject in objectsInRange) { * if (boardObject.BoardObjectClass == BoardObjectClass.Building) { * _simulation.handleAttackBuilding((Building)boardObject, this); * } else { * _simulation.handleAttackUnit((Unit)boardObject, this); * } * } */ this._remainingTurnsToReload = this._reloadTime; }
public Server(int PortNumber) : base() { _portNumber = PortNumber; #pragma warning disable 0618 _listener = new TcpListener(_portNumber); #pragma warning restore 0618 try { _listener.Start(); } catch (SocketException) { MessageBox.Show("Port that server uses is used by different process"); _serverEnd = true; } InfoLog.WriteInfo("Server listnening started successfully", EPrefix.ServerInformation); _playersUnlogged = new Dictionary <short, Player>(); _playerCollection = new Dictionary <short, Player>(); MessageHandler = new MenuMessageHandler(this); MessageHandler.SetSender(_msgSender); StartMessageProcessing(); _chat = new Chat(_msgSender); _gameManager = new GameManager(this, _msgSender); InfoLog.WriteInfo("Server menu message handling started successfully", EPrefix.ServerInformation); }
public void Stop() { isProcessing = false; readStream.Close(); InfoLog.WriteInfo("Receiver stopped", EPrefix.ClientInformation); }
public void Mute() { this.Volume = 0; isMuted = true; InfoLog.WriteInfo("Music muted", EPrefix.AudioEngine); }
public override void ProcessItem(Message msg) { try { InfoLog.WriteInfo("Sending message : " + msg.Type, EPrefix.ClientInformation); if (msg.Type == MessageType.Build) { InfoLog.WriteInfo("Sending build message: " + ((BuildMessage)msg).ToString()); } if (msg.Type == MessageType.BuildUnitMessage) { InfoLog.WriteInfo("Sending build unit message: " + ((BuildUnitMessage)msg).ToString()); } msg.Serialize(writeStream); writeStream.Flush(); if (MessageSend != null) { lock (MessageSend) { MessageSend(this, new MessageEventArgs((byte)msg.Type, msg)); } } } catch (Exception ex) { InfoLog.WriteException(ex); if (ConnectionLost != null) { lock (ConnectionLost) { ConnectionLost(this, EventArgs.Empty); } } } }
public void SendMessage(Message msg) { try { if (!_isDisconnected) { if (msg.Type == MessageType.Build) { BuildMessage bm = (BuildMessage)msg; InfoLog.WriteInfo("Sending build message to player: " + this.Id, EPrefix.Test); InfoLog.WriteInfo("Buildmessage data: " + bm.ToString(), EPrefix.Test); } if (msg.Type == MessageType.BuildUnitMessage) { BuildUnitMessage bum = (BuildUnitMessage)msg; InfoLog.WriteInfo("Sending build unit message to player: " + this.Id, EPrefix.Test); InfoLog.WriteInfo("BuildUnitMessage data: " + bum.ToString(), EPrefix.Test); } msg.Serialize(_writeStream); _writeStream.Flush(); if (msg.Type == MessageType.DoTurn) { _tac.Unset(this.Login); } } } catch (Exception ex) { InfoLog.WriteException(ex); ExecuteOnConnectionLost(); } }
public void ProcessChatEntry(Message msg) { Player player = _server.GetPlayer(msg.SenderId); InfoLog.WriteInfo(string.Format(ProcessStringFormat, "Chat entry", player.Login), EPrefix.ServerProcessInfo); if (null == player || player.State == MenuState.Chat) { return; } MenuState state = PlayerStateMachine.Transform(player.State, MenuAction.ChatEntry); if (state == MenuState.Invalid) { InfoLog.WriteInfo("Chat entry unsuccesful", EPrefix.ServerInformation); return; } //Mogly zajsc dwie sytuacje - gracz przechodzi ze stanu zalogowany, albo z //game roomu switch (player.State) { case MenuState.GameChoose: RemoveFromGameRoom(player); break; } lock (player.SyncRoot) { player.State = state; } AddToChat(player); }
void Instance_GameInitialization(object sender, GameInitEventArgs e) { PlayerInfo pi = ClientPlayerInfo.Player; PositionData[] aPd = e.gameInitInfo; foreach (PositionData pd in aPd) { //TODO: get info //_currPlayer = _sim.Players[pd.PlayerId]; Player p = _sim.Players[pd.PlayerId]; ObjectID mcvID = new ObjectID(p.Id, p.GenerateObjectID()); InfoLog.WriteInfo(mcvID.ToString() + " for MVC", EPrefix.GObj); UnitMCV mcv = new UnitMCV(mcvID, GlobalSettings.Wrapper.MCVs[0], new Position(pd.X, _sim.Map.Height - pd.Y - 1), _sim.Map, this._sim); p.AddUnit(mcv); _sim.ClearFogOfWar(mcv); // vjust for fun ;p ObjectID tankID = new ObjectID(p.Id, p.GenerateObjectID()); UnitTank u = new UnitTank(tankID, GlobalSettings.Wrapper.Tanks[0], new Position((short)((pd.X + 1) % _sim.Map.Width), _sim.Map.Height - pd.Y - 1), this._sim.Map, this._sim); InfoLog.WriteInfo(tankID.ToString() + " for tank: " + u.TypeID, EPrefix.GObj); p.AddUnit(u); _sim.ClearFogOfWar(u); // ^ //this.sim.Map.Units[u.Position.X, u.Position.Y].AddLast(u); } this._sim.StartSimulation(); this._sim.DoTurn(1); }
public void ProcessGameChooseEntry(Message msg) { Player player = _server.GetPlayer(msg.SenderId); InfoLog.WriteInfo(string.Format(ProcessStringFormat, "Game Choose Entry", player.Login), EPrefix.ServerProcessInfo); if (null == player || player.State == MenuState.GameChoose) { return; } MenuState state = PlayerStateMachine.Transform(player.State, MenuAction.GameChooseEntry); if (state == MenuState.Invalid) { InfoLog.WriteInfo("GameChoose entry unsuccesful by player: " + player.Login, EPrefix.ServerInformation); return; } //wejscie moze nastapic z czatu albo z game joina switch (player.State) { case MenuState.Chat: MoveFromChatToGameRoom(player); break; case MenuState.GameJoin: RemoveFromGameJoin(player); break; } lock (player.SyncRoot) { player.State = state; } }
/// <summary> /// Process join game /// </summary> /// <param name="textMessage"></param> private void ProcessJoinGame(TextMessage textMessage) { Player player = _server.GetPlayer(textMessage.SenderId); InfoLog.WriteInfo(string.Format(ProcessStringFormat, "Join Game", textMessage.SenderId), EPrefix.ServerProcessInfo); if (player == null) { return; } MenuState state = PlayerStateMachine.Transform(player.State, MenuAction.GameJoinEntry); if (state == MenuState.Invalid) { SendMessage(Utils.CreateResultMessage(ResponseType.JoinGame, ResultType.Unsuccesful), player.Id); } ResultType result = _server.GameManager.IsJoinGamePossible(textMessage.Text, _server.GetPlayer(textMessage.SenderId)); if (result == ResultType.Successful) { SendMessage(Utils.CreateResultMessage(ResponseType.JoinGame, result), player.Id); _server.GameManager.JoinGame(textMessage.Text, player); player.State = state; } else { SendMessage(Utils.CreateResultMessage(ResponseType.JoinGame, result), player.Id); } }
private void ServerProcess() { if (Settings.Default.DBAvail) { switch (YadDB.Init()) { case InitDBResult.Successful: InfoLog.WriteInfo("Database initialized successfully...", EPrefix.DatebaseInfo); _server = new Server(_ServerPortNo); _server.Start(); break; case InitDBResult.CreateMDBFileFailed: InfoLog.WriteInfo("Unable to create .mdb file...", EPrefix.DatebaseInfo); break; case InitDBResult.CreateDBFailed: InfoLog.WriteInfo("Unablie to create database...", EPrefix.DatebaseInfo); break; } } else { _server = new Server(_ServerPortNo); _server.Start(); } }
public void OnBadLocation(int id) { InfoLog.WriteInfo("Enter OnBadLocation", EPrefix.BMan); if (id == -1) { return; } InfoLog.WriteInfo("lock leftState in OnBadLocation", EPrefix.BMan); lock (((ICollection)_leftState).SyncRoot) { if (!_leftState.ContainsKey(id)) { return; } _leftState[id] = RightStripState.Normal; } InfoLog.WriteInfo("release leftState in OnBadLocation", EPrefix.BMan); InfoLog.WriteInfo("lock stripdata in OnBadLocation", EPrefix.BMan); lock (((ICollection)_stripData).SyncRoot) { if (!_stripData.ContainsKey(id)) { return; } ActivateForObject(id); } InfoLog.WriteInfo("release stripdata in OnBadLocation", EPrefix.BMan); _rightStripe.ActivateAll(); InfoLog.WriteInfo("Exit OnBadLocation", EPrefix.BMan); }
private void buttonUp_Click(object sender, EventArgs e) { InfoLog.WriteInfo("buttonUp: delta: " + delta + " num: " + num + " viewable: " + viewable, EPrefix.Stripe); ShowUpper(1); Refresh(); }
public override void DoAI() { if (_remainingTurnsInMove > 0 && Moving && state == UnitState.stopped) { Move(); return; } switch (state) { case UnitState.moving: //BoardObject nearest; if (Move() == false) { InfoLog.WriteInfo("MCV:AI: move -> stop ", EPrefix.SimulationInfo); state = UnitState.stopped; } else { InfoLog.WriteInfo("MCV:AI: move -> move ", EPrefix.SimulationInfo); } break; case UnitState.stopped: break; } }
private void HandleRightButtonDown(MouseEventArgs e) { Position pos = GameGraphics.TranslateMousePosition(e.Location); if (!_isCreatingBuilding && !_isCreatingUnit) { BoardObject bo = boardObjectAt(pos); if (bo != null) { _gameLogic.AttackOrder(bo); } else { _gameLogic.MoveOrder(pos); } return; } if (_isCreatingBuilding) { _buildManager.OnBadLocation(_objectCreatorId); } _isCreatingUnit = false; InfoLog.WriteInfo("_isCreatingUnit = false; in HandleRightButtonDown", EPrefix.BMan); _isCreatingBuilding = false; }
private void CreateUnit(short playerId, short type, Position pos) { InfoLog.WriteInfo("CreateUnit", EPrefix.Test); Player p = players[playerId]; Unit u = null; ObjectID id = new ObjectID(playerId, p.GenerateObjectID()); InfoLog.WriteInfo(id.ToString() + " dla jednostki: " + type, EPrefix.Test); if (GlobalSettings.Wrapper.harvestersMap.ContainsKey(type)) { u = new UnitHarvester(id, GlobalSettings.Wrapper.harvestersMap[type], pos, this._map, this, GlobalSettings.Wrapper.harvestersMap[type].__Speed); ((UnitHarvester)u).SpiceUnload += new SpiceUnloadDelegate(SpiceUnload); } else if (GlobalSettings.Wrapper.mcvsMap.ContainsKey(type)) { u = new UnitMCV(id, GlobalSettings.Wrapper.mcvsMap[type], pos, this._map, this); } else if (GlobalSettings.Wrapper.tanksMap.ContainsKey(type)) { u = new UnitTank(id, GlobalSettings.Wrapper.tanksMap[type], pos, this._map, this); } else if (GlobalSettings.Wrapper.troopersMap.ContainsKey(type)) { u = new UnitTrooper(id, GlobalSettings.Wrapper.troopersMap[type], pos, this._map, this); } p.AddUnit(u); ClearFogOfWar(u); OnUnitCompleted(u); }
private void openGLView_MouseDown(object sender, MouseEventArgs e) { InfoLog.WriteInfo("MouseDown", EPrefix.UIManager); switch (e.Button) { case MouseButtons.Left: HandleLeftButtonDown(e); break; case MouseButtons.Middle: HandleMiddleButtonDown(e); break; case MouseButtons.Right: HandleRightButtonDown(e); break; case MouseButtons.XButton1: case MouseButtons.XButton2: case MouseButtons.None: default: break; } }
public void InitConnection(string hostname, int port) { try { tcpClient = new TcpClient(); tcpClient.NoDelay = true; InfoLog.WriteInfo("Connecting to " + hostname + " on port " + port + " ...", EPrefix.ClientInformation); tcpClient.Connect(hostname, port); NetUtils.SetKeepAlive(tcpClient); InfoLog.WriteInfo("Connected succesfully", EPrefix.ClientInformation); sender.Stream = tcpClient.GetStream(); sender.Start(); InfoLog.WriteInfo("Sender run succesfully", EPrefix.ClientInformation); receiver.Stream = tcpClient.GetStream(); receiver.Start(); } catch (Exception ex) { InfoLog.WriteException(ex); if (ex is SocketException) { throw new Exception("Connection exception", ex); } } }
protected override void onMessageAttack(AttackMessage am) { InfoLog.WriteInfo("MessageAttack", EPrefix.SimulationInfo); // set attacked object in attacker unit Unit attacker = players[am.Attacker.PlayerID].GetUnit(am.Attacker); if (attacker == null) { return; } Player p = players[am.Attacked.PlayerID]; BoardObject b; bool isBuilding = false; b = p.GetBuilding(am.Attacked); if (b != null) { isBuilding = true; } else { b = p.GetUnit(am.Attacked); if (b == null) { InfoLog.WriteInfo("MessageMove: PlayerID:" + am.Attacked.PlayerID + " attacked object does not exist", EPrefix.SimulationInfo); return; } } attacker.OrderedAttack = true; attacker.OrderAttack(b, isBuilding); }
public void JoinGame(string name, Player player) { SendJoinGameMessage(_games[name], player.Id); _games[name].AddPlayer(player); player.GameName = name; InfoLog.WriteInfo("Player " + player.Login + "has joined game: " + name, EPrefix.ServerAction); }
private void ServerThread() { InfoLog.WriteInfo("Server loop starts...", EPrefix.Initialization); ServerProcess(); InfoLog.WriteInfo("Server loop ends...", EPrefix.Finalization); Application.Exit(); }
protected bool FindNearestTargetInFireRange(out BoardObject nearest) { int count; Position[] viewSpiral = RangeSpiral(this.FireRange, out count); Map m = this._map; Position p = this.Position; Position spiralPos; LinkedList <Unit> units; LinkedList <Building> buildings; for (int i = 0; i < count; ++i) { spiralPos = viewSpiral[i]; if (p.X + spiralPos.X >= 0 && p.X + spiralPos.X < m.Width && p.Y + spiralPos.Y >= 0 && p.Y + spiralPos.Y < m.Height) { units = m.Units[p.X + spiralPos.X, p.Y + spiralPos.Y]; foreach (Unit unit in units) { if (unit.Equals(this)) { continue; } if (unit.ObjectID.PlayerID != this.ObjectID.PlayerID && _simulation.Players[unit.ObjectID.PlayerID].TeamID != _simulation.Players[this.ObjectID.PlayerID].TeamID) { // target //TODO RS: bresenham to check if there is a way to shoot. // else - continue -> move attackingBuilding = false; InfoLog.WriteInfo("Unit:AI: found unit in fire range < " + this.FireRange, EPrefix.SimulationInfo); nearest = unit; return(true); } } buildings = m.Buildings[p.X + spiralPos.X, p.Y + spiralPos.Y]; foreach (Building building in buildings) { // erase true;) if (building.ObjectID.PlayerID != this.ObjectID.PlayerID && _simulation.Players[building.ObjectID.PlayerID].TeamID != _simulation.Players[this.ObjectID.PlayerID].TeamID) { attackingBuilding = true; nearest = building; InfoLog.WriteInfo("Unit:AI: found building fire range < " + this.FireRange, EPrefix.SimulationInfo); return(true); } } } } nearest = null; return(false); }
private void RemoveGame(ServerGameInfo sgi) { lock (((ICollection)_games).SyncRoot) { _games.Remove(sgi.Name); } InfoLog.WriteInfo(string.Format(Resources.ActionStringFormat, "game removal"), EPrefix.ServerAction); InfoLog.WriteInfo("Removed game: " + sgi.Name, EPrefix.ServerAction); }
private void ProcessPause(short id) { InfoLog.WriteInfo("Setting pause..."); int turnid = _gameServer.Simulation.GetPlayerTurn(id) + _gameServer.Simulation.Delta + 1; _gameServer.PauseCtrl.SetPause(turnid, id); InfoLog.WriteInfo("for turn: " + turnid); }
private void PlaceBuilding(short id, int creatorID) { InfoLog.WriteInfo("Placing building: " + id + "creatorID: " + creatorID, EPrefix.BMan); _objectToCreateId = id; _objectCreatorId = creatorID; this._isCreatingBuilding = true; _selecting = false; }
/// <summary> /// checks if object is in shooting range /// </summary> /// <param name="ob"></param> /// <returns></returns> protected bool CheckRangeToShoot(BoardObject ob) { int r = (int)Math.Floor(Math.Pow(ob.Position.X - this.Position.X, 2) + Math.Pow(ob.Position.Y - this.Position.Y, 2)); int range = this.FireRange * this.FireRange; InfoLog.WriteInfo("Unit:AI: in range:" + r + " ?<= " + range, EPrefix.SimulationInfo); return(r <= range); }
public void UpdatePercent(short type, int percent) { InfoLog.WriteInfo("Enter Update percent in BuildStripe", EPrefix.Stripe); buttons[type].State = StripButtonState.Percantage; buttons[type].Percentage = percent; //InvokeShow(type); //UpdateFlowLayoutPanelSize(); InfoLog.WriteInfo("Left Update percent in BuildStripe", EPrefix.Stripe); }
private void RightBuildActiveClick(int id, bool isUnit) { InfoLog.WriteInfo("Enter RightBuildActiveClick", EPrefix.BMan); InfoLog.WriteInfo("lock cObjLock in RightBuildActiveClick", EPrefix.BMan); int current = -1; lock (cObjLock) current = _currentObjectID; InfoLog.WriteInfo("unlock cObjLock in RightBuildActiveClick", EPrefix.BMan); if (current == -1) { InfoLog.WriteInfo("Exit RightBuildingClick", EPrefix.BMan); return; } if (isUnit) { DeactivateOther(-1); _rightStripe.DeactivateAll(); BuildUnitMessage buMessage = (BuildUnitMessage)MessageFactory.Create(MessageType.BuildUnitMessage); buMessage.UnitType = (short)id; buMessage.CreatorID = current; buMessage.IdPlayer = _gameLogic.CurrentPlayer.Id; Connection.Instance.SendMessage(buMessage); InfoLog.WriteInfo("Current: " + current, EPrefix.BMan); InfoLog.WriteInfo("Exit RightBuildingActiveClick", EPrefix.BMan); return; } else { InfoLog.WriteInfo("lock leftState in RightBuildActiveClick", EPrefix.BMan); lock (((ICollection)_leftState).SyncRoot) _leftState[current] = RightStripState.Placing; InfoLog.WriteInfo("lock leftState in RightBuildActiveClick", EPrefix.BMan); InfoLog.WriteInfo("lock stripData in RightBuildActiveClick", EPrefix.BMan); lock (((ICollection)_stripData).SyncRoot) _stripData[current][(short)id].State = StripButtonState.Ready; InfoLog.WriteInfo("unlock stripData in RightBuildActiveClick", EPrefix.BMan); DeactivateOther((short)id); _rightStripe.DeactivateAll(); _rightStripe.SetState(id, StripButtonState.Ready); return; } /*InfoLog.WriteInfo("lock stripData in RightBuildActiveClick", EPrefix.BMan); * lock (((ICollection)_stripData).SyncRoot) * UpdateView(current,false); * InfoLog.WriteInfo("unlock stripData in RightBuildActiveClick", EPrefix.BMan); * InfoLog.WriteInfo("Exit RightBuildingClick", EPrefix.BMan);*/ }
void leftStripe_onBuildingChosen(int id) { InfoLog.WriteInfo("leftStripe_onBuildChosen " + id, EPrefix.GameGraphics); _buildManager.SwitchCurrentBuilding(id); this._isCreatingBuilding = false; InfoLog.WriteInfo("_isCreatingUnit = false; in leftStripe_onBuildingChosen", EPrefix.BMan); // show building on rightStripe //ShowPossibilitiesForBuilding(id); }
protected bool FindNearestTargetInViewRange(out BoardObject ob) { int count; Position[] viewSpiral = RangeSpiral(this.ViewRange, out count); Map m = this._map; Position p = this.Position; Position spiralPos; LinkedList <Unit> units; LinkedList <Building> buildings; for (int i = 0; i < count; ++i) { spiralPos = viewSpiral[i]; if (p.X + spiralPos.X >= 0 && p.X + spiralPos.X < m.Width && p.Y + spiralPos.Y >= 0 && p.Y + spiralPos.Y < m.Height) { units = m.Units[p.X + spiralPos.X, p.Y + spiralPos.Y]; foreach (Unit unit in units) { //TODO erase true;) if (unit.Equals(this)) { continue; } if (unit.ObjectID.PlayerID != this.ObjectID.PlayerID && _simulation.Players[unit.ObjectID.PlayerID].TeamID != _simulation.Players[this.ObjectID.PlayerID].TeamID) { ob = unit; InfoLog.WriteInfo("Unit:AI: found unit in view in range < " + this.ViewRange, EPrefix.SimulationInfo); return(true); } } buildings = m.Buildings[p.X + spiralPos.X, p.Y + spiralPos.Y]; foreach (Building building in buildings) { //TODO erase true;) if (building.ObjectID.PlayerID != this.ObjectID.PlayerID && _simulation.Players[building.ObjectID.PlayerID].TeamID != _simulation.Players[this.ObjectID.PlayerID].TeamID) { attackingBuilding = true; ob = building; InfoLog.WriteInfo("Unit:AI: found building in view in range < " + this.ViewRange, EPrefix.SimulationInfo); return(true); } } } } ob = null; return(false); }