private void SendUpdate() { Unit[] currentlyDeadUnits = new Unit[this.deadUnits.Count]; for (int i = 0; i < currentlyDeadUnits.Length; i++) { currentlyDeadUnits[i] = this.deadUnits.Dequeue(); } List <UnitDTO> units = UsersManager.CurrentPlayer.Units.Where(u => u.Modified).Concat(currentlyDeadUnits).Select(UnitFactory.ToDto).ToList(); List <ResourceProviderDTO> resProvs = UsersManager.CurrentPlayer.ResourceProviders.Where(rp => rp.Modified).Select(ResProvFactory.ToDto).ToList(); ResourceSetDTO resSet = ResourceSetFactory.ToDto(UsersManager.CurrentPlayer.ResourceSet); ICollection <EntityDTO> modifiedEntities = units.Concat <EntityDTO>(resProvs).ToArray(); if (modifiedEntities.Count > 0) { Client.Socket.Writer.Send(Message.Create(Service.UpdateEntities, modifiedEntities)); } foreach (var unit in UsersManager.CurrentPlayer.Units) { unit.Modified = false; } foreach (var rp in UsersManager.CurrentPlayer.ResourceProviders) { rp.Modified = false; } Client.Socket.Writer.Send(Message.Create(Service.UpdateResourceSet, resSet)); }
private void UpdateResourceSet(Client client, ResourceSetDTO changedResSet) { var player = this.server.Players[client.Id]; // ugly as f**k player.ResourceSet.Food.Quantity = changedResSet.Food.Quantity; player.ResourceSet.Gold.Quantity = changedResSet.Gold.Quantity; player.ResourceSet.Wood.Quantity = changedResSet.Wood.Quantity; player.ResourceSet.Metal.Quantity = changedResSet.Metal.Quantity; player.ResourceSet.Rock.Quantity = changedResSet.Rock.Quantity; player.ResourceSet.Population.Quantity = changedResSet.Population.Quantity; }
public static ResourceSet FromDto(ResourceSetDTO resSetDto) { return(new ResourceSet(resSetDto.Id, new Resource(resSetDto.Gold.Quantity, ResourceType.Gold), new Resource(resSetDto.Wood.Quantity, ResourceType.Wood), new Resource(resSetDto.Food.Quantity, ResourceType.Food), new Resource(resSetDto.Rock.Quantity, ResourceType.Rock), new Resource(resSetDto.Metal.Quantity, ResourceType.Metal), new Resource(resSetDto.Population.Quantity, ResourceType.Population))); }