[9636] Move item real-time/in-game duration counting flag to new extraflags field.

Client expected only positive duration values, so stop use duration field as signed.
This commit is contained in:
VladimirMangos 2010-03-29 09:48:38 +04:00
parent 8e25d43443
commit d7c1e06d1b
11 changed files with 62 additions and 29 deletions

View file

@ -24,7 +24,7 @@ CREATE TABLE `db_version` (
`version` varchar(120) default NULL,
`creature_ai_version` varchar(120) default NULL,
`cache_id` int(10) default '0',
`required_9622_01_mangos_gameobject` bit(1) default NULL
`required_9636_01_mangos_item_template` bit(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes';
--
@ -2252,7 +2252,7 @@ CREATE TABLE `item_template` (
`GemProperties` mediumint(9) NOT NULL default '0',
`RequiredDisenchantSkill` smallint(6) NOT NULL default '-1',
`ArmorDamageModifier` float NOT NULL default '0',
`Duration` int(11) NOT NULL default '0' COMMENT 'Duration in seconds. Negative value means realtime, postive value ingame time',
`Duration` int(11) UNSIGNED DEFAULT '0' NOT NULL COMMENT 'Duration in seconds.',
`ItemLimitCategory` smallint(6) NOT NULL default '0',
`HolidayId` int(11) UNSIGNED DEFAULT '0' NOT NULL,
`ScriptName` varchar(64) NOT NULL default '',

View file

@ -0,0 +1,14 @@
ALTER TABLE db_version CHANGE COLUMN required_9622_01_mangos_gameobject required_9636_01_mangos_item_template bit;
ALTER TABLE item_template
CHANGE COLUMN NonConsumable ExtraFlags tinyint(1) UNSIGNED DEFAULT '0' NOT NULL;
UPDATE item_template
SET ExtraFlags = ExtraFlags | 0x2 WHERE Duration < 0 ;
UPDATE item_template
SET Duration = abs(Duration);
ALTER TABLE item_template
CHANGE COLUMN Duration Duration int(11) UNSIGNED DEFAULT '0' NOT NULL;

View file

@ -95,6 +95,7 @@ pkgdata_DATA = \
9632_01_characters_characters.sql \
9634_01_characters_corpse.sql \
9635_01_characters_characters.sql \
9636_01_mangos_item_template.sql \
README
## Additional files to include when running 'make dist'
@ -170,4 +171,5 @@ EXTRA_DIST = \
9632_01_characters_characters.sql \
9634_01_characters_corpse.sql \
9635_01_characters_characters.sql \
9636_01_mangos_item_template.sql \
README

View file

@ -268,7 +268,7 @@ bool Item::Create( uint32 guidlow, uint32 itemid, Player const* owner)
SetSpellCharges(i,itemProto->Spells[i].SpellCharges);
SetUInt32Value(ITEM_FIELD_FLAGS, itemProto->Flags);
SetUInt32Value(ITEM_FIELD_DURATION, abs(itemProto->Duration));
SetUInt32Value(ITEM_FIELD_DURATION, itemProto->Duration);
return true;
}
@ -403,20 +403,20 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result)
}
// update duration if need, and remove if not need
if((proto->Duration==0) != (GetUInt32Value(ITEM_FIELD_DURATION)==0))
if ((proto->Duration == 0) != (GetUInt32Value(ITEM_FIELD_DURATION) == 0))
{
SetUInt32Value(ITEM_FIELD_DURATION,abs(proto->Duration));
SetUInt32Value(ITEM_FIELD_DURATION, proto->Duration);
need_save = true;
}
// set correct owner
if(owner_guid != 0 && GetOwnerGUID() != owner_guid)
if (owner_guid != 0 && GetOwnerGUID() != owner_guid)
{
SetOwnerGUID(owner_guid);
need_save = true;
}
if(need_save) // normal item changed state set not work at loading
if (need_save) // normal item changed state set not work at loading
{
std::ostringstream ss;
ss << "UPDATE item_instance SET data = '";

View file

@ -418,7 +418,7 @@ void WorldSession::HandleItemQuerySingleOpcode( WorldPacket & recv_data )
data << pProto->GemProperties;
data << pProto->RequiredDisenchantSkill;
data << pProto->ArmorDamageModifier;
data << abs(pProto->Duration); // added in 2.4.2.8209, duration (seconds)
data << pProto->Duration; // added in 2.4.2.8209, duration (seconds)
data << pProto->ItemLimitCategory; // WotLK, ItemLimitCategory
data << pProto->HolidayId; // Holiday.dbc?
SendPacket( &data );

View file

@ -469,6 +469,14 @@ inline uint8 ItemSubClassToDurabilityMultiplierId(uint32 ItemClass, uint32 ItemS
return 0;
}
enum ItemExtraFlags
{
ITEM_EXTRA_NON_CONSUMABLE = 0x01, // use as additional flag to spellcharges_N negative values, item not expire at no chanrges
ITEM_EXTRA_REAL_TIME_DURATION = 0x02, // if set and have Duration time, then offline time included in counting, if not set then counted only in game time
ITEM_EXTRA_ALL // all used flags, used for check DB data
};
// GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push,N), also any gcc version not support it at some platform
#if defined( __GNUC__ )
#pragma pack(1)
@ -578,7 +586,7 @@ struct ItemPrototype
uint32 GemProperties; // id from GemProperties.dbc
uint32 RequiredDisenchantSkill;
float ArmorDamageModifier;
int32 Duration; // negative = realtime, positive = ingame time
uint32 Duration; // negative = realtime, positive = ingame time
uint32 ItemLimitCategory; // id from ItemLimitCategory.dbc
uint32 HolidayId; // id from Holidays.dbc
uint32 ScriptId;
@ -586,7 +594,7 @@ struct ItemPrototype
uint32 FoodType;
uint32 MinMoneyLoot;
uint32 MaxMoneyLoot;
uint32 NonConsumable;
uint32 ExtraFlags; // see ItemExtraFlags
// helpers
bool CanChangeEquipStateInCombat() const

View file

@ -2072,14 +2072,13 @@ void ObjectMgr::LoadItemPrototypes()
const_cast<ItemPrototype*>(proto)->HolidayId = 0;
}
if(proto->NonConsumable)
if(proto->ExtraFlags)
{
if (proto->NonConsumable > 1)
{
sLog.outErrorDb("Item (Entry: %u) has wrong NonConsumable (%u), must be 0..1",i,proto->NonConsumable);
const_cast<ItemPrototype*>(proto)->NonConsumable = 1;
}
if (proto->ExtraFlags & ~ITEM_EXTRA_ALL)
sLog.outErrorDb("Item (Entry: %u) has wrong ExtraFlags (%u) with unused bits set",i,proto->ExtraFlags);
if (proto->ExtraFlags & ITEM_EXTRA_NON_CONSUMABLE)
{
bool can_be_need = false;
for (int j = 0; j < MAX_ITEM_PROTO_SPELLS; ++j)
{
@ -2092,8 +2091,18 @@ void ObjectMgr::LoadItemPrototypes()
if (!can_be_need)
{
sLog.outErrorDb("Item (Entry: %u) has redundant NonConsumable (%u), item not have negative charges",i,proto->NonConsumable);
const_cast<ItemPrototype*>(proto)->NonConsumable = 0;
sLog.outErrorDb("Item (Entry: %u) has redundant non-consumable flag in ExtraFlags, item not have negative charges", i);
const_cast<ItemPrototype*>(proto)->ExtraFlags &= ~ITEM_EXTRA_NON_CONSUMABLE;
}
}
if (proto->ExtraFlags & ITEM_EXTRA_REAL_TIME_DURATION)
{
if (proto->Duration == 0)
{
sLog.outErrorDb("Item (Entry: %u) has redundant real-time duration flag in ExtraFlags, item not have duration", i);
const_cast<ItemPrototype*>(proto)->ExtraFlags &= ~ITEM_EXTRA_REAL_TIME_DURATION;
}
}
}
}

View file

@ -11863,7 +11863,7 @@ void Player::UpdateItemDuration(uint32 time, bool realtimeonly)
Item* item = *itr;
++itr; // current element can be erased in UpdateDuration
if ((realtimeonly && item->GetProto()->Duration < 0) || !realtimeonly)
if ((realtimeonly && (item->GetProto()->ExtraFlags & ITEM_EXTRA_REAL_TIME_DURATION)) || !realtimeonly)
item->UpdateDuration(this,time);
}
}

View file

@ -3650,7 +3650,7 @@ void Spell::TakeCastItem()
// item has limited charges
if (proto->Spells[i].SpellCharges)
{
if (proto->Spells[i].SpellCharges < 0 && !proto->NonConsumable)
if (proto->Spells[i].SpellCharges < 0 && !(proto->ExtraFlags & ITEM_EXTRA_NON_CONSUMABLE))
expendable = true;
int32 charges = m_CastItem->GetSpellCharges(i);
@ -5557,7 +5557,7 @@ SpellCastResult Spell::CheckItems()
{
// CastItem will be used up and does not count as reagent
int32 charges = m_CastItem->GetSpellCharges(s);
if (proto->Spells[s].SpellCharges < 0 && !proto->NonConsumable && abs(charges) < 2)
if (proto->Spells[s].SpellCharges < 0 && !(proto->ExtraFlags & ITEM_EXTRA_NON_CONSUMABLE) && abs(charges) < 2)
{
++itemcount;
break;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9635"
#define REVISION_NR "9636"
#endif // __REVISION_NR_H__

View file

@ -1,6 +1,6 @@
#ifndef __REVISION_SQL_H__
#define __REVISION_SQL_H__
#define REVISION_DB_CHARACTERS "required_9635_01_characters_characters"
#define REVISION_DB_MANGOS "required_9622_01_mangos_gameobject"
#define REVISION_DB_MANGOS "required_9636_01_mangos_item_template"
#define REVISION_DB_REALMD "required_9010_01_realmd_realmlist"
#endif // __REVISION_SQL_H__