mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Fix repeated weapon story unlock notifications by sending only changed stories in diffs
This commit is contained in:
@@ -35,7 +35,7 @@ func (h *QuestHandler) HandleBigHuntQuestFinish(user *store.UserState, questId i
|
||||
|
||||
outcome := h.evaluateFinishOutcome(user, questId)
|
||||
if !isRetired {
|
||||
h.applyQuestVictory(user, questId, outcome, nowMillis)
|
||||
h.applyQuestVictory(user, questId, &outcome, nowMillis)
|
||||
}
|
||||
|
||||
if isRetired && !isAnnihilated && quest.Stamina > 1 {
|
||||
|
||||
@@ -44,7 +44,7 @@ func (h *QuestHandler) HandleEventQuestFinish(user *store.UserState, eventQuestC
|
||||
|
||||
outcome := h.evaluateFinishOutcome(user, questId)
|
||||
if !isRetired {
|
||||
h.applyQuestVictory(user, questId, outcome, nowMillis)
|
||||
h.applyQuestVictory(user, questId, &outcome, nowMillis)
|
||||
}
|
||||
|
||||
if isRetired && !isAnnihilated && quest.Stamina > 1 {
|
||||
|
||||
@@ -42,7 +42,7 @@ func (h *QuestHandler) HandleExtraQuestFinish(user *store.UserState, questId int
|
||||
|
||||
outcome := h.evaluateFinishOutcome(user, questId)
|
||||
if !isRetired {
|
||||
h.applyQuestVictory(user, questId, outcome, nowMillis)
|
||||
h.applyQuestVictory(user, questId, &outcome, nowMillis)
|
||||
}
|
||||
|
||||
if isRetired && !isAnnihilated && quest.Stamina > 1 {
|
||||
|
||||
@@ -20,6 +20,7 @@ type FinishOutcome struct {
|
||||
MissionClearCompleteRewards []RewardGrant
|
||||
BigWinClearedQuestMissionIds []int32
|
||||
IsBigWin bool
|
||||
ChangedWeaponStoryIds []int32
|
||||
}
|
||||
|
||||
type QuestHandler struct {
|
||||
|
||||
@@ -112,12 +112,14 @@ func (h *QuestHandler) handleQuestStartInternal(user *store.UserState, questId i
|
||||
user.Quests[questId] = questState
|
||||
}
|
||||
|
||||
func (h *QuestHandler) applyQuestVictory(user *store.UserState, questId int32, outcome FinishOutcome, nowMillis int64) {
|
||||
func (h *QuestHandler) applyQuestVictory(user *store.UserState, questId int32, outcome *FinishOutcome, nowMillis int64) {
|
||||
questState := user.Quests[questId]
|
||||
if !questState.IsRewardGranted {
|
||||
h.applyQuestRewards(user, questId, nowMillis)
|
||||
h.grantWeaponStoryUnlocksForQuestScene(user, questId, model.QuestResultTypeHalfResult, nowMillis)
|
||||
h.grantWeaponStoryUnlocksForQuestScene(user, questId, model.QuestResultTypeFullResult, nowMillis)
|
||||
outcome.ChangedWeaponStoryIds = append(outcome.ChangedWeaponStoryIds,
|
||||
h.grantWeaponStoryUnlocksForQuestScene(user, questId, model.QuestResultTypeHalfResult, nowMillis)...)
|
||||
outcome.ChangedWeaponStoryIds = append(outcome.ChangedWeaponStoryIds,
|
||||
h.grantWeaponStoryUnlocksForQuestScene(user, questId, model.QuestResultTypeFullResult, nowMillis)...)
|
||||
questState.IsRewardGranted = true
|
||||
}
|
||||
for _, drop := range outcome.DropRewards {
|
||||
@@ -141,7 +143,7 @@ func (h *QuestHandler) HandleQuestFinish(user *store.UserState, questId int32, i
|
||||
|
||||
outcome := h.evaluateFinishOutcome(user, questId)
|
||||
if !isRetired {
|
||||
h.applyQuestVictory(user, questId, outcome, nowMillis)
|
||||
h.applyQuestVictory(user, questId, &outcome, nowMillis)
|
||||
}
|
||||
|
||||
if isRetired && !isAnnihilated && quest.Stamina > 1 {
|
||||
|
||||
@@ -316,8 +316,8 @@ func (h *QuestHandler) grantParts(user *store.UserState, partsId int32, nowMilli
|
||||
}
|
||||
}
|
||||
|
||||
func (h *QuestHandler) grantWeaponStoryUnlock(user *store.UserState, weaponId, storyIndex int32, nowMillis int64) {
|
||||
store.GrantWeaponStoryUnlock(user, weaponId, storyIndex, nowMillis)
|
||||
func (h *QuestHandler) grantWeaponStoryUnlock(user *store.UserState, weaponId, storyIndex int32, nowMillis int64) bool {
|
||||
return store.GrantWeaponStoryUnlock(user, weaponId, storyIndex, nowMillis)
|
||||
}
|
||||
|
||||
var tutorialCompanionChoices = map[int32]int32{
|
||||
@@ -354,11 +354,12 @@ func (h *QuestHandler) BattleDropRewards(questId int32) []masterdata.BattleDropI
|
||||
return h.BattleDropsByQuestId[questId]
|
||||
}
|
||||
|
||||
func (h *QuestHandler) grantWeaponStoryUnlocksForQuestScene(user *store.UserState, questId int32, resultType model.QuestResultType, nowMillis int64) {
|
||||
func (h *QuestHandler) grantWeaponStoryUnlocksForQuestScene(user *store.UserState, questId int32, resultType model.QuestResultType, nowMillis int64) []int32 {
|
||||
var changedIds []int32
|
||||
if resultType == model.QuestResultTypeHalfResult {
|
||||
questDef, ok := h.QuestById[questId]
|
||||
if !ok {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
rewardGroupId := h.firstClearRewardGroupId(user, questDef)
|
||||
for _, reward := range h.FirstClearRewardsByGroupId[rewardGroupId] {
|
||||
@@ -373,22 +374,27 @@ func (h *QuestHandler) grantWeaponStoryUnlocksForQuestScene(user *store.UserStat
|
||||
groupId := weapon.WeaponStoryReleaseConditionGroupId
|
||||
for _, cond := range h.ReleaseConditionsByGroupId[groupId] {
|
||||
if cond.WeaponStoryReleaseConditionType == model.WeaponStoryReleaseConditionTypeAcquisition && cond.ConditionValue == 0 {
|
||||
h.grantWeaponStoryUnlock(user, weaponId, cond.StoryIndex, nowMillis)
|
||||
if h.grantWeaponStoryUnlock(user, weaponId, cond.StoryIndex, nowMillis) {
|
||||
changedIds = append(changedIds, weaponId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
return changedIds
|
||||
}
|
||||
if resultType == model.QuestResultTypeFullResult {
|
||||
for groupId, conditions := range h.ReleaseConditionsByGroupId {
|
||||
for _, cond := range conditions {
|
||||
if cond.WeaponStoryReleaseConditionType == model.WeaponStoryReleaseConditionTypeQuestClear && cond.ConditionValue == questId {
|
||||
for _, weaponId := range h.WeaponIdsByReleaseConditionGroupId[groupId] {
|
||||
h.grantWeaponStoryUnlock(user, weaponId, cond.StoryIndex, nowMillis)
|
||||
if h.grantWeaponStoryUnlock(user, weaponId, cond.StoryIndex, nowMillis) {
|
||||
changedIds = append(changedIds, weaponId)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return changedIds
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user