public void PerformAttack(Creature attacker, Creature defender) { if (attacker.IsAlive && defender.IsAlive) { if (!_combatRegistry.IsInCombat(attacker.Id)) { _combatRegistry.Register(attacker.Id, defender.Id); } ResolveAttack(attacker, defender); } }
private void Resolve(string creatureId, MovementDirection direction) { var creature = _creatureRegistry.GetById(creatureId); var currentPosition = creature.Position.DeepCopy(); var futureX = 0; var futureY = 0; switch (direction) { case MovementDirection.West: futureX = -1; break; case MovementDirection.East: futureX = 1; break; case MovementDirection.North: futureY = -1; break; case MovementDirection.South: futureY = 1; break; default: _logger.Warn("Invalid movement direction: " + direction); return; } if (_combatRegistry.IsInCombat(creatureId)) { _messageDispatcher.Dispatch(new GameMessage(string.Empty, creature.Id, MessageTopic.MovementFailed, "You are locked in combat and cannot walk away.")); return; } if (IsValidPosition(currentPosition, futureX, futureY)) { creature.Position.Move(futureX, futureY); _playArea.GameMap.Remove(currentPosition.X, currentPosition.Y, creature); _playArea.GameMap.Add(creature.Position.X, creature.Position.Y, creature); } else { _messageDispatcher.Dispatch(new GameMessage(string.Empty, creature.Id, MessageTopic.MovementFailed, "You crashed into a wall!")); } }
private ServerResponse TempCreateStatusResponse(Player player) { var pos = player.Position; var map = _playArea.GameMap; var lightRadius = player.Inventory.Items.FirstOrDefault(i => i.Name == "Torch") != null ? 8 : 2; map.ComputeFov(pos.X, pos.Y, lightRadius); var visibleCells = _mapper.Map <List <GameLib.Area.Cell>, List <Client.Contracts.Area.Cell> >(_playArea.GameMap.GetVisibleCells()); var p = _mapper.Map <GameLib.Entities.Player, Client.Contracts.Entities.Player>(player); var status = new GameStatus { Player = p, X = pos.X, Y = pos.Y, IsInCombat = _combatRegistry.IsInCombat(player.Id), Map = new Client.Contracts.Area.Map { Width = map.Width, Height = map.Height, VisibleCells = visibleCells }, NextActionAvailableUtc = _cooldownRegistry.TimeUntilCooldownIsDone(player.Id) }; // Temp, no point letting the client have to filter out self all the time... if (player.IsAlive) { var activeCell = visibleCells.Single(i => i.X == player.Position.X && i.Y == player.Position.Y); var playerInCell = activeCell.Creatures.Single(i => i.Id == player.Id); activeCell.Creatures.Remove(playerInCell); } var response = new ServerResponse { Type = ResponseType.GameStatus, Payload = JsonConvert.SerializeObject(status) }; return(response); }