123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #include "Hoe.h"
- #include "Game.h"
- HoeToolItemType::HoeToolItemType() // TODO: add broken hoe
- : BasicToolItemType(ItemTypeEnum::HOE,
- "Hoe",
- new HoeToolLevelUpRule(),
- ItemTypeEnum::BROKEN_HOE,
- ModelInfo("tools.m3/hoe", "tools.ltdb/stonehoe.png", 1))
- {}
- Item* HoeToolItemType::createItem() const
- {
- return new BasicToolItem(ItemTypeEnum::HOE, "Hoe");
- }
- ItemSkill* HoeToolItemType::createDefaultItemSkill() const
- {
- return new HoeToolSkill();
- }
- void HoeToolItemType::loadSuperItemSkill(
- ItemSkill* zSkill, Framework::StreamReader* zReader) const
- {
- HoeToolSkill* skill = dynamic_cast<HoeToolSkill*>(zSkill);
- zReader->lese((char*)&skill->level, 4);
- zReader->lese((char*)&skill->xp, 4);
- zReader->lese((char*)&skill->maxXP, 4);
- }
- void HoeToolItemType::saveSuperItemSkill(
- const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const
- {
- const HoeToolSkill* skill = dynamic_cast<const HoeToolSkill*>(zSkill);
- zWriter->schreibe((char*)&skill->level, 4);
- zWriter->schreibe((char*)&skill->xp, 4);
- zWriter->schreibe((char*)&skill->maxXP, 4);
- }
- HoeToolLevelUpRule::HoeToolLevelUpRule()
- : ItemSkillLevelUpRule()
- {}
- void HoeToolLevelUpRule::applyOn(ItemSkill* zSkill)
- {
- HoeToolSkill* skill = dynamic_cast<HoeToolSkill*>(zSkill);
- if (skill->xp >= skill->maxXP)
- {
- skill->level++;
- skill->xp = 0;
- skill->maxXP = skill->maxXP * 2;
- }
- }
- HoeToolSkill::HoeToolSkill()
- : ItemSkill(ItemTypeEnum::HOE),
- level(1),
- xp(0.f),
- maxXP(10.f),
- nextActionCounter(0)
- {}
- bool HoeToolSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
- {
- if (nextActionCounter == 0)
- {
- if (zActor->getStamina() > 0.5f / (float)level)
- {
- if (zTarget->zBlockType()->getId() == BlockTypeEnum::DIRT)
- {
- zActor->setStamina(
- zActor->getStamina() - 0.5f / (float)level);
- zUsedItem->setDurability(zUsedItem->getDurability() - 0.5f);
- Vec3<int> pos = zTarget->getPos();
- int dimension = zTarget->getDimensionId();
- xp += 0.5f;
- Game::INSTANCE->doLater([pos, dimension]() {
- Game::INSTANCE->zDimension(dimension)->placeBlock(
- pos, BlockTypeEnum::FARMLAND);
- });
- nextActionCounter = 20;
- }
- else
- {
- zUsedItem->setDurability(
- zUsedItem->getDurability() - 0.5f / (float)level);
- zActor->setStamina(zActor->getStamina() - 0.5f / (float)level);
- }
- return 1;
- }
- }
- else if (nextActionCounter > 0)
- nextActionCounter--;
- return 0;
- }
- bool HoeToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
- {
- // a hoe can not be used on an entity
- return 0;
- }
|