每周优惠
This commit is contained in:
parent
0da23102a7
commit
120d83901a
@ -1,6 +1,7 @@
|
||||
package chargeCfg
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"server/GoUtil"
|
||||
"server/game/mod/item"
|
||||
"server/gamedata"
|
||||
@ -47,6 +48,14 @@ func GetADReward(ChargeId int) ([]*item.Item, int) {
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
func GetWeeklyDiscountDay() int {
|
||||
data, err := gamedata.GetDataByKey(CFG_CHARGE_CONST, "weekly_discount_day")
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
return gamedata.GetIntValue(data, "Value")
|
||||
}
|
||||
|
||||
func GetMoneyCharge(ChargeId int) float64 {
|
||||
data, err := gamedata.GetDataByIntKey(CFG_CHARGE, ChargeId)
|
||||
if err != nil {
|
||||
@ -81,6 +90,40 @@ func GetEnergyShopId(ChargeId int) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func GetWeeklyInfo(Id int) (int, int) {
|
||||
data, err := gamedata.GetDataByKey(CFG_CHARGE_CONST, "weekly_chess_shop")
|
||||
if err != nil {
|
||||
return 0, 0
|
||||
}
|
||||
var r map[string]interface{}
|
||||
json.Unmarshal([]byte(gamedata.GetStringValue(data, "Value")), &r)
|
||||
if val, ok := r[GoUtil.String(Id)]; ok {
|
||||
arr := val.(map[string]interface{})
|
||||
return GoUtil.Int(arr["Discount"]), GoUtil.Int(arr["Limit"])
|
||||
}
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
func GetWeeklyInfoAll() map[int]gamedata.WeeklyDiscountInfo {
|
||||
data, err := gamedata.GetDataByKey(CFG_CHARGE_CONST, "weekly_chess_shop")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var r map[int]interface{}
|
||||
var res = make(map[int]gamedata.WeeklyDiscountInfo)
|
||||
json.Unmarshal([]byte(gamedata.GetStringValue(data, "Value")), &r)
|
||||
for _, v := range r {
|
||||
v1 := v.(map[string]interface{})
|
||||
Id := GoUtil.Int(v1["Id"])
|
||||
res[Id] = gamedata.WeeklyDiscountInfo{
|
||||
Id: GoUtil.Int(v1["Id"]),
|
||||
Discount: GoUtil.Int(v1["Discount"]),
|
||||
WeeklyLimit: GoUtil.Int(v1["Limit"]),
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func GetEnergyShopReward(ChargeId int, First bool) []*item.Item {
|
||||
data, err := gamedata.GetData(CFG_ENERGY_SHOP)
|
||||
if err != nil {
|
||||
|
||||
@ -40,12 +40,33 @@ func init() {
|
||||
gamedata.InitCfg(CFG_PLAYROOM_ORDERITEM)
|
||||
}
|
||||
|
||||
func GetShopItem(Id int) (int, []*item.Item) {
|
||||
func GetShopItem(Id int) (int, []*item.Item, int, int) {
|
||||
data, err := gamedata.GetDataByIntKey(CFG_PLAYROOM_SHOP, Id)
|
||||
if err != nil {
|
||||
return 0, nil
|
||||
return 0, nil, 0, 0
|
||||
}
|
||||
return gamedata.GetIntValue(data, "ItemId"), gamedata.GetItemList(data, "Cost")
|
||||
return gamedata.GetIntValue(data, "ItemId"), gamedata.GetItemList(data, "Cost"), gamedata.GetIntValue(data, "Discount"), gamedata.GetIntValue(data, "Limit")
|
||||
}
|
||||
|
||||
func GetShopWeeklyLimit() map[int]gamedata.WeeklyDiscountInfo {
|
||||
r := make(map[int]gamedata.WeeklyDiscountInfo)
|
||||
data, err := gamedata.GetData(CFG_PLAYROOM_SHOP)
|
||||
if err != nil {
|
||||
return r
|
||||
}
|
||||
for _, v := range data {
|
||||
Id := gamedata.GetIntValue(v, "ID")
|
||||
Limit := gamedata.GetIntValue(v, "Limit")
|
||||
if Limit == 0 {
|
||||
continue
|
||||
}
|
||||
r[Id] = gamedata.WeeklyDiscountInfo{
|
||||
Id: Id,
|
||||
Discount: gamedata.GetIntValue(v, "Discount"),
|
||||
WeeklyLimit: Limit,
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func GetShopWish(Id int) int {
|
||||
|
||||
@ -2,6 +2,7 @@ package game
|
||||
|
||||
import (
|
||||
"server/GoUtil"
|
||||
playroomCfg "server/conf/playroom"
|
||||
"server/game/mod/item"
|
||||
proto "server/msg"
|
||||
)
|
||||
@ -122,6 +123,20 @@ func PlayroomBackData(p *Player) {
|
||||
Label: v.Label,
|
||||
})
|
||||
}
|
||||
weeklyDiscount := make(map[int32]*proto.WeeklyDiscountInfo)
|
||||
ChargeMod := p.PlayMod.getChargeMod()
|
||||
if ChargeMod.IsWeeklyDiscountDay() {
|
||||
w1 := playroomCfg.GetShopWeeklyLimit()
|
||||
for k, v := range w1 {
|
||||
limitNum := ChargeMod.WeeklyDiscount[k]
|
||||
weeklyDiscount[int32(k)] = &proto.WeeklyDiscountInfo{
|
||||
Id: int32(k),
|
||||
Discount: int32(v.Discount),
|
||||
Count: int32(v.WeeklyLimit - limitNum),
|
||||
}
|
||||
}
|
||||
}
|
||||
r.WeeklyDiscount = weeklyDiscount
|
||||
r.PetAir = PetAir
|
||||
r.PetAirSet = int32(PlayroomMod.GetPetAirSet())
|
||||
r.Chip = ChipMessage
|
||||
|
||||
@ -1425,7 +1425,8 @@ func ReqBuyEnergy(player *Player, buf []byte) error {
|
||||
req := &msg.ReqBuyEnergy{}
|
||||
proto.Unmarshal(buf, req)
|
||||
BaseMod := player.PlayMod.getBaseMod()
|
||||
Item, Energy, Diamond := BaseMod.BuyEnergy(int(req.Energy))
|
||||
ChargeMod := player.PlayMod.getChargeMod()
|
||||
Item, Energy, Diamond := ChargeMod.BuyEnergy()
|
||||
err := player.HandleItem(Item, msg.ITEM_POP_LABEL_BuyEnergy.String())
|
||||
if err != nil {
|
||||
player.SendErrClienRes(&msg.ResBuyEnergy{
|
||||
@ -4071,7 +4072,8 @@ func ReqPlayroomShop(player *Player, buf []byte) error {
|
||||
req := &msg.ReqPlayroomShop{}
|
||||
proto.Unmarshal(buf, req)
|
||||
PlayroomMod := player.PlayMod.getPlayroomMod()
|
||||
AddItems, LoseItem, err := PlayroomMod.ShopBuy(int(req.Id), int(req.Num))
|
||||
ChargeMod := player.PlayMod.getChargeMod()
|
||||
AddItems, LoseItem, err := PlayroomMod.ShopBuy(int(req.Id), int(req.Num), ChargeMod.IsWeeklyDiscountDay())
|
||||
if err != nil {
|
||||
player.SendErrClienRes(&msg.ResPlayroomShop{
|
||||
Code: msg.RES_CODE_FAIL,
|
||||
|
||||
@ -32,9 +32,10 @@ type ChargeMod struct {
|
||||
|
||||
Gift map[int]int // 礼包
|
||||
|
||||
Ad bool // 是否购买免广告
|
||||
AdEndTime int64
|
||||
WishList *WishList
|
||||
Ad bool // 是否购买免广告
|
||||
AdEndTime int64
|
||||
WishList *WishList
|
||||
WeeklyDiscount map[int]int // 每周折扣购买次数
|
||||
}
|
||||
|
||||
type WishList struct {
|
||||
@ -92,6 +93,9 @@ func (c *ChargeMod) InitData() {
|
||||
SendList: make([]int64, 0),
|
||||
}
|
||||
}
|
||||
if c.WeeklyDiscount == nil {
|
||||
c.WeeklyDiscount = make(map[int]int)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ChargeMod) GetMaxCharge() float64 {
|
||||
@ -124,6 +128,7 @@ func (c *ChargeMod) ZeroUpdate(Emit []int) {
|
||||
c.SpecialShop[i] = &SepcialShop{Grade: SpecialGrade, Count: SpecialShopCount}
|
||||
}
|
||||
c.WishList.SendList = make([]int64, 0)
|
||||
c.WeeklyDiscount = make(map[int]int)
|
||||
c.InitChessShop(Emit)
|
||||
}
|
||||
|
||||
@ -293,6 +298,17 @@ func (c *ChargeMod) BackData() *msg.ResCharge {
|
||||
Uid: c.WishList.SendList,
|
||||
}
|
||||
}
|
||||
WeeklyDiscount := make(map[int32]*msg.WeeklyDiscountInfo)
|
||||
WeeklyDiscountInfo := chargeCfg.GetWeeklyInfoAll()
|
||||
for k, v := range WeeklyDiscountInfo {
|
||||
LimitNum := c.WeeklyDiscount[k]
|
||||
WeeklyDiscount[int32(k)] = &msg.WeeklyDiscountInfo{
|
||||
Discount: int32(v.Discount),
|
||||
Count: int32(v.WeeklyLimit - LimitNum),
|
||||
Id: int32(k),
|
||||
}
|
||||
}
|
||||
|
||||
return &msg.ResCharge{
|
||||
Charge: float32(c.Charge),
|
||||
Total: int32(c.Total),
|
||||
@ -308,6 +324,7 @@ func (c *ChargeMod) BackData() *msg.ResCharge {
|
||||
MonthCharge: float32(c.MonthCharge),
|
||||
Wish: resWish,
|
||||
AdEndTime: c.AdEndTime,
|
||||
WeeklyDiscount: WeeklyDiscount,
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,6 +386,23 @@ func (c *ChargeMod) InitChessShop(Emit []int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ChargeMod) BuyEnergy() ([]*item.Item, []*item.Item, int) {
|
||||
diamond := 40
|
||||
if c.IsWeeklyDiscountDay() {
|
||||
LimitNum := c.WeeklyDiscount[0]
|
||||
Discount, WeeklyLimit := chargeCfg.GetWeeklyInfo(0)
|
||||
if LimitNum < WeeklyLimit {
|
||||
diamond = int(math.Round(float64(diamond) * float64(Discount) / 100))
|
||||
c.WeeklyDiscount[0] = LimitNum + 1
|
||||
}
|
||||
}
|
||||
return []*item.Item{
|
||||
item.NewItem(item.ITEM_DIAMOND_ID, diamond),
|
||||
}, []*item.Item{
|
||||
item.NewItem(item.ITEM_ENERGY_ID, 100),
|
||||
}, diamond
|
||||
}
|
||||
|
||||
func (c *ChargeMod) BuyChess(Chess int) ([]*item.Item, []*item.Item, int, error) {
|
||||
v, ok := c.ChessShop[Chess]
|
||||
if !ok {
|
||||
@ -379,8 +413,17 @@ func (c *ChargeMod) BuyChess(Chess int) ([]*item.Item, []*item.Item, int, error)
|
||||
return nil, nil, 0, fmt.Errorf("BuyChess chess count less zero id:%d", Chess)
|
||||
}
|
||||
v.Count--
|
||||
diamond := v.Diamond
|
||||
if c.IsWeeklyDiscountDay() {
|
||||
LimitNum := c.WeeklyDiscount[Chess]
|
||||
Discount, WeeklyLimit := chargeCfg.GetWeeklyInfo(Chess)
|
||||
if LimitNum < WeeklyLimit {
|
||||
diamond = int(math.Round(float64(diamond) * float64(Discount) / 100))
|
||||
c.WeeklyDiscount[Chess] = LimitNum + 1
|
||||
}
|
||||
}
|
||||
return []*item.Item{
|
||||
item.NewItem(item.ITEM_DIAMOND_ID, v.Diamond),
|
||||
item.NewItem(item.ITEM_DIAMOND_ID, diamond),
|
||||
}, []*item.Item{
|
||||
item.NewItem(v.Id, 1),
|
||||
}, v.Id, nil
|
||||
@ -398,7 +441,7 @@ func (c *ChargeMod) AddWish(Id, Type int) ([]*item.Item, error) {
|
||||
ItemId := 0
|
||||
switch Type {
|
||||
case PLAYROOM_SHOP:
|
||||
ItemId, _ = playroomCfg.GetShopItem(Id)
|
||||
ItemId, _, _, _ = playroomCfg.GetShopItem(Id)
|
||||
}
|
||||
if ItemId == 0 {
|
||||
return nil, fmt.Errorf("AddWish itemid not exist id:%d", Id)
|
||||
@ -448,3 +491,12 @@ func (c *ChargeMod) AddWishCount() {
|
||||
}
|
||||
c.WishList.Count++
|
||||
}
|
||||
|
||||
func (c *ChargeMod) IsWeeklyDiscountDay() bool {
|
||||
Day := chargeCfg.GetWeeklyDiscountDay()
|
||||
if Day == -1 {
|
||||
return false
|
||||
}
|
||||
Weekday, _ := GoUtil.GetWeekdayAndHour()
|
||||
return Weekday == Day
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package item
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"server/msg"
|
||||
)
|
||||
|
||||
@ -182,7 +183,6 @@ func Merge(Item1, Item2 []*Item) []*Item {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func MutilItem(i []*Item, num int) []*Item {
|
||||
if i == nil {
|
||||
return nil
|
||||
@ -196,3 +196,17 @@ func MutilItem(i []*Item, num int) []*Item {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func MutilItemFloat(i []*Item, num float64) []*Item {
|
||||
if i == nil {
|
||||
return nil
|
||||
}
|
||||
res := make([]*Item, 0)
|
||||
for _, v := range i {
|
||||
res = append(res, &Item{
|
||||
Id: v.Id,
|
||||
Num: int(math.Round(float64(v.Num) * num)),
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@ -60,6 +60,7 @@ type PlayroomMod struct {
|
||||
FilterVisitor bool // 是否过滤访客
|
||||
TodayVisitedUsers []int // 今日已拜访过的用户
|
||||
ADItem map[int]*ItemInfo
|
||||
WeeklyDiscount map[int]int // 每周折扣
|
||||
}
|
||||
|
||||
type DressInfo struct {
|
||||
@ -292,6 +293,9 @@ func (p *PlayroomMod) InitData() {
|
||||
if p.ADItem == nil {
|
||||
p.ADItem = make(map[int]*ItemInfo)
|
||||
}
|
||||
if p.WeeklyDiscount == nil {
|
||||
p.WeeklyDiscount = make(map[int]int)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PlayroomMod) ZeroUpdate() {
|
||||
@ -302,6 +306,7 @@ func (p *PlayroomMod) ZeroUpdate() {
|
||||
p.DailyTaskReward = make([]int, 0)
|
||||
p.TodayVisitedUsers = make([]int, 0)
|
||||
p.ADItem = make(map[int]*ItemInfo)
|
||||
p.WeeklyDiscount = make(map[int]int)
|
||||
p.InitDailyTask()
|
||||
}
|
||||
|
||||
@ -900,7 +905,6 @@ func (p *PlayroomMod) GetFlipReward() ([]*item.Item, int, int, error) {
|
||||
|
||||
func (p *PlayroomMod) BuyItem(Id int) ([]*item.Item, []*item.Item) {
|
||||
return playroomCfg.GetBuyItem(Id)
|
||||
|
||||
}
|
||||
|
||||
func (p *PlayroomMod) UnLock(Lv int) bool {
|
||||
@ -928,12 +932,18 @@ func (p *PlayroomMod) UnLock(Lv int) bool {
|
||||
}
|
||||
|
||||
// shop
|
||||
func (p *PlayroomMod) ShopBuy(Id, Num int) ([]*item.Item, []*item.Item, error) {
|
||||
AddItemId, CostItem := playroomCfg.GetShopItem(Id)
|
||||
func (p *PlayroomMod) ShopBuy(Id, Num int, WeeklyDiscount bool) ([]*item.Item, []*item.Item, error) {
|
||||
AddItemId, CostItem, Discount, Limit := playroomCfg.GetShopItem(Id)
|
||||
if AddItemId == 0 {
|
||||
return nil, nil, fmt.Errorf("ShopBuy AddItemId is 0")
|
||||
}
|
||||
NewCostItem := item.MutilItem(CostItem, Num)
|
||||
if WeeklyDiscount {
|
||||
LimitNum := p.WeeklyDiscount[Id]
|
||||
if LimitNum < Limit {
|
||||
NewCostItem = item.MutilItemFloat(NewCostItem, float64(Discount)/100.0)
|
||||
}
|
||||
}
|
||||
return []*item.Item{item.NewItem(AddItemId, Num)}, NewCostItem, nil
|
||||
}
|
||||
|
||||
|
||||
@ -67,3 +67,9 @@ type PetOrderItem struct {
|
||||
Num int
|
||||
Grade []int
|
||||
}
|
||||
|
||||
type WeeklyDiscountInfo struct {
|
||||
Id int
|
||||
Discount int
|
||||
WeeklyLimit int
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user