mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Support granting companions and parts from the shop
This commit is contained in:
@@ -59,11 +59,20 @@ func BuildGranter(catalog *masterdata.QuestCatalog) *store.PossessionGranter {
|
||||
}
|
||||
releaseConditions[groupId] = conds
|
||||
}
|
||||
partsById := make(map[int32]store.PartsRef, len(catalog.PartsById))
|
||||
for id, p := range catalog.PartsById {
|
||||
partsById[id] = store.PartsRef{
|
||||
PartsGroupId: p.PartsGroupId,
|
||||
PartsStatusMainLotteryGroupId: p.PartsStatusMainLotteryGroupId,
|
||||
}
|
||||
}
|
||||
return &store.PossessionGranter{
|
||||
CostumeById: costumeById,
|
||||
WeaponById: weaponById,
|
||||
WeaponSkillSlots: catalog.WeaponSkillSlots,
|
||||
WeaponAbilitySlots: catalog.WeaponAbilitySlots,
|
||||
ReleaseConditions: releaseConditions,
|
||||
PartsById: partsById,
|
||||
DefaultPartsStatusMainByLotteryGroup: catalog.DefaultPartsStatusMainByLotteryGroup,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lunar-tear/server/internal/gameutil"
|
||||
"lunar-tear/server/internal/masterdata"
|
||||
"lunar-tear/server/internal/model"
|
||||
@@ -262,55 +260,8 @@ func (h *QuestHandler) applyQuestRewards(user *store.UserState, questId int32, n
|
||||
}
|
||||
|
||||
func (h *QuestHandler) applyRewardPossession(user *store.UserState, possType model.PossessionType, possId, count int32, nowMillis int64) {
|
||||
switch possType {
|
||||
case model.PossessionTypeCompanion:
|
||||
h.grantCompanion(user, possId, nowMillis)
|
||||
case model.PossessionTypeParts:
|
||||
h.grantParts(user, possId, nowMillis)
|
||||
default:
|
||||
h.Granter.GrantFull(user, possType, possId, count, nowMillis)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *QuestHandler) grantCompanion(user *store.UserState, companionId int32, nowMillis int64) {
|
||||
for _, row := range user.Companions {
|
||||
if row.CompanionId == companionId {
|
||||
return
|
||||
}
|
||||
}
|
||||
key := uuid.New().String()
|
||||
user.Companions[key] = store.CompanionState{
|
||||
UserCompanionUuid: key,
|
||||
CompanionId: companionId,
|
||||
Level: 1,
|
||||
HeadupDisplayViewId: 1,
|
||||
AcquisitionDatetime: nowMillis,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *QuestHandler) grantParts(user *store.UserState, partsId int32, nowMillis int64) {
|
||||
var mainStatId int32
|
||||
if partsDef, ok := h.PartsById[partsId]; ok {
|
||||
mainStatId = h.DefaultPartsStatusMainByLotteryGroup[partsDef.PartsStatusMainLotteryGroupId]
|
||||
|
||||
if _, exists := user.PartsGroupNotes[partsDef.PartsGroupId]; !exists {
|
||||
user.PartsGroupNotes[partsDef.PartsGroupId] = store.PartsGroupNoteState{
|
||||
PartsGroupId: partsDef.PartsGroupId,
|
||||
FirstAcquisitionDatetime: nowMillis,
|
||||
LatestVersion: nowMillis,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
key := uuid.New().String()
|
||||
user.Parts[key] = store.PartsState{
|
||||
UserPartsUuid: key,
|
||||
PartsId: partsId,
|
||||
Level: 1,
|
||||
PartsStatusMainId: mainStatId,
|
||||
AcquisitionDatetime: nowMillis,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *QuestHandler) grantWeaponStoryUnlock(user *store.UserState, weaponId, storyIndex int32, nowMillis int64) bool {
|
||||
return store.GrantWeaponStoryUnlock(user, weaponId, storyIndex, nowMillis)
|
||||
@@ -338,7 +289,7 @@ func (h *QuestHandler) applyCompanionTutorialReward(user *store.UserState, choic
|
||||
log.Printf("[QuestHandler] unknown companion tutorial choiceId=%d", choiceId)
|
||||
return nil
|
||||
}
|
||||
h.grantCompanion(user, companionId, nowMillis)
|
||||
h.Granter.GrantCompanion(user, companionId, nowMillis)
|
||||
return []RewardGrant{{
|
||||
PossessionType: model.PossessionTypeCompanion,
|
||||
PossessionId: companionId,
|
||||
|
||||
@@ -100,6 +100,11 @@ type WeaponStoryReleaseCond struct {
|
||||
ConditionValue int32
|
||||
}
|
||||
|
||||
type PartsRef struct {
|
||||
PartsGroupId int32
|
||||
PartsStatusMainLotteryGroupId int32
|
||||
}
|
||||
|
||||
type PossessionGranter struct {
|
||||
CostumeById map[int32]CostumeRef
|
||||
WeaponById map[int32]WeaponRef
|
||||
@@ -107,6 +112,9 @@ type PossessionGranter struct {
|
||||
WeaponAbilitySlots map[int32][]int32
|
||||
ReleaseConditions map[int32][]WeaponStoryReleaseCond
|
||||
|
||||
PartsById map[int32]PartsRef
|
||||
DefaultPartsStatusMainByLotteryGroup map[int32]int32
|
||||
|
||||
LastChangedStoryWeaponIds []int32
|
||||
}
|
||||
|
||||
@@ -122,6 +130,10 @@ func (g *PossessionGranter) GrantFull(user *UserState, possessionType model.Poss
|
||||
g.GrantCostume(user, possessionId, nowMillis)
|
||||
case model.PossessionTypeWeapon, model.PossessionTypeWeaponEnhanced:
|
||||
g.GrantWeapon(user, possessionId, nowMillis)
|
||||
case model.PossessionTypeCompanion, model.PossessionTypeCompanionEnhanced:
|
||||
g.GrantCompanion(user, possessionId, nowMillis)
|
||||
case model.PossessionTypeParts, model.PossessionTypePartsEnhanced:
|
||||
g.GrantParts(user, possessionId, nowMillis)
|
||||
default:
|
||||
GrantPossession(user, possessionType, possessionId, count)
|
||||
}
|
||||
@@ -156,6 +168,44 @@ func (g *PossessionGranter) GrantCostume(user *UserState, costumeId int32, nowMi
|
||||
}
|
||||
}
|
||||
|
||||
func (g *PossessionGranter) GrantCompanion(user *UserState, companionId int32, nowMillis int64) {
|
||||
for _, row := range user.Companions {
|
||||
if row.CompanionId == companionId {
|
||||
return
|
||||
}
|
||||
}
|
||||
key := uuid.New().String()
|
||||
user.Companions[key] = CompanionState{
|
||||
UserCompanionUuid: key,
|
||||
CompanionId: companionId,
|
||||
Level: 1,
|
||||
HeadupDisplayViewId: 1,
|
||||
AcquisitionDatetime: nowMillis,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *PossessionGranter) GrantParts(user *UserState, partsId int32, nowMillis int64) {
|
||||
var mainStatId int32
|
||||
if ref, ok := g.PartsById[partsId]; ok {
|
||||
mainStatId = g.DefaultPartsStatusMainByLotteryGroup[ref.PartsStatusMainLotteryGroupId]
|
||||
if _, exists := user.PartsGroupNotes[ref.PartsGroupId]; !exists {
|
||||
user.PartsGroupNotes[ref.PartsGroupId] = PartsGroupNoteState{
|
||||
PartsGroupId: ref.PartsGroupId,
|
||||
FirstAcquisitionDatetime: nowMillis,
|
||||
LatestVersion: nowMillis,
|
||||
}
|
||||
}
|
||||
}
|
||||
key := uuid.New().String()
|
||||
user.Parts[key] = PartsState{
|
||||
UserPartsUuid: key,
|
||||
PartsId: partsId,
|
||||
Level: 1,
|
||||
PartsStatusMainId: mainStatId,
|
||||
AcquisitionDatetime: nowMillis,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *PossessionGranter) GrantWeapon(user *UserState, weaponId int32, nowMillis int64) {
|
||||
key := uuid.New().String()
|
||||
user.Weapons[key] = WeaponState{
|
||||
|
||||
Reference in New Issue
Block a user