-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
item.cpp
731 lines (635 loc) · 22.2 KB
/
item.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/* Copyright (C) 2013-2014 Michal Brzozowski (rusolis@poczta.fm)
This file is part of KeeperRL.
KeeperRL is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
KeeperRL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.gnu.org/licenses/ . */
#include "stdafx.h"
#include "item.h"
#include "creature.h"
#include "level.h"
#include "statistics.h"
#include "effect.h"
#include "view_object.h"
#include "game.h"
#include "player_message.h"
#include "fire.h"
#include "item_attributes.h"
#include "view.h"
#include "sound.h"
#include "item_class.h"
#include "corpse_info.h"
#include "equipment.h"
#include "attr_type.h"
#include "attack.h"
#include "lasting_effect.h"
#include "creature_name.h"
#include "creature_attributes.h"
#include "content_factory.h"
#include "creature_factory.h"
#include "effect_type.h"
#include "creature_debt.h"
template <class Archive>
void Item::serialize(Archive& ar, const unsigned int version) {
ar(SUBCLASS(OwnedObject<Item>), SUBCLASS(UniqueEntity), SUBCLASS(Renderable));
if (version == 0) {
HeapAllocated<ItemAttributes> SERIAL(attr);
ar(attr);
attributes = make_shared<ItemAttributes>(std::move(*attr));
} else
ar(attributes);
ar(discarded, shopkeeper, fire, classCache, canEquipCache, timeout, abilityInfo);
}
SERIALIZABLE(Item)
SERIALIZATION_CONSTRUCTOR_IMPL(Item)
Item::Item(SItemAttributes attr, const ContentFactory* factory)
: Renderable(ViewObject(attr->viewId, ViewLayer::ITEM, capitalFirst(attr->name))),
attributes(attr), fire(attr->burnTime), canEquipCache(!!attributes->equipmentSlot),
classCache(attributes->itemClass) {
if (!attributes->prefixes.empty())
modViewObject().setModifier(ViewObject::Modifier::AURA);
modViewObject().setGenericId(getUniqueId().getGenericId());
modViewObject().partIds = attributes->partIds;
updateAbility(factory);
}
void Item::setAttributes(SItemAttributes a) {
attributes = a;
}
void Item::updateAbility(const ContentFactory* factory) {
abilityInfo.clear();
for (auto id : attributes->equipedAbility)
abilityInfo.push_back(ItemAbility { *factory->getCreatures().getSpell(id), none, getUniqueId().getGenericId() });
}
void Item::upgrade(vector<PItem> runes, const ContentFactory* factory) {
unordered_map<string, double> multipliers;
for (auto& rune : runes)
if (auto& upgradeInfo = rune->getUpgradeInfo()) {
applyPrefix(*upgradeInfo->prefix, factory);
double mult = 1.0;
if (auto& d = upgradeInfo->diminishModifier) {
if (!multipliers.count(d->first))
multipliers[d->first] = 1.0;
mult = multipliers[d->first];
multipliers[d->first] *= d->second;
}
for (auto& mod : rune->getModifierValues())
addModifier(mod.first, mod.second * mult);
for (auto& a : rune->getAbility())
attributes->equipedAbility.push_back(a.spell.getId());
updateAbility(factory);
attributes->equipedEffect.append(rune->attributes->equipedEffect);
attributes->equipedCompanion = rune->attributes->equipedCompanion;
attributes->weaponInfo.attackerEffect.append(rune->attributes->weaponInfo.attackerEffect);
attributes->weaponInfo.victimEffect.append(rune->attributes->weaponInfo.victimEffect);
for (auto& elem : rune->attributes->specialAttr)
attributes->specialAttr.insert(elem);
}
}
Item::~Item() {
}
PItem Item::getCopy(const ContentFactory* f) const {
auto ret = makeOwner<Item>(make_shared<ItemAttributes>(*attributes), f);
ret->getAbility().clear();
return ret;
}
ItemPredicate Item::classPredicate(ItemClass cl) {
return [cl](const Item* item) { return item->getClass() == cl; };
}
ItemPredicate Item::equipmentSlotPredicate(EquipmentSlot slot) {
return [slot](const Item* item) { return item->canEquip() && item->getEquipmentSlot() == slot; };
}
ItemPredicate Item::classPredicate(vector<ItemClass> cl) {
return [cl](const Item* item) { return cl.contains(item->getClass()); };
}
ItemPredicate Item::namePredicate(const string& name) {
PROFILE;
return [name](const Item* item) { return item->getName() == name; };
}
vector<vector<Item*>> Item::stackItems(const ContentFactory* f, vector<Item*> items,
function<string(const Item*)> suffix) {
PROFILE;
map<string, vector<Item*>> stacks = groupBy<Item*, string>(items, [suffix, f](const Item* item) {
return item->getNameAndModifiers(f) + suffix(item) + toString(item->getViewObject().id().getColor());
});
vector<vector<Item*>> ret;
for (auto& elem : stacks)
ret.push_back(elem.second);
return ret;
}
void Item::onOwned(Creature* c, bool msg, const ContentFactory* factory) {
if (attributes->ownedEffect)
addPermanentEffect(*attributes->ownedEffect, c, msg, factory);
}
void Item::onDropped(Creature* c, bool msg, const ContentFactory* factory) {
if (attributes->ownedEffect)
removePermanentEffect(*attributes->ownedEffect, c, msg, factory);
}
const vector<LastingOrBuff>& Item::getEquipedEffects() const {
return attributes->equipedEffect;
}
void Item::onEquip(Creature* c, bool msg, const ContentFactory* factory) {
for (auto& e : attributes->equipedEffect)
addPermanentEffect(e, c, msg, factory);
if (attributes->equipedCompanion)
c->getAttributes().companions.push_back(*attributes->equipedCompanion);
}
void Item::onUnequip(Creature* c, bool msg, const ContentFactory* factory) {
for (auto& e : attributes->equipedEffect)
removePermanentEffect(e, c, msg, factory);
if (attributes->equipedCompanion)
[&, &companions = c->getAttributes().companions] {
for (int i : All(companions))
if (companions[i].creatures == attributes->equipedCompanion->creatures) {
c->removeCompanions(i);
return;
}
FATAL << "Error removing companion";
}();
}
void Item::fireDamage(Position position) {
bool burning = fire->isBurning();
string noBurningName = getTheName();
fire->set();
if (!burning && fire->isBurning()) {
position.globalMessage(noBurningName + " catches fire");
modViewObject().setAttribute(ViewObject::Attribute::BURNING, min(1.0, double(fire->getBurnState()) / 50));
}
}
void Item::iceDamage(Position) {
}
const Fire& Item::getFire() const {
return *fire;
}
bool Item::canEverTick(bool carried) const {
return discarded || fire->canBurn() || !!timeout || (carried && attributes->carriedTickEffect);
}
void Item::tick(Position position, bool carried) {
PROFILE_BLOCK("Item::tick");
if (fire->isBurning()) {
// INFO << getName() << " burning ";
position.fireDamage(5);
modViewObject().setAttribute(ViewObject::Attribute::BURNING, min(1.0, double(fire->getBurnState()) / 50));
fire->tick();
if (!fire->isBurning()) {
position.globalMessage(getTheName() + " burns out");
discarded = true;
}
}
specialTick(position);
if (timeout) {
if (position.getGame()->getGlobalTime() >= *timeout) {
position.globalMessage(getTheName() + " disappears!");
discarded = true;
}
}
if (carried && attributes->carriedTickEffect)
attributes->carriedTickEffect->apply(position);
}
void Item::applyPrefix(const ItemPrefix& prefix, const ContentFactory* factory) {
modViewObject().setModifier(ViewObject::Modifier::AURA);
::applyPrefix(factory, prefix, *attributes);
updateAbility(factory);
}
void Item::setTimeout(GlobalTime t) {
timeout = t;
}
void Item::onHitSquareMessage(Position pos, const Attack& attack, int numItems) {
if (attributes->fragile) {
pos.globalMessage(getPluralTheNameAndVerb(numItems, "crashes", "crash") + " on the " + pos.getName());
pos.unseenMessage("You hear a crash");
discarded = true;
} else
pos.globalMessage(getPluralTheNameAndVerb(numItems, "hits", "hit") + " the " + pos.getName());
if (attributes->ownedEffect && *attributes->ownedEffect == LastingEffect::LIGHT_SOURCE)
pos.fireDamage(20);
if (attributes->effect && effectAppliedWhenThrown())
attributes->effect->apply(pos, attack.attacker);
}
bool Item::effectAppliedWhenThrown() const {
return attributes->effectAppliedWhenThrown;
}
const optional<CreaturePredicate>& Item::getApplyPredicate() const {
return attributes->applyPredicate;
}
vector<ItemAbility>& Item::getAbility() {
for (auto& info : abilityInfo)
if (info.itemId != getUniqueId().getGenericId()) {
info.itemId = getUniqueId().getGenericId();
info.timeout = none;
}
return abilityInfo;
}
void Item::onHitCreature(Creature* c, const Attack& attack, int numItems) {
if (attributes->fragile) {
c->you(numItems > 1 ? MsgType::ITEM_CRASHES_PLURAL : MsgType::ITEM_CRASHES, getPluralTheName(numItems));
discarded = true;
} else
c->you(numItems > 1 ? MsgType::HIT_THROWN_ITEM_PLURAL : MsgType::HIT_THROWN_ITEM, getPluralTheName(numItems));
if (attributes->effect && effectAppliedWhenThrown())
attributes->effect->apply(c->getPosition(), attack.attacker);
c->takeDamage(attack);
}
TimeInterval Item::getApplyTime() const {
return attributes->applyTime;
}
double Item::getWeight() const {
return attributes->weight;
}
vector<string> Item::getDescription(const ContentFactory* factory) const {
vector<string> ret;
if (!attributes->description.empty())
ret.push_back(attributes->description);
if (attributes->effectDescription)
if (auto& effect = attributes->effect) {
ret.push_back("Usage effect: " + effect->getName(factory));
ret.push_back(effect->getDescription(factory));
}
for (auto& effect : getWeaponInfo().victimEffect)
ret.push_back("Victim affected by: " + effect.effect.getName(factory) + " (" + toPercentage(effect.chance) + " chance)");
for (auto& effect : getWeaponInfo().attackerEffect)
ret.push_back("Attacker affected by: " + effect.getName(factory));
for (auto& effect : attributes->equipedEffect) {
ret.push_back("Effect when equipped: " + ::getName(effect, factory));
ret.push_back(::getDescription(effect, factory));
}
if (auto& info = attributes->upgradeInfo)
ret.append(info->getDescription(factory));
for (auto& info : abilityInfo)
ret.push_back("Grants ability: "_s + info.spell.getName(factory));
for (auto& elem : attributes->specialAttr)
ret.push_back(toStringWithSign(elem.second.first) + " " + factory->attrInfo.at(elem.first).name + " " +
elem.second.second.getName(factory));
return ret;
}
bool Item::hasOwnedEffect(LastingEffect e) const {
return attributes->ownedEffect && *attributes->ownedEffect == e;
}
CreaturePredicate Item::getAutoEquipPredicate() const {
return attributes->autoEquipPredicate;
}
const string& Item::getEquipWarning() const {
return attributes->equipWarning;
}
const WeaponInfo& Item::getWeaponInfo() const {
return attributes->weaponInfo;
}
ItemClass Item::getClass() const {
return classCache;
}
const vector<StorageId>& Item::getStorageIds() const {
return attributes->storageIds;
}
const optional<string>& Item::getEquipmentGroup() const {
return attributes->equipmentGroup;
}
ViewId Item::getEquipedViewId() const {
return attributes->equipedViewId.value_or(getViewObject().id());
}
int Item::getPrice() const {
return attributes->price;
}
CostInfo Item::getCraftingCost() const {
return attributes->craftingCost;
}
bool Item::isShopkeeper(const Creature* c) const {
return shopkeeper == c->getUniqueId();
}
void Item::setShopkeeper(const Creature* s) {
if (s)
shopkeeper = s->getUniqueId();
else
shopkeeper = none;
}
bool Item::isOrWasForSale() const {
return !!shopkeeper;
}
optional<CollectiveResourceId> Item::getResourceId() const {
return attributes->resourceId;
}
void Item::setResourceId(optional<CollectiveResourceId> id) {
attributes->resourceId = id;
}
const optional<ItemUpgradeInfo>& Item::getUpgradeInfo() const {
return attributes->upgradeInfo;
}
void Item::setUpgradeInfo(ItemUpgradeInfo info) {
attributes->upgradeInfo = std::move(info);
}
vector<ItemUpgradeType> Item::getAppliedUpgradeType() const {
auto c = getClass();
if (!attributes->upgradeType.empty())
return attributes->upgradeType;
switch (c) {
case ItemClass::ARMOR:
return {ItemUpgradeType::ARMOR};
case ItemClass::WEAPON:
return {ItemUpgradeType::WEAPON};
case ItemClass::RANGED_WEAPON:
return {ItemUpgradeType::RANGED_WEAPON};
default:
return {};
}
}
int Item::getMaxUpgrades() const {
return attributes->maxUpgrades;
}
const optional<string>& Item::getIngredientType() const {
return attributes->ingredientType;
}
void Item::apply(Creature* c, bool noSound) {
if (attributes->applySound && !noSound)
c->getPosition().addSound(*attributes->applySound);
applySpecial(c);
}
bool Item::canApply() const {
return !!attributes->effect;
}
void Item::applySpecial(Creature* c) {
if (attributes->uses > -1 && --attributes->uses == 0) {
discarded = true;
if (attributes->usedUpMsg)
c->privateMessage(getTheName() + " is used up.");
}
if (attributes->effect)
attributes->effect->apply(c->getPosition(), c);
}
string Item::getApplyMsgThirdPerson(const Creature* owner) const {
if (attributes->applyMsgThirdPerson)
return *attributes->applyMsgThirdPerson;
switch (getClass()) {
case ItemClass::FOOD: return "eats " + getAName(false, owner);
default: return attributes->applyVerb.second + " " + getAName(false, owner);
}
}
string Item::getApplyMsgFirstPerson(const Creature* owner) const {
if (attributes->applyMsgFirstPerson)
return *attributes->applyMsgFirstPerson;
switch (getClass()) {
case ItemClass::FOOD: return "eat " + getAName(false, owner);
default: return attributes->applyVerb.first + " " + getAName(false, owner);
}
}
optional<StatId> Item::getProducedStat() const {
return attributes->producedStat;
}
void Item::setName(const string& n) {
attributes->name = n;
}
Creature* Item::getShopkeeper(const Creature* owner) const {
if (shopkeeper) {
for (Creature* c : owner->getDebt().getCreditors(owner))
if (c->getUniqueId() == *shopkeeper)
return c;
for (Creature* c : owner->getVisibleCreatures())
if (c->getUniqueId() == *shopkeeper)
return c;
}
return nullptr;
}
string Item::getName(bool plural, const Creature* owner) const {
PROFILE;
string suff;
if (fire->isBurning())
suff.append(" (burning)");
if (owner && getShopkeeper(owner))
suff += " (" + toString(getPrice()) + (plural ? " gold each)" : " gold)");
if (owner && owner->isAffected(LastingEffect::BLIND))
return getBlindName(plural);
return getVisibleName(plural) + suff;
}
string Item::getAName(bool getPlural, const Creature* owner) const {
PROFILE;
if (attributes->noArticle || getPlural)
return getName(getPlural, owner);
else
return addAParticle(getName(getPlural, owner));
}
string Item::getTheName(bool getPlural, const Creature* owner) const {
PROFILE;
string the = (attributes->noArticle || getPlural) ? "" : "the ";
return the + getName(getPlural, owner);
}
string Item::getPluralName(int count) const {
PROFILE;
if (count > 1)
return toString(count) + " " + getName(true);
else
return getName(false);
}
string Item::getPluralTheName(int count) const {
if (count > 1)
return toString(count) + " " + getTheName(true);
else
return getTheName(false);
}
string Item::getPluralAName(int count) const {
if (count > 1)
return toString(count) + " " + getTheName(true);
else
return getAName(false);
}
string Item::getPluralTheNameAndVerb(int count, const string& verbSingle, const string& verbPlural) const {
return getPluralTheName(count) + " " + (count > 1 ? verbPlural : verbSingle);
}
static void appendWithSpace(string& s, const string& suf) {
if (!s.empty() && !suf.empty())
s += " ";
s += suf;
}
string Item::getVisibleName(bool getPlural) const {
string ret;
if (!getPlural)
ret = attributes->name;
else {
if (attributes->plural)
ret = *attributes->plural;
else if (attributes->name.back() != 's')
ret = attributes->name + "s";
else
ret = attributes->name;
}
if (!attributes->prefixes.empty())
ret = attributes->prefixes.back() + " " + ret;
appendWithSpace(ret, getSuffix());
return ret;
}
static string withSign(int a) {
if (a >= 0)
return "+" + toString(a);
else
return toString(a);
}
const optional<string>& Item::getArtifactName() const {
return attributes->artifactName;
}
void Item::setArtifactName(const string& s) {
attributes->artifactName = s;
}
string Item::getSuffix() const {
string artStr;
if (!attributes->suffixes.empty())
artStr += attributes->suffixes.back();
if (attributes->artifactName)
appendWithSpace(artStr, "named " + *attributes->artifactName);
if (fire->isBurning())
appendWithSpace(artStr, "(burning)");
return artStr;
}
string Item::getModifiers(const ContentFactory* factory, bool shorten) const {
HashSet<AttrType> printAttr;
if (!shorten) {
for (auto attr : attributes->modifiers)
printAttr.insert(attr.first);
} else
switch (getClass()) {
case ItemClass::OTHER:
for (auto& attr : attributes->modifiers)
if (attr.second > 0)
printAttr.insert(attr.first);
break;
case ItemClass::RANGED_WEAPON:
for (auto& attr : attributes->modifiers)
if (factory->attrInfo.at(attr.first).isAttackAttr)
printAttr.insert(attr.first);
break;
case ItemClass::WEAPON:
printAttr.insert(getWeaponInfo().meleeAttackAttr);
break;
case ItemClass::ARMOR:
printAttr.insert(AttrType("DEFENSE"));
if (attributes->modifiers.count(AttrType("PARRY")))
printAttr.insert(AttrType("PARRY"));
break;
default: break;
}
vector<string> attrStrings;
for (auto attr : printAttr)
attrStrings.push_back(withSign(getValueMaybe(attributes->modifiers, attr).value_or(0)) +
(shorten ? "" : " " + factory->attrInfo.at(attr).name));
string attrString = combine(attrStrings, true);
if (!attrString.empty())
attrString = "(" + attrString + ")";
if (attributes->uses > -1 && attributes->displayUses)
appendWithSpace(attrString, "(" + toString(attributes->uses) + " uses left)");
return attrString;
}
string Item::getShortName(const ContentFactory* factory, const Creature* owner, bool plural) const {
PROFILE;
if (owner && owner->isAffected(LastingEffect::BLIND) && attributes->blindName)
return getBlindName(plural);
if (attributes->artifactName)
return *attributes->artifactName + " " + getModifiers(factory, true);
string name;
if (!attributes->suffixes.empty())
name = attributes->suffixes.back();
else if (!attributes->prefixes.empty())
name = attributes->prefixes.back();
else if (attributes->shortName) {
name = *attributes->shortName;
appendWithSpace(name, getSuffix());
} else
name = getVisibleName(plural);
appendWithSpace(name, getModifiers(factory, true));
return name;
}
string Item::getNameAndModifiers(const ContentFactory* factory, bool getPlural, const Creature* owner) const {
PROFILE;
auto ret = getName(getPlural, owner);
appendWithSpace(ret, getModifiers(factory));
return ret;
}
string Item::getBlindName(bool plural) const {
PROFILE;
if (attributes->blindName)
return *attributes->blindName + (plural ? "s" : "");
else
return getName(plural);
}
bool Item::isDiscarded() {
return discarded;
}
const optional<AssembledMinion>& Item::getAssembledMinion() const {
return attributes->assembledMinion;
}
const optional<Effect>& Item::getEffect() const {
return attributes->effect;
}
bool Item::canEquip() const {
return canEquipCache;
}
EquipmentSlot Item::getEquipmentSlot() const {
CHECK(canEquip());
return *attributes->equipmentSlot;
}
bool Item::isConflictingEquipment(const Item* other) const {
auto impl = [](const Item* it1, const Item* it2) {
return it1->getWeaponInfo().twoHanded && it2->canEquip() && it2->getEquipmentSlot() == EquipmentSlot::SHIELD;
};
return other != this && (impl(this, other) || impl(other, this));
}
void Item::addModifier(AttrType type, int value) {
attributes->modifiers[type] += value;
}
const HashMap<AttrType, int>& Item::getModifierValues() const {
return attributes->modifiers;
}
int Item::getModifier(AttrType type) const {
int ret = getValueMaybe(attributes->modifiers, type).value_or(0);
// CHECK(abs(ret) < 10000) << type.data() << " " << ret << " " << getName();
return ret;
}
const HashMap<AttrType, pair<int, CreaturePredicate>>& Item::getSpecialModifiers() const {
return attributes->specialAttr;
}
optional<CorpseInfo> Item::getCorpseInfo() const {
return none;
}
void Item::getAttackMsg(const Creature* c, const string& enemyName) const {
auto weaponInfo = getWeaponInfo();
auto swingMsg = [&] (const char* verb) {
if (!weaponInfo.itselfMessage) {
c->secondPerson("You "_s + verb + " your " + getName() + " at " + enemyName);
c->thirdPerson(c->getName().the() + " " + verb + "s " + his(c->getAttributes().getGender()) + " " + getName() + " at " + enemyName);
} else {
c->secondPerson("You "_s + verb + " yourself at " + enemyName);
c->thirdPerson(c->getName().the() + " " + verb + "s " + himself(c->getAttributes().getGender()) + " at " + enemyName);
}
};
auto biteMsg = [&] (const char* verb2, const char* verb3) {
c->secondPerson("You "_s + verb2 + " " + enemyName);
c->thirdPerson(c->getName().the() + " " + verb3 + " " + enemyName);
};
switch (weaponInfo.attackMsg) {
case AttackMsg::SWING:
swingMsg("swing");
break;
case AttackMsg::THRUST:
swingMsg("thrust");
break;
case AttackMsg::WAVE:
swingMsg("wave");
break;
case AttackMsg::KICK:
biteMsg("kick", "kicks");
break;
case AttackMsg::BITE:
biteMsg("bite", "bites");
break;
case AttackMsg::TOUCH:
biteMsg("touch", "touches");
break;
case AttackMsg::CLAW:
biteMsg("claw", "claws");
break;
case AttackMsg::SPELL:
biteMsg("curse", "curses");
break;
case AttackMsg::PUNCH:
biteMsg("punch", "punches");
break;
}
}