-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt at adding auction dialog functionality
(cherry picked from commit b21df8308be3c62f0ff40203a685e485b3060516)
- Loading branch information
Showing
19 changed files
with
470 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Illarionserver - server for the game Illarion | ||
* Copyright 2011 Illarion e.V. | ||
* | ||
* This file is part of Illarionserver. | ||
* | ||
* Illarionserver is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* Illarionserver 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 Affero General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License along with | ||
* Illarionserver. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "dialog/AuctionDialog.hpp" | ||
|
||
#include "data/Data.hpp" | ||
|
||
AuctionDialog::AuctionDialog(const string &title, const luabind::object &callback) | ||
: Dialog(title, "AuctionDialog", callback) {} | ||
|
||
auto AuctionDialog::getOffersSize() const -> index_type { return offers.size(); } | ||
|
||
auto AuctionDialog::getOffersBegin() const -> offer_iterator { return offers.cbegin(); } | ||
|
||
auto AuctionDialog::getOffersEnd() const -> offer_iterator { return offers.cend(); } | ||
|
||
void AuctionDialog::addOffer(TYPE_OF_ITEM_ID item, const string &name, TYPE_OF_WORTH price) { | ||
const auto &itemStruct = Data::items()[item]; | ||
addOffer(item, name, price, itemStruct.BuyStack); | ||
} | ||
|
||
void AuctionDialog::addOffer(TYPE_OF_ITEM_ID item, const string &name, TYPE_OF_WORTH price, TYPE_OF_BUY_STACK stack) { | ||
if (canAddOffer()) { | ||
offers.emplace_back(item, name, price, stack); | ||
} | ||
} | ||
|
||
auto AuctionDialog::getPrimaryRequestsSize() const -> index_type { return getProductsSize(primaryRequests); } | ||
|
||
auto AuctionDialog::getPrimaryRequestsBegin() const -> product_iterator { return getProductsBegin(primaryRequests); } | ||
|
||
auto AuctionDialog::getPrimaryRequestsEnd() const -> product_iterator { return getProductsEnd(primaryRequests); } | ||
|
||
void AuctionDialog::addPrimaryRequest(TYPE_OF_ITEM_ID item, const string &name, TYPE_OF_WORTH price) { | ||
addProduct(primaryRequests, item, name, price); | ||
} | ||
|
||
auto AuctionDialog::getSecondaryRequestsSize() const -> index_type { return getProductsSize(secondaryRequests); } | ||
|
||
auto AuctionDialog::getSecondaryRequestsBegin() const -> product_iterator { | ||
return getProductsBegin(secondaryRequests); | ||
} | ||
|
||
auto AuctionDialog::getSecondaryRequestsEnd() const -> product_iterator { return getProductsEnd(secondaryRequests); } | ||
|
||
void AuctionDialog::addSecondaryRequest(TYPE_OF_ITEM_ID item, const string &name, TYPE_OF_WORTH price) { | ||
addProduct(secondaryRequests, item, name, price); | ||
} | ||
|
||
auto AuctionDialog::getResult() const -> Result { return result; } | ||
|
||
void AuctionDialog::setResult(Result result) { this->result = result; } | ||
|
||
auto AuctionDialog::getPurchaseIndex() const -> index_type { return purchaseIndex; } | ||
|
||
void AuctionDialog::setPurchaseIndex(index_type index) { purchaseIndex = index; } | ||
|
||
auto AuctionDialog::getPurchaseAmount() const -> Item::number_type { return purchaseAmount; } | ||
|
||
void AuctionDialog::setPurchaseAmount(Item::number_type amount) { purchaseAmount = amount; } | ||
|
||
auto AuctionDialog::getSaleItem() const -> const ScriptItem & { return saleItem; } | ||
|
||
void AuctionDialog::setSaleItem(const ScriptItem &item) { saleItem = item; } | ||
|
||
auto AuctionDialog::getLookAtList() const -> ListType { return lookAtList; } | ||
|
||
void AuctionDialog::setLookAtList(ListType list) { lookAtList = list; } | ||
|
||
auto AuctionDialog::closeOnMove() const -> bool { return true; } | ||
|
||
auto AuctionDialog::getProductsSize(const product_list &products) -> index_type { return products.size(); } | ||
|
||
auto AuctionDialog::getProductsBegin(const product_list &products) -> product_iterator { return products.cbegin(); } | ||
|
||
auto AuctionDialog::getProductsEnd(const product_list &products) -> product_iterator { return products.cend(); } | ||
|
||
void AuctionDialog::addProduct(product_list &products, TYPE_OF_ITEM_ID item, const string &name, TYPE_OF_WORTH price) { | ||
if (canAddProduct(products)) { | ||
products.emplace_back(item, name, price); | ||
} | ||
} | ||
|
||
auto AuctionDialog::canAddOffer() const -> bool { return offers.size() < MAXPRODUCTS; } | ||
|
||
auto AuctionDialog::canAddProduct(const product_list &products) -> bool { return products.size() < MAXPRODUCTS; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Illarionserver - server for the game Illarion | ||
* Copyright 2011 Illarion e.V. | ||
* | ||
* This file is part of Illarionserver. | ||
* | ||
* Illarionserver is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* Illarionserver 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 Affero General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License along with | ||
* Illarionserver. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef AUCTION_DIALOG_HPP | ||
#define AUCTION_DIALOG_HPP | ||
|
||
#include "Item.hpp" | ||
#include "dialog/Dialog.hpp" | ||
|
||
#include <utility> | ||
#include <vector> | ||
|
||
using std::vector; | ||
|
||
class Product { | ||
private: | ||
TYPE_OF_ITEM_ID item; | ||
string name; | ||
TYPE_OF_WORTH price; | ||
|
||
public: | ||
Product(TYPE_OF_ITEM_ID item, string name, TYPE_OF_WORTH price) : item(item), name(std::move(name)), price(price){}; | ||
[[nodiscard]] auto getItem() const -> TYPE_OF_ITEM_ID { return item; }; | ||
[[nodiscard]] auto getName() const -> const string & { return name; }; | ||
[[nodiscard]] auto getPrice() const -> TYPE_OF_WORTH { return price; }; | ||
}; | ||
|
||
class OfferProduct : public Product { | ||
private: | ||
TYPE_OF_BUY_STACK stack; | ||
|
||
public: | ||
OfferProduct(TYPE_OF_ITEM_ID item, const string &name, TYPE_OF_WORTH price, TYPE_OF_BUY_STACK stack) | ||
: Product(item, name, price), stack(stack){}; | ||
[[nodiscard]] auto getStack() const -> TYPE_OF_BUY_STACK { return stack; }; | ||
}; | ||
|
||
class AuctionDialog : public Dialog { | ||
public: | ||
using index_type = uint8_t; | ||
using product_list = vector<Product>; | ||
using product_iterator = product_list::const_iterator; | ||
using offer_list = vector<OfferProduct>; | ||
using offer_iterator = offer_list::const_iterator; | ||
|
||
enum Result { playerAborts = 0, playerBids = 1, playerLooksAt = 2 }; | ||
|
||
enum ListType { listBid = 1 }; | ||
|
||
private: | ||
static const uint32_t MAXPRODUCTS = 256; | ||
offer_list offers; | ||
product_list primaryRequests; | ||
product_list secondaryRequests; | ||
|
||
Result result{playerAborts}; | ||
|
||
index_type purchaseIndex{0}; | ||
Item::number_type purchaseAmount{0}; | ||
|
||
ScriptItem saleItem; | ||
|
||
ListType lookAtList{listSell}; | ||
|
||
public: | ||
AuctionDialog(const string &title, const luabind::object &callback); | ||
|
||
auto getOffersSize() const -> index_type; | ||
auto getOffersBegin() const -> offer_iterator; | ||
auto getOffersEnd() const -> offer_iterator; | ||
void addOffer(TYPE_OF_ITEM_ID item, const string &name, TYPE_OF_WORTH price); | ||
void addOffer(TYPE_OF_ITEM_ID item, const string &name, TYPE_OF_WORTH price, TYPE_OF_BUY_STACK stack); | ||
|
||
auto getPrimaryRequestsSize() const -> index_type; | ||
auto getPrimaryRequestsBegin() const -> product_iterator; | ||
auto getPrimaryRequestsEnd() const -> product_iterator; | ||
void addPrimaryRequest(TYPE_OF_ITEM_ID item, const string &name, TYPE_OF_WORTH price); | ||
|
||
auto getSecondaryRequestsSize() const -> index_type; | ||
auto getSecondaryRequestsBegin() const -> product_iterator; | ||
auto getSecondaryRequestsEnd() const -> product_iterator; | ||
void addSecondaryRequest(TYPE_OF_ITEM_ID item, const string &name, TYPE_OF_WORTH price); | ||
|
||
auto getResult() const -> Result; | ||
void setResult(Result result); | ||
|
||
auto getPurchaseIndex() const -> index_type; | ||
void setPurchaseIndex(index_type index); | ||
auto getPurchaseAmount() const -> Item::number_type; | ||
void setPurchaseAmount(Item::number_type amount); | ||
|
||
auto getSaleItem() const -> const ScriptItem &; | ||
void setSaleItem(const ScriptItem &item); | ||
|
||
auto getLookAtList() const -> ListType; | ||
void setLookAtList(ListType list); | ||
|
||
auto closeOnMove() const -> bool override; | ||
|
||
private: | ||
static auto getProductsSize(const product_list &products) -> index_type; | ||
static auto getProductsBegin(const product_list &products) -> product_iterator; | ||
static auto getProductsEnd(const product_list &products) -> product_iterator; | ||
static void addProduct(product_list &products, TYPE_OF_ITEM_ID item, const string &name, TYPE_OF_WORTH price); | ||
auto canAddOffer() const -> bool; | ||
static auto canAddProduct(const product_list &products) -> bool; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.