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 package stringsupport
import ( import (
"strings"
"strconv"
"bytes" "bytes"
"io/ioutil" "io/ioutil"
"strconv"
"strings"
"golang.org/x/text/encoding" "golang.org/x/text/encoding"
"golang.org/x/text/encoding/japanese" "golang.org/x/text/encoding/japanese"
@@ -83,16 +83,16 @@ func ConvertShiftJISToUTF8(text string) (string, error) {
} }
*/ */
func UTF8ToSJIS(x string) ([]byte) { func UTF8ToSJIS(x string) []byte {
e := japanese.ShiftJIS.NewEncoder() e := japanese.ShiftJIS.NewEncoder()
xt, _, err := transform.String(e, x) xt, _, err := transform.String(e, x)
if err != nil { if err != nil {
panic(err) panic(err)
} }
return []byte(xt) return []byte(xt)
} }
func SJISToUTF8(b []byte) (string) { func SJISToUTF8(b []byte) string {
d := japanese.ShiftJIS.NewDecoder() d := japanese.ShiftJIS.NewDecoder()
result, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(b), d)) result, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(b), d))
if err != nil { if err != nil {
@@ -103,13 +103,13 @@ func SJISToUTF8(b []byte) (string) {
func PaddedString(x string, size uint, t bool) []byte { func PaddedString(x string, size uint, t bool) []byte {
if t { if t {
e := japanese.ShiftJIS.NewEncoder() e := japanese.ShiftJIS.NewEncoder()
xt, _, err := transform.String(e, x) xt, _, err := transform.String(e, x)
if err != nil { if err != nil {
panic(err) panic(err)
} }
x = xt x = xt
} }
out := make([]byte, size) out := make([]byte, size)
copy(out, x) copy(out, x)
out[len(out)-1] = 0 out[len(out)-1] = 0
@@ -127,8 +127,8 @@ func CSVRemove(csv string, v int) string {
s := strings.Split(csv, ",") s := strings.Split(csv, ",")
for i, e := range s { for i, e := range s {
if e == strconv.Itoa(v) { if e == strconv.Itoa(v) {
s[i] = s[len(s) - 1] s[i] = s[len(s)-1]
s = s[:len(s) - 1] s = s[:len(s)-1]
} }
} }
return strings.Join(s, ",") return strings.Join(s, ",")
@@ -153,6 +153,19 @@ func CSVLength(csv string) int {
return len(s) 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. // ConvertUTF8ToShiftJIS converts a UTF8 string to a Shift-JIS []byte.
func ConvertUTF8ToShiftJIS(text string) ([]byte, error) { func ConvertUTF8ToShiftJIS(text string) ([]byte, error) {
r := bytes.NewBuffer([]byte(text)) 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, claimed bool NOT NULL DEFAULT false,
hunters text NOT NULL DEFAULT '', hunters text NOT NULL DEFAULT '',
treasure 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; END;

View File

@@ -82,10 +82,12 @@ func handleMsgMhfRegistGuildTresure(s *Session, p mhfpacket.MHFPacket) {
level := bf.ReadUint32() level := bf.ReadUint32()
huntData.WriteUint32(s.charID) huntData.WriteUint32(s.charID)
huntData.WriteBytes(stringsupport.PaddedString(s.Name, 18, true)) huntData.WriteBytes(stringsupport.PaddedString(s.Name, 18, true))
catsUsed := ""
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
catID := bf.ReadUint32() catID := bf.ReadUint32()
huntData.WriteUint32(catID) huntData.WriteUint32(catID)
if catID > 0 { if catID > 0 {
catsUsed = stringsupport.CSVAdd(catsUsed, int(catID))
for _, cat := range guildCats { for _, cat := range guildCats {
if cat.CatID == catID { if cat.CatID == catID {
huntData.WriteBytes(cat.CatName) huntData.WriteBytes(cat.CatName)
@@ -95,8 +97,8 @@ func handleMsgMhfRegistGuildTresure(s *Session, p mhfpacket.MHFPacket) {
huntData.WriteBytes(bf.ReadBytes(9)) 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)", _, 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()) guild.ID, s.charID, destination, level, Time_Current_Adjusted().Unix(), huntData.Data(), catsUsed)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -1,21 +1,19 @@
package channelserver package channelserver
import ( import (
"math/rand" "erupe-ce/common/byteframe"
"os" "erupe-ce/common/stringsupport"
"io"
"io/ioutil"
"path/filepath"
"erupe-ce/network/mhfpacket" "erupe-ce/network/mhfpacket"
"erupe-ce/server/channelserver/compression/deltacomp" "erupe-ce/server/channelserver/compression/deltacomp"
"erupe-ce/server/channelserver/compression/nullcomp" "erupe-ce/server/channelserver/compression/nullcomp"
"erupe-ce/common/byteframe"
"go.uber.org/zap" "go.uber.org/zap"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
) )
// THERE ARE [PARTENER] [MERCENARY] [OTOMO AIRU] // THERE ARE [PARTENER] [MERCENARY] [OTOMO AIRU]
/////////////////////////////////////////// ///////////////////////////////////////////
@@ -236,7 +234,7 @@ func handleMsgMhfSaveOtomoAirou(s *Session, p mhfpacket.MHFPacket) {
bf.Seek(-4, io.SeekCurrent) bf.Seek(-4, io.SeekCurrent)
bf.WriteUint32(nextID) bf.WriteUint32(nextID)
} }
_ = bf.ReadBytes(uint(dataLen)-4) _ = bf.ReadBytes(uint(dataLen) - 4)
} }
comp, err := nullcomp.Compress(bf.Data()) comp, err := nullcomp.Compress(bf.Data())
if err != nil { if err != nil {
@@ -297,8 +295,28 @@ func getGuildAirouList(s *Session) []CatDefinition {
return guildCats 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? // 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 FROM characters c
INNER JOIN guild_characters gc INNER JOIN guild_characters gc
ON gc.character_id = c.id ON gc.character_id = c.id
@@ -330,7 +348,8 @@ func getGuildAirouList(s *Session) []CatDefinition {
bf := byteframe.NewByteFrameFromBytes(decomp) bf := byteframe.NewByteFrameFromBytes(decomp)
cats := GetCatDetails(bf) cats := GetCatDetails(bf)
for _, cat := range cats { for _, cat := range cats {
if cat.CurrentTask == 4 { _, exists := bannedCats[cat.CatID]
if cat.CurrentTask == 4 && !exists {
guildCats = append(guildCats, cat) guildCats = append(guildCats, cat)
} }
} }