123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include "StoneTool.h"
- #include "Block.h"
- BrokenStoneToolItemType::BrokenStoneToolItemType()
- : ItemType(ID, "BrokenStoneTool", 0, 0, ModelInfo("itemCube", "blocks.ltdb/stone.png", 6)) // TODO: correct model
- {}
- Item* BrokenStoneToolItemType::createItem() const
- {
- return createBasicItem("Stone Tool", 100.f, 100.f, 100.f, 100.f, 0, 0, 0, 1, 0, 10);
- }
- StoneToolItemType::StoneToolItemType()
- : ItemType(ID, "StoneTool", new StoneToolLevelUpRule(), BrokenStoneToolItemType::INSTANCE, 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("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(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;
- zUsedItem->setHp(zUsedItem->getHp() - damage / 50);
- }
- }
- void StoneToolSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
- {
- // TODO
- }
|