赛跑活动
This commit is contained in:
parent
534d00a975
commit
71eafdecb0
@ -3,6 +3,7 @@ package randnameCfg
|
||||
import (
|
||||
"server/GoUtil"
|
||||
"server/gamedata"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -22,3 +23,28 @@ func GetRandName() string {
|
||||
}
|
||||
return gamedata.GetStringValue(v, "EnName")
|
||||
}
|
||||
|
||||
func GetRandNames(n int) []string {
|
||||
rs := make([]string, n)
|
||||
data, err := gamedata.GetData(CFG_RAND_NAME)
|
||||
if err != nil {
|
||||
for i := 0; i < n; i++ {
|
||||
id := strconv.Itoa(i + 1)
|
||||
rs[i] = "Lily" + id
|
||||
}
|
||||
}
|
||||
all := make([]int, len(data))
|
||||
for k := range data {
|
||||
ik := GoUtil.Int(k)
|
||||
all = append(all, ik)
|
||||
}
|
||||
ids := GoUtil.RandSliceNumNonAdjacent(all, n)
|
||||
for _, v := range ids {
|
||||
v, err := gamedata.GetDataByIntKey(CFG_RAND_NAME, v)
|
||||
if err != nil {
|
||||
rs = append(rs, "Lucy")
|
||||
}
|
||||
rs = append(rs, gamedata.GetStringValue(v, "EnName"))
|
||||
}
|
||||
return rs
|
||||
}
|
||||
|
||||
@ -190,7 +190,9 @@ func RaceBackData(p *Player) {
|
||||
for _, v := range RaceMod.Opponent {
|
||||
Opponent = append(Opponent, &msg.Raceopponent{
|
||||
Id: int32(v.Id),
|
||||
Image: int32(v.Image),
|
||||
Name: v.Name,
|
||||
Face: int32(v.Face),
|
||||
Avatar: int32(v.Avatar),
|
||||
Progress: int32(v.Progress),
|
||||
})
|
||||
}
|
||||
|
||||
@ -156,8 +156,9 @@ func (p *PlayerChessData) HandleChess(player *Player, handle_list []*msg.ChessHa
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Type := mergeDataCfg.GetTypeById(ChessId)
|
||||
AddChessList = append(AddChessList, ChessId)
|
||||
if !GoUtil.InArray(EmitId, []int{561, 562, 563, 564, 701, 702, 703, 704, 705, 706, 0}) { // 宝箱生成的棋子不扣体力
|
||||
if !GoUtil.InArray(EmitId, []int{561, 562, 563, 564, 701, 702, 703, 704, 705, 706, 0}) && Type != "Resource" { // 宝箱生成的棋子不扣体力
|
||||
addChessCostEnergy++
|
||||
}
|
||||
|
||||
|
||||
@ -812,7 +812,8 @@ func ReqChessEx(player *Player, buf []byte) error {
|
||||
})
|
||||
return err
|
||||
}
|
||||
if req.Type == 4 {
|
||||
// 限时事件气泡 幸运猫
|
||||
if req.Type == msg.CHESS_EX_TYPE_CHESS_EX_EVENT {
|
||||
LimitedTimeEventMod := player.PlayMod.getLimitedTimeEventMod()
|
||||
err := LimitedTimeEventMod.LuckyCat(int(req.NewChessId))
|
||||
if err != nil {
|
||||
@ -826,6 +827,7 @@ func ReqChessEx(player *Player, buf []byte) error {
|
||||
"req": int(req.NewChessId),
|
||||
})
|
||||
}
|
||||
|
||||
player.PlayMod.save()
|
||||
player.PushClientRes(ChessMod.BackData())
|
||||
player.PushClientRes(&msg.ResChessEx{
|
||||
|
||||
@ -221,6 +221,8 @@ func (cb *ChessBorad) SellChess(id int) ([]*item.Item, error) {
|
||||
items = append(items, &item.Item{Id: item.ITEM_DIAMOND_ID, Num: CfgRecord.SellNum})
|
||||
case "energy":
|
||||
items = append(items, &item.Item{Id: item.ITEM_ENERGY_ID, Num: CfgRecord.SellNum})
|
||||
case "Racing Battery":
|
||||
items = append(items, &item.Item{Id: item.ITEM_RACING_BATTERY_ID, Num: CfgRecord.SellNum})
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ const (
|
||||
ITEM_STAR_ID = 100002
|
||||
ITEM_DIAMOND_ID = 100003
|
||||
ITEM_FIVE_STAR_CARD_PACK = 100008
|
||||
ITEM_RACING_BATTERY_ID = 100027
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@ -2,8 +2,10 @@ package race
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"server/GoUtil"
|
||||
raceCfg "server/conf/race"
|
||||
randnameCfg "server/conf/randname"
|
||||
"server/game/mod/item"
|
||||
)
|
||||
|
||||
@ -19,8 +21,9 @@ type RaceMod struct {
|
||||
|
||||
type Opponent struct {
|
||||
Id int
|
||||
Type int
|
||||
Image int
|
||||
Avatar int
|
||||
Face int
|
||||
Name string
|
||||
Progress int
|
||||
}
|
||||
|
||||
@ -51,17 +54,14 @@ func (r *RaceMod) StartGame() error {
|
||||
if r.StartTime != 0 {
|
||||
return fmt.Errorf("the game has started")
|
||||
}
|
||||
MaxPass := raceCfg.GetMaxPass(r.Id)
|
||||
if r.Rank != 1 || r.Pass > MaxPass {
|
||||
r.Pass = 1
|
||||
}
|
||||
r.Rank = 0
|
||||
r.StartTime = GoUtil.Now()
|
||||
Opponent := make([]*Opponent, 0)
|
||||
OpponentNum := raceCfg.GetRaceNum(r.Pass)
|
||||
for i := 1; i < OpponentNum; i++ {
|
||||
Opponent = append(Opponent, randOpponent(i))
|
||||
names := randnameCfg.GetRandNames(OpponentNum)
|
||||
for i := 0; i < OpponentNum; i++ {
|
||||
Opponent = append(Opponent, randOpponent(i, names[i]))
|
||||
}
|
||||
r.EndTime = r.StartTime + int64(raceCfg.GetCD(r.Id))
|
||||
r.Opponent = Opponent
|
||||
return nil
|
||||
}
|
||||
@ -71,35 +71,24 @@ func (r *RaceMod) AddCoin(Num int) {
|
||||
return
|
||||
}
|
||||
r.Progress += Num
|
||||
Need := raceCfg.GetRaceNeed(r.Pass)
|
||||
if r.Progress >= Need && r.Rank == 0 {
|
||||
r.EndTime = GoUtil.Now()
|
||||
Rank := 1
|
||||
for _, v := range r.Opponent {
|
||||
if v.Progress >= r.Progress {
|
||||
Rank++
|
||||
}
|
||||
}
|
||||
r.Rank = Rank
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RaceMod) GetReward() ([]*item.Item, error) {
|
||||
if r.EndTime == 0 {
|
||||
return nil, fmt.Errorf("the game is not over")
|
||||
}
|
||||
|
||||
if r.Rank != 1 {
|
||||
return nil, fmt.Errorf("you are not the first")
|
||||
Need := raceCfg.GetRaceNeed(r.Pass)
|
||||
if r.Progress < Need {
|
||||
return nil, fmt.Errorf("not enough progress")
|
||||
}
|
||||
Cd := raceCfg.GetCD(r.Id)
|
||||
if r.Rank != 1 {
|
||||
return nil, fmt.Errorf("you are not the first")
|
||||
}
|
||||
Items := make([]*item.Item, 0)
|
||||
Reward := raceCfg.GetReward(r.Id)
|
||||
Items = append(Items, Reward...)
|
||||
if r.EndTime-r.StartTime < int64(Cd) {
|
||||
Now := GoUtil.Now()
|
||||
if Now <= r.EndTime {
|
||||
ExtraReward := raceCfg.GetExtraReward(r.Id)
|
||||
Items = append(Items, ExtraReward...)
|
||||
}
|
||||
@ -110,15 +99,16 @@ func (r *RaceMod) GetReward() ([]*item.Item, error) {
|
||||
}
|
||||
r.StartTime = 0
|
||||
r.EndTime = 0
|
||||
r.Progress = 0
|
||||
r.Progress -= Need
|
||||
r.Opponent = nil
|
||||
return Items, nil
|
||||
}
|
||||
|
||||
func randOpponent(Id int) *Opponent {
|
||||
func randOpponent(Id int, name string) *Opponent {
|
||||
return &Opponent{
|
||||
Id: Id,
|
||||
Type: GoUtil.RandNum(1, 3),
|
||||
Image: GoUtil.RandNum(1, 3),
|
||||
Id: Id,
|
||||
Name: name,
|
||||
Face: rand.Intn(10),
|
||||
Avatar: rand.Intn(10),
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user