123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #include "StoneTool.h"
- #include "Block.h"
- #include "Player.h"
- StoneToolItemType::StoneToolItemType()
- : ItemType(ItemTypeEnum::STONE_TOOL,
- "StoneTool",
- new StoneToolLevelUpRule(),
- ItemTypeEnum::STONE_TOOL_BROKEN,
- ModelInfo("items.m3/stoneTool",
- "blocks.ltdb/stone.png",
- 6)) // TODO: correct model
- {}
- void StoneToolItemType::loadSuperItemSkill(
- ItemSkill* zSkill, Framework::StreamReader* zReader) const
- {
- StoneToolSkill* skill = dynamic_cast<StoneToolSkill*>(zSkill);
- if (!skill)
- throw "StoneToolItemType::loadSuperItemSkill was called with an "
- "invalid skill";
- zReader->lese((char*)&skill->level, 4);
- zReader->lese((char*)&skill->xp, 4);
- zReader->lese((char*)&skill->maxXP, 4);
- }
- void StoneToolItemType::saveSuperItemSkill(
- const ItemSkill* zSkill, Framework::StreamWriter* zWriter) const
- {
- const StoneToolSkill* skill = dynamic_cast<const StoneToolSkill*>(zSkill);
- if (!skill)
- throw "StoneToolItemType::saveSuperItemSkill was called with an "
- "invalid skill";
- zWriter->schreibe((char*)&skill->level, 4);
- zWriter->schreibe((char*)&skill->xp, 4);
- zWriter->schreibe((char*)&skill->maxXP, 4);
- }
- Item* StoneToolItemType::createItem() const
- {
- return createBasicItem(
- id, "Stone Tool", 100.f, 100.f, 100.f, 100.f, 0, 0, 0, 1, 1, 1);
- }
- ItemSkill* StoneToolItemType::createDefaultItemSkill() const
- {
- return new StoneToolSkill();
- }
- StoneToolLevelUpRule::StoneToolLevelUpRule()
- : ItemSkillLevelUpRule()
- {}
- void StoneToolLevelUpRule::applyOn(ItemSkill* zSkill)
- {
- StoneToolSkill* skill = dynamic_cast<StoneToolSkill*>(zSkill);
- if (!skill)
- throw "StoneToolLevelUpRule::applyOn was called with an invalid skill";
- if (skill->xp >= skill->maxXP)
- {
- skill->level++;
- skill->xp = 0;
- skill->maxXP = skill->maxXP * 1.5f;
- }
- }
- StoneToolSkill::StoneToolSkill()
- : ItemSkill(ItemTypeEnum::STONE_TOOL)
- {
- level = 1;
- xp = 0;
- maxXP = 10;
- }
- void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
- {
- if (zActor->getStamina() > 0.0001f)
- {
- if (zTarget && zTarget->getHardness() <= 2)
- {
- float damage
- = (1 + ((float)level / 10.f)) / (zTarget->getHardness() + 1);
- zTarget->setHP(zTarget->getHP() - damage);
- xp += damage / 20;
- zActor->setStamina(zActor->getStamina() - 0.0001f);
- zUsedItem->setHp(zUsedItem->getHp() - damage / 50);
- }
- else
- {
- zActor->setStamina(zActor->getStamina() - 0.0001f);
- zUsedItem->setHp(zUsedItem->getHp() - 0.001f);
- }
- }
- }
- void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
- {
- // TODO
- }
|