public void TestTargetBack() { var client = ServerMocker.GetClient(); var player = client.FullLoginSequence(_player); var skeleton = new Skeleton() { Position = new Position(0, 1) }; skeleton.AggroBehaviuor = BehaviourPool.Get <TargetBack>(); Server.Events.Call(new EntitySpawnEvent() { Entity = skeleton, Position = skeleton.Position }); var chunk = player.GetChunk(); client.SendToServer(new EntityTargetPacket() { TargetUuid = skeleton.UID, WhoUuid = player.UID }); Assert.That(skeleton.Target == player); }
public void UpdateCollisionInArea(Pos pos) { //TODO use rects //Debug.Log("GenerateCollisionInArea: " + pos.x + " , " + pos.y + ", areaWidth: " + _parameters.areaWidth + ", areaHeight:" + _parameters.areaHeight); var rect = new Rect(pos.x - _parameters.areaWidth / 2f, pos.y - _parameters.areaHeight / 2f, _parameters.areaWidth, _parameters.areaHeight); //_lastRect for (int x = (int)rect.xMin; x < (int)rect.xMax; x++) { for (int y = (int)rect.yMin; y < (int)rect.yMax; y++) { var tilePos = new Pos(x, y); var blockType = _mapInfo.GetBlockAt(tilePos); bool hasCollider = _colliders.ContainsKey(tilePos); if (blockType == BlockType.EMPTY) { if (hasCollider) { var coll = _colliders[tilePos]; _colliderPool.Return(coll); _colliders.Remove(tilePos); } continue; } if (hasCollider) { continue; } var collInst = _colliderPool.Get(); collInst.offset = new Vector2(x, y) + Vector2.one * 0.5f; collInst.size = Vector2.one; _colliders.Add(new Pos(x, y), collInst); } } _lastRect = rect; }
public void TestMonsterMovingCollision() { var client = ServerMocker.GetClient(); client.FullLoginSequence(_player); var skeleton = new Skeleton(); skeleton.Position = new Position(1, 1); skeleton.MovementBehaviour = BehaviourPool.Get <LeftRightWalk>(); Server.Map.GetTile(2, 1).TileId = 2; // block var originalX = skeleton.Position.X; Server.Events.Call(new EntitySpawnEvent() { Entity = skeleton, Position = skeleton.Position }); client.SendToServer(new EntityMovePacket() { To = new Position(_player.X, _player.Y + 1), UID = _player.UserId, }); client.RecievedPackets.Clear(); skeleton.MovementTick(); Assert.That(skeleton.Position.X == originalX, "Skeleton couldnt have moved as he was in between 2 obstacles"); Assert.That(client.RecievedPackets.Count == 0, "Player should not recieve monster move packets if the monster didnt moved"); }
public Skeleton() { this.Name = "Skeleton"; this.MovementBehaviour = BehaviourPool.Get <LeftRightWalk>(); this.AggroBehaviuor = BehaviourPool.Get <TargetBack>(); }
public Skeleton() { this.Name = "Skeleton"; this.MovementBehaviour = BehaviourPool.Get <RandomWalk>(); }
public Skeleton() { this.Name = "Skeleton"; this.MovementBehaviour = BehaviourPool.Get <LeftRightWalk>(); }