2023-10-31 22:40:14 +00:00
|
|
|
package person
|
|
|
|
|
|
|
|
import (
|
2023-11-02 17:50:52 +00:00
|
|
|
"github.com/ectrc/snow/aid"
|
2023-10-31 22:40:14 +00:00
|
|
|
"github.com/ectrc/snow/storage"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Quest struct {
|
|
|
|
ID string
|
|
|
|
TemplateID string
|
2023-11-02 17:50:52 +00:00
|
|
|
State string
|
2023-10-31 22:40:14 +00:00
|
|
|
Objectives []string
|
|
|
|
ObjectiveCounts []int64
|
|
|
|
BundleID string
|
|
|
|
ScheduleID string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewQuest(templateID string, bundleID string, scheduleID string) *Quest {
|
|
|
|
return &Quest{
|
|
|
|
ID: uuid.New().String(),
|
|
|
|
TemplateID: templateID,
|
2023-11-02 17:50:52 +00:00
|
|
|
State: "Active",
|
2023-10-31 22:40:14 +00:00
|
|
|
Objectives: []string{},
|
|
|
|
ObjectiveCounts: []int64{},
|
|
|
|
BundleID: bundleID,
|
|
|
|
ScheduleID: scheduleID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-02 17:50:52 +00:00
|
|
|
func NewDailyQuest(templateID string) *Quest {
|
|
|
|
return &Quest{
|
|
|
|
ID: uuid.New().String(),
|
|
|
|
TemplateID: templateID,
|
|
|
|
State: "Active",
|
|
|
|
Objectives: []string{},
|
|
|
|
ObjectiveCounts: []int64{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-31 22:40:14 +00:00
|
|
|
func FromDatabaseQuest(quest *storage.DB_Quest, profileType *string) *Quest {
|
|
|
|
return &Quest{
|
|
|
|
ID: quest.ID,
|
|
|
|
TemplateID: quest.TemplateID,
|
2023-11-02 17:50:52 +00:00
|
|
|
State: quest.State,
|
2023-10-31 22:40:14 +00:00
|
|
|
Objectives: quest.Objectives,
|
|
|
|
ObjectiveCounts: quest.ObjectiveCounts,
|
|
|
|
BundleID: quest.BundleID,
|
|
|
|
ScheduleID: quest.ScheduleID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-02 17:50:52 +00:00
|
|
|
func (q *Quest) GenerateFortniteQuestEntry() aid.JSON {
|
|
|
|
json := aid.JSON{
|
|
|
|
"templateId": q.TemplateID,
|
|
|
|
"attributes": aid.JSON{
|
|
|
|
"quest_state": q.State,
|
|
|
|
"challenge_bundle_id": q.BundleID,
|
|
|
|
},
|
|
|
|
"quantity": 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, objective := range q.Objectives {
|
|
|
|
json["attributes"].(aid.JSON)["completion_" + objective] = q.ObjectiveCounts[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
return json
|
|
|
|
}
|
|
|
|
|
2023-10-31 22:40:14 +00:00
|
|
|
func (q *Quest) Delete() {
|
2023-11-01 21:33:25 +00:00
|
|
|
storage.Repo.DeleteQuest(q.ID)
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Quest) AddObjective(objective string, count int64) {
|
|
|
|
q.Objectives = append(q.Objectives, objective)
|
|
|
|
q.ObjectiveCounts = append(q.ObjectiveCounts, count)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Quest) SetObjectiveCount(objective string, count int64) {
|
|
|
|
for i, obj := range q.Objectives {
|
|
|
|
if obj == objective {
|
|
|
|
q.ObjectiveCounts[i] = count
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Quest) UpdateObjectiveCount(objective string, delta int64) {
|
|
|
|
for i, obj := range q.Objectives {
|
|
|
|
if obj == objective {
|
|
|
|
q.ObjectiveCounts[i] += delta
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Quest) GetObjectiveCount(objective string) int64 {
|
|
|
|
for i, obj := range q.Objectives {
|
|
|
|
if obj == objective {
|
|
|
|
return q.ObjectiveCounts[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Quest) GetObjectiveIndex(objective string) int {
|
|
|
|
for i, obj := range q.Objectives {
|
|
|
|
if obj == objective {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Quest) RemoveObjective(objective string) {
|
|
|
|
for i, obj := range q.Objectives {
|
|
|
|
if obj == objective {
|
|
|
|
q.Objectives = append(q.Objectives[:i], q.Objectives[i+1:]...)
|
|
|
|
q.ObjectiveCounts = append(q.ObjectiveCounts[:i], q.ObjectiveCounts[i+1:]...)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Quest) ToDatabase(profileId string) *storage.DB_Quest {
|
|
|
|
return &storage.DB_Quest{
|
|
|
|
ProfileID: profileId,
|
|
|
|
ID: q.ID,
|
|
|
|
TemplateID: q.TemplateID,
|
2023-11-02 17:50:52 +00:00
|
|
|
State: q.State,
|
2023-10-31 22:40:14 +00:00
|
|
|
Objectives: q.Objectives,
|
|
|
|
ObjectiveCounts: q.ObjectiveCounts,
|
|
|
|
BundleID: q.BundleID,
|
|
|
|
ScheduleID: q.ScheduleID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Quest) Save() {
|
|
|
|
//storage.Repo.SaveQuest(q.ToDatabase())
|
|
|
|
}
|