/// <summary> /// Destructs this instance. /// </summary> public virtual void Destruct() { this._level.GetTileMap().RemoveGameObject(this); for (int i = 0; i < this._components.Count; i++) { if (this._components[i] != null) { this._components[i].Destruct(); this._components[i].RemoveGameObjectReferences(this); } } if (this._position != null) { this._position.Destruct(); this._position = null; } if (this._listener != null) { this._listener.Destruct(); this._listener = null; } this._data = null; this._level = null; }
public void RefreshArmyCampSize(bool unk) { if (this.m_unit != null && this.m_productionTimer == null) { int maxUnits = this.GetMaxUnitsInCamp((LogicCharacterData)this.m_unit.GetData()); int unitCount = this.m_unit.GetCount(); if (maxUnits > unitCount) { LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); homeOwnerAvatar.CommodityCountChangeHelper(7, this.m_unit.GetData(), maxUnits - unitCount); this.m_unit.SetCount(maxUnits); if (this.m_parent.GetLevel().GetState() == 1) { LogicGameObjectListener listener = this.m_parent.GetListener(); if (listener != null) { for (int i = unitCount; i < maxUnits; i++) { if (i > 25) { return; } // TODO: Implement listener. } } } } } }
public virtual void Destruct() { if (this.m_level != null) { this.m_level.GetTileMap().RemoveGameObject(this); } for (int i = 0; i < LogicComponent.COMPONENT_TYPE_COUNT; i++) { if (this.m_components[i] != null) { this.m_components[i].Destruct(); this.m_components[i] = null; } } if (this.m_position != null) { this.m_position.Destruct(); this.m_position = null; } if (this.m_listener != null) { this.m_listener.Destruct(); this.m_listener = null; } }
public LogicGameObject(LogicGameObjectData data, LogicLevel level, int villageType) { Debugger.DoAssert(villageType < 2, "VillageType not set! Game object has not been added to LogicGameObjectManager."); this.m_data = data; this.m_level = level; this.m_villageType = villageType; this.m_position = new LogicVector2(); this.m_listener = new LogicGameObjectListener(); this.m_components = new LogicComponent[LogicComponent.COMPONENT_TYPE_COUNT]; }
/// <summary> /// Initializes a new instance of the <see cref="LogicGameObject" /> class. /// </summary> public LogicGameObject(LogicData data, LogicLevel level, int villageType) { Debugger.DoAssert(villageType < 2, "VillageType not set! Game object has not been added to LogicGameObjectManager."); this._data = data; this._level = level; this._villageType = villageType; this._globalId = -1; this._position = new LogicVector2(); this._listener = new LogicGameObjectListener(); this._components = new LogicArrayList <LogicComponent>(21); for (int i = 0; i < 17; i++) { this._components.Add(null); } }
/// <summary> /// Executes this instance. /// </summary> public override int Execute(LogicLevel level) { for (int i = 0; i < this._unitsCount.Count; i++) { if (this._unitsCount[i] < 0) { return(-1); } } if (LogicDataTables.GetGlobals().EnableTroopDeletion() && level.GetState() == 1 && this._unitsData.Count > 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); Int32 removedUnits = 0; for (int i = 0; i < this._unitsData.Count; i++) { LogicCombatItemData data = this._unitsData[i]; Int32 unitCount = this._unitsCount[i]; if (this._removeType[i] != 0) { Int32 upgLevel = this._unitsUpgLevel[i]; if (data.GetCombatItemType() != 0) { if (data.GetCombatItemType() == 1) { playerAvatar.SetAllianceUnitCount(data, upgLevel, LogicMath.Max(0, playerAvatar.GetAllianceUnitCount(data, upgLevel) - unitCount)); if (unitCount > 0) { do { playerAvatar.GetChangeListener().AllianceUnitRemoved(data, upgLevel); } while (--unitCount != 0); } removedUnits |= 2; } } else { LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle(); if (allianceCastle != null) { LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent(); Int32 unitTypeIndex = bunkerComponent.GetUnitTypeIndex(data); if (unitTypeIndex != -1) { Int32 cnt = bunkerComponent.GetUnitCount(unitTypeIndex); if (cnt > 0) { bunkerComponent.RemoveUnits(data, upgLevel, cnt); playerAvatar.SetAllianceUnitCount(data, upgLevel, LogicMath.Max(0, playerAvatar.GetAllianceUnitCount(data, upgLevel) - unitCount)); removedUnits |= 1; if (unitCount > 0) { do { playerAvatar.GetChangeListener().AllianceUnitRemoved(data, upgLevel); } while (--unitCount != 0); } } } } } } else { if (playerAvatar != null && data != null) { playerAvatar.CommodityCountChangeHelper(0, data, -unitCount); } LogicArrayList <LogicComponent> components = level.GetComponentManager().GetComponents(0); for (int j = 0; j < components.Count; j++) { if (unitCount > 0) { LogicUnitStorageComponent storageComponent = (LogicUnitStorageComponent)components[j]; Int32 unitTypeIndex = storageComponent.GetUnitTypeIndex(data); if (unitTypeIndex != -1) { Int32 cnt = storageComponent.GetUnitCount(unitTypeIndex); if (cnt > 0) { cnt = LogicMath.Min(cnt, unitCount); storageComponent.RemoveUnits(data, cnt); int type = 2; if (data.GetCombatItemType() == 0) { if (storageComponent.GetParentListener() != null) { LogicGameObjectListener listener = storageComponent.GetParentListener(); for (int k = 0; k < cnt; k++) { listener.UnitRemoved(data); } } type = 1; } unitCount -= cnt; removedUnits |= type; } } } } } } switch (removedUnits) { case 3: if (LogicDataTables.GetGlobals().UseNewTraining()) { level.GetGameObjectManager().GetUnitProduction().MergeSlots(); level.GetGameObjectManager().GetSpellProduction().MergeSlots(); } break; case 2: if (LogicDataTables.GetGlobals().UseNewTraining()) { level.GetGameObjectManager().GetSpellProduction().MergeSlots(); } break; case 1: if (LogicDataTables.GetGlobals().UseNewTraining()) { level.GetGameObjectManager().GetUnitProduction().MergeSlots(); } break; default: Debugger.Print("WTF: " + removedUnits); break; } } return(0); }
/// <summary> /// Sets the gameobject listener. /// </summary> public void SetListener(LogicGameObjectListener listener) { this._listener = listener; }
public override void Tick() { if (this.m_hp < this.m_maxHp && this.m_regenerationEnabled) { int rebuildEffectHp = this.m_maxHp / 5; int prevHp = this.m_hp; if (this.m_maxRegenerationTime <= 0) { this.m_hp = this.m_maxHp; this.m_regenTime = 0; } else { this.m_regenTime += 64; int tmp = LogicMath.Max(1000 * this.m_maxRegenerationTime / (this.m_maxHp / 100), 1); this.m_hp += 100 * (this.m_regenTime / tmp); if (this.m_hp >= this.m_maxHp) { this.m_hp = this.m_maxHp; this.m_regenTime = 0; } else { this.m_regenTime %= tmp; } } if (prevHp < rebuildEffectHp && this.m_hp >= rebuildEffectHp) { LogicGameObjectListener listener = this.GetParentListener(); if (listener != null) { // Listener. } } } if (this.m_extraHpTime > 0) { this.m_extraHpTime -= 64; if (this.m_extraHpTime <= 0) { this.m_extraHpTime = 0; if (this.m_hp > 0) { if (this.m_originalHp != this.m_maxHp) { this.m_hp = (int)(this.m_originalHp * (long)this.m_hp / this.m_maxHp); this.m_maxHp = this.m_originalHp; } this.m_extraHpTime = -1; } } } if (this.m_poisonInitTime <= 0) { if (this.m_poisonTime > 0) { this.m_poisonTime -= 10; if (this.m_poisonTime <= 0) { this.m_poisonTime = 0; this.m_poisonDamage = 0; } } } else { this.m_poisonInitTime = LogicMath.Max(this.m_poisonInitTime - 64, 0); } if (this.m_poisonTime > 0) { this.CauseDamage((int)(((this.m_poisonDamage * this.m_poisonTime / 1000L) * 64L) / 1000L), 0, null); } this.m_invulnerabilityTime = LogicMath.Max(this.m_invulnerabilityTime - 64, 0); for (int i = 0; i < 8; i++) { this.m_healingTime[i] -= 64; if (this.m_healingTime[i] <= 0) { this.m_healingTime[i] = 0; this.m_healingId[i] = 0; } } this.m_lastDamageTime += 1; if (this.m_shrinkTime > 0) { this.m_shrinkTime -= 1; if (this.m_shrinkTime == 0) { Debugger.HudPrint("HP TO ORIGINAL"); this.m_hp = LogicMath.Min(this.m_originalHp * (100 * this.m_hp / this.m_maxHp) / 100, this.m_originalHp); this.m_maxHp = this.m_originalHp; } } }