public override void Save(LogicJSONObject jsonObject, int villageType) { LogicJSONArray unitArray = new LogicJSONArray(); for (int i = 0; i < this.m_slots.Size(); i++) { LogicUnitSlot slot = this.m_slots[i]; if (slot.GetData() != null && slot.GetCount() > 0) { if (slot.GetLevel() != -1) { Debugger.Error("Invalid unit level."); } LogicJSONArray unitObject = new LogicJSONArray(2); unitObject.Add(new LogicJSONNumber(slot.GetData().GetGlobalID())); unitObject.Add(new LogicJSONNumber(slot.GetCount())); unitArray.Add(unitObject); } } jsonObject.Put("units", unitArray); }
/// <summary> /// Gets the unit count by data. /// </summary> public int GetUnitCountByData(LogicCombatItemData data) { int count = 0; for (int i = 0; i < this._slots.Count; i++) { LogicUnitSlot unitSlot = this._slots[i]; if (unitSlot.GetData() == data) { count += unitSlot.GetCount(); } } return(count); }
public static LogicJSONArray UnitSlotArrayToJSONArray(LogicArrayList <LogicUnitSlot> dataSlotArray) { LogicJSONArray jsonArray = new LogicJSONArray(dataSlotArray.Size()); for (int i = 0; i < dataSlotArray.Size(); i++) { LogicUnitSlot unitSlot = dataSlotArray[i]; LogicJSONArray objectArray = new LogicJSONArray(); objectArray.Add(new LogicJSONNumber(unitSlot.GetData().GetGlobalID())); objectArray.Add(new LogicJSONNumber(unitSlot.GetLevel())); objectArray.Add(new LogicJSONNumber(unitSlot.GetCount())); jsonArray.Add(objectArray); } return(jsonArray); }
public void AddAvatarAllianceUnitsToCastle() { LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0); LogicBuilding allianceCastle = gameObjectManager.GetAllianceCastle(); if (allianceCastle != null) { LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent(); if (bunkerComponent != null) { bunkerComponent.RemoveAllUnits(); LogicArrayList <LogicUnitSlot> units = this.m_level.GetHomeOwnerAvatar().GetAllianceUnits(); for (int i = 0; i < units.Size(); i++) { LogicUnitSlot unitSlot = units[i]; LogicCombatItemData data = (LogicCombatItemData)unitSlot.GetData(); int count = unitSlot.GetCount(); if (data != null) { if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { for (int j = 0; j < count; j++) { if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace()) { bunkerComponent.AddUnitImpl(data, unitSlot.GetLevel()); } } } } else { Debugger.Error("LogicComponentManager::addAvatarAllianceUnitsToCastle - NULL character"); } } } } }
public override int Execute(LogicLevel level) { if (level.IsReadyForAttack()) { if (level.GetVillageType() == 0) { if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles()) { if (!level.GetTileMap().IsValidAttackPos(this.m_x >> 9, this.m_y >> 9)) { return(-2); } } else { LogicTile tile = level.GetTileMap().GetTile(this.m_x >> 9, this.m_y >> 9); if (tile == null) { return(-4); } if (tile.GetPassableFlag() == 0) { return(-3); } } LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { if (this.m_data != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); if (gameObjectManager.GetGameObjectCountByData(this.m_data) <= 0 && playerAvatar.GetAllianceCastleUsedCapacity() > 0) { LogicAlliancePortal alliancePortal = (LogicAlliancePortal)LogicGameObjectFactory.CreateGameObject(this.m_data, level, level.GetVillageType()); LogicBunkerComponent bunkerComponent = alliancePortal.GetBunkerComponent(); alliancePortal.SetInitialPosition(this.m_x, this.m_y); if (bunkerComponent != null) { bunkerComponent.SetMaxCapacity(playerAvatar.GetAllianceCastleTotalCapacity()); if (level.GetBattleLog() != null) { if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0) { level.UpdateLastUsedArmy(); } } if (level.GetGameMode().IsInAttackPreparationMode()) { level.GetGameMode().EndAttackPreparation(); } bunkerComponent.RemoveAllUnits(); LogicArrayList <LogicUnitSlot> allianceUnits = playerAvatar.GetAllianceUnits(); for (int i = 0; i < allianceUnits.Size(); i++) { LogicUnitSlot slot = allianceUnits[i]; LogicCombatItemData data = (LogicCombatItemData)slot.GetData(); if (data != null) { int count = slot.GetCount(); if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { for (int j = 0; j < count; j++) { if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace()) { bunkerComponent.AddUnitImpl(data, slot.GetLevel()); } } } } else { Debugger.Error("LogicPlaceAlliancePortalCommand::execute - NULL alliance character"); } } } gameObjectManager.AddGameObject(alliancePortal, -1); return(0); } } } return(-5); } } return(-1); }