套餐优惠礼包
This commit is contained in:
parent
2e04fe3164
commit
498e8c24f5
@ -2,17 +2,49 @@ package activityCfg
|
||||
|
||||
import (
|
||||
"server/GoUtil"
|
||||
"server/game/mod/item"
|
||||
"server/gamedata"
|
||||
"server/pkg/github.com/name5566/leaf/log"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
CFG_ACTIVITY = "Activity"
|
||||
CFG_ACTIVITY = "Activity"
|
||||
CFG_ACTIVITY_GIFT = "ActivityGift"
|
||||
)
|
||||
|
||||
func init() {
|
||||
gamedata.InitCfg(CFG_ACTIVITY)
|
||||
gamedata.InitCfg(CFG_ACTIVITY_GIFT)
|
||||
}
|
||||
|
||||
func GetActivityGiftId(chargeId int) int {
|
||||
data, err := gamedata.GetData(CFG_ACTIVITY_GIFT)
|
||||
if err != nil {
|
||||
log.Debug("GetActivityGift err:%v", err)
|
||||
}
|
||||
for _, v := range data {
|
||||
ChargeId := gamedata.GetIntValue(v, "ChargeId")
|
||||
if ChargeId == chargeId {
|
||||
return gamedata.GetIntValue(v, "AId")
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func GetAcitivityGiftItems(chargeId int) []*item.Item {
|
||||
data, err := gamedata.GetData(CFG_ACTIVITY_GIFT)
|
||||
if err != nil {
|
||||
log.Debug("GetAcitivityGiftItems err:%v", err)
|
||||
}
|
||||
for _, v := range data {
|
||||
ChargeId := gamedata.GetIntValue(v, "ChargeId")
|
||||
if ChargeId == chargeId {
|
||||
Items := gamedata.GetItemList(v, "Items")
|
||||
return Items
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetActivityList() []*gamedata.ActivityData {
|
||||
@ -37,6 +69,7 @@ func GetActivityList() []*gamedata.ActivityData {
|
||||
ActivityData := &gamedata.ActivityData{
|
||||
Id: Id,
|
||||
Type: Type,
|
||||
AType: gamedata.GetIntValue(v, "AType"),
|
||||
Name: Name,
|
||||
Title: Title,
|
||||
Level: Level,
|
||||
|
||||
@ -46,6 +46,15 @@ func GetActivityInfo(p *Player, actType int) *ActivityInfo {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetActivityInfoById(p *Player, Id int) *ActivityInfo {
|
||||
for _, v := range p.activity {
|
||||
if v.Id == Id {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetActivityStatus(p *Player, actType int) int {
|
||||
ActivityInfo := GetActivityInfo(p, actType)
|
||||
if ActivityInfo == nil {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
activityCfg "server/conf/activity"
|
||||
"server/game/mod/piggyBank"
|
||||
"server/msg"
|
||||
"server/pkg/github.com/name5566/leaf/log"
|
||||
@ -11,6 +12,30 @@ func Charge(p *Player, ChargeId int) {
|
||||
EndlessFire(p, ChargeId) // 无尽礼包
|
||||
PiggyBankFire(p, ChargeId) // 猪猪银行
|
||||
PlayroomFire(p, ChargeId) // 游乐场
|
||||
ActivityFire(p, ChargeId) // 活动礼包
|
||||
}
|
||||
|
||||
func ActivityFire(p *Player, ChargeId int) {
|
||||
ActivityMod := p.PlayMod.getActivityMod()
|
||||
ActivityId := activityCfg.GetActivityGiftId(ChargeId)
|
||||
ActivityInfo := GetActivityInfoById(p, ActivityId)
|
||||
if ActivityInfo == nil {
|
||||
log.Debug("ActivityFire ActivityInfo nil : player id :%d, charge id:%d", p.M_DwUin, ChargeId)
|
||||
return
|
||||
}
|
||||
Item, err := ActivityMod.Fire(ChargeId)
|
||||
if err != nil {
|
||||
log.Debug("ActivityFire err : %s", err)
|
||||
return
|
||||
}
|
||||
err = p.HandleItem(Item, msg.ITEM_POP_LABEL_ActivityGift.String())
|
||||
if err != nil {
|
||||
log.Debug("ChargeFire err : %s", err)
|
||||
return
|
||||
}
|
||||
p.PlayMod.save()
|
||||
p.initAcitivity()
|
||||
p.BackDataActivity()
|
||||
}
|
||||
|
||||
func PlayroomFire(p *Player, ChargeId int) {
|
||||
|
||||
@ -76,11 +76,18 @@ func ReqGmCommand_(player *Player, Command string) error {
|
||||
player.PlayMod.getBaseMod().Level = num
|
||||
player.PlayMod.getBaseMod().Exp = 0
|
||||
player.PushClientRes(player.PlayerBaseMod.BackAsset())
|
||||
player.initAcitivity()
|
||||
player.BackDataActivity()
|
||||
case "zeroUpdate":
|
||||
VarMod := player.PlayMod.getVarMod()
|
||||
VarMod.DailyResetTime = 0
|
||||
player.ZeroUpdate(nil)
|
||||
// G_GameLogicPtr.ZeroFlush()
|
||||
case "resetActivity":
|
||||
ActivityMod := player.PlayMod.getActivityMod()
|
||||
ActivityMod.Var = nil
|
||||
ActivityMod.InitData()
|
||||
player.PlayMod.save()
|
||||
case "weekUpdate":
|
||||
VarMod := player.PlayMod.getVarMod()
|
||||
VarMod.WeeklyResetTime = 0
|
||||
|
||||
@ -827,10 +827,14 @@ func (p *Player) initAcitivity() {
|
||||
p.activity = make(map[int]*ActivityInfo)
|
||||
ActivityList := activityCfg.GetActivityList()
|
||||
Level := p.GetPlayerBaseMod().GetLevel()
|
||||
ActivityMod := p.PlayMod.getActivityMod()
|
||||
for _, v := range ActivityList {
|
||||
if v.Level > Level {
|
||||
continue
|
||||
}
|
||||
if !ActivityMod.CheckActivity(v) {
|
||||
continue
|
||||
}
|
||||
p.activity[v.Id] = &ActivityInfo{
|
||||
StartT: v.StartTime,
|
||||
EndT: v.EndTime,
|
||||
|
||||
@ -515,6 +515,7 @@ func (p *PlayerBaseData) AddExp(player *Player, exp int) (int, error) {
|
||||
player.PushClientRes(ChargeMod.BackData())
|
||||
// 重载活动
|
||||
player.initAcitivity()
|
||||
player.BackDataActivity()
|
||||
p.p.TeLog("level_up", map[string]interface{}{
|
||||
"after_level": BaseMod.Level,
|
||||
})
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"server/db"
|
||||
"server/game/mod/activity"
|
||||
"server/game/mod/avatar"
|
||||
"server/game/mod/base"
|
||||
"server/game/mod/card"
|
||||
@ -75,6 +76,7 @@ type PlayerModList struct {
|
||||
FriendTreasure friendTreasure.FriendTreasureMod // 好友宝藏
|
||||
Emoji emoji.EmojiMod // 表情
|
||||
Collect collect.Collect // 收集
|
||||
Activity activity.Activity // 活动
|
||||
}
|
||||
|
||||
func (p *PlayerModData) LoadDataFromDB(dwUin interface{}) bool {
|
||||
@ -173,6 +175,7 @@ func (p *PlayerModData) InitMod(player *Player) (bool, error) {
|
||||
p.ModList.Playroom.InitData()
|
||||
p.ModList.Emoji.InitData()
|
||||
p.ModList.Collect.InitData()
|
||||
p.ModList.Activity.InitData()
|
||||
return is_update, nil
|
||||
}
|
||||
|
||||
@ -356,3 +359,7 @@ func (p *PlayerMod) getEmojiMod() *emoji.EmojiMod {
|
||||
func (p *PlayerMod) getCollectMod() *collect.Collect {
|
||||
return &p.mod_list.Collect
|
||||
}
|
||||
|
||||
func (p *PlayerMod) getActivityMod() *activity.Activity {
|
||||
return &p.mod_list.Activity
|
||||
}
|
||||
|
||||
@ -103,7 +103,6 @@ func HandleClientReq(args []interface{}) {
|
||||
data, _ := proto.Marshal(ResRegisterAccount)
|
||||
gl.PackResInfo(a, "ResRegisterAccount", data)
|
||||
case "ReqLogin":
|
||||
|
||||
detail := &msg.ReqLogin{}
|
||||
proto.Unmarshal(buf, detail)
|
||||
accountInfo := db.GetAccountInfoFromDb(detail.UserName)
|
||||
|
||||
72
src/server/game/mod/activity/activity.go
Normal file
72
src/server/game/mod/activity/activity.go
Normal file
@ -0,0 +1,72 @@
|
||||
package activity
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"server/gamedata"
|
||||
)
|
||||
|
||||
const (
|
||||
ACT_STATUS_NOT_START = 0
|
||||
ACT_STATUS_START = 1
|
||||
ACT_STATUS_END = 2
|
||||
)
|
||||
|
||||
const (
|
||||
ACT_TYPE_MINING = 1 // 挖矿
|
||||
ACT_TYPE_GUESS_COLOR = 2 // 猜颜色
|
||||
ACT_TYPE_RACE = 3 // 赛跑
|
||||
ACT_TYPE_DISCOUNT_GIFT = 4 // 折扣礼包
|
||||
)
|
||||
|
||||
const (
|
||||
ACT_ATYPE_NORMAL = 1 // 普通活动
|
||||
ACT_ATYPE_LIMIT_GIFT = 2 // 限时礼包活动
|
||||
)
|
||||
|
||||
type Activity struct {
|
||||
Var map[int]interface{}
|
||||
// 活动数据
|
||||
}
|
||||
|
||||
type Gift struct {
|
||||
Buy bool
|
||||
Time int64
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register(&Gift{})
|
||||
}
|
||||
|
||||
func (a *Activity) InitData() {
|
||||
a.Var = make(map[int]interface{})
|
||||
}
|
||||
|
||||
func (a *Activity) GetVar(key int) interface{} {
|
||||
return a.Var[key]
|
||||
}
|
||||
|
||||
func (a *Activity) SetVar(key int, value interface{}) {
|
||||
a.Var[key] = value
|
||||
}
|
||||
|
||||
func (a *Activity) getGIftVar(key int) *Gift {
|
||||
Var := a.GetVar(key)
|
||||
if Var == nil {
|
||||
Var = &Gift{}
|
||||
a.SetVar(key, Var)
|
||||
}
|
||||
return Var.(*Gift)
|
||||
}
|
||||
|
||||
func (a *Activity) CheckActivity(data *gamedata.ActivityData) bool {
|
||||
switch data.AType {
|
||||
case ACT_ATYPE_NORMAL:
|
||||
return true
|
||||
case ACT_ATYPE_LIMIT_GIFT:
|
||||
Var := a.getGIftVar(data.Id)
|
||||
if Var.Buy {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
19
src/server/game/mod/activity/activityGift.go
Normal file
19
src/server/game/mod/activity/activityGift.go
Normal file
@ -0,0 +1,19 @@
|
||||
package activity
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"server/GoUtil"
|
||||
activityCfg "server/conf/activity"
|
||||
"server/game/mod/item"
|
||||
)
|
||||
|
||||
func (a *Activity) Fire(Id int) ([]*item.Item, error) {
|
||||
AId := activityCfg.GetActivityGiftId(Id)
|
||||
Var := a.getGIftVar(AId)
|
||||
if Var.Buy {
|
||||
return nil, fmt.Errorf("已购买")
|
||||
}
|
||||
Var.Buy = true
|
||||
Var.Time = GoUtil.Now()
|
||||
return activityCfg.GetAcitivityGiftItems(Id), nil
|
||||
}
|
||||
@ -44,6 +44,7 @@ type ActivityData struct {
|
||||
StartTime int64
|
||||
EndTime int64
|
||||
Type int
|
||||
AType int
|
||||
Name string
|
||||
Title string
|
||||
Mail string
|
||||
|
||||
@ -81,6 +81,7 @@ const (
|
||||
ITEM_POP_LABEL_HandbookAllReward ITEM_POP_LABEL = 55 // 图鉴收集奖励
|
||||
ITEM_POP_LABEL_TLUpvote ITEM_POP_LABEL = 56 // 时间线点赞
|
||||
ITEM_POP_LABEL_Collect ITEM_POP_LABEL = 57 // 收集
|
||||
ITEM_POP_LABEL_ActivityGift ITEM_POP_LABEL = 58 // 活动礼包
|
||||
)
|
||||
|
||||
// Enum value maps for ITEM_POP_LABEL.
|
||||
@ -144,6 +145,7 @@ var (
|
||||
55: "HandbookAllReward",
|
||||
56: "TLUpvote",
|
||||
57: "Collect",
|
||||
58: "ActivityGift",
|
||||
}
|
||||
ITEM_POP_LABEL_value = map[string]int32{
|
||||
"Playroom": 0,
|
||||
@ -204,6 +206,7 @@ var (
|
||||
"HandbookAllReward": 55,
|
||||
"TLUpvote": 56,
|
||||
"Collect": 57,
|
||||
"ActivityGift": 58,
|
||||
}
|
||||
)
|
||||
|
||||
@ -22252,7 +22255,7 @@ var file_proto_Gameapi_proto_rawDesc = []byte{
|
||||
0x64, 0x22, 0x38, 0x0a, 0x0a, 0x52, 0x65, 0x71, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x47, 0x6d, 0x12,
|
||||
0x10, 0x0a, 0x03, 0x55, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x55, 0x69,
|
||||
0x64, 0x12, 0x18, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2a, 0xd6, 0x08, 0x0a, 0x0e,
|
||||
0x28, 0x09, 0x52, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2a, 0xe8, 0x08, 0x0a, 0x0e,
|
||||
0x49, 0x54, 0x45, 0x4d, 0x5f, 0x50, 0x4f, 0x50, 0x5f, 0x4c, 0x41, 0x42, 0x45, 0x4c, 0x12, 0x0c,
|
||||
0x0a, 0x08, 0x50, 0x6c, 0x61, 0x79, 0x72, 0x6f, 0x6f, 0x6d, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09,
|
||||
0x50, 0x69, 0x67, 0x67, 0x79, 0x42, 0x61, 0x6e, 0x6b, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x43,
|
||||
@ -22322,17 +22325,18 @@ var file_proto_Gameapi_proto_rawDesc = []byte{
|
||||
0x10, 0x36, 0x12, 0x15, 0x0a, 0x11, 0x48, 0x61, 0x6e, 0x64, 0x62, 0x6f, 0x6f, 0x6b, 0x41, 0x6c,
|
||||
0x6c, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x10, 0x37, 0x12, 0x0c, 0x0a, 0x08, 0x54, 0x4c, 0x55,
|
||||
0x70, 0x76, 0x6f, 0x74, 0x65, 0x10, 0x38, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x6f, 0x6c, 0x6c, 0x65,
|
||||
0x63, 0x74, 0x10, 0x39, 0x2a, 0x42, 0x0a, 0x0b, 0x48, 0x41, 0x4e, 0x44, 0x4c, 0x45, 0x5f, 0x54,
|
||||
0x59, 0x50, 0x45, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x44, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07,
|
||||
0x43, 0x4f, 0x4d, 0x50, 0x4f, 0x53, 0x45, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x42, 0x55, 0x59,
|
||||
0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x53, 0x45, 0x4c, 0x4c, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06,
|
||||
0x52, 0x45, 0x4d, 0x4f, 0x56, 0x45, 0x10, 0x04, 0x2a, 0x21, 0x0a, 0x08, 0x52, 0x45, 0x53, 0x5f,
|
||||
0x43, 0x4f, 0x44, 0x45, 0x12, 0x08, 0x0a, 0x04, 0x46, 0x41, 0x49, 0x4c, 0x10, 0x00, 0x12, 0x0b,
|
||||
0x0a, 0x07, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x01, 0x2a, 0x2e, 0x0a, 0x09, 0x49,
|
||||
0x54, 0x45, 0x4d, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x12, 0x0a, 0x0a, 0x06, 0x45, 0x4e, 0x45, 0x52,
|
||||
0x47, 0x59, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x53, 0x54, 0x41, 0x52, 0x10, 0x01, 0x12, 0x0b,
|
||||
0x0a, 0x07, 0x44, 0x49, 0x41, 0x4d, 0x4f, 0x4e, 0x44, 0x10, 0x02, 0x42, 0x08, 0x5a, 0x06, 0x2e,
|
||||
0x2e, 0x2f, 0x6d, 0x73, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x63, 0x74, 0x10, 0x39, 0x12, 0x10, 0x0a, 0x0c, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79,
|
||||
0x47, 0x69, 0x66, 0x74, 0x10, 0x3a, 0x2a, 0x42, 0x0a, 0x0b, 0x48, 0x41, 0x4e, 0x44, 0x4c, 0x45,
|
||||
0x5f, 0x54, 0x59, 0x50, 0x45, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x44, 0x44, 0x10, 0x00, 0x12, 0x0b,
|
||||
0x0a, 0x07, 0x43, 0x4f, 0x4d, 0x50, 0x4f, 0x53, 0x45, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x42,
|
||||
0x55, 0x59, 0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x53, 0x45, 0x4c, 0x4c, 0x10, 0x03, 0x12, 0x0a,
|
||||
0x0a, 0x06, 0x52, 0x45, 0x4d, 0x4f, 0x56, 0x45, 0x10, 0x04, 0x2a, 0x21, 0x0a, 0x08, 0x52, 0x45,
|
||||
0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x12, 0x08, 0x0a, 0x04, 0x46, 0x41, 0x49, 0x4c, 0x10, 0x00,
|
||||
0x12, 0x0b, 0x0a, 0x07, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x01, 0x2a, 0x2e, 0x0a,
|
||||
0x09, 0x49, 0x54, 0x45, 0x4d, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x12, 0x0a, 0x0a, 0x06, 0x45, 0x4e,
|
||||
0x45, 0x52, 0x47, 0x59, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x53, 0x54, 0x41, 0x52, 0x10, 0x01,
|
||||
0x12, 0x0b, 0x0a, 0x07, 0x44, 0x49, 0x41, 0x4d, 0x4f, 0x4e, 0x44, 0x10, 0x02, 0x42, 0x08, 0x5a,
|
||||
0x06, 0x2e, 0x2e, 0x2f, 0x6d, 0x73, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user