Merge remote-tracking branch 'jeffreyhaines/master'

actorid
Marc Zinnschlag 11 years ago
commit 50f1679a4c

@ -123,8 +123,13 @@ namespace MWClass
else
data->mContainerStore = new MWWorld::ContainerStore();
// Relates to NPC gold reset delay
data->mCreatureStats.setTradeTime(MWWorld::TimeStamp(0.0, 0));
data->mCreatureStats.setGoldPool(ref->mBase->mData.mGold);
// store
ptr.getRefData().setCustomData (data.release());
ptr.getRefData().setCustomData(data.release());
getContainerStore(ptr).fill(ref->mBase->mInventory, getId(ptr), "",
MWBase::Environment::get().getWorld()->getStore());
@ -134,7 +139,7 @@ namespace MWClass
getContainerStore(ptr).add(MWWorld::ContainerStore::sGoldId, ref->mBase->mData.mGold, ptr);
if (ref->mBase->mFlags & ESM::Creature::Weapon)
getInventoryStore(ptr).autoEquip(ptr);
getInventoryStore(ptr).autoEquip(ptr);
}
}

@ -357,6 +357,11 @@ namespace MWClass
data->mInventoryStore.fill(ref->mBase->mInventory, getId(ptr), "",
MWBase::Environment::get().getWorld()->getStore());
// Relates to NPC gold reset delay
data->mNpcStats.setTradeTime(MWWorld::TimeStamp(0.0, 0));
data->mNpcStats.setGoldPool(gold);
// store
ptr.getRefData().setCustomData (data.release());
@ -365,6 +370,8 @@ namespace MWClass
getContainerStore(ptr).add(MWWorld::ContainerStore::sGoldId, gold, ptr);
getInventoryStore(ptr).autoEquip(ptr);
}
}

@ -84,8 +84,11 @@ namespace MWGui
mCurrentBalance = 0;
mCurrentMerchantOffer = 0;
checkTradeTime();
std::vector<MWWorld::Ptr> itemSources;
MWBase::Environment::get().getWorld()->getContainersOwnedBy(actor, itemSources);
// Important: actor goes last, so that items purchased by the merchant go into his inventory
itemSources.push_back(actor);
std::vector<MWWorld::Ptr> worldItems;
@ -360,6 +363,8 @@ namespace MWGui
addOrRemoveGold(-mCurrentBalance, mPtr);
}
updateTradeTime();
MWBase::Environment::get().getWindowManager()->getDialogueWindow()->addResponse(
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sBarterDialog5")->getString());
@ -474,4 +479,33 @@ namespace MWGui
}
return merchantGold;
}
// Relates to NPC gold reset delay
void TradeWindow::checkTradeTime()
{
MWWorld::ContainerStore store = mPtr.getClass().getContainerStore(mPtr);
const MWMechanics::CreatureStats &sellerStats = mPtr.getClass().getCreatureStats(mPtr);
double delay = boost::lexical_cast<double>(MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fBarterGoldResetDelay")->getInt());
// if time stamp longer than gold reset delay, reset gold.
if (MWBase::Environment::get().getWorld()->getTimeStamp() >= sellerStats.getTradeTime() + delay)
{
addOrRemoveGold(-store.count(MWWorld::ContainerStore::sGoldId), mPtr);
addOrRemoveGold(+sellerStats.getGoldPool(), mPtr);
}
}
void TradeWindow::updateTradeTime()
{
MWWorld::ContainerStore store = mPtr.getClass().getContainerStore(mPtr);
MWMechanics::CreatureStats &sellerStats = mPtr.getClass().getCreatureStats(mPtr);
double delay = boost::lexical_cast<double>(MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fBarterGoldResetDelay")->getInt());
// If trade timestamp is within reset delay don't set
if ( ! (MWBase::Environment::get().getWorld()->getTimeStamp() >= sellerStats.getTradeTime() &&
MWBase::Environment::get().getWorld()->getTimeStamp() < sellerStats.getTradeTime() + delay) )
{
sellerStats.setTradeTime(MWBase::Environment::get().getWorld()->getTimeStamp());
}
}
}

@ -100,6 +100,10 @@ namespace MWGui
virtual void onReferenceUnavailable();
int getMerchantGold();
// Relates to NPC gold reset delay
void checkTradeTime();
void updateTradeTime();
};
}

@ -476,4 +476,24 @@ namespace MWMechanics
for (int i=0; i<3; ++i)
mDynamic[i].readState (state.mDynamic[i]);
}
// Relates to NPC gold reset delay
void CreatureStats::setTradeTime(MWWorld::TimeStamp tradeTime)
{
mTradeTime = tradeTime;
}
MWWorld::TimeStamp CreatureStats::getTradeTime() const
{
return mTradeTime;
}
void CreatureStats::setGoldPool(int pool)
{
mGoldPool = pool;
}
int CreatureStats::getGoldPool() const
{
return mGoldPool;
}
}

@ -54,6 +54,11 @@ namespace MWMechanics
bool mRecalcDynamicStats;
std::map<std::string, MWWorld::TimeStamp> mUsedPowers;
MWWorld::TimeStamp mTradeTime; // Relates to NPC gold reset delay
int mGoldPool; // the pool of merchant gold not in inventory
protected:
bool mIsWerewolf;
AttributeValue mWerewolfAttributes[8];
@ -221,6 +226,13 @@ namespace MWMechanics
void writeState (ESM::CreatureStats& state) const;
void readState (const ESM::CreatureStats& state);
// Relates to NPC gold reset delay
void setTradeTime(MWWorld::TimeStamp tradeTime);
MWWorld::TimeStamp getTradeTime() const;
void setGoldPool(int pool);
int getGoldPool() const;
};
}

Loading…
Cancel
Save