//这个只会在初始化调用 server需要手动调用。 但是客户端之后播放录像的时候调用初始化。 protected void initMap() { //这两个参数需要后端自己赋值。 先临时这么写一下。 if (FightMain.instance.mode == ConfigConstant.MODE_CHAOS || FightMain.instance.mode == ConfigConstant.MODE_TEST_CHAOS) { FightMain.instance.mapId = "map01"; } else { FightMain.instance.mapId = "map02"; } this.mapData = new MapData(FightMain.instance.mapId, FightMain.instance.mode); this._delayCalls = new MultiAction(this); this.birthBeanController = new BirthBeanController(this); this.birthBeanController.init(); //Biggo添加 //if (FightMain.isLocal) this.aiController = new AIController(this); //警告之后地图里的要加速。 this.warnning = this.addDelayCall((this.mapData.fightTime - this.mapData.finalTime) * 1000, this.warningTimeHandler, ConfigConstant.MAP_CALL_BACK_WARNING); this.birthGrids = new BirthGridManager(this); this.findEntity = new FindEntityManager(this); this.createBarrier(); this.birthGrids.createBirthGrids(); //这一步如果有萝卜 就创建萝卜。 this.refereeController = new RefereeController(this); this.refereeController.init(); this.createPlayers(); FightMain.isTest = true; this.createBean(); this.birthBeanController.removeWaitBean(); //this.printGrid(); }
protected virtual void setData(Dictionary <string, object> data) { this.mapData = new MapData(data["id"].ToString(), (int)(data["fightMode"])); if (data.ContainsKey("playerInitData")) { this.mapData.playerInitData = new List <object>((object[])data["playerInitData"]); } this.birthGrids = new BirthGridManager(this); this.findEntity = new FindEntityManager(this); //TODO:写在这里 容易对比。 后端不用抄setData的方法。 List <Dictionary <string, object> > netObjectDatas = new List <object>((object[])data["entitys"]).ConvertAll <Dictionary <string, object> >((object obj) => { return((Dictionary <string, object>)obj); }); netObjectDatas.Sort((Dictionary <string, object> obj1, Dictionary <string, object> obj2) => { return((int)(obj1["type"]) - (int)(obj2["type"])); }); Dictionary <int, INetObject> netObjects = this._netObjects; this._netObjects = new Dictionary <int, INetObject>(); //先生成出netObject for (int i = 0, len = netObjectDatas.Count; i < len; i++) { int netId = (int)(netObjectDatas[i]["netId"]); INetObject obj = netObjects.ContainsKey(netId) ? netObjects[netId] : null; int type = (int)(netObjectDatas[i]["type"]); if (null != obj && obj.type != type) { throw new Exception("初始化类型不对!"); } if (null == obj) { NetObjectFactory.createNetObject(type, this, netId); } else { netObjects.Remove(netId); this.addNetObject(obj); } } //netObject已经被移除掉了。 此时如果再有就说明恢复过程中有被删除的。这里手动的把它们删除掉! foreach (INetObject obj in netObjects.Values) { Utils.clearObject(obj); } this.netId = (int)(data["netId"]); this.random.seed = long.Parse((data["randomSeed"]).ToString()); this.random.seedNum = (int)(data["randomSeedNum"]); this._delayCalls = (MultiAction)this.getNetObject((int)(data["delayCalls"])); this.speedRate = Convert.ToSingle(data["speedRate"]); this.powerGain = (int)(data["powerGain"]); this.killPlayerNum = (int)(data["killPlayerNum"]); if (data.ContainsKey("warnning")) { this.warnning = (TimeAction)this.getNetObject((int)(data["warnning"])); this.warnning.callBack = this.warningTimeHandler; } else { this.warningTimeHandler(); } this.birthBeanController = (BirthBeanController)this.getNetObject((int)(data["birthBeanController"])); this.refereeController = (RefereeController)this.getNetObject((int)(data["refereeController"])); this.beans = new List <object>((object[])data["beans"]).ConvertAll <LoopBeanEntity>((object netId) => { return((LoopBeanEntity)this.getNetObject((int)(netId))); }); this.persons = new List <object>((object[])data["persons"]).ConvertAll <PersonEntity>((object netId) => { return((PersonEntity)this.getNetObject((int)(netId))); }); this.players = new List <object>((object[])data["players"]).ConvertAll <PlayerEntity>((object netId) => { return((PlayerEntity)this.getNetObject((int)(netId))); }); this.bullets = new List <object>((object[])data["bullets"]).ConvertAll <BulletEntity>((object netId) => { return((BulletEntity)this.getNetObject((int)(netId))); }); this.others = new List <object>((object[])data["others"]).ConvertAll <FightEntity>((object netId) => { return((FightEntity)this.getNetObject((int)(netId))); }); //按照type顺序 进行初始化。 优先级 gemo->buff->actionBase->actionCommon->action->entity for (int i = 0, len = netObjectDatas.Count; i < len; i++) { int netId = (int)(netObjectDatas[i]["netId"]); this.getNetObject(netId).setData(netObjectDatas[i]); } this.birthGrids.createBirthGrids(); ((ClientRunTime)this).localPlayer = (ClientPlayerEntity)this.getPlayer(((ClientRunTime)this).uid); //for(int i = 0, len = this.players.Count; i < len; i++) { // ( (ClientPlayerEntity)this.players[i] ).build(); //} //Biggo添加 if (FightMain.isLocal) { this.aiController = new AIController(this); } for (int i = 0, len = this.players.Count; i < len; i++) { if (this.players[i] != ((ClientRunTime)this).localPlayer) { this.aiController.openAI(this.players[i], 1); } } }