1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include "Hoe.h"
- #include "Game.h"
- HoeToolItemType::HoeToolItemType() // TODO: add broken hoe
- : BasicToolItemType(ItemTypeEnum::HOE, "Hoe", new HoeToolLevelUpRule(), 0, 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)
- {}
- void HoeToolSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
- {
- if (nextActionCounter == 0)
- {
- if (zTarget->zBlockType()->getId() == BlockTypeEnum::DIRT)
- {
- if (zActor->getStamina() > 0.5f / (float)level)
- {
- 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 if (nextActionCounter > 0)
- nextActionCounter--;
- }
- void HoeToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
- {
- // a hoe can not be used on an entity
- }
|