back_recharge
wangyuan 2019-01-07 16:16:59 +08:00
parent a5db8e814a
commit d953c6377a
10 changed files with 292 additions and 8 deletions

View File

@ -40,7 +40,7 @@ public class LjsdMongoTemplate {
public <T> T findById(String collectionName, String id, Class<T> clazz) throws Exception {
DBCollection coll = mongoTemplate.getCollection(collectionName);
DBObject doc = coll.findOne(id.toString());
DBObject doc = coll.findOne(id);
return BeanUtil.dbObject2Bean(doc, clazz);
}

View File

@ -0,0 +1,5 @@
package com.ljsd.jieling.core;
public interface GlobalsDef {
String DEFAULT_NAME = "无名妖灵师";
}

View File

@ -1,5 +1,7 @@
package com.ljsd.jieling.handler;
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.CommonProto;
@ -33,11 +35,12 @@ public class LoginRequestHandler extends BaseHandler {
LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={},messageNum={},messageStr={}",
userId, token,msgId,msgIndex,getPlayerInfoRequest.getNum(),getPlayerInfoRequest.getStr());
User userForLogin = UserManager.getUserForLogin(userId);
CommonProto.Common.Player player = CommonProto.Common.Player
.newBuilder()
.setUid(12345)
.setUid(userId)
.setGold(10000)
.build();

View File

@ -0,0 +1,127 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
public class Hero extends MongoBase {
private String id;
private int templateId; //模板ID
private int heroType;
private int level;//等级
private int star;
private int quality;
private int hp;
private int attack;
private int pDefence;
private int mDefence;
private int speed;
public void setId(String id) throws Exception {
updateString("id",id);
this.id = id;
}
public void setTemplateId(int templateId) throws Exception {
updateString("templateId",templateId);
this.templateId = templateId;
}
public void setHeroType(int heroType) throws Exception {
updateString("heroType",heroType);
this.heroType = heroType;
}
public void setLevel(int level) throws Exception {
updateString("level",level);
this.level = level;
}
public void setStar(int star) throws Exception {
updateString("star",star);
this.star = star;
}
public void setQuality(int quality) throws Exception {
updateString("quality",quality);
this.quality = quality;
}
public void setHp(int hp) throws Exception {
updateString("hp",hp);
this.hp = hp;
}
public void setAttack(int attack) throws Exception {
updateString("attack",attack);
this.attack = attack;
}
public void setpDefence(int pDefence) throws Exception {
updateString("pDefence",pDefence);
this.pDefence = pDefence;
}
public void setmDefence(int mDefence) throws Exception {
updateString("mDefence",mDefence);
this.mDefence = mDefence;
}
public void setSpeed(int speed) throws Exception {
updateString("speed",speed);
this.speed = speed;
}
public String getId() {
return id;
}
public int getTemplateId() {
return templateId;
}
public int getHeroType() {
return heroType;
}
public int getLevel() {
return level;
}
public int getStar() {
return star;
}
public int getQuality() {
return quality;
}
public int getHp() {
return hp;
}
public int getAttack() {
return attack;
}
public int getpDefence() {
return pDefence;
}
public int getmDefence() {
return mDefence;
}
public int getSpeed() {
return speed;
}
}

View File

@ -2,6 +2,37 @@ package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
import java.util.HashMap;
import java.util.Map;
public class HeroManager extends MongoBase {
private Map<String, Hero> heroMap;
public HeroManager() {
heroMap = new HashMap();
}
public Map<String, Hero> getItemMap() {
return heroMap;
}
public void setItemMap(Map<String, Hero> heroMap) {
this.heroMap = heroMap;
}
public void addHero(Hero hero) throws Exception {
//绑定关系
hero.init(getRoot(), getMongoKey() + ".heroMap." + hero.getId());
updateString("heroMap." + hero.getTemplateId(), hero);
heroMap.put(hero.getId(), hero);
}
public Hero getHero(String heroId) {
return heroMap.get(heroId);
}
public void removeHero(String heroId) {
heroMap.remove(heroId);
}
}

View File

@ -0,0 +1,37 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
public class Item extends MongoBase {
private int templateId;
private int overlap;
private long haveTime;
public void setTemplateId(int templateId) throws Exception {
updateString("templateId",templateId);
this.templateId = templateId;
}
public void setOverlap(int overlap) throws Exception {
updateString("overlap",overlap);
this.overlap = overlap;
}
public void setHaveTime(long haveTime) throws Exception {
updateString("haveTime",haveTime);
this.haveTime = haveTime;
}
public int getTemplateId() {
return templateId;
}
public int getOverlap() {
return overlap;
}
public long getHaveTime() {
return haveTime;
}
}

View File

@ -2,7 +2,36 @@ package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
public class ItemManager extends MongoBase {
import java.util.HashMap;
import java.util.Map;
public class ItemManager extends MongoBase {
private Map<Integer, Item> itemMap;
public ItemManager() {
itemMap = new HashMap();
}
public Map<Integer, Item> getItemMap() {
return itemMap;
}
public void setItemMap(Map<Integer, Item> itemMap) {
this.itemMap = itemMap;
}
public void addItem(Item item) throws Exception {
item.init(getRoot(), getMongoKey() + ".itemMap." + item.getTemplateId());
updateString("itemMap." + item.getTemplateId(), item);
itemMap.put(item.getTemplateId(), item);
}
public Item getItem(Integer key) {
return itemMap.get(key);
}
public void removeItem(Integer key) {
itemMap.remove(key);
}
}

View File

@ -15,9 +15,48 @@ public class User extends MongoRoot {
private MapManager mapManager;
public User(int uid,MapManager mapManager){
public User(int uid,PlayerInfoManager playerInfoManager, ItemManager itemManager,
HeroManager heroManager, MapManager mapManager){
setMyMongoDBPool(_myMongoDBPool);
setId(Integer.toString(uid));
this.playerInfoManager = playerInfoManager;
this.itemManager = itemManager;
this.heroManager = heroManager;
this.mapManager = mapManager;
//綁定关系
playerInfoManager.init(this, "playerInfoManager", false);
itemManager.init(this, "itemManager", false);
heroManager.init(this, "heroManager", false);
mapManager.init(this, "mapManager", false);
}
public User(){
setMyMongoDBPool(_myMongoDBPool);
this.playerInfoManager = new PlayerInfoManager();
this.itemManager = new ItemManager();
this.heroManager = new HeroManager();
this.mapManager = new MapManager();
//綁定关系
playerInfoManager.init(this, "playerInfoManager", false);
itemManager.init(this, "itemManager", false);
heroManager.init(this, "heroManager", false);
mapManager.init(this, "mapManager", false);
}
public PlayerInfoManager getPlayerInfoManager() {
return playerInfoManager;
}
public ItemManager getItemManager() {
return itemManager;
}
public HeroManager getHeroManager() {
return heroManager;
}
public MapManager getMapManager() {
return mapManager;
}
public static void init(LjsdMongoTemplate ljsdMongoTemplate) {

View File

@ -9,7 +9,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class UserManager {
private static Map<Integer, User> userMap = new ConcurrentHashMap<>();
private static LjsdMongoTemplate ljsdMongoTemplate;
public static LjsdMongoTemplate ljsdMongoTemplate;
public static void init(ConfigurableApplicationContext configurableApplicationContext) {
ljsdMongoTemplate =configurableApplicationContext.getBean(LjsdMongoTemplate.class);
User.init(ljsdMongoTemplate);
@ -25,13 +25,24 @@ public class UserManager {
user = ljsdMongoTemplate.findById(User.getCollectionName(), Integer.toString(uid), User.class);
}
if (user == null) {
user = new User(uid,new MapManager());
UserManager.addUser(user);
ljsdMongoTemplate.save(user);
user = registerUser(uid);
}else{
refreshUserLoginInfo(user);
}
return user;
}
private static void refreshUserLoginInfo(User user) {
}
private static User registerUser(int uid) throws Exception {
User user = new User(uid,new PlayerInfoManager(),new ItemManager(),new HeroManager(),new MapManager());
UserManager.addUser(user);
ljsdMongoTemplate.save(user);
return user;
}
public static User getUser(int uid) throws Exception {
User user = userMap.get(uid);

View File

@ -1,6 +1,7 @@
package com.ljsd.jieling.util;
import com.google.protobuf.GeneratedMessage;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.netty.PackageConstant;
import com.ljsd.jieling.netty.cocdex.Tea;
import com.ljsd.jieling.network.session.ISession;
@ -46,6 +47,7 @@ public class MessageUtil {
public static void sendMessage(ISession session, int uid,int index, int result, int msgId, GeneratedMessage generatedMessage, boolean flush) throws Exception {
byte[] byteBuf = wrappedBuffer(uid, session.getToken(), index, result, msgId, generatedMessage);
UserManager.ljsdMongoTemplate.lastUpdate();
if (flush) {
session.writeAndFlush(byteBuf);
} else {