AniBasicSteveMapCharacterController.cpp 27.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
//
//  IMapCharacterController.cpp
//  WattsenglishFoodApp
//
//  Created by Katarzyna Kalinowska-Górska on 22/03/2020.
//

#include "AniBasicSteveMapCharacterController.h"
#include "AniMapUtils.h"
#include "AniGeometryUtils.h"
#include "AniMiscUtils.h"
#include "AniTutorialMapControl.h"
#include "AniGardenSpriteAnimator.h"

void AniBasicSteveMapCharacterController::approachAdventureObject(IMapAdventureObject* p_advObject, AniMapUtils::TileData tile){
//    if(dynamic_cast<MapAdventureObjectSlide*>(p_advObject) != nullptr){ //TODO inaczej
//        tut_sendTappedSlideEvent();
//    }
    if(m_delegate->shouldApproachItem(p_advObject, tile)){
        IMapCharacterController::approachAdventureObject(p_advObject, tile);
    } else {
        moveCharacterToTile(tile, [&](){
        });
    }
}

void AniBasicSteveMapCharacterController::interactWithAdventureObjects(std::vector<IMapAdventureObject*> p_advObjects) {
    clearVisitedAdventureObjects();
    if(m_characterDisabled){
        return;
    }
    
    // handle a case with more than one ladder starting at the same point
    if(p_advObjects.size() > 1){
        for(auto it = p_advObjects.end()-1; it != p_advObjects.begin()-1; --it){
            if((*it)->getObjectClassName() == MapAdventureObjectLadder::ClassName){
                auto ladder = (*it)->getAssociatedMapImageObjects().begin()->second;
                if(!AniGeometryUtils::getBoundingBoxToWorld(ladder).containsPoint(m_lastSingleTouchedPoint)){ // a ladder must have a map image object
                    p_advObjects.erase(it);
                    break; //because we always have no more than 2
                }
            }
        }
    }
    
    // if still have more than one ladder, pick the one whose occupied tile was pressed (apart from the entry tile, they should be disjoint..)
    if(p_advObjects.size() > 1){
        auto touchedTile = m_mapController->getTileForTouchPoint(m_lastSingleTouchedPoint);
        for(auto it = p_advObjects.end()-1; it != p_advObjects.begin()-1; --it){
            if((*it)->getObjectClassName() == MapAdventureObjectLadder::ClassName){
                auto occupiedTiles = (*it)->getOccupiedTiles();
                if(std::find(occupiedTiles.begin(), occupiedTiles.end(), touchedTile) == occupiedTiles.end()){ // a ladder must have a map image object
                    p_advObjects.erase(it);
                    break; //because we always have no more than 2 and one should stay
                }
            }
        }
    }
    
    // the parent implementation just interacts with all of them
    IMapCharacterController::interactWithAdventureObjects(p_advObjects);
}

void AniBasicSteveMapCharacterController::interactWithAdventureObject(IMapAdventureObject* p_advObject) {
    
    if(m_characterDisabled){
        return;
    }
    
    auto entryTiles = p_advObject->getEntryTiles();
    auto steveTile = getCurrentCharacterTile();
    if(std::find(entryTiles.begin(), entryTiles.end(), steveTile) == entryTiles.end()){
        // if not stepped on one of the entry tiles, don't interact
        return;
    }
    
    auto className = p_advObject->getObjectClassName();
    if(className == MapAdventureObjectSlide::ClassName){
        interactWithSlideAdventureObject(dynamic_cast<MapAdventureObjectSlide*>(p_advObject));
    } else if(className == MapAdventureObjectLadder::ClassName){
        interactWithLadderAdventureObject(dynamic_cast<MapAdventureObjectLadder*>(p_advObject));
    } else if(className == MapAdventureObjectLog::ClassName){
        interactWithLogAdventureObject(dynamic_cast<MapAdventureObjectLog*>(p_advObject));
    } else if(className == MapAdventureObjectPickupItem::ClassName){
        interactWithPickupItemAdventureObject(dynamic_cast<MapAdventureObjectPickupItem*>(p_advObject));
    }
}

void AniBasicSteveMapCharacterController::interactWithSlideAdventureObject(MapAdventureObjectSlide* p_slide){
    static float SlideDuration = 1.f;
    auto steve = steveCharacter();
    steve->startSliding();
    steve->setPosition(p_slide->getAnimationStartPoint());
    adjustCharacterDepth();
    auto endPosition = p_slide->getAnimationEndPoint();
    auto endStandTile = p_slide->getEndStandTile();
    auto endStandTilePosition = AniMapUtils::getInstance().getTileMiddlePosition(m_mapController->getMap(), endStandTile.col, endStandTile.row);
    if(endStandTilePosition.x >= steve->getPositionX()){
        steveCharacter()->faceRight();
    } else {
        steveCharacter()->faceLeft();
    }
    
    auto mapEvent = new AniTutorialMapControl::CharacterStartedSlidingEvent();
    m_mapControl->mapEvent(this, mapEvent);
    delete mapEvent;
    
    steve->runAction(cocos2d::Sequence::create(cocos2d::MoveTo::create(SlideDuration, endPosition),
                                               cocos2d::CallFunc::create(std::bind([&](cocos2d::Vec2 endStandPos){
        auto steve = steveCharacter();
        if(steve){
            steve->setPosition(endStandPos);
            steve->stopSliding();
            adjustCharacterDepth();
            auto mapEvent = new AniTutorialMapControl::CharacterFinishedSlidingEvent();
            m_mapControl->mapEvent(this, mapEvent);
            delete mapEvent;
        }
    }, endStandTilePosition)),
    nullptr)); //TODO magic number
}

void AniBasicSteveMapCharacterController::interactWithLadderAdventureObject(MapAdventureObjectLadder* p_ladder){
    if(!p_ladder->isReady()){
        m_fingerInteractingWithObject = true;
        if(std::find(m_visitedAdventureObjects.begin(), m_visitedAdventureObjects.end(), p_ladder) == m_visitedAdventureObjects.end()){
            m_visitedAdventureObjects.push_back(p_ladder);
            m_mapController->centerCameraOnNode(p_ladder->getMapImageObject());
//            m_mapController->setCameraDestination(AniSteveCharacter()->getPosition());
            p_ladder->startBlinking();
            m_delegate->onApproachedRotatingItem(p_ladder);
        }
    }
}

void AniBasicSteveMapCharacterController::interactWithLogAdventureObject(MapAdventureObjectLog* p_log){
    m_fingerInteractingWithObject = true;
    if(std::find(m_visitedAdventureObjects.begin(), m_visitedAdventureObjects.end(), p_log) == m_visitedAdventureObjects.end()){
        m_visitedAdventureObjects.push_back(p_log);
        m_mapController->centerCameraOnNode(p_log->getMapImageObject());
//        m_mapController->setCameraDestination(p_log->getMapImageObject()->getPosition());
        p_log->startBlinking();
        m_delegate->onApproachedRotatingItem(p_log);
    }
}

void AniBasicSteveMapCharacterController::interactWithPickupItemAdventureObject(MapAdventureObjectPickupItem* p_item){
    
    if(m_delegate == nullptr || m_delegate->isRightPickUpItem(p_item)){
        // do a victory dance for a moment
        static float VictoryDanceDuration = 5.f;
        m_mapCharacter->startDancing();
        m_mapCharacter->runAction(cocos2d::Sequence::create(cocos2d::DelayTime::create(VictoryDanceDuration), cocos2d::CallFunc::create([&](){
            m_mapCharacter->stopDancing();
        }), nullptr));
        
        // "take" the item - item should disappear
        p_item->pickUp();
        if(m_delegate != nullptr){
            m_delegate->onRightItemPickedUp(p_item);
        }
        auto mapSPrite = p_item->getAssociatedMapImageObjects().begin()->second;
        mapSPrite->setLocalZOrder(1000);
        ISpriteAnimator::AnimParam paramJumpToZero;
        if(m_mapCharacter->getPositionX() > mapSPrite->getPositionX()){
            paramJumpToZero.boolParam = true;
        } else {
            paramJumpToZero.boolParam = false;
            mapSPrite->setFlippedX(true);
        }
        
        if(p_item->getObjectName() == "pickUpItem1Bear"){
            AniGardenSpriteAnimator::create()->animateSprite(mapSPrite, AniGardenSpriteAnimator::AnimationTagWaddleOff, {paramJumpToZero}, [](){});
        } else {
            AniGardenSpriteAnimator::create()->animateSprite(mapSPrite, AniGardenSpriteAnimator::AnimationTagJumpOff, {paramJumpToZero}, [](){});
        }
        
    } else if(m_delegate->isBonusPickUpItem(p_item)){
        m_delegate->onBonusItemPickUp(p_item);
        
    } else {
        // wrong item, but do not activate anything if it's one of the less occupied tiles
        // exception: if being approached, the character might stop next to it, but still it was intentional
        if(m_approachedAdventureObject == p_item){
            m_delegate->onWrongItemPickUpTry(p_item);
        } else {
            auto tiles = p_item->getOccupiedTilesRestrictedByIntersectionPercent(0.5f); //TODO de-magic, naming convention wrong, they are not percent
            auto characterTile = getCurrentCharacterTile();
            if(std::find(tiles.begin(), tiles.end(), characterTile) != tiles.end()){
                m_delegate->onWrongItemPickUpTry(p_item);
            }
        }
    }
    
    // call the delegate - steve will probably say something and the game will go on
}


// IMapControlInterface

void AniBasicSteveMapCharacterController::handleCommandSingleXYPress(const IMapControlSingleXYEventData& eventData) {
    if(m_characterDisabled){
        return;
    }
    
    if(m_mapController->isInZoomMode()){
        return;
    }
    
    //TODO comment this out
    auto map = m_mapController->getMap();
    auto AniMapUtils = AniMapUtils::getInstance();
    auto touchLocationOnMap = AniMapUtils.translateScreenPositionToMapPosition(eventData.screenPointCurrent, map->getParent()->getPosition());
    auto rowCol = AniMapUtils.translateXYPointToColRow(touchLocationOnMap, map->getTileSize().width, map->getTileSize().height, map->getMapSize().width, map->getMapSize().height);
      
//    cocos2d::log("TOUCHED TILE: %d %d\n", rowCol.col, rowCol.row);
    m_lastSingleTouchedPoint = eventData.screenPointCurrent;
    
    updateLastUserActivityTime();
    
    MapAdventureObjectRotatingEnd* visitedLadderORLog = pickVisitedMapAdventureObjectRotatingEnd();
    if(visitedLadderORLog != nullptr){
//        if(AniGeometryUtils::getBoundingBoxToWorld(visitedLadderORLog->getMapImageObject()).containsPoint(eventData.screenPointCurrent)){
        if(checkIfTouchedAdventureObject(visitedLadderORLog, eventData.screenPointCurrent)){
            auto pointConverted = visitedLadderORLog->getMapImageObject()->getParent()->convertToNodeSpace(eventData.screenPointCurrent);
            if(!visitedLadderORLog->evalReady(pointConverted)){ //don't let just clicking end the business
                m_isDraggingObject = true;
                visitedLadderORLog->rotate(pointConverted);
                adjustCharacterDepth();
                checkIfObjectRotatingEndReady(visitedLadderORLog);
                return; //blocking all other activity
            }
        }
    } else if(m_mapCharacter->isBusy()){
        return;
    }

    if(AniGeometryUtils::getBoundingBoxToWorld(m_mapCharacter).containsPoint(eventData.screenPointCurrent)){
        _singleTouchDetectedTime = cocos2d::utils::getTimeInMilliseconds();
        _singleTouchMoveLock = true;
        return;
    }

    auto mapPosition = m_mapController->getMap()->getParent()->getPosition();
    m_mapController->centerCameraOnNode(m_mapCharacter);
    
    moveCharacterToTouchedTile(eventData.screenPointCurrent, mapPosition);
    
    m_currentScreenTouchPoint = eventData.screenPointCurrent;
    
    
//    if(dynamic_cast<MapAdventureObjectSlide*>(p_advObject) != nullptr){ //TODO inaczej
//           tut_sendTappedSlideEvent();
//       }
}

void AniBasicSteveMapCharacterController::handleCommandSingleXYMove(const IMapControlSingleXYEventData& eventData) {
    
    m_lastSingleTouchedPoint = eventData.screenPointCurrent;
    
    if(m_characterDisabled){
        return;
    }
    
    updateLastUserActivityTime();
    
    if(m_mapController->isInZoomMode()){
        return;
    }
    
    if(m_isDraggingObject){
    MapAdventureObjectRotatingEnd* visitedLadderORLog = pickVisitedMapAdventureObjectRotatingEnd();
    if(visitedLadderORLog != nullptr){
            auto pointConverted = visitedLadderORLog->getMapImageObject()->getParent()->convertToNodeSpace(eventData.screenPointCurrent);
            visitedLadderORLog->rotate(pointConverted);
            adjustCharacterDepth();
            checkIfObjectRotatingEndReady(visitedLadderORLog);
        }
        return;
    }
    
    
    
    if(shouldBlockCharacterControl()){
        return;
    }
    
    if(m_mapCharacter->isBusy())
        return;
    
    if(AniGeometryUtils::getBoundingBoxToWorld(m_mapCharacter).containsPoint(eventData.screenPointCurrent)){
        if(_singleTouchMoveLock){
            return;
        }
    }
    
    if(m_currentScreenTouchPoint.x == -1){
        return;
    }
    
    _singleTouchMoveLock = false; //if started not on Steve, remove lock right away
    this->moveCharacterToTouchedTile(eventData.screenPointCurrent, m_mapController->getCameraPosition());
    m_currentScreenTouchPoint = eventData.screenPointCurrent;
}

void AniBasicSteveMapCharacterController::handleCommandSingleXYRelease(const IMapControlSingleXYEventData& eventData){
    
    if(m_characterDisabled){
        return;
    }
    
        updateLastUserActivityTime();
    
    if(m_mapController->isInZoomMode()){
        return;
    }
    
    if(m_isDraggingObject){
        m_isDraggingObject = false;
        auto ladderOrLog = pickVisitedMapAdventureObjectRotatingEnd();
        if(ladderOrLog != nullptr){
            ladderOrLog->resetRotation();
            adjustCharacterDepth();
        }
        return;
    }
    
        m_currentScreenTouchPoint.x = m_currentScreenTouchPoint.y = -1;
}

void AniBasicSteveMapCharacterController::handleCommandMultipleXYPress(const std::vector<IMapControlSingleXYEventData>& eventData){
    m_currentScreenTouchPoint = { -1, -1};
//    m_multiTouchDetected = true; //
}

void AniBasicSteveMapCharacterController::handleCommandMultipleXYMove(const std::vector<IMapControlSingleXYEventData>& eventData){
    m_currentScreenTouchPoint = { -1, -1};
}

void AniBasicSteveMapCharacterController::handleCommandMultipleXYRelease(const std::vector<IMapControlSingleXYEventData>& eventData){
    m_currentScreenTouchPoint = { -1, -1};
}

void AniBasicSteveMapCharacterController::handleCommandSingleXYLongPress(const IMapControlSingleXYEventData& eventData){
    
    if(m_characterDisabled){
        return;
    }
    
    if(shouldBlockCharacterControl()){
        return;
    }
    
    if(AniGeometryUtils::getBoundingBoxToWorld(m_mapCharacter).containsPoint(eventData.screenPointCurrent)){
        updateLastUserActivityTime();
        if(!m_mapCharacter->isBusy()){
            moveCharacterToTouchedTile(eventData.screenPointCurrent, m_mapController->getCameraPosition());
            _singleTouchMoveLock = false;
        }
    }
}

void AniBasicSteveMapCharacterController::handleCommandSingleXYTap(const IMapControlSingleXYEventData& eventData){
    
    if(m_characterDisabled){
        return;
    }
    
    if(AniGeometryUtils::getBoundingBoxToWorld(m_mapCharacter).containsPoint(eventData.screenPointCurrent)){
        updateLastUserActivityTime();
        m_mapCharacter->poke();
    } //else {
    
}

void AniBasicSteveMapCharacterController::handleCommandTicklingStarted(){
    if(m_characterDisabled){
        return;
    }
    if(shouldBlockCharacterControl()){
        return;
    }
    updateLastUserActivityTime();
    m_mapCharacter->startLaughing();
}

void AniBasicSteveMapCharacterController::handleCommandTicklingContinued(){
    if(m_characterDisabled){
        return;
    }
    if(shouldBlockCharacterControl()){
        return;
    }
    
    updateLastUserActivityTime();
    if(!m_mapCharacter->isLaughing()){
        m_mapCharacter->startLaughing();
    }
}

void AniBasicSteveMapCharacterController::handleCommandTicklingEnded(){
    if(m_characterDisabled){
        return;
    }
//    if(!m_shouldBlockCharacterControl){
//
//    }
    updateLastUserActivityTime();
    m_mapCharacter->stopLaughing();
    tut_sendTicklingFinishedEvent();
}

void AniBasicSteveMapCharacterController::handleCommandFastSwipe(const IMapControlSwipeEventData& eventData){
    if(m_characterDisabled){
        return;
    }
    if(m_blockJump || shouldBlockCharacterControl()){
        return;
    }
    
    if(!m_mapCharacter->isInFingerMoveState()){
//        if(AniGeometryUtils::getBoundingBoxToWorld(m_mapCharacter).containsPoint(eventData.startLocation)){
        if(AniMiscUtils::getExtendedActiveArea(m_mapCharacter, 200, 40.0).containsPoint(eventData.startLocation)){
            updateLastUserActivityTime();
                auto jumpTile = getJumpTile(eventData.speed, eventData.directionX, eventData.directionY);
                tut_sendJumpStartedEvent(steveCharacter()->getPosition(), jumpTile);
                if(jumpTile == getCurrentCharacterTile()){
                    m_mapCharacter->jump(eventData.speed.getLength(), [&, jumpTile](){
                        m_mapController->centerCameraOnNode(m_mapCharacter);
                        adjustCharacterDepth();
                        tut_sendJumpFinishedEvent(steveCharacter()->getPosition(), jumpTile);
                    });
                } else {
                    steveCharacter()->jump(AniMapUtils::getInstance().getTileMiddlePosition(m_mapController->getMap(), jumpTile.col, jumpTile.row), [&, jumpTile]{
                        IMapCharacterController::interactWithAdventureObjects();
                        adjustCharacterWalkingType(getCurrentCharacterTile());
                        adjustCharacterDepth();
                        m_mapController->centerCameraOnNode(m_mapCharacter);
                        tut_sendJumpFinishedEvent(steveCharacter()->getPosition(), jumpTile);
                     });
                }
            }
            adjustCharacterDepth();
    }
}

AniMapUtils::TileData AniBasicSteveMapCharacterController::getJumpTile(cocos2d::Vec2 speed, int dirX, int dirY){
    auto currentTile = getCurrentCharacterTile();
    static auto minDelta = minSwipeDelta*AniScalingUtils::scaleAspectFillToDesignIpadProSize();
    if(speed.x < minDelta){
        dirX = 0;
    }
    
    if(speed.y < minDelta){
        dirY = 0;
    }
    
    auto jumpTile = AniMapUtils::getInstance().getClosestTileInDirection(m_mapController->getMap(), m_mapController->getTileLayer(), currentTile, dirX, dirY, 2, 2);
    if(jumpTile == currentTile){
        jumpTile = AniMapUtils::getInstance().getClosestTileInXDirection(m_mapController->getMap(), m_mapController->getTileLayer(), currentTile, dirX, 2, 2);
    }
    if(jumpTile == currentTile){
        jumpTile = AniMapUtils::getInstance().getClosestTileInYDirection(m_mapController->getMap(), m_mapController->getTileLayer(), currentTile, dirY, 2, 2);
    }
    if(jumpTile == currentTile){
        jumpTile = AniMapUtils::getInstance().getClosestTileInDirection(m_mapController->getMap(), m_mapController->getTileLayer(), currentTile, dirX, -dirY, 2, 2);
    }
    
    return jumpTile;
}

void AniBasicSteveMapCharacterController::moveCharacterToTouchedTile(const cocos2d::Point& touchLocation, const cocos2d::Point& mapPosition) {
    if(m_characterDisabled){
        return;
    }
    clearVisitedAdventureObjects();
    IMapCharacterController::moveCharacterToTouchedTile(touchLocation, mapPosition);
}

void AniBasicSteveMapCharacterController::clearVisitedAdventureObjects() {
    for(auto it = m_visitedAdventureObjects.begin(); it != m_visitedAdventureObjects.end(); ++ it){
          auto rotatingEndObject = dynamic_cast<MapAdventureObjectRotatingEnd*>(*it);
          if(rotatingEndObject != nullptr){
              rotatingEndObject->stopBlinking();
              if(rotatingEndObject->isReady()){
                  m_delegate->onFinishedRotatingItem(rotatingEndObject);
              } else {
                  m_delegate->onCancelledRotatingItem(rotatingEndObject);
              }
          }
      }

    m_visitedAdventureObjects.clear();
}

void AniBasicSteveMapCharacterController::onTileChange(const AniMapUtils::TileData& previousTile, const AniMapUtils::TileData& newTile){
    auto steve = steveCharacter();
    auto wasClimbing = steve->isClimbing();
    adjustCharacterWalkingType(newTile);
    auto tileLevel = AniMapUtils::getInstance().getTileLevel(m_mapController->getMap(), m_mapController->getTileLayer(), previousTile);
    //tile leve 3 or geater means that we're climbing down
    if(steve->isClimbing() && !wasClimbing && tileLevel < 3){
        steve->playClimbSound();
    }
    
    auto advObjects = m_mapController->getAdventureObjectsAtMapPoint(m_mapCharacter->getPosition());
    for (auto it = advObjects.begin(); it != advObjects.end(); ++it){
        auto pickupItem = dynamic_cast<MapAdventureObjectPickupItem*>(*it);
        if(pickupItem != nullptr && m_delegate->isBonusPickUpItem(pickupItem)){
            interactWithPickupItemAdventureObject(pickupItem);
        }
    }
    
    auto characterBB = m_mapCharacter->getBoundingBox();
    m_mapController->revealTilesInRadius(cocos2d::Point(characterBB.getMidX(), characterBB.getMidY()), m_tileRevealRange.x/cocos2d::Director::getInstance()->getContentScaleFactor(),m_tileRevealRange.y/cocos2d::Director::getInstance()->getContentScaleFactor());
}

void AniBasicSteveMapCharacterController::adjustCharacterWalkingType(const AniMapUtils::TileData& tile){
    bool isNormalWalkTile = true;
    auto objectTileID = m_mapController->getTileObjectLayer()->getTileGIDAt(tile.convertToVec2());
    if(objectTileID > 0){
        auto ladderProperty = AniMapUtils::getInstance().getTileProperty(m_mapController->getMap(), m_mapController->getTileObjectLayer(), tile, "ladderClimbPoint");
        if(ladderProperty != cocos2d::Value::Null){
            auto isLadder = ladderProperty.asBool();
            if(isLadder){
                isNormalWalkTile = false;
                auto ladderDir = AniMapUtils::getInstance().getTileProperty(m_mapController->getMap(), m_mapController->getTileObjectLayer(), tile, "ladderDirection").asString();
                if(ladderDir == "left"){
                    steveCharacter()->setClimbing(true, -1);
                } else {
                    steveCharacter()->setClimbing(true, 1);
                }
            }
        }
    }
    if(isNormalWalkTile){
        steveCharacter()->setClimbing(false);
    }
}

void AniBasicSteveMapCharacterController::removeVisitedAdventureObject(IMapAdventureObject* m_object){
    auto foundIt = std::find(m_visitedAdventureObjects.begin(), m_visitedAdventureObjects.end(), m_object);
    if(foundIt != m_visitedAdventureObjects.end()){
        m_visitedAdventureObjects.erase(foundIt);
    }
}

//MapAdventureObjectLadder* AniBasicSteveMapCharacterController::pickVisitedLadder(){
//    for(auto it = m_visitedAdventureObjects.begin(); it != m_visitedAdventureObjects.end(); ++ it){
//        auto ladder = dynamic_cast<MapAdventureObjectLadder*>(*it);
//        if(ladder != nullptr){
//            return ladder;
//        }
//    }
//    return nullptr;
//}

MapAdventureObjectRotatingEnd* AniBasicSteveMapCharacterController::pickVisitedMapAdventureObjectRotatingEnd(){
    for(auto it = m_visitedAdventureObjects.begin(); it != m_visitedAdventureObjects.end(); ++ it){
        auto ladder = dynamic_cast<MapAdventureObjectRotatingEnd*>(*it);
        if(ladder != nullptr){
            return ladder;
        }
    }
    return nullptr;
}

void AniBasicSteveMapCharacterController::checkIfObjectRotatingEndReady(MapAdventureObjectRotatingEnd* visitedLadderORLog){
    if(visitedLadderORLog->isReady()){
        m_isDraggingObject = false;
        visitedLadderORLog->stopBlinking();
        removeVisitedAdventureObject(visitedLadderORLog);
        m_blockJump = true; // rotating the object often involves swiping up on steve. disable jump for a moment.
        getCharacter()->scheduleOnce([&](float){
            m_blockJump = false;
        }, 0.4f, "jumpUnblock");
        m_mapController->centerCameraOnNode(m_mapCharacter);
        m_delegate->onFinishedRotatingItem(visitedLadderORLog);
        approachAdventureObject(visitedLadderORLog, getCurrentCharacterTile());
    }
}
           
   bool AniBasicSteveMapCharacterController::checkIfTouchedAdventureObject(IMapAdventureObject* p_adventureObject, cocos2d::Point p_touchPointScreen){
//       auto mapPoint = AniMapUtils::getInstance().translateScreenPositionToMapPosition(p_touchPointScreen, m_mapController->getCameraPosition());
       auto mapImageObjects = p_adventureObject->getAssociatedMapImageObjects();
       for(auto it = mapImageObjects.begin(); it != mapImageObjects.end(); ++it){
           // problem with extended area: when rotated, the area is big. it definitely doesn't need extending.
           // another thing is, this area might be too big, and instead of dragging, we just have a click and that's it :/
           // small rotation means the log/ladder is lying flat and bb is small - hard to reach
           auto extendedAdvObjectBB = it->second->getRotation() <= 15 ? AniMiscUtils::getExtendedActiveArea(it->second, 10, 30) :
           AniMiscUtils::getExtendedActiveArea(it->second, 10, 10);//AniGeometryUtils::getBoundingBoxToWorld(it->second);
           if(extendedAdvObjectBB.containsPoint(p_touchPointScreen)){
               if(p_adventureObject)
               return true;
           }
       }
       return false;
   }

bool AniBasicSteveMapCharacterController::shouldBlockCharacterControl(){
    return pickVisitedMapAdventureObjectRotatingEnd() != nullptr || m_mapController->isInZoomMode();// m_multiTouchDetected;
}

MapAdventureObjectRotatingEnd* AniBasicSteveMapCharacterController::currentlyInteractedWithObject(){
    return pickVisitedMapAdventureObjectRotatingEnd();
}
//void AniBasicSteveMapCharacterController::handleSingleTouchDownForLadder(MapAdventureObjectLadder* p_ladder){
//
//}
//
//void AniBasicSteveMapCharacterController::handleSingleTouchMoveForLadder(MapAdventureObjectLadder* p_ladder){
//
//}
//
//void AniBasicSteveMapCharacterController::handleSingleTouchReleaseForLadder(MapAdventureObjectLadder* p_ladder){
//
//}

void AniBasicSteveMapCharacterController::steveReadyForAdventure(){
    auto steve = steveCharacter();
    steve->stopAllActions();
    steve->adjustDefaultImage();
    steve->setTimeToGetBored(20);
}

void AniBasicSteveMapCharacterController::steveLookAround(){
    steveCharacter()->lookAroundAndSmile();
}


void AniBasicSteveMapCharacterController::disableSteveHappy(){
    disableCharacter();
    steveCharacter()->sitAndSmile();
}

void AniBasicSteveMapCharacterController::disableSteveDisappointed(){
    disableCharacter();
    steveCharacter()->sitAndSulk();
}

//void AniBasicSteveMapCharacterController::tut_sendTappedTileEvent(AniMapUtils::TileData p_tile){
//    auto mapEvent = new AniTutorialMapControl::CharacterTappedTileEvent(p_tile);
//       m_mapControl->mapEvent(this, mapEvent);
//       delete mapEvent;
//}

void AniBasicSteveMapCharacterController::tut_sendJumpStartedEvent(cocos2d::Vec2 p_characterPosition, AniMapUtils::TileData p_tile){
    auto mapEvent = new AniTutorialMapControl::CharacterStartedJumpingEvent(p_characterPosition, p_tile);
    m_mapControl->mapEvent(this, mapEvent);
    delete mapEvent;
}

void AniBasicSteveMapCharacterController::tut_sendJumpFinishedEvent(cocos2d::Vec2 p_characterPosition, AniMapUtils::TileData p_tile){
    auto mapEvent = new AniTutorialMapControl::CharacterFinishedJumpingEvent(p_characterPosition, p_tile);
    m_mapControl->mapEvent(this, mapEvent);
    delete mapEvent;
}

void AniBasicSteveMapCharacterController::tut_sendTicklingFinishedEvent(){
    auto mapEvent = new AniTutorialMapControl::CharacterFinishedLaughingEvent();
    m_mapControl->mapEvent(this, mapEvent);
    delete mapEvent;
}