public void JoinRoom(string roomID, PlayerVO playerVO) { //mock data /*string playersRawData = Resources.Load<TextAsset>("players").text; * Messenger<PlayerVO[]>.Broadcast(ServerCommand.ADD_PLAYERS, dataParser.GetPlayersData(playersRawData)); * * string initialGameData = getRoundDataFromJson(_currentRoundNumber); * Messenger<RoundResultVO[]>.Broadcast(ServerCommand.START_GAME, dataParser.GetRoundResultsData(initialGameData)); * _currentRoundNumber++; */ //TODO: implement functionality: //send user's data to server //wait for commands from server: //ServerCommand.ADD_PLAYERS //ServerCommand.REMOVE_PLAYERS //ServerCommand.START_GAME //Dictionary<string, string> data = new Dictionary<string, string>(); //data["message"] = "hello server!"; //socket.Connect(); JoinRoomCommandVO commandVO = new JoinRoomCommandVO { roomID = name, playerVO = playerVO }; socket.Emit(ServerCommands.JOIN_ROOM, new JSONObject(JsonUtility.ToJson(commandVO))); }
private void EndBattleSetting() { _UsersPlayerVODirty = false; _UsersPlayerVO = null; _UIForm.SetDefaultInfo(); _UIForm.CloseUIForm(); }
// TODO: rewrite in future, add player selector void initPlayers() { PlayerVO playerD = new PlayerVO(Config.PLAYER_ME, "", "1", "PlayerMe"); GameModel.inst.Players[Config.PLAYER_ME] = playerD; if (SelectPlayerContext.Count < 4) { PlayerVO playerA = new PlayerVO(Config.PLAYER_A, "", "101", "PlayerA"); PlayerVO playerB = new PlayerVO(Config.PLAYER_B, "", "102", "PlayerB"); PlayerVO playerC = new PlayerVO(Config.PLAYER_C, "", "103", "PlayerC"); GameModel.inst.Players[Config.PLAYER_A] = playerA; GameModel.inst.Players[Config.PLAYER_B] = playerB; GameModel.inst.Players[Config.PLAYER_C] = playerC; } for (int i = 0; i < GameModel.inst.Players.Length; i++) { if (i != Config.PLAYER_ME) { GameObject container = GameObject.Find(GameModel.inst.Players[i].Container); GameObject avatar = container.transform.Find("Avatar").gameObject; SpriteRenderer renderer = avatar.GetComponent <SpriteRenderer>(); renderer.sprite = Resources.Load <Sprite>("PLayers/" + GameModel.inst.Players[i].ImageName); GameObject scoreContainer = GameObject.Find("EndLevelScore"); GameObject avatarScore = scoreContainer.transform.Find("Score" + GameModel.inst.Players[i].Container).gameObject; SpriteRenderer rendererScore = avatarScore.GetComponent <SpriteRenderer>(); rendererScore.sprite = Resources.Load <Sprite>("PLayers/" + GameModel.inst.Players[i].ImageName); } } Debug.Log("players init!"); }
public void MoveTroops() { PlayerVO from = (GameFacade.Instance.RetrieveProxy(PlayerVOProxy.NAME) as PlayerVOProxy).GetPlayer(userID); PlayerVO end = (GameFacade.Instance.RetrieveProxy(PlayerVOProxy.NAME) as PlayerVOProxy).GetPlayer(targetPlyerID); BattleManager.Instance.aiSystem._AICommander.MoveTroops(from.mainBases[mainbaseIndex], end.mainBases[targetMainbaseIndex]); }
public void JoinRoom(string roomID, PlayerVO playerVO) { //TODO: implement functionality: //send user's data to server //wait for commands from server: //ServerCommand.ADD_PLAYERS //ServerCommand.REMOVE_PLAYERS //ServerCommand.START_GAME //Dictionary<string, string> data = new Dictionary<string, string>(); //data["message"] = "hello server!"; //socket.Connect(); JoinRoomCommandVO commandVO = new JoinRoomCommandVO { roomID = roomID, playerVO = playerVO }; socket.On(ServerCommand.ADD_PLAYERS, OnAddPlayers); socket.On(ServerCommand.START_MATCH, OnStartGame); socket.On(ServerCommand.ROUND_RESULTS, OnRoundResults); string json = JsonUtility.ToJson(commandVO); socket.Emit(ServerCommands.JOIN_ROOM, new JSONObject(json)); }
private void AddPlayerItem(PlayerVO player) { var grid = FindEmptyGrid(PL_PlayerList1); if (grid == null) { grid = FindEmptyGrid(PL_PlayerList2); } if (grid == null) { throw new Exception("no empty grid"); } GameObject item = Instantiate(_playerItemPrefab, grid) as GameObject; //TODO: 改成隐藏/显示的方案 不需要频繁创建/销毁 var playerItem = item.GetComponent <PlayerItem>(); (playerItem.UserId, playerItem.UserName, playerItem.Level, playerItem.PrepareState, playerItem.VehicleName, playerItem.Attack, playerItem.Motility, playerItem.Defend, playerItem.MaxHealth) = (player.UserID, player.UserName, player.Level.ToString(), player.PrepareState, player.CurVehicle.VehicleName, player.CurVehicle.Attack, player.CurVehicle.Motility, player.CurVehicle.Defend, player.CurVehicle.MaxHealth); var kickBtn = item.GetComponentInChildren <Button>(true); kickBtn.onClick.AddListener(() => OnKick?.Invoke(player.UserID)); //显示踢除按钮 if (_playerManagerInstance.RoomOwner.UserID == _playerManagerInstance.LocalPlayer.UserID && playerItem.UserId != _playerManagerInstance.LocalPlayer.UserID) { kickBtn.gameObject.SetActive(true); } //显示房主标签 if (_playerManagerInstance.RoomOwner.UserID == player.UserID) { item.transform.Find("RoomOwnerText").GetComponent <Text>().gameObject.SetActive(true); item.transform.parent.GetComponent <Toggle>().isOn = true; } }
/// <summary> /// 获取建筑属于玩家的哪个基地,不属于,返回NULL /// </summary> /// <param name="building"></param> /// <returns></returns> public MainBaseVO GetMainBasePlayerBuildingBelongTo(IBuildingVO building, PlayerVO playerVO) { if (building.buildingType == E_Building.MainBase) { return(building as MainBaseVO); } PlayerVO player = playerVO; IList <MainBaseVO> mainbases = player.mainBases; List <IBuildingVO> buildings = null; Vector3Int downLeft; Vector3Int upRight; Vector3Int downLeftb; Vector3Int upRightb; if (mainbases.Count == 0) { return(null); } for (int i = 0; i < mainbases.Count; i++) { downLeft = building.tilePositon - new Vector3Int(building.rect.position.x, 0, building.rect.position.y); if (!mainbases[i].IsIn(downLeft)) { continue; } downLeft.x += building.rect.size.x - 1; if (!mainbases[i].IsIn(downLeft)) { continue; } downLeft.z += building.rect.size.y - 1; upRight = downLeft; if (!mainbases[i].IsIn(downLeft)) { continue; } downLeft.x -= building.rect.size.x - 1; if (!mainbases[i].IsIn(downLeft)) { continue; } buildings = mainbases[i].ownBuildings; for (int j = 0; j < buildings.Count; j++) { downLeftb = buildings[j].tilePositon - new Vector3Int(building.rect.position.x, 0, building.rect.position.y); upRightb = downLeftb + new Vector3Int(buildings[j].rect.width - 1, 0, buildings[j].rect.height - 1); if (downLeft.x <= upRightb.x && upRight.x >= downLeftb.x && downLeft.z <= upRightb.z && upRight.z >= downLeftb.z) { return(null); } } return(mainbases[i]); } return(null); }
public Character GetCharacter(PlayerVO data) { GameObject characterGO = Instantiate(characterPrefabs[data.characterData.characterId], Vector3.zero, Quaternion.identity) as GameObject; Character character = characterGO.GetComponent <Character>(); character.SetData(data); return(character); }
public MainBaseVO CreateMainBase(PlayerVO owner) { MainBaseVO mainBaseVO = new MainBaseVO(owner); CreateBuilding(mainBaseVO, mainBaseVO, owner); return(mainBaseVO); }
public void ReceiveSoldier(MainBaseVO mainBaseVO, PlayerVO player, float time) { MainBaseState mainBaseState; if (_MainBaseStatesInUsed.TryGetValue(mainBaseVO, out mainBaseState)) { mainBaseState.ReceiveSoldier(player, time); } }
/// <summary> /// 判断建筑是否能够建造 /// </summary> /// <param name="playerID"></param> /// <param name="building"></param> /// <returns></returns> public bool IsCanConstructionUserBuilding(int playerID, IBuildingVO building) { PlayerVO player = _Players[playerID]; IList <MainBaseVO> mainbases = player.mainBases; List <IBuildingVO> buildings = null; Vector3Int downLeft; Vector3Int middle; Vector3Int upRight; Vector3Int downLeftb; Vector3Int upRightb; if (mainbases.Count == 0) { return(false); } for (int i = 0; i < mainbases.Count; i++) { downLeft = building.tilePositon - new Vector3Int(building.rect.position.x, 0, building.rect.position.y); middle = downLeft; if (!mainbases[i].IsIn(middle)) { continue; } middle.x += building.rect.size.x - 1; if (!mainbases[i].IsIn(middle)) { continue; } middle.z += building.rect.size.y - 1; upRight = middle; if (!mainbases[i].IsIn(middle)) { continue; } middle.x -= building.rect.size.x - 1; if (!mainbases[i].IsIn(middle)) { continue; } buildings = mainbases[i].ownBuildings; for (int j = 0; j < buildings.Count; j++) { downLeftb = buildings[j].tilePositon - new Vector3Int(building.rect.position.x, 0, building.rect.position.y); upRightb = downLeftb + new Vector3Int(buildings[j].rect.width - 1, 0, buildings[j].rect.height - 1); if (downLeft.x <= upRightb.x && upRight.x >= downLeftb.x && downLeft.z <= upRightb.z && upRight.z >= downLeftb.z) { return(false); } } return(true); } return(false); }
public void VisitAllPlayerMainBase(PlayerVO vo, Action <MainBaseVO> visitor) { if (vo != null && visitor != null) { var enumerator = vo.mainBases.GetEnumerator(); while (enumerator.MoveNext()) { visitor(enumerator.Current); } } }
public MainBaseVO(PlayerVO ower) : this() { if (ower != null) { this._Ower = ower; _IsMain = ower.AddMainBases(this); if (!_IsMain) { prefabName = SubPrefabName; } } }
public override void ReceiveSoldier(PlayerVO player, float time) { base.ReceiveSoldier(player, time); if (!player.Equals(_OccuptedPlayer)) { _OccupiedTime = time + GlobalSetting.BULDING_MAINBASE_OCCUPIED_TIME; _Player = player; } ChangePlayer(player); }
public void Build(PlayerVO ower, E_Building buildingType, MainBaseVO mainBaseVO) { IBuildingVO buildingVO = null; Vector3Int center = default; int radius = 0; int count = 0; if (mainBaseVO != null) { center = mainBaseVO.tilePositon; radius = mainBaseVO.radius; } switch (buildingType) { case E_Building.None: break; case E_Building.MainBase: buildingVO = new MainBaseVO(); count = GetBuildMainbasePositionClose(_ConstructionInfos, ower); break; case E_Building.FarmLand: buildingVO = new FarmLandVO(); count = GetBuildPosition(_ConstructionInfos, center, radius, buildingVO.rect); break; case E_Building.GoldMine: buildingVO = new GoldMineVO(); count = GetBuildPosition(_ConstructionInfos, center, radius, buildingVO.rect); break; case E_Building.MilitaryCamp: buildingVO = new MilitaryCampVO(); count = GetBuildPosition(_ConstructionInfos, center, radius, buildingVO.rect); break; default: break; } ConstructionInfo constructionInfo = _SelectConstructionHandler(_ConstructionInfos, count, 0); if (constructionInfo.isRotation) { buildingVO.Rotate(); } buildingVO.tilePositon = constructionInfo.position; var msgParam = TwoMsgParamsPool <PlayerVO, IBuildingVO> .Instance.Pop(); msgParam.InitParams(ower, buildingVO); sender.Invoke(GlobalSetting.Cmd_ConfirmConstruction, msgParam); }
public static void grabCards(PlayerVO grabber) { string namePositionPoint = grabber.Container; Vector3 position = GameObject.Find(namePositionPoint).transform.position; AudioManager.inst.playGrab(); for (int i = 0; i < GameModel.inst.cardsOnDeck.Count; i++) { CardVO card = GameModel.inst.cardsOnDeck[i] as CardVO; iTween.MoveTo(card.gameObject, iTween.Hash("x", position.x, "y", position.y, "time", 0.7, "oncomplete", "endGrab")); // callback is in CardMediator Debug.Log("grab card # " + card.Id); } }
public void Login(SessionDataVO sessionData) { //socket.Connect(); //TODO: change to real data from server //if login successful - we get player's raw data //otherwise we get null data (error object) PlayerVO playerVO = new PlayerVO(); playerVO.id = sessionData.Login; playerVO.name = sessionData.Login; Messenger <PlayerVO> .Broadcast(ServerCommand.LOGIN, playerVO); }
/// <summary> /// 创建一个玩家 /// </summary> /// <param name="name">玩家名称</param> /// <param name="group">玩家属于的阵营</param> /// <returns></returns> public PlayerVO CreatePlayer(string name, byte group) { PlayerVO player = new PlayerVO(name, group); _Players.Add(player); player.gold = GlobalSetting.PLAYER_ORIGINAL_GOLD; player.grain = GlobalSetting.PLAYER_ORIGINAL_GRAIN; if (player.IsUser) { SendNotification(GlobalSetting.Msg_UsersPlayerCreated, player); } return(player); }
private void SetOriginData(IBuildingVO buildingVO, MainBaseVO mainBaseVO, PlayerVO player) { switch (buildingVO.buildingType) { case E_Building.MainBase: var tempMainBaseVO = buildingVO as MainBaseVO; SetMainBaseOriginData(tempMainBaseVO); player.goldLimit += tempMainBaseVO.goldLimit; player.grainLimit += tempMainBaseVO.grainLimit; player.soldierAmount += tempMainBaseVO.soldierNum; player.soldierAmountLimit += tempMainBaseVO.soldierNumLimit; _AllMainBases.Add(tempMainBaseVO); OccupiedMainBase(tempMainBaseVO, Time.time); SendNotification(GlobalSetting.Msg_MainbaseCreateComplete, tempMainBaseVO); break; case E_Building.FarmLand: var tempFarmLandVO = buildingVO as FarmLandVO; //SetFarmLandOriginData(tempFarmLandVO); mainBaseVO.grainLimit += tempFarmLandVO.grainLimit; player.grainLimit += tempFarmLandVO.grainLimit; mainBaseVO.grainOutputNum += tempFarmLandVO.grainOutputNum; break; case E_Building.GoldMine: var tempGoldMineVO = buildingVO as GoldMineVO; //SetGoldMineOriginData(tempGoldMineVO); mainBaseVO.goldLimit += tempGoldMineVO.goldLimit; player.goldLimit += tempGoldMineVO.goldLimit; mainBaseVO.goldOutputNum += tempGoldMineVO.goldOutputNum; break; case E_Building.MilitaryCamp: var tempMilitaryCampVO = buildingVO as MilitaryCampVO; //SetMilitaryCampOriginData(tempMilitaryCampVO); mainBaseVO.soldierNumLimit += tempMilitaryCampVO.soldierNumLimit; player.soldierAmountLimit += tempMilitaryCampVO.soldierNumLimit; mainBaseVO.trainNum += tempMilitaryCampVO.trainNum; break; default: break; } }
public override void Execute(INotification notification) { var parameter = notification.Body as TwoMsgParams <PlayerVO, MainBaseVO>; if (parameter != null) { PlayerVO playerVO = parameter.first; MainBaseVO mainBaseVO = parameter.second; if (parameter.first != null && parameter.second != null) { PlayerVOProxy playerProxy = Facade.RetrieveProxy(PlayerVOProxy.NAME) as PlayerVOProxy; BuildingVOProxy buildingProxy = Facade.RetrieveProxy(BuildingVOProxy.NAME) as BuildingVOProxy; if (mainBaseVO.ower != playerVO) {//占领 if (mainBaseVO.ower.IsUser) { bool isWin = mainBaseVO.ower.mainBases.Count == buildingProxy.mainBaseTotalCount; playerProxy.VisitAllPlayers((p) => { if (!p.Equals(mainBaseVO.ower)) { _OthersDonotHaveSoldier = _OthersDonotHaveSoldier && p.soldierAmount <= 0; } }); isWin = isWin && _OthersDonotHaveSoldier; if (isWin) { BattleManager.Instance.SetBattleResult(true); } } else { } } else {//收复 } } TwoMsgParamsPool <PlayerVO, MainBaseVO> .Instance.Push(parameter); parameter = null; } }
public void CreateBuilding(IBuildingVO buildingVO, MainBaseVO mainBaseVO, PlayerVO player) { if (!_PlayerToMainBase.ContainsKey(player.Id)) { _PlayerToMainBase.Add(player.Id, new List <MainBaseVO>()); } if (buildingVO.buildingType == E_Building.MainBase) { _PlayerToMainBase[player.Id].Add(mainBaseVO); } SetOriginData(buildingVO, mainBaseVO, player); _BuildingToMainBase.Add(buildingVO, mainBaseVO); SendNotification(GlobalSetting.Msg_BuildBuilding, buildingVO); if (player.IsUser) { SendNotification(GlobalSetting.Msg_SetUsersPlayerBattleInfoDirty); } }
public void SetData(PlayerVO data) { PlayerData = data; _tfNickname.text = data.name; }
public MainBaseVO CreateMainBase(PlayerVO owner) { MainBaseVO mainBaseVO = new MainBaseVO(owner); return(mainBaseVO); }
private int GetBuildMainbasePositionClose(ConstructionInfo[] outPositionList, PlayerVO ower) { if (outPositionList == null && outPositionList.Length == 0) { return(0); } int count = 0; MainBaseVO closeMainbase = null; MainBaseVO testMainBase = null; int radius = 0; int testRadius = 0; int absY = 0; int length = 0; for (int i = 0; i < ower.mainBases.Count; i++) { closeMainbase = ower.mainBases[i]; radius = closeMainbase.isMain ? _MainbaseMaxRadius : _SubbaseMaxRadius; radius += _SubbaseMaxRadius; bool isNeedAdd = true; for (int x = 1 - radius; x < radius; x++) { absY = (radius - 1) - Math.Abs(x); Vector3Int temp = testMainBase.tilePositon + new Vector3Int(x, 0, absY); for (int j = 0; j < ower.mainBases.Count; j++) { if (i == j) { continue; } testMainBase = ower.mainBases[j]; isNeedAdd = true; length = Math.Abs(temp.x - testMainBase.tilePositon.x) + Math.Abs(temp.z - testMainBase.tilePositon.z) + 1; if (length >= radius) { isNeedAdd = false; break; } } if (mapProxy.IsCanOccupedArea(temp, _SubbaseMaxRadius)) { isNeedAdd = true; for (int k = 0; k < count; k++) { if (temp == outPositionList[k].position) { isNeedAdd = false; break; } } if (isNeedAdd) { outPositionList[count].position = temp; outPositionList[count].isRotation = false; //TODO 获取城堡坐在的位置的资源加成数据 count++; if (count >= outPositionList.Length) { return(count); } } } temp = testMainBase.tilePositon + new Vector3Int(x, 0, -absY); if (mapProxy.IsCanOccupedArea(temp, _SubbaseMaxRadius)) { isNeedAdd = true; for (int k = 0; k < count; k++) { if (temp == outPositionList[k].position) { isNeedAdd = false; break; } } if (isNeedAdd) { outPositionList[count].position = temp; outPositionList[count].isRotation = false; //TODO 获取城堡坐在的位置的资源加成数据 count++; if (count >= outPositionList.Length) { return(count); } } } } } return(count); }
public void SetPlayerVo(LevelStartPlayerDataHolderParams playerData) { Vo = playerData.PlayerData; }
public void SaveUserData(PlayerVO playerVO) { mainModel.User = playerVO; }
private void InitUsersPlayerInfo(PlayerVO vo) { _UsersPlayerVO = vo; _UIForm.SetPlayerFlag(vo.colorIndex); }
public override void ReceiveSoldier(PlayerVO player, float time) { base.ReceiveSoldier(player, time); ChangePlayer(player); }
// Start is called before the first frame update public void CreateBuilding() { PlayerVO playerVO = (GameFacade.Instance.RetrieveProxy(PlayerVOProxy.NAME) as PlayerVOProxy).GetPlayer(userID); BattleManager.Instance.aiSystem._AIBuilder.Build(playerVO, buildingType, playerVO.mainBases[0]); }
public static void Init() { player = new PlayerVO(); }
public void UpgradeMainbase() { PlayerVO playerVO = (GameFacade.Instance.RetrieveProxy(PlayerVOProxy.NAME) as PlayerVOProxy).GetPlayer(userID); BattleManager.Instance.aiSystem._AIBuilder.UpgradeMainbase(playerVO.mainBases[mainbaseIndex]); }