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;
78 
79  while (a) {
80  allowed.append(a->name);
81  a = a->next;
82  }
83  return allowed;
84 }
85 
86 AssetWrapper::PossibleUse ArtifactWrapper::uses(const AssetWrapper *asset, std::string &) const {
87  auto face = dynamic_cast<const FaceWrapper *>(asset);
88  if (face) {
89  return myWrappedItem->item->face == face->wrappedItem() ? Uses : DoesntUse;
90  }
91  auto anim = dynamic_cast<const AnimationWrapper *>(asset);
92  if (anim) {
93  return myWrappedItem->item->animation == anim->wrappedItem() ? Uses : DoesntUse;
94  }
95  return DoesntUse;
96 }
ArtifactWrapper::displayIcon
virtual QIcon displayIcon() const override
Definition: ArtifactWrapper.cpp:48
AssetTWrapper< artifact >::myWrappedItem
artifact * myWrappedItem
Definition: AssetWrapper.h:103
ArtifactListWrapper.h
obj::face
const Face * face
Definition: object.h:339
AssetWrapper::AssetUpdated
@ AssetUpdated
Definition: AssetWrapper.h:32
ResourcesManager
Definition: ResourcesManager.h:80
AnimationWrapper
Definition: AnimationWrapper.h:24
disinfect.a
a
Definition: disinfect.py:13
AssetWrapper::PossibleUse
PossibleUse
Definition: AssetWrapper.h:31
guildoracle.list
list
Definition: guildoracle.py:87
ResourcesManager::wrap
ArchetypeWrapper * wrap(archt *arch, AssetWrapper *parent)
Definition: ResourcesManager.h:126
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:65
linked_char
Definition: global.h:89
FaceWrapper
Definition: FaceWrapper.h:24
ArtifactWrapper::chance
int chance
Definition: ArtifactWrapper.h:29
artifactstruct::chance
uint16_t chance
Definition: artifact.h:16
ArtifactWrapper::item
QObject item
Definition: ArtifactWrapper.h:28
obj::name
sstring name
Definition: object.h:317
ArtifactWrapper::uses
virtual PossibleUse uses(const AssetWrapper *asset, std::string &) const override
Definition: ArtifactWrapper.cpp:86
AssetWrapper
Definition: AssetWrapper.h:25
artifactstruct::difficulty
uint8_t difficulty
Definition: artifact.h:17
FaceWrapper.h
AssetWrapper::Uses
@ Uses
Definition: AssetWrapper.h:31
ArtifactWrapper::ArtifactWrapper
ArtifactWrapper(AssetWrapper *parent, artifact *art, ResourcesManager *resourcesManager)
Definition: ArtifactWrapper.cpp:19
animate.anim
string anim
Definition: animate.py:20
obj::animation
const Animations * animation
Definition: object.h:424
artifact_compute_chance_for_item
void artifact_compute_chance_for_item(const object *op, const artifact *art, int *numerator, int *denominator)
Definition: artifact.cpp:141
ArtifactWrapper::difficulty
int difficulty
Definition: ArtifactWrapper.h:30
artifactstruct
Definition: artifact.h:14
ResourcesManager.h
obj::type
uint8_t type
Definition: object.h:346
ArtifactWrapper::mySpecificItem
const object * mySpecificItem
Definition: ArtifactWrapper.h:52
artifact_get_face
uint16_t artifact_get_face(const artifact *art)
Definition: artifact.cpp:642
ArtifactWrapper::myResourcesManager
ResourcesManager * myResourcesManager
Definition: ArtifactWrapper.h:51
ArtifactWrapper::allowed
QStringList allowed
Definition: ArtifactWrapper.h:31
artifactstruct::item
object * item
Definition: artifact.h:15
ArtifactWrapper.h
ArtifactWrapper::name
QString name
Definition: ArtifactWrapper.h:27
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition: AssetWrapper.h:54
AssetWrapper::DoesntUse
@ DoesntUse
Definition: AssetWrapper.h:31
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:575
artifactstruct::allowed
linked_char * allowed
Definition: artifact.h:19
AssetTWrapper
Definition: AssetWrapper.h:93