1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #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);
- 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);
- 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->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
- }
|