427 lines
9.6 KiB
Go
427 lines
9.6 KiB
Go
package playroom
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"server/GoUtil"
|
|
limitedTimeEventCfg "server/conf/limitedTimeEvent"
|
|
playroomCfg "server/conf/playroom"
|
|
"server/game/mod/item"
|
|
"server/msg"
|
|
)
|
|
|
|
type PlayroomMod struct {
|
|
Collect map[int]int // 装饰
|
|
Room map[int]int // 房间
|
|
Status int // 0: 未开始 1: 进行中 2: 结束
|
|
Endtime int64 // 结束时间
|
|
Starttime int64 // 开始时间
|
|
WorkStatus int // 0: 未开始 1: 进行中 2: 结束
|
|
Visitor map[int]*Info // 访客
|
|
MoodInfo map[int]*Mood // 心情
|
|
AllMood int // 总心情
|
|
Reward []*item.Item // 奖励
|
|
DayFirstT int // 每日未首次触发次数
|
|
Trigger int // 未触发次数
|
|
HasVisit map[int]int64 // 今日已拜访的玩家
|
|
Target int // 拜访的目标
|
|
GameId int // 游戏ID
|
|
GameReward map[int]*item.Item // 游戏奖励
|
|
GameStatus int // 游戏状态
|
|
Exclude bool // 是否排除
|
|
LoseItem []*item.Item // 失去的物品
|
|
Chip int // 碎片
|
|
Flip map[int]int // 翻牌
|
|
FlipReward []*item.Item // 翻牌奖励
|
|
WorkOutline int // 是否离线
|
|
}
|
|
|
|
const (
|
|
STATUS_IDLE = 0 // 未开始
|
|
STATUS_VISIT = 1 // 拜访
|
|
|
|
MOOD_TYPE_ENTER = 1 // 娱乐
|
|
MOOD_TYPE_FOOD = 2 // 食物
|
|
MOOD_TYPE_CLEAN = 3 // 清洁
|
|
|
|
GAME_RESULT_LOW = 1 // 低
|
|
GAME_RESULT_MIDDLE = 2 // 中
|
|
GAME_RESULT_HIGH = 3 // 高
|
|
|
|
FLIP_TYPE_COPPER = 1 // 铜
|
|
FLIP_TYPE_SILVER = 2 // 银
|
|
FLIP_TYPE_GOLD = 3 // 金
|
|
)
|
|
|
|
type Mood struct {
|
|
Id int
|
|
Num int
|
|
Time int64
|
|
}
|
|
|
|
type Info struct {
|
|
Time int64
|
|
Times int
|
|
}
|
|
|
|
func (p *PlayroomMod) InitData() {
|
|
if p.Collect == nil {
|
|
p.Collect = make(map[int]int)
|
|
InitCollect := playroomCfg.GetInitDecorate()
|
|
for _, v := range InitCollect {
|
|
p.Collect[v] = 1
|
|
}
|
|
}
|
|
if p.Room == nil {
|
|
p.Room = make(map[int]int)
|
|
}
|
|
if p.Visitor == nil {
|
|
p.Visitor = make(map[int]*Info)
|
|
}
|
|
if p.MoodInfo == nil {
|
|
p.MoodInfo = make(map[int]*Mood)
|
|
}
|
|
if p.Reward == nil {
|
|
p.Reward = make([]*item.Item, 0)
|
|
}
|
|
if p.HasVisit == nil {
|
|
p.HasVisit = make(map[int]int64)
|
|
}
|
|
if p.GameReward == nil {
|
|
p.GameReward = make(map[int]*item.Item)
|
|
}
|
|
if p.LoseItem == nil {
|
|
p.LoseItem = make([]*item.Item, 0)
|
|
}
|
|
if p.Flip == nil {
|
|
p.Flip = make(map[int]int)
|
|
}
|
|
}
|
|
|
|
func (p *PlayroomMod) GetVisitor() map[int]*Info {
|
|
return p.Visitor
|
|
}
|
|
|
|
func (p *PlayroomMod) GetTarget() int {
|
|
return p.Target
|
|
}
|
|
|
|
func (p *PlayroomMod) GetHasVisit() map[int]int64 {
|
|
return p.HasVisit
|
|
}
|
|
|
|
func (p *PlayroomMod) GetMood() map[int]int {
|
|
Mood := make(map[int]int)
|
|
for k, v := range p.MoodInfo {
|
|
Mood[k] = v.Num
|
|
}
|
|
return Mood
|
|
}
|
|
|
|
func (p *PlayroomMod) GetMoodInfo(Id int) *Mood {
|
|
return p.MoodInfo[Id]
|
|
}
|
|
|
|
func (p *PlayroomMod) GetCollect() map[int]int {
|
|
return p.Collect
|
|
}
|
|
|
|
func (p *PlayroomMod) GetRoom() map[int]int {
|
|
return p.Room
|
|
}
|
|
|
|
func (p *PlayroomMod) GetStatus() int {
|
|
return p.Status
|
|
}
|
|
|
|
func (p *PlayroomMod) GetChip() int {
|
|
return p.Chip
|
|
}
|
|
|
|
func (p *PlayroomMod) AddChip() {
|
|
p.Chip = min(p.Chip+1, 5)
|
|
}
|
|
|
|
func (p *PlayroomMod) SetTarget(Target int) {
|
|
p.Target = Target
|
|
p.Status = 1
|
|
p.HasVisit[Target] = GoUtil.Now()
|
|
}
|
|
|
|
func (p *PlayroomMod) SetGameId(GameId int) {
|
|
if p.GameId != 0 {
|
|
return
|
|
}
|
|
p.GameId = GameId
|
|
}
|
|
|
|
func (p *PlayroomMod) CreateOrderReward(Star int, itemMod *item.ItemMod) {
|
|
if Star == 0 {
|
|
return
|
|
}
|
|
p.Reward = make([]*item.Item, 0)
|
|
var Item1, Item2 int
|
|
VisitorItem := playroomCfg.GetVisitorItem()
|
|
if Star < playroomCfg.GetOrderStar() {
|
|
Item1, Item2 = playroomCfg.GetNormalItem()
|
|
} else {
|
|
Item1, Item2 = playroomCfg.GetPremiumItem()
|
|
}
|
|
|
|
Item1Num := itemMod.GetItem(Item1)
|
|
Item2Num := itemMod.GetItem(Item2)
|
|
if p.DayFirstT == 2 {
|
|
p.Reward = append(p.Reward, &item.Item{Id: VisitorItem, Num: 1})
|
|
return
|
|
}
|
|
if p.Trigger == 4 {
|
|
p.Reward = append(p.Reward, &item.Item{Id: VisitorItem, Num: 1})
|
|
p.Trigger = 0
|
|
return
|
|
}
|
|
if Item1Num == 0 && Item2Num == 0 {
|
|
Prob := GoUtil.RandSlice([]int{Item1, Item2})
|
|
p.Reward = append(p.Reward, &item.Item{Id: Prob, Num: 1})
|
|
p.DayFirstT++
|
|
p.Trigger++
|
|
return
|
|
}
|
|
if math.Abs(float64(Item1Num-Item2Num)) > 3 {
|
|
RI := GoUtil.IfTrue(Item1Num > Item2Num, Item2, Item1).(int)
|
|
p.Reward = append(p.Reward, &item.Item{Id: RI, Num: 1})
|
|
p.DayFirstT++
|
|
p.Trigger++
|
|
return
|
|
}
|
|
var RandSlice []int
|
|
if Star < playroomCfg.GetOrderStar() {
|
|
RandSlice = []int{Item1, Item2}
|
|
} else {
|
|
RandSlice = []int{Item1, Item2, VisitorItem}
|
|
}
|
|
Prob := GoUtil.RandSlice(RandSlice)
|
|
p.Reward = append(p.Reward, &item.Item{Id: Prob, Num: 1})
|
|
if Prob == VisitorItem {
|
|
p.DayFirstT = 3
|
|
p.Trigger = 0
|
|
} else {
|
|
p.DayFirstT++
|
|
p.Trigger++
|
|
}
|
|
}
|
|
|
|
func (p *PlayroomMod) GetReward() []*item.Item {
|
|
return p.Reward
|
|
}
|
|
|
|
func (p *PlayroomMod) Interact(Id, Type int) ([]*item.Item, int, error) {
|
|
MoodType, ItemList, Effect := playroomCfg.GetInteract(Id, Type)
|
|
if MoodType == 0 {
|
|
return nil, 0, fmt.Errorf("Interact MoodType is 0")
|
|
}
|
|
if Effect > 0 {
|
|
p.AllMood = min(100, p.AllMood+10)
|
|
}
|
|
p.AddMood(MoodType, Effect)
|
|
return ItemList, MoodType, nil
|
|
}
|
|
|
|
func (p *PlayroomMod) AddMood(Id, Num int) {
|
|
_, ok := p.MoodInfo[Id]
|
|
if !ok {
|
|
p.MoodInfo[Id] = &Mood{Id: Id, Num: 0}
|
|
}
|
|
p.MoodInfo[Id].Num = max(0, min(p.MoodInfo[Id].Num+Num, 100))
|
|
if p.MoodInfo[Id].Num != 0 && p.MoodInfo[Id].Time == 0 {
|
|
p.MoodInfo[Id].Time = GoUtil.Now()
|
|
}
|
|
if p.MoodInfo[Id].Num == 0 {
|
|
p.MoodInfo[Id].Time = 0
|
|
}
|
|
}
|
|
|
|
func (p *PlayroomMod) AddVisitor(Id int, Time int64) {
|
|
v, ok := p.Visitor[Id]
|
|
if !ok {
|
|
p.Visitor[Id] = &Info{Time: Time, Times: 1}
|
|
return
|
|
}
|
|
v.Times++
|
|
v.Time = Time
|
|
}
|
|
|
|
func (p *PlayroomMod) SetRoom(Room map[int]int) error {
|
|
p.Room = Room
|
|
return nil
|
|
}
|
|
|
|
func (p *PlayroomMod) AddCollect(Id int) {
|
|
p.Collect[Id]++
|
|
}
|
|
|
|
func (p *PlayroomMod) ResetGame() {
|
|
p.Target = 0
|
|
p.Status = 0
|
|
p.GameId = 0
|
|
p.GameReward = make(map[int]*item.Item)
|
|
}
|
|
|
|
func (p *PlayroomMod) ResetLose() {
|
|
p.LoseItem = make([]*item.Item, 0)
|
|
}
|
|
|
|
func (p *PlayroomMod) SetGameReward(Chess1, Chess2, Star int) {
|
|
p.GameReward[1] = &item.Item{Id: Chess1, Num: 1}
|
|
p.GameReward[2] = &item.Item{Id: Chess2, Num: 1}
|
|
p.GameReward[3] = &item.Item{Id: item.ITEM_STAR_ID, Num: Star}
|
|
}
|
|
|
|
func (p *PlayroomMod) SetGameRewardFlip(N1, N2, N3 int) {
|
|
p.GameReward[1] = &item.Item{Id: item.ITEM_STAR_ID, Num: N1}
|
|
p.GameReward[2] = &item.Item{Id: item.ITEM_STAR_ID, Num: N2}
|
|
p.GameReward[3] = &item.Item{Id: item.ITEM_STAR_ID, Num: N3}
|
|
}
|
|
|
|
func (p *PlayroomMod) SelectReward(Id int) []*item.Item {
|
|
v, ok := p.GameReward[Id]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return []*item.Item{v}
|
|
}
|
|
|
|
func (p *PlayroomMod) Lose(Item []*item.Item) {
|
|
p.LoseItem = append(p.LoseItem, Item...)
|
|
}
|
|
|
|
func (p *PlayroomMod) Work() ([]*item.Item, error) {
|
|
if p.Endtime > GoUtil.Now() {
|
|
p.WorkStatus = 1
|
|
return nil, nil
|
|
}
|
|
p.Starttime = GoUtil.Now()
|
|
p.Endtime = GoUtil.Now() + 86400
|
|
p.WorkStatus = 1
|
|
ItemId := playroomCfg.GetWorkItem()
|
|
return []*item.Item{item.NewItem(ItemId, 1)}, nil
|
|
}
|
|
|
|
func (p *PlayroomMod) Rest() {
|
|
p.WorkStatus = 2
|
|
}
|
|
|
|
func (p *PlayroomMod) SetWorkOutline(Status int) {
|
|
p.WorkOutline = Status
|
|
}
|
|
|
|
func (p *PlayroomMod) ResetWork() {
|
|
p.WorkStatus = 0
|
|
p.Endtime = 0
|
|
}
|
|
|
|
func (p *PlayroomMod) Outline() {
|
|
p.WorkOutline = 1
|
|
}
|
|
|
|
func (p *PlayroomMod) GetVisitorInfo(Id int) (int, int64) {
|
|
v, ok := p.Visitor[Id]
|
|
if !ok {
|
|
return 0, 0
|
|
}
|
|
return v.Times, v.Time
|
|
}
|
|
func (p *PlayroomMod) Draw() (int, []*item.Item, error) {
|
|
if p.AllMood < 100 {
|
|
return 0, nil, fmt.Errorf("Draw AllMood < 100")
|
|
}
|
|
p.AllMood = 0
|
|
ProbList := limitedTimeEventCfg.GetSenceJackpotProb()
|
|
Id := GoUtil.RandMap(ProbList)
|
|
return Id, limitedTimeEventCfg.GetSenceJackpotReward(Id), nil
|
|
}
|
|
|
|
func (p *PlayroomMod) NotifyWork() *msg.NotifyPlayroomWork {
|
|
return &msg.NotifyPlayroomWork{
|
|
WorkStatus: int32(p.WorkStatus),
|
|
StartTime: int32(p.Starttime),
|
|
}
|
|
}
|
|
|
|
func (p *PlayroomMod) NotifyLose() *msg.NotifyPlayroomLose {
|
|
return &msg.NotifyPlayroomLose{
|
|
LoseItem: item.ItemToMsg(p.LoseItem),
|
|
Chip: int32(p.Chip),
|
|
}
|
|
}
|
|
|
|
func (p *PlayroomMod) NotifyStatus() *msg.NofiPlayroomStatus {
|
|
return &msg.NofiPlayroomStatus{
|
|
WorkOutline: int32(p.WorkOutline),
|
|
}
|
|
}
|
|
|
|
func (p *PlayroomMod) NotifyMood() *msg.NotifyPlayroomMood {
|
|
Mood := make(map[int32]int32, 0)
|
|
for k, v := range p.MoodInfo {
|
|
Mood[int32(k)] = int32(v.Num)
|
|
}
|
|
return &msg.NotifyPlayroomMood{
|
|
AllMood: int32(p.AllMood),
|
|
Mood: Mood,
|
|
}
|
|
}
|
|
|
|
func (p *PlayroomMod) Fire(ChargeId int) []*item.Item {
|
|
WorkChargeId := playroomCfg.GetWorkChargeId()
|
|
if ChargeId == WorkChargeId {
|
|
ItemId := playroomCfg.GetWorkItem()
|
|
return []*item.Item{item.NewItem(ItemId, 1)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *PlayroomMod) RemoveChip(Num int) []*item.Item {
|
|
Num = min(Num, p.Chip)
|
|
p.Chip -= Num
|
|
return []*item.Item{item.NewItem(item.ITEM_STAR_ID, Num*50)}
|
|
}
|
|
|
|
func (p *PlayroomMod) FlipCard(Pos int) (int, error) {
|
|
if p.Status != STATUS_VISIT {
|
|
return 0, fmt.Errorf("FlipCard Status is not STATUS_VISIT")
|
|
}
|
|
RandMap := map[int]int{
|
|
FLIP_TYPE_COPPER: 35,
|
|
FLIP_TYPE_SILVER: 45,
|
|
FLIP_TYPE_GOLD: 20,
|
|
}
|
|
Prob := GoUtil.RandMap(RandMap)
|
|
p.Flip[Pos] = Prob
|
|
|
|
return Prob, nil
|
|
}
|
|
|
|
func (p *PlayroomMod) GetFlipReward() ([]*item.Item, error) {
|
|
check := make(map[int]int)
|
|
Items := make([]*item.Item, 0)
|
|
for _, v := range p.Flip {
|
|
check[v]++
|
|
if check[v] == 3 {
|
|
switch v {
|
|
case FLIP_TYPE_COPPER:
|
|
Items = append(Items, p.GameReward[FLIP_TYPE_COPPER])
|
|
case FLIP_TYPE_SILVER:
|
|
Items = append(Items, p.GameReward[FLIP_TYPE_SILVER])
|
|
case FLIP_TYPE_GOLD:
|
|
Items = append(Items, p.GameReward[FLIP_TYPE_GOLD])
|
|
}
|
|
p.Status = STATUS_IDLE
|
|
p.GameId = 0
|
|
p.Flip = make(map[int]int)
|
|
p.Target = 0
|
|
return Items, nil
|
|
}
|
|
}
|
|
return Items, fmt.Errorf("GetFlipReward check is not 3")
|
|
}
|