1 /* Copyright (C) 2013-2014 Michal Brzozowski (rusolis@poczta.fm)
2 
3    This file is part of KeeperRL.
4 
5    KeeperRL is free software; you can redistribute it and/or modify it under the terms of the
6    GNU General Public License as published by the Free Software Foundation; either version 2
7    of the License, or (at your option) any later version.
8 
9    KeeperRL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10    even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License along with this program.
14    If not, see http://www.gnu.org/licenses/ . */
15 
16 #pragma once
17 
18 #include "util.h"
19 #include "enums.h"
20 #include "unique_entity.h"
21 #include "renderable.h"
22 #include "position.h"
23 #include "owner_pointer.h"
24 
25 class Level;
26 class Attack;
27 class Fire;
28 class ItemAttributes;
29 class Effect;
30 struct CorpseInfo;
31 class RangedWeapon;
32 
33 class Item : public Renderable, public UniqueEntity<Item>, public OwnedObject<Item> {
34   public:
35   Item(const ItemAttributes&);
36   virtual ~Item();
37 
38   void apply(WCreature, bool noSound = false);
39 
40   bool isDiscarded();
41 
42   string getName(bool plural = false, WConstCreature owner = nullptr) const;
43   string getTheName(bool plural = false, WConstCreature owner = nullptr) const;
44   string getAName(bool plural = false, WConstCreature owner = nullptr) const;
45   string getNameAndModifiers(bool plural = false, WConstCreature owner = nullptr) const;
46   const optional<string>& getArtifactName() const;
47   void setArtifactName(const string&);
48   string getShortName(WConstCreature owner = nullptr, bool noSuffix = false) const;
49   string getPluralName(int count) const;
50   string getPluralTheName(int count) const;
51   string getPluralTheNameAndVerb(int count, const string& verbSingle, const string& verbPlural) const;
52 
53   const optional<Effect>& getEffect() const;
54   optional<Effect> getAttackEffect() const;
55   ItemClass getClass() const;
56 
57   int getPrice() const;
58   void setShopkeeper(WConstCreature shopkeeper);
59   WCreature getShopkeeper(WConstCreature owner) const;
60   bool isShopkeeper(WConstCreature) const;
61   // This function returns true after shopkeeper was killed. TODO: refactor shops.
62   bool isOrWasForSale() const;
63 
64   optional<TrapType> getTrapType() const;
65   optional<CollectiveResourceId> getResourceId() const;
66 
67   bool canEquip() const;
68   EquipmentSlot getEquipmentSlot() const;
69   void addModifier(AttrType, int value);
70   int getModifier(AttrType) const;
71   const optional<RangedWeapon>& getRangedWeapon() const;
72   AttrType getMeleeAttackAttr() const;
73   void tick(Position);
74 
75   string getApplyMsgThirdPerson(WConstCreature owner) const;
76   string getApplyMsgFirstPerson(WConstCreature owner) const;
77   string getNoSeeApplyMsg() const;
78 
79   void onEquip(WCreature);
80   void onUnequip(WCreature);
onEquipSpecial(WCreature)81   virtual void onEquipSpecial(WCreature) {}
onUnequipSpecial(WCreature)82   virtual void onUnequipSpecial(WCreature) {}
83   virtual void fireDamage(double amount, Position);
84   double getFireSize() const;
85 
86   void onHitSquareMessage(Position, int numItems);
87   void onHitCreature(WCreature c, const Attack& attack, int numItems);
88 
89   double getApplyTime() const;
90   double getWeight() const;
91   string getDescription() const;
92 
93   AttackType getAttackType() const;
94   bool isWieldedTwoHanded() const;
95   int getMinStrength() const;
96 
97   static ItemPredicate effectPredicate(Effect);
98   static ItemPredicate classPredicate(ItemClass);
99   static ItemPredicate equipmentSlotPredicate(EquipmentSlot);
100   static ItemPredicate classPredicate(vector<ItemClass>);
101   static ItemPredicate namePredicate(const string& name);
102   static ItemPredicate isRangedWeaponPredicate();
103 
104   static vector<vector<WItem>> stackItems(vector<WItem>,
105       function<string(WConstItem)> addSuffix = [](WConstItem) { return ""; });
106 
107   virtual optional<CorpseInfo> getCorpseInfo() const;
108 
109   SERIALIZATION_DECL(Item);
110 
111   protected:
specialTick(Position)112   virtual void specialTick(Position) {}
113   void setName(const string& name);
114   bool SERIAL(discarded) = false;
115   virtual void applySpecial(WCreature);
116 
117   private:
118   string getModifiers(bool shorten = false) const;
119   string getVisibleName(bool plural) const;
120   string getBlindName(bool plural) const;
121   HeapAllocated<ItemAttributes> SERIAL(attributes);
122   optional<UniqueEntity<Creature>::Id> SERIAL(shopkeeper);
123   HeapAllocated<Fire> SERIAL(fire);
124   bool SERIAL(canEquipCache);
125   ItemClass SERIAL(classCache);
126 };
127