public void IncreaseStolenResourceCount(LogicResourceData data, int count) { if (this.m_level != null) { this.m_level.GetAchievementManager().IncreaseLoot(data, count); } int idx = -1; for (int i = 0; i < this.m_lootCount.Size(); i++) { if (this.m_lootCount[i].GetData() == data) { idx = i; break; } } if (idx != -1) { this.m_lootCount[idx].SetCount(this.m_lootCount[idx].GetCount() + count); } else { this.m_lootCount.Add(new LogicDataSlot(data, count)); } }
public override void ResourcesStolen(int damage, int hp) { if (damage > 0 && hp > 0) { LogicDataTable table = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < this.m_stealableResourceCount.Size(); i++) { LogicResourceData data = (LogicResourceData)table.GetItemAt(i); int stealableResource = this.GetStealableResourceCount(i); if (damage < hp) { stealableResource = damage * stealableResource / hp; } if (stealableResource > 0 && data.GetWarResourceReferenceData() != null) { this.m_parent.GetLevel().GetBattleLog().IncreaseStolenResourceCount(data.GetWarResourceReferenceData(), stealableResource); this.m_resourceCount[i] -= stealableResource; LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar(); homeOwnerAvatar.CommodityCountChangeHelper(0, data, -stealableResource); visitorAvatar.CommodityCountChangeHelper(0, data.GetWarResourceReferenceData(), stealableResource); this.m_stealableResourceCount[i] = LogicMath.Max(this.m_stealableResourceCount[i] - stealableResource, 0); } } } }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (this.m_unitData != null) { LogicUnitUpgradeComponent unitUpgradeComponent = building.GetUnitUpgradeComponent(); if (unitUpgradeComponent != null && unitUpgradeComponent.CanStartUpgrading(this.m_unitData)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); int upgradeLevel = playerAvatar.GetUnitUpgradeLevel(this.m_unitData); int upgradeCost = this.m_unitData.GetUpgradeCost(upgradeLevel); LogicResourceData upgradeResourceData = this.m_unitData.GetUpgradeResource(upgradeLevel); if (playerAvatar.HasEnoughResources(upgradeResourceData, upgradeCost, true, this, false)) { playerAvatar.CommodityCountChangeHelper(0, upgradeResourceData, -upgradeCost); unitUpgradeComponent.StartUpgrading(this.m_unitData); return(0); } } } } return(-1); }
public void ReengageLootCart(int secs) { LogicObstacleData obstacleData = this.GetObstacleData(); LogicLootCartComponent lootCartComponent = (LogicLootCartComponent)this.GetComponent(LogicComponentType.LOOT_CART); LogicBuilding townHall = this.m_level.GetGameObjectManagerAt(0).GetTownHall(); Debugger.DoAssert(obstacleData.IsLootCart(), string.Empty); Debugger.DoAssert(lootCartComponent != null, string.Empty); Debugger.DoAssert(townHall != null, string.Empty); LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHall.GetUpgradeLevel()); int cap = secs * townhallLevelData.GetCartLootReengagement(resourceData) / 100; if (cap > lootCartComponent.GetResourceCount(i)) { lootCartComponent.SetResourceCount(i, cap); } } }
public override void ReadFromJSON(LogicJSONObject jsonObject) { base.ReadFromJSON(jsonObject); this.m_resourceData = (LogicResourceData)LogicJSONHelper.GetLogicData(jsonObject, "resource"); this.m_resourceAmount = LogicJSONHelper.GetInt(jsonObject, "resourceAmount"); }
public void AddResources(LogicResourceData data, int count) { LogicDeliverableResource instance = null; for (int i = 0; i < this.m_deliverables.Size(); i++) { LogicDeliverable deliverable = this.m_deliverables[i]; if (deliverable.GetDeliverableType() == 1) { LogicDeliverableResource deliverableResource = (LogicDeliverableResource)deliverable; if (deliverableResource.GetResourceData() == data) { instance = deliverableResource; break; } } } if (instance != null) { instance.SetResourceAmount(instance.GetResourceAmount() + count); } else { LogicDeliverableResource deliverableResource = new LogicDeliverableResource(); deliverableResource.SetResourceData(data); deliverableResource.SetResourceAmount(count); this.m_deliverables.Add(deliverableResource); } }
public override void Decode(ByteStream stream) { this.m_buyResourceData = (LogicResourceData)ByteStreamHelper.ReadDataReference(stream, LogicDataType.RESOURCE); this.m_buyResourceCount = stream.ReadVInt(); base.Decode(stream); }
public override void ReadFromJSON(LogicJSONObject jsonObject) { base.ReadFromJSON(jsonObject); this.m_scaledResourceData = (LogicResourceData)LogicJSONHelper.GetLogicData(jsonObject, "scaledResource"); this.m_scaledResourceMultiplier = LogicJSONHelper.GetInt(jsonObject, "scaledResourceMultiplier"); }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (building.IsLocked()) { if (building.GetUpgradeLevel() == 0 && building.CanUnlock(true)) { LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.GetConstructionTime(0, level, 0) == 0 || level.HasFreeWorkers(this, -1)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResource = buildingData.GetBuildResource(0); int buildCost = buildingData.GetBuildCost(0, level); if (playerAvatar.HasEnoughResources(buildResource, buildCost, true, this, false)) { playerAvatar.CommodityCountChangeHelper(0, buildResource, -buildCost); building.StartConstructing(true); building.GetListener().RefreshState(); return(0); } } } } } return(-1); }
/// <summary> /// Called when the mission is finished. /// </summary> public void Finished() { LogicClientAvatar playerAvatar = this._level.GetPlayerAvatar(); if (!playerAvatar.IsMissionCompleted(this._data)) { Debugger.Print("Mission " + this._data.GetName() + " finished"); playerAvatar.SetMissionCompleted(this._data, true); playerAvatar.GetChangeListener().CommodityCountChanged(0, this._data.GetRewardResourceData(), 1); this.AddRewardUnits(); LogicResourceData rewardResourceData = this._data.GetRewardResourceData(); if (rewardResourceData != null) { playerAvatar.AddMisisonResourceReward(rewardResourceData, this._data.GetRewardResourceCount()); } int rewardXp = this._data.GetRewardXp(); if (rewardXp > 0) { playerAvatar.XpGainHelper(rewardXp); } } }
/// <summary> /// Initializes a new instance of the <see cref="LogicBuyResourcesCommand" /> class. /// </summary> public LogicBuyResourcesCommand(LogicResourceData data, int resourceCount, LogicResourceData resource2Data, int resource2Count, LogicCommand resourceCommand) { this._resourceData = data; this._resource2Data = resource2Data; this._command = resourceCommand; this._resourceCount = resourceCount; this._resource2Count = resource2Count; }
public override int Execute(LogicLevel level) { if (this.m_decoData != null) { if (this.m_decoData.GetVillageType() == level.GetVillageType()) { if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, this.m_decoData.GetWidth(), this.m_decoData.GetHeight(), null)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResourceData = this.m_decoData.GetBuildResource(); int buildCost = this.m_decoData.GetBuildCost(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false) && !level.IsDecoCapReached(this.m_decoData, true)) { if (buildResourceData.IsPremiumCurrency()) { playerAvatar.UseDiamonds(buildCost); playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_decoData.GetGlobalID(), 0, buildCost, level.GetVillageType()); } else { playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); } LogicDeco deco = (LogicDeco)LogicGameObjectFactory.CreateGameObject(this.m_decoData, level, level.GetVillageType()); deco.SetInitialPosition(this.m_x << 9, this.m_y << 9); level.GetGameObjectManager().AddGameObject(deco, -1); int width = deco.GetWidthInTiles(); int height = deco.GetHeightInTiles(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { LogicObstacle tallGrass = level.GetTileMap().GetTile(this.m_x + i, this.m_y + j).GetTallGrass(); if (tallGrass != null) { level.GetGameObjectManager().RemoveGameObject(tallGrass); } } } return(0); } } return(-1); } return(-32); } return(-1); }
public override int Execute(LogicLevel level) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicGameObjectManager gameObjectManager = level.GetGameObjectManager(); LogicResourceData repairResourceData = null; int repairCost = 0; for (int i = 0; i < this.m_gameObjectIds.Size(); i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.IsDisarmed() && !trap.IsConstructing()) { LogicTrapData data = trap.GetTrapData(); repairResourceData = data.GetBuildResource(); repairCost += data.GetRearmCost(trap.GetUpgradeLevel()); } } } if (repairResourceData != null && repairCost != 0) { if (playerAvatar.HasEnoughResources(repairResourceData, repairCost, true, this, false)) { playerAvatar.CommodityCountChangeHelper(0, repairResourceData, -repairCost); for (int i = 0; i < this.m_gameObjectIds.Size(); i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.IsDisarmed() && !trap.IsConstructing()) { trap.RepairTrap(); } } } return(0); } return(-2); } return(-1); }
public override int Execute(LogicLevel level) { if (level.GetVillageType() == 1) { if (this.m_gameObjectId != 0) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(1); LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (this.m_unitData != null && level.GetGameMode().GetCalendar().IsProductionEnabled(this.m_unitData)) { if (this.m_unitData.GetVillageType() == 1) { LogicVillage2UnitComponent village2UnitComponent = building.GetVillage2UnitComponent(); if (village2UnitComponent != null) { if (this.m_unitData.IsUnlockedForProductionHouseLevel(gameObjectManager.GetHighestBuildingLevel(this.m_unitData.GetProductionHouseData(), true)) ) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData trainResource = this.m_unitData.GetTrainingResource(); int trainCost = this.m_unitData.GetTrainingCost(playerAvatar.GetUnitUpgradeLevel(this.m_unitData)); if (playerAvatar.HasEnoughResources(trainResource, trainCost, true, this, false)) { village2UnitComponent.TrainUnit(this.m_unitData); playerAvatar.CommodityCountChangeHelper(0, trainResource, -trainCost); } return(0); } return(-7); } return(-4); } return(-8); } } return(-5); } return(-1); } return(-10); }
public int GetStolenResources(LogicResourceData data) { for (int i = 0; i < this.m_lootCount.Size(); i++) { if (this.m_lootCount[i].GetData() == data) { return(this.m_lootCount[i].GetCount()); } } return(0); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { int villageType = level.GetVillageType(); if (this._buildingData.GetVillageType() == villageType) { if (this._buildingData.GetBuildingClass().CanBuy) { if (level.IsValidPlaceForBuilding(this._x, this._y, this._buildingData.GetWidth(), this._buildingData.GetHeight(), null)) { if (!level.IsBuildingCapReached(this._buildingData, true)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResourceData = this._buildingData.GetBuildResource(0); int buildResourceCost = this._buildingData.GetBuildCost(0, level); if (playerAvatar.HasEnoughResources(buildResourceData, buildResourceCost, true, this, false)) { if (this._buildingData.IsWorkerBuilding() || this._buildingData.GetConstructionTime(0, level, 0) <= 0 && !LogicDataTables.GetGlobals().WorkerForZeroBuilTime() || level.HasFreeWorkers(this, -1)) { if (buildResourceData.PremiumCurrency) { playerAvatar.UseDiamonds(buildResourceCost); } else { playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildResourceCost); } LogicBuilding building = (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this._buildingData, level, villageType); building.SetPositionXY(this._x << 9, this._y << 9); level.GetGameObjectManager().AddGameObject(building, -1); building.StartConstructing(false); if (this._buildingData.IsWall() && level.IsBuildingCapReached(this._buildingData, false)) { level.GetGameListener().BuildingCapReached(this._buildingData); } } } return(0); } } } return(-33); } return(-32); }
/// <summary> /// Destructs this instance. /// </summary> public override void Destruct() { base.Destruct(); if (this._command != null) { this._command.Destruct(); this._command = null; } this._resourceData = null; this._resource2Data = null; }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (building.CanSell()) { playerAvatar.CommodityCountChangeHelper(0, building.GetSellResource(), building.GetSellPrice()); building.OnSell(); level.GetGameObjectManager().RemoveGameObject(building); return(0); } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.DECO) { LogicDeco deco = (LogicDeco)gameObject; LogicDecoData data = deco.GetDecoData(); LogicResourceData buildResourceData = data.GetBuildResource(); int sellPrice = data.GetSellPrice(); if (buildResourceData.IsPremiumCurrency()) { playerAvatar.SetDiamonds(playerAvatar.GetDiamonds() + sellPrice); playerAvatar.SetFreeDiamonds(playerAvatar.GetFreeDiamonds() + sellPrice); playerAvatar.GetChangeListener().FreeDiamondsAdded(sellPrice, 6); } else { playerAvatar.CommodityCountChangeHelper(0, buildResourceData, sellPrice); } level.GetGameObjectManager().RemoveGameObject(deco); return(0); } } return(-1); }
public void IncreaseLoot(LogicResourceData resourceData, int count) { LogicDataTable table = LogicDataTables.GetTable(LogicDataType.ACHIEVEMENT); LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar(); for (int i = 0; i < table.GetItemCount(); i++) { LogicAchievementData data = (LogicAchievementData)table.GetItemAt(i); if (data.GetActionType() == LogicAchievementData.ACTION_TYPE_LOOT && data.GetResourceData() == resourceData) { this.RefreshAchievementProgress(playerAvatar, data, playerAvatar.GetAchievementProgress(data) + count); } } }
/// <summary> /// Trains the unit with new training. /// </summary> public int NewTrainingUnit(LogicLevel level) { if (LogicDataTables.GetGlobals().UseNewTraining()) { if (this._unitData != null) { LogicUnitProduction unitProduction = this._unitData.GetCombatItemType() == 1 ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction(); if (!unitProduction.IsLocked()) { if (this._unitCount > 0) { if (this._unitData.GetDataType() == unitProduction.GetUnitProductionType()) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData trainingResourceData = this._unitData.GetTrainingResource(); Int32 trainingCost = level.GetGameMode().GetCalendar().GetUnitTrainingCost(this._unitData, playerAvatar.GetUnitUpgradeLevel(this._unitData)); Int32 refundCount = LogicMath.Max(trainingCost * (this._unitData.GetDataType() != 3 ? LogicDataTables.GetGlobals().GetSpellCancelMultiplier() : LogicDataTables.GetGlobals().GetTrainCancelMultiplier()) / 100, 0); while (unitProduction.RemoveUnit(this._unitData, this._slotId)) { playerAvatar.CommodityCountChangeHelper(0, trainingResourceData, refundCount); if (--this._unitCount <= 0) { break; } } return(0); } } return(-1); } return(-23); } return(-1); } return(-99); }
public int GetResourceCost(LogicResourceData resourceData) { int cost = 0; LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); LogicCalendar calendar = this.m_level.GetCalendar(); LogicDataTable table = LogicDataTables.GetTable(LogicDataType.CHARACTER); for (int i = 0; i < table.GetItemCount(); i++) { LogicCharacterData data = (LogicCharacterData)table.GetItemAt(i); if (calendar.IsProductionEnabled(data) && !data.IsSecondaryTroop()) { int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId); if (count > 0) { if (data.GetTrainingResource() == resourceData) { cost += count * calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data)); } } } } table = LogicDataTables.GetTable(LogicDataType.SPELL); for (int i = 0; i < table.GetItemCount(); i++) { LogicSpellData data = (LogicSpellData)table.GetItemAt(i); if (calendar.IsProductionEnabled(data)) { int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId); if (count > 0) { if (data.GetTrainingResource() == resourceData) { cost += count * calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data)); } } } } return(cost); }
public virtual void ResourcesStolen(int damage, int hp) { if (damage > 0 && hp > 0) { LogicDataTable table = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < this.m_stealableResourceCount.Size(); i++) { LogicResourceData data = (LogicResourceData)table.GetItemAt(i); int stealableResource = this.GetStealableResourceCount(i); if (damage < hp) { stealableResource = damage * stealableResource / hp; } if (stealableResource > 0) { this.m_parent.GetLevel().GetBattleLog().IncreaseStolenResourceCount(data, stealableResource); this.m_resourceCount[i] -= stealableResource; LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar(); homeOwnerAvatar.CommodityCountChangeHelper(0, data, -stealableResource); visitorAvatar.CommodityCountChangeHelper(0, data, stealableResource); if (homeOwnerAvatar.IsNpcAvatar()) { LogicNpcData npcData = ((LogicNpcAvatar)homeOwnerAvatar).GetNpcData(); if (data == LogicDataTables.GetGoldData()) { visitorAvatar.CommodityCountChangeHelper(1, npcData, stealableResource); } else if (data == LogicDataTables.GetElixirData()) { visitorAvatar.CommodityCountChangeHelper(2, npcData, stealableResource); } } this.m_stealableResourceCount[i] = LogicMath.Max(this.m_stealableResourceCount[i] - stealableResource, 0); } } } }
public int CollectResources() { int collected = -1; if (this.m_parent.GetLevel().GetHomeOwnerAvatar().IsClientAvatar()) { collected = 0; LogicClientAvatar playerAvatar = (LogicClientAvatar)this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicDataTable table = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < table.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)table.GetItemAt(i); if (data.GetWarResourceReferenceData() != null) { int count = playerAvatar.GetResourceCount(data); if (count > 0) { int unusedResourceCap = playerAvatar.GetUnusedResourceCap(data.GetWarResourceReferenceData()); if (unusedResourceCap != 0) { if (count > unusedResourceCap) { count = unusedResourceCap; } if (data.GetName().Equals("WarGold")) { this.m_parent.GetLevel().GetAchievementManager().IncreaseWarGoldResourceLoot(count); } collected = count; playerAvatar.CommodityCountChangeHelper(0, data.GetWarResourceReferenceData(), count); playerAvatar.CommodityCountChangeHelper(0, data, -count); } } } } } return(collected); }
public void DivideAvatarResourcesToStorages() { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null) { LogicArrayList <LogicComponent> resourceStorageComponents = this.m_components[(int)LogicComponentType.RESOURCE_STORAGE]; LogicArrayList <LogicComponent> warResourceStorageComponents = this.m_components[(int)LogicComponentType.WAR_RESOURCE_STORAGE]; LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); if (!data.IsPremiumCurrency()) { if (data.GetWarResourceReferenceData() != null) { Debugger.DoAssert(warResourceStorageComponents.Size() < 2, "Too many war storage components"); for (int j = 0; j < warResourceStorageComponents.Size(); j++) { LogicWarResourceStorageComponent warResourceStorageComponent = (LogicWarResourceStorageComponent)warResourceStorageComponents[j]; warResourceStorageComponent.SetCount(i, homeOwnerAvatar.GetResourceCount(data)); } } else { for (int j = 0; j < resourceStorageComponents.Size(); j++) { ((LogicResourceStorageComponent)resourceStorageComponents[j]).SetCount(i, 0); } int resourceCount = homeOwnerAvatar.GetResourceCount(data); if (this.m_level.GetBattleLog() != null && data.GetVillageType() == 1) { resourceCount = LogicMath.Max(resourceCount - this.m_level.GetBattleLog().GetCostCount(data), 0); } this.AddResources(i, resourceCount, true); } } } } }
public override void Decode(ByteStream stream) { this.m_resourceCount = stream.ReadInt(); this.m_resourceData = (LogicResourceData)ByteStreamHelper.ReadDataReference(stream, LogicDataType.RESOURCE); this.m_resource2Count = stream.ReadInt(); if (this.m_resource2Count > 0) { this.m_resource2Data = (LogicResourceData)ByteStreamHelper.ReadDataReference(stream, LogicDataType.RESOURCE); } if (stream.ReadBoolean()) { this.m_command = LogicCommandManager.DecodeCommand(stream); } base.Decode(stream); }
/// <summary> /// Decodes this instnace. /// </summary> public override void Decode(ByteStream stream) { this._resourceCount = stream.ReadInt(); this._resourceData = (LogicResourceData)stream.ReadDataReference(2); this._resource2Count = stream.ReadInt(); if (this._resource2Count > 0) { this._resource2Data = (LogicResourceData)stream.ReadDataReference(2); } if (stream.ReadBoolean()) { this._command = LogicCommandManager.DecodeCommand(stream); } base.Decode(stream); }
public override int Execute(LogicLevel level) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { if (this.m_allianceCreate) { LogicGlobals globals = LogicDataTables.GetGlobals(); LogicResourceData resource = globals.GetAllianceCreateResourceData(); int removeCount = LogicMath.Min(globals.GetAllianceCreateCost(), playerAvatar.GetResourceCount(resource)); playerAvatar.CommodityCountChangeHelper(0, resource, -removeCount); } playerAvatar.SetAllianceId(this.m_allianceId.Clone()); playerAvatar.SetAllianceName(this.m_allianceName); playerAvatar.SetAllianceBadgeId(this.m_allianceBadgeId); playerAvatar.SetAllianceLevel(this.m_allianceExpLevel); playerAvatar.SetAllianceRole(this.m_allianceCreate ? LogicAvatarAllianceRole.LEADER : LogicAvatarAllianceRole.MEMBER); playerAvatar.GetChangeListener().AllianceJoined(playerAvatar.GetAllianceId(), this.m_allianceName, this.m_allianceBadgeId, this.m_allianceExpLevel, playerAvatar.GetAllianceRole()); LogicGameListener gameListener = level.GetGameListener(); if (gameListener != null) { if (this.m_allianceCreate) { gameListener.AllianceCreated(); } else { gameListener.AllianceJoined(); } } return(0); } return(-1); }
/// <summary> /// Cancels the construction of trap. /// </summary> public void CancelConstruction() { LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar()) { if (this._constructionTimer != null) { this._constructionTimer.Destruct(); this._constructionTimer = null; int upgLevel = this._upgLevel; if (this._upgrading) { this.SetUpgradeLevel(this._upgLevel); upgLevel += 1; } LogicTrapData data = this.GetTrapData(); LogicResourceData buildResourceData = data.GetBuildResource(); Int32 buildCost = data.GetBuildCost(upgLevel); Int32 refundedCount = LogicMath.Max(LogicDataTables.GetGlobals().GetBuildCancelMultiplier() * buildCost / 100, 0); Debugger.Print("LogicTrap::cancelConstruction refunds: " + refundedCount); homeOwnerAvatar.CommodityCountChangeHelper(0, buildResourceData, refundedCount); this._level.GetWorkerManagerAt(this._data.GetVillageType()).DeallocateWorker(this); if (upgLevel != 0) { if (this._listener != null) { this._listener.RefreshState(); } } else { this.GetGameObjectManager().RemoveGameObject(this); } } } }
public bool IsNotEmpty() { LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicDataTable table = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < table.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)table.GetItemAt(i); if (data.GetWarResourceReferenceData() != null) { if (homeOwnerAvatar.GetResourceCount(data) > 0) { return(true); } } } return(false); }
public override void Save(LogicJSONObject jsonObject, int villageType) { LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null) { if (LogicDataTables.GetGoldData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defg", new LogicJSONNumber(count)); } } else if (LogicDataTables.GetElixirData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defe", new LogicJSONNumber(count)); } } else if (LogicDataTables.GetDarkElixirData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defde", new LogicJSONNumber(count)); } } } } }