| 1628 | } |
| 1629 | |
| 1630 | void TaskManager::SyncClientSharedTaskWithPersistedState(Client *c, ClientTaskState *cts) |
| 1631 | { |
| 1632 | auto character_tasks = CharacterTasksRepository::GetWhere( |
| 1633 | database, |
| 1634 | fmt::format("charid = {} ORDER BY acceptedtime", c->CharacterID()) |
| 1635 | ); |
| 1636 | |
| 1637 | for (auto &character_task: character_tasks) { |
| 1638 | if (character_task.type == TASK_TYPE_SHARED) { |
| 1639 | auto st = SharedTaskMembersRepository::GetWhere( |
| 1640 | database, |
| 1641 | fmt::format( |
| 1642 | "character_id = {}", |
| 1643 | c->CharacterID() |
| 1644 | ) |
| 1645 | ); |
| 1646 | |
| 1647 | if (!st.empty()) { |
| 1648 | int64 shared_task_id = st[0].shared_task_id; |
| 1649 | auto activities = SharedTaskActivityStateRepository::GetWhere( |
| 1650 | database, |
| 1651 | fmt::format( |
| 1652 | "shared_task_id = {}", |
| 1653 | shared_task_id |
| 1654 | ) |
| 1655 | ); |
| 1656 | |
| 1657 | ClientTaskInformation *shared_task = nullptr; |
| 1658 | shared_task = &cts->m_active_shared_task; |
| 1659 | |
| 1660 | // has active shared task |
| 1661 | if (cts->HasActiveSharedTask()) { |
| 1662 | |
| 1663 | LogTasksDetail( |
| 1664 | "[SyncClientSharedTaskWithPersistedState] Client [{}] has shared_task, sync with database", |
| 1665 | c->GetCleanName() |
| 1666 | ); |
| 1667 | |
| 1668 | bool fell_behind_state = false; |
| 1669 | for (auto &a: activities) { |
| 1670 | |
| 1671 | LogTasksDetail( |
| 1672 | "shared_task loop local [{}] shared [{}]", |
| 1673 | shared_task->activity[a.activity_id].done_count, |
| 1674 | a.done_count |
| 1675 | ); |
| 1676 | |
| 1677 | // we're behind shared task state, update self |
| 1678 | if (shared_task->activity[a.activity_id].done_count < a.done_count) { |
| 1679 | |
| 1680 | // update done count |
| 1681 | shared_task->activity[a.activity_id].done_count = a.done_count; |
| 1682 | |
| 1683 | // activity state |
| 1684 | shared_task->activity[a.activity_id].activity_state = |
| 1685 | (a.completed_time > 0 ? ActivityCompleted : ActivityHidden); |
| 1686 | |
| 1687 | // flag to update character_activities table entry on save |
nothing calls this directly
no test coverage detected