Example #1
0
void Plantable::Plant(ItemPtr sourceItem)
{
    auto x = Player::Get().GetPositionX();
    auto y = Player::Get().GetPositionY();
    auto currentLandmark = GameState::Get().GetCurrentLandmark();
    auto currentTile = currentLandmark->GetTile(x, y);

    if (currentTile.TileType != TileType::Tilled) {
        GameState::Get().AddLogMessage("You can only plant on tilled land!");
        return;
    }

    auto item = currentLandmark->GetItem(x, y);
    if (item != nullptr) {
        GameState::Get().AddLogMessageFmt("Cannot plant, %s is on the ground here.", item->GetName().c_str());
        return;
    }

    auto crop = GameState::Get().GetItemFromItemDatabase(this->Crop);
    crop->SetCount(1);
    currentLandmark->AddItem(x, y, crop);

    auto growableInterface = crop->GetInterface<Growable>(ItemInterfaceType::Growable);
    if (growableInterface != nullptr) {
        growableInterface->StartGrowing(crop);
    }

    sourceItem->RemoveOne();

}