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 {
|
2023-11-05 01:58:00 +00:00
|
|
|
ID string
|
|
|
|
ProfileID string
|
|
|
|
TemplateID string
|
|
|
|
State string
|
|
|
|
Objectives []string
|
2023-10-31 22:40:14 +00:00
|
|
|
ObjectiveCounts []int64
|
2023-11-05 01:58:00 +00:00
|
|
|
BundleID string
|
|
|
|
ScheduleID string
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewQuest(templateID string, bundleID string, scheduleID string) *Quest {
|
|
|
|
return &Quest{
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: uuid.New().String(),
|
|
|
|
TemplateID: templateID,
|
|
|
|
State: "Active",
|
|
|
|
Objectives: []string{},
|
2023-10-31 22:40:14 +00:00
|
|
|
ObjectiveCounts: []int64{},
|
2023-11-05 01:58:00 +00:00
|
|
|
BundleID: bundleID,
|
|
|
|
ScheduleID: scheduleID,
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-02 17:50:52 +00:00
|
|
|
func NewDailyQuest(templateID string) *Quest {
|
|
|
|
return &Quest{
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: uuid.New().String(),
|
|
|
|
TemplateID: templateID,
|
|
|
|
State: "Active",
|
|
|
|
Objectives: []string{},
|
2023-11-02 17:50:52 +00:00
|
|
|
ObjectiveCounts: []int64{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-05 01:58:00 +00:00
|
|
|
func FromDatabaseQuest(quest *storage.DB_Quest) *Quest {
|
2023-10-31 22:40:14 +00:00
|
|
|
return &Quest{
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: quest.ID,
|
|
|
|
ProfileID: quest.ProfileID,
|
|
|
|
TemplateID: quest.TemplateID,
|
|
|
|
State: quest.State,
|
|
|
|
Objectives: quest.Objectives,
|
2023-10-31 22:40:14 +00:00
|
|
|
ObjectiveCounts: quest.ObjectiveCounts,
|
2023-11-05 01:58:00 +00:00
|
|
|
BundleID: quest.BundleID,
|
|
|
|
ScheduleID: quest.ScheduleID,
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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{
|
2023-11-05 01:58:00 +00:00
|
|
|
ID: q.ID,
|
|
|
|
ProfileID: profileId,
|
|
|
|
TemplateID: q.TemplateID,
|
|
|
|
State: q.State,
|
|
|
|
Objectives: q.Objectives,
|
2023-10-31 22:40:14 +00:00
|
|
|
ObjectiveCounts: q.ObjectiveCounts,
|
2023-11-05 01:58:00 +00:00
|
|
|
BundleID: q.BundleID,
|
|
|
|
ScheduleID: q.ScheduleID,
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Quest) Save() {
|
2023-11-05 01:58:00 +00:00
|
|
|
storage.Repo.SaveQuest(q.ToDatabase(q.ProfileID))
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|