void processUnitDeath(NetIncomingMessage msg) { short unitID = msg.ReadInt16(); short team = msg.ReadInt16(); Unit unit = Player.Players[team].UnitArray[unitID]; if (unit != null && !unit.IsDead) { unit.Die(); } }
void processUnitHpUpdate(NetIncomingMessage msg) { short unitID = msg.ReadInt16(); short team = msg.ReadInt16(); short hp = msg.ReadInt16(); Unit unit = Player.Players[team].UnitArray[unitID]; if (unit != null && hp < unit.Hp) { unit.Hp = hp; if (hp <= 0) { unit.Die(); } } }
void processUnitStatusUpdate(NetIncomingMessage msg) { short unitID = msg.ReadInt16(); short team = msg.ReadInt16(); short hp = msg.ReadInt16(); Vector2 position = new Vector2(msg.ReadFloat(), msg.ReadFloat()); float rotation = msg.ReadFloat(); bool idle = msg.ReadBoolean(); Unit unit = Player.Players[team].UnitArray[unitID]; if (unit != null) { if (hp < unit.Hp && !unit.IsDead) { unit.Hp = hp; if (hp <= 0) { unit.Die(); } return; } //if (unit.IsIdle) if (idle) { if (unit.IsIdle) { unit.CenterPoint = position; } if (!unit.IsIdle) { unit.NextCommand(); } } else { Vector2 expectedPosition = new Vector2(position.X + unit.Speed * connection.AverageRoundtripTime / 2 * (float)Math.Cos(rotation), position.Y + unit.Speed * connection.AverageRoundtripTime / 2 * (float)Math.Sin(rotation)); if (Vector2.Distance(expectedPosition, unit.CenterPoint) > unit.Radius) { //unit.CenterPoint -= new Vector2((unit.CenterPoint.X - expectedPosition.X), (unit.CenterPoint.Y - expectedPosition.Y)); unit.CenterPoint = expectedPosition; } } // read current command ID int commandID = msg.ReadInt16(); // if its not the same as our current command, look for it in queue if (commandID != -1 && unit.Commands.Count > 0 && commandID != unit.Commands[0].ID) { for (int i = 1; i < unit.Commands.Count; i++) { UnitCommand command = unit.Commands[i]; if (command.ID == commandID) { // do NextCommand enough times to catch up for (int s = 0; s < i; s++) { unit.NextCommand(); } } } } // read cargoAmount at end if worker WorkerNublet worker = unit as WorkerNublet; if (worker != null) { short cargoAmount = msg.ReadInt16(); worker.CargoAmount = cargoAmount; } } }