本文整理汇总了C++中Town::getTownID方法的典型用法代码示例。如果您正苦于以下问题:C++ Town::getTownID方法的具体用法?C++ Town::getTownID怎么用?C++ Town::getTownID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Town
的用法示例。
在下文中一共展示了Town::getTownID方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getReceiver
bool Mailbox::getReceiver(Item* item, std::string& name, uint32_t& dp)
{
if(!item)
return false;
if(item->getID() == ITEM_PARCEL) /**We need to get the text from the label incase its a parcel**/
{
Container* parcel = item->getContainer();
if(parcel)
{
for(ItemList::const_iterator cit = parcel->getItems(); cit != parcel->getEnd(); cit++)
{
if((*cit)->getID() == ITEM_LABEL)
{
item = (*cit);
if(item->getText() != "")
break;
}
}
}
}
else if(item->getID() != ITEM_LETTER) /**The item is somehow not a parcel or letter**/
{
std::cout << "Mailbox::getReciver error, trying to get reciecer from unkown item! ID:: " << item->getID() << "." << std::endl;
return false;
}
if(!item || item->getText() == "") /**No label/letter found or its empty.**/
return false;
std::string temp;
std::istringstream iss(item->getText(), std::istringstream::in);
std::string strTown = "";
uint32_t curLine = 1;
while(getline(iss, temp, '\n'))
{
if(curLine == 1)
name = temp;
else if(curLine == 2)
strTown = temp;
else
break;
++curLine;
}
trimString(name);
trimString(strTown);
Town* town = Towns::getInstance().getTown(strTown);
if(town)
{
dp = town->getTownID();
return true;
}
return false;
}
示例2: getDepotId
bool Mailbox::getDepotId(const std::string& strTown, uint32_t& depotId)
{
Town* town = Towns::getInstance().getTown(strTown);
if(town){
depotId = town->getTownID();
}
else{
return false;
}
return true;
}
示例3: payHouses
bool Houses::payHouses()
{
if(rentPeriod == RENTPERIOD_NEVER) {
return true;
}
uint32_t currentTime = std::time(NULL);
for(HouseMap::iterator it = houseMap.begin(); it != houseMap.end(); ++it){
House* house = it->second;
if(house->getHouseOwner() != 0 && house->getPaidUntil() < currentTime &&
house->getRent() != 0){
uint32_t ownerid = house->getHouseOwner();
Town* town = Towns::getInstance().getTown(house->getTownId());
if(!town){
#ifdef __DEBUG_HOUSES__
std::cout << "Warning: [Houses::payHouses] town = NULL, townid = " <<
house->getTownId() << ", houseid = " << house->getHouseId() << std::endl;
#endif
continue;
}
std::string name;
if(!IOPlayer::instance()->getNameByGuid(ownerid, name)){
//player doesnt exist, remove it as house owner?
//house->setHouseOwner(0);
continue;
}
Player* player = g_game.getPlayerByName(name);
if(!player){
player = new Player(name, NULL);
if(!IOPlayer::instance()->loadPlayer(player, name)){
#ifdef __DEBUG__
std::cout << "Failure: [Houses::payHouses], can not load player: " << name << std::endl;
#endif
delete player;
continue;
}
}
Depot* depot = player->getDepot(town->getTownID(), true);
// savePlayerHere is an ugly hack
// to avoid saving 2 times a not online player
// when items are transferred to his depot
bool savePlayerHere = true;
if(depot){
//get money from depot
bool useAccBalance = g_config.getBool(ConfigManager::USE_ACCBALANCE) != 0;
bool hasEnoughMoney = false;
if(useAccBalance){
if(player->balance >= house->getRent()){
player->balance -= house->getRent();
hasEnoughMoney = true;
}
}
else{
hasEnoughMoney = g_game.removeMoney(depot, house->getRent(), FLAG_NOLIMIT);
}
if(hasEnoughMoney){
uint32_t paidUntil = currentTime;
switch(rentPeriod){
case RENTPERIOD_DAILY:
paidUntil += 24 * 60 * 60;
break;
case RENTPERIOD_WEEKLY:
paidUntil += 24 * 60 * 60 * 7;
break;
case RENTPERIOD_MONTHLY:
paidUntil += 24 * 60 * 60 * 30;
break;
case RENTPERIOD_YEARLY:
paidUntil += 24 * 60 * 60 * 365;
case RENTPERIOD_NEVER:
break;
}
house->setPaidUntil(paidUntil);
}
else if(currentTime >= house->getLastWarning() + 24 * 60 * 60){
if(house->getPayRentWarnings() >= 7){
house->setHouseOwner(0);
// setHouseOwner will load the player,
// transfer house items to his depot and then
// will save it, so here should not be saved
// again
savePlayerHere = false;
}
else{
int daysLeft = 7 - house->getPayRentWarnings();
Item* letter = Item::CreateItem(ITEM_LETTER_STAMPED);
std::string period = "";
switch(rentPeriod){
//.........这里部分代码省略.........
示例4: payHouse
bool Houses::payHouse(House* house, time_t time)
{
if(rentPeriod == RENTPERIOD_NEVER){
return true;
}
if(house->getRent() == 0 || house->getPaidUntil() > time || house->getHouseOwner() == 0){
return true;
}
uint32_t ownerid = house->getHouseOwner();
Town* town = Towns::getInstance()->getTown(house->getTownId());
if(!town){
#ifdef __DEBUG_HOUSES__
std::cout << "Warning: [Houses::payHouses] town = NULL, townid = " <<
house->getTownId() << ", houseid = " << house->getHouseId() << std::endl;
#endif
return false;
}
std::string name;
if(!IOPlayer::instance()->getNameByGuid(ownerid, name)){
//player doesnt exist, remove it as house owner?
//house->setHouseOwner(0);
return false;
}
Player* player = g_game.getPlayerByNameEx(name);
if(!player){
return false;
}
// savePlayerHere is an ugly hack
// to avoid saving 2 times a not online player
// when items are transferred to his depot
bool savePlayerHere = true;
bool hasPaidRent = payRent(player, house, time);
if(!hasPaidRent && time >= house->getLastWarning() + 24 * 60 * 60){
if(house->getPayRentWarnings() >= 7){
house->setHouseOwner(0);
// setHouseOwner will load the player,
// transfer house items to his depot and then
// will save it, so here should not be saved
// again
savePlayerHere = false;
}
else{
Depot* depot = player->getDepot(town->getTownID(), true);
if(depot){
int daysLeft = 7 - house->getPayRentWarnings();
Item* letter = Item::CreateItem(ITEM_LETTER_STAMPED);
std::string period = "";
switch(rentPeriod){
case RENTPERIOD_DAILY:
period = "daily";
break;
case RENTPERIOD_WEEKLY:
period = "weekly";
break;
case RENTPERIOD_MONTHLY:
period = "monthly";
break;
case RENTPERIOD_YEARLY:
period = "annual";
break;
case RENTPERIOD_NEVER:
//
break;
}
std::stringstream warningText;
warningText << "Warning! \n" <<
"The " << period << " rent of " << house->getRent() << " gold for your house \""
<< house->getName() << "\" is payable. Have it available within " << daysLeft <<
" days, or you will lose this house.";
letter->setText(warningText.str());
g_game.internalAddItem(NULL, depot, letter, INDEX_WHEREEVER);
house->setPayRentWarnings(house->getPayRentWarnings() + 1);
house->setLastWarning(time);
}
}
}
if(player->isOffline()){
if(savePlayerHere){
IOPlayer::instance()->savePlayer(player);
}
delete player;
}
return hasPaidRent;
}
示例5: payRent
bool Houses::payRent(Player* player, House* house, time_t time /*= 0*/)
{
if(rentPeriod == RENTPERIOD_NEVER){
return true;
}
if(time == 0){
time = std::time(NULL);
}
if(house->getRent() == 0 || house->getPaidUntil() > time){
return true;
}
Town* town = Towns::getInstance()->getTown(house->getTownId());
if(!town){
#ifdef __DEBUG_HOUSES__
std::cout << "Warning: [Houses::payHouses] town = NULL, townid = " <<
house->getTownId() << ", houseid = " << house->getHouseId() << std::endl;
#endif
return false;
}
bool hasEnoughMoney = false;
Depot* depot = player->getDepot(town->getTownID(), true);
if(depot){
if(g_config.getNumber(ConfigManager::USE_ACCBALANCE)){
if(player->getBalance() >= house->getRent()){
player->setBalance(player->getBalance() - house->getRent());
hasEnoughMoney = true;
}
}
else{
hasEnoughMoney = g_game.removeMoney(player, depot, house->getRent(), FLAG_IGNORECAPACITY);
}
}
if(hasEnoughMoney){
time_t paidUntil = time;
switch(rentPeriod){
case RENTPERIOD_DAILY:
paidUntil += 24 * 60 * 60;
break;
case RENTPERIOD_WEEKLY:
paidUntil += 24 * 60 * 60 * 7;
break;
case RENTPERIOD_MONTHLY:
paidUntil += 24 * 60 * 60 * 30;
break;
case RENTPERIOD_YEARLY:
paidUntil += 24 * 60 * 60 * 365;
break;
case RENTPERIOD_NEVER:
default:
break;
}
house->setPaidUntil(paidUntil);
}
return hasEnoughMoney;
}