mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-23 12:24:45 +01:00
active feature generator
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package channelserver
|
package channelserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -53,8 +53,6 @@ func handleMsgMhfEnumerateEvent(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
stubEnumerateNoResults(s, pkt.AckHandle)
|
stubEnumerateNoResults(s, pkt.AckHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
var persistentEventSchedule []activeFeature
|
|
||||||
|
|
||||||
type activeFeature struct {
|
type activeFeature struct {
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
ActiveFeatures uint32
|
ActiveFeatures uint32
|
||||||
@@ -63,25 +61,16 @@ type activeFeature struct {
|
|||||||
|
|
||||||
func handleMsgMhfGetWeeklySchedule(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfGetWeeklySchedule(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfGetWeeklySchedule)
|
pkt := p.(*mhfpacket.MsgMhfGetWeeklySchedule)
|
||||||
// ActiveFeatures is a bit field, 0x3FFF is all 14 active features.
|
persistentEventSchedule := make([]activeFeature, 8) // generate day after weekly restart
|
||||||
// Long term it should probably be made persistent and simply cycle a couple daily
|
|
||||||
// Times seem to need to be timeServerFix.midnight which is likely why matching timezone was required originally
|
|
||||||
if len(persistentEventSchedule) == 0 {
|
|
||||||
if s.server.erupeConfig.DevMode && s.server.erupeConfig.DevModeOptions.OpcodeMessages {
|
|
||||||
s.logger.Info("\nGenerating active feature...")
|
|
||||||
}
|
|
||||||
persistentEventSchedule = make([]activeFeature, 8)
|
|
||||||
//weapons := generateRandomNumber(1, 14, 8)
|
|
||||||
for x := -1; x < 7; x++ {
|
for x := -1; x < 7; x++ {
|
||||||
var feat uint32
|
feat := generateActiveWeapons(14) // number of active weapons
|
||||||
feat |= 65535
|
// TODO: only generate this once per restart (server should be restarted weekly)
|
||||||
|
// then load data from db instead of regenerating
|
||||||
persistentEventSchedule[x+1] = activeFeature {
|
persistentEventSchedule[x+1] = activeFeature {
|
||||||
StartTime: Time_Current_Midnight().Add(time.Duration(24*x) * time.Hour),
|
StartTime: Time_Current_Midnight().Add(time.Duration(24*x) * time.Hour),
|
||||||
ActiveFeatures: feat,
|
ActiveFeatures: uint32(feat),
|
||||||
Unk1: 0,
|
Unk1: 0,
|
||||||
}
|
}
|
||||||
fmt.Println(feat)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := byteframe.NewByteFrame()
|
resp := byteframe.NewByteFrame()
|
||||||
@@ -96,14 +85,12 @@ func handleMsgMhfGetWeeklySchedule(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRandomNumber(start int, end int, count int) []int {
|
func generateActiveWeapons(count int) int {
|
||||||
if end < start || (end-start) < count {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
nums := make([]int, 0)
|
nums := make([]int, 0)
|
||||||
|
var result int
|
||||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
for len(nums) < count {
|
for len(nums) < count {
|
||||||
num := r.Intn((end - start)) + start
|
num := r.Intn(14)
|
||||||
exist := false
|
exist := false
|
||||||
for _, v := range nums {
|
for _, v := range nums {
|
||||||
if v == num {
|
if v == num {
|
||||||
@@ -115,7 +102,10 @@ func generateRandomNumber(start int, end int, count int) []int {
|
|||||||
nums = append(nums, num)
|
nums = append(nums, num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nums
|
for _, num := range nums {
|
||||||
|
result += int(math.Pow(2, float64(num)))
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
type loginBoost struct {
|
type loginBoost struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user