//创建军队 public void CreateTroop(MainBaseVO start, MainBaseVO end, int amount) { if (start != null && start.soldierNum > 0 && end != null && amount > 0) { Troop troop = default; if (_WaitTroops.Count == 0) { troop = new Troop(); troop.soldiers = new List <GameObject>(); } else { troop = _WaitTroops[0]; _WaitTroops.RemoveAt(0); troop.soldiers.Clear(); } troop.start = start; troop.starter = start.ower; troop.end = end; troop.amount = amount; _Troops.Add(troop); } }
private void MoveCameraToMainBase(MainBaseVO mainBaseVO) { var positon = TwoMsgParamsPool <float, float> .Instance.Pop(); positon.InitParams(mainBaseVO.postion.x, mainBaseVO.postion.z); SendNotification(GlobalSetting.Msg_CameraFocusPoint, positon); }
public MainBaseVO CreateMainBase(PlayerVO owner) { MainBaseVO mainBaseVO = new MainBaseVO(owner); CreateBuilding(mainBaseVO, mainBaseVO, owner); return(mainBaseVO); }
private void OccupiedMainBase(MainBaseVO mainBaseVO, float time) { MainBaseState mainBaseState; mainBaseState = GetState(EMainBaseState.Occupied); mainBaseState.Init(mainBaseVO, mainBaseVO.ower); mainBaseState.Enter(time); _MainBaseStatesInUsed.Add(mainBaseVO, mainBaseState); }
public void ReceiveSoldier(MainBaseVO mainBaseVO, PlayerVO player, float time) { MainBaseState mainBaseState; if (_MainBaseStatesInUsed.TryGetValue(mainBaseVO, out mainBaseState)) { mainBaseState.ReceiveSoldier(player, time); } }
public void AddBuildingInfo(MainBaseVO vo) { _MapProxy.SetBuildingInfo(true, vo.tilePositon, vo.rect); if (vo.buildingType == E_Building.MainBase) { MainBaseVO mainBase = vo as MainBaseVO; _MapProxy.SetOccupiedInfo(true, mainBase.tilePositon, mainBase.radius); } }
public void UpgradeMainbase(MainBaseVO mainBaseVO) { if (mainBaseVO == null) { return; } if (buildingProxy.IsCanLevelUp(mainBaseVO)) { sender(GlobalSetting.Cmd_UpdateMainBase, mainBaseVO); } }
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 void MoveTroops(MainBaseVO from, MainBaseVO end) { if (from != null && end != null && !from.Equals(end)) { int soldierCount = from.soldierNum / 2; if (soldierCount <= 0) { return; } var msgParam = TreeMsgParamsPool <MainBaseVO, MainBaseVO, int> .Instance.Pop(); msgParam.InitParams(from, end, soldierCount); sender(GlobalSetting.Cmd_MoveTroops, msgParam); } }
public override void HandleNotification(INotification notification) { Debug.Log("进入Mediator,处理消息"); switch (notification.Name) { case GlobalSetting.Msg_InitMiniMapMediator: Awake(); _MiniMapUIForm = notification.Body as MiniMapUIForm; InitMiniMapMediator(); Debug.Log("进入Mediator,处理消息 Msg_InitMiniMapMediator"); break; case GlobalSetting.Msg_UpdateMainBase: Debug.Log("进入Mediator,处理消息 Msg_UpdateMainBase"); break; case GlobalSetting.Msg_MainbaseCreateComplete: Debug.Log("进入Mediator,处理消息 Msg_MainbaseCreateComplete"); _MainBaseVO = notification.Body as MainBaseVO; var _MainBaseGo = _MiniMapUIForm.CreateMainBase(); var _TilePositon = Position(_MainBaseVO.tilePositon); _MainBaseGo.GetComponent <RectTransform>().anchoredPosition = new Vector2(_TilePositon.x, _TilePositon.y); var sc = _MainBaseGo.GetComponent <MainBaseDrawEvent>(); sc.mainBaseVO = _MainBaseVO; _Dic_MainBaseVO.Add(_MainBaseGo, _MainBaseVO); break; case GlobalSetting.Msg_MapCreateComplete: Debug.Log("进入Mediator,处理消息 Msg_MapCreateComplete"); _MapData = notification.Body as float[, ]; _MapWidth = _MapData.GetLength(0) * _Scale; _MapHeight = _MapData.GetLength(1) * _Scale; break; case GlobalSetting.Msg_MapUpdateSoldiersPositon: Debug.Log("进入Mediator,处理消息 Msg_MapUpdateSoldiersPositon"); _MapSoldierInfo = notification.Body as MapSoldierInfo; FillTroopsData(); 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; } }
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 bool IsCanLevelUp(MainBaseVO vO) { bool isCan = false; if (vO.isMain) { isCan = vO.level < StaticDataHelper.MainBaseMaxLevel; } else { isCan = vO.level < StaticDataHelper.SubBaseMaxLevel; } isCan = isCan && vO.data.UpLevelGoldRequire <= vO.ower.gold; isCan = isCan && vO.data.UpLevelGrainRequire <= vO.ower.grain; return(isCan); }
public void UpdateLevelMainBase(MainBaseVO mainBaseVO) { var currentData = mainBaseVO.data; var data = GetNextLevelDate(mainBaseVO); mainBaseVO.level++; mainBaseVO.data = data; mainBaseVO.radius = data.Radius; mainBaseVO.grainLimit += data.GrainLimit - currentData.GrainLimit; mainBaseVO.goldLimit += data.GoldLimit - currentData.GrainLimit; mainBaseVO.soldierNumLimit += data.SoldierLimit - currentData.SoldierLimit; mainBaseVO.ower.grainLimit += data.GrainLimit - currentData.GrainLimit; mainBaseVO.ower.goldLimit += data.GoldLimit - currentData.GrainLimit; mainBaseVO.ower.soldierAmountLimit += data.SoldierLimit - currentData.SoldierLimit; SendNotification(GlobalSetting.Msg_UpdateMainBase, mainBaseVO); SendNotification(GlobalSetting.Msg_SetUsersPlayerBattleInfoDirty); }
private MainBaseLevelData GetNextLevelDate(MainBaseVO vO) { MainBaseLevelData data = vO.data; if (vO.isMain) { if (vO.level < StaticDataHelper.MainBaseMaxLevel) { data = StaticDataHelper.LevelToMainBaseLevelData[vO.level + 1]; } } else { if (vO.level < StaticDataHelper.SubBaseMaxLevel) { data = StaticDataHelper.LevelToSubBaseLevelData[vO.level + 1]; } } return(data); }
public int GetMainbaseNextLevelRadius(MainBaseVO vO) { int radius = vO.radius; if (vO.isMain) { if (vO.level < StaticDataHelper.MainBaseMaxLevel) { radius = StaticDataHelper.LevelToMainBaseLevelData[vO.level + 1].Radius; } } else { if (vO.level < StaticDataHelper.SubBaseMaxLevel) { radius = StaticDataHelper.LevelToSubBaseLevelData[vO.level + 1].Radius; } } return(radius); }
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 override void Execute(INotification notification) { MainBaseVO mainBaseVO = notification.Body as MainBaseVO; if (mainBaseVO != null) { var buildingProxy = Facade.RetrieveProxy(BuildingVOProxy.NAME) as BuildingVOProxy; var mapProxy = Facade.RetrieveProxy(MapVOProxy.NAME) as MapVOProxy; bool isCanLevelUp = buildingProxy.IsCanLevelUp(mainBaseVO); int nextLevelRadius = buildingProxy.GetMainbaseNextLevelRadius(mainBaseVO); isCanLevelUp = isCanLevelUp && mapProxy.IsCanOccupedRingArea(mainBaseVO.tilePositon, mainBaseVO.radius, nextLevelRadius); if (isCanLevelUp) { //扣除消耗 mainBaseVO.ower.gold -= mainBaseVO.data.UpLevelGoldRequire; mainBaseVO.ower.grain -= mainBaseVO.data.UpLevelGrainRequire; //占用地图 mapProxy.SetOccupiedInfo(true, mainBaseVO.tilePositon, nextLevelRadius); //扩大范围 buildingProxy.UpdateLevelMainBase(mainBaseVO); } } }
private void SetMainBaseOriginData(MainBaseVO mainBaseVO) { if (mainBaseVO.isMain) { mainBaseVO.goldOutputNum = GlobalSetting.BUILDING_MAINBASE_GOLD_OUTPUT; mainBaseVO.grainOutputNum = GlobalSetting.BUILDING_MAINBASE_GRAIN_OUTPUT; mainBaseVO.trainNum = GlobalSetting.BUILDING_MAINBASE_SOLDIER_OUTPUT; mainBaseVO.data = StaticDataHelper.LevelToMainBaseLevelData[1]; mainBaseVO.soldierNum = GlobalSetting.PLAYER_ORIGINAL_SOLDIER; } else { mainBaseVO.goldOutputNum = GlobalSetting.BUILDING_SUBBASE_GOLD_OUTPUT; mainBaseVO.grainOutputNum = GlobalSetting.BUILDING_SUBBASE_GRAIN_OUTPUT; mainBaseVO.trainNum = GlobalSetting.BUILDING_SUBBASE_SOLDIER_OUTPUT; mainBaseVO.data = StaticDataHelper.LevelToSubBaseLevelData[1]; mainBaseVO.soldierNum = 0; } mainBaseVO.radius = mainBaseVO.data.Radius; mainBaseVO.grainLimit = mainBaseVO.data.GrainLimit; mainBaseVO.goldLimit = mainBaseVO.data.GoldLimit; mainBaseVO.soldierNumLimit = mainBaseVO.data.SoldierLimit; }
public MainBaseVO CreateMainBase(PlayerVO owner) { MainBaseVO mainBaseVO = new MainBaseVO(owner); return(mainBaseVO); }
private void OnClick_MainBaseMoveTroops(GameObject go) { MainBaseVO _MainBase = null; _Dic_MainBaseVO.TryGetValue(go, out _MainBase); }
public int GetNextLevelRadius(MainBaseVO vO) { return(_BuildingVOProxy.GetMainbaseNextLevelRadius(vO)); }
public bool IsMainBaseCanLevelUp(MainBaseVO vo) { return(_BuildingVOProxy.IsCanLevelUp(vo)); }
public void CreateMainBase(MainBaseVO vo) { _BuildingVOProxy.CreateBuilding(vo, vo, vo.ower); }
public override void HandleNotification(INotification notification) { switch (notification.Name) { case GlobalSetting.Msg_InitMobilizeTroopsMediator: MobilizeTroopsInfoUIForm uiform = notification.Body as MobilizeTroopsInfoUIForm; if (uiform) { InitMobilizeTroopsMediator(uiform); } break; case GlobalSetting.Msg_PickMainBase: MainBaseVO vO = notification.Body as MainBaseVO; if (vO != null) { if (_OriginMainBaseVO == null && _TargetMainBaseVO == null) { _UIForm.OpenUIForm(GlobalSetting.UI_MobilizeTroopsInfoUIForm); } if (vO.ower.IsUser && _OriginMainBaseVO == null) { _OriginMainBaseVO = vO; _TroopSoldiers = vO.soldierNum / 2; _UIForm.SetOriginInfo(vO.tilePositon, _TroopSoldiers); } else if (_OriginMainBaseVO != null && vO.Equals(_OriginMainBaseVO)) { _TroopSoldiers = vO.soldierNum / 2; _UIForm.SetOriginInfo(vO.tilePositon, _TroopSoldiers); } else { _TargetMainBaseVO = vO; _UIForm.SetTargetInfo(vO.tilePositon); } if (_OriginMainBaseVO != null && _TargetMainBaseVO != null) { var threeCmdParams = TreeMsgParamsPool <MainBaseVO, MainBaseVO, int> .Instance.Pop(); threeCmdParams.InitParams(_OriginMainBaseVO, _TargetMainBaseVO, _TroopSoldiers); SendNotification(GlobalSetting.Cmd_MoveTroops, threeCmdParams); _OriginMainBaseVO = null; _TargetMainBaseVO = null; _UIForm.DelayClose(1); } } break; case GlobalSetting.Msg_EndBattle: _OriginMainBaseVO = null; _TargetMainBaseVO = null; _UIForm.CloseUIForm(); break; default: break; } }
private void MoveTroopsCancel() { _OriginMainBaseVO = null; _TargetMainBaseVO = null; _UIForm.CloseUIForm(); }
public override void Execute(INotification notification) { var msgParam = notification.Body as TwoMsgParams <PlayerVO, IBuildingVO>; if (msgParam != null && msgParam.first != null && msgParam.second != null) { PlayerVO playerVo = msgParam.first; IBuildingVO building = msgParam.second; PlayerVOProxy playerVOProxy = Facade.RetrieveProxy(PlayerVOProxy.NAME) as PlayerVOProxy; MapVOProxy mapVOProxy = Facade.RetrieveProxy(MapVOProxy.NAME) as MapVOProxy; BuildingVOProxy buildingProxy = Facade.RetrieveProxy(BuildingVOProxy.NAME) as BuildingVOProxy; //判断资源是否满足创建需求 if (playerVo.gold < building.createCostGold || playerVo.grain < building.createCostGrain) { return; } playerVo.gold -= building.createCostGold; playerVo.grain -= building.createCostGrain; switch (building.buildingType) { case E_Building.None: break; case E_Building.MainBase: //判断是否可以被添加.... MainBaseVO mainBaseVO = building as MainBaseVO; if (mainBaseVO != null) { if (mapVOProxy.IsCanOccupedArea(mainBaseVO.tilePositon, mainBaseVO.radius)) { mainBaseVO.SetOwer(playerVo); buildingProxy.CreateBuilding(mainBaseVO, mainBaseVO, playerVo); //更新地图建筑信息 mapVOProxy.SetBuildingInfo(true, building.tilePositon, building.rect); //更新占领信息 mapVOProxy.SetOccupiedInfo(true, building.tilePositon, mainBaseVO.radius); } } break; case E_Building.FarmLand: case E_Building.GoldMine: case E_Building.MilitaryCamp: MainBaseVO mainBase = playerVOProxy.GetMainBasePlayerBuildingBelongTo(building, playerVo); if (mainBase != null) { //添加建筑 mainBase.AddBuilding(building); //更新地图建筑信息 mapVOProxy.SetBuildingInfo(true, building.tilePositon, building.rect); buildingProxy.CreateBuilding(building, mainBase, playerVo); } break; default: break; } TwoMsgParamsPool <PlayerVO, IBuildingVO> .Instance.Push(msgParam); } BattleManager.Instance.CancelConstraction(); }
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 InitMainBase(MainBaseVO vO) { this.m_Data = vO; m_CurrentRadius = vO.radius; }