private void sendRollInfo( List<AbstractRole> sameMapMembers, int[] points, GoodsBase goodsBase, int num, AbstractRole winner, int maxIndex) { // 构建roll点信息 StringBuffer buffer = new StringBuffer(); buffer.append(((RoleInstance) winner).getRoleName()); buffer.append( GameContext.getI18n().messageFormat(TextId.FALL_ROLL_POINT_GAIN, points[maxIndex])); buffer.append(Wildcard.getChatGoodsContent(goodsBase, ChannelType.System, num)); // buffer.append("[").append(goodsBase.getName()).append("]"); int index = -1; for (AbstractRole role : sameMapMembers) { index++; if (role.getRoleId().equals(winner.getRoleId())) { continue; } buffer.append(","); buffer.append(((RoleInstance) role).getRoleName()); buffer.append(" "); buffer.append(points[index]); buffer.append(GameContext.getI18n().getText(TextId.FALL_ROLL_POINT)); } C1802_ChatRouteRespMessage trsMsg = new C1802_ChatRouteRespMessage(); trsMsg.setChannelType(ChannelType.System.getType()); trsMsg.setMessage(buffer.toString()); trsMsg.setContextList(null); trsMsg.setSendRoleId(-1); trsMsg.setSendRoleName(GameContext.getI18n().getText(TextId.SYSTEM)); for (AbstractRole role : sameMapMembers) { role.getBehavior().sendMessage(trsMsg); } }
@Override public boolean fallBox(NpcInstance dieNpc, RoleInstance role, OutputConsumeType ocType) { // 1.获得npc掉落 // 2.获得世界掉落 // 3.获得任务掉落 // 4.生成宝箱 if (null == dieNpc || null == role || null == role.getMapInstance()) { return false; } String templateId = dieNpc.getNpc().getNpcid(); Team team = role.getTeam(); if (null == team || team.getOnlinePlayerNum() <= 1) { // 获得掉落物品 List<GoodsOperateBean> npcLootList = this.getLootGoodsBeanMap(templateId); // 任务掉落 List<GoodsOperateBean> questGoodsList = this.getQuestLootList(templateId, role); if (!Util.isEmpty(questGoodsList)) { if (null == npcLootList) { npcLootList = new ArrayList<GoodsOperateBean>(); } npcLootList.addAll(questGoodsList); } return this.npcDieFallBox(role, npcLootList, dieNpc, ocType); } // 获得本地图内同队伍的玩家 MapInstance mapInstance = role.getMapInstance(); List<AbstractRole> sameMapMembers = new ArrayList<AbstractRole>(); for (AbstractRole member : team.getMembers()) { MapInstance mi = member.getMapInstance(); if (null == mi || !mi.getInstanceId().equals(mapInstance.getInstanceId())) { continue; } sameMapMembers.add(member); } NpcTemplate npcTemplate = GameContext.getNpcApp().getNpcTemplate(templateId); LootList lootList = npcLootListMap.get(npcTemplate.getLootNpc() + ""); LootList worldLootList = worldLootListMap.get(npcTemplate.getLootWorld() + ""); List<GoodsOperateBean> needRollList = null; List<GoodsOperateBean> allMapGoodsList = null; if (null != lootList && lootList.getLootType() == NpcLootType.NORMAL.getType()) { needRollList = this.mergerGoodsBeanMap(this.getGoodsBean(lootList), this.getGoodsBean(worldLootList)); } else { needRollList = this.getGoodsBean(worldLootList); allMapGoodsList = this.getGoodsBean(lootList); } // roll点分配 Map<String, List<GoodsOperateBean>> rollList = this.roll(needRollList, sameMapMembers); for (AbstractRole itemRole : sameMapMembers) { List<GoodsOperateBean> roleRollList = rollList.get(itemRole.getRoleId()); List<GoodsOperateBean> questGoodsList = this.getQuestLootList(templateId, (RoleInstance) itemRole); List<GoodsOperateBean> roleList = new ArrayList<GoodsOperateBean>(); if (!Util.isEmpty(roleRollList)) { roleList.addAll(roleRollList); } if (!Util.isEmpty(questGoodsList)) { roleList.addAll(questGoodsList); } if (!Util.isEmpty(allMapGoodsList)) { roleList.addAll(allMapGoodsList); } if (Util.isEmpty(roleList)) { continue; } this.npcDieFallBox((RoleInstance) itemRole, roleList, dieNpc, ocType); } return true; }
/** * roll点分配 * * @param itemList * @param sameMapMembers * @return */ public Map<String, List<GoodsOperateBean>> roll( List<GoodsOperateBean> itemList, List<AbstractRole> sameMapMembers) { Map<String, List<GoodsOperateBean>> result = Maps.newHashMap(); if (Util.isEmpty(itemList)) { return result; } int size = sameMapMembers.size(); if (1 == size) { result.put(sameMapMembers.get(0).getRoleId(), itemList); return result; } for (GoodsOperateBean agb : itemList) { try { int goodsId = agb.getGoodsId(); int goodsNum = agb.getGoodsNum(); GoodsBase goodsBase = GameContext.getGoodsApp().getGoodsBase(goodsId); if (null == goodsBase) { continue; } int[] points = new int[size]; int maxIndex = 0; int maxPoint = -1; int prePoint = -1; // 前一次随机分数 for (int index = 0; index < size; index++) { int point = 0; if (goodsBase.getCareer() < 0 || goodsBase.getCareer() == ((RoleInstance) sameMapMembers.get(index)).getCareer()) { // 职业匹配额外+50分,确保物品被匹配的职业roll到 point = 50; } int thisPoint = RandomUtil.randomIntWithoutZero(50) + point; if (prePoint == thisPoint) { // 随机的点数与上次相同,再随机一次 thisPoint = RandomUtil.randomIntWithoutZero(50) + point; } if (maxPoint < thisPoint) { maxPoint = thisPoint; maxIndex = index; } else if (maxPoint == thisPoint && RandomUtil.randomBoolean()) { // 点数相同,随机处理一下是否替换,否则一直是第一个分数相同的人 maxIndex = index; } points[index] = thisPoint; prePoint = thisPoint; } AbstractRole winner = sameMapMembers.get(maxIndex); String maxRoleId = winner.getRoleId(); if (!result.containsKey(maxRoleId)) { result.put(maxRoleId, new ArrayList<GoodsOperateBean>()); } result.get(maxRoleId).add(agb); // 蓝色(含)品质的物品需要发送roll结构 boolean sendRollResult = goodsBase.getQualityType() >= QualityType.blue.getType(); if (sendRollResult) { sendRollInfo(sameMapMembers, points, goodsBase, goodsNum, winner, maxIndex); } } catch (Exception ex) { logger.error("", ex); } } return result; }