ActivityLogic.java 182 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544
  1. package com.ljsd.jieling.logic.activity;
  2. import com.ljsd.GameApplication;
  3. import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
  4. import com.ljsd.jieling.core.VipPrivilegeType;
  5. import com.ljsd.jieling.db.mongo.MongoUtil;
  6. import com.ljsd.jieling.db.redis.RedisKey;
  7. import com.ljsd.jieling.db.redis.RedisUtil;
  8. import com.ljsd.jieling.exception.ErrorCode;
  9. import com.ljsd.jieling.exception.ErrorCodeException;
  10. import com.ljsd.jieling.globals.BIReason;
  11. import com.ljsd.jieling.globals.Global;
  12. import com.ljsd.jieling.handler.activity.BlessInfoConfig;
  13. import com.ljsd.jieling.jbean.*;
  14. import com.ljsd.jieling.logic.OnlineUserManager;
  15. import com.ljsd.jieling.logic.activity.event.*;
  16. import com.ljsd.jieling.logic.dao.*;
  17. import com.ljsd.jieling.logic.dao.root.GlobalSystemControl;
  18. import com.ljsd.jieling.logic.dao.root.User;
  19. import com.ljsd.jieling.logic.mail.MailLogic;
  20. import com.ljsd.jieling.logic.mission.GameEvent;
  21. import com.ljsd.jieling.logic.mission.event.MissionEventDistributor;
  22. import com.ljsd.jieling.logic.player.PlayerLogic;
  23. import com.ljsd.jieling.logic.store.StoreLogic;
  24. import com.ljsd.jieling.logic.store.bean.AbstractWelfareBag;
  25. import com.ljsd.jieling.network.server.ProtocolsManager;
  26. import com.ljsd.jieling.network.session.ISession;
  27. import com.ljsd.jieling.protocols.*;
  28. import com.ljsd.jieling.util.*;
  29. import config.*;
  30. import manager.STableManager;
  31. import org.slf4j.Logger;
  32. import org.slf4j.LoggerFactory;
  33. import org.springframework.data.domain.Sort;
  34. import org.springframework.data.mongodb.core.MongoTemplate;
  35. import org.springframework.data.mongodb.core.query.Criteria;
  36. import org.springframework.data.mongodb.core.query.Query;
  37. import org.springframework.data.redis.core.ZSetOperations;
  38. import util.MathUtils;
  39. import util.TimeUtils;
  40. import java.util.*;
  41. import java.util.function.Function;
  42. import java.util.stream.Collectors;
  43. import java.util.stream.Stream;
  44. /**
  45. *
  46. */
  47. public class ActivityLogic implements IEventHandler {
  48. private static final Logger LOGGER = LoggerFactory.getLogger(ActivityLogic.class);
  49. private ActivityLogic() {
  50. LOGGER.info("------ddd ActivityLogic进入001------");
  51. Poster.getPoster().listenEvent(this, MinuteTaskEvent.class);
  52. }
  53. private Set<Integer> openActivityIds = new HashSet<>();
  54. private Map<Integer, TimeControllerOfFunction> seasonActivityIds = new HashMap<>();
  55. private int secretBoxSeasonTimes = 0; //秘盒赛季
  56. @Override
  57. public void onEvent(IEvent event) throws Exception {
  58. if (event instanceof MinuteTaskEvent) {
  59. checkActiviyStatus();
  60. }
  61. }
  62. public void flushEveryDay(User user, PlayerInfoProto.FivePlayerUpdateIndication.Builder fBuilder) throws Exception {
  63. //跟新签到天数
  64. if (user.getPlayerInfoManager().getSignTotay() == 1) {
  65. user.getPlayerInfoManager().setSign(user.getPlayerInfoManager().getSign() + 1);
  66. user.getPlayerInfoManager().setSignTotay(0);
  67. if (user.getPlayerInfoManager().getOffLineTime() != 0) {
  68. if (user.getPlayerInfoManager().getSign() >= SSignInConfig.getsSignInConfigMap().size()) {
  69. user.getPlayerInfoManager().setSign(0);
  70. user.getPlayerInfoManager().setSignTotay(0);
  71. }
  72. }
  73. }
  74. //更新每日充值
  75. ActivityLogic.getInstance().resumeActivity(user, ActivityType.DAILY_RECHARGE);
  76. ActivityLogic.getInstance().resumeActivity(user, ActivityType.DAILY_RECHARGE_2);
  77. //更新每日累计充值
  78. ActivityLogic.getInstance().resumeActivity(user, ActivityType.RECHARGE_NUM);
  79. ActivityLogic.getInstance().resumeActivity(user, ActivityType.RECHARGE_SUM_DAY);
  80. //更新首日充值st
  81. user.getPlayerInfoManager().getRechargeInfo().setDailyFirst(0);
  82. //更新累计充值天数
  83. user.getPlayerInfoManager().setRechargedaily(0);
  84. user.getPlayerInfoManager().setLuckWheelLimitTime(0);
  85. user.getPlayerInfoManager().setLuckAdvanceWheelLimitTime(0);
  86. updateActivityMissionProgress(user, ActivityType.SevenLogin, 1);
  87. updateActivityMissionProgress(user, ActivityType.NEW_DAY_LOGIN, 1);
  88. Poster.getPoster().dispatchEvent(new NewWelfareEvent(user, NewWelfareTypeEnum.LOGIN_TIMES.getType(), 1));
  89. //幸运转盘活动刷新
  90. ActivityLogic.getInstance().resumeActivity(user, ActivityType.LUCK_WHEEL);
  91. ActivityLogic.getInstance().resumeActivity(user, ActivityType.LUCK_WHEEL_ADVANCE);
  92. ActivityLogic.getInstance().resumeActivity(user, ActivityType.TREASURE);
  93. ActivityLogic.getInstance().resumeActivity(user, ActivityType.FOREVER_MEMBER);
  94. ActivityLogic.getInstance().resumeActivity(user, ActivityType.FOREVER_MEMBER_PLUS);
  95. //神秘指令
  96. ActivityLogic.getInstance().resumeActivity(user, ActivityType.CARD_SUBJECT_MYSTICAL_INSTRUCT);
  97. Set<Integer> upFiveActivityTypes = new HashSet<>();
  98. upFiveActivityTypes.add(ActivityType.SevenLogin);
  99. upFiveActivityTypes.add(ActivityType.NEW_DAY_LOGIN);
  100. upFiveActivityTypes.add(ActivityType.RECHARGE_SUM_DAY);
  101. upFiveActivityTypes.add(ActivityType.DAILY_RECHARGE);
  102. upFiveActivityTypes.add(ActivityType.DAILY_RECHARGE_2);
  103. upFiveActivityTypes.add(ActivityType.LUCK_WHEEL);
  104. upFiveActivityTypes.add(ActivityType.LUCK_WHEEL_ADVANCE);
  105. upFiveActivityTypes.add(ActivityType.RECHARGE_NUM);
  106. upFivePlayerActivity(user, upFiveActivityTypes, fBuilder);
  107. ActivityLogic.getInstance().resumeActivity(user,ActivityType.ADJUTANTFIGHT);
  108. ActivityLogic.getInstance().resumeActivity(user,ActivityType.JADE_DYNASTY_MISSION);
  109. }
  110. public void flushForLogin(User user, ISession iSession) throws Exception {
  111. checkActivityIsFinish(user);
  112. checkActivityOfUser(user, null);
  113. sendLuckWheelPool(user, iSession);
  114. }
  115. public static class Instance {
  116. public final static ActivityLogic instance = new ActivityLogic();
  117. }
  118. //检查活动状态
  119. public void checkActiviyStatus() throws Exception {
  120. long now = System.currentTimeMillis();
  121. Map<Integer, SGlobalActivity> sGlobalActivityMap = SGlobalActivity.getsGlobalActivityMap();
  122. checkRoleActiviyStatus(); //检查角色活动状态 (活动开启类型:5循环)
  123. //检查开启的活动 非相对创角时间 (活动开启类型:1绝对时间,3开服时间)
  124. for (SGlobalActivity sGlobalActivity : sGlobalActivityMap.values()) {
  125. int time = sGlobalActivity.getTime();
  126. ActivityTypeEnum.getActicityType(sGlobalActivity.getId());
  127. //2创角时间,4解锁时间,5循环
  128. if (time == ActivityType.OPEN_TYPE_ROLE || time == ActivityType.OPEN_TYPE_ROLE_SERVER || time == ActivityType.OPEN_TYPE_SEASON) {
  129. continue;
  130. }
  131. long startTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), 0, 1);
  132. long endTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), 0, 2);
  133. long gapEndTime = endTime + sGlobalActivity.getGapTime() * TimeUtils.DAY;
  134. LOGGER.debug("checkActiviyStatus:" + sGlobalActivity.getId() + " 开始时间:" + startTime + " 结束时间:" + endTime + " gapEndTime:" + gapEndTime);
  135. if (now < startTime || sGlobalActivity.getIsOpen() == 0) {
  136. //如果没到活动开启时间,但是openActivityIds里有了这个活动,证明是热更延迟开启的活动,需要清除掉
  137. if (openActivityIds.contains(sGlobalActivity.getId())) {
  138. openActivityIds.remove(sGlobalActivity.getId());
  139. }
  140. LOGGER.debug("活动未开始:" + sGlobalActivity.getId());
  141. continue;
  142. }
  143. //如果没有开放
  144. if (!isOpen(sGlobalActivity)) {
  145. LOGGER.debug("活动未开放:" + sGlobalActivity.getId());
  146. continue;
  147. }
  148. if (endTime != 0 && now > endTime) {
  149. if (!openActivityIds.contains(sGlobalActivity.getId())) {
  150. if (now < gapEndTime) {
  151. openActivityIds.add(sGlobalActivity.getId());
  152. LOGGER.debug("活动已开启:" + sGlobalActivity.getId());
  153. }
  154. continue;
  155. }
  156. if (now > gapEndTime) {
  157. LOGGER.debug("活动已结束:" + sGlobalActivity.getId());
  158. openActivityIds.remove(sGlobalActivity.getId());
  159. }
  160. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(sGlobalActivity.getId());
  161. if (null == abstractActivity) {
  162. LOGGER.debug("活动不存在:" + sGlobalActivity.getId());
  163. continue;
  164. }
  165. abstractActivity.onActivityEnd();
  166. LOGGER.debug("活动已结束:" + sGlobalActivity.getId());
  167. continue;
  168. }
  169. // if (endTime != 0 && now > endTime) {
  170. // if (openActivityIds.contains(sGlobalActivity.getId())) {
  171. // openActivityIds.remove(sGlobalActivity.getId());
  172. // AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(sGlobalActivity.getId());
  173. // if (null == abstractActivity) {
  174. // continue;
  175. // }
  176. // abstractActivity.onActivityEnd();
  177. // }
  178. // continue;
  179. // }
  180. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(sGlobalActivity.getId());
  181. if (null == abstractActivity) {
  182. LOGGER.error("活动不存在:" + sGlobalActivity.getId());
  183. continue;
  184. }
  185. abstractActivity.onActivityStart();
  186. openActivityIds.add(sGlobalActivity.getId());
  187. }
  188. //活动数据处理分发到角色线程
  189. InnerMessageUtil.broadcastWithRandom(user1 -> {
  190. if (user1 == null) {
  191. return;
  192. }
  193. ISession session = OnlineUserManager.getSessionByUid(user1.getId());
  194. if (null == session) {
  195. return;
  196. }
  197. PlayerInfoProto.ActivityUpateIndication.Builder builder = PlayerInfoProto.ActivityUpateIndication.newBuilder();
  198. MissionEventDistributor.requestStart();
  199. /**
  200. * czq
  201. * @see SecretExpectRankActivity 关联这个活动
  202. * 如果训练精英活动结束了 两个写死的VIP特权需要去掉
  203. */
  204. Set<Integer> openNews = checkActivityOfUser(user1, builder);
  205. for (int i = 0; i < builder.getCloseActivityIdList().size(); i++) {
  206. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(builder.getCloseActivityIdList().get(i));
  207. int[] shopId = sGlobalActivity.getShopId();
  208. //如果活动关联了商店
  209. if (shopId != null && shopId.length > 0) {
  210. for (int j = 0; j < shopId.length; i++) {
  211. int realShopId = shopId[i];
  212. if (realShopId > 0) {
  213. user1.getStoreManager().removeStoreInfo(realShopId);
  214. }
  215. }
  216. }
  217. if(sGlobalActivity.getType() == ActivityTypeEnum.SECURT_EXPERT.getType()) {
  218. user1.getPlayerInfoManager().removeVipPriviliageId(153);
  219. user1.getPlayerInfoManager().removeVipPriviliageId(154);
  220. break;
  221. }
  222. }
  223. //send new/close activity indication
  224. if (!openNews.isEmpty()) {
  225. Map<Integer, ActivityMission> activityMissionMap = user1.getActivityManager().getActivityMissionMap();
  226. Map<Integer, ActivityMission> activityUpdateMap = new HashMap<>();
  227. boolean sendLuckWheelPool = false;
  228. for (Integer activityId : openNews) {
  229. int type = SGlobalActivity.getsGlobalActivityMap().get(activityId).getType();
  230. if (type == ActivityType.LUCK_WHEEL || type == ActivityType.LUCK_WHEEL_ADVANCE)
  231. sendLuckWheelPool = true;
  232. activityUpdateMap.put(activityId, activityMissionMap.get(activityId));
  233. }
  234. List<CommonProto.ActivityInfo> activityInfos = getActivityInfos(activityUpdateMap, user1.getPlayerInfoManager().getCreateTime());
  235. builder.addAllActivityInfo(activityInfos);
  236. if (sendLuckWheelPool) {
  237. sendLuckWheelPool(user1, session);
  238. }
  239. }
  240. if (builder.getActivityInfoCount() > 0 || builder.getCloseActivityIdCount() > 0) {
  241. MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.ACTIVITY_UPDATE_INDICATION_VALUE, builder.build(), true);
  242. }
  243. MissionEventDistributor.requestEnd(session, true);
  244. }, new LinkedList<>(OnlineUserManager.sessionMap.keySet()), 5);
  245. }
  246. private static boolean isOpen(SGlobalActivity sGlobalActivity) {
  247. boolean isOpen = true;
  248. if (sGlobalActivity.getIsOpen() == 0) {
  249. isOpen = false;
  250. return isOpen;
  251. }
  252. int[][] ifOpen = sGlobalActivity.getIfOpen();
  253. if (ifOpen != null && ifOpen.length > 0) {
  254. for (int i = 0; i < ifOpen.length ; i++) {
  255. if (ifOpen[i][0] == 2) { //开服
  256. if (GameApplication.serverConfig.getCacheOpenTime() + ifOpen[i][1] * TimeUtils.ONE_DAY > TimeUtils.now()) {
  257. isOpen = false;
  258. break;
  259. }
  260. }
  261. }
  262. }
  263. return isOpen;
  264. }
  265. //检查角色活动状态 (活动开启类型:5循环) 轮询活动判断
  266. public void checkRoleActiviyStatus() throws Exception {
  267. long now = System.currentTimeMillis();
  268. Map<Integer, SGlobalActivity> sGlobalActivityMap = SGlobalActivity.getsGlobalActivityMap();
  269. List<Integer> openList = new ArrayList<>();
  270. List<Integer> closeList = new ArrayList<>();
  271. for (SGlobalActivity sGlobalActivity : sGlobalActivityMap.values()) {
  272. int time = sGlobalActivity.getTime();
  273. ActivityTypeEnum.getActicityType(sGlobalActivity.getId());
  274. if (time != ActivityType.OPEN_TYPE_SEASON) { //5 = 活动开启类型:循环
  275. continue;
  276. }
  277. if(!isOpen(sGlobalActivity)) {
  278. continue;
  279. }
  280. long systemOpenLong = sGlobalActivity.getStartTimeLong();
  281. long systemEndLong = sGlobalActivity.getEndTimeLong();
  282. int id = sGlobalActivity.getId();
  283. if (seasonActivityIds.containsKey(id)) {
  284. // //强制关闭
  285. systemOpenLong = seasonActivityIds.get(id).getStartTime();
  286. systemEndLong = seasonActivityIds.get(id).getEndTime();
  287. if (now < systemOpenLong || (now > systemEndLong)) {
  288. closeList.add(id);
  289. continue;
  290. }
  291. long endTime = seasonActivityIds.get(id).getEndTime();
  292. if (now > endTime) {
  293. closeList.add(id);
  294. }
  295. } else {
  296. long seasonOpenLong = sGlobalActivity.getStartTimeLong(); //活动开启时间
  297. long seasonEndLong = sGlobalActivity.getEndTimeLong(); //活动结束时间(秒) 注:孙龙的宝藏时间是任务时间,奖励时间在此基础上多一天 东海寻仙包括了活动结束后的预告时间
  298. long diffTime = seasonEndLong - seasonOpenLong; //活动时间
  299. long seasonInterval = sGlobalActivity.getSleepTime() * 60 * 1000L; //循环活动间隔时间(分钟),最小2
  300. long passTims = now - seasonOpenLong; //活动开始已过时间
  301. if (passTims > 0) {
  302. //if (diffTime + seasonInterval == 0) {
  303. if (seasonInterval == 0 || diffTime > seasonInterval) {
  304. LOGGER.info("the sGlobalSystemConfig info{},{}", sGlobalActivity.getId(), sGlobalActivity.getSleepTime());
  305. }
  306. long mod = passTims % (diffTime + seasonInterval);
  307. //long mod = passTims % seasonInterval;
  308. if (mod < diffTime) { //新的周期开启
  309. openList.add(id);
  310. //计算开启时间、关闭时间
  311. long turns = passTims / (diffTime + seasonInterval);
  312. long addTim = turns * (diffTime + seasonInterval);
  313. // long turns = passTims / seasonInterval;
  314. // long addTim = turns * seasonInterval;
  315. long timeOpenOfThis = seasonOpenLong + addTim; //开启时间
  316. long timeCloseOfThis = seasonEndLong + addTim; //结束时间
  317. TimeControllerOfFunction function = new TimeControllerOfFunction(id, 1, timeOpenOfThis, timeCloseOfThis,(int)turns);
  318. // GlobalSystemControl globalSystemControl = MongoUtil.getInstence().getMyMongoTemplate().findById(GameApplication.serverId, GlobalSystemControl.class);
  319. // if (globalSystemControl == null) {
  320. // globalSystemControl = new GlobalSystemControl(GameApplication.serverId);
  321. // }
  322. // Map<Integer, TimeControllerOfFunction> timeControllerOfFunctionMap = globalSystemControl.getTimeControllerOfActivityMap();
  323. // TimeControllerOfFunction function = new TimeControllerOfFunction(id, 1, timeOpenOfThis, timeCloseOfThis);
  324. // if (timeControllerOfFunctionMap.containsKey(id)) {
  325. // function.setTimes(timeControllerOfFunctionMap.get(id).getTimes());
  326. // }
  327. seasonActivityIds.put(id, function);
  328. }
  329. }
  330. }
  331. }
  332. if (openList.isEmpty() && closeList.isEmpty()) {
  333. return;
  334. }
  335. GlobalSystemControl globalSystemControl = MongoUtil.getInstence().getMyMongoTemplate().findById(GameApplication.serverId, GlobalSystemControl.class);
  336. if (globalSystemControl == null) {
  337. globalSystemControl = new GlobalSystemControl(GameApplication.serverId);
  338. }
  339. Map<Integer, TimeControllerOfFunction> timeControllerOfFunctionMap = globalSystemControl.getTimeControllerOfActivityMap();
  340. List<Integer> reallyOpenList = new ArrayList<>();
  341. // List<Integer> reallyCloseList = new ArrayList<>();
  342. boolean needUpdate = false;
  343. for (Integer id : openList) {
  344. TimeControllerOfFunction timeControllerOfFunction = timeControllerOfFunctionMap.get(id);
  345. if (timeControllerOfFunction == null || timeControllerOfFunction.getStartTime() != seasonActivityIds.get(id).getStartTime()) {
  346. needUpdate = true;
  347. TimeControllerOfFunction timeControllerOfFunctionCacheItem = seasonActivityIds.get(id);
  348. if (timeControllerOfFunction != null) {
  349. timeControllerOfFunctionCacheItem.setTimes(timeControllerOfFunction.getTimes() + 1);
  350. } else {
  351. timeControllerOfFunctionCacheItem.setTimes(1);
  352. }
  353. globalSystemControl.updateTimeControllerOfActivityMap(seasonActivityIds.get(id));
  354. reallyOpenList.add(id);
  355. }
  356. }
  357. LOGGER.info(" ----轮询关闭活动 seasonActivityIds---- closeList={}", closeList.toString());
  358. for (Integer id : closeList) {
  359. LOGGER.info(" ----轮询关闭活动 seasonActivityIds---- id={}", id.toString());
  360. seasonActivityIds.remove(id);
  361. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(id);
  362. if (null != abstractActivity) {
  363. abstractActivity.onActivityEnd();
  364. }
  365. }
  366. if (needUpdate) {
  367. MongoTemplate otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(GameApplication.serverId);
  368. otherMonogTemplate.save(globalSystemControl);
  369. // openAction(reallyOpenList);
  370. }
  371. // closeAction(closeList);
  372. // updateGetFunctionOfTimeResponse();
  373. }
  374. public void newPlayerOpenActivityMission(User user) throws Exception {
  375. checkActivityOfUser(user, null);
  376. ISession session = OnlineUserManager.getSessionByUid(user.getId());
  377. if (null != session)
  378. sendLuckWheelPool(user, session);
  379. }
  380. public void checkNeedOpenStore(User user, int storeId, long startTime, long endTime) throws Exception {
  381. if (storeId == 0) {
  382. return;
  383. }
  384. StoreLogic.initOnsStoereWithTime(user, storeId, startTime, endTime);
  385. }
  386. public boolean initAllActivityMission(Map<Integer, ActivityMission> map, int activityId) {
  387. if (map.containsKey(activityId)) {
  388. return false;
  389. }
  390. ActivityMission activityMission = new ActivityMission();
  391. //自动初始化
  392. map.put(activityId, activityMission);
  393. initMissionInfo(activityMission, activityId);
  394. // activityMission.init(getRootId(), getMongoKey() + ".activityMissionMap." + activityId);
  395. return true;
  396. }
  397. public boolean initAllActivityMission(Map<Integer, ActivityMission> map, int activityId, int version) {
  398. // if (map.containsKey(activityId)) {
  399. // return false;
  400. // }
  401. ActivityMission activityMission = new ActivityMission();
  402. //自动初始化
  403. map.put(activityId, activityMission);
  404. initMissionInfo(activityMission, activityId, version);
  405. activityMission.setSeason(version);
  406. // activityMission.init(getRootId(), getMongoKey() + ".activityMissionMap." + activityId);
  407. return true;
  408. }
  409. public void initMissionInfo(ActivityMission activityMission, int activityId) {
  410. List<SActivityRewardConfig> sActivityRewardConfigs = SActivityRewardConfig.getsActivityRewardConfigByActivityId(activityId);
  411. if (sActivityRewardConfigs == null) {
  412. return;
  413. }
  414. for (SActivityRewardConfig sActivityRewardConfig : sActivityRewardConfigs) {
  415. ActivityProgressInfo activityProgressInfo = new ActivityProgressInfo();
  416. activityProgressInfo.setProgrss(ActivityLogic.getInstance().getInitActivityMissionProgress(activityId));
  417. activityProgressInfo.setState(0);
  418. activityMission.getActivityMissionMap().put(sActivityRewardConfig.getId(), activityProgressInfo);
  419. }
  420. activityMission.setOpenType(1);
  421. activityMission.setActivityState(ActivityType.OPEN_STATE);
  422. activityMission.setV(0);
  423. activityMission.setCreatTime(TimeUtils.now());
  424. }
  425. public void initMissionInfo(ActivityMission activityMission, int activityId, int version) {
  426. List<SActivityRewardConfig> sActivityRewardConfigs = SActivityRewardConfig.getsActivityRewardConfigByActivityId(activityId);
  427. if (sActivityRewardConfigs == null) {
  428. return;
  429. }
  430. for (SActivityRewardConfig sActivityRewardConfig : sActivityRewardConfigs) {
  431. ActivityProgressInfo activityProgressInfo = new ActivityProgressInfo();
  432. activityProgressInfo.setProgrss(ActivityLogic.getInstance().getInitActivityMissionProgress(activityId));
  433. activityProgressInfo.setState(0);
  434. activityMission.getActivityMissionMap().put(sActivityRewardConfig.getId(), activityProgressInfo);
  435. }
  436. activityMission.setOpenType(1);
  437. activityMission.setActivityState(ActivityType.OPEN_STATE);
  438. activityMission.setV(0);
  439. activityMission.setSeason(version);
  440. activityMission.setCreatTime(TimeUtils.now());
  441. }
  442. public void initOtherMission(ActivityMission activityMission, List<Integer> missionIds) {
  443. for (Integer missionId : missionIds) {
  444. ActivityProgressInfo activityProgressInfo = new ActivityProgressInfo();
  445. activityProgressInfo.setProgrss(0);
  446. activityProgressInfo.setState(0);
  447. activityMission.getActivityMissionMap().put(missionId, activityProgressInfo);
  448. }
  449. activityMission.setOpenType(1);
  450. activityMission.setV(0);
  451. activityMission.setActivityState(ActivityType.OPEN_STATE);
  452. }
  453. public LuckWheelMission getLuckWheel(ActivityManager activityManager, int type) {
  454. LuckWheelMission luckWheelMission = type == ActivityType.LUCK_WHEEL ? activityManager.getLuckWheel() : activityManager.getLuckWheelAdvance();
  455. if (null == luckWheelMission) {
  456. String key = type == ActivityType.LUCK_WHEEL ? "luckWheel" : "luckWheelAdvance";
  457. if (type == ActivityType.LUCK_WHEEL) {
  458. luckWheelMission = new LuckWheelMission();
  459. activityManager.setLuckWheel(luckWheelMission);
  460. } else {
  461. luckWheelMission = new LuckWheelMission();
  462. activityManager.setLuckWheelAdvance(luckWheelMission);
  463. }
  464. }
  465. return luckWheelMission;
  466. }
  467. public void initLuckWheel(ActivityManager activityManager, int type) {
  468. LuckWheelMission luckWheelMission = type == ActivityType.LUCK_WHEEL ? activityManager.getLuckWheel() : activityManager.getLuckWheelAdvance();
  469. if (null != luckWheelMission) {
  470. String key = type == ActivityType.LUCK_WHEEL ? "luckWheel" : "luckWheelAdvance";
  471. if (type == ActivityType.LUCK_WHEEL) {
  472. activityManager.setLuckWheel(luckWheelMission);
  473. } else {
  474. luckWheelMission = new LuckWheelMission();
  475. activityManager.setLuckWheelAdvance(luckWheelMission);
  476. }
  477. }
  478. }
  479. public Set<Integer> checkActivityOfUser(User user, PlayerInfoProto.ActivityUpateIndication.Builder builder) throws Exception {
  480. long now = TimeUtils.now();
  481. if (user == null) {
  482. return new HashSet<>(1);
  483. }
  484. ActivityManager activityManager = user.getActivityManager();
  485. Map<Integer, SGlobalActivity> sGlobalActivityMap = SGlobalActivity.getsGlobalActivityMap();
  486. Set<Integer> openNewActivityIds = new HashSet<>();
  487. long userCreateTime = user.getPlayerInfoManager().getCreateTime();
  488. // LOGGER.info("----openActivityIds ={}",openActivityIds);
  489. //初始化活动 绝对时间和相对开服时间
  490. for (Integer openActivityId : openActivityIds) {
  491. SGlobalActivity sGlobalActivity = sGlobalActivityMap.get(openActivityId);
  492. if(!isOpen(sGlobalActivity)) {
  493. continue;
  494. }
  495. ActivityMission activityMission = activityManager.getActivityMissionMap().get(openActivityId);
  496. List<SActivityRewardConfig> sActivityRewardConfigs = SActivityRewardConfig.getsActivityRewardConfigByActivityId(openActivityId);
  497. if (activityMission != null) {
  498. if(sActivityRewardConfigs == null){
  499. // LOGGER.info("sActivityRewardConfigs is null,openActivityId ={}",openActivityId);
  500. continue;
  501. }
  502. if(activityMission.getActivityMissionMap() != null && activityMission.getActivityMissionMap().size() == sActivityRewardConfigs.size()) {
  503. continue;
  504. }else {
  505. List<Integer> idList = SActivityRewardConfig.getsActivityIdByActivityId(openActivityId);
  506. Iterator<Integer> iterator = idList.iterator();
  507. while (iterator.hasNext()){
  508. Integer id = iterator.next();
  509. if(!activityMission.getActivityMissionMap().keySet().contains(id)){
  510. ActivityProgressInfo activityProgressInfo = new ActivityProgressInfo();
  511. activityProgressInfo.setProgrss(ActivityLogic.getInstance().getInitActivityMissionProgress(openActivityId));
  512. activityProgressInfo.setState(0);
  513. activityMission.getActivityMissionMap().put(id, activityProgressInfo);
  514. }
  515. }
  516. if(activityMission.getActivityMissionMap().size() == sActivityRewardConfigs.size()) {
  517. continue;
  518. }
  519. }
  520. }
  521. // if(!initOtherActivity(user, sGlobalActivity)){
  522. initAllActivityMission(activityManager.getActivityMissionMap(), openActivityId);
  523. // }
  524. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(openActivityId);
  525. if (null == abstractActivity) {
  526. continue;
  527. }
  528. abstractActivity.initActivity(user);
  529. // //ReportUtil.onReportEvent(user, ReportEventEnum.JOIN_ACTIVITY.getType(),String.valueOf(openActivityId));
  530. int activityOpenState = getActivityOpenState(user, openActivityId);
  531. abstractActivity.setOpenState(user, activityOpenState);
  532. if (activityOpenState == ActivityType.UNOPEN_STATE) {
  533. continue;
  534. }
  535. //非角色活动开启通知
  536. openNewActivityIds.add(openActivityId);
  537. }
  538. // LOGGER.info("----seasonActivityIds ={}",seasonActivityIds.values());
  539. for (TimeControllerOfFunction timeIDinfo : seasonActivityIds.values()) {
  540. int openActivityId = timeIDinfo.getId();
  541. SGlobalActivity sGlobalActivity = sGlobalActivityMap.get(openActivityId);
  542. if(!isUserCreateTimeOpen(sGlobalActivity, userCreateTime, now)) {
  543. continue;
  544. }
  545. ActivityMission activityMission = activityManager.getActivityMissionMap().get(openActivityId);
  546. if (activityMission != null) {
  547. if (activityMission.getSeason() == 0) {
  548. //更新season
  549. activityMission.setSeason(timeIDinfo.getTimes());
  550. }
  551. if (activityMission.getSeason() == seasonActivityIds.getOrDefault(openActivityId, new TimeControllerOfFunction()).getTimes()) {
  552. continue;
  553. }
  554. //如果任务创建的时间大于本轮开始的时间 则不需要初始化
  555. long startTime = seasonActivityIds.getOrDefault(sGlobalActivity.getId(), new TimeControllerOfFunction()).getStartTime();
  556. if(activityMission.getCreatTime() >= startTime) {
  557. continue;
  558. }
  559. if(sGlobalActivity.getType() == ActivityType.COW_FLY_SKY
  560. && activityMission.getSeason() != timeIDinfo.getTimes()
  561. && now <= timeIDinfo.getEndTime() + sGlobalActivity.getGapTime() * TimeUtils.ONE_DAY) {
  562. //特殊处理下,因循环周期时间判断有问题,开启不了任务,重启开启任务
  563. activityMission.setSeason(timeIDinfo.getTimes());
  564. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(openActivityId);
  565. if (null == abstractActivity) continue;
  566. abstractActivity.initActivity(user);
  567. continue;
  568. }
  569. LOGGER.info("[活动新周期2] [uid:{}] [activityId:{}] [activityType:{}] [activityStartTime:{}] [activitySeason:{}] [confactivitySeason:{}]", user.getId(), openActivityId, sGlobalActivity.getType(), sGlobalActivity.getStartTimeLong(), activityMission.getSeason(), timeIDinfo.getTimes());
  570. goRewardActivity(user, openActivityId, builder, now > timeIDinfo.getEndTime() + sGlobalActivity.getGapTime() * TimeUtils.ONE_DAY);
  571. continue;
  572. }
  573. // if(!initOtherActivity(user, sGlobalActivity)){
  574. initAllActivityMission(activityManager.getActivityMissionMap(), openActivityId, timeIDinfo.getTimes());
  575. // }
  576. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(openActivityId);
  577. if (null == abstractActivity) {
  578. continue;
  579. }
  580. abstractActivity.initActivity(user);
  581. // //ReportUtil.onReportEvent(user, ReportEventEnum.JOIN_ACTIVITY.getType(),String.valueOf(openActivityId));
  582. int activityOpenState = getActivityOpenState(user, openActivityId);
  583. abstractActivity.setOpenState(user, activityOpenState);
  584. if (activityOpenState == ActivityType.UNOPEN_STATE) {
  585. continue;
  586. }
  587. //非角色活动开启通知
  588. openNewActivityIds.add(openActivityId);
  589. }
  590. Map<Integer, ActivityMission> activityMissionMap = activityManager.getActivityMissionMap();
  591. for (SGlobalActivity sGlobalActivity : sGlobalActivityMap.values()) {
  592. int activityId = sGlobalActivity.getId();
  593. if (openActivityIds.contains(activityId)) {
  594. if (!isConfigIfOpen(sGlobalActivity, userCreateTime, now)) {
  595. continue;
  596. }
  597. } else if (activityMissionMap.containsKey(activityId)) {
  598. //如果活动没有开启,但是玩家有这个活动的数据,则清除,并通知客户端活动关闭
  599. long startTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), userCreateTime, 1);
  600. if (SGlobalActivity.getsGlobalActivityMap().get(activityId).getTime() == 5) {
  601. if (seasonActivityIds.containsKey(activityId)) {
  602. startTime = seasonActivityIds.getOrDefault(activityId, new TimeControllerOfFunction()).getStartTime();
  603. // LOGGER.info("[5类型活动] [uid:{}] [activityId:{}] [activityType:{}] [activityStartTime:{}]", user.getId(), activityId, sGlobalActivity.getType(), startTime);
  604. }
  605. }
  606. if (TimeUtils.now() < startTime) {
  607. LOGGER.info("[活动延期,清除遗留玩家数据] [uid:{}] [activityId:{}] [activityType:{}] [activityStartTime:{}]", user.getId(), activityId, sGlobalActivity.getType(), sGlobalActivity.getStartTimeLong());
  608. activityMissionMap.remove(activityId);
  609. if (builder != null) {
  610. builder.addCloseActivityId(activityId);
  611. }
  612. }
  613. }
  614. int time = sGlobalActivity.getTime();
  615. if (sGlobalActivity.getOpenRules().length == 3 && sGlobalActivity.getOpenRules()[0] != 4) {
  616. //等级关闭
  617. int level = sGlobalActivity.getOpenRules()[2];
  618. if (user.getPlayerInfoManager().getLevel() >= level && level != 0) {
  619. goRewardActivity(user, activityId, builder, now > now + sGlobalActivity.getGapTime() * TimeUtils.ONE_DAY);
  620. }
  621. if (user.getPlayerInfoManager().getLevel() < sGlobalActivity.getOpenRules()[1]) {
  622. //等級未開啓
  623. user.getActivityManager().getActivityMissionMap().remove(activityId);
  624. }
  625. }
  626. if (time == ActivityType.OPEN_TYPE_ROLE) { // 活动开启类型:创角时间
  627. long startTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), userCreateTime, 1);
  628. long endTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), userCreateTime, 2);
  629. if (now < startTime) {
  630. continue;
  631. }
  632. if (endTime != 0 && now > endTime) {
  633. goRewardActivity(user, activityId, builder, now > endTime + sGlobalActivity.getGapTime() * TimeUtils.ONE_DAY);
  634. continue;
  635. }
  636. ActivityMission activityMission = activityMissionMap.get(activityId);
  637. if (activityMission != null) {
  638. continue;
  639. }
  640. int activityOpenState = getActivityOpenState(user, activityId);
  641. if (activityOpenState != ActivityType.OPEN_STATE) {
  642. continue;
  643. }
  644. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(activityId);
  645. if (null == abstractActivity) {
  646. continue;
  647. }
  648. // //ReportUtil.onReportEvent(user, ReportEventEnum.JOIN_ACTIVITY.getType(),String.valueOf(activityId));
  649. abstractActivity.initActivity(user);
  650. // if(!initOtherActivity(user, sGlobalActivity)){
  651. initAllActivityMission(activityManager.getActivityMissionMap(), activityId);
  652. abstractActivity.setOpenState(user, activityOpenState);
  653. if (activityOpenState == ActivityType.UNOPEN_STATE) {
  654. continue;
  655. }
  656. openNewActivityIds.add(activityId);
  657. } else if (time == ActivityType.OPEN_TYPE_ROLE_SERVER) { // 活动开启类型:解锁时间
  658. long startTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), ActivityType.OPEN_TYPE_SERVER, userCreateTime, 1);
  659. long endTime = 0;
  660. if (now < startTime) {
  661. continue;
  662. }
  663. if (endTime != 0 && now > endTime) {
  664. goRewardActivity(user, activityId, builder, now > endTime + sGlobalActivity.getGapTime() * TimeUtils.ONE_DAY);
  665. continue;
  666. }
  667. ActivityMission activityMission = activityMissionMap.get(activityId);
  668. if (activityMission != null) {
  669. continue;
  670. }
  671. int activityOpenState = getActivityOpenState(user, activityId);
  672. if (activityOpenState != ActivityType.OPEN_STATE) {
  673. continue;
  674. }
  675. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(activityId);
  676. if (null == abstractActivity) {
  677. continue;
  678. }
  679. // //ReportUtil.onReportEvent(user, ReportEventEnum.JOIN_ACTIVITY.getType(),String.valueOf(activityId));
  680. abstractActivity.initActivity(user);
  681. // if(!initOtherActivity(user, sGlobalActivity)){
  682. initAllActivityMission(activityManager.getActivityMissionMap(), activityId);
  683. //
  684. abstractActivity.setOpenState(user, activityOpenState);
  685. if (activityOpenState == ActivityType.UNOPEN_STATE) {
  686. continue;
  687. }
  688. openNewActivityIds.add(activityId);
  689. } else if (time == ActivityType.OPEN_TYPE_SEASON) { //活动开启类型:循环
  690. if (!seasonActivityIds.containsKey(activityId)) {
  691. //LOGGER.info("[循环活动结束周期1] [uid:{}] [activityId:{}] [activityType:{}] [activityStartTime:{}] [activitySeason:{}] [confactivitySeason:{}]", user.getId(), activityId, sGlobalActivity.getType(), sGlobalActivity.getStartTimeLong());
  692. long endTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), user.getPlayerInfoManager().getCreateTime(), 2);
  693. goRewardActivity(user, activityId, builder, now > endTime + sGlobalActivity.getGapTime() * TimeUtils.ONE_DAY);
  694. continue;
  695. }
  696. long startTime = seasonActivityIds.get(activityId).getStartTime();
  697. long endTime = seasonActivityIds.get(activityId).getEndTime();
  698. if (now < startTime) {
  699. continue;
  700. }
  701. if (endTime != 0 && now > endTime) {
  702. LOGGER.info("[循环活动结束周期2] [uid:{}] [activityId:{}] [activityType:{}] [activityStartTime:{}] [activitySeason:{}] [confactivitySeason:{}]", user.getId(), activityId, sGlobalActivity.getType(), sGlobalActivity.getStartTimeLong());
  703. goRewardActivity(user, activityId, builder, now > endTime + sGlobalActivity.getGapTime() * TimeUtils.ONE_DAY);
  704. continue;
  705. }
  706. ActivityMission activityMission = activityMissionMap.get(activityId);
  707. if (activityMission != null) {
  708. //如果season为0 修改为当前活动season
  709. if(activityMission.getSeason() == 0) {
  710. activityMission.setSeason(seasonActivityIds.getOrDefault(activityId, new TimeControllerOfFunction()).getTimes());
  711. }
  712. if (activityMission.getSeason() == seasonActivityIds.getOrDefault(activityId, new TimeControllerOfFunction()).getTimes()) {
  713. continue;
  714. }
  715. startTime = seasonActivityIds.getOrDefault(activityId, new TimeControllerOfFunction()).getStartTime();
  716. if(activityMission.getCreatTime() >= startTime) {
  717. continue;
  718. }
  719. LOGGER.info("[活动新周期] [uid:{}] [activityId:{}] [activityType:{}] [activityStartTime:{}] [activitySeason:{}] [confactivitySeason:{}]", user.getId(), activityId, sGlobalActivity.getType(), sGlobalActivity.getStartTimeLong(), activityMission.getSeason(), seasonActivityIds.get(activityId).getTimes());
  720. goRewardActivity(user, activityId, builder, now > endTime + sGlobalActivity.getGapTime() * TimeUtils.ONE_DAY);
  721. }
  722. int activityOpenState = getActivityOpenState(user, activityId);
  723. if (activityOpenState != ActivityType.OPEN_STATE) {
  724. continue;
  725. }
  726. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(activityId);
  727. if (null == abstractActivity) {
  728. continue;
  729. }
  730. // //ReportUtil.onReportEvent(user, ReportEventEnum.JOIN_ACTIVITY.getType(),String.valueOf(activityId));
  731. //abstractActivity.initActivity(user);
  732. // if(!initOtherActivity(user, sGlobalActivity)){
  733. //initAllActivityMission(activityManager.getActivityMissionMap(), activityId);
  734. initAllActivityMission(activityManager.getActivityMissionMap(), activityId, seasonActivityIds.get(activityId).getTimes());
  735. abstractActivity.setOpenState(user, activityOpenState);
  736. if (activityOpenState == ActivityType.UNOPEN_STATE) {
  737. continue;
  738. }
  739. openNewActivityIds.add(activityId);
  740. checkRoleActiviyStatus(); //检查角色活动状态 (活动开启类型:5循环)
  741. } else {
  742. long endTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), userCreateTime, 2);
  743. goRewardActivity(user, activityId, builder, now > endTime + sGlobalActivity.getGapTime() * TimeUtils.ONE_DAY);
  744. }
  745. }
  746. return openNewActivityIds;
  747. }
  748. /**
  749. * 配置了ifOpen 并且活动开放才返回true
  750. * @param sGlobalActivity
  751. * @param userCreateTime 用户创角时间
  752. * @param now //系统当前时间
  753. * @return
  754. */
  755. private boolean isConfigIfOpen(SGlobalActivity sGlobalActivity, long userCreateTime, long now) {
  756. boolean isConfig = false;
  757. int[][] ifOpen = sGlobalActivity.getIfOpen();
  758. if (ifOpen != null && ifOpen.length > 0) {
  759. for (int i = 0; i < ifOpen.length ; i++) {
  760. if (ifOpen[i][0] == 1) { //创角
  761. if (userCreateTime + ifOpen[i][1] * TimeUtils.ONE_DAY <= now) {
  762. isConfig = true;
  763. break;
  764. }
  765. }
  766. }
  767. }
  768. return isConfig;
  769. }
  770. /**
  771. * 判断活动开放 是否符合创角配置
  772. * @param sGlobalActivity
  773. * @param userCreateTime
  774. * @param now
  775. * @return
  776. */
  777. private boolean isUserCreateTimeOpen(SGlobalActivity sGlobalActivity, long userCreateTime, long now) {
  778. boolean isConfig = true;
  779. int[][] ifOpen = sGlobalActivity.getIfOpen();
  780. if (ifOpen != null && ifOpen.length > 0) {
  781. for (int i = 0; i < ifOpen.length ; i++) {
  782. if (ifOpen[i][0] == 1) { //创角
  783. if (userCreateTime + ifOpen[i][1] * TimeUtils.ONE_DAY > now) {
  784. isConfig = false;
  785. break;
  786. }
  787. }
  788. }
  789. }
  790. return isConfig;
  791. }
  792. private static void goRewardActivity(User user, int activityId, PlayerInfoProto.ActivityUpateIndication.Builder builder, boolean isRemoveInfo) throws Exception {
  793. ActivityMission activityMission = user.getActivityManager().getActivityMissionMap().get(activityId);
  794. if (activityMission != null) {
  795. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(activityId);
  796. if (null == abstractActivity) {
  797. return;
  798. }
  799. SGlobalActivity _sGlobalActivity = SGlobalActivity.getsGlobalActivityInfo(activityId);
  800. if(_sGlobalActivity != null
  801. && (_sGlobalActivity.getType() == ActivityType.EXCHANGEANDDROP || _sGlobalActivity.getType() == ActivityType.HERO_TRIAL_STAR)) {
  802. if(!isRemoveInfo) //这个类型特殊判断一下,暂时不修改通用的checkActivityOfUser方法
  803. return;
  804. }
  805. if (activityMission.getOpenType() != ActivityType.CLOSE_STATE) {
  806. abstractActivity.onActivityEndSelfWithDealReward(user);
  807. abstractActivity.setOpenState(user, ActivityType.CLOSE_STATE);
  808. Poster.getPoster().dispatchEvent(new ActivityStateChangeEvent(user.getId(), activityId, ActivityType.CLOSE_STATE));
  809. }
  810. if (isRemoveInfo) {
  811. user.getActivityManager().getActivityMissionMap().remove(activityId);
  812. LOGGER.info("the uid={},remove the activity id ={}", user.getId(), activityId);
  813. if (builder != null) {
  814. builder.addCloseActivityId(activityId);
  815. }
  816. }
  817. }
  818. }
  819. public static ActivityLogic getInstance() {
  820. return ActivityLogic.Instance.instance;
  821. }
  822. //获取所有活动
  823. public void getAllActivityInfo(ISession session) throws Exception {
  824. int uid = session.getUid();
  825. User user = UserManager.getUser(uid);
  826. long createTime = user.getPlayerInfoManager().getCreateTime();
  827. int rewardResponseValue = MessageTypeProto.MessageType.GET_ALL_ACTIVITY_RESPONSE_VALUE;
  828. checkActivityOfUser(user, null);
  829. List<CommonProto.ActivityInfo> activityInfoList = getActivityInfos(user.getActivityManager().getActivityMissionMap(), createTime);
  830. PlayerInfoProto.GetAllActivityResponse.Builder builder = PlayerInfoProto.GetAllActivityResponse.newBuilder();
  831. if(user.getPlayerInfoManager().getLevel() >= 10) { //10级以上才有活动
  832. List<Integer> activityIdList = new ArrayList<>(); //没有结束的活动ID
  833. for (CommonProto.ActivityInfo activityInfo : activityInfoList) {
  834. activityIdList.add(activityInfo.getActivityId());
  835. }
  836. ActivityEndDelItem(user,activityIdList); //活动结束 删除对应的背包道具
  837. }
  838. for (CommonProto.ActivityInfo activityInfo : activityInfoList) {
  839. LOGGER.info("the uid={},getAllActivityInfo={}", uid, activityInfo.getActivityId());
  840. }
  841. builder.addAllActivityInfo(activityInfoList);
  842. sendLuckWheelPool(user, session);
  843. MessageUtil.sendMessage(session, 1, rewardResponseValue, builder.build(), true);
  844. }
  845. /**
  846. * 活动结束 删除对应的背包道具
  847. */
  848. public void ActivityEndDelItem(User user,List<Integer> activityIdList) {
  849. ItemManager itemManager = user.getItemManager();
  850. List<Integer> itemIdList = new ArrayList<>(); //没有结束的活动ID,活动结束要删除的道具Id
  851. for (int activityId : activityIdList){
  852. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(activityId);
  853. int[] activityItem = sGlobalActivity.getActivityItem();
  854. if(activityItem != null && activityItem.length > 0) {
  855. for (int i = 0; i < activityItem.length; i++) {
  856. itemIdList.add(activityItem[i]);
  857. }
  858. }
  859. }
  860. //默认不存在训练精英活动
  861. boolean hasSE = false;
  862. //开启的商店
  863. Map<Integer, OpenActData> openShopInfos = new HashMap<>();
  864. List<Integer> closeShopIds = new ArrayList<>();
  865. for (SGlobalActivity sGlobalActivity : SGlobalActivity.getsGlobalActivityMap().values()) {
  866. //如果存在训练精英活动
  867. if (activityIdList.contains(sGlobalActivity.getId()) && sGlobalActivity.getType() == ActivityTypeEnum.SECURT_EXPERT.getType()) {
  868. hasSE = true;
  869. }
  870. //如果活动结束了 删除活动关联的商店
  871. if (!activityIdList.contains(sGlobalActivity.getId()) && sGlobalActivity.getShopId() != null && sGlobalActivity.getShopId().length > 0 ) {
  872. for (int i = 0; i < sGlobalActivity.getShopId().length; i++) {
  873. int shopId = sGlobalActivity.getShopId()[i];
  874. if ( shopId > 0 ) {
  875. closeShopIds.add(shopId);
  876. }
  877. }
  878. }
  879. if (activityIdList.contains(sGlobalActivity.getId()) && sGlobalActivity.getShopId() != null && sGlobalActivity.getShopId().length > 0 ) {
  880. for (int i = 0; i < sGlobalActivity.getShopId().length; i++) {
  881. int shopId = sGlobalActivity.getShopId()[i];
  882. if ( shopId > 0 ) {
  883. OpenActData shop = new OpenActData();
  884. long startTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(),sGlobalActivity.getEndTimeLong(),sGlobalActivity.getTime(),user.getPlayerInfoManager().getCreateTime(), 1);
  885. long endTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(),sGlobalActivity.getEndTimeLong(),sGlobalActivity.getTime(),user.getPlayerInfoManager().getCreateTime(), 2);
  886. shop.shopId = shopId;
  887. shop.startTime = startTime;
  888. shop.endTime = endTime;
  889. openShopInfos.put(shopId, shop);
  890. }
  891. }
  892. }
  893. if (sGlobalActivity.getActivityItem() != null && sGlobalActivity.getActivityItem().length > 0) {
  894. if (!activityIdList.contains(sGlobalActivity.getId())) {
  895. int[] activityItem = sGlobalActivity.getActivityItem();
  896. for (int itemId : activityItem) {
  897. if(itemManager.getItemMap().containsKey(itemId)) {
  898. if (!itemIdList.contains(itemId)) {
  899. itemManager.removeItem(itemId);
  900. LOGGER.info("----活动结束 删除道具----UserId={},ItemId", user.getId(), itemId);
  901. continue;
  902. }
  903. LOGGER.info("----活动结束 有不同期活动开始,不删除道具----UserId={},ItemId={}", user.getId(), itemId);
  904. }
  905. }
  906. }
  907. }
  908. }
  909. if(!closeShopIds.isEmpty()) {
  910. closeShopIds.forEach(e-> {
  911. //如果活动被关闭 并且活动关联的商店在开启的活动中没有关联 则删除
  912. if(!openShopInfos.containsKey(e)) {
  913. user.getStoreManager().removeStoreInfo(e);
  914. }
  915. });
  916. }
  917. if(!openShopInfos.isEmpty()) {
  918. openShopInfos.forEach((shopId, shopInfo)-> {
  919. //如果商店不包括应该开启的商店 则重新初始化
  920. if(!user.getStoreManager().getStoreInfoMap().containsKey(shopId)) {
  921. try {
  922. StoreLogic.initOnsStoereWithTime(user, shopId, shopInfo.startTime, shopInfo.endTime);
  923. } catch (Exception e) {
  924. LOGGER.error("initOnsStoreWithTime failed !!!");
  925. }
  926. }
  927. });
  928. }
  929. /**
  930. * @see SecretExpectRankActivity
  931. * 如果是训练精英活动结束了
  932. */
  933. if(! hasSE) {
  934. user.getPlayerInfoManager().removeVipPriviliageId(153);
  935. user.getPlayerInfoManager().removeVipPriviliageId(154);
  936. } else {
  937. //不存在则加回去
  938. if(user.getPlayerInfoManager().getVipInfo().get(153) == null) {
  939. user.getPlayerInfoManager().addVipInfo(153);
  940. }
  941. if(user.getPlayerInfoManager().getVipInfo().get(154) == null) {
  942. user.getPlayerInfoManager().addVipInfo(154);
  943. }
  944. }
  945. }
  946. private static class OpenActData {
  947. OpenActData() {
  948. }
  949. public long startTime;
  950. public long endTime;
  951. public int shopId;
  952. }
  953. private void sendLuckWheelPool(User user, ISession session) {
  954. PlayerInfoProto.LuckWheelIndication.Builder builder = PlayerInfoProto.LuckWheelIndication.newBuilder();
  955. builder.addAllPosInfos(LuckWheelActivity.getLuckWheelReward(user, ActivityType.LUCK_WHEEL));
  956. builder.addAllPosInfosAdvance(LuckWheelActivity.getLuckWheelReward(user, ActivityType.LUCK_WHEEL_ADVANCE));
  957. if (builder.getPosInfosAdvanceCount() == 0 || builder.getPosInfosCount() == 0) {
  958. return;
  959. }
  960. MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.LUCKWHEEL_POOL_INDICATION_VALUE, builder.build(), true);
  961. }
  962. public List<CommonProto.ActivityInfo> getActivityInfos(Map<Integer, ActivityMission> activityMissionMap, long createTime) {
  963. Map<Integer, SGlobalActivity> sGlobalActivityMap = SGlobalActivity.getsGlobalActivityMap();
  964. List<CommonProto.ActivityInfo> activityInfoList = new ArrayList<>(activityMissionMap.size());
  965. LOGGER.info("--openActivityIds={}",openActivityIds);
  966. LOGGER.info("--seasonActivityIds={}",seasonActivityIds.keySet());
  967. int dayOfWeek = TimeUtils.getDayOfWeek(); //获取周几, 周日 7; 其他正常
  968. List<Integer> dayList = new ArrayList<>();
  969. dayList.add(6);
  970. dayList.add(7);
  971. dayList.add(1);
  972. for (Map.Entry<Integer, ActivityMission> activityState : activityMissionMap.entrySet()) {
  973. Integer activityId = activityState.getKey();
  974. ActivityMission activityMission = activityState.getValue();
  975. //todo 活动未初始化成功
  976. // if (activityMission == null) {
  977. // continue;
  978. // }
  979. if (activityMission.getActivityMissionMap().size() == 0) {
  980. Iterator<SGlobalActivity> iterator = sGlobalActivityMap.values().iterator();
  981. while (iterator.hasNext()) {
  982. SGlobalActivity next = iterator.next();
  983. if (next.getType() == activityId) {
  984. ActivityProgressInfo aInfo = new ActivityProgressInfo();
  985. aInfo.setRootId(next.getId());
  986. aInfo.setProgrss(0);
  987. aInfo.setState(0);
  988. activityMission.getActivityMissionMap().put(activityId, aInfo);
  989. }
  990. }
  991. }
  992. int activityStatus = activityMission.getActivityState();
  993. if (activityStatus == -1) {
  994. continue;
  995. }
  996. SGlobalActivity sGlobalActivity = sGlobalActivityMap.get(activityId);
  997. if (activityStatus == ActivityType.CLOSE_STATE) {
  998. long prepareTime = ToolsUtil.getEndTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), 0, sGlobalActivity.getGapTime());
  999. activityInfoList.add(CommonProto.ActivityInfo.newBuilder().setActivityId(activityId).setEndTime((int) (prepareTime / 1000)).build());
  1000. continue;
  1001. }
  1002. if (sGlobalActivity == null) {
  1003. sGlobalActivity = new SGlobalActivity();
  1004. }
  1005. if (sGlobalActivity.getIsSaving() == 0 && activityStatus != ActivityType.OPEN_STATE) {
  1006. continue;
  1007. }
  1008. int startTime = (int) (ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), createTime, 1) / 1000);
  1009. int endTime;
  1010. if (sGlobalActivity.getGapTime() != 0) {
  1011. endTime = (int) (ToolsUtil.getEndTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), createTime, sGlobalActivity.getGapTime()) / 1000);
  1012. } else {
  1013. endTime = (int) (ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), createTime, 2) / 1000);
  1014. }
  1015. if (sGlobalActivity.getTime() == 5) {
  1016. if (seasonActivityIds.containsKey(sGlobalActivity.getId())) {
  1017. startTime = (int)( seasonActivityIds.get(sGlobalActivity.getId()).getStartTime() / 1000);
  1018. endTime = (int) (seasonActivityIds.get(sGlobalActivity.getId()).getEndTime() / 1000);
  1019. }
  1020. }
  1021. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(sGlobalActivity.getId());
  1022. if (abstractActivity == null) {
  1023. LOGGER.error(sGlobalActivity.getId() + ":活动类型不存在");
  1024. continue;
  1025. }
  1026. List<CommonProto.ActivityInfo.MissionInfo> missionInfos = abstractActivity.getAllMissInfo(activityMission);
  1027. int time = sGlobalActivity.getTime();
  1028. // ActivityTypeEnum.getActicityType(sGlobalActivity.getId());
  1029. //2创角时间,4解锁时间,5循环
  1030. // if (time == ActivityType.OPEN_TYPE_ROLE || time == ActivityType.OPEN_TYPE_ROLE_SERVER || time == ActivityType.OPEN_TYPE_SEASON) {
  1031. //
  1032. // }
  1033. if(openActivityIds.contains(activityId)){
  1034. activityInfoList.add(CommonProto.ActivityInfo.newBuilder().setActivityId(activityId).addAllMission(missionInfos).setStartTime(startTime).setEndTime(endTime).setValue(activityMission.getV()).setReallyOpen(activityMission.getOpenType()).build());
  1035. }else if(seasonActivityIds.containsKey(activityId)){
  1036. if(activityId == ActivityType.WEEK_END_REWARD && !dayList.contains(dayOfWeek)){ //周末福利 非周末时间
  1037. continue;
  1038. }
  1039. activityInfoList.add(CommonProto.ActivityInfo.newBuilder().setActivityId(activityId).addAllMission(missionInfos).setStartTime(startTime).setEndTime(endTime).setValue(activityMission.getV()).setReallyOpen(activityMission.getOpenType()).build());
  1040. }
  1041. if(time == ActivityType.OPEN_TYPE_ROLE || time == ActivityType.OPEN_TYPE_ROLE_SERVER){
  1042. activityInfoList.add(CommonProto.ActivityInfo.newBuilder().setActivityId(activityId).addAllMission(missionInfos).setStartTime(startTime).setEndTime(endTime).setValue(activityMission.getV()).setReallyOpen(activityMission.getOpenType()).build());
  1043. }
  1044. }
  1045. return activityInfoList;
  1046. }
  1047. public void sendActivityInfo(User user, int activityId) {
  1048. ISession session = OnlineUserManager.getSessionByUid(user.getId());
  1049. if (session != null) {
  1050. PlayerInfoProto.ActivityUpateIndication.Builder builder = PlayerInfoProto.ActivityUpateIndication.newBuilder();
  1051. Map<Integer, ActivityMission> activityMissionMap = user.getActivityManager().getActivityMissionMap();
  1052. Map<Integer, ActivityMission> activityUpdateMap = new HashMap<>();
  1053. boolean sendLuckWheelPool = false;
  1054. int type = SGlobalActivity.getsGlobalActivityMap().get(activityId).getType();
  1055. if (type == ActivityType.LUCK_WHEEL || type == ActivityType.LUCK_WHEEL_ADVANCE)
  1056. sendLuckWheelPool = true;
  1057. activityUpdateMap.put(activityId, activityMissionMap.get(activityId));
  1058. List<CommonProto.ActivityInfo> activityInfos = getActivityInfos(activityUpdateMap, user.getPlayerInfoManager().getCreateTime());
  1059. builder.addAllActivityInfo(activityInfos);
  1060. if (sendLuckWheelPool) {
  1061. sendLuckWheelPool(user, session);
  1062. }
  1063. MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.ACTIVITY_UPDATE_INDICATION_VALUE, builder.build(), true);
  1064. }
  1065. }
  1066. public void openActivityReallyOpen(User user, int activityType) {
  1067. ActivityManager activityManager = user.getActivityManager();
  1068. Map<Integer, ActivityMission> activityMissionMap = activityManager.getActivityMissionMap();
  1069. for (Map.Entry<Integer, ActivityMission> item : activityMissionMap.entrySet()) {
  1070. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(item.getKey());
  1071. int targetActivityType = sGlobalActivity.getType();
  1072. if (targetActivityType == activityType) {
  1073. ActivityMission value = item.getValue();
  1074. if (value.getOpenType() == 0) {
  1075. value.setOpenType(1);
  1076. }
  1077. }
  1078. }
  1079. }
  1080. public int getActivityOpenState(User user, int activityId) {
  1081. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityInfo(activityId);
  1082. if (sGlobalActivity == null) {
  1083. return ActivityType.CLOSE_STATE;
  1084. }
  1085. int[] openRules = sGlobalActivity.getOpenRules();
  1086. int state = ActivityType.OPEN_STATE;
  1087. if (openRules != null && openRules.length > 0) {
  1088. int openRuleType = openRules[0];
  1089. int openRulleValue = openRules[1];
  1090. if (openRuleType == 1) {
  1091. int virtureId = SMainLevelConfig.config.get(openRulleValue).getVirtureId();
  1092. int fightId = user.getMainLevelManager().getFightId();
  1093. SMainLevelConfig mineMainLevelConfig = SMainLevelConfig.fightPreMap.get(fightId);
  1094. if (user.getMainLevelManager().getState() == 2) {
  1095. mineMainLevelConfig = SMainLevelConfig.config.get(user.getMainLevelManager().getFightId());
  1096. }
  1097. int myVirtureId = 0;
  1098. if (mineMainLevelConfig != null) {
  1099. myVirtureId = mineMainLevelConfig.getVirtureId();
  1100. }
  1101. if (virtureId > myVirtureId) {
  1102. state = ActivityType.UNOPEN_STATE;
  1103. }
  1104. } else if (openRuleType == 2) {
  1105. int maxLevel = Integer.MAX_VALUE - 1;
  1106. if (openRules.length >= 3) {
  1107. maxLevel = openRules[2];
  1108. }
  1109. if (user.getPlayerInfoManager().getLevel() < openRulleValue || user.getPlayerInfoManager().getLevel() > maxLevel) {
  1110. state = ActivityType.UNOPEN_STATE;
  1111. }
  1112. } else if (openRuleType == 3) {
  1113. state = ActivityType.UNOPEN_STATE;
  1114. } else if (openRuleType == 4) {
  1115. int openLevel = 0;
  1116. if(openRules.length >= 3){
  1117. openLevel = openRules[2];
  1118. }
  1119. if(openRulleValue > 0 && openRulleValue > user.getPlayerInfoManager().getVipLevel()){
  1120. state = ActivityType.UNOPEN_STATE;
  1121. }
  1122. if(openLevel > 0 && openLevel > user.getPlayerInfoManager().getLevel()){
  1123. state = ActivityType.UNOPEN_STATE;
  1124. }
  1125. }
  1126. }
  1127. return state;
  1128. }
  1129. public void updateActivityMissionProgress(User user, int activityType, int count) {
  1130. for (Integer id : getOpenActivityIdsByType(user, activityType, true)) {
  1131. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(id);
  1132. if (abstractActivity == null) {
  1133. continue;
  1134. }
  1135. abstractActivity.update(user, count);
  1136. }
  1137. }
  1138. //活动PVE任务:通过活动Id更新任务
  1139. public void updateActivityMissionProgressByActivityId(User user, int activityId, int count) {
  1140. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(activityId);
  1141. if (abstractActivity != null) {
  1142. abstractActivity.update(user, count);
  1143. }
  1144. }
  1145. public void resumeActivity(User user, int activityType) throws Exception {
  1146. for (Integer id : getOpenActivityIdsByType(user, activityType, false)) {
  1147. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(id);
  1148. if (abstractActivity == null) {
  1149. continue;
  1150. }
  1151. abstractActivity.onResume(user);
  1152. }
  1153. }
  1154. public Set<Integer> getOpenActivityIdsByType(User user, int activityType, boolean withState) {
  1155. Set<Integer> ids = new HashSet<>();
  1156. ActivityManager activityManager = user.getActivityManager();
  1157. Map<Integer, ActivityMission> activityMissionMap = activityManager.getActivityMissionMap();
  1158. for (Map.Entry<Integer, ActivityMission> item : activityMissionMap.entrySet()) {
  1159. ActivityMission activityMission = item.getValue();
  1160. if (withState && activityMission.getActivityState() != ActivityType.OPEN_STATE) {
  1161. continue;
  1162. }
  1163. Integer activityId = item.getKey();
  1164. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(activityId);
  1165. if (sGlobalActivity != null) {
  1166. int targetActivityType = sGlobalActivity.getType();
  1167. if (targetActivityType != activityType) {
  1168. continue;
  1169. }
  1170. }
  1171. ids.add(activityId);
  1172. }
  1173. return ids;
  1174. }
  1175. public void upFivePlayerActivity(User user, Set<Integer> activityType, PlayerInfoProto.FivePlayerUpdateIndication.Builder fBuilder) {
  1176. if (fBuilder == null) {
  1177. return;
  1178. }
  1179. ActivityManager activityManager = user.getActivityManager();
  1180. Map<Integer, ActivityMission> activityMissionMap = activityManager.getActivityMissionMap();
  1181. for (Map.Entry<Integer, ActivityMission> item : activityMissionMap.entrySet()) {
  1182. ActivityMission activityMission = item.getValue();
  1183. if (activityMission.getActivityState() != ActivityType.OPEN_STATE) {
  1184. continue;
  1185. }
  1186. Integer activityId = item.getKey();
  1187. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(activityId);
  1188. int targetActivityType = sGlobalActivity.getType();
  1189. if (!activityType.contains(targetActivityType)) {
  1190. continue;
  1191. }
  1192. AbstractActivity abstractActivity = ActivityTypeEnum.getActicityType(activityId);
  1193. if (null == abstractActivity) {
  1194. continue;
  1195. }
  1196. if (abstractActivity instanceof LuckWheelActivity) {
  1197. if (targetActivityType == ActivityType.LUCK_WHEEL)
  1198. fBuilder.addAllPosInfos(LuckWheelActivity.getLuckWheelReward(user, targetActivityType));
  1199. if (targetActivityType == ActivityType.LUCK_WHEEL_ADVANCE)
  1200. fBuilder.addAllPosInfosAdvance(LuckWheelActivity.getLuckWheelReward(user, targetActivityType));
  1201. continue;
  1202. }
  1203. long createTime = user.getPlayerInfoManager().getCreateTime();
  1204. int startTime = (int) (ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), createTime, 1) / 1000);
  1205. int endTime = (int) (ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), createTime, 2) / 1000);
  1206. List<CommonProto.ActivityInfo.MissionInfo> missionInfos = abstractActivity.getAllMissInfo(activityMission);
  1207. fBuilder.addActivityInfo(CommonProto.ActivityInfo.newBuilder().setValue(activityMission.getV()).setActivityId(activityId).addAllMission(missionInfos).setStartTime(startTime).setEndTime(endTime).setReallyOpen(activityMission.getOpenType()).build());
  1208. fBuilder.setHadLuckTime(user.getPlayerInfoManager().getLuckWheelLimitTime());
  1209. fBuilder.setHadAdvanceLuckTime(user.getPlayerInfoManager().getLuckAdvanceWheelLimitTime());
  1210. }
  1211. }
  1212. public void checkActivityIsFinish(User user) {
  1213. ActivityManager activityManager = user.getActivityManager();
  1214. Map<Integer, ActivityMission> activityMissionMap = activityManager.getActivityMissionMap();
  1215. // for (Map.Entry<Integer, ActivityMission> item : activityMissionMap.entrySet()) {
  1216. // ActivityMission activityMission = item.getValue();
  1217. // if (activityMission.getActivityState() != ActivityType.OPEN_STATE) {
  1218. // continue;
  1219. // }
  1220. // if(SGlobalActivity.getsGlobalActivityInfo(item.getKey() )==null){
  1221. // activityMissionMap.remove(item.getKey());
  1222. // continue;
  1223. // }
  1224. // checkActivityMissionFinishAndTaked(user.getId(), item.getKey(), activityMission);
  1225. // }
  1226. for (Iterator<Map.Entry<Integer, ActivityMission>> it = activityMissionMap.entrySet().iterator(); it.hasNext(); ) {
  1227. Map.Entry<Integer, ActivityMission> item = it.next();
  1228. ActivityMission activityMission = item.getValue();
  1229. if (activityMission.getActivityState() != ActivityType.OPEN_STATE) {
  1230. continue;
  1231. }
  1232. if (SGlobalActivity.getsGlobalActivityInfo(item.getKey()) == null) {
  1233. it.remove();
  1234. continue;
  1235. }
  1236. checkActivityMissionFinishAndTaked(user.getId(), item.getKey(), activityMission);
  1237. }
  1238. }
  1239. public boolean checkActivityMissionFinishAndTaked(int uid, int activityId, ActivityMission activityMission) {
  1240. Map<Integer, ActivityProgressInfo> activityProgressInfoMap = activityMission.getActivityMissionMap();
  1241. for (Map.Entry<Integer, ActivityProgressInfo> item : activityProgressInfoMap.entrySet()) {
  1242. ActivityProgressInfo activityProgressInfo = item.getValue();
  1243. int missionStatus = activityProgressInfo.getState();
  1244. if (missionStatus == ActivityType.WILL_TAKE) {
  1245. return false;
  1246. }
  1247. // if (SGlobalActivity.getsGlobalActivityMap().get(activityId).getType() == ActivityType.TREASURE) {
  1248. if (SGlobalActivity.getsGlobalActivityTypeInfo(activityId, ActivityType.TREASURE)) {
  1249. if (missionStatus == ActivityType.HAD_TAKED) {
  1250. return false;
  1251. }
  1252. }
  1253. }
  1254. if (activityProgressInfoMap.isEmpty()) {
  1255. return false;
  1256. }
  1257. // SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(activityId);
  1258. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityInfo(activityId);
  1259. if (sGlobalActivity == null) {
  1260. return true;
  1261. }
  1262. if (sGlobalActivity.getResetGrade() == 0) {
  1263. activityMission.setActivityState(ActivityType.FINISH_STATE);
  1264. Poster.getPoster().dispatchEvent(new ActivityStateChangeEvent(uid, activityId, ActivityType.FINISH_STATE));
  1265. }
  1266. return true;
  1267. }
  1268. public int getInitActivityMissionProgress(int activityId) {
  1269. int defalutProgress = 0;
  1270. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityInfo(activityId);
  1271. int activityType = sGlobalActivity.getType();
  1272. switch (activityType) {
  1273. case ActivityType.SevenLogin:
  1274. case ActivityType.NEW_DAY_LOGIN:
  1275. defalutProgress = 1;
  1276. break;
  1277. default:
  1278. break;
  1279. }
  1280. return defalutProgress;
  1281. }
  1282. //秘盒
  1283. public void getSecretBox(ISession session) throws Exception {
  1284. int uid = session.getUid();
  1285. User user = UserManager.getUser(uid);
  1286. SecretBoxManager secretBoxManager = user.getSecretBoxManager();
  1287. if (secretBoxSeasonTimes == 0) {
  1288. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  1289. }
  1290. if (secretBoxManager.getCurSeason() != secretBoxSeasonTimes) {
  1291. flushSecretBoxOfSeasonChange(secretBoxManager);
  1292. }
  1293. PlayerInfoProto.GetSecretBoxInfoResponse build = PlayerInfoProto.GetSecretBoxInfoResponse.newBuilder()
  1294. .setSeason(secretBoxManager.getCurSeason())
  1295. .setCount(secretBoxManager.getCount())
  1296. .build();
  1297. MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.GET_SECRETBOX_RESPONSE_VALUE, build, true);
  1298. }
  1299. public void flushSecretBoxOfSeasonChange(SecretBoxManager secretBoxManager) {
  1300. secretBoxManager.setCount(0);
  1301. secretBoxManager.setCurSeason(secretBoxSeasonTimes);
  1302. }
  1303. public void randomSecretBox(ISession session, int id) throws Exception {
  1304. int uid = session.getUid();
  1305. User user = UserManager.getUser(uid);
  1306. SecretBoxManager secretBoxManager = user.getSecretBoxManager();
  1307. SDifferDemonsBoxSetting sDifferDemonsBoxSetting = SDifferDemonsBoxSetting.getConfig().get(id);
  1308. if (sDifferDemonsBoxSetting == null || sDifferDemonsBoxSetting.getSeasonTimes() != secretBoxSeasonTimes) {
  1309. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  1310. }
  1311. if (secretBoxManager.getCurSeason() != secretBoxSeasonTimes) {
  1312. flushSecretBoxOfSeasonChange(secretBoxManager);
  1313. }
  1314. int randCount = sDifferDemonsBoxSetting.getSecondaryCost();
  1315. boolean allowedFree = false;
  1316. if (randCount == 1) {
  1317. allowedFree = PlayerLogic.getInstance().checkAndUpdate(user, VipPrivilegeType.FREE_SECRET_RANDOM, 1);
  1318. }
  1319. if (!allowedFree) {
  1320. int[][] mainCost = sDifferDemonsBoxSetting.getMainCost();
  1321. boolean enough = ItemUtil.itemCost(user, mainCost, BIReason.SECRETBOX_CONSUME, id);
  1322. if (!enough) {
  1323. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  1324. }
  1325. }
  1326. int count = secretBoxManager.getCount();
  1327. int[][] randDrop = new int[randCount][];
  1328. for (int i = 1; i <= randCount; i++) {
  1329. int secretBoxRandomPool = getSecretBoxRandomPool(sDifferDemonsBoxSetting, count + i);
  1330. int[] dropInfos = getSecretBoxRewardByPool(secretBoxRandomPool);
  1331. randDrop[i - 1] = dropInfos;
  1332. }
  1333. secretBoxManager.setCount(secretBoxManager.getCount() + randCount);
  1334. CommonProto.Drop.Builder drop = ItemUtil.dropPer(user, randDrop, BIReason.TAKE_SECRET_REWARD);
  1335. int[] extraItem = sDifferDemonsBoxSetting.getExtraItem();
  1336. CommonProto.Drop.Builder extraDrop = ItemUtil.drop(user, new int[][]{extraItem}, BIReason.TAKE_SECRET_EXTRA_REWARD);
  1337. PlayerInfoProto.SecretBoxRandomResponse build = PlayerInfoProto.SecretBoxRandomResponse.newBuilder().setDrop(drop).setExtrarReward(extraDrop).build();
  1338. MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.SECRETBOX_RANDOM_RESPONSE_VALUE, build, true);
  1339. user.getUserMissionManager().onGameEvent(user, GameEvent.SECRETBOX, id, randCount);
  1340. Poster.getPoster().dispatchEvent(new SecretBoxEvent(uid, randCount));
  1341. }
  1342. private int[] getSecretBoxRewardByPool(int secretBoxRandomPool) {
  1343. List<SDifferDemonsBoxPools> sDifferDemonsBoxPoolsList = SDifferDemonsBoxPools.getsDifferDemonsBoxPoolByPoolId(secretBoxRandomPool);
  1344. int totalWeight = 0;
  1345. for (SDifferDemonsBoxPools sDifferDemonsBoxPool : sDifferDemonsBoxPoolsList) {
  1346. totalWeight += sDifferDemonsBoxPool.getWeight();
  1347. }
  1348. int randomWeight = MathUtils.randomInt(totalWeight) + 1;
  1349. for (SDifferDemonsBoxPools sDifferDemonsBoxPool : sDifferDemonsBoxPoolsList) {
  1350. randomWeight -= sDifferDemonsBoxPool.getWeight();
  1351. if (randomWeight <= 0) {
  1352. return sDifferDemonsBoxPool.getReward();
  1353. }
  1354. }
  1355. return null;
  1356. }
  1357. private int getSecretBoxRandomPool(SDifferDemonsBoxSetting sDifferDemonsBoxSetting, int count) {
  1358. int seasonTimes = sDifferDemonsBoxSetting.getSeasonTimes();
  1359. int poolId = 0;
  1360. List<SDifferDemonsBoxSeaons> sDifferDemonsBoxSeaonList = SDifferDemonsBoxSeaons.getsDifferDemonsBoxSeaonsBySeason(seasonTimes);
  1361. for (SDifferDemonsBoxSeaons sDifferDemonsBoxSeaons : sDifferDemonsBoxSeaonList) {
  1362. int surelyTimes = sDifferDemonsBoxSeaons.getSurelyTimes();
  1363. if (count % surelyTimes != 0) {
  1364. continue;
  1365. }
  1366. if (count / surelyTimes > 0) {
  1367. poolId = sDifferDemonsBoxSeaons.getSurelyPools();
  1368. }
  1369. }
  1370. if (poolId == 0) {
  1371. poolId = sDifferDemonsBoxSetting.getRandomPool();
  1372. }
  1373. return poolId;
  1374. }
  1375. public void checkSecretBoxSeason() {
  1376. try {
  1377. long now = TimeUtils.now();
  1378. int newSecretBoxSeasonTimes = 0;
  1379. for (SDifferDemonsBoxSetting sDifferDemonsBoxSetting : SDifferDemonsBoxSetting.getConfig().values()) {
  1380. long seasonStartLong = sDifferDemonsBoxSetting.getSeasonStartLong();
  1381. long seasonEndLong = sDifferDemonsBoxSetting.getSeasonEndLong();
  1382. if (now >= seasonStartLong && now <= seasonEndLong) {
  1383. newSecretBoxSeasonTimes = sDifferDemonsBoxSetting.getSeasonTimes();
  1384. break;
  1385. }
  1386. }
  1387. if (newSecretBoxSeasonTimes != secretBoxSeasonTimes) {
  1388. secretBoxSeasonTimes = newSecretBoxSeasonTimes;
  1389. PlayerInfoProto.UpdateSecretBoxSeasonIndication build = PlayerInfoProto.UpdateSecretBoxSeasonIndication.newBuilder().setNewSeasonId(newSecretBoxSeasonTimes).build();
  1390. MessageUtil.sendAllOnlineUserMsg(MessageTypeProto.MessageType.UPDATE_SECRET_BOX_SEASON_INDICATION_VALUE, build);
  1391. }
  1392. } catch (Exception e) {
  1393. LOGGER.error("Exception::=>{}", e.toString());
  1394. }
  1395. }
  1396. private int getBlessActivityId(User user) {
  1397. Map<Integer, ActivityMission> activityMissionMap = user.getActivityManager().getActivityMissionMap();
  1398. for (Integer activityId : activityMissionMap.keySet()) {
  1399. if (SGlobalActivity.getsGlobalActivityMap().get(activityId).getType() == ActivityType.BLESSACTIVITY) {
  1400. return activityId;
  1401. }
  1402. }
  1403. return 0;
  1404. }
  1405. /**
  1406. * 云梦抽取
  1407. *
  1408. * @param session
  1409. * @param locationId
  1410. * @param messageType
  1411. * @throws Exception
  1412. */
  1413. public void blessChoose(ISession session, int locationId, MessageTypeProto.MessageType messageType) throws Exception {
  1414. User user = UserManager.getUser(session.getUid());
  1415. int blessActivityId = getBlessActivityId(user);
  1416. if (blessActivityId == 0) {
  1417. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  1418. }
  1419. ActivityMission activityMission = user.getActivityManager().getActivityMissionMap().get(blessActivityId);
  1420. if (activityMission == null) {
  1421. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  1422. }
  1423. Map<Integer, ActivityProgressInfo> activityProgressInfoMap = activityMission.getActivityMissionMap();
  1424. if (activityProgressInfoMap.get(locationId + BlessInfoConfig.START_CAPACITY).getProgrss() != 0) {
  1425. throw new ErrorCodeException(ErrorCode.REWARD_DRAWN);
  1426. }
  1427. int resultRewardId = 0;
  1428. if (activityProgressInfoMap.get(BlessInfoConfig.BLESS_STATUS).getProgrss() == -1) {
  1429. Map<Integer, SBlessingRewardPool> poolMap = STableManager.getConfig(SBlessingRewardPool.class);
  1430. int[][] result = new int[BlessInfoConfig.START_CAPACITY][];
  1431. int index = 0;
  1432. for (Map.Entry<Integer, ActivityProgressInfo> entry : activityProgressInfoMap.entrySet()) {
  1433. if (entry.getKey() > BlessInfoConfig.START_CAPACITY) {
  1434. continue;
  1435. }
  1436. int[] temp = new int[2];
  1437. temp[0] = entry.getValue().getProgrss();
  1438. temp[1] = poolMap.get(entry.getValue().getProgrss()).getExtractWeight();
  1439. result[index] = temp;
  1440. index++;
  1441. }
  1442. int[] order = MathUtils.randomFromWeightWithTaking(result, BlessInfoConfig.START_CAPACITY);
  1443. for (int i = 0; i < order.length; i++) {
  1444. LOGGER.info("获取顺序{}", order[i]);
  1445. }
  1446. index = 0;
  1447. for (Map.Entry<Integer, ActivityProgressInfo> entry : activityProgressInfoMap.entrySet()) {
  1448. if (entry.getKey() > BlessInfoConfig.START_CAPACITY) {
  1449. continue;
  1450. }
  1451. ActivityProgressInfo progress = new ActivityProgressInfo();
  1452. progress.setProgrss(order[index]);
  1453. activityMission.getActivityMissionMap().put(entry.getKey(), progress);
  1454. index++;
  1455. }
  1456. // ActivityProgressInfo activityProgressInfo1 = activityProgressInfoMap.getOrDefault(BlessInfoConfig.BLESS_PROGRESS_STATUS,new ActivityProgressInfo());
  1457. // activityProgressInfo1.setProgrss(activityProgressInfo1.getProgrss()+1);
  1458. // activityProgressInfo1.setState(0);
  1459. // activityMission.getActivityMissionMap().put(BlessInfoConfig.BLESS_PROGRESS_STATUS,activityProgressInfo1);
  1460. activityMission.getActivityMissionMap().put(BlessInfoConfig.BLESS_STATUS, new ActivityProgressInfo());
  1461. // activityMission.updateProgressInfo(BlessInfoConfig.BLESS_PROGRESS_STATUS, new ActivityProgressInfo(1, 0));
  1462. }
  1463. ActivityProgressInfo activityProgressInfo1 = new ActivityProgressInfo();
  1464. activityProgressInfo1.setProgrss(activityProgressInfoMap.get(BlessInfoConfig.BLESS_PROGRESS_STATUS).getProgrss() + 1);
  1465. activityProgressInfo1.setState(0);
  1466. activityMission.getActivityMissionMap().put(BlessInfoConfig.BLESS_PROGRESS_STATUS, activityProgressInfo1);
  1467. //检验消耗道具
  1468. int[][] costConfig = SBlessingConfig.blessingConfigMap.get(blessActivityId).getCost();
  1469. int[][] cost = new int[1][];
  1470. int[] temp = new int[2];
  1471. temp[0] = costConfig[0][0];
  1472. temp[1] = (int) MathUtils.calABX(activityProgressInfoMap.get(BlessInfoConfig.BLESS_PROGRESS_STATUS).getProgrss(), costConfig[1]);
  1473. cost[0] = temp;
  1474. LOGGER.info("本次为第{}次抽取,消耗{}个数为{}", activityProgressInfoMap.get(BlessInfoConfig.BLESS_PROGRESS_STATUS).getProgrss(), temp[0], temp[1]);
  1475. boolean costResult = ItemUtil.itemCost(user, cost, BIReason.BLESS_CHOOSE_CONSUME, 1);
  1476. if (!costResult) {
  1477. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  1478. }
  1479. if (activityProgressInfoMap.get(BlessInfoConfig.BLESS_PROGRESS_STATUS).getProgrss() > 0) {
  1480. for (Map.Entry<Integer, ActivityProgressInfo> entry : activityProgressInfoMap.entrySet()) {
  1481. if (entry.getKey() > BlessInfoConfig.START_CAPACITY) {
  1482. continue;
  1483. }
  1484. if (entry.getValue().getProgrss() == 0) {
  1485. continue;
  1486. }
  1487. resultRewardId = entry.getValue().getProgrss();
  1488. ActivityProgressInfo progress = new ActivityProgressInfo();
  1489. progress.setProgrss(entry.getValue().getProgrss());
  1490. activityMission.getActivityMissionMap().put(locationId + BlessInfoConfig.START_CAPACITY, progress);
  1491. activityMission.getActivityMissionMap().put(entry.getKey(), new ActivityProgressInfo());
  1492. break;
  1493. }
  1494. }
  1495. LOGGER.info("本次抽取的Id为{}", resultRewardId);
  1496. Map<Integer, SBlessingRewardPool> poolMap = STableManager.getConfig(SBlessingRewardPool.class);
  1497. int[][] dropItem = new int[1][];
  1498. for (Integer count : SBlessingConfig.blessingConfigMap.get(blessActivityId).getCounts()) {
  1499. if (count != activityProgressInfoMap.get(BlessInfoConfig.BLESS_PROGRESS_STATUS).getProgrss()) {
  1500. continue;
  1501. }
  1502. dropItem = new int[2][];
  1503. dropItem[1] = poolMap.get(activityProgressInfoMap.get(BlessInfoConfig.COUNT_REWARD_START_ID + count).getProgrss()).getReward();
  1504. break;
  1505. }
  1506. int[] reward = poolMap.get(resultRewardId).getReward();
  1507. dropItem[0] = reward;
  1508. CommonProto.Drop.Builder drop = ItemUtil.dropPer(user, dropItem, BIReason.BLESS_REWARD);
  1509. // if (activityProgressInfoMap.get(BlessInfoConfig.BLESS_PROGRESS_STATUS).getProgrss() == BlessInfoConfig.START_CAPACITY + 1) {
  1510. // if (SBlessingConfig.sBlessingConfig.getIsRefresh() != 0) {
  1511. // blessRefresh(user);
  1512. // }
  1513. // }
  1514. PlayerInfoProto.blessChooseResponse response = PlayerInfoProto.blessChooseResponse.newBuilder().setReward(drop).setChooseRewardId(resultRewardId).build();
  1515. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
  1516. }
  1517. //云梦请求数据
  1518. public void blessInfo(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
  1519. User user = UserManager.getUser(session.getUid());
  1520. int blessActivityId = getBlessActivityId(user);
  1521. if (blessActivityId == 0) {
  1522. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  1523. }
  1524. ActivityMission activityMission = user.getActivityManager().getActivityMissionMap().get(blessActivityId);
  1525. if (activityMission == null) {
  1526. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  1527. }
  1528. PlayerInfoProto.blessResponse.Builder response = getBlessInfoResponse(activityMission);
  1529. // LOGGER.info("{},{},{}",response.getFixRewardList().toString(),response.getLegendRewardList().toString(),response.getSupremeRewardList().toString());
  1530. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response.build(), true);
  1531. }
  1532. public PlayerInfoProto.blessResponse.Builder getBlessInfoResponse(ActivityMission activityMission) {
  1533. PlayerInfoProto.blessResponse.Builder response = PlayerInfoProto.blessResponse.newBuilder();
  1534. Map<Integer, ActivityProgressInfo> blessInfoMap = activityMission.getActivityMissionMap();
  1535. //保存之前
  1536. if (blessInfoMap.get(BlessInfoConfig.BLESS_STATUS).getProgrss() == -1) {
  1537. for (Map.Entry<Integer, ActivityProgressInfo> entry : blessInfoMap.entrySet()) {
  1538. if (entry.getKey() / BlessInfoConfig.COUNT_REWARD_START_ID > 0) {
  1539. CommonProto.blessReward blessReward = CommonProto.blessReward.newBuilder()
  1540. .setLocationId(entry.getKey() % BlessInfoConfig.COUNT_REWARD_START_ID)
  1541. .setState(0)
  1542. .setRewardId(entry.getValue().getProgrss())
  1543. .build();
  1544. response.addCountReward(blessReward);
  1545. continue;
  1546. } else if (entry.getKey() / BlessInfoConfig.SUPREME_REWARD_START_ID > 0) {
  1547. CommonProto.blessReward blessReward = CommonProto.blessReward.newBuilder()
  1548. .setLocationId(entry.getKey() % BlessInfoConfig.SUPREME_REWARD_START_ID + 1)
  1549. .setState(0)
  1550. .setRewardId(entry.getValue().getProgrss())
  1551. .build();
  1552. response.addSupremeReward(blessReward);
  1553. continue;
  1554. } else if (entry.getKey() / BlessInfoConfig.LEGEND_REWARD_START_ID > 0) {
  1555. CommonProto.blessReward blessReward = CommonProto.blessReward.newBuilder()
  1556. .setLocationId(entry.getKey() % BlessInfoConfig.LEGEND_REWARD_START_ID + 1)
  1557. .setState(0)
  1558. .setRewardId(entry.getValue().getProgrss())
  1559. .build();
  1560. response.addLegendReward(blessReward);
  1561. continue;
  1562. } else if (entry.getKey() <= BlessInfoConfig.START_CAPACITY) {
  1563. CommonProto.blessReward blessReward = CommonProto.blessReward.newBuilder()
  1564. .setLocationId(entry.getKey())
  1565. .setState(0)
  1566. .setRewardId(entry.getValue().getProgrss())
  1567. .build();
  1568. response.addFixReward(blessReward);
  1569. }
  1570. }
  1571. } else {//保存之后
  1572. for (Map.Entry<Integer, ActivityProgressInfo> entry : blessInfoMap.entrySet()) {
  1573. if (entry.getKey() / BlessInfoConfig.COUNT_REWARD_START_ID > 0) {
  1574. CommonProto.blessReward blessReward = CommonProto.blessReward.newBuilder()
  1575. .setLocationId(entry.getKey() % BlessInfoConfig.COUNT_REWARD_START_ID)
  1576. .setState(1)
  1577. .setRewardId(entry.getValue().getProgrss())
  1578. .build();
  1579. response.addCountReward(blessReward);
  1580. continue;
  1581. } else if (entry.getKey() / BlessInfoConfig.SUPREME_REWARD_START_ID > 0) {
  1582. CommonProto.blessReward blessReward = CommonProto.blessReward.newBuilder()
  1583. .setLocationId(entry.getKey() % BlessInfoConfig.SUPREME_REWARD_START_ID + 1)
  1584. .setState(1)
  1585. .setRewardId(entry.getValue().getProgrss())
  1586. .build();
  1587. response.addSupremeReward(blessReward);
  1588. continue;
  1589. } else if (entry.getKey() / BlessInfoConfig.LEGEND_REWARD_START_ID > 0) {
  1590. CommonProto.blessReward blessReward = CommonProto.blessReward.newBuilder()
  1591. .setLocationId(entry.getKey() % BlessInfoConfig.LEGEND_REWARD_START_ID + 1)
  1592. .setState(1)
  1593. .setRewardId(entry.getValue().getProgrss())
  1594. .build();
  1595. response.addLegendReward(blessReward);
  1596. continue;
  1597. }
  1598. }
  1599. for (int i = BlessInfoConfig.CHOOSE_START_ID; i <= BlessInfoConfig.REWARD_VIEW_END_ID; i++) {
  1600. for (Map.Entry<Integer, ActivityProgressInfo> entry : blessInfoMap.entrySet()) {
  1601. if (entry.getKey() != i) {
  1602. continue;
  1603. }
  1604. if (i < BlessInfoConfig.REWARD_VIEW_START_ID) {
  1605. // LOGGER.info("显示顺序是{}", entry.getKey());
  1606. CommonProto.blessReward blessReward = CommonProto.blessReward.newBuilder()
  1607. .setLocationId(i - BlessInfoConfig.START_CAPACITY)
  1608. .setState(1)
  1609. .setRewardId(entry.getValue().getProgrss())
  1610. .build();
  1611. response.addFixReward(blessReward);
  1612. } else {
  1613. CommonProto.blessReward blessReward = CommonProto.blessReward.newBuilder()
  1614. .setLocationId(i - BlessInfoConfig.CHOOSE_END_ID)
  1615. .setState(1)
  1616. .setRewardId(entry.getValue().getProgrss())
  1617. .build();
  1618. response.addRewardView(blessReward);
  1619. }
  1620. }
  1621. }
  1622. }
  1623. response.setCount(blessInfoMap.get(BlessInfoConfig.BLESS_PROGRESS_STATUS).getProgrss());
  1624. response.setLastRefreshTime(blessInfoMap.get(BlessInfoConfig.LAST_REFRESH_TIME).getProgrss());
  1625. return response;
  1626. }
  1627. public void blessSaveOptionalReward(ISession session, int[] rewardIds, MessageTypeProto.MessageType messageType) throws Exception {
  1628. User user = UserManager.getUser(session.getUid());
  1629. // for(Map.Entry<Integer,SBlessingConfig> entry:SBlessingConfig.blessingConfigMap.entrySet()){
  1630. //
  1631. // int activityOpenState = getActivityOpenState(user, entry.getKey());
  1632. // if(activityOpenState==ActivityType.OPEN_STATE){
  1633. // blessingConfig = entry.getValue();
  1634. // continue;
  1635. // }
  1636. // }
  1637. int blessActivityId = getBlessActivityId(user);
  1638. if (blessActivityId == 0) {
  1639. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  1640. }
  1641. SBlessingConfig blessingConfig = SBlessingConfig.blessingConfigMap.get(blessActivityId);
  1642. ActivityMission activityMission = user.getActivityManager().getActivityMissionMap().get(blessActivityId);
  1643. if (activityMission.getActivityMissionMap().get(BlessInfoConfig.BLESS_STATUS).getProgrss() != -1) {
  1644. throw new ErrorCodeException(ErrorCode.CANNOT_SAVE);
  1645. }
  1646. if (blessingConfig.getRandomNum() != BlessInfoConfig.START_CAPACITY - rewardIds.length) {
  1647. throw new ErrorCodeException(ErrorCode.NUM_ERR);
  1648. }
  1649. for (int i = 0; i < rewardIds.length; i++) {
  1650. ActivityProgressInfo info = new ActivityProgressInfo();
  1651. info.setProgrss(rewardIds[i]);
  1652. activityMission.getActivityMissionMap().put(i + 1, info);
  1653. }
  1654. //奖励预览赋值
  1655. for (int i = 0; i < BlessInfoConfig.START_CAPACITY; i++) {
  1656. activityMission.getActivityMissionMap().put(i + BlessInfoConfig.REWARD_VIEW_START_ID, activityMission.getActivityMissionMap().get(i + 1));
  1657. }
  1658. ActivityProgressInfo activityProgressInfo1 = new ActivityProgressInfo();
  1659. activityProgressInfo1.setProgrss(0);
  1660. activityProgressInfo1.setState(0);
  1661. activityMission.getActivityMissionMap().put(BlessInfoConfig.BLESS_STATUS, activityProgressInfo1);
  1662. MessageUtil.sendMessage(session, 1, messageType.getNumber(), null, true);
  1663. }
  1664. /**
  1665. * 云梦手动刷新
  1666. *
  1667. * @param session
  1668. * @param messageType
  1669. * @throws Exception
  1670. */
  1671. public void blessRefreshReward(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
  1672. User user = UserManager.getUser(session.getUid());
  1673. // ActivityMission activityMission = blessRefresh(user);
  1674. //
  1675. // Poster.getPoster().dispatchEvent(new BlessInfoRefreshEvent(session.getUid()));
  1676. // ActivityProgressInfo newInfo = new ActivityProgressInfo();
  1677. //// newInfo.setState();
  1678. //// activityMission.getActivityMissionMap().put(BlessInfoConfig.LAST_REFRESH_TIME, new ActivityProgressInfo((int) (TimeUtils.now() / 1000), 0));
  1679. // PlayerInfoProto.blessRefresh res = PlayerInfoProto.blessRefresh.newBuilder().setReward(getBlessInfoResponse(activityMission).build()).build();
  1680. // MessageUtil.sendMessage(session, 1, messageType.getNumber(), res, true);
  1681. Poster.getPoster().dispatchEvent(new BlessInfoRefreshEvent(session.getUid()));
  1682. }
  1683. // /**
  1684. // * 获取战力排行榜
  1685. // */
  1686. // public void getForceRank(ISession session, int page, int acitvityId) throws Exception {
  1687. //
  1688. // if (page == 0) {
  1689. // page = 1;
  1690. // }
  1691. // int start = (page - 1) * 20, end = page * 20 - 1;
  1692. // List<CommonProto.UseForceInfo> useForceInfoList = new ArrayList<>(20);
  1693. // Set<ZSetOperations.TypedTuple<String>> rankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.FORCE_RANK,"", start, end);
  1694. // for (ZSetOperations.TypedTuple<String> item : rankInfo) {
  1695. // String value = item.getValue();
  1696. // int score = item.getScore().intValue();
  1697. // int uid = Integer.parseInt(value);
  1698. // User user = UserManager.getUser(uid, true);
  1699. // if (null == user) {
  1700. // continue;
  1701. // }
  1702. // PlayerManager playerInfoManager = user.getPlayerInfoManager();
  1703. // CommonProto.UseForceInfo personInfoBuild = CommonProto.UseForceInfo.newBuilder()
  1704. // .setLeve(playerInfoManager.getLevel())
  1705. // .setName(playerInfoManager.getNickName())
  1706. // .setForce(score)
  1707. // .setRank(++start)
  1708. // .setHeadFrame(playerInfoManager.getHeadFrame())
  1709. // .setHead(playerInfoManager.getHead())
  1710. // .setUid(uid)
  1711. // .build();
  1712. // useForceInfoList.add(personInfoBuild);
  1713. // }
  1714. //
  1715. // int uid = session.getUid();
  1716. //// int score = RedisUtil.getInstence().getZSetScore(RedisKey.FORCE_RANK, "", Integer.toString(uid)).intValue();
  1717. // int score = Double.valueOf(RankContext.getRankEnum(RankEnum.FORCE_RANK.getType()).getScoreById(uid)).intValue();
  1718. // int myRank = RedisUtil.getInstence().getZSetreverseRank(RedisKey.FORCE_RANK, "", Integer.toString(uid)).intValue();
  1719. //
  1720. // PlayerInfoProto.GetForceRankInfoResponse buildResponse = PlayerInfoProto.GetForceRankInfoResponse.newBuilder()
  1721. // .setMyRank(myRank)
  1722. // .setMyForce(score)
  1723. // .addAllUseForceInfo(useForceInfoList)
  1724. // .build();
  1725. // MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.GETF_FORCE_RANK_INFO_RESPONSE_VALUE, buildResponse, true);
  1726. //
  1727. // }
  1728. /**
  1729. * 获取达人排行榜
  1730. */
  1731. public void getExpertRank(ISession session, int acitvityId) throws Exception {
  1732. int start = 0;
  1733. int maxSize = STableManager.getFigureConfig(CommonStaticConfig.class).getGameSetting().getShowRank();
  1734. List<CommonProto.ExpertInfo> expertInfos = new LinkedList<>();
  1735. Set<ZSetOperations.TypedTuple<String>> rankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.EXPERT_RANK, Integer.toString(acitvityId), 0, maxSize - 1);
  1736. for (ZSetOperations.TypedTuple<String> item : rankInfo) {
  1737. String value = item.getValue();
  1738. int score = item.getScore().intValue();
  1739. int uid = Integer.parseInt(value);
  1740. User user = UserManager.getUser(uid, true);
  1741. if (null == user) {
  1742. continue;
  1743. }
  1744. PlayerManager playerInfoManager = user.getPlayerInfoManager();
  1745. CommonProto.ExpertInfo personInfoBuild = CommonProto.ExpertInfo.newBuilder()
  1746. .setName(playerInfoManager.getNickName())
  1747. .setScore(score)
  1748. .setLevel(playerInfoManager.getLevel())
  1749. .setHeadFrame(playerInfoManager.getHeadFrame())
  1750. .setHead(playerInfoManager.getHead())
  1751. .setRank(++start)
  1752. .build();
  1753. expertInfos.add(personInfoBuild);
  1754. }
  1755. //策划要全部数据
  1756. // if (rankInfo.size() > 2 * maxSize) {
  1757. // //删除多余数据 预留一些 长度maxSize
  1758. // String key = RedisKey.getKey(RedisKey.EXPERT_RANK, String.valueOf(acitvityId), false);
  1759. // int size = RedisUtil.getInstence().getZsetSize(key);
  1760. // RedisUtil.getInstence().removeZSetRangeByRank(key, maxSize, size);
  1761. // }
  1762. int uid = session.getUid();
  1763. int score = RedisUtil.getInstence().getZSetScore(RedisKey.EXPERT_RANK, Integer.toString(acitvityId), Integer.toString(uid)).intValue();
  1764. int myRank = RedisUtil.getInstence().getZSetreverseRank(RedisKey.EXPERT_RANK, Integer.toString(acitvityId), Integer.toString(uid)).intValue();
  1765. PlayerInfoProto.GetExpertInfoResponse buildResponse = PlayerInfoProto.GetExpertInfoResponse.newBuilder()
  1766. .setMyRank(myRank)
  1767. .addAllExpert(expertInfos)
  1768. .setMyScore(score)
  1769. .build();
  1770. MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.GETF_EXPERT_RANK_INFO_RESPONSE_VALUE, buildResponse, true);
  1771. }
  1772. /**
  1773. * 我要变强
  1774. *
  1775. * @param session
  1776. * @param messageType
  1777. */
  1778. public void toBeStronger(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
  1779. User user = UserManager.getUser(session.getUid());
  1780. user.getUserMissionManager().onGameEvent(user, GameEvent.TO_BE_STRONGER);
  1781. // PlayerInfoProto.GetToBeStrongerResponse.Builder response = PlayerInfoProto.GetToBeStrongerResponse.newBuilder();
  1782. // for(int i = 0 ; i <6;i++){
  1783. // CommonProto.StrongerInfo.Builder info = CommonProto.StrongerInfo.newBuilder().setCurScore(1000).setMaxScore(6000);
  1784. // response.addInfos(info.build());
  1785. // }
  1786. MessageUtil.sendMessage(session, 1, messageType.getNumber(), null, true);
  1787. }
  1788. /**
  1789. * 戒灵秘宝直接购买等级
  1790. *
  1791. * @param session
  1792. * @param messageType
  1793. * @throws Exception
  1794. */
  1795. public void treasureBuyLevel(ISession session, int level, MessageTypeProto.MessageType messageType) throws Exception {
  1796. User user = UserManager.getUser(session.getUid());
  1797. int treasureLevel = user.getPlayerInfoManager().getTreasureLevel();
  1798. if (level <= treasureLevel) {
  1799. throw new ErrorCodeException(ErrorCode.LEVEL_ERR);
  1800. }
  1801. int num = 0;
  1802. int[][] cost = SSpecialConfig.getTwiceArrayValue(SSpecialConfig.SUNLONG_COST);
  1803. //这段代码并没有实现每一级相同的购买价格???
  1804. /*for(int i = level;i>treasureLevel;i--){
  1805. num+=MathUtils.calABX(i,cost[1]);
  1806. }*/
  1807. num = (int) MathUtils.calABX(level - treasureLevel, cost[1]);
  1808. int[][] costItems = new int[1][];
  1809. int[] costTemp = {cost[0][0], num};
  1810. costItems[0] = costTemp;
  1811. boolean result = ItemUtil.itemCost(user, costItems, BIReason.TREASURE_BUY_LEVEL_CONSUME, 1);
  1812. if (result) {
  1813. user.getPlayerInfoManager().setTreasureLevel(level);
  1814. } else {
  1815. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  1816. }
  1817. PlayerInfoProto.TreasureLevelUpIndication indication = PlayerInfoProto.TreasureLevelUpIndication.newBuilder().setLevel(user.getPlayerInfoManager().getTreasureLevel()).build();
  1818. MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.TREASURE_LEVELUP_INDICATION_VALUE, indication, true);
  1819. MessageUtil.sendMessage(session, 1, messageType.getNumber(), null, true);
  1820. }
  1821. public Set<Integer> getActivityStatusByType(User user, int type) {
  1822. List<SGlobalActivity> activities = SGlobalActivity.sGlobalActivityMapByType.get(type);
  1823. if (activities.isEmpty()) {
  1824. return new HashSet<>();
  1825. } else {
  1826. Set<Integer> objects = activities.stream().filter(n -> user.getActivityManager().getActivityMissionMap().keySet().contains(n.getId())).map(sGlobalActivity -> sGlobalActivity.getId()).collect(Collectors.toSet());
  1827. return objects;
  1828. }
  1829. }
  1830. public void getNextActivityId(ISession session, int activityId, MessageTypeProto.MessageType messageType) throws Exception {
  1831. User user = UserManager.getUser(session.getUid());
  1832. List<SGlobalActivity> sGlobalActivities = SGlobalActivity.sGlobalActivityMapByType.get(activityId);
  1833. if (sGlobalActivities.isEmpty()) {
  1834. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  1835. }
  1836. Function<SGlobalActivity, Integer> function = v -> (int) ToolsUtil.getTimeLong(v.getStartTimeLong(), v.getEndTimeLong(), v.getTime(), user.getPlayerInfoManager().getCreateTime(), 1);
  1837. Stream<SGlobalActivity> stream = sGlobalActivities.stream().sorted(Comparator.comparing(function))
  1838. .filter(v -> ToolsUtil.getTimeLong(v.getStartTimeLong(), v.getEndTimeLong(), v.getTime(), user.getPlayerInfoManager().getCreateTime(), 1) > TimeUtils.now());
  1839. List<SGlobalActivity> collect = stream.collect(Collectors.toList());
  1840. if (collect.isEmpty()) {
  1841. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  1842. }
  1843. int id = collect.get(0).getId();
  1844. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(id);
  1845. if (sGlobalActivity == null) {
  1846. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_ON);
  1847. }
  1848. long startTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), user.getPlayerInfoManager().getCreateTime(), 1);
  1849. PlayerInfoProto.NextActivityResponse response = PlayerInfoProto.NextActivityResponse.newBuilder().setId(id).setTime((int) (startTime / 1000)).build();
  1850. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
  1851. }
  1852. public void getTreasureNextRefreshTime(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
  1853. int dayRefreshTime = (int) (TimeUtils.getLastOrUnderHour(TimeUtils.now(), 0, 0, false) / 1000);
  1854. //int weekRefreshTime = (int) (TimeUtils.getNextWeekendStartTime(1, 0) / 1000);
  1855. User user = UserManager.getUser(session.getUid());
  1856. long _time = getTreasureNextWeekRefreshTime(user);
  1857. int weekRefreshTime = (int)(_time/1000);
  1858. long checkTime = TimeUtils.getTimeBeforeOrAfterMinute(_time,-7 * 24 * TimeUtils.MIN_HOUR);
  1859. long weekRefresh = user.getUserMissionManager().getTreasureMissionIdsType().getWeekRefresh();
  1860. if(checkTime != weekRefresh) {//修复线上玩家的时间不对问题
  1861. LOGGER.info("check uid:{},checkTime:{},weekRefresh:{}",user.getId(),checkTime,weekRefresh);
  1862. user.getUserMissionManager().getTreasureMissionIdsType().setWeekRefresh(checkTime);
  1863. }
  1864. PlayerInfoProto.TreasureRefreshTimeResponse response = PlayerInfoProto.TreasureRefreshTimeResponse.newBuilder().setDayTime(dayRefreshTime).setWeekTime(weekRefreshTime).build();
  1865. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
  1866. }
  1867. public long getTreasureNextWeekRefreshTime(User user){
  1868. Set<Integer> activityIds = getActivityStatusByType(user,ActivityType.TREASURE);
  1869. long result = 0;
  1870. if(!activityIds.isEmpty()){
  1871. int activityId = activityIds.stream().findFirst().get();
  1872. long startTime = getSeasonActivityStartAndEndTime(user,activityId)[0];
  1873. long now = System.currentTimeMillis();
  1874. if(startTime > 0) {
  1875. long _time;
  1876. for(int i = 1; i < 999999; i++) {
  1877. _time = TimeUtils.getTimeBeforeOrAfterMinute(startTime,i * 7 * 24 * TimeUtils.MIN_HOUR);
  1878. if(_time > now) {
  1879. result = _time;
  1880. break;
  1881. }
  1882. }
  1883. }
  1884. }
  1885. return result;
  1886. }
  1887. // public void getTreasureNextRefreshTime(ISession session,MessageTypeProto.MessageType messageType) throws Exception {
  1888. // int dayRefreshTime=(int) (TimeUtils.getLastOrUnderHour(TimeUtils.now(), 5,0, false)/1000);
  1889. // int uid = session.getUid();
  1890. // User user = UserManager.getUser(uid);
  1891. // PlayerInfoProto.TreasureRefreshTimeResponse response;
  1892. // if(user.getActivityManager().getActivityMissionMap().containsKey(801)){
  1893. // int weekRefreshTime = (int)(TimeUtils.getNextWeekendStartTime(1,5)/1000);
  1894. // response = PlayerInfoProto.TreasureRefreshTimeResponse.newBuilder().setDayTime(dayRefreshTime).setWeekTime(weekRefreshTime).build();
  1895. // }else{
  1896. // long weekRefresh = user.getUserMissionManager().getTreasureMissionIdsType().getWeekRefresh();
  1897. // response = PlayerInfoProto.TreasureRefreshTimeResponse.newBuilder().setDayTime(dayRefreshTime).setWeekTime((int)(weekRefresh/1000)).build();
  1898. // }
  1899. // MessageUtil.sendMessage(session,1,messageType.getNumber(),response,true);
  1900. // }
  1901. public void getJadeDynastyNextRefreshTime(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
  1902. int dayRefreshTime = (int) (TimeUtils.getLastOrUnderHour(TimeUtils.now(), 0, 0, false) / 1000);
  1903. int weekRefreshTime = (int) (TimeUtils.getNextWeekendStartTime(1, 0) / 1000);
  1904. PlayerInfoProto.JadeDynastyRefreshTimeResponse response = PlayerInfoProto.JadeDynastyRefreshTimeResponse.newBuilder().setDayTime(dayRefreshTime).setWeekTime(weekRefreshTime).build();
  1905. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
  1906. }
  1907. public void getShengDanNextRefreshTime(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
  1908. int dayRefreshTime = (int) (TimeUtils.getLastOrUnderHour(TimeUtils.now(), 0, 0, false) / 1000);
  1909. int weekRefreshTime = (int) (TimeUtils.getNextWeekendStartTime(1, 0) / 1000);
  1910. PlayerInfoProto.ShengDanRefreshTimeResponse response = PlayerInfoProto.ShengDanRefreshTimeResponse.newBuilder().setDayTime(dayRefreshTime).setWeekTime(weekRefreshTime).build();
  1911. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
  1912. }
  1913. public void getMysticalInstructNextRefreshTime(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
  1914. int dayRefreshTime = (int) (TimeUtils.getLastOrUnderHour(TimeUtils.now(), 0, 0, false) / 1000);
  1915. int weekRefreshTime = (int) (TimeUtils.getNextWeekendStartTime(1, 0) / 1000);
  1916. PlayerInfoProto.MysticalInstructRefreshTimeResponse response = PlayerInfoProto.MysticalInstructRefreshTimeResponse.newBuilder().setDayTime(dayRefreshTime).setWeekTime(weekRefreshTime).build();
  1917. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
  1918. }
  1919. public void getHeroCollectNextRefreshTime(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
  1920. int dayRefreshTime = (int) (TimeUtils.getLastOrUnderHour(TimeUtils.now(), 0, 0, false) / 1000);
  1921. int weekRefreshTime = (int) (TimeUtils.getNextWeekendStartTime(1, 0) / 1000);
  1922. PlayerInfoProto.HeroCollectRefreshTimeResponse response = PlayerInfoProto.HeroCollectRefreshTimeResponse.newBuilder().setDayTime(dayRefreshTime).setWeekTime(weekRefreshTime).build();
  1923. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true);
  1924. }
  1925. //检查活动是否开启
  1926. public static boolean checkActivityOpen(User user, int activityType) {
  1927. ActivityManager activityManager = user.getActivityManager();
  1928. Map<Integer, ActivityMission> activityMissionMap = activityManager.getActivityMissionMap();
  1929. for (Map.Entry<Integer, ActivityMission> item : activityMissionMap.entrySet()) {
  1930. // LOGGER.info("user id {} activityType {} key{}", user.getId(), activityType, item.getKey());
  1931. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(item.getKey());
  1932. if (sGlobalActivity == null) {
  1933. // LOGGER.info("user id {} activityType {} key{}",user.getId(),activityType,item.getKey());
  1934. // return false;
  1935. continue;
  1936. }
  1937. int targetActivityType = sGlobalActivity.getId();
  1938. if (targetActivityType == activityType) {
  1939. return true;
  1940. }
  1941. }
  1942. return false;
  1943. }
  1944. //检查活动是否开启
  1945. public static boolean checkActivityIsOpen(User user, int activityType) {
  1946. ActivityManager activityManager = user.getActivityManager();
  1947. Map<Integer, ActivityMission> activityMissionMap = activityManager.getActivityMissionMap();
  1948. for (Map.Entry<Integer, ActivityMission> item : activityMissionMap.entrySet()) {
  1949. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(item.getKey());
  1950. if (sGlobalActivity == null) {
  1951. continue;
  1952. // return false;
  1953. }
  1954. int targetActivityType = sGlobalActivity.getId();
  1955. if (targetActivityType == activityType) {
  1956. if (item.getValue().getActivityState() == ActivityType.UNOPEN_STATE || item.getValue().getActivityState() == ActivityType.CLOSE_STATE) {
  1957. return false;
  1958. }
  1959. return true;
  1960. }
  1961. }
  1962. return false;
  1963. }
  1964. /**
  1965. * 检查绝对时间 和相对开服时间活动是否开启
  1966. */
  1967. public boolean checkGlobleActivityOpen(int activityId) {
  1968. return openActivityIds.contains(activityId);
  1969. }
  1970. //扭转乾坤
  1971. public void goodLuckRandom(ISession session, int activityId, MessageTypeProto.MessageType messageType) throws Exception {
  1972. SGoodLuck sGoodLuck = SGoodLuck.goodLuckMap.get(activityId);
  1973. if (sGoodLuck == null) {
  1974. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_ON);
  1975. }
  1976. User user = UserManager.getUser(session.getUid());
  1977. if (!user.getActivityManager().getActivityMissionMap().containsKey(activityId)) {
  1978. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  1979. }
  1980. int[][] cost = sGoodLuck.getCost();
  1981. boolean itemCost = ItemUtil.itemCost(user, cost, BIReason.GOOD_LUCK_CONSUME, 1);
  1982. if (!itemCost) {
  1983. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  1984. }
  1985. int[][] reward = sGoodLuck.getReward();
  1986. int random = MathUtils.random(1, reward.length);
  1987. CommonProto.Drop.Builder drop = ItemUtil.drop(user, new int[][]{reward[random - 1]}, BIReason.GOOD_LUCK_DROP);
  1988. ActivityProto.GoodLuckResponse.Builder response = ActivityProto.GoodLuckResponse.newBuilder().setIndex(random).setDrop(drop);
  1989. MessageUtil.sendMessage(session, 1, messageType.getNumber(), response.build(), true);
  1990. }
  1991. /**
  1992. * 灵兽活动选择灵兽
  1993. *
  1994. * @param session
  1995. * @param activityId
  1996. * @param chooseId
  1997. */
  1998. public void chooseSpecialMonster(ISession session, int activityId, int chooseId) throws Exception {
  1999. SGlobalActivity activity = SGlobalActivity.getsGlobalActivityMap().get(activityId);
  2000. if (activity == null || activity.getType() != ActivityType.SPECIAL_MONSTER_RANDOM_ACTIVITY) {
  2001. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_ON);
  2002. }
  2003. User user = UserManager.getUser(session.getUid());
  2004. Map<Integer, ActivityMission> activityMissionMap = user.getActivityManager().getActivityMissionMap();
  2005. ActivityMission activityMission = activityMissionMap.get(activityId);
  2006. if (activityMission == null || !activityMission.getActivityMissionMap().containsKey(0)) {
  2007. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_ON);
  2008. }
  2009. Map<Integer, SSpiritAnimalSummon> sSpiritAnimalSummon = STableManager.getConfig(SSpiritAnimalSummon.class);
  2010. if (!sSpiritAnimalSummon.containsKey(chooseId) || sSpiritAnimalSummon.get(chooseId).getActivityID() != activityId) {
  2011. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_ON);
  2012. }
  2013. activityMission.getActivityMissionMap().get(0).setProgrss(chooseId);
  2014. MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.SPECICAL_MONSTER_CHOOSE_RESPONSE_VALUE, null, true);
  2015. }
  2016. public static long[] getStartAndEndTime(User user, int activityId) {
  2017. long[] result = new long[2];
  2018. long startTime = 0;
  2019. long endTime = 0;
  2020. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(activityId);
  2021. if (sGlobalActivity.getTime() == ActivityType.OPEN_TYPE_ROLE) {
  2022. startTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), user.getPlayerInfoManager().getCreateTime(), 1);
  2023. endTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), user.getPlayerInfoManager().getCreateTime(), 2);
  2024. } else {
  2025. startTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), 0, 1);
  2026. endTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), 0, 2);
  2027. }
  2028. result[0] = startTime;
  2029. result[1] = endTime;
  2030. return result;
  2031. }
  2032. /**
  2033. * 轮询活动的时间
  2034. * @param user
  2035. * @param activityId
  2036. * @return
  2037. */
  2038. public long[] getSeasonActivityStartAndEndTime(User user, int activityId){
  2039. long[] result = new long[2];
  2040. long startTime = 0;
  2041. long endTime = 0;
  2042. SGlobalActivity sGlobalActivity = SGlobalActivity.getsGlobalActivityMap().get(activityId);
  2043. if (sGlobalActivity.getTime() == ActivityType.OPEN_TYPE_ROLE) {
  2044. startTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), user.getPlayerInfoManager().getCreateTime(), 1);
  2045. endTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), user.getPlayerInfoManager().getCreateTime(), 2);
  2046. } if(sGlobalActivity.getTime() == ActivityType.OPEN_TYPE_SEASON && seasonActivityIds.containsKey(activityId)) {
  2047. startTime = seasonActivityIds.get(activityId).getStartTime();
  2048. endTime = seasonActivityIds.get(activityId).getEndTime();
  2049. } else {
  2050. startTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), 0, 1);
  2051. endTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(), sGlobalActivity.getEndTimeLong(), sGlobalActivity.getTime(), 0, 2);
  2052. }
  2053. result[0] = startTime;
  2054. result[1] = endTime;
  2055. return result;
  2056. }
  2057. /**
  2058. * 集字活动 -- 炮击
  2059. *
  2060. * @param iSession
  2061. * @param id
  2062. * @param messageType
  2063. * @throws Exception
  2064. */
  2065. public void wordExchangeBombardActivity(ISession iSession, int id, MessageTypeProto.MessageType messageType) throws Exception {
  2066. User user = UserManager.getUser(iSession.getUid());
  2067. SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(id);
  2068. int lotteryType = sLotterySetting.getLotteryType(); //招募类型
  2069. int[][] costItem = sLotterySetting.getCostItem(); //招募消耗的道具
  2070. int[][] diamondBoxContain = sLotterySetting.getDiamondBoxContain(); //高级招募包含库(库#概率)
  2071. int perCount = sLotterySetting.getPerCount(); //抽卡次数
  2072. int mergePool = sLotterySetting.getMergePool(); //将单抽和十连合并起来 数字相同为同一卡池
  2073. int activityId = sLotterySetting.getActivityId(); //活动id
  2074. if (lotteryType != 22 && activityId != 104004) {
  2075. throw new ErrorCodeException(ErrorCode.PARAM_ERR);
  2076. }
  2077. int costItemKey = costItem[0][0];
  2078. int costItemNum = costItem[0][1];
  2079. long itemNum = user.getItemManager().getItemNum(costItemKey); //背包物品数量
  2080. if (itemNum < costItemNum) {
  2081. throw new ErrorCodeException(ErrorCode.ITEM_NULL);
  2082. }
  2083. //消耗物品
  2084. boolean enoughCost = ItemUtil.itemCost(user, costItem, BIReason.WORDEXCHANGEBOMBARD_CONSUME, 1);
  2085. if (!enoughCost) {
  2086. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  2087. }
  2088. int pool_id = diamondBoxContain[0][0];
  2089. ActivityManager activityManager = user.getActivityManager();
  2090. Map<Integer, Integer> idCountMap = activityManager.getIdCountMap();
  2091. List<Integer> poolIdList = new ArrayList<>();
  2092. int minCount = 0;
  2093. int minPoolId = pool_id;
  2094. if(mergePool != 0) {
  2095. List<SLotterySpecialConfig> specialConfigs = SLotterySpecialConfig.getLotterySpecialConfigListByType(mergePool);
  2096. if (specialConfigs != null && !specialConfigs.isEmpty()) {
  2097. for (SLotterySpecialConfig everyConfig : specialConfigs) {
  2098. if (everyConfig.getIsNeedShow() == 0) {
  2099. minCount = everyConfig.getCount();
  2100. minPoolId = everyConfig.getpool_id();
  2101. break;
  2102. }
  2103. }
  2104. }
  2105. }
  2106. int count = 0;
  2107. if (idCountMap.get(costItemKey) != null) {
  2108. count = idCountMap.get(costItemKey);
  2109. }
  2110. for (int i = 0; i < perCount; i++) {
  2111. //本次是否触发保底
  2112. if (count + 1 < minCount) { //count + 1 表示 最小是1,从1开始
  2113. count++;
  2114. poolIdList.add(pool_id);
  2115. continue;
  2116. }
  2117. poolIdList.add(minPoolId);
  2118. count = 0;
  2119. }
  2120. idCountMap.put(costItemKey, count);
  2121. //增加的商品
  2122. int[][] rewardSum = new int[perCount][2]; //单次奖励
  2123. for (int i = 0; i < poolIdList.size(); i++) {
  2124. //SLotteryRewardConfig sLotteryRewardConfig = randomMotherShipPlanByPoolId(pool_id, 1, user.getPlayerInfoManager().getLevel());
  2125. SLotteryRewardConfig sLotteryRewardConfig = randomMotherShipPlanByPoolId(poolIdList.get(i), 1, user.getPlayerInfoManager().getLevel());
  2126. if(sLotteryRewardConfig == null){
  2127. throw new ErrorCodeException(ErrorCode.PARAM_ERR);
  2128. }
  2129. //增加的商品
  2130. int[] reward = sLotteryRewardConfig.getReward(); //单次奖励
  2131. rewardSum[i] = reward;
  2132. }
  2133. //增加商品
  2134. CommonProto.Drop.Builder drop = ItemUtil.drop(user, rewardSum, BIReason.WORDEXCHANGEBOMBARD_REWARD);
  2135. PlayerInfoProto.WordExchangeBombardActivityResponse.Builder response = PlayerInfoProto.WordExchangeBombardActivityResponse.newBuilder();
  2136. response.setDrop(drop);
  2137. MessageUtil.sendMessage(iSession, 1, messageType.getNumber(), response.build(), true);
  2138. }
  2139. /**
  2140. * 卡牌主题:初始化信息 请求
  2141. * @param iSession
  2142. * @param activityId
  2143. * @param messageType
  2144. * @throws Exception
  2145. */
  2146. public void CardSubjectInit(ISession iSession, int activityId, MessageTypeProto.MessageType messageType) throws Exception {
  2147. User user = UserManager.getUser(iSession.getUid());
  2148. int relationActivityId = activityId;
  2149. Map<Integer, Integer> map = SWishActivityRelationConfig.getWishActivityRelationMapByActivityId();
  2150. if (map != null && map.containsKey(activityId)) {
  2151. relationActivityId = map.get(activityId);
  2152. }
  2153. ActivityManager activityManager = user.getActivityManager();
  2154. Map<Integer, Integer> wishRewardTimesMap = activityManager.getWishRewardTimesMap(); //卡牌主题:英雄驾到 心愿奖励次数 key=activityId, value=心愿奖励次数
  2155. int rewardTimes = 0; //心愿奖励次数
  2156. if(wishRewardTimesMap != null && wishRewardTimesMap.containsKey(relationActivityId)){
  2157. rewardTimes = wishRewardTimesMap.get(relationActivityId); //心愿奖励次数
  2158. }
  2159. Map<Integer, Integer> wishTimesMap = activityManager.getWishTimesMap(); //获取 招募次数
  2160. int wishTimes = 0; //招募次数
  2161. if(wishTimesMap != null && wishTimesMap.containsKey(relationActivityId)){
  2162. wishTimes = wishTimesMap.get(relationActivityId);
  2163. }
  2164. Map<Integer, Integer> wishIdMap = activityManager.getWishIdMap();//心愿奖励Id key=activityId, value=心愿奖励Id
  2165. int wishId = 0; //心愿奖励Id
  2166. if(wishIdMap != null && wishIdMap.containsKey(relationActivityId)){
  2167. wishId = wishIdMap.get(relationActivityId);
  2168. }
  2169. SWishPoolConfig sWishPoolConfig = SWishPoolConfig.getsWishPoolConfigMapByActivityId().get(relationActivityId);
  2170. int times = sWishPoolConfig.getWishTimes(); //心愿奖励所需要的保底次数 40
  2171. PlayerInfoProto.CardSubjectInitResponse.Builder response = PlayerInfoProto.CardSubjectInitResponse.newBuilder();
  2172. response.setWishTimes(rewardTimes);
  2173. response.setTimes(times - wishTimes);
  2174. response.setWishId(wishId == 0 ? 1 : wishId); //心愿奖励Id 默认=1
  2175. MessageUtil.sendMessage(iSession, 1, messageType.getNumber(), response.build(), true);
  2176. }
  2177. /**
  2178. * 卡牌主题:英雄豪礼-免费领取
  2179. * @param iSession
  2180. * @param activityId
  2181. * @param taskId
  2182. * @param messageType
  2183. * @throws Exception
  2184. */
  2185. public void cardSubjectHeroLuxuryGetFreeActivity(ISession iSession, int activityId,int taskId, MessageTypeProto.MessageType messageType) throws Exception {
  2186. User user = UserManager.getUser(iSession.getUid());
  2187. int relationActivityId = activityId;
  2188. Map<Integer, Integer> map = SWishActivityRelationConfig.getWishActivityRelationMapByActivityId();
  2189. if (map != null && map.containsKey(activityId)) {
  2190. relationActivityId = map.get(activityId);
  2191. }
  2192. ActivityManager activityManager = user.getActivityManager();
  2193. Map<Integer, Integer> wishRewardTimesMap = activityManager.getWishRewardTimesMap(); //卡牌主题:英雄驾到 心愿奖励次数 key=activityId, value=心愿奖励次数
  2194. //int rewardTimes = wishRewardTimesMap.get(relationActivityId); //心愿奖励次数
  2195. int rewardTimes = 0; //心愿奖励次数
  2196. if(wishRewardTimesMap != null && wishRewardTimesMap.containsKey(relationActivityId)){
  2197. rewardTimes = wishRewardTimesMap.get(relationActivityId); //心愿奖励次数
  2198. }
  2199. Map<Integer, Integer> wishFreeRewardMap = activityManager.getWishFreeRewardMap();
  2200. //int wishTimes = wishFreeRewardMap.get(activityId); //已领取心愿奖励条件 次数
  2201. int wishTimes = 0; //已领取心愿奖励条件 次数
  2202. if(wishFreeRewardMap != null && wishFreeRewardMap.containsKey(activityId)){
  2203. wishTimes = wishFreeRewardMap.get(activityId); //已领取心愿奖励条件 次数
  2204. }
  2205. SWishTaskRewardConfig sWishTaskRewardConfig = STableManager.getConfig(SWishTaskRewardConfig.class).get(taskId);
  2206. int condition = sWishTaskRewardConfig.getCondition(); //达成心愿条件
  2207. if(condition > rewardTimes){
  2208. throw new ErrorCodeException(ErrorCode.COUNT_NOT_ENOUGH); //次数不足
  2209. }else {
  2210. if(wishTimes > condition){
  2211. throw new ErrorCodeException(ErrorCode.HAD_TAKE_REWARD); //2已领取
  2212. }
  2213. }
  2214. int[] freeReward = sWishTaskRewardConfig.getFreeReward(); //免费奖励
  2215. //更新 已领取心愿奖励条件 次数
  2216. wishFreeRewardMap.put(activityId,condition);
  2217. activityManager.setWishFreeRewardMap(wishFreeRewardMap);
  2218. //增加商品
  2219. CommonProto.Drop.Builder drop = ItemUtil.drop(user, new int[][]{freeReward}, BIReason.CARD_SUBJECT_HERO_LUXURY_GET_FREE_REWARD);
  2220. PlayerInfoProto.CardSubjectHeroGetFreeResponse.Builder response = PlayerInfoProto.CardSubjectHeroGetFreeResponse.newBuilder();
  2221. response.setDrop(drop);
  2222. MessageUtil.sendMessage(iSession, 1, messageType.getNumber(), response.build(), true);
  2223. }
  2224. /**
  2225. * 牌主题:英雄豪礼
  2226. * @param iSession
  2227. * @param activityId 活动ID
  2228. * @param messageType
  2229. * @throws Exception
  2230. */
  2231. public void cardSubjectHeroLuxuryActivity(ISession iSession, int activityId, MessageTypeProto.MessageType messageType) throws Exception {
  2232. User user = UserManager.getUser(iSession.getUid());
  2233. int relationActivityId = activityId;
  2234. Map<Integer, Integer> map = SWishActivityRelationConfig.getWishActivityRelationMapByActivityId();
  2235. if (map != null && map.containsKey(activityId)) {
  2236. relationActivityId = map.get(activityId);
  2237. }
  2238. ActivityManager activityManager = user.getActivityManager();
  2239. Map<Integer, Integer> wishRewardTimesMap = activityManager.getWishRewardTimesMap(); //卡牌主题:英雄驾到 心愿奖励次数 key=activityId, value=心愿奖励次数
  2240. int rewardTimes = 0; //心愿奖励次数
  2241. if(wishRewardTimesMap != null && wishRewardTimesMap.containsKey(relationActivityId)){
  2242. rewardTimes = wishRewardTimesMap.get(relationActivityId); //心愿奖励次数
  2243. }
  2244. // int freeStatus = 0; //免费礼包状态; 0不能领取,1可领取,2已领取
  2245. Map<Integer, Integer> wishFreeRewardMap = activityManager.getWishFreeRewardMap();
  2246. //int wishTimes = activityManager.getWishFreeRewardMap().get(activityId); //已领取心愿奖励条件 次数 value=达成心愿条件最后次数 对应WishTaskRewardConfig表
  2247. int wishTimes = 0;
  2248. if(wishFreeRewardMap != null && wishFreeRewardMap.containsKey(activityId)){
  2249. wishTimes = wishFreeRewardMap.get(activityId);
  2250. }
  2251. List<CommonProto.HeroLuxury> heroLuxuries = new ArrayList<>();
  2252. List<SWishTaskRewardConfig> sWishTaskRewardConfigs = SWishTaskRewardConfig.getWishTaskRewardConfigByActivityIdMap().get(activityId);
  2253. for (SWishTaskRewardConfig config : sWishTaskRewardConfigs) {
  2254. CommonProto.HeroLuxury heroLuxury = buildHeroLuxury(config, rewardTimes, wishTimes);
  2255. heroLuxuries.add(heroLuxury);
  2256. }
  2257. PlayerInfoProto.CardSubjectHeroLuxuryGetResponse.Builder response = PlayerInfoProto.CardSubjectHeroLuxuryGetResponse.newBuilder();
  2258. response.setTimes(rewardTimes);
  2259. response.addAllHeroLuxury(heroLuxuries);
  2260. MessageUtil.sendMessage(iSession, 1, messageType.getNumber(), response.build(), true);
  2261. }
  2262. public static CommonProto.HeroLuxury buildHeroLuxury(SWishTaskRewardConfig config,int rewardTimes,int wishTimes) {
  2263. CommonProto.HeroLuxury.Builder heroLuxury = CommonProto.HeroLuxury.newBuilder();
  2264. heroLuxury.setId(config.getId());
  2265. int freeStatus = 0; //免费礼包状态; 0不能领取,1可领取,2已领取
  2266. if(config.getCondition() <= rewardTimes){ //可领取
  2267. if(wishTimes < config.getCondition()){
  2268. freeStatus = 1; //可领取
  2269. }else {
  2270. freeStatus = 2; //2已领取
  2271. }
  2272. }
  2273. heroLuxury.setFreeStatus(freeStatus);
  2274. return heroLuxury.build();
  2275. }
  2276. /**
  2277. * 卡牌主题:英雄驾到 切换心愿池
  2278. */
  2279. public void cardSubjeckWishPoolChange(ISession iSession,int activityId, int id, MessageTypeProto.MessageType messageType) throws Exception {
  2280. User user = UserManager.getUser(iSession.getUid());
  2281. //英雄驾到 ActivityType=50000的活动ID
  2282. List<Integer> activityIdList = new ArrayList<>();
  2283. List<SGlobalActivity> sGlobalActivities = SGlobalActivity.sGlobalActivityMapByType.get(ActivityType.CARD_SUBJECT_HERO_GET);
  2284. for (SGlobalActivity globalActivity : sGlobalActivities){
  2285. activityIdList.add(globalActivity.getId());
  2286. }
  2287. //int activityId = activityIdList.get(0);
  2288. SWishPoolConfig sWishPoolConfig = SWishPoolConfig.getsWishPoolConfigMapByActivityId().get(activityId);
  2289. //int wishTimes = sWishPoolConfig.getWishTimes(); //心愿奖励保底次数,本期活动每个心愿奖励所需要的保底次数
  2290. int[] changeWishCost = sWishPoolConfig.getChangeWishCost(); //切换心愿奖励消耗,填写值为:道具id#数量
  2291. int[] wishReward = sWishPoolConfig.getWishReward1(); //切换的心愿奖池
  2292. if(id == 1){
  2293. wishReward = sWishPoolConfig.getWishReward1();
  2294. }else if(id == 2){
  2295. wishReward = sWishPoolConfig.getWishReward2();
  2296. }else if(id == 3){
  2297. wishReward = sWishPoolConfig.getWishReward3();
  2298. }else if(id == 4){
  2299. wishReward = sWishPoolConfig.getWishReward4();
  2300. }else if(id == 5){
  2301. wishReward = sWishPoolConfig.getWishReward5();
  2302. }
  2303. Item item = new Item();
  2304. item.setItemId(wishReward[0]);
  2305. item.setItemNum(wishReward[1]);
  2306. int costItemKey = changeWishCost[0];
  2307. int costItemNum = changeWishCost[1];
  2308. long itemNum = user.getItemManager().getItemNum(costItemKey); //背包物品数量
  2309. if (itemNum < costItemNum) {
  2310. throw new ErrorCodeException(ErrorCode.ITEM_NULL);
  2311. }
  2312. //消耗物品
  2313. boolean enoughCost = ItemUtil.itemCost(user, new int[][]{{costItemKey,costItemNum}}, BIReason.CARD_SUBJECT_WISH_POOL_CHANGE_COST, 1);
  2314. if (!enoughCost) {
  2315. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  2316. }
  2317. ActivityManager activityManager = user.getActivityManager();
  2318. //更新 心愿奖励
  2319. Map<Integer, Item> wishRewardMap = activityManager.getWishRewardMap();
  2320. wishRewardMap.put(activityId,item);
  2321. activityManager.setWishRewardMap(wishRewardMap);
  2322. //更新心愿Id
  2323. Map<Integer, Integer> wishIdMap = activityManager.getWishIdMap();
  2324. wishIdMap.put(activityId,id);
  2325. activityManager.setWishIdMap(wishIdMap);
  2326. PlayerInfoProto.CardSubjeckWishPoolChangeResponse.Builder response = PlayerInfoProto.CardSubjeckWishPoolChangeResponse.newBuilder();
  2327. MessageUtil.sendMessage(iSession, 1, messageType.getNumber(), response.build(), true);
  2328. }
  2329. /**
  2330. * 卡牌主题:英雄驾到 招募
  2331. * @param iSession
  2332. * @param id
  2333. * @param messageType
  2334. * @throws Exception
  2335. */
  2336. public void cardSubjectHeroGetActivity(ISession iSession, int id, MessageTypeProto.MessageType messageType) throws Exception {
  2337. User user = UserManager.getUser(iSession.getUid());
  2338. SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(id);
  2339. int lotteryType = sLotterySetting.getLotteryType(); //招募类型
  2340. int[][] costItem = sLotterySetting.getCostItem(); //招募消耗的道具
  2341. int[][] diamondBoxContain = sLotterySetting.getDiamondBoxContain(); //高级招募包含库(库#概率)
  2342. int perCount = sLotterySetting.getPerCount(); //抽卡次数
  2343. int mergePool = sLotterySetting.getMergePool(); //将单抽和十连合并起来 数字相同为同一卡池
  2344. int activityId = sLotterySetting.getActivityId(); //活动id
  2345. //英雄驾到 ActivityType=50000的活动ID
  2346. List<Integer> activityIdList = new ArrayList<>();
  2347. List<SGlobalActivity> sGlobalActivities = SGlobalActivity.sGlobalActivityMapByType.get(ActivityType.CARD_SUBJECT_HERO_GET);
  2348. for (SGlobalActivity globalActivity : sGlobalActivities) {
  2349. activityIdList.add(globalActivity.getId());
  2350. }
  2351. if (lotteryType != 52 && !activityIdList.contains(activityId)) { //52 = LotterySetting表ActivityId=70001的 LotteryType
  2352. throw new ErrorCodeException(ErrorCode.PARAM_ERR);
  2353. }
  2354. int costItemKey = costItem[0][0];
  2355. int costItemNum = costItem[0][1];
  2356. long itemNum = user.getItemManager().getItemNum(costItemKey); //背包物品数量
  2357. if (itemNum < costItemNum) {
  2358. throw new ErrorCodeException(ErrorCode.ITEM_NULL);
  2359. }
  2360. //消耗物品
  2361. boolean enoughCost = ItemUtil.itemCost(user, costItem, BIReason.CARD_SUBJECT_HERO_GET_COST, 1);
  2362. if (!enoughCost) {
  2363. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  2364. }
  2365. ActivityManager activityManager = user.getActivityManager();
  2366. //------------心愿保底 WishPoolConfig Start -----------
  2367. Map<Integer, Integer> wishTimesMap = activityManager.getWishTimesMap(); //获取 招募次数
  2368. Map<Integer, Item> wishRewardMap = activityManager.getWishRewardMap(); //获取 心愿奖励
  2369. Map<Integer, Integer> wishRewardTimesMap = activityManager.getWishRewardTimesMap(); //获取 心愿奖励次数
  2370. Map<Integer, Integer> wishIdMap = activityManager.getWishIdMap(); //心愿奖励Id key=activityId, value=心愿奖励Id
  2371. SWishPoolConfig sWishPoolConfig = SWishPoolConfig.getsWishPoolConfigMapByActivityId().get(activityId);
  2372. int wishTimes = sWishPoolConfig.getWishTimes(); //心愿奖励所需要的保底次数 40
  2373. int relationActivityId = activityId;
  2374. if(!SWishActivityRelationConfig.getWishActivityRelationMapByActivityId().values().contains(activityId)){
  2375. relationActivityId = SWishActivityRelationConfig.getWishActivityRelationMapByActivityId().get(activityId);
  2376. }
  2377. int wishId = 0; //心愿奖励Id
  2378. if(wishIdMap != null && wishIdMap.containsKey(relationActivityId)){
  2379. wishId = wishIdMap.get(relationActivityId);
  2380. }
  2381. int[] wishReward = sWishPoolConfig.getWishReward1(); //切换的心愿奖池
  2382. if(wishId == 1){
  2383. wishReward = sWishPoolConfig.getWishReward1();
  2384. }else if(wishId == 2){
  2385. wishReward = sWishPoolConfig.getWishReward2();
  2386. }else if(wishId == 3){
  2387. wishReward = sWishPoolConfig.getWishReward3();
  2388. }else if(wishId == 4){
  2389. wishReward = sWishPoolConfig.getWishReward4();
  2390. }else if(wishId == 5){
  2391. wishReward = sWishPoolConfig.getWishReward5();
  2392. }
  2393. int pool_id = diamondBoxContain[0][0]; //高级招募包含库(库#概率)
  2394. // List<Integer> poolIdList = new ArrayList<>();
  2395. int cardCount = 0; //获取 招募次数
  2396. if (wishTimesMap.get(activityId) != null) {
  2397. cardCount = wishTimesMap.get(activityId);
  2398. }
  2399. //------------心愿保底 WishPoolConfig End -----------
  2400. //------------Lottery保底 Start--------------------
  2401. // int pool_id = diamondBoxContain[0][0]; //高级招募包含库(库#概率)
  2402. Map<Integer, Integer> idCountMap = activityManager.getIdCountMap();
  2403. List<Integer> poolIdList = new ArrayList<>();
  2404. int minCount = 0;
  2405. int minPoolId = pool_id;
  2406. if (mergePool != 0) {
  2407. List<SLotterySpecialConfig> specialConfigs = SLotterySpecialConfig.getLotterySpecialConfigListByType(mergePool);
  2408. if (specialConfigs != null && !specialConfigs.isEmpty()) {
  2409. for (SLotterySpecialConfig everyConfig : specialConfigs) {
  2410. if (everyConfig.getIsNeedShow() == 0) {
  2411. minCount = everyConfig.getCount();
  2412. minPoolId = everyConfig.getpool_id();
  2413. break;
  2414. }
  2415. }
  2416. }
  2417. } else {
  2418. minCount = wishTimes;
  2419. }
  2420. //增加的商品
  2421. int[][] rewardSum = new int[perCount][2]; //单次奖励
  2422. int curWishTimes = 0; //本次招募获取心愿次数
  2423. // int count = 0;
  2424. // if (idCountMap.get(costItemKey) != null) {
  2425. // count = idCountMap.get(costItemKey);
  2426. // }
  2427. for (int i = 0; i < perCount; i++) {
  2428. //本次是否触发保底
  2429. if (cardCount + 1 < minCount) { //count + 1 表示 最小是1,从1开始
  2430. //count++;
  2431. cardCount++;
  2432. poolIdList.add(pool_id);
  2433. continue;
  2434. }
  2435. //count = 0;
  2436. cardCount = 0;
  2437. curWishTimes+=1;
  2438. //wishTimesMap.put(activityId,count);
  2439. int wishRewardTimes = 0;
  2440. if(wishRewardTimesMap.containsKey(activityId)){
  2441. wishRewardTimes = wishRewardTimesMap.get(activityId);
  2442. }
  2443. wishRewardTimesMap.put(activityId, wishRewardTimes + 1); //更新 心愿奖励次数
  2444. activityManager.setWishRewardTimesMap(wishRewardTimesMap);
  2445. }
  2446. //idCountMap.put(costItemKey, count);
  2447. wishTimesMap.put(activityId, cardCount); //更新 招募次数
  2448. activityManager.setWishTimesMap(wishTimesMap);
  2449. //------------Lottery保底 End--------------------
  2450. boolean haveWishReward = false; //此次招募是否有心愿奖励
  2451. for (int i = 0; i < poolIdList.size(); i++) {
  2452. //SLotteryRewardConfig sLotteryRewardConfig = randomMotherShipPlanByPoolId(pool_id, 1, user.getPlayerInfoManager().getLevel());
  2453. SLotteryRewardConfig sLotteryRewardConfig = randomMotherShipPlanByPoolId(poolIdList.get(i), 1, user.getPlayerInfoManager().getLevel());
  2454. if (sLotteryRewardConfig == null) {
  2455. throw new ErrorCodeException(ErrorCode.PARAM_ERR);
  2456. }
  2457. //增加的商品
  2458. int[] reward = sLotteryRewardConfig.getReward(); //单次奖励
  2459. if (wishReward[0] == reward[0] && wishReward[1] == reward[1]) {
  2460. //玩家获得心愿奖励次数
  2461. user.getUserMissionManager().onGameEvent(user, GameEvent.WISH_REWARD_TIMES, 900);
  2462. curWishTimes += 1;
  2463. haveWishReward = true;
  2464. int wishRewardTimes = 0;
  2465. if(wishRewardTimesMap.containsKey(activityId)){
  2466. wishRewardTimes = wishRewardTimesMap.get(activityId);
  2467. }
  2468. wishRewardTimesMap.put(activityId, wishRewardTimes + 1); //更新 心愿奖励次数
  2469. activityManager.setWishRewardTimesMap(wishRewardTimesMap);
  2470. }
  2471. rewardSum[i] = reward;
  2472. }
  2473. if(haveWishReward){
  2474. cardCount = 0;
  2475. wishTimesMap.put(activityId, cardCount); //更新 招募次数
  2476. activityManager.setWishTimesMap(wishTimesMap);
  2477. }
  2478. if(curWishTimes > 0){
  2479. for (int i = poolIdList.size(); i< perCount; i++) {
  2480. rewardSum[i] = wishReward;
  2481. //玩家获得心愿奖励次数
  2482. user.getUserMissionManager().onGameEvent(user, GameEvent.WISH_REWARD_TIMES, 900);
  2483. }
  2484. }
  2485. //增加商品
  2486. CommonProto.Drop.Builder drop = ItemUtil.drop(user, rewardSum, BIReason.CARD_SUBJECT_HERO_GET_REWARD);
  2487. int wishRewardTimes = 0; //心愿奖励次数
  2488. if(wishRewardTimesMap != null && wishRewardTimesMap.containsKey(relationActivityId)){
  2489. wishRewardTimes = wishRewardTimesMap.get(relationActivityId);
  2490. }
  2491. PlayerInfoProto.CardSubjectHeroGetActivityResponse.Builder response = PlayerInfoProto.CardSubjectHeroGetActivityResponse.newBuilder();
  2492. response.setDrop(drop);
  2493. response.setTimes(wishTimes-cardCount); //X次之后必定获得心愿奖励
  2494. response.setWishRewardTimes(wishRewardTimes); //心愿奖励次数
  2495. MessageUtil.sendMessage(iSession, 1, messageType.getNumber(), response.build(), true);
  2496. }
  2497. public static SLotteryRewardConfig randomMotherShipPlanByPoolId(int poolId, int randomCount, int userLevel) {
  2498. List<SLotteryRewardConfig> sLotteryRewardConfigs = new ArrayList<>();
  2499. List<SLotteryRewardConfig> sLotteryRewardConfigListByPoolId = SLotteryRewardConfig.getSLotteryRewardConfigListByPoolId(poolId);
  2500. int totalCountByPoolId = 0;
  2501. for (SLotteryRewardConfig sLotteryRewardConfig : sLotteryRewardConfigListByPoolId) {
  2502. int[] openRules = sLotteryRewardConfig.getOpenRules();
  2503. boolean canAdd = true;
  2504. if (openRules != null && openRules.length > 0) {
  2505. int openType = openRules[0];
  2506. int openValue = openRules[1];
  2507. switch (openType) {
  2508. case 1:
  2509. canAdd = randomCount > openValue;
  2510. break;
  2511. case 2:
  2512. canAdd = userLevel > openValue;
  2513. break;
  2514. }
  2515. }
  2516. if (canAdd) {
  2517. sLotteryRewardConfigs.add(sLotteryRewardConfig);
  2518. totalCountByPoolId += sLotteryRewardConfig.getWeight();
  2519. }
  2520. }
  2521. int randCount = MathUtils.randomInt(totalCountByPoolId) + 1;
  2522. int weight = 0;
  2523. for (SLotteryRewardConfig sLotteryRewardConfig : sLotteryRewardConfigs) {
  2524. weight += sLotteryRewardConfig.getWeight();
  2525. if (weight >= randCount) {
  2526. return sLotteryRewardConfig;
  2527. }
  2528. }
  2529. return null;
  2530. }
  2531. // public static SLotteryRewardConfig randomMotherShipPlanByPoolId(int poolId, int randomCount, int userLevel) {
  2532. // List<SLotteryRewardConfig> sLotteryRewardConfigs = new ArrayList<>();
  2533. // List<SLotteryRewardConfig> sLotteryRewardConfigListByPoolId = SLotteryRewardConfig.getSLotteryRewardConfigListByPoolId(poolId);
  2534. // int totalCountByPoolId = 0;
  2535. // for (SLotteryRewardConfig sLotteryRewardConfig : sLotteryRewardConfigListByPoolId) {
  2536. // int[] openRules = sLotteryRewardConfig.getOpenRules();
  2537. // boolean canAdd = true;
  2538. // if (openRules != null && openRules.length > 0) {
  2539. // int openType = openRules[0];
  2540. // int openValue = openRules[1];
  2541. // switch (openType) {
  2542. // case 1:
  2543. // canAdd = randomCount > openValue;
  2544. // break;
  2545. // case 2:
  2546. // canAdd = userLevel > openValue;
  2547. // break;
  2548. // }
  2549. // }
  2550. // if (canAdd) {
  2551. // sLotteryRewardConfigs.add(sLotteryRewardConfig);
  2552. // totalCountByPoolId += sLotteryRewardConfig.getWeight();
  2553. // }
  2554. // }
  2555. //
  2556. // int randCount = MathUtils.randomInt(totalCountByPoolId) + 1;
  2557. // int weight = 0;
  2558. // for (SLotteryRewardConfig sLotteryRewardConfig : sLotteryRewardConfigs) {
  2559. // weight += sLotteryRewardConfig.getWeight();
  2560. // if (weight >= randCount) {
  2561. // return sLotteryRewardConfig;
  2562. // }
  2563. // }
  2564. // return null;
  2565. // }
  2566. /**
  2567. * 副官招募
  2568. *
  2569. * @param iSession
  2570. * @param layer 层级
  2571. * @param type 抽奖道具类型
  2572. * @param messageType
  2573. * @throws Exception
  2574. */
  2575. public void adjutantLayerActivity(ISession iSession, int layer, int type, MessageTypeProto.MessageType messageType) throws Exception {
  2576. User user = UserManager.getUser(iSession.getUid());
  2577. Set<Integer> openActivityId = ActivityLogic.getInstance().getOpenActivityIdsByType(user, ActivityTypeEnum.ADJUTANTLAYER.getType(), true);
  2578. if (openActivityId.size() == 0) {
  2579. throw new ErrorCodeException(ErrorCode.PARAM_ERR);
  2580. }
  2581. int openId = 0;
  2582. for (Iterator iterator = openActivityId.iterator(); iterator.hasNext(); ) {
  2583. openId = (int) iterator.next();
  2584. }
  2585. LOGGER.info("now adjutantLayerActivity id is {}", openId);
  2586. Map<Integer, SLayerPoolConfig> layerPoolConfigMap = SLayerPoolConfig.sByLayerMap.get(openId);
  2587. if (layerPoolConfigMap.size() == 0) {
  2588. throw new ErrorCodeException(ErrorCode.PARAM_ERR);
  2589. }
  2590. SLayerPoolConfig config = layerPoolConfigMap.get(layer);
  2591. int setId = config.getLotteryId()[type];
  2592. SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(setId);
  2593. int perCount = sLotterySetting.getPerCount();
  2594. int maxTimes = sLotterySetting.getMaxTimes();
  2595. if (maxTimes != 0 && !PlayerLogic.getInstance().checkAndUpdate(user, maxTimes, perCount)) {
  2596. throw new ErrorCodeException(ErrorCode.ADJUTANT_ACT_BUYCOUNT_ENOUGH);
  2597. }
  2598. //所有获得物品
  2599. int[][] resultRandom = new int[perCount][];
  2600. //进行抽取
  2601. for (int i = 0; i < perCount; i++) {
  2602. int rewardId = randomOne(user, setId);
  2603. SLotteryRewardConfig sLotteryRewardConfig = STableManager.getConfig(SLotteryRewardConfig.class).get(rewardId);
  2604. resultRandom[i] = sLotteryRewardConfig.getReward();
  2605. }
  2606. //消耗商品
  2607. int[][] costItem = sLotterySetting.getCostItem();//消耗的道具
  2608. boolean enoughCost = ItemUtil.itemCost(user, costItem, BIReason.ADJUTANT_LAYER_COST, 1);
  2609. if (!enoughCost) {
  2610. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  2611. }
  2612. //增加商品
  2613. CommonProto.Drop.Builder drop = ItemUtil.drop(user, resultRandom, BIReason.ADJUTANT_LAYER_REWARD);
  2614. Map resultRandomMap = ItemUtil.arrayToMap(resultRandom);
  2615. int[] unlockItem = config.getUnlockitem();
  2616. if (resultRandomMap.get(unlockItem[0]) != null) {
  2617. user.getActivityManager().setAdjutantLayer(user.getActivityManager().getAdjutantLayer() + 1);
  2618. if (layer == 4) {
  2619. user.getActivityManager().setAdjutantLayer(1);
  2620. }
  2621. }
  2622. if (type == 0) {
  2623. user.getActivityManager().setAdjutantLayerBuyNum(user.getActivityManager().getAdjutantLayerBuyNum() + 1);
  2624. }
  2625. AdjutantProto.AdjutantLayerActivityResponse.Builder response = AdjutantProto.AdjutantLayerActivityResponse.newBuilder();
  2626. response.setLayer(user.getActivityManager().getAdjutantLayer());
  2627. response.setBuyNum(user.getActivityManager().getAdjutantLayerBuyNum());
  2628. response.setDrop(drop);
  2629. MessageUtil.sendMessage(iSession, 1, messageType.getNumber(), response.build(), true);
  2630. }
  2631. /**
  2632. * 每次抽取
  2633. *
  2634. * @param user
  2635. * @param setId
  2636. * @return
  2637. * @throws Exception
  2638. */
  2639. public static int randomOne(User user, int setId) throws Exception {
  2640. SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(setId);
  2641. if (sLotterySetting == null) {
  2642. throw new ErrorCodeException(ErrorCode.PARAM_ERR);
  2643. }
  2644. int mergePool = sLotterySetting.getMergePool();
  2645. List<SLotterySpecialConfig> specialConfigs = SLotterySpecialConfig.getLotterySpecialConfigListByType(mergePool);
  2646. HeroManager heroManager = user.getHeroManager();
  2647. Set<Integer> mustSet = new HashSet<>();
  2648. Map<Integer, Map<Integer, Integer>> randomPoolByType = heroManager.getRandomPoolByType();
  2649. //设置用户必出计数器
  2650. if (specialConfigs != null && !specialConfigs.isEmpty()) {
  2651. if (!randomPoolByType.containsKey(mergePool)) {
  2652. randomPoolByType.put(mergePool, new HashMap<>());
  2653. for (SLotterySpecialConfig config : specialConfigs) {
  2654. randomPoolByType.get(mergePool).put(config.getDifferentType(), 0);
  2655. }
  2656. }
  2657. //保底次数计算
  2658. for (Map.Entry<Integer, Integer> countEntry : randomPoolByType.get(mergePool).entrySet()) {
  2659. SLotterySpecialConfig config = null;
  2660. // if(specialConfigs.isEmpty()){
  2661. // continue;
  2662. // }
  2663. for (SLotterySpecialConfig everyConfig : specialConfigs) {
  2664. if (everyConfig.getDifferentType() != countEntry.getKey()) {
  2665. continue;
  2666. }
  2667. config = everyConfig;
  2668. }
  2669. if (config == null) {
  2670. throw new ErrorCodeException(ErrorCode.CFG_NULL);
  2671. }
  2672. //本次是否触发保底
  2673. if (countEntry.getValue() + 1 < config.getCount()) {
  2674. continue;
  2675. }
  2676. //保底触发次数统计
  2677. Map<Integer, Integer> mustRandomCount = heroManager.getMustRandomCount();
  2678. if (mustRandomCount.containsKey(countEntry.getKey())) {
  2679. //是否已经到了保底触发上限
  2680. if (config.getMin_num() != 0 && mustRandomCount.get(countEntry.getKey()) >= config.getMin_num()) {
  2681. continue;
  2682. } else {
  2683. mustRandomCount.put(countEntry.getKey(), mustRandomCount.get(countEntry.getKey()) + 1);
  2684. }
  2685. } else {
  2686. mustRandomCount.put(countEntry.getKey(), 1);
  2687. }
  2688. heroManager.setMustRandomCount(mustRandomCount);
  2689. mustSet.add(countEntry.getKey());
  2690. }
  2691. }
  2692. SLotteryRewardConfig sLotteryRewardConfig;
  2693. //是否有必出
  2694. if (mustSet.isEmpty()) {
  2695. sLotteryRewardConfig = randomHeroByPoolId(getPooId(sLotterySetting), 1, user.getPlayerInfoManager().getLevel());
  2696. int star = sLotteryRewardConfig.getStar();
  2697. if (randomPoolByType.get(mergePool) != null) {
  2698. for (int key : randomPoolByType.get(mergePool).keySet()) {
  2699. if (star == key) {
  2700. randomPoolByType.get(mergePool).put(key, 0);
  2701. } else {
  2702. int curValue = randomPoolByType.get(mergePool).getOrDefault(key, 0);
  2703. randomPoolByType.get(mergePool).put(key, curValue + 1);
  2704. }
  2705. }
  2706. }
  2707. } else {
  2708. //有必出时比较各个优先级,取优先级高的
  2709. int maxId = 0;
  2710. for (int mustId : mustSet) {
  2711. maxId = mustId > maxId ? mustId : maxId;
  2712. }
  2713. System.out.println("触发必出" + maxId);
  2714. SLotterySpecialConfig onConfig = null;
  2715. for (SLotterySpecialConfig everyConfig : specialConfigs) {
  2716. if (everyConfig.getDifferentType() != maxId) {
  2717. continue;
  2718. }
  2719. onConfig = everyConfig;
  2720. }
  2721. if (onConfig == null) {
  2722. throw new ErrorCodeException(ErrorCode.CFG_NULL);
  2723. }
  2724. sLotteryRewardConfig = randomHeroByPoolId(onConfig.getpool_id(), 1, user.getPlayerInfoManager().getLevel());
  2725. randomPoolByType.get(mergePool).put(maxId, 0);
  2726. }
  2727. heroManager.updateRandomPoolByType(mergePool, randomPoolByType.get(mergePool));
  2728. int result = sLotteryRewardConfig.getId();
  2729. return result;
  2730. }
  2731. private static int getPooId(SLotterySetting sLotterySetting) throws Exception {
  2732. int[][] diamondBoxContain = sLotterySetting.getDiamondBoxContain();
  2733. int totalWeight = 0;
  2734. for (int i = 0; i < diamondBoxContain.length; i++) {
  2735. int[] poolWeightInfo = diamondBoxContain[i];
  2736. totalWeight += poolWeightInfo[1];
  2737. }
  2738. int randWeight = MathUtils.randomInt(totalWeight) + 1;
  2739. int weight = 0;
  2740. for (int i = 0; i < diamondBoxContain.length; i++) {
  2741. int[] poolWeightInfo = diamondBoxContain[i];
  2742. weight += poolWeightInfo[1];
  2743. if (randWeight <= weight) {
  2744. return poolWeightInfo[0];
  2745. }
  2746. }
  2747. return 0;
  2748. }
  2749. public static SLotteryRewardConfig randomHeroByPoolId(int poolId, int randomCount, int userLevel){
  2750. return randomHeroByPoolId(poolId,randomCount,userLevel,null);
  2751. }
  2752. public static SLotteryRewardConfig randomHeroByPoolId(int poolId, int randomCount, int userLevel, List<Integer> excludeList) {
  2753. List<SLotteryRewardConfig> sLotteryRewardConfigs = new ArrayList<>();
  2754. List<SLotteryRewardConfig> sLotteryRewardConfigListByPoolId = SLotteryRewardConfig.getSLotteryRewardConfigListByPoolId(poolId);
  2755. int totalCountByPoolId = 0;
  2756. for (SLotteryRewardConfig sLotteryRewardConfig : sLotteryRewardConfigListByPoolId) {
  2757. if(excludeList != null && excludeList.contains(sLotteryRewardConfig.getId()))
  2758. continue;
  2759. int[] openRules = sLotteryRewardConfig.getOpenRules();
  2760. boolean canAdd = true;
  2761. if (openRules != null && openRules.length > 0) {
  2762. int openType = openRules[0];
  2763. int openValue = openRules[1];
  2764. switch (openType) {
  2765. case 1:
  2766. canAdd = randomCount > openValue;
  2767. break;
  2768. case 2:
  2769. canAdd = userLevel > openValue;
  2770. break;
  2771. }
  2772. }
  2773. if (canAdd) {
  2774. sLotteryRewardConfigs.add(sLotteryRewardConfig);
  2775. totalCountByPoolId += sLotteryRewardConfig.getWeight();
  2776. }
  2777. }
  2778. int randCount = MathUtils.randomInt(totalCountByPoolId) + 1;
  2779. int weight = 0;
  2780. for (SLotteryRewardConfig sLotteryRewardConfig : sLotteryRewardConfigs) {
  2781. if(excludeList != null && excludeList.contains(sLotteryRewardConfig.getId()))
  2782. continue;
  2783. weight += sLotteryRewardConfig.getWeight();
  2784. if (weight >= randCount) {
  2785. return sLotteryRewardConfig;
  2786. }
  2787. }
  2788. return null;
  2789. }
  2790. /**
  2791. * BOX扭蛋 抽取
  2792. */
  2793. public void boxPoolRandom(ISession session, int id) throws Exception {
  2794. SBoxPoolConfig sBoxPoolConfig = STableManager.getConfig(SBoxPoolConfig.class).get(id);
  2795. if(sBoxPoolConfig == null){
  2796. throw new ErrorCodeException(ErrorCode.CFG_NULL);
  2797. }
  2798. int activityId = sBoxPoolConfig.getActivityId();
  2799. int uid = session.getUid();
  2800. User user = UserManager.getUser(uid);
  2801. ActivityMission activityMission = user.getActivityManager().getActivityMissionMap().get(activityId);
  2802. if(activityMission == null && activityMission.getActivityState() != ActivityType.OPEN_STATE){
  2803. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  2804. }
  2805. BoxPoolInfo boxPoolInfo = user.getActivityManager().getBoxPoolInfo(sBoxPoolConfig.getId());
  2806. if(boxPoolInfo == null){
  2807. boxPoolInfo = new BoxPoolInfo(sBoxPoolConfig.getId(),sBoxPoolConfig.getFirstLotteryId());
  2808. user.getActivityManager().addBoxPoolInfo(boxPoolInfo);
  2809. }
  2810. int lotteryId = boxPoolInfo.getLotteryId();
  2811. SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(lotteryId);
  2812. if(sLotterySetting == null){
  2813. throw new ErrorCodeException(ErrorCode.CFG_NULL);
  2814. }
  2815. if(boxPoolRandomFinish(boxPoolInfo,sLotterySetting)){
  2816. LOGGER.error("box pool random finish uid:{},id:{},lotteryId:{}",uid,id,lotteryId);
  2817. throw new ErrorCodeException(ErrorCode.PARAM_ERR);
  2818. }
  2819. //消耗商品
  2820. int[][] costItem = sLotterySetting.getCostItem();//消耗的道具
  2821. Map<Integer,Integer> costItemMap = null;
  2822. if(costItem != null && costItem.length > 0){
  2823. costItemMap = new HashMap<>();
  2824. for(int[] array : costItem){
  2825. costItemMap.put(array[0],array[1] + costItemMap.getOrDefault(array[0],0));
  2826. }
  2827. }
  2828. boolean enoughCost = ItemUtil.checkCost(user,costItemMap);
  2829. if (!enoughCost) {
  2830. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  2831. }
  2832. ItemUtil.itemCost(user,costItemMap,BIReason.BOX_POOL_RANDOM_COST,1);
  2833. int poolId = sLotterySetting.getDiamondBoxContain()[0][0];
  2834. SLotteryRewardConfig rewardConfig = randomHeroByPoolId(poolId,1,user.getPlayerInfoManager().getLevel(),boxPoolInfo.getRandomRewardList());
  2835. int[][] itemArray = new int[1][];
  2836. itemArray[0] = rewardConfig.getReward();
  2837. CommonProto.Drop.Builder drop = ItemUtil.drop(user,itemArray,BIReason.BOX_POOL_RANDOM_REWARD);
  2838. List<Integer> randomRewardList = boxPoolInfo.getRandomRewardList();
  2839. randomRewardList.add(rewardConfig.getId());
  2840. boxPoolInfo.setRandomRewardList(randomRewardList);
  2841. int[] autoResetParam = sBoxPoolConfig.getAutoReset();
  2842. if(autoResetParam[0] == 1 && autoResetParam[1] != 0
  2843. && (boxPoolInfo.getAutoResetCount() < autoResetParam[1] || autoResetParam[1] < 0)){
  2844. //奖励抽完自动重置
  2845. boolean isFinish = boxPoolRandomFinish(boxPoolInfo,sLotterySetting);
  2846. if(isFinish){
  2847. resetBoxPoolInfo(uid,boxPoolInfo,true);
  2848. }
  2849. }
  2850. ActivityProto.BoxPoolInfo info = ActivityProto.BoxPoolInfo.newBuilder().setId(boxPoolInfo.getId())
  2851. .setLotteryId(boxPoolInfo.getLotteryId()).setAutoResetCount(boxPoolInfo.getAutoResetCount())
  2852. .setManualResetCount(boxPoolInfo.getManualResetCount()).addAllRewardList(boxPoolInfo.getRandomRewardList()).build();
  2853. ActivityProto.BoxPoolOperateResponse response = ActivityProto.BoxPoolOperateResponse.newBuilder()
  2854. .setInfo(info)
  2855. .setDrop(drop).build();
  2856. MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.BoxPoolOperateResponse.getNumber(), response, true);
  2857. }
  2858. /**
  2859. * BOX扭蛋 手动重置
  2860. * @param session
  2861. * @param id
  2862. */
  2863. public void boxPoolManualReset(ISession session, int id) throws Exception {
  2864. int uid = session.getUid();
  2865. User user = UserManager.getUser(uid);
  2866. SBoxPoolConfig sBoxPoolConfig = STableManager.getConfig(SBoxPoolConfig.class).get(id);
  2867. if(sBoxPoolConfig == null){
  2868. throw new ErrorCodeException(ErrorCode.CFG_NULL);
  2869. }
  2870. ActivityMission activityMission = user.getActivityManager().getActivityMissionMap().get(sBoxPoolConfig.getActivityId());
  2871. if(activityMission == null && activityMission.getActivityState() != ActivityType.OPEN_STATE){
  2872. throw new ErrorCodeException(ErrorCode.ACTIVITY_NOT_OPEN);
  2873. }
  2874. int[] manualResetParam = sBoxPoolConfig.getManualReset();
  2875. if(manualResetParam[0] == 1 && manualResetParam[1] == 0) {
  2876. LOGGER.error("uid:{},can not manual reset.",uid);
  2877. throw new ErrorCodeException(ErrorCode.PARAM_ERR);
  2878. }
  2879. int lotteryId = sBoxPoolConfig.getFirstLotteryId();
  2880. SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(lotteryId);
  2881. if(sLotterySetting == null){
  2882. throw new ErrorCodeException(ErrorCode.CFG_NULL);
  2883. }
  2884. BoxPoolInfo boxPoolInfo = user.getActivityManager().getBoxPoolInfo(sBoxPoolConfig.getId());
  2885. if(boxPoolInfo == null){
  2886. boxPoolInfo = new BoxPoolInfo(sBoxPoolConfig.getId(),sBoxPoolConfig.getFirstLotteryId());
  2887. user.getActivityManager().addBoxPoolInfo(boxPoolInfo);
  2888. }
  2889. if(manualResetParam[1] >0 && boxPoolInfo.getManualResetCount() >= manualResetParam[1]){
  2890. LOGGER.error("reset count not enough,uid:{},manualResetCount:{},maxTimes:{}",uid,boxPoolInfo.getManualResetCount(),manualResetParam[1]);
  2891. throw new ErrorCodeException(ErrorCode.COUNT_NOT_ENOUGH);
  2892. }
  2893. //消耗商品
  2894. int[][] costItem = sBoxPoolConfig.getManualResetCost();//消耗的道具
  2895. Map<Integer,Integer> costItemMap = null;
  2896. if(costItem != null && costItem.length > 0){
  2897. costItemMap = new HashMap<>();
  2898. for(int[] array : costItem){
  2899. costItemMap.put(array[0],array[1] + costItemMap.getOrDefault(array[0],0));
  2900. }
  2901. }
  2902. boolean enoughCost = ItemUtil.checkCost(user,costItemMap);
  2903. if (!enoughCost) {
  2904. throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
  2905. }
  2906. ItemUtil.itemCost(user,costItemMap,BIReason.BOX_POOL_MANUAL_RESET,1);
  2907. resetBoxPoolInfo(uid,boxPoolInfo,false);//手动重置
  2908. ActivityProto.BoxPoolInfo info = ActivityProto.BoxPoolInfo.newBuilder().setId(boxPoolInfo.getId())
  2909. .setLotteryId(boxPoolInfo.getLotteryId()).setAutoResetCount(boxPoolInfo.getAutoResetCount())
  2910. .setManualResetCount(boxPoolInfo.getManualResetCount()).addAllRewardList(boxPoolInfo.getRandomRewardList()).build();
  2911. ActivityProto.BoxPoolOperateResponse response = ActivityProto.BoxPoolOperateResponse.newBuilder()
  2912. .setInfo(info).build();
  2913. MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.BoxPoolOperateResponse.getNumber(), response, true);
  2914. }
  2915. private boolean boxPoolRandomFinish(BoxPoolInfo boxPoolInfo, SLotterySetting sLotterySetting) {
  2916. int poolId = sLotterySetting.getDiamondBoxContain()[0][0];
  2917. List<SLotteryRewardConfig> sLotteryRewardConfigList = SLotteryRewardConfig.getSLotteryRewardConfigListByPoolId(poolId);
  2918. for(SLotteryRewardConfig sLotteryRewardConfig : sLotteryRewardConfigList){
  2919. if(!boxPoolInfo.getRandomRewardList().contains(sLotteryRewardConfig.getId())){
  2920. return false;
  2921. }
  2922. }
  2923. return true;
  2924. }
  2925. private void resetBoxPoolInfo(int uid, BoxPoolInfo boxPoolInfo, boolean autoReset){
  2926. SBoxPoolConfig sBoxPoolConfig = STableManager.getConfig(SBoxPoolConfig.class).get(boxPoolInfo.getId());
  2927. int poolRandomType = sBoxPoolConfig.getPoolRandomType();
  2928. List<Integer> lotteryIdArray = Arrays.stream(sBoxPoolConfig.getLotteryId()).boxed().collect(Collectors.toList());
  2929. int lotteryId = 0;
  2930. if(poolRandomType == 1){//顺序模式
  2931. int index = lotteryIdArray.indexOf(lotteryId);
  2932. if(index < 0){
  2933. lotteryId = lotteryIdArray.get(0);
  2934. } else if(index >= (lotteryIdArray.size()-1)){
  2935. lotteryId = lotteryIdArray.get(lotteryIdArray.size() - 1);
  2936. }else{
  2937. lotteryId = lotteryIdArray.get(index+1);
  2938. }
  2939. }else if(poolRandomType == 2){//随机模式
  2940. Collections.shuffle(lotteryIdArray);
  2941. lotteryId = lotteryIdArray.get(0);
  2942. }else{
  2943. LOGGER.error("poolRandomType not exits, uid:{},id:{},poolRandomType:{}",uid,boxPoolInfo.getId(),poolRandomType);
  2944. return;
  2945. }
  2946. boxPoolInfo.setLotteryId(lotteryId);
  2947. boxPoolInfo.setRandomRewardList(new ArrayList<>());
  2948. if(autoReset){
  2949. boxPoolInfo.setAutoResetCount(boxPoolInfo.getAutoResetCount() + 1);
  2950. }else{
  2951. boxPoolInfo.setManualResetCount(boxPoolInfo.getManualResetCount() + 1);
  2952. }
  2953. }
  2954. public void dailyRefreshBoxInfo(User user) {
  2955. try{
  2956. Collection<BoxPoolInfo> list = user.getActivityManager().getBoxPoolInfos();
  2957. for(BoxPoolInfo info : list){
  2958. SBoxPoolConfig sBoxPoolConfig = STableManager.getConfig(SBoxPoolConfig.class).get(info.getId());
  2959. if(sBoxPoolConfig != null){
  2960. int[] autoResetParam = sBoxPoolConfig.getAutoReset();
  2961. int[] manualResetParam = sBoxPoolConfig.getManualReset();
  2962. if(autoResetParam[0] == 2){
  2963. info.setLotteryId(0);
  2964. info.setRandomRewardList(new ArrayList<>());
  2965. info.setAutoResetCount(0);
  2966. }
  2967. if(manualResetParam[0] == 2) {
  2968. info.setManualResetCount(0);
  2969. }
  2970. }
  2971. }
  2972. }catch (Exception e){
  2973. LOGGER.error("error",e);
  2974. }
  2975. }
  2976. public int[][] fillUpForeverMemberReward(User user, int goodsId, int reward[][]){
  2977. int [][] result = reward;
  2978. try{
  2979. Integer activityId = SGlobalActivity.sRechargeId2ActivityId.get(goodsId);
  2980. SGlobalActivity sGlobalActivity2 = SGlobalActivity.getsGlobalActivityMap().get(activityId);
  2981. int activityType = sGlobalActivity2.getType();
  2982. List<SGlobalActivity> sGlobalActivityList = SGlobalActivity.getsGlobalActivityMapByType().get(activityType);
  2983. //List<SGlobalActivity> sGlobalActivityList = SGlobalActivity.getsGlobalActivityMapByType().get(ActivityType.FOREVER_MEMBER);
  2984. if(sGlobalActivityList == null || sGlobalActivityList.isEmpty()){
  2985. LOGGER.info("sGlobalActivityList is null, uid:{},goodsId:{}",user.getId(),goodsId);
  2986. return result;
  2987. }
  2988. SGlobalActivity config = null;
  2989. for(SGlobalActivity sGlobalActivity : sGlobalActivityList) {
  2990. if(Arrays.stream(sGlobalActivity.getCanBuyRechargeId()).anyMatch(e-> e==goodsId)){
  2991. config = sGlobalActivity;
  2992. break;
  2993. }
  2994. }
  2995. int[][] _reward = {};
  2996. List <SActivityRewardConfig> sActivityRewardConfigList = SActivityRewardConfig.getsActivityRewardConfigByActivityId(config.getId());
  2997. if(sActivityRewardConfigList != null){
  2998. for(SActivityRewardConfig sActivityRewardConfig : sActivityRewardConfigList) {
  2999. if(sActivityRewardConfig.getValues()[1][0] == 1){
  3000. _reward = sActivityRewardConfig.getReward();
  3001. break;
  3002. }
  3003. }
  3004. }
  3005. if(_reward.length > 0) {
  3006. Map<Integer,Integer> itemMap = new HashMap<>();
  3007. for(int[] items : reward){
  3008. itemMap.put(items[0],items[1]);
  3009. }
  3010. int num = TimeUtils.differentDays(user.getPlayerInfoManager().getCreateTime(),System.currentTimeMillis());
  3011. if(num > 0) {
  3012. for(int[] items : _reward){
  3013. itemMap.put(items[0],items[1] * num);
  3014. }
  3015. }
  3016. result = new int[itemMap.size()][];
  3017. int index = 0;
  3018. for(Map.Entry<Integer,Integer> entry : itemMap.entrySet()) {
  3019. result[index++] = new int[]{entry.getKey(),entry.getValue()};
  3020. }
  3021. }
  3022. }catch (Exception e) {
  3023. LOGGER.error("exception===> ",e);
  3024. }
  3025. return result;
  3026. }
  3027. public void activationForeverMember(User user, int goodsId,int activityType) {
  3028. try{
  3029. //List<SGlobalActivity> sGlobalActivityList = SGlobalActivity.getsGlobalActivityMapByType().get(ActivityType.FOREVER_MEMBER);
  3030. List<SGlobalActivity> sGlobalActivityList = SGlobalActivity.getsGlobalActivityMapByType().get(activityType);
  3031. if(sGlobalActivityList == null || sGlobalActivityList.isEmpty()){
  3032. LOGGER.info("sGlobalActivityList is null, uid:{},goodsId:{}",user.getId(),goodsId);
  3033. return;
  3034. }
  3035. SGlobalActivity config = null;
  3036. for(SGlobalActivity sGlobalActivity : sGlobalActivityList) {
  3037. if(Arrays.stream(sGlobalActivity.getCanBuyRechargeId()).anyMatch(e-> e==goodsId)){
  3038. config = sGlobalActivity;
  3039. break;
  3040. }
  3041. }
  3042. user.getActivityManager().setForeverMember(true);
  3043. ActivityMission activityMission = user.getActivityManager().getActivityMissionMap().get(config.getId());
  3044. if(activityMission == null){//活动检查定时任务可能还没检查到,手动检查一下再取活动数据
  3045. ActivityLogic.getInstance().checkActivityOfUser(user,null);
  3046. activityMission = user.getActivityManager().getActivityMissionMap().get(config.getId());
  3047. }
  3048. activityMission.setV(1);//客户端通过这个值判断已激活
  3049. // updateActivityMissionProgress(user,ActivityType.FOREVER_MEMBER,0);
  3050. updateActivityMissionProgress(user,activityType,0);
  3051. }catch (Exception e){
  3052. LOGGER.error("activationForeverMember exception, uid:{},goodsId:{}",user.getId(),goodsId);
  3053. LOGGER.error("activationForeverMember exception,",e);
  3054. }
  3055. }
  3056. public void checkDailyForeverMemberReward(){
  3057. sendDailyForeverMemberReward();
  3058. }
  3059. private void sendDailyForeverMemberReward() {
  3060. try{
  3061. LOGGER.info("sendDailyForeverMemberReward begin...");
  3062. MongoTemplate mongoTemplate = MongoUtil.getLjsdMongoTemplate().getMongoTemplate(GameApplication.serverId);
  3063. if(mongoTemplate == null){
  3064. LOGGER.error("sendDailyForeverMemberReward error, serverId:{}",GameApplication.serverId);
  3065. return;
  3066. }
  3067. Query countQuery = new Query();
  3068. countQuery.addCriteria(Criteria.where("activityManager.foreverMember").is(true));
  3069. long count = mongoTemplate.count(countQuery,User.class);
  3070. if(count <= 0) {
  3071. LOGGER.info("sendDailyForeverMemberReward count is 0.");
  3072. return;
  3073. }
  3074. int _limit = 500;//一次只返回这么多数据,分批次查询,分批次发
  3075. int page = (int)(count + _limit -1) / _limit;
  3076. int _id = 0;
  3077. for(int i = 0; i < page; i++){
  3078. Query query = new Query();
  3079. query.addCriteria(Criteria.where("activityManager.foreverMember").is(true))
  3080. .with(new Sort(Sort.Direction.ASC,"_id"))
  3081. .addCriteria(Criteria.where("_id").gt(_id)).limit(_limit)
  3082. .fields().include("activityManager.foreverMember");
  3083. List<User> list = mongoTemplate.find(query,User.class);
  3084. if(list != null && !list.isEmpty()){
  3085. _id = list.get(list.size()-1).getId();
  3086. for(User _user : list){
  3087. User user = UserManager.getUser(_user.getId());
  3088. AyyncWorker ayyncWorker = new AyyncWorker(user, false, new AyncWorkerRunnable() {
  3089. @Override
  3090. public void work(User user) throws Exception {
  3091. resumeActivity(user,ActivityType.FOREVER_MEMBER);
  3092. resumeActivity(user,ActivityType.FOREVER_MEMBER_PLUS);
  3093. }
  3094. });
  3095. ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);
  3096. }
  3097. }
  3098. }
  3099. LOGGER.info("sendDailyForeverMemberReward end...");
  3100. }catch (Exception e){
  3101. LOGGER.error("sendDailyForeverMemberReward error: ",e);
  3102. }
  3103. }
  3104. //周末福利 隔天刷新
  3105. public void flushDay(ISession session) throws Exception{
  3106. //周末福利 活动结束会清空道具
  3107. List<SGlobalActivity> sGlobalActivities = SGlobalActivity.getsGlobalActivityMapByType().get(ActivityType.WEEK_END_REWARD);
  3108. if(sGlobalActivities != null) {
  3109. Iterator<SGlobalActivity> iterator1 = sGlobalActivities.iterator();
  3110. while (iterator1.hasNext()) {
  3111. SGlobalActivity next1 = iterator1.next();
  3112. int activityId = next1.getId(); //活动id
  3113. User user = UserManager.getUser(session.getUid());
  3114. ActivityManager activityManager = user.getActivityManager();
  3115. ActivityMission activityMission = activityManager.getActivityMissionMap().get(activityId);
  3116. int dayOfWeek = TimeUtils.getDayOfWeek(); //获取周几, 周日 0; 其他正常
  3117. List<SActivityRewardConfig> sActivityRewardConfigs = SActivityRewardConfig.getsActivityRewardConfigByActivityId(activityId);
  3118. Iterator<SActivityRewardConfig> iterator = sActivityRewardConfigs.iterator();
  3119. int missionId = 0;
  3120. while (iterator.hasNext()) {
  3121. SActivityRewardConfig next = iterator.next();
  3122. int[][] values = next.getValues();
  3123. if (values[0][0] == 0 && values[1][0] == dayOfWeek) {
  3124. missionId = next.getId();
  3125. // ActivityProgressInfo activityProgressInfo = new ActivityProgressInfo();
  3126. // if(activityMission != null){
  3127. // activityProgressInfo = activityMission.getActivityMissionMap().get(missionId);
  3128. // }
  3129. if (activityMission == null) {
  3130. continue;
  3131. }
  3132. ActivityProgressInfo activityProgressInfo = activityMission.getActivityMissionMap().get(missionId);
  3133. if (activityProgressInfo == null) {
  3134. continue;
  3135. }
  3136. //up miss
  3137. activityProgressInfo.setProgrss(0);
  3138. activityProgressInfo.setState(ActivityType.WILL_TAKE);
  3139. if (activityMission != null) {
  3140. sendActivityProgress(session, activityMission, Collections.singleton(missionId), activityId);
  3141. }
  3142. }
  3143. }
  3144. }
  3145. }
  3146. }
  3147. public void sendActivityProgress(ISession session, ActivityMission activityMission, Set<Integer> filterMissId,int activityId) {
  3148. PlayerInfoProto.ActivityUpateProgressIndication.Builder builder = PlayerInfoProto.ActivityUpateProgressIndication.newBuilder();
  3149. builder.setActivityInfo(CommonProto.ActivityInfo.newBuilder().setValue(activityMission.getV()).addAllMission(getAllMissInfo(activityMission, filterMissId)).setActivityId(activityId));
  3150. if (session != null) {
  3151. MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.ACTIVITY_UPDATE_PROGRESS_INDICATION_VALUE, builder.build(), true);
  3152. }
  3153. }
  3154. public List<CommonProto.ActivityInfo.MissionInfo> getAllMissInfo(ActivityMission activityMission, Set<Integer> filter) {
  3155. Map<Integer, ActivityProgressInfo> activityProgressInfoMap = activityMission.getActivityMissionMap();
  3156. List<CommonProto.ActivityInfo.MissionInfo> missionInfos = new ArrayList<>(activityProgressInfoMap.size());
  3157. for (Map.Entry<Integer, ActivityProgressInfo> missionProgress : activityProgressInfoMap.entrySet()) {
  3158. if (filter != null && !filter.contains(missionProgress.getKey())) {
  3159. continue;
  3160. }
  3161. Integer missionId = missionProgress.getKey();
  3162. ActivityProgressInfo activityProgressInfo = missionProgress.getValue();
  3163. missionInfos.add(CommonProto.ActivityInfo.MissionInfo.newBuilder().setMissionId(missionId).setProgress(activityProgressInfo.getProgrss()).setState(activityProgressInfo.getState()).build());
  3164. }
  3165. return missionInfos;
  3166. }
  3167. public void flushWeek(ISession session) throws Exception {
  3168. //周末福利 活动结束会清空道具
  3169. List<SGlobalActivity> sGlobalActivities = SGlobalActivity.getsGlobalActivityMapByType().get(ActivityType.WEEK_END_REWARD);
  3170. Iterator<SGlobalActivity> iterator1 = sGlobalActivities.iterator();
  3171. while (iterator1.hasNext()) {
  3172. SGlobalActivity next1 = iterator1.next();
  3173. int activityId = next1.getId(); //活动id
  3174. User user = UserManager.getUser(session.getUid());
  3175. ActivityManager activityManager = user.getActivityManager();
  3176. ActivityMission activityMission = activityManager.getActivityMissionMap().get(activityId);
  3177. int dayOfWeek = TimeUtils.getDayOfWeek(); //获取周几, 周日 0; 其他正常
  3178. List<SActivityRewardConfig> sActivityRewardConfigs = SActivityRewardConfig.getsActivityRewardConfigByActivityId(activityId);
  3179. Iterator<SActivityRewardConfig> iterator = sActivityRewardConfigs.iterator();
  3180. Set<Integer> missions = new HashSet<>();
  3181. while (iterator.hasNext()) {
  3182. SActivityRewardConfig next = iterator.next();
  3183. // int[][] values = next.getValues();
  3184. // if (values[0][0] == 0 && values[1][0] != dayOfWeek) {
  3185. int missionId = next.getId();
  3186. missions.add(missionId);
  3187. if(activityMission == null){
  3188. continue;
  3189. }
  3190. ActivityProgressInfo activityProgressInfo = activityMission.getActivityMissionMap().get(missionId);
  3191. if(activityProgressInfo == null){
  3192. continue;
  3193. }
  3194. //up miss
  3195. activityProgressInfo.setProgrss(0);
  3196. activityProgressInfo.setState(ActivityType.WILL_TAKE);
  3197. // }
  3198. }
  3199. if(activityMission != null) {
  3200. sendActivityProgress(session, activityMission, missions, activityId);
  3201. }
  3202. }
  3203. }
  3204. }