the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 110 lines 3.4 kB view raw
1#pragma once 2 3class ItemInstance; 4class Inventory; 5class DamageSource; 6class Enchantment; 7class EnchantmentInstance; 8 9class EnchantmentHelper 10{ 11private: 12 static Random random; 13 14public: 15 static int getEnchantmentLevel(int enchantmentId, shared_ptr<ItemInstance> piece); 16 static unordered_map<int, int> *getEnchantments(shared_ptr<ItemInstance> item); 17 static void setEnchantments(unordered_map<int, int> *enchantments, shared_ptr<ItemInstance> item); 18 19 static int getEnchantmentLevel(int enchantmentId, ItemInstanceArray inventory); 20 21private: 22 23 24 class EnchantmentIterationMethod 25 { 26 public: 27 virtual void doEnchantment(Enchantment *enchantment, int level) = 0; 28 }; 29 30 static void runIterationOnItem(EnchantmentIterationMethod &method, shared_ptr<ItemInstance> piece); 31 static void runIterationOnInventory(EnchantmentIterationMethod &method, ItemInstanceArray inventory); 32 33 class GetDamageProtectionIteration : public EnchantmentIterationMethod 34 { 35 public: 36 int sum; 37 DamageSource *source; 38 39 virtual void doEnchantment(Enchantment *enchantment, int level); 40 }; 41 42 static GetDamageProtectionIteration getDamageProtectionIteration; 43 44 /** 45 * Fetches the protection value for enchanted items. 46 * 47 * @param inventory 48 * @param source 49 * @return 50 */ 51public: 52 static int getDamageProtection(ItemInstanceArray armor, DamageSource *source); 53 54private: 55 class GetDamageBonusIteration : public EnchantmentIterationMethod 56 { 57 public: 58 float sum; 59 shared_ptr<LivingEntity> target; 60 61 virtual void doEnchantment(Enchantment *enchantment, int level); 62 }; 63 64 static GetDamageBonusIteration getDamageBonusIteration; 65 66 /** 67 * 68 * @param inventory 69 * @param target 70 * @return 71 */ 72public: 73 static float getDamageBonus(shared_ptr<LivingEntity> source, shared_ptr<LivingEntity> target); 74 static int getKnockbackBonus(shared_ptr<LivingEntity> source, shared_ptr<LivingEntity> target); 75 static int getFireAspect(shared_ptr<LivingEntity> source); 76 static int getOxygenBonus(shared_ptr<LivingEntity> source); 77 static int getDiggingBonus(shared_ptr<LivingEntity> source); 78 static int getDigDurability(shared_ptr<LivingEntity> source); 79 static bool hasSilkTouch(shared_ptr<LivingEntity> source); 80 static int getDiggingLootBonus(shared_ptr<LivingEntity> source); 81 static int getKillingLootBonus(shared_ptr<LivingEntity> source); 82 static bool hasWaterWorkerBonus(shared_ptr<LivingEntity> source); 83 static int getArmorThorns(shared_ptr<LivingEntity> source); 84 static shared_ptr<ItemInstance> getRandomItemWith(Enchantment *enchantment, shared_ptr<LivingEntity> source); 85 86 /** 87 * 88 * @param random 89 * @param slot 90 * The table slot, 0-2 91 * @param bookcases 92 * How many book cases that are found around the table. 93 * @param itemInstance 94 * Which item that is being enchanted. 95 * @return The enchantment cost, 0 means unchantable, 50 is max. 96 */ 97 static int getEnchantmentCost(Random *random, int slot, int bookcases, shared_ptr<ItemInstance> itemInstance); 98 99 static shared_ptr<ItemInstance> enchantItem(Random *random, shared_ptr<ItemInstance> itemInstance, int enchantmentCost); 100 101 /** 102 * 103 * @param random 104 * @param itemInstance 105 * @param enchantmentCost 106 * @return 107 */ 108 static vector<EnchantmentInstance *> *selectEnchantment(Random *random, shared_ptr<ItemInstance> itemInstance, int enchantmentCost); 109 static unordered_map<int, EnchantmentInstance *> *getAvailableEnchantmentResults(int value, shared_ptr<ItemInstance> itemInstance); 110};