GM添加道具

back_recharge
gaojie 2019-01-15 15:03:28 +08:00
parent c675a9f768
commit 93fb410ee9
12 changed files with 222 additions and 81 deletions

View File

@ -0,0 +1,6 @@
Id Name BackpackOrNot ItemType ItemBaseType Quantity IsStacking
int string bool int int int bool
1 玩家经验 false 0 1 5 false
2 金币 true 0 1 5 false
3 钻石 true 0 1 5 false
4 铁矿 false 0 1 5 false

View File

@ -1,18 +0,0 @@
id event groups
int int mut,int#int,2
1 102011 13#8|13#9|14#8|14#9
2 101010 10#5
3 102010 18#5|18#6|19#5|19#6
4 102013 9#1|9#2|10#1|10#2
5 102001 2#3|3#1|3#4
6 101001 4#4|4#5|5#4|5#5|5#7|5#8|6#1|6#2|6#7|6#8|7#1|7#2|18#9|18#10|19#9|19#10|20#6|20#7
7 102012 13#1|13#2|14#1|14#2
8 102004 7#9|7#10|8#3|8#4|8#9|8#10|9#3|9#4|11#2|11#3|12#2|12#3|13#5|13#6|14#5|14#6|15#9|15#10|16#9|16#10
9 102015 9#8|10#8
10 102014 6#4|6#5|7#4|7#5
11 101005 8#6|8#7|9#6|9#7|18#2|18#3|19#2|19#3
12 102016 15#3|16#3
13 101006 3#2
14 101007 2#10
15 101008 17#7
16 101009 12#9

View File

@ -1,14 +0,0 @@
id event groups
int int mut,int#int,2
1 201012 5#3|5#4|6#3|6#4
2 101010 9#8
3 101011 16#7
4 101001 2#6|3#5|3#6|4#8|4#9|5#8|6#7|7#7|8#5|8#6|9#5|9#6|11#4|12#4|14#6|15#6|16#3|16#4|17#3|17#4
5 101002 12#1|12#2|13#1|13#2|18#5|18#6|19#6
6 101003 4#4
7 101004 5#10|6#10
8 101005 7#1|7#2|8#1|8#2|11#8|11#9|12#8|12#9|14#2|14#3|14#9|14#10|15#2|15#3|15#9|15#10|19#4|19#7|19#8|20#3|20#8
9 101006 3#8
10 101007 5#5
11 101008 11#10
12 101009 18#2

View File

@ -1,30 +0,0 @@
Id Style Refresh
int int int
101001 1 2
101002 3 2
101003 5 2
101004 9 2
101005 1 2
101006 6 3
101007 7 3
101008 6 2
101009 6 3
101010 8 2
101011 8 2
101012 4 2
102001 9 2
102002 1 2
102003 1 2
102004 1 2
102005 6 3
102006 6 3
102007 6 3
102008 6 3
102009 6 3
102010 3 1
102011 3 2
102012 3 2
102013 3 1
102014 3 2
102015 2 2
102016 2 2

View File

@ -1,3 +0,0 @@
id length width
int int int
1 10 20

View File

@ -62,7 +62,7 @@ public class GameApplication {
RedisUtil.getInstence().init(configurableApplicationContext);
// STableManager.initialize("com.ljsd.jieling.config");
STableManager.initialize("com.ljsd.jieling.config");
UserManager.init(configurableApplicationContext);

View File

@ -0,0 +1,51 @@
package com.ljsd.jieling.config;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.Table;
import java.util.Map;
@Table(name = "ItemConfig")
public class SItem implements BaseConfig {
public static Map<Integer, SItem> sItemMap;
private int id;
private boolean backpackOrNot; //是否进背包
private int itemType;
private int itemBaseType; //道具类型(该道具在哪个背包显示)
private int quantity;
private boolean isStacking;
@Override
public void init() throws Exception {
sItemMap = STableManager.getConfig(SItem.class);
}
public int getId() {
return id;
}
public static Map<Integer, SItem> getsItemMap() {
return sItemMap;
}
public boolean isBackpackOrNot() {
return backpackOrNot;
}
public int getItemType() {
return itemType;
}
public int getItemBaseType() {
return itemBaseType;
}
public int getQuantity() {
return quantity;
}
public boolean isStacking() {
return isStacking;
}
}

View File

@ -0,0 +1,5 @@
package com.ljsd.jieling.globals;
public interface GlobalGm {
int ADD_ITEM = 0;//添加道具
}

View File

@ -0,0 +1,56 @@
package com.ljsd.jieling.handler.GameGM;
import com.ljsd.jieling.globals.GlobalGm;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.dao.Item;
import com.ljsd.jieling.logic.dao.ItemManager;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.GMCommandProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.ItemUtil;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Component
public class GMRequestHandler extends BaseHandler{
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(GMRequestHandler.class);
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.GM_COMMAND;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
byte[] message = netData.parseClientProtoNetData();
GMCommandProto.GMCommand gmCommand = GMCommandProto.GMCommand.parseFrom(message);
String command = gmCommand.getCommand();
if (!command.contains("#") || command.split("#").length < 3) {
LOGGER.error("wrong command :" + command);
return;
}
String[] commandArray = command.split("#");
int uid = Integer.parseInt(commandArray[0]);
int gmCommandType = Integer.parseInt(commandArray[1]);// type 0添加道具
int prarm1 = 0, prarm2 = 0;
User cUser = UserManager.getUser(uid);
switch (gmCommandType){
case GlobalGm.ADD_ITEM:
giveItem(cUser,prarm1,prarm2);
break;
}
}
private void giveItem(User cUser,int itemId,int itemNum) throws Exception {
Map<Integer,Integer> itemMap = new ConcurrentHashMap<>();
itemMap.put(itemId,itemNum);
ItemUtil.addItem(cUser,itemMap);
}
}

View File

@ -1,6 +1,7 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
import com.ljsd.jieling.config.SItem;
import java.util.HashMap;
import java.util.Map;
@ -20,7 +21,7 @@ public class ItemManager extends MongoBase {
this.itemMap = itemMap;
}
public void addItem(Item item) throws Exception {
public void addItem(Item item) throws Exception {
item.init(getRoot(), getMongoKey() + ".itemMap." + item.getItemId());
updateString("itemMap." + item.getItemId(), item);
itemMap.put(item.getItemId(), item);
@ -34,4 +35,17 @@ public class ItemManager extends MongoBase {
itemMap.remove(key);
}
public Item newItem(int itemId, int itemNum) throws Exception {
SItem sItem = SItem.getsItemMap().get(itemId);
Item item = new Item();
item.setItemId(itemId);
item.setItemNum(itemNum);
item.setItemType(sItem.getItemType());
item.setItemQuality(sItem.getQuantity());
int endTime = (int)(System.currentTimeMillis()/1000);
item.setEndingTime(endTime);
item.setStacking( sItem.isStacking());
return item;
}
}

View File

@ -0,0 +1,36 @@
package com.ljsd.jieling.util;
import com.ljsd.jieling.config.SItem;
import com.ljsd.jieling.logic.dao.Item;
import com.ljsd.jieling.logic.dao.ItemManager;
import com.ljsd.jieling.logic.dao.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
public class ItemUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(ItemUtil.class);
/**
*
* @param user
* @param itemMap
* @throws Exception
*/
public static void addItem(User user, Map<Integer, Integer> itemMap) throws Exception {
ItemManager itemManager = user.getItemManager();
for (Map.Entry<Integer, Integer> entry : itemMap.entrySet()) {
Item item = itemManager.getItem(entry.getKey());
if (item == null){
item = itemManager.newItem(entry.getKey(), entry.getValue());
}else{
if (item.isStacking()){
item.setItemNum(item.getItemNum() + entry.getValue());
}
}
itemManager.addItem(item);
}
}
}

View File

@ -9,12 +9,9 @@ import java.util.List;
import java.util.Map;
public class ExcelUtils {
// private static final Logger LOGGER = LoggerFactory.getLogger(ExcelUtils.class);
private static boolean isWrite = true;
// excel文件地址
private static String excelPath ="tmp/";
// 生成txt文件地址
private static String path = "conf/server/";
private static String path = "C:/ljsd/jieling_conf/";
public static void main(String[] args) throws IOException {
readExcelData();
@ -49,30 +46,53 @@ public class ExcelUtils {
Object cellData;
sheet = wb.getSheetAt(0);
String sheetName = sheet.getSheetName();
System.out.println("buildDataInfo => collection name="+sheetName);
// LOGGER.info("collection name={}", sheetName);
System.out.println("bulidMapInfo => collection name="+sheetName);
int rownum = sheet.getPhysicalNumberOfRows();
FileWriter fw = new FileWriter(path + sheetName + ".txt");
PrintWriter out = new PrintWriter(fw);
for (int i = 0; i < rownum; i++) {
if (i == 2 || i == 3){
if (i == 2 || i == 3 || i == 4 ||i == 5||i == 6){
continue;
}
Row row1 = sheet.getRow(2);
Row row2 = sheet.getRow(1);
Row row4 = sheet.getRow(4);
int colnum = row1.getPhysicalNumberOfCells();
row = sheet.getRow(i);
// for (Cell c :row){
// System.out.println(c.getColumnIndex() +"==="+row.getCell(c.getColumnIndex()));
// }
if (row != null) {
int colnum = row.getPhysicalNumberOfCells();
StringBuilder info = new StringBuilder();
for (int j = 0; j < colnum; j++) {
if (getCellFormatValue(row1.getCell(j)).toString().isEmpty()){
continue;
}
for (int j = 1; j <= colnum; j++) {
int cellFormatValue = (int) getCellFormatValue(row1.getCell(j));
if (cellFormatValue == 3){
continue;
}
Cell cell = row.getCell(j);
if (cell == null){
Cell cell1 = row4.getCell(j);
if (cell1==null){
String in = getIn(row2.getCell(j).toString());
if (info.length() == 0){
info = info.append(in);
}else{
info.append("\t").append(in);
}
}else{
cellData = getCellFormatValue(cell1);
if (info.length() == 0){
info = info.append(cellData);
}else{
info.append("\t").append(cellData);
}
}
}
if (getCellFormatValue(row1.getCell(j)).toString().isEmpty()){
continue;
}
//文件名
cellData = getCellFormatValue(row.getCell(j));
cellData = getCellFormatValue(cell);
if (info.length() == 0){
info = info.append(cellData);
}else{
@ -87,11 +107,25 @@ public class ExcelUtils {
out.close();
}
private static String getIn(String row2) {
String str = "";
switch (row2) {
case "bool":
str = "false";
break;
case "int":
str = "0";
break;
default:
str = null;
}
return str;
}
private static void bulidMapInfo(Workbook wb) throws IOException {
Sheet sheet = wb.getSheetAt(0);
String sheetName = sheet.getSheetName();
System.out.println("bulidMapInfo => collection name="+sheetName);
// LOGGER.info("collection name={}", sheetName);
int rowNum = sheet.getPhysicalNumberOfRows();
FileWriter fw = new FileWriter(path + sheetName + ".txt");
PrintWriter out = new PrintWriter(fw);
@ -225,6 +259,10 @@ public class ExcelUtils {
}
break;
}
case Cell.CELL_TYPE_BOOLEAN:{
cellValue =cell.getBooleanCellValue();
break;
}
case Cell.CELL_TYPE_STRING: {
cellValue = cell.getRichStringCellValue().getString();
break;