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();

}
Exemple #2
0
void Plantable::Plant(std::shared_ptr<Item> 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();
   // Equip another item if we can find one
   for (auto item : Player::Get().GetInventory()) {
      if (item->ItemTarget->GetName() != sourceItem->GetName()) {
         continue;
      }

      Player::Get().EquipFromInventory(item->ItemTarget);
      break;
   }
}