Crossfire Server, Trunk
ArtifactWrapper.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "ArtifactWrapper.h"
14 #include "ResourcesManager.h"
15 #include "CREPixmap.h"
16 #include "faces/FaceWrapper.h"
17 #include "ArtifactListWrapper.h"
18 
20  : AssetTWrapper(parent, "Artifact", art), myResourcesManager(resourcesManager), mySpecificItem(nullptr)
21 {
22 }
23 
25  QString name(myWrappedItem->item->name);
26  if (mySpecificItem) {
27  int n, d;
29  name = tr("%1 (%2%, %3 chances on %4)")
30  .arg(name)
31  .arg(qRound(100. * n / d))
32  .arg(n)
33  .arg(d);
34  } else {
36  if (list && list->total_chance != 0) {
37  name = tr("%1 (%2%, %3 chances on %4)")
38  .arg(name)
39  .arg(qRound((float)100 * myWrappedItem->chance / list->total_chance))
40  .arg(myWrappedItem->chance)
41  .arg(list->total_chance);
42  }
43  }
44 
45  return name;
46 }
47 
50 }
51 
52 QString ArtifactWrapper::name() const {
53  return myWrappedItem->item->name;
54 }
55 
56 QObject* ArtifactWrapper::item() {
57  return myResourcesManager->wrap(myWrappedItem->item, this);
58 }
59 
60 int ArtifactWrapper::chance() const {
61  return myWrappedItem->chance;
62 }
63 
64 void ArtifactWrapper::setChance(int chance) {
65  if (myWrappedItem->chance != chance) {
68  }
69 }
70 
71 int ArtifactWrapper::difficulty() const {
72  return myWrappedItem->difficulty;
73 }
74 
75 QStringList ArtifactWrapper::allowed() const {
76  QStringList allowed;
77  for (const auto a : myWrappedItem->allowed)
78  allowed.append(a);
79  return allowed;
80 }
81 
82 AssetWrapper::PossibleUse ArtifactWrapper::uses(const AssetWrapper *asset, std::string &) const {
83  auto face = dynamic_cast<const FaceWrapper *>(asset);
84  if (face) {
85  return myWrappedItem->item->face == face->wrappedItem() ? Uses : DoesntUse;
86  }
87  auto anim = dynamic_cast<const AnimationWrapper *>(asset);
88  if (anim) {
89  return myWrappedItem->item->animation == anim->wrappedItem() ? Uses : DoesntUse;
90  }
91  return DoesntUse;
92 }
ArtifactWrapper::displayIcon
virtual QIcon displayIcon() const override
Definition: ArtifactWrapper.cpp:48
AssetTWrapper< artifact >::myWrappedItem
artifact * myWrappedItem
Definition: AssetWrapper.h:104
ArtifactListWrapper.h
AssetWrapper::AssetUpdated
@ AssetUpdated
Definition: AssetWrapper.h:33
ResourcesManager
Definition: ResourcesManager.h:80
AnimationWrapper
Definition: AnimationWrapper.h:24
disinfect.a
a
Definition: disinfect.py:13
ResourcesManager::wrap
ArchetypeWrapper * wrap(archetype *arch, AssetWrapper *parent)
Definition: ResourcesManager.h:132
AssetWrapper::PossibleUse
PossibleUse
Definition: AssetWrapper.h:32
guildoracle.list
list
Definition: guildoracle.py:87
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:65
artifact::item
object * item
Definition: artifact.h:15
artifact::allowed
std::vector< sstring > allowed
Definition: artifact.h:18
FaceWrapper
Definition: FaceWrapper.h:24
ArtifactWrapper::chance
int chance
Definition: ArtifactWrapper.h:29
ArtifactWrapper::item
QObject item
Definition: ArtifactWrapper.h:28
ArtifactWrapper::uses
virtual PossibleUse uses(const AssetWrapper *asset, std::string &) const override
Definition: ArtifactWrapper.cpp:82
AssetWrapper
Definition: AssetWrapper.h:25
object::face
const Face * face
Definition: object.h:341
object::type
uint8_t type
Definition: object.h:348
FaceWrapper.h
AssetWrapper::Uses
@ Uses
Definition: AssetWrapper.h:32
ArtifactWrapper::ArtifactWrapper
ArtifactWrapper(AssetWrapper *parent, artifact *art, ResourcesManager *resourcesManager)
Definition: ArtifactWrapper.cpp:19
animate.anim
string anim
Definition: animate.py:20
object::animation
const Animations * animation
Definition: object.h:428
artifact_compute_chance_for_item
void artifact_compute_chance_for_item(const object *op, const artifact *art, int *numerator, int *denominator)
Definition: artifact.cpp:133
ArtifactWrapper::difficulty
int difficulty
Definition: ArtifactWrapper.h:30
ResourcesManager.h
object::name
sstring name
Definition: object.h:319
artifact::chance
uint16_t chance
Definition: artifact.h:16
ArtifactWrapper::mySpecificItem
const object * mySpecificItem
Definition: ArtifactWrapper.h:52
artifact_get_face
uint16_t artifact_get_face(const artifact *art)
Definition: artifact.cpp:638
ArtifactWrapper::myResourcesManager
ResourcesManager * myResourcesManager
Definition: ArtifactWrapper.h:51
ArtifactWrapper::allowed
QStringList allowed
Definition: ArtifactWrapper.h:31
ArtifactWrapper.h
artifact::difficulty
uint8_t difficulty
Definition: artifact.h:17
ArtifactWrapper::name
QString name
Definition: ArtifactWrapper.h:27
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition: AssetWrapper.h:55
AssetWrapper::DoesntUse
@ DoesntUse
Definition: AssetWrapper.h:32
artifact
Definition: artifact.h:14
ArtifactWrapper::displayName
virtual QString displayName() const override
Definition: ArtifactWrapper.cpp:24
ArtifactWrapper::setChance
void setChance(int chance)
Definition: ArtifactWrapper.cpp:64
CREPixmap.h
find_artifactlist
artifactlist * find_artifactlist(int type)
Definition: artifact.cpp:574
AssetTWrapper
Definition: AssetWrapper.h:94