123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #include "Recipie.h"
- #include "CraftingStorage.h"
- Recipie::Recipie()
- : ReferenceCounter()
- {}
- void Recipie::addIngredient(ItemFilter* filter, int amount)
- {
- filters.add(filter);
- inputAmount.add(amount);
- }
- void Recipie::addOutput(Item* item, int amount)
- {
- outputs.add(item);
- outputAmount.add(amount);
- }
- bool Recipie::testApplicability(CraftingStorage* zStorage)
- {
- for (int i = 0; i < outputs.getEintragAnzahl(); i++)
- {
- if (!zStorage->hasFreeSpace(outputs.z(i), outputAmount.get(i)))
- return 0;
- }
- return zStorage->isAllAvailable(filters, inputAmount);
- }
- void Recipie::apply(CraftingStorage* zStorage)
- {
- zStorage->consume(filters, inputAmount);
- for (int i = 0; i < outputs.getEintragAnzahl(); i++)
- {
- ItemStack* stack
- = new ItemStack(outputs.z(i)->zItemType()->cloneItem(outputs.z(i)),
- outputAmount.get(i));
- zStorage->addCraftingResult(stack);
- stack->release();
- }
- }
- ShapedRecipie::ShapedRecipie(int width, int height)
- : ReferenceCounter(),
- width(width),
- height(height),
- output(0),
- outputAmount(0)
- {
- for (int i = 0; i < width * height; i++)
- {
- filters.add(0);
- modifiers.add(0);
- }
- }
- ShapedRecipie::~ShapedRecipie()
- {
- if (output) output->release();
- }
- void ShapedRecipie::setIngredient(
- int x, int y, ItemFilter* filter, ItemModifier* modifier)
- {
- filters.set(filter, width * y + x);
- modifiers.set(modifier, width * y + x);
- }
- void ShapedRecipie::setOutput(Item* item, int amount)
- {
- if (output) output->release();
- output = item;
- outputAmount = amount;
- }
- bool ShapedRecipie::testApplicability(ShapedCraftingStorage* zStorage)
- {
- return zStorage->isAllAvailable(filters, width, height)
- && zStorage->hasFreeSpace(output, outputAmount);
- }
- void ShapedRecipie::apply(ShapedCraftingStorage* zStorage)
- {
- zStorage->consume(filters, modifiers, width, height);
- ItemStack* stack
- = new ItemStack(output->zItemType()->cloneItem(output), outputAmount);
- zStorage->addCraftingResult(stack);
- stack->release();
- }
- Framework::Array<ItemInfo> ShapedRecipie::getOutput(
- ShapedCraftingStorage* zStorage)
- {
- Framework::Array<ItemInfo> result;
- ItemInfo info;
- info.count = outputAmount;
- info.type = output->zItemType()->getId();
- info.hp = output->getHp();
- info.durability = output->getDurability();
- info.maxHp = output->getMaxHp();
- info.maxDurability = output->getMaxDurability();
- result.add(info);
- return result;
- }
|