private void SetupPlayers(GameContext game, Presets preset, HexGridBehaviour grid) { PlayerListData pld = GameObject.FindObjectOfType <PlayerListData>(); if (pld != null) { IEnumerator <Vector3> basePos = CoordinatesForBases(grid); foreach (var player in pld._model) { GameEntity pEntity = game.CreateEntity(); pEntity.AddTeam(player.Color); pEntity.isLocalPlayer = (player.Type == PlayerTypeEnum.Human); pEntity.isAIPlayer = (player.Type == PlayerTypeEnum.AI); basePos.MoveNext(); GameEntity baseEntity = preset.CreateBlueprint(Presets.EntitasPresetEnum.BASE); HexCellBehaviour home = grid.GetCell(basePos.Current); baseEntity.ReplaceLocation(home, home.GetComponent <EntitasLink>().id); baseEntity.ReplaceTeam(player.Color); baseEntity.ReplaceStartPosition(home.transform.position.x, home.transform.position.y, home.transform.position.z); } } else { Debug.Log("No player setup found; I'm assuming this scene was started in Unity Editor for debugging purposes"); GameEntity pEntity = game.CreateEntity(); pEntity.AddTeam(0); pEntity.isLocalPlayer = true; pEntity.isAIPlayer = false; } }
/// <summary> /// 复制(潜拷贝) /// </summary> protected override void toShadowCopy(BaseData data) { if (!(data is PlayerListData)) { return; } PlayerListData mData = (PlayerListData)data; this.system = mData.system; this.func = mData.func; this.activity = mData.activity; this.role = mData.role; this.scene = mData.scene; this.character = mData.character; this.social = mData.social; this.bag = mData.bag; this.mail = mData.mail; this.quest = mData.quest; this.guide = mData.guide; this.friend = mData.friend; this.equip = mData.equip; this.team = mData.team; this.union = mData.union; this.achievement = mData.achievement; this.pet = mData.pet; }
/** 保存一次 */ public void saveOnce() { if (!_playerLoaded) { return; } //初始化过的 if (GameC.player.system.inited()) { string path = _playerSavePath; PlayerListData data = GameC.player.createListData(); GameC.player.writeListData(data); BaseData exData = _offLineExData?.clone(); ThreadControl.addAssistFunc(() => { _stream.clear(); _stream.writeInt(BaseC.config.getDBDataVersion()); data.writeBytesFull(_stream); _offlineWorkListData.writeBytesFull(_stream); exData?.writeBytesFull(_stream); FileUtils.writeFileForBytesWriteStream(path, _stream); }); } }
void OnGotPlayerList(PlayerListData players) { PlayerListItem[] playerListItems = playerList.GetComponentsInChildren <PlayerListItem>(); if (playerListItems != null) { for (int i = 0; i < playerListItems.Length; i++) { bool remain = false; for (int j = 0; j < players.players.Length; j++) { if (playerListItems[i].player.playerID == players.players[j].playerID) { remain = true; break; } } if (!remain) { GameObject.Destroy(playerListItems[i].gameObject); } } } playerListItems = playerList.GetComponentsInChildren <PlayerListItem>(); for (int i = 0; i < players.players.Length; i++) { PlayerListItem playerListItem = null; if (playerListItems != null) { for (int j = 0; j < playerListItems.Length; j++) { if (playerListItems[j].player.playerID == players.players[i].playerID) { playerListItem = playerListItems[j]; break; } } } if (playerListItem == null) { playerListItem = Instantiate(playerListItemPrefab) as PlayerListItem; playerListItem.transform.SetParent(playerList, false); playerListItem.SetPlayer(players.players[i]); } else { if (players.players[i].playerID != SocketLobby.Instance.connectionID) { playerListItem.SetPlayer(players.players[i]); } } } }
/** 通过 listData 选择 */ protected virtual void showSinglePlayerLogin(PlayerListData listData) { if (listData == null) { listData = createSinglePlayer(createCreatePlayerData()); } singleLogin(listData); }
/** 单人模式登录 */ public void singleLogin(PlayerListData listData) { //初始化离线数据 initClient(listData, false); //先切换到预备游戏 _stepTool.doStepAbs(PreGameStart); //不考虑有场景的情况,目前直接进入空场景 GameC.scene.onEnterNoneScene(); }
private void initNewPlayer() { _listData = null; _offlineWorkListData = GameC.factory.createClientOfflineWorkListData(); _offlineWorkListData.initDefault(); _offLineExData = GameC.factory.createPlayerOfflineCacheExData(); _offLineExData.initDefault(); _currentIndex = _offlineWorkListData.index; }
/** 登录离线数据 */ public bool offlineLogin() { ClientLoginCacheData data = GameC.save.loadLoginCache(); if (data == null) { Ctrl.errorLog("不能找不到缓存数据"); return(false); } if (data.lastPlayerID <= 0) { Ctrl.errorLog("不该没有上次登录角色ID"); return(false); } GameC.offline.loadPlayer(data.lastPlayerID); PlayerListData listData = GameC.offline.getListData(); if (listData == null) { Ctrl.errorLog("找不到角色缓存数据,或角色数据失效"); return(false); } GameC.player.readListData(listData); if (GameC.player.hasEmptyData()) { Ctrl.errorLog("离线登录时,存在空数据"); return(false); } //初始化离线数据 initClient(listData, false); //先切换到预备游戏 _stepTool.doStepAbs(PreGameStart); //不考虑有场景的情况,目前直接进入空场景 GameC.scene.onEnterNoneScene(); beginLoginHttp(); return(true); }
public virtual void AddKill(string userId) { // You can override the SyncPlayer.cs file to include a function like "Dead" // public void Dead() //{ // if (lastDamageSender != null && lastDamageSender.GetComponent<PhotonView>()) // { // FindObjectOfType<ExamplePlayerList>().AddKill(lastDamageSender.GetComponent<PhotonView>().Owner.UserId); // FindObjectOfType<ExamplePlayerList>().AddDeath(PhotonNetwork.LocalPlayer.UserId); // } //} PlayerListData item = data.Find(x => x.userId == userId); if (item != null) { item.kills += 1; } }
/// <summary> /// 写列表数据(深拷) /// </summary> public override void writeListData(PlayerListData listData) { GPlayerListData mData = (GPlayerListData)listData; mData.system = (SystemPartData)this.system.makePartData(); mData.gfunc = (GFuncPartData)this.gfunc.makePartData(); mData.activity = (ActivityPartData)this.activity.makePartData(); mData.grole = (GRolePartData)this.grole.makePartData(); mData.gscene = (GScenePartData)this.gscene.makePartData(); mData.gcharacter = (GCharacterPartData)this.gcharacter.makePartData(); mData.social = (SocialPartData)this.social.makePartData(); mData.gbag = (GBagPartData)this.gbag.makePartData(); mData.mail = (MailPartData)this.mail.makePartData(); mData.quest = (QuestPartData)this.quest.makePartData(); mData.guide = (GuidePartData)this.guide.makePartData(); mData.gfriend = (GFriendPartData)this.gfriend.makePartData(); mData.gunion = (GUnionPartData)this.gunion.makePartData(); mData.gteam = (GTeamPartData)this.gteam.makePartData(); }
/// <summary> /// 从列表数据读取 /// </summary> public override void readListData(PlayerListData listData) { GPlayerListData mData = (GPlayerListData)listData; this.system.setData(mData.system); this.gfunc.setData(mData.gfunc); this.activity.setData(mData.activity); this.grole.setData(mData.grole); this.gscene.setData(mData.gscene); this.gcharacter.setData(mData.gcharacter); this.social.setData(mData.social); this.gbag.setData(mData.gbag); this.mail.setData(mData.mail); this.quest.setData(mData.quest); this.guide.setData(mData.guide); this.gfriend.setData(mData.gfriend); this.gunion.setData(mData.gunion); this.gteam.setData(mData.gteam); }
/// <summary> /// 写列表数据(深拷) /// </summary> public virtual void writeListData(PlayerListData listData) { listData.system = (SystemPartData)this.system.makePartData(); listData.func = (FuncPartData)this.func.makePartData(); listData.activity = (ActivityPartData)this.activity.makePartData(); listData.role = (RolePartData)this.role.makePartData(); listData.scene = (ScenePartData)this.scene.makePartData(); listData.character = (CharacterPartData)this.character.makePartData(); listData.social = (SocialPartData)this.social.makePartData(); listData.bag = (BagPartData)this.bag.makePartData(); listData.mail = (MailPartData)this.mail.makePartData(); listData.quest = (QuestPartData)this.quest.makePartData(); listData.guide = (GuidePartData)this.guide.makePartData(); listData.friend = (FriendPartData)this.friend.makePartData(); listData.equip = (EquipPartData)this.equip.makePartData(); listData.team = (TeamPartData)this.team.makePartData(); listData.union = (UnionPartData)this.union.makePartData(); listData.achievement = (AchievementPartData)this.achievement.makePartData(); listData.pet = (PetPartData)this.pet.makePartData(); }
public override PlayerListData createListData() { if (!_g1) { _m1 = instance.Type.GetMethod("createListData", 0); _g1 = true; } if (_m1 != null && !_b1) { _b1 = true; PlayerListData re = (PlayerListData)appdomain.Invoke(_m1, instance, null); _b1 = false; return(re); } else { return(base.createListData()); } }
/// <summary> /// 从列表数据读取 /// </summary> public virtual void readListData(PlayerListData listData) { this.system.setData(listData.system); this.func.setData(listData.func); this.activity.setData(listData.activity); this.role.setData(listData.role); this.scene.setData(listData.scene); this.character.setData(listData.character); this.social.setData(listData.social); this.bag.setData(listData.bag); this.mail.setData(listData.mail); this.quest.setData(listData.quest); this.guide.setData(listData.guide); this.friend.setData(listData.friend); this.equip.setData(listData.equip); this.team.setData(listData.team); this.union.setData(listData.union); this.achievement.setData(listData.achievement); this.pet.setData(listData.pet); }
public override void readListData(PlayerListData listData) { if (!_g2) { _m2 = instance.Type.GetMethod("readListData", 1); _g2 = true; } if (_m2 != null && !_b2) { _b2 = true; _p1[0] = listData; appdomain.Invoke(_m2, instance, _p1); _p1[0] = null; _b2 = false; } else { base.readListData(listData); } }
public override void writeListData(PlayerListData listData) { if (!_g3) { _m3 = instance.Type.GetMethod("writeListData", 1); _g3 = true; } if (_m3 != null && !_b3) { _b3 = true; _p1[0] = listData; appdomain.Invoke(_m3, instance, _p1); _p1[0] = null; _b3 = false; } else { base.writeListData(listData); } }
protected override void showSinglePlayerLogin(PlayerListData listData) { if (!_g21) { _m21 = instance.Type.GetMethod("showSinglePlayerLogin", 1); _g21 = true; } if (_m21 != null && !_b21) { _b21 = true; _p1[0] = listData; appdomain.Invoke(_m21, instance, _p1); _p1[0] = null; _b21 = false; } else { base.showSinglePlayerLogin(listData); } }
protected override PlayerListData createSinglePlayer(CreatePlayerData createData) { if (!_g23) { _m23 = instance.Type.GetMethod("createSinglePlayer", 1); _g23 = true; } if (_m23 != null && !_b23) { _b23 = true; _p1[0] = createData; PlayerListData re = (PlayerListData)appdomain.Invoke(_m23, instance, _p1); _p1[0] = null; _b23 = false; return(re); } else { return(base.createSinglePlayer(createData)); } }
/** 选择角色登录 */ protected virtual void stepPlayerLogin() { if (CommonSetting.isSingleGame) { GameC.offline.loadPlayer(1); PlayerListData listData = GameC.offline.getListData(); showSinglePlayerLogin(listData); } else { long playerID = _playerList[0].playerID; if (CommonSetting.useOfflineGame) { GameC.offline.loadPlayer(playerID); ClientOfflineWorkListData listData = GameC.offline.getOfflineWorkListData(); SList <ClientOfflineWorkData> list = new SList <ClientOfflineWorkData>(); if (listData != null) { list.addAll(listData.list); } Ctrl.log("发送离线登录"); PlayerLoginForOfflineRequest.create(playerID, list, listData != null ? listData.clientRandomSeedIndex : 0).send(); } else { //登录 PlayerLoginRequest.create(playerID).send(); } } }
/** 创建单人角色 */ protected virtual PlayerListData createSinglePlayer(CreatePlayerData createData) { Player player = GameC.player; player.newInitData(); RolePartData rolePartData = player.role.getPartData(); //设置基础键组 rolePartData.playerID = 1; rolePartData.name = createData.name; rolePartData.userID = 1; rolePartData.uid = getVisitorUID(); rolePartData.createAreaID = 1; rolePartData.platform = PlatformType.Visitor; rolePartData.isAdult = true; SystemPartData systemPartData = player.system.getPartData(); systemPartData.createDate = DateData.getNow(); //记录创建时间 //逻辑相关 player.role.doCreatePlayer(createData); //创建调用 player.onNewCreate(); //创建角色日志 GameC.log.createPlayer(player); PlayerListData listData = player.createListData(); player.writeListData(listData); return(listData); }
void PlaceExistingPlayersOnMap(PlayerListData playerListData, SpaceData spaceData) { playerManager.Init(playerListData); foreach (PlanetData planet in spaceData.planets) { if (planet.Owner != null) { PlayerData correctPlayerObject = playerListData.GetPlayerByName(planet.Owner.Name); planet.Owner = correctPlayerObject; planet.Owner.AddPlanetToOwnership(planet); } } }
/** 读取某角色(离线用) */ public void loadPlayer(long playerID) { int serverBornCode = GameC.save.getCacheServerBornCode(); if (_currentBornCode == serverBornCode && _currentPlayerID == playerID) { return; } _currentBornCode = serverBornCode; _currentPlayerID = playerID; //兼容旧版 if (_currentBornCode <= 0) { _playerSavePath = Application.persistentDataPath + "/player_" + playerID + "/offlinePlayer.bin"; } else { _playerSavePath = Application.persistentDataPath + "/player_" + serverBornCode + "_" + playerID + "/offlinePlayer.bin"; } _listData = null; if (FileUtils.fileExists(_playerSavePath)) { BytesReadStream stream = FileUtils.readFileForBytesReadStream(_playerSavePath); int version = stream.readInt(); //版本号不匹配 if (version != BaseC.config.getDBDataVersion()) { Ctrl.errorLog("本地存储结构版本不匹配,已清空persistant!,old:" + version + ",new:" + BaseC.config.getDBDataVersion()); //不是正式版 if (!ShineSetting.isOfficial) { if (ShineSetting.isRelease) { FileUtils.deleteFile(_playerSavePath); } else { FileUtils.clearDir(Application.persistentDataPath); } initNewPlayer(); return; } //跳过list stream.startReadObj(); stream.endReadObj(); _listData = null; } else { _listData = GameC.player.createListData(); _listData.readBytesFull(stream); } _offlineWorkListData = GameC.factory.createClientOfflineWorkListData(); _offlineWorkListData.readBytesFull(stream); _offLineExData = GameC.factory.createPlayerOfflineCacheExData(); _offLineExData.readBytesFull(stream); _currentIndex = _offlineWorkListData.index; } else { initNewPlayer(); } if (!_playerLoaded) { _playerLoaded = true; //需要离线部分 if (CommonSetting.useOfflineGame) { TimeDriver.instance.setInterval(onSave, CommonSetting.offlineSaveDelay); } } }
/** 初始化player数据(isOnline:是否在线登录,否则是离线登录) */ public void initClient(PlayerListData listData, bool isOnline) { bool lastOnline = CommonSetting.useOfflineGame && GameC.player.system.inited(); //此处不用 if (lastOnline) { reBuildPlayer(false); } //读数据 GameC.player.readListData(listData); if (CommonSetting.useOfflineGame) { //离线事务 GameC.offline.loadPlayer(GameC.player.role.playerID); // bool hasError=GameC.player.system.getPartData().clientOfflineWorkReceiveIndex!=GameC.player.system.getPartData().clientOfflineWorkIndex; GameC.offline.receiveIndex(GameC.player.system.getPartData().clientOfflineWorkReceiveIndex); // if(lastOnline && hasError) // { // GameC.info.showInfoCode(InfoCodeType.OfflineWorkFailed); // return; // } } //加载好本地缓存数据 GameC.playerSave.loadPlayer(GameC.player.role.playerID); GameC.player.system.setInited(true); GameC.player.system.setOnline(isOnline); if (CommonSetting.useOfflineGame && !isOnline) { //数据版本升级 GameC.playerVersion.checkVersion(GameC.player); } //读后 GameC.player.afterReadData(); if (CommonSetting.isSingleGame) { //检查一次功能开启 GameC.player.func.checkAllFunctions(); } GameC.player.beforeLogin(); //保存本次登录角色 GameC.save.cacheLoginPlayer(GameC.player.role.uid, GameC.player.role.playerID, GameC.player.system.getPartData().serverBornCode); //初始化红点 GameC.redPoint.initFirst(); if (CommonSetting.useOfflineGame) { GameC.offline.saveOnce(); } Ctrl.log("initClient后半段"); if (lastOnline) { //派发消息 GameC.player.dispatch(GameEventType.InitClient); } else { if (ShineSetting.openCheck) { if (_stepTool.isComplete(PreGameStart)) { Ctrl.errorLog("step不该已完成:PlayerLogin"); } } _stepTool.completeStep(PlayerLogin); } }
/// <summary> /// 复制(深拷贝) /// </summary> protected override void toCopy(BaseData data) { if (!(data is PlayerListData)) { return; } PlayerListData mData = (PlayerListData)data; if (mData.system != null) { this.system = (SystemPartData)mData.system.clone(); } else { this.system = null; nullObjError("system"); } if (mData.func != null) { this.func = (FuncPartData)mData.func.clone(); } else { this.func = null; nullObjError("func"); } if (mData.activity != null) { this.activity = (ActivityPartData)mData.activity.clone(); } else { this.activity = null; nullObjError("activity"); } if (mData.role != null) { this.role = (RolePartData)mData.role.clone(); } else { this.role = null; nullObjError("role"); } if (mData.scene != null) { this.scene = (ScenePartData)mData.scene.clone(); } else { this.scene = null; nullObjError("scene"); } if (mData.character != null) { this.character = (CharacterPartData)mData.character.clone(); } else { this.character = null; nullObjError("character"); } if (mData.social != null) { this.social = (SocialPartData)mData.social.clone(); } else { this.social = null; nullObjError("social"); } if (mData.bag != null) { this.bag = (BagPartData)mData.bag.clone(); } else { this.bag = null; nullObjError("bag"); } if (mData.mail != null) { this.mail = (MailPartData)mData.mail.clone(); } else { this.mail = null; nullObjError("mail"); } if (mData.quest != null) { this.quest = (QuestPartData)mData.quest.clone(); } else { this.quest = null; nullObjError("quest"); } if (mData.guide != null) { this.guide = (GuidePartData)mData.guide.clone(); } else { this.guide = null; nullObjError("guide"); } if (mData.friend != null) { this.friend = (FriendPartData)mData.friend.clone(); } else { this.friend = null; nullObjError("friend"); } if (mData.equip != null) { this.equip = (EquipPartData)mData.equip.clone(); } else { this.equip = null; nullObjError("equip"); } if (mData.team != null) { this.team = (TeamPartData)mData.team.clone(); } else { this.team = null; nullObjError("team"); } if (mData.union != null) { this.union = (UnionPartData)mData.union.clone(); } else { this.union = null; nullObjError("union"); } if (mData.achievement != null) { this.achievement = (AchievementPartData)mData.achievement.clone(); } else { this.achievement = null; nullObjError("achievement"); } if (mData.pet != null) { this.pet = (PetPartData)mData.pet.clone(); } else { this.pet = null; nullObjError("pet"); } }
/// <summary> /// 是否数据一致 /// </summary> protected override bool toDataEquals(BaseData data) { PlayerListData mData = (PlayerListData)data; if (mData.system != null) { if (this.system == null) { return(false); } if (!this.system.dataEquals(mData.system)) { return(false); } } else { if (this.system != null) { return(false); } } if (mData.func != null) { if (this.func == null) { return(false); } if (!this.func.dataEquals(mData.func)) { return(false); } } else { if (this.func != null) { return(false); } } if (mData.activity != null) { if (this.activity == null) { return(false); } if (!this.activity.dataEquals(mData.activity)) { return(false); } } else { if (this.activity != null) { return(false); } } if (mData.role != null) { if (this.role == null) { return(false); } if (!this.role.dataEquals(mData.role)) { return(false); } } else { if (this.role != null) { return(false); } } if (mData.scene != null) { if (this.scene == null) { return(false); } if (!this.scene.dataEquals(mData.scene)) { return(false); } } else { if (this.scene != null) { return(false); } } if (mData.character != null) { if (this.character == null) { return(false); } if (!this.character.dataEquals(mData.character)) { return(false); } } else { if (this.character != null) { return(false); } } if (mData.social != null) { if (this.social == null) { return(false); } if (!this.social.dataEquals(mData.social)) { return(false); } } else { if (this.social != null) { return(false); } } if (mData.bag != null) { if (this.bag == null) { return(false); } if (!this.bag.dataEquals(mData.bag)) { return(false); } } else { if (this.bag != null) { return(false); } } if (mData.mail != null) { if (this.mail == null) { return(false); } if (!this.mail.dataEquals(mData.mail)) { return(false); } } else { if (this.mail != null) { return(false); } } if (mData.quest != null) { if (this.quest == null) { return(false); } if (!this.quest.dataEquals(mData.quest)) { return(false); } } else { if (this.quest != null) { return(false); } } if (mData.guide != null) { if (this.guide == null) { return(false); } if (!this.guide.dataEquals(mData.guide)) { return(false); } } else { if (this.guide != null) { return(false); } } if (mData.friend != null) { if (this.friend == null) { return(false); } if (!this.friend.dataEquals(mData.friend)) { return(false); } } else { if (this.friend != null) { return(false); } } if (mData.equip != null) { if (this.equip == null) { return(false); } if (!this.equip.dataEquals(mData.equip)) { return(false); } } else { if (this.equip != null) { return(false); } } if (mData.team != null) { if (this.team == null) { return(false); } if (!this.team.dataEquals(mData.team)) { return(false); } } else { if (this.team != null) { return(false); } } if (mData.union != null) { if (this.union == null) { return(false); } if (!this.union.dataEquals(mData.union)) { return(false); } } else { if (this.union != null) { return(false); } } if (mData.achievement != null) { if (this.achievement == null) { return(false); } if (!this.achievement.dataEquals(mData.achievement)) { return(false); } } else { if (this.achievement != null) { return(false); } } if (mData.pet != null) { if (this.pet == null) { return(false); } if (!this.pet.dataEquals(mData.pet)) { return(false); } } else { if (this.pet != null) { return(false); } } return(true); }
public void Init(PlayerListData playerListData) { this.PlayerListData = playerListData; }
void PlaceNewPlayersOnMap(PlayerData humanPlayer, int aiCount) { Planet home = space.getRandomEmptyStartPlanet(); if (home == null) { Debug.LogError("Failed to set home planet for human player. There are no start planets on the map"); } home.planetData.SetOwner(humanPlayer); var aiPlayers = new List<AiPlayer>(); for (int i = 0; i < aiCount; ++i) { PlayerData aiData = new PlayerData(); AiPlayer player = new AiPlayer(aiData, space); home = space.getRandomEmptyStartPlanet(); if (home == null) { Debug.LogError("Failed to set home planet for ai. There are no start planets on the map"); break; } aiPlayers.Add(player); home.planetData.SetOwner(aiData); } PlayerListData playerListData = new PlayerListData(humanPlayer, aiPlayers); playerManager.Init(playerListData); }