aboutsummaryrefslogtreecommitdiff
path: root/src/game/Item.cpp
diff options
context:
space:
mode:
authorMachiavelli <none@none>2010-03-20 16:26:16 +0100
committerMachiavelli <none@none>2010-03-20 16:26:16 +0100
commita0d8b0be48ea0419d6014d0a54256f4ef278c860 (patch)
tree0b1b6cfcab127fc6967f13b1576a8963bb1c07ed /src/game/Item.cpp
parent10417f1e6db974ff6e46a88b06147e87820ba850 (diff)
Item system update
- Set ITEM_FIELD_CREATE_PLAYED_TIME to 0 in Item::Create, should fix crash described in issue 1199 - Change some function calls so on Player::_saveInventory the core doesn't have to check for existance of item anymore when iterating over m_refundableItems. The loop will now only update played time, removal of items from this set is done in other functions. - Cleanup in affected functions. --HG-- branch : trunk
Diffstat (limited to 'src/game/Item.cpp')
-rw-r--r--src/game/Item.cpp66
1 files changed, 44 insertions, 22 deletions
diff --git a/src/game/Item.cpp b/src/game/Item.cpp
index 217013e8e22..639ec842342 100644
--- a/src/game/Item.cpp
+++ b/src/game/Item.cpp
@@ -248,7 +248,10 @@ Item::Item( )
m_lootGenerated = false;
mb_in_trade = false;
m_lastPlayedTimeUpdate = time(NULL);
- m_RefundData = NULL;
+
+ m_refundRecipient = 0;
+ m_paidMoney = 0;
+ m_paidExtendedCost = 0;
}
bool Item::Create( uint32 guidlow, uint32 itemid, Player const* owner)
@@ -274,6 +277,8 @@ bool Item::Create( uint32 guidlow, uint32 itemid, Player const* owner)
SetUInt32Value(ITEM_FIELD_FLAGS, itemProto->Flags);
SetUInt32Value(ITEM_FIELD_DURATION, abs(itemProto->Duration));
+
+ SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, 0);
return true;
}
@@ -330,8 +335,6 @@ void Item::SaveToDB()
CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid = '%u'", guid);
if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED))
CharacterDatabase.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", GetGUIDLow());
- if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE))
- DeleteRefundDataFromDB();
delete this;
return;
}
@@ -1050,16 +1053,12 @@ void Item::BuildUpdate(UpdateDataMapType& data_map)
void Item::SaveRefundDataToDB()
{
- ItemRefund* RefundData = GetRefundData();
- if (!RefundData)
- return;
-
std::ostringstream ss;
ss << "INSERT INTO item_refund_instance VALUES(";
ss << GetGUIDLow() << ",";
- ss << RefundData->eligibleFor << ",";
- ss << RefundData->paidMoney << ",";
- ss << RefundData->paidExtendedCost;
+ ss << GetRefundRecipient() << ",";
+ ss << GetPaidMoney() << ",";
+ ss << GetPaidExtendedCost();
ss << ")";
CharacterDatabase.Execute(ss.str().c_str());
@@ -1075,30 +1074,53 @@ void Item::SetNotRefundable(Player *owner)
if (!HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE))
return;
- if (m_RefundData)
- delete m_RefundData;
-
RemoveFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_REFUNDABLE);
SetState(ITEM_CHANGED, owner);
- DeleteRefundDataFromDB();
+
+ SetRefundRecipient(0);
+ SetPaidMoney(0);
+ SetPaidExtendedCost(0);
+ DeleteRefundDataFromDB();
+
owner->DeleteRefundReference(this);
}
void Item::UpdatePlayedTime(Player *owner)
{
+ /* Here we update our played time
+ We simply add a number to the current played time,
+ based on the time elapsed since the last update hereof.
+ */
+ // Get current played time
+ uint32 current_playtime = GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME);
+ // Calculate time elapsed since last played time update
time_t curtime = time(NULL);
uint32 elapsed = curtime - m_lastPlayedTimeUpdate;
- SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, GetPlayedTime(true) + elapsed);
- SetState(ITEM_CHANGED, owner);
- m_lastPlayedTimeUpdate = curtime;
+ uint32 new_playtime = current_playtime + elapsed;
+ // Check if the refund timer has expired yet
+ if (new_playtime <= 2*HOUR)
+ {
+ // No? Proceed.
+ // Update the data field
+ SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, new_playtime);
+ // Flag as changed to get saved to DB
+ SetState(ITEM_CHANGED, owner);
+ // Speaks for itself
+ m_lastPlayedTimeUpdate = curtime;
+ return;
+ }
+ // Yes
+ SetNotRefundable(owner);
}
-uint32 Item::GetPlayedTime(bool raw)
+uint32 Item::GetPlayedTime()
{
- if (raw)
- return GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME);
-
time_t curtime = time(NULL);
uint32 elapsed = curtime - m_lastPlayedTimeUpdate;
- return uint32(GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME) + elapsed);
+ return GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME) + elapsed;
+}
+
+bool Item::IsRefundExpired()
+{
+ return (GetPlayedTime() > 2*HOUR);
} \ No newline at end of file