OnContainerChanged update
This commit is contained in:
parent
cd66ad1eac
commit
0c22f0b8bd
Binary file not shown.
Binary file not shown.
@ -177,7 +177,7 @@ namespace ArtifactTracker
|
|||||||
|
|
||||||
g_bHomeContainer = IsHome()
|
g_bHomeContainer = IsHome()
|
||||||
&& refr
|
&& refr
|
||||||
&& refr.get()->GetParentCell() == RE::PlayerCharacter::GetSingleton()->GetParentCell()
|
&& IsInSameCell(refr.get())
|
||||||
&& !g_persistentMap.contains(refr.get()->formID);
|
&& !g_persistentMap.contains(refr.get()->formID);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@ -408,10 +408,10 @@ namespace ArtifactTracker
|
|||||||
|
|
||||||
const auto ref = it->second;
|
const auto ref = it->second;
|
||||||
|
|
||||||
if (ref && GetItemCount(ref, form) - a_event->itemCount <= 0) { // no items left in the container
|
if (ref && GetItemCount(ref, form) <= 0) { // no items left in the container
|
||||||
for (const auto& persref : g_persistentMap) {
|
for (const auto& persref : g_persistentMap) {
|
||||||
if (persref.second != ref) {
|
if (persref.second != ref) {
|
||||||
if (GetItemCount(persref.second, form) > 0) {
|
if (GetItemCount(persref.second, form)) {
|
||||||
// if other containers have it, do nothing
|
// if other containers have it, do nothing
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -421,15 +421,19 @@ namespace ArtifactTracker
|
|||||||
g_listFound->AddForm(form);
|
g_listFound->AddForm(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (g_cellStorage && !g_bHomeContainer) { // taken from a container at home
|
return;
|
||||||
|
|
||||||
const auto container = RE::TESForm::LookupByID<RE::TESObjectREFR>(a_event->oldContainer);
|
} else if (g_cellStorage) { // taken from a container at home
|
||||||
if (container && GetItemCount(container, form) - a_event->itemCount <= 0) {
|
|
||||||
SyncCellStorage(container->formID);
|
if (!g_bHomeContainer) {
|
||||||
|
const auto container = RE::TESForm::LookupByID<RE::TESObjectREFR>(a_event->oldContainer);
|
||||||
|
if (container && !GetItemCount(container, form)) {
|
||||||
|
SyncCellStorage(container->formID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_listStored->HasForm(form) && !g_listFound->HasForm(form)) { // it's a new item, move it to found
|
if (!g_listStored->HasForm(form) && !g_listFound->HasForm(form)) { // it's a new item, move it to found
|
||||||
@ -460,7 +464,7 @@ namespace ArtifactTracker
|
|||||||
} else {
|
} else {
|
||||||
const auto container = ref->As<RE::TESObjectREFR>();
|
const auto container = ref->As<RE::TESObjectREFR>();
|
||||||
if (container) {
|
if (container) {
|
||||||
if (g_cellStorage && container->GetParentCell() == RE::PlayerCharacter::GetSingleton()->GetParentCell()) { // stored at home
|
if (g_cellStorage && IsInSameCell(container)) { // stored at home
|
||||||
|
|
||||||
if (!g_bHomeContainer && !g_listStored->HasForm(form)) {
|
if (!g_bHomeContainer && !g_listStored->HasForm(form)) {
|
||||||
ListRemoveItem(g_listFound, form);
|
ListRemoveItem(g_listFound, form);
|
||||||
@ -468,8 +472,7 @@ namespace ArtifactTracker
|
|||||||
g_listStored->AddForm(form);
|
g_listStored->AddForm(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
// During OnContainerChanged, InventoryChanges do not have the current change included yet
|
} else if (a_event->oldContainer == 0x14 && !g_listStored->HasForm(form) && !GetItemCount(RE::PlayerCharacter::GetSingleton(), form) && !FollowersHaveItem(form)) {
|
||||||
} else if (a_event->oldContainer == 0x14 && !g_listStored->HasForm(form) && (GetItemCount(RE::PlayerCharacter::GetSingleton(), form) - a_event->itemCount <= 0) && !FollowersHaveItem(form)) {
|
|
||||||
// disposed by player
|
// disposed by player
|
||||||
ListRemoveItem(g_listFound, form);
|
ListRemoveItem(g_listFound, form);
|
||||||
g_listNew->AddForm(form);
|
g_listNew->AddForm(form);
|
||||||
@ -482,7 +485,14 @@ namespace ArtifactTracker
|
|||||||
|
|
||||||
if (g_cellStorage && a_event->reference) { // dropped or placed on rack at home by any actor
|
if (g_cellStorage && a_event->reference) { // dropped or placed on rack at home by any actor
|
||||||
|
|
||||||
if (GetItemCount(g_cellStorage, form) <= 0) {
|
if (a_event->oldContainer != 0x14) {
|
||||||
|
const auto ref = RE::TESForm::LookupByID<RE::TESObjectREFR>(a_event->oldContainer);
|
||||||
|
if (!ref || !IsInSameCell(ref)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GetItemCount(g_cellStorage, form)) {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
SKSE::log::info("Added dropped {} to cell storage", form->GetName());
|
SKSE::log::info("Added dropped {} to cell storage", form->GetName());
|
||||||
RE::DebugNotification("Adding to cell storage");
|
RE::DebugNotification("Adding to cell storage");
|
||||||
@ -496,14 +506,12 @@ namespace ArtifactTracker
|
|||||||
g_listStored->AddForm(form);
|
g_listStored->AddForm(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (a_event->oldContainer == 0x14) { // dropped, dismantled, consumed, removed by a script
|
} else if (a_event->oldContainer == 0x14) { // dropped, consumed, dismantle, removed by script
|
||||||
|
|
||||||
if (!g_listStored->HasForm(form)) {
|
if (!g_listStored->HasForm(form)) {
|
||||||
if ((GetItemCount(RE::PlayerCharacter::GetSingleton(), form) - a_event->itemCount <= 0) && !FollowersHaveItem(form)) {
|
if (!GetItemCount(RE::PlayerCharacter::GetSingleton(), form) && !FollowersHaveItem(form)) {
|
||||||
if (g_listFound->HasForm(form)) {
|
ListRemoveItem(g_listFound, form);
|
||||||
ListRemoveItem(g_listFound, form);
|
g_listNew->AddForm(form);
|
||||||
g_listNew->AddForm(form);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (!g_listFound->HasForm(form)) {
|
} else if (!g_listFound->HasForm(form)) {
|
||||||
ListRemoveItem(g_listNew, form);
|
ListRemoveItem(g_listNew, form);
|
||||||
@ -518,10 +526,10 @@ namespace ArtifactTracker
|
|||||||
|
|
||||||
const auto ref = it->second;
|
const auto ref = it->second;
|
||||||
|
|
||||||
if (ref && GetItemCount(ref, form) - a_event->itemCount <= 0) { // no items left in the container
|
if (ref && !GetItemCount(ref, form)) { // no items left in the container
|
||||||
for (const auto& persref : g_persistentMap) {
|
for (const auto& persref : g_persistentMap) {
|
||||||
if (persref.second != ref) {
|
if (persref.second != ref) {
|
||||||
if (GetItemCount(persref.second, form) > 0) {
|
if (GetItemCount(persref.second, form)) {
|
||||||
// if other containers have it, do nothing
|
// if other containers have it, do nothing
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -539,15 +547,15 @@ namespace ArtifactTracker
|
|||||||
const auto ref = RE::TESForm::LookupByID(a_event->oldContainer);
|
const auto ref = RE::TESForm::LookupByID(a_event->oldContainer);
|
||||||
|
|
||||||
if (ref->Is(RE::FormType::ActorCharacter)) {
|
if (ref->Is(RE::FormType::ActorCharacter)) {
|
||||||
if (ref->As<RE::Actor>()->IsPlayerTeammate() && GetItemCount(ref->As<RE::TESObjectREFR>(), form) - a_event->itemCount <= 0) { // removed from companion (probably, disarmed)
|
if (ref->As<RE::Actor>()->IsPlayerTeammate() && GetItemCount(ref->As<RE::TESObjectREFR>(), form) <= 0) { // removed from companion (probably, disarmed)
|
||||||
if (!g_listStored->HasForm(form) && g_listFound->HasForm(form)) {
|
if (!g_listStored->HasForm(form) && g_listFound->HasForm(form)) {
|
||||||
|
|
||||||
if (GetItemCount(RE::PlayerCharacter::GetSingleton(), form) <= 0) {
|
if (!GetItemCount(RE::PlayerCharacter::GetSingleton(), form)) {
|
||||||
// player does not have it, check companions
|
// player does not have it, check companions
|
||||||
if (const auto processLists = RE::ProcessLists::GetSingleton(); processLists) {
|
if (const auto processLists = RE::ProcessLists::GetSingleton(); processLists) {
|
||||||
for (auto& actorHandle : processLists->highActorHandles) {
|
for (auto& actorHandle : processLists->highActorHandles) {
|
||||||
if (auto actor = actorHandle.get(); actor && actor->IsPlayerTeammate() && actor->formID != ref->formID) {
|
if (auto actor = actorHandle.get(); actor && actor->IsPlayerTeammate() && actor->formID != ref->formID) {
|
||||||
if (GetItemCount(actor.get(), form) > 0) {
|
if (GetItemCount(actor.get(), form)) {
|
||||||
// other companion has it, do nothing
|
// other companion has it, do nothing
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -564,9 +572,9 @@ namespace ArtifactTracker
|
|||||||
} else {
|
} else {
|
||||||
const auto container = ref->As<RE::TESObjectREFR>();
|
const auto container = ref->As<RE::TESObjectREFR>();
|
||||||
if (container) {
|
if (container) {
|
||||||
if (g_cellStorage && container->GetParentCell() == RE::PlayerCharacter::GetSingleton()->GetParentCell()) { // deleted from container at home
|
if (g_cellStorage && IsInSameCell(container)) { // deleted from container at home
|
||||||
|
|
||||||
if (GetItemCount(container, form) - a_event->itemCount <= 0) {
|
if (!GetItemCount(container, form)) {
|
||||||
SyncCellStorage(container->formID);
|
SyncCellStorage(container->formID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ inline void ListRevert(RE::BGSListForm* a_form)
|
|||||||
return func(a_form);
|
return func(a_form);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::int32_t GetItemCount(RE::TESObjectREFR* a_container, RE::TESForm* a_form)
|
inline std::uint32_t GetItemCount(RE::TESObjectREFR* a_container, RE::TESForm* a_form)
|
||||||
{
|
{
|
||||||
std::int32_t iResult = 0;
|
std::int32_t iResult = 0;
|
||||||
|
|
||||||
@ -124,3 +124,8 @@ inline bool FollowersHaveItem(RE::TESForm* a_form)
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool IsInSameCell(RE::TESObjectREFR* ref)
|
||||||
|
{
|
||||||
|
return ref && (ref->GetParentCell() == RE::PlayerCharacter::GetSingleton()->GetParentCell());
|
||||||
|
}
|
||||||
|
@ -15,6 +15,7 @@ int iArtifactCount = 0
|
|||||||
|
|
||||||
|
|
||||||
event OnInit()
|
event OnInit()
|
||||||
|
Utility.wait(3.0) ; wait for quickstart scripts to finish
|
||||||
OnPlayerLoadGame()
|
OnPlayerLoadGame()
|
||||||
endevent
|
endevent
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user