12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #include "Shovel.h"
- #include "Game.h"
- ShovelToolItemType::ShovelToolItemType() // TODO: add broken Shovel
- : BasicToolItemType(ItemTypeEnum::SHOVEL,
- "Shovel",
- new ShovelToolLevelUpRule(),
- ItemTypeEnum::SHOVEL_BROKEN,
- ModelInfo("tools.m3/shovel", "tools.ltdb/stonehoe.png", 1)) // use same texture as hoe
- {}
- Item* ShovelToolItemType::createItem() const
- {
- return new BasicToolItem(ItemTypeEnum::SHOVEL, "Shovel");
- }
- ItemSkill* ShovelToolItemType::createDefaultItemSkill() const
- {
- return new ShovelToolSkill();
- }
- void ShovelToolItemType::loadSuperItemSkill(
- ItemSkill* zSkill, Framework::StreamReader* zReader) const
- {
- ShovelToolSkill* skill = dynamic_cast<ShovelToolSkill*>(zSkill);
- zReader->lese((char*)&skill->level, 4);
- zReader->lese((char*)&skill->xp, 4);
- zReader->lese((char*)&skill->maxXP, 4);
- }
- void ShovelToolItemType::saveSuperItemSkill(
- const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const
- {
- const ShovelToolSkill* skill = dynamic_cast<const ShovelToolSkill*>(zSkill);
- zWriter->schreibe((char*)&skill->level, 4);
- zWriter->schreibe((char*)&skill->xp, 4);
- zWriter->schreibe((char*)&skill->maxXP, 4);
- }
- ShovelToolLevelUpRule::ShovelToolLevelUpRule()
- : ItemSkillLevelUpRule()
- {}
- void ShovelToolLevelUpRule::applyOn(ItemSkill* zSkill)
- {
- ShovelToolSkill* skill = dynamic_cast<ShovelToolSkill*>(zSkill);
- if (skill->xp >= skill->maxXP)
- {
- skill->level++;
- skill->xp = 0;
- skill->maxXP = skill->maxXP * 2;
- }
- }
- ShovelToolSkill::ShovelToolSkill()
- : ItemSkill(ItemTypeEnum::SHOVEL),
- level(1),
- xp(0.f),
- maxXP(10.f)
- {}
- bool ShovelToolSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
- {
- if (zActor->getStamina() > 0.0001f)
- {
- if (zTarget->zBlockType()->getId() == BlockTypeEnum::DIRT
- || zTarget->zBlockType()->getId() == BlockTypeEnum::GRAVEL
- || zTarget->zBlockType()->getId() == BlockTypeEnum::SAND)
- {
- float damage
- = (2 + ((float)level / 3.f)) / (zTarget->getHardness() + 1);
- zTarget->setHP(zTarget->getHP() - damage);
- xp += damage / 20;
- zActor->setStamina(zActor->getStamina() - 0.0001f);
- zUsedItem->setDurability(zUsedItem->getDurability() - damage / 50);
- }
- else
- {
- zActor->setStamina(zActor->getStamina() - 0.0001f);
- zUsedItem->setDurability(zUsedItem->getDurability() - 0.001f);
- }
- return true;
- }
- return false;
- }
- bool ShovelToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
- {
- // an Shovel can not be used on an entity
- return 0;
- }
|