public void BuyWall() { BuildingIdentity buildingIdentity = LogicController.Instance.BuyWall(this.BuildingBehavior.FirstZoneIndex); this.BuildingLogicData = LogicController.Instance.GetBuildingObject(buildingIdentity); SceneManager.Instance.EnableCreateWallContinuation = true; this.ConstructBuilding(); SceneManager.Instance.LastWallTilePosition = this.BuildingBehavior.FirstZoneIndex; //if (this.BuildingLogicData.BuildingType == BuildingType.Wall) // { int upperLimitCount = ConfigInterface.Instance.BuildingNumberRestrictionsConfigHelper.GetBuildingNumberRestrictions(LogicController.Instance.CurrentCityHallLevel).RestrictionDict[this.BuildingLogicData.BuildingType]; int hasCount = LogicController.Instance.GetBuildingCount(this.BuildingLogicData.BuildingType); if (hasCount < upperLimitCount) { int initialLevel = ConfigInterface.Instance.BuildingConfigHelper.GetInitialLevel(this.BuildingLogicData.BuildingType); BuildingConfigData buildingConfigData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(this.BuildingLogicData.BuildingType, initialLevel); SceneManager.Instance.ConstructBuilding(buildingConfigData, this.BuildingLogicData.BuildingType, false); } else { UIErrorMessage.Instance.ErrorMessage(2); } // } }
public void FinishUpgradeWithoutCommunication() { this.m_Data.UpgradeRemainingWorkload = null; this.m_Data.BuilderBuildingNO = null; int nextLevel = this.m_Data.Level == 0 ? this.m_Data.ConfigData.InitialLevel : this.m_Data.Level + this.m_Data.ConfigData.UpgradeStep; this.m_Data.Level = nextLevel; BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper. GetBuildingData(this.m_Data.BuildingID.buildingType, this.m_Data.Level); this.m_Data.ConfigData = configData; if (this.m_Data.Level > 0) { if (this.m_Data.ConfigData.CanProduceGold) { this.m_Data.LastCollectedGoldTick = LogicTimer.Instance.GetServerTick(); } if (this.m_Data.ConfigData.CanProduceFood) { this.m_Data.LastCollectedFoodTick = LogicTimer.Instance.GetServerTick(); } if (this.m_Data.ConfigData.CanProduceOil) { this.m_Data.LastCollectedOilTick = LogicTimer.Instance.GetServerTick(); } } this.AddComponentAccordingToConfigData(configData, ((int)BuildingFunction.All)); }
public void FinishBuildingUpgrade(BuildingIdentity id) { BuildingLogicData building = this.m_BuildingModule.GetBuildingObject(id); BuildingConfigData oldData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(id.buildingType, building.Level); BuildingConfigData newData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(id.buildingType, building.Level + oldData.UpgradeStep); if (!newData.CanProduceGold) { this.m_PlayerModule.AddGoldCapacity(newData.StoreGoldCapacity, oldData.StoreGoldCapacity); } if (!newData.CanProduceFood) { this.m_PlayerModule.AddFoodCapacity(newData.StoreFoodCapacity, oldData.StoreFoodCapacity); } if (!newData.CanProduceOil) { this.m_PlayerModule.AddOilCapacity(newData.StoreOilCapacity, oldData.StoreOilCapacity); } if (newData.CanStoreProps) { this.m_PlayerModule.AddPropsCapacity(newData.StorePropsCapacity, oldData.StorePropsCapacity); } this.m_BuildingModule.FinishBuildingUpgrade(id); this.RewardResource(oldData.UpgradeRewardGold, oldData.UpgradeRewardFood, oldData.UpgradeRewardOil, oldData.UpgradeRewardGem, oldData.UpgradeRewardExp); this.TaskManager.OnUpgradeBuilding(id.buildingType, this.m_BuildingModule.GetBuildingObject(id).Level); }
public void FinishBuildingConstruct(BuildingIdentity id) { int initialLevel = ConfigInterface.Instance.BuildingConfigHelper.GetInitialLevel(id.buildingType); BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(id.buildingType, initialLevel); if (!configData.CanProduceGold) { this.m_PlayerModule.AddGoldCapacity(configData.StoreGoldCapacity); } if (!configData.CanProduceFood) { this.m_PlayerModule.AddFoodCapacity(configData.StoreFoodCapacity); } if (!configData.CanProduceOil) { this.m_PlayerModule.AddOilCapacity(configData.StoreOilCapacity); } if (configData.CanStoreProps) { this.m_PlayerModule.AddPropsCapacity(configData.StorePropsCapacity); } this.m_BuildingModule.FinishBuildingConstruct(id); BuildingConfigData initialConfigData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(id.buildingType, 0); this.RewardResource(initialConfigData.UpgradeRewardGold, initialConfigData.UpgradeRewardFood, initialConfigData.UpgradeRewardOil, initialConfigData.UpgradeRewardGem, initialConfigData.UpgradeRewardExp); this.m_TaskModule.OnConstructBuilding(id.buildingType); }
public void ConstructBuilding(BuildingType type, int level) { BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(type, level); TilePosition centerPosition = PositionConvertor.GetBuildingTileIndexFromWorldPosition(this.m_SceneCamare.position); TilePosition position = this.FindValidBuildingPosition(centerPosition, configData.BuildingObstacleList); if (position != null) { this.ConstructBuilding(type, level, position); } }
void ShowSelectBuilderWindow(BuilderMenuType builderMenuType) { BuildingConfigData buildingConfigData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(this.BuildingBehavior.BuildingType, 0); UIManager.Instance.UIWindowSelectBuilder.BuildingConfigData = buildingConfigData; UIManager.Instance.UIWindowSelectBuilder.BuildingLogicData = this.BuildingLogicData; UIManager.Instance.UIWindowSelectBuilder.BuilderMenuType = builderMenuType; UIManager.Instance.UIWindowSelectBuilder.BuildingBehavior = this.BuildingBehavior; UIManager.Instance.UIWindowSelectBuilder.ShowWindow(); this.BuildingBehavior.ActiveButton(false); }
public BuildingIdentity ConstructBuilding(BuildingType type, int builderBuildingNO, TilePosition position) { BuildingData data = new BuildingData(); BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(type, 0); //int builderHutLevel = this.m_Buildings[BuildingType.BuilderHut][builderBuildingNO].Level; //BuilderConfigData builderData = ConfigInterface.Instance.BuilderConfigHelper.GetBuilderData(builderHutLevel); data.ConfigData = configData; int NO = this.m_Buildings.ContainsKey(type) ? this.m_Buildings[type].Count : 0; data.BuildingID = new BuildingIdentity(type, NO); data.Level = 0; data.UpgradeRemainingWorkload = configData.UpgradeWorkload; data.BuilderBuildingNO = builderBuildingNO; data.BuildingPosition = position; if (type == BuildingType.Tavern) { List <MercenaryType> mercenaryTypes = ConfigInterface.Instance.MercenaryConfigHelper.GetAvailableMercenaries(configData.InitialLevel); Dictionary <MercenaryType, MercenaryProductData> dict = new Dictionary <MercenaryType, MercenaryProductData>(); foreach (MercenaryType mercenaryType in mercenaryTypes) { MercenaryProductData productData = new MercenaryProductData(); MercenaryConfigData config = ConfigInterface.Instance.MercenaryConfigHelper.GetMercenaryData(mercenaryType); productData.ConfigData = config; productData.ReadyNumber = config.MaxProduceNumber; dict.Add(mercenaryType, productData); } data.ProduceMercenary = new MercenaryProductCollectionLogicObject(dict); } if (!this.m_Buildings.ContainsKey(type)) { this.m_Buildings.Add(type, new Dictionary <int, BuildingLogicObject>()); } this.m_Buildings[type].Add(data.BuildingID.buildingNO, this.ConstructBuildingLogicObject(data)); this.m_BuilderManager.SendBuilder(builderBuildingNO, this.GetBuildingObject(data.BuildingID)); this.m_CommunicationHelper.SendConstructBuildingRequest(data.BuildingID, position, builderBuildingNO); BuildingIdentity result = new BuildingIdentity(); result.buildingType = type; result.buildingNO = data.BuildingID.buildingNO; return(result); }
private void AddComponentAccordingToConfigData(BuildingConfigData configData, int functionMask) { if (configData.CanProduceArmy && (functionMask & ((int)BuildingFunction.ProduceArmy)) != 0 && this.m_ArmyProduceComponent == null) { ArmyProduceComponent comp = new ArmyProduceComponent(); this.InitialComponent(comp); comp.ProduceFinished += this.ArmyProduced; this.m_ArmyProduceComponent = comp; } if (configData.CanProduceItem && (functionMask & ((int)BuildingFunction.ProduceItem)) != 0 && this.m_ItemProduceComponent == null) { ItemProduceComponent comp = new ItemProduceComponent(); this.InitialComponent(comp); comp.ProduceFinished += this.ItemProduced; this.m_ItemProduceComponent = comp; } if (configData.CanUpgradeArmy && (functionMask & ((int)BuildingFunction.UpgradeArmy)) != 0 && this.m_ArmyUpgradeComponent == null) { ArmyUpgradeComponent comp = new ArmyUpgradeComponent(); this.InitialComponent(comp); comp.ProduceFinished += this.ArmyUpgraded; this.m_ArmyUpgradeComponent = comp; } if (configData.CanUpgradeItem && (functionMask & ((int)BuildingFunction.UpgradeItem)) != 0 && this.m_ItemUpgradeComponent == null) { ItemUpgradeComponent comp = new ItemUpgradeComponent(); this.InitialComponent(comp); comp.ProduceFinished += this.ItemUpgraded; this.m_ItemUpgradeComponent = comp; } if (this.m_Data.ProduceMercenary != null && (functionMask & ((int)BuildingFunction.ProduceMercenary)) != 0 && this.m_MercenaryComponents == null) { this.m_MercenaryComponents = new Dictionary <MercenaryType, MercenaryProduceComponent>(); foreach (MercenaryType type in this.m_Data.ProduceMercenary.Products.Keys) { MercenaryProduceComponent comp = new MercenaryProduceComponent(type); this.InitialComponent(comp); this.m_MercenaryComponents.Add(type, comp); } } }
public void RecordPlunderResource(int gold, int food, int oil, BuildingPropertyBehavior property) { this.m_GoldTrophy += gold; this.m_FoodTrophy += food; this.m_OilTrophy += oil; BattleSceneHelper.Instance.Plunder(gold, food, oil); if (BattleDirector.Instance != null) { LogicController.Instance.PlunderResource(gold, food, oil); PlunderResourceRequestParameter request = new PlunderResourceRequestParameter(); request.OperateTime = TimeTickRecorder.Instance.CurrentTimeTick - BattleDirector.Instance.MatchStartTick; BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(property.BuildingType, property.Level); if (gold > 0) { request.PlunderGold = gold; if (configData.CanProduceGold) { request.BuildingType = property.BuildingType; request.BuildingNO = property.BuildingNO; } } if (food > 0) { request.PlunderFood = food; if (configData.CanProduceFood) { request.BuildingType = property.BuildingType; request.BuildingNO = property.BuildingNO; } } if (oil > 0) { request.PlunderOil = oil; if (configData.CanProduceOil) { request.BuildingType = property.BuildingType; request.BuildingNO = property.BuildingNO; } } CommunicationUtility.Instance.PlunderResource(request); } }
void ConstructEvent(Action function) { BuildingConfigData buildingConfigData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(this.BuildingBehavior.BuildingType, 0); Dictionary <CostType, int> costBalance = this.BuildingBehavior.Created ? SystemFunction.UpgradeCostBalance(this.BuildingLogicData) : SystemFunction.UpgradeCosBalance(buildingConfigData); Dictionary <CostType, int> costTotal = this.BuildingBehavior.Created ? SystemFunction.UpgradeTotalCost(this.BuildingLogicData) : SystemFunction.UpgradeTotalCost(buildingConfigData); int costGem = this.BuildingBehavior.Created ? this.BuildingLogicData.UpgradeGem : buildingConfigData.UpgradeGem; if (costBalance.Count > 0) { int costBalanceGem = SystemFunction.ResourceConvertToGem(costBalance); //int costResourceToGem = SystemFunction.ResourceConvertToGem(costTotal) - costGem; string resourceContext = SystemFunction.BuyReusoureContext(costBalance); UIManager.Instance.UIWindowCostPrompt.ShowWindow(costBalanceGem, resourceContext, SystemFunction.BuyReusoureTitle(costBalance)); UIManager.Instance.UIWindowCostPrompt.UnRegistDelegate(); UIManager.Instance.UIWindowCostPrompt.Click += () => { if (SystemFunction.CostUplimitCheck(costTotal[CostType.Gold], costTotal[CostType.Food], costTotal[CostType.Oil])) { if (LogicController.Instance.PlayerData.CurrentStoreGem - costBalanceGem /*costResourceToGem*/ < costGem) { print("宝石不足,去商店"); UIManager.Instance.UIWindowFocus = null; //UIManager.Instance.UIButtonShopping.GoShopping(); UIManager.Instance.UISelectShopMenu.GoShopping(); } else { print("宝石换资源!"); SystemFunction.BuyResources(costBalance); function.Invoke(); } } else { UIErrorMessage.Instance.ErrorMessage(16); } }; } else { function.Invoke(); } }
private void BuyBuilding(BuildingType type, int buildingNO, TilePosition position) { BuildingData data = new BuildingData(); int initialLevel = ConfigInterface.Instance.BuildingConfigHelper.GetInitialLevel(type); BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(type, initialLevel); data.ConfigData = configData; data.BuildingID = new BuildingIdentity(type, buildingNO); data.Level = initialLevel; data.BuildingPosition = position; if (!this.m_Buildings.ContainsKey(type)) { this.m_Buildings.Add(type, new Dictionary <int, BuildingLogicObject>()); } this.m_Buildings[type].Add(data.BuildingID.buildingNO, this.ConstructBuildingLogicObject(data)); this.ReCalculateResource(); }
public void ConstructBuilding(BuildingType type, int level, TilePosition position) { BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(type, level); string prefabName = string.Format("{0}{1}{2}", ClientStringConstants.BATTLE_SCENE_RESOURCE_PREFAB_PREFIX_NAME, ClientStringConstants.BUILDING_OBJECT_PREFAB_PREFIX_NAME, configData.BuildingPrefabName); GameObject buildingPrefab = Resources.Load(prefabName) as GameObject; GameObject newBuilding = GameObject.Instantiate(buildingPrefab) as GameObject; GameObject.DestroyImmediate(newBuilding.GetComponent <BuildingAI>()); GameObject.DestroyImmediate(newBuilding.GetComponent <BuildingHPBehavior>()); ResourceStoreBehavior storeBehavior = newBuilding.GetComponent <ResourceStoreBehavior>(); if (storeBehavior != null) { GameObject.DestroyImmediate(storeBehavior); } WallUtility wall = newBuilding.GetComponent <WallUtility>(); if (wall != null) { GameObject.DestroyImmediate(wall); newBuilding.AddComponent <EditorWallUtility>(); } EditorBuildingBehavior buildingBehavior = newBuilding.AddComponent <EditorBuildingBehavior>(); buildingBehavior.Position = position; buildingBehavior.BuildingType = type; buildingBehavior.Level = level; newBuilding.transform.position = PositionConvertor.GetWorldPositionByBuildingTileIndex(position); newBuilding.transform.parent = this.m_SceneParent; this.PopulateMapData(position, configData.BuildingObstacleList, newBuilding); }
public void InitialWithResponseData(FriendResponseParameter parameter, string friendName) { UserData userData = new UserData(); userData.Name = friendName; userData.Honour = parameter.Honour; userData.Level = parameter.Level; userData.CurrentStoreGold = parameter.PlayerGold; userData.CurrentStoreFood = parameter.PlayerFood; userData.CurrentStoreOil = parameter.PlayerOil; userData.ConfigData = ConfigInterface.Instance.PlayerConfigHelper.GetPlayerData(parameter.Level); this.m_FriendData = new PlayerLogicData(userData); this.m_LogicObjects = new Dictionary <BuildingType, Dictionary <int, BuildingLogicObject> >(); this.m_ArmyObjects = new Dictionary <ArmyType, Dictionary <int, FriendArmyParameter> >(); this.m_Mercenaries = new Dictionary <MercenaryType, int>(); this.m_ItemObjects = new Dictionary <ItemType, Dictionary <int, FriendItemParameter> >(); this.m_AchievementBuildings = new Dictionary <int, AchievementBuildingLogicData>(); this.m_Buffs = new List <BuffLogicData>(); this.m_Props = new List <PropsLogicData>(); this.m_ResourceManager = new ResourceManager(); this.m_ArmyLevels = new Dictionary <ArmyType, int>(); Dictionary <BuildingType, Dictionary <int, BuildingData> > datas = new Dictionary <BuildingType, Dictionary <int, BuildingData> >(); this.m_RemovableObjects = new Dictionary <long, RemovableObjectLogicData>(); int objectID = 0; foreach (FriendObjectParameter param in parameter.Objects) { RemovableObjectData data = new RemovableObjectData(); data.BuilderBuildingNO = param.BuilderBuildingNO; data.Position = new TilePosition(param.PositionColumn, param.PositionRow); if (param.IsRemoving) { if (param.BuilderBuildingNO.HasValue) { data.RemainingWorkload = 0; } else { data.RemainingWorkload = 1; } } data.RemovableObjectNo = objectID; data.RemovableObjectType = param.ObjectType; data.ConfigData = ConfigInterface.Instance.RemovableConfigHelper.GetRemovableObjectData(param.ObjectType); this.m_RemovableObjects.Add(objectID, new RemovableObjectLogicData(data)); objectID++; } int buildingNo = 0; foreach (FriendAchievementBuildingParameter param in parameter.AchievementBuildings) { AchievementBuildingData data = new AchievementBuildingData(); data.AchievementBuildingType = param.AchievementBuildingType; data.BuildingNo = buildingNo++; data.BuildingPosition = new TilePosition(param.PositionColumn, param.PositionRow); data.Life = param.Life; data.ConfigData = ConfigInterface.Instance.AchievementBuildingConfigHelper.GetAchievementBuildingData(param.AchievementBuildingType); this.m_AchievementBuildings.Add(data.BuildingNo, new AchievementBuildingLogicData(data)); } foreach (FriendBuffParameter buff in parameter.Buffs) { BuffData b = new BuffData(); b.RelatedPropsType = buff.PropsType; b.RemainingCD = 10; b.BuffConfigData = ConfigInterface.Instance.PropsConfigHelper.GetPropsData(buff.PropsType).FunctionConfigData as PropsBuffConfigData; BuffLogicData data = new BuffLogicData(b); this.m_Buffs.Add(data); } int tempPropsID = 0; foreach (FriendPropsParameter props in parameter.Props) { PropsData p = new PropsData(); PropsConfigData propsConfigData = ConfigInterface.Instance.PropsConfigHelper.GetPropsData(props.PropsType); p.PropsConfigData = propsConfigData; p.PropsNo = tempPropsID++; p.PropsType = props.PropsType; p.RemainingCD = 10; p.RemainingUseTime = propsConfigData.MaxUseTimes; PropsLogicData data = new PropsLogicData(p); this.m_Props.Add(data); } foreach (FriendBuildingParameter param in parameter.Buildings) { BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(param.BuildingTypeID, param.Level); BuildingData data = new BuildingData(); data.BuilderBuildingNO = param.BuilderBuildingNO; data.BuildingID = new BuildingIdentity(param.BuildingTypeID, param.BuildingNO); data.BuildingPosition = new TilePosition(param.PositionColumn, param.PositionRow); data.Level = param.Level; if (param.IsUpgrading) { if (param.BuilderBuildingNO.HasValue) { data.UpgradeRemainingWorkload = 1; } else { data.UpgradeRemainingWorkload = 0; } } if (param.IsResourceAccelerate) { data.RemainResourceAccelerateTime = 1; } if (param.IsArmyAccelerate) { data.RemainArmyAccelerateTime = 1; } if (param.IsItemAccelerate) { data.RemainItemAccelerateTime = 1; } data.ConfigData = configData; if (param.CurrentStoreGold.HasValue) { data.CurrentStoreGold = param.CurrentStoreGold.Value; } else if (configData.CanStoreGold) { this.m_ResourceManager.AddStorage(ResourceType.Gold, data.BuildingID, configData.StoreGoldCapacity); } if (param.CurrentStoreFood.HasValue) { data.CurrentStoreFood = param.CurrentStoreFood.Value; } else if (configData.CanStoreFood) { this.m_ResourceManager.AddStorage(ResourceType.Food, data.BuildingID, configData.StoreFoodCapacity); } if (param.CurrentStoreOil.HasValue) { data.CurrentStoreOil = param.CurrentStoreOil.Value; } else if (configData.CanStoreOil) { this.m_ResourceManager.AddStorage(ResourceType.Oil, data.BuildingID, configData.StoreOilCapacity); } if (!this.m_LogicObjects.ContainsKey(param.BuildingTypeID)) { this.m_LogicObjects.Add(param.BuildingTypeID, new Dictionary <int, BuildingLogicObject>()); } if (!datas.ContainsKey(param.BuildingTypeID)) { datas.Add(param.BuildingTypeID, new Dictionary <int, BuildingData>()); } this.m_LogicObjects[param.BuildingTypeID].Add(param.BuildingNO, new BuildingLogicObject(data, (int)BuildingFunction.ProduceResource, false)); datas[param.BuildingTypeID].Add(param.BuildingNO, data); data.AvailableMercenary = new List <MercenaryIdentity>(); if (param.Mercenaries != null) { foreach (KeyValuePair <MercenaryType, int> mercenary in param.Mercenaries) { MercenaryConfigData mercenaryConfigData = ConfigInterface.Instance.MercenaryConfigHelper.GetMercenaryData(mercenary.Key); this.m_AlreadyArmyCapacity += mercenaryConfigData.CapcityCost * mercenary.Value; for (int i = 0; i < mercenary.Value; i++) { data.AvailableMercenary.Add(new MercenaryIdentity(mercenary.Key, i)); if (!this.m_Mercenaries.ContainsKey(mercenary.Key)) { this.m_Mercenaries.Add(mercenary.Key, 0); } this.m_Mercenaries[mercenary.Key]++; } } } data.AvailableArmy = new List <ArmyIdentity>(); if (param.Armies != null) { foreach (FriendArmyParameter army in param.Armies) { if (!this.m_ArmyLevels.ContainsKey(army.ArmyType)) { this.m_ArmyLevels.Add(army.ArmyType, army.ArmyLevel); } ArmyType type = army.ArmyType; ArmyConfigData armyConfigData = ConfigInterface.Instance.ArmyConfigHelper.GetArmyData(army.ArmyType, army.ArmyLevel); this.m_AlreadyArmyCapacity += armyConfigData.CapcityCost; if (!this.m_ArmyObjects.ContainsKey(type)) { this.m_ArmyObjects.Add(type, new Dictionary <int, FriendArmyParameter>()); } ArmyIdentity armyID = new ArmyIdentity(type, this.m_ArmyObjects[type].Count); data.AvailableArmy.Add(armyID); this.m_ArmyObjects[type].Add(armyID.armyNO, army); } } data.AvailableItem = new List <ItemIdentity>(); if (param.Items != null) { foreach (FriendItemParameter item in param.Items) { ItemType type = item.ItemType; if (!this.m_ItemObjects.ContainsKey(type)) { this.m_ItemObjects.Add(type, new Dictionary <int, FriendItemParameter>()); } ItemIdentity itemID = new ItemIdentity(type, this.m_ItemObjects[type].Count); data.AvailableItem.Add(itemID); this.m_ItemObjects[type].Add(itemID.itemNO, item); } } this.m_TotalCampCapacity += configData.ArmyCapacity; } Dictionary <ResourceType, Dictionary <BuildingIdentity, int> > result = this.m_ResourceManager.CalculateStorage (userData.CurrentStoreGold, userData.CurrentStoreFood, userData.CurrentStoreOil); foreach (KeyValuePair <ResourceType, Dictionary <BuildingIdentity, int> > resource in result) { foreach (KeyValuePair <BuildingIdentity, int> r in resource.Value) { switch (resource.Key) { case ResourceType.Gold: { datas[r.Key.buildingType][r.Key.buildingNO].CurrentStoreGold = r.Value; } break; case ResourceType.Food: { datas[r.Key.buildingType][r.Key.buildingNO].CurrentStoreFood = r.Value; } break; case ResourceType.Oil: { datas[r.Key.buildingType][r.Key.buildingNO].CurrentStoreOil = r.Value; } break; } } } }
// Use this for initialization void Start() { this.m_ConfigData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(this.m_Type, 0); }
public void ConstructBuilding(FindRivalResponseParameter response) { foreach (BattleRemovableObjectParameter removableObject in response.Objects) { this.ConstructRemovableObject(removableObject); } foreach (BattleDefenseObjectParameter defenseObject in response.DefenseObjects) { this.ConstructDefenseObject(defenseObject); } if (response.Buffs != null) { BuildingBuffSystem.Instance.ClearBuff(); BuildingBuffSystem.Instance.InitialBuff(response.Buffs); } bool isReplay = Application.loadedLevelName == ClientStringConstants.BATTLE_REPLAY_LEVEL_NAME; Dictionary <BuildingType, int> NOGenerater = new Dictionary <BuildingType, int>(); if (isReplay) { for (int i = 0; i < (int)BuildingType.Length; i++) { NOGenerater.Add((BuildingType)i, 0); } } Age age = Age.Prehistoric; bool isInitialAge = false; List <BuildingSurfaceBehavior> notInitialSurfaces = new List <BuildingSurfaceBehavior>(); foreach (BattleBuildingParameter building in response.Buildings) { BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(building.BuildingType, building.Level); string prefabName = string.Format("{0}{1}{2}", ClientStringConstants.BATTLE_SCENE_RESOURCE_PREFAB_PREFIX_NAME, ClientStringConstants.BUILDING_OBJECT_PREFAB_PREFIX_NAME, configData.BuildingPrefabName); GameObject buildingPrefab = Resources.Load(prefabName) as GameObject; GameObject buildingObject = GameObject.Instantiate(buildingPrefab) as GameObject; buildingObject.transform.position = PositionConvertor.GetWorldPositionFromBuildingTileIndex (new TilePosition(building.PositionColumn, building.PositionRow)); buildingObject.transform.parent = this.m_ParentNode; BuildingPropertyBehavior property = buildingObject.GetComponent <BuildingPropertyBehavior>(); property.BuildingType = building.BuildingType; if (building.BuildingType == BuildingType.CityHall) { this.m_CurrentRivalCityHallLevel = building.Level; age = CommonUtilities.CommonUtilities.GetAgeFromCityHallLevel(building.Level); isInitialAge = true; } if (isReplay) { property.BuildingNO = NOGenerater[building.BuildingType]; NOGenerater[building.BuildingType]++; } else { property.BuildingNO = building.BuildingNO; } property.BuildingCategory = (BuildingCategory)configData.Category; property.Level = building.Level; property.BuildingPosition = new TilePosition(building.PositionColumn, building.PositionRow); property.BuildingObstacleList = new List <TilePosition>(); property.ActorObstacleList = new List <TilePosition>(); foreach (TilePoint buildingObstacle in configData.BuildingObstacleList) { property.BuildingObstacleList.Add(buildingObstacle.ConvertToTilePosition()); } foreach (TilePoint actorObstacle in configData.ActorObstacleList) { property.ActorObstacleList.Add(actorObstacle.ConvertToTilePosition()); } //propert property.PlunderRate = configData.PlunderRate; property.GoldCapacity = configData.StoreGoldCapacity; property.FoodCapacity = configData.StoreFoodCapacity; property.OilCapacity = configData.StoreOilCapacity; property.Buffs = BuildingBuffSystem.Instance.GetBuffs(property.BuildingCategory); if (building.CurrentGold.HasValue || building.CurrentFood.HasValue || building.CurrentOil.HasValue) { property.Gold = building.CurrentGold.HasValue ? building.CurrentGold.Value : 0; property.Food = building.CurrentFood.HasValue ? building.CurrentFood.Value : 0; property.Oil = building.CurrentOil.HasValue ? building.CurrentOil.Value : 0; property.Gold = Mathf.RoundToInt(property.Gold * property.PlunderRate); property.Food = Mathf.RoundToInt(property.Food * property.PlunderRate); property.Oil = Mathf.RoundToInt(property.Oil * property.PlunderRate); property.OriginalGold = property.Gold; property.OriginalFood = property.Food; property.OriginalOil = property.Oil; this.m_SceneHelper.AddProduceResourceBuilding(property); } else { if ((configData.CanStoreGold && !configData.CanProduceGold && building.Level != 0) || (configData.CanStoreFood && !configData.CanProduceFood && building.Level != 0) || (configData.CanStoreOil && !configData.CanProduceOil && building.Level != 0)) { this.m_SceneHelper.AddResourceBuilding(buildingObject, new CapacityConfigData() { GoldCapacity = configData.StoreGoldCapacity, FoodCapacity = configData.StoreFoodCapacity, OilCapacity = configData.StoreOilCapacity }); } } BuildingHPBehavior hp = buildingObject.GetComponent <BuildingHPBehavior>(); hp.TotalHP = Mathf.Max(1, configData.MaxHP + property.BuffHPEffect); hp.SceneHelper = this.m_SceneHelper; hp.ArmorCategory = configData.ArmorCategory; if (building.BuilderLevel.HasValue) { BattleObstacleUpgradingInfo info = new BattleObstacleUpgradingInfo() { AttachedBuilderLevel = building.BuilderLevel.Value, ObstacleProperty = property }; this.m_SceneHelper.AddUpgradingObstacle(info); } if (building.IsUpgrading) { this.ConstructFacility(buildingObject, property); } BuildingSurfaceBehavior surface = buildingObject.GetComponent <BuildingSurfaceBehavior>(); if (surface != null) { if (isInitialAge) { surface.SetSurface(age, building.BuildingType); } else { notInitialSurfaces.Add(surface); } } BuildingAI buildingAI = buildingObject.GetComponent <BuildingAI>(); if (configData.CanAttack && !building.IsUpgrading) { buildingAI.enabled = false; AttackBehavior attackBehavior = null; if (configData.ApMinScope > 0) { attackBehavior = buildingObject.AddComponent <RingAttackBehavior>(); ((RingAttackBehavior)attackBehavior).BlindScope = configData.ApMinScope; } else { attackBehavior = buildingObject.AddComponent <AttackBehavior>(); } int cd = Mathf.FloorToInt(configData.AttackCD * ClientConfigConstants.Instance.TicksPerSecond); attackBehavior.AttackCD = Mathf.Max(1, cd - property.BuffAttackSpeedEffect); attackBehavior.AttackScope = configData.ApMaxScope; attackBehavior.AttackValue = Mathf.Max(1, configData.AttackValue + property.BuffAttackValueEffect); attackBehavior.BulletFlySpeed = configData.AttackMiddleSpeed; attackBehavior.AttackType = (AttackType)configData.AttackType; attackBehavior.AttackCategory = configData.AttackCategory; attackBehavior.TargetType = (TargetType)configData.TargetType; attackBehavior.DamageScope = configData.DamageScope; attackBehavior.PushTicks = configData.DamagePushTicks; attackBehavior.PushVelocity = configData.DamagePushVelocity; attackBehavior.BulletParent = this.m_BulletParent; buildingAI.AttackBehavior = attackBehavior; BuildingIdleState idleState = new BuildingIdleState(buildingAI, true); buildingAI.ChangeState(idleState); buildingAI.SceneHelper = BattleSceneHelper.Instance; } else { buildingAI.DetachSelf(); } this.m_SceneHelper.ConstructBuilding(buildingObject); } foreach (BuildingSurfaceBehavior surface in notInitialSurfaces) { surface.SetSurface(age, surface.GetComponent <BuildingPropertyBehavior>().BuildingType); } this.m_SceneHelper.DistributeResource(response.TotalGold, response.TotalFood, response.TotalOil); foreach (BattleAchievementBuildingParameter achievementBuilding in response.AchievementBuildings) { this.ConstructAchievementBuilding(achievementBuilding, age); } }
public static FindRivalResponseParameter ConvertJSONToParameter(Hashtable map) { FindRivalResponseParameter result = new FindRivalResponseParameter(); result.Objects = new List <BattleRemovableObjectParameter>(); result.Buildings = new List <BattleBuildingParameter>(); result.AchievementBuildings = new List <BattleAchievementBuildingParameter>(); result.DefenseObjects = new List <BattleDefenseObjectParameter>(); result.RivalHonour = 10000; result.RivalID = -100; result.RivalLevel = -100; result.RivalName = "电脑"; result.TotalFood = 0; result.TotalGold = 0; result.TotalOil = 0; if (map.ContainsKey(EditorConfigInterface.Instance.MapBuildingKey)) { var buildings = (ArrayList)map[EditorConfigInterface.Instance.MapBuildingKey]; foreach (var b in buildings) { Hashtable building = (Hashtable)b; BattleBuildingParameter param = new BattleBuildingParameter(); param.BuildingNO = Convert.ToInt32(building[EditorConfigInterface.Instance.MapBuildingNoKey]); param.BuildingType = (BuildingType)(Convert.ToInt32(building[EditorConfigInterface.Instance.MapBuildingTypeKey])); param.IsUpgrading = false; param.Level = Convert.ToInt32(building[EditorConfigInterface.Instance.MapBuildingLevelKey]); param.PositionColumn = Convert.ToInt32(building[EditorConfigInterface.Instance.MapBuildingColumnKey]); param.PositionRow = Convert.ToInt32(building[EditorConfigInterface.Instance.MapBuildingRowKey]); BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(param.BuildingType, param.Level); if (configData.StoreGoldCapacity > 0) { if (configData.CanProduceGold) { param.CurrentGold = configData.StoreGoldCapacity; } else { result.TotalGold += configData.StoreGoldCapacity; } } if (configData.StoreFoodCapacity > 0) { if (configData.CanProduceFood) { param.CurrentFood = configData.StoreFoodCapacity; } else { result.TotalFood += configData.StoreFoodCapacity; } } if (configData.StoreOilCapacity > 0) { if (configData.CanProduceOil) { param.CurrentOil = configData.StoreOilCapacity; } else { result.TotalOil += configData.StoreOilCapacity; } } result.Buildings.Add(param); } } if (map.ContainsKey(EditorConfigInterface.Instance.MapRemovableObjectKey)) { var objects = (ArrayList)map[EditorConfigInterface.Instance.MapRemovableObjectKey]; foreach (var o in objects) { Hashtable removableObject = (Hashtable)o; BattleRemovableObjectParameter param = new BattleRemovableObjectParameter(); param.ObjectType = (RemovableObjectType)(Convert.ToInt32(removableObject[EditorConfigInterface.Instance.MapRemovableObjectTypeKey])); param.PositionRow = Convert.ToInt32(removableObject[EditorConfigInterface.Instance.MapBuildingRowKey]); param.PositionColumn = Convert.ToInt32(removableObject[EditorConfigInterface.Instance.MapBuildingColumnKey]); result.Objects.Add(param); } } if (map.ContainsKey(EditorConfigInterface.Instance.MapAchievementBuildingKey)) { var achievementBuildings = (ArrayList)map[EditorConfigInterface.Instance.MapAchievementBuildingKey]; int buildingNo = 0; foreach (var a in achievementBuildings) { Hashtable achievementBuilding = (Hashtable)a; BattleAchievementBuildingParameter param = new BattleAchievementBuildingParameter(); param.AchievementBuildingNo = ++buildingNo; param.AchievementBuildingType = (AchievementBuildingType)(Convert.ToInt32(achievementBuilding[EditorConfigInterface.Instance.MapAchievementBuildingTypeKey])); param.IsDropProps = false; param.PositionRow = Convert.ToInt32(achievementBuilding[EditorConfigInterface.Instance.MapAchievementBuildingRowKey]); param.PositionColumn = Convert.ToInt32(achievementBuilding[EditorConfigInterface.Instance.MapAchievementBuildingColumnKey]); result.AchievementBuildings.Add(param); } } if (map.ContainsKey(EditorConfigInterface.Instance.MapDefenseObjectKey)) { var defenseObjects = (ArrayList)map[EditorConfigInterface.Instance.MapDefenseObjectKey]; long objectID = 0; foreach (var d in defenseObjects) { Hashtable defenseObject = (Hashtable)d; BattleDefenseObjectParameter param = new BattleDefenseObjectParameter(); param.DefenseObjectID = objectID++; param.PropsType = (PropsType)(Convert.ToInt32(defenseObject[EditorConfigInterface.Instance.MapDefenseObjectTypeKey])); param.PositionRow = Convert.ToInt32(defenseObject[EditorConfigInterface.Instance.MapDefenseObjectRowKey]); param.PositionColumn = Convert.ToInt32(defenseObject[EditorConfigInterface.Instance.MapDefenseObjectColumnKey]); result.DefenseObjects.Add(param); } } return(result); }
private BuildingData GenerateBuildingData(BuildingParameter param, List <ArmyData> armies, List <ItemData> items, Dictionary <MercenaryIdentity, MercenaryData> mercenaries, List <ObjectUpgrade <ArmyType> > armyUpgrades, List <ObjectUpgrade <ItemType> > itemUpgrades, UserData userData) { BuildingData result = new BuildingData(); BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData (param.BuildingTypeID, param.Level); result.ConfigData = configData; BuildingIdentity id = new BuildingIdentity(); id.buildingNO = param.BuildingNO; id.buildingType = param.BuildingTypeID; result.BuildingID = id; result.BuildingPosition = new TilePosition(param.PositionColumn, param.PositionRow); result.Level = param.Level; result.UpgradeRemainingWorkload = param.RemainWorkload; if (param.LastCollectGoldTick.HasValue) { result.LastCollectedGoldTick = param.LastCollectGoldTick.Value; } if (param.CollectedGold.HasValue) { result.CollectedGold = param.CollectedGold.Value; } if (param.LastCollectFoodTick.HasValue) { result.LastCollectedFoodTick = param.LastCollectFoodTick.Value; } if (param.CollectedFood.HasValue) { result.CollectedFood = param.CollectedFood.Value; } if (param.LastCollectOilTick.HasValue) { result.LastCollectedOilTick = param.LastCollectOilTick.Value; } if (param.CollectedOil.HasValue) { result.CollectedOil = param.CollectedOil.Value; } if (param.ArmyProducts != null) { result.ProduceArmy = new List <KeyValuePair <ArmyType, List <ArmyIdentity> > >(); ArmyType?previousType = null; foreach (ArmyProductParameter product in param.ArmyProducts) { if (previousType.HasValue && previousType.Value == product.ArmyType) { result.ProduceArmy[result.ProduceArmy.Count - 1].Value.Add(new ArmyIdentity(product.ArmyType, product.ArmyNO)); } else { List <ArmyIdentity> newList = new List <ArmyIdentity>() { new ArmyIdentity(product.ArmyType, product.ArmyNO) }; result.ProduceArmy.Add(new KeyValuePair <ArmyType, List <ArmyIdentity> >(product.ArmyType, newList)); } previousType = product.ArmyType; armies.Add(this.GenerateArmyData(product, userData)); } } if (param.Armies != null) { result.AvailableArmy = new List <ArmyIdentity>(); foreach (ArmyParameter army in param.Armies) { result.AvailableArmy.Add(new ArmyIdentity(army.ArmyType, army.ArmyNO)); armies.Add(this.GenerateArmyData(army, userData, id)); } } if (param.ArmyUpgrade != null) { result.ArmyUpgrade = param.ArmyUpgrade.ArmyType; ObjectUpgrade <ArmyType> upgrade = new ObjectUpgrade <ArmyType>(param.ArmyUpgrade.ArmyType, param.ArmyUpgrade.RemainingWorkload); armyUpgrades.Add(upgrade); } if (param.ItemProducts != null) { result.ProduceItem = new List <KeyValuePair <ItemType, List <ItemIdentity> > >(); ItemType?previousType = null; foreach (ItemProductParameter product in param.ItemProducts) { if (previousType.HasValue && previousType.Value == product.ItemType) { result.ProduceItem[result.ProduceItem.Count - 1].Value.Add(new ItemIdentity(product.ItemType, product.ItemNO)); } else { List <ItemIdentity> newList = new List <ItemIdentity>() { new ItemIdentity(product.ItemType, product.ItemNO) }; result.ProduceItem.Add(new KeyValuePair <ItemType, List <ItemIdentity> >(product.ItemType, newList)); } previousType = product.ItemType; items.Add(this.GenerateItemData(product, userData)); } } if (param.Items != null) { result.AvailableItem = new List <ItemIdentity>(); foreach (ItemParameter item in param.Items) { result.AvailableItem.Add(new ItemIdentity(item.ItemType, item.ItemNO)); items.Add(this.GenerateItemData(item, userData)); } } if (param.ItemUpgrade != null) { result.ItemUpgrade = param.ItemUpgrade.ItemType; ObjectUpgrade <ItemType> upgrade = new ObjectUpgrade <ItemType>(param.ItemUpgrade.ItemType, param.ItemUpgrade.RemainingWorkload); itemUpgrades.Add(upgrade); } if (param.Mercenaries != null) { result.AvailableMercenary = new List <MercenaryIdentity>(); foreach (MercenaryParameter mercenary in param.Mercenaries) { result.AvailableMercenary.Add(new MercenaryIdentity(mercenary.MercenaryType, mercenary.MercenaryNO)); mercenaries.Add(new MercenaryIdentity(mercenary.MercenaryType, mercenary.MercenaryNO), this.GenerateMercenaryData(mercenary, id)); } } if (param.MercenaryProducts != null) { Dictionary <MercenaryType, MercenaryProductData> dict = new Dictionary <MercenaryType, MercenaryProductData>(); foreach (MercenaryProductParameter mercenaryProduct in param.MercenaryProducts) { MercenaryProductData data = new MercenaryProductData(); data.ReadyNumber = mercenaryProduct.Number; data.RemainingTime = mercenaryProduct.RemainingSecond; data.ConfigData = ConfigInterface.Instance.MercenaryConfigHelper.GetMercenaryData(mercenaryProduct.MercenaryType); dict.Add(mercenaryProduct.MercenaryType, data); } result.ProduceMercenary = new MercenaryProductCollectionLogicObject(dict); } if (param.ResourceAccelerate != null) { result.RemainResourceAccelerateTime = param.ResourceAccelerate.RemainingTime; } if (param.ArmyAccelerate != null) { result.RemainArmyAccelerateTime = param.ArmyAccelerate.RemainingTime; } if (param.ItemAccelerate != null) { result.RemainItemAccelerateTime = param.ItemAccelerate.RemainingTime; } return(result); }
public void DestroyBuilding(TilePosition position, BuildingConfigData configData) { this.PopulateMapData(position, configData.BuildingObstacleList, null); }