(where: Pos = null, teleportArea: Pos = null)
| 450 | } |
| 451 | |
| 452 | public castPlayerTeleport(where: Pos = null, teleportArea: Pos = null): void{ |
| 453 | var teleportSucceeded: boolean = false; |
| 454 | var teleportPosition: Pos; |
| 455 | |
| 456 | // If there's a special position to teleport the player, but no teleport area (which means we want to teleport it to this precise point only) |
| 457 | if(where != null && teleportArea == null){ |
| 458 | // If we manage to teleport here |
| 459 | if(this.getGame().getPlayer().teleport(where)) |
| 460 | teleportSucceeded = true; |
| 461 | } |
| 462 | // Else, no special position at all or a teleport area |
| 463 | else{ |
| 464 | // Find where the teleport area will begin |
| 465 | if(where == null) |
| 466 | where = new Pos(0, 0); |
| 467 | |
| 468 | // Find the size of the teleport area |
| 469 | if(teleportArea == null) |
| 470 | teleportArea = new Pos(this.getRealQuestSize().x-1, this.getRealQuestSize().y-1); |
| 471 | |
| 472 | // We try to teleport 10 times in the teleport area, if one time succeed then it's okay, else the teleport fails |
| 473 | for(var i = 0; i < 10; i++){ |
| 474 | teleportPosition = where.plus(Random.fromPosition(teleportArea)); |
| 475 | // If we're not trying to teleport where we already are and the teleport succeed |
| 476 | if(teleportPosition != this.getGame().getPlayer().getGlobalPosition() && this.getGame().getPlayer().teleport(teleportPosition)){ |
| 477 | teleportSucceeded = true; |
| 478 | break; |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | // Show a message depending on teleportSucceeded |
| 484 | if(teleportSucceeded){ |
| 485 | this.getGame().getQuestLog().addMessage(new QuestLogMessage("You cast a teleport spell!")); |
| 486 | } |
| 487 | else{ |
| 488 | this.getGame().getQuestLog().addMessage(new QuestLogMessage("You failed to cast the teleport spell. Magic works in mysterious ways...")); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | public castPlayerTimeSlowing(): void{ |
| 493 | // We invert questSlowedDown |
no test coverage detected