main_dhc_test.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. package main
  2. import (
  3. "f1-game/internal/enum"
  4. "f1-game/internal/pb"
  5. "f1-game/tool/client-cli/cli"
  6. "fmt"
  7. "math/rand"
  8. "sync"
  9. "testing"
  10. "time"
  11. cherryHttp "github.com/cherry-game/cherry/extend/http"
  12. ctime "github.com/cherry-game/cherry/extend/time"
  13. clog "github.com/cherry-game/cherry/logger"
  14. )
  15. func testDHCSetup() *cli.Robot {
  16. var (
  17. // url = "http://192.168.1.232:18080"
  18. // addr = "192.168.1.232:30001"
  19. url = "http://dev.f1.chun-pu.com"
  20. addr = "127.0.0.1:30001"
  21. serverId = "4"
  22. account = "dhc-031211"
  23. password = "123456"
  24. pid = "2188004"
  25. )
  26. cli.RegisterDevAccount(url, account, password)
  27. robot := cli.EnterServer(url, pid, account, password, addr, serverId, true)
  28. return robot
  29. }
  30. func TestDHCMain(t *testing.T) {
  31. testDHCSetup()
  32. select {}
  33. }
  34. func TestDHCMainMap(t *testing.T) {
  35. robot := testDHCSetup()
  36. robot.MapLogin()
  37. time.Sleep(1 * time.Second)
  38. // robot.SelectState(1)
  39. // time.Sleep(1 * time.Second)
  40. robot.MapEnter()
  41. time.Sleep(1 * time.Second)
  42. robot.FacilityUp(10200)
  43. // robot.MapMarch(1, enum.MarchType_Siege, 63, 755, false, false)
  44. // time.Sleep(3 * time.Second)
  45. // robot.MapMarch(2, enum.MarchType_Siege, 63, 755, false, false)
  46. // time.Sleep(3 * time.Second)
  47. // robot.MapMarch(3, enum.MarchType_Siege, 63, 755, false, false)
  48. // time.Sleep(3 * time.Second)
  49. // robot.MapMarch(1, enum.MarchType_Occupy, 72, 712, false, true)
  50. // time.Sleep(3 * time.Second)
  51. // robot.MapMarch(2, enum.MarchType_Assemble, 63, 755, false, true)
  52. // time.Sleep(3 * time.Second)
  53. // robot.MapMarch(3, enum.MarchType_Assemble, 63, 755, false, false)
  54. // time.Sleep(3 * time.Second)
  55. // robot.MapStop(1)
  56. // time.Sleep(3 * time.Second)
  57. // robot.MapRetreat(1, 0)
  58. // time.Sleep(3 * time.Second)
  59. select {}
  60. }
  61. // 获取赛季霸业任务
  62. func TestSeasonQuestInfo(t *testing.T) {
  63. robot := testDHCSetup()
  64. time.Sleep(1 * time.Second)
  65. robot.MapLogin()
  66. time.Sleep(1 * time.Second)
  67. robot.SeasonQuestInfo()
  68. }
  69. // 领取赛季霸业奖励
  70. func TestSeasonQuestReward(t *testing.T) {
  71. robot := testDHCSetup()
  72. time.Sleep(1 * time.Second)
  73. robot.MapLogin()
  74. time.Sleep(1 * time.Second)
  75. questID := int32(101)
  76. robot.SeasonQuestReward(questID)
  77. select {}
  78. }
  79. // 地图交易所货柜解锁
  80. func TestExchangeSlotUnlock(t *testing.T) {
  81. robot := testDHCSetup()
  82. time.Sleep(1 * time.Second)
  83. robot.MapLogin()
  84. time.Sleep(1 * time.Second)
  85. robot.ExchangeSlotUnlock(enum.ExchangeActType_Sell)
  86. select {}
  87. }
  88. // 获取资源的历史求购价格
  89. func TestExchangeHistoryPrice(t *testing.T) {
  90. robot := testDHCSetup()
  91. time.Sleep(1 * time.Second)
  92. robot.MapLogin()
  93. time.Sleep(1 * time.Second)
  94. robot.ExchangeHistoryPrice(101)
  95. select {}
  96. }
  97. // 交易所交易物品
  98. func TestExchangeItem(t *testing.T) {
  99. robot := testDHCSetup()
  100. time.Sleep(1 * time.Second)
  101. robot.MapLogin()
  102. time.Sleep(1 * time.Second)
  103. robot.ExchangeItem(enum.ExchangeActType_Sell, enum.ItemIDWoodUnBound, 1, 1)
  104. // time.Sleep(50 * time.Millisecond)
  105. // transID := robot.ExchangeMyItems(enum.ExchangeActType_Wish)
  106. // if transID != "" {
  107. // time.Sleep(50 * time.Millisecond)
  108. // robot.ExchangeItemUpdate(enum.ExchangeUpdateType_Retrieve, transID)
  109. // }
  110. // for _, itemID := range enum.ItemMaxNumList {
  111. // robot.ExchangeItem(enum.ExchangeActType_Sell, itemID, 1+rand.Int63n(4), 10+rand.Int31n(10))
  112. // time.Sleep(1 * time.Second)
  113. // }
  114. select {}
  115. }
  116. // 购买商品
  117. func TestExchangeBuyItem(t *testing.T) {
  118. robot := testDHCSetup()
  119. time.Sleep(1 * time.Second)
  120. robot.MapLogin()
  121. time.Sleep(1 * time.Second)
  122. transID := "miNdctqlureFjhkbfR2JXK"
  123. count := int32(1)
  124. robot.ExchangeBuyItem(count, transID)
  125. select {}
  126. }
  127. // 查询交易所交易物品
  128. func TestExchangeQuery(t *testing.T) {
  129. robot := testDHCSetup()
  130. time.Sleep(1 * time.Second)
  131. robot.MapLogin()
  132. time.Sleep(1 * time.Second)
  133. var (
  134. pageNum int32 = 1
  135. itemIDList = []int32{}
  136. subTypeList = []int32{}
  137. qualityList = []int32{}
  138. priceSort = enum.ExchangeSortType_None
  139. countSort = enum.ExchangeSortType_None
  140. )
  141. robot.ExchangeQuery(pageNum, itemIDList, subTypeList, qualityList, priceSort, countSort)
  142. select {}
  143. }
  144. // 获取自己的交易商品列表
  145. func TestExchangeMyItems(t *testing.T) {
  146. robot := testDHCSetup()
  147. time.Sleep(1 * time.Second)
  148. robot.MapLogin()
  149. time.Sleep(1 * time.Second)
  150. robot.ExchangeMyItems(enum.ExchangeActType_Sell)
  151. select {}
  152. }
  153. // 更新地图交易所商品
  154. func TestExchangeItemUpdate(t *testing.T) {
  155. robot := testDHCSetup()
  156. time.Sleep(1 * time.Second)
  157. robot.MapLogin()
  158. time.Sleep(1 * time.Second)
  159. transID := "WvzFHxz2YM2YFhuQEYWpI2"
  160. updateType := enum.ExchangeUpdateType_Cancel
  161. robot.ExchangeItemUpdate(updateType, transID)
  162. time.Sleep(1 * time.Second)
  163. var (
  164. pageNum int32 = 1
  165. itemIDList = []int32{}
  166. subTypeList = []int32{}
  167. qualityList = []int32{}
  168. priceSort = enum.ExchangeSortType_Asc
  169. countSort = enum.ExchangeSortType_Desc
  170. )
  171. robot.ExchangeQuery(pageNum, itemIDList, subTypeList, qualityList, priceSort, countSort)
  172. select {}
  173. }
  174. // 获取交易所日志
  175. func TestExchangeLog(t *testing.T) {
  176. robot := testDHCSetup()
  177. time.Sleep(1 * time.Second)
  178. robot.MapLogin()
  179. time.Sleep(1 * time.Second)
  180. logType := enum.ExchangeLogType_Sell
  181. lastLogID := int64(0)
  182. robot.ExchangeLog(logType, lastLogID)
  183. select {}
  184. }
  185. // 获取联盟仓库信息
  186. func TestLeagueStorage(t *testing.T) {
  187. robot := testDHCSetup()
  188. time.Sleep(1 * time.Second)
  189. robot.MapLogin()
  190. time.Sleep(3 * time.Second)
  191. robot.LeagueStorageInfo()
  192. select {}
  193. }
  194. // 联盟调整税率
  195. func TestLeagueRatioUpdate(t *testing.T) {
  196. robot := testDHCSetup()
  197. time.Sleep(1 * time.Second)
  198. robot.MapLogin()
  199. time.Sleep(3 * time.Second)
  200. robot.LeagueRatioUpdate(20201, 10)
  201. select {}
  202. }
  203. // 联盟F币分红
  204. func TestLeagueFundBonus(t *testing.T) {
  205. robot := testDHCSetup()
  206. time.Sleep(1 * time.Second)
  207. robot.LeagueFundBonus(100, 12121, 112313)
  208. select {}
  209. }
  210. // 获取联盟城池列表
  211. func TestLeagueCastleList(t *testing.T) {
  212. robot := testDHCSetup()
  213. time.Sleep(1 * time.Second)
  214. robot.GetLeagueCastleList()
  215. }
  216. // 联盟城池城主任命
  217. func TestLeagueCastleAppoint(t *testing.T) {
  218. robot := testDHCSetup()
  219. time.Sleep(1 * time.Second)
  220. robot.LeagueCastleAppoint(101001, 1049132)
  221. }
  222. // 获取联盟科技列表
  223. func TestLeagueTechList(t *testing.T) {
  224. robot := testDHCSetup()
  225. time.Sleep(1 * time.Second)
  226. robot.GetLeagueTechList()
  227. }
  228. // 联盟科技升级
  229. func TestLeagueTechUpgrade(t *testing.T) {
  230. robot := testDHCSetup()
  231. time.Sleep(1 * time.Second)
  232. robot.LeagueTechUpgrade(1001)
  233. }
  234. // 英雄上阵
  235. func TestHeroLineupUp(t *testing.T) {
  236. robot := testDHCSetup()
  237. time.Sleep(1 * time.Second)
  238. robot.TeamUp(1049155, 1, 1, 1)
  239. time.Sleep(500 * time.Microsecond)
  240. // robot.TeamLeave(1, 1)
  241. // time.Sleep(500 * time.Microsecond)
  242. // robot.TeamUp(1048889, 1, 2, 3)
  243. // time.Sleep(500 * time.Microsecond)
  244. // robot.TeamUp(1048898, 1, 3, 5)
  245. // time.Sleep(500 * time.Microsecond)
  246. }
  247. // 获取个人战报列表
  248. func TestReportList(t *testing.T) {
  249. robot := testDHCSetup()
  250. time.Sleep(1 * time.Second)
  251. robot.MapLogin()
  252. time.Sleep(1 * time.Second)
  253. robot.ReportList("", enum.ReportCategory_All)
  254. select {}
  255. }
  256. // 获取个人收藏战报列表
  257. func TestReportInfo(t *testing.T) {
  258. robot := testDHCSetup()
  259. time.Sleep(1 * time.Second)
  260. robot.ReportInfo()
  261. }
  262. // 战报收藏和取消收藏
  263. func TestReportLike(t *testing.T) {
  264. robot := testDHCSetup()
  265. time.Sleep(1 * time.Second)
  266. robot.ReportLike(enum.ReportLikeType_Group, "1001", false)
  267. }
  268. // 战报一键阅读
  269. func TestReportRead(t *testing.T) {
  270. robot := testDHCSetup()
  271. time.Sleep(1 * time.Second)
  272. robot.ReportRead("")
  273. }
  274. // 获取同盟战报列表
  275. func TestLeagueReportList(t *testing.T) {
  276. robot := testDHCSetup()
  277. time.Sleep(1 * time.Second)
  278. robot.LeagueReportList(0, enum.ReportCategory_PVP)
  279. select {}
  280. }
  281. // 发起探险战斗
  282. func TestChapterBattle(t *testing.T) {
  283. robot := testDHCSetup()
  284. time.Sleep(1 * time.Second)
  285. robot.ChapterBattle(1011)
  286. }
  287. // 探险战斗验证
  288. func TestChapterVerify(t *testing.T) {
  289. robot := testDHCSetup()
  290. time.Sleep(1 * time.Second)
  291. robot.ChapterVerify(enum.BattleCampType_Left)
  292. }
  293. // 发送聊天消息
  294. func TestChatSend(t *testing.T) {
  295. robot := testDHCSetup()
  296. for i := range 1 {
  297. time.Sleep(1 * time.Second)
  298. robot.ChatSend(enum.ChatType_Game, 4, fmt.Sprintf("hello TestDHC%d", i))
  299. }
  300. select {}
  301. }
  302. // 聊天消息获取
  303. func TestChatMsgList(t *testing.T) {
  304. robot := testDHCSetup()
  305. time.Sleep(1 * time.Second)
  306. // robot.MapLogin()
  307. // time.Sleep(1 * time.Second)
  308. robot.ChatMsgList(enum.ChatType_Game, 4, 656893032578399168)
  309. select {}
  310. }
  311. // 创建聊天群组
  312. func TestChatGroupCreate(t *testing.T) {
  313. robot := testDHCSetup()
  314. time.Sleep(1 * time.Second)
  315. robot.ChatGroupCreate("h4", 1066402)
  316. select {}
  317. }
  318. // 群组成员修改
  319. func TestChatGroupPlayerChange(t *testing.T) {
  320. robot := testDHCSetup()
  321. time.Sleep(1 * time.Second)
  322. robot.ChatGroupPlayerChange(1025, []int64{1066353})
  323. select {}
  324. }
  325. // 群组邀请确认
  326. func TestChatGroupInviteConfirm(t *testing.T) {
  327. robot := testDHCSetup()
  328. robot.ChatGroupInviteConfirm(1028, true)
  329. }
  330. // 获取群组成员列表
  331. func TestChatGroupPlayerList(t *testing.T) {
  332. robot := testDHCSetup()
  333. time.Sleep(1 * time.Second)
  334. robot.ChatGroupPlayerList(1028)
  335. }
  336. // 解散群组
  337. func TestChatGroupDismiss(t *testing.T) {
  338. robot := testDHCSetup()
  339. time.Sleep(1 * time.Second)
  340. robot.ChatGroupDismiss(1030)
  341. }
  342. // 主动退出群组
  343. func TestChatGroupQuit(t *testing.T) {
  344. robot := testDHCSetup()
  345. time.Sleep(1 * time.Second)
  346. robot.ChatGroupQuit(1027)
  347. }
  348. // 设置群组聊天免打扰
  349. func TestGroupChatNofitySetting(t *testing.T) {
  350. robot := testDHCSetup()
  351. time.Sleep(1 * time.Second)
  352. robot.ChatGroupMute(1031, false)
  353. }
  354. // 私聊发送消息
  355. func TestChatPrivateSend(t *testing.T) {
  356. robot := testDHCSetup()
  357. time.Sleep(3 * time.Second)
  358. for i := 0; i < 1; i++ {
  359. robot.ChatPrivateSend(1048857, fmt.Sprintf("测试私聊消息4 hello I am dhc-test %d", i))
  360. time.Sleep(3 * time.Second)
  361. }
  362. select {}
  363. }
  364. // 获取私聊消息列表
  365. func TestChatPrivateMsgList(t *testing.T) {
  366. robot := testDHCSetup()
  367. time.Sleep(1 * time.Second)
  368. robot.ChatPrivateMsgList(1066419, 0)
  369. }
  370. // 聊天设置
  371. func TestChatSetting(t *testing.T) {
  372. robot := testDHCSetup()
  373. time.Sleep(1 * time.Second)
  374. robot.ChatSetting(false, false, false)
  375. }
  376. // 查询玩家信息
  377. func TestFriendSearch(t *testing.T) {
  378. robot := testDHCSetup()
  379. time.Sleep(1 * time.Second)
  380. robot.FriendSearch(1048584)
  381. }
  382. // 添加好友
  383. func TestFriendAdd(t *testing.T) {
  384. robot := testDHCSetup()
  385. time.Sleep(1 * time.Second)
  386. robot.FriendAdd(1066406)
  387. select {}
  388. }
  389. // 好友邀请确认
  390. func TestFriendConfirm(t *testing.T) {
  391. robot := testDHCSetup()
  392. time.Sleep(1 * time.Second)
  393. robot.FriendConfirm(1066408, true)
  394. select {}
  395. }
  396. // 删除好友
  397. func TestFriendDel(t *testing.T) {
  398. robot := testDHCSetup()
  399. time.Sleep(1 * time.Second)
  400. robot.FriendDel(1066408)
  401. select {}
  402. }
  403. // 设置黑名单
  404. func TestBlackSetting(t *testing.T) {
  405. robot := testDHCSetup()
  406. time.Sleep(1 * time.Second)
  407. robot.BlackSetting(1066355, false)
  408. select {}
  409. }
  410. // 举报
  411. func TestComplaint(t *testing.T) {
  412. robot := testDHCSetup()
  413. time.Sleep(1 * time.Second)
  414. robot.Complaint(1048585, enum.ComplaintType_BadName, "")
  415. }
  416. // 建筑升级
  417. func TestFacilityUp(t *testing.T) {
  418. robot := testDHCSetup()
  419. time.Sleep(1 * time.Second)
  420. robot.FacilityUp(1)
  421. }
  422. // 建筑取消升级
  423. func TestFacilityCancel(t *testing.T) {
  424. robot := testDHCSetup()
  425. time.Sleep(1 * time.Second)
  426. robot.FacilityCancel(1)
  427. }
  428. // 建筑立即升级完成
  429. func TestFacilityFinish(t *testing.T) {
  430. robot := testDHCSetup()
  431. time.Sleep(1 * time.Second)
  432. robot.FacilityFinish(1)
  433. }
  434. // 建筑队列解锁
  435. func TestFacilityQueueUnlock(t *testing.T) {
  436. robot := testDHCSetup()
  437. time.Sleep(1 * time.Second)
  438. robot.FacilityQueueUnlock(2)
  439. }
  440. // 充值创建
  441. func TestChargeCreate(t *testing.T) {
  442. robot := testDHCSetup()
  443. time.Sleep(1 * time.Second)
  444. robot.ChargeCreate(83001)
  445. select {}
  446. }
  447. // 每日周月卡奖励领取
  448. func TestCardReward(t *testing.T) {
  449. robot := testDHCSetup()
  450. time.Sleep(1 * time.Second)
  451. robot.CardReward(81003)
  452. select {}
  453. }
  454. // 支付测试
  455. func TestPayment(t *testing.T) {
  456. reqURL := "http://127.0.0.1/pay/test_payment?orderID=602573286605938496"
  457. cherryHttp.GET(reqURL)
  458. }
  459. // 英雄穿戴装备
  460. func TestHeroWearEquip(t *testing.T) {
  461. robot := testDHCSetup()
  462. time.Sleep(1 * time.Second)
  463. robot.HeroWearEquip(&pb.HeroEquip{
  464. HeroGUID: 1048603,
  465. EquipGUIDList: []int64{1048661, 1048642, 1048660},
  466. })
  467. select {}
  468. }
  469. // 英雄脱下装备
  470. func TestHeroTakeOffEquip(t *testing.T) {
  471. robot := testDHCSetup()
  472. time.Sleep(1 * time.Second)
  473. robot.HeroTakeOffEquip(&pb.I64I64{
  474. Key: 1048603,
  475. Value: 0,
  476. })
  477. select {}
  478. }
  479. // 领取每日VIP点数
  480. func TestVipDailyExpReward(t *testing.T) {
  481. robot := testDHCSetup()
  482. time.Sleep(1 * time.Second)
  483. robot.VipDailyExpReward()
  484. select {}
  485. }
  486. // 领取每日VIP宝箱奖励
  487. func TestVipDailyBoxReward(t *testing.T) {
  488. time.Sleep(1 * time.Second)
  489. robot := testDHCSetup()
  490. robot.VipDailyBoxReward(0)
  491. select {}
  492. }
  493. // 使用道具
  494. func TestDHCItemUse(t *testing.T) {
  495. robot := testDHCSetup()
  496. time.Sleep(1 * time.Second)
  497. robot.MapLogin()
  498. time.Sleep(1 * time.Second)
  499. robot.ItemUse(140003, 3)
  500. select {}
  501. }
  502. func Test_dhc_RegisterDevAccount(t *testing.T) {
  503. var (
  504. url = "http://192.168.1.225:18080"
  505. accountNum = 10000
  506. )
  507. accountList := make(map[string]string)
  508. for i := 1; i <= accountNum; i++ {
  509. key := fmt.Sprintf("dhc_%d", i)
  510. accountList[key] = key
  511. }
  512. cli.RegisterDevAccounts(url, accountList)
  513. }
  514. func Test_dhc_EnterServer(t *testing.T) {
  515. var (
  516. url = "http://192.168.1.225:18080"
  517. addr = "192.168.1.225:30001"
  518. gameNodeID = "4"
  519. testAccounts = make(map[string]string)
  520. pid = "2188004"
  521. maxAccountNum = 500
  522. )
  523. for i := 1; i <= maxAccountNum; i++ {
  524. key := fmt.Sprintf("dhc_122910_%d", i)
  525. testAccounts[key] = key
  526. cli.RegisterDevAccount(url, key, key)
  527. }
  528. now := ctime.Now()
  529. wg := &sync.WaitGroup{}
  530. wg.Add(maxAccountNum)
  531. for userName, password := range testAccounts {
  532. go func(userName, password string) {
  533. time.Sleep(50 + (time.Duration(rand.Int31n(100)) * time.Millisecond))
  534. robot := cli.EnterServer(url, pid, userName, password, addr, gameNodeID, false)
  535. robot.RandSleep()
  536. robot.MapLogin()
  537. wg.Done()
  538. }(userName, password)
  539. }
  540. wg.Wait()
  541. clog.Infof("elapsedTime = %dms", now.NowDiffMillisecond())
  542. }