implement treasure hunt cooldowns

This commit is contained in:
wish
2022-07-23 09:35:55 +10:00
parent 7e994187b3
commit 863e8fc860
4 changed files with 68 additions and 33 deletions

View File

@@ -1,10 +1,10 @@
package stringsupport
import (
"strings"
"strconv"
"bytes"
"io/ioutil"
"strconv"
"strings"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/japanese"
@@ -83,7 +83,7 @@ func ConvertShiftJISToUTF8(text string) (string, error) {
}
*/
func UTF8ToSJIS(x string) ([]byte) {
func UTF8ToSJIS(x string) []byte {
e := japanese.ShiftJIS.NewEncoder()
xt, _, err := transform.String(e, x)
if err != nil {
@@ -92,7 +92,7 @@ func UTF8ToSJIS(x string) ([]byte) {
return []byte(xt)
}
func SJISToUTF8(b []byte) (string) {
func SJISToUTF8(b []byte) string {
d := japanese.ShiftJIS.NewDecoder()
result, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(b), d))
if err != nil {
@@ -153,6 +153,19 @@ func CSVLength(csv string) int {
return len(s)
}
func CSVElems(csv string) []int {
var r []int
if csv == "" {
return r
}
s := strings.Split(csv, ",")
for i := 0; i < len(s); i++ {
j, _ := strconv.ParseInt(s[i], 10, 64)
r = append(r, int(j))
}
return r
}
// ConvertUTF8ToShiftJIS converts a UTF8 string to a Shift-JIS []byte.
func ConvertUTF8ToShiftJIS(text string) ([]byte, error) {
r := bytes.NewBuffer([]byte(text))

View File

@@ -49,7 +49,8 @@ CREATE TABLE IF NOT EXISTS public.guild_hunts
claimed bool NOT NULL DEFAULT false,
hunters text NOT NULL DEFAULT '',
treasure text NOT NULL DEFAULT '',
hunt_data bytea NOT NULL
hunt_data bytea NOT NULL,
cats_used text NOT NULL
);
END;

View File

@@ -82,10 +82,12 @@ func handleMsgMhfRegistGuildTresure(s *Session, p mhfpacket.MHFPacket) {
level := bf.ReadUint32()
huntData.WriteUint32(s.charID)
huntData.WriteBytes(stringsupport.PaddedString(s.Name, 18, true))
catsUsed := ""
for i := 0; i < 5; i++ {
catID := bf.ReadUint32()
huntData.WriteUint32(catID)
if catID > 0 {
catsUsed = stringsupport.CSVAdd(catsUsed, int(catID))
for _, cat := range guildCats {
if cat.CatID == catID {
huntData.WriteBytes(cat.CatName)
@@ -95,8 +97,8 @@ func handleMsgMhfRegistGuildTresure(s *Session, p mhfpacket.MHFPacket) {
huntData.WriteBytes(bf.ReadBytes(9))
}
}
_, err = s.server.db.Exec("INSERT INTO guild_hunts (guild_id, host_id, destination, level, return, hunt_data) VALUES ($1, $2, $3, $4, $5, $6)",
guild.ID, s.charID, destination, level, Time_Current_Adjusted().Unix(), huntData.Data())
_, err = s.server.db.Exec("INSERT INTO guild_hunts (guild_id, host_id, destination, level, return, hunt_data, cats_used) VALUES ($1, $2, $3, $4, $5, $6, $7)",
guild.ID, s.charID, destination, level, Time_Current_Adjusted().Unix(), huntData.Data(), catsUsed)
if err != nil {
panic(err)
}

View File

@@ -1,21 +1,19 @@
package channelserver
import (
"math/rand"
"os"
"io"
"io/ioutil"
"path/filepath"
"erupe-ce/common/byteframe"
"erupe-ce/common/stringsupport"
"erupe-ce/network/mhfpacket"
"erupe-ce/server/channelserver/compression/deltacomp"
"erupe-ce/server/channelserver/compression/nullcomp"
"erupe-ce/common/byteframe"
"go.uber.org/zap"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
)
// THERE ARE [PARTENER] [MERCENARY] [OTOMO AIRU]
///////////////////////////////////////////
@@ -297,8 +295,28 @@ func getGuildAirouList(s *Session) []CatDefinition {
return guildCats
}
// Get cats used recently
// Retail reset at midday, 12 hours is a midpoint
tempBanDuration := 43200 - (1800) // Minus hunt time
bannedCats := make(map[uint32]int)
var csvTemp string
rows, err := s.server.db.Query(`SELECT cats_used
FROM guild_hunts gh
INNER JOIN characters c
ON gh.host_id = c.id
WHERE c.id=$1 AND gh.return+$2>$3`, s.charID, tempBanDuration, Time_Current_Adjusted().Unix())
if err != nil {
s.logger.Warn("Failed to get recently used airous", zap.Error(err))
}
for rows.Next() {
rows.Scan(&csvTemp)
for i, j := range stringsupport.CSVElems(csvTemp) {
bannedCats[uint32(j)] = i
}
}
// ellie's GetGuildMembers didn't seem to pull leader?
rows, err := s.server.db.Query(`SELECT c.otomoairou
rows, err = s.server.db.Query(`SELECT c.otomoairou
FROM characters c
INNER JOIN guild_characters gc
ON gc.character_id = c.id
@@ -330,7 +348,8 @@ func getGuildAirouList(s *Session) []CatDefinition {
bf := byteframe.NewByteFrameFromBytes(decomp)
cats := GetCatDetails(bf)
for _, cat := range cats {
if cat.CurrentTask == 4 {
_, exists := bannedCats[cat.CatID]
if cat.CurrentTask == 4 && !exists {
guildCats = append(guildCats, cat)
}
}