public void Destruct() { this.m_functionData = null; this.m_calendarEvent = null; this.m_errorHandler = null; this.m_parameters = null; }
public bool IsEqual(LogicCalendarEvent calendarEvent) { if (this.m_id == calendarEvent.m_id) { return(this.m_version == calendarEvent.m_version); } return(false); }
public LogicCalendarFunction(LogicCalendarEvent calendarEvent, int idx, LogicJSONObject jsonObject, LogicCalendarErrorHandler errorHandler) { this.m_parameters = new LogicArrayList <string>(); this.m_calendarEvent = calendarEvent; this.m_errorHandler = errorHandler; this.m_idx = idx; this.Load(jsonObject); }
public static LogicCalendarEvent LoadFromJSON(LogicJSONObject jsonObject, LogicCalendarErrorHandler errorHandler) { LogicJSONNumber typeObject = jsonObject.GetJSONNumber("type"); LogicCalendarEvent calendarEvent = LogicCalendarEventFactory.CreateByType(typeObject.GetIntValue()); if (errorHandler != null) { calendarEvent.SetErrorHandler(errorHandler); } calendarEvent.Init(jsonObject); return(calendarEvent); }
public int GetSpellProductionBoostCost() { int spellProductionBoostCost = LogicDataTables.GetGlobals().GetNewTrainingBoostLaboratoryCost(); for (int i = this.m_activeCalendarEvents.Size() - 1; i >= 0; i--) { LogicCalendarEvent calendarEvent = this.m_activeCalendarEvents[i]; if (calendarEvent.GetNewTrainingBoostSpellCost() <= spellProductionBoostCost) { spellProductionBoostCost = calendarEvent.GetNewTrainingBoostSpellCost(); } } return(spellProductionBoostCost); }
public int GetUnitProductionBoostCost() { int unitProductionBoostCost = LogicDataTables.GetGlobals().GetNewTrainingBoostBarracksCost(); for (int i = this.m_activeCalendarEvents.Size() - 1; i >= 0; i--) { LogicCalendarEvent calendarEvent = this.m_activeCalendarEvents[i]; if (calendarEvent.GetNewTrainingBoostBarracksCost() <= unitProductionBoostCost) { unitProductionBoostCost = calendarEvent.GetNewTrainingBoostBarracksCost(); } } return(unitProductionBoostCost); }
public LogicArrayList <LogicCalendarEvent> GetActiveCalendarEvents(int minTimestamp, int maxTimestamp) { LogicArrayList <LogicCalendarEvent> activeCalendarEvents = new LogicArrayList <LogicCalendarEvent>(); for (int i = 0; i < this.m_calendarEvents.Size(); i++) { LogicCalendarEvent calendarEvent = this.m_calendarEvents[i]; if (calendarEvent.GetStartTime() <= minTimestamp && calendarEvent.GetEndTime() >= maxTimestamp) { activeCalendarEvents.Add(calendarEvent); } } return(activeCalendarEvents); }
public static int GetDuelBonusPercentLose(LogicCalendar instance, LogicConfiguration configuration) { if (instance == null) { Debugger.Warning("LogicCalender is NULL for getDuelBonusPercentLose call"); if (configuration != null) { return(configuration.GetDuelBonusPercentLose()); } return(100); } int percent = -1; for (int i = 0; i < instance.m_activeCalendarEvents.Size(); i++) { LogicCalendarEvent calendarEvent = instance.m_activeCalendarEvents[i]; if (calendarEvent.GetCalendarEventType() == LogicCalendarEvent.EVENT_TYPE_DUEL_LOOT_LIMIT) { LogicDuelLootLimitCalendarEvent duelLootLimitCalendarEvent = (LogicDuelLootLimitCalendarEvent)calendarEvent; if (percent == -1 || duelLootLimitCalendarEvent.GetDuelBonusPercentLose() <= percent) { percent = duelLootLimitCalendarEvent.GetDuelBonusPercentLose(); } } } if (percent == -1) { if (configuration != null) { return(configuration.GetDuelBonusPercentLose()); } return(100); } return(0); }
public bool HasNewActiveCalendarEvents(LogicArrayList <LogicCalendarEvent> currentActiveCalendarEvents, int minTimestamp, int maxTimestamp) { int enableCalendarCount = 0; for (int i = 0, j = 0; i < this.m_calendarEvents.Size(); i++) { LogicCalendarEvent calendarEvent = this.m_calendarEvents[i]; if (calendarEvent.GetStartTime() <= minTimestamp && calendarEvent.GetEndTime() >= maxTimestamp) { if (j < currentActiveCalendarEvents.Size()) { if (!calendarEvent.IsEqual(currentActiveCalendarEvents[j++])) { return(true); } } ++enableCalendarCount; } } return(enableCalendarCount != currentActiveCalendarEvents.Size()); }
public virtual LogicJSONObject Save() { LogicJSONObject jsonObject = new LogicJSONObject(); jsonObject.Put("type", new LogicJSONNumber(this.GetCalendarEventType())); jsonObject.Put("id", new LogicJSONNumber(this.m_id)); jsonObject.Put("version", new LogicJSONNumber(this.m_version)); jsonObject.Put("visibleTime", new LogicJSONString(LogicCalendarEvent.ConvertTimestampToString(this.m_visibleTime))); jsonObject.Put("startTime", new LogicJSONString(LogicCalendarEvent.ConvertTimestampToString(this.m_startTime))); jsonObject.Put("endTime", new LogicJSONString(LogicCalendarEvent.ConvertTimestampToString(this.m_endTime))); jsonObject.Put("clashBoxEntryName", new LogicJSONString(this.m_clashBoxEntryName)); jsonObject.Put("eventEntryName", new LogicJSONString(this.m_eventEntryData != null ? this.m_eventEntryData.GetName() : string.Empty)); jsonObject.Put("inboxEntryId", new LogicJSONNumber(this.m_inboxEntryId)); jsonObject.Put("notificationTid", new LogicJSONString(this.m_notificationTid)); jsonObject.Put("image", new LogicJSONString(this.m_image)); jsonObject.Put("sc", new LogicJSONString(this.m_sc)); jsonObject.Put("localization", new LogicJSONString(this.m_localization)); LogicJSONArray functionArray = new LogicJSONArray(this.m_functions.Size()); for (int i = 0; i < this.m_functions.Size(); i++) { functionArray.Add(this.m_functions[i].Save()); } jsonObject.Put("functions", functionArray); if (this.m_targeting != null) { LogicJSONObject targetingObject = new LogicJSONObject(); this.m_targeting.Save(jsonObject); jsonObject.Put("targeting", targetingObject); } return(jsonObject); }
public void ApplyToEvent(LogicCalendarEvent calendarEvent) { switch (this.m_functionData.GetFunctionType()) { case LogicCalendarEventFunctionData.FUNCTION_TYPE_TROOP_TRAINING_BOOST: calendarEvent.SetNewTrainingBoostBarracksCost(this.GetIntParameter(0)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_SPELL_BREWING_BOOST: calendarEvent.SetNewTrainingBoostSpellCost(this.GetIntParameter(0)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_BUILDING_BOOST: calendarEvent.AddBuildingBoost(this.GetDataParameter(0, LogicDataType.BUILDING), this.GetIntParameter(1)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_TROOP_DISCOUNT: calendarEvent.AddTroopDiscount(this.GetDataParameter(0, LogicDataType.CHARACTER), this.GetIntParameter(1)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_SPELL_DISCOUNT: calendarEvent.AddTroopDiscount(this.GetDataParameter(0, LogicDataType.SPELL), this.GetIntParameter(1)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_CLAN_XP_MULTIPLIER: calendarEvent.SetAllianceXpMultiplier(this.GetIntParameter(0)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_OFFER_BUNDLE: calendarEvent.AddEnabledData(this.GetDataParameter(0, LogicDataType.GEM_BUNDLE)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_STAR_BONUS_MULTIPLIER: calendarEvent.SetStarBonusMultiplier(this.GetIntParameter(0)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_ENABLE_TROOP: calendarEvent.AddEnabledData(this.GetDataParameter(0, LogicDataType.CHARACTER)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_ENABLE_SPELL: calendarEvent.AddEnabledData(this.GetDataParameter(0, LogicDataType.SPELL)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_ENABLE_TRAP: calendarEvent.AddEnabledData(this.GetDataParameter(0, LogicDataType.TRAP)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_USE_TROOP: calendarEvent.AddUseTroop((LogicCombatItemData)this.GetDataParameter(0, LogicDataType.CHARACTER), this.GetIntParameter(1), this.GetIntParameter(2), this.GetIntParameter(3), this.GetIntParameter(4)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_TARGETING_TOWN_HALL_LEVEL: case LogicCalendarEventFunctionData.FUNCTION_TYPE_TARGETING_PURCHASED_DIAMONDS: Debugger.Warning("You should no longer target thru event functions."); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_ENABLE_BILLING_PACKAGE: calendarEvent.AddEnabledData(this.GetDataParameter(0, LogicDataType.BILLING_PACKAGE)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_CHANGE_WORKER_LOOK: // TODO: Implement this (client). break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_GIVE_FREE_TROOPS: calendarEvent.AddFreeTroop((LogicCombatItemData)this.GetDataParameter(0, LogicDataType.CHARACTER), this.GetIntParameter(1)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_GIVE_FREE_SPELLS: calendarEvent.AddFreeTroop((LogicCombatItemData)this.GetDataParameter(0, LogicDataType.SPELL), this.GetIntParameter(1)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_GIVE_FREE_HERO_HEALTH: if (this.GetDataParameter(0, LogicDataType.HERO) != null) { calendarEvent.AddFreeTroop((LogicCombatItemData)this.GetDataParameter(0, LogicDataType.HERO), 1); } else { LogicDataTable table = LogicDataTables.GetTable(LogicDataType.HERO); for (int i = 0; i < table.GetItemCount(); i++) { calendarEvent.AddFreeTroop((LogicCombatItemData)table.GetItemAt(i), 1); } } break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_BUILDING_SIGN: // TODO: Implement this (client). break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_BUILDING_DESTROYED_SPAWN_UNIT: calendarEvent.AddBuildingDestroyedSpawnUnit((LogicBuildingData)this.GetDataParameter(0, LogicDataType.BUILDING), (LogicCharacterData)this.GetDataParameter(1, LogicDataType.CHARACTER), this.GetIntParameter(2)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_USE_SPELL: calendarEvent.AddUseTroop((LogicCombatItemData)this.GetDataParameter(0, LogicDataType.SPELL), this.GetIntParameter(1), this.GetIntParameter(2), this.GetIntParameter(3), this.GetIntParameter(4)); break; case LogicCalendarEventFunctionData.FUNCTION_TYPE_CLAN_WAR_LOOT_MULTIPLIER: calendarEvent.SetAllianceWarWinLootMultiplier(this.GetIntParameter(0)); calendarEvent.SetAllianceWarDrawLootMultiplier(this.GetIntParameter(1)); calendarEvent.SetAllianceWarLooseLootMultiplier(this.GetIntParameter(2)); break; default: Debugger.Error(string.Format("Unknown function type: {0}.", this.m_functionData.GetFunctionType())); break; } }
public void Error(LogicCalendarEvent eventName, string message) { Debugger.Error(string.Format("Error in calendar event {0}: {1}", eventName, message)); }
public void WarningFunction(LogicCalendarEvent eventName, LogicCalendarFunction function, string parameter, string message) { Debugger.Error(string.Format("Warning in calendar event {0}, function {1}, parameter {2}: {3}", eventName, function, parameter, message)); }
public void WarningField(LogicCalendarEvent eventName, string field, string message) { Debugger.Error(string.Format("Warning in calendar event {0}, field {1}: {2}", eventName, field, message)); }
public void ErrorFunction(LogicCalendarEvent eventName, LogicCalendarFunction function, string message) { Debugger.Error(string.Format("Error in calendar event {0}, field {1}: {2}", eventName, function, message)); }
public virtual void Load(LogicJSONObject jsonObject) { if (jsonObject == null) { this.m_errorHandler.Error(this, "Json cannot be null"); } this.m_id = LogicJSONHelper.GetInt(jsonObject, "id", -1); this.m_version = LogicJSONHelper.GetInt(jsonObject, "version", 0); this.m_newTrainingBoostBarracksCost = LogicDataTables.GetGlobals().GetNewTrainingBoostBarracksCost(); this.m_newTrainingBoostSpellCost = LogicDataTables.GetGlobals().GetNewTrainingBoostLaboratoryCost(); this.m_startTime = LogicCalendarEvent.ConvertStringToTimestamp(LogicJSONHelper.GetString(jsonObject, "startTime"), false); this.m_endTime = LogicCalendarEvent.ConvertStringToTimestamp(LogicJSONHelper.GetString(jsonObject, "endTime"), true); if (this.m_startTime >= this.m_endTime) { this.m_errorHandler.ErrorField(this, "endTime", "End time must be after start time."); } LogicJSONString visibleTimeString = jsonObject.GetJSONString("visibleTime"); if (visibleTimeString != null) { this.m_visibleTime = LogicCalendarEvent.ConvertStringToTimestamp(visibleTimeString.GetStringValue(), false); if (this.m_visibleTime > this.m_startTime) { this.m_errorHandler.ErrorField(this, "visibleTime", "Visible time must be before or at start time."); } } else { this.m_visibleTime = 0; } this.m_clashBoxEntryName = jsonObject.GetJSONString("clashBoxEntryName").GetStringValue(); LogicJSONString eventEntryNameString = jsonObject.GetJSONString("eventEntryName"); this.m_eventEntryData = LogicDataTables.GetEventEntryByName(eventEntryNameString.GetStringValue(), null); if (eventEntryNameString.GetStringValue().Length > 0) { if (this.m_eventEntryData == null) { this.m_errorHandler.ErrorField(this, "eventEntryName", string.Format("Invalid event entry name: {0}.", eventEntryNameString.GetStringValue())); } if (this.m_visibleTime == 0) { this.m_errorHandler.ErrorField(this, "visibleTime", "Visible time must be set if event entry name is set."); } } if (this.m_visibleTime != 0) { if (this.m_eventEntryData == null) { this.m_errorHandler.ErrorField(this, "eventEntryName", "Event entry name must be set if visible time is set."); } } this.m_inboxEntryId = LogicJSONHelper.GetInt(jsonObject, "inboxEntryId", -1); this.m_notificationTid = LogicJSONHelper.GetString(jsonObject, "notificationTid"); this.m_image = LogicJSONHelper.GetString(jsonObject, "image"); this.m_sc = LogicJSONHelper.GetString(jsonObject, "sc"); this.m_localization = LogicJSONHelper.GetString(jsonObject, "localization"); LogicJSONObject targetingObject = jsonObject.GetJSONObject("targeting"); if (targetingObject != null) { this.m_targeting = new LogicCalendarTargeting(jsonObject); } LogicJSONArray functionArray = jsonObject.GetJSONArray("functions"); if (functionArray != null) { for (int i = 0; i < functionArray.Size(); i++) { this.m_functions.Add(new LogicCalendarFunction(this, i, functionArray.GetJSONObject(i), this.m_errorHandler)); } } }