public override int Execute(LogicLevel level) { if (level != null) { LogicGameObject gameObject; if (level.GetState() == 5) { gameObject = LogicGameObjectFactory.CreateGameObject(this.m_data, level, level.GetVillageType()); gameObject.Load(this.m_json); level.GetGameObjectManager().AddGameObject(gameObject, -1); } else { gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_id); } if (gameObject != null) { if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; LogicGameObjectManagerListener listener = level.GetGameObjectManager().GetListener(); listener.AddGameObject(gameObject); gameObject.LoadingFinished(); gameObject.GetListener().RefreshState(); LogicTriggerComponent triggerComponent = trap.GetTriggerComponent(); if (triggerComponent != null) { triggerComponent.SetTriggered(); } } return(0); } Debugger.Warning("PGO == NULL in LogicTriggerComponentTriggeredCommand"); return(-2); } 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 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; } } } }