public static void ParseCharacterChoice(Connection connection, string line) { Dictionary <int, PlayerCharacter> choices = connection.Account.Characters.GetChoices( ); int choice; if (int.TryParse(line, out choice) && choices.ContainsKey(choice)) { connection.CurrentCharacter = choices[choice]; //find the room they quit in var area = Mud.I.Areas.FirstOrDefault(a => a.Rooms.Exists(r => r.Vnum == connection.CurrentCharacter.CurrentRoomVnum)); Room room = Mud.I.StartingRoom; if (area != null) { room = area.Rooms.FirstOrDefault(r => r.Vnum == connection.CurrentCharacter.CurrentRoomVnum); if (room == null) { room = Mud.I.StartingRoom; } } //assign the room to the player... connection.CurrentCharacter.CurrentRoom = room; //and the player to the room... (this will be removed when the player quits or moves) room.AddCharacter(connection.CurrentCharacter); connection.ConnectionStatus = ConnectionStatus.Playing; //force the user to look ParsePlaying(connection, "look"); } else { connection.SendLine("Invalid choice."); SendCharacterChoices(connection); } }
public void TestAddCharacterGetsPrintedInLook( ) { Room r = new Room("a", "b", "c"); Character c = new Character("Bob Jones", "A non-descript person."); r.AddCharacter(c); Assert.Contains("Bob Jones", r.Look()); }
void NewRoom() { Events.SetShader(ShaderManager.states.NONE); Room newRoom = GetRoom(); roomID++; room_in_scene = Instantiate(newRoom); room_in_scene.AddCharacter(character_in_scene); character_in_scene.SetMaxDistance(room_in_scene.MAX_DISTANCE); }
private void SpawnCharacterInRandomRoom() { if (_hasStoppedSpawning) { return; } CharacterType characterType = _characterHand.GetRandomElement(); int characterTypeIdx = (int)characterType; if (characterTypeIdx >= visitorPrefabs.Length) { Debug.LogError("Trying to spawn character of type (" + characterType.ToString() + ") but no prefab has been defined for it."); return; } int roomIndex = _roomHand.GetRandomElement(); if (roomIndex >= spawnPositions.Length) { Debug.LogError("Trying to spawn character of type (" + characterType.ToString() + ") in room (" + roomIndex.ToString() + ") but the room doesn't exist."); return; } CharacterCharge characterCharge = CharacterCharge.Neutral; if (_hasSplitted) { characterCharge = _chargeHand.GetRandomElement(); } Room room = spawnPositions[roomIndex].room; GameObject characterGO = Instantiate(visitorPrefabs[characterTypeIdx], visitorParent); Character character = characterGO.GetComponent <Character>(); character.characterCharge = characterCharge; Vector3 characterPosition = spawnPositions[roomIndex].positionHand.GetRandomElement().position; characterPosition.z = characterGO.transform.position.z; characterGO.transform.position = characterPosition; character.targetPosition = room.GetRandomFreeDancePosition(); room.AddCharacter(character); if (!_hasSplitted && (_characterHand.numHandsDelivered > numVisitorHandsBeforeSplit)) { introController.showChargeIntro = true; _hasSplitted = true; } else if (_characterHand.numHandsDelivered > (numVisitorHandsBeforeSplit + numVisitorHandsAfterSplit)) { _hasStoppedSpawning = true; } }
public void AddCharacterTest() { var room = new Room { Id = "test-room", ShortDescr = "test room" }; var ch = new Mock <Character>(); var mockCharacterSet = new Mock <CharacterSet>(); mockCharacterSet.Setup(set => set.Add(ch.Object)); room.Characters = mockCharacterSet.Object; room.AddCharacter(ch.Object); mockCharacterSet.VerifyAll(); }
public void TestGiveItemToWithNullItem() { Room r = _testRoom; Character c = _testCharacter; r.AddCharacter(c); Peggy p = new Peggy(); p.SetCurrentRoom(r); Item i = _goodTestItem; p.AddItemToInventory(i); Assert.Throws <ArgumentException>(() => p.GiveItemTo(null, c.Name)); Assert.True(p.InventoryHasItems()); }
public void TestTakeItemFromCharacter() { Room r = _testRoom; Character c = _testCharacter; Item i = _goodTestItem; c.AddItem(i); r.AddCharacter(c); Peggy p = new Peggy(); p.SetCurrentRoom(r); string res = p.TakeItemFrom(i.Name, c.Name); string expected = $"{i.Name} has been added to your inventory.\r\n"; Assert.Equal(expected, res); Assert.True(p.InventoryHasItems()); }
public void TestLook() { Room r = _testRoom; Container c1 = _testContainer; Character c2 = _testCharacter; r.AddContainer(c1); r.AddCharacter(c2); Peggy p = new Peggy(); p.SetCurrentRoom(r); string res = p.Look(); string expected = "You are in the Test Room, you see...\r\n" + " - Test Container\r\n - Test Character\r\n"; Assert.Equal(expected, res); }
public override void OnTouchEnded(TouchEventInfo eventInfo) { // Check if there's a room below Ray ray = Camera.main.ScreenPointToRay(eventInfo.touchPositionPix); int numHits = Physics2D.RaycastNonAlloc(ray.origin, ray.direction, _raycastResults, raycastDistance, raycastLayerMask); Room droppedToRoom = null; for (int hitIdx = 0; hitIdx < numHits; ++hitIdx) { Room room = _raycastResults[hitIdx].collider.GetComponentInParent <Room>(); if (null != room) { droppedToRoom = room; break; } } if ((null != droppedToRoom) && (droppedToRoom.HasCapacity())) { droppedToRoom.AddCharacter(character); Vector3 targetPosition = ray.origin; targetPosition.z = character.transform.position.z; character.targetPosition = droppedToRoom.GetRandomFreeDancePosition(); character.transform.position = targetPosition; if (null != _visitorSpawner) { _visitorSpawner.SpawnReplacementForCharacter(character); } } else { character.transform.position = _initialPosition; if (null != _characterPreviousRoom) { _characterPreviousRoom.AddCharacter(character); } } character.isDragged = false; }
public void TestGiveItemToWithInvalidItem() { Room r = _testRoom; Character c = _testCharacter; r.AddCharacter(c); Peggy p = new Peggy(); p.SetCurrentRoom(r); Item i = _goodTestItem; p.AddItemToInventory(i); string res = p.GiveItemTo("shitty name", c.Name); string expected = $"There's nothing in your inventory called shitty name.\r\n"; Assert.Equal(expected, res); Assert.True(p.InventoryHasItems()); }
public void TestGiveItemTo() { Room r = _testRoom; Character c = _testCharacter; r.AddCharacter(c); Peggy p = new Peggy(); p.SetCurrentRoom(r); Item i = _goodTestItem; p.AddItemToInventory(i); string res = p.GiveItemTo(i.Name, c.Name); string expected = $"Removed {i.Name} from your inventory.\r\n"; Assert.Equal(expected, res); Assert.False(p.InventoryHasItems()); }