1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include "StoneTool.h"
- #include "Block.h"
- BrokenStoneToolItemType::BrokenStoneToolItemType()
- : ItemType(ID, "BrokenStoneTool", 0, 0, ModelInfo("itemCube", "player.ltdb/player.png", 6)) // TODO: correct model
- {}
- Item* BrokenStoneToolItemType::createItem() const
- {
- return createBasicItem("Stone Tool", 0.f, 0.f, 0.f, 0.f, 0, 0, 0, 1, 0, 10);
- }
- StoneToolItemType::StoneToolItemType()
- : ItemType(ID, "StoneTool", new StoneToolLevelUpRule(), BrokenStoneToolItemType::INSTANCE, ModelInfo("itemCube", "player.ltdb/player.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("Stone Tool", 0.f, 0.f, 10.f, 10.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(StoneToolItemType::INSTANCE)
- {
- level = 1;
- xp = 0;
- maxXP = 10;
- }
- void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
- {
- if (zTarget && zTarget->getHardness() <= 2)
- {
- float damage = (1 + ((float)level / 10.f)) / (zTarget->getHardness() + 1);
- zTarget->setHP(zTarget->getHP() - damage);
- xp += damage / 20;
- }
- }
- void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
- {
- // TODO
- }
|