/// <summary> /// Starts the upgrading of the trap. /// </summary> public void StartUpgrading() { if (this._constructionTimer != null) { this._constructionTimer.Destruct(); this._constructionTimer = null; } LogicTrapData data = this.GetTrapData(); this._upgrading = true; int buildTime = data.GetBuildTime(this._upgLevel + 1); if (buildTime <= 0) { this.FinishConstruction(false); } else { this._level.GetWorkerManagerAt(data.GetVillageType()).AllocateWorker(this); this._constructionTimer = new LogicTimer(); this._constructionTimer.StartTimer(buildTime, this._level.GetLogicTime(), true, this._level.GetGameMode().GetCurrentTimestamp()); } }
public void LoadUpgradeLevel(LogicJSONObject jsonObject) { LogicJSONNumber lvlObject = jsonObject.GetJSONNumber("lvl"); LogicTrapData data = this.GetTrapData(); if (lvlObject != null) { this.m_upgLevel = lvlObject.GetIntValue(); int maxLvl = data.GetUpgradeLevelCount(); if (this.m_upgLevel >= maxLvl) { Debugger.Warning(string.Format("LogicTrap::load() - Loaded upgrade level {0} is over max! (max = {1}) id {2} data id {3}", lvlObject.GetIntValue(), maxLvl, this.m_globalId, data.GetGlobalID())); this.m_upgLevel = maxLvl - 1; } else { if (this.m_upgLevel < -1) { Debugger.Error("LogicTrap::load() - Loaded an illegal upgrade level!"); } } } }
/// <summary> /// Sets the upgrade level. /// </summary> public void SetUpgradeLevel(int upgLevel) { LogicTrapData data = this.GetTrapData(); this._upgLevel = LogicMath.Min(upgLevel, data.GetUpgradeLevelCount()); this._numSpawns = data.GetNumSpawns(upgLevel); }
public void SetUpgradeLevel(int upgLevel) { LogicTrapData data = this.GetTrapData(); this.m_upgLevel = LogicMath.Clamp(upgLevel, 0, data.GetUpgradeLevelCount() - 1); this.m_numSpawns = data.GetNumSpawns(this.m_upgLevel); }
private static bool CanUpgradeTHV2(LogicLevel level) { if (level.GetVillageType() == 1) { LogicDataTable buildingTable = LogicDataTables.GetTable(LogicDataType.BUILDING); for (int i = 0; i < buildingTable.GetItemCount(); i++) { LogicBuildingData buildingData = (LogicBuildingData)buildingTable.GetItemAt(i); if (buildingData.GetVillageType() == 1 && !level.IsBuildingCapReached(buildingData, false)) { return(false); } } LogicDataTable trapTable = LogicDataTables.GetTable(LogicDataType.TRAP); for (int i = 0; i < trapTable.GetItemCount(); i++) { LogicTrapData trapData = (LogicTrapData)trapTable.GetItemAt(i); if (trapData.GetVillageType() == 1 && !level.IsTrapCapReached(trapData, false)) { return(false); } } return(true); } return(false); }
/// <summary> /// Decodes this instnace. /// </summary> public override void Decode(ByteStream stream) { this._x = stream.ReadInt(); this._y = stream.ReadInt(); this._trapData = (LogicTrapData)stream.ReadDataReference(11); base.Decode(stream); }
/// <summary> /// Destructs this instance. /// </summary> public override void Destruct() { base.Destruct(); this._x = 0; this._y = 0; this._trapData = null; }
public override void Decode(ByteStream stream) { this.m_x = stream.ReadInt(); this.m_y = stream.ReadInt(); this.m_trapData = (LogicTrapData)ByteStreamHelper.ReadDataReference(stream, LogicDataType.TRAP); base.Decode(stream); }
/// <summary> /// Initializes a new instance of the <see cref="LogicObstacle" /> class. /// </summary> public LogicTrap(LogicData data, LogicLevel level, int villageType) : base(data, level, villageType) { this.AddComponent(new LogicLayoutComponent(this)); LogicTrapData trapData = (LogicTrapData)data; this._numSpawns = trapData.GetNumSpawns(0); this._spawnInitDelay = trapData.GetSpawnInitialDelayMS() / 64; }
public void CreateProjectile(LogicProjectileData data) { LogicTrapData trapData = this.GetTrapData(); LogicVector2 position = new LogicVector2(); LogicArrayList <LogicGameObject> characters = this.GetGameObjectManager().GetGameObjects(LogicGameObjectType.CHARACTER); LogicGameObject closestGameObject = null; for (int i = 0, minDistance = 0; i < characters.Size(); i++) { LogicCharacter character = (LogicCharacter)characters[i]; LogicHitpointComponent hitpointComponent = character.GetHitpointComponent(); if (hitpointComponent != null && hitpointComponent.GetTeam() == 0) { if (character.IsFlying() && character.IsAlive()) { int housingSpace = character.GetCharacterData().GetHousingSpace(); if (housingSpace >= trapData.GetMinTriggerHousingLimit() && character.GetChildTroops() == null) { if (trapData.GetHealerTrigger() || character.GetCombatComponent() == null || !character.GetCombatComponent().IsHealer()) { position.m_x = character.GetPosition().m_x - this.GetMidX(); position.m_y = character.GetPosition().m_y - this.GetMidY(); int lengthSquared = position.GetLengthSquared(); if (minDistance == 0 || lengthSquared < minDistance) { minDistance = lengthSquared; closestGameObject = character; } } } } } } position.Destruct(); if (closestGameObject != null) { LogicProjectile projectile = (LogicProjectile)LogicGameObjectFactory.CreateGameObject(data, this.m_level, this.m_villageType); projectile.SetInitialPosition(null, this.GetMidX(), this.GetMidY()); projectile.SetTarget(this.GetMidX(), this.GetMidY(), 0, closestGameObject, data.GetRandomHitPosition()); projectile.SetDamage(trapData.GetDamage(this.m_upgLevel)); projectile.SetDamageRadius(trapData.GetDamageRadius(this.m_upgLevel)); projectile.SetPushBack(trapData.GetPushback(), !trapData.GetDoNotScalePushByDamage()); projectile.SetMyTeam(1); projectile.SetHitEffect(trapData.GetDamageEffect(), null); this.GetGameObjectManager().AddGameObject(projectile, -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); }
/// <summary> /// Gets if this <see cref="LogicTrap"/> is maxed. /// </summary> public bool IsMaxUpgradeLevel() { LogicTrapData trapData = this.GetTrapData(); if (trapData.GetVillageType() != 1 || this.GetRequiredTownHallLevelForUpgrade() < this._level.GetGameMode().GetConfiguration().GetMaxTownHallLevel() - 1) { return(this._upgLevel >= trapData.GetUpgradeLevelCount() - 1); } return(true); }
public bool HasAirMode() { LogicTrapData data = (LogicTrapData)this.m_data; if (data.GetSpawnedCharAir() == null || data.GetSpawnedCharGround() == null) { return(data.HasAlternativeMode()); } return(true); }
public override void SaveToSnapshot(LogicJSONObject jsonObject, int layoutId) { if (this.m_upgLevel != 0 || this.m_constructionTimer == null || this.m_upgrading) { jsonObject.Put("lvl", new LogicJSONNumber(this.m_upgLevel)); } else { jsonObject.Put("lvl", new LogicJSONNumber(-1)); } if (this.m_constructionTimer != null) { jsonObject.Put("const_t", new LogicJSONNumber(this.m_constructionTimer.GetRemainingSeconds(this.m_level.GetLogicTime()))); } LogicTrapData data = this.GetTrapData(); if (data.HasAlternativeMode() || data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null) { LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT); if (layoutComponent != null) { for (int i = 0; i < 8; i++) { jsonObject.Put(layoutComponent.GetLayoutVariableNameAirMode(i, false), new LogicJSONBoolean(this.m_useAirMode[i])); } } } if (data.GetDirectionCount() > 0) { LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT); if (layoutComponent != null) { for (int i = 0; i < 8; i++) { jsonObject.Put(layoutComponent.GetLayoutVariableNameTrapDirection(i, false), new LogicJSONNumber(this.m_direction[i])); } } } base.SaveToSnapshot(jsonObject, layoutId); }
public static void Init() { GameBaseGenerator.HomeOwnerAvatar = new LogicClientAvatar(); GameBaseGenerator.HomeOwnerAvatar.SetName("Supercell - Private CoC Server"); GameBaseGenerator.HomeOwnerAvatar.SetExpLevel(500); GameBaseGenerator.HomeOwnerAvatar.SetScore(5000); GameBaseGenerator.HomeOwnerAvatar.SetLeagueType(LogicDataTables.GetTable(LogicDataType.LEAGUE).GetItemCount() - 1); GameBaseGenerator.m_random = new LogicRandom(Environment.TickCount); GameBaseGenerator.m_defenseBuildingArray = new LogicArrayList <LogicBuildingData>(); GameBaseGenerator.m_otherBuildingArray = new LogicArrayList <LogicBuildingData>(); GameBaseGenerator.m_trapArray = new LogicArrayList <LogicTrapData>(); LogicDataTable buildingTable = LogicDataTables.GetTable(LogicDataType.BUILDING); LogicDataTable trapTable = LogicDataTables.GetTable(LogicDataType.TRAP); for (int i = 0; i < buildingTable.GetItemCount(); i++) { LogicBuildingData buildingData = (LogicBuildingData)buildingTable.GetItemAt(i); if (buildingData.IsEnabledInVillageType(0)) { if (buildingData.GetBuildingClass().GetName() == "Defense") { GameBaseGenerator.m_defenseBuildingArray.Add(buildingData); } else { GameBaseGenerator.m_otherBuildingArray.Add(buildingData); } } } for (int i = 0; i < trapTable.GetItemCount(); i++) { LogicTrapData trapData = (LogicTrapData)trapTable.GetItemAt(i); if (trapData.IsEnabledInVillageType(0)) { GameBaseGenerator.m_trapArray.Add(trapData); } } }
public LogicTrap(LogicGameObjectData data, LogicLevel level, int villageType) : base(data, level, villageType) { this.m_fadeTime = -1; this.m_hitTime = -1; this.m_useAirMode = new bool[8]; this.m_draftUseAirMode = new bool[8]; this.m_direction = new int[8]; this.m_draftDirection = new int[8]; LogicTrapData trapData = (LogicTrapData)data; this.AddComponent(new LogicTriggerComponent(this, trapData.GetTriggerRadius(), trapData.GetAirTrigger(), trapData.GetGroundTrigger(), trapData.GetHealerTrigger(), trapData.GetMinTriggerHousingLimit())); this.AddComponent(new LogicLayoutComponent(this)); this.m_numSpawns = trapData.GetNumSpawns(0); this.m_spawnInitDelay = trapData.GetSpawnInitialDelayMS() / 64; }
/// <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 void SpawnUnit(int count) { LogicTrapData data = this.GetTrapData(); LogicCharacterData spawnData = this.m_useAirMode[this.m_level.GetActiveLayout(this.m_villageType)] ? data.GetSpawnedCharAir() : data.GetSpawnedCharGround(); if (spawnData != null) { LogicVector2 position = new LogicVector2(); for (int i = 0, j = 59, k = 0, l = 0; i < count; i++, j += 59, k += 128, l += 360) { int random = l / data.GetNumSpawns(this.m_upgLevel) + j * this.m_numSpawns % 360; int randomX = (byte)(k & 0x80) ^ 0x180; int posX = this.GetMidX() + LogicMath.GetRotatedX(randomX, 0, random); int posY = this.GetMidY() + LogicMath.GetRotatedY(randomX, 0, random); if (spawnData.IsFlying()) { position.m_x = posX; position.m_y = posY; } else { if (!this.m_level.GetTileMap().GetNearestPassablePosition(posX, posY, position, 1536)) { continue; } } LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnData, this.m_level, this.m_villageType); character.GetHitpointComponent().SetTeam(1); character.GetMovementComponent().EnableJump(3600000); character.SetInitialPosition(position.m_x, position.m_y); character.SetSpawnTime(200); this.GetGameObjectManager().AddGameObject(character, -1); } position.Destruct(); } }
public static float GetTrapStrength(LogicTrapData data, int upgLevel) { int damageStrength = data.GetDamage(upgLevel); if (damageStrength == 0) { if (data.GetNumSpawns(upgLevel) != 0) { damageStrength = data.GetNumSpawns(upgLevel); } if (data.GetEjectHousingLimit(upgLevel) != 0) { damageStrength = data.GetEjectHousingLimit(upgLevel); } if (data.GetPushback() != 0) { damageStrength = data.GetPushback(); } } return(damageStrength * 0.014286f * data.GetStrengthWeight(upgLevel)); }
public override void Tick() { base.Tick(); if (this.m_constructionTimer != null) { if (this.m_level.GetRemainingClockTowerBoostTime() > 0 && this.m_data.GetVillageType() == 1) { this.m_constructionTimer.SetFastForward(this.m_constructionTimer.GetFastForward() + 4 * LogicDataTables.GetGlobals().GetClockTowerBoostMultiplier() - 4); } if (this.m_constructionTimer.GetRemainingSeconds(this.m_level.GetLogicTime()) <= 0) { this.FinishConstruction(false); } } if (this.m_disarmed) { if (this.m_fadeTime >= 0) { this.m_fadeTime = LogicMath.Min(this.m_fadeTime + 64, 1000); } } LogicTriggerComponent triggerComponent = this.GetTriggerComponent(); if (triggerComponent.IsTriggered() && !this.m_disarmed && !this.m_upgrading) { LogicTrapData data = this.GetTrapData(); if (this.m_numSpawns > 0) { if (this.m_spawnInitDelay != 0) { this.m_spawnInitDelay -= 1; } else { this.SpawnUnit(1); this.m_numSpawns -= 1; this.m_spawnInitDelay = this.GetTrapData().GetTimeBetweenSpawnsMS() / 64; } } if (this.m_actionTime >= 0) { this.m_actionTime += 64; } if (this.m_hitTime >= 0) { this.m_hitTime += 64; } if (this.m_actionTime > data.GetActionFrame()) { this.m_hitTime = data.GetHitDelayMS(); this.m_actionTime = -1; } else if (this.m_hitTime > data.GetHitDelayMS()) { if (data.GetSpell() != null) { LogicSpell spell = (LogicSpell)LogicGameObjectFactory.CreateGameObject(data.GetSpell(), this.m_level, this.m_villageType); spell.SetUpgradeLevel(0); spell.SetInitialPosition(this.GetMidX(), this.GetMidY()); spell.SetTeam(1); this.GetGameObjectManager().AddGameObject(spell, -1); } else if (data.GetProjectile(this.m_upgLevel) != null) { this.CreateProjectile(data.GetProjectile(this.m_upgLevel)); } else if (data.GetDamageMod() != 0) { this.m_level.AreaBoost(this.GetMidX(), this.GetMidY(), data.GetDamageRadius(this.m_upgLevel), -data.GetSpeedMod(), -data.GetSpeedMod(), data.GetDamageMod(), 0, data.GetDurationMS() / 16, 0, false); } else if (data.GetEjectVictims()) { if (data.GetThrowDistance() <= 0) { this.EjectCharacters(); } else { this.ThrowCharacters(); } } else { bool defaultMode = true; if (data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null || data.HasAlternativeMode()) { int activeLayout = this.m_level.GetActiveLayout(); if (activeLayout <= 7) { defaultMode = this.m_useAirMode[activeLayout] ^ true; } } this.m_level.AreaDamage(0, this.GetMidX(), this.GetMidY(), data.GetDamageRadius(this.m_upgLevel), data.GetDamage(this.m_upgLevel), data.GetPreferredTarget(), data.GetPreferredTargetDamageMod(), data.GetDamageEffect(), 1, null, defaultMode ? 1 : 0, 0, 100, true, false, 100, 0, this, 100, 0); } this.m_hitTime = 0; this.m_hitCount += 1; if (this.m_hitCount >= data.GetHitCount() && this.m_numSpawns == 0) { this.m_fadeTime = 1; this.m_hitTime = -1; this.m_disarmed = true; this.m_numSpawns = data.GetNumSpawns(this.m_upgLevel); this.m_spawnInitDelay = data.GetSpawnInitialDelayMS() / 64; } } } }
public virtual void TrapCapReached(LogicTrapData data) { }
/// <summary> /// Initializes a new instance of the <see cref="LogicBuyTrapCommand" /> class. /// </summary> public LogicBuyTrapCommand(int x, int y, LogicTrapData trapData) { this._x = x; this._y = y; this._trapData = trapData; }
public override void Save(LogicJSONObject jsonObject, int villageType) { if (this.m_upgLevel != 0 || this.m_constructionTimer == null || this.m_upgrading) { jsonObject.Put("lvl", new LogicJSONNumber(this.m_upgLevel)); } else { jsonObject.Put("lvl", new LogicJSONNumber(-1)); } if (this.m_constructionTimer != null) { jsonObject.Put("const_t", new LogicJSONNumber(this.m_constructionTimer.GetRemainingSeconds(this.m_level.GetLogicTime()))); if (this.m_constructionTimer.GetEndTimestamp() != -1) { jsonObject.Put("const_t_end", new LogicJSONNumber(this.m_constructionTimer.GetEndTimestamp())); } if (this.m_constructionTimer.GetFastForward() != -1) { jsonObject.Put("con_ff", new LogicJSONNumber(this.m_constructionTimer.GetFastForward())); } } if (this.m_disarmed && this.GetTrapData().GetVillageType() != 1) { jsonObject.Put("needs_repair", new LogicJSONBoolean(true)); } LogicTrapData data = this.GetTrapData(); if (data.HasAlternativeMode() || data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null) { LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT); if (layoutComponent != null) { for (int i = 0; i < 8; i++) { jsonObject.Put(layoutComponent.GetLayoutVariableNameAirMode(i, false), new LogicJSONBoolean(this.m_useAirMode[i])); jsonObject.Put(layoutComponent.GetLayoutVariableNameAirMode(i, true), new LogicJSONBoolean(this.m_draftUseAirMode[i])); } } } if (data.GetDirectionCount() > 0) { LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT); if (layoutComponent != null) { for (int i = 0; i < 8; i++) { jsonObject.Put(layoutComponent.GetLayoutVariableNameTrapDirection(i, false), new LogicJSONNumber(this.m_direction[i])); jsonObject.Put(layoutComponent.GetLayoutVariableNameTrapDirection(i, true), new LogicJSONNumber(this.m_draftDirection[i])); } } } base.Save(jsonObject, villageType); }
/// <summary> /// Finishes the construction of the <see cref="LogicBuilding"/>. /// </summary> public void FinishConstruction(bool ignoreState) { int state = this._level.GetState(); if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState) { LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar()) { LogicTrapData data = this.GetTrapData(); if (this._constructionTimer != null) { this._constructionTimer.Destruct(); this._constructionTimer = null; } this._level.GetWorkerManagerAt(this._data.GetVillageType()).DeallocateWorker(this); if (this._upgLevel != 0 || this._upgrading) { if (this._upgLevel >= data.GetUpgradeLevelCount() - 1) { Debugger.Warning("LogicTrap - Trying to upgrade to level that doesn't exist! - " + data.GetName()); this._upgLevel = data.GetUpgradeLevelCount() - 1; } else { this._upgLevel += 1; } } if (!ignoreState && !this._disarmed) { if (this.GetListener() != null) { // Listener. } } this.XpGainHelper(LogicGamePlayUtil.TimeToExp(data.GetBuildTime(this._upgLevel)), homeOwnerAvatar, ignoreState); if (this._disarmed) { // Listener. } this._fadeTime = 0; this._disarmed = false; this._upgrading = false; if (this._listener != null) { this._listener.RefreshState(); } if (state == 1) { this._level.GetAchievementManager().RefreshStatus(); } } else { Debugger.Warning("LogicTrap::finishCostruction failed - Avatar is null or not client avatar"); } } }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectId); if (gameObject != null) { if (gameObject.GetGameObjectType() == 0) { LogicBuilding building = (LogicBuilding)gameObject; LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.IsTownHallVillage2()) { if (!this.UnlockVillage2()) { return(-76); } } if (buildingData.GetVillageType() == level.GetVillageType()) { if (building.GetWallIndex() == 0) { if (building.CanUpgrade(true)) { int nextUpgradeLevel = building.GetUpgradeLevel() + 1; int buildCost = buildingData.GetBuildCost(nextUpgradeLevel, level); LogicResourceData buildResourceData = this._useAltResources ? buildingData.GetAltBuildResource(nextUpgradeLevel) : buildingData.GetBuildResource(nextUpgradeLevel); if (buildResourceData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { int constructionTime = buildingData.GetConstructionTime(nextUpgradeLevel, level, 0); if (constructionTime != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); building.StartUpgrading(true, false); return(0); } } } return(-1); } return(-35); } return(-32); } else if (gameObject.GetGameObjectType() == 4) { LogicTrap trap = (LogicTrap)gameObject; if (trap.CanUpgrade(true)) { LogicTrapData data = trap.GetTrapData(); LogicResourceData buildResourceData = data.GetBuildResource(); LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); int buildCost = data.GetBuildCost(trap.GetUpgradeLevel() + 1); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { int constructionTime = data.GetBuildTime(trap.GetUpgradeLevel() + 1); if (constructionTime != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); trap.StartUpgrading(); return(0); } } } } else if (gameObject.GetGameObjectType() == 8) { if (!this._useAltResources) { LogicVillageObject villageObject = (LogicVillageObject)gameObject; // TODO: Implement upgrade vObjs. } return(-31); } } return(-1); }
public override void Load(LogicJSONObject jsonObject) { this.LoadUpgradeLevel(jsonObject); LogicTrapData data = this.GetTrapData(); if (data.HasAlternativeMode() || data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null) { LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT); if (layoutComponent != null) { for (int i = 0; i < 8; i++) { LogicJSONBoolean airModeObject = jsonObject.GetJSONBoolean(layoutComponent.GetLayoutVariableNameAirMode(i, false)); if (airModeObject != null) { this.m_useAirMode[i] = airModeObject.IsTrue(); } LogicJSONBoolean draftAirModeObject = jsonObject.GetJSONBoolean(layoutComponent.GetLayoutVariableNameAirMode(i, true)); if (draftAirModeObject != null) { this.m_draftUseAirMode[i] = draftAirModeObject.IsTrue(); } } } LogicTriggerComponent triggerComponent = this.GetTriggerComponent(); int layoutId = this.m_level.GetCurrentLayout(); bool airMode = this.m_useAirMode[layoutId]; triggerComponent.SetAirTrigger(airMode); triggerComponent.SetGroundTrigger(!airMode); } if (data.GetDirectionCount() > 0) { LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT); if (layoutComponent != null) { for (int i = 0; i < 8; i++) { LogicJSONNumber trapDistanceObject = jsonObject.GetJSONNumber(layoutComponent.GetLayoutVariableNameTrapDirection(i, false)); if (trapDistanceObject != null) { this.m_direction[i] = trapDistanceObject.GetIntValue(); } LogicJSONNumber draftTrapDistanceObject = jsonObject.GetJSONNumber(layoutComponent.GetLayoutVariableNameTrapDirection(i, true)); if (draftTrapDistanceObject != null) { this.m_draftDirection[i] = draftTrapDistanceObject.GetIntValue(); } } } } this.m_level.GetWorkerManagerAt(this.m_villageType).DeallocateWorker(this); if (this.m_constructionTimer != null) { this.m_constructionTimer.Destruct(); this.m_constructionTimer = null; } LogicJSONNumber constTimeObject = jsonObject.GetJSONNumber("const_t"); if (constTimeObject != null) { int constTime = constTimeObject.GetIntValue(); if (!LogicDataTables.GetGlobals().ClampBuildingTimes()) { if (this.m_upgLevel < data.GetUpgradeLevelCount() - 1) { constTime = LogicMath.Min(constTime, data.GetBuildTime(this.m_upgLevel + 1)); } } this.m_constructionTimer = new LogicTimer(); this.m_constructionTimer.StartTimer(constTime, this.m_level.GetLogicTime(), false, -1); LogicJSONNumber constTimeEndObject = jsonObject.GetJSONNumber("const_t_end"); if (constTimeEndObject != null) { this.m_constructionTimer.SetEndTimestamp(constTimeEndObject.GetIntValue()); } LogicJSONNumber conffObject = jsonObject.GetJSONNumber("con_ff"); if (conffObject != null) { this.m_constructionTimer.SetFastForward(conffObject.GetIntValue()); } this.m_level.GetWorkerManagerAt(this.m_villageType).AllocateWorker(this); this.m_upgrading = this.m_upgLevel != -1; } LogicJSONBoolean disarmed = jsonObject.GetJSONBoolean("needs_repair"); if (disarmed != null) { this.m_disarmed = disarmed.IsTrue(); } this.SetUpgradeLevel(this.m_upgLevel); base.Load(jsonObject); }
public override void LoadFromSnapshot(LogicJSONObject jsonObject) { if (this.m_data.GetVillageType() == 1) { this.Load(jsonObject); return; } LogicTrapData data = this.GetTrapData(); this.LoadUpgradeLevel(jsonObject); this.m_level.GetWorkerManagerAt(this.m_villageType).DeallocateWorker(this); if (this.m_constructionTimer != null) { this.m_constructionTimer.Destruct(); this.m_constructionTimer = null; } if (data.HasAlternativeMode() || data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null) { LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT); if (layoutComponent != null) { for (int i = 0; i < 8; i++) { LogicJSONBoolean airModeObject = jsonObject.GetJSONBoolean(layoutComponent.GetLayoutVariableNameAirMode(i, false)); if (airModeObject != null) { this.m_useAirMode[i] = airModeObject.IsTrue(); } } } LogicTriggerComponent triggerComponent = this.GetTriggerComponent(); bool airMode = this.m_useAirMode[this.m_level.GetWarLayout()]; triggerComponent.SetAirTrigger(airMode); triggerComponent.SetGroundTrigger(!airMode); } if (data.GetDirectionCount() > 0) { LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT); if (layoutComponent != null) { for (int i = 0; i < 8; i++) { LogicJSONNumber trapDistanceObject = jsonObject.GetJSONNumber(layoutComponent.GetLayoutVariableNameTrapDirection(i, false)); if (trapDistanceObject != null) { this.m_direction[i] = trapDistanceObject.GetIntValue(); } } } } this.m_level.GetWorkerManagerAt(this.m_data.GetVillageType()).DeallocateWorker(this); if (this.m_constructionTimer != null) { this.m_constructionTimer.Destruct(); this.m_constructionTimer = null; } this.SetUpgradeLevel(this.m_upgLevel); base.LoadFromSnapshot(jsonObject); }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null) { if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.IsTownHallVillage2()) { if (!LogicUpgradeBuildingCommand.CanUpgradeTHV2(level)) { return(-76); } } if (buildingData.GetVillageType() == level.GetVillageType()) { if (level.GetGameObjectManager().GetAvailableBuildingUpgradeCount(building) <= 0) { return(-34); } if (building.GetWallIndex() == 0) { if (building.CanUpgrade(true)) { int nextUpgradeLevel = building.GetUpgradeLevel() + 1; int buildCost = buildingData.GetBuildCost(nextUpgradeLevel, level); LogicResourceData buildResourceData = this.m_useAltResource ? buildingData.GetAltBuildResource(nextUpgradeLevel) : buildingData.GetBuildResource(nextUpgradeLevel); if (buildResourceData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { if (buildingData.GetConstructionTime(nextUpgradeLevel, level, 0) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); building.StartUpgrading(true, false); return(0); } } } return(-1); } return(-35); } return(-32); } if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.CanUpgrade(true)) { LogicTrapData data = trap.GetTrapData(); LogicResourceData buildResourceData = data.GetBuildResource(); LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); int buildCost = data.GetBuildCost(trap.GetUpgradeLevel() + 1); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { if (data.GetBuildTime(trap.GetUpgradeLevel() + 1) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); trap.StartUpgrading(); return(0); } } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.VILLAGE_OBJECT) { if (!this.m_useAltResource) { LogicVillageObject villageObject = (LogicVillageObject)gameObject; if (villageObject.CanUpgrade(true)) { LogicVillageObjectData data = villageObject.GetVillageObjectData(); LogicResourceData buildResourceData = data.GetBuildResource(); int buildCost = data.GetBuildCost(villageObject.GetUpgradeLevel() + 1); if (buildResourceData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { if (data.GetBuildTime(villageObject.GetUpgradeLevel() + 1) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); villageObject.StartUpgrading(true); return(0); } } } return(-1); } return(-31); } } return(-1); }
public static LogicClientHome GenerateBase(LogicGameObjectData gameObjectData) { LogicClientHome logicClientHome = new LogicClientHome(); LogicGameMode logicGameMode = new LogicGameMode(); LogicLevel logicLevel = logicGameMode.GetLevel(); LogicGameObjectManager logicGameObjectManager = logicLevel.GetGameObjectManagerAt(0); logicLevel.SetLoadingVillageType(-1); logicLevel.SetVillageType(0); logicLevel.SetExperienceVersion(1); logicLevel.SetHomeOwnerAvatar(GameBaseGenerator.HomeOwnerAvatar); LogicBuilding townHall = new LogicBuilding(LogicDataTables.GetTownHallData(), logicLevel, 0); townHall.SetInitialPosition((LogicLevel.TILEMAP_SIZE_X / 2 - townHall.GetWidthInTiles() / 2) << 9, (LogicLevel.TILEMAP_SIZE_Y / 2 - townHall.GetHeightInTiles() / 2) << 9); townHall.SetUpgradeLevel(townHall.GetBuildingData().GetUpgradeLevelCount() - 1); logicGameObjectManager.AddGameObject(townHall, -1); LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHall.GetUpgradeLevel()); if (gameObjectData == null) { LogicArrayList <LogicGameObject> scrambler = new LogicArrayList <LogicGameObject>(); for (int i = 0; i < GameBaseGenerator.m_defenseBuildingArray.Size(); i++) { LogicBuildingData buildingData = GameBaseGenerator.m_defenseBuildingArray[i]; for (int j = townhallLevelData.GetUnlockedBuildingCount(buildingData); j > 0; j--) { LogicBuilding logicBuilding = (LogicBuilding)GameBaseGenerator.CreateAndPlaceRandomlyGameObject(buildingData, logicLevel, buildingData.GetWidth(), buildingData.GetHeight(), 0); if (logicBuilding != null) { logicBuilding.SetLocked(false); logicBuilding.SetUpgradeLevel(buildingData.GetUpgradeLevelCount() - 1); scrambler.Add(logicBuilding); int upgradeLevel = buildingData.GetUpgradeLevelCount() - 1; int minUpgradeLevelForGearUp = buildingData.GetMinUpgradeLevelForGearUp(); if (minUpgradeLevelForGearUp > -1 && upgradeLevel >= minUpgradeLevelForGearUp) { if (GameBaseGenerator.m_random.Rand(100) >= 50) { logicBuilding.SetGearLevel(1); } } if (buildingData.GetAttackerItemData(upgradeLevel).GetTargetingConeAngle() != 0) { logicBuilding.GetCombatComponent().ToggleAimAngle(buildingData.GetAimRotateStep() * GameBaseGenerator.m_random.Rand(360 / buildingData.GetAimRotateStep()), 0, false); } if (buildingData.GetAttackerItemData(upgradeLevel).HasAlternativeAttackMode()) { if (minUpgradeLevelForGearUp > -1 && logicBuilding.GetGearLevel() != 1) { continue; } if (GameBaseGenerator.m_random.Rand(100) >= 50) { logicBuilding.GetCombatComponent().ToggleAttackMode(0, false); } } } } } for (int i = 0; i < GameBaseGenerator.m_otherBuildingArray.Size(); i++) { LogicBuildingData buildingData = GameBaseGenerator.m_otherBuildingArray[i]; for (int j = townhallLevelData.GetUnlockedBuildingCount(buildingData); j > 0; j--) { LogicBuilding logicBuilding = (LogicBuilding)GameBaseGenerator.CreateAndPlaceRandomlyGameObject(buildingData, logicLevel, buildingData.GetWidth(), buildingData.GetHeight(), 0); if (logicBuilding != null) { logicBuilding.SetLocked(false); logicBuilding.SetUpgradeLevel(buildingData.GetUpgradeLevelCount() - 1); scrambler.Add(logicBuilding); } } } for (int i = 0; i < GameBaseGenerator.m_trapArray.Size(); i++) { LogicTrapData trapData = (LogicTrapData)GameBaseGenerator.m_trapArray[i]; for (int j = townhallLevelData.GetUnlockedTrapCount(trapData); j > 0; j--) { LogicTrap trap = (LogicTrap)GameBaseGenerator.CreateAndPlaceRandomlyGameObject(trapData, logicLevel, trapData.GetWidth(), trapData.GetHeight(), 0); if (trap != null) { trap.SetUpgradeLevel(trapData.GetUpgradeLevelCount() - 1); scrambler.Add(trap); } } } for (int i = 0; i < scrambler.Size(); i++) { LogicGameObject gameObject = scrambler[i]; LogicData data = gameObject.GetData(); int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); int x = gameObject.GetX(); int y = gameObject.GetY(); LogicArrayList <LogicGameObject> available = new LogicArrayList <LogicGameObject>(); for (int j = i + 1; j < scrambler.Size(); j++) { if (data != scrambler[j].GetData()) { if (scrambler[j].GetWidthInTiles() == width && scrambler[j].GetHeightInTiles() == height) { available.Add(scrambler[j]); } } } if (available.Size() != 0) { LogicGameObject swapObj = available[GameBaseGenerator.m_random.Rand(available.Size())]; gameObject.SetInitialPosition(swapObj.GetX(), swapObj.GetY()); swapObj.SetInitialPosition(x, y); } } } else { int maxUpgradeLevel = 0; int width = 1; int height = 1; switch (gameObjectData.GetDataType()) { case LogicDataType.BUILDING: { LogicBuildingData logicBuildingData = (LogicBuildingData)gameObjectData; maxUpgradeLevel = logicBuildingData.GetUpgradeLevelCount(); width = logicBuildingData.GetWidth(); height = logicBuildingData.GetHeight(); break; } case LogicDataType.TRAP: LogicTrapData logicTrapData = (LogicTrapData)gameObjectData; maxUpgradeLevel = logicTrapData.GetUpgradeLevelCount(); width = logicTrapData.GetWidth(); height = logicTrapData.GetHeight(); break; } int upgLevel = maxUpgradeLevel - 1; int x = 0; int y = 0; while (true) { LogicBuilding building = (LogicBuilding)GameBaseGenerator.CreateGameObjectIfAnyPlaceExist(gameObjectData, logicLevel, width, height, 0, x, y); if (building == null) { break; } building.SetLocked(false); building.SetUpgradeLevel(upgLevel != -1 ? upgLevel : GameBaseGenerator.m_random.Rand(building.GetUpgradeLevel())); x = building.GetTileX(); y = building.GetTileY(); } } for (int i = 0; i < 10; i++) { logicGameObjectManager.Village1CreateObstacle(); } LogicJSONObject jsonObject = new LogicJSONObject(); logicGameMode.SaveToJSON(jsonObject); logicGameMode.Destruct(); logicClientHome.SetHomeJSON(LogicJSONParser.CreateJSONString(jsonObject, 2048)); CompressibleStringHelper.Compress(logicClientHome.GetCompressibleHomeJSON()); return(logicClientHome); }
public override int Execute(LogicLevel level) { if (this.m_gameObjectData != null && level.GetUnplacedObjectCount(this.m_gameObjectData) > 0) { if (level.GetVillageType() == this.m_gameObjectData.GetVillageType()) { LogicDataType dataType = this.m_gameObjectData.GetDataType(); if (dataType == LogicDataType.BUILDING) { LogicBuildingData buildingData = (LogicBuildingData)this.m_gameObjectData; if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, buildingData.GetWidth(), buildingData.GetHeight(), null)) { if (!level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel)) { return(-63); } LogicBuilding building = (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this.m_gameObjectData, level, level.GetVillageType()); building.SetPositionXY(this.m_x << 9, this.m_y << 9); level.GetGameObjectManager().AddGameObject(building, -1); building.FinishConstruction(false, true); building.SetUpgradeLevel(this.m_upgradeLevel); } return(0); } if (dataType == LogicDataType.TRAP) { LogicTrapData trapData = (LogicTrapData)this.m_gameObjectData; if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, trapData.GetWidth(), trapData.GetHeight(), null)) { if (!level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel)) { return(-64); } LogicTrap trap = (LogicTrap)LogicGameObjectFactory.CreateGameObject(this.m_gameObjectData, level, level.GetVillageType()); trap.SetPositionXY(this.m_x << 9, this.m_y << 9); trap.FinishConstruction(false); trap.SetUpgradeLevel(this.m_upgradeLevel); level.GetGameObjectManager().AddGameObject(trap, -1); } return(0); } if (dataType == LogicDataType.DECO) { LogicDecoData decoData = (LogicDecoData)this.m_gameObjectData; if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, decoData.GetWidth(), decoData.GetHeight(), null)) { if (!level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel)) { return(-65); } LogicDeco deco = (LogicDeco)LogicGameObjectFactory.CreateGameObject(this.m_gameObjectData, level, level.GetVillageType()); deco.SetPositionXY(this.m_x << 9, this.m_y << 9); level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel); level.GetGameObjectManager().AddGameObject(deco, -1); } return(0); } return(-3); } return(-35); } return(0); }