From 815e9d4f07fc9250d69e04ca4d091414327018da Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Fri, 13 Jan 2023 20:26:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E4=BC=9Aboss=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_opencond.json | 21 +++-- utils/time.go | 153 ++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 12 deletions(-) create mode 100644 utils/time.go diff --git a/bin/json/game_opencond.json b/bin/json/game_opencond.json index 4d32cc4a7..cc95de0e0 100644 --- a/bin/json/game_opencond.json +++ b/bin/json/game_opencond.json @@ -34,7 +34,7 @@ "main": [ { "key": "platlv", - "param": 1 + "param": 5 }, { "key": "maxmapid", @@ -224,7 +224,7 @@ } ], "optional": "", - "wkqbx": 1, + "wkqbx": 2, "kqbx": 0, "img": "zc_icon_01", "prompt": { @@ -1126,7 +1126,7 @@ "main": [ { "key": "platlv", - "param": 2 + "param": 20 }, { "key": "maxmapid", @@ -1204,7 +1204,7 @@ "main": [ { "key": "platlv", - "param": 1 + "param": 10 }, { "key": "maxmapid", @@ -1212,7 +1212,7 @@ } ], "optional": "", - "wkqbx": 1, + "wkqbx": 2, "kqbx": 0, "img": "zc_icon_01", "prompt": { @@ -1400,7 +1400,7 @@ "main": [ { "key": "platlv", - "param": 1 + "param": 5 }, { "key": "maxmapid", @@ -1572,7 +1572,6 @@ "text": "功能暂未开启" }, "uiid": 0 -<<<<<<< HEAD }, { "id": "slidescreen_up", @@ -1583,7 +1582,7 @@ "main": [ { "key": "worldtaskid", - "param": 20010 + "param": 20060 } ], "optional": "", @@ -1605,7 +1604,7 @@ "main": [ { "key": "worldtaskid", - "param": 20010 + "param": 20060 } ], "optional": "", @@ -1627,7 +1626,7 @@ "main": [ { "key": "worldtaskid", - "param": 20010 + "param": 20060 } ], "optional": "", @@ -1639,7 +1638,5 @@ "text": "" }, "uiid": 0 -======= ->>>>>>> f52b7e00 (公会boss优化) } ] \ No newline at end of file diff --git a/utils/time.go b/utils/time.go new file mode 100644 index 000000000..7e006e087 --- /dev/null +++ b/utils/time.go @@ -0,0 +1,153 @@ +package utils + +import ( + "fmt" + "go_dreamfactory/sys/configure" + "math" + "time" + + "github.com/jinzhu/now" +) + +// 判断时间点处于今天 +func IsToday(d int64) bool { + tt := time.Unix(d, 0) + now := configure.Now() + return tt.Year() == now.Year() && tt.Month() == now.Month() && tt.Day() == now.Day() +} + +//判断是否大于1周 +func IsAfterWeek(d int64) bool { + tt := time.Unix(d, 0) + nowt := configure.Now() + if !tt.Before(nowt) { + return false + } + at := now.With(tt).AddDate(0, 0, 7).Unix() + return nowt.Unix() >= at +} + +// 是否今日首次 +func IsFirstTody(timestamp int64) bool { + now := configure.Now() + if timestamp == 0 || timestamp > now.Unix() { + return false + } + tt := time.Unix(timestamp, 0) + if !IsToday(timestamp) { + if tt.Before(now) { + return true + } + } + return false +} + +// 获取当前时间戳下一天0点时间戳 +func GetZeroTime(curTime int64) int64 { + currentTime := time.Unix(curTime, 0) + startTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, currentTime.Location()) + + return startTime.Unix() + 86400 //3600*24 +} + +func IsYestoday(timestamp int64) bool { + tt := time.Unix(timestamp, 0) + yesTime := configure.Now().AddDate(0, 0, -1) + return tt.Year() == yesTime.Year() && tt.Month() == yesTime.Month() && tt.Day() == yesTime.Day() +} + +// 确定换算规则 现实1H = 虚拟4H +// 计算:根据开服时间为起始时间,计算当前时间与起始时间的差值,计算虚拟当前时间 +func MatrixingHour(beginTime string) (t time.Time) { + location, err := time.LoadLocation("Asia/Shanghai") + if err != nil { + return + } + myConfig := &now.Config{ + WeekStartDay: time.Monday, + TimeLocation: location, + TimeFormats: []string{"2006-01-02 15:04:05"}, + } + + serverStartTime, _ := myConfig.Parse(beginTime) + + n := configure.Now() + timeSub := n.Sub(serverStartTime) + hourSub := timeSub.Hours() * 2 + + hh, _ := time.ParseDuration("1h") + fmt.Println(hourSub, math.Ceil(hourSub)) + t2 := serverStartTime.Add(hh * time.Duration(math.Ceil(hourSub))) + + fmt.Println(t2) + + return +} + +// 时间戳格式化字符串日期 +func FormatStr(timestamp int64, format string) string { + if format == "" { + format = "2006-01-02 15:04:05" + } + return time.Unix(timestamp, 0).Format(format) +} + +func AddHour(hour int) time.Time { + return configure.Now().Add(time.Duration(hour) * time.Hour) +} + +// CD +func IsInCDHour(cdTime int64) bool { + if cdTime == 0 { + return false + } + return configure.Now().Unix() < cdTime +} + +// 获取本月的开始和结束的时间戳 +func GetMonthStartEnd() (int64, int64) { + t := configure.Now() + monthStartDay := t.AddDate(0, 0, -t.Day()+1) + monthStartTime := time.Date(monthStartDay.Year(), monthStartDay.Month(), monthStartDay.Day(), 0, 0, 0, 0, t.Location()) + monthEndDay := monthStartTime.AddDate(0, 1, -1) + monthEndTime := time.Date(monthEndDay.Year(), monthEndDay.Month(), monthEndDay.Day(), 23, 59, 59, 0, t.Location()) + _d1 := monthStartTime.Unix() + _d2 := monthEndTime.Unix() + fmt.Printf("%d,%d", _d1, _d2) + return _d1, _d2 +} + +// 获取今天零点时间戳 +func GetTodayZeroTime(curTime int64) int64 { + currentTime := time.Unix(curTime, 0) + startTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, currentTime.Location()) + + return startTime.Unix() +} + +// 计算自然天数 +func DiffDays(t1, t2 int64) int { + if t1 == t2 { + return -1 + } + + if t1 > t2 { + t1, t2 = t2, t1 + } + + secOfDay := 3600 * 24 + diffDays := 0 + secDiff := t2 - t1 + if secDiff > int64(secOfDay) { + tmpDays := int(secDiff / int64(secOfDay)) + t1 += int64(tmpDays) * int64(secOfDay) + diffDays += tmpDays + } + st := time.Unix(t1, 0) + et := time.Unix(t2, 0) + dateformat := "20060102" + if st.Format(dateformat) != et.Format(dateformat) { + diffDays += 1 + } + return diffDays +}