tablesink_cmd.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. package gamelogic
  2. import (
  3. "bet24.com/servers/common"
  4. "bet24.com/servers/games/fish/bullet"
  5. _ "bet24.com/servers/games/fish/config"
  6. "bet24.com/servers/games/fish/fish"
  7. "bet24.com/servers/games/fish/fishcommon"
  8. item "bet24.com/servers/micros/item_inventory/proto"
  9. "bet24.com/servers/user"
  10. "bet24.com/utils"
  11. "encoding/json"
  12. "fmt"
  13. "math/rand"
  14. )
  15. func (ts *tablesink) OnGameMessage(userIndex int32, cmd, data string) bool {
  16. usr := ts.table.GetPlayer(userIndex)
  17. if usr == nil {
  18. ts.table.LogWithTableId("tablesink.OnGameMessage,usr[%d] not exist", userIndex)
  19. return false
  20. }
  21. chairId := usr.GetUserChairId()
  22. if !fishcommon.IsValidChair(chairId) {
  23. ts.table.LogWithTableId("tablesink.OnGameMessage invalid chair %d", chairId)
  24. return false
  25. }
  26. defer utils.TimeCost(fmt.Sprintf("tablesink.OnGameMessage[%s]", cmd))()
  27. switch cmd {
  28. case fishcommon.ADD_BULLET:
  29. ts.addBullet(usr, cmd, data, chairId)
  30. case fishcommon.CATCH_FISH:
  31. ts.catchFish(usr, cmd, data, chairId)
  32. case fishcommon.SET_BULLET:
  33. ts.setBullet(usr, cmd, data)
  34. case fishcommon.SET_CANNON:
  35. ts.setCannon(usr, cmd, data)
  36. case fishcommon.USE_ITEM:
  37. ts.useItem(usr, cmd, data)
  38. case fishcommon.GAME_SCENE:
  39. //ts.table.NotifySceneChanged(chairId)
  40. gameScene := ts.getChairScene()
  41. ts.table.SendGameData(userIndex, fishcommon.GAME_SCENE, gameScene)
  42. // 如果鱼群来了
  43. if ts.groupState {
  44. ts.sendGroup(userIndex, false)
  45. }
  46. case fishcommon.SPECIAL_CATCH:
  47. ts.specialCatch(usr, cmd, data)
  48. case fishcommon.SPECIAL_CATCH_END:
  49. ts.specialCatchEnd(usr, cmd, data)
  50. case fishcommon.SPECIAL_SHOOT:
  51. ts.specialShoot(usr, cmd, data)
  52. case fishcommon.UPGRADE_BULLET:
  53. ts.upgradeBullet(usr, cmd, data)
  54. default:
  55. ts.table.LogWithTableId("tablesink.HandleCmd usr(%d),unhandled cmd(%v:%v) ", usr.GetUserId(), cmd, data)
  56. return false
  57. }
  58. return false
  59. }
  60. func (ts *tablesink) addBullet(usr *user.UserInfo, cmd, data string, chairID int) {
  61. var add fishcommon.AddBullet
  62. err := json.Unmarshal([]byte(data), &add)
  63. if err != nil {
  64. ts.table.LogWithTableId("tablesink.addBullet failed %v", data)
  65. return
  66. }
  67. blt := bullet.GetBullet(add.BulletID)
  68. if blt == nil {
  69. ts.table.LogWithTableId("tablesink.addBullet invalid bulletID %d", add.BulletID)
  70. return
  71. }
  72. // 检查金币是否足够
  73. //if !usr.ModifyGold(-bullet.Odds) {
  74. if !ts.checkGold(usr, blt.Odds, chairID) {
  75. ts.table.LogWithTableId("tablesink.addBullet not enough gold")
  76. ts.sendBulletFailed(usr, add.ClientID, "not enough gold", add.BulletID)
  77. return
  78. }
  79. b := ts.bulletmgr.addBullet(usr.GetUserId(), add.BulletID, add.Angle, add.FishKey, chairID, blt.Odds)
  80. b.ClientID = add.ClientID
  81. ts.broadcastBullet(b)
  82. }
  83. func (ts *tablesink) checkGold(usr *user.UserInfo, bulletOdds int, chairID int) bool {
  84. // 总金币
  85. gold := usr.GetUserGold()
  86. flyingBullet := 0 //ts.bulletmgr.getFlyingBullet(usr.GetUserId())
  87. if flyingBullet+bulletOdds > gold {
  88. ts.table.LogWithTableId("tablesink.checkGold flyingBullet(%d) + bulletOdds(%d) > gold(%d)", flyingBullet, bulletOdds, gold)
  89. return false
  90. }
  91. return true
  92. }
  93. func (ts *tablesink) sendBulletFailed(usr *user.UserInfo, clientID int, msg string, bulledID int) {
  94. data := fmt.Sprintf(`{"ClientID":%d,"Msg":"%v","BulletID":%d}`, clientID, msg, bulledID)
  95. ts.table.SendGameData(usr.GetUserIndex(), fishcommon.BULLET_FAILED, data)
  96. }
  97. func (ts *tablesink) sendBullet(userIndex int32, bullet *bullet.Bullet) {
  98. msg := fishcommon.ADD_BULLET
  99. data, _ := json.Marshal(bullet)
  100. msgData := string(data)
  101. ts.table.SendGameData(userIndex, msg, msgData)
  102. }
  103. func (ts *tablesink) broadcastBullet(bullet *bullet.Bullet) {
  104. ts.sendBullet(-1, bullet)
  105. }
  106. func (ts *tablesink) broadcastData(msg, data string) {
  107. ts.table.SendGameData(-1, msg, data)
  108. }
  109. func (ts *tablesink) sendFish(userIndex int32, fish *fish.Fish) {
  110. msg := fishcommon.ADD_FISH
  111. data, _ := json.Marshal(fish)
  112. ts.table.SendGameData(userIndex, msg, string(data))
  113. }
  114. func (ts *tablesink) broadcastFish(fish *fish.Fish) {
  115. ts.sendFish(-1, fish)
  116. }
  117. func (ts *tablesink) getRoomUser(userId int) *fishuser {
  118. for _, v := range ts.Users {
  119. if v == nil {
  120. continue
  121. }
  122. if v.userId == userId {
  123. return v
  124. }
  125. }
  126. return nil
  127. }
  128. func (ts *tablesink) onCatchFish(fi *fish.FishInfo, earn int, userName string) {
  129. if fi.BonusFish == 0 {
  130. return
  131. }
  132. if earn <= 0 {
  133. return
  134. }
  135. //msg := fmt.Sprintf("[%s]在<color=#ff0000>[%s]</color>捕获了[%s],获得了金币<color=#ff0000>[%d]</color>", userName, config.Room.RoomDesc, fi.Name, earn)
  136. //coreservice.SendBroadcast(-1, fishcommon.GAMEID, 0, msg, "")
  137. }
  138. func (ts *tablesink) catchFish(usr *user.UserInfo, cmd, data string, chairID int) {
  139. var catch fishcommon.CatchFish
  140. fishUser := ts.getRoomUser(usr.GetUserId())
  141. if fishUser == nil {
  142. ts.table.LogWithTableId("tablesink.catchFish failed fishUser[%d,%d] not found", usr.GetUserId(), chairID)
  143. return
  144. }
  145. err := json.Unmarshal([]byte(data), &catch)
  146. if err != nil {
  147. ts.table.LogWithTableId("tablesink.catchFish failed %v", data)
  148. return
  149. }
  150. // 查询下bullet和fish
  151. bullet := ts.bulletmgr.getBullet(catch.BulletKey)
  152. if bullet == nil || bullet.UserID != usr.GetUserId() {
  153. ts.table.LogWithTableId("tablesink.catchFish failed bullet not found")
  154. ts.sendCatchFailed(usr, catch, 0, false)
  155. return
  156. }
  157. f := ts.fishmgr.getFish(catch.FishKey)
  158. if f == nil || f.IsDead() {
  159. ts.table.LogWithTableId("tablesink.catchFish failed fish not found or dead %d", catch.FishKey)
  160. //ts.fishmgr.dump()
  161. ts.sendCatchFailed(usr, catch, bullet.BulletID, false)
  162. return
  163. }
  164. fi := fish.GetFishInfo(f.FishID)
  165. if fi == nil {
  166. ts.table.LogWithTableId("catshFish fishID[%d] invalid", f.FishID)
  167. return
  168. }
  169. ok := ts.writeUserGold(usr, fishUser, -bullet.GetOdds())
  170. if !ok {
  171. ts.table.LogWithTableId("tablesink.catchFish failed insufficient balance")
  172. //ts.fishmgr.dump()
  173. ts.sendCatchFailed(usr, catch, bullet.BulletID, false)
  174. return
  175. }
  176. fishUser.setWaterPoolValue(-bullet.GetOdds(), bullet.GetOdds())
  177. // 添加奖池
  178. if ts.prizePool != nil {
  179. ts.sendPoolValue()
  180. }
  181. var ret fishcommon.CatchFishRet
  182. ret.CatchFish = catch
  183. ret.BulletID = bullet.BulletID
  184. ret.UserId = usr.GetUserId()
  185. ret.IsCatch = f.IsCatch(fishUser.getUserOdds(), ts.systemOdds, ts.roomInfo.OddsExtra)
  186. if ret.IsCatch {
  187. f.Status = fish.Fish_Dead
  188. ret.Coin = bullet.GetOdds() * f.GetOdds()
  189. ts.onCatchFish(fi, ret.Coin, usr.GetUserNickName())
  190. // 是否产生道具
  191. ret.ItemId, ret.ItemCount = ts.fishDrop.getDropItem(f.FishID)
  192. if ret.ItemCount > 0 {
  193. var items []item.ItemPack
  194. items = append(items, item.ItemPack{ItemId: ret.ItemId, Count: ret.ItemCount})
  195. item.AddItems(usr.GetUserId(), items, "捕鱼掉落", common.LOGTYPE_FISH_DROP)
  196. }
  197. // 转盘鱼
  198. ret.PrizeWheelItemId, ret.PrizeWheelItemCount = f.GetPrize()
  199. if ret.PrizeWheelItemCount > 0 {
  200. var items []item.ItemPack
  201. items = append(items, item.ItemPack{ItemId: ret.PrizeWheelItemId, Count: ret.PrizeWheelItemCount})
  202. item.AddItems(usr.GetUserId(), items, "捕鱼转盘", common.LOGTYPE_FISH_DROP)
  203. }
  204. if fi.SpecialType > 0 {
  205. ts.table.LogWithTableId("catchFish 击中特效鱼 %v", fi)
  206. // 如果是slot
  207. if fi.SpecialEffect == item.SpecialEffect_Slot {
  208. ret.SlotMultiple = fi.Param1 + rand.Intn(fi.Param2-fi.Param1)
  209. ret.Coin += bullet.GetOdds() * ret.SlotMultiple
  210. ts.table.LogWithTableId("catchFish 击中Slot鱼 产生倍数 %d", ret.SlotMultiple)
  211. } else {
  212. ts.Users[chairID].addSpecial(f.FishKey, bullet.GetOdds(), fi.SpecialEffect, fi.SpecialType, fi.Param1, fi.Param2)
  213. }
  214. } else {
  215. ts.table.LogWithTableId("catchFish 击中普通鱼 %v", fi)
  216. }
  217. ts.broadcastCatch(ret, false)
  218. // 是否产生奖池
  219. if ts.prizePool != nil && fi.BonusFish > 0 {
  220. var draw fishcommon.PrizePoolDraw_resp
  221. draw.UserId = usr.GetUserId()
  222. draw.Bingo, draw.Point, draw.Pool = ts.prizePool.Draw(ret.UserId, bullet.GetOdds())
  223. if draw.Bingo {
  224. // 写分
  225. ts.writeUserGold(usr, fishUser, draw.Point)
  226. fishUser.setWaterPoolValue(draw.Point, 0)
  227. }
  228. ts.broadcastPoolDraw(draw)
  229. ts.sendPoolEnergy(ret.UserId)
  230. }
  231. } else {
  232. ts.sendCatch(usr.GetUserIndex(), ret, false)
  233. }
  234. // ts.table.LogWithTableId("catchFish UserID[%d],BulletOdds[%d],Win[%d],FishID[%d]", ret.UserId, bullet.GetOdds(), ret.Coin, catch.FishKey)
  235. // 写分
  236. ts.writeUserGold(usr, fishUser, ret.Coin)
  237. fishUser.setWaterPoolValue(ret.Coin, 0)
  238. // 加入纪录
  239. ts.recordmgr.addUserRecord(ret.UserId, f.FishID, bullet.GetOdds(), ret.Coin)
  240. // 删除子弹
  241. ts.bulletmgr.removeBullet(catch.BulletKey)
  242. }
  243. func (ts *tablesink) sendConfig(userIndex int32) {
  244. ts.table.SendGameData(userIndex, fishcommon.CONFIG_BULLET, bullet.GetConfig())
  245. ts.table.SendGameData(userIndex, fishcommon.CONFIG_FISH, fish.GetFishConfig())
  246. }
  247. func (ts *tablesink) broadcastCatch(catch fishcommon.CatchFishRet, isSpecial bool) {
  248. ts.sendCatch(-1, catch, isSpecial)
  249. }
  250. func (ts *tablesink) sendCatch(userIndex int32, catch fishcommon.CatchFishRet, isSpecial bool) {
  251. msg := fishcommon.CATCH_FISH
  252. if isSpecial {
  253. msg = fishcommon.SPECIAL_CATCH
  254. }
  255. data, _ := json.Marshal(catch)
  256. msgData := string(data)
  257. ts.table.SendGameData(userIndex, msg, msgData)
  258. }
  259. func (ts *tablesink) sendCatchFailed(usr *user.UserInfo, catch fishcommon.CatchFish, bulletID int, isSpecial bool) {
  260. msg := fishcommon.CATCH_FAILED
  261. if isSpecial {
  262. msg = fishcommon.SPECIAL_CATCH
  263. }
  264. var f fishcommon.CatchFishFailed
  265. f.CatchFish = catch
  266. f.BulletID = bulletID
  267. data, _ := json.Marshal(f)
  268. msgData := string(data)
  269. ts.table.SendGameData(usr.GetUserIndex(), msg, msgData)
  270. }
  271. func (ts *tablesink) setBullet(usr *user.UserInfo, cmd, data string) {
  272. var bulletID fishcommon.SetBullet
  273. err := json.Unmarshal([]byte(data), &bulletID)
  274. if err != nil {
  275. ts.table.LogWithTableId("tablesink.setBullet failed %v", data)
  276. return
  277. }
  278. fishUser := ts.getRoomUser(usr.GetUserId())
  279. if fishUser == nil {
  280. return
  281. }
  282. if fishUser.setBullet(bulletID.BulletID) {
  283. // 广播玩家信息
  284. ts.broadCastUserInfo(usr)
  285. }
  286. }
  287. func (ts *tablesink) setCannon(usr *user.UserInfo, cmd, data string) {
  288. var cannon fishcommon.SetCannon
  289. err := json.Unmarshal([]byte(data), &cannon)
  290. if err != nil {
  291. ts.table.LogWithTableId("tablesink.setCannon failed %v", data)
  292. return
  293. }
  294. fishUser := ts.getRoomUser(usr.GetUserId())
  295. if fishUser == nil {
  296. return
  297. }
  298. if fishUser.setCannon(cannon.Cannon, true) {
  299. // 广播玩家信息
  300. ts.broadCastUserInfo(usr)
  301. } else {
  302. ts.table.SendGameData(usr.GetUserIndex(), cmd, "setCannon failed")
  303. }
  304. }
  305. func (ts *tablesink) useItem(usr *user.UserInfo, cmd, data string) {
  306. var itm fishcommon.UseItem
  307. err := json.Unmarshal([]byte(data), &itm)
  308. if err != nil {
  309. ts.table.LogWithTableId("tablesink.useItem failed %v", data)
  310. return
  311. }
  312. roomUser := ts.getRoomUser(usr.GetUserId())
  313. if roomUser == nil {
  314. ts.table.LogWithTableId("tablesink.useItem roomUser not found %d", usr.GetUserId())
  315. return
  316. }
  317. bl := bullet.GetBullet(roomUser.getBulletId())
  318. bulletOdds := ts.roomInfo.BulletMin
  319. if bl != nil {
  320. bulletOdds = bl.Odds
  321. }
  322. itm.UserId = usr.GetUserId()
  323. succeeded, _ := item.Consume(itm.UserId, itm.ItemId, 0, 1, 0)
  324. if !succeeded {
  325. // user类已经广播过失败的消息了
  326. return
  327. }
  328. //coreservice.DoTaskAction(itm.UserId, task.TaskAction_user_item, 1)
  329. // 广播玩家信息
  330. ts.broadCastUseItem(itm)
  331. extra := item.GetItemEffect(itm.ItemId) // 特殊道具后面处理
  332. effectType := extra.SpecialType
  333. specialEffect := extra.SpecialEffect
  334. if specialEffect > 0 {
  335. // 如果是冰冻效果
  336. if specialEffect == item.SpecialEffect_Frozen {
  337. ts.addEffecting(specialEffect, extra.Param1)
  338. // 延长所有鱼的生命
  339. ts.fishmgr.addExtraLife(extra.Param1)
  340. } else {
  341. // 如果是激光道具
  342. roomUser.addSpecial(itm.ItemId, bulletOdds, specialEffect, effectType, extra.Param1, extra.Param2)
  343. }
  344. }
  345. }
  346. func (ts *tablesink) specialCatch(usr *user.UserInfo, cmd, data string) {
  347. var sc fishcommon.SpecialCatch
  348. err := json.Unmarshal([]byte(data), &sc)
  349. if err != nil {
  350. ts.table.LogWithTableId("tablesink.specialCatch failed %v", data)
  351. return
  352. }
  353. roomUser := ts.getRoomUser(usr.GetUserId())
  354. if roomUser == nil {
  355. ts.table.LogWithTableId("tablesink.specialCatch roomUser not found %d", usr.GetUserId())
  356. return
  357. }
  358. for _, v := range sc.TargetFishKeys {
  359. catch := fishcommon.CatchFish{BulletKey: 0, FishKey: v}
  360. f := ts.fishmgr.getFish(v)
  361. if f == nil || f.IsDead() {
  362. ts.table.LogWithTableId("tablesink.specialCatch failed fish not found or dead %d", v)
  363. ts.sendCatchFailed(usr, catch, 0, true)
  364. continue
  365. }
  366. fi := fish.GetFishInfo(f.FishID)
  367. if fi == nil {
  368. ts.table.LogWithTableId("catshFish fishID[%d] invalid", f.FishID)
  369. continue
  370. }
  371. bulletOdds, power := roomUser.useSpecial(sc.OriginFishKey)
  372. if power == 0 {
  373. ts.table.LogWithTableId("specialCatch no power")
  374. // roomUser.removeSpecial(sc.OriginFishKey)
  375. return
  376. }
  377. // 计算是否捕获
  378. var ret fishcommon.CatchFishRet
  379. ret.CatchFish = catch
  380. ret.BulletID = 0
  381. ret.UserId = usr.GetUserId()
  382. isCatch := false
  383. for i := 0; i < power; i++ {
  384. isCatch = f.IsCatch(roomUser.getUserOdds(), ts.systemOdds, ts.roomInfo.OddsExtra)
  385. if isCatch {
  386. break
  387. }
  388. }
  389. ret.IsCatch = isCatch
  390. if !ret.IsCatch {
  391. ts.sendCatch(usr.GetUserIndex(), ret, true)
  392. continue
  393. }
  394. f.Status = fish.Fish_Dead
  395. ret.Coin = bulletOdds * f.GetOdds()
  396. ts.onCatchFish(fi, ret.Coin, usr.GetUserNickName())
  397. // 是否产生道具
  398. ret.ItemId, ret.ItemCount = ts.fishDrop.getDropItem(f.FishID)
  399. if ret.ItemCount > 0 {
  400. var items []item.ItemPack
  401. items = append(items, item.ItemPack{ItemId: ret.ItemId, Count: ret.ItemCount})
  402. item.AddItems(usr.GetUserId(), items, "捕鱼掉落", common.LOGTYPE_FISH_DROP)
  403. }
  404. // 转盘鱼
  405. ret.PrizeWheelItemId, ret.PrizeWheelItemCount = f.GetPrize()
  406. if ret.PrizeWheelItemCount > 0 {
  407. var items []item.ItemPack
  408. items = append(items, item.ItemPack{ItemId: ret.PrizeWheelItemId, Count: ret.PrizeWheelItemCount})
  409. item.AddItems(usr.GetUserId(), items, "捕鱼转盘", common.LOGTYPE_FISH_DROP)
  410. }
  411. roomUser.specialUsed(sc.OriginFishKey, ret.Coin)
  412. if fi.SpecialType > 0 {
  413. // 如果是slot
  414. if fi.SpecialEffect == item.SpecialEffect_Slot {
  415. ret.SlotMultiple = fi.Param1 + rand.Intn(fi.Param2-fi.Param1)
  416. ret.Coin = bulletOdds * ret.SlotMultiple
  417. } else {
  418. roomUser.addSpecial(f.FishKey, bulletOdds, fi.SpecialEffect, fi.SpecialType, fi.Param1, fi.Param2)
  419. }
  420. }
  421. ts.broadcastCatch(ret, true)
  422. ts.table.LogWithTableId("specialCatch UserID[%d],BulletOdds[%d],Win[%d],FishID[%d]", ret.UserId, bulletOdds, ret.Coin, catch.FishKey)
  423. // 写分
  424. ts.writeUserGold(usr, roomUser, ret.Coin)
  425. roomUser.setWaterPoolValue(ret.Coin, 0)
  426. // 加入纪录
  427. ts.recordmgr.getUserRecord(ret.UserId).addRecord(f.FishID, 0, ret.Coin)
  428. }
  429. }
  430. func (ts *tablesink) specialShoot(usr *user.UserInfo, cmd, data string) {
  431. ts.broadcastData(cmd, data)
  432. }
  433. func (ts *tablesink) specialCatchEnd(usr *user.UserInfo, cmd, data string) {
  434. var sc fishcommon.SpecialCatchEnd
  435. err := json.Unmarshal([]byte(data), &sc)
  436. if err != nil {
  437. ts.table.LogWithTableId("tablesink.specialCatchEnd failed %v", data)
  438. return
  439. }
  440. sc.UserId = usr.GetUserId()
  441. roomUser := ts.getRoomUser(usr.GetUserId())
  442. if roomUser == nil {
  443. ts.table.LogWithTableId("tablesink.specialCatchEnd roomUser not found %d", usr.GetUserId())
  444. return
  445. }
  446. sc.TotalEarn = roomUser.removeSpecial(sc.OriginFishKey)
  447. d, _ := json.Marshal(sc)
  448. ts.broadcastData(cmd, string(d))
  449. }
  450. func (ts *tablesink) upgradeBullet(usr *user.UserInfo, cmd, data string) {
  451. roomUser := ts.getRoomUser(usr.GetUserId())
  452. if roomUser == nil {
  453. ts.table.LogWithTableId("tablesink.upgradeBullet roomUser not found %d", usr.GetUserId())
  454. return
  455. }
  456. var ret fishcommon.UpgradeBullet_resp
  457. curBulletId := roomUser.getMaxBulletId()
  458. // 如果已经是最高等级了
  459. if curBulletId == ts.roomInfo.BulletMax {
  460. ts.table.LogWithTableId("tablesink.upgradeBullet 已经是最高等级了")
  461. ret.Succeeded = false
  462. ret.ErrorMsg = "升级失败,已经是本房间最高等级"
  463. d, _ := json.Marshal(ret)
  464. ts.table.SendGameData(usr.GetUserIndex(), cmd, string(d))
  465. return
  466. }
  467. count := bullet.GetUpgradeCount(curBulletId)
  468. if count == 0 {
  469. ts.table.LogWithTableId("tablesink.upgradeBullet failed count == 0")
  470. ret.Succeeded = false
  471. ret.ErrorMsg = "升级失败"
  472. d, _ := json.Marshal(ret)
  473. ts.table.SendGameData(usr.GetUserIndex(), cmd, string(d))
  474. return
  475. }
  476. // 此处暂时写死
  477. /*
  478. 原本需要扣除精华来升级子弹
  479. itemId := common.ESSENCE_ITEMID
  480. ok, _ := user.UseItem(itemId, 0, count)
  481. if !ok {
  482. ret.Succeeded = false
  483. ret.ErrorMsg = "升级失败,精华不足!"
  484. d, _ := json.Marshal(ret)
  485. go user.WriteMsg(cmd, string(d))
  486. return
  487. }
  488. */
  489. ret.Succeeded = true
  490. d, _ := json.Marshal(ret)
  491. ts.table.SendGameData(usr.GetUserIndex(), cmd, string(d))
  492. roomUser.setMaxBulletId(curBulletId + 1)
  493. ts.broadCastUserInfo(usr)
  494. }
  495. func (ts *tablesink) sendPoolValue() {
  496. ts.broadcastPoolValue = true
  497. }
  498. func (ts *tablesink) broadcastPool() {
  499. if true {
  500. return
  501. }
  502. if ts.prizePool == nil {
  503. return
  504. }
  505. data := fmt.Sprintf("%d", ts.prizePool.GetPoolValue())
  506. ts.broadcastData(fishcommon.POOL_VALUE, data)
  507. }
  508. func (ts *tablesink) broadcastPoolDraw(draw fishcommon.PrizePoolDraw_resp) {
  509. data, _ := json.Marshal(draw)
  510. ts.broadcastData(fishcommon.POOL_DRAW, string(data))
  511. }
  512. func (ts *tablesink) writeUserGold(usr *user.UserInfo, fUser *fishuser, amount int) bool {
  513. //ok, _ := ts.table.WriteUserMoney(userId, amount, tax, status, scoreType, ts.roomInfo.RoomName)
  514. // 这里不实际写分,只修改变量
  515. gold := usr.GetUserGold()
  516. if gold+amount < 0 {
  517. return false
  518. }
  519. usr.SetUserGold(gold + amount)
  520. fUser.addScore(amount)
  521. return true
  522. }
  523. func (ts *tablesink) doWriteUserGold(fUser *fishuser) {
  524. consume, earn := fUser.getConsumeAndEarnAndClear()
  525. //ts.table.LogWithTableId("doWriteUserGold UserId[%d] consume[%d] earn[%d]", fUser.userId, consume, earn)
  526. if consume < 0 {
  527. ts.table.WriteUserMoney(fUser.userId, consume, 0, 0, 1, ts.roomInfo.RoomName)
  528. }
  529. if earn > 0 {
  530. ts.table.WriteUserMoney(fUser.userId, earn, 0, 0, 2, ts.roomInfo.RoomName)
  531. }
  532. }
  533. func (ts *tablesink) onTimerWriteScore() {
  534. ts.table.SetTimer(fishcommon.TIMER_WRITESCORE, fishcommon.TIME_WRITESCORE)
  535. for _, v := range ts.Users {
  536. if v != nil {
  537. go ts.doWriteUserGold(v)
  538. }
  539. }
  540. }